|
|
1.1 root 1: /*
2: * berknews - send news article via Berknet
3: *
4: * Synopsis:
5: * berknews [-o] [-n newsgroup] host_net_command machine remote_rnews
6: */
7:
8: static char *SccsId = "@(#)berknews.c 2.3 4/26/83";
9:
10: #include <stdio.h>
11: #include <ctype.h>
12: #ifndef USG
13: #include <whoami.h>
14: struct utsname {
15: char Sysname[9];
16: char nodename[33];
17: char release[9];
18: char version[9];
19: };
20: #else
21: #include <sys/utsname.h>
22: #endif
23:
24:
25: struct network {
26: char *uucpname;
27: char *berkname;
28: } berknet[] = {
29: /* UUCP Net Name BerkNet Name
30: ------------- ------------ */
31: "ucbvax", "CSVAX",
32: "populi", "G",
33: "ucbarpa", "ARPAVAX",
34: "ucbcfo-c", "C",
35: "ucbopt", "ESVAX",
36: "ucbcad", "ucbcad",
37: "ucbcory", "Cory",
38: "ucb", "C70",
39: "ucbmathstat", "MathStat",
40: "ucbonyx", "Onyx",
41: "ucbkim", "Kim",
42: "ucbcfo-a", "A",
43: "ucbcfo-b", "B",
44: "ucbcfo-d", "D",
45: "ucbcfo-e", "E",
46: "ucbcfo-f", "F",
47: "ucbingvax", "IngVAX",
48: "ucbingres", "Ingres",
49: "ucbeecs40", "EECS40",
50: "ucbvlsi", "VLSI",
51: "ucbsrc", "SRC",
52: "ucbimage", "Image",
53: '\0', '\0'
54: };
55:
56: char *index();
57: char buffer[BUFSIZ];
58: int linecount;
59:
60: FILE *popen();
61: main(argc, argv)
62: int argc;
63: char **argv;
64: {
65: FILE *out;
66: char sender[BUFSIZ],newsgroup[100];
67: char *punct;
68: char sysn[20];
69: int sysnl;
70: struct utsname ubuf;
71:
72: if (argc < 4) {
73: fprintf(stderr, "Too few arguments.\n");
74: exit(1);
75: }
76:
77: #ifdef debug
78: printf("%s - -m%s %s\n", argv[1], argv[2], argv[3]);
79: sprintf(buffer, "cat");
80: #else
81: sprintf(buffer, "%s - -m%s %s", argv[1], argv[2], argv[3]);
82: #endif
83: out = popen(buffer, "w");
84: uname(&ubuf);
85: strcpy(sysn, ubuf.nodename);
86: strcat(sysn, "!");
87: sysnl = strlen(sysn);
88:
89: while (fgets(buffer, sizeof buffer, stdin)) {
90: if (fromline()) {
91: punct = index(buffer, '!');
92: if (punct == NULL)
93: printf("Bad from line: '%s'\n", buffer);
94: else {
95: *punct = ':'; /* berknet mail delimeter */
96: if (!strncmp("From: ", buffer, 6))
97: punct = &buffer[6];
98: else if (!strncmp("From ",buffer,5))
99: punct = &buffer[5];
100: else
101: punct = buffer;
102: fiddle(punct);
103: }
104: }
105: fputs(buffer, out);
106: }
107: pclose(out);
108: exit(0);
109: }
110:
111: fromline() {
112: if (!linecount && (!strncmp("From: ", buffer, 6) || !strncmp("From ", buffer, 5)))
113: return ++linecount;
114: return 0;
115: }
116:
117: /*
118: * make sure the host name is a correct berknet address, since the
119: * internal names are not the berknet host names.
120: */
121: fiddle(buf)
122: char *buf;
123: {
124: char uucpname[100];
125: register struct network *netptr;
126: char *rest;
127:
128: strcpy(uucpname, buf);
129: rest = index(uucpname, ':');
130: *rest++ = 0;
131: #ifdef debug
132: printf("uucpname = '%s', buf = '%s', rest = '%s'\n", uucpname, buf, rest);
133: #endif
134: for (netptr = &berknet[0]; strcmp(netptr->uucpname, uucpname) && netptr->uucpname; netptr++)
135: ;
136: if (netptr->uucpname)
137: sprintf(buf, "%s:%s", netptr->berkname, rest);
138: else
139: sprintf(buf, "UNKNOWN:%s", rest);
140: }
141:
142: /*
143: * Return the ptr in sp at which the character c appears;
144: * NULL if not found
145: */
146:
147: char *
148: index(sp, c)
149: register char *sp, c;
150: {
151: do {
152: if (*sp == c)
153: return(sp);
154: } while (*sp++);
155: return(NULL);
156: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.