|
|
1.1 ! root 1: /* ! 2: * readnews - read news articles. ! 3: */ ! 4: ! 5: static char *SccsId = "@(#)readnews.c 2.10 4/23/83"; ! 6: ! 7: #include "rparams.h" ! 8: ! 9: /* ! 10: * readnews - article reading program ! 11: */ ! 12: ! 13: #ifndef SYSBUF ! 14: char SYSBUF[BUFSIZ]; /* to buffer std out */ ! 15: #endif ! 16: ! 17: #define OPTION 0 /* pick up an option string */ ! 18: #define STRING 1 /* pick up a string of arguments */ ! 19: ! 20: /* ! 21: * Authors: ! 22: * Matt Glickman ucbvax!glickman ! 23: * Mark Horton cbosg!mark ! 24: * Stephen Daniels duke!swd ! 25: * Tom Truscott duke!trt ! 26: */ ! 27: ! 28: main(argc, argv) ! 29: int argc; ! 30: register char **argv; ! 31: { ! 32: register char *ptr; /* pointer to rest of buffer */ ! 33: char *user, *home; ! 34: struct passwd *pw; ! 35: struct group *gp; ! 36: int i, optflag = FALSE, space = FALSE; ! 37: struct utsname ubuf; ! 38: char *myrc; ! 39: #ifdef NOTIFY ! 40: FILE *nfd; /* notify file descriptor */ ! 41: #endif ! 42: ! 43: /* set up defaults and initialize. */ ! 44: pathinit(); ! 45: mode = UNKNOWN; ! 46: header.title[0] = header.nbuf[0] = '\0'; ! 47: titlebuf[0] = coptbuf[0] = datebuf[0] = '\0'; ! 48: uname(&ubuf); ! 49: strcpy(SYSNAME, ubuf.nodename); ! 50: SYSNAME[SNLN] = '\0'; ! 51: ! 52: savmask = umask(N_UMASK); /* set up mask */ ! 53: uid = getuid(); ! 54: gid = getgid(); ! 55: duid = 0; ! 56: dgid = 0; ! 57: ! 58: #ifndef V6 ! 59: #ifndef SHELL ! 60: if ((SHELL = getenv("SHELL")) == NULL) ! 61: SHELL = "/bin/sh"; ! 62: #endif ! 63: #ifndef IHCC ! 64: /* ! 65: * IHCC does not allow use of $LOGNAME to prevent forgery. ! 66: * Note that this shouldn't matter in readnews, since inews ! 67: * does all the actual posting of news. ! 68: */ ! 69: if ((user = getenv("USER")) == NULL) ! 70: user = getenv("LOGNAME"); ! 71: if ((home = getenv("HOME")) == NULL) ! 72: home = getenv("LOGDIR"); ! 73: #endif ! 74: if (user == NULL || home == NULL) ! 75: getuser(); ! 76: else { ! 77: strcpy(username, user); ! 78: strcpy(header.path, username); ! 79: strcpy(userhome, home); ! 80: } ! 81: ! 82: getuser(); ! 83: if (!(MAILER = getenv("MAILER"))) ! 84: MAILER = "mail"; /* was /bin/mail */ ! 85: ! 86: #ifdef PAGE ! 87: if (myrc = getenv("PAGER")) ! 88: strcpy(PAGER, myrc); ! 89: else ! 90: # ifdef IHCC ! 91: sprintf(PAGER,"%s/bin/%s",logdir(HOME),PAGE); ! 92: # else ! 93: strcpy(PAGER, PAGE); ! 94: # endif ! 95: #else ! 96: strcpy(PAGER, ""); ! 97: #endif ! 98: ! 99: if (ptr = getenv("NEWSOPTS")) ! 100: strcpy(rcbuf, ptr); ! 101: else ! 102: *rcbuf = '\0'; ! 103: if (*rcbuf) { ! 104: strcat(rcbuf, " \1"); ! 105: ptr = rcbuf; ! 106: while (*++ptr) ! 107: if (isspace(*ptr)) ! 108: *ptr = '\0'; ! 109: for (ptr = rcbuf; ; ptr++) { ! 110: if (!*ptr) ! 111: continue; ! 112: if (*ptr == '\1') ! 113: break; ! 114: if (++line > LINES) ! 115: xerror("Too many options.\n"); ! 116: if ((rcline[line] = malloc(strlen(ptr) + 1)) == NULL) ! 117: xerror("Not enough memory.\n"); ! 118: argvrc[line] = rcline[line]; ! 119: strcpy(rcline[line], ptr); ! 120: while (*ptr) ! 121: ptr++; ! 122: } ! 123: } ! 124: #else ! 125: getuser(); ! 126: #endif ! 127: myrc = getenv("NEWSRC"); ! 128: if (myrc == NULL) { ! 129: myrc = NEWSRC; ! 130: sprintf(newsrc, "%s/%s", userhome, myrc); ! 131: } else { ! 132: strcpy(newsrc, myrc); ! 133: } ! 134: if (access(newsrc, 0)) ! 135: newrc(newsrc); ! 136: if ((rcfp = fopen(newsrc, "r")) != NULL) { ! 137: rcreadok = FALSE; ! 138: while (fgets(rcbuf, LBUFLEN, rcfp) != NULL) { ! 139: if (!(space = isspace(*rcbuf))) ! 140: optflag = FALSE; ! 141: if (!strncmp(rcbuf, "options ", 8)) ! 142: optflag = TRUE; ! 143: if (optflag) { ! 144: strcat(rcbuf, "\1"); ! 145: if (space) ! 146: ptr = rcbuf - 1; ! 147: else ! 148: ptr = &rcbuf[7]; ! 149: while (*++ptr) ! 150: if (isspace(*ptr)) ! 151: *ptr = '\0'; ! 152: if (space) ! 153: ptr = rcbuf; ! 154: else ! 155: ptr = &rcbuf[8]; ! 156: for (; ; ptr++) { ! 157: if (!*ptr) ! 158: continue; ! 159: if (*ptr == '\1') ! 160: break; ! 161: if (++line > LINES) ! 162: xerror("Too many options.\n"); ! 163: if ((rcline[line] = malloc(strlen(ptr) + 1)) == NULL) ! 164: xerror("Not enough memory.\n"); ! 165: argvrc[line] = rcline[line]; ! 166: strcpy(rcline[line], ptr); ! 167: while (*ptr) ! 168: ptr++; ! 169: } ! 170: } ! 171: } ! 172: fclose(rcfp); ! 173: rcreadok = TRUE; ! 174: } ! 175: if (line != -1) { ! 176: #ifdef DEBUG ! 177: for (i = 0; i <= line; i++) ! 178: fprintf(stderr, "options: %s\n", rcline[i]); ! 179: #endif ! 180: process(line + 2, argvrc); ! 181: do { ! 182: #ifdef DEBUG ! 183: fprintf(stderr, "Freeing %d\n", line); ! 184: #endif ! 185: free(rcline[line]); ! 186: } while (line--); ! 187: } ! 188: ! 189: argv++; ! 190: strcat(header.nbuf, ADMSUB); ! 191: ngcat(header.nbuf); ! 192: process(argc, argv); ! 193: if (!nflag) { ! 194: strcpy(header.nbuf, DFLTSUB); ! 195: ngcat(header.nbuf); ! 196: strcat(header.nbuf, ADMSUB); ! 197: ngcat(header.nbuf); ! 198: } ! 199: if (*header.nbuf) ! 200: lcase(header.nbuf); ! 201: makehimask(header.nbuf, "junk"); ! 202: makehimask(header.nbuf, "control"); ! 203: makehimask(header.nbuf, "test"); ! 204: ! 205: setbuf(stdout, SYSBUF); ! 206: sigtrap = FALSE; /* true if a signal has been caught */ ! 207: if (!pflag && !lflag && !eflag) { ! 208: signal(SIGQUIT, SIG_IGN); ! 209: signal(SIGHUP, onsig); ! 210: signal(SIGINT, onsig); ! 211: signal(SIGPIPE, onsig); ! 212: } ! 213: ! 214: /* ! 215: * ALL of the command line has now been processed. (!) ! 216: */ ! 217: ! 218: if (!*header.nbuf) ! 219: ngcat(strcpy(header.nbuf, DFLTSUB)); ! 220: if (sflag) { ! 221: ngdel(header.nbuf); ! 222: printf("Subscription list: %s\n", header.nbuf); ! 223: xxit(0); ! 224: } ! 225: if (!xflag && (rcfp = xfopen(newsrc, "r"))) { ! 226: while (!sigtrap && fgets(rcbuf, LBUFLEN, rcfp) != NULL) { ! 227: if (!nstrip(rcbuf)) ! 228: xerror(".newsrc line too long"); ! 229: if (++line >= LINES) ! 230: xerror("Too many .newsrc lines"); ! 231: if ((rcline[line] = malloc(strlen(rcbuf) + 1)) == NULL) ! 232: xerror("Not enough memory"); ! 233: strcpy(rcline[line], rcbuf); ! 234: } ! 235: fclose(rcfp); ! 236: } ! 237: actfp = xfopen(ACTIVE, "r"); ! 238: ! 239: #ifdef DEBUG ! 240: fprintf(stderr, "header.nbuf = %s\n", header.nbuf); ! 241: #endif ! 242: switch (mode) { ! 243: case UNKNOWN: ! 244: readr(); ! 245: break; ! 246: #ifdef TMAIL ! 247: case MAIL: ! 248: Mail(); ! 249: break; ! 250: #endif ! 251: } ! 252: fflush(stdout); ! 253: if (xflag || lflag || tflag) ! 254: xxit(0); ! 255: if (*groupdir && mode != MAIL) ! 256: updaterc(); ! 257: writeoutrc(); ! 258: xxit(0); ! 259: ! 260: /* Camel, R.O.H. */ ! 261: } ! 262: ! 263: /* ! 264: * Write out the .newsrc file. We sort it into "active" file order, ! 265: * for speed in future invocations, and to get rid of junk. ! 266: */ ! 267: writeoutrc() ! 268: { ! 269: FILE *rcfp, *actfp; ! 270: char afline[BUFLEN]; ! 271: register int i, c; ! 272: register char *p; ! 273: ! 274: if (!rcreadok) ! 275: return; ! 276: #ifdef VMS ! 277: unlink(newsrc); ! 278: #endif ! 279: ! 280: rcfp = xfopen(newsrc, "w"); ! 281: actfp = xfopen(ACTIVE, "r"); ! 282: ! 283: /* Write out options line, continuations, and comments. */ ! 284: for (i=0; ;i++) { ! 285: c = rcline[i][0]; ! 286: if (c != 'o' && c != '#' && c != ' ' && c != '\t') ! 287: break; ! 288: if (c == 'o' && strncmp(rcline[i], "options", 7) != 0) ! 289: break; ! 290: fprintf(rcfp, "%s\n", rcline[i]); ! 291: } ! 292: ! 293: /* For each newsgroup in active, find that newsrc line and write it out. */ ! 294: while (fgets(afline, sizeof afline, actfp)) { ! 295: p = index(afline, ' '); ! 296: if (p) ! 297: *p = 0; ! 298: i = findrcline(afline); ! 299: if (i >= 0) ! 300: fprintf(rcfp, "%s\n", rcline[i]); ! 301: } ! 302: fclose(rcfp); ! 303: fclose(actfp); ! 304: } ! 305: ! 306: /* ! 307: * Forbid newsgroup ng, unless he asked for it in nbuf. ! 308: */ ! 309: makehimask(nbuf, ng) ! 310: char *nbuf, *ng; ! 311: { ! 312: if (!findex(nbuf, ng)) { ! 313: ngcat(nbuf); ! 314: strcat(nbuf, "!"); ! 315: strcat(nbuf, ng); ! 316: ngcat(nbuf); ! 317: } ! 318: } ! 319: ! 320: /* ! 321: * Return true if the string searchfor is in string, but not if preceeded by !. ! 322: */ ! 323: findex(string, searchfor) ! 324: char *string, *searchfor; ! 325: { ! 326: register char first; ! 327: register char *p; ! 328: ! 329: first = *searchfor; ! 330: for (p=index(string, first); p; p = index(p+1, first)) { ! 331: if (p==string || (p>string && p[-1] != '!' && strncmp(p, searchfor, strlen(searchfor)) == 0)) ! 332: return TRUE; ! 333: } ! 334: return FALSE; ! 335: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.