1: #ifndef lint
   2: static char sccsid[] = "@(#)gnsys.c	5.2 (Berkeley) 7/2/83";
   3: #endif
   4: 
   5: /*
   6:  * Mods:
   7:  * The "retry" code below prevents uucico from calling
   8:  * a site which it has called earlier.
   9:  * Also, uucico does callok() only once for each system.
  10:  * Done by unc!smb
  11:  */
  12: 
  13: #include "uucp.h"
  14: #include <sys/types.h>
  15: #ifdef  NDIR
  16: #include "ndir.h"
  17: #else
  18: #include <sys/dir.h>
  19: #endif
  20: 
  21: 
  22: #define LSIZE 100   /* number of systems to store */
  23: #define WSUFSIZE 6  /* work file name suffix size */
  24: 
  25: /*******
  26:  *	gnsys(sname, dir, pre)
  27:  *	char *sname, *dir, pre;
  28:  *
  29:  *	gnsys  -  this routine will return the next
  30:  *	system name which has work to be done.
  31:  *	"pre" is the prefix for work files.
  32:  *	"dir" is the directory to search.
  33:  *	"sname" is a string of size DIRSIZ - WSUFSIZE.
  34:  *
  35:  *	return codes:
  36:  *		0  -  no more names
  37:  *		1  -  name returned in sname
  38:  *		FAIL  -  bad directory
  39:  */
  40: 
  41: gnsys(sname, dir, pre)
  42: char *sname, *dir, pre;
  43: {
  44:     register char *s, *p1, *p2;
  45:     char px[3];
  46:     static char *list[LSIZE];
  47:     static int nitem=0, n=0, base=0;
  48:     char systname[NAMESIZE], filename[NAMESIZE];
  49:     DIR *dirp;
  50: 
  51: retry:
  52:     px[0] = pre;
  53:     px[1] = '.';
  54:     px[2] = '\0';
  55:     if (nitem == base) {
  56:         /* get list of systems with work */
  57:         int i;
  58:         dirp = opendir(subdir(dir,pre), "r");
  59:         ASSERT(dirp != NULL, "BAD DIRECTORY", dir, 0);
  60:         for (i = base; i < LSIZE; i++)
  61:             list[i] = NULL;
  62:         while (gnamef(dirp, filename) != 0) {
  63:             if (!prefix(px, filename))
  64:                 continue;
  65:             p2 = filename + strlen(filename)
  66:                 - WSUFSIZE;
  67:             p1 = filename + strlen(px);
  68:             for(s = systname; p1 <= p2; p1++)
  69:                 *s++ = *p1;
  70:             *s = '\0';
  71:             if (systname[0] == '\0')
  72:                 continue;
  73:             nitem = srchst(systname, list, nitem);
  74:             if (LSIZE <= nitem) break;
  75:         }
  76: 
  77:         closedir(dirp);
  78:     }
  79: 
  80:     if (nitem == base) {
  81:         for (n = 0; n < nitem; n++)
  82:             if (list[n] != NULL)
  83:                 free(list[n]);
  84:         return(0);
  85:     }
  86:     while(nitem > n) {
  87:         strcpy(sname, list[n++]);
  88:         if (callok(sname) == 0)
  89:             return(1);
  90:     }
  91:     base = n = nitem;
  92:     goto retry;
  93: }
  94: 
  95: /***
  96:  *	srchst(name, list, n)
  97:  *	char *name, **list;
  98:  *	int n;
  99:  *
 100:  *	srchst  -  this routine will do a linear search
 101:  *	of list (list) to find name (name).
 102:  *	If the name is not found, it is added to the
 103:  *	list.
 104:  *	The number of items in the list (n) is
 105:  *	returned (incremented if a name is added).
 106:  *
 107:  *	return codes:
 108:  *		n - the number of items in the list
 109:  */
 110: 
 111: srchst(name, list, n)
 112: char *name;
 113: register char **list;
 114: int n;
 115: {
 116:     register int i;
 117:     register char *p;
 118: 
 119:     for (i = 0; i < n; i++)
 120:         if (strcmp(name, list[i]) == 0)
 121:             break;
 122:     if (i >= n) {
 123:         if ((p = calloc((unsigned)strlen(name) + 1, sizeof (char)))
 124:             == NULL)
 125:             return(n);
 126:         strcpy(p, name);
 127:         list[n++] = p;
 128:     }
 129:     return(n);
 130: }

Defined functions

gnsys defined in line 41; used 1 times
srchst defined in line 111; used 1 times
  • in line 73

Defined variables

sccsid defined in line 2; never used

Defined macros

LSIZE defined in line 22; used 3 times
WSUFSIZE defined in line 23; used 1 times
  • in line 66
Last modified: 1983-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 837
Valid CSS Valid XHTML 1.0 Strict