diff options
author | rsc <devnull@localhost> | 2005-10-29 16:26:44 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-10-29 16:26:44 +0000 |
commit | 5cdb17983ae6e6367ad7a940cb219eab247a9304 (patch) | |
tree | 8ca1ef49af2a96e7daebe624d91fdf679814a057 /src/cmd/upas/send/skipequiv.c | |
parent | cd3745196389579fb78b9b01ef1daefb5a57aa71 (diff) | |
download | plan9port-5cdb17983ae6e6367ad7a940cb219eab247a9304.tar.gz plan9port-5cdb17983ae6e6367ad7a940cb219eab247a9304.tar.bz2 plan9port-5cdb17983ae6e6367ad7a940cb219eab247a9304.zip |
Thanks to John Cummings.
Diffstat (limited to 'src/cmd/upas/send/skipequiv.c')
-rw-r--r-- | src/cmd/upas/send/skipequiv.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/cmd/upas/send/skipequiv.c b/src/cmd/upas/send/skipequiv.c new file mode 100644 index 00000000..f40181ad --- /dev/null +++ b/src/cmd/upas/send/skipequiv.c @@ -0,0 +1,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; +} |