Blame docs/doc2gih.c

Packit 0986c0
#ifndef lint
Packit 0986c0
static char *RCSid() { return RCSid("$Id: doc2gih.c,v 1.18 2017/07/02 05:24:35 sfeam Exp $"); }
Packit 0986c0
#endif
Packit 0986c0
Packit 0986c0
/* GNUPLOT - doc2gih.c */
Packit 0986c0
Packit 0986c0
/*[
Packit 0986c0
 * Copyright 1986 - 1993, 1998, 2004   Thomas Williams, Colin Kelley
Packit 0986c0
 *
Packit 0986c0
 * Permission to use, copy, and distribute this software and its
Packit 0986c0
 * documentation for any purpose with or without fee is hereby granted,
Packit 0986c0
 * provided that the above copyright notice appear in all copies and
Packit 0986c0
 * that both that copyright notice and this permission notice appear
Packit 0986c0
 * in supporting documentation.
Packit 0986c0
 *
Packit 0986c0
 * Permission to modify the software is granted, but not the right to
Packit 0986c0
 * distribute the complete modified source code.  Modifications are to
Packit 0986c0
 * be distributed as patches to the released version.  Permission to
Packit 0986c0
 * distribute binaries produced by compiling modified sources is granted,
Packit 0986c0
 * provided you
Packit 0986c0
 *   1. distribute the corresponding source modifications from the
Packit 0986c0
 *    released version in the form of a patch file along with the binaries,
Packit 0986c0
 *   2. add special version identification to distinguish your version
Packit 0986c0
 *    in addition to the base release version number,
Packit 0986c0
 *   3. provide your name and address as the primary contact for the
Packit 0986c0
 *    support of your modified version, and
Packit 0986c0
 *   4. retain our contact information in regard to use of the base
Packit 0986c0
 *    software.
Packit 0986c0
 * Permission to distribute the released version of the source code along
Packit 0986c0
 * with corresponding source modifications in the form of a patch file is
Packit 0986c0
 * granted with same provisions 2 through 4 for binary distributions.
Packit 0986c0
 *
Packit 0986c0
 * This software is provided "as is" without express or implied warranty
Packit 0986c0
 * to the extent permitted by applicable law.
Packit 0986c0
]*/
Packit 0986c0
Packit 0986c0
/*
Packit 0986c0
 * doc2gih.c  -- program to convert Gnuplot .DOC format to gnuplot
Packit 0986c0
 * interactive help (.GIH) format.
Packit 0986c0
 *
Packit 0986c0
 * This involves stripping all lines with a leading digit or
Packit 0986c0
 * a leading @, #, or %.
Packit 0986c0
 * Modified by Russell Lang from hlp2ms.c by Thomas Williams
Packit 0986c0
 *
Packit 0986c0
 * usage:  doc2gih [file.doc [file.gih]]
Packit 0986c0
 *
Packit 0986c0
 * Original version by David Kotz used the following one line script!
Packit 0986c0
 * sed '/^[0-9@#%]/d' file.doc > file.gih
Packit 0986c0
 */
Packit 0986c0
Packit 0986c0
#ifdef HAVE_CONFIG_H
Packit 0986c0
# include "config.h"
Packit 0986c0
#endif
Packit 0986c0
Packit 0986c0
#include "syscfg.h"
Packit 0986c0
#include "stdfn.h"
Packit 0986c0
#include "doc2x.h"
Packit 0986c0
Packit 0986c0
void convert __PROTO((FILE *, FILE *));
Packit 0986c0
void process_line __PROTO((char *, FILE *));
Packit 0986c0
Packit 0986c0
int
Packit 0986c0
main (int argc, char **argv)
Packit 0986c0
{
Packit 0986c0
    FILE *infile;
Packit 0986c0
    FILE *outfile;
Packit 0986c0
Packit 0986c0
    infile = stdin;
Packit 0986c0
    outfile = stdout;
Packit 0986c0
Packit 0986c0
    if (argc > 3) {
Packit 0986c0
	fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
Packit 0986c0
	exit(EXIT_FAILURE);
Packit 0986c0
    }
Packit 0986c0
    if (argc >= 2) {
Packit 0986c0
	if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
Packit 0986c0
	    fprintf(stderr, "%s: Can't open %s for reading\n",
Packit 0986c0
		    argv[0], argv[1]);
Packit 0986c0
	    exit(EXIT_FAILURE);
Packit 0986c0
	}
Packit 0986c0
    }
Packit 0986c0
    if (argc == 3) {
Packit 0986c0
	if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
Packit 0986c0
	    fprintf(stderr, "%s: Can't open %s for writing\n",
Packit 0986c0
		    argv[0], argv[2]);
Packit 0986c0
	    exit(EXIT_FAILURE);
Packit 0986c0
	}
Packit 0986c0
    }
Packit 0986c0
Packit 0986c0
    convert(infile, outfile);
Packit 0986c0
Packit 0986c0
    return EXIT_SUCCESS;
Packit 0986c0
}
Packit 0986c0
Packit 0986c0
Packit 0986c0
void
Packit 0986c0
convert (FILE *inf, FILE *outf)
Packit 0986c0
{
Packit 0986c0
    static char line[MAX_LINE_LEN+1];
Packit 0986c0
Packit 0986c0
    while (get_line(line, sizeof(line), inf))
Packit 0986c0
        process_line(line, outf);
Packit 0986c0
}
Packit 0986c0
Packit 0986c0
Packit 0986c0
void
Packit 0986c0
process_line(char *line, FILE *b)
Packit 0986c0
{
Packit 0986c0
    static int line_count = 0;
Packit 0986c0
Packit 0986c0
    line_count++;
Packit 0986c0
Packit 0986c0
    switch (line[0]) {		/* control character */
Packit 0986c0
    case '?':{			/* interactive help entry */
Packit 0986c0
	    (void) fputs(line, b);
Packit 0986c0
	    break;
Packit 0986c0
	}
Packit 0986c0
    case '@':{			/* start/end table */
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case '#':{			/* latex table entry */
Packit 0986c0
	    if (line[1] == 'b' && line[2] == ' ') {	/* bullet */
Packit 0986c0
		fputs(" * ", b);
Packit 0986c0
		fputs(line+2, b);
Packit 0986c0
	    }  else if (line[1] == '#') {
Packit 0986c0
		fputs("   ", b);
Packit 0986c0
		fputs(line+2, b);
Packit 0986c0
	    }
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case '=':{			/* latex index entry */
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case 'F':{			/* latex embedded figure */
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case '%':{			/* troff table entry */
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case '^':{			/* html entry */
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case '\n':			/* empty text line */
Packit 0986c0
    case ' ':{			/* normal text line */
Packit 0986c0
	    (void) fputs(line, b);
Packit 0986c0
	    break;
Packit 0986c0
	}
Packit 0986c0
    default:{
Packit 0986c0
	    if (isdigit((int)line[0])) {	/* start of section */
Packit 0986c0
		/* ignore */
Packit 0986c0
	    } else
Packit 0986c0
		fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
Packit 0986c0
			line[0], line_count);
Packit 0986c0
	    break;
Packit 0986c0
	}
Packit 0986c0
    }
Packit 0986c0
}