home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3170 < prev    next >
Encoding:
Internet Message Format  |  1991-04-08  |  8.7 KB

  1. From: rob@mtdiablo.Concord.CA.US (Rob Bernardo)
  2. Newsgroups: alt.sources
  3. Subject: New rebatch compatible with cnews of patchdate 24-Mar-1991
  4. Message-ID: <1991Apr4.031152.17236@mtdiablo.Concord.CA.US>
  5. Date: 4 Apr 91 03:11:52 GMT
  6.  
  7.  
  8. I have updated rebatch to deal (only) with compressed news batches that
  9. end in .Z, as found with cnews of patchdate 24-Mar-1991.  The wrapper
  10. shell script included in in this version of rebatch is **not**
  11. compatible with earlier versions of cnews that do not suffix compressed
  12. news batches with .Z.  The C program dorebatch has been improved.  It
  13. should work with the older rebatch wrapper shell script, but I have not
  14. tested them together.
  15.  
  16. From the README file:
  17.  
  18.     This program will reform news batches that suffer from relaynews 'unbatcher
  19.     out of sync' problems. It presumes that any line beginning with
  20.        #! rnews
  21.     is the beginning of a new article and reforms the news batches by parsing
  22.     them into separate articles and recalculating the article character counts.
  23.  
  24.     This program consists of a C program dorebatch and a wrapper shell
  25.     script.
  26.  
  27.  
  28. ---- Cut Here and unpack ----
  29. #!/bin/sh
  30. # shar:    Shell Archiver  (v1.22)
  31. #    Packed Wed Apr  3 18:59:08 PST 1991 by mtdiablo!rob
  32. #    from directory /tmp/rebatch
  33. #
  34. #    Run the following text with /bin/sh to create:
  35. #      Makefile
  36. #      README
  37. #      dorebatch.c
  38. #      rebatch
  39. #
  40. if test -f Makefile; then echo "File Makefile exists"; else
  41. echo "x - extracting Makefile (Text)"
  42. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  43. XNEWSOWNER=bin
  44. XNEWSGRP=bin
  45. XMODE=755
  46. XNEWSLIB=/usr/local/lib
  47. X
  48. Xall:    dorebatch
  49. X
  50. Xinstall:    dorebatch
  51. X    install -g ${NEWSGRP} -o ${NEWSOWNER} -m ${MODE} rebatch ${NEWSLIB}/newsbin/batch
  52. X    install -g ${NEWSGRP} -o ${NEWSOWNER} -m ${MODE} dorebatch ${NEWSLIB}/newsbin/batch
  53. SHAR_EOF
  54. chmod 0644 Makefile || echo "restore of Makefile fails"
  55. set `wc -c Makefile`;Sum=$1
  56. if test "$Sum" != "262"
  57. then echo original size 262, current size $Sum;fi
  58. fi
  59. if test -f README; then echo "File README exists"; else
  60. echo "x - extracting README (Text)"
  61. sed 's/^X//' << 'SHAR_EOF' > README &&
  62. X@(#)README    1.2    Delta Date 4/3/91    Mt. Diablo Software Solutions
  63. X
  64. XThis version of rebatch is compatible with cnews with a last patchdate of
  65. X24-Mar-1991.
  66. X
  67. XThis program will reform news batches that suffer from relaynews 'unbatcher
  68. Xout of sync' problems. It presumes that any line beginning with 
  69. X    #! rnews
  70. Xis the beginning of a new article and reforms the news batches by parsing
  71. Xthem into separate articles and recalculating the article character counts. 
  72. X
  73. XThis program consists of a C program dorebatch and a wrapper shell
  74. Xscript. The command line syntax for dorebatch is
  75. X
  76. X    dorebatch [-v] -i input_file -o output_file
  77. X
  78. Xwhere -v enables slightly verbose messages, and where input_file and
  79. Xoutput_file are the old and reformed *uncompressed* news archive files,
  80. Xrespectively.
  81. X
  82. XThe shell wrapper rebatch (used with no arguments), will run dorebatch
  83. Xon all *compressed* .Z files in the cnews in.coming/bad directory and
  84. Xwill create a reformed *compressed* news archive of the same name in
  85. Xin.coming/, where cnews newsrun can reprocess them again.  If successful
  86. Xin reforming the batch, rebatch will remove the old .Z file in in.coming/bad.
  87. X
  88. XYou may need to tailor rebatch for you particular cnews configuration.
  89. X
  90. XA trivial makefile is supplied to compile and install dorebatch and rebatch,
  91. Xhowever it uses the SUN O/S flavor of install(1), which you may need to
  92. Xrework for you flavor of UNIX.
  93. SHAR_EOF
  94. chmod 0444 README || echo "restore of README fails"
  95. set `wc -c README`;Sum=$1
  96. if test "$Sum" != "1388"
  97. then echo original size 1388, current size $Sum;fi
  98. fi
  99. if test -f dorebatch.c; then echo "File dorebatch.c exists"; else
  100. echo "x - extracting dorebatch.c (Text)"
  101. sed 's/^X//' << 'SHAR_EOF' > dorebatch.c &&
  102. X#ifndef lint
  103. Xstatic char sccsid[] = "@(#)dorebatch.c    1.2    Delta Date 4/3/91  Mt. Diablo Software Solutions";
  104. X#endif
  105. X
  106. X#define ZCAT "zcat"
  107. X#define RNEWSSTRING "#! rnews"
  108. X
  109. X#include <stdio.h>
  110. X
  111. Xint verbose;
  112. Xextern int errno;
  113. Xextern int sys_nerr;
  114. Xextern char *sys_errlist[];
  115. X
  116. X#define ERRNO_MSG    (errno < sys_nerr ? sys_errlist[errno] : "unknown errno")
  117. X
  118. Xmain(argc, argv)
  119. Xint argc;
  120. Xchar **argv;
  121. X{
  122. X    char dataline[BUFSIZ];
  123. X    char *infile = NULL, *outfile = NULL;
  124. X    FILE *infp, *outfp;
  125. X    long artbegin, artend, nextartbegin;
  126. X    int eofreached, optret, rnewslen, charcnt, artcnt, argerr;
  127. X    extern int optind;
  128. X    extern char *optarg;
  129. X
  130. X    /* Process command line */
  131. X    argerr = 0;
  132. X    while ((optret = getopt(argc, argv, "vi:o:")) != -1) {
  133. X    switch (optret) {
  134. X    case 'v':
  135. X        verbose = 1;
  136. X        break;
  137. X    case 'i':
  138. X        infile = optarg;
  139. X        break;
  140. X
  141. X    case 'o':
  142. X        outfile = optarg;
  143. X        break;
  144. X
  145. X    default:
  146. X        argerr++;
  147. X    }
  148. X    }
  149. X
  150. X    if(!infile || !outfile || argerr) {
  151. X    fprintf(stderr, "%s: usage: %s -i [infile] -o [outfile]\n",
  152. X            argv[0], argv[0]);
  153. X    exit(-1);
  154. X    }
  155. X
  156. X    /* Open input file */
  157. X    if((infp = fopen(infile, "r")) == NULL) {
  158. X    fprintf(stderr, "%s: fopen(%s, \"r\") failed\n", argv[0], infile);
  159. X    exit(errno?errno:-1);
  160. X    }
  161. X
  162. X    /* Open output file */
  163. X    if((outfp = fopen(outfile, "w+")) == NULL) {
  164. X    fprintf(stderr, "%s: fopen(%s, \"w+\") failed\n", argv[0], outfile);
  165. X    fclose(infp);
  166. X    exit(errno?errno:-1);
  167. X    }
  168. X
  169. X    /* Verify first line is rnews */
  170. X    if(fgets(dataline, BUFSIZ, infp) == NULL) {
  171. X    fprintf(stderr, "%s: premature end of file %s\n", argv[0], infile);
  172. X    fclose(infp);
  173. X    exit(errno?errno:-1);
  174. X    }
  175. X    rnewslen = strlen(RNEWSSTRING);
  176. X    if(strncmp(dataline, RNEWSSTRING, rnewslen)) {
  177. X    fprintf(stderr, "%s: file %s not a news archive\n",
  178. X        argv[0], infile);
  179. X    fclose(infp);
  180. X    exit(errno?errno:-1);
  181. X    }
  182. X    artbegin = artend = ftell(infp);
  183. X    eofreached = 0;
  184. X    artcnt = 0;
  185. X
  186. X    if(verbose)
  187. X    printf("input = %s output = %s\n", infile, outfile);
  188. X
  189. X    /* Process each article in batch */
  190. X    while(!eofreached) {
  191. X
  192. X    /* Read a line from input. If oef or end of article,
  193. X     * capture begin point of next article,
  194. X     * calculate article size from end and begin points
  195. X     * of current article,
  196. X     * write rnews line with size on output file,
  197. X     * rewind to begin point of current article,
  198. X     * copy article to output file and quite loop,
  199. X     * and advance to new article begin point.
  200. X     * Otherwise store current point as provisional
  201. X     * end point of current article.
  202. X     */
  203. X    while (1) {
  204. X        if(fgets(dataline, BUFSIZ, infp) == NULL)
  205. X        eofreached = 1;
  206. X
  207. X        if(eofreached||(!strncmp(dataline, RNEWSSTRING, rnewslen))) {
  208. X
  209. X        nextartbegin = ftell(infp);
  210. X        charcnt = artend - artbegin;
  211. X        fprintf(outfp, "%s %d\n", RNEWSSTRING, charcnt);
  212. X        if(verbose)
  213. X            printf("article %d charcnt %d\n", artcnt, charcnt);
  214. X        if(fseek(infp, artbegin, 0) == -1) {
  215. X            fprintf(stderr, "%s: fseek back to article beginning failed\n", argv[0]);
  216. X                fclose(infp);
  217. X                    fclose(outfp);
  218. X                    exit(errno?errno:-1);
  219. X        }
  220. X        while(ftell(infp) < artend) {
  221. X            if(fgets(dataline, BUFSIZ, infp) == NULL) {
  222. X            fprintf(stderr, "%s: fgets from %s failed\n",
  223. X                argv[0], infile);
  224. X            fclose(infp);
  225. X            fclose(outfp);
  226. X            exit(errno?errno:-1);
  227. X            }
  228. X            if(fputs(dataline, outfp) == EOF) {
  229. X            fprintf(stderr, "%s: fputs to %s failed\n",
  230. X                argv[0], outfile);
  231. X            fclose(infp);
  232. X            fclose(outfp);
  233. X            exit(errno?errno:-1);
  234. X            }
  235. X        } 
  236. X        artcnt++;
  237. X        artbegin = artend = nextartbegin;
  238. X        if(fseek(infp, artbegin, 0) == -1) {
  239. X            fprintf(stderr, "%s: fseek back to article beginning failed\n", argv[0]);
  240. X                fclose(infp);
  241. X                    fclose(outfp);
  242. X                    exit(errno?errno:-1);
  243. X        }
  244. X        break;
  245. X
  246. X        } else 
  247. X        artend = ftell(infp);
  248. X    }
  249. X    }
  250. X
  251. X    fclose(infp);
  252. X    fclose(outfp);
  253. X    exit(0);
  254. X}
  255. SHAR_EOF
  256. chmod 0444 dorebatch.c || echo "restore of dorebatch.c fails"
  257. set `wc -c dorebatch.c`;Sum=$1
  258. if test "$Sum" != "3821"
  259. then echo original size 3821, current size $Sum;fi
  260. fi
  261. if test -f rebatch; then echo "File rebatch exists"; else
  262. echo "x - extracting rebatch (Text)"
  263. sed 's/^X//' << 'SHAR_EOF' > rebatch &&
  264. X#! /bin/sh
  265. X# @(#)rebatch    1.3    Delta Date 4/3/91  Mt. Diablo Software Solutions
  266. X# =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  267. X. ${NEWSCONFIG-/usr/local/lib/news/bin/config}
  268. Xumask $NEWSUMASK
  269. X
  270. XPATH=$NEWSCTL/bin:$NEWSBIN/batch:$NEWSBIN:$NEWSPATH ; export PATH
  271. XTMP=/tmp/rebatch$$
  272. Xfor file in  ${NEWSARTS}/in.coming/bad/*.Z
  273. Xdo
  274. X    barename=`basename $file`
  275. X    newbatch=`echo "${NEWSARTS}/in.coming/$barename" | sed -e 's/.Z$//'`
  276. X    echo "rebatching $barename"
  277. X    zcat $file > $TMP && dorebatch -i $TMP -o $newbatch && compress $newbatch && rm $file 
  278. X    rm -f $TMP
  279. Xdone
  280. SHAR_EOF
  281. chmod 0444 rebatch || echo "restore of rebatch fails"
  282. set `wc -c rebatch`;Sum=$1
  283. if test "$Sum" != "561"
  284. then echo original size 561, current size $Sum;fi
  285. fi
  286. exit 0
  287. -- 
  288. Rob Bernardo                    Mt. Diablo Software Solutions
  289. email: rob@mtdiablo.Concord.CA.US        phone: (415) 827-4301
  290.