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