Home » Archimedes archive » Acorn User » AU 1995-07.adf » !Internet_StarterPak » !Newsbase/Support/taylor/csrc/c/lrnews

!Newsbase/Support/taylor/csrc/c/lrnews

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1995-07.adf » !Internet_StarterPak
Filename: !Newsbase/Support/taylor/csrc/c/lrnews
Read OK:
File size: 1104 bytes
Load address: 0000
Exec address: 0000
File contents
/* lrnews.c - simple news unbatching program.
 *
 * Author:  	    Gunnar Z�tl
 * Date:    	    18-Sep-1994
 * Last Modified:   18-Sep-1994
 *
 * Usage: lrnews < newsbatch
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <kernel.h>
#include "upath.h"
#include "config.h"

#ifndef FALSE
#define FALSE 0
#define TRUE (!FALSE)
#endif

#ifdef DEBUG
#undef DEBUG
#define DEBUG(x) printf x
#else
#undef DEBUG
#define DEBUG(x)
#endif

/* this tests wether the given file already exists
 */
int file_exists(char *name)
{
    _kernel_osfile_block osfile;
    int found;

    found = _kernel_osfile(5, name, &osfile);
    return found ? TRUE : FALSE;
}

/* this returns one batch name that is guaranteed not to exist in NEWSDEST
 * at the time the value is returned.
 */
char *lrnews_batchname(void)
{
    char buffer[BUFLEN];
    static char name[SBUFLEN];
    char *p, *q;
    sprintf(buffer, "%s%s", getenv(NEWSDEST), DELIM);
    q = buffer + strlen(buffer);
    do
    {
    	sprintf(name, "%u", time(NULL));
    	p = name;
    	strcat(q, p);
    	if (file_exists(upath(buffer)))
    	    p = NULL;
    } while (p == NULL);
    return p;
}

/* appends whatever is on stdin to the given file handle. If the string
 * hdr is not NULL, then it is written to the file first. This is for
 * pre-read #! rnews lines.
 */
int lrnews_saveto(FILE *out, char *hdr)
{
    char buffer[BUFLEN];
    int i;
    if (hdr != NULL)
    	fputs(hdr, out);
    while (!feof(stdin))
    {
    	i = fread(buffer, 1, UPLEN, stdin);
    	fwrite(buffer, 1, i, out);
    }
    return TRUE;
}

