|
|
1.1 root 1: #include "uucp.h"
2:
3:
4: #define LSIZE 30 /* number of systems to store */
5: #define WSUFSIZE 6 /* work file name suffix size */
6:
7: /*******
8: * gnsys(sname, dir, pre)
9: * char *sname, *dir, pre;
10: *
11: * gnsys - this routine will return the next
12: * system name which has work to be done.
13: * "pre" is the prefix for work files.
14: * "dir" is the directory to search.
15: * "sname" is a string of size DIRSIZ - WSUFSIZE.
16: *
17: * return codes:
18: * 0 - no more names
19: * 1 - name returned in sname
20: * FAIL - bad directory
21: */
22:
23: gnsys(sname, dir, pre)
24: char *sname, *dir, pre;
25: {
26: char *s, *p1, *p2;
27: char px[3];
28: static char *list[LSIZE];
29: static int nitem=0, n=0;
30: char sysname[NAMESIZE], filename[NAMESIZE];
31: FILE *fp;
32:
33: px[0] = pre;
34: px[1] = '.';
35: px[2] = '\0';
36: if (nitem == 0) {
37: /* get list of systems with work */
38: int i;
39: fp = fopen(dir, "r");
40: ASSERT(fp != NULL, "BAD DIRECTRY %s\n", dir);
41: for (i = 0; i < LSIZE; i++)
42: list[i] = NULL;
43: while (gnamef(fp, filename) != 0) {
44: if (!prefix(px, filename))
45: continue;
46: p2 = filename + strlen(filename)
47: - WSUFSIZE;
48: p1 = filename + strlen(px);
49: for(s = sysname; p1 <= p2; p1++)
50: *s++ = *p1;
51: *s = '\0';
52: if (sysname[0] == '\0')
53: continue;
54: nitem = srchst(sysname, list, nitem);
55: if (LSIZE <= nitem) break;
56: }
57:
58: fclose(fp);
59: }
60:
61: if (nitem == 0)
62: return(0);
63: while(nitem > n) {
64: strcpy(sname, list[n++]);
65: if (callok(sname) == 0)
66: return(1);
67: }
68: for (n = 0; n < nitem; n++)
69: if (list[n] != NULL)
70: free(list[n]);
71: nitem = n = 0;
72: return(0);
73: }
74:
75: /***
76: * srchst(name, list, n)
77: * char *name, **list;
78: * int n;
79: *
80: * srchst - this routine will do a linear search
81: * of list (list) to find name (name).
82: * If the name is not found, it is added to the
83: * list.
84: * The number of items in the list (n) is
85: * returned (incremented if a name is added).
86: *
87: * return codes:
88: * n - the number of items in the list
89: */
90:
91: srchst(name, list, n)
92: char *name, **list;
93: int n;
94: {
95: int i;
96: char *p;
97: extern char *calloc();
98:
99: for (i = 0; i < n; i++)
100: if (strcmp(name, list[i]) == 0)
101: break;
102: if (i >= n) {
103: if ((p = calloc(strlen(name) + 1, sizeof (char)))
104: == NULL)
105: return(n);
106: strcpy(p, name);
107: list[n++] = p;
108: }
109: return(n);
110: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.