int old_match(const char *pattern, const char *string) { char type = 0; while (*string && *pattern && *pattern != '*' && *pattern != '%') { if (*pattern == '\\' && pattern[1]) { if (!*++pattern || !(mkupper(*pattern) == mkupper(*string))) return 0; else pattern++, string++, total_explicit++; continue; /* Erf! try $match(\\* *) */ } if (*pattern == '?') pattern++, string++; else if (mkupper(*pattern) == mkupper(*string)) pattern++, string++, total_explicit++; else break; } if (*pattern == '*' || *pattern == '%') { type = (*pattern++); while (*string) { if (old_match(pattern, string)) return 1; else if (type == '*' || *string != ' ') string++; else break; } } /* Slurp up any trailing *'s or %'s... */ if (!*string && (type == '*' || type == '%')) while (*pattern && (*pattern == '*' || *pattern == '%')) pattern++; if (!*string && !*pattern) return 1; return 0; }
char *strstrx(char *s1, char *s2) // like strstr but case insensitive // see also strcasestr { char *ss1, *ss2, *spt ; ss1 = strdup(s1) ; ss2 = strdup(s2) ; mkupper(ss1) ; mkupper(ss2) ; spt = strstr(ss1, ss2) ; if (spt != NULL) { spt = s1 + (spt - ss1) ; } freestring(&ss1) ; freestring(&ss2) ; return spt ; }
char * unix2vms_path(char *dst, const char *src) { #if !SYS_VMS char tmp2[NFILEN]; #endif char tmp[NFILEN]; char leading[NFILEN]; char *t; char *s = strcpy(tmp, src); /* ... to permit src == dst */ char *d = dst; char c = '?'; int bracket = FALSE; /* true when "[" passed. */ int on_top = FALSE; /* true when no "[." lead */ int node = FALSE; /* true when node found */ int device = FALSE; /* true when device found */ int len; /* * If VMS 'getenv()' is given an upper-case name, it assumes that it * corresponds to a logical device assignment. As a special case, if * we have a leading token of this form, translate it. */ if ((len = leading_uc(leading, s)) != 0) { s += len; len = strlen(strcpy(d, leading)); while (len > 1 && d[len - 1] == ' ') len--; if (*s) { /* text follows leading token */ s++; /* skip (assumed) SLASHC */ if ((len > 1) && (d[len - 1] == COLON)) { on_top = TRUE; } else if (strchr(s, SLASHC)) { /* must do a splice */ if ((len > 2) && (d[len - 1] == R_BLOCK)) { bracket++; if (d[len - 2] == PERIOD) /* rooted-device ? */ len -= 2; else len--; } } } d[len] = EOS; if ((t = strchr(d, COLON)) != NULL) { if (t[1] == COLON) { node = TRUE; if ((t = strchr(t + 2, COLON)) != NULL) device = TRUE; } else device = TRUE; } d += len; } else if (*s == CH_TILDE) { /* process home-directory reference */ char *home = getenv("SYS$LOGIN"); #if !SYS_VMS if (home == 0) home = unix2vms_path(tmp2, getenv("HOME")); #endif node = device = TRUE; s++; len = strlen(strcpy(d, home)); if (d[len - 1] == R_BLOCK) { bracket++; if (strcmp(s, "/")) { /* strip right-bracket to allow new levels */ if (d[len - 2] == PERIOD) len--; d[len - 1] = PERIOD; } else { s++; len--; } } d += len; } /* look for node-name in VMS-format */ if (!node && (t = strchr(s, '!')) != 0 && (t[1] == SLASHC || t[1] == EOS)) { leaf_dot = DotPrefix(s); while (s < t) *d++ = CharToVms(*s++); *d++ = COLON; *d++ = COLON; s++; /* skip over '!' */ } /* look for device-name, indicated by a leading SLASHC */ if (!device && (*s == SLASHC)) { leaf_dot = DotPrefix(++s); if ((t = strchr(s, SLASHC)) == 0) t = skip_string(s); else if (t[1] == EOS) on_top = TRUE; while (s < t) *d++ = CharToVms(*s++); if (d != dst) *d++ = COLON; } /* permit leading "./" to simplify cases in which we concatenate */ if (!strncmp(s, "./", 2)) s += 2; /* translate repeated leading "../" */ while (!strncmp(s, "../", 3)) { s += 3; if (!bracket++) *d++ = L_BLOCK; *d++ = '-'; } if (!strcmp(s, "..")) { s += 2; if (!bracket++) *d++ = L_BLOCK; *d++ = '-'; } if (strchr(s, SLASHC)) { if (!bracket++) *d++ = L_BLOCK; if (*s == SLASHC) { s++; } else if (!on_top) { *d++ = PERIOD; } while ((c = *s++) != EOS) { if (c == PERIOD) { c = '$'; if (*s == SLASHC) /* ignore "./" */ continue; } if (c == SLASHC) { leaf_dot = DotPrefix(s); if (strchr(s, SLASHC)) *d++ = PERIOD; else { break; } } else { *d++ = CharToVms(c); } } } if (bracket) { if (on_top && d[-1] == L_BLOCK) { (void) strcpy(d, RootDir); d += strlen(d); } *d++ = R_BLOCK; } if (c != EOS && *s) { leaf_dot = DotPrefix(s); while ((c = *s) != EOS) { if ((leaf_ver = is_version(s)) == TRUE) { leaf_dot = TRUE; /* no longer pertinent */ (void) strcpy(d, s); *d = SEMICOLON; /* make this unambiguous */ d += strlen(d); break; } else { *d++ = CharToVms(c); } s++; } if (!leaf_dot) *d++ = PERIOD; if (!leaf_ver) *d++ = SEMICOLON; } *d = EOS; return mkupper(dst); }
static void loop() { char buf[BUFSIZ]; char *p; int c; signal(SIGALRM, bye); while (alarm(300), fgets(buf, sizeof(buf), stdin)) { bytes_received_count += strlen(buf); alarm(0); if ((p=strchr(buf, '\n')) != 0) *p=0; else while ((c=getc(stdin)) >= 0 && c != '\n') ; p=strtok(buf, " \t\r"); if (!p) p=""; mkupper(p); if (strcmp(p, "QUIT") == 0) { printed(printf("+OK Bye-bye.\r\n")); fflush(stdout); cleanup(); acctout("INFO: LOGOUT"); return; } if (strcmp(p, "STAT") == 0) { do_stat(); continue; } if (strcmp(p, "LIST") == 0) { do_list(strtok(NULL, " \t\r")); continue; } if (strcmp(p, "RETR") == 0) { unsigned i; if ((i=getmsgnum(strtok(NULL, " \t\r"))) == 0) continue; do_retr(i-1, 0); continue; } if (strcmp(p, "CAPA") == 0) { pop3dcapa(); continue; } if (strcmp(p, "DELE") == 0) { unsigned i; if ((i=getmsgnum(strtok(NULL, " \t\r"))) == 0) continue; msglist_a[i-1]->isdeleted=1; printed(printf("+OK Deleted.\r\n")); fflush(stdout); continue; } if (strcmp(p, "NOOP") == 0) { printed(printf("+OK Yup.\r\n")); fflush(stdout); continue; } if (strcmp(p, "RSET") == 0) { unsigned i; for (i=0; i<msglist_cnt; i++) msglist_a[i]->isdeleted=0; printed(printf("+OK Resurrected.\r\n")); fflush(stdout); continue; } if (strcmp(p, "TOP") == 0) { unsigned i, j; const char *q; if ((i=getmsgnum(strtok(NULL, " \t\r"))) == 0) continue; q=strtok(NULL, " \t\r"); if (!q) goto error; j=atoi(q); do_retr(i-1, &j); continue; } if (strcmp(p, "UIDL") == 0) { do_uidl(strtok(NULL, " \t\r")); continue; } error: printed(printf("-ERR Invalid command.\r\n")); fflush(stdout); } acctout("INFO: DISCONNECTED"); }
/* * Evaluate a function. * * @fname: name of function to evaluate. */ char *gtfun(char *fname) { int fnum; /* index to function to eval */ int status; /* return status */ char *tsp; /* temporary string pointer */ char arg1[NSTRING]; /* value of first argument */ char arg2[NSTRING]; /* value of second argument */ char arg3[NSTRING]; /* value of third argument */ static char result[2 * NSTRING]; /* string result */ /* look the function up in the function table */ fname[3] = 0; /* only first 3 chars significant */ mklower(fname); /* and let it be upper or lower case */ for (fnum = 0; fnum < ARRAY_SIZE(funcs); fnum++) if (strcmp(fname, funcs[fnum].f_name) == 0) break; /* return errorm on a bad reference */ if (fnum == ARRAY_SIZE(funcs)) return errorm; /* if needed, retrieve the first argument */ if (funcs[fnum].f_type >= MONAMIC) { if ((status = macarg(arg1)) != TRUE) return errorm; /* if needed, retrieve the second argument */ if (funcs[fnum].f_type >= DYNAMIC) { if ((status = macarg(arg2)) != TRUE) return errorm; /* if needed, retrieve the third argument */ if (funcs[fnum].f_type >= TRINAMIC) if ((status = macarg(arg3)) != TRUE) return errorm; } } /* and now evaluate it! */ switch (fnum) { case UFADD: return itoa(atoi(arg1) + atoi(arg2)); case UFSUB: return itoa(atoi(arg1) - atoi(arg2)); case UFTIMES: return itoa(atoi(arg1) * atoi(arg2)); case UFDIV: return itoa(atoi(arg1) / atoi(arg2)); case UFMOD: return itoa(atoi(arg1) % atoi(arg2)); case UFNEG: return itoa(-atoi(arg1)); case UFCAT: strcpy(result, arg1); return strcat(result, arg2); case UFLEFT: return strncpy(result, arg1, atoi(arg2)); case UFRIGHT: return (strcpy(result, &arg1[(strlen(arg1) - atoi(arg2))])); case UFMID: return (strncpy(result, &arg1[atoi(arg2) - 1], atoi(arg3))); case UFNOT: return ltos(stol(arg1) == FALSE); case UFEQUAL: return ltos(atoi(arg1) == atoi(arg2)); case UFLESS: return ltos(atoi(arg1) < atoi(arg2)); case UFGREATER: return ltos(atoi(arg1) > atoi(arg2)); case UFSEQUAL: return ltos(strcmp(arg1, arg2) == 0); case UFSLESS: return ltos(strcmp(arg1, arg2) < 0); case UFSGREAT: return ltos(strcmp(arg1, arg2) > 0); case UFIND: return strcpy(result, getval(arg1)); case UFAND: return ltos(stol(arg1) && stol(arg2)); case UFOR: return ltos(stol(arg1) || stol(arg2)); case UFLENGTH: return itoa(strlen(arg1)); case UFUPPER: return mkupper(arg1); case UFLOWER: return mklower(arg1); case UFTRUTH: return ltos(atoi(arg1) == 42); case UFASCII: return itoa((int) arg1[0]); case UFCHR: result[0] = atoi(arg1); result[1] = 0; return result; case UFGTKEY: result[0] = tgetc(); result[1] = 0; return result; case UFRND: return itoa((ernd() % abs(atoi(arg1))) + 1); case UFABS: return itoa(abs(atoi(arg1))); case UFSINDEX: return itoa(sindex(arg1, arg2)); case UFENV: #if ENVFUNC tsp = getenv(arg1); return tsp == NULL ? "" : tsp; #else return ""; #endif case UFBIND: return transbind(arg1); case UFEXIST: return ltos(fexist(arg1)); case UFFIND: tsp = flook(arg1, TRUE); return tsp == NULL ? "" : tsp; case UFBAND: return itoa(atoi(arg1) & atoi(arg2)); case UFBOR: return itoa(atoi(arg1) | atoi(arg2)); case UFBXOR: return itoa(atoi(arg1) ^ atoi(arg2)); case UFBNOT: return itoa(~atoi(arg1)); case UFXLATE: return xlat(arg1, arg2, arg3); } exit(-11); /* never should get here */ }