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

Annotation of OpenXM_contrib/gnuplot/docs/doc2html.c, Revision 1.1.1.2

1.1       maekawa     1: /*
1.1.1.2 ! maekawa     2:  * $Id: doc2html.c,v 1.7 1998/10/28 21:04:09 lhecking Exp $
1.1       maekawa     3:  *
                      4:  */
                      5:
                      6: /* GNUPLOT - doc2html.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:  * doc2html.c  -- program to convert Gnuplot .DOC format to
                     40:  *        World Wide Web (WWW) HyperText Markup Language (HTML) format
                     41:  *
                     42:  * Created by Russell Lang from doc2ipf by Roger Fearick from
                     43:  * doc2rtf by M Castro from doc2gih by Thomas Williams.
                     44:  * 1994-11-03
                     45:  *
                     46:  * usage:  doc2html gnuplot.doc gnuplot.htm
                     47:  *
                     48:  */
                     49:
                     50: /* note that tables must begin in at least the second column to */
                     51: /* be formatted correctly and tabs are forbidden */
                     52:
                     53: #ifdef HAVE_CONFIG_H
                     54: # include "config.h"
                     55: #endif
                     56:
                     57: #include "ansichek.h"
                     58: #include "stdfn.h"
                     59:
                     60: #define MAX_LINE_LEN 1023
                     61:
                     62: #include "doc2x.h"
                     63: #include "xref.h"
                     64:
                     65: static boolean debug = FALSE;
                     66: char title[256];
                     67:
                     68: void convert __PROTO((FILE *, FILE *));
                     69: void process_line __PROTO((char *, FILE *));
                     70:
                     71: /* From xref.c */
                     72: extern struct LIST *lookup __PROTO((char *));
                     73:
                     74: int main(argc, argv)
                     75: int argc;
                     76: char **argv;
                     77: {
                     78:     FILE *infile;
                     79:     FILE *outfile;
                     80:
                     81:     if (argv[argc - 1][0] == '-' && argv[argc - 1][1] == 'd') {
                     82:        debug = TRUE;
                     83:        argc--;
                     84:     }
                     85:     if ((argc > 3) || (argc == 1)) {
                     86:        fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
                     87:        exit(EXIT_FAILURE);
                     88:     }
                     89:     if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
                     90:        fprintf(stderr, "%s: Can't open %s for reading\n",
                     91:                argv[0], argv[1]);
                     92:        exit(EXIT_FAILURE);
                     93:     }
                     94:     if (argc == 3) {
                     95:        if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
                     96:            fprintf(stderr, "%s: Can't open %s for writing\n",
                     97:                    argv[0], argv[2]);
                     98:            exit(EXIT_FAILURE);
                     99:        }
                    100:        safe_strncpy(title, argv[2], sizeof(title));
                    101:     } else {
                    102:        outfile = stdout;
                    103:        safe_strncpy(title, argv[1], sizeof(title));
                    104:     }
                    105:     strtok(title, ".");                /* remove type */
                    106:     parse(infile);
                    107:     convert(infile, outfile);
                    108:     exit(EXIT_SUCCESS);
                    109: }
                    110:
                    111: void convert(a, b)
                    112: FILE *a, *b;
                    113: {
                    114:     static char line[MAX_LINE_LEN+1];
                    115:
                    116:     /* generate html header */
                    117:     fprintf(b, "<HTML>\n\
                    118: <HEAD>\n\
                    119: <TITLE>%s</TITLE>\n\
                    120: </HEAD>\n\
                    121: <BODY>\n\
                    122: <H1>%s</H1><P>\n", title, title);
                    123:
                    124:     /* process each line of the file */
                    125:     while (get_line(line, sizeof(line), a)) {
                    126:        process_line(line, b);
                    127:     }
                    128:
                    129:     /* close final page and generate trailer */
                    130:     fprintf(b, "\n<P><HR>Created automatically by doc2html\n\
                    131: </BODY>\n\
                    132: </HTML>\n");
                    133:
                    134:     list_free();
                    135: }
                    136:
                    137: void process_line(line, b)
                    138: char *line;
                    139: FILE *b;
                    140: {
                    141:     static int line_count = 0;
                    142:     static char line2[MAX_LINE_LEN+1];
                    143:     static int last_line;
                    144:     char hyplink1[64];
                    145:     int i, j;
                    146:     static int startpage = 1;
                    147:     char topic[MAX_LINE_LEN+1];
                    148:     int k, l;
                    149:     struct LIST *klist;
                    150:     static int tabl = 0;
                    151:     static int para = 0;
                    152:     static int inquote = FALSE;
                    153:     static int inref = FALSE;
                    154:
                    155:     line_count++;
                    156:
                    157:     i = j = 0;
                    158:
                    159:     while (line[i] != NUL) {
                    160:        switch (line[i]) {
                    161:        case '<':
                    162:            strcpy(&line2[j], "&lt;");
                    163:            j += strlen("&lt.") - 1;
                    164:            break;
                    165:
                    166:        case '>':
                    167:            strcpy(&line2[j], "&gt;");
                    168:            j += strlen("&gt.") - 1;
                    169:            break;
                    170:
                    171:        case '&':
                    172:            strcpy(&line2[j], "&amp;");
                    173:            j += strlen("&amp;") - 1;
                    174:            break;
                    175:
                    176:        case '\r':
                    177:        case '\n':
                    178:            break;
                    179:        case '`':               /* backquotes mean boldface or link */
                    180:            if ((!inref) && (!inquote)) {
                    181:                k = i + 1;      /* index into current string */
                    182:                l = 0;          /* index into topic string */
                    183:                while ((line[k] != '`') && (line[k] != NUL))
                    184:                    topic[l++] = line[k++];
                    185:                topic[l] = NUL;
                    186:                klist = lookup(topic);
                    187:                if (klist && ((k = klist->line) != last_line)) {
                    188:                    sprintf(hyplink1, "<A HREF=\042#%d\042>", k);
                    189:                    strcpy(line2 + j, hyplink1);
                    190:                    j += strlen(hyplink1) - 1;
                    191:
                    192:                    inref = k;
                    193:                } else {
                    194:                    if (debug && k != last_line)
                    195:                        fprintf(stderr, "Can't make link for \042%s\042 on line %d\n", topic, line_count);
                    196:                    line2[j++] = '<';
                    197:                    line2[j++] = 'B';
                    198:                    line2[j] = '>';
                    199:                    inquote = TRUE;
                    200:                }
                    201:            } else {
                    202:                if (inquote && inref)
                    203:                    fprintf(stderr, "Warning: Reference Quote conflict line %d\n", line_count);
                    204:                if (inquote) {
                    205:                    line2[j++] = '<';
                    206:                    line2[j++] = '/';
                    207:                    line2[j++] = 'B';
                    208:                    line2[j] = '>';
                    209:                    inquote = FALSE;
                    210:                }
                    211:                if (inref) {
                    212:                    /* must be inref */
                    213:                    line2[j++] = '<';
                    214:                    line2[j++] = '/';
                    215:                    line2[j++] = 'A';
                    216:                    line2[j] = '>';
                    217:                    inref = 0;
                    218:                }
                    219:            }
                    220:            break;
                    221:        default:
                    222:            line2[j] = line[i];
                    223:        }
                    224:        i++;
                    225:        j++;
                    226:        line2[j] = NUL;
                    227:     }
                    228:
                    229:     i = 1;
                    230:
                    231:     switch (line[0]) {         /* control character */
                    232:     case '?':{                 /* interactive help entry */
                    233: #ifdef FIXLATER
                    234:            if (intable)
                    235:                intablebut = TRUE;
                    236:            fprintf(b, "\n:i1. %s", &(line[1]));        /* index entry */
                    237: #endif
                    238:            break;
                    239:        }
                    240:     case '@':{                 /* start/end table */
                    241:            break;              /* ignore */
                    242:        }
                    243:     case '#':{                 /* latex table entry */
                    244:            break;              /* ignore */
                    245:        }
                    246:     case '^':{                 /* external link escape */
                    247:            (void) fputs(line + 1, b);  /* copy directly */
                    248:            break;              /* ignore */
                    249:        }
                    250:     case '%':{                 /* troff table entry */
                    251:            break;              /* ignore */
                    252:        }
                    253:     case '\n':                 /* empty text line */
                    254:        if (tabl)
                    255:            fprintf(b, "</PRE>\n");     /* rjl */
                    256:        para = 0;
                    257:        tabl = 0;
                    258:        fprintf(b, "<P>");
                    259:        break;
                    260:     case ' ':{                 /* normal text line */
                    261:            if ((line2[1] == NUL) || (line2[1] == '\n')) {
                    262:                fprintf(b, "<P>");
                    263:                para = 0;
                    264:                tabl = 0;
                    265:            }
                    266:            if (line2[1] == ' ') {
                    267:                if (!tabl) {
                    268:                    fprintf(b, "<PRE>\n");
                    269:                }
                    270:                fprintf(b, "%s\n", &line2[1]);
                    271:                tabl = 1;
                    272:                para = 0;
                    273:            } else {
                    274:                if (tabl) {
                    275:                    fprintf(b, "</PRE>\n<P>");  /* rjl */
                    276:                }
                    277:                tabl = 0;
                    278:                if (!para)
                    279:                    para = 1;   /* not in para so start one */
                    280:                fprintf(b, "%s \n", &line2[1]);
                    281:            }
                    282:            break;
                    283:        }
                    284:     default:{
                    285:            if (isdigit((int)line[0])) {        /* start of section */
                    286:                if (tabl)
                    287:                    fprintf(b, "</PRE>\n");     /* rjl */
                    288:                if (startpage) {        /* use the new level 0 */
                    289:                    refs(0, b, "<P>\n", "<P>\n", "<A HREF=\042#%d\042>%s</A><BR>\n");
                    290:                } else {
                    291:                    refs(last_line, b, "<P>\n", "<P>\n", "<A HREF=\042#%d\042>%s</A><BR>\n");
                    292:                }
                    293:                para = 0;       /* not in a paragraph */
                    294:                tabl = 0;
                    295:                last_line = line_count;
                    296:                startpage = 0;
                    297:                if (debug)
                    298:                    fprintf(stderr, "%d: %s\n", line_count, &line2[1]);
                    299:                klist = lookup(&line2[1]);
                    300:                if (klist)
                    301:                    k = klist->line;
                    302:                else
                    303:                    k = -1;
                    304:                /* output unique ID and section title */
                    305:                fprintf(b, "<HR><A NAME=\042%d\042>\n<H%c>", line_count, line[0] == '1' ? line[0] : line[0] - 1);
                    306:                fprintf(b, &(line2[1]));        /* title */
                    307:                fprintf(b, "</H%c>\n<P>", line[0] == '1' ? line[0] : line[0] - 1);
                    308:            } else
                    309:                fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
                    310:                        line[0], line_count);
                    311:            break;
                    312:        }
                    313:     }
                    314: }

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