1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#include "common.h"
#include "send.h"
#undef isspace
#define isspace(c) ((c)==' ' || (c)=='\t' || (c)=='\n')
/*
* skip past all systems in equivlist
*/
extern char*
skipequiv(char *base)
{
char *sp;
static Biobuf *fp;
while(*base){
sp = strchr(base, '!');
if(sp==0)
break;
*sp = '\0';
if(lookup(base, "equivlist", &fp, 0, 0)==1){
/* found or us, forget this system */
*sp='!';
base=sp+1;
} else {
/* no files or system is not found, and not us */
*sp='!';
break;
}
}
return base;
}
static int
okfile(char *cp, Biobuf *fp)
{
char *buf;
int len;
char *bp, *ep;
int c;
len = strlen(cp);
Bseek(fp, 0, 0);
/* one iteration per system name in the file */
while(buf = Brdline(fp, '\n')) {
ep = &buf[Blinelen(fp)];
for(bp=buf; bp < ep;){
while(isspace(*bp) || *bp==',')
bp++;
if(strncmp(bp, cp, len) == 0) {
c = *(bp+len);
if(isspace(c) || c==',')
return 1;
}
while(bp < ep && (!isspace(*bp)) && *bp!=',')
bp++;
}
}
/* didn't find it, prohibit forwarding */
return 0;
}
/* return 1 if name found in one of the files
* 0 if name not found in one of the files
* -1 if neither file exists
*/
extern int
lookup(char *cp, char *local, Biobuf **lfpp, char *global, Biobuf **gfpp)
{
static String *file = 0;
if (local) {
if (file == 0)
file = s_new();
abspath(local, UPASLIB, s_restart(file));
if (*lfpp != 0 || (*lfpp = sysopen(s_to_c(file), "r", 0)) != 0) {
if (okfile(cp, *lfpp))
return 1;
} else
local = 0;
}
if (global) {
abspath(global, UPASLIB, s_restart(file));
if (*gfpp != 0 || (*gfpp = sysopen(s_to_c(file), "r", 0)) != 0) {
if (okfile(cp, *gfpp))
return 1;
} else
global = 0;
}
return (local || global)? 0 : -1;
}
|