[llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/LICENSE Makefile externs.h large.lout large.lout.ld lout.li output_large.ps small.lout z01.c z02.c z03.c z04.c z05.c z06.c z07.c z08.c z09.c z10.c z11.c z12.c z13.c z14.c z15.c z16.c z17.c z18.c z19.c z20.c z21.c z22.c z23.c z24.c z25.c z26.c z27.c z28.c z29.c z30.c z31.c z32.c z33.c z34.c z35.c z36.c z37.c z38.c z39.c z40.c z41.c z42.c z43.c z44.c z45.c z46.c z47.c z48.c z49.c z50.c z51.c
Chris Lattner
sabre at nondot.org
Tue Jan 9 15:45:04 PST 2007
Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset:
LICENSE added (r1.1)
Makefile added (r1.1)
externs.h added (r1.1)
large.lout added (r1.1)
large.lout.ld added (r1.1)
lout.li added (r1.1)
output_large.ps added (r1.1)
small.lout added (r1.1)
z01.c added (r1.1)
z02.c added (r1.1)
z03.c added (r1.1)
z04.c added (r1.1)
z05.c added (r1.1)
z06.c added (r1.1)
z07.c added (r1.1)
z08.c added (r1.1)
z09.c added (r1.1)
z10.c added (r1.1)
z11.c added (r1.1)
z12.c added (r1.1)
z13.c added (r1.1)
z14.c added (r1.1)
z15.c added (r1.1)
z16.c added (r1.1)
z17.c added (r1.1)
z18.c added (r1.1)
z19.c added (r1.1)
z20.c added (r1.1)
z21.c added (r1.1)
z22.c added (r1.1)
z23.c added (r1.1)
z24.c added (r1.1)
z25.c added (r1.1)
z26.c added (r1.1)
z27.c added (r1.1)
z28.c added (r1.1)
z29.c added (r1.1)
z30.c added (r1.1)
z31.c added (r1.1)
z32.c added (r1.1)
z33.c added (r1.1)
z34.c added (r1.1)
z35.c added (r1.1)
z36.c added (r1.1)
z37.c added (r1.1)
z38.c added (r1.1)
z39.c added (r1.1)
z40.c added (r1.1)
z41.c added (r1.1)
z42.c added (r1.1)
z43.c added (r1.1)
z44.c added (r1.1)
z45.c added (r1.1)
z46.c added (r1.1)
z47.c added (r1.1)
z48.c added (r1.1)
z49.c added (r1.1)
z50.c added (r1.1)
z51.c added (r1.1)
---
Log message:
Readd mibench
---
Diffs of the changes: (+43536 -0)
LICENSE | 56
Makefile | 7
externs.h | 3535 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
large.lout | 502 +++++++
large.lout.ld | 238 +++
lout.li | 44
small.lout | 250 +++
z01.c | 859 +++++++++++++
z02.c | 976 +++++++++++++++
z03.c | 906 ++++++++++++++
z04.c | 242 +++
z05.c | 834 +++++++++++++
z06.c | 1553 ++++++++++++++++++++++++
z07.c | 674 ++++++++++
z08.c | 2068 ++++++++++++++++++++++++++++++++
z09.c | 294 ++++
z10.c | 1077 ++++++++++++++++
z11.c | 305 ++++
z12.c | 1372 +++++++++++++++++++++
z13.c | 789 ++++++++++++
z14.c | 910 ++++++++++++++
z15.c | 844 +++++++++++++
z16.c | 635 +++++++++
z17.c | 407 ++++++
z18.c | 504 +++++++
z19.c | 1030 ++++++++++++++++
z20.c | 1044 ++++++++++++++++
z21.c | 522 ++++++++
z22.c | 1253 +++++++++++++++++++
z23.c | 1352 +++++++++++++++++++++
z24.c | 123 +
z25.c | 1028 ++++++++++++++++
z26.c | 318 ++++
z27.c | 212 +++
z28.c | 259 ++++
z29.c | 830 ++++++++++++
z30.c | 192 +++
z31.c | 374 +++++
z32.c | 165 ++
z33.c | 865 +++++++++++++
z34.c | 112 +
z35.c | 151 ++
z36.c | 1225 +++++++++++++++++++
z37.c | 1873 +++++++++++++++++++++++++++++
z38.c | 656 ++++++++++
z39.c | 236 +++
z40.c | 267 ++++
z41.c | 730 +++++++++++
z42.c | 243 +++
z43.c | 402 ++++++
z44.c | 573 ++++++++
z45.c | 238 +++
z46.c | 481 +++++++
z47.c | 250 +++
z48.c | 3712 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
z49.c | 1413 ++++++++++++++++++++++
z50.c | 881 +++++++++++++
z51.c | 645 ++++++++++
58 files changed, 43536 insertions(+)
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/LICENSE
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/LICENSE:1.1
*** /dev/null Tue Jan 9 17:44:45 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/LICENSE Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,56 ----
+ THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24)
+ BASSER LOUT VERSION 3 COPYRIGHT (C) 1994, 2000 Jeffrey H. Kingston
+
+ Jeffrey H. Kingston
+ Basser Department of Computer Science
+ The University of Sydney 2006
+ AUSTRALIA
+
+ Telephone (direct): 61 2 692 4216
+ Telephone (messages): 61 2 692 3423
+ Email: jeff at cs.usyd.edu.au
+ Fax: 61 2 692 3838
+
+ This program 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 1, or (at your option)
+ any later version.
+
+ This program 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
+ (file gnu.gpl in this directory); if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ This directory contains everything needed to install the Lout document
+ formatting system. It contains the following directories:
+
+ data Lout databases (in Lout)
+ doc Lout documentation (in Lout)
+ font Adobe Systems font metrics files
+ hyph Lout hyphenation files (see hyph/README for info)
+ include Lout packages (in Lout)
+ locale Locale-specific error messages
+ man Lout and prg2lout manual entries
+ maps Lout Character Mapping (LCM) files
+ setup Lout setup files (in Lout)
+ software Information about Lout-related software from elsewhere
+
+ and the following files:
+
+ READMEPDF A description of the PDF back end
+ blurb A news blurb describing Lout
+ blurb.short A short news blurb describing Lout
+ prg2lout.c prg2lout source code (all in one file)
+ externs.h z*.c Lout source code
+ gnu.gpl A copy of the GNU General Public License
+ makefile A makefile for installing Lout
+ maillist Information about a public mailing list about Lout
+ notes.dsc Notes on the degree of Lout's conformance with the
+ PostScript Document Structuring Conventions
+ whatsnew A brief informal update on recent changes
+
+ See the makefile for installation instructions.
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,7 ----
+ LEVEL = ../../../..
+
+ PROG = consumer-typeset
+ CPPFLAGS = -DOS_UNIX=1 -DOS_DOS=0 -DOS_MAC=0 -DDB_FIX=0 -DUSE_STAT=1 -DSAFE_DFT=0 -DCOLLATE=1 -DLIB_DIR=\"lout.lib\" -DFONT_DIR=\"font\" -DMAPS_DIR=\"maps\" -DINCL_DIR=\"include\" -DDATA_DIR=\"data\" -DHYPH_DIR=\"hyph\" -DLOCALE_DIR=\"locale\" -DCHAR_IN=1 -DCHAR_OUT=0 -DLOCALE_ON=1 -DASSERT_ON=1 -DDEBUG_ON=0 -DPDF_COMPRESSION=0
+ LDFLAGS = -lm
+ RUN_OPTIONS = -I data/include -D data/data -F data/font -C data/maps -H data/hyph large.lout > output_large.ps
+ include $(LEVEL)/MultiSource/Makefile.multisrc
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,3535 ----
+ /*@externs.h:External Declarations:Directories and file conventions@**********/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: externs.h */
+ /* MODULE: External Declarations */
+ /* */
+ /*****************************************************************************/
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <stdarg.h>
+ #include <locale.h>
+
+ #if LOCALE_ON
+ #include <nl_types.h>
+ extern nl_catd MsgCat;
+ #define condcatgets(cat, set, msg, s) (cat ? catgets(cat, set, msg, s) : s)
+ #else
+ #define condcatgets(cat, set, msg, s) s
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* Include, font and database directories, and the DEBUG_ON and ASSERT_ON */
+ /* flags (defined by -D options on the cc command line in the makefile). */
+ /* */
+ /* LATIN Non-zero means compile for ISO-LATIN-1 char set. */
+ /* LIB_DIR The system directory where library files are kept */
+ /* INCL_DIR The subdirectory of LIB_DIR where @Include files are kept */
+ /* FONT_DIR The subdirectory of LIB_DIR where .AFM font files are kept */
+ /* MAPS_DIR The subdirectory of LIB_DIR where .LCM files are kept */
+ /* DATA_DIR The subdirectory of LIB_DIR where database files are kept */
+ /* HYPH_DIR The subdirectory of LIB_DIR where hyphenation files kept */
+ /* LOCALE_DIR The subdirectory of LIB_DIR where locale files are kept */
+ /* CHAR_IN Determines assignment of input chars to lex classes */
+ /* CHAR_OUT Determines appearance of literal chars in output */
+ /* DEBUG_ON Non-zero means compile debug code (lout -d) */
+ /* ASSERT_ON Non-zero means test assertions */
+ /* LOCALE_ON Non-zero means compile setlocale() etc. code */
+ /* */
+ /* #define LIB_DIR "/usr/local/lib/lout" */
+ /* #define INCL_DIR "include" */
+ /* #define FONT_DIR "font" */
+ /* #define MAPS_DIR "maps" */
+ /* #define DATA_DIR "data" */
+ /* #define HYPH_DIR "hyph" */
+ /* #define LOCALE_DIR "locale" (only used if LOCALE_ON) */
+ /* #define CHAR_IN 0 */
+ /* #define CHAR_OUT 0 */
+ /* #define DEBUG_ON 0 */
+ /* #define ASSERT_ON 1 */
+ /* #define LOCALE_ON 1 */
+ /* */
+ /*****************************************************************************/
+
+
+ /*@::File naming conventions and version@*************************************/
+ /* */
+ /* File naming conventions and version */
+ /* */
+ /* LOUT_VERSION Version information */
+ /* CROSS_DB The default name of the cross reference database */
+ /* SOURCE_SUFFIX Optional suffix of source files and include files */
+ /* INDEX_SUFFIX The suffix of database index files */
+ /* NEW_INDEX_SUFFIX The suffix of new database index files */
+ /* DATA_SUFFIX The suffix of database data files */
+ /* NEW_DATA_SUFFIX The additional suffix of new database data files */
+ /* HYPH_SUFFIX The suffix of unpacked hyphenation files */
+ /* HYPH_PACKED_SUFFIX The suffix of packed hyphenation files */
+ /* FILTER_IN The prefix of the name of the input file to filters */
+ /* FILTER_OUT The prefix of the name of the output file to filters */
+ /* FILTER_ERR The name of the error file to filters */
+ /* */
+ /*****************************************************************************/
+
+ #define LOUT_VERSION AsciiToFull("Basser Lout Version 3.24 (October 2000)")
+ #define CROSS_DB AsciiToFull("lout")
+ #define SOURCE_SUFFIX AsciiToFull(".lt")
+ #define INDEX_SUFFIX AsciiToFull(".li")
+ #define NEW_INDEX_SUFFIX AsciiToFull(".lix")
+ #define DATA_SUFFIX AsciiToFull(".ld")
+ #define NEW_DATA_SUFFIX AsciiToFull("x")
+ #define HYPH_SUFFIX AsciiToFull(".lh")
+ #define HYPH_PACKED_SUFFIX AsciiToFull(".lp")
+ #define FILTER_IN AsciiToFull("louti")
+ #define FILTER_OUT AsciiToFull("lout")
+ #define FILTER_ERR AsciiToFull("lout.err")
+
+
+ /*****************************************************************************/
+ /* */
+ /* Operating system dependent things */
+ /* */
+ /* (1) File read and write modes for binary files, and directory character */
+ /* */
+ /* MS-DOS text file line endings differ from Unix line endings. This is */
+ /* usually ignorable but causes problems with binary files and files where */
+ /* you do arithmetic on fseek() values. In Lout the problematic files are */
+ /* compressed trie and hyphenation files, and database index files. So */
+ /* we must read and write these files in "binary mode" in MS-DOS. For */
+ /* completeness we have included synonyms for all file modes used by Lout: */
+ /* */
+ /* READ_BINARY Mode passed to fopen() when reading a "binary file" */
+ /* WRITE_BINARY Mode passed to fopen() when writing a "binary file" */
+ /* READ_TEXT Mode passed to fopen() when reading a "text file" */
+ /* APPEND_TEXT Mode passed to fopen() when appending to "text file" */
+ /* WRITE_TEXT Mode passed to fopen() when writing a "text file" */
+ /* STR_DIR Directory character used in file path names */
+ /* */
+ /* (2) System command and file name for uncompressing EPS files */
+ /* */
+ /* UNCOMPRESS_COM System command for uncompressing compressed EPS file */
+ /* LOUT_EPS Name of temporary uncompressed EPS file */
+ /* */
+ /* There is one further call to system() in the Lout source code: the one */
+ /* that implements filtered parameters such as prg2lout. The strings */
+ /* passed to this call to system() are the values of @Filter symbols */
+ /* within Lout definitions. */
+ /* */
+ /*****************************************************************************/
+
+ #if OS_UNIX
+ #define READ_BINARY "r"
+ #define WRITE_BINARY "w"
+ #define READ_TEXT "r"
+ #define APPEND_TEXT "a"
+ #define WRITE_TEXT "w"
+ #define STR_DIR AsciiToFull("/")
+ #define UNCOMPRESS_COM "gunzip -c %s > %s"
+ #define LOUT_EPS "lout.eps"
+ #else
+ #if OS_DOS
+ #define READ_BINARY "rb"
+ #define WRITE_BINARY "wb"
+ #define READ_TEXT "rt"
+ #define APPEND_TEXT "at"
+ #define WRITE_TEXT "wt"
+ #define STR_DIR AsciiToFull("/")
+ #define UNCOMPRESS_COM "gunzip -c %s > %s"
+ #define LOUT_EPS "lout.eps"
+ #else
+ #if OS_MAC
+ #define READ_BINARY "r"
+ #define WRITE_BINARY "w"
+ #define READ_TEXT "r"
+ #define APPEND_TEXT "a"
+ #define WRITE_TEXT "w"
+ #define STR_DIR AsciiToFull(":")
+ #define UNCOMPRESS_COM "gunzip -c %s > %s"
+ #define LOUT_EPS "lout.eps"
+ #else
+ If you're compiling this, you've got the wrong settings in the makefile!
+ #endif
+ #endif
+ #endif
+
+ /*@::Significant limits@******************************************************/
+ /* */
+ /* Significant Limits (other insignificant ones appear in other files) */
+ /* */
+ /* MAX_FULL_LENGTH The maximum value storable in type FULL_LENGTH. */
+ /* NB this cannot be 2**31 - 1 because there are */
+ /* intermediate results that exceed MAX_FULL_LENGTH */
+ /* and are subsequently reduced to MAX_FULL_LENGTH. */
+ /* For example, some intermediate results may exceed */
+ /* MAX_FULL_LENGTH by a factor of SF, which is defined */
+ /* below to be 128 (2**7). The value given is 2**23-1, */
+ /* which is about 148 metres in Lout's precision. */
+ /* */
+ /* MAX_SHORT_LENGTH The maximum value storable in type SHORT_LENGTH. */
+ /* */
+ /* MAX_FILES The maximum number of files. This could only be */
+ /* increased if the file_num() field of type FILE_POS */
+ /* is enlarged beyond its present 16 bits. */
+ /* */
+ /* MAX_LINE 1 + the maximum length of an input line in source */
+ /* and database files. This is used for the lexical */
+ /* analyser's input line buffer only, and could be */
+ /* increased immediately to 4096, and even further if */
+ /* more than the current 12 bits was assigned to the */
+ /* col_num() field of type FILE_POS. */
+ /* */
+ /* MAX_WORD 1 + the maximum length of a word storable in an */
+ /* object record, which includes all file path names */
+ /* too. It is reasonable to make this MAX_LINE, since */
+ /* a word longer than MAX_LINE cannot be read in. */
+ /* */
+ /* MAX_OBJECT_REC 1 + the maximum size of an object record, measured */
+ /* in ALIGNs. The value chosen should exceed */
+ /* ceiling( (wr + MAX_WORD - 4) / sizeof(ALIGN) ) */
+ /* where wr = sizeof(struct word_rec), so that words of */
+ /* length MAX_WORD-1 can be stored in an object record. */
+ /* */
+ /* MAX_BUFF 1 + the maximum length of a "standard buffer"; these */
+ /* buffers are used in a variety of places throughout */
+ /* the program for holding one line of a font file, */
+ /* one file path name, one symbol full name, etc. This */
+ /* may be increased immediately without limit. */
+ /* */
+ /* MAX_FONT The maximum number of sized fonts allowed. This */
+ /* can be increased beyond 4096 only by setting aside */
+ /* a larger word_font() field. */
+ /* */
+ /* MAX_COLOUR The maximum number of distinct left parameters of */
+ /* @SetColour and @SetColor symbols allowed (after */
+ /* evaluation). This can be increased beyond 1024 */
+ /* only by setting aside a larger word_colour() field. */
+ /* */
+ /* MAX_LANGUAGE The maximum number of distinct languages allowed. */
+ /* This can be increased beyond 256 only by setting */
+ /* aside a larger word_language() field. */
+ /* */
+ /* MAX_LEX_STACK The maximum depth of @Includes and @Databases. This */
+ /* can be increased immediately by any small amount. */
+ /* */
+ /* MAX_CHARS The maximimum number of characters in a font. This */
+ /* cannot be increased easily. */
+ /* */
+ /*****************************************************************************/
+
+ #define MAX_FULL_LENGTH 8388607 /* 2**23 - 1, about 148 metres */
+ #define MAX_SHORT_LENGTH 32767
+ #define MAX_FILES 65535
+ #define MAX_LINE 2048
+ #define MAX_WORD 2048
+ #define MAX_OBJECT_REC ceiling(sizeof(struct word_type)+MAX_WORD,sizeof(ALIGN))
+ #define MAX_BUFF 512
+ #define MAX_FONT 4096
+ #define MAX_COLOUR 4096
+ #define MAX_LANGUAGE 64
+ #define MAX_LEX_STACK 10
+ #define MAX_CHARS 256
+
+ /*****************************************************************************/
+ /* */
+ /* Miscellaneous Macros */
+ /* */
+ /*****************************************************************************/
+
+ #define BOOLEAN unsigned
+ #define FALSE 0
+ #define TRUE 1
+ #define bool(x) (x ? AsciiToFull("TRUE") : AsciiToFull("FALSE") )
+ #define CHILD 0
+ #define PARENT 1
+ #define COLM 0
+ #define ROWM 1
+ #define dimen(x) (x == COLM ? AsciiToFull("COLM") : AsciiToFull("ROWM") )
+ #define nilobj ( (OBJECT) NULL )
+ #define null ( (FILE *) NULL )
+
+ #define find_max(a, b) ((a) < (b) ? (b) : (a))
+ #define find_min(a, b) ((a) < (b) ? (a) : (b))
+ #define ceiling(a, b) ( ((a) - 1)/(b) + 1 ) /* ceiling(a/b) */
+ #define is_odd(x) ( (x) & 1 ) /* TRUE if x is odd number */
+
+ /*@::ALIGN, FULL_LENGTH, FONT_NUM, COLOUR_NUM, LANGUAGE_NUM, FULL_CHAR@*******/
+ /* */
+ /* typedef ALIGN - used for forcing record alignment. */
+ /* */
+ /*****************************************************************************/
+
+ typedef char *ALIGN;
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef FULL_LENGTH - an integer physical distance. */
+ /* */
+ /*****************************************************************************/
+
+ typedef int FULL_LENGTH;
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef SHORT_LENGTH - an short integer physical distance. */
+ /* */
+ /*****************************************************************************/
+
+ typedef short int SHORT_LENGTH;
+
+
+ /*****************************************************************************/
+ /* */
+ /* FONT_NUM - internal name for a font. */
+ /* */
+ /*****************************************************************************/
+
+ typedef unsigned FONT_NUM;
+
+
+ /*****************************************************************************/
+ /* */
+ /* COLOUR_NUM - internal name for a colour. */
+ /* */
+ /*****************************************************************************/
+
+ typedef unsigned COLOUR_NUM;
+
+
+ /*****************************************************************************/
+ /* */
+ /* LANGUAGE_NUM - internal name for a language. */
+ /* */
+ /*****************************************************************************/
+
+ typedef unsigned LANGUAGE_NUM;
+
+
+ /*****************************************************************************/
+ /* */
+ /* MAPPING - internal name for a character mapping vector. */
+ /* */
+ /*****************************************************************************/
+
+ typedef unsigned MAPPING;
+
+
+ /*****************************************************************************/
+ /* */
+ /* LINE - a line from a database index file. */
+ /* */
+ /*****************************************************************************/
+
+ typedef char *LINE;
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef FULL_CHAR - one of the characters manipulated by Lout. */
+ /* */
+ /* This program does not deal with 7-bit ASCII characters. Instead, its */
+ /* characters are defined by the FULL_CHAR typedef, and could be anything */
+ /* from 7-bit ASCII to 8-bit ISO-LATIN-1 to 16-bit UNICODE and beyond. */
+ /* */
+ /* Unfortunately C favours signed 8-bit characters: literal strings are */
+ /* pointers to them, argv[] and the standard libraries assume them. We get */
+ /* around these problems by using our own library, including AsciiToFull() */
+ /* to convert an ASCII string (such as a C string) into a FULL_CHAR string. */
+ /* */
+ /* Formally this library appears in module z39.c; however since this */
+ /* implementation uses 8-bit unsigned characters, most of the routines */
+ /* can be implemented by macros containing type-cast calls to C standard */
+ /* library routines. These appear in the z39.c externs list below. */
+ /* */
+ /*****************************************************************************/
+
+ typedef unsigned char FULL_CHAR;
+
+ /*****************************************************************************/
+ /* */
+ /* typedef POINTER- name for type of generic pointer */
+ /* */
+ /*****************************************************************************/
+
+ typedef void *POINTER;
+
+ /*@::Character literals@******************************************************/
+ /* */
+ /* Character Literals */
+ /* */
+ /* The following macros ensure that no Lout source is ever compared to a */
+ /* literal character other than '\0': */
+ /* */
+ /*****************************************************************************/
+
+ #define CH_FLAG_ALTERR 'a' /* the -a command line flag */
+ #define CH_FLAG_CROSS 'c' /* the -c command line flag */
+ #define CH_FLAG_ENCPATH 'C' /* the -C command line flag */
+ #define CH_FLAG_DEBUG 'd' /* the -d command line flag */
+ #define CH_FLAG_DIRPATH 'D' /* the -D command line flag */
+ #define CH_FLAG_ERRFILE 'e' /* the -e command line flag */
+ #define CH_FLAG_EPSFIRST 'E' /* first letter of the -EPS flag */
+ #define CH_FLAG_FNTPATH 'F' /* the -F command line flag */
+ #define CH_FLAG_HYPHEN 'h' /* the -h command line flag */
+ #define CH_FLAG_HYPPATH 'H' /* the -H command line flag */
+ #define CH_FLAG_INCLUDE 'i' /* the -i command line flag */
+ #define CH_FLAG_INCPATH 'I' /* the -I command line flag */
+ #define CH_FLAG_NOKERN 'k' /* the -k command line flag */
+ #define CH_FLAG_NOCOLLATE 'l' /* the -l command line flag */
+ #define CH_FLAG_COLLATE 'L' /* the -L command line flag */
+ #define CH_FLAG_MEMCHECK 'm' /* the -m command line flag */
+ #define CH_FLAG_MEMCR 'M' /* the -M command line flag */
+ #define CH_FLAG_OUTFILE 'o' /* the -o command line flag */
+ #define CH_FLAG_PLAIN 'p' /* the -p command line flag */
+ #define CH_FLAG_FFPLAIN 'P' /* the -P command line flag */
+ #define CH_FLAG_SUPPRESS 's' /* the -s command line flag */
+ #define CH_FLAG_SAFE 'S' /* the -S command line flag */
+ #define CH_FLAG_USAGE 'u' /* the -u command line flag */
+ #define CH_FLAG_UNSAFE 'U' /* the -U command line flag */
+ #define CH_FLAG_VERSION 'V' /* the -V command line flag */
+ #define CH_FLAG_INITALL 'x' /* the -x command line flag */
+ #define CH_FLAG_OPTION '-' /* the -- command line flag */
+ #define CH_FLAG_WORDS 'w' /* the -w command line flag */
+ #define CH_FLAG_PDF 'Z' /* the -Z command line flag */
+
+ #define CH_SPACE ' ' /* space character */
+ #define CH_NEWLINE '\n' /* the newline character */
+ #define CH_SYMSTART '@' /* extra letter symbols may have */
+ #define CH_UNDERSCORE '_' /* extra letter symbols may have */
+ #define CH_QUOTE '"' /* the quote character */
+ #define CH_ZERO '0' /* the first digit character, zero */
+ #define CH_EIGHT '8' /* the last even digit character */
+ #define CH_NINE '9' /* the last odd digit character */
+ #define CH_INCGAP '+' /* begins an incrementing gap */
+ #define CH_DECGAP '-' /* begins a decrementing gap */
+ #define CH_MINUS '-' /* minus sign */
+ #define CH_HYPHEN '-' /* the hyphen character */
+ #define CH_NOBREAK 'u' /* `unbreakable' character for gaps */
+
+ #define CH_UNIT_CM 'c' /* unit of measurement: centimetres */
+ #define CH_UNIT_IN 'i' /* unit of measurement: inches */
+ #define CH_UNIT_PT 'p' /* unit of measurement: points */
+ #define CH_UNIT_EM 'm' /* unit of measurement: ems */
+ #define CH_UNIT_FT 'f' /* unit of measurement: fontsizes */
+ #define CH_UNIT_SP 's' /* unit of measurement: spacewidths */
+ #define CH_UNIT_VS 'v' /* unit of measurement: vspaces */
+ #define CH_UNIT_WD 'w' /* unit of measurement: follwidths */
+ #define CH_UNIT_BD 'b' /* unit of measurement: boundwidths */
+ #define CH_UNIT_RL 'r' /* unit of measurement: relwidths */
+ #define CH_UNIT_DG 'd' /* unit of measurement: degrees */
+ #define CH_UNIT_YU 'y' /* unit of measurement: y unit */
+ #define CH_UNIT_ZU 'z' /* unit of measurement: z unit */
+
+ #define CH_MODE_EDGE 'e' /* spacing mode: edge-to-edge */
+ #define CH_MODE_HYPH 'h' /* spacing mode: hyphenation */
+ #define CH_MODE_MARK 'x' /* spacing mode: mark-to-mark */
+ #define CH_MODE_OVER 'o' /* spacing mode: overstrike */
+ #define CH_MODE_KERN 'k' /* spacing mode: kerning */
+ #define CH_MODE_TABL 't' /* spacing mode: tabulation */
+
+ #define octaldigit(ch) ( (ch) >= '0' && (ch) <= '7' )
+ #define decimaldigit(ch) ( (ch) >= '0' && (ch) <= '9' )
+ #define digitchartonum(ch) ( (ch) - '0' )
+ #define numtodigitchar(ch) ( (ch) + '0' )
+ #define beginsbreakstyle(ch) ( (ch) >= 'a' && (ch) <= 'z' )
+ #define numericchar(ch) ( decimaldigit(ch) || (ch) == '.' )
+
+
+ /*@::String literals, FULL_CHAR type@*****************************************/
+ /* */
+ /* String Literals. */
+ /* */
+ /* All significant string literals are defined here. The program has many */
+ /* others, however: format strings, debug output, etc. */
+ /* */
+ /*****************************************************************************/
+
+ #define STR_EMPTY AsciiToFull("")
+ #define STR_QUOTE AsciiToFull("\"")
+ #define STR_ESCAPE AsciiToFull("\\")
+ #define STR_COMMENT AsciiToFull("#")
+ #define STR_SPACE AsciiToFull(" ")
+ #define STR_FORMFEED AsciiToFull("\f")
+ #define STR_TAB AsciiToFull("\t")
+ #define STR_NEWLINE AsciiToFull("\n")
+ #define STR_LETTERS_LOWER AsciiToFull("abcdefghijklmnopqrstuvwxyz")
+ #define STR_LETTERS_UPPER AsciiToFull("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+ #define STR_LETTERS_SYMSTART AsciiToFull("@")
+ #define STR_LETTERS_UNDERSCORE AsciiToFull("_")
+
+ #if CHAR_IN==0
+ #define STR_LETTERS_EXTRA0 AsciiToFull("")
+ #define STR_LETTERS_EXTRA1 AsciiToFull("")
+ #define STR_LETTERS_EXTRA2 AsciiToFull("")
+ #define STR_LETTERS_EXTRA3 AsciiToFull("")
+ #define STR_LETTERS_EXTRA4 AsciiToFull("")
+ #define STR_LETTERS_EXTRA5 AsciiToFull("")
+ #define STR_LETTERS_EXTRA6 AsciiToFull("")
+ #define STR_LETTERS_EXTRA7 AsciiToFull("")
+ #else
+ #define STR_LETTERS_EXTRA0 AsciiToFull("\300\301\302\303\304\305\306\307")
+ #define STR_LETTERS_EXTRA1 AsciiToFull("\310\311\312\313\314\315\316\317")
+ #define STR_LETTERS_EXTRA2 AsciiToFull("\320\321\322\323\324\325\326")
+ #define STR_LETTERS_EXTRA3 AsciiToFull("\330\331\332\333\334\335\336\337")
+ #define STR_LETTERS_EXTRA4 AsciiToFull("\340\341\342\343\344\345\346\347")
+ #define STR_LETTERS_EXTRA5 AsciiToFull("\350\351\352\353\354\355\356\357")
+ #define STR_LETTERS_EXTRA6 AsciiToFull("\360\361\362\363\364\365\366")
+ #define STR_LETTERS_EXTRA7 AsciiToFull("\370\371\372\373\374\375\376\377")
+ #endif
+
+ #define STR_STDIN AsciiToFull("-")
+ #define STR_STDOUT AsciiToFull("-")
+ #define STR_HYPHEN AsciiToFull("-")
+ #define STR_EPS AsciiToFull("EPS")
+ #define STR_POSTSCRIPT AsciiToFull("PostScript")
+ #define STR_PLAINTEXT AsciiToFull("PlainText")
+ #define STR_PDF AsciiToFull("PDF")
+ #define STR_ELSE AsciiToFull("else")
+ #define STR_NOCROSS AsciiToFull("??")
+ #define STR_BADKEY AsciiToFull("badkey")
+ #define STR_NONE AsciiToFull("none")
+ #define STR_NOCHAR AsciiToFull("-none-")
+ #define STR_ZERO AsciiToFull("0")
+ #define STR_PS_SPACENAME AsciiToFull("space")
+ #define STR_FONT_RECODE AsciiToFull("Recode")
+ #define STR_FONT_NORECODE AsciiToFull("NoRecode")
+ #define STR_COLOUR_NOCHANGE AsciiToFull("nochange")
+
+ #define STR_BREAK_HYPHEN AsciiToFull("hyphen")
+ #define STR_BREAK_NOHYPHEN AsciiToFull("nohyphen")
+ #define STR_BREAK_ADJUST AsciiToFull("adjust")
+ #define STR_BREAK_OUTDENT AsciiToFull("outdent")
+ #define STR_BREAK_RAGGED AsciiToFull("ragged")
+ #define STR_BREAK_CRAGGED AsciiToFull("cragged")
+ #define STR_BREAK_RRAGGED AsciiToFull("rragged")
+ #define STR_BREAK_ORAGGED AsciiToFull("oragged")
+ #define STR_BREAK_LINES AsciiToFull("lines")
+ #define STR_BREAK_CLINES AsciiToFull("clines")
+ #define STR_BREAK_RLINES AsciiToFull("rlines")
+ #define STR_BREAK_NOFIRST AsciiToFull("unbreakablefirst")
+ #define STR_BREAK_FIRST AsciiToFull("breakablefirst")
+ #define STR_BREAK_NOLAST AsciiToFull("unbreakablelast")
+ #define STR_BREAK_LAST AsciiToFull("breakablelast")
+
+ #define STR_SPACE_LOUT AsciiToFull("lout")
+ #define STR_SPACE_COMPRESS AsciiToFull("compress")
+ #define STR_SPACE_SEPARATE AsciiToFull("separate")
+ #define STR_SPACE_TROFF AsciiToFull("troff")
+ #define STR_SPACE_TEX AsciiToFull("tex")
+
+ #define STR_SMALL_CAPS_ON AsciiToFull("smallcaps")
+ #define STR_SMALL_CAPS_OFF AsciiToFull("nosmallcaps")
+
+ #define STR_GAP_RJUSTIFY AsciiToFull("1rt")
+ #define STR_GAP_ZERO_HYPH AsciiToFull("0ch")
+
+
+ /*@::GAP, STYLE@**************************************************************/
+ /* */
+ /* typedef GAP - what separates one object from another. */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { unsigned ospare : 7; /* left for other things in STYLE */
+ BOOLEAN onobreak : 1; /* TRUE if this gap is unbreakable */
+ BOOLEAN omark : 1; /* TRUE if this gap is marked */
+ BOOLEAN ojoin : 1; /* TRUE if joins exist across gap */
+ unsigned ounits : 3; /* units of measurement: fixed, etc */
+ unsigned omode : 3; /* spacing mode: edge-to-edge, etc */
+ SHORT_LENGTH owidth; /* width of the gap */
+ } GAP;
+
+ #define nobreak(x) (x).onobreak
+ #define mark(x) (x).omark
+ #define join(x) (x).ojoin
+ #define units(x) (x).ounits
+ #define mode(x) (x).omode
+ #define width(x) (x).owidth
+
+ #define SetGap(x, xnobreak, xmark, xjoin, xunits, xmode, xwidth) \
+ ( nobreak(x) = xnobreak, mark(x) = xmark, join(x) = xjoin, \
+ units(x) = xunits, mode(x) = xmode, width(x) = xwidth \
+ )
+
+ #define GapCopy(x, y) \
+ ( nobreak(x) = nobreak(y), mark(x) = mark(y), join(x) = join(y), \
+ units(x) = units(y), mode(x) = mode(y), width(x) = width(y) \
+ )
+
+ #define ClearGap(x) SetGap(x, FALSE, FALSE, TRUE, FIXED_UNIT, NO_MODE, 0)
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef STYLE - information about how to break text, etc. */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { union {
+ GAP oline_gap; /* separation between lines */
+ struct {
+ BOOLEAN ovadjust : 1; /* @VAdjust in effect */
+ BOOLEAN ohadjust : 1; /* @HAdjust in effect */
+ BOOLEAN opadjust : 1; /* @PAdjust in effect */
+ unsigned osmall_caps : 1; /* small capitals */
+ unsigned ospace_style : 3; /* space style: lout, troff, tex, .. */
+ } oss1;
+ } osu1;
+ union {
+ GAP ospace_gap; /* separation induced by white space */
+ struct {
+ unsigned ohyph_style : 2; /* hyphenation off or on */
+ unsigned ofill_style : 2; /* fill lines with text off/on */
+ unsigned odisplay_style : 3; /* display lines adjusted, ragged... */
+ } oss2;
+ } osu2;
+ SHORT_LENGTH oyunit; /* value of y unit of measurement */
+ SHORT_LENGTH ozunit; /* value of z unit of measurement */
+ FONT_NUM ofont : 12; /* current font */
+ COLOUR_NUM ocolour : 10; /* current colour */
+ BOOLEAN ooutline : 2; /* TRUE if outlining words */
+ LANGUAGE_NUM olanguage : 6; /* current language */
+ BOOLEAN onobreakfirst : 1; /* no break after first line of para */
+ BOOLEAN onobreaklast : 1; /* no break after last line of para */
+ } STYLE;
+
+ #define line_gap(x) (x).osu1.oline_gap
+ #define vadjust(x) (x).osu1.oss1.ovadjust
+ #define hadjust(x) (x).osu1.oss1.ohadjust
+ #define padjust(x) (x).osu1.oss1.opadjust
+ #define small_caps(x) (x).osu1.oss1.osmall_caps
+ #define space_style(x) (x).osu1.oss1.ospace_style
+ #define space_gap(x) (x).osu2.ospace_gap
+ #define hyph_style(x) (x).osu2.oss2.ohyph_style
+ #define fill_style(x) (x).osu2.oss2.ofill_style
+ #define display_style(x)(x).osu2.oss2.odisplay_style
+ #define font(x) (x).ofont
+ #define colour(x) (x).ocolour
+ #define outline(x) (x).ooutline
+ #define language(x) (x).olanguage
+ #define nobreakfirst(x) (x).onobreaklast
+ #define nobreaklast(x) (x).onobreakfirst
+ #define yunit(x) (x).oyunit
+ #define zunit(x) (x).ozunit
+
+ #define StyleCopy(x, y) \
+ ( GapCopy(line_gap(x), line_gap(y)), \
+ hyph_style(x) = hyph_style(y), \
+ fill_style(x) = fill_style(y), \
+ display_style(x) = display_style(y), \
+ small_caps(x) = small_caps(y), \
+ GapCopy(space_gap(x), space_gap(y)), \
+ font(x) = font(y), \
+ colour(x) = colour(y), \
+ outline(x) = outline(y), \
+ language(x) = language(y), \
+ nobreakfirst(x) = nobreakfirst(y), \
+ nobreaklast(x) = nobreaklast(y), \
+ vadjust(x) = vadjust(y), \
+ hadjust(x) = hadjust(y), \
+ padjust(x) = padjust(y), \
+ space_style(x) = space_style(y), \
+ yunit(x) = yunit(y), \
+ zunit(x) = zunit(y) \
+ )
+
+
+ /*@::CONSTRAINT, FILE_NUM, FILE_POS, LIST@************************************/
+ /* */
+ /* typedef CONSTRAINT - a size constraint. */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { FULL_LENGTH obc;
+ FULL_LENGTH obfc;
+ FULL_LENGTH ofc;
+ FULL_LENGTH osparec;
+ } CONSTRAINT;
+
+ #define bc(x) (x).obc
+ #define bfc(x) (x).obfc
+ #define fc(x) (x).ofc
+ #define sparec(x) (x).osparec
+ #define constrained(x) (bc(x) != MAX_FULL_LENGTH || \
+ bfc(x) != MAX_FULL_LENGTH || fc(x) != MAX_FULL_LENGTH)
+
+ #define SetConstraint(c,x,y,z) (bc(c) = (x), bfc(c) = (y), fc(c) = (z))
+ #define CopyConstraint(x, y) (bc(x) = bc(y), bfc(x) = bfc(y), fc(x) = fc(y))
+ #define FitsConstraint(b, f, c) (b <= bc(c) && b + f <= bfc(c) && f <= fc(c))
+
+ #define ig_fnum(x) bc(constraint(x))
+ #define ig_xtrans(x) bfc(constraint(x))
+ #define ig_ytrans(x) fc(constraint(x))
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef FILE_NUM - the internal representation of a file. */
+ /* */
+ /*****************************************************************************/
+
+ typedef unsigned short FILE_NUM;
+ #define NO_FILE 0
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef FILE_POS - a position in the set of input files. */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { unsigned char otype; /* space for object type field */
+ unsigned char orec_size; /* space for object record size */
+ FILE_NUM ofile_num; /* no. of file this record is from */
+ unsigned oline_num : 20; /* the line number of this record */
+ unsigned ocol_num : 12; /* column number this is related to */
+ } FILE_POS;
+
+ #define file_num(x) (x).ofile_num
+ #define col_num(x) (x).ocol_num
+ #define line_num(x) (x).oline_num
+
+ #define FposCopy(x, y) \
+ ( file_num(x) = file_num(y), \
+ line_num(x) = line_num(y), \
+ col_num(x) = col_num(y) \
+ )
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef LIST - two pointers used to make one doubly linked list */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct { union rec *opred, *osucc; } LIST;
+
+
+ /*@::FIRST_UNION@*************************************************************/
+ /* */
+ /* typedef FIRST_UNION - first eight bytes of object record (after LISTs). */
+ /* */
+ /* The fpos is overwritten in WORDs and QWORDs during FixAndPrintObject by */
+ /* the horizontal coordinate of the word, which has to be remembered. */
+ /* */
+ /*****************************************************************************/
+
+ typedef union
+ {
+ FILE_POS ofpos;
+ struct
+ { unsigned char otype, orec_size;
+ int oword_save_mark;
+ } os11;
+
+ } FIRST_UNION;
+
+
+ /*@::SECOND_UNION, THIRD_UNION, FOURTH_UNION@*********************************/
+ /* */
+ /* typedef SECOND_UNION - four bytes holding various flags etc. */
+ /* */
+ /*****************************************************************************/
+
+ typedef union
+ {
+ struct /* used by all tokens */
+ { unsigned char oprecedence;
+ unsigned char ohspace, ovspace;
+ } os21;
+
+ struct /* used by WORD objects only, except underline used by all */
+ /* objects, including GAP_OBJ */
+ { FONT_NUM oword_font : 12;
+ COLOUR_NUM oword_colour : 10;
+ BOOLEAN oword_outline : 1;
+ LANGUAGE_NUM oword_language : 6;
+ unsigned ounderline : 2;
+ unsigned oword_hyph : 1;
+ } os22;
+
+ struct /* used by non-WORD objects */
+ { unsigned char ofoll_or_prec;
+ unsigned char ocross_type; /* CROSS objects only */
+ BOOLEAN onon_blocking: 1;
+ BOOLEAN osized : 1;
+ BOOLEAN othreaded : 1;
+ BOOLEAN oexternal_hor: 1;
+ BOOLEAN oexternal_ver: 1;
+ BOOLEAN oblocked : 1;
+ BOOLEAN otrigger_ext : 1;
+ BOOLEAN omust_expand : 1;
+ BOOLEAN ogall_dir : 1;
+ BOOLEAN oopt_hyph : 1;
+ BOOLEAN oopt_gazumped: 1;
+ BOOLEAN oadjust_cat : 1;
+ BOOLEAN oforce_gall : 1;
+ unsigned ounderline : 2;
+ /* don't forget ounderline from os22 applies in this union! */
+ } os23;
+
+ struct /* used by WORD and QWORD when they are database nodes */
+ { unsigned short oleft_pos;
+ unsigned char oreading;
+ unsigned char oin_memory;
+ } os24;
+
+ struct /* used by WORD and QWORD when they are font records */
+ { FONT_NUM ofont_num : 12;
+ unsigned short ofont_page;
+ } os25;
+
+ struct /* used by symbol table entries */
+ { unsigned char oprecedence;
+ BOOLEAN ois_tag : 1;
+ BOOLEAN ohas_tag : 1;
+ BOOLEAN ohas_lpar : 1;
+ BOOLEAN ohas_rpar : 1;
+ BOOLEAN oright_assoc : 1;
+ BOOLEAN ois_target : 1;
+ BOOLEAN ohas_target : 1;
+ BOOLEAN oforce_target : 1;
+ BOOLEAN ohas_body : 1;
+ BOOLEAN oindefinite : 1;
+ BOOLEAN orecursive : 1;
+ BOOLEAN ouses_extern_target : 1;
+ BOOLEAN ois_extern_target : 1;
+ BOOLEAN ois_key : 1;
+ BOOLEAN ohas_key : 1;
+ BOOLEAN odirty : 1;
+ BOOLEAN ovisible : 1;
+ BOOLEAN ohas_mark : 1;
+ BOOLEAN ohas_join : 1;
+ BOOLEAN ohas_par : 1;
+ BOOLEAN ouses_galley : 1;
+ BOOLEAN ohoriz_galley : 1;
+ BOOLEAN oimports_encl : 1;
+ } os26;
+
+ } SECOND_UNION;
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef THIRD_UNION - eight bytes usually holding an object size. */
+ /* */
+ /* In database records this space is used for a file pointer, or a pointer */
+ /* to a LINE array if the database is in-memory; in certain */
+ /* WORD objects used privately in z10.c it is used for a galley-position. */
+ /* In font records it holds the font size, space width, etc. In filter */
+ /* words it holds a pointer to the symbol being filtered. */
+ /* */
+ /*****************************************************************************/
+
+ typedef union
+ {
+ struct
+ { FULL_LENGTH oback[2];
+ FULL_LENGTH ofwd[2];
+ } os31;
+
+ FILE *odb_filep;
+ LINE *odb_lines;
+
+ struct
+ { FULL_LENGTH ofont_size;
+ FULL_LENGTH ofont_xheight2;
+ FULL_LENGTH ofont_spacewidth;
+ MAPPING ofont_mapping : 7;
+ BOOLEAN ofont_recoded : 1;
+ } os32;
+
+ struct
+ { unsigned char ocs_type;
+ FILE_NUM ocs_fnum;
+ int ocs_pos;
+ int ocs_lnum;
+ } os33;
+
+ union rec *ofilter_actual;
+
+ } THIRD_UNION;
+
+
+ /*****************************************************************************/
+ /* */
+ /* typedef FOURTH_UNION - twelve bytes holding a STYLE or CONSTRAINT. */
+ /* */
+ /*****************************************************************************/
+
+ typedef union
+ {
+ STYLE osave_style;
+ CONSTRAINT oconstraint;
+
+ } FOURTH_UNION;
+
+
+ /*@::OBJECT@******************************************************************/
+ /* */
+ /* typedef OBJECT - the general-purpose record used throughout Lout. */
+ /* */
+ /* This record is a complex union type. Which fields are defined in any */
+ /* given record depends on its type() tag field, as follows. But first */
+ /* we define some collections of fields that are commonly defined together. */
+ /* */
+ /* ALL - these fields are defined in all objects. They won't be mentioned */
+ /* again, but they are always there. */
+ /* */
+ /* type Tag field for the record */
+ /* rec_size Size of this record, in words (for memory allocator) */
+ /* succ Next element on list of parents, children */
+ /* pred Previous element on list of parents, children */
+ /* fpos Position in input file which gave rise to this */
+ /* object (could be null; overwritten by word_save_mark */
+ /* locally in FixAndPrintOjbect). It sub-fields are: */
+ /* */
+ /* file_num internal file number */
+ /* line_num line number in that file */
+ /* col_num column number on that line */
+ /* */
+ /* Lout attempts to put a meaningful fpos into every */
+ /* object, so that error messages related to that */
+ /* object can have meaningful line numbers. This has */
+ /* not been done in every case; it ought to be. */
+ /* */
+ /* TOKEN - these fields are defined for all objects that are input tokens. */
+ /* They may be overwritten after parsing is completed. */
+ /* */
+ /* precedence Precedence of this token (0 if has no parameters) */
+ /* hspace Horizontal space preceding this token */
+ /* vspace Vertical space preceding this token */
+ /* */
+ /* SIZED - these fields are defined for all objects that represent Lout */
+ /* objects and hence have a horizontal and vertical size. They */
+ /* will be undefined until after MinSize() is called on the object, */
+ /* and defined thereafter. */
+ /* */
+ /* back[COLM] Horizontal size to left of object's mark */
+ /* fwd[COLM] Horizontal size to right of object's mark */
+ /* back[ROWM] Vertical size above object's mark */
+ /* fwd[ROWM] Vertical size below object's mark */
+ /* */
+ /* GAP - a gap between two Lout objects. */
+ /* */
+ /* nobreak TRUE if gap is unbreakable (has u tag) */
+ /* mark TRUE if gap is marked (has ^ tag) */
+ /* join TRUE if a mark-joining gap (e.g. | not ||) */
+ /* units units of measurement (fixed, or r or d etc) */
+ /* mode gap mode (mark-to-mark, etc.) */
+ /* width width of gap in the given units */
+ /* */
+ /* STYLE - the style (attributes affecting the appearance) of an object. */
+ /* */
+ /* line_gap How much to separate lines by */
+ /* vadjust TRUE when @VAdjust is in effect */
+ /* hadjust TRUE when @HAdjust is in effect */
+ /* padjust TRUE when @PAdjust is in effect */
+ /* small_caps TRUE when small capitals wanted */
+ /* space_style Spacing style (lout, troff etc. from @Space) */
+ /* space_gap Object separation given a white space, i.e. "1s" */
+ /* hyph_style Hyphenation (undefined, off, on) */
+ /* fill_style Fill lines (undefined, off, on) */
+ /* display_style Display style for lines (adjust, centre, etc.) */
+ /* yunit Value of y unit of measurement */
+ /* zunit Value of z unit of measurement */
+ /* font Which internal font (including size) to use */
+ /* colour Which internal colour to use */
+ /* outline TRUE if outlining words rather than filling them */
+ /* language Which internal language to use */
+ /* nobreakfirst TRUE if break not allowed after first line of para */
+ /* nobreaklastt TRUE if break not allowed before last line of para */
+ /* */
+ /* CONSTRAINT - a constraint on how large some object is allowed to be, */
+ /* either horizontally or vertically */
+ /* */
+ /* bc how large back may be (MAX_FULL_LEN if infinite) */
+ /* fc how large fwd may be (MAX_FULL_LEN if infinite) */
+ /* bfc how large back + fwd may be (MAX_FULL_LEN if inf.) */
+ /* */
+ /* */
+ /* Here now is the list of all object types, what they represent, and */
+ /* what fields they contain. The list also indicates what children each */
+ /* object of the given type can expect to have. */
+ /* */
+ /* LINK - one link in the directed acyclic graph which is Lout's universal */
+ /* internal data structure. All the other types below are various */
+ /* types of nodes. Has ALL only (and no fpos) except see CROSS_SYM */
+ /* */
+ /* GAP_OBJ - a gap between two Lout objects */
+ /* */
+ /* gap The gap itself (type GAP) */
+ /* underline TRUE if continuous underlining crosses this gap */
+ /* save_* These fields used by optimum paragraph breaker only */
+ /* first child If the gap is not just white space, the gap object */
+ /* */
+ /* CLOSURE - an invocation of a user-defined symbol, not yet expanded */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED After sizing if indefinite (the sizes will be zero) */
+ /* save_style Style to print this invocation in when expanded */
+ /* actual The symbol table record defining this symbol */
+ /* threaded TRUE if symbol lies on a vertical thread */
+ /* external_ver TRUE if symbol is external in a vertical galley */
+ /* external_hor TRUE if symbol is external in a horizontal galley */
+ /* children PAR objects whose children are the actual parameters */
+ /* */
+ /* UNDER_REC - a temporary object inserted by FixAndPrintObject to help */
+ /* with working out continuous underlining */
+ /* */
+ /* back(COLM) Horizontal position of start of underline */
+ /* fwd(COLM) Horizontal position of end of underline */
+ /* back(ROWM) [type clash] font determining underline appearance */
+ /* fwd(ROWM) [type clash] the colour of the underline */
+ /* */
+ /* PAGE_LABEL - a @PageLabel object */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED Indefinite, so all sizes will be zero */
+ /* first child The parameter of the @PageLabel object */
+ /* */
+ /* NULL_CLOS - a @Null object */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED Indefinite, so all sizes will be zero */
+ /* */
+ /* CROSS, FORCE_CROSS - a cross reference (or forcing cross reference) obj */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED Indefinite, so all sizes will be zero */
+ /* cross_type Type of cross reference (preceding, following, etc.) */
+ /* children The two parameters of the cross reference */
+ /* */
+ /* HEAD - the header record for a galley invocation */
+ /* */
+ /* force_gall TRUE if this is a forcing galley (i.e. "force into") */
+ /* actual The symbol table record defining this galley */
+ /* enclose_obj If galley has @Enclose, the enclose object */
+ /* limiter Helps decide whether to break off or scale if stuck */
+ /* opt_components If optimizing, the sequence of components */
+ /* opt_constraints If optimizing, the sequence of size constraints */
+ /* opt_counts If optimizing, the sequence of numbers of components */
+ /* In each child of opt_counts, comp_count has the num */
+ /* opt_comps_permitted number of components left before opt break */
+ /* opt_hyph If optimizing, whether to hyphenate the galley */
+ /* opt_gazumped If optimizing, galley has been gazumped recently */
+ /* gall_dir Promotion direction (COLM for horizontal galleys) */
+ /* ready_galls Galleys read in from cross reference database */
+ /* must_expand TRUE if must expand galley object even if indefinite */
+ /* sized TRUE after galley object has been sized */
+ /* foll_or_prec Direction of search for target (forward, back, etc.) */
+ /* whereto Symbol this galley is targeted at */
+ /* seen_nojoin TRUE if // op found within galley anywhere */
+ /* headers either nilobj or an ACAT of header components */
+ /* */
+ /* SPLIT - a split object, used for building tables */
+ /* */
+ /* SIZED The size of the whole object */
+ /* first child An object whose horizontal size is the overall size */
+ /* second child An object whose vertical size is the overall size */
+ /* */
+ /* PAR - actual parameter of a symbol invocation (always child of CLOSURE) */
+ /* */
+ /* TOKEN While still being parsed */
+ /* actual The symbol table record defining this parameter */
+ /* first child A Lout object, the value of this parameter */
+ /* */
+ /* WORD, QWORD - a literal word, or a literal word entered in quotes "" */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the word */
+ /* word_font Font to print this word in (from style) */
+ /* word_colour Colour to print this word in (from style) */
+ /* word_outline If TRUE, print this word in outline (from style) */
+ /* word_language Language (for hyphenation) of this word (from style) */
+ /* underline TRUE if continuous underlining goes under this word */
+ /* word_hyph Hyphenation wanted for this word (from style) */
+ /* word_save_mark Coord of column mark, temporarily in FixAndPrint */
+ /* string[] The characters of the word, null-terminated */
+ /* */
+ /* WORD, QWORD when used as database header records */
+ /* */
+ /* string[] Database index file name */
+ /* reading TRUE if this database can be read from */
+ /* in_memory TRUE if this database's index is held in memory */
+ /* db_filep Pointer to database file (if not in_memory) */
+ /* left_pos Seek pos of 1st entry in db_filep (if not in_memory) */
+ /* db_lines Pointer to database index lines (if in_memory) */
+ /* db_lineslen Number of database index lines (if in_memory) */
+ /* first child List of symbols held in this database */
+ /* other children CROSS_SYM symbols of symbols in this database */
+ /* The *links* to these have the following fields: */
+ /* number An ID number for this sym in this db */
+ /* db_targ TRUE if sym is a galley target */
+ /* */
+ /* WORD, QWORD when used as font records (consult z37.c for more detail) */
+ /* */
+ /* string[] Font name */
+ /* font_num The number of this font */
+ /* font_page Number of most recent page using this font */
+ /* font_size Size of this font */
+ /* font_xheight2 Half-x height of this font */
+ /* font_spacewidth Preferred width of space between words in this font */
+ /* font_mapping The mapping to apply with this font */
+ /* font_recoded TRUE if font needs recoding in PostScript output */
+ /* */
+ /* WORD, QWORD when used in hash table to check whether crs defined twice */
+ /* */
+ /* db_checksym Symbol of the cross reference */
+ /* string[] Tag of the cross reference */
+ /* */
+ /* HSPANNER (VSPANNER) - An object that spans columns (rows) */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* spanner_broken TRUE after BreakObject() applied to this object */
+ /* spanner_count Number of columns (rows) spanned by this spanner */
+ /* spanner_sized Number of cols (rows) of this spanner sized so far */
+ /* spanner_fixed Number of cols (rows) of this spanner fixed so far */
+ /* save_mark used temporarily by FixAndPrintObject */
+ /* constraint Space available for this object as known to MinSize */
+ /* first child The object that is doing the spanning */
+ /* */
+ /* COL_THR (ROW_THR) - object representing all objects on a col (row) mark */
+ /* */
+ /* SIZED The horizontal (vertical) size only */
+ /* thr_state Tells whether thread is sized or not yet */
+ /* children The objects on the mark */
+ /* parents The parents of the children (one-to-one) */
+ /* */
+ /* ACAT - a paragraph (sequence of objects separated by & or white space) */
+ /* */
+ /* SIZED The size of the object */
+ /* save_style The style to print this paragraph in */
+ /* children The paragraph's objects and gaps (obj-gap-obj...obj) */
+ /* */
+ /* HCAT (VCAT) - a horizontal (vertical) sequence of objects */
+ /* */
+ /* SIZED The size of the object */
+ /* save_style The style to print this object in */
+ /* children The objects and gaps (obj-gap-obj...obj) */
+ /* adjust_cat Whether to perform adjustment (@VAdjust, etc.) */
+ /* */
+ /* WIDE (HIGH) - @Wide (@High) object */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* constraint The horizontal (vertical) size constraint */
+ /* first child The right parameter of this symbol */
+ /* */
+ /* HSHIFT (VSHIFT) - @HShift (@VShift) object */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* shift_type left, right etc. */
+ /* shift_gap The amount to shift */
+ /* first child The right parameter of this symbol */
+ /* */
+ /* HSCALE (VSCALE) - @HScale (@VScale) object */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* save_mark used temporarily by FixAndPrintObject */
+ /* constraint used temporarily by FixAndPrintObject */
+ /* first child The right parameter of this symbol */
+ /* */
+ /* SCALE - @Scale object */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* bc(constraint) The horizontal scale factor */
+ /* fc(constraint) The vertical scale factor */
+ /* save_mark used temporarily by FixAndPrintObject */
+ /* vert_sized TRUE if vertical size of object is known */
+ /* first child The right parameter of this symbol */
+ /* */
+ /* BEGIN_HEADER, SET_HEADER - @BeginHeaderComponent, @SetHeaderComponent */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object (will be 0) */
+ /* first child The gap for after this header (before manifesting) */
+ /* last child The right parameter of this symbol */
+ /* */
+ /* END_HEADER, CLEAR_HEADER - @EndHeaderComponent, @ClearHeaderComponent */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object (will be 0) */
+ /* */
+ /* ONE_COL (ONE_ROW) - @OneCol (@OneRow) object */
+ /* HCOVER (VCOVER) - @HCover (@VCover) object */
+ /* HCONTRACT (VCONTRACT) - @HContract (@VContract) object */
+ /* HEXPAND (VEXPAND) - @HExpand (@VExpand) object */
+ /* START_HSPAN, START_VSPAN - @StartHSpan, @StartVSpan */
+ /* START_HVSPAN - @StartHVSpan */
+ /* HSPAN (VSPAN) - @HSpan (@VSpan) symbols */
+ /* KERN_SHRINK - @KernShrink object */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* first child The right parameter of this symbol (if any) */
+ /* */
+ /* PADJUST (HADJUST, VADJUST) - @PAdjust (@HAdjust, @VAdjust) symbols */
+ /* */
+ /* TOKEN While still being parsed */
+ /* first child The right parameter of this symbol */
+ /* */
+ /* ROTATE - @Rotate symbol */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* save_mark used temporarily by FixAndPrintObject */
+ /* sparec(cons) Amount to rotate by (after manifesting) */
+ /* first child Amount to rotate by (before manifesting) */
+ /* last child The right parameter of this symbol */
+ /* */
+ /* BACKGROUND - @Background symbol */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* children The two parameters of this symbol */
+ /* */
+ /* GRAPHIC, PLAIN_GRAPHIC - @Graphic, @PlainGraphic symbols */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* save_mark used temporarily by FixAndPrintObject */
+ /* children The two parameters of this symbol */
+ /* */
+ /* LINK_SOURCE, LINK_DEST - @LinkSource, @LinkDest symbols */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* save_mark used temporarily by FixAndPrintObject */
+ /* children The two parameters of this symbol */
+ /* */
+ /* CASE - @Case symbol */
+ /* */
+ /* TOKEN While still being parsed */
+ /* first child The left parameter of @Case */
+ /* last child The right parameter (sequence of @Yield objects) */
+ /* */
+ /* VERBATIM (RAWVERBATIM) - @Verbatim (@RawVerbatim) symbol */
+ /* */
+ /* TOKEN While still being parsed */
+ /* first child The right parameter of this symbol */
+ /* */
+ /* FILTERED - object recording filtered Lout object */
+ /* */
+ /* filter_use_begin TRUE if filter enclosed in @Begin ... @End */
+ /* filter_actual The symbol this is an invocation of */
+ /* first child WORD containing file name of filter input file */
+ /* second child WORD containing file name of filter output file */
+ /* last child Scope snapshot for reading filter output file */
+ /* */
+ /* XCHAR - @Char symbol */
+ /* NEXT - @Next symbol */
+ /* ONE_OF - @OneOf symbol */
+ /* UNDERLINE - @Underline symbol */
+ /* */
+ /* TOKEN While still being parsed */
+ /* last child The right parameter of this symbol */
+ /* */
+ /* FONT, SPACE, BREAK - @Font, @Space, @Break symbols */
+ /* YUNIT, ZUNIT - @YUnit, @ZUnit symbols */
+ /* COLOUR, OUTLINE, LANGUAGE - @Colour, @Outline, @Language symbols */
+ /* PLUS, MINUS, - @Plus, @Minus symbols */
+ /* MELD, COMMON, RUMP, INSERT - @Meld, @Common, @Rump, @Insert symbols */
+ /* OPEN, TAGGED - @Open, @Tagged symbols */
+ /* YIELD - @Yield symbol */
+ /* */
+ /* TOKEN While still being parsed */
+ /* first child The left parameter of this symbol */
+ /* last child The right parameter of this symbol */
+ /* */
+ /* ENV_OBJ - a Lout object with environment attached */
+ /* */
+ /* first child The Lout object */
+ /* last child Its environment (ENV object) */
+ /* */
+ /* ENV - environment of some Lout object */
+ /* */
+ /* children Components of the environment */
+ /* */
+ /* INCGRAPHIC, SINCGRAPHIC - @IncludeGraphic, @SysIncludeGraphic symbols */
+ /* */
+ /* TOKEN While still being parsed */
+ /* SIZED The size of the object */
+ /* save_mark used temporarily by FixAndPrintObject */
+ /* incgraphic_ok TRUE if file name pans out OK */
+ /* last child The right parameter of this symbol */
+ /* */
+ /* TSPACE, TJUXTA - tokens representing white space */
+ /* */
+ /* TOKEN While still being parsed */
+ /* mark(gap) FALSE */
+ /* join(gap) TRUE */
+ /* */
+ /* BEGIN - @Begin symbol */
+ /* */
+ /* TOKEN While still being parsed */
+ /* actual Symbol this @Begin starts parameter of */
+ /* */
+ /* END - @End symbol */
+ /* LBR, RBR - tokens representing left brace and right brace */
+ /* USE, NOT_REVEALED - @Use, @NotRevealed symbols */
+ /* GSTUB_EXT, GSTUB_INT, GSTUB_NONE - stubs for transferred galleys */
+ /* UNEXPECTED_EOF - unexpected end of file token */
+ /* INCLUDE, SYS_INCLUDE - @Include, @SysInclude symbols */
+ /* PREPEND, SYS_PREPEND - @PrependGraphic, @SysPrependGraphic symbols */
+ /* ENVA, ENVB, ENVC, ENVD - @LEnvA, @LEnvB, @LEnvC, @LEnvD tokens only */
+ /* CENV, CLOS, LVIS, LUSE, LEO - @LCEnv, @LClos, @LVis, @LUse, @LEO tokens */
+ /* BACKEND - @BackEnd symbol */
+ /* CURR_LANG, CURR_FAMILY, CURR_FACE - @CurrLang, @CurrFamily, @CurrFace */
+ /* CURR_YUNIT, CURR_ZUNIT - @CurrYUnit, @CurrZUnit */
+ /* */
+ /* TOKEN While still being parsed */
+ /* */
+ /* DEAD - the index of a dead galley */
+ /* */
+ /* UNATTACHED - the index of an unattached galley */
+ /* */
+ /* actual The galley referred to */
+ /* non_blocking TRUE if this index should not block galley flushing */
+ /* blocked TRUE if this index is now blocking galley flushing */
+ /* pinpoint Exact anchor point of this index */
+ /* */
+ /* RECEPTIVE, RECEIVING - the index of a receptive or receiving object */
+ /* */
+ /* actual The object (symbol invocation) referred to */
+ /* trigger_externs TRUE is this index's galley has external galleys */
+ /* non_blocking TRUE if this index should not block galley flushing */
+ /* blocked TRUE if this index is now blocking galley flushing */
+ /* */
+ /* RECURSIVE - the index of a recursive but definite object */
+ /* */
+ /* actual The recursive symbol invocation referred to */
+ /* */
+ /* PRECEDES - an index recording a precedes/follows flushing constraint */
+ /* */
+ /* first child Other parent of this is the corresponding FOLLOWS */
+ /* */
+ /* FOLLOWS - an index recording a precedes/follows flushing constraint */
+ /* */
+ /* blocked TRUE if this index is now blocking galley flushing */
+ /* first child Other parent of this is the corresponding PRECEDES */
+ /* */
+ /* CROSS_LIT - not actually an object at all */
+ /* */
+ /* CROSS_PREC, CROSS_FOLL, CROSS_FOLL_OR_PREC - the index of a cross ref */
+ /* */
+ /* actual The cross reference referred to */
+ /* underline TRUE if continuous underline goes through here */
+ /* first child Equal to actual */
+ /* */
+ /* GALL_PREC, GALL_FOLL, GALL_FOLL_OR_PREC - index of a galley */
+ /* */
+ /* actual The galley referred to */
+ /* underline TRUE if continuous underline goes through here */
+ /* pinpoint Exact anchor point of this index */
+ /* */
+ /* GALL_TARG - index of the target of a galley */
+ /* */
+ /* actual The galley target (symbol invocation) referred to */
+ /* underline TRUE if continuous underline goes through here */
+ /* */
+ /* PAGE_LABEL_IND - the index of a @PageLabel object */
+ /* */
+ /* actual The @PageLabel object referred to */
+ /* underline TRUE if continuous underline goes through here */
+ /* first child Equal to actual */
+ /* */
+ /* SCALE_IND - the index of a @Scale symbol with empty left parameter */
+ /* COVER_IND - the index of an @HCover or @VCover object */
+ /* EXPAND_IND - the index of an @HExpand or @VExpand object */
+ /* */
+ /* actual The object referred to */
+ /* underline TRUE if continuous underline goes through here */
+ /* */
+ /* THREAD - a sequence of threads (basically local to Manifest) */
+ /* */
+ /* children The threads */
+ /* */
+ /* CROSS_SYM - a record of the cross reference state of some symbol */
+ /* */
+ /* target_state Whether we currently have a preceding target */
+ /* target_file Which file target is written to */
+ /* target_val Value of target (if target_state == SEEN_TARGET) */
+ /* target_seq A sequence number */
+ /* target_pos Seek position of target in target_file */
+ /* target_lnum Line number of target in target_file */
+ /* gall_seq Sequence number for galleys targeted to here */
+ /* symb The symbol table record of the symbol this is for */
+ /* gall_tag I forget! */
+ /* gall_tfile The most recent cr database file for this sym */
+ /* children Cross references and galleys waiting for a target */
+ /* These children have the following fields: */
+ /* */
+ /* string[] The sequence number */
+ /* cs_type The cross reference type */
+ /* cs_fnum File number where value written */
+ /* cs_pos File seek position */
+ /* cs_lnum File line number */
+ /* */
+ /* CR_ROOT - all CROSS_SYM objects are children of this singleton */
+ /* */
+ /* children All CROSS_SYM symbols */
+ /* */
+ /* MACRO - a symbol table entry for a symbol which is a macro */
+ /* LOCAL - a symbol table entry for a symbol which is a local symbol */
+ /* LPAR - a symbol table entry for a symbol which is a left parameter */
+ /* RPAR - a symbol table entry for a symbol which is a right parameter */
+ /* NPAR - a symbol table entry for a symbol which is a named parameter */
+ /* */
+ /* enclosing The symbol that this one is defined within, if any */
+ /* sym_body The symbol body (token sequence if MACRO) */
+ /* base_uses Local to symbol table, for calculating call graph */
+ /* uses Call graph info */
+ /* marker For call graph calculation */
+ /* imports The import list preceding this symbol, if any */
+ /* filter Child @Filter symbol, if any */
+ /* use_invocation A @Use clause containing this symbol, if any */
+ /* predefined If predefined symbol, its non-zero enum code */
+ /* has_compulsory Number of parameters with "compulsory" tag */
+ /* uses_count Number of times this symbol is used */
+ /* npar_code One-letter abbreviation for this NPAR */
+ /* cross_sym The CROSS_SYM record for this symbol, if any */
+ /* recursive TRUE if symbol is recursive */
+ /* has_body TRUE if symbol has a body parameter */
+ /* imports_encl TRUE if symbol imports the symbol enclosing itself */
+ /* right_assoc TRUE if this symbol has "associativity right" */
+ /* precedence The precedence of this symbol */
+ /* indefinite TRUE if this symbol is indefinite (e.g. receptive) */
+ /* recursive TRUE if symbol is recursive */
+ /* is_extern_target TRUE if symbol is the target of external galley */
+ /* uses_extern_target TRUE if symbol uses target of an external galley */
+ /* visible TRUE if symbol is exported */
+ /* uses_galley TRUE if symbol uses a galley */
+ /* horiz_galley if galley, ROWM if vertical, COLM if horizontal */
+ /* is_compulsory TRUE if this is a parameter with "compulsory" tag */
+ /* dirty TRUE if must copy this parameter, not link it */
+ /* has_par TRUE if this symbol has at least one parameter */
+ /* has_lpar TRUE if this symbol has a left parameter */
+ /* has_rpar TRUE if this symbol has a right or body parameter */
+ /* has_target TRUE if this symbol has a target (is a galley) */
+ /* force_target TRUE if this symbol has a forcing target */
+ /* is_target TRUE if this symbol is @Target, defining a target */
+ /* has_tag TRUE if this symbol has a @Tag parameter */
+ /* is_tag TRUE if this symbol is a @Tag parameter */
+ /* has_key TRUE if this symbol has a @Key parameter */
+ /* is_key TRUE if this symbol is a @Key parameter */
+ /* has_optimize TRUE if this symbol has an @Optimize parameter */
+ /* is_optimize TRUE if this symbol is an @Optimize parameter */
+ /* has_merge TRUE if this symbol has a @Merge parameter */
+ /* is_merge TRUE if this symbol is a @Merge parameter */
+ /* has_enclose TRUE if this symbol has an @Enclose parameter */
+ /* is_enclose TRUE if this symbol is an @Enclose parameter */
+ /* */
+ /* EXT_GALL - a record of an external galley, not actually read in yet */
+ /* */
+ /* eg_fnum Number of file read from */
+ /* eg_fpos Position in that file */
+ /* eg_lnum Line number in that file */
+ /* eg_cont Continuation (where to look for next galley) */
+ /* eg_symbol The symbol that is the target of this galley */
+ /* first child The galley tag */
+ /* second child The galley sequence string */
+ /* */
+ /* CR_LIST - a list of cross references */
+ /* */
+ /* children The cross-references */
+ /* */
+ /* SCOPE_SNAPSHOT - a snapshot of one element of the current scope stack */
+ /* */
+ /* ss_npars_only Value of npars_only in this element */
+ /* ss_vis_only Value of vis_only in this element */
+ /* ss_body_ok Value of body_ok in this element */
+ /* ss_suppress Value of suppress_visible in this element */
+ /* */
+ /* DISPOSED - a disposed object (available for reallocation) */
+ /* */
+ /*****************************************************************************/
+
+ typedef union rec
+ {
+ struct word_type /* all fields of WORD and QWORD, token and object */
+ { LIST olist[2];
+ FIRST_UNION ou1;
+ SECOND_UNION ou2;
+ THIRD_UNION ou3;
+ FULL_CHAR ostring[4];
+ } os1;
+
+ struct closure_type /* all fields of CLOSURE, both as token and object */
+ { LIST olist[2];
+ FIRST_UNION ou1;
+ SECOND_UNION ou2;
+ THIRD_UNION ou3;
+ FOURTH_UNION ou4;
+ union rec *oactual;
+ union
+ { union rec *owhereto;
+ union rec *opinpoint;
+ FULL_LENGTH osave_mark;
+ } oux;
+ /* union rec *oready_galls; */
+ } os2;
+
+ struct head_type /* all fields of HEAD, both as token and object */
+ { LIST olist[2];
+ FIRST_UNION ou1;
+ SECOND_UNION ou2;
+ THIRD_UNION ou3;
+ FOURTH_UNION ou4;
+ union rec *oactual;
+ union
+ { union rec *owhereto;
+ union rec *opinpoint;
+ FULL_LENGTH osave_mark;
+ } oux;
+ union rec *oready_galls;
+ union rec *oopt_components;
+ union rec *oopt_constraints;
+ union rec *oopt_counts;
+ union rec *olimiter;
+ union rec *oenclose_obj;
+ union rec *oheaders;
+ union rec *odead_headers;
+ int oopt_comps_permitted;
+ } os2a;
+
+ struct object_type /* the general OBJECT */
+ { LIST olist[2];
+ FIRST_UNION ou1;
+ SECOND_UNION ou2;
+ THIRD_UNION ou3;
+ FOURTH_UNION ou4;
+ } os3;
+
+ struct link_type /* LINK */
+ { LIST olist[2];
+ unsigned char otype;
+ unsigned char onumber;
+ unsigned char odb_targ;
+ } os4;
+
+ struct gapobj_type /* GAP_OBJ */
+ { LIST olist[2];
+ FIRST_UNION ou1;
+ SECOND_UNION ou2;
+ GAP ogap;
+ int osave_badness; /* optimum paragraph breaker */
+ SHORT_LENGTH osave_space; /* optimum paragraph breaker */
+ SHORT_LENGTH osave_actual_gap; /* optimum paragraph breaker */
+ union rec *osave_prev; /* optimum paragraph breaker */
+ union rec *osave_cwid; /* optimum paragraph breaker */
+ } os5;
+
+ struct symbol_type
+ { LIST olist[2];
+ FIRST_UNION ou1;
+ SECOND_UNION ou2;
+ union rec *oenclosing;
+ union rec *osym_body;
+ union rec *obase_uses;
+ union rec *ouses;
+ union rec *omarker;
+ union rec *ocross_sym;
+ union rec *oimports;
+ union rec *ofilter;
+ union rec *ouse_invocation;
+ short unsigned opredefined;
+ short unsigned ohas_compulsory;
+ unsigned char ouses_count;
+ unsigned char onpar_code;
+ BOOLEAN ois_optimize : 1;
+ BOOLEAN ohas_optimize : 1;
+ BOOLEAN ois_merge : 1;
+ BOOLEAN ohas_merge : 1;
+ BOOLEAN ois_enclose : 1;
+ BOOLEAN ohas_enclose : 1;
+ BOOLEAN ois_compulsory : 1;
+ } os6;
+
+ struct cr_type
+ { LIST olist[2];
+ unsigned char otype;
+ unsigned char otarget_state;
+ FILE_NUM otarget_file;
+ /* FILE_NUM ocr_file; unused */
+ union rec *otarget_val;
+ int otarget_seq;
+ int otarget_pos;
+ int otarget_lnum;
+ /* int ocr_seq; unused */
+ int ogall_seq;
+ union rec *osymb;
+ union rec *ogall_tag;
+ FILE_NUM ogall_tfile;
+ } os7;
+
+ struct ext_gall_type
+ { LIST olist[2];
+ unsigned char otype;
+ FILE_NUM oeg_fnum;
+ int oeg_lnum;
+ long oeg_fpos;
+ long oeg_cont;
+ union rec *oeg_symbol;
+ } os8;
+
+ struct uses_type
+ { union rec *oitem;
+ union rec *onext;
+ } os9;
+ #define USES_SIZE ceiling( sizeof(struct uses_type), sizeof(ALIGN) )
+
+ struct hash_entry_type
+ { LIST olist[1];
+ } os10;
+
+ } *OBJECT;
+
+
+ /*@::macros for fields of OBJECT@*********************************************/
+ /* */
+ /* Macros for fields of OBJECT. */
+ /* */
+ /*****************************************************************************/
+
+ #define succ(x, dim) (x)->os1.olist[dim].osucc
+ #define pred(x, dim) (x)->os1.olist[dim].opred
+
+ #define type(x) (x)->os1.ou1.os11.otype
+ #define rec_size(x) (x)->os1.ou1.os11.orec_size
+ #define precedence(x) (x)->os1.ou2.os21.oprecedence
+ #define hspace(x) (x)->os1.ou2.os21.ohspace
+ #define vspace(x) (x)->os1.ou2.os21.ovspace
+
+ #define word_font(x) (x)->os1.ou2.os22.oword_font
+ #define spanner_count(x) word_font(x)
+ #define word_colour(x) (x)->os1.ou2.os22.oword_colour
+ #define spanner_sized(x) word_colour(x)
+ #define word_outline(x) (x)->os1.ou2.os22.oword_outline
+ #define word_language(x) (x)->os1.ou2.os22.oword_language
+ #define spanner_fixed(x) word_language(x)
+ #define spanner_broken(x) word_outline(x)
+ #define underline(x) (x)->os1.ou2.os22.ounderline
+ #define word_hyph(x) (x)->os1.ou2.os22.oword_hyph
+ #define filter_use_begin(x) (x)->os1.ou2.os22.oword_colour
+
+ #define ss_npars_only(x) word_font(x)
+ #define ss_vis_only(x) word_colour(x)
+ #define ss_body_ok(x) word_outline(x)
+ #define ss_suppress(x) word_language(x)
+
+ #define non_blocking(x) (x)->os1.ou2.os23.onon_blocking
+ #define vert_sized(x) non_blocking(x)
+ #define sized(x) (x)->os1.ou2.os23.osized
+ #define threaded(x) (x)->os1.ou2.os23.othreaded
+ #define external_ver(x) (x)->os1.ou2.os23.oexternal_ver
+ #define external_hor(x) (x)->os1.ou2.os23.oexternal_hor
+ #define blocked(x) (x)->os1.ou2.os23.oblocked
+ #define seen_nojoin(x) blocked(x)
+ #define trigger_externs(x) (x)->os1.ou2.os23.otrigger_ext
+ #define must_expand(x) (x)->os1.ou2.os23.omust_expand
+ #define gall_dir(x) (x)->os1.ou2.os23.ogall_dir
+ #define opt_hyph(x) (x)->os1.ou2.os23.oopt_hyph
+ #define opt_gazumped(x) (x)->os1.ou2.os23.oopt_gazumped
+ #define adjust_cat(x) (x)->os1.ou2.os23.oadjust_cat
+ #define force_gall(x) (x)->os1.ou2.os23.oforce_gall
+ #define cross_type(x) (x)->os1.ou2.os23.ocross_type
+ #define foll_or_prec(x) (x)->os1.ou2.os23.ofoll_or_prec
+ #define thr_state(x) cross_type(x)
+ #define incgraphic_ok(x) cross_type(x)
+
+ #define left_pos(x) (x)->os1.ou2.os24.oleft_pos
+ #define db_lineslen(x) left_pos(x)
+ #define reading(x) (x)->os1.ou2.os24.oreading
+ #define in_memory(x) (x)->os1.ou2.os24.oin_memory
+
+ #define is_tag(x) (x)->os1.ou2.os26.ois_tag
+ #define has_tag(x) (x)->os1.ou2.os26.ohas_tag
+ #define has_lpar(x) (x)->os1.ou2.os26.ohas_lpar
+ #define has_rpar(x) (x)->os1.ou2.os26.ohas_rpar
+ #define right_assoc(x) (x)->os1.ou2.os26.oright_assoc
+ #define is_target(x) (x)->os1.ou2.os26.ois_target
+ #define has_target(x) (x)->os1.ou2.os26.ohas_target
+ #define force_target(x) (x)->os1.ou2.os26.oforce_target
+ #define has_body(x) (x)->os1.ou2.os26.ohas_body
+ #define indefinite(x) (x)->os1.ou2.os26.oindefinite
+ #define recursive(x) (x)->os1.ou2.os26.orecursive
+ #define uses_extern_target(x) (x)->os1.ou2.os26.ouses_extern_target
+ #define is_extern_target(x) (x)->os1.ou2.os26.ois_extern_target
+ #define is_key(x) (x)->os1.ou2.os26.ois_key
+ #define has_key(x) (x)->os1.ou2.os26.ohas_key
+ #define dirty(x) (x)->os1.ou2.os26.odirty
+ #define visible(x) (x)->os1.ou2.os26.ovisible
+ #define has_mark(x) (x)->os1.ou2.os26.ohas_mark
+ #define has_join(x) (x)->os1.ou2.os26.ohas_join
+ #define has_par(x) (x)->os1.ou2.os26.ohas_par
+ #define uses_galley(x) (x)->os1.ou2.os26.ouses_galley
+ #define horiz_galley(x) (x)->os1.ou2.os26.ohoriz_galley
+ #define imports_encl(x) (x)->os1.ou2.os26.oimports_encl
+
+ #define fpos(x) (x)->os1.ou1.ofpos
+ #define word_save_mark(x) (x)->os1.ou1.os11.oword_save_mark
+
+ #define back(x, dim) (x)->os1.ou3.os31.oback[dim]
+ #define comp_count(x) back(x, COLM)
+ #define fwd(x, dim) (x)->os1.ou3.os31.ofwd[dim]
+ #define size(x, dim) (back(x, dim) + fwd(x, dim))
+ #define db_filep(x) (x)->os1.ou3.odb_filep
+ #define db_lines(x) (x)->os1.ou3.odb_lines
+ #define filter_actual(x) (x)->os1.ou3.ofilter_actual
+ #define db_checksym(x) filter_actual(x)
+
+ #define cs_type(x) (x)->os1.ou3.os33.ocs_type
+ #define cs_fnum(x) (x)->os1.ou3.os33.ocs_fnum
+ #define cs_pos(x) (x)->os1.ou3.os33.ocs_pos
+ #define cs_lnum(x) (x)->os1.ou3.os33.ocs_lnum
+
+ #define gall_rec(x) (x)->os1.ou3.os33.ogall_rec
+ #define gall_type(x) (x)->os1.ou3.os33.ogall_type
+ #define gall_pos(x) (x)->os1.ou3.os33.ogall_pos
+
+ #define string(x) (x)->os1.ostring
+
+ #define save_style(x) (x)->os2.ou4.osave_style
+ #define constraint(x) (x)->os2.ou4.oconstraint
+ #define shift_type(x) width(space_gap(save_style(x)))
+ #define shift_gap(x) line_gap(save_style(x))
+
+ #define actual(x) (x)->os2.oactual
+ #define whereto(x) (x)->os2.oux.owhereto
+ #define pinpoint(x) (x)->os2.oux.opinpoint
+ #define save_mark(x) (x)->os2.oux.osave_mark
+ #define ready_galls(x) (x)->os2a.oready_galls
+ #define opt_components(x) (x)->os2a.oopt_components
+ #define opt_constraints(x) (x)->os2a.oopt_constraints
+ #define opt_counts(x) (x)->os2a.oopt_counts
+ #define limiter(x) (x)->os2a.olimiter
+ #define enclose_obj(x) (x)->os2a.oenclose_obj
+ #define headers(x) (x)->os2a.oheaders
+ #define dead_headers(x) (x)->os2a.odead_headers
+ #define opt_comps_permitted(x) (x)->os2a.oopt_comps_permitted
+
+ #define number(x) (x)->os4.onumber
+ #define db_targ(x) (x)->os4.odb_targ
+
+ #define gap(x) (x)->os5.ogap
+ #define save_badness(x) (x)->os5.osave_badness
+ #define save_space(x) (x)->os5.osave_space
+ #define save_actual_gap(x) (x)->os5.osave_actual_gap
+ #define save_prev(x) (x)->os5.osave_prev
+ #define save_cwid(x) (x)->os5.osave_cwid
+
+ #define enclosing(x) (x)->os6.oenclosing
+ #define sym_body(x) (x)->os6.osym_body
+ #define base_uses(x) (x)->os6.obase_uses
+ #define uses(x) (x)->os6.ouses
+ #define marker(x) (x)->os6.omarker
+ #define cross_sym(x) (x)->os6.ocross_sym
+ #define imports(x) (x)->os6.oimports
+ #define filter(x) (x)->os6.ofilter
+ #define use_invocation(x) (x)->os6.ouse_invocation
+ #define predefined(x) (x)->os6.opredefined
+ #define has_compulsory(x) (x)->os6.ohas_compulsory
+ #define uses_count(x) (x)->os6.ouses_count
+ #define npar_code(x) (x)->os6.onpar_code
+ #define is_optimize(x) (x)->os6.ois_optimize
+ #define has_optimize(x) (x)->os6.ohas_optimize
+ #define is_merge(x) (x)->os6.ois_merge
+ #define has_merge(x) (x)->os6.ohas_merge
+ #define is_enclose(x) (x)->os6.ois_enclose
+ #define has_enclose(x) (x)->os6.ohas_enclose
+ #define is_compulsory(x) (x)->os6.ois_compulsory
+
+ #define target_state(x) (x)->os7.otarget_state
+ #define target_file(x) (x)->os7.otarget_file
+ /* #define cr_file(x) (x)->os7.ocr_file unused */
+ #define target_val(x) (x)->os7.otarget_val
+ #define target_seq(x) (x)->os7.otarget_seq
+ #define target_pos(x) (x)->os7.otarget_pos
+ #define target_lnum(x) (x)->os7.otarget_lnum
+ /* #define cr_seq(x) (x)->os7.ocr_seq unused */
+ #define gall_seq(x) (x)->os7.ogall_seq
+ #define symb(x) (x)->os7.osymb
+ #define gall_tag(x) (x)->os7.ogall_tag
+ #define gall_tfile(x) (x)->os7.ogall_tfile
+
+ #define eg_fnum(x) (x)->os8.oeg_fnum
+ #define eg_fpos(x) (x)->os8.oeg_fpos
+ #define eg_lnum(x) (x)->os8.oeg_lnum
+ #define eg_cont(x) (x)->os8.oeg_cont
+ #define eg_symbol(x) (x)->os8.oeg_symbol
+
+ #define item(x) (x)->os9.oitem
+ #define next(x) (x)->os9.onext
+
+ #define font_num(x) (x)->os1.ou2.os25.ofont_num
+ #define font_page(x) (x)->os1.ou2.os25.ofont_page
+ #define font_size(x) (x)->os1.ou3.os32.ofont_size
+ #define font_xheight2(x) (x)->os1.ou3.os32.ofont_xheight2
+ #define font_spacewidth(x) (x)->os1.ou3.os32.ofont_spacewidth
+ #define font_mapping(x) (x)->os1.ou3.os32.ofont_mapping
+ #define font_recoded(x) (x)->os1.ou3.os32.ofont_recoded
+
+
+ /*@::FONT_INFO@***************************************************************/
+ /* */
+ /* typedef FONT_INFO - information about font metrics etc. Really private */
+ /* but shared between z37.c and z24.c */
+ /* */
+ /*****************************************************************************/
+
+ struct metrics {
+ SHORT_LENGTH up;
+ SHORT_LENGTH down;
+ SHORT_LENGTH left;
+ SHORT_LENGTH right;
+ SHORT_LENGTH last_adjust;
+ };
+
+ typedef struct composite_rec {
+ FULL_CHAR char_code;
+ SHORT_LENGTH x_offset;
+ SHORT_LENGTH y_offset;
+ } COMPOSITE;
+
+ typedef struct font_rec {
+ struct metrics *size_table; /* metrics of sized fonts */
+ FULL_CHAR *lig_table; /* ligatures */
+ unsigned short *composite; /* non-zero means composite */
+ COMPOSITE *cmp_table; /* composites to build */
+ int cmp_top; /* length of cmp_table */
+ OBJECT font_table; /* record of sized fonts */
+ OBJECT original_face; /* face object of this font */
+ SHORT_LENGTH underline_pos; /* position of underline */
+ SHORT_LENGTH underline_thick; /* thickness of underline */
+ unsigned short *kern_table; /* first kerning chars */
+ FULL_CHAR *kern_chars; /* second kerning chars */
+ unsigned char *kern_value; /* points into kern_lengths */
+ SHORT_LENGTH *kern_sizes; /* sizes of kernings */
+ } FONT_INFO;
+
+
+ /*@::MAP_VEC@*****************************************************************/
+ /* */
+ /* typedef MAP_VEC - information about character mappings. Really private */
+ /* to z38.c but (for efficiency) shared with z37.c and z24.c */
+ /* */
+ /*****************************************************************************/
+
+ #define MAX_CHASH 353 /* size of hash table */
+ #define MAP_UPPERCASE 0 /* the map to upper case */
+ #define MAP_LOWERCASE 1 /* the map to lower case */
+ #define MAP_UNACCENTED 2 /* the map to unaccented */
+ #define MAP_ACCENT 3 /* the map to the accent character */
+ #define MAPS 4 /* the number of maps in each file */
+
+ typedef struct mapvec {
+ OBJECT file_name; /* name of file containing the vec */
+ FILE_NUM fnum; /* the file number of this file */
+ BOOLEAN seen_recoded; /* TRUE if a font recode was seen */
+ int last_page_printed; /* most recent page on which printed */
+ OBJECT name; /* PostScript name of encoding vec */
+ OBJECT vector[MAX_CHARS]; /* character names */
+ FULL_CHAR hash_table[MAX_CHASH]; /* character hash table for inverse */
+ FULL_CHAR map[MAPS][MAX_CHARS]; /* the mappings */
+ } *MAP_VEC;
+
+
+ /*@::BACK_END@****************************************************************/
+ /* */
+ /* typedef BACK_END - an OO-like record describing one back end */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct back_end_rec {
+ int code; /* the code number of the back end */
+ FULL_CHAR *name; /* string name of the back end */
+ BOOLEAN scale_avail; /* TRUE if @Scale is available */
+ BOOLEAN rotate_avail; /* TRUE if @Rotate is available */
+ BOOLEAN graphic_avail; /* TRUE if @Graphic is available */
+ BOOLEAN incgraphic_avail; /* TRUE if @IncludeGraphic is avail. */
+ BOOLEAN plaingraphic_avail; /* TRUE if @PlainGraphic is avail. */
+ BOOLEAN fractional_spacing_avail; /* TRUE if fractional spacing avail. */
+ BOOLEAN uses_font_metrics; /* TRUE if actual font metrics used */
+ BOOLEAN colour_avail; /* TRUE if colour is available */
+ void (*PrintInitialize)(FILE *fp);
+ void (*PrintLength)(FULL_CHAR *buff, int length, int length_dim);
+ void (*PrintPageSetupForFont)(OBJECT face, int font_curr_page,
+ FULL_CHAR *font_name, FULL_CHAR *first_size_str);
+ void (*PrintPageResourceForFont)(FULL_CHAR *font_name, BOOLEAN first);
+ void (*PrintMapping)(MAPPING m);
+ void (*PrintBeforeFirstPage)(FULL_LENGTH h, FULL_LENGTH v, FULL_CHAR *label);
+ void (*PrintBetweenPages)(FULL_LENGTH h, FULL_LENGTH v, FULL_CHAR *label);
+ void (*PrintAfterLastPage)(void);
+ void (*PrintWord)(OBJECT x, int hpos, int vpos);
+ void (*PrintPlainGraphic)(OBJECT x, FULL_LENGTH xmk,FULL_LENGTH ymk,OBJECT z);
+ void (*PrintUnderline)(FONT_NUM fnum, COLOUR_NUM col, FULL_LENGTH xstart,
+ FULL_LENGTH xstop, FULL_LENGTH ymk);
+ void (*CoordTranslate)(FULL_LENGTH xdist, FULL_LENGTH ydist);
+ void (*CoordRotate)(FULL_LENGTH amount);
+ void (*CoordScale)(float hfactor, float vfactor);
+ void (*SaveGraphicState)(OBJECT x);
+ void (*RestoreGraphicState)(void);
+ void (*PrintGraphicObject)(OBJECT x);
+ void (*DefineGraphicNames)(OBJECT x);
+ void (*SaveTranslateDefineSave)(OBJECT x,FULL_LENGTH xdist,FULL_LENGTH ydist);
+ void (*PrintGraphicInclude)(OBJECT x,FULL_LENGTH colmark,FULL_LENGTH rowmark);
+ void (*LinkSource)(OBJECT name, FULL_LENGTH llx, FULL_LENGTH lly,
+ FULL_LENGTH urx, FULL_LENGTH ury);
+ void (*LinkDest)(OBJECT name, FULL_LENGTH llx, FULL_LENGTH lly,
+ FULL_LENGTH urx, FULL_LENGTH ury);
+ void (*LinkCheck)();
+ } *BACK_END;
+
+
+ /*@::object types@************************************************************/
+ /* */
+ /* OBJECT, TOKEN AND OTHER TYPES inhabiting type(x) and predefined(x) */
+ /* */
+ /* Key letters in the adjacent comment indicate where the tag is legal: */
+ /* */
+ /* t a token type, pushed on token stack */
+ /* o an object type (returned by reduce(), inserted by Manifest) */
+ /* i an index type (a child of a galley header other than an object) */
+ /* s a predefined symbol (some symbol table entry has this predefined()) */
+ /* n an indefinite object i.e. one which is ignored in catenation ops */
+ /* */
+ /*****************************************************************************/
+
+ #define LINK 0 /* a link between objects */
+ #define GAP_OBJ 1 /* o a gap object */
+ #define CLOSURE 2 /* to n a closure of a symbol */
+ #define UNDER_REC 3 /* o n record of underlining */
+ #define PAGE_LABEL 4 /* to sn @PageLabel */
+ #define NULL_CLOS 5 /* to sn @Null */
+ #define CROSS 6 /* to sn && (a cross reference obj) */
+ #define FORCE_CROSS 7 /* to sn &&& (a forcing cross ref.) */
+ #define HEAD 8 /* o n a galley header */
+ #define SPLIT 9 /* o @Split */
+ #define PAR 10 /* o a parameter of a closure */
+ #define WORD 11 /* o a word */
+ #define QWORD 12 /* o a word (was quoted in i/p) */
+ #define HSPANNER 13 /* o a horizontal spanner */
+ #define VSPANNER 14 /* o a vertical spanner */
+ #define ROW_THR 15 /* o a row thread */
+ #define COL_THR 16 /* o a column thread */
+ #define ACAT 17 /* to s a sequence of &-ed objs */
+ #define HCAT 18 /* to s a sequence of |-ed objs */
+ #define VCAT 19 /* to s a sequence of /-ed objs */
+ #define BEGIN_HEADER 20 /* to s @BeginHeaderComponent */
+ #define END_HEADER 21 /* to s @EndHeaderComponent */
+ #define SET_HEADER 22 /* to s @SetHeaderComponent */
+ #define CLEAR_HEADER 23 /* to s @ClearHeaderComponent */
+ #define ONE_COL 24 /* to s @OneCol */
+ #define ONE_ROW 25 /* to s @OneRow */
+ #define WIDE 26 /* to s @Wide */
+ #define HIGH 27 /* to s @High */
+ #define HSHIFT 28 /* to s @HShift */
+ #define VSHIFT 29 /* to s @VShift */
+ #define HSCALE 30 /* to s @HScale */
+ #define VSCALE 31 /* to s @VScale */
+ #define HCOVER 32 /* to s @HCover */
+ #define VCOVER 33 /* to s @VCover */
+ #define SCALE 34 /* to s @Scale */
+ #define KERN_SHRINK 35 /* to s @KernShrink */
+ #define HCONTRACT 36 /* to s @HContract */
+ #define VCONTRACT 37 /* to s @VContract */
+ #define HLIMITED 38 /* to s @HLimited */
+ #define VLIMITED 39 /* to s @VLimited */
+ #define HEXPAND 40 /* to s @HExpand */
+ #define VEXPAND 41 /* to s @VExpand */
+ #define START_HSPAN 42 /* to s @StartHSpan */
+ #define START_VSPAN 43 /* to s @StartVSpan */
+ #define START_HVSPAN 44 /* to s @StartHVSpan */
+ #define HSPAN 45 /* to s @HSpan */
+ #define VSPAN 46 /* to s @VSpan */
+ #define PADJUST 47 /* to s @PAdjust */
+ #define HADJUST 48 /* to s @HAdjust */
+ #define VADJUST 49 /* to s @VAdjust */
+ #define ROTATE 50 /* to s @Rotate */
+ #define BACKGROUND 51 /* to s @Background */
+ #define CASE 52 /* to s @Case */
+ #define VERBATIM 53 /* to s @Verbatim */
+ #define RAW_VERBATIM 54 /* to s @RawVerbatim */
+ #define YIELD 55 /* to s @Yield */
+ #define BACKEND 56 /* to s @BackEnd */
+ #define FILTERED 57 /* to s filtered object (no name) */
+ #define XCHAR 58 /* to s @Char */
+ #define FONT 59 /* to s @Font */
+ #define SPACE 60 /* to s @Space */
+ #define YUNIT 61 /* to s @YUnit */
+ #define ZUNIT 62 /* to s @ZUnit */
+ #define BREAK 63 /* to s @Break */
+ #define UNDERLINE 64 /* to s @Underline */
+ #define COLOUR 65 /* to s @SetColour and @SetColor */
+ #define OUTLINE 66 /* to s @Outline */
+ #define LANGUAGE 67 /* to s @Language */
+ #define CURR_LANG 68 /* to s @CurrLang */
+ #define CURR_FAMILY 69 /* to s @CurrFamily */
+ #define CURR_FACE 70 /* to s @CurrFace */
+ #define CURR_YUNIT 71 /* to s @CurrYUnit */
+ #define CURR_ZUNIT 72 /* to s @CurrZUnit */
+ #define COMMON 73 /* to s @Common */
+ #define RUMP 74 /* to s @Rump */
+ #define MELD 75 /* to s @Meld */
+ #define INSERT 76 /* to s @Insert */
+ #define ONE_OF 77 /* to s @OneOf */
+ #define NEXT 78 /* to s @Next */
+ #define PLUS 79 /* to s @Plus */
+ #define MINUS 80 /* to s @Minus */
+ #define ENV_OBJ 81 /* to s object with envt (no name) */
+ #define ENV 82 /* to s @LEnv */
+ #define ENVA 83 /* to s @LEnvA */
+ #define ENVB 84 /* to s @LEnvB */
+ #define ENVC 85 /* to s @LEnvC */
+ #define ENVD 86 /* to s @LEnvD */
+ #define CENV 87 /* to s @LCEnv */
+ #define CLOS 88 /* to s @LClos */
+ #define LVIS 89 /* to s @LVis */
+ #define LUSE 90 /* to s @LUse */
+ #define LEO 91 /* to s @LEO */
+ #define OPEN 92 /* to s @Open */
+ #define TAGGED 93 /* to s @Tagged */
+ #define INCGRAPHIC 94 /* to s @IncludeGraphic */
+ #define SINCGRAPHIC 95 /* to s @SysIncludeGraphic */
+ #define PLAIN_GRAPHIC 96 /* to s @PlainGraphic */
+ #define GRAPHIC 97 /* to s @Graphic */
+ #define LINK_SOURCE 98 /* to s @LinkSource */
+ #define LINK_DEST 99 /* to s @LinkDest */
+ #define TSPACE 100 /* t a space token, parser only */
+ #define TJUXTA 101 /* t a juxta token, parser only */
+ #define LBR 102 /* t s left brace token */
+ #define RBR 103 /* t s right brace token */
+ #define BEGIN 104 /* t s @Begin token */
+ #define END 105 /* t s @End token */
+ #define USE 106 /* t s @Use */
+ #define NOT_REVEALED 107 /* t s @NotRevealed */
+ #define GSTUB_NONE 108 /* t a galley stub, no rpar */
+ #define GSTUB_INT 109 /* t galley stub internal rpar */
+ #define GSTUB_EXT 110 /* t galley stub external rpar */
+ #define UNEXPECTED_EOF 111 /* t unexpected end of file */
+ #define INCLUDE 112 /* s @Include */
+ #define SYS_INCLUDE 113 /* s @SysInclude */
+ #define PREPEND 114 /* s @Prepend */
+ #define SYS_PREPEND 115 /* s @SysPrepend */
+ #define DATABASE 116 /* s @Database */
+ #define SYS_DATABASE 117 /* s @SysDatabase */
+ /* #define START 118 */ /* s \Start */
+ #define DEAD 119 /* i a dead galley */
+ #define UNATTACHED 120 /* i an inner, unsized galley */
+ #define RECEPTIVE 121 /* i a receptive object index */
+ #define RECEIVING 122 /* i a receiving object index */
+ #define RECURSIVE 123 /* i a recursive definite obj. */
+ #define PRECEDES 124 /* i an ordering constraint */
+ #define FOLLOWS 125 /* i other end of ordering c. */
+ #define CROSS_LIT 126 /* i literal word cross-ref */
+ #define CROSS_FOLL 127 /* i following type cross-ref */
+ #define CROSS_FOLL_OR_PREC 128 /* i follorprec type cross-ref */
+ #define GALL_FOLL 129 /* i galley with &&following */
+ #define GALL_FOLL_OR_PREC 130 /* i galley with &&following */
+ #define CROSS_TARG 131 /* i value of cross-ref */
+ #define GALL_TARG 132 /* i target of these galleys */
+ #define GALL_PREC 133 /* i galley with &&preceding */
+ #define CROSS_PREC 134 /* i preceding type cross-ref */
+ #define PAGE_LABEL_IND 135 /* i index of PAGE_LABEL */
+ #define SCALE_IND 136 /* i index of auto SCALE */
+ #define COVER_IND 137 /* i index of HCOVER or VCOVER */
+ #define EXPAND_IND 138 /* i index of HEXPAND or VEXPD */
+ #define THREAD 139 /* a sequence of threads */
+ #define CROSS_SYM 140 /* cross-ref info */
+ #define CR_ROOT 141 /* RootCross */
+ #define MACRO 142 /* a macro symbol */
+ #define LOCAL 143 /* a local symbol */
+ #define LPAR 144 /* a left parameter */
+ #define NPAR 145 /* a named parameter */
+ #define RPAR 146 /* a right parameter */
+ #define EXT_GALL 147 /* an external galley */
+ #define CR_LIST 148 /* a list of cross references */
+ #define SCOPE_SNAPSHOT 149 /* a scope snapshot */
+ #define DISPOSED 150 /* a disposed record */
+
+ #define is_indefinite(x) ((x) >= CLOSURE && (x) <= HEAD)
+ #define is_header(x) ((x) >= BEGIN_HEADER && (x) <= CLEAR_HEADER)
+ #define is_definite(x) ((x) >= SPLIT && (x) <= LINK_DEST)
+ #define is_par(x) ((x) >= LPAR && (x) <= RPAR)
+ #define is_index(x) ((x) >= DEAD && (x) <= EXPAND_IND)
+ #define is_type(x) ((x) >= LINK && (x) < DISPOSED)
+ #define is_word(x) ((x) == WORD || (x) == QWORD)
+ #define is_cross(x) ((x) == CROSS || (x) == FORCE_CROSS)
+ #define is_cat_op(x) (((x)>=ACAT && (x)<=VCAT) || (x)==TSPACE || (x)<=TJUXTA)
+
+
+ /*@::miscellaneous constants@*************************************************/
+ /* */
+ /* Miscellaneous globally defined constants */
+ /* */
+ /*****************************************************************************/
+
+ /* gap modes occupying mode(x) */
+ #define NO_MODE 0 /* for error detection: no mode */
+ #define EDGE_MODE 1 /* edge-to-edge spacing */
+ #define HYPH_MODE 2 /* edge-to-edge with hyphenation */
+ #define MARK_MODE 3 /* mark-to-mark spacing */
+ #define OVER_MODE 4 /* overstrike spacing */
+ #define KERN_MODE 5 /* kerning spacing */
+ #define TAB_MODE 6 /* tabulation spacing */
+ #define ADD_HYPH 7 /* temp value used by FillObject */
+
+ /* hyph_style(style) options */
+ #define HYPH_UNDEF 0 /* hyphenation option undefined */
+ #define HYPH_OFF 1 /* hyphenation off */
+ #define HYPH_ON 2 /* hyphenation on */
+
+ /* fill_style(style) options */
+ #define FILL_UNDEF 0 /* fill option undefined */
+ #define FILL_OFF 1 /* no filling of lines */
+ #define FILL_ON 2 /* fill lines with text */
+
+ /* underline(obj) options */
+ #define UNDER_UNDEF 0 /* underline undefined */
+ #define UNDER_OFF 1 /* no underlining */
+ #define UNDER_ON 2 /* underline this */
+
+ /* space_style(style) options */
+ #define SPACE_LOUT 0 /* interpret white space Lout's way */
+ #define SPACE_COMPRESS 1 /* compress multiple white spaces */
+ #define SPACE_SEPARATE 2 /* compress an separate */
+ #define SPACE_TROFF 3 /* interpret white space troff's way */
+ #define SPACE_TEX 4 /* interpret white space TeX's way */
+
+ /* display_style(style) options */
+ #define DISPLAY_UNDEF 0 /* display option undefined */
+ #define DISPLAY_ADJUST 1 /* adjust lines (except last) */
+ #define DISPLAY_OUTDENT 2 /* outdent lines (except first) */
+ #define DISPLAY_ORAGGED 3 /* outdent but don't adjust */
+ #define DISPLAY_LEFT 4 /* left-justify lines, no adjust */
+ #define DISPLAY_CENTRE 5 /* centre lines, no adjust */
+ #define DISPLAY_RIGHT 6 /* right-justify lines, no adjust */
+ #define DO_ADJUST 7 /* placed in ACATs when adjust need */
+
+ /* small_caps(style) options */
+ #define SMALL_CAPS_OFF 0 /* don't want small capitals */
+ #define SMALL_CAPS_ON 1 /* small capitals */
+
+ /* sides of a mark */
+ #define BACK 151 /* means lies to left of mark */
+ #define ON 152 /* means lies on mark */
+ #define FWD 153 /* means lies to right of mark */
+
+ /* statuses of thread objects */
+ #define NOTSIZED 0 /* this thread object is not sized */
+ #define SIZED 1 /* thread is sized but not printed */
+ #define FINALSIZE 2 /* thread object size is now final */
+
+ /* constraint statuses */
+ #define PROMOTE 154 /* this component may be promoted */
+ #define CLOSE 155 /* must close dest before promoting */
+ #define BLOCK 156 /* cannot promote this component */
+ #define CLEAR 157 /* this constraint is now satisfied */
+
+ /* gap increment types */
+ #define GAP_ABS 158 /* absolute, e.g. 3p */
+ #define GAP_INC 159 /* increment, e.g. +3p */
+ #define GAP_DEC 160 /* decrement, e.g. -3p */
+
+ /* file types */
+ #define SOURCE_FILE 0 /* input file from command line */
+ #define INCLUDE_FILE 1 /* @Include file */
+ #define INCGRAPHIC_FILE 2 /* @IncludeGraphic file */
+ #define DATABASE_FILE 3 /* database file */
+ #define INDEX_FILE 4 /* database index file */
+ #define FONT_FILE 5 /* font file */
+ #define PREPEND_FILE 6 /* PostScript prologue file */
+ #define HYPH_FILE 7 /* hyphenation file */
+ #define HYPH_PACKED_FILE 8 /* packed hyphenation file */
+ #define MAPPING_FILE 9 /* character mapping file */
+ #define FILTER_FILE 10 /* filter output file */
+ #define MAX_TYPES 11 /* number of file types */
+
+ /* path types (i.e. sequences of directories for file searching) */
+ #define SOURCE_PATH 0 /* path to search for source files */
+ #define INCLUDE_PATH 1 /* path for @Include files */
+ #define SYSINCLUDE_PATH 2 /* path for @SysInclude files */
+ #define DATABASE_PATH 3 /* path for @Database files */
+ #define SYSDATABASE_PATH 4 /* path for @SysDatabase files */
+ #define FONT_PATH 5 /* path for font metrics (AFM) files */
+ #define HYPH_PATH 6 /* path for hyphenation files */
+ #define MAPPING_PATH 7 /* path for mapping (LCM) files */
+ #define MAX_PATHS 8 /* number of mapping paths */
+
+ /* units of measurement */
+ #define NO_UNIT 0 /* no unit - for error detection */
+ #define FIXED_UNIT 1 /* inches, cm, points, ems, y, z */
+ #define FRAME_UNIT 2 /* b unit (frame widths) */
+ #define AVAIL_UNIT 3 /* r unit (available spaces) */
+ #define DEG_UNIT 4 /* d unit (degrees) */
+ #define NEXT_UNIT 5 /* w unit (inners) */
+
+ /* units of distance as multiples of the basic unit */
+ #define CM 567 /* 1 centimetre */
+ #define IN 1440 /* 1 inch */
+ #define EM 120 /* 1 em (= 1/12 inch) */
+ #define PT 20 /* 1 point (= 1/72 inch) */
+ #define FR 4096 /* virtual unit for frame units */
+ #define DG 128 /* virtual unit for degrees */
+ #define SF 128 /* virtual unit for @Scale factors */
+
+ /* default size of characters for the PLAINTEXT back end */
+ #define PLAIN_WIDTH 144 /* default char width, 10 per inch */
+ #define PLAIN_HEIGHT 240 /* default char height, 6 per inch */
+
+ /* precedences */
+ #define NO_PREC 0 /* lower than any precedence */
+ #define BEGIN_PREC 1 /* precedence of @Begin */
+ #define END_PREC 2 /* precedence of @End */
+ #define LBR_PREC 3 /* precedence of { */
+ #define RBR_PREC 4 /* precedence of } */
+ #define VCAT_PREC 5 /* precedence of / */
+ #define HCAT_PREC 6 /* precedence of | */
+ #define ACAT_PREC 7 /* precedence of & and white space */
+ #define MIN_PREC 10 /* minimum precedence of user ops */
+ #define MAX_PREC 100 /* maximim precedence of user ops */
+ #define DEFAULT_PREC 100 /* default precedence of user ops */
+ #define CROSSOP_PREC 101 /* precedence of && and &&& ops */
+ #define GAP_PREC 102 /* precedence of gap op after cat op */
+ #define JUXTA_PREC 103 /* precedence of juxtaposition & */
+ #define FILTER_PREC 104 /* precedence of filter symbol ops */
+ #define FORCE_PREC 105 /* higher than any precedence */
+
+ /* back ends */
+ #define POSTSCRIPT 0 /* PostScript back end */
+ #define PDF 1 /* PDF back end */
+ #define PLAINTEXT 2 /* plain text back end */
+
+ /* error types */
+ #define INTERN 0 /* internal error (i.e. bug) */
+ #define FATAL 1 /* fatal error, abort now */
+ #define WARN 2 /* warning, non-fatal */
+
+ /* status values returned by AttachGalley() */
+ #define ATTACH_KILLED 0
+ #define ATTACH_INPUT 1
+ #define ATTACH_NOTARGET 2
+ #define ATTACH_SUSPEND 3
+ #define ATTACH_NULL 4
+ #define ATTACH_ACCEPT 5
+
+ /* types of memory usage, used to debug memory consumption */
+ #define MEM_BINARY 0 /* the executable binary */
+ #define MEM_OBJECTS 1 /* objects currently in free list */
+ #define MEM_FONTS 2 /* fonts */
+ #define MEM_LEX 3 /* lexical analyser file buffers */
+ #define MEM_FILES 4 /* table of file names */
+ #define MEM_CROSSREF 5 /* table of file names */
+ #define MEM_PAGES 6 /* page grids (-p only) */
+ #define MEM_DBCHECK 7 /* database checks */
+ #define MEM_DB 8 /* in_memory database */
+ #define MEM_HYPH_PATS 9 /* hyphenation patterns */
+ #define MEM_CMAPS 10 /* character maps */
+ #define MEM_COLOUR_TAB 11 /* colour table */
+ #define MEM_LANG_TAB 12 /* language table */
+ #define MEM_USAGE_MAX 13 /* number of memory usage types */
+
+ /*@::Keywords@****************************************************************/
+ /* */
+ /* Keywords. */
+ /* */
+ /*****************************************************************************/
+
+ #define KW_START AsciiToFull("\\Start")
+ #define KW_PRINT AsciiToFull("\\Print")
+ #define KW_OPTGALL AsciiToFull("@OptGall")
+ #define KW_DEF AsciiToFull("def")
+ #define KW_FONTDEF AsciiToFull("@FontDef")
+ #define KW_FAMILY AsciiToFull("@Family")
+ #define KW_FACE AsciiToFull("@Face")
+ #define KW_NAME AsciiToFull("@Name")
+ #define KW_METRICS AsciiToFull("@Metrics")
+ #define KW_EXTRA_METRICS AsciiToFull("@ExtraMetrics")
+ #define KW_MAPPING AsciiToFull("@Mapping")
+ #define KW_RECODE AsciiToFull("@Recode")
+ #define KW_LANGDEF AsciiToFull("langdef")
+ #define KW_FORCE AsciiToFull("force")
+ #define KW_HORIZ AsciiToFull("horizontally")
+ #define KW_INTO AsciiToFull("into")
+ #define KW_EXTEND AsciiToFull("extend")
+ #define KW_IMPORT AsciiToFull("import")
+ #define KW_EXPORT AsciiToFull("export")
+ #define KW_PRECEDENCE AsciiToFull("precedence")
+ #define KW_ASSOC AsciiToFull("associativity")
+ #define KW_LEFT AsciiToFull("left")
+ #define KW_RIGHT AsciiToFull("right")
+ #define KW_BODY AsciiToFull("body")
+ #define KW_FILTER AsciiToFull("@Filter")
+ #define KW_FILTERIN AsciiToFull("@FilterIn")
+ #define KW_FILTEROUT AsciiToFull("@FilterOut")
+ #define KW_FILTERERR AsciiToFull("@FilterErr")
+ #define KW_MACRO AsciiToFull("macro")
+ #define KW_NAMED AsciiToFull("named")
+ #define KW_COMPULSORY AsciiToFull("compulsory")
+ #define KW_COMMON AsciiToFull("@Common")
+ #define KW_RUMP AsciiToFull("@Rump")
+ #define KW_MELD AsciiToFull("@Meld")
+ #define KW_INSERT AsciiToFull("@Insert")
+ #define KW_ONE_OF AsciiToFull("@OneOf")
+ #define KW_NEXT AsciiToFull("@Next")
+ #define KW_PLUS AsciiToFull("@Plus")
+ #define KW_MINUS AsciiToFull("@Minus")
+ #define KW_WIDE AsciiToFull("@Wide")
+ #define KW_HIGH AsciiToFull("@High")
+ #define KW_HSHIFT AsciiToFull("@HShift")
+ #define KW_VSHIFT AsciiToFull("@VShift")
+ #define KW_BEGIN_HEADER AsciiToFull("@BeginHeaderComponent")
+ #define KW_END_HEADER AsciiToFull("@EndHeaderComponent")
+ #define KW_SET_HEADER AsciiToFull("@SetHeaderComponent")
+ #define KW_CLEAR_HEADER AsciiToFull("@ClearHeaderComponent")
+ #define KW_ONE_COL AsciiToFull("@OneCol")
+ #define KW_ONE_ROW AsciiToFull("@OneRow")
+ #define KW_HSCALE AsciiToFull("@HScale")
+ #define KW_VSCALE AsciiToFull("@VScale")
+ #define KW_HCOVER AsciiToFull("@HCover")
+ #define KW_VCOVER AsciiToFull("@VCover")
+ #define KW_SCALE AsciiToFull("@Scale")
+ #define KW_KERN_SHRINK AsciiToFull("@KernShrink")
+ #define KW_HCONTRACT AsciiToFull("@HContract")
+ #define KW_VCONTRACT AsciiToFull("@VContract")
+ #define KW_HLIMITED AsciiToFull("@HLimited")
+ #define KW_VLIMITED AsciiToFull("@VLimited")
+ #define KW_HEXPAND AsciiToFull("@HExpand")
+ #define KW_VEXPAND AsciiToFull("@VExpand")
+ #define KW_STARTHVSPAN AsciiToFull("@StartHVSpan")
+ #define KW_STARTHSPAN AsciiToFull("@StartHSpan")
+ #define KW_STARTVSPAN AsciiToFull("@StartVSpan")
+ #define KW_HSPAN AsciiToFull("@HSpan")
+ #define KW_VSPAN AsciiToFull("@VSpan")
+ #define KW_PADJUST AsciiToFull("@PAdjust")
+ #define KW_HADJUST AsciiToFull("@HAdjust")
+ #define KW_VADJUST AsciiToFull("@VAdjust")
+ #define KW_ROTATE AsciiToFull("@Rotate")
+ #define KW_BACKGROUND AsciiToFull("@Background")
+ #define KW_INCGRAPHIC AsciiToFull("@IncludeGraphic")
+ #define KW_SINCGRAPHIC AsciiToFull("@SysIncludeGraphic")
+ #define KW_GRAPHIC AsciiToFull("@Graphic")
+ #define KW_LINK_SOURCE AsciiToFull("@LinkSource")
+ #define KW_LINK_DEST AsciiToFull("@LinkDest")
+ #define KW_PLAINGRAPHIC AsciiToFull("@PlainGraphic")
+ #define KW_VERBATIM AsciiToFull("@Verbatim")
+ #define KW_RAWVERBATIM AsciiToFull("@RawVerbatim")
+ #define KW_CASE AsciiToFull("@Case")
+ #define KW_YIELD AsciiToFull("@Yield")
+ #define KW_BACKEND AsciiToFull("@BackEnd")
+ #define KW_XCHAR AsciiToFull("@Char")
+ #define KW_FONT AsciiToFull("@Font")
+ #define KW_SPACE AsciiToFull("@Space")
+ #define KW_YUNIT AsciiToFull("@YUnit")
+ #define KW_ZUNIT AsciiToFull("@ZUnit")
+ #define KW_BREAK AsciiToFull("@Break")
+ #define KW_UNDERLINE AsciiToFull("@Underline")
+ #define KW_COLOUR AsciiToFull("@SetColour")
+ #define KW_COLOR AsciiToFull("@SetColor")
+ #define KW_OUTLINE AsciiToFull("@Outline")
+ #define KW_LANGUAGE AsciiToFull("@Language")
+ #define KW_CURR_LANG AsciiToFull("@CurrLang")
+ #define KW_CURR_FAMILY AsciiToFull("@CurrFamily")
+ #define KW_CURR_FACE AsciiToFull("@CurrFace")
+ #define KW_CURR_YUNIT AsciiToFull("@CurrYUnit")
+ #define KW_CURR_ZUNIT AsciiToFull("@CurrZUnit")
+ #define KW_ENV AsciiToFull("@LEnv")
+ #define KW_ENVA AsciiToFull("@@A")
+ #define KW_ENVB AsciiToFull("@@B")
+ #define KW_ENVC AsciiToFull("@@C")
+ #define KW_ENVD AsciiToFull("@@D")
+ #define KW_CENV AsciiToFull("@@E")
+ #define KW_CLOS AsciiToFull("@LClos")
+ #define KW_LVIS AsciiToFull("@@V")
+ #define KW_LUSE AsciiToFull("@LUse")
+ #define KW_LEO AsciiToFull("@LEO")
+ #define KW_OPEN AsciiToFull("@Open")
+ #define KW_USE AsciiToFull("@Use")
+ #define KW_NOT_REVEALED AsciiToFull("@NotRevealed")
+ #define KW_TAGGED AsciiToFull("@Tagged")
+ #define KW_DATABASE AsciiToFull("@Database")
+ #define KW_SYSDATABASE AsciiToFull("@SysDatabase")
+ #define KW_INCLUDE AsciiToFull("@Include")
+ #define KW_SYSINCLUDE AsciiToFull("@SysInclude")
+ #define KW_PREPEND AsciiToFull("@PrependGraphic")
+ #define KW_SYSPREPEND AsciiToFull("@SysPrependGraphic")
+ #define KW_TARGET AsciiToFull("@Target")
+ #define KW_FOLLOWING AsciiToFull("following")
+ #define KW_PRECEDING AsciiToFull("preceding")
+ #define KW_FOLL_OR_PREC AsciiToFull("foll_or_prec")
+ #define KW_NOW AsciiToFull("now")
+ #define KW_NULL AsciiToFull("@Null")
+ #define KW_PAGE_LABEL AsciiToFull("@PageLabel")
+ #define KW_GALLEY AsciiToFull("@Galley")
+ #define KW_FORCE_GALLEY AsciiToFull("@ForceGalley")
+ #define KW_INPUT AsciiToFull("@LInput")
+ #define KW_SPLIT AsciiToFull("@Split")
+ #define KW_TAG AsciiToFull("@Tag")
+ #define KW_KEY AsciiToFull("@Key")
+ #define KW_OPTIMIZE AsciiToFull("@Optimize")
+ #define KW_MERGE AsciiToFull("@Merge")
+ #define KW_ENCLOSE AsciiToFull("@Enclose")
+ #define KW_CROSS AsciiToFull("&&")
+ #define KW_FORCE_CROSS AsciiToFull("&&&")
+ #define KW_LBR AsciiToFull("{")
+ #define KW_RBR AsciiToFull("}")
+ #define KW_BEGIN AsciiToFull("@Begin")
+ #define KW_END AsciiToFull("@End")
+ #define KW_VCAT_NN AsciiToFull("//")
+ #define KW_VCAT_MN AsciiToFull("^//")
+ #define KW_VCAT_NJ AsciiToFull("/")
+ #define KW_VCAT_MJ AsciiToFull("^/")
+ #define KW_HCAT_NN AsciiToFull("||")
+ #define KW_HCAT_MN AsciiToFull("^||")
+ #define KW_HCAT_NJ AsciiToFull("|")
+ #define KW_HCAT_MJ AsciiToFull("^|")
+ #define KW_ACAT_NJ AsciiToFull("&")
+ #define KW_ACAT_MJ AsciiToFull("^&")
+ #define KW_MOMENT AsciiToFull("@Moment")
+ #define KW_SECOND AsciiToFull("@Second")
+ #define KW_MINUTE AsciiToFull("@Minute")
+ #define KW_HOUR AsciiToFull("@Hour")
+ #define KW_DAY AsciiToFull("@Day")
+ #define KW_MONTH AsciiToFull("@Month")
+ #define KW_YEAR AsciiToFull("@Year")
+ #define KW_CENTURY AsciiToFull("@Century")
+ #define KW_WEEKDAY AsciiToFull("@WeekDay")
+ #define KW_YEARDAY AsciiToFull("@YearDay")
+ #define KW_DAYLIGHTSAVING AsciiToFull("@DaylightSaving")
+
+ /*@::GetMem(), New(), NewWord()@**********************************************/
+ /* */
+ /* GetMem(x, siz, pos) */
+ /* New(x, typ) */
+ /* NewWord(x, typ, len, pos) */
+ /* */
+ /* Set x to point to a new record, of appropriate length (in ALIGNs). */
+ /* The New and NewWord versions initialise LIST, type and rec_size fields. */
+ /* NewWord must be used for WORD and QWORD objects. */
+ /* */
+ /*****************************************************************************/
+
+ #if DEBUG_ON
+ #define newcount zz_newcount++
+ #define freecount zz_listcount--
+
+ #define checknew(typ) \
+ { assert1( is_type(typ), "New: type", Image(typ) ); \
+ assert( zz_lengths[typ] > 0, "New: zero length!" ); \
+ }
+
+ #define checkmem(z, typ) \
+ { if( (MemCheck != 0) && ( (POINTER) z == MemCheck) ) \
+ fprintf(stderr, "%ld = New(%s)\n", (long) z, Image(type(z))); \
+ }
+
+ #else
+ #define newcount
+ #define freecount
+ #define checknew(typ)
+ #define checkmem(z, typ)
+ #endif
+
+ #define GetMem(x, siz, pos) \
+ { newcount; \
+ if( (zz_size=(siz)) >= MAX_OBJECT_REC ) \
+ Error(1, 1, "word is too long", FATAL, pos); \
+ else if( zz_free[zz_size] == nilobj ) \
+ x = GetMemory(zz_size, pos); \
+ else \
+ { x = zz_hold = zz_free[zz_size]; \
+ freecount; \
+ zz_free[zz_size] = pred(zz_hold, CHILD); \
+ } \
+ }
+
+ #define New(x, typ) \
+ { checknew(typ); \
+ GetMem(zz_hold, zz_lengths[typ], no_fpos); \
+ type(zz_hold) = typ; \
+ checkmem(zz_hold, typ); \
+ x = pred(zz_hold, CHILD) = succ(zz_hold, CHILD) = \
+ pred(zz_hold, PARENT) = succ(zz_hold, PARENT) = zz_hold; \
+ }
+
+ #define NewWord(x, typ, len, pos) \
+ { zz_size = sizeof(struct word_type) - 4 + ((len)+1)*sizeof(FULL_CHAR); \
+ /* NB the following line RESETS zz_size */ \
+ GetMem(zz_hold, ceiling(zz_size, sizeof(ALIGN)), pos); \
+ checkmem(zz_hold, typ); \
+ rec_size(zz_hold) = zz_size; \
+ type(zz_hold) = typ; \
+ x = pred(zz_hold, CHILD) = succ(zz_hold, CHILD) = \
+ pred(zz_hold, PARENT) = succ(zz_hold, PARENT) = zz_hold; \
+ }
+
+ /*@::PutMem(), Dispose()@*****************************************************/
+ /* */
+ /* PutMem(x, siz) */
+ /* Dispose(x) */
+ /* */
+ /* Dispose x, which is of size siz. Dispose works out the size itself. */
+ /* */
+ /*****************************************************************************/
+ #if DEBUG_ON
+ #define disposecount zz_disposecount++; zz_listcount++;
+
+ #define disposecheck \
+ { assert( zz_size >= 0 && zz_size < MAX_OBJECT_REC, "Dispose: size" ); \
+ }
+
+ #define setdisposed \
+ { if( (MemCheck != 0) && ((POINTER) zz_hold == MemCheck) ) \
+ fprintf(stderr, "Dispose(%ld, %s)\n", (long) zz_hold, \
+ Image(type(zz_hold))); \
+ type(zz_hold) = DISPOSED; \
+ }
+
+ #else
+ #define disposecount
+ #define disposecheck
+ #define setdisposed
+ #endif
+
+ #define PutMem(x, siz) \
+ { disposecount; \
+ zz_hold = (x); \
+ zz_size = (siz); \
+ disposecheck; \
+ pred(zz_hold, CHILD) = zz_free[zz_size]; \
+ zz_free[zz_size] = zz_hold; \
+ }
+
+ #define Dispose(x) \
+ { zz_hold = (x); \
+ PutMem(zz_hold, is_word(type(zz_hold)) ? \
+ rec_size(zz_hold) : zz_lengths[type(zz_hold)]); \
+ setdisposed; \
+ }
+
+ /*@::Append(), Delete()@******************************************************/
+ /* */
+ /* OBJECT Append(x, y, dir) */
+ /* */
+ /* Return the append of lists x and y (dir is PARENT or CHILD). */
+ /* */
+ /*****************************************************************************/
+
+ #define Append(x, y, dir) \
+ ( zz_res = (x), zz_hold = (y), \
+ zz_hold == nilobj ? zz_res : \
+ zz_res == nilobj ? zz_hold : \
+ ( zz_tmp = pred(zz_hold, dir), \
+ pred(zz_hold, dir) = pred(zz_res, dir), \
+ succ(pred(zz_res, dir), dir) = zz_hold, \
+ pred(zz_res, dir) = zz_tmp, \
+ succ(zz_tmp, dir) = zz_res \
+ ) \
+ )
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT Delete(x, dir) */
+ /* */
+ /* Delete x from its dir list, and return succ(x, dir) or nilobj if none. */
+ /* */
+ /*****************************************************************************/
+
+ #define Delete(x, dir) \
+ ( zz_hold = (x), \
+ succ(zz_hold, dir) == zz_hold ? nilobj : \
+ ( zz_res = succ(zz_hold, dir), \
+ pred(zz_res, dir) = pred(zz_hold, dir), \
+ succ(pred(zz_hold, dir), dir) = zz_res, \
+ pred(zz_hold, dir) = succ(zz_hold, dir) = zz_hold, \
+ zz_res \
+ ) \
+ )
+
+ #define Down(x) succ(x, CHILD)
+ #define NextDown(x) succ(x, CHILD)
+ #define LastDown(x) pred(x, CHILD)
+ #define PrevDown(x) pred(x, CHILD)
+ #define Up(x) succ(x, PARENT)
+ #define NextUp(x) succ(x, PARENT)
+ #define LastUp(x) pred(x, PARENT)
+ #define PrevUp(x) pred(x, PARENT)
+
+ #define Child(y, link) \
+ for( y = pred(link, PARENT); type(y) == LINK; y = pred(y, PARENT) )
+
+ #define CountChild(y, link, i) \
+ for( y=pred(link, PARENT), i=1; type(y)==LINK; y = pred(y, PARENT), i++ )
+
+ #define Parent(y, link) \
+ for( y = pred(link, CHILD); type(y) == LINK; y = pred(y, CHILD) )
+
+
+ /*@::UpDim(), DownDim(), Link(), DeleteLink(), etc.@**************************/
+ /* */
+ /* UpDim(x, dim) */
+ /* DownDim(x, dim) */
+ /* */
+ /* Returns the dim child or parent link of node x (dim == COLM or ROWM). */
+ /* */
+ /*****************************************************************************/
+
+ #define UpDim(x, dim) ( (dim) == COLM ? succ(x, PARENT) : pred(x, PARENT) )
+ #define DownDim(x, dim) ( (dim) == COLM ? succ(x, CHILD) : pred(x, CHILD) )
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT Link(x, y) */
+ /* */
+ /* Make y a child of x in the directed graph, using a new link. */
+ /* The link node is returned. */
+ /* */
+ /*****************************************************************************/
+
+ #define Link(x, y) \
+ { New(xx_link, LINK); \
+ Append(xx_link, (x), CHILD); \
+ Append(xx_link, (y), PARENT); \
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* DeleteLink(link) */
+ /* */
+ /* Cut the link between nodes x and y of the directed graph. */
+ /* Returns the link node of the next child of x, or x if none. */
+ /* */
+ /*****************************************************************************/
+
+ #define DeleteLink(link) \
+ { xx_link = (link); \
+ Delete(xx_link, PARENT); \
+ Delete(xx_link, CHILD); \
+ Dispose(xx_link); \
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* DisposeChild(link) */
+ /* */
+ /* Delete link, and if its child is thereby unattached, dispose it. */
+ /* */
+ /*****************************************************************************/
+
+ #define DisposeChild(link) \
+ { xx_link = (link); \
+ xx_tmp = Delete(xx_link, PARENT); \
+ Delete(xx_link, CHILD); \
+ Dispose(xx_link); \
+ if( succ(xx_tmp, PARENT) == xx_tmp ) DisposeObject(xx_tmp); \
+ } /* end DisposeChild */
+
+
+ /*****************************************************************************/
+ /* */
+ /* MoveLink(link, x, dir) */
+ /* */
+ /* Move the dir end of link from wherever it is now to node x. */
+ /* */
+ /*****************************************************************************/
+
+ #define MoveLink(link, x, dir) \
+ ( xx_link = (link), \
+ Delete(xx_link, 1 - (dir) ), \
+ Append(xx_link, (x), 1 - (dir) ) \
+ ) /* end MoveLink */
+
+
+ /*@::TransferLinks(), DeleteNode(), etc.@*************************************/
+ /* */
+ /* TransferLinks(start_link, stop_link, dest_link) */
+ /* */
+ /* Move parent end of links start_link (inclusive) to stop_link (exclusive) */
+ /* to just before dest_link. */
+ /* */
+ /*****************************************************************************/
+
+ #define TransferLinks(start_link, stop_link, dest_link) \
+ { OBJECT xxstart = start_link, xxstop = stop_link, xxdest = dest_link; \
+ if( xxstart != xxstop ) \
+ { assert( type(xxstart) == LINK, "TransferLinks: start_link!" ); \
+ Append(xxstart, xxstop, CHILD); /* actually a split */ \
+ Append(xxstart, xxdest, CHILD); \
+ } \
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* DeleteNode(x) */
+ /* */
+ /* Delete node x and every edge attaching to x. */
+ /* */
+ /*****************************************************************************/
+
+ #define DeleteNode(x) \
+ { xx_hold = (x); \
+ while( Up(xx_hold) != xx_hold ) DeleteLink( Up(xx_hold) ); \
+ while( Down(xx_hold) != xx_hold ) DeleteLink( Down(xx_hold) ); \
+ Dispose(xx_hold); \
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* MergeNode(x, y) */
+ /* */
+ /* Take all the children of y and make them children of x. */
+ /* Take all the parents of y and make them parents of x. Dispose y. */
+ /* */
+ /*****************************************************************************/
+
+ #define MergeNode(x, y) \
+ { xx_res = (x); xx_hold = (y); \
+ xx_tmp = Delete(xx_hold, PARENT); \
+ Append(xx_res, xx_tmp, PARENT); \
+ xx_tmp = Delete(xx_hold, CHILD); \
+ Append(xx_res, xx_tmp, CHILD); \
+ Dispose(xx_hold); \
+ } /* end MergeNode */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ReplaceNode(x, y) */
+ /* */
+ /* Move all the parent links of y to x. */
+ /* */
+ /*****************************************************************************/
+
+ #define ReplaceNode(x, y) \
+ ( xx_tmp = Delete((y), PARENT), \
+ Append((x), xx_tmp, PARENT) \
+ ) /* end ReplaceNode */
+
+
+ /*@::FirstDefinite(), NextDefinite(), etc.@***********************************/
+ /* */
+ /* FirstDefinite(x, link, y, jn) */
+ /* */
+ /* On input, x is an object and link and y are undefined. On output there */
+ /* are two cases: */
+ /* */
+ /* link != x. Then y is first definite child of x and link is its link; */
+ /* jn is TRUE iff all gaps on the way to link were joined. */
+ /* */
+ /* link == x. Then x has no definite child and y is undefined. */
+ /* */
+ /* A SPLIT object is considered to be definite if both its children are */
+ /* definite. This condition is returned by SplitIsDefinite. */
+ /* */
+ /*****************************************************************************/
+
+ #define FirstDefinite(x, link, y, jn) \
+ { jn = TRUE; \
+ for( link = Down(x); link != x; link = NextDown(link) ) \
+ { Child(y, link); \
+ if( type(y) == GAP_OBJ ) jn = jn && join(gap(y)); \
+ else if( type(y)==SPLIT ? SplitIsDefinite(y) : is_definite(type(y)))\
+ break; \
+ } \
+ } /* end FirstDefinite */
+
+
+ /*****************************************************************************/
+ /* */
+ /* NextDefinite(x, link, y) */
+ /* */
+ /* On input, x is an object and link is a link to one of its children; y */
+ /* is undefined. On output there are two cases: */
+ /* */
+ /* link != x. Then y is the first definite child of x following link, and */
+ /* link is changed to be the link of y. */
+ /* */
+ /* link == x. Then x has no definite child following link, and y remains */
+ /* undefined. */
+ /* */
+ /*****************************************************************************/
+
+ #define NextDefinite(x, link, y) \
+ { for( link = NextDown(link); link != x; link = NextDown(link) ) \
+ { Child(y, link); \
+ if( type(y) == SPLIT ? SplitIsDefinite(y) : is_definite(type(y)) ) \
+ break; \
+ } \
+ } /* end NextDefinite */
+
+
+ /*****************************************************************************/
+ /* */
+ /* NextDefiniteWithGap(x, link, y, g, jn) */
+ /* */
+ /* On input, x is an object and link is a link to one of its children; y */
+ /* and g are undefined. On output there are two cases: */
+ /* */
+ /* link != x. Then y is the first definite child of x following link, and */
+ /* link is changed to be the link of y. Also, g is defined */
+ /* to be the gap just before y; this must exist and is tested */
+ /* by an assert test; and jn is true iff all of the gaps on */
+ /* the way from old link to new link are join gaps. */
+ /* */
+ /* link == x. Then x has no definite child following link, and y and g */
+ /* remain undefined. */
+ /* */
+ /*****************************************************************************/
+
+ #define NextDefiniteWithGap(x, link, y, g, jn) \
+ { g = nilobj; jn = TRUE; \
+ for( link = NextDown(link); link != x; link = NextDown(link) ) \
+ { Child(y, link); \
+ if( type(y) == GAP_OBJ ) g = y, jn = jn && join(gap(y)); \
+ else if( type(y)==SPLIT ? SplitIsDefinite(y):is_definite(type(y)) ) \
+ { \
+ debug2(DFS, D, " NextDefiniteWithGap at %s %s", \
+ Image(type(y)), EchoObject(y)); \
+ assert( g != nilobj, "NextDefiniteWithGap: g == nilobj!" ); \
+ break; \
+ } \
+ } \
+ } /* end NextDefiniteWithGap */
+
+ /*@@**************************************************************************/
+ /* */
+ /* LastDefinite(x, link, y) */
+ /* */
+ /* On input, x is an object and link and y are undefined. On output there */
+ /* are two cases: */
+ /* */
+ /* link != x. Then y is the last definite child of x and link is its link. */
+ /* */
+ /* link == x. Then x has no definite child and y is undefined. */
+ /* */
+ /* A SPLIT object is considered to be definite if both its children are */
+ /* definite. This condition is returned by SplitIsDefinite. */
+ /* */
+ /*****************************************************************************/
+
+ #define LastDefinite(x, link, y) \
+ { for( link = LastDown(x); link != x; link = PrevDown(link) ) \
+ { Child(y, link); \
+ if( type(y) == SPLIT ? SplitIsDefinite(y) : is_definite(type(y)) ) \
+ break; \
+ } \
+ } /* end LastDefinite */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PrevDefinite(x, link, y) */
+ /* */
+ /* On input, x is an object and link is a link to one of its children; y */
+ /* is undefined. On output there are two cases: */
+ /* */
+ /* link != x. Then y is the first definite child of x preceding link, and */
+ /* link is changed to be the link of y. */
+ /* */
+ /* link == x. Then x has no definite child preceding link, and y remains */
+ /* undefined. */
+ /* */
+ /*****************************************************************************/
+
+ #define PrevDefinite(x, link, y) \
+ { for( link = PrevDown(link); link != x; link = PrevDown(link) ) \
+ { Child(y, link); \
+ if( type(y) == SPLIT ? SplitIsDefinite(y) : is_definite(type(y)) ) \
+ break; \
+ } \
+ } /* end PrevDefinite */
+
+
+ /*@::Module Declarations@*****************************************************/
+ /* */
+ /* MODULE DECLARATIONS */
+ /* */
+ /*****************************************************************************/
+
+ /***** z01.c Supervise **************************************/
+ extern int main(int argc, char *argv[]);
+ extern POINTER MemCheck;
+ extern OBJECT StartSym;
+ extern OBJECT GalleySym;
+ extern OBJECT ForceGalleySym;
+ extern OBJECT InputSym;
+ extern OBJECT PrintSym;
+ extern OBJECT FilterInSym;
+ extern OBJECT FilterOutSym;
+ extern OBJECT FilterErrSym;
+ extern OBJECT VerbatimSym;
+ extern OBJECT RawVerbatimSym;
+ extern OBJECT OptGallSym;
+ extern BACK_END BackEnd;
+ extern OBJECT CommandOptions;
+ extern BOOLEAN AllowCrossDb;
+ extern BOOLEAN UseCollate;
+ extern BOOLEAN InMemoryDbIndexes;
+ extern BOOLEAN Kern;
+ extern BOOLEAN SafeExecution;
+ extern BOOLEAN AltErrorFormat;
+ extern int TotalWordCount;
+ extern BOOLEAN InitializeAll;
+ #if LOCALE_ON
+ extern nl_catd MsgCat;
+ #endif
+
+ /***** z02.c Lexical Analyser **************************************/
+ extern BOOLEAN LexLegalName(FULL_CHAR *str);
+ extern void LexInit(void);
+ extern void LexPush(FILE_NUM x, int offs, int ftyp, int lnum, BOOLEAN same);
+ extern void LexPop(void);
+ extern long LexNextTokenPos(void);
+ extern OBJECT LexGetToken(void);
+ extern OBJECT LexScanVerbatim(FILE *fp, BOOLEAN end_stop, FILE_POS *err_pos,
+ BOOLEAN lessskip);
+
+ /***** z03.c File Service **************************************/
+ extern FILE_POS *no_fpos;
+ extern void InitFiles(void);
+ extern void AddToPath(int fpath, OBJECT dirname);
+ extern FILE_NUM DefineFile(FULL_CHAR *str, FULL_CHAR *suffix,
+ FILE_POS *xfpos, int ftype, int fpath);
+ extern FILE_NUM FirstFile(int ftype);
+ extern FILE_NUM NextFile(FILE_NUM i);
+ extern FILE_NUM FileNum(FULL_CHAR *str, FULL_CHAR *suffix);
+ extern FILE_NUM DatabaseFileNum(FILE_POS *xfpos);
+ extern FULL_CHAR *FileName(FILE_NUM fnum);
+ extern FULL_CHAR *FullFileName(FILE_NUM fnum);
+ extern FULL_CHAR *EchoFilePos(FILE_POS *pos);
+ extern FULL_CHAR *EchoAltFilePos(FILE_POS *pos);
+ extern FULL_CHAR *EchoFileSource(FILE_NUM fnum);
+ extern FULL_CHAR *EchoFileLine(FILE_POS *pos);
+ extern FILE_POS *PosOfFile(FILE_NUM fnum);
+ extern FILE *OpenFile(FILE_NUM fnum, BOOLEAN check_ld, BOOLEAN check_lt);
+ extern FILE *OpenIncGraphicFile(FULL_CHAR *str, unsigned char typ,
+ OBJECT *full_name, FILE_POS *xfpos, BOOLEAN *compressed);
+ extern void FileSetUpdated(FILE_NUM fnum, int newlines);
+ extern int FileGetLineCount(FILE_NUM fnum);
+ extern BOOLEAN FileTestUpdated(FILE_NUM fnum);
+
+ /***** z04.c Token Service **************************************/
+ extern OBJECT NewToken(unsigned char xtype, FILE_POS *xfpos,
+ unsigned char xvspace, unsigned char xhspace,
+ unsigned char xprec, OBJECT xactual);
+ extern OBJECT CopyTokenList(OBJECT x, FILE_POS *pos);
+ extern FULL_CHAR *EchoCatOp(unsigned xtype, BOOLEAN xmark, BOOLEAN xjoin);
+ extern FULL_CHAR *EchoToken(OBJECT x);
+
+ /***** z05.c Read Definitions **************************************/
+ extern void ReadPrependDef(unsigned typ, OBJECT encl);
+ extern void ReadDatabaseDef(unsigned typ, OBJECT encl);
+ extern void ReadDefinitions(OBJECT *token, OBJECT encl,
+ unsigned char res_type);
+
+ /***** z06.c Object Parser **************************************/
+ extern void SetScope(OBJECT env, int *count, BOOLEAN vis_only);
+ extern void InitParser(FULL_CHAR *cross_db);
+ extern OBJECT Parse(OBJECT *token, OBJECT encl, BOOLEAN defs_allowed,
+ BOOLEAN transfer_allowed);
+
+ /***** z07.c Object Service **************************************/
+ extern BOOLEAN SplitIsDefinite(OBJECT x);
+ extern int DisposeObject(OBJECT x);
+ extern OBJECT MakeWord(unsigned typ, FULL_CHAR *str, FILE_POS *pos);
+ extern OBJECT MakeWordTwo(unsigned typ, FULL_CHAR *str1, FULL_CHAR *str2,
+ FILE_POS *pos);
+ extern OBJECT MakeWordThree(FULL_CHAR *s1, FULL_CHAR *s2, FULL_CHAR *s3);
+ extern OBJECT CopyObject(OBJECT x, FILE_POS *pos);
+ extern OBJECT InsertObject(OBJECT x, OBJECT *ins, STYLE *style);
+ extern OBJECT Meld(OBJECT x, OBJECT y);
+
+ /***** z08.c Object Manifest **************************************/
+ extern OBJECT ReplaceWithTidy(OBJECT x, BOOLEAN one_word);
+ extern OBJECT Manifest(OBJECT x, OBJECT env, STYLE *style, OBJECT bthr[2],
+ OBJECT fthr[2], OBJECT *target, OBJECT *crs, BOOLEAN ok,
+ BOOLEAN need_expand, OBJECT *enclose, BOOLEAN fcr);
+
+ /***** z09.c Closure Expansion **************************************/
+ extern OBJECT SearchEnv(OBJECT env, OBJECT sym);
+ extern OBJECT SetEnv(OBJECT x, OBJECT y);
+ extern void AttachEnv(OBJECT env, OBJECT x);
+ extern OBJECT GetEnv(OBJECT x);
+ extern OBJECT DetachEnv(OBJECT x);
+ extern OBJECT ClosureExpand(OBJECT x, OBJECT env, BOOLEAN crs_wanted,
+ OBJECT *crs, OBJECT *res_env);
+ extern OBJECT ParameterCheck(OBJECT x, OBJECT env);
+
+ /***** z10.c Cross References **************************************/
+ extern void CrossInit(OBJECT sym);
+ extern OBJECT CrossMake(OBJECT sym, OBJECT val, int ctype);
+ extern OBJECT GallTargEval(OBJECT sym, FILE_POS *dfpos);
+ extern void CrossAddTag(OBJECT x);
+ extern OBJECT CrossExpand(OBJECT x, OBJECT env, STYLE *style,
+ OBJECT *crs, OBJECT *res_env);
+ extern void CrossSequence(OBJECT x);
+ extern void CrossClose(void);
+
+ /***** z11.c Style Service **************************************/
+ extern FULL_CHAR *EchoStyle(STYLE *style);
+ extern void SpaceChange(STYLE *style, OBJECT x);
+ extern void BreakChange(STYLE *style, OBJECT x);
+ extern void YUnitChange(STYLE *style, OBJECT x);
+ extern void ZUnitChange(STYLE *style, OBJECT x);
+
+ /***** z12.c Size Finder **************************************/
+ extern void SpannerAvailableSpace(OBJECT y, int dim, FULL_LENGTH *resb,
+ FULL_LENGTH *resf);
+ extern OBJECT MinSize(OBJECT x, int dim, OBJECT *extras);
+
+ /***** z13.c Object Breaking **************************************/
+ extern OBJECT BreakObject(OBJECT x, CONSTRAINT *c);
+
+ /***** z14.c Object Filling **************************************/
+ extern OBJECT FillObject(OBJECT x, CONSTRAINT *c, OBJECT multi,
+ BOOLEAN can_hyphenate, BOOLEAN allow_shrink,
+ BOOLEAN extend_unbreakable, BOOLEAN *hyph_used);
+
+ /***** z15.c Size Constraints **************************************/
+ extern void MinConstraint(CONSTRAINT *xc, CONSTRAINT *yc);
+ extern void SetSizeToMaxForwardConstraint(FULL_LENGTH *b, FULL_LENGTH *f,
+ CONSTRAINT *c);
+ extern void EnlargeToConstraint(FULL_LENGTH *b, FULL_LENGTH *f,
+ CONSTRAINT *c);
+ extern int ScaleToConstraint(FULL_LENGTH b, FULL_LENGTH f,
+ CONSTRAINT *c);
+ extern void InvScaleConstraint(CONSTRAINT *yc, FULL_LENGTH sf,
+ CONSTRAINT*xc);
+ extern void RotateConstraint(CONSTRAINT *c, OBJECT y, FULL_LENGTH angle,
+ CONSTRAINT *hc, CONSTRAINT *vc, int dim);
+ extern BOOLEAN InsertScale(OBJECT x, CONSTRAINT *c);
+ extern void Constrained(OBJECT x, CONSTRAINT *xc, int dim, OBJECT *why);
+ extern FULL_CHAR *EchoConstraint(CONSTRAINT *c);
+ extern void DebugConstrained(OBJECT x);
+
+ /***** z16.c Size Adjustments **************************************/
+ extern FULL_LENGTH FindShift(OBJECT x, OBJECT y, int dim);
+ extern void SetNeighbours(OBJECT link, BOOLEAN ratm, OBJECT *pg,
+ OBJECT *pdef, OBJECT *sg, OBJECT *sdef, int *side);
+ extern void AdjustSize(OBJECT x, FULL_LENGTH b, FULL_LENGTH f, int dim);
+
+ /***** z17.c Gap Widths **************************************/
+ extern void GetGap(OBJECT x, STYLE *style, GAP *res_gap,
+ unsigned *res_inc);
+ extern FULL_LENGTH MinGap(FULL_LENGTH a, FULL_LENGTH b, FULL_LENGTH c, GAP *xgap);
+ extern FULL_LENGTH ExtraGap(FULL_LENGTH a, FULL_LENGTH b, GAP *xgap, int dir);
+ extern FULL_LENGTH ActualGap(FULL_LENGTH a, FULL_LENGTH b, FULL_LENGTH c,
+ GAP *xgap, FULL_LENGTH f, FULL_LENGTH mk);
+ extern FULL_CHAR *EchoGap(GAP *xgap);
+
+ /***** z18.c Galley Transfer **************************************/
+ extern STYLE InitialStyle;
+ extern OBJECT InitialEnvironment;
+ extern void TransferInit(OBJECT InitEnv);
+ extern OBJECT TransferBegin(OBJECT x);
+ extern void TransferComponent(OBJECT x);
+ extern void TransferEnd(OBJECT x);
+ extern void TransferClose(void);
+
+ /***** z19.c Galley Attaching **************************************/
+ extern void DetachGalley(OBJECT hd);
+ extern OBJECT SearchGalley(OBJECT start, OBJECT sym, BOOLEAN forwards,
+ BOOLEAN subgalleys, BOOLEAN closures, BOOLEAN input);
+ extern int AttachGalley(OBJECT hd, OBJECT *inners, OBJECT *suspend_pt);
+
+ /***** z20.c Galley Flushing **************************************/
+ extern FULL_CHAR *DebugInnersNames(OBJECT inners);
+ extern void FlushGalley(OBJECT hd);
+
+ /*** z21.c Galley Maker **************************************/
+ extern void SizeGalley(OBJECT hd, OBJECT env, BOOLEAN rows,
+ BOOLEAN joined, BOOLEAN nonblock, BOOLEAN trig,
+ STYLE *style, CONSTRAINT *c, OBJECT target,
+ OBJECT *dest_index, OBJECT *recs, OBJECT *inners,
+ OBJECT enclose);
+
+ /*** z22.c Galley Service **************************************/
+ extern void Interpose(OBJECT z, int typ, OBJECT x, OBJECT y);
+ extern void FlushInners(OBJECT inners, OBJECT hd);
+ extern void ExpandRecursives(OBJECT recs);
+ extern void HandleHeader(OBJECT hd, OBJECT header);
+ extern void Promote(OBJECT hd, OBJECT stop_link, OBJECT dest_index,
+ BOOLEAN join_after);
+ extern void KillGalley(OBJECT hd, BOOLEAN optimize);
+ extern void FreeGalley(OBJECT hd, OBJECT stop_link, OBJECT *inners,
+ OBJECT relocate_link, OBJECT sym);
+ extern void SetTarget(OBJECT hd);
+ extern int CheckComponentOrder(OBJECT preceder, OBJECT follower);
+
+ /***** z23.c Galley Printer **************************************/
+ extern OBJECT FixAndPrintObject(OBJECT x, FULL_LENGTH xmk, FULL_LENGTH xb,
+ FULL_LENGTH xf, int dim, BOOLEAN suppress, FULL_LENGTH pg,
+ int count, FULL_LENGTH *actual_back, FULL_LENGTH *actual_fwd);
+
+ /***** z24.c Print Service **************************************/
+ extern char *EightBitToPrintForm[];
+
+ /***** z25.c Object Echo **************************************/
+ extern FULL_CHAR *EchoObject(OBJECT x);
+ extern void DebugObject(OBJECT x);
+ extern FULL_CHAR *EchoIndex(OBJECT index);
+ extern void DebugGalley(OBJECT hd, OBJECT pinpt, int indent);
+
+ /***** z26.c Echo Service **************************************/
+ extern void BeginString(void);
+ extern void AppendString(FULL_CHAR *str);
+ extern FULL_CHAR *EndString(void);
+ extern FULL_CHAR *EchoLength(int len);
+ extern FULL_CHAR *Image(unsigned int c);
+ extern void SetLengthDim(int dim);
+
+ /***** z27.c Debug Service **************************************/
+ #if DEBUG_ON
+ extern void DebugInit(FULL_CHAR *str);
+ extern void Debug(int category, int urgency, char *str, ...);
+ extern void ProfileOn(char *str);
+ extern void ProfileOff(char *str);
+ extern void ProfilePrint(void);
+ #endif
+
+ /***** z28.c Error Service **************************************/
+ extern void ErrorInit(FULL_CHAR *str);
+ extern BOOLEAN ErrorSeen(void);
+ extern void EnterErrorBlock(BOOLEAN ok_to_print);
+ extern void LeaveErrorBlock(BOOLEAN commit);
+ extern void CheckErrorBlocks(void);
+ extern POINTER Error(int set_num, int msg_num, char *str, int etype,
+ FILE_POS *pos, ...);
+
+ /***** z29.c Symbol Table **************************************/
+ extern void InitSym(void);
+ extern void PushScope(OBJECT x, BOOLEAN npars, BOOLEAN vis);
+ extern void PopScope(void);
+ extern void SuppressVisible(void);
+ extern void UnSuppressVisible(void);
+ extern void SuppressScope(void);
+ extern void UnSuppressScope(void);
+ extern void SwitchScope(OBJECT sym);
+ extern void UnSwitchScope(OBJECT sym);
+ extern void BodyParAllowed(void);
+ extern void BodyParNotAllowed(void);
+ extern OBJECT GetScopeSnapshot(void);
+ extern void LoadScopeSnapshot(OBJECT ss);
+ extern void ClearScopeSnapshot(OBJECT ss);
+ extern OBJECT InsertSym(FULL_CHAR *str, unsigned char xtype,
+ FILE_POS *xfpos, unsigned char xprecedence,
+ BOOLEAN xindefinite, BOOLEAN xrecursive,
+ unsigned xpredefined, OBJECT xenclosing, OBJECT xbody);
+ extern void InsertAlternativeName(FULL_CHAR *str, OBJECT s,
+ FILE_POS *xfpos);
+ extern OBJECT SearchSym(FULL_CHAR *str, int len);
+ extern FULL_CHAR *SymName(OBJECT s);
+ extern FULL_CHAR *FullSymName(OBJECT x, FULL_CHAR *str);
+ extern OBJECT ChildSym(OBJECT s, unsigned typ);
+ extern OBJECT ChildSymWithCode(OBJECT s, unsigned char code);
+ extern void CheckSymSpread(void);
+ extern void DeleteEverySym(void);
+ extern void DebugScope(void);
+
+ /***** z30.c Symbol Uses **************************************/
+ extern void InsertUses(OBJECT x, OBJECT y);
+ extern void FlattenUses(void);
+ extern BOOLEAN SearchUses(OBJECT x, OBJECT y);
+ extern OBJECT FirstExternTarget(OBJECT sym, OBJECT *cont);
+ extern OBJECT NextExternTarget(OBJECT sym, OBJECT *cont);
+
+ /***** z31.c Memory Allocator **************************************/
+ extern void DebugRegisterUsage(int typ, int delta_num, int delta_size);
+ extern void DebugMemory(void);
+ extern void MemInit(void);
+ extern OBJECT GetMemory(int siz, FILE_POS *pos);
+ extern OBJECT zz_free[];
+ extern unsigned char zz_lengths[];
+ extern int zz_newcount;
+ extern int zz_disposecount;
+ extern int zz_listcount;
+ extern OBJECT zz_hold;
+ extern OBJECT zz_tmp;
+ extern OBJECT zz_res;
+ extern int zz_size;
+ extern OBJECT xx_link, xx_tmp;
+ extern OBJECT xx_hold, xx_res;
+
+ /***** z32.c Counter Service **********************************/
+ extern OBJECT Next(OBJECT x, int inc, BOOLEAN *done);
+
+ /***** z33.c Database Service **************************************/
+ extern OBJECT OldCrossDb;
+ extern OBJECT NewCrossDb;
+ extern OBJECT DbCreate(OBJECT x);
+ extern void DbInsert(OBJECT db, BOOLEAN gall, OBJECT sym, FULL_CHAR *tag,
+ FILE_POS *tagfpos, FULL_CHAR *seq, FILE_NUM dfnum,
+ long dfpos, int dlnum, BOOLEAN check);
+ extern void DbConvert(OBJECT db, BOOLEAN full_name);
+ extern void DbClose(OBJECT db);
+ extern OBJECT DbLoad(OBJECT stem, int fpath, BOOLEAN create, OBJECT symbs,
+ BOOLEAN in_memory);
+ extern BOOLEAN DbRetrieve(OBJECT db, BOOLEAN gall, OBJECT sym,
+ FULL_CHAR *tag, FULL_CHAR *seq, FILE_NUM *dfnum,
+ long *dfpos, int *dlnum, long *cont);
+ extern BOOLEAN DbRetrieveNext(OBJECT db, BOOLEAN *gall, OBJECT *sym,
+ FULL_CHAR *tag, FULL_CHAR *seq, FILE_NUM *dfnum,
+ long *dfpos, int *dlnum, long *cont);
+
+ /***** z34.c Rotation Service **************************************/
+ extern void RotateSize(FULL_LENGTH *xcb, FULL_LENGTH *xcf,
+ FULL_LENGTH *xrb, FULL_LENGTH *xrf, OBJECT y,
+ FULL_LENGTH theta);
+
+ /***** z35.c Time Keeper **************************************/
+ extern FULL_CHAR *TimeString(void);
+ extern void InitTime(void);
+ extern OBJECT MomentSym;
+ extern OBJECT StartMoment(void);
+
+ /***** z36.c Hyphenation **************************************/
+ extern BOOLEAN ReadHyphTable(LANGUAGE_NUM lnum);
+ extern OBJECT Hyphenate(OBJECT x);
+
+ /***** z37.c Font Service *************************************/
+ extern FONT_INFO *finfo;
+ extern int font_curr_page;
+ extern void FontInit(void);
+ extern void FontChange(STYLE *style, OBJECT x);
+ extern void FontWordSize(OBJECT x);
+ extern FULL_LENGTH FontSize(FONT_NUM fnum, OBJECT x);
+ extern FULL_LENGTH FontHalfXHeight(FONT_NUM fnum);
+ extern MAPPING FontMapping(FONT_NUM fnum, FILE_POS *xfpos);
+ extern FULL_CHAR *FontName(FONT_NUM fnum);
+ extern FULL_CHAR *FontFamily(FONT_NUM fnum);
+ extern FULL_CHAR *FontFace(FONT_NUM fnum);
+ extern FULL_CHAR *FontFamilyAndFace(FONT_NUM fnum);
+ extern void FontPrintAll(FILE *fp);
+ extern void FontPrintPageSetup(FILE *fp);
+ extern void FontPrintPageResources(FILE *fp);
+ extern void FontAdvanceCurrentPage(void);
+ extern void FontPageUsed(OBJECT face);
+ extern BOOLEAN FontNeeded(FILE *fp);
+
+ /***** z38.c Character Mappings **************************************/
+ extern MAP_VEC MapTable[];
+ extern MAPPING MapLoad(OBJECT filename, BOOLEAN recoded);
+ extern FULL_CHAR MapCharEncoding(FULL_CHAR *str, MAPPING m);
+ extern FULL_CHAR *MapEncodingName(MAPPING m);
+ extern void MapPrintEncodings();
+ extern void MapEnsurePrinted(MAPPING m, int curr_page);
+ extern void MapPrintPSResources(FILE *fp);
+ extern OBJECT MapSmallCaps(OBJECT x, STYLE *style);
+ extern BOOLEAN MapIsLowerCase(FULL_CHAR ch, MAPPING m);
+
+
+ /***** z39.c String Handler **************************************/
+ #define AsciiToFull(x) ( (FULL_CHAR *) (x) )
+ #define StringEqual(a, b) (strcmp((char *)(a), (char *)(b))==0)
+ extern int strcollcmp(char *a, char *b);
+ #define TabbedStringLessEqual(a, b) \
+ ( UseCollate ? strcollcmp((char *)(a),(char *)(b)) <= 0 \
+ : strcmp((char *)(a),(char *)(b)) <= 0 )
+ #define StringCat(a, b) strcat((char *)(a),(char *)(b))
+ #define StringCopy(a, b) strcpy((char *)(a),(char *)(b))
+ #define StringLength(a) strlen((char *)(a))
+ #define StringFOpen(a, b) fopen( (char *) (a), (b) )
+ #define StringFPuts(a, b) fputs( (char *) (a), (b) )
+ #define StringFGets(a, b, c) fgets( (char *) (a), (b), (c) )
+ #define StringRemove(a) remove((char *)(a))
+ #define StringRename(a, b) rename((char *)(a),(char *)(b))
+ extern BOOLEAN StringBeginsWith(FULL_CHAR *str, FULL_CHAR *pattern);
+ extern BOOLEAN StringEndsWith(FULL_CHAR *str, FULL_CHAR *pattern);
+ extern BOOLEAN StringContains(FULL_CHAR *str, FULL_CHAR *pattern);
+ extern FULL_CHAR *StringInt(int i);
+ extern FULL_CHAR *StringFiveInt(int i);
+ extern FULL_CHAR *StringQuotedWord(OBJECT x);
+
+ /***** z40.c Filter Handler **************************************/
+ extern void FilterInit(void);
+ extern OBJECT FilterCreate(BOOLEAN use_begin, OBJECT act, FILE_POS *xfpos);
+ extern void FilterSetFileNames(OBJECT x);
+ extern OBJECT FilterExecute(OBJECT x, FULL_CHAR *command, OBJECT env);
+ extern void FilterWrite(OBJECT x, FILE *fp, int *linecount);
+ extern void FilterScavenge(BOOLEAN all);
+
+ /***** z41.c Object Input-Output **************************************/
+ extern OBJECT ReadFromFile(FILE_NUM fnum, long pos, int lnum);
+ extern void AppendToFile(OBJECT x, FILE_NUM fnum, int *pos, int *lnum);
+ extern void CloseFiles(void);
+
+ /***** z42.c Colour Service **************************************/
+ extern void ColourInit(void);
+ extern void ColourChange(STYLE *style, OBJECT x);
+ extern FULL_CHAR *ColourCommand(COLOUR_NUM cnum);
+
+ /***** z43.c Language Service **************************************/
+ extern void LanguageInit(void);
+ extern BOOLEAN LanguageWordEndsSentence(OBJECT wd, BOOLEAN lc_prec);
+ extern void LanguageDefine(OBJECT names, OBJECT hyph_file);
+ extern void LanguageChange(STYLE *style, OBJECT x);
+ extern FULL_CHAR *LanguageString(LANGUAGE_NUM lnum);
+ extern OBJECT LanguageHyph(LANGUAGE_NUM lnum);
+ extern BOOLEAN LanguageSentenceEnds[];
+
+ /***** z44.c Vertical Hyphenation **************************************/
+ extern BOOLEAN VerticalHyphenate(OBJECT y);
+ extern OBJECT ConvertGalleyList(OBJECT x);
+ extern OBJECT BuildEnclose(OBJECT hd);
+
+ /***** z45.c External Sort **************************************/
+ extern LINE *ReadLines(FILE *fp, FULL_CHAR *fname, FULL_CHAR *first_line, int *len);
+ extern void WriteLines(FILE *fp, LINE *lines, int len);
+ extern void SortLines(LINE *lines, int lines_len);
+ extern void SortFile(FULL_CHAR *infile, FULL_CHAR *outfile);
+
+ /***** z46.c Optimal Galleys **************************************/
+ extern BOOLEAN FindOptimize(OBJECT x, OBJECT env);
+ extern void SetOptimize(OBJECT hd, STYLE *style);
+ extern void GazumpOptimize(OBJECT hd, OBJECT dest);
+ extern void CalculateOptimize(OBJECT hd);
+ extern void DebugOptimize(OBJECT hd);
+
+ /***** z47.c Environment Table **************************************/
+ extern void EnvInit(void);
+ extern BOOLEAN EnvWriteRetrieve(OBJECT env, FILE_NUM fnum, int *offset,
+ int *lnum);
+ extern void EnvWriteInsert(OBJECT env, FILE_NUM fnum, int offset,int lnum);
+ extern BOOLEAN EnvReadRetrieve(FILE_NUM fnum, int offset, OBJECT *env);
+ extern void EnvReadInsert(FILE_NUM fnum, int offset, OBJECT env);
+ extern void EnvDebug(void);
+
+ /***** z48.c PDF back end (old) **************************************/
+ extern void PDFFile_Init(FILE* in_fp, int in_h_bound, int in_v_bound,
+ int in_IN, int in_CM, int in_PT, int in_EM);
+ extern void PDFFile_BeginFontEncoding(FILE* in_fp,
+ const char* in_encoding_name);
+ extern void PDFFile_EndFontEncoding(FILE* in_fp);
+ extern void PDFFile_Cleanup(FILE* in_fp);
+ extern void PDFPage_Init(FILE* in_fp, float in_scale_factor,
+ int in_line_width);
+ extern void PDFPage_Cleanup(FILE* in_fp);
+ extern void PDFPage_Write(FILE* in_fp, char* in_str);
+ extern void PDFPage_Push(FILE* in_fp);
+ extern void PDFPage_Pop(FILE* in_fp);
+ extern void PDFPage_Scale(FILE* in_fp, float in_h_scale_factor,
+ float in_v_scale_factor);
+ extern void PDFPage_Translate(FILE* in_fp, float in_delta_h,
+ float in_delta_v);
+ extern void PDFPage_Rotate(FILE* in_fp, float in_angle_in_radians);
+ extern void PDFPage_SetVars(int xsize, int ysize, int xmark, int ymark,
+ int loutf, int loutv, int louts);
+ extern void PDFPage_WriteGraphic(FILE* in_fp, FULL_CHAR* in_str);
+ extern void PDFPage_PrintUnderline(FILE* in_fp, int in_x1, int in_x2,
+ int in_y, int in_thickness);
+
+ extern void PDFFont_AddFont(
+ FILE* in_fp,
+ const FULL_CHAR* in_short_font_name,
+ const FULL_CHAR* in_real_font_name,
+ const FULL_CHAR* in_font_encoding_name);
+ extern void PDFFont_Set(FILE* in_fp, FULL_LENGTH in_font_size,
+ FULL_CHAR * in_short_font_name);
+ extern void PDFText_OpenXY(FILE* in_fp, int hpos, int vpos);
+ extern void PDFText_OpenX(FILE* in_fp, int hpos);
+ extern void PDFText_Open(FILE* in_fp);
+ extern void PDFText_Kern(FILE* in_fp, int in_kern);
+ extern void PDFText_Close(FILE* in_fp);
+ extern BOOLEAN PDFHasValidTextMatrix(void);
+
+ /***** z49.c PostScript back end **************************************/
+ extern BOOLEAN Encapsulated; /* TRUE if EPS file is wanted */
+ extern BACK_END PS_BackEnd; /* PostScript back end record */
+
+ /***** z50.c PDF back end (new) **************************************/
+ extern BACK_END PDF_BackEnd; /* PDF back end record */
+
+ /***** z51.c Plain text back end **************************************/
+ extern BACK_END Plain_BackEnd; /* Plain Text back end record */
+ extern FULL_LENGTH PlainCharWidth; /* character width */
+ extern FULL_LENGTH PlainCharHeight; /* character height */
+ extern BOOLEAN PlainFormFeed; /* true if using \f */
+
+ /*@::assert(), debug(), debug flags@******************************************/
+ /* */
+ /* ASSERT AND DEBUG CODE */
+ /* */
+ /*****************************************************************************/
+
+ #if ASSERT_ON
+ #define assert(c, m) \
+ { if( !(c) ) Error(1, 2, "assert failed in %s", INTERN, no_fpos, m); }
+ #define assert1(c, m, p1) \
+ { if( !(c) ) Error(1, 3, "assert failed in %s %s", INTERN,no_fpos,m, p1); }
+ #else
+ #define assert(c, m)
+ #define assert1(c, m, p1)
+ #endif
+
+ #if DEBUG_ON
+
+ struct dbs
+ { char *flag; /* external names for debug flags */
+ BOOLEAN on[3]; /* the debug flags */
+ };
+ extern struct dbs dbg[];
+
+ /* debug routines */
+ #define debug0(cat, urg, str) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str); }
+ #define debug1(cat, urg, str, p1) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1); }
+ #define debug2(cat, urg, str, p1, p2) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2); }
+ #define debug3(cat, urg, str, p1, p2, p3) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3); }
+ #define debug4(cat, urg, str, p1, p2, p3, p4) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3, p4); }
+ #define debug5(cat, urg, str, p1, p2, p3, p4, p5) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3, p4, p5); }
+ #define debug6(cat, urg, str, p1, p2, p3, p4, p5, p6) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3, p4, p5, p6); }
+ #define debug7(cat, urg, str, p1, p2, p3, p4, p5, p6, p7) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3, p4, p5,p6,p7); }
+ #define debug8(cat, urg, str, p1, p2, p3, p4, p5, p6, p7, p8) \
+ { if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2,p3,p4,p5,p6,p7,p8); }
+ #define ifdebug(cat, urg, x) \
+ { if( dbg[cat].on[urg] ) { x; } }
+
+ #define debugcond0(cat, urg, cond, str) \
+ { if( dbg[cat].on[urg] && cond ) Debug(cat, urg, str); }
+ #define debugcond1(cat, urg, cond, str, p1) \
+ { if( dbg[cat].on[urg] && cond ) Debug(cat, urg, str, p1); }
+ #define debugcond2(cat, urg, cond, str, p1, p2) \
+ { if( dbg[cat].on[urg] && cond ) Debug(cat, urg, str, p1, p2); }
+ #define debugcond3(cat, urg, cond, str, p1, p2, p3) \
+ { if( dbg[cat].on[urg] && cond ) Debug(cat, urg, str, p1, p2, p3); }
+ #define debugcond4(cat, urg, cond, str, p1, p2, p3, p4) \
+ { if( dbg[cat].on[urg] && cond ) Debug(cat, urg, str, p1, p2, p3, p4); }
+ #define debugcond5(cat, urg, cond, str, p1, p2, p3, p4, p5) \
+ { if( dbg[cat].on[urg] && cond ) Debug(cat, urg, str, p1, p2, p3, p4, p5);}
+ #define debugcond6(cat, urg, cond, str, p1, p2, p3, p4, p5, p6) \
+ { if( dbg[cat].on[urg] && cond ) Debug(cat, urg, str, p1, p2,p3,p4,p5,p6);}
+ #define ifdebugcond(cat, urg, cond, x) \
+ { if( dbg[cat].on[urg] && cond ) { x; } }
+ #define debug_init(str) \
+ DebugInit(str)
+
+ /* debug styles */
+ #define D 0
+ #define DD 1
+ #define DDD 2
+
+ /* debug flags */
+ #define DSP 1 /* z01.c -dsp Supervise */
+ #define DLA 2 /* z02.c -dla Lexical Analyser */
+ #define DFS 3 /* z03.c -dfs File Service */
+ #define DTS 4 /* z04.c -dts Token Service */
+ #define DRD 5 /* z05.c -drd Read Definitions */
+ #define DOP 6 /* z06.c -dop Object Parser */
+ #define DOS 7 /* z07.c -dos Object Service */
+ #define DOM 8 /* z08.c -dom Object Manifest */
+ #define DCE 9 /* z09.c -dce Closure Expansion */
+ #define DCR 10 /* z10.c -dcr Cross References */
+ #define DSS 11 /* z11.c -dss Style Service */
+ #define DSF 12 /* z12.c -dsf Size Finder */
+ #define DOB 13 /* z13.c -dob Object Breaking */
+ #define DOF 14 /* z14.c -dof Object Filling */
+ #define DSC 15 /* z15.c -dsc Size Constraints */
+ #define DSA 16 /* z16.c -dsa Size Adjustments */
+ #define DGW 17 /* z17.c -dgw Gap Widths */
+ #define DGT 18 /* z18.c -dgt Galley Transfer */
+ #define DGA 19 /* z19.c -dgf Galley Attaching */
+ #define DGF 20 /* z20.c -dgf Galley Flushing */
+ #define DGM 21 /* z21.c -dgm Galley Maker */
+ #define DGS 22 /* z22.c -dgs Galley Service */
+ #define DGP 23 /* z23.c -dgp Galley Printer */
+ #define DPS 24 /* z24.c -dps Print Service */
+ #define DOE 25 /* z25.c -doe Object Echo */
+ #define DES 26 /* z26.c -des Echo Service */
+ #define DZZ 27 /* z27.c -dzz Debug Service */
+ #define DYY 28 /* z28.c -dyy Error Service */
+ #define DST 29 /* z29.c -dst Symbol Table */
+ #define DSU 30 /* z30.c -dsu Symbol Uses */
+ #define DMA 31 /* z31.c -dma Memory Allocator */
+ #define DCS 32 /* z32.c -dcs Counter Service */
+ #define DBS 33 /* z33.c -dbs Database Service */
+ #define DRS 34 /* z34.c -drs Rotation Service */
+ #define DTK 35 /* z35.c -dtk Time Keeper */
+ #define DHY 36 /* z36.c -dhy Hyphenation */
+ #define DFT 37 /* z37.c -dft Font Service */
+ #define DCM 38 /* z38.c -dcm Character Mapping */
+ #define DSH 39 /* z39.c -dsh String Handler */
+ #define DFH 40 /* z40.c -dsh Filter Handler */
+ #define DIO 41 /* z41.c -dio Object Input-Output */
+ #define DCO 42 /* z42.c -dco Colour Service */
+ #define DLS 43 /* z43.c -dls Language Service */
+ #define DVH 44 /* z44.c -dvh Vertical Hyphenation */
+ #define DEX 45 /* z45.c -dex External Sort */
+ #define DOG 46 /* z46.c -dex Optimal Galleys */
+ #define DET 47 /* z47.c -det Environment Table */
+ #define DPD 48 /* z48.c -dpd PDF Back End (old) */
+ #define DPO 49 /* z49.c -dpo PostScript Back End */
+ #define DPF 50 /* z50.c -dpf PDF Back End */
+ #define DPT 51 /* z51.c -dpt Plain Text Back End */
+ #define DPP 52 /* -dpp Profiling */
+ #define ANY 53 /* -d any */
+
+ #else
+ #define ifdebug(cat, urg, x)
+ #define debug0(cat, urg, str)
+ #define debug1(cat, urg, str, p1)
+ #define debug2(cat, urg, str, p1, p2)
+ #define debug3(cat, urg, str, p1, p2, p3)
+ #define debug4(cat, urg, str, p1, p2, p3, p4)
+ #define debug5(cat, urg, str, p1, p2, p3, p4, p5)
+ #define debug6(cat, urg, str, p1, p2, p3, p4, p5, p6)
+ #define debug7(cat, urg, str, p1, p2, p3, p4, p5, p6, p7)
+ #define debug8(cat, urg, str, p1, p2, p3, p4, p5, p6, p7, p8)
+
+ #define debugcond0(cat, urg, cond, str)
+ #define debugcond1(cat, urg, cond, str, p1)
+ #define debugcond2(cat, urg, cond, str, p1, p2)
+ #define debugcond3(cat, urg, cond, str, p1, p2, p3)
+ #define debugcond4(cat, urg, cond, str, p1, p2, p3, p4)
+ #define debugcond5(cat, urg, cond, str, p1, p2, p3, p4, p5)
+ #define debugcond6(cat, urg, cond, str, p1, p2, p3, p4, p5, p6)
+ #define ifdebugcond(cat, urg, cond, x)
+ #define debug_init(str) Error(1, 4, "%s - debug flags not implemented", \
+ FATAL, no_fpos, str)
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/large.lout
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/large.lout:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/large.lout Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,502 ----
+ @SysInclude { tbl }
+ @SysInclude { doc }
+ def @HeaderA right x { @CD +8p @Font { x } }
+ def @HeaderB right x { @CD +6p @Font { x } }
+ def @HeaderC right x { @CD +4p @Font { x } }
+ def @HeaderD right x { @CD +2p @Font { x } }
+ def @HeaderE right x { @CD -1p @Font { x } }
+ def @HeaderF right x { @CD -2p @Font { x } }
+ # Created by HTML::LoutParser.pm on 2001/06/28 from SimpleScalar.htm.
+ @Doc @Text @Begin
+ #DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
+
+ # saved from url=(0041)http://www.simplescalar.org/overview.html
+
+ #start html
+ #start head
+
+ @InitialBreak {adjust 1.2fx hyphen}
+
+ @CentredDisplay { +10p } @Font {#start title
+ SimpleScalar Tools Overview Page}
+ #end title
+
+ #unhandled start meta attributes= (content=>text/html; charset=iso-8859-1), (http-equiv=>Content-Type)
+
+ #unhandled start meta attributes= (name=>GENERATOR), (content=>MSHTML 5.50.4616.200)
+ #end head
+
+ #start body attributes= (background=>SimpleScalar_files/whitevellum.gif)
+
+ { clines } @Break {
+ #start center
+
+
+ @HeaderB {#start h2
+ { Times Base 10p } @Font {#start font attributes= (color=>#006aff)
+ Announcements}
+ #end font
+ }
+ #end h2
+ }
+ #end center
+
+
+ @BulletList
+ #start ul
+
+
+ @ListItem {#start li
+
+
+ @HeaderC {#start h3
+ New web pages!}
+ #end h3
+ The new domain and mailing lists are just about up!
+
+ @PP
+ #start p
+ @LLP
+ #end p
+ #end li
+ }
+
+ @EndList
+ #end ul
+
+
+ @PP
+ #start p
+
+ @LLP
+ #start br
+
+
+ @LLP @FullWidthRule @LLP
+ #start hr
+
+
+ @PP
+ #start p
+
+ { clines } @Break {
+ #start center
+
+
+ @HeaderB {#start h2
+ { Times Base 10p } @Font {#start font attributes= (color=>#006aff)
+ SimpleScalar Overview}
+ #end font
+ }
+ #end h2
+ }
+ #end center
+ {}@B {#start strong
+ What
+ is the SimpleScalar tool set? }
+ #end strong
+
+
+ @PP
+ #start p
+ This tool set consists of compiler, assembler, linker, simulation, and
+ visualization tools for the SimpleScalar architecture. With this tool set,
+ the
+ user can simulate real programs on a range of modern processors and
+ systems,
+ using fast execution-driven simulation. We provide simulators ranging from
+ a
+ fast functional simulator to a detailed, out-of-order issue processor that
+ supports non-blocking caches, speculative execution, and state-of-the-art
+ branch
+ prediction. The tool set is partly derived from the GNU software
+ development
+ tools. It provides researchers with an easily extensible, portable,
+ high-performance test bed for systems design.
+
+ @PP
+ #start p
+ {}@B {#start strong
+ Who wrote the SimpleScalar tool set?}
+ #end strong
+
+
+ @PP
+ #start p
+ Much of the compiler tools are simply ports of the GNU software development
+ tools to the SimpleScalar architecture. The ports as well as the simulators
+ were
+ written by Todd Austin (while he was a Ph.D. student at the University of
+ Wisconsin-Madison, working in the Multiscalar Group under {}@Underline {#start a attributes= (href=>http://www.cs.wisc.edu/~sohi)
+ Guri Sohi}
+ #end a
+ ; he is now with Intel Corp.).
+ The tool set is now supported by {}@Underline {#start a attributes= (href=>http://www.cs.utexas.edu/users/dburger)
+ Doug Burger}
+ #end a
+ , who wrote the
+ documentation for both releases 1.0 and 2.0. Contributions have also been
+ made
+ by Manoj Franklin, {}@Underline {#start a attributes= (href=>http://www.cs.wisc.edu/~breach)
+ Scott Breach}
+ #end a
+ ,
+ and Kevin Skadron.
+
+ @PP
+ #start p
+ The development of this code was originally supported by grants from the
+ National Science Foundation (grant CCR-9303030 plus software capitalization
+ supplement) and the Office of Naval Research (grant N00014-93-1-0465). Many
+ sources, all appreciated, currently fund development on several fronts.
+
+ @PP
+ #start p
+ {}@B {#start strong
+ On which platforms does it run?}
+ #end strong
+
+
+ @PP
+ #start p
+ SimpleScalar should port easily to any 32-bit flavor of UNIX, particularly
+ those that support POSIX-compliant syscalls. The tools have been installed
+ (and
+ should cleanly build) on the following systems:
+
+ @PP
+ #start p
+
+ { clines } @Break {
+ #start center
+
+
+ @LLP
+ @Tbl
+ rule { yes }
+ aformat {@Cell A | @Cell B | @Cell C | @Cell D | @Cell E | @Cell F }
+ {
+ #start table
+
+ #unhandled start tbody
+
+ @Rowa
+ #start tr
+
+ A {#start td attributes= (width=>100)
+ {}@B {#start b
+ Architecture}
+ #end b
+ }
+ #end td
+
+ B {#start td
+ {}@B {#start b
+ Operating System}
+ #end b
+ }
+ #end td
+
+ C {#start td
+ {}@B {#start b
+ Compiler}
+ #end b
+ }
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ x86}
+ #end td
+
+ B {#start td
+ Free BSD 2.2}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ x86}
+ #end td
+
+ B {#start td
+ CygWin32"/"Windows NT}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ x86}
+ #end td
+
+ B {#start td
+ Linux1.3}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ x86}
+ #end td
+
+ B {#start td
+ Solaris2}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ SPARC}
+ #end td
+
+ B {#start td
+ SunOS 4.1.3}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ SPARC}
+ #end td
+
+ B {#start td
+ Solaris 2}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ RS6000}
+ #end td
+
+ B {#start td
+ AIX 4.1.3}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ RS6000}
+ #end td
+
+ B {#start td
+ AIX 4.1.3}
+ #end td
+
+ C {#start td
+ xlc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ PA-RISC}
+ #end td
+
+ B {#start td
+ HPUX}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ Alpha}
+ #end td
+
+ B {#start td
+ DEC Unix 3.2}
+ #end td
+
+ C {#start td
+ gcc}
+ #end td
+
+ #end tr
+
+ @Rowa
+ #start tr
+
+ A {#start td
+ Alpha}
+ #end td
+
+ B {#start td
+ DEC Unix 3.2}
+ #end td
+
+ C {#start td
+ c89}
+ #end td
+
+ #end tr
+ #unhandled end tbody
+ }@LLP
+ #end table
+ }
+ #end center
+
+
+ @PP
+ #start p
+ {}@B {#start strong
+ How can I keep informed as to new releases and
+ announcements?}
+ #end strong
+
+
+ @PP
+ #start p
+ We have set up serveral SimpleScalar mailing lists for various topics. To
+ subscribe, go to the {}@Underline {#start a attributes= (href=>http://www.simplescalar.org/subscribe.html)
+ mailing list page}
+ #end a
+ and
+ follow the directions. {}@B {#start strong
+ How do I see old mailing list messages?}
+ #end strong
+
+
+ @PP
+ #start p
+ Steve Raasch at Michigan was kind enough to set up an SS mailing list
+ archive. You should pore through these before sending a question to the
+ list,
+ which goes to hundreds of people. Lots of the same questions gets asked
+ over and
+ over, and the answers to new users' questions are likely to be in the
+ archive!
+
+ @PP
+ #start p
+ The archive is available at: {}@Underline {#start a attributes= (href=>http://ord.eecs.umich.edu/)
+ http:"/""/"ord.eecs.umich.edu"/"}
+ #end a
+ .
+
+ @PP
+ #start p
+ {}@B {#start strong
+ What's new in version 2.0?}
+ #end strong
+
+
+ @PP
+ #start p
+ We have added numerous features and utilities. The code has been cleaned up
+ and is better documented, plus all known bugs have been fixed. The code now
+ includes much more sophisticated arguments and statistics packages (that
+ allow
+ you to use config files to set simulation parameters), plus cleaner
+ statistics
+ reporting. We have provided a source-level debugger called DLite!, which
+ allows
+ you to step through the program being simulated. We have also added a
+ pipeline
+ tracer, which allows you to track pipeline state in the out-of-order
+ simulator.
+ We have removed the simulators' dependence on the BFD utilities, making
+ binutils' installation optional. There are two new simulators, sim-profile
+ and
+ sim-cheetah, that do useful profiling and multiple simultaneous cache
+ configuration simulations, respectively. Finally, we include pre-built
+ binaries,
+ both small test binaries and a complete set of the SPEC95 binaries built
+ for
+ SimpleScalar (both big- and little-endian).
+
+ @PP
+ #start p
+ @LLP
+ #end table
+
+ { clines } @Break {
+ #start center
+ }
+ #end center
+
+
+ @PP
+ #start p
+
+
+ @LLP @FullWidthRule @LLP
+ #start hr
+
+ Last modified: Sun Feb 27 2000 23:29 by {}@Underline {#start a attributes= (href=>mailto:dburger at cs.utexas.edu)
+ Doug Burger}
+ #end a
+
+ @LLP
+ #start br
+
+
+ @LLP @FullWidthRule @LLP
+ #start hr
+
+ #end body
+ #end html
+
+ @End @Text
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/large.lout.ld
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/large.lout.ld:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/large.lout.ld Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,238 ----
+ {@@E {
+ { @@A { @@E {
+ { @@A { @@E {
+ { @@A { @@E {
+ { @@A { @@E {
+ @@C
+ }
+ {@LUse @TblSetup} } }
+ }
+ {@LUse @BasicSetup} } }
+ }
+ {@LUse @DocumentSetup} } }
+ }
+ {@@V @BeginTheoremCounter {}} } }
+ }
+ {@@V @TheoremCounterMarker
+ \a{"10.2599.large.lout.1"}
+ \b{{} @Join 0}}}
+
+ {@@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@@V @BeginDefinitionCounter {}} } }
+ }
+ {@@V @DefinitionCounterMarker
+ \a{"10.2658.large.lout.1"}
+ \b{{} @Join 0}}}
+
+ {@@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@@V @BeginClaimCounter {}} } }
+ }
+ {@@V @ClaimCounterMarker
+ \a{"10.2713.large.lout.1"}
+ \b{{} @Join 0}}}
+
+ {@@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@@V @BeginPropositionCounter {}} } }
+ }
+ {@@V @PropositionCounterMarker
+ \a{"10.2768.large.lout.1"}
+ \b{{} @Join 0}}}
+
+ {@@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@@V @BeginLemmaCounter {}} } }
+ }
+ {@@V @LemmaCounterMarker
+ \a{"10.2823.large.lout.1"}
+ \b{{} @Join 0}}}
+
+ {@@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@@V @BeginCorollaryCounter {}} } }
+ }
+ {@@V @CorollaryCounterMarker
+ \a{"10.2878.large.lout.1"}
+ \b{{} @Join 0}}}
+
+ {@@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@@V @BeginExampleCounter {}} } }
+ }
+ {@@V @ExampleCounterMarker
+ \a{"10.2933.large.lout.1"}
+ \b{{} @Join 0}}}
+
+ {@@E {
+ { @@B { { @@A { @@E {
+ @@D "35 3"
+ }
+ {Yes @BeginDisplayCounter {}} } }
+ }
+ {@@E {
+ { @@A { @@E {
+ @@D "1161 80"
+ }
+ {?? @@V @Do ??} } }
+ }
+ {@@V y}} }
+ }
+ {@@V @NumDispCounterMarker
+ \a{"7.1249.large.lout.1"}
+ \b{{} @Join 0}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {@@V @FigurePrefixMarker
+ \a{"10.3494.large.lout.1"}
+ \b{}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {@@V @FigureCounterMarker
+ \a{"10.3502.large.lout.1"}
+ \b{0}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {@@V @TablePrefixMarker
+ \a{"10.3739.large.lout.1"}
+ \b{}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {@@V @TableCounterMarker
+ \a{"10.3747.large.lout.1"}
+ \b{0}}}
+
+ {@@E {
+ { @@A { @@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@@V @PageList
+ \a{1}
+ \b{Simple}
+ \d{Portrait}
+ \c{Yes}
+ 1} } }
+ }
+ {@@V @SimplePageList
+ \a{1}
+ \b{Simple}
+ \d{Portrait}
+ \c{Yes}
+ \e{@@V @AtTop}
+ 1} } }
+ }
+ {@PageMarker
+ \a{"7.1067.large.lout.1"}
+ \c{1}
+ \b{Arabic @@V @Num 1}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {@@V @FootNoteCounterMarker
+ \a{"10.1381.large.lout.1"}
+ \b{0}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {Start @Runner
+ \g{"10.796.large.lout.2"}}}
+
+ {@@E {
+ @@D "35 3"
+ }
+ {@NumberMarker
+ \a{"7.1052.large.lout.2"}
+ \b{1}}}
+
+ {@@E {
+ { @@A { @@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@LUse @OrdinarySetup} } }
+ }
+ {@Text { @LInput }} } }
+ }
+ {@@V listitem
+ \a{"7.1492.large.lout.1"}
+ ???}}
+
+ {@@E {
+ { @@A { @@E {
+ @@D "1717 126"
+ }
+ {@@V @SimpleEvenPageList
+ \a{1}
+ \b{Simple}
+ 2} } }
+ }
+ {@PageMarker
+ \a{"7.1067.large.lout.2"}
+ \c{2}
+ \b{Arabic @@V @Num 2}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {@@V @FootNoteCounterMarker
+ \a{"10.1381.large.lout.2"}
+ \b{0}}}
+
+ {@@E {
+ { @@A { @@E {
+ @@D "21 2"
+ }
+ {@@V @SimplePageList
+ \a{1}
+ \b{Simple}
+ \d{Portrait}
+ 3} } }
+ }
+ {@PageMarker
+ \a{"7.1067.large.lout.3"}
+ \c{3}
+ \b{Arabic @@V @Num 3}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {@@V @FootNoteCounterMarker
+ \a{"10.1381.large.lout.3"}
+ \b{0}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {NonStart @Runner
+ \g{"10.796.large.lout.3"}}}
+
+ {@@E {
+ @@D "21 2"
+ }
+ {NonStart @Runner
+ \g{"10.796.large.lout.1"}}}
+
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/lout.li
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/lout.li:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/lout.li Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,44 ----
+ 00 Basser Lout Version 3.24 (October 2000) database index file
+ 00symbol 1 @BasicSetup @DocumentSetup @TheoremCounterMarker
+ 00symbol 10 @BasicSetup @DocumentSetup @FigureCounterMarker
+ 00symbol 11 @BasicSetup @DocumentSetup @TablePrefixMarker
+ 00symbol 12 @BasicSetup @DocumentSetup @TableCounterMarker
+ 00symbol 13 @BasicSetup @PageMarker
+ 00symbol 14 @BasicSetup @DocumentSetup @FootNoteCounterMarker
+ 00symbol 15 @BasicSetup @DocumentSetup @Runner
+ 00symbol 16 @BasicSetup @NumberMarker
+ 00symbol 17 @BasicSetup listitem
+ 00symbol 2 @BasicSetup @DocumentSetup @DefinitionCounterMarker
+ 00symbol 3 @BasicSetup @DocumentSetup @ClaimCounterMarker
+ 00symbol 4 @BasicSetup @DocumentSetup @PropositionCounterMarker
+ 00symbol 5 @BasicSetup @DocumentSetup @LemmaCounterMarker
+ 00symbol 6 @BasicSetup @DocumentSetup @CorollaryCounterMarker
+ 00symbol 7 @BasicSetup @DocumentSetup @ExampleCounterMarker
+ 00symbol 8 @BasicSetup @NumDispCounterMarker
+ 00symbol 9 @BasicSetup @DocumentSetup @FigurePrefixMarker
+ 1&10.2599.large.lout.1 0 00001 0 1 large.lout
+ 10&10.3502.large.lout.1 0 00010 1456 105 large.lout
+ 11&10.3739.large.lout.1 0 00011 1542 112 large.lout
+ 12&10.3747.large.lout.1 0 00012 1625 119 large.lout
+ 13&7.1067.large.lout.1 0 00013 1710 126 large.lout
+ 13&7.1067.large.lout.2 0 00020 2377 184 large.lout
+ 13&7.1067.large.lout.3 0 00022 2634 205 large.lout
+ 13&7.1492.large.lout.1 0 00019 1710 126 large.lout
+ 13&last.page 0 00026 2634 205 large.lout
+ 14&10.1381.large.lout.1 0 00014 1997 151 large.lout
+ 14&10.1381.large.lout.2 0 00021 2546 198 large.lout
+ 14&10.1381.large.lout.3 0 00023 2810 220 large.lout
+ 15&10.796.large.lout.1 0 00025 2967 233 large.lout
+ 15&10.796.large.lout.2 0 00015 2085 158 large.lout
+ 15&10.796.large.lout.3 0 00024 2898 227 large.lout
+ 16&7.1052.large.lout.2 0 00016 2151 164 large.lout
+ 16&7.1492.large.lout.1 0 00018 2151 164 large.lout
+ 17&7.1492.large.lout.1 0 00017 2225 171 large.lout
+ 2&10.2658.large.lout.1 0 00002 260 20 large.lout
+ 3&10.2713.large.lout.1 0 00003 412 30 large.lout
+ 4&10.2768.large.lout.1 0 00004 554 40 large.lout
+ 5&10.2823.large.lout.1 0 00005 708 50 large.lout
+ 6&10.2878.large.lout.1 0 00006 850 60 large.lout
+ 7&10.2933.large.lout.1 0 00007 1000 70 large.lout
+ 8&7.1249.large.lout.1 0 00008 1146 80 large.lout
+ 9&10.3494.large.lout.1 0 00009 1372 98 large.lout
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/small.lout
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/small.lout:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/small.lout Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,250 ----
+ @SysInclude { tbl }
+ @SysInclude { doc }
+ def @HeaderA right x { @CD +8p @Font { x } }
+ def @HeaderB right x { @CD +6p @Font { x } }
+ def @HeaderC right x { @CD +4p @Font { x } }
+ def @HeaderD right x { @CD +2p @Font { x } }
+ def @HeaderE right x { @CD -1p @Font { x } }
+ def @HeaderF right x { @CD -2p @Font { x } }
+ # Created by HTML::LoutParser.pm on 2001/06/28 from GNUgcc.htm.
+ @Doc @Text @Begin
+ #DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
+
+ # saved from url=(0044)http://www.gnu.org/press/2001-06-18-GCC.html
+
+ #start html
+ #start head
+
+ @CentredDisplay { +10p } @Font {#start title
+ GNU Compiler Collection Version 3.0 Is Released; Includes Support for Java
+ and IA-64 - GNU Project - Free Software Foundation (FSF)}
+ #end title
+
+ #unhandled start meta attributes= (content=>text/html; charset=windows-1252), (http-equiv=>Content-Type)
+
+ #unhandled start meta attributes= (content=>GNU, FSF, Free Software Foundation, Linux, press, GPL, general, public, license, freedom, software, free, gcc, complier, collection, release, toolset, java, c, c++, intel, amd, stallman, open, source, commercial, sustainable, business, models), (http-equiv=>Keywords)
+
+ #unhandled start meta attributes= (content=>The Free Software Foundation announced on Monday 18 June 2001 the 3.0 release of the GNU Compiler Collection (GCC). GCC is a Free (as in freedom) Software compiler toolset, licensed under the GNU General Public License (GPL). Native Java compilation support is now available.), (http-equiv=>Description)
+ #unhandled start link attributes= (href=>mailto:pr at gnu.org), (rev=>made)
+
+ #unhandled start meta attributes= (name=>GENERATOR), (content=>MSHTML 5.50.4616.200)
+ #end head
+
+ #start body attributes= (bgcolor=>#ffffff), (vlink=>#9900dd), (text=>#000000), (link=>#1f00ff), (alink=>#ff0000)
+ {}@Underline {#start a attributes= (href=>http://www.gnu.org/press/2001-06-18-GCC.txt)
+ A plain text version of this
+ press release is available}
+ #end a
+ .
+
+ @PP
+ #start p
+ {}@B {#start strong
+ FOR IMMEDIATE RELEASE}
+ #end strong
+
+ @LLP
+ #start br
+ Media Contact: Free Software
+ Foundation
+ @LLP
+ #start br
+ Bradley M. Kuhn {}@Underline {#start a attributes= (href=>mailto:pr at gnu.org)
+ mailto:pr"@"gnu.org}
+ #end a
+
+ @LLP
+ #start br
+ Phone: +1-617-542-5942
+ @LLP
+ #start br
+
+ @LLP
+ #start br
+
+
+ @HeaderA {#start h1
+ GNU Compiler Collection Version 3.0 Is Released}
+ #end h1
+
+ @LLP
+ #start br
+
+
+ @HeaderB {#start h2
+ Includes Support for Java and IA-64}
+ #end h2
+
+
+ @PP
+ #start p
+ {}@B {#start strong
+ Boston, Massachusetts, USA}
+ #end strong
+ - {}@I {#start i
+ Monday, June 18, 2001}
+ #end i
+ -
+ The Free Software Foundation announced today the 3.0 release of the GNU
+ Compiler
+ Collection (GCC). GCC is a Free (as in freedom) Software compiler toolset,
+ licensed under the GNU General Public License (GPL).
+
+ @PP
+ #start p
+ This version of GCC fully incorporates a native-code compiler for the Java
+ programming language. This allows Java programs that run faster, while
+ using a
+ completely Free Software system without depending on a proprietary Java
+ compiler.
+
+ @PP
+ #start p
+ GCC 3.0 includes rewritten support the Intel and AMD 32-bit family of
+ processors, which includes all Pentium systems. GCC 3.0 now generates much
+ better output for these processors. This allows programs to run faster on
+ such
+ systems.
+
+ @PP
+ #start p
+ GCC 3.0 supports the Intel IA-64 processor. This support will allow
+ completely Free Software systems to run on the IA-64 architecture
+ immediately
+ upon the public release of IA-64. GCC 3.0 also supports other new chipsets
+ from
+ Motorola, Atmel, Mitsubishi, Fujitsu and Sun.
+
+ @PP
+ #start p
+ GCC 3.0 vastly improves C++ support. Many bug fixes and changes to the C++
+ support library allow GCC 3.0 to conform better to ISO C++ standards than
+ ever
+ before. Also included is a new Application Binary Interface (ABI) for C++.
+
+ @PP
+ #start p
+ But, technological considerations are not the most important reasons for
+ using GCC. Richard M. Stallman, president of the Free Software Foundation,
+ pointed out: ``Many users choose GCC for technical advantages, such as
+ having one
+ compiler that works on many systems, or its powerful C extensions. But the
+ most
+ important benefit of GCC is freedom--your freedom. A free operating system
+ requires a free compiler. GCC was an essential step on the road to
+ freedom.''
+
+ @PP
+ #start p
+ GCC 3.0 has benefitted from the efforts of several successful businesses
+ built around support and development of Free Software. GCC, which is Free
+ Software licensed under the GPL, has facilitated sustainable business
+ models.
+ Some of these companies are listed in the Free Software Foundation's
+ service
+ directory, which can be found at:
+ @LLP
+ #start br
+ {}@Underline {#start a attributes= (href=>http://www.gnu.org/prep/service.html)
+ http:"/""/"www.gnu.org"/"prep"/"service.html}
+ #end a
+
+
+ @PP
+ #start p
+ More information about the new features of GCC 3.0 can be found at:
+ @LLP
+ #start br
+ {}@Underline {#start a attributes= (href=>http://www.gnu.org/software/gcc/gcc-3.0/features.html)
+ http:"/""/"www.gnu.org"/"software"/"gcc"/"gcc-3.0"/"features.html}
+ #end a
+
+
+ @PP
+ #start p
+ The software can be downloaded from:
+ @LLP
+ #start br
+ {}@Underline {#start a attributes= (href=>http://www.gnu.org/software/gcc/releases.html)
+ http:"/""/"www.gnu.org"/"software"/"gcc"/"releases.html}
+ #end a
+
+
+ @PP
+ #start p
+ Users are encouraged to use mirror sites for downloads, to decrease the
+ load
+ on GNU and FSF servers.
+
+ @PP
+ #start p
+
+
+ @LLP @FullWidthRule @LLP
+ #start hr
+
+
+ @HeaderC {#start h3
+ About the GNU Compiler Collection (GCC):}
+ #end h3
+
+ @LLP
+ #start br
+ The GNU Compiler Collection
+ (GCC), originally called the GNU C Compiler, includes compilers for the C,
+ C++,
+ Objective C, Fortran, and Java languages. Originally developed by Richard
+ M.
+ Stallman, GCC is now developed and improved by a worldwide network of
+ volunteers, lead by the GCC Steering Committee, the official maintainers of
+ GCC.
+ The GCC website can be found at:
+ @LLP
+ #start br
+ {}@Underline {#start a attributes= (href=>http://www.gnu.org/software/gcc/gcc.html)
+ http:"/""/"www.gnu.org"/"software"/"gcc"/"gcc.html}
+ #end a
+
+
+ @PP
+ #start p
+
+
+ @HeaderC {#start h3
+ About GNU:}
+ #end h3
+
+ @LLP
+ #start br
+ GNU is a Free Software Unix-like operating system.
+ Development of GNU began in 1984. GCC is the compiler for the GNU system.
+
+ @LLP @FullWidthRule @LLP
+ #start hr
+
+
+ @PP
+ #start p
+ Copyright (C) 2001 Free Software Foundation, Inc., 59 Temple Place - Suite
+ 330, Boston, MA 02111, USA
+
+ @PP
+ #start p
+ Verbatim copying and distribution of this entire article is permitted in
+ any
+ medium, provided this notice is preserved.
+
+ @PP
+ #start p
+ Updated: # timestamp start
+ $Date: 2007/01/09 23:44:35 $ $Author: bkuhn
+ $ # timestamp end
+
+
+ @LLP @FullWidthRule @LLP
+ #start hr
+
+ #end body
+ #end html
+
+ @End @Text
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z01.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z01.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z01.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,859 ----
+ /*@z01.c:Supervise:StartSym, AllowCrossDb, etc.@******************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z01.c */
+ /* MODULE: Supervise */
+ /* EXTERNS: main(), StartSym, GalleySym, ForceGalleySym, InputSym, */
+ /* PrintSym, AllowCrossDb */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ /* On DOS/Win32 we need to set binary mode on stdout (Uwe) */
+ #if OS_DOS
+ #include <io.h>
+ #include <fcntl.h>
+ #ifdef __DJGPP__
+ #define _setmode(fd, mode) setmode((fd), (mode))
+ #define _fileno(stream) fileno((stream))
+ #endif
+ #endif
+
+ /*****************************************************************************/
+ /* */
+ /* MemCheck - check this memory location */
+ /* */
+ /*****************************************************************************/
+
+ POINTER MemCheck = 0;
+
+
+ /*****************************************************************************/
+ /* */
+ /* StartSym the symbol table entry for \Start (overall scope) */
+ /* GalleySym the symbol table entry for @Galley */
+ /* ForceGalleySym the symbol table entry for @ForceGalley */
+ /* InputSym the symbol table entry for @LInput */
+ /* PrintSym the symbol table entry for \Print (root target) */
+ /* OptGallSym the symbol table entry for @OptGall (optimal galley rec) */
+ /* FilterInSym the symbol table entry for @FilterIn */
+ /* FilterOutSym the symbol table entry for @FilterOut */
+ /* FilterErrSym the symbol table entry for @FilterErr */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT StartSym, GalleySym, ForceGalleySym, InputSym, PrintSym, OptGallSym,
+ FilterInSym, FilterOutSym, FilterErrSym, VerbatimSym, RawVerbatimSym;
+
+
+ /*****************************************************************************/
+ /* */
+ /* BackEnd The back end (PostScript, PDF, etc.) to use */
+ /* CommandOptions Command-line options (ACAT of objects) */
+ /* UseCollate Use local collation sequence rather than ASCII */
+ /* AllowCrossDb Allow references to OldCrossDb and NewCrossDb */
+ /* InMemoryDbIndexes True if cr database index file is to be in-memory */
+ /* Kern Do kerning */
+ /* SafeExecution Execute safely, i.e. prohibit system() calls */
+ /* AltErrorFormat Use alternative error message format */
+ /* InitializeAll TRUE if this is an initializing run. */
+ /* MsgCat category for locale-specific messages */
+ /* TotalWordCount total number of words printed */
+ /* */
+ /*****************************************************************************/
+
+ BACK_END BackEnd;
+ OBJECT CommandOptions;
+ BOOLEAN UseCollate;
+ BOOLEAN AllowCrossDb;
+ BOOLEAN InMemoryDbIndexes;
+ BOOLEAN Kern;
+ BOOLEAN SafeExecution;
+ BOOLEAN AltErrorFormat;
+ BOOLEAN InitializeAll;
+ #if LOCALE_ON
+ nl_catd MsgCat;
+ #endif
+ int TotalWordCount;
+
+
+ /*****************************************************************************/
+ /* */
+ /* static OBJECT load(xstr, xpredefined, xleft, xright, xindef, xprec) */
+ /* */
+ /* Load a predefined operator with these attributes into the symbol table. */
+ /* If the operator has parameters, load symbols for those also. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT load(FULL_CHAR *xstr, unsigned xpre,
+ BOOLEAN xleft, BOOLEAN xright, BOOLEAN xindef, unsigned char xprec)
+ { OBJECT s;
+ s = InsertSym(xstr, LOCAL, no_fpos, xprec, xindef, FALSE, xpre,
+ StartSym, nilobj);
+ if( xleft ) InsertSym( AsciiToFull("pa"), LPAR, no_fpos, DEFAULT_PREC,
+ FALSE, FALSE, 0, s, nilobj);
+ if( xright ) InsertSym( AsciiToFull("pb"), RPAR, no_fpos, DEFAULT_PREC,
+ FALSE, FALSE, 0, s, nilobj);
+ if( xleft && xright && xpre != PLUS && xpre != MINUS )
+ right_assoc(s) = TRUE;
+ return s;
+ } /* end load */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static void PrintUsage(fp) */
+ /* */
+ /* Print usage information on file fp. */
+ /* */
+ /*****************************************************************************/
+ #define lput(str) fprintf(fp, "%s\n", str)
+
+ static void PrintUsage(FILE *fp)
+ {
+ lput("" );
+ lput("usage: lout options files" );
+ lput("" );
+ lput(" -s suppress access to cross reference database" );
+ lput(" -EPS EPS (Encapsulated PostScript) output" );
+ lput(" -PDF or -Z PDF (Adobe Portable Document Format) output" );
+ lput(" -p plain text output instead of PostScript" );
+ lput(" -P like -p but with form-feed char between pages" );
+ lput(" -S safe execution (disable calls to system(3))" );
+ lput(" -U unsafe execution (allow calls to system(3))" );
+ lput(" -l ASCII collation order when sorting indexes etc." );
+ lput(" -L locale collation order when sorting indexes etc." );
+ lput(" -o file output to file instead of stdout" );
+ lput(" -e file error messages to file instead of stderr" );
+ lput(" -a alternative error format: file:line:col ..." );
+ lput(" -w print total number of words in output" );
+ lput(" -i file like @SysInclude { file }; not recommended" );
+ lput(" -I directory add directory to include file search path" );
+ lput(" -C directory add directory to LCM file search path" );
+ lput(" -F directory add directory to font metrics file search path" );
+ lput(" -H directory add directory to hyphenation file search path" );
+ lput(" -D directory add directory to database file search path" );
+ lput(" --option{value} set option e.g. --'@InitialFont{Times Base 10p}'" );
+ lput(" -c file use file.li instead of lout.li for crossrefs" );
+ lput(" -M save memory (don't read in database indexes)" );
+ lput(" -x initializing run, not for ordinary use" );
+ lput(" -u print this usage message on stderr and exit" );
+ lput(" -V print version and configuration information" );
+ lput(" - a file name denoting standard input" );
+ lput("" );
+
+ } /* end PrintUsage */
+
+
+ /*@::GetArg(), main()@********************************************************/
+ /* */
+ /* GetArg(argv, argc, i) */
+ /* */
+ /* Get the next argument from the command line and return it. */
+ /* Return NULL if it isn't there. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR *GetArg(char *argv[], int argc, int *i)
+ { if( !StringEqual(AsciiToFull(argv[*i]+2), STR_EMPTY) )
+ return AsciiToFull(argv[*i]+2);
+ else if( *i < argc-1 && *argv[*i + 1] != CH_HYPHEN )
+ return AsciiToFull(argv[(*i)++ +1]);
+ else
+ return (FULL_CHAR *) NULL;
+ } /* end GetArg */
+
+
+ /*****************************************************************************/
+ /* */
+ /* main(argc, argv) */
+ /* */
+ /* Read command line, initialise everything, read definitions, read */
+ /* galleys, clean up and exit. */
+ /* */
+ /*****************************************************************************/
+
+ int main(int argc, char *argv[])
+ { int i, len; FULL_CHAR *arg;
+ OBJECT t, y, res, s; /* current token, parser output */
+ BOOLEAN stdin_seen; /* TRUE when stdin file seen */
+ int source_file_count; /* number of source files in command */
+ FULL_CHAR *cross_db; /* name of cross reference database */
+ FULL_CHAR *outfile; /* name of output file */
+ FULL_CHAR *lib; /* name of library directory */
+ FILE *out_fp;
+ long MemCheckLong;
+ FULL_CHAR oname[MAX_BUFF], oval[MAX_BUFF], buff[MAX_BUFF], *p;
+ int bp; OBJECT z;
+ BOOLEAN seen_wordcount;
+ #if LOCALE_ON
+ char catname[MAX_BUFF], *loc;
+ #endif
+
+ /* find the name of the library directory, from envt or else from -D */
+ lib = AsciiToFull(getenv("LOUTLIB"));
+ if( lib == (FULL_CHAR *) NULL )
+ lib = AsciiToFull(LIB_DIR);
+
+ /* set locale if that's what we are doing */
+ #if LOCALE_ON
+ loc = setlocale(LC_MESSAGES, "");
+ if( loc == (char *) NULL )
+ { Error(1, 6, "unable to initialize locale", WARN, no_fpos);
+ loc = "C";
+ }
+ sprintf(catname, "%s/%s/%s/LC_MESSAGES/errors.%s",
+ lib, LOCALE_DIR, loc, loc);
+ MsgCat = catopen(catname, 0);
+ #endif
+
+ /* initialise various modules, add current directory to search paths */
+ TotalWordCount = 0;
+ seen_wordcount = FALSE;
+ BackEnd = PS_BackEnd;
+ PlainCharWidth = PLAIN_WIDTH;
+ PlainCharHeight = PLAIN_HEIGHT;
+ PlainFormFeed = FALSE;
+ InitializeAll = FALSE;
+ UseCollate = COLLATE;
+ AllowCrossDb = TRUE;
+ InMemoryDbIndexes = TRUE;
+ Encapsulated = FALSE;
+ SafeExecution = SAFE_DFT ? TRUE : FALSE;
+ Kern = TRUE;
+ MemInit();
+ InitSym();
+ LexInit();
+ InitFiles();
+ AddToPath(SOURCE_PATH, MakeWord(WORD, STR_EMPTY, no_fpos));
+ AddToPath(DATABASE_PATH, MakeWord(WORD, STR_EMPTY, no_fpos));
+ AddToPath(INCLUDE_PATH, MakeWord(WORD, STR_EMPTY, no_fpos));
+
+ /* read command line */
+ stdin_seen = FALSE;
+ AltErrorFormat = FALSE;
+ cross_db = CROSS_DB;
+ outfile = STR_STDOUT;
+ source_file_count = 0;
+ New(CommandOptions, ACAT);
+ for( i = 1; i < argc; i++ )
+ {
+ if( *argv[i] == CH_HYPHEN ) switch( *(argv[i]+1) )
+ {
+ case CH_FLAG_OUTFILE:
+
+ /* read name of output file */
+ if( (outfile = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 7, "usage: -o <filename>", FATAL, no_fpos);
+ if( StringEndsWith(outfile, SOURCE_SUFFIX) )
+ Error(1, 28, "-o: output file name %s ends with %s",
+ FATAL, no_fpos, outfile, SOURCE_SUFFIX);
+ break;
+
+
+ case CH_FLAG_SUPPRESS:
+
+ /* suppress references to OldCrossDb and NewCrossDb */
+ AllowCrossDb = FALSE;
+ break;
+
+
+ case CH_FLAG_MEMCR:
+
+ /* don't use in-memory database indexes */
+ InMemoryDbIndexes = FALSE;
+ break;
+
+
+ case CH_FLAG_NOKERN:
+
+ /* suppress kerning */
+ Kern = FALSE;
+ break;
+
+
+ case CH_FLAG_NOCOLLATE:
+
+ /* suppress local collation */
+ UseCollate = FALSE;
+ break;
+
+
+ case CH_FLAG_COLLATE:
+
+ /* invoke local collation */
+ UseCollate = TRUE;
+ break;
+
+
+ case CH_FLAG_CROSS:
+
+ /* read name of cross reference database */
+ if( (cross_db = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 8, "usage: -c <filename>", FATAL, no_fpos);
+ break;
+
+
+ case CH_FLAG_ERRFILE:
+
+ /* read log file name */
+ if( (arg = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 9, "usage: -e <filename>", FATAL, no_fpos);
+ ErrorInit(arg);
+ break;
+
+
+ case CH_FLAG_ALTERR:
+
+ /* alternative error message format */
+ AltErrorFormat = TRUE;
+ break;
+
+
+ case CH_FLAG_EPSFIRST:
+
+ /* -EPS produces encapsulated PostScript output */
+ if( !StringEqual(AsciiToFull(argv[i]+1), STR_EPS) )
+ Error(1, 10, "usage: -EPS", FATAL, no_fpos);
+ Encapsulated = TRUE;
+ break;
+
+
+ case CH_FLAG_DIRPATH:
+
+ /* add directory to database and sysdatabase paths */
+ if( (arg = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 11, "usage: -D <directoryname>", FATAL, no_fpos);
+ AddToPath(DATABASE_PATH, MakeWord(WORD, arg, no_fpos));
+ AddToPath(SYSDATABASE_PATH, MakeWord(WORD, arg, no_fpos));
+ break;
+
+
+ case CH_FLAG_ENCPATH:
+
+ /* add directory to character mapping path */
+ if( (arg = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 12, "usage: -C <directoryname>", FATAL, no_fpos);
+ AddToPath(MAPPING_PATH, MakeWord(WORD, arg, no_fpos));
+ break;
+
+
+ case CH_FLAG_FNTPATH:
+
+ /* add directory to font path */
+ if( (arg = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 13, "usage: -F <directoryname>", FATAL, no_fpos);
+ AddToPath(FONT_PATH, MakeWord(WORD, arg, no_fpos));
+ break;
+
+
+ case CH_FLAG_HYPPATH:
+
+ /* add directory to hyph path */
+ if( (arg = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 14, "usage: -H <directoryname>", FATAL, no_fpos);
+ AddToPath(HYPH_PATH, MakeWord(WORD, arg, no_fpos));
+ break;
+
+
+ case CH_FLAG_INCPATH:
+
+ /* add directory to include and sysinclude paths */
+ if( (arg = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 15, "usage: -I <directoryname>", FATAL, no_fpos);
+ AddToPath(INCLUDE_PATH, MakeWord(WORD, arg, no_fpos));
+ AddToPath(SYSINCLUDE_PATH, MakeWord(WORD, arg, no_fpos));
+ break;
+
+
+ case CH_FLAG_INCLUDE:
+
+ /* read sysinclude file and strip any .lt suffix */
+ if( (arg = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 16, "usage: -i <filename>", FATAL, no_fpos);
+ len = StringLength(arg) - StringLength(SOURCE_SUFFIX);
+ if( len >= 0 && StringEqual(&arg[len], SOURCE_SUFFIX) )
+ StringCopy(&arg[len], STR_EMPTY);
+ debug0(DFS, D, " calling DefineFile from main (1)");
+ DefineFile(arg, STR_EMPTY, no_fpos, SOURCE_FILE, SYSINCLUDE_PATH);
+ break;
+
+
+ case CH_FLAG_HYPHEN:
+
+ /* declare hyphenation file */
+ if( FirstFile(HYPH_FILE) != NO_FILE )
+ Error(1, 17, "two -h options illegal", FATAL, no_fpos);
+ if( (arg = GetArg(argv, argc, &i)) == NULL )
+ Error(1, 18, "usage: -h <filename>", FATAL, no_fpos);
+ debug0(DFS, D, " calling DefineFile from main (2)");
+ DefineFile(arg, STR_EMPTY, no_fpos, HYPH_FILE, INCLUDE_PATH);
+ DefineFile(arg, HYPH_SUFFIX, no_fpos, HYPH_PACKED_FILE, INCLUDE_PATH);
+ break;
+
+
+ case CH_FLAG_VERSION:
+
+ fprintf(stderr, "%s\n", LOUT_VERSION);
+ fprintf(stderr, "%-28s %s\n",
+ "Basser Lout written by:", "Jeffrey H. Kingston (jeff at cs.usyd.edu.au)");
+ fprintf(stderr, "%-28s %s\n",
+ "Free source available from:", "ftp://ftp.cs.usyd.edu.au/jeff/lout");
+ fprintf(stderr, "%-28s %s %s\n",
+ "This executable compiled:", __TIME__, __DATE__);
+ fprintf(stderr, "%-28s %s%s%s\n", "System include directory:",
+ lib, STR_DIR, INCL_DIR);
+ fprintf(stderr, "%-28s %s%s%s\n", "System database directory:",
+ lib, STR_DIR, DATA_DIR);
+ fprintf(stderr, "Database index files created afresh automatically:%s\n",
+ USE_STAT ? " yes" : " no");
+ fprintf(stderr, "Safe execution (disabling system()) is default:%s\n",
+ SAFE_DFT ? " yes" : " no");
+ fprintf(stderr, "strcoll() used for sorting by default:%s\n",
+ COLLATE ? " yes" : " no");
+ fprintf(stderr, "PDF compression on:%s\n",
+ PDF_COMPRESSION ? " yes" : " no");
+ fprintf(stderr, "Debugging (-d, -dd, -ddd flags) available:%s\n",
+ DEBUG_ON ? " yes" : " no");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Basser Lout comes with ABSOLUTELY NO WARRANTY.\n");
+ fprintf(stderr, "This is free software, and you are welcome to\n");
+ fprintf(stderr, "redistribute it under certain conditions. For\n");
+ fprintf(stderr, "details on both points, consult the GNU General\n");
+ fprintf(stderr, "Public License (distributed with this software).\n");
+ exit(0);
+ break;
+
+
+ case CH_FLAG_WORDS:
+
+ seen_wordcount = TRUE;
+ break;
+
+
+ case CH_FLAG_PDF:
+
+ BackEnd = PDF_BackEnd;
+ break;
+
+
+ case CH_FLAG_FFPLAIN:
+
+ if( StringEqual(AsciiToFull(argv[i]+1), STR_PDF) )
+ {
+ BackEnd = PDF_BackEnd;
+ break;
+ }
+ PlainFormFeed = TRUE;
+ /* NB NO BREAK */
+
+
+ case CH_FLAG_PLAIN:
+
+ BackEnd = Plain_BackEnd;
+ if( *(argv[i]+2) != '\0' )
+ { float len1, len2; FULL_CHAR units1, units2;
+ if( sscanf(argv[i]+2, "%f%c%f%c",&len1,&units1,&len2,&units2) != 4 )
+ { Error(1, 19, "usage: lout -%c<length><length>",
+ FATAL, no_fpos, *(argv[i]+1));
+ }
+ switch( units1 )
+ {
+ case CH_UNIT_CM: PlainCharWidth = len1 * CM; break;
+ case CH_UNIT_IN: PlainCharWidth = len1 * IN; break;
+ case CH_UNIT_PT: PlainCharWidth = len1 * PT; break;
+ case CH_UNIT_EM: PlainCharWidth = len1 * EM; break;
+
+ default: Error(1, 20, "lout -%c: units must be c, i, p, or m",
+ FATAL, no_fpos, *(argv[i]+1));
+ break;
+ }
+ switch( units2 )
+ {
+ case CH_UNIT_CM: PlainCharHeight = len2 * CM; break;
+ case CH_UNIT_IN: PlainCharHeight = len2 * IN; break;
+ case CH_UNIT_PT: PlainCharHeight = len2 * PT; break;
+ case CH_UNIT_EM: PlainCharHeight = len2 * EM; break;
+
+ default: Error(1, 21, "lout -%c: units must be c, i, p, or m",
+ FATAL, no_fpos, *(argv[i]+1));
+ break;
+ }
+ }
+ break;
+
+
+ case CH_FLAG_INITALL:
+
+ InitializeAll = TRUE;
+ AllowCrossDb = FALSE;
+ break;
+
+
+ case CH_FLAG_USAGE:
+
+ PrintUsage(stderr);
+ exit(0);
+ break;
+
+
+ case CH_FLAG_DEBUG:
+
+ debug_init(AsciiToFull(argv[i]));
+ break;
+
+
+ case CH_FLAG_MEMCHECK:
+
+ sscanf(argv[i], "-m%ld", &MemCheckLong);
+ MemCheck = (POINTER) MemCheckLong;
+ fprintf(stderr, "checking memory location %ld\n", (long) MemCheck);
+ break;
+
+
+ case '\0':
+
+ /* read stdin as file name */
+ if( stdin_seen )
+ Error(1, 23, "standard input specified twice", FATAL, no_fpos);
+ stdin_seen = TRUE;
+ debug0(DFS, D, " calling DefineFile from main (3)");
+ DefineFile(STR_STDIN, STR_EMPTY, no_fpos, SOURCE_FILE, SOURCE_PATH);
+ break;
+
+
+ case CH_FLAG_OPTION:
+
+ /* read command-line document option */
+ if( sscanf(argv[i]+2, "%[^{ ] { %[^}] }", oname, oval) != 2 ||
+ StringLength(oname) == 0 || StringLength(oval) == 0 )
+ Error(1, 24, "error in command-line option %s", FATAL, no_fpos,
+ argv[i]+2);
+ y = MakeWord(WORD, oname, no_fpos);
+ Link(CommandOptions, y);
+ New(y, ACAT);
+ Link(CommandOptions, y);
+ bp = 0;
+ for( p = oval; *p != '\0'; p++ ) switch( *p )
+ {
+ case ' ':
+ case '\t':
+ case '\n':
+ case '{':
+ case '}':
+
+ if( bp > 0 )
+ { buff[bp++] = '\0';
+ if( Down(y) != y )
+ { OBJECT g;
+ New(g, GAP_OBJ);
+ hspace(g) = 1; vspace(g) = 0;
+ FposCopy(fpos(g), *no_fpos);
+ Link(y, g);
+ }
+ z = MakeWord(WORD, buff, no_fpos);
+ Link(y, z);
+ bp = 0;
+ }
+ break;
+
+
+ default:
+
+ buff[bp++] = *p;
+ break;
+ }
+ if( bp > 0 )
+ { buff[bp++] = '\0';
+ z = MakeWord(WORD, buff, no_fpos);
+ Link(y, z);
+ }
+ if( Down(y) == y )
+ Error(1, 25, "error in command-line option %s", FATAL, no_fpos,
+ argv[i]+2);
+ break;
+
+
+ case CH_FLAG_SAFE:
+
+ /* ensure safe execution by disabling system calls */
+ SafeExecution = TRUE;
+ break;
+
+ case CH_FLAG_UNSAFE:
+
+ /* allow unsafe execution */
+ SafeExecution = FALSE;
+ break;
+
+ default:
+
+ PrintUsage(stderr);
+ Error(1, 26, "unknown command line flag %s", FATAL, no_fpos, argv[i]);
+ break;
+
+ }
+ else
+ { /* argument is source file, strip any .lout suffix and define it */
+ arg = AsciiToFull(argv[i]);
+ len = StringLength(arg) - StringLength(SOURCE_SUFFIX);
+ if( len >= 0 && StringEqual(&arg[len], SOURCE_SUFFIX) )
+ StringCopy(&arg[len], STR_EMPTY);
+ debug0(DFS, D, " calling DefineFile from main (4)");
+ DefineFile(AsciiToFull(argv[i]), STR_EMPTY, no_fpos,
+ SOURCE_FILE, SOURCE_PATH);
+ source_file_count++;
+ }
+ } /* for */
+
+ if( UseCollate )
+ {
+ if (!setlocale (LC_COLLATE, ""))
+ Error(1, 30, "unable to initialize collation", WARN, no_fpos);
+ }
+
+ /* start timing if required */
+ ifdebug(DPP, D, ProfileOn("main"));
+
+ /* open output file, or stdout if none specified, and initialize printer */
+ if( StringEqual(outfile, STR_STDOUT) )
+ {
+ #if OS_DOS
+ /* For DOS/Win32 we need to set binary mode on stdout to prevent
+ PDF compressed streams and xrefs from being corrupted - Uwe 12/98 */
+ if( BackEnd->code != PLAINTEXT &&
+ _setmode(_fileno(stdout), _O_BINARY) == -1 )
+ Error(1, 31, "cannot set binary mode on stdout", FATAL, no_fpos);
+ #endif
+ out_fp = stdout;
+ }
+ else
+ { out_fp = StringFOpen(outfile,
+ BackEnd->code == PLAINTEXT ? WRITE_TEXT : WRITE_BINARY);
+ if( out_fp == null )
+ Error(1, 27, "cannot open output file %s", FATAL, no_fpos, outfile);
+ }
+
+ /* initialize miscellaneous modules */
+ ColourInit();
+ LanguageInit();
+ BackEnd->PrintInitialize(out_fp);
+
+ /* append default directories to file search paths */
+ AddToPath(FONT_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(FONT_DIR)));
+ AddToPath(HYPH_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(HYPH_DIR)));
+ AddToPath(MAPPING_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(MAPS_DIR)));
+ AddToPath(SYSDATABASE_PATH,MakeWordThree(lib,STR_DIR, AsciiToFull(DATA_DIR)));
+ AddToPath(DATABASE_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(DATA_DIR)));
+ AddToPath(SYSINCLUDE_PATH,MakeWordThree(lib, STR_DIR, AsciiToFull(INCL_DIR)));
+ AddToPath(INCLUDE_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(INCL_DIR)));
+
+ /* use stdin if no source files were mentioned */
+ if( source_file_count == 0 )
+ { debug0(DFS, D, " calling DefineFile from main (5)");
+ DefineFile(STR_STDIN, STR_EMPTY, no_fpos, SOURCE_FILE, SOURCE_PATH);
+ }
+
+ /* load predefined symbols into symbol table */
+ StartSym = nilobj; /* Not a mistake */
+ StartSym = load(KW_START, 0, FALSE, FALSE, TRUE, NO_PREC );
+ GalleySym = load(KW_GALLEY, 0, FALSE, FALSE, TRUE, NO_PREC );
+ ForceGalleySym= load(KW_FORCE_GALLEY, 0, FALSE, FALSE, TRUE, NO_PREC );
+ InputSym = load(KW_INPUT, 0, FALSE, FALSE, TRUE, NO_PREC );
+ PrintSym = load(KW_PRINT, 0, FALSE, FALSE, TRUE, NO_PREC );
+ FilterInSym = load(KW_FILTERIN, 0, FALSE, FALSE, FALSE, NO_PREC );
+ FilterOutSym = load(KW_FILTEROUT, 0, FALSE, FALSE, FALSE, NO_PREC );
+ FilterErrSym = load(KW_FILTERERR, 0, FALSE, FALSE, FALSE, NO_PREC );
+ OptGallSym = load(KW_OPTGALL, 0, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ VerbatimSym = load(KW_VERBATIM,VERBATIM,FALSE, TRUE, FALSE, DEFAULT_PREC);
+ RawVerbatimSym= load(KW_RAWVERBATIM,RAW_VERBATIM,FALSE,TRUE,FALSE,DEFAULT_PREC);
+
+
+ load(KW_BEGIN, BEGIN, FALSE, FALSE, FALSE, BEGIN_PREC );
+ load(KW_END, END, FALSE, FALSE, FALSE, END_PREC );
+ load(KW_ENV, ENV, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_ENVA, ENVA, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_ENVB, ENVB, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_ENVC, ENVC, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_ENVD, ENVD, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_CENV, CENV, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_CLOS, CLOS, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_LVIS, LVIS, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_LUSE, LUSE, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_LEO, LEO, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_LBR, LBR, FALSE, FALSE, FALSE, LBR_PREC );
+ load(KW_RBR, RBR, FALSE, FALSE, FALSE, RBR_PREC );
+ load(KW_INCLUDE, INCLUDE, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_SYSINCLUDE, SYS_INCLUDE, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_PREPEND, PREPEND, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_SYSPREPEND, SYS_PREPEND, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_DATABASE, DATABASE, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_SYSDATABASE, SYS_DATABASE, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_USE, USE, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_NOT_REVEALED, NOT_REVEALED, FALSE, FALSE, FALSE, NO_PREC );
+ load(KW_CASE, CASE, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_YIELD, YIELD, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_BACKEND, BACKEND, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_XCHAR, XCHAR, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_FONT, FONT, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_SPACE, SPACE, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_YUNIT, YUNIT, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_ZUNIT, ZUNIT, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_BREAK, BREAK, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_UNDERLINE, UNDERLINE, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_COLOUR, COLOUR, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_COLOR, COLOUR, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_OUTLINE, OUTLINE, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_LANGUAGE, LANGUAGE, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_CURR_LANG, CURR_LANG, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_CURR_FAMILY, CURR_FAMILY, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_CURR_FACE, CURR_FACE, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_CURR_YUNIT, CURR_YUNIT, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_CURR_ZUNIT, CURR_ZUNIT, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_COMMON, COMMON, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_RUMP, RUMP, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_MELD, MELD, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_INSERT, INSERT, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_ONE_OF, ONE_OF, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_NEXT, NEXT, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_PLUS, PLUS, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_MINUS, MINUS, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_OPEN, OPEN, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_TAGGED, TAGGED, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_WIDE, WIDE, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HIGH, HIGH, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HSHIFT, HSHIFT, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_VSHIFT, VSHIFT, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_BEGIN_HEADER, BEGIN_HEADER, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_END_HEADER, END_HEADER, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_SET_HEADER, SET_HEADER, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_CLEAR_HEADER, CLEAR_HEADER, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_ONE_COL, ONE_COL, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_ONE_ROW, ONE_ROW, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HSCALE, HSCALE, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_VSCALE, VSCALE, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HCOVER, HCOVER, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_VCOVER, VCOVER, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_KERN_SHRINK, KERN_SHRINK, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_SCALE, SCALE, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HCONTRACT, HCONTRACT, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_VCONTRACT, VCONTRACT, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HLIMITED, HLIMITED, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_VLIMITED, VLIMITED, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HEXPAND, HEXPAND, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_VEXPAND, VEXPAND, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_STARTHVSPAN, START_HVSPAN, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_STARTHSPAN, START_HSPAN, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_STARTVSPAN, START_VSPAN, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HSPAN, HSPAN, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_VSPAN, VSPAN, FALSE, FALSE, FALSE, DEFAULT_PREC);
+ load(KW_PADJUST, PADJUST, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_HADJUST, HADJUST, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_VADJUST, VADJUST, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_ROTATE, ROTATE, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_BACKGROUND, BACKGROUND, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_INCGRAPHIC, INCGRAPHIC, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_SINCGRAPHIC, SINCGRAPHIC, FALSE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_PLAINGRAPHIC, PLAIN_GRAPHIC, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_GRAPHIC, GRAPHIC, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_LINK_SOURCE, LINK_SOURCE, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_LINK_DEST, LINK_DEST, TRUE, TRUE, FALSE, DEFAULT_PREC);
+ load(KW_CROSS, CROSS, TRUE, TRUE, FALSE, CROSSOP_PREC);
+ load(KW_FORCE_CROSS, FORCE_CROSS, TRUE, TRUE, FALSE, CROSSOP_PREC);
+ load(KW_NULL, NULL_CLOS, FALSE, FALSE, TRUE, NO_PREC );
+ load(KW_PAGE_LABEL, PAGE_LABEL, FALSE, TRUE, TRUE, DEFAULT_PREC);
+
+ #define setcat(s, mk, jn) has_mark(s)=mk, has_join(s)=jn
+
+ s=load(KW_VCAT_NN, VCAT, TRUE, TRUE, FALSE, VCAT_PREC); setcat(s,FALSE,FALSE);
+ s=load(KW_VCAT_MN, VCAT, TRUE, TRUE, FALSE, VCAT_PREC); setcat(s,TRUE, FALSE);
+ s=load(KW_VCAT_NJ, VCAT, TRUE, TRUE, FALSE, VCAT_PREC); setcat(s,FALSE,TRUE);
+ s=load(KW_VCAT_MJ, VCAT, TRUE, TRUE, FALSE, VCAT_PREC); setcat(s,TRUE, TRUE);
+ s=load(KW_HCAT_NN, HCAT, TRUE, TRUE, FALSE, HCAT_PREC); setcat(s,FALSE,FALSE);
+ s=load(KW_HCAT_MN, HCAT, TRUE, TRUE, FALSE, HCAT_PREC); setcat(s,TRUE, FALSE);
+ s=load(KW_HCAT_NJ, HCAT, TRUE, TRUE, FALSE, HCAT_PREC); setcat(s,FALSE,TRUE);
+ s=load(KW_HCAT_MJ, HCAT, TRUE, TRUE, FALSE, HCAT_PREC); setcat(s,TRUE, TRUE);
+ s=load(KW_ACAT_NJ, ACAT, TRUE, TRUE, FALSE, ACAT_PREC); setcat(s,FALSE,TRUE);
+ s=load(KW_ACAT_MJ, ACAT, TRUE, TRUE, FALSE, ACAT_PREC); setcat(s,TRUE, TRUE);
+
+ /* intialize fonts and load @FontDef symbol */
+ FontInit();
+
+ /* intialize current time and load @Moment symbol */
+ InitTime();
+
+ /* initialize filter module */
+ FilterInit();
+
+ /* initialize enviroment table module */
+ EnvInit();
+
+ /* initialise scope chain to <StartSym> */
+ PushScope(StartSym, FALSE, FALSE);
+
+ /* initialise lexical analyser */
+ LexPush(FirstFile(SOURCE_FILE), 0, SOURCE_FILE, 1, FALSE);
+
+ /* process input files */
+ InitParser(cross_db);
+ t = NewToken(BEGIN, no_fpos, 0, 0, BEGIN_PREC, StartSym);
+ res = Parse(&t, StartSym, TRUE, TRUE);
+ debug0(DGT, D, "calling TransferEnd(res) from main()");
+ DisposeObject(CommandOptions);
+ TransferEnd(res);
+ TransferClose();
+
+ /* close various modules */
+ BackEnd->PrintAfterLastPage();
+ BackEnd->LinkCheck();
+ CrossClose();
+ CloseFiles();
+
+ /* remove any leftover filter temporary files */
+ FilterScavenge(TRUE);
+
+ /* print word count, if required */
+ if( seen_wordcount )
+ Error(1, 29, "total of all words printed: %d", WARN,no_fpos,TotalWordCount);
+
+ /* check for unbalanced error blocks */
+ CheckErrorBlocks();
+
+ /* wrapup */
+ ifdebug(DST, DD, CheckSymSpread() );
+ ifdebug(ANY, D, DeleteEverySym() );
+ debug0(DMA, D, "at end of run:");
+ ifdebug(DMA, D, DebugMemory() );
+ ifdebug(DPP, D, ProfileOff("main"));
+ ifdebug(DPP, D, ProfilePrint());
+ ifdebug(DET, D, EnvDebug());
+
+ #if LOCALE_ON
+ catclose(MsgCat);
+ #endif
+
+ exit(0);
+ return 0;
+ } /* end main */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z02.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z02.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z02.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,976 ----
+ /*@z02.c:Lexical Analyser:Declarations@***************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z02.c */
+ /* MODULE: Lexical Analyser */
+ /* EXTERNS: LexLegalName(), LexInit(), LexPush(), LexPop(), */
+ /* LexNextTokenPos(), LexGetToken() */
+ /* */
+ /* Implementation note: this fast and cryptic lexical analyser is adapted */
+ /* from Waite, W. M.: The Cost of Lexical Analysis, in Software - Practice */
+ /* and Experience, v16, pp473-488 (May 1986). */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define BUFFER_SIZE 8192 /* size of buffer for block read */
+ #define OTHER 0 /* punctuation or other character */
+ #define LETTER 1 /* letter type */
+ #define QUOTE 2 /* quoted string delimiter type */
+ #define ESCAPE 3 /* escape character inside strings */
+ #define COMMENT 4 /* comment delimiter type */
+ #define CSPACE 5 /* space character type */
+ #define FORMFEED 6 /* formfeed character type */
+ #define TAB 7 /* tab character type */
+ #define NEWLINE 8 /* newline character type */
+ #define ENDFILE 9 /* end of file character type */
+
+ static unsigned char chtbl[256]; /* type table indexed by a FULL_CHAR */
+ static FULL_CHAR *chpt; /* pointer to current text character */
+ static FULL_CHAR *frst; /* address of first buffer character */
+ static FULL_CHAR *limit; /* just past last char in buffer */
+ static FULL_CHAR *buf; /* the character buffer start pos */
+ static int blksize; /* size of block read; others too */
+ static FULL_CHAR last_char; /* last char read in from file */
+ static FULL_CHAR *startline; /* position in buff of last newline */
+ static FILE_NUM this_file; /* number of currently open file */
+ static FILE *fp; /* current input file */
+ static FILE_POS file_pos; /* current file position */
+ static short ftype; /* the type of the current file */
+ static OBJECT next_token; /* next token if already read */
+ static int offset; /* where to start reading in file */
+ static int first_line_num; /* number of first line (if offset) */
+ static BOOLEAN same_file; /* TRUE if same file as preceding */
+ static FULL_CHAR *mem_block; /* file buffer */
+
+ static int stack_free; /* first free slot in lexical stack */
+ static struct {
+ FULL_CHAR *chpt; /* pointer to current text character */
+ FULL_CHAR *frst; /* address of first buffer character */
+ FULL_CHAR *limit; /* just past last char in buffer */
+ FULL_CHAR *buf; /* the character buffer start pos */
+ int blksize; /* size of block read; others too */
+ FULL_CHAR last_char; /* last char read in from file */
+ FULL_CHAR *startline; /* position in buff of last newline */
+ FILE_NUM this_file; /* number of currently open file */
+ FILE *fp; /* current input file */
+ FILE_POS file_pos; /* current file position */
+ short ftype; /* the type of the current file */
+ OBJECT next_token; /* next token if already read */
+ int offset; /* where to start reading in file */
+ int first_line_num; /* number of first line (if offset) */
+ BOOLEAN same_file; /* TRUE if same file as preceding */
+ long save_ftell; /* ftell() position if same_file */
+ FULL_CHAR *mem_block; /* file buffer */
+ } lex_stack[MAX_LEX_STACK];
+
+ /*@::LexLegalName(), LexInit()@***********************************************/
+ /* */
+ /* BOOLEAN LexLegalName(str) */
+ /* */
+ /* Check whether str is a valid name for a symbol table entry. */
+ /* Valid names have the BNF form */
+ /* */
+ /* <name> ::= <letter> { <letter> } */
+ /* <name> ::= <special> { <special> } */
+ /* <name> ::= <escape> { <letter> } */
+ /* */
+ /* The third form is inaccessible to users and is for internal use only. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN LexLegalName(FULL_CHAR *str)
+ { int i; BOOLEAN res;
+ debug1(DLA, DDD, "LexLegalName( %s )", str);
+ switch( chtbl[str[0]] )
+ {
+ case ESCAPE:
+ case LETTER:
+
+ for( i = 1; chtbl[str[i]] == LETTER; i++ );
+ res = str[i] == '\0';
+ break;
+
+
+ case OTHER:
+
+ for( i = 1; chtbl[str[i]] == OTHER; i++ );
+ res = str[i] == '\0';
+ break;
+
+
+ default:
+
+ res = FALSE;
+ break;
+
+ }
+ debug1(DLA, DDD, "LexLegalName returning %s", bool(res));
+ return res;
+ } /* end LexLegalName */
+
+
+ /*****************************************************************************/
+ /* */
+ /* LexInit() */
+ /* */
+ /* Initialise character types. Those not touched are 0 (OTHER). */
+ /* The function initchtbl() assists in initializing the chtbl. */
+ /* */
+ /*****************************************************************************/
+
+ static void initchtbl(val, str)
+ int val; FULL_CHAR *str;
+ { int i;
+ for( i = 0; str[i] != '\0'; i++ )
+ chtbl[ str[i] ] = val;
+ } /* end initchtbl */
+
+ void LexInit(void)
+ { initchtbl(LETTER, STR_LETTERS_LOWER);
+ initchtbl(LETTER, STR_LETTERS_UPPER);
+ initchtbl(LETTER, STR_LETTERS_SYMSTART);
+ initchtbl(LETTER, STR_LETTERS_UNDERSCORE);
+ initchtbl(LETTER, STR_LETTERS_EXTRA0);
+ initchtbl(LETTER, STR_LETTERS_EXTRA1);
+ initchtbl(LETTER, STR_LETTERS_EXTRA2);
+ initchtbl(LETTER, STR_LETTERS_EXTRA3);
+ initchtbl(LETTER, STR_LETTERS_EXTRA4);
+ initchtbl(LETTER, STR_LETTERS_EXTRA5);
+ initchtbl(LETTER, STR_LETTERS_EXTRA6);
+ initchtbl(LETTER, STR_LETTERS_EXTRA7);
+ initchtbl(QUOTE, STR_QUOTE);
+ initchtbl(ESCAPE, STR_ESCAPE);
+ initchtbl(COMMENT, STR_COMMENT);
+ initchtbl(CSPACE, STR_SPACE);
+ initchtbl(FORMFEED,STR_FORMFEED);
+ initchtbl(TAB, STR_TAB);
+ initchtbl(NEWLINE, STR_NEWLINE);
+ chtbl['\0'] = ENDFILE;
+ stack_free = -1;
+ } /* end LexInit */
+
+ /*@::LexPush(), LexPop()@*****************************************************/
+ /* */
+ /* LexPush(x, offs, ftype, lnum, same) */
+ /* */
+ /* Start reading from the file sequence whose first file is x (subsequent */
+ /* files are obtained from NextFile). The first file (x) is to be fseeked */
+ /* to offs. When the sequence is done, ftype determines how to continue: */
+ /* */
+ /* ftype action */
+ /* */
+ /* SOURCE_FILE last input file ends, return @End \Input */
+ /* DATABASE_FILE database file, return @End \Input */
+ /* INCLUDE_FILE include file, must pop lexical analyser and continue */
+ /* FILTER_FILE filter file, return @End @FilterOut */
+ /* */
+ /* lnum is the line number at offs, to be used when creating file pos's */
+ /* in the tokens returned. same is TRUE when this file is the same as */
+ /* the file currently being read, in which case there is no need to */
+ /* close that file and open this one; just an fseek is required. */
+ /* */
+ /*****************************************************************************/
+
+ void LexPush(FILE_NUM x, int offs, int ftyp, int lnum, BOOLEAN same)
+ { int i;
+ debug5(DLA, DD, "LexPush(%s, %d, %s, %d, %s)", FileName(x), offs,
+ ftyp==SOURCE_FILE ? "source" : ftyp==INCLUDE_FILE ? "include":"database",
+ lnum, bool(same));
+ if( stack_free >= MAX_LEX_STACK - 1 )
+ { if( ftyp == INCLUDE_FILE )
+ Error(2, 1, "too many open files when opening include file %s; open files are:",
+ WARN, PosOfFile(x), FullFileName(x));
+ else
+ Error(2, 2, "too many open files when opening database file %s; open files are:",
+ WARN, PosOfFile(x), FileName(x));
+ for( i = stack_free - 1; i >= 0; i-- )
+ {
+ Error(2, 23, " %s", WARN, no_fpos,
+ EchoFileSource(lex_stack[i].this_file));
+ }
+ Error(2, 24, "exiting now", FATAL, no_fpos);
+ }
+ if( stack_free >= 0 ) /* save current state */
+ { lex_stack[stack_free].chpt = chpt;
+ lex_stack[stack_free].frst = frst;
+ lex_stack[stack_free].limit = limit;
+ lex_stack[stack_free].buf = buf;
+ lex_stack[stack_free].blksize = blksize;
+ lex_stack[stack_free].last_char = last_char;
+ lex_stack[stack_free].startline = startline;
+ lex_stack[stack_free].this_file = this_file;
+ lex_stack[stack_free].fp = fp;
+ lex_stack[stack_free].ftype = ftype;
+ lex_stack[stack_free].next_token = next_token;
+ lex_stack[stack_free].offset = offset;
+ lex_stack[stack_free].first_line_num = first_line_num;
+ lex_stack[stack_free].same_file = same_file;
+ lex_stack[stack_free].mem_block = mem_block;
+ FposCopy( lex_stack[stack_free].file_pos, file_pos );
+ }
+ stack_free += 1;
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_LEX,1, (MAX_LINE+BUFFER_SIZE+2)*sizeof(FULL_CHAR)));
+ mem_block = (FULL_CHAR *) malloc((MAX_LINE+BUFFER_SIZE+2)*sizeof(FULL_CHAR));
+ if( mem_block == NULL )
+ Error(2, 3, "run out of memory when opening file %s",
+ FATAL, PosOfFile(x), FullFileName(x));
+ buf = chpt = &mem_block[MAX_LINE];
+ last_char = CH_NEWLINE;
+ this_file = x; offset = offs;
+ first_line_num = lnum; same_file = same;
+ ftype = ftyp; next_token = nilobj;
+ *chpt = '\0';
+ if( same_file )
+ { lex_stack[stack_free-1].save_ftell = ftell(fp);
+ }
+ else
+ { fp = null;
+ }
+ } /* end LexPush */
+
+
+ /*****************************************************************************/
+ /* */
+ /* LexPop() - pop lexical analyser. */
+ /* */
+ /*****************************************************************************/
+
+ void LexPop(void)
+ { debug0(DLA, DD, "LexPop()");
+ assert( stack_free > 0, "LexPop: stack_free <= 0!" );
+ stack_free--;
+ if( same_file )
+ { fseek(fp, lex_stack[stack_free].save_ftell, SEEK_SET);
+ }
+ else
+ { if( fp != null ) fclose(fp);
+ }
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_LEX,-1,-(MAX_LINE+BUFFER_SIZE+2)* (int) sizeof(FULL_CHAR))
+ );
+ free( (char *) mem_block);
+ mem_block = lex_stack[stack_free].mem_block;
+ chpt = lex_stack[stack_free].chpt;
+ frst = lex_stack[stack_free].frst;
+ limit = lex_stack[stack_free].limit;
+ buf = lex_stack[stack_free].buf;
+ blksize = lex_stack[stack_free].blksize;
+ last_char = lex_stack[stack_free].last_char;
+ startline = lex_stack[stack_free].startline;
+ this_file = lex_stack[stack_free].this_file;
+ fp = lex_stack[stack_free].fp;
+ ftype = lex_stack[stack_free].ftype;
+ next_token = lex_stack[stack_free].next_token;
+ offset = lex_stack[stack_free].offset;
+ first_line_num = lex_stack[stack_free].first_line_num;
+ same_file = lex_stack[stack_free].same_file;
+ FposCopy( file_pos, lex_stack[stack_free].file_pos );
+ } /* end LexPop */
+
+
+ /*@::setword(), LexNextTokenPos(), srcnext()@*********************************/
+ /* */
+ /* setword(typ, res, file_pos, str, len) */
+ /* */
+ /* Set variable res to a WORD or QWORD token containing string str, etc. */
+ /* */
+ /*****************************************************************************/
+
+ #define setword(typ, res, file_pos, str, len) \
+ { NewWord(res, typ, len, &file_pos); \
+ FposCopy(fpos(res), file_pos); \
+ for( c = 0; c < len; c++ ) string(res)[c] = str[c]; \
+ string(res)[c] = '\0'; \
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* long LexNextTokenPos() */
+ /* */
+ /* Equivalent to ftell() on the (buffered) current lex file. */
+ /* */
+ /*****************************************************************************/
+
+ long LexNextTokenPos(void)
+ { long res;
+ if( next_token != nilobj )
+ Error(2, 4, "illegal macro invocation in database",
+ FATAL, &fpos(next_token));
+ res = ftell(fp) - (limit - chpt) - (buf - frst);
+ #if DB_FIX
+ /* uwe: 1997-11-04
+ *
+ * On NT under Visual C++ ftell() and fseek() always use binary
+ * positions, even if the file was opened in text mode. This means
+ * that every LF in between the CHPT and LIMIT was counted by
+ * ftell() as *TWO* bytes. The pointer arithmetic above adjusts the
+ * ftold value as lout has not yet read chars past CHPT, but it
+ * counts each LF as *ONE* byte, naturally.
+ *
+ * The code below compensates for this binary/text brain death.
+ *
+ * PS: gcc from Cygnus' gnuwin32 has sane ftell() and does *NOT*
+ * need this workaround (I haven't tried compiling lout with gcc
+ * though, as the result will need cygwin.dll to run).
+ */
+ {
+ register FULL_CHAR *p;
+ for (p = chpt; p < limit; ++p) {
+ if (*p == (FULL_CHAR) CH_NEWLINE)
+ --res;
+ }
+ }
+ #endif /* DB_FIX */
+
+ debug1(DLA, DD, "LexNextTokenPos() returning %ld", res);
+ return res;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* static srcnext() */
+ /* */
+ /* Move to new line of input file. May need to recharge buffer. */
+ /* */
+ /*****************************************************************************/
+
+ static void srcnext(void)
+ { register FULL_CHAR *col;
+ debugcond4(DLA, DD, stack_free <= 1,
+ "srcnext(); buf: %d, chpt: %d, frst: %d, limit: %d",
+ buf - mem_block, chpt - mem_block, frst - mem_block, limit - mem_block);
+
+ /* if time to transfer last line to area preceding buffer, do so */
+ if( blksize != 0 && chpt < limit )
+ { debugcond0(DLA, DD, stack_free <= 1, "srcnext: transferring.");
+ col = buf;
+ while( (*--col = *--limit) != CH_NEWLINE );
+ frst = col + 1; limit++; blksize = 0;
+ }
+
+ /* if buffer is empty, read next block */
+ /*** changed by JK 9/92 from "if( chpt == limit )" to fix long lines bug */
+ if( chpt >= limit )
+ { if( chpt > limit )
+ { col_num(file_pos) = 1;
+ Error(2, 5, "line is too long (or final newline missing)",
+ FATAL, &file_pos);
+ }
+ chpt = frst;
+ blksize = fread( (char *) buf, sizeof(char), BUFFER_SIZE, fp);
+ if( blksize > 0 )
+ last_char = *(buf + blksize - 1);
+ if( blksize < BUFFER_SIZE && last_char != CH_NEWLINE )
+ {
+ /* at end of file since blksize = 0; so add missing newline char */
+ blksize++;
+ last_char = *(buf+blksize-1) = CH_NEWLINE;
+
+ /* this adjustment breaks LexNextTokenPos, so fatal error if database */
+ if( ftype == DATABASE_FILE )
+ {
+ line_num(file_pos) = col_num(file_pos) = 0;
+ Error(2, 25, "a database file must end with a newline; this one doesn't",
+ FATAL, &file_pos);
+ }
+ }
+ debugcond4(DLA, DD, stack_free <= 1,
+ "srcnext: %d = fread(0x%x, %d, %d, fp)",
+ blksize, buf, sizeof(char), BUFFER_SIZE);
+ frst = buf; limit = buf + blksize; *limit = CH_NEWLINE;
+ }
+
+ /* if nothing more to read, make this clear */
+ if( chpt >= limit )
+ { debugcond0(DLA, DD, stack_free <= 1, "srcnext: nothing more to read");
+ chpt = limit = buf; *limit = '\0';
+ }
+ debugcond4(DLA, DD, stack_free <= 1,
+ "srcnext returning; buf: %d, chpt: %d, frst: %d, limit: %d",
+ buf - mem_block, chpt - mem_block, frst - mem_block, limit - mem_block);
+ } /* end srcnext */
+
+
+ /*@::LexGetToken()@***********************************************************/
+ /* */
+ /* OBJECT LexGetToken() */
+ /* */
+ /* Get next token from input. Look it up in symbol table. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT LexGetToken(void)
+ {
+ FULL_CHAR *startpos; /* where the latest token started */
+ register FULL_CHAR *p, *q; /* pointer to current input char */
+ register int c; /* temporary character (really char) */
+ OBJECT res; /* result token */
+ int vcount, hcount; /* no. of newlines and spaces seen */
+
+ if( next_token != nilobj )
+ { next_token = Delete(res = next_token, PARENT);
+ debugcond4(DLA, DD, stack_free <= 1,
+ "LexGetToken%s (in macro) returning %d.%d %s",
+ EchoFilePos(&file_pos), vspace(res), hspace(res), EchoToken(res));
+ return res;
+ }
+
+ res = nilobj; p = chpt;
+ vcount = hcount = 0;
+ do switch( chtbl[*p++] )
+ {
+ case ESCAPE:
+
+ if( ftype==DATABASE_FILE && *p>='a' && *p<='z' && *(p+1) == '{' /*}*/ )
+ { res = NewToken(LBR, &file_pos, 0, 0, (unsigned) *p, StartSym);
+ p += 2;
+ }
+ else
+ {
+ col_num(file_pos) = (startpos = p-1) - startline;
+ Error(2, 6, "character %c outside quoted string",
+ WARN, &file_pos, *startpos);
+ }
+ break;
+
+
+ case COMMENT:
+
+ debug1(DLA, DDD, "LexGetToken%s: comment", EchoFilePos(&file_pos));
+ while( (c = *p++) != CH_NEWLINE && c != '\0' );
+ if( c == CH_NEWLINE )
+ {
+ /* do NEWLINE action, only preserve existing horizontal space */
+ /* and don't count the newline in the vcount. */
+ chpt = p; srcnext();
+ line_num(file_pos)++;
+ col_num(file_pos) = 0;
+ startline = (p = chpt) - 1;
+ }
+ else
+ {
+ --p;
+ }
+ break;
+
+
+ case CSPACE:
+ case FORMFEED:
+
+ hcount++;
+ break;
+
+
+ case TAB:
+
+ hcount += 8;
+ break;
+
+
+ case NEWLINE:
+
+ chpt = p; srcnext();
+ line_num(file_pos)++;
+ col_num(file_pos) = 0;
+ vcount++; hcount = 0;
+ startline = (p = chpt) - 1;
+ break;
+
+
+ case ENDFILE:
+
+ debug0(DLA, DDD, "LexGetToken: endfile");
+ if( !same_file )
+ {
+ /* close current file, if any */
+ if( fp != null )
+ { fclose(fp); fp = null;
+ this_file = ftype == SOURCE_FILE ? NextFile(this_file) : NO_FILE;
+ }
+
+ /* open next file */
+ while( this_file != NO_FILE )
+ { file_num(file_pos) = this_file;
+ line_num(file_pos) = 1;
+ col_num(file_pos) = 0;
+ fp = OpenFile(this_file, FALSE, TRUE);
+ if( fp != null ) break;
+ Error(2, 7, "cannot open file %s",
+ WARN, &file_pos, FullFileName(this_file));
+ this_file = ftype == SOURCE_FILE ? NextFile(this_file) : NO_FILE;
+ }
+ }
+
+ if( fp != null )
+ { if( offset != 0 )
+ { debugcond1(DLA, DD, stack_free <= 1, "fseek(fp, %d, SEEK_SET)", offset);
+ fseek(fp, (long) offset, SEEK_SET);
+ offset = 0L;
+ line_num(file_pos) = first_line_num;
+ }
+ frst = limit = chpt = buf;
+ blksize = 0; last_char = CH_NEWLINE;
+ srcnext();
+ startline = (p = chpt) - 1;
+ hcount = 0;
+ }
+
+ /* no next file, so take continuation */
+ else switch( ftype )
+ {
+
+ case SOURCE_FILE:
+ case DATABASE_FILE:
+
+ /* input ends with "@End \Input" then UNEXPECTED_EOF */
+ res = NewToken(END, &file_pos, 0, 0, END_PREC, StartSym);
+ next_token = NewToken(UNEXPECTED_EOF, &file_pos,0,0,NO_PREC,nilobj);
+ --p; startline = p;
+ break;
+
+
+ case FILTER_FILE:
+
+ /* input ends with "@End @FilterOut" */
+ res = NewToken(END, &file_pos, 0, 0, END_PREC, FilterOutSym);
+ /* ***
+ next_token = NewToken(CLOSURE,&file_pos,0,0,NO_PREC,FilterOutSym);
+ *** */
+ --p; startline = p;
+ break;
+
+
+ case INCLUDE_FILE:
+
+ LexPop();
+ p = chpt;
+ hcount = 0;
+ break;
+
+
+ default:
+
+ assert(FALSE, "unknown file type");
+ break;
+
+ } /* end switch */
+ break;
+
+
+ case OTHER:
+
+ col_num(file_pos) = (startpos = p-1) - startline;
+ while( chtbl[*p++] == OTHER );
+ c = p - startpos - 1;
+ do
+ { res = SearchSym(startpos, c);
+ --c; --p;
+ } while( c > 0 && res == nilobj );
+ goto MORE; /* 7 lines down */
+
+
+ case LETTER:
+
+ col_num(file_pos) = (startpos = p-1) - startline;
+ while( chtbl[*p++] == LETTER ); --p;
+ res = SearchSym(startpos, p - startpos);
+
+ MORE: if( res == nilobj )
+ { setword(WORD, res, file_pos, startpos, p-startpos);
+ }
+ else if( type(res) == MACRO )
+ { if( recursive(res) )
+ { Error(2, 8, "recursion in macro", WARN, &file_pos);
+ setword(WORD, res, file_pos, startpos, p-startpos);
+ }
+ else
+ { res = CopyTokenList( sym_body(res), &file_pos );
+ if( res != nilobj ) next_token = Delete(res, PARENT);
+ else hcount = 0;
+ }
+ }
+ else if( predefined(res) == 0 )
+ { res = NewToken(CLOSURE, &file_pos, 0, 0, precedence(res), res);
+ }
+ else if( predefined(res) == INCLUDE || predefined(res) == SYS_INCLUDE )
+ { OBJECT t, fname; FILE_NUM fnum; int len; BOOLEAN scope_suppressed;
+ chpt = p;
+ t = LexGetToken();
+ scope_suppressed = (type(t)==WORD && StringEqual(string(t), KW_LBR));
+
+ if( type(t)!=LBR && !scope_suppressed )
+ { Error(2, 9, "%s expected (after %s)",
+ WARN, &fpos(t), KW_LBR, SymName(res));
+ Dispose(t);
+ res = nilobj;
+ break;
+ }
+ if( scope_suppressed )
+ { UnSuppressScope();
+ Dispose(t);
+ New(t, LBR);
+ }
+ fname = Parse(&t, nilobj, FALSE, FALSE);
+ fname = ReplaceWithTidy(fname, FALSE);
+ if( scope_suppressed ) SuppressScope();
+ if( !is_word(type(fname)) )
+ { Error(2, 10, "name of include file expected here",
+ WARN, &fpos(fname));
+ Dispose(fname);
+ res = nilobj;
+ break;
+ }
+ len = StringLength(string(fname)) - StringLength(SOURCE_SUFFIX);
+ if( len >= 0 && StringEqual(&string(fname)[len], SOURCE_SUFFIX) )
+ StringCopy(&string(fname)[len], STR_EMPTY);
+ debug0(DFS, D, " calling DefineFile from LexGetToken");
+ fnum = DefineFile(string(fname), STR_EMPTY, &fpos(fname),
+ INCLUDE_FILE,
+ predefined(res)==INCLUDE ? INCLUDE_PATH : SYSINCLUDE_PATH);
+ Dispose(fname);
+ LexPush(fnum, 0, INCLUDE_FILE, 1, FALSE);
+ res = LexGetToken();
+ vcount++; /** TEST ADDITION! **/
+ p = chpt;
+ }
+ else if( predefined(res) == END )
+ res = NewToken(predefined(res), &file_pos,0,0,precedence(res),nilobj);
+ else
+ res = NewToken(predefined(res), &file_pos,0,0,precedence(res),res);
+ break;
+
+
+ case QUOTE:
+
+ col_num(file_pos) = (startpos = q = p) - 1 - startline;
+ do switch( chtbl[*q++ = *p++] )
+ {
+ case OTHER:
+ case LETTER:
+ case COMMENT:
+ case CSPACE:
+ case FORMFEED:
+ case TAB: break;
+
+ case NEWLINE:
+ case ENDFILE: --p;
+ Error(2, 11, "unterminated string", WARN, &file_pos);
+ setword(QWORD, res, file_pos, startpos, q-1-startpos);
+ break;
+
+ case QUOTE: setword(QWORD, res, file_pos, startpos, q-1-startpos);
+ break;
+
+ case ESCAPE: q--;
+ if( chtbl[*p] == NEWLINE || chtbl[*p] == ENDFILE )
+ { Error(2, 12, "unterminated string", WARN, &file_pos);
+ setword(QWORD, res, file_pos, startpos, q-startpos);
+ }
+ else if( octaldigit(*p) )
+ { int count, ch;
+ count = ch = 0;
+ do
+ { ch = ch * 8 + digitchartonum(*p++);
+ count++;
+ } while( octaldigit(*p) && count < 3 );
+ if( ch == '\0' )
+ Error(2, 13, "skipping null character in string",
+ WARN, &file_pos);
+ else *q++ = ch;
+ }
+ else *q++ = *p++;
+ break;
+
+ default: Error(2, 14, "LexGetToken: error in quoted string",
+ INTERN, &file_pos);
+ break;
+
+ } while( res == nilobj );
+ break;
+
+
+ default:
+
+ assert(FALSE, "LexGetToken: bad chtbl[]");
+ break;
+
+ } while( res == nilobj );
+
+ if( p - startline >= MAX_LINE )
+ { col_num(file_pos) = 1;
+ Error(2, 15, "line is too long (or final newline missing)",FATAL,&file_pos);
+ }
+
+ chpt = p;
+ vspace(res) = vcount;
+ hspace(res) = hcount;
+ debugcond5(DLA, DD, stack_free <= 1, "LexGetToken%s returning %s %s %d.%d",
+ EchoFilePos(&file_pos), Image(type(res)), EchoToken(res),
+ vspace(res), hspace(res));
+ return res;
+ } /* end LexGetToken */
+
+
+ /*@::LexScanVerbatim@*********************************************************/
+ /* */
+ /* OBJECT LexScanVerbatim(fp, end_stop, err_pos, lessskip) */
+ /* */
+ /* Scan input file and transfer to filter file fp, or if that is NULL, make */
+ /* a VCAT of objects, one per line (or just a WORD if one line only), and */
+ /* return that object as the result. If end_stop, terminate at @End, else */
+ /* terminate at matching right brace. */
+ /* */
+ /* If lessskip is true it means that we should skip only up to and */
+ /* including the first newline character, as opposed to the usual */
+ /* skipping of all initial white space characters. */
+ /* */
+ /*****************************************************************************/
+
+ #define print(ch) \
+ { debug2(DLA, D, "print(%c), bufftop = %d", ch, bufftop); \
+ if( fp == NULL ) \
+ { if( bufftop < MAX_BUFF ) \
+ { if( chtbl[ch] == NEWLINE ) \
+ { res = BuildLines(res, buff, &bufftop); \
+ } \
+ else buff[bufftop++] = ch; \
+ } \
+ } \
+ else putc(ch, fp); \
+ }
+
+ #define clear() \
+ { int i; \
+ for( i = 0; i < hs_top; i++ ) print(hs_buff[i]); \
+ hs_top = 0; \
+ }
+
+ #define hold(ch) \
+ { if( hs_top == MAX_BUFF ) clear(); \
+ hs_buff[hs_top++] = ch; \
+ }
+
+ static OBJECT BuildLines(OBJECT current, FULL_CHAR *buff, int *bufftop)
+ { OBJECT wd, res, gp, gpword; int c;
+
+ /* build a new word and reset the buffer */
+ setword(WORD, wd, file_pos, buff, *bufftop);
+ debug1(DLA, D, "BuildLines(current, %s)", EchoObject(wd));
+ *bufftop = 0;
+
+ if( current == nilobj )
+ {
+ /* if this is the first word, make it the result */
+ res = wd;
+ }
+ else
+ {
+ /* if this is the second word, make the result a VCAT */
+ if( type(current) == WORD )
+ { New(res, VCAT);
+ FposCopy(fpos(res), fpos(current));
+ Link(res, current);
+ }
+ else res = current;
+
+ /* now attach the new word to res, preceded by a one-line gap */
+ New(gp, GAP_OBJ);
+ mark(gap(gp)) = FALSE;
+ join(gap(gp)) = FALSE;
+ FposCopy(fpos(gp), file_pos);
+ gpword = MakeWord(WORD, AsciiToFull("1vx"), &file_pos);
+ Link(gp, gpword);
+ Link(res, gp);
+ Link(res, wd);
+ }
+ debug1(DLA, D, "BuildLines returning %s", EchoObject(res));
+ return res;
+ }
+
+ OBJECT LexScanVerbatim(fp, end_stop, err_pos, lessskip)
+ FILE *fp; BOOLEAN end_stop; FILE_POS *err_pos; BOOLEAN lessskip;
+ {
+ register FULL_CHAR *p; /* pointer to current input char */
+ int depth; /* depth of nesting of { ... } */
+ BOOLEAN finished; /* TRUE when finished */
+ BOOLEAN skipping; /* TRUE when skipping initial spaces */
+ FULL_CHAR hs_buff[MAX_BUFF]; /* hold spaces here in case last */
+ int hs_top; /* next free spot in hs_buff */
+ FULL_CHAR buff[MAX_BUFF]; /* hold line here if not to file */
+ int bufftop; /* top of buff */
+ OBJECT res = nilobj; /* result object if not to file */
+
+ debug3(DLA, D, "LexScanVerbatim(fp, %s, %s, %s)",
+ bool(end_stop), EchoFilePos(err_pos), bool(lessskip));
+ if( next_token != nilobj )
+ { Error(2, 16, "filter parameter in macro", FATAL, err_pos);
+ }
+
+ p = chpt; depth = 0;
+ finished = FALSE;
+ skipping = TRUE;
+ hs_top = 0;
+ bufftop = 0;
+ while( !finished ) switch( chtbl[*p++] )
+ {
+ case ESCAPE:
+ case COMMENT:
+ case QUOTE:
+
+ skipping = FALSE;
+ clear();
+ print(*(p-1));
+ break;
+
+
+ case CSPACE:
+ case TAB:
+ case FORMFEED:
+
+ if( !skipping ) hold(*(p-1));
+ break;
+
+
+ case NEWLINE:
+
+ if( !skipping ) hold(*(p-1));
+ if( lessskip ) skipping = FALSE;
+ chpt = p; srcnext();
+ line_num(file_pos)++;
+ col_num(file_pos) = 0;
+ startline = (p = chpt) - 1;
+ break;
+
+
+ case ENDFILE:
+
+ if( fp == NULL )
+ Error(2, 22, "end of file reached while reading %s",
+ FATAL, err_pos, lessskip ? KW_RAWVERBATIM : KW_VERBATIM);
+ else
+ Error(2, 17, "end of file reached while reading filter parameter",
+ FATAL, err_pos);
+ break;
+
+
+ case OTHER:
+
+ skipping = FALSE;
+ if( *(p-1) == '{' /*}*/ )
+ { clear();
+ print(*(p-1));
+ depth++;
+ }
+ else if( *(p-1) == /*{*/ '}' )
+ { if( !end_stop && depth == 0 )
+ { p--;
+ finished = TRUE;
+ }
+ else
+ { clear();
+ print(*(p-1));
+ depth--;
+ }
+ }
+ else
+ { clear();
+ print(*(p-1));
+ }
+ break;
+
+
+ case LETTER:
+
+ skipping = FALSE;
+ if( *(p-1) == '@' )
+ {
+ p--;
+ if( end_stop && StringBeginsWith(p, KW_END) )
+ { finished = TRUE;
+ }
+ else if( StringBeginsWith(p, KW_INCLUDE) ||
+ StringBeginsWith(p, KW_SYSINCLUDE) )
+ { OBJECT incl_fname, t; FILE *incl_fp; int ch; FILE_NUM fnum;
+ BOOLEAN sysinc = StringBeginsWith(p, KW_SYSINCLUDE);
+ clear();
+ p += sysinc ? StringLength(KW_SYSINCLUDE):StringLength(KW_INCLUDE);
+ chpt = p;
+ t = LexGetToken();
+ if( type(t) != LBR ) Error(2, 18, "expected %s here (after %s)",
+ FATAL, &fpos(t), KW_LBR, sysinc ? KW_SYSINCLUDE : KW_INCLUDE);
+ incl_fname = Parse(&t, nilobj, FALSE, FALSE);
+ p = chpt;
+ incl_fname = ReplaceWithTidy(incl_fname, FALSE);
+ if( !is_word(type(incl_fname)) )
+ Error(2, 19, "expected file name here", FATAL,&fpos(incl_fname));
+ debug0(DFS, D, " calling DefineFile from LexScanVerbatim");
+ fnum = DefineFile(string(incl_fname), STR_EMPTY, &fpos(incl_fname),
+ INCLUDE_FILE, sysinc ? SYSINCLUDE_PATH : INCLUDE_PATH);
+ Dispose(incl_fname);
+ incl_fp = OpenFile(fnum, FALSE, TRUE);
+ if( incl_fp == NULL )
+ Error(2, 20, "cannot open include file %s",
+ FATAL, PosOfFile(fnum), FullFileName(fnum));
+ while( (ch = getc(incl_fp)) != EOF )
+ print(ch);
+ fclose(incl_fp);
+ }
+ else
+ { clear();
+ print(*p);
+ p++;
+ }
+ }
+ else
+ { clear();
+ print(*(p-1));
+ }
+ break;
+
+
+ default:
+
+ Error(2, 22, "unreadable character (octal %o)",INTERN,&file_pos,*(p-1));
+ assert(FALSE, "LexScanVerbatim: bad chtbl[]");
+ break;
+
+ };
+ print('\n');
+
+ if( p - startline >= MAX_LINE )
+ { col_num(file_pos) = 1;
+ Error(2, 21, "line is too long (or final newline missing)",FATAL,&file_pos);
+ }
+
+ chpt = p;
+ if( fp == NULL && res == nilobj )
+ res = MakeWord(WORD, STR_EMPTY, &file_pos);
+
+ debug2(DLA, D, "LexScanVerbatim returning %s at %s",
+ EchoObject(res), EchoFilePos(&file_pos));
+ return res;
+ } /* end LexScanVerbatim */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z03.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z03.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z03.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,906 ----
+ /*@z03.c:File Service:Declarations, no_fpos@******************************** */
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.23) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z03.c */
+ /* MODULE: File Service */
+ /* EXTERNS: InitFiles(), AddToPath(), DefineFile(), FirstFile(), */
+ /* NextFile(), FileNum(), FileName(), EchoFilePos(), */
+ /* PosOfFile(), OpenFile(), OpenIncGraphicFile() */
+ /* EchoFileFrom() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #if USE_STAT
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #endif
+
+ #define INIT_TAB 3 /* initial file table size */
+
+ #define file_number(x) word_font(x) /* file number of file x */
+ #define type_of_file(x) word_colour(x) /* type of file x */
+ #define used_suffix(x) word_hyph(x) /* file needs .lt suffix */
+ #define updated(x) fwd(x, COLM) /* TRUE when x is updated */
+ #define line_count(x) fwd(x, ROWM) /* number of lines written */
+ #define path(x) back(x, COLM) /* search path for file x */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FILE_TABLE */
+ /* */
+ /* A symbol table permitting access to file records by number or name. */
+ /* The table will automatically enlarge to accept any number of entries, */
+ /* but there is an arbitrary limit of 65535 files imposed so that file */
+ /* numbers can be stored in 16 bit fields. */
+ /* */
+ /* ftab_new(newsize) New empty table, newsize capacity */
+ /* ftab_insert(x, &S) Insert new file object x into S */
+ /* ftab_retrieve(str, S) Retrieve file object of name str */
+ /* ftab_num(S, num) Retrieve file object of number num */
+ /* ftab_debug(S, fp) Debug print of table S to file fp */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { int filetab_size; /* size of table */
+ int filetab_count; /* number of files in table */
+ struct filetab_rec
+ { OBJECT by_number; /* file record by number */
+ OBJECT by_name_hash; /* file record by name hash */
+ } filetab[1];
+ } *FILE_TABLE;
+
+ #define ftab_size(S) (S)->filetab_size
+ #define ftab_count(S) (S)->filetab_count
+ #define ftab_num(S, i) (S)->filetab[i].by_number
+ #define ftab_name(S, i) (S)->filetab[i].by_name_hash
+
+ #define hash(pos, str, S) \
+ { FULL_CHAR *p = str; \
+ pos = *p++; \
+ while( *p ) pos += *p++; \
+ pos = pos % ftab_size(S); \
+ }
+
+ static FILE_TABLE ftab_new(int newsize)
+ { FILE_TABLE S; int i;
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_FILES, 1,
+ 2*sizeof(int) + newsize * sizeof(struct filetab_rec)));
+ S = (FILE_TABLE) malloc(2*sizeof(int) + newsize * sizeof(struct filetab_rec));
+ if( S == (FILE_TABLE) NULL )
+ Error(3, 1, "run out of memory when enlarging file table", FATAL, no_fpos);
+ ftab_size(S) = newsize;
+ ftab_count(S) = 0;
+ for( i = 0; i < newsize; i++ )
+ { ftab_num(S, i) = ftab_name(S, i) = nilobj;
+ }
+ return S;
+ } /* end ftab_new */
+
+ static void ftab_insert(OBJECT x, FILE_TABLE *S);
+
+ static FILE_TABLE ftab_rehash(FILE_TABLE S, int newsize)
+ { FILE_TABLE NewS; int i;
+ NewS = ftab_new(newsize);
+ for( i = 1; i <= ftab_count(S); i++ )
+ ftab_insert(ftab_num(S, i), &NewS);
+ for( i = 0; i < ftab_size(S); i++ )
+ { if( ftab_name(S, i) != nilobj ) DisposeObject(ftab_name(S, i));
+ }
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_FILES, -1,
+ -(2*sizeof(int) + ftab_size(S) * sizeof(struct filetab_rec))));
+ free(S);
+ return NewS;
+ } /* end ftab_rehash */
+
+ static void ftab_insert(OBJECT x, FILE_TABLE *S)
+ { int pos, num;
+ if( ftab_count(*S) == ftab_size(*S) - 1 ) /* one less since 0 unused */
+ *S = ftab_rehash(*S, 2*ftab_size(*S));
+ num = ++ftab_count(*S);
+ if( num > MAX_FILES )
+ Error(3, 2, "too many files (maximum is %d)",
+ FATAL, &fpos(x), MAX_FILES);
+ hash(pos, string(x), *S);
+ if( ftab_name(*S, pos) == nilobj ) New(ftab_name(*S, pos), ACAT);
+ Link(ftab_name(*S, pos), x);
+ file_number(x) = num;
+ ftab_num(*S, num) = x;
+ } /* end ftab_insert */
+
+ static OBJECT ftab_retrieve(FULL_CHAR *str, FILE_TABLE S)
+ { OBJECT x, link, y; int pos;
+ hash(pos, str, S);
+ x = ftab_name(S, pos);
+ if( x == nilobj ) return nilobj;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(str, string(y)) ) return y;
+ }
+ return nilobj;
+ } /* end ftab_retrieve */
+
+ #if DEBUG_ON
+ static void ftab_debug(FILE_TABLE S, FILE *fp)
+ { int i; OBJECT x, link, y;
+ fprintf(fp, " table size: %d; current number of files: %d\n",
+ ftab_size(S), ftab_count(S));
+ for( i = 0; i < ftab_size(S); i++ )
+ { x = ftab_num(S, i);
+ fprintf(fp, " ftab_num(S, %d) = %s\n", i,
+ x == nilobj ? AsciiToFull("<nilobj>") :
+ !is_word(type(x)) ? AsciiToFull("not WORD!") : string(x) );
+ }
+ fprintf(fp, "\n");
+ for( i = 0; i < ftab_size(S); i++ )
+ { x = ftab_name(S, i);
+ fprintf(fp, " ftab_name(S, %d) =", i);
+ if( x == nilobj )
+ fprintf(fp, " <nilobj>");
+ else if( type(x) != ACAT )
+ fprintf(fp, " not ACAT!");
+ else for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ fprintf(fp, " %s",
+ is_word(type(y)) ? string(y) : AsciiToFull("not-WORD!"));
+ }
+ fprintf(fp, "\n");
+ }
+ } /* end ftab_debug */
+
+ static char *file_types[] /* the type names for debug */
+ = { "source", "include", "incgraphic", "database", "index",
+ "font", "prepend", "hyph", "hyphpacked",
+ "mapping", "filter" };
+ #endif
+
+
+ static OBJECT empty_path; /* file path with just "" in */
+ static FILE_TABLE file_tab; /* the file table */
+ static OBJECT file_type[MAX_TYPES]; /* files of each type */
+ static OBJECT file_path[MAX_PATHS]; /* the search paths */
+ static char *file_mode[MAX_TYPES] =
+ { READ_TEXT, READ_TEXT, READ_TEXT, READ_TEXT, READ_BINARY, READ_TEXT,
+ READ_TEXT, READ_TEXT, READ_BINARY, READ_TEXT, READ_TEXT };
+
+
+ /*****************************************************************************/
+ /* */
+ /* no_fpos */
+ /* */
+ /* A null file position value. */
+ /* */
+ /*****************************************************************************/
+
+ static FILE_POS no_file_pos = {0, 0, 0, 0, 0};
+ FILE_POS *no_fpos = &no_file_pos;
+
+
+ /*@::InitFiles(), AddToPath(), DefineFile()@**********************************/
+ /* */
+ /* InitFiles() */
+ /* */
+ /* Initialize this module. */
+ /* */
+ /*****************************************************************************/
+
+ void InitFiles(void)
+ { int i; OBJECT tmp;
+ for( i = 0; i < MAX_TYPES; i++ ) New(file_type[i], ACAT);
+ for( i = 0; i < MAX_PATHS; i++ ) New(file_path[i], ACAT);
+ file_tab = ftab_new(INIT_TAB);
+ New(empty_path, ACAT);
+ tmp = MakeWord(WORD, STR_EMPTY, no_fpos);
+ Link(empty_path, tmp);
+ } /* end InitFiles */
+
+
+ /*****************************************************************************/
+ /* */
+ /* AddToPath(fpath, dirname) */
+ /* */
+ /* Add the directory dirname to the end of search path fpath. */
+ /* */
+ /*****************************************************************************/
+
+ void AddToPath(int fpath, OBJECT dirname)
+ { Link(file_path[fpath], dirname);
+ } /* end AddToPath */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FILE_NUM DefineFile(str, suffix, xfpos, ftype, fpath) */
+ /* */
+ /* Declare a file whose name is str plus suffix and whose fpos is xfpos. */
+ /* The file type is ftype, and its search path is fpath. */
+ /* */
+ /*****************************************************************************/
+
+ FILE_NUM DefineFile(FULL_CHAR *str, FULL_CHAR *suffix,
+ FILE_POS *xfpos, int ftype, int fpath)
+ { register int i;
+ OBJECT fname;
+ assert( ftype < MAX_TYPES, "DefineFile: ftype!" );
+ debug5(DFS, DD, "DefineFile(%s, %s,%s, %s, %d)",
+ str, suffix, EchoFilePos(xfpos), file_types[ftype], fpath);
+ if( ftype == SOURCE_FILE && (i = StringLength(str)) >= 3 )
+ {
+ /* check that file name does not end in ".li" or ".ld" */
+ if( StringEqual(&str[i-StringLength(DATA_SUFFIX)], DATA_SUFFIX) )
+ Error(3, 3, "database file %s where source file expected",
+ FATAL, xfpos, str);
+ if( StringEqual(&str[i-StringLength(INDEX_SUFFIX)], INDEX_SUFFIX) )
+ Error(3, 4, "database index file %s where source file expected",
+ FATAL, xfpos, str);
+ }
+ if( StringLength(str) + StringLength(suffix) >= MAX_WORD )
+ Error(3, 5, "file name %s%s is too long", FATAL, no_fpos, str, suffix);
+ fname = MakeWordTwo(WORD, str, suffix, xfpos);
+ Link(file_type[ftype], fname);
+ path(fname) = fpath;
+ updated(fname) = FALSE;
+ line_count(fname) = 0;
+ type_of_file(fname) = ftype;
+ used_suffix(fname) = FALSE;
+ ftab_insert(fname, &file_tab);
+ debug1(DFS, DD, "DefineFile returning %s", string(fname));
+ ifdebug(DFS, DD, ftab_debug(file_tab, stderr));
+ return file_number(fname);
+ } /* end DefineFile */
+
+
+ /*@::FirstFile(), NextFile(), FileNum()@**************************************/
+ /* */
+ /* FILE_NUM FirstFile(ftype) */
+ /* */
+ /* Returns first file of type ftype, else NO_FILE. */
+ /* */
+ /*****************************************************************************/
+
+ FILE_NUM FirstFile(int ftype)
+ { FILE_NUM i;
+ OBJECT link, y;
+ debug1(DFS, DD, "FirstFile( %s )", file_types[ftype]);
+ link = Down(file_type[ftype]);
+ if( type(link) == ACAT ) i = NO_FILE;
+ else
+ { Child(y, link);
+ i = file_number(y);
+ }
+ debug1(DFS, DD, "FirstFile returning %s", i==NO_FILE ? STR_NONE : FileName(i));
+ return i;
+ } /* end FirstFile */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FILE_NUM NextFile(i) */
+ /* */
+ /* Returns the next file after file i of the type of i, else NO_FILE. */
+ /* */
+ /*****************************************************************************/
+
+ FILE_NUM NextFile(FILE_NUM i)
+ { OBJECT link, y;
+ debug1(DFS, DD, "NextFile( %s )", FileName(i));
+ link = NextDown(Up(ftab_num(file_tab, i)));
+ if( type(link) == ACAT ) i = NO_FILE;
+ else
+ { Child(y, link);
+ i = file_number(y);
+ }
+ debug1(DFS, DD, "NextFile returning %s", i==NO_FILE ? STR_NONE : FileName(i));
+ return i;
+ } /* end NextFile */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FILE_NUM FileNum(str, suffix) */
+ /* */
+ /* Return the number of the file with name str plus suffix, else NO_FILE. */
+ /* */
+ /*****************************************************************************/
+
+ FILE_NUM FileNum(FULL_CHAR *str, FULL_CHAR *suffix)
+ { register int i; OBJECT fname;
+ FULL_CHAR buff[MAX_BUFF];
+ debug2(DFS, DD, "FileNum(%s, %s)", str, suffix);
+ if( StringLength(str) + StringLength(suffix) >= MAX_BUFF )
+ Error(3, 6, "file name %s%s is too long", FATAL, no_fpos, str, suffix);
+ StringCopy(buff, str);
+ StringCat(buff, suffix);
+ fname = ftab_retrieve(buff, file_tab);
+ i = fname == nilobj ? NO_FILE : file_number(fname);
+ debug1(DFS, DD, "FileNum returning %s",
+ i == NO_FILE ? STR_NONE : FileName( (FILE_NUM) i));
+ return (FILE_NUM) i;
+ } /* end FileNum */
+
+ /*****************************************************************************/
+ /* */
+ /* FILE_NUM DatabaseFileNum(FILE_POS *xfpos) */
+ /* */
+ /* Return a suitable database file number for writing something out whose */
+ /* file position is xfpos. */
+ /* */
+ /*****************************************************************************/
+
+ FILE_NUM DatabaseFileNum(FILE_POS *xfpos)
+ { OBJECT x;
+ FILE_NUM fnum; FULL_CHAR *str;
+ debug2(DFS, D, "DatabaseFileNum(%s %s)", EchoFilePos(xfpos),
+ EchoFileSource(file_num(*xfpos)));
+ x = ftab_num(file_tab, file_num(*xfpos));
+ switch( type_of_file(x) )
+ {
+ case SOURCE_FILE:
+ case INCLUDE_FILE:
+
+ /* return the corresponding database file (may need to be defined) */
+ str = FileName(file_num(*xfpos));
+ fnum = FileNum(str, DATA_SUFFIX);
+ if( fnum == NO_FILE )
+ { debug0(DFS, DD, " calling DefineFile from DatabaseFileNum");
+ fnum = DefineFile(str, DATA_SUFFIX, xfpos, DATABASE_FILE, SOURCE_PATH);
+ }
+ break;
+
+
+ case DATABASE_FILE:
+
+ /* return the enclosing source file (recursively if necessary) */
+ if( file_num(fpos(x)) == NO_FILE )
+ {
+ /* xfpos lies in a cross-reference database file; use itself */
+ /* ***
+ Error(3, 18, "DatabaseFileNum: database file position unknown",
+ INTERN, no_fpos);
+ *** */
+ fnum = file_num(*xfpos);
+ }
+ else
+ {
+ /* xfpos lies in a user-defined database file; use its source */
+ fnum = DatabaseFileNum(&fpos(x));
+ }
+ break;
+
+
+ case FILTER_FILE:
+
+ /* return the enclosing source file (recursively if necessary) */
+ if( file_num(fpos(x)) == NO_FILE )
+ Error(3, 7, "DatabaseFileNum: filter file position unknown",
+ INTERN, no_fpos);
+ fnum = DatabaseFileNum(&fpos(x));
+ break;
+
+
+ default:
+
+ Error(3, 8, "DatabaseFileNum: unexpected file type", INTERN, no_fpos);
+ fnum = NO_FILE;
+ break;
+
+ }
+ debug2(DFS, D, "DatabaseFileNum returning %d (%s)", fnum,
+ fnum == NO_FILE ? AsciiToFull("NO_FILE") : FileName(fnum));
+ return fnum;
+ } /* end DatabaseFileNum */
+
+
+ /*@::FileName(), EchoFilePos(), PosOfFile()@**********************************/
+ /* */
+ /* FULL_CHAR *FileName(fnum) */
+ /* FULL_CHAR *FullFileName(fnum) */
+ /* */
+ /* Return the string name of this file. This is as given to DefineFile */
+ /* until OpenFile is called, after which it is the full path name. */
+ /* */
+ /* FullFileName is the same except it will add a .lt to the file name */
+ /* if that was needed when the file was opened for reading. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *FileName(FILE_NUM fnum)
+ { OBJECT x;
+ x = ftab_num(file_tab, fnum);
+ assert( x != nilobj, "FileName: x == nilobj!" );
+ if( Down(x) != x ) Child(x, Down(x));
+ return string(x);
+ } /* end FileName */
+
+
+ FULL_CHAR *FullFileName(FILE_NUM fnum)
+ { OBJECT x;
+ static FULL_CHAR ffbuff[2][MAX_BUFF];
+ static int ffbp = 1;
+
+ x = ftab_num(file_tab, fnum);
+ assert( x != nilobj, "FileName: x == nilobj!" );
+ if( used_suffix(x) )
+ {
+ if( Down(x) != x ) Child(x, Down(x));
+ ffbp = (ffbp + 1) % 2;
+ StringCopy(ffbuff[ffbp], string(x));
+ StringCat(ffbuff[ffbp], SOURCE_SUFFIX);
+ return ffbuff[ffbp];
+ }
+ else
+ {
+ if( Down(x) != x ) Child(x, Down(x));
+ return string(x);
+ }
+ } /* end FullFileName */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *EchoFilePos(pos) */
+ /* */
+ /* Returns a string reporting the value of file position pos. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR buff[2][MAX_BUFF]; static int bp = 1;
+
+ static void append_fpos(FILE_POS *pos)
+ { OBJECT x;
+ x = ftab_num(file_tab, file_num(*pos));
+ assert( x != nilobj, "EchoFilePos: file_tab entry is nilobj!" );
+ if( file_num(fpos(x)) > 0 )
+ { append_fpos( &fpos(x) );
+ if( StringLength(buff[bp]) + 2 >= MAX_BUFF )
+ Error(3, 9, "file position %s... is too long to print",
+ FATAL, no_fpos, buff[bp]);
+ StringCat(buff[bp], STR_SPACE);
+ StringCat(buff[bp], STR_DIR);
+ }
+ if( StringLength(buff[bp]) + StringLength(string(x)) + 13 >= MAX_BUFF )
+ Error(3, 10, "file position %s... is too long to print",
+ FATAL, no_fpos, buff[bp]);
+ StringCat(buff[bp], STR_SPACE);
+ StringCat(buff[bp], STR_QUOTE);
+ StringCat(buff[bp], string(x));
+ StringCat(buff[bp], STR_QUOTE);
+ if( line_num(*pos) != 0 )
+ { StringCat(buff[bp], STR_SPACE);
+ StringCat(buff[bp], StringInt( (int) line_num(*pos)));
+ StringCat(buff[bp], AsciiToFull(","));
+ StringCat(buff[bp], StringInt( (int) col_num(*pos)));
+ }
+ } /* end append_fpos */
+
+ FULL_CHAR *EchoFilePos(FILE_POS *pos)
+ { bp = (bp + 1) % 2;
+ StringCopy(buff[bp], STR_EMPTY);
+ if( file_num(*pos) > 0 ) append_fpos(pos);
+ return buff[bp];
+ } /* end EchoFilePos */
+
+ FULL_CHAR *EchoAltFilePos(FILE_POS *pos)
+ {
+ bp = (bp + 1) % 2;
+ StringCopy(buff[bp], STR_EMPTY);
+ if( file_num(*pos) > 0 )
+ {
+ /* *** x = ftab_num(file_tab, file_num(*pos)); *** */
+ StringCat(buff[bp], FullFileName(file_num(*pos)));
+ if( line_num(*pos) != 0 )
+ { StringCat(buff[bp], AsciiToFull(":"));
+ StringCat(buff[bp], StringInt( (int) line_num(*pos)));
+ StringCat(buff[bp], AsciiToFull(":"));
+ StringCat(buff[bp], StringInt( (int) col_num(*pos)));
+ }
+ }
+ return buff[bp];
+ } /* end EchoFilePos */
+
+
+ /*@::EchoFileSource(), EchoFileLine(), PosOfFile()@***************************/
+ /* */
+ /* FULL_CHAR *EchoFileSource(fnum) */
+ /* */
+ /* Returns a string reporting the "file source" information for file fnum. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EchoFileSource(FILE_NUM fnum)
+ { OBJECT x, nextx;
+ bp = (bp + 1) % 2;
+ StringCopy(buff[bp], STR_EMPTY);
+ if( fnum > 0 )
+ { StringCat(buff[bp], STR_SPACE);
+ x = ftab_num(file_tab, fnum);
+ assert( x != nilobj, "EchoFileSource: x == nilobj!" );
+ if( type_of_file(x) == FILTER_FILE )
+ { StringCat(buff[bp], AsciiToFull(condcatgets(MsgCat, 3, 11, "filter")));
+ /* for estrip's benefit: Error(3, 11, "filter"); */
+ StringCat(buff[bp], STR_SPACE);
+ }
+ StringCat(buff[bp], AsciiToFull(condcatgets(MsgCat, 3, 12, "file")));
+ /* for estrip's benefit: Error(3, 12, "file"); */
+ StringCat(buff[bp], STR_SPACE);
+ /* *** x = ftab_num(file_tab, fnum); *** */
+ StringCat(buff[bp], STR_QUOTE);
+ StringCat(buff[bp], FullFileName(fnum));
+ StringCat(buff[bp], STR_QUOTE);
+ if( file_num(fpos(x)) > 0 )
+ { StringCat(buff[bp], AsciiToFull(" ("));
+ for(;;)
+ { nextx = ftab_num(file_tab, file_num(fpos(x)));
+ StringCat(buff[bp], AsciiToFull(condcatgets(MsgCat, 3, 13, "from")));
+ /* for estrip's benefit: Error(3, 13, "from"); */
+ StringCat(buff[bp], STR_SPACE);
+ StringCat(buff[bp], STR_QUOTE);
+ StringCat(buff[bp], string(nextx));
+ StringCat(buff[bp], STR_QUOTE);
+ StringCat(buff[bp], STR_SPACE);
+ StringCat(buff[bp], AsciiToFull(condcatgets(MsgCat, 3, 14, "line")));
+ /* for estrip's benefit: Error(3, 14, "line"); */
+ StringCat(buff[bp], STR_SPACE);
+ StringCat(buff[bp], StringInt( (int) line_num(fpos(x))));
+ if( file_num(fpos(nextx)) == 0 ) break;
+ StringCat(buff[bp], AsciiToFull(", "));
+ x = nextx;
+ }
+ StringCat(buff[bp], AsciiToFull(")"));
+ }
+ }
+ return buff[bp];
+ } /* end EchoFileSource */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *EchoFileLine(pos) */
+ /* */
+ /* Returns a string reporting the "line source" information for pos. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EchoFileLine(FILE_POS *pos)
+ { bp = (bp + 1) % 2;
+ StringCopy(buff[bp], STR_EMPTY);
+ if( file_num(*pos) > 0 && line_num(*pos) != 0 )
+ { StringCat(buff[bp], StringInt( (int) line_num(*pos)));
+ StringCat(buff[bp], AsciiToFull(","));
+ StringCat(buff[bp], StringInt( (int) col_num(*pos)));
+ }
+ return buff[bp];
+ } /* end EchoFileLIne */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FILE_POS *PosOfFile(fnum) */
+ /* */
+ /* Returns a pointer to the file position where file fnum was encountered. */
+ /* */
+ /*****************************************************************************/
+
+ FILE_POS *PosOfFile(FILE_NUM fnum)
+ { OBJECT x = ftab_num(file_tab, fnum);
+ assert( x != nilobj, "PosOfFile: file_tab entry is nilobj!" );
+ return &fpos(x);
+ }
+
+ /*@::SearchPath()@************************************************************/
+ /* */
+ /* static FILE *SearchPath(str, fpath, check_ld, check_lt, full_name, xfpos,*/
+ /* read_mode) */
+ /* */
+ /* Search the given path for a file whose name is str. If found, open */
+ /* it with mode read_mode; return the resulting FILE *. */
+ /* */
+ /* If check_ld is TRUE, it means that the file to be opened is a .li file */
+ /* and OpenFile() is required to check whether the corresponding .ld file */
+ /* is present. If it is, then the search must stop. Furthermore, if the */
+ /* .li file is out of date wrt the .ld file, it is to be removed. */
+ /* */
+ /* If check_lt is TRUE, it means that the file to be opened is a source */
+ /* file and OpenFile() is required to check for a .lt suffix version. */
+ /* */
+ /* Also return the full path name in object *full_name if different from */
+ /* the existing name, else nilobj. */
+ /* */
+ /* Set *used_source_suffix to TRUE if the .lt source suffix had to be */
+ /* added in order to find the file. */
+ /* */
+ /*****************************************************************************/
+
+ static FILE *SearchPath(FULL_CHAR *str, OBJECT fpath, BOOLEAN check_ld,
+ BOOLEAN check_lt, OBJECT *full_name, FILE_POS *xfpos, char *read_mode,
+ BOOLEAN *used_source_suffix)
+ { FULL_CHAR buff[MAX_BUFF], buff2[MAX_BUFF];
+ OBJECT link, y, cpath; FILE *fp, *fp2;
+ debug4(DFS, DD, "[ SearchPath(%s, %s, %s, %s, -)", str, EchoObject(fpath),
+ bool(check_ld), bool(check_lt));
+
+ *used_source_suffix = FALSE;
+
+ /* if file name is "stdin" just return it */
+ if( StringEqual(str, STR_STDIN) )
+ {
+ debug0(DFS, DD, "] SearchPath returning stdin");
+ *full_name = nilobj;
+ return stdin;
+ }
+
+ /* use fpath if relative file name, use empty_path if absolute filename */
+ cpath = StringBeginsWith(str, STR_DIR) ? empty_path : fpath;
+
+ /* try opening each path name in the search path */
+ fp = null;
+ for( link = Down(cpath); fp == null && link != cpath; link = NextDown(link) )
+ { Child(y, link);
+
+ /* set buff to the full path name */
+ if( StringLength(string(y)) == 0 )
+ { StringCopy(buff, str);
+ }
+ else
+ { if( StringLength(string(y)) + StringLength(STR_DIR) +
+ StringLength(str) >= MAX_BUFF )
+ Error(3, 15, "file path name %s%s%s is too long",
+ FATAL, &fpos(y), string(y), STR_DIR, str);
+ StringCopy(buff, string(y));
+ StringCat(buff, STR_DIR);
+ StringCat(buff, str);
+ }
+
+ /* try opening the full path name */
+ fp = StringFOpen(buff, read_mode);
+ debug1(DFS, DD, fp == null ? " fail %s" : " succeed %s", buff);
+
+ /* if failed to find .li file, exit if corresponding .ld file */
+ if( check_ld && fp == null )
+ {
+ StringCopy(buff2, buff);
+ StringCopy(&buff2[StringLength(buff2) - StringLength(INDEX_SUFFIX)],
+ DATA_SUFFIX);
+ fp2 = StringFOpen(buff2, READ_TEXT);
+ debug1(DFS, DD, fp2 == null ? " fail %s" : " succeed %s", buff2);
+ if( fp2 != null )
+ { fclose(fp2);
+ debug0(DFS, DD, "] SearchPath returning null (adjacent .ld file)");
+ *full_name = nilobj;
+ return null;
+ }
+ }
+
+ #if USE_STAT
+ /*****************************************************************/
+ /* */
+ /* If your compiler won't compile this bit, it is probably */
+ /* because you either don't have the stat() system call on */
+ /* your system (it is not ANSI C), or because it can't be */
+ /* found in the header files declared at the top of this file. */
+ /* */
+ /* The simple correct thing to do is to set the USESTAT macro */
+ /* in the makefile to 0. You won't lose much. */
+ /* */
+ /*****************************************************************/
+
+ /* if found .li file, compare dates with corresponding .ld file */
+ if( check_ld && fp != null )
+ {
+ struct stat indexstat, datastat;
+ StringCopy(buff2, buff);
+ StringCopy(&buff2[StringLength(buff2) - StringLength(INDEX_SUFFIX)],
+ DATA_SUFFIX);
+ debug2(DFS, DD, "SearchPath comparing dates of .li %s and .ld %s",
+ buff, buff2);
+ if( stat( (char *) buff, &indexstat) == 0 &&
+ stat( (char *) buff2, &datastat) == 0 )
+ {
+ debug2(DFS, DD, "SearchPath mtimes are .li %d and .ld %d",
+ (int) indexstat.st_mtime, (int) datastat.st_mtime);
+ if( datastat.st_mtime > indexstat.st_mtime )
+ { fclose(fp);
+ debug1(DFS, DD, "SearchPath calling StringRemove(%s)", buff);
+ StringRemove(buff);
+ debug0(DFS, DD, "] SearchPath returning null (.li out of date)");
+ *full_name = nilobj;
+ return null;
+ }
+ }
+ }
+ #endif
+
+ /* if check_lt, see if buff.lt exists as well as or instead of buff */
+ if( check_lt )
+ {
+ StringCopy(buff2, buff);
+ StringCat(buff2, SOURCE_SUFFIX);
+ fp2 = StringFOpen(buff2, READ_TEXT);
+ debug1(DFS, DD, fp2 == null ? " fail %s" : " succeed %s", buff2);
+ if( fp2 != null )
+ { if( fp != null )
+ Error(3, 16, "files %s and %s both exist", FATAL, xfpos,buff,buff2);
+ fp = fp2;
+ *used_source_suffix = TRUE;
+ }
+ }
+
+ }
+ debug1(DFS, DD, "] SearchPath returning (fp %s null)", fp==null ? "==" : "!=");
+ *full_name = (fp == null || StringLength(string(y)) == 0) ? nilobj :
+ MakeWord(WORD, buff, xfpos);
+ return fp;
+ } /* end SearchPath */
+
+
+ /*@::OpenFile(), OpenIncGraphicFile()@****************************************/
+ /* */
+ /* FILE *OpenFile(fnum, check_ld, check_lt) */
+ /* */
+ /* Open for reading the file whose number is fnum. This involves */
+ /* searching for it along its path if not previously opened. */
+ /* */
+ /* If check_ld is TRUE, it means that the file to be opened is a .li file */
+ /* and OpenFile() is required to check whether the corresponding .ld file */
+ /* is present. If it is, then the search must stop. Furthermore, if the */
+ /* .li file is out of date wrt the .ld file, it is to be removed. */
+ /* */
+ /* If check_lt is TRUE, it means that the file to be opened is a source */
+ /* file and OpenFile() is required to check for a .lt suffix version */
+ /* if the file does not open without it. */
+ /* */
+ /*****************************************************************************/
+
+ FILE *OpenFile(FILE_NUM fnum, BOOLEAN check_ld, BOOLEAN check_lt)
+ { FILE *fp; OBJECT fname, full_name, y; BOOLEAN used_source_suffix;
+ ifdebug(DPP, D, ProfileOn("OpenFile"));
+ debug2(DFS, DD, "[ OpenFile(%s, %s)", FileName(fnum), bool(check_ld));
+ fname = ftab_num(file_tab, fnum);
+ if( Down(fname) != fname )
+ { Child(y, Down(fname));
+ fp = StringFOpen(string(y), file_mode[type_of_file(fname)]);
+ debug1(DFS,DD,fp==null ? " failed on %s" : " succeeded on %s", string(y));
+ }
+ else
+ { fp = SearchPath(string(fname), file_path[path(fname)], check_ld,
+ check_lt, &full_name, &fpos(fname), file_mode[type_of_file(fname)],
+ &used_source_suffix);
+ if( full_name != nilobj ) Link(fname, full_name);
+ used_suffix(fname) = used_source_suffix;
+ }
+ ifdebug(DPP, D, ProfileOff("OpenFile"));
+ debug1(DFS, DD, "] OpenFile returning (fp %s null)", fp==null ? "==" : "!=");
+ return fp;
+ } /* end OpenFile */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FILE *OpenIncGraphicFile(str, typ, full_name, xfpos, compressed) */
+ /* */
+ /* Open for reading the @IncludeGraphic file str; typ is INCGRAPHIC or */
+ /* SINCGRAPHIC. Return the full name in full_name. Set compressed to */
+ /* TRUE if the file was a compressed file. */
+ /* */
+ /*****************************************************************************/
+ #define MAX_COMPRESSED 6
+ static char *compress_suffixes[MAX_COMPRESSED]
+ = { ".gz", "-gz", ".z", "-z", "_z", ".Z" };
+
+ FILE *OpenIncGraphicFile(FULL_CHAR *str, unsigned char typ,
+ OBJECT *full_name, FILE_POS *xfpos, BOOLEAN *compressed)
+ { FILE *fp; int p, i; BOOLEAN used_source_suffix;
+ debug2(DFS, DD, "OpenIncGraphicFile(%s, %s, -)", str, Image(typ));
+ assert( typ == INCGRAPHIC || typ == SINCGRAPHIC, "OpenIncGraphicFile!" );
+ p = (typ == INCGRAPHIC ? INCLUDE_PATH : SYSINCLUDE_PATH);
+ fp = SearchPath(str, file_path[p], FALSE, FALSE, full_name, xfpos,
+ READ_TEXT, &used_source_suffix);
+ if( *full_name == nilobj ) *full_name = MakeWord(WORD, str, xfpos);
+
+ if( fp == null )
+ {
+ /* if file didn't open, nothing more to do */
+ *compressed = FALSE;
+ fp = null;
+ }
+ else
+ {
+ /* if file is compressed, uncompress it into file LOUT_EPS */
+ for( i = 0; i < MAX_COMPRESSED; i++ )
+ { if( StringEndsWith(string(*full_name), AsciiToFull(compress_suffixes[i])) )
+ break;
+ }
+ if( i < MAX_COMPRESSED )
+ { char buff[MAX_BUFF];
+ fclose(fp);
+ sprintf(buff, UNCOMPRESS_COM, (char *) string(*full_name), LOUT_EPS);
+ if( SafeExecution )
+ {
+ Error(3, 17, "safe execution prohibiting command: %s", WARN, xfpos,buff);
+ *compressed = FALSE;
+ fp = null;
+ }
+ else
+ {
+ system(buff);
+ fp = fopen(LOUT_EPS, READ_TEXT);
+ *compressed = TRUE;
+ }
+ }
+ else *compressed = FALSE;
+ }
+
+ debug2(DFS, DD, "OpenIncGraphicFile returning (fp %s null, *full_name = %s)",
+ fp==null ? "==" : "!=", string(*full_name));
+ return fp;
+ } /* end OpenIncGraphicFile */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FileSetUpdated(fnum, newlines) */
+ /* */
+ /* Declare that file fnum has been updated, and that it now contains */
+ /* newlines lines. */
+ /* */
+ /*****************************************************************************/
+
+ void FileSetUpdated(FILE_NUM fnum, int newlines)
+ {
+ debug2(DFS, DD, "FileSetUpdated(%s, %d)", FileName(fnum), newlines);
+ updated(ftab_num(file_tab, fnum)) = TRUE;
+ line_count(ftab_num(file_tab, fnum)) = newlines;
+ debug0(DFS, DD, "FileSetUpdated returning");
+ } /* end FileSetUpdated */
+
+
+ /*****************************************************************************/
+ /* */
+ /* int FileGetLineCount(FILE_NUM fnum) */
+ /* */
+ /* Return the number of lines so far written to file fnum. */
+ /* */
+ /*****************************************************************************/
+
+ int FileGetLineCount(FILE_NUM fnum)
+ { int res;
+ debug1(DFS, DD, "FileGetLineCount(%s)", FileName(fnum));
+ res = line_count(ftab_num(file_tab, fnum));
+ debug1(DFS, DD, "FileGetLineCount returning %d", res);
+ return res;
+ } /* end FileGetLineCount */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN FileTestUpdated(fnum) */
+ /* */
+ /* Test whether file fnum has been declared to be updated. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN FileTestUpdated(FILE_NUM fnum)
+ { return (BOOLEAN) updated(ftab_num(file_tab, fnum));
+ } /* end FileTestUpdated */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z04.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z04.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z04.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,242 ----
+ /*@z04.c:Token Service:NewToken(), CopyTokenList()@***************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z04.c */
+ /* MODULE: Token Service */
+ /* EXTERNS: NewToken(), CopyTokenList(), EchoCatOp(), EchoToken() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT NewToken(xtype, xfpos, xvspace, xhspace, xprec, xactual) */
+ /* */
+ /* Returns a new non-WORD token initialised as the parameters indicate. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT NewToken(unsigned char xtype, FILE_POS *xfpos, unsigned char xvspace,
+ unsigned char xhspace, unsigned char xprec, OBJECT xactual)
+ { OBJECT res;
+ debug1(DTS, DDD, "NewToken(%s, ...)", Image(xtype));
+ New(res, xtype); FposCopy(fpos(res), *xfpos);
+ vspace(res) = xvspace; hspace(res) = xhspace;
+ precedence(res) = xprec; actual(res) = xactual;
+ debug1(DTS, DDD, "NewToken returning %s", EchoToken(res));
+ return res;
+ } /* end NewToken */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT CopyTokenList(x, pos) */
+ /* */
+ /* Returns a copy of the list of tokens pointed to by x. */
+ /* All file positions in the copy are set to *pos. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT CopyTokenList(OBJECT x, FILE_POS *pos)
+ { OBJECT y, z, res;
+ res = nilobj; y = x;
+ if( x != nilobj ) do
+ { if( is_word(type(y)) )
+ { z = MakeWord(type(y), string(y), pos);
+ vspace(z) = vspace(y); hspace(z) = hspace(y);
+ }
+ else z = NewToken(type(y), pos,vspace(y),hspace(y),precedence(y),actual(y));
+ res = Append(res, z, PARENT);
+ y = succ(y, PARENT);
+ } while( y != x );
+ return res;
+ } /* end CopyTokenList */
+
+ /*@::EchoCatOp(), EchoToken()@************************************************/
+ /* */
+ /* FULL_CHAR *EchoCatOp(xtype, xmark, xjoin) */
+ /* */
+ /* Return the catenation operator with this type, mark and join. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EchoCatOp(unsigned xtype, BOOLEAN xmark, BOOLEAN xjoin)
+ { switch( xtype )
+ {
+ case VCAT: return (xmark ? xjoin ? KW_VCAT_MJ : KW_VCAT_MN
+ : xjoin ? KW_VCAT_NJ : KW_VCAT_NN);
+
+ case HCAT: return (xmark ? xjoin ? KW_HCAT_MJ : KW_HCAT_MN
+ : xjoin ? KW_HCAT_NJ : KW_HCAT_NN);
+
+ case ACAT: return (xmark ? xjoin ? KW_ACAT_MJ : AsciiToFull("??")
+ : xjoin ? KW_ACAT_NJ : AsciiToFull("??") );
+
+ default: assert(FALSE, "EchoCatOp");
+ return STR_EMPTY;
+
+ } /* end switch */
+ } /* end EchoCatOp */
+
+
+ #if DEBUG_ON
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *EchoToken(x) */
+ /* */
+ /* Return an image of token x. Do not worry about preceding space. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EchoToken(OBJECT x)
+ { switch( type(x) )
+ {
+ case WORD:
+
+ return string(x);
+
+
+ case QWORD:
+
+ return StringQuotedWord(x);
+
+
+ case TSPACE:
+ case TJUXTA:
+ case USE:
+ case NOT_REVEALED:
+ case GSTUB_EXT:
+ case GSTUB_INT:
+ case GSTUB_NONE:
+
+ return Image(type(x));
+
+
+ case UNEXPECTED_EOF:
+ case BEGIN:
+ case END:
+ case ENV:
+ case ENVA:
+ case ENVB:
+ case ENVC:
+ case ENVD:
+ case CENV:
+ case CLOS:
+ case LBR:
+ case RBR:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case CROSS:
+ case FORCE_CROSS:
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case SCALE:
+ case KERN_SHRINK:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+ case ROTATE:
+ case BACKGROUND:
+ case VERBATIM:
+ case RAW_VERBATIM:
+ case CASE:
+ case YIELD:
+ case BACKEND:
+ case XCHAR:
+ case FONT:
+ case SPACE:
+ case YUNIT:
+ case ZUNIT:
+ case BREAK:
+ case UNDERLINE:
+ case COLOUR:
+ case OUTLINE:
+ case LANGUAGE:
+ case CURR_LANG:
+ case CURR_FAMILY:
+ case CURR_FACE:
+ case CURR_YUNIT:
+ case CURR_ZUNIT:
+ case COMMON:
+ case RUMP:
+ case MELD:
+ case INSERT:
+ case ONE_OF:
+ case NEXT:
+ case PLUS:
+ case MINUS:
+ case OPEN:
+ case TAGGED:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case ACAT:
+ case HCAT:
+ case VCAT:
+ case CLOSURE:
+ case PREPEND:
+ case SYS_PREPEND:
+ case DATABASE:
+ case SYS_DATABASE:
+ case LUSE:
+ case LEO:
+ case LVIS:
+
+ return actual(x) != nilobj ? SymName(actual(x)) : Image(type(x));
+
+
+ default:
+
+ assert1(FALSE, "EchoToken:", Image(type(x)));
+ return STR_EMPTY;
+ }
+ } /* end EchoToken */
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z05.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z05.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z05.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,834 ----
+ /*@z05.c:Read Definitions:ReadLangDef()@**************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z05.c */
+ /* MODULE: Read Definitions */
+ /* EXTERNS: ReadPrependDef(), ReadDatabaseDef(), ReadDefinitions() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* is_string(t, str) */
+ /* */
+ /* If t is a token denoting unquoted word str, return TRUE. */
+ /* */
+ /*****************************************************************************/
+
+ #define is_string(t, str) (type(t) == WORD && StringEqual(string(t), str) )
+
+
+ /*****************************************************************************/
+ /* */
+ /* static ReadLangDef(encl) */
+ /* */
+ /* Read one language definition and pass it on to the language module. The */
+ /* syntax is langdef <name> ... <name> { <object> } */
+ /* */
+ /*****************************************************************************/
+
+ static void ReadLangDef(OBJECT encl)
+ { OBJECT t, names, inside;
+
+ New(names, ACAT);
+ t = LexGetToken();
+ while( is_word(type(t)) )
+ { Link(names, t);
+ t = LexGetToken();
+ }
+ if( type(t) != LBR )
+ { Error(5, 4, "expected opening %s of langdef here", WARN, &fpos(t), KW_LBR);
+ Dispose(t);
+ return;
+ }
+ inside = Parse(&t, encl, FALSE, FALSE);
+ inside = ReplaceWithTidy(inside, FALSE);
+ LanguageDefine(names, inside);
+ return;
+ } /* end ReadLangDef */
+
+
+ /*@::ReadPrependDef(), ReadDatabaseDef()@*************************************/
+ /* */
+ /* ReadPrependDef(typ, encl) */
+ /* */
+ /* Read @Prepend { <filename> } and record its presence. */
+ /* */
+ /*****************************************************************************/
+
+ void ReadPrependDef(unsigned typ, OBJECT encl)
+ { OBJECT t, fname;
+ t = LexGetToken();
+ if( type(t) != LBR )
+ { Error(5, 5, "left brace expected here in %s declaration",
+ WARN, &fpos(t), KW_PREPEND);
+ Dispose(t);
+ return;
+ }
+ fname = Parse(&t, encl, FALSE, FALSE);
+ fname = ReplaceWithTidy(fname, FALSE);
+ if( !is_word(type(fname)) )
+ { Error(5, 6, "name of %s file expected here", WARN, &fpos(fname),KW_PREPEND);
+ DisposeObject(fname);
+ return;
+ }
+ debug0(DFS, D, " calling DefineFile from ReadPrependDef");
+ DefineFile(string(fname), STR_EMPTY, &fpos(fname), PREPEND_FILE,
+ typ == PREPEND ? INCLUDE_PATH : SYSINCLUDE_PATH);
+
+ } /* end ReadPrependDef */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ReadDatabaseDef(typ, encl) */
+ /* */
+ /* Read @Database <symname> ... <symname> { <filename> } and record it. */
+ /* */
+ /*****************************************************************************/
+
+ void ReadDatabaseDef(unsigned typ, OBJECT encl)
+ { OBJECT symbs, t, fname;
+ New(symbs, ACAT);
+ t = LexGetToken();
+ while( type(t)==CLOSURE || (type(t)==WORD && string(t)[0]==CH_SYMSTART) )
+ { if( type(t) == CLOSURE )
+ { Link(symbs, t);
+ }
+ else
+ { Error(5, 7, "unknown or misspelt symbol %s", WARN, &fpos(t), string(t));
+ Dispose(t);
+ }
+ t = LexGetToken();
+ }
+ if( type(t) != LBR )
+ { Error(5, 8, "symbol name or %s expected here (%s declaration)",
+ WARN, &fpos(t), KW_LBR, KW_DATABASE);
+ Dispose(t);
+ return;
+ }
+ if( Down(symbs) == symbs )
+ { Error(5, 9, "symbol names missing in %s declaration",
+ WARN, &fpos(t), KW_DATABASE);
+ }
+ fname = Parse(&t, encl, FALSE, FALSE);
+ fname = ReplaceWithTidy(fname, FALSE);
+ if( !is_word(type(fname)) )
+ { Error(5, 10, "name of %s file expected here", WARN, &fpos(fname),
+ KW_DATABASE);
+ DisposeObject(fname);
+ return;
+ }
+ if( StringEndsWith(string(fname), DATA_SUFFIX) )
+ { Error(5, 47, "%s suffix should be omitted in %s clause", WARN,
+ &fpos(fname), DATA_SUFFIX, KW_DATABASE);
+ DisposeObject(fname);
+ return;
+ }
+ if( Down(symbs) != symbs )
+ (void) DbLoad(fname, typ == DATABASE ? DATABASE_PATH : SYSDATABASE_PATH,
+ TRUE, symbs, InMemoryDbIndexes);
+ } /* end ReadDatabaseDef */
+
+
+ /*@::ReadTokenList()@*********************************************************/
+ /* */
+ /* static ReadTokenList(token, res) */
+ /* */
+ /* Read a list of tokens from input and append them to sym_body(res). */
+ /* The list is assumed to begin immediately after token, which is either */
+ /* an LBR or a @Begin, and input is to be read up to and including the */
+ /* matching RBR or @End @Sym. */
+ /* */
+ /*****************************************************************************/
+ #define NextToken(t, res) \
+ t = LexGetToken(); sym_body(res) = Append(sym_body(res), t, PARENT);
+
+ static void ReadTokenList(OBJECT token, OBJECT res)
+ { OBJECT t, xsym, new_par, imps, link, y; int scope_count, i;
+ NextToken(t, res);
+ for(;;) switch(type(t))
+ {
+ case WORD:
+
+ if( string(t)[0] == CH_SYMSTART )
+ Error(5, 11, "symbol %s unknown or misspelt", WARN, &fpos(t),
+ string(t));
+ NextToken(t, res);
+ break;
+
+
+ case QWORD:
+
+ NextToken(t, res);
+ break;
+
+
+ case VCAT:
+ case HCAT:
+ case ACAT:
+ case CROSS:
+ case FORCE_CROSS:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case SCALE:
+ case KERN_SHRINK:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+ case ROTATE:
+ case BACKGROUND:
+ case RAW_VERBATIM:
+ case VERBATIM:
+ case CASE:
+ case YIELD:
+ case BACKEND:
+ case XCHAR:
+ case FONT:
+ case SPACE:
+ case YUNIT:
+ case ZUNIT:
+ case BREAK:
+ case UNDERLINE:
+ case COLOUR:
+ case OUTLINE:
+ case LANGUAGE:
+ case CURR_LANG:
+ case CURR_FAMILY:
+ case CURR_FACE:
+ case CURR_YUNIT:
+ case CURR_ZUNIT:
+ case COMMON:
+ case RUMP:
+ case MELD:
+ case INSERT:
+ case ONE_OF:
+ case NEXT:
+ case PLUS:
+ case MINUS:
+ case TAGGED:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case NOT_REVEALED:
+
+ NextToken(t, res);
+ break;
+
+
+ case LUSE:
+ case LVIS:
+ case ENV:
+ case USE:
+ case DATABASE:
+ case SYS_DATABASE:
+ case PREPEND:
+ case SYS_PREPEND:
+ case OPEN:
+
+ Error(5, 12, "symbol %s not allowed in macro", WARN, &fpos(t),
+ SymName(actual(t)));
+ NextToken(t, res);
+ break;
+
+
+ case LBR:
+
+ ReadTokenList(t, res);
+ NextToken(t, res);
+ break;
+
+
+ case UNEXPECTED_EOF:
+
+ Error(5, 13, "unexpected end of input", FATAL, &fpos(t));
+ break;
+
+
+ case BEGIN:
+
+ Error(5, 14, "%s not expected here", WARN, &fpos(t), SymName(actual(t)));
+ NextToken(t, res);
+ break;
+
+
+ case RBR:
+
+ if( type(token) != LBR )
+ Error(5, 15, "unmatched %s in macro", WARN, &fpos(t), KW_RBR);
+ return;
+
+
+ case END:
+
+ if( type(token) != BEGIN )
+ Error(5, 16, "unmatched %s in macro", WARN, &fpos(t), KW_END);
+ else
+ { NextToken(t, res);
+ if( type(t) != CLOSURE )
+ {
+ if( type(t) == WORD && string(t)[0] == CH_SYMSTART )
+ Error(5, 17, "symbol %s unknown or misspelt",
+ WARN, &fpos(t), string(t));
+ else
+ Error(5, 18, "symbol name expected after %s", WARN,&fpos(t),KW_END);
+ }
+ else if( actual(token) != actual(t) )
+ Error(5, 19, "%s %s does not match %s %s", WARN, &fpos(t),
+ SymName(actual(token)), KW_BEGIN, SymName(actual(t)), KW_END);
+ }
+ return;
+
+
+ case CLOSURE:
+
+ xsym = actual(t);
+ PushScope(xsym, TRUE, FALSE);
+ NextToken(t, res);
+ PopScope();
+ if( type(t) == CROSS || type(t) == FORCE_CROSS )
+ { NextToken(t, res);
+ break;
+ }
+
+ /* read named parameters */
+ while( type(t) == CLOSURE && enclosing(actual(t)) == xsym &&
+ type(actual(t)) == NPAR )
+ { new_par = t;
+ NextToken(t, res);
+ if( type(t) != LBR )
+ { if( type(t) == RBR )
+ { if( type(token) != LBR )
+ Error(5, 20, "unmatched %s in macro", WARN, &fpos(t), KW_RBR);
+ return;
+ }
+ Error(5, 21, "%s must follow named parameter %s",
+ WARN, &fpos(new_par), KW_LBR, SymName(actual(new_par)));
+ break;
+ }
+
+ /* add import list of the named parameter to current scope */
+ scope_count = 0;
+ imps = imports(actual(new_par));
+ if( imps != nilobj )
+ { for( link = Down(imps); link != imps; link = NextDown(link) )
+ { Child(y, link);
+ PushScope(actual(y), FALSE, TRUE);
+ scope_count++;
+ }
+ }
+
+ /* read the body of the named parameter */
+ PushScope(actual(new_par), FALSE, FALSE);
+ ReadTokenList(t, res);
+ PopScope();
+
+ /* pop the scopes pushed for the import list */
+ for( i = 0; i < scope_count; i++ )
+ PopScope();
+
+ /* get next token, possibly another named parameter */
+ PushScope(xsym, TRUE, FALSE);
+ NextToken(t, res);
+ PopScope();
+ }
+
+ /* read body parameter, if any */
+ if( has_body(xsym) )
+ {
+ if( type(t) == LBR || type(t) == BEGIN )
+ { PushScope(xsym, FALSE, TRUE);
+ PushScope(ChildSym(xsym, RPAR), FALSE, FALSE);
+ if( type(t) == BEGIN ) actual(t) = xsym;
+ ReadTokenList(t, res);
+ PopScope();
+ PopScope();
+ NextToken(t, res);
+ }
+ else if( type(t) != RBR && type(t) != END )
+ Error(5, 22, "right parameter of %s must begin with %s",
+ WARN, &fpos(t), SymName(xsym), KW_LBR);
+ }
+ break;
+
+
+ default:
+
+ Error(5, 23, "ReadTokenList: %s", INTERN, &fpos(t), Image(type(t)));
+ break;
+
+ }
+ } /* end ReadTokenList */
+
+
+ /*@::ReadMacro()@*************************************************************/
+ /* */
+ /* static OBJECT ReadMacro(token, encl) */
+ /* */
+ /* Read a macro from input and insert into symbol table. */
+ /* Token *token contains the "macro" keyword. Input is read up to and */
+ /* including the closing right brace, and nilobj returned in *token if OK. */
+ /* The proper scope for reading the macro body is open at entry and exit. */
+ /* ReadMacro returns the new symbol table entry if successful, else nilobj. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT ReadMacro(OBJECT *token, OBJECT curr_encl, OBJECT encl)
+ { OBJECT t, res;
+
+ /* find macro name and insert into symbol table */
+ SuppressScope();
+ Dispose(*token); t = LexGetToken();
+ if( !is_word(type(t)) )
+ { Error(5, 24, "%s ignored (name is missing)", WARN, &fpos(t), KW_MACRO);
+ debug1(ANY, D, "offending type is %s", Image(type(t)));
+ UnSuppressScope();
+ *token = t;
+ return nilobj;
+ }
+ res = InsertSym(string(t), MACRO, &fpos(t), 0, FALSE,TRUE,0,curr_encl,nilobj);
+ if( curr_encl != encl ) visible(res) = TRUE;
+ UnSuppressScope();
+
+ /* find alternative names for this symbol */
+ Dispose(t); t = LexGetToken();
+ while( is_word(type(t)) )
+ {
+ InsertAlternativeName(string(t), res, &fpos(t));
+ Dispose(t); t = LexGetToken();
+ }
+
+ /* find opening left brace */
+ if( type(t) != LBR )
+ { Error(5, 25, "%s ignored (opening %s is missing)",
+ WARN, &fpos(t), KW_MACRO, KW_LBR);
+ *token = t;
+ return nilobj;
+ }
+
+ /* read macro body */
+ ReadTokenList(t, res);
+ Dispose(t);
+
+ /* clean up (kill final RBR, dispose macro name) and exit */
+ t = pred(sym_body(res), PARENT);
+ sym_body(res) = Delete(t, PARENT);
+ Dispose(t);
+ recursive(res) = FALSE;
+ *token = nilobj;
+ return res;
+ } /* end ReadMacro */
+
+
+ /*@::ReadDefinitions()@*******************************************************/
+ /* */
+ /* ReadDefinitions(token, encl, res_type) */
+ /* */
+ /* Read a sequence of definitions and insert them into the symbol table. */
+ /* Either a sequence of local definitions (res_type == LOCAL) or named */
+ /* parameters (res_type == NPAR) is expected; *token is the first def etc. */
+ /* A scope appropriate for reading the bodies of the definitions is open. */
+ /* The parent definition is encl. */
+ /* */
+ /*****************************************************************************/
+
+ void ReadDefinitions(OBJECT *token, OBJECT encl, unsigned char res_type)
+ { OBJECT t, res, res_target, export_list, import_list, link, y, z;
+ OBJECT curr_encl; BOOLEAN compulsory_par, has_import_encl;
+ t = *token;
+
+ while( res_type==LOCAL || is_string(t, KW_NAMED) || is_string(t, KW_IMPORT) )
+ {
+ curr_encl = encl;
+
+ if( is_string(t, KW_LANGDEF) )
+ { ReadLangDef(encl);
+ t = LexGetToken();
+ continue; /* next definition */
+ }
+ else if( type(t) == PREPEND || type(t) == SYS_PREPEND )
+ { ReadPrependDef(type(t), encl);
+ Dispose(t);
+ t = LexGetToken();
+ continue; /* next definition */
+ }
+ else if( type(t) == DATABASE || type(t) == SYS_DATABASE )
+ { ReadDatabaseDef(type(t), encl);
+ Dispose(t);
+ t = LexGetToken();
+ continue; /* next definition */
+ }
+
+ if( !is_string(t, KW_DEF) && !is_string(t, KW_MACRO) &&
+ !is_string(t, KW_NAMED) && !is_string(t, KW_IMPORT) &&
+ !is_string(t, KW_EXTEND) && !is_string(t, KW_EXPORT) )
+ break;
+
+ /* get import or extend list and change scope appropriately */
+ BodyParNotAllowed();
+ New(import_list, ACAT);
+ has_import_encl = FALSE;
+ if( is_string(t, KW_IMPORT) )
+ { Dispose(t);
+ t = LexGetToken();
+ while( type(t) == CLOSURE ||
+ (type(t)==WORD && !is_string(t,KW_EXPORT) && !is_string(t,KW_DEF)
+ && !is_string(t, KW_MACRO) && !is_string(t, KW_NAMED)) )
+ { if( type(t) == CLOSURE )
+ { if( type(actual(t)) == LOCAL )
+ {
+ /* *** letting this through now
+ if( res_type == NPAR && has_par(actual(t)) )
+ {
+ Error(5, 46, "named parameter import %s has parameters",
+ WARN, &fpos(t), SymName(actual(t)));
+ }
+ else
+ {
+ *** */
+ PushScope(actual(t), FALSE, TRUE);
+ if( actual(t) == encl ) has_import_encl = TRUE;
+ Link(import_list, t);
+ /* ***
+ }
+ *** */
+ }
+ else
+ { Error(5, 26, "import name expected here", WARN, &fpos(t));
+ Dispose(t);
+ }
+ }
+ else
+ { Error(5, 27, "import %s not in scope", WARN, &fpos(t), string(t));
+ Dispose(t);
+ }
+ t = LexGetToken();
+ }
+ }
+ else if( is_string(t, KW_EXTEND) )
+ { Dispose(t);
+ t = LexGetToken();
+ while( type(t) == CLOSURE ||
+ (type(t)==WORD && !is_string(t,KW_EXPORT) && !is_string(t,KW_DEF)
+ && !is_string(t, KW_MACRO)) )
+ { if( type(t) == CLOSURE )
+ { if( imports(actual(t)) != nilobj )
+ { Error(5, 48, "%s has %s clause, so cannot be extended",
+ WARN, &fpos(t), SymName(actual(t)), KW_IMPORT);
+ }
+ else if( type(actual(t)) == LOCAL )
+ { PushScope(actual(t), FALSE, FALSE);
+ curr_encl = actual(t);
+ debug1(DRD, D, " curr_encl = %s", SymName(curr_encl));
+ Link(import_list, t);
+ }
+ else
+ { Error(5, 28, "%s symbol name expected here",
+ WARN, &fpos(t), KW_EXTEND);
+ Dispose(t);
+ }
+ }
+ else
+ { Error(5, 29, "extend symbol %s not in scope", WARN,&fpos(t),string(t));
+ Dispose(t);
+ }
+ t = LexGetToken();
+ }
+ }
+
+ /* get export list and store for setting visible flags below */
+ New(export_list, ACAT);
+ if( is_string(t, KW_EXPORT) )
+ { Dispose(t);
+ SuppressScope();
+ t = LexGetToken();
+ while( is_word(type(t)) && !is_string(t, KW_DEF) && !is_string(t, KW_IMPORT)
+ && !is_string(t, KW_MACRO) && !is_string(t, KW_EXTEND) )
+ { Link(export_list, t);
+ t = LexGetToken();
+ }
+ UnSuppressScope();
+ }
+
+
+ if( res_type == LOCAL && !is_string(t, KW_DEF) && !is_string(t, KW_MACRO) )
+ { Error(5, 30, "keyword %s or %s expected here", WARN, &fpos(t),
+ KW_DEF, KW_MACRO);
+ break;
+ }
+ if( res_type == NPAR && !is_string(t, KW_NAMED) )
+ { Error(5, 31, "keyword %s expected here", WARN, &fpos(t), KW_NAMED);
+ break;
+ }
+
+ if( is_string(t, KW_MACRO) )
+ { if( Down(export_list) != export_list )
+ Error(5, 32, "ignoring export list of macro", WARN, &fpos(t));
+ res = ReadMacro(&t, curr_encl, encl);
+ }
+ else
+ {
+ SuppressScope(); Dispose(t); t = LexGetToken();
+
+ /* check for compulsory keyword */
+ if( res_type == NPAR && is_string(t, KW_COMPULSORY) )
+ { compulsory_par = TRUE;
+ Dispose(t); t = LexGetToken();
+ }
+ else compulsory_par = FALSE;
+
+ /* find name of symbol and insert it */
+ if( !is_word(type(t)) )
+ { Error(5, 33, "symbol name expected here", WARN, &fpos(t));
+ debug1(ANY, D, "offending type is %s", Image(type(t)));
+ UnSuppressScope();
+ *token = t;
+ return;
+ }
+ res = InsertSym(string(t), res_type, &fpos(t), DEFAULT_PREC,
+ FALSE, FALSE, 0, curr_encl, nilobj);
+ if( curr_encl != encl ) visible(res) = TRUE;
+ if( has_import_encl )
+ {
+ imports_encl(res) = TRUE;
+ debug1(DCE, D, " setting import_encl(%s) to TRUE", SymName(res));
+ }
+ if( compulsory_par )
+ { has_compulsory(encl)++;
+ is_compulsory(res) = TRUE;
+ }
+ Dispose(t); t = LexGetToken();
+
+ /* find alternative names for this symbol */
+ while( is_word(type(t)) && !is_string(t, KW_NAMED) &&
+ !is_string(t, KW_IMPORT) &&
+ !is_string(t, KW_FORCE) && !is_string(t, KW_INTO) &&
+ !is_string(t, KW_HORIZ) && !is_string(t, KW_PRECEDENCE) &&
+ !is_string(t, KW_ASSOC) && !is_string(t, KW_LEFT) &&
+ !is_string(t, KW_RIGHT) && !is_string(t, KW_BODY) &&
+ !is_string(t, KW_LBR) && !is_string(t, KW_BEGIN) )
+ {
+ InsertAlternativeName(string(t), res, &fpos(t));
+ Dispose(t); t = LexGetToken();
+ }
+
+ /* find force, if any */
+ if( is_string(t, KW_FORCE) )
+ { force_target(res) = TRUE;
+ Dispose(t); t = LexGetToken();
+ if( !is_string(t, KW_INTO) && !is_string(t, KW_HORIZ) )
+ Error(5, 34, "%s expected here", WARN, &fpos(t), KW_INTO);
+ }
+
+ /* find horizontally, if any */
+ if( is_string(t, KW_HORIZ) )
+ { horiz_galley(res) = COLM;
+ Dispose(t); t = LexGetToken();
+ /* *** want to allow KW_HORIZ with @Target form now
+ if( !is_string(t, KW_INTO) )
+ Error(5, 35, "%s expected here", WARN, &fpos(t), KW_INTO);
+ *** */
+ }
+
+ /* find into clause, if any */
+ res_target = nilobj;
+ if( is_string(t, KW_INTO) )
+ { UnSuppressScope();
+ Dispose(t); t = LexGetToken();
+ if( type(t) != LBR )
+ { Error(5, 36, "%s expected here", WARN, &fpos(t), KW_LBR);
+ debug1(ANY, D, "offending type is %s", Image(type(t)));
+ UnSuppressScope();
+ *token = t;
+ return;
+ }
+ res_target = Parse(&t, curr_encl, FALSE, FALSE);
+ SuppressScope();
+ if( t == nilobj ) t = LexGetToken();
+ }
+
+ /* find precedence clause, if any */
+ if( is_string(t, KW_PRECEDENCE) )
+ { int prec = 0;
+ Dispose(t);
+ t = LexGetToken();
+ while( type(t) == WORD && decimaldigit(string(t)[0]) )
+ {
+ prec = prec * 10 + digitchartonum(string(t)[0]);
+ Dispose(t); t = LexGetToken();
+ }
+
+ if( prec < MIN_PREC )
+ { Error(5, 37, "precedence is too low (%d substituted)",
+ WARN, &fpos(t), MIN_PREC);
+ prec = MIN_PREC;
+ }
+ else if( prec > MAX_PREC )
+ { Error(5, 38, "precedence is too high (%d substituted)",
+ WARN, &fpos(t), MAX_PREC);
+ prec = MAX_PREC;
+ }
+ precedence(res) = prec;
+ }
+
+ /* find associativity clause, if any */
+ if( is_string(t, KW_ASSOC) )
+ { Dispose(t); t = LexGetToken();
+ if( is_string(t, KW_LEFT) ) right_assoc(res) = FALSE;
+ else if( !is_string(t, KW_RIGHT) )
+ Error(5, 39, "associativity altered to %s", WARN, &fpos(t), KW_RIGHT);
+ Dispose(t); t = LexGetToken();
+ }
+
+ /* find left parameter, if any */
+ if( is_string(t, KW_LEFT) )
+ { Dispose(t); t = LexGetToken();
+ if( type(t) != WORD )
+ { Error(5, 40, "cannot find %s parameter name", WARN, &fpos(t), KW_LEFT);
+ debug1(ANY, D, "offending type is %s", Image(type(t)));
+ UnSuppressScope();
+ *token = t;
+ return;
+ }
+ InsertSym(string(t), LPAR, &fpos(t), DEFAULT_PREC,
+ FALSE, FALSE, 0, res, nilobj);
+ Dispose(t); t = LexGetToken();
+ }
+
+ /* find named parameters, if any */
+ UnSuppressScope();
+ ReadDefinitions(&t, res, NPAR);
+
+ /* find right or body parameter, if any */
+ if( is_string(t, KW_RIGHT) || is_string(t, KW_BODY) )
+ { has_body(res) = is_string(t, KW_BODY);
+ SuppressScope();
+ Dispose(t); t = LexGetToken();
+ if( type(t) != WORD )
+ { Error(5, 41, "cannot find %s parameter name", WARN,&fpos(t),KW_RIGHT);
+ debug1(ANY, D, "offending type is %s", Image(type(t)));
+ UnSuppressScope();
+ *token = t;
+ return;
+ }
+ InsertSym(string(t), RPAR, &fpos(t), DEFAULT_PREC,
+ FALSE, FALSE, 0, res, nilobj);
+ UnSuppressScope();
+ Dispose(t); t = LexGetToken();
+ }
+
+ /* read local definitions and body */
+ if( res_target != nilobj )
+ InsertSym(KW_TARGET, LOCAL, &fpos(res_target), DEFAULT_PREC,
+ FALSE, FALSE, 0, res, res_target);
+ if( type(t) == WORD && StringEqual(string(t), KW_LBR) )
+ { z = NewToken(LBR, &fpos(t), 0, 0, LBR_PREC, StartSym);
+ Dispose(t);
+ t = z;
+ }
+ else if( type(t) == WORD && StringEqual(string(t), KW_BEGIN) )
+ { z = NewToken(BEGIN, &fpos(t), 0, 0, BEGIN_PREC, StartSym);
+ Dispose(t);
+ t = z;
+ }
+ else if( type(t) != LBR && type(t) != BEGIN )
+ Error(5, 42, "opening left brace or @Begin of %s expected",
+ FATAL, &fpos(t), SymName(res));
+ if( type(t) == BEGIN ) actual(t) = res;
+ PushScope(res, FALSE, FALSE);
+ BodyParAllowed();
+ sym_body(res) = Parse(&t, res, TRUE, FALSE);
+
+ /* set visible flag of the exported symbols */
+ for( link=Down(export_list); link != export_list; link=NextDown(link) )
+ { Child(y, link);
+ z = SearchSym(string(y), StringLength(string(y)));
+ if( z == nilobj || enclosing(z) != res )
+ Error(5, 43, "exported symbol %s is not defined in %s",
+ WARN, &fpos(y), string(y), SymName(res));
+ else if( has_body(res) && type(z) == RPAR )
+ Error(5, 44, "body parameter %s may not be exported",
+ WARN, &fpos(y), string(y));
+ else if( visible(z) )
+ Error(5, 45, "symbol %s exported twice", WARN, &fpos(y), string(y));
+ else visible(z) = TRUE;
+ }
+ DisposeObject(export_list);
+
+ /* pop scope of res */
+ PopScope();
+ }
+
+ /* pop import scopes and store imports in sym tab */
+ for( link=Down(import_list); link != import_list; link=NextDown(link) )
+ {
+ PopScope();
+ }
+ if( Down(import_list) == import_list || curr_encl != encl )
+ { DisposeObject(import_list);
+ import_list = nilobj;
+ }
+ else
+ {
+ imports(res) = import_list;
+ }
+
+ BodyParAllowed();
+ if( t == nilobj ) t = LexGetToken();
+
+ } /* end while */
+
+ *token = t;
+ return;
+ } /* end ReadDefinitions */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z06.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z06.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z06.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1553 ----
+ /*@z06.c:Parser:PushObj(), PushToken(), etc.@*********************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z06.c */
+ /* MODULE: Parser */
+ /* EXTERNS: InitParser(), Parse() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define LEFT_ASSOC 0
+ #define RIGHT_ASSOC 1
+
+ #define PREV_OP 0 /* means an operator was previous */
+ #define PREV_OBJ 1 /* prev was object not ending in RBR */
+ #define PREV_RBR 2 /* prev was object ending in RBR */
+
+ static OBJECT cross_name; /* name of the cr database */
+
+
+ #define MAX_STACK 100 /* size of parser stacks */
+ static OBJECT obj_stack[MAX_STACK]; /* stack of objects */
+ static int otop = -1; /* top of obj_stack */
+ static OBJECT tok_stack[MAX_STACK]; /* stack of tokens */
+ static int ttop = -1; /* top of tok_stack */
+ static int unknown_count = 0; /* no. of unknown symbols */
+ #if DEBUG_ON
+ static BOOLEAN debug_now = FALSE; /* TRUE when want to debug */
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT OptimizeCase(x) */
+ /* */
+ /* Optimize the @Case expression x, which is known to be of the form */
+ /* "@BackEnd @Case ...", by evaluating it immediately if its choices */
+ /* are all literal words or "else". */
+ /* */
+ /*****************************************************************************/
+
+ static void check_yield(OBJECT y, OBJECT *res_yield, BOOLEAN *all_literals)
+ { OBJECT s1, link, z;
+ Child(s1, Down(y));
+ debug1(DOP, DD, " checkyield(%s)", EchoObject(y));
+ if( is_word(type(s1)) )
+ { if( StringEqual(string(s1), BackEnd->name) ||
+ StringEqual(string(s1),STR_ELSE) )
+ if( *res_yield == nilobj ) *res_yield = y;
+ }
+ else if( type(s1) == ACAT )
+ { for( link = Down(s1); link != s1; link = NextDown(link) )
+ { Child(z, link);
+ if( type(z) == GAP_OBJ ) continue;
+ if( is_word(type(z)) )
+ { if( StringEqual(string(z), BackEnd->name) ||
+ StringEqual(string(s1), STR_ELSE))
+ if( *res_yield == nilobj ) *res_yield = y;
+ }
+ else
+ { *all_literals = FALSE;
+ *res_yield = nilobj;
+ break;
+ }
+ }
+ }
+ else
+ { *all_literals = FALSE;
+ *res_yield = nilobj;
+ }
+ debug2(DOP, DD, " checkyield returning (%s, %s)", EchoObject(*res_yield),
+ bool(*all_literals));
+ }
+
+ OBJECT OptimizeCase(OBJECT x)
+ { OBJECT link, s2, y, res_yield, res; BOOLEAN all_literals;
+ debug1(DOP, DD, "OptimizeCase(%s)", EchoObject(x));
+ assert( type(x) == CASE, "OptimizeCase: type(x) != CASE!" );
+
+ Child(s2, LastDown(x));
+ all_literals = TRUE; res_yield = nilobj;
+ if( type(s2) == YIELD )
+ { check_yield(s2, &res_yield, &all_literals);
+ }
+ else if( type(s2) == ACAT )
+ { for( link = Down(s2); link != s2 && all_literals; link = NextDown(link) )
+ {
+ Child(y, link);
+ debug2(DOP, DD, " OptimizeCase examining %s %s", Image(type(y)),
+ EchoObject(y));
+ if( type(y) == GAP_OBJ ) continue;
+ if( type(y) == YIELD )
+ { check_yield(y, &res_yield, &all_literals);
+ }
+ else
+ { all_literals = FALSE;
+ res_yield = nilobj;
+ }
+ }
+ }
+ else
+ { all_literals = FALSE;
+ res_yield = nilobj;
+ }
+
+ if( all_literals && res_yield != nilobj )
+ { Child(res, LastDown(res_yield));
+ DeleteLink(Up(res));
+ DisposeObject(x);
+ }
+ else
+ { res = x;
+ }
+
+ debug1(DOP, DD, "OptimizeCase returning %s", EchoObject(res));
+ return res;
+ } /* end OptimizeCase */
+
+
+ /*****************************************************************************/
+ /* */
+ /* HuntCommandOptions(x) */
+ /* */
+ /* See if any of the command-line options apply to closure x. If so, */
+ /* change x to reflect the overriding command line option. */
+ /* */
+ /*****************************************************************************/
+
+ static void HuntCommandOptions(OBJECT x)
+ { OBJECT colink, coname, coval, opt, y, link, sym; BOOLEAN found;
+ debug1(DOP, DD, "HuntCommandOptions(%s)", SymName(actual(x)));
+ sym = actual(x);
+ for( colink = Down(CommandOptions); colink != CommandOptions;
+ colink = NextDown(NextDown(colink)) )
+ {
+ Child(coname, colink);
+ Child(coval, NextDown(colink));
+ debug2(DOP, DD, " hunting \"%s\" with value \"%s\"", string(coname),
+ EchoObject(coval));
+
+ /* set found to TRUE iff coname is the name of an option of x */
+ found = FALSE;
+ for( link = Down(sym); link != sym; link = NextDown(link) )
+ { Child(opt, link);
+ if( type(opt) == NPAR && StringEqual(SymName(opt), string(coname)) )
+ { found = TRUE;
+ debug2(DOP, DD, " %s is an option of %s", string(coname),SymName(sym));
+ break;
+ }
+ }
+
+ if( found )
+ {
+ /* see whether this option is already set within x */
+ found = FALSE;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == PAR && actual(y) == opt )
+ { found = TRUE;
+ debug2(DOP, DD, " %s is set in %s", string(coname), SymName(sym));
+ break;
+ }
+ }
+
+ if( found )
+ {
+ /* option exists already in x: replace it with oval */
+ DisposeChild(Down(y));
+ Link(y, coval);
+ debug2(DOP, DD, " replacing %s value with %s; x =", string(coname),
+ EchoObject(coval));
+ ifdebug(DOP, DD, DebugObject(x));
+ }
+ else
+ {
+ /* option applies to x but has not yet been set in x */
+ New(y, PAR);
+ Link(x, y);
+ actual(y) = opt;
+ Link(y, coval);
+ debug2(DOP, DD, " inserting %s with value %s; x =", string(coname),
+ EchoObject(coval));
+ ifdebug(DOP, DD, DebugObject(x));
+ }
+ }
+ }
+ debug1(DOP, DD, "HuntCommandOptions(%s) returning", SymName(sym));
+ } /* end HuntCommandOptions */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PushObj(x) */
+ /* PushToken(t) */
+ /* OBJECT PopObj() */
+ /* OBJECT PopToken() */
+ /* OBJECT TokenTop */
+ /* OBJECT ObjTop */
+ /* */
+ /* Push and pop from the object and token stacks; examine top item. */
+ /* */
+ /*****************************************************************************/
+
+ #define PushObj(x) \
+ { zz_hold = x; \
+ if( ++otop < MAX_STACK ) obj_stack[otop] = zz_hold; \
+ else Error(6, 1, "expression is too deeply nested", \
+ FATAL, &fpos(obj_stack[otop-1])); \
+ }
+
+ #define PushToken(t) \
+ { if( ++ttop < MAX_STACK ) tok_stack[ttop] = t; \
+ else Error(6, 2, "expression is too deeply nested", \
+ FATAL, &fpos(tok_stack[ttop-1])); \
+ }
+
+ #define PopObj() obj_stack[otop--]
+ #define PopToken() tok_stack[ttop--]
+ #define TokenTop tok_stack[ttop]
+ #define ObjTop obj_stack[otop]
+
+
+ /*@::DebugStacks(), InsertSpace()@********************************************/
+ /* */
+ /* DebugStacks() */
+ /* */
+ /* Print debug output of the stacks state */
+ /* */
+ /*****************************************************************************/
+
+ #if DEBUG_ON
+ static void DebugStacks(int initial_ttop, int obj_prev)
+ { int i;
+ debug3(ANY, D, " obj_prev: %s; otop: %d; ttop: %d",
+ obj_prev == PREV_OP ? "PREV_OP" : obj_prev == PREV_OBJ ? "PREV_OBJ" :
+ obj_prev == PREV_RBR ? "PREV_RBR" : "???", otop, ttop);
+ for( i = 0; i <= otop; i++ )
+ debug3(ANY, D, " obj[%d] = (%s) %s", i,
+ Image(type(obj_stack[i])), EchoObject(obj_stack[i]));
+ for( i = 0; i <= ttop; i++ )
+ { if( i == initial_ttop+1 ) debug0(DOP, DD, " $");
+ debug3(ANY, D, " tok[%d] = %s (precedence %d)", i,
+ type(tok_stack[i]) == CLOSURE ?
+ SymName(actual(tok_stack[i])) : Image(type(tok_stack[i])),
+ precedence(tok_stack[i]));
+ }
+ } /* end DebugStacks */
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* InsertSpace(t) */
+ /* */
+ /* Add any missing catenation operator in front of token t. */
+ /* */
+ /*****************************************************************************/
+
+ #define InsertSpace(t) \
+ if( obj_prev ) \
+ { int typ, prec; \
+ if( hspace(t) + vspace(t) > 0 ) \
+ typ = TSPACE, prec = ACAT_PREC; \
+ else if( type(t) == LBR || obj_prev == PREV_RBR ) \
+ typ = TJUXTA, prec = ACAT_PREC; \
+ else \
+ typ = TJUXTA, prec = JUXTA_PREC; \
+ debugcond1(DOP, DD, debug_now, "[ InsertSpace(%s)", Image(typ)); \
+ while( obj_prev && precedence(TokenTop) >= prec ) \
+ obj_prev = Reduce(); \
+ if( obj_prev ) \
+ { New(tmp, typ); precedence(tmp) = prec; \
+ vspace(tmp) = vspace(t); hspace(tmp) = hspace(t); \
+ mark(gap(tmp)) = FALSE; join(gap(tmp)) = TRUE; \
+ FposCopy(fpos(tmp), fpos(t)); \
+ PushToken(tmp); \
+ } \
+ debugcond0(DOP, DD, debug_now, "] end InsertSpace()"); \
+ } /* end InsertSpace */
+
+
+ /*@::Shift(), ShiftObj()@*****************************************************/
+ /* */
+ /* static Shift(t, prec, rassoc, leftpar, rightpar) */
+ /* static ShiftObj(t) */
+ /* */
+ /* Shift token or object t onto the stacks; it has the attributes shown. */
+ /* */
+ /*****************************************************************************/
+
+ #define Shift(t, prec, rassoc, leftpar, rightpar) \
+ { debugcond5(DOP, DD, debug_now, "[ Shift(%s, %d, %s, %s, %s)", \
+ Image(type(t)), prec, rassoc ? "rightassoc" : "leftassoc", \
+ leftpar ? "lpar" : "nolpar", rightpar ? "rpar" : "norpar"); \
+ if( leftpar ) \
+ { for(;;) \
+ { if( !obj_prev ) \
+ { PushObj( MakeWord(WORD, STR_EMPTY, &fpos(t)) ); \
+ obj_prev = PREV_OBJ; \
+ } \
+ else if( precedence(TokenTop) >= prec + rassoc ) \
+ { obj_prev = Reduce(); \
+ if( ttop == initial_ttop ) \
+ { *token = t; \
+ debugcond0(DOP, DD, debug_now, \
+ "] ] end Shift() and Parse(); stacks are:"); \
+ ifdebugcond(DOP, DD, debug_now, \
+ DebugStacks(initial_ttop, obj_prev)); \
+ return PopObj(); \
+ } \
+ } \
+ else break; \
+ } \
+ } \
+ else InsertSpace(t); \
+ PushToken(t); \
+ if( rightpar ) obj_prev = FALSE; \
+ else \
+ { obj_prev = Reduce(); \
+ if( ttop == initial_ttop ) \
+ { *token = nilobj; \
+ debugcond0(DOP, DD, debug_now, \
+ "] ] end Shift and Parse; stacks are:"); \
+ ifdebugcond(DOP, DD, debug_now, \
+ DebugStacks(initial_ttop, obj_prev)); \
+ return PopObj(); \
+ } \
+ } \
+ debugcond0(DOP, DD, debug_now, "] end Shift()"); \
+ } /* end Shift */
+
+
+ #define ShiftObj(t, new_obj_prev) \
+ { debugcond1(DOP, DD, debug_now, "[ ShiftObj(%s)", Image(type(t))); \
+ InsertSpace(t); \
+ PushObj(t); \
+ obj_prev = new_obj_prev; \
+ debugcond0(DOP, DD, debug_now, "] end ShiftObj()"); \
+ }
+
+ /*@::Reduce()@****************************************************************/
+ /* */
+ /* static Reduce() */
+ /* */
+ /* Perform a single reduction of the stacks. */
+ /* */
+ /*****************************************************************************/
+
+ static BOOLEAN Reduce(void)
+ { OBJECT p1, p2, p3, s1, s2, tmp;
+ OBJECT op; int obj_prev;
+ debugcond0(DOP, DD, debug_now, "[ Reduce()");
+ /* ifdebugcond(DOP, DD, debug_now, DebugStacks(0, TRUE)); */
+
+ op = PopToken();
+ obj_prev = PREV_OBJ;
+ switch( type(op) )
+ {
+
+ case GSTUB_INT:
+ case GSTUB_EXT:
+
+ debug0(DGT, D, "calling TransferEnd( PopObj() ) from Reduce()");
+ TransferEnd( PopObj() );
+ New(p1, NULL_CLOS);
+ PushObj(p1);
+ Dispose(op);
+ break;
+
+
+ case GSTUB_NONE:
+
+ New(p1, NULL_CLOS);
+ PushObj(p1);
+ Dispose(op);
+ break;
+
+
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case SCALE:
+ case KERN_SHRINK:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+ case ROTATE:
+ case BACKGROUND:
+ case YIELD:
+ case BACKEND:
+ case XCHAR:
+ case FONT:
+ case SPACE:
+ case YUNIT:
+ case ZUNIT:
+ case BREAK:
+ case UNDERLINE:
+ case COLOUR:
+ case OUTLINE:
+ case LANGUAGE:
+ case CURR_LANG:
+ case CURR_FAMILY:
+ case CURR_FACE:
+ case CURR_YUNIT:
+ case CURR_ZUNIT:
+ case COMMON:
+ case RUMP:
+ case MELD:
+ case INSERT:
+ case ONE_OF:
+ case NEXT:
+ case PLUS:
+ case MINUS:
+ case TAGGED:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case OPEN:
+ case RAW_VERBATIM:
+ case VERBATIM:
+
+ if( has_rpar(actual(op)) )
+ { s2 = PopObj();
+ Link(op, s2);
+ }
+ if( has_lpar(actual(op)) )
+ { s1 = PopObj();
+ Link(Down(op), s1);
+ }
+ PushObj(op);
+ break;
+
+
+ case CASE:
+
+ if( has_rpar(actual(op)) )
+ { s2 = PopObj();
+ Link(op, s2);
+ }
+ if( has_lpar(actual(op)) )
+ { s1 = PopObj();
+ Link(Down(op), s1);
+ if( type(s1) == BACKEND )
+ { op = OptimizeCase(op);
+ }
+ }
+ PushObj(op);
+ break;
+
+
+ case CROSS:
+ case FORCE_CROSS:
+
+ s2 = PopObj();
+ Link(op, s2);
+ s1 = PopObj();
+ Link(Down(op), s1);
+ if( type(s1) != CLOSURE )
+ Error(6, 3, "left parameter of %s is not a symbol (or not visible)",
+ WARN, &fpos(s1), Image(type(op)));
+ PushObj(op);
+ break;
+
+
+ case CLOSURE:
+
+ if( has_rpar(actual(op)) )
+ { New(s2, PAR);
+ tmp = PopObj();
+ Link(s2, tmp);
+ FposCopy(fpos(s2), fpos(tmp));
+ actual(s2) = ChildSym(actual(op), RPAR);
+ Link(op, s2);
+ }
+ if( has_lpar(actual(op)) )
+ { New(s1, PAR);
+ tmp = PopObj();
+ Link(s1, tmp);
+ FposCopy(fpos(s1), fpos(tmp));
+ actual(s1) = ChildSym(actual(op), LPAR);
+ Link(Down(op), s1);
+ }
+ PushObj(op);
+ break;
+
+
+ case LBR:
+
+ Error(6, 4, "unmatched %s (inserted %s)", WARN, &fpos(op),
+ KW_LBR, KW_RBR);
+ Dispose(op);
+ obj_prev = PREV_RBR;
+ break;
+
+
+ case BEGIN:
+
+ assert1(FALSE, "Reduce: unmatched", KW_BEGIN);
+ break;
+
+
+ case RBR:
+
+ if( type(TokenTop) == LBR )
+ { /* *** FposCopy(fpos(ObjTop), fpos(TokenTop)); *** */
+ Dispose( PopToken() );
+ }
+ else if( type(TokenTop) == BEGIN )
+ { if( file_num(fpos(TokenTop)) > 0 )
+ Error(6, 5, "unmatched %s; inserted %s at%s (after %s)",
+ WARN, &fpos(op), KW_RBR, KW_LBR,
+ EchoFilePos(&fpos(TokenTop)), KW_BEGIN);
+ else
+ Error(6, 6, "unmatched %s not enclosed in anything",
+ FATAL, &fpos(op), KW_RBR);
+ }
+ else
+ { assert1(FALSE, "Reduce: unmatched", KW_RBR);
+ }
+ Dispose(op);
+ obj_prev = PREV_RBR;
+ break;
+
+
+ case END:
+
+ if( type(TokenTop) != BEGIN )
+ { assert1(FALSE, "Reduce: unmatched", KW_END);
+ }
+ else
+ { if( actual(op) != actual(TokenTop) )
+ {
+ if( actual(op) == StartSym )
+ Error(6, 7, "%s %s appended at end of file to match %s at%s",
+ WARN, &fpos(op), KW_END, SymName(actual(TokenTop)),
+ KW_BEGIN, EchoFilePos(&fpos(TokenTop)) );
+ else if( actual(op) == nilobj )
+ Error(6, 8, "%s replaced by %s %s to match %s at%s",
+ WARN, &fpos(op), KW_END, KW_END,
+ actual(TokenTop) == nilobj ? AsciiToFull("??") :
+ SymName(actual(TokenTop)),
+ KW_BEGIN, EchoFilePos(&fpos(TokenTop)) );
+ else
+ Error(6, 9, "%s %s replaced by %s %s to match %s at%s",
+ WARN, &fpos(op), KW_END, SymName(actual(op)),
+ KW_END, SymName(actual(TokenTop)),
+ KW_BEGIN, EchoFilePos(&fpos(TokenTop)) );
+ }
+ Dispose( PopToken() );
+ }
+ Dispose(op);
+ obj_prev = PREV_RBR;
+ break;
+
+
+ case GAP_OBJ:
+
+ p1 = PopObj();
+ Link(op, p1);
+ PushObj(op);
+ obj_prev = PREV_OP;
+ break;
+
+
+ case VCAT:
+ case HCAT:
+ case ACAT:
+
+ p3 = PopObj(); p2 = PopObj(); p1 = PopObj();
+ if( type(p1) == type(op) )
+ { Dispose(op);
+ }
+ else
+ { Link(op, p1);
+ p1 = op;
+ }
+ Link(p1, p2);
+ Link(p1, p3);
+ PushObj(p1);
+ break;
+
+
+ case TSPACE:
+ case TJUXTA:
+
+ p2 = PopObj(); p1 = PopObj();
+ if( type(p1) != ACAT )
+ { New(tmp, ACAT);
+ Link(tmp, p1);
+ FposCopy(fpos(tmp), fpos(p1));
+ p1 = tmp;
+ }
+ type(op) = GAP_OBJ;
+ Link(p1, op);
+ Link(p1, p2);
+ PushObj(p1);
+ break;
+
+
+ default:
+
+ assert1(FALSE, "Reduce:", Image(type(op)));
+ break;
+
+ } /* end switch */
+ debugcond1(DOP, DD, debug_now, "] end Reduce(), returning %s",
+ obj_prev == PREV_OP ? "PREV_OP" : obj_prev == PREV_OBJ ? "PREV_OBJ" :
+ obj_prev == PREV_RBR ? "PREV_RBR" : "???");
+ return obj_prev;
+ } /* end Reduce */
+
+
+ /*@::SetScope(), InitParser()@************************************************/
+ /* */
+ /* SetScope(env, count, vis_only) */
+ /* */
+ /* Push scopes required to parse object whose environment is env. */
+ /* Add to *count the number of scope pushes made. */
+ /* */
+ /* If vis_only is true, we only want visible things of the top-level */
+ /* element of env to be visible in this scope. */
+ /* */
+ /*****************************************************************************/
+
+ void SetScope(OBJECT env, int *count, BOOLEAN vis_only)
+ { OBJECT link, y, yenv; BOOLEAN visible_only;
+ debugcond2(DOP,DD, debug_now, "[ SetScope(%s, %d)", EchoObject(env), *count);
+ assert( env != nilobj && type(env) == ENV, "SetScope: type(env) != ENV!" );
+ if( Down(env) != env )
+ { Child(y, Down(env));
+ assert( LastDown(y) != y, "SetScope: LastDown(y)!" );
+ link = LastDown(env) != Down(env) ? LastDown(env) : LastDown(y);
+ Child(yenv, link);
+ assert( type(yenv) == ENV, "SetScope: type(yenv) != ENV!" );
+ SetScope(yenv, count, FALSE);
+ visible_only = vis_only || (use_invocation(actual(y)) != nilobj);
+ /* i.e. from @Use clause */
+ PushScope(actual(y), FALSE, visible_only); (*count)++;
+ /*** this following was a bright idea that did not work owing to
+ allowing body parameters at times they definitely shouldn't be
+ BodyParAllowed();
+ ***/
+ }
+ debugcond1(DOP, DD, debug_now, "] SetScope returning, count = %d", *count);
+ } /* end SetScope */
+
+
+ /*****************************************************************************/
+ /* */
+ /* InitParser() */
+ /* */
+ /* Initialise the parser to contain just GstubExt. */
+ /* Remember cross_db, the name of the cross reference database, for Parse. */
+ /* */
+ /*****************************************************************************/
+
+ void InitParser(FULL_CHAR *cross_db)
+ { if( StringLength(cross_db) >= MAX_WORD )
+ Error(6, 10, "cross reference database file name %s is too long",
+ FATAL, no_fpos, cross_db);
+ cross_name = MakeWord(WORD, cross_db, no_fpos);
+ PushToken( NewToken(GSTUB_EXT, no_fpos, 0, 0, DEFAULT_PREC, StartSym) );
+ } /* end InitParser */
+
+
+ /*@::ParseEnvClosure()@*******************************************************/
+ /* */
+ /* static OBJECT ParseEnvClosure(t, encl) */
+ /* */
+ /* Parse an object which is a closure with environment. Consume the */
+ /* concluding @LClos. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT ParseEnvClosure(OBJECT t, OBJECT encl)
+ { OBJECT env, res, y; int count, i;
+ debugcond0(DOP, DDD, debug_now, "ParseEnvClosure(t, encl)");
+ assert( type(t) == ENV, "ParseEnvClosure: type(t) != ENV!" );
+ env = t; t = LexGetToken();
+ while( type(t) != CLOS ) switch( type(t) )
+ {
+ case LBR: count = 0;
+ SetScope(env, &count, FALSE);
+ y = Parse(&t, encl, FALSE, FALSE);
+ if( type(y) != CLOSURE )
+ {
+ debug1(DIO, D, " Parse() returning %s:", Image(type(y)));
+ ifdebug(DIO, D, DebugObject(y));
+ Error(6, 11, "syntax error in cross reference database",
+ FATAL, &fpos(y));
+ }
+ for( i = 1; i <= count; i++ ) PopScope();
+ AttachEnv(env, y);
+ debug0(DCR, DDD, " calling SetEnv from ParseEnvClosure (a)");
+ env = SetEnv(y, nilobj);
+ t = LexGetToken();
+ break;
+
+ case ENV: y = ParseEnvClosure(t, encl);
+ debug0(DCR, DDD, " calling SetEnv from ParseEnvClosure (b)");
+ env = SetEnv(y, env);
+ t = LexGetToken();
+ break;
+
+ default: Error(6, 12, "error in cross reference database",
+ FATAL, &fpos(t));
+ break;
+ }
+ Dispose(t);
+ if( Down(env) == env || Down(env) != LastDown(env) )
+ Error(6, 13, "error in cross reference database", FATAL, &fpos(env));
+ Child(res, Down(env));
+ DeleteNode(env);
+ debugcond1(DOP, DDD, debug_now, "ParseEnvClosure ret. %s", EchoObject(res));
+ assert( type(res) == CLOSURE, "ParseEnvClosure: type(res) != CLOSURE!" );
+ return res;
+ } /* end ParseEnvClosure */
+
+
+ /*@::Parse()@*****************************************************************/
+ /* */
+ /* OBJECT Parse(token, encl, defs_allowed, transfer_allowed) */
+ /* */
+ /* Parse input tokens, beginning with *token, looking for an object of the */
+ /* form { ... } or @Begin ... @End <sym>, and return the object. */
+ /* The parent definition is encl, and scope has been set appropriately. */
+ /* Parse reads up to and including the last token of the object */
+ /* (the right brace or <sym>), and returns nilobj in *token. */
+ /* */
+ /* If defs_allowed == TRUE, there may be local definitions in the object. */
+ /* In this case, encl is guaranteed to be the enclosing definition. */
+ /* */
+ /* If transfer_allowed == TRUE, the parser may transfer components to the */
+ /* galley handler as they are read. */
+ /* */
+ /* Note: the lexical analyser returns "@End \Input" at end of input, so the */
+ /* parser does not have to handle end of input separately. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT Parse(OBJECT *token, OBJECT encl,
+ BOOLEAN defs_allowed, BOOLEAN transfer_allowed)
+ { OBJECT t, x, tmp, xsym, env, y, link, res, imps, xlink;
+ int i, offset, lnum, initial_ttop = ttop;
+ int obj_prev, scope_count, compulsory_count; BOOLEAN revealed;
+
+ debugcond4(DOP, DD, debug_now, "[ Parse(%s, %s, %s, %s)", EchoToken(*token),
+ SymName(encl), bool(defs_allowed), bool(transfer_allowed));
+ assert( type(*token) == LBR || type(*token) == BEGIN, "Parse: *token!" );
+
+ obj_prev = PREV_OP;
+ Shift(*token, precedence(*token), 0, FALSE, TRUE);
+ t = LexGetToken();
+ if( defs_allowed )
+ { ReadDefinitions(&t, encl, LOCAL);
+
+ /* if error in definitions, stop now */
+ if( ErrorSeen() )
+ Error(6, 14, "exiting now", FATAL, &fpos(t));
+
+ if( encl == StartSym )
+ {
+ /* read @Use, @Database, and @Prepend commands and defs and construct env */
+ New(env, ENV);
+ for(;;)
+ {
+ if( type(t) == WORD && (
+ StringEqual(string(t), KW_DEF) ||
+ /* StringEqual(string(t), KW_FONTDEF) || */
+ StringEqual(string(t), KW_LANGDEF) ||
+ StringEqual(string(t), KW_MACRO) ||
+ StringEqual(string(t), KW_IMPORT) ||
+ StringEqual(string(t), KW_EXTEND) ||
+ StringEqual(string(t), KW_EXPORT) ) )
+ {
+ ReadDefinitions(&t, encl, LOCAL);
+
+ /* if error in definitions, stop now */
+ if( ErrorSeen() )
+ Error(6, 39, "exiting now", FATAL, &fpos(t));
+
+ }
+ else if( type(t) == USE )
+ {
+ OBJECT crs, res_env; STYLE style;
+ Dispose(t); t = LexGetToken();
+ if( type(t) != LBR )
+ Error(6, 15, "%s expected after %s", FATAL, &fpos(t),KW_LBR,KW_USE);
+ debug0(DOP, DD, " Parse() calling Parse for @Use clause");
+ y = Parse(&t, encl, FALSE, FALSE);
+ if( is_cross(type(y)) )
+ { OBJECT z;
+ Child(z, Down(y));
+ if( type(z) == CLOSURE )
+ { crs = nilobj;
+ y = CrossExpand(y, env, &style, &crs, &res_env);
+ if( crs != nilobj )
+ { Error(6, 16, "%s or %s tag not allowed here",
+ FATAL, &fpos(y), KW_PRECEDING, KW_FOLLOWING);
+ }
+ HuntCommandOptions(y);
+ AttachEnv(res_env, y);
+ debug0(DCR, DDD, " calling SetEnv from Parse (a)");
+ env = SetEnv(y, env);
+ }
+ else Error(6, 17, "invalid parameter of %s", FATAL, &fpos(y), KW_USE);
+ }
+ else if( type(y) == CLOSURE )
+ { if( use_invocation(actual(y)) != nilobj )
+ Error(6, 18, "symbol %s occurs in two %s clauses",
+ FATAL, &fpos(y), SymName(actual(y)), KW_USE);
+ use_invocation(actual(y)) = y;
+ HuntCommandOptions(y);
+ AttachEnv(env, y);
+ debug0(DCR, DDD, " calling SetEnv from Parse (b)");
+ env = SetEnv(y, nilobj);
+ }
+ else Error(6, 19, "invalid parameter of %s", FATAL, &fpos(y), KW_USE);
+ PushScope(actual(y), FALSE, TRUE);
+ t = LexGetToken();
+ }
+ else if( type(t) == PREPEND || type(t) == SYS_PREPEND )
+ { ReadPrependDef(type(t), encl);
+ Dispose(t);
+ t = LexGetToken();
+ }
+ else if( type(t) == DATABASE || type(t) == SYS_DATABASE )
+ { ReadDatabaseDef(type(t), encl);
+ Dispose(t);
+ t = LexGetToken();
+ }
+ else break;
+ }
+
+ /* transition point from defs to content; turn on debugging now */
+ #if DEBUG_ON
+ debug_now = TRUE;
+ #endif
+ debugcond4(DOP, DD, debug_now, "[ Parse (first) (%s, %s, %s, %s)",
+ EchoToken(*token), SymName(encl), bool(defs_allowed),
+ bool(transfer_allowed));
+
+ /* load cross-references from previous run, open new cross refs */
+ if( AllowCrossDb )
+ {
+ NewCrossDb = DbCreate(MakeWord(WORD, string(cross_name), no_fpos));
+ OldCrossDb = DbLoad(cross_name, SOURCE_PATH, FALSE, nilobj,
+ InMemoryDbIndexes);
+ }
+ else OldCrossDb = NewCrossDb = nilobj;
+
+ /* tidy up and possibly print symbol table */
+ FlattenUses();
+ ifdebug(DST, DD, DebugObject(StartSym));
+
+ TransferInit(env);
+ debug0(DMA, D, "at end of definitions:");
+ ifdebug(DMA, D, DebugMemory());
+ }
+ }
+
+ for(;;)
+ {
+ debugcond0(DOP, DD, debug_now, "");
+ ifdebugcond(DOP, DD, debug_now, DebugStacks(0, obj_prev));
+ debugcond0(DOP, DD, debug_now, "");
+ debugcond2(DOP, DD, debug_now, ">> %s (precedence %d)", EchoToken(t), precedence(t));
+
+ switch( type(t) )
+ {
+
+ case WORD:
+
+ if( string(t)[0] == CH_SYMSTART &&
+ (obj_prev != PREV_OBJ || vspace(t) + hspace(t) > 0) )
+ {
+ Error(6, 20, "symbol %s unknown or misspelt",
+ WARN, &fpos(t), string(t));
+ if( ++unknown_count > 25 )
+ {
+ Error(6, 21, "too many errors (%s lines missing or out of order?)",
+ FATAL, &fpos(t), KW_SYSINCLUDE);
+ }
+ }
+ ShiftObj(t, PREV_OBJ);
+ t = LexGetToken();
+ break;
+
+
+ case QWORD:
+
+ ShiftObj(t, PREV_OBJ);
+ t = LexGetToken();
+ break;
+
+
+ case VCAT:
+ case HCAT:
+ case ACAT:
+
+ /* clean up left context */
+ Shift(t, precedence(t), LEFT_ASSOC, TRUE, TRUE);
+
+ /* invoke transfer subroutines if appropriate */
+ /* *** if( type(t) == VCAT && !has_join(actual(t)) *** */
+ if( transfer_allowed && type(t) == VCAT && !has_join(actual(t))
+ && type(tok_stack[ttop-2]) == GSTUB_EXT )
+ {
+ debug0(DGT, DD, " calling TransferComponent from Parse:");
+ ifdebug(DGT, DD, DebugStacks(0, obj_prev));
+ TransferComponent( PopObj() );
+ New(tmp, NULL_CLOS);
+ FposCopy( fpos(tmp), fpos(t) );
+ PushObj(tmp);
+ }
+
+ /* push GAP_OBJ token, to cope with 3 parameters */
+ New(x, GAP_OBJ);
+ mark(gap(x)) = has_mark(actual(t));
+ join(gap(x)) = has_join(actual(t));
+ hspace(x) = hspace(t);
+ vspace(x) = vspace(t);
+ precedence(x) = GAP_PREC;
+ FposCopy( fpos(x), fpos(t) );
+ Shift(x, GAP_PREC, LEFT_ASSOC, FALSE, TRUE);
+
+ /* if op is followed by space, insert {} */
+ t = LexGetToken();
+ if( hspace(t) + vspace(t) > 0 )
+ { ShiftObj(MakeWord(WORD, STR_EMPTY, &fpos(x)), PREV_OBJ);
+ }
+ break;
+
+
+ case CROSS:
+ case FORCE_CROSS:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case SCALE:
+ case KERN_SHRINK:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+ case ROTATE:
+ case BACKGROUND:
+ case CASE:
+ case YIELD:
+ case BACKEND:
+ case XCHAR:
+ case FONT:
+ case SPACE:
+ case YUNIT:
+ case ZUNIT:
+ case BREAK:
+ case UNDERLINE:
+ case COLOUR:
+ case OUTLINE:
+ case LANGUAGE:
+ case CURR_LANG:
+ case CURR_FAMILY:
+ case CURR_FACE:
+ case CURR_YUNIT:
+ case CURR_ZUNIT:
+ case COMMON:
+ case RUMP:
+ case MELD:
+ case INSERT:
+ case ONE_OF:
+ case NEXT:
+ case TAGGED:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+
+ /* clean up left context of t (these ops are all right associative) */
+ Shift(t, precedence(t), RIGHT_ASSOC,
+ has_lpar(actual(t)), has_rpar(actual(t)));
+ t = LexGetToken();
+ break;
+
+
+ case VERBATIM:
+ case RAW_VERBATIM:
+
+ /* clean up left context of t */
+ x = t;
+ Shift(t, precedence(t), RIGHT_ASSOC,
+ has_lpar(actual(t)), has_rpar(actual(t)));
+
+ /* check for opening brace or begin following, and shift it onto the stacks */
+ t = LexGetToken();
+ if( type(t) != BEGIN && type(t) != LBR )
+ Error(6, 40, "right parameter of %s or %s must be enclosed in braces",
+ FATAL, &fpos(x), KW_VERBATIM, KW_RAWVERBATIM);
+ actual(t) = type(x) == VERBATIM ? VerbatimSym : RawVerbatimSym;
+ Shift(t, LBR_PREC, 0, FALSE, TRUE);
+
+ /* read right parameter and add it to the stacks, and reduce */
+ y = LexScanVerbatim( (FILE *) NULL, type(t) == BEGIN, &fpos(t),
+ type(x) == RAW_VERBATIM);
+ ShiftObj(y, PREV_OBJ);
+
+ /* carry on, hopefully to the corresponding right brace or @End @Verbatim */
+ t = LexGetToken();
+ break;
+
+
+ case PLUS:
+ case MINUS:
+
+ /* clean up left context of t (these ops are all left associative) */
+ Shift(t, precedence(t), LEFT_ASSOC,
+ has_lpar(actual(t)), has_rpar(actual(t)));
+ t = LexGetToken();
+ break;
+
+
+ case UNEXPECTED_EOF:
+
+ Error(6, 22, "unexpected end of input", FATAL, &fpos(t));
+ break;
+
+
+ case BEGIN:
+
+ if( actual(t) == nilobj )
+ { Error(6, 23, "%s replaced by %s", WARN, &fpos(t), KW_BEGIN, KW_LBR);
+ type(t) = LBR;
+ }
+ /* NB NO BREAK! */
+
+
+ case LBR:
+
+ Shift(t, LBR_PREC, 0, FALSE, TRUE);
+ t = LexGetToken();
+ break;
+
+
+ case END:
+
+ if( actual(t) == nilobj ) /* haven't sought following symbol yet */
+ { x = LexGetToken();
+ if( type(x) == CLOSURE )
+ { actual(t) = actual(x);
+ Dispose(x);
+ x = nilobj;
+ }
+ else if( type(x) == VERBATIM )
+ { actual(t) = VerbatimSym;
+ Dispose(x);
+ x = nilobj;
+ }
+ else if( type(x) == RAW_VERBATIM )
+ { actual(t) = RawVerbatimSym;
+ Dispose(x);
+ x = nilobj;
+ }
+ else if( type(x) == WORD && string(x)[0] == CH_SYMSTART )
+ { Error(6, 24, "unknown or misspelt symbol %s after %s deleted",
+ WARN, &fpos(x), string(x), KW_END);
+ actual(t) = nilobj;
+ Dispose(x);
+ x = nilobj;
+ }
+ else
+ { Error(6, 25, "symbol expected after %s", WARN, &fpos(x), KW_END);
+ actual(t) = nilobj;
+ }
+ }
+ else x = nilobj;
+ Shift(t, precedence(t), 0, TRUE, FALSE);
+ t = (x != nilobj) ? x : LexGetToken();
+ break;
+
+
+ case RBR:
+
+ Shift(t, precedence(t), 0, TRUE, FALSE);
+ t = LexGetToken();
+ break;
+
+
+ case USE:
+ case NOT_REVEALED:
+ case PREPEND:
+ case SYS_PREPEND:
+ case DATABASE:
+ case SYS_DATABASE:
+
+ Error(6, 26, "%s symbol out of place",
+ FATAL, &fpos(t), SymName(actual(t)));
+ break;
+
+
+ case ENV:
+
+ /* only occurs in cross reference databases */
+ res = ParseEnvClosure(t, encl);
+ ShiftObj(res, PREV_OBJ);
+ t = LexGetToken();
+ break;
+
+
+ case ENVA:
+
+ /* only occurs in cross reference databases */
+ offset = LexNextTokenPos() -StringLength(KW_ENVA)-StringLength(KW_LBR)-1;
+ Dispose(t); t = LexGetToken();
+ tmp = Parse(&t, encl, FALSE, FALSE);
+ env = SetEnv(tmp, nilobj);
+ ShiftObj(env, PREV_OBJ);
+ t = LexGetToken();
+ EnvReadInsert(file_num(fpos(t)), offset, env);
+ break;
+
+
+ case ENVB:
+
+ /* only occurs in cross reference databases */
+ offset = LexNextTokenPos() -StringLength(KW_ENVB)-StringLength(KW_LBR)-1;
+ Dispose(t); t = LexGetToken();
+ env = Parse(&t, encl, FALSE, FALSE);
+ t = LexGetToken();
+ res = Parse(&t, encl, FALSE, FALSE);
+ env = SetEnv(res, env);
+ ShiftObj(env, PREV_OBJ);
+ t = LexGetToken();
+ EnvReadInsert(file_num(fpos(t)), offset, env);
+ break;
+
+
+ case ENVC:
+
+ /* only occurs in cross reference databases */
+ Dispose(t); t = LexGetToken();
+ New(res, ENV);
+ ShiftObj(res, PREV_OBJ);
+ break;
+
+
+ case ENVD:
+
+ /* only occurs in cross reference databases */
+ Dispose(t); t = LexGetToken();
+ if( type(t) != QWORD ||
+ sscanf((char *) string(t), "%d %d", &offset, &lnum) != 2 )
+ Error(6, 37, "error in cross reference database", FATAL, &fpos(t));
+ if( !EnvReadRetrieve(file_num(fpos(t)), offset, &env) )
+ { LexPush(file_num(fpos(t)), offset, DATABASE_FILE, lnum, TRUE);
+ Dispose(t); t = LexGetToken();
+ env = Parse(&t, encl, FALSE, FALSE);
+ LexPop();
+ }
+ else
+ { Dispose(t);
+ }
+ ShiftObj(env, PREV_OBJ);
+ t = LexGetToken();
+ break;
+
+
+ case CENV:
+
+ /* only occurs in cross reference databases */
+ Dispose(t); t = LexGetToken();
+ env = Parse(&t, encl, FALSE, FALSE);
+ scope_count = 0;
+ SetScope(env, &scope_count, FALSE);
+ t = LexGetToken();
+ res = Parse(&t, encl, FALSE, FALSE);
+ for( i = 0; i < scope_count; i++ ) PopScope();
+ AttachEnv(env, res);
+ ShiftObj(res, PREV_OBJ);
+ t = LexGetToken();
+ break;
+
+
+ case LUSE:
+
+ /* only occurs in cross-reference databases */
+ /* copy invocation from use_invocation(xsym), don't read it */
+ Dispose(t); t = LexGetToken();
+ if( type(t) != CLOSURE )
+ Error(6, 27, "symbol expected following %s", FATAL,&fpos(t),KW_LUSE);
+ xsym = actual(t);
+ if( use_invocation(xsym) == nilobj )
+ Error(6, 28, "%s clause(s) changed from previous run",
+ FATAL, &fpos(t), KW_USE);
+ x = CopyObject(use_invocation(xsym), no_fpos);
+ for( link = LastDown(x); link != x; link = PrevDown(link) )
+ { Child(y, link);
+ if( type(y) == ENV )
+ { DeleteLink(link);
+ break;
+ }
+ }
+ ShiftObj(x, PREV_OBJ);
+ t = LexGetToken();
+ break;
+
+
+ case LVIS:
+
+ /* only occurs in cross-reference databases */
+ SuppressVisible();
+ Dispose(t); t = LexGetToken();
+ UnSuppressVisible();
+ if( type(t) != CLOSURE )
+ Error(6, 29, "symbol expected following %s", FATAL,&fpos(t),KW_LVIS);
+ /* NB NO BREAK! */
+
+
+ case CLOSURE:
+
+ x = t; xsym = actual(x);
+
+ /* look ahead one token, which could be an NPAR */
+ /* or could be @NotRevealed */
+ PushScope(xsym, TRUE, FALSE);
+ t = LexGetToken();
+ if( type(t) == NOT_REVEALED )
+ { Dispose(t);
+ t = LexGetToken();
+ revealed = FALSE;
+ }
+ else revealed = TRUE;
+ PopScope();
+
+ /* if x starts a cross-reference, make it a CLOSURE */
+ if( is_cross(type(t)) )
+ { ShiftObj(x, PREV_OBJ);
+ break;
+ }
+
+ /* clean up left context of x */
+ Shift(x,precedence(x),right_assoc(xsym),has_lpar(xsym),has_rpar(xsym));
+
+ /* update uses relation if required */
+ if( encl != StartSym && encl != nilobj )
+ { if( has_target(xsym) )
+ { uses_galley(encl) = TRUE;
+ dirty(encl) = (dirty(encl) || dirty(xsym));
+ }
+ else if( revealed ) InsertUses(encl, xsym);
+ }
+
+ /* read named parameters */
+ compulsory_count = 0;
+ while( (type(t) == CLOSURE && enclosing(actual(t)) == xsym
+ && type(actual(t)) == NPAR)
+ || (type(t) == LBR && precedence(t) != LBR_PREC) )
+ {
+ OBJECT new_par;
+
+ /* check syntax and attach the named parameter to x */
+ if( type(t) == CLOSURE )
+ {
+ new_par = t;
+ t = LexGetToken();
+ if( type(t) != LBR )
+ { Error(6, 30, "%s must follow named parameter %s",
+ WARN, &fpos(new_par), KW_LBR, SymName(actual(new_par)));
+ Dispose(new_par);
+ break;
+ }
+ }
+ else
+ {
+ /* compressed form of named parameter */
+ new_par = NewToken(CLOSURE, &fpos(t), vspace(t), hspace(t),
+ NO_PREC, ChildSymWithCode(x, precedence(t)));
+ precedence(t) = LBR_PREC;
+ }
+
+ /* add import list of the named parameter to current scope */
+ scope_count = 0;
+ imps = imports(actual(new_par));
+ if( imps != nilobj )
+ { for( link = Down(imps); link != imps; link = NextDown(link) )
+ { Child(y, link);
+ PushScope(actual(y), FALSE, TRUE);
+ scope_count++;
+ }
+ }
+
+ /* read the body of the named parameter */
+ PushScope(actual(new_par), FALSE, FALSE);
+ tmp = Parse(&t, encl, FALSE, FALSE);
+ PopScope();
+ type(new_par) = PAR;
+ Link(new_par, tmp);
+
+ /* pop the scopes pushed for the import list */
+ for( i = 0; i < scope_count; i++ )
+ PopScope();
+
+ /* check that new_par has not already occurred, then link it to x */
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) == PAR, "Parse: type(y) != PAR!" );
+ if( actual(new_par) == actual(y) )
+ { Error(6, 31, "named parameter %s of %s appears twice", WARN,
+ &fpos(new_par), SymName(actual(new_par)), SymName(actual(x)));
+ DisposeObject(new_par);
+ new_par = nilobj;
+ break;
+ }
+ }
+ if( new_par != nilobj )
+ {
+ /* keep track of the number of compulsory named parameters */
+ if( is_compulsory(actual(new_par)) )
+ compulsory_count++;
+
+ Link(x, new_par);
+ }
+
+ /* get next token, possibly another NPAR */
+ PushScope(xsym, TRUE, FALSE); /* allow NPARs only */
+ if( t == nilobj ) t = LexGetToken();
+ PopScope();
+
+ } /* end while */
+
+ /* report absence of compulsory parameters */
+ debug4(DOP, D, "%s %s %d : %d", EchoFilePos(&fpos(x)),
+ SymName(xsym), compulsory_count, has_compulsory(xsym));
+ if( compulsory_count < has_compulsory(xsym) )
+ {
+ for( xlink = Down(xsym); xlink != xsym; xlink = NextDown(xlink) )
+ { Child(tmp, xlink);
+ if( type(tmp) == NPAR && is_compulsory(tmp) )
+ { for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == PAR && actual(y) == tmp )
+ break;
+ }
+ if( link == x )
+ {
+ Error(6, 38, "compulsory option %s missing from %s",
+ WARN, &fpos(x), SymName(tmp), SymName(xsym));
+ }
+ }
+ }
+ }
+
+ /* record symbol name in BEGIN following, if any */
+ if( type(t) == BEGIN )
+ { if( !has_rpar(xsym) )
+ Error(6, 32, "%s out of place here (%s has no right parameter)",
+ WARN, &fpos(x), KW_BEGIN, SymName(xsym));
+ else actual(t) = xsym;
+ }
+
+ /* if x can be transferred, do so */
+ if( transfer_allowed && has_target(xsym) &&
+ !has_key(xsym) && filter(xsym) == nilobj )
+ {
+ if( !has_rpar(xsym) || uses_count(ChildSym(xsym, RPAR)) <= 1 )
+ {
+ debug1(DGT, D, "examining transfer of %s", SymName(xsym));
+ ifdebug(DGT, D, DebugStacks(initial_ttop, obj_prev));
+ i = has_rpar(xsym) ? ttop -1 : ttop;
+ while( is_cat_op(type(tok_stack[i])) ) i--;
+ if( (type(tok_stack[i])==LBR || type(tok_stack[i])==BEGIN)
+ && type(tok_stack[i-1]) == GSTUB_EXT )
+ {
+ /* at this point it is likely that x is transferable */
+ if( has_rpar(xsym) )
+ { New(tmp, CLOSURE);
+ actual(tmp) = InputSym;
+ FposCopy( fpos(tmp), fpos(t) );
+ ShiftObj(tmp, PREV_OBJ);
+ obj_prev = Reduce();
+ }
+ x = PopObj();
+ x = TransferBegin(x);
+ if( type(x) == CLOSURE ) /* failure: unReduce */
+ { if( has_rpar(xsym) )
+ { Child(tmp, LastDown(x));
+ assert(type(tmp)==PAR && type(actual(tmp))==RPAR,
+ "Parse: cannot undo rpar" );
+ DisposeChild(LastDown(x));
+ if( has_lpar(xsym) )
+ { Child(tmp, Down(x));
+ assert(type(tmp)==PAR && type(actual(tmp))==LPAR,
+ "Parse: cannot undo lpar" );
+ Child(tmp, Down(tmp));
+ PushObj(tmp);
+ DeleteLink(Up(tmp));
+ DisposeChild(Down(x));
+ }
+ PushToken(x); obj_prev = PREV_OP;
+ }
+ else
+ { PushObj(x);
+ obj_prev = PREV_OBJ;
+ }
+ }
+ else /* success */
+ { obj_prev = PREV_OP;
+ Shift(x, NO_PREC, 0, FALSE, has_rpar(xsym));
+ }
+ }
+ }
+ } /* end if has_target */
+
+ if( filter(xsym) != nilobj )
+ {
+ if( type(t) == BEGIN || type(t) == LBR )
+ {
+ /* create filter object and copy parameter into temp file */
+ tmp = FilterCreate((BOOLEAN) (type(t) == BEGIN), xsym, &fpos(t));
+
+ /* push filter object onto stacks and keep going */
+ Shift(t, precedence(t), 0, FALSE, TRUE);
+ ShiftObj(tmp, PREV_OBJ);
+ t = LexGetToken();
+ }
+ else Error(6, 33, "right parameter of %s must be enclosed in braces",
+ FATAL, &fpos(x), SymName(xsym));
+ }
+
+ else if( has_body(xsym) )
+ { if( type(t) == BEGIN || type(t) == LBR )
+ { PushScope(xsym, FALSE, TRUE);
+ PushScope(ChildSym(xsym, RPAR), FALSE, FALSE);
+ PushObj( Parse(&t, encl, FALSE, TRUE) );
+ obj_prev = Reduce();
+ PopScope();
+ PopScope();
+ if( t == nilobj ) t = LexGetToken();
+ }
+ else
+ { Error(6, 34, "body parameter of %s must be enclosed in braces",
+ WARN, &fpos(t), SymName(xsym));
+ }
+ }
+ break;
+
+
+ case OPEN:
+
+ x = t; xsym = nilobj;
+ Shift(t, precedence(t), RIGHT_ASSOC, TRUE, TRUE);
+ if( type(ObjTop) == CLOSURE ) xsym = actual(ObjTop);
+ else if( is_cross(type(ObjTop)) && Down(ObjTop) != ObjTop )
+ { Child(tmp, Down(ObjTop));
+ if( type(tmp) == CLOSURE ) xsym = actual(tmp);
+ }
+ t = LexGetToken();
+
+ if( xsym == nilobj )
+ Error(6, 35, "invalid left parameter of %s", WARN, &fpos(x), KW_OPEN);
+ else if( type(t) != BEGIN && type(t) != LBR )
+ Error(6, 36, "right parameter of %s must be enclosed in braces",
+ WARN, &fpos(t), KW_OPEN);
+ else
+ { PushScope(xsym, FALSE, TRUE);
+ tmp = Parse(&t, encl, FALSE, FALSE);
+ ShiftObj(tmp, PREV_RBR);
+ PopScope();
+ if( t == nilobj ) t = LexGetToken();
+ obj_prev = Reduce();
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "Parse:", Image(type(t)));
+ break;
+
+ } /* end switch */
+ } /* end for */
+
+ } /* end Parse */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z07.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z07.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z07.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,674 ----
+ /*@z07.c:Object Service:SplitIsDefinite(), DisposeObject()@*******************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z07.c */
+ /* MODULE: Object Service */
+ /* EXTERNS: MakeWord(), MakeWordTwo(), MakeWordThree(), */
+ /* DisposeObject(), CopyObject(), */
+ /* SplitIsDefinite(), InsertObject() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN SplitIsDefinite(x) */
+ /* */
+ /* Return TRUE if x is a definite SPLIT object (both children definite) */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN SplitIsDefinite(OBJECT x)
+ { OBJECT y1, y2;
+ assert( type(x) == SPLIT, "SplitIsDefinite: x not a SPLIT!" );
+ Child(y1, DownDim(x, COLM));
+ Child(y2, DownDim(x, ROWM));
+ return is_definite(type(y1)) && is_definite(type(y2));
+ } /* end SplitIsDefinite */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DisposeSplitObject(x) */
+ /* */
+ /* Dispose SPLIT object x, taking care to handle COL_THR and ROW_THR */
+ /* children properly. */
+ /* */
+ /*****************************************************************************/
+
+ static void DisposeSplitObject(OBJECT x)
+ { int i, count;
+ OBJECT y, link, uplink;
+ debug1(DOS, D, "[ DisposeSplitObject( %ld )", (long) x);
+ assert(type(x) == SPLIT, "DisposeSplitObject: type(x) != SPLIT!");
+ assert(Down(x) != x, "DisposeSplitObject: x has no children!")
+ assert(LastDown(x) != Down(x), "DisposeSplitObject: x has one child!")
+ assert(LastDown(x) == NextDown(Down(x)), "DisposeSplitObject: children!")
+
+ /* handle first child */
+ CountChild(y, Down(x), count);
+ if( type(y) == COL_THR )
+ {
+ /* find corresponding child link out of y and delete that link */
+ for( link = Down(y), uplink = Up(y), i = 1;
+ link != y && uplink != y && i < count;
+ link = NextDown(link), uplink = NextUp(uplink), i++ );
+ assert( link != y && uplink != y, "DisposeSplitObject: link (a)!" );
+ DisposeChild(link);
+ }
+ DisposeChild(Down(x));
+
+ /* handle second child */
+ CountChild(y, LastDown(x), count);
+ if( type(y) == ROW_THR )
+ {
+ /* find corresponding child link out of y and delete that link */
+ for( link = Down(y), uplink = Up(y), i = 1;
+ link != y && uplink != y && i < count;
+ link = NextDown(link), uplink = NextUp(uplink), i++ );
+ assert( link != y && uplink != y, "DisposeSplitObject: link (b)!" );
+ DisposeChild(link);
+ }
+ DisposeChild(LastDown(x));
+ debug0(DOS, D, "] DisposeSplitObject returning");
+ } /* end DisposeSplitObject */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DisposeObject(x) */
+ /* */
+ /* Dispose object x recursively, leaving intact any shared descendants. */
+ /* We return a useless integer so that we can use this in expresssions. */
+ /* */
+ /* If x is a SPLIT object then one or both of its children could be */
+ /* COL_THR or ROW_THR objects. If such thread object is has this SPLIT */
+ /* as its ith parent, then we need to dispose its ith child. */
+ /* */
+ /*****************************************************************************/
+
+ int DisposeObject(OBJECT x)
+ { debug2(DOS,DDD,"[DisposeObject( %ld ), type = %s, x =", (long) x, Image(type(x)));
+ ifdebug(DOS, DDD, DebugObject(x));
+ assert( Up(x) == x, "DisposeObject: x has a parent!" );
+ if( type(x) == SPLIT )
+ DisposeSplitObject(x);
+ else
+ { while( Down(x) != x ) DisposeChild(Down(x));
+ Dispose(x);
+ }
+ debug0(DOS, DDD, "]DisposeObject returning.");
+ return 0;
+ } /* end DisposeObject */
+
+
+ /*@::MakeWord(), MakeWordTwo()@***********************************************/
+ /* */
+ /* OBJECT MakeWord(typ, str, pos) */
+ /* */
+ /* Return an unsized WORD or QWORD made from the given string and fpos. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT MakeWord(unsigned typ, FULL_CHAR *str, FILE_POS *pos)
+ { OBJECT res;
+ NewWord(res, typ, StringLength(str), pos);
+ StringCopy(string(res), str);
+ FposCopy(fpos(res), *pos);
+ debug4(DOS, DDD, "MakeWord(%s, %s, %s) returning %s",
+ Image(typ), str, EchoFilePos(pos), EchoObject(res));
+ return res;
+ } /* end MakeWord */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT MakeWordTwo(typ, str1, str2, pos) */
+ /* */
+ /* Return an unsized WORD or QWORD made from the two strings and fpos. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT MakeWordTwo(unsigned typ, FULL_CHAR *str1, FULL_CHAR *str2, FILE_POS *pos)
+ { int len1 = StringLength(str1);
+ int len2 = StringLength(str2);
+ OBJECT res;
+ debug4(DOS, DDD, "MakeWordTwo(%s, %s, %s, %s)",
+ Image(typ), str1, str2, EchoFilePos(pos));
+ NewWord(res, typ, len1 + len2, pos);
+ StringCopy(string(res), str1);
+ StringCopy(&string(res)[len1], str2);
+ FposCopy(fpos(res), *pos);
+ debug5(DOS, DDD, "MakeWordTwo(%s, %s, %s, %s) returning %s",
+ Image(typ), str1, str2, EchoFilePos(pos), EchoObject(res));
+ return res;
+ } /* end MakeWordTwo */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT MakeWordThree(s1, s2, s3) */
+ /* */
+ /* Return an unsized WORD containing these three strings. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT MakeWordThree(FULL_CHAR *s1, FULL_CHAR *s2, FULL_CHAR *s3)
+ { int len1 = StringLength(s1);
+ int len2 = StringLength(s2);
+ int len3 = StringLength(s3);
+ OBJECT res;
+ debug3(DOS, DDD, "MakeWordThree(%s, %s, %s)", s1, s2, s3);
+ NewWord(res, WORD, len1 + len2 + len3, no_fpos);
+ StringCopy(string(res), s1);
+ StringCopy(&string(res)[len1], s2);
+ StringCopy(&string(res)[len1 + len2], s3);
+ debug4(DOS, DDD, "MakeWordThree(%s, %s, %s) returning %s",
+ s1, s2, s3, EchoObject(res));
+ return res;
+ } /* end MakeWordThree */
+
+
+ /*@::CopyObject()@************************************************************/
+ /* */
+ /* OBJECT CopyObject(x, pos) */
+ /* */
+ /* Make a copy of unsized object x, setting all file positions to *pos. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT CopyObject(OBJECT x, FILE_POS *pos)
+ { OBJECT y, link, res, tmp;
+
+ debug2(DOS, DD, "[ CopyObject(%s, %s)", EchoObject(x), EchoFilePos(pos));
+ switch( type(x) )
+ {
+
+ case WORD:
+ case QWORD:
+
+ NewWord(res, type(x), StringLength(string(x)), pos);
+ StringCopy(string(res), string(x));
+ break;
+
+
+ case GAP_OBJ:
+
+ New(res, GAP_OBJ);
+ mark(gap(res)) = mark(gap(x));
+ join(gap(res)) = join(gap(x));
+ hspace(res) = hspace(x);
+ vspace(res) = vspace(x);
+ if( Down(x) != x )
+ { Child(y, Down(x));
+ tmp = CopyObject(y, pos);
+ Link(res, tmp);
+ }
+ break;
+
+
+ /* case HEAD: */
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case CROSS:
+ case FORCE_CROSS:
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case SCALE:
+ case KERN_SHRINK:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+ case ROTATE:
+ case BACKGROUND:
+ case RAW_VERBATIM:
+ case VERBATIM:
+ case CASE:
+ case YIELD:
+ case BACKEND:
+ case XCHAR:
+ case FONT:
+ case SPACE:
+ case YUNIT:
+ case ZUNIT:
+ case BREAK:
+ case UNDERLINE:
+ case COLOUR:
+ case OUTLINE:
+ case LANGUAGE:
+ case CURR_LANG:
+ case CURR_FAMILY:
+ case CURR_FACE:
+ case CURR_YUNIT:
+ case CURR_ZUNIT:
+ case COMMON:
+ case RUMP:
+ case MELD:
+ case INSERT:
+ case ONE_OF:
+ case NEXT:
+ case PLUS:
+ case MINUS:
+ case OPEN:
+ case TAGGED:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case VCAT:
+ case HCAT:
+ case ACAT:
+ case ENV_OBJ:
+
+ New(res, type(x));
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ tmp = CopyObject(y, pos);
+ Link(res, tmp);
+ }
+ break;
+
+
+ case FILTERED:
+
+ New(res, type(x));
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ Link(res, y); /* do not copy children of FILTERED */
+ }
+ debug3(DFH, D, "copying FILTERED %d into %d %s",
+ (int) x, (int) res, EchoObject(res));
+ break;
+
+
+ case ENV:
+
+ res = x; /* do not copy environments */
+ break;
+
+
+ case PAR:
+
+ New(res, PAR);
+ actual(res) = actual(x);
+ assert( Down(x) != x, "CopyObject: PAR child!" );
+ Child(y, Down(x));
+ tmp = CopyObject(y, pos);
+ Link(res, tmp);
+ break;
+
+
+ case CLOSURE:
+
+ New(res, CLOSURE);
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) != CLOSURE, "CopyObject: CLOSURE!" );
+ tmp = CopyObject(y, pos);
+ Link(res, tmp);
+ }
+ actual(res) = actual(x);
+ StyleCopy(save_style(res), save_style(x));
+ break;
+
+
+ default:
+
+ assert1(FALSE, "CopyObject:", Image(type(x)));
+ res = nilobj;
+ break;
+
+ } /* end switch */
+ if( pos == no_fpos ) FposCopy(fpos(res), fpos(x));
+ else FposCopy(fpos(res), *pos);
+ debug1(DOS, DD, "] CopyObject returning %s", EchoObject(res));
+ return res;
+ } /* end CopyObject */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT InsertObject(OBJECT x, OBJECT *ins, STYLE *style) */
+ /* */
+ /* Search through manifested object x for an ACAT where ins may be */
+ /* attached. If successful, set *ins to nilobj after the attachment. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT InsertObject(OBJECT x, OBJECT *ins, STYLE *style)
+ { OBJECT link, y, g, res;
+ debug2(DOS, DDD, "InsertObject(%s, %s)", EchoObject(x), EchoObject(*ins));
+ switch( type(x) )
+ {
+ case WORD:
+ case QWORD:
+
+ New(res, ACAT);
+ FposCopy(fpos(res), fpos(x));
+ ReplaceNode(res, x);
+ Link(res, x);
+ StyleCopy(save_style(res), *style);
+ adjust_cat(res) = padjust(*style);
+ res = InsertObject(res, ins, style);
+ break;
+
+
+ case NULL_CLOS:
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+ case HEAD:
+ case CROSS:
+ case FORCE_CROSS:
+ case PAGE_LABEL:
+ case CLOSURE:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case HSPAN:
+ case VSPAN:
+
+ res = x;
+ break;
+
+
+ case HCAT:
+ case VCAT:
+ case COL_THR:
+ case ROW_THR:
+ case SPLIT:
+
+ for( link = Down(x); link != x && *ins != nilobj; link = NextDown(link) )
+ { Child(y, link);
+ y = InsertObject(y, ins, style);
+ }
+ res = x;
+ break;
+
+
+ case ONE_COL:
+ case ONE_ROW:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case ROTATE:
+ case BACKGROUND:
+ case SCALE:
+ case KERN_SHRINK:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+
+ Child(y, LastDown(x));
+ y = InsertObject(y, ins, style);
+ res = x;
+ break;
+
+
+ case ACAT:
+
+ New(g, GAP_OBJ);
+ SetGap(gap(g), FALSE, FALSE, TRUE, FIXED_UNIT, EDGE_MODE, 0);
+ hspace(g) = vspace(g) = 0;
+ underline(g) = UNDER_OFF;
+ Link(Down(x), g);
+ Link(Down(x), *ins);
+ underline(*ins) = UNDER_OFF;
+ *ins = nilobj;
+ res = x;
+ break;
+
+
+ default:
+
+ assert1(FALSE, "InsertObject:", Image(type(x)));
+ res = x;
+ break;
+
+ }
+ debug2(DOS, DDD, "InsertObject returning (%s) %s",
+ *ins == nilobj ? "success" : "failure", EchoObject(res));
+ return res;
+ } /* end InsertObject */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Meld(x, y) */
+ /* */
+ /* Return the meld of x with y. */
+ /* */
+ /*****************************************************************************/
+ #define NO_DIR 0
+ #define X_DIR 1
+ #define Y_DIR 2
+ #define XY_DIR 3
+ #define MAX_MELD 32
+
+ OBJECT Meld(OBJECT x, OBJECT y)
+ { OBJECT res;
+ char table[MAX_MELD][MAX_MELD], dir[MAX_MELD][MAX_MELD];
+ OBJECT xcomp[MAX_MELD], ycomp[MAX_MELD];
+ OBJECT xgaps[MAX_MELD], ygaps[MAX_MELD];
+ BOOLEAN is_equal;
+ OBJECT link, z, g; BOOLEAN jn;
+ int xlen, ylen, xi, yi;
+ debug2(DOS, D, "Meld(%s, %s)", EchoObject(x), EchoObject(y));
+ assert(type(x) == ACAT, "Meld: type(x) != ACAT");
+ assert(type(y) == ACAT, "Meld: type(y) != ACAT");
+
+ /* initialize xcomp, xgaps, xlen */
+ debug0(DOS, DD, " initializing xcomp[]");
+ xlen = 0;
+ xcomp[xlen] = nilobj;
+ xlen++;
+ g = nilobj;
+ FirstDefinite(x, link, z, jn);
+ while( link != x )
+ { if( xlen >= MAX_MELD )
+ Error(7, 1, "%s: maximum paragraph length (%d) exceeded", FATAL, &fpos(x),
+ KW_MELD, MAX_MELD-1);
+ xcomp[xlen] = z;
+ xgaps[xlen] = g;
+ debug3(DOS, DD, " initializing xcomp[%d] to %s %s",
+ xlen, Image(type(z)), EchoObject(z));
+ xlen++;
+ NextDefiniteWithGap(x, link, z, g, jn)
+ }
+
+ /* initialize ycomp, ygaps, ylen */
+ debug0(DOS, DD, " initializing ycomp[]");
+ ylen = 0;
+ ycomp[ylen] = nilobj;
+ ylen++;
+ g = nilobj;
+ FirstDefinite(y, link, z, jn);
+ while( link != y )
+ { if( ylen >= MAX_MELD )
+ Error(7, 1, "%s: maximum paragraph length (%d) exceeded", FATAL, &fpos(y),
+ KW_MELD, MAX_MELD-1);
+ ycomp[ylen] = z;
+ ygaps[ylen] = g;
+ debug3(DOS, DD, " initializing ycomp[%d] to %s %s",
+ ylen, Image(type(z)), EchoObject(z));
+ ylen++;
+ NextDefiniteWithGap(y, link, z, g, jn)
+ }
+
+ /* initialize table and dir */
+ debug0(DOS, DD, " initializing table[]");
+ table[0][0] = 0;
+ dir[0][0] = NO_DIR;
+ for( xi = 1; xi < xlen; xi++ )
+ { table[xi][0] = 0;
+ dir[xi][0] = X_DIR;
+ }
+ for( yi = 1; yi < ylen; yi++ )
+ { table[0][yi] = 0;
+ dir[0][yi] = Y_DIR;
+ }
+ for( xi = 1; xi < xlen; xi++ )
+ {
+ for( yi = 1; yi < ylen; yi++ )
+ {
+ if( is_word(type(xcomp[xi])) )
+ { is_equal = is_word(type(ycomp[yi])) &&
+ StringEqual(string(xcomp[xi]), string(ycomp[yi]));
+ }
+ else
+ {
+ is_equal = (type(xcomp[xi]) == type(ycomp[yi]));
+ }
+ if( is_equal )
+ {
+ table[xi][yi] = 1 + table[xi - 1][yi - 1];
+ dir[xi][yi] = XY_DIR;
+ debug3(DOS, DD, " assigning (XY) table[%d][%d] = %d", xi, yi,
+ table[xi][yi]);
+ }
+ else if( table[xi - 1][yi] > table[xi][yi - 1] )
+ {
+ table[xi][yi] = table[xi - 1][yi];
+ dir[xi][yi] = X_DIR;
+ debug3(DOS, DD, " assigning (X) table[%d][%d] = %d", xi, yi,
+ table[xi][yi]);
+ }
+ else
+ {
+ table[xi][yi] = table[xi][yi - 1];
+ dir[xi][yi] = Y_DIR;
+ debug3(DOS, DD, " assigning (Y) table[%d][%d] = %d", xi, yi,
+ table[xi][yi]);
+ }
+ }
+ }
+
+ /* traverse table from [xlen-l][ylen-1] back to [0][0], finding who's in */
+ debug0(DOS, DD, " traversing table[]");
+ New(res, ACAT);
+ StyleCopy(save_style(res), save_style(x));
+ for( xi = xlen - 1, yi = ylen - 1; dir[xi][yi] != NO_DIR; )
+ {
+ switch( dir[xi][yi] )
+ {
+ case XY_DIR:
+
+ debug3(DOS, DD, " at table[%d][%d] (XY) linking %s",
+ xi, yi, EchoObject(xcomp[xi]));
+ Link(Down(res), xcomp[xi]);
+ g = xgaps[xi];
+ xi--;
+ yi--;
+ break;
+
+
+ case Y_DIR:
+
+ debug3(DOS, DD, " at table[%d][%d] (ydec) linking %s",
+ xi, yi, EchoObject(ycomp[yi]));
+ Link(Down(res), ycomp[yi]);
+ g = ygaps[yi];
+ yi--;
+ break;
+
+
+ case X_DIR:
+
+ debug3(DOS, DD, " at table[%d][%d] (xdec) linking %s",
+ xi, yi, EchoObject(xcomp[xi]));
+ Link(Down(res), xcomp[xi]);
+ g = xgaps[xi];
+ xi--;
+ }
+
+ /* add gap if not last time; either g or one we make up */
+ if( dir[xi][yi] != NO_DIR )
+ {
+ if( g == nilobj )
+ {
+ OBJECT tmp;
+ New(g, GAP_OBJ);
+ hspace(g) = 1; vspace(g) = 0;
+ FposCopy(fpos(g), *no_fpos);
+ SetGap(gap(g), FALSE, FALSE, TRUE, FIXED_UNIT, EDGE_MODE,
+ width(space_gap(save_style(res))));
+ tmp = MakeWord(WORD, AsciiToFull("1s"), &fpos(g));
+ Link(g, tmp);
+ Link(Down(res), g);
+ }
+ else
+ {
+ assert(Up(g) == LastUp(g), "Meld: g!" );
+ Link(Down(res), g);
+ }
+ }
+ }
+
+ debug1(DOS, D, "Meld returning %s", EchoObject(res));
+ return res;
+ }
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z08.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z08.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z08.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,2068 ----
+ /*@z08.c:Object Manifest:ReplaceWithSplit()@**********************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z08.c */
+ /* MODULE: Object Manifest */
+ /* EXTERNS: Manifest() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define line_breaker(g) \
+ (vspace(g) > 0 || (units(gap(g)) == FRAME_UNIT && width(gap(g)) > FR))
+
+
+ /*****************************************************************************/
+ /* */
+ /* static SetUnderline(x) */
+ /* */
+ /* Set underline() flags in object x to UNDER_ON as appropriate. */
+ /* */
+ /*****************************************************************************/
+
+ static void SetUnderline(OBJECT x)
+ { OBJECT y, link;
+ debug2(DOM, DD, " Manifest underlining %s %s", Image(type(x)),EchoObject(x));
+ if( type(x) == ACAT )
+ { for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ SetUnderline(y);
+ }
+ }
+ debug3(DOM, DDD, " SetUnderline underline() := %s for %s %s",
+ "UNDER_ON", Image(type(x)), EchoObject(x));
+ underline(x) = UNDER_ON;
+ } /* end SetUnderline */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static ReplaceWithSplit(x, bthr, fthr) */
+ /* */
+ /* Replace object x with a SPLIT object, if threads for this object are */
+ /* requested by bthr and/or fthr. */
+ /* */
+ /*****************************************************************************/
+
+ #define ReplaceWithSplit(x, bthr, fthr) \
+ if( bthr[ROWM] || bthr[COLM] || fthr[ROWM] || fthr[COLM] ) \
+ x = insert_split(x, bthr, fthr)
+
+ static OBJECT insert_split(OBJECT x, OBJECT bthr[2], OBJECT fthr[2])
+ { OBJECT res, new_op; int dim;
+ debug1(DOM, DD, "ReplaceWithSplit(%s, -)", EchoObject(x));
+ assert( type(x) != SPLIT, "ReplaceWithSplit: type(x) already SPLIT!" );
+ New(res, SPLIT);
+ FposCopy(fpos(res), fpos(x));
+ ReplaceNode(res, x);
+ for( dim = COLM; dim <= ROWM; dim++ )
+ { if( bthr[dim] || fthr[dim] )
+ {
+ debug0(DGP, D, " calling New(thread) from Manifest now");
+ New(new_op, dim == COLM ? COL_THR : ROW_THR);
+ thr_state(new_op) = NOTSIZED;
+ fwd(new_op, 1-dim) = 0; /* will hold max frame_size */
+ back(new_op, 1-dim) = 0; /* will hold max frame_origin */
+ FposCopy(fpos(new_op), fpos(x));
+ Link(res, new_op); Link(new_op, x);
+ if( bthr[dim] ) Link(bthr[dim], new_op);
+ if( fthr[dim] ) Link(fthr[dim], new_op);
+ }
+ else Link(res, x);
+ }
+
+ debug1(DOM, DD, "ReplaceWithSplit returning %s", EchoObject(res));
+ return res;
+ } /* end insert_split */
+
+ /*@::ReplaceWithTidy()@*******************************************************/
+ /* */
+ /* OBJECT ReplaceWithTidy(x, one_word) */
+ /* */
+ /* Replace object x with a tidier version in which juxtapositions are */
+ /* folded. If this is not possible, return the original object. */
+ /* */
+ /* If one_word is TRUE, the result is to be a single QWORD with inter- */
+ /* word spaces converted to single space characters. Otherwise an ACAT */
+ /* is the preferred result. */
+ /* */
+ /* *** Meaning changed, now interword spaces are converted to the same */
+ /* number of spaces to assist construction of sorting keys. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT ReplaceWithTidy(OBJECT x, BOOLEAN one_word)
+ { static FULL_CHAR buff[MAX_BUFF]; /* the growing current word */
+ static int buff_len; /* length of current word */
+ static FILE_POS buff_pos; /* filepos of current word */
+ static unsigned buff_typ; /* WORD or QWORD of current */
+ OBJECT link, y, tmp, res; /* temporaries */
+ int i;
+ debug2(DOM, DD, "ReplaceWithTidy(%s, %s)", EchoObject(x), bool(one_word));
+ switch( type(x) )
+ {
+ case ACAT:
+
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == ACAT )
+ { tmp = Down(y); TransferLinks(tmp, y, link);
+ DisposeChild(link); link = PrevDown(tmp);
+ }
+ }
+ res = nilobj; buff_len = 0; buff_typ = WORD;
+ FposCopy(buff_pos, fpos(x));
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( is_word(type(y)) )
+ { if( buff_len + StringLength(string(y)) >= MAX_BUFF )
+ Error(8, 1, "word is too long", WARN, &fpos(y));
+ else
+ { if( buff_len == 0 ) FposCopy(buff_pos, fpos(y));
+ StringCopy(&buff[buff_len], string(y));
+ buff_len += StringLength(string(y));
+ if( type(y) == QWORD ) buff_typ = QWORD;
+ }
+ }
+ else if( type(y) == GAP_OBJ )
+ { if( Down(y) != y || hspace(y) + vspace(y) > 0 )
+ { if( one_word )
+ { if( buff_len + hspace(y) + vspace(y) >= MAX_BUFF )
+ Error(8, 2, "word is too long", WARN, &fpos(y));
+ else
+ { for( i = 0; i < hspace(y) + vspace(y); i++ )
+ { StringCopy(&buff[buff_len], AsciiToFull(" "));
+ buff_len++;
+ }
+ buff_typ = QWORD;
+ }
+ }
+ else
+ { tmp = MakeWord(buff_typ, buff, &buff_pos);
+ buff_len = 0; buff_typ = WORD;
+ if( res == nilobj )
+ { New(res, ACAT);
+ FposCopy(fpos(res), fpos(x));
+ }
+ Link(res, tmp); Link(res, y);
+ }
+ }
+ }
+ else /* error */
+ { if( res != nilobj ) DisposeObject(res);
+ debug0(DOM, DD, "ReplaceWithTidy returning unchanged");
+ return x;
+ }
+ }
+ tmp = MakeWord(buff_typ, buff, &buff_pos);
+ if( res == nilobj ) res = tmp;
+ else Link(res, tmp);
+ ReplaceNode(res, x); DisposeObject(x);
+ debug1(DOM, DD, "ReplaceWithTidy returning %s", EchoObject(res));
+ return res;
+
+
+ case WORD:
+ case QWORD:
+
+ debug1(DOM, DD, "ReplaceWithTidy returning %s", EchoObject(x));
+ return x;
+
+
+ default:
+
+ debug0(DOM, DD, "ReplaceWithTidy returning unchanged");
+ return x;
+ }
+ } /* end ReplaceWithTidy */
+
+
+ /*@::GetScaleFactor()@********************************************************/
+ /* */
+ /* static float GetScaleFactor(x) */
+ /* */
+ /* Find a scale factor in object x and return it as a float, after checks. */
+ /* */
+ /*****************************************************************************/
+
+ static float GetScaleFactor(OBJECT x)
+ { float scale_factor;
+ if( !is_word(type(x)) )
+ { Error(8, 3, "replacing invalid scale factor by 1.0", WARN, &fpos(x));
+ scale_factor = 1.0;
+ }
+ else if( sscanf( (char *) string(x), "%f", &scale_factor) != 1 )
+ { Error(8, 4, "replacing invalid scale factor %s by 1.0",
+ WARN, &fpos(x), string(x));
+ scale_factor = 1.0;
+ }
+ else if( scale_factor < 0.01 )
+ { Error(8, 5, "replacing undersized scale factor %s by 1.0",
+ WARN, &fpos(x), string(x));
+ scale_factor = 1.0;
+ }
+ else if( scale_factor > 100 )
+ { Error(8, 6, "replacing oversized scale factor %s by 1.0",
+ WARN, &fpos(x), string(x));
+ scale_factor = 1.0;
+ }
+ return scale_factor;
+ } /* GetScaleFactor */
+
+
+ static OBJECT nbt[2] = { nilobj, nilobj }; /* constant nilobj threads */
+ static OBJECT nft[2] = { nilobj, nilobj }; /* constant nilobj threads */
+ static OBJECT ntarget = nilobj; /* constant nilobj target */
+ static OBJECT nenclose = nilobj; /* constant nilobj enclose */
+
+
+ /*@::ManifestCat@*************************************************************/
+ /* */
+ /* OBJECT ManifestCat(x,env,style,bthr, fthr, target, crs, ok, need_expand, */
+ /* enclose, fcr) */
+ /* */
+ /* This procedure implements Manifest (see below) when x is HCAT or VCAT. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT ManifestCat(OBJECT x, OBJECT env, STYLE *style, OBJECT bthr[2],
+ OBJECT fthr[2], OBJECT *target, OBJECT *crs, BOOLEAN ok, BOOLEAN need_expand,
+ OBJECT *enclose, BOOLEAN fcr)
+ { OBJECT bt[2], ft[2], y, link, gaplink, g, first_bt, last_ft, z;
+ int par, perp;
+ unsigned res_inc; BOOLEAN still_backing;
+ STYLE new_style;
+ debug1(DOM, DD, "[ ManifestCat(%s)", EchoObject(x));
+
+ StyleCopy(new_style, *style);
+ if( type(x) == HCAT )
+ { par = ROWM;
+ adjust_cat(x) = hadjust(*style);
+ hadjust(new_style) = FALSE;
+ }
+ else
+ { par = COLM;
+ adjust_cat(x) = vadjust(*style);
+ vadjust(new_style) = FALSE;
+ }
+ perp = 1 - par;
+ link = Down(x);
+ gaplink = NextDown(link);
+ assert( link!=x && gaplink!=x, "Manifest/VCAT: less than two children!" );
+ Child(y, link); Child(g, gaplink);
+
+ /* set bt and ft threads for y */
+ bt[perp] = bthr[perp];
+ ft[perp] = fthr[perp];
+ if( bthr[par] ) { New(first_bt, THREAD); }
+ else first_bt = nilobj;
+ bt[par] = first_bt;
+ if( join(gap(g)) ) { New(ft[par], THREAD); }
+ else ft[par] = nilobj;
+ still_backing = first_bt != nilobj;
+
+ /* manifest y and insinuate any cross-references */
+ y = Manifest(y, env, &new_style, bt, ft, target, crs, ok, FALSE, enclose, fcr);
+ if( type(x) == VCAT && ok && *crs != nilobj )
+ { debug1(DCR, DD, " insinuating %s", EchoObject(*crs));
+ TransferLinks(Down(*crs), *crs, link);
+ DisposeObject(*crs);
+ *crs = nilobj;
+ }
+
+ /* manifest the remaining children */
+ while( g != nilobj )
+ {
+ /* manifest the gap object, store it in gap(g), add perp threads */
+ assert( type(g) == GAP_OBJ, "Manifest/VCAT: type(g) != GAP_OBJECT!" );
+ assert( Down(g) != g, "Manifest/VCAT: GAP_OBJ has no child!" );
+ Child(z, Down(g));
+ debug1(DOM, DD, "manifesting gap, style = %s", EchoStyle(style));
+ z = Manifest(z, env, &new_style, nbt, nft, &ntarget, crs, FALSE, FALSE, enclose, fcr);
+ debug1(DOM, DD, "replacing with tidy, style = %s", EchoStyle(style));
+ z = ReplaceWithTidy(z, FALSE);
+ debug1(DOM, DD, "calling GetGap, style = %s", EchoStyle(style));
+ GetGap(z, style, &gap(g), &res_inc);
+ if( bt[perp] ) Link(bt[perp], g);
+ if( ft[perp] ) Link(ft[perp], g);
+
+ /* find the next child y, and following gap if any */
+ link = NextDown(gaplink);
+ assert( link != x, "Manifest/VCAT: GAP_OBJ is last child!" );
+ Child(y, link);
+ gaplink = NextDown(link);
+ if( gaplink == x ) g = nilobj;
+ else Child(g, gaplink);
+
+ /* set bt and ft threads for y */
+ last_ft = ft[par];
+ if( ft[par] ) { New(bt[par], THREAD); } else bt[par] = nilobj;
+ if( g != nilobj )
+ { if( join(gap(g)) ) { New(ft[par], THREAD); } else ft[par] = nilobj;
+ }
+ else
+ {
+ if( fthr[par] ) { New(ft[par], THREAD); } else ft[par] = nilobj;
+ }
+
+ /* manifest y and insinuate any cross references */
+ y = Manifest(y, env, &new_style, bt, ft, target, crs, ok, FALSE, enclose, fcr);
+ if( type(x) == VCAT && ok && *crs != nilobj )
+ { debug1(DCR, DD, " insinuating %s", EchoObject(*crs));
+ TransferLinks(Down(*crs), *crs, link);
+ DisposeObject(*crs);
+ *crs = nilobj;
+ }
+
+ if( bt[par] ) /* then thread lists last_ft and bt[par] must merge */
+ { OBJECT llink, rlink, lthread, rthread;
+ BOOLEAN goes_through;
+ assert( Down(bt[par]) != bt[par], "Manifest: bt[par] no children!" );
+ assert( last_ft!=nilobj && Down(last_ft)!=last_ft, "Manifest:last_ft!" );
+
+ /* check whether marks run right through y in par direction */
+ goes_through = FALSE;
+ if( ft[par] )
+ { assert( Down(ft[par]) != ft[par], "Manifest: ft[par] child!" );
+ Child(lthread, LastDown(bt[par]));
+ Child(rthread, LastDown(ft[par]));
+ goes_through = lthread == rthread;
+ }
+
+ /* merge the thread lists */
+ llink = Down(last_ft); rlink = Down(bt[par]);
+ while( llink != last_ft && rlink != bt[par] )
+ { Child(lthread, llink);
+ Child(rthread, rlink);
+ assert( lthread != rthread, "Manifest: lthread == rthread!" );
+ MergeNode(lthread, rthread);
+ llink = NextDown(llink);
+ rlink = NextDown(rlink);
+ }
+
+ /* attach leftover back threads to first_bt if required */
+ if( rlink != bt[par] )
+ {
+ if( still_backing ) TransferLinks(rlink, bt[par], first_bt);
+ }
+ DisposeObject(bt[par]);
+
+ /* attach leftover forward threads to ft[par] if required */
+ if( llink != last_ft )
+ {
+ if( goes_through ) TransferLinks(llink, last_ft, ft[par]);
+ }
+ DisposeObject(last_ft);
+
+ if( !goes_through ) still_backing = FALSE;
+
+ }
+ else still_backing = FALSE;
+
+ } /* end while */
+
+ /* export par threads */
+ if( fthr[par] ) MergeNode(fthr[par], ft[par]);
+ if( bthr[par] ) MergeNode(bthr[par], first_bt);
+ debug0(DOM, DD, "] ManifestCat returning");
+ return x;
+ } /* end ManifestCat */
+
+
+ /*@::ManifestCase@************************************************************/
+ /* */
+ /* OBJECT ManifestCase(x,env,style,bthr,fthr, target, crs, ok, need_expand, */
+ /* enclose, fcr) */
+ /* */
+ /* This procedure implements Manifest (see below) when x is CASE. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT ManifestCase(OBJECT x, OBJECT env, STYLE *style, OBJECT bthr[2],
+ OBJECT fthr[2], OBJECT *target, OBJECT *crs, BOOLEAN ok, BOOLEAN need_expand,
+ OBJECT *enclose, BOOLEAN fcr)
+ { OBJECT y, tag, ylink, yield, ytag, zlink;
+ OBJECT res, z, firsttag, firstres;
+
+ /* make sure left parameter (the tag) is in order */
+ debug0(DOM, DD, " manifesting CASE now");
+ Child(tag, Down(x));
+ debug1(DOM, DD, " manifesting CASE tag %s now", EchoObject(tag));
+ tag = Manifest(tag, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE,
+ &nenclose, fcr);
+ tag = ReplaceWithTidy(tag, FALSE);
+
+ /* make sure the right parameter is an ACAT */
+ Child(y, LastDown(x));
+ if( type(y) == YIELD )
+ { New(z, ACAT);
+ MoveLink(Up(y), z, PARENT);
+ Link(x, z);
+ y = z;
+ }
+ if( type(y) != ACAT )
+ { Error(8, 7, "%s deleted (right parameter is malformed)",
+ WARN, &fpos(y), KW_CASE);
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x); DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ }
+
+ /* hunt through right parameter for res, the selected case */
+ res = nilobj; firsttag = nilobj;
+ for( ylink = Down(y); ylink != y && res == nilobj; ylink = NextDown(ylink) )
+ { Child(yield, ylink);
+ if( type(yield) == GAP_OBJ ) continue;
+ if( type(yield) != YIELD )
+ { Error(8, 8, "%s expected here", WARN, &fpos(yield), KW_YIELD);
+ break;
+ }
+ Child(ytag, Down(yield));
+ ytag = Manifest(ytag, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE,
+ &nenclose, fcr);
+ ytag = ReplaceWithTidy(ytag, FALSE);
+ if( is_word(type(ytag)) )
+ { if( firsttag == nilobj )
+ { firsttag = ytag;
+ Child(firstres, LastDown(yield));
+ }
+ if( (is_word(type(tag)) && StringEqual(string(ytag), string(tag))) ||
+ StringEqual(string(ytag), STR_ELSE) )
+ { Child(res, LastDown(yield));
+ break;
+ }
+ }
+ else if( type(ytag) == ACAT )
+ { z = ytag;
+ for( zlink = Down(z); zlink != z; zlink = NextDown(zlink) )
+ { Child(ytag, zlink);
+ if( type(ytag) == GAP_OBJ ) continue;
+ if( !is_word(type(ytag)) )
+ { Error(8, 9, "error in left parameter of %s",
+ WARN, &fpos(ytag), KW_YIELD);
+ break;
+ }
+ if( firsttag == nilobj )
+ { firsttag = ytag;
+ Child(firstres, LastDown(yield));
+ }
+ if( (is_word(type(tag)) && StringEqual(string(ytag), string(tag)))
+ || StringEqual(string(ytag), STR_ELSE) )
+ { Child(res, LastDown(yield));
+ break;
+ }
+ }
+ }
+ else Error(8, 10, "error in left parameter of %s",
+ WARN, &fpos(ytag), KW_YIELD);
+ }
+ if( res == nilobj )
+ { if( firsttag != nilobj )
+ { Error(8, 11, "replacing unknown %s option %s by %s",
+ WARN, &fpos(tag), KW_CASE, string(tag), string(firsttag));
+ res = firstres;
+ debug1(DGP, D, " res = %s", EchoObject(res));
+ }
+ else
+ { Error(8, 12, "%s deleted (choice %s unknown)",
+ WARN, &fpos(tag), KW_CASE, string(tag));
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x); DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ }
+ }
+
+ /* now manifest the result and replace x with it */
+ DeleteLink(Up(res));
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ x = Manifest(res, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ } /* ManifestCase */
+
+
+ /*@::ManifestTg@**************************************************************/
+ /* */
+ /* OBJECT ManifestTg(x,env,style,bthr, fthr, target, crs, ok, need_expand, */
+ /* enclose, fcr) */
+ /* */
+ /* This procedure implements Manifest (see below) when x is TAGGED. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT ManifestTg(OBJECT x, OBJECT env, STYLE *style, OBJECT bthr[2],
+ OBJECT fthr[2], OBJECT *target, OBJECT *crs, BOOLEAN ok, BOOLEAN need_expand,
+ OBJECT *enclose, BOOLEAN fcr)
+ { OBJECT y, tag, z;
+
+ /* make sure first argument is a cross-reference */
+ assert( Down(x) != x && NextDown(Down(x)) != x &&
+ NextDown(NextDown(Down(x))) == x, "Manifest TAGGED: children!" );
+ Child(y, Down(x));
+ if( !is_cross(type(y)) )
+ {
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, TRUE);
+ if( !is_cross(type(y)) )
+ { Error(8, 13, "left parameter of %s is not a cross reference",
+ WARN, &fpos(y), KW_TAGGED);
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x); DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ }
+ }
+
+ /* make sure the arguments of the cross-reference are OK */
+ Child(z, Down(y));
+ if( type(z) != CLOSURE )
+ { Error(8, 14, "left parameter of %s must be a symbol",
+ WARN, &fpos(y), KW_TAGGED);
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x); DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ }
+ if( !has_tag(actual(z)) )
+ { Error(8, 15, "symbol %s not allowed here (it has no %s)",
+ WARN, &fpos(z), SymName(actual(z)), KW_TAG);
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x); DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ }
+ Child(z, NextDown(Down(y)));
+ z = Manifest(z, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ z = ReplaceWithTidy(z, FALSE);
+ if( is_word(type(z)) && StringEqual(string(z), KW_PRECEDING) )
+ cross_type(y) = CROSS_PREC;
+ else if( is_word(type(z)) && StringEqual(string(z), KW_FOLLOWING) )
+ cross_type(y) = CROSS_FOLL;
+ else if( is_word(type(z)) && StringEqual(string(z), KW_FOLL_OR_PREC) )
+ cross_type(y) = CROSS_FOLL_OR_PREC;
+ else
+ { Error(8, 16, "%s, %s or %s expected in left parameter of %s",
+ WARN, &fpos(z), KW_PRECEDING, KW_FOLLOWING, KW_FOLL_OR_PREC, KW_TAGGED);
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x); DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ }
+
+ /* make sure second argument (the new key) is ok */
+ Child(tag, LastDown(x));
+ tag = Manifest(tag, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ tag = ReplaceWithTidy(tag, TRUE); /* && */
+ if( !is_word(type(tag)) )
+ { Error(8, 17, "right parameter of %s must be a simple word",
+ WARN, &fpos(tag), KW_TAGGED);
+ ifdebug(DOM, DD, DebugObject(tag));
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x); DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ }
+
+ /* assemble insinuated cross reference which replaces x */
+ ReplaceNode(tag, z);
+ DisposeObject(z);
+ ReplaceNode(y, x);
+ DisposeObject(x);
+ x = y;
+ ReplaceWithSplit(x, bthr, fthr);
+ debug1(DCR, DD, " tagged manifesting %s", EchoObject(x));
+ return x;
+ } /* end ManifestTg */
+
+
+ /*@::ManifestCl@**************************************************************/
+ /* */
+ /* OBJECT ManifestCl(x,env,style,bthr, fthr, target, crs, ok, need_expand, */
+ /* enclose, fcr) */
+ /* */
+ /* This procedure implements Manifest (see below) when x is CLOSURE. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT ManifestCl(OBJECT x, OBJECT env, STYLE *style, OBJECT bthr[2],
+ OBJECT fthr[2], OBJECT *target, OBJECT *crs, BOOLEAN ok, BOOLEAN need_expand,
+ OBJECT *enclose, BOOLEAN fcr)
+ { OBJECT y, link, sym, res_env, hold_env, hold_env2, z, newz, command;
+ BOOLEAN symbol_free;
+
+ sym = actual(x);
+ StyleCopy(save_style(x), *style);
+ debugcond2(DOM, D, StringEqual(SymName(sym), "@Section"),
+ "manifesting %s at %s", SymName(sym), EchoFilePos(&fpos(x)));
+ debug1(DOM, DD, " [ manifesting closure %s", SymName(sym));
+
+ /* enclose, if required */
+ if( *enclose != nilobj && (actual(x)==GalleySym || actual(x)==ForceGalleySym) )
+ { OBJECT sym, par;
+ ReplaceNode(*enclose, x);
+ Child(sym, Down(*enclose));
+ Child(par, Down(sym));
+ DisposeChild(Down(par));
+ Link(par, x);
+ x = *enclose;
+ *enclose = nilobj;
+ debug1(DHY, DD, " Manifest/enclose: %s", EchoObject(x));
+ debug1(DOM, DD, " Manifest/enclose: %s", EchoObject(x));
+ x = Manifest(x, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ debug0(DOM, DD, " ] returning from manifesting closure (enclose)");
+ return x;
+ }
+
+ /* expand parameters where possible, and find if they are all free */
+ symbol_free = TRUE;
+ debugcond1(DOM, DD, indefinite(sym), " freeing %s", EchoObject(x));
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) == PAR, "Manifest/CLOSURE: type(y) != PAR!" );
+ Child(z, Down(y));
+
+ /* try to evaluate the actual parameter z */
+ if( !is_word(type(z)) && !has_par(actual(y)) )
+ {
+ if( is_tag(actual(y)) || is_key(actual(y)) )
+ { z = Manifest(z, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ z = ReplaceWithTidy(z, TRUE);
+ if( !is_word(type(z)) )
+ {
+ debug2(ANY, D, "z = %s %s", Image(type(z)), EchoObject(z));
+ Error(8, 41, "this %s is not a sequence of one or more words", FATAL,
+ &fpos(y), SymName(actual(y)));
+ }
+ }
+ else if( type(z) == NEXT )
+ { z = Manifest(z, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ z = ReplaceWithTidy(z, FALSE);
+ }
+ else if( type(z) == CLOSURE && is_par(type(actual(z))) )
+ {
+ /* see whether z would come to something simple if expanded */
+ newz = ParameterCheck(z, env);
+ debugcond2(DOM, DD, indefinite(sym), " ParameterCheck(%s, env) = %s",
+ EchoObject(z), EchoObject(newz));
+ if( newz != nilobj )
+ { ReplaceNode(newz, z);
+ DisposeObject(z);
+ z = newz;
+ }
+ }
+ }
+
+ /* now check z to see whether it is either a word or and ACAT of words */
+ /* ***
+ if( type(z) == ACAT )
+ { int i = 0; OBJECT t, tlink, g;
+ tlink = Down(z);
+ for( ; tlink != z && symbol_free; tlink = NextDown(tlink), i++ )
+ { Child(t, tlink);
+ switch( type(t) )
+ {
+ case WORD:
+ case QWORD: if( i > 20 ) symbol_free = FALSE;
+ break;
+
+ case GAP_OBJ: if( Down(t) != t )
+ { Child(g, Down(t));
+ if( !is_word(type(g)) ) symbol_free = FALSE;
+ }
+ break;
+
+ default: symbol_free = FALSE;
+ break;
+
+ }
+ }
+ }
+ else
+ *** */
+
+ if( !is_word(type(z)) )
+ { symbol_free = FALSE;
+ }
+ }
+ debugcond2(DOM, DD, indefinite(sym)," s_f = %s, x = %s",
+ bool(symbol_free), EchoObject(x));
+
+ /* if all parameters are free of symbols, optimize environment */
+ if( symbol_free && imports(sym) == nilobj && enclosing(sym) != StartSym )
+ { y = SearchEnv(env, enclosing(sym));
+ if( y != nilobj && type(y) == CLOSURE )
+ { OBJECT prntenv;
+ Parent(prntenv, Up(y));
+ if( type(prntenv) != ENV ) fprintf(stderr, "%s\n", Image(type(prntenv)));
+ assert(type(prntenv) == ENV, "Manifest: prntenv!");
+ if( Down(prntenv) == LastDown(prntenv) )
+ { env = prntenv;
+ }
+ else
+ { debug0(DCR, DDD, "calling SetEnv from Manifest (a)");
+ env = SetEnv(y, nilobj);
+ }
+ New(hold_env2, ACAT); Link(hold_env2, env);
+ }
+ else
+ { /* *** letting this through now
+ if( has_par(enclosing(sym)) )
+ Error(8, 18, "symbol %s used outside %s", WARN, &fpos(x), SymName(sym),
+ SymName(enclosing(sym)));
+ *** */
+ hold_env2 = nilobj;
+ }
+ }
+ else hold_env2 = nilobj;
+
+ debug3(DOM, DD, " expansion: has_target %s, indefinite %s, recursive %s",
+ bool(has_target(sym)), bool(indefinite(sym)), bool(recursive(sym)));
+ if( has_target(sym) && !need_expand )
+ {
+ /* convert symbols with targets to unsized galleys */
+ OBJECT hd;
+ New(hd, HEAD);
+ FposCopy(fpos(hd), fpos(x));
+ actual(hd) = sym;
+ limiter(hd) = opt_components(hd) = opt_constraints(hd) = nilobj;
+ gall_dir(hd) = horiz_galley(sym);
+ ready_galls(hd) = nilobj;
+ must_expand(hd) = TRUE;
+ sized(hd) = FALSE;
+ ReplaceNode(hd, x);
+ Link(hd, x);
+ AttachEnv(env, x);
+ SetTarget(hd);
+ enclose_obj(hd) = (has_enclose(sym) ? BuildEnclose(hd) : nilobj);
+ headers(hd) = dead_headers(hd) = nilobj;
+ x = hd;
+ threaded(x) = bthr[COLM] != nilobj || fthr[COLM] != nilobj;
+ ReplaceWithSplit(x, bthr, fthr);
+ }
+ else if(
+ *target == sym ? (*target = nilobj, TRUE) :
+ need_expand ? TRUE :
+ uses_galley(sym) && !recursive(sym) ? TRUE :
+ !indefinite(sym) && !recursive(sym) ? TRUE :
+ indefinite(sym) && *target != nilobj ? SearchUses(sym, *target)
+ : FALSE
+ )
+ {
+ /* expand the closure and manifest the result */
+ debug1(DOM, DD, "expanding; style: %s", EchoStyle(style));
+ debug0(DCE, DD, " calling ClosureExpand from Manifest/CLOSURE");
+ /* *** now requesting cross refs always, not only if ok
+ x = ClosureExpand(x, env, ok, crs, &res_env);
+ *** */
+ x = ClosureExpand(x, env, TRUE, crs, &res_env);
+ New(hold_env, ACAT); Link(hold_env, res_env);
+ debug1(DOM, DD, "recursive call; style: %s", EchoStyle(style));
+ if( type(x) == FILTERED )
+ { assert( type(sym) == RPAR, "ManifestCl/filtered: type(sym)!" );
+ assert( filter(enclosing(sym)) != nilobj, "ManifestCl filter-encl!" );
+ New(command, CLOSURE);
+ FposCopy(fpos(command), fpos(x));
+ actual(command) = filter(enclosing(sym));
+ FilterSetFileNames(x);
+ command = Manifest(command,env,style,nbt,nft,&ntarget,crs,FALSE,FALSE, &nenclose, fcr);
+ command = ReplaceWithTidy(command, TRUE);
+ if( !is_word(type(command)) )
+ Error(8, 19, "filter parameter of %s symbol is not simple",
+ FATAL, &fpos(command), SymName(enclosing(sym)));
+ y = FilterExecute(x, string(command), res_env);
+ debug2(DFH, D, "after \"%s\", will manifest result with style %s",
+ string(command), EchoStyle(style));
+ DisposeObject(command);
+ ReplaceNode(y, x);
+ DisposeObject(x);
+ x = y;
+ }
+ x = Manifest(x, res_env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ DisposeObject(hold_env);
+ }
+ else
+ {
+ AttachEnv(env, x);
+ threaded(x) = bthr[COLM] != nilobj || fthr[COLM] != nilobj;
+ debug0(DOM, DD, " closure; calling ReplaceWithSplit");
+ ReplaceWithSplit(x, bthr, fthr);
+ }
+ if( hold_env2 != nilobj ) DisposeObject(hold_env2);
+ debug0(DOM, DD, " ] returning from manifesting closure");
+ return x;
+ } /* end ManifestCl */
+
+
+ /*@::Manifest()@**************************************************************/
+ /* */
+ /* OBJECT Manifest(x, env, style, bthr, fthr, target, crs, ok, need_expand, */
+ /* enclose, fcr) */
+ /* */
+ /* Manifest object x, interpreted in environment env and style style. */
+ /* The result replaces x, and is returned also. */
+ /* The manifesting operation converts x from a pure parse tree object */
+ /* containing closures and no threads, to an object ready for sizing, */
+ /* with fonts propagated to the words, fill styles propagated to the */
+ /* ACATs, and line spacings propagated to all interested parties. */
+ /* All non-recursive, non-indefinite closures are expanded. */
+ /* Threads joining objects on a mark are constructed, and SPLIT objects */
+ /* inserted, so that sizing becomes a trivial operation. */
+ /* */
+ /* Manifest will construct threads and pass them up as children of bthr[] */
+ /* and fthr[] whenever non-nilobj values of these variables are passed in: */
+ /* */
+ /* bthr[COLM] protrudes upwards from x */
+ /* fthr[COLM] protrudes downwards from x */
+ /* bthr[ROWM] protrudes leftwards from x */
+ /* fthr[ROWM] protrudes rightwards from x */
+ /* */
+ /* If *target != nilobj, Manifest will expand indefinite closures leading */
+ /* to the first @Galley lying within an object of type *target. */
+ /* */
+ /* If *target != nilobj and *enclose != nilobj, Manifest will enclose */
+ /* any @Galley or @ForceGalley it comes across in *enclose. */
+ /* */
+ /* The env parameter contains the environment in which x is to be */
+ /* evaluated. Environments are shared, so their correct disposal is not */
+ /* simple. The rule is this: the code which creates an environment, or */
+ /* detaches it, is responsible for holding it with a dummy parent until */
+ /* it is no longer required. */
+ /* */
+ /* Some objects x are not "real" in the sense that they do not give rise */
+ /* to rectangles in the final printed document. The left parameter of */
+ /* @Wide and similar operators, and the gap following a concatenation */
+ /* operator, are examples of such non-real objects. The ok flag is true */
+ /* when x is part of a real object. This is needed because some things, */
+ /* such as the insinuation of cross references, the breaking of */
+ /* lines @Break ACAT objects, and conversion to small capitals, only apply */
+ /* to real objects. */
+ /* */
+ /* If *crs != nilobj, it points to a list of indexes to cross-references */
+ /* which are to be insinuated into the manifested form of x if x is real. */
+ /* */
+ /* If need_expand is TRUE it forces closure x to expand. */
+ /* */
+ /* If fcr is TRUE, the objective is to expand until a cross-reference is */
+ /* the result; so expansion will stop at a CROSS or FORCE_CROSS object. */
+ /* */
+ /* A postcondition of Manifest() is that the underline() flag is set to */
+ /* either UNDER_ON or UNDER_OFF in every WORD, every QWORD, and every child */
+ /* of every ACAT, including the gaps. This can be verified by checking */
+ /* that the WORD and QWORD cases set underline() to UNDER_OFF, and the ACAT */
+ /* case sets every child of the ACAT to UNDER_OFF. To see that the correct */
+ /* subset of these flags gets changed to UNDER_ON, consult SetUnderline(). */
+ /* The underline() flag is undefined otherwise, and should have value */
+ /* UNDER_UNDEF. */
+ /* */
+ /*****************************************************************************/
+ #define MAX_DEPTH 1000
+
+ OBJECT Manifest(OBJECT x, OBJECT env, STYLE *style, OBJECT bthr[2],
+ OBJECT fthr[2], OBJECT *target, OBJECT *crs, BOOLEAN ok, BOOLEAN need_expand,
+ OBJECT *enclose, BOOLEAN fcr)
+ { OBJECT bt[2], ft[2], y, link, gaplink, g; register FULL_CHAR *p;
+ OBJECT res, res_env, res_env2, hold_env, hold_env2, z, prev;
+ OBJECT link1, link2, x1, x2, y1, y2;
+ int par, num1, num2; GAP res_gap; unsigned res_inc; STYLE new_style;
+ BOOLEAN done, multiline; FULL_CHAR ch; float scale_factor;
+ static int depth = 0;
+ #if DEBUG_ON
+ static unsigned int debug_type[MAX_DEPTH];
+ static OBJECT debug_actual[MAX_DEPTH];
+ static int debug_lnum[MAX_DEPTH];
+ BOOLEAN eee = (*enclose != nilobj);
+ debug_type[depth] = type(x);
+ debug_lnum[depth] = line_num(fpos(x));
+ if( type(x) == CLOSURE ) debug_actual[depth] = actual(x);
+ depth++;
+ if( depth == MAX_DEPTH )
+ { Error(8, 20, "maximum depth of symbol expansion (%d) reached",
+ WARN, &fpos(x), MAX_DEPTH);
+ Error(8, 21, "the symbols currently being expanded are:", WARN, &fpos(x));
+ while( --depth >= 0 )
+ {
+ Error(8, 22, "at %d: %d %s %s", WARN, &fpos(x), depth, debug_lnum[depth],
+ Image(debug_type[depth]), debug_type[depth] == CLOSURE ?
+ FullSymName(debug_actual[depth], AsciiToFull(".")) : STR_EMPTY);
+ }
+ Error(8, 23, "exiting now", FATAL, &fpos(x));
+ }
+ #else
+ depth++;
+ if( depth == MAX_DEPTH )
+ {
+ Error(8, 40, "maximum depth of symbol expansion (%d) reached",
+ FATAL, &fpos(x), MAX_DEPTH);
+ }
+ #endif
+
+ debug2(DOM, DD, "[Manifest(%s %s )", Image(type(x)), EchoObject(x));
+ debug1(DOM, DD, " environment: %s", EchoObject(env));
+ debug6(DOM, DD, " style: %s; target: %s; threads: %s%s%s%s",
+ EchoStyle(style), SymName(*target),
+ bthr[COLM] ? " up" : "", fthr[COLM] ? " down" : "",
+ bthr[ROWM] ? " left" : "", fthr[ROWM] ? " right" : "");
+ debugcond2(DHY, DD, eee, "[ Manifest(%s, *enclose = %s)",
+ EchoObject(x), EchoObject(*enclose));
+
+ switch( type(x) )
+ {
+
+ case ENV_OBJ:
+
+ debug0(DHY, DD, "[Manifest env_obj:");
+ ifdebug(DHY, DD, DebugObject(x));
+ Child(y, Down(x));
+ Child(res_env, NextDown(Down(x)));
+ assert( type(res_env) == ENV, "Manifest/ENV_OBJ: res_env!");
+ y = Manifest(y, res_env, style, bthr, fthr, target, crs, ok, TRUE, enclose, fcr);
+ /* we always expand children of ENV_OBJ (need_expand == TRUE) */
+ ReplaceNode(y, x);
+ DisposeObject(x);
+ x = y;
+ debug1(DHY, DD, "]Manifest env_obj returning %s", EchoObject(x));
+ break;
+
+
+ case CLOSURE:
+
+ x = ManifestCl(x, env, style, bthr, fthr, target, crs, ok, need_expand, enclose, fcr);
+ break;
+
+
+ case PAGE_LABEL:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, TRUE);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case NULL_CLOS:
+
+ StyleCopy(save_style(x), *style);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case CROSS:
+ case FORCE_CROSS:
+
+ assert( Down(x) != x && LastDown(x) != Down(x), "Manifest: CROSS child!");
+ if( !fcr ) /* stop if fcr, i.e. if purpose was to find a cross-reference */
+ {
+ debug0(DCR, DD, " calling CrossExpand from Manifest/CROSS");
+ Child(y, Down(x));
+ if( type(y) == CLOSURE )
+ {
+ /* *** want cross ref now always, not only if ok
+ x = CrossExpand(x, env, style, ok, crs, &res_env);
+ *** */
+ x = CrossExpand(x, env, style, crs, &res_env);
+ assert( type(x) == CLOSURE, "Manifest/CROSS: type(x)!" );
+ New(hold_env, ACAT); Link(hold_env, res_env);
+ /* expand here (calling Manifest immediately makes unwanted cr) */
+ debug0(DCE, DD, " calling ClosureExpand from Manifest/CROSS");
+ x = ClosureExpand(x, res_env, FALSE, crs, &res_env2);
+ New(hold_env2, ACAT); Link(hold_env2, res_env2);
+ x = Manifest(x, res_env2, style, bthr, fthr, target, crs, ok, TRUE, enclose, fcr);
+ DisposeObject(hold_env);
+ DisposeObject(hold_env2);
+ }
+ else
+ { y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x);
+ DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ }
+ }
+ break;
+
+
+ case WORD:
+ case QWORD:
+
+ if( !ok || *crs == nilobj )
+ { word_font(x) = font(*style);
+ word_colour(x) = colour(*style);
+ word_outline(x) = outline(*style);
+ word_language(x) = language(*style);
+ word_hyph(x) = hyph_style(*style) == HYPH_ON;
+ debug3(DOM, DDD, " manfifest/WORD underline() := %s for %s %s",
+ "UNDER_OFF", Image(type(x)), EchoObject(x));
+ if( small_caps(*style) && ok ) x = MapSmallCaps(x, style);
+ underline(x) = UNDER_OFF;
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+ }
+ New(y, ACAT);
+ FposCopy(fpos(y), fpos(x));
+ ReplaceNode(y, x);
+ Link(y, x); x = y;
+ /* NB NO BREAK! */
+
+
+ case ACAT:
+
+ StyleCopy(save_style(x), *style);
+ adjust_cat(x) = padjust(*style);
+ StyleCopy(new_style, *style);
+ padjust(new_style) = FALSE;
+ assert(Down(x) != x, "Manifest: ACAT!" );
+ link = Down(x); Child(y, link);
+ assert( type(y) != GAP_OBJ, "Manifest ACAT: GAP_OBJ is first!" );
+ multiline = FALSE;
+
+ /* manifest first child and insert any cross references */
+ if( is_word(type(y)) )
+ { word_font(y) = font(*style);
+ word_colour(y) = colour(*style);
+ word_outline(y) = outline(*style);
+ word_language(y) = language(*style);
+ word_hyph(y) = hyph_style(*style) == HYPH_ON;
+ if( small_caps(*style) && ok ) y = MapSmallCaps(y, style);
+ }
+ else y = Manifest(y, env, &new_style, nbt, nft, target, crs, ok, FALSE, enclose, fcr);
+ debug3(DOM, DDD, " manfifest/ACAT1 underline() := %s for %s %s",
+ "UNDER_OFF", Image(type(y)), EchoObject(y));
+ underline(y) = UNDER_OFF;
+ /* ??? if( is_word(type(y)) ) */
+ if( ok && *crs != nilobj )
+ {
+ debug1(DCR, DD, " insinuating %s", EchoObject(*crs));
+ TransferLinks(Down(*crs), *crs, link);
+ DisposeObject(*crs);
+ *crs = nilobj;
+ }
+ prev = y;
+
+ /* manifest subsequent gaps and children */
+ for( gaplink = Down(link); gaplink != x; gaplink = NextDown(link) )
+ {
+ Child(g, gaplink);
+ assert( type(g) == GAP_OBJ, "Manifest ACAT: no GAP_OBJ!" );
+ debug3(DOM, DDD, " manfifest/ACAT2 underline() := %s for %s %s",
+ "UNDER_OFF", Image(type(g)), EchoObject(g));
+ underline(g) = UNDER_OFF;
+ link = NextDown(gaplink);
+ assert( link != x, "Manifest ACAT: GAP_OBJ is last!" );
+ Child(y, link);
+ assert( type(y) != GAP_OBJ, "Manifest ACAT: double GAP_OBJ!" );
+
+ /* manifest the next child */
+ debug1(DOM, DD, " in ACAT (3), style = %s", EchoStyle(style));
+ if( is_word(type(y)) )
+ { word_font(y) = font(*style);
+ word_colour(y) = colour(*style);
+ word_outline(y) = outline(*style);
+ word_language(y) = language(*style);
+ word_hyph(y) = hyph_style(*style) == HYPH_ON;
+ if( small_caps(*style) && ok ) y = MapSmallCaps(y, style);
+ }
+ else y = Manifest(y, env, &new_style, nbt, nft, target, crs, ok, FALSE, enclose, fcr);
+ debug3(DOM, DDD, " manifest/ACAT3 underline() := %s for %s %s",
+ "UNDER_OFF", Image(type(y)), EchoObject(y));
+ underline(y) = UNDER_OFF;
+
+ /* manifest the gap object */
+ if( Down(g) != g )
+ {
+ /* explicit & operator whose value is the child of g */
+ Child(z, Down(g));
+ z = Manifest(z, env, &new_style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ z = ReplaceWithTidy(z, FALSE);
+ GetGap(z, style, &gap(g), &res_inc);
+ vspace(g) = hspace(g) = 0;
+ }
+ else
+ {
+ /* implicit & operator */
+ GapCopy(gap(g), space_gap(*style));
+ switch( space_style(*style) )
+ {
+ case SPACE_LOUT:
+
+ /* usual Lout spacing, the number of white space characters */
+ width(gap(g)) = width(gap(g)) * (vspace(g) + hspace(g));
+ break;
+
+
+ case SPACE_COMPRESS:
+
+ /* either zero or one space */
+ if( vspace(g) + hspace(g) == 0 )
+ { width(gap(g)) = 0;
+ }
+ else
+ { /* else width is like one space, so OK as is */
+ }
+ break;
+
+
+ case SPACE_SEPARATE:
+
+ /* exactly one space always, so do nothing further */
+ break;
+
+
+ case SPACE_TROFF:
+
+ /* Lout spacing plus one extra space for sentence end at eoln */
+ width(gap(g)) = width(gap(g)) * (vspace(g) + hspace(g));
+ debugcond2(DLS, DD, vspace(g) > 0, " prev = %s %s",
+ Image(type(prev)), EchoObject(prev));
+ if( vspace(g) > 0 )
+ {
+ /* set z to the preceding object; may need to search ACATs! */
+ z = prev;
+ while( type(z) == ACAT
+ || type(z) == ONE_COL || type(z) == ONE_ROW
+ || type(z) == HCONTRACT || type(z) == VCONTRACT )
+ { Child(z, LastDown(z));
+ }
+
+ /* if preceding object is a word, check for end sentence */
+ if( is_word(type(z)) )
+ {
+ for( p = string(z); *p != '\0'; p++ );
+ debug4(DLS, DD, " prev = %s, last = %c, LSE = %s, LWES = %s",
+ EchoObject(z), *(p-1), bool(LanguageSentenceEnds[*(p-1)]),
+ bool(LanguageWordEndsSentence(z, FALSE)));
+ if( p != string(z) && LanguageSentenceEnds[*(p-1)]
+ && LanguageWordEndsSentence(z, FALSE) )
+ width(gap(g)) += width(space_gap(*style));
+ }
+ }
+ break;
+
+
+ case SPACE_TEX:
+
+ if( vspace(g) + hspace(g) == 0 )
+ {
+ /* zero spaces gives zero result, as for compress above */
+ width(gap(g)) = 0;
+ }
+ else
+ {
+ /* set z to the preceding object; may need to search ACATs! */
+ z = prev;
+ while( type(z) == ACAT
+ || type(z) == ONE_COL || type(z) == ONE_ROW
+ || type(z) == HCONTRACT || type(z) == VCONTRACT )
+ { Child(z, LastDown(z));
+ }
+
+ /* one extra space if preceding is word ending sentence */
+ if( is_word(type(z)) )
+ {
+ for( p = string(z); *p != '\0'; p++ );
+ debug4(DLS, DD, " prev = %s, last = %c, LSE = %s, LWES = %s",
+ EchoObject(z), *(p-1), bool(LanguageSentenceEnds[*(p-1)]),
+ bool(LanguageWordEndsSentence(z, TRUE)));
+ if( p != string(z) && LanguageSentenceEnds[*(p-1)]
+ && LanguageWordEndsSentence(z, TRUE) )
+ width(gap(g)) += width(space_gap(*style));
+ }
+ }
+ break;
+
+
+ default:
+
+ assert(FALSE, "Manifest: unexpected space_style!");
+ break;
+ }
+ nobreak(gap(g)) = (width(gap(g)) == 0);
+ if( line_breaker(g) && is_definite(type(y)) ) multiline = TRUE;
+ }
+ debug1(DOM, DD, " in ACAT, gap = %s", EchoLength(width(gap(g))));
+
+ /* compress adjacent juxtaposed words of equal font, etc. */
+ if( is_word(type(y)) && width(gap(g)) == 0 && nobreak(gap(g)) &&
+ vspace(g)+hspace(g)==0 &&
+ units(gap(g)) == FIXED_UNIT && mode(gap(g)) == EDGE_MODE &&
+ prev != nilobj && is_word(type(prev)) && !mark(gap(g)) &&
+ word_font(prev) == word_font(y) &&
+ word_colour(prev) == word_colour(y) &&
+ word_outline(prev) == word_outline(y) &&
+ word_language(prev) == word_language(y) )
+ /* no need to compare underline() since both are false */
+ { unsigned typ;
+ assert( underline(prev) == UNDER_OFF, "Manifest/ACAT: underline(prev)!" );
+ assert( underline(y) == UNDER_OFF, "Manifest/ACAT: underline(y)!" );
+ if( StringLength(string(prev))+StringLength(string(y)) >= MAX_BUFF )
+ Error(8, 24, "word %s%s is too long",
+ FATAL, &fpos(prev), string(prev), string(y));
+ z = y;
+ typ = type(prev) == QWORD || type(y) == QWORD ? QWORD : WORD;
+ y = MakeWordTwo(typ, string(prev), string(y), &fpos(prev));
+ word_font(y) = word_font(prev);
+ word_colour(y) = word_colour(prev);
+ word_outline(y) = word_outline(prev);
+ word_language(y) = word_language(prev);
+ word_hyph(y) = word_hyph(prev);
+ underline(y) = UNDER_OFF;
+ debug3(DOM, DDD, " manifest/ACAT4 underline() := %s for %s %s",
+ "UNDER_OFF", Image(type(y)), EchoObject(y));
+ MoveLink(link, y, CHILD);
+ DisposeObject(z);
+ DisposeChild(Up(prev));
+ DisposeChild(gaplink);
+ }
+ prev = y;
+
+ /* insinuate any cross-references */
+ if( ok && *crs != nilobj )
+ {
+ debug1(DCR, DD, " insinuating %s", EchoObject(*crs));
+ TransferLinks(Down(*crs), *crs, link);
+ DisposeObject(*crs);
+ *crs = nilobj;
+ }
+ }
+
+ /* implement FILL_OFF break option if required */
+ /* *** this has been moved now to MinSize, z12.c *** */
+
+ /* ***
+ if( ok && multiline && fill_style(*style) == FILL_UNDEF )
+ Error(8, 25, "missing %s symbol or option", FATAL, &fpos(x), KW_BREAK);
+ if( ok && multiline && fill_style(*style) == FILL_OFF )
+ { OBJECT prev_acat, new_acat; BOOLEAN jn;
+
+ %* compress any ACAT children of ACAT x *%
+ for( link = x; NextDown(link) != x; link = NextDown(link) )
+ { Child(y, NextDown(link));
+ if( type(y) == ACAT )
+ { TransferLinks(Down(y), y, NextDown(link));
+ DisposeChild(Up(y));
+ link = PrevDown(link);
+ }
+ }
+
+ %* do line breaks now *%
+ prev_acat = x;
+ New(x, VCAT);
+ adjust_cat(x) = FALSE;
+ ReplaceNode(x, prev_acat);
+ Link(x, prev_acat);
+ FirstDefinite(prev_acat, link, y, jn);
+ if( link != prev_acat )
+ {
+ NextDefiniteWithGap(prev_acat, link, y, g, jn);
+ while( link != prev_acat )
+ {
+ if( mode(gap(g)) != NO_MODE && line_breaker(g) )
+ { OBJECT glink = PrevDown(Up(g));
+ debug2(DOM, DD, "lines gap just before definite %s at %s",
+ Image(type(y)), EchoFilePos(&fpos(y)));
+ MoveLink(NextDown(glink), x, PARENT);
+ GapCopy(gap(g), line_gap(*style));
+ width(gap(g)) *= find_max(1, vspace(g));
+ New(new_acat, ACAT);
+ adjust_cat(new_acat) = padjust(*style);
+ FposCopy(fpos(new_acat), fpos(g));
+ if( hspace(g) > 0 )
+ { z = MakeWord(WORD, STR_EMPTY, &fpos(g));
+ word_font(z) = font(*style);
+ word_colour(z) = colour(*style);
+ word_outline(z) = outline(*style);
+ word_language(z) = language(*style);
+ word_hyph(z) = hyph_style(*style) == HYPH_ON;
+ underline(z) = UNDER_OFF;
+ Link(new_acat, z);
+ New(z, GAP_OBJ);
+ hspace(z) = hspace(g);
+ vspace(z) = 0;
+ underline(z) = UNDER_OFF;
+ GapCopy(gap(z), space_gap(*style));
+ width(gap(z)) *= hspace(z);
+ Link(new_acat, z);
+ }
+ TransferLinks(NextDown(glink), prev_acat, new_acat);
+ StyleCopy(save_style(new_acat), *style);
+ Link(x, new_acat);
+ prev_acat = new_acat;
+ glink = prev_acat;
+ }
+ NextDefiniteWithGap(prev_acat, link, y, g, jn);
+ }
+ }
+
+ %* remove any singleton ACAT objects under x, if they are VCATs *%
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == ACAT && Down(y) == LastDown(y) )
+ { Child(z, Down(y));
+ if( type(z) == VCAT )
+ { MoveLink(link, z, CHILD);
+ DisposeObject(y);
+ }
+ }
+ }
+ }
+ *** */
+
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case HCAT:
+ case VCAT:
+
+ x = ManifestCat(x, env, style, bthr, fthr, target, crs, ok, need_expand,
+ enclose, fcr);
+ break;
+
+
+ case WIDE:
+ case HIGH:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, FALSE);
+ GetGap(y, style, &res_gap, &res_inc);
+ if( res_inc != GAP_ABS || mode(res_gap) != EDGE_MODE ||
+ units(res_gap) != FIXED_UNIT )
+ { Error(8, 26, "replacing invalid left parameter of %s by 2i",
+ WARN, &fpos(y), Image(type(x)) );
+ units(res_gap) = FIXED_UNIT;
+ width(res_gap) = 2*IN;
+ }
+ SetConstraint(constraint(x), MAX_FULL_LENGTH, width(res_gap), MAX_FULL_LENGTH);
+ DisposeChild(Down(x));
+ goto ETC; /* two cases down from here */
+
+
+ case HSHIFT:
+ case VSHIFT:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, FALSE);
+ GetGap(y, style, &shift_gap(x), &res_inc);
+ shift_type(x) = res_inc;
+ if( mode(shift_gap(x)) != EDGE_MODE ||
+ (units(shift_gap(x))!=FIXED_UNIT && units(shift_gap(x))!=NEXT_UNIT) )
+ { Error(8, 27, "replacing invalid left parameter of %s by +0i",
+ WARN, &fpos(y), Image(type(x)) );
+ shift_type(x) = GAP_INC;
+ units(shift_gap(x)) = FIXED_UNIT;
+ width(shift_gap(x)) = 0;
+ mode(shift_gap(x)) = EDGE_MODE;
+ }
+ DisposeChild(Down(x));
+ goto ETC; /* next case down from here */
+
+
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case ONE_COL:
+ case ONE_ROW:
+
+ ETC:
+ par = (type(x)==ONE_COL || type(x)==HEXPAND || type(x) == HCONTRACT ||
+ type(x)==HLIMITED || type(x)==WIDE || type(x)==HSHIFT) ? COLM : ROWM;
+ Child(y, Down(x));
+
+ /* manifest the child, propagating perp threads and suppressing pars */
+ bt[par] = ft[par] = nilobj;
+ bt[1-par] = bthr[1-par]; ft[1-par] = fthr[1-par];
+ y = Manifest(y, env, style, bt, ft, target, crs, ok, FALSE, enclose, fcr);
+
+ /* replace with split object if par threads needed */
+ bt[par] = bthr[par]; ft[par] = fthr[par];
+ bt[1-par] = ft[1-par] = nilobj;
+ ReplaceWithSplit(x, bt, ft);
+ break;
+
+
+ case BEGIN_HEADER:
+ case SET_HEADER:
+
+ /* first manifest gap, which is left parameter */
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE,
+ &nenclose, fcr);
+ y = ReplaceWithTidy(y, FALSE);
+ GetGap(y, style, &line_gap(save_style(x)), &res_inc);
+
+ /* now the right parameter */
+ Child(y, LastDown(x));
+ y = Manifest(y, env, style, bthr, fthr, target, crs, ok, need_expand,
+ enclose, fcr);
+ break;
+
+
+ case END_HEADER:
+ case CLEAR_HEADER:
+
+ /* give these objects a dummy child, just so that threads can attach */
+ /* to it and keep the thread code happy. Don't use ReplaceWithSplit */
+ /* because we don't want a split above a header */
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ Link(x, y);
+ y = Manifest(y, env, style, bthr, fthr, target, crs, ok, need_expand,
+ enclose, fcr);
+ break;
+
+
+ case HSPAN:
+ case VSPAN:
+
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case ROTATE:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, FALSE);
+ GetGap(y, style, &res_gap, &res_inc);
+ if( res_inc != GAP_ABS || mode(res_gap) != EDGE_MODE ||
+ units(res_gap) != DEG_UNIT )
+ { Error(8, 28, "replacing invalid left parameter of %s by 0d",
+ WARN, &fpos(y), Image(type(x)) );
+ units(res_gap) = DEG_UNIT;
+ width(res_gap) = 0;
+ }
+ sparec(constraint(x)) = width(res_gap);
+ DisposeChild(Down(x));
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok, FALSE,enclose,fcr);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case BACKGROUND:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok, FALSE,enclose,fcr);
+ Child(y, LastDown(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok, FALSE,enclose,fcr);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok, FALSE,enclose,fcr);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case SCALE:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, FALSE);
+ if( is_word(type(y)) && StringEqual(string(y), STR_EMPTY) )
+ {
+ /* missing scale factor, meaning to be inserted automatically */
+ bc(constraint(x)) = fc(constraint(x)) = 0; /* work out later */
+ }
+ else if( type(y) != ACAT )
+ {
+ /* presumably one word, common factor for horizontal and vertical */
+ scale_factor = GetScaleFactor(y);
+ bc(constraint(x)) = fc(constraint(x)) = scale_factor * SF;
+ }
+ else
+ {
+ /* get horizontal scale factor */
+ Child(z, Down(y));
+ scale_factor = GetScaleFactor(z);
+ bc(constraint(x)) = scale_factor * SF;
+
+ /* get vertical scale factor */
+ Child(z, LastDown(y));
+ scale_factor = GetScaleFactor(z);
+ fc(constraint(x)) = scale_factor * SF;
+ }
+ DisposeChild(Down(x));
+ Child(y, LastDown(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok, FALSE, enclose, fcr);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case KERN_SHRINK:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ Child(y, LastDown(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok, FALSE, enclose, fcr);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case YIELD:
+
+ Error(8, 29, "%s not expected here", FATAL, &fpos(x), KW_YIELD);
+ break;
+
+
+ case RAW_VERBATIM:
+ case VERBATIM:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ DeleteLink(Down(x));
+ MergeNode(y, x); x = y;
+ break;
+
+
+ case CASE:
+
+ x = ManifestCase(x,env,style, bthr, fthr, target, crs, ok, need_expand, enclose, fcr);
+ break;
+
+
+ case BACKEND:
+
+ res = MakeWord(WORD, BackEnd->name, &fpos(x));
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ x = Manifest(res, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ break;
+
+
+ case XCHAR:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, FALSE);
+ if( !is_word(type(y)) )
+ { Error(8, 30, "%s dropped (parameter is not a simple word)",
+ WARN, &fpos(y), KW_XCHAR);
+ res = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ }
+ else if( (word_font(y) = font(*style)) == 0 )
+ { Error(8, 31, "%s dropped (no current font at this point)",
+ WARN, &fpos(y), KW_XCHAR);
+ res = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ }
+ else
+ { ch = MapCharEncoding(string(y), FontMapping(word_font(y), &fpos(y)));
+ if( ch == '\0' )
+ { type(y) = QWORD;
+ Error(8, 32, "%s dropped (character %s unknown in font %s)",
+ WARN, &fpos(y), KW_XCHAR, StringQuotedWord(y),
+ FontFamilyAndFace(word_font(y)));
+ res = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ }
+ else
+ { res = MakeWord(QWORD, STR_SPACE, &fpos(x));
+ string(res)[0] = ch;
+ }
+ }
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ x = Manifest(res, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ break;
+
+
+ case CURR_LANG:
+
+ if( language(*style) == 0 )
+ { Error(8, 33, "no current language at this point, using %s",
+ WARN, &fpos(x), STR_NONE);
+ res = MakeWord(WORD, STR_NONE, &fpos(x));
+ }
+ else res = MakeWord(WORD, LanguageString(language(*style)), &fpos(x));
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ x = Manifest(res, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ break;
+
+
+ case CURR_FAMILY:
+ case CURR_FACE:
+
+ if( font(*style) == 0 )
+ { Error(8, 38, "no current font at this point, using %s",
+ WARN, &fpos(x), STR_NONE);
+ res = MakeWord(WORD, STR_NONE, &fpos(x));
+ }
+ else if( type(x) == CURR_FAMILY )
+ res = MakeWord(WORD, FontFamily(font(*style)), &fpos(x));
+ else
+ res = MakeWord(WORD, FontFace(font(*style)), &fpos(x));
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ x = Manifest(res, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ break;
+
+
+ case CURR_YUNIT:
+ case CURR_ZUNIT:
+
+ { FULL_CHAR buff[20];
+ if( type(x) == CURR_YUNIT )
+ sprintf( (char *) buff, "%dp", yunit(*style) / PT);
+ else
+ sprintf( (char *) buff, "%dp", zunit(*style) / PT);
+ res = MakeWord(WORD, buff, &fpos(x));
+ }
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ x = Manifest(res, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ break;
+
+
+ case FONT:
+ case SPACE:
+ case YUNIT:
+ case ZUNIT:
+ case BREAK:
+ case COLOUR:
+ case LANGUAGE:
+
+ assert( Down(x) != x && NextDown(Down(x)) != x, "Manifest: FONT!" );
+ StyleCopy(new_style, *style);
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, type(x) == COLOUR);
+ switch( type(x) )
+ {
+ case FONT: FontChange(&new_style, y);
+ break;
+
+ case SPACE: SpaceChange(&new_style, y);
+ break;
+
+ case YUNIT: YUnitChange(&new_style, y);
+ break;
+
+ case ZUNIT: ZUnitChange(&new_style, y);
+ break;
+
+ case BREAK: BreakChange(&new_style, y);
+ break;
+
+ case COLOUR: ColourChange(&new_style, y);
+ break;
+
+ case LANGUAGE: LanguageChange(&new_style, y);
+ break;
+
+ }
+ DisposeChild(Down(x));
+ Child(y, Down(x));
+ y = Manifest(y, env, &new_style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ DeleteLink(Down(x));
+ MergeNode(y, x); x = y;
+ break;
+
+
+ case OUTLINE:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+
+ StyleCopy(new_style, *style);
+ if( type(x) == OUTLINE ) outline(new_style) = TRUE;
+ else if( type(x) == VADJUST ) vadjust(new_style) = TRUE;
+ else if( type(x) == HADJUST ) hadjust(new_style) = TRUE;
+ else padjust(new_style) = TRUE;
+ Child(y, Down(x));
+ y = Manifest(y, env, &new_style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ DeleteLink(Down(x));
+ MergeNode(y, x); x = y;
+ break;
+
+
+ case UNDERLINE:
+
+ /* change x to an ACAT and set the underline flags in its child */
+ assert( Down(x) != x && NextDown(Down(x)) == x, "Manifest: UNDERLINE!" );
+ type(x) = ACAT;
+ adjust_cat(x) = padjust(*style);
+ padjust(*style) = FALSE;
+ StyleCopy(save_style(x), *style);
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok, FALSE, enclose, fcr);
+ SetUnderline(x);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case MELD:
+ case COMMON:
+ case RUMP:
+
+ assert( Down(x) != x && NextDown(Down(x)) != x, "Manifest: COMMON!" );
+ debug2(DHY, DDD, "[Manifest %s %s", EchoObject(x), EchoObject(env));
+
+ /* find the first child of x, make sure it is an ACAT, and manifest */
+ Child(x1, Down(x));
+ if( type(x1) != ACAT )
+ { OBJECT newx1;
+ New(newx1, ACAT);
+ adjust_cat(newx1) = padjust(*style);
+ padjust(*style) = FALSE;
+ MoveLink(Down(x), newx1, CHILD);
+ Link(newx1, x1);
+ x1 = newx1;
+ }
+ x1 = Manifest(x1, env, style, nbt, nft, target, crs, ok, FALSE, enclose, fcr);
+ link1 = x1;
+ while( NextDown(link1) != x1 )
+ { Child(z, NextDown(link1));
+ if( type(z) == ACAT )
+ { TransferLinks(Down(z), z, NextDown(link1));
+ DisposeChild(Up(z));
+ }
+ else link1 = NextDown(link1);
+ }
+ debug1(DHY, DDD, " manifested x1 = %s", EchoObject(x1));
+
+ /* find the second child of x, make sure it is an ACAT, and manifest */
+ Child(x2, NextDown(Down(x)));
+ if( type(x2) != ACAT )
+ { OBJECT newx2;
+ New(newx2, ACAT);
+ adjust_cat(newx2) = padjust(*style);
+ padjust(*style) = FALSE;
+ MoveLink(NextDown(Down(x)), newx2, CHILD);
+ Link(newx2, x2);
+ x2 = newx2;
+ }
+ x2 = Manifest(x2, env, style, nbt, nft, target, crs, ok, FALSE, enclose, fcr);
+ link2 = x2;
+ while( NextDown(link2) != x2 )
+ { Child(z, NextDown(link2));
+ if( type(z) == ACAT )
+ { TransferLinks(Down(z), z, NextDown(link2));
+ DisposeChild(Up(z));
+ }
+ else link2 = NextDown(link2);
+ }
+ debug1(DHY, DDD, " manifested x2 = %s", EchoObject(x2));
+
+ if( type(x) == MELD )
+ {
+ /* if Meld, result is Meld(x1, x2) */
+ res = Meld(x1, x2);
+ }
+ else
+ {
+
+ /* find the point where x1 and x2 begin to differ */
+ link1 = Down(x1);
+ link2 = Down(x2);
+ while( link1 != x1 && link2 != x2 )
+ {
+ Child(y1, link1);
+ Child(y2, link2);
+ debug1(DHY, DDD, " y1 = %s", EchoObject(y1));
+ debug1(DHY, DDD, " y2 = %s", EchoObject(y2));
+ if( is_word(type(y1)) && is_word(type(y2)) )
+ {
+ if( !StringEqual(string(y1), string(y2)) ) break;
+ }
+ else if( type(y1) != type(y2) ) break;
+ link1 = NextDown(link1);
+ link2 = NextDown(link2);
+ }
+
+ /* if COMMON, result is x1 or x2 if either ran out, */
+ /* or else x2 (say) up to but not including link2 and prec gap */
+ if( type(x) == COMMON )
+ { if( link2 == x2 )
+ { res = x2;
+ }
+ else if( link1 == x1 )
+ { res = x1;
+ }
+ else
+ { if( link2 == Down(x2) )
+ res = MakeWord(WORD, STR_EMPTY, &fpos(x2));
+ else
+ { TransferLinks(PrevDown(link2), x2, x1);
+ res = x2;
+ }
+ }
+ }
+
+ /* if RUMP, result is x2 starting from link2 or NextDown(link2) */
+ else if( type(x) == RUMP )
+ { if( link2 == x2 )
+ res = MakeWord(WORD, STR_EMPTY, &fpos(x2));
+ else if( link1 == x1 )
+ {
+ TransferLinks(Down(x2), NextDown(link2), x1);
+ res = x2;
+ }
+ else /* link1 != x1 */
+ {
+ TransferLinks(Down(x2), link2, x1);
+ res = x2;
+ }
+ }
+ }
+
+ /* now res replaces x */
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ x = res;
+ ReplaceWithSplit(x, bthr, fthr);
+ debug1(DHY, DDD, "]Manifest returning %s", EchoObject(x));
+ break;
+
+
+ case INSERT:
+
+ /* manifest and detach the left parameter, call it z */
+ Child(z, Down(x));
+ z = Manifest(z, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ DeleteLink(Down(x));
+
+ /* manifest the right parameter and make it the result */
+ Child(y, LastDown(x));
+ y = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ DeleteLink(LastDown(x));
+ MergeNode(y, x); x = y;
+
+ /* now find the reattachment point for z down inside the result, x */
+ x = InsertObject(x, &z, style);
+ if( z != nilobj )
+ { Error(8, 34, "object dropped by %s: no suitable insert point", WARN,
+ &fpos(x), KW_INSERT);
+ DisposeObject(z);
+ }
+ break;
+
+
+ case ONE_OF:
+
+ Child(y, Down(x));
+ if( type(y) != ACAT )
+ {
+ /* child is not a sequence of choices, so ignore ONE_OF */
+ Error(8, 39, "%s ignored: no choices in right parameter", WARN,
+ &fpos(x), KW_ONE_OF);
+ y = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE,
+ enclose, fcr);
+ DeleteLink(Down(x));
+ MergeNode(y, x); x = y;
+ }
+ else
+ {
+ /* try each child in turn; result is first to find *target */
+ OBJECT target_before;
+ for( link = Down(y); link != y; link = NextDown(link) )
+ {
+ Child(z, link);
+ if( type(z) == GAP_OBJ ) continue;
+ target_before = *target;
+ z = Manifest(z, env, style, bthr, fthr, target, crs, ok, FALSE,
+ enclose, fcr);
+ if( *target != target_before )
+ break;
+ }
+ DeleteLink(Up(z));
+ ReplaceNode(z, x);
+ DisposeObject(x);
+ x = z;
+ }
+ break;
+
+
+ case NEXT:
+
+ assert( Down(x) != x, "Manifest/NEXT: Down(x) == x!" );
+ Child(y, Down(x));
+ debug1(DCS, DD, " Manifesting Next( %s, 1 )", EchoObject(y));
+ y = Manifest(y, env, style, bthr, fthr, target, crs, FALSE, FALSE, enclose, fcr);
+ debug1(DCS, DD, " calling Next( %s, 1 )", EchoObject(y));
+ done = FALSE;
+ y = Next(y, 1, &done);
+ debug2(DCS, DD, " Next(done = %s) returning %s",
+ bool(done), EchoObject(y));
+ DeleteLink(Down(x));
+ MergeNode(y, x); x = y;
+ break;
+
+
+ case PLUS:
+ case MINUS:
+
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, FALSE);
+ Child(z, NextDown(Down(x)));
+ z = Manifest(z, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ z = ReplaceWithTidy(z, FALSE);
+ if( is_word(type(y)) && sscanf( (char *) string(y), "%d", &num1) == 1 &&
+ is_word(type(z)) && sscanf( (char *) string(z), "%d", &num2) == 1 )
+ {
+ FULL_CHAR buff[MAX_BUFF];
+ sprintf( (char *) buff, "%d", type(x) == PLUS ? num1+num2 : num1-num2);
+ res = MakeWord(WORD, buff, &fpos(x));
+ }
+ else
+ { res = MakeWord(WORD, STR_NOCROSS, &fpos(x));
+ }
+ debug4(DOM, DD, "{ %s } %s { %s } = %s", EchoObject(y), Image(type(x)),
+ EchoObject(z), EchoObject(res));
+ res = Manifest(res, env, style, bthr, fthr, target, crs, FALSE, FALSE, enclose, fcr);
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ x = res;
+ break;
+
+
+ case OPEN:
+
+ debug0(DCR, DD, " [ Manifest/OPEN begins:");
+ Child(y, Down(x));
+ DeleteLink(Down(x));
+ Child(res, LastDown(x));
+ hold_env = nilobj;
+ if( type(y) == CLOSURE )
+ { AttachEnv(env, y);
+ StyleCopy(save_style(y), *style);
+ debug0(DCR, DDD, "calling SetEnv from Manifest (b)");
+ res_env = SetEnv(y, nilobj);
+ New(hold_env, ACAT); Link(hold_env, res_env);
+ res = Manifest(res, res_env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ }
+ else if( is_cross(type(y)) )
+ { Child(z, Down(y));
+ if( type(z) == CLOSURE )
+ { debug0(DCR, DD, " calling CrossExpand from Manifest/OPEN");
+ /* *** want cross ref now always, not only if ok
+ y = CrossExpand(y, env, style, ok, crs, &res_env);
+ *** */
+ y = CrossExpand(y, env, style, crs, &res_env);
+ AttachEnv(res_env, y);
+ debug0(DCR, DDD, "calling SetEnv from Manifest (c)");
+ res_env = SetEnv(y, env);
+ New(hold_env, ACAT); Link(hold_env, res_env);
+ res = Manifest(res, res_env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ }
+ else
+ { Error(8, 35, "invalid left parameter of %s", WARN, &fpos(y), KW_OPEN);
+ res = Manifest(res, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ }
+ }
+ else
+ { Error(8, 36, "invalid left parameter of %s", WARN, &fpos(y), KW_OPEN);
+ res = Manifest(res, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ }
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ if( hold_env != nilobj ) DisposeObject(hold_env);
+ x = res;
+ debug0(DCR, DD, " ] Manifest/OPEN ends");
+ break;
+
+
+ case TAGGED:
+
+ x = ManifestTg(x, env, style, bthr, fthr, target, crs, ok, need_expand, enclose, fcr);
+ debug2(DCR, DD, "Manifest returning %ld %s", (long) x, EchoObject(x));
+ break;
+
+
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+
+ debug1(DRS, DD, " graphic style in Manifest = %s", EchoStyle(style));
+ Child(y, LastDown(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok, FALSE, enclose, fcr);
+ StyleCopy(save_style(x), *style);
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case LINK_SOURCE:
+ case LINK_DEST:
+
+ Child(y, LastDown(x));
+ y = Manifest(y, env, style, nbt, nft, target, crs, ok,FALSE,enclose,fcr);
+ StyleCopy(save_style(x), *style);
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE,
+ &nenclose, fcr);
+ y = ReplaceWithTidy(y, TRUE);
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+
+ StyleCopy(save_style(x), *style);
+ debug2(DGP, DD, " manifest at %s (style %s)",
+ EchoObject(x), EchoStyle(&save_style(x)));
+ Child(y, Down(x));
+ y = Manifest(y, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, fcr);
+ y = ReplaceWithTidy(y, FALSE);
+ if( !is_word(type(y)) )
+ { Error(8, 37, "%s deleted (invalid right parameter)", WARN, &fpos(y),
+ type(x) == INCGRAPHIC ? KW_INCGRAPHIC : KW_SINCGRAPHIC);
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(y, x); DisposeObject(x);
+ x = Manifest(y, env, style, bthr, fthr, target, crs, ok, FALSE, enclose, fcr);
+ return x;
+ }
+ ReplaceWithSplit(x, bthr, fthr);
+ break;
+
+
+ default:
+
+ assert1(FALSE, "Manifest:", Image(type(x)));
+ break;
+
+ } /* end switch */
+
+ debug2(DOM, DD, "]Manifest returning %s %s", Image(type(x)), EchoObject(x));
+ debug1(DOM, DD, " at exit, style = %s", EchoStyle(style));
+ debug1(DOM, DDD, "up: ", EchoObject(bthr[COLM]));
+ debug1(DOM, DDD, "down: ", EchoObject(fthr[COLM]));
+ debug1(DOM, DDD, "left: ", EchoObject(bthr[ROWM]));
+ debug1(DOM, DDD, "right: ", EchoObject(fthr[ROWM]));
+ debugcond1(DHY, DD, eee, "] Manifest returning %s", EchoObject(x));
+ depth--;
+ return x;
+ } /* end Manifest */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z09.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z09.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z09.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,294 ----
+ /*@z09.c:Closure Expansion:SearchEnv()@***************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z09.c */
+ /* MODULE: Closure Expansion */
+ /* EXTERNS: SearchEnv(), SetEnv(), AttachEnv(), GetEnv(), */
+ /* DetachEnv(), ClosureExpand() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT SearchEnv(env, sym) */
+ /* */
+ /* Search environment env for a symbol such that actual() == sym. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT SearchEnv(OBJECT env, OBJECT sym)
+ { OBJECT link, y;
+ debug2(DCE, DD, "[ SearchEnv(%s, %s)", EchoObject(env), SymName(sym));
+ for(;;)
+ {
+ debug1(DCE, DDD, " searching env %s", EchoObject(env));
+ assert( env != nilobj && type(env) == ENV, "SearchEnv: env!" );
+ if( Down(env) == env )
+ { debug0(DCE, DD, "] SearchEnv returning <nilobj>");
+ return nilobj;
+ }
+ Child(y, Down(env));
+ assert( type(y) == CLOSURE, "SearchEnv: type(y) != CLOSURE!" );
+ if( actual(y) == sym )
+ { debug1(DCE, DD, "] SearchEnv returning %s", EchoObject(y));
+ return y;
+ }
+ assert( LastDown(y) != y, "SearchEnv: LastDown(y) == y!" );
+ link = LastDown(env) != Down(env) ? LastDown(env) : LastDown(y);
+ Child(env, link);
+ }
+ } /* end SearchEnv */
+
+
+ /*@::SetEnv(), AttachEnv(), GetEnv(), DetachEnv()@****************************/
+ /* */
+ /* OBJECT SetEnv(x, y) */
+ /* */
+ /* Create a new environment containing x and possibly y. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT SetEnv(OBJECT x, OBJECT y)
+ { OBJECT res;
+ debug1(DCE, DD, "SetEnv( x, %s ), x =", EchoObject(y));
+ ifdebug(DCE, DD, DebugObject(x));
+ assert( x!=nilobj && type(x)==CLOSURE, "SetEnv: x==nilobj or not CLOSURE!" );
+ assert( y==nilobj || type(y)==ENV, "SetEnv: y!=nilobj && type(y) != ENV!" );
+ New(res, ENV); Link(res, x);
+ if( y != nilobj ) Link(res, y);
+ debug1(DCE, DD, "SetEnv returning %s", EchoObject(res));
+ return res;
+ } /* end SetEnv */
+
+
+ /*****************************************************************************/
+ /* */
+ /* AttachEnv(env, x) */
+ /* */
+ /* Attach environment env to CLOSURE x. */
+ /* */
+ /*****************************************************************************/
+
+ void AttachEnv(OBJECT env, OBJECT x)
+ { debug2(DCE, DD, "AttachEnv( %s, %s )", EchoObject(env), EchoObject(x));
+ assert( env != nilobj && type(env) == ENV, "AttachEnv: type(env) != ENV!" );
+ assert( type(x) == CLOSURE || type(x) == ENV_OBJ, "AttachEnv: type(x)!" );
+ Link(x, env);
+ debug0(DCE, DD, "AttachEnv returning.");
+ } /* end AttachEnv */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT GetEnv(x) */
+ /* */
+ /* Get from CLOSURE x the environment previously attached. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT GetEnv(OBJECT x)
+ { OBJECT env;
+ assert( type(x) == CLOSURE, "GetEnv: type(x) != CLOSURE!" );
+ assert( LastDown(x) != x, "GetEnv: LastDown(x) == x!" );
+ Child(env, LastDown(x));
+ assert( type(env) == ENV, "GetEnv: type(env) != ENV!" );
+ return env;
+ } /* end GetEnv */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT DetachEnv(x) */
+ /* */
+ /* Detach from CLOSURE x the environment previously attached. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT DetachEnv(OBJECT x)
+ { OBJECT env;
+ debug1(DCE, DD, "DetachEnv( %s )", EchoObject(x));
+ assert( type(x) == CLOSURE, "DetachEnv: type(x) != CLOSURE!" );
+ assert( LastDown(x) != x, "DetachEnv: LastDown(x) == x!" );
+ Child(env, LastDown(x));
+ DeleteLink(LastDown(x));
+ assert( type(env) == ENV, "DetachEnv: type(env) != ENV!" );
+ debug1(DCE, DD, "DetachEnv resturning %s", EchoObject(env));
+ return env;
+ } /* end DetachEnv */
+
+
+ /*@::ClosureExpand()@*********************************************************/
+ /* */
+ /* OBJECT ClosureExpand(x, env, crs_wanted, crs, res_env) */
+ /* */
+ /* Return expansion of closure x in environment env. */
+ /* The body comes from the environment of x if x is a parameter, else from */
+ /* the symbol table. The original x is pushed into the environments. */
+ /* If crs_wanted and x has a tag, a cross-reference is added to crs. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT ClosureExpand(OBJECT x, OBJECT env, BOOLEAN crs_wanted,
+ OBJECT *crs, OBJECT *res_env)
+ { OBJECT link, y, res, prnt_env, par, prnt;
+ debug3(DCE, D, "[ ClosureExpand( %s, %s, %s, crs, res_env )",
+ EchoObject(x), EchoObject(env), bool(crs_wanted));
+ assert( type(x) == CLOSURE, "ClosureExpand given non-CLOSURE!");
+ assert( predefined(actual(x)) == FALSE, "ClosureExpand given predefined!" );
+
+ /* add tag to x if needed but not provided; add cross-reference to crs */
+ if( has_tag(actual(x)) ) CrossAddTag(x);
+ if( crs_wanted && has_tag(actual(x)) )
+ { OBJECT tmp = CopyObject(x, no_fpos); AttachEnv(env, tmp);
+ y = CrossMake(actual(x), tmp, CROSS_TARG);
+ New(tmp, CROSS_TARG); actual(tmp) = y; Link(tmp, y);
+ if( *crs == nilobj ) New(*crs, CR_LIST); Link(*crs, tmp);
+ }
+
+ /* case x is a parameter */
+ res = *res_env = nilobj;
+ if( is_par(type(actual(x))) )
+ { prnt = SearchEnv(env, enclosing(actual(x)));
+ if( prnt != nilobj )
+ {
+ prnt_env = GetEnv(prnt);
+ for( link = Down(prnt); link != prnt; link = NextDown(link) )
+ { Child(par, link);
+ if( type(par) == PAR && actual(par) == actual(x) )
+ { assert( Down(par) != par, "ExpandCLosure: Down(par)!");
+ Child(res, Down(par));
+ if( dirty(enclosing(actual(par))) || is_enclose(actual(par)) )
+ { debug2(DCE, DD, "copy %s %s", SymName(actual(par)), EchoObject(res));
+ res = CopyObject(res, no_fpos);
+ }
+ else
+ { debug2(DCE, DD, "link %s %s",
+ FullSymName(actual(par), AsciiToFull(".")), EchoObject(res));
+ DeleteLink(Down(par));
+ y = MakeWord(WORD, STR_NOCROSS, &fpos(res));
+ Link(par, y);
+ }
+ ReplaceNode(res, x);
+ if( type(actual(x)) == RPAR && has_body(enclosing(actual(x))) )
+ { debug0(DCR, DDD, " calling SetEnv from ClosureExpand (a)");
+ *res_env = SetEnv(prnt, nilobj); DisposeObject(x);
+ }
+ else if( type(actual(x)) == NPAR && imports_encl(actual(x)) )
+ { debug0(DCR, DDD, " calling SetEnv from ClosureExpand (x)");
+ AttachEnv(env, x);
+ *res_env = SetEnv(x, nilobj);
+ }
+ else
+ { AttachEnv(env, x);
+ debug0(DCR, DDD, " calling SetEnv from ClosureExpand (b)");
+ *res_env = SetEnv(x, prnt_env);
+ }
+ break;
+ }
+ }
+ }
+ else
+ {
+ /* fail only if there is no default value available */
+ if( sym_body(actual(x)) == nilobj )
+ {
+ debug3(DCE, D, "failing ClosureExpand( %s, crs, %s, %s, res_env )\n",
+ EchoObject(x), bool(crs_wanted), EchoObject(env));
+ Error(9, 2, "no value for parameter %s of symbol %s:", WARN, &fpos(x),
+ SymName(actual(x)), SymName(enclosing(actual(x))));
+ Error(9, 1, "symbol with import list misused", FATAL, &fpos(x));
+ }
+ }
+ }
+
+ /* case x is a user-defined symbol or default parameter */
+ if( res == nilobj )
+ { if( sym_body(actual(x)) == nilobj )
+ res = MakeWord(WORD,STR_NOCROSS,&fpos(x));
+ else res = CopyObject(sym_body(actual(x)), &fpos(x));
+ ReplaceNode(res, x); AttachEnv(env, x);
+ debug0(DCR, DDD, " calling SetEnv from ClosureExpand (c)");
+ *res_env = SetEnv(x, nilobj);
+ }
+
+ assert( *res_env!=nilobj && type(*res_env)==ENV, "ClosureExpand: *res_env!");
+ debug0(DCE, D, "] ClosureExpand returning, res =");
+ ifdebug(DCE, D, DebugObject(res));
+ debug1(DCE, D, " environment = %s", EchoObject(*res_env));
+ return res;
+ } /* end ClosureExpand */
+
+
+ /*@::ParameterCheck()@********************************************************/
+ /* */
+ /* OBJECT ParameterCheck(x, env) */
+ /* */
+ /* Check whether object x (which is an actual parameter that happens to be */
+ /* a CLOSURE) has a value which is a simple word, and if so return a copy */
+ /* of that word, else nilobj. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT ParameterCheck(OBJECT x, OBJECT env)
+ { OBJECT link, y, res, prnt_env, par, prnt;
+ debug2(DCE, DD, "ParameterCheck(%s, %s)", EchoObject(x), EchoObject(env));
+ assert( type(x) == CLOSURE, "ParameterCheck given non-CLOSURE!");
+
+ /* case x is a parameter */
+ prnt = SearchEnv(env, enclosing(actual(x)));
+ if( prnt == nilobj )
+ { debug0(DCE, DD, "ParameterCheck returning nilobj (prnt fail)");
+ return nilobj;
+ }
+ prnt_env = GetEnv(prnt);
+ for( link = Down(prnt); link != prnt; link = NextDown(link) )
+ { Child(par, link);
+ if( type(par) == PAR && actual(par) == actual(x) )
+ { assert( Down(par) != par, "ParameterCheck: Down(par)!");
+ Child(y, Down(par));
+ res = is_word(type(y)) ? CopyObject(y, no_fpos) : nilobj;
+ debug1(DCE, DD, " ParameterCheck returning %s", EchoObject(res));
+ return res;
+ }
+ }
+
+ /* case x is a default parameter */
+ y = sym_body(actual(x));
+ if( y == nilobj )
+ { res = nilobj;
+ }
+ else if( is_word(type(y)) )
+ { res = CopyObject(y, &fpos(y));
+ }
+ else if( type(y) == CLOSURE && is_par(type(actual(y))) )
+ { res = ParameterCheck(y, prnt_env);
+ }
+ else
+ { res = nilobj;
+ }
+ debug1(DCE, DD, "ParameterCheck returning %s", EchoObject(res));
+ return res;
+ } /* end ParameterCheck */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z10.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z10.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z10.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1077 ----
+ /*@z10.c:Cross References:CrossInit(), CrossMake()@***************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z10.c */
+ /* MODULE: Cross References */
+ /* EXTERNS: CrossInit(), CrossMake(), GallTargEval(), CrossAddTag(), */
+ /* CrossExpand(), CrossSequence(), CrossClose() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define NO_TARGET 0
+ #define SEEN_TARGET 1
+ #define WRITTEN_TARGET 2
+ #define INIT_CROSSREF_NUM 100
+
+ static OBJECT RootCross = nilobj; /* header for all crs */
+
+ /*****************************************************************************/
+ /* */
+ /* CROSSREF_TABLE */
+ /* */
+ /* A symbol table permitting access to cross reference generated tags by */
+ /* a mapping (symbol x file) -> current tag. */
+ /* */
+ /* crtab_getnext(sym, fnum, S) Get next value associated with sym,fnum */
+ /* crtab_debug(S, fp) Debug print of table S to file fp */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct crossref_rec
+ { struct crossref_rec *crtab_next;
+ OBJECT crtab_sym;
+ FILE_NUM crtab_fnum;
+ int crtab_value;
+ } *CROSSREF_ENTRY;
+
+ typedef struct
+ { int tab_size; /* size of table */
+ int tab_count; /* number of entries held */
+ CROSSREF_ENTRY tab_chains[1]; /* the chains of entries */
+ } *CROSSREF_TABLE;
+
+ #define crtab_size(S) (S)->tab_size
+ #define crtab_count(S) (S)->tab_count
+ #define crtab_chain(S,i) (S)->tab_chains[i]
+
+ #define hash(pos, sym, fnum, S) \
+ { pos = ( ((unsigned long) sym) + fnum ) % crtab_size(S); \
+ }
+
+ static CROSSREF_TABLE crtab_new(int newsize)
+ { CROSSREF_TABLE S; int i;
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_CROSSREF, 1,
+ 2*sizeof(int) + newsize*sizeof(CROSSREF_ENTRY)));
+ S = (CROSSREF_TABLE)
+ malloc(2*sizeof(int) + newsize*sizeof(CROSSREF_ENTRY));
+ if( S == (CROSSREF_TABLE) NULL )
+ Error(10, 1, "run out of memory enlarging crossref table", FATAL, no_fpos);
+ crtab_size(S) = newsize;
+ crtab_count(S) = 0;
+ for( i = 0; i < newsize; i++ )
+ crtab_chain(S, i) = (CROSSREF_ENTRY) nilobj;
+ return S;
+ } /* end crtab_new */
+
+ static CROSSREF_TABLE crtab_rehash(CROSSREF_TABLE S, int newsize)
+ { CROSSREF_TABLE NewS; int i; unsigned long newpos; CROSSREF_ENTRY p, q;
+ NewS = crtab_new(newsize);
+ for( i = 0; i < crtab_size(S); i++ )
+ { p = crtab_chain(S, i);
+ while( p != NULL )
+ { q = p->crtab_next;
+ hash(newpos, p->crtab_sym, p->crtab_fnum, NewS);
+ p->crtab_next = crtab_chain(NewS, newpos);
+ crtab_chain(NewS, newpos) = p;
+ crtab_count(NewS)++;
+ p = q;
+ }
+ }
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_CROSSREF, -1,
+ -(2*sizeof(int) + crtab_size(S)*sizeof(CROSSREF_ENTRY))));
+ free(S);
+ return NewS;
+ } /* end crtab_rehash */
+
+ static int crtab_getnext(OBJECT sym, FILE_NUM fnum, CROSSREF_TABLE *S)
+ { CROSSREF_ENTRY x; OBJECT t; unsigned long pos;
+
+ /* if S is NULL, create a new table */
+ if( *S == NULL ) *S = crtab_new(INIT_CROSSREF_NUM);
+
+ /* if (sym, fnum) exists, increment its value and return it */
+ hash(pos, sym, fnum, *S);
+ for( x = crtab_chain(*S, pos); x != NULL; x = x->crtab_next )
+ { if( x->crtab_sym == sym && x->crtab_fnum == fnum )
+ return ++x->crtab_value;
+ }
+
+ /* if table is full, rehash */
+ if( crtab_count(*S) == crtab_size(*S) )
+ { *S = crtab_rehash(*S, 2*crtab_size(*S));
+ hash(pos, sym, fnum, *S);
+ }
+
+ /* insert a new entry for (sym, fnum) with value 1 */
+ GetMem(t, sizeof(struct crossref_rec), no_fpos);
+ x = (CROSSREF_ENTRY) t;
+ x->crtab_sym = sym;
+ x->crtab_fnum = fnum;
+ x->crtab_next = crtab_chain(*S, pos);
+ crtab_chain(*S, pos) = x;
+ crtab_count(*S)++;
+ return x->crtab_value = 1;
+
+ } /* end crtab_getnext */
+
+ #if DEBUG_ON
+ static void crtab_debug(CROSSREF_TABLE S, FILE *fp)
+ { int i; CROSSREF_ENTRY x;
+ if( S == NULL )
+ { fprintf(fp, " null table\n");
+ return;
+ }
+ fprintf(fp, " table size: %d; current count: %d\n",
+ crtab_size(S), crtab_count(S));
+ for( i = 0; i < crtab_size(S); i++ )
+ { fprintf(fp, "crtab_chain(S, %d) =", i);
+ for( x = crtab_chain(S, i); x != NULL; x = x->crtab_next )
+ { fprintf(fp, " %s:%s,%d",
+ SymName(x->crtab_sym), FileName(x->crtab_fnum), x->crtab_value);
+ }
+ fprintf(fp, "\n");
+ }
+ } /* end crtab_debug */
+ #endif
+
+ static CROSSREF_TABLE crossref_tab = NULL;
+
+
+ /*@@**************************************************************************/
+ /* */
+ /* CrossInit(sym) Initialize cross_sym(sym). */
+ /* */
+ /*****************************************************************************/
+
+ void CrossInit(OBJECT sym)
+ { OBJECT cs;
+ New(cs, CROSS_SYM);
+ target_state(cs) = NO_TARGET; target_seq(cs) = 0;
+ /* cr_file(cs) = NO_FILE; unused */
+ gall_seq(cs) = 0; gall_tag(cs) = nilobj;
+ gall_tfile(cs) = NO_FILE;
+ symb(cs) = sym; cross_sym(sym) = cs;
+ if( RootCross == nilobj ) New(RootCross, CR_ROOT); Link(RootCross, cs);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT CrossMake(sym, val, ctype) */
+ /* */
+ /* Make a cross-reference with the given sym and tag value (NB no fpos). */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT CrossMake(OBJECT sym, OBJECT val, int ctype)
+ { OBJECT v1, res;
+ debug3(DCR, DD, "CrossMake(%s, %s, %s)", SymName(sym),
+ EchoObject(val), Image(ctype));
+ New(res, CROSS); cross_type(res) = ctype; threaded(res) = FALSE;
+ New(v1, CLOSURE); actual(v1) = sym;
+ Link(res, v1); Link(res, val);
+ debug1(DCR, DD, "CrossMake returning %s", EchoObject(res));
+ return res;
+ }
+
+ /*@::GallTargEval(), CrossGenTag()@*******************************************/
+ /* */
+ /* OBJECT GallTargEval(sym, dfpos) */
+ /* */
+ /* Produce a suitable cross-reference for a galley target. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT GallTargEval(OBJECT sym, FILE_POS *dfpos)
+ { OBJECT cs, res;
+ FULL_CHAR buff[MAX_BUFF], *str;
+ debug2(DCR, DD, "GallTargEval( %s,%s )", SymName(sym), EchoFilePos(dfpos));
+ if( cross_sym(sym) == nilobj ) CrossInit(sym);
+ cs = cross_sym(sym);
+ if( file_num(*dfpos) != gall_tfile(cs) )
+ { gall_tfile(cs) = file_num(*dfpos);
+ gall_seq(cs) = 0;
+ }
+ str = FileName(gall_tfile(cs));
+ ++gall_seq(cs);
+ if( StringLength(str) + 6 >= MAX_BUFF )
+ Error(10, 2, "automatically generated tag %s&%d is too long",
+ FATAL, dfpos, str, gall_seq(cs));
+ StringCopy(buff, str);
+ StringCat(buff, AsciiToFull("&"));
+ StringCat(buff, StringInt(gall_seq(cs)));
+ res = CrossMake(sym, MakeWord(WORD, buff, dfpos), GALL_TARG);
+ debug1(DCR, DD, "GallTargEval returning %s", EchoObject(res));
+ return res;
+ } /* end GallTargEval */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static OBJECT CrossGenTag(x) */
+ /* */
+ /* Generate a tag suitable for labelling closure x, in such a way that */
+ /* the same tag is likely to be generated on subsequent runs. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT CrossGenTag(OBJECT x)
+ { FULL_CHAR buff[MAX_BUFF], *file_name;
+ OBJECT sym, res; FILE_NUM fnum;
+ int seq;
+ debug1(DCR, DD, "CrossGenTag( %s )", SymName(actual(x)));
+ sym = actual(x);
+ if( cross_sym(sym) == nilobj ) CrossInit(sym);
+ fnum = file_num(fpos(x));
+ file_name = FileName(fnum);
+ seq = crtab_getnext(sym, fnum, &crossref_tab);
+ debug3(DCR, DDD, "%d = crtab_getnext(%s, %s, S); S =",
+ seq, SymName(sym), FileName(fnum));
+ ifdebug(DCR, DDD, crtab_debug(crossref_tab, stderr));
+ if( StringLength(file_name) + 20 >= MAX_BUFF )
+ Error(10, 3, "automatically generated tag is too long (contains %s)",
+ FATAL, &fpos(x), file_name);
+ sprintf( (char *) buff, "%d.%d.%s.%d",
+ file_num(fpos(sym)), line_num(fpos(sym)), file_name, seq);
+ res = MakeWord(QWORD, buff, &fpos(x));
+ debug2(DCR, DD, "CrossGenTag( %s ) returning %s", SymName(actual(x)), string(res));
+ return res;
+ } /* end CrossGenTag */
+
+
+ /*@::CrossAddTag()@***********************************************************/
+ /* */
+ /* CrossAddTag(x) */
+ /* */
+ /* Add an automatically generated @Tag parameter to closure x if required. */
+ /* */
+ /*****************************************************************************/
+
+ void CrossAddTag(OBJECT x)
+ { OBJECT link, par, ppar, y;
+ debug1(DCR, DD, "CrossAddTag( %s )", EchoObject(x));
+
+ /* search the parameter list of x for a @Tag parameter */
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(par, link);
+ if( type(par) == PAR && is_tag(actual(par)) )
+ {
+ /* has tag, but if value is empty object, delete it */
+ Child(y, Down(par));
+ if( is_word(type(y)) && StringEqual(string(y), STR_EMPTY) )
+ { DisposeChild(link);
+ link = x;
+ }
+ break;
+ }
+ }
+ if( link == x )
+ {
+ /* search the definition of x for name of its @Tag parameter */
+ ppar = nilobj;
+ for( link=Down(actual(x)); link != actual(x); link = NextDown(link) )
+ { Child(y, link);
+ if( is_par(type(y)) && is_tag(y) )
+ { ppar = y;
+ break;
+ }
+ }
+ if( ppar != nilobj ) /* should always hold */
+ {
+ /* prepare new PAR containing generated tag */
+ New(par, PAR);
+ actual(par) = ppar;
+ y = CrossGenTag(x);
+ Link(par, y);
+
+ /* find the right spot, then link it to x */
+ switch( type(ppar) )
+ {
+ case LPAR: link = Down(x);
+ break;
+
+ case NPAR: link = Down(x);
+ if( Down(x) != x )
+ { Child(y, Down(x));
+ if( type(y) == PAR && type(actual(y)) == LPAR )
+ link = NextDown(link);
+ }
+ break;
+
+ case RPAR: for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) != PAR ) break;
+ }
+ break;
+ }
+ Link(link, par);
+ }
+ }
+ debug1(DCR, DD, "CrossAddTag returning %s", EchoObject(x));
+ } /* end CrossAddTag */
+
+
+ /*@::CrossExpand()@***********************************************************/
+ /* */
+ /* OBJECT CrossExpand(x, env, style, crs, res_env) */
+ /* */
+ /* Return the value of cross-reference x, with environment *res_env. If */
+ /* x has a non-literal tag, it must be tracked, so an object is added to */
+ /* *crs for this purpose. The result replaces x, which is disposed. */
+ /* */
+ /*****************************************************************************/
+ static OBJECT nbt[2] = { nilobj, nilobj };
+ static OBJECT nft[2] = { nilobj, nilobj };
+ static OBJECT ntarget = nilobj;
+ static OBJECT nenclose = nilobj;
+
+ OBJECT CrossExpand(OBJECT x, OBJECT env, STYLE *style,
+ OBJECT *crs, OBJECT *res_env)
+ { OBJECT sym, res, tag, y, cs, link, db, tmp, index;
+ int ctype, count, i; FULL_CHAR buff[MAX_BUFF], seq[MAX_BUFF], *str;
+ FILE_NUM fnum, dfnum; BOOLEAN tagerror = FALSE;
+ long cont, dfpos; int dlnum;
+ assert( is_cross(type(x)), "CrossExpand: x!" );
+ debug2(DCR, DD, "[ CrossExpand( %s, env, style, %s, res_env )",
+ EchoObject(x), EchoObject(*crs));
+ assert( NextDown(Down(x)) == LastDown(x), "CrossExpand: #args!" );
+
+ /* manifest and tidy the right parameter */
+ Child(tag, LastDown(x));
+ debug0(DOM, D, " [ calling Manifest from CrossExpand");
+ tag = Manifest(tag, env, style, nbt, nft, &ntarget, crs, FALSE, FALSE, &nenclose, FALSE);
+ debug0(DOM, D, " ] returning from Manifest");
+ tag = ReplaceWithTidy(tag, TRUE); /* && */
+
+ /* extract sym (the symbol name) and tag (the tag value) from x */
+ Child(y, Down(x));
+ assert( type(y) == CLOSURE, "ClosureExpand: type(y) != CLOSURE!" );
+ sym = actual(y);
+ ctype = !is_word(type(tag)) ? 1 :
+ StringEqual(string(tag), STR_EMPTY) ? 2 :
+ StringEqual(string(tag), KW_PRECEDING) ? CROSS_PREC :
+ StringEqual(string(tag), KW_FOLL_OR_PREC) ? CROSS_FOLL_OR_PREC :
+ StringEqual(string(tag), KW_FOLLOWING) ? CROSS_FOLL : CROSS_LIT;
+
+ res = nilobj;
+ switch( ctype )
+ {
+
+ case 1:
+
+ Error(10, 4, "value of right parameter of %s is not a simple word",
+ WARN, &fpos(tag), KW_CROSS);
+ break;
+
+
+ case 2:
+
+ Error(10, 5, "value of right parameter of %s is an empty word",
+ WARN, &fpos(tag), KW_CROSS);
+ break;
+
+
+ case CROSS_LIT:
+
+ debug2(DCR, DD, " CROSS_LIT sym %s, tag %s", SymName(sym), string(tag));
+ if( cross_sym(sym) == nilobj ) CrossInit(sym);
+ cs = cross_sym(sym);
+ if( sym == MomentSym && StringEqual(string(tag), KW_NOW) )
+ { /* this is a request for the current time */
+ res = StartMoment();
+ }
+ else
+ { if( !has_tag(sym) )
+ { Error(10, 6, "symbol %s used in cross reference has no %s parameter",
+ WARN, &fpos(x), SymName(sym), KW_TAG);
+ tagerror = TRUE;
+ }
+ for( link = NextUp(Up(cs)); link != cs; link = NextUp(link) )
+ { Parent(db, link);
+ assert( is_word(type(db)), "CrossExpand: db!" );
+ if( DbRetrieve(db, FALSE, sym, string(tag), seq, &dfnum, &dfpos,
+ &dlnum, &cont) )
+ {
+ SwitchScope(nilobj);
+ count = 0;
+ /* condition db != OldCrossDb added to fix inconsistency with */
+ /* the call to AttachEnv below, which always carried it; but */
+ /* there may still be a problem when db != OldCrossDb because */
+ /* in that case all symbols currently visible are declared */
+ /* visible in the database entry; perhaps InitialEnvironment */
+ /* would be best */
+ if( db != OldCrossDb )
+ { SetScope(env, &count, FALSE);
+ debug2(DCR, DD, "Retrieving %s, env = %s", SymName(sym),
+ EchoObject(env));
+ }
+ else
+ { debug1(DCR, DD, "Retrieving %s, env = nilobj", SymName(sym));
+ }
+ res = ReadFromFile(dfnum, dfpos, dlnum);
+ for( i = 1; i <= count; i++ ) PopScope();
+ UnSwitchScope(nilobj);
+ if( db != OldCrossDb ) AttachEnv(env, res);
+ break;
+ }
+ }
+ }
+ break;
+
+
+ case CROSS_PREC:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+
+ if( has_tag(sym) )
+ { int new_seq;
+ if( cross_sym(sym) == nilobj ) CrossInit(sym);
+ cs = cross_sym(sym);
+ assert( cs != nilobj, "CrossExpand/CROSS_FOLL: cs == nilobj!" );
+ assert( type(cs) == CROSS_SYM, "CrossExpand/CROSS_FOLL: type(cs)!" );
+
+ /* generate literal tag buff, used to track this cross reference */
+ fnum = file_num(fpos(tag));
+ new_seq = crtab_getnext(sym, fnum, &crossref_tab);
+ str = FileName(fnum);
+
+ if( StringLength(str) + 5 >= MAX_BUFF )
+ Error(10, 7, "automatically generated tag %s_%d is too long",
+ FATAL, &fpos(x), str, new_seq); /* was cr_seq(cs) */
+ StringCopy(buff, str);
+ StringCat(buff, AsciiToFull("_"));
+ StringCat(buff, StringInt(new_seq)); /* was cr_seq(cs) */
+ debug1(DCR, DD, " CROSS_PREC or CROSS_FOLL generated tag %s", buff);
+
+ /* generate tracking cross reference and index, and add to *crs */
+ tmp = CrossMake(sym, MakeWord(WORD, buff, &fpos(tag)), ctype);
+ New(index, ctype);
+ actual(index) = tmp;
+ Link(index, tmp);
+ if( *crs == nilobj ) New(*crs, CR_LIST);
+ Link(*crs, index);
+
+ /* read tracking cross ref from previous run from cross-ref database */
+ if( AllowCrossDb &&
+ DbRetrieve(OldCrossDb, FALSE, sym, buff, seq, &dfnum, &dfpos,
+ &dlnum, &cont) )
+ {
+ SwitchScope(nilobj);
+ res = ReadFromFile(dfnum, dfpos, dlnum);
+ UnSwitchScope(nilobj);
+ }
+ }
+ else
+ { Error(10, 8, "symbol %s used in cross reference has no %s parameter",
+ WARN, &fpos(x), SymName(sym), KW_TAG);
+ tagerror = TRUE;
+ }
+ break;
+
+
+ default:
+
+ assert(FALSE, "CrossExpand ctype");
+ break;
+
+
+ } /* end switch */
+ if( res == nilobj )
+ { OBJECT envt;
+ /* *** reporting this now whether or not crs_wanted
+ if( ctype > 1 && !tagerror && crs_wanted )
+ *** */
+ if( ctype > 1 && !tagerror )
+ { debug3(DCR, DD, " reporting unresolved cross reference %s%s%s",
+ SymName(sym), KW_CROSS, string(tag));
+ Error(10, 9, "unresolved cross reference %s%s%s",
+ WARN, &fpos(x), SymName(sym), KW_CROSS, string(tag));
+ }
+
+ /* build dummy result with environment attached */
+ /* nb at present we are not adding dummy import closures to this! */
+ New(res, CLOSURE); actual(res) = sym;
+ y = res;
+ debug1(DCR, DD, "First y = %s", SymName(actual(y)));
+ while( enclosing(actual(y)) != StartSym )
+ { New(tmp, CLOSURE);
+ actual(tmp) = enclosing(actual(y));
+ debug0(DCR, DDD, " calling SetEnv from CrossExpand (a)");
+ envt = SetEnv(tmp, nilobj);
+ AttachEnv(envt, y);
+ y = tmp;
+ debug1(DCR, DD, "Later y = %s", SymName(actual(y)));
+ }
+ New(envt, ENV); Link(y, envt);
+ }
+
+ /* set environment, replace x by res, debug and exit */
+ *res_env = DetachEnv(res);
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ assert( type(res) == CLOSURE, "CrossExpand: type(res) != CLOSURE!" );
+ assert( actual(res) == sym, "CrossExpand: actual(res) != sym!" );
+ debug1(DCR, DD, "] CrossExpand returning %s", EchoObject(res));
+ debug1(DCR, DD, " *crs = %s", EchoObject(*crs));
+ debug1(DCR, DD, " *res_env = %s", EchoObject(*res_env));
+ return res;
+ } /* end CrossExpand */
+
+
+ /*@::CrossSequence()@*********************************************************/
+ /* */
+ /* CrossSequence(x) */
+ /* */
+ /* Object x is an insinuated cross-reference that has just been popped off */
+ /* the top of the root galley. Resolve it with the sequence of others. */
+ /* */
+ /*****************************************************************************/
+
+ void CrossSequence(OBJECT x)
+ { OBJECT sym, tag, val, tmp, cs, par, key, hold_key, link, y, env, hold_env;
+ unsigned ctype; FULL_CHAR buff[MAX_BUFF], *seq;
+ FILE_NUM dfnum; int dfpos, dlnum;
+
+ /* if suppressing cross-referencing, dispose x and quit */
+ if( !AllowCrossDb )
+ { if( Up(x) == x ) DisposeObject(x);
+ debug0(DCR, DD, "CrossSequence returning (!AllowCrossDb).");
+ return;
+ }
+
+ /* get interesting fragments from x */
+ debugcond1(DCR, DD, !is_cross(type(x)), " type(x) = %s, x =", Image(type(x)));
+ ifdebugcond(DCR, DD, !is_cross(type(x)), DebugObject(x));
+ assert( is_cross(type(x)), "CrossSequence: type(x)!" );
+ ctype = cross_type(x);
+ Child(tmp, Down(x));
+ assert( type(tmp) == CLOSURE, "CrossSequence: type(tmp)!" );
+ sym = actual(tmp);
+ if( cross_sym(sym) == nilobj ) CrossInit(sym);
+ cs = cross_sym(sym);
+ assert( type(cs) == CROSS_SYM, "CrossSequence: cs!" );
+
+ /* debug output */
+ debug2(DCR, D, "[ CrossSequence %s %s", Image(ctype), EchoObject(x));
+ debug1(DCR, DD, " x = %s", EchoObject(x));
+ ifdebug(DCR, D, DebugObject(cs));
+
+ /* delete as much of x as possible */
+ Child(tag, NextDown(Down(x)));
+ DeleteLink(NextDown(Down(x)));
+ if( Up(x) == x ) DisposeObject(x);
+
+ switch( ctype )
+ {
+ case GALL_FOLL:
+ case GALL_FOLL_OR_PREC:
+ case GALL_PREC:
+
+ /* find the value of key of the galley, if any */
+ val = tag; key = hold_key = nilobj;
+ assert( type(val) == CLOSURE, "CrossSequence/GALL_FOLL: type(val)!" );
+ if( has_key(actual(val)) )
+ { for( link=Down(actual(val)); link != actual(val); link=NextDown(link) )
+ { Child(y, link);
+ if( is_key(y) )
+ { OBJECT nbt[2], nft[2], crs, ntarget, nenclose;
+ nbt[COLM] = nft[COLM] = nbt[ROWM] = nft[ROWM] = nilobj;
+ crs = ntarget = nenclose = nilobj;
+ New(key, CLOSURE);
+ actual(key) = y;
+ New(hold_key, ACAT);
+ Link(hold_key, key);
+ New(env, ENV);
+ Link(env, val);
+ New(hold_env, ACAT);
+ Link(hold_env, env);
+ debug0(DOM, D, " [ calling Manifest from CrossSequence");
+ key = Manifest(key, env, &save_style(val), nbt, nft,
+ &ntarget, &crs, FALSE, TRUE, &nenclose, FALSE);
+ debug0(DOM, D, " ] returning from Manifest");
+ key = ReplaceWithTidy(key, TRUE);
+ DeleteLink(Down(env));
+ DisposeObject(hold_env);
+ }
+ }
+ }
+
+ /* write out the galley */
+ dfnum = DatabaseFileNum(&fpos(val));
+ AppendToFile(val, dfnum, &dfpos, &dlnum);
+
+ /* determine the sequence number or string of this galley */
+ if( key == nilobj )
+ { ++gall_seq(cs);
+ StringCopy(buff, StringFiveInt(gall_seq(cs)));
+ seq = buff;
+ }
+ else if( !is_word(type(key)) )
+ { Error(10, 10, "%s parameter is not a word", WARN, &fpos(key), KW_KEY);
+ debug1(DCR, DD, "key = %s", EchoObject(key));
+ seq = STR_BADKEY;
+ }
+ else if( StringEqual(string(key), STR_EMPTY) )
+ { Error(10, 11, "%s parameter is an empty word", WARN,&fpos(key),KW_KEY);
+ seq = STR_BADKEY;
+ }
+ else seq = string(key);
+
+ /* either write out the index immediately or store it for later */
+ /* if( ctype == GALL_PREC || ctype == GALL_FOLL_OR_PREC ) */
+ if( ctype == GALL_PREC )
+ { if( gall_tag(cs) == nilobj )
+ {
+ if( ctype == GALL_PREC )
+ Error(10, 12, "no %s galley target precedes this %s%s%s", WARN,
+ &fpos(val), SymName(sym), SymName(sym), KW_CROSS, KW_PRECEDING);
+ else
+ Error(10, 22, "no %s galley target follows or precedes this %s%s%s",
+ WARN, &fpos(val), SymName(sym), SymName(sym), KW_CROSS,
+ KW_FOLL_OR_PREC);
+ debug0(DCR, DD, " ... so substituting \"none\"");
+ gall_tag(cs) = MakeWord(WORD, STR_NONE, &fpos(val));
+ }
+ assert( is_word(type(gall_tag(cs))) &&
+ !StringEqual(string(gall_tag(cs)), STR_EMPTY),
+ "CrossSequence: gall_tag!" );
+ debug4(DCR, DD, " inserting galley (%s) %s&%s %s",
+ ctype == GALL_PREC ? "GALL_PREC" : "GALL_FOLL_OR_PREC", SymName(sym),
+ string(gall_tag(cs)), seq);
+ DbInsert(NewCrossDb, TRUE, sym, string(gall_tag(cs)), no_fpos, seq,
+ dfnum, (long) dfpos, dlnum, FALSE);
+ }
+ else
+ { tmp = MakeWord(WORD, seq, &fpos(val));
+ cs_type(tmp) = ctype;
+ cs_fnum(tmp) = dfnum;
+ cs_pos(tmp) = dfpos;
+ cs_lnum(tmp) = dlnum;
+ Link(cs, tmp);
+ debug2(DCR, D, " saving galley (foll) %s&? %s", SymName(sym), seq);
+ }
+ DisposeObject(val);
+ if( hold_key != nilobj ) DisposeObject(hold_key);
+ break;
+
+
+ case GALL_TARG:
+
+ if( gall_tag(cs) != nilobj ) DisposeObject(gall_tag(cs));
+ if( !is_word(type(tag)) || StringEqual(string(tag), STR_EMPTY) )
+ {
+ debug2(DCR, D, " GALL_TARG %s put none for %s",
+ SymName(sym), EchoObject(tag));
+ DisposeObject(tag);
+ gall_tag(cs) = MakeWord(WORD, STR_NONE, no_fpos);
+ }
+ else gall_tag(cs) = tag;
+ debug2(DCR, D, " have new %s gall_targ %s", SymName(sym),
+ EchoObject(gall_tag(cs)));
+ for( link = Down(cs); link != cs; link = NextDown(link) )
+ { Child(y, link);
+ assert( is_word(type(y)) && !StringEqual(string(y), STR_EMPTY),
+ "CrossSequence: GALL_TARG y!" );
+ switch( cs_type(y) )
+ {
+
+ case GALL_PREC:
+ case GALL_FOLL:
+ case GALL_FOLL_OR_PREC:
+
+ debug4(DCR, D, " inserting galley (%s) %s&%s %s",
+ Image(cs_type(y)), SymName(sym), string(gall_tag(cs)), string(y));
+ if( Down(y) != y )
+ Child(val, Down(y));
+ else
+ val = nilobj;
+ DbInsert(NewCrossDb, TRUE, sym, string(gall_tag(cs)), no_fpos,
+ string(y), cs_fnum(y), (long) cs_pos(y), cs_lnum(y), FALSE);
+ link = PrevDown(link);
+ DisposeChild(NextDown(link));
+ break;
+
+
+ case CROSS_LIT:
+ case CROSS_PREC:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+
+ break;
+
+
+ default:
+
+ assert(FALSE, "CrossSequence: cs_type!");
+ break;
+ }
+ }
+ break;
+
+
+ case CROSS_PREC:
+
+ if( target_state(cs) == NO_TARGET )
+ { Error(10, 13, "no %s precedes this %s%s%s", WARN, &fpos(tag),
+ SymName(sym), SymName(sym), KW_CROSS, KW_PRECEDING);
+ break;
+ }
+ if( target_state(cs) == SEEN_TARGET )
+ {
+ debug2(DCR, DD, " inserting %s cross_targ %s",
+ SymName(sym), target_val(cs));
+ AppendToFile(target_val(cs), target_file(cs), &target_pos(cs),
+ &target_lnum(cs));
+ DisposeObject(target_val(cs));
+ target_val(cs) = nilobj;
+ target_state(cs) = WRITTEN_TARGET;
+ }
+ if( !is_word(type(tag)) || StringEqual(string(tag), STR_EMPTY) )
+ {
+ debug2(DCR, DD, " GALL_TARG %s put none for %s", SymName(sym),
+ EchoObject(tag));
+ DisposeObject(tag);
+ tag = MakeWord(WORD, STR_NONE, no_fpos);
+ }
+ debug3(DCR, DD, " inserting cross (prec) %s&%s %s", SymName(sym),
+ string(tag), "0");
+ DbInsert(NewCrossDb, FALSE, sym, string(tag), &fpos(tag), STR_ZERO,
+ target_file(cs), (long) target_pos(cs), target_lnum(cs), TRUE);
+ DisposeObject(tag);
+ break;
+
+
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+
+ if( !is_word(type(tag)) )
+ { Error(10, 14, "tag of %s is not a simple word",
+ WARN, &fpos(tag), SymName(symb(cs)));
+ debug1(DCR, DD, " tag = %s", EchoObject(tag));
+ }
+ else if( StringEqual(string(tag), STR_EMPTY) )
+ {
+ debug1(DCR, DD, " ignoring cross (foll) %s (empty tag)", SymName(sym));
+ }
+ else
+ { Link(cs, tag);
+ cs_fnum(tag) = file_num(fpos(tag));
+ cs_type(tag) = ctype;
+ debug4(DCR, DD, " storing cross (%s) %s&%s %s", Image(ctype),
+ SymName(sym), string(tag), "?");
+ }
+ break;
+
+
+ case CROSS_TARG:
+
+ /* get rid of old target, if any, and add new one */
+ if( target_state(cs) == SEEN_TARGET )
+ {
+ debug2(DCR, DD, " disposing unused %s cross_targ %s", SymName(sym),
+ target_val(cs));
+ DisposeObject(target_val(cs));
+ }
+ debug2(DCR, DD, " remembering new %s cross_targ %s", SymName(sym),
+ EchoObject(tag));
+ target_val(cs) = tag;
+ assert( Up(tag) == tag, "CrossSeq: Up(tag)!" );
+
+ target_file(cs) = DatabaseFileNum(&fpos(tag));
+ target_state(cs) = SEEN_TARGET;
+
+ /* store tag of the galley, if any, and delete excessive right pars */
+ tag = nilobj;
+ assert( type(target_val(cs)) == CLOSURE, "CrossSequence: target_val!" );
+ link = Down(target_val(cs));
+ for( ; link != target_val(cs); link = NextDown(link) )
+ { Child(par, link);
+ if( type(par) == PAR )
+ {
+ assert( Down(par) != par, "CrossSequence: Down(PAR)!" );
+ if( is_tag(actual(par)) )
+ {
+ /* sort out the value of this tag now */
+ Child(tag, Down(par));
+ tag = ReplaceWithTidy(tag, TRUE); /* && */
+ if( !is_word(type(tag)) )
+ { Error(10, 15, "tag of %s is not a simple word",
+ WARN, &fpos(tag), SymName(actual(target_val(cs))));
+ debug1(DCR, DD, " tag = %s", EchoObject(tag));
+ }
+ else if( StringEqual(string(tag), STR_EMPTY) )
+ {
+ debug1(DCR, DD, " ignoring cross (own tag) %s (empty tag)",
+ SymName(sym));
+ }
+ else
+ {
+ cs_fnum(tag) = file_num(fpos(tag));
+ cs_type(tag) = CROSS_LIT;
+ Link(cs, tag);
+ debug4(DCR, DD, " storing cross (%s) %s&%s %s",
+ Image(cs_type(tag)), SymName(sym), string(tag), "?");
+ }
+ }
+ else if( type(actual(par)) == RPAR )
+ {
+ /* replace any oversized right parameter by question marks */
+ Child(y, Down(par));
+ switch( type(y) )
+ {
+ case WORD:
+ case QWORD:
+ case ACAT:
+ case OPEN:
+ case NEXT:
+ case NULL_CLOS:
+ case CROSS:
+ case FORCE_CROSS:
+ case TAGGED:
+
+ /* leave objects of these types as is */
+ break;
+
+
+ default:
+
+ /* replace all other types by three question marks */
+ tmp = MakeWord(WORD, AsciiToFull("???"), &fpos(y));
+ ReplaceNode(tmp, y);
+ DisposeObject(y);
+ break;
+
+ }
+ }
+ }
+ }
+
+ /* if new target is already writable, write it */
+ if( Down(cs) != cs )
+ {
+ debug2(DCR, DD, " writing %s cross_targ %s", SymName(sym),
+ EchoObject(target_val(cs)));
+ AppendToFile(target_val(cs), target_file(cs), &target_pos(cs),
+ &target_lnum(cs));
+ DisposeObject(target_val(cs));
+ target_val(cs) = nilobj;
+ for( link = Down(cs); link != cs; link = NextDown(link) )
+ { Child(tag, link);
+ assert( is_word(type(tag)) && !StringEqual(string(tag), STR_EMPTY),
+ "CrossSeq: non-WORD or empty tag!" );
+ switch( cs_type(tag) )
+ {
+
+ case CROSS_LIT:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+
+ debug3(DCR, DD, " inserting cross (foll) %s&%s %s", SymName(sym),
+ string(tag), "0");
+ DbInsert(NewCrossDb, FALSE, sym, string(tag), &fpos(tag),
+ STR_ZERO, target_file(cs), (long) target_pos(cs),
+ target_lnum(cs), TRUE);
+ link = PrevDown(link);
+ DisposeChild(NextDown(link));
+ break;
+
+
+ case GALL_FOLL:
+ case GALL_PREC:
+ case GALL_FOLL_OR_PREC:
+
+ break;
+
+
+ default:
+
+ assert(FALSE, "CrossSequence: cs_type!");
+ break;
+ }
+ }
+ target_state(cs) = WRITTEN_TARGET;
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "CrossSequence:", Image(ctype));
+ break;
+
+ } /* end switch */
+ debug0(DCR, D, "] CrossSequence returning.");
+ debug0(DCR, D, " cs =");
+ ifdebug(DCR, DD, DebugObject(cs));
+ } /* end CrossSequence */
+
+
+ /*@::CrossClose()@************************************************************/
+ /* */
+ /* CrossClose() */
+ /* */
+ /* Check for dangling forward references, and convert old cross reference */
+ /* database to new one. */
+ /* */
+ /*****************************************************************************/
+
+ void CrossClose(void)
+ { OBJECT link, cs, ylink, y, sym; BOOLEAN g; int len, count;
+ FILE_NUM dfnum; long dfpos, cont; int dlnum;
+ FULL_CHAR buff[MAX_BUFF], seq[MAX_BUFF], tag[MAX_BUFF];
+ debug0(DCR, D, "[ CrossClose()");
+ ifdebug(DCR, DD, if( RootCross != nilobj ) DebugObject(RootCross));
+
+ /* if suppressing cross referencing, return */
+ if( !AllowCrossDb )
+ { debug0(DCR, DD, "CrossClose returning (!AllowCrossDb).");
+ return;
+ }
+
+ /* check for dangling forward references and dispose cross ref structures */
+ if( RootCross != nilobj )
+ { for( link = Down(RootCross); link != RootCross; link = NextDown(link) )
+ { Child(cs, link);
+ sym = symb(cs);
+ assert( type(cs) == CROSS_SYM, "CrossClose: type(cs)!" );
+ count = 0;
+ for( ylink = Down(cs); ylink != cs; ylink = NextDown(ylink) )
+ { Child(y, ylink);
+ assert( is_word(type(y)) && !StringEqual(string(y), STR_EMPTY),
+ "CrossClose: GALL_TARG y!" );
+ switch( cs_type(y) )
+ {
+
+ case CROSS_FOLL:
+
+ debug2(DCR, DD, "cs_type(y) = %s, y = %s",
+ Image(cs_type(y)), EchoObject(y));
+ if( count < 5 )
+ Error(10, 16, "no %s follows this %s%s%s", WARN, &fpos(y),
+ SymName(sym), SymName(sym), KW_CROSS, KW_FOLLOWING);
+ else if( count == 5 )
+ Error(10, 17, "and more undefined %s%s%s", WARN, no_fpos,
+ SymName(sym), KW_CROSS, KW_FOLLOWING);
+ count++;
+ break;
+
+
+ case CROSS_FOLL_OR_PREC:
+
+ /* no following target, so switch to preceding */
+ if( target_state(cs) == NO_TARGET )
+ { Error(10, 18, "no %s follows or precedes this %s%s%s", WARN,
+ &fpos(y), SymName(sym), SymName(sym),KW_CROSS,KW_FOLL_OR_PREC);
+ break;
+ }
+ if( target_state(cs) == SEEN_TARGET )
+ {
+ debug2(DCR, DD, " inserting %s cross_targ %s",
+ SymName(sym), target_val(cs));
+ AppendToFile(target_val(cs), target_file(cs), &target_pos(cs),
+ &target_lnum(cs));
+ DisposeObject(target_val(cs));
+ target_val(cs) = nilobj;
+ target_state(cs) = WRITTEN_TARGET;
+ }
+ if( !is_word(type(y)) || StringEqual(string(y), STR_EMPTY) )
+ {
+ debug2(DCR, DD, " CROSS_FOLL_OR_PREC %s put none for %s",
+ SymName(sym), EchoObject(y));
+ y = MakeWord(WORD, STR_NONE, no_fpos);
+ }
+ debug4(DCR, DD, " inserting cross (%s) %s&%s %s",
+ Image(cs_type(y)), SymName(sym), string(y), "0");
+ DbInsert(NewCrossDb, FALSE, sym, string(y), &fpos(y), STR_ZERO,
+ target_file(cs), (long) target_pos(cs), target_lnum(cs), TRUE);
+ break;
+
+
+ case GALL_FOLL:
+
+ debug2(DCR, DD, "cs_type(y) = %s, y = %s",
+ Image(cs_type(y)), EchoObject(y));
+ if( count < 5 )
+ Error(10, 19, "no %s follows this %s%s%s", WARN, &fpos(y),
+ SymName(sym), SymName(sym), KW_CROSS, KW_FOLLOWING);
+ else if( count == 5 )
+ Error(10, 20, "and more undefined %s%s%s", WARN, no_fpos,
+ SymName(sym), KW_CROSS, KW_FOLLOWING);
+ DbInsert(NewCrossDb, TRUE, sym, STR_NONE, no_fpos,
+ string(y), cs_fnum(y), (long) cs_pos(y), cs_lnum(y), FALSE);
+ count++;
+ break;
+
+
+ case GALL_FOLL_OR_PREC:
+
+ if( gall_tag(cs) == nilobj )
+ { Error(10, 21, "no %s precedes or follows this %s%s%s", WARN,
+ &fpos(y), SymName(sym), SymName(sym),KW_CROSS,KW_FOLL_OR_PREC);
+ gall_tag(cs) = MakeWord(WORD, STR_NONE, no_fpos);
+ }
+ debug3(DCR, DD, " inserting galley (foll_or_prec) %s&%s %s",
+ SymName(sym), string(gall_tag(cs)), string(y));
+ DbInsert(NewCrossDb, TRUE, sym, string(gall_tag(cs)), no_fpos,
+ string(y), cs_fnum(y), (long) cs_pos(y), cs_lnum(y), FALSE);
+ break;
+
+
+ default:
+
+ debug1(DCR, DD, "CrossClose: unknown cs_type %s",
+ Image(cs_type(y)));
+ assert(FALSE, "CrossClose: unknown cs_type!");
+ break;
+ }
+ }
+ ifdebug(ANY, D,
+ if( target_state(cs) == SEEN_TARGET ) DisposeObject(target_val(cs));
+ if( gall_tag(cs) != nilobj ) DisposeObject(gall_tag(cs));
+ );
+ }
+ ifdebug(ANY, D, DisposeObject(RootCross); );
+ }
+
+ /* add to NewCrossDb those entries of OldCrossDb from other source files */
+ /* but set check to FALSE so that we don't worry about duplication there */
+ cont = 0L; len = StringLength(DATA_SUFFIX);
+ while( DbRetrieveNext(OldCrossDb,&g,&sym,tag,seq,&dfnum,&dfpos,&dlnum,&cont))
+ { if( g ) continue;
+ StringCopy(buff, FileName(dfnum));
+ StringCopy(&buff[StringLength(buff) - len], STR_EMPTY);
+ if( FileNum(buff, STR_EMPTY) == NO_FILE )
+ DbInsert(NewCrossDb, FALSE, sym, tag, no_fpos, seq, dfnum, dfpos,
+ dlnum, FALSE);
+ }
+
+ /* close OldCrossDb's .li file so that NewCrossDb can use its name */
+ DbClose(OldCrossDb);
+
+ /* make NewCrossDb readable, for next run */
+ DbConvert(NewCrossDb, TRUE);
+
+ debug0(DCR, D, "] CrossClose returning.");
+ ifdebug(DCR, DD, crtab_debug(crossref_tab, stderr));
+ } /* end CrossClose */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z11.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z11.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z11.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,305 ----
+ /*@z11.c:Style Service:EchoStyle()@*******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z11.c */
+ /* MODULE: Style Service */
+ /* EXTERNS: EchoStyle(), SpaceChange(), BreakChange() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ #if DEBUG_ON
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *EchoStyle(style) */
+ /* */
+ /* Returns a string showing the value of the style. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EchoStyle(STYLE *style)
+ { static FULL_CHAR res[100];
+ static char *hyphwords[] = { "hyph_undef", "hyph_off", "hyph_on" };
+ static char *fillwords[] = { "fill_undef", "fill_off", "fill_on" };
+ static char *spacewords[] = { "lout", "comp", "troff", "tex" };
+ static char *displaywords[] = { "undef", "adjust", "outdent", "oragged",
+ "left", "centre", "right", "do" };
+
+ StringCopy(res, AsciiToFull("["));
+ StringCat(res, EchoCatOp(VCAT,mark(line_gap(*style)),join(line_gap(*style))));
+ StringCat(res, EchoGap(&line_gap(*style)));
+ StringCat(res, AsciiToFull(", "));
+ StringCat(res, font(*style) == 0 ?
+ AsciiToFull("nofont") : FontFamilyAndFace(font(*style)));
+ StringCat(res, AsciiToFull(" ("));
+ StringCat(res, AsciiToFull(spacewords[space_style(*style)]));
+ StringCat(res, AsciiToFull(" "));
+ StringCat(res, EchoGap(&space_gap(*style)));
+ StringCat(res, AsciiToFull("), "));
+ StringCat(res, AsciiToFull(hyph_style(*style) < 3 ?
+ hyphwords[hyph_style(*style)] : "?"));
+ StringCat(res, AsciiToFull(":"));
+ StringCat(res, AsciiToFull(fill_style(*style) < 3 ?
+ fillwords[fill_style(*style)] : "?"));
+ StringCat(res, AsciiToFull(":"));
+ StringCat(res, AsciiToFull(display_style(*style) < 7 ?
+ displaywords[display_style(*style)] : "?"));
+ if( small_caps(*style) > 0 ) StringCat(res, AsciiToFull(":smallcaps"));
+ if( vadjust(*style) ) StringCat(res, AsciiToFull(":vadjust"));
+ if( hadjust(*style) ) StringCat(res, AsciiToFull(":hadjust"));
+ if( padjust(*style) ) StringCat(res, AsciiToFull(":padjust"));
+ if( yunit(*style) != 0 )
+ { StringCat(res, AsciiToFull(":y="));
+ StringCat(res, EchoLength(yunit(*style)));
+ }
+ if( zunit(*style) != 0 )
+ { StringCat(res, AsciiToFull(":z="));
+ StringCat(res, EchoLength(zunit(*style)));
+ }
+ if( nobreakfirst(*style) ) StringCat(res, AsciiToFull(":NBF"));
+ if( nobreaklast(*style) ) StringCat(res, AsciiToFull(":NBL"));
+ StringCat(res, AsciiToFull("]"));
+ return res;
+ } /* end EchoStyle */
+ #endif
+
+
+ /*@::SpaceChange()@***********************************************************/
+ /* */
+ /* SpaceChange(style, x) */
+ /* */
+ /* Change the current break style as indicated by object x. */
+ /* */
+ /*****************************************************************************/
+
+ static void changespace(STYLE *style, OBJECT x)
+ { GAP res_gap; unsigned gap_inc;
+ assert( is_word(type(x)), "changespace: type(x)!" );
+ if( beginsbreakstyle(string(x)[0]) )
+ {
+ /* should be a new space style option */
+ if( StringEqual(string(x), STR_SPACE_LOUT) )
+ space_style(*style) = SPACE_LOUT;
+ else if( StringEqual(string(x), STR_SPACE_COMPRESS) )
+ space_style(*style) = SPACE_COMPRESS;
+ else if( StringEqual(string(x), STR_SPACE_SEPARATE) )
+ space_style(*style) = SPACE_SEPARATE;
+ else if( StringEqual(string(x), STR_SPACE_TROFF) )
+ space_style(*style) = SPACE_TROFF;
+ else if( StringEqual(string(x), STR_SPACE_TEX) )
+ space_style(*style) = SPACE_TEX;
+ else Error(11, 1, "unknown option to %s symbol (%s)",
+ WARN, &fpos(x), KW_SPACE, string(x));
+ }
+ else /* should be a new space gap */
+ { GetGap(x, style, &res_gap, &gap_inc);
+ if( gap_inc != GAP_ABS && units(res_gap) != units(space_gap(*style)) )
+ { Error(11, 2, "spacing %s is not compatible with current spacing",
+ WARN, &fpos(x), string(x));
+ }
+ else
+ { units(space_gap(*style)) = units(res_gap);
+ mode(space_gap(*style)) = mode(res_gap);
+ width(space_gap(*style)) = gap_inc == GAP_ABS ? width(res_gap) :
+ gap_inc == GAP_INC ? width(space_gap(*style)) + width(res_gap) :
+ find_max(width(space_gap(*style)) - width(res_gap), 0);
+ }
+ }
+ debug1(DSS, D, "SpaceChange returning %s", EchoStyle(style));
+ } /* end SpaceChange */
+
+
+ void SpaceChange(STYLE *style, OBJECT x)
+ { OBJECT link, y;
+ debug2(DSS, D, "SpaceChange(%s, %s)", EchoStyle(style), EchoObject(x));
+ switch( type(x) )
+ {
+ case NULL_CLOS: break;
+
+ case WORD:
+ case QWORD: if( !StringEqual(string(x), STR_EMPTY) )
+ changespace(style, x);
+ break;
+
+
+ case ACAT: for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ || type(y) == NULL_CLOS ) continue;
+ else if( is_word(type(y)) )
+ { if( !StringEqual(string(y), STR_EMPTY) )
+ changespace(style, y);
+ }
+ else Error(11, 3, "invalid left parameter of %s",
+ WARN, &fpos(x), KW_SPACE);
+ }
+ break;
+
+
+ default: Error(11, 4, "invalid left parameter of %s",
+ WARN, &fpos(x), KW_SPACE);
+ break;
+ }
+ debug1(DSS, D, "SpaceChange returning %s", EchoStyle(style));
+ } /* end SpaceChange */
+
+
+ /*@::BreakChange()@***********************************************************/
+ /* */
+ /* BreakChange(style, x) */
+ /* */
+ /* Change the current break style as indicated by object x. */
+ /* */
+ /*****************************************************************************/
+
+ static void changebreak(STYLE *style, OBJECT x)
+ { GAP res_gap; unsigned gap_inc;
+ if( beginsbreakstyle(string(x)[0]) )
+ {
+ /* should be a new break style option */
+ if( StringEqual(string(x), STR_BREAK_HYPHEN) )
+ hyph_style(*style) = HYPH_ON;
+ else if( StringEqual(string(x), STR_BREAK_NOHYPHEN) )
+ hyph_style(*style) = HYPH_OFF;
+ else if( StringEqual(string(x), STR_BREAK_ADJUST) )
+ fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_ADJUST;
+ else if( StringEqual(string(x), STR_BREAK_OUTDENT) )
+ fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_OUTDENT;
+ else if( StringEqual(string(x), STR_BREAK_RAGGED) )
+ fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_LEFT;
+ else if( StringEqual(string(x), STR_BREAK_CRAGGED) )
+ fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_CENTRE;
+ else if( StringEqual(string(x), STR_BREAK_RRAGGED) )
+ fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_RIGHT;
+ else if( StringEqual(string(x), STR_BREAK_ORAGGED) )
+ fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_ORAGGED;
+ else if( StringEqual(string(x), STR_BREAK_LINES) )
+ fill_style(*style) = FILL_OFF, display_style(*style) = DISPLAY_LEFT;
+ else if( StringEqual(string(x), STR_BREAK_CLINES) )
+ fill_style(*style) = FILL_OFF, display_style(*style) = DISPLAY_CENTRE;
+ else if( StringEqual(string(x), STR_BREAK_RLINES) )
+ fill_style(*style) = FILL_OFF, display_style(*style) = DISPLAY_RIGHT;
+ else if( StringEqual(string(x), STR_BREAK_NOFIRST) )
+ nobreakfirst(*style) = TRUE;
+ else if( StringEqual(string(x), STR_BREAK_FIRST) )
+ nobreakfirst(*style) = FALSE;
+ else if( StringEqual(string(x), STR_BREAK_NOLAST) )
+ nobreaklast(*style) = TRUE;
+ else if( StringEqual(string(x), STR_BREAK_LAST) )
+ nobreaklast(*style) = FALSE;
+ else Error(11, 5, "unknown option to %s symbol (%s)",
+ WARN, &fpos(x), KW_BREAK, string(x));
+ }
+ else /* should be a new inter-line gap */
+ { GetGap(x, style, &res_gap, &gap_inc);
+ if( gap_inc != GAP_ABS && units(res_gap) != units(line_gap(*style)) )
+ Error(11, 6, "line spacing %s is not compatible with current spacing",
+ WARN, &fpos(x), string(x));
+ else
+ { units(line_gap(*style)) = units(res_gap);
+ mode(line_gap(*style)) = mode(res_gap);
+ width(line_gap(*style)) = gap_inc == GAP_ABS ? width(res_gap) :
+ gap_inc == GAP_INC ? width(line_gap(*style)) + width(res_gap) :
+ find_max(width(line_gap(*style)) - width(res_gap), 0);
+ }
+ }
+ } /* end changebreak */
+
+ void BreakChange(STYLE *style, OBJECT x)
+ { OBJECT link, y;
+ debug3(DSS, D, "BreakChange(%s, %s at %s)", EchoStyle(style),
+ EchoObject(x), EchoFilePos(&fpos(x)));
+ switch( type(x) )
+ {
+ case NULL_CLOS: break;
+
+ case WORD:
+ case QWORD: if( !StringEqual(string(x), STR_EMPTY) )
+ changebreak(style, x);
+ break;
+
+
+ case ACAT: for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ || type(y) == NULL_CLOS ) continue;
+ else if( is_word(type(y)) )
+ { if( !StringEqual(string(y), STR_EMPTY) )
+ changebreak(style, y);
+ }
+ else Error(11, 7, "invalid left parameter of %s",
+ WARN, &fpos(x), KW_BREAK);
+ }
+ break;
+
+
+ default: Error(11, 8, "invalid left parameter of %s",
+ WARN, &fpos(x), KW_BREAK);
+ break;
+ }
+ debug1(DSS, D, "BreakChange returning %s", EchoStyle(style));
+ } /* end BreakChange */
+
+
+ /*@::YUnitChange(), ZUnitChange()@********************************************/
+ /* */
+ /* YUnitChange(style, x) */
+ /* */
+ /* Change the current value of the y unit as indicated by object x. */
+ /* */
+ /*****************************************************************************/
+
+ void YUnitChange(STYLE *style, OBJECT x)
+ { GAP res_gap; unsigned gap_inc;
+ GetGap(x, style, &res_gap, &gap_inc);
+ if( units(res_gap) != FIXED_UNIT )
+ Error(11, 9, "this unit not allowed with %s symbol",
+ WARN, &fpos(x), KW_YUNIT);
+ else
+ { if( gap_inc == GAP_ABS ) yunit(*style) = width(res_gap);
+ else if( gap_inc == GAP_INC ) yunit(*style) += width(res_gap);
+ else yunit(*style) = find_max(yunit(*style) - width(res_gap), 0);
+ }
+ } /* end YUnitChange */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ZUnitChange(style, x) */
+ /* */
+ /* Change the current value of the z unit as indicated by object x. */
+ /* */
+ /*****************************************************************************/
+
+ void ZUnitChange(STYLE *style, OBJECT x)
+ { GAP res_gap; unsigned gap_inc;
+ GetGap(x, style, &res_gap, &gap_inc);
+ if( units(res_gap) != FIXED_UNIT )
+ Error(11, 10, "this unit not allowed with %s symbol",
+ WARN, &fpos(x), KW_ZUNIT);
+ else
+ { if( gap_inc == GAP_ABS ) zunit(*style) = width(res_gap);
+ else if( gap_inc == GAP_INC ) zunit(*style) += width(res_gap);
+ else zunit(*style) = find_max(zunit(*style) - width(res_gap), 0);
+ }
+ } /* end ZUnitChange */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z12.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z12.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z12.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1372 ----
+ /*@z12.c:Size Finder:MinSize()@***********************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z12.c */
+ /* MODULE: Size Finder */
+ /* EXTERNS: MinSize() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define line_breaker(g) \
+ (vspace(g) > 0 || (units(gap(g)) == FRAME_UNIT && width(gap(g)) > FR))
+ #define IG_LOOKING 0
+ #define IG_NOFILE 1
+ #define IG_BADFILE 2
+ #define IG_BADSIZE 3
+ #define IG_OK 4
+
+ #if DEBUG_ON
+ static int debug_depth = 1;
+ static int debug_depth_max = 5;
+ #endif
+
+ /*****************************************************************************/
+ /* */
+ /* KernLength(fnum, ch1, ch2, res) */
+ /* */
+ /* Set res to the kern length between ch1 and ch2 in font fnum, or 0 if */
+ /* none. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_LENGTH KernLength(FONT_NUM fnum, FULL_CHAR ch1, FULL_CHAR ch2)
+ { FULL_LENGTH res;
+ MAPPING m = font_mapping(finfo[fnum].font_table);
+ FULL_CHAR *unacc = MapTable[m]->map[MAP_UNACCENTED];
+ int ua_ch1 = unacc[ch1];
+ int ua_ch2 = unacc[ch2];
+ int i = finfo[fnum].kern_table[ua_ch1], j;
+ if( i == 0 ) res = 0;
+ else
+ { FULL_CHAR *kc = finfo[fnum].kern_chars;
+ for( j = i; kc[j] > ua_ch2; j++ );
+ res = (kc[j] == ua_ch2) ?
+ finfo[fnum].kern_sizes[finfo[fnum].kern_value[j]] : 0;
+ }
+ return res;
+ } /* end KernLength */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BuildSpanner(x) */
+ /* */
+ /* Build a spanning structure starting at x. */
+ /* */
+ /*****************************************************************************/
+
+ static BOOLEAN BuildSpanner(OBJECT x)
+ { OBJECT link, prnt, y, hspanner, vspanner, end_link, t, hprnt, vprnt, spanobj;
+ BOOLEAN need_hspanner, need_vspanner;
+ debug1(DSF, DD, "BuildSpanner(%s)", EchoObject(x));
+ assert( type(x) == START_HVSPAN || type(x) == START_HSPAN ||
+ type(x) == START_VSPAN , "BuildSpanner: type(x) != SPAN!" );
+ Child(spanobj, Down(x));
+ assert(Up(spanobj) == LastUp(spanobj), "BuildSpanner: spanobj!" );
+ DeleteLink(Up(spanobj));
+
+ need_hspanner = (type(x) == START_HVSPAN || type(x) == START_HSPAN);
+ if( need_hspanner )
+ {
+ /* check that column context is legal, if not exit with FALSE */
+ Parent(hprnt, UpDim(x, COLM));
+ if( type(hprnt) != COL_THR )
+ {
+ Error(12, 10, "%s deleted (not in column)", WARN,&fpos(x),Image(type(x)));
+ return FALSE;
+ }
+
+ /* build hspanner object and interpose it between x and spanobj */
+ New(hspanner, HSPANNER);
+ FposCopy(fpos(hspanner), fpos(x));
+ spanner_broken(hspanner) = FALSE;
+ Link(x, hspanner);
+ Link(hspanner, spanobj);
+
+ /* link later members of the spanner on the same row mark to hspanner */
+ /* by definition this is every member across to the last @HSpan before a */
+ /* @StartHVSpan or @StartHSpan or @StartVSpan or @VSpan or end of row */
+ Parent(prnt, UpDim(x, ROWM));
+ if( type(prnt) != ROW_THR )
+ {
+ Error(12, 11, "%s symbol out of place", FATAL, &fpos(x), Image(type(x)));
+ }
+ assert(type(prnt) == ROW_THR, "BuildSpanner: type(prnt)!");
+ spanner_sized(hspanner) = spanner_fixed(hspanner) = 0;
+ spanner_count(hspanner) = 1;
+ end_link = NextDown(UpDim(x, ROWM));
+ for( link = NextDown(UpDim(x, ROWM)); link != prnt; link = NextDown(link) )
+ { Child(y, link);
+ debug2(DSF, DD, " examining ver %s %s", Image(type(y)), EchoObject(y));
+ if( type(y) == HSPAN )
+ end_link = NextDown(link);
+ else if( type(y) == START_HVSPAN || type(y) == START_HSPAN ||
+ type(y) == START_VSPAN || type(y) == VSPAN )
+ break;
+ }
+ for( link = NextDown(UpDim(x,ROWM)); link!=end_link; link = NextDown(link) )
+ {
+ /* each of these components becomes @HSpan and is added to hspanner */
+ Child(y, link);
+ New(t, HSPAN);
+ FposCopy(fpos(t), fpos(y));
+ ReplaceNode(t, y);
+ DisposeObject(y);
+ Link(t, hspanner);
+ spanner_count(hspanner)++;
+ }
+ }
+ else Link(x, spanobj);
+
+ need_vspanner = (type(x) == START_HVSPAN || type(x) == START_VSPAN);
+ if( need_vspanner )
+ {
+ /* check that row context is legal, if not exit with FALSE */
+ Parent(vprnt, UpDim(x, ROWM));
+ if( type(vprnt) != ROW_THR )
+ {
+ Error(12, 12, "%s deleted (not in row)", WARN, &fpos(x), Image(type(x)));
+ return FALSE;
+ }
+
+ /* build vspanner object and interpose it between x and spanobj */
+ New(vspanner, VSPANNER);
+ FposCopy(fpos(vspanner), fpos(x));
+ spanner_broken(vspanner) = FALSE;
+ Link(x, vspanner);
+ Link(vspanner, spanobj);
+
+ /* link later members of the spanner on the same column mark to vspanner */
+ /* by definition this is every member down to the last @VSpan before a */
+ /* @StartHVSpan or @StartHSpan or @StartVSpan or @HSpan or end of column */
+ Parent(prnt, UpDim(x, COLM));
+ assert(type(prnt) == COL_THR, "BuildSpanner: type(prnt)!");
+ spanner_sized(vspanner) = spanner_fixed(vspanner) = 0;
+ spanner_count(vspanner) = 1;
+ end_link = NextDown(UpDim(x, COLM));
+ for( link = NextDown(UpDim(x, COLM)); link != prnt; link = NextDown(link) )
+ { Child(y, link);
+ debug2(DSF, DD, " examining hor %s %s", Image(type(y)), y);
+ if( type(y) == VSPAN )
+ end_link = NextDown(link);
+ else if( type(y) == START_HVSPAN || type(y) == START_HSPAN ||
+ type(y) == START_VSPAN || type(y) == HSPAN )
+ break;
+ }
+ for( link = NextDown(UpDim(x,COLM)); link!=end_link; link = NextDown(link) )
+ {
+ /* each of these components becomes @VSpan and is added to vspanner */
+ Child(y, link);
+ New(t, VSPAN);
+ FposCopy(fpos(t), fpos(y));
+ ReplaceNode(t, y);
+ DisposeObject(y);
+ Link(t, vspanner);
+ spanner_count(vspanner)++;
+ }
+ }
+ else Link(x, spanobj);
+
+ debug2(DSF, DD, "BuildSpanner returning TRUE (rows = %d, cols = %d)",
+ need_vspanner ? spanner_count(vspanner) : 0,
+ need_hspanner ? spanner_count(hspanner) : 0);
+ ifdebug(DSF, DD, DebugObject(x));
+ return TRUE;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN FindSpannerGap(thr, cat_op, gp) */
+ /* */
+ /* For the purposes of calculating spanning spacing, find the gap between */
+ /* this object and the preceding one under the nearest cat_op. */
+ /* */
+ /* If found, set &gp to the gap object and return TRUE; else return FALSE. */
+ /* */
+ /*****************************************************************************/
+
+ static BOOLEAN FindSpannerGap(OBJECT thr, unsigned dim, unsigned cat_op,
+ OBJECT *res)
+ { OBJECT link, x;
+
+ /* find nearest enclosing cat_op that we aren't the first element of */
+ link = UpDim(thr, dim);
+ Parent(x, link);
+ while( (type(x) != cat_op || type(PrevDown(link)) != LINK) && Up(x) != x )
+ { link = UpDim(x, dim);
+ Parent(x, link);
+ }
+
+ /* if found and a gap precedes thr's component of it, return that gap */
+ if( type(x) == cat_op && type(PrevDown(link)) == LINK )
+ { Child(*res, PrevDown(link));
+ assert(type(*res) == GAP_OBJ, "FindSpannerGap: type(*res)!" );
+ }
+ else if( type(x) == HEAD && gall_dir(x)==dim && type(PrevDown(link))==LINK )
+ { Child(*res, PrevDown(link));
+ assert(type(*res) == GAP_OBJ, "FindSpannerGap (HEAD): type(*res)!" );
+ nobreak(gap(*res)) = TRUE;
+ }
+ else *res = nilobj;
+
+ debug1(DSF, DD, " FindSpannerGap returning %s", EchoObject(*res));
+ return (*res != nilobj);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void SpannerAvailableSpace(x, dim, rb, rf) */
+ /* */
+ /* Work out the total space available to hold this spanner, and set */
+ /* (*rb, *rf) to record this value. This space equals the total width */
+ /* of all columns (and their intervening gaps) spanned, with the mark */
+ /* of the last column being the one separating rb from rf. */
+ /* */
+ /*****************************************************************************/
+
+ void SpannerAvailableSpace(OBJECT y, int dim, FULL_LENGTH *resb,
+ FULL_LENGTH *resf)
+ { OBJECT slink, s, thr, gp, prevthr;
+ FULL_LENGTH b, f;
+ unsigned thr_type, cat_type;
+
+ assert( type(y) == HSPANNER || type(y) == VSPANNER, "SpannerAvail!");
+ debug4(DSF, DD, "SpannerAvailableSpace(%d %s %s, %s)",
+ spanner_count(y), Image(type(y)), EchoObject(y), dimen(dim));
+ if( dim == COLM )
+ { thr_type = COL_THR;
+ cat_type = HCAT;
+ }
+ else
+ { thr_type = ROW_THR;
+ cat_type = VCAT;
+ }
+
+ /* first calculate the total space consumed in earlier spans */
+ /* Invariant: (b, f) is the size up to and including prev */
+ /* */
+ prevthr = nilobj;
+ for( slink = Up(y); slink != y; slink = NextUp(slink) )
+ { Parent(s, slink);
+ Parent(thr, UpDim(s, dim));
+ if( type(thr) == thr_type )
+ {
+ assert( thr_state(thr) == SIZED, "SpannerAvailableSpace: thr_state!" );
+ if( prevthr == nilobj )
+ {
+ /* this is the first column spanned over */
+ b = back(thr, dim);
+ f = fwd(thr, dim);
+ debug4(DSF, DD, " first component %s,%s: b = %s, f = %s",
+ EchoLength(back(thr, dim)), EchoLength(fwd(thr, dim)),
+ EchoLength(b), EchoLength(f));
+ }
+ else if( FindSpannerGap(thr, dim, cat_type, &gp) )
+ {
+ /* this is a subquent column spanned over */
+ b += MinGap(fwd(prevthr, dim), back(thr, dim), fwd(thr, dim), &gap(gp));
+ f = fwd(thr, dim);
+ debug5(DSF, DD, " later component %s,%s: gp = %s, b = %s, f = %s",
+ EchoLength(back(thr, dim)), EchoLength(fwd(thr, dim)), EchoObject(gp),
+ EchoLength(b), EchoLength(f));
+ }
+ else
+ {
+ Error(12, 13, "search for gap preceding %s failed, using zero",
+ WARN, &fpos(s), Image(type(s)));
+ b += fwd(prevthr, dim) + back(thr, dim);
+ f = fwd(thr, dim);
+ debug4(DSF, DD, " later component %s,%s: (no gap), b = %s, f = %s",
+ EchoLength(back(thr, dim)), EchoLength(fwd(thr, dim)),
+ EchoLength(b), EchoLength(f));
+ }
+ }
+ else
+ Error(12, 14, "%s deleted (out of place)", WARN,&fpos(s),Image(type(s)));
+ prevthr = thr;
+ }
+
+ *resb = b;
+ *resf = f;
+ SetConstraint(constraint(y), MAX_FULL_LENGTH, b+f, MAX_FULL_LENGTH);
+ debug2(DSF, DD, "SpannerAvailableSpace returning %s,%s",
+ EchoLength(*resb), EchoLength(*resf));
+ } /* end SpannerAvailableSpace */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT MinSize(x, dim, extras) */
+ /* */
+ /* Set fwd(x, dim) and back(x, dim) to their minimum possible values. */
+ /* If dim == ROWM, construct an extras list and return it in *extras. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT MinSize(OBJECT x, int dim, OBJECT *extras)
+ { OBJECT y, z, link, prev, t, g, full_name;
+ FULL_LENGTH b, f, dble_fwd, llx, lly, urx, ury; int status, read_status;
+ float fllx, flly, furx, fury;
+ BOOLEAN dble_found, found, will_expand, first_line, cp;
+ FILE *fp; FULL_CHAR buff[MAX_BUFF];
+
+ debug2(DSF, DD, "[ MinSize( %s, %s, extras )", EchoObject(x), dimen(dim));
+ debugcond4(DSF, D, dim == COLM && debug_depth++ < debug_depth_max,
+ "%*s[ MinSize(COLM, %s %d)", (debug_depth-1)*2, " ",
+ Image(type(x)), (int) x);
+ ifdebug(DSF, DDD, DebugObject(x));
+
+ switch( type(x) )
+ {
+
+ case WORD:
+ case QWORD:
+
+ if( dim == COLM ) FontWordSize(x);
+ break;
+
+
+ case CROSS:
+ case FORCE_CROSS:
+
+ /* add index to the cross-ref */
+ if( dim == ROWM )
+ { New(z, cross_type(x)); /* CROSS_PREC, CROSS_FOLL or CROSS_FOLL_OR_PREC */
+ debug2(DCR, DD, " MinSize CROSS: %ld %s", (long) x, EchoObject(x));
+ actual(z) = x;
+ Link(z, x); /* new code to avoid disposal */
+ Link(*extras, z);
+ debug2(DCR, DD, " MinSize index: %ld %s", (long) z, EchoObject(z));
+ }
+ back(x, dim) = fwd(x, dim) = 0;
+ break;
+
+
+ case PAGE_LABEL:
+
+ if( dim == ROWM )
+ { New(z, PAGE_LABEL_IND);
+ actual(z) = x;
+ Link(z, x);
+ Link(*extras, z);
+ }
+ back(x, dim) = fwd(x, dim) = 0;
+ break;
+
+
+ case NULL_CLOS:
+
+ back(x, dim) = fwd(x, dim) = 0;
+ break;
+
+
+ case HEAD:
+
+ if( dim == ROWM )
+ {
+ /* replace the galley x by a dummy closure y */
+ New(y, NULL_CLOS);
+ FposCopy(fpos(y), fpos(x));
+ ReplaceNode(y, x);
+
+ if( has_key(actual(x)) )
+ {
+ /* galley is sorted, make insinuated cross-reference */
+ New(z, foll_or_prec(x));
+ pinpoint(z) = y;
+ Child(t, Down(x));
+ actual(z) = CrossMake(whereto(x), t, (int) type(z));
+ Link(*extras, z);
+ DisposeObject(x);
+ debug1(DCR, DDD, " MinSize: %s", EchoObject(z));
+ }
+ else
+ {
+ /* galley is following, make UNATTACHED */
+ New(z, UNATTACHED); Link(z, x);
+ pinpoint(z) = y;
+ Link(*extras, z);
+ debug1(DCR, DDD, " MinSize: %s", EchoObject(z));
+ }
+ x = y; /* now sizing y, not x */
+ back(x, COLM) = fwd(x, COLM) = 0; /* fix non-zero size @Null bug!! */
+ }
+ else
+ {
+ debug2(DGT, DD, "MinSize setting external_ver(%s %s) = FALSE",
+ Image(type(x)), SymName(actual(x)));
+ external_ver(x) = external_hor(x) = FALSE;
+ }
+ back(x, dim) = fwd(x, dim) = 0;
+ break;
+
+
+ case CLOSURE:
+
+ assert( !has_target(actual(x)), "MinSize: CLOSURE has target!" );
+ if( dim == ROWM )
+ { if( indefinite(actual(x)) )
+ { New(z, RECEPTIVE);
+ actual(z) = x;
+ Link(*extras, z);
+ debug1(DCR, DDD, " MinSize: %s", EchoObject(z));
+ }
+ else if( recursive(actual(x)) )
+ { New(z, RECURSIVE);
+ actual(z) = x;
+ Link(*extras, z);
+ debug1(DCR, DDD, " MinSize: %s", EchoObject(z));
+ }
+ else
+ { assert(FALSE, "MinSize: definite non-recursive closure");
+ }
+ }
+ else
+ {
+ debug2(DGT, DD, "MinSize setting external_ver(%s %s) = FALSE",
+ Image(type(x)), SymName(actual(x)));
+ external_ver(x) = external_hor(x) = FALSE;/* nb must be done here!*/
+ }
+ back(x, dim) = fwd(x, dim) = 0;
+ break;
+
+
+ case ONE_COL:
+ case ONE_ROW:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ break;
+
+
+ case BACKGROUND:
+
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ Child(y, LastDown(x));
+ y = MinSize(y, dim, extras);
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ break;
+
+
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+
+ /* if first touch, build the spanner */
+ if( (type(x) == START_HVSPAN || type(x) == START_HSPAN ||
+ type(x) == START_VSPAN) && dim == COLM )
+ {
+ if( !BuildSpanner(x) )
+ {
+ t = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ ReplaceNode(t, x);
+ x = t;
+ back(x, COLM) = fwd(x, COLM) = 0;
+ break;
+ }
+ }
+
+ /* if first vertical touch, break if necessary */
+ if( (type(x) == START_HVSPAN || type(x) == START_HSPAN) && dim == ROWM )
+ { CONSTRAINT c;
+
+ /* find the HSPANNER */
+ Child(t, DownDim(x, COLM));
+ assert( type(t) == HSPANNER, "MinSize/SPAN: type(t) != HSPANNER!" );
+
+ /* find the available space for this HSPANNER and break it */
+ SpannerAvailableSpace(t, COLM, &b, &f);
+ SetConstraint(c, MAX_FULL_LENGTH, b+f, MAX_FULL_LENGTH);
+ debug2(DSF,DD, " BreakObject(%s,%s)",EchoObject(t),EchoConstraint(&c));
+ t = BreakObject(t, &c);
+ spanner_broken(t) = TRUE;
+ }
+
+ /* make sure that HSPAN links to HSPANNER, VSPAN to VSPANNER */
+ /* NB must follow breaking since that could affect the value of y */
+ Child(y, DownDim(x, dim));
+ if( (type(x) == HSPAN && type(y) != HSPANNER) ||
+ (type(x) == VSPAN && type(y) != VSPANNER) )
+ {
+ if( dim == COLM )
+ Error(12, 15, "%s replaced by empty object (out of place)",
+ WARN, &fpos(x), Image(type(x)));
+ back(x, dim) = fwd(x, dim) = 0;
+ break;
+ }
+
+ /* now size the object */
+ if( (type(x)==HSPAN && dim==ROWM) || (type(x)==VSPAN && dim==COLM) )
+ {
+ /* perp dimension, covered by preceding @Span, so may be zero. */
+ back(x, dim) = fwd(x, dim) = 0;
+ }
+ else if( type(y) != HSPANNER && type(y) != VSPANNER )
+ {
+ /* no spanning in this dimension */
+ MinSize(y, dim, extras);
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ }
+ else if( ++spanner_sized(y) != spanner_count(y) )
+ {
+ /* not the last column or row, so say zero */
+ back(x, dim) = fwd(x, dim) = 0;
+ }
+ else
+ {
+ /* this is the last column or row of a spanner. Its width is its */
+ /* natural width minus anything that will fit over the top of the */
+ /* things it spans. */
+
+ MinSize(y, dim, extras);
+ SpannerAvailableSpace(y, dim, &b, &f);
+ back(x, dim) = 0;
+ fwd(x, dim) = find_max(size(y, dim) - b, 0);
+ debug3(DSF, DD, " size(y, %s) = %s,%s", dimen(dim),
+ EchoLength(back(y, dim)), EchoLength(fwd(y, dim)));
+ }
+ debug4(DSF, DD, "finishing MinSize(%s) of %s span, reporting %s,%s",
+ dimen(dim), spanner_count(y) != 1 ? "multi-column" : "one-column",
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ break;
+
+
+ case HSPANNER:
+ case VSPANNER:
+
+ assert( (type(x) == HSPANNER) == (dim == COLM), "MinSize: SPANNER!" );
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ break;
+
+
+ case HEXPAND:
+ case VEXPAND:
+
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+
+ /* insert index into *extras for expanding later */
+ if( dim == ROWM )
+ { New(z, EXPAND_IND);
+ actual(z) = x;
+ Link(*extras, z);
+ /* Can't do Link(z, x) because Constrained goes up and finds z */
+ debug2(DCR, DD, " MinSize index: %ld %s", (long) z, EchoObject(z));
+ }
+ break;
+
+
+ case END_HEADER:
+ case CLEAR_HEADER:
+
+ back(x, dim) = fwd(x, dim) = 0;
+ Child(y, Down(x));
+ back(y, dim) = fwd(y, dim) = 0;
+ break;
+
+
+ case BEGIN_HEADER:
+ case SET_HEADER:
+
+ Child(y, LastDown(x));
+ y = MinSize(y, dim, extras);
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ debug4(DSF, D, "MinSize(%s, %s) := (%s, %s)", Image(type(x)),
+ dimen(dim), EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ break;
+
+
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+
+ Child(y, LastDown(x));
+ y = MinSize(y, dim, extras);
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ break;
+
+
+ case HCOVER:
+ case VCOVER:
+
+ /* work out size and set to 0 if parallel */
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ if( (dim == COLM) == (type(x) == HCOVER) )
+ back(x, dim) = fwd(x, dim) = 0;
+ else
+ { back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ }
+
+ /* insert index into *extras for revising size later */
+ if( dim == ROWM )
+ { New(z, COVER_IND);
+ actual(z) = x;
+ Link(*extras, z);
+ /* Can't do Link(z, x) because Constrained goes up and finds z */
+ debug2(DCR, DD, " MinSize index: %ld %s", (long) z, EchoObject(z));
+ }
+ break;
+
+
+ case HSCALE:
+ case VSCALE:
+
+ /* work out size and set to 0 if parallel */
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ if( (dim == COLM) == (type(x) == HSCALE) )
+ back(x, dim) = fwd(x, dim) = 0;
+ else
+ { back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ }
+ break;
+
+
+ case ROTATE:
+
+ Child(y, Down(x));
+ if( dim == COLM )
+ { y = MinSize(y, COLM, extras);
+ New(whereto(x), ACAT);
+ y = MinSize(y, ROWM, &whereto(x));
+ RotateSize(&back(x, COLM), &fwd(x, COLM), &back(x, ROWM), &fwd(x, ROWM),
+ y, sparec(constraint(x)));
+ }
+ else
+ { TransferLinks(Down(whereto(x)), whereto(x), *extras);
+ Dispose(whereto(x));
+ }
+ break;
+
+
+ case SCALE:
+
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ if( dim == COLM )
+ { back(x, dim) = (back(y, dim) * bc(constraint(x))) / SF;
+ fwd(x, dim) = (fwd(y, dim) * bc(constraint(x))) / SF;
+ if( bc(constraint(x)) == 0 ) /* Lout-supplied factor required */
+ { New(z, SCALE_IND);
+ actual(z) = x;
+ Link(*extras, z);
+ debug1(DSF, DDD, " MinSize: %s", EchoObject(z));
+ vert_sized(x) = FALSE;
+ }
+ }
+ else
+ { back(x, dim) = (back(y, dim) * fc(constraint(x))) / SF;
+ fwd(x, dim) = (fwd(y, dim) * fc(constraint(x))) / SF;
+ vert_sized(x) = TRUE;
+ }
+ break;
+
+
+ case KERN_SHRINK:
+
+
+ Child(y, LastDown(x));
+ y = MinSize(y, dim, extras);
+ if( dim == COLM )
+ { FULL_CHAR ch_left, ch_right; FULL_LENGTH ksize;
+ debug3(DSF, DD, "MinSize(%s,%s %s, COLM)",
+ EchoLength(back(y, COLM)), EchoLength(fwd(y, COLM)),
+ EchoObject(x));
+
+ /* default value if don't find anything */
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+
+ /* find first character of left parameter */
+ ch_right = (FULL_CHAR) '\0';
+ Child(y, Down(x));
+ while( type(y) == ACAT )
+ { Child(y, Down(y));
+ }
+ if( is_word(type(y)) ) ch_right = string(y)[0];
+
+ /* find last character of right parameter */
+ ch_left = (FULL_CHAR) '\0';
+ Child(y, LastDown(x));
+ while( type(y) == ACAT )
+ { Child(y, LastDown(y));
+ }
+ if( is_word(type(y)) ) ch_left = string(y)[StringLength(string(y))-1];
+
+ /* adjust if successful */
+ if( ch_left != (FULL_CHAR) '\0' && ch_right != (FULL_CHAR) '\0' )
+ {
+ ksize = KernLength(word_font(y), ch_left, ch_right);
+ debug4(DSF, DD, " KernLength(%s, %c, %c) = %s",
+ FontName(word_font(y)), (char) ch_left, (char) ch_right,
+ EchoLength(ksize));
+ fwd(x, dim) += ksize;
+ }
+
+ }
+ else
+ { back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ }
+ break;
+
+
+ case WIDE:
+
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ if( dim == COLM )
+ { y = BreakObject(y, &constraint(x));
+ assert( FitsConstraint(back(y, dim), fwd(y, dim), constraint(x)),
+ "MinSize: BreakObject failed to fit!" );
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ EnlargeToConstraint(&back(x, dim), &fwd(x, dim), &constraint(x));
+ }
+ else
+ { back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ }
+ break;
+
+
+ case HIGH:
+
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ if( dim == ROWM )
+ { if( !FitsConstraint(back(y, dim), fwd(y, dim), constraint(x)) )
+ { Error(12, 1, "forced to enlarge %s from %s to %s", WARN, &fpos(x),
+ KW_HIGH, EchoLength(bfc(constraint(x))), EchoLength(size(y, dim)));
+ debug0(DSF, DD, "offending object was:");
+ ifdebug(DSF, DD, DebugObject(y));
+ SetConstraint(constraint(x), MAX_FULL_LENGTH, size(y, dim), MAX_FULL_LENGTH);
+ }
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ EnlargeToConstraint(&back(x, dim), &fwd(x, dim), &constraint(x));
+ }
+ else
+ { back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ }
+ break;
+
+
+ case HSHIFT:
+ case VSHIFT:
+
+ Child(y, Down(x));
+ y = MinSize(y, dim, extras);
+ if( (dim == COLM) == (type(x) == HSHIFT) )
+ { f = FindShift(x, y, dim);
+ back(x, dim) = find_min(MAX_FULL_LENGTH, find_max(0, back(y, dim) + f));
+ fwd(x, dim) = find_min(MAX_FULL_LENGTH, find_max(0, fwd(y, dim) - f));
+ }
+ else
+ { back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ }
+ break;
+
+
+ case SPLIT:
+
+ link = DownDim(x, dim); Child(y, link);
+ y = MinSize(y, dim, extras);
+ back(x, dim) = back(y, dim);
+ fwd(x, dim) = fwd(y, dim);
+ break;
+
+
+ case ACAT:
+
+ if( fill_style(save_style(x)) == FILL_OFF )
+ { OBJECT new_line, g, z, res; BOOLEAN jn;
+
+ /* convert ACAT to VCAT of lines if more than one line */
+ /* first, compress all ACAT children */
+ for( link = x; NextDown(link) != x; link = NextDown(link) )
+ { Child(y, NextDown(link));
+ if( type(y) == ACAT )
+ {
+ TransferLinks(Down(y), y, NextDown(link));
+ DisposeChild(Up(y));
+ link = PrevDown(link);
+ }
+ }
+
+ /* check each definite subobject in turn for a linebreak preceding */
+ FirstDefinite(x, link, y, jn);
+ if( link != x )
+ {
+ res = nilobj;
+ NextDefiniteWithGap(x, link, y, g, jn);
+ while( link != x )
+ {
+ /* check whether we need to break the paragraph here at g */
+ if( mode(gap(g)) != NO_MODE && line_breaker(g) )
+ {
+ /* if this is our first break, build res */
+ if( res == nilobj )
+ {
+ New(res, VCAT);
+ adjust_cat(res) = FALSE;
+ ReplaceNode(res, x);
+ }
+
+ /* make new line of stuff up to g and append it to res */
+ New(new_line, ACAT);
+ TransferLinks(NextDown(x), Up(g), new_line);
+ StyleCopy(save_style(new_line), save_style(x));
+ adjust_cat(new_line) = padjust(save_style(x));
+ Link(res, new_line);
+ debug2(DSF, D, " new_line(adjust_cat %s) = %s",
+ bool(adjust_cat(new_line)), EchoObject(new_line));
+
+ /* may need to insert space at start of remainder */
+ if( hspace(g) > 0 )
+ {
+ /* make an empty word to occupy the first spot */
+ z = MakeWord(WORD, STR_EMPTY, &fpos(g));
+ word_font(z) = font(save_style(x));
+ word_colour(z) = colour(save_style(x));
+ word_outline(z) = outline(save_style(x));
+ word_language(z) = language(save_style(x));
+ word_hyph(z) = hyph_style(save_style(x)) == HYPH_ON;
+ underline(z) = UNDER_OFF;
+ back(z, COLM) = fwd(z, COLM) = 0;
+ Link(Down(x), z);
+
+ /* follow the empty word with a gap of the right width */
+ New(z, GAP_OBJ);
+ hspace(z) = hspace(g);
+ vspace(z) = 0;
+ underline(z) = UNDER_OFF;
+ GapCopy(gap(z), space_gap(save_style(x)));
+ width(gap(z)) *= hspace(z);
+ Link(NextDown(Down(x)), z);
+
+ debug2(DSF, D, " hspace(g) = %d, width(gap(z)) = %s",
+ hspace(g), EchoLength(width(gap(z))));
+ }
+
+ /* append a gap to res (recycle g) */
+ MoveLink(Up(g), res, PARENT);
+ GapCopy(gap(g), line_gap(save_style(x)));
+ width(gap(g)) *= find_max(1, vspace(g));
+
+ }
+ NextDefiniteWithGap(x, link, y, g, jn);
+ }
+
+ /* at end of loop, if we have a res, leftover last line is linked */
+ if( res != nilobj )
+ {
+ Link(res, x);
+ x = res;
+ }
+ }
+ }
+ /* *** NB NO BREAK *** */
+
+
+ case HCAT:
+ case VCAT:
+
+ if( (dim == ROWM) == (type(x) == VCAT) )
+ {
+ /********************************************************************/
+ /* */
+ /* Calculate sizes parallel to join direction; loop invariant is: */
+ /* */
+ /* If prev == nilobj, there are no definite children equal to */
+ /* or to the left of Child(link). */
+ /* If prev != nilobj, prev is the rightmost definite child to */
+ /* the left of Child(link), and (b, f) is the total size up */
+ /* to the mark of prev i.e. not including fwd(prev). */
+ /* g is the most recent gap, or nilobj if none found yet. */
+ /* will_expand == TRUE when a gap is found that is likely to */
+ /* enlarge when ActualGap is called later on. */
+ /* */
+ /********************************************************************/
+
+ prev = g = nilobj; will_expand = FALSE; must_expand(x) = FALSE;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( is_index(type(y)) )
+ { if( dim == ROWM )
+ { link = PrevDown(link);
+ MoveLink(NextDown(link), *extras, PARENT);
+ }
+ continue;
+ }
+ else if( type(y) == type(x) )
+ { link = PrevDown(link);
+ TransferLinks(Down(y), y, NextDown(link));
+ DisposeChild(Up(y));
+ continue;
+ }
+ else if( type(y) == GAP_OBJ ) g = y;
+ else /* calculate size of y and accumulate it */
+ { if( is_word(type(y)) )
+ { if( dim == COLM )
+ {
+ /* compress adjacent words if compatible */
+ if( prev != nilobj && width(gap(g)) == 0 && nobreak(gap(g)) &&
+ type(x) == ACAT &&
+ is_word(type(prev)) && vspace(g) + hspace(g) == 0 &&
+ units(gap(g)) == FIXED_UNIT &&
+ mode(gap(g)) == EDGE_MODE && !mark(gap(g)) &&
+ word_font(prev) == word_font(y) &&
+ word_colour(prev) == word_colour(y) &&
+ word_outline(prev) == word_outline(y) &&
+ word_language(prev) == word_language(y) &&
+ underline(prev) == underline(y) &&
+ NextDown(NextDown(Up(prev))) == link
+ )
+ {
+ unsigned typ;
+ debug3(DSF, DD, "compressing %s and %s at %s",
+ EchoObject(prev), EchoObject(y), EchoFilePos(&fpos(prev)));
+ if( StringLength(string(prev)) + StringLength(string(y))
+ >= MAX_BUFF )
+ Error(12, 2, "word %s%s is too long", FATAL, &fpos(prev),
+ string(prev), string(y));
+ typ = type(prev) == QWORD || type(y) == QWORD ? QWORD : WORD;
+ y = MakeWordTwo(typ, string(prev), string(y), &fpos(prev));
+ word_font(y) = word_font(prev);
+ word_colour(y) = word_colour(prev);
+ word_outline(y) = word_outline(prev);
+ word_language(y) = word_language(prev);
+ word_hyph(y) = word_hyph(prev);
+ underline(y) = underline(prev);
+ FontWordSize(y);
+ Link(Up(prev), y);
+ DisposeChild(Up(prev));
+ DisposeChild(Up(g));
+ DisposeChild(link);
+ prev = y;
+ link = Up(prev);
+ continue;
+ }
+
+ FontWordSize(y);
+ debug4(DSF, DD, "FontWordSize( %s ) font %d = %s,%s",
+ EchoObject(y), word_font(y),
+ EchoLength(back(y, COLM)), EchoLength(fwd(y, COLM)));
+ }
+ }
+ else y = MinSize(y, dim, extras);
+
+ if( is_indefinite(type(y)) )
+ {
+ /* error if preceding gap has mark */
+ if( g != nilobj && mark(gap(g)) )
+ { Error(12, 3, "^ deleted (it may not precede this object)",
+ WARN, &fpos(y));
+ mark(gap(g)) = FALSE;
+ }
+
+ /* error if next unit is used in preceding gap */
+ if( g != nilobj && units(gap(g)) == NEXT_UNIT )
+ { Error(12, 4, "gap replaced by 0i (%c unit not allowed here)",
+ WARN, &fpos(y), CH_UNIT_WD);
+ units(gap(g)) = FIXED_UNIT;
+ width(gap(g)) = 0;
+ }
+ }
+ else
+ {
+ /* calculate running total length */
+ if( prev == nilobj ) b = back(y, dim), f = 0;
+ else
+ { FULL_LENGTH tmp;
+ tmp = MinGap(fwd(prev,dim), back(y,dim), fwd(y, dim), &gap(g));
+ assert(g!=nilobj && mode(gap(g))!=NO_MODE, "MinSize: NO_MODE!");
+ if( units(gap(g)) == FIXED_UNIT && mode(gap(g)) == TAB_MODE )
+ {
+ f = find_max(width(gap(g)) + back(y, dim), f + tmp);
+ }
+ else
+ {
+ f = f + tmp;
+ }
+ if( units(gap(g)) == FRAME_UNIT && width(gap(g)) > FR )
+ will_expand = TRUE;
+ if( units(gap(g)) == AVAIL_UNIT && mark(gap(g)) && width(gap(g)) > 0 )
+ Error(12, 9, "mark alignment incompatible with centring or right justification",
+ WARN, &fpos(g));
+ /* ***
+ if( units(gap(g)) == AVAIL_UNIT && width(gap(g)) >= FR )
+ will_expand = TRUE;
+ *** */
+ if( mark(gap(g)) ) b += f, f = 0;
+ }
+ prev = y;
+ }
+ debug2(DSF,DD," b = %s, f = %s",EchoLength(b),EchoLength(f));
+ }
+ } /* end for */
+
+ if( prev == nilobj ) b = f = 0;
+ else f += fwd(prev, dim);
+ back(x, dim) = find_min(MAX_FULL_LENGTH, b);
+ fwd(x, dim) = find_min(MAX_FULL_LENGTH, f);
+
+ if( type(x) == ACAT && will_expand ) fwd(x, COLM) = MAX_FULL_LENGTH;
+ }
+ else
+ {
+ /********************************************************************/
+ /* */
+ /* Calculate sizes perpendicular to join direction */
+ /* */
+ /* Loop invariant: */
+ /* */
+ /* if found, (b, f) is the size of x, from the last // or from */
+ /* the start, up to link exclusive. Else no children yet. */
+ /* If dble_found, a previous // exists, and (0, dble_fwd) is */
+ /* the size of x from the start up to that //. */
+ /* */
+ /********************************************************************/
+
+ dble_found = found = FALSE; dble_fwd = 0;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ debug4(DSF, DD, " %s in %s, y = %s %s", dimen(dim),
+ Image(type(x)), Image(type(y)), EchoObject(y));
+ if( is_index(type(y)) )
+ { if( dim == ROWM )
+ { link = PrevDown(link);
+ MoveLink(NextDown(link), *extras, PARENT);
+ }
+ continue;
+ }
+ else if( type(y) == type(x) )
+ { link = PrevDown(link);
+ TransferLinks(Down(y), y, NextDown(link));
+ DisposeChild(Up(y));
+ continue;
+ }
+ else if( type(y) == GAP_OBJ )
+ { assert( found, "MinSize/VCAT/perp: !found!" );
+ if( !join(gap(y)) )
+ {
+ /* found // or || operator, so end current group */
+ dble_found = TRUE;
+ dble_fwd = find_max(dble_fwd, b + f);
+ debug1(DSF, DD, " endgroup, dble_fwd: %s", EchoLength(dble_fwd));
+ found = FALSE;
+ }
+ }
+ else /* found object */
+ {
+ /* calculate size of subobject y */
+ if( is_word(type(y)) )
+ { if( dim == COLM ) FontWordSize(y);
+ }
+ else y = MinSize(y, dim, extras);
+ if( found )
+ { b = find_max(b, back(y, dim));
+ f = find_max(f, fwd(y, dim));
+ }
+ else
+ { b = back(y, dim);
+ f = fwd(y, dim);
+ found = TRUE;
+ }
+ debug2(DSF,DD, " b: %s, f: %s", EchoLength(b), EchoLength(f));
+ }
+ } /* end for */
+ assert( found, "MinSize/VCAT/perp: !found (2)!" );
+
+ /* finish off last group */
+ if( dble_found )
+ { back(x, dim) = 0;
+ dble_fwd = find_max(dble_fwd, b + f);
+ fwd(x, dim) = find_min(MAX_FULL_LENGTH, dble_fwd);
+ debug1(DSF, DD, " end group, dble_fwd: %s", EchoLength(dble_fwd));
+ }
+ else
+ { back(x, dim) = b;
+ fwd(x, dim) = f;
+ }
+ } /* end else */
+ break;
+
+
+ case COL_THR:
+
+ assert( dim == COLM, "MinSize/COL_THR: dim!" );
+ if( thr_state(x) == NOTSIZED )
+ { assert( Down(x) != x, "MinSize/COL_THR: Down(x)!" );
+
+ /* first size all the non-spanning members of the thread */
+ debug1(DSF, DD, "[[ starting sizing %s", Image(type(x)));
+ b = f = 0;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) != GAP_OBJ, "MinSize/COL_THR: GAP_OBJ!" );
+ if( type(y) != START_HVSPAN && type(y) != START_HSPAN &&
+ type(y) != HSPAN && type(y) != VSPAN )
+ { y = MinSize(y, dim, extras);
+ b = find_max(b, back(y, dim));
+ f = find_max(f, fwd(y, dim));
+ }
+ }
+ back(x, dim) = b;
+ fwd(x, dim) = f;
+ thr_state(x) = SIZED;
+ debug3(DSF, DD, "][ middle sizing %s (%s,%s)", Image(type(x)),
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+
+ /* now size all the spanning members of the thread */
+ /* these will use back(x, dim) and fwd(x, dim) during sizing */
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) != GAP_OBJ, "MinSize/COL_THR: GAP_OBJ!" );
+ if( type(y) == START_HVSPAN || type(y) == START_HSPAN ||
+ type(y) == HSPAN || type(y) == VSPAN )
+ { y = MinSize(y, dim, extras);
+ b = find_max(b, back(y, dim));
+ f = find_max(f, fwd(y, dim));
+ }
+ }
+ back(x, dim) = b;
+ fwd(x, dim) = f;
+ debug3(DSF, DD, "]] end sizing %s (%s,%s)", Image(type(x)),
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ }
+ break;
+
+
+ case ROW_THR:
+
+ assert( dim == ROWM, "MinSize/ROW_THR: dim!" );
+ if( thr_state(x) == NOTSIZED )
+ { assert( Down(x) != x, "MinSize/ROW_THR: Down(x)!" );
+
+ /* first size all the non-spanning members of the thread */
+ debug1(DSF, DD, "[[ starting sizing %s", Image(type(x)));
+ b = f = 0;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) != GAP_OBJ, "MinSize/ROW_THR: GAP_OBJ!" );
+ if( type(y) != START_HVSPAN && type(y) != START_VSPAN &&
+ type(y) != HSPAN && type(y) != VSPAN )
+ { y = MinSize(y, dim, extras);
+ debug5(DSF, DD, " MinSize(%s) has size %s,%s -> %s,%s",
+ Image(type(y)), EchoLength(back(y, dim)), EchoLength(fwd(y, dim)),
+ EchoLength(b), EchoLength(f));
+ b = find_max(b, back(y, dim));
+ f = find_max(f, fwd(y, dim));
+ }
+ }
+ back(x, dim) = b;
+ fwd(x, dim) = f;
+ thr_state(x) = SIZED;
+ debug3(DSF, DD, "][ middle sizing %s (%s,%s)", Image(type(x)),
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+
+ /* now size all the spanning members of the thread */
+ /* these will use back(x, dim) and fwd(x, dim) during sizing */
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) != GAP_OBJ, "MinSize/ROW_THR: GAP_OBJ!" );
+ if( type(y) == START_HVSPAN || type(y) == START_VSPAN ||
+ type(y) == HSPAN || type(y) == VSPAN )
+ { y = MinSize(y, dim, extras);
+ back(x, dim) = find_max(back(x, dim), back(y, dim));
+ fwd(x, dim) = find_max(fwd(x, dim), fwd(y, dim));
+ debug5(DSF, DD, " MinSize(%s) has size %s,%s -> %s,%s",
+ Image(type(y)), EchoLength(back(y, dim)), EchoLength(fwd(y, dim)),
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ }
+ }
+ debug3(DSF, DD, "]] end sizing %s (%s,%s)", Image(type(x)),
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ }
+ break;
+
+
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+
+ /* open file, check for initial %!, and hunt for %%BoundingBox line */
+ /* according to DSC Version 3.0, the BoundingBox parameters must be */
+ /* integers; but we read them as floats and truncate since files */
+ /* with fractional values seem to be common in the real world */
+ if( dim == ROWM ) break;
+ status = IG_LOOKING;
+ Child(y, Down(x));
+ fp = OpenIncGraphicFile(string(y), type(x), &full_name, &fpos(y), &cp);
+ if( fp == NULL ) status = IG_NOFILE;
+ first_line = TRUE;
+ /* ***
+ while( status == IG_LOOKING && StringFGets(buff, MAX_BUFF, fp) != NULL )
+ *** */
+ while( status == IG_LOOKING )
+ {
+ read_status = fscanf(fp, "%[^\n\r]%*c", (char *) buff);
+ if( read_status == 0 || read_status == EOF )
+ {
+ /* end of input and no luck */
+ break;
+ }
+ if( first_line && !StringBeginsWith(buff, AsciiToFull("%!")) )
+ status = IG_BADFILE;
+ else
+ { first_line = FALSE;
+ if( buff[0] == '%'
+ && StringBeginsWith(buff, AsciiToFull("%%BoundingBox:"))
+ && !StringContains(buff, AsciiToFull("(atend)")) )
+ { if( sscanf( (char *) buff, "%%%%BoundingBox: %f %f %f %f",
+ &fllx, &flly, &furx, &fury) == 4 )
+ {
+ status = IG_OK;
+ llx = fllx;
+ lly = flly;
+ urx = furx;
+ ury = fury;
+ }
+ else status = IG_BADSIZE;
+ }
+ }
+ }
+
+ /* report error or calculate true size, depending on status */
+ switch( status )
+ {
+ case IG_NOFILE:
+
+ Error(12, 5, "%s deleted (cannot open file %s)", WARN, &fpos(x),
+ type(x) == INCGRAPHIC ? KW_INCGRAPHIC : KW_SINCGRAPHIC,
+ string(full_name));
+ incgraphic_ok(x) = FALSE;
+ back(x, COLM) = fwd(x, COLM) = back(x, ROWM) = fwd(x, ROWM) = 0;
+ break;
+
+ case IG_LOOKING:
+
+ Error(12, 6, "%s given zero size (no BoundingBox line in file %s)",
+ WARN, &fpos(x),
+ type(x) == INCGRAPHIC ? KW_INCGRAPHIC : KW_SINCGRAPHIC,
+ string(full_name));
+ back(y, COLM) = fwd(y, COLM) = back(y, ROWM) = fwd(y, ROWM) = 0;
+ back(x, COLM) = fwd(x, COLM) = back(x, ROWM) = fwd(x, ROWM) = 0;
+ incgraphic_ok(x) = TRUE;
+ fclose(fp);
+ if( cp ) StringRemove(AsciiToFull(LOUT_EPS));
+ break;
+
+ case IG_BADFILE:
+
+ Error(12, 7, "%s deleted (bad first line in file %s)", WARN,
+ &fpos(x), type(x) == INCGRAPHIC ? KW_INCGRAPHIC : KW_SINCGRAPHIC,
+ string(full_name));
+ incgraphic_ok(x) = FALSE;
+ back(x, COLM) = fwd(x, COLM) = back(x, ROWM) = fwd(x, ROWM) = 0;
+ fclose(fp);
+ if( cp ) StringRemove(AsciiToFull(LOUT_EPS));
+ break;
+
+ case IG_BADSIZE:
+
+ Error(12, 8, "%s given zero size (bad BoundingBox line in file %s)",
+ WARN, &fpos(x),
+ type(x) == INCGRAPHIC ? KW_INCGRAPHIC : KW_SINCGRAPHIC,
+ string(full_name));
+ back(y, COLM) = fwd(y, COLM) = back(y, ROWM) = fwd(y, ROWM) = 0;
+ back(x, COLM) = fwd(x, COLM) = back(x, ROWM) = fwd(x, ROWM) = 0;
+ incgraphic_ok(x) = TRUE;
+ fclose(fp);
+ if( cp ) StringRemove(AsciiToFull(LOUT_EPS));
+ break;
+
+ case IG_OK:
+
+ Child(y, Down(x));
+ back(y, COLM) = llx; fwd(y, COLM) = urx;
+ back(y, ROWM) = lly; fwd(y, ROWM) = ury;
+ b = (urx - llx) * PT;
+ b = find_min(MAX_FULL_LENGTH, find_max(0, b));
+ back(x, COLM) = fwd(x, COLM) = b / 2;
+ b = (ury - lly) * PT;
+ b = find_min(MAX_FULL_LENGTH, find_max(0, b));
+ back(x, ROWM) = fwd(x, ROWM) = b / 2;
+ incgraphic_ok(x) = TRUE;
+ fclose(fp);
+ if( cp ) StringRemove(AsciiToFull(LOUT_EPS));
+ break;
+
+ }
+ DisposeObject(full_name);
+ break;
+
+
+ default:
+
+ assert1(FALSE, "MinSize", Image(type(x)));
+ break;
+
+
+ } /* end switch */
+ debugcond6(DSF, D, dim == COLM && --debug_depth < debug_depth_max,
+ "%*s] MinSize(COLM, %s %d) = (%s, %s)", debug_depth*2, " ", Image(type(x)),
+ (int) x, EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ debug1(DSF, DD, "] MinSize returning, x = %s", EchoObject(x));
+ debug3(DSF, DD, " (%s size is %s, %s)", dimen(dim),
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)) );
+ ifdebug(DSF, DDD, DebugObject(x));
+
+ assert(back(x, dim) >= 0, "MinSize: back(x, dim) < 0!");
+ assert(fwd(x, dim) >= 0, "MinSize: fwd(x, dim) < 0!");
+
+ return x;
+ } /* end MinSize */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z13.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z13.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z13.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,789 ----
+ /*@z13.c:Object Breaking:BreakJoinedGroup()@**********************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z13.c */
+ /* MODULE: Object Breaking */
+ /* EXTERNS: BreakObject() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define broken(x) back(x, ROWM) /* OK since no vertical sizes yet */
+
+ #if DEBUG_ON
+ static int debug_depth = 1;
+ static int debug_depth_max = 5;
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* static BreakJoinedGroup(start, stop, m, c, res_back, res_fwd) */
+ /* */
+ /* Break joined group of components of a VCAT, beginning from Child(start) */
+ /* inclusive and ending at Child(stop) inclusive. Break component m first */
+ /* because it is the widest. */
+ /* */
+ /*****************************************************************************/
+
+ static void BreakJoinedGroup(OBJECT start, OBJECT stop, OBJECT m,
+ CONSTRAINT *c, FULL_LENGTH *res_back, FULL_LENGTH *res_fwd)
+ { OBJECT y, link; FULL_LENGTH b, f, sb, sf; CONSTRAINT yc;
+ debug1(DOB, DD, "[ BreakJoinedGroup(start, stop, m, %s, -, -)",
+ EchoConstraint(c));
+
+ /* work out a suitable constraint to apply to each component */
+ sb = sf = 0;
+ for( link = start; link != NextDown(stop); link = NextDown(link) )
+ { Child(y, link);
+ if( !is_definite(type(y)) ) continue;
+ sb = find_max(sb, back(y, COLM));
+ sf = find_max(sf, fwd(y, COLM));
+ }
+ if( sb <= bc(*c) )
+ {
+ /* make sure the constraint will accept objects with size (sb, 0) */
+ b = sb;
+ f = 0;
+ }
+ else
+ {
+ /* sb is too wide anyway, so don't worry about it */
+ b = 0;
+ f = 0;
+ }
+ SetConstraint(yc, find_min(bc(*c), bfc(*c)-f), bfc(*c), find_min(fc(*c), bfc(*c)-b));
+
+ /* apply this constraint to each component in turn, m first */
+ if( m != nilobj )
+ {
+ debug1(DOB, DD, " +++BreakJoinedGroup calling first child, yc = %s",
+ EchoConstraint(&yc));
+ m = BreakObject(m, &yc);
+ b = back(m, COLM);
+ f = fwd(m, COLM);
+ SetConstraint(yc, find_min(bc(yc), bfc(yc)-f), bfc(yc), find_min(fc(yc), bfc(yc)-b));
+ }
+ else b = f = 0;
+ for( link = start; link != NextDown(stop); link = NextDown(link) )
+ { Child(y, link);
+ if( !is_definite(type(y)) || y == m ) continue;
+ debug1(DOB, DD, " +++BreakJoinedGroup calling child, yc = %s",
+ EchoConstraint(&yc));
+ y = BreakObject(y, &yc);
+ b = find_max(b, back(y, COLM));
+ f = find_max(f, fwd(y, COLM));
+ SetConstraint(yc, find_min(bc(yc), bfc(yc)-f), bfc(yc), find_min(fc(yc), bfc(yc)-b));
+ }
+ if( !FitsConstraint(b, f, *c) )
+ { debug3(DOB, DD, " in BreakJoinedGroup: !FitsConstraint(%s, %s, %s)",
+ EchoLength(b), EchoLength(f), EchoConstraint(c));
+ Error(13, 1, "failed to break column to fit into its available space",
+ WARN, m != nilobj ? &fpos(m) : (y != nilobj ? &fpos(y) : no_fpos));
+ }
+ *res_back = b; *res_fwd = f;
+ debug2(DOB, DD,"] BreakJoinedGroup returning (%s, %s)",
+ EchoLength(b), EchoLength(f));
+ } /* end BreakJoinedGroup */
+
+
+ /*@::BreakVcat()@*************************************************************/
+ /* */
+ /* static OBJECT BreakVcat(x, c) */
+ /* */
+ /* Break a VCAT to satisfy constraint c. This is tedious because every */
+ /* group of components between // ... // must be broken separately. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT BreakVcat(OBJECT x, CONSTRAINT *c)
+ { OBJECT y, link, start_group, m; FULL_LENGTH b, f, dble_fwd; CONSTRAINT tc;
+ BOOLEAN dble_found;
+ debug1(DOB, DD, "[ BreakVcat(x, %s)", EchoConstraint(c));
+ assert(Down(x) != x, "BreakVcat: Down(x) == x!" );
+ SetConstraint(tc, MAX_FULL_LENGTH, find_min(bfc(*c), fc(*c)), MAX_FULL_LENGTH);
+
+ dble_found = FALSE; dble_fwd = 0; start_group = nilobj;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( is_index(type(y)) ) continue;
+ if( type(y) == GAP_OBJ )
+ { assert( start_group != nilobj, "BreakVcat: start_group == nilobj!" );
+ if( !join(gap(y)) )
+ {
+ /* finish off and break this group */
+ if( !FitsConstraint(b, f, tc) )
+ BreakJoinedGroup(start_group, link, m, &tc, &b, &f);
+ dble_found = TRUE;
+ dble_fwd = find_max(dble_fwd, b + f);
+ start_group = nilobj;
+ debug1(DOB, DD, " end group, dble_fwd: %s", EchoLength(dble_fwd));
+ }
+ }
+ else if( start_group == nilobj )
+ {
+ /* start new group */
+ b = back(y, COLM); f = fwd(y, COLM);
+ start_group = link; m = y;
+ debug2(DOB, DD, " starting group (b = %s, f = %s):",
+ EchoLength(b), EchoLength(f));
+ ifdebug(DOB, DD, DebugObject(y));
+ }
+ else
+ {
+ /* continue with current group */
+ b = find_max(b, back(y, COLM)); f = find_max(f, fwd(y, COLM));
+ if( fwd(y, COLM) > fwd(m, COLM) ) m = y;
+ debug3(DOB, DD, " in group%s (b = %s, f = %s):",
+ m == y ? " (new max)" : "",
+ EchoLength(b), EchoLength(f));
+ ifdebug(DOB, DD, DebugObject(y));
+ }
+ }
+ assert( start_group != nilobj, "BreakVcat: start_group == nilobj (2)!" );
+
+ if( dble_found )
+ {
+ /* finish off and break this last group, and set sizes of x */
+ if( !FitsConstraint(b, f, tc) )
+ BreakJoinedGroup(start_group, LastDown(x), m, &tc, &b, &f);
+ dble_fwd = find_max(dble_fwd, b + f);
+ debug1(DOB, DD, " ending last group, dble_fwd: %s",EchoLength(dble_fwd));
+ back(x, COLM) = 0; fwd(x, COLM) = find_min(MAX_FULL_LENGTH, dble_fwd);
+ }
+ else
+ {
+ /* finish off and break this last and only group, and set sizes of x */
+ debug2(DOB, DD, " BreakVcat ending last and only group (%s, %s)",
+ EchoLength(b), EchoLength(f));
+ BreakJoinedGroup(start_group, LastDown(x), m, c, &b, &f);
+ back(x, COLM) = b; fwd(x, COLM) = f;
+ }
+
+ debug0(DOB, DD, "] BreakVcat returning x:");
+ ifdebug(DOB, DD, DebugObject(x));
+ debug2(DOB, DD, " (size is %s, %s)",
+ EchoLength(back(x, COLM)), EchoLength(fwd(x, COLM)));
+ return x;
+ } /* end BreakVcat */
+
+
+ /*@::BreakTable()@************************************************************/
+ /* */
+ /* static OBJECT BreakTable(x, c) */
+ /* */
+ /* Break table (HCAT) x to satisfy constraint c. */
+ /* */
+ /* Outline of algorithm: */
+ /* */
+ /* bcount = number of components to left of mark; */
+ /* fcount = no. of components on and right of mark; */
+ /* bwidth = what back(x) would be if all components had size (0, 0); */
+ /* fwidth = what fwd(x) would be if all components had size (0, 0); */
+ /* Set all components of x to Unbroken (broken(y) holds this flag); */
+ /* while( an Unbroken component of x exists ) */
+ /* { my = the Unbroken component of x of minimum width; */
+ /* mc = desirable constraint for my (see below); */
+ /* BreakObject(my, &mc); */
+ /* Set my to Broken and update bcount, fcount, bwidth, fwidth */
+ /* to reflect the actual size of my, now broken; */
+ /* } */
+ /* */
+ /* The constraint mc is chosen in an attempt to ensure that: */
+ /* */
+ /* a) Any sufficiently narrow components will not break; */
+ /* b) All broken components will have the same bfc(mc), if possible; */
+ /* c) All available space is used. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT BreakTable(OBJECT x, CONSTRAINT *c)
+ { FULL_LENGTH bwidth, fwidth; /* running back(x) and fwd(x) */
+ int bcount, fcount; /* running no. of components */
+ OBJECT mlink, my; /* minimum-width unbroken component */
+ BOOLEAN ratm; /* TRUE when my has a mark to its right */
+ int mside; /* side of the mark my is on: BACK, ON, FWD */
+ FULL_LENGTH msize; /* size of my (minimal among unbroken) */
+ CONSTRAINT mc; /* desirable constraint for my */
+ OBJECT pg, prec_def; /* preceding definite object of my */
+ OBJECT sg, succ_def; /* succeeding definite object of my */
+ FULL_LENGTH pd_extra,sd_extra;/* space availiable for free each side of my */
+ FULL_LENGTH av_colsize; /* the size of each unbroken component */
+ /* if they are all assigned equal width */
+ FULL_LENGTH fwd_max, back_max;/* maximum space available forward of or */
+ /* back of the mark, when columns are even */
+ FULL_LENGTH col_size; /* the column size actually used in breaking */
+ FULL_LENGTH prev_col_size; /* previous column size (try to keep equal) */
+ FULL_LENGTH beffect, feffect; /* the amount bwidth, fwidth must increase */
+ /* when my is broken */
+ OBJECT link, y, prev, g; FULL_LENGTH tmp, tmp2;
+
+ debug1(DOB, DD, "[ BreakTable( x, %s )", EchoConstraint(c));
+
+ /* Initialise csize, bcount, fcount, bwidth, fwidth and broken(y) */
+ bcount = fcount = 0; bwidth = fwidth = 0; prev = nilobj;
+ prev_col_size = 0;
+ Child(y, Down(x));
+ assert( type(y) != GAP_OBJ, "BreakTable: GAP_OBJ!" );
+ assert( !is_index(type(y)), "BreakTable: index!" );
+ broken(y) = is_indefinite(type(y));
+ if( !broken(y) ) prev = y, fcount = 1;
+
+ for( link = NextDown(Down(x)); link != x; link = NextDown(NextDown(link)) )
+ {
+ /* find the next gap g and following child y */
+ Child(g, link);
+ assert( type(g) == GAP_OBJ, "BreakTable: GAP_OBJ!" );
+ assert( NextDown(link) != x, "BreakTable: GAP_OBJ is last!" );
+ Child(y, NextDown(link));
+
+ assert( type(y) != GAP_OBJ, "BreakTable: GAP_OBJ!" );
+ assert( !is_index(type(y)), "BreakTable: index!" );
+ broken(y) = is_indefinite(type(y));
+ if( !broken(y) )
+ { if( prev == nilobj ) fcount = 1;
+ else if( mark(gap(g)) )
+ { bcount += fcount;
+ bwidth += fwidth + MinGap(0, 0, 0, &gap(g));
+ fcount = 1; fwidth = 0;
+ }
+ else
+ { fwidth += MinGap(0, 0, 0, &gap(g));
+ fcount += 1;
+ }
+ prev = y;
+ }
+ }
+
+ /* if column gaps alone are too wide, kill them all */
+ if( !FitsConstraint(bwidth, fwidth, *c) )
+ {
+ debug2(DOB, DD, "column gaps alone too wide: bwidth: %s; fwidth: %s",
+ EchoLength(bwidth), EchoLength(fwidth));
+ Error(13, 2, "reducing column gaps to 0i (object is too wide)",
+ WARN, &fpos(x));
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(g, link);
+ if( type(g) == GAP_OBJ )
+ { SetGap(gap(g), nobreak(gap(g)), mark(gap(g)), join(gap(g)),
+ FIXED_UNIT, EDGE_MODE, 0);
+ }
+ }
+ bwidth = fwidth = 0;
+ }
+
+ /* break each column, from smallest to largest */
+ while( bcount + fcount > 0 && FitsConstraint(bwidth, fwidth, *c) )
+ {
+ debug2(DOB, DD, "bcount: %d; bwidth: %s", bcount, EchoLength(bwidth));
+ debug2(DOB, DD, "fcount: %d; fwidth: %s", fcount, EchoLength(fwidth));
+
+ /* find a minimal-width unbroken component my */
+ my = nilobj; msize = size(x, COLM); /* an upper bound for size(y) */
+ for( link = Down(x); ; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) != GAP_OBJ, "BreakTable: type(y) == GAP_OBJ!" );
+ if( !broken(y) && (size(y, COLM) < msize || my == nilobj) )
+ { msize = size(y, COLM);
+ my = y; mlink = link;
+ ratm = FALSE;
+ }
+
+ /* next gap */
+ link = NextDown(link);
+ if( link == x ) break;
+ Child(g, link);
+ assert( type(g) == GAP_OBJ, "BreakTable: type(g) != GAP_OBJ!" );
+ if( mark(gap(g)) ) ratm = TRUE;
+ }
+
+ /* find neighbouring definite objects and resulting pd_extra and sd_extra */
+ SetNeighbours(mlink, ratm, &pg, &prec_def, &sg, &succ_def, &mside);
+ debug2(DOB, DD, "my (%s): %s", Image(mside), EchoObject(my));
+ pd_extra = pg == nilobj ? 0 :
+ ExtraGap(broken(prec_def) ? fwd(prec_def,COLM) : 0, 0, &gap(pg), BACK);
+ sd_extra = sg == nilobj ? 0 :
+ ExtraGap(0, broken(succ_def) ? back(succ_def,COLM) : 0, &gap(sg), FWD);
+ debug2(DOB, DD, "pd_extra: %s; sd_extra: %s",
+ EchoLength(pd_extra), EchoLength(sd_extra) );
+
+ /* calculate desirable constraints for my */
+ av_colsize = (bfc(*c) - bwidth - fwidth) / (bcount + fcount);
+ debug1(DOB, DD, "av_colsize = %s", EchoLength(av_colsize));
+ debug1(DOB, DD, "prev_col_size = %s", EchoLength(prev_col_size));
+ switch( mside )
+ {
+
+ case BACK:
+
+ back_max = find_min(bc(*c), bwidth + av_colsize * bcount);
+ col_size = (back_max - bwidth) / bcount;
+ if( col_size > prev_col_size && col_size - prev_col_size < PT )
+ col_size = prev_col_size;
+ SetConstraint(mc,
+ find_min(MAX_FULL_LENGTH, col_size + pd_extra),
+ find_min(MAX_FULL_LENGTH, col_size + pd_extra + sd_extra),
+ find_min(MAX_FULL_LENGTH, col_size + sd_extra));
+ break;
+
+
+ case ON:
+
+ fwd_max = find_min(fc(*c), fwidth + av_colsize * fcount);
+ col_size = (fwd_max - fwidth) / fcount;
+ if( col_size > prev_col_size && col_size - prev_col_size < PT )
+ col_size = prev_col_size;
+ SetConstraint(mc,
+ find_min(MAX_FULL_LENGTH, pd_extra + back(my, COLM)),
+ find_min(MAX_FULL_LENGTH, pd_extra + back(my, COLM) + col_size + sd_extra),
+ find_min(MAX_FULL_LENGTH, col_size + sd_extra));
+ break;
+
+
+ case FWD:
+
+ fwd_max = find_min(fc(*c), fwidth + av_colsize * fcount);
+ col_size = (fwd_max - fwidth) / fcount;
+ if( col_size > prev_col_size && col_size - prev_col_size < PT )
+ col_size = prev_col_size;
+ SetConstraint(mc,
+ find_min(MAX_FULL_LENGTH, col_size + pd_extra),
+ find_min(MAX_FULL_LENGTH, col_size + pd_extra + sd_extra),
+ find_min(MAX_FULL_LENGTH, col_size + sd_extra));
+ break;
+
+
+ default:
+
+ assert(FALSE, "BreakTable: mside");
+ break;
+ }
+ debug1(DOB, DD, "col_size = %s", EchoLength(col_size));
+ prev_col_size = col_size;
+
+ /* now break my according to these constraints, and accept it */
+ debug2(DOB, DD, " calling BreakObject(%s, %s)", EchoObject(my),
+ EchoConstraint(&mc));
+ my = BreakObject(my, &mc); broken(my) = TRUE;
+
+ /* calculate the effect of accepting my on bwidth and fwidth */
+ if( pg != nilobj )
+ { tmp = broken(prec_def) ? fwd(prec_def, COLM) : 0;
+ beffect = MinGap(tmp, back(my, COLM), fwd(my, COLM), &gap(pg)) -
+ MinGap(tmp, 0, 0, &gap(pg));
+ }
+ else beffect = back(my, COLM);
+
+ if( sg != nilobj )
+ { tmp = broken(succ_def) ? back(succ_def, COLM) : 0;
+ tmp2 = broken(succ_def) ? fwd(succ_def, COLM) : 0;
+ feffect = MinGap(fwd(my, COLM), tmp, tmp2, &gap(sg)) -
+ MinGap(0, tmp, tmp2, &gap(sg));
+ }
+ else feffect = fwd(my, COLM);
+
+ switch( mside )
+ {
+ case BACK: bwidth += beffect + feffect;
+ bcount--;
+ break;
+
+ case ON: bwidth += beffect; fwidth += feffect;
+ fcount--;
+ break;
+
+ case FWD: fwidth += beffect + feffect;
+ fcount--;
+ break;
+
+ default: assert(FALSE, "BreakTable: mside");
+ break;
+ }
+
+ } /* end while */
+
+ back(x, COLM) = bwidth;
+ fwd(x, COLM) = fwidth;
+
+ debug2(DOB, DD, "] BreakTable returning %s,%s; x =",
+ EchoLength(bwidth), EchoLength(fwidth));
+ ifdebug(DOB, DD, DebugObject(x));
+ return x;
+ } /* end BreakTable */
+
+
+ /*@::BreakObject()@***********************************************************/
+ /* */
+ /* OBJECT BreakObject(x, c) */
+ /* */
+ /* Break lines of object x so that it satisfies constraint c. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT BreakObject(OBJECT x, CONSTRAINT *c)
+ { OBJECT link, y; CONSTRAINT yc; FULL_LENGTH f; BOOLEAN junk;
+ debugcond4(DOB, D, debug_depth++ < debug_depth_max,
+ "%*s[ BreakObject(%s %d)", (debug_depth-1)*2, " ", Image(type(x)), (int) x);
+ debug4(DOB, DD, "[ BreakObject(%s (%s,%s), %s), x =",
+ Image(type(x)), EchoLength(back(x, COLM)), EchoLength(fwd(x, COLM)),
+ EchoConstraint(c));
+ ifdebug(DOB, DD, DebugObject(x));
+
+ /* if constraint is negative (should really be never), replace with empty */
+ if( !(bc(*c)>=0 && bfc(*c)>=0 && fc(*c)>=0) )
+ {
+ Error(13, 11, "replacing with empty object: negative size constraint %s,%s,%s",
+ WARN, &fpos(x), EchoLength(bc(*c)), EchoLength(bfc(*c)), EchoLength(fc(*c)));
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ back(y, COLM) = fwd(y, COLM) = 0;
+ ReplaceNode(y, x);
+ DisposeObject(x);
+ x = y;
+ debugcond6(DOB, D, --debug_depth < debug_depth_max,
+ "%*s] BreakObject(%s %d) (neg!) = (%s, %s)", debug_depth*2, " ",
+ Image(type(x)), (int) x, EchoLength(back(x, COLM)),
+ EchoLength(fwd(x, COLM)));
+ debug0(DOB, DD, "] BreakObject returning (negative constraint).");
+ return x;
+ }
+
+ /* if no breaking required, return immediately */
+ if( FitsConstraint(back(x, COLM), fwd(x, COLM), *c) )
+ { debug0(DOB, DD, "] BreakObject returning (fits).");
+ debugcond6(DOB, D, --debug_depth < debug_depth_max,
+ "%*s] BreakObject(%s %d) (fits) = (%s, %s)", debug_depth*2, " ",
+ Image(type(x)), (int) x, EchoLength(back(x, COLM)),
+ EchoLength(fwd(x, COLM)));
+ return x;
+ }
+
+ switch( type(x) )
+ {
+
+ case ROTATE:
+
+ if( BackEnd->scale_avail && InsertScale(x, c) )
+ {
+ Parent(x, Up(x));
+ Error(13, 3, "%s object scaled horizontally by factor %.2f (too wide)",
+ WARN, &fpos(x), KW_ROTATE, (float) bc(constraint(x)) / SF );
+ }
+ else
+ { Error(13, 4, "%s deleted (too wide; cannot break %s)",
+ WARN, &fpos(x), KW_ROTATE, KW_ROTATE);
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ back(y, COLM) = fwd(y, COLM) = 0;
+ ReplaceNode(y, x);
+ DisposeObject(x);
+ x = y;
+ }
+ break;
+
+
+ case SCALE:
+
+ InvScaleConstraint(&yc, bc(constraint(x)), c);
+ Child(y, Down(x));
+ y = BreakObject(y, &yc);
+ back(x, COLM) = (back(y, COLM) * bc(constraint(x))) / SF;
+ fwd(x, COLM) = (fwd(y, COLM) * bc(constraint(x))) / SF;
+ break;
+
+
+ case KERN_SHRINK:
+
+ /* not really accurate, but there you go */
+ Child(y, LastDown(x));
+ y = BreakObject(y, c);
+ back(x, COLM) = back(y, COLM);
+ fwd(x, COLM) = fwd(y, COLM);
+ break;
+
+
+ case WORD:
+ case QWORD:
+
+ if( word_hyph(x) )
+ {
+ /* create an ACAT with the same size as x */
+ New(y, ACAT);
+ FposCopy(fpos(y), fpos(x));
+ back(y, COLM) = back(x, COLM);
+ fwd(y, COLM) = fwd(x, COLM);
+ back(y, ROWM) = back(x, ROWM);
+ fwd(y, ROWM) = fwd(x, ROWM);
+
+ /* set ACAT's save_style; have to invent a line_gap, unfortunately */
+ SetGap(line_gap(save_style(y)), FALSE, FALSE, FALSE, FIXED_UNIT,
+ MARK_MODE, 1.1 * FontSize(word_font(x), x));
+ SetGap(space_gap(save_style(y)), FALSE, FALSE, TRUE, FIXED_UNIT,
+ EDGE_MODE, 0);
+ hyph_style(save_style(y)) = HYPH_ON;
+ fill_style(save_style(y)) = FILL_ON;
+ display_style(save_style(y)) = DISPLAY_LEFT;
+ small_caps(save_style(y)) = FALSE;
+ font(save_style(y)) = word_font(x);
+ colour(save_style(y)) = word_colour(x);
+ outline(save_style(y)) = word_outline(x);
+ language(save_style(y)) = word_language(x);
+ debug3(DOF, DD, " in BreakObject y %s %s %s",
+ EchoStyle(&save_style(y)), Image(type(y)), EchoObject(y));
+
+ /* enclose x in the ACAT and try breaking (i.e. filling) it */
+ ReplaceNode(y, x);
+ Link(y, x);
+ x = y;
+ debug3(DOF, DD, " in BreakObject x %s %s %s",
+ EchoStyle(&save_style(x)), Image(type(x)), EchoObject(x));
+ x = BreakObject(x, c);
+ }
+ else if( BackEnd->scale_avail && InsertScale(x, c) )
+ { OBJECT tmp;
+ tmp = x;
+ Parent(x, Up(x));
+ Error(13, 5, "word %s scaled horizontally by factor %.2f (too wide)",
+ WARN, &fpos(x), string(tmp), (float) bc(constraint(x)) / SF);
+ }
+ else
+ { Error(13, 6, "word %s deleted (too wide)", WARN, &fpos(x), string(x));
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ back(y, COLM) = fwd(y, COLM) = 0;
+ ReplaceNode(y, x);
+ DisposeObject(x);
+ x = y;
+ }
+ break;
+
+
+ case WIDE:
+
+ MinConstraint(&constraint(x), c);
+ Child(y, Down(x));
+ y = BreakObject(y, &constraint(x));
+ back(x, COLM) = back(y, COLM);
+ fwd(x, COLM) = fwd(y, COLM);
+ EnlargeToConstraint(&back(x, COLM), &fwd(x, COLM), &constraint(x));
+ break;
+
+
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+
+ if( BackEnd->scale_avail && InsertScale(x, c) )
+ {
+ Parent(x, Up(x));
+ Error(13, 7, "%s scaled horizontally by factor %.2f (too wide)",
+ WARN, &fpos(x),
+ type(x) == INCGRAPHIC ? KW_INCGRAPHIC : KW_SINCGRAPHIC,
+ (float) bc(constraint(x)) / SF);
+ }
+ else
+ { Error(13, 8, "%s deleted (too wide)", WARN, &fpos(x),
+ type(x) == INCGRAPHIC ? KW_INCGRAPHIC : KW_SINCGRAPHIC);
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ back(y, COLM) = fwd(y, COLM) = 0;
+ ReplaceNode(y, x);
+ DisposeObject(x);
+ x = y;
+ }
+ break;
+
+
+ case HIGH:
+ case VSCALE:
+ case VCOVER:
+ case VSHIFT:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case ONE_COL:
+ case ONE_ROW:
+ case HSPANNER:
+
+ assert( Down(x) == LastDown(x), "BreakObject: downs!" );
+ Child(y, Down(x));
+ y = BreakObject(y, c);
+ back(x, COLM) = back(y, COLM);
+ fwd(x, COLM) = fwd(y, COLM);
+ break;
+
+
+ case BACKGROUND:
+
+ Child(y, Down(x));
+ y = BreakObject(y, c);
+ Child(y, LastDown(x));
+ y = BreakObject(y, c);
+ back(x, COLM) = back(y, COLM);
+ fwd(x, COLM) = fwd(y, COLM);
+ break;
+
+
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+
+ /* these all have size zero except the last one, so if we get to */
+ /* this point we must be at the last column and need to break it. */
+ /* this is done just by setting its size to zero, unless it is */
+ /* the last column in which case it claims everything that is */
+ /* going; the real break is deferred to the first ROWM touch, */
+ /* when we know that all contributing columns have been broken */
+ /* unless the child is not a spanner, in which case it's @OneCol */
+ Child(y, Down(x));
+ if( type(y) != HSPANNER )
+ {
+ y = BreakObject(y, c);
+ back(x, COLM) = back(y, COLM);
+ fwd(x, COLM) = fwd(y, COLM);
+ }
+ else
+ {
+ back(x, COLM) = 0;
+ fwd(x, COLM) = find_min(bfc(*c), fc(*c));
+ }
+ break;
+
+
+ case HSHIFT:
+
+ Child(y, Down(x));
+ f = FindShift(x, y, COLM);
+ SetConstraint(yc,
+ find_min(bc(*c), bfc(*c)) - f, bfc(*c), find_min(fc(*c), bfc(*c)) + f);
+ BreakObject(y, &yc);
+ f = FindShift(x, y, COLM);
+ back(x, COLM) = find_min(MAX_FULL_LENGTH, find_max(0, back(y, COLM) + f));
+ fwd(x, COLM) = find_min(MAX_FULL_LENGTH, find_max(0, fwd(y, COLM) - f));
+ break;
+
+
+ case END_HEADER:
+ case CLEAR_HEADER:
+
+ /* these have size zero anyway, so not likely to reach this point */
+ break;
+
+
+ case BEGIN_HEADER:
+ case SET_HEADER:
+
+ Child(y, LastDown(x));
+ y = BreakObject(y, c);
+ back(x, COLM) = back(y, COLM);
+ fwd(x, COLM) = fwd(y, COLM);
+ debug3(DOB, D, "BreakObject(%s, COLM) = (%s, %s)", Image(type(x)),
+ EchoLength(back(x, COLM)), EchoLength(fwd(x, COLM)));
+ break;
+
+
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+
+ Child(y, LastDown(x));
+ y = BreakObject(y, c);
+ back(x, COLM) = back(y, COLM);
+ fwd(x, COLM) = fwd(y, COLM);
+ break;
+
+
+ case SPLIT:
+
+ Child(y, DownDim(x, COLM));
+ y = BreakObject(y, c);
+ back(x, COLM) = back(y, COLM);
+ fwd(x, COLM) = fwd(y, COLM);
+ break;
+
+
+ case ACAT:
+
+ if( back(x, COLM) > 0 )
+ { int sz; OBJECT rpos;
+ /* shift the column mark of x to the left edge */
+ sz = size(x, COLM);
+ fwd(x, COLM) = find_min(MAX_FULL_LENGTH, sz);
+ back(x, COLM) = 0;
+ rpos = x;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ && mark(gap(y)) )
+ { mark(gap(y)) = FALSE;
+ rpos = y;
+ }
+ }
+ if( FitsConstraint(back(x, COLM), fwd(x, COLM), *c) )
+ { Error(13, 9, "column mark of unbroken paragraph moved left",
+ WARN, &fpos(rpos));
+ break;
+ }
+ Error(13, 10, "column mark of paragraph moved left before breaking",
+ WARN, &fpos(rpos));
+ ifdebug(DOB, DD, DebugObject(x));
+ }
+ x = FillObject(x, c, nilobj, TRUE, TRUE, FALSE, &junk);
+ break;
+
+
+ case HCAT:
+
+ x = BreakTable(x, c);
+ break;
+
+
+ case COL_THR:
+
+ BreakJoinedGroup(Down(x), LastDown(x), nilobj, c,
+ &back(x,COLM), &fwd(x,COLM));
+ break;
+
+
+ case VCAT:
+
+ x = BreakVcat(x, c);
+ break;
+
+
+ default:
+
+ assert1(FALSE, "BreakObject:", Image(type(x)));
+ break;
+
+ }
+ assert( back(x, COLM) >= 0, "BreakObject: back(x, COLM) < 0!" );
+ assert( fwd(x, COLM) >= 0, "BreakObject: fwd(x, COLM) < 0!" );
+ debugcond6(DOB, D, --debug_depth < debug_depth_max,
+ "%*s] BreakObject(%s %d) = (%s, %s)", debug_depth*2, " ", Image(type(x)),
+ (int) x, EchoLength(back(x, COLM)), EchoLength(fwd(x, COLM)));
+ debug2(DOB, DD, "] BreakObject returning %s,%s, x =",
+ EchoLength(back(x, COLM)), EchoLength(fwd(x, COLM)));
+ ifdebug(DOB, DD, DebugObject(x));
+ return x;
+ } /* end BreakObject */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z14.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z14.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z14.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,910 ----
+ /*@z14.c:Fill Service:Declarations@*******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z14.c */
+ /* MODULE: Fill Service */
+ /* EXTERNS: FillObject() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define TOO_TIGHT_BAD 1048576 /* 2^21; badness of a too tight line */
+ #define TOO_LOOSE_BAD 65536 /* 2^16; the max badness of a too loose line */
+ #define TIGHT_BAD 4096 /* 2^12; the max badness of a tight line */
+ #define LOOSE_BAD 4096 /* 2^12; the max badness of a loose line */
+ #define HYPH_BAD 128 /* 2^ 7; threshold for calling hyphenation */
+ #define HYPH_BAD_INCR 16 /* 2 ^4: the badness of one hyphen */
+ #define WIDOW_BAD_INCR 128 /* 2 ^7: the badness of one widow word */
+ #define SQRT_TOO_LOOSE 512 /* 2^ 9; sqrt(TOO_LOOSE_BAD) (used to be) */
+ #define SQRT_TIGHT_BAD 128 /* 2^ 7; sqrt(TIGHT_BAD) (used to be) */
+ #define SQRT_LOOSE_BAD 128 /* 2^ 7; sqrt(LOOSE_BAD) (used to be) */
+ #define SQRT_TOO_TIGHT 8192 /* 2^13; sqrt(TOO_TIGHT_BAD) (used to be) */
+ #define MAX_EXPAND 1
+ #define MAX_SHRINK 4
+
+
+ typedef struct {
+ OBJECT llink; /* link to gap before left end of interval */
+ OBJECT rlink; /* link to gap after right end of interval */
+ OBJECT cwid; /* link to current line width in multi case */
+ int nat_width; /* natural width of interval */
+ int space_width; /* natural width of spaces in the interval */
+ int badness; /* badness of this interval */
+ unsigned char class; /* badness class of this interval */
+ unsigned char tab_count; /* number of gaps with tab mode in interval */
+ int tab_pos; /* if tab_count > 0, this holds the position */
+ /* of the left edge of the object following */
+ /* the rightmost tab gap in the interval */
+ int width_to_tab; /* if tab_count > 0, the interval width up */
+ /* to but not including the rightmost tab */
+ } INTERVAL;
+
+
+ /*****************************************************************************/
+ /* */
+ /* Badness classes */
+ /* */
+ /*****************************************************************************/
+
+ #define TOO_LOOSE 0 /* interval is too loose */
+ #define LOOSE 1 /* interval is loose but not too loose */
+ #define TIGHT 2 /* interval is tight but not too tight */
+ #define TOO_TIGHT 3 /* interval is too tight */
+ #define TAB_OVERLAP 4 /* interval has a tab and left part overlaps */
+ #define AT_END 5 /* interval ends at right end of paragraph */
+ #define UNBREAKABLE_LEFT 6 /* interval has an unbreakable gap at left */
+ #define UNBREAKABLE_RIGHT 7 /* interval has an unbreakable gap at right */
+ #define EMPTY_INTERVAL 8 /* interval is empty */
+
+ /*@::SetIntervalBadness()@****************************************************/
+ /* */
+ /* SetIntervalBadness(I) */
+ /* */
+ /* Private, calculates the badness and badness class of a non-empty */
+ /* interval. Does not take into account any unbreakable gap at either end. */
+ /* */
+ /*****************************************************************************/
+
+ #define SetIntervalBadness(I, max_width, etc_width) \
+ { OBJECT g; int badness; \
+ int col_width; \
+ \
+ /* initialize to saved badness of left-adjoining interval, if any */ \
+ /* and set width of column */ \
+ if( I.llink == x ) \
+ { col_width = (I.cwid!=nilobj) ? bfc(constraint(I.cwid)) : max_width; \
+ I.badness = 0; \
+ } \
+ else \
+ { col_width = (I.cwid!=nilobj) ? bfc(constraint(I.cwid)) : etc_width; \
+ Child(g, I.llink); \
+ I.badness = save_badness(g); \
+ } \
+ \
+ /* penalize widow lines, of the form [ <object> &1rt ... ] */ \
+ if( I.tab_count > 0 ) \
+ { OBJECT glink = NextDown(NextDown(I.llink)); \
+ assert( type(glink) == LINK, "SIB: glink!"); \
+ Child(g, glink); \
+ if( type(g) == GAP_OBJ && mode(gap(g)) == TAB_MODE && \
+ units(gap(g)) == AVAIL_UNIT && width(gap(g)) == 1*FR ) \
+ I.badness += WIDOW_BAD_INCR; \
+ } \
+ \
+ if( col_width <= 0 ) \
+ { if( I.nat_width == 0 ) \
+ { I.class = TOO_LOOSE; \
+ I.badness += 0; \
+ } \
+ else \
+ { I.class = TIGHT; \
+ I.badness += TOO_TIGHT_BAD; \
+ } \
+ } \
+ else if( I.tab_count > 0 && I.width_to_tab > I.tab_pos ) \
+ { I.class = TAB_OVERLAP; \
+ I.badness += TOO_TIGHT_BAD; \
+ } \
+ else if( MAX_EXPAND*(col_width-I.nat_width) > 2*I.space_width ) \
+ { I.class = I.tab_count > 0 ? LOOSE : TOO_LOOSE; \
+ badness = (SQRT_TOO_LOOSE*(col_width - I.nat_width)) / col_width; \
+ I.badness += badness * badness; \
+ } \
+ else if( I.nat_width <= col_width ) \
+ { I.class = LOOSE; \
+ badness = (SQRT_LOOSE_BAD*(col_width - I.nat_width)) / col_width; \
+ I.badness += badness * badness; \
+ } \
+ else if( BackEnd->fractional_spacing_avail && allow_shrink && \
+ MAX_SHRINK*(I.nat_width-col_width) <= I.space_width ) \
+ { I.class = TIGHT; \
+ badness = (SQRT_TIGHT_BAD*(col_width - I.nat_width)) / col_width; \
+ I.badness += badness * badness; \
+ } \
+ else \
+ { I.class = TOO_TIGHT; \
+ /*** \
+ badness = (SQRT_TOO_TIGHT*(col_width-I.nat_width)) / col_width; \
+ I.badness += badness * badness; \
+ ***/ \
+ I.badness += TOO_TIGHT_BAD; \
+ } \
+ assert( I.badness >= 0, "SetIntervalBadness: badness < 0!" ); \
+ } /* end macro SetIntervalBadness */
+
+
+ /*@::MoveRightToGap()@********************************************************/
+ /* */
+ /* MoveRightToGap(I, x, rlink, right, max_width, etc_width, hyph_word) */
+ /* */
+ /* Private. Shared by IntervalInit and IntervalShiftRightEnd, for moving */
+ /* to the next gap to the right, setting save_space(newg), checking for */
+ /* hyphenation case, and setting the interval badness. */
+ /* */
+ /*****************************************************************************/
+
+ #define MoveRightToGap(I,x,rlink,right,max_width,etc_width,hyph_word) \
+ { OBJECT newg, foll, tmp; \
+ BOOLEAN jn, unbreakable_at_right = FALSE; \
+ debug0(DOF, DDD, "MoveRightToGap(I, x, rlink, right, -, -, -)"); \
+ \
+ /* search onwards to find newg, the next true breakpoint */ \
+ Child(tmp, rlink); \
+ debug2(DOF, DDD, "NextDefiniteWithGap(%s, %s)", EchoObject(x), \
+ EchoObject(tmp)); \
+ NextDefiniteWithGap(x, rlink, foll, newg, jn); \
+ \
+ /* set right link and calculate badness of the new interval */ \
+ if( rlink != x ) \
+ { \
+ assert( Up(newg) == LastUp(newg), "MoveRightToGap: newg!" ); \
+ /* set save_space(newg) now so that it is OK to forget right */ \
+ debug0(DOF, DDD, " MoveRightToGap setting save_space(newg)"); \
+ if( I.cwid != nilobj ) etc_width = bfc(constraint(I.cwid)); \
+ if( mode(gap(newg)) == TAB_MODE ) \
+ { save_space(newg) = ActualGap(0, back(foll,COLM), fwd(foll,COLM), \
+ &gap(newg), etc_width, 0) - back(foll, COLM); \
+ } \
+ else \
+ { save_space(newg) = ActualGap(fwd(right, COLM), back(foll, COLM), \
+ fwd(foll,COLM), &gap(newg), etc_width, \
+ I.nat_width - fwd(right,COLM)) \
+ - back(foll, COLM) - fwd(right, COLM); \
+ } \
+ \
+ ifdebug(DOF, DDD, \
+ if( Down(newg) != newg ) \
+ { OBJECT tmp; \
+ Child(tmp, Down(newg)); \
+ debug5(DOF, DDD, "newg %s: %s %s, gap = %s, save_space = %s", \
+ Image(type(newg)), Image(type(tmp)), EchoObject(tmp), \
+ EchoGap(&gap(newg)), EchoLength(save_space(newg))); \
+ } \
+ else debug3(DOF, DDD, "newg %s: gap = %s, save_space = %s", \
+ Image(type(newg)), EchoGap(&gap(newg)), \
+ EchoLength(save_space(newg))); \
+ ) \
+ \
+ /* sort out ending with hyphenation and/or being unbreakable */ \
+ /* NB ADD_HYPH is possible after a restart */ \
+ if( mode(gap(newg)) == HYPH_MODE || mode(gap(newg)) == ADD_HYPH ) \
+ { if( hyph_allowed ) \
+ { \
+ /* hyphenation is allowed, so add hyph_word to nat_width */ \
+ if( is_word(type(right)) && \
+ !(string(right)[StringLength(string(right))-1] == CH_HYPHEN) ) \
+ { \
+ /* make sure hyph_word exists and is of the right font */ \
+ debug0(DOF, DDD, " MoveRightToGap checking hyph_word"); \
+ if( hyph_word == nilobj ) \
+ { hyph_word = MakeWord(WORD, STR_HYPHEN, &fpos(x)); \
+ word_font(hyph_word) = 0; \
+ word_colour(hyph_word) = colour(save_style(x)); \
+ word_outline(hyph_word) = outline(save_style(x)); \
+ word_language(hyph_word) = language(save_style(x)); \
+ word_hyph(hyph_word) = hyph_style(save_style(x))==HYPH_ON; \
+ } \
+ if( word_font(hyph_word) != font(save_style(x)) ) \
+ { word_font(hyph_word) = font(save_style(x)); \
+ FposCopy(fpos(hyph_word), fpos(x)); \
+ FontWordSize(hyph_word); \
+ } \
+ \
+ mode(gap(newg)) = ADD_HYPH; \
+ I.nat_width += size(hyph_word, COLM); \
+ debug0(DOF, DDD, " adding hyph_word from nat_width"); \
+ } \
+ } \
+ else \
+ { \
+ /* hyphenation is not allowed, so this gap is unbreakable */ \
+ unbreakable_at_right = TRUE; \
+ } \
+ } \
+ else if( nobreak(gap(newg)) ) \
+ unbreakable_at_right = TRUE; \
+ \
+ I.rlink = Up(newg); \
+ debug2(DOF, DDD, " MoveRightToGap setting I.rlink to %s %s", \
+ Image(type(newg)), EchoObject(newg)); \
+ } \
+ else I.rlink = x; \
+ SetIntervalBadness(I, max_width, etc_width); \
+ if( unbreakable_at_right ) I.class = UNBREAKABLE_RIGHT; \
+ else if( I.class == TIGHT && mode(gap(newg)) == TAB_MODE ) \
+ I.class = TOO_TIGHT, I.badness = TOO_TIGHT_BAD; \
+ debug0(DOF, DDD, "MoveRightToGap returning."); \
+ }
+
+ /*@::IntervalInit(), IntervalShiftRightEnd()@*********************************/
+ /* */
+ /* IntervalInit(I, x, max_width, etc_width, hyph_word) */
+ /* */
+ /* Set I to the first interval of x. */
+ /* */
+ /*****************************************************************************/
+
+ #define IntervalInit(I, x, max_width, etc_width, hyph_word) \
+ { OBJECT rlink, right; BOOLEAN jn; \
+ debug0(DOF, DDD, "IntervalInit(I, x, -, -, hyph_word)"); \
+ I.llink = x; \
+ \
+ FirstDefinite(x, rlink, right, jn); \
+ if( rlink == x ) I.class = AT_END, I.rlink = x; \
+ else \
+ { \
+ /* have first definite object, so set interval width etc. */ \
+ if( multi != nilobj ) \
+ { Child(I.cwid, Down(multi)); \
+ } \
+ else I.cwid = nilobj; \
+ I.nat_width = size(right, COLM); \
+ I.space_width = 0; \
+ I.tab_count = 0; \
+ \
+ /* move to gap, check hyphenation there etc. */ \
+ MoveRightToGap(I,x,rlink,right,max_width,etc_width,hyph_word); \
+ } \
+ debug0(DOF, DDD, "IntervalInit returning."); \
+ } /* end macro IntervalInit */
+
+
+ /*****************************************************************************/
+ /* */
+ /* IntervalShiftRightEnd(I, x, hyph_word, max_width, etc_width) */
+ /* */
+ /* Shift the right end of interval I one place to the right. */
+ /* */
+ /*****************************************************************************/
+
+ #define IntervalShiftRightEnd(I, x, hyph_word, max_width, etc_width) \
+ { OBJECT rlink, g, right; \
+ assert( I.class != AT_END, "IntervalShiftRightEnd: AT_END!" ); \
+ rlink = I.rlink; \
+ if( rlink == x ) I.class = AT_END; \
+ else \
+ { \
+ /* I is optimal here so save its badness and left endpoint */ \
+ Child(g, rlink); \
+ assert( type(g) == GAP_OBJ, "IntervalShiftRightEnd: type(g)!" ); \
+ save_badness(g) = I.badness; \
+ save_prev(g) = I.llink; \
+ save_cwid(g) = I.cwid; \
+ \
+ /* if hyphenation case, must take away width of hyph_word */ \
+ /* and increase the badness to discourage breaks at this point */ \
+ if( mode(gap(g)) == ADD_HYPH ) \
+ { I.nat_width -= size(hyph_word,COLM); \
+ save_badness(g) += HYPH_BAD_INCR; \
+ debug0(DOF, DDD, " subtracting hyph_word from nat_width"); \
+ } \
+ \
+ /* find definite object which must lie just to the right of g */ \
+ NextDefinite(x, rlink, right); \
+ assert( rlink != x, "IntervalShiftRightEnd: rlink == x!" ); \
+ \
+ /* modify I to reflect the addition of g and right */ \
+ if( mode(gap(g)) == TAB_MODE ) \
+ { I.tab_count++; \
+ I.tab_pos = save_space(g); \
+ I.width_to_tab = I.nat_width; \
+ I.nat_width = save_space(g) + size(right, COLM); \
+ I.space_width = 0; \
+ } \
+ else \
+ { I.nat_width += save_space(g) + size(right, COLM); \
+ I.space_width += save_space(g); \
+ } \
+ \
+ /* now shift one step to the right */ \
+ MoveRightToGap(I, x, rlink, right, max_width, etc_width,hyph_word); \
+ } \
+ } /* end macro IntervalShiftRightEnd */
+
+
+ /*@::IntervalShiftLeftEnd(), IntervalBadness()@*******************************/
+ /* */
+ /* IntervalShiftLeftEnd(I, x, max_width, etc_width) */
+ /* */
+ /* Shift the left end of interval I one place to the right. */
+ /* */
+ /*****************************************************************************/
+
+ #define IntervalShiftLeftEnd(I, x, max_width, etc_width) \
+ { OBJECT llink, left, lgap, y; BOOLEAN jn; \
+ debug1(DOF, DDD, "IntervalShiftLeftEnd(%s)", IntervalPrint(I, x)); \
+ assert( I.class != AT_END, "IntervalShiftLeftEnd: AT_END!" ); \
+ \
+ /* find left, the leftmost definite object of I */ \
+ llink = I.llink; \
+ NextDefinite(x, llink, left); \
+ assert( llink != x, "IntervalShiftLeftEnd: llink == x!" ); \
+ \
+ /* find lgap, the first true breakpoint following left */ \
+ NextDefiniteWithGap(x, llink, y, lgap, jn); \
+ assert( llink != x, "IntervalShiftLeftEnd: llink == x!" ); \
+ \
+ /* calculate width and badness of interval minus left and lgap */ \
+ if( mode(gap(lgap)) == TAB_MODE ) \
+ { assert( I.tab_count > 0 || Up(lgap) == I.rlink, \
+ "IntervalShiftLeftEnd: tab_count <= 0!" ); \
+ I.tab_count--; \
+ if( I.tab_count == 0 ) I.nat_width -= save_space(lgap); \
+ } \
+ else /* take from nat_width, or if tab, from width_to_tab */ \
+ { if( I.tab_count == 0 ) \
+ { I.nat_width -= save_space(lgap) + size(left, COLM); \
+ I.space_width -= save_space(lgap); \
+ } \
+ else if( I.tab_count == 1 ) \
+ { I.width_to_tab -= save_space(lgap) + size(left, COLM); \
+ } \
+ /* else no changes since tabs hide them */ \
+ } \
+ I.llink = Up(lgap); \
+ if( I.llink == I.rlink ) \
+ { I.class = EMPTY_INTERVAL; \
+ I.badness = TOO_TIGHT_BAD + 1; \
+ } \
+ else \
+ { \
+ if( save_cwid(lgap) != nilobj ) \
+ { OBJECT tlink; \
+ tlink = NextDown(Up(save_cwid(lgap))); \
+ if( type(tlink) == ACAT ) I.cwid = save_cwid(lgap); \
+ else Child(I.cwid, tlink); \
+ } \
+ SetIntervalBadness(I, max_width, etc_width); \
+ if( nobreak(gap(lgap)) || ( !hyph_allowed && \
+ (mode(gap(lgap))==HYPH_MODE || mode(gap(lgap))==ADD_HYPH) ) ) \
+ I.class = UNBREAKABLE_LEFT; \
+ } \
+ debug1(DOF, DDD, "IShiftLeftEnd returning %s", IntervalPrint(I, x)); \
+ } /* end macro IntervalShiftLeftEnd */
+
+
+ /*****************************************************************************/
+ /* */
+ /* IntervalBadness(I) */
+ /* */
+ /* Return the badness of interval I. */
+ /* */
+ /*****************************************************************************/
+
+ #define IntervalBadness(I) (I.badness)
+
+
+ /*@IntervalClass(), IntervalPrint()@******************************************/
+ /* */
+ /* IntervalClass(I) */
+ /* */
+ /* Return the badness class of interval I. */
+ /* */
+ /*****************************************************************************/
+
+ #define IntervalClass(I) (I.class)
+
+
+ #if DEBUG_ON
+ /*****************************************************************************/
+ /* */
+ /* IntervalPrint(I, x) */
+ /* */
+ /* Return string image of the contents of interval I of ACAT x. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR *IntervalPrint(INTERVAL I, OBJECT x)
+ { static char *class_name[] =
+ { "TOO_LOOSE", "LOOSE", "TIGHT", "TOO_TIGHT", "TAB_OVERLAP", "AT_END",
+ "UNBREAKABLE_LEFT", "UNBREAKABLE_RIGHT" };
+ OBJECT link, y, g, z; int i;
+ static FULL_CHAR res[300];
+ if( I.llink == I.rlink ) return AsciiToFull("[]");
+ StringCopy(res, AsciiToFull(""));
+ if( I.cwid != nilobj )
+ { StringCat(res, AsciiToFull("!"));
+ StringCat(res, EchoLength(bfc(constraint(I.cwid))));
+ StringCat(res, AsciiToFull("!"));
+ }
+ StringCat(res, AsciiToFull("["));
+ g = nilobj;
+ for( link = NextDown(I.llink); link != I.rlink; link = NextDown(link) )
+ { assert(link != x, "IntervalPrint: link == x!");
+ Child(y, link);
+ debug2(DOF, DDD, "IntervalPrint at %s %s", Image(type(y)), EchoObject(y));
+ assert(y != x, "IntervalPrint: y == x!");
+ if( type(y) == GAP_OBJ )
+ { g = y;
+ if( Down(g) != g )
+ { Child(z, Down(g));
+ StringCat(res, STR_SPACE);
+ StringCat(res, EchoCatOp(ACAT, mark(gap(g)), join(gap(g)))),
+ StringCat(res, is_word(type(z)) ? string(z) : Image(type(z)));
+ StringCat(res, STR_SPACE);
+ }
+ else for( i = 1; i <= hspace(g) + vspace(g); i++ )
+ StringCat(res, STR_SPACE);
+ }
+ else if( is_word(type(y)) )
+ StringCat(res, string(y)[0] == '\0' ? AsciiToFull("{}") : string(y));
+ else StringCat(res, Image(type(y)));
+ }
+ StringCat(res, AsciiToFull("] n"));
+ StringCat(res, EchoLength(I.nat_width));
+ StringCat(res, AsciiToFull(", "));
+ StringCat(res, EchoLength(I.space_width));
+ StringCat(res, AsciiToFull(" ("));
+ StringCat(res, AsciiToFull(class_name[I.class]));
+ StringCat(res, AsciiToFull(" "));
+ StringCat(res, StringInt(I.badness));
+ StringCat(res, AsciiToFull(")"));
+ if( I.tab_count > 0 )
+ { StringCat(res, AsciiToFull(" <"));
+ StringCat(res, StringInt(I.tab_count));
+ StringCat(res, STR_SPACE);
+ StringCat(res, EchoLength(I.width_to_tab));
+ StringCat(res, AsciiToFull(":"));
+ StringCat(res, EchoLength(I.tab_pos));
+ StringCat(res, AsciiToFull(">"));
+ }
+ return res;
+ } /* end IntervalPrint */
+ #endif
+
+
+ /*@::FillObject()@************************************************************/
+ /* */
+ /* FillObject(x, c, multi, can_hyphenate, allow_shrink, extend_unbreakable, */
+ /* hyph_used) */
+ /* */
+ /* Break ACAT x into lines using optimal breakpoints. Set hyph_used to */
+ /* TRUE if any hyphenation was done. */
+ /* */
+ /* multi If multi is not nilobj, ignore c and use the */
+ /* sequence of constraints within multi for the */
+ /* successive lines. */
+ /* */
+ /* can_hyphenate TRUE if hyphenation is permitted during this fill. */
+ /* */
+ /* allow_shrink TRUE if gaps may be shrunk as well as expanded. */
+ /* */
+ /* extend_unbreakable TRUE if nobreak(gap()) fields are to be set so as */
+ /* to prevent gaps hidden under overstruck objects */
+ /* from becoming break points. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT FillObject(OBJECT x, CONSTRAINT *c, OBJECT multi, BOOLEAN can_hyphenate,
+ BOOLEAN allow_shrink, BOOLEAN extend_unbreakable, BOOLEAN *hyph_used)
+ { INTERVAL I, BestI; OBJECT res, gp, tmp, z, y, link, ylink, prev, next;
+ int max_width, etc_width, outdent_margin, f; BOOLEAN jn; unsigned typ;
+ static OBJECT hyph_word = nilobj;
+ BOOLEAN hyph_allowed; /* TRUE when hyphenation of words is permitted */
+ assert( type(x) == ACAT, "FillObject: type(x) != ACAT!" );
+
+ debug4(DOF, D, "FillObject(x, %s, can_hyph = %s, %s); %s",
+ EchoConstraint(c), bool(can_hyphenate),
+ multi == nilobj ? "nomulti" : "multi", EchoStyle(&save_style(x)));
+ ifdebug(DOF, DD, DebugObject(x); fprintf(stderr, "\n\n") );
+
+ *hyph_used = FALSE;
+
+ if( multi == nilobj )
+ {
+ /* set max_width (width of 1st line), etc_width (width of later lines) */
+ max_width = find_min(fc(*c), bfc(*c));
+ if( display_style(save_style(x)) == DISPLAY_OUTDENT ||
+ display_style(save_style(x)) == DISPLAY_ORAGGED )
+ { outdent_margin = 2 * FontSize(font(save_style(x)), x);
+ etc_width = max_width - outdent_margin;
+ }
+ else etc_width = max_width;
+ assert( size(x, COLM) > max_width, "FillObject: initial size!" );
+
+ /* if column width is ridiculously small, exit with error message */
+ if( max_width <= 2 * FontSize(font(save_style(x)), x) )
+ {
+ Error(14, 6, "paragraph deleted (assigned width %s is too narrow)",
+ WARN, &fpos(x), EchoLength(max_width));
+ res = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ word_font(res) = font(save_style(x));
+ word_colour(res) = colour(save_style(x));
+ word_outline(res) = outline(save_style(x));
+ word_language(res) = language(save_style(x));
+ word_hyph(res) = hyph_style(save_style(x)) == HYPH_ON;
+ back(res, COLM) = fwd(res, COLM) = 0;
+ ReplaceNode(res, x);
+ DisposeObject(x);
+ return res;
+ }
+ }
+ else max_width = etc_width = 0; /* not used really */
+
+ /* add &1rt {} to end of paragraph */
+ New(gp, GAP_OBJ); hspace(gp) = 1; vspace(gp) = 0;
+ SetGap(gap(gp), FALSE, FALSE, TRUE, AVAIL_UNIT, TAB_MODE, 1*FR);
+ tmp = MakeWord(WORD, STR_GAP_RJUSTIFY, &fpos(x));
+ Link(gp, tmp); Link(x, gp);
+ tmp = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ back(tmp, COLM) = fwd(tmp, COLM) = back(tmp, ROWM) = fwd(tmp, ROWM) = 0;
+ word_font(tmp) = 0;
+ word_colour(tmp) = 0;
+ word_outline(tmp) = 0;
+ word_language(tmp) = 0;
+ word_hyph(tmp) = 0;
+ underline(tmp) = UNDER_OFF;
+ Link(x, tmp);
+
+ /* if extend_unbreakable, run through x and set every gap in the */
+ /* shadow of a previous gap to be unbreakable */
+ if( extend_unbreakable )
+ { int f, max_f; OBJECT g;
+ FirstDefinite(x, link, y, jn);
+ assert( link != x, "FillObject/extend_unbreakable: link == x!" );
+ f = max_f = size(y, COLM); prev = y;
+ NextDefiniteWithGap(x, link, y, g, jn);
+ while( link != x )
+ {
+ /* add unbreakableness if gap is overshadowed by a previous one */
+ f += MinGap(fwd(prev, COLM), back(y, COLM), fwd(y, COLM), &gap(g))
+ - fwd(prev, COLM) + back(y, COLM);
+ if( f < max_f )
+ { if( units(gap(g)) == FIXED_UNIT )
+ nobreak(gap(g)) = TRUE;
+ }
+ else
+ { max_f = f;
+ }
+
+ /* on to next component and gap */
+ prev = y;
+ NextDefiniteWithGap(x, link, y, g, jn);
+ }
+ }
+
+ /* initially we can hyphenate if hyphenation is on, but not first pass */
+ if( hyph_style(save_style(x)) == HYPH_UNDEF )
+ Error(14, 7, "hyphen or nohyphen option missing", FATAL, &fpos(x));
+ hyph_allowed = FALSE;
+
+ /* initialize I to first interval, BestI to best ending here, and run */
+ RESTART:
+ IntervalInit(I, x, max_width, etc_width, hyph_word); BestI = I;
+ while( IntervalClass(I) != AT_END )
+ {
+ debug0(DOF, D, "loop:");
+ debug1(DOF, D, " %s", IntervalPrint(I, x));
+ switch( IntervalClass(I) )
+ {
+
+ case TOO_LOOSE:
+ case EMPTY_INTERVAL:
+
+ /* too loose, so save best and shift right end */
+ if( IntervalClass(I) == EMPTY_INTERVAL ||
+ IntervalBadness(BestI) <= IntervalBadness(I) )
+ I = BestI;
+ debug1(DOF, D, "BestI: %s\n", IntervalPrint(I, x));
+ /* NB no break */
+
+
+ case UNBREAKABLE_RIGHT:
+
+ IntervalShiftRightEnd(I, x, hyph_word, max_width, etc_width);
+ BestI = I;
+ break;
+
+
+ case LOOSE:
+ case TIGHT:
+ case TOO_TIGHT:
+
+ /* reasonable, so check best and shift left end */
+ if( IntervalBadness(I) < IntervalBadness(BestI) ) BestI = I;
+ /* NB no break */
+
+
+ case UNBREAKABLE_LEFT:
+ case TAB_OVERLAP:
+
+ /* too tight, or unbreakable gap at left end, so shift left end */
+ IntervalShiftLeftEnd(I, x, max_width, etc_width);
+ break;
+
+
+ /* ***
+ case EMPTY_INTERVAL:
+
+ PrevDefinite(x, I.llink, y);
+ if( can_hyphenate )
+ { x = Hyphenate(x);
+ can_hyphenate = FALSE;
+ hyph_allowed = TRUE;
+ *hyph_used = TRUE;
+ }
+ else CorrectOversize(x, I.llink,
+ (I.cwid!=nilobj) ? bfc(constraint(I.cwid)) : etc_width);
+ goto RESTART;
+ *** */
+
+
+ default:
+
+ assert(FALSE, "FillObject: IntervalClass(I)");
+ break;
+
+ }
+ }
+
+ /* do end processing */
+ ifdebug(DOF, DD,
+ debug0(DOF, DD, "final result:");
+ debug1(DOF, DD, "%s", IntervalPrint(BestI, x));
+ while( BestI.llink != x )
+ { BestI.rlink = BestI.llink;
+ Child(gp, BestI.rlink);
+ BestI.llink = save_prev(gp);
+ debug1(DOF, DD, "%s", IntervalPrint(BestI, x));
+ }
+ );
+
+ if( can_hyphenate && IntervalBadness(BestI) > HYPH_BAD )
+ {
+ /* the result is bad enough to justify the cost of a second attempt, */
+ /* with hyphenation turned on this time */
+ x = Hyphenate(x);
+ can_hyphenate = FALSE;
+ hyph_allowed = TRUE;
+ *hyph_used = TRUE;
+ goto RESTART;
+ }
+ else if( I.llink == x )
+ { /* The result has only one line. Since the line did not fit initially, */
+ /* this must mean either that a large word was discarded or else that */
+ /* the line was only slightly tight */
+ if( multi == nilobj )
+ { res = x;
+ back(res, COLM) = 0; fwd(res, COLM) = max_width;
+ }
+ else
+ { New(res, VCAT);
+ adjust_cat(res) = FALSE;
+ ReplaceNode(res, x);
+ Link(res, x);
+ }
+ }
+ else
+ { OBJECT lgap, llink;
+ New(res, VCAT);
+ adjust_cat(res) = FALSE;
+ back(res, COLM) = 0; fwd(res, COLM) = max_width;
+ ReplaceNode(res, x);
+ llink = I.llink;
+
+ /* break the lines of x */
+ while( llink != x )
+ { New(y, ACAT);
+ adjust_cat(y) = adjust_cat(x);
+ FposCopy(fpos(y), fpos(x));
+ StyleCopy(save_style(y), save_style(x));
+ if( Down(res) != res &&
+ (display_style(save_style(y)) == DISPLAY_ADJUST ||
+ display_style(save_style(y)) == DISPLAY_OUTDENT) )
+ display_style(save_style(y)) = DO_ADJUST;
+ back(y, COLM) = 0;
+ fwd(y, COLM) = max_width;
+
+ /* if outdented paragraphs, add 2.0f @Wide & to front of new line */
+ if( display_style(save_style(x)) == DISPLAY_OUTDENT ||
+ display_style(save_style(x)) == DISPLAY_ORAGGED )
+ {
+ OBJECT t1, t2, z;
+ t1 = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ back(t1, COLM) = fwd(t1, COLM) = back(t1, ROWM) = fwd(t1, ROWM) = 0;
+ word_font(t1) = 0;
+ word_colour(t1) = 0;
+ word_outline(t1) = 0;
+ word_language(t1) = 0;
+ word_hyph(t1) = 0;
+ underline(t1) = UNDER_OFF;
+ New(t2, WIDE);
+ SetConstraint(constraint(t2), MAX_FULL_LENGTH, outdent_margin,
+ MAX_FULL_LENGTH);
+ back(t2, COLM) = 0; fwd(t2, COLM) = outdent_margin;
+ underline(t2) = UNDER_OFF;
+ Link(t2, t1);
+ Link(y, t2);
+ New(z, GAP_OBJ);
+ hspace(z) = vspace(z) = 0;
+ SetGap(gap(z), TRUE, FALSE, TRUE, FIXED_UNIT, EDGE_MODE, 0);
+ Link(y, z);
+ }
+
+ /* move the line to below y */
+ TransferLinks(NextDown(llink), x, y);
+
+ /* add hyphen to end of previous line, if lgap is ADD_HYPH */
+ Child(lgap, llink);
+ if( mode(gap(lgap)) == ADD_HYPH )
+ { OBJECT z; BOOLEAN under;
+
+ /* work out whether the hyphen needs to be underlined */
+ Child(z, LastDown(x));
+ under = underline(z);
+
+ /* add zero-width gap object */
+ New(z, GAP_OBJ);
+ debug0(DOF, DD, " adding hyphen\n");
+ hspace(z) = vspace(z) = 0;
+ underline(z) = under;
+ SetGap(gap(z), TRUE, FALSE, TRUE, FIXED_UNIT, EDGE_MODE, 0);
+ Link(x, z);
+
+ /* add hyphen */
+ z = MakeWord(WORD, STR_HYPHEN, &fpos(y));
+ word_font(z) = font(save_style(x));
+ word_colour(z) = colour(save_style(x));
+ word_outline(z) = outline(save_style(x));
+ word_language(z) = language(save_style(x));
+ word_hyph(z) = hyph_style(save_style(x)) == HYPH_ON;
+ underline(z) = under;
+ FontWordSize(z);
+ Link(x, z);
+ }
+
+ /* attach y to res, recycle lgap for gap separating the two lines */
+ Link(NextDown(res), y);
+ MoveLink(llink, NextDown(res), PARENT);
+ hspace(lgap) = 0;
+ vspace(lgap) = 1;
+ GapCopy(gap(lgap), line_gap(save_style(x)));
+ if( Down(lgap) != lgap ) DisposeChild(Down(lgap));
+
+ /* move on to previous line */
+ llink = save_prev(lgap);
+ }
+
+ /* attach first line, x, to res */
+ Link(NextDown(res), x);
+ back(x, COLM) = 0;
+ fwd(x, COLM) = max_width;
+ if( display_style(save_style(x)) == DISPLAY_ADJUST ||
+ display_style(save_style(x)) == DISPLAY_OUTDENT )
+ display_style(save_style(x)) = DO_ADJUST;
+
+ /* if last line contains only the {} from final &1rt {}, delete the line */
+ /* and the preceding gap */
+ Child(y, LastDown(res));
+ if( Down(y) == LastDown(y) )
+ { DisposeChild(LastDown(res));
+ assert( Down(res) != LastDown(res), "almost empty paragraph!" );
+ DisposeChild(LastDown(res));
+ }
+
+ /* else delete the final &1rt {} from the last line, to help clines */
+ else
+ { Child(z, LastDown(y));
+ assert( type(z)==WORD && string(z)[0]=='\0', "FillObject: last word!" );
+ DisposeChild(LastDown(y));
+ Child(z, LastDown(y));
+ assert( type(z) == GAP_OBJ, "FillObject: last gap_obj!" );
+ DisposeChild(LastDown(y));
+ }
+
+ /* set unbreakable bit of first and last inter-line gaps, if required */
+ if( nobreakfirst(save_style(x)) && Down(res) != LastDown(res) )
+ { Child(gp, NextDown(Down(res)));
+ assert( type(gp) == GAP_OBJ, "FillObject: type(gp) != GAP_OBJ (a)!" );
+ nobreak(gap(gp)) = TRUE;
+ }
+ if( nobreaklast(save_style(x)) && Down(res) != LastDown(res) )
+ { Child(gp, PrevDown(LastDown(res)));
+ assert( type(gp) == GAP_OBJ, "FillObject: type(gp) != GAP_OBJ (b)!" );
+ nobreak(gap(gp)) = TRUE;
+ }
+
+
+ /* recalculate the width of the last line, since it may now be smaller */
+ assert( LastDown(res) != res, "FillObject: empty paragraph!" );
+ Child(y, LastDown(res));
+ FirstDefinite(y, link, z, jn);
+ assert( link != y, "FillObject: last line is empty!" );
+ f = back(z, COLM); prev = z;
+ NextDefiniteWithGap(y, link, z, gp, jn);
+ while( link != y )
+ {
+ f += MinGap(fwd(prev, COLM), back(z, COLM), fwd(z, COLM), &gap(gp));
+ prev = z;
+ NextDefiniteWithGap(y, link, z, gp, jn);
+ }
+ fwd(y, COLM) = find_min(MAX_FULL_LENGTH, f + fwd(prev, COLM));
+
+ /* make last line DO_ADJUST if it is oversize */
+ if( size(y, COLM) > max_width ) display_style(save_style(y)) = DO_ADJUST;
+ }
+
+ /* rejoin unused hyphenated gaps so that kerning will work across them */
+ if( *hyph_used && type(res) == VCAT )
+ { for( link = Down(res); link != res; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == ACAT )
+ { for( ylink = Down(y); ylink != y; ylink = NextDown(ylink) )
+ { Child(gp, ylink);
+ if( type(gp) == GAP_OBJ && width(gap(gp)) == 0 &&
+ mode(gap(gp)) == ADD_HYPH )
+ {
+ /* possible candidate for joining, look into what's on each side */
+ Child(prev, PrevDown(ylink));
+ Child(next, NextDown(ylink));
+ if( is_word(type(prev)) && is_word(type(next)) &&
+ word_font(prev) == word_font(next) &&
+ word_colour(prev) == word_colour(next) &&
+ word_outline(prev) == word_outline(next) &&
+ word_language(prev) == word_language(next) &&
+ underline(prev) == underline(next) )
+ {
+ debug2(DOF, D, "joining %s with %s", EchoObject(prev),
+ EchoObject(next));
+ typ = type(prev) == QWORD || type(next) == QWORD ? QWORD : WORD;
+ tmp = MakeWordTwo(typ, string(prev), string(next), &fpos(prev));
+ word_font(tmp) = word_font(prev);
+ word_colour(tmp) = word_colour(prev);
+ word_outline(tmp) = word_outline(prev);
+ word_language(tmp) = word_language(prev);
+ word_hyph(tmp) = word_hyph(prev);
+ FontWordSize(tmp);
+ underline(tmp) = underline(prev);
+ MoveLink(ylink, tmp, CHILD);
+ DisposeChild(Up(prev));
+ DisposeChild(Up(next));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ debug0(DOF, D, "FillObject exiting");
+ return res;
+ } /* end FillObject */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z15.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z15.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z15.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,844 ----
+ /*@z15.c:Size Constraints:MinConstraint(), EnlargeToConstraint()@*************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z15.c */
+ /* MODULE: Size Constraints */
+ /* EXTERNS: MinConstraint(), EnlargeToConstraint(), */
+ /* ReflectConstraint(), SemiRotateConstraint(), */
+ /* RotateConstraint(), InvScaleConstraint(), Constrained(), */
+ /* EchoConstraint(), DebugConstrained() */
+ /* */
+ /*****************************************************************************/
+ #include <math.h>
+ #ifndef M_PI
+ #define M_PI 3.1415926535897931160E0
+ #endif
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* MinConstraint(xc, yc) */
+ /* */
+ /* Replace *xc by the minimum of the two constraints *xc and *yc. */
+ /* */
+ /*****************************************************************************/
+
+ void MinConstraint(CONSTRAINT *xc, CONSTRAINT *yc)
+ { bc(*xc) = find_min(bc(*xc), bc(*yc));
+ bfc(*xc) = find_min(bfc(*xc), bfc(*yc));
+ fc(*xc) = find_min(fc(*xc), fc(*yc));
+ } /* end MinConstraint */
+
+
+ /*****************************************************************************/
+ /* */
+ /* SetSizeToMaxForwardConstraint(b, f, c) */
+ /* */
+ /* Set *b, *f to their largest possible value within constraint *c, such */
+ /* that *f is as large as possible. */
+ /* */
+ /*****************************************************************************/
+
+ void SetSizeToMaxForwardConstraint(FULL_LENGTH *b, FULL_LENGTH *f, CONSTRAINT *c)
+ {
+ *f = find_min(bfc(*c), fc(*c));
+ *b = find_min(bc(*c), bfc(*c) - *f);
+ } /* end EnlargeToConstraint */
+
+
+ /*****************************************************************************/
+ /* */
+ /* EnlargeToConstraint(b, f, c) */
+ /* */
+ /* Enlarge *b,*f to its largest possible value within constraint *c. */
+ /* */
+ /*****************************************************************************/
+
+ void EnlargeToConstraint(FULL_LENGTH *b, FULL_LENGTH *f, CONSTRAINT *c)
+ {
+ *f = find_min(bfc(*c) - *b, fc(*c));
+ } /* end EnlargeToConstraint */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ReflectConstraint(xc, yc) */
+ /* */
+ /* Set xc to the constraint which is yc with its back and forward reversed. */
+ /* */
+ /*****************************************************************************/
+
+ #define ReflectConstraint(xc, yc) SetConstraint(xc, fc(yc), bfc(yc), bc(yc))
+
+
+ /*@::ScaleToConstraint(), InvScaleConstraint(), etc@**************************/
+ /* */
+ /* int ScaleToConstraint(b, f, c) */
+ /* */
+ /* Return the scale factor needed to scale object of size b, f down so it */
+ /* has a size which fits tightly into constraint c. */
+ /* */
+ /*****************************************************************************/
+
+ int ScaleToConstraint(FULL_LENGTH b, FULL_LENGTH f, CONSTRAINT *c)
+ { float scale_factor; int res;
+ debug3(DSC, DD, "ScaleToConstraint(%s, %s, %s)", EchoLength(b),
+ EchoLength(f), EchoConstraint(c));
+ scale_factor = 1.0;
+ if( b > 0 ) scale_factor = find_min(scale_factor, (float) bc(*c)/b );
+ if( b + f > 0 ) scale_factor = find_min(scale_factor, (float) bfc(*c)/(b + f));
+ if( f > 0 ) scale_factor = find_min(scale_factor, (float) fc(*c)/f );
+ res = scale_factor * SF;
+ debug2(DSC, DD, "ScaleToConstraint returning %.2f (%d)", scale_factor, res);
+ return res;
+ } /* end ScaleToConstraint */
+
+
+ /*****************************************************************************/
+ /* */
+ /* InvScaleConstraint(yc, sf, xc) */
+ /* */
+ /* Scale constraint xc to the inverse of the scale factor sf. */
+ /* */
+ /*****************************************************************************/
+
+ void InvScaleConstraint(CONSTRAINT *yc, FULL_LENGTH sf, CONSTRAINT *xc)
+ {
+ #if DEBUG_ON
+ char buff[10];
+ #endif
+ ifdebug(DSC, DD, sprintf(buff, "%.3f", (float) sf / SF));
+ debug2(DSC, DD, "InvScaleConstraint(yc, %s, %s)", buff, EchoConstraint(xc));
+ assert( sf > 0, "InvScaleConstraint: sf <= 0!" );
+ bc(*yc) = bc(*xc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH :
+ find_min(MAX_FULL_LENGTH, bc(*xc) * SF / sf);
+ bfc(*yc) = bfc(*xc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH :
+ find_min(MAX_FULL_LENGTH, bfc(*xc)* SF / sf);
+ fc(*yc) = fc(*xc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH :
+ find_min(MAX_FULL_LENGTH, fc(*xc) * SF / sf);
+ debug1(DSC, DD, "InvScaleConstraint returning %s", EchoConstraint(yc));
+ } /* end InvScaleConstraint */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static SemiRotateConstraint(xc, u, v, angle, yc) */
+ /* */
+ /* Used by RotateConstraint to calculate one rotated constraint. */
+ /* */
+ /*****************************************************************************/
+
+ static void SemiRotateConstraint(CONSTRAINT *xc, FULL_LENGTH u, FULL_LENGTH v,
+ float angle, CONSTRAINT *yc)
+ { float cs, sn;
+ #if DEBUG_ON
+ char buff[20];
+ #endif
+ ifdebug(DSC, DD, sprintf(buff, "%.1f", angle * 360.0 / (2 * M_PI)));
+ debug4(DSC, DD, "SemiRotateConstraint(xc, %s, %s, %sd, %s",
+ EchoLength(u), EchoLength(v), buff, EchoConstraint(yc));
+ cs = cos(angle); sn = sin(angle);
+ if( fabs(cs) < 1e-6 )
+ SetConstraint(*xc, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ else
+ SetConstraint(*xc,
+ find_min(MAX_FULL_LENGTH, (bc(*yc) - u * sn) / cs),
+ find_min(MAX_FULL_LENGTH, (bfc(*yc) - u * sn - v * sn) / cs),
+ find_min(MAX_FULL_LENGTH, (fc(*yc) - v * sn) / cs ));
+ debug1(DSC, DD, "SemiRotateConstraint returning %s", EchoConstraint(xc));
+ } /* end SemiRotateConstraint */
+
+
+ /*@::RotateConstraint()@******************************************************/
+ /* */
+ /* RotateConstraint(c, y, angle, hc, vc, dim) */
+ /* */
+ /* Take the object angle @Rotate y, which is supposed to be constrained */
+ /* horizontally by hc and vertically by vc, and determine a constraint */
+ /* (either horizontal or vertical, depending on dim) for y. */
+ /* */
+ /* The constraint returned is a trigonometric function of all these */
+ /* parameters, including the present size of y in dimension 1-dim. */
+ /* */
+ /*****************************************************************************/
+
+ void RotateConstraint(CONSTRAINT *c, OBJECT y, FULL_LENGTH angle,
+ CONSTRAINT *hc, CONSTRAINT *vc, int dim)
+ { CONSTRAINT c1, c2, c3, dc; float theta, psi;
+ #if DEBUG_ON
+ char buff[20];
+ #endif
+ ifdebug(DSC, DD, sprintf(buff, "%.1f", (float) angle / DG ));
+ debug4(DSC, DD, "RotateConstraint(c, y, %sd, %s, %s, %s)",
+ buff, EchoConstraint(hc), EchoConstraint(vc), dimen(dim));
+
+ /* work out angle in radians between 0 and 2*PI */
+ theta = (float) angle * 2 * M_PI / (float) (DG * 360);
+ while( theta < 0 ) theta += 2 * M_PI;
+ while( theta >= 2 * M_PI ) theta -= 2 * M_PI;
+ assert( 0 <= theta && theta <= 2 * M_PI, "RotateConstraint: theta!" );
+
+ /* determine theta, c1, and c2 depending on which quadrant we are in */
+ if( theta <= M_PI / 2.0 ) /* first quadrant */
+ { theta = theta;
+ CopyConstraint(c1, *hc);
+ CopyConstraint(c2, *vc);
+ }
+ else if ( theta <= M_PI ) /* second quadrant */
+ { theta -= M_PI / 2.0;
+ ReflectConstraint(c1, *vc);
+ CopyConstraint(c2, *hc);
+ }
+ else if ( theta <= 3.0 * M_PI / 2.0 ) /* third quadrant */
+ { theta -= M_PI;
+ ReflectConstraint(c1, *hc);
+ ReflectConstraint(c2, *vc);
+ }
+ else /* fourth quadrant */
+ { theta -= 3.0 * M_PI / 2.0;
+ CopyConstraint(c1, *vc);
+ ReflectConstraint(c2, *hc);
+ }
+ psi = M_PI / 2.0 - theta;
+ debug2(DSC, DD, " c1: %s; c2: %s", EchoConstraint(&c1), EchoConstraint(&c2));
+
+ /* return the minimum of the two constraints, rotated */
+ if( dim == COLM )
+ { SemiRotateConstraint(c, back(y, ROWM), fwd(y, ROWM), theta, &c1);
+ ReflectConstraint(c3, c2);
+ SemiRotateConstraint(&dc, fwd(y, ROWM), back(y, ROWM), psi, &c3);
+ MinConstraint(c, &dc);
+ }
+ else
+ { SemiRotateConstraint(c, back(y, COLM), fwd(y, COLM), psi, &c1);
+ SemiRotateConstraint(&dc, fwd(y, COLM), back(y, COLM), theta, &c2);
+ MinConstraint(c, &dc);
+ }
+
+ debug1(DSC, DD, "RotateConstraint returning %s", EchoConstraint(c));
+ } /* end RotateConstraint */
+
+ /*@::InsertScale()@***********************************************************/
+ /* */
+ /* BOOLEAN InsertScale(x, c) */
+ /* */
+ /* Insert a @Scale object above x so that x is scaled horizontally to fit */
+ /* constraint c. If this is not possible, owing to the necessary scale */
+ /* factor being too small, then don't do it; return FALSE instead. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN InsertScale(OBJECT x, CONSTRAINT *c)
+ { int scale_factor; OBJECT prnt;
+ scale_factor = ScaleToConstraint(back(x, COLM), fwd(x, COLM), c);
+ if( scale_factor >= 0.2 * SF )
+ {
+ New(prnt, SCALE);
+ underline(prnt) = underline(x);
+ FposCopy(fpos(prnt), fpos(x));
+
+ /* set horizontal size and scale factor */
+ bc(constraint(prnt)) = scale_factor;
+ back(prnt, COLM) = ( back(x, COLM) * scale_factor ) / SF;
+
+ /* *** slightly too small?
+ fwd(prnt, COLM) = ( fwd(x, COLM) * scale_factor ) / SF;
+ *** */
+ fwd(prnt, COLM) = find_min(bfc(*c) - back(prnt, COLM), fc(*c));
+
+ /* set vertical size and scale factor */
+ fc(constraint(prnt)) = 1 * SF;
+ back(prnt, ROWM) = back(x, ROWM);
+ fwd(prnt, ROWM) = fwd(x, ROWM);
+
+ /* link prnt above x and return */
+ ReplaceNode(prnt, x);
+ Link(prnt, x);
+ return TRUE;
+ }
+ else return FALSE;
+ } /* end InsertScale */
+
+
+ /*@::CatConstrained()@********************************************************/
+ /* */
+ /* static CatConstrained(x, xc, ratm, y, dim, OBJECT *why) */
+ /* */
+ /* Calculate the size constraint of object x, as for Constrained below. */
+ /* y is the enclosing VCAT etc. object; ratm is TRUE if a ^ lies after */
+ /* x anywhere. dim is COLM or ROWM. */
+ /* */
+ /* The meaning of the key variables is as follows: */
+ /* */
+ /* be The amount by which back(x, dim) can increase from zero */
+ /* without having any impact on size(y, dim). Thereafter, */
+ /* any increase causes an equal increase in size(y, dim). */
+ /* */
+ /* fe The amount by which fwd(x, dim) can increase from zero */
+ /* without having any impact on size(y, dim). Thereafter, */
+ /* any increase causes an equal increase in size(y, dim). */
+ /* */
+ /* backy, The value that back(y, dim) and fwd(y, dim) would have if x */
+ /* fwdy was definite with size 0,0. They will in general be larger */
+ /* than the present values if x is indefinite, and smaller */
+ /* if x is definite, although it depends on marks and gaps. */
+ /* */
+ /*****************************************************************************/
+
+ static void CatConstrained(OBJECT x, CONSTRAINT *xc, BOOLEAN ratm,
+ OBJECT y, int dim, OBJECT *why)
+ { int side; /* the size of y that x is on: BACK, ON, FWD */
+ CONSTRAINT yc; /* constraints on y */
+ FULL_LENGTH backy, fwdy; /* back(y), fwd(y) would be if x was (0, 0) */
+ FULL_LENGTH be, fe; /* amount back(x), fwd(x) can be for free */
+ FULL_LENGTH beffect, feffect; /* scratch variables for calculations */
+ FULL_LENGTH seffect; /* scratch variables for calculations */
+ OBJECT link, sg, pg; /* link to x, its successor and predecessor */
+ OBJECT prec_def, sd; /* definite object preceding (succeeding) x */
+ int tb, tbf, tf, tbc, tbfc, tfc, mxy, myz;
+
+ Constrained(y, &yc, dim, why);
+ if( constrained(yc) )
+ {
+ /* find the link of x, and its neighbours and their links */
+ link = UpDim(x, dim);
+ SetNeighbours(link, ratm, &pg, &prec_def, &sg, &sd, &side);
+
+ /* amount of space available at x without changing the size of y */
+ be = pg == nilobj ? 0 : ExtraGap(fwd(prec_def, dim), 0, &gap(pg), BACK);
+ fe = sg == nilobj ? 0 : ExtraGap(0, back(sd, dim), &gap(sg), FWD);
+
+ if( is_indefinite(type(x)) )
+ {
+ /* insert two lengths and delete one */
+ beffect = pg==nilobj ? 0 : MinGap(fwd(prec_def, dim), 0, 0, &gap(pg));
+ feffect = sg==nilobj ? 0 : MinGap(0, back(sd,dim), fwd(sd,dim), &gap(sg));
+ seffect = pg==nilobj ?
+ sg == nilobj ? 0 : back(sd, dim) :
+ sg == nilobj ? fwd(prec_def, dim) :
+ MinGap(fwd(prec_def, dim), back(sd, dim), fwd(sd, dim), &gap(sg));
+
+ switch( side )
+ {
+ case BACK: backy = back(y, dim) + beffect + feffect - seffect;
+ fwdy = fwd(y, dim);
+ break;
+
+ case ON: /* must be first, other cases prohibited */
+ backy = 0;
+ fwdy = fwd(y, dim) + feffect;
+ break;
+
+ case FWD: backy = back(y, dim);
+ fwdy = fwd(y, dim) + beffect + feffect - seffect;
+ break;
+ }
+ }
+
+ else /* x is definite */
+
+ { beffect = pg == nilobj ? back(x, dim) :
+ MinGap(fwd(prec_def, dim), back(x,dim), fwd(x,dim), &gap(pg)) -
+ MinGap(fwd(prec_def, dim), 0, 0, &gap(pg));
+
+ feffect = sg == nilobj ? fwd(x, dim) :
+ MinGap(fwd(x, dim), back(sd, dim), fwd(sd, dim), &gap(sg)) -
+ MinGap(0, back(sd, dim), fwd(sd, dim), &gap(sg));
+
+ switch( side )
+ {
+ case BACK: backy = back(y, dim) - beffect - feffect;
+ fwdy = fwd(y, dim);
+ break;
+
+ case ON: backy = back(y, dim) - beffect;
+ fwdy = fwd(y, dim) - feffect;
+ break;
+
+ case FWD: backy = back(y, dim);
+ fwdy = fwd(y, dim) - beffect - feffect;
+ break;
+ }
+ }
+
+ debug5(DSC, DD, " side: %s, backy: %s, fwdy: %s, be: %s, fe: %s",
+ Image(side), EchoLength(backy), EchoLength(fwdy),
+ EchoLength(be), EchoLength(fe) );
+
+ if( !FitsConstraint(backy, fwdy, yc) )
+ SetConstraint(*xc, -1, -1, -1);
+ else switch( side )
+ {
+
+ case BACK:
+
+ tbc = bc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bc(yc) - backy;
+ tbfc = bfc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bfc(yc) - backy - fwdy;
+ mxy = find_min(tbc, tbfc);
+ tb = find_min(MAX_FULL_LENGTH, be + mxy);
+ tbf = find_min(MAX_FULL_LENGTH, be + fe + mxy);
+ tf = find_min(MAX_FULL_LENGTH, fe + mxy);
+ SetConstraint(*xc, tb, tbf, tf);
+ break;
+
+
+ case ON:
+
+ tbc = bc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bc(yc) - backy;
+ tbfc = bfc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bfc(yc) - backy - fwdy;
+ tfc = fc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : fc(yc) - fwdy;
+ mxy = find_min(tbc, tbfc);
+ myz = find_min(tfc, tbfc);
+ tb = find_min(MAX_FULL_LENGTH, be + mxy);
+ tbf = find_min(MAX_FULL_LENGTH, be + fe + tbfc);
+ tf = find_min(MAX_FULL_LENGTH, fe + myz);
+ SetConstraint(*xc, tb, tbf, tf);
+ break;
+
+
+ case FWD:
+
+ tfc = fc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : fc(yc) - fwdy;
+ tbfc = bfc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bfc(yc) - backy - fwdy;
+ mxy = find_min(tfc, tbfc);
+ tb = find_min(MAX_FULL_LENGTH, be + mxy);
+ tbf = find_min(MAX_FULL_LENGTH, be + fe + mxy);
+ tf = find_min(MAX_FULL_LENGTH, fe + mxy);
+ SetConstraint(*xc, tb, tbf, tf);
+ break;
+
+ }
+ } /* end if( constrained ) */
+ else SetConstraint(*xc, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ } /* end CatConstrained */
+
+
+ /*@::Constrained()@***********************************************************/
+ /* */
+ /* Constrained(x, xc, dim, why) */
+ /* */
+ /* Calculate the size constraint of object x, and return it in *xc. */
+ /* */
+ /* If the resulting constraint is a hard one caused by coming up against */
+ /* a HIGH (vertical) or WIDE (horizontal), set *why to this object; if */
+ /* not, leave *why unchanged. */
+ /* */
+ /*****************************************************************************/
+
+ void Constrained(OBJECT x, CONSTRAINT *xc, int dim, OBJECT *why)
+ { OBJECT y, link, lp, rp, z, tlink, g; CONSTRAINT yc, hc, vc;
+ BOOLEAN ratm; FULL_LENGTH xback, xfwd; int tb, tf, tbf, tbc, tfc;
+ SetLengthDim(dim);
+ debug2(DSC, DD, "[ Constrained(%s, xc, %s, why), x =",
+ Image(type(x)), dimen(dim));
+ ifdebug(DSC, DD, DebugObject(x));
+ assert( Up(x) != x, "Constrained: x has no parent!" );
+
+ /* a CLOSURE which is external_ver is unconstrained in the ROWM direction */
+ /* a CLOSURE which is external_hor is unconstrained in both directions */
+ if( type(x) == CLOSURE && ((dim==ROWM && external_ver(x)) || external_hor(x)) )
+ {
+ SetConstraint(*xc, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ debug1(DSC, DD, "] Constrained returning %s (external)",EchoConstraint(xc));
+ return;
+ }
+
+ /* find y, the parent of x */
+ link = UpDim(x, dim); ratm = FALSE;
+ for( tlink = NextDown(link); type(tlink) == LINK; tlink = NextDown(tlink) )
+ { Child(g, tlink);
+ if( type(g) == GAP_OBJ && mark(gap(g)) ) ratm = TRUE;
+ }
+ y = tlink;
+ debug1(DSC, DDD, "parent y = %s", Image(type(y)));
+ ifdebug(DSC, DDD, DebugObject(y));
+
+ switch( type(y) )
+ {
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case KERN_SHRINK:
+ case BEGIN_HEADER:
+ case SET_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case SPLIT:
+ case BACKGROUND:
+
+ Constrained(y, xc, dim, why);
+ break;
+
+
+ case HSCALE:
+ case VSCALE:
+
+ if( (dim == COLM) != (type(y) == HSCALE) ) Constrained(y, xc, dim, why);
+ else SetConstraint(*xc, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ break;
+
+
+ case HCOVER:
+ case VCOVER:
+
+ /* dubious, but not likely to arise anyway */
+ if( (dim == COLM) != (type(y) == HCOVER) ) Constrained(y, xc, dim, why);
+ else SetConstraint(*xc, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ break;
+
+
+ case SCALE:
+
+ Constrained(y, &yc, dim, why);
+ if( dim == COLM && bc(constraint(y)) == 0 )
+ {
+ /* Lout-supplied factor required later, could be tiny */
+ SetConstraint(*xc, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ }
+ else
+ { InvScaleConstraint(xc,
+ dim == COLM ? bc(constraint(y)) : fc(constraint(y)), &yc);
+ }
+ break;
+
+
+ case ROTATE:
+
+ Constrained(y, &hc, COLM, why); Constrained(y, &vc, ROWM, why);
+ RotateConstraint(xc, x, sparec(constraint(y)), &hc, &vc, dim);
+ break;
+
+
+ case WIDE:
+ case HIGH:
+
+ Constrained(y, xc, dim, why);
+ if( (type(y)==WIDE) == (dim==COLM) )
+ { MinConstraint(xc, &constraint(y));
+ *why = y;
+ }
+ break;
+
+
+ case HLIMITED:
+ case VLIMITED:
+
+ if( (type(y) == HLIMITED) == (dim == COLM) )
+ {
+ BOOLEAN still_searching = TRUE;
+ z = y;
+ SetConstraint(*xc, back(z, dim), size(z, dim), fwd(z, dim));
+ debug2(DSC, D, " [ %s (%s)", Image(type(z)), EchoConstraint(xc));
+ while( still_searching && Up(z) != z )
+ {
+ Parent(z, UpDim(z, dim));
+ switch( type(z) )
+ {
+ case VLIMITED:
+ case HLIMITED:
+ case COL_THR:
+ case ROW_THR:
+ case ONE_COL:
+ case ONE_ROW:
+ case HCONTRACT:
+ case VCONTRACT:
+ case SPLIT:
+ case START_VSPAN:
+ case START_HSPAN:
+
+ SetConstraint(*xc, back(z, dim), size(z, dim), fwd(z, dim));
+ debug2(DSC, DD, " let s = %s (%s)", Image(type(z)),
+ EchoConstraint(xc));
+ break;
+
+
+ case HSPANNER:
+ case VSPANNER:
+
+ /* SpannerAvailableSpace(z, dim, &b, &f); */
+ CopyConstraint(*xc, constraint(z));
+ debug2(DSC, D, " ] let s = %s (%s) and stop",
+ Image(type(z)), EchoConstraint(&constraint(z)));
+ still_searching = FALSE;
+ break;
+
+
+ default:
+
+ debug1(DSC, D, " ] stopping at %s", Image(type(z)));
+ still_searching = FALSE;
+ break;
+ }
+ }
+ *why = y;
+ }
+ else
+ {
+ Constrained(y, xc, dim, why);
+ }
+ break;
+
+
+ case VSPANNER:
+ case HSPANNER:
+
+ /* we're saying that a spanner has a fixed constraint that is */
+ /* determined just once in its life */
+ CopyConstraint(*xc, constraint(y));
+ debug2(DSC, DD, " Constrained(%s) = %s", Image(type(y)), EchoConstraint(xc));
+ /* SetConstraint(*xc, back(y, dim), size(y, dim), fwd(y, dim)); */
+ break;
+
+
+ case HSHIFT:
+ case VSHIFT:
+
+ if( (type(y) == HSHIFT) == (dim == COLM) )
+ { Constrained(y, &yc, dim, why);
+ tf = FindShift(y, x, dim);
+ SetConstraint(*xc,
+ find_min(bc(yc), bfc(yc)) - tf, bfc(yc), find_min(fc(yc), bfc(yc)) + tf);
+ }
+ else Constrained(y, xc, dim, why);
+ break;
+
+
+ case HEAD:
+
+ if( dim == ROWM )
+ SetConstraint(*xc, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ else
+ { CopyConstraint(yc, constraint(y));
+ debug1(DSC, DD, " head: %s; val is:", EchoConstraint(&yc));
+ ifdebug(DSC, DD, DebugObject(y));
+ goto REST_OF_HEAD; /* a few lines down */
+ }
+ break;
+
+
+ case COL_THR:
+ case ROW_THR:
+
+ assert( (type(y)==COL_THR) == (dim==COLM), "Constrained: COL_THR!" );
+ Constrained(y, &yc, dim, why);
+ tb = bfc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bfc(yc) - fwd(y, dim);
+ tb = find_min(bc(yc), tb);
+ tf = bfc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bfc(yc) - back(y, dim);
+ tf = find_min(fc(yc), tf);
+ SetConstraint(*xc, tb, bfc(yc), tf);
+ break;
+
+
+ case VCAT:
+ case HCAT:
+ case ACAT:
+
+ if( (type(y)==VCAT) == (dim==ROWM) )
+ { CatConstrained(x, xc, ratm, y, dim, why);
+ break;
+ }
+ Constrained(y, &yc, dim, why);
+ if( !constrained(yc) )
+ SetConstraint(*xc, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ else
+ {
+ REST_OF_HEAD:
+ /* let lp and rp be the links of the gaps delimiting */
+ /* the components joined to x (or parent if no such) */
+ for( lp = PrevDown(link); lp != y; lp = PrevDown(lp) )
+ { Child(z, lp);
+ if( type(z) == GAP_OBJ && !join(gap(z)) ) break;
+ }
+ for( rp = NextDown(link); rp != y; rp = NextDown(rp) )
+ { Child(z, rp);
+ if( type(z) == GAP_OBJ && !join(gap(z)) ) break;
+ }
+ if( lp == y && rp == y && !(type(y) == HEAD && seen_nojoin(y)) )
+ {
+ /* if whole object is joined, do this */
+ tb = bfc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bfc(yc) - fwd(y, dim);
+ tb = find_min(bc(yc), tb);
+ tf = bfc(yc) == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : bfc(yc) - back(y, dim);
+ tf = find_min(fc(yc), tf);
+ SetConstraint(*xc, tb, bfc(yc), tf);
+ }
+ else
+ {
+ /* if // or || is present, do this */
+ xback = xfwd = 0;
+ for(link = NextDown(lp); link != rp; link = NextDown(link) )
+ { Child(z, link);
+ if( type(z) == GAP_OBJ || is_index(type(z)) ) continue;
+ xback = find_max(xback, back(z, dim));
+ xfwd = find_max(xfwd, fwd(z, dim));
+ }
+ debug2(DSC, DD, " lp != rp; xback,xfwd = %s,%s",
+ EchoLength(xback), EchoLength(xfwd));
+ tbf = find_min(bfc(yc), fc(yc));
+ tbc = tbf == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : tbf - xfwd;
+ tfc = tbf == MAX_FULL_LENGTH ? MAX_FULL_LENGTH : tbf - xback;
+ SetConstraint(*xc, tbc, tbf, tfc);
+ }
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "Constrained:", Image(type(y)));
+ break;
+
+ }
+ debug2(DSC, DD, "] Constrained %s returning %s", Image(type(x)),
+ EchoConstraint(xc));
+ } /* end Constrained */
+
+
+ /*@::EchoConstraint(), DebugConstrained()@************************************/
+ /* */
+ /* FULL_CHAR *EchoConstraint(c) */
+ /* */
+ /* Returns a string showing constraint *c, in centimetres. */
+ /* */
+ /*****************************************************************************/
+ #if DEBUG_ON
+
+ FULL_CHAR *EchoConstraint(CONSTRAINT *c)
+ { static char str[2][40];
+ static int i = 0;
+ i = (i+1) % 2;
+ sprintf(str[i], "<%s, %s, %s>", EchoLength(bc(*c)), EchoLength(bfc(*c)),
+ EchoLength(fc(*c)));
+ return AsciiToFull(str[i]);
+ } /* end EchoConstraint */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DebugConstrained(x) */
+ /* */
+ /* Calculate and print the constraints of all closures lying within */
+ /* sized object x. */
+ /* */
+ /*****************************************************************************/
+
+ void DebugConstrained(OBJECT x)
+ { OBJECT y, link, why;
+ CONSTRAINT c;
+ debug1(DSC, DDD, "DebugConstrained( %s )", EchoObject(x) );
+ switch( type(x) )
+ {
+
+ case CROSS:
+ case FORCE_CROSS:
+ case ROTATE:
+ case BACKGROUND:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case KERN_SHRINK:
+ case WORD:
+ case QWORD:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+
+ break;
+
+
+ case CLOSURE:
+
+ Constrained(x, &c, COLM, &why);
+ debug2(DSC, DD, "Constrained( %s, &c, COLM ) = %s",
+ EchoObject(x), EchoConstraint(&c));
+ Constrained(x, &c, ROWM, &why);
+ debug2(DSC, DD, "Constrained( %s, &c, ROWM ) = %s",
+ EchoObject(x), EchoConstraint(&c));
+ break;
+
+
+ case SPLIT:
+
+ link = DownDim(x, COLM); Child(y, link);
+ DebugConstrained(y);
+ break;
+
+
+ case HEAD:
+ case ONE_COL:
+ case ONE_ROW:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case SCALE:
+ case WIDE:
+ case HIGH:
+
+ link = Down(x); Child(y, link);
+ DebugConstrained(y);
+ break;
+
+
+ case COL_THR:
+ case VCAT:
+ case HCAT:
+ case ACAT:
+
+ for( link = Down(x); link != x; link =NextDown(link) )
+ { Child(y, link);
+ if( type(y) != GAP_OBJ && !is_index(type(y)) ) DebugConstrained(y);
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "DebugConstrained:", Image(type(x)));
+ break;
+
+ }
+ debug0(DSC, DDD, "DebugConstrained returning.");
+ } /* end DebugConstrained */
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z16.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z16.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z16.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,635 ----
+ /*@z16.c:Size Adjustment:SetNeighbours(), CatAdjustSize()@********************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z16.c */
+ /* MODULE: Size Adjustment */
+ /* EXTERNS: FindShift(), SetNeighbours(), AdjustSize() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_LENGTH FindShift(x, y, dim) */
+ /* */
+ /* x = @HShift y or @VShift y depending on dim. FindShift returns the */
+ /* length of the shift measured from the mark of y to the mark of x. */
+ /* This is negative if the mark of y is to the right of the mark of x. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_LENGTH FindShift(OBJECT x, OBJECT y, int dim)
+ { FULL_LENGTH len, res;
+ debug4(DSF, DD, "FindShift(%s, %s %s, %s)", Image(type(x)),
+ Image(type(y)), EchoObject(y), dimen(dim));
+
+ /* first determine the magnitude of the shift */
+ switch( units(shift_gap(x)) )
+ {
+ case FIXED_UNIT: len = width(shift_gap(x));
+ break;
+
+ case NEXT_UNIT: len = (size(y, dim) * width(shift_gap(x))) / FR;
+ break;
+
+ default: assert(FALSE, "FindShift: units");
+ break;
+ }
+
+ /* then calculate the shift depending on the shift type */
+ switch( shift_type(x) )
+ {
+ case GAP_ABS: res = len - back(y, dim);
+ break;
+
+ case GAP_INC: res = len;
+ break;
+
+ case GAP_DEC: res = - len;
+ break;
+
+ default: assert(FALSE, "FindShift: type");
+ break;
+ }
+
+ debug1(DSF, DD, "FindShift returning %s", EchoLength(res));
+ return res;
+ } /* end FindShift */
+
+
+ /*****************************************************************************/
+ /* */
+ /* SetNeighbours(link, ratm, pg, pdef, sg, sdef, side) */
+ /* */
+ /* This is a utility routine used by CatConstrained(), AdjustSize(), */
+ /* BreakTable() and FlushGalley() for calculating size updates in objects. */
+ /* Assuming that link is the link of a component of a VCAT etc., and that */
+ /* ratm is TRUE if there is a marked component to the right of link, set */
+ /* */
+ /* pg to the gap separating link from the first definite object */
+ /* to the left, or nilobj if none. If pg != nilobj, set pdef to */
+ /* the preceding definite object; else pdef is undefined. */
+ /* */
+ /* sg to the gap separating link from the first definite object */
+ /* to the right, or nilobj if none. if sg != nilobj, set sdef to */
+ /* the succeeding definite object; else sdef is undefined. */
+ /* */
+ /* side to the side of the mark link is on; either BACK, ON or FWD. */
+ /* */
+ /*****************************************************************************/
+
+ void SetNeighbours(OBJECT link, BOOLEAN ratm, OBJECT *pg, OBJECT *pdef,
+ OBJECT *sg, OBJECT *sdef, int *side)
+ { OBJECT plink, slink;
+
+ /* find preceding definite; if it exists, set *pg */
+ *pg = nilobj;
+ for( plink = PrevDown(link); type(plink) == LINK; plink = PrevDown(plink) )
+ { Child(*pdef, plink);
+ if( type(*pdef) == SPLIT ? SplitIsDefinite(*pdef) : is_definite(type(*pdef)) )
+ { Child(*pg, PrevDown(link));
+ while( is_index(type(*pg)) )
+ { link = PrevDown(link);
+ Child(*pg, PrevDown(link));
+ }
+ assert( type(*pg) == GAP_OBJ, "SetNeighbours: type(*pg)!" );
+ break;
+ }
+ }
+
+ /* find succeeding definite; if it exists, set *sg */
+ *sg = nilobj;
+ for( slink = NextDown(link); type(slink) == LINK; slink = NextDown(slink) )
+ { Child(*sdef, slink);
+ if( type(*sdef) == SPLIT ? SplitIsDefinite(*sdef) : is_definite(type(*sdef)) )
+ { Child(*sg, PrevDown(slink));
+ while( is_index(type(*sg)) )
+ { slink = PrevDown(slink);
+ Child(*sg, PrevDown(slink));
+ }
+ assert( type(*sg) == GAP_OBJ, "SetNeighbours: type(*sg)!" );
+ break;
+ }
+ }
+
+ *side = ratm ? BACK : *pg == nilobj || mark(gap(*pg)) ? ON : FWD;
+ debug4(DSA, DD,
+ "SetNeighbours: ratm == %s, pg %s nilobj, sg %s nilobj, side == %s",
+ bool(ratm), *pg == nilobj ? "==" : "!=", *sg == nilobj ? "==" : "!=",
+ *side == BACK ? "BACK" : *side == ON ? "ON" : "FWD");
+ } /* end SetNeighbours */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static CatAdjustSize(x, b, f, ratm, y, dim) */
+ /* */
+ /* Adjust the size of x to be *b, *f. Object x is known to lie in add-set */
+ /* y; ratm is TRUE iff there is a mark to the right of x. Return the */
+ /* new size of y in *b, *f. */
+ /* */
+ /*****************************************************************************/
+
+ static void CatAdjustSize(OBJECT x, FULL_LENGTH *b, FULL_LENGTH *f, BOOLEAN ratm,
+ OBJECT y, int dim)
+ { OBJECT link;
+ OBJECT pg, prec_def, sg, sd;
+ FULL_LENGTH beffect, feffect, seffect; int side;
+ int bb, ff;
+
+ debug6(DSA, DD, "CatAdjustSize(%s x, %s, %s, %s, %s y, %s)", Image(type(x)),
+ EchoLength(*b), EchoLength(*f), bool(ratm), Image(type(y)), dimen(dim));
+ debug2(DSA,DD, "x(%s,%s) =", EchoLength(back(x,dim)), EchoLength(fwd(x,dim)));
+ ifdebug(DSA, DD, DebugObject(x));
+ debug2(DSA,DD, "y(%s,%s) =", EchoLength(back(y,dim)), EchoLength(fwd(y,dim)));
+ ifdebug(DSA, DD, DebugObject(y));
+
+ /* DO_ADJUST ACAT is a special case because adjustment affects its size */
+ if( dim==COLM && type(y)==ACAT && display_style(save_style(y)) == DO_ADJUST )
+ { back(x, dim) = *b; fwd(x, dim) = *f;
+ *b = back(y, dim); *f = fwd(y, dim);
+ debug2(DSA, DD, "CatAdjustSize ACAT %s,%s", EchoLength(*b), EchoLength(*f));
+ return;
+ }
+
+ link = UpDim(x, dim);
+ SetNeighbours(link, ratm, &pg, &prec_def, &sg, &sd, &side);
+ { ifdebug(DSA, DD,
+ if( pg != nilobj && mode(gap(pg)) == NO_MODE )
+ { debug1(DSA, DD, "NO_MODE gap pg, is_indefinite(x) == %s, y =",
+ bool(is_indefinite(type(x))) );
+ ifdebug(DSA, DD, DebugObject(y));
+ }
+ if( sg != nilobj && mode(gap(sg)) == NO_MODE )
+ { debug1(DSA, DD, "NO_MODE gap sg, is_indefinite(x) == %s, y =",
+ bool(is_indefinite(type(x))) );
+ ifdebug(DSA, DD, DebugObject(y));
+ }
+ ); }
+ if( is_indefinite(type(x)) )
+ {
+ beffect = pg == nilobj ? *b :
+ MinGap(fwd(prec_def, dim), *b, *f, &gap(pg));
+
+ feffect = sg == nilobj ? *f :
+ MinGap(*f, back(sd, dim), fwd(sd, dim), &gap(sg));
+
+ seffect = pg == nilobj ? sg == nilobj ? 0 : back(sd, dim) :
+ sg == nilobj ? fwd(prec_def, dim) :
+ MinGap(fwd(prec_def, dim), back(sd,dim), fwd(sd,dim), &gap(sg));
+ }
+ else /* !is_indefinite(type(x)) */
+ {
+ beffect = pg == nilobj ? *b - back(x, dim) :
+ MinGap(fwd(prec_def, dim), *b, *f, &gap(pg)) -
+ MinGap(fwd(prec_def, dim), back(x, dim), fwd(x, dim), &gap(pg));
+
+ feffect = sg == nilobj ? *f - fwd(x, dim) :
+ MinGap(*f, back(sd, dim), fwd(sd, dim), &gap(sg)) -
+ MinGap(fwd(x, dim), back(sd, dim), fwd(sd, dim), &gap(sg));
+
+ seffect = 0;
+ }
+
+ debug3(DSA, D, " pg = %s, sg = %s, side = %s",
+ pg == nilobj ? AsciiToFull("<nil>") : EchoGap(&gap(pg)),
+ sg == nilobj ? AsciiToFull("<nil>") : EchoGap(&gap(sg)), Image(side));
+ debug3(DSA, D, " beffect = %s, feffect = %s, seffect = %s",
+ EchoLength(beffect), EchoLength(feffect), EchoLength(seffect));
+ back(x, dim) = *b; fwd(x, dim) = *f;
+ switch( side )
+ {
+ case BACK: bb = back(y, dim) + beffect + feffect - seffect;
+ ff = fwd(y, dim);
+ break;
+
+ case ON: bb = back(y, dim) + beffect - seffect;
+ ff = fwd(y, dim) + feffect;
+ break;
+
+ case FWD: bb = back(y, dim);
+ ff = fwd(y, dim) + beffect + feffect - seffect;
+ break;
+ }
+ *b = bb; *f = ff;
+ debug2(DSA, DD, "CatAdjustSize returning %s,%s", EchoLength(*b), EchoLength(*f));
+ } /* end CatAdjustSize */
+
+
+ /*@::AdjustSize()@************************************************************/
+ /* */
+ /* AdjustSize(x, b, f, dim) */
+ /* */
+ /* Adjust the size of object x, in dimension dim, to be b, f. If x is a */
+ /* CLOSURE, the adjustment is from a CLOSURE to a definite object of size */
+ /* b, f. */
+ /* */
+ /*****************************************************************************/
+
+ void AdjustSize(OBJECT x, FULL_LENGTH b, FULL_LENGTH f, int dim)
+ { OBJECT y, link, tlink, lp, rp, z, index;
+ BOOLEAN ratm; FULL_LENGTH tb, tf, cby, cfy, rby, rfy;
+
+ SetLengthDim(dim);
+ debug6(DSA, D, "[ AdjustSize( %s(%s,%s), %s, %s, %s ), x =",
+ type(x) == CLOSURE ? SymName(actual(x)) : Image(type(x)),
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)),
+ EchoLength(b), EchoLength(f), dimen(dim));
+ ifdebug(DSA, DD, DebugObject(x) );
+
+ while( b != back(x, dim) || f != fwd(x, dim) || is_indefinite(type(x)) )
+ { assert( Up(x) != x, "AdjustSize: Up(x) == x!" );
+ if( b < 0 || f < 0 )
+ Error(16, 5, "cannot recover from earlier errors", FATAL, &fpos(x));
+
+ /* these cases are unique because they have multiple parents */
+ if( type(x) == COL_THR || type(x) == ROW_THR )
+ { assert( (type(x)==COL_THR) == (dim==COLM), "AdjustSize: COL_THR!" );
+ back(x, dim) = b; fwd(x, dim) = f;
+ for( link = Up(x); link != x; link = NextUp(link) )
+ { Parent(y, link);
+ assert( type(y) == SPLIT, "AdjustSize: type(y) != SPLIT!") ;
+ AdjustSize(y, b, f, dim);
+ }
+ debug0(DSA, D, "] AdjustSize (thread case) returning.");
+ return;
+ }
+
+ link = UpDim(x, dim); ratm = FALSE;
+ for( tlink=NextDown(link); type(tlink) == LINK; tlink=NextDown(tlink) )
+ { Child(y, tlink);
+ if( type(y) == GAP_OBJ && mark(gap(y)) ) ratm = TRUE;
+ }
+ y = tlink;
+
+ debug5(DSA, D, " b = %s, f = %s, y = %s(%s,%s), x =",
+ EchoLength(b), EchoLength(f), Image(type(y)),
+ EchoLength(back(y, dim)), EchoLength(fwd(y, dim)));
+ ifdebug(DSA, DD, DebugObject(x) );
+
+ switch( type(y) )
+ {
+
+ case HEAD:
+
+ if( gall_dir(y) == COLM )
+ { back(x, dim) = b, fwd(x, dim) = f;
+ debug0(DSA, D, "] AdjustSize returning at horiz HEAD");
+ return;
+ }
+ else if( dim == ROWM )
+ { back(x, dim) = b, fwd(x, dim) = f;
+ debug0(DSA, D, "] AdjustSize ROWM returning at HEAD");
+ return;
+ }
+ else
+ {
+ /* let lp and rp be the gaps delimiting the */
+ /* components joined to x */
+ for( lp = PrevDown(link); lp != y; lp = PrevDown(lp) )
+ { Child(z, lp);
+ if( type(z) == GAP_OBJ && !join(gap(z)) ) break;
+ }
+ for( rp = NextDown(link); rp != y; rp = NextDown(rp) )
+ { Child(z, rp);
+ if( type(z) == GAP_OBJ && !join(gap(z)) ) break;
+ }
+
+ back(x, dim) = b; fwd(x, dim) = f;
+ if( lp == y && rp == y && !seen_nojoin(y) )
+ {
+ /* if whole object is joined, do this */
+ b = find_max(b, back(y, dim));
+ f = find_max(f, fwd(y, dim));
+ debug3(DSA, D, " under head %s, whole object joined, b = %s, f = %s)",
+ SymName(actual(y)), EchoLength(b), EchoLength(f));
+ }
+ else
+ {
+ /* if // or || is present, do this */
+ debug1(DSA, D, " [ under head %s with //, working out tb and tf:",
+ SymName(actual(y)));
+ tb = tf = 0;
+ for( link = NextDown(lp); link != rp; link = NextDown(link) )
+ { Child(z, link);
+ debugcond1(DSA, D, type(z) == GAP_OBJ,
+ " gap %s", EchoCatOp(VCAT, mark(gap(z)), join(gap(z))));
+ if( type(z) == GAP_OBJ || is_index(type(z)) ) continue;
+ debug6(DSA, D, " component %s %s(%s, %s) so tb = %s, tf = %s",
+ Image(type(z)), type(z) == CLOSURE ? SymName(actual(z)) : STR_EMPTY,
+ EchoLength(back(z, dim)), EchoLength(fwd(z, dim)),
+ EchoLength(tb), EchoLength(tf));
+ ifdebugcond(DSA, DD, dim == COLM && fwd(z, dim) > 20*CM, DebugObject(z));
+ tb = find_max(tb, back(z, dim));
+ tf = find_max(tf, fwd(z, dim));
+ }
+ b = 0; f = find_max(tb + tf, fwd(y, dim));
+ debug5(DSA, D, " ] under head %s with //, tb = %s, tf = %s, b = %s, f = %s",
+ SymName(actual(y)), EchoLength(tb), EchoLength(tf),
+ EchoLength(b), EchoLength(f));
+ }
+ if( back(y, dim) == b && fwd(y, dim) == f )
+ {
+ debug0(DSA, D, "] AdjustSize (COLM) returning at HEAD (no wider)");
+ return;
+ }
+ debug3(DSA, DD, "AdjustSize widening HEAD %s to b = %s, f = %s",
+ SymName(actual(y)), EchoLength(b), EchoLength(f));
+ ifdebugcond(DSA, DD, dim == COLM && f > 20*CM, DebugObject(y));
+ back(y, dim) = b; fwd(y, dim) = f;
+ if( Up(y) == y )
+ {
+ debug0(DSA, D, "] AdjustSize ret. at HEAD (no parent)" );
+ return;
+ }
+ Parent(index, Up(y));
+ if( type(index) != RECEIVING )
+ {
+ debug1(DSA,D, "] AdjustSize ret. at HEAD (%s)", Image(type(index)));
+ return;
+ }
+ assert(actual(index)!=nilobj, "AdjustSize: actual(index)==nilobj!" );
+ assert( type(actual(index)) == CLOSURE, "AdjustSize: index non-C!" );
+ if( actual(actual(index)) != GalleySym &&
+ actual(actual(index)) != ForceGalleySym )
+ {
+ debug0(DSA, D, "] AdjustSize ret. at HEAD (not @Galley, so root)" );
+ return;
+ }
+ y = actual(index);
+ debug3(DSA, DD, "AdjustSize jumping to y = %s of size %s,%s",
+ Image(type(y)), EchoLength(back(y, dim)), EchoLength(fwd(y, dim)));
+ }
+ break;
+
+
+ case SPLIT:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HEXPAND:
+ case VEXPAND:
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case KERN_SHRINK:
+ case BACKGROUND:
+
+ back(x, dim) = b; fwd(x, dim) = f;
+ break;
+
+
+ case HSCALE:
+ case VSCALE:
+
+ back(x, dim) = b; fwd(x, dim) = f;
+ if( (dim==COLM) == (type(y)==HSCALE) )
+ { debug0(DSA, D, "] AdjustSize returning at HSCALE or VSCALE");
+ return;
+ }
+ break;
+
+
+ case HCOVER:
+ case VCOVER:
+
+ /* dubious, but not likely to arise in practice */
+ back(x, dim) = b; fwd(x, dim) = f;
+ if( (dim==COLM) == (type(y)==HCOVER) )
+ { debug0(DSA, D, "] AdjustSize returning at HCOVER or VCOVER");
+ return;
+ }
+ break;
+
+
+ case SCALE:
+
+ back(x, dim) = b; fwd(x, dim) = f;
+ if( dim == COLM )
+ { b *= bc(constraint(y)) / SF;
+ f *= bc(constraint(y)) / SF;
+ }
+ else
+ { b *= fc(constraint(y)) / SF;
+ f *= fc(constraint(y)) / SF;
+ }
+ break;
+
+
+ case ROTATE:
+
+ back(x, dim) = b; fwd(x, dim) = f;
+ RotateSize(&cby, &cfy, &rby, &rfy, x, sparec(constraint(y)));
+ if( cby != back(y, COLM) || cfy != fwd(y, COLM) )
+ AdjustSize(y, cby, cfy, COLM);
+ if( rby != back(y, ROWM) || rfy != fwd(y, ROWM) )
+ AdjustSize(y, rby, rfy, ROWM);
+ debug1(DSA, D, "] AdjustSize returning at %s.", Image(type(y)));
+ return;
+
+
+ case WIDE:
+ case HIGH:
+
+ if( (type(y) == WIDE) == (dim == COLM) )
+ { if( !FitsConstraint(b, f, constraint(y)) )
+ { Error(16, 2, "size constraint %s,%s,%s broken by %s,%s",
+ WARN, &fpos(y),
+ EchoLength(bc(constraint(y))), EchoLength(bfc(constraint(y))),
+ EchoLength(fc(constraint(y))), EchoLength(b), EchoLength(f));
+ SetConstraint(constraint(y), MAX_FULL_LENGTH, b+f, MAX_FULL_LENGTH);
+ }
+ back(x, dim) = b; fwd(x, dim) = f;
+ EnlargeToConstraint(&b, &f, &constraint(y));
+ }
+ else
+ { back(x, dim) = b;
+ fwd(x, dim) = f;
+ }
+ break;
+
+
+ case HLIMITED:
+ case VLIMITED:
+
+ if( (type(y) == HLIMITED) == (dim == COLM) )
+ {
+ /* ***
+ Parent(z, UpDim(y, dim));
+ if( type(z) == ROW_THR || type(z) == COL_THR )
+ {
+ SetConstraint(constraint(y), back(z,dim), size(z,dim), fwd(z,dim));
+ }
+ else
+ {
+ SetConstraint(constraint(y), back(y,dim), size(y,dim), fwd(y,dim));
+ }
+ if( !FitsConstraint(b, f, constraint(y)) )
+ { Error(16, 3, "%s of size %s,%s broken by %s,%s",
+ WARN, &fpos(y), Image(type(y)),
+ EchoLength(back(y, dim)), EchoLength(fwd(y, dim)),
+ EchoLength(b), EchoLength(f));
+ }
+ *** */
+ back(x, dim) = b; fwd(x, dim) = f;
+ }
+ else
+ { back(x, dim) = b;
+ fwd(x, dim) = f;
+ }
+ break;
+
+
+ case HSHIFT:
+ case VSHIFT:
+
+ back(x, dim) = b; fwd(x, dim) = f;
+ if( (type(y) == HSHIFT) == (dim == COLM) )
+ { tf = FindShift(y, x, dim);
+ b = find_min(MAX_FULL_LENGTH, find_max(0, b + tf));
+ f = find_min(MAX_FULL_LENGTH, find_max(0, f - tf));
+ }
+ break;
+
+
+ case COL_THR:
+ case ROW_THR:
+
+ assert( (type(y)==COL_THR) == (dim==COLM), "AdjustSize: COL_THR!" );
+ back(x, dim) = b; fwd(x, dim) = f;
+ b = find_max(b, back(y, dim));
+ f = find_max(f, fwd(y, dim));
+ break;
+
+
+ case VCAT:
+ case HCAT:
+ case ACAT:
+
+ if( (type(y) == VCAT) == (dim == ROWM) )
+ CatAdjustSize(x, &b, &f, ratm, y, dim);
+ else
+ {
+ /* let lp and rp be the gaps bracketing the components joined to x */
+ for( lp = PrevDown(link); lp != y; lp = PrevDown(lp) )
+ { Child(z, lp);
+ if( type(z) == GAP_OBJ && !join(gap(z)) ) break;
+ }
+ for( rp = NextDown(link); rp != y; rp = NextDown(rp) )
+ { Child(z, rp);
+ if( type(z) == GAP_OBJ && !join(gap(z)) ) break;
+ }
+
+ back(x, dim) = b; fwd(x, dim) = f;
+ if( lp == y && rp == y )
+ {
+ /* if whole object is joined, do this */
+ b = find_max(b, back(y, dim));
+ f = find_max(f, fwd(y, dim));
+ }
+ else
+ { /* if // or || is present, do this */
+ tb = tf = 0;
+ for( link = NextDown(lp); link != rp; link = NextDown(link) )
+ { Child(z, link);
+ if( type(z) == GAP_OBJ || is_index(type(z)) ) continue;
+ tb = find_max(tb, back(z, dim));
+ tf = find_max(tf, fwd(z, dim));
+ }
+ b = 0; f = find_max(tb + tf, fwd(y, dim));
+ }
+ }
+ break;
+
+
+ case START_HVSPAN:
+
+ Error(16, 4, "size adjustment of %s not implemented",
+ WARN, &fpos(y), Image(type(y)));
+ break;
+
+
+ case START_VSPAN:
+ case VSPAN:
+
+ if( dim == COLM )
+ {
+ back(x, dim) = b; fwd(x, dim) = f;
+ }
+ else Error(16, 4, "size adjustment of %s not implemented",
+ WARN, &fpos(y), Image(type(y)));
+ break;
+
+
+ case START_HSPAN:
+ case HSPAN:
+
+ if( dim == ROWM )
+ {
+ back(x, dim) = b; fwd(x, dim) = f;
+ }
+ else Error(16, 4, "size adjustment of %s not implemented",
+ WARN, &fpos(y), Image(type(y)));
+ break;
+
+
+ case HSPANNER:
+ case VSPANNER:
+
+ assert( (dim == COLM) == (type(y) == HSPANNER), "AdjustSize: span");
+ back(x, dim) = b; fwd(x, dim) = f;
+ debug5(DSC, D, " adjusting %s from (%s,%s) to (%s,%s)",
+ Image(type(y)), EchoLength(back(y, dim)), EchoLength(fwd(y, dim)),
+ EchoLength(b), EchoLength(f));
+ back(y, dim) = b; fwd(y, dim) = f;
+ debug1(DSA, D, "] AdjustSize returning at %s", Image(type(y)));
+ return;
+ break;
+
+
+ case WORD:
+ case QWORD:
+ case CLOSURE:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case CROSS:
+ case FORCE_CROSS:
+ default:
+
+ assert1(FALSE, "AdjustSize:", Image(type(y)));
+ break;
+
+
+ } /* end switch */
+ x = y;
+ } /* end while */
+ debug0(DSA, D, "] AdjustSize returning.");
+ } /* end AdjustSize */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z17.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z17.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z17.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,407 ----
+ /*@z17.c:Gap Widths:GetGap()@*************************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z17.c */
+ /* MODULE: Gap Widths */
+ /* EXTERNS: GetGap(), MinGap(), ExtraGap(), ActualGap(), EchoGap() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* GetGap(x, style, res_gap, res_inc) */
+ /* */
+ /* Object x is expected to be a WORD or QWORD containing a gap: */
+ /* */
+ /* <gap> ::= [ <increment> ] <width> [ <mode> ] [ <nobreak> ] */
+ /* ::= */
+ /* */
+ /* <nobreak> ::= u */
+ /* <increment> ::= + | - */
+ /* <width> ::= <unsigned number> <units> */
+ /* <units> ::= c | i | p | m | f | s */
+ /* ::= v | w | b | r | d | y | z */
+ /* <mode> ::= e | h | x | o | k | t | n */
+ /* */
+ /* Set *res_gap to the gap in the strings of x; *res_inc is the increment. */
+ /* The gap is calculated using the given style. */
+ /* If the gap is empty, this is a synonym for 0ie. */
+ /* If there is an error, GetGap prints a message and returns 0ie. */
+ /* */
+ /*****************************************************************************/
+ #define setwidths(x, y) w = x; units(*res_gap) = y; break;
+
+ void GetGap(OBJECT x, STYLE *style, GAP *res_gap, unsigned *res_inc)
+ { int w; float num;
+ FULL_CHAR *str;
+
+ debug2(DGW, D, "GetGap( %s, %s, res_gap, res_inc )",
+ EchoObject(x), EchoStyle(style));
+
+ nobreak(*res_gap) = FALSE;
+ width(*res_gap) = 0; units(*res_gap) = FIXED_UNIT;
+ mode(*res_gap) = EDGE_MODE; *res_inc = GAP_ABS;
+
+ /* make sure we have a WORD or QWORD argument */
+ if( !is_word(type(x)) )
+ { Error(17, 1, "gap is not a simple word", WARN, &fpos(x));
+ debug1(DGW, D, "GetGap failing (x = %s)", EchoObject(x));
+ return;
+ }
+ str = string(x);
+
+ /* if word is empty, return 0ie */
+ if( *str == '\0' )
+ { debug0(DGW, D, "GetGap returning (null word)");
+ return;
+ }
+
+ /* read the optional gap increment */
+ if( *str == CH_INCGAP ) *res_inc = GAP_INC, str++;
+ else if( *str == CH_DECGAP ) *res_inc = GAP_DEC, str++;
+
+ /* read the gap width */
+ if( sscanf((char *) str, "%f", &num) != 1 )
+ { Error(17, 2, "width missing from %s", WARN, &fpos(x), string(x));
+ Error(17, 3, "%s, %s and %s must be enclosed in double quotes",
+ WARN, &fpos(x), KW_VCAT_NJ, KW_HCAT_NJ, KW_ACAT_NJ);
+ debug0(DGW, D, "GetGap failing (width missing)");
+ return;
+ }
+ while( numericchar(*str) ) str++;
+
+ /* read the compulsory units, calculate length, and check reasonableness */
+ switch( *str++ )
+ {
+ case CH_UNIT_CM: setwidths( num*CM, FIXED_UNIT );
+ case CH_UNIT_IN: setwidths( num*IN, FIXED_UNIT );
+ case CH_UNIT_PT: setwidths( num*PT, FIXED_UNIT );
+ case CH_UNIT_EM: setwidths( num*EM, FIXED_UNIT );
+ case CH_UNIT_FT: setwidths( num*FontSize(font(*style), x), FIXED_UNIT );
+ case CH_UNIT_SP: setwidths( num*width(space_gap(*style)), FIXED_UNIT );
+ case CH_UNIT_VS: setwidths( num*width(line_gap(*style)), FIXED_UNIT );
+ case CH_UNIT_YU: setwidths( num*yunit(*style), FIXED_UNIT );
+ case CH_UNIT_ZU: setwidths( num*zunit(*style), FIXED_UNIT );
+ case CH_UNIT_WD: setwidths( num*FR, NEXT_UNIT );
+ case CH_UNIT_BD: setwidths( num*FR, FRAME_UNIT );
+ case CH_UNIT_RL: setwidths( num*FR, AVAIL_UNIT );
+
+ case CH_UNIT_DG: if( *res_inc == GAP_DEC ) num = - num;
+ *res_inc = GAP_ABS;
+ while( num > 180.0 ) num -= 360.0;
+ while( num < -180.0 ) num += 360.0;
+ assert((num>=-180.0) && (num<=180.0), "GetGap: dg!");
+ setwidths( num*DG, DEG_UNIT );
+
+ default: Error(17, 4, "units letter missing from %s",
+ WARN, &fpos(x), string(x));
+ debug0(DGW, D, "GetGap failing (units letter missing)");
+ return;
+ }
+
+ if( units(*res_gap) == AVAIL_UNIT && w > FR )
+ { Error(17, 5, "%.1fr too large (1.0r substituted)", WARN, &fpos(x), num);
+ w = FR;
+ }
+ width(*res_gap) = w;
+
+ /* read the optional gap mode */
+ switch( *str )
+ {
+ case CH_NOBREAK:
+ case '\0': mode(*res_gap) = EDGE_MODE; break;
+ case CH_MODE_EDGE: mode(*res_gap) = EDGE_MODE; str++; break;
+ case CH_MODE_HYPH: mode(*res_gap) = HYPH_MODE; str++; break;
+ case CH_MODE_MARK: mode(*res_gap) = MARK_MODE; str++; break;
+ case CH_MODE_OVER: mode(*res_gap) = OVER_MODE; str++; break;
+ case CH_MODE_KERN: mode(*res_gap) = KERN_MODE; str++; break;
+ case CH_MODE_TABL: mode(*res_gap) = TAB_MODE; str++; break;
+
+ default: Error(17, 7, "unknown gap mode in %s",
+ WARN, &fpos(x), string(x));
+ debug0(DGW, D, "GetGap failing (spacing mode)");
+ return;
+ }
+
+ /* read the optional nobreak */
+ if( *str == CH_NOBREAK )
+ {
+ if( mode(*res_gap) == HYPH_MODE )
+ Error(17, 9, "replacing self-contradictory gap %s by breakable version",
+ WARN, &fpos(x), string(x));
+ else nobreak(*res_gap) = TRUE;
+ str++;
+ }
+
+ /* if string has not terminated, error */
+ if( *str != '\0' )
+ Error(17, 8, "invalid width or gap %s", WARN, &fpos(x), string(x));
+
+ debug2(DGW, D, "GetGap returning (res_gap = %s, res_inc = %s)",
+ EchoGap(res_gap), Image( (int) *res_inc) );
+ } /* end GetGap */
+
+
+ /*@::MinGap()@****************************************************************/
+ /* */
+ /* FULL_LENGTH MinGap(a, b, c, xgap) */
+ /* */
+ /* Returns the minimum possible separation between the marks of two */
+ /* objects with the given intervening gap. */
+ /* The first object has fwd value a, the second has back value b and fwd c. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_LENGTH MinGap(FULL_LENGTH a, FULL_LENGTH b, FULL_LENGTH c, GAP *xgap)
+ { FULL_LENGTH res; int w;
+ switch( units(*xgap) )
+ {
+ case FIXED_UNIT: w = width(*xgap);
+ break;
+
+ case FRAME_UNIT: w = 0;
+ break;
+
+ case AVAIL_UNIT: w = 0;
+ break;
+
+ case NEXT_UNIT: w = width(*xgap) * (b + c) / FR;
+ break;
+
+ default: assert(FALSE, "MinGap: units");
+ break;
+ }
+ switch( mode(*xgap) )
+ {
+ case NO_MODE: assert(FALSE, "MinGap: NO_MODE");
+ res = 0;
+ break;
+
+ case ADD_HYPH:
+ case HYPH_MODE:
+ case EDGE_MODE: res = find_min(MAX_FULL_LENGTH, a + w + b);
+ break;
+
+ case MARK_MODE: if( BackEnd->fractional_spacing_avail )
+ res = find_max(w, a + b + (FULL_LENGTH) (0.1 * w) );
+ else
+ res = find_max(w, a + b);
+ break;
+
+ case OVER_MODE: res = w;
+ break;
+
+ case KERN_MODE: res = find_max(find_max(a, b), w);
+ break;
+
+ case TAB_MODE: res = a + b;
+ break;
+
+ default: assert(FALSE, "MinGap: mode");
+ res = 0;
+ break;
+
+ }
+ debug5(DGW, DD, "MinGap( _,%s %s %s,%s ) = %s", EchoLength(a),
+ EchoGap(xgap), EchoLength(b), EchoLength(c), EchoLength(res) );
+ return res;
+ } /* end MinGap */
+
+
+ /*@::ExtraGap()@**************************************************************/
+ /* */
+ /* FULL_LENGTH ExtraGap(a, b, xgap, dir) */
+ /* */
+ /* Consider two objects, the first with forward length a, the second with */
+ /* back length b. The objects are separated by the given gap. */
+ /* If dir == FWD, ExtraGap returns the maximum amount that a could be */
+ /* increased without increasing MinGap(a, b, c, xgap). */
+ /* If dir == BACK, similarly for b. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_LENGTH ExtraGap(FULL_LENGTH a, FULL_LENGTH b, GAP *xgap, int dir)
+ { FULL_LENGTH tmp, res;
+ FULL_LENGTH w = units(*xgap) == FIXED_UNIT ? width(*xgap) : 0;
+ switch( mode(*xgap) )
+ {
+ case NO_MODE: assert(FALSE, "ExtraGap: NO_MODE");
+ res = 0;
+ break;
+
+ case ADD_HYPH:
+ case HYPH_MODE:
+ case EDGE_MODE: res = 0;
+ break;
+
+ case MARK_MODE: if( BackEnd->fractional_spacing_avail )
+ res = find_max(0, (FULL_LENGTH) (0.9 * w) - a - b);
+ else
+ res = find_max(0, w - a - b);
+ break;
+
+ case OVER_MODE: res = MAX_FULL_LENGTH;
+ break;
+
+ case KERN_MODE: tmp = find_max(a, find_max(b, w));
+ res = dir == BACK ? tmp - b : tmp - a;
+ break;
+
+ case TAB_MODE: res = 0;
+ break;
+
+ default: assert(FALSE, "ExtraGap: mode");
+ res = 0;
+ break;
+
+ }
+ debug5(DGW, DD, "ExtraGap( %s, %s, %s, %s ) = %s", EchoLength(a),
+ EchoLength(b), EchoGap(xgap), Image(dir), EchoLength(res));
+ return res;
+ } /* end ExtraGap */
+
+
+ /*@::ActualGap()@*************************************************************/
+ /* */
+ /* FULL_LENGTH ActualGap(prevf, b, f, xgap, frame_size, mk) */
+ /* */
+ /* Returns the actual separation between the marks of an object of size */
+ /* (?, prevf) and an object of size (b, f) separated by gap *xgap in a */
+ /* frame of size frame_size; the first object lies at mk in the frame, */
+ /* where 0 <= mk <= frame_size. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_LENGTH ActualGap(FULL_LENGTH prevf, FULL_LENGTH b, FULL_LENGTH f,
+ GAP *xgap, FULL_LENGTH frame_size, FULL_LENGTH mk)
+ { FULL_LENGTH res; int w, w2;
+ switch( units(*xgap) )
+ {
+ case FIXED_UNIT: w = width(*xgap);
+ break;
+
+ case FRAME_UNIT: if( width(*xgap) > FR )
+ w = MAX_FULL_LENGTH;
+ else
+ w = (width(*xgap) * frame_size) / FR;
+ break;
+
+ case AVAIL_UNIT: w = (width(*xgap) * (frame_size - b - f)) / FR;
+ w = find_max(w, 0);
+ break;
+
+ case NEXT_UNIT: w = width(*xgap) * (b + f) / FR;
+ break;
+
+ default: assert(FALSE, "ActualGap: units");
+ break;
+ }
+ switch( mode(*xgap) )
+ {
+ case NO_MODE: Error(17, 10, "cannot continue after previous error(s)", FATAL, no_fpos);
+ assert(FALSE, "ActualGap: NO_MODE");
+ w2 = 0;
+ break;
+
+ case ADD_HYPH:
+ case HYPH_MODE:
+ case EDGE_MODE: w2 = prevf + w + b;
+ break;
+
+ case MARK_MODE: if( BackEnd->fractional_spacing_avail )
+ w2 = find_max(w, prevf + b + (FULL_LENGTH) (0.1 * w) );
+ else
+ w2 = find_max(w, prevf + b);
+ break;
+
+ case OVER_MODE: w2 = w;
+ break;
+
+ case KERN_MODE: w2 = find_max( find_max(prevf, b), w);
+ break;
+
+ case TAB_MODE: w2 = w + b - mk;
+ w2 = find_max(w2, prevf + b );
+ break;
+
+ default: assert(FALSE, "ActualGap: mode");
+ w2 = 0;
+ break;
+ }
+ res = find_min(MAX_FULL_LENGTH, w2);
+ debug7(DGW, DD, "ActualGap( _,%s %s %s,%s; frame_size %s, mk %s ) = %s",
+ EchoLength(prevf), EchoGap(xgap), EchoLength(b), EchoLength(f),
+ EchoLength(frame_size), EchoLength(mk), EchoLength(res));
+ return res;
+ } /* end ActualGap */
+
+
+ /*@::EchoGap()@***************************************************************/
+ /* */
+ /* FULL_CHAR *EchoGap(xgap) */
+ /* */
+ /* Returns a static string showing the indicated xgap. */
+ /* */
+ /*****************************************************************************/
+ #if DEBUG_ON
+
+ FULL_CHAR *EchoGap(GAP *xgap)
+ { char *letter = "?ehxoktH"; char c; FULL_CHAR *res;
+ char *u;
+ static int i = 0;
+ static char buff[3][20];
+ c = mode(*xgap) <= 7 ? letter[mode(*xgap)] : '?';
+ c = letter[mode(*xgap)];
+ u = nobreak(*xgap) ? "u" : "";
+ switch( units(*xgap) )
+ {
+ case 0: sprintf(buff[i], "(none)%c", c);
+ break;
+
+ case FIXED_UNIT: sprintf(buff[i], "%.1fc%c%s", (float) width(*xgap)/CM, c,u);
+ break;
+
+ case NEXT_UNIT: sprintf(buff[i], "%.1fw%c%s", (float) width(*xgap)/FR, c,u);
+ break;
+
+ case FRAME_UNIT: sprintf(buff[i], "%.1fb%c%s", (float) width(*xgap)/FR, c,u);
+ break;
+
+ case AVAIL_UNIT: sprintf(buff[i], "%.1fr%c%s", (float) width(*xgap)/FR, c,u);
+ break;
+
+ case DEG_UNIT: sprintf(buff[i], "%.1fd", (float) width(*xgap) / DG);
+ break;
+
+ default: assert(FALSE, "EchoGap: units");
+ break;
+
+ }
+ res = AsciiToFull(buff[i]);
+ i = (i + 1) % 3;
+ return res;
+ } /* end EchoGap */
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z18.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z18.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z18.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,504 ----
+ /*@z18.c:Galley Transfer:Declarations@****************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z18.c */
+ /* MODULE: Galley Transfer */
+ /* EXTERNS: TransferInit(), TransferBegin(), TransferComponent(), */
+ /* TransferEnd(), TransferClose() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ #define MAX_DEPTH 30 /* max depth of galleys */
+ static OBJECT root_galley = nilobj; /* the root galley */
+ static OBJECT targets[MAX_DEPTH]; /* currently open \Inputs */
+ static CONSTRAINT constraints[MAX_DEPTH]; /* their COLM constraints */
+ static int itop; /* stack top */
+ static CONSTRAINT initial_constraint; /* initial COLM constraint */
+ STYLE InitialStyle; /* initial style */
+ OBJECT InitialEnvironment; /* initial environment */
+
+ #if DEBUG_ON
+ static void debug_targets(void)
+ { int i; OBJECT tmp;
+ for( i = 0; i <= itop; i++ )
+ { if( targets[i] == nilobj || Down(targets[i]) == targets[i] ) tmp = nilobj;
+ else Child(tmp, Down(targets[i]));
+ debug3(DGT, D, " target[%d] %s = %s", i,
+ EchoConstraint(&constraints[i]), EchoObject(tmp));
+ }
+ } /* end debug_targets */
+ #endif
+
+
+ /*@::TransferInit()@**********************************************************/
+ /* */
+ /* TransferInit(InitEnv) */
+ /* */
+ /* Initialise this module. The initial environment is InitEnv. */
+ /* */
+ /*****************************************************************************/
+
+ void TransferInit(OBJECT InitEnv)
+ { OBJECT dest, x, y, recs, inners, nothing, dest_index, up_hd, why;
+ debug1(DGT, D, "[ TransferInit( %s )", EchoObject(InitEnv));
+ SetConstraint(initial_constraint,
+ MAX_FULL_LENGTH-1, MAX_FULL_LENGTH-1, MAX_FULL_LENGTH-1);
+
+ /* set initial environment and style */
+ InitialEnvironment = InitEnv;
+ SetGap(line_gap(InitialStyle), FALSE,FALSE,FALSE,FIXED_UNIT,MARK_MODE,18*PT);
+ vadjust(InitialStyle) = FALSE;
+ hadjust(InitialStyle) = FALSE;
+ padjust(InitialStyle) = FALSE;
+ space_style(InitialStyle) = SPACE_LOUT;
+ SetGap(space_gap(InitialStyle), FALSE,FALSE,TRUE,FIXED_UNIT,EDGE_MODE,1*EM);
+ hyph_style(InitialStyle) = HYPH_UNDEF;
+ fill_style(InitialStyle) = FILL_UNDEF;
+ display_style(InitialStyle) = DISPLAY_UNDEF;
+ small_caps(InitialStyle) = SMALL_CAPS_OFF;
+ font(InitialStyle) = 0; /* i.e. undefined */
+ colour(InitialStyle) = 0; /* i.e. undefined */
+ outline(InitialStyle) = FALSE; /* i.e. not outlined */
+ language(InitialStyle) = 0; /* i.e. undefined */
+ yunit(InitialStyle) = 0; /* i.e. zero */
+ zunit(InitialStyle) = 0; /* i.e. zero */
+ nobreakfirst(InitialStyle) = FALSE;
+ nobreaklast(InitialStyle) = FALSE;
+
+ /* construct destination for root galley */
+ New(up_hd, HEAD);
+ force_gall(up_hd) = FALSE;
+ actual(up_hd) = enclose_obj(up_hd) = limiter(up_hd) = nilobj;
+ headers(up_hd) = dead_headers(up_hd) = nilobj;
+ opt_components(up_hd) = opt_constraints(up_hd) = nilobj;
+ gall_dir(up_hd) = ROWM;
+ New(dest_index, RECEIVING);
+ New(dest, CLOSURE); actual(dest) = PrintSym;
+ actual(dest_index) = dest;
+ debug2(DGT, D, "TransferInit setting external_ver(%s %s) = TRUE",
+ Image(type(dest)), SymName(actual(dest)));
+ external_ver(dest) = TRUE;
+ external_hor(dest) = FALSE;
+ threaded(dest) = FALSE;
+ blocked(dest_index) = FALSE;
+ Link(up_hd, dest_index);
+
+ /* construct root galley */
+ New(root_galley, HEAD);
+ force_gall(root_galley) = FALSE;
+ enclose_obj(root_galley) = limiter(root_galley) = nilobj;
+ headers(root_galley) = dead_headers(root_galley) = nilobj;
+ opt_components(root_galley) = opt_constraints(root_galley) = nilobj;
+ gall_dir(root_galley) = ROWM;
+ FposCopy(fpos(root_galley), *no_fpos);
+ actual(root_galley) = whereto(root_galley) = nilobj;
+ ready_galls(root_galley) = nilobj;
+ must_expand(root_galley) = sized(root_galley) =FALSE;
+ foll_or_prec(root_galley) = GALL_FOLL;
+ New(x, CLOSURE); actual(x) = InputSym;
+ Link(root_galley, x);
+ SizeGalley(root_galley, InitEnv, TRUE, FALSE, FALSE, FALSE, &InitialStyle,
+ &initial_constraint, nilobj, ¬hing, &recs, &inners, nilobj);
+ assert( recs == nilobj , "TransferInit: recs != nilobj!" );
+ assert( inners == nilobj , "TransferInit: inners != nilobj!" );
+ Link(dest_index, root_galley);
+
+ /* initialise target and constraint stacks */
+ Child(y, Down(root_galley));
+ assert( type(y) == RECEPTIVE && type(actual(y)) == CLOSURE &&
+ actual(actual(y)) == InputSym, "TransferInit: initial galley!" );
+ assert( external_ver(actual(y)), "TransferInit: input sym not external!" );
+ blocked(y) = TRUE;
+ itop = 0;
+ New(targets[itop], ACAT);
+ Link(targets[itop], y);
+ Constrained(actual(y), &constraints[itop], COLM, &why);
+ debug2(DSC, DD, "Constrained( %s, COLM ) = %s",
+ EchoObject(y), EchoConstraint(&constraints[itop]));
+
+ debug0(DGT, D, "] TransferInit returning.");
+ ifdebug(DGT, DD, debug_targets());
+ } /* end TransferInit */
+
+
+ /*@::TransferBegin()@*********************************************************/
+ /* */
+ /* OBJECT TransferBegin(x) */
+ /* */
+ /* Commence the transfer of a new galley whose header is invocation x. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT TransferBegin(OBJECT x)
+ { OBJECT xsym, index, y, link, env, new_env, hold_env, res, hd, target, why;
+ CONSTRAINT c;
+ debug1(DGT, D, "[ [ TransferBegin( %s )", EchoObject(x));
+ ifdebug(DGT, DD, debug_targets());
+ assert( type(x) == CLOSURE, "TransferBegin: non-CLOSURE!" );
+
+ /* add an automatically generated @Tag parameter to x if required */
+ if( has_tag(actual(x)) ) CrossAddTag(x);
+
+ /* construct new (inner) env chain */
+ if( Down(targets[itop]) == targets[itop] )
+ Error(18, 1, "cannot attach galley %s", FATAL,&fpos(x),SymName(actual(x)));
+ Child(target, Down(targets[itop]));
+ xsym = actual(x);
+ env = GetEnv(actual(target));
+ debug1(DGT, DD, " current env chain: %s", EchoObject(env));
+ if( has_body(xsym) )
+ {
+ /* prepare a copy of x for inclusion in environment */
+ y = CopyObject(x, no_fpos);
+
+ /* attach its environment */
+ AttachEnv(env, y);
+
+ /* now the new environment is y catenated with the old one */
+ debug0(DCR, DDD, "calling SetEnv from TransferBegin (a)");
+ new_env = SetEnv(y, nilobj);
+ }
+ else new_env = env;
+ New(hold_env, ACAT); Link(hold_env, new_env);
+ debug1(DGT, DD, " new env chain: %s", EchoObject(new_env));
+
+ /* convert x into an unsized galley called hd */
+ New(index, UNATTACHED);
+ pinpoint(index) = nilobj;
+ New(hd, HEAD);
+ FposCopy(fpos(hd), fpos(x));
+ actual(hd) = xsym;
+ limiter(hd) = opt_components(hd) = opt_constraints(hd) = nilobj;
+ gall_dir(hd) = ROWM;
+ ready_galls(hd) = nilobj;
+ must_expand(hd) = TRUE;
+ sized(hd) = FALSE;
+ Link(index, hd);
+ Link(hd, x);
+ AttachEnv(env, x);
+ SetTarget(hd);
+ enclose_obj(hd) = (has_enclose(actual(hd)) ? BuildEnclose(hd) : nilobj);
+ headers(hd) = dead_headers(hd) = nilobj;
+
+ /* search for destination for hd and release it */
+ Link(Up(target), index);
+ debug0(DGF,D, "");
+ debug1(DGF,D, " calling FlushGalley(%s) from TransferBegin, root_galley =",
+ SymName(actual(hd)));
+ ifdebug(DGF, D, DebugGalley(root_galley, nilobj, 4));
+ if( whereto(hd) == nilobj || !uses_extern_target(whereto(hd)) ) /* &&& */
+ FlushGalley(hd);
+
+ /* if failed to flush, undo everything and exit */
+ Parent(index, Up(hd));
+ if( type(index) == UNATTACHED && !sized(hd) )
+ { DeleteNode(index);
+ DisposeObject(hold_env);
+ if( LastDown(x) != x )
+ { Child(env, LastDown(x));
+ if( type(env) == ENV ) DisposeChild(LastDown(x));
+ }
+ debug1(DGT,D, "] TransferBegin returning failed, x: %s", EchoObject(x));
+ return x;
+ }
+
+ if( has_rpar(actual(hd)) )
+ {
+ /* set up new target to be inner \InputSym, or nilobj if none */
+ if( ++itop >= MAX_DEPTH )
+ Error(18, 2, "galley nested too deeply (max is %d)",
+ FATAL, &fpos(x), MAX_DEPTH);
+ New(targets[itop], ACAT); target = nilobj;
+ for( link = Down(hd); link != hd; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == RECEPTIVE && actual(actual(y)) == InputSym )
+ {
+ Constrained(actual(y), &constraints[itop], COLM, &why);
+ if( FitsConstraint(0, 0, constraints[itop]) )
+ { Link(targets[itop], y); target = y;
+ debug2(DSC, DD, "Constrained( %s, COLM ) = %s",
+ EchoObject(y), EchoConstraint(&constraints[itop]));
+ env = DetachEnv(actual(y));
+ AttachEnv(new_env, actual(y));
+ }
+ else
+ { Error(18, 3, "galley %s deleted (insufficient width at target)",
+ WARN, &fpos(hd), SymName(actual(hd)));
+ }
+ break;
+ }
+ }
+
+ /* return a token appropriate to the new target */
+ if( target == nilobj || external_ver(actual(target)) )
+ res = NewToken(GSTUB_EXT, no_fpos, 0, 0, precedence(xsym), nilobj);
+ else
+ { Constrained(actual(target), &c, ROWM, &why);
+ if( constrained(c) )
+ Error(18, 4, "right parameter of %s is vertically constrained",
+ FATAL, &fpos(target), SymName(xsym));
+ else res = NewToken(GSTUB_INT, no_fpos, 0, 0, precedence(xsym), nilobj);
+ }
+ debug1(DGT, D, "] TransferBegin returning %s", Image(type(res)));
+ }
+ else
+ {
+ res = NewToken(GSTUB_NONE, no_fpos, 0, 0, precedence(xsym), nilobj);
+ debug1(DGT, D, "] TransferBegin returning %s", Image(type(res)));
+ }
+
+ DisposeObject(hold_env);
+ ifdebug(DGT, DD, debug_targets());
+ return res;
+ } /* end TransferBegin */
+
+ /*@::TransferComponent()@*****************************************************/
+ /* */
+ /* TransferComponent(x) */
+ /* */
+ /* Transfer component x of a galley. */
+ /* */
+ /*****************************************************************************/
+
+ void TransferComponent(OBJECT x)
+ { OBJECT y, env, start_search, recs, inners, nothing, hd, dest, dest_index;
+ debug1(DGT, D, "[ TransferComponent( %s )", EchoObject(x));
+ ifdebug(DGT, DD, debug_targets());
+
+ /* if no dest_index, discard x and exit */
+ if( Down(targets[itop]) == targets[itop] )
+ { DisposeObject(x);
+ debug0(DGT, D, "] TransferComponent returning (no target).");
+ return;
+ }
+ Child(dest_index, Down(targets[itop]));
+ assert( external_ver(actual(dest_index)), "TransferComponent: internal!" );
+
+ /* make the component into a galley */
+ New(hd, HEAD);
+ force_gall(hd) = FALSE;
+ enclose_obj(hd) = limiter(hd) = headers(hd) = dead_headers(hd) = nilobj;
+ opt_components(hd) = opt_constraints(hd) = nilobj;
+ gall_dir(hd) = ROWM;
+ FposCopy(fpos(hd), fpos(x));
+ actual(hd) = whereto(hd) = ready_galls(hd) = nilobj;
+ foll_or_prec(hd) = GALL_FOLL;
+ must_expand(hd) = sized(hd) = FALSE;
+ Link(hd, x);
+ dest = actual(dest_index);
+ env = GetEnv(dest);
+ debug1(DGT, DD, " current env chain: %s", EchoObject(env));
+ SizeGalley(hd, env, TRUE, threaded(dest), FALSE, TRUE, &save_style(dest),
+ &constraints[itop], nilobj, ¬hing, &recs, &inners, nilobj);
+ if( recs != nilobj ) ExpandRecursives(recs);
+ debug3(DSA, D, "after SizeGalley, hd width is (%s,%s), constraint was %s",
+ EchoLength(back(hd, COLM)), EchoLength(fwd(hd, COLM)),
+ EchoConstraint(&constraints[itop]));
+
+ /* promote the components, remembering where old spot was */
+ start_search = PrevDown(Up(dest_index));
+ debug1(DSA, D, " calling AdjustSize from TransferComponent %s",
+ EchoFilePos(&fpos(hd)));
+ ifdebug(DSA, D,
+ Child(y, Down(hd));
+ while( type(y) == VCAT ) Child(y, Down(y));
+ debug2(DSA, D, " first component is %s at %s",
+ Image(type(y)), EchoFilePos(&fpos(y)));
+ if( NextDown(Down(hd)) != hd && NextDown(NextDown(Down(hd))) != hd )
+ { Child(y, NextDown(NextDown(Down(hd))));
+ debug2(DSA, D, " second component is %s at %s",
+ Image(type(y)), EchoFilePos(&fpos(y)));
+ }
+ );
+ AdjustSize(dest, back(hd, COLM), fwd(hd, COLM), COLM);
+ debug0(DGS, D, "calling Promote(hd, hd) from TransferComponent");
+ Promote(hd, hd, dest_index, FALSE);
+ DeleteNode(hd);
+
+ /* flush any widowed galleys attached to \Input */
+ if( Down(dest_index) != dest_index )
+ { OBJECT tinners, index;
+ New(tinners, ACAT);
+ while( Down(dest_index) != dest_index )
+ { Child(y, Down(dest_index));
+ assert( type(y) == HEAD, "TransferComponent: input child!" );
+ if( opt_components(y) != nilobj )
+ { DisposeObject(opt_components(y));
+ opt_components(y) = nilobj;
+ debug1(DOG, D, "TransferComponent de-optimizing %s (@Input case)",
+ SymName(actual(y)));
+ }
+ DetachGalley(y);
+ Parent(index, Up(y));
+ MoveLink(Up(index), NextDown(start_search), PARENT);
+ Link(tinners, index);
+ }
+ debug0(DGF, D, " calling FlushInners() from TransferComponent (a)");
+ FlushInners(tinners, nilobj);
+ }
+
+ /* flush any galleys inside hd */
+ if( inners != nilobj )
+ {
+ debug0(DGF, D, " calling FlushInners() from TransferComponent (b)");
+ FlushInners(inners, nilobj);
+ }
+
+ /* flush parent galley, if needed */
+ if( blocked(dest_index) )
+ { blocked(dest_index) = FALSE;
+ Parent(y, Up(dest_index));
+ debug0(DGF, D, " calling FlushGalley from TransferComponent");
+ FlushGalley(y);
+ }
+
+ debug0(DGT, D, "] TransferComponent returning.");
+ ifdebug(DGT, DD, debug_targets());
+ } /* end TransferComponent */
+
+
+ /*@::TransferEnd()@***********************************************************/
+ /* */
+ /* TransferEnd(x) */
+ /* */
+ /* End the transfer of a galley. */
+ /* */
+ /*****************************************************************************/
+
+ void TransferEnd(OBJECT x)
+ { OBJECT recs, inners, nothing, z, env, dest, hd, dest_index, y, start_search;
+ debug1(DGT, D, "[ TransferEnd( %s )", EchoObject(x));
+ ifdebug(DGT, DD, debug_targets());
+
+ /* if no dest_index, discard x and exit */
+ if( Down(targets[itop]) == targets[itop] )
+ { DisposeObject(x); DisposeObject(targets[itop--]);
+ debug0(DGT, D, "] TransferEnd returning: no dest_index");
+ return;
+ }
+ Child(dest_index, Down(targets[itop]));
+
+ /* make the component into a galley */
+ New(hd, HEAD); FposCopy(fpos(hd), fpos(x));
+ force_gall(hd) = FALSE;
+ enclose_obj(hd) = limiter(hd) = headers(hd) = dead_headers(hd) = nilobj;
+ opt_components(hd) = opt_constraints(hd) = nilobj;
+ gall_dir(hd) = ROWM;
+ actual(hd) = whereto(hd) = ready_galls(hd) = nilobj;
+ foll_or_prec(hd) = GALL_FOLL;
+ must_expand(hd) = sized(hd) = FALSE;
+ Link(hd, x); dest = actual(dest_index); env = GetEnv(dest);
+ debug1(DGT, DD, " current env chain: %s", EchoObject(env));
+ SizeGalley(hd, env, external_ver(dest), threaded(dest), FALSE, TRUE,
+ &save_style(dest), &constraints[itop], nilobj, ¬hing, &recs, &inners,
+ nilobj);
+ if( recs != nilobj ) ExpandRecursives(recs);
+ debug3(DSA, D, "after SizeGalley, hd width is (%s,%s), constraint was %s",
+ EchoLength(back(hd, COLM)), EchoLength(fwd(hd, COLM)),
+ EchoConstraint(&constraints[itop]));
+
+ /* promote the components, remembering where old spot was */
+ start_search = PrevDown(Up(dest_index));
+ debug0(DSA, D, "calling AdjustSize from TransferEnd (a)");
+ AdjustSize(dest, back(hd, COLM), fwd(hd, COLM), COLM);
+ if( !external_ver(dest) )
+ { Child(z, LastDown(hd));
+ debug0(DSA, D, "calling AdjustSize from TransferEnd (b)");
+ AdjustSize(dest, back(z, ROWM), fwd(z, ROWM), ROWM);
+ Interpose(dest, VCAT, hd, z);
+ }
+ debug0(DGS, D, "calling Promote(hd, hd) from TransferEnd");
+ Promote(hd, hd, dest_index, TRUE); DeleteNode(hd);
+
+ /* flush any widowed galleys attached to \Input */
+ if( Down(dest_index) != dest_index )
+ { OBJECT tinners, index;
+ New(tinners, ACAT);
+ while( Down(dest_index) != dest_index )
+ { Child(y, Down(dest_index));
+ assert( type(y) == HEAD, "TransferEnd: input child!" );
+ if( opt_components(y) != nilobj )
+ { DisposeObject(opt_components(y));
+ opt_components(y) = nilobj;
+ debug1(DOG, D, "TransferEnd de-optimizing %s (@Input case)",
+ SymName(actual(y)));
+ }
+ DetachGalley(y);
+ Parent(index, Up(y));
+ MoveLink(Up(index), NextDown(start_search), PARENT);
+ Link(tinners, index);
+ }
+ debug0(DGF, D, " calling FlushInners() from TransferEnd (a)");
+ FlushInners(tinners, nilobj);
+ }
+
+ /* flush any galleys inside hd */
+ if( inners != nilobj )
+ {
+ debug0(DGF, D, " calling FlushInners() from TransferEnd (b)");
+ FlushInners(inners, nilobj);
+ }
+
+ /* close dest_index, and flush parent galley if needed */
+ if( blocked(dest_index) )
+ { Parent(y, Up(dest_index));
+ DeleteNode(dest_index);
+ debug0(DGF, D, " calling FlushGalley from TransferEnd");
+ FlushGalley(y);
+ }
+ else DeleteNode(dest_index);
+
+ /* pop target stack and exit */
+ DisposeObject(targets[itop--]);
+ debug0(DGT, D, "] ] TransferEnd returning.");
+ ifdebug(DGT, DD, debug_targets());
+ } /* end TransferEnd */
+
+ /*@::TransferClose()@*********************************************************/
+ /* */
+ /* TransferClose() */
+ /* */
+ /* Close this module. */
+ /* */
+ /*****************************************************************************/
+
+ void TransferClose(void)
+ { OBJECT inners;
+ debug0(DGT, D, "[ TransferClose()");
+ ifdebug(DGT, DD, debug_targets());
+ debug0(DGA, D, " calling FreeGalley from TransferClose");
+ if( LastDown(root_galley) != root_galley )
+ { inners = nilobj;
+ FreeGalley(root_galley, root_galley, &inners, nilobj, nilobj);
+ if( inners != nilobj )
+ {
+ debug0(DGF, D, " calling FlushInners() from TransferClose");
+ FlushInners(inners, nilobj);
+ }
+ debug0(DGF, D, " calling FlushGalley from TransferClose");
+ FlushGalley(root_galley);
+ }
+ debug0(DGT, D, "] TransferClose returning.");
+ }
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z19.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z19.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z19.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1030 ----
+ /*@z19.c:Galley Attaching:DetachGalley()@*************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z19.c */
+ /* MODULE: Galley Attaching */
+ /* EXTERNS: SearchGalley(), AttachGalley(), DetachGalley() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT InterposeScale(y, scale_factor, dim) */
+ /* */
+ /* Interpose a @Scale symbol above y with the given scale factor. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT InterposeScale(OBJECT y, int scale_factor, int dim)
+ { OBJECT res;
+ New(res, SCALE);
+ FposCopy(fpos(res), fpos(y));
+ if( dim == COLM )
+ { bc(constraint(res)) = scale_factor;
+ fc(constraint(res)) = 1 * SF;
+ }
+ else
+ { bc(constraint(res)) = 1 * SF;
+ fc(constraint(res)) = scale_factor;
+ }
+ back(res, dim) = (back(y, dim) * scale_factor) / SF;
+ fwd(res, dim) = (fwd(y, dim) * scale_factor) / SF;
+ back(res, 1-dim) = back(y, 1-dim);
+ fwd(res, 1-dim) = fwd(y, 1-dim);
+ ReplaceNode(res, y);
+ Link(res, y);
+ return res;
+ } /* end InterposeScale */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT InterposeWideOrHigh(y, dim) */
+ /* */
+ /* Interpose a @Wide or @High symbol above y with the same size as y, with */
+ /* a value which prevents any further increase in the size of y. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT InterposeWideOrHigh(OBJECT y, int dim)
+ { OBJECT res;
+ New(res, dim == COLM ? WIDE : HIGH);
+ FposCopy(fpos(res), fpos(y));
+ back(res, dim) = back(y, dim);
+ fwd(res, dim) = fwd(y, dim);
+ back(res, 1-dim) = back(y, 1-dim);
+ fwd(res, 1-dim) = fwd(y, 1-dim);
+ SetConstraint(constraint(res), MAX_FULL_LENGTH, size(res, dim), MAX_FULL_LENGTH);
+ ReplaceNode(res, y);
+ Link(res, y);
+ return res;
+ } /* end InterposeWideOrHigh */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DetachGalley(hd) */
+ /* */
+ /* Detach galley hd from its target. */
+ /* */
+ /*****************************************************************************/
+
+ void DetachGalley(OBJECT hd)
+ { OBJECT prnt, index;
+ assert( type(hd) == HEAD && Up(hd) != hd, "DetachGalley: precondition!" );
+ debug1(DGA, D, "DetachGalley( %s )", SymName(actual(hd)));
+ Parent(prnt, Up(hd));
+ assert( Up(prnt) != prnt, "DetachGalley: parent!" );
+ New(index, UNATTACHED);
+ pinpoint(index) = nilobj;
+ MoveLink(Up(hd), index, PARENT);
+ Link(NextDown(Up(prnt)), index);
+ debug0(DGA, D, "DetachGalley returning.");
+ } /* end DetachGalley */
+
+
+ /*@::SearchGalley()@**********************************************************/
+ /* */
+ /* OBJECT SearchGalley(start, sym, forwards, subgalleys, closures, input) */
+ /* */
+ /* Search a galley and its sub-galleys for a target which uses sym. The */
+ /* meanings of the flags are as follows: */
+ /* */
+ /* forwards If TRUE, search forwards from just after start, else */
+ /* search backwards from just before start */
+ /* subgalleys If TRUE, search down into sub-galleys of this galley */
+ /* closures If TRUE, closures in this galley are acceptable results */
+ /* input If TRUE, InputSym is an acceptable result */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT SearchGalley(OBJECT start, OBJECT sym, BOOLEAN forwards,
+ BOOLEAN subgalleys, BOOLEAN closures, BOOLEAN input)
+ { OBJECT y, res, z, zlink, link;
+ debug5(DGA, DD, "[ SearchGalley(start, %s, %s, %s, %s, %s)", SymName(sym),
+ forwards ? "fwd" : "back", subgalleys ? "subgalleys" : "nosubgalleys",
+ closures ? "closures" : "noclosures", input ? "input" : "noinput");
+ assert( type(start) == LINK || type(start) == HEAD, "SearchGalley: start!" );
+
+ link = forwards ? NextDown(start) : PrevDown(start);
+ res = nilobj;
+ while( res == nilobj && type(link) != HEAD )
+ { Child(y, link);
+ switch( type(y) )
+ {
+ case UNATTACHED:
+ case RECEIVING:
+
+ debug1(DGA, DD, " examining %s", EchoIndex(y));
+ if( subgalleys )
+ for( zlink = Down(y); zlink!=y && res==nilobj; zlink=NextDown(zlink) )
+ { Child(z, zlink);
+ res = SearchGalley(z, sym, TRUE, TRUE, TRUE, input);
+ }
+ if( res == nilobj && input && type(y) == RECEIVING &&
+ actual(actual(y)) == InputSym )
+ res = y;
+ break;
+
+
+ case RECEPTIVE:
+
+ debug1(DGA, DD, " examining %s", EchoIndex(y));
+ if( closures && type(actual(y)) == CLOSURE
+ && SearchUses(actual(actual(y)), sym) ) res = y;
+ else if( input && actual(actual(y)) == InputSym ) res = y;
+ break;
+
+
+ default:
+
+ break;
+
+ }
+ link = forwards ? NextDown(link) : PrevDown(link);
+ }
+ debug1(DGA, DD, "] SearchGalley returning %s", EchoIndex(res));
+ return res;
+ } /* end SearchGalley */
+
+
+ /*@@**************************************************************************/
+ /* */
+ /* int AttachGalley(hd, inners, suspend_pt) */
+ /* */
+ /* Attach galley hd, which may be unsized, to a destination. This involves */
+ /* searching for a destination forward or back from the attachment point of */
+ /* hd and promoting up to and including the first definite component of hd. */
+ /* */
+ /* Although AttachGalley never flushes any galleys, it may identify some */
+ /* galleys which should be flushed, even if the attach is itself not */
+ /* successful. These are returned in *inners, or nilobj if none. */
+ /* */
+ /* The integer returned by AttachGalley indicates what happened to hd: */
+ /* */
+ /* ATTACH_KILLED The galley was sized to begin with but no target */
+ /* for it could be found. The galley has been killed */
+ /* and that's the end of it. */
+ /* */
+ /* ATTACH_INPUT When searching for a target for the galley we came */
+ /* upon InputSym, suggesting that the target might be */
+ /* still to be read. So the galley has been linked to */
+ /* that InputSym and must now wait. */
+ /* */
+ /* ATTACH_NOTARGET The galley is unsized and no target could be found */
+ /* for it. This is fine, it just means that we can't */
+ /* flush the galley now and we must try again later. */
+ /* */
+ /* ATTACH_SUSPEND The galley is sized and a target was found for it, */
+ /* but the first component of the galley proved to be */
+ /* indefinite so could not be promoted. The galley */
+ /* remains unattached but is moved to just before its */
+ /* target so that it can find it easily later when its */
+ /* first component becomes definite and it is flushed. */
+ /* */
+ /* ATTACH_NULL The galley is sized and a target was found for it, */
+ /* but the body of the galley proved to be null (i.e. */
+ /* there were no definite components to be flushed). */
+ /* This is to be treated just like the normal case */
+ /* following, except that the target is replaced by */
+ /* @Null rather than by its body. */
+ /* */
+ /* ATTACH_ACCEPT The galley is sized and a target was found for it, */
+ /* and one component of the galley has been promoted. */
+ /* */
+ /*****************************************************************************/
+
+ int AttachGalley(OBJECT hd, OBJECT *inners, OBJECT *suspend_pt)
+ { OBJECT hd_index; /* the index of hd in the enclosing galley */
+ OBJECT hd_inners; /* inner galleys of hd, if unsized */
+ OBJECT dest; /* the target @Galley hd empties into */
+ OBJECT dest_index; /* the index of dest */
+ OBJECT target; /* the target indefinite containing dest */
+ OBJECT target_index; /* the index of target */
+ OBJECT target_galley; /* the body of target, made into a galley */
+ OBJECT tg_inners; /* inner galleys of target_galley */
+ BOOLEAN need_precedes; /* true if destination lies before galley */
+ OBJECT recs; /* list of recursive definite objects */
+ OBJECT link, y; /* for scanning through the components of hd */
+ CONSTRAINT c; /* temporary variable holding a constraint */
+ OBJECT env, n1, tmp, zlink, z, sym; /* placeholders and temporaries */
+ BOOLEAN was_sized; /* true if sized(hd) initially */
+ int dim; /* the galley direction */
+ FULL_LENGTH perp_back, perp_fwd;
+ OBJECT why, junk;
+
+ debug2(DGA, D, "[ AttachGalley(Galley %s into %s)",
+ SymName(actual(hd)), SymName(whereto(hd)));
+ ifdebug(DGA, DD, DebugGalley(hd, nilobj, 4));
+ assert( Up(hd) != hd, "AttachGalley: no index!" );
+ Parent(hd_index, Up(hd));
+ assert( type(hd_index) == UNATTACHED, "AttachGalley: not UNATTACHED!" );
+ hd_inners = tg_inners = nilobj;
+ was_sized = sized(hd);
+ dim = gall_dir(hd);
+
+ for(;;)
+ {
+ /*************************************************************************/
+ /* */
+ /* Search for a destination for hd. If hd is unsized, search for */
+ /* inner galleys preceding it first of all, then for receptive objects */
+ /* following it, possibly in inner galleys. If no luck, exit. */
+ /* If hd is sized, search only for receptive objects in the current */
+ /* galley below the current spot, and fail if cannot find any. */
+ /* */
+ /*************************************************************************/
+
+ sym = whereto(hd);
+ if( sized(hd) )
+ {
+ /* sized galley case: search on from current spot */
+ target_index = SearchGalley(Up(hd_index), sym, TRUE, FALSE, TRUE, TRUE);
+ if( target_index == nilobj )
+ {
+ /* search failed to find any new target, so kill the galley */
+ for( link = Down(hd); link != hd; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == SPLIT ) Child(y, DownDim(y, dim));
+ if( is_definite(type(y)) ) break;
+ }
+ if( link != hd )
+ Error(19, 1, "galley %s deleted from here (no target)",
+ WARN, &fpos(y), SymName(actual(hd)));
+ if( hd_inners != nilobj ) DisposeObject(hd_inners), hd_inners=nilobj;
+ if( tg_inners != nilobj ) DisposeObject(tg_inners), tg_inners=nilobj;
+ KillGalley(hd, FALSE);
+ *inners = nilobj;
+ debug0(DGA, D, "] AttachGalley returning ATTACH_KILLED");
+ return ATTACH_KILLED;
+ }
+ else if( actual(actual(target_index)) == InputSym )
+ {
+ /* search found input object, so suspend on that */
+ DeleteNode(hd_index);
+ Link(target_index, hd);
+ *inners = nilobj;
+ debug0(DGA, D, "] AttachGalley returning ATTACH_INPUT");
+ return ATTACH_INPUT;
+ }
+
+ }
+ else /* unsized galley, either backwards or normal */
+ {
+ if( foll_or_prec(hd) == GALL_PREC )
+ { target_index= SearchGalley(Up(hd_index), sym, FALSE, TRUE,TRUE,FALSE);
+ need_precedes = FALSE;
+ }
+ else
+ { target_index = SearchGalley(Up(hd_index), sym, FALSE,TRUE,FALSE,FALSE);
+ need_precedes = (target_index != nilobj);
+ if( target_index == nilobj )
+ target_index = SearchGalley(Up(hd_index), sym, TRUE,TRUE,TRUE,FALSE);
+ }
+
+ /* if no luck, exit without error */
+ if( target_index == nilobj )
+ { *inners = nilobj;
+ debug0(DGA, D, "] AttachGalley returning ATTACH_NOTARGET");
+ return ATTACH_NOTARGET;
+ }
+ }
+ assert( type(target_index) == RECEPTIVE, "AttachGalley: target_index!" );
+ target = actual(target_index);
+ assert( type(target) == CLOSURE, "AttachGalley: target!" );
+
+ /* set target_galley to the expanded value of target */
+ debug1(DYY, D, "[ EnterErrorBlock(FALSE) (expanding target %s)",
+ SymName(actual(target)));
+ EnterErrorBlock(FALSE);
+ New(target_galley, HEAD);
+ force_gall(target_galley) = FALSE;
+ enclose_obj(target_galley) = limiter(target_galley) = nilobj;
+ headers(target_galley) = dead_headers(target_galley) = nilobj;
+ opt_components(target_galley) = opt_constraints(target_galley) = nilobj;
+ gall_dir(target_galley) = external_hor(target) ? COLM : ROWM;
+ FposCopy(fpos(target_galley), fpos(target));
+ actual(target_galley) = actual(target);
+ whereto(target_galley) = ready_galls(target_galley) = nilobj;
+ foll_or_prec(target_galley) = GALL_FOLL;
+ must_expand(target_galley) = FALSE;
+ sized(target_galley) = FALSE;
+
+ /* get perpendicular constraint (none if horizontal galley) */
+ if( dim == ROWM )
+ {
+ Constrained(target, &c, 1-dim, &junk);
+ if( !constrained(c) )
+ Error(19, 2, "receptive symbol %s has unconstrained width",
+ FATAL, &fpos(target), SymName(actual(target)));
+ debug2(DSC, DD, "Constrained( %s, 1-dim ) = %s",
+ EchoObject(target), EchoConstraint(&c));
+ if( !FitsConstraint(0, 0, c) )
+ { debug0(DGA, D, " reject: target_galley horizontal constraint is -1");
+ y = nilobj;
+ goto REJECT;
+ }
+ }
+ else /* actually unused */
+ SetConstraint(c, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+
+ debug1(DGA, DDD, " expanding %s", EchoObject(target));
+ tmp = CopyObject(target, no_fpos);
+ Link(target_galley, tmp);
+ env = DetachEnv(tmp);
+ debug4(DGM, D, " external_ver(%s) = %s, external_hor(%s) = %s",
+ SymName(actual(target)), bool(external_ver(target)),
+ SymName(actual(target)), bool(external_hor(target)));
+ SizeGalley(target_galley, env,
+ external_ver(target) || external_hor(target),
+ threaded(target), non_blocking(target_index),
+ trigger_externs(target_index), &save_style(target),
+ &c, whereto(hd), &dest_index, &recs, &tg_inners,
+ enclose_obj(hd) != nilobj ? CopyObject(enclose_obj(hd), no_fpos):nilobj);
+ debug1(DGA, DD, " SizeGalley tg_inners: %s", DebugInnersNames(tg_inners));
+ if( recs != nilobj ) ExpandRecursives(recs);
+ dest = actual(dest_index);
+ if( underline(dest) == UNDER_UNDEF ) underline(dest) = UNDER_OFF;
+
+ /* verify that hd satisfies any horizontal constraint on dest */
+ if( dim == ROWM )
+ {
+ debug1(DGA, DDD, " checking hor fit of hd in %s",SymName(actual(dest)));
+ Constrained(dest, &c, 1-dim, &junk);
+ debug3(DSC, DD, "Constrained( %s, %s ) = %s",
+ EchoObject(dest), dimen(1-dim), EchoConstraint(&c));
+ assert( constrained(c), "AttachGalley: dest unconstrained!" );
+ if( !FitsConstraint(0, 0, c) )
+ { debug0(DGA, D, " reject: hd horizontal constraint is -1");
+ y = nilobj;
+ goto REJECT;
+ }
+ }
+
+ /* manifest and size the galley if not done yet */
+ if( !sized(hd) )
+ {
+ debug2(DYY, D, "[ EnterErrorBlock(TRUE) (sizing galley %s into %s)",
+ SymName(actual(hd)), SymName(whereto(hd)));
+ EnterErrorBlock(TRUE);
+ n1 = nilobj;
+ Child(y, Down(hd));
+ env = DetachEnv(y);
+ /*** threaded() only defined in ROWM case
+ SizeGalley(hd, env, TRUE, threaded(dest), non_blocking(target_index),
+ TRUE, &save_style(dest), &c, nilobj, &n1, &recs, &hd_inners);
+ *** */
+ SizeGalley(hd, env, TRUE, dim == ROWM ? threaded(dest) : FALSE,
+ non_blocking(target_index), TRUE, &save_style(dest), &c, nilobj,
+ &n1, &recs, &hd_inners, nilobj);
+ debug1(DGA,DD," SizeGalley hd_inners: %s", DebugInnersNames(hd_inners));
+ if( recs != nilobj ) ExpandRecursives(recs);
+ if( need_precedes ) /* need an ordering constraint */
+ { OBJECT index1, index2;
+ New(index1, PRECEDES);
+ New(index2, FOLLOWS);
+ blocked(index2) = FALSE;
+ tmp = MakeWord(WORD, STR_EMPTY, no_fpos);
+ Link(index1, tmp); Link(index2, tmp);
+ Link(Up(hd_index), index1);
+ Link(Down(hd), index2);
+ debug0(DGA, D, " inserting PRECEDES and FOLLOWS");
+ }
+ LeaveErrorBlock(TRUE);
+ debug0(DYY, D, "] LeaveErrorBlock(TRUE) (finished sizing galley)");
+ }
+
+ if( dim == ROWM )
+ { if( !FitsConstraint(back(hd, 1-dim), fwd(hd, 1-dim), c) )
+ { debug3(DGA, D, " reject: hd %s,%s does not fit target_galley %s",
+ EchoLength(back(hd, 1-dim)), EchoLength(fwd(hd, 1-dim)),
+ EchoConstraint(&c));
+ Error(19, 3, "too little horizontal space for galley %s at %s",
+ WARN, &fpos(hd), SymName(actual(hd)), SymName(actual(dest)));
+ goto REJECT;
+ }
+ }
+
+ /* check status of first component of hd */
+ debug0(DGA, DDD, " now ready to attach; hd =");
+ ifdebug(DGA, DDD, DebugObject(hd));
+ for( link = Down(hd); link != hd; link = NextDown(link) )
+ {
+ Child(y, link);
+ debug1(DGA, DDD, " examining %s", EchoIndex(y));
+ if( type(y) == SPLIT ) Child(y, DownDim(y, dim));
+ switch( type(y) )
+ {
+
+ case EXPAND_IND:
+ case SCALE_IND:
+ case COVER_IND:
+ case GALL_PREC:
+ case GALL_FOLL:
+ case GALL_FOLL_OR_PREC:
+ case GALL_TARG:
+ case CROSS_PREC:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+ case CROSS_TARG:
+ case PAGE_LABEL_IND:
+
+ break;
+
+
+ case PRECEDES:
+ case UNATTACHED:
+
+ if( was_sized )
+ { /* SizeGalley was not called, so hd_inners was not set by it */
+ if( hd_inners == nilobj ) New(hd_inners, ACAT);
+ Link(hd_inners, y);
+ }
+ break;
+
+
+ case RECEPTIVE:
+
+ goto SUSPEND;
+
+
+ case RECEIVING:
+
+ goto SUSPEND;
+
+
+ case FOLLOWS:
+
+ Child(tmp, Down(y));
+ if( Up(tmp) == LastUp(tmp) )
+ { link = pred(link, CHILD);
+ debug0(DGA, DD, " disposing FOLLOWS");
+ DisposeChild(NextDown(link));
+ break;
+ }
+ Parent(tmp, Up(tmp));
+ assert(type(tmp) == PRECEDES, "Attach: PRECEDES!");
+ switch( CheckComponentOrder(tmp, target_index) )
+ {
+ case CLEAR: DeleteNode(tmp);
+ link = pred(link, CHILD);
+ DisposeChild(NextDown(link));
+ break;
+
+ case PROMOTE: break;
+
+ case BLOCK: debug0(DGA, DD, "CheckContraint: BLOCK");
+ goto SUSPEND;
+
+ case CLOSE: debug0(DGA, D, " reject: CheckContraint");
+ goto REJECT;
+ }
+ break;
+
+
+ case GAP_OBJ:
+
+ underline(y) = underline(dest);
+ if( !join(gap(y)) ) seen_nojoin(hd) = TRUE;
+ break;
+
+
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+
+ /* do nothing until actually promoted out of here */
+ underline(y) = underline(dest);
+ break;
+
+
+ case CLOSURE:
+ case CROSS:
+ case FORCE_CROSS:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+
+ underline(y) = underline(dest);
+ break;
+
+
+ case WORD:
+ case QWORD:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case ROTATE:
+ case BACKGROUND:
+ case SCALE:
+ case KERN_SHRINK:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case ACAT:
+ case HCAT:
+ case VCAT:
+ case ROW_THR:
+ case COL_THR:
+
+
+ underline(y) = underline(dest);
+ if( dim == ROWM )
+ {
+ /* make sure y is not joined to a target below (vertical only) */
+ for( zlink = NextDown(link); zlink != hd; zlink = NextDown(zlink) )
+ { Child(z, zlink);
+ switch( type(z) )
+ {
+ case RECEPTIVE:
+
+ if( non_blocking(z) )
+ { zlink = PrevDown(zlink);
+ DeleteNode(z);
+ }
+ else
+ { y = z;
+ goto SUSPEND;
+ }
+ break;
+
+
+ case RECEIVING:
+
+ if( non_blocking(z) )
+ { zlink = PrevDown(zlink);
+ while( Down(z) != z )
+ { Child(tmp, Down(y));
+ if( opt_components(tmp) != nilobj )
+ { DisposeObject(opt_components(tmp));
+ opt_components(tmp) = nilobj;
+ debug3(DOG, D, "AttachGalley(%s) de-optimizing %s %s",
+ SymName(actual(hd)), SymName(actual(tmp)), "(join)");
+ }
+ DetachGalley(tmp);
+ KillGalley(tmp, FALSE);
+ }
+ DeleteNode(z);
+ }
+ else
+ { y = z;
+ goto SUSPEND;
+ }
+ break;
+
+
+ case GAP_OBJ:
+
+ if( !join(gap(z)) ) zlink = PrevDown(hd);
+ break;
+
+
+ default: break;
+ }
+ }
+
+ /* if HCAT, try vertical hyphenation (vertical galleys only) */
+ if( type(y) == HCAT ) VerticalHyphenate(y);
+ }
+
+
+ /* check availability of parallel space for the first component */
+ why = nilobj;
+ Constrained(dest, &c, dim, &why);
+ debug3(DGF, DD, " dest parallel Constrained(%s, %s) = %s",
+ EchoObject(dest), dimen(dim), EchoConstraint(&c));
+ if( !FitsConstraint(back(y, dim), fwd(y, dim), c) )
+ { BOOLEAN scaled;
+
+ /* if forcing galley doesn't fit, try scaling first component */
+ scaled = FALSE;
+ if( force_gall(hd) && size(y, dim) > 0 )
+ { int scale_factor;
+ scale_factor = ScaleToConstraint(back(y,dim), fwd(y,dim), &c);
+ if( scale_factor > 0.5 * SF )
+ { char num1[20], num2[20];
+ sprintf(num1, "%.1fc", (float) size(y, dim) / CM);
+ sprintf(num2, "%.1fc", (float) bfc(c) / CM);
+ if( dim == ROWM )
+ Error(19, 4, "%s object too high for %s space; %s inserted",
+ WARN, &fpos(y), num1, num2, KW_SCALE);
+ else
+ Error(19, 5, "%s object too wide for %s space; %s inserted",
+ WARN, &fpos(y), num1, num2, KW_SCALE);
+ y = InterposeScale(y, scale_factor, dim);
+ scaled = TRUE;
+ }
+ }
+
+ /* otherwise we must reject, and warn the user */
+ if( !scaled )
+ { char num1[20], num2[20];
+ debug3(DGA, D, " reject: vsize %s,%s in %s; y=",
+ EchoLength(back(y, dim)), EchoLength(fwd(y, dim)),
+ EchoConstraint(&c));
+ ifdebug(DGA, D, DebugObject(y));
+ if( size(y, dim) > 0 )
+ { sprintf(num1, "%.1fc", (float) size(y, dim) / CM);
+ sprintf(num2, "%.1fc", (float) bfc(c) / CM);
+ if( dim == ROWM )
+ Error(19, 12, "%s object too high for %s space; will try elsewhere",
+ WARN, &fpos(y), num1, num2);
+ else
+ Error(19, 13, "%s object too wide for %s space; will try elsewhere",
+ WARN, &fpos(y), num1, num2);
+ }
+ goto REJECT;
+ }
+
+ }
+
+ /* check availability of perpendicular space for first component */
+ if( dim == ROWM )
+ { perp_back = back(hd, 1-dim); perp_fwd = fwd(hd, 1-dim);
+ }
+ else
+ { perp_back = back(y, 1-dim); perp_fwd = fwd(y, 1-dim);
+ }
+ Constrained(dest, &c, 1-dim, &junk);
+ debug3(DGF, DD, " dest perpendicular Constrained(%s, %s) = %s",
+ EchoObject(dest), dimen(1-dim), EchoConstraint(&c));
+ if( !FitsConstraint(perp_back, perp_fwd, c) )
+ { BOOLEAN scaled;
+
+ /* if forcing galley doesn't fit, try scaling first component */
+ scaled = FALSE;
+ if( force_gall(hd) && perp_back + perp_fwd > 0 )
+ { int scale_factor;
+ scale_factor = ScaleToConstraint(perp_back, perp_fwd, &c);
+ if( scale_factor > 0.5 * SF )
+ { char num1[20], num2[20];
+ sprintf(num1, "%.1fc", (float) (perp_back + perp_fwd) / CM);
+ sprintf(num2, "%.1fc", (float) bfc(c) / CM);
+ if( 1-dim == ROWM )
+ Error(19, 6, "%s object too high for %s space; %s inserted",
+ WARN, &fpos(y), num1, num2, KW_SCALE);
+ else
+ Error(19, 7, "%s object too wide for %s space; %s inserted",
+ WARN, &fpos(y), num1, num2, KW_SCALE);
+ y = InterposeScale(y, scale_factor, 1-dim);
+ scaled = TRUE;
+ }
+ }
+
+ /* otherwise we must reject, and warn the user */
+ if( !scaled )
+ {
+ debug3(DGA, D, " reject: vsize %s,%s in %s; y=",
+ EchoLength(perp_back), EchoLength(perp_fwd),
+ EchoConstraint(&c));
+ ifdebug(DGA, D, DebugObject(y));
+ goto REJECT;
+ }
+
+ }
+
+ /* dest seems OK, so perform its size adjustments */
+ debug0(DSA, D, "calling AdjustSize from AttachGalley (a)");
+ AdjustSize(dest, back(y, dim), fwd(y, dim), dim);
+ debug0(DSA, D, "calling AdjustSize from AttachGalley (b)");
+ AdjustSize(dest, perp_back, perp_fwd, 1-dim);
+
+
+ /* now check parallel space for target_galley in target */
+ Constrained(target, &c, dim, &why);
+ debug3(DGF, DD, " target parallel Constrained(%s, %s) = %s",
+ EchoObject(target), dimen(dim), EchoConstraint(&c));
+ Child(z, LastDown(target_galley)); /* works in all cases? */
+ assert( !is_index(type(z)), "AttachGalley: is_index(z)!" );
+ assert( back(z, dim)>=0 && fwd(z, dim)>=0, "AttachGalley: z size!" );
+ if( !FitsConstraint(back(z, dim), fwd(z, dim), c) )
+ { BOOLEAN scaled;
+
+ debug2(DGA, D, " why = %d %s", (int) why, EchoObject(why));
+ debug2(DGA, D, " limiter = %d %s", (int) limiter(hd),
+ EchoObject(limiter(hd)));
+
+ /* if forcing galley doesn't fit, try scaling z */
+ scaled = FALSE;
+ if( force_gall(hd) && size(z, dim) > 0 && limiter(hd) != why )
+ { int scale_factor;
+ scale_factor = ScaleToConstraint(back(z,dim), fwd(z,dim), &c);
+ if( scale_factor > 0.5 * SF )
+ { char num1[20], num2[20];
+ sprintf(num1, "%.1fc", (float) size(z, dim) / CM);
+ sprintf(num2, "%.1fc", (float) bfc(c) / CM);
+ if( dim == ROWM )
+ Error(19, 8, "%s object too high for %s space; %s inserted",
+ WARN, &fpos(y), num1, num2, KW_SCALE);
+ else
+ Error(19, 9, "%s object too wide for %s space; %s inserted",
+ WARN, &fpos(y), num1, num2, KW_SCALE);
+ z = InterposeWideOrHigh(z, dim);
+ z = InterposeScale(z, scale_factor, dim);
+ scaled = TRUE;
+ }
+ }
+
+ if( !scaled )
+ { char num1[20], num2[20];
+ limiter(hd) = why;
+ debug3(DGA, D, " set limiter(%s) = %d %s", SymName(actual(hd)),
+ (int) limiter(hd), EchoObject(limiter(hd)));
+ debug3(DGA, D, " reject: size was %s,%s in %s; y =",
+ EchoLength(back(z, dim)), EchoLength(fwd(z, dim)),
+ EchoConstraint(&c));
+ ifdebug(DGA, D, DebugObject(y));
+ if( size(z, dim) > 0 )
+ { sprintf(num1, "%.1fc", (float) size(z, dim) / CM);
+ sprintf(num2, "%.1fc", (float) bfc(c) / CM);
+ if( dim == ROWM )
+ Error(19, 14, "%s object too high for %s space; will try elsewhere",
+ WARN, &fpos(y), num1, num2);
+ else
+ Error(19, 15, "%s object too wide for %s space; will try elsewhere",
+ WARN, &fpos(y), num1, num2);
+ }
+ goto REJECT;
+ }
+ }
+ limiter(hd) = why;
+ debug3(DGA, D, " set limiter(%s) = %d %s", SymName(actual(hd)),
+ (int) limiter(hd), EchoObject(limiter(hd)));
+
+ /* now check perpendicular space for target_galley in target */
+ Constrained(target, &c, 1-dim, &junk);
+ debug3(DGF, DD, " target perpendicular Constrained(%s, %s) = %s",
+ EchoObject(target), dimen(1-dim), EchoConstraint(&c));
+ Child(z, LastDown(target_galley)); /* works in all cases? */
+ assert( !is_index(type(z)), "AttachGalley: is_index(z)!" );
+ assert( back(z, 1-dim)>=0 && fwd(z, 1-dim)>=0,
+ "AttachGalley: z size (perpendicular)!" );
+ if( !FitsConstraint(back(z, 1-dim), fwd(z, 1-dim), c) )
+ { BOOLEAN scaled;
+
+ /* if forcing galley doesn't fit, try scaling z */
+ scaled = FALSE;
+ if( force_gall(hd) && size(z, 1-dim) > 0 )
+ { int scale_factor;
+ scale_factor = ScaleToConstraint(back(z,1-dim), fwd(z,1-dim), &c);
+ if( scale_factor > 0.5 * SF )
+ { char num1[20], num2[20];
+ sprintf(num1, "%.1fc", (float) size(z, 1-dim) / CM);
+ sprintf(num2, "%.1fc", (float) bfc(c) / CM);
+ if( 1-dim == ROWM )
+ Error(19, 10, "%s object too high for %s space; %s inserted",
+ WARN, &fpos(y), num1, num2, KW_SCALE);
+ else
+ Error(19, 11, "%s object too wide for %s space; %s inserted",
+ WARN, &fpos(y), num1, num2, KW_SCALE);
+ z = InterposeWideOrHigh(z, 1-dim);
+ z = InterposeScale(z, scale_factor, 1-dim);
+ scaled = TRUE;
+ }
+ }
+
+ if( !scaled )
+ {
+ debug3(DGA, D, " reject: size was %s,%s in %s; y =",
+ EchoLength(back(z, 1-dim)), EchoLength(fwd(z, 1-dim)),
+ EchoConstraint(&c));
+ ifdebug(DGA, D, DebugObject(y));
+ goto REJECT;
+ }
+ }
+
+ /* target seems OK, so adjust sizes and accept */
+ if( external_hor(target) )
+ {
+ /* don't adjust any sizes, none to adjust */
+ debug0(DSA, D, "not calling AdjustSize from AttachGalley (c)");
+ }
+ else if( external_ver(target) )
+ {
+ /* adjust perp size only, to galley size */
+ debug0(DSA, D, "calling AdjustSize from AttachGalley (d)");
+ AdjustSize(target, back(target_galley, 1-dim),
+ fwd(target_galley, 1-dim), 1-dim);
+ }
+ else
+ {
+ /* adjust both directions, using z (last component) */
+ Child(z, LastDown(target_galley));
+ debug0(DSA, D, "AttachGalley AdjustSize using z =");
+ ifdebug(DSA, D, DebugObject(z));
+ debug0(DSA, D, "calling AdjustSize from AttachGalley (e)");
+ AdjustSize(target, back(z, dim), fwd(z, dim), dim);
+ debug0(DSA, D, "calling AdjustSize from AttachGalley (f)");
+ AdjustSize(target, back(z, 1-dim), fwd(z, 1-dim), 1-dim);
+ }
+
+ goto ACCEPT;
+
+
+ default:
+
+ assert1(FALSE, "AttachGalley:", Image(type(y)));
+ break;
+
+ } /* end switch */
+ } /* end for */
+
+ /* null galley: promote whole galley without expanding the target */
+ debug0(DGA, D, " null galley");
+ if( tg_inners != nilobj ) DisposeObject(tg_inners), tg_inners = nilobj;
+ DisposeObject(target_galley);
+ LeaveErrorBlock(FALSE);
+ debug0(DYY, D, "] LeaveErrorBlock(FALSE) (null galley)");
+
+ /* kill off any null objects within the galley, then transfer it */
+ /* don't use Promote() since it does extra unwanted things here */
+ for( link = Down(hd); link != hd; link = NextDown(link) )
+ { Child(y, link);
+ switch( type(y) )
+ {
+
+ case GAP_OBJ:
+ case CLOSURE:
+ case CROSS:
+ case FORCE_CROSS:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+
+ link = PrevDown(link);
+ debug1(DGA, D, " null galley, disposing %s", Image(type(y)));
+ DisposeChild(NextDown(link));
+ break;
+
+
+ default:
+
+ break;
+ }
+ }
+ TransferLinks(NextDown(hd), hd, Up(target_index));
+
+ /* attach hd temporarily to target_index */
+ MoveLink(Up(hd), target_index, PARENT);
+ assert( type(hd_index) == UNATTACHED, "AttachGalley: type(hd_index)!" );
+ DeleteNode(hd_index);
+
+ /* return; only hd_inners needs to be flushed now */
+ *inners = hd_inners;
+ debug0(DGA, D, "] AttachGalley returning ATTACH_NULL");
+ return ATTACH_NULL;
+
+
+ REJECT:
+
+ /* reject first component */
+ /* debug1(DGA, D, " reject %s", EchoObject(y)); */
+ debug0(DGA, D, " reject first component");
+ LeaveErrorBlock(TRUE);
+ debug0(DYY, D, "] LeaveErrorBlock(TRUE) (REJECT)");
+ if( tg_inners != nilobj ) DisposeObject(tg_inners), tg_inners = nilobj;
+ DisposeObject(target_galley);
+ if( foll_or_prec(hd) == GALL_PREC && !sized(hd) )
+ {
+ /* move to just before the failed target */
+ MoveLink(Up(hd_index), Up(target_index), PARENT);
+ }
+ else
+ {
+ /* move to just after the failed target */
+ MoveLink(Up(hd_index), NextDown(Up(target_index)), PARENT);
+ }
+ continue;
+
+
+ SUSPEND:
+
+ /* suspend at first component */
+ debug1(DGA, D, " suspend %s", EchoIndex(y));
+ blocked(y) = TRUE;
+ LeaveErrorBlock(FALSE);
+ debug0(DYY, D, "] LeaveErrorBlock(FALSE) (SUSPEND)");
+ if( tg_inners != nilobj ) DisposeObject(tg_inners), tg_inners = nilobj;
+ DisposeObject(target_galley);
+ MoveLink(Up(hd_index), Up(target_index), PARENT);
+ if( was_sized )
+ { /* nothing new to flush if suspending and already sized */
+ if( hd_inners != nilobj ) DisposeObject(hd_inners), hd_inners=nilobj;
+ *inners = nilobj;
+ }
+ else
+ { /* flush newly discovered inners if not sized before */
+ *inners = hd_inners;
+ }
+ debug0(DGA, D, "] AttachGalley returning ATTACH_SUSPEND");
+ *suspend_pt = y;
+ return ATTACH_SUSPEND;
+
+
+ ACCEPT:
+
+ /* accept first component; now committed to the attach */
+ debug3(DGA, D, " accept %s %s %s", Image(type(y)), EchoObject(y),
+ EchoFilePos(&fpos(y)));
+ LeaveErrorBlock(TRUE);
+ debug0(DYY, D, "] LeaveErrorBlock(TRUE) (ACCEPT)");
+
+ /* attach hd to dest */
+ MoveLink(Up(hd), dest_index, PARENT);
+ assert( type(hd_index) == UNATTACHED, "AttachGalley: type(hd_index)!" );
+ DeleteNode(hd_index);
+
+ /* move first component of hd into dest */
+ /* nb Interpose must be done after all AdjustSize calls */
+ if( dim == ROWM && !external_ver(dest) )
+ Interpose(dest, VCAT, hd, y);
+ else if( dim == COLM && !external_hor(dest) )
+ { Interpose(dest, ACAT, y, y);
+ Parent(junk, Up(dest));
+ assert( type(junk) == ACAT, "AttachGalley: type(junk) != ACAT!" );
+ StyleCopy(save_style(junk), save_style(dest));
+ adjust_cat(junk) = padjust(save_style(junk));
+ }
+ debug1(DGS, D, "calling Promote(hd, %s) from AttachGalley/ACCEPT",
+ link == hd ? "hd" : "NextDown(link)");
+ Promote(hd, link == hd ? hd : NextDown(link), dest_index, TRUE);
+
+ /* move target_galley into target */
+ /* nb Interpose must be done after all AdjustSize calls */
+ if( !(external_ver(target) || external_hor(target)) )
+ { Child(z, LastDown(target_galley));
+ Interpose(target, VCAT, z, z);
+ }
+ debug0(DGS, D, "calling Promote(target_galley) from AttachGalley/ACCEPT");
+ Promote(target_galley, target_galley, target_index, TRUE);
+ DeleteNode(target_galley);
+ assert(Down(target_index)==target_index, "AttachGalley: target_ind");
+ if( blocked(target_index) ) blocked(dest_index) = TRUE;
+ DeleteNode(target_index);
+
+ /* return; both tg_inners and hd_inners need to be flushed now; */
+ /* if was_sized, hd_inners contains the inners of the first component; */
+ /* otherwise it contains the inners of all components, from SizeGalley */
+ if( tg_inners == nilobj ) *inners = hd_inners;
+ else if( hd_inners == nilobj ) *inners = tg_inners;
+ else
+ { TransferLinks(Down(hd_inners), hd_inners, tg_inners);
+ DeleteNode(hd_inners);
+ *inners = tg_inners;
+ }
+ debug0(DGA, D, "] AttachGalley returning ATTACH_ACCEPT");
+ ifdebug(DGA, D,
+ if( dim == COLM && !external_hor(dest) )
+ { OBJECT z;
+ Parent(z, Up(dest));
+ debug2(DGA, D, " COLM dest_encl on exit = %s %s",
+ Image(type(z)), EchoObject(z));
+ }
+ )
+ return ATTACH_ACCEPT;
+
+ } /* end for */
+ } /* end AttachGalley */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z20.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z20.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z20.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1044 ----
+ /*@z20.c:Galley Flushing:DebugInnersNames()@**********************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z20.c */
+ /* MODULE: Galley Flushing */
+ /* EXTERNS: FlushGalley() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ #if DEBUG_ON
+ FULL_CHAR *DebugInnersNames(OBJECT inners)
+ { static FULL_CHAR buff[MAX_BUFF];
+ OBJECT link, y, z;
+ StringCopy(buff, STR_EMPTY);
+ if( inners != nilobj )
+ { for( link = Down(inners); link != inners; link = NextDown(link) )
+ { Child(y, link);
+ if( link != Down(inners) ) StringCat(buff, STR_SPACE);
+ switch( type(y) )
+ {
+
+ case RECEIVING:
+ case UNATTACHED:
+
+ assert( Down(y) != y, "DebugInnersNames: UNATTACHED!");
+ Child(z, Down(y));
+ StringCat(buff, SymName(actual(z)));
+ break;
+
+
+ case PRECEDES:
+ case GALL_PREC:
+ case DEAD:
+
+ StringCat(buff, Image(type(y)));
+ break;
+
+
+ default:
+
+ assert1(FALSE, "DebugInnersNames:", Image(type(y)));
+ break;
+ }
+ }
+ }
+ return buff;
+ } /* end DebugInnersNames */
+ #endif
+
+
+ /*@::ParentFlush(), FlushGalley()@********************************************/
+ /* */
+ /* ParentFlush(prnt_flush, dest_index, kill) */
+ /* */
+ /* Flush the galley which is the parent of dest_index, if likely to flush. */
+ /* If kill is TRUE, delete dest_index. */
+ /* */
+ /*****************************************************************************/
+
+ static void ParentFlush(BOOLEAN prnt_flush, OBJECT dest_index, BOOLEAN kill)
+ { OBJECT prnt;
+ debug3(DGF, DD, "ParentFlush(%s, %s, %s)",
+ bool(prnt_flush), EchoIndex(dest_index), bool(kill));
+ if( prnt_flush )
+ { Parent(prnt, Up(dest_index));
+ if( kill ) DeleteNode(dest_index);
+ debug0(DGF, DD, " calling FlushGalley from ParentFlush");
+ FlushGalley(prnt);
+ }
+ else if( kill ) DeleteNode(dest_index)
+ debug0(DGF, DD, "ParentFlush returning.");
+ } /* end ParentFlush */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FlushGalley(hd) */
+ /* */
+ /* Flush galley hd as far as possible. It could be the root galley. */
+ /* */
+ /*****************************************************************************/
+
+ void FlushGalley(OBJECT hd)
+ { OBJECT dest; /* the target galley hd empties into */
+ OBJECT dest_index; /* the index of dest */
+ OBJECT inners; /* list of galleys and PRECEDES to flush */
+ OBJECT link, y; /* for scanning through the components of hd */
+ int dim; /* direction of galley */
+ CONSTRAINT dest_par_constr; /* the parallel size constraint on dest */
+ CONSTRAINT dest_perp_constr; /* the perpendicular size constraint on dest */
+ int pb, pf, f; /* candidate replacement sizes for dest */
+
+ OBJECT dest_encl; /* the VCAT or ACAT enclosing dest, if any */
+ int dest_side; /* if dest_encl != nilobj, side dest is on */
+ BOOLEAN need_adjust; /* TRUE as soon as dest_encl needs adjusting */
+ FULL_LENGTH dest_back, dest_fwd; /* the current size of dest_encl or dest */
+ FULL_LENGTH frame_size; /* the total constraint of dest_encl */
+ OBJECT prec_gap; /* the gap preceding dest if any else nilobj */
+ OBJECT prec_def; /* the component preceding dest, if any */
+ OBJECT succ_gap; /* the gap following dest if any else nilobj */
+ OBJECT succ_def; /* the component following dest, if any */
+ OBJECT stop_link; /* most recently seen gap link of hd */
+ FULL_LENGTH stop_back; /* back(dest_encl) incl all before stop_link */
+ FULL_LENGTH stop_fwd; /* fwd(dest_encl) incl. all before stop_link */
+ FULL_LENGTH stop_perp_back; /* back(dest_encl) in other direction */
+ FULL_LENGTH stop_perp_fwd; /* fwd(dest_encl) in other direction */
+ BOOLEAN prnt_flush; /* TRUE when the parent of hd needs a flush */
+ BOOLEAN target_is_internal; /* TRUE if flushing into an internal target */
+ BOOLEAN headers_seen; /* TRUE if a header is seen at all */
+ OBJECT zlink, z, tmp, prnt; int attach_status; BOOLEAN remove_target;
+ OBJECT why;
+ FULL_LENGTH perp_back, perp_fwd; /* current perp size of dest_encl */
+
+ debug1(DGF, D, "[ FlushGalley %s (hd)", SymName(actual(hd)));
+ prnt_flush = FALSE;
+ dim = gall_dir(hd);
+
+ RESUME:
+ assert( type(hd) == HEAD, "FlushGalley: type(hd) != HEAD!" );
+ debug1(DGF, D, " resuming FlushGalley %s, hd =", SymName(actual(hd)));
+ ifdebugcond(DGF, DD, actual(hd) == nilobj, DebugGalley(hd, nilobj, 4));
+ assert( Up(hd) != hd, "FlushGalley: resume found no parent to hd!" );
+
+
+ /*@@************************************************************************/
+ /* */
+ /* The first step is to examine the parent of galley hd to determine the */
+ /* status of the galley. If this is not suitable for flushing, we do */
+ /* what we can to change the status. If still no good, return; so if */
+ /* this code does not return, then the galley is ready to flush into a */
+ /* destination in the normal way, and the following variables are set: */
+ /* */
+ /* dest_index the parent of the galley and index of its destination */
+ /* dest the destination of the galley, a @Galley object */
+ /* */
+ /***************************************************************************/
+
+ Parent(dest_index, Up(hd));
+ switch( type(dest_index) )
+ {
+
+ case DEAD:
+
+ /* the galley has been killed off while this process was sleeping */
+ debug1(DGF, D, "] FlushGalley %s returning (DEAD)", SymName(actual(hd)));
+ return;
+
+
+ case UNATTACHED:
+
+ /* the galley is currently not attached to a destination */
+ attach_status = AttachGalley(hd, &inners, &y);
+ debug1(DGF, DD, " ex-AttachGalley inners: %s", DebugInnersNames(inners));
+ Parent(dest_index, Up(hd));
+ switch( attach_status )
+ {
+
+ case ATTACH_KILLED:
+
+ assert(inners==nilobj, "FlushGalley/ATTACH_KILLED: inners!=nilobj!");
+ debug1(DGF, D, "] FlushGalley %s returning (ATTACH_KILLED)",
+ SymName(actual(hd)));
+ debug1(DGF, D, " prnt_flush = %s", bool(prnt_flush));
+ return;
+
+
+ case ATTACH_INPUT:
+
+ ParentFlush(prnt_flush, dest_index, FALSE);
+ assert(inners==nilobj, "FlushGalley/ATTACH_INPUT: inners!=nilobj!");
+ debug1(DGF, D, "] FlushGalley %s returning (ATTACH_INPUT)",
+ SymName(actual(hd)));
+ return;
+
+
+ case ATTACH_NOTARGET:
+
+ ParentFlush(prnt_flush, dest_index, FALSE);
+ assert(inners==nilobj, "FlushGalley/ATTACH_NOTARG: inners!=nilobj!");
+ debug1(DGF, D, "] FlushGalley %s returning (ATTACH_NOTARGET)",
+ SymName(actual(hd)));
+ return;
+
+
+ case ATTACH_SUSPEND:
+
+ /* AttachGalley only returns inners here if they really need to */
+ /* be flushed; in particular the galley must be unsized before */
+ if( inners != nilobj )
+ {
+ debug0(DGF, DD, " calling FlushInners() from FlushGalley (a)");
+ FlushInners(inners, nilobj);
+ goto RESUME;
+ }
+ stop_link = nilobj;
+ goto SUSPEND; /* nb y will be set by AttachGalley in this case */
+
+
+ case ATTACH_NULL:
+
+ /* hd will have been linked to the unexpanded target in this case */
+ remove_target = (actual(actual(dest_index)) == whereto(hd));
+ if( force_gall(hd) )
+ {
+ /* if hd is a forcing galley, close all predecessors */
+ debug3(DGA, D, " forcing ATTACH_NULL case for %s into %s (%s)",
+ SymName(actual(hd)), SymName(whereto(hd)),
+ remove_target ? "remove_target" : "not remove_target");
+ Parent(prnt, Up(dest_index));
+ if( !non_blocking(dest_index) && remove_target )
+ {
+ /* ***
+ prnt_flush = TRUE;
+ *** */
+ prnt_flush = non_blocking(dest_index) = TRUE;
+ }
+ FreeGalley(prnt, Up(dest_index), &inners, Up(dest_index),
+ whereto(hd));
+ }
+ else
+ {
+ debug3(DGA, D, " non-force ATTACH_NULL case for %s into %s (%s)",
+ SymName(actual(hd)), SymName(whereto(hd)),
+ remove_target ? "remove_target" : "not remove_target");
+ if( blocked(dest_index) && remove_target ) prnt_flush = TRUE;
+ }
+ DetachGalley(hd);
+ KillGalley(hd, TRUE);
+ if( inners != nilobj )
+ {
+ debug0(DGF, DD, " calling FlushInners() from FlushGalley (b)");
+ FlushInners(inners, nilobj);
+ }
+ else ParentFlush(prnt_flush, dest_index, remove_target);
+ debug0(DGF, D, "] FlushGalley returning ATTACH_NULL");
+ return;
+
+
+ case ATTACH_ACCEPT:
+
+ /* if hd is a forcing galley, or actual(dest_index) is */
+ /* @ForceGalley, then close all predecessors */
+ if( force_gall(hd) || actual(actual(dest_index)) == ForceGalleySym )
+ { Parent(prnt, Up(dest_index));
+ debug1(DGA, D, " forcing ATTACH_ACCEPT case for %s",
+ SymName(actual(hd)));
+ /* debug0(DGA, DD, " force: prnt ="); */
+ /* ifdebug(DGA, DD, DebugObject(prnt)); */
+ /* debug1(DGA, D," calling FreeGalley from FlushGalley(%s)", */
+ /* SymName(actual(hd))); */
+ if( !non_blocking(dest_index) ) prnt_flush = TRUE; /* bug fix */
+ FreeGalley(prnt, Up(dest_index), &inners, Up(dest_index),
+ whereto(hd));
+ /* debug0(DGA, DD, " force: after FreeGalley, prnt ="); */
+ /* ifdebug(DGA, DD, DebugObject(prnt)); */
+ }
+ else prnt_flush = prnt_flush || blocked(dest_index);
+ debug1(DGF, DD, " force: prnt_flush = %s", bool(prnt_flush));
+ if( inners != nilobj )
+ {
+ debug0(DGF, DD, " calling FlushInners() from FlushGalley (c)");
+ FlushInners(inners, nilobj);
+ }
+ goto RESUME;
+
+
+ default:
+
+ assert(FALSE, "FlushGalley: attach_status");
+ break;
+
+ }
+ break;
+
+
+ case RECEIVING:
+
+ if( actual(actual(dest_index)) == InputSym )
+ { ParentFlush(prnt_flush, dest_index, FALSE);
+ debug1(DGF, D, "] FlushGalley %s retn, input", SymName(actual(hd)));
+ return;
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "FlushGalley: dest_index", Image(type(dest_index)));
+ break;
+ }
+ dest = actual(dest_index);
+ if( underline(dest) == UNDER_UNDEF ) underline(dest) = UNDER_OFF;
+ target_is_internal =
+ (dim==ROWM && !external_ver(dest)) || (dim==COLM && !external_hor(dest));
+ headers_seen = FALSE;
+ debug1(DGF, DD, " dest_index: %s", EchoObject(dest_index));
+
+
+ /*@@************************************************************************/
+ /* */
+ /* The second step is to examine the components of the galley one by one */
+ /* to determine if they can be promoted. Each component has the format */
+ /* */
+ /* { <index> } <object> */
+ /* */
+ /* and is always followed by a gap object (except the last component). */
+ /* An index indicates that the following object has some interesting */
+ /* feature, and it points to that feature inside the object. There are */
+ /* two possible actions for each component, in addition to accepting it: */
+ /* */
+ /* REJECT: The component does not fit, so detach the galley */
+ /* SUSPEND: The component is incomplete; go to sleep and wait */
+ /* */
+ /***************************************************************************/
+
+ stop_link = dest_encl = inners = nilobj;
+ need_adjust = FALSE;
+
+ /***************************************************************************/
+ /* */
+ /* Loop invariant */
+ /* */
+ /* The children of hd up to but not including Child(link) have been */
+ /* examined and pronounced to be promotable, if unbreakable gaps are */
+ /* ignored. When unbreakable gaps are taken into account, the most */
+ /* recent gap where a break is possible is at Child(stop_link), or */
+ /* nowhere if stop_link == nilobj. */
+ /* */
+ /* Case 1: target_is_internal == FALSE */
+ /* */
+ /* If this flag is FALSE, it means that the target of this galley is */
+ /* external. Consequently, there is no need to calculate sizes because */
+ /* there is no constraint on them. Also, a REJECT action is impossible */
+ /* so unbreakable gaps are no impediment. Variable dest_encl is nilobj. */
+ /* */
+ /* Case 2: target_is_internal == TRUE */
+ /* */
+ /* If this flag is TRUE, it means that the target of this galley is */
+ /* internal. Consequently, sizes need to be calculated, and unbreakable */
+ /* gaps need to be taken into account. Variable dest_encl may be not */
+ /* nilobj, in which case the following variables are defined: */
+ /* */
+ /* dest_encl the object enclosing dest (which must exist) */
+ /* prec_gap gap object preceding dest (which must exist) */
+ /* prec_def first definite object preceding dest (must exist) */
+ /* dest_back back(dest_encl) including effect of accepted compts */
+ /* dest_fwd fwd(dest_encl) including effect of accepted compts */
+ /* dest_side BACK or FWD, i.e. which side of the mark dest is on */
+ /* dest_par_constr the parallel size constraint on dest */
+ /* dest_perp_constr the perpendicular size constraint on dest */
+ /* frame_size size of frame enclosing dest_encl */
+ /* perp_back back(dest_encl) in other direction, incl accepteds */
+ /* perp_fwd fwd(dest_encl) in other direction, incl accepteds */
+ /* */
+ /* if dest_encl is nilobj, these variables are not defined. */
+ /* */
+ /* If stop_link is non-nilobj, then in the internal case dest_encl must */
+ /* be non-nilobj, and the following variables are defined: */
+ /* */
+ /* stop_back back(dest_encl) including all before stop_link */
+ /* stop_fwd fwd(dest_encl) including all before stop_link */
+ /* stop_perp_back back(dest_encl) in other direction */
+ /* stop_perp_fwd fwd(dest_encl) in other direction */
+ /* */
+ /* need_adjust is true if at least one definite component has been */
+ /* accepted for promotion and the destination is internal; hence, */
+ /* dest_encl is defined and its size needs to be adjusted. */
+ /* */
+ /* inners is the set of all PRECEDES and UNATTACHED indexes found. */
+ /* */
+ /***************************************************************************/
+
+ for( link = Down(hd); link != hd; link = NextDown(link) )
+ {
+ Child(y, link);
+ if( type(y) == SPLIT ) Child(y, DownDim(y, dim));
+ debug2(DGF, DD, " examining %s %s", Image(type(y)), EchoObject(y));
+ switch( type(y) )
+ {
+
+ case GAP_OBJ:
+
+ underline(y) = underline(dest);
+ prec_gap = y;
+ if( target_is_internal )
+ {
+ /* *** not necessarily true
+ assert( dest_encl != nilobj, "FlushGalley/GAP_OBJ: dest_encl!" );
+ *** */
+ if( dest_encl != nilobj && !nobreak(gap(prec_gap)) )
+ {
+ stop_link = link;
+ stop_back = dest_back;
+ stop_fwd = dest_fwd;
+ stop_perp_back = perp_back;
+ stop_perp_fwd = perp_fwd;
+ }
+ }
+ else stop_link = link;
+ if( !join(gap(y)) ) seen_nojoin(hd) = TRUE;
+ break;
+
+
+ case SCALE_IND:
+ case COVER_IND:
+ case EXPAND_IND:
+ case GALL_PREC:
+ case GALL_FOLL:
+ case GALL_FOLL_OR_PREC:
+ case GALL_TARG:
+ case CROSS_PREC:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+ case CROSS_TARG:
+ case PAGE_LABEL_IND:
+
+ underline(y) = underline(dest);
+ break;
+
+
+ case PRECEDES:
+ case UNATTACHED:
+
+ if( inners == nilobj ) New(inners, ACAT);
+ Link(inners, y);
+ break;
+
+
+ case RECEIVING:
+ case RECEPTIVE:
+
+ goto SUSPEND;
+
+
+ case FOLLOWS:
+
+ Child(tmp, Down(y));
+ if( Up(tmp) == LastUp(tmp) )
+ { link = PrevDown(link);
+ DisposeChild(NextDown(link));
+ break;
+ }
+ Parent(tmp, Up(tmp));
+ assert(type(tmp) == PRECEDES, "Flush: PRECEDES!");
+ switch( CheckComponentOrder(tmp, dest_index) )
+ {
+ case CLEAR: DeleteNode(tmp);
+ link = PrevDown(link);
+ DisposeChild(NextDown(link));
+ break;
+
+ case PROMOTE: break;
+
+ case BLOCK: goto SUSPEND;
+
+ case CLOSE: if( opt_components(hd) != nilobj )
+ { DisposeObject(opt_components(hd));
+ opt_components(hd) = nilobj;
+ debug2(DOG, D, "FlushGalley(%s) de-optimizing %s",
+ "(CLOSE problem)", SymName(actual(hd)));
+ }
+ debug1(DGF, DD, " reject (a) %s", EchoObject(y));
+ goto REJECT;
+ }
+ break;
+
+
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+
+ /* do nothing except take note, until actually promoted out of here */
+ headers_seen = TRUE;
+ break;
+
+
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case WORD:
+ case QWORD:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case ROTATE:
+ case BACKGROUND:
+ case SCALE:
+ case KERN_SHRINK:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case ACAT:
+ case HCAT:
+ case VCAT:
+ case ROW_THR:
+ case CLOSURE:
+ case CROSS:
+ case FORCE_CROSS:
+
+ underline(y) = underline(dest);
+ if( dim == ROWM )
+ {
+ /* make sure y is not joined to a target below (vertical case only) */
+ for( zlink = NextDown(link); zlink != hd; zlink = NextDown(zlink) )
+ { Child(z, zlink);
+ switch( type(z) )
+ {
+ case RECEPTIVE:
+ case RECEIVING: y = z;
+ goto SUSPEND;
+
+ case GAP_OBJ: if( !join(gap(z)) ) zlink = PrevDown(hd);
+ break;
+
+ default: break;
+ }
+ }
+
+ /* try vertical hyphenation before anything else */
+ if( type(y) == HCAT ) VerticalHyphenate(y);
+
+ }
+
+ /* check size constraint */
+ if( target_is_internal )
+ {
+ /* initialise dest_encl etc if not done yet */
+ if( dest_encl == nilobj )
+ { assert( UpDim(dest,1-dim) == UpDim(dest,dim), "FlushG: UpDims!" );
+ /* *** weird old code, trying for UpDim(dest, ROWM)?
+ Parent(dest_encl, NextDown(Up(dest)));
+ *** */
+ Parent(dest_encl, Up(dest));
+ debug4(DGF, DD, " flush dest = %s %s, dest_encl = %s %s",
+ Image(type(dest)), EchoObject(dest),
+ Image(type(dest_encl)), EchoObject(dest_encl));
+ assert( (dim==ROWM && type(dest_encl)==VCAT) ||
+ (dim==COLM && type(dest_encl)==ACAT),
+ "FlushGalley: dest != VCAT or ACAT!" );
+ SetNeighbours(Up(dest), FALSE, &prec_gap, &prec_def,
+ &succ_gap, &succ_def, &dest_side);
+ assert(prec_gap != nilobj || is_indefinite(type(y)),
+ "FlushGalley: prec_gap == nilobj && !is_indefinite(type(y))!" );
+ assert(succ_gap == nilobj, "FlushGalley: succ_gap != nilobj!" );
+ assert(dest_side == FWD || is_indefinite(type(y)),
+ "FlushGalley: dest_side != FWD || !is_indefinite(type(y))!");
+ dest_back = back(dest_encl, dim);
+ dest_fwd = fwd(dest_encl, dim);
+ perp_back = back(dest_encl, 1-dim);
+ perp_fwd = fwd(dest_encl, 1-dim);
+ Constrained(dest_encl, &dest_par_constr, dim, &why);
+ Constrained(dest_encl, &dest_perp_constr, 1-dim, &why);
+ debug1(DGF, DD, " setting dest_perp_constr = %s",
+ EchoConstraint(&dest_perp_constr));
+ frame_size = constrained(dest_par_constr) ? bfc(dest_par_constr) :0;
+ }
+
+ if( !is_indefinite(type(y)) )
+ {
+ ifdebugcond(DGF, DD, mode(gap(prec_gap)) == NO_MODE,
+ DebugGalley(hd, y, 4));
+
+ /* calculate parallel effect of adding y to dest */
+ f = dest_fwd + fwd(y, dim) - fwd(prec_def, dim) +
+ ActualGap(fwd(prec_def, dim), back(y, dim),
+ fwd(y, dim), &gap(prec_gap), frame_size,
+ dest_back + dest_fwd - fwd(prec_def, dim));
+ debug5(DGF, DD, " f = %s + %s - %s + %s (prec_gap %s)",
+ EchoLength(dest_fwd), EchoLength(fwd(y, dim)),
+ EchoLength(fwd(prec_def, dim)), EchoLength(
+ ActualGap(fwd(prec_def, dim), back(y, dim),
+ fwd(y, dim), &gap(prec_gap), frame_size,
+ dest_back + dest_fwd - fwd(prec_def, dim))
+ ), EchoGap(&gap(prec_gap)));
+ debug3(DGF, DD, " b,f: %s,%s; dest_encl: %s",
+ EchoLength(dest_back), EchoLength(f),
+ EchoConstraint(&dest_par_constr));
+
+ /* check new size against parallel constraint */
+ if( (units(gap(prec_gap))==FRAME_UNIT && width(gap(prec_gap)) > FR)
+ || !FitsConstraint(dest_back, f, dest_par_constr)
+ || (opt_components(hd) != nilobj && opt_comps_permitted(hd)<=0)
+ )
+ {
+ if( opt_components(hd) != nilobj )
+ { OBJECT z;
+
+ /* record the size of this just-completed target area for hd */
+ New(z, WIDE);
+ CopyConstraint(constraint(z), dest_par_constr);
+ Link(opt_constraints(hd), z);
+ ifdebug(DOG, D,
+ debug2(DOG, D, "FlushGalley(%s) adding constraint %s",
+ SymName(actual(hd)), EchoConstraint(&constraint(z)));
+ if( units(gap(prec_gap))==FRAME_UNIT &&
+ width(gap(prec_gap)) > FR )
+ { debug1(DOG, D, " prec_gap = %s", EchoGap(&gap(prec_gap)));
+ }
+ if( !FitsConstraint(dest_back, f, dest_par_constr) )
+ { debug3(DOG, D, " !FitsConstraint(%s, %s, %s)",
+ EchoLength(dest_back), EchoLength(f),
+ EchoConstraint(&dest_par_constr));
+ }
+ if( opt_comps_permitted(hd) <= 0 )
+ { debug1(DOG, D, " opt_comps_permitted = %2d",
+ opt_comps_permitted(hd));
+ }
+ debug4(DOG, D, "prec_gap = %s; y = %s (%s,%s):",
+ EchoGap(&gap(prec_gap)), Image(type(y)),
+ EchoLength(back(y, dim)), EchoLength(fwd(y, dim)));
+ DebugObject(y);
+ )
+
+ /* refresh the number of components permitted into the next target */
+ if( opt_counts(hd) != nilobj && Down(opt_counts(hd)) != opt_counts(hd) )
+ { Child(z, Down(opt_counts(hd)));
+ opt_comps_permitted(hd) += comp_count(z) - 1;
+ DisposeChild(Up(z));
+ }
+ else opt_comps_permitted(hd) = MAX_FILES; /* a large number */
+ debug1(DOG, D, " REJECT permitted = %2d", opt_comps_permitted(hd));
+ }
+ debug1(DGF, DD, " reject (b) %s", EchoObject(y));
+ goto REJECT;
+ }
+
+ /* calculate perpendicular effect of adding y to dest */
+ if( seen_nojoin(hd) )
+ {
+ pb = 0;
+ pf = find_max(perp_fwd, size(y, 1-dim));
+ }
+ else
+ {
+ pb = find_max(perp_back, back(y, 1-dim));
+ pf = find_max(perp_fwd, fwd(y, 1-dim));
+ }
+
+ /* check new size against perpendicular constraint */
+ if( !FitsConstraint(pb, pf, dest_perp_constr) )
+ {
+ if( opt_components(hd) != nilobj )
+ { DisposeObject(opt_components(hd));
+ opt_components(hd) = nilobj;
+ debug1(DOG, D, "FlushGalley(%s) de-optimizing (perp problem)",
+ SymName(actual(hd)));
+ }
+ if( dim == ROWM )
+ {
+ Error(20, 3, "component too wide for available space",
+ WARN, &fpos(y));
+ debug6(DGF, DD, " %s,%s [%s,%s] too wide for %s, y = %s",
+ EchoLength(pb), EchoLength(pf),
+ EchoLength(back(y, 1-dim)), EchoLength(fwd(y, 1-dim)),
+ EchoConstraint(&dest_perp_constr), EchoObject(y));
+ }
+ debug1(DGF, DD, " reject (c) %s", EchoObject(y));
+ goto REJECT;
+ }
+
+ /* accept definite component */
+ dest_fwd = f; prec_def = y;
+ perp_back = pb; perp_fwd = pf;
+ need_adjust = TRUE;
+ if( opt_components(hd) != nilobj )
+ { opt_comps_permitted(hd)--;
+ debug1(DOG, D, " ACCEPT permitted = %2d", opt_comps_permitted(hd));
+ }
+ }
+ /* accept indefinite component */
+ } /* end if( target_is_internal ) */
+
+ /* accept this component into dest, subject to following nobreaks */
+ debug3(DGF, DD, " t-accept %s %s %s", Image(type(y)), EchoObject(y),
+ EchoFilePos(&fpos(y)));
+ prnt_flush = prnt_flush || blocked(dest_index);
+ debug1(DGF, DDD, " prnt_flush = %s", bool(prnt_flush));
+ debug1(DGF, DDD, " inners = %s", DebugInnersNames(inners));
+ if( inners != nilobj )
+ { BOOLEAN promotable; OBJECT tgp;
+
+ /* We would prefer to promote right now, then give these inners */
+ /* a chance. However this is not possible unless the following */
+ /* gap (if any) is breakable */
+
+ if( type(NextDown(link)) == LINK )
+ { Child(tgp, NextDown(link));
+ assert( type(tgp) == GAP_OBJ, "FlushGalley: tgp!" );
+ promotable = !nobreak(gap(tgp));
+ }
+ else promotable = TRUE;
+
+ if( promotable )
+ {
+ debug0(DGS, D, "calling Promote(hd, stop_link) from FlushGalley (ACCEPT)");
+ Promote(hd, NextDown(link), dest_index, TRUE);
+ if( need_adjust )
+ { debug0(DSA, D, " calling AdjustSize from FlushGalley (ACCEPT)");
+ AdjustSize(dest_encl, dest_back, dest_fwd, dim);
+ AdjustSize(dest_encl, perp_back, perp_fwd, 1-dim);
+ }
+ debug0(DGF, DD, " calling FlushInners() from FlushGalley (d)");
+ FlushInners(inners, hd);
+ goto RESUME;
+ }
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "FlushGalley:", Image(type(y)));
+ break;
+
+ } /* end switch */
+ } /* end for */
+
+
+ /* EMPTY: */
+
+ /* galley is now completely accepted; clean up and exit */
+ debug0(DGF, DD, " galley empty now");
+ if( inners != nilobj ) DisposeObject(inners);
+ if( Down(hd) != hd )
+ {
+ debug0(DGS, D, "calling Promote(hd, hd) from FlushGalley (EMPTY)");
+ Promote(hd, hd, dest_index, TRUE);
+ if( need_adjust )
+ { debug0(DSA, D, " calling AdjustSize from FlushGalley (EMPTY)");
+ AdjustSize(dest_encl, dest_back, dest_fwd, dim);
+ AdjustSize(dest_encl, perp_back, perp_fwd, 1-dim);
+ }
+ }
+ if( opt_components(hd) != nilobj )
+ { OBJECT z;
+ New(z, WIDE);
+ if( dest_encl != nilobj )
+ CopyConstraint(constraint(z), dest_par_constr);
+ else
+ SetConstraint(constraint(z),
+ MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ Link(opt_constraints(hd), z);
+ debug2(DOG, D, "FlushGalley(%s) empty adding constraint %s",
+ SymName(actual(hd)), EchoConstraint(&constraint(z)));
+ }
+ DetachGalley(hd);
+ debug0(DGF, DD, " calling KillGalley from FlushGalley");
+ KillGalley(hd, TRUE);
+ ParentFlush(prnt_flush, dest_index, TRUE);
+ debug1(DGF,D,"] FlushGalley %s returning (emptied).", SymName(actual(hd)));
+ return;
+
+
+ REJECT:
+
+ /* reject this component and move to a new dest; at this point, link is */
+ /* the link to the rejected component; its child is either y or else it */
+ /* is a SPLIT whose child is y */
+ debug3(DGF, D, "at REJECT now (stop_link %s); headers(%s) = %s",
+ stop_link != nilobj ? "non-nil" : "nil",
+ SymName(actual(hd)), EchoObject(headers(hd)));
+ assert(actual(dest) != PrintSym, "FlushGalley: reject print!");
+ if( inners != nilobj ) DisposeObject(inners);
+ if( stop_link != nilobj )
+ {
+ debug0(DGS, D, "calling Promote(hd, stop_link) from FlushGalley (REJECT)");
+ Promote(hd, stop_link, dest_index, TRUE);
+ if( need_adjust )
+ { debug0(DSA, D, " calling AdjustSize from FlushGalley (REJECT)");
+ AdjustSize(dest_encl, stop_back, stop_fwd, dim);
+ AdjustSize(dest_encl, stop_perp_back, stop_perp_fwd, 1-dim);
+ }
+ }
+
+ /* if headers_seen, handle any headers not already handled by Promote() */
+ if( target_is_internal && headers_seen )
+ { OBJECT z, zlink, top_z;
+ for( zlink = hd; NextDown(zlink) != link; )
+ {
+ Child(z, NextDown(zlink));
+ top_z = z;
+ debug2(DGF, D, "FlushGalley(%s)/REJECT header-examining %s",
+ SymName(actual(hd)), EchoObject(z));
+ if( type(z) == SPLIT )
+ Child(z, DownDim(z, dim));
+ if( is_header(type(z)) )
+ {
+ assert(top_z == z, "FlushGalley: header under SPLIT!");
+ HandleHeader(hd, z);
+ }
+ else
+ zlink = NextDown(zlink);
+ }
+ }
+
+ /* now, if there are headers, dump them into the galley */
+ if( headers(hd) != nilobj )
+ { int headers_count;
+
+ /* dump new copy of headers into top of galley */
+ assert(Down(headers(hd))!=headers(hd), "FlushGalley/REJECT: headers!");
+ tmp = Down(hd);
+ assert( tmp != hd, "FlushGalley/REJECT: first_link!" );
+ headers_count = 0;
+ for( link=Down(headers(hd)); link != headers(hd); link=NextDown(link) )
+ { Child(y, link);
+ debug2(DGS, D, "FlushGalley(%s)/REJECT linking %s",
+ SymName(actual(hd)), EchoObject(y));
+ assert(type(y)!=COL_THR && type(y)!=ROW_THR, "FlushGalley/REJECT THR!");
+ Link(tmp, y);
+ headers_count++;
+ }
+ assert(headers_count % 2 == 0, "FlushGalley/REJECT: headers_count!");
+ }
+
+ /* now detach and resume */
+ DetachGalley(hd);
+ assert( type(dest_index) == RECEIVING, "FlushGalley/REJECT: dest_index!" );
+ prnt_flush = prnt_flush || blocked(dest_index);
+ DeleteNode(dest_index);
+ goto RESUME;
+
+
+ SUSPEND:
+
+ /* suspend this component */
+ debug1(DGF, D, " suspend %s", EchoIndex(y));
+ if( inners != nilobj ) DisposeObject(inners);
+ if( stop_link != nilobj )
+ {
+ debug0(DGS, D, "calling Promote(hd, stop_link) from FlushGalley/SUSPEND");
+ Promote(hd, stop_link, dest_index, TRUE);
+ if( need_adjust )
+ { debug0(DSA, D, " calling AdjustSize from FlushGalley (SUSPEND)");
+ AdjustSize(dest_encl, stop_back, stop_fwd, dim);
+ AdjustSize(dest_encl, stop_perp_back, stop_perp_fwd, 1-dim);
+ }
+ }
+
+ /* check whether external galleys can remove the blockage */
+ if( type(y) == RECEPTIVE && ready_galls(hd) != nilobj && AllowCrossDb )
+ { OBJECT eg, val, index2, hd2, tag, seq, newsym;
+ BOOLEAN found, gall; FULL_CHAR newtag[MAX_BUFF], newseq[MAX_BUFF];
+
+ /* get first ready galley in from cross reference database */
+ Child(eg, Down(ready_galls(hd)));
+ SwitchScope(nilobj);
+ val = ReadFromFile(eg_fnum(eg), eg_fpos(eg), eg_lnum(eg));
+ UnSwitchScope(nilobj);
+ if( val == nilobj )
+ Error(20, 1, "error in database file %s",
+ FATAL, &fpos(y), FileName(eg_fnum(eg)));
+ assert( type(val) == CLOSURE, "AttachG: db CLOSURE!" );
+ New(index2, UNATTACHED);
+ pinpoint(index2) = nilobj;
+ New(hd2, HEAD);
+ FposCopy(fpos(hd2), fpos(val));
+ actual(hd2) = actual(val);
+ limiter(hd2) = nilobj;
+ opt_components(hd2) = opt_constraints(hd2) = nilobj;
+ gall_dir(hd2) = horiz_galley(actual(val));
+ sized(hd2) = FALSE;
+ ready_galls(hd2) = nilobj;
+ must_expand(hd2) = TRUE;
+ Link(index2, hd2);
+ Link(hd2, val);
+ SetTarget(hd2);
+ foll_or_prec(hd2) = GALL_FOLL;
+ enclose_obj(hd2) = (has_enclose(actual(hd2)) ? BuildEnclose(hd2) : nilobj);
+ headers(hd2) = dead_headers(hd2) = nilobj;
+ Link(Up(y), index2);
+
+ /* set up the next ready galley for reading next time */
+ Child(tag, Down(eg)); Child(seq, LastDown(eg));
+ do /* skip duplicate seq values */
+ { found = DbRetrieveNext(OldCrossDb, &gall, &newsym, newtag, newseq,
+ &eg_fnum(eg), &eg_fpos(eg), &eg_lnum(eg), &eg_cont(eg));
+ debug2(DGF, DD, " ext gall found: %15s gall: %15s",
+ bool(gall), bool(found));
+ debug2(DGF, DD, " ext gall new sym: %15s old sym: %15s",
+ SymName(newsym), SymName(eg_symbol(eg)));
+ debug2(DGF, DD, " ext gall new tag: %15s old tag: %15s",
+ newtag, string(tag));
+ debug2(DGF, DD, " ext gall new seq: %15s old seq: %15s",
+ newseq, string(seq));
+ if( found ) found = gall && newsym == eg_symbol(eg) &&
+ StringEqual(newtag, string(tag));
+
+ /* merge galleys whose seq strings are equal */
+ if( found && StringEqual(newseq, string(seq)) )
+ {
+ SwitchScope(nilobj);
+ val = ReadFromFile(eg_fnum(eg), eg_fpos(eg), eg_lnum(eg));
+ UnSwitchScope(nilobj);
+ if( val == nilobj )
+ Error(20, 2, "error in database file %s",
+ FATAL, &fpos(y), FileName(eg_fnum(eg)));
+ assert( type(val) == CLOSURE, "AttachG: db CLOSURE!" );
+ if( !has_merge(actual(val)) ) DisposeObject(val);
+ else /* add val to hd2 */
+ { if( type(hd2) != ACAT )
+ { OBJECT tmp = hd2;
+ New(hd2, ACAT);
+ MoveLink(Up(tmp), hd2, CHILD);
+ Link(hd2, tmp);
+ }
+ Link(hd2, val);
+ }
+ }
+
+ } while( found && StringEqual(newseq, string(seq)) );
+ if( found )
+ { DisposeChild(Up(tag));
+ DisposeChild(Up(seq));
+ tag = MakeWord(WORD, newtag, no_fpos);
+ seq = MakeWord(WORD, newseq, no_fpos);
+ Link(eg, tag); Link(eg, seq);
+ debug1(DGF, DD, " another ext gall: into %s", SymName(newsym));
+ }
+ else
+ { DisposeChild(Up(eg));
+ debug1(DGF, DD, " last ext gall into ", SymName(eg_symbol(eg)));
+ if( Down(ready_galls(hd)) == ready_galls(hd) )
+ { Dispose(ready_galls(hd));
+ ready_galls(hd) = nilobj;
+ debug0(DGF, DD, " all ext galls exhausted");
+ }
+ }
+
+ /* flush the ready galley found above, and resume */
+ debug2(DGF, DD, " ext gall FlushGalley (%s into %s)",
+ SymName(actual(hd2)), SymName(whereto(hd2)));
+ debug0(DGF, DD, " calling FlushGalley from FlushGalley/SUSPEND");
+ if( type(hd2) == ACAT )
+ hd2 = ConvertGalleyList(hd2);
+ FlushGalley(hd2);
+ goto RESUME;
+ }
+ else if( type(y) == RECEPTIVE && trigger_externs(y) && AllowCrossDb )
+ { OBJECT sym, cr, ins, tag, seq, eg, cnt; BOOLEAN found;
+ FULL_CHAR newseq[MAX_BUFF]; FILE_NUM tfnum; long tfpos, tcont;
+ int tlnum;
+ debug1(DGF, DD, " ext gall target %s", SymName(actual(actual(y))));
+ for( sym = FirstExternTarget(actual(actual(y)), &cnt);
+ sym != nilobj; sym = NextExternTarget(actual(actual(y)), &cnt) )
+ {
+ debug1(DGF, DD, " ext gall gall_targ %s", SymName(sym));
+ cr = GallTargEval(sym, &fpos(actual(y)));
+ New(ins, GALL_TARG);
+ actual(ins) = cr;
+ Link(Up(y), ins);
+ Child(tag, LastDown(cr));
+ assert( is_word(type(tag)), "FlushGalley: cr is_word(type(tag))!" );
+ found = DbRetrieve(OldCrossDb, TRUE, sym, string(tag),
+ newseq, &tfnum, &tfpos, &tlnum, &tcont);
+ if( found )
+ { if( ready_galls(hd) == nilobj ) New(ready_galls(hd), ACAT);
+ New(eg, EXT_GALL);
+ debug1(DGF, DD, " ext gall retrieved: into %s", SymName(sym));
+ eg_fnum(eg) = tfnum;
+ eg_fpos(eg) = tfpos;
+ eg_lnum(eg) = tlnum;
+ eg_symbol(eg) = sym;
+ eg_cont(eg) = tcont;
+ tag = MakeWord(WORD, string(tag), no_fpos);
+ Link(eg, tag);
+ seq = MakeWord(WORD, newseq, no_fpos);
+ Link(eg, seq);
+ Link(ready_galls(hd), eg);
+ }
+ }
+ trigger_externs(y) = FALSE;
+ if( ready_galls(hd) != nilobj ) goto RESUME;
+ } /* end if external galleys */
+
+ /* if non-blocking, delete the index and resume */
+ if( type(y) == RECEPTIVE && non_blocking(y) )
+ { DeleteNode(y);
+ goto RESUME;
+ }
+ else if( type(y) == RECEIVING && non_blocking(y) )
+ {
+ if( Down(y) == y )
+ { DeleteNode(y);
+ }
+ else
+ { Child(z, Down(y));
+ if( opt_components(z) != nilobj )
+ GazumpOptimize(z, actual(y));
+ DetachGalley(z);
+ }
+ goto RESUME;
+ }
+
+ /* if all the above fail to remove the blockage, suspend */
+ blocked(y) = TRUE;
+ ParentFlush(prnt_flush, dest_index, FALSE);
+ debug1(DGF,D, "] FlushGalley %s returning (suspend)", SymName(actual(hd)));
+ return;
+
+ } /* end FlushGalley */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z21.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z21.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z21.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,522 ----
+ /*@z21.c:Galley Maker:SizeGalley()@*******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z21.c */
+ /* MODULE: Galley Maker */
+ /* EXTERNS: SizeGalley() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ /*****************************************************************************/
+ /* */
+ /* SizeGalley(hd, env, rows, joined, nonblock, trig, style, c, target, */
+ /* dest_index, recs, inners, enclose) */
+ /* */
+ /* Convert unsized galley hd into sized format. The input parameters are: */
+ /* */
+ /* hd the galley to be converted */
+ /* env its environment (needs to be "held" while manifesting) */
+ /* rows TRUE if the resulting galley may have more than one row */
+ /* joined TRUE if the resulting galley must be simply joined */
+ /* nonblock Set the non_blocking() field of RECEPTIVEs to this value */
+ /* trig TRUE if indefinites of hd may trigger external galleys */
+ /* *style The initial style */
+ /* *c the width constraint hd should conform to */
+ /* target if non-nilobj, expand indefinite objects to reveal a */
+ /* @Galley within this symbol */
+ /* enclose If non-nilobj, enclose any @Galley symbol encountered */
+ /* during manifesting by this symbol. */
+ /* */
+ /* The output parameters, in addition to the converted hd, are: */
+ /* */
+ /* dest_index the index of the @Galley found within target, if any */
+ /* recs list of all RECURSIVE indexes found (or nilobj if none) */
+ /* inners list of all UNATTACHED indexes found (or nilobj if none), */
+ /* not including any that come after the target or InputSym. */
+ /* */
+ /*****************************************************************************/
+
+ void SizeGalley(OBJECT hd, OBJECT env, BOOLEAN rows, BOOLEAN joined,
+ BOOLEAN nonblock, BOOLEAN trig, STYLE *style, CONSTRAINT *c, OBJECT target,
+ OBJECT *dest_index, OBJECT *recs, OBJECT *inners, OBJECT enclose)
+ { OBJECT y, link, z, crs, t, tlink, zlink, tmp, why;
+ OBJECT extras, tmp1, tmp2, bt[2], ft[2], hold_env;
+ BOOLEAN after_target;
+
+ assert( type(hd) == HEAD && Down(hd) != hd, "SizeGalley: precondition!" );
+ assert( !sized(hd), "SizeGalley: already sized!" );
+ debug6(DGM, D, "SizeGalley(%s, -, %s, %s, %s, %s, -, %s, -, -, -), hd =",
+ SymName(actual(hd)), bool(rows), bool(joined), bool(nonblock),
+ bool(trig), EchoConstraint(c));
+ debug1(DGM, DD, " env = %s", EchoObject(env));
+ ifdebug(DGM, D, DebugObject(hd));
+
+ /* manifest the child of hd, making sure it is simply joined if required */
+ Child(y, Down(hd));
+ tmp1 = target;
+ tmp2 = enclose;
+ crs = nilobj;
+ bt[COLM] = ft[COLM] = bt[ROWM] = ft[ROWM] = nilobj;
+ New(hold_env, ACAT); Link(hold_env, env);
+ if( AllowCrossDb && type(y) == CLOSURE && has_optimize(actual(y))
+ && FindOptimize(y, env) )
+ {
+ SetOptimize(hd, style);
+ }
+ debug2(DOM, D, "[ calling Manifest(%s) from SizeGalley(%s)",
+ Image(type(y)), SymName(actual(hd)));
+ debug2(DOB, D, "[ calling Manifest(%s) from SizeGalley(%s)",
+ Image(type(y)), SymName(actual(hd)));
+ if( joined )
+ { New(bt[COLM], THREAD); New(ft[COLM], THREAD);
+ debug0(DGM, DD, "SizeGalley calling Manifest (joined)");
+ y = Manifest(y, env, style, bt, ft, &tmp1, &crs, TRUE, must_expand(hd),
+ &tmp2, FALSE);
+ assert( Down(bt[COLM]) != bt[COLM] && Down(ft[COLM]) != ft[COLM],
+ "SizeGalley: threads!" );
+ Child(tmp1, Down(bt[COLM])); Child(tmp2, Down(ft[COLM]));
+ if( Down(bt[COLM]) != LastDown(bt[COLM]) ||
+ Down(ft[COLM]) != LastDown(ft[COLM]) || tmp1 != tmp2 )
+ Error(21, 1, "galley %s must have just one column mark",
+ FATAL, &fpos(y), SymName(actual(hd)) );
+ DisposeObject(bt[COLM]); DisposeObject(ft[COLM]);
+ }
+ else
+ { debug0(DGM, DD, "SizeGalley calling Manifest (not joined)");
+ y = Manifest(y, env, style, bt, ft, &tmp1, &crs, TRUE, must_expand(hd),
+ &tmp2, FALSE);
+ }
+ debug2(DOM, D, "] returning Manifest(%s) from SizeGalley(%s)",
+ Image(type(y)), SymName(actual(hd)));
+ debug2(DOB, D, "] returning Manifest(%s) from SizeGalley(%s)",
+ Image(type(y)), SymName(actual(hd)));
+ DisposeObject(hold_env);
+ debug0(DGM, DD, "SizeGalley: after manifesting, hd =");
+ ifdebug(DGM, DD, DebugObject(hd));
+
+ /* horizontally size hd */
+ debug0(DGM, DD, "SizeGalley horizontally sizing hd:");
+ New(extras, ACAT);
+ debug2(DSF, D, "[ calling MinSize(%s) from SizeGalley(%s)",
+ Image(type(y)), SymName(actual(hd)));
+ y = MinSize(y, COLM, &extras);
+ debug2(DSF, D, "] returning MinSize(%s) from SizeGalley(%s)",
+ Image(type(y)), SymName(actual(hd)));
+
+ /* break hd if vertical galley */
+ if( gall_dir(hd) == ROWM )
+ {
+ CopyConstraint(constraint(hd), *c);
+ debug0(DGM, DD, "SizeGalley calling BreakObject:");
+ debug2(DOB, D, "[ calling BreakObject(%s) from SizeGalley(%s)",
+ Image(type(y)), SymName(actual(hd)));
+ y = BreakObject(y, c);
+ debug2(DOB, D, "] returning BreakObject(%s) from SizeGalley(%s)",
+ Image(type(y)), SymName(actual(hd)));
+ if( !FitsConstraint(back(y, COLM), fwd(y, COLM), *c) )
+ Error(21, 13, "%s,%s object too wide for available space",
+ FATAL, &fpos(y), EchoLength(back(y, COLM)), EchoLength(fwd(y, COLM)));
+ back(hd, COLM) = back(y, COLM);
+ fwd(hd, COLM) = fwd(y, COLM);
+ assert( FitsConstraint(back(hd, COLM), fwd(hd, COLM), *c),
+ "SizeGalley: BreakObject failed to fit!" );
+ debug2(DSF, D, "MinSize(hd, COLM) = %s,%s",
+ EchoLength(back(hd, COLM)), EchoLength(fwd(hd, COLM)) );
+ }
+
+ /* hyphenate hd if horizontal optimal galley says so */
+ else if( opt_components(hd) != nilobj && opt_hyph(hd) && type(y) == ACAT )
+ { debug0(DOG, D, "SizeGalley calling Hyphenate()");
+ y = Hyphenate(y);
+ }
+
+ /* get the rows of hd to the top level, if required */
+ seen_nojoin(hd) = FALSE;
+ if( rows )
+ { /* OBJECT prev_gap = nilobj; */
+ debug0(DGM, DD, "SizeGalley cleaning up rows of hd:");
+ for( link = hd; NextDown(link) != hd; link = NextDown(link) )
+ { Child(y, NextDown(link));
+ debug2(DGM, DD, " cleaning %s: %s", Image(type(y)), EchoObject(y));
+ switch( type(y) )
+ {
+ case GAP_OBJ:
+
+ /* prev_gap = y; */
+ if( !join(gap(y)) ) seen_nojoin(hd) = TRUE;
+ break;
+
+
+ case VCAT:
+
+ if( gall_dir(hd) == ROWM )
+ { TransferLinks(Down(y), y, Up(y));
+ DisposeChild(Up(y));
+ link = PrevDown(link);
+ }
+ break;
+
+
+ case ACAT:
+
+ if( gall_dir(hd) == COLM )
+ { TransferLinks(Down(y), y, Up(y));
+ DisposeChild(Up(y));
+ link = PrevDown(link);
+ }
+ break;
+
+
+ case SPLIT:
+
+ assert(Up(y)==LastUp(y), "SizeGalley COL_THR: Up(y)!=LastUp(y)!");
+ Child(z, DownDim(y, ROWM));
+ if( is_indefinite(type(z)) )
+ {
+ debug1(DGT, D, "SizeGalley setting external_ver(%s) to TRUE (a)",
+ EchoObject(z));
+ external_ver(z) = TRUE;
+ }
+ else if( type(z) == VCAT )
+ { OBJECT hor, thor, clink, dlink;
+ Child(hor, DownDim(y, COLM));
+ assert( type(hor) == COL_THR, "SizeGalley: missing COL_THR!" );
+ Parent(thor, UpDim(z, COLM));
+ assert( hor == thor, "SizeGalley/SPLIT: hor != thor!" );
+ clink = DownDim(y, COLM);
+ dlink = UpDim(z, COLM);
+ for( tlink = LastDown(z); tlink != z; tlink = PrevDown(tlink) )
+ { Child(t, tlink);
+ if( type(t) == GAP_OBJ )
+ { Link(NextDown(link), t);
+ }
+ else
+ { New(tmp, SPLIT);
+ back(tmp, COLM) = back(hor, COLM);
+ fwd(tmp, COLM) = fwd(hor, COLM);
+ Link(NextDown(link), tmp);
+ Link(tmp, NextUp(clink));
+ Link(NextDown(dlink), t);
+ Link(tmp, t);
+ }
+ }
+ DeleteLink(dlink);
+ assert(Up(y)==LastUp(y), "SizeGalley COL_THR: Up(y) != LastUp(y)!");
+ DisposeChild(Up(y));
+ link = PrevDown(link);
+ }
+ break;
+
+
+ case CLOSURE:
+ case HEAD:
+
+ if( gall_dir(hd) == COLM )
+ external_hor(y) = TRUE;
+ else
+ {
+ debug1(DGT, D, "SizeGalley setting external_ver(%s) to TRUE (b)",
+ EchoObject(y));
+ external_ver(y) = TRUE;
+ }
+ break;
+
+
+ default:
+
+ break;
+ }
+ }
+ }
+
+ /* determine a scale factor for {} @Scale objects */
+ /* NB AdjustSize cannot be done correctly until after seen_nojoin is set */
+ for( link = Down(extras); link != extras; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == SCALE_IND )
+ {
+ /* check that all is in order */
+ CONSTRAINT zc; OBJECT t; FULL_LENGTH b, f;
+ z = actual(y);
+ assert( type(z) == SCALE, "SizeObject: type(z) != SCALE!" );
+ assert( bc(constraint(z)) == 0, "SizeObject: bc(constraint(z)) != 0" );
+ assert( Down(z) != z, "SizeObject SCALE: Down(z) == z!" );
+ Child(t, Down(z));
+
+ /* use @Scale COLM size constraint to determine a suitable scale factor */
+ /* check that @Scale is not in a horizontal galley */
+ if( gall_dir(hd) == COLM )
+ { Error(21, 2, "%s with unspecified scale factor in horizontal galley",
+ FATAL, &fpos(z), KW_SCALE);
+ }
+
+ Constrained(z, &zc, COLM, &why);
+ debug2(DGM, DD, "Constrained(%s, -, COLM) = %s", EchoObject(z),
+ EchoConstraint(&zc));
+ if( !constrained(zc) )
+ { Error(21, 3, "replacing infinite scale factor (unconstrained width) by 1.0",
+ WARN, &fpos(z));
+ bc(constraint(z)) = fc(constraint(z)) = 1 * SF;
+ }
+ else if( size(t, COLM) == 0 )
+ { Error(21, 4, "replacing infinite scale factor (zero width object) by 1.0",
+ WARN, &fpos(z));
+ bc(constraint(z)) = fc(constraint(z)) = 1 * SF;
+ }
+ else if( (float) bfc(zc) / size(t, COLM) > 100.0 )
+ { Error(21, 5, "replacing very large scale factor (over 100) by 1.0",
+ WARN, &fpos(z));
+ bc(constraint(z)) = fc(constraint(z)) = 1 * SF;
+ }
+ else if( (float) bfc(zc) / size(t, COLM) < 0.01 )
+ { if( bfc(zc) == 0 )
+ Error(21, 6, "object deleted (scale factor is zero)",
+ WARN, &fpos(z));
+ else
+ Error(21, 7, "object deleted (scale factor is smaller than 0.01)",
+ WARN, &fpos(z));
+ bc(constraint(z)) = fc(constraint(z)) = 1 * SF;
+ tmp = MakeWord(WORD, STR_EMPTY, &fpos(t));
+ back(tmp, COLM) = fwd(tmp, COLM) = 0;
+ back(tmp, ROWM) = fwd(tmp, ROWM) = 0;
+ word_font(tmp) = word_colour(tmp) = word_language(tmp) = 0;
+ word_outline(tmp) = FALSE;
+ word_hyph(tmp) = FALSE;
+ ReplaceNode(tmp, t);
+ DisposeObject(t);
+ t = tmp;
+ }
+ else bc(constraint(z)) = fc(constraint(z)) = (bfc(zc) * SF)/size(t, COLM);
+
+ /* calculate scaled size and adjust */
+ b = (back(t, COLM) * fc(constraint(z))) / SF;
+ f = (fwd(t, COLM) * fc(constraint(z))) / SF;
+ debug3(DGM, DD, "AdjustSize(%s, %s, %s, COLM)", EchoObject(z),
+ EchoLength(b), EchoLength(f));
+ AdjustSize(z, b, f, COLM);
+
+ /* if already vertically sized (because inside @Rotate) adjust that */
+ if( vert_sized(z) )
+ { b = (back(t, ROWM) * fc(constraint(z))) / SF;
+ f = (fwd(t, ROWM) * fc(constraint(z))) / SF;
+ debug4(DGM, DD, "AdjustSize(%s, %s, %s, %s)", EchoObject(z),
+ EchoLength(b), EchoLength(f), dimen(ROWM));
+ AdjustSize(z, b, f, ROWM);
+ }
+ }
+ }
+ DisposeObject(extras);
+
+ /* size the rows of hd and attach indices where needed */
+ debug0(DGM, DD, " SizeGalley calling MinSize(ROWM):");
+ debug0(DGM, DD, "SizeGalley sizing rows of hd =");
+ ifdebug(DGM, DD, DebugObject(hd));
+ *recs = *inners = *dest_index = nilobj;
+ after_target = FALSE;
+ for( link = Down(hd); link != hd; link = NextDown(link) )
+ { Child(y, link);
+
+ if( type(y) == GAP_OBJ || is_index(type(y)) ) continue;
+ debug0(DGM, DDD, " ROWM sizing:");
+ ifdebug(DGM, DDD, DebugObject(y));
+ New(extras, ACAT);
+ y = MinSize(y, ROWM, &extras);
+ debug3(DSF, DD, "MinSize( %s , ROWM ) = %s,%s", EchoObject(y),
+ EchoLength(back(y, ROWM)), EchoLength(fwd(y, ROWM)) );
+ debug0(DGM, DDD, " ROWM result:");
+ ifdebug(DGM, DDD, DebugObject(y));
+
+ /* now attach indexes in front of y */
+ for( zlink = Down(extras); zlink != extras; zlink = NextDown(zlink) )
+ { Child(z, zlink);
+ blocked(z) = FALSE;
+ /* debug1(DCR, DD, " extra: %s", EchoObject(z)); */
+ debug2(DGM, DD, " extra%s: %s",
+ after_target ? " after_target" : "", EchoObject(z));
+ switch( type(z) )
+ {
+ case RECEPTIVE:
+
+ /* debug2(DCR, DD, " ... uses_ext = %s, trig = %s",
+ bool(uses_extern_target(actual(actual(z)))), bool(trig)); */
+ trigger_externs(z) = uses_extern_target(actual(actual(z))) && trig;
+ non_blocking(z) = nonblock;
+ if( actual(actual(z)) == GalleySym || actual(actual(z)) == ForceGalleySym )
+ *dest_index = z;
+ if( actual(actual(z)) == GalleySym || actual(actual(z)) == ForceGalleySym
+ || actual(actual(z)) == InputSym )
+ after_target = TRUE;
+ break;
+
+
+ case RECURSIVE:
+
+ if( *recs == nilobj ) New(*recs, ACAT);
+ Link(*recs, z);
+ break;
+
+
+ case UNATTACHED:
+
+ if( !after_target ) /* *** new semantics *** */
+ { if( *inners == nilobj ) New(*inners, ACAT);
+ Link(*inners, z);
+ }
+ break;
+
+
+ case SCALE_IND:
+ case EXPAND_IND:
+ case GALL_PREC:
+ case GALL_FOLL:
+ case GALL_FOLL_OR_PREC:
+ case GALL_TARG:
+ case CROSS_PREC:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+ case CROSS_TARG:
+ case PAGE_LABEL_IND:
+
+ debug1(DCR, DD, " SizeGalley: %s", EchoObject(z));
+ break;
+
+
+ case COVER_IND:
+
+ /* adjust size of the COVER object, change it to @Scale etc. */
+ { OBJECT cover, prnt, chld; int dirn, thr_type, ok1, ok2, sf,subst, esubst;
+ float sf1, sf2; CONSTRAINT c; FULL_LENGTH b, f;
+ cover = actual(z);
+ if( type(cover) == HCOVER )
+ { dirn = COLM;
+ thr_type = COL_THR;
+ ok1 = VCAT;
+ ok2 = VCAT;
+ subst = HSCALE;
+ esubst = ONE_COL;
+ }
+ else
+ { dirn = ROWM;
+ thr_type = ROW_THR;
+ ok1 = ACAT;
+ ok2 = HCAT;
+ subst = VSCALE;
+ esubst = ONE_ROW;
+ }
+ Parent(prnt, UpDim(cover, dirn));
+ while( type(prnt) == SPLIT || type(prnt) == thr_type )
+ Parent(prnt, UpDim(prnt, dirn));
+ Child(chld, Down(cover));
+ if( type(prnt) != ok1 && type(prnt) != ok2 )
+ {
+ Error(21, 8, "%s replaced by %s (mark not shared)",
+ WARN, &fpos(cover), Image(type(cover)), Image(subst));
+ debug2(DGM, DDD, " cover = %s %s", Image(type(cover)),
+ EchoObject(cover));
+ debug1(DGM, DDD, " prnt = %s:", Image(type(prnt)));
+ ifdebug(DGM, DDD, DebugObject(prnt));
+ type(cover) = subst;
+ }
+ else if( back(chld, dirn) == 0 && fwd(chld, dirn) == 0 )
+ {
+ /* empty object, this is treated as a no-op */
+ type(cover) = esubst;
+ }
+ else if( back(chld, dirn) == 0 || fwd(chld, dirn) == 0 )
+ { Error(21, 9, "%s replaced by %s (infinite scale factor)",
+ WARN, &fpos(cover), Image(type(cover)), Image(subst));
+ type(cover) = subst;
+ }
+ else if( size(prnt, dirn) == 0 )
+ { Error(21, 10, "%s replaced by %s (zero scale factor)",
+ WARN, &fpos(cover), Image(type(cover)), Image(subst));
+ type(cover) = subst;
+ }
+ else /* sensible scale factor exists */
+ {
+ /* work out proposed scale factor and sizes for cover */
+ sf1 = (float) back(prnt, dirn) / back(chld, dirn);
+ sf2 = (float) fwd(prnt, dirn) / fwd(chld, dirn);
+ sf = find_max(sf1, sf2) * SF;
+ b = (back(chld, dirn) * sf) / SF;
+ f = (fwd(chld, dirn) * sf) / SF;
+
+ /* check whether new object fits */
+ Constrained(cover, &c, dirn, &why);
+ if( FitsConstraint(b, f, c) )
+ {
+ /* it fits, so make cover a SCALE object with this size */
+ type(cover) = SCALE;
+ if( dirn == COLM )
+ { bc(constraint(cover)) = sf;
+ fc(constraint(cover)) = SF;
+ }
+ else
+ { bc(constraint(cover)) = SF;
+ fc(constraint(cover)) = sf;
+ }
+ AdjustSize(cover, b, f, dirn);
+ }
+ else
+ { Error(21, 11, "%s replaced by %s (insufficient space)",
+ WARN, &fpos(cover), Image(type(cover)), Image(subst));
+ type(cover) = subst;
+ }
+ }
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "SizeGalley:", Image(type(z)));
+ break;
+
+ }
+ }
+ TransferLinks(Down(extras), extras, link);
+ assert( Down(extras) == extras && Up(extras) == extras, "SizeG: extras!");
+ Dispose(extras);
+ }
+
+ /* insinuate cross references */
+ if( crs != nilobj )
+ {
+ debug1(DCR, DD, "SizeGalley insinuating %s", EchoObject(crs));
+ TransferLinks(Down(crs), crs, Down(hd));
+ DisposeObject(crs);
+ }
+
+ /* check that *dest_index was found if it was required, and exit */
+ if( target != nilobj && *dest_index == nilobj )
+ Error(21, 12, "unexpected absence of %s from the body of %s",
+ FATAL, &fpos(hd), SymName(target), SymName(actual(hd)));
+ debug3(DGM, D, "SizeGalley returning %s,%s %s; hd =",
+ EchoLength(back(hd, COLM)), EchoLength(fwd(hd, COLM)),
+ EchoConstraint(&constraint(hd)));
+ ifdebug(DGM, D, DebugGalley(hd, nilobj, 4));
+ sized(hd) = TRUE;
+
+ } /* end SizeGalley */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z22.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z22.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z22.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1253 ----
+ /*@z22.c:Galley Service:Interpose()@******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z22.c */
+ /* MODULE: Galley Service */
+ /* EXTERNS: Interpose(), FlushInners(), ExpandRecursives(), */
+ /* Promote(), KillGalley(), FreeGalley(), */
+ /* SetTarget(), CheckComponentOrder() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* Interpose(z, typ, x, y) */
+ /* */
+ /* Insert a new typ object above z. Its sizes are to be taken from x */
+ /* (column) and y (row). */
+ /* */
+ /*****************************************************************************/
+
+ void Interpose(OBJECT z, int typ, OBJECT x, OBJECT y)
+ { OBJECT encl;
+ New(encl, typ);
+ FposCopy(fpos(encl), fpos(y));
+ ReplaceNode(encl, z); Link(encl, z);
+ back(encl, COLM) = back(x, COLM);
+ fwd(encl, COLM) = fwd(x, COLM);
+ back(encl, ROWM) = back(y, ROWM);
+ fwd(encl, ROWM) = fwd(y, ROWM);
+ underline(encl) = underline(z);
+ } /* end Interpose */
+
+
+ /*@::FlushInners()@***********************************************************/
+ /* */
+ /* FlushInners(inners, hd) */
+ /* */
+ /* Flush each galley on the list inners. These have become flushable */
+ /* by being promoted off the top of galley hd; if hd is the root galley, */
+ /* identifiable by having PrintSym as target, do not flush inners at all. */
+ /* */
+ /*****************************************************************************/
+
+ void FlushInners(OBJECT inners, OBJECT hd)
+ { OBJECT y, z, tmp, dest_index;
+
+ ifdebug(DGF, D,
+ OBJECT link;
+ fprintf(stderr, "dgf: [ FlushInners(");
+ for( link = Down(inners); link != inners; link = NextDown(link) )
+ {
+ Child(y, link);
+ fprintf(stderr, " %s", Image(type(y)));
+ switch( type(y) )
+ {
+
+ case DEAD:
+
+ break;
+
+
+ case RECEIVING:
+ case UNATTACHED:
+
+ if( Down(y) != y ) /* bug fix (was assert before) */
+ { assert( Down(y) != y, "FlushInners: UNATTACHED!");
+ Child(z, Down(y));
+ fprintf(stderr, " %s", SymName(actual(z)));
+ }
+ break;
+
+
+ case PRECEDES:
+
+ break;
+
+
+ case GALL_PREC:
+
+ break;
+
+
+ default:
+
+ break;
+ }
+ }
+ fprintf(stderr, ")\n");
+ )
+
+ /* check for root galley case */
+ if( hd != nilobj )
+ { assert( Up(hd) != hd, "FlushInners: Up(hd)!" );
+ Parent(dest_index, Up(hd));
+ if( actual(actual(dest_index)) == PrintSym )
+ { DisposeObject(inners);
+ debug0(DGF, D, "] FlushInners returning (PrintSym)");
+ return;
+ }
+ }
+
+ while( Down(inners) != inners )
+ { Child(y, Down(inners));
+ DeleteLink(Down(inners));
+ switch( type(y) )
+ {
+
+ case DEAD:
+
+ break;
+
+
+ case RECEIVING:
+ case UNATTACHED:
+
+ if( Down(y) != y ) /* bug fix (was assert before) */
+ { assert( Down(y) != y, "FlushInners: UNATTACHED!");
+ Child(z, Down(y));
+ debug1(DGF,D," possibly calling FlushGalley %s from FlushInners (a)",
+ SymName(actual(z)));
+ if( whereto(z)==nilobj || !uses_extern_target(whereto(z)) ) /* &&& */
+ FlushGalley(z);
+ }
+ break;
+
+
+ case PRECEDES:
+
+ Child(tmp, Down(y));
+ if( Up(tmp) != LastUp(tmp) )
+ { Parent(tmp, LastUp(tmp));
+ assert(type(tmp)==FOLLOWS, "FlushInners: FOLLOWS!");
+ if( blocked(tmp) )
+ { blocked(tmp) = FALSE;
+ Parent(z, Up(tmp));
+ debug0(DGF, D, " calling FlushGalley from FlushInners (b)");
+ if( whereto(z)==nilobj || !uses_extern_target(whereto(z)) )/* &&& */
+ FlushGalley(z);
+ }
+ }
+ break;
+
+
+ case GALL_PREC:
+
+ /* someone else is looking after this now */
+ break;
+
+
+ default:
+
+ assert1(FALSE, "FlushInners:", Image(type(y)));
+ break;
+ }
+ }
+ Dispose(inners);
+ debug0(DGF, D, "] FlushInners returning");
+ } /* end FlushInners */
+
+
+ /*@::ExpandRecursives()@******************************************************/
+ /* */
+ /* ExpandRecursives(recs) */
+ /* */
+ /* Expand each of the recursive definite objects in the list recs. */
+ /* */
+ /*****************************************************************************/
+
+ void ExpandRecursives(OBJECT recs)
+ { CONSTRAINT non_c, hc, vc;
+ OBJECT target_index, target, z, n1, inners, newrecs, hd, tmp, env, why;
+ debug0(DCR, DDD, "ExpandRecursives(recs)");
+ SetConstraint(non_c, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ n1 = nilobj;
+ assert(recs != nilobj, "ExpandRecursives: recs == nilobj!");
+ while( Down(recs) != recs )
+ { Child(target_index, Down(recs)); DeleteLink( Down(recs) );
+ assert( type(target_index) == RECURSIVE, "ExpandRecursives: index!" );
+ target = actual(target_index);
+ debug2(DCR, DDD, " expanding %s %s", Image(type(target_index)),
+ EchoObject(target));
+
+ /* expand body of target, convert to galley, and check size */
+ New(hd, HEAD); actual(hd) = actual(target); must_expand(hd) = TRUE;
+ force_gall(hd) = FALSE;
+ enclose_obj(hd) = limiter(hd) = headers(hd) = dead_headers(hd) = nilobj;
+ opt_components(hd) = opt_constraints(hd) = nilobj;
+ gall_dir(hd) = horiz_galley(actual(target));
+ whereto(hd) = ready_galls(hd) = nilobj;
+ foll_or_prec(hd) = GALL_FOLL;
+ sized(hd) = FALSE;
+ tmp = CopyObject(target, &fpos(target)); env = DetachEnv(tmp);
+ Link(hd, tmp); Link(target_index, hd);
+ SizeGalley(hd, env, external_ver(target),
+ gall_dir(hd) == ROWM ? threaded(target) : FALSE, FALSE, FALSE,
+ &save_style(target), &non_c, nilobj, &n1, &newrecs, &inners, nilobj);
+ debug0(DCR, DDD, " as galley:");
+ ifdebug(DCR, DDD, DebugObject(hd));
+ debug1(DGS, DD, "[ ExpandRecursives calling Constrained(%s, COLM)",
+ EchoObject(target));
+ Constrained(target, &hc, COLM, &why);
+ debug2(DGS, DD, "] ExpandRecursives Constrained(%s, COLM) = %s",
+ EchoObject(target), EchoConstraint(&hc));
+ debug3(DCR, DDD, " horizontal size: (%s, %s); constraint: %s",
+ EchoLength(back(hd, COLM)), EchoLength(fwd(hd, COLM)), EchoConstraint(&hc));
+ if( !FitsConstraint(back(hd, COLM), fwd(hd, COLM), hc) )
+ { DisposeChild(Up(hd));
+ if( inners != nilobj ) DisposeObject(inners);
+ if( newrecs != nilobj ) DisposeObject(newrecs);
+ DeleteNode(target_index);
+ debug0(DCR, DDD, " rejecting (too wide)");
+ continue;
+ }
+ if( !external_ver(target) )
+ { Constrained(target, &vc, ROWM, &why);
+ debug2(DSC, DD, "Constrained( %s, ROWM ) = %s",
+ EchoObject(target), EchoConstraint(&vc));
+ Child(z, LastDown(hd));
+ debug3(DCR, DDD, " vsize: (%s, %s); constraint: %s",
+ EchoLength(back(z, ROWM)), EchoLength(fwd(z, ROWM)), EchoConstraint(&vc));
+ if( !FitsConstraint(back(z, ROWM), fwd(z, ROWM), vc) )
+ { DisposeChild(Up(hd));
+ if( inners != nilobj ) DisposeObject(inners);
+ if( newrecs != nilobj ) DisposeObject(newrecs);
+ DeleteNode(target_index);
+ debug0(DCR, DDD, " rejecting (too high)");
+ continue;
+ }
+ }
+
+ /* object fits; adjust sizes and promote */
+ debug0(DSA, D, "calling AdjustSize from ExpandRecursives (a)");
+ AdjustSize(target, back(hd, COLM), fwd(hd, COLM), COLM);
+ if( !external_ver(target) )
+ { debug0(DSA, D, "calling AdjustSize from ExpandRecursives (b)");
+ AdjustSize(target, back(z, ROWM), fwd(z, ROWM), ROWM);
+ Interpose(target, VCAT, z, z);
+ }
+ debug0(DGS, D, "calling Promote(hd, hd) from ExpandRecursives");
+ Promote(hd, hd, target_index, TRUE); DeleteNode(hd);
+ DeleteNode(target_index);
+ if( inners != nilobj )
+ {
+ debug0(DGF, D, " calling FlushInners from ExpandRecursives");
+ FlushInners(inners, nilobj);
+ }
+ if( newrecs != nilobj ) MergeNode(recs, newrecs);
+ } /* end while */
+ Dispose(recs);
+ debug0(DCR, DDD, "ExpandRecursives returning.");
+ } /* end ExpandRecursives */
+
+ /*@::FindSplitInGalley()@*****************************************************/
+ /* */
+ /* static OBJECT FindSplitInGalley(hd) */
+ /* */
+ /* Search simply joined galley hd for a SPLIT object, which must be there. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT FindSplitInGalley(OBJECT hd)
+ { OBJECT link, y;
+ debug0(DGF, D, "FindSplitInGalley(hd)");
+ for( link = Down(hd); link != hd; link = NextDown(link) )
+ { Child(y, link);
+ if( is_definite(type(y)) ) break;
+ }
+ if( link == hd )
+ { debug0(DGF, D, "FindSplitInGalley failing, no definite component; hd =");
+ ifdebug(DGF, D, DebugObject(hd));
+ Error(22, 1, "FindSplit: missing galley component", INTERN, &fpos(hd));
+ }
+ while( type(y) != SPLIT ) switch( type(y) )
+ {
+ case VCAT:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case VCONTRACT:
+ case VLIMITED:
+ case VEXPAND:
+
+ Child(y, Down(y));
+ break;
+
+
+ case BEGIN_HEADER:
+ case SET_HEADER:
+
+ Child(y, LastDown(y));
+ break;
+
+
+ case CLOSURE:
+ case NULL_CLOS:
+ case END_HEADER:
+ case CLEAR_HEADER:
+ case PAGE_LABEL:
+ case HCAT:
+ case WORD:
+ case QWORD:
+ case ACAT:
+ case ROW_THR:
+ case COL_THR:
+ case ONE_COL:
+ case SCALE:
+ case KERN_SHRINK:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case HCONTRACT:
+ case HLIMITED:
+ case HEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case ROTATE:
+ case BACKGROUND:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+
+ debug0(DGF, D, "FindSplitInGalley(hd) failing, hd =");
+ ifdebug(DGF, D, DebugObject(hd));
+ Error(22, 2, "FindSplitInGalley failed", INTERN, &fpos(y),Image(type(y)));
+ break;
+
+
+ default:
+
+ assert1(FALSE, "FindSplitInGalley:", Image(type(y)));
+ break;
+
+ }
+ debug0(DGF, D, "FindSplitInGalley returning.");
+ return y;
+ } /* end FindSplitInGalley */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DisposeHeaders(OBJECT hd) */
+ /* */
+ /* Dispose the headers of hd. */
+ /* */
+ /*****************************************************************************/
+
+ static void DisposeHeaders(OBJECT hd)
+ { if( headers(hd) != nilobj )
+ { assert(type(headers(hd)) == ACAT || type(headers(hd)) == VCAT,
+ "DisposeHeaders: type(headers(hd))!");
+ while( Down(headers(hd)) != headers(hd) )
+ { DisposeChild(Down(headers(hd)));
+ }
+ headers(hd) = nilobj;
+ }
+ } /* end DisposeHeaders */
+
+
+ /*@::HandleHeader()@**********************************************************/
+ /* */
+ /* HandleHeader(hd, link, header) */
+ /* */
+ /* Given galley hd containing header object header, this routine handles */
+ /* the header, i.e. it updates headers(hd) to reflect the effect of the */
+ /* header, then deletes the header and its following gap object. */
+ /* */
+ /* Link is the link from hd to the header (it may actually link to a */
+ /* split object which then links to the header, but no matter). */
+ /* */
+ /* Actually, we no longer allow a SPLIT object above a header, because */
+ /* that means there is a COL_THR or ROW_THR above it and when we dispose */
+ /* the header, Dispose is not able to dispose the appropriate child of the */
+ /* COL_THR or ROW_THR. So Manifest() must not insert a SPLIT above a */
+ /* header, and we check for that. */
+ /* */
+ /*****************************************************************************/
+
+ void HandleHeader(OBJECT hd, OBJECT header)
+ { OBJECT g, z, gaplink;
+ debug3(DGS, D, "[ HandleHeader(%s, %s); headers = %s; galley:",
+ SymName(actual(hd)), EchoObject(header), EchoObject(headers(hd)));
+ ifdebug(DGS, D, DebugGalley(hd, nilobj, 2));
+ assert(is_header(type(header)), "HandleHeader: type(header)!");
+ assert(Up(header) == LastUp(header) && Up(header) != header,
+ "HandleHeader: header parents!");
+ switch( type(header) )
+ {
+
+ case CLEAR_HEADER:
+
+ /* clear out old headers, if any */
+ DisposeHeaders(hd);
+ break;
+
+
+ case SET_HEADER:
+
+ /* clear out old headers (not safe to dispose them yet), if any */
+ DisposeHeaders(hd);
+ /* NB NO BREAK! */
+
+
+ case BEGIN_HEADER:
+
+ /* make new headers if required */
+ if( headers(hd) == nilobj )
+ New(headers(hd), gall_dir(hd) == ROWM ? VCAT : ACAT);
+
+ /* construct a gap object from the left parameter */
+ New(g, GAP_OBJ);
+ underline(g) = FALSE;
+ MoveLink(Down(header), g, PARENT);
+ Child(z, Down(g));
+ GapCopy(gap(g), line_gap(save_style(header)));
+ mark(gap(g)) = join(gap(g)) = FALSE;
+
+ /* move header and gap into headers() */
+ MoveLink(LastDown(header), headers(hd), PARENT);
+ Link(headers(hd), g);
+ debug2(DOB, D, "HandleHeader moving %s header %s",
+ SymName(actual(hd)), Image(type(header)));
+ break;
+
+
+ case END_HEADER:
+
+ if( headers(hd) == nilobj )
+ Error(22, 11, "no header for %s to remove", WARN, &fpos(hd),
+ KW_END_HEADER);
+ else
+ {
+ /* dispose last gap */
+ assert(LastDown(headers(hd))!=headers(hd), "Promote/END_HEADER!");
+ Child(g, LastDown(headers(hd)));
+ assert(type(g) == GAP_OBJ, "HandleHeader: END_HEADER/gap!");
+ DisposeChild(LastDown(headers(hd)));
+
+ /* dispose last header object */
+ assert(LastDown(headers(hd))!=headers(hd), "Promote/END_HEADER!");
+ DisposeChild(LastDown(headers(hd)));
+ if( Down(headers(hd)) == headers(hd) )
+ { DisposeObject(headers(hd));
+ headers(hd) = nilobj;
+ }
+ }
+ break;
+
+ }
+
+ /* dispose header object and following gap object */
+ /* *** old code
+ y = MakeWord(WORD, STR_EMPTY, &fpos(header));
+ back(y, COLM) = fwd(y, COLM) = back(y, ROWM) = fwd(y, ROWM) = 0;
+ ReplaceNode(y, header);
+ *** */
+
+ /* dispose header object (must take care to disentangle safely) */
+ gaplink = NextDown(Up(header));
+ assert(type(gaplink) == LINK, "HandleHeader: type(gaplink)!");
+ if( type(header) == CLEAR_HEADER || type(header) == END_HEADER )
+ {
+ /* first disentangle child properly */
+ assert(Down(header) != header && Down(header) == LastDown(header), "HH!");
+ DisposeChild(Down(header));
+ }
+ DisposeChild(Up(header));
+ DisposeChild(gaplink);
+
+ debug2(DGS, D, "] HandleHeader returning; headers(%s) now %s; galley:",
+ SymName(actual(hd)), EchoObject(headers(hd)));
+ ifdebug(DGS, D, DebugGalley(hd, nilobj, 2));
+ } /* end HandleHeader */
+
+
+ /*@::Promote()@***************************************************************/
+ /* */
+ /* Promote(hd, stop_link, dest_index, join_after) */
+ /* */
+ /* Promote components of galley hd into its destination (dest), up to but */
+ /* not including the one linked to hd by link stop_link, which always */
+ /* follows a component. No size adjustments are made, except that when */
+ /* two col_thr nodes are merged, a COLM adjustment is made to the result. */
+ /* */
+ /* If the galley is ending here, Promote inserts a gap at the end of it. */
+ /* Whether to make this a joining gap or not is a tricky question which */
+ /* Promote answers by referring to join_after. */
+ /* */
+ /* Any BEGIN_HEADER, END_HEADER, SET_HEADER, or CLEAR_HEADER objects in */
+ /* the promoted components are diverted to headers(hd), if the target */
+ /* is internal. */
+ /* */
+ /*****************************************************************************/
+
+ void Promote(OBJECT hd, OBJECT stop_link, OBJECT dest_index, BOOLEAN join_after)
+ {
+ /* these two variables refer to the root galley only */
+ static BOOLEAN first = TRUE; /* TRUE if first component unwritten */
+ static OBJECT page_label=nilobj; /* current page label object */
+
+ OBJECT dest, link, y, z, tmp1, tmp2, why, top_y; FULL_CHAR *label_string;
+ FULL_LENGTH aback, afwd;
+ int dim;
+ debug1(DGS, D, "[ Promote(%s, stop_link):", SymName(actual(hd)));
+ ifdebug(DGS, D, DebugGalley(hd, stop_link, 2));
+
+ assert( type(hd) == HEAD, "Promote: hd!" );
+ assert( type(stop_link) == LINK || stop_link == hd, "Promote: stop_link!" );
+ assert( stop_link != Down(hd), "Promote: stop_link == Down(hd)!" );
+ type(dest_index) = RECEIVING;
+ dest = actual(dest_index);
+
+ /* insert final gap if galley is ending */
+ if( stop_link != hd )
+ { Child(y, stop_link);
+ if( type(y) != GAP_OBJ )
+ { ifdebug(DGS, D, DebugGalley(hd, stop_link, 2));
+ }
+ assert( type(y) == GAP_OBJ, "Promote: missing GAP_OBJ!" );
+ stop_link = NextDown(stop_link);
+ }
+ else
+ { New(y, GAP_OBJ);
+ FposCopy(fpos(y), fpos(hd));
+ hspace(y) = 0; vspace(y) = 1;
+ /* SetGap(gap(y), FALSE, FALSE, seen_nojoin(hd), FIXED_UNIT, NO_MODE, 0); */
+ /* SetGap(gap(y), FALSE, FALSE, threaded(dest), FIXED_UNIT, NO_MODE, 0); */
+ /* SetGap(gap(y), FALSE, FALSE, TRUE, FIXED_UNIT, NO_MODE, 0); */
+ /* ClearGap(gap(y)); */
+ SetGap(gap(y), FALSE, FALSE, join_after, FIXED_UNIT, NO_MODE, 0);
+ Link(stop_link, y);
+ }
+
+ /* if optimizing, add to dummy paragraph containing components and gaps */
+ if( opt_components(hd) != nilobj )
+ { OBJECT last, tmp;
+
+ debug1(DOG, DD, "Promote(%s) optimizing:", SymName(actual(hd)));
+ if( LastDown(opt_components(hd))!=opt_components(hd) && !opt_gazumped(hd) )
+ {
+ Child(last, LastDown(opt_components(hd)));
+ }
+ else last = nilobj;
+ for( link = Down(hd); link != stop_link; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ )
+ {
+ if( last == nilobj )
+ {
+ /* do nothing, gap cannot separate definite objects */
+ debug1(DOG, DD, " skipping initial GAP_OBJ %s", EchoGap(&gap(y)));
+ }
+ else if( type(last) == GAP_OBJ )
+ {
+ /* previous gap must have preceded an indefinite, so overwrite it */
+ FposCopy(fpos(last), fpos(y));
+ debug2(DOG, DD, " overwriting GAP_OBJ %s with %s",
+ EchoGap(&gap(last)), EchoGap(&gap(y)));
+ GapCopy(gap(last), gap(y));
+ if( Down(last) != last ) DisposeChild(Down(last));
+ if( Down(y) != y )
+ { Child(tmp, Down(y));
+ tmp = CopyObject(tmp, no_fpos);
+ Link(last, tmp);
+ }
+ join(gap(last)) = TRUE; /* irrelevant but improves debug output */
+ }
+ else
+ {
+ /* previous was definite, so this gap must be stored */
+ opt_gazumped(hd) = FALSE;
+ New(last, GAP_OBJ);
+ FposCopy(fpos(last), fpos(y));
+ GapCopy(gap(last), gap(y));
+ join(gap(last)) = TRUE; /* irrelevant but improves debug output */
+ hspace(last) = 1;
+ vspace(last) = 0;
+ Link(opt_components(hd), last);
+ debug1(DOG, DD, " adding GAP_OBJ %s", EchoGap(&gap(last)));
+ }
+ }
+ else if( is_word(type(y)) )
+ {
+ /* definite, must be stored */
+ opt_gazumped(hd) = FALSE;
+ last = MakeWord(type(y), string(y), &fpos(y));
+ back(last, COLM) = back(y, gall_dir(hd));
+ fwd(last, COLM) = fwd(y, gall_dir(hd));
+ word_font(last) = word_font(y);
+ word_colour(last) = word_colour(y);
+ word_outline(last) = word_outline(y);
+ word_language(last) = word_language(y);
+ word_hyph(last) = word_hyph(y);
+ Link(opt_components(hd), last);
+ debug2(DOG, DD, " adding %s \"%s\"", Image(type(last)), string(last));
+ }
+ else if( is_indefinite(type(y)) )
+ {
+ /* indefinite, always skip these */
+ }
+ else if( is_definite(type(y)) )
+ {
+ /* definite other than WORD, add it */
+ opt_gazumped(hd) = FALSE;
+ last = MakeWord(QWORD, AsciiToFull("w"), &fpos(y));
+ back(last, COLM) = back(y, gall_dir(hd));
+ fwd(last, COLM) = fwd(y, gall_dir(hd));
+ Link(opt_components(hd), last);
+ debug1(DOG, DD, " adding word for %s", EchoObject(y));
+ }
+ }
+ debug1(DOG, DD, "Promote(%s) end optimizing", SymName(actual(hd)));
+ }
+
+ /* error if promoting a seen_nojoin galley into a threaded destination */
+ if( seen_nojoin(hd) && gall_dir(hd) == ROWM && threaded(dest) )
+ Error(22, 3, "galley %s must have a single column mark",
+ FATAL, &fpos(hd), SymName(actual(hd)));
+
+ /* make nojoin status clear by adding an extra gap at start if needed */
+ if( gall_dir(hd) == ROWM && !external_ver(dest) && seen_nojoin(hd) &&
+ join(gap(y)) )
+ { OBJECT prnt, extra_null, extra_gap;
+
+ /* add nojoin gap at start */
+ Parent(prnt, Up(dest)); /* can't be threaded */
+ assert( type(prnt) == VCAT, "Promote: nojoin case, can't find VCAT" );
+ New(extra_null, NULL_CLOS);
+ back(extra_null, COLM) = fwd(extra_null, COLM) = 0;
+ back(extra_null, ROWM) = fwd(extra_null, ROWM) = 0;
+ New(extra_gap, GAP_OBJ);
+ hspace(extra_gap) = vspace(extra_gap) = 0;
+ SetGap(gap(extra_gap), FALSE, FALSE, FALSE, FIXED_UNIT, EDGE_MODE, 0);
+ Link(Down(prnt), extra_gap);
+ Link(Down(prnt), extra_null);
+ debug0(DGS, DD, " Promote adding extra nojoin gap");
+ /* join(gap(y)) = FALSE; */
+ }
+
+
+ /* if promoting out of root galley, do special things */
+ if( actual(dest) == PrintSym )
+ { CONSTRAINT c;
+ link = hd;
+ while( NextDown(link) != stop_link )
+ { Child(y, NextDown(link));
+ debug2(DGS, DD, "root promote %s %s", Image(type(y)),
+ is_definite(type(y)) ? STR_EMPTY : EchoObject(y));
+ if( type(y) == SPLIT ) Child(y, DownDim(y, ROWM));
+ switch( type(y) )
+ {
+
+ case SCALE_IND:
+ case COVER_IND:
+ case PRECEDES:
+
+ DisposeChild(NextDown(link));
+ break;
+
+
+ case UNATTACHED:
+
+ assert( Down(y) != y, "FlushRootGalley: UNATTACHED!" );
+ Child(z, Down(y));
+ assert( type(z) == HEAD, "FlushRootGalley: unattached HEAD!" );
+ if( sized(z) )
+ {
+ /* galley is part flushed, leave it here */
+ link = NextDown(link);
+ }
+ /* ??? else if( foll_or_prec(z) == GALL_PREC ) */
+ else if( foll_or_prec(z) == GALL_PREC ||
+ foll_or_prec(z) == GALL_FOLL_OR_PREC )
+ {
+ /* galley is preceding or foll_or_prec, send to CrossSequence */
+ OBJECT t;
+ /* type(y) = GALL_PREC; */
+ type(y) = foll_or_prec(z);
+ pinpoint(y) = nilobj;
+ Child(t, Down(z));
+ /* actual(y) = CrossMake(whereto(z), t, GALL_PREC); */
+ actual(y) = CrossMake(whereto(z), t, type(y));
+ DisposeChild(Down(y));
+ CrossSequence(actual(y));
+ DisposeChild(NextDown(link));
+ }
+ else
+ {
+ /* galley was never attached, print message and kill it */
+ Error(22, 4, "galley %s deleted (never attached)",
+ WARN, &fpos(z), SymName(actual(z)));
+ debug1(DGF, D, "never-attached galley %s:", EchoFilePos(&fpos(z)));
+ ifdebug(DGF, D, DebugObject(z));
+ KillGalley(z, FALSE);
+ /* ***
+ link = NextDown(link);
+ *** */
+ }
+ break;
+
+
+ case EXPAND_IND:
+
+ /* expand @HExpand or @VExpand to occupy everything possible */
+ dim = type(actual(y)) == HEXPAND ? COLM : ROWM;
+ Constrained(actual(y), &c, dim, &why);
+ if( constrained(c) )
+ { FULL_LENGTH b = back(actual(y), dim);
+ FULL_LENGTH f = fwd(actual(y), dim);
+ EnlargeToConstraint(&b, &f, &c);
+ debug1(DSA, D, "Promote %s AdjustSize", Image(type(actual(y))));
+ AdjustSize(actual(y), b, f, dim);
+ }
+ DisposeChild(NextDown(link));
+ break;
+
+
+ case PAGE_LABEL_IND:
+
+ if( page_label != nilobj )
+ { DisposeObject(page_label);
+ page_label = nilobj;
+ }
+ Child(z, Down(y));
+ assert( type(z) == PAGE_LABEL, "Promote: type(z) != PAGE_LABEL!" );
+ assert( Down(z) != z, "Promote: PAGE_LABEL Down(z) == z!" );
+ Child(page_label, Down(z));
+ DeleteLink(Up(page_label));
+ DisposeChild(NextDown(link));
+ break;
+
+
+ case CROSS_PREC:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+ case CROSS_TARG:
+
+ debug2(DGS, DD, "root promote %s %s", Image(type(y)), EchoObject(y));
+ /* NB NO BREAK */
+
+
+ case GALL_PREC:
+ case GALL_FOLL:
+ case GALL_FOLL_OR_PREC:
+ case GALL_TARG:
+
+ CrossSequence(actual(y));
+ DisposeChild(NextDown(link));
+ break;
+
+
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+
+ Error(22, 10, "%s symbol ignored (out of place)", WARN, &fpos(y),
+ Image(type(y)));
+ DisposeChild(NextDown(link));
+ break;
+
+
+ case WORD:
+ case QWORD:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case ROTATE:
+ case BACKGROUND:
+ case SCALE:
+ case KERN_SHRINK:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case ACAT:
+ case HCAT:
+ case ROW_THR:
+
+ case CLOSURE:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case CROSS:
+ case FORCE_CROSS:
+
+ /* print this component */
+ debug0(DGS, DD, "root promote definite or indefinite");
+ if( !is_indefinite(type(y)) && size(y, ROWM) != 0 )
+ {
+ /* fix horizontally; work out which fonts needed */
+ SetLengthDim(COLM);
+ FixAndPrintObject(y, back(y, COLM), back(y, COLM), fwd(y, COLM),
+ COLM, FALSE, 0, 0, &aback, &afwd);
+
+ /* print prefatory or page separating material, including fonts */
+ label_string = page_label != nilobj && is_word(type(page_label)) ?
+ string(page_label) : AsciiToFull("?");
+ debug1(DGS, DD, "root promote definite; label_string = %s",
+ label_string);
+ debug1(DCR, DD, "label_string = %s", label_string);
+ if( first )
+ { BackEnd->PrintBeforeFirstPage(size(hd, COLM), size(y, ROWM),
+ label_string);
+ first = FALSE;
+ }
+ else
+ BackEnd->PrintBetweenPages(size(hd, COLM), size(y, ROWM),
+ label_string);
+ if( page_label != nilobj )
+ { DisposeObject(page_label);
+ page_label = nilobj;
+ }
+
+ /* fix and print vertically */
+ debug1(DGF,D, " Promote calling FixAndPrint %s", Image(type(y)));
+ debug3(DGP,D, " Promote calling FixAndPrint %s %s,%s", dimen(ROWM),
+ EchoLength(back(y,ROWM)), EchoLength(fwd(y, ROWM)));
+ SetLengthDim(ROWM);
+ FixAndPrintObject(y, back(y,ROWM), back(y, ROWM), fwd(y, ROWM),
+ ROWM, FALSE, size(y, ROWM), 0, &aback, &afwd);
+
+ }
+ DisposeChild(NextDown(link));
+
+ /* scavenge any filter files now not needed */
+ FilterScavenge(FALSE);
+ break;
+
+
+ case GAP_OBJ:
+
+ DisposeChild(NextDown(link));
+ break;
+
+
+ default:
+
+ assert1(FALSE, "Promote:", Image(type(y)));
+ break;
+
+ }
+ }
+ debug0(DGS, DD, "Promote returning (root galley).");
+ return;
+ }
+
+ /* prepare the promotion */
+ if( external_ver(dest) && gall_dir(hd) == ROWM )
+ { if( threaded(dest) )
+ { Parent(tmp1, UpDim(dest, COLM));
+ assert( type(tmp1) == COL_THR, "Promote: tmp1 not COL_THR!" );
+ y = FindSplitInGalley(hd);
+ assert( type(y) == SPLIT, "Promote: FindSplitInGalley!" );
+ Child(tmp2, DownDim(y, COLM));
+ assert( type(tmp2) == COL_THR, "Promote: tmp2 not COL_THR!" );
+ if( tmp1 != tmp2 )
+ { FULL_LENGTH b = find_max(back(tmp1, COLM), back(tmp2, COLM));
+ FULL_LENGTH f = find_max(fwd(tmp1, COLM), fwd(tmp2, COLM));
+ debug0(DSA, D, "calling AdjustSize(tmp1) from Promote (node merging)");
+ AdjustSize(tmp1, b, f, COLM);
+ debug0(DSA, D, "calling AdjustSize(tmp2) from Promote (node merging)");
+ AdjustSize(tmp2, b, f, COLM);
+ MergeNode(tmp1, tmp2);
+ }
+ }
+ link = Up(dest_index);
+ }
+ else if( external_hor(dest) && gall_dir(hd) == COLM )
+ { link = Up(dest_index);
+ }
+ else
+ {
+ dim = gall_dir(hd);
+ for( link = hd; NextDown(link) != stop_link; )
+ { Child(y, NextDown(link));
+ debug1(DGS, DD, "ordinary promote examining %s", EchoObject(y));
+ top_y = y;
+ if( type(y) == SPLIT )
+ Child(y, DownDim(y, dim));
+ if( is_header(type(y)) )
+ {
+ assert(top_y == y, "Promote: header under SPLIT!");
+ HandleHeader(hd, y);
+ }
+ else if( is_index(type(y)) )
+ MoveLink(NextDown(link), Up(dest_index), PARENT);
+ else link = NextDown(link);
+ }
+ assert( Down(hd) != stop_link, "Promote: Down(hd) == stop_link!" );
+ assert( UpDim(dest, ROWM) == UpDim(dest, COLM), "Promote: dims!" );
+ link = Up(dest);
+ }
+
+ /* promote components */
+ TransferLinks(Down(hd), stop_link, link);
+
+ debug0(DGS, D, "] Promote returning; galley:");
+ ifdebug(DGS, D, DebugGalley(hd, nilobj, 2));
+ } /* end Promote */
+
+
+ /*@::MakeDead(), KillGalley()@************************************************/
+ /* */
+ /* static MakeDead(y) */
+ /* */
+ /* Convert object y into a DEAD object and remove it to the dead store. */
+ /* */
+ /*****************************************************************************/
+
+ static void MakeDead(OBJECT y)
+ { static int dead_count = 0; /* number of DEAD objects seen */
+ static OBJECT dead_store = nilobj; /* where DEAD objects are kept */
+
+ debug1(DGS, DDD, "MakeDead( %s )", Image(type(y)));
+ if( dead_store == nilobj ) New(dead_store, ACAT);
+ type(y) = DEAD;
+ MoveLink(Up(y), dead_store, PARENT);
+ if( dead_count >= 150 )
+ { DisposeChild(Down(dead_store));
+ }
+ else dead_count++;
+ debug1(DGS, DDD, "MakeDead returning (dead_count = %d).", dead_count);
+ } /* end MakeDead */
+
+
+ /*****************************************************************************/
+ /* */
+ /* KillGalley(hd, optimize) */
+ /* */
+ /* Kill galley hd, which may be sized or unsized. The index of hd must */
+ /* be UNATTACHED; it is moved out of its present location to a secret spot. */
+ /* */
+ /* If hd is to be optimized, generate all the stuff for the cross */
+ /* reference database. However, don't do this if optimize is FALSE, for */
+ /* in that case hd is defective in some way and not optimizable. */
+ /* */
+ /*****************************************************************************/
+
+ void KillGalley(OBJECT hd, BOOLEAN optimize)
+ { OBJECT prnt, link, y, z;
+ debug2(DGF, D, "[ KillGalley(Galley %s into %s)",
+ SymName(actual(hd)), SymName(whereto(hd)));
+ assert( type(hd) == HEAD && Up(hd) != hd, "KillGalley: precondition!" );
+ Parent(prnt, Up(hd));
+ assert( type(prnt) == UNATTACHED, "KillGalley: UNATTACHED precondition!" );
+ assert( Up(prnt) != prnt, "KillGalley: prnt!" );
+
+ /* delete any ready_galls that might be hanging about */
+ if( ready_galls(hd) != nilobj )
+ { DisposeObject(ready_galls(hd));
+ ready_galls(hd) = nilobj;
+ }
+
+ /* delete every remaining component */
+ for( link = hd; NextDown(link) != hd; )
+ { Child(y, NextDown(link));
+ switch( type(y) )
+ {
+ case RECEIVING: while( Down(y) != y )
+ { Child(z, Down(y));
+ DetachGalley(z);
+ }
+ DeleteNode(y);
+ break;
+
+ case RECEPTIVE: assert( Down(y) == y, "KillGalley: RECEPTIVE!" );
+ DeleteNode(y);
+ break;
+
+ case UNATTACHED: assert( Down(y) != y, "KillGalley: UNATTACHED!" );
+ Child(z, Down(y)); KillGalley(z, FALSE);
+ break;
+
+ case HEAD: assert(FALSE, "KillGalley: head");
+ break;
+
+ default: DisposeChild(NextDown(link));
+ break;
+ }
+ }
+
+ /* perform optimization calculations if required */
+ if( optimize && opt_components(hd) != nilobj )
+ CalculateOptimize(hd);
+
+ /* move index into dead_store */
+ MakeDead(prnt);
+ debug0(DGF, D, "] KillGalley returning.");
+ } /* end KillGalley */
+
+
+ /*@::FreeGalley()@************************************************************/
+ /* */
+ /* FreeGalley(hd, stop_link, inners, relocate_link, sym) */
+ /* */
+ /* Free galley hd up to but not including stop_link. *Inners is well- */
+ /* defined, either nilobj or an ACAT of galleys to be flushed. */
+ /* */
+ /* Relocate_link defines what to do with any galley attached to one of the */
+ /* freed targets. If it is non-nilobj, galley hd is searched onwards from */
+ /* it to see if a target can be found there. If so, the galley is */
+ /* relocated to just before that point. If not, or if relocate_link is */
+ /* nilobj, the galley is freed and added to *inners for flushing. If the */
+ /* whereto() of such galley is sym, it is freed, not relocated, because the */
+ /* cause of this call to FreeGalley is also targeted to sym, and it will */
+ /* consume all possible targets of sym. */
+ /* */
+ /*****************************************************************************/
+
+ void FreeGalley(OBJECT hd, OBJECT stop_link, OBJECT *inners,
+ OBJECT relocate_link, OBJECT sym)
+ { OBJECT link, y, z, zlink, srch, index;
+ assert( type(hd) == HEAD && sized(hd), "FreeGalley: pre!");
+ assert( Up(hd) != hd, "FreeGalley: Up(hd)!" );
+ assert( *inners == nilobj || type(*inners) == ACAT, "FreeGalley: ACAT!" );
+ debug3(DGA, D, "[ FreeGalley(Galley %s into %s); rl %s nilobj",
+ SymName(actual(hd)), SymName(whereto(hd)),
+ relocate_link == nilobj ? "==" : "!=");
+
+ /* close targets and move or flush any inner galleys */
+ for( link = Down(hd); link != stop_link; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == RECEIVING && actual(actual(y)) == InputSym )
+ Error(22, 5, "forcing galley after input point", WARN, &fpos(actual(y)));
+ else if( type(y) == RECEIVING )
+ {
+ /* either relocate or free each galley */
+ for( zlink = Down(y); zlink != y; )
+ { Child(z, zlink);
+ zlink = NextDown(zlink);
+ assert( type(z) == HEAD, "FreeGalley/RECEIVING: type(z) != HEAD!" );
+ debug1(DGA, D, "FreeGalley examining galley %s", SymName(actual(z)));
+ if( relocate_link != nilobj && whereto(z) != sym &&
+ (srch = SearchGalley(relocate_link, whereto(z), TRUE,
+ FALSE, TRUE, FALSE)) != nilobj )
+ {
+ if( opt_components(z) != nilobj ) GazumpOptimize(z, actual(y));
+ debug2(DGA, D, " FreeGalley relocating %s to just before %s",
+ SymName(actual(z)), SymName(whereto(z)));
+ DetachGalley(z);
+ Parent(index, Up(z));
+ MoveLink(Up(index), Up(srch), PARENT); /* just before new dest */
+ }
+ else
+ { debug1(DGA, D, " FreeGalley freeing galley %s", SymName(actual(z)));
+ FreeGalley(z, z, inners, nilobj, sym);
+ if( *inners == nilobj ) New(*inners, ACAT);
+ Link(*inners, y);
+ }
+ }
+ non_blocking(y) = TRUE;
+ }
+ else if( type(y) == RECEPTIVE )
+ { non_blocking(y) = TRUE;
+ }
+ }
+ debug0(DGA, D, "] FreeGalley returning.");
+ } /* end FreeGalley */
+
+
+ /*@::SetTarget()@*************************************************************/
+ /* */
+ /* SetTarget(hd) */
+ /* */
+ /* Search for the target of unsized galley hd, and set the following: */
+ /* */
+ /* whereto(hd) The symbol which is this galley's target */
+ /* foll_or_prec(hd) GALL_FOLL, GALL_PREC, GALL_FOLL_OR_PREC */
+ /* force_gall(hd) TRUE is this is a forcing galley */
+ /* */
+ /*****************************************************************************/
+
+ void SetTarget(OBJECT hd)
+ { OBJECT x, y, link, cr, lpar, rpar, env;
+ BOOLEAN copied;
+ debug1(DGS, DD, "SetTarget(%s)", SymName(actual(hd)));
+ assert( type(hd) == HEAD, "SetTarget: type(hd) != HEAD!" );
+ Child(x, Down(hd));
+ assert( type(x) == CLOSURE, "SetTarget: type(x) != CLOSURE!" );
+ assert( has_target(actual(x)), "SetTarget: x has no target!" );
+
+ /* search the parameters of x for @Target */
+ cr = nilobj;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == PAR && is_target(actual(y)) )
+ { assert( Down(y) != y, "SetTarget: Down(PAR)!" );
+ Child(cr, Down(y));
+ break;
+ }
+ }
+
+ /* search the children of actual(x) for a default value of @Target */
+ if( cr == nilobj )
+ for( link = Down(actual(x)); link != actual(x); link = NextDown(link) )
+ { Child(y, link);
+ if( is_target(y) )
+ { cr = sym_body(y);
+ break;
+ }
+ }
+ assert(cr != nilobj, "SetTarget: cr == nilobj!");
+
+ /* if cr is not a cross-reference, expand it until it is */
+ copied = FALSE;
+ if( !is_cross(type(cr)) )
+ { OBJECT nbt[2], nft[2], ntarget, ncrs, nenclose;
+ nbt[COLM] = nft[COLM] = nbt[ROWM] = nft[ROWM] = nilobj;
+ ntarget = ncrs = nenclose = nilobj;
+ cr = CopyObject(cr, &fpos(x));
+ copied = TRUE;
+ env = GetEnv(x);
+ cr = Manifest(cr, env, &InitialStyle, nbt, nft, &ntarget, &ncrs,
+ FALSE, FALSE, &nenclose, TRUE);
+ }
+
+ /* check that cr is now a cross-reference object */
+ debug1(DGS, DD, "SetTarget examining %s", EchoObject(cr));
+ debug1(DGS, DD, " type(cr) = %s", Image( (int) type(cr)) );
+ if( !is_cross(type(cr)) )
+ Error(22, 6, "target of %s is not a cross reference",
+ FATAL, &fpos(cr), SymName(actual(x)));
+
+ /* determine which symbol is the target of this galley */
+ Child(lpar, Down(cr));
+ if( type(lpar) != CLOSURE )
+ Error(22, 7, "left parameter of %s is not a symbol",
+ FATAL, &fpos(lpar), KW_CROSS);
+ whereto(hd) = actual(lpar);
+
+ /* determine the direction from the right parameter */
+ Child(rpar, NextDown(Down(cr)));
+ if( !is_word(type(rpar)) )
+ {
+ Error(22, 8, "replacing %s%s? by %s%s%s", WARN, &fpos(rpar),
+ SymName(actual(lpar)), KW_CROSS,
+ SymName(actual(lpar)), KW_CROSS, KW_FOLLOWING);
+ foll_or_prec(hd) = GALL_FOLL;
+ }
+ else if( StringEqual(string(rpar), KW_PRECEDING) )
+ foll_or_prec(hd) = GALL_PREC;
+ else if( StringEqual(string(rpar), KW_FOLLOWING) )
+ foll_or_prec(hd) = GALL_FOLL;
+ else if( StringEqual(string(rpar), KW_FOLL_OR_PREC) )
+ foll_or_prec(hd) = GALL_FOLL_OR_PREC;
+ else
+ {
+ Error(22, 9, "replacing %s%s%s by %s%s%s",
+ WARN, &fpos(rpar), SymName(actual(lpar)), KW_CROSS,
+ string(rpar), SymName(actual(lpar)), KW_CROSS, KW_FOLLOWING);
+ foll_or_prec(hd) = GALL_FOLL;
+ }
+
+ /* determine whether this is a forcing galley */
+ force_gall(hd) = force_target(actual(hd)) || type(cr) == FORCE_CROSS;
+
+ if( copied ) DisposeObject(cr);
+ } /* end SetTarget */
+
+
+ /*@::CheckComponentOrder()@***************************************************/
+ /* */
+ /* int CheckComponentOrder(preceder, follower) */
+ /* */
+ /* Check the ordering relation between components preceder and follower, */
+ /* and return its current status: */
+ /* */
+ /* CLEAR follower definitely follows preceder, and always will; */
+ /* PROMOTE follower is not prevented from following preceder; */
+ /* CLOSE follower must move down its galley to follow preceder; */
+ /* BLOCK follower cannot be guaranteed to follow preceder. */
+ /* */
+ /*****************************************************************************/
+
+ int CheckComponentOrder(OBJECT preceder, OBJECT follower)
+ { OBJECT prec_galley, foll_galley, z; int res;
+ debug2(DGS, DD, "CheckComponentOrder( %s, %s )",
+ EchoObject(preceder), EchoObject(follower));
+ Parent(prec_galley, Up(preceder));
+ Parent(foll_galley, Up(follower));
+ if( prec_galley == foll_galley )
+ { res = CLOSE;
+ for( z = Up(follower); z != foll_galley; z = pred(z, CHILD) )
+ if( z == Up(preceder) )
+ { res = CLEAR;
+ break;
+ }
+ }
+ else
+ { res = PROMOTE;
+ while( Up(prec_galley) != prec_galley )
+ { Parent(z, Up(prec_galley)); /* index of galley */
+ Parent(prec_galley, Up(z)); /* enclosing galley */
+ if( prec_galley == foll_galley )
+ { res = BLOCK;
+ break;
+ }
+ }
+ }
+ debug1(DGS, DD, "CheckComponentOrder returning %s", Image(res));
+ return res;
+ } /* end CheckComponentOrder */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z23.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z23.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z23.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1352 ----
+ /*@z23.c:Galley Printer:ScaleFactor()@****************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z23.c */
+ /* MODULE: Galley Printer */
+ /* EXTERNS: FixAndPrintObject() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define NO_SUPPRESS FALSE
+ #define SUPPRESS TRUE
+ #define word_equal(x, str) (is_word(type(x)) && StringEqual(string(x), str))
+
+
+ /*****************************************************************************/
+ /* */
+ /* static float ScaleFactor(avail_size, inner_size) */
+ /* */
+ /* Return the scale factor for this scaling, or 0 if impossible. */
+ /* */
+ /*****************************************************************************/
+
+ static float ScaleFactor(FULL_LENGTH avail_size, FULL_LENGTH inner_size)
+ { float scale_factor;
+ scale_factor = avail_size <= 0 ? 0 :
+ inner_size <= 0 ? 0 : (float) avail_size / inner_size;
+ return scale_factor;
+ }
+
+
+ /*@::FindAdjustIncrement()@***************************************************/
+ /* */
+ /* static FULL_LENGTH FindAdjustIncrement(x, frame_size, dim) */
+ /* */
+ /* Find the amount by which to increase the width of the subobjects of */
+ /* concatenation object x so that it is adjusted to fill size frame_size. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_LENGTH FindAdjustIncrement(OBJECT x, FULL_LENGTH frame_size,int dim)
+ { OBJECT y, link, prev, g;
+ int adjustable_gaps; BOOLEAN jn;
+ FULL_LENGTH inc, mk, actual_size;
+
+ debug2(DGP, DD, "FindAdjustIncrement(x, %s, %s)",
+ EchoLength(frame_size), dimen(dim));
+ FirstDefinite(x, link, prev, jn);
+ if( link != x )
+ { adjustable_gaps = 0;
+ mk = back(prev, dim);
+ NextDefiniteWithGap(x, link, y, g, jn);
+ while( link != x )
+ { if ( mode(gap(g)) == TAB_MODE || units(gap(g)) == AVAIL_UNIT
+ || units(gap(g)) == FRAME_UNIT )
+ { debug0(DGP, DD, "FindAdjustIncrement returning 0 (tab gap)");
+ return 0;
+ }
+ mk += ActualGap(fwd(prev, dim), back(y, dim), fwd(y, dim), &gap(g),
+ frame_size, mk);
+ prev = y;
+ adjustable_gaps++;
+ NextDefiniteWithGap(x, link, y, g, jn);
+ }
+ actual_size = mk + fwd(prev, dim);
+ debug2(DGP, DD, " actual_size = %s, adjustable_gaps = %d",
+ EchoLength(actual_size), adjustable_gaps);
+ inc = adjustable_gaps==0 ? 0 : (frame_size - actual_size) / adjustable_gaps;
+ }
+ else inc = 0;
+ debug1(DGP, DD, "FindAdjustIncrement returning %s", EchoLength(inc));
+ return inc;
+ } /* end FindAdjustIncrement */
+
+
+ /*@::FixAndPrintObject()@*****************************************************/
+ /* */
+ /* OBJECT FixAndPrintObject(x, xmk, xb, xf, dim, suppress, pg, count, */
+ /* actual_back, actual_fwd) */
+ /* */
+ /* Fix the absolute position of object x in dimension dim, in such a way */
+ /* that the principal mark of x has coordinate xmk, and x has actual size */
+ /* (xb, xf), where usually xb >= back(x, dim) and xf >= fwd(x, dim). */
+ /* */
+ /* Actually, in the case where x includes an object lying on a thread */
+ /* leading outside x, the final size of x may be different. Because */
+ /* of this, the procedure sets *actual_back and *actual_fwd to the actual */
+ /* size of x upon return. The caller assumes that x will exactly occupy */
+ /* this space (actual_back, actual_fwd). */
+ /* */
+ /* The suppress parameter is true if a temporary suppression of adjustment */
+ /* in this direction is in effect (because a neighbouring adjustment has */
+ /* already been done). This is for @HAdjust and @VAdjust, not @PAdjust. */
+ /* */
+ /* If dim == COLM, the coordinate information is merely stored; but if */
+ /* dim == ROWM, it is used to generate PostScript for printing x. */
+ /* */
+ /* Parameter pg records the height of the current page. This is used */
+ /* to correct for the fact that Lout places its origin at the top left, */
+ /* while PostScript places its origin at the bottom left. This correction */
+ /* cannot be made by transforming user space. */
+ /* */
+ /* x is child number count of its parent (used by COL_THR and ROW_THR only) */
+ /* */
+ /* FixAndPrintObject ordinarily returns the object passed to it; however */
+ /* it occasionally replaces that object with another, and then it is the */
+ /* replacement object that is returned. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT FixAndPrintObject(OBJECT x, FULL_LENGTH xmk, FULL_LENGTH xb,
+ FULL_LENGTH xf, int dim, BOOLEAN suppress, FULL_LENGTH pg, int count,
+ FULL_LENGTH *actual_back, FULL_LENGTH *actual_fwd)
+ { OBJECT y, link, prev, g, z, face, thr, res, uplink;
+ /* OBJECT fixed_thr, tmp; */
+ FULL_LENGTH mk, ymk, frame_size, back_edge, yb, yf, inc, f;
+ FULL_LENGTH aback, afwd;
+ int i; float scale_factor; BOOLEAN jn;
+ debug8(DGP, DD, "[ FixAndPrintObject(%s %s%s, %s, %s,%s, %s, %s, pg, count)",
+ Image(type(x)),
+ ((type(x) == WORD || type(x) == QWORD) ? string(x) : STR_EMPTY),
+ EchoFilePos(&fpos(x)),
+ EchoLength(xmk), EchoLength(xb), EchoLength(xf),dimen(dim),
+ (suppress == SUPPRESS ? "suppress" : "no_suppress"));
+ debug2(DGP, DD, " size(x) = %s,%s; x =",
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ ifdebug(DGP, DD, DebugObject(x));
+ res = x;
+
+ /*** start and stop debugging
+ if( dim == COLM && is_word(type(x)) &&
+ StringEqual(string(x), AsciiToFull("STARTBUG")) )
+ dbg[DGP].on[DD] = dbg[DGP].on[D] = TRUE;
+ if( dim == COLM && is_word(type(x)) &&
+ StringEqual(string(x), AsciiToFull("STOPBUG")) )
+ dbg[DGP].on[DD] = dbg[DGP].on[D] = FALSE;
+ *** */
+
+
+ switch( type(x) )
+ {
+
+ case CLOSURE:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case CROSS:
+ case FORCE_CROSS:
+
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+
+ CountChild(y, DownDim(x, dim), count);
+ if( type(y) == HSPANNER || type(y) == VSPANNER )
+ {
+ Child(z, Down(y));
+ Parent(thr, UpDim(x, dim));
+ save_mark(y) = xmk - back(thr, dim) + back(z, dim);
+
+ /* do the fix now if the first column is also the last one */
+ debug2(DGP, DD, " pre-inc spanner_fixed(y) = %d, spanner_count(y) = %d",
+ spanner_fixed(y), spanner_count(y));
+ if( ++spanner_fixed(y) == spanner_count(y) )
+ {
+ debug6(DGP, DD, " f+last SPAN: yf = max(%s + %s - %s, %s, %s - %s)",
+ EchoLength(xmk), EchoLength(xf), EchoLength(save_mark(y)),
+ EchoLength(fwd(z, dim)),
+ EchoLength(bfc(constraint(y))), EchoLength(back(z, dim)));
+ yf = find_max(xmk + xf - save_mark(y), fwd(z, dim));
+ yf = find_max(yf, bfc(constraint(y)) - back(z, dim));
+ z = FixAndPrintObject(z, save_mark(y), back(z, dim), yf, dim,
+ FALSE, pg, 1, &aback, &afwd);
+ spanner_fixed(y) = 0; /* restart for if printed again */
+ }
+ *actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
+ }
+ else
+ {
+ debug6(DGP, DD, "%s alternate FixAndPrintObject(%s, %s, %s, %s, %s, ..)",
+ Image(type(x)), Image(type(y)), EchoLength(xmk), EchoLength(xb),
+ EchoLength(xf), dimen(dim));
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ actual_back, actual_fwd);
+ }
+ break;
+
+
+ case HSPAN:
+ case VSPAN:
+
+ /* do the fix on the last one */
+ if( (dim == COLM) == (type(x) == HSPAN) )
+ {
+ CountChild(y, DownDim(x, dim), count);
+ assert(type(y) == HSPANNER || type(y) == VSPANNER, "FAPO HSPAN/VSPAN!");
+ debug2(DGP, DD, " pre-inc spanner_fixed(y) = %d, spanner_count(y) = %d",
+ spanner_fixed(y), spanner_count(y));
+ if( ++spanner_fixed(y) == spanner_count(y) )
+ {
+ Child(z, Down(y));
+ debug6(DGP, DD, " last SPAN: yf = max(%s + %s - %s, %s, %s - %s)",
+ EchoLength(xmk), EchoLength(xf), EchoLength(save_mark(y)),
+ EchoLength(fwd(z, dim)),
+ EchoLength(bfc(constraint(y))), EchoLength(back(z, dim)));
+ yf = find_max(xmk + xf - save_mark(y), fwd(z, dim));
+ yf = find_max(yf, bfc(constraint(y)) - back(z, dim));
+ z = FixAndPrintObject(z, save_mark(y), back(z, dim), yf, dim,
+ FALSE, pg, 1, &aback, &afwd);
+ *actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
+ spanner_fixed(y) = 0; /* restart for if printed again */
+ }
+ }
+ break;
+
+
+ case WORD:
+ case QWORD:
+
+ if( dim == COLM )
+ {
+ /* save horizontal position for PrintWord below */
+ word_save_mark(x) = xmk;
+
+ /* if first occurrence of this font on this page, notify font */
+ if( string(x)[0] != '\0' )
+ { face = finfo[word_font(x)].original_face;
+ if( font_page(face) < font_curr_page )
+ { debug3(DFT, DD, "FAPO: x = %s, word_font = %d, face = %s",
+ string(x), word_font(x), EchoObject(face));
+ FontPageUsed(face);
+ }
+ }
+ }
+ else
+ {
+ if( string(x)[0] != '\0' )
+ { BackEnd->PrintWord(x, word_save_mark(x), pg - xmk);
+ /* NB if this word is to be underlined, it will be already enclosed
+ in an ACAT by Manifest, and that ACAT will do the underlining */
+ }
+ }
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case WIDE:
+ case HIGH:
+
+ CountChild(y, Down(x), count);
+ if( (dim == COLM) == (type(x) == WIDE) )
+ { yf = bfc(constraint(x)) - back(y, dim);
+ y = FixAndPrintObject(y, xmk, back(y,dim), yf, dim, NO_SUPPRESS, pg,
+ count, &aback, &afwd);
+ *actual_back = xb; *actual_fwd = xf;
+ }
+ else
+ { y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ actual_back, actual_fwd);
+ }
+ break;
+
+
+ case HSHIFT:
+ case VSHIFT:
+
+ CountChild(y, Down(x), count);
+ if( (dim == COLM) == (type(x) == HSHIFT) )
+ {
+ /* work out the size of the shift depending on the units */
+ f = FindShift(x, y, dim);
+ ymk = xmk - f;
+ yb = find_max(0, xb - f);
+ yf = find_max(0, xf + f);
+ y = FixAndPrintObject(y, ymk, yb, yf, dim, suppress, pg, count,
+ &aback, &afwd);
+
+ /* recalculate the size of x as in MinSize */
+ f = FindShift(x, y, dim);
+ *actual_back = find_min(MAX_FULL_LENGTH, find_max(0, aback + f));
+ *actual_fwd = find_min(MAX_FULL_LENGTH, find_max(0, afwd - f));
+ }
+ else
+ { y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ actual_back, actual_fwd);
+ }
+ break;
+
+
+ case HCONTRACT:
+ case VCONTRACT:
+
+ CountChild(y, Down(x), count);
+ if( (dim == COLM) == (type(x) == HCONTRACT) )
+ { y = FixAndPrintObject(y, xmk, back(y,dim), fwd(y,dim), dim,
+ NO_SUPPRESS, pg, count, &aback, &afwd);
+ *actual_back = xb; *actual_fwd = xf;
+ }
+ else
+ { y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ actual_back, actual_fwd);
+ }
+ break;
+
+
+ case ONE_COL:
+ case ONE_ROW:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+
+ CountChild(y, Down(x), count);
+ if( (dim == COLM) == (type(x) == ONE_COL || type(x) == HEXPAND) )
+ { y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
+ &aback, &afwd);
+ *actual_back = xb; *actual_fwd = xf;
+ }
+ else
+ { y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ actual_back, actual_fwd);
+ }
+ break;
+
+
+ case VSCALE:
+
+ debug0(DRS, DD, "FixAndPrintObject at VSCALE");
+ CountChild(y, Down(x), count);
+ if( BackEnd->scale_avail )
+ {
+ if( dim == COLM )
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
+ &aback, &afwd);
+ else if( (scale_factor = ScaleFactor(xb+xf, size(y, ROWM))) > 0 )
+ { BackEnd->SaveGraphicState(y);
+ BackEnd->CoordTranslate(0,
+ pg - (xmk - xb + (FULL_LENGTH) (back(y, ROWM) * scale_factor)));
+ BackEnd->CoordScale(1.0, scale_factor);
+ y = FixAndPrintObject(y, 0, back(y,ROWM), fwd(y,ROWM), dim,
+ NO_SUPPRESS, 0, count, &aback, &afwd);
+ BackEnd->RestoreGraphicState();
+ }
+ else if( !is_word(type(y)) || string(y)[0] != '\0' )
+ Error(23, 1, "object deleted (it cannot be scaled vertically)",
+ WARN, &fpos(x));
+ }
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case HSCALE:
+
+ debug0(DRS, DD, "FixAndPrintObject at HSCALE");
+ CountChild(y, Down(x), count);
+ if( BackEnd->scale_avail )
+ { if( dim == COLM )
+ { save_mark(x) = xmk;
+ bc(constraint(x)) = xb;
+ fc(constraint(x)) = xf;
+ if( (scale_factor = ScaleFactor(xb+xf, size(y, COLM))) > 0 )
+ y = FixAndPrintObject(y, 0, back(y, COLM), fwd(y, COLM), dim,
+ NO_SUPPRESS, pg, count, &aback, &afwd);
+ else if( !is_word(type(y)) || string(y)[0] != '\0' )
+ Error(23, 2, "object deleted (it cannot be scaled horizontally)",
+ WARN, &fpos(y));
+ }
+ else if( (scale_factor =
+ ScaleFactor(bc(constraint(x))+fc(constraint(x)),size(y,COLM))) > 0 )
+ { BackEnd->SaveGraphicState(y);
+ BackEnd->CoordTranslate(save_mark(x) - bc(constraint(x))
+ + (FULL_LENGTH) (back(y, COLM)*scale_factor), 0);
+ BackEnd->CoordScale(scale_factor, 1.0);
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
+ &aback, &afwd);
+ BackEnd->RestoreGraphicState();
+ }
+ }
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case SCALE:
+
+ CountChild(y, Down(x), count);
+ if( BackEnd->scale_avail )
+ {
+ if( dim == COLM )
+ { assert( bc(constraint(x)) > 0, "FAPO: horizontal scale factor!" );
+ save_mark(x) = xmk;
+ yb = xb * SF / bc(constraint(x));
+ yf = xf * SF / bc(constraint(x));
+ y = FixAndPrintObject(y, 0, yb, yf, dim, NO_SUPPRESS, pg, count,
+ &aback, &afwd);
+ }
+ else
+ { assert( fc(constraint(x)) > 0, "FAPO: vertical scale factor!" );
+ yb = xb * SF / fc(constraint(x));
+ yf = xf * SF / fc(constraint(x));
+ BackEnd->SaveGraphicState(y);
+ BackEnd->CoordTranslate(save_mark(x), pg - xmk);
+ BackEnd->CoordScale( (float)bc(constraint(x))/SF,
+ (float)fc(constraint(x))/SF);
+ y = FixAndPrintObject(y, 0, yb, yf, dim, NO_SUPPRESS, 0, count,
+ &aback, &afwd);
+ BackEnd->RestoreGraphicState();
+ }
+ }
+ else if( bc(constraint(x)) == SF && fc(constraint(x)) == SF )
+ {
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ &aback, &afwd);
+ }
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case KERN_SHRINK:
+
+ CountChild(y, LastDown(x), count);
+ if( dim == COLM )
+ { y = FixAndPrintObject(y, xmk, back(y,dim), fwd(y,dim), dim,
+ NO_SUPPRESS, pg, count, &aback, &afwd);
+ *actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
+ }
+ else
+ { y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ actual_back, actual_fwd);
+ }
+ break;
+
+
+ case BACKGROUND:
+
+ /* this object has the size of its second child; but its first */
+ /* child gets printed too, in the same space */
+ CountChild(y, Down(x), count);
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ &aback, &afwd);
+ CountChild(y, LastDown(x), count);
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ &aback, &afwd);
+ *actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
+ break;
+
+
+ case ROTATE:
+
+ CountChild(y, Down(x), count);
+ if( BackEnd->rotate_avail )
+ {
+ if( dim == COLM )
+ { CONSTRAINT colc, rowc, yc;
+ save_mark(x) = xmk;
+ SetConstraint(colc, back(x,COLM), MAX_FULL_LENGTH, fwd(x,COLM));
+ SetConstraint(rowc, back(x,ROWM), MAX_FULL_LENGTH, fwd(x,ROWM));
+ RotateConstraint(&yc, y, sparec(constraint(x)), &colc, &rowc,COLM);
+ y = FixAndPrintObject(y, 0, bc(yc), fc(yc), COLM, NO_SUPPRESS, pg,
+ count, &aback, &afwd);
+ }
+ else
+ { CONSTRAINT colc, rowc, yc;
+ BackEnd->SaveGraphicState(y);
+ BackEnd->CoordTranslate(save_mark(x), pg - xmk);
+ BackEnd->CoordRotate(sparec(constraint(x)));
+ SetConstraint(colc, back(x,COLM), MAX_FULL_LENGTH, fwd(x,COLM));
+ SetConstraint(rowc, back(x,ROWM), MAX_FULL_LENGTH, fwd(x,ROWM));
+ RotateConstraint(&yc, y, sparec(constraint(x)), &colc, &rowc, ROWM);
+ y = FixAndPrintObject(y, 0, bc(yc), fc(yc), ROWM, NO_SUPPRESS, 0,
+ count, &aback, &afwd);
+ BackEnd->RestoreGraphicState();
+ }
+ }
+ else if( sparec(constraint(x)) == 0 )
+ y = FixAndPrintObject(y,xmk,xb,xf,dim,suppress,pg,count,&aback,&afwd);
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case PLAIN_GRAPHIC:
+
+ CountChild(y, LastDown(x), count);
+ if( BackEnd->plaingraphic_avail )
+ {
+ if( dim == COLM )
+ {
+ back(x, dim) = xb; /* NB state change here */
+ fwd(x, dim) = xf;
+ save_mark(x) = xmk - back(x, dim);
+ debug2(DGP, DD, "PLAIN_GRAPHIC COLM storing size %s, %s",
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ &aback, &afwd);
+ }
+ else
+ { OBJECT tmp, pre, post;
+ Child(tmp, Down(x));
+ if( type(tmp) == VCAT )
+ { Child(pre, Down(tmp));
+ Child(post, LastDown(tmp));
+ }
+ else pre = tmp, post = nilobj;
+ back(x, dim) = xb;
+ fwd(x, dim) = xf;
+ BackEnd->PrintPlainGraphic(pre, save_mark(x),
+ pg - (xmk - back(x, dim)), x);
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
+ &aback, &afwd);
+ if( post != nilobj )
+ BackEnd->PrintPlainGraphic(post, save_mark(x),
+ pg - (xmk - back(x, dim)), x);
+ }
+ }
+ else
+ y = FixAndPrintObject(y, xmk,xb,xf,dim,suppress,pg,count,&aback,&afwd);
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case GRAPHIC:
+
+ CountChild(y, LastDown(x), count);
+ if( BackEnd->graphic_avail )
+ {
+ if( dim == COLM )
+ {
+ /* if first occurrence of this font on this page, notify font */
+ if( font(save_style(x)) > 0 )
+ { face = finfo[font(save_style(x))].original_face;
+ if( font_page(face) < font_curr_page ) FontPageUsed(face);
+ }
+
+ back(x, dim) = xb; /* NB state change here */
+ fwd(x, dim) = xf;
+ debug2(DGP, DD, "GRAPHIC COLM storing size %s, %s",
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
+ save_mark(x) = xmk - back(x, COLM);
+ y = FixAndPrintObject(y, xb, xb, xf, dim, NO_SUPPRESS, pg, count,
+ &aback, &afwd);
+ }
+ else
+ { OBJECT tmp, pre, post;
+ Child(tmp, Down(x));
+ if( type(tmp) == VCAT )
+ { Child(pre, Down(tmp));
+ Child(post, LastDown(tmp));
+ }
+ else pre = tmp, post = nilobj;
+ back(x, dim) = xb;
+ fwd(x, dim) = xf;
+
+ BackEnd->SaveTranslateDefineSave(x, save_mark(x),
+ pg - (xmk + fwd(x, ROWM)));
+ BackEnd->PrintGraphicObject(pre);
+ BackEnd->RestoreGraphicState();
+ y = FixAndPrintObject(y, xb, xb, xf, dim, NO_SUPPRESS, xb + xf,
+ count, &aback, &afwd);
+ if( post != nilobj ) BackEnd->PrintGraphicObject(post);
+ BackEnd->RestoreGraphicState();
+ }
+ }
+ else
+ y = FixAndPrintObject(y, xmk,xb,xf,dim,suppress,pg,count,&aback,&afwd);
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case LINK_SOURCE:
+ case LINK_DEST:
+
+ CountChild(y, LastDown(x), count);
+ if( dim == COLM )
+ save_mark(x) = xmk;
+ else
+ { Child(z, Down(x));
+ if( type(x) == LINK_SOURCE )
+ BackEnd->LinkSource(z, save_mark(x) - back(x, COLM),
+ (pg - xmk) - xf, save_mark(x) + fwd(x, COLM),
+ (pg - xmk) + xb);
+ else
+ BackEnd->LinkDest(z, save_mark(x) - back(x, COLM),
+ (pg - xmk) - xf, save_mark(x) + fwd(x, COLM),
+ (pg - xmk) + xb);
+ }
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
+ &aback, &afwd);
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+
+ CountChild(y, Down(x), count);
+ if( BackEnd->incgraphic_avail )
+ {
+ if( dim == COLM )
+ { save_mark(x) = xmk;
+ if( incgraphic_ok(x) )
+ { debug2(DGP, DD, " %s (style %s)",
+ EchoObject(x), EchoStyle(&save_style(x)));
+ face = finfo[font(save_style(x))].original_face;
+ if( font_page(face) < font_curr_page )
+ { debug3(DFT, DD, "FAPO-IG: x = %s, font = %d, face = %s",
+ string(x), font(save_style(x)), EchoObject(face));
+ FontPageUsed(face);
+ }
+ }
+ }
+ else if( incgraphic_ok(x) )
+ BackEnd->PrintGraphicInclude(x, save_mark(x), pg - xmk);
+ }
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case SPLIT:
+
+ link = DownDim(x, dim); CountChild(y, link, count);
+ y = FixAndPrintObject(y, xmk, find_max(back(y, dim), xb),
+ find_max(fwd(y, dim), xf), dim, suppress, pg, count,
+ actual_back, actual_fwd);
+ break;
+
+
+ case VCAT:
+ case HCAT:
+
+ if( (type(x) == VCAT) == (dim == ROWM) )
+ {
+ debug6(DGP, DD, "[ FAPO-CAT %s (%s,%s): xmk %s, xb %s, xf %s",
+ Image(type(x)), EchoLength(back(x, dim)), EchoLength(fwd(x, dim)),
+ EchoLength(xmk), EchoLength(xb), EchoLength(xf));
+
+ FirstDefinite(x, link, prev, jn);
+ if( link != x )
+ {
+
+ /*******************************************************************/
+ /* */
+ /* handle the special case of a 0rt gap at the beginning (left */
+ /* justify) by converting it to 0ie but increasing fwd(prev) to */
+ /* the maximum possible */
+ /* */
+ /*******************************************************************/
+
+ NextDefiniteWithGap(x, link, y, g, jn);
+ if( link != x && mode(gap(g)) == TAB_MODE &&
+ units(gap(g)) == AVAIL_UNIT && width(gap(g)) == 0 )
+ {
+ debug2(DGP, DD, " FAPO-CAT converting 0rt (back(x, dim) %s, xb %s)",
+ EchoLength(back(x, dim)), EchoLength(xb));
+ /* NB state change here */
+ fwd(prev, dim) += xb - back(x, dim);
+ back(x, dim) = xb;
+ mode(gap(g)) = EDGE_MODE;
+ units(gap(g)) = FIXED_UNIT;
+ }
+ FirstDefinite(x, link, prev, jn);
+
+ /*******************************************************************/
+ /* */
+ /* Initialize the following variables: */
+ /* */
+ /* frame_size the total width actually available */
+ /* */
+ /* back_edge where the first element begins */
+ /* */
+ /* inc the adjust increment, used when adjusting gaps */
+ /* */
+ /* mk where the mark of prev is to go */
+ /* */
+ /*******************************************************************/
+
+ frame_size = back(x, dim) + xf;
+ back_edge = xmk - back(x, dim);
+ if( adjust_cat(x) && !suppress )
+ inc = FindAdjustIncrement(x, frame_size, dim);
+ else inc = 0;
+ mk = back_edge + back(prev, dim);
+ debug4(DGP, DD, " FAPO-CAT back_edge %s, mk %s, frame %s, inc %s",
+ EchoLength(back_edge), EchoLength(mk), EchoLength(frame_size),
+ EchoLength(inc));
+
+ /*******************************************************************/
+ /* */
+ /* Fix each element "prev" in turn along the cat operator */
+ /* */
+ /*******************************************************************/
+
+ NextDefiniteWithGap(x, link, y, g, jn);
+ while( link != x )
+ {
+ if( mode(gap(g)) == TAB_MODE && units(gap(g)) == AVAIL_UNIT &&
+ width(gap(g))==FR )
+ {
+ /* object is followed by 1rt gap, give it full space to print */
+ debug5(DGP,D," FAPO (a) calling FAPO(%s, %s, %s, max(%s, %s))",
+ Image(type(prev)), EchoLength(mk), EchoLength(back(prev, dim)),
+ EchoLength(fwd(prev, dim)), EchoLength(xmk+xf-mk-size(y,dim)));
+ prev = FixAndPrintObject(prev, mk, back(prev, dim),
+ find_max(fwd(prev, dim), xmk+xf-mk - size(y, dim)),
+ dim, NO_SUPPRESS, pg, count, &aback, &afwd);
+ }
+ else
+ {
+ debug5(DGP, DD, " FAPO-CAT (b) calling FAPO(%s, %s, %s, %s+%s)",
+ Image(type(prev)), EchoLength(mk), EchoLength(back(prev, dim)),
+ EchoLength(fwd(prev, dim)), EchoLength(inc));
+ prev = FixAndPrintObject(prev, mk, back(prev, dim),
+ fwd(prev, dim) + inc, dim, NO_SUPPRESS, pg, count,&aback,&afwd);
+ }
+ mk += ActualGap(afwd, back(y, dim), fwd(y, dim), &gap(g),
+ frame_size, mk - back_edge);
+ prev = y;
+ NextDefiniteWithGap(x, link, y, g, jn);
+ }
+
+ /*******************************************************************/
+ /* */
+ /* At end, fix last element in conformity with "suppress" */
+ /* and set *actual_back and *actual_fwd. */
+ /* */
+ /*******************************************************************/
+
+ if( suppress )
+ {
+ debug4(DGP, DD, " FAPO-CAT (c) calling FAPO(%s, %s, %s, %s)",
+ Image(type(prev)), EchoLength(mk), EchoLength(back(prev, dim)),
+ EchoLength(fwd(prev, dim)));
+ prev = FixAndPrintObject(prev, mk, back(prev, dim), fwd(prev, dim),
+ dim, NO_SUPPRESS, pg, count, &aback, &afwd);
+ }
+ else
+ {
+ debug5(DGP, DD," FAPO-CAT (d) calls FAPO(%s, %s, %s, max(%s, %s))",
+ Image(type(prev)), EchoLength(mk), EchoLength(back(prev, dim)),
+ EchoLength(fwd(prev, dim)), EchoLength(xmk + xf - mk));
+ ifdebug(DGP, DD, DebugObject(prev));
+ prev = FixAndPrintObject(prev, mk, back(prev,dim),
+ find_max(fwd(prev, dim), xmk + xf - mk),
+ dim, NO_SUPPRESS, pg, count, &aback, &afwd);
+ }
+ *actual_back = find_max(back(x, dim), xb);
+ *actual_fwd = mk + fwd(prev, dim) - back_edge - *actual_back;
+ debugcond4(DGP, DD, type(x) == HCAT,
+ "HCAT original (%s, %s) to actual (%s, %s)",
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)),
+ EchoLength(*actual_back), EchoLength(*actual_fwd));
+ }
+ else *actual_back = xb, *actual_fwd = xf;
+ debug0(DGP, DD, "] FAPO-CAT returning.");
+ }
+ else
+ { OBJECT start_group, zlink, m; BOOLEAN dble_found;
+ FULL_LENGTH b, f, dlen;
+ start_group = nilobj; dble_found = FALSE; dlen = 0;
+ debug0(DGP, DD, " groups beginning.");
+ FirstDefinite(x, link, y, jn);
+ if( link != x )
+ {
+ /* start first group, with or without join */
+ b = back(y, dim);
+ f = fwd(y, dim);
+ m = y;
+ start_group = link;
+ dble_found = !jn;
+ debug4(DGP, DD, " starting first group %s (%sdbl_found): b %s, f %s",
+ Image(type(y)), dble_found ? "" : "not ",
+ EchoLength(b), EchoLength(f));
+
+ NextDefiniteWithGap(x, link, y, g, jn);
+ while( link != x )
+ {
+ if( !jn )
+ {
+ /* finish off and fix the group ending just before g */
+ debug2(DGP, DD, " finishing group: b = %s, f = %s",
+ EchoLength(b), EchoLength(f));
+ m = FixAndPrintObject(m, xmk+b, b, xf-b, dim,
+ NO_SUPPRESS, pg, count, &aback, &afwd);
+ b = back(m, dim); f = fwd(m, dim);
+ for( zlink = start_group; zlink != link; zlink=NextDown(zlink) )
+ { CountChild(z, zlink, count);
+ if( !is_definite(type(z)) || z == m ) continue;
+ z = FixAndPrintObject(z, xmk + b, b, xf - b, dim,
+ SUPPRESS, pg, count, &aback, &afwd);
+ b = find_max(b, back(z, dim)); f = find_max(f, fwd(z, dim));
+ }
+ dlen = find_max(dlen, b + f);
+ dble_found = TRUE;
+ start_group = nilobj;
+
+ /* start new group */
+ b = back(y, dim);
+ f = fwd(y, dim);
+ m = y;
+ start_group = link;
+ debug2(DGP, DD, " starting group: b = %s, f = %s",
+ EchoLength(b), EchoLength(f));
+ }
+ else
+ {
+ /* continue with current group */
+ b = find_max(b, back(y, dim));
+ f = find_max(f, fwd(y, dim));
+ if( fwd(y, dim) > fwd(m, dim) ) m = y;
+ debug2(DGP, DD, " continuing group: b = %s, f = %s",
+ EchoLength(b), EchoLength(f));
+ }
+
+ NextDefiniteWithGap(x, link, y, g, jn);
+ }
+ assert( start_group != nilobj, "FAPO: final start_group!" );
+
+ if( dble_found || !jn )
+ {
+ /* finish off and fix this last group */
+ debug2(DGP, DD, " finishing last group: b = %s, f = %s",
+ EchoLength(b), EchoLength(f));
+ m = FixAndPrintObject(m, xmk+b, b, xf - b, dim, NO_SUPPRESS, pg,
+ count, &aback, &afwd);
+ b = back(m, dim); f = fwd(m, dim);
+ for( zlink = start_group; zlink != x; zlink = NextDown(zlink) )
+ { CountChild(z, zlink, count);
+ if( !is_definite(type(z)) || z == m ) continue;
+ z = FixAndPrintObject(z, xmk+b, b, xf - b, dim, SUPPRESS, pg,
+ count, &aback, &afwd);
+ b = find_max(b, back(z, dim)); f = find_max(f, fwd(z, dim));
+ }
+ dlen = find_max(dlen, b + f);
+ *actual_back = 0; *actual_fwd = dlen;
+ }
+ else
+ {
+ /* finish off and fix this last and only group */
+ debug2(DGP, DD, " finishing last and only group: b = %s, f = %s",
+ EchoLength(b), EchoLength(f));
+ m = FixAndPrintObject(m, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
+ &b, &f);
+ for( zlink = start_group; zlink != x; zlink = NextDown(zlink) )
+ { CountChild(z, zlink, count);
+ if( !is_definite(type(z)) || z == m ) continue;
+ z = FixAndPrintObject(z, xmk, xb, xf, dim, SUPPRESS, pg, count,
+ &aback, &afwd);
+ b = find_max(b, aback); f = find_max(f, afwd);
+ }
+ *actual_back = b; *actual_fwd = f;
+ }
+ }
+ }
+ break;
+
+
+ case ACAT:
+
+ if( dim == COLM )
+ { BOOLEAN will_adjust, adjusting;
+ FULL_LENGTH actual_size,
+ adjust_indent, frame_size, back_edge, adjust_inc, inc, adjust_sofar;
+ int adjustable_gaps, gaps_sofar;
+ BOOLEAN underlining; int underline_xstart;
+ FONT_NUM underline_font; COLOUR_NUM underline_colour;
+ OBJECT urec, last_bad_gap;
+
+
+ /*********************************************************************/
+ /* */
+ /* The first step is to calculate the following values: */
+ /* */
+ /* last_bad_gap The rightmost tab gap, or nilobj if none; */
+ /* */
+ /* adjustable_gaps the number of gaps suitable for adjustment; */
+ /* i.e. to the right of the right-most tab gap, */
+ /* and of non-zero width; */
+ /* */
+ /* actual_size the actual size of x without adjustment. */
+ /* */
+ /* These are needed when adjusting the line. */
+ /* */
+ /*********************************************************************/
+
+ FirstDefinite(x, link, y, jn);
+ if( link == x )
+ {
+ *actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
+ break; /* no definite children, nothing to print */
+ }
+
+ /*** nasty bug finder
+ { OBJECT ff = y;
+ debugcond1(DGP, DD, word_equal(ff, "@ReportLayout"),
+ "FAPO(%s, COLM)", EchoObject(x));
+ debugcond1(DGP, DD, word_equal(ff, "@ReportLayout"),
+ " adjust_cat(x) = %s", bool(adjust_cat(x)));
+ }
+ ***/
+
+ last_bad_gap = nilobj;
+ adjustable_gaps = 0;
+ back_edge = xmk - xb;
+ mk = back_edge + back(y, dim);
+ frame_size = xb + xf;
+ prev = y;
+ NextDefiniteWithGap(x, link, y, g, jn);
+ while( link != x )
+ {
+ save_actual_gap(g) = ActualGap(fwd(prev, dim), back(y, dim),
+ fwd(y, dim), &gap(g), frame_size, mk - back_edge);
+ mk += save_actual_gap(g);
+ if( mode(gap(g)) == TAB_MODE || units(gap(g)) == AVAIL_UNIT
+ || units(gap(g)) == FRAME_UNIT )
+ { last_bad_gap = g;
+ adjustable_gaps = 0;
+ }
+ else if( width(gap(g)) > 0 ) adjustable_gaps++;
+ prev = y;
+ NextDefiniteWithGap(x, link, y, g, jn);
+ }
+ actual_size = mk + fwd(prev, dim) - back_edge;
+
+ /*********************************************************************/
+ /* */
+ /* It is possible that the line cannot be displayed in any */
+ /* reasonable way, because the paragraph breaker was forced to */
+ /* produce an overfull line. In this case, actual_size will */
+ /* exceed frame_size and there will be no adjustable gaps. The */
+ /* solution is to horizontally scale the line if possible, or */
+ /* else to not print it at all. */
+ /* */
+ /*********************************************************************/
+
+ if( actual_size > frame_size && adjustable_gaps == 0 )
+ {
+ /* can't be fixed by adjustment, so scale the line or delete it */
+ CONSTRAINT c;
+ SetConstraint(c, 0, frame_size, frame_size);
+ fwd(x, dim) = actual_size;
+ debug2(DGP, DD, " oversize, actual_size = %s, frame_size = %s",
+ EchoLength(actual_size), EchoLength(frame_size));
+ if( BackEnd->scale_avail && InsertScale(x, &c) )
+ {
+ /* the problem has just been fixed, by inserting a @Scale above x */
+ OBJECT prnt;
+ Parent(prnt, Up(x));
+ Child(y, Down(x));
+ if( actual_size - frame_size < 1 * PT )
+ {
+ /* the correction is probably due to roundoff error, and */
+ /* anyway is too small to print an error message about */
+ }
+ else if( Down(x) == LastDown(x) && is_word(type(y)) )
+ {
+ Error(23, 3, "word %s horizontally scaled by factor %.2f (too wide for %s paragraph)",
+ WARN, &fpos(y), string(y), (float) bc(constraint(prnt)) / SF,
+ EchoLength(frame_size));
+ }
+ else
+ {
+ Error(23, 4, "%s object horizontally scaled by factor %.2f (too wide for %s paragraph)",
+ WARN, &fpos(x), EchoLength(size(x, COLM)),
+ (float) bc(constraint(prnt)) / SF, EchoLength(frame_size));
+ }
+ prnt = FixAndPrintObject(prnt, xmk, back(prnt, dim), fwd(prnt, dim), dim,
+ NO_SUPPRESS, pg, count, &aback, &afwd);
+ }
+ else
+ {
+ /* fix the problem by refraining from printing the line */
+ if( size(x, COLM) <= 0 )
+ Error(23, 5, "oversize object has size 0 or less", INTERN, &fpos(x));
+ Child(y, Down(x));
+ if( Down(x) == LastDown(x) && is_word(type(y)) )
+ { Error(23, 6, "word %s deleted (too wide for %s paragraph)",
+ WARN, &fpos(y), string(y), EchoLength(frame_size));
+ }
+ else
+ { Error(23, 7, "%s object deleted (too wide for %s paragraph)",
+ WARN, &fpos(x), EchoLength(size(x, COLM)), EchoLength(frame_size));
+ }
+
+ /* delete and dispose every child of x */
+ while( Down(x) != x )
+ DisposeChild(Down(x));
+ y = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ Link(x, y);
+ back(y, COLM) = fwd(y, COLM) = 0;
+ back(y, ROWM) = fwd(y, ROWM) = 0;
+ }
+ }
+ else
+ {
+
+ /********************************************************************/
+ /* */
+ /* The line may be displayed in one of four ways: centred, right- */
+ /* justified, adjusted, or none of the above (i.e. left justified).*/
+ /* An overfull line is always adjusted; otherwise, the line will */
+ /* be centred or right justified if the display style asks for it; */
+ /* otherwise, the line will be adjusted if adjust_cat(x) == TRUE */
+ /* (i.e. there is an enclosing @PAdjust) or if the display style is*/
+ /* DO_ADJUST (meaning that this line is one of a paragraph set in */
+ /* the adjust or outdent break style, other than the last line); */
+ /* otherwise, the line is left justified. */
+ /* */
+ /* The second step is to decide which of these four cases holds */
+ /* for this line, and to record the decision in these variables: */
+ /* */
+ /* will_adjust TRUE if the adjusted style applies; in this */
+ /* case, variables adjust_inc and inc will be */
+ /* set to the appropriate adjustment value; */
+ /* */
+ /* adjust_indent If centring or right justification applies, */
+ /* the indent to produce this, else zero. */
+ /* */
+ /* NB adjust_inc may be negative, if the optimal paragraph breaker */
+ /* has chosen to shrink some gaps. */
+ /* */
+ /* NB we are assigning to adjust_cat here; is this a problem? */
+ /* */
+ /********************************************************************/
+
+ if( actual_size > frame_size )
+ {
+ assert( adjustable_gaps > 0, "FAPO: adjustable_gaps!" );
+ adjust_cat(x) = TRUE;
+ adjust_indent = 0;
+ }
+ else switch( display_style(save_style(x)) )
+ {
+ case DO_ADJUST: adjust_cat(x) = TRUE;
+ adjust_indent = 0;
+ debug1(DSF, D, "adjust %s", EchoObject(x));
+ break;
+
+ case DISPLAY_CENTRE: adjust_cat(x) = FALSE;
+ adjust_indent = (frame_size - actual_size)/2;
+ debug1(DGP, DD, "cdisp %s", EchoObject(x));
+ break;
+
+ case DISPLAY_RIGHT: adjust_cat(x) = FALSE;
+ adjust_indent = frame_size - actual_size;
+ debug1(DGP, DD, "rdisp %s", EchoObject(x));
+ debug1(DSF, D, "rdisp %s", EchoObject(x));
+ break;
+
+ default: /* leave adjust_cat(x) as is */
+ adjust_indent = 0;
+ break;
+ }
+
+ debug2(DGP, DD, "ACAT %s %s",
+ EchoStyle(&save_style(x)), EchoObject(x));
+ debug2(DGP, DD, "frame_size = %s, actual_size = %s",
+ EchoLength(frame_size), EchoLength(actual_size));
+
+ if( adjust_cat(x) && adjustable_gaps > 0 )
+ { will_adjust = TRUE;
+ adjust_inc = (frame_size - actual_size) / adjustable_gaps;
+ inc = find_max(adjust_inc, 0);
+ gaps_sofar = 0; /* number of gaps adjusted so far */
+ adjust_sofar = 0; /* total width of adjustments so far */
+ debug2(DGP, DD,"will_adjust: adjustable_gaps = %d, adjust_inc = %s",
+ adjustable_gaps, EchoLength(adjust_inc));
+ }
+ else will_adjust = FALSE;
+
+
+ /********************************************************************/
+ /* */
+ /* The third and final step is to traverse x, fixing subobjects. */
+ /* Variable "adjusting" is true while adjusting is occurring. */
+ /* */
+ /********************************************************************/
+
+ underlining = FALSE;
+ adjusting = will_adjust && last_bad_gap == nilobj;
+ FirstDefinite(x, link, y, jn);
+ prev = y;
+ mk = xmk - back(x, dim) + back(y, dim) + adjust_indent;
+ NextDefiniteWithGap(x, link, y, g, jn);
+ while( link != x )
+ {
+ /* check for underlining */
+ if( underline(prev) == UNDER_ON )
+ {
+ debug3(DGP, D, " FAPO/ACAT1 underline() := %s for %s %s",
+ bool(FALSE), Image(type(prev)), EchoObject(prev));
+ if( !underlining )
+ {
+ /* underlining begins here */
+ underlining = TRUE;
+ debug2(DGP, DD, "underlining begins at %s %s",
+ Image(type(prev)), EchoObject(prev));
+ underline_font = is_word(type(prev)) ? word_font(prev) :
+ font(save_style(x));
+ underline_colour = is_word(type(prev)) ? word_colour(prev) :
+ colour(save_style(x));
+ underline_xstart = mk - back(prev, dim);
+ }
+ if( underline(g) == UNDER_OFF )
+ {
+ /* underlining ends here */
+ debug2(DGP, D, "underlining ends at %s %s",
+ Image(type(prev)), EchoObject(prev));
+ New(urec, UNDER_REC);
+ back(urec, COLM) = underline_xstart;
+ fwd(urec, COLM) = mk + fwd(prev, dim);
+ back(urec, ROWM) = underline_font;
+ fwd(urec, ROWM) = underline_colour;
+ underlining = FALSE;
+ Link(Up(prev), urec);
+ }
+ }
+
+ /* fix previous definite now we know it is not the last one */
+ if( adjusting && width(gap(g)) > 0 )
+ { int tmp;
+
+ prev = FixAndPrintObject(prev, mk, back(prev, dim),
+ fwd(prev, dim) + inc, dim, NO_SUPPRESS, pg, count,&aback,&afwd);
+ gaps_sofar++;
+ tmp = ((frame_size - actual_size) * gaps_sofar) / adjustable_gaps;
+ mk += save_actual_gap(g) + (tmp - adjust_sofar);
+ adjust_sofar = tmp;
+ }
+ else
+ {
+ prev = FixAndPrintObject(prev, mk, back(prev, dim), fwd(prev,dim),
+ dim, NO_SUPPRESS, pg, count, &aback, &afwd);
+
+ mk += save_actual_gap(g);
+ }
+ prev = y;
+
+ /* commence adjustment if required */
+ if( !adjusting && will_adjust && g == last_bad_gap )
+ adjusting = TRUE;
+
+ NextDefiniteWithGap(x, link, y, g, jn);
+ }
+
+ /* check for underlining */
+ debugcond3(DGP, DD, underline(prev) == UNDER_UNDEF,
+ " underlining is UNDER_UNDEF in %s: %s %s in para:",
+ EchoFilePos(&fpos(prev)), Image(type(prev)), EchoObject(prev));
+ debugcond1(DGP, DD, underline(prev)==UNDER_UNDEF, "%s",EchoObject(x));
+ assert( underline(prev) == UNDER_OFF || underline(prev) == UNDER_ON,
+ "FixAndPrint: underline(prev)!" );
+ if( underline(prev) == UNDER_ON )
+ {
+ debug3(DGP, D, " FAPO/ACAT1 underline() := %s for %s %s",
+ bool(FALSE), Image(type(prev)), EchoObject(prev));
+ if( !underlining )
+ {
+ /* underlining begins here */
+ debug2(DGP, DD, "underlining begins at %s %s",
+ Image(type(prev)), EchoObject(prev));
+ underlining = TRUE;
+ underline_font = is_word(type(prev)) ? word_font(prev) :
+ font(save_style(x));
+ underline_colour = is_word(type(prev)) ? word_colour(prev) :
+ colour(save_style(x));
+ underline_xstart = mk - back(prev, dim);
+ }
+
+ /* underlining must end here */
+ debug2(DGP, DD, "underlining ends at %s %s",
+ Image(type(prev)), EchoObject(prev));
+ New(urec, UNDER_REC);
+ back(urec, COLM) = underline_xstart;
+ fwd(urec, COLM) = mk + fwd(prev, dim);
+ back(urec, ROWM) = underline_font;
+ fwd(urec, ROWM) = underline_colour;
+ underlining = FALSE;
+ Link(Up(prev), urec);
+ }
+
+ /* fix the last definite subobject, prev, which must exist */
+ prev = FixAndPrintObject(prev, mk, back(prev, dim),
+ frame_size - (mk - xmk) - back(x, dim),
+ dim, NO_SUPPRESS, pg, count, &aback, &afwd);
+
+ }
+ }
+ else for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( !is_definite(type(y)) )
+ {
+ if( type(y) == UNDER_REC ) /* generate an underline now */
+ { BackEnd->PrintUnderline(back(y, ROWM), fwd(y, ROWM), back(y, COLM),
+ fwd(y, COLM), pg - xmk);
+ link = PrevDown(link); /* remove all trace of underlining */
+ DisposeChild(Up(y)); /* in case we print this object again */
+ }
+ continue;
+ }
+ y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
+ &aback, &afwd);
+ }
+ *actual_back = xb; *actual_fwd = xf;
+ break;
+
+
+ case COL_THR:
+ case ROW_THR:
+
+ assert( (type(x) == COL_THR) == (dim == COLM), "FixAndPrintObject: thr!" );
+ for( link = Down(x), uplink = Up(x), i = 1;
+ link != x && uplink != x && i < count;
+ link = NextDown(link), uplink = NextUp(uplink), i++ );
+ assert( link != x && uplink != x, "FixAndPrintObject: link or uplink!" );
+ CountChild(y, link, count);
+ debug7(DGP, DD, " fapo of %s (%s,%s) child %d %s (%s,%s)",
+ Image(type(x)),
+ EchoLength(back(x, dim)), EchoLength(fwd(x, dim)),
+ i, Image(type(y)), EchoLength(back(y, dim)), EchoLength(fwd(y, dim)));
+ MoveLink(uplink, link, CHILD); DeleteLink(link);
+ assert( type(y) != GAP_OBJ, "FAPO: THR!");
+
+ if( thr_state(x) != FINALSIZE )
+ { back(x, dim) = xb; fwd(x, dim) = xf;
+ thr_state(x) = FINALSIZE;
+ }
+
+ y = FixAndPrintObject(y, xmk, back(x, dim), fwd(x, dim), dim,
+ NO_SUPPRESS, pg, count, &aback, &afwd);
+ *actual_back = xb; *actual_fwd = xf;
+ /* if( Up(x) == x ) Dispose(x); */
+ break;
+
+ /* convert everyone to FIXED_COL_THR or FIXED_ROW_THR as appropriate */
+ /* *** old code
+ if( thr_state(x) == FINALSIZE )
+ debug1(DGP, D, "thr_state(%d)", (int) x);
+ assert(thr_state(x) != FINALSIZE, "FAPO/COL_THR: thr_state(x)!");
+ ifdebug(DGP, D,
+ link = Down(x);
+ uplink = Up(x);
+ while( link != x && uplink != x )
+ {
+ Parent(tmp, uplink);
+ debug1(DGP, D, "parnt: %s", EchoObject(tmp));
+ Child(tmp, link);
+ debug1(DGP, D, "child: %s", EchoObject(tmp));
+ link = NextDown(link);
+ uplink = NextUp(uplink);
+ }
+ while( uplink != x )
+ { Parent(tmp, uplink);
+ debug1(DGP, D, "extra parnt: %s", EchoObject(tmp));
+ uplink = NextUp(uplink);
+ }
+ while( link != x )
+ { Child(tmp, link);
+ debug1(DGP, D, "extra child: %s", EchoObject(tmp));
+ link = NextDown(link);
+ }
+ )
+ i = 1; res = nilobj;
+ while( Down(x) != x && Up(x) != x )
+ {
+ New(fixed_thr, type(x) == COL_THR ? FIXED_COL_THR : FIXED_ROW_THR);
+ MoveLink(Up(x), fixed_thr, CHILD);
+ MoveLink(Down(x), fixed_thr, PARENT);
+ back(fixed_thr, dim) = xb;
+ fwd(fixed_thr, dim) = xf;
+ if( count == i )
+ res = fixed_thr;
+ i++;
+ }
+ if( Up(x) != x || Down(x) != x )
+ {
+ debug2(DGP, D, "links problem at %s %d:", Image(type(x)), (int) x);
+ if( Up(x) != x )
+ {
+ Parent(tmp, Up(x));
+ debug1(DGP, D, "first parent is %s", EchoObject(tmp));
+ }
+ if( Down(x) != x )
+ {
+ Child(tmp, Down(x));
+ debug1(DGP, D, "first child is %s", EchoObject(tmp));
+ }
+ }
+ assert( Up(x) == x && Down(x) == x, "FAPO/COL_THR: x links!" );
+ Dispose(x);
+ assert(res != nilobj, "FixAndPrintObject: COL_THR res!");
+ x = res;
+ *** */
+ /* NB NO BREAK! */
+
+
+ /* ***
+ case FIXED_COL_THR:
+ case FIXED_ROW_THR:
+
+ assert( (type(x) == FIXED_COL_THR) == (dim == COLM),
+ "FixAndPrintObject: fixed_thr!" );
+ CountChild(y, Down(x), count);
+ y = FixAndPrintObject(y, xmk, back(x, dim), fwd(x, dim), dim,
+ NO_SUPPRESS, pg, count, &aback, &afwd);
+ *actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
+ break;
+ *** */
+
+
+ case BEGIN_HEADER:
+ case END_HEADER:
+ case SET_HEADER:
+ case CLEAR_HEADER:
+
+ if( dim == COLM )
+ Error(23, 8, "%s symbol ignored (out of place)", WARN, &fpos(x),
+ Image(type(x)));
+ break;
+
+
+ default:
+
+ assert1(FALSE, "FixAndPrintObject:", Image(type(x)));
+ break;
+
+
+ } /* end switch */
+ debug2(DGP, DD, "] FixAndPrintObject returning (actual %s,%s).",
+ EchoLength(*actual_back), EchoLength(*actual_fwd));
+ return res;
+ } /* end FixAndPrintObject */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z24.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z24.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z24.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,123 ----
+ /*@z24.c:Print Service:PrintInit()@*******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* PDF Back End by Vincent Tan, February 1998. */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z24.c */
+ /* MODULE: Print Service */
+ /* EXTERNS: EightBitToPrintForm */
+ /* */
+ /* This module used to be a combined implementation of all the back */
+ /* ends. Now these have been split off into separate files, there is */
+ /* very little left in this module. */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*@::EightBitToPrintForm()@***************************************************/
+ /* */
+ /* char *EightBitToPrintForm[] */
+ /* */
+ /* Given 8-bit character i, returns a string of characters that will be */
+ /* interpreted by PostScript as character i when read within a string. */
+ /* */
+ /* CHAR_OUT==1 Printable ASCII literal, others as escape sequences */
+ /* CHAR_OUT==2 Printable ISO-LATIN-1 literal, others escaped */
+ /* */
+ /*****************************************************************************/
+
+ char *EightBitToPrintForm[] = {
+ #if CHAR_OUT==0
+ "", "\\001", "\\002", "\\003", "\\004", "\\005", "\\006", "\\007",
+ "\\010", "\\011", "\\012", "\\013", "\\014", "\\015", "\\016", "\\017",
+ "\\020", "\\021", "\\022", "\\023", "\\024", "\\025", "\\026", "\\027",
+ "\\030", "\\031", "\\032", "\\033", "\\034", "\\035", "\\036", "\\037",
+ " ", "!", "\"", "#", "$", "%", "&", "'",
+ "\\(", "\\)", "*", "+", ",", "-", ".", "/",
+ "0", "1", "2", "3", "4", "5", "6", "7",
+ "8", "9", ":", ";", "<", "=", ">", "?",
+ "@", "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", "[", "\\\\", "]", "^", "_",
+ "`", "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", "{", "|", "}", "~", "\\177",
+ "\\200", "\\201", "\\202", "\\203", "\\204", "\\205", "\\206", "\\207",
+ "\\210", "\\211", "\\212", "\\213", "\\214", "\\215", "\\216", "\\217",
+ "\\220", "\\221", "\\222", "\\223", "\\224", "\\225", "\\226", "\\227",
+ "\\230", "\\231", "\\232", "\\233", "\\234", "\\235", "\\236", "\\237",
+ "\\240", "\\241", "\\242", "\\243", "\\244", "\\245", "\\246", "\\247",
+ "\\250", "\\251", "\\252", "\\253", "\\254", "\\255", "\\256", "\\257",
+ "\\260", "\\261", "\\262", "\\263", "\\264", "\\265", "\\266", "\\267",
+ "\\270", "\\271", "\\272", "\\273", "\\274", "\\275", "\\276", "\\277",
+ "\\300", "\\301", "\\302", "\\303", "\\304", "\\305", "\\306", "\\307",
+ "\\310", "\\311", "\\312", "\\313", "\\314", "\\315", "\\316", "\\317",
+ "\\320", "\\321", "\\322", "\\323", "\\324", "\\325", "\\326", "\\327",
+ "\\330", "\\331", "\\332", "\\333", "\\334", "\\335", "\\336", "\\337",
+ "\\340", "\\341", "\\342", "\\343", "\\344", "\\345", "\\346", "\\347",
+ "\\350", "\\351", "\\352", "\\353", "\\354", "\\355", "\\356", "\\357",
+ "\\360", "\\361", "\\362", "\\363", "\\364", "\\365", "\\366", "\\367",
+ "\\370", "\\371", "\\372", "\\373", "\\374", "\\375", "\\376", "\\377"
+ #else
+ #if CHAR_OUT==1
+ "", "\\001", "\\002", "\\003", "\\004", "\\005", "\\006", "\\007",
+ "\\010", "\\011", "\\012", "\\013", "\\014", "\\015", "\\016", "\\017",
+ "\\020", "\\021", "\\022", "\\023", "\\024", "\\025", "\\026", "\\027",
+ "\\030", "\\031", "\\032", "\\033", "\\034", "\\035", "\\036", "\\037",
+ " ", "!", "\"", "#", "$", "%", "&", "'",
+ "\\(", "\\)", "*", "+", ",", "-", ".", "/",
+ "0", "1", "2", "3", "4", "5", "6", "7",
+ "8", "9", ":", ";", "<", "=", ">", "?",
+ "@", "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", "[", "\\\\", "]", "^", "_",
+ "`", "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", "{", "|", "}", "~", "\\177",
+ "\\200", "\\201", "\\202", "\\203", "\\204", "\\205", "\\206", "\\207",
+ "\\210", "\\211", "\\212", "\\213", "\\214", "\\215", "\\216", "\\217",
+ "\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227",
+ "\230", "\\231", "\232", "\233", "\\234", "\235", "\236", "\237",
+ "\240", "\241", "\242", "\243", "\244", "\245", "\246", "\247",
+ "\250", "\251", "\252", "\253", "\254", "\255", "\256", "\257",
+ "\260", "\261", "\262", "\263", "\264", "\265", "\266", "\267",
+ "\270", "\271", "\272", "\273", "\274", "\275", "\276", "\277",
+ "\300", "\301", "\302", "\303", "\304", "\305", "\306", "\307",
+ "\310", "\311", "\312", "\313", "\314", "\315", "\316", "\317",
+ "\320", "\321", "\322", "\323", "\324", "\325", "\326", "\327",
+ "\330", "\331", "\332", "\333", "\334", "\335", "\336", "\337",
+ "\340", "\341", "\342", "\343", "\344", "\345", "\346", "\347",
+ "\350", "\351", "\352", "\353", "\354", "\355", "\356", "\357",
+ "\360", "\361", "\362", "\363", "\364", "\365", "\366", "\367",
+ "\370", "\371", "\372", "\373", "\374", "\375", "\376", "\377"
+ #else
+ If you are trying to compile this you have the wrong CHAR_OUT value!
+ #endif
+ #endif
+ };
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z25.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z25.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z25.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1028 ----
+ /*@z25.c:Object Echo:aprint(), cprint(), printnum()@**************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z25.c */
+ /* MODULE: Object Echo */
+ /* EXTERNS: EchoObject(), DebugObject() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #if DEBUG_ON
+
+ static int limit; /* column where newline is needed */
+ static int indent; /* current indent */
+ static int col; /* current output column */
+ static FILE *fp; /* current output file */
+
+ #define moveright() (indent += 3)
+ #define moveleft() (indent -= 3)
+
+
+ /*****************************************************************************/
+ /* */
+ /* static aprint(x) */
+ /* static cprint(x) */
+ /* */
+ /* Print the ASCII or FULL_CHAR string x onto the appropriate output. */
+ /* */
+ /*****************************************************************************/
+
+ static void cprint(FULL_CHAR *x)
+ { col += StringLength(x);
+ if( fp == null ) AppendString(x);
+ else StringFPuts(x, fp);
+ } /* end print */
+
+ static void aprint(char *x)
+ { cprint(AsciiToFull(x));
+ } /* end aprint */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static printnum(x) */
+ /* */
+ /* Print the number x onto the appropriate output. */
+ /* */
+ /*****************************************************************************/
+
+ static void printnum(int x)
+ { cprint(StringInt(x));
+ } /* end printnum */
+
+
+ /*@::tab(), newline(), space()@***********************************************/
+ /* */
+ /* static tab(x) */
+ /* */
+ /* Tab to column x, or anyway insert at least one space. */
+ /* */
+ /*****************************************************************************/
+
+ static void tab(int x)
+ { do
+ aprint(" ");
+ while( col < x );
+ } /* end tab */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static newline() */
+ /* */
+ /* Echo a newline to the appropriate output (unless output is a string). */
+ /* Correct indenting and right limits are maintained, if possible. */
+ /* */
+ /*****************************************************************************/
+
+ static void newline(void)
+ { if( fp == null ) AppendString(STR_SPACE);
+ else
+ { fputs("\n", fp);
+ fflush(fp);
+ for( col = 0; col < indent; col++ ) fputs(" ", fp);
+ }
+ } /* end newline */
+
+
+ /*@::echo()@******************************************************************/
+ /* */
+ /* static echo(x, outer_prec, count) */
+ /* */
+ /* Echo x. The result will be enclosed in braces only if its precedence */
+ /* is less than or equal to outer_prec (words and parameterless closures */
+ /* are taken to have infinite precedence, i.e. never enclosed in braces). */
+ /* */
+ /* x is child number count of its parent. Used by COL_THR and ROW_THR */
+ /* only. */
+ /* */
+ /*****************************************************************************/
+
+ static void echo(OBJECT x, unsigned outer_prec, int count)
+ { OBJECT link, y, tmp, sym, z;
+ char *op; int prec, i, childcount, ycount;
+ BOOLEAN npar_seen, name_printed, lbr_printed, braces_needed;
+
+ switch( type(x) )
+ {
+
+ case DEAD:
+
+ aprint("#dead");
+ break;
+
+
+ case UNDER_REC:
+
+ aprint("#under_rec");
+ break;
+
+
+ case UNATTACHED:
+
+ aprint( "#unattached " );
+ moveright();
+ if( Down(x) != x )
+ { CountChild(y, Down(x), count);
+ if( y != x ) echo(y, NO_PREC, count);
+ else aprint("<child is self!>");
+ }
+ else aprint("<no child!>");
+ moveleft();
+ break;
+
+
+ case SCALE_IND:
+ case COVER_IND:
+ case EXPAND_IND:
+ case GALL_PREC:
+ case GALL_FOLL:
+ case GALL_FOLL_OR_PREC:
+ case GALL_TARG:
+ case CROSS_PREC:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+ case CROSS_TARG:
+ case RECURSIVE:
+ case PAGE_LABEL_IND:
+
+ /* aprint("#"); cprint(Image(type(x))); aprint(" "); */
+ echo(actual(x), NO_PREC, 1);
+ break;
+
+
+ case RECEPTIVE:
+ case RECEIVING:
+
+ aprint(type(x) == RECEIVING ? "#receiving " : "#receptive ");
+ if( external_ver(actual(x)) ) aprint("(external_ver) ");
+ if( external_hor(actual(x)) ) aprint("(external_hor) ");
+ if( threaded(actual(x)) ) aprint("(threaded) ");
+ if( blocked(x) ) aprint("(blocked) " );
+ if( trigger_externs(x) ) aprint("(trigger_externs) " );
+ if( non_blocking(x) ) aprint("(non_blocking) " );
+ cprint( type(actual(x)) == CLOSURE ?
+ SymName(actual(actual(x))) : Image(type(actual(x))) );
+ aprint(" ");
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ moveright();
+ echo(y, NO_PREC, count);
+ moveleft();
+ }
+ break;
+
+
+ case PRECEDES:
+
+ aprint("#precedes");
+ break;
+
+
+ case FOLLOWS:
+
+ aprint("#follows");
+ if( blocked(x) ) aprint(" (blocked)");
+ CountChild(y, Down(x), count);
+ if( Up(y) == LastUp(y) ) aprint(" (no precedes!)");
+ break;
+
+
+ case HEAD:
+
+ aprint("Galley "); cprint(SymName(actual(x)));
+ aprint(" into "); cprint(SymName(whereto(x)));
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ newline();
+ echo(y, type(y) == GAP_OBJ ? VCAT : VCAT_PREC, count);
+ }
+ break;
+
+
+ case ROW_THR:
+
+ aprint("{R ");
+ for( i=0, link = Down(x); link != x && i < count ; link = NextDown(link), i++ );
+ if( link != x )
+ { CountChild(y, link, count);
+ echo(y, VCAT_PREC, count);
+ /* newline(); */
+ }
+ aprint(" R}");
+ break;
+
+
+ /* ***
+ case COL_THR:
+
+ aprint("{C ");
+ for( i=0, link = Down(x); link != x && i < count ; link = NextDown(link), i++ );
+ if( link != x )
+ { CountChild(y, link, count);
+ echo(y, HCAT_PREC, count);
+ }
+ aprint(" C}");
+ break;
+ *** */
+
+
+ case COL_THR:
+
+ aprint("{C ");
+ newline();
+ for( i=1, link = Down(x); link != x; link = NextDown(link), i++ )
+ {
+ if( i == count )
+ aprint("C@ ");
+ else
+ aprint("C: ");
+ CountChild(y, link, ycount);
+ echo(y, HCAT_PREC, ycount);
+ newline();
+ }
+ aprint(" C}");
+ break;
+
+
+ case HSPANNER:
+
+ aprint("{HS ");
+ CountChild(y, Down(x), count);
+ echo(y, NO_PREC, count);
+ aprint(" HS}");
+ break;
+
+
+ case VSPANNER:
+
+ aprint("{VS ");
+ CountChild(y, Down(x), count);
+ echo(y, NO_PREC, count);
+ aprint(" VS}");
+ break;
+
+
+ case THREAD:
+
+ aprint("<thread>");
+ break;
+
+
+ case VCAT: op = "/", prec = VCAT_PREC; goto ETC;
+ case HCAT: op = "|", prec = HCAT_PREC; goto ETC;
+
+ ETC:
+ if( Down(x) == x )
+ { aprint(op);
+ aprint("<empty>");
+ break;
+ }
+ if( prec <= outer_prec ) aprint("{ ");
+ /* *** if( Down(x) == LastDown(x) ) aprint(op); must be manifested */
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ if( is_index(type(y)) )
+ newline();
+ else if( (type(y) == GAP_OBJ && type(x) != ACAT) )
+ newline();
+ if( type(y) == GAP_OBJ ) echo(y, type(x), count);
+ else echo(y, prec, count);
+ }
+ if( prec <= outer_prec ) aprint(" }");
+ break;
+
+
+ case ACAT: op = "&", prec = ACAT_PREC;
+
+ childcount = 0;
+ aprint("[[ ");
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ if( type(y) == GAP_OBJ )
+ {
+ echo(y, ACAT, count);
+ continue;
+ }
+ childcount++;
+ aprint("[");
+ echo(y, prec, count);
+ aprint("]");
+ /* ***
+ if( link == Down(x) || link == LastDown(x) )
+ echo(y, prec, count);
+ else if( NextDown(NextDown(link)) == LastDown(x) )
+ { sprintf(buff, " ++%d++ ", childcount+1);
+ aprint(buff);
+ }
+ *** */
+ }
+ aprint(" ]]");
+ break;
+
+
+ case GAP_OBJ:
+
+ /* in this case the outer_prec argument is VCAT, HCAT or ACAT */
+ if( Down(x) != x )
+ { if( outer_prec == ACAT ) aprint(" ");
+ cprint( EchoCatOp(outer_prec, mark(gap(x)), join(gap(x))) );
+ CountChild(y, Down(x), count);
+ echo(y, FORCE_PREC, count);
+ aprint(" ");
+ }
+ /* ***
+ else if( outer_prec == ACAT )
+ { for( i = 1; i <= vspace(x); i++ ) newline();
+ for( i = 1; i <= hspace(x); i++ ) aprint(" ");
+ }
+ *** */
+ else
+ { cprint( EchoCatOp(outer_prec, mark(gap(x)), join(gap(x))) );
+ cprint( EchoGap(&gap(x)) );
+ aprint(" ");
+ }
+ break;
+
+
+ case WORD:
+
+ if( StringLength(string(x)) == 0 )
+ aprint("{}");
+ else
+ { aprint("\"");
+ cprint( string(x) );
+ aprint("\"");
+ }
+ break;
+
+
+ case QWORD:
+
+ cprint( StringQuotedWord(x) );
+ break;
+
+
+ case ENV:
+
+ /* debug only */
+ aprint("<");
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ if( type(y) == CLOSURE )
+ { cprint( SymName(actual(y)) );
+ if( LastDown(y) != y ) echo(GetEnv(y), NO_PREC, count);
+ }
+ else if( type(y) == ENV ) echo(y, NO_PREC, count);
+ else cprint(Image(type(y)));
+ if( NextDown(link) != x ) aprint(" ");
+ }
+ aprint(">");
+ break;
+
+
+ case CROSS:
+ case FORCE_CROSS:
+
+ assert( Down(x) != x, "echo: CROSS Down(x)!" );
+ CountChild(y, Down(x), count);
+ if( type(y) == CLOSURE ) cprint(SymName(actual(y)));
+ else
+ { cprint(KW_LBR);
+ echo(y, NO_PREC, count);
+ cprint(KW_RBR);
+ }
+ cprint(Image(type(x)));
+ /* ***
+ cprint(KW_CROSS);
+ aprint("<");
+ cprint(Image(cross_type(x)));
+ aprint(">");
+ *** */
+ aprint(" ");
+ if( NextDown(Down(x)) != x )
+ { CountChild(y, NextDown(Down(x)), count);
+ echo(y, NO_PREC, count);
+ }
+ else aprint("??");
+ break;
+
+
+ case CLOSURE:
+
+ sym = actual(x);
+ braces_needed =
+ precedence(sym) <= outer_prec && (has_lpar(sym) || has_rpar(sym));
+
+ /* print brace if needed */
+ if( braces_needed ) aprint("{ ");
+
+ npar_seen = FALSE; name_printed = FALSE;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ if( type(y) == PAR )
+ { assert( Down(y) != y, "EchoObject: Down(PAR)!" );
+ switch( type(actual(y)) )
+ {
+ case LPAR: Child(tmp, Down(y));
+ echo(tmp, (unsigned) precedence(sym), 1);
+ aprint(" ");
+ break;
+
+ case NPAR: if( !name_printed )
+ { cprint(SymName(sym));
+ aprint("%");
+ cprint(SymName(enclosing(sym)));
+ if( external_ver(x) || external_hor(x) || threaded(x) )
+ { aprint(" #");
+ if( external_ver(x) ) aprint(" external_ver");
+ if( external_hor(x) ) aprint(" external_hor");
+ if( threaded(x) ) aprint(" threaded");
+ newline();
+ }
+ name_printed = TRUE;
+ }
+ newline(); aprint(" ");
+ cprint( SymName(actual(y)) );
+ aprint(" { ");
+ Child(tmp, Down(y));
+ echo(tmp, NO_PREC, 1);
+ aprint(" }");
+ npar_seen = TRUE;
+ break;
+
+ case RPAR: if( !name_printed )
+ { cprint(SymName(sym));
+ aprint("%");
+ cprint(SymName(enclosing(sym)));
+ if( external_ver(x) || external_hor(x) || threaded(x) )
+ { aprint(" #");
+ if( external_ver(x) ) aprint(" external_ver");
+ if( external_hor(x) ) aprint(" external_hor");
+ if( threaded(x) ) aprint(" threaded");
+ newline();
+ }
+ name_printed = TRUE;
+ }
+ if( npar_seen ) newline();
+ else aprint(" ");
+ Child(tmp, Down(y));
+ if( has_body(sym) )
+ { aprint("{ ");
+ echo(tmp, NO_PREC, 1);
+ aprint(" }");
+ }
+ else echo(tmp, (unsigned) precedence(sym), 1);
+ break;
+
+ default: assert1(FALSE, "echo:", Image(type(actual(y))));
+ break;
+
+ }
+ }
+ }
+ if( !name_printed )
+ { cprint( SymName(sym) );
+ aprint("%");
+ cprint(SymName(enclosing(sym)));
+ if( external_ver(x) || external_hor(x) || threaded(x) )
+ { aprint(" #");
+ if( external_ver(x) ) aprint(" external_ver");
+ if( external_hor(x) ) aprint(" external_hor");
+ if( threaded(x) ) aprint(" threaded");
+ newline();
+ }
+ }
+
+ /* print closing brace if needed */
+ if( braces_needed ) aprint(" }");
+ break;
+
+
+ case SPLIT:
+
+ /* this should occur only in debug output case */
+ cprint(KW_SPLIT); moveright();
+ CountChild(y, DownDim(x, COLM), count);
+ aprint(" COLM:");
+ echo(y, FORCE_PREC, count);
+ newline();
+ /* ***
+ Child(y, DownDim(x, ROWM));
+ aprint(" ROWM:");
+ echo(y, FORCE_PREC);
+ *** */
+ moveleft();
+ break;
+
+
+ case PAR:
+
+ /* this should occur only in debug output case */
+ aprint("par "); cprint(SymName(actual(x)));
+ break;
+
+
+ case CR_LIST:
+
+ aprint("(");
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ echo(y, NO_PREC, count);
+ if( NextDown(link) != x ) aprint(", ");
+ }
+ aprint(")");
+ break;
+
+
+ case MACRO:
+
+ newline(); cprint(KW_MACRO);
+ aprint(" "); cprint(SymName(x));
+ if( sym_body(x) != nilobj )
+ { newline(); cprint(KW_LBR);
+ y = sym_body(x);
+ do
+ { for( i = 1; i <= vspace(y); i++ ) newline();
+ for( i = 1; i <= hspace(y); i++ ) aprint(" ");
+ cprint(EchoToken(y));
+ y = succ(y, PARENT);
+ } while( y != sym_body(x) );
+ newline(); cprint(KW_RBR);
+ }
+ else aprint(" {}");
+ if( visible(x) ) aprint(" # (visible)");
+ break;
+
+
+ case NPAR:
+ case LOCAL:
+
+ /* print predefined operators in abbreviated form */
+ if( sym_body(x) == nilobj && enclosing(x) != nilobj )
+ { tab(3); aprint("# sys ");
+ cprint(SymName(x));
+ break;
+ }
+
+ /* print def line and miscellaneous debug info */
+ if( type(x) == LOCAL ) newline();
+ cprint(type(x) == NPAR ? KW_NAMED : KW_DEF);
+ aprint(" "); cprint( SymName(x) );
+ if( recursive(x) || indefinite(x) || visible(x) ||
+ is_extern_target(x) || uses_extern_target(x) || uses_galley(x) )
+ { tab(25); aprint("#");
+ if( visible(x) ) aprint(" visible");
+ if( recursive(x) ) aprint(" recursive");
+ if( indefinite(x) ) aprint(" indefinite");
+ if( is_extern_target(x) ) aprint(" is_extern_target");
+ if( uses_extern_target(x) ) aprint(" uses_extern_target");
+ if( uses_galley(x) ) aprint(" uses_galley");
+ }
+
+ /* print uses list, if necessary */
+ if( uses(x) != nilobj || dirty(x) )
+ { newline(); aprint(" # ");
+ if( dirty(x) ) aprint("dirty, ");
+ aprint("uses");
+ if( uses(x) != nilobj )
+ { tmp = next(uses(x));
+ do
+ { aprint(" "), cprint( SymName(item(tmp)) );
+ tmp = next(tmp);
+ } while( tmp != next(uses(x)) );
+ }
+ /* ***
+ for( tmp = uses(x); tmp != nilobj; tmp = next(tmp) )
+ { aprint(" "), cprint( SymName(item(tmp)) );
+ }
+ *** */
+ }
+
+ /* print precedence, if necessary */
+ if( precedence(x) != DEFAULT_PREC )
+ { newline(); aprint(" "); cprint(KW_PRECEDENCE);
+ aprint(" "); printnum(precedence(x));
+ }
+
+ /* print associativity, if necessary */
+ if( !right_assoc(x) )
+ { newline(); aprint(" ");
+ cprint(KW_ASSOC); aprint(" "); cprint(KW_LEFT);
+ }
+
+ /* print named parameters and local objects */
+ lbr_printed = FALSE;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ assert( enclosing(y) == x, "echo: enclosing(y) != x!" );
+ switch( type(y) )
+ {
+ case LPAR:
+ case RPAR: newline(); aprint(" ");
+ cprint( type(y) == LPAR ? KW_LEFT :
+ has_body(x) ? KW_BODY : KW_RIGHT);
+ aprint(" ");
+ cprint( SymName(y) );
+ aprint(" # uses_count = ");
+ printnum(uses_count(y));
+ if( visible(y) ) aprint(" (visible)");
+ break;
+
+ case NPAR: moveright(); newline();
+ echo(y, NO_PREC, count);
+ aprint(" # uses_count = ");
+ printnum(uses_count(y));
+ moveleft();
+ break;
+
+ case MACRO:
+ case LOCAL: if( !lbr_printed )
+ { newline();
+ cprint(KW_LBR);
+ lbr_printed = TRUE;
+ }
+ moveright();
+ echo(y, NO_PREC, count);
+ moveleft(); newline();
+ break;
+
+ default: assert1(FALSE, "echo:", Image(type(y)));
+ break;
+ }
+ }
+ if( type(x) == NPAR && Down(x) == x ) aprint(" ");
+ else newline();
+ if( !lbr_printed )
+ { cprint(KW_LBR); aprint(" ");
+ lbr_printed = TRUE;
+ }
+ else aprint(" ");
+
+ /* print body */
+ moveright();
+ if( sym_body(x) != nilobj ) echo(sym_body(x), NO_PREC, 1);
+ moveleft(); if( type(x) == LOCAL ) newline();
+ cprint(KW_RBR);
+ break;
+
+
+ case BEGIN_HEADER:
+ case SET_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case COMMON:
+ case RUMP:
+ case MELD:
+ case INSERT:
+ case ONE_OF:
+ case NEXT:
+ case PLUS:
+ case MINUS:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+ case ROTATE:
+ case BACKGROUND:
+ case SCALE:
+ case KERN_SHRINK:
+ case CASE:
+ case YIELD:
+ case XCHAR:
+ case FONT:
+ case SPACE:
+ case YUNIT:
+ case ZUNIT:
+ case BREAK:
+ case UNDERLINE:
+ case COLOUR:
+ case OUTLINE:
+ case LANGUAGE:
+ case OPEN:
+ case TAGGED:
+ case ENV_OBJ:
+
+
+ /* print enclosing left brace if needed */
+ braces_needed = (DEFAULT_PREC <= outer_prec);
+ if( braces_needed ) cprint(KW_LBR), aprint(" ");
+
+ /* print left parameter */
+ if( Down(x) != LastDown(x) )
+ { CountChild(y, Down(x), count);
+ echo(y, find_max(outer_prec, DEFAULT_PREC), count);
+ aprint(" ");
+ }
+
+ cprint(Image(type(x)));
+
+ /* print right parameter */
+ assert( LastDown(x) != x, "echo: right parameter of predefined!" );
+ aprint(" ");
+ CountChild(y, LastDown(x), count);
+ echo(y, type(x)==OPEN ? FORCE_PREC : find_max(outer_prec,DEFAULT_PREC),
+ count);
+ if( braces_needed ) aprint(" "), cprint(KW_RBR);
+ break;
+
+
+ case RAW_VERBATIM:
+ case VERBATIM:
+
+ cprint(type(x) == VERBATIM ? KW_VERBATIM : KW_RAWVERBATIM);
+ aprint(" ");
+ cprint(KW_LBR);
+ CountChild(y, Down(x), count);
+ if( type(y) == WORD )
+ { cprint(string(y));
+ }
+ else
+ { newline();
+ for( link = Down(y); link != y; link = NextDown(link) )
+ { Child(z, link)
+ cprint(string(z));
+ newline();
+ }
+ }
+ cprint(KW_RBR);
+ break;
+
+
+ case CURR_LANG:
+ case CURR_FAMILY:
+ case CURR_FACE:
+ case CURR_YUNIT:
+ case CURR_ZUNIT:
+ case BACKEND:
+ case PAGE_LABEL:
+ case HSPAN:
+ case VSPAN:
+ case END_HEADER:
+ case CLEAR_HEADER:
+
+ /* predefined symbols that have (or may have) no parameters */
+ cprint(Image(type(x)));
+ break;
+
+
+ case FILTERED:
+
+ aprint("[filtered ");
+ if( Down(x) != x )
+ { Child(y, Down(x));
+ if( type(y) != WORD ) cprint(Image(type(y)));
+ else cprint(string(y));
+ }
+ else aprint("?");
+ aprint("]");
+ break;
+
+
+ case NULL_CLOS:
+
+ cprint(Image(type(x)));
+ break;
+
+
+ case CR_ROOT:
+
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { CountChild(y, link, count);
+ echo(y, NO_PREC, count); newline();
+ }
+ break;
+
+
+ case CROSS_SYM:
+
+ aprint("Cross-references for ");
+ cprint(SymName(symb(x))); newline();
+ switch( target_state(x) )
+ {
+ case 0: aprint("NO_TARGET");
+ break;
+
+ case 1: aprint("SEEN_TARGET ");
+ printnum(target_seq(x));
+ aprint(": ");
+ echo(target_val(x), NO_PREC, 1);
+ break;
+
+ case 2: aprint("WRITTEN_TARGET ");
+ printnum(target_seq(x));
+ aprint(": to file ");
+ cprint(FileName(target_file(x)));
+ aprint(" at ");
+ printnum(target_pos(x));
+ break;
+
+ default: aprint("ILLEGAL!");
+ break;
+ }
+ newline();
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ aprint(" ");
+ cprint(Image(cs_type(y)));
+ aprint(": ");
+ cprint(string(y));
+ newline();
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "echo:", Image(type(x)));
+ break;
+
+ } /* end switch */
+ } /* end echo */
+
+
+ /*@::EchoObject(), DebugObject()@*********************************************/
+ /* */
+ /* FULL_CHAR *EchoObject(x) */
+ /* */
+ /* Return an image of unsized object x in result. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EchoObject(OBJECT x)
+ { debug0(DOE, D, "EchoObject()");
+ fp = null;
+ col = 0;
+ indent = 0;
+ limit = 60;
+ if( fp == null )
+ BeginString();
+ if( x == nilobj ) AppendString(AsciiToFull("<nilobj>"));
+ else echo(x, type(x) == GAP_OBJ ? VCAT : 0, 1);
+ debug0(DOE, D, "EchoObject returning");
+ return EndString();
+ } /* end EchoObject */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DebugObject(x) */
+ /* */
+ /* Send an image of unsized object x to result. */
+ /* */
+ /*****************************************************************************/
+
+ void DebugObject(OBJECT x)
+ { debug0(DOE, D, "DebugObject()");
+ fp = stderr;
+ col = 0;
+ indent = 0;
+ limit = 60;
+ if( x == nilobj ) fprintf(stderr, "<nilobj>");
+ else echo(x, type(x) == GAP_OBJ ? VCAT : 0, 1);
+ fprintf(stderr, "\n");
+ debug0(DOE, D, "DebugObject returning");
+ } /* end DebugObject */
+
+
+ /*@::EchoIndex()@*************************************************************/
+ /* */
+ /* FULL_CHAR *EchoIndex() */
+ /* */
+ /* Echo a component of a galley, briefly. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EchoIndex(OBJECT index)
+ { static char buff[MAX_BUFF]; OBJECT z;
+ if( index == nilobj )
+ { sprintf(buff, "<nilobj>");
+ }
+ else switch( type(index) )
+ {
+ case RECEIVING:
+
+ sprintf(buff, "receiving %s%s", type(actual(index)) == CLOSURE ?
+ SymName(actual(actual(index))) : Image(type(actual(index))),
+ non_blocking(index) ? " (non_blocking)" : "");
+ break;
+
+
+ case RECEPTIVE:
+
+ sprintf(buff, "receptive %s%s", type(actual(index)) == CLOSURE ?
+ SymName(actual(actual(index))) : Image(type(actual(index))),
+ non_blocking(index) ? " (non_blocking)" : "");
+ break;
+
+
+ case UNATTACHED:
+
+ if( Down(index) != index )
+ { Child(z, Down(index));
+ }
+ else z = nilobj;
+ sprintf(buff, "unattached %s",
+ z == nilobj ? AsciiToFull("<nilobj>") : SymName(actual(z)));
+ break;
+
+
+ case WORD:
+ case QWORD:
+
+ sprintf(buff, "\"%s\"", string(index));
+ break;
+
+
+ default:
+
+ sprintf(buff, "%s", Image(type(index)));
+ break;
+ }
+ return AsciiToFull(buff);
+ } /* end EchoIndex */
+
+
+ /*@::DebugGalley()@***********************************************************/
+ /* */
+ /* DebugGalley(hd, pinpt, indent) */
+ /* */
+ /* Print overview of galley hd on stderr; mark pinpoint if found */
+ /* */
+ /*****************************************************************************/
+ #define eprint(x, a, b, c) fprintf(stderr, "| %d %-7s %20s %s\n", x, a, b, c)
+
+ void DebugGalley(OBJECT hd, OBJECT pinpt, int indent)
+ { OBJECT link, y; char istr[30]; int i;
+ for( i = 0; i < indent; i++ ) istr[i] = ' ';
+ istr[i] = '\0';
+ if( type(hd) != HEAD )
+ { fprintf(stderr, "%shd is %s\n", istr, Image(type(hd)));
+ return;
+ }
+ fprintf(stderr, "%sgalley %s into %s\n", istr,
+ SymName(actual(hd)), SymName(whereto(hd)));
+ for( link = Down(hd); link != hd; link = NextDown(link) )
+ { Child(y, link);
+ if( y == pinpt || link == pinpt )
+ { fprintf(stderr, "++ %d %s ", (int) y, Image(type(y)));
+ DebugObject(y);
+ }
+ else
+ if( type(y) == GAP_OBJ )
+ eprint((int) y, "gap_obj", Image(type(y)), EchoGap(&gap(y)));
+ else if( is_index(type(y)) )
+ eprint((int) y, "index", Image(type(y)), "");
+ else if( is_definite(type(y)) )
+ eprint((int) y, "def_obj", Image(type(y)), is_word(type(y)) ? string(y):STR_EMPTY);
+ else if( is_indefinite(type(y)) )
+ eprint((int) y, "indefin", Image(type(y)),
+ type(y) == CLOSURE ? SymName(actual(y)) : STR_EMPTY);
+ else
+ eprint((int) y, "unknown", Image(type(y)), "");
+ }
+ } /* end DebugGalley */
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z26.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z26.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z26.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,318 ----
+ /*@z26.c:Echo Service:BeginString()@******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z26.c */
+ /* MODULE: Echo Service */
+ /* EXTERNS: BeginString(), AppendString(), EndString(), */
+ /* EchoLength(), Image() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ #if DEBUG_ON
+ #define MULTI 7 /* max no of simultaneous calls */
+
+ static FULL_CHAR buff[MULTI][2*MAX_BUFF];/* buffers for strings */
+ static int curr = 1; /* current buffer in use */
+ static int bp; /* next free space in buff[curr] */
+ static BOOLEAN instring = FALSE; /* TRUE while making a string */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BeginString() */
+ /* */
+ /* Locate a clear buffer into which debug output may be accumulated. */
+ /* */
+ /*****************************************************************************/
+
+ void BeginString(void)
+ { assert(!instring, "BeginString: currently in string");
+ instring = TRUE; curr = (curr + 1) % MULTI;
+ assert( 0 <= curr && curr < MULTI, "BeginString: curr!" );
+ StringCopy(buff[curr], ""); bp = 0;
+ }
+
+
+ /*@::AppendString(), EndString(), EchoLength()@*******************************/
+ /* */
+ /* AppendString(str, p1, p2, p3, p4, p5, p6) */
+ /* */
+ /* Sprintf str to the current buffer, if space is available there. */
+ /* */
+ /*****************************************************************************/
+
+ void AppendString(FULL_CHAR *str)
+ { int len;
+ assert(instring, "AppendString: no current string");
+ assert( 0 <= curr && curr < MULTI, "BeginString: curr!" );
+ if( bp == MAX_BUFF ) return; /* no space, do nothing */
+
+ len = StringLength(str);
+ if( len + bp >= MAX_BUFF )
+ { StringCopy( &buff[curr][MAX_BUFF/2], AsciiToFull(" ... <too long>") );
+ bp = MAX_BUFF;
+ }
+ else
+ { StringCopy(&buff[curr][bp], str);
+ while( buff[curr][bp] != '\0' ) bp++;
+ if( bp >= MAX_BUFF ) Error(26, 1, "AppendString abort", INTERN, no_fpos);
+ }
+ } /* end AppendString */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *EndString() */
+ /* */
+ /* Return the string constructed by previous AppendString operations. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EndString(void)
+ { assert(instring, "EndString: no string");
+ assert( 0 <= curr && curr < MULTI, "BeginString: curr!" );
+ instring = FALSE;
+ return buff[curr];
+ } /* end Endstring */
+ #endif
+
+ /*****************************************************************************/
+ /* */
+ /* SetLengthDim(int dim) */
+ /* */
+ /* Set dimension for echoing lengths. */
+ /* */
+ /*****************************************************************************/
+
+ static int length_dim = COLM;
+
+ void SetLengthDim(int dim)
+ {
+ length_dim = dim;
+ }
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *EchoLength(len) */
+ /* */
+ /* Echo a length. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *EchoLength(int len)
+ { static FULL_CHAR buff[8][20];
+ static int i = 0;
+ i = (i + 1) % 8;
+ if( len == MAX_FULL_LENGTH )
+ sprintf( (char *) buff[i], "%s", "INF");
+ else
+ BackEnd->PrintLength(buff[i], len, ROWM);
+ return buff[i];
+ } /* end EchoLength */
+
+
+ /*@::Image()@*****************************************************************/
+ /* */
+ /* FULL_CHAR *Image(c) */
+ /* */
+ /* Returns the string value of type c. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *Image(unsigned int c)
+ { static FULL_CHAR b[20];
+ switch(c)
+ {
+
+ case LINK: return AsciiToFull("link");
+
+ case SPLIT: return AsciiToFull("split");
+ case HEAD: return AsciiToFull("head");
+ case PAR: return AsciiToFull("par");
+ case WORD: return AsciiToFull("word");
+ case QWORD: return AsciiToFull("qword");
+ case GAP_OBJ: return AsciiToFull("gap_obj");
+ case ROW_THR: return AsciiToFull("row_thr");
+ case COL_THR: return AsciiToFull("col_thr");
+ case CLOSURE: return AsciiToFull("closure");
+ case NULL_CLOS: return KW_NULL;
+ case PAGE_LABEL: return KW_PAGE_LABEL;
+ case CROSS: return KW_CROSS;
+ case FORCE_CROSS: return KW_FORCE_CROSS;
+ case BEGIN_HEADER: return KW_BEGIN_HEADER;
+ case END_HEADER: return KW_END_HEADER;
+ case SET_HEADER: return KW_SET_HEADER;
+ case CLEAR_HEADER: return KW_CLEAR_HEADER;
+ case ONE_COL: return KW_ONE_COL;
+ case ONE_ROW: return KW_ONE_ROW;
+ case WIDE: return KW_WIDE;
+ case HIGH: return KW_HIGH;
+ case HSHIFT: return KW_HSHIFT;
+ case VSHIFT: return KW_VSHIFT;
+ case HSCALE: return KW_HSCALE;
+ case VSCALE: return KW_VSCALE;
+ case HCOVER: return KW_HCOVER;
+ case VCOVER: return KW_VCOVER;
+ case HCONTRACT: return KW_HCONTRACT;
+ case VCONTRACT: return KW_VCONTRACT;
+ case HLIMITED: return KW_HLIMITED;
+ case VLIMITED: return KW_VLIMITED;
+ case HEXPAND: return KW_HEXPAND;
+ case VEXPAND: return KW_VEXPAND;
+ case START_HVSPAN: return KW_STARTHVSPAN;
+ case START_HSPAN: return KW_STARTHSPAN;
+ case START_VSPAN: return KW_STARTVSPAN;
+ case HSPAN: return KW_HSPAN;
+ case VSPAN: return KW_VSPAN;
+ case HSPANNER: return AsciiToFull("hspannner");
+ case VSPANNER: return AsciiToFull("vspannner");
+ case PADJUST: return KW_PADJUST;
+ case HADJUST: return KW_HADJUST;
+ case VADJUST: return KW_VADJUST;
+ case ROTATE: return KW_ROTATE;
+ case BACKGROUND: return KW_BACKGROUND;
+ case SCALE: return KW_SCALE;
+ case KERN_SHRINK: return KW_KERN_SHRINK;
+ case RAW_VERBATIM: return KW_RAWVERBATIM;
+ case VERBATIM: return KW_VERBATIM;
+ case CASE: return KW_CASE;
+ case YIELD: return KW_YIELD;
+ case BACKEND: return KW_BACKEND;
+ case FILTERED: return AsciiToFull("filtered");
+ case XCHAR: return KW_XCHAR;
+ case FONT: return KW_FONT;
+ case SPACE: return KW_SPACE;
+ case YUNIT: return KW_YUNIT;
+ case ZUNIT: return KW_ZUNIT;
+ case BREAK: return KW_BREAK;
+ case UNDERLINE: return KW_UNDERLINE;
+ case COLOUR: return KW_COLOUR;
+ case OUTLINE: return KW_OUTLINE;
+ case LANGUAGE: return KW_LANGUAGE;
+ case CURR_LANG: return KW_CURR_LANG;
+ case CURR_FAMILY: return KW_CURR_FAMILY;
+ case CURR_FACE: return KW_CURR_FACE;
+ case CURR_YUNIT: return KW_CURR_YUNIT;
+ case CURR_ZUNIT: return KW_CURR_ZUNIT;
+ case COMMON: return KW_COMMON;
+ case RUMP: return KW_RUMP;
+ case MELD: return KW_MELD;
+ case INSERT: return KW_INSERT;
+ case ONE_OF: return KW_ONE_OF;
+ case NEXT: return KW_NEXT;
+ case PLUS: return KW_PLUS;
+ case MINUS: return KW_MINUS;
+ case ENV_OBJ: return AsciiToFull("env_obj");
+ case ENV: return KW_ENV;
+ case ENVA: return KW_ENVA;
+ case ENVB: return KW_ENVB;
+ case ENVC: return KW_ENVC;
+ case ENVD: return KW_ENVD;
+ case CENV: return KW_CENV;
+ case CLOS: return KW_CLOS;
+ case LVIS: return KW_LVIS;
+ case LUSE: return KW_LUSE;
+ case LEO: return KW_LEO;
+ case OPEN: return KW_OPEN;
+ case TAGGED: return KW_TAGGED;
+ case INCGRAPHIC: return KW_INCGRAPHIC;
+ case SINCGRAPHIC: return KW_SINCGRAPHIC;
+ case PLAIN_GRAPHIC: return KW_PLAINGRAPHIC;
+ case GRAPHIC: return KW_GRAPHIC;
+ case LINK_SOURCE: return KW_LINK_SOURCE;
+ case LINK_DEST: return KW_LINK_DEST;
+ case ACAT: return AsciiToFull("acat");
+ case HCAT: return AsciiToFull("hcat");
+ case VCAT: return AsciiToFull("vcat");
+
+ case TSPACE: return AsciiToFull("tspace");
+ case TJUXTA: return AsciiToFull("tjuxta");
+ case LBR: return AsciiToFull("lbr");
+ case RBR: return AsciiToFull("rbr");
+ case UNEXPECTED_EOF: return AsciiToFull("unexpected_eof");
+ case BEGIN: return KW_BEGIN;
+ case END: return KW_END;
+ case USE: return KW_USE;
+ case NOT_REVEALED: return KW_NOT_REVEALED;
+ case GSTUB_NONE: return AsciiToFull("gstub_none");
+ case GSTUB_INT: return AsciiToFull("gstub_int");
+ case GSTUB_EXT: return AsciiToFull("gstub_ext");
+ case INCLUDE: return KW_INCLUDE;
+ case SYS_INCLUDE: return KW_SYSINCLUDE;
+ case PREPEND: return KW_PREPEND;
+ case SYS_PREPEND: return KW_SYSPREPEND;
+ case DATABASE: return KW_DATABASE;
+ case SYS_DATABASE: return KW_SYSDATABASE;
+ /* case START: return AsciiToFull("start"); unused */
+
+ case DEAD: return AsciiToFull("dead");
+ case UNATTACHED: return AsciiToFull("unattached");
+ case RECEPTIVE: return AsciiToFull("receptive");
+ case RECEIVING: return AsciiToFull("receiving");
+ case RECURSIVE: return AsciiToFull("recursive");
+ case PRECEDES: return AsciiToFull("precedes");
+ case FOLLOWS: return AsciiToFull("follows");
+ case CROSS_LIT: return AsciiToFull("cross_lit");
+ case CROSS_FOLL: return AsciiToFull("cross_foll");
+ case CROSS_FOLL_OR_PREC: return AsciiToFull("cross_foll_or_prec");
+ case GALL_FOLL: return AsciiToFull("gall_foll");
+ case GALL_FOLL_OR_PREC: return AsciiToFull("gall_foll_or_prec");
+ case CROSS_TARG: return AsciiToFull("cross_targ");
+ case GALL_TARG: return AsciiToFull("gall_targ");
+ case GALL_PREC: return AsciiToFull("gall_prec");
+ case CROSS_PREC: return AsciiToFull("cross_prec");
+ case PAGE_LABEL_IND: return AsciiToFull("page_label_ind");
+ case SCALE_IND: return AsciiToFull("scale_ind");
+ case COVER_IND: return AsciiToFull("cover_ind");
+ case EXPAND_IND: return AsciiToFull("expand_ind");
+ case THREAD: return AsciiToFull("thread");
+ case CROSS_SYM: return AsciiToFull("cross_sym");
+ case CR_ROOT: return AsciiToFull("cr_root");
+ case MACRO: return KW_MACRO;
+ case LOCAL: return AsciiToFull("local");
+ case LPAR: return AsciiToFull("lpar");
+ case NPAR: return AsciiToFull("npar");
+ case RPAR: return AsciiToFull("rpar");
+ case CR_LIST: return AsciiToFull("cr_list");
+ case EXT_GALL: return AsciiToFull("ext_gall");
+ case DISPOSED: return AsciiToFull("disposed");
+
+ case BACK: return AsciiToFull("back");
+ case ON: return AsciiToFull("on");
+ case FWD: return AsciiToFull("fwd");
+
+ case PROMOTE: return AsciiToFull("promote");
+ case CLOSE: return AsciiToFull("close");
+ case BLOCK: return AsciiToFull("block");
+ case CLEAR: return AsciiToFull("clear");
+
+ case GAP_ABS: return AsciiToFull("abs");
+ case GAP_INC: return AsciiToFull("inc");
+ case GAP_DEC: return AsciiToFull("dec");
+
+ default: sprintf( (char *) b, "?? (%d)", c);
+ return b;
+ } /* end switch */
+ } /* end Image */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z27.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z27.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z27.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,212 ----
+ /*@z27.c:Debug Service:Debug flags@*******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z27.c */
+ /* MODULE: Debug Service */
+ /* EXTERNS: dbg[], DebugInit(), Debug() */
+ /* ProfileOn(), ProfileOff(), ProfilePrint() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ #if DEBUG_ON
+ struct dbs dbg[] = {
+ {"zz", {0, 0, 0}}, /* - unused - */
+ {"sp", {0, 0, 0}}, /* Supervise */
+ {"la", {0, 0, 0}}, /* Lexical Analyser */
+ {"fs", {0, 0, 0}}, /* File Service */
+ {"ts", {0, 0, 0}}, /* Token Service */
+ {"rd", {0, 0, 0}}, /* Read Definitions */
+ {"op", {0, 0, 0}}, /* Object Parser */
+ {"os", {0, 0, 0}}, /* Object Service */
+ {"om", {0, 0, 0}}, /* Object Manifest */
+ {"ce", {0, 0, 0}}, /* Closure Expansion */
+ {"cr", {0, 0, 0}}, /* Cross References */
+ {"ss", {0, 0, 0}}, /* Style Service */
+ {"sf", {0, 0, 0}}, /* Size Finder */
+ {"ob", {0, 0, 0}}, /* Object Breaking */
+ {"of", {0, 0, 0}}, /* Object Filling */
+ {"sc", {0, 0, 0}}, /* Size Constraints */
+ {"sa", {0, 0, 0}}, /* Size Adjustments */
+ {"gw", {0, 0, 0}}, /* Gap Widths */
+ {"gt", {0, 0, 0}}, /* Galley Transfer */
+ {"ga", {0, 0, 0}}, /* Galley Attaching */
+ {"gf", {0, 0, 0}}, /* Galley Flusher */
+ {"gm", {0, 0, 0}}, /* Galley Maker */
+ {"gs", {0, 0, 0}}, /* Galley Service */
+ {"gp", {0, 0, 0}}, /* Galley Printer */
+ {"ps", {0, 0, 0}}, /* Print Service */
+ {"oe", {0, 0, 0}}, /* Object Echo */
+ {"es", {0, 0, 0}}, /* Echo Service */
+ {"zz", {0, 0, 0}}, /* Debug Service (unused) */
+ {"yy", {0, 0, 0}}, /* Error Service */
+ {"st", {0, 0, 0}}, /* Symbol Table */
+ {"su", {0, 0, 0}}, /* Symbol Uses */
+ {"ma", {0, 0, 0}}, /* Memory Allocator */
+ {"cs", {0, 0, 0}}, /* Counter Service */
+ {"bs", {0, 0, 0}}, /* Database Service */
+ {"rs", {0, 0, 0}}, /* Rotation Service */
+ {"tk", {0, 0, 0}}, /* Time Keeper */
+ {"hy", {0, 0, 0}}, /* Hyphenation */
+ {"ft", {0, 0, 0}}, /* Font Tables */
+ {"cm", {0, 0, 0}}, /* Character Mappings */
+ {"sh", {0, 0, 0}}, /* String Handler */
+ {"fh", {0, 0, 0}}, /* Filter Handler */
+ {"io", {0, 0, 0}}, /* Object Input-Output */
+ {"co", {0, 0, 0}}, /* Colour Service */
+ {"ls", {0, 0, 0}}, /* Language Service */
+ {"vh", {0, 0, 0}}, /* Vertical Hyphenation */
+ {"ex", {0, 0, 0}}, /* External Sort */
+ {"og", {0, 0, 0}}, /* Optimal Galleys */
+ {"et", {0, 0, 0}}, /* Environment Table */
+ {"pd", {0, 0, 0}}, /* PDF Back End (old) */
+ {"po", {0, 0, 0}}, /* PostScript Back End */
+ {"pf", {0, 0, 0}}, /* PDF Back End */
+ {"pt", {0, 0, 0}}, /* Plain Text Back End */
+ {"pp", {0, 0, 0}}, /* Profiling */
+ {"", {0, 0, 0}}, /* any */
+ };
+
+ /*@::DebugInit(), Debug()@****************************************************/
+ /* */
+ /* DebugInit(str) */
+ /* */
+ /* Turn on the debug flag given by str. */
+ /* */
+ /*****************************************************************************/
+
+ void DebugInit(FULL_CHAR *str)
+ { int j, urg;
+ for( urg = 0; urg < 2 && str[urg+2] == CH_FLAG_DEBUG; urg++ );
+ for( j = 1; ; j++ )
+ { if( StringEqual(AsciiToFull(dbg[j].flag), &str[urg+2]) ) break;
+ if( StringEqual(AsciiToFull(dbg[j].flag), STR_EMPTY) )
+ Error(27, 1, "unknown debug flag %s", FATAL, no_fpos, str);
+ }
+ for( ; urg >= 0; urg-- ) dbg[j].on[urg] = dbg[ANY].on[urg] = TRUE;
+ } /* end DebugInit */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Debug(category, urgency, str, ...) */
+ /* */
+ /* Print str on debug output, if the flag corresponding to the given */
+ /* debug category and urgency is on. */
+ /* */
+ /*****************************************************************************/
+
+ void Debug(int category, int urgency, char *str, ...)
+ { static BOOLEAN first_message = TRUE;
+ va_list ap;
+ if( first_message )
+ { fprintf(stderr, "\nLout Debug Output:\n");
+ first_message = FALSE;
+ }
+ fprintf(stderr, "%2s: ", dbg[category].flag);
+ va_start(ap, str);
+ vfprintf(stderr, str, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+ fflush(stderr);
+ } /* end Debug */
+
+
+ /*@::ProfileOn(), ProfileOff(), ProfilePrint()@*******************************/
+ /* */
+ /* ProfileOn(str) */
+ /* */
+ /* Start profiling label str. */
+ /* */
+ /*****************************************************************************/
+ #define MAXPROF 20
+ #include <time.h>
+
+ struct profrec
+ { char *label; /* label of the profile */
+ int calls; /* number of calls with this label */
+ long time; /* total time of this label */
+ };
+
+ static struct profrec profstack[MAXPROF];
+ static struct profrec profstore[MAXPROF];
+ static int proftop = 0, profsize = 0;
+
+ void ProfileOn(char *str)
+ { int i; time_t raw_time;
+ for( i = 0; i < proftop; i++ )
+ { if( strcmp(profstack[i].label, str) == 0 )
+ { for( i = 0; i < proftop; i++ )
+ fprintf(stderr, "profstack[%d] = %s\n", i, profstack[i].label);
+ assert1(FALSE, "ProfileOn: restarted", str);
+ }
+ }
+ assert(proftop < MAXPROF, "ProfileOn: overflow");
+ time(&raw_time); profstack[proftop].label = str;
+ profstack[proftop++].time = raw_time;
+ } /* end ProfileOn */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ProfileOff(str) */
+ /* */
+ /* Stop profiling label str. */
+ /* */
+ /*****************************************************************************/
+
+ void ProfileOff(char *str)
+ { int i; time_t raw_time;
+ assert1(proftop > 0 && strcmp(profstack[proftop-1].label, str) == 0,
+ "ProfileOff: not current", str);
+ for( i = 0; i < profsize && strcmp(profstore[i].label, str) != 0; i++ );
+ if( i >= profsize )
+ { profsize++;
+ assert(profsize < MAXPROF, "ProfileOff: overflow");
+ profstore[i].label = str;
+ profstore[i].calls = 0;
+ profstore[i].time = 0;
+ }
+ time(&raw_time); profstore[i].calls += 1;
+ profstore[i].time += (raw_time - profstack[--proftop].time);
+ } /* end ProfileOff */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ProfilePrint() */
+ /* */
+ /* Print results of profiling. */
+ /* */
+ /*****************************************************************************/
+
+ void ProfilePrint(void)
+ { int i;
+ for( i = 0; i < profsize; i++ )
+ { fprintf(stderr, "Profile %-20s %6ld secs, %3d calls, %6.2f secs/call\n",
+ profstore[i].label, profstore[i].time, profstore[i].calls,
+ (float) profstore[i].time / profstore[i].calls );
+ }
+ } /* end ProfilePrint */
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z28.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z28.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z28.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,259 ----
+ /*@z28.c:Error Service:ErrorInit(), ErrorSeen()@******************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z28.c */
+ /* MODULE: Error Service */
+ /* EXTERNS: ErrorInit(), Error(), ErrorSeen() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ #define MAX_BLOCKS 20 /* max number of error blocks */
+ #define MAX_ERRORS 20 /* max number of held error messages */
+
+ static BOOLEAN print_block[MAX_BLOCKS]; /* TRUE if print this block */
+ static int start_block[MAX_BLOCKS]; /* first message of block */
+ static char message[MAX_ERRORS][MAX_BUFF]; /* the error messages */
+ static int message_fnum[MAX_ERRORS]; /* file number of error mess */
+ static FILE *fp = NULL; /* file pointer of log file */
+ static BOOLEAN error_seen = FALSE; /* TRUE after first error */
+ static int block_top = 0; /* first free error block */
+ static int mess_top = 0; /* first free error message */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ErrorInit(str) */
+ /* */
+ /* Open log file str and initialise this module. */
+ /* */
+ /*****************************************************************************/
+
+ void ErrorInit(FULL_CHAR *str)
+ { if( fp != NULL )
+ Error(28, 1, "-e argument appears twice in command line", FATAL, no_fpos);
+ fp = StringFOpen(str, WRITE_TEXT);
+ if( fp == NULL )
+ Error(28, 2, "cannot open error file %s", FATAL, no_fpos, str);
+ } /* end ErrorInit */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN ErrorSeen() */
+ /* */
+ /* TRUE once an error has been found. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN ErrorSeen(void)
+ { return error_seen;
+ } /* end ErrorSeen */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PrintFileBanner(fnum) */
+ /* */
+ /* If fnum was not the subject of the previous call to PrintFileBanner, */
+ /* print a file banner for fnum. */
+ /* */
+ /*****************************************************************************/
+
+ static void PrintFileBanner(int fnum)
+ { static int CurrentFileNum = -1;
+ if( fnum != CurrentFileNum )
+ { fprintf(fp, "lout%s:\n", EchoFileSource(fnum));
+ CurrentFileNum = fnum;
+ }
+ } /* end PrintFileBanner */
+
+
+ /*@::EnterErrorBlock(), LeaveErrorBlock()@************************************/
+ /* */
+ /* EnterErrorBlock(ok_to_print) */
+ /* */
+ /* Start off a new block of error messages. If ok_to_print, they do not */
+ /* need to be held for a later commit. */
+ /* */
+ /*****************************************************************************/
+
+ void EnterErrorBlock(BOOLEAN ok_to_print)
+ { if( block_top < MAX_BLOCKS )
+ { print_block[block_top] = ok_to_print;
+ start_block[block_top] = mess_top;
+ block_top++;
+ }
+ else Error(28, 3, "too many levels of error messages", FATAL, no_fpos);
+ } /* end EnterErrorBlock */
+
+
+ /*****************************************************************************/
+ /* */
+ /* LeaveErrorBlock(commit) */
+ /* */
+ /* Finish off a block of error messages. If commit is true, print them, */
+ /* otherwise discard them. */
+ /* */
+ /*****************************************************************************/
+
+ void LeaveErrorBlock(BOOLEAN commit)
+ { int i;
+ debug0(DYY, D, " leaving error block");
+ assert( block_top > 0, "LeaveErrorBlock: no matching EnterErrorBlock!" );
+ assert( commit || !print_block[block_top - 1], "LeaveErrorBlock: commit!" );
+ if( fp == NULL ) fp = stderr;
+ if( commit )
+ { for( i = start_block[block_top - 1]; i < mess_top; i++ )
+ {
+ if( AltErrorFormat )
+ { fputs(message[i], fp);
+ }
+ else
+ { PrintFileBanner(message_fnum[i]);
+ fputs(message[i], fp);
+ }
+ }
+ }
+ block_top--;
+ mess_top = start_block[block_top];
+ } /* end LeaveErrorBlock */
+
+
+ /*****************************************************************************/
+ /* */
+ /* CheckErrorBlocks() */
+ /* */
+ /* Check (at end of run) that all error blocks have been unstacked. */
+ /* */
+ /*****************************************************************************/
+
+ void CheckErrorBlocks(void)
+ { assert( block_top == 0, "CheckErrorBlocks: block_top != 0!" );
+ } /* end CheckErrorBlocks */
+
+
+ /*@::Error()@*****************************************************************/
+ /* */
+ /* Error(etype, pos, str, p1, p2, p3, p4, p5, p6) */
+ /* */
+ /* Report error of type etype at position *pos in input. */
+ /* The error message is str with parameters p1 - p6. */
+ /* */
+ /*****************************************************************************/
+
+ POINTER Error(int set_num, int msg_num, char *str, int etype, FILE_POS *pos, ...)
+ {
+ va_list ap;
+ char val[MAX_BUFF];
+ va_start(ap, pos);
+ vsprintf(val, condcatgets(MsgCat, set_num, msg_num, str), ap);
+ if( fp == NULL ) fp = stderr;
+ switch( etype )
+ {
+
+ case INTERN:
+
+ while( block_top > 0 ) LeaveErrorBlock(TRUE);
+ if( AltErrorFormat )
+ {
+ fprintf(fp, condcatgets(MsgCat, 28, 7, "%s internal error: %s\n"),
+ EchoAltFilePos(pos), val);
+ /* for estrip's benefit: Error(28, 7, "%s internal error: %s\n") */
+ }
+ else
+ {
+ PrintFileBanner(file_num(*pos));
+ fprintf(fp, condcatgets(MsgCat, 28, 4, " %6s internal error: %s\n"),
+ EchoFileLine(pos), val);
+ /* for estrip's benefit: Error(28, 4, " %6s internal error: %s\n") */
+ }
+ #if DEBUG_ON
+ abort();
+ #else
+ exit(1);
+ #endif
+ break;
+
+
+ case FATAL:
+
+ while( block_top > 0 ) LeaveErrorBlock(TRUE);
+ if( AltErrorFormat )
+ {
+ fprintf(fp, condcatgets(MsgCat, 28, 8, "%s: fatal error: %s\n"),
+ EchoAltFilePos(pos), val);
+ }
+ else
+ {
+ PrintFileBanner(file_num(*pos));
+ fprintf(fp, condcatgets(MsgCat, 28, 5, " %6s: fatal error: %s\n"),
+ EchoFileLine(pos), val);
+ }
+ /* for estrip's benefit: Error(28, 5, " %6s: fatal error: %s\n") */
+ /* for estrip's benefit: Error(28, 8, "%s: fatal error: %s\n") */
+ exit(1);
+ break;
+
+
+ case WARN:
+
+ if( block_top == 0 || print_block[block_top - 1] )
+ {
+ if( AltErrorFormat )
+ {
+ fprintf(fp, "%s: %s\n", EchoAltFilePos(pos), val);
+ }
+ else
+ {
+ PrintFileBanner(file_num(*pos));
+ fprintf(fp, " %6s: %s\n", EchoFileLine(pos), val);
+ }
+ }
+ else if( mess_top < MAX_ERRORS )
+ {
+ if( AltErrorFormat )
+ {
+ sprintf(message[mess_top++], "%s: %s\n", EchoAltFilePos(pos), val);
+ }
+ else
+ { message_fnum[mess_top] = file_num(*pos);
+ sprintf(message[mess_top++], " %6s: %s\n",
+ EchoFileLine(pos), val);
+ }
+ }
+ else Error(28, 6, "too many error messages", FATAL, pos);
+ error_seen = TRUE;
+ break;
+
+
+ default:
+
+ assert(FALSE, "Error: invalid error type");
+ break;
+
+ }
+ va_end(ap);
+ return 0;
+ } /* end Error */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z29.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z29.c:1.1
*** /dev/null Tue Jan 9 17:45:03 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z29.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,830 ----
+ /*@z29.c:Symbol Table:Declarations, hash()@***********************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z29.c */
+ /* MODULE: Symbol Table */
+ /* EXTERNS: InitSym(), PushScope(), PopScope(), SuppressVisible(), */
+ /* UnSuppressVisible(), SuppressScope(), UnSuppressScope(), */
+ /* SwitchScope(), UnSwitchScope(), BodyParAllowed(), */
+ /* BodyParNotAllowed(), InsertSym(), SearchSym(), */
+ /* SymName(), FullSymName(), ChildSym(), CheckSymSpread(), */
+ /* DeleteEverySym() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ #define MAX_STACK 300 /* size of scope stack */
+ #define MAX_TAB 1783 /* size of hash table */
+
+ #define length(x) word_font(x)
+
+ static OBJECT scope[MAX_STACK]; /* the scope stack */
+ static BOOLEAN npars_only[MAX_STACK]; /* look for NPAR exc */
+ static BOOLEAN vis_only[MAX_STACK]; /* look for visibles */
+ static BOOLEAN body_ok[MAX_STACK]; /* look for body par */
+ static BOOLEAN suppress_scope; /* suppress scoping */
+ static BOOLEAN suppress_visible; /* suppress visible */
+ static int scope_top; /* scope stack top */
+ static struct { OBJECT f1, f2; } symtab[MAX_TAB]; /* the hash table */
+ #if DEBUG_ON
+ static int sym_spread[MAX_TAB] = { 0 }; /* hash table spread */
+ static int sym_count = 0; /* symbol count */
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* #define hash(str, len, val) */
+ /* */
+ /* Set val to the hash value of string str, which has length len. */
+ /* The hash function is just the character sum mod MAX_TAB. */
+ /* This definition assumes that working variables rlen and x exist. */
+ /* */
+ /*****************************************************************************/
+
+ #define hash(str, len, val) \
+ { rlen = len; \
+ x = str; \
+ val = *x++; \
+ while( --rlen ) val += *x++; \
+ val %= MAX_TAB; \
+ }
+
+
+ /*@::InitSym(), PushScope(), PopScope(), SuppressVisible(), etc.@*************/
+ /* */
+ /* InitSym() */
+ /* */
+ /* Initialize the symbol table to empty. */
+ /* */
+ /*****************************************************************************/
+
+ void InitSym(void)
+ { int i;
+ scope_top = 0;
+ suppress_scope = FALSE;
+ suppress_visible = FALSE;
+ for( i = 0; i < MAX_TAB; i++ )
+ symtab[i].f1 = symtab[i].f2 = (OBJECT) &symtab[i];
+ } /* end InitSym */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PushScope(x, npars, vis) */
+ /* PopScope() */
+ /* */
+ /* Add or remove an OBJECT x (which must be in the symbol table) to or from */
+ /* the scope stack. If npars is TRUE, only the named parameters of x are */
+ /* added to scope. If vis is TRUE, only visible locals and parameters are */
+ /* added. */
+ /* */
+ /*****************************************************************************/
+
+ void PushScope(OBJECT x, BOOLEAN npars, BOOLEAN vis)
+ { debug3(DST, DD, "[ PushScope(%s, %s, %s)", SymName(x), bool(npars), bool(vis));
+ assert( suppress_scope == FALSE, "PushScope: suppress_scope!" );
+ if( scope_top >= MAX_STACK )
+ {
+ #if DEBUG_ON
+ int i;
+ for( i = 0; i < scope_top; i++ )
+ Error(29, 1, " scope[%2d] = %s", WARN, &fpos(x), i, SymName(scope[i]));
+ #endif
+ Error(29, 2, "scope depth limit exceeded", INTERN, &fpos(x));
+ }
+ scope[scope_top] = x;
+ npars_only[scope_top] = npars;
+ vis_only[scope_top] = vis;
+ body_ok[scope_top] = FALSE;
+ scope_top++;
+ } /* end PushScope */
+
+ void PopScope(void)
+ { debug0(DST, DD, "] PopScope()");
+ assert( scope_top > 0, "PopScope: tried to pop empty scope stack");
+ assert( suppress_scope == FALSE, "PopScope: suppress_scope!" );
+ scope_top--;
+ } /* end PopScope */
+
+
+ /*****************************************************************************/
+ /* */
+ /* SuppressVisible() */
+ /* UnSuppressVisible() */
+ /* */
+ /* Make all children of any symbol acceptable, not just the exported ones. */
+ /* */
+ /*****************************************************************************/
+
+ void SuppressVisible(void)
+ { debug0(DST, DD, "[ SuppressVisible()");
+ suppress_visible = TRUE;
+ } /* end SuppressVisible */
+
+ void UnSuppressVisible(void)
+ { debug0(DST, DD, "] UnSuppressVisible()");
+ suppress_visible = FALSE;
+ } /* end UnSuppressVisible */
+
+
+ /*@::SuppressScope(), UnSuppressScope(), SwitchScope(), UnswitchScope()@******/
+ /* */
+ /* SuppressScope() */
+ /* UnSuppressScope() */
+ /* */
+ /* Suppress all scopes (so that all calls to SearchSym fail); and undo it. */
+ /* */
+ /*****************************************************************************/
+
+
+ void SuppressScope(void)
+ { debug0(DST, DD, "[ SuppressScope()");
+ suppress_scope = TRUE;
+ } /* end SuppressScope */
+
+ void UnSuppressScope(void)
+ { debug0(DST, DD, "] UnSuppressScope()");
+ suppress_scope = FALSE;
+ } /* end UnSuppressScope */
+
+
+ /*****************************************************************************/
+ /* */
+ /* SwitchScope(sym) */
+ /* UnSwitchScope(sym) */
+ /* */
+ /* Switch to the scope of sym (if nilobj, StartSym); and switch back again. */
+ /* */
+ /*****************************************************************************/
+
+ void SwitchScope(OBJECT sym)
+ { int i;
+ OBJECT new_scopes[MAX_STACK];
+ if( sym == nilobj ) PushScope(StartSym, FALSE, FALSE);
+ else
+ { i = 0;
+ while( sym != StartSym )
+ { new_scopes[i++] = enclosing(sym);
+ sym = enclosing(sym);
+ }
+ while( i > 0 ) PushScope(new_scopes[--i], FALSE, FALSE);
+ }
+ }
+
+ void UnSwitchScope(OBJECT sym)
+ { if( sym == nilobj ) PopScope();
+ else
+ { while( sym != StartSym )
+ { PopScope();
+ sym = enclosing(sym);
+ }
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* BodyParAllowed() */
+ /* BodyParNotAllowed() */
+ /* */
+ /* Allow or disallow invocations of the body parameter of the current tos. */
+ /* */
+ /*****************************************************************************/
+
+ void BodyParAllowed(void)
+ { debug0(DST, DD, "BodyParAllowed()");
+ body_ok[scope_top-1] = TRUE;
+ } /* end BodyParAllowed */
+
+ void BodyParNotAllowed(void)
+ { debug0(DST, DD, "BodyParNotAllowed()");
+ body_ok[scope_top-1] = FALSE;
+ } /* end BodyParNotAllowed */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DebugScope(void) */
+ /* */
+ /* Debug print of current scope stack */
+ /* */
+ /*****************************************************************************/
+
+ void DebugScope(void)
+ { int i;
+ if( suppress_scope )
+ {
+ debug0(DST, D, "suppressed");
+ }
+ else for( i = 0; i < scope_top; i++ )
+ { debug6(DST, D, "%s %s%s%s%s%s",
+ i == scope_top - 1 ? "->" : " ",
+ SymName(scope[i]),
+ npars_only[i] ? " npars_only" : "",
+ vis_only[i] ? " vis_only" : "",
+ body_ok[i] ? " body_ok" : "",
+ i == scope_top - 1 && suppress_visible ? " suppress_visible" : "");
+ }
+ } /* end DebugScope */
+
+
+ /*@::ScopeSnapshot()@*********************************************************/
+ /* */
+ /* OBJECT GetScopeSnapshot() */
+ /* LoadScopeSnapshot(ss) */
+ /* ClearScopeSnapshot(ss) */
+ /* */
+ /* A scope snapshot is a complete record of the state of the scope stack */
+ /* at some moment. These routines allow you to take a scope snapshot, */
+ /* then subsequently load it (i.e. make it the current scope), then */
+ /* subsequently clear it (i.e. return to whatever was before the Load). */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT GetScopeSnapshot()
+ { OBJECT ss, x; int i;
+ New(ss, ACAT);
+ for( i = scope_top-1; scope[i] != StartSym; i-- )
+ {
+ New(x, SCOPE_SNAPSHOT);
+ Link(ss, x);
+ Link(x, scope[i]);
+ ss_npars_only(x) = npars_only[i];
+ ss_vis_only(x) = vis_only[i];
+ ss_body_ok(x) = body_ok[i];
+ }
+ ss_suppress(ss) = suppress_visible;
+ return ss;
+ } /* end GetScopeSnapshot */
+
+
+ void LoadScopeSnapshot(OBJECT ss)
+ { OBJECT link, x, sym; BOOLEAN tmp;
+ assert( type(ss) == ACAT, "LoadScopeSnapshot: type(ss)!" );
+ PushScope(StartSym, FALSE, FALSE);
+ for( link = LastDown(ss); link != ss; link = PrevDown(link) )
+ { Child(x, link);
+ assert( type(x) == SCOPE_SNAPSHOT, "LoadScopeSnapshot: type(x)!" );
+ Child(sym, Down(x));
+ PushScope(sym, ss_npars_only(x), ss_vis_only(x));
+ body_ok[scope_top-1] = ss_body_ok(x);
+ }
+ tmp = suppress_visible;
+ suppress_visible = ss_suppress(ss);
+ ss_suppress(ss) = tmp;
+ debug0(DST, D, "after LoadScopeSnapshot, scope is:")
+ ifdebug(DST, D, DebugScope());
+ } /* end LoadScopeSnapshot */
+
+
+ void ClearScopeSnapshot(OBJECT ss)
+ {
+ while( scope[scope_top-1] != StartSym )
+ scope_top--;
+ scope_top--;
+ suppress_visible = ss_suppress(ss);
+ } /* end ClearScopeSnapshot */
+
+
+ /*@::InsertSym()@*************************************************************/
+ /* */
+ /* OBJECT InsertSym(str, xtype, xfpos, xprecedence, indefinite, xrecursive, */
+ /* xpredefined, xenclosing, xbody) */
+ /* */
+ /* Insert a new symbol into the table. Its string value is str. */
+ /* Initialise the symbol as the parameters indicate. */
+ /* Return a pointer to the new symbol. */
+ /* If str is not a valid symbol name, InsertSym prints an error */
+ /* message and does not insert the symbol. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT InsertSym(FULL_CHAR *str, unsigned char xtype, FILE_POS *xfpos,
+ unsigned char xprecedence, BOOLEAN xindefinite, BOOLEAN xrecursive,
+ unsigned xpredefined, OBJECT xenclosing, OBJECT xbody)
+ { register int sum, rlen;
+ register unsigned char *x;
+ OBJECT p, q, s, tmp, link, entry, plink; int len;
+
+ debug3(DST, DD, "InsertSym( %s, %s, in %s )",
+ Image(xtype), str, SymName(xenclosing));
+ if( !LexLegalName(str) )
+ Error(29, 3, "invalid symbol name %s", WARN, xfpos, str);
+
+ New(s, xtype);
+ FposCopy(fpos(s), *xfpos);
+ has_body(s) = FALSE;
+ filter(s) = nilobj;
+ use_invocation(s) = nilobj;
+ imports(s) = nilobj;
+ imports_encl(s) = FALSE;
+ right_assoc(s) = TRUE;
+ precedence(s) = xprecedence;
+ indefinite(s) = xindefinite;
+ recursive(s) = xrecursive;
+ predefined(s) = xpredefined;
+ enclosing(s) = xenclosing;
+ sym_body(s) = xbody;
+ base_uses(s) = nilobj;
+ uses(s) = nilobj;
+ marker(s) = nilobj;
+ cross_sym(s) = nilobj;
+ is_extern_target(s) = FALSE;
+ uses_extern_target(s)= FALSE;
+ visible(s) = FALSE;
+ uses_galley(s) = FALSE;
+ horiz_galley(s) = ROWM;
+ has_compulsory(s) = 0;
+ is_compulsory(s) = FALSE;
+
+ uses_count(s) = 0;
+ dirty(s) = FALSE;
+ if( enclosing(s) != nilobj && type(enclosing(s)) == NPAR )
+ dirty(s) = dirty(enclosing(s)) = TRUE;
+
+ has_par(s) = FALSE;
+ has_lpar(s) = FALSE;
+ has_rpar(s) = FALSE;
+ if( is_par(type(s)) ) has_par(enclosing(s)) = TRUE;
+ if( type(s) == LPAR ) has_lpar(enclosing(s)) = TRUE;
+ if( type(s) == RPAR ) has_rpar(enclosing(s)) = TRUE;
+
+ /* assign a code letter between a and z to any NPAR symbol */
+ if( type(s) == NPAR )
+ { if( LastDown(enclosing(s)) != enclosing(s) )
+ { Child(tmp, LastDown(enclosing(s)));
+ if( type(tmp) == NPAR )
+ { if( npar_code(tmp) == 'z' || npar_code(tmp) == ' ' )
+ npar_code(s) = ' ';
+ else
+ npar_code(s) = npar_code(tmp)+1;
+ }
+ else
+ npar_code(s) = 'a';
+ }
+ else npar_code(s) = 'a';
+ }
+
+ has_target(s) = FALSE;
+ force_target(s) = FALSE;
+ if( !StringEqual(str, KW_TARGET) ) is_target(s) = FALSE;
+ else
+ { is_target(s) = has_target(enclosing(s)) = TRUE;
+
+ /* if @Target is found after @Key, take note of external target */
+ if( has_key(enclosing(s)) && xbody != nilobj && is_cross(type(xbody)) )
+ { if( LastDown(xbody) != Down(xbody) )
+ { OBJECT sym;
+ Child(sym, Down(xbody));
+ if( type(sym) == CLOSURE )
+ { is_extern_target(actual(sym)) = TRUE;
+ uses_extern_target(actual(sym)) = TRUE;
+ }
+ }
+ }
+ }
+
+ has_tag(s) = is_tag(s) = FALSE;
+ has_key(s) = is_key(s) = FALSE;
+ has_optimize(s) = is_optimize(s) = FALSE;
+ has_merge(s) = is_merge(s) = FALSE;
+ has_enclose(s) = is_enclose(s) = FALSE;
+ if( enclosing(s) != nilobj && type(enclosing(s)) == LOCAL )
+ {
+ if( StringEqual(str, KW_TAG) )
+ is_tag(s) = has_tag(enclosing(s)) = dirty(enclosing(s)) = TRUE;
+
+ if( StringEqual(str, KW_OPTIMIZE) )
+ is_optimize(s) = has_optimize(enclosing(s)) = TRUE;
+
+ if( StringEqual(str, KW_KEY) )
+ { is_key(s) = has_key(enclosing(s)) = dirty(enclosing(s)) = TRUE;
+
+ /* if @Key is found after @Target, take note of external target */
+ for( link=Down(enclosing(s)); link!=enclosing(s); link=NextDown(link) )
+ { Child(p, link);
+ if( is_target(p) && sym_body(p)!=nilobj && is_cross(type(sym_body(p))) )
+ { OBJECT sym;
+ Child(sym, Down(sym_body(p)));
+ if( type(sym) == CLOSURE )
+ { is_extern_target(actual(sym)) = TRUE;
+ uses_extern_target(actual(sym)) = TRUE;
+ }
+ }
+ }
+ }
+
+ if( StringEqual(str, KW_MERGE) )
+ is_merge(s) = has_merge(enclosing(s)) = TRUE;
+
+ if( StringEqual(str, KW_ENCLOSE) )
+ is_enclose(s) = has_enclose(enclosing(s)) = TRUE;
+ }
+
+ if( StringEqual(str, KW_FILTER) )
+ { if( type(s) != LOCAL || enclosing(s) == StartSym )
+ Error(29, 4, "%s must be a local definition", WARN, &fpos(s), str);
+ else if( !has_rpar(enclosing(s)) )
+ Error(29, 14, "%s must lie within a symbol with a right parameter",
+ WARN, &fpos(s), KW_FILTER);
+ else
+ { filter(enclosing(s)) = s;
+ precedence(enclosing(s)) = FILTER_PREC;
+ }
+ }
+
+ if( type(s) == RPAR && has_body(enclosing(s)) &&
+ (is_tag(s) || is_key(s) || is_optimize(s)) )
+ Error(29, 5, "a body parameter may not be named %s", WARN, &fpos(s), str);
+
+ if( type(s) == RPAR && has_target(enclosing(s)) &&
+ (is_tag(s) || is_key(s) || is_optimize(s)) )
+ Error(29, 6, "the right parameter of a galley may not be called %s",
+ WARN, &fpos(s), str);
+
+ len = StringLength(str);
+ hash(str, len, sum);
+
+ ifdebug(DST, DD, sym_spread[sum]++; sym_count++);
+ entry = (OBJECT) &symtab[sum];
+ for( plink = Down(entry); plink != entry; plink = NextDown(plink) )
+ { Child(p, plink);
+ if( length(p) == len && StringEqual(str, string(p)) )
+ { for( link = Down(p); link != p; link = NextDown(link) )
+ { Child(q, link);
+ if( enclosing(s) == enclosing(q) )
+ { Error(29, 7, "symbol %s previously defined at%s",
+ WARN, &fpos(s), str, EchoFilePos(&fpos(q)) );
+ if( AltErrorFormat )
+ {
+ Error(29, 13, "symbol %s previously defined here",
+ WARN, &fpos(q), str);
+ }
+ break;
+ }
+ }
+ goto wrapup;
+ }
+ }
+
+ /* need a new OBJECT as well as s */
+ NewWord(p, WORD, len, xfpos);
+ length(p) = len;
+ StringCopy(string(p), str);
+ Link(entry, p);
+
+ wrapup:
+ Link(p, s);
+ if( enclosing(s) != nilobj ) Link(enclosing(s), s);
+ debug2(DST, DD, "InsertSym Link(%s, %s) and returning.",
+ SymName(enclosing(s)), SymName(s));
+ return s;
+ } /* end InsertSym */
+
+
+ /*****************************************************************************/
+ /* */
+ /* InsertAlternativeName(str, s, xfpos) */
+ /* */
+ /* Insert an alternative name for symbol s. */
+ /* */
+ /*****************************************************************************/
+
+ void InsertAlternativeName(FULL_CHAR *str, OBJECT s, FILE_POS *xfpos)
+ { register int sum, rlen;
+ register unsigned char *x;
+ int len;
+ OBJECT entry, link, plink, p, q;
+ debug3(DST, DD, "InsertAlternativeName(%s, %s, %s)",
+ str, SymName(s), EchoFilePos(xfpos));
+
+ len = StringLength(str);
+ hash(str, len, sum);
+
+ ifdebug(DST, DD, sym_spread[sum]++; sym_count++);
+ entry = (OBJECT) &symtab[sum];
+ for( plink = Down(entry); plink != entry; plink = NextDown(plink) )
+ { Child(p, plink);
+ if( length(p) == len && StringEqual(str, string(p)) )
+ { for( link = Down(p); link != p; link = NextDown(link) )
+ { Child(q, link);
+ if( enclosing(s) == enclosing(q) )
+ { Error(29, 12, "symbol name %s previously defined at%s",
+ WARN, &fpos(s), str, EchoFilePos(&fpos(q)) );
+ break;
+ }
+ }
+ goto wrapup;
+ }
+ }
+
+ /* need a new OBJECT as well as s */
+ NewWord(p, WORD, len, xfpos);
+ length(p) = len;
+ StringCopy(string(p), str);
+ Link(entry, p);
+
+ wrapup:
+ Link(p, s);
+ /* not for copies if( enclosing(s) != nilobj ) Link(enclosing(s), s); */
+ debug0(DST, DD, "InsertAlternativeName returning.");
+ } /* end InsertAlternativeName */
+
+
+ /*@::SearchSym(), SymName()@**************************************************/
+ /* */
+ /* OBJECT SearchSym(str, len) */
+ /* */
+ /* Search the symbol table for str, with length len, and return an */
+ /* OBJECT referencing the entry if found. Otherwise return nilobj. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT SearchSym(FULL_CHAR *str, int len)
+ { register int rlen, sum;
+ register FULL_CHAR *x, *y;
+ OBJECT p, q, link, plink, entry;
+ int s;
+
+ debug2(DST, DDD, "SearchSym( %c..., %d )", str[0], len);
+
+ hash(str, len, sum);
+ rlen = len;
+ entry = (OBJECT) &symtab[sum];
+ for( plink = Down(entry); plink != entry; plink = NextDown(plink) )
+ { Child(p, plink);
+ if( rlen == length(p) )
+ { x = str; y = string(p);
+ do; while( *x++ == *y++ && --rlen );
+ if( rlen == 0 )
+ {
+ debug1(DST, DDD, " found %s", string(p));
+ s = scope_top;
+ do
+ { s--;
+ for( link = Down(p); link != p; link = NextDown(link) )
+ { Child(q, link);
+ { debugcond4(DST, DDD, enclosing(q) == scope[s],
+ " !npars_only[s] = %s, !vis_only[s] = %s, body_ok[s] = %s, !ss = %s",
+ bool(!npars_only[s]), bool(!vis_only[s]), bool(body_ok[s]),
+ bool(!suppress_scope));
+ }
+ if( enclosing(q) == scope[s]
+ && (!npars_only[s] || type(q) == NPAR)
+ && (!vis_only[s] || visible(q) || suppress_visible )
+ && (body_ok[s] || type(q)!=RPAR || !has_body(enclosing(q))
+ || suppress_visible )
+ && (!suppress_scope || StringEqual(string(p), KW_INCLUDE) ||
+ StringEqual(string(p), KW_SYSINCLUDE))
+ )
+ { debug3(DST, DD, "SearchSym returning %s %s%%%s",
+ Image(type(q)), SymName(q), SymName(enclosing(q)));
+ return q;
+ }
+ }
+ } while( scope[s] != StartSym );
+ }
+ }
+ rlen = len;
+ }
+ debug0(DST, DDD, "SearchSym returning <nilobj>");
+ return nilobj;
+ } /* end SearchSym */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *SymName(s) */
+ /* */
+ /* Return the string value of the name of symbol s. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *SymName(OBJECT s)
+ { OBJECT p;
+ if( s == nilobj ) return AsciiToFull("<nilobj>");
+ Parent(p, Up(s));
+ assert( is_word(type(p)), "SymName: !is_word(type(p))!" );
+ return string(p);
+ } /* end SymName */
+
+
+ /*@::FullSymName(), ChildSym()@***********************************************/
+ /* */
+ /* FULL_CHAR *FullSymName(x, str) */
+ /* */
+ /* Return the path name of symbol x. with str separating each entry. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *FullSymName(OBJECT x, FULL_CHAR *str)
+ { OBJECT stack[20]; int i;
+ static FULL_CHAR buff[MAX_BUFF], *sname;
+ if( x == nilobj ) return AsciiToFull("<nilobj>");
+ assert( enclosing(x) != nilobj, "FullSymName: enclosing(x) == nilobj!" );
+ for( i = 0; enclosing(x) != nilobj && i < 20; i++ )
+ { stack[i] = x;
+ x = enclosing(x);
+ }
+ StringCopy(buff, STR_EMPTY);
+ for( i--; i > 0; i-- )
+ { sname = SymName(stack[i]);
+ if( StringLength(sname)+StringLength(str)+StringLength(buff) >= MAX_BUFF )
+ Error(29, 8, "full name of symbol is too long", FATAL, &fpos(x));
+ StringCat(buff, sname);
+ StringCat(buff, str);
+ }
+ sname = SymName(stack[0]);
+ if( StringLength(sname) + StringLength(buff) >= MAX_BUFF )
+ Error(29, 9, "full name of symbol is too long", FATAL, &fpos(x));
+ StringCat(buff, sname);
+ return buff;
+ } /* end FullSymName */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT ChildSym(s, typ) */
+ /* */
+ /* Find the child of symbol s of type typ, either LPAR or RPAR. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT ChildSym(OBJECT s, unsigned typ)
+ { OBJECT link, y;
+ for( link = Down(s); link != s; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == typ && enclosing(y) == s ) return y;
+ }
+ Error(29, 10, "symbol %s has missing %s", FATAL, &fpos(s),
+ SymName(s), Image(typ));
+ return nilobj;
+ } /* end ChildSym */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT ChildSymWithCode(s, code) */
+ /* */
+ /* Find the child of symbol s with the given npar code, else nil. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT ChildSymWithCode(OBJECT s, unsigned char code)
+ { OBJECT link, y;
+ for( link = Down(actual(s)); link != actual(s); link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == NPAR && enclosing(y) == actual(s) && npar_code(y) == code )
+ return y;
+ }
+ Error(29, 11, "symbol %s has erroneous code %c (database out of date?)",
+ FATAL, &fpos(s), SymName(actual(s)), (char) code);
+ return nilobj;
+ } /* end ChildSym */
+
+
+ /*@::CheckSymSpread(), DeleteSymBody()@***************************************/
+ /* */
+ /* CheckSymSpread() */
+ /* */
+ /* Check the spread of symbols through the hash table. */
+ /* */
+ /*****************************************************************************/
+ #if DEBUG_ON
+
+ void CheckSymSpread(void)
+ { int i, j, sum, usum; OBJECT entry, plink;
+ debug2(DST, DD, "Symbol table spread (table size = %d, symbols = %d):",
+ MAX_TAB, sym_count);
+ usum = sum = 0;
+ for( i = 0; i < MAX_TAB; i++ )
+ { fprintf(stderr, "%4d: ", i);
+ for( j = 1; j <= sym_spread[i]; j++ )
+ { fprintf(stderr, ".");
+ sum += j;
+ }
+ entry = (OBJECT) &symtab[i];
+ for( plink=Down(entry), j=1; plink != entry; plink=NextDown(plink), j++ )
+ { fprintf(stderr, "+");
+ usum += j;
+ }
+ fprintf(stderr, "\n");
+ }
+ fprintf(stderr, "average length counting duplicate names = %.1f\n",
+ (float) sum / sym_count);
+ fprintf(stderr, "average length not counting duplicate names = %.1f\n",
+ (float) usum / sym_count);
+ } /* end CheckSymSpread */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static DeleteSymBody(s) */
+ /* */
+ /* Delete the body of symbol s. */
+ /* */
+ /*****************************************************************************/
+
+ static void DeleteSymBody(OBJECT s)
+ { OBJECT t;
+ debug1(DST, DDD, "DeleteSymBody( %s )", SymName(s));
+ switch( type(s) )
+ {
+ case MACRO: while( sym_body(s) != nilobj )
+ { t = sym_body(s);
+ sym_body(s) = Delete(sym_body(s), PARENT);
+ Dispose(t);
+ }
+ break;
+
+ case LPAR:
+ case NPAR:
+ case RPAR:
+ case LOCAL: if( sym_body(s) != nilobj ) DisposeObject(sym_body(s));
+ break;
+
+ default: assert1(FALSE, "DeleteSymBody:", Image(type(s)));
+ break;
+ }
+ debug0(DST, DDD, "DeleteSymBody returning.");
+ } /* end DeleteSymBody */
+
+
+ /*@::DeleteEverySym()@********************************************************/
+ /* */
+ /* DeleteEverySym() */
+ /* */
+ /* Delete every symbol in the symbol table. */
+ /* Note that we first delete all bodies, then the symbols themselves. */
+ /* This is so that the closures within the bodies have well-defined */
+ /* actual() pointers, even while the symbol table is being disposed. */
+ /* If this is not done, debug output during the disposal gets confused. */
+ /* */
+ /*****************************************************************************/
+
+ void DeleteEverySym(void)
+ { int i, j, load, cost; OBJECT p, plink, link, x, entry;
+ debug0(DST, DD, "DeleteEverySym()");
+
+ /* dispose the bodies of all symbols */
+ for( i = 0; i < MAX_TAB; i++ )
+ { entry = (OBJECT) &symtab[i];
+ for( plink = Down(entry); plink != entry; plink = NextDown(plink) )
+ { Child(p, plink);
+ for( link = Down(p); link != p; link = NextDown(link) )
+ { Child(x, link); DeleteSymBody(x);
+ /* *** will not work now
+ while( base_uses(x) != nilobj )
+ { tmp = base_uses(x); base_uses(x) = next(tmp);
+ PutMem(tmp, USES_SIZE);
+ }
+ while( uses(x) != nilobj )
+ { tmp = uses(x); uses(x) = next(tmp);
+ PutMem(tmp, USES_SIZE);
+ }
+ *** */
+ }
+ }
+ }
+
+ /* dispose the symbol name strings, gather statistics, and print them */
+ load = cost = 0;
+ for( i = 0; i < MAX_TAB; i++ )
+ { j = 1; entry = (OBJECT) &symtab[i];
+ while( Down(entry) != entry )
+ { load += 1; cost += j; j += 1;
+ DisposeChild(Down(entry));
+ }
+ }
+ if( load > 0 )
+ { debug4(DST, DD, "size = %d, items = %d (%d%%), probes = %.1f",
+ MAX_TAB, load, (100*load)/MAX_TAB, (float) cost/load);
+ }
+ else
+ { debug1(DST, DD, "table size = %d, no entries in table", MAX_TAB);
+ }
+ debug0(DST, DD, "DeleteEverySym returning.");
+ } /* end DeleteEverySym */
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z30.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z30.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z30.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,192 ----
+ /*@z30.c:Symbol uses:InsertUses()@********************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z30.c */
+ /* MODULE: Symbol Uses */
+ /* EXTERNS: InsertUses(), FlattenUses(), SearchUses(), */
+ /* FirstExternTarget(), NextExternTarget() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* InsertUses(x, y) */
+ /* */
+ /* Record the fact that symbol x uses symbol y, by linking them. */
+ /* Increment count of the number of times y is used, if y is a parameter. */
+ /* */
+ /*****************************************************************************/
+
+ void InsertUses(OBJECT x, OBJECT y)
+ { OBJECT tmp;
+ debug2(DSU, D, "InsertUses( %s, %s )", SymName(x), SymName(y));
+ if( type(x) == LOCAL && type(y) == LOCAL && !predefined(y) )
+ { GetMem(tmp, USES_SIZE, no_fpos); item(tmp) = y;
+ if( base_uses(x) == nilobj ) next(tmp) = tmp;
+ else next(tmp) = next(base_uses(x)), next(base_uses(x)) = tmp;
+ base_uses(x) = tmp;
+ }
+ if( is_par(type(y)) )
+ {
+ uses_count(y) += (enclosing(y) == x ? 1 : 2);
+ if( dirty(y) || uses_count(y) > 1 ) dirty(enclosing(y)) = TRUE;
+ }
+ else if( sym_body(y) == nilobj || dirty(y) ) dirty(x) = TRUE;
+ debug5(DSU, D, "InsertUses returning ( %s %s; %s %s, count = %d )",
+ SymName(x), (dirty(x) ? "dirty" : "clean"),
+ SymName(y), (dirty(y) ? "dirty" : "clean"), uses_count(y));
+ } /* end InsertUses */
+
+
+ /*@::GatherUses(), GatherAllUses(), FlattenUses()@****************************/
+ /* */
+ /* static GatherUses(x, sym) */
+ /* static GatherAllUses(x) */
+ /* */
+ /* GatherUses adds all the unmarked descendants of x to the uses relation */
+ /* of sym; GatherAllUses applies gather_uses to all descendants of x. */
+ /* */
+ /*****************************************************************************/
+
+ static void GatherUses(OBJECT x, OBJECT sym)
+ { OBJECT link, y, tmp;
+ if( base_uses(x) != nilobj )
+ { link = next(base_uses(x));
+ do
+ { y = item(link);
+ if( marker(y) != sym )
+ { if( y != sym )
+ { marker(y) = sym;
+ GetMem(tmp, USES_SIZE, no_fpos); item(tmp) = y;
+ if( uses(sym) == nilobj ) next(tmp) = tmp;
+ else next(tmp) = next(uses(sym)), next(uses(sym)) = tmp;
+ uses(sym) = tmp;
+ if( indefinite(y) ) indefinite(sym) = TRUE;
+ if( uses_extern_target(y) ) uses_extern_target(sym) = TRUE;
+ GatherUses(y, sym);
+ }
+ else recursive(sym) = TRUE;
+ }
+ link = next(link);
+ } while( link != next(base_uses(x)) );
+ }
+ } /* end GatherUses */
+
+
+ static void GatherAllUses(OBJECT x)
+ { OBJECT link, y;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == LOCAL ) GatherUses(y, y);
+ GatherAllUses(y);
+ }
+ } /* end GatherAllUses */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FlattenUses() */
+ /* */
+ /* Traverse the directed graph assembled by InsertUses, finding its */
+ /* transitive closure and storing this explicitly in uses(x) for all x. */
+ /* */
+ /*****************************************************************************/
+
+ void FlattenUses(void)
+ { GatherAllUses(StartSym);
+ } /* end FlattenUses */
+
+
+ /*@::SearchUses(), FirstExternTarget(), NextExternTarget()@*******************/
+ /* */
+ /* BOOLEAN SearchUses(x, y) */
+ /* */
+ /* Discover whether symbol x uses symbol y by searching the uses list of x. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN SearchUses(OBJECT x, OBJECT y)
+ { OBJECT p;
+ debug3(DSU, DD, "SearchUses(%s, %s) uses: %d", SymName(x),SymName(y),uses(x));
+ if( x == y ) return TRUE;
+ if( uses(x) != nilobj )
+ { p = next(uses(x));
+ do
+ { debug1(DSU, DDD, " checking %s", SymName(item(p)));
+ if( item(p) == y ) return TRUE;
+ p = next(p);
+ } while( p != next(uses(x)) );
+ }
+ return FALSE;
+ } /* end SearchUses */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT FirstExternTarget(sym, cont) */
+ /* OBJECT NextExternTarget(sym, cont) */
+ /* */
+ /* Together these two procedures return all symbols which are both used by */
+ /* sym and a target for at least one external galley. Return nilobj at end.*/
+ /* */
+ /*****************************************************************************/
+
+ OBJECT FirstExternTarget(OBJECT sym, OBJECT *cont)
+ { OBJECT res;
+ debug1(DSU, D, "FirstExternTarget( %s )", SymName(sym));
+ res = nilobj; *cont = nilobj;
+ if( is_extern_target(sym) ) res = sym;
+ else if( uses(sym) != nilobj )
+ { *cont = next(uses(sym));
+ do
+ { if( is_extern_target(item(*cont)) )
+ { res = item(*cont);
+ break;
+ }
+ *cont = next(*cont);
+ } while( *cont != next(uses(sym)) );
+ }
+ debug1(DSU, D, "FirstExternTarget returning %s", SymName(res));
+ return res;
+ } /* end FirstExternTarget */
+
+ OBJECT NextExternTarget(OBJECT sym, OBJECT *cont)
+ { OBJECT res;
+ debug1(DSU, D, "NextExternTarget( %s )", SymName(sym));
+ res = nilobj;
+ if( *cont != nilobj )
+ { *cont = next(*cont);
+ while( *cont != next(uses(sym)) )
+ { if( is_extern_target(item(*cont)) )
+ { res = item(*cont);
+ break;
+ }
+ *cont = next(*cont);
+ }
+ }
+ debug1(DSU, D, "NextExternTarget returning %s", SymName(res));
+ return res;
+ } /* end NextExternTarget */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,374 ----
+ /*@z31.c:Memory Allocator:DebugMemory()@**************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z31.c */
+ /* MODULE: Memory Allocator */
+ /* EXTERNS: DebugMemory(), zz_free[], MemInit(), GetMemory() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ #define MEM_CHUNK 1020 /* how many ALIGNs to get from sys */
+
+
+ #if DEBUG_ON
+ static int no_of_calls = 0; /* number of calls to calloc() */
+ static int recs_created = 0; /* number of records created */
+ static int bytes_created = 0; /* number of bytes in created recs */
+ int zz_newcount = 0; /* number of calls to New() */
+ int zz_disposecount = 0; /* number of calls to Dispose() */
+ int zz_listcount = 0; /* number of elements in zz_free[] */
+
+ static int usage_nums[MEM_USAGE_MAX] = { 0 };
+ static int usage_bytes[MEM_USAGE_MAX] = { 0 };
+ static int max_usage_bytes[MEM_USAGE_MAX] = { 0 };
+ static int curr_total_bytes, max_total_bytes = 0;
+ static char *usage_strings[] = {
+ "lout binary",
+ "object memory chunks",
+ "font tables",
+ "lex buffers",
+ "file tables",
+ "cross reference tables",
+ "plain text output grids",
+ "database check tables",
+ "hyphenation pattern tables",
+ "character mappings",
+ "colour tables",
+ "language tables",
+ };
+
+ /*****************************************************************************/
+ /* */
+ /* DebugRegisterUsage(typ, delta_num, delta_size) */
+ /* */
+ /* Register a change in the number of things of type typ that */
+ /* have been allocated memory, and the change in the number of bytes. */
+ /* */
+ /*****************************************************************************/
+
+ void DebugRegisterUsage(int typ, int delta_num, int delta_size)
+ { int i;
+ assert(0 <= typ && typ < MEM_USAGE_MAX, "DebugRegisterUsage!");
+ usage_nums[typ] += delta_num;
+ usage_bytes[typ] += delta_size;
+ curr_total_bytes += delta_size;
+ if( curr_total_bytes > max_total_bytes )
+ { max_total_bytes = curr_total_bytes;
+ for( i = 0; i < MEM_USAGE_MAX; i++ )
+ max_usage_bytes[i] = usage_bytes[i];
+ }
+ } /* end DebugRegisterUsage */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DebugMemory() */
+ /* */
+ /* Print memory usage. */
+ /* */
+ /*****************************************************************************/
+
+ void DebugMemory(void)
+ { int i, j; OBJECT p; int recs_free, bytes_free;
+
+ recs_free = bytes_free = 0;
+ for( i = 0; i < MAX_OBJECT_REC; i++ )
+ { if( zz_free[i] != nilobj )
+ { j = 0;
+ for( p = zz_free[i]; p != nilobj; p = pred(p, CHILD) ) j++;
+ debug3(DMA, DD, "zz_free[%2d]: %5d (%d bytes)", i, j,
+ i * j * sizeof(ALIGN));
+ recs_free += j;
+ bytes_free += i* j * sizeof(ALIGN);
+ }
+ }
+
+ debug4(DMA, D, "%-35s %8s %8s %8s",
+ "Summary of malloc() memory usage", "Quantity", "Bytes", "At max.");
+
+ for( i = 1; i < MEM_USAGE_MAX; i++ )
+ {
+ debug4(DMA, D, "%-35s %8d %8d %8d", usage_strings[i], usage_nums[i],
+ usage_bytes[i], max_usage_bytes[i]);
+ }
+ debug4(DMA, D, "%-35s %8s %8s %8s", "", "", "--------", "--------");
+ debug4(DMA, D, "%-35s %8s %8d %8d", "","",curr_total_bytes,max_total_bytes);
+
+
+ /***
+ debug3(DMA, D, "%-12s %8s %8s", "", "records", "bytes");
+ debug4(DMA, D, "%-12s %8s %8d (%d calls)", "calloc", "-",
+ no_of_calls * MEM_CHUNK * sizeof(ALIGN), no_of_calls);
+ debug3(DMA, D, "%-12s %8d %8d", "created", recs_created, bytes_created);
+ debug3(DMA, D, "%-12s %8d %8d", "free (count)", recs_free, bytes_free);
+ debug3(DMA, D, "%-12s %8d %8s", "free (var)", zz_listcount, "-");
+ debug3(DMA, D, "%-12s %8d %8s", "new-dispose",
+ zz_newcount - zz_disposecount, "-");
+ debug3(DMA, D, "%-12s %8d %8s", "created-free",
+ recs_created - recs_free, "-");
+ debug2(DMA, D, "newcount %d, disposecount %d", zz_newcount, zz_disposecount);
+ *** */
+
+ debug0(DMA, D, "");
+
+ } /* end DebugMemory */
+ #endif
+
+
+ /*@::zz_free[], zz_lengths[], MemInit()@**************************************/
+ /* */
+ /* OBJECT zz_free[], zz_hold, zz_tmp, zz_res */
+ /* int zz_size */
+ /* unsigned char zz_lengths[] */
+ /* */
+ /* zz_free[i]: free records of size i*sizeof(ALIGN). */
+ /* zz_lengths[i]: the number of ALIGNs in a record of type i. */
+ /* These variables are used only within the New() and Dispose() macros, */
+ /* and the list handling macros. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT zz_free[MAX_OBJECT_REC], zz_hold, zz_tmp, zz_res;
+ int zz_size;
+ unsigned char zz_lengths[DISPOSED]; /* DISPOSED is 1 + max type */
+ OBJECT xx_link, xx_tmp, xx_res, xx_hold;
+
+
+ /*****************************************************************************/
+ /* */
+ /* MemInit() */
+ /* */
+ /* Initialise memory allocator. */
+ /* */
+ /*****************************************************************************/
+
+ void MemInit(void)
+ {
+ zz_lengths[ WORD ] = 0;
+ zz_lengths[ QWORD ] = 0;
+ zz_lengths[ LINK ] = ceiling(sizeof(struct link_type), sizeof(ALIGN));
+
+ /* object types, except closure NB have actual() field in token phase! */
+ zz_lengths[ CLOSURE ] =
+ zz_lengths[ NULL_CLOS ] =
+ zz_lengths[ PAGE_LABEL ] =
+ zz_lengths[ UNDER_REC ] =
+ zz_lengths[ CROSS ] =
+ zz_lengths[ FORCE_CROSS ] =
+ zz_lengths[ SPLIT ] =
+ zz_lengths[ PAR ] =
+ zz_lengths[ ROW_THR ] =
+ zz_lengths[ COL_THR ] =
+ zz_lengths[ HSPANNER ] =
+ zz_lengths[ VSPANNER ] =
+ zz_lengths[ ACAT ] =
+ zz_lengths[ HCAT ] =
+ zz_lengths[ VCAT ] =
+ zz_lengths[ BEGIN_HEADER ] =
+ zz_lengths[ END_HEADER ] =
+ zz_lengths[ SET_HEADER ] =
+ zz_lengths[ CLEAR_HEADER ] =
+ zz_lengths[ ONE_COL ] =
+ zz_lengths[ ONE_ROW ] =
+ zz_lengths[ WIDE ] =
+ zz_lengths[ HIGH ] =
+ zz_lengths[ HSHIFT ] =
+ zz_lengths[ VSHIFT ] =
+ zz_lengths[ HSCALE ] =
+ zz_lengths[ VSCALE ] =
+ zz_lengths[ HCOVER ] =
+ zz_lengths[ VCOVER ] =
+ zz_lengths[ SCALE ] =
+ zz_lengths[ KERN_SHRINK ] =
+ zz_lengths[ HCONTRACT ] =
+ zz_lengths[ VCONTRACT ] =
+ zz_lengths[ HLIMITED ] =
+ zz_lengths[ VLIMITED ] =
+ zz_lengths[ HEXPAND ] =
+ zz_lengths[ VEXPAND ] =
+ zz_lengths[ START_HVSPAN ] =
+ zz_lengths[ START_HSPAN ] =
+ zz_lengths[ START_VSPAN ] =
+ zz_lengths[ HSPAN ] =
+ zz_lengths[ VSPAN ] =
+ zz_lengths[ PADJUST ] =
+ zz_lengths[ HADJUST ] =
+ zz_lengths[ VADJUST ] =
+ zz_lengths[ ROTATE ] =
+ zz_lengths[ BACKGROUND ] =
+ zz_lengths[ VERBATIM ] =
+ zz_lengths[ RAW_VERBATIM ] =
+ zz_lengths[ CASE ] =
+ zz_lengths[ YIELD ] =
+ zz_lengths[ BACKEND ] =
+ zz_lengths[ FILTERED ] =
+ zz_lengths[ XCHAR ] =
+ zz_lengths[ FONT ] =
+ zz_lengths[ SPACE ] =
+ zz_lengths[ YUNIT ] =
+ zz_lengths[ ZUNIT ] =
+ zz_lengths[ BREAK ] =
+ zz_lengths[ UNDERLINE ] =
+ zz_lengths[ COLOUR ] =
+ zz_lengths[ OUTLINE ] =
+ zz_lengths[ LANGUAGE ] =
+ zz_lengths[ CURR_LANG ] =
+ zz_lengths[ CURR_FAMILY ] =
+ zz_lengths[ CURR_FACE ] =
+ zz_lengths[ CURR_YUNIT ] =
+ zz_lengths[ CURR_ZUNIT ] =
+ zz_lengths[ COMMON ] =
+ zz_lengths[ RUMP ] =
+ zz_lengths[ MELD ] =
+ zz_lengths[ INSERT ] =
+ zz_lengths[ ONE_OF ] =
+ zz_lengths[ NEXT ] =
+ zz_lengths[ PLUS ] =
+ zz_lengths[ MINUS ] =
+ zz_lengths[ ENV_OBJ ] =
+ zz_lengths[ ENV ] =
+ zz_lengths[ ENVA ] =
+ zz_lengths[ ENVB ] =
+ zz_lengths[ ENVC ] =
+ zz_lengths[ ENVD ] =
+ zz_lengths[ CENV ] =
+ zz_lengths[ CLOS ] =
+ zz_lengths[ LVIS ] =
+ zz_lengths[ LUSE ] =
+ zz_lengths[ LEO ] =
+ zz_lengths[ OPEN ] =
+ zz_lengths[ TAGGED ] =
+ zz_lengths[ INCGRAPHIC ] =
+ zz_lengths[ SINCGRAPHIC ] =
+ zz_lengths[ PLAIN_GRAPHIC] =
+ zz_lengths[ GRAPHIC ] =
+ zz_lengths[ LINK_SOURCE ] =
+ zz_lengths[ LINK_DEST ] =
+ ceiling(sizeof(struct closure_type), sizeof(ALIGN));
+
+ zz_lengths[ HEAD ] =
+ ceiling(sizeof(struct head_type), sizeof(ALIGN));
+
+ zz_lengths[ LBR ] =
+ zz_lengths[ RBR ] =
+ zz_lengths[ BEGIN ] =
+ zz_lengths[ END ] =
+ zz_lengths[ USE ] =
+ zz_lengths[ NOT_REVEALED ] =
+ zz_lengths[ GSTUB_NONE ] =
+ zz_lengths[ GSTUB_INT ] =
+ zz_lengths[ GSTUB_EXT ] =
+ zz_lengths[ UNEXPECTED_EOF] =
+ zz_lengths[ PREPEND ] =
+ zz_lengths[ SYS_PREPEND ] =
+ zz_lengths[ DATABASE ] =
+ zz_lengths[ SYS_DATABASE ] =
+ zz_lengths[ DEAD ] =
+ zz_lengths[ UNATTACHED ] =
+ zz_lengths[ RECEPTIVE ] =
+ zz_lengths[ RECEIVING ] =
+ zz_lengths[ RECURSIVE ] =
+ zz_lengths[ PRECEDES ] =
+ zz_lengths[ FOLLOWS ] =
+ zz_lengths[ CROSS_FOLL ] =
+ zz_lengths[ CROSS_FOLL_OR_PREC] =
+ zz_lengths[ GALL_FOLL ] =
+ zz_lengths[ GALL_FOLL_OR_PREC ] =
+ zz_lengths[ CROSS_TARG ] =
+ zz_lengths[ GALL_TARG ] =
+ zz_lengths[ GALL_PREC ] =
+ zz_lengths[ CROSS_PREC ] =
+ zz_lengths[ PAGE_LABEL_IND] =
+ zz_lengths[ SCALE_IND ] =
+ zz_lengths[ COVER_IND ] =
+ zz_lengths[ EXPAND_IND ] =
+ zz_lengths[ THREAD ] =
+ zz_lengths[ CR_LIST ] =
+ zz_lengths[ SCOPE_SNAPSHOT] =
+ ceiling(sizeof(struct closure_type), sizeof(ALIGN));
+
+ /* symbol types */
+ zz_lengths[ MACRO ] =
+ zz_lengths[ LOCAL ] =
+ zz_lengths[ LPAR ] =
+ zz_lengths[ RPAR ] =
+ zz_lengths[ NPAR ] =
+ ceiling(sizeof(struct symbol_type), sizeof(ALIGN));
+
+ /* gap objects */
+ zz_lengths[ TSPACE ] =
+ zz_lengths[ TJUXTA ] =
+ zz_lengths[ GAP_OBJ ] =
+ ceiling(sizeof(struct gapobj_type), sizeof(ALIGN));
+
+ /* cross-reference and data base types */
+ zz_lengths[ CROSS_SYM ] =
+ zz_lengths[ CR_ROOT ] = ceiling(sizeof(struct cr_type) , sizeof(ALIGN));
+
+ /* external galley record */
+ zz_lengths[ EXT_GALL ] = ceiling(sizeof(struct ext_gall_type),sizeof(ALIGN));
+
+ } /* end MemInit() */
+
+
+ /*@::GetMemory()@*************************************************************/
+ /* */
+ /* OBJECT GetMemory(siz, pos) */
+ /* */
+ /* Return a pointer to siz ALIGNs of memory (0 < siz < MAX_OBJECT_REC). */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT GetMemory(int siz, FILE_POS *pos)
+ { static ALIGN *next_free = (ALIGN *) nilobj;
+ static ALIGN *top_free = (ALIGN *) nilobj;
+ OBJECT res;
+
+ debug1(DMA, DDD, "GetMemory( %d )", siz);
+
+ /* get memory from operating system, if not enough left here */
+ if( &next_free[siz] > top_free )
+ {
+ #if DEBUG_ON
+ DebugRegisterUsage(MEM_OBJECTS, 1, MEM_CHUNK * sizeof(ALIGN));
+ #endif
+ next_free = (ALIGN *) calloc(MEM_CHUNK, sizeof(ALIGN));
+ ifdebug(DMA, D, no_of_calls++; )
+ if( next_free == NULL )
+ Error(31, 1, "exiting now (run out of memory)", FATAL, pos);
+ top_free = &next_free[MEM_CHUNK];
+ debug2(DMA, DD, "GetMemory: calloc returned %ld - %ld",
+ (long) next_free, (long) top_free);
+ }
+
+ res = (OBJECT) next_free;
+ next_free = &next_free[siz];
+ #if DEBUG_ON
+ recs_created++; bytes_created += siz * sizeof(ALIGN);
+ #endif
+ debug3(DMA, DDD, "GetMemory returning @%ld (next_free = @%ld, top_free = @%ld",
+ (long) res, (long) next_free, (long) top_free);
+ return res;
+ } /* end GetMemory */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z32.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z32.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z32.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,165 ----
+ /*@z32.c:Counter Service:Next()@**********************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z32.c */
+ /* MODULE: Counter Service */
+ /* EXTERNS: Next() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT Next(x, inc, done) */
+ /* */
+ /* Return x with its value incremented by inc (if possible). */
+ /* Set *done to TRUE if successful, leave *done unchanged otherwise. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT Next(OBJECT x, int inc, BOOLEAN *done)
+ { OBJECT y, link; int l, r, n, len;
+ FULL_CHAR buff[MAX_BUFF];
+ debug3(DCS, DD, "Next( %s, %d, %s )", EchoObject(x), inc, bool(*done));
+ switch( type(x) )
+ {
+ case WORD:
+ case QWORD:
+
+ len = StringLength(string(x));
+ for( r = len - 1; r >= 0 && !decimaldigit(string(x)[r]); r--);
+ if( r < 0 ) break;
+ for( l = r-1; l >= 0 && decimaldigit(string(x)[l]); l-- );
+ sscanf( (char *) &string(x)[l+1], "%d", &n);
+ string(x)[l+1] = '\0';
+ StringCopy(buff, string(x));
+ StringCat(buff, StringInt(n+inc));
+ StringCat(buff, &string(x)[r+1]);
+ if( StringLength(buff) >= MAX_BUFF )
+ Error(32, 1, "word %s is too long", FATAL, &fpos(x), buff);
+ y = MakeWord(type(x), buff, &fpos(x));
+ word_font(y) = word_font(x);
+ word_colour(y) = word_colour(x);
+ word_outline(y) = word_outline(x);
+ word_language(y) = word_language(x);
+ word_hyph(y) = word_hyph(x);
+ underline(y) = underline(x);
+ MergeNode(y, x); x = y;
+ *done = TRUE;
+ break;
+
+
+ case INCGRAPHIC:
+ case SINCGRAPHIC:
+ case GAP_OBJ:
+ case CLOSURE:
+ case NULL_CLOS:
+ case PAGE_LABEL:
+ case CROSS:
+ case FORCE_CROSS:
+ case START_HVSPAN:
+ case START_HSPAN:
+ case START_VSPAN:
+ case HSPAN:
+ case VSPAN:
+ case END_HEADER:
+ case CLEAR_HEADER:
+
+ break;
+
+
+ case BEGIN_HEADER:
+ case SET_HEADER:
+ case ONE_COL:
+ case ONE_ROW:
+ case WIDE:
+ case HIGH:
+ case HSHIFT:
+ case VSHIFT:
+ case HCONTRACT:
+ case VCONTRACT:
+ case HLIMITED:
+ case VLIMITED:
+ case HEXPAND:
+ case VEXPAND:
+ case PADJUST:
+ case HADJUST:
+ case VADJUST:
+ case HSCALE:
+ case VSCALE:
+ case HCOVER:
+ case VCOVER:
+ case ROTATE:
+ case BACKGROUND:
+ case SCALE:
+ case KERN_SHRINK:
+ case SPLIT:
+ case PLAIN_GRAPHIC:
+ case GRAPHIC:
+ case LINK_SOURCE:
+ case LINK_DEST:
+
+ Child(y, LastDown(x));
+ y = Next(y, inc, done);
+ break;
+
+
+ case ACAT:
+
+ /* *** seems identical!
+ link = LastDown(x);
+ while( link != x && !*done )
+ { Child(y, link);
+ if( is_index(type(y)) ) continue;
+ y = Next(y, inc, done);
+ if( !*done ) link = PrevDown(link);
+ }
+ break;
+ *** */
+
+
+ case COL_THR:
+ case ROW_THR:
+ case HCAT:
+ case VCAT:
+
+ link = LastDown(x);
+ while( link != x && !*done )
+ { Child(y, link);
+ if( is_index(type(y)) ) continue;
+ y = Next(y, inc, done);
+ if( !*done ) link = PrevDown(link);
+ }
+ break;
+
+
+ default:
+
+ assert1(FALSE, "Next:", Image(type(x)));
+ break;
+
+ } /* end switch */
+ debug1(DCS, DD, "Next returning %s", EchoObject(x));
+ return x;
+ } /* end Next */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z33.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z33.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z33.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,865 ----
+ /*@z33.c:Database Service:OldCrossDb(), NewCrossDb(), SymToNum()@*************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.23) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z33.c */
+ /* MODULE: Database Service */
+ /* EXTERNS: OldCrossDb, NewCrossDb, DbCreate(), DbInsert(), */
+ /* DbConvert(), DbClose(), DbLoad(), DbRetrieve(), */
+ /* DbRetrieveNext() */
+ /* */
+ /*****************************************************************************/
+ #define INIT_DBCHECK_NUM 107
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* DBCHECK_TABLE */
+ /* */
+ /* A symbol table holding all non-galley cross references, basically */
+ /* implementing a function (sym, tag) -> fpos (if any). */
+ /* */
+ /* dtab_new(newsize) New empty table, newsize capacity */
+ /* dtab_insert(x, S) Insert new (sym, tag) pair x into S */
+ /* dtab_retrieve(sym, tag, S) Retrieve (sym, tag) pair from S */
+ /* dtab_debug(S, fp) Debug print of table S to file fp */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { int dbchecktab_size; /* size of table */
+ int dbchecktab_count; /* number of objects held */
+ OBJECT dbchecktab_item[1];
+ } *DBCHECK_TABLE;
+
+ #define dtab_size(S) (S)->dbchecktab_size
+ #define dtab_count(S) (S)->dbchecktab_count
+ #define dtab_item(S, i) (S)->dbchecktab_item[i]
+
+ #define hash(pos, sym, tag, S) \
+ { FULL_CHAR *p = tag; \
+ pos = (unsigned long) sym; \
+ while( *p ) pos += *p++; \
+ pos = pos % dtab_size(S); \
+ }
+
+ static DBCHECK_TABLE dtab_new(int newsize)
+ { DBCHECK_TABLE S; int i;
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_DBCHECK, 1,
+ 2*sizeof(int) + newsize * sizeof(OBJECT)));
+ S = (DBCHECK_TABLE)
+ malloc(2*sizeof(int) + newsize * sizeof(OBJECT));
+ if( S == (DBCHECK_TABLE) NULL )
+ Error(33, 1, "run out of memory enlarging dbcheck table", FATAL, no_fpos);
+ dtab_size(S) = newsize;
+ dtab_count(S) = 0;
+ for( i = 0; i < newsize; i++ ) dtab_item(S, i) = nilobj;
+ return S;
+ } /* end dtab_new */
+
+ static void dtab_insert(OBJECT x, DBCHECK_TABLE *S);
+
+ static DBCHECK_TABLE dtab_rehash(DBCHECK_TABLE S, int newsize)
+ { DBCHECK_TABLE NewS; int i; OBJECT link, z;
+ NewS = dtab_new(newsize);
+ for( i = 0; i < dtab_size(S); i++ )
+ { if( dtab_item(S, i) != nilobj )
+ { OBJECT ent = dtab_item(S, i);
+ assert( type(ent) == ACAT, "dtab_rehash: ACAT!" );
+ for( link = Down(ent); link != ent; link = NextDown(link) )
+ { Child(z, link);
+ dtab_insert(z, &NewS);
+ }
+ DisposeObject(ent);
+ }
+ }
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_DBCHECK, -1,
+ -(2*sizeof(int) + dtab_size(S) * sizeof(OBJECT))));
+ free(S);
+ return NewS;
+ } /* end dtab_rehash */
+
+ static void dtab_insert(OBJECT x, DBCHECK_TABLE *S)
+ { unsigned long pos; OBJECT z, link, y;
+ if( dtab_count(*S) == dtab_size(*S) - 1 ) /* one less since 0 unused */
+ *S = dtab_rehash(*S, 2*dtab_size(*S));
+ dtab_count(*S)++;
+ hash(pos, db_checksym(x), string(x), *S);
+ if( dtab_item(*S, pos) == nilobj ) New(dtab_item(*S, pos), ACAT);
+ z = dtab_item(*S, pos);
+ for( link = Down(z); link != z; link = NextDown(link) )
+ { Child(y, link);
+ if( db_checksym(x) == db_checksym(y) && StringEqual(string(x), string(y)) )
+ { assert(FALSE, "Dbcheck: entry inserted twice");
+ }
+ }
+ Link(dtab_item(*S, pos), x);
+ } /* end dtab_insert */
+
+ static OBJECT dtab_retrieve(OBJECT sym, FULL_CHAR *tag, DBCHECK_TABLE S)
+ { OBJECT x, link, y; unsigned long pos;
+ hash(pos, sym, tag, S);
+ x = dtab_item(S, pos);
+ if( x == nilobj ) return nilobj;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( sym == db_checksym(y) && StringEqual(tag, string(y)) )
+ return y;
+ }
+ return nilobj;
+ } /* end dtab_retrieve */
+
+ #if DEBUG_ON
+ static void dtab_debug(DBCHECK_TABLE S, FILE *fp)
+ { int i; OBJECT x, link, y;
+ fprintf(fp, " table size: %d; current number of items: %d\n",
+ dtab_size(S), dtab_count(S));
+ for( i = 0; i < dtab_size(S); i++ )
+ { x = dtab_item(S, i);
+ fprintf(fp, "dtab_item(S, %d) =", i);
+ if( x == nilobj )
+ fprintf(fp, " <nilobj>");
+ else if( type(x) != ACAT )
+ fprintf(fp, " not ACAT!");
+ else for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ fprintf(fp, " %s&&%s",
+ is_word(type(y)) ? SymName(db_checksym(y)) : AsciiToFull("?"),
+ is_word(type(y)) ? string(y) : AsciiToFull("not-WORD!"));
+ }
+ fprintf(fp, "\n");
+ }
+ } /* end dtab_debug */
+ #endif
+
+ static DBCHECK_TABLE DbCheckTable; /* the dbcheck table */
+ static BOOLEAN DbCheckTableInit = FALSE; /* TRUE if table inited */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OldCrossDb Database containing cross references from previous run. */
+ /* NewCrossDb Writable database of cross references from this run. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT OldCrossDb, NewCrossDb;
+
+
+ /*****************************************************************************/
+ /* */
+ /* #define SymToNum(db, sym, num, gall) */
+ /* */
+ /* Set num to the number used to refer to sym in database db. If sym is */
+ /* not currently referred to in db, create a new number and record sym. */
+ /* If gall is true, sym is the target of galleys stored in this database. */
+ /* Store in boolean fields db_targ(link) and is_extern_target(sym). */
+ /* */
+ /*****************************************************************************/
+
+ #define SymToNum(db, sym, num, gall) \
+ { OBJECT link, yy; int count; \
+ count = 0; \
+ for( link = Down(db); link != db; link = NextDown(link) ) \
+ { Child(yy, link); \
+ assert(type(yy)==CROSS_SYM || type(yy)==ACAT, "SymToNum: yy!"); \
+ if( type(yy) != CROSS_SYM ) continue; \
+ if( symb(yy) == sym ) break; \
+ if( number(link) > count ) count = number(link); \
+ } \
+ if( link == db ) \
+ { if( cross_sym(sym) == nilobj ) CrossInit(sym); \
+ Link(db, cross_sym(sym)); \
+ link = LastDown(db); \
+ number(link) = count + 1; \
+ db_targ(link) = FALSE; \
+ } \
+ num = number(link); \
+ if( gall ) db_targ(link) = is_extern_target(sym) = \
+ uses_extern_target(sym) = TRUE; \
+ } /* end SymToNum */
+
+
+ /*@::NumToSym(), DbCreate()@**************************************************/
+ /* */
+ /* #define NumToSym(db, num, sym) */
+ /* */
+ /* Set sym to the symbol which is referred to in database db by num. */
+ /* */
+ /*****************************************************************************/
+
+ #define NumToSym(db, num, sym) \
+ { OBJECT link, y; \
+ for( link = Down(db); link != db; link = NextDown(link) ) \
+ { Child(y, link); \
+ if( type(y) == CROSS_SYM && number(link) == num ) break; \
+ } \
+ assert( link != db, "NumToSym: no sym"); \
+ assert( type(y) == CROSS_SYM, "NumToSym: y!" ); \
+ sym = symb(y); \
+ } /* end NumToSym */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT DbCreate(x) */
+ /* */
+ /* Create a new writable database with name (i.e. file stem) x and file */
+ /* position fpos for error messages. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT DbCreate(OBJECT x)
+ { OBJECT db = x;
+ debug1(DBS, DD, "DbCreate(%s)", string(db));
+ assert( is_word(type(x)), "DbCreate: !is_word(type(x))" );
+ reading(db) = FALSE; db_filep(db) = null;
+ debug1(DBS, DD, "DbCreate returning %s", EchoObject(db));
+ return db;
+ } /* end DbCreate */
+
+
+ /*@::DbInsert()@**************************************************************/
+ /* */
+ /* DbInsert(db, gall, sym, tag, tagfpos, seq, dfnum, dlnum, dfpos) */
+ /* */
+ /* Insert a new entry into writable database db. The primary key of the */
+ /* entry has these three parts: */
+ /* */
+ /* gall TRUE if inserting a galley */
+ /* sym The symbol which is the target of this entry */
+ /* tag The tag of this target (must be a non-null string) */
+ /* */
+ /* tagfpos is the file position that the tag originated from. */
+ /* There is also an auxiliary key, seq, which enforces an ordering on */
+ /* entries with equal primary keys but is not itself ever retrieved. This */
+ /* ordering is used for sorted galleys. The value of the entry has the */
+ /* following parts: */
+ /* */
+ /* dfnum The file containing the object */
+ /* dfpos The position of the object in that file */
+ /* dlnum The line number of the object in the file */
+ /* */
+ /* If check is TRUE, we need to check whether an entry with this key has */
+ /* been inserted before. This will never be the case with galley entries. */
+ /* */
+ /*****************************************************************************/
+
+ void DbInsert(OBJECT db, BOOLEAN gall, OBJECT sym, FULL_CHAR *tag,
+ FILE_POS *tagfpos, FULL_CHAR *seq, FILE_NUM dfnum, long dfpos, int dlnum,
+ BOOLEAN check)
+ { int symnum; OBJECT chk;
+ static int extra_seq = 0;
+ FULL_CHAR buff[MAX_BUFF];
+ assert( is_word(type(db)), "DbInsert: db!" );
+ assert( tag[0] != '\0', "DbInsert: null tag!" );
+ assert( seq[0] != '\0', "DbInsert: null seq!" );
+ ifdebug(DPP, D, ProfileOn("DbInsert"));
+ debug6(DBS, D, "DbInsert(%s, %s, %s, %s, %s, %s, dlnum, dfpos)",
+ string(db), bool(gall), SymName(sym), tag, seq,
+ dfnum == NO_FILE ? AsciiToFull(".") : FileName(dfnum));
+ assert(!reading(db), "DbInsert: insert into reading database");
+
+ /* if required, check that (sym, tag) not already inserted */
+ if( check )
+ {
+ debug2(DBS, DD, " checking %s&&%s, DbCheckTable =", SymName(sym), tag);
+ if( !DbCheckTableInit )
+ { DbCheckTable = dtab_new(INIT_DBCHECK_NUM);
+ DbCheckTableInit = TRUE;
+ }
+ ifdebug(DBS, DD, dtab_debug(DbCheckTable, stderr));
+ chk = dtab_retrieve(sym, tag, DbCheckTable);
+ if( chk == nilobj )
+ { chk = MakeWord(WORD, tag, tagfpos);
+ db_checksym(chk) = sym;
+ dtab_insert(chk, &DbCheckTable);
+ }
+ else
+ { if( file_num(fpos(chk)) > 0 )
+ Error(33, 4, "cross reference %s&&%s used previously, at%s",
+ WARN, tagfpos, SymName(sym), tag, EchoFilePos(&fpos(chk)));
+ else Error(33, 5, "cross reference %s&&%s used previously",
+ WARN, tagfpos, SymName(sym), tag);
+ }
+ }
+
+ /* open database index file if not already done */
+ if( db_filep(db) == null )
+ { if( StringLength(string(db)) + StringLength(NEW_INDEX_SUFFIX) >= MAX_BUFF )
+ Error(33, 2, "database file name %s%s is too long",
+ FATAL, no_fpos, string(db), NEW_INDEX_SUFFIX);
+ StringCopy(buff, string(db));
+ StringCat(buff, NEW_INDEX_SUFFIX);
+ db_filep(db) = StringFOpen(buff, WRITE_BINARY);
+ if( db_filep(db) == null )
+ Error(33, 3, "cannot write to database file %s", FATAL, &fpos(db), buff);
+ }
+
+ /* work out database index file entry and append it to file */
+ if( dfnum != NO_FILE )
+ { StringCopy(buff, FileName(dfnum));
+ StringCopy(&buff[StringLength(buff)-StringLength(DATA_SUFFIX)], STR_EMPTY);
+ }
+ else StringCopy(buff, AsciiToFull("."));
+ SymToNum(db, sym, symnum, gall);
+ ifdebug(DBS, DD,
+ fprintf(stderr, " -> %s%d&%s\t%s\t%ld\t%d\t%s\n", gall ? "0" : "", symnum,
+ tag, seq, dfpos, dlnum, buff);
+ );
+ fprintf(db_filep(db), "%s%d&%s\t%s\t%s\t%ld\t%d\t%s\n", gall ? "0" : "",
+ symnum, tag, seq, StringFiveInt(++extra_seq), dfpos, dlnum, buff);
+
+ /* return */
+ debug0(DBS, DD, "DbInsert returning.");
+ ifdebug(DPP, D, ProfileOff("DbInsert"));
+ } /* end DbInsert */
+
+
+ /*@::DbConvert(), DbClose()@**************************************************/
+ /* */
+ /* DbConvert(db, full_name) */
+ /* */
+ /* Convert database db from writable to readable, then dispose it. */
+ /* full_name is TRUE if symbols are to be known by their full path name. */
+ /* */
+ /*****************************************************************************/
+
+ void DbConvert(OBJECT db, BOOLEAN full_name)
+ { FULL_CHAR oldname[MAX_BUFF+10], newname[MAX_BUFF];
+ OBJECT link, y;
+ ifdebug(DPP, D, ProfileOn("DbConvert"));
+ debug2(DBS, DD, "DbConvert( %ld %s )", (long) db, string(db));
+ assert( !reading(db), "DbConvert: reading database");
+ StringCopy(newname, string(db));
+ StringCat(newname, INDEX_SUFFIX);
+ StringCopy(oldname, string(db));
+ StringCat(oldname, NEW_INDEX_SUFFIX);
+ if( db_filep(db) != null )
+ {
+ fprintf(db_filep(db), "00 %s %s\n", LOUT_VERSION, "database index file");
+ for( link = Down(db); link != db; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) == CROSS_SYM || type(y) == ACAT, "DbConvert: y!" );
+ if( type(y) != CROSS_SYM ) continue;
+ fprintf(db_filep(db), "%s %d %s\n",
+ db_targ(link) ? "00target" : "00symbol",
+ number(link),
+ full_name ? FullSymName(symb(y), AsciiToFull(" ")) : SymName(symb(y)));
+ }
+ fclose(db_filep(db));
+ debug2(DBS, DD, " calling SortFile(%s, %s)", oldname, newname);
+ SortFile(oldname, newname);
+ }
+ else StringRemove(newname);
+ StringRemove(oldname);
+ DeleteNode(db);
+ debug0(DBS, DD, "DbConvert returning.");
+ ifdebug(DPP, D, ProfileOff("DbConvert"));
+ } /* end DbConvert */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DbClose(db) */
+ /* */
+ /* Close readable database db. */
+ /* */
+ /*****************************************************************************/
+
+ void DbClose(OBJECT db)
+ { if( db != nilobj && !in_memory(db) && db_filep(db) != NULL )
+ { fclose(db_filep(db));
+ db_filep(db) = NULL;
+ }
+ } /* end DbClose */
+
+
+ /*@::DbLoad()@****************************************************************/
+ /* */
+ /* OBJECT DbLoad(stem, fpath, create, symbs, in_mem) */
+ /* */
+ /* Open for reading the database whose index file name is string(stem).li. */
+ /* This file has not yet been defined; its search path is fpath. If it */
+ /* will not open and create is true, try creating it from string(stem).ld. */
+ /* */
+ /* symbs is an ACAT of CLOSUREs showing the symbols that the database may */
+ /* contain; or nilobj if the database may contain any symbol. */
+ /* */
+ /* If in_mem is true, this database index is to be kept in internal memory, */
+ /* rather than an external file, as a speed optimization. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT DbLoad(OBJECT stem, int fpath, BOOLEAN create, OBJECT symbs,
+ BOOLEAN in_mem)
+ { FILE *fp; OBJECT db, t, res, tag, par, sym, link, y;
+ int i, lnum, dlnum, num, count, leftp;
+ FILE_NUM index_fnum, dfnum; long dfpos;
+ BOOLEAN gall; FULL_CHAR line[MAX_BUFF], sym_name[MAX_BUFF]; char *gotline;
+ ifdebug(DPP, D, ProfileOn("DbLoad"));
+ debug3(DBS, DD, "[ DbLoad(%s, %d, %s, -)", string(stem), fpath, bool(create));
+
+ /* open or else create index file fp */
+ debug0(DFS, D, " calling DefineFile from DbLoad (1)");
+ index_fnum = DefineFile(string(stem), INDEX_SUFFIX, &fpos(stem), INDEX_FILE,
+ fpath);
+ fp = OpenFile(index_fnum, create, FALSE);
+
+ /* read first line of database index file, which should have the version */
+ if( fp != null )
+ { if( StringFGets(line, MAX_BUFF, fp) == NULL ||
+ !StringBeginsWith(&line[3], LOUT_VERSION) )
+ {
+ /* out of date, pretend it isn't there at all */
+ StringRemove(FileName(index_fnum));
+ fp = null;
+ }
+ }
+
+ if( fp == null && create )
+ { db = nilobj;
+ debug0(DFS, D, " calling DefineFile from DbLoad (2)");
+ /* *** bug fix JeffK 12/9/00; need same path as index file
+ dfnum = DefineFile(string(stem), DATA_SUFFIX, &fpos(stem),
+ DATABASE_FILE, DATABASE_PATH);
+ *** */
+ dfnum = DefineFile(string(stem), DATA_SUFFIX, &fpos(stem),
+ DATABASE_FILE, fpath);
+ dfpos = 0L; LexPush(dfnum, 0, DATABASE_FILE, 1, FALSE);
+ t = LexGetToken();
+ dlnum = line_num(fpos(t));
+ while( type(t) == LBR )
+ { res = Parse(&t, StartSym, FALSE, FALSE);
+ if( t != nilobj || type(res) != CLOSURE )
+ Error(33, 6, "syntax error in database file %s",
+ FATAL, &fpos(res), FileName(dfnum));
+ assert( symbs != nilobj, "DbLoad: create && symbs == nilobj!" );
+ if( symbs != nilobj )
+ { for( link = Down(symbs); link != symbs; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == CLOSURE && actual(y) == actual(res) ) break;
+ }
+ if( link == symbs )
+ Error(33, 7, "%s found in database but not declared in %s line",
+ FATAL, &fpos(res), SymName(actual(res)), KW_DATABASE);
+ }
+ for( tag = nilobj, link = Down(res); link != res; link = NextDown(link) )
+ { Child(par, link);
+ if( type(par) == PAR && is_tag(actual(par)) && Down(par) != par )
+ { Child(tag, Down(par));
+ break;
+ }
+ }
+ if( tag == nilobj )
+ Error(33, 8, "database symbol %s has no tag",
+ FATAL, &fpos(res), SymName(actual(res)));
+ tag = ReplaceWithTidy(tag, TRUE); /* && */
+ if( !is_word(type(tag)) )
+ Error(33, 9, "database symbol tag is not a simple word",
+ FATAL, &fpos(res));
+ if( StringEqual(string(tag), STR_EMPTY) )
+ Error(33, 10, "database symbol tag is an empty word", FATAL,&fpos(res));
+ if( db == nilobj )
+ { StringCopy(line, FileName(dfnum));
+ i = StringLength(line) - StringLength(INDEX_SUFFIX);
+ assert( i > 0, "DbLoad: FileName(dfnum) (1)!" );
+ StringCopy(&line[i], STR_EMPTY);
+ db = DbCreate(MakeWord(WORD, line, &fpos(stem)));
+ }
+ DbInsert(db, FALSE, actual(res), string(tag), &fpos(tag), STR_ZERO,
+ NO_FILE, dfpos, dlnum, TRUE);
+ DisposeObject(res); dfpos = LexNextTokenPos(); t = LexGetToken();
+ dlnum = line_num(fpos(t));
+ }
+ if( type(t) != END )
+ Error(33, 11, "%s or end of file expected here", FATAL, &fpos(t), KW_LBR);
+ LexPop();
+ if( db == nilobj )
+ { StringCopy(line, FileName(dfnum));
+ i = StringLength(line) - StringLength(INDEX_SUFFIX);
+ assert( i > 0, "DbLoad: FileName(dfnum) (2)!" );
+ StringCopy(&line[i], STR_EMPTY);
+ db = DbCreate(MakeWord(WORD, line, &fpos(stem)));
+ }
+ DbConvert(db, FALSE);
+ if( (fp = OpenFile(index_fnum, FALSE, FALSE)) == null ||
+ StringFGets(line, MAX_BUFF, fp) == NULL ||
+ !StringBeginsWith(&line[3], LOUT_VERSION) )
+ Error(33, 12, "cannot open database file %s",
+ FATAL, &fpos(db), FileName(index_fnum));
+ }
+
+ /* set up database record */
+ StringCopy(line, FileName(index_fnum));
+ i = StringLength(line) - StringLength(INDEX_SUFFIX);
+ assert( i > 0, "DbLoad: FileName(index_fnum)!" );
+ StringCopy(&line[i], STR_EMPTY);
+ db = MakeWord(WORD, line, &fpos(stem));
+ reading(db) = TRUE;
+ in_memory(db) = in_mem;
+ if( symbs != nilobj )
+ { assert( type(symbs) == ACAT, "DbLoad: type(symbs)!" );
+ Link(db, symbs);
+ }
+ if( fp == null )
+ { debug1(DBS, DD, "] DbLoad returning (empty) %s", string(db));
+ db_filep(db) = null;
+ db_lines(db) = (LINE *) NULL;
+ ifdebug(DPP, D, ProfileOff("DbLoad"));
+ return db;
+ }
+
+ /* read header lines of index file, find its symbols */
+ leftp = 0; lnum = 1;
+ gotline = StringFGets(line, MAX_BUFF, fp);
+ while( gotline != NULL )
+ {
+ if( line[0] != '0' || line[1] != '0' ) break;
+ lnum++;
+ leftp = (int) ftell(fp);
+ gall = StringBeginsWith(line, AsciiToFull("00target "));
+ sscanf( (char *) line, gall ? "00target %d" : "00symbol %d", &num);
+ for( i = 9; line[i] != CH_SPACE && line[i] != '\0'; i++ );
+ if( symbs == nilobj )
+ {
+ /* any symbols are possible, full path names in index file required */
+ count = 0; sym = StartSym;
+ while( line[i] != CH_NEWLINE && line[i] != '\0' )
+ { PushScope(sym, FALSE, FALSE); count++;
+ sscanf( (char *) &line[i+1], "%s", sym_name);
+ sym = SearchSym(sym_name, StringLength(sym_name));
+ i += StringLength(sym_name) + 1;
+ }
+ for( i = 1; i <= count; i++ ) PopScope();
+ }
+ else
+ {
+ /* only symbs symbols possible, full path names not required */
+ sym = nilobj;
+ sscanf( (char *) &line[i+1], "%s", sym_name);
+ for( link = Down(symbs); link != symbs; link = NextDown(link) )
+ { Child(y, link);
+ assert( type(y) == CLOSURE, "DbLoad: type(y) != CLOSURE!" );
+ if( StringEqual(sym_name, SymName(actual(y))) )
+ { sym = actual(y);
+ break;
+ }
+ }
+ }
+ if( sym != nilobj && sym != StartSym )
+ { if( cross_sym(sym) == nilobj ) CrossInit(sym);
+ Link(db, cross_sym(sym));
+ link = LastDown(db);
+ number(link) = num; db_targ(link) = gall;
+ if( gall ) is_extern_target(sym) = uses_extern_target(sym) = TRUE;
+ }
+ else
+ { Error(33, 13, "undefined symbol in database file %s (line %d)",
+ WARN, &fpos(db), FileName(index_fnum), lnum);
+ debug1(DBS, DD, "] DbLoad returning %s (error)", string(db));
+ fclose(fp);
+ in_memory(db) = FALSE;
+ db_filep(db) = null; /* subsequently treated like an empty database */
+ ifdebug(DPP, D, ProfileOff("DbLoad"));
+ return db;
+ }
+ gotline = StringFGets(line, MAX_BUFF, fp);
+ }
+
+ /* if in_memory, go on to read the entire database index into memory */
+ if( in_memory(db) )
+ { int len;
+ if( gotline == NULL )
+ db_lines(db) = 0;
+ else
+ {
+ db_lines(db) = ReadLines(fp, FileName(index_fnum), line, &len);
+ db_lineslen(db) = len;
+ SortLines(db_lines(db), db_lineslen(db));
+ }
+ }
+ else /* external, save leftpos and file pointer */
+ { db_filep(db) = fp;
+ left_pos(db) = leftp;
+ }
+
+ /* return */
+ debug1(DBS, DD, "] DbLoad returning %s", string(db));
+ ifdebug(DPP, D, ProfileOff("DbLoad"));
+ return db;
+ } /* end DbLoad */
+
+
+ /*@::SearchFile()@************************************************************/
+ /* */
+ /* static BOOLEAN SearchFile(fp, left, right, str, line) */
+ /* */
+ /* File fp is a text file. left is the beginning of a line, right is the */
+ /* end of a line. Search the file by binary search for a line beginning */
+ /* with str. If found, return it in line, else return FALSE. */
+ /* */
+ /*****************************************************************************/
+
+ static BOOLEAN SearchFile(FILE *fp, int left, int right,
+ FULL_CHAR *str, FULL_CHAR *line)
+ { int l, r, mid, mid_end; FULL_CHAR buff[MAX_BUFF]; BOOLEAN res;
+ ifdebug(DPP, D, ProfileOn("SearchFile"));
+ debug3(DBS, DD, "SearchFile(fp, %d, %d, %s, line)", left, right, str);
+
+ l = left; r = right;
+ while( l <= r )
+ {
+ /* loop invt: (l==0 or fp[l-1]==CH_NEWLINE) and (fp[r] == CH_NEWLINE) */
+ /* and first key >= str lies in the range fp[l..r+1] */
+
+ /* find line near middle of the range; mid..mid_end brackets it */
+ debug2(DBS, DD, " start loop: l = %d, r = %d", l, r);
+ mid = (l + r)/2;
+ fseek(fp, (long) mid, SEEK_SET);
+ do { mid++; } while( getc(fp) != CH_NEWLINE );
+ if( mid == r + 1 )
+ { mid = l;
+ fseek(fp, (long) mid, SEEK_SET);
+ }
+ StringFGets(line, MAX_BUFF, fp);
+ mid_end = (int) ftell(fp) - 1;
+ debug3(DBS, DD, " mid: %d, mid_end: %d, line: %s", mid, mid_end, line);
+ assert( l <= mid, "SearchFile: l > mid!" );
+ assert( mid < mid_end, "SearchFile: mid >= mid_end!" );
+ assert( mid_end <= r, "SearchFile: mid_end > r!" );
+
+ /* compare str with this line and prepare next step */
+ debug2(DBS, DD, " comparing key %s with line %s", str, line);
+ if( TabbedStringLessEqual(str, line) ) r = mid - 1;
+ else l = mid_end + 1;
+ } /* end while */
+
+ /* now first key >= str lies in fp[l]; compare it with str */
+ if( l < right )
+ { fseek(fp, (long) l, SEEK_SET);
+ StringFGets(line, MAX_BUFF, fp);
+ sscanf( (char *) line, "%[^\t]", buff);
+ res = StringEqual(str, buff);
+ }
+ else res = FALSE;
+ debug1(DBS, DD, "SearchFile returning %s", bool(res));
+ ifdebug(DPP, D, ProfileOff("SearchFile"));
+ return res;
+ } /* end SearchFile */
+
+
+ /*@::SearchLines()@***********************************************************/
+ /* */
+ /* static BOOLEAN SearchLines(LINE *lines, int left, int right, str, lnum) */
+ /* */
+ /* Search the sorted array of LINE arrays lines[left..right] for a line */
+ /* beginning with str, and return TRUE if found else FALSE. */
+ /* */
+ /* If TRUE is returned then the number of the line is in *lnum. */
+ /* */
+ /*****************************************************************************/
+
+ static BOOLEAN SearchLines(LINE *lines, int left, int right, FULL_CHAR *str,
+ int *lnum)
+ { int l, r, mid; FULL_CHAR buff[MAX_BUFF];
+ BOOLEAN res;
+ debug3(DBS, D, "SearchLines(lines, %d, %d, %s, lnum)", left, right, str);
+ if( right < left )
+ {
+ debug0(DBS, D, "SearchLines returning FALSE (empty lines)");
+ return FALSE;
+ }
+ l = left;
+ r = right - 1;
+ while( l <= r )
+ {
+ /* loop invt: first key >= str (if any) lies in the range lines[l..r+1] */
+ /* and left <= l <= right and r < right */
+ mid = (l + r) / 2;
+ debug4(DBS, D, " [l %d, r %d] examining lines[%d] = %s", l, r, mid,
+ lines[mid]);
+ if( TabbedStringLessEqual(str, (FULL_CHAR *) lines[mid]) ) r = mid - 1;
+ else l = mid + 1;
+ }
+ sscanf( (char *) lines[l], "%[^\t]", buff);
+ if( StringEqual(str, buff) )
+ {
+ res = TRUE;
+ *lnum = l;
+ debug1(DBS, D, "SearchLines returning TRUE (lnum %d)", *lnum);
+ }
+ else
+ { res = FALSE;
+ debug0(DBS, D, "SearchLines returning FALSE");
+ }
+ return res;
+ } /* end SearchLines */
+
+
+ /*@::DbRetrieve()@************************************************************/
+ /* */
+ /* BOOLEAN DbRetrieve(db, gall, sym, tag, seq, dfnum, dfpos, dlnum, cont) */
+ /* */
+ /* Retrieve the first entry of database db with the given gall, sym and */
+ /* tag. Set *seq, *dfnum, *dlnum, *dfpos to the associated value. */
+ /* Set *cont to a private value for passing to DbRetrieveNext. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN DbRetrieve(OBJECT db, BOOLEAN gall, OBJECT sym, FULL_CHAR *tag,
+ FULL_CHAR *seq, FILE_NUM *dfnum, long *dfpos, int *dlnum, long *cont)
+ { int symnum, lnum; FULL_CHAR line[MAX_BUFF], buff[MAX_BUFF];
+ ifdebug(DPP, D, ProfileOn("DbRetrieve"));
+ debug4(DBS, DD, "DbRetrieve(%s, %s%s&%s)", string(db), gall ? "0" : "",
+ SymName(sym), tag);
+
+ /* check OK to proceed */
+ if( !reading(db) || db_filep(db) == null )
+ { debug0(DBS, DD, "DbRetrieve returning FALSE (empty or not reading)");
+ ifdebug(DPP, D, ProfileOff("DbRetrieve"));
+ return FALSE;
+ }
+
+ /* convert parameters into search key */
+ SymToNum(db, sym, symnum, FALSE);
+ sprintf( (char *) buff, "%s%d&%s", gall ? "0" : "", symnum, tag);
+
+ if( in_memory(db) )
+ {
+ /* search internal table, return if not found; set *cont to continuation */
+ if( !SearchLines(db_lines(db), 0, db_lineslen(db) - 1, buff, &lnum) )
+ { debug0(DBS, DD, "DbRetrieve returning FALSE (key not present)");
+ ifdebug(DPP, D, ProfileOff("DbRetrieve"));
+ return FALSE;
+ }
+ sscanf( (char *) db_lines(db)[lnum],
+ "%*[^\t]\t%[^\t]\t%*[^\t]\t%ld\t%d\t%[^\n]", seq, dfpos, dlnum, buff);
+ *cont = lnum+1;
+ }
+ else
+ {
+ /* search for key in file, return if not found; set *cont to continuatn */
+ fseek(db_filep(db), 0L, SEEK_END);
+ if( !SearchFile(db_filep(db), (int) left_pos(db),
+ (int) ftell(db_filep(db)) - 1, buff, line) )
+ { debug0(DBS, DD, "DbRetrieve returning FALSE (key not present)");
+ ifdebug(DPP, D, ProfileOff("DbRetrieve"));
+ return FALSE;
+ }
+ sscanf( (char *) line,
+ "%*[^\t]\t%[^\t]\t%*[^\t]\t%ld\t%d\t%[^\n]", seq, dfpos, dlnum, buff);
+ *cont = ftell(db_filep(db));
+ }
+
+ /* work out file name if . abbreviation used, and possibly define file */
+ if( StringEqual(buff, AsciiToFull(".")) )
+ { StringCopy(buff, string(db));
+ }
+ *dfnum = FileNum(buff, DATA_SUFFIX);
+ if( *dfnum == NO_FILE ) /* can only occur in cross reference database */
+ { debug0(DFS, D, " calling DefineFile from DbRetrieve");
+ *dfnum = DefineFile(buff, DATA_SUFFIX, &fpos(db),
+ DATABASE_FILE, SOURCE_PATH);
+ }
+
+ /* return */
+ debug3(DBS, DD, "DbRetrieve returning TRUE (in %s at %ld, line %d)",
+ FileName(*dfnum), *dfpos, *dlnum);
+ ifdebug(DPP, D, ProfileOff("DbRetrieve"));
+ return TRUE;
+ } /* end DbRetrieve */
+
+
+ /*@::DbRetrieveNext()@********************************************************/
+ /* */
+ /* BOOLEAN DbRetrieveNext(db, gall, sym, tag, seq, dfnum, dfpos,dlnum,cont) */
+ /* */
+ /* Retrieve the entry of database db pointed to by *cont. */
+ /* Set *gall, *sym, *tag, *seq, *dfnum, *dlnum, *dfpos to the value. */
+ /* Reset *cont to the next entry for passing to the next DbRetrieveNext. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN DbRetrieveNext(OBJECT db, BOOLEAN *gall, OBJECT *sym, FULL_CHAR *tag,
+ FULL_CHAR *seq, FILE_NUM *dfnum, long *dfpos, int *dlnum, long *cont)
+ { FULL_CHAR line[MAX_BUFF], *cline, fname[MAX_BUFF]; int symnum;
+ ifdebug(DPP, D, ProfileOn("DbRetrieveNext"));
+ debug2(DBS, DD, "DbRetrieveNext( %s, %ld )", string(db), *cont);
+ assert(reading(db), "DbRetrieveNext: not reading");
+
+ /* check OK to proceed */
+ if( db_filep(db) == null )
+ { debug0(DBS, DD, "DbRetrieveNext returning FALSE (empty database)");
+ ifdebug(DPP, D, ProfileOff("DbRetrieveNext"));
+ return FALSE;
+ }
+
+ if( in_memory(db) )
+ {
+ /* get next entry from internal database */
+ if( *cont >= db_lineslen(db) )
+ { debug0(DBS, DD, "DbRetrieveNext returning FALSE (no successor)");
+ ifdebug(DPP, D, ProfileOff("DbRetrieveNext"));
+ return FALSE;
+ }
+ cline = (FULL_CHAR *) db_lines(db)[*cont];
+ *gall = (cline[0] == '0' ? 1 : 0);
+ sscanf((char *)&cline[*gall], "%d&%[^\t]\t%[^\t]\t%*[^\t]\t%ld\t%d\t%[^\n]",
+ &symnum, tag, seq, dfpos, dlnum, fname);
+ *cont = *cont + 1;
+ }
+ else
+ {
+ /* use *cont to find position of next entry; advance *cont */
+ fseek(db_filep(db), *cont == 0L ? (long) left_pos(db) : *cont, SEEK_SET);
+ if( StringFGets(line, MAX_BUFF, db_filep(db)) == NULL )
+ { debug0(DBS, DD, "DbRetrieveNext returning FALSE (no successor)");
+ ifdebug(DPP, D, ProfileOff("DbRetrieveNext"));
+ return FALSE;
+ }
+ *gall = (line[0] == '0' ? 1 : 0);
+ sscanf((char *)&line[*gall], "%d&%[^\t]\t%[^\t]\t%*[^\t]\t%ld\t%d\t%[^\n]",
+ &symnum, tag, seq, dfpos, dlnum, fname);
+ *cont = ftell(db_filep(db));
+ }
+
+ /* work out file name if . abbreviation used, and possibly define file */
+ if( StringEqual(fname, AsciiToFull(".")) )
+ { StringCopy(fname, string(db));
+ }
+ *dfnum = FileNum(fname, DATA_SUFFIX);
+ if( *dfnum == NO_FILE ) /* can only occur in cross reference database */
+ { debug0(DFS, D, " calling DefineFile from DbRetrieveNext");
+ *dfnum = DefineFile(fname, DATA_SUFFIX, &fpos(db),
+ DATABASE_FILE, SOURCE_PATH);
+ }
+ NumToSym(db, symnum, *sym);
+
+ /* return */
+ debug3(DBS, DD, "DbRetrieveNext returning TRUE (in %s at %ld, line %d)",
+ FileName(*dfnum), *dfpos, *dlnum);
+ ifdebug(DPP, D, ProfileOff("DbRetrieveNext"));
+ return TRUE;
+ } /* end DbRetrieveNext */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z34.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z34.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z34.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,112 ----
+ /*@z34.c:Rotation Service:Declarations@***************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z34.c */
+ /* MODULE: Rotation Service */
+ /* EXTERNS: RotateSize() */
+ /* */
+ /*****************************************************************************/
+ #include <math.h>
+ #ifndef M_PI
+ #define M_PI 3.1415926535897931160E0
+ #endif
+ #include "externs.h"
+
+ typedef struct { double x, y; } rect_coord;
+ typedef struct { double angle, radius; } polar_coord;
+
+ #define rect_to_polar(rect, polar) \
+ polar.angle = atan2(rect.y, rect.x), \
+ polar.radius = sqrt(rect.x*rect.x + rect.y*rect.y)
+
+ #define polar_to_rect(polar, rect) \
+ rect.x = polar.radius * cos(polar.angle), \
+ rect.y = polar.radius * sin(polar.angle)
+
+
+ /*@::RotateSize()@************************************************************/
+ /* */
+ /* RotateSize(xcb, xcf, xrb, xrf, y, theta) */
+ /* */
+ /* Calculate the size of x, assuming that it is y rotated by theta degrees. */
+ /* */
+ /*****************************************************************************/
+
+ void RotateSize(FULL_LENGTH *xcb, FULL_LENGTH *xcf, FULL_LENGTH *xrb,
+ FULL_LENGTH *xrf, OBJECT y, FULL_LENGTH theta)
+ { rect_coord ycorners[4], xcorner; polar_coord pol;
+ double maxx, maxy, minx, miny, ang; int i;
+ #if DEBUG_ON
+ char buff1[20], buff2[20];
+ #endif
+
+ /* calculate theta in radians */
+ ang = (double) theta * 2 * M_PI / (double) (DG * 360);
+ ifdebug(DRS, D, sprintf(buff2, "%.1f", ang));
+ debug2(DRS, D, "RotateSize( %s, %s )", EchoObject(y), buff2);
+ debug4(DRS, DD, " ycb %s, ycf %s, yrb %s, yrf %s",
+ EchoLength(back(y, COLM)), EchoLength(fwd(y, COLM)),
+ EchoLength(back(y, ROWM)), EchoLength(fwd(y, ROWM)));
+
+ /* set up coordinates of the four corners of y */
+ ycorners[0].x = (float) fwd(y, COLM);
+ ycorners[0].y = (float) back(y, ROWM);
+ ycorners[1].x = - (float) back(y, COLM);
+ ycorners[1].y = (float) back(y, ROWM);
+ ycorners[2].x = - (float) back(y, COLM);
+ ycorners[2].y = - (float) fwd(y, ROWM);
+ ycorners[3].x = (float) fwd(y, COLM);
+ ycorners[3].y = - (float) fwd(y, ROWM);
+
+ /* rotate these four corners by theta and store their extremes */
+ maxx = maxy = (float) - MAX_FULL_LENGTH;
+ minx = miny = (float) MAX_FULL_LENGTH;
+ for( i = 0; i < 4; i++ )
+ {
+ if( ycorners[i].x == 0 && ycorners[i].y == 0 )
+ { pol.radius = 0; pol.angle = 0; }
+ else rect_to_polar(ycorners[i], pol);
+ ifdebug(DRS, DD, sprintf(buff1, "%.1f", pol.angle));
+ ifdebug(DRS, DD, sprintf(buff2, "%.1f", ang));
+ debug5(DRS, DD, " transforming (%s, %s) -> (%s, %s) + %s",
+ EchoLength( (int) ycorners[i].x), EchoLength( (int) ycorners[i].y),
+ EchoLength( (int) pol.radius), buff1, buff2);
+ pol.angle += ang;
+ polar_to_rect(pol, xcorner);
+ ifdebug(DRS, DD, sprintf(buff1, "%.1f", pol.angle));
+ debug4(DRS, DD, " transforming (%s, %s) -> (%s, %s)",
+ EchoLength( (int) pol.radius), buff1,
+ EchoLength( (int) xcorner.x), EchoLength( (int) xcorner.y) );
+ maxx = find_max(maxx, xcorner.x); minx = find_min(minx, xcorner.x);
+ maxy = find_max(maxy, xcorner.y); miny = find_min(miny, xcorner.y);
+ }
+
+ /* store sizes back into x and return */
+ *xcb = - (int) minx; *xcf = (int) maxx;
+ *xrb = (int) maxy; *xrf = - (int) miny;
+ debug0(DRS, D, "RotateSize returning.");
+ debug4(DRS, DD, " xcb %s, xcf %s, xrb %s, xrf %s",
+ EchoLength(*xcb), EchoLength(*xcf),
+ EchoLength(*xrb), EchoLength(*xrf));
+ } /* end RotateSize */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z35.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z35.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z35.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,151 ----
+ /*@z35.c:Time Keeper: MomentSym(), TimeString()@******************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z35.c */
+ /* MODULE: Time Keeper */
+ /* EXTERNS: MomentSym, InitTime(), StartMoment(), TimeString() */
+ /* */
+ /*****************************************************************************/
+ #include <time.h>
+ #include "externs.h"
+
+ #define load(str, typ, encl) \
+ sym = InsertSym(str, typ, no_fpos, DEFAULT_PREC, \
+ FALSE, FALSE, 0, encl, MakeWord(WORD, STR_EMPTY, no_fpos)); \
+ if( typ == NPAR ) visible(sym) = TRUE
+
+ #define add_par(format, val, sym) \
+ sprintf( (char *) buff, format, val); \
+ New(par, PAR); actual(par) = sym; \
+ Link(current_moment, par); \
+ tmp = MakeWord(WORD, buff, no_fpos); \
+ Link(par, tmp);
+
+ static OBJECT current_moment = nilobj;
+ static FULL_CHAR time_string[30] = { '\0' };
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT MomentSym; */
+ /* */
+ /* The symbol table entry for the @Moment symbol. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT MomentSym = nilobj;
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *TimeString() */
+ /* */
+ /* Returns a pointer to a string containing the current time. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *TimeString(void)
+ { return time_string;
+ } /* end TimeString */
+
+
+ /*@::InitTime(), StartMoment()@***********************************************/
+ /* */
+ /* InitTime() */
+ /* */
+ /* Place a declaration of the @Moment symbol into the symbol table, and */
+ /* initialize the value of the object StartMoment. */
+ /* */
+ /*****************************************************************************/
+
+ void InitTime(void)
+ { time_t raw_time; struct tm *now;
+ FULL_CHAR buff[20]; OBJECT par, tmp, sym, env;
+ OBJECT tag, second, minute, hour, weekday,
+ monthday, yearday, month, year, century, dst;
+ debug0(DTK, D, "InitTime()");
+
+ /* define @Moment symbol with its host of named parameters */
+ MomentSym = load(KW_MOMENT, LOCAL, StartSym);
+ tag = load(KW_TAG, NPAR, MomentSym);
+ second = load(KW_SECOND, NPAR, MomentSym);
+ minute = load(KW_MINUTE, NPAR, MomentSym);
+ hour = load(KW_HOUR, NPAR, MomentSym);
+ monthday = load(KW_DAY, NPAR, MomentSym);
+ month = load(KW_MONTH, NPAR, MomentSym);
+ year = load(KW_YEAR, NPAR, MomentSym);
+ century = load(KW_CENTURY, NPAR, MomentSym);
+ weekday = load(KW_WEEKDAY, NPAR, MomentSym);
+ yearday = load(KW_YEARDAY, NPAR, MomentSym);
+ dst = load(KW_DAYLIGHTSAVING, NPAR, MomentSym);
+
+ /* get current time and convert to ASCII */
+ if( time(&raw_time) == -1 )
+ Error(35, 1, "unable to obtain the current time", WARN, no_fpos);
+ now = localtime(&raw_time);
+ StringCopy(time_string, AsciiToFull(asctime(now)));
+
+ /* start of current_moment */
+ New(current_moment, CLOSURE);
+ actual(current_moment) = MomentSym;
+
+ /* attach its many parameters */
+ add_par("%s", KW_NOW, tag);
+ add_par("%.2d", now->tm_sec, second);
+ add_par("%.2d", now->tm_min, minute);
+ add_par("%.2d", now->tm_hour, hour);
+ add_par("%d", now->tm_mday, monthday);
+ add_par("%d", now->tm_mon + 1, month);
+ add_par("%.2d", now->tm_year % 100, year);
+ add_par("%d", (now->tm_year+1900) / 100, century);
+ add_par("%d", now->tm_wday + 1, weekday);
+ add_par("%d", now->tm_yday, yearday);
+ add_par("%d", now->tm_isdst, dst);
+
+ /* add a null environment */
+ New(env, ENV);
+ AttachEnv(env, current_moment);
+ debug0(DTK, D, "InitTime() returning.");
+ debug0(DTK, DD, "current_moment =");
+ ifdebug(DTK, DD, DebugObject(current_moment));
+ } /* end InitTime */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT StartMoment() */
+ /* */
+ /* Returns a copy of the initial time. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT StartMoment(void)
+ { OBJECT res;
+ debug0(DTK, D, "StartMoment()");
+ assert(current_moment != nilobj, "StartMoment: current_moment == nilobj!");
+ res = CopyObject(current_moment, no_fpos);
+ debug0(DTK, D, "StartMoment returning");
+ ifdebug(DTK, D, DebugObject(res));
+ return res;
+ }
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z36.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z36.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z36.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1225 ----
+ /*@z36.c:Hyphenation: Declarations@*******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z36.c */
+ /* MODULE: Hyphenation */
+ /* EXTERNS: Hyphenate() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define NODE_MULT 4 /* what to multiply node indexes by */
+ #define MAX_CHAR 256 /* max chars represented in one char */
+ #define TRIE_MAGIC 5361534
+ #define KILL_CLASS 0 /* characters preventing hyphenation */
+ #define PUNCT_CLASS 1 /* characters delimiting hyphenation */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static tex_codes[] */
+ /* */
+ /* TeX hyphenation files often contain escape sequences consisting of a */
+ /* backslash and two or three characters to denote 8-bit characters. This */
+ /* code will read and translate such sequences if they are in the following */
+ /* list. */
+ /* */
+ /*****************************************************************************/
+
+ static char *tex_codes[] = {
+
+ "Agrave", "`A", "\300",
+ "Aacute", "'A", "\301",
+ "Acircumflex", "^A", "\302",
+ "Atilde", "~A", "\303",
+ "Adieresis", "\"A", "\304",
+ "agrave", "`a", "\340",
+ "aacute", "'a", "\341",
+ "acircumflex", "^a", "\342",
+ "atilde", "~a", "\343",
+ "adieresis", "\"a", "\344",
+
+ "ccedilla", "cc", "\347",
+
+ "Egrave", "`E", "\310",
+ "Eacute", "'E", "\311",
+ "Ecircumflex", "^E", "\312",
+ "Edieresis", "\"E", "\313",
+ "egrave", "`e", "\350",
+ "eacute", "'e", "\351",
+ "ecircumflex", "^e", "\352",
+ "edieresis", "\"e", "\353",
+
+ "Igrave", "`I", "\314",
+ "Iacute", "'I", "\315",
+ "Icircumflex", "^I", "\316",
+ "Idieresis", "\"I", "\317",
+ "igrave", "`\\i", "\354",
+ "iacute", "'\\i", "\355",
+ "icircumflex", "^\\i", "\356",
+ "idieresis", "\"\\i","\357",
+
+ "Ograve", "`O", "\322",
+ "Oacute", "'O", "\323",
+ "Ocircumflex", "^O", "\324",
+ "Otilde", "~O", "\325",
+ "Odieresis", "\"O", "\326",
+ "ograve", "`o", "\362",
+ "oacute", "'o", "\363",
+ "ocircumflex", "^o", "\364",
+ "otilde", "~o", "\365",
+ "odieresis", "\"o", "\366",
+
+ "Ugrave", "`U", "\331",
+ "Uacute", "'U", "\332",
+ "Ucircumflex", "^U", "\333",
+ "Udieresis", "\"U", "\334",
+ "ugrave", "`u", "\371",
+ "uacute", "'u", "\372",
+ "ucircumflex", "^u", "\373",
+ "udieresis", "\"u", "\374",
+
+ "", "", ""
+ };
+
+ static void DecodeEscapes(FULL_CHAR *str, FULL_CHAR *fname, int hline_num)
+ { FULL_CHAR *p, *q;
+ int i;
+ p = q = str;
+ while( *q != '\0' )
+ {
+ if( *q == '\\' )
+ { for( i = 0; tex_codes[i][0] != '\0'; i += 3 )
+ {
+ if( StringBeginsWith(q+1, AsciiToFull(tex_codes[i+1])) )
+ break;
+ }
+ if( tex_codes[i][0] != '\0' )
+ {
+ StringCopy(p, tex_codes[i+2]);
+ p += StringLength(AsciiToFull(tex_codes[i+2]));
+ q += StringLength(AsciiToFull(tex_codes[i+1])) + 1;
+ }
+ else
+ {
+ Error(36, 1, "in hyphenation file %s, unknown escape sequence (line %d)",
+ FATAL, no_fpos, fname, hline_num);
+ }
+ }
+ else *p++ = *q++;
+ }
+ *p++ = '\0';
+ } /* end DecodeEscapes */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static TRIE HyphTables[] */
+ /* */
+ /* The packed hyphenation tables, indexed by language. An entry is NULL */
+ /* when the table for that language has not yet been read in; TriedFile */
+ /* is TRUE after we have tried to read that file, whether or not we were */
+ /* successful. */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct trie_rec
+ { int magic; /* a magic number to make sure ok */
+ int class_count; /* the number of character classes */
+ unsigned char class[MAX_CHAR]; /* the character classes */
+ short *node_mem; /* the node memory */
+ int node_lim; /* top of node memory */
+ int node_free; /* first free space in node memory */
+ FULL_CHAR *string_mem; /* the string memory */
+ int string_lim; /* top of string memory */
+ int string_first; /* the first (last inserted) string */
+ } *TRIE;
+
+ static TRIE HyphTables[MAX_LANGUAGE] = { NULL };
+ static BOOLEAN TriedFile[MAX_LANGUAGE] = { FALSE };
+
+
+ /*@::CompressValue(), UncompressValue()@**************************************/
+ /* */
+ /* CompressValue(p, q) */
+ /* */
+ /* Compress value string p, placing the result in q. */
+ /* */
+ /*****************************************************************************/
+ #define FirstHalf(y) ( (y) >> 4 )
+ #define LastHalf(y) ( (y) & 15 )
+ #define AssignFirstHalf(x, y) ( (x) = ((y) << 4) )
+ #define AssignLastHalf(x, y) ( (x) |= (y) )
+
+ #define CompressValue(compressed, uncompressed) \
+ /* FULL_CHAR *compressed, *uncompressed; */ \
+ { register FULL_CHAR *p, *q; \
+ p = compressed; q = uncompressed; \
+ for( ; ; ) \
+ { \
+ if( *q == (FULL_CHAR) '\0' ) \
+ { *p = (FULL_CHAR) '\0'; \
+ break; \
+ } \
+ AssignFirstHalf(*p, *q++ - '0' + 2); \
+ if( *q == (FULL_CHAR) '\0' ) \
+ { *++p = (FULL_CHAR) '\0'; \
+ break; \
+ } \
+ AssignLastHalf(*p, *q++ - '0' + 2); \
+ p++; \
+ } \
+ }
+
+ /*****************************************************************************/
+ /* */
+ /* UncompressValue(q, p) */
+ /* */
+ /* Uncompress value string q, placing the result in p. */
+ /* */
+ /*****************************************************************************/
+
+ #define UncompressValue(compressed, uncompressed) \
+ /* FULL_CHAR *compressed, *uncompressed; */ \
+ { register FULL_CHAR *p, *q; \
+ p = compressed; q = uncompressed; \
+ for( ; ; ) \
+ { \
+ if( FirstHalf(*p) == '\0' ) break; \
+ *q++ = FirstHalf(*p) + '0' - 2; \
+ if( LastHalf(*p) == '\0' ) break; \
+ *q++ = LastHalf(*p) + '0' - 2; \
+ p++; \
+ } \
+ *q = (FULL_CHAR) '\0'; \
+ }
+
+ /*@::AltCompressValue(), AltUncompressValue()@********************************/
+ /* */
+ /* AltCompressValue(compressed, uncompressed) */
+ /* */
+ /* Compress value string, placing the result in compressed. */
+ /* */
+ /* This is an alternative compression scheme to the one given above, which */
+ /* should give better compression. The result is a sequence of pairs of */
+ /* the form (skip, value) saying that we are to skip so many places and */
+ /* then insert the given non-zero value. All the other values are zero. */
+ /* Skip values are 4-bit numbers (maximum skip is 15, but we will insert */
+ /* a 15 skip with a zero value in the rare case of skipping further). */
+ /* Values are also 4-bit numbers, known to be non-zero. So the memory */
+ /* cost is 8 bits per non-zero value. */
+ /* */
+ /*****************************************************************************/
+ #define CharPack(ch, a, b) (ch = ((a) << 4) | (b))
+ #define CharUnPack(ch, a, b) ((a) = (ch) >> 4, (b) = (ch) & 15)
+
+ #define AltCompressValue(compressed, uncompressed) \
+ /* FULL_CHAR *compressed, *uncompressed; */ \
+ { register FULL_CHAR *p, *q, *prev; \
+ prev = (uncompressed) - 1; p = (compressed); \
+ for( q = (uncompressed); *q != (FULL_CHAR) '\0'; q++ ) \
+ { \
+ if( *q != (FULL_CHAR) '0' || q - prev - 1 >= 15 ) \
+ { \
+ CharPack(*p++, q - prev - 1, *q - '0' + 2); \
+ prev = q; \
+ } \
+ } \
+ *p++ = (FULL_CHAR) '\0'; \
+ }
+
+ /*****************************************************************************/
+ /* */
+ /* AltUncompressValue(q, p) */
+ /* */
+ /* Uncompress value string q, placing the result in p. */
+ /* */
+ /*****************************************************************************/
+
+ #define AltUncompressValue(compressed, uncompressed) \
+ { register FULL_CHAR *p, *q, xval; int i, skip; \
+ q = (uncompressed); \
+ for( p = (compressed); *p != (FULL_CHAR) '\0'; p++ ) \
+ { CharUnPack(*p, skip, xval); \
+ for( i = 0; i < skip; i++ ) \
+ *q++ = (FULL_CHAR) '0'; \
+ *q++ = (FULL_CHAR) (xval + '0' - 2); \
+ } \
+ *q++ = (FULL_CHAR) '\0'; \
+ debug1(DHY, D, "AltUncompressValue returning %s", (uncompressed)); \
+ }
+
+ /* ***
+ static void AltUncompressValue(FULL_CHAR *compressed, FULL_CHAR *uncompressed)
+ { register FULL_CHAR *p, *q, xval; int i, skip;
+ q = uncompressed;
+ for( p = compressed; *p != (FULL_CHAR) '\0'; p++ )
+ { CharUnPack(*p, skip, xval);
+ for( i = 0; i < skip; i++ )
+ *q++ = (FULL_CHAR) '0';
+ *q++ = (FULL_CHAR) (xval + '0' - 2);
+ }
+ *q++ = (FULL_CHAR) '\0';
+ debug1(DHY, D, "AltUncompressValue returning %s", uncompressed);
+ }
+ *** */
+
+ /*@@**************************************************************************/
+ /* */
+ /* ClassConvert(in, out, T, fname, hline_num) */
+ /* */
+ /* Set out[i] to the character class of in[i] in T, for all i. */
+ /* */
+ /*****************************************************************************/
+
+ #define ClassConvert(in, out, T, fname, hline_num) \
+ { int i; \
+ for( i = 0; in[i] != '\0'; i++ ) \
+ if( T->class[in[i]] != 0 ) out[i] = T->class[in[i]]; \
+ else \
+ Error(36, 2, "in hyphenation file %s, line %d: character (octal %o) is not in any class", \
+ FATAL, no_fpos, fname, hline_num, in[i]); \
+ out[i] = '\0'; \
+ } /* end ClassConvert */
+
+
+ /*@::findrep(), TrieRetrieve(), ShowRate()@***********************************/
+ /* */
+ /* findrep(i, T) Returns one character whose class in T is i. */
+ /* */
+ /*****************************************************************************/
+ #if DEBUG_ON
+
+ static FULL_CHAR findrep(int i, TRIE T)
+ { int ch;
+ for( ch = 0; ch < MAX_CHAR; ch++ )
+ if( T->class[ch] == i ) return (FULL_CHAR) ch;
+ Error(36, 3, "DoTriePrint: findrep failed", INTERN, no_fpos);
+ return (FULL_CHAR) ch; /* never reached, but gcc doesn't know that */
+ } /* end findrep */
+
+
+ #if 0
+ /*****************************************************************************/
+ /* */
+ /* static FULL_CHAR *TrieRetrieve(key, T) */
+ /* */
+ /* Retrieve the value associated with key in T, or NULL if not present. */
+ /* This procedure is not presently in use. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR *TrieRetrieve(FULL_CHAR *key, TRIE T)
+ { FULL_CHAR str[MAX_BUFF]; int i, curr_node, next_node, pos;
+ debug1(DHY, DD, "TrieRetrieve(%s, T)", key);
+ ClassConvert(key, str, T, STR_EMPTY, 0);
+
+ /* invariant: curr_node is an existing node of T with prefix str[0..i-1] */
+ curr_node = i = 0;
+ for(;;)
+ {
+ /* if next_node is 0, the string was never inserted */
+ next_node = T->node_mem[curr_node + str[i]];
+ if( next_node == 0 ) return (FULL_CHAR *) NULL;
+
+ /* if next_node < 0 it represents an offset into the string memory */
+ if( next_node < 0 )
+ { pos = - next_node;
+ if( str[i] != '\0' )
+ { do
+ { if( str[++i] != T->string_mem[pos++] ) return (FULL_CHAR *) NULL;
+ } while( str[i] != '\0' );
+ }
+ return &(T->string_mem[pos]);
+ }
+
+ /* otherwise next_node is the trie node to be searched next */
+ curr_node = NODE_MULT*next_node; i++;
+ }
+ } /* end TrieRetrieve */
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* static ShowRate(key, start, stop, rate, fp) */
+ /* */
+ /* Debug print of key[] and rate[] on file fp. */
+ /* */
+ /*****************************************************************************/
+
+ static void ShowRate(FULL_CHAR *key, int start, int stop, FULL_CHAR *rate,
+ FILE *fp)
+ { int i;
+ fprintf(fp, "key: ");
+ for( i = start; i < stop; i++ ) fprintf(fp, " %c", key[i]);
+ fprintf(fp, "\nrate:");
+ for( i = 0; rate[i] != '\0'; i++ ) fprintf(fp, " %c", rate[i]);
+ fprintf(fp, "\n");
+ } /* end ShowRate */
+
+
+ /*@::DoTriePrint(), TriePrint()@**********************************************/
+ /* */
+ /* static DoTriePrint(T, node, len, fp) */
+ /* */
+ /* Print on file fp the subset of the entries of trie T stored in node and */
+ /* its descendants. The node has prefix prefix[0..len-1]. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR prefix[MAX_BUFF];
+
+ static void DoTriePrint(TRIE T, int node, int len, FILE *fp)
+ { int i, next_node, pos; FULL_CHAR str[20];
+ for( i = 0; i < T->class_count; i++ )
+ {
+ /* if next_node < 0, have string to print */
+ next_node = T->node_mem[node + i];
+ if( next_node < 0 )
+ {
+ prefix[len] = '\0';
+ fprintf(fp, "%s", prefix);
+ pos = - next_node;
+ if( i != 0 )
+ {
+ fprintf(fp, "%c", findrep(i, T));
+ while( T->string_mem[pos] != '\0' )
+ { fprintf(fp, "%c", findrep(T->string_mem[pos], T));
+ pos++;
+ }
+ pos++;
+ }
+ AltUncompressValue(&(T->string_mem[pos]), str);
+ fprintf(fp, " %s\n", str);
+ }
+
+ /* else if next_node > 0 have a child node to explore */
+ else if( next_node > 0 )
+ { assert( i > 0, "DoTriePrint: i == 0!" );
+ prefix[len] = findrep(i, T);
+ prefix[len+1] = '\0';
+ DoTriePrint(T, NODE_MULT*next_node, len+1, fp);
+ }
+ }
+ } /* end DoTriePrint */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static TriePrint(T, fp) */
+ /* */
+ /* Print trie T on file fp. */
+ /* */
+ /*****************************************************************************/
+
+ static void TriePrint(TRIE T, FILE *fp)
+ { int i, ch;
+ assert( T-> magic == TRIE_MAGIC, "TriePrint: magic!" );
+ fprintf(fp, "Classes:");
+ for( i = 1; i < T->class_count; i++ )
+ { fprintf(fp, " ");
+ for( ch = 0; ch < MAX_CHAR; ch++ )
+ if( T->class[ch] == i ) fprintf(fp, "%c", ch);
+ }
+ fprintf(fp, "\n");
+ fprintf(fp, "Node space: %d capacity, %d used\n", T->node_lim, T->node_free);
+ fprintf(fp, "String space: %d capacity, %d used\n", T->string_lim,
+ T->string_lim - T->string_first);
+ prefix[0] = '\0';
+ DoTriePrint(T, 0, 0, fp);
+ } /* end TriePrint */
+ #endif
+
+
+ /*@::NewTrie(), NewTrieString(), NewTrieNode()@*******************************/
+ /* */
+ /* static TRIE NewTrie(node_lim, string_lim) */
+ /* */
+ /* Initialize a new trie with this much space for nodes and strings. */
+ /* */
+ /*****************************************************************************/
+
+ static TRIE NewTrie(unsigned node_lim, unsigned string_lim)
+ { TRIE T; int i;
+ debug2(DHY, DD, "NewTrie(%d, %d)", node_lim, string_lim);
+ ifdebug(DMA, DD, DebugRegisterUsage(MEM_HYPH_PATS, 1,
+ sizeof(struct trie_rec) + node_lim*sizeof(short)+string_lim*sizeof(char)));
+ T = (TRIE) malloc( sizeof(struct trie_rec)
+ + node_lim*sizeof(short) + string_lim*sizeof(char));
+ if( T == (TRIE) NULL )
+ Error(36, 4, "run out of memory while constructing hyphenation table",
+ FATAL, no_fpos);
+ T->magic = TRIE_MAGIC; T->class_count = 1;
+ for( i = 0; i < MAX_CHAR; i++ ) T->class[i] = 0;
+ T->node_mem = (short *) ( (char *) T + sizeof(struct trie_rec));
+ T->node_lim = node_lim; T->node_free = 0;
+ T->string_mem = (FULL_CHAR *) &(T->node_mem[node_lim]);
+ T->string_lim = T->string_first = string_lim;
+ debug0(DHY, DD, "NewTrie returning.");
+ return T;
+ } /* end NewTrie */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static short NewTrieString(str, T) */
+ /* */
+ /* Copy a new string into T, and return its offset in string_mem; */
+ /* */
+ /*****************************************************************************/
+
+ static short NewTrieString(FULL_CHAR *str, TRIE T)
+ { short res = T->string_first - StringLength(str) - 1;
+ if( res >= 0 )
+ { T->string_first = res; StringCopy(&(T->string_mem[res]), str);
+ }
+ return res;
+ } /* end NewTrieString */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ststic int NewTrieNode(T) */
+ /* */
+ /* Allocate a new empty trie node in T, and return its offset in node_mem. */
+ /* */
+ /*****************************************************************************/
+
+ static int NewTrieNode(TRIE T)
+ { int i; int res;
+ if( T->node_free + T->class_count > T->node_lim )
+ Error(36, 5, "hyphenation trie node limit exceeded", INTERN, no_fpos);
+ res = T->node_free; T->node_free += T->class_count;
+ for( i = res; i < T->node_free; i++ ) T->node_mem[i] = 0;
+ return res;
+ } /* end NewTrieNode */
+
+
+ /*@::AddClassToTrie(), TrieInsert()@******************************************/
+ /* */
+ /* static AddClassToTrie(str, T) */
+ /* */
+ /* Add a new character class, whose members are the characters of str, to */
+ /* trie T. This cannot occur after the first insertion. */
+ /* */
+ /*****************************************************************************/
+
+ static void AddClassToTrie(FULL_CHAR *str, TRIE T)
+ { int i;
+ assert( T->string_first == T->string_lim, "AddClassToTrie: after insertion");
+ for( i = 0; str[i] != '\0'; i++ )
+ if( T->class[str[i]] == 0 ) T->class[str[i]] = T->class_count;
+ else Error(36, 6, "hyphenation class of %c may not be changed",
+ INTERN, no_fpos, str[i]);
+ T->class_count++;
+ } /* end AddClassToTrie */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static BOOLEAN TrieInsert(key, value, T, fname, hline_num) */
+ /* */
+ /* Insert a new key and value into trie T (originating in file fname on */
+ /* line hline_num). */
+ /* */
+ /*****************************************************************************/
+
+ static BOOLEAN TrieInsert(FULL_CHAR *key, FULL_CHAR *value, TRIE T,
+ FULL_CHAR *fname, int hline_num)
+ { FULL_CHAR str[MAX_BUFF], compressed_value[MAX_BUFF];
+ int i, curr_node, next_node, pos, ch; short strpos;
+ debug2(DHY, DD, "TrieInsert(%s, %s, T)", key, value);
+
+ /* if first insertion, add one node after making sure class_count is even */
+ if( T->node_free == 0 )
+ { T->class_count = NODE_MULT * ceiling(T->class_count, NODE_MULT);
+ ch = NewTrieNode(T);
+ }
+
+ AltCompressValue(compressed_value, value);
+
+ /* invariant: curr_node is an existing node of T with prefix str[0..i-1] */
+ ClassConvert(key, str, T, fname, hline_num);
+ curr_node = i = 0;
+ for(;;)
+ {
+ /* if str is ended, add compressed_value only to string memory */
+ if( str[i] == '\0' )
+ { if( T->node_mem[curr_node] != 0 )
+ Error(36, 7, "hyphenation string %s already inserted",
+ INTERN, no_fpos, key);
+ else
+ {
+ strpos = NewTrieString(compressed_value, T);
+ if( strpos < 0 )
+ { debug0(DHY, DD, "TrieInsert returning FALSE (trie full)");
+ return FALSE;
+ }
+ T->node_mem[curr_node] = - strpos;
+ }
+ debug0(DHY, DD, "TrieInsert returning TRUE (empty suffix).");
+ return TRUE;
+ }
+
+ /* if next position is unoccupied, store remainder of str and value */
+ next_node = T->node_mem[curr_node + str[i]];
+ if( next_node == 0 )
+ { ch = NewTrieString(compressed_value, T);
+ if( ch < 0 )
+ { debug0(DHY, DD, "TrieInsert returning FALSE (trie full)");
+ return FALSE;
+ }
+ strpos = NewTrieString(&str[i+1], T);
+ if( strpos < 0 )
+ { debug0(DHY, DD, "TrieInsert returning FALSE (trie full)");
+ return FALSE;
+ }
+ T->node_mem[curr_node + str[i]] = - strpos;
+ debug0(DHY, DD, "TrieInsert returning (non-empty suffix).");
+ return TRUE;
+ }
+
+ /* if next position is occupied by a non-empty string, move that */
+ /* string down one level and replace it by a trie node */
+ if( next_node < 0 )
+ { pos = - next_node;
+ ch = T->string_mem[pos];
+ if( T->string_first == pos ) T->string_first++;
+ T->node_mem[curr_node + str[i]] = next_node = NewTrieNode(T)/NODE_MULT;
+ T->node_mem[NODE_MULT*next_node + ch] = -(pos+1);
+ }
+
+ /* now next is the offset of the next node to be searched */
+ curr_node = NODE_MULT*next_node; i++;
+ }
+ } /* end TrieInsert */
+
+
+ /*@::BeGetChar(), BePutChar(), BeGetShort(), BePutShort(), etc.@**************/
+ /* */
+ /* BeGetChar(fp, pv) */
+ /* BePutChar(fp, v) */
+ /* BeGetShort(fp, pv) */
+ /* BePutShort(fp, v) */
+ /* BeGetInt(fp, pv) */
+ /* BePutInt(fp, v) */
+ /* */
+ /* Get char, short, or int pv from file fp, and put char, short, or int */
+ /* onto file fp. These routines are designed so that the file can be */
+ /* written or read safely by big-endian and little-endian architectures; */
+ /* this is accomplished by reading and writing one byte at a time to and */
+ /* from a big-endian format file. All return 0 on success, -1 on failure. */
+ /* Thanks to David W. Sanderson for this code. */
+ /* */
+ /*****************************************************************************/
+
+ #define BeGetChar(fp, pv) ( (c = getc(fp)) == EOF ? -1 : (*pv = c & 0xFF, 0) )
+ #define BePutChar(fp, v) ( putc( (char) (v & 0xFF), fp), 0 )
+
+ #define BeGetShort(fp, pv) \
+ ( (c = getc(fp)) == EOF ? -1 : \
+ ( *pv = (c & 0xFF) << 8, \
+ (c = getc(fp)) == EOF ? -1 : (*pv |= c & 0xFF, 0) \
+ ) \
+ )
+
+ #define BePutShort(fp, v) \
+ ( putc((v >> 8) & 0xFF, fp), putc(v & 0xFF, fp), 0 )
+
+ static int BeGetInt(FILE *fp, int *pv)
+ { int c;
+ if ((c = getc(fp)) == EOF) return -1;
+ *pv = (c & 0xFF) << 24;
+ if ((c = getc(fp)) == EOF) return -1;
+ *pv |= (c & 0xFF) << 16;
+ if ((c = getc(fp)) == EOF) return -1;
+ *pv |= (c & 0xFF) << 8;
+ if ((c = getc(fp)) == EOF) return -1;
+ *pv |= c & 0xFF;
+ return 0;
+ }
+
+ static int BePutInt(FILE *fp, int v)
+ {
+ putc((v >> 24) & 0xFF, fp);
+ putc((v >> 16) & 0xFF, fp);
+ putc((v >> 8) & 0xFF, fp);
+ putc(v & 0xFF, fp);
+ return 0;
+ }
+
+
+ /*@::CompressTrie(), TrieRead(), AccumulateRating()@**************************/
+ /* */
+ /* static CompressTrie(T) */
+ /* */
+ /* Compress trie T and return its length in characters. */
+ /* */
+ /*****************************************************************************/
+
+ static void CompressTrie(TRIE T)
+ { FULL_CHAR *p, *q; int len, i;
+ debug0(DHY, DD, "CompressTrie(T), T =");
+ debug2(DHY, DD, "Node space: %d capacity, %d used\n",
+ T->node_lim, T->node_free);
+ debug2(DHY, DD, "String space: %d capacity, %d used\n",
+ T->string_lim, T->string_lim - T->string_first);
+ ifdebug(DHY, DD, TriePrint(T, stderr));
+ T->node_lim = T->node_free;
+ for( i = 0; i < T->node_lim; i++ )
+ if( T->node_mem[i] < 0 )
+ T->node_mem[i] = - ( -T->node_mem[i] - T->string_first);
+ p = (FULL_CHAR *) &(T->node_mem[T->node_free]);
+ q = &(T->string_mem[T->string_first]);
+ len = T->string_lim - T->string_first;
+ for( i = 0; i < len; i++ ) *p++ = *q++;
+ T->string_mem = (FULL_CHAR *) &(T->node_mem[T->node_lim]);
+ T->string_first = 0;
+ T->string_lim = len;
+ len = sizeof(struct trie_rec) + T->node_lim * sizeof(short)
+ + T->string_lim * sizeof(FULL_CHAR);
+ debug1(DHY, DD, "CompressTrie returning; len = %d, T =", len);
+ ifdebug(DHY, DD, TriePrint(T, stderr));
+ } /* end CompressTrie */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static TRIE TrieRead(lnum, success) */
+ /* */
+ /* Read in a packed trie if possible, otherwise pack an unpacked one. */
+ /* The trie is to be for language lnum. */
+ /* */
+ /* Boolean success is set to true if no errors were encountered. If the */
+ /* file read was a placeholder, success will be true but still a null */
+ /* TRIE will be returned. */
+ /* */
+ /*****************************************************************************/
+ #define START_STATE 0
+ #define CLASSES_STATE 1
+ #define EXCEPTIONS_STATE 2
+ #define LENGTH_LIMIT_STATE 3
+ #define PATTERNS_STATE 4
+
+ static TRIE TrieRead(LANGUAGE_NUM lnum, BOOLEAN *success)
+ { TRIE T; FILE_NUM unpacked_fnum, packed_fnum; OBJECT fname;
+ FILE *unpacked_fp, *packed_fp; unsigned len;
+ int prev, i, j, c, state, hline_num, length_limit;
+ #if DEBUG_ON
+ int icount = 0;
+ #endif
+ debug2(DHY, DD, "TrieRead(%d %s)", lnum,
+ lnum == 0 ? STR_NONE : LanguageString(lnum));
+
+ /* get hyphenation file name from language module */
+ fname = LanguageHyph(lnum);
+ assert( fname == nilobj || is_word(type(fname)), "TrieRead: fname!" );
+ if( fname == nilobj )
+ { *success = FALSE;
+ return (TRIE) NULL;
+ }
+
+ /* define and open packed file */
+ debug0(DFS, DD, " calling DefineFile from TrieRead (1)");
+ packed_fnum = DefineFile(string(fname), HYPH_PACKED_SUFFIX,
+ &fpos(fname), HYPH_PACKED_FILE, HYPH_PATH);
+ if( InitializeAll )
+ {
+ /* initializing so want to reconstruct packed files */
+ /* thanks to Ian Jackson <ian at chiark.greenend.org.uk> for this */
+ packed_fp = NULL;
+ }
+ else
+ {
+ /* not initializing so use existing packed files if possible */
+ packed_fp = OpenFile(packed_fnum, FALSE, FALSE);
+ }
+
+ if( packed_fp == NULL )
+ {
+ /* no packed file, so define and open unpacked one instead */
+ FULL_CHAR str[MAX_BUFF], key[MAX_BUFF], value[MAX_BUFF],
+ buff[MAX_BUFF+10];
+ int bpos, bcount;
+ debug0(DFS, DD, " calling DefineFile from TrieRead (2)");
+ unpacked_fnum = DefineFile(string(fname), HYPH_SUFFIX,
+ &fpos(fname), HYPH_FILE, HYPH_PATH);
+ unpacked_fp = OpenFile(unpacked_fnum, FALSE, FALSE);
+ if( unpacked_fp == NULL )
+ { Error(36, 8, "cannot open hyphenation file %s",
+ WARN, no_fpos, FileName(unpacked_fnum));
+ *success = FALSE;
+ return (TRIE) NULL;
+ }
+
+ /* check that first line contains magic header or stub */
+ if( StringFGets(str, MAX_BUFF, unpacked_fp) == NULL ||
+ ( !StringEqual(str, AsciiToFull("Lout hyphenation information\n")) &&
+ !StringEqual(str, AsciiToFull("Lout hyphenation placeholder\n")) )
+ )
+ Error(36, 9, "header line of hyphenation file %s missing",
+ FATAL, no_fpos, FileName(unpacked_fnum));
+
+ /* if file is just a placeholder, exit silently with success */
+ if( !StringEqual(str, AsciiToFull("Lout hyphenation information\n")) )
+ { *success = TRUE;
+ return (TRIE) NULL;
+ }
+
+ /* read the classes, exceptions, and patterns from the unpacked file */
+ T = NewTrie( (unsigned) 120000, (unsigned) 32767);
+ state = START_STATE;
+ hline_num = 1;
+ length_limit = 0;
+ while( StringFGets(buff, MAX_BUFF, unpacked_fp) != NULL )
+ {
+ hline_num++; bpos = 0;
+ while( sscanf( (char *) &buff[bpos], "%s%n", str, &bcount) == 1 &&
+ str[0] != '%' )
+ {
+ bpos += bcount;
+ DecodeEscapes(str, string(fname), hline_num);
+
+ switch( state )
+ {
+ case START_STATE:
+
+ if( !StringEqual(str, AsciiToFull("Classes:")) )
+ Error(36, 10, "Classes heading of hyphenation file %s missing",
+ FATAL, no_fpos, FileName(unpacked_fnum));
+ state = CLASSES_STATE;
+ break;
+
+
+ case CLASSES_STATE:
+
+ if( StringEqual(str, AsciiToFull("Exceptions:")) )
+ { state = EXCEPTIONS_STATE;
+ }
+ else if( StringEqual(str, AsciiToFull("Patterns:")) )
+ { state = PATTERNS_STATE;
+ }
+ else if( StringEqual(str, AsciiToFull("LengthLimit:")) )
+ { state = LENGTH_LIMIT_STATE;
+ }
+ else
+ { debug1(DHY, DD, "adding class %s", str);
+ AddClassToTrie(str, T);
+ }
+ break;
+
+
+ case EXCEPTIONS_STATE:
+
+ if( StringEqual(str, AsciiToFull("Patterns:")) )
+ { state = PATTERNS_STATE;
+ }
+ else if( StringEqual(str, AsciiToFull("LengthLimit:")) )
+ { state = LENGTH_LIMIT_STATE;
+ }
+ else
+ { prev = CH_EIGHT; j = 0;
+ key[j] = '.', value[j++] = prev, prev = CH_EIGHT;
+ for( i = 0; str[i] != '\0'; i++ )
+ { if( str[i] == CH_HYPHEN ) prev = CH_NINE;
+ else key[j] = str[i], value[j++] = prev, prev = CH_EIGHT;
+ }
+ key[j] = '.', value[j++] = prev, prev = CH_EIGHT;
+ key[j] = '\0'; value[j] = prev; value[j+1] = '\0';
+ if( !TrieInsert(key, value, T, string(fname), hline_num) )
+ {
+ Error(36, 11, "hyphenation file %s%s is too large (at line %d)",
+ WARN, &fpos(fname), string(fname), HYPH_SUFFIX, hline_num);
+ *success = FALSE;
+ return (TRIE) NULL;
+ }
+ }
+ break;
+
+
+ case LENGTH_LIMIT_STATE:
+
+ if( StringEqual(str, AsciiToFull("Patterns:")) )
+ { state = PATTERNS_STATE;
+ }
+ else if( sscanf( (char *) str, "%d", &length_limit) != 1 )
+ {
+ Error(36, 20, "bad LengthLimit in hyphenation file %s%s (line %d)",
+ WARN, &fpos(fname), string(fname), HYPH_SUFFIX, hline_num);
+ *success = FALSE;
+ return (TRIE) NULL;
+ }
+ break;
+
+
+ case PATTERNS_STATE:
+
+ prev = CH_ZERO; j = 0;
+ for( i = 0; str[i] != '\0'; i++ )
+ { if( decimaldigit(str[i]) ) prev = str[i];
+ else key[j] = str[i], value[j++] = prev, prev = CH_ZERO;
+ }
+ key[j] = '\0'; value[j] = prev; value[j+1] = '\0';
+ if( length_limit == 0 || j <= length_limit )
+ {
+ debug3(DHY, DD, "TrieInsert(%s, %s, T) [%d]", key, value, ++icount);
+ if( !TrieInsert(key, value, T, string(fname), hline_num) )
+ {
+ Error(36, 12, "hyphenation file %s%s is too large (at line %d)",
+ WARN, &fpos(fname), string(fname), HYPH_SUFFIX, hline_num);
+ *success = FALSE;
+ return (TRIE) NULL;
+ }
+ }
+ break;
+
+
+ default:
+
+ assert(FALSE, "TrieRead: state");
+ break;
+
+ } /* end switch */
+ } /* end while */
+ } /* end while */
+
+ if( state != PATTERNS_STATE )
+ Error(36, 13, "format error in hyphenation file %s",
+ FATAL, no_fpos, FileName(unpacked_fnum));
+ fclose(unpacked_fp);
+ CompressTrie(T);
+
+ /* write the compressed trie out to the packed file */
+ /* cannot use FileName(packed_fnum) because path won't be right */
+ StringCopy(buff, FileName(unpacked_fnum));
+ StringCopy(&buff[StringLength(buff) - StringLength(HYPH_SUFFIX)],
+ HYPH_PACKED_SUFFIX);
+ packed_fp = StringFOpen(buff, WRITE_BINARY);
+ if( packed_fp == NULL )
+ Error(36, 14, "cannot write to hyphenation file %s", FATAL,no_fpos,buff);
+ BePutInt(packed_fp, T->magic);
+ BePutInt(packed_fp, T->class_count);
+ for( i = 0; i < MAX_CHAR; i++ ) BePutChar(packed_fp, T->class[i]);
+ /* BePutInt(packed_fp, 0); */ /* placeholder for node_mem now omitted */
+ BePutInt(packed_fp, T->node_lim);
+ BePutInt(packed_fp, T->node_free);
+ /* BePutInt(packed_fp, 0); */ /* placeholder for string_mem now omitted */
+ BePutInt(packed_fp, T->string_lim);
+ BePutInt(packed_fp, T->string_first);
+ for( i=0; i < T->node_free; i++ ) BePutShort(packed_fp, T->node_mem[i]);
+ for( i=0; i < T->string_lim; i++) BePutChar(packed_fp, T->string_mem[i]);
+ fclose(packed_fp);
+
+ /* free T */
+ ifdebug(DMA, DD, DebugRegisterUsage(MEM_HYPH_PATS, 1,
+ sizeof(struct trie_rec) + 120000*sizeof(short)+32767*sizeof(char)));
+ free(T);
+
+ /* now try again to open packed_fnum, the file just written */
+ packed_fp = OpenFile(packed_fnum, FALSE, FALSE);
+ if( packed_fp == NULL )
+ Error(36, 15, "cannot open hyphenation file %s",
+ FATAL, no_fpos, FileName(packed_fnum));
+ } /* end if( packed_fp == NULL ) */
+
+ /* now packed hyphenation file is open, read it in */
+ fseek(packed_fp, 0L, SEEK_END);
+ len = (unsigned) ftell(packed_fp); rewind(packed_fp);
+ ifdebug(DMA, DD, DebugRegisterUsage(MEM_HYPH_PATS, 1, len));
+ /* the 2*sizeof(void*) is for the sizes of node_mem and string_mem */
+ T = (TRIE) malloc(len + 2*sizeof(void*));
+ if( T == (TRIE) NULL )
+ Error(36, 16, "run out of memory while reading hyphenation table",
+ FATAL, no_fpos);
+ if( BeGetInt(packed_fp, &T->magic) != 0 )
+ Error(36, 17, "error on read from packed hyphenation file %s",
+ FATAL, no_fpos, FileName(packed_fnum));
+ if( T->magic != TRIE_MAGIC )
+ Error(36, 18, "bad magic number in hyphenation file %s",
+ FATAL, no_fpos, FileName(packed_fnum));
+ BeGetInt(packed_fp, &T->class_count);
+ for( i = 0; i < MAX_CHAR; i++ ) BeGetChar(packed_fp, &T->class[i]);
+ /* BeGetInt(packed_fp, &i); */ /* placeholder for node_mem now omitted */
+ BeGetInt(packed_fp, &T->node_lim);
+ BeGetInt(packed_fp, &T->node_free);
+ /* BeGetInt(packed_fp, &i); */ /* placeholder for string_mem now omitted */
+ BeGetInt(packed_fp, &T->string_lim);
+ BeGetInt(packed_fp, &T->string_first);
+ T->node_mem = (short *) ( (char *) T + sizeof(struct trie_rec) );
+ T->string_mem = (FULL_CHAR *) &(T->node_mem[T->node_lim]);
+ for( i = 0; i < T->node_free; i++ ) BeGetShort(packed_fp, &T->node_mem[i]);
+ for( i = 0; i < T->string_lim; i++ ) BeGetChar(packed_fp, &T->string_mem[i]);
+ fclose(packed_fp);
+
+ /* debug and exit */
+ debug0(DHY, DD, "TrieRead returning, T =");
+ *success = TRUE;
+ ifdebug(DHY, DD, TriePrint(T, stderr));
+ return T;
+ } /* end TrieRead */
+
+
+ /*****************************************************************************/
+ /* */
+ /* AccumulateRating(x, y) */
+ /* */
+ /* Accumulate the hyphenation rating string x into y. */
+ /* */
+ /*****************************************************************************/
+
+ #define AccumulateRating(x, y) \
+ { FULL_CHAR *p = x, *q = y; \
+ while( *p ) \
+ { if( *p > *q ) *q = *p; \
+ p++, q++; \
+ } \
+ } /* end AccumulateRating */
+
+
+ /*@::ReadHyphTable()@*********************************************************/
+ /* */
+ /* BOOLEAN ReadHyphTable(lnum) */
+ /* */
+ /* Read hyphenation table for language lnum. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN ReadHyphTable(LANGUAGE_NUM lnum)
+ { BOOLEAN res;
+ debug1(DHY, DD, "ReadHyphTable(%d)", lnum);
+ assert(lnum > 0, "ReadHyphTable: lnum <= 0!");
+ assert(HyphTables[lnum]==(TRIE) NULL && !TriedFile[lnum], "ReadHyphTable!");
+ HyphTables[lnum] = TrieRead(lnum, &res);
+ TriedFile[lnum] = TRUE;
+ debug2(DHY, DD, "ReadHyphTable(%d) returning %s", lnum, bool(res));
+ return res;
+ } /* end ReadHyphTable */
+
+
+ /*@::Hyphenate@***************************************************************/
+ /* */
+ /* OBJECT Hyphenate(x) */
+ /* */
+ /* Hyphenate ACAT object x, returning the hyphenated result. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT Hyphenate(OBJECT x)
+ { OBJECT link, y, z, next_link; TRIE T; LANGUAGE_NUM lnum;
+ FULL_CHAR str[MAX_WORD+2], rate[MAX_WORD+3], val[MAX_WORD+3],
+ *class, *key, *ss, *s, *p, *rem, *lig, *a, *b;
+ int start, stop, i, curr_node, next_node, pos;
+ BOOLEAN hyphenated, success;
+ assert( type(x) == ACAT, "Hyphenate: type(x) != ACAT!" );
+ debug1(DHY, D, "Hyphenate(%s)", EchoObject(x));
+
+ /* for each word y of x, try to hyphenate it */
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( !is_word(type(y)) || string(y)[0] == '\0' || !word_hyph(y) )
+ {
+ if( type(y) == GAP_OBJ && mode(gap(y)) == HYPH_MODE )
+ nobreak(gap(y)) = FALSE;
+ continue;
+ }
+ debug1(DHY, DD, "Hyphenate() examining %s", EchoObject(y));
+
+ /* determine T, the trie to use */
+ lnum = word_language(y);
+ if( lnum == 0 )
+ Error(36, 19, "no current language for word %s",
+ FATAL, &fpos(y), string(y));
+ T = HyphTables[lnum];
+
+ /* if no trie is present, try to get it from a file */
+ if( T == (TRIE) NULL )
+ { if( !TriedFile[lnum] )
+ { T = HyphTables[lnum] = TrieRead(lnum, &success);
+ TriedFile[lnum] = TRUE;
+ }
+ if( T == (TRIE) NULL )
+ { debug1(DHY, DD, "Hyphenate continuing (no trie for %s)", string(y));
+ continue;
+ }
+ }
+
+ /* start := index of first letter of y, stop := index following last */
+ key = string(y); class = T->class;
+ for( start = 0; class[key[start]] == PUNCT_CLASS; start++ );
+ for( stop = start; class[key[stop]] > PUNCT_CLASS; stop++ );
+
+ /* if a - ended the run, hyphenate there only */
+ if( key[stop] == CH_HYPHEN )
+ {
+ /* actually, don't hyphenate if the hyphen is last in the word [thanks Uwe] */
+ if( key[stop+1] == '\0' )
+ continue;
+
+ next_link = NextDown(link);
+ z = MakeWord(WORD, &key[stop+1], &fpos(y));
+ word_font(z) = word_font(y);
+ word_colour(z) = word_colour(y);
+ word_outline(z) = word_outline(y);
+ word_language(z) = word_language(y);
+ word_hyph(z) = word_hyph(y);
+ underline(z) = underline(y);
+ debug1(DHY, DD, "Hyphenate (hyph case) making fragment %s", string(z));
+ FontWordSize(z);
+ Link(NextDown(link), z);
+ New(z, GAP_OBJ);
+ hspace(z) = vspace(z) = 0;
+ SetGap(gap(z), FALSE, FALSE, TRUE, FIXED_UNIT, HYPH_MODE, 0);
+ underline(z) = underline(y);
+ Link(NextDown(link), z);
+ Link(z, MakeWord(WORD, STR_GAP_ZERO_HYPH, &fpos(y)));
+ key[stop + 1] = '\0';
+ FontWordSize(y);
+ /* *** link = PrevDown(next_link); */
+ link = NextDown(link);
+ continue;
+ }
+
+ /* do not hyphenate if less than 5 letters, or a kill char is nearby */
+ if( stop - start < 5 ) continue;
+ if( key[stop] != '\0' && class[key[stop]] == KILL_CLASS ) continue;
+
+ /* let str[] be the converted substring, let rate[] be all CH_ZERO */
+ str[0] = PUNCT_CLASS; rate[0] = CH_ZERO;
+ for( i = 0; i < stop - start; i++ )
+ { str[i+1] = class[key[start + i]];
+ rate[i+1] = CH_ZERO;
+ }
+ str[i+1] = PUNCT_CLASS; rate[i+1] = CH_ZERO;
+ str[i+2] = '\0'; rate[i+2] = CH_ZERO;
+ rate[i+3] = '\0';
+ ifdebug(DHY, DD, ShowRate(key, start, stop, rate, stderr));
+
+ /* for each suffix of str[], accumulate patterns matching its prefixes */
+ ss = str;
+ do
+ {
+ ifdebug(DHY, DD,
+ fprintf(stderr, "trying suffix \"");
+ for( p = ss; *p != 0; p++ ) fprintf(stderr, "%c", findrep(*p, T));
+ fprintf(stderr, "\"\n");
+ );
+
+ /* accumulate all prefixes of ss */
+ curr_node = 0; s = ss;
+ for(;;)
+ {
+ /* if curr_node has empty string, that is one prefix */
+ pos = T->node_mem[curr_node];
+ if( pos < 0 )
+ { AltUncompressValue(&(T->string_mem[- pos]), val);
+ AccumulateRating(val, rate+(ss-str));
+ debug1(DHY, DD, " found %s", val);
+ }
+
+ /* if ss is finished, no other prefixes are possible */
+ if( *s == '\0' ) break;
+
+ /* determine next_node and break if empty */
+ next_node = T->node_mem[curr_node + *s];
+ if( next_node == 0 ) break;
+
+ /* if next_node is a string, check whether it is a prefix of ss */
+ if( next_node < 0 )
+ { rem = &(T->string_mem[-next_node]);
+ do
+ { if( *rem == '\0' )
+ { AltUncompressValue(rem+1, val);
+ AccumulateRating(val, rate+(ss-str));
+ debug1(DHY, DD, " found %s", val);
+ break;
+ }
+ } while( *++s == *rem++ );
+ break;
+ }
+
+ /* otherwise go on to the next trie node */
+ curr_node = NODE_MULT*next_node; s++;
+ }
+ } while( *(++ss + 1) != PUNCT_CLASS );
+ ifdebug(DHY, DD, ShowRate(key, start, stop, rate, stderr));
+
+ /* set rate[i] to CH_ZERO whenever key[start+i-1] lies within a ligature */
+ lig = finfo[word_font(y)].lig_table;
+ for( p = key, i = 2; *p != '\0'; p++, i++ )
+ { if( lig[*p] > 1 )
+ { a = &lig[ lig[*p] + MAX_CHARS ];
+ while( *a++ == *p )
+ { b = p+1;
+ while( *a == *b && *(a+1) != '\0' && *b != '\0' ) a++, b++;
+ if( *(a+1) == '\0' )
+ { rate[i] = CH_ZERO;
+ break;
+ }
+ else
+ { while( *++a );
+ a++;
+ }
+ }
+ }
+ }
+ ifdebug(DHY, DD, ShowRate(key, start, stop, rate, stderr));
+
+ /* now rate[] has accumulated ratings; use it to perform hyphenations */
+ hyphenated = FALSE;
+ next_link = NextDown(link);
+ for( i = stop - start - 1; i >= 3; i-- )
+ {
+ /* hyphenate at i if rate[i] is odd */
+ if( is_odd(rate[i]) )
+ { z = MakeWord(WORD, &key[start+i-1], &fpos(y));
+ word_font(z) = word_font(y);
+ word_colour(z) = word_colour(y);
+ word_outline(z) = word_outline(y);
+ word_language(z) = word_language(y);
+ word_hyph(z) = word_hyph(y);
+ underline(z) = underline(y);
+ debug1(DHY, D, "Hyphenate making fragment %s", string(z));
+ FontWordSize(z);
+ Link(NextDown(link), z);
+ New(z, GAP_OBJ);
+ hspace(z) = vspace(z) = 0;
+ SetGap(gap(z), FALSE, FALSE, TRUE, FIXED_UNIT, HYPH_MODE, 0);
+ underline(z) = underline(y);
+ Link(NextDown(link), z);
+ Link(z, MakeWord(WORD, STR_GAP_ZERO_HYPH, &fpos(y)));
+ key[start + i - 1] = '\0';
+ hyphenated = TRUE;
+ }
+ }
+ if( hyphenated )
+ { FontWordSize(y);
+ link = PrevDown(next_link);
+ }
+
+ } /* end for each word */
+
+ debug3(DHY, D, "Hyphenate returning %s,%s %s",
+ EchoLength(back(x, COLM)), EchoLength(fwd(x, COLM)), EchoObject(x));
+ return x;
+ } /* end Hyphenate */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z37.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z37.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z37.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1873 ----
+ /*@z37.c:Font Service:Declarations@*******************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z37.c */
+ /* MODULE: Font Service */
+ /* EXTERNS: FontInit(), FontDefine(), FontChange(), FontWordSize(), */
+ /* FontSize(), FontHalfXHeight(), FontEncoding(), */
+ /* FontMapping(), FontFamilyAndFace(), FontNeeded() */
+ /* */
+ /* This module implements fonts, using encoding vectors and Adobe font */
+ /* metrics files (.AFM files, version 2). */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define DEFAULT_XHEIGHT 500 /* the default XHeight if font has none */
+ #define NO_FONT 0 /* the not-a-font font number */
+ #define SZ_DFT 1000 /* default lout size is 50p */
+ #define INIT_FINFO_SIZE 100 /* initial number of sized fonts set aside */
+
+ /*****************************************************************************/
+ /* */
+ /* These definitions have been moved to "externs.h" since z24.c needs them: */
+ /* */
+ /* struct metrics { */
+ /* SHORT_LENGTH up; */
+ /* SHORT_LENGTH down; */
+ /* SHORT_LENGTH left; */
+ /* SHORT_LENGTH right; */
+ /* SHORT_LENGTH last_adjust; */
+ /* }; */
+ /* */
+ /* typedef struc composite_rec { */
+ /* FULL_CHAR char_code; */
+ /* SHORT_LENGTH x_offset; */
+ /* SHORT_LENGTH y_offset; */
+ /* } COMPOSITE; */
+ /* */
+ /* typedef struct font_rec { */
+ /* struct metrics *size_table; metrics of sized fonts */
+ /* FULL_CHAR *lig_table; ligatures */
+ /* unsigned short *composite; non-zero means composite */
+ /* COMPOSITE *cmp_table; composites to build */
+ /* int cmp_top; length of cmp_table */
+ /* OBJECT font_table; record of sized fonts */
+ /* OBJECT original_face; face object of font */
+ /* SHORT_LENGTH underline_pos; position of underline */
+ /* SHORT_LENGTH underline_thick; thickness of underline */
+ /* unsigned short *kern_table; first kerning chars */
+ /* FULL_CHAR *kern_chars; second kerning chars */
+ /* unsigned char *kern_value; points into kern_lengths */
+ /* SHORT_LENGTH *kern_sizes; sizes of kernings */
+ /* } FONT_INFO; */
+ /* */
+ /*****************************************************************************/
+
+ /*****************************************************************************/
+ /* */
+ /* Private data structures of this module */
+ /* */
+ /* +++++++++++++++++++++++++++ */
+ /* + + */
+ /* root -> + ACAT + */
+ /* + + */
+ /* + + */
+ /* +++++++++++++++++++++++++++ */
+ /* | font families... */
+ /* | */
+ /* +-----+-----------------------------------------------+ ... */
+ /* | | */
+ /* | | */
+ /* +++++++++++++++++++++++++++ */
+ /* + + */
+ /* family -> + WORD + */
+ /* + string (family name) + */
+ /* + + */
+ /* +++++++++++++++++++++++++++ */
+ /* | faces of this family... */
+ /* | */
+ /* +-----+-----------------------------------------------+ ... */
+ /* | | */
+ /* | | */
+ /* +++++++++++++++++++++++++++++++++ */
+ /* + + */
+ /* face -> + WORD + */
+ /* + string (face name) + */
+ /* + font_recoded + */
+ /* + font_mapping + */
+ /* + font_page + */
+ /* + + */
+ /* +++++++++++++++++++++++++++++++++ */
+ /* | size records... */
+ /* | */
+ /* +----------+---------+--------------------+-----------------------+ */
+ /* | | | | */
+ /* | | | | */
+ /* +++++++++++++++++++ +++++++++++++++++++ +++++++++++++++++++++ */
+ /* + + + + + + */
+ /* + WORD + + WORD + + WORD + */
+ /* + string (font + + string (AFM + + string (short + */
+ /* + name) + + file name) + + font name) + */
+ /* + + + + + font_num + */
+ /* +++++++++++++++++++ +++++++++++++++++++ + font_size + */
+ /* | + font_xheight2 + */
+ /* | + font_recoded + */
+ /* ++++++++++++++++++++ + font_mapping + */
+ /* + + + font_spacewidth + */
+ /* (optional) + WORD + + + */
+ /* + string (extra + +++++++++++++++++++++ */
+ /* + AFM file name) + */
+ /* + + */
+ /* ++++++++++++++++++++ */
+ /* */
+ /*****************************************************************************/
+
+ int font_curr_page; /* current page number */
+ FONT_INFO *finfo; /* all the font table info */
+ static int finfo_size; /* current finfo array size */
+ static OBJECT font_root; /* root of tree of fonts */
+ static OBJECT font_used; /* fonts used on this page */
+ static FONT_NUM font_count; /* number of sized fonts */
+ static int font_seqnum; /* unique number for a font */
+ static OBJECT FontDefSym; /* symtab entry for @FontDef */
+ static OBJECT fd_tag; /* @FontDef @Tag entry */
+ static OBJECT fd_family; /* @FontDef @Family entry */
+ static OBJECT fd_face; /* @FontDef @Face entry */
+ static OBJECT fd_name; /* @FontDef @Name entry */
+ static OBJECT fd_metrics; /* @FontDef @Metrics entry */
+ static OBJECT fd_extra_metrics; /* @FontDef @ExtraMetrics */
+ static OBJECT fd_mapping; /* @FontDef @Mapping entry */
+ static OBJECT fd_recode; /* @FontDef @Recode entry */
+
+
+ /*@::FontInit(), FontDebug()@*************************************************/
+ /* */
+ /* FontInit() */
+ /* */
+ /* Initialise this module. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT load(FULL_CHAR *name, unsigned dtype, OBJECT encl, BOOLEAN compulsory)
+ { OBJECT res;
+ res = InsertSym(name, dtype, no_fpos, DEFAULT_PREC, FALSE, FALSE, 0, encl,
+ MakeWord(WORD, STR_EMPTY, no_fpos));
+ if( dtype == NPAR ) visible(res) = TRUE;
+ if( compulsory )
+ { has_compulsory(encl)++;
+ is_compulsory(res) = TRUE;
+ }
+ return res;
+ }
+
+ void FontInit(void)
+ {
+ debug0(DFT, D, "FontInit()");
+ font_curr_page = 1;
+ font_count = 0;
+ New(font_root, ACAT);
+ New(font_used, ACAT);
+ font_seqnum = 0;
+ finfo = (FONT_INFO *) malloc(INIT_FINFO_SIZE * sizeof(FONT_INFO));
+ finfo_size = INIT_FINFO_SIZE;
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_FONTS, 1, INIT_FINFO_SIZE * sizeof(FONT_INFO)));
+
+ /* set up FontDefSym */
+ FontDefSym = load(KW_FONTDEF, LOCAL, StartSym, FALSE);
+ fd_tag = load(KW_TAG, NPAR, FontDefSym, TRUE);
+ fd_family = load(KW_FAMILY, NPAR, FontDefSym, TRUE);
+ fd_face = load(KW_FACE, NPAR, FontDefSym, TRUE);
+ fd_name = load(KW_NAME, NPAR, FontDefSym, TRUE);
+ fd_metrics = load(KW_METRICS, NPAR, FontDefSym, TRUE);
+ fd_extra_metrics = load(KW_EXTRA_METRICS, NPAR, FontDefSym, FALSE);
+ fd_mapping = load(KW_MAPPING, NPAR, FontDefSym, TRUE);
+ fd_recode = load(KW_RECODE, NPAR, FontDefSym, FALSE);
+
+ debug0(DFT, D, "FontInit returning.");
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* FontDebug() */
+ /* */
+ /* Print out font tree (not currectly used). */
+ /* */
+ /*****************************************************************************/
+
+ #if DEBUG_ON
+ static void FontDebug(void)
+ { OBJECT family, face, link, flink, zlink, z; int i;
+ assert(font_root!=nilobj && type(font_root)==ACAT, "FontDebug: font_root!");
+ for( link = Down(font_root); link != font_root; link = NextDown(link) )
+ { Child(family, link);
+ assert( is_word(type(family)), "FontDebug: family!" );
+ debug1(DFS, D, "family %s:", string(family));
+ for( flink = Down(family); flink != family; flink = NextDown(flink) )
+ { Child(face, flink);
+ assert( is_word(type(face)), "FontDebug: face!" );
+ debug1(DFS, D, " face %s:", string(face));
+ for( zlink = Down(face); zlink != face; zlink = NextDown(zlink) )
+ { Child(z, zlink);
+ if( is_word(type(z)) )
+ { debug2(DFS, D, " %s%s", string(z), Down(z) != z ? " child" : "");
+ }
+ else
+ { debug1(DFS, D, " %s", Image(type(z)));
+ }
+ }
+ }
+ }
+ for( i = 1; i <= font_count; i++ )
+ fprintf(stderr, " finfo[%d].font_table = %s\n", i,
+ EchoObject(finfo[i].font_table));
+ } /* end FontDebug */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DebugKernTable(fnum) */
+ /* */
+ /* Print debug output of kern table for font fnum. */
+ /* */
+ /*****************************************************************************/
+
+ static void DebugKernTable(FONT_NUM fnum)
+ { int i, j;
+ unsigned short *kt = finfo[fnum].kern_table;
+ FULL_CHAR *kc = finfo[fnum].kern_chars;
+ unsigned char *kv = finfo[fnum].kern_value;
+ SHORT_LENGTH *ks = finfo[fnum].kern_sizes;
+ debug1(DFT, DD, "DebugKernTable(%d)", fnum);
+ for( i = 0; i < MAX_CHARS; i++ )
+ { if( kt[i] != 0 )
+ { debug1(DFT, DD, "kt[%d]:", i);
+ for( j = kt[i]; kc[j] != '\0'; j++ )
+ { debug3(DFT, DD, "KPX %c %c %d", i, kc[j], ks[kv[j]]);
+ }
+ }
+ }
+ debug1(DFT, DD, "DebugKernTable(%d) returning", fnum);
+ } /* DebugKernTable */
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* ReadCharMetrics(face, fixed_pitch, xheight2,lig,ligtop,fnum,fnt,lnum,fp) */
+ /* */
+ /* Read a sequence of character metrics lines. The font record is */
+ /* face, its ligatures are lig[0..ligtop], font number fnum, metrics fnt. */
+ /* The line number is lnum; input is to be read from file fp. */
+ /* */
+ /*****************************************************************************/
+
+ static void ReadCharMetrics(OBJECT face, BOOLEAN fixed_pitch, int xheight2,
+ FULL_CHAR *lig, int *ligtop, FILE_NUM fnum, struct metrics *fnt,
+ int *lnum, FILE *fp)
+ { FULL_CHAR buff[MAX_BUFF], command[MAX_BUFF], ch, ligchar;
+ int i, wx, llx, lly, urx, ury;
+ float fl_wx, fl_llx, fl_lly, fl_urx, fl_ury;
+ BOOLEAN wxfound, bfound;
+ OBJECT AFMfilename;
+
+ Child(AFMfilename, NextDown(Down(face)));
+ while( StringFGets(buff, MAX_BUFF, fp) != NULL &&
+ !StringBeginsWith(buff, AsciiToFull("EndCharMetrics")) &&
+ !StringBeginsWith(buff, AsciiToFull("EndExtraCharMetrics")) )
+ {
+ /* read one line containing metric info for one character */
+ debug1(DFT, DD, " ReadCharMetrics: %s", buff);
+ (*lnum)++; ch = '\0';
+ wxfound = bfound = FALSE;
+ i = 0; while( buff[i] == ' ' ) i++;
+ while( buff[i] != '\n' )
+ {
+ debug2(DFT, DDD, " ch = %d, &buff[i] = %s", ch, &buff[i]);
+ sscanf( (char *) &buff[i], "%s", command);
+ if( StringEqual(command, "N") )
+ { sscanf( (char *) &buff[i], "N %s", command);
+ ch = MapCharEncoding(command, font_mapping(face));
+ }
+ else if( StringEqual(command, "WX") )
+ { sscanf( (char *) &buff[i], "WX %f", &fl_wx);
+ wx = fl_wx;
+ wxfound = TRUE;
+ }
+ else if( StringEqual(command, "B") )
+ { sscanf( (char *) &buff[i], "B %f %f %f %f",
+ &fl_llx, &fl_lly, &fl_urx, &fl_ury);
+ llx = fl_llx;
+ lly = fl_lly;
+ urx = fl_urx;
+ ury = fl_ury;
+ bfound = TRUE;
+ }
+ else if( StringEqual(command, "L") &&
+ BackEnd->uses_font_metrics && ch != '\0' )
+ { if( lig[ch] == 1 ) lig[ch] = (*ligtop) - MAX_CHARS;
+ lig[(*ligtop)++] = ch;
+ i++; /* skip L */
+ while( buff[i] == ' ' ) i++;
+ while( buff[i] != ';' && buff[i] != '\n' )
+ { sscanf( (char *) &buff[i], "%s", command);
+ ligchar = MapCharEncoding(command, font_mapping(face));
+ if( ligchar != '\0' ) lig[(*ligtop)++] = ligchar;
+ else
+ { Error(37, 1, "ignoring unencoded ligature character %s in font file %s (line %d)",
+ WARN, &fpos(AFMfilename), command, FileName(fnum), *lnum);
+ lig[ch] = 1;
+ }
+ if( *ligtop > 2*MAX_CHARS - 5 )
+ Error(37, 2, "too many ligature characters in font file %s (line %d)",
+ FATAL, &fpos(AFMfilename), FileName(fnum), *lnum);
+ while( buff[i] != ' ' && buff[i] != ';' ) i++;
+ while( buff[i] == ' ' ) i++;
+ }
+ lig[(*ligtop)++] = '\0';
+ }
+ while( buff[i] != ';' && buff[i] != '\n' ) i++;
+ if( buff[i] == ';' )
+ { i++; while( buff[i] == ' ' ) i++;
+ }
+ }
+ if( ch > '\0' )
+ {
+ if( !wxfound )
+ { Error(37, 3, "WX missing in font file %s (line %d)",
+ FATAL, &fpos(AFMfilename), FileName(fnum), *lnum);
+ }
+ if( !bfound )
+ { Error(37, 4, "B missing in font file %s (line %d)",
+ FATAL, &fpos(AFMfilename), FileName(fnum), *lnum);
+ }
+ if( lig[ch] == 1 ) lig[ch] = 0; /* set to known if unknown */
+ else if( lig[ch] > 1 ) /* add '\0' to end of ligs */
+ lig[(*ligtop)++] = '\0';
+ if( BackEnd->uses_font_metrics )
+ {
+ fnt[ch].left = llx;
+ fnt[ch].down = lly - xheight2;
+ fnt[ch].right = wx;
+ fnt[ch].up = ury - xheight2;
+ fnt[ch].last_adjust = (urx==0 || wx==0 || fixed_pitch) ? 0 : urx - wx;
+ }
+ else
+ {
+ fnt[ch].left = 0;
+ fnt[ch].down = - PlainCharHeight / 2;
+ fnt[ch].right = PlainCharWidth;
+ fnt[ch].up = PlainCharHeight / 2;
+ fnt[ch].last_adjust = 0;
+ }
+ debug6(DFT, DDD, " fnt[%c] = (%d,%d,%d,%d,%d)",ch, fnt[ch].left,
+ fnt[ch].down, fnt[ch].right, fnt[ch].up, fnt[ch].last_adjust);
+ }
+ }
+ } /* end ReadCharMetrics */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ReadCompositeMetrics(face, Extrafilename, extra_fnum, lnum, composite, */
+ /* cmp, cmptop, fp) */
+ /* */
+ /* Read a sequence of composite metrics lines. The font record is face. */
+ /* The line number is lnum; input is to be read from file fp. */
+ /* */
+ /*****************************************************************************/
+
+ static void ReadCompositeMetrics(OBJECT face, OBJECT Extrafilename,
+ FILE_NUM extra_fnum, int *lnum, unsigned short composite[],
+ COMPOSITE cmp[], int *cmptop, FILE *fp)
+ { char *status;
+ FULL_CHAR buff[MAX_BUFF], composite_name[100], name[100];
+ int composite_num, x_offset, y_offset, i, count;
+ FULL_CHAR composite_code, code;
+
+ /* build composites */
+ while( (status = StringFGets(buff, MAX_BUFF, fp)) != (char *) NULL
+ && StringBeginsWith(buff, AsciiToFull("CC")) )
+ {
+ (*lnum)++;
+ debug1(DFT, D, " composite: %s", buff);
+
+ /* read CC <charname> <number_of_pieces> ; and move i to after it */
+ if( sscanf((char *)buff, "CC %s %d ", composite_name, &composite_num) != 2 )
+ Error(37, 5, "syntax error in extra font file %s (line %d)",
+ FATAL, &fpos(Extrafilename), FileName(extra_fnum), *lnum);
+ for( i = 0; buff[i] != ';' && buff[i] != '\n' && buff[i] != '\0'; i++ );
+ if( buff[i] != ';' )
+ Error(37, 5, "syntax error in extra font file %s (line %d)",
+ FATAL, &fpos(Extrafilename), FileName(extra_fnum), *lnum);
+ i++;
+
+ /* add entry for this character to composite */
+ composite_code = MapCharEncoding(composite_name,font_mapping(face));
+ if( composite_code == (FULL_CHAR) '\0' )
+ Error(37, 6, "unknown character name %s in font file %s (line %d)",
+ FATAL, &fpos(Extrafilename), FileName(extra_fnum), *lnum);
+ composite[composite_code] = *cmptop;
+
+ for( count = 0; count < composite_num; count++ )
+ {
+ /* read one PCC <charname> <xoffset> <yoffset> ; and move i to after it */
+ if( sscanf((char *)&buff[i]," PCC %s %d %d",name,&x_offset,&y_offset)!=3 )
+ Error(37, 5, "syntax error in extra font file %s (line %d)",
+ FATAL, &fpos(Extrafilename), FileName(extra_fnum), *lnum);
+ for( ; buff[i] != ';' && buff[i] != '\n' && buff[i] != '\0'; i++ );
+ if( buff[i] != ';' )
+ Error(37, 5, "syntax error in extra font file %s (line %d)",
+ FATAL, &fpos(Extrafilename), FileName(extra_fnum), *lnum);
+ i++;
+
+ /* load this piece into cmp */
+ if( *cmptop >= MAX_CHARS )
+ Error(37, 7, "too many composites in file %s (at line %d)",
+ FATAL, &fpos(Extrafilename), FileName(extra_fnum), *lnum);
+ code = MapCharEncoding(name, font_mapping(face));
+ cmp[*cmptop].char_code = code;
+ cmp[*cmptop].x_offset = x_offset;
+ cmp[*cmptop].y_offset = y_offset;
+ (*cmptop)++;
+ }
+
+ /* add null terminating component */
+ if( *cmptop >= MAX_CHARS )
+ Error(37, 8, "too many composites in file %s (at line %d)",
+ FATAL, &fpos(Extrafilename), FileName(extra_fnum), *lnum);
+ cmp[*cmptop].char_code = (FULL_CHAR) '\0';
+ (*cmptop)++;
+ }
+ if( status == (char *) NULL ||
+ !StringBeginsWith(buff, AsciiToFull("EndBuildComposites")) )
+ Error(37, 9, "missing EndBuildComposites in extra font file %s (line %d)",
+ FATAL, &fpos(Extrafilename), FileName(extra_fnum), *lnum);
+ } /* end ReadCompositeMetrics */
+
+
+ /*@::FontRead()@**************************************************************/
+ /* */
+ /* static OBJECT FontRead(FULL_CHAR *family_name, *face_name, OBJECT err) */
+ /* */
+ /* Search the font databases for a font with this family and face name. */
+ /* If found, read the font and update this module's data structures, then */
+ /* return the face object. */
+ /* */
+ /* If an error occurs, use fpos(err) for reporting its location if nothing */
+ /* better suggests itself. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT FontRead(FULL_CHAR *family_name, FULL_CHAR *face_name, OBJECT err)
+ {
+ OBJECT cs, link, db, fontdef_obj, y, ylink;
+ FULL_CHAR tag[100], seq[100];
+ FILE_NUM dfnum; long dfpos, cont; int dlnum;
+ BOOLEAN font_name_found;
+ OBJECT family, face, font_name, AFMfilename, Extrafilename, LCMfilename;
+ OBJECT recode, first_size;
+ FULL_CHAR buff[MAX_BUFF], command[MAX_BUFF], ch;
+ char *status;
+ int xheight2, i, lnum, ligtop, cmptop;
+ float fl_xheight2, fl_under_pos, fl_under_thick;
+ int under_pos, under_thick;
+ BOOLEAN upfound, utfound, xhfound;
+ BOOLEAN fixed_pitch = FALSE;
+ FILE_NUM fnum, extra_fnum; FILE *fp, *extra_fp;
+ struct metrics *fnt;
+ FULL_CHAR *lig; unsigned short *composite; COMPOSITE *cmp;
+ unsigned short *kt; FULL_CHAR *kc; unsigned char *kv; SHORT_LENGTH *ks;
+ debug2(DFT, D, "FontRead(%s, %s)", family_name, face_name);
+
+
+ /***************************************************************************/
+ /* */
+ /* Get the @FontDef object with tag family_name-face_name from databases */
+ /* */
+ /***************************************************************************/
+
+ /* if no databases available, fatal error */
+ cs = cross_sym(FontDefSym);
+ if( cs == nilobj )
+ { Error(37, 10, "unable to set font %s %s (no font databases loaded)",
+ FATAL, no_fpos, family_name, face_name);
+ }
+
+ /* search the databases for @FontDef @Tag { family-face } */
+ sprintf( (char *) tag, "%s-%s", family_name, face_name);
+ for( link = NextUp(Up(cs)); link != cs; link = NextUp(link) )
+ { Parent(db, link);
+ if( DbRetrieve(db, FALSE, FontDefSym,tag,seq,&dfnum,&dfpos,&dlnum,&cont) )
+ break;
+ }
+
+ /* if not found, return nilobj */
+ if( link == cs )
+ { debug0(DFT, D, "FontRead returning nilobj (not in any database)");
+ return nilobj;
+ }
+
+ /* found it; read @FontDef object from database file */
+ SwitchScope(nilobj);
+ fontdef_obj = ReadFromFile(dfnum, dfpos, dlnum);
+ UnSwitchScope(nilobj);
+ if( fontdef_obj == nilobj )
+ Error(37, 11, "cannot read %s for %s", INTERN, no_fpos, KW_FONTDEF, tag);
+
+
+ /***************************************************************************/
+ /* */
+ /* Extract the attributes of fontdef_obj, and check that they are OK. */
+ /* */
+ /***************************************************************************/
+
+ /* extract the various attributes */
+ family = face = font_name = AFMfilename = nilobj;
+ Extrafilename = LCMfilename = recode = nilobj;
+ for( ylink=Down(fontdef_obj); ylink != fontdef_obj; ylink=NextDown(ylink) )
+ { Child(y, ylink);
+ assert( type(y) == PAR, "FontRead: type(y) != PAR!" );
+ if( actual(y) == fd_tag )
+ {
+ /* do nothing with this one */
+ }
+ else if( actual(y) == fd_family )
+ { Child(family, Down(y));
+ if( !is_word(type(family)) || !StringEqual(string(family), family_name) )
+ Error(37, 12, "font family name %s incompatible with %s value %s",
+ FATAL, &fpos(fontdef_obj), string(family), KW_TAG, tag);
+ }
+ else if( actual(y) == fd_face )
+ { Child(face, Down(y));
+ if( !is_word(type(face)) || !StringEqual(string(face), face_name) )
+ Error(37, 13, "font face name %s incompatible with %s value %s",
+ FATAL, &fpos(fontdef_obj), string(face), KW_TAG, tag);
+ }
+ else if( actual(y) == fd_name )
+ { Child(font_name, Down(y));
+ font_name = ReplaceWithTidy(font_name, TRUE);
+ if( !is_word(type(font_name)) )
+ Error(37, 14, "illegal font name (quotes needed?)",
+ FATAL, &fpos(font_name));
+ }
+ else if( actual(y) == fd_metrics )
+ { Child(AFMfilename, Down(y));
+ AFMfilename = ReplaceWithTidy(AFMfilename, TRUE);
+ if( !is_word(type(AFMfilename)) )
+ Error(37, 15, "illegal font metrics file name (quotes needed?)",
+ FATAL, &fpos(AFMfilename));
+ }
+ else if( actual(y) == fd_extra_metrics )
+ { Child(Extrafilename, Down(y));
+ Extrafilename = ReplaceWithTidy(Extrafilename, TRUE);
+ if( !is_word(type(Extrafilename)) )
+ Error(37, 16, "illegal font extra metrics file name (quotes needed?)",
+ FATAL, &fpos(Extrafilename));
+ }
+ else if( actual(y) == fd_mapping )
+ { Child(LCMfilename, Down(y));
+ LCMfilename = ReplaceWithTidy(LCMfilename, TRUE);
+ if( !is_word(type(LCMfilename)) )
+ Error(37, 17, "illegal mapping file name (quotes needed?)",
+ FATAL, &fpos(LCMfilename));
+ }
+ else if( actual(y) == fd_recode )
+ { Child(recode, Down(y));
+ recode = ReplaceWithTidy(recode, TRUE);
+ if( !is_word(type(recode)) )
+ Error(37, 18, "illegal value of %s", FATAL, &fpos(recode),
+ SymName(fd_recode));
+ }
+ else
+ { assert(FALSE, "FontRead: cannot identify component of FontDef")
+ }
+
+ }
+
+ /* check that all the compulsory ones were found */
+ /* a warning message will have already been given if not */
+ if( family == nilobj || face == nilobj || font_name == nilobj ||
+ AFMfilename == nilobj || LCMfilename == nilobj )
+ {
+ debug0(DFT, D, "FontRead returning nilobj (missing compulsory)");
+ return nilobj;
+ }
+
+
+ /***************************************************************************/
+ /* */
+ /* Update font tree to have this family, face and first_size. */
+ /* */
+ /***************************************************************************/
+
+ /* insert family into font tree if not already present */
+ for( link = Down(font_root); link != font_root; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(string(y), string(family)) )
+ { family = y;
+ break;
+ }
+ }
+ if( link == font_root )
+ MoveLink(Up(family), font_root, PARENT);
+
+ /* insert face into family, or error if already present */
+ for( link = Down(family); link != family; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(string(y), string(face)) )
+ { Error(37, 19, "font %s %s already defined, at%s", WARN, &fpos(face),
+ string(family), string(face), EchoFilePos(&fpos(y)));
+ debug0(DFT, D, "FontRead returning: font already defined");
+ DisposeObject(fontdef_obj);
+ return y;
+ }
+ }
+ MoveLink(Up(face), family, PARENT);
+
+ /* PostScript name and AFM file name are first two children of face */
+ Link(face, font_name);
+ Link(face, AFMfilename);
+
+ /* AFM file name has extra file name as optional child */
+ if( Extrafilename != nilobj )
+ Link(AFMfilename, Extrafilename);
+
+ /* load character mapping file */
+ if( recode != nilobj && StringEqual(string(recode), AsciiToFull("No")) )
+ { font_recoded(face) = FALSE;
+ font_mapping(face) = MapLoad(LCMfilename, FALSE);
+ }
+ else if( recode == nilobj || StringEqual(string(recode), AsciiToFull("Yes")) )
+ { font_recoded(face) = TRUE;
+ font_mapping(face) = MapLoad(LCMfilename, TRUE);
+ }
+ else Error(37, 20, "expecting either Yes or No here", FATAL, &fpos(recode));
+
+ /* say that this font is currently unused on any page */
+ font_page(face) = 0;
+
+ /* get a new number for this (default) font size */
+ if( ++font_count >= finfo_size )
+ { if( font_count > MAX_FONT )
+ Error(37, 21, "too many different fonts and sizes (maximum is %d)",
+ FATAL, &fpos(err),MAX_FONT);
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_FONTS, -1, -finfo_size * sizeof(FONT_INFO)));
+ finfo_size *= 2;
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_FONTS, 1, finfo_size * sizeof(FONT_INFO)));
+ finfo = (FONT_INFO *) realloc(finfo, finfo_size * sizeof(FONT_INFO));
+ if( finfo == (FONT_INFO *) NULL )
+ Error(37, 22, "run out of memory when increasing font table size",
+ FATAL, &fpos(err));
+ }
+
+ /* build the first size record, and initialize it with what we know now */
+ first_size = MakeWordTwo(WORD, AsciiToFull("fnt"), StringInt(++font_seqnum),
+ no_fpos);
+ Link(face, first_size);
+ font_num(first_size) = font_count;
+ font_size(first_size) = BackEnd->uses_font_metrics ? SZ_DFT : PlainCharHeight;
+ font_recoded(first_size) = font_recoded(face);
+ font_mapping(first_size) = font_mapping(face);
+ font_num(face) = font_num(first_size); /* Uwe's suggestion, helps PDF */
+ /* leaves font_xheight2 and font_spacewidth still to do */
+
+
+ /***************************************************************************/
+ /* */
+ /* Read the Adobe font metrics file, and record what's in it. */
+ /* */
+ /***************************************************************************/
+
+ /* open the Adobe font metrics (AFM) file of the font */
+ debug0(DFS, D, " calling DefineFile from FontRead");
+ fnum = DefineFile(string(AFMfilename), STR_EMPTY, &fpos(AFMfilename),
+ FONT_FILE, FONT_PATH);
+ fp = OpenFile(fnum, FALSE, FALSE);
+ if( fp == NULL )
+ Error(37, 23, "cannot open font file %s", FATAL, &fpos(AFMfilename),
+ FileName(fnum));
+
+ /* check that the AFM file begins, as it should, with "StartFontMetrics" */
+ if( StringFGets(buff, MAX_BUFF, fp) == NULL ||
+ sscanf( (char *) buff, "%s", command) != 1 ||
+ !StringEqual(command, "StartFontMetrics") )
+ { debug1(DFT, DD, "first line of AFM file:%s", buff);
+ debug1(DFT, DD, "command:%s", command);
+ Error(37, 24, "font file %s does not begin with StartFontMetrics",
+ FATAL, &fpos(AFMfilename), FileName(fnum));
+ }
+
+ /* initialise font metrics table for the new font */
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_FONTS, 1, MAX_CHARS * sizeof(struct metrics)));
+ fnt = (struct metrics *) malloc(MAX_CHARS * sizeof(struct metrics));
+ if( fnt == (struct metrics *) NULL )
+ Error(37, 25, "run out of memory while reading font file %s",
+ FATAL, &fpos(err), FileName(fnum));
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_FONTS, 0, 2*MAX_CHARS*sizeof(FULL_CHAR)));
+
+ /* initialise ligature table for the new font */
+ lig = (FULL_CHAR *) malloc(2*MAX_CHARS*sizeof(FULL_CHAR));
+ if( lig == (FULL_CHAR *) NULL )
+ Error(37, 25, "run out of memory while reading font file %s",
+ FATAL, &fpos(err), FileName(fnum));
+ for( i = 0; i < MAX_CHARS; i++ ) lig[i] = 1; /* i.e. char unknown */
+ ligtop = MAX_CHARS+2; /* must avoid ligtop - MAX_CHARS == 0 or 1 */
+
+ /* initialise composites table for the new font */
+ composite = (unsigned short *) malloc(MAX_CHARS * sizeof(unsigned short));
+ if( composite == (unsigned short *) NULL )
+ Error(37, 25, "run out of memory while reading font file %s",
+ FATAL, &fpos(err), FileName(fnum));
+ cmp = (COMPOSITE *) malloc(MAX_CHARS * sizeof(COMPOSITE));
+ if( cmp == (COMPOSITE *) NULL )
+ Error(37, 25, "run out of memory while reading font file %s",
+ FATAL, &fpos(err), FileName(fnum));
+ for( i = 0; i < MAX_CHARS; i++ ) composite[i] = 0; /* i.e. not composite */
+ cmptop = 1; /* must avoid cmptop == 0 */
+
+ /* initialise kerning table for the new font */
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_FONTS, 0, MAX_CHARS * sizeof(unsigned short)));
+ kt = (unsigned short *) malloc(MAX_CHARS * sizeof(unsigned short));
+ if( kt == (unsigned short *) NULL )
+ Error(37, 25, "run out of memory while reading font file %s",
+ FATAL, &fpos(err), FileName(fnum));
+ for( i = 0; i < MAX_CHARS; i++ ) kt[i] = 0; /* i.e. no kerns */
+ ks = (SHORT_LENGTH *) NULL; /* i.e. no kern sizes */
+
+ /* read font metrics file fp */
+ xhfound = upfound = utfound = FALSE;
+ xheight2 = under_thick = under_pos = 0;
+ kc = (FULL_CHAR *) NULL;
+ kv = (unsigned char *) NULL;
+ ks = (SHORT_LENGTH *) NULL;
+ font_name_found = FALSE; lnum = 1;
+ while( (status = StringFGets(buff, MAX_BUFF, fp)) != (char *) NULL &&
+ !(buff[0] == 'E' && StringEqual(buff, AsciiToFull("EndFontMetrics\n"))) )
+ {
+ lnum++;
+ sscanf( (char *) buff, "%s", command);
+ switch( command[0] )
+ {
+
+ case 'U':
+
+ if( StringEqual(command, AsciiToFull("UnderlinePosition")) )
+ { if( upfound )
+ { Error(37, 26, "UnderlinePosition found twice in font file (line %d)",
+ FATAL, &fpos(AFMfilename), lnum);
+ }
+ sscanf( (char *) buff, "UnderlinePosition %f", &fl_under_pos);
+ under_pos = fl_under_pos;
+ upfound = TRUE;
+ }
+ else if( StringEqual(command, AsciiToFull("UnderlineThickness")) )
+ { if( utfound )
+ { Error(37, 27, "UnderlineThickness found twice in font file (line %d)",
+ FATAL, &fpos(AFMfilename), lnum);
+ }
+ sscanf( (char *) buff, "UnderlineThickness %f", &fl_under_thick);
+ under_thick = fl_under_thick;
+ utfound = TRUE;
+ }
+ break;
+
+
+ case 'X':
+
+ if( StringEqual(command, AsciiToFull("XHeight")) )
+ { if( xhfound )
+ { Error(37, 28, "XHeight found twice in font file (line %d)",
+ FATAL, &fpos(AFMfilename), lnum);
+ }
+ sscanf( (char *) buff, "XHeight %f", &fl_xheight2);
+ xheight2 = fl_xheight2 / 2;
+ xhfound = TRUE;
+ }
+ break;
+
+
+ case 'F':
+
+ if( StringEqual(command, AsciiToFull("FontName")) )
+ { if( font_name_found )
+ { Error(37, 29, "FontName found twice in font file %s (line %d)",
+ FATAL, &fpos(AFMfilename), FileName(fnum), lnum);
+ }
+ sscanf( (char *) buff, "FontName %s", command);
+ if( StringEqual(command, STR_EMPTY) )
+ { Error(37, 30, "FontName empty in font file %s (line %d)",
+ FATAL, &fpos(AFMfilename), FileName(fnum), lnum);
+ }
+ Child(y, Down(face));
+ if( !StringEqual(command, string(y)) )
+ Error(37, 31, "FontName in font file (%s) and %s (%s) disagree",
+ WARN, &fpos(AFMfilename), command, KW_FONTDEF, string(y));
+ font_name_found = TRUE;
+ }
+ break;
+
+
+ case 'I':
+
+ if( StringEqual(command, AsciiToFull("IsFixedPitch")) )
+ {
+ sscanf( (char *) buff, "IsFixedPitch %s", command);
+ if( StringEqual(command, AsciiToFull("true")) )
+ { fixed_pitch = TRUE;
+ }
+ }
+ break;
+
+
+ case 'S':
+
+ if( StringEqual(command, AsciiToFull("StartCharMetrics")) )
+ {
+ if( !font_name_found )
+ Error(37, 32, "FontName missing in file %s",
+ FATAL, &fpos(AFMfilename), FileName(fnum));
+ if( !xhfound ) xheight2 = DEFAULT_XHEIGHT / 2;
+ ReadCharMetrics(face, fixed_pitch, xheight2, lig, &ligtop,
+ fnum, fnt, &lnum, fp);
+ }
+ else if( BackEnd->uses_font_metrics && Kern &&
+ StringEqual(command, AsciiToFull("StartKernPairs")) )
+ { FULL_CHAR ch1, ch2, last_ch1;
+ FULL_CHAR name1[30], name2[30];
+ int kc_top, ks_top, pos, num_pairs, ksize; float fl_ksize;
+
+ if( sscanf( (char *) buff, "StartKernPairs %d", &num_pairs) != 1 )
+ Error(37, 33, "syntax error on StartKernPairs line in font file %s (line %d)",
+ FATAL, &fpos(AFMfilename), FileName(fnum), lnum);
+ kc_top = 1; ks_top = 1;
+ ifdebug(DMA, D,
+ DebugRegisterUsage(MEM_FONTS, 0, 2*num_pairs * sizeof(FULL_CHAR)));
+ kc = (FULL_CHAR *) malloc(2 * num_pairs * sizeof(FULL_CHAR));
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_FONTS, 0,
+ 2 * num_pairs * sizeof(unsigned char)));
+ kv = (unsigned char *) malloc(2 * num_pairs * sizeof(unsigned char));
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_FONTS, 0,
+ num_pairs * sizeof(SHORT_LENGTH)));
+ ks = (SHORT_LENGTH *) malloc(num_pairs * sizeof(SHORT_LENGTH));
+ last_ch1 = '\0';
+ while( StringFGets(buff, MAX_BUFF, fp) == (char *) buff &&
+ !StringBeginsWith(buff, AsciiToFull("EndKernPairs")) )
+ {
+ debug1(DFT, DD, "FontRead reading %s", buff);
+ lnum++;
+ if( StringBeginsWith(buff, AsciiToFull("KPX")) )
+ {
+ /* get the two character names and kern size from buff */
+ if( sscanf((char *)buff, "KPX %s %s %f",name1,name2,&fl_ksize)!=3 )
+ Error(37, 34, "syntax error in font file %s (line %d): %s",
+ FATAL, &fpos(AFMfilename), FileName(fnum), lnum, buff);
+
+ /* ignore size 0 kern pairs (they are frequent, why?) */
+ ksize = fl_ksize;
+ if( ksize == 0 ) continue;
+
+ /* check that both characters are encoded */
+ ch1 = MapCharEncoding(name1, font_mapping(face));
+ if( ch1 == '\0' )
+ {
+ continue;
+ }
+ ch2 = MapCharEncoding(name2, font_mapping(face));
+ if( ch2 == '\0' )
+ {
+ continue;
+ }
+
+ /* check that ch1 is contiguous with previous occurrences */
+ if( ch1 != last_ch1 && kt[ch1] != 0 )
+ { Error(37, 35, "non-contiguous kerning pair %s %s in font file %s (line %d)",
+ WARN, &fpos(AFMfilename), name1, name2, FileName(fnum), lnum);
+ continue;
+ }
+ last_ch1 = ch1;
+
+ /* if ch1 never seen before, make new entry in kt[] and kc[] */
+ if( kt[ch1] == 0 )
+ { debug2(DFT, DD, " kt[%d] = %d", ch1, kc_top);
+ kt[ch1] = kc_top;
+ kc[kc_top] = (FULL_CHAR) '\0';
+ kv[kc_top] = 0;
+ kc_top++;
+ }
+
+ /* find kerning size in ks[] or else add it to the end */
+ for( pos = 1; pos < ks_top; pos++ )
+ { if( ks[pos] == ksize ) break;
+ }
+ if( pos == ks_top )
+ { if( ks_top == num_pairs )
+ Error(37, 36, "too many kerning pairs in font file %s (line %d)",
+ FATAL, &fpos(AFMfilename), FileName(fnum), lnum);
+ debug2(DFT, DD, " ks[%d] = %d", pos, ksize);
+ ks[pos] = ksize;
+ ks_top++;
+ }
+
+ /* insert ch2 into the kc entries (sorted decreasing) for ch1 */
+ for( i = kc_top-1; i >= kt[ch1] && kc[i] < ch2; i-- )
+ { kc[i+1] = kc[i];
+ kv[i+1] = kv[i];
+ }
+ if( i >= kt[ch1] && kc[i] == ch2 )
+ Error(37, 37, "kerning pair %s %s appears twice in font file %s (line %d)",
+ FATAL, &fpos(AFMfilename), name1, name2, FileName(fnum), lnum);
+ kc[i+1] = ch2;
+ kv[i+1] = pos;
+ kc_top++;
+ }
+ }
+ ks[0] = ks_top;
+ }
+ break;
+
+
+ default:
+
+ break;
+
+ }
+ }
+
+ /* make sure we terminated the font metrics file gracefully */
+ if( status == (char *) NULL )
+ Error(37, 38, "EndFontMetrics missing from font file %s",
+ FATAL, &fpos(AFMfilename), FileName(fnum));
+ fclose(fp);
+ fp = (FILE *) NULL;
+
+ /* complete the initialization of first_size */
+ font_xheight2(first_size) =
+ BackEnd->uses_font_metrics ? xheight2 : PlainCharHeight / 4;
+ ch = MapCharEncoding(STR_PS_SPACENAME, font_mapping(first_size));
+ font_spacewidth(first_size) = ch == '\0' ? 0 : fnt[ch].right;
+
+
+ /***************************************************************************/
+ /* */
+ /* Read the optional Extra font metrics file, and record what's in it. */
+ /* */
+ /***************************************************************************/
+
+ if( Extrafilename != nilobj )
+ { debug0(DFS, D, " calling DefineFile from FontRead (extra_filename)");
+ extra_fnum = DefineFile(string(Extrafilename), STR_EMPTY,
+ &fpos(Extrafilename), FONT_FILE, FONT_PATH);
+ extra_fp = OpenFile(extra_fnum, FALSE, FALSE);
+ if( extra_fp == NULL )
+ Error(37, 39, "cannot open extra font file %s", FATAL,
+ &fpos(Extrafilename), FileName(extra_fnum));
+ lnum = 0;
+
+ while( StringFGets(buff, MAX_BUFF, extra_fp) != (char *) NULL )
+ {
+ debug1(DFT, D, " Extra: %s", buff);
+ lnum++;
+ sscanf( (char *) buff, "%s", command);
+ if( command[0] == 'S' )
+ {
+ if( StringEqual(command, AsciiToFull("StartExtraCharMetrics")) )
+ {
+ /* get extra character metrics, just like the others */
+ debug0(DFT, D, " StartExtraCharMetrics calling ReadCharMetrics");
+ ReadCharMetrics(face, fixed_pitch, xheight2, lig, &ligtop,
+ extra_fnum, fnt, &lnum, extra_fp);
+ }
+ else if( StringEqual(command, AsciiToFull("StartBuildComposites")) )
+ {
+ /* build composites */
+ debug0(DFT, D, " StartBuildComposites");
+ ReadCompositeMetrics(face, Extrafilename, extra_fnum, &lnum,
+ composite, cmp, &cmptop, extra_fp);
+ }
+ }
+ }
+
+ fclose(extra_fp);
+ extra_fp = (FILE *) NULL;
+ }
+
+
+ /***************************************************************************/
+ /* */
+ /* Set finfo[fontcount] and exit. */
+ /* */
+ /***************************************************************************/
+
+ finfo[font_count].font_table = first_size;
+ finfo[font_count].original_face = face;
+ finfo[font_count].underline_pos = xheight2 - under_pos;
+ finfo[font_count].underline_thick = under_thick;
+ finfo[font_count].size_table = fnt;
+ finfo[font_count].lig_table = lig;
+ finfo[font_count].composite = composite;
+ finfo[font_count].cmp_table = cmp;
+ finfo[font_count].cmp_top = cmptop;
+ finfo[font_count].kern_table = kt;
+ finfo[font_count].kern_chars = kc;
+ finfo[font_count].kern_value = kv;
+ finfo[font_count].kern_sizes = ks;
+
+ ifdebug(DFT, DD, DebugKernTable(font_count));
+ debug4(DFT, D, "FontRead returning: %d, name %s, fs %d, xh2 %d",
+ font_count, string(first_size), font_size(first_size), xheight2);
+ return face;
+
+ } /* end FontRead */
+
+
+ /*@::FontChange()@************************************************************/
+ /* */
+ /* FontChange(style, x) */
+ /* */
+ /* Returns an internal font number which is the current font changed */
+ /* according to word object x. e.g. if current font is Roman 12p and x is */
+ /* "-3p", then FontChange returns the internal font number of Roman 9p. */
+ /* */
+ /* FontChange permits empty and null objects within x; these have no */
+ /* effect. */
+ /* */
+ /*****************************************************************************/
+
+ void FontChange(STYLE *style, OBJECT x)
+ { /* register */ int i;
+ OBJECT requested_family, requested_face, requested_size;
+ OBJECT par[3], family, face, fsize, y, link, new, old, tmpf;
+ GAP gp; SHORT_LENGTH flen; int num, c; unsigned inc;
+ struct metrics *newfnt, *oldfnt;
+ FULL_CHAR *lig;
+ int cmptop;
+ COMPOSITE *oldcmp, *newcmp;
+ SHORT_LENGTH *oldks, *newks; int klen;
+ debug2(DFT, D, "FontChange( %s, %s )", EchoStyle(style), EchoObject(x));
+ assert( font(*style) <= font_count, "FontChange: font_count!");
+ ifdebug(DFT, DD, FontDebug());
+
+ /***************************************************************************/
+ /* */
+ /* Analyse x, doing any small-caps style changes immediately, and putting */
+ /* all the other words of x into par[0 .. num-1] for further analysis. */
+ /* */
+ /***************************************************************************/
+
+ num = 0;
+ if( type(x) == NULL_CLOS )
+ { /* acceptable, but do nothing */
+ }
+ else if( is_word(type(x)) )
+ {
+ if( StringEqual(string(x), STR_SMALL_CAPS_ON) )
+ small_caps(*style) = SMALL_CAPS_ON;
+ else if( StringEqual(string(x), STR_SMALL_CAPS_OFF) )
+ small_caps(*style) = SMALL_CAPS_OFF;
+ else if( !StringEqual(string(x), STR_EMPTY) )
+ par[num++] = x;
+ }
+ else if( type(x) == ACAT )
+ { for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ debug1(DFT, DDD, " pars examining y = %s", EchoObject(y));
+ if( type(y) == GAP_OBJ || type(y) == NULL_CLOS ) continue;
+ if( is_word(type(y)) )
+ {
+ if( StringEqual(string(y), STR_SMALL_CAPS_ON) )
+ small_caps(*style) = SMALL_CAPS_ON;
+ else if( StringEqual(string(y), STR_SMALL_CAPS_OFF) )
+ small_caps(*style) = SMALL_CAPS_OFF;
+ else if( !StringEqual(string(y), STR_EMPTY) )
+ {
+ if( num >= 3 )
+ { Error(37, 40, "error in left parameter of %s",
+ WARN, &fpos(x), KW_FONT);
+ debug0(DFT, D, "FontChange returning: ACAT children");
+ return;
+ }
+ par[num++] = y;
+ }
+ }
+ else
+ { Error(37, 41, "error in left parameter of %s",
+ WARN, &fpos(x), KW_FONT);
+ debug0(DFT, D, "FontChange returning: ACAT children");
+ return;
+ }
+ }
+ }
+ else
+ { Error(37, 42, "error in left parameter of %s", WARN, &fpos(x), KW_FONT);
+ debug0(DFT, D, "FontChange returning: wrong type");
+ return;
+ }
+ debug1(DFT, DDD, " found pars, num = %d", num);
+ if( num == 0 )
+ { debug1(DFT, D, "FontChange returning %s", EchoStyle(style));
+ return;
+ }
+
+ /***************************************************************************/
+ /* */
+ /* Extract size, family, and face changes (if any) from par[0 .. num-1]. */
+ /* */
+ /***************************************************************************/
+
+ /* extract fsize parameter, if any */
+ assert( num >= 1 && num <= 3, "FontChange: num!" );
+ requested_size = nilobj;
+ for( i = 0; i < num; i++ )
+ {
+ c = string(par[i])[0];
+ if( c == CH_INCGAP || c == CH_DECGAP || decimaldigit(c) )
+ {
+ /* extract fsize, shuffle the rest down */
+ requested_size = par[i];
+ for( i = i + 1; i < num; i++ )
+ par[i-1] = par[i];
+ num--;
+ }
+ }
+
+ /* what remains must be family and face */
+ switch( num )
+ {
+ case 0:
+
+ requested_family = requested_face = nilobj;
+ break;
+
+
+ case 1:
+
+ requested_family = nilobj;
+ requested_face = par[0];
+ break;
+
+
+ case 2:
+
+ requested_family = par[0];
+ requested_face = par[1];
+ break;
+
+
+ default:
+
+ Error(37, 43, "error in left parameter of %s", WARN, &fpos(x), KW_FONT);
+ debug0(DFT, D, "FontChange returning: too many parameters");
+ return;
+ break;
+ }
+
+ /* check for initial font case: must have family, face, and size */
+ if( font(*style) == NO_FONT && (requested_size == nilobj ||
+ requested_family == nilobj || requested_face == nilobj) )
+ Error(37, 44, "initial font must have family, face and size",
+ FATAL, &fpos(x));
+
+
+ /***************************************************************************/
+ /* */
+ /* Either find the family and face already existing, or load them. */
+ /* */
+ /***************************************************************************/
+
+ /* get font family */
+ family = nilobj;
+ if( requested_family != nilobj )
+ {
+ /* search for this family */
+ for( link = Down(font_root); link != font_root; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(string(requested_family), string(y)) ) break;
+ }
+ if( link != font_root )
+ family = y;
+ }
+ else
+ {
+ /* preserve current family */
+ assert( Up(finfo[font(*style)].font_table)!=finfo[font(*style)].font_table,
+ "FontChange: Up(finfo[font(*style)].font_table) !" );
+ Parent(tmpf, Up(finfo[font(*style)].font_table));
+ assert( is_word(type(tmpf)), "FontChange: type(tmpf)!" );
+ assert( Up(tmpf) != tmpf, "FontChange: Up(tmpf)!" );
+ Parent(family, Up(tmpf));
+ assert( is_word(type(family)), "FontChange: type(family)!" );
+ }
+
+ /* get font face, if have family */
+ face = nilobj;
+ if( family != nilobj )
+ {
+ if( requested_face != nilobj )
+ {
+ /* search for this face in family */
+ for( link = Down(family); link != family; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(string(requested_face), string(y)) ) break;
+ }
+ if( link != family )
+ face = y;
+ }
+ else
+ {
+ /* preserve current face */
+ Parent(face, Up(finfo[font(*style)].font_table));
+ assert( is_word(type(face)), "FontChange: type(face)!" );
+ assert( Up(face) != face, "FontChange: Up(face)!" );
+ }
+ }
+
+ if( face == nilobj )
+ {
+ /* face not loaded, try the font databases */
+ assert( family != nilobj || requested_family != nilobj, "FontChange fr!" );
+ assert( requested_face != nilobj, "FontChange requested_face!");
+ if( family != nilobj )
+ requested_family = family;
+ face = FontRead(string(requested_family), string(requested_face), x);
+
+ if( face == nilobj )
+ {
+ /* missing face name error; check whether a family name was intended */
+ for( link = Down(font_root); link != font_root; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(string(y), string(requested_face)) ) break;
+ }
+ if( link != font_root )
+ Error(37, 45, "font family name %s must be followed by a face name",
+ WARN, &fpos(requested_face), string(requested_face));
+ else
+ Error(37, 46, "there is no font with family name %s and face name %s",
+ WARN, &fpos(requested_face), string(requested_family),
+ string(requested_face));
+ debug0(DFT, D, "FontChange returning (unable to set face)");
+ return;
+ }
+ }
+
+ assert( Down(face) != face, "FontChange: no children!" );
+ assert( NextDown(Down(face)) != face, "FontChange: 1 child!" );
+ assert( NextDown(NextDown(Down(face))) != face, "FontChange: 2 children!" );
+
+ /***************************************************************************/
+ /* */
+ /* Now have family and face; search for size and return it if found. */
+ /* */
+ /***************************************************************************/
+
+ /* get font size as integer flen */
+ if( requested_size == nilobj )
+ flen = font_size(finfo[font(*style)].font_table);
+ else
+ { GetGap(requested_size, style, &gp, &inc);
+ if( mode(gp) != EDGE_MODE || units(gp) != FIXED_UNIT )
+ { Error(37, 47, "syntax error in font size %s; ignoring it",
+ WARN, &fpos(requested_size), string(requested_size));
+ flen = font_size(finfo[font(*style)].font_table);
+ }
+ else if( inc == GAP_ABS )
+ flen = width(gp);
+ else if( font(*style) == NO_FONT )
+ { Error(37, 48, "no current font on which to base size change %s",
+ FATAL, &fpos(requested_size), string(requested_size));
+ }
+ else if( inc == GAP_INC )
+ flen = font_size(finfo[font(*style)].font_table) + width(gp);
+ else if( inc == GAP_DEC )
+ flen = font_size(finfo[font(*style)].font_table) - width(gp);
+ else Error(37, 49, "FontChange: %d", INTERN, &fpos(x), inc);
+ }
+
+ if( flen <= 0 )
+ { Error(37, 50, "%s %s ignored (result is not positive)",
+ WARN, &fpos(requested_size), string(requested_size), KW_FONT);
+ debug0(DFT, D,"FontChange returning (non-positive size)");
+ return;
+ }
+
+ /* search fonts of face for desired size; return if already present */
+ if( !(BackEnd->uses_font_metrics) ) flen = PlainCharHeight;
+ for( link=NextDown(NextDown(Down(face))); link!=face; link = NextDown(link) )
+ { Child(fsize, link);
+ if( font_size(fsize) == flen )
+ { font(*style) = font_num(fsize);
+ SetGap(space_gap(*style), nobreak(space_gap(*style)), FALSE, TRUE,
+ FIXED_UNIT, EDGE_MODE, font_spacewidth(fsize));
+ debug2(DFT, D,"FontChange returning (old) %d (XHeight2 = %d)",
+ font(*style), font_xheight2(finfo[font(*style)].font_table));
+ return;
+ }
+ }
+
+ /***************************************************************************/
+ /* */
+ /* No suitable size right now, so scale the original size and exit. */
+ /* */
+ /***************************************************************************/
+
+ /* get a new number for this new size */
+ if( ++font_count >= finfo_size )
+ { if( font_count > MAX_FONT )
+ Error(37, 51, "too many different fonts and sizes (max is %d)",
+ FATAL, &fpos(x), MAX_FONT);
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_FONTS, -1,
+ -finfo_size * sizeof(FONT_INFO)));
+ finfo_size *= 2;
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_FONTS, 1,
+ finfo_size * sizeof(FONT_INFO)));
+ finfo = (FONT_INFO *) realloc(finfo, finfo_size * sizeof(FONT_INFO));
+ if( finfo == (FONT_INFO *) NULL )
+ Error(37, 52, "run out of memory when increasing font table size",
+ FATAL, &fpos(x));
+ }
+
+ /* create a new sized font record */
+ Child(old, NextDown(NextDown(Down(face))));
+ assert( is_word(type(old)), "FontChange: old!" );
+ new = MakeWord(WORD, string(old), no_fpos);
+ Link(face, new);
+ font_num(new) = font_count;
+ font_size(new) = BackEnd->uses_font_metrics ? flen : font_size(old);
+ font_xheight2(new) = font_xheight2(old) * font_size(new) / font_size(old);
+ font_recoded(new) = font_recoded(old);
+ font_mapping(new) = font_mapping(old);
+ font_spacewidth(new) = font_spacewidth(old) * font_size(new)/font_size(old);
+ finfo[font_count].font_table = new;
+ finfo[font_count].original_face = face;
+ finfo[font_count].underline_pos =
+ (finfo[font_num(old)].underline_pos * font_size(new)) / font_size(old);
+ finfo[font_count].underline_thick =
+ (finfo[font_num(old)].underline_thick * font_size(new)) / font_size(old);
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_FONTS, 1,
+ MAX_CHARS * sizeof(struct metrics)));
+ finfo[font_count].size_table =
+ (struct metrics *) malloc(MAX_CHARS * sizeof(struct metrics));
+ if( finfo[font_count].size_table == (struct metrics *) NULL )
+ Error(37, 53, "run out of memory when changing font or font size",
+ FATAL, &fpos(x));
+ finfo[font_count].lig_table = lig = finfo[font_num(old)].lig_table;
+
+ /* scale old font to new size */
+ newfnt = finfo[font_num(new)].size_table;
+ oldfnt = finfo[font_num(old)].size_table;
+ for( i = 0; i < MAX_CHARS; i++ ) if( lig[i] != 1 )
+ { newfnt[i].left = (oldfnt[i].left * font_size(new)) / font_size(old);
+ newfnt[i].right = (oldfnt[i].right * font_size(new)) / font_size(old);
+ newfnt[i].down = (oldfnt[i].down * font_size(new)) / font_size(old);
+ newfnt[i].up = (oldfnt[i].up * font_size(new)) / font_size(old);
+ newfnt[i].last_adjust = (oldfnt[i].last_adjust * font_size(new)) / font_size(old);
+ }
+
+ /* copy and scale composite table */
+ finfo[font_count].composite = finfo[font_num(old)].composite;
+ finfo[font_count].cmp_top = cmptop = finfo[font_num(old)].cmp_top;
+ oldcmp = finfo[font_num(old)].cmp_table;
+ newcmp = (COMPOSITE *) malloc(cmptop*sizeof(COMPOSITE));
+ if( newcmp == (COMPOSITE *) NULL )
+ Error(37, 54, "run out of memory when changing font or font size",
+ FATAL, &fpos(x));
+ for( i = 1; i < cmptop; i++ ) /* NB position 0 is unused */
+ { newcmp[i].char_code = oldcmp[i].char_code;
+ if( newcmp[i].char_code != (FULL_CHAR) '\0' )
+ { newcmp[i].x_offset = (oldcmp[i].x_offset*font_size(new)) / font_size(old);
+ newcmp[i].y_offset = (oldcmp[i].y_offset*font_size(new)) / font_size(old);
+ debug5(DFT, D, "FontChange scales composite %d from (%d, %d) to (%d, %d)",
+ (int) newcmp[i].char_code, oldcmp[i].x_offset, oldcmp[i].y_offset,
+ newcmp[i].x_offset, newcmp[i].y_offset);
+ }
+ }
+ finfo[font_count].cmp_table = newcmp;
+
+ /* copy and scale kerning tables */
+ finfo[font_count].kern_table = finfo[font_num(old)].kern_table;
+ finfo[font_count].kern_chars = finfo[font_num(old)].kern_chars;
+ finfo[font_count].kern_value = finfo[font_num(old)].kern_value;
+ oldks = finfo[font_num(old)].kern_sizes;
+ if( oldks != (SHORT_LENGTH *) NULL )
+ { klen = oldks[0];
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_FONTS, 0, klen * sizeof(SHORT_LENGTH)));
+ finfo[font_count].kern_sizes = newks =
+ (SHORT_LENGTH *) malloc(klen * sizeof(SHORT_LENGTH));
+ if( newks == (SHORT_LENGTH *) NULL )
+ Error(37, 55, "run out of memory when changing font or font size",
+ FATAL, &fpos(x));
+ newks[0] = klen;
+ for( i = 1; i < klen; i++ )
+ newks[i] = (oldks[i] * font_size(new)) / font_size(old);
+ }
+ else finfo[font_count].kern_sizes = (SHORT_LENGTH *) NULL;
+
+ /* return new font number and exit */
+ font(*style) = font_count;
+ SetGap(space_gap(*style), nobreak(space_gap(*style)), FALSE, TRUE,
+ FIXED_UNIT, EDGE_MODE, font_spacewidth(new));
+ debug2(DFT, D,"FontChange returning (scaled) %d (XHeight2 = %d)",
+ font(*style), font_xheight2(finfo[font(*style)].font_table));
+ /* FontDebug(); */
+ } /* end FontChange */
+
+
+ /*****************************************************************************/
+ /* */
+ /* KernLength(fnum, ch1, ch2, res) */
+ /* */
+ /* Set res to the kern length between ch1 and ch2 in font fnum, or 0 if */
+ /* none. Actually we first convert ch1 and ch2 to corresponding unaccented */
+ /* characters, because metrics files don't seem to contain kerning pairs */
+ /* for accented characters. */
+ /* */
+ /*****************************************************************************/
+
+ #define KernLength(fnum, mp, ch1, ch2, res) \
+ { int ua_ch1 = mp[ch1]; \
+ int ua_ch2 = mp[ch2]; \
+ int i = finfo[fnum].kern_table[ua_ch1], j; \
+ if( i == 0 ) res = 0; \
+ else \
+ { FULL_CHAR *kc = finfo[fnum].kern_chars; \
+ for( j = i; kc[j] > ua_ch2; j++ ); \
+ res = (kc[j] == ua_ch2) ? \
+ finfo[fnum].kern_sizes[finfo[fnum].kern_value[j]] : 0; \
+ } \
+ } /* end KernLength */
+
+
+ /*@::FontWordSize()@**********************************************************/
+ /* */
+ /* FontWordSize(x) */
+ /* */
+ /* Calculate the horizontal and vertical size of WORD or QWORD x, including */
+ /* the effect of ligature sequences but not replacing them with ligatures. */
+ /* */
+ /*****************************************************************************/
+
+ void FontWordSize(OBJECT x)
+ { FULL_CHAR *p, *q, *a, *b, *lig, *unacc, *acc; OBJECT tmp;
+ FULL_CHAR buff[MAX_BUFF]; MAPPING m;
+ int r, u, d, ksize; struct metrics *fnt;
+ debug2(DFT, D, "FontWordSize( %s ), font = %d", string(x), word_font(x));
+ assert( is_word(type(x)), "FontWordSize: !is_word(type(x))!" );
+
+ p = string(x);
+ q = buff;
+ if( *p )
+ { if( word_font(x) < 1 || word_font(x) > font_count )
+ Error(37, 56, "no current font at word %s", FATAL, &fpos(x), string(x));
+ if( word_colour(x) == 0 && BackEnd->colour_avail )
+ Error(37, 57, "no current colour at word %s", FATAL, &fpos(x), string(x));
+ if( word_language(x) == 0 )
+ Error(37, 58, "no current language at word %s", FATAL,&fpos(x),string(x));
+ fnt = finfo[word_font(x)].size_table;
+ lig = finfo[word_font(x)].lig_table;
+ m = font_mapping(finfo[word_font(x)].font_table);
+ unacc = MapTable[m]->map[MAP_UNACCENTED];
+ acc = MapTable[m]->map[MAP_ACCENT];
+ d = u = r = 0;
+ do
+ {
+ /* check for missing glyph (lig[] == 1) or ligatures (lig[] > 1) */
+ debug2(DFT, D, " examining `%c' lig = %d", *p, lig[*p]);
+ if( lig[*q = *p++] )
+ {
+ if( lig[*q] == 1 )
+ { tmp = MakeWord(QWORD, STR_SPACE, &fpos(x));
+ string(tmp)[0] = *q;
+ /* bug fix: unaccented version exists if unacc differs from self */
+ if( unacc[*q] != *q )
+ {
+ /* *** this is acceptable now, let this char through
+ Error(37, 59, "accent dropped from character %s (it has no glyph in font %s)",
+ WARN, &fpos(x),
+ StringQuotedWord(tmp), FontFamilyAndFace(word_font(x)));
+ *(p-1) = *q = unacc[*q];
+ *** */
+ debug2(DFT, D, " unacc[%c] = `%c'", *q, unacc[*q]);
+ fnt[*q].up = fnt[unacc[*q]].up;
+ fnt[*q].down = fnt[unacc[*q]].down;
+ fnt[*q].left = fnt[unacc[*q]].left;
+ fnt[*q].right = fnt[unacc[*q]].right;
+ fnt[*q].last_adjust = fnt[unacc[*q]].last_adjust;
+ lig[*q] = 0;
+ }
+ else
+ {
+ debug1(DFT, D, " unacc[%c] = 0, replacing by space", *q);
+ Error(37, 60, "character %s replaced by space (it has no glyph in font %s)",
+ WARN, &fpos(x),
+ StringQuotedWord(tmp), FontFamilyAndFace(word_font(x)));
+ *(p-1) = *q = CH_SPACE;
+ }
+ Dispose(tmp);
+ }
+ else
+ {
+ debug1(DFT, D, " processing ligature beginning at %c", *q);
+ a = &lig[ lig[*(p-1)] + MAX_CHARS ];
+ while( *a++ == *(p-1) )
+ { b = p;
+ while( *a == *b && *(a+1) != '\0' && *b != '\0' ) a++, b++;
+ if( *(a+1) == '\0' )
+ { *q = *a;
+ p = b;
+ break;
+ }
+ else
+ { while( *++a );
+ a++;
+ }
+ }
+ }
+ }
+
+ /* accumulate size of *q */
+ if( fnt[*q].up > u ) u = fnt[*q].up;
+ if( fnt[*q].down < d ) d = fnt[*q].down;
+ r += fnt[*q++].right;
+ } while( *p );
+ *q = '\0';
+
+ /* adjust for last character */
+ r += fnt[*(q-1)].last_adjust;
+
+ /* add kern lengths to r */
+ for( p = buff, q = p+1; *q; p++, q++ )
+ { KernLength(word_font(x), unacc, *p, *q, ksize);
+ debugcond3(DFT, D, ksize != 0, " KernLength(fnum, %c, %c) = %d",
+ *p, *q, ksize);
+ r += ksize;
+ }
+ /* set sizes of x */
+ back(x, COLM) = 0;
+ fwd(x, COLM) = r;
+ back(x, ROWM) = u;
+ fwd(x, ROWM) = -d;
+ }
+ else back(x, COLM) = fwd(x, COLM) = back(x, ROWM) = fwd(x, ROWM) = 0;
+ debug4(DFT, D, "FontWordSize returning %hd %hd %hd %hd",
+ back(x, COLM), fwd(x, COLM), back(x, ROWM), fwd(x, ROWM));
+ } /* end FontWordSize */
+
+
+ /*@::FontSize(), FontHalfXHeight(), FontEncoding(), FontName()@***************/
+ /* */
+ /* FULL_LENGTH FontSize(fnum, x) */
+ /* */
+ /* Return the size of this font. x is for error messages only. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_LENGTH FontSize(FONT_NUM fnum, OBJECT x)
+ { debug1(DFT, D, "FontSize( %d )", fnum);
+ assert( fnum <= font_count, "FontSize!" );
+ if( fnum <= 0 )
+ Error(37, 61, "no current font at this point", FATAL, &fpos(x));
+ debug1(DFT, D, "FontSize returning %d", font_size(finfo[fnum].font_table));
+ return font_size(finfo[fnum].font_table);
+ } /* end FontSize */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_LENGTH FontHalfXHeight(fnum) */
+ /* */
+ /* Return the xheight2 value of this font. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_LENGTH FontHalfXHeight(FONT_NUM fnum)
+ { debug1(DFT, DD, "FontHalfXHeight( %d )", fnum);
+ assert( fnum <= font_count, "FontHalfXHeight!" );
+ debug1(DFT, DD, "FontHalfXHeight returning %d",
+ font_xheight2(finfo[fnum].font_table));
+ return font_xheight2(finfo[fnum].font_table);
+ } /* end FontHalfXHeight */
+
+
+ /*****************************************************************************/
+ /* */
+ /* MAPPING FontMapping(fnum, xfpos) */
+ /* */
+ /* Return the character mapping of this font, to use for small caps, etc. */
+ /* xfpos is the file position for error messages. */
+ /* */
+ /*****************************************************************************/
+
+ MAPPING FontMapping(FONT_NUM fnum, FILE_POS *xfpos)
+ { debug1(DFT, DD, "FontMapping( %d )", fnum);
+ assert( fnum <= font_count, "FontMapping!" );
+ if( fnum <= 0 )
+ Error(37, 62, "no current font at this point", FATAL, xfpos);
+ debug1(DFT, DD, "FontMapping returning %d",
+ font_mapping(finfo[fnum].font_table));
+ return font_mapping(finfo[fnum].font_table);
+ } /* end FontMapping */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *FontName(fnum) */
+ /* */
+ /* Return the short PostScript name of this font. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *FontName(FONT_NUM fnum)
+ { debug1(DFT, D, "FontName( %d )", fnum);
+ assert( fnum <= font_count, "FontName!" );
+ debug1(DFT, D, "FontName returning %s", string(finfo[fnum].font_table));
+ return string(finfo[fnum].font_table);
+ } /* end FontName */
+
+
+ /*@::FontFamily(), FontFace@**************************************************/
+ /* */
+ /* FULL_CHAR *FontFamilyAndFace(fnum) */
+ /* */
+ /* Return a static string of the current font family and face. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *FontFamily(FONT_NUM fnum)
+ { OBJECT face, family;
+ debug1(DFT, D, "FontFamily( %d )", fnum);
+ assert( fnum <= font_count, "FontFamiliy!" );
+ Parent(face, Up(finfo[fnum].font_table));
+ Parent(family, Up(face));
+ debug1(DFT, D, "FontFamily returning %s", string(family));
+ return string(family);
+ } /* end FontFamilyAndFace */
+
+
+ FULL_CHAR *FontFace(FONT_NUM fnum)
+ { OBJECT face, family;
+ debug1(DFT, D, "FontFacec( %d )", fnum);
+ assert( fnum <= font_count, "FontFamiliy!" );
+ Parent(face, Up(finfo[fnum].font_table));
+ Parent(family, Up(face));
+ debug1(DFT, D, "FontFace returning %s", string(face));
+ return string(face);
+ } /* end FontFamilyAndFace */
+
+
+ /*@::FontFamilyAndFace(), FontPrintAll()@*************************************/
+ /* */
+ /* FULL_CHAR *FontFamilyAndFace(fnum) */
+ /* */
+ /* Return a static string of the current font family and face. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *FontFamilyAndFace(FONT_NUM fnum)
+ { OBJECT face, family; static FULL_CHAR buff[80];
+ debug1(DFT, D, "FontFamilyAndFace( %d )", fnum);
+ assert( fnum <= font_count, "FontName!" );
+ Parent(face, Up(finfo[fnum].font_table));
+ Parent(family, Up(face));
+ if( StringLength(string(family)) + StringLength(string(face)) + 1 > 80 )
+ Error(37, 63, "family and face names %s %s are too long",
+ FATAL, no_fpos, string(family), string(face));
+ StringCopy(buff, string(family));
+ StringCat(buff, STR_SPACE);
+ StringCat(buff, string(face));
+ debug1(DFT, D, "FontName returning %s", buff);
+ return buff;
+ } /* end FontFamilyAndFace */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FontPrintAll(fp) */
+ /* */
+ /* Print all font encoding commands on output file fp */
+ /* */
+ /*****************************************************************************/
+
+ void FontPrintAll(FILE *fp)
+ { OBJECT family, face, first_size, ps_name, link, flink;
+ assert(font_root!=nilobj && type(font_root)==ACAT, "FontDebug: font_root!");
+ debug0(DFT, DD, "FontPrintAll(fp)");
+ for( link = Down(font_root); link != font_root; link = NextDown(link) )
+ { Child(family, link);
+ assert( is_word(type(family)), "FontPrintAll: family!" );
+ for( flink = Down(family); flink != family; flink = NextDown(flink) )
+ { Child(face, flink);
+ assert( is_word(type(face)), "FontPrintAll: face!" );
+ assert( Down(face) != face && NextDown(Down(face)) != face &&
+ NextDown(NextDown(Down(face))) != face, "FontDebug: Down(face)!");
+ Child(ps_name, Down(face));
+ assert( is_word(type(ps_name)), "FontPrintAll: ps_name!" );
+ Child(first_size, NextDown(NextDown(Down(face))));
+ assert( is_word(type(first_size)), "FontPrintAll: first_size!" );
+ if( font_recoded(face) )
+ { fprintf(fp, "/%s%s %s /%s LoutRecode\n",
+ string(ps_name), string(first_size),
+ MapEncodingName(font_mapping(face)), string(ps_name));
+ fprintf(fp, "/%s { /%s%s LoutFont } def\n", string(first_size),
+ string(ps_name), string(first_size));
+ }
+ else fprintf(fp, "/%s { /%s LoutFont } def\n", string(first_size),
+ string(ps_name));
+ }
+ }
+ fputs("\n", fp);
+ debug0(DFT, DD, "FontPrintAll returning.");
+ } /* end FontPrintAll */
+
+
+ /*@@**************************************************************************/
+ /* */
+ /* FontPrintPageSetup(fp) */
+ /* */
+ /* Print all font encoding commands needed for the current page onto fp. */
+ /* */
+ /*****************************************************************************/
+
+ void FontPrintPageSetup(FILE *fp)
+ { OBJECT face, first_size, ps_name, link;
+ assert(font_root!=nilobj && type(font_root)==ACAT, "FontDebug: font_root!");
+ assert(font_used!=nilobj && type(font_used)==ACAT, "FontDebug: font_used!");
+ debug0(DFT, DD, "FontPrintPageSetup(fp)");
+ for( link = Down(font_used); link != font_used; link = NextDown(link) )
+ {
+ Child(face, link);
+ assert( is_word(type(face)), "FontPrintPageSetup: face!" );
+ assert( Down(face) != face, "FontDebug: Down(face)!");
+
+ /* print font encoding command */
+ Child(first_size, NextDown(NextDown(Down(face))));
+ assert( is_word(type(first_size)), "FontPrintPageSetup: first_size!" );
+ Child(ps_name, Down(face));
+ assert( is_word(type(ps_name)), "FontPrintPageSetup: ps_name!" );
+ BackEnd->PrintPageSetupForFont(face, font_curr_page,
+ string(ps_name), string(first_size));
+ }
+ debug0(DFT, DD, "FontPrintPageSetup returning.");
+ } /* end FontPrintPageSetup */
+
+
+ /*@@**************************************************************************/
+ /* */
+ /* FontPrintPageResources(fp) */
+ /* */
+ /* Print all page resources (i.e. fonts needed or supplied) onto fp. */
+ /* */
+ /*****************************************************************************/
+
+ void FontPrintPageResources(FILE *fp)
+ { OBJECT face, ps_name, link, pface, pname, plink;
+ BOOLEAN first;
+ assert(font_root!=nilobj && type(font_root)==ACAT, "FontDebug: font_root!");
+ assert(font_used!=nilobj && type(font_used)==ACAT, "FontDebug: font_used!");
+ debug0(DFT, DD, "FontPrintPageResources(fp)");
+ first = TRUE;
+ for( link = Down(font_used); link != font_used; link = NextDown(link) )
+ {
+ Child(face, link);
+ assert( is_word(type(face)), "FontPrintPageResources: face!" );
+ assert( Down(face) != face, "FontDebug: Down(face)!");
+ Child(ps_name, Down(face));
+ assert( is_word(type(ps_name)), "FontPrintPageResources: ps_name!" );
+
+ /* make sure this ps_name has not been printed before (ugly, I know). */
+ /* Repeats arise when the font appears twice in the database under */
+ /* different family-face names, perhaps because of sysnonyms like */
+ /* Italic and Slope, or perhaps because of different encoding vectors */
+ for( plink = Down(font_used); plink != link; plink = NextDown(plink) )
+ {
+ Child(pface, plink);
+ Child(pname, Down(pface));
+ if( StringEqual(string(pname), string(ps_name)) )
+ break;
+ }
+ if( plink == link )
+ {
+ /* not seen before, so print it */
+ BackEnd->PrintPageResourceForFont(string(ps_name), first);
+ first = FALSE;
+ }
+ }
+ debug0(DFT, DD, "FontPrintPageResources returning.");
+ } /* end FontPrintPageResources */
+
+
+ /*@@**************************************************************************/
+ /* */
+ /* FontAdvanceCurrentPage() */
+ /* */
+ /* Advance the current page. */
+ /* */
+ /*****************************************************************************/
+
+ void FontAdvanceCurrentPage(void)
+ { debug0(DFT, DD, "FontAdvanceCurrentPage()");
+ while( Down(font_used) != font_used ) DeleteLink(Down(font_used));
+ font_curr_page++;
+ debug0(DFT, DD, "FontAdvanceCurrentPage() returning.");
+ } /* end FontAdvanceCurrentPage */
+
+
+ /*@::FontPageUsed()@**********************************************************/
+ /* */
+ /* OBJECT FontPageUsed(face) */
+ /* */
+ /* Declares that font face is used on the current page. */
+ /* */
+ /*****************************************************************************/
+
+ void FontPageUsed(OBJECT face)
+ { debug1(DFT, DD, "FontPageUsed(%d)", font_num(face));
+ assert( font_page(face) < font_curr_page, "FontPageUsed!" );
+ Link(font_used, face);
+ font_page(face) = font_curr_page;
+ debug0(DFT, DD, "FontPageUsed returning");
+ } /* end FontPageUsed */
+
+
+ /*@::FontNeeded()@************************************************************/
+ /* */
+ /* OBJECT FontNeeded(fp) */
+ /* */
+ /* Writes font needed resources onto file out_fp. Returns TRUE if none. */
+ /* Now that we are using a database, every font that is actually loaded */
+ /* is really needed. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN FontNeeded(FILE *fp)
+ { BOOLEAN first_need = TRUE;
+ OBJECT link, flink, family, face, ps_name;
+ for( link = Down(font_root); link != font_root; link = NextDown(link) )
+ { Child(family, link);
+ for( flink = Down(family); flink != family; flink = NextDown(flink) )
+ { Child(face, flink);
+ Child(ps_name, Down(face));
+ assert( is_word(type(ps_name)), "FontPrintPageResources: ps_name!" );
+ fprintf(fp, "%s font %s\n",
+ first_need ? "%%DocumentNeededResources:" : "%%+", string(ps_name));
+ first_need = FALSE;
+ }
+ }
+ return first_need;
+ } /* end FontNeeded */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z38.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z38.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z38.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,656 ----
+ /*@z38.c:Character Mappings:Declarations@*************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z38.c */
+ /* MODULE: Character Mappings */
+ /* EXTERNS: MapLoad(), MapCharEncoding(), MapEncodingName(), */
+ /* MapPrintEncodings(), MapPrintResources(), MapSmallCaps() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define MAX_MAP 20 /* max number of lcm files */
+
+ /*****************************************************************************/
+ /* */
+ /* Should really be private but have been placed in externs because for */
+ /* efficiency they are used by z37.c and z34.c */
+ /* */
+ /* #define MAX_CHASH 353 */
+ /* #define MAP_UPPERCASE 0 */
+ /* #define MAP_LOWERCASE 1 */
+ /* #define MAP_UNACCENTED 2 */
+ /* #define MAP_ACCENT 3 */
+ /* #define MAPS 4 */
+ /* */
+ /* typedef struct mapvec { */
+ /* OBJECT file_name; */
+ /* FILE_NUM fnum; */
+ /* BOOLEAN seen_recoded; */
+ /* int last_page_printed; */
+ /* OBJECT name; */
+ /* OBJECT vector[MAX_CHARS]; */
+ /* FULL_CHAR hash_table[MAX_CHASH]; */
+ /* FULL_CHAR map[MAPS][MAX_CHARS]; */
+ /* } *MAP_VEC; */
+ /* */
+ /*****************************************************************************/
+
+ MAP_VEC MapTable[MAX_MAP]; /* the mappings */
+
+ static OBJECT notdef_word = nilobj; /* notdef word */
+ static int maptop = 1; /* first free slot in MapTable[] */
+ /* save 0 for "no mapping" */
+
+ /*****************************************************************************/
+ /* */
+ /* static int NameInsert(cname) */
+ /* static FULL_CHAR NameRetrieve(cname) */
+ /* */
+ /*****************************************************************************/
+
+ #define hash(str, pos) \
+ { FULL_CHAR *p = str; \
+ for( pos = 2 * *p++; *p; pos += *p++); \
+ pos = pos % MAX_CHASH; \
+ }
+
+ static void NameInsert(FULL_CHAR *cname, int ccode, MAP_VEC map)
+ { int pos;
+ hash(cname, pos);
+ while( map->hash_table[pos] != (FULL_CHAR) '\0' )
+ pos = (pos + 1) % MAX_CHASH;
+ map->vector[ccode] = MakeWord(WORD, cname, no_fpos);
+ map->hash_table[pos] = ccode;
+ } /* end NameInsert */
+
+ static FULL_CHAR NameRetrieve(FULL_CHAR *cname, MAP_VEC map)
+ { int pos; FULL_CHAR ch;
+ hash(cname, pos);
+ while( (ch = map->hash_table[pos]) != (FULL_CHAR) '\0' )
+ {
+ if( StringEqual(string(map->vector[ch]), cname) )
+ return ch;
+ pos = (pos + 1) % MAX_CHASH;
+ }
+ return ch;
+ } /* end NameRetrieve */
+
+
+ /*@::MapLoad()@***************************************************************/
+ /* */
+ /* MAPPING MapLoad(file_name, recoded) */
+ /* */
+ /* Declare file_name to be a character mapping (LCM) file. A file may be */
+ /* so declared more than once. Parameter recoded is true if the font that */
+ /* uses this mapping declares that it needs to be recoded, which in turn */
+ /* means that this mapping might have to be printed out. Whether or not it */
+ /* is actually printed depends upon whether we print a font that uses it */
+ /* and that requires recoding. */
+ /* */
+ /*****************************************************************************/
+
+ MAPPING MapLoad(OBJECT file_name, BOOLEAN recoded)
+ { FILE *fp; MAP_VEC map; MAPPING res;
+ int i, m, curr_line_num, line_pos, prev_code, dc, oc, count;
+ FULL_CHAR buff[MAX_BUFF], cn[MAX_BUFF], ch, mapname[MAX_BUFF],
+ mapval[MAX_BUFF];
+ debug2(DCM,D, "MapLoad(%s, %s)", EchoObject(file_name), bool(recoded));
+
+ /* if the file name is "-", it means no mapping file is supplied */
+ if( StringEqual(string(file_name), AsciiToFull("-")) )
+ { debug1(DCM, D, "MapLoad returning 0 (file name is %s)",
+ string(file_name));
+ return (MAPPING) 0;
+ }
+
+ /* if seen this file name before, just update seen_recoded and return prev */
+ for( res = 1; res < maptop; res++ )
+ {
+ if( StringEqual(string(MapTable[res]->file_name), string(file_name)) )
+ { Dispose(file_name);
+ MapTable[res]->seen_recoded = MapTable[res]->seen_recoded || recoded;
+ debug1(DCM, D, "MapLoad returning %d (not new)", res);
+ return res;
+ }
+ }
+
+ /* initialize PostScript name of all undefined characters */
+ if( notdef_word == nilobj )
+ notdef_word = MakeWord(WORD, AsciiToFull(".notdef"), no_fpos);
+
+ /* new, so allocate a new slot in MapTable for this new mapping */
+ if( maptop == MAX_MAP )
+ Error(38, 1, "too many character mappings", FATAL, &fpos(file_name));
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_CMAPS, 1, sizeof(struct mapvec)));
+ MapTable[res = maptop++] = map = (MAP_VEC) malloc( sizeof(struct mapvec) );
+ if( map == (MAP_VEC) NULL )
+ Error(38, 2, "run out of memory when loading character mapping",
+ FATAL, &fpos(file_name));
+
+ /* initialize all the fields */
+ map->file_name = file_name;
+ debug0(DFS, D, " calling DefineFile from MapLoad");
+ map->fnum = DefineFile(string(file_name), STR_EMPTY, &fpos(file_name),
+ MAPPING_FILE, MAPPING_PATH);
+ fp = OpenFile(map->fnum, FALSE, FALSE);
+ if( fp == NULL ) Error(38, 3, "cannot open character mapping file %s",
+ FATAL, PosOfFile(map->fnum), FileName(map->fnum));
+ map->seen_recoded = recoded;
+ map->last_page_printed = 0;
+ StringCopy(buff, AsciiToFull("vec"));
+ StringCat(buff, StringInt(maptop));
+ map->name = MakeWord(WORD, buff, no_fpos);
+ for( m = 0; m < MAPS; m++ )
+ { for( i = 0; i < MAX_CHARS; i++ )
+ map->map[m][i] = '\0';
+ }
+
+ /* unaccented map is defined to be self as default */
+ for( i = 0; i < MAX_CHARS; i++ )
+ map->map[MAP_UNACCENTED][i] = i;
+
+ for( i = 0; i < MAX_CHARS; i++ ) map->vector[i] = notdef_word;
+ for( i = 0; i < MAX_CHASH; i++ ) map->hash_table[i] = 0;
+
+ /* first pass through the file; read character codes and names only */
+ prev_code = -1; curr_line_num = 0;
+ while( fgets( (char *) buff, MAX_BUFF, fp) == (char *) buff )
+ {
+ /* skip comment lines and blank lines */
+ curr_line_num++;
+ for( i = 0; buff[i] == ' ' || buff[i] == '\t'; i++ );
+ if( buff[i] == '#' || buff[i] == '\n' || buff[i] == '\0' ) continue;
+
+ /* parse line and check validity of decimal and octal character codes */
+ count = sscanf( (char *) buff, "%d %o %s", &dc, &oc, cn);
+ if( count < 2 )
+ Error(38, 4, "character code(s) missing in mapping file (line %d)",
+ FATAL, &fpos(file_name));
+ if( dc != oc )
+ Error(38, 5, "decimal and octal codes disagree in mapping file (line %d)",
+ FATAL, &fpos(file_name));
+ if( dc < 1 && !StringEqual(cn, STR_NOCHAR) )
+ Error(38, 6, "code %d too small (min is 1) in mapping file (line %d)",
+ FATAL, &fpos(file_name), dc, curr_line_num);
+ if( dc < prev_code )
+ Error(38, 7, "code %d out of order in mapping file (line %d)",
+ FATAL, &fpos(file_name), dc, curr_line_num);
+ if( dc == prev_code )
+ Error(38, 8, "code %d repeated in mapping file (line %d)",
+ FATAL, &fpos(file_name), dc, curr_line_num);
+ if( dc > MAX_CHARS )
+ Error(38, 9, "code %d too large (max is %d) in mapping file (line %d)",
+ FATAL, &fpos(file_name), dc, MAX_CHARS, curr_line_num);
+ prev_code = dc;
+
+ /* insert character name, if any */
+ debug2(DCM, DD, " line %d: %s", curr_line_num, cn);
+ if( count >= 3 && !StringEqual(cn, STR_NOCHAR) )
+ {
+ /* insert (cn, dc) pair into hash table; name may be repeated */
+ if( (ch = NameRetrieve(cn, map)) != 0 )
+ map->vector[dc] = map->vector[ch];
+ else
+ NameInsert(cn, dc, map);
+ }
+ }
+
+ /* second pass through the file: read mappings */
+ rewind(fp);
+ curr_line_num = 0;
+ while( fgets( (char *) buff, MAX_BUFF, fp) == (char *) buff )
+ {
+ /* skip comment lines and blank lines */
+ curr_line_num++;
+ for( i = 0; buff[i] == ' ' || buff[i] == '\t'; i++ );
+ if( buff[i] == '#' || buff[i] == '\n' || buff[i] == '\0' ) continue;
+
+ /* parse line */
+ count = sscanf( (char *) buff, "%d %o %s%n",
+ &dc, &oc, cn, &line_pos);
+
+ /* find and insert the maps */
+ while( sscanf( (char *) &buff[line_pos], "%s %[^;];%n",
+ mapname, mapval, &i) == 2 )
+ {
+ debug3(DCM, DD, " line %d: %s %s", curr_line_num, mapname, mapval);
+ line_pos += i;
+ if( StringEqual(mapname, AsciiToFull("UC")) )
+ m = MAP_UPPERCASE;
+ else if( StringEqual(mapname, AsciiToFull("LC")) )
+ m = MAP_LOWERCASE;
+ else if( StringEqual(mapname, AsciiToFull("UA")) )
+ m = MAP_UNACCENTED;
+ else if( StringEqual(mapname, AsciiToFull("AC")) )
+ m = MAP_ACCENT;
+ else
+ Error(38, 10, "unknown mapping name %s in mapping file %s (line %d)",
+ FATAL, &fpos(file_name), mapname, FileName(map->fnum), curr_line_num);
+ ch = NameRetrieve(mapval, map);
+ if( ch == (FULL_CHAR) '\0' )
+ Error(38, 11, "unknown character %s in mapping file %s (line %d)",
+ FATAL, &fpos(file_name), mapval, FileName(map->fnum), curr_line_num);
+ map->map[m][dc] = ch;
+ }
+ }
+ fclose(fp);
+ debug1(DCM, D, "MapLoad returning %d (new mapping)", res);
+ return res;
+ } /* end MapLoad */
+
+
+ /*@::MapCharEncoding(), MapEncodingName(), MapPrintEncodings()@***************/
+ /* */
+ /* FULL_CHAR MapCharEncoding(str, map) */
+ /* */
+ /* Returns the character code corresponding to character name str in */
+ /* MAPPING enc, or 0 if not found. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR MapCharEncoding(FULL_CHAR *str, MAPPING m)
+ { MAP_VEC map;
+ map = MapTable[m];
+ return (FULL_CHAR) NameRetrieve(str, map);
+ } /* end MapCharEncoding */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *MapEncodingName(m) */
+ /* */
+ /* Returns the PostScript name of the encoding vector of mapping m */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *MapEncodingName(MAPPING m)
+ { assert( m < maptop, "MapEncodingName: m out of range!" );
+ return string(MapTable[m]->name);
+ } /* end MapEncodingName */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void MapEnsurePrinted(MAPPING m, int curr_page) */
+ /* */
+ /* Ensure that MAPPING m is printed on page curr_page, if required. */
+ /* It's required if it has neither been printed on the current page */
+ /* already, nor on page 1 (page 1 is really the entire document setup). */
+ /* */
+ /*****************************************************************************/
+
+ void MapEnsurePrinted(MAPPING m, int curr_page)
+ { MAP_VEC map = MapTable[m];
+ assert( map->seen_recoded, "MapEnsurePrinted: not seen_recoded!" );
+ if( map->last_page_printed < curr_page && map->last_page_printed != 1 )
+ { map->last_page_printed = curr_page;
+ BackEnd->PrintMapping(m);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* MapPrintEncodings() */
+ /* */
+ /* Print all encoding vectors in existence so far; this counts as printing */
+ /* them on "page 1", but in fact they will appear in the document setup */
+ /* section. */
+ /* */
+ /*****************************************************************************/
+
+ void MapPrintEncodings()
+ { MAPPING m; MAP_VEC map;
+ for( m = 1; m < maptop; m++ )
+ { if( MapTable[m]->seen_recoded )
+ { BackEnd->PrintMapping(m);
+ map = MapTable[m];
+ map->last_page_printed = 1;
+ }
+ }
+ } /* end MapPrintEncodings */
+
+
+ /*****************************************************************************/
+ /* */
+ /* MapPrintPSResources(fp) */
+ /* */
+ /* Print PostScript resource entries for all encoding vectors on file fp. */
+ /* */
+ /*****************************************************************************/
+
+ void MapPrintPSResources(FILE *fp)
+ { MAPPING m; MAP_VEC map;
+ for( m = 1; m < maptop; m++ ) if( MapTable[m]->seen_recoded )
+ { map = MapTable[m];
+ fprintf(fp, "%%%%+ encoding %s\n", string(map->name));
+ }
+ } /* end MapPrintPSResources */
+
+
+ /*@@**************************************************************************/
+ /* */
+ /* OBJECT DoWord(buff, q, x, fnum) */
+ /* */
+ /* Replace WORD or QWORD x by a small caps version, based on word_font(x). */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT DoWord(FULL_CHAR *buff, FULL_CHAR *q, OBJECT x, FONT_NUM fnum)
+ { OBJECT res;
+ *q++ = '\0';
+ res = MakeWord(type(x), buff, &fpos(x));
+ word_font(res) = fnum;
+ word_colour(res) = word_colour(x);
+ word_outline(res) = word_outline(x);
+ word_language(res) = word_language(x);
+ word_hyph(res) = word_hyph(x);
+ underline(res) = UNDER_OFF;
+ return res;
+ } /* end DoWord */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT DoVShift(x, vshift, chld) */
+ /* */
+ /* Make an new VSHIFT object with the given shift and child. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT DoVShift(OBJECT x, FULL_LENGTH vshift, OBJECT chld)
+ { OBJECT res;
+ New(res, VSHIFT);
+ FposCopy(fpos(res), fpos(x));
+ shift_type(res) = GAP_DEC;
+ units(shift_gap(res)) = FIXED_UNIT;
+ mode(shift_gap(res)) = EDGE_MODE;
+ width(shift_gap(res)) = vshift;
+ underline(res) = UNDER_OFF;
+ Link(res, chld);
+ return res;
+ }
+
+ /*****************************************************************************/
+ /* */
+ /* void DoAddGap(new_acat) */
+ /* */
+ /* Add a new 0i gap object to new_acat. */
+ /* */
+ /*****************************************************************************/
+
+ static void DoAddGap(OBJECT new_acat)
+ { OBJECT new_g;
+ New(new_g, GAP_OBJ);
+ FposCopy(fpos(new_g), fpos(new_acat));
+ hspace(new_g) = vspace(new_g) = 0;
+ SetGap(gap(new_g), TRUE, FALSE, TRUE, FIXED_UNIT, EDGE_MODE, 0*IN);
+ underline(new_g) = UNDER_OFF;
+ Link(new_acat, new_g);
+ }
+
+ /*@::MapSmallCaps()@**********************************************************/
+ /* */
+ /* OBJECT MapSmallCaps(x, style) */
+ /* */
+ /* Replace WORD or QWORD x by a small caps version, based on word_font(x). */
+ /* */
+ /*****************************************************************************/
+ #define INIT 0
+ #define ALL_NON 1
+ #define ALL_TRANS 2
+ #define MIXED_NON 3
+ #define MIXED_TRANS 4
+ #define transformable(ch) (uc[ch] != '\0')
+
+ OBJECT MapSmallCaps(OBJECT x, STYLE *style)
+ { MAPPING m; int i; OBJECT new_y, new_x, new_acat, tmp;
+ FULL_CHAR buff[MAX_BUFF], *uc, *p, *q;
+ FONT_NUM small_font; FULL_LENGTH vshift; int state; STYLE new_style;
+ static OBJECT font_change_word = nilobj;
+ assert( is_word(type(x)), "MapSmallCaps: !is_word(type(x))" );
+ debug2(DCM, D, "MapSmallCaps(%s %s)", Image(type(x)), string(x));
+
+ /* get the mapping and return if there isn't one for this font */
+ m = FontMapping(font_num(x), &fpos(x));
+ if( m == 0 )
+ { debug0(DCM, D, "MapSmallCaps returning unchanged (mapping is 0)");
+ return x;
+ }
+ assert( 1 <= m && m < maptop, "MapSmallCaps: mapping out of range!" );
+ uc = MapTable[m]->map[MAP_UPPERCASE];
+
+ /* if plain text, apply the mapping and exit */
+ if( !(BackEnd->scale_avail) )
+ {
+ for( i = 0; string(x)[i] != '\0'; i++ )
+ if( uc[string(x)[i]] != '\0' )
+ string(x)[i] = uc[string(x)[i]];
+ debug1(DCM, D, "MapSmallCaps returning (plain text) %s", EchoObject(x));
+ return x;
+ }
+
+ /* set up the font change word if not already done */
+ if( font_change_word == nilobj )
+ { font_change_word = MakeWord(WORD, AsciiToFull("0.7f"), no_fpos);
+ }
+
+ state = INIT; q = buff;
+ for( p = string(x); *p != '\0'; p++ )
+ {
+ debug2(DCM, DD, " examining %c (%s)", *p,
+ transformable(*p) ? "transformable" : "not transformable");
+ switch( state )
+ {
+ case INIT:
+
+ /* this state is for when we are at the first character */
+ if( transformable(*p) )
+ { *q++ = uc[*p];
+
+ /* work out what the smaller font is going to be, and the vshift */
+ StyleCopy(new_style, *style);
+ FontChange(&new_style, font_change_word);
+ small_font = font(new_style);
+ vshift = FontHalfXHeight(word_font(x)) - FontHalfXHeight(small_font);
+
+ state = ALL_TRANS;
+ }
+ else
+ { *q++ = *p;
+ state = ALL_NON;
+ }
+ break;
+
+
+ case ALL_NON:
+
+ /* in this state, all characters so far are non-transformable */
+ if( transformable(*p) )
+ {
+ /* work out what the smaller font is going to be */
+ StyleCopy(new_style, *style);
+ FontChange(&new_style, font_change_word);
+ small_font = font(new_style);
+ vshift = FontHalfXHeight(word_font(x)) - FontHalfXHeight(small_font);
+
+ /* make a new WORD out of the current contents of buff */
+ new_y = DoWord(buff, q, x, word_font(x));
+
+ /* construct the skeleton of the result to replace x */
+ New(new_x, ONE_COL);
+ FposCopy(fpos(new_x), fpos(x));
+ New(new_acat, ACAT);
+ FposCopy(fpos(new_acat), fpos(x));
+ Link(new_x, new_acat);
+ Link(new_acat, new_y);
+ DoAddGap(new_acat);
+
+ /* start off a new buffer with *p */
+ q = buff;
+ *q++ = uc[*p];
+ state = MIXED_TRANS;
+ }
+ else *q++ = *p;
+ break;
+
+
+ case ALL_TRANS:
+
+ /* in this state, all characters so far are transformable */
+ if( transformable(*p) ) *q++ = uc[*p];
+ else
+ {
+ /* make a new @VShift WORD out of the current contents of buff */
+ tmp = DoWord(buff, q, x, small_font);
+ new_y = DoVShift(x, vshift, tmp);
+
+ /* construct the skeleton of the result to replace x */
+ New(new_x, ONE_COL);
+ FposCopy(fpos(new_x), fpos(x));
+ New(new_acat, ACAT);
+ FposCopy(fpos(new_acat), fpos(x));
+ Link(new_x, new_acat);
+ Link(new_acat, new_y);
+ DoAddGap(new_acat);
+
+ /* start off a new buffer with *p */
+ q = buff;
+ *q++ = *p;
+ state = MIXED_NON;
+ }
+ break;
+
+
+ case MIXED_NON:
+
+ /* in this state the previous char was non-transformable, but */
+ /* there have been characters before that that were transformable */
+ if( transformable(*p) )
+ {
+ /* make a new WORD out of the current contents of buff */
+ new_y = DoWord(buff, q, x, word_font(x));
+
+ /* link the new word into the growing structure that replaces x */
+ Link(new_acat, new_y);
+ DoAddGap(new_acat);
+
+ /* start off a new buffer with *p */
+ q = buff;
+ *q++ = uc[*p];
+ state = MIXED_TRANS;
+ }
+ else *q++ = *p;
+ break;
+
+
+ case MIXED_TRANS:
+
+ /* in this state the previous char was transformable, but there */
+ /* have been characters before that that were non-transformable */
+ if( transformable(*p) ) *q++ = uc[*p];
+ else
+ {
+ /* make a new @VShift WORD out of the current contents of buff */
+ tmp = DoWord(buff, q, x, small_font);
+ new_y = DoVShift(x, vshift, tmp);
+
+ /* link the new word into the growing structure that replaces x */
+ Link(new_acat, new_y);
+ DoAddGap(new_acat);
+
+ /* start off a new buffer with *p */
+ q = buff;
+ *q++ = *p;
+ state = MIXED_NON;
+ }
+ break;
+
+ }
+ }
+
+ /* now at termination, clean up the structure */
+ switch( state )
+ {
+ case INIT:
+ case ALL_NON:
+
+ /* original x is OK as is: either empty or all non-transformable */
+ break;
+
+
+ case ALL_TRANS:
+
+ /* make a new @VShift WORD and replace x with it */
+ tmp = DoWord(buff, q, x, small_font);
+ new_x = DoVShift(x, vshift, tmp);
+ ReplaceNode(new_x, x);
+ Dispose(x);
+ x = new_x;
+ break;
+
+
+ case MIXED_NON:
+
+ /* make a new WORD, add to new_acat, and replace x */
+ new_y = DoWord(buff, q, x, word_font(x));
+ Link(new_acat, new_y);
+ ReplaceNode(new_x, x);
+ Dispose(x);
+ x = new_x;
+ break;
+
+
+ case MIXED_TRANS:
+
+ /* make a new @VShift WORD, add to new_acat, and replace x */
+ tmp = DoWord(buff, q, x, small_font);
+ new_y = DoVShift(x, vshift, tmp);
+ Link(new_acat, new_y);
+ ReplaceNode(new_x, x);
+ Dispose(x);
+ x = new_x;
+ break;
+ }
+ debug1(DCM, D, "MapSmallCaps returning %s", EchoObject(x));
+ return x;
+ } /* end MapSmallCaps */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN MapIsLowerCase(FULL_CHAR ch, MAPPING m) */
+ /* */
+ /* Returns TRUE if ch is a lower-case character in mapping m; i.e. if it */
+ /* has a corresponding upper-case character. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN MapIsLowerCase(FULL_CHAR ch, MAPPING m)
+ { BOOLEAN res;
+ debug2(DCM, D, "MapIsLowerCase(%c, %d)", ch, m);
+ res = (MapTable[m]->map[MAP_UPPERCASE][ch] != '\0');
+ debug1(DCM, D, "MapIsLowerCase returning %s", bool(res));
+ return res;
+ } /* end MapIsLowerCase */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z39.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z39.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z39.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,236 ----
+ /*@z39.c:String Handler:AsciiToFull(), StringEqual(), etc.@*******************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z39.c */
+ /* MODULE: String Handler */
+ /* EXTERNS: AsciiToFull(), StringEqual(), */
+ /* StringCat(), StringCopy(), StringLength(), */
+ /* StringFOpen(), StringFPuts(), StringFGets(), */
+ /* StringRemove(), StringRename(), StringBeginsWith(), */
+ /* StringContains(), StringInt(), StringFiveInt(), */
+ /* StringQuotedWord() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* AsciiToFull(str) Returns ASCII string as FULL_CHARs. */
+ /* BOOLEAN StringEqual(a, b) TRUE if strings a and b are equal */
+ /* StringCat(a, b) Catenate string b onto end of a */
+ /* StringCopy(a, b) Overwrite string a with string b */
+ /* StringLength(a) Length of string a */
+ /* StringFOpen(str, mode) Equivalent to fopen(str, mode) */
+ /* StringFPuts(str, fp) Equivalent to fputs(str, fp) */
+ /* StringFGets(str, n, fp) Equivalent to fgets(str, n, fp) */
+ /* StringRemove(a) Equivalent to remove(a) */
+ /* StringRename(a, b) Equivalent to rename(a, b) */
+ /* */
+ /* These procedures are defined as macros in file externs. */
+ /* */
+ /*****************************************************************************/
+
+
+ /*****************************************************************************/
+ /* */
+ /* int strcollcmp(char *a, char *b) */
+ /* */
+ /* Written by Valery Ushakov (uwe). */
+ /* */
+ /* Like strcoll, but returns 0 only iff strcmp returns 0. */
+ /* This allow to test for equality using only strcmp. --uwe */
+ /* */
+ /* The new version of strcollcmp analyses a and b into three fields */
+ /* separated by \t, then does the comparison field by field. This is */
+ /* to ensure that the collation order of \t has no effect on the result. */
+ /* */
+ /*****************************************************************************/
+
+ /* *** old version
+ int strcollcmp(char *a, char *b)
+ {
+ int order = strcoll (a, b);
+ if( order == 0 ) / * then disambiguate with strcmp * /
+ order = strcmp (a, b);
+ return order;
+ }
+ *** */
+
+ int strcollcmp(char *a, char *b)
+ { char a1[100], b1[100];
+ int order;
+ sscanf(a, "%[^\t]", a1);
+ sscanf(b, "%[^\t]", b1);
+ order = strcoll(a1, b1);
+ if( order == 0 )
+ order = strcmp(a, b); /* disambiguate with strcmp */
+ debug3(DBS, D, "strcollcmp(\"%s<tab>\", \"%s<tab>\") = %d", a1, b1, order)
+ return order;
+ }
+
+ /*@::StringBeginsWith(), StringContains(), StringInt(), StringFiveInt()@******/
+ /* */
+ /* BOOLEAN StringBeginsWith(str, pattern) */
+ /* BOOLEAN StringEndsWith(str, pattern) */
+ /* */
+ /* Check whether str begins with or ends with pattern. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN StringBeginsWith(FULL_CHAR *str, FULL_CHAR *pattern)
+ { FULL_CHAR *sp, *pp;
+ sp = str; pp = pattern;
+ while( *sp != '\0' && *pp != '\0' )
+ { if( *sp++ != *pp++ ) return FALSE;
+ }
+ return (*pp == '\0');
+ } /* end StringBeginsWith */
+
+
+ BOOLEAN StringEndsWith(FULL_CHAR *str, FULL_CHAR *pattern)
+ { FULL_CHAR *sp, *pp; int slen, plen;
+ slen = StringLength(str);
+ plen = StringLength(pattern);
+ if( slen < plen ) return FALSE;
+ sp = &str[slen - plen]; pp = pattern;
+ while( *sp != '\0' && *pp != '\0' )
+ { if( *sp++ != *pp++ ) return FALSE;
+ }
+ return (*pp == '\0');
+ } /* end StringBeginsWith */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN StringContains(str, pattern) */
+ /* */
+ /* Check whether str contains pattern. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN StringContains(FULL_CHAR *str, FULL_CHAR *pattern)
+ { FULL_CHAR *sp;
+ for( sp = str; *sp != '\0'; sp++ )
+ { if( StringBeginsWith(sp, pattern) ) return TRUE;
+ }
+ return FALSE;
+ } /* end StringContains */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *StringInt(i) */
+ /* FULL_CHAR *StringFiveInt(i) */
+ /* */
+ /* Returns a string version of integer i. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *StringInt(int i)
+ { static FULL_CHAR buff[20];
+ sprintf( (char *) buff, "%d", i);
+ return buff;
+ } /* end StringInt */
+
+ FULL_CHAR *StringFiveInt(int i)
+ { static FULL_CHAR buff[20];
+ sprintf( (char *) buff, "%.5d", i);
+ return buff;
+ } /* end StringInt */
+
+
+ /*@::StringQuotedWord()@******************************************************/
+ /* */
+ /* static char *quoted_string[] */
+ /* */
+ /* quoted_string[ch] is a string containing the representation of the */
+ /* 8-bit character ch within a quoted string in a Lout source file. */
+ /* */
+ /*****************************************************************************/
+
+ static char *quoted_string[] = {
+ "\\000", "\\001", "\\002", "\\003", "\\004", "\\005", "\\006", "\\007",
+ "\\010", "\\011", "\\012", "\\013", "\\014", "\\015", "\\016", "\\017",
+ "\\020", "\\021", "\\022", "\\023", "\\024", "\\025", "\\026", "\\027",
+ "\\030", "\\031", "\\032", "\\033", "\\034", "\\035", "\\036", "\\037",
+ " ", "!", "\\\"", "#", "$", "%", "&", "'",
+ "(", ")", "*", "+", ",", "-", ".", "/",
+ "0", "1", "2", "3", "4", "5", "6", "7",
+ "8", "9", ":", ";", "<", "=", ">", "?",
+
+ "@", "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", "[", "\\\\", "]", "^", "_",
+ "`", "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", "{", "|", "}", "~", "\\177",
+
+ "\\200", "\\201", "\\202", "\\203", "\\204", "\\205", "\\206", "\\207",
+ "\\210", "\\211", "\\212", "\\213", "\\214", "\\215", "\\216", "\\217",
+ "\\220", "\\221", "\\222", "\\223", "\\224", "\\225", "\\226", "\\227",
+ "\\230", "\\231", "\\232", "\\233", "\\234", "\\235", "\\236", "\\237",
+ "\\240", "\\241", "\\242", "\\243", "\\244", "\\245", "\\246", "\\247",
+ "\\250", "\\251", "\\252", "\\253", "\\254", "\\255", "\\256", "\\257",
+ "\\260", "\\261", "\\262", "\\263", "\\264", "\\265", "\\266", "\\267",
+ "\\270", "\\271", "\\272", "\\273", "\\274", "\\275", "\\276", "\\277",
+
+ "\\300", "\\301", "\\302", "\\303", "\\304", "\\305", "\\306", "\\307",
+ "\\310", "\\311", "\\312", "\\313", "\\314", "\\315", "\\316", "\\317",
+ "\\320", "\\321", "\\322", "\\323", "\\324", "\\325", "\\326", "\\327",
+ "\\330", "\\331", "\\332", "\\333", "\\334", "\\335", "\\336", "\\337",
+ "\\340", "\\341", "\\342", "\\343", "\\344", "\\345", "\\346", "\\347",
+ "\\350", "\\351", "\\352", "\\353", "\\354", "\\355", "\\356", "\\357",
+ "\\360", "\\361", "\\362", "\\363", "\\364", "\\365", "\\366", "\\367",
+ "\\370", "\\371", "\\372", "\\373", "\\374", "\\375", "\\376", "\\377",
+ };
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *StringQuotedWord(x) */
+ /* */
+ /* Returns the string in QWORD x in the form it would need to take if it */
+ /* was a quoted word in a Lout source file. Note that the result is */
+ /* returned in a static variable so it needs to be copied before a */
+ /* subsequent call to StringQuotedWord is made. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *StringQuotedWord(OBJECT x)
+ { FULL_CHAR *p, *q, *r;
+ static FULL_CHAR buff[MAX_BUFF];
+ assert( type(x) == QWORD, "StringQuotedWord: type(x) != QWORD!" );
+ q = buff;
+ *q++ = CH_QUOTE;
+ for( p = string(x); *p != '\0'; p++ )
+ {
+ for( r = (FULL_CHAR *) quoted_string[*p]; *r != '\0'; *q++ = *r++ );
+ }
+ *q++ = CH_QUOTE;
+ *q++ = '\0';
+ return buff;
+ } /* StringQuotedWord */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z40.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z40.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z40.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,267 ----
+ /*@z40.c:Filter Handler:FilterInit()@*****************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z40.c */
+ /* MODULE: Filter Handler */
+ /* EXTERNS: FilterInit(), FilterCreate(), FilterSetFileNames(), */
+ /* FilterExecute(), FilterWrite(), FilterScavenge() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ static int filter_count; /* number of filter files */
+ static OBJECT filter_active; /* the active filter file records */
+ static OBJECT filter_in_filename; /* initial name of filter input file */
+ static OBJECT filter_out_filename; /* initial name of filter ouput file */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FilterInit() */
+ /* */
+ /* Initialize this module. */
+ /* */
+ /*****************************************************************************/
+
+ void FilterInit(void)
+ { filter_count = 0;
+ New(filter_active, ACAT);
+ sym_body(FilterInSym) = MakeWord(WORD, FILTER_IN, no_fpos);
+ sym_body(FilterOutSym) = MakeWord(WORD, FILTER_OUT, no_fpos);
+ sym_body(FilterErrSym) = MakeWord(WORD, FILTER_ERR, no_fpos);
+ filter_in_filename = sym_body(FilterInSym);
+ filter_out_filename = sym_body(FilterOutSym);
+ } /* end FilterInit */
+
+
+ /*@::FilterCreate(), FilterSetFileNames()@************************************/
+ /* */
+ /* OBJECT FilterCreate(use_begin, act, xfpos) */
+ /* */
+ /* Create and return a new FILTERED object. Open the corresponding file */
+ /* for writing and dump the parameter text to be filtered into it. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT FilterCreate(BOOLEAN use_begin, OBJECT act, FILE_POS *xfpos)
+ { FULL_CHAR buff[MAX_LINE]; FILE *fp; OBJECT x, res, junk;
+ debug3(DFH, D, "FilterCreate(%s, %s, %s)", bool(use_begin),
+ SymName(act), EchoFilePos(xfpos));
+ New(res, FILTERED);
+ FposCopy(fpos(res), *xfpos);
+ ++filter_count;
+ sprintf( (char *) buff, "%s%d", FILTER_IN, filter_count);
+ fp = StringFOpen(buff, WRITE_TEXT);
+ if( fp == NULL )
+ Error(40, 1, "cannot open temporary filter file %s", FATAL, xfpos, buff);
+ x = MakeWord(WORD, buff, xfpos);
+ filter_use_begin(x) = use_begin;
+ filter_actual(x) = act;
+ Link(res, x);
+ Link(filter_active, x);
+ junk = LexScanVerbatim(fp, use_begin, xfpos, FALSE);
+ fclose(fp);
+ sprintf( (char *) buff, "%s%d", FILTER_OUT, filter_count);
+ x = MakeWord(WORD, buff, xfpos);
+ Link(res, x);
+ if( has_body(act) ) PushScope(act, FALSE, TRUE);
+ x = GetScopeSnapshot();
+ if( has_body(act) ) PopScope();
+ Link(res, x);
+ debug2(DFH, D, "FilterCreate returning %d %s", (int) res, EchoObject(res));
+ return res;
+ } /* end FilterCreate */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FilterSetFileNames(x) */
+ /* */
+ /* Set @FilterIn, @FilterOut, and @FilterErr to suitable values for the */
+ /* manifesting of the command which runs filter x. */
+ /* */
+ /*****************************************************************************/
+
+ void FilterSetFileNames(OBJECT x)
+ { OBJECT y;
+ assert( type(x) == FILTERED, "FilterSetFileNames: type(x)!" );
+ assert( Down(x) != x, "FilterSetFileNames: x has no children!" );
+ debug2(DFH, D, "FilterSetFileNames(%d %s)", (int) x, EchoObject(x));
+ Child(y, Down(x));
+ assert( type(y) == WORD, "FilterSetFileNames: type(y)!" );
+ sym_body(FilterInSym) = y;
+ Child(y, NextDown(Down(x)));
+ assert( type(y) == WORD, "FilterSetFileNames: type(y) (2)!" );
+ sym_body(FilterOutSym) = y;
+ debug0(DFH, D, "FilterSetFileNames returning.");
+ } /* end FilterSetFileNames */
+
+
+ /*@::FilterExecute()@*********************************************************/
+ /* */
+ /* OBJECT FilterExecute(x, command, env) */
+ /* */
+ /* Execute the filter command on FILTERED object x, and return the result. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT FilterExecute(OBJECT x, FULL_CHAR *command, OBJECT env)
+ { int status; OBJECT t, res, scope_snapshot; char line[MAX_LINE];
+ FILE *err_fp; FILE_NUM filter_out_file;
+
+ assert( type(x) == FILTERED, "FilterExecute: type(x)!" );
+ assert( type(env) == ENV, "FilterExecute: type(env)!" );
+ debug4(DFH, D, "FilterExecute(%d %s, \"%s\", %s)", (int) x, EchoObject(x),
+ command, EchoObject(env));
+
+ /* reset FilterInSym since Manifest of @Filter is now complete */
+ sym_body(FilterInSym) = filter_in_filename;
+
+ if( SafeExecution )
+ {
+ /* if safe execution, print error message and return empty object */
+ Error(40, 2, "safe execution prohibiting command: %s", WARN, &fpos(x),
+ command);
+ res = MakeWord(WORD, STR_EMPTY, &fpos(x));
+ }
+ else
+ {
+ /* execute the command, echo error messages, and exit if status problem */
+ status = system( (char *) command);
+ err_fp = StringFOpen(FILTER_ERR, READ_TEXT);
+ if( err_fp != NULL )
+ { while( fgets(line, MAX_LINE, err_fp) != NULL )
+ { if( line[strlen(line)-1] == '\n' )
+ line[strlen(line)-1] = '\0';
+ Error(40, 3, "%s", WARN, &fpos(x), line);
+ }
+ fclose(err_fp);
+ StringRemove(FILTER_ERR);
+ }
+ if( status != 0 )
+ Error(40, 4, "failure (non-zero status) of filter: %s",
+ FATAL, &fpos(x), command);
+
+ /* read in output of system command as a Lout object */
+ /* *** using scope snapshot now
+ SwitchScope(nilobj);
+ count = 0;
+ SetScope(env, &count, TRUE);
+ *** */
+ Child(scope_snapshot, LastDown(x));
+ LoadScopeSnapshot(scope_snapshot);
+ debug0(DFS, D, " calling DefineFile from FilterExecute");
+ filter_out_file =
+ DefineFile(string(sym_body(FilterOutSym)), STR_EMPTY, &fpos(x),
+ FILTER_FILE, SOURCE_PATH);
+ LexPush(filter_out_file, 0, FILTER_FILE, 1, FALSE);
+ t = NewToken(BEGIN, &fpos(x), 0, 0, BEGIN_PREC, FilterOutSym);
+ res = Parse(&t, nilobj, FALSE, FALSE);
+ LexPop();
+ /* *** using scope snapshot now
+ for( i = 1; i <= count; i++ ) PopScope();
+ UnSwitchScope(nilobj);
+ *** */
+ ClearScopeSnapshot(scope_snapshot);
+ StringRemove(string(sym_body(FilterOutSym)));
+ sym_body(FilterOutSym) = filter_out_filename;
+ }
+
+ debug1(DFH, D, "FilterExecute returning %s", EchoObject(res));
+ return res;
+ } /* end FilterExecute */
+
+
+ /*@::FilterWrite(), FilterScavenge()@*****************************************/
+ /* */
+ /* FilterWrite(x, fp, linecount) */
+ /* */
+ /* Write out the active FILTERED object x by copying the file. */
+ /* Increment *linecount by the number of lines written. */
+ /* */
+ /*****************************************************************************/
+
+ void FilterWrite(OBJECT x, FILE *fp, int *linecount)
+ { FILE *in_fp; OBJECT y; int ch;
+ assert( type(x) == FILTERED, "FilterWrite: type(x)!" );
+ debug2(DFH, D, "[ FilterWrite(%d %s, fp)", (int) x, EchoObject(x));
+ Child(y, Down(x));
+ in_fp = StringFOpen(string(y), READ_TEXT);
+ if( in_fp == NULL )
+ Error(40, 5, "cannot read filter temporary file %s",
+ FATAL, &fpos(x), string(y));
+ if( filter_use_begin(y) )
+ { StringFPuts(KW_BEGIN, fp);
+ StringFPuts("\n", fp);
+ *linecount += 1;
+ while( (ch = getc(in_fp)) != EOF )
+ { putc(ch, fp);
+ if( ch == '\n' ) *linecount += 1;
+ }
+ StringFPuts(KW_END, fp);
+ StringFPuts(" ", fp);
+ StringFPuts(SymName(filter_actual(y)), fp);
+ }
+ else
+ { StringFPuts(KW_LBR, fp);
+ StringFPuts("\n", fp);
+ *linecount += 1;
+ while( (ch = getc(in_fp)) != EOF )
+ { putc(ch, fp);
+ ifdebug(DFH, D, putc(ch, stderr));
+ if( ch == '\n' ) *linecount += 1;
+ }
+ StringFPuts(KW_RBR, fp);
+ }
+ StringFPuts("\n", fp);
+ *linecount += 1;
+ fclose(in_fp);
+ debug0(DFH, D, "] FilterWrite returning.");
+ } /* end FilterWrite */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FilterScavenge(all) */
+ /* */
+ /* Unlink unneeded filter files, or all remaining filter files if all. */
+ /* */
+ /*****************************************************************************/
+
+ void FilterScavenge(BOOLEAN all)
+ { OBJECT y, link, nextlink;
+ ifdebug(DFH, D, return);
+ debug1(DFH, D, "FilterScavenge(%s)", bool(all));
+ for( link = Down(filter_active); link != filter_active; link = nextlink )
+ { Child(y, link);
+ nextlink = NextDown(link);
+ if( all || Up(y) == LastUp(y) )
+ { debug1(DFH, D, "FilterScavenge scavenging %s", string(y));
+ StringRemove(string(y));
+ DisposeChild(link);
+ }
+ }
+ debug0(DFH, D, "FilterScavenge returning.");
+ } /* end FilterScavenge */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z41.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z41.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z41.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,730 ----
+ /*@z41.c:Object Input-Output:AppendToFile, ReadFromFile@**********************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z41.c */
+ /* MODULE: Object Input-Output */
+ /* EXTERNS: ReadFromFile(), AppendToFile(), CloseFiles() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ static FILE_NUM last_write_fnum = NO_FILE;
+ static FILE *last_write_fp = null;
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT ReadFromFile(fnum, pos, lnum) */
+ /* */
+ /* Read an object from file fnum starting at position pos. */
+ /* The object may include @Env operators defining its environment, or */
+ /* not, but in any case ReadFromFile assumes that the correct scope is set. */
+ /* lnum is the line number of the spot you end up at when you seek to pos. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT ReadFromFile(FILE_NUM fnum, long pos, int lnum)
+ { OBJECT t, res;
+ #if DEBUG_ON
+ int ipos;
+ #endif
+ ifdebug(DPP, D, ProfileOn("ReadFromFile"));
+ ifdebug(DIO, D, ipos = (int) pos);
+ debug3(DIO, D, "ReadFromFile(%s, %d, %d)", FileName(fnum), ipos, lnum);
+ LexPush(fnum, (int) pos, DATABASE_FILE, lnum, FALSE);
+ t = LexGetToken();
+ if( type(t) != LBR )
+ { debug1(DIO, D, " following because type(t) = %s", Image(type(t)));
+ Error(41, 1, "database index file seems to be out of date",
+ FATAL, &fpos(t));
+ }
+ res = Parse(&t, StartSym, FALSE, FALSE);
+ if( t != nilobj || type(res) != CLOSURE )
+ { debug1(DIO, D, " following because of %s", t!=nilobj ? "t" : "type(res)");
+ Error(41, 2, "syntax error in database file", FATAL, &fpos(res));
+ }
+ LexPop();
+ debug1(DIO, D, "ReadFromFile returning %s", EchoObject(res));
+ ifdebug(DPP, D, ProfileOff("ReadFromFile"));
+ return res;
+ } /* end ReadFromFile */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static Optimize(x, env) */
+ /* */
+ /*****************************************************************************/
+ static void OptimizeParameterList(OBJECT x, OBJECT env);
+
+ static void Optimize(OBJECT x, OBJECT env)
+ { OBJECT tmp;
+ if( Down(x) != x )
+ { OptimizeParameterList(x, env);
+ }
+ tmp = ParameterCheck(x, env);
+ if( tmp != nilobj )
+ { ReplaceNode(tmp, x);
+ DisposeObject(x);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* OptimizeParameterList(x, env) */
+ /* */
+ /* Optimize the space required to print the parameters of x by evaluating */
+ /* them in environment env if this is feasible. */
+ /* */
+ /*****************************************************************************/
+
+ static void OptimizeParameterList(OBJECT x, OBJECT env)
+ { OBJECT y, z, link, t, tlink;
+ assert( type(x) == CLOSURE, "OptimizeParameterList: type(x) != CLOSURE!" );
+ if( env == nilobj ) return;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == PAR )
+ { Child(z, Down(y));
+ if( type(z) == CLOSURE )
+ {
+ Optimize(z, env);
+ }
+ else if( type(z) == ACAT )
+ { for( tlink = Down(z); tlink != z; tlink = NextDown(tlink) )
+ { Child(t, Down(tlink));
+ if( type(t) == CLOSURE )
+ Optimize(t, env);
+ }
+ }
+ }
+ }
+ } /* end OptimizeParameter */
+
+
+ /*@::WriteClosure()@**********************************************************/
+ /* */
+ /* static WriteClosure(x, linecount, fnum, env) */
+ /* */
+ /* Write closure x to file last_write_fp, without enclosing braces and */
+ /* without any environment attached. If x happens to be a closure that */
+ /* was previously read as a @Use clause, write only @LUse and the name. */
+ /* Increment *linecount by the number of lines written. */
+ /* The file being written to is fnum; the environment is env (for optim.) */
+ /* */
+ /*****************************************************************************/
+ static void WriteObject(OBJECT x, int outer_prec, int *linecount, FILE_NUM fnum);
+
+ static BOOLEAN need_lvis(OBJECT sym) /* true if @LVis needed before sym */
+ { return !visible(sym) &&
+ enclosing(sym) != StartSym &&
+ type(enclosing(sym)) == LOCAL;
+ } /* end need_lvis */
+
+ static void WriteClosure(OBJECT x, int *linecount, FILE_NUM fnum, OBJECT env)
+ { OBJECT y, link, z, sym;
+ BOOLEAN npar_written, name_printed;
+ debug2(DIO, D, "[ WriteClosure(%s %s)", Image(type(x)), EchoObject(x));
+
+ sym = actual(x);
+ /* *** if( use_invocation(sym) == x ) *** */
+ if( use_invocation(sym) != nilobj )
+ { StringFPuts(KW_LUSE, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(SymName(sym), last_write_fp);
+ }
+ else
+ { npar_written = FALSE; name_printed = FALSE;
+ OptimizeParameterList(x, env);
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == PAR ) switch( type(actual(y)) )
+ {
+ case LPAR:
+
+ assert( Down(y) != y, "WriteObject/CLOSURE: LPAR!" );
+ Child(z, Down(y));
+ WriteObject(z, (int) precedence(sym), linecount, fnum);
+ StringFPuts(STR_SPACE, last_write_fp);
+ break;
+
+
+ case NPAR:
+
+ assert( Down(y) != y, "WriteObject/CLOSURE: NPAR!" );
+ Child(z, Down(y));
+ if( !name_printed )
+ { if( need_lvis(sym) )
+ { StringFPuts(KW_LVIS, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ }
+ StringFPuts(SymName(sym), last_write_fp);
+ name_printed = TRUE;
+ }
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+
+ if( npar_code(actual(y)) != ' ' )
+ { StringFPuts(STR_ESCAPE, last_write_fp);
+ fprintf(last_write_fp, "%c", (char) npar_code(actual(y)));
+ }
+ else
+ { StringFPuts(SymName(actual(y)), last_write_fp);
+ }
+
+ StringFPuts(KW_LBR, last_write_fp);
+ WriteObject(z, NO_PREC, linecount, fnum);
+ StringFPuts(KW_RBR, last_write_fp);
+ npar_written = TRUE;
+ break;
+
+
+ case RPAR:
+
+ assert( Down(y) != y, "WriteObject/CLOSURE: RPAR!" );
+ Child(z, Down(y));
+ if( !name_printed )
+ { if( need_lvis(sym) )
+ { StringFPuts(KW_LVIS, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ }
+ StringFPuts(SymName(sym), last_write_fp);
+ name_printed = TRUE;
+ }
+ if( npar_written )
+ { StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+ else
+ { StringFPuts(STR_SPACE, last_write_fp);
+ }
+ /* old version: if( filter(sym) != nilobj ) */
+ if( filter(sym) != nilobj && type(z) == FILTERED ) /* ??? */
+ {
+ debug1(DIO, D, " filter(sym) != nilobj, type(z) == %s",
+ Image(type(z)));
+ assert( type(z) == FILTERED, "WriteClosure: filter!" );
+ WriteObject(z, NO_PREC, linecount, fnum);
+ }
+ else if( has_body(sym) )
+ {
+ StringFPuts(KW_LBR, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ WriteObject(z, NO_PREC, linecount, fnum);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_RBR, last_write_fp);
+ }
+ else WriteObject(z, (int) precedence(sym), linecount, fnum);
+ break;
+
+
+ default:
+
+ assert1(FALSE, "WriteClosure:", Image(type(actual(y))));
+ break;
+
+ } /* end switch */
+ } /* end for each parameter */
+ if( !name_printed )
+ { if( need_lvis(sym) )
+ { StringFPuts(KW_LVIS, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ }
+ StringFPuts(SymName(sym), last_write_fp);
+ name_printed = TRUE;
+ }
+ }
+ debug0(DIO, D, "] WriteClosure returning");
+ } /* end WriteClosure */
+
+
+ /*@::WriteObject()@***********************************************************/
+ /* */
+ /* static WriteObject(x, outer_prec, linecount, fnum) */
+ /* */
+ /* Write object x to file last_write_fp, assuming it is a subobject of an */
+ /* object and the precedence of operators enclosing it is outer_prec. */
+ /* Increment *linecount by the number of lines written. */
+ /* The file being written to is fnum. */
+ /* */
+ /*****************************************************************************/
+
+ static void WriteObject(OBJECT x, int outer_prec, int *linecount, FILE_NUM fnum)
+ { OBJECT link, y, z, gap_obj, sym, env; FULL_CHAR *name; int offset, lnum;
+ int prec, i, last_prec; BOOLEAN braces_needed;
+ debug2(DIO, D, "[ WriteObject(%s %s)", Image(type(x)), EchoObject(x));
+ switch( type(x) )
+ {
+
+ case WORD:
+
+ if( StringLength(string(x)) == 0 && outer_prec > ACAT_PREC )
+ { StringFPuts(KW_LBR, last_write_fp);
+ StringFPuts(KW_RBR, last_write_fp);
+ }
+ else StringFPuts(string(x), last_write_fp);
+ break;
+
+
+ case QWORD:
+
+ StringFPuts(StringQuotedWord(x), last_write_fp);
+ break;
+
+
+ case VCAT: prec = VCAT_PREC; goto ETC;
+ case HCAT: prec = HCAT_PREC; goto ETC;
+ case ACAT: prec = ACAT_PREC; goto ETC;
+
+ ETC:
+ if( prec < outer_prec ) StringFPuts(KW_LBR, last_write_fp);
+ last_prec = prec;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ )
+ { if( Down(y) == y )
+ { assert( type(x) == ACAT, "WriteObject: Down(y) == y!" );
+ for( i = 1; i <= vspace(y); i++ )
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += vspace(y);
+ for( i = 1; i <= hspace(y); i++ )
+ StringFPuts(STR_SPACE, last_write_fp);
+ last_prec = (vspace(y) + hspace(y) == 0) ? JUXTA_PREC : ACAT_PREC;
+ }
+ else
+ { Child(gap_obj, Down(y));
+ if( type(x)==ACAT )
+ StringFPuts(STR_SPACE, last_write_fp);
+ else
+ { StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+ StringFPuts(EchoCatOp(type(x), mark(gap(y)), join(gap(y))),
+ last_write_fp);
+ if( !is_word(type(gap_obj)) || StringLength(string(gap_obj)) != 0 )
+ WriteObject(gap_obj, FORCE_PREC, linecount, fnum);
+ StringFPuts(STR_SPACE, last_write_fp);
+ last_prec = prec;
+ }
+ }
+ else
+ { if( type(x) == ACAT )
+ { OBJECT next_gap; int next_prec;
+ if( NextDown(link) != x )
+ { Child(next_gap, NextDown(link));
+ assert( type(next_gap) == GAP_OBJ, "WriteObject: next_gap!" );
+ next_prec = (vspace(next_gap) + hspace(next_gap) == 0)
+ ? JUXTA_PREC : ACAT_PREC;
+ }
+ else next_prec = prec;
+ WriteObject(y, find_max(last_prec, next_prec), linecount, fnum);
+ }
+ else WriteObject(y, prec, linecount, fnum);
+ }
+ }
+ if( prec < outer_prec ) StringFPuts(KW_RBR, last_write_fp);
+ break;
+
+
+ case ENV:
+
+ if( Down(x) == x )
+ {
+ /* environment is empty */
+ StringFPuts(KW_ENVC, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+ else if( EnvWriteRetrieve(x, fnum, &offset, &lnum) )
+ {
+ /* environment was previously written to this file */
+ StringFPuts(KW_ENVD, last_write_fp);
+ fprintf(last_write_fp, " \"%d %d\"", offset, lnum);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+ else
+ {
+ /* record the position of this environment */
+ EnvWriteInsert(x, fnum, (int) ftell(last_write_fp), *linecount);
+
+ /* write the environment */
+ if( Down(x) == LastDown(x) )
+ {
+ /* envt contains just one closure (with its environment) */
+ Child(y, Down(x));
+ assert( type(y) == CLOSURE, "WriteObject: ENV/CLOSURE!" );
+ StringFPuts(KW_LBR, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_ENVA, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_LBR, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ WriteObject(y, NO_PREC, linecount, fnum);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_RBR, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_RBR, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+ else
+ {
+ /* envt contains a closure (with envt) plus an environment */
+ Child(env, LastDown(x));
+ assert( type(env) == ENV, "WriteObject: ENV/ENV!" );
+ StringFPuts(KW_LBR, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_ENVB, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_LBR, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ WriteObject(env, NO_PREC, linecount, fnum);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_RBR, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ Child(y, Down(x));
+ assert( type(y) == CLOSURE, "WriteObject: ENV/ENV+CLOSURE!" );
+ StringFPuts(KW_LBR, last_write_fp);
+ WriteObject(y, NO_PREC, linecount, fnum);
+ StringFPuts(KW_RBR, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_RBR, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+ }
+ break;
+
+
+ case CLOSURE:
+
+ sym = actual(x); env = nilobj;
+ if( LastDown(x) != x )
+ { Child(y, LastDown(x));
+ if( type(y) == ENV ) env = y;
+ }
+
+ braces_needed = env != nilobj ||
+ (precedence(sym) <= outer_prec && (has_lpar(sym) || has_rpar(sym))) ||
+ outer_prec >= JUXTA_PREC;
+
+ /* print environment */
+ if( env != nilobj )
+ { StringFPuts(KW_CENV, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_LBR, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ WriteObject(env, NO_PREC, linecount, fnum);
+ StringFPuts(KW_RBR, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+
+ /* print left brace if needed */
+ if( braces_needed ) StringFPuts(KW_LBR, last_write_fp);
+
+ /* print the closure proper */
+ WriteClosure(x, linecount, fnum, env);
+
+ /* print closing brace if needed */
+ if( braces_needed ) StringFPuts(KW_RBR, last_write_fp);
+
+ /* print closing environment if needed */
+ /* ***
+ if( env != nilobj )
+ { StringFPuts(KW_RBR, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+ *** */
+ break;
+
+
+ case CROSS:
+ case FORCE_CROSS:
+
+ Child(y, Down(x));
+ assert( type(y) == CLOSURE, "WriteObject/CROSS: type(y) != CLOSURE!" );
+ if( DEFAULT_PREC <= outer_prec ) StringFPuts(KW_LBR, last_write_fp);
+ if( need_lvis(actual(y)) )
+ { StringFPuts(KW_LVIS, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ }
+ StringFPuts(SymName(actual(y)), last_write_fp);
+ StringFPuts(type(x) == CROSS ? KW_CROSS : KW_FORCE_CROSS, last_write_fp);
+ Child(y, LastDown(x));
+ WriteObject(y, FORCE_PREC, linecount, fnum);
+ if( DEFAULT_PREC <= outer_prec ) StringFPuts(KW_RBR, last_write_fp);
+ break;
+
+
+ case NULL_CLOS: name = KW_NULL; goto SETC;
+ case PAGE_LABEL: name = KW_PAGE_LABEL; goto SETC;
+ case BEGIN_HEADER: name = KW_BEGIN_HEADER; goto SETC;
+ case END_HEADER: name = KW_END_HEADER; goto SETC;
+ case SET_HEADER: name = KW_SET_HEADER; goto SETC;
+ case CLEAR_HEADER: name = KW_CLEAR_HEADER; goto SETC;
+ case ONE_COL: name = KW_ONE_COL; goto SETC;
+ case ONE_ROW: name = KW_ONE_ROW; goto SETC;
+ case WIDE: name = KW_WIDE; goto SETC;
+ case HIGH: name = KW_HIGH; goto SETC;
+ case HSHIFT: name = KW_HSHIFT; goto SETC;
+ case VSHIFT: name = KW_VSHIFT; goto SETC;
+ case HSCALE: name = KW_HSCALE; goto SETC;
+ case VSCALE: name = KW_VSCALE; goto SETC;
+ case HCOVER: name = KW_HCOVER; goto SETC;
+ case VCOVER: name = KW_VCOVER; goto SETC;
+ case SCALE: name = KW_SCALE; goto SETC;
+ case KERN_SHRINK: name = KW_KERN_SHRINK; goto SETC;
+ case HCONTRACT: name = KW_HCONTRACT; goto SETC;
+ case VCONTRACT: name = KW_VCONTRACT; goto SETC;
+ case HLIMITED: name = KW_HLIMITED; goto SETC;
+ case VLIMITED: name = KW_VLIMITED; goto SETC;
+ case HEXPAND: name = KW_HEXPAND; goto SETC;
+ case VEXPAND: name = KW_VEXPAND; goto SETC;
+ case START_HVSPAN: name = KW_STARTHVSPAN; goto SETC;
+ case START_HSPAN: name = KW_STARTHSPAN; goto SETC;
+ case START_VSPAN: name = KW_STARTVSPAN; goto SETC;
+ case HSPAN: name = KW_HSPAN; goto SETC;
+ case VSPAN: name = KW_VSPAN; goto SETC;
+ case PADJUST: name = KW_PADJUST; goto SETC;
+ case HADJUST: name = KW_HADJUST; goto SETC;
+ case VADJUST: name = KW_VADJUST; goto SETC;
+ case ROTATE: name = KW_ROTATE; goto SETC;
+ case BACKGROUND: name = KW_BACKGROUND; goto SETC;
+ case CASE: name = KW_CASE; goto SETC;
+ case YIELD: name = KW_YIELD; goto SETC;
+ case BACKEND: name = KW_BACKEND; goto SETC;
+ case XCHAR: name = KW_XCHAR; goto SETC;
+ case FONT: name = KW_FONT; goto SETC;
+ case SPACE: name = KW_SPACE; goto SETC;
+ case YUNIT: name = KW_YUNIT; goto SETC;
+ case ZUNIT: name = KW_ZUNIT; goto SETC;
+ case BREAK: name = KW_BREAK; goto SETC;
+ case UNDERLINE: name = KW_UNDERLINE; goto SETC;
+ case COLOUR: name = KW_COLOUR; goto SETC;
+ case OUTLINE: name = KW_OUTLINE; goto SETC;
+ case LANGUAGE: name = KW_LANGUAGE; goto SETC;
+ case CURR_LANG: name = KW_CURR_LANG; goto SETC;
+ case CURR_FAMILY: name = KW_CURR_FAMILY; goto SETC;
+ case CURR_FACE: name = KW_CURR_FACE; goto SETC;
+ case CURR_YUNIT: name = KW_CURR_YUNIT; goto SETC;
+ case CURR_ZUNIT: name = KW_CURR_ZUNIT; goto SETC;
+ case COMMON: name = KW_COMMON; goto SETC;
+ case RUMP: name = KW_RUMP; goto SETC;
+ case MELD: name = KW_MELD; goto SETC;
+ case INSERT: name = KW_INSERT; goto SETC;
+ case ONE_OF: name = KW_ONE_OF; goto SETC;
+ case NEXT: name = KW_NEXT; goto SETC;
+ case PLUS: name = KW_PLUS; goto SETC;
+ case MINUS: name = KW_MINUS; goto SETC;
+ case OPEN: name = KW_OPEN; goto SETC;
+ case TAGGED: name = KW_TAGGED; goto SETC;
+ case INCGRAPHIC: name = KW_INCGRAPHIC; goto SETC;
+ case SINCGRAPHIC: name = KW_SINCGRAPHIC; goto SETC;
+ case PLAIN_GRAPHIC: name = KW_PLAINGRAPHIC; goto SETC;
+ case GRAPHIC: name = KW_GRAPHIC; goto SETC;
+ case LINK_SOURCE: name = KW_LINK_SOURCE; goto SETC;
+ case LINK_DEST: name = KW_LINK_DEST; goto SETC;
+
+ /* print left parameter, if present */
+ SETC:
+ if( DEFAULT_PREC <= outer_prec ) StringFPuts(KW_LBR, last_write_fp);
+ if( Down(x) != LastDown(x) )
+ { Child(y, Down(x));
+ WriteObject(y, DEFAULT_PREC, linecount, fnum);
+ StringFPuts(STR_SPACE, last_write_fp);
+ }
+
+ /* print the name of the symbol */
+ StringFPuts(name, last_write_fp);
+
+ /* print right parameter, if present */
+ if( LastDown(x) != x )
+ { Child(y, LastDown(x));
+ StringFPuts(STR_SPACE, last_write_fp);
+ if( type(x) == OPEN )
+ { StringFPuts(KW_LBR, last_write_fp);
+ WriteObject(y, NO_PREC, linecount, fnum);
+ StringFPuts(KW_RBR, last_write_fp);
+ }
+ else WriteObject(y, DEFAULT_PREC, linecount, fnum);
+ }
+ if( DEFAULT_PREC <= outer_prec ) StringFPuts(KW_RBR, last_write_fp);
+ break;
+
+
+ case RAW_VERBATIM:
+ case VERBATIM:
+
+ StringFPuts(type(x) == VERBATIM ? KW_VERBATIM : KW_RAWVERBATIM, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(KW_BEGIN, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ Child(y, Down(x));
+ if( type(y) == WORD )
+ {
+ StringFPuts(string(y), last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ }
+ else
+ {
+ assert( type(y) == VCAT, "WriteObject/VERBATIM!" );
+ for( link = Down(y); link != y; link = NextDown(link) )
+ { Child(z, link);
+ if( type(z) == GAP_OBJ ) continue;
+ assert( type(z) == WORD, "WriteObject/VERBATIM/WORD!");
+ StringFPuts(string(z), last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ *linecount += 1;
+ }
+ }
+ StringFPuts(KW_END, last_write_fp);
+ StringFPuts(STR_SPACE, last_write_fp);
+ StringFPuts(type(x) == VERBATIM ? KW_VERBATIM : KW_RAWVERBATIM, last_write_fp);
+ break;
+
+
+ case FILTERED:
+
+ FilterWrite(x, last_write_fp, linecount);
+ break;
+
+
+ default:
+
+ assert1(FALSE, "WriteObject:", Image(type(x)));
+ break;
+
+ } /* end switch */
+ debug0(DIO, D, "] WriteObject returning");
+ } /* end WriteObject */
+
+
+ /*@::AppendToFile(), CloseFiles()@********************************************/
+ /* */
+ /* AppendToFile(x, fnum, pos, lnum) */
+ /* */
+ /* Append object x to file fnum, returning its fseek position in *pos. */
+ /* and its line number in lnum. Record that this file has been updated. */
+ /* */
+ /*****************************************************************************/
+
+ void AppendToFile(OBJECT x, FILE_NUM fnum, int *pos, int *lnum)
+ { FULL_CHAR buff[MAX_BUFF], *str; int linecount;
+ debug2(DIO, D, "[ AppendToFile( %s, %s )", EchoObject(x), FileName(fnum));
+
+ /* open file fnum for writing */
+ if( last_write_fnum != fnum )
+ { if( last_write_fnum != NO_FILE ) fclose(last_write_fp);
+ str = FileName(fnum);
+ if( StringLength(str) + StringLength(NEW_DATA_SUFFIX) >= MAX_BUFF )
+ Error(41, 3, "file name %s%s is too long",
+ FATAL, PosOfFile(fnum), str, NEW_DATA_SUFFIX);
+ StringCopy(buff, str); StringCat(buff, NEW_DATA_SUFFIX);
+ last_write_fp = StringFOpen(buff,
+ FileTestUpdated(fnum) ? APPEND_TEXT : WRITE_TEXT);
+ if( last_write_fp == null )
+ Error(41, 4, "cannot append to database file %s", FATAL, no_fpos, buff);
+ last_write_fnum = fnum;
+ (void) fseek(last_write_fp, 0L, SEEK_END);
+ }
+
+ /* write x out and record the fact that fnum has changed */
+ *pos = (int) ftell(last_write_fp);
+ StringFPuts(KW_LBR, last_write_fp);
+ linecount = FileGetLineCount(fnum);
+ *lnum = linecount + 1;
+ WriteObject(x, NO_PREC, &linecount, fnum);
+ StringFPuts(KW_RBR, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ StringFPuts(STR_NEWLINE, last_write_fp);
+ FileSetUpdated(fnum, linecount + 2);
+ debug0(DIO, D, "] AppendToFile returning.");
+ } /* end AppendToFile */
+
+
+ /*****************************************************************************/
+ /* */
+ /* CloseFiles() */
+ /* */
+ /* Close all files and move new versions to the names of old versions. */
+ /* */
+ /*****************************************************************************/
+
+ void CloseFiles(void)
+ { FILE_NUM fnum; FULL_CHAR oldname[MAX_BUFF], newname[MAX_BUFF];
+ FILE *fp;
+ ifdebug(DPP, D, ProfileOn("CloseFiles"));
+ debug0(DIO, D, "CloseFiles()");
+
+ /* close off last file opened by AppendToFile above */
+ if( last_write_fnum != NO_FILE ) fclose(last_write_fp);
+
+ /* get rid of old database files */
+ for( fnum=FirstFile(SOURCE_FILE); fnum != NO_FILE; fnum = NextFile(fnum) )
+ { StringCopy(oldname, FileName(fnum));
+ StringCat(oldname, DATA_SUFFIX);
+ debug1(DIO, D, "remove(%s)", oldname);
+ StringRemove(oldname);
+ }
+
+ /* move any new database files to the old names, if updated */
+ /* just to avoid confusion: the "new name" means the ".ldx" */
+ /* temporary file name; the "old name" means the permanent */
+ /* name, i.e. ".ld". So we have to move the new name to */
+ /* the old name. */
+
+ for( fnum=FirstFile(DATABASE_FILE); fnum != NO_FILE; fnum = NextFile(fnum) )
+ { if( FileTestUpdated(fnum) )
+ {
+ /* construct new and old file names */
+ StringCopy(oldname, FileName(fnum));
+ StringCopy(newname, oldname);
+ StringCat(newname, NEW_DATA_SUFFIX);
+
+ /* guaranteed portable algorithm for changing the name of file */
+ /* "newname" to "oldname": if "oldname" exists already, then */
+ /* remove it (avoids removing a non-existent file, which can */
+ /* be a problem); then rename "newname" to be "oldname" (avoids */
+ /* overwriting an existing file "oldname", another problem) */
+
+ if( (fp = StringFOpen(oldname, READ_TEXT)) != NULL )
+ { fclose(fp);
+ StringRemove(oldname);
+ }
+ debug2(DIO, D, "rename(%s, %s)", newname, oldname);
+ if( StringRename(newname, oldname) != 0 )
+ Error(41, 5, "rename(%s, %s) failed", INTERN, no_fpos,newname,oldname);
+ }
+ }
+ debug0(DIO, D, "CloseFiles returning.");
+ ifdebug(DPP, D, ProfileOff("CloseFiles"));
+ } /* end CloseFiles */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z42.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z42.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z42.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,243 ----
+ /*@z42.c:Colour Service:ColourChange, ColourCommand@**************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z42.c */
+ /* MODULE: Colour Service */
+ /* EXTERNS: ColourChange(), ColourCommand() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define INIT_COLOUR_NUM 100
+
+
+ /*****************************************************************************/
+ /* */
+ /* COLOUR_TABLE */
+ /* */
+ /* A symbol table permitting access to colour records by number or name. */
+ /* The table will automatically enlarge to accept any number of entries, */
+ /* but there is an arbitrary limit of 65535 colours imposed so that colour */
+ /* numbers can be stored in 16 bit fields. */
+ /* */
+ /* ctab_new(newsize) New empty table, newsize capacity */
+ /* ctab_insert(x, &S) Insert new colour object x into S */
+ /* ctab_retrieve(str, S) Retrieve colour object of name str */
+ /* ctab_num(S, num) Retrieve colour object, number num */
+ /* ctab_debug(S, fp) Debug print of table S to file fp */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { int coltab_size; /* size of table */
+ int coltab_count; /* number of colours held */
+ struct coltab_rec
+ { OBJECT by_number; /* colour record by number */
+ OBJECT by_name_hash; /* colour record by name */
+ } coltab[1];
+ } *COLOUR_TABLE;
+
+ #define ctab_size(S) (S)->coltab_size
+ #define ctab_count(S) (S)->coltab_count
+ #define ctab_num(S, i) (S)->coltab[i].by_number
+ #define ctab_name(S, i) (S)->coltab[i].by_name_hash
+
+ #define hash(pos, str, S) \
+ { FULL_CHAR *p = str; \
+ pos = *p++; \
+ while( *p ) pos += *p++; \
+ pos = pos % ctab_size(S); \
+ }
+
+ static COLOUR_TABLE ctab_new(int newsize)
+ { COLOUR_TABLE S; int i;
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_COLOUR_TAB, 1,
+ 2*sizeof(int) + newsize * sizeof(struct coltab_rec)));
+ S = (COLOUR_TABLE) malloc(2*sizeof(int) + newsize * sizeof(struct coltab_rec));
+ if( S == (COLOUR_TABLE) NULL )
+ Error(42, 1, "ran out of memory when enlarging colour table",
+ FATAL, no_fpos);
+ ctab_size(S) = newsize;
+ ctab_count(S) = 0;
+ for( i = 0; i < newsize; i++ )
+ { ctab_num(S, i) = ctab_name(S, i) = nilobj;
+ }
+ return S;
+ } /* end ctab_new */
+
+ static void ctab_insert(OBJECT x, COLOUR_TABLE *S);
+
+ static COLOUR_TABLE ctab_rehash(COLOUR_TABLE S, int newsize)
+ { COLOUR_TABLE NewS; int i;
+ NewS = ctab_new(newsize);
+ for( i = 1; i <= ctab_count(S); i++ )
+ ctab_insert(ctab_num(S, i), &NewS);
+ for( i = 0; i < ctab_size(S); i++ )
+ { if( ctab_name(S, i) != nilobj ) DisposeObject(ctab_name(S, i));
+ }
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_COLOUR_TAB, -1,
+ -(2*sizeof(int) + ctab_size(S) * sizeof(struct coltab_rec))));
+ free(S);
+ return NewS;
+ } /* end ctab_rehash */
+
+ static void ctab_insert(OBJECT x, COLOUR_TABLE *S)
+ { int pos, num;
+ if( ctab_count(*S) == ctab_size(*S) - 1 ) /* one less since 0 unused */
+ *S = ctab_rehash(*S, 2*ctab_size(*S));
+ num = ++ctab_count(*S);
+ if( num > MAX_COLOUR )
+ Error(42, 2, "too many colours (maximum is %d)",
+ FATAL, &fpos(x), MAX_COLOUR);
+ hash(pos, string(x), *S);
+ if( ctab_name(*S, pos) == nilobj ) New(ctab_name(*S, pos), ACAT);
+ Link(ctab_name(*S, pos), x);
+ word_colour(x) = num;
+ ctab_num(*S, num) = x;
+ } /* end ctab_insert */
+
+ static OBJECT ctab_retrieve(FULL_CHAR *str, COLOUR_TABLE S)
+ { OBJECT x, link, y; int pos;
+ hash(pos, str, S);
+ x = ctab_name(S, pos);
+ if( x == nilobj ) return nilobj;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(str, string(y)) ) return y;
+ }
+ return nilobj;
+ } /* end ctab_retrieve */
+
+ #if DEBUG_ON
+ static void ctab_debug(COLOUR_TABLE S, FILE *fp)
+ { int i; OBJECT x, link, y;
+ fprintf(fp, " table size: %d; current number of colours: %d\n",
+ ctab_size(S), ctab_count(S));
+ for( i = 0; i < ctab_size(S); i++ )
+ { x = ctab_num(S, i);
+ fprintf(fp, " ctab_num(S, %d) = %s\n", i,
+ x == nilobj ? AsciiToFull("<nilobj>") :
+ is_word(type(x)) ? string(x) : AsciiToFull("not WORD!"));
+ }
+ fprintf(fp, "\n");
+ for( i = 0; i < ctab_size(S); i++ )
+ { x = ctab_name(S, i);
+ fprintf(fp, "ctab_name(S, %d) =", i);
+ if( x == nilobj )
+ fprintf(fp, " <nilobj>");
+ else if( type(x) != ACAT )
+ fprintf(fp, " not ACAT!");
+ else for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ fprintf(fp, " %s",
+ is_word(type(y)) ? string(y) : AsciiToFull("not-WORD!"));
+ }
+ fprintf(fp, "\n");
+ }
+ } /* end ctab_debug */
+ #endif
+
+
+ static COLOUR_TABLE col_tab;
+
+ /*****************************************************************************/
+ /* */
+ /* ColourInit() */
+ /* */
+ /* Initialize this module. */
+ /* */
+ /*****************************************************************************/
+
+ void ColourInit(void)
+ { col_tab = ctab_new(INIT_COLOUR_NUM);
+ } /* end ColourInit */
+
+
+ /*****************************************************************************/
+ /* */
+ /* ColourChange(style, x) */
+ /* */
+ /* Change the current style to contain the colour of colour command x. */
+ /* */
+ /*****************************************************************************/
+
+ void ColourChange(STYLE *style, OBJECT x)
+ { OBJECT cname;
+ debug2(DCO, D, "ColourChange(%s, %s)", EchoStyle(style), EchoObject(x));
+
+ /* if argument is not a word, fail and exit */
+ if( !is_word(type(x)) )
+ { Error(42, 3, "%s ignored (illegal left parameter)", WARN, &fpos(x),
+ KW_COLOUR);
+ debug0(DCO, D, "ColourChange returning (colour unchanged)");
+ return;
+ }
+
+ /* if argument is empty, fail and exit */
+ if( StringEqual(string(x), STR_EMPTY) )
+ { if( BackEnd->colour_avail )
+ Error(42, 4, "%s ignored (empty left parameter)", WARN, &fpos(x),
+ KW_COLOUR);
+ debug0(DCO, D, "ColourChange returning (colour unchanged)");
+ return;
+ }
+
+ /* if argument is nochange, do nothing */
+ if( StringEqual(string(x), STR_COLOUR_NOCHANGE) )
+ { debug0(DCO, D, "ColourChange returning (colour nochange)");
+ return;
+ }
+
+ /* retrieve colour command if present, else insert it */
+ { cname = ctab_retrieve(string(x), col_tab);
+ if( cname == nilobj )
+ { cname = MakeWord(type(x), string(x), &fpos(x));
+ ctab_insert(cname, &col_tab);
+ colour(*style) = word_colour(cname);
+ }
+ else colour(*style) = word_colour(cname);
+ }
+
+ debug1(DCO, D, "ColourChange returning (colour = %s)", string(cname));
+ ifdebug(DCO, DD, ctab_debug(col_tab, stderr));
+ } /* ColourChange */
+
+
+ /*@::ColourCommand()@*********************************************************/
+ /* */
+ /* FULL_CHAR *ColourCommand(cnum) */
+ /* */
+ /* Return the PostScript command for producing colour cnum. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *ColourCommand(COLOUR_NUM cnum)
+ { FULL_CHAR *res;
+ debug1(DCO, D, "ColourCommand(%d)", cnum);
+ assert( cnum > 0 && cnum <= ctab_count(col_tab), "ColourCommand: number" );
+
+ res = string(ctab_num(col_tab, cnum));
+
+ debug1(DCO, D, "ColourCommand returning %s", res);
+ return res;
+ } /* end ColourCommand */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z43.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z43.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z43.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,402 ----
+ /*@z43.c:Language Service:LanguageChange, LanguageString@*********************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z43.c */
+ /* MODULE: Language Service */
+ /* EXTERNS: LanguageInit(), LanguageDefine(), LanguageChange(), */
+ /* LanguageString(), LanguageHyph() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define INIT_LANGUAGE_NUM 100
+
+
+ /*****************************************************************************/
+ /* */
+ /* LANGUAGE_TABLE */
+ /* */
+ /* A symbol table permitting access to language name records. */
+ /* The table will automatically enlarge to accept any number of entries. */
+ /* */
+ /* ltab_new(newsize) New empty table, newsize capacity */
+ /* ltab_insert(x, &S) Insert new language name object x into S */
+ /* ltab_retrieve(str, S) Retrieve language name object named str */
+ /* ltab_debug(S, fp) Debug print of table S to file fp */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { int langtab_size; /* size of table */
+ int langtab_count; /* number of objects held */
+ OBJECT langtab_item[1];
+ } *LANGUAGE_TABLE;
+
+ #define ltab_size(S) (S)->langtab_size
+ #define ltab_count(S) (S)->langtab_count
+ #define ltab_item(S, i) (S)->langtab_item[i]
+
+ #define hash(pos, str, S) \
+ { FULL_CHAR *p = str; \
+ pos = *p++; \
+ while( *p ) pos += *p++; \
+ pos = pos % ltab_size(S); \
+ }
+
+ static LANGUAGE_TABLE ltab_new(int newsize)
+ { LANGUAGE_TABLE S; int i;
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_LANG_TAB, 1,
+ 2*sizeof(int) + newsize * sizeof(OBJECT)));
+ S = (LANGUAGE_TABLE)
+ malloc(2*sizeof(int) + newsize * sizeof(OBJECT));
+ if( S == (LANGUAGE_TABLE) NULL )
+ Error(43, 1, "run out of memory enlarging language table", FATAL, no_fpos);
+ ltab_size(S) = newsize;
+ ltab_count(S) = 0;
+ for( i = 0; i < newsize; i++ ) ltab_item(S, i) = nilobj;
+ return S;
+ } /* end ltab_new */
+
+ static void ltab_insert(OBJECT x, LANGUAGE_TABLE *S);
+
+ static LANGUAGE_TABLE ltab_rehash(LANGUAGE_TABLE S, int newsize)
+ { LANGUAGE_TABLE NewS; int i;
+ NewS = ltab_new(newsize);
+ for( i = 1; i <= ltab_size(S); i++ )
+ { if( ltab_item(S, i) != nilobj )
+ ltab_insert(ltab_item(S, i), &NewS);
+ }
+ free(S);
+ return NewS;
+ } /* end ltab_rehash */
+
+ static void ltab_insert(OBJECT x, LANGUAGE_TABLE *S)
+ { int pos; OBJECT z, link, y;
+ if( ltab_count(*S) == ltab_size(*S) - 1 ) /* one less since 0 unused */
+ *S = ltab_rehash(*S, 2*ltab_size(*S));
+ hash(pos, string(x), *S);
+ if( ltab_item(*S, pos) == nilobj ) New(ltab_item(*S, pos), ACAT);
+ z = ltab_item(*S, pos);
+ for( link = Down(z); link != z; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(string(x), string(y)) )
+ { Error(43, 2, "language name %s used twice (first at%s)",
+ FATAL, &fpos(x), string(x), EchoFilePos(&fpos(y)));
+ }
+ }
+ Link(ltab_item(*S, pos), x);
+ } /* end ltab_insert */
+
+ static OBJECT ltab_retrieve(FULL_CHAR *str, LANGUAGE_TABLE S)
+ { OBJECT x, link, y; int pos;
+ hash(pos, str, S);
+ x = ltab_item(S, pos);
+ if( x == nilobj ) return nilobj;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(str, string(y)) ) return y;
+ }
+ return nilobj;
+ } /* end ltab_retrieve */
+
+ #if DEBUG_ON
+ static void ltab_debug(LANGUAGE_TABLE S, FILE *fp)
+ { int i; OBJECT x, link, y;
+ fprintf(fp, " table size: %d; current number of keys: %d\n",
+ ltab_size(S), ltab_count(S));
+ for( i = 0; i < ltab_size(S); i++ )
+ { x = ltab_item(S, i);
+ fprintf(fp, "ltab_item(S, %d) =", i);
+ if( x == nilobj )
+ fprintf(fp, " <nilobj>");
+ else if( type(x) != ACAT )
+ fprintf(fp, " not ACAT!");
+ else for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ fprintf(fp, " %s",
+ is_word(type(y)) ? string(y) : AsciiToFull("not-WORD!"));
+ }
+ fprintf(fp, "\n");
+ }
+ } /* end ltab_debug */
+ #endif
+
+
+ static LANGUAGE_TABLE names_tab; /* the language names */
+ static OBJECT *hyph_tab; /* arry of hyph filenames */
+ static OBJECT *canonical_tab; /* array of lang names */
+ static int lang_tabsize; /* size of prev two arrays */
+ static int lang_count; /* number of languages */
+ static OBJECT lang_ends[MAX_LANGUAGE];/* sentence endings */
+
+ /*@@**************************************************************************/
+ /* */
+ /* BOOLEAN LanguageSentenceEnds[] */
+ /* */
+ /* LanguageSentenceEnds[ch] is TRUE if there exists a language in which */
+ /* character ch could occur at the end of a sentence. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN LanguageSentenceEnds[MAX_CHARS];
+
+
+ /*@::LanguageInit(), LanguageDefine()@****************************************/
+ /* */
+ /* LanguageInit() */
+ /* */
+ /* Initialize this module. */
+ /* */
+ /*****************************************************************************/
+
+ void LanguageInit(void)
+ { int i;
+ debug0(DLS, D, "LanguageInit()");
+ names_tab = ltab_new(INIT_LANGUAGE_NUM);
+ lang_count = 0;
+ lang_tabsize = INIT_LANGUAGE_NUM;
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_LANG_TAB, 0,
+ INIT_LANGUAGE_NUM * sizeof(OBJECT)));
+ hyph_tab = (OBJECT *) malloc(INIT_LANGUAGE_NUM * sizeof(OBJECT));
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_LANG_TAB, 0,
+ INIT_LANGUAGE_NUM * sizeof(OBJECT)));
+ canonical_tab = (OBJECT *) malloc(INIT_LANGUAGE_NUM * sizeof(OBJECT));
+ for( i = 0; i < MAX_CHARS; i++ ) LanguageSentenceEnds[i] = FALSE;
+ debug0(DLS, D, "LanguageInit returning.");
+ } /* end LanguageInit */
+
+
+ /*****************************************************************************/
+ /* */
+ /* LanguageDefine(names, inside) */
+ /* */
+ /* Define a language whose names are given by ACAT of words names, and */
+ /* whose associated hyphenation patterns file name is hyph_file. */
+ /* */
+ /*****************************************************************************/
+
+ void LanguageDefine(OBJECT names, OBJECT inside)
+ { OBJECT link, y, hyph_file; BOOLEAN junk; FULL_CHAR ch;
+ int len;
+ assert( names != nilobj && type(names) == ACAT, "LanguageDefine: names!");
+ assert( Down(names) != names, "LanguageDefine: names is empty!");
+ debug2(DLS, D, "LanguageDefine(%s, %s)",
+ EchoObject(names), EchoObject(inside));
+
+ /* double table size if overflow */
+ if( ++lang_count >= lang_tabsize )
+ {
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_LANG_TAB, 0,
+ -lang_tabsize * sizeof(OBJECT)));
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_LANG_TAB, 0,
+ -lang_tabsize * sizeof(OBJECT)));
+ lang_tabsize *= 2;
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_LANG_TAB, 0,
+ lang_tabsize * sizeof(OBJECT)));
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_LANG_TAB, 0,
+ lang_tabsize * sizeof(OBJECT)));
+ hyph_tab = (OBJECT *) realloc(hyph_tab, lang_tabsize * sizeof(OBJECT) );
+ canonical_tab = (OBJECT *) realloc(canonical_tab, lang_tabsize * sizeof(OBJECT) );
+ }
+
+ /* insert each language name into names_tab */
+ for( link = Down(names); link != names; link = NextDown(link) )
+ { Child(y, link);
+ assert( is_word(type(y)), "LanguageDefine: type(y) != WORD!" );
+ word_language(y) = lang_count;
+ ltab_insert(y, &names_tab);
+ }
+
+ /* initialize canonical language name entry */
+ Child(y, Down(names));
+ canonical_tab[lang_count] = y;
+
+ /* make inside an ACAT if it isn't already */
+ if( type(inside) != ACAT )
+ { New(y, ACAT);
+ FposCopy(fpos(y), fpos(inside));
+ Link(y, inside);
+ inside = y;
+ }
+
+ /* initialize hyphenation file entry (first child of inside) */
+ Child(hyph_file, Down(inside));
+ DeleteLink(Down(inside));
+ if( !is_word(type(hyph_file)) )
+ Error(43, 3, "hyphenation file name expected here",
+ FATAL, &fpos(inside));
+ if( StringEqual(string(hyph_file), STR_EMPTY) ||
+ StringEqual(string(hyph_file), STR_HYPHEN) )
+ { Dispose(hyph_file);
+ hyph_tab[lang_count] = nilobj;
+ }
+ else hyph_tab[lang_count] = hyph_file;
+
+ /* initialize sentence ends */
+ lang_ends[lang_count] = inside;
+ for( link = Down(inside); link != inside; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ )
+ { link = PrevDown(link);
+ DisposeChild(NextDown(link));
+ continue;
+ }
+ if( !is_word(type(y)) )
+ { debug2(DLS, D, "word patterns failing on %s %s", Image(type(y)),
+ EchoObject(y));
+ Error(43, 4, "expected word ending pattern here", FATAL, &fpos(y));
+ }
+ len = StringLength(string(y));
+ if( len == 0 )
+ Error(43, 5, "empty word ending pattern", FATAL, &fpos(y));
+ ch = string(y)[len - 1];
+ LanguageSentenceEnds[ch] = TRUE;
+ }
+
+ /* if initializing run, initialize the hyphenation table */
+ if( InitializeAll )
+ { if( hyph_tab[lang_count] != nilobj )
+ junk = ReadHyphTable(lang_count);
+ }
+
+ debug0(DLS, D, "LanguageDefine returning.");
+ } /* end LanguageDefine */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN LanguageWordEndsSentence(OBJECT wd, BOOLEAN lc_prec) */
+ /* */
+ /* Returns TRUE if word ends a sentence in the current language. This is */
+ /* so if it ends with a string in the list associated with the current */
+ /* language. If lc_prec is TRUE, it is also necessary for the character */
+ /* preceding this suffix to be lower-case. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN LanguageWordEndsSentence(OBJECT wd, BOOLEAN lc_prec)
+ { OBJECT x, y, link; int pos;
+ assert( is_word(type(wd)), "LanguageWordEndsSentence: wd!" );
+ debug2(DLS, D, "LanguageWordEndsSentence(%d %s)",
+ word_language(wd), EchoObject(wd));
+ x = lang_ends[word_language(wd)];
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEndsWith(string(wd), string(y)) )
+ {
+ if( !lc_prec )
+ { debug0(DLS, D, "LanguageWordEndsSentence returning TRUE (!lc_prec)");
+ return TRUE;
+ }
+
+ /* now check whether the preceding character is lower case */
+ pos = StringLength(string(wd)) - StringLength(string(y)) - 1;
+ if( pos >= 0 &&
+ MapIsLowerCase(string(wd)[pos], FontMapping(word_font(wd), &fpos(wd))))
+ {
+ debug0(DLS, D, "LanguageWordEndsSentence returning TRUE (!lc_prec)");
+ return TRUE;
+ }
+ }
+ }
+ debug0(DLS, D, "LanguageWordEndsSentence returning FALSE");
+ return FALSE;
+ } /* end LanguageWordEndsSentence */
+
+
+ /*@::LanguageChange(), LanguageString(), LanguageHyph()@**********************/
+ /* */
+ /* LanguageChange(style, x) */
+ /* */
+ /* Change the current style to contain the language of language command x. */
+ /* */
+ /*****************************************************************************/
+
+ void LanguageChange(STYLE *style, OBJECT x)
+ { OBJECT lname;
+ debug2(DLS, D, "LanguageChange(%s, %s)", EchoStyle(style), EchoObject(x));
+
+ /* if argument is not a word, fail and exit */
+ if( !is_word(type(x)) )
+ { Error(43, 6, "%s ignored (illegal left parameter)", WARN, &fpos(x),
+ KW_LANGUAGE);
+ debug0(DLS, D, "LanguageChange returning (language unchanged)");
+ return;
+ }
+
+ /* if argument is empty, return unchanged */
+ if( StringEqual(string(x), STR_EMPTY) )
+ { debug0(DLS, D, "LanguageChange returning (empty, language unchanged)");
+ return;
+ }
+
+ /* retrieve language record if present, else leave style unchanged */
+ lname = ltab_retrieve(string(x), names_tab);
+ if( lname == nilobj )
+ Error(43, 7, "%s ignored (unknown language %s)", WARN, &fpos(x),
+ KW_LANGUAGE, string(x));
+ else language(*style) = word_language(lname);
+
+ debug1(DLS, D, "LanguageChange returning (language = %s)", string(lname));
+ ifdebug(DLS, DD, ltab_debug(names_tab, stderr));
+ } /* LanguageChange */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *LanguageString(lnum) */
+ /* */
+ /* Return the canonical name of language lnum. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_CHAR *LanguageString(LANGUAGE_NUM lnum)
+ { FULL_CHAR *res;
+ debug1(DLS, D, "LanguageString(%d)", lnum);
+ assert( lnum > 0 && lnum <= lang_count, "LanguageString: unknown number" );
+
+ res = string(canonical_tab[lnum]);
+
+ debug1(DLS, D, "LanguageString returning %s", res);
+ return res;
+ } /* end LanguageString */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT LanguageHyph(lnum) */
+ /* */
+ /* Return the hyphenation file name object for language lnum. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT LanguageHyph(LANGUAGE_NUM lnum)
+ { OBJECT res;
+ debug1(DLS, D, "LanguageHyph(%d)", lnum);
+ assert( lnum > 0 && lnum <= lang_count, "LanguageHyph: unknown number" );
+
+ res = hyph_tab[lnum];
+
+ debug1(DLS, D, "LanguageHyph returning %s", EchoObject(res));
+ return res;
+ } /* end LanguageHyph */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z44.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z44.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z44.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,573 ----
+ /*@z44.c:Vertical Hyphenation:VerticalHyphenate()@****************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z44.c */
+ /* MODULE: Vertical Hyphenation */
+ /* EXTERNS: VerticalHyphenate(), ConvertGalleyList() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* FirstDefiniteCompressed(x, link, y) */
+ /* NextDefiniteWithGapCompressed(x, link, y, g) */
+ /* */
+ /* Like FirstDefinite() and NextDefiniteWithGap(), except that these */
+ /* versions assume that x is of type VCAT, and they compress any VCAT */
+ /* objects found within x as they go. */
+ /* */
+ /*****************************************************************************/
+
+ #define FirstDefiniteCompressed(x, link, y) \
+ { BOOLEAN jn; \
+ FirstDefinite(x, link, y, jn); \
+ while( link != x && type(y) == VCAT ) \
+ { TransferLinks(Down(y), y, link); \
+ DisposeChild(link); \
+ FirstDefinite(x, link, y, jn); \
+ } \
+ assert( link==x || is_definite(type(y)), "FirstDefiniteCompressed!"); \
+ }
+
+ #define NextDefiniteWithGapCompressed(x, link, y, g) \
+ { OBJECT start_link = PrevDown(link), ylink, yg, z; \
+ BOOLEAN jn; \
+ NextDefiniteWithGap(x, link, y, g, jn); \
+ while( link != x && type(y) == VCAT ) \
+ { FirstDefinite(y, ylink, z, jn); \
+ if( ylink != y && PrevDown(ylink) != y ) \
+ { Child(yg, PrevDown(ylink)); \
+ assert( type(yg)==GAP_OBJ && mode(gap(yg)) != NO_MODE, "NDWGC!"); \
+ MoveLink(PrevDown(ylink), Up(g), PARENT); \
+ MoveLink(Up(g), ylink, PARENT); \
+ } \
+ TransferLinks(Down(y), y, link); \
+ DisposeChild(link); \
+ link = NextDown(start_link); \
+ NextDefiniteWithGap(x, link, y, g, jn); \
+ } \
+ assert( link==x || is_definite(type(y)), "FirstDefiniteCompressed!"); \
+ assert( link==x || mode(gap(g)) != NO_MODE, \
+ "FirstDefiniteWithGapCompressed: mode(gap(g))!" ); \
+ }
+
+
+ /*@@**************************************************************************/
+ /* */
+ /* OBJECT FindTarget(index) */
+ /* */
+ /* Work out what the given index is pointing at, or nilobj if nothing. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT FindTarget(OBJECT index)
+ { OBJECT res;
+ debug1(DVH, DD, "FindTarget(%s)", Image(type(index)));
+ switch( type(index) )
+ {
+ case DEAD:
+
+ res = nilobj;
+ break;
+
+
+ case UNATTACHED:
+ case GALL_PREC:
+ case GALL_FOLL:
+ case GALL_FOLL_OR_PREC:
+
+ res = pinpoint(index);
+ break;
+
+
+ case RECEPTIVE:
+ case RECEIVING:
+ case RECURSIVE:
+ case SCALE_IND:
+ case COVER_IND:
+ case EXPAND_IND:
+
+ res = actual(index);
+ break;
+
+
+ case PRECEDES:
+ case FOLLOWS:
+ case CROSS_TARG:
+ case CROSS_PREC:
+ case CROSS_FOLL:
+ case CROSS_FOLL_OR_PREC:
+ case PAGE_LABEL_IND:
+
+ res = nilobj; /* somewhat doubtful */
+ break;
+
+
+ case GALL_TARG:
+
+ res = nilobj; /* somewhat doubtful */
+ break;
+
+
+ default:
+
+ assert1(FALSE, "FindTarget: unknown index", Image(type(index)));
+ break;
+ }
+ debug1(DVH, DD, "FindTarget returning %s", EchoObject(res));
+ return res;
+ } /* end FindTarget */
+
+
+ /*@@**************************************************************************/
+ /* */
+ /* OBJECT WhichComponent(target) */
+ /* */
+ /* Return the component of the enclosing galley that contains target, */
+ /* or nilobj if some problem. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT WhichComponent(OBJECT target)
+ { OBJECT prnt;
+ debug1(DVH, DD, "WhichComponent(%s)", EchoObject(target));
+ while( Up(target) != target )
+ { Parent(prnt, Up(target));
+ if( type(prnt) == HEAD )
+ { debug1(DVH, DD, "WhichComponent returning %s", EchoObject(target));
+ return target;
+ }
+ target = prnt;
+ }
+ debug0(DVH, DD, "WhichComponent returning nilobj");
+ return nilobj;
+ } /* end WhichComponent */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT EncloseInHcat(nxt, y, replace) */
+ /* */
+ /* Enclose object nxt in an HCAT, similar to HCAT y, at position replace. */
+ /* The link to nxt will now link to the new HCAT. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT EncloseInHcat(OBJECT nxt, OBJECT y, OBJECT replace)
+ { OBJECT new_y, new_row_thread, s1, new_s1, s2, new_s2, link, sh, new_sh, tmp;
+ assert( Up(nxt) != nxt, "EncloseInHCat: Up(nxt) == nxt!" );
+ New(new_y, HCAT);
+ adjust_cat(new_y) = FALSE;
+ MoveLink(Up(nxt), new_y, CHILD);
+ assert( Up(nxt) == nxt, "EncloseInHCat: Up(nxt) != nxt!" );
+ FposCopy(fpos(new_y), fpos(y));
+ back(new_y, COLM) = back(y, COLM);
+ fwd(new_y, COLM) = fwd(y, COLM);
+ back(new_y, ROWM) = back(nxt, ROWM);
+ fwd(new_y, ROWM) = fwd(nxt, ROWM);
+ New(new_row_thread, ROW_THR);
+ back(new_row_thread, ROWM) = back(new_y, ROWM);
+ fwd(new_row_thread, ROWM) = fwd(new_y, ROWM);
+ thr_state(new_row_thread) = SIZED;
+ for( link = Down(y); link != y; link = NextDown(link) )
+ { Child(s1, link);
+ if( type(s1) == GAP_OBJ )
+ { New(new_s1, GAP_OBJ);
+ FposCopy(fpos(new_s1), fpos(s1));
+ GapCopy(gap(new_s1), gap(s1));
+ hspace(new_s1) = hspace(s1);
+ vspace(new_s1) = vspace(s1);
+ Link(new_y, new_s1);
+ continue;
+ }
+ if( type(s1) == WIDE || type(s1) == ONE_COL )
+ Child(s2, Down(s1));
+ else s2 = s1;
+ assert( type(s2) == SPLIT, "EncloseInHcat: type(s2) != SPLIT!" );
+ Child(sh, DownDim(s2, COLM));
+ New(new_s2, SPLIT);
+ FposCopy(fpos(new_s2), fpos(s2));
+ if( s2 != s1 )
+ { New(new_s1, type(s1));
+ back(new_s1, COLM) = back(s1, COLM);
+ fwd(new_s1, COLM) = fwd(s1, COLM);
+ back(new_s1, ROWM) = back(new_row_thread, COLM);
+ fwd(new_s1, ROWM) = fwd(new_row_thread, COLM);
+ Link(new_y, new_s1);
+ Link(new_s1, new_s2);
+ }
+ else Link(new_y, new_s2);
+ if( sh == replace )
+ {
+ /* replace sh by nxt in the copy */
+ new_sh = nxt;
+ back(new_sh, COLM) = back(s2, COLM);
+ fwd(new_sh, COLM) = fwd(s2, COLM);
+ }
+ else
+ {
+ /* replace sh by an empty object of the same width in the copy */
+ New(new_sh, WIDE);
+ FposCopy(fpos(new_sh), fpos(sh));
+ SetConstraint(constraint(new_sh), back(sh,COLM),size(sh,COLM),fwd(sh,COLM));
+ back(new_sh, COLM) = back(sh, COLM);
+ fwd(new_sh, COLM) = fwd(sh, COLM);
+ back(new_sh, ROWM) = fwd(new_sh, ROWM) = 0;
+ tmp = MakeWord(WORD, STR_EMPTY, &fpos(sh));
+ back(tmp, COLM) = fwd(tmp, COLM) = 0;
+ back(tmp, ROWM) = fwd(tmp, ROWM) = 0;
+ underline(tmp) = UNDER_OFF;
+ Link(new_sh, tmp);
+ }
+ Link(new_s2, new_sh);
+ back(new_s2, COLM) = back(new_sh, COLM);
+ fwd(new_s2, COLM) = fwd(new_sh, COLM);
+ Link(new_s2, new_row_thread);
+ back(new_s2, ROWM) = back(new_row_thread, ROWM);
+ fwd(new_s2, ROWM) = fwd(new_row_thread, ROWM);
+ Link(new_row_thread, new_sh);
+ }
+ return new_y;
+ } /* end EncloseInHcat */
+
+
+ /*@::VerticalHyphenate()@*****************************************************/
+ /* */
+ /* BOOLEAN VerticalHyphenate(OBJECT y) */
+ /* */
+ /* Attempt to vertically hyphenate galley component y, of type HCAT. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN VerticalHyphenate(OBJECT y)
+ { OBJECT large_comp, index, z, link, g;
+ OBJECT row_thread, s1, s2, sh, sv, shp, prev, nxt, large_comp_split;
+ FULL_LENGTH rump_fwd;
+ debug1(DVH, D, "[ VerticalHyphenate(y: %s), y =", EchoLength(size(y, ROWM)));
+ ifdebug(DVH, D, DebugObject(y));
+ debug0(DVH, DD, "galley before vertical hyphenation:");
+ ifdebug(DVH, DD, Parent(z, Up(y)); DebugGalley(z, y, 2));
+
+ /* find large_comp, the largest VCAT component, or else return FALSE */
+ row_thread = large_comp = nilobj;
+ rump_fwd = 0;
+ assert( type(y) == HCAT, "VerticalHyphenate: type(y) != HCAT!" );
+ for( link = Down(y); link != y; link = NextDown(link) )
+ { Child(s1, link);
+ if( type(s1) == GAP_OBJ )
+ { if( !join(gap(s1)) )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (not joined)");
+ return FALSE;
+ }
+ continue;
+ }
+
+ /* check that s2 is a SPLIT object whose children look right */
+ if( type(s1) == WIDE || type(s1) == ONE_COL )
+ Child(s2, Down(s1));
+ else s2 = s1;
+ if( type(s2) != SPLIT )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (child not SPLIT)");
+ return FALSE;
+ }
+ Child(sh, DownDim(s2, COLM));
+ Child(sv, DownDim(s2, ROWM));
+ if( type(sv) != ROW_THR )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (no ROW_THR)");
+ return FALSE;
+ }
+ if( row_thread == nilobj ) row_thread = sv;
+ if( sv != row_thread )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (different ROW_THR)");
+ return FALSE;
+ }
+ Parent(shp, UpDim(sh, ROWM));
+ if( shp != row_thread )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (sh parent)");
+ return FALSE;
+ }
+
+ /* Now sh is one of the HCAT components */
+ if( type(sh) != VCAT )
+ { rump_fwd = find_max(rump_fwd, fwd(sh, ROWM));
+ }
+ else if( large_comp != nilobj )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (two VCATs)");
+ return FALSE;
+ }
+ else
+ { large_comp = sh;
+ large_comp_split = s2;
+ }
+ }
+
+ /* if no large_comp, return */
+ if( large_comp == nilobj )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (no VCAT)");
+ return FALSE;
+ }
+
+ /* check that large_comp has at least two components */
+ FirstDefiniteCompressed(large_comp, link, prev);
+ if( link == large_comp )
+ { debug0(DVH,D, "] VerticalHyphenate returning FALSE (VCAT: no components)");
+ return FALSE;
+ }
+ NextDefiniteWithGapCompressed(large_comp, link, nxt, g);
+ if( link == large_comp )
+ { debug0(DVH,D, "] VerticalHyphenate returning FALSE (VCAT: one component)");
+ return FALSE;
+ }
+
+ /* make sure that first gap does not change when rearranging */
+ rump_fwd = find_max(rump_fwd, fwd(prev, ROWM));
+ if( MinGap(rump_fwd, back(nxt, ROWM), fwd(nxt, ROWM), &gap(g)) !=
+ MinGap(fwd(prev, ROWM), back(nxt, ROWM), fwd(nxt, ROWM), &gap(g)) )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (first gap changes)");
+ return FALSE;
+ }
+
+ /* check that large_comp has no joins */
+ for( link = Down(large_comp); link != large_comp; link = NextDown(link) )
+ { Child(z, link);
+ if( type(z) == GAP_OBJ && mode(gap(z)) != NO_MODE && join(gap(z)) )
+ { debug0(DVH, D, "] VerticalHyphenate returning FALSE (VCAT: joined)");
+ return FALSE;
+ }
+ }
+
+ /* enclose all definite components after the first in HCATs */
+ for( link = NextDown(Up(prev)); link != large_comp; link = NextDown(link) )
+ { Child(nxt, link);
+ if( type(nxt) == GAP_OBJ ) continue;
+ if( is_definite(type(nxt)) )
+ nxt = EncloseInHcat(nxt, y, large_comp);
+ }
+
+ /* move all components after the first to the top level */
+ TransferLinks(Up(g), large_comp, NextDown(Up(y)));
+
+ /* change the size of y to its new, smaller value */
+ fwd(y, ROWM) = fwd(row_thread, ROWM) = fwd(large_comp, ROWM)
+ = fwd(large_comp_split, ROWM) = fwd(prev, ROWM);
+
+ /* set link to the link of the first thing before y which is not an index */
+ for( link = PrevDown(Up(y)); type(link) == LINK; link = PrevDown(link) )
+ { Child(index, link);
+ if( !is_index(type(index)) ) break;
+ }
+
+ /* for each index, find where it's pointing and possibly move it */
+ while( NextDown(link) != Up(y) )
+ { Child(index, NextDown(link));
+ assert( is_index(type(index)), "MoveIndexes: is_index!" );
+ z = FindTarget(index);
+ if( z != nilobj )
+ { z = WhichComponent(z);
+ if( z != nilobj && z != y )
+ { MoveLink(NextDown(link), Up(z), PARENT);
+ }
+ else link = NextDown(link);
+ }
+ else link = NextDown(link);
+ }
+
+ debug1(DVH, D, "] VerticalHyphenate returning TRUE (y: %s)",
+ EchoLength(size(y, ROWM)));
+ debug0(DVH, DD, "galley after vertical hyphenation:");
+ ifdebug(DVH, DD, Parent(z, Up(y)); DebugGalley(z, y, 2));
+ return TRUE;
+ } /* end VerticalHyphenate */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static OBJECT BuildMergeTree(int n, OBJECT x, OBJECT *lenv, *lact) */
+ /* */
+ /* Build a balanced tree of n-1 @Merge symbols, whose parameters are the */
+ /* first n children of x. Return in lenv the environment of the root */
+ /* @Merge symbol, and in *lact the symbol table entry for the parent of */
+ /* this @Merge symbol. */
+ /* */
+ /*****************************************************************************/
+
+ static OBJECT BuildMergeTree(int n, OBJECT x, OBJECT *lenv, OBJECT *lact)
+ { OBJECT res, merge, link, y, l, r, env, act, left_par, right_par;
+ debug2(DHY, DD, "BuildMergeTree(%d, %s, -. -)", n, EchoObject(x));
+
+ if( n == 1 )
+ { New(res, ENV_OBJ);
+ Child(y, Down(x));
+ MoveLink(Down(x), res, PARENT);
+ assert(type(y)==CLOSURE && has_merge(actual(y)), "BuildMergeTree: has_m!");
+ *lact = actual(y);
+ *lenv = DetachEnv(y);
+ AttachEnv(*lenv, res);
+ }
+ else
+ {
+ /* build the two subtrees */
+ l = BuildMergeTree(n/2, x, lenv, lact);
+ r = BuildMergeTree( n - n/2, x, &env, &act);
+
+ /* set merge to new @Merge closure */
+ for( link = Down(act); link != act; link = NextDown(link) )
+ { Child(y, link);
+ if( is_merge(y) ) break;
+ }
+ assert( y != act, "BuildMergeTree: y!" );
+ New(merge, CLOSURE);
+ actual(merge) = y;
+
+ /* build left parameter of the new @Merge */
+ New(left_par, PAR);
+ actual(left_par) = ChildSym(y, LPAR);
+ Link(merge, left_par);
+ Link(left_par, l);
+
+ /* build right parameter of the new @Merge */
+ New(right_par, PAR);
+ actual(right_par) = ChildSym(y, RPAR);
+ Link(merge, right_par);
+ Link(right_par, r);
+
+ New(res, ENV_OBJ);
+ Link(res, merge);
+ Link(res, env);
+ }
+
+ debug2(DHY, DD, "BuildMergeTree returning %s (*lact = %s)",
+ EchoObject(res), SymName(*lact));
+ return res;
+ } /* end BuildMergeTree */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT ConvertGalleyList(x) */
+ /* */
+ /* Convert a set of galleys x into a single galley containing a balanced */
+ /* tree of @Merge symbols. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT ConvertGalleyList(OBJECT x)
+ { OBJECT res, y, link, junk1, junk2, obj; int n;
+ debug1(DHY, DD, "ConvertGalleyList(%s)", EchoObject(x));
+ Child(res, Down(x));
+ Child(y, Down(res));
+ MoveLink(Down(x), y, CHILD);
+ DeleteLink(Down(res));
+ MoveLink(Up(x), res, CHILD);
+ for( link = Down(x), n = 0; link != x; link = NextDown(link), n++ );
+ y = BuildMergeTree(n, x, &junk1, &junk2);
+ assert( Down(x) == x && Up(x) == x, "ConvertGalleyList: x!" );
+ Dispose(x);
+ Child(obj, Down(y));
+ MoveLink(Down(y), res, PARENT);
+ MoveLink(LastDown(y), obj, PARENT);
+ assert( Down(y) == y && Up(y) == y, "ConvertGalleyList: y!" );
+ Dispose(y);
+ debug0(DHY, DD, "ConvertGalleyList returning, res =");
+ ifdebug(DHY, DD, DebugObject(res));
+ return res;
+ } /* end ConvertGalleyList */
+
+
+ /*****************************************************************************/
+ /* */
+ /* OBJECT BuildEnclose(hd) */
+ /* */
+ /* Build the @Enclose object for galley hd. */
+ /* */
+ /*****************************************************************************/
+
+ OBJECT BuildEnclose(OBJECT hd)
+ { OBJECT sym, parsym, x, y, link, par, val, env, res;
+ debug1(DOM, D, "BuildEnclose(%s)", SymName(actual(hd)));
+
+ /* find @Enclose symbol and check that it has just one parameter */
+ for( link = Down(actual(hd)); link != actual(hd); link = NextDown(link) )
+ { Child(sym, link);
+ if( is_enclose(sym) ) break;
+ }
+ assert( link != actual(hd), "BuildEnclose: no enclose!" );
+ parsym = nilobj;
+ for( link = Down(sym); link != sym; link = NextDown(link) )
+ { Child(y, link);
+ switch( type(y) )
+ {
+ case LPAR:
+ case NPAR:
+
+ Error(44, 1, "%s may not have a left or named parameter", FATAL,
+ &fpos(y), KW_ENCLOSE);
+ break;
+
+
+ case RPAR:
+
+ if( has_body(sym) )
+ Error(44, 2, "%s may not have a body parameter", FATAL,
+ &fpos(y), KW_ENCLOSE);
+ parsym = y;
+ break;
+
+
+ default:
+
+ break;
+ }
+ }
+ if( parsym == nilobj )
+ Error(44, 3, "%s must have a right parameter", FATAL, &fpos(sym),KW_ENCLOSE);
+
+ /* set x to new @Enclose closure with dummy actual right parameter */
+ New(x, CLOSURE);
+ FposCopy(fpos(x), fpos(hd));
+ actual(x) = sym;
+ New(par, PAR);
+ FposCopy(fpos(par), fpos(hd));
+ actual(par) = parsym;
+ Link(x, par);
+ val = MakeWord(WORD, AsciiToFull("??"), &fpos(hd));
+ Link(par, val);
+
+ /* set env to the appropriate environment for this symbol */
+ /* strictly speaking y should not be included if sym is a parameter */
+ Child(y, Down(hd));
+ assert(type(y) == CLOSURE, "BuildEnclose: hd child!");
+ y = CopyObject(y, &fpos(hd));
+ env = SetEnv(y, nilobj);
+
+ /* build res, an ENV_OBJ with x at left and env at right */
+ New(res, ENV_OBJ);
+ Link(res, x);
+ Link(res, env);
+
+ debug1(DOM, D, "BuildEnclose returning %s", EchoObject(res));
+ return res;
+ } /* end BuildEnclose */
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z45.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z45.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z45.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,238 ----
+ /*@z45.c:External Sort:SortFile()@********************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z45.c */
+ /* MODULE: External Sort */
+ /* EXTERNS: SortFile() */
+ /* */
+ /* This simple sort utility assumes that the source file can all be read */
+ /* into memory. If not, you get an "out of memory" error message. */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+ #define BUFF_SIZE 4096 /* size of one memory buffer */
+ #define LINES_GUESS 2000 /* initial guess of number of lines */
+
+
+ /*****************************************************************************/
+ /* */
+ /* LINE *ReadLines(FILE *fp, FULL_CHAR *fname, FULL_CHAR *first_line, *len) */
+ /* */
+ /* Read all of the lines of fp into memory and return a null-terminated */
+ /* array of pointers to these lines, and set *len to the number of lines. */
+ /* Make sure the lines themselves are null-terminated, also. */
+ /* */
+ /* fname is the name of the file being sorted, and is used for error */
+ /* messages only. */
+ /* */
+ /* if first_line is non-null then it is a pointer to a string which is */
+ /* to become as the first line of the result. This string needs copying. */
+ /* */
+ /*****************************************************************************/
+
+ LINE *ReadLines(FILE *fp, FULL_CHAR *fname, FULL_CHAR *first_line, int *len)
+ {
+ char *buff; /* the current input line buffer */
+ char *buff_top; /* first spot off end of buffer */
+ char *bp; /* first free spot in buff */
+
+ LINE *lines; /* the array of pointers to lines */
+ int lines_length; /* the length of the lines array */
+ LINE *lines_top; /* first spot off end of lines */
+ LINE *lp; /* first free spot in lines */
+
+ char *p, *q;
+ int ch;
+ debug1(DEX, D, "ReadLines(-, %s, -)", fname);
+
+ /* initialize buff to be empty with size BUFF_SIZE */
+ buff = malloc(BUFF_SIZE * sizeof(char));
+ if( buff == NULL )
+ Error(45, 1, "run out of memory when reading index file %s",
+ FATAL, no_fpos, fname);
+ buff_top = buff + BUFF_SIZE;
+ bp = buff;
+
+ /* initialize the lines buffer to be the first line */
+ lines_length = LINES_GUESS;
+ lines = malloc(lines_length * sizeof(LINE *));
+ lines_top = &lines[lines_length];
+ lp = lines;
+
+ /* add first_line to lines buffer if required */
+ if( first_line != (FULL_CHAR *) null )
+ {
+ *lp = malloc((StringLength(first_line) + 1) * sizeof(char));
+ StringCopy( (char *) *lp, first_line);
+ lp++;
+ }
+
+ *lp++ = bp;
+ while( (ch = getc(fp)) != EOF )
+ {
+ debug4(DEX, DD, "lines: [%d %d(%d) %d]",
+ (int) lines, (int) (lp-1), (int) *(lp-1), (int) lines_top -1);
+ debug3(DEX, DD, " buff: [%d bp %d %d]",
+ (int) buff, (int) bp, (int) buff_top - 1);
+ assert( (int) buff >= (int) lines_top ||
+ (int) buff_top <= (int) lines,
+ "ReadLines: lines and buff overlap!" );
+
+ /* get new buffer and copy current line across if out of buff space */
+ if( bp == buff_top )
+ {
+ debug0(DEX, D, " getting new buff");
+ buff = malloc(BUFF_SIZE * sizeof(char));
+ if( buff == NULL )
+ Error(45, 2, "run out of memory when reading index file %s",
+ FATAL, no_fpos, fname);
+ buff_top = buff + BUFF_SIZE;
+ for( p = buff, q = *(lp-1); q != bp; *p++ = *q++ );
+ bp = p; *bp = '\0';
+ debug1(DEX, D, " copied into new buff: %s", buff);
+ *(lp-1) = buff;
+ if( bp == buff_top )
+ Error(45, 3, "line too long when reading index file %s",
+ FATAL, no_fpos, fname);
+ }
+
+ /* if newline char, end this line and start the next */
+ if( ch == '\n' )
+ {
+ *bp++ = '\0';
+ debug1(DEX, D, " finished line: %s", *(lp-1));
+
+ /* if no room in lines for next line, double its size */
+ if( lp == lines_top )
+ {
+ debug1(DEX, D, " realloc(lines, %d)", 2 * lines_length);
+ lines = realloc(lines, 2 * lines_length * sizeof(LINE *));
+ if( lines == NULL )
+ Error(45, 4, "run out of memory when reading index file %s",
+ FATAL, no_fpos, fname);
+ lp = &lines[lines_length];
+ lines_length = 2 * lines_length;
+ lines_top = &lines[lines_length];
+ }
+
+ *lp++ = bp;
+ }
+ else /* ordinary char with space available, so just add it */
+ {
+ *bp++ = ch;
+ }
+ }
+
+ *len = (lp - lines - 1);
+ debug1(DEX, D, "ReadLines returning (len = %d)", *len);
+ return lines;
+
+ } /* end ReadLines */
+
+
+ /*****************************************************************************/
+ /* */
+ /* WriteLines(FILE *fp, LINE *lines, int len) */
+ /* */
+ /* Write array of lines "lines", of length len, to file fp. */
+ /* */
+ /*****************************************************************************/
+
+ void WriteLines(FILE *fp, LINE *lines, int len)
+ { int i;
+ for( i = 0; i < len; i++ )
+ { fputs(lines[i], fp);
+ fputs("\n", fp);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* Line comparison functions (for qsort) */
+ /* */
+ /* By Jeff Kingston and Valery Ushakov (uwe). */
+ /* */
+ /*****************************************************************************/
+
+ static int pstrcmp(const void *a, const void *b) /* !UseCollate */
+ {
+ return strcmp (*(char **)a, *(char **)b);
+ }
+
+ static int pstrcollcmp(const void *a, const void *b) /* UseCollate */
+ {
+ return strcollcmp (*(char **)a, *(char**)b);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void SortLines(LINE *lines, int lines_len) */
+ /* */
+ /* Sort the given lines. */
+ /* */
+ /*****************************************************************************/
+
+ void SortLines(LINE *lines, int lines_len)
+ {
+ qsort(lines, lines_len, sizeof(LINE), (UseCollate ? pstrcollcmp : pstrcmp));
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void SortFile(char *infile, char *outfile) */
+ /* */
+ /* Sort file infile, placing the result on file outfile. */
+ /* */
+ /*****************************************************************************/
+
+ void SortFile(FULL_CHAR *infile, FULL_CHAR *outfile)
+ {
+ LINE *lines;
+ int lines_len;
+ FILE *in_fp, *out_fp;
+ debug2(DEX, D, "SortFile(%s, %s)", infile, outfile);
+
+ /* open input file */
+ in_fp = fopen( (char *) infile, READ_BINARY);
+ if( in_fp == (FILE *) NULL )
+ Error(45, 5, "cannot open index file %s for reading",
+ FATAL, no_fpos, outfile);
+
+ /* open output file */
+ out_fp = fopen( (char *) outfile, WRITE_BINARY);
+ if( out_fp == (FILE *) NULL )
+ Error(45, 6, "cannot open index file %s for writing",
+ FATAL, no_fpos, outfile);
+
+ /* read lines, sort them, and write them out again sorted */
+ lines = ReadLines(in_fp, infile, (FULL_CHAR *) NULL, &lines_len);
+ SortLines(lines, lines_len);
+ fclose(in_fp);
+ WriteLines(out_fp, lines, lines_len);
+ fclose(out_fp);
+ }
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z46.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z46.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z46.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,481 ----
+ /*@z46.c:Optimal Galleys:FindOptimize()@**************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z46.c */
+ /* MODULE: Optimal Galleys */
+ /* EXTERNS: FindOptimize(), SetOptimize(), GazumpOptimize(), */
+ /* CalculateOptimize(), DebugOptimize() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN FindOptimize(x, env) */
+ /* */
+ /* Object x is a CLOSURE which represents an at present unsized galley. */
+ /* Return TRUE if x has an @Optimize parameter which is Yes. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN FindOptimize(OBJECT x, OBJECT env)
+ { OBJECT y, link, res;
+ OBJECT bt[2], ft[2], ntarget, nenclose, crs;
+ debug1(DOG, D, "FindOptimize( %s )", EchoObject(x));
+ assert( type(x) == CLOSURE, "FindOptimize: type(x) != CLOSURE!" );
+ assert( has_target(actual(x)), "FindOptimize: x has no target!" );
+
+ /* search the parameter list of x for @Optimize */
+ res = nilobj;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == PAR && is_optimize(actual(y)) )
+ { assert( Down(y) != y, "FindOptimize: Down(PAR)!" );
+ Child(res, Down(y));
+ res = CopyObject(res, &fpos(x));
+ break;
+ }
+ }
+
+ /* search the children list of actual(x) for a default value of @Target */
+ if( res == nilobj )
+ for( link = Down(actual(x)); link != actual(x); link = NextDown(link) )
+ { Child(y, link);
+ if( is_optimize(y) )
+ { res = CopyObject(sym_body(y), &fpos(x));
+ break;
+ }
+ }
+
+ /* should have found it by now */
+ assert( res != nilobj, "FindOptimize: res == nilobj!" );
+
+ /* manifest and tidy the parameter, return TRUE if Yes */
+ bt[COLM] = ft[COLM] = bt[ROWM] = ft[ROWM] = ntarget = nenclose = crs = nilobj;
+ res = Manifest(res, env, &save_style(x), bt, ft, &ntarget, &crs, TRUE, FALSE,
+ &nenclose, FALSE);
+ res = ReplaceWithTidy(res, TRUE);
+ if( !is_word(type(res)) )
+ { Error(46, 1, "unable to evaluate %s parameter, assuming value is No",
+ WARN, &fpos(x), KW_OPTIMIZE);
+ debug2(DOG, D, "FindOptimize returning FALSE; found %s %s",
+ Image(type(res)), EchoObject(res));
+ return FALSE;
+ }
+ else if( StringEqual(string(res), AsciiToFull("Yes")) )
+ { debug0(DOG, D, "FindOptimize returning TRUE");
+ return TRUE;
+ }
+ else if( StringEqual(string(res), AsciiToFull("No")) )
+ { debug0(DOG, D, "FindOptimize returning FALSE");
+ return FALSE;
+ }
+ else
+ { Error(46, 2, "value of %s operator is neither Yes nor No, assuming No",
+ WARN, &fpos(x), KW_OPTIMIZE);
+ debug1(DOG, D, "FindOptimize returning FALSE (found WORD %s)", string(res));
+ return FALSE;
+ }
+ } /* end FindOptimize */
+
+
+ /*****************************************************************************/
+ /* */
+ /* SetOptimize(hd, style) */
+ /* */
+ /* Initialize the optimization data of galley hd. Search the cross ref */
+ /* database for information about its fate on the previous run. */
+ /* */
+ /*****************************************************************************/
+
+ void SetOptimize(OBJECT hd, STYLE *style)
+ { FULL_CHAR buff[MAX_BUFF], seq[MAX_BUFF];
+ OBJECT res, y, link, z; FILE_NUM dfnum; long dfpos, cont; int dlnum;
+ debug2(DOG, D, "SetOptimize(%s, %s)", SymName(actual(hd)), EchoStyle(style));
+
+ /* set opt_counts(hd) to result of previous run, if any */
+ StringCopy(buff, SymName(actual(hd)));
+ StringCat(buff, AsciiToFull("."));
+ StringCat(buff, StringInt(line_num(fpos(hd))));
+ if( DbRetrieve(OldCrossDb, FALSE, OptGallSym, buff, seq, &dfnum,
+ &dfpos, &dlnum, &cont) )
+ {
+ SwitchScope(nilobj);
+ res = ReadFromFile(dfnum, dfpos, dlnum);
+ UnSwitchScope(nilobj);
+ assert( res != nilobj, "SetOptimize: res == nilobj!" );
+ assert( type(res) == CLOSURE, "SetOptimize: type(res) != CLOSURE!" );
+ assert( actual(res) == OptGallSym, "SetOptimize: actual(res) != Opt!" );
+ assert( Down(res) != res, "SetOptimize: Down(res) == res!" );
+ Child(y, Down(res));
+ assert( type(y) == PAR, "SetOptimize: type(y) != PAR!" );
+ Child(y, Down(y));
+ assert( type(y) == ACAT, "SetOptimize: type(y) != ACAT!" );
+ y = ReplaceWithTidy(y, FALSE);
+ opt_hyph(hd) = FALSE;
+ assert( type(y) == ACAT, "SetOptimize: type(y) != ACAT (2)!" );
+ for( link = y; NextDown(link) != y; link = NextDown(link) )
+ { Child(z, NextDown(link));
+ if( type(z) == GAP_OBJ )
+ { DisposeChild(NextDown(link));
+ link = PrevDown(link);
+ }
+ else if( is_word(type(z)) )
+ { if( StringEqual(string(z), AsciiToFull("h")) )
+ { opt_hyph(hd) = TRUE;
+ DisposeChild(NextDown(link));
+ link = PrevDown(link);
+ }
+ else
+ { int num = 0;
+ sscanf( (char *) string(z), "%d", &num);
+ assert( num > 0, "SetOptimize: num <= 0!" );
+ comp_count(z) = num;
+ }
+ }
+ else
+ { assert( FALSE, "SetOptimize: type(z)!" );
+ }
+ }
+ DeleteLink(Up(y));
+ DisposeObject(res);
+ opt_counts(hd) = y;
+ }
+ else opt_counts(hd) = nilobj;
+
+ /* set up first opt_comps_permitted value */
+ if( opt_counts(hd) != nilobj && Down(opt_counts(hd)) != opt_counts(hd) )
+ { Child(z, Down(opt_counts(hd)));
+ opt_comps_permitted(hd) = comp_count(z) - 1;
+ DisposeChild(Up(z));
+ }
+ else opt_comps_permitted(hd) = MAX_FILES; /* a large number */
+ debug1(DOG, D, " initial permitted = %2d", opt_comps_permitted(hd));
+
+ /* set opt_components(hd) and opt_constraints(hd) for storing this run */
+ New(opt_components(hd), ACAT);
+ opt_gazumped(hd) = FALSE;
+ New(opt_constraints(hd), ACAT);
+ StyleCopy(save_style(opt_components(hd)), *style);
+ if( gall_dir(hd) == ROWM )
+ hyph_style(save_style(opt_components(hd))) = HYPH_OFF;
+
+ debug0(DOG, D, "SetOptimize returning:");
+ ifdebug(DOG, D, DebugOptimize(hd));
+ } /* end SetOptimize */
+
+
+ /*****************************************************************************/
+ /* */
+ /* GazumpOptimize(hd, dest) */
+ /* */
+ /* Optimizing galley hd, currently attached to @Galley dest, is to be */
+ /* gazumped by some other galley. Record the current size constraint and */
+ /* add &1rt {} to the list of components. */
+ /* */
+ /*****************************************************************************/
+
+ void GazumpOptimize(OBJECT hd, OBJECT dest)
+ { OBJECT g, tmp, junk, prnt;
+
+ debug2(DOG, D, "GazumpOptimize(%s, %s)", SymName(actual(hd)),
+ EchoObject(dest));
+ assert( type(hd) == HEAD, "GazumpOptimize: type(hd) != HEAD!" );
+ assert( opt_components(hd) != nilobj, "GazumpOptimize: opt_c!" );
+
+ /* record the size of this just-completed target area for hd */
+ New(tmp, WIDE);
+ if( (gall_dir(hd) == COLM && external_hor(dest)) ||
+ (gall_dir(hd) == COLM && external_hor(dest)) )
+ { SetConstraint(constraint(tmp), MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);
+ }
+ else
+ { Parent(prnt, Up(dest));
+ Constrained(prnt, &constraint(tmp), gall_dir(hd), &junk);
+ }
+ Link(opt_constraints(hd), tmp);
+ debug2(DOG, D, "GazumpOptimize(%s) adding constraint %s",
+ SymName(actual(hd)), EchoConstraint(&constraint(tmp)));
+
+ /* optimizing galley is being gazumped; record this as &1rt {} &1c */
+ if( LastDown(opt_components(hd)) != opt_components(hd) )
+ { Child(g, LastDown(opt_components(hd)));
+ assert( type(g) == GAP_OBJ, "FlushGalley: type(g) != GAP_OBJ!" );
+
+ /* ***
+ SetGap(gap(g), FALSE, FALSE, TRUE, FRAME_UNIT, EDGE_MODE, 2 * FR);
+ if( Down(g) == g )
+ { junk = MakeWord(WORD, AsciiToFull("2b"), &fpos(g));
+ Link(g, junk);
+ }
+ *** */
+
+ /* first we overwrite whatever is there now by &1rt */
+ SetGap(gap(g), FALSE, FALSE, TRUE, AVAIL_UNIT, TAB_MODE, 1 * FR);
+ if( Down(g) != g ) DisposeChild(Down(g));
+ tmp = MakeWord(WORD, AsciiToFull("1rt"), &fpos(g));
+ Link(g, tmp);
+
+ /* next we add an empty word */
+ tmp = MakeWord(WORD, STR_EMPTY, &fpos(g));
+ back(tmp, COLM) = fwd(tmp, COLM) = 0;
+ back(tmp, ROWM) = fwd(tmp, ROWM) = 0;
+ word_font(tmp) = word_colour(tmp) = 0;
+ word_outline(tmp) = FALSE;
+ word_language(tmp) = word_hyph(tmp) = 0;
+ Link(opt_components(hd), tmp);
+
+ /* finally we add &1c */
+ New(g, GAP_OBJ);
+ hspace(g) = 1; vspace(g) = 0;
+ FposCopy(fpos(g), fpos(tmp));
+ SetGap(gap(g), FALSE, FALSE, TRUE, FIXED_UNIT, EDGE_MODE, 1 * CM);
+ tmp = MakeWord(WORD, AsciiToFull("1c"), &fpos(g));
+ Link(g, tmp);
+ Link(opt_components(hd), g);
+
+ opt_gazumped(hd) = TRUE;
+ debug2(DOG, D, "GazumpOptimize(%s) new gap is %s",
+ SymName(actual(hd)), EchoGap(&gap(g)));
+ }
+
+ /* refresh the number of comps permitted into the next target */
+ if( opt_counts(hd) != nilobj && Down(opt_counts(hd)) != opt_counts(hd) )
+ { Child(tmp, Down(opt_counts(hd)));
+ opt_comps_permitted(hd) += comp_count(tmp) - 1;
+ DisposeChild(Up(tmp));
+ }
+ else opt_comps_permitted(hd) = MAX_FILES;
+
+ debug1(DOG, D, "GazumpOptimize returning, permitted = %2d",
+ opt_comps_permitted(hd));
+ } /* end GazumpOptimize */
+
+
+ /*****************************************************************************/
+ /* */
+ /* CalculateOptimize(hd) */
+ /* */
+ /* Calculate the optimal break for galley hd and write the result into */
+ /* the cross reference database. */
+ /* */
+ /*****************************************************************************/
+
+ void CalculateOptimize(OBJECT hd)
+ { OBJECT z, y, ylink, og, og_par, para, link, wd, g, last;
+ int count, compcount; FULL_CHAR buff[MAX_BUFF];
+ FILE_NUM fnum; int write_pos, write_lnum; BOOLEAN hyph_used;
+ debug1(DOG, D, "CalculateOptimize(%s)", SymName(actual(hd)));
+
+ /* delete the concluding GAP_OBJ stuck in by Promote() */
+ assert( LastDown(opt_components(hd)) != opt_components(hd), "CO!" );
+ Child(last, LastDown(opt_components(hd)));
+ assert( type(last) == GAP_OBJ, "CalculateOptimize: type(last)!" );
+ DisposeChild(Up(last));
+ ifdebug(DOG, D, DebugOptimize(hd));
+
+ /* break the paragraph; don't let user see any error messages */
+ assert( opt_constraints(hd) != nilobj, "KillGalley: no opt_constraints!" );
+ assert( Down(opt_constraints(hd)) != opt_constraints(hd), "KillGalleyo!" );
+ /* *** no longer needed since z14 doesn't refer to these fields
+ back(opt_components(hd), COLM) = 0;
+ fwd(opt_components(hd), COLM) = MAX_FULL_LENGTH;
+ *** */
+ Child(y, LastDown(opt_constraints(hd)));
+ EnterErrorBlock(FALSE);
+ opt_components(hd) = FillObject(opt_components(hd), &constraint(y),
+ opt_constraints(hd), FALSE, FALSE, TRUE, &hyph_used);
+ LeaveErrorBlock(FALSE);
+ debug1(DOG, D, "after breaking (%shyph_used):", hyph_used ? "" : "not ");
+ ifdebug(DOG, D, DebugOptimize(hd));
+
+ /* quit if one line only */
+ if( type(opt_components(hd)) != VCAT ||
+ Down(opt_components(hd)) == LastDown(opt_components(hd)) )
+ {
+ debug0(DOG, D, "CalculateOptimize returning (one target only)");
+ return;
+ }
+
+ /* construct a new @OptGall symbol */
+ New(og, CLOSURE);
+ actual(og) = OptGallSym;
+ FposCopy(fpos(og), fpos(hd));
+ New(og_par, PAR);
+ actual(og_par) = ChildSym(OptGallSym, RPAR);
+ Link(og, og_par);
+ New(para, ACAT);
+ Link(og_par, para);
+
+ /* begin with "h" if hyphenation was used */
+ if( hyph_used )
+ { wd = MakeWord(WORD, AsciiToFull("h"), &fpos(hd));
+ Link(para, wd);
+ }
+
+ /* attach words showing the number of components per target */
+ compcount = 0;
+ for( link = Down(opt_components(hd)); link != opt_components(hd);
+ link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) != ACAT ) continue;
+
+ /* let wd be a word containing the number of components in this target */
+ count = 0;
+ for( ylink = Down(y); ylink != y; ylink = NextDown(ylink) )
+ { Child(z, ylink);
+ if( type(z) != GAP_OBJ ) count++;
+ }
+ wd = MakeWord(WORD, StringInt(count), &fpos(y));
+
+ /* link wd to para, prepended by a gap if not first */
+ if( Down(para) != para )
+ { New(g, GAP_OBJ);
+ SetGap(gap(g), FALSE, FALSE, TRUE, FIXED_UNIT, EDGE_MODE, 1*EM);
+ if( ++compcount % 20 == 0 )
+ { hspace(g) = 0;
+ vspace(g) = 1;
+ }
+ else
+ { hspace(g) = 1;
+ vspace(g) = 0;
+ }
+ Link(para, g);
+ }
+ Link(para, wd);
+ }
+ debug2(DOG, D, "CalculateOptimize(%s) made object %s",
+ SymName(actual(hd)), EchoObject(og));
+
+ /* dispose the optimizing data structures */
+ DisposeObject(opt_components(hd));
+ opt_components(hd) = nilobj;
+ DisposeObject(opt_constraints(hd));
+ opt_constraints(hd) = nilobj;
+
+ /* write result onto cross-reference database */
+ if( AllowCrossDb )
+ {
+ /* construct a suitable tag for this galley's entry */
+ StringCopy(buff, SymName(actual(hd)));
+ StringCat(buff, AsciiToFull("."));
+ StringCat(buff, StringInt(line_num(fpos(hd))));
+ fnum = DatabaseFileNum(&fpos(hd));
+ AppendToFile(og, fnum, &write_pos, &write_lnum);
+ DbInsert(NewCrossDb, FALSE, OptGallSym, buff, &fpos(hd),
+ STR_ZERO, fnum, write_pos, write_lnum, FALSE);
+ }
+ debug0(DOG, D, "CalculateOptimize returning.");
+ }
+
+ #if DEBUG_ON
+ /*****************************************************************************/
+ /* */
+ /* DebugOptimizedAcat(x) */
+ /* */
+ /* Debug output of one line of optimized ACAT. */
+ /* */
+ /*****************************************************************************/
+
+ static void DebugOptimizedAcat(OBJECT x)
+ { OBJECT link, y;
+ assert( type(x) == ACAT, "DebugOptimizedAcat!" );
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ )
+ { debug1(DOG, D, " GAP_OBJ %s", EchoGap(&gap(y)));
+ }
+ else if( is_word(type(y)) )
+ { debug2(DOG, D, " word (%s, %s)", EchoLength(back(y, COLM)),
+ EchoLength(fwd(y, COLM)));
+ }
+ else
+ { debug1(DOG, D, " %s", Image(type(y)));
+ }
+ }
+ } /* end DebugOptimizedAcat */
+
+
+ /*****************************************************************************/
+ /* */
+ /* DebugOptimize(hd) */
+ /* */
+ /* Debug output of optimized galley hd. */
+ /* */
+ /*****************************************************************************/
+
+ void DebugOptimize(OBJECT hd)
+ { OBJECT link, y;
+
+ assert( opt_components(hd) != nilobj, "DebugOptimize!");
+ debug3(DOG, D, "Optimized Galley %s %sinto %s", SymName(actual(hd)),
+ gall_dir(hd) == COLM ? "horizontally " : "", SymName(whereto(hd)));
+
+ /* print components */
+ /* *** believe this now ***
+ if( type(opt_components(hd)) == ACAT )
+ DebugOptimizedAcat(opt_components(hd));
+ else if( type(opt_components(hd)) == VCAT )
+ {
+ for( link = Down(opt_components(hd)); link != opt_components(hd);
+ link = NextDown(link) )
+ {
+ Child(y, link);
+ if( type(y) == ACAT ) DebugOptimizedAcat(y);
+ debug0(DOG, D, "----------------");
+ }
+ }
+ else debug1(DOG, D, "? %s ?", Image(type(opt_components(hd))));
+ *** */
+ debug0(DOG, D, "components:");
+ ifdebug(DOG, D, DebugObject(opt_components(hd)));
+ debug0(DOG, D, "");
+
+ /* print constraints */
+ debug0(DOG, D, "constraints:");
+ for( link = Down(opt_constraints(hd)); link != opt_constraints(hd);
+ link = NextDown(link) )
+ {
+ Child(y, link);
+ debug1(DOG, D, "%s", EchoConstraint(&constraint(y)));
+ }
+ debug0(DOG, D, "");
+
+ /* print counts */
+ debug0(DOG, D, "counts");
+ if( opt_counts(hd) != nilobj )
+ {
+ if( opt_hyph(hd) )
+ fprintf(stderr, "hyph");
+ for( link = Down(opt_counts(hd)); link != opt_counts(hd);
+ link = NextDown(link) )
+ { Child(y, link);
+ fprintf(stderr, " %d", comp_count(y));
+ }
+ fprintf(stderr, "\n");
+ }
+ debug0(DOG, D, "");
+ } /* end DebugOptimize */
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z47.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z47.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z47.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,250 ----
+ /*@z47.c:Environment Table:EnvReadRetrieve()@*********************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z47.c */
+ /* MODULE: Environment Table */
+ /* EXTERNS: EnvInit(), EnvWriteRetrieve(), EnvWriteInsert(), */
+ /* EnvReadRetrieve(), EnvReadInsert() */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+ #define TAB_SIZE 211
+ #define MAX_CACHE 180
+
+ #define env_offset(x) back(x, ROWM)
+ #define env_lnum(x) line_num(fpos(x))
+ #define env_fnum(x) file_num(fpos(x))
+ #define env_read(x) sized(x)
+
+ static OBJECT env_cache; /* cache of envts in use */
+ static int cache_count; /* current size of cache */
+ static int stat_writes; /* calls to WriteRetrieve */
+ static int stat_write_hits; /* hits in WriteRetrieve */
+ static int stat_reads; /* calls to ReadRetrieve */
+ static int stat_read_hits; /* hits in ReadRetrieve */
+
+ static OBJECT tab[TAB_SIZE];
+
+ #define hash1(pos, env, fnum) \
+ { \
+ pos = ( (unsigned int) env + fnum ) % TAB_SIZE; \
+ }
+
+ #define hash2(pos, fnum, offset) \
+ { \
+ pos = ( offset + fnum ) % TAB_SIZE; \
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void EnvInit(void) */
+ /* */
+ /* Initialize this module. */
+ /* */
+ /*****************************************************************************/
+
+ void EnvInit(void)
+ { int i;
+ debug0(DET, DD, "EnvInit()");
+ stat_reads = 0;
+ stat_read_hits = 0;
+ stat_writes = 0;
+ stat_write_hits = 0;
+ New(env_cache, ACAT);
+ cache_count = 0;
+ for( i = 0; i < TAB_SIZE; i++ )
+ { tab[i] = nilobj;
+ }
+ debug0(DET, DD, "EnvInit returning");
+ } /* end EnvInit */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN EnvWriteRetrieve(OBJECT env, FILE_NUM fnum, int *offset, *lnum) */
+ /* */
+ /* Return the offset in file fnum where environment env has been written, */
+ /* or FALSE if env has not been written to this file. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN EnvWriteRetrieve(OBJECT env, FILE_NUM fnum, int *offset, int *lnum)
+ { unsigned int pos; OBJECT link, y, z;
+ debug2(DET, DD, "EnvWriteRetrieve(env %d, %s)", (int) env, FileName(fnum));
+ debug1(DET, DDD, " %s", EchoObject(env));
+ stat_writes++;
+ hash1(pos, env, fnum);
+ if( tab[pos] != nilobj )
+ {
+ for( link = Down(tab[pos]); link != tab[pos]; link = NextDown(link) )
+ { Child(y, link);
+ Child(z, Down(y));
+ if( env_fnum(y) == fnum && z == env && !env_read(y) )
+ { MoveLink(LastUp(y), env_cache, PARENT);
+ *offset = env_offset(y);
+ *lnum = env_lnum(y);
+ stat_write_hits++;
+ debug2(DET, DD, "EnvWriteRetrieve returning TRUE (offset %d, lnum %d)",
+ *offset, *lnum);
+ return TRUE;
+ }
+ }
+ }
+ debug0(DET, DD, "EnvWriteRetrieve returning FALSE");
+ return FALSE;
+ } /* end EnvWriteRetrieve */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void EnvWriteInsert(OBJECT env, FILE_NUM fnum, int offset, int lnum) */
+ /* */
+ /* Record the fact that environment env has been written to file fnum */
+ /* at the given offset. */
+ /* */
+ /*****************************************************************************/
+
+ void EnvWriteInsert(OBJECT env, FILE_NUM fnum, int offset, int lnum)
+ { unsigned int pos; OBJECT loser, x;
+ debug3(DET, DD, "EnvWriteInsert(env %d, %s, %d)", (int) env,
+ FileName(fnum), offset);
+
+ /* to limit the cache size, remove least recently used entry if full */
+ if( cache_count >= MAX_CACHE )
+ {
+ Child(loser, Down(env_cache));
+ DeleteLink(Up(loser));
+ DisposeChild(Up(loser));
+ cache_count--;
+ }
+
+ /* insert the new entry */
+ hash1(pos, env, fnum);
+ if( tab[pos] == nilobj ) New(tab[pos], ACAT);
+ New(x, ACAT);
+ env_fnum(x) = fnum;
+ env_offset(x) = offset;
+ env_lnum(x) = lnum;
+ env_read(x) = FALSE;
+ Link(tab[pos], x);
+ Link(env_cache, x);
+ Link(x, env);
+ cache_count++;
+
+ debug1(DET, DD, "EnvWriteInsert returning (cache_count = %d)", cache_count);
+ } /* end EnvWriteInsert */
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN EnvReadRetrieve(FILE_NUM fnum, int offset, OBJECT *env) */
+ /* */
+ /* Return the environment that appears in file fnum at the given offset, */
+ /* or FALSE if this is not currently known. */
+ /* */
+ /*****************************************************************************/
+
+ BOOLEAN EnvReadRetrieve(FILE_NUM fnum, int offset, OBJECT *env)
+ { int pos; OBJECT link, y, z;
+ debug2(DET, DD, "EnvReadRetrieve(%s, %d)", FileName(fnum), offset);
+ stat_reads++;
+
+ hash2(pos, fnum, offset);
+ if( tab[pos] != nilobj )
+ {
+ for( link = Down(tab[pos]); link != tab[pos]; link = NextDown(link) )
+ { Child(y, link);
+ Child(z, Down(y));
+ if( env_fnum(y) == fnum && env_offset(y) == offset && env_read(y) )
+ { MoveLink(LastUp(y), env_cache, PARENT);
+ Child(*env, Down(y));
+ stat_read_hits++;
+ debug1(DET, DD, "EnvReadRetrieve returning env %d", (int) *env);
+ return TRUE;
+ }
+ }
+ }
+ debug0(DET, DD, "EnvReadRetrieve returning FALSE");
+ return FALSE;
+ } /* end EnvReadRetrieve */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void EnvReadInsert(FILE_NUM fnum, int offset, OBJECT env) */
+ /* */
+ /* Record the fact that environment env has just been read from file fnum */
+ /* at position offset. */
+ /* */
+ /*****************************************************************************/
+
+ void EnvReadInsert(FILE_NUM fnum, int offset, OBJECT env)
+ { int pos; OBJECT x, loser;
+ debug3(DET, DD, "EnvReadInsert(%s, %d, env %d)",
+ FileName(fnum), offset, (int) env);
+
+ /* to limit the cache size, remove least recently used entry if full */
+ if( cache_count >= MAX_CACHE )
+ {
+ Child(loser, Down(env_cache));
+ DeleteLink(Up(loser));
+ DisposeChild(Up(loser));
+ cache_count--;
+ }
+
+ /* insert the new entry */
+ hash2(pos, fnum, offset);
+ if( tab[pos] == nilobj ) New(tab[pos], ACAT);
+ New(x, ACAT);
+ env_fnum(x) = fnum;
+ env_offset(x) = offset;
+ env_read(x) = TRUE;
+ Link(tab[pos], x);
+ Link(env_cache, x);
+ Link(x, env);
+ cache_count++;
+
+ debug1(DET, DD, "EnvReadInsert returning (cache_count = %d)", cache_count);
+ } /* end EnvReadInsert */
+
+
+ #if DEBUG_ON
+ /*****************************************************************************/
+ /* */
+ /* void EnvDebug() */
+ /* */
+ /* Debug statistics of this module's performance. */
+ /* */
+ /*****************************************************************************/
+
+ void EnvDebug(void)
+ {
+ debug3(DET, D, "Env Table %6s %6s %6s", "calls", "hits", "% hits");
+ debug3(DET, D, "reading %6d %6d %6.1f", stat_reads, stat_read_hits,
+ stat_reads == 0 ? (float) 0 : (float) 100 * stat_read_hits / stat_reads);
+ debug3(DET, D, "writing %6d %6d %6.1f", stat_writes, stat_write_hits,
+ stat_writes == 0 ? (float) 0 : (float) 100 * stat_write_hits / stat_writes);
+ } /* end EnvDebug */
+ #endif
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z48.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z48.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z48.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,3712 ----
+ /*@z48.c:PDF back end@********************************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This PDF Back End module written by Vincent Tan, March 1998. */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z48.c */
+ /* MODULE: PDF back end */
+ /* EXTERNS: PDFFile_Init(), PDFFile_BeginFontEncoding(), */
+ /* PDFFile_EndFontEncoding(), PDFFile_Cleanup(), */
+ /* PDFPage_Init(), PDFPage_Cleanup(), PDFPage_Write(), */
+ /* PDFPage_Push(), PDFPage_Pop(), PDFPage_Scale(), */
+ /* PDFPage_Translate(), PDFPage_Rotate(), PDFPage_SetVars(), */
+ /* PDFPage_WriteGraphic(), PDFPage_PrintUnderline(), */
+ /* PDFFont_AddFont(), PDFFont_Set(), PDFText_OpenXY(), */
+ /* PDFText_OpenX(), PDFText_Open(), PDFText_Kern(), */
+ /* PDFText_Close(), PDFHasValidTextMatrix() */
+ /* */
+ /*****************************************************************************/
+ #define PI 3.1415926535897931160
+ #include "externs.h"
+
+
+ /* ANSI headers */
+ #include <ctype.h>
+ #include <math.h>
+ #include <time.h>
+
+ /* zlib headers: define PDF_COMPRESSION = 0 if you don't have zlib library */
+ #if PDF_COMPRESSION
+ #include "zlib.h"
+ #endif
+
+ static void Assert(BOOLEAN condition, FILE_POS *inFilePos)
+ {
+ if (!condition) /* allows me to set a breakpoint here */
+ assert(condition, inFilePos);
+ }
+
+ /* #define's and typedefs */
+ #undef USE_MATRICES
+ #undef _CALC_LARGEST_PAGE_OBJECT_
+
+ enum {
+ kBase14FontCount = 14, /* there are 14 base PDF fonts */
+ kBufferSize = 1024 /* size of buffer for skipping non-marking commands */
+ };
+
+ #if PDF_COMPRESSION
+ enum {
+ kRawOutputBufferSize = 4096, /* arbitrary choice */
+ kCompressedOutputBufferSize = 4096 /* arbitrary choice */
+ };
+ #endif
+
+ enum {
+ kNumberOfObjectsPerBlock = 256, /* arbitrary choice */
+ kNumberOfPagesPerBlock = 64 /* arbitrary choice */
+ };
+
+ typedef enum {
+ kFitNoChange = 0, /* special default case */
+ kFit, /* [ /Fit ]: fit the page to the window */
+ kFitH, /* [ /FitH top ]: fit the width of the page to window; */
+ /* top specifies y-coord of the top edge of the window */
+ kFitV, /* [ /FitV left ]: fit the height of the page to the */
+ /* window. left specifies x-coord of left edge of win. */
+ kFitR, /* [ /FitR left bottom right top ]: fit the rectangle */
+ /* specified by left bottom right top in the window. */
+ /* If the height (top - bottom) and width (right-left) */
+ /* imply different zoom factors, the numerically */
+ /* smaller zoom factor is used, to ensure that the */
+ /* specified rectangle fits in the window */
+ kFitB, /* [ /FitB ]: fit the page's bounding box to window */
+ kFitBH, /* [ /FitBH top ]: fit the width of the page's bound. */
+ /* box to the window. top specifies the y-coordinate */
+ /* of the top edge of the window */
+ kFitBV, /* [ /FitBV left ]: fit the height of the page's */
+ /* bounding box to the window. left specifies the */
+ /* x-coordinate of the left edge of the window */
+
+ kNumberOfDestLinkOptions
+ } PDF_LINK_DEST_OPTION;
+
+ enum eUnitsKeywords {
+ k_in = 0,
+ k_cm,
+ k_pt,
+ k_em,
+ k_loutf,
+ k_loutv,
+ k_louts,
+ kNumberOfUnitKeywords
+ };
+
+ enum eGraphicsKeywords {
+ k_xsize = 0,
+ k_ysize,
+ k_xmark,
+ k_ymark,
+ kNumberOfGraphicsKeywords
+ };
+
+ enum eArithmeticKeywords {
+ k_add = 0,
+ k_sub,
+ k_mul,
+ k_div,
+ k_sin,
+ k_cos,
+ k_pick,
+ kNumberOfArithmeticKeywords
+ };
+
+ typedef enum {
+ k_link_source = 0, /* source of a link to an internal document target */
+ k_link_external, /* source of a link to an external document target */
+ k_link_URI, /* source of a link to an (external) URI target */
+ k_link_target, /* internal document target */
+ k_link_target_for_export, /* external document target */
+ kNumberOfLinkKeywords
+ } PDF_LINK_KEYWORD;
+
+ enum {
+ k_author = 0,
+ k_title,
+ k_subject,
+ k_keywords,
+ kNumberOfDocInfoKeywords
+ };
+
+
+ /* basic types */
+ #ifdef USE_MATRICES
+ typedef double t_matrix[9];
+ #endif
+
+ typedef char t_tempbuf[512];
+ typedef unsigned int PDF_OBJECT_NUM;
+ typedef PDF_OBJECT_NUM PDF_PAGE_OBJECT_NUM; /* an object number that can */
+ /* refer ONLY to page object */
+ typedef unsigned int PDF_FONT_NUM;
+ typedef unsigned int PDF_PAGE_NUM;
+ typedef unsigned int PDF_FILE_OFFSET;
+
+
+ /* font list */
+ struct t_font_list_entry {
+ struct t_font_list_entry *m_next_font_entry;
+ FULL_CHAR *m_PDF_font_name;
+ FULL_CHAR *m_short_font_name;
+ FULL_CHAR *m_actual_font_name;
+ PDF_OBJECT_NUM m_font_encoding_obj; /* valid for entire PDF file */
+ PDF_OBJECT_NUM m_pdf_object_number; /* valid for entire PDF file */
+ BOOLEAN m_font_resource_in_pdf; /* TRUE when PDF file has */
+ /* /Type /Font resource */
+ BOOLEAN m_in_use; /* used on a per-page basis */
+ };
+
+ typedef struct t_font_list_entry t_font_list_entry, *t_font_list_entry_ptr;
+
+
+ /* offsets of all objects (for xref list) */
+ typedef PDF_FILE_OFFSET t_offset_array[kNumberOfObjectsPerBlock];
+
+ struct t_offset_block {
+ struct t_offset_block *m_next_block;
+ t_offset_array m_block;
+ };
+
+ typedef struct t_offset_block t_offset_block, *t_offset_block_ptr;
+
+
+ /* for /Pages object */
+ typedef PDF_PAGE_OBJECT_NUM t_page_array[kNumberOfPagesPerBlock];
+
+ struct t_page_block {
+ struct t_page_block *m_next_block;
+ t_page_array m_block;
+ };
+
+ typedef struct t_page_block t_page_block, *t_page_block_ptr;
+
+
+ /* for font encodings */
+ struct t_font_encoding_entry {
+ struct t_font_encoding_entry* m_next_entry;
+ PDF_OBJECT_NUM m_object_num;
+ FULL_CHAR *m_font_encoding;
+ };
+
+ typedef struct t_font_encoding_entry
+ t_font_encoding_entry, *t_font_encoding_entry_ptr;
+
+
+ /* for qsave/qrestore [see PDFPage_Push()] */
+ struct t_qsave_entry {
+ struct t_qsave_entry *m_next_entry;
+ int m_page_h_origin, m_page_v_origin;
+ float m_page_h_scale_factor, m_page_v_scale_factor;
+ };
+
+ typedef struct t_qsave_entry t_qsave_entry, *t_qsave_entry_ptr;
+
+
+ /* for qsave/qrestore [see PDFPage_Push()] */
+ struct t_qsave_marking_entry {
+ struct t_qsave_marking_entry* m_next_entry;
+ unsigned int m_buffer_pos;
+ };
+
+ typedef struct t_qsave_marking_entry t_qsave_marking_entry, *t_qsave_marking_entry_ptr;
+
+
+ /* target of link annotations */
+ struct t_target_annot_entry {
+ struct t_target_annot_entry* m_next_entry;
+
+ /* all of the following are always defined */
+ FULL_CHAR *m_name;
+ PDF_PAGE_OBJECT_NUM m_page_object_num;
+
+ /* these are in PDF's default user space coordinates */
+ int m_ll_x;
+ int m_ll_y;
+ int m_ur_x;
+ int m_ur_y;
+
+ BOOLEAN m_for_export;
+ };
+
+ typedef struct t_target_annot_entry t_target_annot_entry, *t_target_annot_entry_ptr;
+
+ /* source of link annotations */
+ struct t_source_annot_entry {
+ struct t_source_annot_entry* m_next_entry;
+
+ t_target_annot_entry* m_target; /* if is a link and this is NULL then */
+ /* the link is a fwd link and remains */
+ /* unresolvable until the page is */
+ /* encountered - instead, the m_name */
+ /* field is defined; m_target will be */
+ /* NULL for URI type links */
+
+ FULL_CHAR *m_name; /* this string is defined if m_target */
+ /* is NULL otherwise it is null */
+ /* for URI links, this contains the */
+ /* URI to link to */
+ FULL_CHAR *m_file_spec; /* only defined for link_type == */
+ /* k_link_external */
+
+ /* all of the following are always defined */
+ /* these are in PDF's default user space coordinates */
+ int m_ll_x;
+ int m_ll_y;
+ int m_ur_x;
+ int m_ur_y;
+
+ PDF_OBJECT_NUM m_this_object_num; /* obj num of this "/Type /Annot" obj */
+ PDF_PAGE_OBJECT_NUM m_this_page_object_num; /* obj num of the page that */
+ /* this annot lies in */
+ PDF_LINK_DEST_OPTION m_dest_option;
+ PDF_LINK_KEYWORD m_link_type;
+
+ BOOLEAN m_written_to_PDF_file;
+ };
+
+ typedef struct t_source_annot_entry t_source_annot_entry, *t_source_annot_entry_ptr;
+
+
+ /* matrices */
+ #ifdef USE_MATRICES
+ struct t_matrix_entry {
+ struct t_matrix_entry* m_next_entry;
+ t_matrix m_matrix;
+ };
+
+ typedef struct t_matrix_entry t_matrix_entry, *t_matrix_entry_ptr;
+ #endif
+
+
+ /* statics */
+
+ /* general */
+ static BOOLEAN g_PDF_debug;
+
+ /* objects */
+ static PDF_OBJECT_NUM g_next_objnum;
+ static t_offset_block_ptr g_obj_offset_list; /* first block */
+ static t_offset_block_ptr g_cur_obj_offset_block;
+
+ /* fonts */
+ static t_font_list_entry_ptr g_font_list; /* backwards */
+ static t_font_encoding_entry_ptr g_font_encoding_list; /* backwards */
+
+ /* pages */
+ static PDF_PAGE_NUM g_page_count; /* current page num, */
+ /* starting at 1 */
+ static PDF_PAGE_OBJECT_NUM g_page_object_num; /* obj num of current*/
+ /* "/Type /Page" obj,*/
+ /* corr. to page */
+ /* num g_page_count */
+ static t_page_block_ptr g_page_block_list; /* first block */
+ static t_page_block_ptr g_cur_page_block;
+ static PDF_OBJECT_NUM g_pages_root;
+
+ /* document */
+ static int g_doc_h_bound;
+ static int g_doc_v_bound;
+ static FULL_CHAR* g_doc_author;
+ static FULL_CHAR* g_doc_title;
+ static FULL_CHAR* g_doc_subject;
+ static FULL_CHAR* g_doc_keywords;
+
+ /* link annotations */
+ static t_target_annot_entry_ptr g_target_annot_list;
+ static BOOLEAN g_has_exported_targets;
+
+ /* globals for each page */
+ /* these indicate what kind of content the page has */
+ static BOOLEAN g_page_uses_fonts;
+ static BOOLEAN g_page_has_text;
+ static BOOLEAN g_page_has_graphics;
+
+ /* these are only defined when the page has some content */
+ static PDF_OBJECT_NUM g_page_contents_obj_num;
+ static PDF_OBJECT_NUM g_page_length_obj_num;
+ static PDF_FILE_OFFSET g_page_start_offset;
+
+ /* valid after a PDF_Push and PDF_Pop */
+ static t_qsave_entry_ptr g_qsave_stack;
+
+ static t_qsave_marking_entry_ptr g_qsave_marking_stack; /* implemented as a */
+ /* linked list; pts */
+ /* to top of stack */
+ static BOOLEAN g_in_buffering_mode;
+ static char g_buffer[kBufferSize]; /* this buffer is used*/
+ /* for removing redundant operations */
+ static unsigned int g_buffer_pos;
+
+ /* valid after a link annotation has been defined */
+ static t_source_annot_entry_ptr g_source_annot_list;
+
+ #ifdef USE_MATRICES
+ static t_matrix g_cur_matrix;
+ static t_matrix_entry_ptr g_matrix_stack;
+ #endif
+
+ /* track these values in case they are ever required */
+ static float g_page_h_scale_factor, g_page_v_scale_factor;
+ static int g_page_h_origin, g_page_v_origin;
+ static int g_page_line_width;
+
+ /* magic keywords (actually they will appear in Lout documents as "__in", "__cm", etc.) */
+ static char *g_unit_keywords[kNumberOfUnitKeywords] =
+ {
+ "in", "cm", "pt", "em", "loutf", "loutv", "louts" /* MUST be followed by a fp number */
+ };
+
+ static char *g_graphic_keywords[kNumberOfGraphicsKeywords] =
+ {
+ "xsize", "ysize", "xmark", "ymark" /* like macros, these expand to the actual value */
+ };
+
+ static char *g_arithmetic_keywords[kNumberOfArithmeticKeywords] =
+ {
+ /* syntax: "__mul(x, y)" emits (x * y) to 2 decimal places */
+ /* */
+ /* Notes: */
+ /* */
+ /* sin and cos expect their arguments in degrees */
+ /* */
+ /* for negation, use "__sub(0, arg)" */
+ /* */
+ /* __pick(i, expr1, expr2, expr3...) picks the ith expr from the */
+ /* list of expr the "," are optional (if they are not used, you */
+ /* should separate values with whitespace) */
+
+ "add", "sub", "mul", "div", "sin", "cos", "pick" /* like macros, these expand to the actual value */
+ };
+
+ static char *g_link_keywords[kNumberOfLinkKeywords] =
+ {
+ /* syntax: "__link_source=<<name_of_target_link [dest_link_option]>>" */
+ /* */
+ /* example: "__link_source=<<chapter6>>" */
+ /* example: "__link_source=<<part7 __FitH>>" */
+
+ "link_source=<<",
+
+ /* syntax: "__link_external=<<name_of_target_link __link_to=file_spec>>"*/
+ /* syntax: "__link_external=<<name_of_target_link __link_to=<< /FS /URL /F (url)>>>>" */
+ /* */
+ /* ** note the special format required for URL links ** */
+ /* */
+ /* example: "__link_external=<<chapter6 __link_to=/usr/bin/file.pdf>>" */
+ /* example: "__link_external=<<chapter6 __link_to=<< /FS /URL /F */
+ /* (ftp://ftp.cs.usyd.edu.au/jeff/lout/user.pdf) >>>>" */
+
+ "link_external=<<",
+
+ /* syntax: "__link_URI=<<URL>>" */
+ /* */
+ /* example: "__link_URI=<<http://www.adobe.com>>" */
+
+ "link_URI=<<",
+
+ /* syntax: "__link_target=<<name_of_target_link>>" where */
+ /* name_of_target_link is in this PDF file; name_of_target_link CANNOT */
+ /* be accessed by external documents in links */
+ /* */
+ /* example: "__link_target=<<my_internal_target>>" */
+
+ "link_target=<<",
+
+ /* syntax: "__link_target_for_export=<<name_of_target_link>>" where */
+ /* name_of_target_link is in this file; name_of_target_link can be */
+ /* accessed by external documents in links */
+ /* */
+ /* example: "__link_target_for_export=<<my_exported_target>>" */
+
+ "link_target_for_export=<<"
+ };
+
+ static char *g_dest_link_options[kNumberOfDestLinkOptions] =
+ {
+ /* see PDF_LINK_DEST_OPTION for descriptions of the meanings of these */
+ "__FitNoChange",
+ "__Fit",
+ "__FitH",
+ "__FitV",
+ "__FitR",
+ "__FitB",
+ "__FitBH",
+ "__FitBV"
+ };
+
+ static char* g_external_file_spec_keyword[1] =
+ {
+ "__link_to="
+ };
+
+ static char* g_doc_info_keywords[kNumberOfDocInfoKeywords] =
+ {
+ "author=", "title=", "subject=", "keywords="
+ };
+
+ static int g_units[kNumberOfUnitKeywords];
+
+ static int g_graphics_vars[kNumberOfGraphicsKeywords];
+
+ /* text state */
+ static BOOLEAN g_TJ_pending;
+ static BOOLEAN g_ET_pending;
+ static BOOLEAN g_valid_text_matrix; /* true when BT...ET block open */
+
+
+ /* expressions */
+ static int g_expr_depth = 0;
+ static int g_expr_index;
+ static t_tempbuf g_expr;
+
+ /* links */
+ static int g_link_depth = 0;
+ static int g_link_index;
+ static t_tempbuf g_link;
+ static PDF_LINK_KEYWORD g_link_keyword;
+
+ /* the 14 base fonts */
+ static char *g_standard_base_14_fonts[kBase14FontCount] = {
+ "Courier",
+ "Courier-Bold",
+ "Courier-Oblique",
+ "Courier-BoldOblique",
+ "Helvetica",
+ "Helvetica-Bold",
+ "Helvetica-Oblique",
+ "Helvetica-BoldOblique",
+ "Symbol",
+ "Times",
+ "Times-Bold",
+ "Times-Italic",
+ "Times-BoldItalic",
+ "ZapfDingbats"
+ };
+
+
+ #if PDF_COMPRESSION
+ static BOOLEAN g_apply_compression;
+ static z_stream g_comp_stream; /* zlib compression stream */
+ static unsigned char* g_raw_buffer_ptr;
+
+ /* compression buffers */
+ static unsigned char g_raw_output[kRawOutputBufferSize];
+ static unsigned char g_compressed_output[kCompressedOutputBufferSize];
+ #endif
+
+ /* for calculating largest page object */
+ #ifdef _CALC_LARGEST_PAGE_OBJECT_
+ static PDF_FILE_OFFSET g_max_page_length = 0;
+ #endif
+
+ BOOLEAN PDFHasValidTextMatrix(void) /* this is called from z24.c */
+ {
+ return g_valid_text_matrix;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* t_offset_block_ptr PDFObject_FindOffsetBlock(PDF_OBJECT_NUM in_obj_num) */
+ /* */
+ /* Find the offset block for the given object number. */
+ /* */
+ /*****************************************************************************/
+
+ static t_offset_block_ptr PDFObject_FindOffsetBlock(PDF_OBJECT_NUM in_obj_num,
+ unsigned int* out_block_pos)
+ {
+ int wanted_block_num = (in_obj_num - 1) / kNumberOfObjectsPerBlock;
+ int block_pos = (in_obj_num - 1) % kNumberOfObjectsPerBlock;
+ t_offset_block_ptr the_block = g_obj_offset_list;
+
+ Assert((in_obj_num > 0) && (in_obj_num < g_next_objnum), no_fpos);
+
+ /* find block */
+ while (wanted_block_num != 0) {
+ Assert(the_block != NULL, no_fpos);
+ the_block = the_block->m_next_block;
+ wanted_block_num--;
+ }
+ Assert(the_block != NULL, no_fpos);
+
+ if (out_block_pos != NULL)
+ *out_block_pos = block_pos;
+ return the_block;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_OBJECT_NUM PDFObject_New(FILE* in_fp) */
+ /* */
+ /* Return the next available object number. */
+ /* */
+ /*****************************************************************************/
+
+ static PDF_OBJECT_NUM PDFObject_New(/* FILE* in_fp */)
+ {
+ int wanted_block_num = (g_next_objnum - 1) / kNumberOfObjectsPerBlock;
+ int block_pos = (g_next_objnum - 1) % kNumberOfObjectsPerBlock;
+ t_offset_block_ptr the_block = g_cur_obj_offset_block;
+
+ /* if first obj in a block then allocate the block */
+ if (block_pos == 0)
+ {
+ the_block = (t_offset_block_ptr) malloc(sizeof(t_offset_block));
+ if (the_block == NULL)
+ Error(48, 1, "PDFObject_New: run out of memory", FATAL, no_fpos);
+ if (wanted_block_num == 0) /* if first block in file */
+ {
+ Assert(g_obj_offset_list == NULL, no_fpos);
+ g_obj_offset_list = the_block;
+ }
+ else
+ {
+ Assert(g_cur_obj_offset_block != NULL, no_fpos);
+ g_cur_obj_offset_block->m_next_block = the_block;
+ }
+ the_block->m_next_block = NULL; /* don't forget to init this! */
+ g_cur_obj_offset_block = the_block;
+ }
+ else
+ {
+ Assert(the_block != NULL, no_fpos);
+ }
+
+ /* initialise the offset of this object to zero (it hasn't been written */
+ /* to the PDF file yet) */
+ the_block->m_block[block_pos] = 0; /* ftell(in_fp); */
+
+ return g_next_objnum++;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFObject_WriteRef(FILE* in_fp, PDF_OBJECT_NUM in_object_number) */
+ /* */
+ /* Return the next available object number and write a reference to it. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFObject_WriteRef(FILE* in_fp, PDF_OBJECT_NUM in_object_number)
+ {
+ fprintf(in_fp, "%u 0 R", in_object_number);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFObject_WriteObj(FILE* in_fp, PDF_OBJECT_NUM in_object_number) */
+ /* */
+ /* Write the object's definition (and remember its file position). */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFObject_WriteObj(FILE* in_fp, PDF_OBJECT_NUM in_object_number)
+ {
+ unsigned int block_pos;
+ t_offset_block_ptr block =
+ PDFObject_FindOffsetBlock(in_object_number, &block_pos);
+ Assert(block->m_block[block_pos]==0, no_fpos); /* offset shd be "unknown" */
+ block->m_block[block_pos] = ftell(in_fp); /* remember offset for xref */
+
+ fprintf(in_fp, "%u 0 obj\n", in_object_number);
+ }
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_OBJECT_NUM PDFObject_WriteNewObj(FILE* in_fp) */
+ /* */
+ /* Return the next available object number and write its definition. */
+ /* */
+ /*****************************************************************************/
+
+ static PDF_OBJECT_NUM PDFObject_WriteNewObj(FILE* in_fp)
+ {
+ PDF_OBJECT_NUM next_ref = PDFObject_New(/* in_fp */);
+ PDFObject_WriteObj(in_fp, next_ref);
+ return next_ref;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_OBJECT_NUM PDFObject_WriteNextRef(FILE* in_fp) */
+ /* */
+ /* Return the next available object number and write a reference to it. */
+ /* */
+ /*****************************************************************************/
+
+ /* ***
+ static PDF_OBJECT_NUM PDFObject_WriteNextRef(FILE* in_fp)
+ {
+ PDF_OBJECT_NUM next_ref = PDFObject_New(in_fp);
+ PDFObject_WriteRef(in_fp, next_ref);
+ return next_ref;
+ }
+ *** */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFFile_BeginFontEncoding(FILE* in_fp, const char* in_encoding_name) */
+ /* */
+ /* Begin font encoding. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFFile_BeginFontEncoding(FILE* in_fp, const char* in_encoding_name)
+ {
+ PDF_OBJECT_NUM encoding_num;
+ t_font_encoding_entry_ptr encoding_entry;
+
+ /* TO FILL IN: create entry in font-encoding list and add this encoding */
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% font encoding '%s':\n%%\n", in_encoding_name);
+
+ encoding_num = PDFObject_WriteNewObj(in_fp);
+ fputs("<<\n/Type /Encoding\n/Differences [ 0\n", in_fp);
+
+ /* add font encoding to list of encodings (assume we don't get passed the */
+ /* same encoding more than once) */
+ encoding_entry =
+ (t_font_encoding_entry_ptr) malloc(sizeof(t_font_encoding_entry));
+ if (encoding_entry == NULL)
+ Error(48, 2, "PDFFile_BeginFontEncoding: run out of memory",FATAL,no_fpos);
+
+ encoding_entry->m_font_encoding =
+ (FULL_CHAR*) malloc(strlen(in_encoding_name) + 1);
+ if (encoding_entry->m_font_encoding == NULL)
+ Error(48, 3, "PDFFile_BeginFontEncoding: out of memory", FATAL, no_fpos);
+
+ encoding_entry->m_next_entry = g_font_encoding_list;
+ encoding_entry->m_object_num = encoding_num;
+ strcpy((char*) encoding_entry->m_font_encoding, (char*) in_encoding_name);
+ g_font_encoding_list = encoding_entry;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFFile_EndFontEncoding(FILE* in_fp) */
+ /* */
+ /* End of font encoding. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFFile_EndFontEncoding(FILE* in_fp)
+ {
+ fputs("]\n>>\nendobj\n", in_fp);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* const FULL_CHAR* PDFFont_FindListEntry(const FULL_CHAR* in_real_font_name)*/
+ /* */
+ /* Try to find the font list entry with the specified real font name; */
+ /* return the entry's reference if found else return NULL. */
+ /* */
+ /*****************************************************************************/
+
+ static t_font_list_entry_ptr
+ PDFFont_FindListEntry(const FULL_CHAR* in_real_font_name)
+ {
+ t_font_list_entry_ptr entry = g_font_list;
+
+ while (entry != NULL) {
+ if (strcmp((char*)in_real_font_name, (char*)entry->m_actual_font_name)==0)
+ break;
+ entry = entry->m_next_font_entry;
+ }
+ return entry;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* const FULL_CHAR* */
+ /* PDFFont_FindListEntry_Short(const FULL_CHAR* in_short_font_name) */
+ /* */
+ /* Try to find the font list entry with the specified real font name; */
+ /* return the entry's reference if found else return NULL. */
+ /* */
+ /*****************************************************************************/
+
+ static t_font_list_entry_ptr
+ PDFFont_FindListEntry_Short(const FULL_CHAR* in_short_font_name)
+ {
+ t_font_list_entry_ptr entry = g_font_list;
+
+ while (entry != NULL) {
+ if (strcmp((char*)in_short_font_name, (char*)entry->m_short_font_name)==0)
+ break;
+ entry = entry->m_next_font_entry;
+ }
+ return entry;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* const t_font_list_entry_ptr PDFFont_NewListEntry( */
+ /* const FULL_CHAR* in_short_font_name, const FULL_CHAR* in_real_font_name)*/
+ /* */
+ /* Create a new font entry and return the short name of the font. */
+ /* */
+ /*****************************************************************************/
+
+ static t_font_list_entry_ptr
+ PDFFont_NewListEntry(const FULL_CHAR* in_short_font_name,
+ const FULL_CHAR* in_real_font_name,
+ PDF_OBJECT_NUM in_font_encoding_obj)
+ {
+ PDF_FONT_NUM next_font_num = 0;
+ t_font_list_entry_ptr new_entry = g_font_list;
+ /* t_font_list_entry_ptr last_font_list_entry = NULL; */
+
+ /* find next available font number */
+ {
+ while (new_entry != NULL) {
+ next_font_num++;
+ new_entry = new_entry->m_next_font_entry;
+ }
+ }
+
+ /* make a new font list entry */
+ {
+ char PDF_font_name[64] = "/F";
+ char num[32];
+
+ new_entry = (t_font_list_entry_ptr) malloc(sizeof(t_font_list_entry));
+ if (new_entry == NULL)
+ Error(48, 4, "PDFFont_NewListEntry: run out of memory", FATAL, no_fpos);
+
+ sprintf(num, "%u", next_font_num);
+ strcat(PDF_font_name, num);
+
+ new_entry->m_PDF_font_name =
+ (FULL_CHAR*) malloc(strlen((char*) PDF_font_name) + 1);
+ if (new_entry->m_PDF_font_name == NULL)
+ Error(48, 5, "PDFFont_NewListEntry: run out of memory", FATAL, no_fpos);
+ strcpy((char*) new_entry->m_PDF_font_name, PDF_font_name);
+
+ new_entry->m_short_font_name =
+ (FULL_CHAR*) malloc(strlen((char*) in_short_font_name) + 1);
+ if (new_entry->m_short_font_name == NULL)
+ Error(48, 6, "PDFFont_NewListEntry: run out of memory", FATAL, no_fpos);
+ strcpy((char*) new_entry->m_short_font_name, (char*) in_short_font_name);
+
+ new_entry->m_actual_font_name =
+ (FULL_CHAR*) malloc(strlen((char*) in_real_font_name) + 1);
+ if (new_entry->m_actual_font_name == NULL)
+ Error(48, 7, "PDFFont_NewListEntry: run out of memory", FATAL, no_fpos);
+ strcpy((char*) new_entry->m_actual_font_name, (char*) in_real_font_name);
+
+ new_entry->m_font_encoding_obj = in_font_encoding_obj;
+
+ new_entry->m_pdf_object_number = 0; /* don't give this font resource an */
+ /* object number until needed */
+ /* new_entry->m_in_use = TRUE; */ /* should be cleared after each page */
+ /* g_page_uses_fonts = TRUE; */
+ new_entry->m_font_resource_in_pdf = FALSE; /* not in PDF file yet */
+
+ new_entry->m_next_font_entry = g_font_list;
+ g_font_list = new_entry;
+ }
+ debug1(DPD, D, "new PDF font entry with short name %s",
+ new_entry->m_short_font_name);
+ return new_entry;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* const t_font_list_entry_ptr PDFGetFont(const char* in_real_font_name) */
+ /* */
+ /* Return the reference of a font entry. Never returns NULL. */
+ /* */
+ /*****************************************************************************/
+ /*
+ static t_font_list_entry_ptr PDFGetFont(const FULL_CHAR* in_real_font_name)
+ {
+ t_font_list_entry_ptr entry = PDFFont_FindListEntry(in_real_font_name);
+ if (entry == NULL)
+ entry = PDFFont_NewListEntry(in_real_font_name);
+ return entry;
+ }
+ */
+
+ /*****************************************************************************/
+ /* */
+ /* PDFFont_WriteObjectRef(FILE* in_fp, t_font_list_entry_ptr in_font_entry) */
+ /* */
+ /* Write a reference to the object to the file. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFFont_WriteObjectRef(FILE* in_fp,
+ const t_font_list_entry* in_font_entry)
+ {
+ Assert(in_font_entry->m_pdf_object_number != 0, no_fpos);
+ PDFObject_WriteRef(in_fp, in_font_entry->m_pdf_object_number);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFFont_WriteObject(FILE* in_fp, */
+ /* t_font_list_entry_ptr in_font_entry) */
+ /* */
+ /* Write a reference to the object to the file. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFFont_WriteObject(FILE* in_fp, t_font_list_entry_ptr in_font_entry)
+ {
+ if (in_font_entry->m_pdf_object_number == 0)
+ in_font_entry->m_pdf_object_number = PDFObject_New(/* in_fp */);
+ PDFObject_WriteObj(in_fp, in_font_entry->m_pdf_object_number);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* BOOLEAN PDFFont_IsOneOfTheBase14Fonts(const FULL_CHAR* in_real_font_name)*/
+ /* */
+ /* Returns true if given font is one of the base 14 fonts. */
+ /* */
+ /*****************************************************************************/
+
+ static BOOLEAN PDFFont_IsOneOfTheBase14Fonts(const FULL_CHAR* in_real_font_name)
+ {
+ int i;
+ for (i = 0; i < kBase14FontCount; i++)
+ if (strcmp(g_standard_base_14_fonts[i], (char*) in_real_font_name) == 0)
+ return TRUE;
+ return FALSE;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDFFont_WriteFontResource(FILE* in_fp, */
+ /* t_font_list_entry_ptr in_font_entry) */
+ /* */
+ /* Writes out the PDF idea of a Font resource. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFFont_WriteFontResource(FILE* in_fp,
+ t_font_list_entry_ptr in_font_entry)
+ {
+ if (! in_font_entry->m_font_resource_in_pdf)
+ {
+ in_font_entry->m_font_resource_in_pdf = TRUE;
+
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% declare use of font %s:\n%%\n",
+ in_font_entry->m_actual_font_name);
+
+ PDFFont_WriteObject(in_fp, in_font_entry);
+ fputs("<<\n/Type /Font\n/Subtype /Type1\n", in_fp);
+ fprintf(in_fp, "/Name %s\n", (char*) in_font_entry->m_PDF_font_name);
+ fprintf(in_fp, "/BaseFont /%s\n", (char*) in_font_entry->m_actual_font_name);
+ if (! PDFFont_IsOneOfTheBase14Fonts(in_font_entry->m_actual_font_name))
+ {
+ /* ***
+ fputs("/FirstChar 0"\n, in_fp); - we don't do first chars (yet)
+ fputs("/LastChar 255\n", in_fp); - we don't do last chars (yet)
+ fputs("/Widths ", in_fp); - we don't do last chars (yet)
+ fputs("/FontDescriptor ", in_fp); - we don't do font descriptors (yet)
+ *** */
+ }
+
+ if (in_font_entry->m_font_encoding_obj != 0)
+ {
+ fputs("/Encoding ", in_fp);
+ PDFObject_WriteRef(in_fp, in_font_entry->m_font_encoding_obj);
+ fputs("\n", in_fp);
+ }
+
+ /* ***
+ else
+ Error(48, 8, "PDFFont_WriteFontResource: a font has no encoding",
+ WARN, no_fpos);
+ *** */
+ fputs(">>\nendobj\n", in_fp);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDFFont_WriteFontResource_name(FILE* in_fp, */
+ /* const FULL_CHAR* in_real_font_name) */
+ /* */
+ /* Writes out the PDF idea of a Font resource. */
+ /* */
+ /*****************************************************************************/
+
+ /* ***
+ static void PDFFont_WriteFontResource_name(FILE* in_fp,
+ const FULL_CHAR* in_real_font_name)
+ {
+ t_font_list_entry_ptr entry = PDFFont_FindListEntry(in_real_font_name);
+ Assert(entry != NULL, no_fpos);
+ PDFFont_WriteFontResource(in_fp, entry);
+ }
+ *** */
+
+
+ /*****************************************************************************/
+ /* */
+ /* const FULL_CHAR* PDFGetPDFFontName(const FULL_CHAR* in_real_font_name) */
+ /* */
+ /* Return the short name of a font. */
+ /* */
+ /*****************************************************************************/
+
+ /* ***
+ static const FULL_CHAR* PDFGetPDFFontName(const FULL_CHAR* in_real_font_name)
+ {
+ t_font_list_entry_ptr entry = PDFFont_FindListEntry(in_real_font_name);
+ Assert(entry != NULL, no_fpos);
+ return entry->m_PDF_font_name;
+ }
+ *** */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_OBJECT_NUM PDFFont_FindFontEncoding(FULL_CHAR* in_font_encoding_name) */
+ /* */
+ /* Return the object number of a given font encoding. */
+ /* */
+ /*****************************************************************************/
+
+ static PDF_OBJECT_NUM PDFFont_FindFontEncoding(
+ const FULL_CHAR* in_font_encoding_name)
+ {
+ t_font_encoding_entry_ptr entry = g_font_encoding_list;
+
+ /* these two lines are Uwe patch Jul 18, 2000 */
+ if (in_font_encoding_name == NULL)
+ return 0;
+
+ while (entry != NULL)
+ {
+ if (strcmp((char*)in_font_encoding_name, (char*)entry->m_font_encoding)==0)
+ break;
+ entry = entry->m_next_entry;
+ }
+ return (entry != NULL) ? entry->m_object_num : 0;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFFont_AddFont( */
+ /* FILE* in_fp, const FULL_CHAR* in_short_font_name, */
+ /* const FULL_CHAR* in_real_font_name) */
+ /* */
+ /* Add this font to the list of fonts that the document uses. Also remember */
+ /* that this font is "in use" (output when page resources are written). */
+ /* */
+ /*****************************************************************************/
+
+ void PDFFont_AddFont(FILE* in_fp, const FULL_CHAR* in_short_font_name,
+ const FULL_CHAR* in_real_font_name, const FULL_CHAR* in_font_encoding_name)
+ {
+ t_font_list_entry_ptr entry = PDFFont_FindListEntry(in_real_font_name);
+ debug4(DPD, D, "PDFFont_AddFont(-, %s, %s, %s) [new = %s]",
+ in_short_font_name, in_real_font_name,
+ (in_font_encoding_name ? in_font_encoding_name : ""),
+ bool(entry == NULL));
+ /* *** this attempted bug fix by Jeff K. problem may be multiple font
+ entries for the same font
+ if (entry == NULL)
+ *** */
+ if (TRUE)
+ entry = PDFFont_NewListEntry(in_short_font_name, in_real_font_name,
+ PDFFont_FindFontEncoding(in_font_encoding_name));
+
+ /* ***
+ entry->m_in_use = TRUE;
+ g_page_uses_fonts = TRUE;
+ *** */
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_SetVars(int xsize, int ysize, int xmark, int ymark, */
+ /* int loutf, int loutv, int louts) */
+ /* */
+ /* Writes a string to the page's stream. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_SetVars(int xsize, int ysize, int xmark, int ymark,
+ int loutf, int loutv, int louts)
+ {
+ g_graphics_vars[k_xsize] = xsize;
+ g_graphics_vars[k_ysize] = ysize;
+ g_graphics_vars[k_xmark] = xmark;
+ g_graphics_vars[k_ymark] = ymark;
+
+ g_units[k_loutf] = loutf;
+ g_units[k_loutv] = loutv;
+ g_units[k_louts] = louts;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_FlushCompressedBuffer(FILE* in_fp) */
+ /* */
+ /* Flushes the compressed output buffer to the page's stream. */
+ /* */
+ /*****************************************************************************/
+
+ #if PDF_COMPRESSION
+ static void PDFPage_FlushCompressedBuffer(FILE* in_fp)
+ {
+ int err;
+
+ Assert(g_apply_compression, no_fpos);
+ do {
+ err = deflate(&g_comp_stream, Z_FINISH);
+
+ fwrite(g_compressed_output,
+ sizeof(g_compressed_output) - g_comp_stream.avail_out, 1, in_fp);
+ g_comp_stream.next_out = g_compressed_output;
+ g_comp_stream.avail_out = sizeof(g_compressed_output);
+ } while (err == Z_OK);
+
+ if (err != Z_STREAM_END)
+ Error(48, 9, "PDFPage_FlushCompressedBuffer: zlib error occurred",
+ FATAL, no_fpos);
+
+ err = deflateEnd(&g_comp_stream);
+ if (err != Z_OK)
+ Error(48, 10, "PDFPage_FlushCompressedBuffer: zlib error occurred",
+ FATAL, no_fpos);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_FlushRawBuffer(FILE* in_fp) */
+ /* */
+ /* Attempts to compress the raw buffer; also flushes the compressed output */
+ /* buffer to the page's stream if it is full. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFPage_FlushRawBuffer(FILE* in_fp)
+ {
+ int err;
+
+ /* compress the raw buffer */
+ Assert(g_apply_compression, no_fpos);
+ g_comp_stream.next_in = g_raw_output;
+ g_comp_stream.avail_in = (uInt) (g_raw_buffer_ptr - g_raw_output);
+ Assert(g_comp_stream.avail_out != 0, no_fpos);
+
+ /* always compress to the point where the raw buffer is empty */
+ do {
+ err = deflate(&g_comp_stream, Z_NO_FLUSH);
+ /* bug fix from newman-andy at yale.edu Feb 23 2000 if (err != Z_OK) */
+ if ( err != Z_OK && g_comp_stream.avail_in != 0 )
+ Error(48, 11, "PDFPage_FlushRawBuffer: zlib error occurred",FATAL,no_fpos);
+
+ /* IF compressed output buffer is full THEN flush it to disk and reset it */
+ if (g_comp_stream.avail_out == 0)
+ {
+ if (fwrite(g_compressed_output, sizeof(g_compressed_output), 1, in_fp)!=1)
+ Error(48, 12, "PDFPage_FlushRawBuffer: write error occurred",
+ FATAL, no_fpos);
+ g_comp_stream.next_out = g_compressed_output;
+ g_comp_stream.avail_out = sizeof(g_compressed_output);
+ }
+ } while (g_comp_stream.avail_in != 0);
+
+ /* reset raw buffer for next call */
+ g_raw_buffer_ptr = g_raw_output;
+ }
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_WriteStream(FILE* in_fp, char* in_str) */
+ /* */
+ /* Writes a string to the page's stream. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFPage_WriteStream(FILE* in_fp, char* in_str)
+ {
+ if (*in_str == 0)
+ return;
+
+ #if PDF_COMPRESSION
+ if (g_apply_compression)
+ {
+ unsigned int total = strlen(in_str);
+ char *ptr = in_str;
+
+ while (total != 0)
+ {
+ unsigned int len = total;
+ BOOLEAN needToFlush =
+ ((g_raw_buffer_ptr + len) > (g_raw_output + sizeof(g_raw_output)));
+ if (needToFlush)
+ len = g_raw_output + sizeof(g_raw_output) - g_raw_buffer_ptr;
+ memcpy(g_raw_buffer_ptr, ptr, len);
+
+ ptr += len;
+ g_raw_buffer_ptr += len;
+ total -= len;
+
+ /* IF need to flush raw buffer THEN do so */
+ if (needToFlush) PDFPage_FlushRawBuffer(in_fp);
+ } /* while still have bytes to process */
+ }
+ else
+ #endif
+ fputs(in_str, in_fp);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_Begin(FILE* in_fp) */
+ /* */
+ /* Begins the page's stream. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFPage_Begin(FILE* in_fp)
+ {
+ if (g_page_contents_obj_num == 0)
+ {
+ t_tempbuf str;
+
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% page %u's contents:\n%%\n", g_page_count);
+
+ g_page_contents_obj_num = PDFObject_WriteNewObj(in_fp);
+ g_page_length_obj_num = PDFObject_New(/* in_fp */);
+ fputs("<< /Length ", in_fp);
+ PDFObject_WriteRef(in_fp, g_page_length_obj_num);
+ #if PDF_COMPRESSION
+ if (g_apply_compression) fputs(" /Filter /FlateDecode", in_fp);
+ #endif
+ fputs(" >>\nstream\n", in_fp);
+ g_page_start_offset = ftell(in_fp);
+
+ #if PDF_COMPRESSION
+ if (g_apply_compression)
+ {
+ int err;
+
+ g_raw_buffer_ptr = g_raw_output;
+ g_comp_stream.zalloc = (alloc_func) Z_NULL;
+ g_comp_stream.zfree = (free_func) Z_NULL;
+ g_comp_stream.opaque = (voidpf) Z_NULL;
+
+ err = deflateInit(&g_comp_stream, Z_DEFAULT_COMPRESSION);
+ if (err != Z_OK)
+ Error(48, 13, "PDFPage_Begin: zlib error occurred", FATAL, no_fpos);
+
+ g_comp_stream.next_out = g_compressed_output;
+ g_comp_stream.avail_out = sizeof(g_compressed_output);
+ }
+ #endif
+
+ #ifndef USE_MATRICES
+ sprintf(str, "%.2f 0 0 %.2f 0 0 cm\n",
+ g_page_h_scale_factor, g_page_v_scale_factor);
+ PDFPage_WriteStream(in_fp, str);
+ #endif
+ sprintf(str, "%u w\n", g_page_line_width);
+ PDFPage_WriteStream(in_fp, str);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_FlushBuffer(FILE* in_fp) */
+ /* */
+ /* Flush the buffer to the page's stream and turn off buffering mode. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFPage_FlushBuffer(FILE* in_fp)
+ {
+ if (g_in_buffering_mode)
+ {
+ g_in_buffering_mode = FALSE;
+
+ /* empty the stack since it's no longer needed */
+ while (g_qsave_marking_stack != NULL)
+ {
+ t_qsave_marking_entry_ptr entry = g_qsave_marking_stack;
+ g_qsave_marking_stack = entry->m_next_entry;
+ free(entry);
+ }
+
+ /* output the buffer */
+ PDFPage_WriteStream(in_fp, g_buffer);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_FILE_OFFSET PDFPage_End(FILE* in_fp) */
+ /* */
+ /* Ends the page's stream. */
+ /* */
+ /*****************************************************************************/
+
+ static PDF_FILE_OFFSET PDFPage_End(FILE* in_fp)
+ {
+
+ /* if page has no marks on it then write out an empty stream */
+ if (g_in_buffering_mode)
+ {
+ g_buffer_pos = 0;
+ g_buffer[0] = '\0'; /* force empty string to be written */
+ PDFPage_FlushBuffer(in_fp); /* all I really want is to empty the stack */
+ }
+
+ /* IF applying compression THEN first flush the raw buffer and then flush */
+ /* the compressed buffer (must be performed in that order!) */
+ #if PDF_COMPRESSION
+ if (g_apply_compression)
+ {
+ if ((g_raw_buffer_ptr > g_raw_output) && (g_raw_buffer_ptr[-1] == '\n'))
+ g_raw_buffer_ptr--; /* remove last linefeed */
+
+ PDFPage_FlushRawBuffer(in_fp);
+ PDFPage_FlushCompressedBuffer(in_fp);
+ fputs("\n", in_fp);
+ }
+ #endif
+
+ /* close page's stream */
+ Assert(g_page_contents_obj_num != 0, no_fpos);
+ {
+ PDF_FILE_OFFSET page_length = ftell(in_fp) - g_page_start_offset;
+
+ /* close page's stream */
+ fputs("endstream\nendobj\n", in_fp);
+ return page_length;
+ }
+ return 0;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_Write(FILE* in_fp, char* in_str) */
+ /* */
+ /* Writes a string to the page's stream. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_Write(FILE* in_fp, char* in_str)
+ {
+ if (*in_str == 0)
+ return;
+
+ PDFPage_Begin(in_fp); /* write page content's hdr "<< /Length >> stream"...*/
+
+ /* IF trying to remove redundant operations THEN */
+ if (g_in_buffering_mode)
+ {
+
+ /* if buffer will overflow then turn off buffering and flush buffer */
+ unsigned int len = strlen(in_str);
+ if ( (g_buffer_pos + len) > (kBufferSize-1) ) /* -1 for NULL char */
+ {
+ PDFPage_FlushBuffer(in_fp);
+ PDFPage_WriteStream(in_fp, in_str);
+ }
+ else
+ {
+ strcpy(g_buffer + g_buffer_pos, in_str); /* save into buffer */
+ g_buffer_pos += len;
+ }
+ }
+ else
+ {
+ if (g_TJ_pending)
+ {
+ g_TJ_pending = FALSE; /* clear it */
+ PDFPage_WriteStream(in_fp, ")]TJ\n");
+ }
+
+ if (g_ET_pending)
+ {
+ g_ET_pending = FALSE; /* clear it */
+ PDFPage_WriteStream(in_fp, "ET\n");
+ g_valid_text_matrix = FALSE; /* Td is not allowed */
+ }
+
+ PDFPage_WriteStream(in_fp, in_str);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDFPage_Push(FILE* in_fp) */
+ /* */
+ /* Saves the current graphics state. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_Push(FILE* in_fp)
+ {
+
+ /* push origin coords */
+ {
+ t_qsave_entry_ptr entry = (t_qsave_entry_ptr) malloc(sizeof(t_qsave_entry));
+ if (entry == NULL)
+ Error(48, 14, "PDFPage_Push: run out of memory", FATAL, no_fpos);
+
+ entry->m_page_h_origin = g_page_h_origin;
+ entry->m_page_v_origin = g_page_v_origin;
+ /* entry->m_page_h_scale_factor = g_page_h_scale_factor; */
+ /* entry->m_page_v_scale_factor = g_page_v_scale_factor; */
+ entry->m_next_entry = g_qsave_stack;
+ g_qsave_stack = entry;
+ }
+
+ /* if buffering text */
+ if (g_in_buffering_mode)
+ {
+
+ /* push current state */
+ t_qsave_marking_entry_ptr entry =
+ (t_qsave_marking_entry_ptr) malloc(sizeof(t_qsave_marking_entry));
+ if (entry == NULL)
+ Error(48, 15, "PDFPage_Push: run out of memory", FATAL, no_fpos);
+
+ entry->m_next_entry = g_qsave_marking_stack; /* next-to-top-of-stack */
+ entry->m_buffer_pos = g_buffer_pos;
+ g_qsave_marking_stack = entry; /* new TOS */
+ /* g_in_buffering_mode = TRUE; */
+ }
+
+ /* write out push op */
+ PDFPage_Write(in_fp, "q\n");
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDFPage_Pop(FILE* in_fp) */
+ /* */
+ /* Restores the current graphics state. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_Pop(FILE* in_fp)
+ {
+
+ /* pop origin coords */
+ {
+ t_qsave_entry_ptr entry = g_qsave_stack;
+
+ g_page_h_origin = entry->m_page_h_origin;
+ g_page_v_origin = entry->m_page_v_origin;
+ /* g_page_h_scale_factor = entry->m_page_h_scale_factor; */
+ /* g_page_v_scale_factor = entry->m_page_v_scale_factor; */
+
+ g_qsave_stack = entry->m_next_entry;
+
+ free(entry);
+ }
+
+ /* if no marks on page since last push (and thus there should be a stack) */
+ if (g_in_buffering_mode)
+ {
+
+ /* pop state: behave as if the q...Q never existed */
+ t_qsave_marking_entry_ptr entry = g_qsave_marking_stack;
+
+ Assert(entry != NULL, no_fpos);
+
+ g_qsave_marking_stack = entry->m_next_entry; /* new TOS */
+ g_buffer_pos = entry->m_buffer_pos;
+ g_buffer[g_buffer_pos] = '\0'; /* chop off unwanted text */
+
+ free(entry);
+ }
+ else
+ {
+ Assert(g_qsave_marking_stack == NULL, no_fpos);
+ PDFPage_Write(in_fp, "\nQ\n");
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDFFont_Set(FILE* in_fp, FULL_LENGTH in_font_size, */
+ /* FULL_CHAR* in_font_name) */
+ /* */
+ /* Sets the font name and size for subsequent text write statements. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFFont_Set(FILE* in_fp, FULL_LENGTH in_font_size,
+ FULL_CHAR *in_short_font_name)
+ {
+ t_tempbuf str;
+
+ t_font_list_entry_ptr entry = PDFFont_FindListEntry_Short(in_short_font_name);
+ if( entry == NULL )
+ {
+ Error(48, 42, "cannot find font entry for name %s", FATAL, no_fpos,
+ in_short_font_name);
+ }
+ /* Assert(entry != NULL, no_fpos); */
+ #ifdef USE_MATRICES
+ sprintf(str, "%s %u Tf\n", entry->m_PDF_font_name,
+ (int) (g_page_v_scale_factor * in_font_size));
+ #else
+ sprintf(str, "%s %u Tf\n", entry->m_PDF_font_name, in_font_size);
+ /* g_text_font_size_in_ems = g_page_v_scale_factor * in_font_size; */
+ #endif
+
+ #if 1
+
+ /* font changes can occur within BT...ET blocks, so temporarily turn off */
+ /* g_ET_pending. I do it this way so that the qsave_marking_stack */
+ /* optimisation can still be applied (this avoids output such as */
+ /* "/F0 240 Tf /F0 240 Tf /F1 600 Tf" and instead produces "") */
+ if (g_TJ_pending)
+ {
+ g_TJ_pending = FALSE; /* clear it */
+ PDFPage_WriteStream(in_fp, ")]TJ\n");
+ }
+
+ {
+ BOOLEAN cur_ET_pending = g_ET_pending;
+
+ g_ET_pending = FALSE; /* clear it */
+ PDFPage_Write(in_fp, str);
+ g_ET_pending = cur_ET_pending; /* restore it */
+ }
+ #else
+ /* font changes can occur within BT...ET blocks, so bypass PDFPage_Write() */
+ PDFPage_WriteStream(in_fp, str);
+ #endif
+ entry->m_in_use = TRUE;
+ g_page_uses_fonts = TRUE;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_RMove(FILE* in_fp, int hdelta, int vdelta) */
+ /* */
+ /* Offsets text pen by the given offsets. */
+ /* */
+ /*****************************************************************************/
+
+ /* ***
+ void PDFText_RMove(FILE* in_fp, int hdelta, int vdelta)
+ {
+ t_tempbuf str;
+
+ g_tx_hpos += hdelta;
+ g_tx_vpos += vdelta;
+ #if 1
+ sprintf(str, "ET\n1 0 0 1 %d %d cm\nBT\n", hdelta, vdelta);
+ #else
+ sprintf(str, "1 0 0 1 %d %d Tm\n", g_tx_hpos, g_tx_vpos);
+ #endif
+ PDFPage_Write(in_fp, str);
+ }
+ *** */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_MoveTo(FILE* in_fp, int hpos, int vpos) */
+ /* */
+ /* Move text pen to the given coords. */
+ /* */
+ /*****************************************************************************/
+
+ /* ***
+ static void PDFText_MoveTo(FILE* in_fp, int hpos, int vpos)
+ {
+ g_tx_hpos = 0;
+ g_tx_vpos = 0;
+ #if 1
+ PDFText_RMove(in_fp, hpos, vpos);
+ #else
+ {
+ t_tempbuf str;
+ sprintf(str, "1 0 0 1 %d %d Tm\n", hpos, vpos);
+ PDFPage_Write(in_fp, str);
+ }
+ #endif
+ }
+ *** */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_OpenString(FILE* in_fp) */
+ /* */
+ /* Open TJ block */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFText_OpenString(FILE* in_fp)
+ {
+ if (g_TJ_pending)
+ g_TJ_pending = FALSE; /* clear it */
+ else
+ PDFPage_Write(in_fp, "[(");
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_MoveToXYAndOpen(FILE* in_fp, int hpos, int vpos) */
+ /* */
+ /* Move text pen to the given coords. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFText_MoveToXYAndOpen(FILE* in_fp, int hpos, int vpos)
+ {
+ #if 1
+ t_tempbuf str;
+ sprintf(str, "1 0 0 1 %d %d Tm\n", hpos, vpos);
+ PDFPage_Write(in_fp, str);
+ #else
+ PDFText_MoveTo(in_fp, hpos, vpos);
+ #endif
+ PDFText_OpenString(in_fp);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_MoveToXAndOpen(FILE* in_fp, int hpos, int vpos) */
+ /* */
+ /* Move text pen to the given coords. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFText_MoveToXAndOpen(FILE* in_fp, int hpos)
+ {
+ #if 1
+ t_tempbuf str;
+ sprintf(str, "%d 0 Td\n", hpos);
+ PDFPage_Write(in_fp, str);
+ #else
+ PDFText_MoveTo(in_fp, hpos, vpos);
+ #endif
+ PDFText_OpenString(in_fp);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_OpenBT(FILE* in_fp) */
+ /* */
+ /* Opens a text object at the given coords. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFText_OpenBT(FILE* in_fp)
+ {
+ PDFPage_FlushBuffer(in_fp); /* about to mark page: flush buffered PDF */
+
+ g_page_has_text = TRUE;
+
+ if (g_TJ_pending)
+ {
+ g_TJ_pending = FALSE; /* clear it */
+ PDFPage_WriteStream(in_fp, ")]TJ\n");
+ }
+
+ if (g_ET_pending)
+ g_ET_pending = FALSE; /* clear it */
+ else
+ {
+ PDFPage_Write(in_fp, "BT\n");
+ g_valid_text_matrix = TRUE; /* Td is allowed */
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_OpenXY(FILE* in_fp, int hpos, int vpos) */
+ /* */
+ /* Opens a text object at the given coords. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFText_OpenXY(FILE* in_fp, int hpos, int vpos)
+ {
+ PDFText_OpenBT(in_fp);
+ PDFText_MoveToXYAndOpen(in_fp, hpos, vpos);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_OpenX(FILE* in_fp, int hpos) */
+ /* */
+ /* Opens a text object at the given coords. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFText_OpenX(FILE* in_fp, int hpos)
+ {
+ PDFText_OpenBT(in_fp);
+ PDFText_MoveToXAndOpen(in_fp, hpos);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_Open(FILE* in_fp) */
+ /* */
+ /* Opens a text object. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFText_Open(FILE* in_fp)
+ {
+ if (g_TJ_pending)
+ {
+ g_TJ_pending = FALSE; /* clear it */
+ Assert(g_ET_pending == TRUE, no_fpos);
+ g_ET_pending = FALSE; /* clear it */
+ }
+ else
+ {
+ PDFText_OpenBT(in_fp);
+ PDFText_OpenString(in_fp);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_Kern(FILE* in_fp, int in_kern) */
+ /* */
+ /* Apply kerning to a text string. */
+ /* */
+ /* Note: in_kern is in 1/1000 of font size */
+ /* */
+ /*****************************************************************************/
+
+ void PDFText_Kern(FILE* in_fp, int in_kern)
+ {
+ t_tempbuf str;
+
+ /* sprintf(str, ")%d(", -in_kern * 1000 / g_text_font_size_in_ems); */
+ sprintf(str, ")%d(", -in_kern);
+ PDFPage_Write(in_fp, str);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFText_Close(FILE* in_fp) */
+ /* */
+ /* Closes a previously opened text object. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFText_Close(FILE* in_fp)
+ {
+ /* PDFPage_Begin(in_fp); - shouldn't be needed */
+ Assert(g_page_contents_obj_num != 0, no_fpos);
+
+ g_TJ_pending = TRUE;
+ /* PDFPage_Write(in_fp, ")] TJ\n"); */
+ g_ET_pending = TRUE;
+ }
+
+
+ #ifdef USE_MATRICES
+
+ /*****************************************************************************/
+ /* */
+ /* void PDF_Matrix_XY(double* in_out_x, double* in_out_y) */
+ /* */
+ /* Returns (x, y) after applying the current matrix: */
+ /* */
+ /* [ a b 0 ] */
+ /* [ x y 1 ] x [ c d 0 ] = [ ax+cy+e bx+dy+f 1 ] */
+ /* [ e f 1 ] */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_Matrix_XY(double* in_out_x, double* in_out_y)
+ {
+ double result_x, result_y;
+
+ result_x = g_cur_matrix[0] * *in_out_x + g_cur_matrix[3] * *in_out_y +
+ g_cur_matrix[6];
+ result_y = g_cur_matrix[1] * *in_out_x + g_cur_matrix[4] * *in_out_y +
+ g_cur_matrix[7];
+ *in_out_x = result_x;
+ *in_out_y = result_y;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_Matrix_Mul(t_matrix in_left, t_matrix in_right, t_matrix out_result) */
+ /* */
+ /* Multiplies the given matrices. */
+ /* */
+ /* [ a b 0 ] [ g h 0 ] [ ag+bi ah+bj 0 ] */
+ /* [ c d 0 ] x [ i j 0 ] = [ cg+di ch+dj 0 ] */
+ /* [ e f 1 ] [ k l 1 ] [ eg+fi+k eh+fj+l 1 ] */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_Matrix_Mul(t_matrix in_left, t_matrix in_right,
+ t_matrix out_result)
+ {
+ t_matrix result;
+ result[0] = in_left[0] * in_right[0] + in_left[1] * in_right[3];
+ result[1] = in_left[0] * in_right[1] + in_left[1] * in_right[4];
+ result[2] = 0;
+ result[3] = in_left[3] * in_right[0] + in_left[4] * in_right[3];
+ result[4] = in_left[3] * in_right[1] + in_left[4] * in_right[4];
+ result[5] = 0;
+ result[6] = in_left[6] * in_right[0] + in_left[7] * in_right[3] + in_right[6];
+ result[7] = in_left[6] * in_right[1] + in_left[7] * in_right[4] + in_right[7];
+ result[8] = 1;
+
+ memcpy(out_result, result, sizeof(t_matrix));
+ }
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_Scale(float in_h_scale_factor, float in_v_scale_factor) */
+ /* */
+ /* Changes CTM by scale factor: */
+ /* */
+ /* [ sh 0 0 ] */
+ /* [ 0 sv 0 ] */
+ /* [ 0 0 1 ] */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_Scale(FILE* in_fp, float in_h_scale_factor, float in_v_scale_factor)
+ {
+ #ifdef USE_MATRICES
+ t_matrix m = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+ m[0] = in_h_scale_factor;
+ m[4] = in_v_scale_factor;
+
+ PDF_Matrix_Mul(m, g_cur_matrix, g_cur_matrix);
+ #else
+ t_tempbuf str;
+
+ sprintf(str, "%.2f 0 0 %.2f 0 0 cm\n", in_h_scale_factor, in_v_scale_factor);
+ PDFPage_Write(in_fp, str);
+ #endif
+ g_page_h_scale_factor *= in_h_scale_factor;
+ g_page_v_scale_factor *= in_v_scale_factor;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_Rotate(FILE* in_fp, float in_angle_in_radians) */
+ /* */
+ /* Changes CTM by rotation factor. */
+ /* */
+ /* [ cos a sin a 0 ] */
+ /* [ -sin a cos a 0 ] */
+ /* [ 0 0 1 ] */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_Rotate(FILE* in_fp, float in_angle_in_radians)
+ {
+ float cos_radians = cos(in_angle_in_radians);
+ float sin_radians = sin(in_angle_in_radians);
+ #ifdef USE_MATRICES
+ t_matrix m = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+ m[0] = m[4] = cos_radians;
+ m[1] = sin_radians;
+ m[3] = -sin_radians;
+ PDF_Matrix_Mul(m, g_cur_matrix, g_cur_matrix);
+ #else
+ t_tempbuf str;
+
+ sprintf(str, "%.2f %.2f %.2f %.2f 0 0 cm\n", cos_radians, sin_radians,
+ -sin_radians, cos_radians);
+ PDFPage_Write(in_fp, str);
+ #endif
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_Translate(FILE* in_fp, float in_delta_h, float in_delta_v) */
+ /* */
+ /* Changes CTM by translation: */
+ /* */
+ /* [ 1 0 0 ] */
+ /* [ 0 1 0 ] */
+ /* [ dh dv 1 ] */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_Translate(FILE* in_fp, float in_delta_h, float in_delta_v)
+ {
+ #ifdef USE_MATRICES
+ t_matrix m = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
+ m[6] = in_delta_h;
+ m[7] = in_delta_v;
+ PDF_Matrix_Mul(m, g_cur_matrix, g_cur_matrix);
+ #else
+ t_tempbuf str;
+
+ sprintf(str, "1 0 0 1 %.2f %.2f cm\n", in_delta_h, in_delta_v);
+ PDFPage_Write(in_fp, str);
+ #endif
+ g_page_h_origin += in_delta_h;
+ g_page_v_origin += in_delta_v;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFTargetAnnot_New(FULL_CHAR* in_annot_name, ...) */
+ /* */
+ /* Create a new target annotation entry. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFTargetAnnot_New(FULL_CHAR* in_annot_name,
+ unsigned int in_annot_name_length, int in_ll_x, int in_ll_y, int in_ur_x,
+ int in_ur_y, BOOLEAN in_for_export)
+ {
+ t_target_annot_entry_ptr entry =
+ (t_target_annot_entry_ptr) malloc(sizeof(t_target_annot_entry));
+
+ if (entry == NULL)
+ Error(48, 16, "PDFTargetAnnot_New: run out of memory", FATAL, no_fpos);
+
+ entry->m_name = (FULL_CHAR*) malloc(in_annot_name_length + 1);
+ if (entry->m_name == NULL)
+ Error(48, 17, "PDFTargetAnnot_New: run out of memory", FATAL, no_fpos);
+ memcpy(entry->m_name, in_annot_name, in_annot_name_length);
+ entry->m_name[in_annot_name_length] = '\0';
+
+ Assert(g_page_contents_obj_num != 0, no_fpos);
+ entry->m_page_object_num = g_page_object_num;
+
+ entry->m_ll_x = in_ll_x;
+ entry->m_ll_y = in_ll_y;
+ entry->m_ur_x = in_ur_x;
+ entry->m_ur_y = in_ur_y;
+ entry->m_for_export = in_for_export;
+
+ entry->m_next_entry = g_target_annot_list;
+ g_target_annot_list = entry;
+
+ if (in_for_export)
+ g_has_exported_targets = in_for_export;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* t_target_annot_entry_ptr PDFTargetAnnot_Find(FULL_CHAR* in_annot_name) */
+ /* */
+ /* Finds an annotation. Returns NULL if not found. */
+ /* */
+ /*****************************************************************************/
+
+ static t_target_annot_entry_ptr PDFTargetAnnot_Find(FULL_CHAR* in_annot_name)
+ {
+ t_target_annot_entry_ptr entry = g_target_annot_list;
+
+ /* this takes O(n) time; may need re-implementing if speed is a factor */
+ while (entry != NULL)
+ {
+ if (strcmp((char*) in_annot_name, (char*) entry->m_name) == 0)
+ break;
+ entry = entry->m_next_entry;
+ }
+
+ return entry;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDFSourceAnnot_Write(FILE* in_fp, */
+ /* t_source_annot_entry_ptr in_source_entry) */
+ /* */
+ /* Write an annot which specifies the source and target of the link. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFSourceAnnot_Write(FILE* in_fp, t_source_annot_entry_ptr in_entry)
+ {
+ t_target_annot_entry_ptr target;
+
+ Assert(in_entry != NULL, no_fpos);
+
+ target = in_entry->m_target;
+
+ /* if it is an unresolved forward link then exit */
+ if ( (in_entry->m_link_type == k_link_source) && (target == NULL) )
+ return;
+
+ /* green light: write it out */
+ if (g_PDF_debug)
+ {
+ fprintf(in_fp, "%%\n%% annotation in page object # %u to %s:\n%%\n",
+ in_entry->m_this_page_object_num, in_entry->m_target->m_name);
+ }
+
+ PDFObject_WriteObj(in_fp, in_entry->m_this_object_num);
+ fprintf(in_fp, "<<\n/Type /Annot\n/Subtype /Link\n"
+ /* this is what Adobe does (it's also more flexible) */
+ "/Rect [ %d %d %d %d ]\n/Border [ 0 0 0 ]\n",
+ /* "/BS << /Type /Border /S /U >>\n" */
+ /* border appearance is "underline" */
+ in_entry->m_ll_x, in_entry->m_ll_y, in_entry->m_ur_x, in_entry->m_ur_y);
+
+ switch (in_entry->m_link_type)
+ {
+ case k_link_source:
+
+ fprintf(in_fp, "/Dest [ ");
+ PDFObject_WriteRef(in_fp, in_entry->m_target->m_page_object_num);
+ switch (in_entry->m_dest_option)
+ {
+ case kFitNoChange:
+
+ fprintf(in_fp, " /XYZ null null null");
+ /* NB NO BREAK */
+
+ case kFit:
+
+ fprintf(in_fp, " /Fit");
+ break;
+
+
+ case kFitH:
+
+ /* [ /FitH top ]: fit the width of the page to the window; top */
+ /* specifies the y-coordinate of the top edge of the window */
+ fprintf(in_fp, " /FitH %u", target->m_ur_y);
+ break;
+
+
+ case kFitV:
+
+ /* [ /FitV left ]: fit the height of the page to the window; */
+ /* left specifies the x-coordinate of the left edge of the window */
+ fprintf(in_fp, " /FitV %u", target->m_ll_x);
+ break;
+
+
+ case kFitR:
+
+ /* [ /FitR left bottom right top ]: fit the rectangle specified */
+ /* by left bottom right top in the window. If the height (top - */
+ /* bottom) and width (right - left) imply different zoom factors, */
+ /* the numerically smaller zoom factor is used, to ensure that */
+ /* the specified rectangle fits in the window */
+ fprintf(in_fp, " /FitR %u %u %u %u", target->m_ll_x, target->m_ll_y,
+ target->m_ur_x, target->m_ur_y);
+ break;
+
+
+ case kFitB:
+
+ /* [ /FitB ]: fit the page's bounding box to the window */
+ fprintf(in_fp, " /FitB");
+ break;
+
+
+ case kFitBH:
+
+ /* [ /FitBH top ]: fit the width of the page's bounding box to */
+ /* the window. top specifies the y-coord of top edge of window */
+ fprintf(in_fp, " /FitBH %u", target->m_ur_y);
+ break;
+
+
+ case kFitBV:
+
+ /* [ /FitBV left ]: fit the height of the page' bounding box to */
+ /* the window. left specifies the x-coordinate of the left edge */
+ /* of the window */
+ fprintf(in_fp, " /FitBV %u", target->m_ll_x);
+ break;
+
+
+ default:
+
+ Error(48, 18, "PDFSourceAnnot_Write: invalid link dest option",
+ FATAL, no_fpos);
+ }
+ fprintf(in_fp, " ]\n");
+ break;
+
+
+ case k_link_external:
+
+ #if 1 /* required wrapper for URLs is now in the Lout libraries */
+ fprintf(in_fp, "/A << /Type /Action /S /GoToR /D (%s) /F\n"
+ /* <= split across lines for LONG file specs */
+ "(%s) >>\n", in_entry->m_name, in_entry->m_file_spec);
+ #else
+ if (in_entry->m_file_spec[0] != '<')
+ {
+ /* note: destination/target is specified as a string, as is file spec */
+ fprintf(in_fp, "/A << /Type /Action /S /GoToR /D (%s) /F\n"
+ /* <= split across lines for LONG file specs */
+ "(%s) >>\n", in_entry->m_name, in_entry->m_file_spec);
+ }
+ else
+ {
+ /* if file spec starts with '<' then URL, eg <http://www.adobe.com> */
+ Assert(in_entry->m_file_spec[strlen((char*) in_entry->m_file_spec)-1]
+ == '>', no_fpos);
+ fprintf(in_fp, "/A << /Type /Action /S /GoToR /D (%s) /F\n"
+ /* <= split across lines for LONG file specs */
+ "<< /FS /URL /F (%s) >> >>\n", in_entry->m_name, in_entry->m_file_spec);
+ }
+ #endif
+ break;
+
+
+ case k_link_URI:
+
+ fprintf(in_fp, "/A << /Type /Action /S /URI /URI\n"
+ /* <= split across lines for LONG URI's */
+ "(%s) >>\n", in_entry->m_name);
+ break;
+
+
+ case k_link_target:
+ case k_link_target_for_export:
+ case kNumberOfLinkKeywords:
+
+ break;
+ }
+
+ fprintf(in_fp, ">>\nendobj\n");
+ in_entry->m_written_to_PDF_file = TRUE;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFSourceAnnot_New(FULL_CHAR* in_annot_name) */
+ /* */
+ /* Create an entry in the g_source_annot_list which links to in_annot_name. */
+ /* */
+ /*****************************************************************************/
+
+ static t_source_annot_entry_ptr
+ PDFSourceAnnot_New(PDF_LINK_KEYWORD in_link_type, FULL_CHAR* in_annot_name,
+ unsigned int in_annot_name_length, int in_ll_x, int in_ll_y, int in_ur_x,
+ int in_ur_y, PDF_LINK_DEST_OPTION in_link_dest_option)
+ {
+ t_target_annot_entry_ptr target = NULL;
+ t_source_annot_entry_ptr entry =
+ (t_source_annot_entry_ptr) malloc(sizeof(t_source_annot_entry));
+
+ if (entry == NULL)
+ Error(48, 19, "PDFSourceAnnot_New: run out of memory", FATAL, no_fpos);
+
+ entry->m_ll_x = in_ll_x;
+ entry->m_ll_y = in_ll_y;
+ entry->m_ur_x = in_ur_x;
+ entry->m_ur_y = in_ur_y;
+
+ entry->m_this_object_num = PDFObject_New(/* in_fp */);
+ entry->m_this_page_object_num = g_page_object_num;
+ entry->m_link_type = in_link_type;
+ Assert((in_link_dest_option >= kFitNoChange) &&
+ (in_link_dest_option <= kFitBV), no_fpos);
+ entry->m_dest_option = in_link_dest_option;
+ entry->m_file_spec = NULL;
+ entry->m_written_to_PDF_file = FALSE;
+
+ if (in_link_type == k_link_source)
+ target = PDFTargetAnnot_Find(in_annot_name);
+
+ if (target != NULL)
+ {
+ entry->m_target = target;
+ entry->m_name = NULL;
+ }
+ else
+ {
+ entry->m_target = NULL; /* fwd link */
+ entry->m_name = (FULL_CHAR*) malloc(in_annot_name_length + 1);
+ if (entry->m_name == NULL)
+ Error(48, 20, "PDFSourceAnnot_New: run out of memory", FATAL, no_fpos);
+ memcpy(entry->m_name, in_annot_name, in_annot_name_length);
+ entry->m_name[in_annot_name_length] = '\0';
+ }
+
+ entry->m_next_entry = g_source_annot_list;
+ g_source_annot_list = entry;
+
+ return entry;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDFSourceAnnot_Dispose(t_source_annot_entry_ptr in_source_annot) */
+ /* */
+ /* Dispose of a source annot entry; returns the next entry in the list. */
+ /* */
+ /*****************************************************************************/
+
+ static t_source_annot_entry_ptr
+ PDFSourceAnnot_Dispose(t_source_annot_entry_ptr in_source_annot)
+ {
+ t_source_annot_entry_ptr next_entry = in_source_annot->m_next_entry;
+
+ if (in_source_annot->m_name != NULL)
+ free(in_source_annot->m_name);
+ if (in_source_annot->m_file_spec != NULL)
+ free(in_source_annot->m_file_spec);
+ free(in_source_annot);
+ return next_entry;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* float PDFPage_GetFloat(FULL_CHAR* in_str) */
+ /* */
+ /* Outputs an appropriate PDF string for drawing a graphic element. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR *PDFPage_GetFloat(FULL_CHAR* in_str, float* out_value)
+ {
+ if (sscanf((char*) in_str, "%f", out_value) == 1)
+ {
+ /* skip (presumed) floating point number: [ ]*[+|-][0-9.]* */
+ while (isspace(*in_str))
+ in_str++;
+ if ( (*in_str == '-') || (*in_str == '+') )
+ in_str++;
+ while (isdigit(*in_str) || (*in_str == '.'))
+ in_str++;
+ }
+ else Error(48, 21, "PDFPage_GetFloat: unable to evaluate number for Lout graphic keyword processing",
+ FATAL, no_fpos);
+ return in_str;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* int PDFKeyword_Find(int in_number_of_array_elements, */
+ /* char* in_keyword_array[], FULL_CHAR* in_str) */
+ /* */
+ /* Return index into keyword array if an element matches the given string. */
+ /* Returns -1 if not found. */
+ /* */
+ /*****************************************************************************/
+
+ static int PDFKeyword_Find(int in_number_of_array_elements,
+ char* in_keyword_array[], FULL_CHAR* in_str)
+ {
+ unsigned int i;
+
+ /* look for keyword */
+ for (i = 0; i < in_number_of_array_elements; i++)
+ {
+ unsigned int len = strlen(in_keyword_array[i]);
+
+ if (memcmp(in_keyword_array[i], in_str, len) == 0)
+ break;
+ }
+
+ return (i < in_number_of_array_elements) ? i : -1;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *PDFPage_ProcessGraphicsKeyword(FULL_CHAR* charPtr, int i) */
+ /* */
+ /* Processes a link keyword. */
+ /* */
+ /*****************************************************************************/
+
+ #if 0 /* this function is no longer used */
+
+ static FULL_CHAR *PDFPage_ProcessGraphicsKeyword(FULL_CHAR* charPtr, int i,
+ char** strPtr)
+ {
+ float value;
+
+ /* if need be, expand this later to a full blown expression evaluator (ugh) */
+ switch (*charPtr)
+ {
+ case '+':
+
+ Assert(FALSE, no_fpos);
+ charPtr = PDFPage_GetFloat(++charPtr, &value);
+ sprintf(*strPtr, "%.2f", g_graphics_vars[i] + value);
+ break;
+
+
+ case '-':
+
+ Assert(FALSE, no_fpos);
+ charPtr = PDFPage_GetFloat(++charPtr, &value);
+ sprintf(*strPtr, "%.2f", g_graphics_vars[i] - value);
+ break;
+
+
+ case '*':
+
+ Assert(FALSE, no_fpos);
+ charPtr = PDFPage_GetFloat(++charPtr, &value);
+ sprintf(*strPtr, "%.2f", g_graphics_vars[i] * value);
+ break;
+
+
+ case '/':
+
+ Assert(FALSE, no_fpos);
+ charPtr = PDFPage_GetFloat(++charPtr, &value);
+ Assert(value != 0, no_fpos); /* not great since value is a float... */
+ sprintf(*strPtr, "%.2f", g_graphics_vars[i] / value);
+ break;
+
+
+ default:
+
+ sprintf(*strPtr, "%d", g_graphics_vars[i]);
+ break;
+ }
+ *strPtr += strlen(*strPtr);
+ return charPtr;
+ }
+
+ #endif
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_ProcessLinkKeyword(void) */
+ /* */
+ /* Processes a link keyword. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFPage_ProcessLinkKeyword(void)
+ {
+ FULL_CHAR* charPtr = (FULL_CHAR*) g_link;
+ PDF_LINK_KEYWORD keyword = g_link_keyword;
+ unsigned int link_len = 0;
+ FULL_CHAR* link_name = charPtr;
+
+ /* scan for name of link; scan until end of string or until ' __' reached */
+ /* (scan for name of link; scan until end of string or whitespace reached) */
+ #if 1
+
+ FULL_CHAR* parm = NULL;
+ debug1(DPD, D, "PDFPage_ProcessLinkKeyword(g_link = %s", g_link);
+
+ while ((*charPtr != '\0') &&
+ !(isspace(charPtr[0]) && (charPtr[1] == '_') && (charPtr[2] == '_')))
+ {
+ link_len++;
+ charPtr++;
+ }
+
+ if (*charPtr != '\0')
+ parm = ++charPtr;
+
+ while (*charPtr != '\0')
+ charPtr++;
+ #else
+ while ((*charPtr != '\0') && ! isspace(*charPtr))
+ {
+ link_len++;
+ charPtr++;
+ }
+ #endif
+ if (link_len == 0)
+ Error(48, 22, "PDFPage_ProcessLinkKeyword: empty link-name / URI; ignored.",
+ WARN, no_fpos);
+ else
+ {
+
+ /* see documentaton for @Graphic for the meaning of the x, y parms */
+ /* translate the object's box into PDF's default user space */
+ int ll_x = g_page_h_origin * g_page_h_scale_factor;
+ int ll_y = g_page_v_origin * g_page_v_scale_factor;
+ int ur_x = (g_page_h_origin + g_graphics_vars[k_xsize]) * g_page_h_scale_factor;
+ int ur_y = (g_page_v_origin + g_graphics_vars[k_ysize]) * g_page_v_scale_factor;
+
+ /* remove this block later (it produces debugging output): */
+ #if 0
+ {
+ t_tempbuf strz = "PDFPage_ProcessLinkKeyword: ";
+ switch (keyword)
+ {
+ case k_link_source:
+
+ strcat(strz, "link_source =");
+ break;
+
+
+ case k_link_external:
+
+ strcat(strz, "link_external =");
+ break;
+
+
+ case k_link_URI:
+
+ strcat(strz, "link_URI =");
+ break;
+
+
+ case k_link_target:
+
+ strcat(strz, "link_target =");
+ break;
+
+
+ case k_link_target_for_export:
+
+ strcat(strz, "link_target_for_export=");
+ break;
+ }
+ strcat(strz, (char*) link_name);
+ fprintf(stderr, "%s", strz);
+ /* Err or(48, 23, strz, WARN, no_fpos); */
+ }
+ #endif
+ switch (keyword)
+ {
+ case k_link_source:
+
+ {
+ int j;
+
+ /* if there is a dest option specified then get it */
+ if (parm != NULL)
+ {
+ j = PDFKeyword_Find(kNumberOfDestLinkOptions, g_dest_link_options,
+ charPtr);
+ if (j >= 0) /* note signed comparison */
+ charPtr += strlen(g_dest_link_options[j]);
+ else
+ {
+ j = (int) kFitNoChange; /* default */
+ /* must consume the rest of the string */
+ while (*charPtr != '\0')
+ charPtr++;
+ link_len = charPtr - link_name;
+ }
+ }
+ else
+ j = (int) kFitNoChange; /* default */
+
+ PDFSourceAnnot_New(keyword, link_name, link_len,
+ ll_x, ll_y, ur_x, ur_y, (PDF_LINK_DEST_OPTION) j);
+ break;
+ }
+
+
+ case k_link_external:
+ case k_link_URI:
+
+ {
+ t_source_annot_entry_ptr source;
+ source = PDFSourceAnnot_New(keyword, link_name, link_len, ll_x,
+ ll_y, ur_x, ur_y, (PDF_LINK_DEST_OPTION) 0 /* doesn't matter */);
+ if (keyword == k_link_external)
+ {
+ int j;
+
+ link_len = 0;
+
+ if (parm != NULL)
+ {
+ j = PDFKeyword_Find(1, g_external_file_spec_keyword, parm);
+ if (j == 0)
+ {
+ parm += strlen(g_external_file_spec_keyword[0]);
+ link_len = strlen((char*) parm);
+ #if 0
+ /* scan for name of file spec; scan until end of string or */
+ /* until whitespace reached */
+ link_name = charPtr;
+ while ((*charPtr != '\0') && ! isspace(*charPtr))
+ {
+ link_len++;
+ charPtr++;
+ }
+ #endif
+ }
+ }
+
+ if (link_len == 0)
+ Error(48, 24, "PDFPage_ProcessLinkKeyword: empty file spec",
+ FATAL, no_fpos);
+ else
+ {
+ source->m_file_spec = (FULL_CHAR*) malloc(link_len + 1);
+ if (source->m_file_spec == NULL)
+ Error(48, 25, "PDFPage_ProcessLinkKeyword: out of memory",
+ FATAL, no_fpos);
+ #if 1
+ strcpy((char*) source->m_file_spec, (char*) parm);
+ #else
+ memcpy(source->m_file_spec, link_name, link_len);
+ source->m_file_spec[link_len] = '\0';
+ #endif
+ }
+ }
+ break;
+ }
+
+
+ case k_link_target:
+ case k_link_target_for_export:
+
+ PDFTargetAnnot_New(link_name, link_len, ll_x, ll_y, ur_x, ur_y,
+ keyword == k_link_target_for_export);
+ break;
+
+
+ case kNumberOfLinkKeywords:
+ break;
+
+ } /* switch */
+ } /* else */
+
+ debug0(DPD, D, "PDFPage_ProcessLinkKeyword returning");
+ /* return charPtr; */
+ } /* PDFPage_ProcessLinkKeyword */
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR* PDFPage_ProcessDocInfoKeyword(FULL_CHAR* charPtr, int i) */
+ /* */
+ /* Processes a document info keyword. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR *PDFPage_ProcessDocInfoKeyword(FULL_CHAR* charPtr, int i)
+ {
+ switch (i)
+ {
+ case k_author:
+
+ if (g_doc_author != NULL)
+ free(g_doc_author);
+ g_doc_author = (FULL_CHAR*) malloc(strlen((char*) charPtr) + 1);
+ if (g_doc_author == NULL)
+ Error(48, 26, "PDFPage_ProcessDocInfoKeyword: no memory for __author=",
+ WARN, no_fpos);
+ else
+ strcpy((char*) g_doc_author, (char*) charPtr);
+ break;
+
+
+ case k_title:
+
+ if (g_doc_title != NULL)
+ free(g_doc_title);
+ g_doc_title = (FULL_CHAR*) malloc(strlen((char*) charPtr) + 1);
+ if (g_doc_title == NULL)
+ Error(48, 27, "PDFPage_ProcessDocInfoKeyword: no memory for __title=",
+ WARN, no_fpos);
+ else
+ strcpy((char*) g_doc_title, (char*) charPtr);
+ break;
+
+
+ case k_subject:
+
+ if (g_doc_subject != NULL)
+ free(g_doc_subject);
+ g_doc_subject = (FULL_CHAR*) malloc(strlen((char*) charPtr) + 1);
+ if (g_doc_subject == NULL)
+ Error(47, 28, "PDFPage_ProcessDocInfoKeyword: no memory for __subject=",
+ WARN, no_fpos);
+ else
+ strcpy((char*) g_doc_subject, (char*) charPtr);
+ break;
+
+
+ case k_keywords:
+ if (g_doc_keywords != NULL)
+ free(g_doc_keywords);
+ g_doc_keywords = (FULL_CHAR*) malloc(strlen((char*) charPtr) + 1);
+ if (g_doc_keywords == NULL)
+ Error(48, 29, "PDFPage_ProcessDocInfoKeyword: no memory for __keywords=",
+ WARN, no_fpos);
+ else
+ strcpy((char*) g_doc_keywords, (char*) charPtr);
+ break;
+
+ }
+ return (charPtr + strlen((char*) charPtr));
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_EvalExpr(char* inExpr) */
+ /* */
+ /* Evaluate collected expression in the given expression buffer. */
+ /* */
+ /*****************************************************************************/
+
+ static char *PDFPage_EvalExpr(char* inExpr, float* outValue)
+ {
+ int i;
+ char* chp = inExpr;
+
+ while (isspace( (int) *chp)) /* ignore leading white space */
+ chp++;
+
+ while (*chp == '_')
+ chp++;
+
+ while (*chp == '+') /* ignore unary + */
+ chp++;
+
+ if (isdigit((int) *chp) || (*chp == '.'))
+ {
+ chp = (char*) PDFPage_GetFloat((FULL_CHAR*) chp, outValue);
+ }
+ else if (*chp == '-') /* handle unary negation */
+ {
+ float val;
+
+ chp = PDFPage_EvalExpr(++chp, &val);
+ *outValue = -val;
+ }
+ else
+ {
+ i = PDFKeyword_Find(kNumberOfArithmeticKeywords,
+ g_arithmetic_keywords, (FULL_CHAR*) chp);
+ if (i >= 0)
+ {
+ float val1, val2;
+
+ chp += strlen(g_arithmetic_keywords[i]);
+
+ while (isspace( (int) *chp))
+ chp++;
+ if (*chp != '(')
+ Error(48, 30, "PDFPage_EvalExpr: '(' expected", FATAL, no_fpos);
+ chp = PDFPage_EvalExpr(++chp, &val1);
+ if ( (i <= k_div) || (i == k_pick) )
+ {
+ int count;
+
+ if (i == k_pick)
+ {
+ count = floor(val1);
+ Assert(count != 0, no_fpos);
+ }
+ else
+ count = 1;
+
+ if (*chp != ',')
+ Error(48, 31, "PDFPage_EvalExpr: ',' expected", FATAL, no_fpos);
+
+ do {
+ chp = PDFPage_EvalExpr(++chp, &val2);
+ if ((count != 1) && (*chp == ','))
+ ++chp;
+ } while (--count != 0);
+ }
+ if (*chp != ')')
+ Error(48, 32, "PDFPage_EvalExpr: ')' expected", FATAL, no_fpos);
+ ++chp;
+ switch (i)
+ {
+
+ case k_add:
+ *outValue = val1 + val2;
+ break;
+
+
+ case k_sub:
+
+ *outValue = val1 - val2;
+ break;
+
+
+ case k_mul:
+
+ *outValue = val1 * val2;
+ break;
+
+
+ case k_div:
+
+ Assert(val2 != 0, no_fpos); /* not great since value is a float... */
+ *outValue = val1 / val2;
+ break;
+
+
+ case k_sin:
+
+ *outValue = sin((double) val1 * (double) PI / (double) 180.0);
+ break;
+
+
+ case k_cos:
+
+ *outValue = cos((double) val1 * (double) PI / (double) 180.0);
+ break;
+
+
+ case k_pick:
+
+ *outValue = val2;
+ break;
+ }
+ }
+ else
+ {
+ i = PDFKeyword_Find(kNumberOfGraphicsKeywords, g_graphic_keywords,
+ (FULL_CHAR*) chp);
+ if (i >= 0)
+ {
+ chp += strlen(g_graphic_keywords[i]);
+ *outValue = g_graphics_vars[i];
+ }
+ else
+ {
+ i = PDFKeyword_Find(kNumberOfUnitKeywords, g_unit_keywords, (FULL_CHAR*) chp);
+ if (i >= 0)
+ {
+ chp += strlen(g_unit_keywords[i]);
+ *outValue = g_units[i];
+ }
+ else
+ {
+ Error(48, 33, "PDFPage_EvalExpr: __add, __sub, __mul, __div, or a unit keyword was expected",
+ FATAL, no_fpos);
+ }
+ }
+ }
+ }
+ return chp;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *PDFPage_CollectExpr(FULL_CHAR* charPtr) */
+ /* */
+ /* Collect expression into the expression buffer. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR *PDFPage_CollectExpr(FULL_CHAR* charPtr, BOOLEAN* outHasResult,
+ float* outResult)
+ {
+ *outHasResult = FALSE;
+ while (*charPtr != 0)
+ {
+ char ch;
+
+ if ( g_expr_index >= sizeof(g_expr) )
+ Error(48, 34, "PDFPage_CollectExpr: expression too long (max. 512 chars)",
+ FATAL, no_fpos);
+
+ g_expr[g_expr_index++] = ch = *charPtr++;
+ if (ch == '(')
+ g_expr_depth++;
+ else if (ch == ')')
+ {
+ Assert(g_expr_depth != 0, no_fpos);
+ g_expr_depth--;
+ if (g_expr_depth == 0)
+ {
+ g_expr[g_expr_index] = '\0'; /* terminate the string */
+ (char*) PDFPage_EvalExpr(g_expr, outResult);
+ *outHasResult = TRUE;
+ break; /* exit while */
+ }
+ }
+ }
+ return charPtr;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* FULL_CHAR *PDFPage_CollectLink(FULL_CHAR* charPtr) */
+ /* */
+ /* Collect link into the link buffer. */
+ /* */
+ /*****************************************************************************/
+
+ static FULL_CHAR *PDFPage_CollectLink(FULL_CHAR* charPtr
+ /*, BOOLEAN* outHasResult, float* outResult*/)
+ {
+ debug1(DPD, D, "PDFPage_CollectLink(\"%s\")", charPtr);
+ while (*charPtr != 0)
+ {
+ char ch;
+
+ if ( g_link_index >= sizeof(g_link) )
+ Error(48, 35, "PDFPage_CollectLink: link too long (max. 512 chars)",
+ FATAL, no_fpos);
+
+ g_link[g_link_index++] = ch = *charPtr++;
+ if ((ch == '<') && (*charPtr == '<'))
+ {
+ g_link[g_link_index++] = *charPtr++;
+ g_link_depth++;
+ }
+ else if ((ch == '>') && (*charPtr == '>'))
+ {
+ Assert(g_link_depth != 0, no_fpos);
+
+ g_link_depth--;
+ if (g_link_depth == 0)
+ {
+ /* I don't want the outermost '<<' '>>' pair */
+ g_link[--g_link_index] = '\0'; /* terminate the string */
+
+ PDFPage_ProcessLinkKeyword();
+
+ charPtr++;
+ break; /* exit while */
+ }
+ else
+ g_link[g_link_index++] = *charPtr++;
+ }
+ }
+ debug0(DPD, D, "PDFPage_CollectLink returning");
+ return charPtr;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_WriteGraphic(FILE* in_fp, FULL_CHAR* in_str) */
+ /* */
+ /* Outputs an appropriate PDF string for drawing a graphic element. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_WriteGraphic(FILE* in_fp, FULL_CHAR* in_str)
+ {
+ t_tempbuf str;
+
+ FULL_CHAR *charPtr = in_str;
+ char *strPtr = str;
+
+ if (*charPtr == 0)
+ return;
+
+ /* if in collecting an expression mode then collect until terminating ')' */
+ if (g_expr_depth != 0)
+ {
+ BOOLEAN hasResult;
+ float value;
+
+ charPtr = PDFPage_CollectExpr(charPtr, &hasResult, &value);
+ if (hasResult)
+ {
+ sprintf(strPtr, "%.2f", value);
+ strPtr += strlen(strPtr);
+ }
+ }
+
+ /* if in collecting-a-link mode then collect until terminating '>>' */
+ if (g_link_depth != 0)
+ charPtr = PDFPage_CollectLink(charPtr);
+
+ /* scan the string for '__' otherwise output it */
+ while (*charPtr != 0)
+ {
+ int i;
+ float value;
+
+ Assert(strPtr < (str + sizeof(t_tempbuf)), no_fpos);
+
+ /* look for "__" (double underline) */
+ if ( (charPtr[0] == '_') && (charPtr[1] == '_') )
+ {
+ charPtr += 2;
+
+ /* "in", "cm", "pt", "em", "loutf", "loutv", "louts" */
+ #if 0
+ i = PDFKeyword_Find(kNumberOfUnitKeywords, g_unit_keywords, charPtr);
+ if (i >= 0)
+ {
+ Assert(FALSE, no_fpos);
+ charPtr += strlen(g_unit_keywords[i]); /* skip keyword */
+ charPtr = PDFPage_GetFloat(charPtr, &value); /* get value */
+ sprintf(strPtr, "%.2f", g_units[i] * value); /* output it */
+ strPtr += strlen(strPtr);
+ }
+ else
+ #endif
+ {
+
+ /* "xsize", "ysize", "xmark", "ymark" */
+ i = PDFKeyword_Find(kNumberOfGraphicsKeywords, g_graphic_keywords, charPtr);
+ if (i >= 0)
+ {
+ charPtr += strlen(g_graphic_keywords[i]);
+ #if 1
+ sprintf(strPtr, "%d", g_graphics_vars[i]);
+ strPtr += strlen(strPtr);
+ #else
+ charPtr = PDFPage_ProcessGraphicsKeyword(charPtr, i, &strPtr);
+ #endif
+ }
+ else
+ {
+ /* "link_source=<<", "link_target=<<", "link_target_for_export=<<", "link_URI=<<" */
+ i = PDFKeyword_Find(kNumberOfLinkKeywords, g_link_keywords, charPtr);
+ if (i >= 0)
+ {
+ charPtr += strlen(g_link_keywords[i]);
+ #if 1
+ while (isspace(*charPtr))
+ charPtr++;
+
+ g_link_index = 0;
+ g_link_depth++;
+ g_link_keyword = (PDF_LINK_KEYWORD) i;
+ charPtr = PDFPage_CollectLink(charPtr);
+ #else
+ charPtr = PDFPage_ProcessLinkKeyword(charPtr, (PDF_LINK_KEYWORD) i);
+ #endif
+ } /* if */
+ else
+ {
+
+ /* "author=", "title=", "subject=", "keywords=" */
+ i = PDFKeyword_Find(kNumberOfDocInfoKeywords, g_doc_info_keywords, charPtr);
+ if (i >= 0)
+ {
+ charPtr += strlen(g_doc_info_keywords[i]);
+ charPtr = PDFPage_ProcessDocInfoKeyword(charPtr, i);
+ }
+ else
+ {
+
+ /* "add" "sub" "mul" "div", "sin", "cos" */
+ i = PDFKeyword_Find(kNumberOfArithmeticKeywords, g_arithmetic_keywords, charPtr);
+ if (i >= 0)
+ {
+ strcpy(g_expr, g_arithmetic_keywords[i]);
+ charPtr += strlen(g_arithmetic_keywords[i]);
+ while (isspace(*charPtr))
+ charPtr++;
+ if (*charPtr != '(')
+ Error(48, 36, "PDFPage_WriteGraphic: '(' expected", FATAL, no_fpos);
+
+ strcat(g_expr, "(");
+ g_expr_index = strlen(g_expr);
+ g_expr_depth++;
+ {
+ BOOLEAN hasResult;
+
+ charPtr = PDFPage_CollectExpr(++charPtr, &hasResult, &value);
+ if (hasResult)
+ {
+ sprintf(strPtr, "%.2f", value);
+ strPtr += strlen(strPtr);
+ }
+ }
+ }
+ else
+ {
+ /* alert user in case there was a spelling mistake */
+ Error(48, 37, "PDFPage_WriteGraphic: '__' encountered while processing @Graphic", WARN, no_fpos);
+ *strPtr++ = '_';
+ *strPtr++ = '_';
+ } /* else */
+ } /* else */
+ } /* else */
+ } /* else */
+ } /* else */
+ } /* if */
+ else
+ {
+ *strPtr++ = *charPtr++;
+ }
+ }
+
+ *strPtr = 0;
+
+ PDFPage_FlushBuffer(in_fp); /* this is a marking operation, so flush */
+ PDFPage_Write(in_fp, str);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDFPage_PrintUnderline(FILE* in_fp, int x1, int x2, int y, int thickness) */
+ /* */
+ /* Implements underlining (just draws a horizontal line). */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_PrintUnderline(FILE* in_fp, int in_x1, int in_x2, int in_y,
+ int in_thickness)
+ {
+ t_tempbuf str;
+
+ /* this is a marking operation, so flush and turn off buffering */
+ PDFPage_FlushBuffer(in_fp);
+
+ /* fprintf(out_fp, "/ul { gsave setlinewidth dup 3 1 roll\n"); */
+ /* fprintf(out_fp, " moveto lineto stroke grestore } bind def\n"); */
+
+ sprintf(str, "q %d w %d %d m %d %d l s Q\n",in_thickness,in_x1,in_y,in_x2,in_y);
+ PDFPage_Write(in_fp, str);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_Init(FILE* in_fp, float in_scale_factor, int in_line_width) */
+ /* */
+ /* Inits the vars for the start of processing a new page. */
+ /* */
+ /* [ 0 1 2 ] [ s 0 0 ] */
+ /* [ 3 4 5 ] = [ 0 s 0 ] */
+ /* [ 6 7 8 ] [ 0 0 1 ] */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_Init(FILE* in_fp, float in_scale_factor, int in_line_width)
+ {
+
+ #ifdef USE_MATRICES
+ g_cur_matrix[0] = g_cur_matrix[4] = in_scale_factor;
+ g_cur_matrix[1] = g_cur_matrix[2] = g_cur_matrix[3] =
+ g_cur_matrix[5] = g_cur_matrix[6] = g_cur_matrix[7] = 0;
+ g_cur_matrix[8] = 1;
+ g_matrix_stack = NULL;
+ #endif
+
+ /* clear/init page vars */
+ g_page_uses_fonts = FALSE;
+ g_page_has_text = FALSE;
+ g_page_has_graphics = FALSE;
+
+ g_page_contents_obj_num = 0; /* undefined */
+ g_page_length_obj_num = 0; /* undefined */
+ g_page_start_offset = 0; /* undefined */
+ /* g_text_font_size_in_ems = 0; */ /* undefined */
+
+ g_page_h_scale_factor = g_page_v_scale_factor = in_scale_factor;
+ g_page_h_origin = g_page_v_origin = 0;
+ g_page_line_width = in_line_width;
+
+ /* ***
+ g_graphics_vars[k_in] = IN;
+ g_graphics_vars[k_cm] = CM;
+ g_graphics_vars[k_pt] = PT;
+ g_graphics_vars[k_em] = EM;
+ *** */
+ g_graphics_vars[k_xsize] = 0; /* undefined */
+ g_graphics_vars[k_ysize] = 0; /* undefined */
+ g_graphics_vars[k_xmark] = 0; /* undefined */
+ g_graphics_vars[k_ymark] = 0; /* undefined */
+ /* ***
+ g_graphics_vars[k_loutf] = 0;
+ g_graphics_vars[k_loutv] = 0;
+ g_graphics_vars[k_louts] = 0;
+ *** */
+
+ /* No need to touch k_in other constant units */
+ g_units[k_loutf] = 0; /* undefined */
+ g_units[k_loutv] = 0; /* undefined */
+ g_units[k_louts] = 0; /* undefined */
+
+ g_ET_pending = FALSE;
+ g_TJ_pending = FALSE;
+ g_valid_text_matrix = FALSE; /* Td is not allowed */
+
+ /* mark all fonts "not in use" */
+ {
+ t_font_list_entry_ptr entry = g_font_list;
+ while (entry != NULL) {
+ entry->m_in_use = FALSE; /* set the "in use" state to "not in use" */
+ entry = entry->m_next_font_entry;
+ }
+ }
+
+ /* init qsave stack */
+ g_qsave_stack = NULL;
+
+ /* init qsave_marking stack */
+ g_qsave_marking_stack = NULL;
+ g_buffer_pos = 0;
+ /* buffer contains empty string */
+ g_buffer[0] = '\0';
+ /* try to chop entire stream if possible! Originally: FALSE; */
+ /* turn on buffering only AFTER a save request */
+ g_in_buffering_mode = FALSE;
+ /* try to chop entire stream if possible! Originally: FALSE; */
+ /* turn on buffering only AFTER a save request */
+ g_in_buffering_mode = TRUE;
+
+ /* bump page number */
+ ++g_page_count;
+ g_page_object_num = PDFObject_New(/* in_fp */);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFPage_Cleanup(FILE* in_fp) */
+ /* */
+ /* Cleans up the processing after a page's contents have been written out. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFPage_Cleanup(FILE* in_fp)
+ {
+ BOOLEAN hasAnnot = FALSE;
+
+ Assert(g_qsave_stack == NULL, no_fpos);
+
+ /* if page has some content then close its stream object */
+ if (g_page_contents_obj_num != 0)
+ {
+ PDF_FILE_OFFSET page_length = PDFPage_End(in_fp);
+
+ #ifdef _CALC_LARGEST_PAGE_OBJECT_
+ if (page_length > g_max_page_length)
+ g_max_page_length = page_length;
+ #endif
+
+ /* write page's length object */
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% length object for page %u:\n%%\n", g_page_count);
+
+ PDFObject_WriteObj(in_fp, g_page_length_obj_num);
+ fprintf(in_fp, "%u\nendobj\n", page_length);
+
+ /* write out any used font resources */
+ {
+ t_font_list_entry_ptr entry = g_font_list;
+ while (entry != NULL) {
+ PDFFont_WriteFontResource(in_fp, entry);
+ entry = entry->m_next_font_entry;
+ }
+ }
+ }
+
+ /* write out annotations */
+ {
+ t_source_annot_entry_ptr source = g_source_annot_list;
+
+ while (source != NULL)
+ {
+ if (source->m_this_page_object_num == g_page_object_num)
+ {
+
+ /* even if the annotation(s) cannot be written out now, flag the */
+ /* fact that this page has annotations */
+ hasAnnot = TRUE;
+
+ /* attempt to write out annotation */
+ PDFSourceAnnot_Write(in_fp, source);
+ } /* if annot entry belongs to this page */
+ source = source->m_next_entry;
+ } /* while */
+ }
+
+ /* start writing page object ("/Type /Page"); remember its number */
+ {
+ unsigned int wanted_block_num = (g_page_count - 1) / kNumberOfPagesPerBlock;
+ unsigned int block_pos = (g_page_count - 1) % kNumberOfPagesPerBlock;
+ t_page_block_ptr the_block = g_cur_page_block;
+
+ /* if first obj in a block then allocate the block */
+ if (block_pos == 0)
+ {
+ the_block = (t_page_block_ptr) malloc(sizeof(t_page_block));
+ if (the_block == NULL)
+ Error(48, 38, "PDFPage_Cleanup: run out of memory", FATAL, no_fpos);
+ if (wanted_block_num == 0) /* if first block in file */
+ {
+ Assert(g_page_block_list == NULL, no_fpos);
+ g_page_block_list = the_block;
+ }
+ else
+ {
+ Assert(g_cur_page_block != NULL, no_fpos);
+ g_cur_page_block->m_next_block = the_block;
+ }
+ the_block->m_next_block = NULL; /* don't forget to init this! */
+ g_cur_page_block = the_block;
+ }
+ else
+ {
+ Assert(the_block != NULL, no_fpos);
+ }
+
+ /* save object number of this page for later use in the /Pages list */
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% page number %u:\n%%\n", g_page_count);
+ the_block->m_block[block_pos] = g_page_object_num;
+ PDFObject_WriteObj(in_fp, g_page_object_num);
+ /* PDFObject_WriteNewObj(in_fp); */
+ }
+
+ /* write out /Page ID */
+ fputs("<<\n/Type /Page\n", in_fp);
+
+ /* write out page size and orientation */
+ fprintf(in_fp, "/CropBox [ 0 0 %u %u ]\n",g_doc_h_bound,g_doc_v_bound);
+
+ /* write out parent object ref */
+ fputs("/Parent ", in_fp);
+ PDFObject_WriteRef(in_fp, g_pages_root);
+ fputs("\n", in_fp);
+
+ /* write out contents object ref (if it exists) */
+ if (g_page_contents_obj_num != 0)
+ {
+ fputs("/Contents ", in_fp);
+ PDFObject_WriteRef(in_fp, g_page_contents_obj_num);
+ fputs("\n", in_fp);
+ }
+
+ /* open resources dictionary */
+ if (g_page_uses_fonts || g_page_has_text || g_page_has_graphics)
+ fputs("/Resources\n<<\n", in_fp);
+
+ /* write out font resources used */
+ if (g_page_uses_fonts)
+ {
+ t_font_list_entry_ptr entry = g_font_list;
+ fputs("/Font <<", in_fp);
+ while (entry != NULL) {
+ if (entry->m_in_use) {
+ fprintf(in_fp, " %s ", entry->m_PDF_font_name);
+ PDFFont_WriteObjectRef(in_fp, entry);
+ }
+ entry = entry->m_next_font_entry;
+ }
+ fputs(" >>\n", in_fp);
+ }
+
+ /* write out any procsets used */
+ if (g_page_has_text || g_page_has_graphics)
+ {
+ fputs("/ProcSet [ /PDF", in_fp);
+ if (g_page_has_text)
+ fputs(" /Text", in_fp);
+ fputs(" ]\n", in_fp);
+ }
+
+ /* close resources dictionary */
+ if (g_page_uses_fonts || g_page_has_text || g_page_has_graphics)
+ fputs(">>\n", in_fp);
+
+ /* write out annot array */
+ if (hasAnnot)
+ {
+ t_source_annot_entry_ptr entry = g_source_annot_list;
+ t_source_annot_entry_ptr previous_entry = NULL;
+
+ /* write out annotations */
+ fputs("/Annots [", in_fp);
+ while (entry != NULL)
+ {
+ if (entry->m_this_page_object_num == g_page_object_num)
+ {
+ fputs(" ", in_fp);
+ PDFObject_WriteRef(in_fp, entry->m_this_object_num);
+
+ /* if the annotation has just been written out above then delete it */
+ if (entry->m_written_to_PDF_file)
+ {
+ t_source_annot_entry_ptr next_entry = entry->m_next_entry;
+ if (g_source_annot_list == entry)
+ g_source_annot_list = next_entry;
+ if (previous_entry != NULL)
+ previous_entry->m_next_entry = next_entry;
+ PDFSourceAnnot_Dispose(entry);
+ entry = next_entry;
+ }
+ else /* annot is a fwd referring one: defer deleting it */
+ {
+ previous_entry = entry;
+ entry = entry->m_next_entry;
+ }
+ } /* if annot entry belongs to this page */
+ else /* annot does not belong to this page; skip it */
+ {
+ previous_entry = entry;
+ entry = entry->m_next_entry;
+ }
+ } /* while */
+ fputs(" ]\n", in_fp);
+ } /* if */
+
+ /* close object */
+ fputs(">>\nendobj\n", in_fp);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFFile_Init(FILE* in_fp, int in_h_bound, int in_v_bound) */
+ /* */
+ /* Initialize this module. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFFile_Init(FILE* in_fp, int in_h_bound, int in_v_bound,
+ int in_IN, int in_CM, int in_PT, int in_EM)
+ {
+ /* write PDF header */
+ fputs("%PDF-1.2\n", in_fp); /* identifies this as PDF */
+ fputs("\045\342\343\317\323\n", in_fp); /* 0x25 0xE2 0xE3 0xCF 0xD3 */
+
+ /* set debugging status */
+ #if DEBUG_ON
+ g_PDF_debug = dbg[DPD].on[D] || dbg[DPD].on[DD] || dbg[DPD].on[DDD];
+ #else
+ g_PDF_debug = FALSE;
+ #endif
+
+ #if PDF_COMPRESSION
+ g_apply_compression = !g_PDF_debug;
+ #endif
+
+ /* objects */
+ g_next_objnum = 1; /* object numbers start at one */
+ g_obj_offset_list = NULL;
+ g_cur_obj_offset_block = NULL;
+
+ /* fonts */
+ g_font_list = NULL;
+ g_font_encoding_list = NULL;
+
+ /* pages */
+ g_page_count = 0;
+ g_page_block_list = NULL;
+ g_cur_page_block = NULL;
+ g_pages_root = PDFObject_New(/* in_fp */);
+
+ /* doc */
+ g_doc_h_bound = in_h_bound;
+ g_doc_v_bound = in_v_bound;
+ g_doc_author = NULL;
+ g_doc_title = NULL;
+ g_doc_subject = NULL;
+ g_doc_keywords = NULL;
+
+ /* link annotations */
+ g_target_annot_list = NULL;
+ g_has_exported_targets = FALSE;
+ g_source_annot_list = NULL;
+
+ /* units */
+ g_units[k_in] = in_IN;
+ g_units[k_cm] = in_CM;
+ g_units[k_pt] = in_PT;
+ g_units[k_em] = in_EM;
+
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFFile_WritePagesObject(FILE* in_fp) */
+ /* */
+ /* Cleans up processing after all pages has been written out. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDFFile_WritePagesObject(FILE* in_fp)
+ {
+ unsigned int i;
+ t_page_block_ptr the_block = g_page_block_list;
+
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% root of pages tree:\n%%\n");
+
+ /* write out the root of the Pages tree */
+ PDFObject_WriteObj(in_fp, g_pages_root);
+ fputs("<<\n", in_fp);
+ fputs("/Type /Pages\n", in_fp);
+ fputs("/Kids [ ", in_fp);
+ for (i = 0; i < g_page_count; i++)
+ {
+ int block_pos = i % kNumberOfPagesPerBlock;
+ PDFObject_WriteRef(in_fp, the_block->m_block[block_pos]);
+ if (block_pos == (kNumberOfPagesPerBlock - 1))
+ {
+ the_block = the_block->m_next_block;
+ /* Assert(the_block != NULL, no_fpos); not always true! */
+ }
+ fputs(" ", in_fp);
+ }
+ fprintf(in_fp, " ]\n/Count %u\n", g_page_count);
+ /* ***
+ fprintf(in_fp, "/MediaBox [ 0 0 612 792 ]\n");
+ fprintf(in_fp, "/MediaBox [ 0 0 %u %u ]\n",g_doc_h_bound,g_doc_v_bound);
+ *** */
+ fprintf(in_fp, "/MediaBox [ 0 0 %u %u ]\n", g_doc_h_bound, g_doc_v_bound);
+ fputs(">>\nendobj\n", in_fp);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_FILE_OFFSET PDFFile_WriteXREF(FILE* in_fp) */
+ /* */
+ /* Writes out the XREF table. */
+ /* */
+ /*****************************************************************************/
+
+ static PDF_FILE_OFFSET PDFFile_WriteXREF(FILE* in_fp)
+ {
+ int i;
+ PDF_FILE_OFFSET xref_start;
+ t_offset_block_ptr the_block = g_obj_offset_list;
+
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% xref table:\n%%\n");
+
+ xref_start = ftell(in_fp);
+ fputs("xref\n", in_fp);
+ fprintf(in_fp, "0 %u\n", g_next_objnum);
+ fputs("0000000000 65535 f \n", in_fp); /* object 0 is a deleted obj */
+ Assert( (g_next_objnum == 1) || (the_block != NULL), no_fpos);
+ for (i = 1; i < g_next_objnum; i++) /* write out list of object offsets */
+ {
+ int block_pos = (i - 1) % kNumberOfObjectsPerBlock;
+
+ /* always write an entry (even if the object doesn't exist) */
+ fprintf(in_fp, "%010u 00000 n \n", the_block->m_block[block_pos]);
+
+ if (the_block->m_block[block_pos] == 0)
+ {
+ t_tempbuf str;
+
+ strcpy(str, "PDFFile_WriteXREF: undefined object number: ");
+ sprintf(str + strlen(str), "%u", i);
+ Error(48, 39, "%s", WARN, no_fpos, str);
+ }
+
+ if (block_pos == (kNumberOfObjectsPerBlock - 1))
+ {
+ the_block = the_block->m_next_block;
+ /* Assert(the_block != NULL, no_fpos); not always true! */
+ }
+ }
+ return xref_start;
+ }
+
+ /*****************************************************************************/
+ /* */
+ /* void PDFFile_Cleanup(FILE* in_fp) */
+ /* */
+ /* Cleans up processing after all pages has been written out. */
+ /* */
+ /*****************************************************************************/
+
+ void PDFFile_Cleanup(FILE* in_fp)
+ {
+ PDF_FILE_OFFSET xref_start; /* file offset of start of xref table */
+ PDF_OBJECT_NUM catalog_obj_num;
+ PDF_OBJECT_NUM info_obj_num;
+ PDF_OBJECT_NUM dests_obj_num;
+
+ /* write out any unresolved link annotations. This could be done earlier */
+ /* (in fact, it can be done as each new target is defined) but I've */
+ /* arbitrarily decided to do it here. */
+ {
+ t_source_annot_entry_ptr source = g_source_annot_list;
+
+ while (source != NULL)
+ {
+ t_target_annot_entry_ptr target;
+
+ Assert(source->m_target == NULL, no_fpos);
+ target = PDFTargetAnnot_Find(source->m_name);
+ if (target != NULL)
+ {
+ source->m_target = target;
+ PDFSourceAnnot_Write(in_fp, source);
+ }
+ source = source->m_next_entry;
+ }
+ }
+
+ /* write out pages object */
+ PDFFile_WritePagesObject(in_fp);
+
+ /* if file has exported targets for links then write out /Dests dictionary */
+ if (g_has_exported_targets)
+ {
+ t_target_annot_entry_ptr entry = g_target_annot_list;
+
+ Assert(entry != NULL, no_fpos); /* should be at least an entry! */
+
+ /* write PDF 1.1 style /Dests dictionary */
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% /Dests dictionary (exported links):\n%%\n");
+
+ dests_obj_num = PDFObject_WriteNewObj(in_fp);
+ fputs("<<\n", in_fp);
+
+ while (entry != NULL)
+ {
+ if (entry->m_for_export)
+ {
+ fprintf(in_fp, "/%s [ ", entry->m_name);
+ PDFObject_WriteRef(in_fp, entry->m_page_object_num);
+ fprintf(in_fp, " /XYZ null null null ]\n");
+ }
+ entry = entry->m_next_entry;
+ }
+ fputs(">>\nendobj\n", in_fp);
+ }
+
+ /* write out catalog object */
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% catalog:\n%%\n");
+
+ catalog_obj_num = PDFObject_WriteNewObj(in_fp);
+ fputs("<<\n", in_fp);
+ fputs("/Type /Catalog\n", in_fp);
+ fputs("/Pages ", in_fp);
+ PDFObject_WriteRef(in_fp, g_pages_root);
+ fputs("\n", in_fp);
+
+ /* if file has exported targets for links then write out a /Dest dictionary */
+ if (g_has_exported_targets)
+ {
+ fputs("/Dests ", in_fp);
+ PDFObject_WriteRef(in_fp, dests_obj_num);
+ fputs("\n", in_fp);
+ }
+
+ /* ***
+ fputs("/PageMode ", in_fp);
+ switch ()
+ {
+ }
+ fputs("\n", in_fp);
+ *** */
+
+ fputs(">>\nendobj\n", in_fp);
+
+ /* write out info object */
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% Info object:\n%%\n");
+
+ /* ***
+ Author string (Optional) The name of the person who created the document.
+ CreationDate Date (Optional) The date the document was created.
+ ModDate Date (Optional) The date the document was last modified.
+ Creator string (Optional) If the document was converted into a PDF document from another
+ form, this is the name of the application that created the original document.
+ Producer string (Optional) The name of the application that converted the document from its native
+ format to PDF.
+ Title string (Optional) The documentÕs title.
+ Subject string (Optional) The subject of the document.
+ Keywords string (Optional) Keywords associated with the document.
+
+ example:
+
+ /Creator (Adobe Illustrator)
+ /CreationDate (D:19930204080603-08'00')
+ /Author (Werner Heisenberg)
+ /Producer (Acrobat Network Distiller 1.0 for Macintosh)
+ *** */
+
+ info_obj_num = PDFObject_WriteNewObj(in_fp);
+ fputs("<<\n", in_fp);
+
+ fprintf(in_fp, "/Creator (%s)\n", LOUT_VERSION);
+ fprintf(in_fp, "/Producer (%s)\n", LOUT_VERSION);
+
+ {
+ time_t now;
+ struct tm *date;
+
+ /* I will presume that localtime() is Y2K compliant. If it isn't */
+ /* on your system, feel free to tweak this code. :-) */
+
+ now = time( NULL );
+ date = localtime( &now );
+ fprintf(in_fp, "/CreationDate (D:%.4d%.2d%.2d%.2d%.2d%.2d)\n",
+ date->tm_year + 1900, date->tm_mon + 1, date->tm_mday,
+ date->tm_hour, date->tm_min, date->tm_sec);
+ }
+
+ if (g_doc_author != NULL)
+ fprintf(in_fp, "/Author (%s)\n", g_doc_author);
+
+ if (g_doc_title != NULL)
+ fprintf(in_fp, "/Title (%s)\n", g_doc_title);
+
+ if (g_doc_subject != NULL)
+ fprintf(in_fp, "/Subject (%s)\n", g_doc_subject);
+
+ if (g_doc_keywords != NULL)
+ fprintf(in_fp, "/Keywords (%s)\n", g_doc_keywords);
+
+ fputs(">>\nendobj\n", in_fp);
+
+ /* write out xref table */
+ xref_start = PDFFile_WriteXREF(in_fp);
+
+ /* write out trailer */
+ /* *** uwe: comments can appear in the body only.
+ if (g_PDF_debug)
+ fprintf(in_fp, "%%\n%% trailer:\n%%\n");
+ *** */
+
+ fputs("trailer\n<<\n", in_fp);
+ fprintf(in_fp, "/Size %u\n", g_next_objnum);
+ fputs("/Root ", in_fp);
+ PDFObject_WriteRef(in_fp, catalog_obj_num);
+ fputs("\n/Info ", in_fp);
+ PDFObject_WriteRef(in_fp, info_obj_num);
+
+ fprintf(in_fp, " >>\nstartxref\n%u\n", xref_start);
+ fputs("%%EOF\n", in_fp);
+
+ /* memory deallocation (no need to dispose of the qsave_marking_stack */
+ /* because it's always empty after a page has been processed) */
+
+ while (g_obj_offset_list != NULL)
+ {
+ t_offset_block_ptr the_block = g_obj_offset_list;
+ g_obj_offset_list = the_block->m_next_block;
+ free(the_block);
+ }
+
+ while (g_font_encoding_list != NULL)
+ {
+ t_font_encoding_entry_ptr the_block = g_font_encoding_list;
+ g_font_encoding_list = the_block->m_next_entry;
+ free(the_block->m_font_encoding);
+ free(the_block);
+ }
+
+ while (g_font_list != NULL)
+ {
+ t_font_list_entry_ptr the_block = g_font_list;
+ g_font_list = the_block->m_next_font_entry;
+ free(the_block->m_PDF_font_name);
+ free(the_block->m_short_font_name);
+ free(the_block->m_actual_font_name);
+ free(the_block);
+ }
+
+ while (g_page_block_list != NULL)
+ {
+ t_page_block_ptr the_block = g_page_block_list;
+ g_page_block_list = the_block->m_next_block;
+ free(the_block);
+ }
+
+ while (g_source_annot_list != NULL)
+ {
+ t_source_annot_entry_ptr entry = g_source_annot_list;
+
+ if (entry->m_target == NULL)
+ {
+ t_tempbuf str;
+ strcpy(str, "PDFFile_Cleanup: unresolved link annotation named ");
+ strcat(str, (char*) entry->m_name);
+ Error(48, 40, "%s", WARN, no_fpos, str);
+ }
+
+ g_source_annot_list = PDFSourceAnnot_Dispose(entry);
+ }
+
+ while (g_target_annot_list != NULL)
+ {
+ t_target_annot_entry_ptr entry = g_target_annot_list;
+ g_target_annot_list = entry->m_next_entry;
+ free(entry->m_name);
+ free(entry);
+ }
+
+ #ifdef _CALC_LARGEST_PAGE_OBJECT_
+ /* display largest page object */
+ {
+ t_tempbuf str;
+ /* JK sprintf(str, "The largest page object is %u bytes long.", g_max_page_length); */
+ Error(48, 41, "The largest page object is %u bytes long.", WARN, no_fpos, g_max_page_length);
+ }
+ #endif
+ }
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z49.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z49.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z49.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,1413 ----
+ /*@z49.c:PostScript Back End:PS_BackEnd@**************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z49.c */
+ /* MODULE: PostScript Back End */
+ /* EXTERNS: PS_BackEnd */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* State variables for this module */
+ /* */
+ /*****************************************************************************/
+ #define StartUpResource "LoutStartUp"
+ #define NO_FONT 0 /* actually stolen from z37.c */
+ #define NO_COLOUR 0
+ #define MAX_GS 50 /* maximum depth of graphics states */
+
+ BOOLEAN Encapsulated; /* TRUE if EPS file is wanted */
+
+ typedef struct
+ {
+ FONT_NUM gs_font; /* font number of this state */
+ COLOUR_NUM gs_colour; /* colour number of this state */
+ BOOLEAN gs_cpexists; /* TRUE if a current point exists */
+ FULL_LENGTH gs_currenty; /* if cpexists, its y coordinate */
+ short gs_xheight2; /* of font exists, half xheight */
+ } GRAPHICS_STATE;
+
+ static GRAPHICS_STATE gs_stack[MAX_GS];/* graphics state stack */
+ static int gs_stack_top; /* top of graphics state stack */
+
+ static FONT_NUM currentfont; /* font of most recent atom */
+ static COLOUR_NUM currentcolour; /* colour of most recent atom */
+ static short currentxheight2;/* half xheight in current font */
+ static BOOLEAN cpexists; /* true if a current point exists */
+ static FULL_LENGTH currenty; /* if cpexists, its y coordinate */
+
+ static int wordcount; /* atoms printed since last newline */
+ static int pagecount; /* total number of pages printed */
+ static BOOLEAN prologue_done; /* TRUE after prologue is printed */
+ static OBJECT needs; /* Resource needs of included EPSFs */
+ static OBJECT supplied; /* Resources supplied by this file */
+ static FILE *out_fp; /* file to print PostScript on */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Data structures for checking links */
+ /* */
+ /* We keep a hash table of all dest points, and an ordinary list of all */
+ /* source points. To check that no dest point appears twice, we consult */
+ /* the hash table once for each dest point to ensure it is not already */
+ /* there. To check that every source point has an dest, we run through */
+ /* the list of source points at end of run and look each one up in the */
+ /* dest point hash table. */
+ /* */
+ /*****************************************************************************/
+
+ /*****************************************************************************/
+ /* */
+ /* LINK_DEST_TABLE */
+ /* */
+ /* A symbol table permitting access to link dest name objects. */
+ /* The table will automatically enlarge to accept any number of entries. */
+ /* */
+ /* ltab_new(newsize) New empty table, newsize capacity */
+ /* ltab_insert(x, &S) Insert new link dest name object x into S */
+ /* ltab_retrieve(str, S) Retrieve link dest name object named str */
+ /* ltab_debug(S, fp) Debug print of table S to file fp */
+ /* */
+ /*****************************************************************************/
+
+ typedef struct
+ { int linktab_size; /* size of table */
+ int linktab_count; /* number of objects held */
+ OBJECT linktab_item[1];
+ } *LINK_DEST_TABLE;
+
+ #define ltab_size(S) (S)->linktab_size
+ #define ltab_count(S) (S)->linktab_count
+ #define ltab_item(S, i) (S)->linktab_item[i]
+
+ #define hash(pos, str, S) \
+ { FULL_CHAR *p = str; \
+ pos = *p++; \
+ while( *p ) pos += *p++; \
+ pos = pos % ltab_size(S); \
+ }
+
+ static LINK_DEST_TABLE ltab_new(int newsize)
+ { LINK_DEST_TABLE S; int i;
+ /* ifdebug(DMA, D, DebugRegisterUsage(MEM_LINK_TAB, 1,
+ 2*sizeof(int) + newsize * sizeof(OBJECT))); */
+ S = (LINK_DEST_TABLE)
+ malloc(2*sizeof(int) + newsize * sizeof(OBJECT));
+ if( S == (LINK_DEST_TABLE) NULL )
+ Error(43, 1, "run out of memory enlarging link dest table", FATAL, no_fpos);
+ ltab_size(S) = newsize;
+ ltab_count(S) = 0;
+ for( i = 0; i < newsize; i++ ) ltab_item(S, i) = nilobj;
+ return S;
+ } /* end ltab_new */
+
+ static void ltab_insert(OBJECT x, LINK_DEST_TABLE *S);
+
+ static LINK_DEST_TABLE ltab_rehash(LINK_DEST_TABLE S, int newsize)
+ { LINK_DEST_TABLE NewS; int i;
+ NewS = ltab_new(newsize);
+ for( i = 1; i <= ltab_size(S); i++ )
+ { if( ltab_item(S, i) != nilobj )
+ ltab_insert(ltab_item(S, i), &NewS);
+ }
+ free(S);
+ return NewS;
+ } /* end ltab_rehash */
+
+ static void ltab_insert(OBJECT x, LINK_DEST_TABLE *S)
+ { int pos; OBJECT z, link, y;
+ if( ltab_count(*S) == ltab_size(*S) - 1 ) /* one less since 0 unused */
+ *S = ltab_rehash(*S, 2*ltab_size(*S));
+ hash(pos, string(x), *S);
+ if( ltab_item(*S, pos) == nilobj ) New(ltab_item(*S, pos), ACAT);
+ z = ltab_item(*S, pos);
+ for( link = Down(z); link != z; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(string(x), string(y)) )
+ { Error(43, 2, "link name %s used twice (first at%s)",
+ WARN, &fpos(x), string(x), EchoFilePos(&fpos(y)));
+ }
+ }
+ Link(ltab_item(*S, pos), x);
+ } /* end ltab_insert */
+
+ static OBJECT ltab_retrieve(FULL_CHAR *str, LINK_DEST_TABLE S)
+ { OBJECT x, link, y; int pos;
+ hash(pos, str, S);
+ x = ltab_item(S, pos);
+ if( x == nilobj ) return nilobj;
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( StringEqual(str, string(y)) ) return y;
+ }
+ return nilobj;
+ } /* end ltab_retrieve */
+
+ #if DEBUG_ON
+ static void ltab_debug(LINK_DEST_TABLE S, FILE *fp)
+ { int i; OBJECT x, link, y;
+ fprintf(fp, " table size: %d; current number of keys: %d\n",
+ ltab_size(S), ltab_count(S));
+ for( i = 0; i < ltab_size(S); i++ )
+ { x = ltab_item(S, i);
+ fprintf(fp, "ltab_item(S, %d) =", i);
+ if( x == nilobj )
+ fprintf(fp, " <nilobj>");
+ else if( type(x) != ACAT )
+ fprintf(fp, " not ACAT!");
+ else for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ fprintf(fp, " %s",
+ is_word(type(y)) ? string(y) : AsciiToFull("not-WORD!"));
+ }
+ fprintf(fp, "\n");
+ }
+ } /* end ltab_debug */
+ #endif
+
+ static LINK_DEST_TABLE link_dest_tab; /* the link dest names */
+ static OBJECT link_source_list; /* the link source names */
+
+ /*****************************************************************************/
+ /* */
+ /* Print a number x on file fp. */
+ /* */
+ /*****************************************************************************/
+
+ #define printnum(x, fp) \
+ { char buff[20]; register int i, y; \
+ if( x >= 0 ) y = x; \
+ else { y = -x; putc(CH_MINUS, fp); } \
+ i = 0; \
+ do { buff[i++] = numtodigitchar(y % 10); \
+ } while( (y = (y / 10)) > 0 ); \
+ do { --i; putc(buff[i], fp); \
+ } while( i ); \
+ }
+
+ /*****************************************************************************/
+ /* */
+ /* PS_PrintInitialize(FILE *fp) */
+ /* */
+ /* Initialize this module; fp is the output file. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintInitialize(FILE *fp)
+ {
+ debug0(DPO, DD, "PS_PrintInitialize(fp)");
+ out_fp = fp;
+ prologue_done = FALSE;
+ gs_stack_top = -1;
+ currentfont = NO_FONT;
+ currentcolour = NO_COLOUR;
+ cpexists = FALSE;
+ wordcount = pagecount = 0;
+ New(needs, ACAT);
+ New(supplied, ACAT);
+ debug0(DPO, DD, "PS_PrintInitialize returning.");
+ link_dest_tab = ltab_new(200);
+ New(link_source_list, ACAT);
+ } /* end PS_PrintInitialize */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PS_PrintLength(FULL_CHAR *buff, int length, int length_dim) */
+ /* */
+ /* Print a length (debugging only) */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintLength(FULL_CHAR *buff, int length, int length_dim)
+ {
+ sprintf( (char *) buff, "%.3fc", (float) length/CM);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PS_PrintPageSetupForFont(OBJECT face, int font_curr_page, */
+ /* FULL_CHAR *font_name, FULL_CHAR *short_name) */
+ /* */
+ /* Print the page setup commands required to use a font on some page: */
+ /* */
+ /* face The font face record, defining which font we need */
+ /* font_curr_page The current page number */
+ /* font_name The name of the font */
+ /* short_name Internal short name for the font */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintPageSetupForFont(OBJECT face, int font_curr_page,
+ FULL_CHAR *font_name, FULL_CHAR *short_name)
+ {
+ fprintf(out_fp, "%%%%IncludeResource: font %s\n", font_name);
+ if( font_recoded(face) )
+ {
+ MapEnsurePrinted(font_mapping(face), font_curr_page);
+ fprintf(out_fp, "/%s%s %s /%s LoutRecode\n",
+ font_name, short_name,
+ MapEncodingName(font_mapping(face)), font_name);
+ fprintf(out_fp, "/%s { /%s%s LoutFont } def\n", short_name,
+ font_name, short_name);
+ }
+ else fprintf(out_fp, "/%s { /%s LoutFont } def\n", short_name, font_name);
+ } /* end PrintPageSetupForFont */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PS_PrintPageResourceForFont(FULL_CHAR *font_name, BOOLEAN first) */
+ /* */
+ /* Print page resource info on file fp for font font_name; first is true */
+ /* if this is the first resource on this page. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintPageResourceForFont(FULL_CHAR *font_name, BOOLEAN first)
+ {
+ fprintf(out_fp, "%s font %s\n", first ? "%%PageResources:" : "%%+",font_name);
+ } /* end PS_PrintPageResourceForFont */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static void PS_PrintMapping(MAPPING m) */
+ /* */
+ /* Print mapping m onto out_fp. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintMapping(MAPPING m)
+ { MAP_VEC map = MapTable[m]; int i;
+ fprintf(out_fp, "%%%%BeginResource: encoding %s\n", string(map->name));
+ fprintf(out_fp, "/%s [\n", string(map->name));
+ for( i = 0; i < MAX_CHARS; i++ )
+ fprintf(out_fp, "/%s%c", string(map->vector[i]), (i+1)%8 != 0 ? ' ' : '\n');
+ fprintf(out_fp, "] def\n");
+ fprintf(out_fp, "%%%%EndResource\n\n");
+ } /* end PrintMapping */
+
+
+ /*****************************************************************************/
+ /* */
+ /* char *MediaName(int h, int v) */
+ /* */
+ /* Return the PostScript MediaName attribute appropriate to a page of */
+ /* width h and height v. */
+ /* */
+ /* Communicated by Valeriy E. Ushakov, who wrote: */
+ /* */
+ /* "Attached is a patch to recognize known paper sizes and emit them as */
+ /* media name in DocumentMedia comment. GhostView and other PostScript */
+ /* viewers recognize these names and display them to the user. Thus user */
+ /* knows what paper size document uses without having to know the magic */
+ /* numbers." */
+ /* */
+ /*****************************************************************************/
+
+ static const char *MediaName(int h, int v)
+ {
+ struct paper {
+ const char *name;
+ FULL_LENGTH width, height;
+ };
+
+ /* names for known paper sizes */
+ static const struct paper paper_map[] = {
+ { "Letter", 612*PT, 792*PT },
+ { "Tabloid", 792*PT, 1224*PT },
+ { "Ledger", 1224*PT, 792*PT },
+ { "Legal", 612*PT, 1008*PT },
+ { "Statement", 396*PT, 612*PT },
+ { "Executive", 540*PT, 720*PT },
+ { "A3", 842*PT, 1190*PT },
+ { "A4", 595*PT, 842*PT },
+ { "A5", 420*PT, 595*PT },
+ { "B4", 729*PT, 1032*PT },
+ { "B5", 516*PT, 729*PT },
+ { "Folio", 612*PT, 936*PT },
+ { "Quarto", 610*PT, 780*PT },
+ { "10x14", 720*PT, 1008*PT },
+ { NULL, 0, 0 }
+ };
+
+ /* default media name */
+ static const char *user_defined = "Plain";
+
+ const struct paper *p;
+ for (p = paper_map; p->name; ++p) {
+ if ((h == p->width) && (v == p->height)) {
+ return p->name;
+ }
+ }
+ return user_defined;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* static void PrintBeforeFirstPage(FULL_LENGTH h, FULL_LENGTH v, */
+ /* FULL_CHAR *label) */
+ /* */
+ /* Print whatever is needed before the start of the first page: the */
+ /* PostScript prologue, augmented with any @PrependGraphic or */
+ /* @SysPrependGraphic files specified by the user. The following */
+ /* PostScript operators are defined: */
+ /* */
+ /* scale_factor fnt scale and set font */
+ /* x_coordinate x move to x_coordinate, current y coordinate */
+ /* string s show string */
+ /* number in result is number inches */
+ /* number cm result is number centimetres */
+ /* number pt result is number points */
+ /* number sp result is number spaces */
+ /* number vs result is number vspaces */
+ /* number ft result is number font-sizes */
+ /* */
+ /* as well as LoutGraphic, for use with the @Graphic operator: */
+ /* */
+ /* xsize ysize xmark ymark fr vs sp LoutGraphic - */
+ /* */
+ /* Define xmark, ymark, xsize, ysize to be the positions of */
+ /* these features of x, and define symbols ft, vs and sp */
+ /* to be the current font size, line separation, and space width. */
+ /* */
+ /*****************************************************************************/
+
+ #define p0(str) fputs(str, out_fp)
+ #define p1(str, arg1) fprintf(out_fp, str, arg1)
+ #define p2(str, arg1, arg2) fprintf(out_fp, str, arg1, arg2)
+ #define p3(str, arg1, arg2, arg3) fprintf(out_fp, str, arg1, arg2, arg3)
+
+ static void PS_PrintBeforeFirstPage(FULL_LENGTH h, FULL_LENGTH v,
+ FULL_CHAR *label)
+ { FILE_NUM fnum; FULL_CHAR *p;
+ debug2(DPO, DD, "PrintBeforeFirst(%d, %d)", h, v);
+
+ /* print header comments for PostScript DSC 3.0 output */
+ if( Encapsulated )
+ p0("%!PS-Adobe-3.0 EPSF-3.0\n");
+ else
+ p0("%!PS-Adobe-3.0\n");
+ p1("%%%%Creator: %s\n", LOUT_VERSION);
+ p1("%%%%CreationDate: %s", TimeString());
+ p0("%%DocumentData: Binary\n");
+ p0("%%DocumentNeededResources: (atend)\n");
+ p0("%%DocumentSuppliedResources: (atend)\n");
+ p3("%%%%DocumentMedia: %s %d %d 0 white ()\n", MediaName(h, v), h/PT, v/PT);
+ p0("%%PageOrder: Ascend\n");
+ p0("%%Pages: (atend)\n");
+ p2("%%%%BoundingBox: 0 0 %d %d\n", h/PT, v/PT);
+ p0("%%EndComments\n\n");
+
+ /* print procedure definitions part of header */
+ p0("%%BeginProlog\n");
+ p1("%%%%BeginResource: procset %s\n", StartUpResource);
+ p0("/save_cp { currentpoint /cp_y exch def /cp_x exch def } def\n");
+ p0("/restore_cp { cp_x cp_y moveto } def\n");
+ p0("/outline { gsave 1 1 1 setrgbcolor dup show save_cp\n");
+ p0(" grestore true charpath stroke restore_cp } bind def\n");
+ p0("/m { 3 1 roll moveto show } bind def\n");
+ p0("/mo { 3 1 roll moveto outline } bind def\n");
+ p0("/s { exch currentpoint exch pop moveto show } bind def\n");
+ p0("/so { exch currentpoint exch pop moveto outline } bind def\n");
+ p0("/k { exch neg 0 rmoveto show } bind def\n");
+ p0("/ko { exch neg 0 rmoveto outline } bind def\n");
+ p0("/r { exch 0 rmoveto show } bind def\n");
+ p0("/ro { exch 0 rmoveto outline } bind def\n");
+ p0("/c { gsave 3 1 roll rmoveto show grestore } bind def\n");
+ p0("/co { gsave 3 1 roll rmoveto outline grestore } bind def\n");
+ p0("/ul { gsave setlinewidth dup 3 1 roll\n");
+ p0(" moveto lineto stroke grestore } bind def\n");
+ p1("/in { %d mul } def\n", IN);
+ p1("/cm { %d mul } def\n", CM);
+ p1("/pt { %d mul } def\n", PT);
+ p1("/em { %d mul } def\n", EM);
+ p0("/sp { louts mul } def\n");
+ p0("/vs { loutv mul } def\n");
+ p0("/ft { loutf mul } def\n");
+ p0("/dg { } def\n\n");
+
+ p0("/LoutGraphic {\n");
+ p0(" /louts exch def\n");
+ p0(" /loutv exch def\n");
+ p0(" /loutf exch def\n");
+ p0(" /ymark exch def\n");
+ p0(" /xmark exch def\n");
+ p0(" /ysize exch def\n");
+ p0(" /xsize exch def\n} def\n\n");
+
+ p0("/LoutGr2 { gsave translate LoutGraphic gsave } def\n\n");
+
+ /* print definition used by Lout output to recode fonts */
+ /* adapted from PostScript Language Reference Manual (2nd Ed), p. 275 */
+ /* usage: /<fullname> <encodingvector> /<originalname> LoutRecode - */
+
+ p0("/LoutFont\n");
+ p0("{ findfont exch scalefont setfont\n");
+ p0("} bind def\n\n");
+
+ p0("/LoutRecode {\n");
+ p0(" { findfont dup length dict begin\n");
+ p0(" {1 index /FID ne {def} {pop pop} ifelse} forall\n");
+ p0(" /Encoding exch def\n");
+ p0(" currentdict end definefont pop\n");
+ p0(" }\n");
+ p0(" stopped pop\n");
+ p0("} bind def\n\n");
+
+ /* print definitions used by Lout output when including EPSF files */
+ /* copied from PostScript Language Reference Manual (2nd Ed.), p. 726 */
+
+ p0("/BeginEPSF {\n");
+ p0(" /LoutEPSFState save def\n");
+ p0(" /dict_count countdictstack def\n");
+ p0(" /op_count count 1 sub def\n");
+ p0(" userdict begin\n");
+ p0(" /showpage { } def\n");
+ p0(" 0 setgray 0 setlinecap\n");
+ p0(" 1 setlinewidth 0 setlinejoin\n");
+ p0(" 10 setmiterlimit [] 0 setdash newpath\n");
+ p0(" /languagelevel where\n");
+ p0(" { pop languagelevel\n");
+ p0(" 1 ne\n");
+ p0(" { false setstrokeadjust false setoverprint\n");
+ p0(" } if\n");
+ p0(" } if\n");
+ p0("} bind def\n\n");
+
+ p0("/EndEPSF {\n");
+ p0(" count op_count sub { pop } repeat\n");
+ p0(" countdictstack dict_count sub { end } repeat\n");
+ p0(" LoutEPSFState restore\n");
+ p0("} bind def\n");
+
+ p0("%%EndResource\n\n");
+
+ /* print prepend files (assumed to be organized as DSC 3.0 Resources) */
+ for( fnum = FirstFile(PREPEND_FILE); fnum != NO_FILE; fnum=NextFile(fnum) )
+ { FULL_CHAR buff[MAX_BUFF]; FILE *fp;
+ if( (fp = OpenFile(fnum, FALSE, FALSE)) == null )
+ Error(49, 3, "cannot open %s file %s", WARN, PosOfFile(fnum),
+ KW_PREPEND, FileName(fnum));
+ else if( StringFGets(buff, MAX_BUFF, fp) == NULL )
+ Error(49, 4, "%s file %s is empty", WARN, PosOfFile(fnum),
+ KW_PREPEND, FileName(fnum));
+ else
+ {
+ if( StringBeginsWith(buff, AsciiToFull("%%BeginResource:")) )
+ { OBJECT tmp;
+ tmp = MakeWord(WORD, &buff[strlen("%%BeginResource:")], no_fpos);
+ Link(supplied, tmp);
+ }
+ else
+ Error(49, 5, "%s file %s lacks PostScript BeginResource comment",
+ WARN, PosOfFile(fnum), KW_PREPEND, FileName(fnum));
+ StringFPuts(buff, out_fp);
+ p2("%% %s file %s\n", KW_PREPEND, FileName(fnum));
+ while( StringFGets(buff, MAX_BUFF, fp) != NULL )
+ StringFPuts(buff, out_fp);
+ p0("\n");
+ fclose(fp);
+ }
+ }
+
+ fputs("%%EndProlog\n\n", out_fp);
+ fputs("%%BeginSetup\n", out_fp);
+ MapPrintEncodings();
+
+ /* pdfmark compatibility code, as in the pdfmark Reference Manual p10 */
+ p0("/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse\n");
+
+ /* FontPrintPageSetup(out_fp); */
+ fputs("%%EndSetup\n\n", out_fp);
+ fprintf(out_fp, "%%%%Page: ");
+ for( p = label; *p != '\0'; p++ )
+ fputs(EightBitToPrintForm[*p], out_fp);
+ fprintf(out_fp, " %d\n", ++pagecount);
+ fprintf(out_fp, "%%%%BeginPageSetup\n");
+ FontPrintPageResources(out_fp);
+ fprintf(out_fp, "/pgsave save def\n");
+ FontPrintPageSetup(out_fp);
+ FontAdvanceCurrentPage();
+ fprintf(out_fp, "%.4f dup scale %d setlinewidth\n", 1.0 / PT, PT/2);
+ fprintf(out_fp, "%%%%EndPageSetup\n\n");
+ prologue_done = TRUE;
+ } /* end PS_PrintBeforeFirstPage */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_PrintAfterLastPage() */
+ /* */
+ /* Clean up this module and close output stream. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintAfterLastPage(void)
+ { OBJECT x, link; BOOLEAN first_need;
+ if( prologue_done )
+ {
+ fprintf(out_fp, "\npgsave restore\nshowpage\n");
+ fprintf(out_fp, "\n%%%%Trailer\n");
+
+ /* print resource requirements (DSC 3.0 version) - fonts */
+ first_need = FontNeeded(out_fp);
+
+ /* print resource requirements (DSC 3.0 version) - included EPSFs */
+ for( link = Down(needs); link != needs; link = NextDown(link) )
+ { Child(x, link);
+ assert(is_word(type(x)), "PrintAfterLast: needs!" );
+ fprintf(out_fp, "%s %s",
+ first_need ? "%%DocumentNeededResources:" : "%%+", string(x));
+ first_need = FALSE;
+ }
+
+ /* print resources supplied */
+ fprintf(out_fp, "%%%%DocumentSuppliedResources: procset %s\n",
+ StartUpResource);
+ for( link = Down(supplied); link != supplied; link = NextDown(link) )
+ { Child(x, link);
+ fprintf(out_fp, "%%%%+ %s", string(x));
+ }
+ MapPrintPSResources(out_fp);
+
+ fprintf(out_fp, "%%%%Pages: %d\n", pagecount);
+ fprintf(out_fp, "%%%%EOF\n");
+ }
+ } /* end PS_PrintAfterLastPage */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_PrintBetweenPages(h, v, label) */
+ /* */
+ /* Start a new output component, of size h by v; label is the page label */
+ /* to attach to the %%Page comment. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintBetweenPages(FULL_LENGTH h, FULL_LENGTH v, FULL_CHAR *label)
+ { FULL_CHAR *p;
+ debug2(DPO, DD, "PrintBetweenPages(%d, %d)", h, v);
+
+ fprintf(out_fp, "\npgsave restore\nshowpage\n");
+ gs_stack_top = 0;
+ cpexists = FALSE;
+ currentfont = NO_FONT;
+ currentcolour = NO_COLOUR;
+ if( Encapsulated )
+ { PS_PrintAfterLastPage();
+ Error(49, 6, "truncating -EPS document at end of first page",
+ FATAL, no_fpos);
+ }
+ fprintf(out_fp, "\n%%%%Page: ");
+ for( p = label; *p != '\0'; p++ )
+ fputs(EightBitToPrintForm[*p], out_fp);
+ fprintf(out_fp, " %d\n", ++pagecount);
+ fprintf(out_fp, "%%%%BeginPageSetup\n");
+ FontPrintPageResources(out_fp);
+ fprintf(out_fp, "/pgsave save def\n");
+ FontPrintPageSetup(out_fp);
+ FontAdvanceCurrentPage();
+ fprintf(out_fp, "%.4f dup scale %d setlinewidth\n", 1.0 / PT, PT/2);
+ fprintf(out_fp, "%%%%EndPageSetup\n");
+ wordcount = 0;
+ } /* end PS_PrintBetweenPages */
+
+
+ /*****************************************************************************/
+ /* */
+ /* KernLength(fnum, ch1, ch2, res) */
+ /* */
+ /* Set res to the kern length between ch1 and ch2 in font fnum, or 0 if */
+ /* none. */
+ /* */
+ /*****************************************************************************/
+
+ #define KernLength(fnum, mp, ch1, ch2, res) \
+ { int ua_ch1 = mp[ch1]; \
+ int ua_ch2 = mp[ch2]; \
+ int i, j; \
+ i = finfo[fnum].kern_table[ua_ch1], j; \
+ if( i == 0 ) res = 0; \
+ else \
+ { FULL_CHAR *kc = finfo[fnum].kern_chars; \
+ for( j = i; kc[j] > ua_ch2; j++ ); \
+ res = (kc[j] == ua_ch2) ? \
+ finfo[fnum].kern_sizes[finfo[fnum].kern_value[j]] : 0; \
+ } \
+ } /* end KernLength */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static void PrintComposite(COMPOSITE *cp, BOOLEAN outline, FILE *fp) */
+ /* */
+ /* Print composite character cp, assuming that the current point is */
+ /* set to the correct origin. If outline is true, we want to print the */
+ /* composite character in outline. */
+ /* */
+ /*****************************************************************************/
+
+ static void PrintComposite(COMPOSITE *cp, BOOLEAN outline, FILE *fp)
+ { debug1(DPO, D, "PrintComposite(cp, %s, fp)", bool(outline));
+ while( cp->char_code != '\0' )
+ {
+ debug4(DPO, D, " cp = %d printing code %d (%d, %d)", (int) cp,
+ cp->char_code, cp->x_offset, cp->y_offset);
+ fprintf(fp, "%d %d (%c)%s ", cp->x_offset, cp->y_offset,
+ cp->char_code, outline ? "co" : "c");
+ cp++;
+ }
+ } /* end PrintComposite */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_PrintWord(x, hpos, vpos) */
+ /* */
+ /* Print non-empty word x; its marks cross at the point (hpos, vpos). */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintWord(OBJECT x, int hpos, int vpos)
+ { FULL_CHAR *p, *q, *a, *b, *lig, *unacc;
+ int ksize; char *command; MAPPING m;
+ unsigned short *composite; COMPOSITE *cmp;
+
+ debug6(DPO, DD, "PrintWord( %s, %d, %d ) font %d colour %d%s", string(x),
+ hpos, vpos, word_font(x), word_colour(x), word_outline(x) ? " outline":"");
+ TotalWordCount++;
+
+ /* if font is different to previous word then print change */
+ if( word_font(x) != currentfont )
+ { currentfont = word_font(x);
+ currentxheight2 = FontHalfXHeight(currentfont);
+ fprintf(out_fp, "%hd %s", FontSize(currentfont, x), FontName(currentfont));
+ if( ++wordcount >= 5 )
+ { putc('\n', out_fp);
+ wordcount = 0;
+ }
+ else putc(' ', out_fp);
+ }
+
+ /* if colour is different to previous word then print change */
+ if( word_colour(x) != currentcolour )
+ { currentcolour = word_colour(x);
+ if( currentcolour > 0 )
+ { fprintf(out_fp, "%s", ColourCommand(currentcolour));
+ if( ++wordcount >= 5 )
+ { putc('\n', out_fp);
+ wordcount = 0;
+ }
+ else putc(' ', out_fp);
+ }
+ }
+
+ /* convert ligature sequences into ligature characters */
+ lig = finfo[word_font(x)].lig_table;
+ p = q = string(x);
+ do
+ {
+ /* check for missing glyph (lig[] == 1) or ligatures (lig[] > 1) */
+ if( lig[*q++ = *p++] )
+ {
+ if( lig[*(q-1)] == 1 ) continue;
+ else
+ { a = &lig[ lig[*(p-1)] + MAX_CHARS ];
+ while( *a++ == *(p-1) )
+ { b = p;
+ while( *a == *b && *(a+1) != '\0' && *b != '\0' ) a++, b++;
+ if( *(a+1) == '\0' )
+ { *(q-1) = *a;
+ p = b;
+ break;
+ }
+ else
+ { while( *++a );
+ a++;
+ }
+ }
+ }
+ }
+ } while( *p );
+ *q = '\0';
+
+ /* move to coordinate of x */
+ cmp = finfo[word_font(x)].cmp_table;
+ composite = finfo[word_font(x)].composite;
+ debug1(DPO, DDD, " currentxheight2 = %d", currentxheight2);
+ vpos = vpos - currentxheight2;
+ if( cpexists && currenty == vpos )
+ { printnum(hpos, out_fp);
+ command = word_outline(x) ? "so" : "s";
+ }
+ else
+ { currenty = vpos;
+ printnum(hpos, out_fp);
+ putc(' ', out_fp);
+ printnum(currenty, out_fp);
+ command = word_outline(x) ? "mo" : "m";
+ cpexists = TRUE;
+ }
+
+ /* show string(x) */
+ putc('(', out_fp);
+ p = string(x);
+ if( composite[*p] )
+ {
+ fprintf(out_fp, ")%s ", command);
+ debug3(DPO, D,
+ " calling PrintComposite(&cmp[composite[%d] = %d]); cmp_top = %d",
+ (int) *p, composite[*p], finfo[word_font(x)].cmp_top);
+ PrintComposite(&cmp[composite[*p]], word_outline(x), out_fp);
+ printnum(finfo[word_font(x)].size_table[*p].right, out_fp);
+ putc('(', out_fp);
+ command = word_outline(x) ? "ro" : "r";
+ }
+ else fputs(EightBitToPrintForm[*p], out_fp);
+ m = font_mapping(finfo[word_font(x)].font_table);
+ unacc = MapTable[m]->map[MAP_UNACCENTED];
+ /* acc = MapTable[m]->map[MAP_ACCENT]; */
+ for( p++; *p; p++ )
+ { KernLength(word_font(x), unacc, *(p-1), *p, ksize);
+ if( ksize != 0 )
+ { fprintf(out_fp, ")%s %d(", command, -ksize);
+ ++wordcount;
+ command = word_outline(x) ? "ko" : "k";
+ }
+ if( composite[*p] )
+ { fprintf(out_fp, ")%s ", command);
+ debug3(DPO, D,
+ " calling PrintComposite(&cmp[composite[%d] = %d]); cmp_top = %d",
+ (int) *p, composite[*p], finfo[word_font(x)].cmp_top);
+ PrintComposite(&cmp[composite[*p]], word_outline(x), out_fp);
+ printnum(finfo[word_font(x)].size_table[*p].right, out_fp);
+ putc('(', out_fp);
+ command = word_outline(x) ? "ro" : "r";
+ }
+ else fputs(EightBitToPrintForm[*p], out_fp);
+ }
+ if( ++wordcount >= 5 )
+ { fprintf(out_fp, ")%s\n", command);
+ wordcount = 0;
+ }
+ else fprintf(out_fp, ")%s ", command);
+ debug0(DPO, DDD, "PrintWord returning");
+ } /* end PS_PrintWord */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_PrintPlainGraphic(OBJECT x, FULL_LENGTH xmk, ymk, OBJECT z) */
+ /* */
+ /* Print a plain graphic object */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintPlainGraphic(OBJECT x, FULL_LENGTH xmk,
+ FULL_LENGTH ymk, OBJECT z)
+ {
+ assert(FALSE, "PS_PrintPlainGraphic: this routine should never be called!");
+ } /* end PS_PrintPlainGraphic */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_PrintUnderline(fnum, col, xstart, xstop, ymk) */
+ /* */
+ /* Draw an underline suitable for font fnum, in colour col, from xstart to */
+ /* xstop at the appropriate distance below mark ymk. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_PrintUnderline(FONT_NUM fnum, COLOUR_NUM col,
+ FULL_LENGTH xstart, FULL_LENGTH xstop, FULL_LENGTH ymk)
+ {
+ debug5(DPO, DD, "PrintUnderline(fnt %d, col %d, xstart %s, xstop %s, ymk %s)",
+ fnum, col, EchoLength(xstart), EchoLength(xstop), EchoLength(ymk));
+
+ /* if colour is different to previously then print change */
+ if( col != currentcolour )
+ { currentcolour = col;
+ if( currentcolour > 0 )
+ { fprintf(out_fp, "%s", ColourCommand(currentcolour));
+ if( ++wordcount >= 5 )
+ { putc('\n', out_fp);
+ wordcount = 0;
+ }
+ else putc(' ', out_fp);
+ }
+ }
+
+ /* now print the underline command */
+ fprintf(out_fp, "%d %d %d %d ul\n", xstart, xstop,
+ ymk - finfo[fnum].underline_pos, finfo[fnum].underline_thick);
+ debug0(DPO, DD, "PrintUnderline returning.");
+ } /* end PS_PrintUnderline */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_CoordTranslate(xdist, ydist) */
+ /* */
+ /* Translate coordinate system by the given x and y distances. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_CoordTranslate(FULL_LENGTH xdist, FULL_LENGTH ydist)
+ { debug2(DPO, D, "PS_CoordTranslate(%s, %s)",
+ EchoLength(xdist), EchoLength(ydist));
+ fprintf(out_fp, "%d %d translate\n", xdist, ydist);
+ cpexists = FALSE;
+ debug0(DPO, D, "PS_CoordTranslate returning.");
+ } /* end PS_CoordTranslate */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_CoordRotate(amount) */
+ /* */
+ /* Rotate coordinate system by given amount (in internal DG units) */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_CoordRotate(FULL_LENGTH amount)
+ { debug1(DPO, D, "PS_CoordRotate(%.1f degrees)", (float) amount / DG);
+ fprintf(out_fp, "%.4f rotate\n", (float) amount / DG);
+ cpexists = FALSE;
+ debug0(DPO, D, "CoordRotate returning.");
+ } /* end PS_CoordRotate */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_CoordScale(ratio, dim) */
+ /* */
+ /* Scale coordinate system by ratio in the given dimension. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_CoordScale(float hfactor, float vfactor)
+ {
+ #if DEBUG_ON
+ char buff[20];
+ #endif
+ ifdebug(DPO, D, sprintf(buff, "%.3f, %.3f", hfactor, vfactor));
+ debug1(DPO, D, "CoordScale(%s)", buff);
+ fprintf(out_fp, "%.4f %.4f scale\n", hfactor, vfactor);
+ cpexists = FALSE;
+ debug0(DPO, D, "CoordScale returning.");
+ } /* end PS_CoordScale */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_SaveGraphicState(x) */
+ /* */
+ /* Save current coord system on stack for later restoration. */
+ /* Object x is just for error reporting, not really used at all. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_SaveGraphicState(OBJECT x)
+ { debug0(DPO, D, "SaveGraphicState()");
+ fprintf(out_fp, "gsave\n");
+ gs_stack_top++;
+ if( gs_stack_top >= MAX_GS )
+ Error(49, 7, "rotations, graphics etc. too deeply nested (max is %d)",
+ FATAL, &fpos(x), MAX_GS);
+ gs_stack[gs_stack_top].gs_font = currentfont;
+ gs_stack[gs_stack_top].gs_colour = currentcolour;
+ gs_stack[gs_stack_top].gs_cpexists = cpexists;
+ gs_stack[gs_stack_top].gs_currenty = currenty;
+ gs_stack[gs_stack_top].gs_xheight2 = currentxheight2;
+ debug0(DPO, D, "PS_SaveGraphicState returning.");
+ } /* end PS_SaveGraphicState */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_RestoreGraphicState() */
+ /* */
+ /* Restore previously saved coordinate system. NB we normally assume that */
+ /* no white space is needed before any item of output, but since this */
+ /* procedure is sometimes called immediately after PrintGraphicObject(), */
+ /* which does not append a concluding space, we prepend one here. */
+ /* */
+ /*****************************************************************************/
+
+ void PS_RestoreGraphicState(void)
+ { debug0(DPO, D, "PS_RestoreGraphicState()");
+ fprintf(out_fp, "\ngrestore\n");
+ currentfont = gs_stack[gs_stack_top].gs_font;
+ currentcolour = gs_stack[gs_stack_top].gs_colour;
+ cpexists = gs_stack[gs_stack_top].gs_cpexists;
+ currenty = gs_stack[gs_stack_top].gs_currenty;
+ currentxheight2 = gs_stack[gs_stack_top].gs_xheight2;
+ gs_stack_top--;
+ debug0(DPO, D, "PS_RestoreGraphicState returning.");
+ } /* end PS_RestoreGraphicState */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_PrintGraphicObject(x) */
+ /* */
+ /* Print object x on out_fp */
+ /* */
+ /*****************************************************************************/
+
+ void PS_PrintGraphicObject(OBJECT x)
+ { OBJECT y, link;
+ debug3(DPO, D, "PS_PrintGraphicObject(%s %s %s)",
+ EchoFilePos(&fpos(x)), Image(type(x)), EchoObject(x));
+ switch( type(x) )
+ {
+ case WORD:
+ case QWORD:
+
+ StringFPuts(string(x), out_fp);
+ break;
+
+
+ case ACAT:
+
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ )
+ {
+ if( vspace(y) > 0 ) fputs("\n", out_fp);
+ else if( hspace(y) > 0 ) fputs(" ", out_fp);
+ }
+ else if( is_word(type(y)) || type(y) == ACAT )
+ PS_PrintGraphicObject(y);
+ else if( type(y) == WIDE || is_index(type(y)) )
+ {
+ /* ignore: @Wide, indexes are sometimes inserted by Manifest */
+ }
+ else
+ { Error(49, 8, "error in left parameter of %s",
+ WARN, &fpos(x), KW_GRAPHIC);
+ debug1(DPO, D, " type(y) = %s, y =", Image(type(y)));
+ ifdebug(DPO, D, DebugObject(y));
+ }
+ }
+ break;
+
+
+ default:
+
+ Error(49, 9, "error in left parameter of %s", WARN, &fpos(x), KW_GRAPHIC);
+ debug1(DPO, D, " type(x) = %s, x =", Image(type(x)));
+ ifdebug(DPO, D, DebugObject(x));
+ break;
+
+ }
+ debug0(DPO, D, "PS_PrintGraphicObject returning");
+ } /* end PS_PrintGraphicObject */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_DefineGraphicNames(x) */
+ /* */
+ /* Generate PostScript for xsize, ysize etc. names of graphic object. */
+ /* */
+ /*****************************************************************************/
+
+ void PS_DefineGraphicNames(OBJECT x)
+ { assert( type(x) == GRAPHIC, "PrintGraphic: type(x) != GRAPHIC!" );
+ debug1(DPO, D, "DefineGraphicNames( %s )", EchoObject(x));
+ debug1(DPO, DD, " style = %s", EchoStyle(&save_style(x)));
+
+ /* if font is different to previous word then print change */
+ if( font(save_style(x)) != currentfont )
+ { currentfont = font(save_style(x));
+ if( currentfont > 0 )
+ { currentxheight2 = FontHalfXHeight(currentfont);
+ fprintf(out_fp, "%hd %s ", FontSize(currentfont, x),
+ FontName(currentfont));
+ }
+ }
+
+ /* if colour is different to previous word then print change */
+ if( colour(save_style(x)) != currentcolour )
+ { currentcolour = colour(save_style(x));
+ if( currentcolour > 0 )
+ fprintf(out_fp, "%s ", ColourCommand(currentcolour));
+ }
+
+ /* now print the actual command that defines the names */
+ fprintf(out_fp, "%d %d %d %d %d %d %d LoutGraphic\n",
+ size(x, COLM), size(x, ROWM), back(x, COLM), fwd(x, ROWM),
+ currentfont <= 0 ? 12*PT : FontSize(currentfont, x),
+ width(line_gap(save_style(x))), width(space_gap(save_style(x))));
+ debug0(DPO, D, "PS_DefineGraphicNames returning.");
+ } /* end PS_DefineGraphicNames */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_SaveTranslateDefineSave(x, xdist, ydist) */
+ /* */
+ /* Equivalent to the sequence of calls */
+ /* */
+ /* SaveGraphicState(x) */
+ /* CoordTranslate(xdist, ydist) */
+ /* DefineGraphicNames(x) */
+ /* SaveGraphicState(x) */
+ /* */
+ /* but generates less PostScript. */
+ /* */
+ /*****************************************************************************/
+
+ void PS_SaveTranslateDefineSave(OBJECT x, FULL_LENGTH xdist, FULL_LENGTH ydist)
+ {
+ if( gs_stack_top >= MAX_GS - 1 || font(save_style(x)) != currentfont ||
+ colour(save_style(x))!=currentcolour )
+ {
+ /* do it bit by bit, will be rare anyway */
+ PS_SaveGraphicState(x);
+ PS_CoordTranslate(xdist, ydist);
+ PS_DefineGraphicNames(x);
+ PS_SaveGraphicState(x);
+ }
+ else
+ {
+ /* no font or colour changes, no stack overflow, so can optimize */
+
+ /* from Save */
+ gs_stack_top++;
+ gs_stack[gs_stack_top].gs_font = currentfont;
+ gs_stack[gs_stack_top].gs_colour = currentcolour;
+ gs_stack[gs_stack_top].gs_cpexists = cpexists;
+ gs_stack[gs_stack_top].gs_currenty = currenty;
+ gs_stack[gs_stack_top].gs_xheight2 = currentxheight2;
+
+ /* from CoordTranslate */
+ cpexists = FALSE;
+
+ /* from Save */
+ gs_stack_top++;
+ gs_stack[gs_stack_top].gs_font = currentfont;
+ gs_stack[gs_stack_top].gs_colour = currentcolour;
+ gs_stack[gs_stack_top].gs_cpexists = cpexists;
+ gs_stack[gs_stack_top].gs_currenty = currenty;
+ gs_stack[gs_stack_top].gs_xheight2 = currentxheight2;
+
+ /* accumulated output from all four calls, repackaged */
+ fprintf(out_fp, "%d %d %d %d %d %d %d %d %d LoutGr2\n",
+ size(x, COLM), size(x, ROWM), back(x, COLM), fwd(x, ROWM),
+ currentfont <= 0 ? 12*PT : FontSize(currentfont, x),
+ width(line_gap(save_style(x))), width(space_gap(save_style(x))),
+ xdist, ydist);
+
+ }
+ } /* end PS_SaveTranslateDefineSave */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_PrintGraphicInclude(x, colmark, rowmark) */
+ /* */
+ /* Print graphic include file, with appropriate surrounds. This code */
+ /* closely follows the PostScript Language Reference Manual, 2n ed., */
+ /* pages 733-5, except we do not clip the included EPSF. */
+ /* */
+ /* Note to porters: Version 3.0 of the EPSF standard is not compatible */
+ /* with previous versions. Thus, this output may crash your system. */
+ /* If you can find out which comment line(s) are causing the trouble, */
+ /* you can add to procedure strip_out to strip them out during the */
+ /* file inclusion step. e.g. on my system %%EOF causes problems, so I */
+ /* strip it out. */
+ /* */
+ /* May 1994: I've just discovered that %%Trailer causes problems for */
+ /* the mpage Unix utility, so now I'm stripping it out as well. */
+ /* */
+ /*****************************************************************************/
+ #define SKIPPING 0
+ #define READING_DNR 1
+ #define FINISHED 2
+
+ static BOOLEAN strip_out(FULL_CHAR *buff)
+ { if( StringBeginsWith(buff, AsciiToFull("%%EOF")) ) return TRUE;
+ if( StringBeginsWith(buff, AsciiToFull("%%Trailer")) ) return TRUE;
+ return FALSE;
+ } /* end strip_out */
+
+ void PS_PrintGraphicInclude(OBJECT x, FULL_LENGTH colmark, FULL_LENGTH rowmark)
+ { OBJECT y, full_name; FULL_CHAR buff[MAX_BUFF];
+ FILE *fp; int state; BOOLEAN compressed;
+ debug0(DPO, D, "PS_PrintGraphicInclude(x)");
+
+ assert(type(x)==INCGRAPHIC || type(x)==SINCGRAPHIC, "PrintGraphicInclude!");
+ assert(incgraphic_ok(x), "PrintGraphicInclude: !incgraphic_ok(x)!");
+
+ /* open the include file and get its full path name */
+ Child(y, Down(x));
+ fp = OpenIncGraphicFile(string(y), type(x), &full_name,&fpos(y),&compressed);
+ assert( fp != NULL, "PrintGraphicInclude: fp!" );
+
+ /* if font is different to previous word then print change */
+ if( font(save_style(x)) != currentfont )
+ { currentfont = font(save_style(x));
+ currentxheight2 = FontHalfXHeight(currentfont);
+ fprintf(out_fp, "%hd %s\n", FontSize(currentfont,x), FontName(currentfont));
+ }
+
+ /* if colour is different to previous word then print change */
+ if( colour(save_style(x)) != currentcolour )
+ { currentcolour = colour(save_style(x));
+ if( currentcolour > 0 )
+ {
+ fprintf(out_fp, "%s\n", ColourCommand(currentcolour));
+ }
+ }
+
+ /* generate appropriate header code */
+ fprintf(out_fp, "BeginEPSF\n");
+ PS_CoordTranslate(colmark - back(x, COLM), rowmark - fwd(x, ROWM));
+ PS_CoordScale( (float) PT, (float) PT );
+ PS_CoordTranslate(-back(y, COLM), -back(y, ROWM));
+ fprintf(out_fp, "%%%%BeginDocument: %s\n", string(full_name));
+
+ /* copy through the include file, except divert resources lines to needs */
+ /* and strip out some comment lines that cause problems */
+ state = (StringFGets(buff, MAX_BUFF, fp) == NULL) ? FINISHED : SKIPPING;
+ while( state != FINISHED ) switch(state)
+ {
+ case SKIPPING:
+
+ if( StringBeginsWith(buff, AsciiToFull("%%DocumentNeededResources:")) &&
+ !StringContains(buff, AsciiToFull("(atend)")) )
+ { y = MakeWord(WORD, &buff[StringLength("%%DocumentNeededResources:")],
+ no_fpos);
+ Link(needs, y);
+ state = (StringFGets(buff,MAX_BUFF,fp)==NULL) ? FINISHED : READING_DNR;
+ }
+ else
+ { if( StringBeginsWith(buff, AsciiToFull("%%LanguageLevel:")) )
+ Error(49, 10, "ignoring LanguageLevel comment in %s file %s",
+ WARN, &fpos(x), KW_INCGRAPHIC, string(full_name));
+ if( StringBeginsWith(buff, AsciiToFull("%%Extensions:")) )
+ Error(49, 11, "ignoring Extensions comment in %s file %s",
+ WARN, &fpos(x), KW_INCGRAPHIC, string(full_name));
+ if( !strip_out(buff) ) StringFPuts(buff, out_fp);
+ state = (StringFGets(buff, MAX_BUFF, fp) == NULL) ? FINISHED : SKIPPING;
+ }
+ break;
+
+ case READING_DNR:
+
+ if( StringBeginsWith(buff, AsciiToFull("%%+")) )
+ { x = MakeWord(WORD, &buff[StringLength(AsciiToFull("%%+"))], no_fpos);
+ Link(needs, x);
+ state = (StringFGets(buff,MAX_BUFF,fp)==NULL) ? FINISHED : READING_DNR;
+ }
+ else
+ { if( !strip_out(buff) ) StringFPuts(buff, out_fp);
+ state = (StringFGets(buff, MAX_BUFF, fp) == NULL) ? FINISHED : SKIPPING;
+ }
+ break;
+ }
+
+ /* wrapup */
+ DisposeObject(full_name);
+ fclose(fp);
+ if( compressed ) StringRemove(AsciiToFull(LOUT_EPS));
+ fprintf(out_fp, "\n%%%%EndDocument\nEndEPSF\n");
+ wordcount = 0;
+ debug0(DPO, D, "PS_PrintGraphicInclude returning.");
+ } /* end PS_PrintGraphicInclude */
+ /*****************************************************************************/
+ /* */
+ /* char *ConvertToPDFName(name) */
+ /* */
+ /* Convert string(name) to a suitable PDF label. The result is in static */
+ /* memory and must be copied before the next call to ConvertToPDFName. */
+ /* */
+ /* At present our algorithm is to prefix the label with "LOUT" and to */
+ /* replace all non-alphanumerics by one underscore. */
+ /* */
+ /*****************************************************************************/
+ #define in_range(ch, a, b) ( (ch) >= (a) && (ch) <= (b) )
+ #define is_lower(ch) in_range(ch, 'a', 'z')
+ #define is_upper(ch) in_range(ch, 'A', 'Z')
+ #define is_digit(ch) in_range(ch, '0', '9')
+ #define is_alphanum(ch) (is_lower(ch) || is_upper(ch) || is_digit(ch))
+
+ char *ConvertToPDFName(OBJECT name)
+ { static char buff[200];
+ char *q;
+ FULL_CHAR *p;
+ strcpy(buff, "LOUT");
+ q = &buff[strlen(buff)];
+ for( p = string(name); *p != '\0'; p++ )
+ {
+ if( q >= &buff[199] )
+ Error(49, 12, "tag %s is too long", FATAL, &fpos(name), string(name));
+ if( is_alphanum(*p) )
+ *q++ = (char) *p;
+ else
+ *q++ = '_';
+ }
+ *q++ = '\0';
+ return buff;
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_LinkSource(name, llx, lly, urx, ury) */
+ /* */
+ /* Print a link source point. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_LinkSource(OBJECT name, FULL_LENGTH llx, FULL_LENGTH lly,
+ FULL_LENGTH urx, FULL_LENGTH ury)
+ { debug5(DPO, D, "PS_LinkSource(%s, %d, %d, %d, %d)", EchoObject(name),
+ llx, lly, urx, ury);
+
+ /* print the link source point */
+ fprintf(out_fp,
+ "\n[ /Rect [%d %d %d %d] /Subtype /Link /Dest /%s /ANN pdfmark\n",
+ llx, lly, urx, ury, ConvertToPDFName(name));
+
+ /* remember it so that at end of run can check if it has an dest point */
+ Link(link_source_list, name);
+ debug0(DPO, D, "PS_LinkSource returning.");
+ } /* end PS_LinkSource */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_LinkDest(name, llx, lly, urx, ury) */
+ /* */
+ /* Print a link dest point (note llx etc are not used), after making sure */
+ /* that no previously printed dest point has the same name. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_LinkDest(OBJECT name, FULL_LENGTH llx, FULL_LENGTH lly,
+ FULL_LENGTH urx, FULL_LENGTH ury)
+ { OBJECT prev;
+ debug5(DPO, D, "PS_LinkDest(%s, %d, %d, %d, %d)", EchoObject(name),
+ llx, lly, urx, ury);
+
+ prev = ltab_retrieve(string(name), link_dest_tab);
+ if( prev == nilobj )
+ {
+ /* not used previously, so print it and remember it */
+ fprintf(out_fp, "\n[ /Dest /%s /DEST pdfmark\n", ConvertToPDFName(name));
+ ltab_insert(name, &link_dest_tab);
+ }
+ else
+ {
+ /* used previously, so don't print it, and warn the user */
+ Error(49, 13, "link destination %s ignored (there is already one at%s)",
+ WARN, &fpos(name), string(name), EchoFilePos(&fpos(prev)));
+ }
+ debug0(DPO, D, "PS_LinkDest returning.");
+ } /* end PS_LinkDest */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_LinkCheck() */
+ /* */
+ /* Called at end of run; will check that for every link source point there */
+ /* is a link dest point. */
+ /* */
+ /*****************************************************************************/
+
+ static void PS_LinkCheck()
+ { OBJECT y, link;
+ debug0(DPO, D, "PS_LinkCheck()");
+
+ for( link=Down(link_source_list); link!=link_source_list; link=NextDown(link) )
+ { Child(y, link);
+ assert( is_word(type(y)), " PS_LinkCheck: !is_word(type(y))!");
+ if( ltab_retrieve(string(y), link_dest_tab) == nilobj )
+ Error(49, 14, "link name %s has no destination point", WARN, &fpos(y),
+ string(y));
+ }
+
+ debug0(DPO, D, "PS_LinkCheck returning.");
+ } /* end PS_LinkCheck */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PS_BackEnd */
+ /* */
+ /* The record into which all of these functions are packaged. */
+ /* */
+ /*****************************************************************************/
+
+ static struct back_end_rec ps_back = {
+ POSTSCRIPT, /* the code number of the back end */
+ STR_POSTSCRIPT, /* string name of the back end */
+ TRUE, /* TRUE if @Scale is available */
+ TRUE, /* TRUE if @Rotate is available */
+ TRUE, /* TRUE if @Graphic is available */
+ TRUE, /* TRUE if @IncludeGraphic is avail. */
+ FALSE, /* TRUE if @PlainGraphic is avail. */
+ TRUE, /* TRUE if fractional spacing avail. */
+ TRUE, /* TRUE if actual font metrics used */
+ TRUE, /* TRUE if colour is available */
+ PS_PrintInitialize,
+ PS_PrintLength,
+ PS_PrintPageSetupForFont,
+ PS_PrintPageResourceForFont,
+ PS_PrintMapping,
+ PS_PrintBeforeFirstPage,
+ PS_PrintBetweenPages,
+ PS_PrintAfterLastPage,
+ PS_PrintWord,
+ PS_PrintPlainGraphic,
+ PS_PrintUnderline,
+ PS_CoordTranslate,
+ PS_CoordRotate,
+ PS_CoordScale,
+ PS_SaveGraphicState,
+ PS_RestoreGraphicState,
+ PS_PrintGraphicObject,
+ PS_DefineGraphicNames,
+ PS_SaveTranslateDefineSave,
+ PS_PrintGraphicInclude,
+ PS_LinkSource,
+ PS_LinkDest,
+ PS_LinkCheck,
+ };
+
+ BACK_END PS_BackEnd = &ps_back;
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z50.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z50.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z50.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,881 ----
+ /*@z50.c:PDF Back End:PDF_BackEnd@********************************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z49.c */
+ /* MODULE: PDF Back End */
+ /* EXTERNS: PDF_BackEnd */
+ /* */
+ /*****************************************************************************/
+ #include <math.h> /* for fabs() */
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* State variables for this module */
+ /* */
+ /*****************************************************************************/
+ #define NO_FONT 0 /* actually stolen from z37.c */
+ #define NO_COLOUR 0
+ #define MAX_GS 50 /* maximum depth of graphics states */
+
+ static FILE *out_fp; /* file to print PDF on */
+
+ typedef struct
+ {
+ FONT_NUM gs_font; /* font number of this state */
+ COLOUR_NUM gs_colour; /* colour number of this state */
+ BOOLEAN gs_cpexists; /* TRUE if a current point exists */
+ FULL_LENGTH gs_currenty; /* if cpexists, its y coordinate */
+ short gs_xheight2; /* of font exists, half xheight */
+ } GRAPHICS_STATE;
+
+ static GRAPHICS_STATE gs_stack[MAX_GS];/* graphics state stack */
+ static int gs_stack_top; /* top of graphics state stack */
+
+ static FONT_NUM currentfont; /* font of most recent atom */
+ static COLOUR_NUM currentcolour; /* colour of most recent atom */
+ static short currentxheight2;/* half xheight in current font */
+ static BOOLEAN cpexists; /* true if a current point exists */
+ static FULL_LENGTH currenty; /* if cpexists, its y coordinate */
+
+ static int wordcount; /* atoms printed since last newline */
+ static int pagecount; /* total number of pages printed */
+ static BOOLEAN prologue_done; /* TRUE after prologue is printed */
+ static OBJECT needs; /* Resource needs of included EPSFs */
+ static OBJECT supplied; /* Resources supplied by this file */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Print a number x on file fp. */
+ /* */
+ /*****************************************************************************/
+
+ #define printnum(x, fp) \
+ { char buff[20]; register int i, y; \
+ if( x >= 0 ) y = x; \
+ else { y = -x; putc(CH_MINUS, fp); } \
+ i = 0; \
+ do { buff[i++] = numtodigitchar(y % 10); \
+ } while( (y = (y / 10)) > 0 ); \
+ do { --i; putc(buff[i], fp); \
+ } while( i ); \
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintInitialize(FILE *fp) */
+ /* */
+ /* Initialize this module; fp is the output file. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintInitialize(FILE *fp)
+ {
+ debug0(DPF, DD, "PDF_PrintInitialize(fp)");
+ out_fp = fp;
+ prologue_done = FALSE;
+ gs_stack_top = -1;
+ currentfont = NO_FONT;
+ currentcolour = NO_COLOUR;
+ cpexists = FALSE;
+ wordcount = pagecount = 0;
+ New(needs, ACAT);
+ New(supplied, ACAT);
+ debug0(DPF, DD, "PDF_PrintInitialize returning.");
+ } /* end PDF_PrintInitialize */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDF_PrintLength(FULL_CHAR *buff, int length, int length_dim) */
+ /* */
+ /* Print a length (debugging only) */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintLength(FULL_CHAR *buff, int length, int length_dim)
+ {
+ sprintf( (char *) buff, "%.3fc", (float) length/CM);
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void PDF_PrintPageSetupForFont(OBJECT face, int font_curr_page, */
+ /* FULL_CHAR *font_name, FULL_CHAR *first_size_str) */
+ /* */
+ /* Print the page setup commands required to use a font on some page: */
+ /* */
+ /* face The font face record, defining which font we need */
+ /* font_curr_page The current page number */
+ /* fp The file to print the command(s) on */
+ /* font_name The name of the font */
+ /* first_size_str No idea, have to check */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintPageSetupForFont(OBJECT face, int font_curr_page,
+ FULL_CHAR *font_name, FULL_CHAR *first_size_str)
+ {
+ FULL_CHAR *enc = NULL;
+ fprintf(out_fp, "%%%%IncludeResource: font %s\n", font_name);
+ /***
+ PDFFont_AddFont(out_fp, first_size_str, font_name,
+ MapEncodingName(font_mapping(face)));
+ ***/
+ if (font_recoded(face)) {
+ MAPPING m = font_mapping(face);
+ /* This is a NASTY hack. Need to rework the interface Since
+ PDF is random-access format - we don't care which page this
+ encoding is for and we need to only print it once -- Uwe */
+ MapEnsurePrinted(m, 1);
+ enc = MapEncodingName(m);
+ }
+ PDFFont_AddFont(out_fp, first_size_str, font_name, enc);
+ } /* end PDF_PrintPageSetupForFont */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintPageResourceForFont(FULL_CHAR *font_name, BOOLEAN first) */
+ /* */
+ /* Print page resource info on file fp for font font_name; first is true */
+ /* if this is the first resource on this page. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintPageResourceForFont(FULL_CHAR *font_name, BOOLEAN first)
+ {
+ /* JK: this was always commented out */
+ /* PDFWriteFontResource(out_fp, font_name); */
+ } /* end PDF_PrintPageResourceForFont */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static void PDF_PrintMapping(MAPPING m) */
+ /* */
+ /* Print mapping m. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintMapping(MAPPING m)
+ { MAP_VEC map = MapTable[m]; int i;
+ PDFFile_BeginFontEncoding(out_fp, (char*) string(map->name));
+ for( i = 0; i < MAX_CHARS; i++ )
+ fprintf(out_fp, "/%s%c", string(map->vector[i]), (i+1)%8 != 0 ? ' ' : '\n');
+ PDFFile_EndFontEncoding(out_fp);
+ } /* end PDF_PrintMapping */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintBeforeFirstPage(h, v, label) */
+ /* */
+ /* This procedure is called just before starting to print the first */
+ /* component of the output. Its size is h, v, and label is the page */
+ /* label to attach to the %%Page comment. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintBeforeFirstPage(FULL_LENGTH h, FULL_LENGTH v,
+ FULL_CHAR *label)
+ {
+ debug2(DPF, DD, "PrintBeforeFirst(%d, %d)", h, v);
+ PDFFile_Init(out_fp, h/PT, v/PT, IN, CM, PT, EM);
+ FontPrintPageSetup(out_fp);
+ PDFPage_Init(out_fp, 1.0 / PT, PT/2);
+ FontPrintPageResources(out_fp); /* write out font objects */
+ FontAdvanceCurrentPage();
+ prologue_done = TRUE;
+ } /* end PDF_PrintBeforeFirstPage */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintBetweenPages(h, v, label) */
+ /* */
+ /* Start a new output component, of size h by v; label is the page label */
+ /* to attach to the %%Page comment. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintBetweenPages(FULL_LENGTH h, FULL_LENGTH v,
+ FULL_CHAR *label)
+ {
+ debug2(DPF, DD, "PrintBetween(%d, %d)", h, v);
+
+ /* write out page objects */
+ PDFPage_Cleanup(out_fp);
+ PDFPage_Init(out_fp, 1.0 / PT, PT/2);
+
+ /* write out font objects */
+ FontPrintPageResources(out_fp);
+ FontPrintPageSetup(out_fp);
+ FontAdvanceCurrentPage();
+ } /* end PDF_PrintBetweenPages */
+
+
+ /*****************************************************************************/
+ /* */
+ /* KernLength(fnum, ch1, ch2, res) */
+ /* */
+ /* Set res to the kern length between ch1 and ch2 in font fnum, or 0 if */
+ /* none. */
+ /* */
+ /*****************************************************************************/
+
+ #define KernLength(fnum, mp, ch1, ch2, res) \
+ { int ua_ch1 = mp[ch1]; \
+ int ua_ch2 = mp[ch2]; \
+ int i, j; \
+ i = finfo[fnum].kern_table[ua_ch1], j; \
+ if( i == 0 ) res = 0; \
+ else \
+ { FULL_CHAR *kc = finfo[fnum].kern_chars; \
+ for( j = i; kc[j] > ua_ch2; j++ ); \
+ res = (kc[j] == ua_ch2) ? \
+ finfo[fnum].kern_sizes[finfo[fnum].kern_value[j]] : 0; \
+ } \
+ } /* end KernLength */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static void PrintComposite(COMPOSITE *cp, BOOLEAN outline, FILE *fp) */
+ /* */
+ /* This routine is unused in this module because it is the PostScript */
+ /* version and no PDF version has been written so far. JeffK 2/5/00. */
+ /* */
+ /* Print composite character cp, assuming that the current point is */
+ /* set to the correct origin. If outline is true, we want to print the */
+ /* composite character in outline. */
+ /* */
+ /*****************************************************************************/
+
+ static void PrintComposite(COMPOSITE *cp, BOOLEAN outline, FILE *fp)
+ { debug1(DPF, D, "PrintComposite(cp, %s, fp)", bool(outline));
+ while( cp->char_code != '\0' )
+ {
+ debug4(DPF, D, " cp = %d printing code %d (%d, %d)", (int) cp,
+ cp->char_code, cp->x_offset, cp->y_offset);
+ fprintf(fp, "%d %d (%c)%s ", cp->x_offset, cp->y_offset,
+ cp->char_code, outline ? "co" : "c");
+ cp++;
+ }
+ } /* end PrintComposite */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintWord(x, hpos, vpos) */
+ /* */
+ /* Print non-empty word x; its marks cross at the point (hpos, vpos). */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintWord(OBJECT x, int hpos, int vpos)
+ { FULL_CHAR *p, *q, *a, *b, *lig, *unacc;
+ int ksize; char *command; MAPPING m;
+ unsigned short *composite; COMPOSITE *cmp; /* currently unused - JeffK */
+ static int last_hpos; /* does not need to be initialised */
+ static int next_hpos = -1;
+ #if 0
+ struct metrics *fnt;
+ #endif
+
+ debug6(DPF, DD, "PrintWord( %s, %d, %d ) font %d colour %d%s", string(x),
+ hpos, vpos, word_font(x), word_colour(x),
+ word_outline(x) ? " outline" : "");
+ TotalWordCount++;
+
+ /* if font is different to previous word then print change */
+ if( word_font(x) != currentfont )
+ { currentfont = word_font(x);
+ currentxheight2 = FontHalfXHeight(currentfont);
+ PDFFont_Set(out_fp, FontSize(currentfont, x), FontName(currentfont));
+ }
+
+ /* if colour is different to previous word then print change */
+ if( word_colour(x) != currentcolour )
+ {
+ currentcolour = word_colour(x);
+ if( currentcolour > 0 )
+ { char str[256];
+ sprintf(str, "%s ", ColourCommand(currentcolour));
+ PDFPage_Write(out_fp, str);
+ }
+ }
+
+ /* move to coordinate of x */
+ debug1(DPF, DDD, " currentxheight2 = %d", currentxheight2);
+ vpos = vpos - currentxheight2;
+ if( cpexists && (currenty == vpos) && PDFHasValidTextMatrix() )
+ { /* printnum(hpos, out_fp); */
+ command = "s";
+
+ /* Note: I calculate the width of the space char here in case the
+ font has changed. This prevents subtle spacing errors. */
+ #if 0
+ fnt = finfo[currentfont].size_table;
+ if( (next_hpos + fnt[' '].right /* width of space char */ ) == hpos )
+ command = " ";
+ #endif
+ }
+ else
+ { currenty = vpos;
+ /* printnum(hpos, out_fp);
+ fputs(" ", out_fp);
+ printnum(currenty, out_fp); */
+ command = "m";
+ cpexists = TRUE;
+ }
+
+ /* convert ligature sequences into ligature characters */
+ lig = finfo[word_font(x)].lig_table;
+ p = q = string(x);
+ do
+ {
+ /* check for missing glyph (lig[] == 1) or ligatures (lig[] > 1) */
+ if( lig[*q++ = *p++] )
+ {
+ if( lig[*(q-1)] == 1 ) continue;
+ else
+ { a = &lig[ lig[*(p-1)] + MAX_CHARS ];
+ while( *a++ == *(p-1) )
+ { b = p;
+ while( *a == *b && *(a+1) != '\0' && *b != '\0' ) a++, b++;
+ if( *(a+1) == '\0' )
+ { *(q-1) = *a;
+ p = b;
+ break;
+ }
+ else
+ { while( *++a );
+ a++;
+ }
+ }
+ }
+ }
+ } while( *p );
+ *q = '\0';
+
+ switch (command[0])
+ {
+ case 'm':
+
+ PDFText_OpenXY(out_fp, hpos, vpos);
+ last_hpos = hpos;
+ next_hpos = hpos + fwd(x, COLM); /* fwd(x, COLM) = width of wd */
+ break;
+
+
+ case 's':
+ #if 0
+ PDFText_Open(out_fp);
+ PDFText_Kern(out_fp, hpos - next_hpos);
+ #else
+ PDFText_OpenX(out_fp, hpos - last_hpos);
+ #endif
+ last_hpos = hpos;
+ next_hpos = hpos + fwd(x, COLM); /* fwd(x, COLM) = width of wd */
+ break;
+ #if 0
+
+
+ case ' ':
+
+ PDFText_Open(out_fp);
+ #if 1
+ /* try kerning to get correct position */
+ PDFText_Kern(out_fp, fnt[' '].right);
+ #else
+ PDFPage_Write(out_fp, EightBitToPrintForm[' ']);
+ #endif
+ next_hpos += fwd(x, COLM) + fnt[' '].right; /* width of space ch */
+ break;
+ #endif
+
+ }
+
+ p = string(x);
+ PDFPage_Write(out_fp, EightBitToPrintForm[*p]);
+
+ m = font_mapping(finfo[word_font(x)].font_table);
+ unacc = MapTable[m]->map[MAP_UNACCENTED];
+ /* acc = MapTable[m]->map[MAP_ACCENT]; */
+ for( p++; *p; p++ )
+ {
+ /* *** this seems right but is actually wrong for PDF,
+ which according to Uwe uses original units for kerning
+ KernLength(word_font(x), unacc, *(p-1), *p, ksize);
+ *** */
+ KernLength(font_num(finfo[word_font(x)].original_face),
+ unacc, *(p-1), *p, ksize);
+ if ( ksize != 0 )
+ {
+ PDFText_Kern(out_fp, ksize);
+ }
+ PDFPage_Write(out_fp, EightBitToPrintForm[*p]);
+ }
+ PDFText_Close(out_fp);
+
+ debug0(DPF, DDD, "PDF_PrintWord returning");
+ } /* end PDF_PrintWord */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintPlainGraphic(OBJECT x, FULL_LENGTH xmk, ymk, OBJECT z) */
+ /* */
+ /* Print a plain graphic object */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintPlainGraphic(OBJECT x, FULL_LENGTH xmk,
+ FULL_LENGTH ymk, OBJECT z)
+ {
+ assert(FALSE, "PDF_PrintPlainGraphic: this routine should never be called!");
+ } /* end PDF_PrintPlainGraphic */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintUnderline(fnum, col, xstart, xstop, ymk) */
+ /* */
+ /* Draw an underline suitable for font fnum, in colour col from xstart to */
+ /* xstop at the appropriate distance below mark ymk. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_PrintUnderline(FONT_NUM fnum, COLOUR_NUM col,
+ FULL_LENGTH xstart, FULL_LENGTH xstop, FULL_LENGTH ymk)
+ {
+ debug5(DPF, DD, "PDF_PrintUnderline(ft %d, co %d, xstrt %s, xstp %s, ymk %s)",
+ fnum, col, EchoLength(xstart), EchoLength(xstop), EchoLength(ymk));
+ PDFPage_PrintUnderline(out_fp, xstart, xstop,
+ ymk - finfo[fnum].underline_pos, finfo[fnum].underline_thick);
+ debug0(DPF, DD, "PrintUnderline returning.");
+ } /* end PDF_PrintUnderline */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintAfterLastPage() */
+ /* */
+ /* Clean up this module and close output stream. */
+ /* */
+ /*****************************************************************************/
+
+ void PDF_PrintAfterLastPage(void)
+ {
+ if( prologue_done )
+ {
+ PDFPage_Cleanup(out_fp); /* write out page objects */
+ /* MapPrintResources(out_fp); not needed */
+ PDFFile_Cleanup(out_fp);
+ }
+ } /* end PDF_PrintAfterLastPage */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_CoordTranslate(xdist, ydist) */
+ /* */
+ /* Translate coordinate system by the given x and y distances. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_CoordTranslate(FULL_LENGTH xdist, FULL_LENGTH ydist)
+ { debug2(DPF, D, "CoordTranslate(%s, %s)",
+ EchoLength(xdist), EchoLength(ydist));
+ if ((xdist != 0) || (ydist != 0))
+ {
+ #if 1
+ PDFPage_Translate(out_fp, xdist, ydist);
+ #else
+ char temp_str[64];
+ sprintf(temp_str, "1 0 0 1 %d %d cm\n", xdist, ydist);
+ PDFPage_Write(out_fp, temp_str);
+ #endif
+ }
+ cpexists = FALSE;
+ debug0(DPF, D, "PDF_CoordTranslate returning.");
+ } /* end PDF_CoordTranslate */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_CoordRotate(amount) */
+ /* */
+ /* Rotate coordinate system by given amount (in internal DG units) */
+ /* */
+ /*****************************************************************************/
+ #define PI 3.1415926535897931160
+
+ static void PDF_CoordRotate(FULL_LENGTH amount)
+ { int theAmount;
+ debug1(DPF, D, "PDF_CoordRotate(%.1f degrees)", (float) amount / DG);
+ theAmount = ((amount / DG) % 360);
+ if( theAmount != 0 )
+ PDFPage_Rotate(out_fp, (double) theAmount * (double) PI / (double) 180.0);
+ cpexists = FALSE;
+ debug0(DPF, D, "CoordRotate returning.");
+ } /* end PDF_CoordRotate */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_CoordScale(ratio, dim) */
+ /* */
+ /* Scale coordinate system by ratio in the given dimension. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_CoordScale(float hfactor, float vfactor)
+ {
+ #if DEBUG_ON
+ char buff[20];
+ #endif
+ ifdebug(DPF, D, sprintf(buff, "%.3f, %.3f", hfactor, vfactor));
+ debug1(DPF, D, "CoordScale(%s)", buff);
+ if ( (fabs(hfactor - 1.0) > 0.01) || (fabs(vfactor - 1.0) > 0.01) )
+ {
+ #if 1
+ PDFPage_Scale(out_fp, hfactor, vfactor);
+ #else
+ char temp_str[64];
+ sprintf(temp_str, "%.2f 0 0 %.2f 0 0 cm\n", hfactor, vfactor);
+ PDFPage_Write(out_fp, temp_str);
+ #endif
+ }
+ cpexists = FALSE;
+ debug0(DPF, D, "CoordScale returning.");
+ } /* end PDF_CoordScale */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_SaveGraphicState(x) */
+ /* */
+ /* Save current coord system on stack for later restoration. */
+ /* Object x is just for error reporting, not really used at all. */
+ /* */
+ /*****************************************************************************/
+
+ void PDF_SaveGraphicState(OBJECT x)
+ { debug0(DPF, D, "PDF_SaveGraphicState()");
+ PDFPage_Push(out_fp);
+ gs_stack_top++;
+ if( gs_stack_top >= MAX_GS )
+ Error(50, 1, "rotations, graphics etc. too deeply nested (max is %d)",
+ FATAL, &fpos(x), MAX_GS);
+ gs_stack[gs_stack_top].gs_font = currentfont;
+ gs_stack[gs_stack_top].gs_colour = currentcolour;
+ gs_stack[gs_stack_top].gs_cpexists = cpexists;
+ gs_stack[gs_stack_top].gs_currenty = currenty;
+ gs_stack[gs_stack_top].gs_xheight2 = currentxheight2;
+ debug0(DPF, D, "PDF_SaveGraphicState returning.");
+ } /* end PDF_SaveGraphicState */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_RestoreGraphicState() */
+ /* */
+ /* Restore previously saved coordinate system. */
+ /* */
+ /* The following note probably only applies to the PostScript back end */
+ /* but I have not looked into this issue myself: */
+ /* */
+ /* NB we normally assume that */
+ /* no white space is needed before any item of output, but since this */
+ /* procedure is sometimes called immediately after PrintGraphicObject(), */
+ /* which does not append a concluding space, we prepend one here. */
+ /* */
+ /*****************************************************************************/
+
+ void PDF_RestoreGraphicState(void)
+ { debug0(DPF, D, "PDF_RestoreGraphicState()");
+ PDFPage_Pop(out_fp);
+ currentfont = gs_stack[gs_stack_top].gs_font;
+ currentcolour = gs_stack[gs_stack_top].gs_colour;
+ cpexists = gs_stack[gs_stack_top].gs_cpexists;
+ currenty = gs_stack[gs_stack_top].gs_currenty;
+ currentxheight2 = gs_stack[gs_stack_top].gs_xheight2;
+ gs_stack_top--;
+ debug0(DPF, D, "PDF_RestoreGraphicState returning.");
+ } /* end PDF_RestoreGraphicState */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintGraphicObject(x) */
+ /* */
+ /* Print object x on out_fp */
+ /* */
+ /*****************************************************************************/
+
+ void PDF_PrintGraphicObject(OBJECT x)
+ { OBJECT y, link;
+ debug3(DPF, D, "PDF_PrintGraphicObject(%s %s %s)",
+ EchoFilePos(&fpos(x)), Image(type(x)), EchoObject(x));
+ switch( type(x) )
+ {
+ case WORD:
+ case QWORD:
+
+ PDFPage_WriteGraphic(out_fp, string(x));
+ break;
+
+
+ case ACAT:
+
+ for( link = Down(x); link != x; link = NextDown(link) )
+ { Child(y, link);
+ if( type(y) == GAP_OBJ )
+ {
+ if( vspace(y) > 0 ) PDFPage_Write(out_fp, "\n");
+ else if( hspace(y) > 0 ) PDFPage_Write(out_fp, " ");
+ }
+ else if( is_word(type(y)) || type(y) == ACAT )
+ PDF_PrintGraphicObject(y);
+ else if( type(y) == WIDE || is_index(type(y)) )
+ {
+ /* ignore: @Wide, indexes are sometimes inserted by Manifest */
+ }
+ else
+ { Error(50, 2, "error in left parameter of %s",
+ WARN, &fpos(x), KW_GRAPHIC);
+ debug1(DPF, D, " type(y) = %s, y =", Image(type(y)));
+ ifdebug(DPF, D, DebugObject(y));
+ }
+ }
+ break;
+
+
+ default:
+
+ Error(50, 3, "error in left parameter of %s", WARN, &fpos(x), KW_GRAPHIC);
+ debug1(DPF, D, " type(x) = %s, x =", Image(type(x)));
+ ifdebug(DPF, D, DebugObject(x));
+ break;
+
+ }
+ debug0(DPF, D, "PDF_PrintGraphicObject returning");
+ } /* end PDF_PrintGraphicObject */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_DefineGraphicNames(x) */
+ /* */
+ /* Generate PostScript for xsize, ysize etc. names of graphic object. */
+ /* */
+ /*****************************************************************************/
+
+ void PDF_DefineGraphicNames(OBJECT x)
+ { assert( type(x) == GRAPHIC, "PrintGraphic: type(x) != GRAPHIC!" );
+ debug1(DPF, D, "DefineGraphicNames( %s )", EchoObject(x));
+ debug1(DPF, DD, " style = %s", EchoStyle(&save_style(x)));
+
+ /* if font is different to previous word then print change */
+ if( font(save_style(x)) != currentfont )
+ { currentfont = font(save_style(x));
+ if( currentfont > 0 )
+ { currentxheight2 = FontHalfXHeight(currentfont);
+ PDFFont_Set(out_fp, FontSize(currentfont, x), FontName(currentfont));
+ }
+ }
+
+ /* if colour is different to previous word then print change */
+ if( colour(save_style(x)) != currentcolour )
+ { currentcolour = colour(save_style(x));
+ if( currentcolour > 0 )
+ { char str[256];
+ sprintf(str, "%s ", ColourCommand(currentcolour));
+ PDFPage_Write(out_fp, str);
+ }
+ }
+
+ PDFPage_SetVars(size(x, COLM), size(x, ROWM), back(x, COLM), fwd(x, ROWM),
+ currentfont <= 0 ? 12*PT : FontSize(currentfont, x),
+ width(line_gap(save_style(x))), width(space_gap(save_style(x))));
+
+ debug0(DPF, D, "PDF_DefineGraphicNames returning.");
+ } /* end PDF_DefineGraphicNames */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_SaveTranslateDefineSave(x, xdist, ydist) */
+ /* */
+ /* Equivalent to the sequence of calls */
+ /* */
+ /* SaveGraphicState(x) */
+ /* CoordTranslate(xdist, ydist) */
+ /* DefineGraphicNames(x) */
+ /* SaveGraphicState(x) */
+ /* */
+ /* but offers prospects for optimization (not taken up in PDF). */
+ /* */
+ /*****************************************************************************/
+
+ void PDF_SaveTranslateDefineSave(OBJECT x, FULL_LENGTH xdist, FULL_LENGTH ydist)
+ {
+ PDF_SaveGraphicState(x);
+ PDF_CoordTranslate(xdist, ydist);
+ PDF_DefineGraphicNames(x);
+ PDF_SaveGraphicState(x);
+ } /* end PDF_SaveTranslateDefineSave */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_PrintGraphicInclude(x, colmark, rowmark) */
+ /* */
+ /* Print graphic include file, with appropriate surrounds. */
+ /* */
+ /*****************************************************************************/
+
+ void PDF_PrintGraphicInclude(OBJECT x, FULL_LENGTH colmark, FULL_LENGTH rowmark)
+ { OBJECT y;
+ debug0(DPF, D, "PDF_PrintGraphicInclude(x)");
+ Child(y, Down(x));
+ Error(50, 4, "cannot include EPS file in PDF output; EPS file %s ignored",
+ WARN, &fpos(x), string(y));
+ debug0(DPF, D, "PDF_PrintGraphicInclude returning.");
+ } /* end PDF_PrintGraphicInclude */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_LinkSource(name, llx, lly, urx, ury) */
+ /* */
+ /* Print a link source point. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_LinkSource(OBJECT name, FULL_LENGTH llx, FULL_LENGTH lly,
+ FULL_LENGTH urx, FULL_LENGTH ury)
+ {
+ debug5(DPF, D, "PDF_LinkSource(%s, %d, %d, %d, %d)", EchoObject(name),
+ llx, lly, urx, ury);
+
+ /* still to do */
+
+ debug0(DPF, D, "PDF_LinkSource returning.");
+ } /* end PDF_LinkSource */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_LinkDest(name, llx, lly, urx, ury) */
+ /* */
+ /* Print a link dest point. */
+ /* */
+ /* Still to do: check that the name has not been used by a previous */
+ /* dest point. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_LinkDest(OBJECT name, FULL_LENGTH llx, FULL_LENGTH lly,
+ FULL_LENGTH urx, FULL_LENGTH ury)
+ {
+ debug5(DPF, D, "PDF_LinkDest(%s, %d, %d, %d, %d)", EchoObject(name),
+ llx, lly, urx, ury);
+
+ /* still to do */
+
+ debug0(DPF, D, "PDF_LinkDest returning.");
+ } /* end PDF_LinkDest */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_LinkCheck() */
+ /* */
+ /* Called at end of run; will check that for every link source point there */
+ /* is a link dest point. */
+ /* */
+ /*****************************************************************************/
+
+ static void PDF_LinkCheck()
+ {
+ debug0(DPF, D, "PDF_LinkCheck()");
+
+ /* still to do */
+
+ debug0(DPF, D, "PDF_LinkCheck returning.");
+ } /* end PDF_LinkCheck */
+
+
+ /*****************************************************************************/
+ /* */
+ /* PDF_BackEnd */
+ /* */
+ /* The record into which all of these functions are packaged. */
+ /* */
+ /*****************************************************************************/
+
+ static struct back_end_rec pdf_back = {
+ PDF, /* the code number of the back end */
+ STR_PDF, /* string name of the back end */
+ TRUE, /* TRUE if @Scale is available */
+ TRUE, /* TRUE if @Rotate is available */
+ TRUE, /* TRUE if @Graphic is available */
+ TRUE, /* TRUE if @IncludeGraphic is avail. */
+ FALSE, /* TRUE if @PlainGraphic is avail. */
+ TRUE, /* TRUE if fractional spacing avail. */
+ TRUE, /* TRUE if actual font metrics used */
+ TRUE, /* TRUE if colour is available */
+ PDF_PrintInitialize,
+ PDF_PrintLength,
+ PDF_PrintPageSetupForFont,
+ PDF_PrintPageResourceForFont,
+ PDF_PrintMapping,
+ PDF_PrintBeforeFirstPage,
+ PDF_PrintBetweenPages,
+ PDF_PrintAfterLastPage,
+ PDF_PrintWord,
+ PDF_PrintPlainGraphic,
+ PDF_PrintUnderline,
+ PDF_CoordTranslate,
+ PDF_CoordRotate,
+ PDF_CoordScale,
+ PDF_SaveGraphicState,
+ PDF_RestoreGraphicState,
+ PDF_PrintGraphicObject,
+ PDF_DefineGraphicNames,
+ PDF_SaveTranslateDefineSave,
+ PDF_PrintGraphicInclude,
+ PDF_LinkSource,
+ PDF_LinkDest,
+ PDF_LinkCheck,
+ };
+
+ BACK_END PDF_BackEnd = &pdf_back;
Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z51.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z51.c:1.1
*** /dev/null Tue Jan 9 17:45:04 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/z51.c Tue Jan 9 17:44:35 2007
***************
*** 0 ****
--- 1,645 ----
+ /*@z51.c:Plain Text Back End:Plain_BackEnd@***********************************/
+ /* */
+ /* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.24) */
+ /* COPYRIGHT (C) 1991, 2000 Jeffrey H. Kingston */
+ /* */
+ /* Jeffrey H. Kingston (jeff at cs.usyd.edu.au) */
+ /* Basser Department of Computer Science */
+ /* The University of Sydney 2006 */
+ /* AUSTRALIA */
+ /* */
+ /* This program 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. */
+ /* */
+ /* This program 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 this program; if not, write to the Free Software */
+ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
+ /* */
+ /* FILE: z49.c */
+ /* MODULE: PostScript Back End */
+ /* EXTERNS: PS_BackEnd */
+ /* */
+ /*****************************************************************************/
+ #include "externs.h"
+
+
+ /*****************************************************************************/
+ /* */
+ /* PlainCharWidth the width of each character */
+ /* PlainCharHeight the height of each character */
+ /* PlainFormFeed TRUE if components to be separated by \f. */
+ /* */
+ /*****************************************************************************/
+
+ FULL_LENGTH PlainCharWidth, PlainCharHeight;
+ BOOLEAN PlainFormFeed;
+
+ /*****************************************************************************/
+ /* */
+ /* State variables for this module */
+ /* */
+ /*****************************************************************************/
+
+ static FILE *out_fp; /* file to print output on */
+ static int hsize; /* horizontal size of page in chars */
+ static int vsize; /* vertical size of page in chars */
+ static FULL_CHAR *page; /* the page (two-dim array of chars) */
+ static BOOLEAN prologue_done; /* TRUE after prologue is printed */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void Plain_PrintInitialize(fp) */
+ /* */
+ /* Initialize this module; fp is the output file. */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_PrintInitialize(FILE *fp)
+ {
+ debug0(DPT, DD, "Plain_PrintInitialize(fp)");
+ out_fp = fp;
+ prologue_done = FALSE;
+ debug0(DPT, DD, "Plain_PrintInitialize returning.");
+ } /* end Plain_PrintInitialize */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void Plain_PrintLength(FULL_CHAR *buff, int length, int length_dim) */
+ /* */
+ /* Print a length (debugging only) */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintLength(FULL_CHAR *buff, int length, int length_dim)
+ {
+ if( length_dim == COLM )
+ {
+ sprintf( (char *) buff, "%.2fs", (float) length/PlainCharWidth);
+ }
+ else
+ {
+ sprintf( (char *) buff, "%.2ff", (float) length/PlainCharHeight);
+ }
+ }
+
+
+ /*****************************************************************************/
+ /* */
+ /* void Plain_PrintPageSetupForFont(OBJECT face, int font_curr_page, */
+ /* FULL_CHAR *font_name, FULL_CHAR *first_size_str) */
+ /* */
+ /* Print the page setup commands required to use a font on some page: */
+ /* */
+ /* face The font face record, defining which font we need */
+ /* font_curr_page The current page number */
+ /* font_name The name of the font */
+ /* first_size_str No idea, have to check */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintPageSetupForFont(OBJECT face, int font_curr_page,
+ FULL_CHAR *font_name, FULL_CHAR *first_size_str)
+ {
+ /* nothing to do here */
+
+ } /* end Plain_PrintPageSetupForFont */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void Plain_PrintPageResourceForFont(FULL_CHAR *font_name, BOOLEAN first) */
+ /* BOOLEAN first) */
+ /* */
+ /* Print page resource info on file fp for font font_name; first is true */
+ /* if this is the first resource on this page. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintPageResourceForFont(FULL_CHAR *font_name, BOOLEAN first)
+ {
+ /* nothing to do here */
+
+ } /* end Plain_PrintPageResourceForFont */
+
+
+ /*****************************************************************************/
+ /* */
+ /* static void Plain_PrintMapping(MAPPING m) */
+ /* */
+ /* Print mapping m. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintMapping(MAPPING m)
+ {
+ /* nothing to do here */
+
+ } /* end Plain_PrintMapping */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void Plain_PrintBeforeFirstPage(h, v, label) */
+ /* */
+ /* This procedure is called just before starting to print the first */
+ /* component of the output. Its size is h, v, and label is the page label. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintBeforeFirstPage(FULL_LENGTH h, FULL_LENGTH v,
+ FULL_CHAR *label)
+ { int i, j;
+ debug2(DPT, DD, "PrintBeforeFirst(%d, %d)", h, v);
+
+ /* get a new page[] and clear it */
+ hsize = ceiling(h, PlainCharWidth);
+ vsize = ceiling(v, PlainCharHeight);
+ debug2(DPT, DD, " PlainCharWidth: %d; PlainCharHeight: %d",
+ PlainCharWidth, PlainCharHeight);
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_PAGES, 1,
+ hsize * vsize * sizeof(FULL_CHAR)));
+ debug2(DPT, DD, " PrintBeforeFirst allocating %d by %d", hsize, vsize);
+ page = (FULL_CHAR *) malloc(hsize * vsize * sizeof(FULL_CHAR));
+ for( i = 0; i < vsize; i++ )
+ for( j = 0; j < hsize; j++ )
+ page[i*hsize + j] = ' ';
+ prologue_done = TRUE;
+ } /* end Plain_PrintBeforeFirstPage */
+
+
+ /*****************************************************************************/
+ /* */
+ /* void Plain_PrintBetweenPages(h, v, label) */
+ /* */
+ /* Start a new output component, of size h by v; label is the page label */
+ /* to attach to the %%Page comment. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintBetweenPages(FULL_LENGTH h, FULL_LENGTH v,
+ FULL_CHAR *label)
+ { int new_hsize, new_vsize, i, j, jmax;
+ debug2(DPT, DD, "PrintBetween(%d, %d)", h, v);
+
+ /* print the page that has just ended */
+ ifdebug(DPT, D,
+ putc('+', out_fp);
+ for( j = 0; j < hsize; j++ ) putc('-', out_fp);
+ putc('+', out_fp);
+ putc('\n', out_fp);
+ );
+ for( i = vsize - 1; i >= 0; i-- )
+ { ifdebug(DPT, D, putc('|', out_fp));
+ for( jmax = hsize-1; jmax >= 0 && page[i*hsize+jmax] == ' '; jmax--);
+ ifdebug(DPT, D, jmax = hsize - 1);
+ for( j = 0; j <= jmax; j++ )
+ putc(page[i*hsize + j], out_fp);
+ ifdebug(DPT, D, putc('|', out_fp));
+ putc('\n', out_fp);
+ }
+ ifdebug(DPT, D,
+ putc('+', out_fp);
+ for( j = 0; j < hsize; j++ ) putc('-', out_fp);
+ putc('+', out_fp);
+ putc('\n', out_fp);
+ );
+
+ /* separate the page from the next one with a form-feed if required */
+ if( PlainFormFeed ) putc('\f', out_fp);
+
+ /* if page size has changed, get a new page[] array */
+ new_hsize = ceiling(h, PlainCharWidth);
+ new_vsize = ceiling(v, PlainCharHeight);
+ if( new_hsize != hsize || new_vsize != vsize )
+ {
+ ifdebug(DMA, D, DebugRegisterUsage(MEM_PAGES, -1,
+ -hsize * vsize * sizeof(FULL_CHAR)));
+ free(page);
+ hsize = new_hsize;
+ vsize = new_vsize;
+ debug2(DPT, DD, " PrintBetween allocating %d by %d", hsize, vsize);
+ ifdebug(DPT, D, DebugRegisterUsage(MEM_PAGES, 1,
+ hsize * vsize * sizeof(FULL_CHAR)));
+ page = (FULL_CHAR *) malloc(hsize * vsize * sizeof(FULL_CHAR));
+ }
+
+ /* clear page[] for the new page just beginning */
+ for( i = 0; i < vsize; i++ )
+ for( j = 0; j < hsize; j++ )
+ page[i*hsize + j] = ' ';
+ } /* end Plain_PrintBetweenPges */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_PrintWord(x, hpos, vpos) */
+ /* */
+ /* Print non-empty word x; its marks cross at the point (hpos, vpos). */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintWord(OBJECT x, int hpos, int vpos)
+ { FULL_CHAR *p; int i, h, v;
+
+ debug6(DPT, DD, "Plain_PrintWord( %s, %d, %d ) font %d colour %d%s",
+ string(x), hpos, vpos, word_font(x), word_colour(x),
+ word_outline(x) ? " outline" : "");
+ TotalWordCount++;
+
+ h = ((float) hpos / PlainCharWidth) + 0.5;
+ v = ((float) vpos / PlainCharHeight);
+ debug3(DPT, DD, "PrintWord(%s at h = %d, v = %d)", string(x), h, v);
+ if( h >= 0 && h + StringLength(string(x)) < hsize && v >= 0 && v < vsize )
+ {
+ assert( h >= 0, "PrintWord: h < 0!" );
+ assert( h < hsize, "PrintWord: h >= hsize!" );
+ assert( v >= 0, "PrintWord: v < 0!" );
+ assert( v < vsize, "PrintWord: v >= vsize!" );
+ p = &page[v*hsize + h];
+ for( i = 0; string(x)[i] != '\0'; i++ )
+ *p++ = string(x)[i];
+ }
+ else
+ Error(51, 1, "word %s deleted (internal error, off page at %d,%d)",
+ WARN, &fpos(x), string(x), h, v);
+ debug0(DPT, DDD, "PrintWord returning");
+ } /* end Plain_PrintWord */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_PrintPlainGraphic(x, xmk, ymk, z) */
+ /* */
+ /* Print plain graphic object x at xmk, ymk with the size of z. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintPlainGraphic(OBJECT x, FULL_LENGTH xmk,
+ FULL_LENGTH ymk, OBJECT z)
+ { int i, len, starth, startv, stoph, stopv, h, v;
+ debug2(DPT, D, "Plain_PrintPlainGraphic(x, xmk %s, ymk %s)",
+ EchoLength(xmk), EchoLength(ymk));
+
+ if( type(x) != WORD && type(x) != QWORD )
+ {
+ Error(51, 2, "left parameter of %s must be a simple word",
+ WARN, &fpos(x), KW_PLAINGRAPHIC);
+ return;
+ }
+ len = StringLength(string(x));
+ if( StringLength(string(x)) == 0 )
+ {
+ Error(51, 3, "left parameter of %s must be a non-empty word",
+ WARN, &fpos(x), KW_PLAINGRAPHIC);
+ return;
+ }
+ starth = (((float) xmk ) / PlainCharWidth) + 0.5;
+ startv = (((float) ymk ) / PlainCharHeight);
+ stoph = (((float) xmk + size(z, COLM)) / PlainCharWidth) + 0.5;
+ stopv = (((float) ymk - size(z, ROWM)) / PlainCharHeight); /* NB - not + */
+ SetLengthDim(COLM);
+ debug5(DPT, D, " xmk %s bk %s fwd %s -> %d,%d",
+ EchoLength(xmk), EchoLength(back(z, COLM)), EchoLength(fwd(z, COLM)),
+ starth, stoph);
+ SetLengthDim(ROWM);
+ debug5(DPT, D, " ymk %s bk %s fwd %s -> %d,%d",
+ EchoLength(ymk), EchoLength(back(z, ROWM)), EchoLength(fwd(z, ROWM)),
+ startv, stopv);
+ if( starth >= 0 && stoph < hsize && startv >= 0 && stopv < vsize )
+ { i = 0;
+ for( v = startv-1; v >= stopv; v-- )
+ {
+ for( h = starth; h < stoph; h++ )
+ {
+ if( i == len ) i = 0;
+ page[v*hsize + h] = string(x)[i++];
+ }
+ }
+ }
+ else
+ {
+ Error(51, 4, "fill %s deleted (internal error, off page at %d,%d)",
+ WARN, &fpos(x), string(x), h, v);
+ }
+ } /* end Plain_PrintPlainGraphic */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_PrintUnderline(fnum, col, xstart, xstop, ymk) */
+ /* */
+ /* Draw an underline suitable for font fnum, in colour col, from xstart to */
+ /* xstop at the appropriate distance below mark ymk. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintUnderline(FONT_NUM fnum, COLOUR_NUM col,
+ FULL_LENGTH xstart, FULL_LENGTH xstop, FULL_LENGTH ymk)
+ {
+
+ debug5(DPT, DD, "Plain_PrintUnderline(fnum %d, col %d, xstart %s, xstop %s, ymk %s )",
+ fnum, col, EchoLength(xstart), EchoLength(xstop), EchoLength(ymk));
+
+ /* do nothing */
+
+ debug0(DPT, DD, "PrintUnderline returning.");
+ } /* end Plain_PrintUnderline */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_PrintAfterLastPage() */
+ /* */
+ /* Clean up this module and close output stream. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_PrintAfterLastPage(void)
+ { int i, j, jmax;
+ if( prologue_done )
+ {
+ /* print the page that has just ended (exists since prologue_done) */
+ ifdebug(DPT, D,
+ putc('+', out_fp);
+ for( j = 0; j < hsize; j++ ) putc('-', out_fp);
+ putc('+', out_fp);
+ putc('\n', out_fp);
+ );
+ for( i = vsize - 1; i >= 0; i-- )
+ { ifdebug(DPT, D, putc('|', out_fp));
+ for( jmax = hsize-1; jmax >= 0 && page[i*hsize+jmax] == ' '; jmax--);
+ ifdebug(DPT, D, jmax = hsize - 1);
+ for( j = 0; j <= jmax; j++ )
+ putc(page[i*hsize + j], out_fp);
+ ifdebug(DPT, D, putc('|', out_fp));
+ putc('\n', out_fp);
+ }
+ ifdebug(DPT, D,
+ putc('+', out_fp);
+ for( j = 0; j < hsize; j++ ) putc('-', out_fp);
+ putc('+', out_fp);
+ putc('\n', out_fp);
+ );
+ }
+ } /* end Plain_PrintAfterLastPage */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_CoordTranslate(xdist, ydist) */
+ /* */
+ /* Translate coordinate system by the given x and y distances. */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_CoordTranslate(FULL_LENGTH xdist, FULL_LENGTH ydist)
+ { debug2(DPT, D, "Plain_CoordTranslate(%s, %s)",
+ EchoLength(xdist), EchoLength(ydist));
+ assert(FALSE, "Plain_CoordTranslate: should never be called!");
+ debug0(DPT, D, "Plain_CoordTranslate returning.");
+ } /* end Plain_CoordTranslate */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_CoordRotate(amount) */
+ /* */
+ /* Rotate coordinate system by given amount (in internal DG units) */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_CoordRotate(FULL_LENGTH amount)
+ { debug1(DPT, D, "Plain_CoordRotate(%.1f degrees)", (float) amount / DG);
+ assert(FALSE, "Plain_CoordRotate: should never be called!");
+ debug0(DPT, D, "Plain_CoordRotate returning.");
+ } /* end Plain_CoordRotate */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_CoordScale(ratio, dim) */
+ /* */
+ /* Scale coordinate system by ratio in the given dimension. */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_CoordScale(float hfactor, float vfactor)
+ {
+ assert(FALSE, "Plain_CoordScale: should never be called!");
+ } /* end Plain_CoordScale */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_SaveGraphicState(x) */
+ /* */
+ /* Save current coord system on stack for later restoration. */
+ /* Object x is just for error reporting, not really used at all. */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_SaveGraphicState(OBJECT x)
+ { debug0(DPT, D, "Plain_SaveGraphicState()");
+ assert(FALSE, "Plain_SaveGraphicState: should never be called!" );
+ debug0(DPT, D, "Plain_SaveGraphicState returning.");
+ } /* end Plain_SaveGraphicState */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_RestoreGraphicState() */
+ /* */
+ /* Restore previously saved coordinate system. */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_RestoreGraphicState(void)
+ { debug0(DPT, D, "Plain_RestoreGraphicState()");
+ assert(FALSE, "Plain_RestoreGraphicState: should never be called!" );
+ debug0(DPT, D, "Plain_RestoreGraphicState returning.");
+ } /* end Plain_RestoreGraphicState */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_PrintGraphicObject(x) */
+ /* */
+ /* Print object x on out_fp */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_PrintGraphicObject(OBJECT x)
+ {
+ debug3(DPT, D, "Plain_PrintGraphicObject(%s %s %s)",
+ EchoFilePos(&fpos(x)), Image(type(x)), EchoObject(x));
+ assert(FALSE, "Plain_PrintGraphicObject: should never be called!" );
+ debug0(DPT, D, "Plain_PrintGraphicObject returning");
+ } /* end Plain_PrintGraphicObject */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_DefineGraphicNames(x) */
+ /* */
+ /* Generate PostScript for xsize, ysize etc. names of graphic object. */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_DefineGraphicNames(OBJECT x)
+ {
+ debug1(DPT, D, "Plain_DefineGraphicNames( %s )", EchoObject(x));
+ debug1(DPT, DD, " style = %s", EchoStyle(&save_style(x)));
+ assert(FALSE, "Plain_DefineGraphicNames: should never be called!" );
+ debug0(DPT, D, "Plain_DefineGraphicNames returning.");
+ } /* end Plain_DefineGraphicNames */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_SaveTranslateDefineSave(x, xdist, ydist) */
+ /* */
+ /* Equivalent to the sequence of calls */
+ /* */
+ /* SaveGraphicState(x) */
+ /* CoordTranslate(xdist, ydist) */
+ /* DefineGraphicNames(x) */
+ /* SaveGraphicState(x) */
+ /* */
+ /* but offers opportunities for optimization. */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_SaveTranslateDefineSave(OBJECT x, FULL_LENGTH xdist,
+ FULL_LENGTH ydist)
+ {
+ assert(FALSE, "Plain_SaveTranslateDefineSave: should never be called!" );
+ } /* end Plain_SaveTranslateDefineSave */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_PrintGraphicInclude(x, colmark, rowmark) */
+ /* */
+ /* Print graphic include file, with appropriate surrounds. */
+ /* */
+ /*****************************************************************************/
+
+ void Plain_PrintGraphicInclude(OBJECT x, FULL_LENGTH colmark,
+ FULL_LENGTH rowmark)
+ {
+ debug0(DPT, D, "Plain_PrintGraphicInclude(x)");
+ assert(FALSE, "Plain_PrintGraphicInclude: should never be called!" );
+ debug0(DPT, D, "Plain_PrintGraphicInclude returning.");
+ } /* end Plain_PrintGraphicInclude */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_LinkSource(name, llx, lly, urx, ury) */
+ /* */
+ /* Print a link source point. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_LinkSource(OBJECT name, FULL_LENGTH llx, FULL_LENGTH lly,
+ FULL_LENGTH urx, FULL_LENGTH ury)
+ {
+ debug5(DPT, D, "Plain_LinkSource(%s, %d, %d, %d, %d)", EchoObject(name),
+ llx, lly, urx, ury);
+ /* do nothing; no links in plain text output */
+ debug0(DPT, D, "Plain_LinkSource returning.");
+ } /* end Plain_LinkSource */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_LinkDest(name, llx, lly, urx, ury) */
+ /* */
+ /* Print a link dest point. */
+ /* */
+ /* Still to do: check that the name has not been used by a previous */
+ /* dest point. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_LinkDest(OBJECT name, FULL_LENGTH llx, FULL_LENGTH lly,
+ FULL_LENGTH urx, FULL_LENGTH ury)
+ {
+ debug5(DPT, D, "Plain_LinkDest(%s, %d, %d, %d, %d)", EchoObject(name),
+ llx, lly, urx, ury);
+ /* do nothing; no links in plain text output */
+ debug0(DPT, D, "Plain_LinkDest returning.");
+ } /* end Plain_LinkDest */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_LinkCheck() */
+ /* */
+ /* Called at end of run; will check that for every link source point there */
+ /* is a link dest point. */
+ /* */
+ /*****************************************************************************/
+
+ static void Plain_LinkCheck()
+ {
+ debug0(DPT, D, "Plain_LinkCheck()");
+ /* do nothing; no links in plain text output */
+ debug0(DPT, D, "Plain_LinkCheck returning.");
+ } /* end Plain_LinkCheck */
+
+
+ /*****************************************************************************/
+ /* */
+ /* Plain_BackEnd */
+ /* */
+ /* The record into which all of these functions are packaged. */
+ /* */
+ /*****************************************************************************/
+
+ static struct back_end_rec plain_back = {
+ PLAINTEXT, /* the code number of the back end */
+ STR_PLAINTEXT, /* string name of the back end */
+ FALSE, /* TRUE if @Scale is available */
+ FALSE, /* TRUE if @Rotate is available */
+ FALSE, /* TRUE if @Graphic is available */
+ FALSE, /* TRUE if @IncludeGraphic is avail. */
+ TRUE, /* TRUE if @PlainGraphic is avail. */
+ FALSE, /* TRUE if fractional spacing avail. */
+ FALSE, /* TRUE if actual font metrics used */
+ FALSE, /* TRUE if colour is available */
+ Plain_PrintInitialize,
+ Plain_PrintLength,
+ Plain_PrintPageSetupForFont,
+ Plain_PrintPageResourceForFont,
+ Plain_PrintMapping,
+ Plain_PrintBeforeFirstPage,
+ Plain_PrintBetweenPages,
+ Plain_PrintAfterLastPage,
+ Plain_PrintWord,
+ Plain_PrintPlainGraphic,
+ Plain_PrintUnderline,
+ Plain_CoordTranslate,
+ Plain_CoordRotate,
+ Plain_CoordScale,
+ Plain_SaveGraphicState,
+ Plain_RestoreGraphicState,
+ Plain_PrintGraphicObject,
+ Plain_DefineGraphicNames,
+ Plain_SaveTranslateDefineSave,
+ Plain_PrintGraphicInclude,
+ Plain_LinkSource,
+ Plain_LinkDest,
+ Plain_LinkCheck,
+ };
+
+ BACK_END Plain_BackEnd = &plain_back;
More information about the llvm-commits
mailing list