int main()
{
    int ret = EXIT_SUCCESS;
    char *r, *s, *t, *u, *batchname;
    FILE *f;
    char buffer[BUFLEN];
    char buffer2[BUFLEN];

    if ((s = getenv(NEWSDEST)) != NULL)
    	s = strcpy(malloc(strlen(s) + 1), s);
    if ((t = getenv(SCRAPDIR)) != NULL)
    	t = strcpy(malloc(strlen(t) + 1), t);
    /* we need both NEWSDEST and SCRAPDIR in order to work.
     */
    if ((s != NULL) && (t != NULL))
    {
    	batchname = lrnews_batchname();
    	r = fgets(buffer, BUFLEN, stdin);
    	DEBUG(("First line in batch is '%s'\n", r));
    	/* if the first line in the article is "#! rnews ...", then we
    	 * copy the batch to NEWSDEST
    	 */
    	if (strncmp(RNEWSHDR, r, strlen(RNEWSHDR)) == 0)
    	{
    	    sprintf(buffer2, "%s%s%s", s, DELIM, batchname);
    	    f = fopen(upath(buffer2), "w");
    	    lrnews_saveto(f, r);
    	    fclose(f);
    	}
    	else
    	{
    	    sprintf(buffer2, "%s%s%s", t, DELIM, batchname);
    	    /* otherwise, if it starts with "#! ", then we extract the
    	     * command it contains and perform it with a scrap copy of
    	     * the batch without the first line as first and the name of
    	     * a (not yet existing) file in NEWSDEST as second argument.
    	     */
    	    if (strncmp(HDRPREFIX, r, strlen(HDRPREFIX)) == 0)
    	    {
	    	f = fopen(buffer2, "w");
    	    	lrnews_saveto(f, NULL);
    	    	fclose(f);
    	    	r = buffer + strlen(HDRPREFIX);
    	    	for (u = r; *u > ' '; ++u);
    	    	*u = 0;
    	    	strcat(r, " ");
    	    	strcat(r, buffer2);
    	    	strcat(r, " ");
    	    	sprintf(buffer2, "%s%s%s", s, DELIM, batchname);
    	    	strcat(r, buffer2);
    	    	if (system(r) != 0)
    	    	{
    	            fprintf(stderr, "Could not perform '%s'\n", buffer);
    	            ret = EXIT_FAILURE;
    	    	}
    	    	else
    	    	/* if all went well, we remove the temp. file in SCRAPDIR
    	    	 */
    	    	{
    	    	    sprintf(buffer2, "%s%s%s", t, DELIM, batchname);
    	    	    remove(upath(buffer2));
    	    	}
    	    }
    	    else
    	    /* you get here when the batch has no "#! ..." header. If you'd
    	     * rather like the article to be copied to NEWSDEST, insert the
    	     * code to do so here.
    	     */
    	    {
	    	f = fopen(buffer2, "w");
    	    	lrnews_saveto(f, r);
    	    	fclose(f);
    	        fprintf(stderr, "Don't know how to handle current batch, it is in %s\n", buffer2);
    	        ret = EXIT_FAILURE;
    	    }
    	}
    }
    else
    {
        if (s == NULL)
    	    fprintf(stderr, "Environment variable %s not found\n", NEWSDEST);
    	if (t == NULL)
    	    fprintf(stderr, "%s must have been set.\n", SCRAPDIR);
    	ret = EXIT_FAILURE;
    }
    exit(ret);
}
00000000  2f 2a 20 6c 72 6e 65 77  73 2e 63 20 2d 20 73 69  |/* lrnews.c - si|
00000010  6d 70 6c 65 20 6e 65 77  73 20 75 6e 62 61 74 63  |mple news unbatc|
00000020  68 69 6e 67 20 70 72 6f  67 72 61 6d 2e 0a 20 2a  |hing program.. *|
00000030  0a 20 2a 20 41 75 74 68  6f 72 3a 20 20 09 20 20  |. * Author:  .  |
00000040  20 20 47 75 6e 6e 61 72  20 5a f6 74 6c 0a 20 2a  |  Gunnar Z.tl. *|
00000050  20 44 61 74 65 3a 20 20  20 20 09 20 20 20 20 31  | Date:    .    1|
00000060  38 2d 53 65 70 2d 31 39  39 34 0a 20 2a 20 4c 61  |8-Sep-1994. * La|
00000070  73 74 20 4d 6f 64 69 66  69 65 64 3a 20 20 20 31  |st Modified:   1|
00000080  38 2d 53 65 70 2d 31 39  39 34 0a 20 2a 0a 20 2a  |8-Sep-1994. *. *|
00000090  20 55 73 61 67 65 3a 20  6c 72 6e 65 77 73 20 3c  | Usage: lrnews <|
000000a0  20 6e 65 77 73 62 61 74  63 68 0a 20 2a 2f 0a 0a  | newsbatch. */..|
000000b0  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
000000c0  68 3e 0a 23 69 6e 63 6c  75 64 65 20 3c 73 74 64  |h>.#include <std|
000000d0  6c 69 62 2e 68 3e 0a 23  69 6e 63 6c 75 64 65 20  |lib.h>.#include |
000000e0  3c 73 74 72 69 6e 67 2e  68 3e 0a 23 69 6e 63 6c  |<string.h>.#incl|
000000f0  75 64 65 20 3c 74 69 6d  65 2e 68 3e 0a 23 69 6e  |ude <time.h>.#in|
00000100  63 6c 75 64 65 20 3c 6b  65 72 6e 65 6c 2e 68 3e  |clude <kernel.h>|
00000110  0a 23 69 6e 63 6c 75 64  65 20 22 75 70 61 74 68  |.#include "upath|
00000120  2e 68 22 0a 23 69 6e 63  6c 75 64 65 20 22 63 6f  |.h".#include "co|
00000130  6e 66 69 67 2e 68 22 0a  0a 23 69 66 6e 64 65 66  |nfig.h"..#ifndef|
00000140  20 46 41 4c 53 45 0a 23  64 65 66 69 6e 65 20 46  | FALSE.#define F|
00000150  41 4c 53 45 20 30 0a 23  64 65 66 69 6e 65 20 54  |ALSE 0.#define T|
00000160  52 55 45 20 28 21 46 41  4c 53 45 29 0a 23 65 6e  |RUE (!FALSE).#en|
00000170  64 69 66 0a 0a 23 69 66  64 65 66 20 44 45 42 55  |dif..#ifdef DEBU|
00000180  47 0a 23 75 6e 64 65 66  20 44 45 42 55 47 0a 23  |G.#undef DEBUG.#|
00000190  64 65 66 69 6e 65 20 44  45 42 55 47 28 78 29 20  |define DEBUG(x) |
000001a0  70 72 69 6e 74 66 20 78  0a 23 65 6c 73 65 0a 23  |printf x.#else.#|
000001b0  75 6e 64 65 66 20 44 45  42 55 47 0a 23 64 65 66  |undef DEBUG.#def|
000001c0  69 6e 65 20 44 45 42 55  47 28 78 29 0a 23 65 6e  |ine DEBUG(x).#en|
000001d0  64 69 66 0a 0a 2f 2a 20  74 68 69 73 20 74 65 73  |dif../* this tes|
000001e0  74 73 20 77 65 74 68 65  72 20 74 68 65 20 67 69  |ts wether the gi|
000001f0  76 65 6e 20 66 69 6c 65  20 61 6c 72 65 61 64 79  |ven file already|
00000200  20 65 78 69 73 74 73 0a  20 2a 2f 0a 69 6e 74 20  | exists. */.int |
00000210  66 69 6c 65 5f 65 78 69  73 74 73 28 63 68 61 72  |file_exists(char|
00000220  20 2a 6e 61 6d 65 29 0a  7b 0a 20 20 20 20 5f 6b  | *name).{.    _k|
00000230  65 72 6e 65 6c 5f 6f 73  66 69 6c 65 5f 62 6c 6f  |ernel_osfile_blo|
00000240  63 6b 20 6f 73 66 69 6c  65 3b 0a 20 20 20 20 69  |ck osfile;.    i|
00000250  6e 74 20 66 6f 75 6e 64  3b 0a 0a 20 20 20 20 66  |nt found;..    f|
00000260  6f 75 6e 64 20 3d 20 5f  6b 65 72 6e 65 6c 5f 6f  |ound = _kernel_o|
00000270  73 66 69 6c 65 28 35 2c  20 6e 61 6d 65 2c 20 26  |sfile(5, name, &|
00000280  6f 73 66 69 6c 65 29 3b  0a 20 20 20 20 72 65 74  |osfile);.    ret|
00000290  75 72 6e 20 66 6f 75 6e  64 20 3f 20 54 52 55 45  |urn found ? TRUE|
000002a0  20 3a 20 46 41 4c 53 45  3b 0a 7d 0a 0a 2f 2a 20  | : FALSE;.}../* |
000002b0  74 68 69 73 20 72 65 74  75 72 6e 73 20 6f 6e 65  |this returns one|
000002c0  20 62 61 74 63 68 20 6e  61 6d 65 20 74 68 61 74  | batch name that|
000002d0  20 69 73 20 67 75 61 72  61 6e 74 65 65 64 20 6e  | is guaranteed n|
000002e0  6f 74 20 74 6f 20 65 78  69 73 74 20 69 6e 20 4e  |ot to exist in N|
000002f0  45 57 53 44 45 53 54 0a  20 2a 20 61 74 20 74 68  |EWSDEST. * at th|
00000300  65 20 74 69 6d 65 20 74  68 65 20 76 61 6c 75 65  |e time the value|
00000310  20 69 73 20 72 65 74 75  72 6e 65 64 2e 0a 20 2a  | is returned.. *|
00000320  2f 0a 63 68 61 72 20 2a  6c 72 6e 65 77 73 5f 62  |/.char *lrnews_b|
00000330  61 74 63 68 6e 61 6d 65  28 76 6f 69 64 29 0a 7b  |atchname(void).{|
00000340  0a 20 20 20 20 63 68 61  72 20 62 75 66 66 65 72  |.    char buffer|
00000350  5b 42 55 46 4c 45 4e 5d  3b 0a 20 20 20 20 73 74  |[BUFLEN];.    st|
00000360  61 74 69 63 20 63 68 61  72 20 6e 61 6d 65 5b 53  |atic char name[S|
00000370  42 55 46 4c 45 4e 5d 3b  0a 20 20 20 20 63 68 61  |BUFLEN];.    cha|
00000380  72 20 2a 70 2c 20 2a 71  3b 0a 20 20 20 20 73 70  |r *p, *q;.    sp|
00000390  72 69 6e 74 66 28 62 75  66 66 65 72 2c 20 22 25  |rintf(buffer, "%|
000003a0  73 25 73 22 2c 20 67 65  74 65 6e 76 28 4e 45 57  |s%s", getenv(NEW|
000003b0  53 44 45 53 54 29 2c 20  44 45 4c 49 4d 29 3b 0a  |SDEST), DELIM);.|
000003c0  20 20 20 20 71 20 3d 20  62 75 66 66 65 72 20 2b  |    q = buffer +|
000003d0  20 73 74 72 6c 65 6e 28  62 75 66 66 65 72 29 3b  | strlen(buffer);|
000003e0  0a 20 20 20 20 64 6f 0a  20 20 20 20 7b 0a 20 20  |.    do.    {.  |
000003f0  20 20 09 73 70 72 69 6e  74 66 28 6e 61 6d 65 2c  |  .sprintf(name,|
00000400  20 22 25 75 22 2c 20 74  69 6d 65 28 4e 55 4c 4c  | "%u", time(NULL|
00000410  29 29 3b 0a 20 20 20 20  09 70 20 3d 20 6e 61 6d  |));.    .p = nam|
00000420  65 3b 0a 20 20 20 20 09  73 74 72 63 61 74 28 71  |e;.    .strcat(q|
00000430  2c 20 70 29 3b 0a 20 20  20 20 09 69 66 20 28 66  |, p);.    .if (f|
00000440  69 6c 65 5f 65 78 69 73  74 73 28 75 70 61 74 68  |ile_exists(upath|
00000450  28 62 75 66 66 65 72 29  29 29 0a 20 20 20 20 09  |(buffer))).    .|
00000460  20 20 20 20 70 20 3d 20  4e 55 4c 4c 3b 0a 20 20  |    p = NULL;.  |
00000470  20 20 7d 20 77 68 69 6c  65 20 28 70 20 3d 3d 20  |  } while (p == |
00000480  4e 55 4c 4c 29 3b 0a 20  20 20 20 72 65 74 75 72  |NULL);.    retur|
00000490  6e 20 70 3b 0a 7d 0a 0a  2f 2a 20 61 70 70 65 6e  |n p;.}../* appen|
000004a0  64 73 20 77 68 61 74 65  76 65 72 20 69 73 20 6f  |ds whatever is o|
000004b0  6e 20 73 74 64 69 6e 20  74 6f 20 74 68 65 20 67  |n stdin to the g|
000004c0  69 76 65 6e 20 66 69 6c  65 20 68 61 6e 64 6c 65  |iven file handle|
000004d0  2e 20 49 66 20 74 68 65  20 73 74 72 69 6e 67 0a  |. If the string.|
000004e0  20 2a 20 68 64 72 20 69  73 20 6e 6f 74 20 4e 55  | * hdr is not NU|
000004f0  4c 4c 2c 20 74 68 65 6e  20 69 74 20 69 73 20 77  |LL, then it is w|
00000500  72 69 74 74 65 6e 20 74  6f 20 74 68 65 20 66 69  |ritten to the fi|
00000510  6c 65 20 66 69 72 73 74  2e 20 54 68 69 73 20 69  |le first. This i|
00000520  73 20 66 6f 72 0a 20 2a  20 70 72 65 2d 72 65 61  |s for. * pre-rea|
00000530  64 20 23 21 20 72 6e 65  77 73 20 6c 69 6e 65 73  |d #! rnews lines|
00000540  2e 0a 20 2a 2f 0a 69 6e  74 20 6c 72 6e 65 77 73  |.. */.int lrnews|
00000550  5f 73 61 76 65 74 6f 28  46 49 4c 45 20 2a 6f 75  |_saveto(FILE *ou|
00000560  74 2c 20 63 68 61 72 20  2a 68 64 72 29 0a 7b 0a  |t, char *hdr).{.|
00000570  20 20 20 20 63 68 61 72  20 62 75 66 66 65 72 5b  |    char buffer[|
00000580  42 55 46 4c 45 4e 5d 3b  0a 20 20 20 20 69 6e 74  |BUFLEN];.    int|
00000590  20 69 3b 0a 20 20 20 20  69 66 20 28 68 64 72 20  | i;.    if (hdr |
000005a0  21 3d 20 4e 55 4c 4c 29  0a 20 20 20 20 09 66 70  |!= NULL).    .fp|
000005b0  75 74 73 28 68 64 72 2c  20 6f 75 74 29 3b 0a 20  |uts(hdr, out);. |
000005c0  20 20 20 77 68 69 6c 65  20 28 21 66 65 6f 66 28  |   while (!feof(|
000005d0  73 74 64 69 6e 29 29 0a  20 20 20 20 7b 0a 20 20  |stdin)).    {.  |
000005e0  20 20 09 69 20 3d 20 66  72 65 61 64 28 62 75 66  |  .i = fread(buf|
000005f0  66 65 72 2c 20 31 2c 20  55 50 4c 45 4e 2c 20 73  |fer, 1, UPLEN, s|
00000600  74 64 69 6e 29 3b 0a 20  20 20 20 09 66 77 72 69  |tdin);.    .fwri|
00000610  74 65 28 62 75 66 66 65  72 2c 20 31 2c 20 69 2c  |te(buffer, 1, i,|
00000620  20 6f 75 74 29 3b 0a 20  20 20 20 7d 0a 20 20 20  | out);.    }.   |
00000630  20 72 65 74 75 72 6e 20  54 52 55 45 3b 0a 7d 0a  | return TRUE;.}.|
00000640  0a 69 6e 74 20 6d 61 69  6e 28 29 0a 7b 0a 20 20  |.int main().{.  |
00000650  20 20 69 6e 74 20 72 65  74 20 3d 20 45 58 49 54  |  int ret = EXIT|
00000660  5f 53 55 43 43 45 53 53  3b 0a 20 20 20 20 63 68  |_SUCCESS;.    ch|
00000670  61 72 20 2a 72 2c 20 2a  73 2c 20 2a 74 2c 20 2a  |ar *r, *s, *t, *|
00000680  75 2c 20 2a 62 61 74 63  68 6e 61 6d 65 3b 0a 20  |u, *batchname;. |
00000690  20 20 20 46 49 4c 45 20  2a 66 3b 0a 20 20 20 20  |   FILE *f;.    |
000006a0  63 68 61 72 20 62 75 66  66 65 72 5b 42 55 46 4c  |char buffer[BUFL|
000006b0  45 4e 5d 3b 0a 20 20 20  20 63 68 61 72 20 62 75  |EN];.    char bu|
000006c0  66 66 65 72 32 5b 42 55  46 4c 45 4e 5d 3b 0a 0a  |ffer2[BUFLEN];..|
000006d0  20 20 20 20 69 66 20 28  28 73 20 3d 20 67 65 74  |    if ((s = get|
000006e0  65 6e 76 28 4e 45 57 53  44 45 53 54 29 29 20 21  |env(NEWSDEST)) !|
000006f0  3d 20 4e 55 4c 4c 29 0a  20 20 20 20 09 73 20 3d  |= NULL).    .s =|
00000700  20 73 74 72 63 70 79 28  6d 61 6c 6c 6f 63 28 73  | strcpy(malloc(s|
00000710  74 72 6c 65 6e 28 73 29  20 2b 20 31 29 2c 20 73  |trlen(s) + 1), s|
00000720  29 3b 0a 20 20 20 20 69  66 20 28 28 74 20 3d 20  |);.    if ((t = |
00000730  67 65 74 65 6e 76 28 53  43 52 41 50 44 49 52 29  |getenv(SCRAPDIR)|
00000740  29 20 21 3d 20 4e 55 4c  4c 29 0a 20 20 20 20 09  |) != NULL).    .|
00000750  74 20 3d 20 73 74 72 63  70 79 28 6d 61 6c 6c 6f  |t = strcpy(mallo|
00000760  63 28 73 74 72 6c 65 6e  28 74 29 20 2b 20 31 29  |c(strlen(t) + 1)|
00000770  2c 20 74 29 3b 0a 20 20  20 20 2f 2a 20 77 65 20  |, t);.    /* we |
00000780  6e 65 65 64 20 62 6f 74  68 20 4e 45 57 53 44 45  |need both NEWSDE|
00000790  53 54 20 61 6e 64 20 53  43 52 41 50 44 49 52 20  |ST and SCRAPDIR |
000007a0  69 6e 20 6f 72 64 65 72  20 74 6f 20 77 6f 72 6b  |in order to work|
000007b0  2e 0a 20 20 20 20 20 2a  2f 0a 20 20 20 20 69 66  |..     */.    if|
000007c0  20 28 28 73 20 21 3d 20  4e 55 4c 4c 29 20 26 26  | ((s != NULL) &&|
000007d0  20 28 74 20 21 3d 20 4e  55 4c 4c 29 29 0a 20 20  | (t != NULL)).  |
000007e0  20 20 7b 0a 20 20 20 20  09 62 61 74 63 68 6e 61  |  {.    .batchna|
000007f0  6d 65 20 3d 20 6c 72 6e  65 77 73 5f 62 61 74 63  |me = lrnews_batc|
00000800  68 6e 61 6d 65 28 29 3b  0a 20 20 20 20 09 72 20  |hname();.    .r |
00000810  3d 20 66 67 65 74 73 28  62 75 66 66 65 72 2c 20  |= fgets(buffer, |
00000820  42 55 46 4c 45 4e 2c 20  73 74 64 69 6e 29 3b 0a  |BUFLEN, stdin);.|
00000830  20 20 20 20 09 44 45 42  55 47 28 28 22 46 69 72  |    .DEBUG(("Fir|
00000840  73 74 20 6c 69 6e 65 20  69 6e 20 62 61 74 63 68  |st line in batch|
00000850  20 69 73 20 27 25 73 27  5c 6e 22 2c 20 72 29 29  | is '%s'\n", r))|
00000860  3b 0a 20 20 20 20 09 2f  2a 20 69 66 20 74 68 65  |;.    ./* if the|
00000870  20 66 69 72 73 74 20 6c  69 6e 65 20 69 6e 20 74  | first line in t|
00000880  68 65 20 61 72 74 69 63  6c 65 20 69 73 20 22 23  |he article is "#|
00000890  21 20 72 6e 65 77 73 20  2e 2e 2e 22 2c 20 74 68  |! rnews ...", th|
000008a0  65 6e 20 77 65 0a 20 20  20 20 09 20 2a 20 63 6f  |en we.    . * co|
000008b0  70 79 20 74 68 65 20 62  61 74 63 68 20 74 6f 20  |py the batch to |
000008c0  4e 45 57 53 44 45 53 54  0a 20 20 20 20 09 20 2a  |NEWSDEST.    . *|
000008d0  2f 0a 20 20 20 20 09 69  66 20 28 73 74 72 6e 63  |/.    .if (strnc|
000008e0  6d 70 28 52 4e 45 57 53  48 44 52 2c 20 72 2c 20  |mp(RNEWSHDR, r, |
000008f0  73 74 72 6c 65 6e 28 52  4e 45 57 53 48 44 52 29  |strlen(RNEWSHDR)|
00000900  29 20 3d 3d 20 30 29 0a  20 20 20 20 09 7b 0a 20  |) == 0).    .{. |
00000910  20 20 20 09 20 20 20 20  73 70 72 69 6e 74 66 28  |   .    sprintf(|
00000920  62 75 66 66 65 72 32 2c  20 22 25 73 25 73 25 73  |buffer2, "%s%s%s|
00000930  22 2c 20 73 2c 20 44 45  4c 49 4d 2c 20 62 61 74  |", s, DELIM, bat|
00000940  63 68 6e 61 6d 65 29 3b  0a 20 20 20 20 09 20 20  |chname);.    .  |
00000950  20 20 66 20 3d 20 66 6f  70 65 6e 28 75 70 61 74  |  f = fopen(upat|
00000960  68 28 62 75 66 66 65 72  32 29 2c 20 22 77 22 29  |h(buffer2), "w")|
00000970  3b 0a 20 20 20 20 09 20  20 20 20 6c 72 6e 65 77  |;.    .    lrnew|
00000980  73 5f 73 61 76 65 74 6f  28 66 2c 20 72 29 3b 0a  |s_saveto(f, r);.|
00000990  20 20 20 20 09 20 20 20  20 66 63 6c 6f 73 65 28  |    .    fclose(|
000009a0  66 29 3b 0a 20 20 20 20  09 7d 0a 20 20 20 20 09  |f);.    .}.    .|
000009b0  65 6c 73 65 0a 20 20 20  20 09 7b 0a 20 20 20 20  |else.    .{.    |
000009c0  09 20 20 20 20 73 70 72  69 6e 74 66 28 62 75 66  |.    sprintf(buf|
000009d0  66 65 72 32 2c 20 22 25  73 25 73 25 73 22 2c 20  |fer2, "%s%s%s", |
000009e0  74 2c 20 44 45 4c 49 4d  2c 20 62 61 74 63 68 6e  |t, DELIM, batchn|
000009f0  61 6d 65 29 3b 0a 20 20  20 20 09 20 20 20 20 2f  |ame);.    .    /|
00000a00  2a 20 6f 74 68 65 72 77  69 73 65 2c 20 69 66 20  |* otherwise, if |
00000a10  69 74 20 73 74 61 72 74  73 20 77 69 74 68 20 22  |it starts with "|
00000a20  23 21 20 22 2c 20 74 68  65 6e 20 77 65 20 65 78  |#! ", then we ex|
00000a30  74 72 61 63 74 20 74 68  65 0a 20 20 20 20 09 20  |tract the.    . |
00000a40  20 20 20 20 2a 20 63 6f  6d 6d 61 6e 64 20 69 74  |    * command it|
00000a50  20 63 6f 6e 74 61 69 6e  73 20 61 6e 64 20 70 65  | contains and pe|
00000a60  72 66 6f 72 6d 20 69 74  20 77 69 74 68 20 61 20  |rform it with a |
00000a70  73 63 72 61 70 20 63 6f  70 79 20 6f 66 0a 20 20  |scrap copy of.  |
00000a80  20 20 09 20 20 20 20 20  2a 20 74 68 65 20 62 61  |  .     * the ba|
00000a90  74 63 68 20 77 69 74 68  6f 75 74 20 74 68 65 20  |tch without the |
00000aa0  66 69 72 73 74 20 6c 69  6e 65 20 61 73 20 66 69  |first line as fi|
00000ab0  72 73 74 20 61 6e 64 20  74 68 65 20 6e 61 6d 65  |rst and the name|
00000ac0  20 6f 66 0a 20 20 20 20  09 20 20 20 20 20 2a 20  | of.    .     * |
00000ad0  61 20 28 6e 6f 74 20 79  65 74 20 65 78 69 73 74  |a (not yet exist|
00000ae0  69 6e 67 29 20 66 69 6c  65 20 69 6e 20 4e 45 57  |ing) file in NEW|
00000af0  53 44 45 53 54 20 61 73  20 73 65 63 6f 6e 64 20  |SDEST as second |
00000b00  61 72 67 75 6d 65 6e 74  2e 0a 20 20 20 20 09 20  |argument..    . |
00000b10  20 20 20 20 2a 2f 0a 20  20 20 20 09 20 20 20 20  |    */.    .    |
00000b20  69 66 20 28 73 74 72 6e  63 6d 70 28 48 44 52 50  |if (strncmp(HDRP|
00000b30  52 45 46 49 58 2c 20 72  2c 20 73 74 72 6c 65 6e  |REFIX, r, strlen|
00000b40  28 48 44 52 50 52 45 46  49 58 29 29 20 3d 3d 20  |(HDRPREFIX)) == |
00000b50  30 29 0a 20 20 20 20 09  20 20 20 20 7b 0a 09 20  |0).    .    {.. |
00000b60  20 20 20 09 66 20 3d 20  66 6f 70 65 6e 28 62 75  |   .f = fopen(bu|
00000b70  66 66 65 72 32 2c 20 22  77 22 29 3b 0a 20 20 20  |ffer2, "w");.   |
00000b80  20 09 20 20 20 20 09 6c  72 6e 65 77 73 5f 73 61  | .    .lrnews_sa|
00000b90  76 65 74 6f 28 66 2c 20  4e 55 4c 4c 29 3b 0a 20  |veto(f, NULL);. |
00000ba0  20 20 20 09 20 20 20 20  09 66 63 6c 6f 73 65 28  |   .    .fclose(|
00000bb0  66 29 3b 0a 20 20 20 20  09 20 20 20 20 09 72 20  |f);.    .    .r |
00000bc0  3d 20 62 75 66 66 65 72  20 2b 20 73 74 72 6c 65  |= buffer + strle|
00000bd0  6e 28 48 44 52 50 52 45  46 49 58 29 3b 0a 20 20  |n(HDRPREFIX);.  |
00000be0  20 20 09 20 20 20 20 09  66 6f 72 20 28 75 20 3d  |  .    .for (u =|
00000bf0  20 72 3b 20 2a 75 20 3e  20 27 20 27 3b 20 2b 2b  | r; *u > ' '; ++|
00000c00  75 29 3b 0a 20 20 20 20  09 20 20 20 20 09 2a 75  |u);.    .    .*u|
00000c10  20 3d 20 30 3b 0a 20 20  20 20 09 20 20 20 20 09  | = 0;.    .    .|
00000c20  73 74 72 63 61 74 28 72  2c 20 22 20 22 29 3b 0a  |strcat(r, " ");.|
00000c30  20 20 20 20 09 20 20 20  20 09 73 74 72 63 61 74  |    .    .strcat|
00000c40  28 72 2c 20 62 75 66 66  65 72 32 29 3b 0a 20 20  |(r, buffer2);.  |
00000c50  20 20 09 20 20 20 20 09  73 74 72 63 61 74 28 72  |  .    .strcat(r|
00000c60  2c 20 22 20 22 29 3b 0a  20 20 20 20 09 20 20 20  |, " ");.    .   |
00000c70  20 09 73 70 72 69 6e 74  66 28 62 75 66 66 65 72  | .sprintf(buffer|
00000c80  32 2c 20 22 25 73 25 73  25 73 22 2c 20 73 2c 20  |2, "%s%s%s", s, |
00000c90  44 45 4c 49 4d 2c 20 62  61 74 63 68 6e 61 6d 65  |DELIM, batchname|
00000ca0  29 3b 0a 20 20 20 20 09  20 20 20 20 09 73 74 72  |);.    .    .str|
00000cb0  63 61 74 28 72 2c 20 62  75 66 66 65 72 32 29 3b  |cat(r, buffer2);|
00000cc0  0a 20 20 20 20 09 20 20  20 20 09 69 66 20 28 73  |.    .    .if (s|
00000cd0  79 73 74 65 6d 28 72 29  20 21 3d 20 30 29 0a 20  |ystem(r) != 0). |
00000ce0  20 20 20 09 20 20 20 20  09 7b 0a 20 20 20 20 09  |   .    .{.    .|
00000cf0  20 20 20 20 20 20 20 20  20 20 20 20 66 70 72 69  |            fpri|
00000d00  6e 74 66 28 73 74 64 65  72 72 2c 20 22 43 6f 75  |ntf(stderr, "Cou|
00000d10  6c 64 20 6e 6f 74 20 70  65 72 66 6f 72 6d 20 27  |ld not perform '|
00000d20  25 73 27 5c 6e 22 2c 20  62 75 66 66 65 72 29 3b  |%s'\n", buffer);|
00000d30  0a 20 20 20 20 09 20 20  20 20 20 20 20 20 20 20  |.    .          |
00000d40  20 20 72 65 74 20 3d 20  45 58 49 54 5f 46 41 49  |  ret = EXIT_FAI|
00000d50  4c 55 52 45 3b 0a 20 20  20 20 09 20 20 20 20 09  |LURE;.    .    .|
00000d60  7d 0a 20 20 20 20 09 20  20 20 20 09 65 6c 73 65  |}.    .    .else|
00000d70  0a 20 20 20 20 09 20 20  20 20 09 2f 2a 20 69 66  |.    .    ./* if|
00000d80  20 61 6c 6c 20 77 65 6e  74 20 77 65 6c 6c 2c 20  | all went well, |
00000d90  77 65 20 72 65 6d 6f 76  65 20 74 68 65 20 74 65  |we remove the te|
00000da0  6d 70 2e 20 66 69 6c 65  20 69 6e 20 53 43 52 41  |mp. file in SCRA|
00000db0  50 44 49 52 0a 20 20 20  20 09 20 20 20 20 09 20  |PDIR.    .    . |
00000dc0  2a 2f 0a 20 20 20 20 09  20 20 20 20 09 7b 0a 20  |*/.    .    .{. |
00000dd0  20 20 20 09 20 20 20 20  09 20 20 20 20 73 70 72  |   .    .    spr|
00000de0  69 6e 74 66 28 62 75 66  66 65 72 32 2c 20 22 25  |intf(buffer2, "%|
00000df0  73 25 73 25 73 22 2c 20  74 2c 20 44 45 4c 49 4d  |s%s%s", t, DELIM|
00000e00  2c 20 62 61 74 63 68 6e  61 6d 65 29 3b 0a 20 20  |, batchname);.  |
00000e10  20 20 09 20 20 20 20 09  20 20 20 20 72 65 6d 6f  |  .    .    remo|
00000e20  76 65 28 75 70 61 74 68  28 62 75 66 66 65 72 32  |ve(upath(buffer2|
00000e30  29 29 3b 0a 20 20 20 20  09 20 20 20 20 09 7d 0a  |));.    .    .}.|
00000e40  20 20 20 20 09 20 20 20  20 7d 0a 20 20 20 20 09  |    .    }.    .|
00000e50  20 20 20 20 65 6c 73 65  0a 20 20 20 20 09 20 20  |    else.    .  |
00000e60  20 20 2f 2a 20 79 6f 75  20 67 65 74 20 68 65 72  |  /* you get her|
00000e70  65 20 77 68 65 6e 20 74  68 65 20 62 61 74 63 68  |e when the batch|
00000e80  20 68 61 73 20 6e 6f 20  22 23 21 20 2e 2e 2e 22  | has no "#! ..."|
00000e90  20 68 65 61 64 65 72 2e  20 49 66 20 79 6f 75 27  | header. If you'|
00000ea0  64 0a 20 20 20 20 09 20  20 20 20 20 2a 20 72 61  |d.    .     * ra|
00000eb0  74 68 65 72 20 6c 69 6b  65 20 74 68 65 20 61 72  |ther like the ar|
00000ec0  74 69 63 6c 65 20 74 6f  20 62 65 20 63 6f 70 69  |ticle to be copi|
00000ed0  65 64 20 74 6f 20 4e 45  57 53 44 45 53 54 2c 20  |ed to NEWSDEST, |
00000ee0  69 6e 73 65 72 74 20 74  68 65 0a 20 20 20 20 09  |insert the.    .|
00000ef0  20 20 20 20 20 2a 20 63  6f 64 65 20 74 6f 20 64  |     * code to d|
00000f00  6f 20 73 6f 20 68 65 72  65 2e 0a 20 20 20 20 09  |o so here..    .|
00000f10  20 20 20 20 20 2a 2f 0a  20 20 20 20 09 20 20 20  |     */.    .   |
00000f20  20 7b 0a 09 20 20 20 20  09 66 20 3d 20 66 6f 70  | {..    .f = fop|
00000f30  65 6e 28 62 75 66 66 65  72 32 2c 20 22 77 22 29  |en(buffer2, "w")|
00000f40  3b 0a 20 20 20 20 09 20  20 20 20 09 6c 72 6e 65  |;.    .    .lrne|
00000f50  77 73 5f 73 61 76 65 74  6f 28 66 2c 20 72 29 3b  |ws_saveto(f, r);|
00000f60  0a 20 20 20 20 09 20 20  20 20 09 66 63 6c 6f 73  |.    .    .fclos|
00000f70  65 28 66 29 3b 0a 20 20  20 20 09 20 20 20 20 20  |e(f);.    .     |
00000f80  20 20 20 66 70 72 69 6e  74 66 28 73 74 64 65 72  |   fprintf(stder|
00000f90  72 2c 20 22 44 6f 6e 27  74 20 6b 6e 6f 77 20 68  |r, "Don't know h|
00000fa0  6f 77 20 74 6f 20 68 61  6e 64 6c 65 20 63 75 72  |ow to handle cur|
00000fb0  72 65 6e 74 20 62 61 74  63 68 2c 20 69 74 20 69  |rent batch, it i|
00000fc0  73 20 69 6e 20 25 73 5c  6e 22 2c 20 62 75 66 66  |s in %s\n", buff|
00000fd0  65 72 32 29 3b 0a 20 20  20 20 09 20 20 20 20 20  |er2);.    .     |
00000fe0  20 20 20 72 65 74 20 3d  20 45 58 49 54 5f 46 41  |   ret = EXIT_FA|
00000ff0  49 4c 55 52 45 3b 0a 20  20 20 20 09 20 20 20 20  |ILURE;.    .    |
00001000  7d 0a 20 20 20 20 09 7d  0a 20 20 20 20 7d 0a 20  |}.    .}.    }. |
00001010  20 20 20 65 6c 73 65 0a  20 20 20 20 7b 0a 20 20  |   else.    {.  |
00001020  20 20 20 20 20 20 69 66  20 28 73 20 3d 3d 20 4e  |      if (s == N|
00001030  55 4c 4c 29 0a 20 20 20  20 09 20 20 20 20 66 70  |ULL).    .    fp|
00001040  72 69 6e 74 66 28 73 74  64 65 72 72 2c 20 22 45  |rintf(stderr, "E|
00001050  6e 76 69 72 6f 6e 6d 65  6e 74 20 76 61 72 69 61  |nvironment varia|
00001060  62 6c 65 20 25 73 20 6e  6f 74 20 66 6f 75 6e 64  |ble %s not found|
00001070  5c 6e 22 2c 20 4e 45 57  53 44 45 53 54 29 3b 0a  |\n", NEWSDEST);.|
00001080  20 20 20 20 09 69 66 20  28 74 20 3d 3d 20 4e 55  |    .if (t == NU|
00001090  4c 4c 29 0a 20 20 20 20  09 20 20 20 20 66 70 72  |LL).    .    fpr|
000010a0  69 6e 74 66 28 73 74 64  65 72 72 2c 20 22 25 73  |intf(stderr, "%s|
000010b0  20 6d 75 73 74 20 68 61  76 65 20 62 65 65 6e 20  | must have been |
000010c0  73 65 74 2e 5c 6e 22 2c  20 53 43 52 41 50 44 49  |set.\n", SCRAPDI|
000010d0  52 29 3b 0a 20 20 20 20  09 72 65 74 20 3d 20 45  |R);.    .ret = E|
000010e0  58 49 54 5f 46 41 49 4c  55 52 45 3b 0a 20 20 20  |XIT_FAILURE;.   |
000010f0  20 7d 0a 20 20 20 20 65  78 69 74 28 72 65 74 29  | }.    exit(ret)|
00001100  3b 0a 7d 0a                                       |;.}.|
00001104