[BACK]Return to doc2gih.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / docs

Annotation of OpenXM_contrib/gnuplot/docs/doc2gih.c, Revision 1.1.1.1

1.1       maekawa     1: /*
                      2:  * $Id: doc2gih.c,v 1.16 1998/04/14 00:16:58 drd Exp $
                      3:  *
                      4:  */
                      5:
                      6: /* GNUPLOT - doc2gih.c */
                      7:
                      8: /*[
                      9:  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
                     10:  *
                     11:  * Permission to use, copy, and distribute this software and its
                     12:  * documentation for any purpose with or without fee is hereby granted,
                     13:  * provided that the above copyright notice appear in all copies and
                     14:  * that both that copyright notice and this permission notice appear
                     15:  * in supporting documentation.
                     16:  *
                     17:  * Permission to modify the software is granted, but not the right to
                     18:  * distribute the complete modified source code.  Modifications are to
                     19:  * be distributed as patches to the released version.  Permission to
                     20:  * distribute binaries produced by compiling modified sources is granted,
                     21:  * provided you
                     22:  *   1. distribute the corresponding source modifications from the
                     23:  *    released version in the form of a patch file along with the binaries,
                     24:  *   2. add special version identification to distinguish your version
                     25:  *    in addition to the base release version number,
                     26:  *   3. provide your name and address as the primary contact for the
                     27:  *    support of your modified version, and
                     28:  *   4. retain our contact information in regard to use of the base
                     29:  *    software.
                     30:  * Permission to distribute the released version of the source code along
                     31:  * with corresponding source modifications in the form of a patch file is
                     32:  * granted with same provisions 2 through 4 for binary distributions.
                     33:  *
                     34:  * This software is provided "as is" without express or implied warranty
                     35:  * to the extent permitted by applicable law.
                     36: ]*/
                     37:
                     38: /*
                     39:  * doc2gih.c  -- program to convert Gnuplot .DOC format to gnuplot
                     40:  * interactive help (.GIH) format.
                     41:  *
                     42:  * This involves stripping all lines with a leading digit or
                     43:  * a leading @, #, or %.
                     44:  * Modified by Russell Lang from hlp2ms.c by Thomas Williams
                     45:  *
                     46:  * usage:  doc2gih [file.doc [file.gih]]
                     47:  *
                     48:  * Original version by David Kotz used the following one line script!
                     49:  * sed '/^[0-9@#%]/d' file.doc > file.gih
                     50:  */
                     51:
                     52: #ifdef HAVE_CONFIG_H
                     53: # include "config.h"
                     54: #endif
                     55:
                     56: #include "ansichek.h"
                     57: #include "stdfn.h"
                     58: #include "doc2x.h"
                     59:
                     60: void convert __PROTO((FILE *, FILE *));
                     61: void process_line __PROTO((char *, FILE *));
                     62:
                     63: int main(argc, argv)
                     64: int argc;
                     65: char **argv;
                     66: {
                     67:     FILE *infile;
                     68:     FILE *outfile;
                     69:
                     70:     infile = stdin;
                     71:     outfile = stdout;
                     72:
                     73:     if (argc > 3) {
                     74:        fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
                     75:        exit(EXIT_FAILURE);
                     76:     }
                     77:     if (argc >= 2) {
                     78:        if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
                     79:            fprintf(stderr, "%s: Can't open %s for reading\n",
                     80:                    argv[0], argv[1]);
                     81:            exit(EXIT_FAILURE);
                     82:        }
                     83:     }
                     84:     if (argc == 3) {
                     85:        if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
                     86:            fprintf(stderr, "%s: Can't open %s for writing\n",
                     87:                    argv[0], argv[2]);
                     88:            exit(EXIT_FAILURE);
                     89:        }
                     90:     }
                     91:
                     92:     convert(infile, outfile);
                     93:
                     94:     exit(EXIT_SUCCESS);
                     95: }
                     96:
                     97:
                     98: void convert (inf, outf)
                     99: FILE *inf, *outf;
                    100: {
                    101:     static char line[MAX_LINE_LEN+1];
                    102:
                    103:     while (get_line(line, sizeof(line), inf))
                    104:         process_line(line, outf);
                    105: }
                    106:
                    107:
                    108: void process_line(line, b)
                    109: char *line;
                    110: FILE *b;
                    111: {
                    112:     static int line_count = 0;
                    113:
                    114:     line_count++;
                    115:
                    116:     switch (line[0]) {         /* control character */
                    117:     case '?':{                 /* interactive help entry */
                    118:            (void) fputs(line, b);
                    119:            break;
                    120:        }
                    121:     case '@':{                 /* start/end table */
                    122:            break;              /* ignore */
                    123:        }
                    124:     case '#':{                 /* latex table entry */
                    125:            break;              /* ignore */
                    126:        }
                    127:     case '%':{                 /* troff table entry */
                    128:            break;              /* ignore */
                    129:        }
                    130:     case '^':{                 /* html entry */
                    131:            break;              /* ignore */
                    132:        }
                    133:     case '\n':                 /* empty text line */
                    134:     case ' ':{                 /* normal text line */
                    135:            (void) fputs(line, b);
                    136:            break;
                    137:        }
                    138:     default:{
                    139:            if (isdigit((int)line[0])) {        /* start of section */
                    140:                /* ignore */
                    141:            } else
                    142:                fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
                    143:                        line[0], line_count);
                    144:            break;
                    145:        }
                    146:     }
                    147: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>