From c617ada4396d9efdfb0a7957496fc4d19f0d7b31 Mon Sep 17 00:00:00 2001 From: wlemb Date: Wed, 17 Jan 2001 14:58:04 +0000 Subject: new html preprocessor --- src/preproc/html/Makefile.sub | 7 + src/preproc/html/pre-html.cc | 1108 ++++++++++++++++++++++++++++++++++++ src/preproc/html/pre-html.h | 37 ++ src/preproc/html/pushbackbuffer.cc | 337 +++++++++++ src/preproc/html/pushbackbuffer.h | 54 ++ 5 files changed, 1543 insertions(+) create mode 100644 src/preproc/html/Makefile.sub create mode 100644 src/preproc/html/pre-html.cc create mode 100644 src/preproc/html/pre-html.h create mode 100755 src/preproc/html/pushbackbuffer.cc create mode 100755 src/preproc/html/pushbackbuffer.h diff --git a/src/preproc/html/Makefile.sub b/src/preproc/html/Makefile.sub new file mode 100644 index 00000000..9d5045a9 --- /dev/null +++ b/src/preproc/html/Makefile.sub @@ -0,0 +1,7 @@ +PROG=pre-grohtml +# MAN1=pre-grohtml.n +MAN1= +XLIBS=$(LIBGROFF) +OBJS=pre-html.o pushbackbuffer.o +CCSRCS=$(srcdir)/pre-html.cc $(srcdir)/pushbackbuffer.cc +NAMEPREFIX=$(g) diff --git a/src/preproc/html/pre-html.cc b/src/preproc/html/pre-html.cc new file mode 100644 index 00000000..61b8a56f --- /dev/null +++ b/src/preproc/html/pre-html.cc @@ -0,0 +1,1108 @@ +// -*- C++ -*- +/* Copyright (C) 2000, 2001 Free Software Foundation, Inc. + Written by Gaius Mulley (gaius@glam.ac.uk). + +This file is part of groff. + +groff is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +groff is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with groff; see the file COPYING. If not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#define PREHTMLC + +#include +#include +#include +#include +#include +#include +#include +#include "lib.h" +#include "errarg.h" +#include "error.h" +#include "stringclass.h" +#include "posix.h" + +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef _POSIX_VERSION +#include +#define PID_T pid_t +#else /* not _POSIX_VERSION */ +#define PID_T int +#endif /* not _POSIX_VERSION */ + +extern char *strerror(); + +#include "pre-html.h" +#include "pushbackbuffer.h" +#include "html-strings.h" + +#define POSTSCRIPTRES 72000 // maybe there is a better way to find this? --fixme-- +#define DEFAULT_IMAGE_RES 80 // 80 pixels per inch resolution +#define DEFAULT_VERTICAL_OFFSET 40 // 40/72 of an inch +#define IMAGE_BOARDER_PIXELS 10 + +#define TRANSPARENT "-background \"#FFF\" -transparent \"#FFF\"" + +// #define DEBUGGING +// #define DEBUG_HTML + +#if !defined(TRUE) +# define TRUE (1==1) +#endif +#if !defined(FALSE) +# define FALSE (1==0) +#endif + +void stop() {} + +typedef enum {CENTERED, LEFT, RIGHT, INLINE} IMAGE_ALIGNMENT; + +static int stdoutfd = 1; // output file descriptor - normally 1 but might move + // -1 means closed +static int copyofstdoutfd =-1; // a copy of stdout, so we can restore stdout when + // writing to post-html +static char *psFileName = 0; // name of postscript file +static char *regionFileName = 0; // name of file containing all image regions +static char *imagePageStem = 0; // stem of all files containing page images +static char *image_device = "pnmraw"; +static int image_res = DEFAULT_IMAGE_RES; +static int vertical_offset= DEFAULT_VERTICAL_OFFSET; +static char *image_template = 0; // image template filename +static int troff_arg = 0; // troff arg index +#if defined(DEBUGGING) +static int debug = FALSE; +static char *troffFileName = 0; // output of pre-html output which is sent to troff -Tps +static char *htmlFileName = 0; // output of pre-html output which is sent to troff -Thtml +#endif + + +/* + * Images are generated via postscript, gs and the pnm utilities. + */ + +#define IMAGE_DEVICE "-Tps" + +/* + * prototypes + */ +static int do_file(const char *filename); + +/* + * sys_fatal - writes a fatal error message. Taken from src/roff/groff/pipeline.c + */ + +void sys_fatal (const char *s) +{ + fprintf(stderr, "%s: %s: %s", program_name, s, strerror(errno)); +} + +/* + * the class and methods for retaining ascii text + */ + +struct char_block { + enum { SIZE = 256 }; + char buffer[SIZE]; + int used; + char_block *next; + + char_block(); +}; + +/* + * char_block - constructor, sets the, used, and, next, fields to zero. + */ + +char_block::char_block() +: used(0), next(0) +{ +} + +class char_buffer { +public: + char_buffer(); + ~char_buffer(); + int read_file(FILE *fp); + int do_html(int argc, char *argv[]); + int do_image(int argc, char *argv[]); + void write_file_html(void); + void write_file_troff(void); + void write_upto_newline (char_block **t, int *i); + int can_see(char_block **t, int *i, char *string); + int skip_spaces(char_block **t, int *i); + void skip_to_newline(char_block **t, int *i); +private: + char_block *head; + char_block *tail; +}; + +/* + * char_buffer - constructor + */ + +char_buffer::char_buffer() +: head(0), tail(0) +{ +} + +/* + * char_buffer - deconstructor, throws aways the whole buffer list. + */ + +char_buffer::~char_buffer() +{ + while (head != 0) { + char_block *temp = head; + head = head->next; + delete temp; + } +} + +/* + * read_file - read in a complete file, fp, placing the contents inside char_blocks. + */ + +int char_buffer::read_file (FILE *fp) +{ + int i=0; + unsigned int old_used; + int n; + + while (! feof(fp)) { + if (tail == 0) { + tail = new char_block; + head = tail; + } else { + if (tail->used == char_block::SIZE) { + tail->next = new char_block; + tail = tail->next; + } + } + // at this point we have a tail which is ready for the next SIZE bytes of the file + + n = fread(tail->buffer, sizeof(char), char_block::SIZE-tail->used, fp); + if (n <= 0) { + // error + return( 0 ); + } else { + tail->used += n*sizeof(char); + } + } + return( 1 ); +} + +/* + * writeNbytes - writes n bytes to stdout. + */ + +static void writeNbytes (char *s, int l) +{ + int n=0; + int r; + + while (nused) && ((*t)->buffer[j] != '\n')) { + j++; + } + if ((j < (*t)->used) && ((*t)->buffer[j] == '\n')) { + j++; + } + writeNbytes((*t)->buffer+(*i), j-(*i)); + if (j == (*t)->used) { + *i = 0; + if ((*t)->buffer[j-1] == '\n') { + *t = (*t)->next; + } else { + *t = (*t)->next; + write_upto_newline(t, i); + } + } else { + // newline was seen + *i = j; + } + } +} + +/* + * can_see - returns TRUE if we can see string in t->buffer[i] onwards + */ + +int char_buffer::can_see (char_block **t, int *i, char *string) +{ + int j = 0; + int l = strlen(string); + int k = *i; + char_block *s = *t; + + while (s) { + while ((kused) && (jbuffer[k] == string[j])) { + j++; + k++; + } + if (j == l) { + *i = k; + *t = s; + return( TRUE ); + } else if ((kused) && (s->buffer[k] != string[j])) { + return( FALSE ); + } + s = s->next; + k = 0; + } + return( FALSE ); +} + +/* + * skip_spaces - returns TRUE if we have not run out of data. + * It also consumes spaces. + */ + +int char_buffer::skip_spaces(char_block **t, int *i) +{ + char_block *s = *t; + int k = *i; + + while (s) { + while ((kused) && (isspace(s->buffer[k]))) { + k++; + } + if (k == s->used) { + k = 0; + s = s->next; + } else { + *i = k; + return( TRUE ); + } + } + return( FALSE ); +} + +/* + * skip_to_newline - skips all characters until a newline is seen. + * The newline is also consumed. + */ + +void char_buffer::skip_to_newline (char_block **t, int *i) +{ + int j=*i; + + if (*t) { + while ((j < (*t)->used) && ((*t)->buffer[j] != '\n')) { + j++; + } + if ((j < (*t)->used) && ((*t)->buffer[j] == '\n')) { + j++; + } + if (j == (*t)->used) { + *i = 0; + if ((*t)->buffer[j-1] == '\n') { + *t = (*t)->next; + } else { + *t = (*t)->next; + skip_to_newline(t, i); + } + } else { + // newline was seen + *i = j; + } + } +} + +/* + * write_file_troff - writes the buffer to stdout (troff). + */ + +void char_buffer::write_file_troff (void) +{ + char_block *t=head; + int r; + int i=0; + + if (t != 0) { + do { + /* + * remember to check the shortest string last + */ + if (can_see(&t, &i, HTML_IMAGE_END)) { + write_end_image(FALSE); + skip_to_newline(&t, &i); + } else if (can_see(&t, &i, HTML_IMAGE_LEFT)) { + write_start_image(LEFT, FALSE); + skip_to_newline(&t, &i); + } else if (can_see(&t, &i, HTML_IMAGE_RIGHT)) { + write_start_image(RIGHT, FALSE); + skip_to_newline(&t, &i); + } else if (can_see(&t, &i, HTML_IMAGE_INLINE)) { + write_start_image(INLINE, FALSE); + skip_to_newline(&t, &i); + } else if (can_see(&t, &i, HTML_IMAGE_CENTERED)) { + write_start_image(CENTERED, FALSE); + skip_to_newline(&t, &i); + } else { + write_upto_newline(&t, &i); + } + } while (t != 0); + } + if (close(stdoutfd) < 0) + sys_fatal("close"); + + // now we grab fd=1 so that the next pipe cannot use fd=1 + if (stdoutfd == 1) { + if (dup(2) != stdoutfd) { + sys_fatal("dup failed to use fd=1"); + } + } +} + +/* + * the image class remembers the position of all images in the postscript file + * and assigns names for each image. + */ + +struct imageItem { + imageItem *next; + int X1; + int Y1; + int X2; + int Y2; + char *imageName; + int resolution; + int maxx; + int pageNo; + + imageItem (int x1, int y1, int x2, int y2, int page, int res, int max_width, char *name); + ~imageItem (); +}; + +/* + * imageItem - constructor + */ + +imageItem::imageItem (int x1, int y1, int x2, int y2, int page, int res, int max_width, char *name) +{ + X1 = x1; + Y1 = y1; + X2 = x2; + Y2 = y2; + pageNo = page; + resolution = res; + maxx = max_width; + imageName = name; + next = 0; +} + +/* + * imageItem - deconstructor + */ + +imageItem::~imageItem () +{ +} + +/* + * imageList - class containing a list of imageItems. + */ + +class imageList { +private: + imageItem *head; + imageItem *tail; + int count; +public: + imageList(); + ~imageList(); + void add(int x1, int y1, int x2, int y2, int page, int res, int maxx, char *name); +}; + +/* + * imageList - constructor. + */ + +imageList::imageList () + : head(0), tail(0), count(0) +{ +} + +/* + * imageList - deconstructor. + */ + +imageList::~imageList () +{ + while (head != 0) { + imageItem *i = head; + head = head->next; + delete i; + } +} + +/* + * createAllPages - creates a set of images, one per page. + */ + +static void createAllPages (void) +{ + char buffer[4096]; + + sprintf(buffer, + "echo showpage | gs -q -dSAFER -sDEVICE=%s -r%d -sOutputFile=%s%%d %s - > /dev/null 2>&1 \n", + image_device, + image_res, + imagePageStem, + psFileName); +#if defined(DEBUGGING) + fwrite(buffer, sizeof(char), strlen(buffer), stderr); + fflush(stderr); +#endif + system(buffer); +} + +/* + * removeAllPages - removes all page images. + */ + +static void removeAllPages (void) +{ + char buffer[4096]; + +#if !defined(DEBUGGING) + sprintf(buffer, + "/bin/rm -f %s* \n", + imagePageStem); + system(buffer); +#endif +} + +/* + * abs - returns the absolute value. + */ + +int abs (int x) +{ + if (x < 0) { + return( -x ); + } else { + return( x ); + } +} + +/* + * min - returns the minimum of two numbers. + */ + +int min (int x, int y) +{ + if (x < y) { + return( x ); + } else { + return( y ); + } +} + +/* + * max - returns the maximum of two numbers. + */ + +int max (int x, int y) +{ + if (x > y) { + return( x ); + } else { + return( y ); + } +} + +/* + * createImage - generates a minimal png file from the set of page images. + */ + +static void createImage (imageItem *i) +{ + if (i->X1 != -1) { + char buffer[4096]; + int x1 = max(min(i->X1, i->X2)*image_res/POSTSCRIPTRES-1*IMAGE_BOARDER_PIXELS, 0); + int y1 = max((image_res*vertical_offset/72)+min(i->Y1, i->Y2)*image_res/POSTSCRIPTRES, 0); + int x2 = min(max(i->X1, i->X2)*image_res/POSTSCRIPTRES+1*IMAGE_BOARDER_PIXELS, i->maxx*image_res/POSTSCRIPTRES); + int y2 = (image_res*vertical_offset/72)+max(i->Y1, i->Y2)*image_res/POSTSCRIPTRES+2*IMAGE_BOARDER_PIXELS; + + sprintf(buffer, + "pnmcut %d %d %d %d < %s%d | pnmtopng %s > %s \n", + x1, y1, x2-x1, y2-y1, + imagePageStem, + i->pageNo, + TRANSPARENT, + i->imageName); +#if defined(DEBUGGING) + fprintf(stderr, buffer); +#endif + system(buffer); +#if defined(DEBUGGING) + } else { + fprintf(stderr, "ignoring image as x1 coord is -1\n"); + fflush(stderr); +#endif + } +} + +/* + * add - an image description to the imageList. + */ + +void imageList::add (int x1, int y1, int x2, int y2, int page, int res, int maxx, char *name) +{ + imageItem *i = new imageItem(x1, y1, x2, y2, page, res, maxx, name); + + if (head == 0) { + head = i; + tail = i; + } else { + tail->next = i; + tail = i; + } + createImage(i); +} + +static imageList listOfImages; // list of images defined by the region file. + +/* + * write_file_html - writes the buffer to stdout (troff). + * It writes out the file replacing template image names with + * actual image names. + */ + +void char_buffer::write_file_html (void) +{ + char_block *t =head; + char *name; + int i=0; + + if (t != 0) { + stop(); + do { + /* + * remember to check the shortest string last + */ + if (can_see(&t, &i, HTML_IMAGE_END)) { + write_end_image(TRUE); + skip_to_newline(&t, &i); + } else if (can_see(&t, &i, HTML_IMAGE_LEFT)) { + write_start_image(LEFT, TRUE); + skip_to_newline(&t, &i); + } else if (can_see(&t, &i, HTML_IMAGE_RIGHT)) { + write_start_image(RIGHT, TRUE); + skip_to_newline(&t, &i); + } else if (can_see(&t, &i, HTML_IMAGE_INLINE)) { + stop(); + write_start_image(INLINE, TRUE); + skip_to_newline(&t, &i); + } else if (can_see(&t, &i, HTML_IMAGE_CENTERED)) { + stop(); + write_start_image(CENTERED, TRUE); + skip_to_newline(&t, &i); + } else { + write_upto_newline(&t, &i); + } + } while (t != 0); + } + if (close(stdoutfd) < 0) + sys_fatal("close"); + + // now we grab fd=1 so that the next pipe cannot use fd=1 + if (stdoutfd == 1) { + if (dup(2) != stdoutfd) { + sys_fatal("dup failed to use fd=1"); + } + } +} + +/* + * generateImages - parses the region file and generates images + * from the postscript file. The region file + * contains the x1,y1 x2,y2 extents of each + * image. + */ + +static void generateImages (char *regionFileName) +{ + pushBackBuffer *f=new pushBackBuffer(regionFileName); + char ch; + + while (f->putPB(f->getPB()) != eof) { + if (f->isString("grohtml-info:page")) { + int page = f->readInt(); + int x1 = f->readInt(); + int y1 = f->readInt(); + int x2 = f->readInt(); + int y2 = f->readInt(); + int maxx = f->readInt(); + char *name = f->readString(); + int res = POSTSCRIPTRES; // --fixme-- prefer (f->readInt()) providing that troff can discover the value + listOfImages.add(x1, y1, x2, y2, page, res, maxx, name); + while ((f->putPB(f->getPB()) != '\n') && + (f->putPB(f->getPB()) != eof)) { + ch = f->getPB(); + } + if (f->putPB(f->getPB()) == '\n') { + ch = f->getPB(); + } + } else { + /* + * write any error messages out to the user + */ + fputc(f->getPB(), stderr); + } + } +} + +/* + * replaceFd - replace a file descriptor, was, with, willbe. + */ + +static void replaceFd (int was, int willbe) +{ + int dupres; + + if (was != willbe) { + if (close(was)<0) { + sys_fatal("close"); + } + dupres = dup(willbe); + if (dupres != was) { + sys_fatal("dup"); + fprintf(stderr, "trying to replace fd=%d with %d dup used %d\n", was, willbe, dupres); + if (willbe == 1) { + fprintf(stderr, "likely that stdout should be opened before %d\n", was); + } + exit(1); + } + if (close(willbe) < 0) { + sys_fatal("close"); + } + } +} + +/* + * waitForChild - waits for child, pid, to exit. + */ + +static void waitForChild (PID_T pid) +{ + PID_T waitpd; + int status; + + waitpd = wait(&status); + if (waitpd != pid) + sys_fatal("wait"); +} + +/* + * alterDeviceTo - if toImage is set then the arg list is altered to include + * IMAGE_DEVICE and we invoke groff rather than troff. + * else + * set -Thtml and troff + */ + +static void alterDeviceTo (int argc, char *argv[], int toImage) +{ + int i=0; + + if (toImage) { + while (i < argc) { + if (strcmp(argv[i], "-Thtml") == 0) { + argv[i] = IMAGE_DEVICE; + } + i++; + } + argv[troff_arg] = "groff"; /* rather than troff */ + } else { + while (i < argc) { + if (strcmp(argv[i], IMAGE_DEVICE) == 0) { + argv[i] = "-Thtml"; + } + i++; + } + argv[troff_arg] = "troff"; /* use troff */ + } +} + +/* + * do_html - sets the troff number htmlflip and + * writes out the buffer to troff -Thtml + */ + +int char_buffer::do_html(int argc, char *argv[]) +{ + int pdes[2]; + PID_T pid; + + if (pipe(pdes) < 0) + sys_fatal("pipe"); + + alterDeviceTo(argc, argv, 0); + argv += troff_arg; // skip all arguments up to troff/groff + argc -= troff_arg; + +#if defined(DEBUG_HTML) + write_file_html(); + writeString("--------------- troff --------------------------\n"); + write_file_troff(); +#else + pid = fork(); + if (pid < 0) + sys_fatal("fork"); + + if (pid == 0) { + // child + replaceFd(0, pdes[0]); + // close end we are not using + if (close(pdes[1])<0) + sys_fatal("close"); + replaceFd(1, copyofstdoutfd); // and restore stdout + + execvp(argv[0], argv); + error("couldn't exec %1: %2", argv[0], strerror(errno), (char *)0); + fflush(stderr); /* just in case error() doesn't */ + exit(1); + } else { + // parent + +#if defined(DEBUGGING) + /* + * slight security risk so only enabled if compiled with defined(DEBUGGING) + */ + if (debug) { + replaceFd(1, creat(htmlFileName, S_IWUSR|S_IRUSR)); + write_file_html(); + } +#endif + replaceFd(1, pdes[1]); + // close end we are not using + if (close(pdes[0])<0) + sys_fatal("close"); + + write_file_html(); + waitForChild(pid); + } +#endif + return( 0 ); +} + +/* + * addps4html - appends -rps4html=1 onto the command list for troff. + */ + +char **addps4html (int argc, char *argv[]) +{ + char **new_argv = (char **)malloc((argc+2)*sizeof(char *)); + int i=0; + + while (i +#include +#include +#include +#include +#include +#include +#include "lib.h" +#include "errarg.h" +#include "error.h" +#include "stringclass.h" +#include "posix.h" + +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif + +#include "pushbackbuffer.h" +#include "pre-html.h" + +#if !defined(TRUE) +# define TRUE (1==1) +#endif + +#if !defined(FALSE) +# define FALSE (1==0) +#endif + +# define ERROR(X) (fprintf(stderr, "%s:%d error %s\n", __FILE__, __LINE__, X) && \ + (fflush(stderr)) && localexit(1)) + + +#define MAXPUSHBACKSTACK 4096 /* maximum number of character that can be pushed back */ + + +/* + * constructor for pushBackBuffer + */ + +pushBackBuffer::pushBackBuffer (char *filename) +{ + charStack = (char *)malloc(MAXPUSHBACKSTACK); + if (charStack == 0) { + sys_fatal("malloc"); + } + stackPtr = 0; /* index to push back stack */ + debug = 0; + verbose = 0; + eofFound = FALSE; + lineNo = 1; + if (strcmp(filename, "") != 0) { + stdIn = dup(0); + close(0); + if (open(filename, O_RDONLY) != 0) { + sys_fatal("when trying to open file"); + } else { + fileName = filename; + } + } +} + +pushBackBuffer::~pushBackBuffer () +{ + int old; + + if (charStack != 0) { + free(charStack); + } + close(0); + /* restore stdin in file descriptor 0 */ + old = dup(stdIn); + close(stdIn); +} + +/* + * localexit - wraps exit with a return code to aid the ERROR macro. + */ + +int localexit (int i) +{ + exit(i); + return( 1 ); +} + +/* + * getPB - returns a character, possibly a pushed back character. + */ + +char pushBackBuffer::getPB (void) +{ + if (stackPtr>0) { + stackPtr--; + return( charStack[stackPtr] ); + } else { + char ch; + + if (read(0, &ch, 1) == 1) { + if (verbose) { + printf("%c", ch); + } + if (ch == '\n') { + lineNo++; + } + return( ch ); + } else { + eofFound = TRUE; + return( eof ); + } + } +} + +/* + * putPB - pushes a character onto the push back stack. + * The same character is returned. + */ + +char pushBackBuffer::putPB (char ch) +{ + if (stackPtr=0) { + if (putPB(s[i]) != s[i]) { + ERROR("assert failed"); + } + i--; + } + } + return( FALSE ); +} + +/* + * isDigit - returns TRUE if the character, ch, is a digit. + */ + +static int isDigit (char ch) +{ + return( ((ch>='0') && (ch<='9')) ); +} + +/* + * isHexDigit - returns TRUE if the character, ch, is a hex digit. + */ + +static int isHexDigit (char ch) +{ + return( (isDigit(ch)) || ((ch>='a') && (ch<='f')) ); +} + +/* + * readInt - returns an integer from the input stream. + */ + +int pushBackBuffer::readInt (void) +{ + int c =0; + int i =0; + int s =1; + char ch=getPB(); + + while (isWhite(ch)) { + ch=getPB(); + } + // now read integer + + if (ch == '-') { + s = -1; + ch = getPB(); + } + while (isDigit(ch)) { + i *= 10; + if ((ch>='0') && (ch<='9')) { + i += (int)(ch-'0'); + } + ch = getPB(); + c++; + } + if (ch != putPB(ch)) { + ERROR("assert failed"); + } + return( i*s ); +} + +/* + * convertToFloat - converts integers, a and b into a.b + */ + +static float convertToFloat (int a, int b) +{ + int c=10; + float f; + + while (b>c) { + c *= 10; + } + f = ((float)a) + (((float)b)/((float)c)); + return( f ); +} + +/* + * readNumber - returns a float representing the word just read. + */ + +float pushBackBuffer::readNumber (void) +{ + int integer; + int fraction; + char ch; + float f; + + integer = readInt(); + if (putPB(getPB()) == '.') { + ch = getPB(); + fraction = readInt(); + f = convertToFloat(integer, fraction); + return( f ); + } else { + return( (float)integer ); + } +} + +/* + * readString - reads a string terminated by white space + * and returns a malloced area of memory containing + * a copy of the characters. + */ + +char *pushBackBuffer::readString (void) +{ + char buffer[MAXPUSHBACKSTACK]; + char *string = 0; + int i=0; + char ch=getPB(); + + while (isWhite(ch)) { + ch=getPB(); + } + while ((i < MAXPUSHBACKSTACK) && (! isWhite(ch)) && (! eofFound)) { + buffer[i] = ch; + i++; + ch = getPB(); + } + if (i < MAXPUSHBACKSTACK) { + buffer[i] = (char)0; + string = (char *)malloc(strlen(buffer)+1); + strcpy(string, buffer); + } + return( string ); +} diff --git a/src/preproc/html/pushbackbuffer.h b/src/preproc/html/pushbackbuffer.h new file mode 100755 index 00000000..93cb3f1a --- /dev/null +++ b/src/preproc/html/pushbackbuffer.h @@ -0,0 +1,54 @@ +// -*- C -*- +/* Copyright (C) 2000, 2001 Free Software Foundation, Inc. + Written by Gaius Mulley (gaius@glam.ac.uk). + +This file is part of groff. + +groff is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +groff is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with groff; see the file COPYING. If not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + + +#define eof (char)-1 + + +/* + * defines the class and methods implemented within pushbackbuffer.cc + */ + +class pushBackBuffer +{ + private: + char *charStack; + int stackPtr; /* index to push back stack */ + int debug; + int verbose; + int eofFound; + char *fileName; + int lineNo; + int stdIn; + + public: + pushBackBuffer (char *); + ~ pushBackBuffer (); + char getPB (void); + char putPB (char ch); + void skipUntilToken (void); + void skipToNewline (void); + float readNumber (void); + int readInt (void); + char *readString (void); + int isString (char *string); +}; + + -- cgit v1.2.1