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

Annotation of OpenXM_contrib/gnuplot/docs/doc2rnh.c, Revision 1.1

1.1     ! maekawa     1: #ifndef lint
        !             2: static char *RCSid = "$Id: doc2rno.c,v 0.01 1997/03/09 21:00:00 lph Exp $";
        !             3: #endif
        !             4:
        !             5: /* GNUPLOT - doc2rnh.c */
        !             6:
        !             7: /*[
        !             8:  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
        !             9:  *
        !            10:  * Permission to use, copy, and distribute this software and its
        !            11:  * documentation for any purpose with or without fee is hereby granted,
        !            12:  * provided that the above copyright notice appear in all copies and
        !            13:  * that both that copyright notice and this permission notice appear
        !            14:  * in supporting documentation.
        !            15:  *
        !            16:  * Permission to modify the software is granted, but not the right to
        !            17:  * distribute the complete modified source code.  Modifications are to
        !            18:  * be distributed as patches to the released version.  Permission to
        !            19:  * distribute binaries produced by compiling modified sources is granted,
        !            20:  * provided you
        !            21:  *   1. distribute the corresponding source modifications from the
        !            22:  *    released version in the form of a patch file along with the binaries,
        !            23:  *   2. add special version identification to distinguish your version
        !            24:  *    in addition to the base release version number,
        !            25:  *   3. provide your name and address as the primary contact for the
        !            26:  *    support of your modified version, and
        !            27:  *   4. retain our contact information in regard to use of the base
        !            28:  *    software.
        !            29:  * Permission to distribute the released version of the source code along
        !            30:  * with corresponding source modifications in the form of a patch file is
        !            31:  * granted with same provisions 2 through 4 for binary distributions.
        !            32:  *
        !            33:  * This software is provided "as is" without express or implied warranty
        !            34:  * to the extent permitted by applicable law.
        !            35: ]*/
        !            36:
        !            37: /*
        !            38:  * doc2rnh.c  -- program to convert Gnuplot .DOC format to
        !            39:  *               Digital Standard Runoff for VMS HELP files
        !            40:  *               (gnuplot.doc, including the terminal documentation
        !            41:  *                is no longer formated for VMS HELP by default)
        !            42:  *
        !            43:  * From hlp2ms by Thomas Williams
        !            44:  *
        !            45:  * Modified by Russell Lang, 2nd October 1989
        !            46:  * to make vms help level 1 and 2 create the same ms section level.
        !            47:  *
        !            48:  * Modified to become doc2ms by David Kotz (David.Kotz@Dartmouth.edu) 12/89
        !            49:  * Added table and backquote support.
        !            50:  *
        !            51:  * Adapted from doc2ms.c (the unix 'runoff' text-processor)
        !            52:  * by Lucas Hart 3/97
        !            53:  *
        !            54:  * right margin is adjusted two spaces for each level to compensate
        !            55:  * for the indentation by VMS HELP
        !            56:  *
        !            57:  * the page width can be adjusted by changing the value of DSR_RM
        !            58:  * usage: $ MCR []doc2rnh gnuplot.doc gnuplot.rnh
        !            59:  *        $ RUNOFF gnuplot.rnh
        !            60:  *
        !            61:  *
        !            62:  */
        !            63:
        !            64: #ifdef HAVE_CONFIG_H
        !            65: # include "config.h"
        !            66: #endif
        !            67:
        !            68: #include "ansichek.h"
        !            69: #include "stdfn.h"
        !            70: #include "doc2x.h"
        !            71:
        !            72: extern boolean single_top_level;
        !            73:
        !            74: #define LINE_SKIP              3
        !            75: #define DSR_RM         70
        !            76:
        !            77: void init __PROTO((FILE *));
        !            78: void convert __PROTO((FILE *, FILE *));
        !            79: void process_line __PROTO((char *, FILE *));
        !            80: void section __PROTO((char *, FILE *));
        !            81: void putrnh __PROTO((char *, FILE *));
        !            82: void putrnh_ __PROTO((char *, FILE *));
        !            83: void finish __PROTO((FILE *));
        !            84:
        !            85: static boolean intable = FALSE;
        !            86: static boolean rnh_table = FALSE;
        !            87: static boolean initial_entry = FALSE;
        !            88:
        !            89: int main(argc, argv)
        !            90: int argc;
        !            91: char **argv;
        !            92: {
        !            93:     FILE *infile;
        !            94:     FILE *outfile;
        !            95:     infile = stdin;
        !            96:     outfile = stdout;
        !            97:
        !            98:     single_top_level = TRUE;
        !            99:
        !           100:     if (argc > 3) {
        !           101:        fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
        !           102:        exit(EXIT_FAILURE);
        !           103:     }
        !           104:     if (argc >= 2) {
        !           105:        if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
        !           106:            fprintf(stderr, "%s: Can't open %s for reading\n",
        !           107:                    argv[0], argv[1]);
        !           108:            exit(EXIT_SUCCESS);
        !           109:        }
        !           110:     }
        !           111:     if (argc == 3) {
        !           112:        if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
        !           113:            fprintf(stderr, "%s: Can't open %s for writing\n",
        !           114:                    argv[0], argv[2]);
        !           115:            exit(EXIT_FAILURE);
        !           116:        }
        !           117:     }
        !           118:     init(outfile);
        !           119:     convert(infile, outfile);
        !           120:     finish(outfile);
        !           121:     exit(EXIT_SUCCESS);
        !           122: }
        !           123:
        !           124:
        !           125: void init(b)
        !           126: FILE *b;
        !           127: {
        !           128:     /*     */
        !           129:     (void) fputs(".no paging\n\
        !           130: .no flags all\n\
        !           131: .left margin 1\n\
        !           132: .right margin 70\n\
        !           133: .no justify\n", b);
        !           134: }
        !           135:
        !           136:
        !           137: void convert(a, b)
        !           138: FILE *a, *b;
        !           139: {
        !           140:     static char line[MAX_LINE_LEN+1];
        !           141:
        !           142:     while (get_line(line, sizeof(line), a)) {
        !           143:        process_line(line, b);
        !           144:     }
        !           145: }
        !           146:
        !           147: void process_line(line, b)
        !           148: char *line;
        !           149: FILE *b;
        !           150: {
        !           151:     switch (line[0]) {         /* control character */
        !           152:     case '?':{                 /* interactive help entry */
        !           153:            break;              /* ignore */
        !           154:        }
        !           155:     case '@':{                 /* start/end table */
        !           156:            if (rnh_table) {
        !           157:                (void) fputs(".end literal\n", b);
        !           158:                rnh_table = FALSE;
        !           159:                intable = FALSE;
        !           160:            } else {
        !           161: /*                       (void) fputs(".literal\n",b);  */
        !           162:                intable = TRUE;
        !           163:                rnh_table = FALSE;
        !           164:                initial_entry = TRUE;
        !           165:            }
        !           166:            /* ignore rest of line */
        !           167:            break;
        !           168:        }
        !           169:     case '^':{                 /* html table entry */
        !           170:            break;              /* ignore */
        !           171:        }
        !           172:     case '#':{                 /* latex table entry */
        !           173:            break;              /* ignore */
        !           174:        }
        !           175:     case '%':{                 /* troff table entry */
        !           176:            break;              /* ignore */
        !           177:        }
        !           178: #if 0
        !           179: /* 'C' is taken care of by termdoc.c */
        !           180:     case 'C':{                 /*  new Comment designator */
        !           181:            break;              /* ignore */
        !           182:        }
        !           183: #endif
        !           184:     case '\n':                 /* empty text line */
        !           185:     case ' ':{                 /* normal text line */
        !           186:
        !           187: /* most tables are simple; no flags means no protected characters
        !           188:  * other than period (command indicator) in first column
        !           189:  *
        !           190:  * However, for ease of maintainence, two tables have sublevels
        !           191:  * and descriptions, corresponding to the printed table entries,
        !           192:  * encapsulated by the table markers.  Therefore we need to
        !           193:  * do some more work.
        !           194:  *
        !           195:  * Doc2hlp just ignores the table headings and treats
        !           196:  * lower levels irrespectively, but we need to break
        !           197:  * the level designators out of the table format.
        !           198:  *
        !           199:  *  The first entry in a table will have either
        !           200:  *     - a level number in the first column => remainder of text in
        !           201:  *                                             table is help text
        !           202:  *     - spaces in the first two columns => rest of text is literal
        !           203:  *                                          to be placed in table format
        !           204:  *
        !           205:  */
        !           206:
        !           207: /* use the "cleartext" table or other text in tables */
        !           208:
        !           209: /*                if (intable)  { /* its already literal */
        !           210:            if (rnh_table) {    /* its a literal */
        !           211:                putrnh(line + 1, b);
        !           212:                break;
        !           213:            }
        !           214:            switch (line[1]) {
        !           215:            case ' ':{
        !           216:                    if ((intable) && (initial_entry)) {
        !           217:                        rnh_table = TRUE;
        !           218:                        initial_entry = FALSE;
        !           219:                        fputs(".literal\n", b);
        !           220:                        putrnh(line + 1, b);
        !           221:                        break;
        !           222:                    }
        !           223:                    /* verbatim mode */
        !           224:                    fputs(".literal\n", b);
        !           225:                    putrnh(line + 1, b);
        !           226:                    fputs(".end literal\n", b);
        !           227:                    break;
        !           228:                }
        !           229:
        !           230: /*
        !           231:  *  "." in first column is the DSR command character;
        !           232:  *  therefore, include the preceeding " "
        !           233:  */
        !           234:            case '.':{
        !           235:                    putrnh(line, b);
        !           236:                    break;
        !           237:                }
        !           238:            default:{
        !           239:                    if (line[0] == '\n')
        !           240:                        fputs(".skip\n", b);    /* totally blank line */
        !           241:                    else
        !           242:                        putrnh(line + 1, b);
        !           243:                    break;
        !           244:                }
        !           245:                break;
        !           246:            }
        !           247:            break;
        !           248:        }
        !           249:     default:{
        !           250:            if (isdigit((int) line[0])) {       /* start of section */
        !           251:
        !           252: /* some HELP text is surrounded by table flags */
        !           253: /* doc2rnh will ignore the flags */
        !           254:
        !           255:                if (intable) {
        !           256:                    if (initial_entry) {
        !           257:                        initial_entry = FALSE;
        !           258:                        rnh_table = FALSE;
        !           259:                    }
        !           260:                }
        !           261:                section(line, b);
        !           262:            } else
        !           263:                fprintf(stderr, "unknown control code '%c' in column 1\n",
        !           264:                        line[0]);
        !           265:            break;
        !           266:        }
        !           267:     }
        !           268: }
        !           269:
        !           270:
        !           271: /* process a line with a digit control char */
        !           272: /* starts a new [sub]section */
        !           273: /* We want to retain section number, so its simpler than w/ TeX or roff */
        !           274:
        !           275: void section(line, b)
        !           276: char *line;
        !           277: FILE *b;
        !           278: {
        !           279:     int sh_i;
        !           280:     static int old = 1;
        !           281: /*
        !           282:    (void) sscanf(line,"%d",&sh_i);
        !           283:    *
        !           284:    * check to make sure this works with terminals also
        !           285:  */
        !           286:     sh_i = atoi(line);
        !           287:
        !           288:     if (sh_i > old) {
        !           289:        do
        !           290:            if (old != 1)       /* this line added by rjl */
        !           291:                (void) fputs(".rm-2\n", b);
        !           292:        while (++old < sh_i);
        !           293:     } else if (sh_i < old) {
        !           294:        do
        !           295:            if (sh_i != 1)      /* this line added by rjl */
        !           296:                (void) fputs(".rm+2\n", b);
        !           297:        while (--old > sh_i);
        !           298:     }
        !           299:     /* added by dfk to capitalize section headers */
        !           300:     /* Header name starts at [2] */
        !           301: /* omit for online documentation
        !           302:  *    if (islower(line[2]))
        !           303:  *       line[2] = toupper(line[2]);
        !           304:  */
        !           305:     old = sh_i;
        !           306:
        !           307:     (void) fputs(".indent -1;\n", b);
        !           308:     (void) putrnh_(line, b);
        !           309:     (void) fputs(".br;\n", b);
        !           310: }
        !           311:
        !           312: /*
        !           313:  * dummy function in case we need to convert some characters in
        !           314:  * output string ala doc2tex and doc2ms
        !           315:  */
        !           316:
        !           317: void putrnh(s, file)
        !           318: char *s;
        !           319: FILE *file;
        !           320: {
        !           321:     (void) fputs(s, file);
        !           322: }
        !           323:
        !           324: /*
        !           325:  * LBR$OUTPUT_HELP treats spaces and "/"s as list separators for topics,
        !           326:  * but they are used in gnuplot.doc for the printed docs; convert to
        !           327:  * "_" and "|"   Modeled after section heading conversions in doc2tex
        !           328:  * and doc2ms.
        !           329:  *
        !           330:  */
        !           331:
        !           332: void putrnh_(s, file)
        !           333: char *s;
        !           334: FILE *file;
        !           335: {
        !           336:     int i, s_len, last_chr;
        !           337:
        !           338:     s_len = strlen(s);
        !           339:
        !           340:     for (i = s_len - 1; i > 2; i--) {  /* any trailing spaces to drop? */
        !           341:        if (s[i] != ' ') {
        !           342:            last_chr = i;
        !           343:            break;
        !           344:        }
        !           345:     }
        !           346:
        !           347:     for (i = 0; i <= last_chr; i++) {
        !           348:        if (i > 2) {
        !           349:            switch (s[i]) {
        !           350:            case ' ':
        !           351:                (void) fputc('_', file);
        !           352:                break;
        !           353:            case '/':
        !           354:                (void) fputc('|', file);
        !           355:                break;
        !           356:            default:
        !           357:                (void) fputc(s[i], file);
        !           358:            }
        !           359:        } else {
        !           360:            (void) fputc(s[i], file);
        !           361:        }
        !           362:     }
        !           363: }
        !           364:
        !           365: void finish(b)                 /* not used */
        !           366: FILE *b;
        !           367: {
        !           368:     return;
        !           369: }

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