📄 slist.c
字号:
char tempName[SERVER_NAME_SIZE], /* Used for copying server name */
tempAddr[26]; /* Used for copying server address */
/*
I'm a simple man with simple tastes, so a bubble sort will do
*/
for ( i = 0 ; i < numServers-1 ; i++ )
for ( j = 0 ; j < numServers-1 ; j++ )
if (strcmp(serverList[j].name, serverList[j+1].name) > 0)
{
/*
Switch the server names
*/
strcpy(tempName, serverList[j].name );
strcpy(serverList[j].name, serverList[j+1].name );
strcpy(serverList[j+1].name, tempName );
/*
Switch the server addresses
*/
strcpy(tempAddr, serverList[j].addr );
strcpy(serverList[j].addr, serverList[j+1].addr );
strcpy(serverList[j+1].addr, tempAddr );
}
return;
}
/****************************************************************************/
/*
Description: Print the list of servers and there addresses
Called by: Main
*/
void PrintServerNames(serverList, numServers, defaultConnection)
SERVER serverList[]; /* List of servers and there addresses */
int numServers; /* Number of servers found */
WORD defaultConnection; /* Default connection */
{
int i, /* Loop counter */
status; /* Status message for this server */
WORD connection; /* Connection ID to a server in the list */
/*
Clear the message that says we are reading server names
*/
fprintf(stderr, GetMessage(ERASE_LINE));
/*
If output is being sent to a file, tell user that we are doing so
*/
if (outputToFile)
fprintf(stderr, GetMessage(WRITING_TO_FILE));
/*
Now print out all the servers
*/
for ( i = 0 ; i <= numServers-1 ; i++ )
{
/*
See if its time to print a header
*/
if (((i % (linesPerScreen - 2) == 0) && pause) || i == 0)
{
Print(GetMessage(HEADER_1));
Print(GetMessage(HEADER_2));
}
/*
See if we are attached to this server
*/
status = STATUS_UNATTACHED;
if (!NWGetConnectionID(serverList[i].name, MY_SESSION,
&connection, NULL))
{
if (connection == defaultConnection)
status = STATUS_DEFAULT;
else
status = STATUS_ATTACHED;
}
/*
Print the server name and address
*/
Print("%-47.47s%-24.24s%-8.8s\n", serverList[i].name,
serverList[i].addr, GetMessage(status));
}
/*
Tell how many servers were found
*/
if (numServers)
Print(GetMessage(NUMBER_OF_SERVERS_FOUND), numServers);
else
{
if (IsWild(targetServer))
Print(GetMessage(NO_MATCHING_SERVER), targetServer);
else
Print(GetMessage(NO_SUCH_SERVER), targetServer);
}
/*
If data was being written to a file, erase the line that
tells him we are writing to the file
*/
if (outputToFile)
fprintf(stderr, GetMessage(ERASE_LINE));
/*
Return to caller
*/
return;
}
/****************************************************************************/
/*
Description: Print some data to standard output, pausing if needed
after each screen full
Called by: PrintServerNames
*/
void Print(formatString, ...)
char *formatString; /* Format control string */
{
int c; /* Character input from keyboard */
va_list args; /* Pointer to variable arguments */
static int /* Lines printed so far */
lines = 0;
/*
Figure out where all those other parameters are
*/
va_start(args, formatString);
/*
Print the text required
*/
vprintf(formatString, args);
/*
Increment number of lines printed
*/
lines++;
/*
If we have printed enough lines, and pause is in effect, wait for
a keypress
*/
if (lines == linesPerScreen && pause)
{
printf(GetMessage(PRESS_A_KEY));
c = getch();
/*
Make sure it wasn't some sort of funky key
*/
if (c == 0 || c == 224)
getch();
/*
If they don't want any more pauses, then don't
*/
if (c == 'C' || c == 'c')
pause = FALSE;
printf(GetMessage(ERASE_LINE));
lines = 0;
}
}
/****************************************************************************/
/*
Description: Print an error message, with optional numeric output
and exit the program
Called by: Main
ReadServerNames
*/
void Error(errorMessageID, ...)
int errorMessageID; /* Error message ID to be printed */
/* Variable arguments may follow */
{
va_list args; /* Pointer to variable arguments */
/*
Figure out where all those other parameters are
*/
va_start(args, errorMessageID);
/*
Print the error message, beep, append a return and exit
*/
fprintf(stderr, GetMessage(ERASE_LINE));
vfprintf(stderr, GetMessage(errorMessageID), args);
fprintf(stderr, "\7\n");
exit(1);
}
/****************************************************************************/
/*
M Code for SList
*/
int ActionProcedure(int action)
{
int abort = 0, unmatch = 0;
switch(action)
{
case 0: {
pause = FALSE; } break;
case 1: {
doDomain = TRUE; } break;
case 2: {
GetServer(); } break;
}
return(abort? 2: (unmatch? 1: 0));
}
/****************************************************************************/
/*
Description: Get the name of the server to be listed, or the
pattern of servers to search for
Called by: M Parser
*/
void GetServer()
{
memcpy(targetServer, TChP(0), TVal(0));
targetServer[TVal(0)] = '\0';
}
/****************************************************************************/
int WildMatch(pattern, string)
char *pattern, *string;
{
char p, s;
int l;
char MatchPeriod;
while ((p = (*pattern & 0x7F)) != '*')
{
s = *string & 0x7F;
if (p == '?')
{
if ((*pattern == SQUESTION)
&& ((s == 0) || (s == '.')))
{
/*special question skip period or end*/
pattern++;
}
else
{
if (s == 0)
return (0); /*no char to match*/
pattern++; /*succeed on ? match*/
string++;
}
}
else if ((*pattern == SPERIOD) && (s == 0))
{
/*match special period to end-of-string*/
pattern++;
}
else if (p != s)
return (0); /*failure on non-match*/
else if (p == 0)
return (1); /*success on match to nulls*/
else
{
/*chars match, but not end yet*/
pattern++;
string++;
}
}
/* MUST MATCH AN ASTERISK WILDCARD */
MatchPeriod = 0;
while ((*pattern & 0x7F) == '*')
{
/* step over asterisks */
if ((*pattern & 0x80) == 0)
MatchPeriod = 0xFF;
pattern++;
}
for (l = 0; (string[l] != 0) && ((string[l] != '.') || MatchPeriod);
l++); /*count max characters that may be skipped*/
p = *pattern & 0x7F;
while (l >= 0)
{
s = string[l] & 0x7F;
if (((p == s) || (p == '?') || (p == '.'))
&& WildMatch(pattern, &string[l]))
return (1); /*success*/
l--;
}
return (0);
}
/****************************************************************************/
int IsWild (s)
char *s;
{
char ch;
while ((ch = *s++ & 0x7F) != 0)
{
switch(ch)
{
case ASTERISK:
case QUESTION:
case SPERIOD:
case SASTERISK:
case SQUESTION:
return(1);
}
}
return (0);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void IsServerInADomain(
WORD connectionID, /* connection ID of server to change */
int *isInADomain, /* flag returns TRUE if in a domain */
char *domainName ) /* name of the domain if isInDomain is TRUE */
{
int ccode = TRUE;
long tmpDummy;
char serverName[SERVER_NAME_SIZE];
NWGetFileServerName(connectionID, serverName);
*isInADomain = FALSE;
*domainName = 0;
if (serverName[0] != '\0')
ccode = NWReadPropertyValue( (WORD) connectionID, serverName,
OT_FILE_SERVER, (char far *)"DOMAIN_NAME", 1, (BYTE far *) domainName,
(BYTE far *)&tmpDummy, (BYTE far *)&tmpDummy);
if ( ccode==0 )
*isInADomain = TRUE;
} /* end IsServerInADomain */
/***************************************************************************/
void DisplayUsageLine(void)
{
int isInADomain, jj;
char domainName[PROPERTY_NAME_SIZE];
WORD maxConnects;
NWGetMaximumConnections(&maxConnects);
for (jj=1; jj<=maxConnects; jj++)
{
IsServerInADomain( jj, &isInADomain,
domainName );
if (isInADomain) break;
}
if (isInADomain)
Error(E_NNS_USAGE);
else
Error(E_USAGE);
}
/**************************************************************************/
/**** SetScrollParms ****************************************************
*
* Input: None;
*
* Output: none
*
* Comment: This routine will detect if output is redirected to a
* file and will enable or disable pausing accordingly. Also
* this routine will detect the number of rows in the current
* video mode so that scrolling will work properly.
*
****/
void SetScrollParms()
{
#ifdef DOS
union REGS inregs, outregs;
#endif
/* Assume that we are going to pause after each screen full */
pause = TRUE;
/* Has output been redirected to a file? If so, don't pause! */
if ( isatty( fileno( stdout ) ) )
{
pause = TRUE;
outputToFile = FALSE;
}
else
{
pause = FALSE;
outputToFile = TRUE;
}
#ifdef DOS
/* Issue BIOS call to get current # of screen lines */
inregs.x.ax = 0x1130;
inregs.h.bh = 0;
inregs.x.dx = 0;
int86( VIDEO_INT, &inregs, &outregs );
if( outregs.x.dx != 0 )
linesPerScreen = (BYTE)outregs.h.dl;
else
#endif
linesPerScreen = MIN_LINES;
}
/****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -