]> git.ipfire.org Git - thirdparty/strongswan.git/blob - doc/utils/rfc_pg.c
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / doc / utils / rfc_pg.c
1 /*
2 * $Header: /var/cvsroot/strongswan/doc/utils/rfc_pg.c,v 1.1 2004/03/15 20:35:24 as Exp $
3 *
4 * from 2-nroff.template file.
5 *
6 * Remove N lines following any line that contains a form feed (^L).
7 * (Why can't this be done with awk or sed?)
8 *
9 * OPTION:
10 * -n# Number of lines to delete following each ^L (0 default).
11 * $Log: rfc_pg.c,v $
12 * Revision 1.1 2004/03/15 20:35:24 as
13 * added files from freeswan-2.04-x509-1.5.3
14 *
15 * Revision 1.1 2002/07/23 18:42:43 mcr
16 * required utility from IETF to help with formatting of drafts.
17 *
18 */
19 #include <stdio.h>
20
21 #define FORM_FEED '\f'
22 #define OPTION "n:N:" /* for getopt() */
23
24 extern char *optarg;
25 extern int optind;
26
27 main(argc, argv)
28 int argc;
29 char *argv[];
30 {
31 int c, /* next input char */
32 nlines = 0; /* lines to delete after ^L */
33 void print_and_delete(); /* print line starting with ^L,
34 then delete N lines */
35
36 /*********************** Process option (-nlines) ***********************/
37
38 while ((c = getopt(argc, argv, OPTION)) != EOF)
39 switch(c)
40 {
41 case 'n' :
42 case 'N' : nlines = atoi(optarg);
43 break;
44 }
45 /************************* READ AND PROCESS CHARS **********************/
46
47 while ((c = getchar()) != EOF)
48 if (c == FORM_FEED)
49 print_and_delete(nlines); /* remove N lines after this one */
50 else
51 putchar(c); /* we write the form feed */
52 exit(0);
53 }
54
55 \f
56 /*
57 * Print rest of line, then delete next N lines.
58 */
59 void print_and_delete(n)
60 int n; /* nbr of lines to delete */
61 {
62 int c, /* next input char */
63 cntr = 0; /* count of deleted lines */
64
65 while ((c = getchar()) != '\n') /* finish current line */
66 putchar(c);
67 putchar('\n'); /* write the last CR */
68 putchar(FORM_FEED);
69
70 for ( ; cntr < n; cntr++)
71 while ((c = getchar()) != '\n')
72 if (c == EOF)
73 exit(0); /* exit on EOF */
74 putchar(c); /* write that last CR */
75 }
76