From 7f17125bab7986ed8f302cfc7fab94add1e81230 Mon Sep 17 00:00:00 2001 From: Steffen Nurpmeso Date: Tue, 7 Oct 2014 15:17:58 +0200 Subject: [PATCH] Adapt src/troff (src/roff/troff) --- src/roff/troff/troff.man => man/src-troff.1.in | 188 +++++---------- src/roff/troff/TODO | 126 ---------- src/roff/troff/reg.h | 76 ------ src/{roff => }/troff/charinfo.h | 57 +++-- src/{roff => }/troff/column.cpp | 125 ++++++---- src/{roff => }/troff/dictionary.cpp | 55 +++-- src/{roff => }/troff/dictionary.h | 80 ++++--- src/{roff => }/troff/div.cpp | 145 +++++++----- src/{roff => }/troff/div.h | 77 ++++-- src/{roff => }/troff/env.cpp | 182 ++++++++------ src/{roff => }/troff/env.h | 144 ++++++----- src/{roff => }/troff/hvunits.h | 91 +++---- src/{roff => }/troff/input.cpp | 316 ++++++++++++++----------- src/{roff => }/troff/input.h | 55 +++-- src/{roff => }/troff/mtsm.cpp | 54 +++-- src/{roff => }/troff/mtsm.h | 87 ++++--- src/{roff => }/troff/node.cpp | 220 ++++++++++------- src/{roff => }/troff/node.h | 203 +++++++++++----- src/{roff => }/troff/number.cpp | 53 +++-- src/{roff => }/troff/reg.cpp | 63 ++--- src/troff/reg.h | 95 ++++++++ src/{roff => }/troff/request.h | 71 ++++-- src/{roff => }/troff/token.h | 70 +++--- src/troff/troff-config.h | 14 ++ src/{roff => }/troff/troff.h | 70 +++--- 25 files changed, 1502 insertions(+), 1215 deletions(-) rename src/roff/troff/troff.man => man/src-troff.1.in (75%) delete mode 100644 src/roff/troff/TODO delete mode 100644 src/roff/troff/reg.h rename src/{roff => }/troff/charinfo.h (78%) rename src/{roff => }/troff/column.cpp (89%) rename src/{roff => }/troff/dictionary.cpp (78%) rename src/{roff => }/troff/dictionary.h (52%) rename src/{roff => }/troff/div.cpp (94%) rename src/{roff => }/troff/div.h (78%) rename src/{roff => }/troff/env.cpp (98%) rename src/{roff => }/troff/env.h (90%) rename src/{roff => }/troff/hvunits.h (85%) rename src/{roff => }/troff/input.cpp (98%) rename src/{roff => }/troff/input.h (69%) rename src/{roff => }/troff/mtsm.cpp (92%) rename src/{roff => }/troff/mtsm.h (68%) rename src/{roff => }/troff/node.cpp (98%) rename src/{roff => }/troff/node.h (87%) rename src/{roff => }/troff/number.cpp (92%) rename src/{roff => }/troff/reg.cpp (87%) create mode 100644 src/troff/reg.h rename src/{roff => }/troff/request.h (57%) rename src/{roff => }/troff/token.h (80%) create mode 100644 src/troff/troff-config.h rename src/{roff => }/troff/troff.h (58%) diff --git a/src/roff/troff/troff.man b/man/src-troff.1.in similarity index 75% rename from src/roff/troff/troff.man rename to man/src-troff.1.in index 8ef8ceeb..9ee8935d 100644 --- a/src/roff/troff/troff.man +++ b/man/src-troff.1.in @@ -1,14 +1,12 @@ -'\" t +'\" t -- preprocess: tbl(1) .ig -troff.man +@ @L_TROFF@.1 -This file is part of groff, the GNU roff type-setting system. +Copyright (c) 2014 Steffen (Daode) Nurpmeso . -Copyright (C) 1989, 2000, 2001, 2002, 2003, 2007, 2008 +Copyright (C) 1989, 2000 - 2003, 2007, 2008 Free Software Foundation, Inc. - written by James Clark - modified by Werner Lemberg Bernd Warken @@ -18,24 +16,21 @@ any later version published by the Free Software Foundation; with the Invariant Sections being this .ig-section and AUTHOR, with no Front-Cover Texts, and with no Back-Cover Texts. -A copy of the Free Documentation License is included as a file called -FDL in the main directory of the groff source package. +You should have received a copy of the Free Documentation License +as part of the file COPYING; also located in the main directory of the +source package of this program. .. . -.\" -------------------------------------------------------------------- -.\" Title -.\" -------------------------------------------------------------------- +.TH @U_TROFF@ @MAN1EXT@ "@MDATE@" "@T_ROFF@ v@VERSION@" . -.TH @G@TROFF @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@" +.\" .SH NAME -@g@troff \- the troff processor of the groff text formatting system -. +@L_TROFF@ \- the troff processor of the @T_ROFF@ text formatting system . -.\" -------------------------------------------------------------------- +.\" .SH SYNOPSIS -.\" -------------------------------------------------------------------- . -.SY @g@troff +.SY @L_TROFF@ .OP \-abcivzCERU .OP \-d cs .OP \-f fam @@ -52,27 +47,23 @@ FDL in the main directory of the groff source package. .RI [ file\~ .\|.\|.] .YS . -. -.\" -------------------------------------------------------------------- +.\" .SH DESCRIPTION -.\" -------------------------------------------------------------------- -. -This manual page describes the GNU version of -.BR troff . -It is part of the groff document formatting system. . -It is functionally compatible with UNIX troff, but has many extensions, -see -.BR \%groff_diff (@MAN7EXT@). -Usually it should be invoked using the -.BR groff (@MAN1EXT@) +@T_TROFF@ is the main workhorse of the @T_ROFF@ text processing system +and translates roff text input into an intermediate output language that +can be and usually is furtherly used by @T_ROFF@ output devices. +It is functionally compatible with UNIX troff, but has many +extensions, see +.BR \%@L_ROFF@_diff (@MAN7EXT@). +Usually it is invoked by using the +.BR @L_ROFF@ (@MAN1EXT@) command which will also run preprocessors and postprocessors in the appropriate order and with the appropriate options. . -. -.\" -------------------------------------------------------------------- +.\" .SH OPTIONS -.\" -------------------------------------------------------------------- +. It is possible to have whitespace between a command line option and its parameter. . @@ -85,14 +76,12 @@ approximation of the typeset output. .TP .B \-b Print a backtrace with each warning or error message. -. This backtrace should help track down the cause of the error. -. The line numbers given in the backtrace may not always be correct, for -.BR @g@troff 's +.BR @L_TROFF@ 's idea of line numbers gets confused by .B as -or +or .B am requests. . @@ -120,7 +109,7 @@ must be a one letter name. .TP .B \-E Inhibit all error messages of -.BR @g@troff . +.BR @L_TROFF@ . Note that this doesn't affect messages output to standard error by macro packages using the .B tm @@ -175,11 +164,10 @@ Read in the file If it isn't found, try .BI tmac. name instead. -. It will be first searched for in directories given with the .B \-M command line option, then in directories given in the -.B GROFF_TMAC_PATH +.B @U_ROFF@_TMAC_PATH environment variable, then in the current directory (only if in unsafe mode), the home directory, @SYSTEMMACRODIR@, @LOCALMACRODIR@, and @MACRODIR@. @@ -189,7 +177,6 @@ mode), the home directory, @SYSTEMMACRODIR@, @LOCALMACRODIR@, and Search directory (or directory path) .I dir for macro files. -. This is scanned before all other macro directories. . .TP @@ -216,7 +203,7 @@ means print every page up to .IB n \- means print every page from .IR n . -.B @g@troff +.B @L_TROFF@ will exit after printing the last page in the list. . .TP @@ -248,13 +235,12 @@ Prepare output for device rather than the default .BR @DEVICE@ ; see -.BR groff (@MAN1EXT@) +.BR @L_ROFF@ (@MAN1EXT@) for a more detailed description. . .TP .B \-U Unsafe mode. -. This will enable the following requests: .BR open , .BR opena , @@ -264,7 +250,6 @@ and .BR pi . For security reasons, these potentially dangerous requests are disabled otherwise. -. It will also add the current directory to the macro search path. . .TP @@ -278,7 +263,6 @@ Enable warning Available warnings are described in the section .I WARNINGS below. -. For example, to enable all warnings, use .B \-w .BR all . @@ -298,15 +282,12 @@ options are allowed. .B \-z Suppress formatted output. . -. -.\" -------------------------------------------------------------------- +.\" .SH WARNINGS -.\" -------------------------------------------------------------------- . The warnings that can be given by -.B @g@troff +.B @L_TROFF@ are divided into the following categories. -. The name associated with each warning is used by the .B \-w and @@ -344,13 +325,11 @@ _ .BR break "\t4" In fill mode, lines which could not be broken so that their length was less than the line length. -. This is enabled by default. . .TP .BR char "\t1" Non-existent characters. -. This is enabled by default. . .TP @@ -380,14 +359,12 @@ request. .TP .BR escape "\t32768" Unrecognized escape sequences. -. When an unrecognized escape sequence is encountered, the escape character is ignored. . .TP .BR font "\t131072" Non-existent fonts. -. This is enabled by default. . .TP @@ -395,7 +372,6 @@ This is enabled by default. Invalid escapes in text ignored with the .B ig request. -. These are conditions that are errors when they do not occur in ignored text. . @@ -406,10 +382,8 @@ Invalid input characters. .TP .BR mac "\t512" Use of undefined strings, macros and diversions. -. When an undefined string, macro or diversion is used, that string is automatically defined as empty. -. So, in most cases, at most one warning will be given for each name. . .TP @@ -419,7 +393,6 @@ Requests that are missing non-optional arguments. .TP .BR number "\t2" Invalid numeric expressions. -. This is enabled by default. . .TP @@ -429,10 +402,8 @@ Out of range arguments. .TP .BR reg "\t1024" Use of undefined number registers. -. When an undefined number register is used, that register is automatically defined to have a value of\~0. -. So, in most cases, at most one warning will be given for use of a particular name. . @@ -449,17 +420,12 @@ Meaningless scaling indicators. .TP .BR space "\t65536" Missing space between a request or macro and its argument. -. This warning will be given when an undefined name longer than two characters is encountered, and the first two characters of the name make a defined name. -. The request or macro will not be invoked. -. When this warning is given, no macro is automatically defined. -. This is enabled by default. -. This warning will never occur in compatibility mode. . .TP @@ -489,17 +455,15 @@ traditional macro packages. .B w All warnings. . -. -.\" -------------------------------------------------------------------- +.\" .SH ENVIRONMENT -.\" -------------------------------------------------------------------- . .TP .SM -.B GROFF_TMAC_PATH +.B @U_ROFF@_TMAC_PATH A colon separated list of directories in which to search for macro files. -.B @g@troff +.B @L_TROFF@ will scan directories given in the .B \-M option before these, and in standard directories (current directory if @@ -511,28 +475,25 @@ after these. . .TP .SM -.B GROFF_TYPESETTER +.B @U_ROFF@_TYPESETTER Default device. . .TP .SM -.B GROFF_FONT_PATH +.B @U_ROFF@_FONT_PATH A colon separated list of directories in which to search for the .BI dev name directory. -.B @g@troff +.B @L_TROFF@ will scan directories given in the .B \-F option before these, and in standard directories .RB ( @LOCALFONTDIR@ , -.BR @FONTDIR@ , -.BR @LEGACYFONTDIR@ ) +.BR @FONTDIR@ ) after these. . -. -.\" -------------------------------------------------------------------- +.\" .SH FILES -.\" -------------------------------------------------------------------- . .TP .B @MACRODIR@/troffrc @@ -559,6 +520,7 @@ Font file for font .I F of device .IR name . +. .P Note that .B troffrc @@ -568,20 +530,17 @@ are neither searched in the current nor in the home directory by default for security reasons (even if the .B \-U option is given). -. Use the .B \-M command line option or the -.B GROFF_TMAC_PATH +.B @U_ROFF@_TMAC_PATH environment variable to add these directories to the search path if necessary. . -. -.\" -------------------------------------------------------------------- +.\" .SH AUTHOR -.\" -------------------------------------------------------------------- . -Copyright (C) 1989, 2001, 2002, 2003, 2007, 2008 +Copyright (C) 1989, 2001 - 2003, 2007, 2008 Free Software Foundation, Inc. . .P @@ -602,68 +561,31 @@ and Bernd Warken .ME . . -.P -This document is part of -.IR groff , -the GNU roff distribution. -. -. -.\" -------------------------------------------------------------------- +.\" .SH "SEE ALSO" -.\" -------------------------------------------------------------------- . .TP -.BR groff (@MAN1EXT@) +.BR @L_ROFF@ (@MAN1EXT@) The main program of the -.I groff +.I @T_ROFF@ system, a wrapper around -.IR @g@troff . +.IR @L_TROFF@ . . .TP -.BR groff (@MAN7EXT@) -A description of the -.I groff -language, including a short but complete reference of all predefined -requests, registers, and escapes of plain -.IR groff . -From the command line, this is called by -.RS -.IP -.B man 7 groff -.RE +.BR @L_ROFF@ (@MAN7EXT@) +A description of the roff language, including a short but complete +reference of all predefined requests, registers, and escapes. . .TP -.BR \%groff_diff (@MAN7EXT@) +.BR \%@L_ROFF@_diff (@MAN7EXT@) The differences of the -.I groff -language and the +.I @T_ROFF@ +language, GNU troff and the .I classical troff language. . -Currently, this is the most actual document of the -.I groff -system. -. .TP .BR roff (@MAN7EXT@) -An overview over -.I groff -and other -.I roff -systems, including pointers to further related documentation. +An overview over roff. . -.P -The -.I groff info -.IR file , -cf.\& -.BR info (@MAN1EXT@), -presents all groff documentation within a single document. -. -.\" -------------------------------------------------------------------- -.\" Emacs variables -.\" -------------------------------------------------------------------- -. -.\" Local Variables: -.\" mode: nroff -.\" End: +.\" s-it2-mode diff --git a/src/roff/troff/TODO b/src/roff/troff/TODO deleted file mode 100644 index bc4c8293..00000000 --- a/src/roff/troff/TODO +++ /dev/null @@ -1,126 +0,0 @@ -A line prefix request to make e.g. French quotation possible: - - He said: >> blablablabla - >> blablabla blabla bla - >> blabla blabla bla bla - >> bla bla bla blablabla - >> blabla. << - -Give a more helpful error message when the indent is set to a value -greater than the line-length. - -Tracing. This is a pain to implement because requests are responsible -for reading their own arguments. - -Possibly implement -s option (stop every N pages). This functionality -would be more appropriate in a postprocessor. - -Line breaking should be smarter. In particular, it should be possible -to shrink spaces. Also avoid having a line that's been shrunk a lot -next to a line that's been stretched a lot. The difficulty is to -design a mechanism that allows the user complete control over the -decision of where to break the line. - -Provide a mechanism to control the shape of the rag in non-justified -text. - -Add a discretionary break escape sequence. \='...'...'...' like TeX. - -Think about kerning between characters and spaces. (Need to implement -get_breakpoints and split methods for kern_pair_node class.) - -In troff, if .L > 1 when a diversion is reread in no-fill mode, then -extra line-spacing is added on. Groff at the moment treats line-spacing -like vertical spacing and doesn't do this. - -Suppose \(ch comes from a special font S, and that the current font is -R. Suppose that R contains a hyphen character and that S does not. -Suppose that the current font is R. Suppose that \(ch is in a word -and has a non-zero hyphen-type. Then we ought to be able to hyphenate, -but we won't be able to because we will look for the hyphen only in -font S and not in font R. - -Perhaps the current input level should be accessible in a number register. - -Should \w deal with a newline like \X? - -Have another look at uses of token::delimiter. Perhaps we need to -distinguish the case where we want to see if a token could start a -number, from the case where we want to see if it could occur somewhere -in a number expression. - -Provide a facility like copy thru in pic. - -Fancier implementation of font families which doesn't group fonts into -families purely on the basis of their names. - -In the DESC file make the number of fonts optional if they are all on -one line. - -Number register to give the diversion level. - -Time various alternative implementations of scale (both in font.c and -number.c). On a sparc it's faster to always do it in floating point. - -Devise a more compact representation for the hyphenation patterns trie. - -Have a per-environment parameter to increase letter-spacing. - -Request to set character height. - -Request to set character slant. - -Provide some way to upcase or downcase strings. - -Support non-uniformly scalable fonts. Perhaps associate a suffix with -a particular range of sizes. eg - sizesuffix .display 14-512 -Then is you ask for R at pointsize 16, groff will first look for -R.display and then R. Probably necessary to be able to specify a -separate unitwidth for each sizesuffix (eg. for X). - -Make it possible to suppress hyphenation on a word-by-word basis. -(Perhaps store hyphenation flags in tfont.) - -Possibly allow multiple simultaneous input line traps. - -Unpaddable, breakable space escape sequence. - -Support hanging punctuation. - -In justified text, if the last line of a paragraph is only a little -bit short it might be desirable to justify the line. Allow the user -control over this. - -The pm request could print where the macro was defined. Also could -optionally print the contents of a macro. - -Provide some way to round numbers to multiples of the current -horizontal or vertical resolution. - -Better string-processing support (search). - -Generalized ligatures. - -Request to remove an environment. (Maintain a count of the references -to the environment from the environment table, environment dictionary -or environment stack.) - -Perhaps in the nr request a leading `-' should only be recognized as a -decrement when it's at the same input level as the request. - -Don't ever change a charinfo. Create new variants instead and chain -them together. - -Unix troff appears to read the first character of a request name in -copy mode. Should we do the same? - -Number register giving name of end macro. - -More thorough range checking. - -Provide syntax for octal and hexadecimal numeric constants. Perhaps -o#100 and x#7f as per Scheme. Or perhaps PostScript 16#7f. Ambiguity -between whether `c' is treated as digit or scaling indicator. - -Local variables. diff --git a/src/roff/troff/reg.h b/src/roff/troff/reg.h deleted file mode 100644 index bc2c3f2d..00000000 --- a/src/roff/troff/reg.h +++ /dev/null @@ -1,76 +0,0 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - - -class reg : public object { -public: - virtual const char *get_string() = 0; - virtual int get_value(units *); - virtual void increment(); - virtual void decrement(); - virtual void set_increment(units); - virtual void alter_format(char f, int w = 0); - virtual const char *get_format(); - virtual void set_value(units); -}; - -class constant_int_reg : public reg { - int *p; -public: - constant_int_reg(int *); - const char *get_string(); -}; - -class general_reg : public reg { - char format; - int width; - int inc; -public: - general_reg(); - const char *get_string(); - void increment(); - void decrement(); - void alter_format(char f, int w = 0); - void set_increment(units); - const char *get_format(); - void add_value(units); - - void set_value(units) = 0; - int get_value(units *) = 0; -}; - -class variable_reg : public general_reg { - units *ptr; -public: - variable_reg(int *); - void set_value(units); - int get_value(units *); -}; - -extern object_dictionary number_reg_dictionary; -extern void set_number_reg(symbol nm, units n); -extern void check_output_limits(int x, int y); -extern void reset_output_registers(); - -reg *lookup_number_reg(symbol); -#if 0 -void inline_define_reg(); -#endif diff --git a/src/roff/troff/charinfo.h b/src/troff/charinfo.h similarity index 78% rename from src/roff/troff/charinfo.h rename to src/troff/charinfo.h index deee2728..d0540c46 100644 --- a/src/roff/troff/charinfo.h +++ b/src/troff/charinfo.h @@ -1,28 +1,37 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2006 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2001, 2002, 2006 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _CHARINFO_H +#define _CHARINFO_H + +#include "config.h" +#include "troff-config.h" class macro; -class charinfo : glyph { +class charinfo +: glyph +{ static int next_index; + charinfo *translation; macro *mac; unsigned char special_translation; @@ -36,6 +45,7 @@ class charinfo : glyph { char translate_input; // non-zero means that asciify_code is // active for .asciify (set by .trin) char_mode mode; + public: enum { // Values for the flags bitmask. See groff // manual, description of the `.cflags' request. @@ -54,7 +64,9 @@ public: TRANSLATE_STRETCHABLE_SPACE, TRANSLATE_HYPHEN_INDICATOR }; + symbol nm; + charinfo(symbol); glyph *as_glyph(); int ends_sentence(); @@ -217,3 +229,6 @@ inline symbol *charinfo::get_symbol() { return( &nm ); } + +#endif // _CHARINFO_H +// s-it2-mode diff --git a/src/roff/troff/column.cpp b/src/troff/column.cpp similarity index 89% rename from src/roff/troff/column.cpp rename to src/troff/column.cpp index 060b088d..18a09277 100644 --- a/src/roff/troff/column.cpp +++ b/src/troff/column.cpp @@ -1,36 +1,40 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ #ifdef COLUMN -#include "troff.h" +#include "config.h" +#include "troff-config.h" + +#include "stringclass.h" #include "symbol.h" + +#include "div.h" #include "dictionary.h" -#include "hvunits.h" #include "env.h" -#include "request.h" +#include "hvunits.h" #include "node.h" -#include "token.h" -#include "div.h" #include "reg.h" -#include "stringclass.h" +#include "request.h" +#include "token.h" +#include "troff.h" void output_file::vjustify(vunits, symbol) { @@ -40,12 +44,14 @@ void output_file::vjustify(vunits, symbol) struct justification_spec; struct output_line; -class column : public output_file { -private: +class column +: public output_file +{ output_file *out; vunits bottom; output_line *col; output_line **tail; + void add_output_line(output_line *); void begin_page(int pageno, vunits page_length); void flush(); @@ -55,6 +61,7 @@ private: void copy_file(hunits, vunits, const char *); int is_printing(); void check_bottom(); + public: column(); ~column(); @@ -73,8 +80,13 @@ column *the_column = 0; struct transparent_output_line; struct vjustify_output_line; -class output_line { +class output_line +{ + friend class column; + friend class justification_spec; + output_line *next; + public: output_line(); virtual ~output_line(); @@ -85,22 +97,26 @@ public: virtual vunits height(); virtual void reset(); virtual vunits extra_space(); // post line - friend class column; - friend class justification_spec; }; -class position_output_line : public output_line { +class position_output_line +: public output_line +{ vunits dist; + public: position_output_line(vunits); vunits distance(); }; - -class node_output_line : public position_output_line { + +class node_output_line +: public position_output_line +{ node *nd; hunits page_offset; vunits before; vunits after; + public: node_output_line(vunits, node *, hunits, vunits, vunits); ~node_output_line(); @@ -109,9 +125,12 @@ public: vunits extra_space(); }; -class vjustify_output_line : public position_output_line { +class vjustify_output_line +: public position_output_line +{ vunits current; symbol typ; + public: vjustify_output_line(vunits dist, symbol); vunits height(); @@ -126,16 +145,22 @@ inline symbol vjustify_output_line::type() return typ; } -class copy_file_output_line : public position_output_line { +class copy_file_output_line +: public position_output_line +{ symbol filename; hunits hpos; + public: copy_file_output_line(vunits, const char *, hunits); void output(output_file *, vunits); }; -class transparent_output_line : public output_line { +class transparent_output_line +: public output_line +{ string buf; + public: transparent_output_line(); void output(output_file *, vunits); @@ -310,7 +335,7 @@ void column::begin_page(int pageno, vunits page_length) } else out->begin_page(pageno, page_length); - + } void column::flush() @@ -442,12 +467,14 @@ vunits column::get_last_extra_space() return p->extra_space(); } -class justification_spec { +class justification_spec +{ vunits height; symbol *type; vunits *amount; int n; int maxn; + public: justification_spec(vunits); ~justification_spec(); @@ -540,7 +567,7 @@ void justification_spec::justify(output_line *col, vunits *bottomp) const assert(total == V0); *bottomp = height - gap; } - + void column::justify(const justification_spec &js) { check_bottom(); @@ -617,7 +644,9 @@ void column_reset() skip_line(); } -class column_bottom_reg : public reg { +class column_bottom_reg +: public reg +{ public: const char *get_string(); }; @@ -627,7 +656,9 @@ const char *column_bottom_reg::get_string() return i_to_a(the_column->get_bottom().to_units()); } -class column_extra_space_reg : public reg { +class column_extra_space_reg +: public reg +{ public: const char *get_string(); }; @@ -637,7 +668,9 @@ const char *column_extra_space_reg::get_string() return i_to_a(the_column->get_last_extra_space().to_units()); } -class column_active_reg : public reg { +class column_active_reg +: public reg +{ public: const char *get_string(); }; @@ -649,8 +682,11 @@ const char *column_active_reg::get_string() static int no_vjustify_mode = 0; -class vjustify_node : public node { +class vjustify_node +: public node +{ symbol typ; + public: vjustify_node(symbol); int reread(int *); @@ -730,3 +766,4 @@ void init_column_requests() } #endif /* COLUMN */ +// s-it2-mode diff --git a/src/roff/troff/dictionary.cpp b/src/troff/dictionary.cpp similarity index 78% rename from src/roff/troff/dictionary.cpp rename to src/troff/dictionary.cpp index 37084b66..694c2e7d 100644 --- a/src/roff/troff/dictionary.cpp +++ b/src/troff/dictionary.cpp @@ -1,28 +1,31 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2004 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2001, 2004 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "troff-config.h" -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - - -#include "troff.h" #include "dictionary.h" - +#include "troff.h" + // is `p' a good size for a hash table static int is_good_size(unsigned int p) @@ -49,7 +52,7 @@ dictionary::dictionary(int n) : size(n), used(0), threshold(0.5), factor(1.5) void *dictionary::lookup(symbol s, void *v) { int i; - for (i = int(s.hash() % size); + for (i = int(s.hash() % size); table[i].v != 0; i == 0 ? i = size - 1: --i) if (s == table[i].s) { @@ -92,7 +95,7 @@ void *dictionary::lookup(const char *p) } // see Knuth, Sorting and Searching, p527, Algorithm R - + void *dictionary::remove(symbol s) { // this relies on the fact that we are using linear probing @@ -209,3 +212,5 @@ int object_dictionary::alias(symbol newnm, symbol oldnm) } return 0; } + +// s-it2-mode diff --git a/src/roff/troff/dictionary.h b/src/troff/dictionary.h similarity index 52% rename from src/roff/troff/dictionary.h rename to src/troff/dictionary.h index 2baab0ab..0fdbe02e 100644 --- a/src/roff/troff/dictionary.h +++ b/src/troff/dictionary.h @@ -1,63 +1,78 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - - +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992 Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _DICTIONARY_H +#define _DICTIONARY_H + +#include "config.h" +#include "troff-config.h" // there is no distinction between name with no value and name with NULL value // null names are not permitted (they will be ignored). -struct association { +class association +{ +public: symbol s; void *v; + association() : v(0) {} }; class dictionary; -class dictionary_iterator { +class dictionary_iterator +{ dictionary *dict; int i; + public: dictionary_iterator(dictionary &); int get(symbol *, void **); }; -class dictionary { +class dictionary +{ + friend class dictionary_iterator; + int size; int used; double threshold; double factor; association *table; + void rehash(int); + public: dictionary(int); void *lookup(symbol s, void *v=0); // returns value associated with key void *lookup(const char *); // if second parameter not NULL, value will be replaced void *remove(symbol); - friend class dictionary_iterator; }; -class object { +class object +{ int rcount; - public: + +public: object(); virtual ~object(); void add_reference(); @@ -66,15 +81,19 @@ class object { class object_dictionary; -class object_dictionary_iterator { +class object_dictionary_iterator +{ dictionary_iterator di; + public: object_dictionary_iterator(object_dictionary &); int get(symbol *, object **); }; -class object_dictionary { +class object_dictionary +{ dictionary d; + public: object_dictionary(int); object *lookup(symbol nm); @@ -85,8 +104,9 @@ public: friend class object_dictionary_iterator; }; - inline int object_dictionary_iterator::get(symbol *sp, object **op) { return di.get(sp, (void **)op); } +#endif // _DICTIONARY_H +// s-it2-mode diff --git a/src/roff/troff/div.cpp b/src/troff/div.cpp similarity index 94% rename from src/roff/troff/div.cpp rename to src/troff/div.cpp index 57446ad3..bef851ed 100644 --- a/src/roff/troff/div.cpp +++ b/src/troff/div.cpp @@ -1,40 +1,42 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) +/*@ Diversions. + * + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2002, 2004 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "troff-config.h" -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - - -// diversions +#include "nonposix.h" +#include "stringclass.h" -#include "troff.h" #include "dictionary.h" +#include "div.h" +#include "env.h" #include "hvunits.h" -#include "stringclass.h" #include "mtsm.h" -#include "env.h" -#include "request.h" #include "node.h" -#include "token.h" -#include "div.h" #include "reg.h" - -#include "nonposix.h" +#include "request.h" +#include "token.h" +#include "troff.h" int exit_started = 0; // the exit process has started int done_end_macro = 0; // the end macro (if any) has finished @@ -51,7 +53,7 @@ static int vertical_position_traps_flag = 1; static vunits truncated_space; static vunits needed_space; -diversion::diversion(symbol s) +diversion::diversion(symbol s) : prev(0), nm(s), vertical_position(V0), high_water_mark(V0), any_chars_added(0), no_space_mode(0), needs_push(0), saved_seen_break(0), saved_seen_space(0), saved_seen_eol(0), saved_suppress_next_eol(0), @@ -154,7 +156,7 @@ void divert_append() { do_divert(1, 0); } - + void box() { do_divert(0, 1); @@ -185,7 +187,7 @@ macro_diversion::macro_diversion(symbol s, int append) .da a .a .di - + This causes an infinite loop in troff anyway. This is because the user could do @@ -206,7 +208,7 @@ macro_diversion::macro_diversion(symbol s, int append) will work and will make `a' contain two copies of what it contained before; in troff, `a' would contain nothing. */ - request_or_macro *rm + request_or_macro *rm = (request_or_macro *)request_dictionary.remove(s); if (!rm || (mac = rm->to_macro()) == 0) mac = new macro; @@ -219,7 +221,7 @@ macro_diversion::macro_diversion(symbol s, int append) // stored in the macro. When we detect this, we copy the contents. mac = new macro(1); if (append) { - request_or_macro *rm + request_or_macro *rm = (request_or_macro *)request_dictionary.lookup(s); if (rm) { macro *m = rm->to_macro(); @@ -345,7 +347,7 @@ trap *top_level_diversion::find_next_trap(vunits *next_trap_pos) for (trap *pt = page_trap_list; pt != 0; pt = pt->next) if (!pt->nm.is_null()) { if (pt->position >= V0) { - if (pt->position > vertical_position + if (pt->position > vertical_position && pt->position < page_length && (next_trap == 0 || pt->position < *next_trap_pos)) { next_trap = pt; @@ -381,7 +383,7 @@ void top_level_diversion::output(node *nd, int retain_size, no_space_mode = 0; vunits next_trap_pos; trap *next_trap = find_next_trap(&next_trap_pos); - if (before_first_page && begin_page()) + if (before_first_page && begin_page()) fatal("sorry, I didn't manage to begin the first page in time: use an explicit .br request"); vertical_size v(vs, post_vs); for (node *tem = nd; tem != 0; tem = tem->next) @@ -507,7 +509,7 @@ void top_level_diversion::add_trap(symbol nam, vunits pos) } else *p = new trap(nam, pos, 0); -} +} void top_level_diversion::remove_trap(symbol nam) { @@ -526,7 +528,7 @@ void top_level_diversion::remove_trap_at(vunits pos) return; } } - + void top_level_diversion::change_trap(symbol nam, vunits pos) { for (trap *p = page_trap_list; p; p = p->next) @@ -777,7 +779,7 @@ void space_request() else // The line might have had line spacing that was truncated. truncated_space += n; - + tok.next(); } @@ -952,12 +954,14 @@ void vertical_position_traps() skip_line(); } -class page_offset_reg : public reg { +class page_offset_reg +: public reg +{ public: int get_value(units *); const char *get_string(); }; - + int page_offset_reg::get_value(units *res) { *res = topdiv->get_page_offset().to_units(); @@ -969,12 +973,14 @@ const char *page_offset_reg::get_string() return i_to_a(topdiv->get_page_offset().to_units()); } -class page_length_reg : public reg { +class page_length_reg +: public reg +{ public: int get_value(units *); const char *get_string(); }; - + int page_length_reg::get_value(units *res) { *res = topdiv->get_page_length().to_units(); @@ -986,12 +992,14 @@ const char *page_length_reg::get_string() return i_to_a(topdiv->get_page_length().to_units()); } -class vertical_position_reg : public reg { +class vertical_position_reg +: public reg +{ public: int get_value(units *); const char *get_string(); }; - + int vertical_position_reg::get_value(units *res) { if (curdiv == topdiv && topdiv->before_first_page) @@ -1009,12 +1017,14 @@ const char *vertical_position_reg::get_string() return i_to_a(curdiv->get_vertical_position().to_units()); } -class high_water_mark_reg : public reg { +class high_water_mark_reg +: public reg +{ public: int get_value(units *); const char *get_string(); }; - + int high_water_mark_reg::get_value(units *res) { *res = curdiv->get_high_water_mark().to_units(); @@ -1026,12 +1036,14 @@ const char *high_water_mark_reg::get_string() return i_to_a(curdiv->get_high_water_mark().to_units()); } -class distance_to_next_trap_reg : public reg { +class distance_to_next_trap_reg +: public reg +{ public: int get_value(units *); const char *get_string(); }; - + int distance_to_next_trap_reg::get_value(units *res) { *res = curdiv->distance_to_next_trap().to_units(); @@ -1043,7 +1055,9 @@ const char *distance_to_next_trap_reg::get_string() return i_to_a(curdiv->distance_to_next_trap().to_units()); } -class diversion_name_reg : public reg { +class diversion_name_reg +: public reg +{ public: const char *get_string(); }; @@ -1053,7 +1067,9 @@ const char *diversion_name_reg::get_string() return curdiv->get_diversion_name(); } -class page_number_reg : public general_reg { +class page_number_reg +: public general_reg +{ public: page_number_reg(); int get_value(units *); @@ -1075,7 +1091,9 @@ int page_number_reg::get_value(units *res) return 1; } -class next_page_number_reg : public reg { +class next_page_number_reg +: public reg +{ public: const char *get_string(); }; @@ -1085,7 +1103,9 @@ const char *next_page_number_reg::get_string() return i_to_a(topdiv->get_next_page_number()); } -class page_ejecting_reg : public reg { +class page_ejecting_reg +: public reg +{ public: const char *get_string(); }; @@ -1095,8 +1115,11 @@ const char *page_ejecting_reg::get_string() return i_to_a(topdiv->get_ejecting()); } -class constant_vunits_reg : public reg { +class constant_vunits_reg +: public reg +{ vunits *p; + public: constant_vunits_reg(vunits *); const char *get_string(); @@ -1111,7 +1134,9 @@ const char *constant_vunits_reg::get_string() return i_to_a(p->to_units()); } -class nl_reg : public variable_reg { +class nl_reg +: public variable_reg +{ public: nl_reg(); void set_value(units); @@ -1135,7 +1160,9 @@ void nl_reg::set_value(units n) topdiv->before_first_page = 2; } -class no_space_mode_reg : public reg { +class no_space_mode_reg +: public reg +{ public: int get_value(units *); const char *get_string(); @@ -1190,7 +1217,7 @@ void init_div_requests() number_reg_dictionary.define(".t", new distance_to_next_trap_reg); number_reg_dictionary.define(".trunc", new constant_vunits_reg(&truncated_space)); - number_reg_dictionary.define(".vpt", + number_reg_dictionary.define(".vpt", new constant_int_reg(&vertical_position_traps_flag)); number_reg_dictionary.define(".z", new diversion_name_reg); number_reg_dictionary.define("dl", new variable_reg(&dl_reg_contents)); @@ -1198,3 +1225,5 @@ void init_div_requests() number_reg_dictionary.define("nl", new nl_reg); number_reg_dictionary.define("%", new page_number_reg); } + +// s-it2-mode diff --git a/src/roff/troff/div.h b/src/troff/div.h similarity index 78% rename from src/roff/troff/div.h rename to src/troff/div.h index c9ff9b40..e19fee89 100644 --- a/src/roff/troff/div.h +++ b/src/troff/div.h @@ -1,31 +1,39 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2004, 2005 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2001, 2002, 2004, 2005 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _DIV_H +#define _DIV_H + +#include "config.h" +#include "troff-config.h" void do_divert(int append, int boxing); void end_diversions(); void page_offset(); -class diversion { +class diversion +{ friend void do_divert(int append, int boxing); friend void end_diversions(); + diversion *prev; node *saved_line; hunits saved_width_total; @@ -33,10 +41,12 @@ class diversion { hunits saved_saved_indent; hunits saved_target_text_length; int saved_prev_line_interrupted; + protected: symbol nm; vunits vertical_position; vunits high_water_mark; + public: int any_chars_added; int no_space_mode; @@ -47,6 +57,7 @@ public: int saved_suppress_next_eol; state_set modified_tag; vunits marked_place; + diversion(symbol s = NULL_SYMBOL); virtual ~diversion(); virtual void output(node *nd, int retain_size, vunits vs, vunits post_vs, @@ -70,11 +81,14 @@ public: class macro; -class macro_diversion : public diversion { +class macro_diversion +: public diversion +{ macro *mac; hunits max_width; symbol diversion_trap; vunits diversion_trap_pos; + public: macro_diversion(symbol, int); ~macro_diversion(); @@ -85,7 +99,7 @@ public: void space(vunits distance, int forced = 0); #ifdef COLUMN void vjustify(symbol); -#endif /* COLUMN */ +#endif vunits distance_to_next_trap(); void set_diversion_trap(symbol, vunits); void clear_diversion_trap(); @@ -93,16 +107,21 @@ public: int is_diversion() { return 1; } }; -struct trap { +class trap +{ +public: trap *next; vunits position; symbol nm; + trap(symbol, vunits, trap *); }; class output_file; -class top_level_diversion : public diversion { +class top_level_diversion +: public diversion +{ int page_number; int page_count; int last_page_count; @@ -110,13 +129,16 @@ class top_level_diversion : public diversion { hunits prev_page_offset; hunits page_offset; trap *page_trap_list; - trap *find_next_trap(vunits *); int have_next_page_number; int next_page_number; int ejecting_page; // Is the current page being ejected? + + trap *find_next_trap(vunits *); + public: int before_first_page; top_level_diversion(); + void output(node *nd, int retain_size, vunits vs, vunits post_vs, hunits width); void transparent_output(unsigned char); @@ -170,3 +192,6 @@ void blank_line(); void begin_page(); extern void cleanup_and_exit(int); + +#endif // _DIV_H +// s-it2-mode diff --git a/src/roff/troff/env.cpp b/src/troff/env.cpp similarity index 98% rename from src/roff/troff/env.cpp rename to src/troff/env.cpp index 5e93625c..184dfd99 100644 --- a/src/roff/troff/env.cpp +++ b/src/troff/env.cpp @@ -1,42 +1,46 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005, - 2006 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2006 Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "troff-config.h" -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. +#include -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "file_case.h" +#include "font.h" +#include "macropath.h" +#include "stringclass.h" -#include "troff.h" +#include "charinfo.h" #include "dictionary.h" +#include "div.h" +#include "env.h" #include "hvunits.h" -#include "stringclass.h" +#include "input.h" #include "mtsm.h" -#include "env.h" -#include "file_case.h" -#include "request.h" #include "node.h" -#include "token.h" -#include "div.h" #include "reg.h" -#include "font.h" -#include "charinfo.h" -#include "macropath.h" -#include "input.h" -#include +#include "request.h" +#include "token.h" +#include "troff.h" symbol default_family("T"); @@ -44,16 +48,18 @@ enum { ADJUST_LEFT = 0, ADJUST_BOTH = 1, ADJUST_CENTER = 3, ADJUST_RIGHT = 5 }; enum { HYPHEN_LAST_LINE = 2, HYPHEN_LAST_CHARS = 4, HYPHEN_FIRST_CHARS = 8 }; -struct env_list { +class env_list +{ +public: environment *env; env_list *next; + env_list(environment *e, env_list *p) : env(e), next(p) {} }; env_list *env_stack; -const int NENVIRONMENTS = 10; environment *env_table[NENVIRONMENTS]; -dictionary env_dictionary(10); +dictionary env_dictionary(NENVIRONMENTS); environment *curenv; static int next_line_number = 0; extern int suppress_push; @@ -64,7 +70,13 @@ charinfo *padding_indicator_char; int translate_space_to_dummy = 0; -class pending_output_line { +class pending_output_line +{ +#ifdef WIDOW_CONTROL + friend void environment::mark_last_line(); + friend void environment::output(node *, int, vunits, vunits, hunits, int); +#endif + node *nd; int no_fill; int was_centered; @@ -73,7 +85,8 @@ class pending_output_line { hunits width; #ifdef WIDOW_CONTROL int last_line; // Is it the last line of the paragraph? -#endif /* WIDOW_CONTROL */ +#endif + public: pending_output_line *next; @@ -81,11 +94,6 @@ public: pending_output_line * = 0); ~pending_output_line(); int output(); - -#ifdef WIDOW_CONTROL - friend void environment::mark_last_line(); - friend void environment::output(node *, int, vunits, vunits, hunits, int); -#endif /* WIDOW_CONTROL */ }; pending_output_line::pending_output_line(node *n, int nf, vunits v, vunits pv, @@ -94,7 +102,7 @@ pending_output_line::pending_output_line(node *n, int nf, vunits v, vunits pv, : nd(n), no_fill(nf), was_centered(ce), vs(v), post_vs(pv), width(w), #ifdef WIDOW_CONTROL last_line(0), -#endif /* WIDOW_CONTROL */ +#endif next(p) { } @@ -137,13 +145,13 @@ void environment::output(node *nd, int no_fill_flag, pending_lines = pending_lines->next; delete tem; } -#else /* WIDOW_CONTROL */ +#else output_pending_lines(); -#endif /* WIDOW_CONTROL */ +#endif if (!trap_sprung_flag && !pending_lines #ifdef WIDOW_CONTROL && (!widow_control || no_fill_flag) -#endif /* WIDOW_CONTROL */ +#endif ) { curenv->construct_format_state(nd, was_centered, !no_fill_flag); curdiv->output(nd, no_fill_flag, vs, post_vs, width); @@ -179,7 +187,6 @@ void environment::output_pending_lines() } #ifdef WIDOW_CONTROL - void environment::mark_last_line() { if (!widow_control || !pending_lines) @@ -200,7 +207,6 @@ void widow_control_request() curenv->widow_control = 1; skip_line(); } - #endif /* WIDOW_CONTROL */ /* font_size functions */ @@ -209,12 +215,10 @@ size_range *font_size::size_table = 0; int font_size::nranges = 0; extern "C" { - int compare_ranges(const void *p1, const void *p2) { return ((size_range *)p1)->min - ((size_range *)p2)->min; } - } void font_size::init_size_table(int *sizes) @@ -939,7 +943,7 @@ int environment::get_bold() hunits environment::get_digit_width() { return env_digit_width(this); -} +} int environment::get_adjust_mode() { @@ -2461,7 +2465,7 @@ void title() curenv->total_post_vertical_spacing(), length_title); curenv->hyphen_line_count = 0; tok.next(); -} +} void adjust() { @@ -2584,7 +2588,7 @@ tab::tab(hunits x, tab_type t) : next(0), pos(x), type(t) { } -tab_stops::tab_stops(hunits distance, tab_type type) +tab_stops::tab_stops(hunits distance, tab_type type) : initial_list(0) { repeated_list = new tab(distance, type); @@ -2699,7 +2703,7 @@ tab_stops::tab_stops() : initial_list(0), repeated_list(0) { } -tab_stops::tab_stops(const tab_stops &ts) +tab_stops::tab_stops(const tab_stops &ts) : initial_list(0), repeated_list(0) { tab **p = &initial_list; @@ -2759,7 +2763,7 @@ void tab_stops::operator=(const tab_stops &ts) p = &(*p)->next; } } - + void set_tabs() { hunits pos; @@ -2965,8 +2969,8 @@ void environment::wrap_up_field() add_padding(); hunits padding = field_distance - (get_text_length() - pre_field_width); if (current_tab && tab_field_spaces != 0) { - hunits tab_padding = scale(padding, - tab_field_spaces, + hunits tab_padding = scale(padding, + tab_field_spaces, field_spaces + tab_field_spaces); padding -= tab_padding; distribute_space(tab_contents, tab_field_spaces, tab_padding, 1); @@ -3027,33 +3031,44 @@ typedef vunits (environment::*VUNITS_FUNCP)(); typedef hunits (environment::*HUNITS_FUNCP)(); typedef const char *(environment::*STRING_FUNCP)(); -class int_env_reg : public reg { +class int_env_reg +: public reg +{ INT_FUNCP func; - public: + +public: int_env_reg(INT_FUNCP); const char *get_string(); int get_value(units *val); }; -class vunits_env_reg : public reg { +class vunits_env_reg +: public reg +{ VUNITS_FUNCP func; - public: + +public: vunits_env_reg(VUNITS_FUNCP f); const char *get_string(); int get_value(units *val); }; - -class hunits_env_reg : public reg { +class hunits_env_reg +: public reg +{ HUNITS_FUNCP func; - public: + +public: hunits_env_reg(HUNITS_FUNCP f); const char *get_string(); int get_value(units *val); }; -class string_env_reg : public reg { +class string_env_reg +: public reg +{ STRING_FUNCP func; + public: string_env_reg(STRING_FUNCP); const char *get_string(); @@ -3073,7 +3088,7 @@ const char *int_env_reg::get_string() { return i_to_a((curenv->*func)()); } - + vunits_env_reg::vunits_env_reg(VUNITS_FUNCP f) : func(f) { } @@ -3113,7 +3128,9 @@ const char *string_env_reg::get_string() return (curenv->*func)(); } -class horizontal_place_reg : public general_reg { +class horizontal_place_reg +: public general_reg +{ public: horizontal_place_reg(); int get_value(units *); @@ -3351,7 +3368,7 @@ void environment::print_env() errprint(" hyphenation margin: %1u\n", hyphenation_margin.to_units()); #ifdef WIDOW_CONTROL errprint(" widow control: %1\n", widow_control ? "yes" : "no"); -#endif /* WIDOW_CONTROL */ +#endif } void print_env() @@ -3503,11 +3520,14 @@ void init_env_requests() struct trie_node; -class trie { +class trie +{ trie_node *tp; + virtual void do_match(int len, void *val) = 0; virtual void do_delete(void *) = 0; void delete_trie_node(trie_node *); + public: trie() : tp(0) {} virtual ~trie(); // virtual to shut up g++ @@ -3517,13 +3537,17 @@ public: void clear(); }; -class hyphen_trie : private trie { +class hyphen_trie +: private trie +{ int *h; + void do_match(int i, void *v); void do_delete(void *v); void insert_pattern(const char *pat, int patlen, int *num); void insert_hyphenation(dictionary *ex, const char *pat, int patlen); int hpf_getc(file_case *fcp); + public: hyphen_trie() {} ~hyphen_trie() {} @@ -3531,10 +3555,13 @@ public: void read_patterns_file(const char *name, int append, dictionary *ex); }; -struct hyphenation_language { +class hyphenation_language +{ +public: symbol name; dictionary exceptions; hyphen_trie patterns; + hyphenation_language(symbol nm) : name(nm), exceptions(501) {} ~hyphenation_language() { } }; @@ -3605,15 +3632,18 @@ static void hyphen_word() skip_line(); } -struct trie_node { +class trie_node +{ +public: char c; trie_node *down; trie_node *right; void *val; + trie_node(char, trie_node *); }; -trie_node::trie_node(char ch, trie_node *p) +trie_node::trie_node(char ch, trie_node *p) : c(ch), down(0), right(p), val(0) { } @@ -3629,7 +3659,6 @@ void trie::clear() tp = 0; } - void trie::delete_trie_node(trie_node *p) { if (p) { @@ -3675,10 +3704,13 @@ void trie::find(const char *pat, int patlen) } } -struct operation { +class operation +{ +public: operation *next; short distance; short num; + operation(int, int, operation *); }; @@ -4055,3 +4087,5 @@ void init_hyphen_requests() init_request("hpfa", hyphenation_patterns_file_append); number_reg_dictionary.define(".hla", new hyphenation_language_reg); } + +// s-it2-mode diff --git a/src/roff/troff/env.h b/src/troff/env.h similarity index 90% rename from src/roff/troff/env.h rename to src/troff/env.h index 14f6bae7..435b1fc4 100644 --- a/src/roff/troff/env.h +++ b/src/troff/env.h @@ -1,23 +1,29 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004, 2005, 2006 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2002, 2004 - 2006 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _ENV_H +#define _ENV_H -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "config.h" +#include "troff-config.h" class statem; @@ -26,10 +32,13 @@ struct size_range { int max; }; -class font_size { +class font_size +{ static size_range *size_table; static int nranges; + int p; + public: font_size(); font_size(int points); @@ -38,6 +47,7 @@ public: int to_units(); int operator==(font_size); int operator!=(font_size); + static void init_size_table(int *sizes); }; @@ -78,9 +88,11 @@ struct tab; enum tab_type { TAB_NONE, TAB_LEFT, TAB_CENTER, TAB_RIGHT }; -class tab_stops { +class tab_stops +{ tab *initial_list; tab *repeated_list; + public: tab_stops(); tab_stops(hunits distance, tab_type type); @@ -144,7 +156,47 @@ void widow_control_request(); void do_divert(int append, int boxing); -class environment { +class environment +{ + friend void title_length(); + friend void space_size(); + friend void fill(); + friend void no_fill(); + friend void adjust(); + friend void no_adjust(); + friend void center(); + friend void right_justify(); + friend void vertical_spacing(); + friend void post_vertical_spacing(); + friend void line_spacing(); + friend void line_length(); + friend void indent(); + friend void temporary_indent(); + friend void do_underline(int); + friend void do_input_trap(int); + friend void set_tabs(); + friend void margin_character(); + friend void no_number(); + friend void number_lines(); + friend void leader_character(); + friend void tab_character(); + friend void hyphenate_request(); + friend void no_hyphenate(); + friend void hyphen_line_max_request(); + friend void hyphenation_space_request(); + friend void hyphenation_margin_request(); + friend void line_width(); +#if 0 + friend void tabs_save(); + friend void tabs_restore(); +#endif + friend void line_tabs_request(); + friend void title(); +#ifdef WIDOW_CONTROL + friend void widow_control_request(); +#endif /* WIDOW_CONTROL */ + friend void do_divert(int append, int boxing); + int dummy; // dummy environment used for \w hunits prev_line_length; hunits line_length; @@ -249,6 +301,7 @@ class environment { void add_padding(); node *make_tab_node(hunits d, node *next = 0); node *get_prev_char(); + public: int seen_space; int seen_eol; @@ -259,7 +312,7 @@ public: unsigned char control_char; unsigned char no_break_control_char; charinfo *hyphen_indicator_char; - + environment(symbol); environment(const environment *); // for temporary environment ~environment(); @@ -297,7 +350,7 @@ public: hunits get_prev_char_skew(); vunits get_prev_char_height(); vunits get_prev_char_depth(); - hunits get_text_length(); // .k + hunits get_text_length(); // .k hunits get_prev_text_length(); // .n hunits get_space_width() { return env_space_width(this); } int get_space_size() { return space_size; } // in ems/36 @@ -360,46 +413,6 @@ public: void construct_format_state(node *n, int was_centered, int fill); void construct_new_line_state(node *n); void dump_troff_state(); - - friend void title_length(); - friend void space_size(); - friend void fill(); - friend void no_fill(); - friend void adjust(); - friend void no_adjust(); - friend void center(); - friend void right_justify(); - friend void vertical_spacing(); - friend void post_vertical_spacing(); - friend void line_spacing(); - friend void line_length(); - friend void indent(); - friend void temporary_indent(); - friend void do_underline(int); - friend void do_input_trap(int); - friend void set_tabs(); - friend void margin_character(); - friend void no_number(); - friend void number_lines(); - friend void leader_character(); - friend void tab_character(); - friend void hyphenate_request(); - friend void no_hyphenate(); - friend void hyphen_line_max_request(); - friend void hyphenation_space_request(); - friend void hyphenation_margin_request(); - friend void line_width(); -#if 0 - friend void tabs_save(); - friend void tabs_restore(); -#endif - friend void line_tabs_request(); - friend void title(); -#ifdef WIDOW_CONTROL - friend void widow_control_request(); -#endif /* WIDOW_CONTROL */ - - friend void do_divert(int append, int boxing); }; extern environment *curenv; @@ -416,3 +429,6 @@ extern symbol default_family; extern int translate_space_to_dummy; extern unsigned char hpf_code_table[]; + +#endif // _ENV_H +// s-it2-mode diff --git a/src/roff/troff/hvunits.h b/src/troff/hvunits.h similarity index 85% rename from src/roff/troff/hvunits.h rename to src/troff/hvunits.h index 99e6692e..86a0ba4f 100644 --- a/src/roff/troff/hvunits.h +++ b/src/troff/hvunits.h @@ -1,33 +1,31 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - - -class vunits { - int n; -public: - vunits(); - vunits(units); - units to_units(); - int is_zero(); - vunits& operator+=(const vunits&); - vunits& operator-=(const vunits&); +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992 Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _HVUNITS_H +#define _HVUNITS_H + +#include "config.h" +#include "troff-config.h" + +class vunits +{ friend inline vunits scale(vunits n, units x, units y); // scale n by x/y friend inline vunits scale(vunits n, vunits x, vunits y); friend inline vunits operator +(const vunits&, const vunits&); @@ -43,20 +41,22 @@ public: friend inline int operator >=(const vunits&, const vunits&); friend inline int operator ==(const vunits&, const vunits&); friend inline int operator !=(const vunits&, const vunits&); -}; -extern vunits V0; - - -class hunits { int n; + public: - hunits(); - hunits(units); + vunits(); + vunits(units); units to_units(); int is_zero(); - hunits& operator+=(const hunits&); - hunits& operator-=(const hunits&); + vunits& operator+=(const vunits&); + vunits& operator-=(const vunits&); +}; + +extern vunits V0; + +class hunits +{ friend inline hunits scale(hunits n, units x, units y); // scale n by x/y friend inline hunits scale(hunits n, double x); friend inline hunits operator +(const hunits&, const hunits&); @@ -72,6 +72,16 @@ public: friend inline int operator >=(const hunits&, const hunits&); friend inline int operator ==(const hunits&, const hunits&); friend inline int operator !=(const hunits&, const hunits&); + + int n; + +public: + hunits(); + hunits(units); + units to_units(); + int is_zero(); + hunits& operator+=(const hunits&); + hunits& operator-=(const hunits&); }; extern hunits H0; @@ -287,7 +297,6 @@ inline int operator !=(const hunits & x, const hunits & y) return x.n != y.n; } - inline hunits& hunits::operator+=(const hunits & x) { n += x.n; @@ -338,3 +347,5 @@ inline units points_to_units(units n) return scale(n, units_per_inch, 72); } +#endif // _HVUNITS_H +// s-it2-mode diff --git a/src/roff/troff/input.cpp b/src/troff/input.cpp similarity index 98% rename from src/roff/troff/input.cpp rename to src/troff/input.cpp index adef5a3b..60733ebe 100644 --- a/src/roff/troff/input.cpp +++ b/src/troff/input.cpp @@ -1,66 +1,53 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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. +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2008 Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#define DEBUGGING // FIXME -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "config.h" +#include "troff-config.h" -#define DEBUGGING +#include "defs.h" +#include "file_case.h" +#include "font.h" +#include "macropath.h" +#include "nonposix.h" +#include "posix.h" +#include "stringclass.h" +#include "unicode.h" -#include "troff.h" +#include "charinfo.h" #include "dictionary.h" +#include "div.h" +#include "env.h" #include "hvunits.h" -#include "stringclass.h" +#include "input.h" #include "mtsm.h" -#include "env.h" -#include "file_case.h" -#include "request.h" #include "node.h" -#include "token.h" -#include "div.h" #include "reg.h" -#include "font.h" -#include "charinfo.h" -#include "macropath.h" -#include "input.h" -#include "defs.h" -#include "unicode.h" - -// Needed for getpid() and isatty() -#include "posix.h" - -#include "nonposix.h" - -#ifdef NEED_DECLARATION_PUTENV -extern "C" { - int putenv(const char *); -} -#endif /* NEED_DECLARATION_PUTENV */ - -#define MACRO_PREFIX "tmac." -#define MACRO_POSTFIX ".tmac" -#define INITIAL_STARTUP_FILE "troffrc" -#define FINAL_STARTUP_FILE "troffrc-end" -#define DEFAULT_INPUT_STACK_LIMIT 1000 +#include "request.h" +#include "token.h" +#include "troff.h" -#ifndef DEFAULT_WARNING_MASK // warnings that are enabled by default -#define DEFAULT_WARNING_MASK \ +#ifndef DEFAULT_WARNING_MASK +# define DEFAULT_WARNING_MASK \ (WARN_CHAR|WARN_NUMBER|WARN_BREAK|WARN_SPACE|WARN_FONT) #endif @@ -68,7 +55,6 @@ extern "C" { #define ABUF_SIZE 16 extern "C" const char *program_name; -extern "C" const char *Version_string; #ifdef COLUMN void init_column_requests(); @@ -163,7 +149,6 @@ const char *input_char_description(int); void process_input_stack(); void chop_macro(); // declare to avoid friend name injection - void set_escape_char() { if (has_arg()) { @@ -201,20 +186,25 @@ void restore_escape_char() struct arg_list; -class input_iterator { +class input_iterator +{ + friend class input_stack; + public: + int is_diversion; + statem *diversion_state; + input_iterator(); input_iterator(int is_div); virtual ~input_iterator() {} int get(node **); - friend class input_stack; - int is_diversion; - statem *diversion_state; + protected: const unsigned char *ptr; const unsigned char *eptr; input_iterator *next; -private: + +private: // FIXME (almost) abstract virtuals in private:?? ok, but.. ?? virtual int fill(node **); virtual int peek(); virtual int has_args() { return 0; } @@ -261,17 +251,23 @@ inline int input_iterator::get(node **p) return ptr < eptr ? *ptr++ : fill(p); } -class input_boundary : public input_iterator { +class input_boundary +: public input_iterator +{ public: int is_boundary() { return 1; } }; -class input_return_boundary : public input_iterator { +class input_return_boundary +: public input_iterator +{ public: int is_boundary() { return 2; } }; -class file_iterator : public input_iterator { +class file_iterator +: public input_iterator +{ file_case *_fcp; int lineno; const char *filename; @@ -279,7 +275,9 @@ class file_iterator : public input_iterator { int seen_escape; enum { BUF_SIZE = 512 }; unsigned char buf[BUF_SIZE]; + void close(); + public: file_iterator(file_case *, const char *); ~file_iterator(); @@ -411,7 +409,13 @@ int file_iterator::set_location(const char *f, int ln) input_iterator nil_iterator; -class input_stack { +class input_stack +{ + static input_iterator *top; + static int level; + static int finish_get(node **); + static int finish_peek(); + public: static int get(node **); static int peek(); @@ -446,11 +450,6 @@ public: static int limit; static int div_level; static statem *diversion_state; -private: - static input_iterator *top; - static int level; - static int finish_get(node **); - static int finish_peek(); }; input_iterator *input_stack::top = &nil_iterator; @@ -460,7 +459,6 @@ int input_stack::div_level = 0; statem *input_stack::diversion_state = NULL; int suppress_push=0; - inline int input_stack::get_level() { return level; @@ -1130,7 +1128,7 @@ static int get_copy(node **nd, int defining, int handle_escape_E) return ESCAPE_RIGHT_PARENTHESIS; case '.': (void)input_stack::get(0); - return c; + return c; case '%': (void)input_stack::get(0); return ESCAPE_PERCENT; @@ -1145,8 +1143,11 @@ static int get_copy(node **nd, int defining, int handle_escape_E) } } -class non_interpreted_char_node : public node { +class non_interpreted_char_node +: public node +{ unsigned char c; + public: non_interpreted_char_node(unsigned char); node *copy(); @@ -1615,9 +1616,12 @@ token_node *node::get_token_node() return 0; } -class token_node : public node { +class token_node +: public node +{ public: token tk; + token_node(const token &t); node *copy(); token_node *get_token_node(); @@ -3035,10 +3039,13 @@ void request::invoke(symbol, int) (*p)(); } -struct char_block { +class char_block +{ +public: enum { SIZE = 128 }; unsigned char s[SIZE]; char_block *next; + char_block(); }; @@ -3047,7 +3054,16 @@ char_block::char_block() { } -class char_list { +class char_list +{ + friend class macro_header; + friend class string_iterator; + + unsigned char *ptr; + int len; + char_block *head; + char_block *tail; + public: char_list(); ~char_list(); @@ -3055,13 +3071,6 @@ public: void set(unsigned char, int); unsigned char get(int); int length(); -private: - unsigned char *ptr; - int len; - char_block *head; - char_block *tail; - friend class macro_header; - friend class string_iterator; }; char_list::char_list() @@ -3138,18 +3147,20 @@ unsigned char char_list::get(int offset) } } -class node_list { +class node_list +{ + friend class macro_header; + friend class string_iterator; + node *head; node *tail; + public: node_list(); ~node_list(); void append(node *); int length(); node *extract(); - - friend class macro_header; - friend class string_iterator; }; void node_list::append(node *n) @@ -3189,11 +3200,13 @@ node_list::~node_list() delete_node_list(head); } -class macro_header { +class macro_header +{ public: int count; char_list cl; node_list nl; + macro_header() { count = 1; } macro_header *copy(int); }; @@ -3397,7 +3410,9 @@ void print_macros() skip_line(); } -class string_iterator : public input_iterator { +class string_iterator +: public input_iterator +{ macro mac; const char *how_invoked; int newline_flag; @@ -3407,9 +3422,12 @@ class string_iterator : public input_iterator { node *nd; int saved_compatible_flag; int with_break; // inherited from the caller + protected: symbol nm; + string_iterator(); + public: string_iterator(const macro &, const char * = 0, symbol = NULL_SYMBOL); int fill(node **); @@ -3540,17 +3558,19 @@ void string_iterator::backtrace() } } -class temp_iterator : public input_iterator { +class temp_iterator +: public input_iterator +{ + friend input_iterator *make_temp_iterator(const char *); + unsigned char *base; + temp_iterator(const char *, int len); public: ~temp_iterator(); - friend input_iterator *make_temp_iterator(const char *); }; -#ifdef __GNUG__ inline -#endif temp_iterator::temp_iterator(const char *s, int len) { base = new unsigned char[len]; @@ -3564,22 +3584,28 @@ temp_iterator::~temp_iterator() a_delete base; } -class small_temp_iterator : public input_iterator { -private: +class small_temp_iterator +: public input_iterator +{ + friend input_iterator *make_temp_iterator(const char *); + + static small_temp_iterator *free_list; + + enum { BLOCK = 16 }; + enum { SIZE = 12 }; + unsigned char buf[SIZE]; + +private: // TODO class all private; ok (has friend: public static? !!), but small_temp_iterator(const char *, int); ~small_temp_iterator(); - enum { BLOCK = 16 }; - static small_temp_iterator *free_list; + void *operator new(size_t); void operator delete(void *); - enum { SIZE = 12 }; - unsigned char buf[SIZE]; - friend input_iterator *make_temp_iterator(const char *); }; small_temp_iterator *small_temp_iterator::free_list = 0; -void *small_temp_iterator::operator new(size_t n) +void *small_temp_iterator::operator new(size_t n) // TODO -> object cache { assert(n == sizeof(small_temp_iterator)); if (!free_list) { @@ -3595,10 +3621,8 @@ void *small_temp_iterator::operator new(size_t n) return p; } -#ifdef __GNUG__ inline -#endif -void small_temp_iterator::operator delete(void *p) +void small_temp_iterator::operator delete(void *p) // TODO -> nope { if (p) { ((small_temp_iterator *)p)->next = free_list; @@ -3610,9 +3634,7 @@ small_temp_iterator::~small_temp_iterator() { } -#ifdef __GNUG__ inline -#endif small_temp_iterator::small_temp_iterator(const char *s, int len) { for (int i = 0; i < len; i++) @@ -3636,10 +3658,13 @@ input_iterator *make_temp_iterator(const char *s) // this is used when macros with arguments are interpolated -struct arg_list { +class arg_list +{ +public: macro mac; int space_follows; arg_list *next; + arg_list(const macro &, int); arg_list(const arg_list *); ~arg_list(); @@ -3667,10 +3692,13 @@ arg_list::~arg_list() { } -class macro_iterator : public string_iterator { +class macro_iterator +: public string_iterator +{ arg_list *args; int argc; - int with_break; // whether called as .foo or 'foo + int with_break; // whether called as .foo or 'foo + public: macro_iterator(symbol, macro &, const char * = "macro", int = 0); macro_iterator(); @@ -3749,7 +3777,6 @@ void macro_iterator::shift(int n) } // This gets used by eg .if '\?xxx\?''. - int operator==(const macro &m1, const macro &m2) { if (m1.len != m2.len) @@ -5441,7 +5468,7 @@ void device_macro_request() macro *m = p->to_macro(); if (m) curenv->add_node(new special_node(*m)); - else + else error("can't transparently throughput a request"); } skip_line(); @@ -5608,7 +5635,7 @@ static void skip_alternative() } /* Note that the level can properly be < 0, eg - + .if 1 \{\ .if 0 \{\ .\}\} @@ -5885,7 +5912,6 @@ void while_continue_request() } // .so - void source() { symbol nm = get_long_name(1); @@ -5905,7 +5931,6 @@ void source() } // like .so but use popen() - void pipe_source() { if (!unsafe_flag) { @@ -6000,7 +6025,7 @@ int parse_bounding_box(char *p, bounding_box *bb) return 0; } -// This version is taken from psrm.cpp +// This version is taken from psrm.cpp FIXME DO IT LIKE #define PS_LINE_MAX 255 cset white_space("\n\r \t"); @@ -6918,7 +6943,9 @@ void token::process() } } -class nargs_reg : public reg { +class nargs_reg +: public reg +{ public: const char *get_string(); }; @@ -6928,7 +6955,9 @@ const char *nargs_reg::get_string() return i_to_a(input_stack::nargs()); } -class lineno_reg : public reg { +class lineno_reg +: public reg +{ public: const char *get_string(); }; @@ -6942,7 +6971,9 @@ const char *lineno_reg::get_string() return i_to_a(line); } -class writable_lineno_reg : public general_reg { +class writable_lineno_reg +: public general_reg +{ public: writable_lineno_reg(); void set_value(units); @@ -6968,7 +6999,9 @@ void writable_lineno_reg::set_value(units n) input_stack::set_location(0, n); } -class filename_reg : public reg { +class filename_reg +: public reg +{ public: const char *get_string(); }; @@ -6983,7 +7016,9 @@ const char *filename_reg::get_string() return 0; } -class break_flag_reg : public reg { +class break_flag_reg +: public reg +{ public: const char *get_string(); }; @@ -6993,8 +7028,11 @@ const char *break_flag_reg::get_string() return i_to_a(input_stack::get_break_flag()); } -class constant_reg : public reg { +class constant_reg +: public reg +{ const char *s; + public: constant_reg(const char *); const char *get_string(); @@ -7140,7 +7178,6 @@ void copy_file() } #ifdef COLUMN - void vjustify() { if (curdiv == topdiv && topdiv->before_first_page) { @@ -7152,8 +7189,7 @@ void vjustify() curdiv->vjustify(type); skip_line(); } - -#endif /* COLUMN */ +#endif void transparent_file() { @@ -7192,11 +7228,14 @@ void transparent_file() tok.next(); } -class page_range { +class page_range +{ int first; int last; + public: page_range *next; + page_range(int, int, page_range *); int contains(int n); }; @@ -7419,9 +7458,12 @@ static void do_string_assignment(const char *s) } } -struct string_list { +class string_list +{ +public: const char *s; string_list *next; + string_list(const char *ss) : s(ss), next(0) {} }; @@ -7444,7 +7486,7 @@ static void add_string(const char *s, string_list **p) void usage(FILE *stream, const char *prog) { fprintf(stream, -"usage: %s -abcivzCERU -wname -Wname -dcs -ffam -mname -nnum -olist\n" +"Synopsis: %s -abcivzCERU -wname -Wname -dcs -ffam -mname -nnum -olist\n" " -rcn -Tname -Fdir -Idir -Mdir [files...]\n", prog); } @@ -7467,7 +7509,7 @@ int main(int argc, char **argv) opterr = 0; hresolution = vresolution = 1; // restore $PATH if called from groff - char* groff_path = getenv("GROFF_PATH__"); + char* groff_path = getenv(U_ROFF_PATH__); if (groff_path) { string e = "PATH"; e += '='; @@ -7482,8 +7524,8 @@ int main(int argc, char **argv) { "version", no_argument, 0, 'v' }, { 0, 0, 0, 0 } }; -#if defined(DEBUGGING) -#define DEBUG_OPTION "D" +#ifdef DEBUGGING +# define DEBUG_OPTION "D" #endif while ((c = getopt_long(argc, argv, "abciI:vw:W:zCEf:m:n:o:r:d:F:M:T:tqs:RU" @@ -7492,7 +7534,7 @@ int main(int argc, char **argv) switch(c) { case 'v': { - printf("GNU troff (groff) version %s\n", Version_string); + printf(L_TROFF " (" T_ROFF ") v" VERSION); exit(0); break; } @@ -7580,7 +7622,7 @@ int main(int argc, char **argv) case 'U': unsafe_flag = 1; // unsafe behaviour break; -#if defined(DEBUGGING) +#ifdef DEBUGGING case 'D': debug_state = 1; break; @@ -7789,7 +7831,7 @@ void init_input_requests() init_request("fchar", define_fallback_character); #ifdef WIDOW_CONTROL init_request("fpl", flush_pending_lines); -#endif /* WIDOW_CONTROL */ +#endif init_request("hcode", hyphenation_code); init_request("hpfcode", hyphenation_patterns_file_code); init_request("ie", if_else_request); @@ -7810,7 +7852,7 @@ void init_input_requests() init_request("psbb", ps_bbox_request); #ifndef POPEN_MISSING init_request("pso", pipe_source); -#endif /* not POPEN_MISSING */ +#endif init_request("rchar", remove_character); init_request("rd", read_request); init_request("return", return_macro_request); @@ -7835,7 +7877,7 @@ void init_input_requests() init_request("unformat", unformat_macro); #ifdef COLUMN init_request("vj", vjustify); -#endif /* COLUMN */ +#endif init_request("warn", warn_request); init_request("warnscale", warnscale_request); init_request("while", while_request); @@ -8097,7 +8139,7 @@ static void read_color_draw_node(token &start) static struct { const char *name; int mask; -} warning_table[] = { +} warning_table[] = { // FIXME const? { "char", WARN_CHAR }, { "range", WARN_RANGE }, { "break", WARN_BREAK }, @@ -8409,7 +8451,7 @@ charinfo *get_charinfo_by_number(int n) // This overrides the same function from libgroff; while reading font // definition files it puts single-letter glyph names into `charset_table' -// and converts glyph names of the form `\x' (`x' a single letter) into `x'. +// and converts glyph names of the form `\x' (`x' a single letter) into `x'. // Consequently, symbol("x") refers to glyph name `\x', not `x'. glyph *name_to_glyph(const char *nm) @@ -8434,3 +8476,5 @@ const char *glyph_to_name(glyph *g) charinfo *ci = (charinfo *)g; // Every glyph is actually a charinfo. return (ci->nm != UNNAMED_SYMBOL ? ci->nm.contents() : NULL); } + +// s-it2-mode diff --git a/src/roff/troff/input.h b/src/troff/input.h similarity index 69% rename from src/roff/troff/input.h rename to src/troff/input.h index 7a194c44..fbb328a4 100644 --- a/src/roff/troff/input.h +++ b/src/troff/input.h @@ -1,26 +1,30 @@ -// -*- C++ -*- -/* Copyright (C) 2001, 2004, 2006 Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 2001, 2004, 2006 Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _INPUT_H +#define _INPUT_H +#include "config.h" +#include "troff-config.h" /* special character codes */ - #ifndef IS_EBCDIC_HOST const int ESCAPE_QUESTION = 015; @@ -46,9 +50,9 @@ const int ESCAPE_SPACE = 037; const int TITLE_REQUEST = 0200; const int COPY_FILE_REQUEST = 0201; const int TRANSPARENT_FILE_REQUEST = 0202; -#ifdef COLUMN +# ifdef COLUMN const int VJUSTIFY_REQUEST = 0203; -#endif /* COLUMN */ +# endif const int ESCAPE_E = 0204; const int LAST_PAGE_EJECTOR = 0205; const int ESCAPE_RIGHT_PARENTHESIS = 0206; @@ -86,9 +90,9 @@ const int ESCAPE_SPACE = 036; const int TITLE_REQUEST = 060; const int COPY_FILE_REQUEST = 061; const int TRANSPARENT_FILE_REQUEST = 062; -#ifdef COLUMN +# ifdef COLUMN const int VJUSTIFY_REQUEST = 063; -#endif /* COLUMN */ +# endif const int ESCAPE_E = 064; const int LAST_PAGE_EJECTOR = 065; const int ESCAPE_RIGHT_PARENTHESIS = 066; @@ -105,3 +109,6 @@ const int DOUBLE_QUOTE = 076; extern void do_glyph_color(symbol); extern void do_fill_color(symbol); + +#endif // _INPUT_H +// s-it2-mode diff --git a/src/roff/troff/mtsm.cpp b/src/troff/mtsm.cpp similarity index 92% rename from src/roff/troff/mtsm.cpp rename to src/troff/mtsm.cpp index 84071975..fbb72be3 100644 --- a/src/roff/troff/mtsm.cpp +++ b/src/troff/mtsm.cpp @@ -1,33 +1,35 @@ -// -*- C++ -*- -/* Copyright (C) 2003, 2004 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - -#define DEBUGGING +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 2003, 2004 Free Software Foundation, Inc. + * Written by Gaius Mulley (gaius@glam.ac.uk) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#define DEBUGGING // FIXME ?? -extern int debug_state; +#include "config.h" +#include "troff-config.h" -#include "troff.h" +#include "env.h" #include "hvunits.h" -#include "stringclass.h" #include "mtsm.h" -#include "env.h" +#include "stringclass.h" +#include "troff.h" +extern int debug_state; static int no_of_statems = 0; // debugging aid int_value::int_value() @@ -633,3 +635,5 @@ units state_set::val(units_value_state) { return unitsset; } + +// s-it2-mode diff --git a/src/roff/troff/mtsm.h b/src/troff/mtsm.h similarity index 68% rename from src/roff/troff/mtsm.h rename to src/troff/mtsm.h index 9ef909c3..f5a459af 100644 --- a/src/roff/troff/mtsm.h +++ b/src/troff/mtsm.h @@ -1,34 +1,37 @@ -// -*- C++ -*- -/* Copyright (C) 2003, 2004 Free Software Foundation, Inc. +/*@ Provides a minimal troff state machine which is necessary to + *@ emit meta tags for the post-grohtml device driver. * - * mtsm.h + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . * + * Copyright (C) 2003, 2004 Free Software Foundation, Inc. * written by Gaius Mulley (gaius@glam.ac.uk) * - * provides a minimal troff state machine which is necessary to - * emit meta tags for the post-grohtml device driver. + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +#ifndef _MTSM_H +#define _MTSM_H -/* -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. +#include "config.h" +#include "troff-config.h" -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - -struct int_value { +class int_value +{ +public: int value; int is_known; + int_value(); ~int_value(); void diff(FILE *, const char *, int_value); @@ -38,13 +41,19 @@ struct int_value { void set_if_unknown(int); }; -struct bool_value : public int_value { +class bool_value +: public int_value +{ +public: bool_value(); ~bool_value(); void diff(FILE *, const char *, bool_value); }; -struct units_value : public int_value { +class units_value +: public int_value +{ +public: units_value(); ~units_value(); void diff(FILE *, const char *, units_value); @@ -52,9 +61,12 @@ struct units_value : public int_value { void set(hunits); }; -struct string_value { +class string_value +{ +public: string value; int is_known; + string_value(); ~string_value(); void diff(FILE *, const char *, string_value); @@ -68,6 +80,7 @@ enum bool_value_state { MTSM_BR, LAST_BOOL }; + enum int_value_state { MTSM_FI, MTSM_RJ, @@ -75,6 +88,7 @@ enum int_value_state { MTSM_SP, LAST_INT }; + enum units_value_state { MTSM_IN, MTSM_LL, @@ -82,17 +96,21 @@ enum units_value_state { MTSM_TI, LAST_UNITS }; + enum string_value_state { MTSM_TA, LAST_STRING }; -struct statem { +class statem +{ int issue_no; bool_value bool_values[LAST_BOOL]; int_value int_values[LAST_INT]; units_value units_values[LAST_UNITS]; string_value string_values[LAST_STRING]; + +public: statem(); statem(statem *); ~statem(); @@ -113,22 +131,28 @@ struct statem { void update(statem *, statem *, string_value_state); }; -struct stack { +class stack +{ +public: stack *next; statem *state; + stack(); stack(statem *, stack *); ~stack(); }; -class mtsm { +class mtsm +{ statem *driver; stack *sp; + int has_changed(int_value_state, statem *); int has_changed(bool_value_state, statem *); int has_changed(units_value_state, statem *); int has_changed(string_value_state, statem *); void inherit(statem *, int); + public: mtsm(); ~mtsm(); @@ -139,11 +163,13 @@ public: void add_tag(FILE *, string); }; -class state_set { +class state_set +{ int boolset; int intset; int unitsset; int stringset; + public: state_set(); ~state_set(); @@ -162,3 +188,6 @@ public: void add(units_value_state, int); units val(units_value_state); }; + +#endif // _MTSM_H +// s-it2-mode diff --git a/src/roff/troff/node.cpp b/src/troff/node.cpp similarity index 98% rename from src/roff/troff/node.cpp rename to src/troff/node.cpp index 0bb5d34f..e873ac64 100644 --- a/src/roff/troff/node.cpp +++ b/src/troff/node.cpp @@ -1,79 +1,58 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2008 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2006, 2008 Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ -extern int debug_state; +#include "config.h" +#include "troff-config.h" -#include "troff.h" +#include -#ifdef HAVE_UNISTD_H #include -#endif -#include "dictionary.h" -#include "hvunits.h" -#include "stringclass.h" -#include "mtsm.h" -#include "env.h" #include "file_case.h" -#include "request.h" -#include "node.h" -#include "token.h" -#include "div.h" -#include "reg.h" #include "font.h" -#include "charinfo.h" -#include "input.h" #include "geometry.h" - #include "nonposix.h" +#include "stringclass.h" -#ifdef _POSIX_VERSION - -#include - -#else /* not _POSIX_VERSION */ - -/* traditional Unix */ - -#define WIFEXITED(s) (((s) & 0377) == 0) -#define WEXITSTATUS(s) (((s) >> 8) & 0377) -#define WTERMSIG(s) ((s) & 0177) -#define WIFSTOPPED(s) (((s) & 0377) == 0177) -#define WSTOPSIG(s) (((s) >> 8) & 0377) -#define WIFSIGNALED(s) (((s) & 0377) != 0 && (((s) & 0377) != 0177)) - -#endif /* not _POSIX_VERSION */ +#include "charinfo.h" +#include "dictionary.h" +#include "div.h" +#include "env.h" +#include "hvunits.h" +#include "input.h" +#include "mtsm.h" +#include "node.h" +#include "reg.h" +#include "request.h" +#include "token.h" +#include "troff.h" +extern int debug_state; // declarations to avoid friend name injections class tfont; class tfont_spec; tfont *make_tfont(tfont_spec &); - -/* - * how many boundaries of images have been written? Useful for - * debugging grohtml - */ - +// how many boundaries of images have been written? Useful for +// debugging grohtml int image_no = 0; static int suppress_start_page = 0; @@ -88,7 +67,7 @@ enum constant_space_type { CONSTANT_SPACE_NONE, CONSTANT_SPACE_RELATIVE, CONSTANT_SPACE_ABSOLUTE - }; +}; struct special_font_list { int n; @@ -99,12 +78,14 @@ special_font_list *global_special_fonts; static int global_ligature_mode = 1; static int global_kern_mode = 1; -class track_kerning_function { +class track_kerning_function +{ int non_zero; units min_size; hunits min_amount; units max_size; hunits max_amount; + public: track_kerning_function(); track_kerning_function(units, hunits, units, hunits); @@ -114,15 +95,18 @@ public: }; // embolden fontno when this is the current font - -struct conditional_bold { +class conditional_bold +{ +public: conditional_bold *next; int fontno; hunits offset; + conditional_bold(int, hunits, conditional_bold * = 0); }; -class font_info { +class font_info +{ tfont *last_tfont; int number; font_size last_size; @@ -139,9 +123,12 @@ class font_info { int last_ligature_mode; int last_kern_mode; conditional_bold *cond_bold_list; + void flush(); + public: special_font_list *sf; + font_info(symbol, int, symbol, font *); int contains(charinfo *); void set_bold(hunits); @@ -165,7 +152,8 @@ public: friend symbol get_style_name(int); }; -class tfont_spec { +class tfont_spec +{ protected: symbol name; int input_position; @@ -180,6 +168,7 @@ protected: hunits constant_space_width; int height; int slant; + public: tfont_spec(symbol, int, font *, font_size, int, int); tfont_spec(const tfont_spec &spec) { *this = spec; } @@ -188,10 +177,14 @@ public: friend tfont *font_info::get_tfont(font_size fs, int, int, int); }; -class tfont : public tfont_spec { +class tfont +: public tfont_spec +{ static tfont *tfont_list; + tfont *next; tfont *plain_version; + public: tfont(tfont_spec &); int contains(charinfo *); @@ -713,12 +706,15 @@ tfont::tfont(tfont_spec &spec) : tfont_spec(spec) /* output_file */ -class real_output_file : public output_file { +class real_output_file +: public output_file +{ #ifndef POPEN_MISSING int piped; #endif int printing; // decision via optional page list int output_on; // \O[0] or \O[1] escape calls + virtual void really_transparent_char(unsigned char) = 0; virtual void really_print_line(hunits x, vunits y, node *n, vunits before, vunits after, hunits width) = 0; @@ -727,8 +723,10 @@ class real_output_file : public output_file { virtual void really_put_filename(const char *, int); virtual void really_on(); virtual void really_off(); + public: FILE *fp; + real_output_file(); ~real_output_file(); void flush(); @@ -743,7 +741,9 @@ public: void copy_file(hunits x, vunits y, const char *filename); }; -class suppress_output_file : public real_output_file { +class suppress_output_file +: public real_output_file +{ public: suppress_output_file(); void really_transparent_char(unsigned char); @@ -751,7 +751,9 @@ public: void really_begin_page(int pageno, vunits page_length); }; -class ascii_output_file : public real_output_file { +class ascii_output_file +: public real_output_file +{ public: ascii_output_file(); void really_transparent_char(unsigned char); @@ -776,7 +778,12 @@ void ascii_output_file::outs(const char *s) struct hvpair; -class troff_output_file : public real_output_file { +class troff_output_file +: public real_output_file +{ + friend void space_char_hmotion_node::tprint(troff_output_file *); + friend void unbreakable_space_node::tprint(troff_output_file *); + units hpos; units vpos; units output_vpos; @@ -798,6 +805,7 @@ class troff_output_file : public real_output_file { int begun_page; int cur_div_level; string tag_list; + void do_motion(); void put(char c); void put(unsigned char c); @@ -806,6 +814,7 @@ class troff_output_file : public real_output_file { void put(const char *s); void set_font(tfont *tf); void flush_tbuf(); + public: troff_output_file(); ~troff_output_file(); @@ -835,8 +844,6 @@ public: int get_hpos() { return hpos; } int get_vpos() { return vpos; } void add_to_tag_list(string s); - friend void space_char_hmotion_node::tprint(troff_output_file *); - friend void unbreakable_space_node::tprint(troff_output_file *); }; static void put_string(const char *s, FILE *fp) @@ -1816,9 +1823,12 @@ void suppress_output_file::really_transparent_char(unsigned char) /* glyphs, ligatures, kerns, discretionary breaks */ -class charinfo_node : public node { +class charinfo_node +: public node +{ protected: charinfo *ci; + public: charinfo_node(charinfo *, statem *, int, node * = 0); int ends_sentence(); @@ -1851,17 +1861,22 @@ int charinfo_node::overlaps_vertically() return ci->overlaps_vertically(); } -class glyph_node : public charinfo_node { +class glyph_node +: public charinfo_node +{ static glyph_node *free_list; + protected: tfont *tf; color *gcol; color *fcol; /* this is needed for grotty */ #ifdef STORE_WIDTH hunits wid; + glyph_node(charinfo *, tfont *, color *, color *, hunits, statem *, int, node * = 0); #endif + public: void *operator new(size_t); void operator delete(void *); @@ -1899,13 +1914,17 @@ public: glyph_node *glyph_node::free_list = 0; -class ligature_node : public glyph_node { +class ligature_node +: public glyph_node +{ node *n1; node *n2; + #ifdef STORE_WIDTH ligature_node(charinfo *, tfont *, color *, color *, hunits, node *, node *, statem *, int, node * = 0); #endif + public: void *operator new(size_t); void operator delete(void *); @@ -1923,10 +1942,13 @@ public: int is_tag(); }; -class kern_pair_node : public node { +class kern_pair_node +: public node +{ hunits amount; node *n1; node *n2; + public: kern_pair_node(hunits, node *, node *, statem *, int, node * = 0); ~kern_pair_node(); @@ -1951,10 +1973,13 @@ public: void vertical_extent(vunits *, vunits *); }; -class dbreak_node : public node { +class dbreak_node +: public node +{ node *none; node *pre; node *post; + public: dbreak_node(node *, node *, statem *, int, node * = 0); ~dbreak_node(); @@ -1980,7 +2005,7 @@ public: int is_tag(); }; -void *glyph_node::operator new(size_t n) +void *glyph_node::operator new(size_t n) // TODO -> ObjectCache! { assert(n == sizeof(glyph_node)); if (!free_list) { @@ -1996,12 +2021,12 @@ void *glyph_node::operator new(size_t n) return p; } -void *ligature_node::operator new(size_t n) +void *ligature_node::operator new(size_t n) // TODO ? { return new char[n]; } -void glyph_node::operator delete(void *p) +void glyph_node::operator delete(void *p) // TODO -> ObjectCache! { if (p) { ((glyph_node *)p)->next = free_list; @@ -2009,7 +2034,7 @@ void glyph_node::operator delete(void *p) } } -void ligature_node::operator delete(void *p) +void ligature_node::operator delete(void *p) // TODO ? { delete[] (char *)p; } @@ -2619,9 +2644,12 @@ hunits dbreak_node::subscript_correction() return none ? none->subscript_correction() : H0; } -class italic_corrected_node : public node { +class italic_corrected_node +: public node +{ node *n; hunits x; + public: italic_corrected_node(node *, hunits, statem *, int, node * = 0); ~italic_corrected_node(); @@ -2760,10 +2788,13 @@ int italic_corrected_node::character_type() return n->character_type(); } -class break_char_node : public node { +class break_char_node +: public node +{ node *ch; char break_code; color *col; + public: break_char_node(node *, int, color *, node * = 0); break_char_node(node *, int, color *, statem *, int, node * = 0); @@ -4205,9 +4236,12 @@ hunits suppress_node::width() /* composite_node */ -class composite_node : public charinfo_node { +class composite_node +: public charinfo_node +{ node *n; tfont *tf; + public: composite_node(node *, charinfo *, tfont *, statem *, int, node * = 0); ~composite_node(); @@ -4414,7 +4448,7 @@ int word_space_node::merge_space(hunits h, hunits sw, hunits ssw) { n += h; assert(orig_width != 0); - width_list *w = orig_width; + width_list *w = orig_width; for (; w->next; w = w->next) ; w->next = new width_list(sw, ssw); @@ -5090,9 +5124,7 @@ node *node::add_char(charinfo *ci, environment *env, return res; } -#ifdef __GNUG__ inline -#endif int same_node(node *n1, node *n2) { if (n1 != 0) { @@ -6510,7 +6542,9 @@ void init_output() the_output = new troff_output_file; } -class next_available_font_position_reg : public reg { +class next_available_font_position_reg +: public reg +{ public: const char *get_string(); }; @@ -6520,7 +6554,9 @@ const char *next_available_font_position_reg::get_string() return i_to_a(next_available_font_position()); } -class printing_reg : public reg { +class printing_reg +: public reg +{ public: const char *get_string(); }; @@ -6533,7 +6569,7 @@ const char *printing_reg::get_string() return "0"; } -void init_node_requests() +void init_node_requests() // TODO move static inits in here?!! { init_request("bd", bold_font); init_request("cs", constant_space); @@ -6558,3 +6594,5 @@ void init_node_requests() number_reg_dictionary.define(".P", new printing_reg); soft_hyphen_char = get_charinfo(HYPHEN_SYMBOL); } + +// s-it2-mode diff --git a/src/roff/troff/node.h b/src/troff/node.h similarity index 87% rename from src/roff/troff/node.h rename to src/troff/node.h index 6b3da78a..5a5e6bcd 100644 --- a/src/roff/troff/node.h +++ b/src/troff/node.h @@ -1,29 +1,38 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2006 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - -struct hyphen_list { +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2004, 2006 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _NODE_H +#define _NODE_H + +#include "config.h" +#include "troff-config.h" + +class hyphen_list +{ +public: unsigned char hyphen; unsigned char breakable; unsigned char hyphenation_code; hyphen_list *next; + hyphen_list(unsigned char code, hyphen_list *p = 0); }; @@ -47,13 +56,16 @@ class glyph_node; class diverted_space_node; class token_node; -struct node { +class node +{ +public: node *next; node *last; statem *state; statem *push_state; int div_nest_level; int is_special; + node(); node(node *); node(node *, statem *, int); @@ -149,7 +161,9 @@ struct breakpoint { char hyphenated; }; -class line_start_node : public node { +class line_start_node +: public node +{ public: line_start_node() {} node *copy() { return new line_start_node; } @@ -160,19 +174,23 @@ public: void asciify(macro *); }; -class space_node : public node { -private: +class space_node +: public node +{ #if 0 enum { BLOCK = 1024 }; static space_node *free_list; void operator delete(void *); #endif + protected: hunits n; char set; char was_escape_colon; color *col; /* for grotty */ + space_node(hunits, int, int, color *, statem *, int, node * = 0); + public: space_node(hunits, color *, statem *, int, node * = 0); space_node(hunits, color *, node * = 0); @@ -201,20 +219,27 @@ public: hyphenation_type get_hyphenation_type(); }; -struct width_list { +class width_list +{ +public: hunits width; hunits sentence_width; width_list *next; + width_list(hunits, hunits); width_list(width_list *); }; -class word_space_node : public space_node { +class word_space_node +: public space_node +{ protected: width_list *orig_width; unsigned char unformat; + word_space_node(hunits, int, color *, width_list *, int, statem *, int, node * = 0); + public: word_space_node(hunits, color *, width_list *, node * = 0); ~word_space_node(); @@ -230,8 +255,11 @@ public: int is_tag(); }; -class unbreakable_space_node : public word_space_node { +class unbreakable_space_node +: public word_space_node +{ unbreakable_space_node(hunits, int, color *, statem *, int, node * = 0); + public: unbreakable_space_node(hunits, color *, node * = 0); node *copy(); @@ -251,9 +279,12 @@ public: hyphenation_type get_hyphenation_type(); }; -class diverted_space_node : public node { +class diverted_space_node +: public node +{ public: vunits n; + diverted_space_node(vunits, node * = 0); diverted_space_node(vunits, statem *, int, node * = 0); node *copy(); @@ -264,10 +295,14 @@ public: int is_tag(); }; -class diverted_copy_file_node : public node { +class diverted_copy_file_node +: public node +{ symbol filename; + public: vunits n; + diverted_copy_file_node(symbol, node * = 0); diverted_copy_file_node(symbol, statem *, int, node * = 0); node *copy(); @@ -278,8 +313,11 @@ public: int is_tag(); }; -class extra_size_node : public node { +class extra_size_node +: public node +{ vunits n; + public: extra_size_node(vunits); extra_size_node(vunits, statem *, int); @@ -291,8 +329,11 @@ public: int is_tag(); }; -class vertical_size_node : public node { +class vertical_size_node +: public node +{ vunits n; + public: vertical_size_node(vunits, statem *, int); vertical_size_node(vunits); @@ -306,12 +347,15 @@ public: int is_tag(); }; -class hmotion_node : public node { +class hmotion_node +: public node +{ protected: hunits n; unsigned char was_tab; unsigned char unformat; color *col; /* for grotty */ + public: hmotion_node(hunits i, color *c, node *nxt = 0) : node(nxt), n(i), was_tab(0), unformat(0), col(c) {} @@ -339,7 +383,9 @@ public: hyphenation_type get_hyphenation_type(); }; -class space_char_hmotion_node : public hmotion_node { +class space_char_hmotion_node +: public hmotion_node +{ public: space_char_hmotion_node(hunits, color *, node * = 0); space_char_hmotion_node(hunits, color *, statem *, int, node * = 0); @@ -356,9 +402,12 @@ public: hyphenation_type get_hyphenation_type(); }; -class vmotion_node : public node { +class vmotion_node +: public node +{ vunits n; color *col; /* for grotty */ + public: vmotion_node(vunits, color *); vmotion_node(vunits, color *, statem *, int); @@ -371,9 +420,12 @@ public: int is_tag(); }; -class hline_node : public node { +class hline_node +: public node +{ hunits x; node *n; + public: hline_node(hunits, node *, node * = 0); hline_node(hunits, node *, statem *, int, node * = 0); @@ -387,9 +439,12 @@ public: int is_tag(); }; -class vline_node : public node { +class vline_node +: public node +{ vunits x; node *n; + public: vline_node(vunits, node *, node * = 0); vline_node(vunits, node *, statem *, int, node * = 0); @@ -405,7 +460,9 @@ public: int is_tag(); }; -class dummy_node : public node { +class dummy_node +: public node +{ public: dummy_node(node *nd = 0) : node(nd) {} node *copy(); @@ -416,7 +473,9 @@ public: hyphenation_type get_hyphenation_type(); }; -class transparent_dummy_node : public node { +class transparent_dummy_node +: public node +{ public: transparent_dummy_node(node *nd = 0) : node(nd) {} node *copy(); @@ -428,8 +487,11 @@ public: hyphenation_type get_hyphenation_type(); }; -class zero_width_node : public node { +class zero_width_node +: public node +{ node *n; + public: zero_width_node(node *); zero_width_node(node *, statem *, int); @@ -445,9 +507,12 @@ public: void vertical_extent(vunits *, vunits *); }; -class left_italic_corrected_node : public node { +class left_italic_corrected_node +: public node +{ node *n; hunits x; + public: left_italic_corrected_node(node * = 0); left_italic_corrected_node(statem *, int, node * = 0); @@ -477,9 +542,12 @@ public: node *merge_glyph_node(glyph_node *); }; -class overstrike_node : public node { +class overstrike_node +: public node +{ node *list; hunits max_width; + public: overstrike_node(); overstrike_node(statem *, int); @@ -497,9 +565,12 @@ public: hyphenation_type get_hyphenation_type(); }; -class bracket_node : public node { +class bracket_node +: public node +{ node *list; hunits max_width; + public: bracket_node(); bracket_node(statem *, int); @@ -514,15 +585,19 @@ public: int is_tag(); }; -class special_node : public node { +class special_node +: public node +{ macro mac; tfont *tf; color *gcol; color *fcol; int no_init_string; + void tprint_start(troff_output_file *); void tprint_char(troff_output_file *, unsigned char); void tprint_end(troff_output_file *); + public: special_node(const macro &, int = 0); special_node(const macro &, tfont *, color *, color *, statem *, int, @@ -537,12 +612,17 @@ public: tfont *get_tfont(); }; -class suppress_node : public node { +class suppress_node +: public node +{ int is_on; int emit_limits; // must we issue the extent of the area written out? symbol filename; char position; int image_id; + + void put(troff_output_file *, const char *); + public: suppress_node(int, int); suppress_node(symbol, char, int); @@ -555,14 +635,15 @@ public: const char *type(); int force_tprint(); int is_tag(); -private: - void put(troff_output_file *, const char *); }; -class tag_node : public node { +class tag_node +: public node +{ public: string tag_string; int delayed; + tag_node(); tag_node(string, int); tag_node(string, statem *, int, int); @@ -575,19 +656,25 @@ public: int ends_sentence(); }; -struct hvpair { +class hvpair +{ +public: hunits h; vunits v; + hvpair(); }; -class draw_node : public node { +class draw_node +: public node +{ int npoints; font_size sz; color *gcol; color *fcol; char code; hvpair *point; + public: draw_node(char, hvpair *, int, font_size, color *, color *); draw_node(char, hvpair *, int, font_size, color *, color *, statem *, int); @@ -629,8 +716,10 @@ extern int next_available_font_position(); extern void init_size_table(int *); extern int get_underline_fontno(); -class output_file { +class output_file +{ char make_g_plus_plus_shut_up; + public: output_file(); virtual ~output_file(); @@ -647,7 +736,7 @@ public: virtual void off(); #ifdef COLUMN virtual void vjustify(vunits, symbol); -#endif /* COLUMN */ +#endif mtsm state; }; @@ -659,11 +748,14 @@ extern output_file *the_output; extern void init_output(); int in_output_page_list(int); -class font_family { +class font_family +{ int *map; int map_size; + public: const symbol nm; + font_family(symbol); ~font_family(); int make_definite(int); @@ -674,3 +766,6 @@ font_family *lookup_family(symbol); symbol get_font_name(int, environment *); symbol get_style_name(int); extern search_path include_search_path; + +#endif // _NODE_H +// s-it2-mode diff --git a/src/roff/troff/number.cpp b/src/troff/number.cpp similarity index 92% rename from src/roff/troff/number.cpp rename to src/troff/number.cpp index 0a4563e4..63afb808 100644 --- a/src/roff/troff/number.cpp +++ b/src/troff/number.cpp @@ -1,31 +1,35 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2004 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2001, 2002, 2004 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "troff-config.h" +#include "stringclass.h" -#include "troff.h" +#include "env.h" #include "hvunits.h" -#include "stringclass.h" #include "mtsm.h" -#include "env.h" #include "token.h" +#include "troff.h" #include "div.h" vunits V0; @@ -195,7 +199,6 @@ int get_integer(int *res, int prev_value) return 1; } - static incr_number_result get_incr_number(units *res, unsigned char si) { if (!start_number()) @@ -696,3 +699,5 @@ hunits::hunits(units x) ? -((-x + hresolution/2 - 1)/hresolution) : (x + hresolution/2 - 1)/hresolution); } + +// s-it2-mode diff --git a/src/roff/troff/reg.cpp b/src/troff/reg.cpp similarity index 87% rename from src/roff/troff/reg.cpp rename to src/troff/reg.cpp index 4501090a..ad572753 100644 --- a/src/roff/troff/reg.cpp +++ b/src/troff/reg.cpp @@ -1,31 +1,36 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2004 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000, 2001, 2004 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "troff-config.h" -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include "troff.h" #include "dictionary.h" -#include "token.h" #include "request.h" +#include "token.h" +#include "troff.h" + #include "reg.h" -object_dictionary number_reg_dictionary(101); +object_dictionary number_reg_dictionary(101); // FIXME static init -> init fun! int reg::get_value(units * /*d*/) { @@ -66,14 +71,14 @@ general_reg::general_reg() : format('1'), width(0), inc(0) { } -static char uppercase_array[] = { +static char uppercase_array[] = { // FIXME const 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', }; -static char lowercase_array[] = { +static char lowercase_array[] = { // FIXME const 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', @@ -211,7 +216,6 @@ const char *general_reg::get_string() return number_value_to_ascii(n, format, width); } - void general_reg::increment() { int n; @@ -263,8 +267,11 @@ const char *general_reg::get_format() return number_format_to_ascii(format, width); } -class number_reg : public general_reg { +class number_reg +: public general_reg +{ units value; + public: number_reg(); int get_value(units *); @@ -471,3 +478,5 @@ void init_reg_requests() init_request("rnn", rename_reg); init_request("pnr", print_number_regs); } + +// s-it2-mode diff --git a/src/troff/reg.h b/src/troff/reg.h new file mode 100644 index 00000000..5483b5f7 --- /dev/null +++ b/src/troff/reg.h @@ -0,0 +1,95 @@ +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000, 2001, 2003 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _REG_H +#define _REG_H + +#include "config.h" +#include "troff-config.h" + +class reg +: public object +{ +public: + virtual const char *get_string() = 0; + virtual int get_value(units *); + virtual void increment(); + virtual void decrement(); + virtual void set_increment(units); + virtual void alter_format(char f, int w = 0); + virtual const char *get_format(); + virtual void set_value(units); +}; + +class constant_int_reg +: public reg +{ + int *p; + +public: + constant_int_reg(int *); + const char *get_string(); +}; + +class general_reg +: public reg +{ + char format; + int width; + int inc; + +public: + general_reg(); + const char *get_string(); + void increment(); + void decrement(); + void alter_format(char f, int w = 0); + void set_increment(units); + const char *get_format(); + void add_value(units); + + void set_value(units) = 0; + int get_value(units *) = 0; +}; + +class variable_reg +: public general_reg +{ + units *ptr; + +public: + variable_reg(int *); + void set_value(units); + int get_value(units *); +}; + +extern object_dictionary number_reg_dictionary; +extern void set_number_reg(symbol nm, units n); +extern void check_output_limits(int x, int y); +extern void reset_output_registers(); + +reg *lookup_number_reg(symbol); +#if 0 +void inline_define_reg(); +#endif + +#endif // _REG_H +// s-it2-mode diff --git a/src/roff/troff/request.h b/src/troff/request.h similarity index 57% rename from src/roff/troff/request.h rename to src/troff/request.h index 591b51fa..a56eb758 100644 --- a/src/roff/troff/request.h +++ b/src/troff/request.h @@ -1,37 +1,48 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004, 2008 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2002, 2004, 2008 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _REQUEST_H +#define _REQUEST_H -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "config.h" +#include "troff-config.h" typedef void (*REQUEST_FUNCP)(); class macro; -class request_or_macro : public object { +class request_or_macro +: public object +{ public: request_or_macro(); virtual void invoke(symbol, int) = 0; virtual macro *to_macro(); }; -class request : public request_or_macro { +class request +: public request_or_macro +{ REQUEST_FUNCP p; + public: void invoke(symbol, int); request(REQUEST_FUNCP); @@ -44,15 +55,24 @@ extern object_dictionary request_dictionary; class macro_header; struct node; -class macro : public request_or_macro { +class macro +: public request_or_macro +{ + friend class string_iterator; + friend void chop_macro(); + friend void substring_request(); + friend int operator==(const macro &, const macro &); + const char *filename; // where was it defined? int lineno; int len; int empty_macro; int is_a_diversion; int is_a_string; // if it contains no newline + public: macro_header *p; + macro(); ~macro(); macro(const macro &); @@ -73,10 +93,6 @@ public: int is_diversion(); int is_string(); void clear_string_flag(); - friend class string_iterator; - friend void chop_macro(); - friend void substring_request(); - friend int operator==(const macro &, const macro &); }; extern void init_input_requests(); @@ -92,3 +108,6 @@ class charinfo; class environment; node *charinfo_to_node_list(charinfo *, const environment *); + +#endif // _REQUEST_H +// s-it2-mode diff --git a/src/roff/troff/token.h b/src/troff/token.h similarity index 80% rename from src/roff/troff/token.h rename to src/troff/token.h index 64939760..44e00eee 100644 --- a/src/roff/troff/token.h +++ b/src/troff/token.h @@ -1,30 +1,38 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2002, 2004 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _TOKEN_H +#define _TOKEN_H + +#include "config.h" +#include "troff-config.h" class charinfo; struct node; class vunits; -class token { +class token +{ + friend void process_input_stack(); + symbol nm; node *nd; unsigned char c; @@ -52,7 +60,7 @@ class token { TOKEN_RIGHT_BRACE, TOKEN_SPACE, // ` ' -- ordinary space TOKEN_SPECIAL, // a special character -- \' \` \- \(xx \[xxx] - TOKEN_SPREAD, // \p -- break and spread output line + TOKEN_SPREAD, // \p -- break and spread output line TOKEN_STRETCHABLE_SPACE, // \~ TOKEN_UNSTRETCHABLE_SPACE, // `\ ' TOKEN_TAB, // tab @@ -61,6 +69,7 @@ class token { TOKEN_ZERO_WIDTH_BREAK, // \: TOKEN_EOF // end of file } type; + public: token(); ~token(); @@ -98,8 +107,6 @@ public: void make_space(); void make_newline(); const char *description(); - - friend void process_input_stack(); }; extern token tok; // the current token @@ -137,12 +144,12 @@ void interpolate_number_reg(symbol, int); const char *asciify(int c); inline int token::newline() -{ - return type == TOKEN_NEWLINE; +{ + return type == TOKEN_NEWLINE; } inline int token::space() -{ +{ return type == TOKEN_SPACE; } @@ -157,7 +164,7 @@ inline int token::unstretchable_space() } inline int token::special() -{ +{ return type == TOKEN_SPECIAL; } @@ -187,7 +194,7 @@ inline int token::page_ejector() inline unsigned char token::ch() { return type == TOKEN_CHAR ? c : 0; -} +} inline int token::eof() { @@ -240,3 +247,6 @@ inline int token::zero_width_break() } int has_arg(); + +#endif // _TOKEN_H +// s-it2-mode diff --git a/src/troff/troff-config.h b/src/troff/troff-config.h new file mode 100644 index 00000000..ec4c3e36 --- /dev/null +++ b/src/troff/troff-config.h @@ -0,0 +1,14 @@ +/*@ Configurable stuff */ +#ifndef _TROFF_CONFIG_H +#define _TROFF_CONFIG_H + +#define MACRO_PREFIX "tmac." +#define MACRO_POSTFIX ".tmac" +#define INITIAL_STARTUP_FILE "troffrc" +#define FINAL_STARTUP_FILE "troffrc-end" +#define DEFAULT_INPUT_STACK_LIMIT 1000 + +#define NENVIRONMENTS 10 + +#endif // _TROFF_CONFIG_H +// s-it2-mode diff --git a/src/roff/troff/troff.h b/src/troff/troff.h similarity index 58% rename from src/roff/troff/troff.h rename to src/troff/troff.h index 661b3ed0..ae5e727d 100644 --- a/src/roff/troff/troff.h +++ b/src/troff/troff.h @@ -1,36 +1,44 @@ -// -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004 - Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) - -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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ - - -#include "lib.h" - +/*@ + * Copyright (c) 2014 Steffen (Daode) Nurpmeso . + * + * Copyright (C) 1989 - 1992, 2000 - 2002, 2004 + * Free Software Foundation, Inc. + * Written by James Clark (jjc@jclark.com) + * + * 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _TROFF_H +#define _TROFF_H + +#include "config.h" +#include "troff-config.h" + +#include #include -#include +#include #include #include -#include +#include -#include "assert.h" +#include "cset.h" +#include "cmap.h" #include "color.h" #include "device.h" +#include "errarg.h" +#include "error.h" +#include "lib.h" #include "searchpath.h" typedef int units; @@ -51,11 +59,6 @@ extern int sizescale; extern search_path *mac_path; -#include "cset.h" -#include "cmap.h" -#include "errarg.h" -#include "error.h" - enum warning_type { WARN_CHAR = 01, WARN_NUMBER = 02, @@ -90,3 +93,6 @@ int output_warning(warning_type, const char *, const errarg & = empty_errarg, const errarg & = empty_errarg, const errarg & = empty_errarg); + +#endif // _TROFF_H +// s-it2-mode -- 2.11.4.GIT