Annotation of researchv10no/cmd/netnews/src/sendnews.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * sendnews - send news article by mail.
        !             3:  */
        !             4: 
        !             5: static char *SccsId = "@(#)sendnews.c  2.6     5/4/83";
        !             6: 
        !             7: #include <stdio.h>
        !             8: #include <ctype.h>
        !             9: #ifndef USG
        !            10: struct utsname {
        !            11:        char    Sysname[9];
        !            12:        char    nodename[33];
        !            13:        char    release[9];
        !            14:        char    version[9];
        !            15: };
        !            16: #else
        !            17: #include <sys/utsname.h>
        !            18: #endif
        !            19: 
        !            20: #define        eq(a,b) (strcmp(a,b) == 0)
        !            21: #define        LNLEN   7                       /* strlen("ucbvax!") */
        !            22: 
        !            23: char *index();
        !            24: char buffer[BUFSIZ];
        !            25: int linecount, oflag = 0, aflag = 0, bflag = 0, toflag = 0;
        !            26: 
        !            27: FILE *popen();
        !            28: main(argc, argv)
        !            29: char **argv;
        !            30: {
        !            31:        FILE *out;
        !            32:        char sender[BUFSIZ],newsgroup[100];
        !            33:        char *punct;
        !            34:        char sysn[20];
        !            35:        int sysnl;
        !            36:        char *bnkludge;
        !            37:        struct utsname ubuf;
        !            38: 
        !            39:        while (**(++argv) == '-') {
        !            40:                if (*++*argv == 'o')
        !            41:                        oflag++;
        !            42:                else if (**argv == 'a')
        !            43:                        aflag++;
        !            44:                else if (**argv == 'b')
        !            45:                        bflag++;
        !            46:                else if (**argv == 'n')
        !            47:                        strcpy(newsgroup, *(++argv));
        !            48:        }
        !            49:        if (aflag && bflag) {
        !            50:                fprintf(stderr, "'-a' and '-b' options mutually exclusive.\n");
        !            51:                exit(1);
        !            52:        }
        !            53: 
        !            54: #ifdef debug
        !            55:        printf("mail %s\n", *argv);
        !            56:        sprintf(buffer, "cat");
        !            57: #else
        !            58:        sprintf(buffer, "mail %s", *argv);
        !            59: #endif
        !            60:        out = popen(buffer, "w");
        !            61:        uname(&ubuf);
        !            62:        strcpy(sysn, ubuf.nodename);
        !            63:        strcat(sysn, "!");
        !            64:        sysnl = strlen(sysn);
        !            65:        bnkludge = "";
        !            66: #ifdef BERKELEY
        !            67:        /*
        !            68:         * ucbvax isn't really on the arpanet, but is berknetted to
        !            69:         * it through ingres.  Hence the following kludge.
        !            70:         */
        !            71:        bnkludge = "ARPAVAX.";
        !            72: #define HOSTNAME "Berkeley"
        !            73: #endif
        !            74: #ifndef HOSTNAME
        !            75: #define HOSTNAME "OuterSpace"
        !            76: #endif
        !            77: 
        !            78:        /* Standard mail prelude to make the formatters happy */
        !            79:        fprintf(out, "To: %s\n", *argv);
        !            80:        fprintf(out, "Subject: network news article\n");
        !            81:        fprintf(out, "\n");
        !            82: 
        !            83:        while (fgets(buffer, sizeof buffer, stdin)) {
        !            84: #ifdef notdef
        !            85:                if (fromline()) {
        !            86:                                if (aflag) {
        !            87:                                        if (!strncmp(buffer, "From ", 5)) {
        !            88:                                                punct = &buffer[4];
        !            89:                                                while (isspace(*punct++))
        !            90:                                                        ;
        !            91:                                                punct--;
        !            92:                                        }
        !            93:                                        else if (!strncmp(buffer, "From: ",6)) {
        !            94:                                                punct = &buffer[6];
        !            95:                                                while (isspace(*punct++))
        !            96:                                                        ;
        !            97:                                                punct--;
        !            98:                                        }
        !            99:                                        else
        !           100:                                                punct = buffer;
        !           101:                                        if (strncmp(punct, sysn, sysnl))
        !           102:                                                printf("Bad from line: '%s'\n", buffer);
        !           103:                                        strcpy(sender, punct+sysnl);
        !           104:                                        sender[strlen(sender)-1] = 0;
        !           105:                                        sprintf(punct, "%s%s@%s\n",
        !           106:                                                bnkludge, sender, HOSTNAME);
        !           107:                                } else if (bflag) {
        !           108:                                        punct = index(buffer, '!');
        !           109:                                        if (punct == NULL)
        !           110:                                                printf("Bad from line: '%s'\n", buffer);
        !           111:                                        else {
        !           112:                                                *punct = ':';   /* berknet mail delimeter */
        !           113:                                                if (!strncmp("From: ", buffer, 6))
        !           114:                                                        punct = &buffer[6];
        !           115:                                                else if (!strncmp("From ",buffer,5))
        !           116:                                                        punct = &buffer[5];
        !           117:                                                else
        !           118:                                                        punct = buffer;
        !           119:                                                fiddle(punct);
        !           120:                                        }
        !           121:                                }
        !           122:                }
        !           123: #endif
        !           124:                if (*newsgroup && ngline()) {
        !           125:                        if (oflag)
        !           126:                                sprintf(buffer, "%s\n", newsgroup);
        !           127:                        else
        !           128:                                sprintf(buffer, "Newsgroups: %s\n", newsgroup);
        !           129:                }
        !           130:                putc('N', out);
        !           131:                fputs(buffer, out);
        !           132:        }
        !           133:        pclose(out);
        !           134:        exit(0);
        !           135: }
        !           136: 
        !           137: fromline() {
        !           138:        if (oflag)
        !           139:                return ++linecount == 3;
        !           140:        if (!linecount && (!strncmp("From: ", buffer, 6) || !strncmp("From ", buffer, 5)))
        !           141:                return ++linecount;
        !           142:        return 0;
        !           143: }
        !           144: 
        !           145: ngline() {
        !           146:        if (oflag)
        !           147:                return linecount == 2;
        !           148:        if (!toflag && (!strncmp("Newsgroups: ", buffer, 12) || !strncmp("To: ",buffer, 4)))
        !           149:                return ++toflag;
        !           150:        return 0;
        !           151: }
        !           152: 
        !           153: /*
        !           154:  * make sure the host name is a correct berknet address, since the
        !           155:  * internal names are not the berknet host names.
        !           156:  */
        !           157: fiddle(buf)
        !           158: char *buf;
        !           159: {
        !           160:        char berkname[10];
        !           161:        char uucpname[100];
        !           162:        char *rest;
        !           163: 
        !           164:        strcpy(uucpname, buf);
        !           165:        rest = index(uucpname, ':');
        !           166:        *rest++ = 0;
        !           167: #ifdef debug
        !           168:        printf("uucpname='%s', buf='%s', rest='%s',...", uucpname, buf, rest);
        !           169: #endif
        !           170:        if (eq(uucpname, "ucbvax"))
        !           171:                strcpy(berkname, "CSVAX");
        !           172:        else if (eq(uucpname, "ucbcory"))
        !           173:                strcpy(berkname, "Cory");
        !           174:        else if (eq(uucpname, "ucbopt"))
        !           175:                strcpy(berkname, "ESVAX");
        !           176:                /*
        !           177:                 * The uucp names from here down are guesswork.
        !           178:                 * They may have to be changed later.  But we can't
        !           179:                 * allow names like a, b, etc to get outside the berknet.
        !           180:                 */
        !           181:        else if (eq(uucpname, "ucbing70"))
        !           182:                strcpy(berkname, "Ing70");
        !           183:        else if (eq(uucpname, "ucbingvax"))
        !           184:                strcpy(berkname, "IngVAX");
        !           185:        else if (eq(uucpname, "ucbcfo_a"))
        !           186:                strcpy(berkname, "A");
        !           187:        else if (eq(uucpname, "ucbcfo_b"))
        !           188:                strcpy(berkname, "B");
        !           189:        else if (eq(uucpname, "ucbcfo_c"))
        !           190:                strcpy(berkname, "C");
        !           191:        else if (eq(uucpname, "ucbcfo_d"))
        !           192:                strcpy(berkname, "D");
        !           193:        else if (eq(uucpname, "ucbcfo_e"))
        !           194:                strcpy(berkname, "E");
        !           195:        else if (eq(uucpname, "ucbcfo_f"))
        !           196:                strcpy(berkname, "F");
        !           197:        else if (eq(uucpname, "ucbcfo_g"))
        !           198:                strcpy(berkname, "G");
        !           199:        else if (eq(uucpname, "ucbeecs40"))
        !           200:                strcpy(berkname, "EECS40");
        !           201:        else if (eq(uucpname, "ucbimage"))
        !           202:                strcpy(berkname, "Image");
        !           203:        else if (eq(uucpname, "ucbsrc"))
        !           204:                strcpy(berkname, "SRC");
        !           205:        else if (eq(uucpname, "ucbarpa"))
        !           206:                strcpy(berkname, "ARPAVAX");
        !           207:        else if (eq(uucpname, "ucbonyx"))
        !           208:                strcpy(berkname, "Onyx");
        !           209:        else if (eq(uucpname, "ucb"))
        !           210:                strcpy(berkname, "C70");
        !           211:        else if (eq(uucpname, "populi"))
        !           212:                strcpy(berkname, "G");
        !           213:        else if (eq(uucpname, "ucbcad"))
        !           214:                strcpy(berkname, "CAD");
        !           215:        else
        !           216:                strcpy(berkname, "UNKNOWN");
        !           217:        sprintf(buf, "%s:%s", berkname, rest);
        !           218: #ifdef debug
        !           219:        printf("berkname='%s', buf='%s'\n", berkname, buf);
        !           220: #endif
        !           221: }
        !           222: 
        !           223: /*
        !           224:  * Return the ptr in sp at which the character c appears;
        !           225:  * NULL if not found
        !           226:  */
        !           227: 
        !           228: char *
        !           229: index(sp, c)
        !           230: register char *sp, c;
        !           231: {
        !           232:        do {
        !           233:                if (*sp == c)
        !           234:                        return(sp);
        !           235:        } while (*sp++);
        !           236:        return(NULL);
        !           237: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.