1: #if !defined(lint) && defined(DOSCCS)
   2: static char sccsid[] = "@(#)gnsys.c	5.4.1 (2.11BSD) 1997/10/31";
   3: #endif
   4: 
   5: #include "uucp.h"
   6: #ifdef  NDIR
   7: #include "ndir.h"
   8: #else
   9: #include <sys/dir.h>
  10: #endif
  11: 
  12: #define LSIZE 128   /* number of systems to store */
  13: #define WSUFSIZE 6  /* work file name suffix size */
  14: 
  15: /*LINTLIBRARY*/
  16: 
  17: /*
  18:  *	this routine will return the next system name which has work to be done.
  19:  *	"sname" is a string of size DIRSIZ - WSUFSIZE.
  20:  *	"pre" is the prefix for work files.
  21:  *	"dir" is the directory to search.
  22:  *
  23:  *	return codes:
  24:  *		1  -  name returned in sname
  25:  *		SUCCESS  -  no more names
  26:  *		FAIL  -  bad directory
  27:  */
  28: 
  29: gnsys(sname, dir, pre)
  30: char *sname, *dir, pre;
  31: {
  32:     register char *s, *p1, *p2;
  33:     char px[3];
  34:     static char *list[LSIZE];
  35:     static int nitem=0, n=0, base=0;
  36:     char systname[NAMESIZE], filename[NAMESIZE];
  37:     DIR *dirp;
  38: 
  39: retry:
  40:     px[0] = pre;
  41:     px[1] = '.';
  42:     px[2] = '\0';
  43:     if (nitem == base) {
  44:         /* get list of systems with work */
  45:         int i;
  46:         dirp = opendir(subdir(dir,pre));
  47:         ASSERT(dirp != NULL, "BAD DIRECTORY", dir, 0);
  48:         for (i = base; i < LSIZE; i++)
  49:             list[i] = NULL;
  50:         while (gnamef(dirp, filename) != 0) {
  51:             if (!prefix(px, filename))
  52:                 continue;
  53:             p2 = filename + strlen(filename)
  54:                 - WSUFSIZE;
  55:             p1 = filename + strlen(px);
  56:             for(s = systname; p1 <= p2; p1++)
  57:                 *s++ = *p1;
  58:             *s = '\0';
  59:             if (systname[0] == '\0')
  60:                 continue;
  61:             nitem = srchst(systname, list, nitem);
  62:             if (LSIZE <= nitem) break;
  63:         }
  64: 
  65:         closedir(dirp);
  66:     }
  67: 
  68:     if (nitem == base) {
  69:         for (n = 0; n < nitem; n++)
  70:             if (list[n] != NULL)
  71:                 free(list[n]);
  72:         return SUCCESS;
  73:     }
  74:     while(nitem > n) {
  75:         /* We only have at most a SYSNSIZE character site name encoded
  76: 		 * in the file. However, we would like to use the full sitename
  77: 		 * if possible. If the number of chars in list[n] is < SYSNSIZE
  78: 		 * then the sitename could not have been truncated and
  79: 		 * we don't bother to check. Otherwise, we scan SYSFILE
  80: 		 * looking for the fullname and return it if we find it
  81: 		 */
  82:         strcpy(sname, list[n++]);
  83:         if (strlen(sname) >= SYSNSIZE) {
  84:             register FILE *fp;
  85:             register char *p;
  86:             char line[MAXFULLNAME];
  87:             fp = fopen(SYSFILE, "r");
  88:             ASSERT(fp != NULL, CANTOPEN, SYSFILE, 0);
  89:             while (cfgets(line, sizeof(line), fp) != NULL) {
  90:                 p = index(line, ' ');
  91:                 if (p)
  92:                     *p = '\0';
  93:                 if (strncmp(sname, line, SYSNSIZE) == SAME) {
  94:                     strncpy(sname, line, MAXBASENAME);
  95:                     break;
  96:                 }
  97:             }
  98:             fclose(fp);
  99:         }
 100:         if (callok(sname) == 0)
 101:             return 1;
 102:     }
 103:     base = n = nitem;
 104:     goto retry;
 105: }
 106: 
 107: /*
 108:  *	this routine will do a linear search of list (list) to find name (name).
 109:  *	If the name is not found, it is added to the list.
 110:  *	The number of items in the list (n) is returned (incremented if a
 111:  *	name is added).
 112:  *
 113:  *	return codes:
 114:  *		n - the number of items in the list
 115:  */
 116: 
 117: srchst(name, list, n)
 118: char *name;
 119: register char **list;
 120: int n;
 121: {
 122:     register int i;
 123:     register char *p;
 124: 
 125:     for (i = 0; i < n; i++)
 126:         if (strcmp(name, list[i]) == 0)
 127:             break;
 128:     if (i >= n) {
 129:         if ((p = (char *)calloc(strlen(name) + 1, sizeof (char)))
 130:             == NULL)
 131:             return n;
 132:         strcpy(p, name);
 133:         list[n++] = p;
 134:     }
 135:     return n;
 136: }

Defined functions

gnsys defined in line 29; used 1 times
srchst defined in line 117; used 1 times
  • in line 61

Defined variables

sccsid defined in line 2; never used

Defined macros

LSIZE defined in line 12; used 3 times
WSUFSIZE defined in line 13; used 1 times
  • in line 54
Last modified: 1997-11-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2653
Valid CSS Valid XHTML 1.0 Strict