2
/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4
* Gaius Mulley (gaius@glam.ac.uk) wrote output.cc
5
* but it owes a huge amount of ideas and raw code from
6
* James Clark (jjc@jclark.com) grops/ps.cc.
10
* provide the simple low level output routines needed by html.cc
14
This file is part of groff.
16
groff is free software; you can redistribute it and/or modify it under
17
the terms of the GNU General Public License as published by the Free
18
Software Foundation; either version 2, or (at your option) any later
21
groff is distributed in the hope that it will be useful, but WITHOUT ANY
22
WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26
You should have received a copy of the GNU General Public License along
27
with groff; see the file COPYING. If not, write to the Free Software
28
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31
#include "stringclass.h"
49
* word - initialise a word and set next to NULL
52
word::word (const char *w, int n)
55
s = (char *)malloc(n+1);
61
* destroy word and the string copy.
70
* word_list - create an empty word list.
73
word_list::word_list ()
74
: length(0), head(0), tail(0)
79
* flush - flush a word list to a FILE, f, and return the
80
* length of the buffered string.
83
int word_list::flush (FILE *f)
97
#if defined(DEBUGGING)
98
fflush(f); // just for testing
104
* add_word - adds a word to the outstanding word list.
107
void word_list::add_word (const char *s, int n)
110
head = new word(s, n);
113
tail->next = new word(s, n);
120
* get_length - returns the number of characters buffered
123
int word_list::get_length (void)
129
* the classes and methods for simple_output manipulation
132
simple_output::simple_output(FILE *f, int n)
133
: fp(f), max_line_length(n), col(0), fixed_point(0), newlines(0)
137
simple_output &simple_output::set_file(FILE *f)
145
simple_output &simple_output::copy_file(FILE *infp)
148
while ((c = getc(infp)) != EOF)
153
simple_output &simple_output::end_line()
163
simple_output &simple_output::special(const char *s)
168
simple_output &simple_output::simple_comment(const char *s)
180
simple_output &simple_output::begin_comment(const char *s)
188
last_word.add_word(s, strlen(s));
192
simple_output &simple_output::end_comment()
196
put_string("-->").nl();
201
* check_newline - checks to see whether we are able to issue
202
* a newline and that one is needed.
205
simple_output &simple_output::check_newline(int n)
207
if ((col + n + last_word.get_length() + 1 > max_line_length) && (newlines)) {
209
col = last_word.flush(fp);
215
* space_or_newline - will emit a newline or a space later on
216
* depending upon the current column.
219
simple_output &simple_output::space_or_newline (void)
221
#if defined(DEBUGGING)
222
fflush(fp); // just for testing
224
if ((col + last_word.get_length() + 1 > max_line_length) && (newlines)) {
226
if (last_word.get_length() > 0) {
227
col = last_word.flush(fp);
232
if (last_word.get_length() != 0) {
237
col += last_word.flush(fp);
244
* nl - writes a newline providing that we
245
* are not in the first column.
248
simple_output &simple_output::nl (void)
251
col += last_word.flush(fp);
259
simple_output &simple_output::set_fixed_point(int n)
261
assert(n >= 0 && n <= 10);
266
simple_output &simple_output::put_raw_char(char c)
268
col += last_word.flush(fp);
274
simple_output &simple_output::put_string(const char *s, int n)
276
last_word.add_word(s, n);
280
simple_output &simple_output::put_string(const char *s)
282
last_word.add_word(s, strlen(s));
286
simple_output &simple_output::put_number(int n)
288
char buf[1 + INT_DIGITS + 1];
289
sprintf(buf, "%d", n);
294
simple_output &simple_output::put_float(double d)
298
sprintf(buf, "%.4f", d);
303
simple_output &simple_output::enable_newlines (int auto_newlines)
306
newlines = auto_newlines;
312
* flush_last_word - flushes the last word and adjusts the
313
* col position. It will insert a newline
314
* before the last word if allowed and if
318
void simple_output::flush_last_word (void)
320
int len=last_word.get_length();
324
if (col + len + 1 > max_line_length) {
331
len += last_word.flush(fp);
335
col += last_word.flush(fp);