Blame docs/doc2ipf.c

Packit 0986c0
#ifndef lint
Packit 0986c0
static char *RCSid() { return RCSid("$Id: doc2ipf.c,v 1.23 2012/05/21 20:39:20 sfeam Exp $"); }
Packit 0986c0
#endif
Packit 0986c0
Packit 0986c0
/* GNUPLOT - doc2ipf.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
 * doc2ipf.c  -- program to convert Gnuplot .DOC format to OS/2
Packit 0986c0
 * ipfc  (.inf/.hlp) format.
Packit 0986c0
 *
Packit 0986c0
 * Modified by Roger Fearick from doc2rtf by M Castro
Packit 0986c0
 *
Packit 0986c0
 * usage:  doc2ipf gnuplot.doc gnuplot.ipf
Packit 0986c0
 *
Packit 0986c0
 */
Packit 0986c0
Packit 0986c0
/* note that tables must begin in at least the second column to */
Packit 0986c0
/* be formatted correctly and tabs are forbidden */
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
Packit 0986c0
#define MAX_LINE_LEN 1023
Packit 0986c0
Packit 0986c0
#include "doc2x.h"
Packit 0986c0
#include "xref.h"
Packit 0986c0
Packit 0986c0
#define MAX_COL 6
Packit 0986c0
Packit 0986c0
/* From xref.c */
Packit 0986c0
extern void *xmalloc __PROTO((size_t));
Packit 0986c0
Packit 0986c0
void convert __PROTO((FILE *, FILE *));
Packit 0986c0
void process_line __PROTO((char *, FILE *));
Packit 0986c0
Packit 0986c0
/* malloc's are not being checked ! */
Packit 0986c0
Packit 0986c0
struct TABENTRY {		/* may have MAX_COL column tables */
Packit 0986c0
    struct TABENTRY *next;
Packit 0986c0
    char col[MAX_COL][256];
Packit 0986c0
};
Packit 0986c0
Packit 0986c0
struct TABENTRY table;
Packit 0986c0
struct TABENTRY *tableins = &table;
Packit 0986c0
int tablecols = 0;
Packit 0986c0
int tablewidth[MAX_COL] = {0, 0, 0, 0, 0, 0};	/* there must be the correct
Packit 0986c0
							   number of zeroes here */
Packit 0986c0
int tablelines = 0;
Packit 0986c0
Packit 0986c0
#define TmpFileName "doc2ipf.tmp"
Packit 0986c0
static TBOOLEAN debug = FALSE;
Packit 0986c0
Packit 0986c0
Packit 0986c0
int
Packit 0986c0
main (int argc, char **argv)
Packit 0986c0
{
Packit 0986c0
    FILE *infile;
Packit 0986c0
    FILE *outfile;
Packit 0986c0
    if (argc == 4 && argv[3][0] == '-' && argv[3][1] == 'd')
Packit 0986c0
	debug = TRUE;
Packit 0986c0
Packit 0986c0
    if (argc != 3 && !debug) {
Packit 0986c0
	fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
Packit 0986c0
	exit(EXIT_FAILURE);
Packit 0986c0
    }
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
    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
	fclose(infile);
Packit 0986c0
	exit(EXIT_FAILURE);
Packit 0986c0
    }
Packit 0986c0
    parse(infile);
Packit 0986c0
    convert(infile, outfile);
Packit 0986c0
    return EXIT_SUCCESS;
