Commit | Line | Data |
---|---|---|
da6efb07 TL |
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 | if (callok(sysname) == 0) | |
55 | nitem = srchst(sysname, list, nitem); | |
56 | if (LSIZE <= nitem) break; | |
57 | } | |
58 | ||
59 | fclose(fp); | |
60 | } | |
61 | ||
62 | if (nitem == 0) | |
63 | return(0); | |
64 | if (nitem <= n ) { | |
65 | for (n = 0; n < nitem; n++) | |
66 | if (list[n] != NULL) | |
67 | free(list[n]); | |
68 | nitem = n = 0; | |
69 | return(0); | |
70 | } | |
71 | ||
72 | strcpy(sname, list[n++]); | |
73 | return(1); | |
74 | } | |
75 | ||
76 | /*** | |
77 | * srchst(name, list, n) | |
78 | * char *name, **list; | |
79 | * int n; | |
80 | * | |
81 | * srchst - this routine will do a linear search | |
82 | * of list (list) to find name (name). | |
83 | * If the name is not found, it is added to the | |
84 | * list. | |
85 | * The number of items in the list (n) is | |
86 | * returned (incremented if a name is added). | |
87 | * | |
88 | * return codes: | |
89 | * n - the number of items in the list | |
90 | */ | |
91 | ||
92 | srchst(name, list, n) | |
93 | char *name, **list; | |
94 | int n; | |
95 | { | |
96 | int i; | |
97 | char *p; | |
98 | extern char *calloc(); | |
99 | ||
100 | for (i = 0; i < n; i++) | |
101 | if (strcmp(name, list[i]) == 0) | |
102 | break; | |
103 | if (i >= n) { | |
104 | if ((p = calloc(strlen(name) + 1, sizeof (char))) | |
105 | == NULL) | |
106 | return(n); | |
107 | strcpy(p, name); | |
108 | list[n++] = p; | |
109 | } | |
110 | return(n); | |
111 | } |