annotate 3rdparty/packages/uucpbb/src/rnews.c @ 3140:03b580a02945

Allow CoCo3FPGA-specific build of superdesc.asm Added new conditional CC3FPGA and code to "level1/modules/superdesc.asm" to reflect changes needed to build the new SD card descriptors for the Coco3FPGA.
author Bill Pierce <merlinious999@gmail.com>
date Sat, 04 Feb 2017 11:06:26 +0100
parents c4c7facbd082
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1772
5ba8e711a1a3 source added
boisy
parents:
diff changeset
1 /* rnews.c --This is the main program to process and distribute Usenet news.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
2 Copyright (C) 1994 Brad Spencer
5ba8e711a1a3 source added
boisy
parents:
diff changeset
3
5ba8e711a1a3 source added
boisy
parents:
diff changeset
4 This file is part of the OS-9 UUCP package, UUCPbb.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
5
5ba8e711a1a3 source added
boisy
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
5ba8e711a1a3 source added
boisy
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
5ba8e711a1a3 source added
boisy
parents:
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
5ba8e711a1a3 source added
boisy
parents:
diff changeset
9 (at your option) any later version.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
10
5ba8e711a1a3 source added
boisy
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
5ba8e711a1a3 source added
boisy
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5ba8e711a1a3 source added
boisy
parents:
diff changeset
14 GNU General Public License for more details.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
15
5ba8e711a1a3 source added
boisy
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
5ba8e711a1a3 source added
boisy
parents:
diff changeset
17 along with this program; if not, write to the Free Software
5ba8e711a1a3 source added
boisy
parents:
diff changeset
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
19
5ba8e711a1a3 source added
boisy
parents:
diff changeset
20 The author of UUCPbb, Bob Billson, can be contacted at:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
21 bob@kc2wz.bubble.org or uunet!kc2wz!bob or by snail mail:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
22 21 Bates Way, Westfield, NJ 07090
5ba8e711a1a3 source added
boisy
parents:
diff changeset
23 */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
24
5ba8e711a1a3 source added
boisy
parents:
diff changeset
25 /* main function */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
26
5ba8e711a1a3 source added
boisy
parents:
diff changeset
27 #define MAIN
5ba8e711a1a3 source added
boisy
parents:
diff changeset
28 #include "uucp.h"
5ba8e711a1a3 source added
boisy
parents:
diff changeset
29 #include "rnews.h"
5ba8e711a1a3 source added
boisy
parents:
diff changeset
30 #include "mbuf.h"
5ba8e711a1a3 source added
boisy
parents:
diff changeset
31 #include "getopt.h"
5ba8e711a1a3 source added
boisy
parents:
diff changeset
32 #include <direct.h>
5ba8e711a1a3 source added
boisy
parents:
diff changeset
33
5ba8e711a1a3 source added
boisy
parents:
diff changeset
34 QQ int debuglvl = 0;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
35 struct mbuf *getgroups();
5ba8e711a1a3 source added
boisy
parents:
diff changeset
36
2106
c4c7facbd082 Fixed up some warnings
boisy
parents: 1772
diff changeset
37 int main(argc,argv)
1772
5ba8e711a1a3 source added
boisy
parents:
diff changeset
38 int argc;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
39 char *argv[];
5ba8e711a1a3 source added
boisy
parents:
diff changeset
40 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
41 char lbuf[512], buf[BIGBUF], filename[100], initng[100];
5ba8e711a1a3 source added
boisy
parents:
diff changeset
42 struct fildes fdes;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
43 FILE *batchfile;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
44 int savein, saveout, fd, pipefd;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
45 char *bigbuf;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
46 int e,p,option,zflag=0;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
47 struct mbuf *g,*gg;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
48 long length = -1;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
49
5ba8e711a1a3 source added
boisy
parents:
diff changeset
50 initng[0] = '\0';
5ba8e711a1a3 source added
boisy
parents:
diff changeset
51
5ba8e711a1a3 source added
boisy
parents:
diff changeset
52 #ifndef _OSK
5ba8e711a1a3 source added
boisy
parents:
diff changeset
53 pflinit();
5ba8e711a1a3 source added
boisy
parents:
diff changeset
54 #endif
5ba8e711a1a3 source added
boisy
parents:
diff changeset
55
5ba8e711a1a3 source added
boisy
parents:
diff changeset
56 /* On the CC3 there seems to be a bit of arcane lore that is needed to
5ba8e711a1a3 source added
boisy
parents:
diff changeset
57 make setbuf() work without crashing on exit. This malloc is part of
5ba8e711a1a3 source added
boisy
parents:
diff changeset
58 what I discovered to work. */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
59
5ba8e711a1a3 source added
boisy
parents:
diff changeset
60 if ((bigbuf = (char *) malloc (BUFSIZ+16)) == NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
61 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
62 fprintf (stderr, "Can't allocate file buffer\n");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
63 exit(207);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
64 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
65
5ba8e711a1a3 source added
boisy
parents:
diff changeset
66 /* I suppose that this is true */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
67 if (getuid() != 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
68 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
69 fprintf (stderr,"Must be root\n");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
70 exit (214);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
71 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
72
5ba8e711a1a3 source added
boisy
parents:
diff changeset
73 while (((option = getopt (argc, argv, "x:n:mz?")) != NONOPT)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
74 || optarg != NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
75 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
76 switch (option)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
77 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
78 /* Set the debug level */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
79 case 'x':
5ba8e711a1a3 source added
boisy
parents:
diff changeset
80 debuglvl = atoi (optarg);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
81 break;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
82
5ba8e711a1a3 source added
boisy
parents:
diff changeset
83 /* Set a newsgroup that is forced, if this is just a single
5ba8e711a1a3 source added
boisy
parents:
diff changeset
84 article */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
85 case 'n':
5ba8e711a1a3 source added
boisy
parents:
diff changeset
86 strcpy (initng, optarg);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
87 break;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
88
5ba8e711a1a3 source added
boisy
parents:
diff changeset
89 /* Force logging to standard output with no reguard to the
5ba8e711a1a3 source added
boisy
parents:
diff changeset
90 debugging level */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
91 case 'z':
5ba8e711a1a3 source added
boisy
parents:
diff changeset
92 zflag++;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
93 break;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
94
5ba8e711a1a3 source added
boisy
parents:
diff changeset
95 /* Must be the file to process */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
96 case NONOPT:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
97 strcpy (filename, optarg);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
98 break;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
99
5ba8e711a1a3 source added
boisy
parents:
diff changeset
100 case '?': /* Help */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
101 default:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
102 usage();
5ba8e711a1a3 source added
boisy
parents:
diff changeset
103 break;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
104 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
105 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
106
5ba8e711a1a3 source added
boisy
parents:
diff changeset
107 if (getparam() == FALSE)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
108 exit (ABORT);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
109
5ba8e711a1a3 source added
boisy
parents:
diff changeset
110 if ((logdir = getenv ("LOGDIR")) != NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
111 logdir = strdup (logdir);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
112 else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
113 logdir = LOGDIR;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
114
5ba8e711a1a3 source added
boisy
parents:
diff changeset
115 if ((newsdir = getdirs ("newsdir")) == NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
116 fatal ("newsdir not in Parameters");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
117
5ba8e711a1a3 source added
boisy
parents:
diff changeset
118 /* Set up the log file. The fprintf below is important, as it makes sure
5ba8e711a1a3 source added
boisy
parents:
diff changeset
119 that standard error has been opened */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
120
5ba8e711a1a3 source added
boisy
parents:
diff changeset
121 if (zflag || debuglvl > 4)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
122 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
123 fprintf (stderr, "\nLogging to stderr\n");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
124 inizlog ("rnews", 3);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
125 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
126 else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
127 inizlog ("rnews", 1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
128
5ba8e711a1a3 source added
boisy
parents:
diff changeset
129 /* Get the groups from the active file */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
130 g = getgroups();
5ba8e711a1a3 source added
boisy
parents:
diff changeset
131
5ba8e711a1a3 source added
boisy
parents:
diff changeset
132 if (debuglvl > 5)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
133 for (gg = g; gg != NULL; gg = gg->mbuf_next)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
134 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
135 sprintf (lbuf, "ACTIVE IN: %s, %d, %d",
5ba8e711a1a3 source added
boisy
parents:
diff changeset
136 ((struct groups *)gg->cbuf)->name,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
137 ((struct groups *)gg->cbuf)->min,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
138 ((struct groups *)gg->cbuf)->max);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
139 log (lbuf);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
140 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
141
5ba8e711a1a3 source added
boisy
parents:
diff changeset
142 /* Got to be able to open the file */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
143 if ((fd = open (filename, 1)) < 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
144 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
145 sprintf (lbuf, "Can't open '%s'", filename);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
146 log (lbuf);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
147 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
148 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
149
5ba8e711a1a3 source added
boisy
parents:
diff changeset
150 if (debuglvl > 3)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
151 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
152 sprintf (lbuf, "Opened '%s'", filename);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
153 log (lbuf);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
154 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
155
5ba8e711a1a3 source added
boisy
parents:
diff changeset
156 /* Hopefully the first bit of the file will tell us what sort of
5ba8e711a1a3 source added
boisy
parents:
diff changeset
157 thing it is */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
158
5ba8e711a1a3 source added
boisy
parents:
diff changeset
159 if ((e = read (fd, buf, BUFSIZ-1)) <= 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
160 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
161 sprintf (lbuf, "Can't read from '%s'", filename);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
162 log (lbuf);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
163 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
164 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
165
5ba8e711a1a3 source added
boisy
parents:
diff changeset
166 /* Ok, it seems to be a compressed file, possibly batched */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
167 if (strncmp (buf, "#! cunbatch", 11) == 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
168 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
169 if (debuglvl > 1)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
170 log ("A compressed news file");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
171
5ba8e711a1a3 source added
boisy
parents:
diff changeset
172 /* Ok, move to the proper place in the file to begin decompression
5ba8e711a1a3 source added
boisy
parents:
diff changeset
173 */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
174
5ba8e711a1a3 source added
boisy
parents:
diff changeset
175 lseek (fd, 12l, 0);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
176
5ba8e711a1a3 source added
boisy
parents:
diff changeset
177 /* Save stdin, stdout and close the originals */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
178 savein = dup (0);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
179 saveout = dup (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
180 close (0);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
181 close (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
182
5ba8e711a1a3 source added
boisy
parents:
diff changeset
183 /* Try making the file's fd stdin, fail if we can't */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
184 if (dup (fd) != 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
185 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
186 log ("Can't dup fd 0");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
187 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
188 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
189
5ba8e711a1a3 source added
boisy
parents:
diff changeset
190 /* The pipe better be stdout !!! */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
191
5ba8e711a1a3 source added
boisy
parents:
diff changeset
192 if ((pipefd = open ("/pipe", 3)) != 1)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
193 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
194 log ("Can't open /pipe");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
195 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
196 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
197
5ba8e711a1a3 source added
boisy
parents:
diff changeset
198 /* Fork compress, complain otherwise */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
199 if ((p = os9fork ("compress", 3, "-d\n", 0, 0, 0)) < 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
200 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
201 log ("Could not fork compress");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
202 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
203 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
204
5ba8e711a1a3 source added
boisy
parents:
diff changeset
205 /* Increase my priority, hopefully, above compress.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
206
5ba8e711a1a3 source added
boisy
parents:
diff changeset
207 The theory is that we will spend most of our time processing and
5ba8e711a1a3 source added
boisy
parents:
diff changeset
208 writing the article file, rather then reading from the pipe.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
209 And when we read from the pipe, we aren't doing anything else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
210 anyway [i.e. possibly sleeping on I/O]. So, don't take up CPU
5ba8e711a1a3 source added
boisy
parents:
diff changeset
211 time on compress, because it will be given the CPU when needed
5ba8e711a1a3 source added
boisy
parents:
diff changeset
212 anyway. This may all be nuts, however....
5ba8e711a1a3 source added
boisy
parents:
diff changeset
213
5ba8e711a1a3 source added
boisy
parents:
diff changeset
214 I've noted that making the priority the same makes for terrible
5ba8e711a1a3 source added
boisy
parents:
diff changeset
215 performance */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
216
5ba8e711a1a3 source added
boisy
parents:
diff changeset
217 setpr (getpid(), 200);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
218 setpr (p, 100);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
219
5ba8e711a1a3 source added
boisy
parents:
diff changeset
220 /* It is important to close the file, on our side, or the end of
5ba8e711a1a3 source added
boisy
parents:
diff changeset
221 file on the pipe won't be detected. */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
222
5ba8e711a1a3 source added
boisy
parents:
diff changeset
223 close (0);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
224
5ba8e711a1a3 source added
boisy
parents:
diff changeset
225 /* Unredirect the file descriptors. More arcane stuff, you really
5ba8e711a1a3 source added
boisy
parents:
diff changeset
226 shouldn't have to do this */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
227
5ba8e711a1a3 source added
boisy
parents:
diff changeset
228 pipefd = dup (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
229 close (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
230 dup (savein);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
231 dup (saveout);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
232
5ba8e711a1a3 source added
boisy
parents:
diff changeset
233 /* Make a FILE pointer for the pipefd */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
234 if ((batchfile = fdopen (pipefd, "r+")) == NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
235 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
236 log ("Couldn't fdopen the pipe fd");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
237 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
238 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
239 setbuf (batchfile, bigbuf);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
240
5ba8e711a1a3 source added
boisy
parents:
diff changeset
241 /* Get the first line, which may indicate that this is a batch of
5ba8e711a1a3 source added
boisy
parents:
diff changeset
242 articles */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
243
5ba8e711a1a3 source added
boisy
parents:
diff changeset
244 if (getline (batchfile, buf) == -1)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
245 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
246 log ("Nothing on the pipe");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
247 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
248 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
249 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
250 else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
251 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
252 /* Must not be compressed. This is also the place where one might
5ba8e711a1a3 source added
boisy
parents:
diff changeset
253 process other compression schemes, like lha. In general, one
5ba8e711a1a3 source added
boisy
parents:
diff changeset
254 should check for each type of compression before assuming that
5ba8e711a1a3 source added
boisy
parents:
diff changeset
255 the file is uncompressed */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
256
5ba8e711a1a3 source added
boisy
parents:
diff changeset
257 if (debuglvl > 1)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
258 log ("An uncompressed news file");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
259
5ba8e711a1a3 source added
boisy
parents:
diff changeset
260 /* Rewind the file and get the size, so we can pass it along, if
5ba8e711a1a3 source added
boisy
parents:
diff changeset
261 needed */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
262
5ba8e711a1a3 source added
boisy
parents:
diff changeset
263 lseek (fd, 0l, 0);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
264
5ba8e711a1a3 source added
boisy
parents:
diff changeset
265 if (_gs_gfd (fd, &fdes, sizeof (fdes)) != -1)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
266 length = (long)fdes.fd_fsize;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
267
5ba8e711a1a3 source added
boisy
parents:
diff changeset
268 /* Make a FILE pointer out of the file fd, instead of the pipe, as
5ba8e711a1a3 source added
boisy
parents:
diff changeset
269 above */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
270
5ba8e711a1a3 source added
boisy
parents:
diff changeset
271 if ((batchfile = fdopen (fd, "r")) == NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
272 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
273 log ("Can't fdopen news file");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
274 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
275 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
276 setbuf (batchfile, bigbuf);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
277
5ba8e711a1a3 source added
boisy
parents:
diff changeset
278 /* Get a line, which could mean that this is a batch of articles */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
279 getline (batchfile, buf);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
280 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
281
5ba8e711a1a3 source added
boisy
parents:
diff changeset
282 /* Ok, we seem to have a batch of articles. Process them, as such */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
283
5ba8e711a1a3 source added
boisy
parents:
diff changeset
284 if (strncmp (buf, "#! rnews ", 9) == 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
285 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
286 if (debuglvl > 1)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
287 log ("A batch of news articles");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
288
5ba8e711a1a3 source added
boisy
parents:
diff changeset
289 procbatch (batchfile, buf, g);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
290 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
291 else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
292 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
293 /* Not a batch of articles, assume that it is a single article */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
294 if (debuglvl > 1)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
295 log ("A single news article");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
296
5ba8e711a1a3 source added
boisy
parents:
diff changeset
297 procart (batchfile, buf, initng, g, length);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
298 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
299
5ba8e711a1a3 source added
boisy
parents:
diff changeset
300 /* Put the updated active file back */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
301 if (debuglvl > 3)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
302 log ("Updating active file");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
303
5ba8e711a1a3 source added
boisy
parents:
diff changeset
304 putgroups (g);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
305
5ba8e711a1a3 source added
boisy
parents:
diff changeset
306 /* Clean things up */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
307 if (debuglvl > 4)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
308 log ("Exiting.....");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
309
5ba8e711a1a3 source added
boisy
parents:
diff changeset
310 fclose (batchfile);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
311 close (pipefd);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
312 close (fd);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
313 wait (0);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
314
5ba8e711a1a3 source added
boisy
parents:
diff changeset
315 /* Close up the log */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
316 deinizlog();
5ba8e711a1a3 source added
boisy
parents:
diff changeset
317 exit (0);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
318 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
319
5ba8e711a1a3 source added
boisy
parents:
diff changeset
320
5ba8e711a1a3 source added
boisy
parents:
diff changeset
321
5ba8e711a1a3 source added
boisy
parents:
diff changeset
322 /* Cheap fatal */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
323
5ba8e711a1a3 source added
boisy
parents:
diff changeset
324 int fatal (s)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
325 char *s;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
326 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
327 fprintf (stderr, "'%s'\n");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
328 exit (ABORT);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
329 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
330
5ba8e711a1a3 source added
boisy
parents:
diff changeset
331
5ba8e711a1a3 source added
boisy
parents:
diff changeset
332
5ba8e711a1a3 source added
boisy
parents:
diff changeset
333 /* Cheaper usage */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
334
5ba8e711a1a3 source added
boisy
parents:
diff changeset
335 int usage()
5ba8e711a1a3 source added
boisy
parents:
diff changeset
336 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
337 fprintf (stderr,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
338 "rnews [-x debug_level] [-n inital_newsgroup] [-z] newsfile\n");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
339 exit (1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
340 }