Packit 0986c0
}
Packit 0986c0
Packit 0986c0
void
Packit 0986c0
convert(FILE *a, FILE *b)
Packit 0986c0
{
Packit 0986c0
    static char line[MAX_LINE_LEN+1];
Packit 0986c0
Packit 0986c0
    /* generate ipf header */
Packit 0986c0
    fprintf(b, ":userdoc.\n:prolog.\n");
Packit 0986c0
    fprintf(b, ":title.GNUPLOT\n");
Packit 0986c0
    fprintf(b, ":docprof toc=123456.\n:eprolog.\n");
Packit 0986c0
Packit 0986c0
    /* process each line of the file */
Packit 0986c0
    while (get_line(line, sizeof(line), a)) {
Packit 0986c0
	process_line(line, b);
Packit 0986c0
    }
Packit 0986c0
Packit 0986c0
    /* close final page and generate trailer */
Packit 0986c0
    fprintf(b, "\n:euserdoc.\n");
Packit 0986c0
Packit 0986c0
    list_free();
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
    static char line2[MAX_LINE_LEN+1];
Packit 0986c0
    char hyplink1[64];
Packit 0986c0
    char *pt, *tablerow;
Packit 0986c0
    int i;
Packit 0986c0
    int j;
Packit 0986c0
    static int startpage = 1;
Packit 0986c0
    char str[MAX_LINE_LEN+1];
Packit 0986c0
    char topic[MAX_LINE_LEN+1];
Packit 0986c0
    int k, l;
Packit 0986c0
    static int tabl = 0;
Packit 0986c0
    static int para = 0;
Packit 0986c0
    static int inquote = FALSE;
Packit 0986c0
    static int inref = FALSE;
Packit 0986c0
    static int intable = FALSE;
Packit 0986c0
    static int intablebut = FALSE;
Packit 0986c0
    static int introffheader = FALSE;
Packit 0986c0
    static char tablechar = '@';
Packit 0986c0
    static FILE *bo = NULL, *bt = NULL;
Packit 0986c0
    static char tabledelim[4] = "%@\n";
Packit 0986c0
    static int nblanks = 0;
Packit 0986c0
    struct LIST *klist;
Packit 0986c0
Packit 0986c0
    line_count++;
Packit 0986c0
Packit 0986c0
    if (debug && introffheader) {
Packit 0986c0
	fprintf(stderr, "%s\n", line);
Packit 0986c0
    }
Packit 0986c0
    if (bo == NULL)
Packit 0986c0
	bo = b;
Packit 0986c0
    i = 0;
Packit 0986c0
    j = 0;
Packit 0986c0
    nblanks = 0;
Packit 0986c0
    while (line[nblanks] == ' ')
Packit 0986c0
	++nblanks;
Packit 0986c0
    while (line[i] != NUL) {
Packit 0986c0
	if (introffheader) {
Packit 0986c0
	    if (line[i] != '\n')
Packit 0986c0
		line2[j] = line[i];
Packit 0986c0
	    else
Packit 0986c0
		line2[j] = NUL;
Packit 0986c0
	} else
Packit 0986c0
	    switch (line[i]) {
Packit 0986c0
	    case '$':
Packit 0986c0
		/* FIXME: this fails for '$' entry in 'unitary operators' */
Packit 0986c0
		if (intable && (tablechar != '$') && (line[0] == '%')) {
Packit 0986c0
		    if (line[++i] == NUL || line[i+1] == NUL)
Packit 0986c0
			break;
Packit 0986c0
		    if (line[i + 1] == '$' || line[i] == 'x' || line[i] == '|') {
Packit 0986c0
			while (line[i] && line[i] != '$')
Packit 0986c0
			    line2[j++] = line[i++];
Packit 0986c0
			--j;
Packit 0986c0
		    } else {
Packit 0986c0
			while (line[i] != '$' && line[i+1] != NUL)
Packit 0986c0
			    i++;
Packit 0986c0
			if (line[i + 1] == ',')
Packit 0986c0
			    i++;
Packit 0986c0
			if (line[i + 1] == ' ')
Packit 0986c0
			    i++;
Packit 0986c0
			line2[j] = line[++i];
Packit 0986c0
		    }
Packit 0986c0
		} else
Packit 0986c0
		    line2[j] = line[i];
Packit 0986c0
		break;
Packit 0986c0
Packit 0986c0
	    case ':':
Packit 0986c0
		strcpy(&line2[j], "&colon.");
Packit 0986c0
		j += strlen("&colon.") - 1;
Packit 0986c0
		break;
Packit 0986c0
Packit 0986c0
	    case '&':
Packit 0986c0
		/* real hack to solve \&_ in postscript doc tables */
Packit 0986c0
		/* (which are a special case hack anyway. */
Packit 0986c0
		if (j > 0 && line2[j - 1] == '\\') {
Packit 0986c0
		    j -= 2;
Packit 0986c0
		    break;
Packit 0986c0
		}
Packit 0986c0
		strcpy(&line2[j], "&amp.");
Packit 0986c0
		j += strlen("&amp.") - 1;
Packit 0986c0
		break;
Packit 0986c0
Packit 0986c0
	    case '\r':
Packit 0986c0
	    case '\n':
Packit 0986c0
		break;
Packit 0986c0
Packit 0986c0
	    case '`':		/* backquotes mean boldface or link */
Packit 0986c0
		if (nblanks > 7) {
Packit 0986c0
		    line2[j] = line[i];
Packit 0986c0
		    break;
Packit 0986c0
		}
Packit 0986c0
		if ((!inref) && (!inquote)) {
Packit 0986c0
		    k = i + 1;	/* index into current string */
Packit 0986c0
		    l = 0;	/* index into topic string */
Packit 0986c0
		    while ((line[k] != '`') && (line[k] != 0)) {
Packit 0986c0
			topic[l] = line[k];
Packit 0986c0
			k++;
Packit 0986c0
			l++;
Packit 0986c0
		    }
Packit 0986c0
		    topic[l] = 0;
Packit 0986c0
		    klist = lookup(topic);
Packit 0986c0
		    if (klist != NULL && (k = klist->line) > 0) {
Packit 0986c0
			sprintf(hyplink1, ":link reftype=hd res=%d.", k);
Packit 0986c0
			strcpy(line2 + j, hyplink1);
Packit 0986c0
			j += strlen(hyplink1) - 1;
Packit 0986c0
Packit 0986c0
			inref = k;
Packit 0986c0
		    } else {
Packit 0986c0
			if (debug)
Packit 0986c0
			    fprintf(stderr, "Can't make link for \042%s\042 on line %d\n", topic, line_count);
Packit 0986c0
			strcpy(line2 + j, ":hp2.");
Packit 0986c0
			j += 4;
Packit 0986c0
			inquote = TRUE;
Packit 0986c0
		    }
Packit 0986c0
		} else {
Packit 0986c0
		    if (inquote && inref)
Packit 0986c0
			fprintf(stderr, "Warning: Reference Quote conflict line %d\n", line_count);
Packit 0986c0
		    if (inquote) {
Packit 0986c0
			strcpy(line2 + j, ":ehp2.");
Packit 0986c0
			j += 5;
Packit 0986c0
			inquote = FALSE;
Packit 0986c0
		    }
Packit 0986c0
		    if (inref) {
Packit 0986c0
			/* must be inref */
Packit 0986c0
			strcpy(line2 + j, ":elink.");
Packit 0986c0
			j += 6;
Packit 0986c0
			inref = FALSE;
Packit 0986c0
		    }
Packit 0986c0
		}
Packit 0986c0
		break;
Packit 0986c0
Packit 0986c0
	    case '.':
Packit 0986c0
		/* Makes code less readable but fixes warnings like
Packit 0986c0
		   <..\docs\gnuplot.ipf:6546> Warning 204: Invalid macro [.gnuplot_iris4d]
Packit 0986c0
		   which is triggered by a '.' character in the first column */
Packit 0986c0
		if (i==1) {
Packit 0986c0
		    strcpy(line2+j, "&per.");
Packit 0986c0
		    j += 4;
Packit 0986c0
		} else
Packit 0986c0
		    line2[j] = line[i];
Packit 0986c0
		break;
Packit 0986c0
Packit 0986c0
	    default:
Packit 0986c0
		line2[j] = line[i];
Packit 0986c0
	    }
Packit 0986c0
	i++;
Packit 0986c0
	j++;
Packit 0986c0
	if ((j >= sizeof(line2))) {
Packit 0986c0
	    fprintf(stderr, "MAX_LINE_LEN exceeded\n");
Packit 0986c0
	    if (inref || inquote)
Packit 0986c0
		fprintf(stderr, "Possible missing link character (`) near above line number\n");
Packit 0986c0
	    abort();
Packit 0986c0
	}
Packit 0986c0
	line2[j] = NUL;
Packit 0986c0
    }
Packit 0986c0
Packit 0986c0
    i = 1;
Packit 0986c0
Packit 0986c0
    switch (line[0]) {		/* control character */
Packit 0986c0
    case '?':{			/* interactive help entry */
Packit 0986c0
	    if (line[1] != '\n') /* skip empty index entries */
Packit 0986c0
		fprintf(b, ":i1.%s", line+1);
Packit 0986c0
	    if (intable)
Packit 0986c0
		intablebut = TRUE;
Packit 0986c0
	    break;
Packit 0986c0
	}
Packit 0986c0
    case '@':{			/* start/end table */
Packit 0986c0
	    intable = !intable;
Packit 0986c0
	    if (intable) {
Packit 0986c0
		tablechar = '@';
Packit 0986c0
		introffheader = TRUE;
Packit 0986c0
		intablebut = FALSE;
Packit 0986c0
		tablelines = 0;
Packit 0986c0
		tablecols = 0;
Packit 0986c0
		tableins = &table;
Packit 0986c0
		for (j = 0; j < MAX_COL; j++)
Packit 0986c0
		    tablewidth[j] = 0;
Packit 0986c0
	    } else {		/* dump table */
Packit 0986c0
		int header = 0;
Packit 0986c0
		introffheader = FALSE; /* position is no longer in a troff header */
Packit 0986c0
		intablebut = FALSE;
Packit 0986c0
		tableins = &table;
Packit 0986c0
		fprintf(b, ":table frame=none rules=vert cols=\'");
Packit 0986c0
		for (j = 0; j < MAX_COL; j++)
Packit 0986c0
		    if (tablewidth[j] > 0)
Packit 0986c0
			fprintf(b, " %d", tablewidth[j]);
Packit 0986c0
		fprintf(b, "\'.\n");
Packit 0986c0
		tableins = tableins->next;
Packit 0986c0
		if (tableins->next != NULL)
Packit 0986c0
		    header = (tableins->next->col[0][1] == '_');
Packit 0986c0
		if (header)
Packit 0986c0
		    tableins->next = tableins->next->next;
Packit 0986c0
		while (tableins != NULL) {
Packit 0986c0
		    fprintf(b, ":row.\n");
Packit 0986c0
		    for (j = 0; j < tablecols; j++)
Packit 0986c0
			if (header)
Packit 0986c0
			    fprintf(b, ":c.:hp9.%s:ehp9.\n", tableins->col[j]);
Packit 0986c0
			else
Packit 0986c0
			    fprintf(b, ":c.%s\n", tableins->col[j]);
Packit 0986c0
		    tableins = tableins->next;
Packit 0986c0
 		    /* skip troff 'horizontal rule' command */		    
Packit 0986c0
 		    if (tableins)
Packit 0986c0
			if (tableins->col[0][1] == '_')
Packit 0986c0
			    tableins = tableins->next;
Packit 0986c0
		    header = 0;
Packit 0986c0
		}
Packit 0986c0
		fprintf(b, ":etable.\n");
Packit 0986c0
		if (bt != NULL) {
Packit 0986c0
		    rewind(bt);
Packit 0986c0
		    while (get_line(str, sizeof(str), bt))
Packit 0986c0
			fputs(str, b);
Packit 0986c0
		    fclose(bt);
Packit 0986c0
		    remove(TmpFileName);
Packit 0986c0
		    bt = NULL;
Packit 0986c0
		    bo = b;
Packit 0986c0
		}
Packit 0986c0
	    }
Packit 0986c0
	    break;
Packit 0986c0
	}
Packit 0986c0
    case '=':{			/* index entry */
Packit 0986c0
	    fprintf(b, ":i1.%s", line+1);
Packit 0986c0
	    break;
Packit 0986c0
	}
Packit 0986c0
    case 'F':{			/* latex embedded figure */
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case '#':{			/* latex table entry */
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case '%':{			/* troff table entry */
Packit 0986c0
	    if (intable) {
Packit 0986c0
		if (introffheader) {
Packit 0986c0
		    if (debug) {
Packit 0986c0
		       fprintf(stderr, ">%s\n", line2);
Packit 0986c0
		       fprintf(stderr, "tablechar: %c\n", tablechar);
Packit 0986c0
		    }
Packit 0986c0
		    if ((line[1] == '.') && (strchr(line2, tablechar) == NULL)) /* ignore troff commands */
Packit 0986c0
			break;
Packit 0986c0
		    pt = strchr(line2, '(');
Packit 0986c0
		    if (pt != NULL)
Packit 0986c0
			tablechar = *(pt + 1);
Packit 0986c0
		    if (debug) {
Packit 0986c0
		       fprintf(stderr, "tablechar: %c\n", tablechar);
Packit 0986c0
		    }
Packit 0986c0
		    pt = strchr(line2 + 2, '.');
Packit 0986c0
		    if (pt != NULL)
Packit 0986c0
			introffheader = FALSE;
Packit 0986c0
		    break;
Packit 0986c0
		}
Packit 0986c0
		if ((line[1] == '.') && (strchr(line+2, tablechar) == NULL)) {	/* ignore troff commands */
Packit 0986c0
		    introffheader = TRUE;
Packit 0986c0
		    break;
Packit 0986c0
		}
Packit 0986c0
		tablerow = line2;
Packit 0986c0
		tableins->next = xmalloc(sizeof(struct TABENTRY));
Packit 0986c0
		tableins = tableins->next;
Packit 0986c0
		tableins->next = NULL;
Packit 0986c0
		j = 0;
Packit 0986c0
		tabledelim[1] = tablechar;
Packit 0986c0
		line2[0] = tablechar;
Packit 0986c0
		while ((pt = strtok(tablerow, tabledelim + 1)) != NULL) {
Packit 0986c0
		    if (*pt != NUL) {	/* ignore null columns */
Packit 0986c0
			char *tagend, *tagstart;
Packit 0986c0
			/* this fails on format line */
Packit 0986c0
			if (j >= MAX_COL) {
Packit 0986c0
			    fprintf(stderr,"j >= MAX_COL\n");
Packit 0986c0
			    exit(EXIT_FAILURE);
Packit 0986c0
			}
Packit 0986c0
			while (*pt==' ') pt++; /* strip spaces */		
Packit 0986c0
			strcpy(tableins->col[j], " ");
Packit 0986c0
			strcat(tableins->col[j], pt);
Packit 0986c0
			k = strlen(pt);
Packit 0986c0
			while (pt[k-1]==' ') k--; /* strip spaces */
Packit 0986c0
			/* length calculation is not correct if we have ipf tag replacements! */
Packit 0986c0
			if (debug) {
Packit 0986c0
			    if (((strchr(pt, ':')!=NULL) && (strchr(pt, '.')!=NULL)) ||
Packit 0986c0
				((strchr(pt, '&')!=NULL) && (strchr(pt, '.')!=NULL)))
Packit 0986c0
				fprintf(stderr, "Warning: likely overestimating table width (%s)\n", pt);
Packit 0986c0
			}
Packit 0986c0
			/* crudely filter out ipf tags:
Packit 0986c0
			     "&tag." and ":tag." are recognized, 
Packit 0986c0
			     (works since all '&' and ':' characters have already been replaced)
Packit 0986c0
			*/
Packit 0986c0
			for (tagend = tagstart = pt; tagstart; ) {
Packit 0986c0
			    tagstart = strchr(tagend, '&';;
Packit 0986c0
			    if (!tagstart)
Packit 0986c0
				tagstart = strchr(tagend, ':');
Packit 0986c0
			    if (tagstart) {
Packit 0986c0
				tagend = strchr(tagstart, '.');
Packit 0986c0
				if (tagend)
Packit 0986c0
				    k -= tagend - tagstart;
Packit 0986c0
			    }
Packit 0986c0
			}
Packit 0986c0
			k += 2; /* add some space */
Packit 0986c0
			if (k > tablewidth[j])
Packit 0986c0
			    tablewidth[j] = k;
Packit 0986c0
			++j;
Packit 0986c0
			tablerow = NULL;
Packit 0986c0
			if (j > tablecols)
Packit 0986c0
			    tablecols = j;
Packit 0986c0
		    }
Packit 0986c0
		}
Packit 0986c0
		while (j < MAX_COL)
Packit 0986c0
		    tableins->col[j++][0] = NUL;
Packit 0986c0
	    }
Packit 0986c0
	    break;		/* ignore */
Packit 0986c0
	}
Packit 0986c0
    case '\n':			/* empty text line */
Packit 0986c0
	/* previously this used to emit ":p." to start a new paragraph,
Packit 0986c0
	   now we just note the end of a paragraph or table */
Packit 0986c0
	para = 0;
Packit 0986c0
	tabl = 0;
Packit 0986c0
	break;
Packit 0986c0
    case ' ':{			/* normal text line */
Packit 0986c0
	    if (intable && !intablebut)
Packit 0986c0
		break;
Packit 0986c0
	    if (intablebut) {	/* indexed items in  table, copy
Packit 0986c0
				   to file after table by saving in
Packit 0986c0
				   a temp file meantime */
Packit 0986c0
		if (bt == NULL) {
Packit 0986c0
		    fflush(bo);
Packit 0986c0
		    bt = fopen(TmpFileName, "w+");
Packit 0986c0
		    if (bt == NULL) {
Packit 0986c0
			fprintf(stderr, "Can't open %s\n", TmpFileName);
Packit 0986c0
		    }
Packit 0986c0
		    else
Packit 0986c0
			bo = bt;
Packit 0986c0
		}
Packit 0986c0
	    }
Packit 0986c0
	    if (intablebut && (bt == NULL))
Packit 0986c0
		break;
Packit 0986c0
	    if ((line2[1] == 0) || (line2[1] == '\n')) {
Packit 0986c0
		    fprintf(bo, ":p.");
Packit 0986c0
		para = 0;
Packit 0986c0
	    }
Packit 0986c0
	    if (line2[1] == ' ') {
Packit 0986c0
		/* start table in a new paragraph */
Packit 0986c0
		if (!tabl) {
Packit 0986c0
		    fprintf(bo, ":p.%s\n", &line2[1]);
Packit 0986c0
		    tabl = 1;	/* not in table so start one */
Packit 0986c0
		    para = 0;
Packit 0986c0
		} else {
Packit 0986c0
		    fprintf(bo, ".br\n%s\n", &line2[1]);
Packit 0986c0
		}
Packit 0986c0
	    } else {
Packit 0986c0
		if (!para) {
Packit 0986c0
		    fprintf(bo, ":p.");
Packit 0986c0
		    para = 1;	/* not in para so start one */
Packit 0986c0
		    tabl = 0;
Packit 0986c0
		}
Packit 0986c0
		fprintf(bo, "%s \n", &line2[1]);
Packit 0986c0
	    }
Packit 0986c0
	    fflush(bo);
Packit 0986c0
	    break;
Packit 0986c0
	}
Packit 0986c0
    case '^':
Packit 0986c0
	break;			/* ignore */
Packit 0986c0
    default:{
Packit 0986c0
#ifdef IPF_MENU_SECTIONS
Packit 0986c0
	    TBOOLEAN leaf;
Packit 0986c0
#endif
Packit 0986c0
	    
Packit 0986c0
	    if (isdigit((int)line[0])) {	/* start of section */
Packit 0986c0
		if (intable) {
Packit 0986c0
		    intablebut = TRUE;
Packit 0986c0
		    if (bt == NULL) {
Packit 0986c0
			fflush(bo);
Packit 0986c0
			bt = fopen(TmpFileName, "w+");
Packit 0986c0
			if (bt == NULL) {
Packit 0986c0
			    fprintf(stderr, "Can't open %s\n", TmpFileName);
Packit 0986c0
			}
Packit 0986c0
			else
Packit 0986c0
			    bo = bt;
Packit 0986c0
		    }
Packit 0986c0
		}
Packit 0986c0
Packit 0986c0
		if (debug) {
Packit 0986c0
		   fprintf(stderr, "%d: %s\n", line_count, &line2[1]);
Packit 0986c0
		}
Packit 0986c0
		klist = lookup(&line2[2]);
Packit 0986c0
		if (klist != NULL)
Packit 0986c0
		    k = klist->line;
Packit 0986c0
		    
Packit 0986c0
		/* end all sections in an empty paragraph to prevent empty sections */
Packit 0986c0
		/* we therefore do no longer have to start sections with an empty paragraph */
Packit 0986c0
		if (!startpage)
Packit 0986c0
		    fprintf(bo, ":p.\n");
Packit 0986c0
		
Packit 0986c0
		/*if( k<0 ) fprintf(bo,":h%c.", line[0]=='1'?line[0]:line[0]-1);
Packit 0986c0
		   else */
Packit 0986c0
Packit 0986c0
#ifdef IPF_MENU_SECTIONS
Packit 0986c0
		/* To make navigation with the old IBM online help viewer (View)
Packit 0986c0
		   easier, the following code creates additional panels which contain
Packit 0986c0
		   references to sub-sections. These are not really needed for
Packit 0986c0
		   Aaron Lawrence's NewView and are therefore disabled by default.
Packit 0986c0
		*/
Packit 0986c0
Packit 0986c0
		/* is this section a leaf ? */
Packit 0986c0
		leaf = TRUE:	
Packit 0986c0
		if (klist)
Packit 0986c0
		    if (klist->next)
Packit 0986c0
			leaf = (klist->next->level <= klist->level);
Packit 0986c0
		
Packit 0986c0
		/* if not create a reference panel */
Packit 0986c0
		if (!leaf) {
Packit 0986c0
		    fprintf(bo, ":h%c res=%d x=left y=top width=20%% height=100%% group=1.%s\n",
Packit 0986c0
		            line[0], line_count, line2+1);
Packit 0986c0
		    fprintf(bo, ":link auto reftype=hd res=%d.\n", line_count+20000);
Packit 0986c0
		    fprintf(bo, ":hp2.%s:ehp2.\n.br\n", line2+1);
Packit 0986c0
		    refs(line_count, bo, NULL, NULL, ":link reftype=hd res=%d.%s:elink.\n.br\n");
Packit 0986c0
		    fprintf(bo, ":h%c res=%d x=right y=top width=80%% height=100%% group=2 hide.", 
Packit 0986c0
		            line[0]+1, line_count+20000);
Packit 0986c0
		}
Packit 0986c0
		else {
Packit 0986c0
		    fprintf(bo, ":h%c res=%d x=right y=top width=80%% height=100%% group=2.", line[0], line_count);
Packit 0986c0
		}
Packit 0986c0
#else		
Packit 0986c0
		fprintf(bo, ":h%c res=%d.", line[0], line_count);
Packit 0986c0
#endif		
Packit 0986c0
		fprintf(bo, "%s\n", line2+1);	/* title */
Packit 0986c0
		
Packit 0986c0
		/* add title page */
Packit 0986c0
		if (startpage)
Packit 0986c0
		    fprintf(bo, ".im titlepag.ipf\n");
Packit 0986c0
		    
Packit 0986c0
		para = 0;	/* not in a paragraph */
Packit 0986c0
		tabl = 0;	/* not in a table     */
Packit 0986c0
		startpage = 0;
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
	}
Packit 0986c0
	break;
Packit 0986c0
    }
Packit 0986c0
}