#ifndef lint
static char *RCSid() { return RCSid("$Id: doc2tex.c,v 1.31 2017-07-14 19:16:28 sfeam Exp $"); }
#endif
/* GNUPLOT - doc2tex.c */
/*[
* Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/*
* doc2tex.c -- program to convert Gnuplot .DOC format to LaTeX document
* Also will work for VMS .HLP files.
* Modified by Russell Lang from hlp2ms.c by Thomas Williams
* Extended by David Kotz to support quotes ("), backquotes, tables.
* Extended by Jens Emmerich to handle '_', '---', paired single
* quotes. Changed "-handling. Added pre/post-verbatim hooks.
*
*
* usage: doc2tex [file.doc [file.tex]]
*
* where file.doc is a Gnuplot .DOC file, and file.tex will be an
* article document suitable for printing with LaTeX.
*
* typical usage for GNUPLOT:
*
* doc2tex gnuplot.doc gnuplot.tex
* latex gnuplot.tex ; latex gnuplot.tex
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "syscfg.h"
#include "stdfn.h"
#include "doc2x.h"
void init __PROTO((FILE *));
void convert __PROTO((FILE *, FILE *));
void process_line __PROTO((char *, FILE *));
void section __PROTO((char *, FILE *));
void puttex __PROTO((char *, FILE *));
void finish __PROTO((FILE *));
static TBOOLEAN intable = FALSE;
static TBOOLEAN verb = FALSE;
static TBOOLEAN see = FALSE;
static TBOOLEAN inhref = FALSE;
static TBOOLEAN figures = FALSE;
int
main (int argc, char **argv)
{
FILE *infile;
FILE *outfile;
int inarg = 1;
infile = stdin;
outfile = stdout;
if (argc > 1 && !strcmp(argv[1],"-figures")) {
figures = TRUE;
inarg = 2;
}
if (argc > (figures ? 4 : 3)) {
fprintf(stderr, "Usage: %s [-figures] [infile [outfile]]\n", argv[0]);
exit(EXIT_FAILURE);
}
if (argc > inarg) {
if ((infile = fopen(argv[inarg], "r")) == (FILE *) NULL) {
fprintf(stderr, "%s: Can't open %s for reading\n",
argv[0], argv[inarg]);
exit(EXIT_FAILURE);
}
}
if (argc == inarg+2) {
if ((outfile = fopen(argv[inarg+1], "w")) == (FILE *) NULL) {
fprintf(stderr, "%s: Can't open %s for writing\n",
argv[0], argv[inarg+1]);
exit(EXIT_FAILURE);
}
}
init(outfile);
convert(infile, outfile);
finish(outfile);
return EXIT_SUCCESS;
}
void
init(FILE *b)
{
(void) fputs("\\input{titlepag.tex}\n", b);
}
void
convert(FILE *a, FILE *b)
{
static char line[MAX_LINE_LEN+1];
while (get_line(line, sizeof(line), a))
process_line(line, b);
}
void
process_line( char *line, FILE *b)
{
char string[MAX_LINE_LEN+1], c;
int i, initlen;
char *ind;
static TBOOLEAN parsed = FALSE;
initlen = strlen(line);
switch (line[0]) { /* control character */
case '?': /* interactive help entry */
/* convert '?xxx' to '\label{xxx}' */
line[strlen(line)-1]=NUL;
(void) fputs("\\label{",b);
fputs(line+1, b);
(void) fputs("}\n",b);
if (!strpbrk(line+1," ")) { /* Make an index entry also */
(void) fputs("\\index{",b);
while ((ind = strpbrk(line+1,"-_")))
*ind = ' ';
fputs(line+1, b);
(void) fputs("}\n",b);
}
break; /* ignore */ /* */
if ((i >= (initlen - 5)) || !strstr(line, "")) {
/* HBB CODEME 2015-08-21: no yyy text, or no closing .
** treat this as a multiline href, and just output the entry TeX for now: */
inhref = TRUE;
in_internal_href = TRUE;
strcpy(internal_href_string, string);
} else {
for ( ; i < (initlen - 5); i++) {
fputc(line[i],b);
}
fputs(" (p.~\\pageref{",b);
fputs(string,b);
fputs("})} ",b);
inhref = FALSE;
in_internal_href = FALSE;
}
} else {
inhref = TRUE;
in_internal_href = FALSE;
if (strstr(line,"") == NULL){
/* To always place urls on a separate line */
/* fputs("\\par\\hskip2.7em\\href{",b); */
fputs("\\href{",b);
} else {
fputs("\\href{",b);
}
parsed = 0;
for (i = 11; i < initlen-1 ; i++){
c = line[i];
if (c == '"') {
;
} else if ( c == '>' && parsed == 0) {
fputs("}{\\tt ",b); parsed = 1;
} else if ( c == '~') {
fputs("\\~",b);
} else if ( c == '_' && parsed == 1) {
fputs("\\_",b);
} else if ( c == '