summaryrefslogtreecommitdiff
path: root/biblio/bibtex/contrib/astron/puntxt.c
blob: 26908c9d93a8bddb338b708f28fcc18ba7c51ed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Filter a LISTSERV PUNCH format message into normal text */

#include <stdio.h>
#include <string.h>

int
main()
{
    char	buffer[81];
    char	*p;
    int		len, n, k;

    k = 0;
    while (gets(buffer) != (char*)NULL)
    {
	k++;
	if (strcmp(buffer,"END/") == 0)
	    break;
	p = strchr(buffer,'/');
	if (p != (char*)NULL) p = strchr(p+1,'/');
	if (p != (char*)NULL) ++p;
	if ( (sscanf(buffer,"%d/%d/",&len,&n) != 2) || (p == (char*)NULL) )
	{
	    fprintf(stderr,"Conversion error on line %d = [%s]\n",k,buffer);
#if 0
	    exit(1);
#endif
	    n = 1;
	}

	if (p != (char*)NULL)
	    fputs(p,stdout);
	else
	{
	    fputs("????",stdout);
	    fputs(buffer,stdout);
	}

	for (; n > 1; --n)		/* copy continuation lines */
	{
	    if (gets(buffer) == (char*)NULL)
		break;
	    k++;
	    fputs(buffer,stdout);
	}
	fputc('\n',stdout);
    }
    exit (0);
}