home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / de / comp / sources / os9 / 3 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  45.4 KB

  1. Xref: sparky de.comp.sources.os9:3 comp.os.os9:1545
  2. Path: sparky!uunet!cs.utexas.edu!sun-barr!news2me.EBay.Sun.COM!seven-up.East.Sun.COM!sungy!stasys!stasys!not-for-mail
  3. From: frank.kaefer@stasys.sta.sub.org (Frank Kaefer)
  4. Newsgroups: de.comp.sources.os9,comp.os.os9
  5. Subject: MNews Prerelease Part07/09
  6. Message-ID: <1hafdmINNpth@stasys.sta.sub.org>
  7. Date: 23 Dec 92 19:41:42 GMT
  8. Sender: news@stasys.sta.sub.org
  9. Followup-To: de.comp.sources.d
  10. Organization: Stasys News Server, Starnberg, Germany
  11. Lines: 1962
  12. Approved: frank.kaefer@stasys.sta.sub.org (Frank Kaefer)
  13. NNTP-Posting-Host: stasys.sta.sub.org
  14.  
  15. Submitted-by: Ulrich Dessauer <ud@Nightmare.ddt.sub.org>
  16. Archive-name: mnews/part07
  17.  
  18. : ----- Cut here ----- Cut here ----- Cut here ----- Cut here -----
  19. : Use  sh filename  to extract shell archive
  20. : This shell archive contains following files:
  21. :     'MAN/News_in.prf                               666 bytes'
  22. :     'MAN/News_out.prf                              448 bytes'
  23. :     'MAN/Rnews.prf                                 680 bytes'
  24. :     'MAN/Sbatch.prf                               2299 bytes'
  25. :     'MAN/Sys.prf                                  3156 bytes'
  26. :     'MISC/Makefile                                 912 bytes'
  27. :     'MISC/decode.c                                3366 bytes'
  28. :     'MISC/delold.c                                2730 bytes'
  29. :     'MISC/encode.c                                3063 bytes'
  30. :     'MISC/news_in.c                               1585 bytes'
  31. :     'MISC/news_out.c                              3113 bytes'
  32. :     'MISC/nstat.c                                 9149 bytes'
  33. :     'MISC/rot13.c                                 1040 bytes'
  34. :     'MISC/unmap.c                                 2012 bytes'
  35. :     'RNEWS/Makefile                                453 bytes'
  36. :     'RNEWS/compr.c                                4277 bytes'
  37. if test -f 'MAN/News_in.prf' ; then
  38.   echo 'File MAN/News_in.prf already exists, overwriting it'
  39.   del 'MAN/News_in.prf'
  40. fi
  41. echo Extracting \"'MAN/News_in.prf'\"
  42. sed "s/^X//" >'MAN/News_in.prf' <<'__END__OF__THIS__FILE__'
  43. X.THS News_in 8L News
  44. X.SH NAME
  45. X$N - gateways incoming mails to news.
  46. X.SH SYNOPSIS
  47. X$N [-f=<sender>] <newsgroup>
  48. X.SH DESCRIPTION
  49. XIn combination with
  50. X.B News_out
  51. X$N can be used to forward news as mails and to allow answering to an
  52. Xarticle via mail. For this you need a flexible mail transport agent,
  53. Xe.g. sendmail or MMail. The
  54. X.B <sender>
  55. Xis optional and currently not used.
  56. X.B <newsgroup>
  57. Xmust be a valid newsgroup either with dots or with hyphens. Valid
  58. Xnewsgroups are then (e.g.) comp-lang-c or rec.games.frp. The hyphen
  59. Xsolution is used to avoid a miss-parsing the dots as domains.
  60. X.SH CAVEATS
  61. XThis is only a very primitiv solution and may cause several problems.
  62. X
  63. __END__OF__THIS__FILE__
  64. if test -f 'MAN/News_out.prf' ; then
  65.   echo 'File MAN/News_out.prf already exists, overwriting it'
  66.   del 'MAN/News_out.prf'
  67. fi
  68. echo Extracting \"'MAN/News_out.prf'\"
  69. sed "s/^X//" >'MAN/News_out.prf' <<'__END__OF__THIS__FILE__'
  70. X.THS News_out 8L News
  71. X.SH NAME
  72. X$N - gateways incoming news to mail.
  73. X.SH SYNOPSIS
  74. X$N <receiver>
  75. X.SH DESCRIPTION
  76. XIn combination with
  77. X.B News_in
  78. X$N can be used to forward news as mails and to allow answering to an
  79. Xarticle via mail. $N tries to set the
  80. X.B Reply-To:
  81. Xline to a valid name (<group>\@newsgroup.<local-domain>) to allow a
  82. Xsimple answer posting by the user.
  83. X.SH CAVEATS
  84. XThis is only a very primitiv solution and may cause several problems.
  85. X
  86. __END__OF__THIS__FILE__
  87. if test -f 'MAN/Rnews.prf' ; then
  88.   echo 'File MAN/Rnews.prf already exists, overwriting it'
  89.   del 'MAN/Rnews.prf'
  90. fi
  91. echo Extracting \"'MAN/Rnews.prf'\"
  92. sed "s/^X//" >'MAN/Rnews.prf' <<'__END__OF__THIS__FILE__'
  93. X.THS Rnews 8L News
  94. X.SH NAME
  95. XRnews - Receive batched Articles from remote System
  96. X.SH SYNOPSIS
  97. Xrnews [-d=<dbglvl>] [<file>]
  98. X.SH DESCRIPTION
  99. X.ti +3
  100. XRnews is called by a remote system to unpack the received news article
  101. Xand feed them to Inews.  If Inews failed for any reasons, rnews will
  102. Xstore this article in
  103. X.B /h0/SPOOL/RNEWS
  104. X(or whereever set using Sysinfo).
  105. X.SH FILES
  106. X.O /h0/SPOOL/RNEWS
  107. XStore failed article there.
  108. X.NO /h0/SPOOL/UUCP/.LOG/rnews.log
  109. XThe logfile, will only be written if existing.
  110. X.EO
  111. X.SH SYSINFO
  112. X.O RNEWS.DIR,s=/h0/SPOOL/RNEWS
  113. XSets the directory where failed article should be placed
  114. X.EO
  115. X.SH SEE ALSO
  116. X Inews - in this distribution
  117. X Sbatch - in this distribution
  118. __END__OF__THIS__FILE__
  119. if test -f 'MAN/Sbatch.prf' ; then
  120.   echo 'File MAN/Sbatch.prf already exists, overwriting it'
  121.   del 'MAN/Sbatch.prf'
  122. fi
  123. echo Extracting \"'MAN/Sbatch.prf'\"
  124. sed "s/^X//" >'MAN/Sbatch.prf' <<'__END__OF__THIS__FILE__'
  125. X.THS Sbatch 8L News
  126. X.SH NAME
  127. XSbatch - Collect and batch News article for remote system
  128. X.SH SYNOPSIS
  129. X.raw
  130. Xsbatch [-c|-c7|-cf|-cf7|-b|-s] [-B=<size>] [-t]
  131. X       [-G=<grade>] [-f=<size>] [-C=<cmd>] [-n=<system>]
  132. X       <system>
  133. X.noraw
  134. X.SH DESCRIPTION
  135. X.ti +3
  136. XSbatch collects all article which should be send to a remote system.
  137. XOn default all articles are batched into one file until the size limit
  138. Xis reached. With
  139. X.O -c
  140. Xyou can compress the news to get a better throughput.
  141. X.NO -cf
  142. Xforces `freeze' to be used instead of compresss.
  143. X.NO -c7
  144. Xwill encode them after compression to transmit them over lines which
  145. Xonly supports 7 Bit.
  146. X.NO -cf7
  147. Xwill be used for 7 Bit channels with `freeze' to compress data.
  148. X.NO -s
  149. Xall articles are spooled as single files.
  150. X.NO -f=<size>
  151. Xgives the limit of a file in kBytes. the default is 50 kByte. 
  152. X.NO -B=<bitcount>
  153. XTo compress with another bitvalue than 16 (the default, use the option
  154. Xto set the bitvalue to 12 to 16. 
  155. X.NO -G=<grade>
  156. XIf your delivering program accepts a grade character in the command
  157. Xstring then you can change this here. 
  158. X.NO -C=<cmd>
  159. Xthe delivery command can be changed with this to a complete new value. 
  160. XThe command may contain two different sequences for inserting the grade
  161. Xcharacter and the system name.  These are
  162. X.bold
  163. X\%S
  164. Xfor the system and
  165. X.bold
  166. X\%G
  167. Xfor the grading.
  168. X.NO -t
  169. Xthis is for use with eight bit characters. If your neighbor host doesn't
  170. Xsupport these characters then they are translated back to pure seven bit
  171. XASCII. Currently only the german umlaute for ISO8859/1 are supported.
  172. X.NO -n=<system>
  173. XIf the name in the command to forward news differs from the filename the
  174. Xbatchfile is stored then this is used as the filename of the batched
  175. Xarticles.
  176. X.EO
  177. X.SH CAVEATS
  178. XThe files are stored in temporary on /dd. If this too small things may
  179. Xfail.
  180. X.SH BUGS
  181. XMay be a lot, none known.
  182. X.SH FILES
  183. X.O /h0/SPOOL/BATCH
  184. XThe articles are stored herein, for each system one file with the
  185. Xfilename of the system. The format is an optional flagfield seperated
  186. Xfrom the main filename by a bar
  187. X.RB (` | ').
  188. XCurrently there are the two flags
  189. X.RB ` N '
  190. Xand
  191. X.RB ` C '
  192. Xfor non-convert and convert from 8 bit (if these optiones are proper
  193. Xinserted the `-t' option is obsolete.)
  194. X.EO
  195. X.SH SEE ALSO
  196. X Inews - in this distribution
  197. X Rnews - in this distribution
  198. __END__OF__THIS__FILE__
  199. if test -f 'MAN/Sys.prf' ; then
  200.   echo 'File MAN/Sys.prf already exists, overwriting it'
  201.   del 'MAN/Sys.prf'
  202. fi
  203. echo Extracting \"'MAN/Sys.prf'\"
  204. sed "s/^X//" >'MAN/Sys.prf' <<'__END__OF__THIS__FILE__'
  205. X.THS Sys 5L News
  206. X.SH NAME
  207. XSys - this file describes the mechanism to forward received articles to
  208. Xother sites or to programs.
  209. X.SH DESCRIPTION
  210. X.ti +3
  211. XThis files specifies the newsgroups and distributions to be forwarded to
  212. Xanother site or to be pipe'd to a program. So you are able to limit the
  213. Xamount of articles to be forwarded by area (distribution) or/and the
  214. Xtopics (newsgroups).
  215. X.SH FORMAT
  216. XThe format of the file is
  217. X.ce
  218. X<system>{> <flags>}:<newsgroups>:<dists>{:<program>}
  219. Xwhere
  220. X.B <system>
  221. Xis in general the system to forward the news (or an ID for programs).
  222. XYou can append a list of other systemnames (seperated by a slash
  223. X.B /
  224. Xform the main system), which are seperated by commas to stop forwarding
  225. Xarticles which had already passed these systems. The
  226. X.B <flags>
  227. Xare a list of flags which are inserted before the filename in the
  228. Xbatchfile. These flags are interpreted by sbatch only. The
  229. X.B <newsgroups>
  230. Xis a list of newsgroups which are in regular expression format (using
  231. XHenry Spencer's regular expression library), seperated by spaces.
  232. XInternal the expression will be enclosed with
  233. X.B ^
  234. Xand
  235. X.bold
  236. X\$
  237. Xto allow only exact matches.
  238. X.B <dists>
  239. Xare the distributions which aren't regular expressions, but they may
  240. Xcontain the meta characters
  241. X.B ?
  242. Xand
  243. X.B *
  244. Xto match one (?) or zero or more (*) characters. The <newsgroups> and
  245. X<dists> field allow a not operation by prefixing an expression with an
  246. X.B !
  247. Xso you can select specific items not to be forwarded. If an article
  248. Xshould be forwarded the filename is written in a file in
  249. X.B /h0/SPOOL/BATCH
  250. Xwith the filename equal to <system> (if possible). This file is used by
  251. X.B sbatch
  252. Xto send the articles themselves.
  253. X.PP
  254. XThe
  255. X.B <program>
  256. Xis optional but if it is given the filename of the article isn't written
  257. Xto the file mentioned above but the article itself is pipe'd to this
  258. Xprogram (so the program must read the article from stdin).
  259. X.PP
  260. XIf the first character of <program> is a plus sign then the rest will be
  261. Xused as a full path to a directory where to store the articles with
  262. Xincreasing numbers. If the first character is a minus sign then the rest
  263. Xis a full path to a directory which is used instead of the batch
  264. Xdirectory (/h0/SPOOL/BATCH).
  265. X.PP
  266. XEach line in this file may be continued in the next line if the last
  267. Xcharacter in the prvious line had been a backslash.
  268. X.PP
  269. XIf a line starts with a colon
  270. X.RB ( : )
  271. Xthen the rest of the line is taken as a filename of a file to be
  272. Xincluded.  With this features it is possible to create one file for each
  273. Xsystem which can be changed from remote via mail.  For this purpose the
  274. Xprogram
  275. X.B remsys
  276. Xcan be found in this distribution.
  277. X.SH EXAMPLES
  278. X.raw 4
  279. Xmyfeed:!local.* to\\.myfeed !to\\..* .*:!local *
  280. Xsubfeed:(sub|muc)\\..*:sub muc world
  281. Xsave:.*source.*:*:save_it
  282. X.noraw
  283. X.B myfeed
  284. Xwill get everything expect these newsgroups which are prefixed by
  285. X.B local
  286. Xor have distribution
  287. X.B local
  288. Xor have the prefix
  289. X.B to.
  290. Xand not followed by myfeed.
  291. X.B subfeed
  292. Xwill only receive groups of a local are (Newsgroups prefixed by muc. or
  293. Xsub. and distribution muc sub and world). The entry
  294. X.B save
  295. Xwill store (assuming a proper program) all articles in source groups.
  296. __END__OF__THIS__FILE__
  297. if test -f 'MISC/Makefile' ; then
  298.   echo 'File MISC/Makefile already exists, overwriting it'
  299.   del 'MISC/Makefile'
  300. fi
  301. echo Extracting \"'MISC/Makefile'\"
  302. sed "s/^X//" >'MISC/Makefile' <<'__END__OF__THIS__FILE__'
  303. X# $Id: Makefile_v 1.1.1.1 90/09/08 16:08:49 ud Exp $
  304. X# $Log:    Makefile_v $
  305. X# Revision 1.1.1.1  90/09/08  16:08:49  ud
  306. X# Insert entry for delold
  307. X# 
  308. X# Revision 1.1  90/08/31  15:28:34  cv
  309. X# Initial revision
  310. X# 
  311. X#
  312. XCC=    cc
  313. XG=    -g
  314. XCFLAGS=    -qt=/dd/TMP $G -v=.. -v=../8BIT
  315. XLIBS=    -l=/dd/LIB/os9lib.l
  316. XLFLAGS=    -q $(LIBS) $G
  317. XODIR=    /h0/ETC/CMDS
  318. X
  319. Xencode:    encode.r
  320. X
  321. Xdecode:    decode.r
  322. X
  323. Xdelold:    delold.r
  324. X    $(CC) $(LFLAGS) delold.r -f=$(ODIR)/$@ -m=50
  325. X    fixmod -uo2.39 $(ODIR)/$@
  326. X
  327. Xunmap:    unmap.r
  328. X    $(CC) $(LFLAGS) unmap.r -f=$(ODIR)/$@
  329. X    fixmod -uo90.91 $(ODIR)/unmap
  330. X
  331. Xnews_in:    news_in.r
  332. X    $(CC) $(LFLAGS) news_in.r -f=$(ODIR)/$@
  333. X    fixmod -uo2.39 $(ODIR)/$@
  334. X
  335. Xnews_out:    news_out.r
  336. X    $(CC) $(LFLAGS) news_out.r -f=$(ODIR)/$@ -l=/dd/LIB/8bit.l
  337. X    fixmod -uo2.39 $(ODIR)/$@
  338. X
  339. Xrot13:    rot13.r
  340. X    $(CC) $(LFLAGS) rot13.r -f=$(ODIR)/$@ -l=/dd/LIB/8bit.l
  341. X
  342. Xnstat:    nstat.r
  343. X    $(CC) $(LFLAGS) nstat.r -f=$(ODIR)/$@ -l=/dd/LIB/8bit.l
  344. X    fixmod -uo2.39 $(ODIR)/$@
  345. __END__OF__THIS__FILE__
  346. if test -f 'MISC/decode.c' ; then
  347.   echo 'File MISC/decode.c already exists, overwriting it'
  348.   del 'MISC/decode.c'
  349. fi
  350. echo Extracting \"'MISC/decode.c'\"
  351. sed "s/^X//" >'MISC/decode.c' <<'__END__OF__THIS__FILE__'
  352. X#include <stdio.h>
  353. X
  354. X#ifdef SCCSID
  355. Xstatic char    *SccsId = "@(#)decode.c    1.3    5/15/85";
  356. X#endif /* SCCSID */
  357. X
  358. X/*
  359. X * This program is the inverse of encode
  360. X *
  361. X * It collects runs of 12 characters, combines pairs of those
  362. X * to form 6 13 bit numbers, extracts the top bit of each of
  363. X * those to make a 13th 6 bit character, and splits each of
  364. X * the remaining 6 12 bit numbers to form 12 6 bit ones.
  365. X *
  366. X * The strings of 6 bit numbers are collected into groups of
  367. X * 4 and converted into 3 8 bit characters.
  368. X *
  369. X * Now all that would be trivial, if we didn't need to worry
  370. X * about ending all this correctly.  About 1/2 of the following
  371. X * program wouldn't be here if the ending didn't matter....
  372. X */
  373. X
  374. X/*
  375. X * the following pair of characters can never occur as a pair
  376. X * in legal input (since (90 * 91 + 90) > 2^13) - they are
  377. X * noticed at the beginning of a 12 char block, and serve to
  378. X * indicate that this block is the terminator.  The character
  379. X * immediately following is the (expanded) terminator length.
  380. X */
  381. X#define    ENDMARK1    ((90*91 + 90) / 91)
  382. X#define    ENDMARK2    ((90*91 + 90) % 91)
  383. X
  384. Xmain()
  385. X{
  386. X    register c;
  387. X    register char *p;
  388. X    register i;
  389. X    register first = 1;
  390. X    register cnt = 0;
  391. X    int errcnt = 0;
  392. X    char b12[12];
  393. X    char c12[12];
  394. X
  395. X    p = b12;
  396. X    i = 12;
  397. X
  398. X    while ((c = getchar()) != EOF) {
  399. X        if (c < ' ' || c >= (' ' + 91)) {
  400. X            if (errcnt++ == 0)
  401. X                fprintf(stderr, "decode: Bad data\n");
  402. X            continue;
  403. X        }
  404. X        if (i == 10 && p[-1] == ENDMARK1 && p[-2] == ENDMARK2) {
  405. X            cnt = c - ' ';
  406. X            i = 12;
  407. X            p -= 2;
  408. X            continue;
  409. X        }
  410. X        *p++ = c - ' ';
  411. X        if (--i == 0) {
  412. X            if (p == &b12[12]) {
  413. X                if (!first)
  414. X                    pack12(c12, 12, 0);
  415. X                else
  416. X                    first = 0;
  417. X                p = c12;
  418. X            } else {
  419. X                pack12(b12, 12, 0);
  420. X                p = b12;
  421. X            }
  422. X            i = 12;
  423. X        }
  424. X    }
  425. X
  426. X    if (p >= &b12[0] && p < &b12[12]) {
  427. X        if (!first)
  428. X            pack12(c12, 12, i == 12 ? cnt : 0);
  429. X    } else
  430. X        pack12(b12, 12, i == 12 ? cnt : 0);
  431. X
  432. X    if (i != 12) {
  433. X        if (p >= &b12[0] && p < &b12[12])
  434. X            pack12(b12, 12-i, cnt);
  435. X        else
  436. X            pack12(c12, 12-i, cnt);
  437. X    }
  438. X
  439. X    exit(0);
  440. X}
  441. X
  442. Xstatic char b4[4];
  443. Xstatic int cnt = 0;
  444. X
  445. Xpack12(p, n, last)
  446. X    register char *p;
  447. X    register n;
  448. X    int last;
  449. X{
  450. X    register i;
  451. X    register char *q;
  452. X    char b13[13];
  453. X
  454. X    {
  455. X        register c;
  456. X        register c13;
  457. X
  458. X        q = b13;
  459. X        c13 = 0;
  460. X
  461. X        for (i = 0; i < n; i += 2) {
  462. X            c = *p++ * 91;
  463. X            c += *p++;
  464. X            c13 <<= 1;
  465. X            if (c & (1 << 12))
  466. X                c13 |= 1;
  467. X            *q++ = (c >> 6) & 0x3f;
  468. X            *q++ = c & 0x3f;
  469. X        }
  470. X        *q++ = c13;
  471. X        if (last)
  472. X            q = &b13[last];
  473. X    }
  474. X
  475. X    p = b13;
  476. X    n = q - p;
  477. X    i = cnt;
  478. X    q = &b4[cnt];
  479. X
  480. X    while (--n > 0) {
  481. X        *q++ = *p++;
  482. X        if (++i == 4) {
  483. X            char b3[3];
  484. X            register char *b = b4;
  485. X
  486. X            /* inline expansion of pack6bit, to save calls ... */
  487. X
  488. X            q = b3;
  489. X            *q++ = (b[0] << 2) | ((b[1] >> 4) & 0x3);
  490. X            *q++ = (b[1] << 4) | ((b[2] >> 2) & 0xf);
  491. X            *q = (b[2] << 6) | (b[3] & 0x3f);
  492. X
  493. X            q = b3;
  494. X            while (--i > 0)
  495. X                putchar(*q++);
  496. X
  497. X            q = b4;
  498. X        }
  499. X    }
  500. X
  501. X    *q++ = *p++;    /* the last octet */
  502. X    ++i;
  503. X
  504. X    if (last || i == 4) {
  505. X        pack6bit(b4, i, last);
  506. X        i = 0;
  507. X    }
  508. X
  509. X    cnt = i;
  510. X}
  511. X
  512. Xpack6bit(p, n, last)
  513. X    register char *p;
  514. X    register int n;
  515. X    int last;
  516. X{
  517. X    register char *q;
  518. X    register i = 3;
  519. X    char b3[3];
  520. X
  521. X    if (last) {
  522. X        i = p[n-1];
  523. X        if (i >= 3) {
  524. X            fprintf(stderr, "Badly encoded file\n");
  525. X            i = 3;        /* do the best we can */
  526. X        }
  527. X    }
  528. X
  529. X    q = b3;
  530. X    *q++ = (p[0] << 2) | ((p[1] >> 4) & 0x3);
  531. X    *q++ = (p[1] << 4) | ((p[2] >> 2) & 0xf);
  532. X    *q = (p[2] << 6) | (p[3] & 0x3f);
  533. X
  534. X    q = b3;
  535. X
  536. X    while (--i >= 0)
  537. X        putchar(*q++);
  538. X}
  539. X
  540. __END__OF__THIS__FILE__
  541. if test -f 'MISC/delold.c' ; then
  542.   echo 'File MISC/delold.c already exists, overwriting it'
  543.   del 'MISC/delold.c'
  544. fi
  545. echo Extracting \"'MISC/delold.c'\"
  546. sed "s/^X//" >'MISC/delold.c' <<'__END__OF__THIS__FILE__'
  547. X/*
  548. X * $Log:    delold.c_v $
  549. X * Revision 1.1  90/09/08  15:52:24  cv
  550. X * Initial revision
  551. X * 
  552. X */
  553. X# ifndef    LINT
  554. Xstatic char rcsid[] = "$Id: delold.c_v 1.1 90/09/08 15:52:24 cv Exp $";
  555. Xstatic char copyright[] = "Copyright (C) 1989, 1990 by Ulrich Dessauer, Germering, Germany.\n";
  556. X# endif        LINT
  557. X# include    <stdio.h>
  558. X# include    <ctype.h>
  559. X# include    <time.h>
  560. X# include    <types.h>
  561. X# include    <stat.h>
  562. X# include    <dir.h>
  563. X# include    "news.h"
  564. X
  565. Xextern char    *malloc ();
  566. Xextern int    errno;
  567. X
  568. Xtypedef struct _dirlist {
  569. X    char    fn[33];
  570. X    int    isdir;
  571. X    struct _dirlist    *next;
  572. X} dirlist;
  573. X
  574. Xtime_t    secs;
  575. Xtime_t    tim;
  576. Xint    count;
  577. Xchar    fpath[1024];
  578. X
  579. Xvoid
  580. Xdo_scan (path)
  581. Xchar *path;
  582. X{
  583. X    DIR        *dp;
  584. X    struct direct    *ent;
  585. X    dirlist        *head, *cur, *tmp;
  586. X    register char    *p;
  587. X    char        *sav;
  588. X    struct stat    st;
  589. X
  590. X    if (path)
  591. X        if (chdir (path) < 0) {
  592. X            fprintf (stderr, "Can't chdir to %s (errno %d).\n", path, errno);
  593. X            return;
  594. X        }
  595. X    head = NULL;
  596. X    cur = NULL;
  597. X    if (!(dp = opendir ("."))) {
  598. X        fprintf (stderr, "Can't open '%s' (errno %d), skip over.\n", path ? path : "[root]", errno);
  599. X        if (path)
  600. X            chdir ("..");
  601. X        return;
  602. X    }
  603. X    if (path) {
  604. X        p = fpath;
  605. X        while (*p)
  606. X            ++p;
  607. X        sav = p;
  608. X        *p++ = '/';
  609. X        strcpy (p, path);
  610. X        printf ("Now in %s\n", fpath);
  611. X    }
  612. X    while (ent = readdir (dp)) {
  613. X        if (ent->d_name[0] == '.')
  614. X            continue;
  615. X        p = ent->d_name;
  616. X        while (*p)
  617. X            if (!isdigit (*p))
  618. X                break;
  619. X            else
  620. X                ++p;
  621. X        if (!(tmp = (dirlist *) malloc (sizeof (dirlist)))) {
  622. X            fprintf (stderr, "PANIC: Out of memory! (errno %d)\n", errno);
  623. X            closedir (dp);
  624. X            exit (1);
  625. X        }
  626. X        strcpy (tmp->fn, ent->d_name);
  627. X        tmp->isdir = (*p != '\0');
  628. X        tmp->next = NULL;
  629. X        if (!head)
  630. X            head = tmp;
  631. X        else
  632. X            cur->next = tmp;
  633. X        cur = tmp;
  634. X    }
  635. X    closedir (dp);
  636. X    cur = head;
  637. X    while (cur) {
  638. X        if (cur->isdir)
  639. X            do_scan (cur->fn);
  640. X        else if (stat (cur->fn, &st) == -1)
  641. X            fprintf (stderr, "Can't stat %s (errno %d).\n", cur->fn, errno);
  642. X        else if (st.st_mtime + secs < tim)
  643. X            if (unlink (cur->fn) < 0)
  644. X                fprintf (stderr, "Can't unlink %s (errno %d).\n", cur->fn, errno);
  645. X            else
  646. X                ++count;
  647. X        tmp = cur;
  648. X        cur = cur->next;
  649. X        free ((char *) tmp);
  650. X    }
  651. X    if (path) {
  652. X        *sav = '\0';
  653. X        chdir ("..");
  654. X    }
  655. X}
  656. X
  657. Xint
  658. Xmain (argc, argv)
  659. Xint argc;
  660. Xchar *argv[];
  661. X{
  662. X    char    buf[256];
  663. X    int    days;
  664. X
  665. X    setuid (getmuid ());
  666. X    if ((argc != 2) || (!isdigit (argv[1][0])))
  667. X        exit (_errmsg (1, "Usage: %s <days>\n", argv[0]));
  668. X    if ((days = atoi (argv[1])) < 1)
  669. X        exit (_errmsg (1, "<days> must be greater than zero.\n"));
  670. X    secs = (time_t) (days * 24 * 60 * 60);
  671. X    time (&tim);
  672. X    if (!info_str (NEWSDIR, buf, sizeof (buf)))
  673. X        strcpy (buf, DEF_NEWSDIR);
  674. X    if (chdir (buf) < 0)
  675. X        exit (_errmsg (1, "Can't chdir() to %s, errno %d.\n", buf, errno));
  676. X    strcpy (fpath, ".");
  677. X    count = 0;
  678. X    do_scan (NULL);
  679. X    printf ("%d old articles deleted.\n", count);
  680. X}
  681. __END__OF__THIS__FILE__
  682. if test -f 'MISC/encode.c' ; then
  683.   echo 'File MISC/encode.c already exists, overwriting it'
  684.   del 'MISC/encode.c'
  685. fi
  686. echo Extracting \"'MISC/encode.c'\"
  687. sed "s/^X//" >'MISC/encode.c' <<'__END__OF__THIS__FILE__'
  688. X#include <stdio.h>
  689. X
  690. X#ifdef SCCSID
  691. Xstatic char    *SccsId = "@(#)encode.c    1.3    5/15/85";
  692. X#endif /* SCCSID */
  693. X
  694. X/*
  695. X * Produce a 7 bit printable encoding of stdin on stdout.
  696. X *
  697. X * Encoding uses acsii chars from ' ' .. 'z'
  698. X * (040 .. 0172) (0x20 - 0x7a) inclusive
  699. X *
  700. X * Method is to expand 3 chars -> 4 6 bit ones.
  701. X * Then collect 13 6 bit chars, and spread the 13th over
  702. X * the preceding 12, so that each of the 12 chars is now
  703. X * 6.5 bits.  These 2 6.5 bit chars are a little hard
  704. X * to represent on most common machines (one of these days
  705. X * sane hosts will have 1/2 bits just for this program)
  706. X * so we take a pair of them, and represent that in 13 bits.
  707. X * 13 bits (max value 8191) can be represented as
  708. X *    A * 91 + B
  709. X * where A < 91, B < 91  (91^2 == 8281, so it fits!)
  710. X *
  711. X * Each of A and B is encoded as a character by adding 32
  712. X * to make it printable (ie: 0x20).
  713. X *
  714. X * The termination conditions are foul beyond belief.  Don't
  715. X * monkey with them!
  716. X *
  717. X * If you think its a fluke that 040 .. 0171 just happen to
  718. X * be the chars that Piet Beertema's uucp 'f' protocol transmits
  719. X * as single bytes, you're insane.  0172 chars are produced
  720. X * with lower frequency than any other (given random data)
  721. X * so the doubling that occurs with that we will just suffer.
  722. X * (A newer 'f' proto, sometime, will probably not use 0172)
  723. X */
  724. X
  725. X/*
  726. X * the following pair of characters cannot legally occur
  727. X * in normal output (since 90*91 + 90 == 8280, which > 2^13)
  728. X * so we use them to indicate that the data that follows is the
  729. X * terminator.  The character immediately following this
  730. X * pair is the length of the (expanded) terminator (which
  731. X * otherwise might be indeterminable)
  732. X */
  733. X#define    ENDMARK1    ((90*91 + 90) / 91 + ' ')
  734. X#define    ENDMARK2    ((90*91 + 90) % 91 + ' ')
  735. X
  736. Xmain()
  737. X{
  738. X    register char *p;
  739. X    register char *e;
  740. X    register c;
  741. X    char b3[3];
  742. X
  743. X    p = b3;
  744. X    e = b3 + 3;
  745. X    while ((c = getchar()) != EOF) {
  746. X        *p++ = c;
  747. X        if (p == e) {
  748. X            encode(b3, 3);
  749. X            p = b3;
  750. X        }
  751. X    }
  752. X    encode(b3, p - b3);
  753. X    flushout();
  754. X    exit(0);
  755. X}
  756. X
  757. Xstatic char b13[13];
  758. Xstatic int cnt = 0;
  759. X
  760. Xencode(c, n)
  761. X    register char *c;
  762. X    int n;
  763. X{
  764. X    register char *p;
  765. X    register i = cnt;
  766. X    register j;
  767. X    char b4[4];
  768. X
  769. X    p = b4;
  770. X
  771. X    p[0] = (c[0] >> 2) & 0x3f;
  772. X    p[1] = ((c[0] & 0x3) << 4) | ((c[1] >> 4) & 0xf);
  773. X    p[2] = ((c[1] & 0xF) << 2) | ((c[2] >> 6) & 0x3);
  774. X    if (n == 3)
  775. X        p[3] = c[2] & 0x3f;
  776. X    else
  777. X        p[3] = n;
  778. X
  779. X    c = &b13[i];
  780. X    for (j = 4; --j >= 0; i++) {
  781. X        if (i == 13) {
  782. X            dumpcode(b13, 13);
  783. X            c = b13;
  784. X            i = 0;
  785. X        }
  786. X        *c++ = *p++;
  787. X    }
  788. X    cnt = i;
  789. X}
  790. X
  791. Xflushout()
  792. X{
  793. X    putchar(ENDMARK1);
  794. X    putchar(ENDMARK2);
  795. X    putchar(cnt + ' ');
  796. X    dumpcode(b13, cnt);
  797. X}
  798. X
  799. Xdumpcode(p, n)
  800. X    register char *p;
  801. X    register int n;
  802. X{
  803. X    register last;
  804. X    register c;
  805. X
  806. X    if (n == 13)
  807. X        n--, last = p[12];
  808. X    else if (n & 1)
  809. X        last = (1 << (6-1));
  810. X    else
  811. X        last = 0;
  812. X
  813. X    for ( ; n > 0; n -= 2) {
  814. X        c = *p++ << 6;
  815. X        c |= *p++;
  816. X        if (last & (1 << (6-1)))
  817. X            c |= (1 << 12);
  818. X        last <<= 1;
  819. X
  820. X        /*
  821. X         * note: 91^2 > 2^13, 90^2 < 2^13, (91 + ' ') is printable
  822. X         */
  823. X
  824. X        /* oh for a compiler that would only do one division... */
  825. X        putchar((c / 91) + ' ');
  826. X        putchar((c % 91) + ' ');
  827. X    }
  828. X}
  829. X
  830. __END__OF__THIS__FILE__
  831. if test -f 'MISC/news_in.c' ; then
  832.   echo 'File MISC/news_in.c already exists, overwriting it'
  833.   del 'MISC/news_in.c'
  834. fi
  835. echo Extracting \"'MISC/news_in.c'\"
  836. sed "s/^X//" >'MISC/news_in.c' <<'__END__OF__THIS__FILE__'
  837. X# include    <stdio.h>
  838. X
  839. Xextern char    *index ();
  840. Xextern char    *strdup ();
  841. Xextern FILE    *xpopen ();
  842. X
  843. Xvoid
  844. Xusage ()
  845. X{
  846. X    fprintf (stderr, "Usage: news_in [-f=<sender>] <newsgroup>\n");
  847. X}
  848. X
  849. Xint
  850. Xmain (ac, av)
  851. Xint ac;
  852. Xchar *av[];
  853. X{
  854. X    char    *from;
  855. X    char    *group;
  856. X    int    t;
  857. X    char    *ptr;
  858. X    FILE    *pp;
  859. X    char    buf[260];
  860. X    int    n;
  861. X    int    err;
  862. X    int    pend;
  863. X
  864. X    setuid (getmuid ());
  865. X    from = NULL;
  866. X    group = NULL;
  867. X    for (t = 1; t < ac; ++t)
  868. X        if (av[t][0] == '-') {
  869. X            ptr = av[t] + 1;
  870. X            while (*ptr) {
  871. X                switch (*ptr) {
  872. X                    case 'f':
  873. X                        ptr += *(ptr + 1) == '=' ? 2 : 1;
  874. X                        from = ptr;
  875. X                        while (*ptr)
  876. X                            ++ptr;
  877. X                        break;
  878. X                    case '?':
  879. X                        usage ();
  880. X                        exit (1);
  881. X                    default:
  882. X                        break;
  883. X                }
  884. X                if (*ptr)
  885. X                    ++ptr;
  886. X            }
  887. X        } else if (!group)
  888. X            group = strdup (av[t]);
  889. X    if (!group)
  890. X        exit (1);
  891. X    ptr = group;
  892. X    while (ptr)
  893. X        if (ptr = index (ptr, '-'))
  894. X            *ptr++ = '.';
  895. X    if (!_strccmp (group, "postmaster"))
  896. X        pp = xpopen ("mail -s=News_In Postmaster", "w");
  897. X    else
  898. X        pp = xpopen ("inews -h", "w");
  899. X    if (!pp)
  900. X        exit (1);
  901. X    err = 0;
  902. X    pend = 0;
  903. X    while ((n = readln (0, buf, 256)) > 0)
  904. X        if (!group) {
  905. X            if (fwrite (buf, sizeof (char), n, pp) != n) {
  906. X                ++err;
  907. X                break;
  908. X            }
  909. X        } else {
  910. X            if ((buf[n - 1] != '\n') || pend) {
  911. X                pend = (!pend);
  912. X                if (fwrite (buf, sizeof (char), n, pp) != n) {
  913. X                    ++err;
  914. X                    break;
  915. X                }
  916. X                continue;
  917. X            } else if (n == 1) {
  918. X                fprintf (pp, "Newsgroups: %s\n\n", group);
  919. X                free (group);
  920. X                group = NULL;
  921. X            } else if (fwrite (buf, sizeof (char), n, pp) != n) {
  922. X                ++err;
  923. X                break;
  924. X            }
  925. X        }
  926. X    free (buf);
  927. X    if (pclose (pp))
  928. X        ++err;
  929. X    exit (err ? 1 : 0);
  930. X}
  931. __END__OF__THIS__FILE__
  932. if test -f 'MISC/news_out.c' ; then
  933.   echo 'File MISC/news_out.c already exists, overwriting it'
  934.   del 'MISC/news_out.c'
  935. fi
  936. echo Extracting \"'MISC/news_out.c'\"
  937. sed "s/^X//" >'MISC/news_out.c' <<'__END__OF__THIS__FILE__'
  938. X# include    <stdio.h>
  939. X# include    <c8type.h>
  940. X
  941. Xextern char    *cuserid ();
  942. Xextern char    *getenv ();
  943. Xextern char    *index ();
  944. Xextern char    *malloc ();
  945. Xextern char    *strdup ();
  946. Xextern char    *strredup ();
  947. Xextern FILE    *xpopen ();
  948. X
  949. Xstruct {
  950. X    char    *pat;
  951. X    int    len;
  952. X} todel[] = {
  953. X    "path:",    5,
  954. X    "message-id:",    11,
  955. X    "reply-to:",    9,
  956. X    "sender:",    7,
  957. X    NULL,        0
  958. X};
  959. X
  960. Xchar *
  961. Xgetng (og, s)
  962. Xchar *og;
  963. Xregister char *s;
  964. X{
  965. X    char    *sav;
  966. X
  967. X    if (s = index (s, ':')) {
  968. X        ++s;
  969. X        while (is8space (*s))
  970. X            ++s;
  971. X        sav = s;
  972. X        while (*s && (*s != ',') && (!is8space (*s)))
  973. X            ++s;
  974. X        *s = '\0';
  975. X        og = strredup (og, sav);
  976. X        s = og;
  977. X        while (s = index (s, '.'))
  978. X            *s++ = '-';
  979. X    }
  980. X    return (og);
  981. X}
  982. X        
  983. Xint
  984. Xmain (ac, av)
  985. Xint ac;
  986. Xchar *av[];
  987. X{
  988. X    FILE        *pp;
  989. X    FILE        *fp;
  990. X    char        fn[128];
  991. X    char        *cmd;
  992. X    int        t;
  993. X    int        siz;
  994. X    int        n;
  995. X    int        inhead;
  996. X    int        mode;
  997. X    char        *ng;
  998. X    char        *path;
  999. X    char        fhost[128];
  1000. X    char        sender[160];
  1001. X    register char    *sptr;
  1002. X    register char    *ptr;
  1003. X
  1004. X    setuid (getmuid ());
  1005. X    if (ac < 2)
  1006. X        exit (0);
  1007. X    if (!(sptr = cuserid ()))
  1008. X        if (!(sptr = getenv ("USER")))
  1009. X            if (!(sptr = getenv ("LOGNAME")))
  1010. X                sptr = "Postmaster";
  1011. X    strcpy (sender, sptr);
  1012. X    sptr = sender;
  1013. X    while (*sptr)
  1014. X        ++sptr;
  1015. X    *sptr++ = '@';
  1016. X    if (gethostname (sptr, 64))
  1017. X        while (*sptr)
  1018. X            ++sptr;
  1019. X    strcpy (fhost, "newsgroup");
  1020. X    ptr = fhost;
  1021. X    while (*ptr)
  1022. X        ++ptr;
  1023. X    if (info_str ("hostdomain", ptr + 1, 96)) {
  1024. X        *ptr = '.';
  1025. X        strcpy (sptr, ptr);
  1026. X    } else
  1027. X        *sptr = '\0';
  1028. X    siz = 0;
  1029. X    for (t = 1; t < ac; ++t)
  1030. X        siz += strlen (av[t]) + 4;
  1031. X    siz += 64;
  1032. X    if (!(cmd = malloc (siz < 260 ? 260 : siz)))
  1033. X        exit (0);
  1034. X    strcpy (cmd, "rmail");
  1035. X    for (t = 1; t < ac; ++t) {
  1036. X        strcat (cmd, " '");
  1037. X        strcat (cmd, av[t]);
  1038. X        strcat (cmd, "'");
  1039. X    }
  1040. X    strcpy (fn, "/dd/TMP/newsoutXXXXXX");
  1041. X    mktemp (fn);
  1042. X    if (!(fp = fopen (fn, "w+")))
  1043. X        exit (0);
  1044. X    if (pp = xpopen (cmd, "w")) {
  1045. X        ng = NULL;
  1046. X        path = NULL;
  1047. X        inhead = 1;
  1048. X        mode = 0;
  1049. X        while ((n = readln (0, cmd, 256)) > 0) {
  1050. X            cmd[n] = '\0';
  1051. X            if (inhead)
  1052. X                for (t = 0; todel[t].pat; ++t)
  1053. X                    if (!_strnccmp (cmd, todel[t].pat, todel[t].len))
  1054. X                        break;
  1055. X            if ((!inhead) || (!todel[t].pat))
  1056. X                if (fputs (cmd, fp) == -1)
  1057. X                    break;
  1058. X            if (inhead)
  1059. X                if (n == 1)
  1060. X                    inhead = 0;
  1061. X                else {
  1062. X                    if ((mode < 1) && (!_strnccmp (cmd, "Newsgroups:", 11))) {
  1063. X                        ng = getng (ng, cmd);
  1064. X                        mode = 1;
  1065. X                    } else if ((mode < 2) && (!_strnccmp (cmd, "Followup-To:", 12))) {
  1066. X                        ng = getng (ng, cmd);
  1067. X                        mode = 2;
  1068. X                    } else if ((!path) && (!_strnccmp (cmd, "Path:", 5)))
  1069. X                        path = strdup (cmd + 5);
  1070. X                }
  1071. X        }
  1072. X        inhead = ng ? 1 : 0;
  1073. X        if (path) {
  1074. X            if (ptr = index (path, '\n'))
  1075. X                *ptr = '\0';
  1076. X            ptr = path;
  1077. X            while (is8space (*ptr))
  1078. X                ++ptr;
  1079. X            while (*ptr)
  1080. X                if (is8alnum (*ptr) || index (".-+", *ptr))
  1081. X                    ++ptr;
  1082. X                else
  1083. X                    *ptr++ = '!';
  1084. X            ptr = path;
  1085. X            while (is8space (*ptr))
  1086. X                ++ptr;
  1087. X            fprintf (pp, "From %s\n", ptr);
  1088. X        }
  1089. X        fseek (fp, 0, 0);
  1090. X        while (fgets (cmd, 256, fp)) {
  1091. X            if (inhead)
  1092. X                if (!strcmp (cmd, "\n")) {
  1093. X                    fprintf (pp, "Sender: %s\n", sender);
  1094. X                    fprintf (pp, "Reply-To: %s@%s\n", ng, fhost);
  1095. X                    inhead = 0;
  1096. X                }
  1097. X            if (fputs (cmd, pp) == -1)
  1098. X                break;
  1099. X        }
  1100. X        fclose (fp);
  1101. X        unlink (fn);
  1102. X        pclose (pp);
  1103. X    }
  1104. X}
  1105. X    
  1106. __END__OF__THIS__FILE__
  1107. if test -f 'MISC/nstat.c' ; then
  1108.   echo 'File MISC/nstat.c already exists, overwriting it'
  1109.   del 'MISC/nstat.c'
  1110. fi
  1111. echo Extracting \"'MISC/nstat.c'\"
  1112. sed "s/^X//" >'MISC/nstat.c' <<'__END__OF__THIS__FILE__'
  1113. X# include    <stdio.h>
  1114. X# include    <c8type.h>
  1115. X# include    <modes.h>
  1116. X# include    <time.h>
  1117. X# include    <types.h>
  1118. X# include    <stat.h>
  1119. X
  1120. X# define    GROUP        "Newsgroups: "
  1121. X# define    FROM        "From: "
  1122. X
  1123. Xextern char    *index ();
  1124. Xextern char    *malloc ();
  1125. Xextern char    *strdup ();
  1126. X
  1127. Xtypedef enum {
  1128. X    False = 0,
  1129. X    True
  1130. X}    Bool;
  1131. X
  1132. Xstatic char    *help[] = {
  1133. X    "Syntax: nstat [<opts>] [<filename>] [<opts>]\n",
  1134. X    "Function: generates a statistic file or evaluates it\n",
  1135. X    "Options:\n",
  1136. X    "      -e        evaluate the statfile\n",
  1137. X    "      -p=<str>  prefix of every groupname\n",
  1138. X    "      -o=<file> the output file for the evaluation (def. stdout).\n",
  1139. X    "      -d        delete statfile after evaluation\n",
  1140. X    "      -h        create header to pipe directly to inews -h\n",
  1141. X    "      -t=<file> use <file> as timestamp since last report\n",
  1142. X    NULL
  1143. X};
  1144. X
  1145. Xstatic void
  1146. Xusage ()
  1147. X{
  1148. X    register int    t;
  1149. X
  1150. X    for (t = 0; help[t]; ++t)
  1151. X        fputs (help[t], stderr);
  1152. X}
  1153. X
  1154. Xstatic void
  1155. Xcollect (fd, file)
  1156. Xregister int fd;
  1157. Xchar *file;
  1158. X{
  1159. X    register char    *ptr;
  1160. X    char        *group;
  1161. X    char        *system;
  1162. X    register int    size;
  1163. X    register char    *buf;
  1164. X    register Bool    inhead;
  1165. X    register int    n;
  1166. X    char        *tmp;
  1167. X
  1168. X    if (! (buf = malloc (520)))
  1169. X        return;
  1170. X    group = NULL;
  1171. X    system = NULL;
  1172. X    size = 0;
  1173. X    inhead = True;
  1174. X    while ((n = readln (fd, buf, 512)) > 0) {
  1175. X        size += n;
  1176. X        if (inhead == True)
  1177. X            if (n == 1)
  1178. X                inhead = False;
  1179. X            else {
  1180. X                buf[n - 1] = '\0';
  1181. X                if ((! group) && (! _strnccmp (buf, GROUP, sizeof (GROUP) - 1))) {
  1182. X                    ptr = buf + sizeof (GROUP) - 1;
  1183. X                    while (is8space (*ptr))
  1184. X                        ++ptr;
  1185. X                    group = strdup (ptr);
  1186. X                } else if ((! system) && (! _strnccmp (buf, FROM, sizeof (FROM) - 1))) {
  1187. X                    ptr = buf + sizeof (FROM) - 1;
  1188. X                    while (is8space (*ptr))
  1189. X                        ++ptr;
  1190. X                    if (tmp = index (ptr, '@')) {
  1191. X                        ++tmp;
  1192. X                        for (ptr = tmp; *ptr && (! is8space (*ptr)) && (! index ("()>", *ptr)); ++ptr)
  1193. X                            ;
  1194. X                        *ptr = '\0';
  1195. X                        system = strdup (tmp);
  1196. X                    }
  1197. X                }
  1198. X            }
  1199. X    }
  1200. X    close (fd);
  1201. X    if (! (group && system))
  1202. X        return;
  1203. X    sprintf (buf, "%s %d %s\n", group, size, system);
  1204. X    n = strlen (buf);
  1205. X    if ((fd = open (file, S_IWRITE)) == -1)
  1206. X        fd = create (file, S_IWRITE, 03);
  1207. X    else
  1208. X        lseek (fd, 0, 2);
  1209. X    if (fd != -1) {
  1210. X        write (fd, buf, n);
  1211. X        close (fd);
  1212. X    }
  1213. X}
  1214. X
  1215. Xtypedef struct _list {
  1216. X    char    *name;        /* Group/System name            */
  1217. X    int    count;        /* # of articles            */
  1218. X    int    cper;        /* % * 100 (e.g. 100 = 1% 10000 = 100%)    */
  1219. X    int    size;        /* size of all articles            */
  1220. X    int    sper;        /* as cper                */
  1221. X    int    average;    /* avergae size of article        */
  1222. X    int    xpost;        /* number of crosspostings        */
  1223. X    struct _list
  1224. X        *next;
  1225. X}    list;
  1226. X
  1227. Xstatic int
  1228. Xadd_list (root, name, size, xpost)
  1229. Xlist **root;
  1230. Xchar *name;
  1231. Xint size;
  1232. Xint xpost;
  1233. X{
  1234. X    register list    *run, *tmp;
  1235. X
  1236. X    for (run = *root; run; run = run -> next)
  1237. X        if (! _strccmp (run -> name, name))
  1238. X            break;
  1239. X    if (run) {
  1240. X        run -> count++;
  1241. X        run -> size += size;
  1242. X        if (xpost > 1)
  1243. X            run -> xpost++;
  1244. X    } else if ((! (tmp = (list *) malloc (sizeof (list)))) || (! (tmp -> name = strdup (name)))) {
  1245. X        fprintf (stderr, "Can't alloc for new list entry.\n");
  1246. X        return (-1);
  1247. X    } else {
  1248. X        tmp -> count = 1;
  1249. X        tmp -> size = size;
  1250. X        tmp -> next = *root;
  1251. X        tmp -> xpost = (xpost > 1) ? 1 : 0;
  1252. X        *root = tmp;
  1253. X    }
  1254. X    return (0);
  1255. X}
  1256. X
  1257. Xstatic void
  1258. Xaver_list (tmp)
  1259. Xregister list *tmp;
  1260. X{
  1261. X    register int    ccount, csize;
  1262. X    register list    *start;
  1263. X
  1264. X    ccount = 0;
  1265. X    csize = 0;
  1266. X    start = tmp;
  1267. X    while (tmp) {
  1268. X        tmp -> average = tmp -> size / tmp -> count;
  1269. X        csize += tmp -> size;
  1270. X        ccount += tmp -> count;
  1271. X        tmp = tmp -> next;
  1272. X    }
  1273. X    for (tmp = start; tmp; tmp = tmp -> next) {
  1274. X        tmp -> cper = (tmp -> count * 10000) / ccount;
  1275. X        tmp -> sper = (tmp -> size * 10000) / csize;
  1276. X    }
  1277. X}
  1278. X
  1279. Xstatic void
  1280. Xsort_list (root, tosize)
  1281. Xlist **root;
  1282. Xregister Bool tosize;
  1283. X{
  1284. X    register list    *r, *p, *c, *t;
  1285. X
  1286. X    r = *root;
  1287. X    p = NULL;
  1288. X    c = r;
  1289. X    while (c -> next)
  1290. X        if (tosize ? (c -> next -> size > c -> size) : (c -> next -> count > c -> count)) {
  1291. X            if (p) {
  1292. X                p -> next = c -> next;
  1293. X                c -> next = c -> next -> next;
  1294. X                p -> next -> next = c;
  1295. X                c = p;
  1296. X                if (c == r)
  1297. X                    p = NULL;
  1298. X                else
  1299. X                    for (p = r; p -> next != c; p = p -> next)
  1300. X                        if (! p -> next) {
  1301. X                            fprintf (stderr, "*** Error in sorting! ***\n");
  1302. X                            break;
  1303. X                        }
  1304. X            } else {
  1305. X                c = c -> next;
  1306. X                r -> next = c -> next;
  1307. X                c -> next = r;
  1308. X                r = c;
  1309. X            }
  1310. X        } else {
  1311. X            p = c;
  1312. X            c = c -> next;
  1313. X        }
  1314. X    *root = r;
  1315. X}
  1316. X
  1317. Xstatic void
  1318. Xdump_list (fp, header, first, tmp)
  1319. Xregister FILE *fp;
  1320. Xchar *header, *first;
  1321. Xregister list *tmp;
  1322. X{
  1323. X    fprintf (fp, "\n%s:\n", header);
  1324. X    fprintf (fp, "%-25.25s  %7.7s (xx.xx%%)  %7.7s (xx.xx%%)  %7.7s  %7.7s\n",
  1325. X        first, "Size", "Count", "Siz/Cont", "X-post");
  1326. X    for (; tmp; tmp = tmp -> next)
  1327. X        fprintf (fp, "%-25.25s  %7d (%2d.%02d%%)  %7d (%2d.%02d%%)  %7d  %7d\n",
  1328. X            tmp -> name, tmp -> size,
  1329. X            tmp -> sper / 100, tmp -> sper % 100,
  1330. X            tmp -> count,
  1331. X            tmp -> cper / 100, tmp -> cper % 100,
  1332. X            tmp -> average, tmp -> xpost);
  1333. X}
  1334. X
  1335. Xstatic void
  1336. Xevaluate (ifile, ofile, prefix, delete, news_header, timestamp)
  1337. Xchar *ifile, *ofile;
  1338. XBool delete;
  1339. Xchar *prefix;
  1340. XBool news_header;
  1341. Xchar *timestamp;
  1342. X{
  1343. X    FILE        *fp;
  1344. X    list        *groot;
  1345. X    list        *sroot;
  1346. X    list        *tmp;
  1347. X    char        *rifile;
  1348. X    register char    *buf;
  1349. X    register int    n;
  1350. X    int        fd;
  1351. X    char        *siz, *sys;
  1352. X    char        *xpost;
  1353. X    char        *ptr, *gp;
  1354. X    int        size;
  1355. X    int        len;
  1356. X    int        tmpfd;
  1357. X    time_t        tim;
  1358. X    struct tm    *tt;
  1359. X    struct tm    ts;
  1360. X    struct stat    st;
  1361. X
  1362. X    if (! (buf = malloc (520))) {
  1363. X        fprintf (stderr, "Can't alloc for input buffer.\n");
  1364. X        return;
  1365. X    }
  1366. X    if (delete) {
  1367. X        if (! (rifile = malloc (strlen (ifile) + 40))) {
  1368. X            fprintf (stderr, "Can't alloc for temp. filename.\n");
  1369. X            return;
  1370. X        }
  1371. X        strcpy (rifile, ifile);
  1372. X        strcat (rifile, "XXXXXX");
  1373. X        mktemp (rifile);
  1374. X        if (rename (ifile, rifile)) {
  1375. X            fprintf (stderr, "Can't rename %s to %s, aborted.\n", ifile, rifile);
  1376. X            return;
  1377. X        }
  1378. X    } else
  1379. X        rifile = NULL;
  1380. X    groot = NULL;
  1381. X    sroot = NULL;
  1382. X    if ((fd = open (rifile ? rifile : ifile, S_IREAD)) == -1) {
  1383. X        fprintf (stderr, "Can't open %s, aborted.\n", rifile ? rifile : ifile);
  1384. X        return;
  1385. X    }
  1386. X    len = (prefix && *prefix) ? strlen (prefix) : 0;
  1387. X    while ((n = readln (fd, buf, 512)) > 0) {
  1388. X        buf[n - 1] = '\0';
  1389. X        if (! (siz = index (buf, ' ')))
  1390. X            continue;
  1391. X        *siz++ = '\0';
  1392. X        if (! (sys = index (siz, ' ')))
  1393. X            continue;
  1394. X        *sys++ = '\0';
  1395. X        size = atoi (siz);
  1396. X        n = 1;
  1397. X        xpost = buf;
  1398. X        gp = NULL;
  1399. X        do {
  1400. X            if (ptr = index (xpost, ',')) {
  1401. X                *ptr++ = '\0';
  1402. X                ++n;
  1403. X            }
  1404. X            if ((! gp) && ((! len) || (! _strnccmp (xpost, prefix, len))))
  1405. X                gp = xpost;
  1406. X            xpost = ptr;
  1407. X        } while (xpost);
  1408. X        if (! gp)
  1409. X            continue;
  1410. X        if ((add_list (& groot, gp, size, n) < 0) || (add_list (& sroot, sys, size, n) < 0))
  1411. X            return;
  1412. X    }
  1413. X    close (fd);
  1414. X    if (ofile) {
  1415. X        if (! (fp = fopen (ofile, "w"))) {
  1416. X            fprintf (stderr, "Can't open %s for writing.\n", ofile);
  1417. X            return;
  1418. X        }
  1419. X    } else
  1420. X        fp = stdout;
  1421. X    if (news_header) {
  1422. X        time (& tim);
  1423. X        tt = localtime (& tim);
  1424. X        fprintf (fp, "Subject: Newsstatistic (%02d/%02d/%02d)\n\n",
  1425. X            tt -> tm_year % 100, tt -> tm_mon + 1, tt -> tm_mday);
  1426. X    }
  1427. X    if (timestamp) {
  1428. X        if (stat (timestamp, & st) == -1)
  1429. X            fprintf (fp, "\nFirst evaluation\n");
  1430. X        else if (tt = localtime (& st.st_mtime)) {
  1431. X            ts = *tt;
  1432. X            time (& tim);
  1433. X            tt = localtime (& tim);
  1434. X            fprintf (fp, "Last evaluation: %02d/%02d/%02d\n",
  1435. X                ts.tm_year % 100, ts.tm_mon + 1, ts.tm_mday);
  1436. X            tim -= st.st_mtime;
  1437. X            tim = tim / (24 * 60 * 60);
  1438. X            fprintf (fp, "Data collected for %d day%s.\n",
  1439. X                tim, tim != 1 ? "s" : "");
  1440. X        }
  1441. X        if ((tmpfd = creat (timestamp, S_IWRITE)) != -1)
  1442. X            close (tmpfd);
  1443. X    }
  1444. X    aver_list (groot);
  1445. X    aver_list (sroot);
  1446. X    sort_list (& groot, True);
  1447. X    dump_list (fp, "Group statistic (sorted by size)", "Groupname", groot);
  1448. X    sort_list (& groot, False);
  1449. X    dump_list (fp, "Group statistic (sorted by # of Articles)", "Groupname", groot);
  1450. X    sort_list (& sroot, True);
  1451. X    dump_list (fp, "System statistic (sorted by size)", "Systemname", sroot);
  1452. X    sort_list (& sroot, False);
  1453. X    dump_list (fp, "System statistic (sorted by # of Articles)", "Systemname", sroot);
  1454. X    if (ofile)
  1455. X        fclose (fp);
  1456. X    if (delete)
  1457. X        unlink (rifile);
  1458. X}
  1459. X
  1460. Xint
  1461. Xmain (argc, argv)
  1462. Xint argc;
  1463. Xchar *argv[];
  1464. X{
  1465. X    register int    t;
  1466. X    register char    *ptr;
  1467. X    char        *file;
  1468. X    char        *ofile;
  1469. X    char        *prefix;
  1470. X    char        *timestamp;
  1471. X    Bool        eval;
  1472. X    Bool        delete;
  1473. X    Bool        news_header;
  1474. X
  1475. X    file = "NewsStat";
  1476. X    ofile = NULL;
  1477. X    prefix = NULL;
  1478. X    timestamp = NULL;
  1479. X    eval = False;
  1480. X    delete = False;
  1481. X    news_header = False;
  1482. X    for (t = 1; t < argc; ++t)
  1483. X        if (argv[t][0] == '-') {
  1484. X            ptr = argv[t] + 1;
  1485. X            while (*ptr) {
  1486. X                switch (*ptr) {
  1487. X                    case 'p':
  1488. X                        ptr += *(ptr + 1) == '=' ? 2 : 1;
  1489. X                        prefix = ptr;
  1490. X                        while (*ptr)
  1491. X                            ++ptr;
  1492. X                        break;
  1493. X                    case 'o':
  1494. X                        ptr += *(ptr + 1) == '=' ? 2 : 1;
  1495. X                        ofile = ptr;
  1496. X                        while (*ptr)
  1497. X                            ++ptr;
  1498. X                        break;
  1499. X                    case 't':
  1500. X                        ptr += *(ptr + 1) == '=' ? 2 : 1;
  1501. X                        timestamp = ptr;
  1502. X                        while (*ptr)
  1503. X                            ++ptr;
  1504. X                        break;
  1505. X                    case 'e':
  1506. X                        eval = True;
  1507. X                        break;
  1508. X                    case 'd':
  1509. X                        delete = True;
  1510. X                        break;
  1511. X                    case 'h':
  1512. X                        news_header = True;
  1513. X                        break;
  1514. X                    case '?':
  1515. X                    default:
  1516. X                        usage ();
  1517. X                        exit (*ptr == '?' ? 0 :
  1518. X                            _errmsg (1, "Unknown option '%c'.\n", *ptr));
  1519. X                }
  1520. X                if (*ptr)
  1521. X                    ++ptr;
  1522. X            }
  1523. X        } else
  1524. X            file = argv[t];
  1525. X    setuid (getmuid ());
  1526. X    if (eval == False)
  1527. X        collect (0, file);
  1528. X    else
  1529. X        evaluate (file, ofile, prefix, delete, news_header, timestamp);
  1530. X}
  1531. __END__OF__THIS__FILE__
  1532. if test -f 'MISC/rot13.c' ; then
  1533.   echo 'File MISC/rot13.c already exists, overwriting it'
  1534.   del 'MISC/rot13.c'
  1535. fi
  1536. echo Extracting \"'MISC/rot13.c'\"
  1537. sed "s/^X//" >'MISC/rot13.c' <<'__END__OF__THIS__FILE__'
  1538. X# include    <modes.h>
  1539. X# include    <c8type.h>
  1540. X
  1541. Xextern char    *malloc ();
  1542. X
  1543. Xchar8        table[256];
  1544. X
  1545. Xvoid
  1546. Xrot (fdi, fdo)
  1547. Xint fdi, fdo;
  1548. X{
  1549. X    static char8    *store = (char *) 0;
  1550. X    register char8    *ptr;
  1551. X    register int    n, t;
  1552. X
  1553. X    if (! store)
  1554. X        if (! (store = (char8 *) malloc (4096 + 4)))
  1555. X            return;
  1556. X    while ((n = read (fdi, store, 4096)) > 0) {
  1557. X        t = n;
  1558. X        ptr = store;
  1559. X        while (t-- > 0) {
  1560. X            *ptr = table[*ptr];
  1561. X            ++ptr;
  1562. X        }
  1563. X        if (fdo != -1) {
  1564. X            if (write (fdo, store, n) != n)
  1565. X                break;
  1566. X        } else {
  1567. X            if (lseek (fdi, -n, 1) == -1)
  1568. X                break;
  1569. X            if (write (fdi, store, n) != n)
  1570. X                break;
  1571. X        }
  1572. X    }
  1573. X}
  1574. X            
  1575. Xint
  1576. Xmain (argc, argv)
  1577. Xint argc;
  1578. Xchar *argv[];
  1579. X{
  1580. X    register int    t;
  1581. X
  1582. X    for (t = 0; t < 256; ++t)
  1583. X        if ((t >= 'a' && t <= 'm') || (t >= 'A' && t <= 'M'))
  1584. X            table[t] = t + 13;
  1585. X        else if ((t >= 'n' && t <= 'z') || (t >= 'N' && t <= 'Z'))
  1586. X            table[t] = t - 13;
  1587. X        else
  1588. X            table[t] = t;
  1589. X    if (argc == 1)
  1590. X        rot (0, 1);
  1591. X    else
  1592. X        for (t = 1; t < argc; ++t) {
  1593. X            int    fd = open (argv[t], S_IREAD | S_IWRITE);
  1594. X
  1595. X            if (fd != -1) {
  1596. X                rot (fd, -1);
  1597. X                close (fd);
  1598. X            }
  1599. X        }
  1600. X}
  1601. X            
  1602. __END__OF__THIS__FILE__
  1603. if test -f 'MISC/unmap.c' ; then
  1604.   echo 'File MISC/unmap.c already exists, overwriting it'
  1605.   del 'MISC/unmap.c'
  1606. fi
  1607. echo Extracting \"'MISC/unmap.c'\"
  1608. sed "s/^X//" >'MISC/unmap.c' <<'__END__OF__THIS__FILE__'
  1609. X/*
  1610. X * $Log:    unmap.c_v $
  1611. X * Revision 1.1  90/08/31  15:28:37  cv
  1612. X * Initial revision
  1613. X * 
  1614. X */
  1615. X# ifndef    LINT
  1616. Xstatic char rcsid[] = "$Id: unmap.c_v 1.1 90/08/31 15:28:37 cv Exp $";
  1617. Xstatic char copyright[] = "Copyright (C) 1989, 1990 by Ulrich Dessauer, Germering, Germany.\n";
  1618. X# endif        LINT
  1619. X# include    <ctype.h>
  1620. X# include    <modes.h>
  1621. X
  1622. Xextern char    *strdup ();
  1623. X
  1624. Xchar *
  1625. Xskip (s)
  1626. Xregister char *s;
  1627. X{
  1628. X    while (*s && (!isspace (*s)))
  1629. X        ++s;
  1630. X    if (*s)
  1631. X        *s++ = '\0';
  1632. X    while (isspace (*s))
  1633. X        ++s;
  1634. X    return (s);
  1635. X}
  1636. X
  1637. Xchar *
  1638. Xstrip (s)
  1639. Xregister char *s;
  1640. X{
  1641. X    register char    *p;
  1642. X    register char    c;
  1643. X
  1644. X    if ((*s == '\'') || (*s == '"')) {
  1645. X        c = *s++;
  1646. X        p = s;
  1647. X        while (*p && (*p != c))
  1648. X            ++p;
  1649. X        *p = '\0';
  1650. X    }
  1651. X    return (s);
  1652. X}
  1653. X
  1654. Xint
  1655. Xmain (argc, argv)
  1656. Xint argc;
  1657. Xchar *argv[];
  1658. X{
  1659. X    char        buffer[256];
  1660. X    int        n;
  1661. X    int        fd;
  1662. X    char        *eof;
  1663. X    char        *fn;
  1664. X    int        len;
  1665. X    register char    *ptr, *sav;
  1666. X
  1667. X    setuid (getmuid ());
  1668. X    eof = 0;
  1669. X    fn = 0;
  1670. X    fd = -1;
  1671. X    if ((argc != 1) && (argc != 2))
  1672. X        exit (_errmsg (1, "Usage: %s [<directory>].\n", argv[0]));
  1673. X    if (argc == 2)
  1674. X        if (chdir (argv[1]) < 0)
  1675. X            exit (_errmsg (1, "Can't chdir() to %s.\n", argv[1]));
  1676. X    while ((n = readln (0, buffer, 256)) > 0) {
  1677. X        buffer[n - 1] = '\0';
  1678. X        if (!_strnccmp (buffer, "cat ", 4)) {
  1679. X            sav = skip (buffer);
  1680. X            do {
  1681. X                ptr = skip (sav);
  1682. X                if ((!strcmp (sav, "<<")) && (!eof)) {
  1683. X                    sav = ptr;
  1684. X                    ptr = skip (sav);
  1685. X                    sav = strip (sav);
  1686. X                    eof = strdup (sav);
  1687. X                } else if ((!strcmp (sav, ">")) && (!fn)) {
  1688. X                    sav = ptr;
  1689. X                    ptr = skip (sav);
  1690. X                    sav = strip (sav);
  1691. X                    fn = strdup (sav);
  1692. X                }
  1693. X                sav = ptr;
  1694. X            } while (*sav);
  1695. X            if (eof && fn)
  1696. X                break;
  1697. X        }
  1698. X    }
  1699. X    if ((n > 0) && eof && fn) {
  1700. X        if ((fd = creat (fn, S_IWRITE)) != -1) {
  1701. X            chmod (fn, 013);
  1702. X            len = strlen (eof);
  1703. X            while ((n = readln (0, buffer, 256)) > 0) {
  1704. X                buffer[n - 1] = '\0';
  1705. X                if (n >= len && (!strcmp (eof, buffer)))
  1706. X                    break;
  1707. X                else {
  1708. X                    write (fd, buffer, n - 1);
  1709. X                    write (fd, "\n", 1);
  1710. X                }
  1711. X            }
  1712. X            close (fd);
  1713. X        }
  1714. X    }
  1715. X    if (n > 0)
  1716. X        while (readln (0, buffer, 256) > 0)
  1717. X            ;
  1718. X    close (0);
  1719. X}
  1720. __END__OF__THIS__FILE__
  1721. if test -f 'RNEWS/Makefile' ; then
  1722.   echo 'File RNEWS/Makefile already exists, overwriting it'
  1723.   del 'RNEWS/Makefile'
  1724. fi
  1725. echo Extracting \"'RNEWS/Makefile'\"
  1726. sed "s/^X//" >'RNEWS/Makefile' <<'__END__OF__THIS__FILE__'
  1727. X# $Id: Makefile_v 1.1 90/08/31 15:37:55 ud Exp $
  1728. X# $Log:    Makefile_v $
  1729. X# Revision 1.1  90/08/31  15:37:55  ud
  1730. X# Initial revision
  1731. X# 
  1732. X#
  1733. XCC=    cc
  1734. XG=    -g
  1735. XCFLAGS=    -qt=/dd/TMP $G -v=..
  1736. XLIBS=    -l=/dd/LIB/os9lib.l
  1737. XLFLAGS=    -qm=4 $(LIBS) $G
  1738. XODIR=    /h0/ETC/CMDS
  1739. X
  1740. XRNEWSC=    rnews.c send.c compr.c compr7.c logit.c mail.c
  1741. XRNEWSR=    rnews.r send.r compr.r compr7.r logit.r mail.r
  1742. X
  1743. X$(ODIR)/rnews:    $(RNEWSR)
  1744. X    $(CC) $(LFLAGS) $(RNEWSR) -f=$(ODIR)/rnews
  1745. X
  1746. Xtags:    $(RNEWSC)
  1747. X    ctags $?
  1748. __END__OF__THIS__FILE__
  1749. if test -f 'RNEWS/compr.c' ; then
  1750.   echo 'File RNEWS/compr.c already exists, overwriting it'
  1751.   del 'RNEWS/compr.c'
  1752. fi
  1753. echo Extracting \"'RNEWS/compr.c'\"
  1754. sed "s/^X//" >'RNEWS/compr.c' <<'__END__OF__THIS__FILE__'
  1755. X/*
  1756. X * $Log:    compr.c_v $
  1757. X * Revision 1.1  90/08/31  15:37:57  ud
  1758. X * Initial revision
  1759. X * 
  1760. X */
  1761. X# ifndef    LINT
  1762. Xstatic char rcsid[] = "$Id: compr.c_v 1.1 90/08/31 15:37:57 ud Exp $";
  1763. X# endif        LINT
  1764. X# include <stdio.h>
  1765. X# include <modes.h>
  1766. X# include <ctype.h>
  1767. X# include "rnews.h"
  1768. X
  1769. Xextern void    logit ();
  1770. Xextern void    start_rnews ();
  1771. Xextern long    lseek ();
  1772. Xextern char    *findmod ();
  1773. Xextern char    *index ();
  1774. Xextern char    *mktemp ();
  1775. Xextern char    *strcpy ();
  1776. X
  1777. Xextern int    errno;
  1778. X
  1779. Xvoid
  1780. Xdo_exec (cmd,w,r)
  1781. Xchar *cmd;
  1782. Xint w,r;
  1783. X{
  1784. X    extern int    os9forkc ();
  1785. X    extern char    **environ;
  1786. X    int        o0, o1;
  1787. X    char        **arg;
  1788. X    int        t, status, pid;
  1789. X    
  1790. X    o0 = dup (0);
  1791. X    o1 = dup (1);
  1792. X    (void) close (0);
  1793. X    (void) dup (w);
  1794. X    (void) close (1);
  1795. X    (void) dup (r);
  1796. X    t = 0;
  1797. X    if (getargs (cmd, &arg) > 0) {
  1798. X        logit (4,"Fork: '%s'\n",arg[0]);
  1799. X        if ((pid = os9exec (os9forkc,findmod (arg[0],arg[0]),arg,environ,0,0,3)) < 0) {
  1800. X            logit (2,"ERROR: Can't fork '%s'\n", arg[0]);
  1801. X            error |= FATAL;
  1802. X            return;
  1803. X        } else
  1804. X            while (((t = wait (&status)) != pid) && (t != -1))
  1805. X                ;
  1806. X        logit (status ? 2 : 3,"'%s' returns %d\n",arg[0],status);
  1807. X    } else {
  1808. X        error |= FATAL;
  1809. X        logit (2, "ERROR: Can't alloc memory for getargs\n");
  1810. X    }
  1811. X    (void) close (0);
  1812. X    (void) dup (o0);
  1813. X    (void) close (o0);
  1814. X    (void) close (1);
  1815. X    (void) dup (o1);
  1816. X    (void) close (o1);
  1817. X    if (status)
  1818. X        error |= FATAL;
  1819. X}
  1820. X
  1821. Xvoid    
  1822. Xcompr (fd,scratch,cmd)
  1823. Xint fd;
  1824. Xint scratch;
  1825. Xchar *cmd;
  1826. X{
  1827. X    char        tmp[40 + sizeof (TEMPDIR)];
  1828. X    char        *buf;
  1829. X    register char    *x;
  1830. X    register int    n;
  1831. X    unsigned int    siz, temp;
  1832. X    int        o;
  1833. X    
  1834. X    (void) sprintf (tmp,"%s/compr.XXXXXX", TEMPDIR);
  1835. X    (void) mktemp (tmp);
  1836. X    _unlink (tmp);
  1837. X    siz = 20000;
  1838. X    while ((siz != 0) && ((buf = malloc (siz + 5)) == (char *) NULL))
  1839. X        siz -= 1000;
  1840. X    if (!siz) {
  1841. X        logit (2,"ERROR: Can't alloc memory\n");
  1842. X        error |= SIMPLE;
  1843. X        return;
  1844. X    }
  1845. X    if ((o = create (tmp,S_IREAD | S_IWRITE,03, 0)) < 0) {
  1846. X        logit (2,"ERROR: Can't create tmpfile '%s'\n",tmp);
  1847. X        error |= SIMPLE;
  1848. X        free (buf);
  1849. X        return;
  1850. X    }
  1851. X    errno = 0;
  1852. X    while ((n = read (fd,buf,siz)) > 0) {
  1853. X        logit (6,"Read %d bytes\n",n);
  1854. X        x = buf;
  1855. X        temp = (unsigned int) n;
  1856. X        while (n-- > 0) {
  1857. X            if (*x && (index ("\l\r",*x) != (char *) NULL))
  1858. X                *x = *x == '\l' ? '\r' : '\l';
  1859. X            ++x;
  1860. X        }
  1861. X        n = write (o,buf,temp);
  1862. X        logit (6,"Wrote %d bytes\n",n);
  1863. X        if (n < 0) {
  1864. X            logit (2,"ERROR: Can't write tmpfile '%s'\n", tmp);
  1865. X            close (o);
  1866. X            _unlink (tmp);
  1867. X            error |= SIMPLE;
  1868. X            free (buf);
  1869. X            return;
  1870. X        }
  1871. X    }
  1872. X    (void) lseek (o,0,0);
  1873. X    o = uncompress_it (o,tmp,cmd);
  1874. X    if (error) {
  1875. X        if (o != -1)
  1876. X            (void) close (o);
  1877. X        _unlink (tmp);
  1878. X        free (buf);
  1879. X        return;
  1880. X    } else {
  1881. X        close (o);
  1882. X        if ((o = open (tmp, S_IREAD)) < 0) {
  1883. X            _unlink (tmp);
  1884. X            free (buf);
  1885. X            error |= SIMPLE;
  1886. X            return;
  1887. X        }
  1888. X    }
  1889. X    start_rnews (o,scratch);
  1890. X    (void) close (o);
  1891. X    _unlink (tmp);
  1892. X    free (buf);
  1893. X}
  1894. X
  1895. Xint
  1896. Xuncompress_it (o,ofile,cmd)
  1897. Xint o;
  1898. Xchar *ofile;
  1899. Xchar *cmd;
  1900. X{
  1901. X    char        tmp[40 + sizeof (TEMPDIR)];
  1902. X    char        *ucpr;
  1903. X    char        *buf;
  1904. X    unsigned int    siz, temp;
  1905. X    register int    n;
  1906. X    register char    *x;
  1907. X    int        w;
  1908. X    
  1909. X    (void) sprintf (tmp, "%s/uncpr.XXXXXX", TEMPDIR);
  1910. X    (void) mktemp (tmp);
  1911. X    _unlink (tmp);
  1912. X    if (((ucpr = malloc ((unsigned int) (strlen (cmd) + 2))) == (char *) NULL) || ((w = create (tmp,S_IREAD | S_IWRITE,03, 0)) < 0)) {
  1913. X        error |= FATAL;
  1914. X        return (-1);
  1915. X    } else
  1916. X        (void) strcpy (ucpr,cmd);
  1917. X    do_exec (ucpr,o,w);
  1918. X    (void) close (o);
  1919. X    (void) unlink (ofile);
  1920. X    if (error) {
  1921. X        (void) close (w);
  1922. X        _unlink (tmp);
  1923. X        free (ucpr);
  1924. X        return (-1);
  1925. X    }
  1926. X    if ((o = create (ofile,S_IREAD | S_IWRITE,03)) < 0) {
  1927. X        logit (2,"ERROR: Can't create tmpfile '%s'\n",ofile);
  1928. X        (void) close (w);
  1929. X        _unlink (tmp);
  1930. X        free (ucpr);
  1931. X        error |= FATAL;
  1932. X        return (-1);
  1933. X    }
  1934. X    (void) lseek (w,0,0);
  1935. X    siz = 20000;
  1936. X    while (siz && ((buf = malloc (siz + 5)) == (char *) NULL))
  1937. X        siz -= 1000;
  1938. X    if (!siz) {
  1939. X        (void) close (w);
  1940. X        _unlink (tmp);
  1941. X        error |= FATAL;
  1942. X        free (ucpr);
  1943. X        return (o);
  1944. X    }
  1945. X    while ((n = read (w,buf,siz)) > 0) {
  1946. X        logit (6,"Read %d bytes\n",n);
  1947. X        temp = (unsigned int) n;
  1948. X        x = buf;
  1949. X        while (n-- > 0) {
  1950. X            if (*x && (index ("\l\r",*x) != (char *) NULL))
  1951. X                *x = *x == '\l' ? '\r' : '\l';
  1952. X            ++x;
  1953. X        }            
  1954. X        n = write (o,buf,temp);
  1955. X        logit (6,"Wrote %d bytes\n",n);
  1956. X        if (n < 0) {
  1957. X            logit (2,"ERROR: Can't write data to '%s'\n",ofile);
  1958. X            close (o);
  1959. X            o = -1;
  1960. X            error |= FATAL;
  1961. X            break;
  1962. X        }
  1963. X    }
  1964. X    (void) close (w);
  1965. X    free (buf);
  1966. X    free (ucpr);
  1967. X    _unlink (tmp);
  1968. X    return (o);
  1969. X}
  1970. __END__OF__THIS__FILE__
  1971. exit 0
  1972. : end of shell archive
  1973.  
  1974. -- 
  1975. Frank Kaefer # fkk@stasys.sta.sub.org # Starnberg, Germany
  1976.