From: Clerk Date: Sat, 16 Aug 2014 16:06:00 +0000 (+0800) Subject: removed libmd5. X-Git-Url: http://git.osdn.net/view?p=putex%2Fputex.git;a=commitdiff_plain;h=ae80400414b6d1c308c3e3036a267ca50549c016 removed libmd5. --- diff --git a/src/texsourc/Makefile.linux.android.static b/src/texsourc/Makefile.linux.android.static index 091224c..424651c 100644 --- a/src/texsourc/Makefile.linux.android.static +++ b/src/texsourc/Makefile.linux.android.static @@ -1,82 +1,79 @@ -# -# Copyright (c) 2014 Clerk Ma -# -# You may freely use, modify and/or distribute this file. -# -# makefile for linux (tested in ubuntu 14.04: gcc 4.8). -# linked libkpathsea.a and libz.a -# ./configure --prefix=/home/clerk/dev --host=arm-linux-androideabi -# - -CC = arm-linux-androideabi-gcc -CFLAGS = -c -O2 -Wno-unused-result -Ilibmd5 -I/home/clerk/android/include -LDFLAGS = /home/clerk/android/lib/libkpathsea.a -lz - -objects = yandytex.o itex.o openinou.o subroute.o local.o \ - tex0.o tex1.o tex2.o tex3.o tex4.o \ - tex5.o tex6.o tex7.o tex8.o tex9.o \ - pool.o md5.o utils.o - -headers = yandytex.h texd.h coerce.h macros.h memory.h - -yandytex: $(objects) - $(CC) -s -o yandytex $(objects) $(LDFLAGS) - -yandytex.o: yandytex.c $(headers) - $(CC) $(CFLAGS) yandytex.c - -itex.o: itex.c $(headers) - $(CC) $(CFLAGS) itex.c - -openinou.o: openinou.c $(headers) - $(CC) $(CFLAGS) openinou.c - -subroute.o: subroute.c $(headers) - $(CC) $(CFLAGS) subroute.c - -local.o: local.c $(headers) - $(CC) $(CFLAGS) local.c - -tex0.o: tex0.c $(headers) - $(CC) $(CFLAGS) tex0.c - -tex1.o: tex1.c $(headers) - $(CC) $(CFLAGS) tex1.c - -tex2.o: tex2.c $(headers) - $(CC) $(CFLAGS) tex2.c - -tex3.o: tex3.c $(headers) - $(CC) $(CFLAGS) tex3.c - -tex4.o: tex4.c $(headers) - $(CC) $(CFLAGS) tex4.c - -tex5.o: tex5.c $(headers) - $(CC) $(CFLAGS) tex5.c - -tex6.o: tex6.c $(headers) - $(CC) $(CFLAGS) tex6.c - -tex7.o: tex7.c $(headers) - $(CC) $(CFLAGS) tex7.c - -tex8.o: tex8.c $(headers) - $(CC) $(CFLAGS) tex8.c - -tex9.o: tex9.c $(headers) - $(CC) $(CFLAGS) tex9.c - -pool.o: pool.c $(headers) - $(CC) $(CFLAGS) pool.c - -md5.o: libmd5/md5.c $(headers) - $(CC) $(CFLAGS) libmd5/md5.c - -utils.o: utils.c $(headers) - $(CC) $(CFLAGS) utils.c - -.PHONY: clean - -clean: - rm yandytex *.o +# +# Copyright (c) 2014 Clerk Ma +# +# You may freely use, modify and/or distribute this file. +# +# makefile for linux (tested in ubuntu 14.04: gcc 4.8). +# linked libkpathsea.a and libz.a +# ./configure --prefix=/home/clerk/dev --host=arm-linux-androideabi +# + +CC = arm-linux-androideabi-gcc +CFLAGS = -c -O2 -Wno-unused-result -I/home/clerk/android/include +LDFLAGS = /home/clerk/android/lib/libkpathsea.a -lz + +objects = yandytex.o itex.o openinou.o subroute.o local.o \ + tex0.o tex1.o tex2.o tex3.o tex4.o \ + tex5.o tex6.o tex7.o tex8.o tex9.o \ + pool.o utils.o + +headers = yandytex.h texd.h coerce.h macros.h memory.h + +yandytex: $(objects) + $(CC) -s -o yandytex $(objects) $(LDFLAGS) + +yandytex.o: yandytex.c $(headers) + $(CC) $(CFLAGS) yandytex.c + +itex.o: itex.c $(headers) + $(CC) $(CFLAGS) itex.c + +openinou.o: openinou.c $(headers) + $(CC) $(CFLAGS) openinou.c + +subroute.o: subroute.c $(headers) + $(CC) $(CFLAGS) subroute.c + +local.o: local.c $(headers) + $(CC) $(CFLAGS) local.c + +tex0.o: tex0.c $(headers) + $(CC) $(CFLAGS) tex0.c + +tex1.o: tex1.c $(headers) + $(CC) $(CFLAGS) tex1.c + +tex2.o: tex2.c $(headers) + $(CC) $(CFLAGS) tex2.c + +tex3.o: tex3.c $(headers) + $(CC) $(CFLAGS) tex3.c + +tex4.o: tex4.c $(headers) + $(CC) $(CFLAGS) tex4.c + +tex5.o: tex5.c $(headers) + $(CC) $(CFLAGS) tex5.c + +tex6.o: tex6.c $(headers) + $(CC) $(CFLAGS) tex6.c + +tex7.o: tex7.c $(headers) + $(CC) $(CFLAGS) tex7.c + +tex8.o: tex8.c $(headers) + $(CC) $(CFLAGS) tex8.c + +tex9.o: tex9.c $(headers) + $(CC) $(CFLAGS) tex9.c + +pool.o: pool.c $(headers) + $(CC) $(CFLAGS) pool.c + +utils.o: utils.c $(headers) + $(CC) $(CFLAGS) utils.c + +.PHONY: clean + +clean: + rm yandytex *.o diff --git a/src/texsourc/Makefile.linux.clang b/src/texsourc/Makefile.linux.clang index 597a1ac..457ca3a 100644 --- a/src/texsourc/Makefile.linux.clang +++ b/src/texsourc/Makefile.linux.clang @@ -1,83 +1,78 @@ -# -# Copyright (c) 2014 Clerk Ma -# -# You may freely use, modify and/or distribute this file. -# -# makefile for linux (tested in ubuntu 14.04: clang/LLVM 4.3). -# -# apt-get install libkpathsea6 libkpathsea-dev -# apt-get install zlib1g zlib1g-dev -# - -CC = clang -CFLAGS = -c -O2 -Ilibmd5 -LDFLAGS = -lkpathsea -lz - -objects = yandytex.o itex.o openinou.o subroute.o local.o \ - tex0.o tex1.o tex2.o tex3.o tex4.o \ - tex5.o tex6.o tex7.o tex8.o tex9.o \ - pool.o md5.o utils.o - -headers = yandytex.h texd.h coerce.h macros.h memory.h - -yandytex: $(objects) - $(CC) -s -o yandytex $(objects) $(LDFLAGS) - -yandytex.o: yandytex.c $(headers) - $(CC) $(CFLAGS) yandytex.c - -itex.o: itex.c $(headers) - $(CC) $(CFLAGS) itex.c - -openinou.o: openinou.c $(headers) - $(CC) $(CFLAGS) openinou.c - -subroute.o: subroute.c $(headers) - $(CC) $(CFLAGS) subroute.c - -local.o: local.c $(headers) - $(CC) $(CFLAGS) local.c - -tex0.o: tex0.c $(headers) - $(CC) $(CFLAGS) tex0.c - -tex1.o: tex1.c $(headers) - $(CC) $(CFLAGS) tex1.c - -tex2.o: tex2.c $(headers) - $(CC) $(CFLAGS) tex2.c - -tex3.o: tex3.c $(headers) - $(CC) $(CFLAGS) tex3.c - -tex4.o: tex4.c $(headers) - $(CC) $(CFLAGS) tex4.c - -tex5.o: tex5.c $(headers) - $(CC) $(CFLAGS) tex5.c - -tex6.o: tex6.c $(headers) - $(CC) $(CFLAGS) tex6.c - -tex7.o: tex7.c $(headers) - $(CC) $(CFLAGS) tex7.c - -tex8.o: tex8.c $(headers) - $(CC) $(CFLAGS) tex8.c - -tex9.o: tex9.c $(headers) - $(CC) $(CFLAGS) tex9.c - -pool.o: pool.c $(headers) - $(CC) $(CFLAGS) pool.c - -md5.o: libmd5/md5.c $(headers) - $(CC) $(CFLAGS) libmd5/md5.c - -utils.o: utils.c $(headers) - $(CC) $(CFLAGS) utils.c - -.PHONY: clean - -clean: - rm yandytex *.o +# +# Copyright (c) 2014 Clerk Ma +# +# You may freely use, modify and/or distribute this file. +# +# makefile for linux (tested in ubuntu 14.04: clang/LLVM 4.3). +# +# + +CC = clang +CFLAGS = -c -O2 -Ilibmd5 +LDFLAGS = -lkpathsea -lz + +objects = yandytex.o itex.o openinou.o subroute.o local.o \ + tex0.o tex1.o tex2.o tex3.o tex4.o \ + tex5.o tex6.o tex7.o tex8.o tex9.o \ + pool.o utils.o dpx.o + +headers = yandytex.h texd.h coerce.h macros.h memory.h + +yandytex: $(objects) + $(CC) -s -o yandytex $(objects) $(LDFLAGS) + +yandytex.o: yandytex.c $(headers) + $(CC) $(CFLAGS) yandytex.c + +itex.o: itex.c $(headers) + $(CC) $(CFLAGS) itex.c + +openinou.o: openinou.c $(headers) + $(CC) $(CFLAGS) openinou.c + +subroute.o: subroute.c $(headers) + $(CC) $(CFLAGS) subroute.c + +local.o: local.c $(headers) + $(CC) $(CFLAGS) local.c + +tex0.o: tex0.c $(headers) + $(CC) $(CFLAGS) tex0.c + +tex1.o: tex1.c $(headers) + $(CC) $(CFLAGS) tex1.c + +tex2.o: tex2.c $(headers) + $(CC) $(CFLAGS) tex2.c + +tex3.o: tex3.c $(headers) + $(CC) $(CFLAGS) tex3.c + +tex4.o: tex4.c $(headers) + $(CC) $(CFLAGS) tex4.c + +tex5.o: tex5.c $(headers) + $(CC) $(CFLAGS) tex5.c + +tex6.o: tex6.c $(headers) + $(CC) $(CFLAGS) tex6.c + +tex7.o: tex7.c $(headers) + $(CC) $(CFLAGS) tex7.c + +tex8.o: tex8.c $(headers) + $(CC) $(CFLAGS) tex8.c + +tex9.o: tex9.c $(headers) + $(CC) $(CFLAGS) tex9.c + +pool.o: pool.c $(headers) + $(CC) $(CFLAGS) pool.c + +utils.o: utils.c $(headers) + $(CC) $(CFLAGS) utils.c + +.PHONY: clean + +clean: + rm yandytex *.o diff --git a/src/texsourc/Makefile.linux.gcc b/src/texsourc/Makefile.linux.gcc index 70d86e3..b50f0fc 100644 --- a/src/texsourc/Makefile.linux.gcc +++ b/src/texsourc/Makefile.linux.gcc @@ -1,83 +1,80 @@ -# -# Copyright (c) 2014 Clerk Ma -# -# You may freely use, modify and/or distribute this file. -# -# makefile for linux (tested in ubuntu 14.04: gcc 4.8). -# -# apt-get install libkpathsea6 libkpathsea-dev -# apt-get install zlib1g zlib1g-dev -# - -CC = gcc -CFLAGS = -c -O2 -Wno-unused-result -Ilibmd5 -LDFLAGS = -lkpathsea -lz - -objects = yandytex.o itex.o openinou.o subroute.o local.o \ - tex0.o tex1.o tex2.o tex3.o tex4.o \ - tex5.o tex6.o tex7.o tex8.o tex9.o \ - pool.o md5.o utils.o - -headers = yandytex.h texd.h coerce.h macros.h memory.h - -yandytex: $(objects) - $(CC) -s -o yandytex $(objects) $(LDFLAGS) - -yandytex.o: yandytex.c $(headers) - $(CC) $(CFLAGS) yandytex.c - -itex.o: itex.c $(headers) - $(CC) $(CFLAGS) itex.c - -openinou.o: openinou.c $(headers) - $(CC) $(CFLAGS) openinou.c - -subroute.o: subroute.c $(headers) - $(CC) $(CFLAGS) subroute.c - -local.o: local.c $(headers) - $(CC) $(CFLAGS) local.c - -tex0.o: tex0.c $(headers) - $(CC) $(CFLAGS) tex0.c - -tex1.o: tex1.c $(headers) - $(CC) $(CFLAGS) tex1.c - -tex2.o: tex2.c $(headers) - $(CC) $(CFLAGS) tex2.c - -tex3.o: tex3.c $(headers) - $(CC) $(CFLAGS) tex3.c - -tex4.o: tex4.c $(headers) - $(CC) $(CFLAGS) tex4.c - -tex5.o: tex5.c $(headers) - $(CC) $(CFLAGS) tex5.c - -tex6.o: tex6.c $(headers) - $(CC) $(CFLAGS) tex6.c - -tex7.o: tex7.c $(headers) - $(CC) $(CFLAGS) tex7.c - -tex8.o: tex8.c $(headers) - $(CC) $(CFLAGS) tex8.c - -tex9.o: tex9.c $(headers) - $(CC) $(CFLAGS) tex9.c - -pool.o: pool.c $(headers) - $(CC) $(CFLAGS) pool.c - -md5.o: libmd5/md5.c $(headers) - $(CC) $(CFLAGS) libmd5/md5.c - -utils.o: utils.c $(headers) - $(CC) $(CFLAGS) utils.c - -.PHONY: clean - -clean: - rm yandytex *.o +# +# Copyright (c) 2014 Clerk Ma +# +# You may freely use, modify and/or distribute this file. +# +# makefile for linux (tested in ubuntu 14.04: gcc 4.8). +# +# apt-get install libkpathsea6 libkpathsea-dev +# apt-get install zlib1g zlib1g-dev +# + +CC = gcc +CFLAGS = -c -O2 -Wno-unused-result +LDFLAGS = -lkpathsea -lz + +objects = yandytex.o itex.o openinou.o subroute.o local.o \ + tex0.o tex1.o tex2.o tex3.o tex4.o \ + tex5.o tex6.o tex7.o tex8.o tex9.o \ + pool.o utils.o + +headers = yandytex.h texd.h coerce.h macros.h memory.h + +yandytex: $(objects) + $(CC) -s -o yandytex $(objects) $(LDFLAGS) + +yandytex.o: yandytex.c $(headers) + $(CC) $(CFLAGS) yandytex.c + +itex.o: itex.c $(headers) + $(CC) $(CFLAGS) itex.c + +openinou.o: openinou.c $(headers) + $(CC) $(CFLAGS) openinou.c + +subroute.o: subroute.c $(headers) + $(CC) $(CFLAGS) subroute.c + +local.o: local.c $(headers) + $(CC) $(CFLAGS) local.c + +tex0.o: tex0.c $(headers) + $(CC) $(CFLAGS) tex0.c + +tex1.o: tex1.c $(headers) + $(CC) $(CFLAGS) tex1.c + +tex2.o: tex2.c $(headers) + $(CC) $(CFLAGS) tex2.c + +tex3.o: tex3.c $(headers) + $(CC) $(CFLAGS) tex3.c + +tex4.o: tex4.c $(headers) + $(CC) $(CFLAGS) tex4.c + +tex5.o: tex5.c $(headers) + $(CC) $(CFLAGS) tex5.c + +tex6.o: tex6.c $(headers) + $(CC) $(CFLAGS) tex6.c + +tex7.o: tex7.c $(headers) + $(CC) $(CFLAGS) tex7.c + +tex8.o: tex8.c $(headers) + $(CC) $(CFLAGS) tex8.c + +tex9.o: tex9.c $(headers) + $(CC) $(CFLAGS) tex9.c + +pool.o: pool.c $(headers) + $(CC) $(CFLAGS) pool.c + +utils.o: utils.c $(headers) + $(CC) $(CFLAGS) utils.c + +.PHONY: clean + +clean: + rm yandytex *.o diff --git a/src/texsourc/Makefile.linux.gcc.static b/src/texsourc/Makefile.linux.gcc.static index b03c94a..87b8f66 100644 --- a/src/texsourc/Makefile.linux.gcc.static +++ b/src/texsourc/Makefile.linux.gcc.static @@ -1,84 +1,81 @@ -# -# Copyright (c) 2014 Clerk Ma -# -# You may freely use, modify and/or distribute this file. -# -# makefle for linux (tested in ubuntu 14.04: gcc 4.8). -# linked libkpathsea.a and libz.a -# - -CC = gcc -CFLAGS = -g -c -O2 -Wno-unused-result -Ilibmd5 -LDFLAGS = /home/clerk/dev/android/lib/libkpathsea.a libdpx.a libpng.a libpaper.a /home/clerk/dev/android/lib/libz.a /home/clerk/dev/android/lib/libkpathsea.a -lm - -objects = yandytex.o itex.o openinou.o subroute.o local.o \ - tex0.o tex1.o tex2.o tex3.o tex4.o \ - tex5.o tex6.o tex7.o tex8.o tex9.o \ - pool.o md5.o utils.o dpx.o - -headers = yandytex.h texd.h coerce.h macros.h memory.h - -yandytex: $(objects) - $(CC) -o yandytex $(objects) $(LDFLAGS) - -yandytex.o: yandytex.c $(headers) - $(CC) $(CFLAGS) yandytex.c - -dpx.o: dpx.c $(headers) - $(CC) $(CFLAGS) dpx.c - -itex.o: itex.c $(headers) - $(CC) $(CFLAGS) itex.c - -openinou.o: openinou.c $(headers) - $(CC) $(CFLAGS) openinou.c - -subroute.o: subroute.c $(headers) - $(CC) $(CFLAGS) subroute.c - -local.o: local.c $(headers) - $(CC) $(CFLAGS) local.c - -tex0.o: tex0.c $(headers) - $(CC) $(CFLAGS) tex0.c - -tex1.o: tex1.c $(headers) - $(CC) $(CFLAGS) tex1.c - -tex2.o: tex2.c $(headers) - $(CC) $(CFLAGS) tex2.c - -tex3.o: tex3.c $(headers) - $(CC) $(CFLAGS) tex3.c - -tex4.o: tex4.c $(headers) - $(CC) $(CFLAGS) tex4.c - -tex5.o: tex5.c $(headers) - $(CC) $(CFLAGS) tex5.c - -tex6.o: tex6.c $(headers) - $(CC) $(CFLAGS) tex6.c - -tex7.o: tex7.c $(headers) - $(CC) $(CFLAGS) tex7.c - -tex8.o: tex8.c $(headers) - $(CC) $(CFLAGS) tex8.c - -tex9.o: tex9.c $(headers) - $(CC) $(CFLAGS) tex9.c - -pool.o: pool.c $(headers) - $(CC) $(CFLAGS) pool.c - -md5.o: libmd5/md5.c $(headers) - $(CC) $(CFLAGS) libmd5/md5.c - -utils.o: utils.c $(headers) - $(CC) $(CFLAGS) utils.c - -.PHONY: clean - -clean: - rm yandytex *.o +# +# Copyright (c) 2014 Clerk Ma +# +# You may freely use, modify and/or distribute this file. +# +# makefle for linux (tested in ubuntu 14.04: gcc 4.8). +# linked libkpathsea.a and libz.a +# + +CC = gcc +CFLAGS = -g -c -O2 -Wno-unused-result +LDFLAGS = /home/clerk/dev/android/lib/libkpathsea.a libdpx.a libpng.a libpaper.a /home/clerk/dev/android/lib/libz.a /home/clerk/dev/android/lib/libkpathsea.a -lm + +objects = yandytex.o itex.o openinou.o subroute.o local.o \ + tex0.o tex1.o tex2.o tex3.o tex4.o \ + tex5.o tex6.o tex7.o tex8.o tex9.o \ + pool.o utils.o dpx.o + +headers = yandytex.h texd.h coerce.h macros.h memory.h + +yandytex: $(objects) + $(CC) -o yandytex $(objects) $(LDFLAGS) + +yandytex.o: yandytex.c $(headers) + $(CC) $(CFLAGS) yandytex.c + +dpx.o: dpx.c $(headers) + $(CC) $(CFLAGS) dpx.c + +itex.o: itex.c $(headers) + $(CC) $(CFLAGS) itex.c + +openinou.o: openinou.c $(headers) + $(CC) $(CFLAGS) openinou.c + +subroute.o: subroute.c $(headers) + $(CC) $(CFLAGS) subroute.c + +local.o: local.c $(headers) + $(CC) $(CFLAGS) local.c + +tex0.o: tex0.c $(headers) + $(CC) $(CFLAGS) tex0.c + +tex1.o: tex1.c $(headers) + $(CC) $(CFLAGS) tex1.c + +tex2.o: tex2.c $(headers) + $(CC) $(CFLAGS) tex2.c + +tex3.o: tex3.c $(headers) + $(CC) $(CFLAGS) tex3.c + +tex4.o: tex4.c $(headers) + $(CC) $(CFLAGS) tex4.c + +tex5.o: tex5.c $(headers) + $(CC) $(CFLAGS) tex5.c + +tex6.o: tex6.c $(headers) + $(CC) $(CFLAGS) tex6.c + +tex7.o: tex7.c $(headers) + $(CC) $(CFLAGS) tex7.c + +tex8.o: tex8.c $(headers) + $(CC) $(CFLAGS) tex8.c + +tex9.o: tex9.c $(headers) + $(CC) $(CFLAGS) tex9.c + +pool.o: pool.c $(headers) + $(CC) $(CFLAGS) pool.c + +utils.o: utils.c $(headers) + $(CC) $(CFLAGS) utils.c + +.PHONY: clean + +clean: + rm yandytex *.o diff --git a/src/texsourc/Makefile.win.clang b/src/texsourc/Makefile.win.clang index 7f5915f..7c132bf 100644 --- a/src/texsourc/Makefile.win.clang +++ b/src/texsourc/Makefile.win.clang @@ -1,99 +1,96 @@ -# Copyright 2007 TeX Users Group. -# Copyright 2014 Clerk Ma. -# -# You may freely use, modify and/or distribute this file. -# -# Makefile for Y&YTeX (tested on Clang/LLVM 3.4) - -CC = clang-cl -LINK = link -RC = rc - -CFLAGS=/nologo /c /MT /GF /Ox /W4 \ - /I"kpathsea" /I"zlib" /I"libmd5" /D_CRT_SECURE_NO_WARNINGS \ - -Wno-char-subscripts -Wno-dangling-else \ - -Wno-deprecated-declarations - -LFLAGS=/NOLOGO /MAP - -objs = yandytex.obj itex.obj openinou.obj subroute.obj local.obj \ - tex0.obj tex1.obj tex2.obj tex3.obj tex4.obj \ - tex5.obj tex6.obj tex7.obj tex8.obj tex9.obj \ - pool.obj yandytex.res md5.obj utils.obj - -yandytex.exe: $(objs) - $(LINK) $(LFLAGS) yandytex itex openinou subroute local \ - tex0 tex1 tex2 tex3 tex4 tex5 tex6 tex7 tex8 tex9 \ - pool yandytex.res md5 utils \ - kpathsea\kpathsea.lib zlib\zlib.lib - del ..\yandy\bin\yandytex.exe - copy yandytex.exe ..\yandy\bin\yandytex.exe - -md5.obj: libmd5\md5.c - $(CC) -Ilibmd5 $(CFLAGS) libmd5\md5.c - -yandytex.res: yandytex.rc - $(RC) /nologo yandytex.rc - -yandytex.obj: yandytex.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) yandytex.c - -itex.obj: itex.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) itex.c - -openinou.obj: openinou.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) openinou.c - -subroute.obj: subroute.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) subroute.c - -local.obj: local.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) local.c - -tex0.obj: tex0.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex1.obj: tex1.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex2.obj: tex2.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex3.obj: tex3.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex4.obj: tex4.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex5.obj: tex5.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex6.obj: tex6.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex7.obj: tex7.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex8.obj: tex8.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex9.obj: tex9.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -pool.obj: pool.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -utils.obj: utils.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -.SUFFIXES: -.SUFFIXES: .obj .c - -c..obj: - $(CC) $(CFLAGS) $*.c - +# Copyright 2007 TeX Users Group. +# Copyright 2014 Clerk Ma. +# +# You may freely use, modify and/or distribute this file. +# +# Makefile for Y&YTeX (tested on Clang/LLVM 3.4) + +CC = clang-cl +LINK = link +RC = rc + +CFLAGS=/nologo /c /MT /GF /Ox /W4 \ + /I"kpathsea" /I"zlib" /D_CRT_SECURE_NO_WARNINGS \ + -Wno-char-subscripts -Wno-dangling-else \ + -Wno-deprecated-declarations + +LFLAGS=/NOLOGO /MAP + +objs = yandytex.obj itex.obj openinou.obj subroute.obj local.obj \ + tex0.obj tex1.obj tex2.obj tex3.obj tex4.obj \ + tex5.obj tex6.obj tex7.obj tex8.obj tex9.obj \ + pool.obj yandytex.res utils.obj + +yandytex.exe: $(objs) + $(LINK) $(LFLAGS) yandytex itex openinou subroute local \ + tex0 tex1 tex2 tex3 tex4 tex5 tex6 tex7 tex8 tex9 \ + pool yandytex.res md5 utils \ + kpathsea\kpathsea.lib zlib\zlib.lib + del ..\yandy\bin\yandytex.exe + copy yandytex.exe ..\yandy\bin\yandytex.exe + +yandytex.res: yandytex.rc + $(RC) /nologo yandytex.rc + +yandytex.obj: yandytex.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) yandytex.c + +itex.obj: itex.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) itex.c + +openinou.obj: openinou.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) openinou.c + +subroute.obj: subroute.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) subroute.c + +local.obj: local.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) local.c + +tex0.obj: tex0.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex1.obj: tex1.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex2.obj: tex2.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex3.obj: tex3.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex4.obj: tex4.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex5.obj: tex5.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex6.obj: tex6.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex7.obj: tex7.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex8.obj: tex8.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex9.obj: tex9.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +pool.obj: pool.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +utils.obj: utils.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +.SUFFIXES: +.SUFFIXES: .obj .c + +c..obj: + $(CC) $(CFLAGS) $*.c + diff --git a/src/texsourc/Makefile.win.msvc b/src/texsourc/Makefile.win.msvc index 981fb80..888f241 100644 --- a/src/texsourc/Makefile.win.msvc +++ b/src/texsourc/Makefile.win.msvc @@ -1,98 +1,95 @@ -# Copyright 2007 TeX Users Group. -# Copyright 2014 Clerk Ma. -# -# You may freely use, modify and/or distribute this file. -# -# Makefile for Y&YTeX (MSVC, tested on VS 2012 and VS 2013) - -CC = cl -LINK = link -RC = rc - -CFLAGS=/nologo /c /MT /GF /Gy /W4 \ - /I"kpathsea" /I"zlib" /I"libmd5" - -LFLAGS=/NOLOGO /MAP - -objs = yandytex.obj itex.obj openinou.obj subroute.obj local.obj \ - tex0.obj tex1.obj tex2.obj tex3.obj tex4.obj \ - tex5.obj tex6.obj tex7.obj tex8.obj tex9.obj \ - pool.obj yandytex.res md5.obj utils.obj - -yandytex.exe: $(objs) - $(LINK) $(LFLAGS) yandytex itex openinou subroute local \ - tex0 tex1 tex2 tex3 tex4 tex5 tex6 tex7 tex8 tex9 \ - pool yandytex.res md5 utils \ - kpathsea\kpathsea.lib zlib\zlib.lib - del ..\yandy\bin\yandytex.exe - copy yandytex.exe ..\yandy\bin\yandytex.exe - -md5.obj: libmd5\md5.c - $(CC) -Ilibmd5 $(CFLAGS) libmd5\md5.c - -yandytex.res: yandytex.rc - $(RC) /nologo yandytex.rc - -yandytex.obj: yandytex.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) yandytex.c - -itex.obj: itex.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) itex.c - -openinou.obj: openinou.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) openinou.c - -subroute.obj: subroute.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) subroute.c - -local.obj: local.c \ - texd.h yandytex.h memory.h coerce.h macros.h - $(CC) $(CFLAGS) local.c - -tex0.obj: tex0.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex1.obj: tex1.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex2.obj: tex2.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex3.obj: tex3.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex4.obj: tex4.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex5.obj: tex5.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex6.obj: tex6.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex7.obj: tex7.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex8.obj: tex8.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -tex9.obj: tex9.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -pool.obj: pool.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -utils.obj: utils.c \ - texd.h yandytex.h memory.h coerce.h macros.h - -.SUFFIXES: -.SUFFIXES: .obj .c - -c..obj: - $(CC) $(CFLAGS) $*.c - - +# Copyright 2007 TeX Users Group. +# Copyright 2014 Clerk Ma. +# +# You may freely use, modify and/or distribute this file. +# +# Makefile for Y&YTeX (MSVC, tested on VS 2012 and VS 2013) + +CC = cl +LINK = link +RC = rc + +CFLAGS=/nologo /c /MT /GF /Gy /W4 \ + /I"kpathsea" /I"zlib" + +LFLAGS=/NOLOGO /MAP + +objs = yandytex.obj itex.obj openinou.obj subroute.obj local.obj \ + tex0.obj tex1.obj tex2.obj tex3.obj tex4.obj \ + tex5.obj tex6.obj tex7.obj tex8.obj tex9.obj \ + pool.obj yandytex.res utils.obj + +yandytex.exe: $(objs) + $(LINK) $(LFLAGS) yandytex itex openinou subroute local \ + tex0 tex1 tex2 tex3 tex4 tex5 tex6 tex7 tex8 tex9 \ + pool yandytex.res utils \ + kpathsea\kpathsea.lib zlib\zlib.lib + del ..\yandy\bin\yandytex.exe + copy yandytex.exe ..\yandy\bin\yandytex.exe + +yandytex.res: yandytex.rc + $(RC) /nologo yandytex.rc + +yandytex.obj: yandytex.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) yandytex.c + +itex.obj: itex.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) itex.c + +openinou.obj: openinou.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) openinou.c + +subroute.obj: subroute.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) subroute.c + +local.obj: local.c \ + texd.h yandytex.h memory.h coerce.h macros.h + $(CC) $(CFLAGS) local.c + +tex0.obj: tex0.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex1.obj: tex1.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex2.obj: tex2.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex3.obj: tex3.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex4.obj: tex4.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex5.obj: tex5.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex6.obj: tex6.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex7.obj: tex7.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex8.obj: tex8.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +tex9.obj: tex9.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +pool.obj: pool.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +utils.obj: utils.c \ + texd.h yandytex.h memory.h coerce.h macros.h + +.SUFFIXES: +.SUFFIXES: .obj .c + +c..obj: + $(CC) $(CFLAGS) $*.c + + diff --git a/src/texsourc/README b/src/texsourc/README index e6b77aa..e7bbcd3 100644 --- a/src/texsourc/README +++ b/src/texsourc/README @@ -1,2 +1,2 @@ -In this directory, you can found sources of Y&Y TeX which is under -developing in MS-Windows (a Linux port is working now). +In this directory, you can found sources of Y&Y TeX which is under +developing in MS-Windows (a Linux port is working now). diff --git a/src/texsourc/coerce.h b/src/texsourc/coerce.h index ff84f80..86a08b8 100644 --- a/src/texsourc/coerce.h +++ b/src/texsourc/coerce.h @@ -1,418 +1,418 @@ -/* Copyright 2007 TeX Users Group - Copyright 2014 Clerk Ma - - 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -void initialize (void); -void print_ln (void); -void print_char_(ASCII_code s); -#define print_char(s) print_char_((ASCII_code) (s)) -void print_(integer s); -#define print(s) print_((integer) (s)) -void prints_(const char * s); -#define prints(s) prints_((const char *) s) -void slow_print_(integer s); -#define slow_print(s) slow_print_((integer) (s)) -void print_nl (const char * s); -void print_esc (const char * s); -void print_the_digs (eight_bits k); -void print_int_(integer n); -#define print_int(n) print_int_((integer) (n)) -void print_cs_(integer p); -#define print_cs(p) print_cs_((integer) (p)) -void sprint_cs (pointer p); -void print_file_name (integer n, integer a, integer e); -void print_size_(integer s); -#define print_size(s) print_size_((integer) (s)) -void print_write_whatsit_(const char * s, pointer p); -#define print_write_whatsit(s, p) print_write_whatsit_((const char *) (s), (pointer) (p)) -void jump_out (void); -void error (void); -void fatal_error (const char * s); -void overflow_(const char * s, integer n); -#define overflow(s, n) overflow_((const char *) (s), (integer) (n)) -void confusion (const char * s); -boolean init_terminal (void); -str_number make_string (void); -boolean str_eq_buf_(str_number s, integer k); -#define str_eq_buf(s, k) str_eq_buf_((str_number) (s), (integer) (k)) -boolean str_eq_str_(str_number s, str_number t); -#define str_eq_str(s, t) str_eq_str_((str_number) (s), (str_number) (t)) -boolean get_strings_started (void); -void print_two_(integer n); -#define print_two(n) print_two_((integer) (n)) -void print_hex_(integer n); -#define print_hex(n) print_hex_((integer) (n)) -void print_roman_int_(integer n); -#define print_roman_int(n) print_roman_int_((integer) (n)) -void print_current_string (void); -void term_input (void); -void int_error_(integer n); -#define int_error(n) int_error_((integer) (n)) -void normalize_selector (void); -void pause_for_instructions (void); -integer half_(integer x); -#define half(x) half_((integer) (x)) -scaled round_decimals_(small_number k); -#define round_decimals(k) round_decimals_((small_number) (k)) -void print_scaled_(scaled s); -#define print_scaled(s) print_scaled_((scaled) (s)) -scaled mult_and_add_(integer n, scaled x, scaled y, scaled max_answer); -#define mult_and_add(n, x, y, max_answer) mult_and_add_((integer) (n), (scaled) (x), (scaled) (y), (scaled) (max_answer)) -scaled x_over_n_(scaled x, integer n); -#define x_over_n(x, n) x_over_n_((scaled) (x), (integer) (n)) -scaled xn_over_d_(scaled x, integer n, integer d); -#define xn_over_d(x, n, d) xn_over_d_((scaled) (x), (integer) (n), (integer) (d)) -halfword badness_(scaled t, scaled s); -#define badness(t, s) badness_((scaled) (t), (scaled) (s)) -void print_word (memory_word w); -void show_token_list_(integer p, integer q, integer l); -#define show_token_list(p, q, l) show_token_list_((integer) (p), (integer) (q), (integer) (l)) -void runaway (void); -pointer get_avail (void); -void flush_list_(pointer p); -#define flush_list(p) flush_list_((pointer) (p)) -pointer get_node (integer s); -void free_node (pointer p, halfword s); -void sort_avail (void); -pointer new_null_box (void); -pointer new_rule (void); -pointer new_ligature_(quarterword f, quarterword c, pointer q); -#define new_ligature(f, c, q) new_ligature_((quarterword) (f), (quarterword) (c), (pointer) (q)) -pointer new_lig_item_(quarterword c); -#define new_lig_item(c) new_lig_item_((quarterword) (c)) -pointer new_disc (void); -pointer new_math (scaled w, small_number s); -pointer new_spec_(pointer p); -#define new_spec(p) new_spec_((pointer) (p)) -pointer new_param_glue (small_number n); -pointer new_glue (pointer q); -pointer new_skip_param (small_number n); -pointer new_kern (scaled w); -pointer new_penalty (integer m); -void check_mem (boolean print_locs); -void search_mem_(pointer p); -#define search_mem(p) search_mem_((pointer) (p)) -void short_display_(integer p); -#define short_display(p) short_display_((integer) (p)) -void print_font_and_char(integer p); -void print_mark (integer p); -void print_rule_dimen (scaled d); -void print_glue_(scaled d, integer order, const char * s); -#define print_glue(d, order, s) print_glue_((scaled) (d), (integer) (order), (const char *) (s)) -void print_spec_(integer p, const char * s); -#define print_spec(p, s) print_spec_((integer) (p), (const char *) (s)) -void print_fam_and_char_(pointer p); -#define print_fam_and_char(p) print_fam_and_char_((pointer) (p)) -void print_delimiter_(pointer p); -#define print_delimiter(p) print_delimiter_((pointer) (p)) -void print_subsidiary_data_(pointer p, ASCII_code c); -#define print_subsidiary_data(p, c) print_subsidiary_data_((pointer) (p), (ASCII_code) (c)) -void print_style_(integer c); -#define print_style(c) print_style_((integer) (c)) -void print_skip_param_(integer n); -#define print_skip_param(n) print_skip_param_((integer) (n)) -void show_node_list_(integer p); -#define show_node_list(p) show_node_list_((integer) (p)) -void show_box_(pointer p); -#define show_box(p) show_box_((pointer) (p)) -void delete_token_ref_(pointer p); -#define delete_token_ref(p) delete_token_ref_((pointer) (p)) -void delete_glue_ref_(pointer p); -#define delete_glue_ref(p) delete_glue_ref_((pointer) (p)) -void flush_node_list_(pointer p); -#define flush_node_list(p) flush_node_list_((pointer) (p)) -pointer copy_node_list_(pointer p); -#define copy_node_list(p) copy_node_list_((pointer) (p)) -void print_mode_(integer m); -#define print_mode(m) print_mode_((integer) (m)) -void push_nest (void); -void pop_nest (void); -void show_activities (void); -void print_param_(integer n); -#define print_param(n) print_param_((integer) (n)) -void begin_diagnostic (void); -void end_diagnostic (boolean blank_line); -void print_length_param_(integer n); -#define print_length_param(n) print_length_param_((integer) (n)) -void print_cmd_chr_(quarterword cmd, halfword chr_code); -#define print_cmd_chr(cmd, chr_code) print_cmd_chr_((quarterword) (cmd), (halfword) (chr_code)) -void show_eqtb (pointer n); -pointer id_lookup_(integer j, integer l); -#define id_lookup(j, l) id_lookup_((integer) (j), (integer) (l)) -void primitive_(str_number s, quarterword c, halfword o); -#define primitive(s, c, o) primitive_(make_string_pool((const char *) s), (quarterword) (c), (halfword) (o)) -void new_save_level (group_code c); -void eq_destroy (memory_word w); -void eq_save (pointer p, quarterword l); -void eq_define_(pointer p, quarterword t, halfword e); -#define eq_define(p, t, e) eq_define_((pointer) (p), (quarterword) (t), (halfword) (e)) -void eq_word_define_(pointer p, integer w); -#define eq_word_define(p, w) eq_word_define_((pointer) (p), (integer) (w)) -void geq_define_(pointer p, quarterword t, halfword e); -#define geq_define(p, t, e) geq_define_((pointer) (p), (quarterword) (t), (halfword) (e)) -void geq_word_define_(pointer p, integer w); -#define geq_word_define(p, w) geq_word_define_((pointer) (p), (integer) (w)) -void save_for_after (halfword t); -void restore_trace (pointer p, const char * s); -void unsave (void); -void prepare_mag (void); -void token_show (pointer p); -void print_meaning (void); -void show_cur_cmd_chr (void); -void show_context (void); -void begin_token_list_(pointer p, quarterword t); -#define begin_token_list(p, t) begin_token_list_((pointer) (p), (quarterword) (t)) -void end_token_list (void); -void back_input (void); -void back_error (void); -void ins_error (void); -void begin_file_reading (void); -void end_file_reading (void); -void clear_for_error_prompt (void); -void check_outer_validity (void); -void get_next (void); -void firm_up_the_line (void); -void get_token (void); -void macro_call (void); -void insert_relax (void); -void expand (void); -void get_x_token (void); -void x_token (void); -void scan_left_brace (void); -void scan_optional_equals (void); -boolean scan_keyword (const char * s); -void mu_error (void); -void scan_eight_bit_int (void); -void scan_char_num (void); -void scan_four_bit_int (void); -void scan_fifteen_bit_int (void); -void scan_twenty_seven_bit_int (void); -void scan_font_ident (void); -void find_font_dimen (boolean writing); -void scan_something_internal (small_number level, boolean negative); -void scan_int (void); -void scan_dimen (boolean mu, boolean inf, boolean shortcut); -void scan_glue (small_number level); -pointer scan_rule_spec (void); -pointer str_toks (pool_pointer b); -pointer the_toks (void); -void ins_the_toks (void); -void conv_toks (void); -pointer scan_toks (boolean macro_def, boolean xpand); -void read_toks (integer n, pointer r); -void pass_text (void); -void change_if_limit (small_number l, pointer p); -void conditional (void); -void begin_name (void); -boolean more_name (ASCII_code c); -void end_name (void); -void pack_file_name (str_number n, str_number a, str_number e); -void pack_buffered_name_(small_number n, integer a, integer b); -#define pack_buffered_name(n, a, b) pack_buffered_name_((small_number) (n), (integer) (a), (integer) (b)) -str_number make_name_string (void); -str_number a_make_name_string_(void); -#define a_make_name_string(f) a_make_name_string_() -str_number b_make_name_string_(void); -#define b_make_name_string(f) b_make_name_string_() -str_number w_make_name_string_(void); -#define w_make_name_string(f) w_make_name_string_() -void scan_file_name (void); -void pack_job_name_(str_number s); -#define pack_job_name(s) pack_job_name_(make_string_pool((const char *) (s))) -void prompt_file_name_(const char * s, str_number e); -#define prompt_file_name(s, e) prompt_file_name_((const char *) s, make_string_pool((const char*) e)) -void open_log_file (void); -void start_input (void); -internal_font_number read_font_info (pointer u, str_number nom, str_number arie, scaled s); -void char_warning_(internal_font_number f, eight_bits c); -#define char_warning(f, c) char_warning_((internal_font_number) (f), (eight_bits) (c)) -pointer new_character_(internal_font_number f, eight_bits c); -#define new_character(f, c) new_character_((internal_font_number) (f), (eight_bits) (c)) -void dvi_swap (void); -void dvi_four_(integer x); -#define dvi_four(x) dvi_four_((integer) (x)) -void dvi_pop_(integer l); -#define dvi_pop(l) dvi_pop_((integer) (l)) -void dvi_font_def (internal_font_number f); -void movement (scaled w, eight_bits o); -void special_out (pointer p); -void hlist_out (void); -void vlist_out (void); -void pdf_ship_out (pointer p); -void ship_out (pointer p); -void prune_movements (integer l); -void write_out (pointer p); -void out_what (pointer p); -void scan_spec (group_code c, boolean three_codes); -pointer hpack_(pointer p, scaled w, small_number m); -#define hpack(p, w, m) hpack_((pointer) (p), (scaled) (w), (small_number) (m)) -pointer vpackage_(pointer p, scaled h, small_number m, scaled l); -#define vpackage(p, h, m, l) vpackage_((pointer) (p), (scaled) (h), (small_number) (m), (scaled) (l)) -void append_to_vlist (pointer b); -pointer new_noad (void); -pointer new_style (small_number s); -pointer new_choice (void); -void show_info (void); -pointer fraction_rule (scaled t); -pointer overbar (pointer b, scaled k, scaled t); -pointer char_box (internal_font_number f, quarterword c); -void stack_into_box (pointer b, internal_font_number f, quarterword c); -scaled height_plus_depth (internal_font_number f, quarterword c); -pointer var_delimiter (pointer d, small_number s, scaled v); -pointer rebox (pointer b, scaled w); -pointer math_glue (pointer g, scaled m); -void math_kern (pointer p, scaled m); -void flush_math (void); -pointer clean_box (pointer p, small_number s); -void fetch (pointer a); -void make_over (pointer q); -void make_under (pointer q); -void make_vcenter (pointer q); -void make_radical (pointer q); -void make_math_accent (pointer q); -void make_fraction (pointer q); -scaled make_op (pointer q); -void make_ord (pointer q); -void make_scripts (pointer q, scaled delta); -small_number make_left_right (pointer q, small_number style, scaled max_d, scaled max_h); -void mlist_to_hlist (void); -void push_alignment (void); -void pop_alignment (void); -void get_preamble_token (void); -void init_align (void); -void init_span (pointer p); -void init_row (void); -void init_col (void); -boolean fin_col (void); -void fin_row (void); -void fin_align (void); -void align_peek (void); -pointer finite_shrink (pointer p); -void try_break (integer pi, small_number breaktype); -void post_line_break (integer final_widow_penalty); -small_number reconstitute (small_number j, small_number n, halfword bchar, halfword hchar); -void hyphenate (void); -trie_op_code new_trie_op (small_number d, small_number n, trie_op_code v); -trie_pointer trie_node (trie_pointer p); -trie_pointer compress_trie (trie_pointer p); -void first_fit (trie_pointer p); -void trie_pack (trie_pointer p); -void trie_fix (trie_pointer p); -void new_patterns (void); -void init_trie (void); -void line_break (integer final_widow_penalty); -void new_hyph_exceptions (void); -pointer prune_page_top (pointer p); -pointer vert_break (pointer p, scaled h, scaled d); -pointer vsplit (eight_bits n, scaled h); -void print_totals (void); -void freeze_page_specs (small_number s); -void box_error (eight_bits n); -void ensure_vbox_(eight_bits n); -#define ensure_vbox(n) ensure_vbox_((eight_bits) (n)) -void fire_up (pointer c); -void build_page (void); -void app_space (void); -void insert_dollar_sign (void); -void you_cant (void); -void report_illegal_case (void); -boolean privileged (void); -boolean its_all_over (void); -void append_glue (void); -void append_kern (void); -void off_save (void); -void extra_right_brace (void); -void normal_paragraph (void); -void box_end (integer box_content); -void begin_box (integer box_content); -void scan_box_(integer box_content); -#define scan_box(box_context) scan_box_((integer) (box_context)) -void package (small_number c); -small_number norm_min (integer h); -void new_graf (boolean indented); -void indent_in_hmode (void); -void head_for_vmode (void); -void end_graf (void); -void begin_insert_or_adjust (void); -void make_mark (void); -void append_penalty (void); -void delete_last (void); -void unpackage (void); -void append_italic_correction (void); -void append_discretionary (void); -void build_discretionary (void); -void make_accent (void); -void align_error (void); -void noalign_error (void); -void omit_error (void); -void do_endv (void); -void cs_error (void); -void push_math (group_code c); -void init_math (void); -void start_eq_no (void); -void scan_math (pointer p); -void set_math_char_(integer c); -#define set_math_char(c) set_math_char_((integer) (c)) -void math_limit_switch(void); -void scan_delimiter_(pointer p, boolean r); -#define scan_delimiter(p, r) scan_delimiter_((pointer) (p), (boolean) (r)) -void math_radical (void); -void math_ac (void); -void append_choices (void); -pointer fin_mlist (pointer p); -void build_choices (void); -void sub_sup (void); -void math_fraction (void); -void math_left_right (void); -void after_math (void); -void resume_after_display (void); -void get_r_token (void); -void trap_zero_glue (void); -void do_register_command (small_number a); -void alter_aux (void); -void alter_prev_graf (void); -void alter_page_so_far (void); -void alter_integer (void); -void alter_box_dimen (void); -void new_font (small_number a); -void new_interaction (void); -void prefixed_command (void); -void do_assignments (void); -void open_or_close_in (void); -void issue_message (void); -void shift_case (void); -void show_whatever (void); -void store_fmt_file (void); -void new_whatsit_(small_number s, small_number w); -#define new_whatsit(s, w) new_whatsit_((small_number) (s), (small_number) (w)) -void new_write_whatsit (small_number w); -void do_extension (void); -void fix_language (void); -void handle_right_brace (void); -void main_control (void); -void give_err_help (void); -boolean open_fmt_file (void); -boolean load_fmt_file (void); -void close_files_and_terminate (void); -void final_cleanup (void); -void init_prim (void); -void debug_help (void); -void fix_date_and_time (void); -void print_banner (void); - -int main_program (void); +/* Copyright 2007 TeX Users Group + Copyright 2014 Clerk Ma + + 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ + +void initialize (void); +void print_ln (void); +void print_char_(ASCII_code s); +#define print_char(s) print_char_((ASCII_code) (s)) +void print_(integer s); +#define print(s) print_((integer) (s)) +void prints_(const char * s); +#define prints(s) prints_((const char *) s) +void slow_print_(integer s); +#define slow_print(s) slow_print_((integer) (s)) +void print_nl (const char * s); +void print_esc (const char * s); +void print_the_digs (eight_bits k); +void print_int_(integer n); +#define print_int(n) print_int_((integer) (n)) +void print_cs_(integer p); +#define print_cs(p) print_cs_((integer) (p)) +void sprint_cs (pointer p); +void print_file_name (integer n, integer a, integer e); +void print_size_(integer s); +#define print_size(s) print_size_((integer) (s)) +void print_write_whatsit_(const char * s, pointer p); +#define print_write_whatsit(s, p) print_write_whatsit_((const char *) (s), (pointer) (p)) +void jump_out (void); +void error (void); +void fatal_error (const char * s); +void overflow_(const char * s, integer n); +#define overflow(s, n) overflow_((const char *) (s), (integer) (n)) +void confusion (const char * s); +boolean init_terminal (void); +str_number make_string (void); +boolean str_eq_buf_(str_number s, integer k); +#define str_eq_buf(s, k) str_eq_buf_((str_number) (s), (integer) (k)) +boolean str_eq_str_(str_number s, str_number t); +#define str_eq_str(s, t) str_eq_str_((str_number) (s), (str_number) (t)) +boolean get_strings_started (void); +void print_two_(integer n); +#define print_two(n) print_two_((integer) (n)) +void print_hex_(integer n); +#define print_hex(n) print_hex_((integer) (n)) +void print_roman_int_(integer n); +#define print_roman_int(n) print_roman_int_((integer) (n)) +void print_current_string (void); +void term_input (void); +void int_error_(integer n); +#define int_error(n) int_error_((integer) (n)) +void normalize_selector (void); +void pause_for_instructions (void); +integer half_(integer x); +#define half(x) half_((integer) (x)) +scaled round_decimals_(small_number k); +#define round_decimals(k) round_decimals_((small_number) (k)) +void print_scaled_(scaled s); +#define print_scaled(s) print_scaled_((scaled) (s)) +scaled mult_and_add_(integer n, scaled x, scaled y, scaled max_answer); +#define mult_and_add(n, x, y, max_answer) mult_and_add_((integer) (n), (scaled) (x), (scaled) (y), (scaled) (max_answer)) +scaled x_over_n_(scaled x, integer n); +#define x_over_n(x, n) x_over_n_((scaled) (x), (integer) (n)) +scaled xn_over_d_(scaled x, integer n, integer d); +#define xn_over_d(x, n, d) xn_over_d_((scaled) (x), (integer) (n), (integer) (d)) +halfword badness_(scaled t, scaled s); +#define badness(t, s) badness_((scaled) (t), (scaled) (s)) +void print_word (memory_word w); +void show_token_list_(integer p, integer q, integer l); +#define show_token_list(p, q, l) show_token_list_((integer) (p), (integer) (q), (integer) (l)) +void runaway (void); +pointer get_avail (void); +void flush_list_(pointer p); +#define flush_list(p) flush_list_((pointer) (p)) +pointer get_node (integer s); +void free_node (pointer p, halfword s); +void sort_avail (void); +pointer new_null_box (void); +pointer new_rule (void); +pointer new_ligature_(quarterword f, quarterword c, pointer q); +#define new_ligature(f, c, q) new_ligature_((quarterword) (f), (quarterword) (c), (pointer) (q)) +pointer new_lig_item_(quarterword c); +#define new_lig_item(c) new_lig_item_((quarterword) (c)) +pointer new_disc (void); +pointer new_math (scaled w, small_number s); +pointer new_spec_(pointer p); +#define new_spec(p) new_spec_((pointer) (p)) +pointer new_param_glue (small_number n); +pointer new_glue (pointer q); +pointer new_skip_param (small_number n); +pointer new_kern (scaled w); +pointer new_penalty (integer m); +void check_mem (boolean print_locs); +void search_mem_(pointer p); +#define search_mem(p) search_mem_((pointer) (p)) +void short_display_(integer p); +#define short_display(p) short_display_((integer) (p)) +void print_font_and_char(integer p); +void print_mark (integer p); +void print_rule_dimen (scaled d); +void print_glue_(scaled d, integer order, const char * s); +#define print_glue(d, order, s) print_glue_((scaled) (d), (integer) (order), (const char *) (s)) +void print_spec_(integer p, const char * s); +#define print_spec(p, s) print_spec_((integer) (p), (const char *) (s)) +void print_fam_and_char_(pointer p); +#define print_fam_and_char(p) print_fam_and_char_((pointer) (p)) +void print_delimiter_(pointer p); +#define print_delimiter(p) print_delimiter_((pointer) (p)) +void print_subsidiary_data_(pointer p, ASCII_code c); +#define print_subsidiary_data(p, c) print_subsidiary_data_((pointer) (p), (ASCII_code) (c)) +void print_style_(integer c); +#define print_style(c) print_style_((integer) (c)) +void print_skip_param_(integer n); +#define print_skip_param(n) print_skip_param_((integer) (n)) +void show_node_list_(integer p); +#define show_node_list(p) show_node_list_((integer) (p)) +void show_box_(pointer p); +#define show_box(p) show_box_((pointer) (p)) +void delete_token_ref_(pointer p); +#define delete_token_ref(p) delete_token_ref_((pointer) (p)) +void delete_glue_ref_(pointer p); +#define delete_glue_ref(p) delete_glue_ref_((pointer) (p)) +void flush_node_list_(pointer p); +#define flush_node_list(p) flush_node_list_((pointer) (p)) +pointer copy_node_list_(pointer p); +#define copy_node_list(p) copy_node_list_((pointer) (p)) +void print_mode_(integer m); +#define print_mode(m) print_mode_((integer) (m)) +void push_nest (void); +void pop_nest (void); +void show_activities (void); +void print_param_(integer n); +#define print_param(n) print_param_((integer) (n)) +void begin_diagnostic (void); +void end_diagnostic (boolean blank_line); +void print_length_param_(integer n); +#define print_length_param(n) print_length_param_((integer) (n)) +void print_cmd_chr_(quarterword cmd, halfword chr_code); +#define print_cmd_chr(cmd, chr_code) print_cmd_chr_((quarterword) (cmd), (halfword) (chr_code)) +void show_eqtb (pointer n); +pointer id_lookup_(integer j, integer l); +#define id_lookup(j, l) id_lookup_((integer) (j), (integer) (l)) +void primitive_(str_number s, quarterword c, halfword o); +#define primitive(s, c, o) primitive_(make_string_pool((const char *) s), (quarterword) (c), (halfword) (o)) +void new_save_level (group_code c); +void eq_destroy (memory_word w); +void eq_save (pointer p, quarterword l); +void eq_define_(pointer p, quarterword t, halfword e); +#define eq_define(p, t, e) eq_define_((pointer) (p), (quarterword) (t), (halfword) (e)) +void eq_word_define_(pointer p, integer w); +#define eq_word_define(p, w) eq_word_define_((pointer) (p), (integer) (w)) +void geq_define_(pointer p, quarterword t, halfword e); +#define geq_define(p, t, e) geq_define_((pointer) (p), (quarterword) (t), (halfword) (e)) +void geq_word_define_(pointer p, integer w); +#define geq_word_define(p, w) geq_word_define_((pointer) (p), (integer) (w)) +void save_for_after (halfword t); +void restore_trace (pointer p, const char * s); +void unsave (void); +void prepare_mag (void); +void token_show (pointer p); +void print_meaning (void); +void show_cur_cmd_chr (void); +void show_context (void); +void begin_token_list_(pointer p, quarterword t); +#define begin_token_list(p, t) begin_token_list_((pointer) (p), (quarterword) (t)) +void end_token_list (void); +void back_input (void); +void back_error (void); +void ins_error (void); +void begin_file_reading (void); +void end_file_reading (void); +void clear_for_error_prompt (void); +void check_outer_validity (void); +void get_next (void); +void firm_up_the_line (void); +void get_token (void); +void macro_call (void); +void insert_relax (void); +void expand (void); +void get_x_token (void); +void x_token (void); +void scan_left_brace (void); +void scan_optional_equals (void); +boolean scan_keyword (const char * s); +void mu_error (void); +void scan_eight_bit_int (void); +void scan_char_num (void); +void scan_four_bit_int (void); +void scan_fifteen_bit_int (void); +void scan_twenty_seven_bit_int (void); +void scan_font_ident (void); +void find_font_dimen (boolean writing); +void scan_something_internal (small_number level, boolean negative); +void scan_int (void); +void scan_dimen (boolean mu, boolean inf, boolean shortcut); +void scan_glue (small_number level); +pointer scan_rule_spec (void); +pointer str_toks (pool_pointer b); +pointer the_toks (void); +void ins_the_toks (void); +void conv_toks (void); +pointer scan_toks (boolean macro_def, boolean xpand); +void read_toks (integer n, pointer r); +void pass_text (void); +void change_if_limit (small_number l, pointer p); +void conditional (void); +void begin_name (void); +boolean more_name (ASCII_code c); +void end_name (void); +void pack_file_name (str_number n, str_number a, str_number e); +void pack_buffered_name_(small_number n, integer a, integer b); +#define pack_buffered_name(n, a, b) pack_buffered_name_((small_number) (n), (integer) (a), (integer) (b)) +str_number make_name_string (void); +str_number a_make_name_string_(void); +#define a_make_name_string(f) a_make_name_string_() +str_number b_make_name_string_(void); +#define b_make_name_string(f) b_make_name_string_() +str_number w_make_name_string_(void); +#define w_make_name_string(f) w_make_name_string_() +void scan_file_name (void); +void pack_job_name_(str_number s); +#define pack_job_name(s) pack_job_name_(make_string_pool((const char *) (s))) +void prompt_file_name_(const char * s, str_number e); +#define prompt_file_name(s, e) prompt_file_name_((const char *) s, make_string_pool((const char*) e)) +void open_log_file (void); +void start_input (void); +internal_font_number read_font_info (pointer u, str_number nom, str_number arie, scaled s); +void char_warning_(internal_font_number f, eight_bits c); +#define char_warning(f, c) char_warning_((internal_font_number) (f), (eight_bits) (c)) +pointer new_character_(internal_font_number f, eight_bits c); +#define new_character(f, c) new_character_((internal_font_number) (f), (eight_bits) (c)) +void dvi_swap (void); +void dvi_four_(integer x); +#define dvi_four(x) dvi_four_((integer) (x)) +void dvi_pop_(integer l); +#define dvi_pop(l) dvi_pop_((integer) (l)) +void dvi_font_def (internal_font_number f); +void movement (scaled w, eight_bits o); +void special_out (pointer p); +void hlist_out (void); +void vlist_out (void); +void pdf_ship_out (pointer p); +void ship_out (pointer p); +void prune_movements (integer l); +void write_out (pointer p); +void out_what (pointer p); +void scan_spec (group_code c, boolean three_codes); +pointer hpack_(pointer p, scaled w, small_number m); +#define hpack(p, w, m) hpack_((pointer) (p), (scaled) (w), (small_number) (m)) +pointer vpackage_(pointer p, scaled h, small_number m, scaled l); +#define vpackage(p, h, m, l) vpackage_((pointer) (p), (scaled) (h), (small_number) (m), (scaled) (l)) +void append_to_vlist (pointer b); +pointer new_noad (void); +pointer new_style (small_number s); +pointer new_choice (void); +void show_info (void); +pointer fraction_rule (scaled t); +pointer overbar (pointer b, scaled k, scaled t); +pointer char_box (internal_font_number f, quarterword c); +void stack_into_box (pointer b, internal_font_number f, quarterword c); +scaled height_plus_depth (internal_font_number f, quarterword c); +pointer var_delimiter (pointer d, small_number s, scaled v); +pointer rebox (pointer b, scaled w); +pointer math_glue (pointer g, scaled m); +void math_kern (pointer p, scaled m); +void flush_math (void); +pointer clean_box (pointer p, small_number s); +void fetch (pointer a); +void make_over (pointer q); +void make_under (pointer q); +void make_vcenter (pointer q); +void make_radical (pointer q); +void make_math_accent (pointer q); +void make_fraction (pointer q); +scaled make_op (pointer q); +void make_ord (pointer q); +void make_scripts (pointer q, scaled delta); +small_number make_left_right (pointer q, small_number style, scaled max_d, scaled max_h); +void mlist_to_hlist (void); +void push_alignment (void); +void pop_alignment (void); +void get_preamble_token (void); +void init_align (void); +void init_span (pointer p); +void init_row (void); +void init_col (void); +boolean fin_col (void); +void fin_row (void); +void fin_align (void); +void align_peek (void); +pointer finite_shrink (pointer p); +void try_break (integer pi, small_number breaktype); +void post_line_break (integer final_widow_penalty); +small_number reconstitute (small_number j, small_number n, halfword bchar, halfword hchar); +void hyphenate (void); +trie_op_code new_trie_op (small_number d, small_number n, trie_op_code v); +trie_pointer trie_node (trie_pointer p); +trie_pointer compress_trie (trie_pointer p); +void first_fit (trie_pointer p); +void trie_pack (trie_pointer p); +void trie_fix (trie_pointer p); +void new_patterns (void); +void init_trie (void); +void line_break (integer final_widow_penalty); +void new_hyph_exceptions (void); +pointer prune_page_top (pointer p); +pointer vert_break (pointer p, scaled h, scaled d); +pointer vsplit (eight_bits n, scaled h); +void print_totals (void); +void freeze_page_specs (small_number s); +void box_error (eight_bits n); +void ensure_vbox_(eight_bits n); +#define ensure_vbox(n) ensure_vbox_((eight_bits) (n)) +void fire_up (pointer c); +void build_page (void); +void app_space (void); +void insert_dollar_sign (void); +void you_cant (void); +void report_illegal_case (void); +boolean privileged (void); +boolean its_all_over (void); +void append_glue (void); +void append_kern (void); +void off_save (void); +void extra_right_brace (void); +void normal_paragraph (void); +void box_end (integer box_content); +void begin_box (integer box_content); +void scan_box_(integer box_content); +#define scan_box(box_context) scan_box_((integer) (box_context)) +void package (small_number c); +small_number norm_min (integer h); +void new_graf (boolean indented); +void indent_in_hmode (void); +void head_for_vmode (void); +void end_graf (void); +void begin_insert_or_adjust (void); +void make_mark (void); +void append_penalty (void); +void delete_last (void); +void unpackage (void); +void append_italic_correction (void); +void append_discretionary (void); +void build_discretionary (void); +void make_accent (void); +void align_error (void); +void noalign_error (void); +void omit_error (void); +void do_endv (void); +void cs_error (void); +void push_math (group_code c); +void init_math (void); +void start_eq_no (void); +void scan_math (pointer p); +void set_math_char_(integer c); +#define set_math_char(c) set_math_char_((integer) (c)) +void math_limit_switch(void); +void scan_delimiter_(pointer p, boolean r); +#define scan_delimiter(p, r) scan_delimiter_((pointer) (p), (boolean) (r)) +void math_radical (void); +void math_ac (void); +void append_choices (void); +pointer fin_mlist (pointer p); +void build_choices (void); +void sub_sup (void); +void math_fraction (void); +void math_left_right (void); +void after_math (void); +void resume_after_display (void); +void get_r_token (void); +void trap_zero_glue (void); +void do_register_command (small_number a); +void alter_aux (void); +void alter_prev_graf (void); +void alter_page_so_far (void); +void alter_integer (void); +void alter_box_dimen (void); +void new_font (small_number a); +void new_interaction (void); +void prefixed_command (void); +void do_assignments (void); +void open_or_close_in (void); +void issue_message (void); +void shift_case (void); +void show_whatever (void); +void store_fmt_file (void); +void new_whatsit_(small_number s, small_number w); +#define new_whatsit(s, w) new_whatsit_((small_number) (s), (small_number) (w)) +void new_write_whatsit (small_number w); +void do_extension (void); +void fix_language (void); +void handle_right_brace (void); +void main_control (void); +void give_err_help (void); +boolean open_fmt_file (void); +boolean load_fmt_file (void); +void close_files_and_terminate (void); +void final_cleanup (void); +void init_prim (void); +void debug_help (void); +void fix_date_and_time (void); +void print_banner (void); + +int main_program (void); int main_init (int ac, char ** av); \ No newline at end of file diff --git a/src/texsourc/dpx.c b/src/texsourc/dpx.c index e087ba9..e344911 100644 --- a/src/texsourc/dpx.c +++ b/src/texsourc/dpx.c @@ -1,711 +1,708 @@ -/* Copyright 2014 Clerk Ma - - 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -/* Y&Y TeX's DVIPDFMX backend. */ - -#define EXTERN extern - -#include "yandytex.h" - -void ensure_pdf_open(void) -{ - if (output_file_name == 0) - { - if (job_name == 0) - open_log_file(); - - pack_job_name(".pdf"); - - while (!b_open_out(pdf_file)) - prompt_file_name("file name for output", ".pdf"); - - output_file_name = b_make_name_string(pdf_file); - } -} - -extern void pdf_set_version(unsigned version); -extern void pdf_set_compression(int level); -extern void pdf_doc_set_creator(const char * creator); -extern void pdf_files_init(void); -extern void pdf_init_device(double dvi2pts, int precision, int black_and_white); -extern void pdf_open_document(const char *filename, - int do_encryption, - double media_width, double media_height, - double annot_grow_amount, int bookmark_open_depth, - int check_gotos); -extern void pdf_doc_begin_page(double scale, double x_origin, double y_origin); -extern void pdf_doc_end_page(void); -extern int spc_exec_at_begin_document(void); -extern int spc_exec_at_end_document(void); -extern int spc_exec_at_begin_page(void); -extern int spc_exec_at_end_page(void); -extern void read_config_file (const char *config); -extern void pdf_hlist_out (void); -extern void pdf_vlist_out (void); - -void pdf_ship_out (pointer p) -{ - integer page_loc; - char j, k; - pool_pointer s; - char old_setting; - - if (tracing_output > 0) - { - print_nl(""); - print_ln(); - prints("Completed box being shipped out"); - } - - if (term_offset > max_print_line - 9) - print_ln(); - else if ((term_offset > 0) || (file_offset > 0)) - print_char(' '); - - print_char('['); - j = 9; - - while ((count(j) == 0) && (j > 0)) - decr(j); - - for (k = 0; k <= j; k++) - { - print_int(count(k)); - - if (k < j) - print_char('.'); - } - - update_terminal(); - - if (tracing_output > 0) - { - print_char(']'); - begin_diagnostic(); - show_box(p); - end_diagnostic(true); - } - - if ((height(p) > max_dimen) || (depth(p) > max_dimen) || - (height(p) + depth(p) + v_offset > max_dimen) || - (width(p) + h_offset > max_dimen)) - { - print_err("Huge page cannot be shipped out"); - help2("The page just created is more than 18 feet tall or", - "more than 18 feet wide, so I suspect something went wrong."); - error(); - - if (tracing_output <= 0) - { - begin_diagnostic(); - print_nl("The following box has been deleted:"); - show_box(p); - end_diagnostic(true); - } - - goto done; - } - - if (height(p) + depth(p) + v_offset > max_v) - max_v = height(p) + depth(p) + v_offset; - - if (width(p) + h_offset > max_h) - max_h = width(p) + h_offset; - - dvi_h = 0; - dvi_v = 0; - cur_h = h_offset; - dvi_f = null_font; - ensure_pdf_open(); - - if (total_pages == 0) - { - //kpse_init_prog("", 600, NULL, NULL); - //kpse_set_program_enabled(kpse_pk_format, true, kpse_src_texmf_cnf); - //pdf_font_set_dpi(600); - //dpx_delete_old_cache(image_cache_life); - pdf_set_version(5); - pdf_set_compression(9); - pdf_init_fontmaps(); - read_config_file("dvipdfmx.cfg"); - pdf_doc_set_producer("Y&YTeX 2.3.0"); - pdf_doc_set_creator("TeX"); - pdf_files_init(); - pdf_init_device(0.000015202, 2, 0); - // 0.000015259 1/65535 - // 0.000152018 - pdf_open_document(pdf_file_name, 0, 595.0, 842.0, 0, 0, (1 << 4)); - //pdf_open_document(pdf_file_name, 0, 595.0 * 65535, 842.0 * 65535, 0, 0, (1 << 4)); - spc_exec_at_begin_document(); - } - - page_loc = dvi_offset + dvi_ptr; - pdf_doc_begin_page(1.0, 72.0, 770.0); - spc_exec_at_begin_page(); - - last_bop = page_loc; - cur_v = height(p) + v_offset; - temp_ptr = p; - - if (type(p) == vlist_node) - pdf_vlist_out(); - else - pdf_hlist_out(); - - spc_exec_at_end_page(); - pdf_doc_end_page(); - incr(total_pages); - cur_s = -1; - -done: - if (tracing_output <= 0) - print_char(']'); - - dead_cycles = 0; - update_terminal(); - -#ifdef STAT - if (tracing_stats > 1) - { - print_nl("Memory usage before: "); - print_int(var_used); - print_char('&'); - print_int(dyn_used); - print_char(';'); - } -#endif - - flush_node_list(p); - -#ifdef STAT - if (tracing_stats > 1) - { - prints(" after: "); - print_int(var_used); - print_char('&'); - print_int(dyn_used); - prints("; still utouched: "); - print_int(hi_mem_min - lo_mem_max - 1); - print_ln(); - } -#endif -} - -void pdf_synch_h (void) -{ - if (cur_h != dvi_h) - dvi_h = cur_h; -} - -void pdf_synch_v (void) -{ - if (cur_v != dvi_v) - dvi_v = cur_v; -} - -int pdf_get_font_id (internal_font_number f) -{ - char * sbuf = malloc(length(font_name[f]) + 1); - int id; - memset(sbuf, 0, length(font_name[f]) + 1); - memcpy(sbuf, str_pool + str_start[font_name[f]], length(font_name[f])); - id = dvi_locate_font(sbuf, font_size[f]); - free(sbuf); - - return id; -} - -void pdf_hlist_out (void) -{ - scaled base_line; - scaled left_edge; - scaled save_h, save_v; - pointer this_box; - // glue_ord g_order; - int g_order; - // char g_sign; - int g_sign; - pointer p; - integer save_loc; - pointer leader_box; - scaled leader_wd; - scaled lx; - boolean outer_doing_leaders; - scaled edge; - real glue_temp; - real cur_glue; - scaled cur_g; - - cur_g = 0; - cur_glue = 0.0; - this_box = temp_ptr; - g_order = glue_order(this_box); - g_sign = glue_sign(this_box); - p = list_ptr(this_box); - incr(cur_s); - - if (cur_s > max_push) - max_push = cur_s; - - save_loc = dvi_offset + dvi_ptr; - base_line = cur_v; - left_edge = cur_h; - - while (p != 0) -reswitch: - if (is_char_node(p)) - { - pdf_synch_h(); - pdf_synch_v(); - - do - { - f = font(p); - c = character(p); - - if (f != dvi_f) - { - if (!font_used[f]) - { - font_used[f] = true; - font_id[f] = pdf_get_font_id(f); - } - - dvi_f = f; - } - - char cbuf[2] = {c, 0}; - pdf_dev_set_string(cur_h, -cur_v, cbuf, 1, char_width(f, char_info(f, c)), font_id[dvi_f], 1); - cur_h = cur_h + char_width(f, char_info(f, c)); - p = link(p); - } while (!(!is_char_node(p))); - - dvi_h = cur_h; - } - else - { - switch (type(p)) - { - case hlist_node: - case vlist_node: - if (list_ptr(p) == 0) - cur_h = cur_h + width(p); - else - { - save_h = dvi_h; - save_v = dvi_v; - cur_v = base_line + shift_amount(p); - temp_ptr = p; - edge = cur_h; - - if (type(p) == vlist_node) - pdf_vlist_out(); - else - pdf_hlist_out(); - - dvi_h = save_h; - dvi_v = save_v; - cur_h = edge + width(p); - cur_v = base_line; - } - break; - - case rule_node: - { - rule_ht = height(p); - rule_dp = depth(p); - rule_wd = width(p); - goto fin_rule; - } - break; - - case whatsit_node: - out_what(p); - break; - - case glue_node: - { - g = glue_ptr(p); - rule_wd = width(g) - cur_g; - - if (g_sign != normal) - { - if (g_sign == stretching) - { - if (stretch_order(g) == g_order) - { - cur_glue = cur_glue + stretch(g); - vet_glue(glue_set(this_box) * cur_glue); - cur_g = round(glue_temp); - } - } - else if (shrink_order(g) == g_order) - { - cur_glue = cur_glue - shrink(g); - vet_glue(glue_set(this_box) * cur_glue); - cur_g = round(glue_temp); - } - } - - rule_wd = rule_wd + cur_g; - - if (subtype(p) >= a_leaders) - { - leader_box = leader_ptr(p); - - if (type(leader_box) == rule_node) - { - rule_ht = height(leader_box); - rule_dp = depth(leader_box); - goto fin_rule; - } - - leader_wd = width(leader_box); - - if ((leader_wd > 0) && (rule_wd > 0)) - { - rule_wd = rule_wd + 10; - edge = cur_h + rule_wd; - lx = 0; - - if (subtype(p) == a_leaders) - { - save_h = cur_h; - cur_h = left_edge + leader_wd * ((cur_h - left_edge) / leader_wd); - - if (cur_h < save_h) - cur_h = cur_h + leader_wd; - } - else - { - lq = rule_wd / leader_wd; - lr = rule_wd % leader_wd; - - if (subtype(p) == c_leaders) - cur_h = cur_h + (lr / 2); - else - { - lx = (2 * lr + lq + 1) / (2 * lq + 2); - cur_h = cur_h + ((lr - (lq - 1)* lx) / 2); - } - } - - while (cur_h + leader_wd <= edge) - { - cur_v = base_line + shift_amount(leader_box); - pdf_synch_v(); - save_v = dvi_v; - pdf_synch_h(); - save_h = dvi_h; - temp_ptr = leader_box; - outer_doing_leaders = doing_leaders; - doing_leaders = true; - - if (type(leader_box) == vlist_node) - pdf_vlist_out(); - else - pdf_hlist_out(); - - doing_leaders = outer_doing_leaders; - dvi_v = save_v; - dvi_h = save_h; - cur_v = base_line; - cur_h = save_h + leader_wd + lx; - } - - cur_h = edge - 10; - goto next_p; - } - } - - goto move_past; - } - break; - - case kern_node: - case math_node: - cur_h = cur_h + width(p); - break; - - case ligature_node: - { - mem[lig_trick] = mem[lig_char(p)]; - link(lig_trick) = link(p); - p = lig_trick; - goto reswitch; - } - break; - - default: - break; - } - - goto next_p; - -fin_rule: - if (is_running(rule_ht)) - rule_ht = height(this_box); - - if (is_running(rule_dp)) - rule_dp = depth(this_box); - - rule_ht = rule_ht + rule_dp; - - if ((rule_ht > 0) && (rule_wd > 0)) - { - pdf_synch_h(); - cur_v = base_line + rule_dp; - pdf_synch_v(); - pdf_dev_set_rule(dvi_h, dvi_v, rule_wd, rule_ht); - cur_v = base_line; - dvi_h = dvi_h + rule_wd; - } - -move_past: - cur_h = cur_h + rule_wd; - -next_p: - p = link(p); - } - - prune_movements(save_loc); - decr(cur_s); -} - -void pdf_vlist_out (void) -{ - scaled left_edge; - scaled top_edge; - scaled save_h, save_v; - pointer this_box; - // glue_ord g_order; - int g_order; - // char g_sign; - int g_sign; - pointer p; - integer save_loc; - pointer leader_box; - scaled leader_ht; - scaled lx; - boolean outer_doing_leaders; - scaled edge; - real glue_temp; - real cur_glue; - scaled cur_g; - - cur_g = 0; - cur_glue = 0.0; - this_box = temp_ptr; - g_order = glue_order(this_box); - g_sign = glue_sign(this_box); - p = list_ptr(this_box); - incr(cur_s); - - if (cur_s > max_push) - max_push = cur_s; - - save_loc = dvi_offset + dvi_ptr; - left_edge = cur_h; - cur_v = cur_v - height(this_box); - top_edge = cur_v; - - while (p != 0) - { - if (is_char_node(p)) - { - confusion("vlistout"); - return; - } - else - { - switch (type(p)) - { - case hlist_node: - case vlist_node: - if (list_ptr(p) == 0) - cur_v = cur_v + height(p) + depth(p); - else - { - cur_v = cur_v + height(p); - pdf_synch_v(); - save_h = dvi_h; - save_v = dvi_v; - cur_h = left_edge + shift_amount(p); - temp_ptr = p; - - if (type(p) == vlist_node) - pdf_vlist_out(); - else - pdf_hlist_out(); - - dvi_h = save_h; - dvi_v = save_v; - cur_v = save_v + depth(p); - cur_h = left_edge; - } - break; - - case rule_node: - { - rule_ht = height(p); - rule_dp = depth(p); - rule_wd = width(p); - goto fin_rule; - } - break; - - case whatsit_node: - out_what(p); - break; - - case glue_node: - { - g = glue_ptr(p); - rule_ht = width(g) - cur_g; - - if (g_sign != normal) - { - if (g_sign == stretching) - { - if (stretch_order(g) == g_order) - { - cur_glue = cur_glue + stretch(g); - vet_glue(glue_set(this_box) * cur_glue); - cur_g = round(glue_temp); - } - } - else if (shrink_order(g) == g_order) /* BUG FIX !!! */ - { - cur_glue = cur_glue - shrink(g); - vet_glue(glue_set(this_box) * cur_glue); - cur_g = round(glue_temp); - } - } - - rule_ht = rule_ht + cur_g; - - if (subtype(p) >= a_leaders) - { - leader_box = leader_ptr(p); - - if (type(leader_box) == rule_node) - { - rule_wd = width(leader_box); - rule_dp = 0; - goto fin_rule; - } - - leader_ht = height(leader_box) + depth(leader_box); - - if ((leader_ht > 0) && (rule_ht > 0)) - { - rule_ht = rule_ht + 10; - edge = cur_v + rule_ht; - lx = 0; - - if (subtype(p) == a_leaders) - { - save_v = cur_v; - cur_v = top_edge + leader_ht * ((cur_v - top_edge) / leader_ht); - - if (cur_v < save_v) - cur_v = cur_v + leader_ht; - } - else - { - lq = rule_ht / leader_ht; - lr = rule_ht % leader_ht; - - if (subtype(p) == c_leaders) - cur_v = cur_v + (lr / 2); - else - { - lx = (2 * lr + lq + 1) / (2 * lq + 2); - cur_v = cur_v + ((lr - (lq - 1) * lx) / 2); - } - } - - while (cur_v + leader_ht <= edge) - { - cur_h = left_edge + shift_amount(leader_box); - pdf_synch_h(); - save_h = dvi_h; - cur_v = cur_v + height(leader_box); - pdf_synch_v(); - save_v = dvi_v; - temp_ptr = leader_box; - outer_doing_leaders = doing_leaders; - doing_leaders = true; - - if (type(leader_box) == vlist_node) - pdf_vlist_out(); - else - pdf_hlist_out(); - - doing_leaders = outer_doing_leaders; - dvi_v = save_v; - dvi_h = save_h; - cur_h = left_edge; - cur_v = save_v - height(leader_box) + leader_ht + lx; - } - - cur_v = edge - 10; - goto next_p; - } - } - - goto move_past; - } - break; - - case kern_node: - cur_v = cur_v + width(p); - break; - - default: - break; - } - - goto next_p; - -fin_rule: - if (is_running(rule_wd)) - rule_wd = width(this_box); - - rule_ht = rule_ht + rule_dp; - cur_v = cur_v + rule_ht; - - if ((rule_ht > 0) && (rule_wd > 0)) - { - pdf_synch_h(); - pdf_synch_v(); - pdf_dev_set_rule(cur_h, -cur_v, rule_wd, rule_ht); - } - - goto next_p; - -move_past: - cur_v = cur_v + rule_ht; - } - -next_p: - p = link(p); - } - - prune_movements(save_loc); - decr(cur_s); -} +/* Copyright 2014 Clerk Ma + + 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ + +/* Y&Y TeX's DVIPDFMX backend. */ + +#define EXTERN extern + +#include "yandytex.h" + +void ensure_pdf_open(void) +{ + if (output_file_name == 0) + { + if (job_name == 0) + open_log_file(); + + pack_job_name(".pdf"); + + while (!b_open_out(pdf_file)) + prompt_file_name("file name for output", ".pdf"); + + output_file_name = b_make_name_string(pdf_file); + } +} + +extern void pdf_set_version(unsigned version); +extern void pdf_set_compression(int level); +extern void pdf_doc_set_creator(const char * creator); +extern void pdf_files_init(void); +extern void pdf_init_device(double dvi2pts, int precision, int black_and_white); +extern void pdf_open_document(const char *filename, + int do_encryption, + double media_width, double media_height, + double annot_grow_amount, int bookmark_open_depth, + int check_gotos); +extern void pdf_doc_begin_page(double scale, double x_origin, double y_origin); +extern void pdf_doc_end_page(void); +extern int spc_exec_at_begin_document(void); +extern int spc_exec_at_end_document(void); +extern int spc_exec_at_begin_page(void); +extern int spc_exec_at_end_page(void); +extern void read_config_file (const char *config); +extern void pdf_hlist_out (void); +extern void pdf_vlist_out (void); + +void pdf_ship_out (pointer p) +{ + integer page_loc; + char j, k; + pool_pointer s; + char old_setting; + + if (tracing_output > 0) + { + print_nl(""); + print_ln(); + prints("Completed box being shipped out"); + } + + if (term_offset > max_print_line - 9) + print_ln(); + else if ((term_offset > 0) || (file_offset > 0)) + print_char(' '); + + print_char('['); + j = 9; + + while ((count(j) == 0) && (j > 0)) + decr(j); + + for (k = 0; k <= j; k++) + { + print_int(count(k)); + + if (k < j) + print_char('.'); + } + + update_terminal(); + + if (tracing_output > 0) + { + print_char(']'); + begin_diagnostic(); + show_box(p); + end_diagnostic(true); + } + + if ((height(p) > max_dimen) || (depth(p) > max_dimen) || + (height(p) + depth(p) + v_offset > max_dimen) || + (width(p) + h_offset > max_dimen)) + { + print_err("Huge page cannot be shipped out"); + help2("The page just created is more than 18 feet tall or", + "more than 18 feet wide, so I suspect something went wrong."); + error(); + + if (tracing_output <= 0) + { + begin_diagnostic(); + print_nl("The following box has been deleted:"); + show_box(p); + end_diagnostic(true); + } + + goto done; + } + + if (height(p) + depth(p) + v_offset > max_v) + max_v = height(p) + depth(p) + v_offset; + + if (width(p) + h_offset > max_h) + max_h = width(p) + h_offset; + + dvi_h = 0; + dvi_v = 0; + cur_h = h_offset; + dvi_f = null_font; + ensure_pdf_open(); + + if (total_pages == 0) + { + //kpse_init_prog("", 600, NULL, NULL); + //kpse_set_program_enabled(kpse_pk_format, true, kpse_src_texmf_cnf); + //pdf_font_set_dpi(600); + //dpx_delete_old_cache(image_cache_life); + pdf_set_version(5); + pdf_set_compression(9); + pdf_init_fontmaps(); + read_config_file("dvipdfmx.cfg"); + pdf_doc_set_producer("Y&YTeX 2.3.0"); + pdf_doc_set_creator("TeX"); + pdf_files_init(); + pdf_init_device(0.000015202, 2, 0); + pdf_open_document(pdf_file_name, 0, 595.0, 842.0, 0, 0, (1 << 4)); + spc_exec_at_begin_document(); + } + + page_loc = dvi_offset + dvi_ptr; + pdf_doc_begin_page(1.0, 72.0, 770.0); + spc_exec_at_begin_page(); + + last_bop = page_loc; + cur_v = height(p) + v_offset; + temp_ptr = p; + + if (type(p) == vlist_node) + pdf_vlist_out(); + else + pdf_hlist_out(); + + spc_exec_at_end_page(); + pdf_doc_end_page(); + incr(total_pages); + cur_s = -1; + +done: + if (tracing_output <= 0) + print_char(']'); + + dead_cycles = 0; + update_terminal(); + +#ifdef STAT + if (tracing_stats > 1) + { + print_nl("Memory usage before: "); + print_int(var_used); + print_char('&'); + print_int(dyn_used); + print_char(';'); + } +#endif + + flush_node_list(p); + +#ifdef STAT + if (tracing_stats > 1) + { + prints(" after: "); + print_int(var_used); + print_char('&'); + print_int(dyn_used); + prints("; still utouched: "); + print_int(hi_mem_min - lo_mem_max - 1); + print_ln(); + } +#endif +} + +void pdf_synch_h (void) +{ + if (cur_h != dvi_h) + dvi_h = cur_h; +} + +void pdf_synch_v (void) +{ + if (cur_v != dvi_v) + dvi_v = cur_v; +} + +int pdf_get_font_id (internal_font_number f) +{ + char * sbuf = malloc(length(font_name[f]) + 1); + int id; + memset(sbuf, 0, length(font_name[f]) + 1); + memcpy(sbuf, str_pool + str_start[font_name[f]], length(font_name[f])); + id = dvi_locate_font(sbuf, font_size[f]); + free(sbuf); + + return id; +} + +void pdf_hlist_out (void) +{ + scaled base_line; + scaled left_edge; + scaled save_h, save_v; + pointer this_box; + // glue_ord g_order; + int g_order; + // char g_sign; + int g_sign; + pointer p; + integer save_loc; + pointer leader_box; + scaled leader_wd; + scaled lx; + boolean outer_doing_leaders; + scaled edge; + real glue_temp; + real cur_glue; + scaled cur_g; + + cur_g = 0; + cur_glue = 0.0; + this_box = temp_ptr; + g_order = glue_order(this_box); + g_sign = glue_sign(this_box); + p = list_ptr(this_box); + incr(cur_s); + + if (cur_s > max_push) + max_push = cur_s; + + save_loc = dvi_offset + dvi_ptr; + base_line = cur_v; + left_edge = cur_h; + + while (p != 0) +reswitch: + if (is_char_node(p)) + { + pdf_synch_h(); + pdf_synch_v(); + + do + { + f = font(p); + c = character(p); + + if (f != dvi_f) + { + if (!font_used[f]) + { + font_used[f] = true; + font_id[f] = pdf_get_font_id(f); + } + + dvi_f = f; + } + + char cbuf[2] = {c, 0}; + pdf_dev_set_string(cur_h, -cur_v, cbuf, 1, char_width(f, char_info(f, c)), font_id[dvi_f], 1); + cur_h = cur_h + char_width(f, char_info(f, c)); + p = link(p); + } while (!(!is_char_node(p))); + + dvi_h = cur_h; + } + else + { + switch (type(p)) + { + case hlist_node: + case vlist_node: + if (list_ptr(p) == 0) + cur_h = cur_h + width(p); + else + { + save_h = dvi_h; + save_v = dvi_v; + cur_v = base_line + shift_amount(p); + temp_ptr = p; + edge = cur_h; + + if (type(p) == vlist_node) + pdf_vlist_out(); + else + pdf_hlist_out(); + + dvi_h = save_h; + dvi_v = save_v; + cur_h = edge + width(p); + cur_v = base_line; + } + break; + + case rule_node: + { + rule_ht = height(p); + rule_dp = depth(p); + rule_wd = width(p); + goto fin_rule; + } + break; + + case whatsit_node: + out_what(p); + break; + + case glue_node: + { + g = glue_ptr(p); + rule_wd = width(g) - cur_g; + + if (g_sign != normal) + { + if (g_sign == stretching) + { + if (stretch_order(g) == g_order) + { + cur_glue = cur_glue + stretch(g); + vet_glue(glue_set(this_box) * cur_glue); + cur_g = round(glue_temp); + } + } + else if (shrink_order(g) == g_order) + { + cur_glue = cur_glue - shrink(g); + vet_glue(glue_set(this_box) * cur_glue); + cur_g = round(glue_temp); + } + } + + rule_wd = rule_wd + cur_g; + + if (subtype(p) >= a_leaders) + { + leader_box = leader_ptr(p); + + if (type(leader_box) == rule_node) + { + rule_ht = height(leader_box); + rule_dp = depth(leader_box); + goto fin_rule; + } + + leader_wd = width(leader_box); + + if ((leader_wd > 0) && (rule_wd > 0)) + { + rule_wd = rule_wd + 10; + edge = cur_h + rule_wd; + lx = 0; + + if (subtype(p) == a_leaders) + { + save_h = cur_h; + cur_h = left_edge + leader_wd * ((cur_h - left_edge) / leader_wd); + + if (cur_h < save_h) + cur_h = cur_h + leader_wd; + } + else + { + lq = rule_wd / leader_wd; + lr = rule_wd % leader_wd; + + if (subtype(p) == c_leaders) + cur_h = cur_h + (lr / 2); + else + { + lx = (2 * lr + lq + 1) / (2 * lq + 2); + cur_h = cur_h + ((lr - (lq - 1)* lx) / 2); + } + } + + while (cur_h + leader_wd <= edge) + { + cur_v = base_line + shift_amount(leader_box); + pdf_synch_v(); + save_v = dvi_v; + pdf_synch_h(); + save_h = dvi_h; + temp_ptr = leader_box; + outer_doing_leaders = doing_leaders; + doing_leaders = true; + + if (type(leader_box) == vlist_node) + pdf_vlist_out(); + else + pdf_hlist_out(); + + doing_leaders = outer_doing_leaders; + dvi_v = save_v; + dvi_h = save_h; + cur_v = base_line; + cur_h = save_h + leader_wd + lx; + } + + cur_h = edge - 10; + goto next_p; + } + } + + goto move_past; + } + break; + + case kern_node: + case math_node: + cur_h = cur_h + width(p); + break; + + case ligature_node: + { + mem[lig_trick] = mem[lig_char(p)]; + link(lig_trick) = link(p); + p = lig_trick; + goto reswitch; + } + break; + + default: + break; + } + + goto next_p; + +fin_rule: + if (is_running(rule_ht)) + rule_ht = height(this_box); + + if (is_running(rule_dp)) + rule_dp = depth(this_box); + + rule_ht = rule_ht + rule_dp; + + if ((rule_ht > 0) && (rule_wd > 0)) + { + pdf_synch_h(); + cur_v = base_line + rule_dp; + pdf_synch_v(); + pdf_dev_set_rule(dvi_h, dvi_v, rule_wd, rule_ht); + cur_v = base_line; + dvi_h = dvi_h + rule_wd; + } + +move_past: + cur_h = cur_h + rule_wd; + +next_p: + p = link(p); + } + + prune_movements(save_loc); + decr(cur_s); +} + +void pdf_vlist_out (void) +{ + scaled left_edge; + scaled top_edge; + scaled save_h, save_v; + pointer this_box; + // glue_ord g_order; + int g_order; + // char g_sign; + int g_sign; + pointer p; + integer save_loc; + pointer leader_box; + scaled leader_ht; + scaled lx; + boolean outer_doing_leaders; + scaled edge; + real glue_temp; + real cur_glue; + scaled cur_g; + + cur_g = 0; + cur_glue = 0.0; + this_box = temp_ptr; + g_order = glue_order(this_box); + g_sign = glue_sign(this_box); + p = list_ptr(this_box); + incr(cur_s); + + if (cur_s > max_push) + max_push = cur_s; + + save_loc = dvi_offset + dvi_ptr; + left_edge = cur_h; + cur_v = cur_v - height(this_box); + top_edge = cur_v; + + while (p != 0) + { + if (is_char_node(p)) + { + confusion("vlistout"); + return; + } + else + { + switch (type(p)) + { + case hlist_node: + case vlist_node: + if (list_ptr(p) == 0) + cur_v = cur_v + height(p) + depth(p); + else + { + cur_v = cur_v + height(p); + pdf_synch_v(); + save_h = dvi_h; + save_v = dvi_v; + cur_h = left_edge + shift_amount(p); + temp_ptr = p; + + if (type(p) == vlist_node) + pdf_vlist_out(); + else + pdf_hlist_out(); + + dvi_h = save_h; + dvi_v = save_v; + cur_v = save_v + depth(p); + cur_h = left_edge; + } + break; + + case rule_node: + { + rule_ht = height(p); + rule_dp = depth(p); + rule_wd = width(p); + goto fin_rule; + } + break; + + case whatsit_node: + out_what(p); + break; + + case glue_node: + { + g = glue_ptr(p); + rule_ht = width(g) - cur_g; + + if (g_sign != normal) + { + if (g_sign == stretching) + { + if (stretch_order(g) == g_order) + { + cur_glue = cur_glue + stretch(g); + vet_glue(glue_set(this_box) * cur_glue); + cur_g = round(glue_temp); + } + } + else if (shrink_order(g) == g_order) /* BUG FIX !!! */ + { + cur_glue = cur_glue - shrink(g); + vet_glue(glue_set(this_box) * cur_glue); + cur_g = round(glue_temp); + } + } + + rule_ht = rule_ht + cur_g; + + if (subtype(p) >= a_leaders) + { + leader_box = leader_ptr(p); + + if (type(leader_box) == rule_node) + { + rule_wd = width(leader_box); + rule_dp = 0; + goto fin_rule; + } + + leader_ht = height(leader_box) + depth(leader_box); + + if ((leader_ht > 0) && (rule_ht > 0)) + { + rule_ht = rule_ht + 10; + edge = cur_v + rule_ht; + lx = 0; + + if (subtype(p) == a_leaders) + { + save_v = cur_v; + cur_v = top_edge + leader_ht * ((cur_v - top_edge) / leader_ht); + + if (cur_v < save_v) + cur_v = cur_v + leader_ht; + } + else + { + lq = rule_ht / leader_ht; + lr = rule_ht % leader_ht; + + if (subtype(p) == c_leaders) + cur_v = cur_v + (lr / 2); + else + { + lx = (2 * lr + lq + 1) / (2 * lq + 2); + cur_v = cur_v + ((lr - (lq - 1) * lx) / 2); + } + } + + while (cur_v + leader_ht <= edge) + { + cur_h = left_edge + shift_amount(leader_box); + pdf_synch_h(); + save_h = dvi_h; + cur_v = cur_v + height(leader_box); + pdf_synch_v(); + save_v = dvi_v; + temp_ptr = leader_box; + outer_doing_leaders = doing_leaders; + doing_leaders = true; + + if (type(leader_box) == vlist_node) + pdf_vlist_out(); + else + pdf_hlist_out(); + + doing_leaders = outer_doing_leaders; + dvi_v = save_v; + dvi_h = save_h; + cur_h = left_edge; + cur_v = save_v - height(leader_box) + leader_ht + lx; + } + + cur_v = edge - 10; + goto next_p; + } + } + + goto move_past; + } + break; + + case kern_node: + cur_v = cur_v + width(p); + break; + + default: + break; + } + + goto next_p; + +fin_rule: + if (is_running(rule_wd)) + rule_wd = width(this_box); + + rule_ht = rule_ht + rule_dp; + cur_v = cur_v + rule_ht; + + if ((rule_ht > 0) && (rule_wd > 0)) + { + pdf_synch_h(); + pdf_synch_v(); + pdf_dev_set_rule(cur_h, -cur_v, rule_wd, rule_ht); + } + + goto next_p; + +move_past: + cur_v = cur_v + rule_ht; + } + +next_p: + p = link(p); + } + + prune_movements(save_loc); + decr(cur_s); +} diff --git a/src/texsourc/itex.c b/src/texsourc/itex.c index 843df60..0922014 100644 --- a/src/texsourc/itex.c +++ b/src/texsourc/itex.c @@ -1,3851 +1,3851 @@ -/* Copyright 1992 Karl Berry - Copyright 2007 TeX Users Group - Copyright 2014 Clerk Ma - - 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#define EXTERN extern - -#include "yandytex.h" - -#define BEGINFMTCHECKSUM 367403084L -#define ENDFMTCHECKSUM 69069L - -#ifdef INITEX - void do_initex (void); -#endif - -/* sec 0004 */ -void initialize (void) -{ - integer i; - integer k; - integer flag; - -#ifndef ALLOCATEHYPHEN - hyph_pointer z; -#endif - - if (!non_ascii) - { - for (i = 0; i <= 255; i++) - xchr[i] = (char) i; - -#ifdef JOKE - xchr[32] = ' '; xchr[33] = '!'; xchr[34] = '"'; xchr[35] = '#'; - xchr[36] = '$'; xchr[37] = '%'; xchr[38] = '&'; xchr[39] = '\''; - xchr[40] = '('; xchr[41] = ')'; xchr[42] = '*'; xchr[43] = '+'; - xchr[44] = ','; xchr[45] = '-'; xchr[46] = '.'; xchr[47] = '/'; - xchr[48] = '0'; xchr[49] = '1'; xchr[50] = '2'; xchr[51] = '3'; - xchr[52] = '4'; xchr[53] = '5'; xchr[54] = '6'; xchr[55] = '7'; - xchr[56] = '8'; xchr[57] = '9'; xchr[58] = ':'; xchr[59] = ';'; - xchr[60] = '<'; xchr[61] = '='; xchr[62] = '>'; xchr[63] = '?'; - xchr[64] = '@'; xchr[65] = 'A'; xchr[66] = 'B'; xchr[67] = 'C'; - xchr[68] = 'D'; xchr[69] = 'E'; xchr[70] = 'F'; xchr[71] = 'G'; - xchr[72] = 'H'; xchr[73] = 'I'; xchr[74] = 'J'; xchr[75] = 'K'; - xchr[76] = 'L'; xchr[77] = 'M'; xchr[78] = 'N'; xchr[79] = 'O'; - xchr[80] = 'P'; xchr[81] = 'Q'; xchr[82] = 'R'; xchr[83] = 'S'; - xchr[84] = 'T'; xchr[85] = 'U'; xchr[86] = 'V'; xchr[87] = 'W'; - xchr[88] = 'X'; xchr[89] = 'Y'; xchr[90] = 'Z'; xchr[91] = '['; - xchr[92] = '\\'; xchr[93] = ']'; xchr[94] = '^'; xchr[95] = '_'; - xchr[96] = '`'; xchr[97] = 'a'; xchr[98] = 'b'; xchr[99] = 'c'; - xchr[100] = 'd'; xchr[101] = 'e'; xchr[102] = 'f'; xchr[103] = 'g'; - xchr[104] = 'h'; xchr[105] = 'i'; xchr[106] = 'j'; xchr[107] = 'k'; - xchr[108] = 'l'; xchr[109] = 'm'; xchr[110] = 'n'; xchr[111] = 'o'; - xchr[112] = 'p'; xchr[113] = 'q'; xchr[114] = 'r'; xchr[115] = 's'; - xchr[116] = 't'; xchr[117] = 'u'; xchr[118] = 'v'; xchr[119] = 'w'; - xchr[120] = 'x'; xchr[121] = 'y'; xchr[122] = 'z'; xchr[123] = '{'; - xchr[124] = '|'; xchr[125] = '}'; xchr[126] = '~'; - - for (i = 0; i <= 31; i++) - xchr[i] = chr(i); - - for (i = 127; i <= 255; i++) - xchr[i]= chr(i); -#endif - } - - for (i = 0; i <= 255; i++) - xord[chr(i)] = invalid_code; - -#ifdef JOKE - for (i = 128; i <= 255 ; i++) - xord[xchr[i]] = i; - - for (i = 0; i <= 126; i++) - xord[xchr[i]] = i; -#endif - - for (i = 0; i <= 255; i++) - xord[xchr[i]] = (char) i; - - xord[127] = 127; - - flag = 0; - - if (trace_flag != 0) - { - for (k = 0; k < 256; k++) - if (xord[k] != k) - { - flag = 1; - break; - } - - if (flag) - { - puts("Inverted mapping xord[] pairs:"); - - for (k = 0; k < 256; k++) - { - if (xord[k] != 127) - printf("%lld => %d\n", k, xord[k]); - } - } - } - - if (interaction < batch_mode) - interaction = error_stop_mode; - - deletions_allowed = true; - set_box_allowed = true; - error_count = 0; - help_ptr = 0; - use_err_help = false; - interrupt = 0; - OK_to_interrupt = true; - -#ifdef DEBUG - was_mem_end = mem_min; - was_lo_max = mem_bot; // mem_min - was_hi_min = mem_top; // mem_max - panicking = false; -#endif - - nest_ptr = 0; - max_nest_stack = 0; - mode = vmode; - head = contrib_head; - tail = contrib_head; - prev_depth = ignore_depth; - mode_line = 0; - prev_graf = 0; - shown_mode = 0; - page_contents = 0; - page_tail = page_head; - -#ifdef ALLOCATEMAIN - if (is_initex) -#endif - link(page_head) = 0; - - last_glue = max_halfword; - last_penalty = 0; - last_kern = 0; - page_depth = 0; - page_max_depth = 0; - - for (k = int_base; k <= eqtb_size; k++) - xeq_level[k] = level_one; - - no_new_control_sequence = true; - next(hash_base) = 0; - text(hash_base) = 0; - - for (k = hash_base + 1; k <= undefined_control_sequence - 1; k++) - hash[k] = hash[hash_base]; - - save_ptr = 0; - cur_level = 1; - cur_group = 0; - cur_boundary = 0; - max_save_stack = 0; - mag_set = 0; - cur_mark[0] = 0; - cur_mark[1] = 0; - cur_mark[2] = 0; - cur_mark[3] = 0; - cur_mark[4] = 0; - cur_val = 0; - cur_val_level = int_val; - radix = 0; - cur_order = normal; - - for (k = 0; k <= 16; k++) - read_open[k] = closed; - - cond_ptr = 0; - if_limit = normal; - cur_if = 0; - if_line = 0; - - for (k = 0; k <= font_max; k++) - font_used[k] = false; - - null_character.b0 = min_quarterword; - null_character.b1 = min_quarterword; - null_character.b2 = min_quarterword; - null_character.b3 = min_quarterword; - total_pages = 0; - max_v = 0; - max_h = 0; - max_push = 0; - last_bop = -1; - doing_leaders = false; - dead_cycles = 0; - cur_s = -1; - half_buf = dvi_buf_size / 2; - dvi_limit = dvi_buf_size; - dvi_ptr = 0; - dvi_offset = 0; - dvi_gone = 0; - down_ptr = 0; - right_ptr = 0; - adjust_tail = 0; - last_badness = 0; - pack_begin_line = 0; - empty_field.rh = 0; - empty_field.lh = 0; - null_delimiter.b0 = 0; - null_delimiter.b1 = 0; - null_delimiter.b2 = 0; - null_delimiter.b3 = 0; - align_ptr = 0; - cur_align = 0; - cur_span = 0; - cur_loop = 0; - cur_head = 0; - cur_tail = 0; - -/* *not* OK with ALLOCATEHYPHEN, since may not be allocated yet */ -#ifndef ALLOCATEHYPHEN - for (z = 0; z <= hyphen_prime; z++) - { - hyph_word[z] = 0; - hyph_list[z] = 0; - } -#endif - - hyph_count = 0; - output_active = false; - insert_penalties = 0; - ligature_present = false; - cancel_boundary = false; - lft_hit = false; - rt_hit = false; - ins_disc = false; - after_token = 0; - long_help_seen = false; - format_ident = 0; - - for (k = 0; k <= 17; k++) - write_open[k] = false; - - edit_name_start = 0; - -#ifdef INITEX - if (is_initex) - do_initex(); -#endif -} - -/* do the part of initialize() that requires mem_top, mem_max or mem[] */ -/* do this part after allocating main memory */ - -#ifdef ALLOCATEMAIN -void initialize_aux (void) -{ -#ifdef DEBUG - was_mem_end = mem_min; - was_lo_max = mem_bot; // mem_min - was_hi_min = mem_top; // mem_max - panicking = false; -#endif - -/* nest_ptr = 0; */ -/* max_nest_stack = 0; */ - mode = vmode; - head = contrib_head; - tail = contrib_head; - prev_depth = ignore_depth; - mode_line = 0; - prev_graf = 0; -/* shown_mode = 0; */ -/* page_contents = 0; */ - page_tail = page_head; - link(page_head) = 0; -} -#endif -/* sec 0815 */ -void line_break (integer final_widow_penalty) -{ - boolean auto_breaking; - pointer prev_p; - pointer q, r, s, prev_s; - internal_font_number f; - /* small_number j; */ - int j; - /* unsigned char c; */ - unsigned int c; - - pack_begin_line = mode_line; - link(temp_head) = link(head); - - if (is_char_node(tail)) - tail_append(new_penalty(inf_penalty)); - else if (type(tail) != glue_node) - tail_append(new_penalty(inf_penalty)); - else - { - type(tail) = penalty_node; - delete_glue_ref(glue_ptr(tail)); - flush_node_list(leader_ptr(tail)); - penalty(tail) = inf_penalty; - } - - link(tail) = new_param_glue(par_fill_skip_code); - init_cur_lang = prev_graf % 65536L; - init_l_hyf = prev_graf / 4194304L; /* 2^22 */ - init_r_hyf = (prev_graf / 65536L) % 64; - pop_nest(); - no_shrink_error_yet = true; - check_shrinkage(left_skip); - check_shrinkage(right_skip); - q = left_skip; - r = right_skip; - background[1] = width(q) + width(r); - background[2] = 0; - background[3] = 0; - background[4] = 0; - background[5] = 0; - background[2 + stretch_order(q)] = stretch(q); - background[2 + stretch_order(r)] = background[2 + stretch_order(r)] + stretch(r); - background[6] = shrink(q) + shrink(r); - minimum_demerits = awful_bad; - minimal_demerits[tight_fit] = awful_bad; - minimal_demerits[decent_fit] = awful_bad; - minimal_demerits[loose_fit] = awful_bad; - minimal_demerits[very_loose_fit] = awful_bad; - - if (par_shape_ptr == 0) - if (hang_indent == 0) - { - last_special_line = 0; - second_width = hsize; - second_indent = 0; - } - else - { - last_special_line = abs(hang_after); - - if (hang_after < 0) - { - first_width = hsize - abs(hang_indent); - - if (hang_indent >= 0) - first_indent = hang_indent; - else - first_indent = 0; - - second_width = hsize; - second_indent = 0; - } - else - { - first_width = hsize; - first_indent = 0; - second_width = hsize - abs(hang_indent); - - if (hang_indent >= 0) - second_indent = hang_indent; - else - second_indent = 0; - } - } - else - { - last_special_line = info(par_shape_ptr) - 1; - second_width = mem[par_shape_ptr + 2 * (last_special_line + 1)].cint; - second_indent = mem[par_shape_ptr + 2 * last_special_line + 1].cint; - } - - if (looseness == 0) - easy_line = last_special_line; - else - easy_line = empty_flag; - - threshold = pretolerance; - - if (threshold >= 0) - { -#ifdef STAT - if (tracing_paragraphs > 0) - { - begin_diagnostic(); - print_nl("@firstpass"); - } -#endif - - second_pass = false; - final_pass = false; - first_pass_count++; - } - else - { - threshold = tolerance; - second_pass = true; - final_pass = (emergency_stretch <= 0); - -#ifdef STAT - if (tracing_paragraphs > 0) - begin_diagnostic(); -#endif - } - - while (true) - { - if (threshold > inf_bad) - threshold = inf_bad; - - if (second_pass) - { -#ifdef INITEX - if (is_initex) - { - if (trie_not_ready) - init_trie(); - } -#endif - - cur_lang = init_cur_lang; - l_hyf = init_l_hyf; - r_hyf = init_r_hyf; - } - - q = get_node(active_node_size); - type(q) = unhyphenated; - fitness(q) = decent_fit; - link(q) = active; - break_node(q) = 0; - line_number(q) = prev_graf + 1; - total_demerits(q) = 0; - link(active) = q; - act_width = background[1]; - do_all_six(store_background); - passive = 0; - printed_node = temp_head; - pass_number = 0; - font_in_short_display = null_font; - cur_p = link(temp_head); - auto_breaking = true; - prev_p = cur_p; - - while ((cur_p != 0) && (link(active) != active)) - { - if (is_char_node(cur_p)) - { - prev_p = cur_p; - - do - { - f = font(cur_p); - act_width = act_width + char_width(f, char_info(f, character(cur_p))); - cur_p = link(cur_p); - } - while (!(!is_char_node(cur_p))); - } - - switch (type(cur_p)) - { - case hlist_node: - case vlist_node: - case rule_node: - act_width = act_width + width(cur_p); - break; - - case whatsit_node: - if (subtype(cur_p) == language_node) - { - cur_lang = what_lang(cur_p); - l_hyf = what_lhm(cur_p); - r_hyf = what_rhm(cur_p); - } - break; - - case glue_node: - { - if (auto_breaking) - { - if (is_char_node(prev_p)) - try_break(0, unhyphenated); - else if (precedes_break(prev_p)) - try_break(0, unhyphenated); - else if ((type(prev_p) == kern_node) && (subtype(prev_p) != explicit)) - try_break(0, unhyphenated); - } - - check_shrinkage(glue_ptr(cur_p)); - q = glue_ptr(cur_p); - act_width = act_width+ width(q); - active_width[2 + stretch_order(q)] = active_width[2 + stretch_order(q)] + stretch(q); - active_width[6] = active_width[6] + shrink(q); - - if (second_pass && auto_breaking) - { - prev_s = cur_p; - s = link(prev_s); - - if (s != 0) - { - while (true) - { - if (is_char_node(s)) - { - c = character(s); - hf = font(s); - } - else if (type(s) == ligature_node) - if (lig_ptr(s) == 0) - goto continu; - else - { - q = lig_ptr(s); - c = character(q); - hf = font(q); - } - else if ((type(s) == kern_node) && (subtype(s) == normal)) - goto continu; - else if (type(s) == whatsit_node) - { - if (subtype(s) == language_node) - { - cur_lang = what_lang(s); - l_hyf = what_lhm(s); - r_hyf = what_rhm(s); - } - goto continu; - } - else - goto done1; - - if (lc_code(c) != 0) - if ((lc_code(c) == (halfword) c) || (uc_hyph > 0)) - goto done2; - else - goto done1; -continu: - prev_s = s; - s = link(prev_s); - } -done2: - hyf_char = hyphen_char[hf]; - - if (hyf_char < 0) - goto done1; - - if (hyf_char > 255) - goto done1; - - ha = prev_s; - - if (l_hyf + r_hyf > 63) - goto done1; - - hn = 0; - - while (true) - { - if (is_char_node(s)) - { - if (font(s) != hf) - goto done3; - - hyf_bchar = character(s); - - c = hyf_bchar; - - if (lc_code(c) == 0) - goto done3; - - if (hn == 63) - goto done3; - - hb = s; - incr(hn); - hu[hn] = c; - hc[hn]= lc_code(c); - hyf_bchar = non_char; - } - else if (type(s) == ligature_node) - { - if (font(lig_char(s)) != hf) - goto done3; - - j = hn; - q = lig_ptr(s); - - if (q != 0) - hyf_bchar = character(q); - - while (q != 0) - { - c = character(q); - - if (lc_code(c) == 0) - goto done3; - - if (j == 63) - goto done3; - - incr(j); - hu[j] = c; - hc[j] = lc_code(c); - q = link(q); - } - - hb = s; - hn = j; - - if (odd(subtype(s))) - hyf_bchar = font_bchar[hf]; - else - hyf_bchar = non_char; - } - else if ((type(s) == kern_node) && (subtype(s) == normal)) - { - hb = s; - hyf_bchar = font_bchar[hf]; - } - else - goto done3; - - s = link(s); - } -done3: - if (hn < l_hyf + r_hyf) - goto done1; - - while (true) - { - if (!(is_char_node(s))) - switch (type(s)) - { - case ligature_node: - break; - - case kern_node: - if (subtype(s) != normal) - goto done4; - break; - - case whatsit_node: - case glue_node: - case penalty_node: - case ins_node: - case adjust_node: - case mark_node: - goto done4; - break; - - default: - goto done1; - break; - } - s = link(s); - } -done4: - hyphenate(); - } -done1:; - } - } - break; - - case kern_node: - if (subtype(cur_p) == explicit) - kern_break(); - else - act_width = act_width + width(cur_p); - break; - - case ligature_node: - { - f = font(lig_char(cur_p)); - act_width = act_width + char_width(f, char_info(f, character(lig_char(cur_p)))); - } - break; - - case disc_node: - { - s = pre_break(cur_p); - disc_width = 0; - - if (s == 0) - try_break(ex_hyphen_penalty, hyphenated); - else - { - do - { - if (is_char_node(s)) - { - f = font(s); - disc_width = disc_width + char_width(f, char_info(f, character(s))); - } - else switch (type(s)) - { - case ligature_node: - { - f = font(lig_char(s)); - disc_width = disc_width + char_width(f, char_info(f, character(lig_char(s)))); - } - break; - - case hlist_node: - case vlist_node: - case rule_node: - case kern_node: - disc_width = disc_width + width(s); - break; - - default: - { - confusion("disc3"); - return; - } - break; - } - - s = link(s); - } - while (!(s == 0)); - - act_width = act_width + disc_width; - try_break(hyphen_penalty, hyphenated); - act_width = act_width - disc_width; - } - - r = replace_count(cur_p); - s = link(cur_p); - - while (r > 0) - { - if (is_char_node(s)) - { - f = font(s); - act_width = act_width + char_width(f, char_info(f, character(s))); - } - else switch (type(s)) - { - case ligature_node: - { - f = font(lig_char(s)); - act_width = act_width + char_width(f, char_info(f, character(lig_char(s)))); - } - break; - - case hlist_node: - case vlist_node: - case rule_node: - case kern_node: - act_width = act_width + width(s); - break; - - default: - { - confusion("disc4"); - return; - } - break; - } - - decr(r); - s = link(s); - } - - prev_p = cur_p; - cur_p = s; - goto done5; - } - break; - - case math_node: - { - auto_breaking = (subtype(cur_p) == after); - kern_break(); - } - break; - - case penalty_node: - try_break(penalty(cur_p), unhyphenated); - break; - - case mark_node: - case ins_node: - case adjust_node: - break; - - default: - { - confusion("paragraph"); - return; - } - break; - } - - prev_p = cur_p; - cur_p = link(cur_p); -done5:; - } - - if (cur_p == 0) - { - try_break(eject_penalty, hyphenated); - - if (link(active) != active) - { - r = link(active); - fewest_demerits = awful_bad; - - do - { - if (type(r) != delta_node) - if (total_demerits(r) < fewest_demerits) - { - fewest_demerits = total_demerits(r); - best_bet = r; - } - - r = link(r); - } - while (!(r == active)); - - best_line = line_number(best_bet); - - if (looseness == 0) - { - goto done; - } - - { - r = link(active); - actual_looseness = 0; - - do - { - if (type(r) != delta_node) - { - line_diff = toint(line_number(r)) - toint(best_line); - - if (((line_diff < actual_looseness) && (looseness <= line_diff)) || - ((line_diff > actual_looseness) && (looseness >= line_diff))) - { - best_bet = r; - actual_looseness = line_diff; - fewest_demerits = total_demerits(r); - } - else if ((line_diff == actual_looseness) && (total_demerits(r) < fewest_demerits)) - { - best_bet = r; - fewest_demerits = total_demerits(r); - } - } - - r = link(r); - } - while (!(r == active)); - - best_line = line_number(best_bet); - } - - if ((actual_looseness == looseness) || final_pass) - { - goto done; - } - } - } - - q = link(active); - - while (q != active) - { - cur_p = link(q); - - if (type(q) == delta_node) - free_node(q, delta_node_size); - else - free_node(q, active_node_size); - - q = cur_p; - } - - q = passive; - - while (q != 0) - { - cur_p = link(q); - free_node(q, passive_node_size); - q = cur_p; - } - - if (!second_pass) - { -#ifdef STAT - if (tracing_paragraphs > 0) - print_nl("@secondpass"); -#endif - threshold = tolerance; - second_pass = true; - second_pass_count++; - final_pass = (emergency_stretch <= 0); - } - else - { -#ifdef STAT - if (tracing_paragraphs > 0) - print_nl("@emergencypass"); -#endif - - background[2] = background[2] + emergency_stretch; - final_pass = true; - ++final_pass_count; - } - } - -done: - if (best_line == decent_fit) - single_line++; - -#ifdef STAT - if (tracing_paragraphs > 0) - { - end_diagnostic(true); - normalize_selector(); - } -#endif - - post_line_break(final_widow_penalty); - q = link(active); - - while (q != active) - { - cur_p = link(q); - - if (type(q) == delta_node) - free_node(q, delta_node_size); - else - free_node(q, active_node_size); - - q = cur_p; - } - - q = passive; - - while (q != 0) - { - cur_p = link(q); - free_node(q, passive_node_size); - q = cur_p; - } - - pack_begin_line = 0; -} -/* sec 1211 */ -void prefixed_command (void) -{ - small_number a; - internal_font_number f; - halfword j; - font_index k; - pointer p, q; - integer n; - boolean e; - - a = 0; - - while (cur_cmd == prefix) - { - if (!odd(a / cur_chr)) - a = a + cur_chr; - - do - { - get_x_token(); - } - while (!((cur_cmd != spacer) && (cur_cmd != relax))); - - if (cur_cmd <= max_non_prefixed_command) - { - print_err("You can't use a prefix with `"); - print_cmd_chr(cur_cmd, cur_chr); - print_char('\''); - help1("I'll pretend you didn't say \\long or \\outer or \\global."); - back_error(); - return; - } - } - - if ((cur_cmd != def) && (a % 4 != 0)) - { - print_err("You can't use `"); - print_esc("long"); - prints("' or `"); - print_esc("outer"); - prints("' with `"); - print_cmd_chr(cur_cmd, cur_chr); - print_char('\''); - help1("I'll pretend you didn't say \\long or \\outer here."); - error(); - } - - if (global_defs != 0) - if (global_defs < 0) - { - if ((a >= 4)) - a = a - 4; - } - else - { - if (!(a >= 4)) - a = a + 4; - } - - switch (cur_cmd) - { - case set_font: - define(cur_font_loc, data, cur_chr); - break; - - case def: - { - if (odd(cur_chr) && !(a >= 4) && (global_defs >= 0)) - a = a + 4; - - e = (cur_chr >= 2); - get_r_token(); - p = cur_cs; - q = scan_toks(true, e); - define(p, call + (a % 4), def_ref); - } - break; - - case let: - { - n = cur_chr; - get_r_token(); - p = cur_cs; - - if (n == 0) - { - do - { - get_token(); - } - while (!(cur_cmd != spacer)); - - if (cur_tok == other_token + '=') - { - get_token(); - - if (cur_cmd == spacer) - get_token(); - } - } - else - { - get_token(); - q = cur_tok; - get_token(); - back_input(); - cur_tok = q; - back_input(); - } - - if (cur_cmd >= call) - add_token_ref(cur_chr); - - define(p, cur_cmd, cur_chr); - } - break; - - case shorthand_def: - { - n = cur_chr; - get_r_token(); - p = cur_cs; - define(p, relax, 256); - scan_optional_equals(); - - switch (n) - { - case char_def_code: - { - scan_char_num(); - define(p, char_given, cur_val); - } - break; - - case math_char_def_code: - { - scan_fifteen_bit_int(); - define(p, math_given, cur_val); - } - break; - - default: - { - scan_eight_bit_int(); - - switch (n) - { - case count_def_code: - define(p, assign_int, count_base + cur_val); - break; - - case dimen_def_code: - define(p, assign_dimen, scaled_base + cur_val); - break; - - case skip_def_code: - define(p, assign_glue, skip_base + cur_val); - break; - - case mu_skip_def_code: - define(p, assign_mu_glue, mu_skip_base + cur_val); - break; - - case toks_def_code: - define(p, assign_toks, toks_base + cur_val); - break; - } - } - break; - } - } - break; - - case read_to_cs: - { - scan_int(); - n = cur_val; - - if (!scan_keyword("to")) - { - print_err("Missing `to' inserted"); - help2("You should have said `\\read to \\cs'.", - "I'm going to look for the \\cs now."); - error(); - } - - get_r_token(); - p = cur_cs; - read_toks(n, p); - define(p, call, cur_val); - } - break; - - case toks_register: - case assign_toks: - { - q = cur_cs; - - if (cur_cmd == toks_register) - { - scan_eight_bit_int(); - p = toks_base + cur_val; - } - else - p = cur_chr; - - scan_optional_equals(); - - do - { - get_x_token(); - } - while (!((cur_cmd != spacer) && (cur_cmd != relax))); - - if (cur_cmd != left_brace) - { - if (cur_cmd == toks_register) - { - scan_eight_bit_int(); - cur_cmd = assign_toks; - cur_chr = toks_base + cur_val; - } - - if (cur_cmd == assign_toks) - { - q = equiv(cur_chr); - - if (q == 0) - define(p, undefined_cs, 0); - else - { - add_token_ref(q); - define(p, call, q); - } - goto done; - } - } - - back_input(); - cur_cs = q; - q = scan_toks(false, false); - - if (link(def_ref) == 0) - { - define(p, undefined_cs, 0); - free_avail(def_ref); - } - else - { - if (p == output_routine_loc) - { - link(q) = get_avail(); - q = link(q); - info(q) = right_brace_token + '}'; - q = get_avail(); - info(q) = left_brace_token + '{'; - link(q) = link(def_ref); - link(def_ref) = q; - } - - define(p, call, def_ref); - } - } - break; - - case assign_int: - { - p = cur_chr; - scan_optional_equals(); - scan_int(); - word_define(p, cur_val); - } - break; - - case assign_dimen: - { - p = cur_chr; - scan_optional_equals(); - scan_dimen(false, false, false); - word_define(p, cur_val); - } - break; - - case assign_glue: - case assign_mu_glue: - { - p = cur_chr; - n = cur_cmd; - scan_optional_equals(); - - if (n == assign_mu_glue) - scan_glue(mu_val); - else - scan_glue(glue_val); - - trap_zero_glue(); - define(p, glue_ref, cur_val); - } - break; - - case def_code: - { - if (cur_chr == cat_code_base) - n = max_char_code; - else if (cur_chr == math_code_base) - n = 32768L; /* 2^15 */ - else if (cur_chr == sf_code_base) - n = 32767; /* 2^15 - 1*/ - else if (cur_chr == del_code_base) - n = 16777215L; /* 2^24 - 1 */ - else - n = 255; - - p = cur_chr; - scan_char_num(); - p = p + cur_val; - scan_optional_equals(); - scan_int(); - - if (((cur_val < 0) && (p < del_code_base)) || (cur_val > n)) - { - print_err("Invalid code("); - print_int(cur_val); - - if (p < del_code_base) - prints("), should be in the range 0.."); - else - prints("), should be at most "); - - print_int(n); - help1("I'm going to use 0 instead of that illegal code value."); - error(); - cur_val = 0; - } - - if (p < math_code_base) - define(p, data, cur_val); - else if (p < del_code_base) - define(p, data, cur_val); - else - word_define(p, cur_val); - } - break; - - case def_family: - { - p = cur_chr; - scan_four_bit_int(); - p = p + cur_val; - scan_optional_equals(); - scan_font_ident(); - define(p, data, cur_val); - } - break; - - case tex_register: - case advance: - case multiply: - case divide: - do_register_command(a); - break; - - case set_box: - { - scan_eight_bit_int(); - - if ((a >= 4)) - n = 256 + cur_val; - else - n = cur_val; - - scan_optional_equals(); - - if (set_box_allowed) - scan_box(box_flag + n); - else - { - print_err("Improper "); - print_esc("setbox"); - help2("Sorry, \\setbox is not allowed after \\halign in a display,", - "or between \\accent and an accented character."); - error(); - } - } - break; - - case set_aux: - alter_aux(); - break; - - case set_prev_graf: - alter_prev_graf(); - break; - - case set_page_dimen: - alter_page_so_far(); - break; - - case set_page_int: - alter_integer(); - break; - - case set_box_dimen: - alter_box_dimen(); - break; - - case set_shape: - { - scan_optional_equals(); - scan_int(); - n = cur_val; - - if (n <= 0) - p = 0; - else - { - p = get_node(2 * n + 1); - info(p) = n; - - for (j = 1; j <= n; j++) - { - scan_dimen(false, false, false); - mem[p + 2 * j - 1].cint = cur_val; - scan_dimen(false, false, false); - mem[p + 2 * j].cint = cur_val; - } - } - - define(par_shape_loc, shape_ref, p); - } - break; - - case hyph_data: - if (cur_chr == 1) - { -#ifdef INITEX - if (is_initex) - { - new_patterns(); - goto done; - } -#endif - print_err("Patterns can be loaded only by INITEX"); - help_ptr = 0; - error(); - - do - { - get_token(); - } - while (!(cur_cmd == right_brace)); - - return; - } - else - { - new_hyph_exceptions(); - goto done; - } - break; - - case assign_font_dimen: - { - find_font_dimen(true); - k = cur_val; - scan_optional_equals(); - scan_dimen(false, false, false); - font_info[k].cint = cur_val; - } - break; - - case assign_font_int: - { - n = cur_chr; - scan_font_ident(); - f = cur_val; - scan_optional_equals(); - scan_int(); - - if (n == 0) - hyphen_char[f] = cur_val; - else - skew_char[f] = cur_val; - } - break; - - case def_font: - new_font(a); - break; - - case set_interaction: - new_interaction(); - break; - - default: - { - confusion("prefix"); - return; - } - break; - } - -done: - if (after_token != 0) - { - cur_tok = after_token; - back_input(); - after_token = 0; - } -} -/* sec 1303 */ -boolean load_fmt_file (void) -{ - integer j, k; - pointer p, q; - integer x; - - undump_int(x); - - if (x != BEGINFMTCHECKSUM) - goto bad_fmt; - - undump_int(x); /* mem_bot */ - - if (x != mem_bot) - goto bad_fmt; - - undump_int(x); /* mem_top */ - -#ifdef ALLOCATEMAIN -/* we already read this once earlier to grab mem_top */ - if (trace_flag) - printf("Read from fmt file mem_top = %lld TeX words\n", x); - - mem = allocate_main_memory(x); - - if (mem == NULL) - exit(EXIT_FAILURE); - - initialize_aux(); /* do `mem' part of initialize */ -#endif - - if (x != mem_top) - goto bad_fmt; - - undump_int(x); /* eqtb_size */ - - if (x != eqtb_size) - goto bad_fmt; - - undump_int(x); /* hash_prime */ - - if (x != hash_prime) - goto bad_fmt; - - undump_int(x); /* hyphen_prime */ - -#ifdef ALLOCATEHYPHEN -/* allow format files dumped with arbitrary (prime) hyphenation exceptions */ - realloc_hyphen(x); - hyphen_prime = x; -#endif - - if (x != hyphen_prime) - goto bad_fmt; - - { - undump_int(x); /* pool_size */ - - if (x < 0) - goto bad_fmt; - -#ifdef ALLOCATESTRING - if (x > current_pool_size) - { - if (trace_flag) - printf("undump string pool reallocation (%lld > %d)\n", x, current_pool_size); - - str_pool = realloc_str_pool(x - current_pool_size + increment_pool_size); - } - - if (x > current_pool_size) -#else - if (x > pool_size) -#endif - { - printf("%s%s\n", "---! Must increase the ", "string pool size"); - goto bad_fmt; - } - else - pool_ptr = x; - } - - { - undump_int(x); /* max_strings */ - - if (x < 0) - goto bad_fmt; - -#ifdef ALLOCATESTRING - if (x > current_max_strings) - { - if (trace_flag) - printf("undump string pointer reallocation (%lld > %d)\n", x, current_max_strings); - - str_start = realloc_str_start(x - current_max_strings + increment_max_strings); - } - - if (x > current_max_strings) -#else - if (x > max_strings) -#endif - { - printf("%s%s\n", "---! Must increase the ", "max strings"); - goto bad_fmt; - } - else - str_ptr = x; - } - - undumpthings(str_start[0], str_ptr + 1); - undumpthings(str_pool[0], pool_ptr); - init_str_ptr = str_ptr; - init_pool_ptr = pool_ptr; - undump(lo_mem_stat_max + 1000, hi_mem_stat_min - 1, lo_mem_max); - undump(lo_mem_stat_max + 1, lo_mem_max, rover); - p = mem_bot; - q = rover; - - do - { - if (undumpthings(mem[p], q + 2 - p)) - return -1; - - p = q + node_size(q); - - if ((p > lo_mem_max) || ((q >= rlink(q)) && (rlink(q) != rover))) - goto bad_fmt; - - q = rlink(q); - } - while (!(q == rover)); - - if (undumpthings(mem[p], lo_mem_max + 1 - p)) - return -1; - - if (mem_min < mem_bot - 2) - { -/* or call add_variable_space(mem_bot - (mem_min + 1)) */ - if (trace_flag) - puts("Splicing in mem_min space in undump!"); - - p = llink(rover); - q = mem_min + 1; - link(mem_min) = 0; /* null */ - info(mem_min) = 0; /* null */ - rlink(p) = q; - llink(rover) = q; - rlink(q) = rover; - llink(q) = p; - link(q) = empty_flag; - node_size(q) = mem_bot - q; - } - - undump(lo_mem_max + 1, hi_mem_stat_min, hi_mem_min); - undump(mem_bot, mem_top, avail); - mem_end = mem_top; - - if (undumpthings(mem[hi_mem_min], mem_end + 1 - hi_mem_min)) - return -1; - - undump_int(var_used); - undump_int(dyn_used); - - k = active_base; - - do - { - undump_int(x); - - if ((x < 1) || (k + x > (eqtb_size + 1))) - goto bad_fmt; - - if (undumpthings(eqtb[k], x)) - return -1; - - k = k + x; - undump_int(x); - - if ((x < 0) || (k + x > (eqtb_size + 1))) - goto bad_fmt; - - for (j = k; j <= k + x - 1; j++) - eqtb[j] = eqtb[k - 1]; - - k = k + x; - } - while (!(k > eqtb_size)); - - undump(hash_base, frozen_control_sequence, par_loc); - par_token = cs_token_flag + par_loc; - undump(hash_base, frozen_control_sequence, write_loc); - undump(hash_base, frozen_control_sequence, hash_used); - - p = hash_base - 1; - - do - { - undump(p + 1, hash_used, p); - undump_hh(hash[p]); - } - while (!(p == hash_used)); - - if (undumpthings(hash[hash_used + 1], undefined_control_sequence - 1 - hash_used)) - return -1; - - undump_int(cs_count); - - if (trace_flag) - printf("itex undump cs_count %lld ", cs_count); - - { - undump_int(x); /* font_mem_size */ - - if (x < 7) - goto bad_fmt; - -#ifdef ALLOCATEFONT - if (trace_flag) - printf("Read from fmt fmem_ptr = %lld\n", x); - - if (x > current_font_mem_size) - { - if (trace_flag) - printf("Undump realloc font_info (%lld > %d)\n", x, current_font_mem_size); - - font_info = realloc_font_info (x - current_font_mem_size + increment_font_mem_size); - } - - if (x > current_font_mem_size) -#else - if (x > font_mem_size) -#endif - { - puts("---! Must increase the font mem size"); - goto bad_fmt; - } - else - fmem_ptr = x; - } - - { - undumpthings(font_info[0], fmem_ptr); - undump_size(font_base, font_max, "font max", font_ptr); - frozen_font_ptr = font_ptr; - undumpthings(font_check[0], font_ptr + 1); - undumpthings(font_size[0], font_ptr + 1); - undumpthings(font_dsize[0], font_ptr + 1); - undumpthings(font_params[0], font_ptr + 1); - undumpthings(hyphen_char[0], font_ptr + 1); - undumpthings(skew_char[0], font_ptr + 1); - undumpthings(font_name[0], font_ptr + 1); - undumpthings(font_area[0], font_ptr + 1); - undumpthings(font_bc[0], font_ptr + 1); - undumpthings(font_ec[0], font_ptr + 1); - undumpthings(char_base[0], font_ptr + 1); - undumpthings(width_base[0], font_ptr + 1); - undumpthings(height_base[0], font_ptr + 1); - undumpthings(depth_base[0], font_ptr + 1); - undumpthings(italic_base[0], font_ptr + 1); - undumpthings(lig_kern_base[0], font_ptr + 1); - undumpthings(kern_base[0], font_ptr + 1); - undumpthings(exten_base[0], font_ptr + 1); - undumpthings(param_base[0], font_ptr + 1); - undumpthings(font_glue[0], font_ptr + 1); - undumpthings(bchar_label[0], font_ptr + 1); - undumpthings(font_bchar[0], font_ptr + 1); - undumpthings(font_false_bchar[0], font_ptr + 1); - } - -/* log not opened yet, so can't show fonts frozen into format */ -/* May be able to avoid the following since we switched to */ -/* non_address from font_mem_size to 0 96/Jan/15 ??? */ - -#ifdef ALLOCATEFONT - { - int count = 0, oldfont_mem_size = 0; - - for (x = 0; x <= font_ptr; x++) - { - if (bchar_label[x] > oldfont_mem_size) - oldfont_mem_size = bchar_label[x]; - } - - if (oldfont_mem_size != non_address && oldfont_mem_size > font_max) - { - for (x = 0; x <= font_ptr; x++) - { - if (bchar_label[x] == oldfont_mem_size) - { - bchar_label[x] = non_address; - count++; - } - } - - if (trace_flag) - printf("oldfont_mem_size is %d --- hit %d times. Using non_address %d\n", - oldfont_mem_size, count, non_address); - } - } -#endif - - undump(0, hyphen_prime, hyph_count); - - for (k = 1; k <= hyph_count; k++) - { - undump(0, hyphen_prime, j); - undump(0, str_ptr, hyph_word[j]); - undump(0, max_halfword, hyph_list[j]); - } - -#ifdef ALLOCATEHYPHEN -/* if user specified new hyphen prime - flush existing exception patterns ! */ -/* but, we can reclaim the string storage wasted ... */ - if (is_initex) - { - if (new_hyphen_prime != 0) - { - realloc_hyphen(new_hyphen_prime); /* reset_hyphen(); */ - hyphen_prime = new_hyphen_prime; - } - } -#endif - - { - undump_int(x); - - if (x < 0) - goto bad_fmt; - -#ifdef ALLOCATETRIES - if (!is_initex) - { - allocate_tries(x); /* allocate only as much as is needed */ - } -#endif - - if (x > trie_size) - { - puts("---! Must increase the trie size"); - goto bad_fmt; - } - else - j = x; - } - -#ifdef INITEX - if (is_initex) - trie_max = j; -#endif - - undumpthings(trie_trl[0], j + 1); - undumpthings(trie_tro[0], j + 1); - undumpthings(trie_trc[0], j + 1); - undump_size(0, trie_op_size, "trie op size", j); - -#ifdef INITEX - if (is_initex) - trie_op_ptr = j; -#endif - - undumpthings(hyf_distance[1], j); - undumpthings(hyf_num[1], j); - undumpthings(hyf_next[1], j); - -#ifdef INITEX - if (is_initex) - { - for (k = 0; k <= 255; k++) - trie_used[k] = min_quarterword; - } -#endif - - k = 256; - - while (j > 0) - { - undump(0, k - 1, k); - undump(1, j, x); - -#ifdef INITEX - if (is_initex) - trie_used[k] = x; -#endif - - j = j - x; - op_start[k] = j; - } - -#ifdef INITEX - if (is_initex) - trie_not_ready = false; -#endif - - undump(batch_mode, error_stop_mode, interaction); - undump(0, str_ptr, format_ident); - undump_int(x); - - if ((x != ENDFMTCHECKSUM) || feof(fmt_file)) - goto bad_fmt; - - return true; - -bad_fmt: - puts("(Fatal format file error; I'm stymied)"); - - return false; -} -/* sec 1335 */ -void final_cleanup (void) -{ - small_number c; - - c = cur_chr; - - if (job_name == 0) - open_log_file(); - - while (input_ptr > 0) - { - if (state == token_list) - end_token_list(); - else - end_file_reading(); - } - - while (open_parens > 0) - { - prints(" )"); - decr(open_parens); - } - - if (cur_level > level_one) - { - print_nl("("); - print_esc("end occurred "); - prints("inside a group at level "); - print_int(cur_level - 1); - print_char(')'); - } - - while (cond_ptr != 0) - { - print_nl("("); - print_esc("end occurred "); - prints("when "); - print_cmd_chr(if_test, cur_if); - - if (if_line != 0) - { - prints("on line "); - print_int(if_line); - } - - prints(" was incomplete)"); - if_line = if_line_field(cond_ptr); - cur_if = subtype(cond_ptr); - temp_ptr = cond_ptr; - cond_ptr = link(cond_ptr); - free_node(temp_ptr, if_node_size); - } - - if (history != spotless) - if (((history == warning_issued) || (interaction < error_stop_mode))) - if (selector == term_and_log) - { - selector = term_only; - print_nl("(see the transcript file for additional information)"); - selector = term_and_log; - } - - if (c == 1) - { -#ifdef INITEX - if (is_initex) - { - for (c = 0; c <= 4; c++) - if (cur_mark[c] != 0) - delete_token_ref(cur_mark[c]); - - if (last_glue != max_halfword) - delete_glue_ref(last_glue); - - store_fmt_file(); - } -#endif - - if (!is_initex) - print_nl("(\\dump is performed only by INITEX)"); - } -} - -void show_frozen (void) -{ - int i; - - fprintf(log_file, "\n(%lld fonts frozen in format file:\n", font_ptr); - - for (i = 1; i <= font_ptr; i++) - { - if (i > 1) - fprintf(log_file, ", "); - - if ((i % 8) == 0) - fprintf(log_file, "\n"); - - fwrite(&str_pool[str_start[font_name[i]]], 1, length(font_name[i]), log_file); - } - - fprintf(log_file, ") "); -} - -int main_program (void) -{ - history = fatal_error_stop; - - if (ready_already == 314159L) - goto start_of_TEX; - - bad = 0; - - if ((half_error_line < 30) || (half_error_line > error_line - 15)) - bad = 1; - - if (max_print_line < 60) - bad = 2; - - if (dvi_buf_size % 8 != 0) - bad = 3; - - if (mem_bot + 1100 > mem_top) - bad = 4; - - if (hash_prime > (hash_size + hash_extra)) - bad = 5; - - if (max_in_open >= 128) - bad = 6; - - if (mem_top < 256 + 11) - bad = 7; - -#ifdef INITEX - if (is_initex) - { - if ((mem_min != 0) || (mem_max != mem_top)) - bad = 10; - } -#endif - - if ((mem_min > mem_bot) || (mem_max < mem_top)) - bad = 10; - - if ((min_quarterword > 0) || (max_quarterword < 255)) - bad = 11; - - if ((min_halfword > 0) || (max_halfword < 32767)) - bad = 12; - - if ((min_quarterword < min_halfword) || (max_quarterword > max_halfword)) - bad = 13; - - if ((mem_min < min_halfword) || (mem_max >= max_halfword) || (mem_bot - mem_min >= max_halfword)) - bad = 14; - - if (mem_max > mem_top + mem_extra_high) - bad = 14; - - if ((0 < min_quarterword) || (font_max > max_quarterword)) - bad = 15; - -#ifdef INCREASEFONTS - if (font_max > 65535) -#else - if (font_max > 256) -#endif - bad = 16; - - if ((save_size > max_halfword) || (max_strings > max_halfword)) - bad = 17; - - if (buf_size > max_halfword) - bad = 18; - - if (max_quarterword - min_quarterword < 255) - bad = 19; - - if (cs_token_flag + undefined_control_sequence > max_halfword) - bad = 21; - - if (format_default_length > file_name_size) - bad = 31; - - if (max_halfword < (mem_top - mem_min) / 2) - bad = 41; - - if (bad > 0) - { - printf("%s%s%ld\n", "Ouch---my internal constants have been clobbered!", - "---case ", (long) bad); - - goto final_end; - } - - initialize(); - -#ifdef INITEX - if (is_initex) - { - if (!get_strings_started()) - goto final_end; - - init_prim(); - init_str_ptr = str_ptr; - init_pool_ptr = pool_ptr; - fix_date_and_time(); - } -#endif - - ready_already = 314159L; - -start_of_TEX: - selector = term_only; - tally = 0; - term_offset = 0; - file_offset = 0; - - print_banner(); - - if (format_ident == 0) - { - prints(" (preloaded format="); - prints(format_name); - prints(")"); - print_ln(); - } - else - { - slow_print(format_ident); - print_ln(); - } - - update_terminal(); - job_name = 0; - name_in_progress = false; - log_opened = false; - output_file_name = 0; - - { - { - input_ptr = 0; - max_in_stack = 0; - in_open = 0; - high_in_open = 0; - open_parens = 0; - max_open_parens = 0; - max_buf_stack = 0; - param_ptr = 0; - max_param_stack = 0; - -#ifdef ALLOCATEBUFFER - memset (buffer, 0, current_buf_size); -#else - memset (buffer, 0, buf_size); -#endif - - first = 0; - scanner_status = 0; - warning_index = 0; - first = 1; - state = new_line; - start = 1; - index = 0; - line = 0; - name = 0; - force_eof = false; - align_state = 1000000L; - - if (!init_terminal()) - goto final_end; - - limit = last; - first = last + 1; - } - - if ((format_ident == 0) || (buffer[loc] == '&') || (buffer[loc] == '+')) - { - if (format_ident != 0) - initialize(); - - if (!open_fmt_file()) - goto final_end; - - if (!load_fmt_file()) - { -#ifdef COMPACTFORMAT - gzclose(gz_fmt_file); -#else - w_close(fmt_file); -#endif - goto final_end; - } - -#ifdef COMPACTFORMAT - gzclose(gz_fmt_file); -#else - w_close(fmt_file); -#endif - - while ((loc < limit) && (buffer[loc] == ' ')) - incr(loc); - } - - if (end_line_char_inactive()) - decr(limit); - else - buffer[limit] = end_line_char; - - fix_date_and_time(); - magic_offset = str_start[886] - 9 * ord_noad; - - if (interaction == batch_mode) - selector = no_print; - else - selector = term_only; - - if ((loc < limit) && (cat_code(buffer[loc]) != escape)) - start_input(); - } - - if (show_tfm_flag && log_opened && font_ptr > 0) - show_frozen(); - - main_time = clock(); - history = spotless; - - if (show_cs_names) - print_cs_names(stdout, 0); - - main_control(); - - if (show_cs_names) - print_cs_names(stdout, 1); - - final_cleanup(); - close_files_and_terminate(); - -final_end: - { - int code; - - update_terminal(); - ready_already = 0; - - if ((history != spotless) && (history != warning_issued)) - code = 1; - else - code = 0; - - return code; - } -} - -#ifdef ALLOCATEMAIN -/* add a block of variable size node space below mem_bot(0) */ -void add_variable_space(int size) -{ - halfword p; - halfword q; - integer t; - - if (mem_min == 0) - t = mem_min; - else - t = mem_min + 1; - - mem_min = t - (size + 1); /* first word in new block - 1 */ - - if (mem_min < mem_start) - { - if (trace_flag) - puts("WARNING: mem_min < mem_start!"); - - mem_min = mem_start; - } - - p = llink(rover); - q = mem_min + 1; - link(mem_min) = 0; /* insert blank word below ??? */ - info(mem_min) = 0; /* insert blank word below ??? */ - rlink(p) = q; - llink(rover) = q; - rlink(q) = rover; - llink(q) = p; - link(q) = empty_flag; - info(q) = t - q; /* block size */ - rover = q; -} -#endif - -#ifdef INITEX -/* split out to allow sharing of code from do_initex and newpattern */ -void reset_trie (void) -{ - integer k; - - for (k = -(integer) trie_op_size; k <= trie_op_size; k++) - trie_op_hash[k] = 0; - - for (k = 0; k <= 255; k++) - trie_used[k] = min_trie_op; - - max_op_used = min_trie_op; - trie_op_ptr = 0; - trie_not_ready = true; - trie_l[0] = 0; - trie_c[0] = 0; - trie_ptr = 0; - trie_not_ready = true; -} -/* borrowed code from initialize() */ -void reset_hyphen(void) -{ - hyph_pointer z; - - for (z = 0; z <= hyphen_prime; z++) - { - hyph_word[z] = 0; - hyph_list[z] = 0; - } - - hyph_count = 0; -} -/* split out to allow optimize for space, not time */ -void do_initex (void) -{ - /* integer i; */ - integer k; - /* hyph_pointer z; */ - - for (k = mem_bot + 1; k <= lo_mem_stat_max; k++) - mem[k].cint = 0; - - k = mem_bot; - - while (k <= lo_mem_stat_max) - { - glue_ref_count(k) = 1; - stretch_order(k) = normal; - shrink_order(k) = normal; - k = k + glue_spec_size; - } - - stretch(fil_glue) = unity; - stretch_order(fil_glue) = fil; - stretch(fill_glue) = unity; - stretch_order(fill_glue) = fill; - stretch(ss_glue) = unity; - stretch_order(ss_glue) = fil; - shrink(ss_glue) = unity; - shrink_order(ss_glue) = fil; - stretch(fil_neg_glue) = -unity; - stretch_order(fil_neg_glue) = fil; - rover = lo_mem_stat_max + 1; - link(rover) = empty_flag; - node_size(rover) = block_size; - llink(rover) = rover; - rlink(rover) = rover; - lo_mem_max = rover + block_size; - link(lo_mem_max) = 0; - info(lo_mem_max) = 0; - - for (k = hi_mem_stat_min; k <= mem_top; k++) - mem[k] = mem[lo_mem_max]; - - info(omit_template) = end_template_token; - link(end_span) = max_quarterword + 1; - info(end_span) = 0; - type(last_active) = hyphenated; - line_number(last_active) = max_halfword; - subtype(last_active) = 0; - subtype(page_ins_head) = 255; - type(page_ins_head) = split_up; - link(mem_top) = page_ins_head; - type(page_head) = glue_node; - subtype(page_head) = normal; - avail = 0; - mem_end = mem_top; - hi_mem_min = hi_mem_stat_min; - var_used = lo_mem_stat_max + 1 - mem_bot; - dyn_used = hi_mem_stat_usage; - eq_type(undefined_control_sequence) = undefined_cs; - equiv(undefined_control_sequence) = 0; - eq_level(undefined_control_sequence) = level_zero; - - for (k = active_base; k <= undefined_control_sequence - 1; k++) - eqtb[k] = eqtb[undefined_control_sequence]; - - equiv(glue_base) = zero_glue; - eq_level(glue_base) = level_one; - eq_type(glue_base) = glue_ref; - - for (k = glue_base + 1; k <= local_base - 1; k++) - eqtb[k] = eqtb[glue_base]; - - glue_ref_count(zero_glue) = glue_ref_count(zero_glue) + local_base - glue_base; - - par_shape_ptr = 0; - eq_type(par_shape_loc) = shape_ref; - eq_level(par_shape_loc) = level_one; - - for (k = output_routine_loc; k <= toks_base + 255; k++) - eqtb[k] = eqtb[undefined_control_sequence]; - - box(0) = 0; - eq_type(box_base) = box_ref; - eq_level(box_base) = level_one; - - for (k = box_base + 1; k <= box_base + 255; k++) - eqtb[k] = eqtb[box_base]; - - cur_font = null_font; - eq_type(cur_font_loc) = data; - eq_level(cur_font_loc) = level_one; - - for (k = math_font_base; k <= math_font_base + 47; k++) - eqtb[k] = eqtb[cur_font_loc]; - - equiv(cat_code_base) = 0; - eq_type(cat_code_base) = data; - eq_level(cat_code_base) = level_one; - - for (k = cat_code_base; k <= int_base - 1; k++) - eqtb[k] = eqtb[cat_code_base]; - - for (k = 0; k <= 255; k++) - { - cat_code(k) = other_char; - math_code(k) = k; - sf_code(k) = 1000; - } - - cat_code(carriage_return) = car_ret; - cat_code(' ') = spacer; - cat_code('\\') = escape; - cat_code('%') = comment; - cat_code(invalid_code) = invalid_char; - cat_code(null_code) = ignore; - - for (k = '0'; k <= '9'; k++) - math_code(k) = k + var_code; - - for (k = 'A'; k <= 'Z'; k++) - { - cat_code(k) = letter; - cat_code(k + 'a' - 'A') = letter; - math_code(k) = k + var_code + 0x100; - math_code(k + 'a' - 'A') = k + 'a' - 'A' + var_code + 0x100; - lc_code(k) = k + 'a' - 'A'; - lc_code(k + 'a' - 'A') = k + 'a' - 'A'; - uc_code(k) = k; - uc_code(k + 'a' - 'A') = k; - sf_code(k) = 999; - } - - for (k = int_base; k <= del_code_base - 1; k++) - eqtb[k].cint = 0; - - mag = 1000; - tolerance = 10000; - hang_after = 1; - max_dead_cycles = 25; - escape_char = '\\'; - end_line_char = carriage_return; - - for (k = 0; k <= 255; k++) - del_code(k) = -1; - - del_code('.') = 0; - - for (k = dimen_base; k <= eqtb_size; k++) - eqtb[k].cint = 0; - - hash_used = frozen_control_sequence; - cs_count = 0; - - if (trace_flag) - puts("initex cs_count = 0 "); - - eq_type(frozen_dont_expand) = dont_expand; - text(frozen_dont_expand) = 499; /* "notexpanded:" */ - - font_ptr = null_font; - fmem_ptr = 7; - font_name[null_font] = 795; /* nullfont */ - font_area[null_font] = 335; /* "" */ - hyphen_char[null_font] = '-'; - skew_char[null_font] = -1; - bchar_label[null_font] = non_address; - font_bchar[null_font] = non_char; - font_false_bchar[null_font] = non_char; - font_bc[null_font] = 1; - font_ec[null_font] = 0; - font_size[null_font] = 0; - font_dsize[null_font] = 0; - char_base[null_font] = 0; - width_base[null_font] = 0; - height_base[null_font] = 0; - depth_base[null_font] = 0; - italic_base[null_font] = 0; - lig_kern_base[null_font] = 0; - kern_base[null_font] = 0; - exten_base[null_font] = 0; - font_glue[null_font] = 0; - font_params[null_font] = 7; - param_base[null_font] = -1; - - for (k = 0; k <= 6; k++) - font_info[k].cint = 0; - - reset_trie(); - text(frozen_protection) = 1184; /* "inaccessible" */ - format_ident = 1251; /* " (INITEX)" */ - text(end_write) = 1290; /* "endwrite" */ - eq_level(end_write) = level_one; - eq_type(end_write) = outer_call; - equiv(end_write) = 0; -} -#endif - -#ifdef INITEX -/* sec 0047 */ -boolean get_strings_started (void) -{ - integer k; - str_number g; - - pool_ptr = 0; - str_ptr = 0; - str_start[0] = 0; - - for (k = 0; k <= 255; k++) - { - if ( (k < ' ') || (k > '~') ) - { - append_char('^'); - append_char('^'); - - if (k < 64) - append_char(k + 64); - else if (k < 128) - append_char(k - 64); - else - { - append_lc_hex(k / 16); - append_lc_hex(k % 16); - } - } - else - append_char(k); - - g = make_string(); - } - - g = load_pool_strings(pool_size - string_vacancies); - - if (g == 0) - { - printf("%s\n", "! You have to increase POOLSIZE." ); - return false; - } - - return true; -} -#endif - -#ifdef INITEX -/* sec 0131 */ -void sort_avail (void) -{ - pointer p, q, r; - pointer old_rover; - - p = get_node(010000000000); - p = rlink(rover); - rlink(rover) = empty_flag; - old_rover = rover; - - while (p != old_rover) - { - if (p < rover) - { - q = p; - p = rlink(q); - rlink(q) = rover; - rover = q; - } - else - { - q = rover; - - while (rlink(q) < p) - q = rlink(q); - - r = rlink(p); - rlink(p) = rlink(q); - rlink(q) = p; - p = r; - } - } - - p = rover; - - while (rlink(p) != empty_flag) - { - llink(rlink(p)) = p; - p = rlink(p); - } - - rlink(p) = rover; - llink(rover) = p; -} -#endif - -#ifdef INITEX -/* sec 0264 */ -void primitive_ (str_number s, quarterword c, halfword o) -{ - pool_pointer k; - small_number j; - /* small_number l; */ - int l; - - if (s < 256) - cur_val = s + single_base; - else - { - k = str_start[s]; - l = str_start[s + 1] - k; - - for (j = 0; j <= l - 1; j++) - buffer[j] = str_pool[k + j]; - - cur_val = id_lookup(0, l); - flush_string(); - text(cur_val) = s; - } - - eq_level(cur_val) = level_one; - eq_type(cur_val) = c; - equiv(cur_val) = o; -} -#endif - -#ifdef INITEX -/* sec 0944 */ -trie_op_code new_trie_op (small_number d, small_number n, trie_op_code v) -{ - integer h; - trie_op_code u; - integer l; - - h = abs(n + 313 * d + 361 * v + 1009 * cur_lang) % (trie_op_size + trie_op_size) + neg_trie_op_size; - - while (true) - { - l = trie_op_hash[h]; - - if (l == 0) - { - if (trie_op_ptr == trie_op_size) - { - overflow("pattern memory ops", trie_op_size); - return 0; - } - - u = trie_used[cur_lang]; - - if (u == max_trie_op) - { - overflow("pattern memory ops per language", max_trie_op - min_trie_op); - return 0; - } - - incr(trie_op_ptr); - incr(u); - trie_used[cur_lang] = u; - - if (u > max_op_used) - max_op_used = u; - - hyf_distance[trie_op_ptr] = d; - hyf_num[trie_op_ptr] = n; - hyf_next[trie_op_ptr] = v; - trie_op_lang[trie_op_ptr] = cur_lang; - trie_op_hash[h] = trie_op_ptr; - trie_op_val[trie_op_ptr] = u; - return u; - } - - if ((hyf_distance[l] == d) && (hyf_num[l] == n) && (hyf_next[l] == v) && (trie_op_lang[l] == cur_lang)) - { - return trie_op_val[l]; - } - - if (h > - (integer) trie_op_size) - decr(h); - else - h = trie_op_size; - } -} -/* sec 0948 */ -trie_pointer trie_node (trie_pointer p) -{ - trie_pointer h; - trie_pointer q; - - /* the 1009, 2718, 3142 are hard-wired constants here (not hyphen_prime) */ - /* compute hash value */ - h = abs(trie_c[p] + 1009 * trie_o[p] + 2718 * trie_l[p] + 3142 * trie_r[p]) % trie_size; - - while (true) - { - q = trie_hash[h]; - - if (q == 0) - { - trie_hash[h] = p; - return p; - } - - if ((trie_c[q] == trie_c[p]) && (trie_o[q] == trie_o[p]) && - (trie_l[q] == trie_l[p]) && (trie_r[q] == trie_r[p])) - { - return q; - } - - if (h > 0) - decr(h); - else - h = trie_size; - } -} -/* sec 0949 */ -trie_pointer compress_trie (trie_pointer p) -{ - if (p == 0) - return 0; - else - { - trie_l[p] = compress_trie(trie_l[p]); - trie_r[p] = compress_trie(trie_r[p]); - - return trie_node(p); - } -} -/* sec 0953 */ -void first_fit (trie_pointer p) -{ - trie_pointer h; - trie_pointer z; - trie_pointer q; - ASCII_code c; - trie_pointer l, r; - short ll; - - c = trie_c[p]; - z = trie_min[c]; - - while (true) - { - h = z - c; - - if (trie_max < h + 256) - { - if (trie_size <= h + 256) - { - overflow("pattern memory", trie_size); - return; - } - - do - { - incr(trie_max); - trie_taken[trie_max] = false; - trie_trl[trie_max] = trie_max + 1; - trie_tro[trie_max] = trie_max - 1; - } - while (!(trie_max == h + 256)); - } - - if (trie_taken[h]) - goto not_found; - - q = trie_r[p]; - - while (q > 0) - { - if (trie_trl[h + trie_c[q]] == 0) - goto not_found; - - q = trie_r[q]; - } - - goto found; - -not_found: - z = trie_trl[z]; - } - -found: - trie_taken[h] = true; - trie_hash[p] = h; - q = p; - - do - { - z = h + trie_c[q]; - l = trie_tro[z]; - r = trie_trl[z]; - trie_tro[r] = l; - trie_trl[l] = r; - trie_trl[z] = 0; - - if (l < 256) - { - if (z < 256) - ll = z; /* short ll */ - else - ll = 256; - - do - { - trie_min[l] = r; - incr(l); - } - while (!(l == ll)); - } - - q = trie_r[q]; - } - while (!(q == 0)); -} -/* sec 0957 */ -void trie_pack (trie_pointer p) -{ - trie_pointer q; - - do - { - q = trie_l[p]; - - if ((q > 0) && (trie_hash[q]== 0)) - { - first_fit(q); - trie_pack(q); - } - - p = trie_r[p]; - } - while (!(p == 0)); -} -/* sec 0959 */ -void trie_fix (trie_pointer p) -{ - trie_pointer q; - ASCII_code c; - trie_pointer z; - - z = trie_hash[p]; - - do - { - q = trie_l[p]; - c = trie_c[p]; - trie_trl[z + c] = trie_hash[q]; - trie_trc[z + c] = c; - trie_tro[z + c] = trie_o[p]; - - if (q > 0) - trie_fix(q); - - p = trie_r[p]; - } - while (!(p == 0)); -} -/* sec 0960 */ -void new_patterns (void) -{ - char k, l; - boolean digit_sensed; - trie_op_code v; - trie_pointer p, q; - boolean first_child; - /* ASCII_code c; */ - int c; - - if (!trie_not_ready) - { - if (allow_patterns) - { - if (trace_flag) - puts("Resetting patterns"); - - reset_trie(); - - if (reset_exceptions) - { - if (trace_flag) - puts("Resetting exceptions"); - - reset_hyphen(); - } - } - } - - if (trie_not_ready) - { - set_cur_lang(); - scan_left_brace(); - k = 0; - hyf[0] = 0; - digit_sensed = false; - - while (true) - { - get_x_token(); - - switch (cur_cmd) - { - case letter: - case other_char: - if (digit_sensed || (cur_chr < '0') || (cur_chr > '9')) - { - if (cur_chr == '.') - cur_chr = 0; - else - { - cur_chr = lc_code(cur_chr); - - if (cur_chr == 0) - { - print_err("Nonletter"); - help1("(See Appendix H.)"); - error(); - } - } - - if (k < 63) - { - incr(k); - hc[k] = cur_chr; - hyf[k] = 0; - digit_sensed = false; - } - } - else if (k < 63) - { - hyf[k] = cur_chr - '0'; - digit_sensed = true; - } - break; - case spacer: - case right_brace: - { - if (k > 0) - { - if (hc[1] == 0) - hyf[0] = 0; - - if (hc[k] == 0) - hyf[k] = 0; - - l = k; - v = min_trie_op; - - while (true) - { - if (hyf[l]!= 0) - v = new_trie_op(k - l, hyf[l], v); - - if (l > 0) - decr(l); - else - goto done1; - } -done1: - q = 0; - hc[0] = cur_lang; - - while (l <= k) - { - c = hc[l]; - incr(l); - p = trie_l[q]; - first_child = true; - - while ((p > 0) && (c > trie_c[p])) - { - q = p; - p = trie_r[q]; - first_child = false; - } - - if ((p == 0) || (c < trie_c[p])) - { - if (trie_ptr == trie_size) - { - overflow("pattern memory", trie_size); - return; - } - - incr(trie_ptr); - trie_r[trie_ptr] = p; - p = trie_ptr; - trie_l[p] = 0; - - if (first_child) - trie_l[q] = p; - else - trie_r[q] = p; - - trie_c[p] = c; - trie_o[p] = min_trie_op; - } - - q = p; - } - - if (trie_o[q] != min_trie_op) - { - print_err("Duplicate pattern"); - help1("(See Appendix H.)"); - error(); - } - - trie_o[q] = v; - } - - if (cur_cmd == right_brace) - goto done; - - k = 0; - hyf[0] = 0; - digit_sensed = false; - } - break; - default: - { - print_err("Bad "); - print_esc("patterns"); - help1("(See Appendix H.)"); - error(); - } - break; - } - } -done:; - } - else - { - print_err("Too late for "); - print_esc("patterns"); - help1("All patterns must be given before typesetting begins."); - error(); - link(garbage) = scan_toks(false, false); - flush_list(def_ref); - } -} -/* sec 0966 */ -void init_trie (void) -{ - trie_pointer p; - /* integer j, k, t; */ - integer j, k; - int t; - trie_pointer r, s; - - op_start[0] = - (integer) min_trie_op; - - for (j = 1; j <= 255; j++) - op_start[j] = op_start[j - 1] + trie_used[j - 1]; - - for (j = 1; j <= trie_op_ptr; j++) - trie_op_hash[j] = op_start[trie_op_lang[j]] + trie_op_val[j]; - - for (j = 1; j <= trie_op_ptr; j++) - { - while (trie_op_hash[j] > j) - { - k = trie_op_hash[j]; - t = hyf_distance[k]; - hyf_distance[k] = hyf_distance[j]; - hyf_distance[j] = t; - t = hyf_num[k]; - hyf_num[k] = hyf_num[j]; - hyf_num[j] = t; - t = hyf_next[k]; - hyf_next[k] = hyf_next[j]; - hyf_next[j]= t; - trie_op_hash[j] = trie_op_hash[k]; - trie_op_hash[k] = k; - } - } - - for (p = 0; p <= trie_size; p++) - trie_hash[p] = 0; - - trie_l[0] = compress_trie(trie_l[0]); - - for (p = 0; p <= trie_ptr; p++) - trie_hash[p] = 0; - - for (p = 0; p <= 255; p++) - trie_min[p] = p + 1; - - trie_trl[0] = 1; - trie_max = 0; - - if (trie_l[0] != 0) - { - first_fit(trie_l[0]); - trie_pack(trie_l[0]); - } - - if (trie_l[0] == 0) - { - for (r = 0; r <= 256; r++) - { - trie_trl[r] = 0; - trie_tro[r] = min_trie_op; - trie_trc[r] = 0; - } - - trie_max = 256; - } - else - { - trie_fix(trie_l[0]); - r = 0; - - do - { - s = trie_trl[r]; - - { - trie_trl[r] = 0; - trie_tro[r] = min_trie_op; - trie_trc[r] = 0; - } - - r = s; - } - while (!(r > trie_max)); - } - - trie_trc[0] = 63; - trie_not_ready = false; -} -#endif - -#ifdef INITEX -/* sec 1302 */ -void store_fmt_file (void) -{ - integer j, k, l; - pointer p, q; - integer x; - - if (!is_initex) - { - puts("! \\dump is performed only by INITEX"); - - if (!knuth_flag) - puts(" (Use -i on the command line)"); - - return; - } - - if (save_ptr != 0) - { - print_err("You can't dump inside a group"); - help1("`{...\\dump}' is a no-no."); - succumb(); - } - - selector = new_string; - prints(" (preloaded format="); - print(job_name); - print_char(' '); - print_int(year); - print_char('.'); - print_int(month); - print_char('.'); - print_int(day); - print_char(')'); - - if (interaction == batch_mode) - selector = log_only; - else - selector = term_and_log; - - str_room(1); - format_ident = make_string(); - pack_job_name(".fmt"); - - while (!w_open_out(fmt_file)) - prompt_file_name("format file name", ".fmt"); - - print_nl("Beginning to dump on file "); - slow_print(w_make_name_string(fmt_file)); - flush_string(); - print_nl(""); - slow_print(format_ident); - - dump_int(BEGINFMTCHECKSUM); - dump_int(mem_bot); - dump_int(mem_top); - dump_int(eqtb_size); - dump_int(hash_prime); - dump_int(hyphen_prime); - dump_int(pool_ptr); - dump_int(str_ptr); - dumpthings(str_start[0], str_ptr + 1); - dumpthings(str_pool[0], pool_ptr); - print_ln(); - print_int(str_ptr); - prints(" strings of total length "); - print_int(pool_ptr); - - sort_avail(); - var_used = 0; - dump_int(lo_mem_max); - dump_int(rover); - p = 0; - q = rover; - x = 0; - - do - { - if (dumpthings(mem[p], q + 2 - p)) - return; - - x = x + q + 2 - p; - var_used = var_used + q - p; - p = q + node_size(q); - q = rlink(q); - } - while (!(q == rover)); - - var_used = var_used + lo_mem_max - p; - dyn_used = mem_end + 1 - hi_mem_min; - - if (dumpthings(mem[p], lo_mem_max + 1 - p)) - return; - - x = x + lo_mem_max + 1 - p; - dump_int(hi_mem_min); - dump_int(avail); - - if (dumpthings(mem[hi_mem_min], mem_end + 1 - hi_mem_min)) - return; - - x = x + mem_end + 1 - hi_mem_min; - p = avail; - - while (p != 0) - { - decr(dyn_used); - p = link(p); - } - - dump_int(var_used); - dump_int(dyn_used); - print_ln(); - print_int(x); - prints(" memory locations dumped; current usage is "); - print_int(var_used); - print_char('&'); - print_int(dyn_used); - - k = active_base; - - do - { - j = k; - - while (j < (int_base - 1)) - { - if ((equiv(j) == equiv(j + 1)) && - (eq_type(j) == eq_type(j + 1)) && - (eq_level(j) == eq_level(j + 1))) - goto found1; - - incr(j); - } - - l = (int_base); - goto done1; - -found1: - incr(j); - l = j; - - while (j < (int_base - 1)) - { - if ((equiv(j) != equiv(j + 1)) || - (eq_type(j) != eq_type(j + 1)) || - (eq_level(j) != eq_level(j + 1))) - goto done1; - - incr(j); - } - -done1: - dump_int(l - k); - - if (dumpthings(eqtb[k], l - k)) - return; - - k = j + 1; - dump_int(k - l); - } - while (!(k == (int_base))); - - do - { - j = k; - - while (j < (eqtb_size)) - { - if (eqtb[j].cint == eqtb[j + 1].cint) - goto found2; - - incr(j); - } - - l = (eqtb_size + 1); - goto done2; - -found2: - incr(j); - l = j; - - while (j < (eqtb_size)) - { - if (eqtb[j].cint != eqtb[j + 1].cint) - goto done2; - - incr(j); - } - -done2: - dump_int(l - k); - - if (dumpthings(eqtb[k], l - k)) - return; - - k = j + 1; - dump_int(k - l); - } - while (!(k > (eqtb_size))); - - dump_int(par_loc); - dump_int(write_loc); - - dump_int(hash_used); - cs_count = frozen_control_sequence - 1 - hash_used; - - if (trace_flag) - printf("itex cs_count %lld hash_size %d hash_extra %d hash_used %d", - cs_count, hash_size, hash_extra, hash_used); - - for (p = hash_base; p <= hash_used; p++) - { - if (text(p) != 0) - { - dump_int(p); - dump_hh(hash[p]); - incr(cs_count); - - if (trace_flag) - puts("itex.c store_fmt_file() cs_count++ "); - } - } - - if (dumpthings(hash[hash_used + 1], undefined_control_sequence - 1 - hash_used)) - return; - - dump_int(cs_count); - print_ln(); - print_int(cs_count); - prints(" multiletter control sequences"); - - dump_int(fmem_ptr); - - { - dumpthings(font_info[0], fmem_ptr); - dump_int(font_ptr); - dumpthings(font_check[0], font_ptr + 1); - dumpthings(font_size[0], font_ptr + 1); - dumpthings(font_dsize[0], font_ptr + 1); - dumpthings(font_params[0], font_ptr + 1); - dumpthings(hyphen_char[0], font_ptr + 1); - dumpthings(skew_char[0], font_ptr + 1); - dumpthings(font_name[0], font_ptr + 1); - dumpthings(font_area[0], font_ptr + 1); - dumpthings(font_bc[0], font_ptr + 1); - dumpthings(font_ec[0], font_ptr + 1); - dumpthings(char_base[0], font_ptr + 1); - dumpthings(width_base[0], font_ptr + 1); - dumpthings(height_base[0], font_ptr + 1); - dumpthings(depth_base[0], font_ptr + 1); - dumpthings(italic_base[0], font_ptr + 1); - dumpthings(lig_kern_base[0], font_ptr + 1); - dumpthings(kern_base[0], font_ptr + 1); - dumpthings(exten_base[0], font_ptr + 1); - dumpthings(param_base[0], font_ptr + 1); - dumpthings(font_glue[0], font_ptr + 1); - dumpthings(bchar_label[0], font_ptr + 1); - dumpthings(font_bchar[0], font_ptr + 1); - dumpthings(font_false_bchar[0], font_ptr + 1); - - for (k = 0; k <= font_ptr; k++) - { - print_nl("\\font"); - print_esc(""); - print(font_id_text(k)); - print_char('='); - print_file_name(font_name[k], font_area[k], 335); - - if (font_size[k] != font_dsize[k]) - { - prints(" at "); - print_scaled(font_size[k]); - prints("pt"); - } - } - } - - print_ln(); - print_int(fmem_ptr - 7); - prints(" words of font info for "); - print_int(font_ptr - font_base); - prints(" preloaded font"); - - if (font_ptr != font_base + 1) - print_char('s'); - - dump_int(hyph_count); - - for (k = 0; k <= hyphen_prime; k++) - { - if (hyph_word[k] != 0) - { - dump_int(k); - dump_int(hyph_word[k]); - dump_int(hyph_list[k]); - } - } - - print_ln(); - print_int(hyph_count); - prints(" hyphenation exception"); - - if (hyph_count != 1) - print_char('s'); - - if (trie_not_ready) - init_trie(); - - dump_int(trie_max); - dumpthings(trie_trl[0], trie_max + 1); - dumpthings(trie_tro[0], trie_max + 1); - dumpthings(trie_trc[0], trie_max + 1); - dump_int(trie_op_ptr); - dumpthings(hyf_distance[1], trie_op_ptr); - dumpthings(hyf_num[1], trie_op_ptr); - dumpthings(hyf_next[1], trie_op_ptr); - print_nl("Hyphenation trie of length "); - print_int(trie_max); - prints(" has "); - print_int(trie_op_ptr); - prints(" op"); - - if (trie_op_ptr != 1) - print_char('s'); - - prints(" out of "); - print_int(trie_op_size); - - for (k = 255; k >= 0; k--) - { - if (trie_used[k] > 0) - { - print_nl(" "); - print_int(trie_used[k]); - prints(" for language "); - print_int(k); - dump_int(k); - dump_int(trie_used[k]); - } - } - - dump_int(interaction); - dump_int(format_ident); - dump_int(ENDFMTCHECKSUM); - tracing_stats = 0; - -#ifdef COMPACTFORMAT - gz_w_close(gz_fmt_file); -#else - w_close(fmt_file); -#endif -} -#endif - -#ifdef INITEX -/* sec 01336 */ -void init_prim (void) -{ - no_new_control_sequence = false; - /* sec 0266 */ - primitive("lineskip", assign_glue, glue_base + line_skip_code); - primitive("baselineskip", assign_glue, glue_base + baseline_skip_code); - primitive("parskip", assign_glue, glue_base + par_skip_code); - primitive("abovedisplayskip", assign_glue, glue_base + above_display_skip_code); - primitive("belowdisplayskip", assign_glue, glue_base + below_display_skip_code); - primitive("abovedisplayshortskip", assign_glue, glue_base + above_display_short_skip_code); - primitive("belowdisplayshortskip", assign_glue, glue_base + below_display_short_skip_code); - primitive("leftskip", assign_glue, glue_base + left_skip_code); - primitive("rightskip", assign_glue, glue_base + right_skip_code); - primitive("topskip", assign_glue, glue_base + top_skip_code); - primitive("splittopskip", assign_glue, glue_base + split_top_skip_code); - primitive("tabskip", assign_glue, glue_base + tab_skip_code); - primitive("spaceskip", assign_glue, glue_base + space_skip_code); - primitive("xspaceskip", assign_glue, glue_base + xspace_skip_code); - primitive("parfillskip", assign_glue, glue_base + par_fill_skip_code); - primitive("thinmuskip", assign_mu_glue, glue_base + thin_mu_skip_code); - primitive("medmuskip", assign_mu_glue, glue_base + med_mu_skip_code); - primitive("thickmuskip", assign_mu_glue, glue_base + thick_mu_skip_code); - /* sec 0230 */ - primitive("output", assign_toks, output_routine_loc); - primitive("everypar", assign_toks, every_par_loc); - primitive("everymath", assign_toks, every_math_loc); - primitive("everydisplay", assign_toks, every_display_loc); - primitive("everyhbox", assign_toks, every_hbox_loc); - primitive("everyvbox", assign_toks, every_vbox_loc); - primitive("everyjob", assign_toks, every_job_loc); - primitive("everycr", assign_toks, every_cr_loc); - primitive("errhelp", assign_toks, err_help_loc); - /* sec 0238 */ - primitive("pretolerance", assign_int, int_base + pretolerance_code); - primitive("tolerance", assign_int, int_base + tolerance_code); - primitive("linepenalty", assign_int, int_base + line_penalty_code); - primitive("hyphenpenalty", assign_int, int_base + hyphen_penalty_code); - primitive("exhyphenpenalty", assign_int, int_base + ex_hyphen_penalty_code); - primitive("clubpenalty", assign_int, int_base + club_penalty_code); - primitive("widowpenalty", assign_int, int_base + widow_penalty_code); - primitive("displaywidowpenalty", assign_int, int_base + display_widow_penalty_code); - primitive("brokenpenalty", assign_int, int_base + broken_penalty_code); - primitive("binoppenalty", assign_int, int_base + bin_op_penalty_code); - primitive("relpenalty", assign_int, int_base + rel_penalty_code); - primitive("predisplaypenalty", assign_int, int_base + pre_display_penalty_code); - primitive("postdisplaypenalty", assign_int, int_base + post_display_penalty_code); - primitive("interlinepenalty", assign_int, int_base + inter_line_penalty_code); - primitive("doublehyphendemerits", assign_int, int_base + double_hyphen_demerits_code); - primitive("finalhyphendemerits", assign_int, int_base + final_hyphen_demerits_code); - primitive("adjdemerits", assign_int, int_base + adj_demerits_code); - primitive("mag", assign_int, int_base + mag_code); - primitive("delimiterfactor", assign_int, int_base + delimiter_factor_code); - primitive("looseness", assign_int, int_base + looseness_code); - primitive("time", assign_int, int_base + time_code); - primitive("day", assign_int, int_base + day_code); - primitive("month", assign_int, int_base + month_code); - primitive("year", assign_int, int_base + year_code); - primitive("showboxbreadth", assign_int, int_base + show_box_breadth_code); - primitive("showboxdepth", assign_int, int_base + show_box_depth_code); - primitive("hbadness", assign_int, int_base + hbadness_code); - primitive("vbadness", assign_int, int_base + vbadness_code); - primitive("pausing", assign_int, int_base + pausing_code); - primitive("tracingonline", assign_int, int_base + tracing_online_code); - primitive("tracingmacros", assign_int, int_base + tracing_macros_code); - primitive("tracingstats", assign_int, int_base + tracing_stats_code); - primitive("tracingparagraphs", assign_int, int_base + tracing_paragraphs_code); - primitive("tracingpages", assign_int, int_base + tracing_pages_code); - primitive("tracingoutput", assign_int, int_base + tracing_output_code); - primitive("tracinglostchars", assign_int, int_base + tracing_lost_chars_code); - primitive("tracingcommands", assign_int, int_base + tracing_commands_code); - primitive("tracingrestores", assign_int, int_base + tracing_restores_code); - primitive("uchyph", assign_int, int_base + uc_hyph_code); - primitive("outputpenalty", assign_int, int_base + output_penalty_code); - primitive("maxdeadcycles", assign_int, int_base + max_dead_cycles_code); - primitive("hangafter", assign_int, int_base + hang_after_code); - primitive("floatingpenalty", assign_int, int_base + floating_penalty_code); - primitive("globaldefs", assign_int, int_base + global_defs_code); - primitive("fam", assign_int, int_base + cur_fam_code); - primitive("escapechar", assign_int, int_base + escape_char_code); - primitive("defaulthyphenchar", assign_int, int_base + default_hyphen_char_code); - primitive("defaultskewchar", assign_int, int_base + default_skew_char_code); - primitive("endlinechar", assign_int, int_base + end_line_char_code); - primitive("newlinechar", assign_int, int_base + new_line_char_code); - primitive("language", assign_int, int_base + language_code); - primitive("lefthyphenmin", assign_int, int_base + left_hyphen_min_code); - primitive("righthyphenmin", assign_int, int_base + right_hyphen_min_code); - primitive("holdinginserts", assign_int, int_base + holding_inserts_code); - primitive("errorcontextlines", assign_int, int_base + error_context_lines_code); - /* sec 0248 */ - primitive("parindent", assign_dimen, dimen_base + par_indent_code); - primitive("mathsurround", assign_dimen, dimen_base + math_surround_code); - primitive("lineskiplimit", assign_dimen, dimen_base + line_skip_limit_code); - primitive("hsize", assign_dimen, dimen_base + hsize_code); - primitive("vsize", assign_dimen, dimen_base + vsize_code); - primitive("maxdepth", assign_dimen, dimen_base + max_depth_code); - primitive("splitmaxdepth", assign_dimen, dimen_base + split_max_depth_code); - primitive("boxmaxdepth", assign_dimen, dimen_base + box_max_depth_code); - primitive("hfuzz", assign_dimen, dimen_base + hfuzz_code); - primitive("vfuzz", assign_dimen, dimen_base + vfuzz_code); - primitive("delimitershortfall", assign_dimen, dimen_base + delimiter_shortfall_code); - primitive("nulldelimiterspace", assign_dimen, dimen_base + null_delimiter_space_code); - primitive("scriptspace", assign_dimen, dimen_base + script_space_code); - primitive("predisplaysize", assign_dimen, dimen_base + pre_display_size_code); - primitive("displaywidth", assign_dimen, dimen_base + display_width_code); - primitive("displayindent", assign_dimen, dimen_base + display_indent_code); - primitive("overfullrule", assign_dimen, dimen_base + overfull_rule_code); - primitive("hangindent", assign_dimen, dimen_base + hang_indent_code); - primitive("hoffset", assign_dimen, dimen_base + h_offset_code); - primitive("voffset", assign_dimen, dimen_base + v_offset_code); - primitive("emergencystretch", assign_dimen, dimen_base + emergency_stretch_code); - primitive(" ", ex_space, 0); - primitive("/", ital_corr, 0); - primitive("accent", accent, 0); - primitive("advance", advance, 0); - primitive("afterassignment", after_assignment, 0); - primitive("aftergroup", after_group, 0); - primitive("begingroup", begin_group, 0); - primitive("char", char_num, 0); - primitive("csname", cs_name, 0); - primitive("delimiter", delim_num, 0); - primitive("divide", divide, 0); - primitive("endcsname", end_cs_name, 0); - primitive("endgroup", end_group, 0); - text(frozen_end_group) = make_string_pool("endgroup"); - eqtb[frozen_end_group] = eqtb[cur_val]; - primitive("expandafter", expand_after, 0); - primitive("font", def_font, 0); - primitive("fontdimen", assign_font_dimen, 0); - primitive("halign", halign, 0); - primitive("hrule", hrule, 0); - primitive("ignorespaces", ignore_spaces, 0); - primitive("insert", insert, 0); - primitive("mark", mark, 0); - primitive("mathaccent", math_accent, 0); - primitive("mathchar", math_char_num, 0); - primitive("mathchoice", math_choice, 0); - primitive("multiply", multiply, 0); - primitive("noalign", no_align, 0); - primitive("noboundary", no_boundary, 0); - primitive("noexpand", no_expand, 0); - primitive("nonscript", non_script, 0); - primitive("omit", omit, 0); - primitive("parshape", set_shape, 0); - primitive("penalty", break_penalty, 0); - primitive("prevgraf", set_prev_graf, 0); - primitive("radical", radical, 0); - primitive("read", read_to_cs, 0); - primitive("relax", relax, 256); - text(frozen_relax) = make_string_pool("relax"); - eqtb[frozen_relax] = eqtb[cur_val]; - primitive("setbox", set_box, 0); - primitive("the", the, 0); - primitive("toks", toks_register, 0); - primitive("vadjust", vadjust, 0); - primitive("valign", valign, 0); - primitive("vcenter", vcenter, 0); - primitive("vrule", vrule, 0); - primitive("par", par_end, 256); - par_loc = cur_val; - par_token = cs_token_flag + par_loc; - primitive("input", input, 0); - primitive("endinput", input, 1); - primitive("topmark", top_bot_mark, top_mark_code); - primitive("firstmark", top_bot_mark, first_mark_code); - primitive("botmark", top_bot_mark, bot_mark_code); - primitive("splitfirstmark", top_bot_mark, split_first_mark_code); - primitive("splitbotmark", top_bot_mark, split_bot_mark_code); - primitive("count", tex_register, int_val); - primitive("dimen", tex_register, dimen_val); - primitive("skip", tex_register, glue_val); - primitive("muskip", tex_register, mu_val); - primitive("spacefactor", set_aux, hmode); - primitive("prevdepth", set_aux, vmode); - primitive("deadcycles", set_page_int, 0); - primitive("insertpenalties", set_page_int, 1); - primitive("wd", set_box_dimen, width_offset); - primitive("ht", set_box_dimen, height_offset); - primitive("dp", set_box_dimen, depth_offset); - primitive("lastpenalty", last_item, int_val); - primitive("lastkern", last_item, dimen_val); - primitive("lastskip", last_item, glue_val); - primitive("inputlineno", last_item, input_line_no_code); - primitive("badness", last_item, badness_code); - primitive("number", convert, number_code); - primitive("romannumeral", convert, roman_numeral_code); - primitive("string", convert, string_code); - primitive("meaning", convert, meaning_code); - primitive("fontname", convert, font_name_code); - primitive("jobname", convert, job_name_code); - primitive("if", if_test, if_char_code); - primitive("ifcat", if_test, if_cat_code); - primitive("ifnum", if_test, if_int_code); - primitive("ifdim", if_test, if_dim_code); - primitive("ifodd", if_test, if_odd_code); - primitive("ifvmode", if_test, if_vmode_code); - primitive("ifhmode", if_test, if_hmode_code); - primitive("ifmmode", if_test, if_mmode_code); - primitive("ifinner", if_test, if_inner_code); - primitive("ifvoid", if_test, if_void_code); - primitive("ifhbox", if_test, if_hbox_code); - primitive("ifvbox", if_test, if_vbox_code); - primitive("ifx", if_test, ifx_code); - primitive("ifeof", if_test, if_eof_code); - primitive("iftrue", if_test, if_true_code); - primitive("iffalse", if_test, if_false_code); - primitive("ifcase", if_test, if_case_code); - primitive("fi", fi_or_else, fi_code); - text(frozen_fi) = make_string_pool("fi"); - eqtb[frozen_fi] = eqtb[cur_val]; - primitive("or", fi_or_else, or_code); - primitive("else", fi_or_else, else_code); - primitive("nullfont", set_font, null_font); - text(frozen_null_font) = 795; - eqtb[frozen_null_font] = eqtb[cur_val]; - primitive("span", tab_mark, span_code); - primitive("cr", car_ret, cr_code); - text(frozen_cr) = make_string_pool("cr"); - eqtb[frozen_cr] = eqtb[cur_val]; - primitive("crcr", car_ret, cr_cr_code); - text(frozen_end_template) = make_string_pool("endtemplate"); - text(frozen_endv) = make_string_pool("endtemplate"); - eq_type(frozen_endv) = endv; - equiv(frozen_endv) = null_list; - eq_level(frozen_endv) = level_one; - eqtb[frozen_end_template] = eqtb[frozen_endv]; - eq_type(frozen_end_template) = end_template; - primitive("pagegoal", set_page_dimen, 0); - primitive("pagetotal", set_page_dimen, 1); - primitive("pagestretch", set_page_dimen, 2); - primitive("pagefilstretch", set_page_dimen, 3); - primitive("pagefillstretch", set_page_dimen, 4); - primitive("pagefilllstretch", set_page_dimen, 5); - primitive("pageshrink", set_page_dimen, 6); - primitive("pagedepth", set_page_dimen, 7); - primitive("end", stop, 0); - primitive("dump", stop, 1); - primitive("hskip", hskip, skip_code); - primitive("hfil", hskip, fil_code); - primitive("hfill", hskip, fill_code); - primitive("hss", hskip, ss_code); - primitive("hfilneg", hskip, fil_neg_code); - primitive("vskip", vskip, skip_code); - primitive("vfil", vskip, fil_code); - primitive("vfill", vskip, fill_code); - primitive("vss", vskip, ss_code); - primitive("vfilneg", vskip, fil_neg_code); - primitive("mskip", mskip, mskip_code); - primitive("kern", kern, explicit); - primitive("mkern", mkern, mu_glue); - primitive("moveleft", hmove, 1); - primitive("moveright", hmove, 0); - primitive("raise", vmove, 1); - primitive("lower", vmove, 0); - primitive("box", make_box, box_code); - primitive("copy", make_box, copy_code); - primitive("lastbox", make_box, last_box_code); - primitive("vsplit", make_box, vsplit_code); - primitive("vtop", make_box, vtop_code); - primitive("vbox", make_box, vtop_code + vmode); - primitive("hbox", make_box, vtop_code + hmode); - primitive("shipout", leader_ship, a_leaders - 1); - primitive("leaders", leader_ship, a_leaders); - primitive("cleaders", leader_ship, c_leaders); - primitive("xleaders", leader_ship, x_leaders); - primitive("indent", start_par, 1); - primitive("noindent", start_par, 0); - primitive("unpenalty", remove_item, penalty_node); - primitive("unkern", remove_item, kern_node); - primitive("unskip", remove_item, glue_node); - primitive("unhbox", un_hbox, box_code); - primitive("unhcopy", un_hbox, copy_code); - primitive("unvbox", un_vbox, box_code); - primitive("unvcopy", un_vbox, copy_code); - primitive("-", discretionary, 1); - primitive("discretionary", discretionary, 0); - primitive("eqno", eq_no, 0); - primitive("leqno", eq_no, 1); - primitive("mathord", math_comp, ord_noad); - primitive("mathop", math_comp, op_noad); - primitive("mathbin", math_comp, bin_noad); - primitive("mathrel", math_comp, rel_noad); - primitive("mathopen", math_comp, open_noad); - primitive("mathclose", math_comp, close_noad); - primitive("mathpunct", math_comp, punct_noad); - primitive("mathinner", math_comp, inner_noad); - primitive("underline", math_comp, under_noad); - primitive("overline", math_comp, over_noad); - primitive("displaylimits", limit_switch, normal); - primitive("limits", limit_switch, limits); - primitive("nolimits", limit_switch, no_limits); - primitive("displaystyle", math_style, display_style); - primitive("textstyle", math_style, text_style); - primitive("scriptstyle", math_style, script_style); - primitive("scriptscriptstyle", math_style, script_script_style); - primitive("above", above, above_code); - primitive("over", above, over_code); - primitive("atop", above, atop_code); - primitive("abovewithdelims", above, delimited_code + above_code); - primitive("overwithdelims", above, delimited_code + over_code); - primitive("atopwithdelims", above, delimited_code + atop_code); - primitive("left", left_right, left_noad); - primitive("right", left_right, right_noad); - text(frozen_right) = make_string_pool("right"); - eqtb[frozen_right] = eqtb[cur_val]; - primitive("long", prefix, 1); - primitive("outer", prefix, 2); - primitive("global", prefix, 4); - primitive("def", def, 0); - primitive("gdef", def, 1); - primitive("edef", def, 2); - primitive("xdef", def, 3); - primitive("let", let, normal); - primitive("futurelet", let, normal + 1); - primitive("chardef", shorthand_def, char_def_code); - primitive("mathchardef", shorthand_def, math_char_def_code); - primitive("countdef", shorthand_def, count_def_code); - primitive("dimendef", shorthand_def, dimen_def_code); - primitive("skipdef", shorthand_def, skip_def_code); - primitive("muskipdef", shorthand_def, mu_skip_def_code); - primitive("toksdef", shorthand_def, toks_def_code); - primitive("catcode", def_code, cat_code_base); - primitive("mathcode", def_code, math_code_base); - primitive("lccode", def_code, lc_code_base); - primitive("uccode", def_code, uc_code_base); - primitive("sfcode", def_code, sf_code_base); - primitive("delcode", def_code, del_code_base); - primitive("textfont", def_family, math_font_base); - primitive("scriptfont", def_family, math_font_base + script_size); - primitive("scriptscriptfont", def_family, math_font_base + script_script_size); - primitive("hyphenation", hyph_data, 0); - primitive("patterns", hyph_data, 1); - primitive("hyphenchar", assign_font_int, 0); - primitive("skewchar", assign_font_int, 1); - primitive("batchmode", set_interaction, batch_mode); - primitive("nonstopmode", set_interaction, nonstop_mode); - primitive("scrollmode", set_interaction, scroll_mode); - primitive("errorstopmode", set_interaction, error_stop_mode); - primitive("openin", in_stream, 1); - primitive("closein", in_stream, 0); - primitive("message", message, 0); - primitive("errmessage", message, 1); - primitive("lowercase", case_shift, lc_code_base); - primitive("uppercase", case_shift, uc_code_base); - primitive("show", xray, show_code); - primitive("showbox", xray, show_box_code); - primitive("showthe", xray, show_the_code); - primitive("showlists", xray, show_lists); - primitive("openout", extension, open_node); - primitive("write", extension, write_node); - write_loc = cur_val; - primitive("closeout", extension, close_node); - primitive("special", extension, special_node); - primitive("immediate", extension, immediate_code); - primitive("setlanguage", extension, set_language_code); - no_new_control_sequence = true; -} -#endif +/* Copyright 1992 Karl Berry + Copyright 2007 TeX Users Group + Copyright 2014 Clerk Ma + + 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ + +#define EXTERN extern + +#include "yandytex.h" + +#define BEGINFMTCHECKSUM 367403084L +#define ENDFMTCHECKSUM 69069L + +#ifdef INITEX + void do_initex (void); +#endif + +/* sec 0004 */ +void initialize (void) +{ + integer i; + integer k; + integer flag; + +#ifndef ALLOCATEHYPHEN + hyph_pointer z; +#endif + + if (!non_ascii) + { + for (i = 0; i <= 255; i++) + xchr[i] = (char) i; + +#ifdef JOKE + xchr[32] = ' '; xchr[33] = '!'; xchr[34] = '"'; xchr[35] = '#'; + xchr[36] = '$'; xchr[37] = '%'; xchr[38] = '&'; xchr[39] = '\''; + xchr[40] = '('; xchr[41] = ')'; xchr[42] = '*'; xchr[43] = '+'; + xchr[44] = ','; xchr[45] = '-'; xchr[46] = '.'; xchr[47] = '/'; + xchr[48] = '0'; xchr[49] = '1'; xchr[50] = '2'; xchr[51] = '3'; + xchr[52] = '4'; xchr[53] = '5'; xchr[54] = '6'; xchr[55] = '7'; + xchr[56] = '8'; xchr[57] = '9'; xchr[58] = ':'; xchr[59] = ';'; + xchr[60] = '<'; xchr[61] = '='; xchr[62] = '>'; xchr[63] = '?'; + xchr[64] = '@'; xchr[65] = 'A'; xchr[66] = 'B'; xchr[67] = 'C'; + xchr[68] = 'D'; xchr[69] = 'E'; xchr[70] = 'F'; xchr[71] = 'G'; + xchr[72] = 'H'; xchr[73] = 'I'; xchr[74] = 'J'; xchr[75] = 'K'; + xchr[76] = 'L'; xchr[77] = 'M'; xchr[78] = 'N'; xchr[79] = 'O'; + xchr[80] = 'P'; xchr[81] = 'Q'; xchr[82] = 'R'; xchr[83] = 'S'; + xchr[84] = 'T'; xchr[85] = 'U'; xchr[86] = 'V'; xchr[87] = 'W'; + xchr[88] = 'X'; xchr[89] = 'Y'; xchr[90] = 'Z'; xchr[91] = '['; + xchr[92] = '\\'; xchr[93] = ']'; xchr[94] = '^'; xchr[95] = '_'; + xchr[96] = '`'; xchr[97] = 'a'; xchr[98] = 'b'; xchr[99] = 'c'; + xchr[100] = 'd'; xchr[101] = 'e'; xchr[102] = 'f'; xchr[103] = 'g'; + xchr[104] = 'h'; xchr[105] = 'i'; xchr[106] = 'j'; xchr[107] = 'k'; + xchr[108] = 'l'; xchr[109] = 'm'; xchr[110] = 'n'; xchr[111] = 'o'; + xchr[112] = 'p'; xchr[113] = 'q'; xchr[114] = 'r'; xchr[115] = 's'; + xchr[116] = 't'; xchr[117] = 'u'; xchr[118] = 'v'; xchr[119] = 'w'; + xchr[120] = 'x'; xchr[121] = 'y'; xchr[122] = 'z'; xchr[123] = '{'; + xchr[124] = '|'; xchr[125] = '}'; xchr[126] = '~'; + + for (i = 0; i <= 31; i++) + xchr[i] = chr(i); + + for (i = 127; i <= 255; i++) + xchr[i]= chr(i); +#endif + } + + for (i = 0; i <= 255; i++) + xord[chr(i)] = invalid_code; + +#ifdef JOKE + for (i = 128; i <= 255 ; i++) + xord[xchr[i]] = i; + + for (i = 0; i <= 126; i++) + xord[xchr[i]] = i; +#endif + + for (i = 0; i <= 255; i++) + xord[xchr[i]] = (char) i; + + xord[127] = 127; + + flag = 0; + + if (trace_flag != 0) + { + for (k = 0; k < 256; k++) + if (xord[k] != k) + { + flag = 1; + break; + } + + if (flag) + { + puts("Inverted mapping xord[] pairs:"); + + for (k = 0; k < 256; k++) + { + if (xord[k] != 127) + printf("%lld => %d\n", k, xord[k]); + } + } + } + + if (interaction < batch_mode) + interaction = error_stop_mode; + + deletions_allowed = true; + set_box_allowed = true; + error_count = 0; + help_ptr = 0; + use_err_help = false; + interrupt = 0; + OK_to_interrupt = true; + +#ifdef DEBUG + was_mem_end = mem_min; + was_lo_max = mem_bot; // mem_min + was_hi_min = mem_top; // mem_max + panicking = false; +#endif + + nest_ptr = 0; + max_nest_stack = 0; + mode = vmode; + head = contrib_head; + tail = contrib_head; + prev_depth = ignore_depth; + mode_line = 0; + prev_graf = 0; + shown_mode = 0; + page_contents = 0; + page_tail = page_head; + +#ifdef ALLOCATEMAIN + if (is_initex) +#endif + link(page_head) = 0; + + last_glue = max_halfword; + last_penalty = 0; + last_kern = 0; + page_depth = 0; + page_max_depth = 0; + + for (k = int_base; k <= eqtb_size; k++) + xeq_level[k] = level_one; + + no_new_control_sequence = true; + next(hash_base) = 0; + text(hash_base) = 0; + + for (k = hash_base + 1; k <= undefined_control_sequence - 1; k++) + hash[k] = hash[hash_base]; + + save_ptr = 0; + cur_level = 1; + cur_group = 0; + cur_boundary = 0; + max_save_stack = 0; + mag_set = 0; + cur_mark[0] = 0; + cur_mark[1] = 0; + cur_mark[2] = 0; + cur_mark[3] = 0; + cur_mark[4] = 0; + cur_val = 0; + cur_val_level = int_val; + radix = 0; + cur_order = normal; + + for (k = 0; k <= 16; k++) + read_open[k] = closed; + + cond_ptr = 0; + if_limit = normal; + cur_if = 0; + if_line = 0; + + for (k = 0; k <= font_max; k++) + font_used[k] = false; + + null_character.b0 = min_quarterword; + null_character.b1 = min_quarterword; + null_character.b2 = min_quarterword; + null_character.b3 = min_quarterword; + total_pages = 0; + max_v = 0; + max_h = 0; + max_push = 0; + last_bop = -1; + doing_leaders = false; + dead_cycles = 0; + cur_s = -1; + half_buf = dvi_buf_size / 2; + dvi_limit = dvi_buf_size; + dvi_ptr = 0; + dvi_offset = 0; + dvi_gone = 0; + down_ptr = 0; + right_ptr = 0; + adjust_tail = 0; + last_badness = 0; + pack_begin_line = 0; + empty_field.rh = 0; + empty_field.lh = 0; + null_delimiter.b0 = 0; + null_delimiter.b1 = 0; + null_delimiter.b2 = 0; + null_delimiter.b3 = 0; + align_ptr = 0; + cur_align = 0; + cur_span = 0; + cur_loop = 0; + cur_head = 0; + cur_tail = 0; + +/* *not* OK with ALLOCATEHYPHEN, since may not be allocated yet */ +#ifndef ALLOCATEHYPHEN + for (z = 0; z <= hyphen_prime; z++) + { + hyph_word[z] = 0; + hyph_list[z] = 0; + } +#endif + + hyph_count = 0; + output_active = false; + insert_penalties = 0; + ligature_present = false; + cancel_boundary = false; + lft_hit = false; + rt_hit = false; + ins_disc = false; + after_token = 0; + long_help_seen = false; + format_ident = 0; + + for (k = 0; k <= 17; k++) + write_open[k] = false; + + edit_name_start = 0; + +#ifdef INITEX + if (is_initex) + do_initex(); +#endif +} + +/* do the part of initialize() that requires mem_top, mem_max or mem[] */ +/* do this part after allocating main memory */ + +#ifdef ALLOCATEMAIN +void initialize_aux (void) +{ +#ifdef DEBUG + was_mem_end = mem_min; + was_lo_max = mem_bot; // mem_min + was_hi_min = mem_top; // mem_max + panicking = false; +#endif + +/* nest_ptr = 0; */ +/* max_nest_stack = 0; */ + mode = vmode; + head = contrib_head; + tail = contrib_head; + prev_depth = ignore_depth; + mode_line = 0; + prev_graf = 0; +/* shown_mode = 0; */ +/* page_contents = 0; */ + page_tail = page_head; + link(page_head) = 0; +} +#endif +/* sec 0815 */ +void line_break (integer final_widow_penalty) +{ + boolean auto_breaking; + pointer prev_p; + pointer q, r, s, prev_s; + internal_font_number f; + /* small_number j; */ + int j; + /* unsigned char c; */ + unsigned int c; + + pack_begin_line = mode_line; + link(temp_head) = link(head); + + if (is_char_node(tail)) + tail_append(new_penalty(inf_penalty)); + else if (type(tail) != glue_node) + tail_append(new_penalty(inf_penalty)); + else + { + type(tail) = penalty_node; + delete_glue_ref(glue_ptr(tail)); + flush_node_list(leader_ptr(tail)); + penalty(tail) = inf_penalty; + } + + link(tail) = new_param_glue(par_fill_skip_code); + init_cur_lang = prev_graf % 65536L; + init_l_hyf = prev_graf / 4194304L; /* 2^22 */ + init_r_hyf = (prev_graf / 65536L) % 64; + pop_nest(); + no_shrink_error_yet = true; + check_shrinkage(left_skip); + check_shrinkage(right_skip); + q = left_skip; + r = right_skip; + background[1] = width(q) + width(r); + background[2] = 0; + background[3] = 0; + background[4] = 0; + background[5] = 0; + background[2 + stretch_order(q)] = stretch(q); + background[2 + stretch_order(r)] = background[2 + stretch_order(r)] + stretch(r); + background[6] = shrink(q) + shrink(r); + minimum_demerits = awful_bad; + minimal_demerits[tight_fit] = awful_bad; + minimal_demerits[decent_fit] = awful_bad; + minimal_demerits[loose_fit] = awful_bad; + minimal_demerits[very_loose_fit] = awful_bad; + + if (par_shape_ptr == 0) + if (hang_indent == 0) + { + last_special_line = 0; + second_width = hsize; + second_indent = 0; + } + else + { + last_special_line = abs(hang_after); + + if (hang_after < 0) + { + first_width = hsize - abs(hang_indent); + + if (hang_indent >= 0) + first_indent = hang_indent; + else + first_indent = 0; + + second_width = hsize; + second_indent = 0; + } + else + { + first_width = hsize; + first_indent = 0; + second_width = hsize - abs(hang_indent); + + if (hang_indent >= 0) + second_indent = hang_indent; + else + second_indent = 0; + } + } + else + { + last_special_line = info(par_shape_ptr) - 1; + second_width = mem[par_shape_ptr + 2 * (last_special_line + 1)].cint; + second_indent = mem[par_shape_ptr + 2 * last_special_line + 1].cint; + } + + if (looseness == 0) + easy_line = last_special_line; + else + easy_line = empty_flag; + + threshold = pretolerance; + + if (threshold >= 0) + { +#ifdef STAT + if (tracing_paragraphs > 0) + { + begin_diagnostic(); + print_nl("@firstpass"); + } +#endif + + second_pass = false; + final_pass = false; + first_pass_count++; + } + else + { + threshold = tolerance; + second_pass = true; + final_pass = (emergency_stretch <= 0); + +#ifdef STAT + if (tracing_paragraphs > 0) + begin_diagnostic(); +#endif + } + + while (true) + { + if (threshold > inf_bad) + threshold = inf_bad; + + if (second_pass) + { +#ifdef INITEX + if (is_initex) + { + if (trie_not_ready) + init_trie(); + } +#endif + + cur_lang = init_cur_lang; + l_hyf = init_l_hyf; + r_hyf = init_r_hyf; + } + + q = get_node(active_node_size); + type(q) = unhyphenated; + fitness(q) = decent_fit; + link(q) = active; + break_node(q) = 0; + line_number(q) = prev_graf + 1; + total_demerits(q) = 0; + link(active) = q; + act_width = background[1]; + do_all_six(store_background); + passive = 0; + printed_node = temp_head; + pass_number = 0; + font_in_short_display = null_font; + cur_p = link(temp_head); + auto_breaking = true; + prev_p = cur_p; + + while ((cur_p != 0) && (link(active) != active)) + { + if (is_char_node(cur_p)) + { + prev_p = cur_p; + + do + { + f = font(cur_p); + act_width = act_width + char_width(f, char_info(f, character(cur_p))); + cur_p = link(cur_p); + } + while (!(!is_char_node(cur_p))); + } + + switch (type(cur_p)) + { + case hlist_node: + case vlist_node: + case rule_node: + act_width = act_width + width(cur_p); + break; + + case whatsit_node: + if (subtype(cur_p) == language_node) + { + cur_lang = what_lang(cur_p); + l_hyf = what_lhm(cur_p); + r_hyf = what_rhm(cur_p); + } + break; + + case glue_node: + { + if (auto_breaking) + { + if (is_char_node(prev_p)) + try_break(0, unhyphenated); + else if (precedes_break(prev_p)) + try_break(0, unhyphenated); + else if ((type(prev_p) == kern_node) && (subtype(prev_p) != explicit)) + try_break(0, unhyphenated); + } + + check_shrinkage(glue_ptr(cur_p)); + q = glue_ptr(cur_p); + act_width = act_width+ width(q); + active_width[2 + stretch_order(q)] = active_width[2 + stretch_order(q)] + stretch(q); + active_width[6] = active_width[6] + shrink(q); + + if (second_pass && auto_breaking) + { + prev_s = cur_p; + s = link(prev_s); + + if (s != 0) + { + while (true) + { + if (is_char_node(s)) + { + c = character(s); + hf = font(s); + } + else if (type(s) == ligature_node) + if (lig_ptr(s) == 0) + goto continu; + else + { + q = lig_ptr(s); + c = character(q); + hf = font(q); + } + else if ((type(s) == kern_node) && (subtype(s) == normal)) + goto continu; + else if (type(s) == whatsit_node) + { + if (subtype(s) == language_node) + { + cur_lang = what_lang(s); + l_hyf = what_lhm(s); + r_hyf = what_rhm(s); + } + goto continu; + } + else + goto done1; + + if (lc_code(c) != 0) + if ((lc_code(c) == (halfword) c) || (uc_hyph > 0)) + goto done2; + else + goto done1; +continu: + prev_s = s; + s = link(prev_s); + } +done2: + hyf_char = hyphen_char[hf]; + + if (hyf_char < 0) + goto done1; + + if (hyf_char > 255) + goto done1; + + ha = prev_s; + + if (l_hyf + r_hyf > 63) + goto done1; + + hn = 0; + + while (true) + { + if (is_char_node(s)) + { + if (font(s) != hf) + goto done3; + + hyf_bchar = character(s); + + c = hyf_bchar; + + if (lc_code(c) == 0) + goto done3; + + if (hn == 63) + goto done3; + + hb = s; + incr(hn); + hu[hn] = c; + hc[hn]= lc_code(c); + hyf_bchar = non_char; + } + else if (type(s) == ligature_node) + { + if (font(lig_char(s)) != hf) + goto done3; + + j = hn; + q = lig_ptr(s); + + if (q != 0) + hyf_bchar = character(q); + + while (q != 0) + { + c = character(q); + + if (lc_code(c) == 0) + goto done3; + + if (j == 63) + goto done3; + + incr(j); + hu[j] = c; + hc[j] = lc_code(c); + q = link(q); + } + + hb = s; + hn = j; + + if (odd(subtype(s))) + hyf_bchar = font_bchar[hf]; + else + hyf_bchar = non_char; + } + else if ((type(s) == kern_node) && (subtype(s) == normal)) + { + hb = s; + hyf_bchar = font_bchar[hf]; + } + else + goto done3; + + s = link(s); + } +done3: + if (hn < l_hyf + r_hyf) + goto done1; + + while (true) + { + if (!(is_char_node(s))) + switch (type(s)) + { + case ligature_node: + break; + + case kern_node: + if (subtype(s) != normal) + goto done4; + break; + + case whatsit_node: + case glue_node: + case penalty_node: + case ins_node: + case adjust_node: + case mark_node: + goto done4; + break; + + default: + goto done1; + break; + } + s = link(s); + } +done4: + hyphenate(); + } +done1:; + } + } + break; + + case kern_node: + if (subtype(cur_p) == explicit) + kern_break(); + else + act_width = act_width + width(cur_p); + break; + + case ligature_node: + { + f = font(lig_char(cur_p)); + act_width = act_width + char_width(f, char_info(f, character(lig_char(cur_p)))); + } + break; + + case disc_node: + { + s = pre_break(cur_p); + disc_width = 0; + + if (s == 0) + try_break(ex_hyphen_penalty, hyphenated); + else + { + do + { + if (is_char_node(s)) + { + f = font(s); + disc_width = disc_width + char_width(f, char_info(f, character(s))); + } + else switch (type(s)) + { + case ligature_node: + { + f = font(lig_char(s)); + disc_width = disc_width + char_width(f, char_info(f, character(lig_char(s)))); + } + break; + + case hlist_node: + case vlist_node: + case rule_node: + case kern_node: + disc_width = disc_width + width(s); + break; + + default: + { + confusion("disc3"); + return; + } + break; + } + + s = link(s); + } + while (!(s == 0)); + + act_width = act_width + disc_width; + try_break(hyphen_penalty, hyphenated); + act_width = act_width - disc_width; + } + + r = replace_count(cur_p); + s = link(cur_p); + + while (r > 0) + { + if (is_char_node(s)) + { + f = font(s); + act_width = act_width + char_width(f, char_info(f, character(s))); + } + else switch (type(s)) + { + case ligature_node: + { + f = font(lig_char(s)); + act_width = act_width + char_width(f, char_info(f, character(lig_char(s)))); + } + break; + + case hlist_node: + case vlist_node: + case rule_node: + case kern_node: + act_width = act_width + width(s); + break; + + default: + { + confusion("disc4"); + return; + } + break; + } + + decr(r); + s = link(s); + } + + prev_p = cur_p; + cur_p = s; + goto done5; + } + break; + + case math_node: + { + auto_breaking = (subtype(cur_p) == after); + kern_break(); + } + break; + + case penalty_node: + try_break(penalty(cur_p), unhyphenated); + break; + + case mark_node: + case ins_node: + case adjust_node: + break; + + default: + { + confusion("paragraph"); + return; + } + break; + } + + prev_p = cur_p; + cur_p = link(cur_p); +done5:; + } + + if (cur_p == 0) + { + try_break(eject_penalty, hyphenated); + + if (link(active) != active) + { + r = link(active); + fewest_demerits = awful_bad; + + do + { + if (type(r) != delta_node) + if (total_demerits(r) < fewest_demerits) + { + fewest_demerits = total_demerits(r); + best_bet = r; + } + + r = link(r); + } + while (!(r == active)); + + best_line = line_number(best_bet); + + if (looseness == 0) + { + goto done; + } + + { + r = link(active); + actual_looseness = 0; + + do + { + if (type(r) != delta_node) + { + line_diff = toint(line_number(r)) - toint(best_line); + + if (((line_diff < actual_looseness) && (looseness <= line_diff)) || + ((line_diff > actual_looseness) && (looseness >= line_diff))) + { + best_bet = r; + actual_looseness = line_diff; + fewest_demerits = total_demerits(r); + } + else if ((line_diff == actual_looseness) && (total_demerits(r) < fewest_demerits)) + { + best_bet = r; + fewest_demerits = total_demerits(r); + } + } + + r = link(r); + } + while (!(r == active)); + + best_line = line_number(best_bet); + } + + if ((actual_looseness == looseness) || final_pass) + { + goto done; + } + } + } + + q = link(active); + + while (q != active) + { + cur_p = link(q); + + if (type(q) == delta_node) + free_node(q, delta_node_size); + else + free_node(q, active_node_size); + + q = cur_p; + } + + q = passive; + + while (q != 0) + { + cur_p = link(q); + free_node(q, passive_node_size); + q = cur_p; + } + + if (!second_pass) + { +#ifdef STAT + if (tracing_paragraphs > 0) + print_nl("@secondpass"); +#endif + threshold = tolerance; + second_pass = true; + second_pass_count++; + final_pass = (emergency_stretch <= 0); + } + else + { +#ifdef STAT + if (tracing_paragraphs > 0) + print_nl("@emergencypass"); +#endif + + background[2] = background[2] + emergency_stretch; + final_pass = true; + ++final_pass_count; + } + } + +done: + if (best_line == decent_fit) + single_line++; + +#ifdef STAT + if (tracing_paragraphs > 0) + { + end_diagnostic(true); + normalize_selector(); + } +#endif + + post_line_break(final_widow_penalty); + q = link(active); + + while (q != active) + { + cur_p = link(q); + + if (type(q) == delta_node) + free_node(q, delta_node_size); + else + free_node(q, active_node_size); + + q = cur_p; + } + + q = passive; + + while (q != 0) + { + cur_p = link(q); + free_node(q, passive_node_size); + q = cur_p; + } + + pack_begin_line = 0; +} +/* sec 1211 */ +void prefixed_command (void) +{ + small_number a; + internal_font_number f; + halfword j; + font_index k; + pointer p, q; + integer n; + boolean e; + + a = 0; + + while (cur_cmd == prefix) + { + if (!odd(a / cur_chr)) + a = a + cur_chr; + + do + { + get_x_token(); + } + while (!((cur_cmd != spacer) && (cur_cmd != relax))); + + if (cur_cmd <= max_non_prefixed_command) + { + print_err("You can't use a prefix with `"); + print_cmd_chr(cur_cmd, cur_chr); + print_char('\''); + help1("I'll pretend you didn't say \\long or \\outer or \\global."); + back_error(); + return; + } + } + + if ((cur_cmd != def) && (a % 4 != 0)) + { + print_err("You can't use `"); + print_esc("long"); + prints("' or `"); + print_esc("outer"); + prints("' with `"); + print_cmd_chr(cur_cmd, cur_chr); + print_char('\''); + help1("I'll pretend you didn't say \\long or \\outer here."); + error(); + } + + if (global_defs != 0) + if (global_defs < 0) + { + if ((a >= 4)) + a = a - 4; + } + else + { + if (!(a >= 4)) + a = a + 4; + } + + switch (cur_cmd) + { + case set_font: + define(cur_font_loc, data, cur_chr); + break; + + case def: + { + if (odd(cur_chr) && !(a >= 4) && (global_defs >= 0)) + a = a + 4; + + e = (cur_chr >= 2); + get_r_token(); + p = cur_cs; + q = scan_toks(true, e); + define(p, call + (a % 4), def_ref); + } + break; + + case let: + { + n = cur_chr; + get_r_token(); + p = cur_cs; + + if (n == 0) + { + do + { + get_token(); + } + while (!(cur_cmd != spacer)); + + if (cur_tok == other_token + '=') + { + get_token(); + + if (cur_cmd == spacer) + get_token(); + } + } + else + { + get_token(); + q = cur_tok; + get_token(); + back_input(); + cur_tok = q; + back_input(); + } + + if (cur_cmd >= call) + add_token_ref(cur_chr); + + define(p, cur_cmd, cur_chr); + } + break; + + case shorthand_def: + { + n = cur_chr; + get_r_token(); + p = cur_cs; + define(p, relax, 256); + scan_optional_equals(); + + switch (n) + { + case char_def_code: + { + scan_char_num(); + define(p, char_given, cur_val); + } + break; + + case math_char_def_code: + { + scan_fifteen_bit_int(); + define(p, math_given, cur_val); + } + break; + + default: + { + scan_eight_bit_int(); + + switch (n) + { + case count_def_code: + define(p, assign_int, count_base + cur_val); + break; + + case dimen_def_code: + define(p, assign_dimen, scaled_base + cur_val); + break; + + case skip_def_code: + define(p, assign_glue, skip_base + cur_val); + break; + + case mu_skip_def_code: + define(p, assign_mu_glue, mu_skip_base + cur_val); + break; + + case toks_def_code: + define(p, assign_toks, toks_base + cur_val); + break; + } + } + break; + } + } + break; + + case read_to_cs: + { + scan_int(); + n = cur_val; + + if (!scan_keyword("to")) + { + print_err("Missing `to' inserted"); + help2("You should have said `\\read to \\cs'.", + "I'm going to look for the \\cs now."); + error(); + } + + get_r_token(); + p = cur_cs; + read_toks(n, p); + define(p, call, cur_val); + } + break; + + case toks_register: + case assign_toks: + { + q = cur_cs; + + if (cur_cmd == toks_register) + { + scan_eight_bit_int(); + p = toks_base + cur_val; + } + else + p = cur_chr; + + scan_optional_equals(); + + do + { + get_x_token(); + } + while (!((cur_cmd != spacer) && (cur_cmd != relax))); + + if (cur_cmd != left_brace) + { + if (cur_cmd == toks_register) + { + scan_eight_bit_int(); + cur_cmd = assign_toks; + cur_chr = toks_base + cur_val; + } + + if (cur_cmd == assign_toks) + { + q = equiv(cur_chr); + + if (q == 0) + define(p, undefined_cs, 0); + else + { + add_token_ref(q); + define(p, call, q); + } + goto done; + } + } + + back_input(); + cur_cs = q; + q = scan_toks(false, false); + + if (link(def_ref) == 0) + { + define(p, undefined_cs, 0); + free_avail(def_ref); + } + else + { + if (p == output_routine_loc) + { + link(q) = get_avail(); + q = link(q); + info(q) = right_brace_token + '}'; + q = get_avail(); + info(q) = left_brace_token + '{'; + link(q) = link(def_ref); + link(def_ref) = q; + } + + define(p, call, def_ref); + } + } + break; + + case assign_int: + { + p = cur_chr; + scan_optional_equals(); + scan_int(); + word_define(p, cur_val); + } + break; + + case assign_dimen: + { + p = cur_chr; + scan_optional_equals(); + scan_dimen(false, false, false); + word_define(p, cur_val); + } + break; + + case assign_glue: + case assign_mu_glue: + { + p = cur_chr; + n = cur_cmd; + scan_optional_equals(); + + if (n == assign_mu_glue) + scan_glue(mu_val); + else + scan_glue(glue_val); + + trap_zero_glue(); + define(p, glue_ref, cur_val); + } + break; + + case def_code: + { + if (cur_chr == cat_code_base) + n = max_char_code; + else if (cur_chr == math_code_base) + n = 32768L; /* 2^15 */ + else if (cur_chr == sf_code_base) + n = 32767; /* 2^15 - 1*/ + else if (cur_chr == del_code_base) + n = 16777215L; /* 2^24 - 1 */ + else + n = 255; + + p = cur_chr; + scan_char_num(); + p = p + cur_val; + scan_optional_equals(); + scan_int(); + + if (((cur_val < 0) && (p < del_code_base)) || (cur_val > n)) + { + print_err("Invalid code("); + print_int(cur_val); + + if (p < del_code_base) + prints("), should be in the range 0.."); + else + prints("), should be at most "); + + print_int(n); + help1("I'm going to use 0 instead of that illegal code value."); + error(); + cur_val = 0; + } + + if (p < math_code_base) + define(p, data, cur_val); + else if (p < del_code_base) + define(p, data, cur_val); + else + word_define(p, cur_val); + } + break; + + case def_family: + { + p = cur_chr; + scan_four_bit_int(); + p = p + cur_val; + scan_optional_equals(); + scan_font_ident(); + define(p, data, cur_val); + } + break; + + case tex_register: + case advance: + case multiply: + case divide: + do_register_command(a); + break; + + case set_box: + { + scan_eight_bit_int(); + + if ((a >= 4)) + n = 256 + cur_val; + else + n = cur_val; + + scan_optional_equals(); + + if (set_box_allowed) + scan_box(box_flag + n); + else + { + print_err("Improper "); + print_esc("setbox"); + help2("Sorry, \\setbox is not allowed after \\halign in a display,", + "or between \\accent and an accented character."); + error(); + } + } + break; + + case set_aux: + alter_aux(); + break; + + case set_prev_graf: + alter_prev_graf(); + break; + + case set_page_dimen: + alter_page_so_far(); + break; + + case set_page_int: + alter_integer(); + break; + + case set_box_dimen: + alter_box_dimen(); + break; + + case set_shape: + { + scan_optional_equals(); + scan_int(); + n = cur_val; + + if (n <= 0) + p = 0; + else + { + p = get_node(2 * n + 1); + info(p) = n; + + for (j = 1; j <= n; j++) + { + scan_dimen(false, false, false); + mem[p + 2 * j - 1].cint = cur_val; + scan_dimen(false, false, false); + mem[p + 2 * j].cint = cur_val; + } + } + + define(par_shape_loc, shape_ref, p); + } + break; + + case hyph_data: + if (cur_chr == 1) + { +#ifdef INITEX + if (is_initex) + { + new_patterns(); + goto done; + } +#endif + print_err("Patterns can be loaded only by INITEX"); + help_ptr = 0; + error(); + + do + { + get_token(); + } + while (!(cur_cmd == right_brace)); + + return; + } + else + { + new_hyph_exceptions(); + goto done; + } + break; + + case assign_font_dimen: + { + find_font_dimen(true); + k = cur_val; + scan_optional_equals(); + scan_dimen(false, false, false); + font_info[k].cint = cur_val; + } + break; + + case assign_font_int: + { + n = cur_chr; + scan_font_ident(); + f = cur_val; + scan_optional_equals(); + scan_int(); + + if (n == 0) + hyphen_char[f] = cur_val; + else + skew_char[f] = cur_val; + } + break; + + case def_font: + new_font(a); + break; + + case set_interaction: + new_interaction(); + break; + + default: + { + confusion("prefix"); + return; + } + break; + } + +done: + if (after_token != 0) + { + cur_tok = after_token; + back_input(); + after_token = 0; + } +} +/* sec 1303 */ +boolean load_fmt_file (void) +{ + integer j, k; + pointer p, q; + integer x; + + undump_int(x); + + if (x != BEGINFMTCHECKSUM) + goto bad_fmt; + + undump_int(x); /* mem_bot */ + + if (x != mem_bot) + goto bad_fmt; + + undump_int(x); /* mem_top */ + +#ifdef ALLOCATEMAIN +/* we already read this once earlier to grab mem_top */ + if (trace_flag) + printf("Read from fmt file mem_top = %lld TeX words\n", x); + + mem = allocate_main_memory(x); + + if (mem == NULL) + exit(EXIT_FAILURE); + + initialize_aux(); /* do `mem' part of initialize */ +#endif + + if (x != mem_top) + goto bad_fmt; + + undump_int(x); /* eqtb_size */ + + if (x != eqtb_size) + goto bad_fmt; + + undump_int(x); /* hash_prime */ + + if (x != hash_prime) + goto bad_fmt; + + undump_int(x); /* hyphen_prime */ + +#ifdef ALLOCATEHYPHEN +/* allow format files dumped with arbitrary (prime) hyphenation exceptions */ + realloc_hyphen(x); + hyphen_prime = x; +#endif + + if (x != hyphen_prime) + goto bad_fmt; + + { + undump_int(x); /* pool_size */ + + if (x < 0) + goto bad_fmt; + +#ifdef ALLOCATESTRING + if (x > current_pool_size) + { + if (trace_flag) + printf("undump string pool reallocation (%lld > %d)\n", x, current_pool_size); + + str_pool = realloc_str_pool(x - current_pool_size + increment_pool_size); + } + + if (x > current_pool_size) +#else + if (x > pool_size) +#endif + { + printf("%s%s\n", "---! Must increase the ", "string pool size"); + goto bad_fmt; + } + else + pool_ptr = x; + } + + { + undump_int(x); /* max_strings */ + + if (x < 0) + goto bad_fmt; + +#ifdef ALLOCATESTRING + if (x > current_max_strings) + { + if (trace_flag) + printf("undump string pointer reallocation (%lld > %d)\n", x, current_max_strings); + + str_start = realloc_str_start(x - current_max_strings + increment_max_strings); + } + + if (x > current_max_strings) +#else + if (x > max_strings) +#endif + { + printf("%s%s\n", "---! Must increase the ", "max strings"); + goto bad_fmt; + } + else + str_ptr = x; + } + + undumpthings(str_start[0], str_ptr + 1); + undumpthings(str_pool[0], pool_ptr); + init_str_ptr = str_ptr; + init_pool_ptr = pool_ptr; + undump(lo_mem_stat_max + 1000, hi_mem_stat_min - 1, lo_mem_max); + undump(lo_mem_stat_max + 1, lo_mem_max, rover); + p = mem_bot; + q = rover; + + do + { + if (undumpthings(mem[p], q + 2 - p)) + return -1; + + p = q + node_size(q); + + if ((p > lo_mem_max) || ((q >= rlink(q)) && (rlink(q) != rover))) + goto bad_fmt; + + q = rlink(q); + } + while (!(q == rover)); + + if (undumpthings(mem[p], lo_mem_max + 1 - p)) + return -1; + + if (mem_min < mem_bot - 2) + { +/* or call add_variable_space(mem_bot - (mem_min + 1)) */ + if (trace_flag) + puts("Splicing in mem_min space in undump!"); + + p = llink(rover); + q = mem_min + 1; + link(mem_min) = 0; /* null */ + info(mem_min) = 0; /* null */ + rlink(p) = q; + llink(rover) = q; + rlink(q) = rover; + llink(q) = p; + link(q) = empty_flag; + node_size(q) = mem_bot - q; + } + + undump(lo_mem_max + 1, hi_mem_stat_min, hi_mem_min); + undump(mem_bot, mem_top, avail); + mem_end = mem_top; + + if (undumpthings(mem[hi_mem_min], mem_end + 1 - hi_mem_min)) + return -1; + + undump_int(var_used); + undump_int(dyn_used); + + k = active_base; + + do + { + undump_int(x); + + if ((x < 1) || (k + x > (eqtb_size + 1))) + goto bad_fmt; + + if (undumpthings(eqtb[k], x)) + return -1; + + k = k + x; + undump_int(x); + + if ((x < 0) || (k + x > (eqtb_size + 1))) + goto bad_fmt; + + for (j = k; j <= k + x - 1; j++) + eqtb[j] = eqtb[k - 1]; + + k = k + x; + } + while (!(k > eqtb_size)); + + undump(hash_base, frozen_control_sequence, par_loc); + par_token = cs_token_flag + par_loc; + undump(hash_base, frozen_control_sequence, write_loc); + undump(hash_base, frozen_control_sequence, hash_used); + + p = hash_base - 1; + + do + { + undump(p + 1, hash_used, p); + undump_hh(hash[p]); + } + while (!(p == hash_used)); + + if (undumpthings(hash[hash_used + 1], undefined_control_sequence - 1 - hash_used)) + return -1; + + undump_int(cs_count); + + if (trace_flag) + printf("itex undump cs_count %lld ", cs_count); + + { + undump_int(x); /* font_mem_size */ + + if (x < 7) + goto bad_fmt; + +#ifdef ALLOCATEFONT + if (trace_flag) + printf("Read from fmt fmem_ptr = %lld\n", x); + + if (x > current_font_mem_size) + { + if (trace_flag) + printf("Undump realloc font_info (%lld > %d)\n", x, current_font_mem_size); + + font_info = realloc_font_info (x - current_font_mem_size + increment_font_mem_size); + } + + if (x > current_font_mem_size) +#else + if (x > font_mem_size) +#endif + { + puts("---! Must increase the font mem size"); + goto bad_fmt; + } + else + fmem_ptr = x; + } + + { + undumpthings(font_info[0], fmem_ptr); + undump_size(font_base, font_max, "font max", font_ptr); + frozen_font_ptr = font_ptr; + undumpthings(font_check[0], font_ptr + 1); + undumpthings(font_size[0], font_ptr + 1); + undumpthings(font_dsize[0], font_ptr + 1); + undumpthings(font_params[0], font_ptr + 1); + undumpthings(hyphen_char[0], font_ptr + 1); + undumpthings(skew_char[0], font_ptr + 1); + undumpthings(font_name[0], font_ptr + 1); + undumpthings(font_area[0], font_ptr + 1); + undumpthings(font_bc[0], font_ptr + 1); + undumpthings(font_ec[0], font_ptr + 1); + undumpthings(char_base[0], font_ptr + 1); + undumpthings(width_base[0], font_ptr + 1); + undumpthings(height_base[0], font_ptr + 1); + undumpthings(depth_base[0], font_ptr + 1); + undumpthings(italic_base[0], font_ptr + 1); + undumpthings(lig_kern_base[0], font_ptr + 1); + undumpthings(kern_base[0], font_ptr + 1); + undumpthings(exten_base[0], font_ptr + 1); + undumpthings(param_base[0], font_ptr + 1); + undumpthings(font_glue[0], font_ptr + 1); + undumpthings(bchar_label[0], font_ptr + 1); + undumpthings(font_bchar[0], font_ptr + 1); + undumpthings(font_false_bchar[0], font_ptr + 1); + } + +/* log not opened yet, so can't show fonts frozen into format */ +/* May be able to avoid the following since we switched to */ +/* non_address from font_mem_size to 0 96/Jan/15 ??? */ + +#ifdef ALLOCATEFONT + { + int count = 0, oldfont_mem_size = 0; + + for (x = 0; x <= font_ptr; x++) + { + if (bchar_label[x] > oldfont_mem_size) + oldfont_mem_size = bchar_label[x]; + } + + if (oldfont_mem_size != non_address && oldfont_mem_size > font_max) + { + for (x = 0; x <= font_ptr; x++) + { + if (bchar_label[x] == oldfont_mem_size) + { + bchar_label[x] = non_address; + count++; + } + } + + if (trace_flag) + printf("oldfont_mem_size is %d --- hit %d times. Using non_address %d\n", + oldfont_mem_size, count, non_address); + } + } +#endif + + undump(0, hyphen_prime, hyph_count); + + for (k = 1; k <= hyph_count; k++) + { + undump(0, hyphen_prime, j); + undump(0, str_ptr, hyph_word[j]); + undump(0, max_halfword, hyph_list[j]); + } + +#ifdef ALLOCATEHYPHEN +/* if user specified new hyphen prime - flush existing exception patterns ! */ +/* but, we can reclaim the string storage wasted ... */ + if (is_initex) + { + if (new_hyphen_prime != 0) + { + realloc_hyphen(new_hyphen_prime); /* reset_hyphen(); */ + hyphen_prime = new_hyphen_prime; + } + } +#endif + + { + undump_int(x); + + if (x < 0) + goto bad_fmt; + +#ifdef ALLOCATETRIES + if (!is_initex) + { + allocate_tries(x); /* allocate only as much as is needed */ + } +#endif + + if (x > trie_size) + { + puts("---! Must increase the trie size"); + goto bad_fmt; + } + else + j = x; + } + +#ifdef INITEX + if (is_initex) + trie_max = j; +#endif + + undumpthings(trie_trl[0], j + 1); + undumpthings(trie_tro[0], j + 1); + undumpthings(trie_trc[0], j + 1); + undump_size(0, trie_op_size, "trie op size", j); + +#ifdef INITEX + if (is_initex) + trie_op_ptr = j; +#endif + + undumpthings(hyf_distance[1], j); + undumpthings(hyf_num[1], j); + undumpthings(hyf_next[1], j); + +#ifdef INITEX + if (is_initex) + { + for (k = 0; k <= 255; k++) + trie_used[k] = min_quarterword; + } +#endif + + k = 256; + + while (j > 0) + { + undump(0, k - 1, k); + undump(1, j, x); + +#ifdef INITEX + if (is_initex) + trie_used[k] = x; +#endif + + j = j - x; + op_start[k] = j; + } + +#ifdef INITEX + if (is_initex) + trie_not_ready = false; +#endif + + undump(batch_mode, error_stop_mode, interaction); + undump(0, str_ptr, format_ident); + undump_int(x); + + if ((x != ENDFMTCHECKSUM) || feof(fmt_file)) + goto bad_fmt; + + return true; + +bad_fmt: + puts("(Fatal format file error; I'm stymied)"); + + return false; +} +/* sec 1335 */ +void final_cleanup (void) +{ + small_number c; + + c = cur_chr; + + if (job_name == 0) + open_log_file(); + + while (input_ptr > 0) + { + if (state == token_list) + end_token_list(); + else + end_file_reading(); + } + + while (open_parens > 0) + { + prints(" )"); + decr(open_parens); + } + + if (cur_level > level_one) + { + print_nl("("); + print_esc("end occurred "); + prints("inside a group at level "); + print_int(cur_level - 1); + print_char(')'); + } + + while (cond_ptr != 0) + { + print_nl("("); + print_esc("end occurred "); + prints("when "); + print_cmd_chr(if_test, cur_if); + + if (if_line != 0) + { + prints("on line "); + print_int(if_line); + } + + prints(" was incomplete)"); + if_line = if_line_field(cond_ptr); + cur_if = subtype(cond_ptr); + temp_ptr = cond_ptr; + cond_ptr = link(cond_ptr); + free_node(temp_ptr, if_node_size); + } + + if (history != spotless) + if (((history == warning_issued) || (interaction < error_stop_mode))) + if (selector == term_and_log) + { + selector = term_only; + print_nl("(see the transcript file for additional information)"); + selector = term_and_log; + } + + if (c == 1) + { +#ifdef INITEX + if (is_initex) + { + for (c = 0; c <= 4; c++) + if (cur_mark[c] != 0) + delete_token_ref(cur_mark[c]); + + if (last_glue != max_halfword) + delete_glue_ref(last_glue); + + store_fmt_file(); + } +#endif + + if (!is_initex) + print_nl("(\\dump is performed only by INITEX)"); + } +} + +void show_frozen (void) +{ + int i; + + fprintf(log_file, "\n(%lld fonts frozen in format file:\n", font_ptr); + + for (i = 1; i <= font_ptr; i++) + { + if (i > 1) + fprintf(log_file, ", "); + + if ((i % 8) == 0) + fprintf(log_file, "\n"); + + fwrite(&str_pool[str_start[font_name[i]]], 1, length(font_name[i]), log_file); + } + + fprintf(log_file, ") "); +} + +int main_program (void) +{ + history = fatal_error_stop; + + if (ready_already == 314159L) + goto start_of_TEX; + + bad = 0; + + if ((half_error_line < 30) || (half_error_line > error_line - 15)) + bad = 1; + + if (max_print_line < 60) + bad = 2; + + if (dvi_buf_size % 8 != 0) + bad = 3; + + if (mem_bot + 1100 > mem_top) + bad = 4; + + if (hash_prime > (hash_size + hash_extra)) + bad = 5; + + if (max_in_open >= 128) + bad = 6; + + if (mem_top < 256 + 11) + bad = 7; + +#ifdef INITEX + if (is_initex) + { + if ((mem_min != 0) || (mem_max != mem_top)) + bad = 10; + } +#endif + + if ((mem_min > mem_bot) || (mem_max < mem_top)) + bad = 10; + + if ((min_quarterword > 0) || (max_quarterword < 255)) + bad = 11; + + if ((min_halfword > 0) || (max_halfword < 32767)) + bad = 12; + + if ((min_quarterword < min_halfword) || (max_quarterword > max_halfword)) + bad = 13; + + if ((mem_min < min_halfword) || (mem_max >= max_halfword) || (mem_bot - mem_min >= max_halfword)) + bad = 14; + + if (mem_max > mem_top + mem_extra_high) + bad = 14; + + if ((0 < min_quarterword) || (font_max > max_quarterword)) + bad = 15; + +#ifdef INCREASEFONTS + if (font_max > 65535) +#else + if (font_max > 256) +#endif + bad = 16; + + if ((save_size > max_halfword) || (max_strings > max_halfword)) + bad = 17; + + if (buf_size > max_halfword) + bad = 18; + + if (max_quarterword - min_quarterword < 255) + bad = 19; + + if (cs_token_flag + undefined_control_sequence > max_halfword) + bad = 21; + + if (format_default_length > file_name_size) + bad = 31; + + if (max_halfword < (mem_top - mem_min) / 2) + bad = 41; + + if (bad > 0) + { + printf("%s%s%ld\n", "Ouch---my internal constants have been clobbered!", + "---case ", (long) bad); + + goto final_end; + } + + initialize(); + +#ifdef INITEX + if (is_initex) + { + if (!get_strings_started()) + goto final_end; + + init_prim(); + init_str_ptr = str_ptr; + init_pool_ptr = pool_ptr; + fix_date_and_time(); + } +#endif + + ready_already = 314159L; + +start_of_TEX: + selector = term_only; + tally = 0; + term_offset = 0; + file_offset = 0; + + print_banner(); + + if (format_ident == 0) + { + prints(" (preloaded format="); + prints(format_name); + prints(")"); + print_ln(); + } + else + { + slow_print(format_ident); + print_ln(); + } + + update_terminal(); + job_name = 0; + name_in_progress = false; + log_opened = false; + output_file_name = 0; + + { + { + input_ptr = 0; + max_in_stack = 0; + in_open = 0; + high_in_open = 0; + open_parens = 0; + max_open_parens = 0; + max_buf_stack = 0; + param_ptr = 0; + max_param_stack = 0; + +#ifdef ALLOCATEBUFFER + memset (buffer, 0, current_buf_size); +#else + memset (buffer, 0, buf_size); +#endif + + first = 0; + scanner_status = 0; + warning_index = 0; + first = 1; + state = new_line; + start = 1; + index = 0; + line = 0; + name = 0; + force_eof = false; + align_state = 1000000L; + + if (!init_terminal()) + goto final_end; + + limit = last; + first = last + 1; + } + + if ((format_ident == 0) || (buffer[loc] == '&') || (buffer[loc] == '+')) + { + if (format_ident != 0) + initialize(); + + if (!open_fmt_file()) + goto final_end; + + if (!load_fmt_file()) + { +#ifdef COMPACTFORMAT + gzclose(gz_fmt_file); +#else + w_close(fmt_file); +#endif + goto final_end; + } + +#ifdef COMPACTFORMAT + gzclose(gz_fmt_file); +#else + w_close(fmt_file); +#endif + + while ((loc < limit) && (buffer[loc] == ' ')) + incr(loc); + } + + if (end_line_char_inactive()) + decr(limit); + else + buffer[limit] = end_line_char; + + fix_date_and_time(); + magic_offset = str_start[886] - 9 * ord_noad; + + if (interaction == batch_mode) + selector = no_print; + else + selector = term_only; + + if ((loc < limit) && (cat_code(buffer[loc]) != escape)) + start_input(); + } + + if (show_tfm_flag && log_opened && font_ptr > 0) + show_frozen(); + + main_time = clock(); + history = spotless; + + if (show_cs_names) + print_cs_names(stdout, 0); + + main_control(); + + if (show_cs_names) + print_cs_names(stdout, 1); + + final_cleanup(); + close_files_and_terminate(); + +final_end: + { + int code; + + update_terminal(); + ready_already = 0; + + if ((history != spotless) && (history != warning_issued)) + code = 1; + else + code = 0; + + return code; + } +} + +#ifdef ALLOCATEMAIN +/* add a block of variable size node space below mem_bot(0) */ +void add_variable_space(int size) +{ + halfword p; + halfword q; + integer t; + + if (mem_min == 0) + t = mem_min; + else + t = mem_min + 1; + + mem_min = t - (size + 1); /* first word in new block - 1 */ + + if (mem_min < mem_start) + { + if (trace_flag) + puts("WARNING: mem_min < mem_start!"); + + mem_min = mem_start; + } + + p = llink(rover); + q = mem_min + 1; + link(mem_min) = 0; /* insert blank word below ??? */ + info(mem_min) = 0; /* insert blank word below ??? */ + rlink(p) = q; + llink(rover) = q; + rlink(q) = rover; + llink(q) = p; + link(q) = empty_flag; + info(q) = t - q; /* block size */ + rover = q; +} +#endif + +#ifdef INITEX +/* split out to allow sharing of code from do_initex and newpattern */ +void reset_trie (void) +{ + integer k; + + for (k = -(integer) trie_op_size; k <= trie_op_size; k++) + trie_op_hash[k] = 0; + + for (k = 0; k <= 255; k++) + trie_used[k] = min_trie_op; + + max_op_used = min_trie_op; + trie_op_ptr = 0; + trie_not_ready = true; + trie_l[0] = 0; + trie_c[0] = 0; + trie_ptr = 0; + trie_not_ready = true; +} +/* borrowed code from initialize() */ +void reset_hyphen(void) +{ + hyph_pointer z; + + for (z = 0; z <= hyphen_prime; z++) + { + hyph_word[z] = 0; + hyph_list[z] = 0; + } + + hyph_count = 0; +} +/* split out to allow optimize for space, not time */ +void do_initex (void) +{ + /* integer i; */ + integer k; + /* hyph_pointer z; */ + + for (k = mem_bot + 1; k <= lo_mem_stat_max; k++) + mem[k].cint = 0; + + k = mem_bot; + + while (k <= lo_mem_stat_max) + { + glue_ref_count(k) = 1; + stretch_order(k) = normal; + shrink_order(k) = normal; + k = k + glue_spec_size; + } + + stretch(fil_glue) = unity; + stretch_order(fil_glue) = fil; + stretch(fill_glue) = unity; + stretch_order(fill_glue) = fill; + stretch(ss_glue) = unity; + stretch_order(ss_glue) = fil; + shrink(ss_glue) = unity; + shrink_order(ss_glue) = fil; + stretch(fil_neg_glue) = -unity; + stretch_order(fil_neg_glue) = fil; + rover = lo_mem_stat_max + 1; + link(rover) = empty_flag; + node_size(rover) = block_size; + llink(rover) = rover; + rlink(rover) = rover; + lo_mem_max = rover + block_size; + link(lo_mem_max) = 0; + info(lo_mem_max) = 0; + + for (k = hi_mem_stat_min; k <= mem_top; k++) + mem[k] = mem[lo_mem_max]; + + info(omit_template) = end_template_token; + link(end_span) = max_quarterword + 1; + info(end_span) = 0; + type(last_active) = hyphenated; + line_number(last_active) = max_halfword; + subtype(last_active) = 0; + subtype(page_ins_head) = 255; + type(page_ins_head) = split_up; + link(mem_top) = page_ins_head; + type(page_head) = glue_node; + subtype(page_head) = normal; + avail = 0; + mem_end = mem_top; + hi_mem_min = hi_mem_stat_min; + var_used = lo_mem_stat_max + 1 - mem_bot; + dyn_used = hi_mem_stat_usage; + eq_type(undefined_control_sequence) = undefined_cs; + equiv(undefined_control_sequence) = 0; + eq_level(undefined_control_sequence) = level_zero; + + for (k = active_base; k <= undefined_control_sequence - 1; k++) + eqtb[k] = eqtb[undefined_control_sequence]; + + equiv(glue_base) = zero_glue; + eq_level(glue_base) = level_one; + eq_type(glue_base) = glue_ref; + + for (k = glue_base + 1; k <= local_base - 1; k++) + eqtb[k] = eqtb[glue_base]; + + glue_ref_count(zero_glue) = glue_ref_count(zero_glue) + local_base - glue_base; + + par_shape_ptr = 0; + eq_type(par_shape_loc) = shape_ref; + eq_level(par_shape_loc) = level_one; + + for (k = output_routine_loc; k <= toks_base + 255; k++) + eqtb[k] = eqtb[undefined_control_sequence]; + + box(0) = 0; + eq_type(box_base) = box_ref; + eq_level(box_base) = level_one; + + for (k = box_base + 1; k <= box_base + 255; k++) + eqtb[k] = eqtb[box_base]; + + cur_font = null_font; + eq_type(cur_font_loc) = data; + eq_level(cur_font_loc) = level_one; + + for (k = math_font_base; k <= math_font_base + 47; k++) + eqtb[k] = eqtb[cur_font_loc]; + + equiv(cat_code_base) = 0; + eq_type(cat_code_base) = data; + eq_level(cat_code_base) = level_one; + + for (k = cat_code_base; k <= int_base - 1; k++) + eqtb[k] = eqtb[cat_code_base]; + + for (k = 0; k <= 255; k++) + { + cat_code(k) = other_char; + math_code(k) = k; + sf_code(k) = 1000; + } + + cat_code(carriage_return) = car_ret; + cat_code(' ') = spacer; + cat_code('\\') = escape; + cat_code('%') = comment; + cat_code(invalid_code) = invalid_char; + cat_code(null_code) = ignore; + + for (k = '0'; k <= '9'; k++) + math_code(k) = k + var_code; + + for (k = 'A'; k <= 'Z'; k++) + { + cat_code(k) = letter; + cat_code(k + 'a' - 'A') = letter; + math_code(k) = k + var_code + 0x100; + math_code(k + 'a' - 'A') = k + 'a' - 'A' + var_code + 0x100; + lc_code(k) = k + 'a' - 'A'; + lc_code(k + 'a' - 'A') = k + 'a' - 'A'; + uc_code(k) = k; + uc_code(k + 'a' - 'A') = k; + sf_code(k) = 999; + } + + for (k = int_base; k <= del_code_base - 1; k++) + eqtb[k].cint = 0; + + mag = 1000; + tolerance = 10000; + hang_after = 1; + max_dead_cycles = 25; + escape_char = '\\'; + end_line_char = carriage_return; + + for (k = 0; k <= 255; k++) + del_code(k) = -1; + + del_code('.') = 0; + + for (k = dimen_base; k <= eqtb_size; k++) + eqtb[k].cint = 0; + + hash_used = frozen_control_sequence; + cs_count = 0; + + if (trace_flag) + puts("initex cs_count = 0 "); + + eq_type(frozen_dont_expand) = dont_expand; + text(frozen_dont_expand) = 499; /* "notexpanded:" */ + + font_ptr = null_font; + fmem_ptr = 7; + font_name[null_font] = 795; /* nullfont */ + font_area[null_font] = 335; /* "" */ + hyphen_char[null_font] = '-'; + skew_char[null_font] = -1; + bchar_label[null_font] = non_address; + font_bchar[null_font] = non_char; + font_false_bchar[null_font] = non_char; + font_bc[null_font] = 1; + font_ec[null_font] = 0; + font_size[null_font] = 0; + font_dsize[null_font] = 0; + char_base[null_font] = 0; + width_base[null_font] = 0; + height_base[null_font] = 0; + depth_base[null_font] = 0; + italic_base[null_font] = 0; + lig_kern_base[null_font] = 0; + kern_base[null_font] = 0; + exten_base[null_font] = 0; + font_glue[null_font] = 0; + font_params[null_font] = 7; + param_base[null_font] = -1; + + for (k = 0; k <= 6; k++) + font_info[k].cint = 0; + + reset_trie(); + text(frozen_protection) = 1184; /* "inaccessible" */ + format_ident = 1251; /* " (INITEX)" */ + text(end_write) = 1290; /* "endwrite" */ + eq_level(end_write) = level_one; + eq_type(end_write) = outer_call; + equiv(end_write) = 0; +} +#endif + +#ifdef INITEX +/* sec 0047 */ +boolean get_strings_started (void) +{ + integer k; + str_number g; + + pool_ptr = 0; + str_ptr = 0; + str_start[0] = 0; + + for (k = 0; k <= 255; k++) + { + if ( (k < ' ') || (k > '~') ) + { + append_char('^'); + append_char('^'); + + if (k < 64) + append_char(k + 64); + else if (k < 128) + append_char(k - 64); + else + { + append_lc_hex(k / 16); + append_lc_hex(k % 16); + } + } + else + append_char(k); + + g = make_string(); + } + + g = load_pool_strings(pool_size - string_vacancies); + + if (g == 0) + { + printf("%s\n", "! You have to increase POOLSIZE." ); + return false; + } + + return true; +} +#endif + +#ifdef INITEX +/* sec 0131 */ +void sort_avail (void) +{ + pointer p, q, r; + pointer old_rover; + + p = get_node(010000000000); + p = rlink(rover); + rlink(rover) = empty_flag; + old_rover = rover; + + while (p != old_rover) + { + if (p < rover) + { + q = p; + p = rlink(q); + rlink(q) = rover; + rover = q; + } + else + { + q = rover; + + while (rlink(q) < p) + q = rlink(q); + + r = rlink(p); + rlink(p) = rlink(q); + rlink(q) = p; + p = r; + } + } + + p = rover; + + while (rlink(p) != empty_flag) + { + llink(rlink(p)) = p; + p = rlink(p); + } + + rlink(p) = rover; + llink(rover) = p; +} +#endif + +#ifdef INITEX +/* sec 0264 */ +void primitive_ (str_number s, quarterword c, halfword o) +{ + pool_pointer k; + small_number j; + /* small_number l; */ + int l; + + if (s < 256) + cur_val = s + single_base; + else + { + k = str_start[s]; + l = str_start[s + 1] - k; + + for (j = 0; j <= l - 1; j++) + buffer[j] = str_pool[k + j]; + + cur_val = id_lookup(0, l); + flush_string(); + text(cur_val) = s; + } + + eq_level(cur_val) = level_one; + eq_type(cur_val) = c; + equiv(cur_val) = o; +} +#endif + +#ifdef INITEX +/* sec 0944 */ +trie_op_code new_trie_op (small_number d, small_number n, trie_op_code v) +{ + integer h; + trie_op_code u; + integer l; + + h = abs(n + 313 * d + 361 * v + 1009 * cur_lang) % (trie_op_size + trie_op_size) + neg_trie_op_size; + + while (true) + { + l = trie_op_hash[h]; + + if (l == 0) + { + if (trie_op_ptr == trie_op_size) + { + overflow("pattern memory ops", trie_op_size); + return 0; + } + + u = trie_used[cur_lang]; + + if (u == max_trie_op) + { + overflow("pattern memory ops per language", max_trie_op - min_trie_op); + return 0; + } + + incr(trie_op_ptr); + incr(u); + trie_used[cur_lang] = u; + + if (u > max_op_used) + max_op_used = u; + + hyf_distance[trie_op_ptr] = d; + hyf_num[trie_op_ptr] = n; + hyf_next[trie_op_ptr] = v; + trie_op_lang[trie_op_ptr] = cur_lang; + trie_op_hash[h] = trie_op_ptr; + trie_op_val[trie_op_ptr] = u; + return u; + } + + if ((hyf_distance[l] == d) && (hyf_num[l] == n) && (hyf_next[l] == v) && (trie_op_lang[l] == cur_lang)) + { + return trie_op_val[l]; + } + + if (h > - (integer) trie_op_size) + decr(h); + else + h = trie_op_size; + } +} +/* sec 0948 */ +trie_pointer trie_node (trie_pointer p) +{ + trie_pointer h; + trie_pointer q; + + /* the 1009, 2718, 3142 are hard-wired constants here (not hyphen_prime) */ + /* compute hash value */ + h = abs(trie_c[p] + 1009 * trie_o[p] + 2718 * trie_l[p] + 3142 * trie_r[p]) % trie_size; + + while (true) + { + q = trie_hash[h]; + + if (q == 0) + { + trie_hash[h] = p; + return p; + } + + if ((trie_c[q] == trie_c[p]) && (trie_o[q] == trie_o[p]) && + (trie_l[q] == trie_l[p]) && (trie_r[q] == trie_r[p])) + { + return q; + } + + if (h > 0) + decr(h); + else + h = trie_size; + } +} +/* sec 0949 */ +trie_pointer compress_trie (trie_pointer p) +{ + if (p == 0) + return 0; + else + { + trie_l[p] = compress_trie(trie_l[p]); + trie_r[p] = compress_trie(trie_r[p]); + + return trie_node(p); + } +} +/* sec 0953 */ +void first_fit (trie_pointer p) +{ + trie_pointer h; + trie_pointer z; + trie_pointer q; + ASCII_code c; + trie_pointer l, r; + short ll; + + c = trie_c[p]; + z = trie_min[c]; + + while (true) + { + h = z - c; + + if (trie_max < h + 256) + { + if (trie_size <= h + 256) + { + overflow("pattern memory", trie_size); + return; + } + + do + { + incr(trie_max); + trie_taken[trie_max] = false; + trie_trl[trie_max] = trie_max + 1; + trie_tro[trie_max] = trie_max - 1; + } + while (!(trie_max == h + 256)); + } + + if (trie_taken[h]) + goto not_found; + + q = trie_r[p]; + + while (q > 0) + { + if (trie_trl[h + trie_c[q]] == 0) + goto not_found; + + q = trie_r[q]; + } + + goto found; + +not_found: + z = trie_trl[z]; + } + +found: + trie_taken[h] = true; + trie_hash[p] = h; + q = p; + + do + { + z = h + trie_c[q]; + l = trie_tro[z]; + r = trie_trl[z]; + trie_tro[r] = l; + trie_trl[l] = r; + trie_trl[z] = 0; + + if (l < 256) + { + if (z < 256) + ll = z; /* short ll */ + else + ll = 256; + + do + { + trie_min[l] = r; + incr(l); + } + while (!(l == ll)); + } + + q = trie_r[q]; + } + while (!(q == 0)); +} +/* sec 0957 */ +void trie_pack (trie_pointer p) +{ + trie_pointer q; + + do + { + q = trie_l[p]; + + if ((q > 0) && (trie_hash[q]== 0)) + { + first_fit(q); + trie_pack(q); + } + + p = trie_r[p]; + } + while (!(p == 0)); +} +/* sec 0959 */ +void trie_fix (trie_pointer p) +{ + trie_pointer q; + ASCII_code c; + trie_pointer z; + + z = trie_hash[p]; + + do + { + q = trie_l[p]; + c = trie_c[p]; + trie_trl[z + c] = trie_hash[q]; + trie_trc[z + c] = c; + trie_tro[z + c] = trie_o[p]; + + if (q > 0) + trie_fix(q); + + p = trie_r[p]; + } + while (!(p == 0)); +} +/* sec 0960 */ +void new_patterns (void) +{ + char k, l; + boolean digit_sensed; + trie_op_code v; + trie_pointer p, q; + boolean first_child; + /* ASCII_code c; */ + int c; + + if (!trie_not_ready) + { + if (allow_patterns) + { + if (trace_flag) + puts("Resetting patterns"); + + reset_trie(); + + if (reset_exceptions) + { + if (trace_flag) + puts("Resetting exceptions"); + + reset_hyphen(); + } + } + } + + if (trie_not_ready) + { + set_cur_lang(); + scan_left_brace(); + k = 0; + hyf[0] = 0; + digit_sensed = false; + + while (true) + { + get_x_token(); + + switch (cur_cmd) + { + case letter: + case other_char: + if (digit_sensed || (cur_chr < '0') || (cur_chr > '9')) + { + if (cur_chr == '.') + cur_chr = 0; + else + { + cur_chr = lc_code(cur_chr); + + if (cur_chr == 0) + { + print_err("Nonletter"); + help1("(See Appendix H.)"); + error(); + } + } + + if (k < 63) + { + incr(k); + hc[k] = cur_chr; + hyf[k] = 0; + digit_sensed = false; + } + } + else if (k < 63) + { + hyf[k] = cur_chr - '0'; + digit_sensed = true; + } + break; + case spacer: + case right_brace: + { + if (k > 0) + { + if (hc[1] == 0) + hyf[0] = 0; + + if (hc[k] == 0) + hyf[k] = 0; + + l = k; + v = min_trie_op; + + while (true) + { + if (hyf[l]!= 0) + v = new_trie_op(k - l, hyf[l], v); + + if (l > 0) + decr(l); + else + goto done1; + } +done1: + q = 0; + hc[0] = cur_lang; + + while (l <= k) + { + c = hc[l]; + incr(l); + p = trie_l[q]; + first_child = true; + + while ((p > 0) && (c > trie_c[p])) + { + q = p; + p = trie_r[q]; + first_child = false; + } + + if ((p == 0) || (c < trie_c[p])) + { + if (trie_ptr == trie_size) + { + overflow("pattern memory", trie_size); + return; + } + + incr(trie_ptr); + trie_r[trie_ptr] = p; + p = trie_ptr; + trie_l[p] = 0; + + if (first_child) + trie_l[q] = p; + else + trie_r[q] = p; + + trie_c[p] = c; + trie_o[p] = min_trie_op; + } + + q = p; + } + + if (trie_o[q] != min_trie_op) + { + print_err("Duplicate pattern"); + help1("(See Appendix H.)"); + error(); + } + + trie_o[q] = v; + } + + if (cur_cmd == right_brace) + goto done; + + k = 0; + hyf[0] = 0; + digit_sensed = false; + } + break; + default: + { + print_err("Bad "); + print_esc("patterns"); + help1("(See Appendix H.)"); + error(); + } + break; + } + } +done:; + } + else + { + print_err("Too late for "); + print_esc("patterns"); + help1("All patterns must be given before typesetting begins."); + error(); + link(garbage) = scan_toks(false, false); + flush_list(def_ref); + } +} +/* sec 0966 */ +void init_trie (void) +{ + trie_pointer p; + /* integer j, k, t; */ + integer j, k; + int t; + trie_pointer r, s; + + op_start[0] = - (integer) min_trie_op; + + for (j = 1; j <= 255; j++) + op_start[j] = op_start[j - 1] + trie_used[j - 1]; + + for (j = 1; j <= trie_op_ptr; j++) + trie_op_hash[j] = op_start[trie_op_lang[j]] + trie_op_val[j]; + + for (j = 1; j <= trie_op_ptr; j++) + { + while (trie_op_hash[j] > j) + { + k = trie_op_hash[j]; + t = hyf_distance[k]; + hyf_distance[k] = hyf_distance[j]; + hyf_distance[j] = t; + t = hyf_num[k]; + hyf_num[k] = hyf_num[j]; + hyf_num[j] = t; + t = hyf_next[k]; + hyf_next[k] = hyf_next[j]; + hyf_next[j]= t; + trie_op_hash[j] = trie_op_hash[k]; + trie_op_hash[k] = k; + } + } + + for (p = 0; p <= trie_size; p++) + trie_hash[p] = 0; + + trie_l[0] = compress_trie(trie_l[0]); + + for (p = 0; p <= trie_ptr; p++) + trie_hash[p] = 0; + + for (p = 0; p <= 255; p++) + trie_min[p] = p + 1; + + trie_trl[0] = 1; + trie_max = 0; + + if (trie_l[0] != 0) + { + first_fit(trie_l[0]); + trie_pack(trie_l[0]); + } + + if (trie_l[0] == 0) + { + for (r = 0; r <= 256; r++) + { + trie_trl[r] = 0; + trie_tro[r] = min_trie_op; + trie_trc[r] = 0; + } + + trie_max = 256; + } + else + { + trie_fix(trie_l[0]); + r = 0; + + do + { + s = trie_trl[r]; + + { + trie_trl[r] = 0; + trie_tro[r] = min_trie_op; + trie_trc[r] = 0; + } + + r = s; + } + while (!(r > trie_max)); + } + + trie_trc[0] = 63; + trie_not_ready = false; +} +#endif + +#ifdef INITEX +/* sec 1302 */ +void store_fmt_file (void) +{ + integer j, k, l; + pointer p, q; + integer x; + + if (!is_initex) + { + puts("! \\dump is performed only by INITEX"); + + if (!knuth_flag) + puts(" (Use -i on the command line)"); + + return; + } + + if (save_ptr != 0) + { + print_err("You can't dump inside a group"); + help1("`{...\\dump}' is a no-no."); + succumb(); + } + + selector = new_string; + prints(" (preloaded format="); + print(job_name); + print_char(' '); + print_int(year); + print_char('.'); + print_int(month); + print_char('.'); + print_int(day); + print_char(')'); + + if (interaction == batch_mode) + selector = log_only; + else + selector = term_and_log; + + str_room(1); + format_ident = make_string(); + pack_job_name(".fmt"); + + while (!w_open_out(fmt_file)) + prompt_file_name("format file name", ".fmt"); + + print_nl("Beginning to dump on file "); + slow_print(w_make_name_string(fmt_file)); + flush_string(); + print_nl(""); + slow_print(format_ident); + + dump_int(BEGINFMTCHECKSUM); + dump_int(mem_bot); + dump_int(mem_top); + dump_int(eqtb_size); + dump_int(hash_prime); + dump_int(hyphen_prime); + dump_int(pool_ptr); + dump_int(str_ptr); + dumpthings(str_start[0], str_ptr + 1); + dumpthings(str_pool[0], pool_ptr); + print_ln(); + print_int(str_ptr); + prints(" strings of total length "); + print_int(pool_ptr); + + sort_avail(); + var_used = 0; + dump_int(lo_mem_max); + dump_int(rover); + p = 0; + q = rover; + x = 0; + + do + { + if (dumpthings(mem[p], q + 2 - p)) + return; + + x = x + q + 2 - p; + var_used = var_used + q - p; + p = q + node_size(q); + q = rlink(q); + } + while (!(q == rover)); + + var_used = var_used + lo_mem_max - p; + dyn_used = mem_end + 1 - hi_mem_min; + + if (dumpthings(mem[p], lo_mem_max + 1 - p)) + return; + + x = x + lo_mem_max + 1 - p; + dump_int(hi_mem_min); + dump_int(avail); + + if (dumpthings(mem[hi_mem_min], mem_end + 1 - hi_mem_min)) + return; + + x = x + mem_end + 1 - hi_mem_min; + p = avail; + + while (p != 0) + { + decr(dyn_used); + p = link(p); + } + + dump_int(var_used); + dump_int(dyn_used); + print_ln(); + print_int(x); + prints(" memory locations dumped; current usage is "); + print_int(var_used); + print_char('&'); + print_int(dyn_used); + + k = active_base; + + do + { + j = k; + + while (j < (int_base - 1)) + { + if ((equiv(j) == equiv(j + 1)) && + (eq_type(j) == eq_type(j + 1)) && + (eq_level(j) == eq_level(j + 1))) + goto found1; + + incr(j); + } + + l = (int_base); + goto done1; + +found1: + incr(j); + l = j; + + while (j < (int_base - 1)) + { + if ((equiv(j) != equiv(j + 1)) || + (eq_type(j) != eq_type(j + 1)) || + (eq_level(j) != eq_level(j + 1))) + goto done1; + + incr(j); + } + +done1: + dump_int(l - k); + + if (dumpthings(eqtb[k], l - k)) + return; + + k = j + 1; + dump_int(k - l); + } + while (!(k == (int_base))); + + do + { + j = k; + + while (j < (eqtb_size)) + { + if (eqtb[j].cint == eqtb[j + 1].cint) + goto found2; + + incr(j); + } + + l = (eqtb_size + 1); + goto done2; + +found2: + incr(j); + l = j; + + while (j < (eqtb_size)) + { + if (eqtb[j].cint != eqtb[j + 1].cint) + goto done2; + + incr(j); + } + +done2: + dump_int(l - k); + + if (dumpthings(eqtb[k], l - k)) + return; + + k = j + 1; + dump_int(k - l); + } + while (!(k > (eqtb_size))); + + dump_int(par_loc); + dump_int(write_loc); + + dump_int(hash_used); + cs_count = frozen_control_sequence - 1 - hash_used; + + if (trace_flag) + printf("itex cs_count %lld hash_size %d hash_extra %d hash_used %d", + cs_count, hash_size, hash_extra, hash_used); + + for (p = hash_base; p <= hash_used; p++) + { + if (text(p) != 0) + { + dump_int(p); + dump_hh(hash[p]); + incr(cs_count); + + if (trace_flag) + puts("itex.c store_fmt_file() cs_count++ "); + } + } + + if (dumpthings(hash[hash_used + 1], undefined_control_sequence - 1 - hash_used)) + return; + + dump_int(cs_count); + print_ln(); + print_int(cs_count); + prints(" multiletter control sequences"); + + dump_int(fmem_ptr); + + { + dumpthings(font_info[0], fmem_ptr); + dump_int(font_ptr); + dumpthings(font_check[0], font_ptr + 1); + dumpthings(font_size[0], font_ptr + 1); + dumpthings(font_dsize[0], font_ptr + 1); + dumpthings(font_params[0], font_ptr + 1); + dumpthings(hyphen_char[0], font_ptr + 1); + dumpthings(skew_char[0], font_ptr + 1); + dumpthings(font_name[0], font_ptr + 1); + dumpthings(font_area[0], font_ptr + 1); + dumpthings(font_bc[0], font_ptr + 1); + dumpthings(font_ec[0], font_ptr + 1); + dumpthings(char_base[0], font_ptr + 1); + dumpthings(width_base[0], font_ptr + 1); + dumpthings(height_base[0], font_ptr + 1); + dumpthings(depth_base[0], font_ptr + 1); + dumpthings(italic_base[0], font_ptr + 1); + dumpthings(lig_kern_base[0], font_ptr + 1); + dumpthings(kern_base[0], font_ptr + 1); + dumpthings(exten_base[0], font_ptr + 1); + dumpthings(param_base[0], font_ptr + 1); + dumpthings(font_glue[0], font_ptr + 1); + dumpthings(bchar_label[0], font_ptr + 1); + dumpthings(font_bchar[0], font_ptr + 1); + dumpthings(font_false_bchar[0], font_ptr + 1); + + for (k = 0; k <= font_ptr; k++) + { + print_nl("\\font"); + print_esc(""); + print(font_id_text(k)); + print_char('='); + print_file_name(font_name[k], font_area[k], 335); + + if (font_size[k] != font_dsize[k]) + { + prints(" at "); + print_scaled(font_size[k]); + prints("pt"); + } + } + } + + print_ln(); + print_int(fmem_ptr - 7); + prints(" words of font info for "); + print_int(font_ptr - font_base); + prints(" preloaded font"); + + if (font_ptr != font_base + 1) + print_char('s'); + + dump_int(hyph_count); + + for (k = 0; k <= hyphen_prime; k++) + { + if (hyph_word[k] != 0) + { + dump_int(k); + dump_int(hyph_word[k]); + dump_int(hyph_list[k]); + } + } + + print_ln(); + print_int(hyph_count); + prints(" hyphenation exception"); + + if (hyph_count != 1) + print_char('s'); + + if (trie_not_ready) + init_trie(); + + dump_int(trie_max); + dumpthings(trie_trl[0], trie_max + 1); + dumpthings(trie_tro[0], trie_max + 1); + dumpthings(trie_trc[0], trie_max + 1); + dump_int(trie_op_ptr); + dumpthings(hyf_distance[1], trie_op_ptr); + dumpthings(hyf_num[1], trie_op_ptr); + dumpthings(hyf_next[1], trie_op_ptr); + print_nl("Hyphenation trie of length "); + print_int(trie_max); + prints(" has "); + print_int(trie_op_ptr); + prints(" op"); + + if (trie_op_ptr != 1) + print_char('s'); + + prints(" out of "); + print_int(trie_op_size); + + for (k = 255; k >= 0; k--) + { + if (trie_used[k] > 0) + { + print_nl(" "); + print_int(trie_used[k]); + prints(" for language "); + print_int(k); + dump_int(k); + dump_int(trie_used[k]); + } + } + + dump_int(interaction); + dump_int(format_ident); + dump_int(ENDFMTCHECKSUM); + tracing_stats = 0; + +#ifdef COMPACTFORMAT + gz_w_close(gz_fmt_file); +#else + w_close(fmt_file); +#endif +} +#endif + +#ifdef INITEX +/* sec 01336 */ +void init_prim (void) +{ + no_new_control_sequence = false; + /* sec 0266 */ + primitive("lineskip", assign_glue, glue_base + line_skip_code); + primitive("baselineskip", assign_glue, glue_base + baseline_skip_code); + primitive("parskip", assign_glue, glue_base + par_skip_code); + primitive("abovedisplayskip", assign_glue, glue_base + above_display_skip_code); + primitive("belowdisplayskip", assign_glue, glue_base + below_display_skip_code); + primitive("abovedisplayshortskip", assign_glue, glue_base + above_display_short_skip_code); + primitive("belowdisplayshortskip", assign_glue, glue_base + below_display_short_skip_code); + primitive("leftskip", assign_glue, glue_base + left_skip_code); + primitive("rightskip", assign_glue, glue_base + right_skip_code); + primitive("topskip", assign_glue, glue_base + top_skip_code); + primitive("splittopskip", assign_glue, glue_base + split_top_skip_code); + primitive("tabskip", assign_glue, glue_base + tab_skip_code); + primitive("spaceskip", assign_glue, glue_base + space_skip_code); + primitive("xspaceskip", assign_glue, glue_base + xspace_skip_code); + primitive("parfillskip", assign_glue, glue_base + par_fill_skip_code); + primitive("thinmuskip", assign_mu_glue, glue_base + thin_mu_skip_code); + primitive("medmuskip", assign_mu_glue, glue_base + med_mu_skip_code); + primitive("thickmuskip", assign_mu_glue, glue_base + thick_mu_skip_code); + /* sec 0230 */ + primitive("output", assign_toks, output_routine_loc); + primitive("everypar", assign_toks, every_par_loc); + primitive("everymath", assign_toks, every_math_loc); + primitive("everydisplay", assign_toks, every_display_loc); + primitive("everyhbox", assign_toks, every_hbox_loc); + primitive("everyvbox", assign_toks, every_vbox_loc); + primitive("everyjob", assign_toks, every_job_loc); + primitive("everycr", assign_toks, every_cr_loc); + primitive("errhelp", assign_toks, err_help_loc); + /* sec 0238 */ + primitive("pretolerance", assign_int, int_base + pretolerance_code); + primitive("tolerance", assign_int, int_base + tolerance_code); + primitive("linepenalty", assign_int, int_base + line_penalty_code); + primitive("hyphenpenalty", assign_int, int_base + hyphen_penalty_code); + primitive("exhyphenpenalty", assign_int, int_base + ex_hyphen_penalty_code); + primitive("clubpenalty", assign_int, int_base + club_penalty_code); + primitive("widowpenalty", assign_int, int_base + widow_penalty_code); + primitive("displaywidowpenalty", assign_int, int_base + display_widow_penalty_code); + primitive("brokenpenalty", assign_int, int_base + broken_penalty_code); + primitive("binoppenalty", assign_int, int_base + bin_op_penalty_code); + primitive("relpenalty", assign_int, int_base + rel_penalty_code); + primitive("predisplaypenalty", assign_int, int_base + pre_display_penalty_code); + primitive("postdisplaypenalty", assign_int, int_base + post_display_penalty_code); + primitive("interlinepenalty", assign_int, int_base + inter_line_penalty_code); + primitive("doublehyphendemerits", assign_int, int_base + double_hyphen_demerits_code); + primitive("finalhyphendemerits", assign_int, int_base + final_hyphen_demerits_code); + primitive("adjdemerits", assign_int, int_base + adj_demerits_code); + primitive("mag", assign_int, int_base + mag_code); + primitive("delimiterfactor", assign_int, int_base + delimiter_factor_code); + primitive("looseness", assign_int, int_base + looseness_code); + primitive("time", assign_int, int_base + time_code); + primitive("day", assign_int, int_base + day_code); + primitive("month", assign_int, int_base + month_code); + primitive("year", assign_int, int_base + year_code); + primitive("showboxbreadth", assign_int, int_base + show_box_breadth_code); + primitive("showboxdepth", assign_int, int_base + show_box_depth_code); + primitive("hbadness", assign_int, int_base + hbadness_code); + primitive("vbadness", assign_int, int_base + vbadness_code); + primitive("pausing", assign_int, int_base + pausing_code); + primitive("tracingonline", assign_int, int_base + tracing_online_code); + primitive("tracingmacros", assign_int, int_base + tracing_macros_code); + primitive("tracingstats", assign_int, int_base + tracing_stats_code); + primitive("tracingparagraphs", assign_int, int_base + tracing_paragraphs_code); + primitive("tracingpages", assign_int, int_base + tracing_pages_code); + primitive("tracingoutput", assign_int, int_base + tracing_output_code); + primitive("tracinglostchars", assign_int, int_base + tracing_lost_chars_code); + primitive("tracingcommands", assign_int, int_base + tracing_commands_code); + primitive("tracingrestores", assign_int, int_base + tracing_restores_code); + primitive("uchyph", assign_int, int_base + uc_hyph_code); + primitive("outputpenalty", assign_int, int_base + output_penalty_code); + primitive("maxdeadcycles", assign_int, int_base + max_dead_cycles_code); + primitive("hangafter", assign_int, int_base + hang_after_code); + primitive("floatingpenalty", assign_int, int_base + floating_penalty_code); + primitive("globaldefs", assign_int, int_base + global_defs_code); + primitive("fam", assign_int, int_base + cur_fam_code); + primitive("escapechar", assign_int, int_base + escape_char_code); + primitive("defaulthyphenchar", assign_int, int_base + default_hyphen_char_code); + primitive("defaultskewchar", assign_int, int_base + default_skew_char_code); + primitive("endlinechar", assign_int, int_base + end_line_char_code); + primitive("newlinechar", assign_int, int_base + new_line_char_code); + primitive("language", assign_int, int_base + language_code); + primitive("lefthyphenmin", assign_int, int_base + left_hyphen_min_code); + primitive("righthyphenmin", assign_int, int_base + right_hyphen_min_code); + primitive("holdinginserts", assign_int, int_base + holding_inserts_code); + primitive("errorcontextlines", assign_int, int_base + error_context_lines_code); + /* sec 0248 */ + primitive("parindent", assign_dimen, dimen_base + par_indent_code); + primitive("mathsurround", assign_dimen, dimen_base + math_surround_code); + primitive("lineskiplimit", assign_dimen, dimen_base + line_skip_limit_code); + primitive("hsize", assign_dimen, dimen_base + hsize_code); + primitive("vsize", assign_dimen, dimen_base + vsize_code); + primitive("maxdepth", assign_dimen, dimen_base + max_depth_code); + primitive("splitmaxdepth", assign_dimen, dimen_base + split_max_depth_code); + primitive("boxmaxdepth", assign_dimen, dimen_base + box_max_depth_code); + primitive("hfuzz", assign_dimen, dimen_base + hfuzz_code); + primitive("vfuzz", assign_dimen, dimen_base + vfuzz_code); + primitive("delimitershortfall", assign_dimen, dimen_base + delimiter_shortfall_code); + primitive("nulldelimiterspace", assign_dimen, dimen_base + null_delimiter_space_code); + primitive("scriptspace", assign_dimen, dimen_base + script_space_code); + primitive("predisplaysize", assign_dimen, dimen_base + pre_display_size_code); + primitive("displaywidth", assign_dimen, dimen_base + display_width_code); + primitive("displayindent", assign_dimen, dimen_base + display_indent_code); + primitive("overfullrule", assign_dimen, dimen_base + overfull_rule_code); + primitive("hangindent", assign_dimen, dimen_base + hang_indent_code); + primitive("hoffset", assign_dimen, dimen_base + h_offset_code); + primitive("voffset", assign_dimen, dimen_base + v_offset_code); + primitive("emergencystretch", assign_dimen, dimen_base + emergency_stretch_code); + primitive(" ", ex_space, 0); + primitive("/", ital_corr, 0); + primitive("accent", accent, 0); + primitive("advance", advance, 0); + primitive("afterassignment", after_assignment, 0); + primitive("aftergroup", after_group, 0); + primitive("begingroup", begin_group, 0); + primitive("char", char_num, 0); + primitive("csname", cs_name, 0); + primitive("delimiter", delim_num, 0); + primitive("divide", divide, 0); + primitive("endcsname", end_cs_name, 0); + primitive("endgroup", end_group, 0); + text(frozen_end_group) = make_string_pool("endgroup"); + eqtb[frozen_end_group] = eqtb[cur_val]; + primitive("expandafter", expand_after, 0); + primitive("font", def_font, 0); + primitive("fontdimen", assign_font_dimen, 0); + primitive("halign", halign, 0); + primitive("hrule", hrule, 0); + primitive("ignorespaces", ignore_spaces, 0); + primitive("insert", insert, 0); + primitive("mark", mark, 0); + primitive("mathaccent", math_accent, 0); + primitive("mathchar", math_char_num, 0); + primitive("mathchoice", math_choice, 0); + primitive("multiply", multiply, 0); + primitive("noalign", no_align, 0); + primitive("noboundary", no_boundary, 0); + primitive("noexpand", no_expand, 0); + primitive("nonscript", non_script, 0); + primitive("omit", omit, 0); + primitive("parshape", set_shape, 0); + primitive("penalty", break_penalty, 0); + primitive("prevgraf", set_prev_graf, 0); + primitive("radical", radical, 0); + primitive("read", read_to_cs, 0); + primitive("relax", relax, 256); + text(frozen_relax) = make_string_pool("relax"); + eqtb[frozen_relax] = eqtb[cur_val]; + primitive("setbox", set_box, 0); + primitive("the", the, 0); + primitive("toks", toks_register, 0); + primitive("vadjust", vadjust, 0); + primitive("valign", valign, 0); + primitive("vcenter", vcenter, 0); + primitive("vrule", vrule, 0); + primitive("par", par_end, 256); + par_loc = cur_val; + par_token = cs_token_flag + par_loc; + primitive("input", input, 0); + primitive("endinput", input, 1); + primitive("topmark", top_bot_mark, top_mark_code); + primitive("firstmark", top_bot_mark, first_mark_code); + primitive("botmark", top_bot_mark, bot_mark_code); + primitive("splitfirstmark", top_bot_mark, split_first_mark_code); + primitive("splitbotmark", top_bot_mark, split_bot_mark_code); + primitive("count", tex_register, int_val); + primitive("dimen", tex_register, dimen_val); + primitive("skip", tex_register, glue_val); + primitive("muskip", tex_register, mu_val); + primitive("spacefactor", set_aux, hmode); + primitive("prevdepth", set_aux, vmode); + primitive("deadcycles", set_page_int, 0); + primitive("insertpenalties", set_page_int, 1); + primitive("wd", set_box_dimen, width_offset); + primitive("ht", set_box_dimen, height_offset); + primitive("dp", set_box_dimen, depth_offset); + primitive("lastpenalty", last_item, int_val); + primitive("lastkern", last_item, dimen_val); + primitive("lastskip", last_item, glue_val); + primitive("inputlineno", last_item, input_line_no_code); + primitive("badness", last_item, badness_code); + primitive("number", convert, number_code); + primitive("romannumeral", convert, roman_numeral_code); + primitive("string", convert, string_code); + primitive("meaning", convert, meaning_code); + primitive("fontname", convert, font_name_code); + primitive("jobname", convert, job_name_code); + primitive("if", if_test, if_char_code); + primitive("ifcat", if_test, if_cat_code); + primitive("ifnum", if_test, if_int_code); + primitive("ifdim", if_test, if_dim_code); + primitive("ifodd", if_test, if_odd_code); + primitive("ifvmode", if_test, if_vmode_code); + primitive("ifhmode", if_test, if_hmode_code); + primitive("ifmmode", if_test, if_mmode_code); + primitive("ifinner", if_test, if_inner_code); + primitive("ifvoid", if_test, if_void_code); + primitive("ifhbox", if_test, if_hbox_code); + primitive("ifvbox", if_test, if_vbox_code); + primitive("ifx", if_test, ifx_code); + primitive("ifeof", if_test, if_eof_code); + primitive("iftrue", if_test, if_true_code); + primitive("iffalse", if_test, if_false_code); + primitive("ifcase", if_test, if_case_code); + primitive("fi", fi_or_else, fi_code); + text(frozen_fi) = make_string_pool("fi"); + eqtb[frozen_fi] = eqtb[cur_val]; + primitive("or", fi_or_else, or_code); + primitive("else", fi_or_else, else_code); + primitive("nullfont", set_font, null_font); + text(frozen_null_font) = 795; + eqtb[frozen_null_font] = eqtb[cur_val]; + primitive("span", tab_mark, span_code); + primitive("cr", car_ret, cr_code); + text(frozen_cr) = make_string_pool("cr"); + eqtb[frozen_cr] = eqtb[cur_val]; + primitive("crcr", car_ret, cr_cr_code); + text(frozen_end_template) = make_string_pool("endtemplate"); + text(frozen_endv) = make_string_pool("endtemplate"); + eq_type(frozen_endv) = endv; + equiv(frozen_endv) = null_list; + eq_level(frozen_endv) = level_one; + eqtb[frozen_end_template] = eqtb[frozen_endv]; + eq_type(frozen_end_template) = end_template; + primitive("pagegoal", set_page_dimen, 0); + primitive("pagetotal", set_page_dimen, 1); + primitive("pagestretch", set_page_dimen, 2); + primitive("pagefilstretch", set_page_dimen, 3); + primitive("pagefillstretch", set_page_dimen, 4); + primitive("pagefilllstretch", set_page_dimen, 5); + primitive("pageshrink", set_page_dimen, 6); + primitive("pagedepth", set_page_dimen, 7); + primitive("end", stop, 0); + primitive("dump", stop, 1); + primitive("hskip", hskip, skip_code); + primitive("hfil", hskip, fil_code); + primitive("hfill", hskip, fill_code); + primitive("hss", hskip, ss_code); + primitive("hfilneg", hskip, fil_neg_code); + primitive("vskip", vskip, skip_code); + primitive("vfil", vskip, fil_code); + primitive("vfill", vskip, fill_code); + primitive("vss", vskip, ss_code); + primitive("vfilneg", vskip, fil_neg_code); + primitive("mskip", mskip, mskip_code); + primitive("kern", kern, explicit); + primitive("mkern", mkern, mu_glue); + primitive("moveleft", hmove, 1); + primitive("moveright", hmove, 0); + primitive("raise", vmove, 1); + primitive("lower", vmove, 0); + primitive("box", make_box, box_code); + primitive("copy", make_box, copy_code); + primitive("lastbox", make_box, last_box_code); + primitive("vsplit", make_box, vsplit_code); + primitive("vtop", make_box, vtop_code); + primitive("vbox", make_box, vtop_code + vmode); + primitive("hbox", make_box, vtop_code + hmode); + primitive("shipout", leader_ship, a_leaders - 1); + primitive("leaders", leader_ship, a_leaders); + primitive("cleaders", leader_ship, c_leaders); + primitive("xleaders", leader_ship, x_leaders); + primitive("indent", start_par, 1); + primitive("noindent", start_par, 0); + primitive("unpenalty", remove_item, penalty_node); + primitive("unkern", remove_item, kern_node); + primitive("unskip", remove_item, glue_node); + primitive("unhbox", un_hbox, box_code); + primitive("unhcopy", un_hbox, copy_code); + primitive("unvbox", un_vbox, box_code); + primitive("unvcopy", un_vbox, copy_code); + primitive("-", discretionary, 1); + primitive("discretionary", discretionary, 0); + primitive("eqno", eq_no, 0); + primitive("leqno", eq_no, 1); + primitive("mathord", math_comp, ord_noad); + primitive("mathop", math_comp, op_noad); + primitive("mathbin", math_comp, bin_noad); + primitive("mathrel", math_comp, rel_noad); + primitive("mathopen", math_comp, open_noad); + primitive("mathclose", math_comp, close_noad); + primitive("mathpunct", math_comp, punct_noad); + primitive("mathinner", math_comp, inner_noad); + primitive("underline", math_comp, under_noad); + primitive("overline", math_comp, over_noad); + primitive("displaylimits", limit_switch, normal); + primitive("limits", limit_switch, limits); + primitive("nolimits", limit_switch, no_limits); + primitive("displaystyle", math_style, display_style); + primitive("textstyle", math_style, text_style); + primitive("scriptstyle", math_style, script_style); + primitive("scriptscriptstyle", math_style, script_script_style); + primitive("above", above, above_code); + primitive("over", above, over_code); + primitive("atop", above, atop_code); + primitive("abovewithdelims", above, delimited_code + above_code); + primitive("overwithdelims", above, delimited_code + over_code); + primitive("atopwithdelims", above, delimited_code + atop_code); + primitive("left", left_right, left_noad); + primitive("right", left_right, right_noad); + text(frozen_right) = make_string_pool("right"); + eqtb[frozen_right] = eqtb[cur_val]; + primitive("long", prefix, 1); + primitive("outer", prefix, 2); + primitive("global", prefix, 4); + primitive("def", def, 0); + primitive("gdef", def, 1); + primitive("edef", def, 2); + primitive("xdef", def, 3); + primitive("let", let, normal); + primitive("futurelet", let, normal + 1); + primitive("chardef", shorthand_def, char_def_code); + primitive("mathchardef", shorthand_def, math_char_def_code); + primitive("countdef", shorthand_def, count_def_code); + primitive("dimendef", shorthand_def, dimen_def_code); + primitive("skipdef", shorthand_def, skip_def_code); + primitive("muskipdef", shorthand_def, mu_skip_def_code); + primitive("toksdef", shorthand_def, toks_def_code); + primitive("catcode", def_code, cat_code_base); + primitive("mathcode", def_code, math_code_base); + primitive("lccode", def_code, lc_code_base); + primitive("uccode", def_code, uc_code_base); + primitive("sfcode", def_code, sf_code_base); + primitive("delcode", def_code, del_code_base); + primitive("textfont", def_family, math_font_base); + primitive("scriptfont", def_family, math_font_base + script_size); + primitive("scriptscriptfont", def_family, math_font_base + script_script_size); + primitive("hyphenation", hyph_data, 0); + primitive("patterns", hyph_data, 1); + primitive("hyphenchar", assign_font_int, 0); + primitive("skewchar", assign_font_int, 1); + primitive("batchmode", set_interaction, batch_mode); + primitive("nonstopmode", set_interaction, nonstop_mode); + primitive("scrollmode", set_interaction, scroll_mode); + primitive("errorstopmode", set_interaction, error_stop_mode); + primitive("openin", in_stream, 1); + primitive("closein", in_stream, 0); + primitive("message", message, 0); + primitive("errmessage", message, 1); + primitive("lowercase", case_shift, lc_code_base); + primitive("uppercase", case_shift, uc_code_base); + primitive("show", xray, show_code); + primitive("showbox", xray, show_box_code); + primitive("showthe", xray, show_the_code); + primitive("showlists", xray, show_lists); + primitive("openout", extension, open_node); + primitive("write", extension, write_node); + write_loc = cur_val; + primitive("closeout", extension, close_node); + primitive("special", extension, special_node); + primitive("immediate", extension, immediate_code); + primitive("setlanguage", extension, set_language_code); + no_new_control_sequence = true; +} +#endif diff --git a/src/texsourc/libmd5/md5.c b/src/texsourc/libmd5/md5.c deleted file mode 100644 index c35d96c..0000000 --- a/src/texsourc/libmd5/md5.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.c is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order - either statically or dynamically; added missing #include - in library. - 2002-03-11 lpd Corrected argument list for main(), and added int return - type, in test program and T value program. - 2002-02-21 lpd Added missing #include in test program. - 2000-07-03 lpd Patched to eliminate warnings about "constant is - unsigned in ANSI C, signed in traditional"; made test program - self-checking. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). - 1999-05-03 lpd Original version. - */ - -#include "md5.h" -#include - -#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ -#ifdef ARCH_IS_BIG_ENDIAN -# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) -#else -# define BYTE_ORDER 0 -#endif - -#define T_MASK ((md5_word_t)~0) -#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) -#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) -#define T3 0x242070db -#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) -#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) -#define T6 0x4787c62a -#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) -#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) -#define T9 0x698098d8 -#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) -#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) -#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) -#define T13 0x6b901122 -#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) -#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) -#define T16 0x49b40821 -#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) -#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) -#define T19 0x265e5a51 -#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) -#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) -#define T22 0x02441453 -#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) -#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) -#define T25 0x21e1cde6 -#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) -#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) -#define T28 0x455a14ed -#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) -#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) -#define T31 0x676f02d9 -#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) -#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) -#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) -#define T35 0x6d9d6122 -#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) -#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) -#define T38 0x4bdecfa9 -#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) -#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) -#define T41 0x289b7ec6 -#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) -#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) -#define T44 0x04881d05 -#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) -#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) -#define T47 0x1fa27cf8 -#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) -#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) -#define T50 0x432aff97 -#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) -#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) -#define T53 0x655b59c3 -#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) -#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) -#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) -#define T57 0x6fa87e4f -#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) -#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) -#define T60 0x4e0811a1 -#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) -#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) -#define T63 0x2ad7d2bb -#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) - - -static void -md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) -{ - md5_word_t - a = pms->abcd[0], b = pms->abcd[1], - c = pms->abcd[2], d = pms->abcd[3]; - md5_word_t t; -#if BYTE_ORDER > 0 - /* Define storage only for big-endian CPUs. */ - md5_word_t X[16]; -#else - /* Define storage for little-endian or both types of CPUs. */ - md5_word_t xbuf[16]; - const md5_word_t *X; -#endif - - { -#if BYTE_ORDER == 0 - /* - * Determine dynamically whether this is a big-endian or - * little-endian machine, since we can use a more efficient - * algorithm on the latter. - */ - static const int w = 1; - - if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ -#endif -#if BYTE_ORDER <= 0 /* little-endian */ - { - /* - * On little-endian machines, we can process properly aligned - * data without copying it. - */ - if (!((data - (const md5_byte_t *)0) & 3)) { - /* data are properly aligned */ - X = (const md5_word_t *)data; - } else { - /* not aligned */ - memcpy(xbuf, data, 64); - X = xbuf; - } - } -#endif -#if BYTE_ORDER == 0 - else /* dynamic big-endian */ -#endif -#if BYTE_ORDER >= 0 /* big-endian */ - { - /* - * On big-endian machines, we must arrange the bytes in the - * right order. - */ - const md5_byte_t *xp = data; - int i; - -# if BYTE_ORDER == 0 - X = xbuf; /* (dynamic only) */ -# else -# define xbuf X /* (static only) */ -# endif - for (i = 0; i < 16; ++i, xp += 4) - xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); - } -#endif - } - -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - - /* Round 1. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ -#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + F(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 7, T1); - SET(d, a, b, c, 1, 12, T2); - SET(c, d, a, b, 2, 17, T3); - SET(b, c, d, a, 3, 22, T4); - SET(a, b, c, d, 4, 7, T5); - SET(d, a, b, c, 5, 12, T6); - SET(c, d, a, b, 6, 17, T7); - SET(b, c, d, a, 7, 22, T8); - SET(a, b, c, d, 8, 7, T9); - SET(d, a, b, c, 9, 12, T10); - SET(c, d, a, b, 10, 17, T11); - SET(b, c, d, a, 11, 22, T12); - SET(a, b, c, d, 12, 7, T13); - SET(d, a, b, c, 13, 12, T14); - SET(c, d, a, b, 14, 17, T15); - SET(b, c, d, a, 15, 22, T16); -#undef SET - - /* Round 2. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ -#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + G(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 1, 5, T17); - SET(d, a, b, c, 6, 9, T18); - SET(c, d, a, b, 11, 14, T19); - SET(b, c, d, a, 0, 20, T20); - SET(a, b, c, d, 5, 5, T21); - SET(d, a, b, c, 10, 9, T22); - SET(c, d, a, b, 15, 14, T23); - SET(b, c, d, a, 4, 20, T24); - SET(a, b, c, d, 9, 5, T25); - SET(d, a, b, c, 14, 9, T26); - SET(c, d, a, b, 3, 14, T27); - SET(b, c, d, a, 8, 20, T28); - SET(a, b, c, d, 13, 5, T29); - SET(d, a, b, c, 2, 9, T30); - SET(c, d, a, b, 7, 14, T31); - SET(b, c, d, a, 12, 20, T32); -#undef SET - - /* Round 3. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + H(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 5, 4, T33); - SET(d, a, b, c, 8, 11, T34); - SET(c, d, a, b, 11, 16, T35); - SET(b, c, d, a, 14, 23, T36); - SET(a, b, c, d, 1, 4, T37); - SET(d, a, b, c, 4, 11, T38); - SET(c, d, a, b, 7, 16, T39); - SET(b, c, d, a, 10, 23, T40); - SET(a, b, c, d, 13, 4, T41); - SET(d, a, b, c, 0, 11, T42); - SET(c, d, a, b, 3, 16, T43); - SET(b, c, d, a, 6, 23, T44); - SET(a, b, c, d, 9, 4, T45); - SET(d, a, b, c, 12, 11, T46); - SET(c, d, a, b, 15, 16, T47); - SET(b, c, d, a, 2, 23, T48); -#undef SET - - /* Round 4. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ -#define I(x, y, z) ((y) ^ ((x) | ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + I(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 6, T49); - SET(d, a, b, c, 7, 10, T50); - SET(c, d, a, b, 14, 15, T51); - SET(b, c, d, a, 5, 21, T52); - SET(a, b, c, d, 12, 6, T53); - SET(d, a, b, c, 3, 10, T54); - SET(c, d, a, b, 10, 15, T55); - SET(b, c, d, a, 1, 21, T56); - SET(a, b, c, d, 8, 6, T57); - SET(d, a, b, c, 15, 10, T58); - SET(c, d, a, b, 6, 15, T59); - SET(b, c, d, a, 13, 21, T60); - SET(a, b, c, d, 4, 6, T61); - SET(d, a, b, c, 11, 10, T62); - SET(c, d, a, b, 2, 15, T63); - SET(b, c, d, a, 9, 21, T64); -#undef SET - - /* Then perform the following additions. (That is increment each - of the four registers by the value it had before this block - was started.) */ - pms->abcd[0] += a; - pms->abcd[1] += b; - pms->abcd[2] += c; - pms->abcd[3] += d; -} - -void -md5_init(md5_state_t *pms) -{ - pms->count[0] = pms->count[1] = 0; - pms->abcd[0] = 0x67452301; - pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; - pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; - pms->abcd[3] = 0x10325476; -} - -void -md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) -{ - const md5_byte_t *p = data; - int left = nbytes; - int offset = (pms->count[0] >> 3) & 63; - md5_word_t nbits = (md5_word_t)(nbytes << 3); - - if (nbytes <= 0) - return; - - /* Update the message length. */ - pms->count[1] += nbytes >> 29; - pms->count[0] += nbits; - if (pms->count[0] < nbits) - pms->count[1]++; - - /* Process an initial partial block. */ - if (offset) { - int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); - - memcpy(pms->buf + offset, p, copy); - if (offset + copy < 64) - return; - p += copy; - left -= copy; - md5_process(pms, pms->buf); - } - - /* Process full blocks. */ - for (; left >= 64; p += 64, left -= 64) - md5_process(pms, p); - - /* Process a final partial block. */ - if (left) - memcpy(pms->buf, p, left); -} - -void -md5_finish(md5_state_t *pms, md5_byte_t digest[16]) -{ - static const md5_byte_t pad[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - md5_byte_t data[8]; - int i; - - /* Save the length before padding. */ - for (i = 0; i < 8; ++i) - data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); - /* Pad to 56 bytes mod 64. */ - md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); - /* Append the length. */ - md5_append(pms, data, 8); - for (i = 0; i < 16; ++i) - digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); -} diff --git a/src/texsourc/libmd5/md5.h b/src/texsourc/libmd5/md5.h deleted file mode 100644 index 698c995..0000000 --- a/src/texsourc/libmd5/md5.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.h is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Removed support for non-ANSI compilers; removed - references to Ghostscript; clarified derivation from RFC 1321; - now handles byte order either statically or dynamically. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); - added conditionalization for C++ compilation from Martin - Purschke . - 1999-05-03 lpd Original version. - */ - -#ifndef md5_INCLUDED -# define md5_INCLUDED - -/* - * This package supports both compile-time and run-time determination of CPU - * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be - * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is - * defined as non-zero, the code will be compiled to run only on big-endian - * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to - * run on either big- or little-endian CPUs, but will run slightly less - * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. - */ - -typedef unsigned char md5_byte_t; /* 8-bit byte */ -typedef unsigned int md5_word_t; /* 32-bit word */ - -/* Define the state of the MD5 Algorithm. */ -typedef struct md5_state_s { - md5_word_t count[2]; /* message length in bits, lsw first */ - md5_word_t abcd[4]; /* digest buffer */ - md5_byte_t buf[64]; /* accumulate block */ -} md5_state_t; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Initialize the algorithm. */ -void md5_init(md5_state_t *pms); - -/* Append a string to the message. */ -void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); - -/* Finish the message and return the digest. */ -void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); - -#ifdef __cplusplus -} /* end extern "C" */ -#endif - -#endif /* md5_INCLUDED */ diff --git a/src/texsourc/libmd5/md5main.c b/src/texsourc/libmd5/md5main.c deleted file mode 100644 index 625a619..0000000 --- a/src/texsourc/libmd5/md5main.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - Copyright (C) 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5main.c,v 1.1 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.c is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Splits off main program into a separate file, md5main.c. - */ - -#include "md5.h" -#include -#include -#include - -/* - * This file builds an executable that performs various functions related - * to the MD5 library. Typical compilation: - * gcc -o md5main -lm md5main.c md5.c - */ -static const char *const usage = "\ -Usage:\n\ - md5main --test # run the self-test (A.5 of RFC 1321)\n\ - md5main --t-values # print the T values for the library\n\ - md5main --version # print the version of the package\n\ -"; -static const char *const version = "2002-04-13"; - -/* Run the self-test. */ -static int -do_test(void) -{ - static const char *const test[7*2] = { - "", "d41d8cd98f00b204e9800998ecf8427e", - "a", "0cc175b9c0f1b6a831c399e269772661", - "abc", "900150983cd24fb0d6963f7d28e17f72", - "message digest", "f96b697d7cb7938d525a2f31aaf161d0", - "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "d174ab98d277d9f5a5611c2c9f419d9f", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a" - }; - int i; - int status = 0; - - for (i = 0; i < 7*2; i += 2) { - md5_state_t state; - md5_byte_t digest[16]; - char hex_output[16*2 + 1]; - int di; - - md5_init(&state); - md5_append(&state, (const md5_byte_t *)test[i], strlen(test[i])); - md5_finish(&state, digest); - for (di = 0; di < 16; ++di) - sprintf(hex_output + di * 2, "%02x", digest[di]); - if (strcmp(hex_output, test[i + 1])) { - printf("MD5 (\"%s\") = ", test[i]); - puts(hex_output); - printf("**** ERROR, should be: %s\n", test[i + 1]); - status = 1; - } - } - if (status == 0) - puts("md5 self-test completed successfully."); - return status; -} - -/* Print the T values. */ -static int -do_t_values(void) -{ - int i; - for (i = 1; i <= 64; ++i) { - unsigned long v = (unsigned long)(4294967296.0 * fabs(sin((double)i))); - - /* - * The following nonsense is only to avoid compiler warnings about - * "integer constant is unsigned in ANSI C, signed with -traditional". - */ - if (v >> 31) { - printf("#define T%d /* 0x%08lx */ (T_MASK ^ 0x%08lx)\n", i, - v, (unsigned long)(unsigned int)(~v)); - } else { - printf("#define T%d 0x%08lx\n", i, v); - } - } - return 0; -} - -/* Main program */ -int -main(int argc, char *argv[]) -{ - if (argc == 2) { - if (!strcmp(argv[1], "--test")) - return do_test(); - if (!strcmp(argv[1], "--t-values")) - return do_t_values(); - if (!strcmp(argv[1], "--version")) { - puts(version); - return 0; - } - } - puts(usage); - return 0; -} diff --git a/src/texsourc/local.c b/src/texsourc/local.c index 1cf3c1a..8da8af4 100644 --- a/src/texsourc/local.c +++ b/src/texsourc/local.c @@ -1,3386 +1,3386 @@ -/* Copyright 2007 TeX Users Group - Copyright 2014 Clerk Ma - - 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#define EXTERN extern - -#include "yandytex.h" - -#define USEOUREALLOC -#define USEMEMSET - -#ifdef USEOUREALLOC - #define REALLOC ourrealloc -#else - #define REALLOC realloc -#endif - -#if defined (__ANDROID__) - #define malloc_usable_size dlmalloc_usable_size -#elif defined (__APPLE__) - #define malloc_usable_size malloc_size -#endif - -#if defined (__clang__) -const char * compiler = "Clang/LLVM"; -#elif defined (__GNUC__) || defined(__GNUG__) -const char * compiler = "GCC"; -#elif defined (_MSC_VER) -const char * compiler = "MSVC"; -#endif - -#if defined (_WIN64) -const char * dist = "Win64"; -#elif defined (_WIN32) -const char * dist = "Win32"; -#elif defined (__ANDROID__) -const char * dist = "Android"; -#elif defined (__APPLE__) -const char * dist = "Darwin"; -#elif defined (__gnu_linux__) -const char * dist = "Linux"; -#else -const char * dist = "Unknown"; -#endif - -const char * compiletime = __TIME__; -const char * compiledate = __DATE__; -const char * yandyversion = "2.3.0"; -const char * application = "Y&Y TeX"; -const char * banner = "This is TeX, Version 3.14159265"; - -void print_banner (void) -{ - char dist_ver[256]; - memset(dist_ver, 0, sizeof(dist_ver)); - sprintf(dist_ver, "%s (%s %s/%s)", banner, application, yandyversion, dist); - prints(dist_ver); -} - -clock_t start_time, main_time, finish_time; - -char * dvi_directory = ""; -char * log_directory = ""; -char * aux_directory = ""; -char * fmt_directory = ""; -char * pdf_directory = ""; - -char log_line[256]; - -boolean mem_spec_flag = false; -boolean format_spec = false; -boolean reorder_arg_flag = true; /* put command line flags/arguments first */ - -/* Mapping from Windows ANSI to DOS code page 850 96/Jan/20 */ - -unsigned char wintodos[128] = -{ - 0, 0, 0, 159, 0, 0, 0, 0, - 94, 0, 0, 0, 0, 0, 0, 0, - 0, 96, 39, 0, 0, 7, 0, 0, - 126, 0, 0, 0, 0, 0, 0, 0, - 32, 173, 189, 156, 207, 190, 221, 21, - 0, 184, 166, 174, 170, 45, 169, 0, - 248, 241, 253, 252, 0, 230, 20, 250, - 0, 251, 167, 175, 172, 171, 243, 168, - 183, 181, 182, 199, 142, 143, 146, 128, - 212, 144, 210, 211, 222, 214, 215, 216, - 209, 165, 227, 224, 226, 229, 153, 158, - 157, 235, 233, 234, 154, 237, 232, 225, - 133, 160, 131, 198, 132, 134, 145, 135, - 138, 130, 136, 137, 141, 161, 140, 139, - 208, 164, 149, 162, 147, 228, 148, 246, - 155, 151, 163, 150, 129, 236, 231, 152 -}; - -void show_usage (void) -{ - printf("\n" - "Useage: yandytex [OPTION]... [+format_file] [tex_file]\n\n" - "--help -? show this usage summary\n" - "--initex -i start up as initex (create format file)\n" - "--verbose -v be verbose (show implementation version number)\n" - "--ascii -n do not allow `non ASCII' characters in input files\n" - " (complain instead)\n" - "--showhex -w do not show `non ASCII' characters in hexadecimal\n" - " (show as is)\n" - "--nodos -d do not allow DOS style file names - i.e. do not convert\n" - " \\ to /\n" - "--nomac -r do not allow Mac style termination - i.e. do not convert\n" - " \\r to \\n\n" - "--patterns -p allow use of \\patterns after loading format (initex only)\n" - "--knuthify -K disable all extensions to basic TeX\n" - "--main-mem -m initial main memory size in kilo words (initex only)\n" - "--hyph-size -e hyphenation exception dictionary size (initex only)\n" - "--trie-size -h hyphenation pattern trie size (initex only)\n" - "--xchr-file -x use `non ASCII' character mapping (xchr[]) defined in file\n" - "--key-file -k use `key replacement' defined in file\n" - "--dvi-dir -o write DVI file in specified directory (default '.')\n" - "--log-dir -l write LOG file in specified directory (default '.')\n" - "--aux-dir -a write AUX file in specified directory (default '.')\n"); - uexit(EXIT_FAILURE); -} - -// Sep 27 1990 => 1990 Sep 27 -// 0123456789 0123456789 -void scivilize (char * date) -{ - int k; - char pyear[6]; - - strcpy(pyear, date + 7); - - for (k = 5; k >= 0; k--) - date[k + 5] = date[k]; - - for (k = 0; k < 4; k++) - date[k] = pyear[k]; - - date[4] = ' '; - - if (date[9] == ' ') - date[9] = '0'; -} - -// Thu Sep 27 06:26:35 1990 => 1990 Sep 27 06:26:35 -void lcivilize (char * date) -{ - int k; - char pyear[6]; - - strcpy(pyear, date + 20); - - for (k = 18; k >= 0; k--) - date[k + 1] = date[k]; - - date[20] = '\0'; - - for (k = 0; k < 4; k++) - date[k] = pyear[k]; - - date[4] = ' '; -} - -void stamp_it (char * s) -{ - char date[11 + 1]; - - strcpy(date, compiledate); - scivilize(date); - sprintf(s, "%s %s (compiled time: %s %s with %s)", - application, yandyversion, date, compiletime, compiler); - s += strlen(s); -} - -#define MAXCHRS 256 -#define NOTDEF 127 - -void read_xchr_sub (FILE * xchr_input) -{ - char buffer[file_name_size]; - int k, from, to, count = 0; - char * s; - - memset(xchr, NOTDEF, MAXCHRS); - memset(xord, NOTDEF, MAXCHRS); - -#ifdef ALLOCATEBUFFER - while (fgets(buffer, current_buf_size, xchr_input) != NULL) -#else - while (fgets(buffer, sizeof(buffer), xchr_input) != NULL) -#endif - { - if (*buffer == '%' || *buffer == ';' || *buffer == '\n') - continue; - - from = (int) strtol (buffer, &s, 0); - to = (int) strtol (s, NULL, 0); - - if (from >= 0 && from < MAXCHRS && to >= 0 && to < MAXCHRS) - { - if (xchr[from] == NOTDEF) - xchr[from] = (unsigned char) to; - else - printf("NOTE: %s collision: %d => %d, %d\n", "xchr", from, xchr[from], to); - - if (xord[to] == NOTDEF) - xord[to] = (unsigned char) from; - else - printf("NOTE: %s collision: %d => %d, %d\n", "xord", to, xord[to], from); - - count++; - } - } - - for (k = 0; k < MAXCHRS; k++) - { - if (xchr[k] == NOTDEF) /* if it has not been filled */ - { - if (xord[k] == NOTDEF) /* see whether used already */ - { - xchr[k] = (unsigned char) k; /* no, so make identity */ - xord[k] = (unsigned char) k; /* no, so make identity */ - } - } - } - - xchr[NOTDEF] = NOTDEF; /* fixed point of mapping */ - - if (trace_flag) - { - printf("Read %d xchr[] pairs:\n", count); - - for (k = 0; k < MAXCHRS; k++) - { - if (xchr[k] != NOTDEF) - printf("%d => %d\n", k, xchr[k]); - } - } -} - -char * replacement[MAXCHRS]; /* pointers to replacement strings */ - -void read_repl_sub (FILE * repl_input) -{ - int k, n, m, chrs; - char buffer[file_name_size]; - char charname[128]; - int charnum[10]; - char * s, * t; - - memset(replacement, 0, MAXCHRS * sizeof(replacement[0])); - - while (fgets(buffer, file_name_size, repl_input) != NULL) - { - if (*buffer == '%' || *buffer == ';' || *buffer == '\n') - continue; - - if ((m = sscanf(buffer, "%d%n %s", &chrs, &n, (char *)&charname)) == 0) - continue; - else if (m == 2) - { - if (*charname == '"') /* deal with quoted string "..." */ - { - s = buffer + n; - t = charname; - - while (*s != '"' && *s != '\0') - s++; /* step up to " */ - - if (*s++ == '\0') - continue; /* sanity check */ - - while (*s != '\0') - { - if (*s == '"') - { - s++; /* is it "" perhaps ? */ - - if (*s != '"') - break; /* no, end of string */ - } - - *t++ = *s++; /* copy over */ - } - - *t = '\0'; /* and terminate */ - } - - if (chrs >= 0 && chrs < MAXCHRS) - replacement[chrs] = xstrdup(charname); - } -/* presently the following can never get triggered */ -/* which is good, because it is perhaps not right ... */ - else if ((m = sscanf (buffer, "%d %d %d %d %d %d %d %d %d %d %d", - &chrs, charnum, charnum+1, charnum+2, charnum+3, charnum+4, - charnum+5, charnum+6, charnum+7, charnum+8, charnum+9)) > 1) { -/* for (k = 0; k < n-1; k++) charname[k] = (char) charnum; */ - for (k = 0; k < n-1; k++) charname[k] = (char) charnum[k]; - charname[m] = '\0'; - if (chrs >= 0 && chrs < MAXCHRS) - replacement[chrs] = xstrdup(charname); - } - else - printf("ERROR: don't understand %s", buffer); - } - - if (trace_flag) - { - puts("Key replacement table"); - - for (k = 0; k < MAXCHRS; k++) - { - if (replacement[k] != NULL) - printf("%d\t%s\n", k, replacement[k]); - } - } -} - -/* Following used both to read xchr[] file and key replacement file */ -/* the flag is 0 for -x=... and the flag is 1 for -k=... */ -int read_xchr_file (char *filename, int flag, char *argv[]) -{ - FILE *xchr_input; - char infile[file_name_size]; - char *s; - - if (filename == NULL) - return -1; - - if (trace_flag) - printf("Reading xchr/repl %s\n", filename); - - /* first try using file as specified */ - strcpy(infile, filename); - - if (trace_flag) - printf("Trying %s\n", infile); - - xchr_input = fopen (infile, "r"); - - if (xchr_input == NULL) - { - if (strrchr(infile, '.') == NULL) - { - if (flag == 0) - strcat(infile, ".map"); - else - strcat(infile, ".key"); - - if (trace_flag) - printf("Trying %s\n", infile); - - xchr_input = fopen(infile, "r"); - } - } - - if (xchr_input == NULL) - { - strcpy(infile, argv[0]); /* try TeX program path */ - - if ((s = strrchr (infile, '\\')) != NULL) - *(s+1) = '\0'; - else if ((s = strrchr (infile, '/')) != NULL) - *(s+1) = '\0'; - else if ((s = strrchr (infile, ':')) != NULL) - *(s+1) = '\0'; - - strcat (infile, filename); - - if (trace_flag) - printf("Trying %s\n", infile); - - xchr_input = fopen (infile, "r"); - - if (xchr_input == NULL) - { - if (strchr(infile, '.') == NULL) - { - if (flag == 0) - strcat(infile, ".map"); - else - strcat(infile, ".key"); - - if (trace_flag) - printf("Trying %s\n", infile); - - xchr_input = fopen (infile, "r"); - } - } - } - - if (xchr_input == NULL) - { - strcpy(infile, argv[0]); /* try TeX program path */ - - if ((s = strrchr (infile, '\\')) != NULL) - *(s + 1) = '\0'; - else if ((s = strrchr (infile, '/')) != NULL) - *(s + 1) = '\0'; - else if ((s = strrchr (infile, ':')) != NULL) - *(s + 1) = '\0'; - - strcat(infile, "keyboard\\"); - strcat(infile, filename); - - if (trace_flag) - printf("Trying %s\n", infile); - - xchr_input = fopen (infile, "r"); - - if (xchr_input == NULL) - { - if (strchr(infile, '.') == NULL) - { - if (flag == 0) - strcat(infile, ".map"); - else - strcat(infile, ".key"); - - if (trace_flag) - printf("Trying %s\n", infile); - - xchr_input = fopen (infile, "r"); - } - } - } - - /* Note: can't look in TeX source file dir, since that is not known yet */ - if (xchr_input == NULL) - { - printf("ERROR: Sorry, cannot find %s file %s", - flag ? " xchr[]" : "key mapping", filename); - perrormod (filename); - return 0; - } - - if (flag == 0) - read_xchr_sub(xchr_input); - else - read_repl_sub(xchr_input); - - (void) fclose(xchr_input); - - return 1; -} - -/* need to also set `key_replace' here based on command line */ -/* need to also allocate `buffercopy' here and free at end */ -/* need to call `readreplace' in appropriate place */ - -#define MAXSPLITS 3 - -/* ad hoc default minimum growth in memory realloc is 62% */ -/* golden ratio (1 + \sqrt{5}) / 2 = 1.618033989... */ -int percent_grow = 62; /* default minimum growth in memory realloc is 62% */ -int total_allocated = 0; /* total memory allocated so far */ -int ini_max_address = 0; /* maximum address when starting */ -int max_address = 0; /* maximum address seen in allocated memory */ - - -void show_maximums (FILE * output) -{ - sprintf(log_line, "Max allocated %d --- max address %d\n", total_allocated, max_address); - fputs(log_line, output); -} - -/* our own version of realloc --- avoid supposed MicroSoft version bug */ -/* also tries _expand first, which can avoid address growth ... */ - -#ifdef USEOUREALLOC -void * ourrealloc (void * old, size_t new_size) -{ - void * mnew; - size_t old_size, overlap; - - /* round up to nearest multiple of four bytes */ - /* avoid unlikely alignment */ - if ((new_size % 4) != 0) - new_size = ((new_size / 4) + 1) * 4; - - if (old == NULL) - return malloc (new_size); /* no old block - use malloc */ - -#ifdef _WIN32 - old_size = _msize (old); -#else - old_size = malloc_usable_size (old); -#endif - - if (old_size >= new_size && old_size < new_size + 4) - return old; - -#ifdef _WIN32 - mnew = _expand (old, new_size); /* first try and expand in place MSVC */ -#else - mnew = realloc (old, new_size); -#endif - - if (mnew != NULL) - { - if (trace_flag) - printf("EXPANDED! %p (%ld) == %p (%ld)\n", - mnew, new_size, old, old_size); - - return mnew; - } - - /* do this if you want to call the real realloc next - */ - mnew = realloc (old, new_size); - - if (mnew != NULL) - return mnew; - - /* we are screwed typically if we ever drop through here - no more space */ - mnew = malloc (new_size); /* otherwise find new space */ - - if (mnew == NULL) - return mnew; /* if unable to allocate */ - - if (old_size < new_size) - overlap = old_size; - else - overlap = new_size; - - memcpy (mnew, old, overlap); /* copy old data to new area */ - free(old); /* free the old area */ - - return mnew; -} -#endif - -void memory_error (const char * s, int n) -{ - if (log_opened) - { - fprintf(log_file, "\n! Unable to allocate %d bytes for %s\n", n, s); - show_maximums(log_file); - } - - printf("\n! Unable to allocate %d bytes for %s\n", n, s); - show_maximums(stderr); -} - -void trace_memory (const char * s, int n) -{ - printf("Allocating %d bytes for %s\n", n, s); -} - -void update_statistics (long address, int size, int old_size) -{ - if (address + size > max_address) - max_address = address + size; - - total_allocated = total_allocated + size - old_size; -} - -void probe_memory (void) -{ - char * s = (char *) malloc(sizeof(void *)); - free(s); - update_statistics ((long) s, 0, 0); -} - -void probe_show (void) -{ - probe_memory(); - show_maximums(stdout); -} - -size_t roundup (size_t n) -{ - if ((n % sizeof(void *)) == 0) - return n; - else - return ((n / sizeof(void *)) + 1) * sizeof(void *); -} - -#ifdef ALLOCATETRIES -/* returns -1 if it fails */ - -int allocate_tries (int trie_max) -{ - int n, nl, no, nc; - - if (trie_max > 1000000) - trie_max = 1000000; - - nl = (trie_max + 1) * sizeof(halfword); - no = (trie_max + 1) * sizeof(halfword); - nc = (trie_max + 1) * sizeof(quarterword); - n = nl + no + nc; - - if (trace_flag) - trace_memory("hyphen trie", n); - - trie_trl = (halfword *) malloc(roundup(nl)); - trie_tro = (halfword *) malloc(roundup(no)); - trie_trc = (quarterword *) malloc(roundup(nc)); - - if (trie_trl == NULL || trie_tro == NULL || trie_trc == NULL) - { - memory_error("hyphen trie", n); - return -1; - } - - if (trace_flag) - printf("Addresses trie_trl %p trie_tro %p trie_trc %p\n", trie_trl, trie_tro, trie_trc); - - update_statistics((long) trie_trl, nl, 0); - update_statistics((long) trie_tro, no, 0); - update_statistics((long) trie_trc, nc, 0); - - trie_size = trie_max; - - if (trace_flag) - probe_show(); - - return 0; // success -} -#endif - -#ifdef ALLOCATEHYPHEN -int current_prime = 0; /* remember in case reallocated later */ - -/* we don't return an address here, since TWO memory regions allocated */ -/* plus, we don't really reallocate, we FLUSH the old information totally */ -/* returns -1 if it fails */ - -int realloc_hyphen (int hyphen_prime) -{ - int n, nw, nl; - - if (!prime(hyphen_prime)) - { - printf("ERROR: non-prime hyphen exception number (%d)\n", hyphen_prime); - return -1; - } - -/* need not/cannot preserve old contents when hyphen prime is changed */ -/* if (hyph_list != NULL) free(hyph_list); */ -/* if (hyph_word != NULL) free(hyph_word); */ - nw = (hyphen_prime + 1) * sizeof(str_number); - nl = (hyphen_prime + 1) * sizeof(halfword); - n = nw + nl; - - if (trace_flag) - trace_memory("hyphen exception", n); - - hyph_word = (str_number *) REALLOC (hyph_word, nw); - hyph_list = (halfword *) REALLOC (hyph_list, nl); - - if (hyph_word == NULL || hyph_list == NULL) - { - memory_error("hyphen exception", n); - return -1; - } - - if (trace_flag) - printf("Addresses hyph_word %p hyph_list %p\n", hyph_word, hyph_list); - -/* cannot preserve old contents when hyphen prime is changed */ -#ifdef USEMEMSET - memset(hyph_word, 0, (hyphen_prime + 1) * sizeof (hyph_word[0])); -#else - for (k = 0; k <= hyphen_prime; k++) - hyph_word[k]= 0; -#endif - -#ifdef USEMEMSET - memset(hyph_list, 0, (hyphen_prime + 1) * sizeof (hyph_list[0])); -#else - for (k = 0; k <= hyphen_prime; k++) - hyph_list[k]= 0; -#endif - - hyph_count = 0; - - if (current_prime != 0) - { - update_statistics((long) hyph_word, nw, (current_prime + 1) * sizeof(str_number)); - update_statistics((long) hyph_list, nl, (current_prime + 1) * sizeof(halfword)); - } - else - { - update_statistics((long) hyph_word, nw, 0); - update_statistics((long) hyph_list, nl, 0); - } - - current_prime = hyphen_prime; - - if (trace_flag) - probe_show(); - - return 0; // success -} -#endif - -int current_mem_size = 0; /* current total words in main mem allocated -1 */ - -/* this gets called from itex.c when it figures out what mem_top is */ -/* or gets called from here when in ini_TeX mode */ /* and nowhere else */ -/* initial allocation only, may get expanded later */ -/* NOTE: we DON't use ALLOCATEHIGH & ALLOCATELOW anymore */ -/* returns NULL if it fails */ - -#ifdef ALLOCATEMAIN -/* initial main memory alloc - mem_top */ -memory_word * allocate_main_memory (int size) -{ - int n; - - if (main_memory != NULL) - { - if (trace_flag) - puts("Reallocating initial memory allocation"); - } - - mem_top = mem_bot + size; - mem_max = mem_top; - mem_start = 0; /* bottom of memory allocated by system */ - mem_min = 0; /* bottom of area made available to TeX */ - n = (mem_max - mem_start + 1) * sizeof (memory_word); - - if (trace_flag) - trace_memory("main memory", n); - - main_memory = (memory_word *) REALLOC (main_memory, n); - - if (main_memory == NULL) - { - memory_error("initial main memory", n); - return NULL; - } - - if (trace_flag) - printf("Address main memory == %p\n", main_memory); - - mem = main_memory; - - if (mem_start != 0 && !is_initex) - mem = main_memory - mem_start; - - if (trace_flag) - printf("Offset address main memory == %p\n", mem); - - update_statistics((long) main_memory, n, (current_mem_size + 1) * sizeof (memory_word)); -/* current_mem_size = (mem_max - mem_start + 1); */ - current_mem_size = mem_max - mem_start; /* total number of words - 1 */ - - if (trace_flag) - probe_show(); - - return mem; -} -#endif - -#ifdef ALLOCATEMAIN -/* int firstallocation = 1; */ - -/* increase main memory allocation at low end and high end */ -/* called only from tex0.c *//* called with one of lo_size or hi_size == 0 */ -/* returns NULL if it fails */ - -memory_word * realloc_main (int lo_size, int hi_size) -{ - int k, min_size; - int new_size = 0; - int n = 0; - memory_word * new_memory = NULL; - - if (trace_flag) - printf("WARNING: Entering realloc_main lo %d hi %d\n", lo_size, hi_size); - - if (is_initex) - { - puts("ERROR: Cannot extent main memory in initex"); - - if (!knuth_flag) - puts("Please use `-m=...' on command line"); - - return NULL; - } - - if (trace_flag) - printf("Old Address %s == %p\n", "main memory", main_memory); - - /* if we REALLY run up to limit ! */ - if (current_mem_size + 1 == max_mem_size) - { - memory_error("main memory", (max_mem_size + 1) * sizeof(memory_word)); - return NULL; - } - -/* first allocation should expand *both* lo and hi */ - if (hi_size == 0 && mem_end == mem_max) - hi_size = lo_size; - - if (lo_size == 0 && mem_start == mem_min) - lo_size = hi_size; - -/* try and prevent excessive frequent reallocations */ -/* while avoiding over allocation by too much */ - min_size = current_mem_size / 100 * percent_grow; - - if (lo_size + hi_size < min_size) - { - if (lo_size > 0 && hi_size > 0) - { - lo_size = min_size / 2; - hi_size = min_size / 2; - } - else if (lo_size > 0) - lo_size = min_size; - else if (hi_size > 0) - hi_size = min_size; - } - - if (lo_size > 0 && lo_size < mem_top / 2) - lo_size = mem_top / 2; - - if (hi_size > 0 && hi_size < mem_top / 2) - hi_size = mem_top / 2; - - for (k = 0; k < MAXSPLITS; k++) - { - new_size = current_mem_size + lo_size + hi_size; - - if (new_size >= max_mem_size) /* bump against limit - ha ha ha */ - { - while (new_size >= max_mem_size) - { - lo_size = lo_size / 2; - hi_size = hi_size / 2; - new_size = current_mem_size + lo_size + hi_size; - } - } - - n = (new_size + 1) * sizeof (memory_word); - - if (trace_flag) - trace_memory("main memory", n); - - new_memory = (memory_word *) REALLOC (main_memory, n); - - if (new_memory != NULL) - break; /* did we get it ? */ - - if (current_mem_size == 0) - break; /* in case we ever use for initial */ - - lo_size = lo_size / 2; hi_size = hi_size / 2; - } - - if (new_memory == NULL) - { - memory_error("main memory", n); - return mem; - } - - if (trace_flag) - printf("New Address %s == %p\n", "main memory", new_memory); - - if (lo_size > 0) - { -/* shift everything upward to make space for new low area */ - if (trace_flag) - printf("memmove %p %p %ld \n", new_memory + lo_size, - new_memory, (current_mem_size + 1) * sizeof(memory_word)); - - memmove (new_memory + lo_size, new_memory, - (current_mem_size + 1) * sizeof(memory_word)); -/* could reduce words moved by (mem_max - mem_end) */ - } - - main_memory = new_memory; /* remember for free later */ - - if (lo_size > 0) - mem_start = mem_start - lo_size; /* update lower limit */ - - if (hi_size > 0) - mem_max = mem_max + hi_size; /* update upper limit */ - - update_statistics ((long) main_memory, n, - (current_mem_size + 1) * sizeof (memory_word)); - current_mem_size = new_size; - - if (current_mem_size != mem_max - mem_start) - puts("ERROR: Impossible Memory Error"); - - if (mem_start != 0) - mem = main_memory - mem_start; - else - mem = main_memory; - - if (trace_flag) - probe_show(); - - return mem; -} -#endif - -#ifdef ALLOCATEFONT -int current_font_mem_size = 0; - -memory_word * realloc_font_info (int size) -{ - memory_word * new_font_info = NULL; - int k, min_size; - int new_size = 0; - int n = 0; - - if (trace_flag) - printf("Old Address %s == %p\n", "font_info", font_info); - - /* during initial allocation, font_info == NULL - realloc acts like malloc */ - /* during initial allocation current_font_mem_size == 0 */ - if (current_font_mem_size == font_mem_size) /* if we REALLY run up to limit */ - { - /* memory_error("font", (font_mem_size + 1) * sizeof(memory_word)); */ - return font_info; /* pass it back to TeX 99/Fabe/4 */ - } - /* try and prevent excessive frequent reallocations */ - /* while avoiding over allocation by too much */ - /* min_size = current_font_mem_size / 2; */ - min_size = current_font_mem_size / 100 * percent_grow; - - if (size < min_size) - size = min_size; - - if (size < initial_font_mem_size) - size = initial_font_mem_size; - - for (k=0; k < MAXSPLITS; k++) - { - new_size = current_font_mem_size + size; - - if (new_size > font_mem_size) - new_size = font_mem_size; /* bump against limit */ - -/* important + 1 since fmemoryword font_info[font_mem_size + 1] original */ - n = (new_size + 1) * sizeof (memory_word); - - if (trace_flag) - trace_memory("font_info", n); - - new_font_info = (memory_word *) REALLOC (font_info, n); - - if (new_font_info != NULL) - break; /* did we get it ? */ - - if (current_font_mem_size == 0) - break; /* initial allocation must work */ - - size = size / 2; - } - - if (new_font_info == NULL) - { - memory_error("font", n); - return font_info; /* try and continue !!! */ - } - - font_info = new_font_info; - - if (trace_flag) - printf("New Address %s == %p\n", "font_info", font_info); - - update_statistics ((long) font_info, n, current_font_mem_size * sizeof(memory_word)); - current_font_mem_size = new_size; - - if (trace_flag) - probe_show(); - - return font_info; -} -#endif - -#ifdef ALLOCATESTRING -int current_pool_size = 0; - -packed_ASCII_code * realloc_str_pool (int size) -{ - int k, min_size; - int new_size = 0; - int n = 0; - packed_ASCII_code * new_str_pool = NULL; - - if (trace_flag) - printf("Old Address %s == %p\n", "string pool", str_pool); - - if (current_pool_size == pool_size) - { -/* memory_error ("string pool", (pool_size + 1) * sizeof(packed_ASCII_code)); */ -/* exit (1); */ - return str_pool; /* pass it back to TeX 99/Fabe/4 */ - } - - min_size = current_pool_size / 100 * percent_grow; - - if (size < min_size) - size = min_size; - - if (size < initial_pool_size) - size = initial_pool_size; - - for (k = 0; k < MAXSPLITS; k++) - { - new_size = current_pool_size + size; - - if (new_size > pool_size) - new_size = pool_size; -/* important + 1 since packed_ASCII_code str_pool[pool_size + 1]; in original */ - n = (new_size + 1) * sizeof (packed_ASCII_code); - - if (trace_flag) - trace_memory("str_pool", n); - - new_str_pool = (packed_ASCII_code *) REALLOC (str_pool, n); /* 95/Sep/24 */ - - if (new_str_pool != NULL) - break; /* did we get it ? */ - - if (current_pool_size == 0) - break; /* initial allocation must work */ - - size = size / 2; /* else can retry smaller */ - } - - if (new_str_pool == NULL) - { - memory_error("string pool", n); - return str_pool; /* try and continue !!! */ - } - - str_pool = new_str_pool; - update_statistics ((long) str_pool, n, current_pool_size); - current_pool_size = new_size; - - if (trace_flag) - printf("New Address %s == %p\n", "string pool", str_pool); - - if (trace_flag) - probe_show(); - - return str_pool; -} -#endif - -#ifdef ALLOCATESTRING -int current_max_strings = 0; - -pool_pointer * realloc_str_start (int size) -{ - int k, min_size; - int n = 0; - int new_size = 0; - pool_pointer * new_str_start = NULL; - - if (trace_flag) - printf("Old Address %s == %p\n", "string start", str_start); - - if (current_max_strings == max_strings) - { -/* memory_error ("string pointer", (max_strings + 1) * sizeof(pool_pointer)); */ -/* exit (1); */ - return str_start; /* pass it back to TeX 99/Fabe/4 */ - } - - min_size = current_max_strings / 100 * percent_grow; - - if (size < min_size) - size = min_size; - - if (size < initial_max_strings) - size = initial_max_strings; - - for (k = 0; k < MAXSPLITS; k++) - { - new_size = current_max_strings + size; - - if (new_size > max_strings) - new_size = max_strings; -/* important + 1 since str_start[maxstring + 1] originally */ - n = (new_size + 1) * sizeof (pool_pointer); - - if (trace_flag) - trace_memory("str_start", n); - - new_str_start = (pool_pointer *) REALLOC (str_start, n); - - if (new_str_start != NULL) - break; /* did we get it ? */ - - if (current_max_strings == 0) - break; /* initial allocation must work */ - - size = size / 2; /* otherwise can try smaller */ - } - - if (new_str_start == NULL) - { - memory_error("string pointer", n); - return str_start; /* try and continue */ - } - - str_start = new_str_start; - update_statistics((long) str_start, n, current_max_strings * sizeof (pool_pointer)); - current_max_strings = new_size; - - if (trace_flag) - printf("New Address %s == %p\n", "string start", str_start); - - if (trace_flag) - probe_show(); - - return str_start; -} -#endif - -#ifdef ALLOCATEINI -/* returns -1 if it fails */ -/* size == trie_size */ -int allocate_ini (int size) -{ - int n, nl, no, nc, nr, nh, nt; - - nh = (size + 1) * sizeof(trie_pointer); - nr = (size + 1) * sizeof(trie_pointer); - nl = (size + 1) * sizeof(trie_pointer); - no = (size + 1) * sizeof(trie_op_code); - nc = (size + 1) * sizeof(packed_ASCII_code); - nt = (size + 1) * sizeof(char); - n = nl + no + nc + nr + nh + nt; - - if (trace_flag) - trace_memory ("initex hyphen trie", n); - - trie_l = (trie_pointer *) malloc (roundup(nl)); - trie_o = (trie_op_code *) malloc (roundup(no)); - trie_c = (packed_ASCII_code *) malloc (roundup(nc)); - trie_r = (trie_pointer *) malloc (roundup(nr)); - trie_hash = (trie_pointer *) malloc (roundup(nh)); - trie_taken = (char *) malloc (roundup(nt)); - - if (trie_c == NULL || trie_o == NULL || trie_l == NULL || trie_r == NULL || - trie_hash == NULL || trie_taken == NULL) - { - memory_error("initex hyphen trie", n); - return -1; - } - - if (trace_flag) - { - printf("Addresses: trie_l %p trie_o %p trie_c %p\n", trie_l, trie_o, trie_c); - printf("Addresses: trie_r %p trie_hash %p trie_taken %p\n", trie_r, trie_hash, trie_taken); - } - - update_statistics ((long) trie_l, nl, 0); - update_statistics ((long) trie_o, no, 0); - update_statistics ((long) trie_c, nc, 0); - update_statistics ((long) trie_r, nr, 0); - update_statistics ((long) trie_hash, nh, 0); - update_statistics ((long) trie_taken, nt, 0); - - if (trace_flag) - probe_show(); - - return 0; // success -} -#endif - -#ifdef ALLOCATESAVESTACK -int current_save_size = 0; - -memory_word * realloc_save_stack (int size) -{ - int k, min_size; - int n = 0, new_size = 0; - memory_word * new_save_stack = NULL; - - if (trace_flag) - printf("Old Address %s == %p\n", "save stack", save_stack); - - if (current_save_size == save_size) - { - return save_stack; /* let TeX handle the error */ - } - - min_size = current_save_size / 100 * percent_grow; - - if (size < min_size) - size = min_size; - - if (size < initial_save_size) - size = initial_save_size; - - for (k = 0; k < MAXSPLITS; k++) - { - new_size = current_save_size + size; - - if (new_size > save_size) - new_size = save_size; - - n = (new_size + 1) * sizeof (memory_word); - - if (trace_flag) - trace_memory("save_stack", n); - - new_save_stack = (memory_word *) REALLOC (save_stack, n); - - if (new_save_stack != NULL) - break; /* did we get it ? */ - - if (current_save_size == 0) - break; /* initial allocation must work */ - - size = size / 2; /* else can retry smaller */ - } - - if (new_save_stack == NULL) - { - memory_error("save_stack", n); - return save_stack; /* try and continue !!! */ - } - - save_stack = new_save_stack; - update_statistics ((long) save_stack, n, current_save_size); - current_save_size = new_size; - - if (trace_flag) - { - printf("Current %s %d\n", "save_size", current_save_size); - printf("New Address %s == %p\n", "save stack", save_stack); - } - - if (trace_flag) - probe_show(); - - return save_stack; -} -#endif - -#ifdef ALLOCATEINPUTSTACK -int current_stack_size = 0; /* input stack size */ - -in_state_record * realloc_input_stack (int size) -{ - int k, min_size; - int n = 0, new_size = 0; - in_state_record * new_input_stack = NULL; - - if (trace_flag) - printf("Old Address %s == %p\n", "input stack", input_stack); - - if (current_stack_size == stack_size) - { - return input_stack; - } - - min_size = current_stack_size / 100 * percent_grow; - - if (size < min_size) - size = min_size; - - if (size < initial_stack_size) - size = initial_stack_size; - - for (k = 0; k < MAXSPLITS; k++) - { - new_size = current_stack_size + size; - - if (new_size > stack_size) - new_size = stack_size; - - n = (new_size + 1) * sizeof(in_state_record); - - if (trace_flag) - trace_memory("input_stack", n); - - new_input_stack = (in_state_record *) REALLOC (input_stack, n); - - if (new_input_stack != NULL) - break; /* did we get it ? */ - - if (current_stack_size == 0) - break; /* initial allocation must work */ - - size = size / 2; /* else can retry smaller */ - } - - if (new_input_stack == NULL) - { - memory_error("input stack", n); - return input_stack; /* try and continue !!! */ - } - - input_stack = new_input_stack; - update_statistics ((long) input_stack, n, current_stack_size); - current_stack_size = new_size; - - if (trace_flag) - { - printf("Current %s %d\n", "stack_size", current_stack_size); - printf("New Address %s == %p\n", "input stack", input_stack); - } - - if (trace_flag) - probe_show(); - - return input_stack; -} -#endif - -#ifdef ALLOCATENESTSTACK -int current_nest_size = 0; /* current nest size */ - -list_state_record * realloc_nest_stack (int size) -{ - int k, min_size; - int n = 0, new_size = 0; - list_state_record * new_nest = NULL; - - if (trace_flag) - printf("Old Address %s == %p\n", "nest stack", nest); - - if (current_nest_size == nest_size) - { - return nest; - } - - min_size = current_nest_size / 100 * percent_grow; - - if (size < min_size) - size = min_size; - - if (size < initial_nest_size) - size = initial_nest_size; - - for (k = 0; k < MAXSPLITS; k++) - { - new_size = current_nest_size + size; - - if (new_size > nest_size) - new_size = nest_size; - - n = (new_size + 1) * sizeof (list_state_record); - - if (trace_flag) - trace_memory("nest stack", n); - - new_nest = (list_state_record *) REALLOC (nest, n); - - if (new_nest != NULL) - break; /* did we get it ? */ - - if (current_nest_size == 0) - break; /* initial allocation must work */ - - size = size / 2; /* else can retry smaller */ - } - - if (new_nest == NULL) - { - memory_error("nest stack", n); - return nest; /* try and continue !!! */ - } - - nest = new_nest; - update_statistics ((long) nest, n, current_nest_size); - current_nest_size = new_size; - - if (trace_flag) - { - printf("Current %s %d\n", "nest_size", current_nest_size); - printf("New Address %s == %p\n", "nest stack", nest); - } - - if (trace_flag) - probe_show(); - - return nest; -} -#endif - -#ifdef ALLOCATEPARAMSTACK -int current_param_size = 0; - -halfword *realloc_param_stack (int size) -{ - int k, min_size; - int n = 0, new_size = 0; - halfword * new_param = NULL; - - if (trace_flag) - printf("Old Address %s == %p\n", "param stack", param_stack); - - if (current_param_size == param_size) - { - return param_stack; - } - - min_size = current_param_size / 100 * percent_grow; - - if (size < min_size) - size = min_size; - - if (size < initial_param_size) - size = initial_param_size; - - for (k = 0; k < MAXSPLITS; k++) - { - new_size = current_param_size + size; - - if (new_size > param_size) - new_size = param_size; - - n = (new_size + 1) * sizeof(pointer); - - if (trace_flag) - trace_memory("param stack", n); - - new_param = (pointer *) REALLOC (param_stack, n); - - if (new_param != NULL) - break; /* did we get it ? */ - - if (current_param_size == 0) - break; /* initial allocation must work */ - - size = size / 2; /* else can retry smaller */ - } - - if (new_param == NULL) - { - memory_error("param stack", n); - return param_stack; /* try and continue !!! */ - } - - param_stack = new_param; - update_statistics((long) param_stack, n, current_param_size); - current_param_size = new_size; - - if (trace_flag) - { - printf("Current %s %d\n", "param_size", current_param_size); - printf("New Address %s == %p\n", "param stack", param_stack); - } - - if (trace_flag) - probe_show(); - - return param_stack; -} -#endif - -#ifdef ALLOCATEBUFFER -int current_buf_size = 0; - -ASCII_code * realloc_buffer (int size) -{ - int k, min_size; - int n = 0, new_size = 0; - ASCII_code * new_buffer = NULL; - - if (trace_flag) - printf("Old Address %s == %p\n", "buffer", buffer); - - if (current_buf_size == buf_size) - { - return buffer; - } - - min_size = current_buf_size / 100 * percent_grow; - - if (size < min_size) - size = min_size; - - if (size < initial_buf_size) - size = initial_buf_size; - - for (k = 0; k < MAXSPLITS; k++) - { - new_size = current_buf_size + size; - - if (new_size > buf_size) - new_size = buf_size; - - n = (new_size + 1) * sizeof(ASCII_code); - - if (trace_flag) - trace_memory("buffer", n); - - new_buffer = (ASCII_code *) REALLOC (buffer, n); - - if (new_buffer != NULL) - break; /* did we get it ? */ - - if (current_buf_size == 0) - break; /* initial allocation must work */ - - size = size / 2; - } - - if (new_buffer == NULL) - { - memory_error("buffer", n); - return buffer; /* try and continue !!! */ - } - - buffer = new_buffer; - update_statistics ((long) buffer, n, current_buf_size); - -#ifdef USEMEMSET - memset(buffer + current_buf_size, 0, new_size - current_buf_size); -#else - for (k = current_buf_size; k < new_size; k++) - buffer[k] = 0; -#endif - - current_buf_size = new_size; - - if (trace_flag) - { - printf("Current %s %d\n", "buffer", current_buf_size); - printf("New Address %s == %p\n", "buffer", buffer); - } - - if (trace_flag) - probe_show(); - - return buffer; -} -#endif - -/* here is the main memory allocation routine -- calls the above */ -/* returns -1 if it fails */ -/* allocate rather than static 93/Nov/26 */ -int allocate_memory (void) -{ -#ifdef ALLOCATEINPUTSTACK - input_stack = NULL; - current_stack_size = 0; - input_stack = realloc_input_stack(initial_stack_size); -#endif - -#ifdef ALLOCATENESTSTACK - nest = NULL; - current_nest_size = 0; - nest = realloc_nest_stack(initial_nest_size); -#endif - -#ifdef ALLOCATEPARAMSTACK - param_stack = NULL; - current_param_size = 0; - param_stack = realloc_param_stack(initial_param_size); -#endif - -#ifdef ALLOCATESAVESTACK - save_stack = NULL; - current_save_size = 0; - save_stack = realloc_save_stack (initial_save_size); -#endif - -#ifdef IGNORED - buffer = NULL; /* need to do earlier */ - current_buf_size = 0; - buffer = realloc_buffer (initial_buf_size); -#endif - -#ifdef ALLOCATESTRING - str_pool = NULL; - current_pool_size = 0; - str_start = NULL; - current_max_strings = 0; - -/* maybe taylor allocations to actual pool file 1300 strings 27000 bytes ? */ - if (is_initex) - { - if (trace_flag) - puts("ini TeX pool and string allocation"); - - str_pool = realloc_str_pool(initial_pool_size); - str_start = realloc_str_start(initial_max_strings); - } -#endif - -/* the following can save a lot of the usual 800k fixed allocation */ -#ifdef ALLOCATEFONT - font_info = NULL; - current_font_mem_size = 0; -/* if not iniTeX, then do initial allocation on fmt file read in itex.c */ -/* if ini-TeX we need to do it here - no format file read later */ - if (is_initex) - font_info = realloc_font_info(initial_font_mem_size); -#endif - -#ifdef ALLOCATEMAIN - main_memory = NULL; - mem = NULL; - mem_min = mem_bot; /* just to avoid complaints in texbody */ - mem_top = mem_initex; - mem_max = mem_top; -/* allocate main memory here if this is iniTeX */ -/* otherwise wait for format undumping in itex.c ... */ - if (is_initex) - { - /* avoid this if format specified on command line ??? */ - mem = allocate_main_memory(mem_initex); /* made variable ! */ - - if (mem == NULL) - return -1; - } -#endif - -/* now for the hyphenation exception stuff */ -#ifdef ALLOCATEHYPHEN - hyph_word = NULL; - hyph_list = NULL; -/* this will be overridden later by what is in format file */ - hyphen_prime = default_hyphen_prime; -/* non ini-TeX use assumes format will be read and that specifies size */ - if (is_initex) - { - if (new_hyphen_prime) - hyphen_prime = new_hyphen_prime; - - if (realloc_hyphen(hyphen_prime)) /* allocate just in case no format */ - return -1; - } -#endif - -/* now for memory for the part of the hyphenation stuff that always needed */ -/* if iniTeX, need to allocate pre-determined fixed amount - trie_size */ -/* if iniTeX not selected, allocate only enough later - undump in itex.c ! */ -#ifdef ALLOCATETRIES - if (is_initex) - { - if (allocate_tries (trie_size)) - return -1; - } -#endif - -/* now for memory for hyphenation stuff needed only when running iniTeX */ -#ifdef ALLOCATEINI - if (is_initex) - { - if (allocate_ini(trie_size)) - return -1; - } - else - { - trie_l = NULL; - trie_r = NULL; - trie_o = NULL; - trie_hash = NULL; - trie_c = NULL; - trie_taken = NULL; - } -#endif - - return 0; // success -} - -/* returns non-zero if error - done to test integrity of stack mostly */ -int free_memory (void) -{ - unsigned int heap_total = 0; - - if (trace_flag) - puts("free_memory "); - - if (verbose_flag || trace_flag) - show_maximums(stdout); - - if (trace_flag) - { - printf("Heap total: %u bytes --- max address %u\n", - heap_total, max_address); - printf("Main Memory: variable node %lld (%lld - %d);\n" - " one word %d (%d - %d)\n", - lo_mem_max - mem_min, mem_min, lo_mem_max, - mem_end - hi_mem_min, hi_mem_min, mem_end); - puts("Freeing memory again"); - } - -/* only free memory if safe ... additional check */ -#ifdef ALLOCATEINI - if (is_initex) - { - if (trie_taken != NULL) - free(trie_taken); - - if (trie_hash != NULL) - free(trie_hash); - - if (trie_r != NULL) - free(trie_r); - - if (trie_c != NULL) - free(trie_c); - - if (trie_o != NULL) - free(trie_o); - - if (trie_l != NULL) - free(trie_l); - - trie_taken = NULL; - trie_hash = NULL; - trie_l = NULL; - trie_r = NULL; - trie_c = NULL; - trie_o = NULL; - } -#endif - -#ifdef ALLOCATETRIES - if (trie_trc != NULL) - free(trie_trc); - - if (trie_tro != NULL) - free(trie_tro); - - if (trie_trl != NULL) - free(trie_trl); - - trie_trc = NULL; - trie_tro = NULL; - trie_trl = NULL; -#endif - -#ifdef ALLOCATEHYPHEN - if (hyph_list != NULL) - free(hyph_list); - - if (hyph_word != NULL) - free(hyph_word); - - hyph_list = NULL; - hyph_word = NULL; -#endif - -#ifdef ALLOCATEMAIN - if (main_memory != NULL) - free(main_memory); - - main_memory = NULL; -#endif - -#ifdef ALLOCATEFONT - if (font_info != NULL) - free(font_info); - - font_info = NULL; -#endif - -#ifdef ALLOCATESTRING - if (str_start != NULL) - free(str_start); - - if (str_pool != NULL) - free(str_pool); - - str_start = NULL; - str_pool = NULL; -#endif - -#ifdef ALLOCATEPARAMSTACK - if (param_stack != NULL) - free(param_stack); - - param_stack = NULL; -#endif - -#ifdef ALLOCATENESTSTACK - if (nest != NULL) - free(nest); - - nest = NULL; -#endif - -#ifdef ALLOCATEINPUTSTACK - if (input_stack != NULL) - free(input_stack); - - input_stack = NULL; -#endif - -#ifdef ALLOCATESAVESTACK - if (save_stack != NULL) - free(save_stack); - - save_stack = NULL; -#endif - - if (format_file != NULL) - free(format_file); - - if (source_direct != NULL) - free(source_direct); - - format_file = NULL; - source_direct = NULL; - - if (dvi_file_name != NULL) - free(dvi_file_name); - - if (log_file_name != NULL) - free(log_file_name); - - if (pdf_file_name != NULL) - free(pdf_file_name); - - pdf_file_name = NULL; - log_file_name = NULL; - dvi_file_name = NULL; - - return 0; -} - -boolean prime (int x) -{ - int k; - int sum = 1; /* 1 + 3 + 5 + k = (k + 1) * (k + 1) / 4 */ - - if (x % 2 == 0) - return false; - - for (k = 3; k < x; k = k + 2) - { - if (x % k == 0) - return false; - - if (sum * 4 > x) - return true; - - sum += k; - } - - return true; -} - -int quitflag = 0; -boolean show_use = false; - -void complainarg (int c, char *s) -{ - printf("ERROR: Do not understand `%c' argument value `%s'\n", c, s); - show_use = true; -} - -/* following is list of allowed command line flags and args */ - -char *allowedargs = "+bcdfijnpqrstvwyzABCDFGIJKLMNOPQRSTVWXYZ023456789?a=e=g=h=k=l=m=o=u=x=E=H=P=U="; - -void reorderargs (int ac, char **av) -{ - int n, m; - char *s, *t; - char takeargs[256]; /* large enough for all command line arg chars */ - - if (ac < 3) - { - return; /* no args ! */ - } - - s = allowedargs; - t = takeargs; /* list of those that take args */ - - while (*s != '\0' && *(s + 1) != '\0') - { - if (*(s + 1) == '=') - *t++ = *s++; /* copy over --- without the = */ - - s++; - } - - *t = '\0'; - - if (trace_flag) - { - show_line(takeargs, 0); - wterm_cr(); - } - - n = 1; - - for (;;) - { - if (*av[n] != '-') - break; - - if (n + 1 < ac && *(av[n] + 2) == '\0' && - strchr(takeargs, *(av[n] + 1)) != NULL) - n += 2; /* step over it */ - else - n++; - - if (n == ac) - break; - } - - for (;;) - { - if (n == ac) - break; - - m = n; - - while (m < ac && *av[m] != '-') - m++; /* first command */ - - if (m == ac) - break; -/* does it take an argument ? and is this argument next ? */ -/* check first whether the `-x' is isolated, or arg follows directly */ -/* then check whether this is one of those that takes an argument */ - if (m+1 < ac && *(av[m] + 2) == '\0' && - strchr(takeargs, *(av[m] + 1)) != NULL) - { - s = av[m]; /* move command down before non-command */ - t = av[m + 1]; - - for (; m > n; m--) - av[m + 1] = av[m - 1]; - - av[n] = s; - av[n + 1] = t; - n += 2; /* step over moved args */ - } - else - { - s = av[m]; /* move command down before non-command */ - - for (; m > n; m--) - av[m] = av[m - 1]; - - av[n] = s; - n++; /* step over moved args */ - } - } -} - -int test_align (long address, int size, const char *str) -{ - int n; - - if (size > sizeof(void *)) - n = address % sizeof(void *); - else - n = address % size; - - if (n != 0) - printf("OFFSET %d (ELEMENT %d) in %s\n", n, size, str); - - return n; -} - -/* activate detailed checking of alignment when trace_flag is set */ - -void check_fixed_align (int flag) -{ - (void) flag; - - if (test_align ((long) &mem_top, 4, "FIXED ALIGNMENT")) - { - puts("PLEASE RECOMPILE ME!"); - } - -#ifdef CHECKALIGNMENT - if (!flag) - return; - - test_align ((long) &mem_top, 4, "mem_top"); - test_align ((long) &mem_max, 4, "mem_max"); - test_align ((long) &mem_min, 4, "mem_min"); - test_align ((long) &bad, 4, "bad"); - test_align ((long) &trie_size, 4, "trie_size"); - test_align ((long) &xord, sizeof(xord[0]), "xord"); - test_align ((long) &xchr, sizeof(xchr[0]), "xchr"); - test_align ((long) &name_length, 4, "name_length"); - test_align ((long) &first, 4, "first"); - test_align ((long) &last, 4, "last"); - test_align ((long) &max_buf_stack, 4, "max_buf_stack"); - test_align ((long) &pool_ptr, 4, "pool_ptr"); - test_align ((long) &str_ptr, 4, "str_ptr"); - test_align ((long) &init_pool_ptr, 4, "init_pool_ptr"); - test_align ((long) &init_str_ptr, 4, "init_str_ptr"); - test_align ((long) &log_file, 4, "log_file"); - test_align ((long) &tally, 4, "tally"); - test_align ((long) &term_offset, 4, "term_offset"); - test_align ((long) &file_offset, 4, "file_offset"); - test_align ((long) &trick_count, 4, "trick_count"); - test_align ((long) &first_count, 4, "first_count"); - test_align ((long) &deletions_allowed, 4, "deletions_allowed"); - test_align ((long) &set_box_allowed, 4, "set_box_allowed"); - test_align ((long) &help_line, sizeof(help_line[0]), "help_line"); - test_align ((long) &use_err_help, 4, "use_err_help"); - test_align ((long) &interrupt, 4, "interrupt"); - test_align ((long) &OK_to_interrupt, 4, "OK_to_interrupt"); - test_align ((long) &arith_error, 4, "arith_error"); - test_align ((long) &tex_remainder, 4, "tex_remainder"); - test_align ((long) &temp_ptr, 4, "temp_ptr"); - test_align ((long) &lo_mem_max, 4, "lo_mem_max"); - test_align ((long) &hi_mem_min, 4, "hi_mem_min"); - test_align ((long) &var_used, 4, "var_used"); - test_align ((long) &dyn_used, 4, "dyn_used"); - test_align ((long) &avail, 4, "avail"); - test_align ((long) &mem_end, 4, "mem_end"); - test_align ((long) &mem_start, 4, "mem_start"); - test_align ((long) &rover, 4, "rover"); - test_align ((long) &font_in_short_display, 4, "font_in_short_display"); - test_align ((long) &depth_threshold, 4, "depth_threshold"); - test_align ((long) &breadth_max, 4, "breadth_max"); - test_align ((long) &nest, sizeof(nest[0]), "nest"); - // test_align ((long) &xeq_level, sizeof(xeq_level[0]), "xeq_level"); - test_align ((long) &zzzad, sizeof(zzzad[0]), "zzzad"); - // test_align ((long) &hash, sizeof(hash[0]), "hash"); - test_align ((long) &zzzae, sizeof(zzzae[0]), "zzzae"); - test_align ((long) &save_stack, sizeof(save_stack[0]), "save_stack"); - test_align ((long) &input_stack, sizeof(input_stack[0]), "input_stack"); - test_align ((long) &input_file, sizeof(input_file[0]), "input_file"); - test_align ((long) &line_stack, sizeof(line_stack[0]), "line_stack"); - test_align ((long) ¶m_stack, sizeof(param_stack[0]), "param_stack"); - test_align ((long) &cur_mark, sizeof(cur_mark[0]), "cur_mark"); - test_align ((long) &pstack, sizeof(pstack[0]), "pstack"); - test_align ((long) &read_file, sizeof(read_file[0]), "read_file"); - test_align ((long) &font_check, sizeof(font_check[0]), "font_check"); - test_align ((long) &font_size, sizeof(font_size[0]), "font_size"); - test_align ((long) &font_dsize, sizeof(font_dsize[0]), "font_dsize"); - test_align ((long) &font_params, sizeof(font_params[0]), "font_params"); - test_align ((long) &font_name, sizeof(font_name[0]), "font_name"); - test_align ((long) &font_area, sizeof(font_area[0]), "font_area"); - test_align ((long) &font_bc, sizeof(font_bc[0]), "font_bc"); - test_align ((long) &font_ec, sizeof(font_ec[0]), "font_ec"); - test_align ((long) &font_glue, sizeof(font_glue[0]), "font_glue"); - test_align ((long) &font_used, sizeof(font_used[0]), "font_used"); - test_align ((long) &hyphen_char, sizeof(hyphen_char[0]), "hyphen_char"); - test_align ((long) &skew_char, sizeof(skew_char[0]), "skew_char"); - test_align ((long) &bchar_label, sizeof(bchar_label[0]), "bchar_label"); - test_align ((long) &font_bchar, sizeof(font_bchar[0]), "font_bchar"); - test_align ((long) &font_false_bchar, sizeof(font_false_bchar[0]), "font_false_bchar"); - test_align ((long) &char_base, sizeof(char_base[0]), "char_base"); - test_align ((long) &width_base, sizeof(width_base[0]), "width_base"); - test_align ((long) &height_base, sizeof(height_base[0]), "height_base"); - test_align ((long) &depth_base, sizeof(depth_base[0]), "depth_base"); - test_align ((long) &italic_base, sizeof(italic_base[0]), "italic_base"); - test_align ((long) &lig_kern_base, sizeof(lig_kern_base[0]), "lig_kern_base"); - test_align ((long) &kern_base, sizeof(kern_base[0]), "kern_base"); - test_align ((long) &exten_base, sizeof(exten_base[0]), "exten_base"); - test_align ((long) ¶m_base, sizeof(param_base[0]), "param_base"); - test_align ((long) &total_stretch, sizeof(total_stretch[0]), "total_stretch"); - test_align ((long) &total_shrink, sizeof(total_shrink[0]), "total_shrink"); - test_align ((long) &active_width, sizeof(active_width[0]), "active_width"); - test_align ((long) &cur_active_width, sizeof(cur_active_width[0]), "cur_active_width"); - test_align ((long) &background, sizeof(background[0]), "background"); - test_align ((long) &break_width, sizeof(break_width[0]), "break_width"); - test_align ((long) &minimal_demerits, sizeof(minimal_demerits[0]), "minimal_demerits"); - test_align ((long) &best_place, sizeof(best_place[0]), "best_place"); - test_align ((long) &best_pl_line, sizeof(best_pl_line[0]), "best_pl_line"); - test_align ((long) &hc, sizeof(hc[0]), "hc"); - test_align ((long) &hu, sizeof(hu[0]), "hu"); - test_align ((long) &hyf, sizeof(hyf[0]), "hyf"); - // test_align ((long) &x, sizeof(x[0]), "x"); - test_align ((long) &hyf_distance, sizeof(hyf_distance[0]), "hyf_distance"); - test_align ((long) &hyf_num, sizeof(hyf_num[0]), "hyf_num"); - test_align ((long) &hyf_next, sizeof(hyf_next[0]), "hyf_next"); - test_align ((long) &op_start, sizeof(op_start[0]), "op_start"); - // test_align ((long) &trie_op_hash, sizeof(trie_op_hash[0]), "trie_op_hash"); - test_align ((long) &trie_used, sizeof(trie_used[0]), "trie_used"); -/* test_align ((long) &trie_op_lang, sizeof(trie_op_lang[0]), "trie_op_lang");*/ - test_align ((long) &trie_op_val, sizeof(trie_op_val[0]), "trie_op_val"); - test_align ((long) &trie_min, sizeof(trie_min[0]), "trie_min"); - test_align ((long) &page_so_far, sizeof(page_so_far[0]), "page_so_far"); - test_align ((long) &write_file, sizeof(write_file[0]), "write_file"); - test_align ((long) &write_open, sizeof(write_open[0]), "write_open"); -#endif -} - -void check_alloc_align (int flag) -{ - (void) flag; - - if (test_align((long) eqtb, sizeof(eqtb[0]), "ALLOCATED ALIGNMENT")) - puts("PLEASE RECOMPILE ME!"); - -#ifdef CHECKALIGNMENT - if (!flag) - return; - -#ifndef ALLOCZEQTB - test_align ((long) eqtb, sizeof(eqtb[0]), "eqtb"); -#endif - - test_align ((long) str_pool, sizeof(str_pool[0]), "str_pool"); /* no op */ - test_align ((long) str_start, sizeof(str_start[0]), "str_start"); - test_align ((long) mem, sizeof(mem[0]), "main memory"); - test_align ((long) font_info, sizeof(font_info[0]), "font memory"); - test_align ((long) trie_trl, sizeof(trie_trl[0]), "trie_trl"); - test_align ((long) trie_tro, sizeof(trie_tro[0]), "trie_tro"); - test_align ((long) trie_trc, sizeof(trie_trc[0]), "trie_trc"); - test_align ((long) hyph_word, sizeof(hyph_word[0]), "hyph_word"); - test_align ((long) hyph_list, sizeof(hyph_list[0]), "hyph_list"); -/* test_align ((long) trie_c, sizeof(trie_c[0]), "trie_c"); *//* no op */ - test_align ((long) trie_o, sizeof(trie_o[0]), "trie_o"); - test_align ((long) trie_l, sizeof(trie_l[0]), "trie_l"); - test_align ((long) trie_r, sizeof(trie_r[0]), "trie_r"); - test_align ((long) trie_hash, sizeof(trie_hash[0]), "trie_hash"); - test_align ((long) trie_taken, sizeof(trie_taken[0]), "trie_taken"); -#endif -} - -boolean shorten_file_name = false; /* don't shorten file names to 8+3 for DOS */ - -/* cache to prevent allocating twice in a row */ - -char * lastname = NULL; -char * lastvalue = NULL; - -/* returns allocated string -- these strings are not freed again */ -/* is it safe to do that now ? 98/Jan/31 */ -char * grabenv (const char * varname) -{ - char * s; - - if (varname == NULL) - return NULL; - - if (*varname == '\0') - return NULL; - - if (lastname != NULL && strcasecmp(lastname, varname) == 0) - { - if (trace_flag) - printf("Cache hit: %s=%s\n", lastname, lastvalue); - - return xstrdup(lastvalue); - } - - s = getenv(varname); - - if (s != NULL) - { - if (lastname != NULL) - free(lastname); - - lastname = xstrdup(varname); - - if (lastvalue != NULL) - free(lastvalue); - - lastvalue = xstrdup(s); - - return xstrdup(s); - } - else - return NULL; -} - -void flush_trailing_slash (char * directory) -{ - char * s; - - if (strcmp(directory, "") != 0) - { - s = directory + strlen(directory) - 1; - - if (*s == '\\' || *s == '/') - *s = '\0'; - } -} - -void knuthify (void) -{ - restrict_to_ascii = false; /* don't complain non ASCII */ - allow_patterns = false; /* don't allow pattern redefinition */ - show_in_hex = true; /* show character code in hex */ - show_in_dos = false; /* redundant with previous */ - show_numeric = false; /* don't show character code decimal */ - show_missing = false; /* don't show missing characters */ - civilize_flag = false; /* don't reorder date fields */ - c_style_flag = false; /* don't add file name to error msg */ - show_fmt_flag = false; /* don't show format file in log */ - show_tfm_flag = false; /* don't show metric file in log */ - tab_step = 0; - show_line_break_stats = false; /* do not show line break stats */ - show_fonts_used = false; - default_rule = 26214; /* revert to default rule thickness */ - pseudo_tilde = false; - pseudo_space = false; - truncate_long_lines = false; - allow_quoted_names = false; - show_cs_names = false; - ignore_frozen = false; - suppress_f_ligs = false; - full_file_name_flag = false; - knuth_flag = true; /* so other code can know about this */ -} - -/* following made global so analyze_flag can be made separate procedure */ - -char * xchr_file = NULL; -char * repl_file = NULL; - -const char * short_options = "m:e:h:0:H:g:P:o:l:a:r:kwvpiKLZMd2t?u"; - -static struct option long_options[] = -{ - {"main-memory", required_argument, NULL, 'm'}, - {"hyph-size", required_argument, NULL, 'e'}, - {"trie-size", required_argument, NULL, 'h'}, - {"backend", required_argument, NULL, '0'}, - {"tab-step", required_argument, NULL, 'H'}, - {"percent-grow", required_argument, NULL, 'g'}, - {"default-rule", required_argument, NULL, 'P'}, - {"dvi-dir", required_argument, NULL, 'o'}, - {"log-dir", required_argument, NULL, 'l'}, - {"aux-dir", required_argument, NULL, 'a'}, - {"key-file", required_argument, NULL, 'k'}, - {"jobname", required_argument, NULL, 'r'}, - {"showhex", no_argument, NULL, 'w'}, - {"verbose", no_argument, NULL, 'v'}, - {"patterns", no_argument, NULL, 'p'}, - {"initex", no_argument, NULL, 'i'}, - {"knuthify", no_argument, NULL, 'K'}, - {"cstyle", no_argument, NULL, 'L'}, - {"showtfm", no_argument, NULL, 'Z'}, - {"showmissing", no_argument, NULL, 'M'}, - {"deslash", no_argument, NULL, 'd'}, - {"suppressflig", no_argument, NULL, '2'}, - {"trace", no_argument, NULL, 't'}, - {"help", no_argument, NULL, '?'}, - {"usage", no_argument, NULL, 'u'}, - {NULL, 0, 0, 0} -}; - -int analyze_flag (int c, char * optarg) -{ - switch (c) - { - case 'r': - c_job_name = optarg; - break; - case 'v': - verbose_flag = true; - break; - case 'i': - is_initex = true; - break; - case 'Q': - interaction = batch_mode; - break; - case 'R': - interaction = nonstop_mode; - break; - case 'S': - interaction = scroll_mode; - break; - case 'T': - interaction = error_stop_mode; - break; - case 'K': - knuthify(); - break; - case 'L': - c_style_flag = true; - break; - case 'Z': - show_tfm_flag = true; - break; - case 'M': - show_missing = false; - break; - case 'd': - deslash = false; - break; - case 'p': - allow_patterns = true; - break; - case 'w': - show_in_hex = true; - break; - case 'j': - show_in_dos = true; - break; - case 'n': - restrict_to_ascii = true; /* 0 - 127 1994/Jan/21 */ - break; - case 'f': - show_fonts_used = false; - break; - case '8': - shorten_file_name = true; - break; - case '9': - show_cs_names = true; - break; - case '4': - ignore_frozen = true; - break; - case 'J': - show_line_break_stats = false; /* 96/Feb/8 */ - break; - case 'O': - show_fmt_flag = false; /* 94/Jun/21 */ - break; - case '2': - suppress_f_ligs = true; /* 99/Jan/5 f-lig */ - break; - case 'z': - full_file_name_flag = false; // 00 Jun 18 - break; - case 't': - trace_flag = true; - break; - case 'q': - quitflag++; /* 93/Dec/16 */ - break; -/* The following are really obscure and should not be advertized */ - case 's': - show_current = false; - break; - case 'N': - show_numeric = false; - break; - case 'A': - civilize_flag = false; - break; - case 'B': - open_trace_flag = true; - break; - case 'Y': - reorder_arg_flag = false; /* local */ - break; - - case 'm': - if (optarg == 0) - mem_initex = mem_top; - else - mem_initex = atoi(optarg) * 1024; - - if (mem_initex == 0) - complainarg(c, optarg); - - mem_spec_flag = true; - break; - -#ifdef VARIABLETRIESIZE - case 'h': - if (optarg == 0) - { - //trie_size = atoi(kpse_var_value("trie_size")); - trie_size = default_trie_size; - } - else - trie_size = atoi(optarg); - - if (trie_size == 0) - complainarg(c, optarg); - break; -#endif - -#ifdef ALLOCATEHYPHEN - case 'e': - if (optarg == 0) - new_hyphen_prime = hyphen_prime * 2; - else - new_hyphen_prime = atoi(optarg); - - if (new_hyphen_prime == 0) - complainarg(c, optarg); - - break; -#endif - case 'g': - if (optarg == 0) - percent_grow = 62; - else - percent_grow = atoi(optarg); - - if (percent_grow == 0) - complainarg(c, optarg); - - break; - - case 'U': - if (optarg == 0) - pseudo_tilde = 0; - else - pseudo_tilde = atoi(optarg); - - if (pseudo_tilde > 255) - pseudo_tilde = 255; - else if (pseudo_tilde < 128) - pseudo_tilde = 128; - - break; - - case 'H': - if (optarg == 0) - tab_step = 8; - else - tab_step = atoi(optarg); - if (tab_step == 0) - complainarg(c, optarg); - break; - - case 'x': - if (optarg == 0) - xchr_file = xstrdup("xchr.map"); - else - xchr_file = xstrdup(optarg); - - if (xchr_file == NULL || *xchr_file == '\0') - complainarg(c, optarg); - break; - - case 'k': - if (optarg == 0) - repl_file = xstrdup("repl.key"); - else - repl_file = xstrdup(optarg); - - if (repl_file == NULL || *repl_file == '\0') - complainarg(c, optarg); - break; - - case 'P': - if (optarg == 0) - default_rule = 26214; - else - default_rule = atoi(optarg); - - if (default_rule == 0) - complainarg(c, optarg); - break; - - case 'E': - if (optarg != 0) - putenv(optarg); - else - complainarg(c, optarg); - break; - - case 'o': - if (optarg == 0) - dvi_directory = ""; - else - dvi_directory = xstrdup(optarg); - - if (strcmp(dvi_directory, "") == 0) - complainarg(c, optarg); - - break; - - case 'l': - if (optarg == 0) - log_directory = ""; - else - log_directory = xstrdup(optarg); - - if (strcmp(log_directory, "") == 0) - complainarg(c, optarg); - - break; - - case 'a': - if (optarg == 0) - aux_directory = ""; - else - aux_directory = xstrdup(optarg); - - if (strcmp(aux_directory, "") == 0) - complainarg(c, optarg); - - break; - - case '?': - default: - show_use = true; - return -1; - break; - } - - return 0; -} - -void strip_name (char *pathname) -{ - char *s; - - if ((s = strrchr(pathname, '\\')) != NULL) - ; - else if ((s = strrchr(pathname, '/')) != NULL) - ; - else if ((s = strrchr(pathname, ':')) != NULL) - s++; - else - s = pathname; - - *s = '\0'; -} - -int read_command_line (int ac, char **av) -{ - int c; - char *optargnew; - int option_idx = 0; - - if (ac < 2) - return 0; - - while ((c = getopt_long_only(ac, av, short_options, long_options, &option_idx)) != EOF) - { - if (optarg != 0 && *optarg == '=') - optargnew = optarg + 1; - else - optargnew = optarg; - - analyze_flag(c, optargnew); - } - - if (show_use || quitflag == 3) - { - stamp_it(log_line); - strcat(log_line, "\n"); - show_line(log_line, 0); - - if (show_use) - show_usage(); - else if (quitflag == 3) - { - strcat(log_line, "\n"); - show_line(log_line, 0); - } - - return -1; // failure - } - - if (repl_file != NULL && *repl_file != '\0') - { - if (read_xchr_file(repl_file, 1, av)) - { - if (trace_flag) - puts("KEY REPLACE ON"); - - key_replace = true; - } - } - - if (xchr_file != NULL && *xchr_file != '\0') - { - if (read_xchr_file(xchr_file, 0, av)) - { - if (trace_flag) - puts("NON ASCII ON"); - - non_ascii = true; - } - } - - return 0; -} - -int init_commands (int ac, char **av) -{ - shipout_flag = out_dvi_flag; - is_initex = false; - allow_patterns = false; - reset_exceptions = false; - non_ascii = false; - key_replace = false; - open_trace_flag = false; - trace_flag = false; - verbose_flag = false; - restrict_to_ascii = false; - show_in_hex = false; /* default is not to show as hex code ^^ 00/Jun/18 */ - show_in_dos = false; /* default is not to translate to DOS 850 */ - return_flag = true; // hard wired now - trimeof = true; // hard wired now - deslash = true; - pseudo_tilde = 254; /* default '~' replace 95/Sep/26 filledbox DOS 850 */ - pseudo_space = 255; /* default ' ' replace 97/June/5 nbspace DOS 850 */ - default_rule = 26214; - show_current = true; - civilize_flag = true; - show_numeric = true; - show_missing = true; - c_style_flag = false; - show_fmt_flag = true; - show_tfm_flag = false; /* don't show metric file in log */ - shorten_file_name = false; /* don't shorten file names to 8+3 */ - truncate_long_lines = true; /* truncate long lines */ - tab_step = 0; /* do not replace tabs with spaces */ - show_line_break_stats = true; /* show line break statistics 96/Feb/8 */ - show_fonts_used = true; /* show fonts used in LOG file 97/Dec/24 */ - allow_quoted_names = true; /* allow quoted names with spaces 98/Mar/15 */ - show_cs_names = false; - knuth_flag = false; - full_file_name_flag = true; /* new default 2000 June 18 */ - errout = stdout; /* as opposed to stderr say --- used ??? */ - new_hyphen_prime = 0; - -#ifdef VARIABLETRIESIZE - // trie_size = default_trie_size; - trie_size = 0; -#endif - - mem_extra_high = 0; - mem_extra_low = 0; - mem_initex = 0; - format_name = "plain"; - - if (read_command_line(ac, av) < 0) - return -1; - - if (optind == 0) - optind = ac; - - return 0; -} - -void initial_memory (void) -{ - /* set initial memory allocations */ - if (mem_extra_high < 0) - mem_extra_high = 0; - - if (mem_extra_low < 0) - mem_extra_low = 0; - - if (mem_initex < 0) - mem_initex = 0; - - if (is_initex) - { - #if defined(ALLOCATEHIGH) || defined(ALLOCATELOW) - if (mem_extra_high != 0 || mem_extra_low != 0) - { - puts("ERROR: Cannot extend main memory in initex"); - mem_extra_high = 0; - mem_extra_low = 0; - } -#endif - } - else - { - if (mem_initex != 0) - { - puts("ERROR: Can only set initial main memory size in initex"); - mem_initex = 0; - } - - if (trie_size != 0) - { - puts("ERROR: Need only set hyphenation trie size in initex"); -/* trie_size = 0; */ - } - } - if (mem_initex == 0) - mem_initex = default_mem_top; - - if (trie_size == 0) - trie_size = default_trie_size; - -/* Just in case user mistakenly specified words instead of kilo words */ - if (mem_extra_high > 10000L * 1024L) - mem_extra_high = mem_extra_high / 1024; - - if (mem_extra_low > 10000L * 1024L) - mem_extra_low = mem_extra_low / 1024; - - if (mem_initex > 10000L * 1024L) - mem_initex = mem_initex / 1024; - - if (mem_initex > 2048L * 1024L) /* extend main memory by 16 mega byte! */ - { - puts("WARNING: There may be no benefit to asking for so much memory"); -/* mem_initex = 2048 * 1024; */ - } - - if (new_hyphen_prime < 0) - new_hyphen_prime = 0; - - if (new_hyphen_prime > 0) - { - if (! is_initex) - puts("ERROR: Can only set hyphen prime in initex"); - else - { - if (new_hyphen_prime % 2 == 0) - new_hyphen_prime++; - - while (!prime(new_hyphen_prime)) - new_hyphen_prime = new_hyphen_prime + 2; - - if (trace_flag) - printf("Using %d as hyphen prime\n", new_hyphen_prime); - } - } - - if (percent_grow > 100) - percent_grow = percent_grow - 100; - - if (percent_grow > 100) - percent_grow = 100; /* upper limit - double */ - - if (percent_grow < 10) - percent_grow = 10; /* lower limit - 10% */ -} - -void perrormod (const char * s) -{ - printf("`%s': %s\n", s, strerror(errno)); -} - -/* convert tilde to pseudo_tilde to hide it from TeX --- 95/Sep/26 */ -/* convert space to pseudo_space to hide it from TeX --- 97/Jun/5 */ -/* called only if pseudo_tilde != 0 or pseudo_space != 0 */ -/* this is then undone in tex3.c both for fopen input and output */ -/* not ideal, since pseudo name appears in log and in error messages ... */ - -void hidetwiddle (char *tname) -{ - char *s = tname; - -#ifdef DEBUGTWIDDLE - if (trace_flag) - printf("Hidetwiddle %s", tname); -#endif - - while (*s != '\0') - { - if (*s == '~' && pseudo_tilde != 0) - *s = (char) pseudo_tilde; /* typically 254 */ - else if (*s == ' ' && pseudo_space != 0) - *s = (char) pseudo_space; /* typically 255 */ - s++; - } - -#ifdef DEBUGTWIDDLE - if (trace_flag) - printf("=> %s\n", tname); -#endif -} - -void deslash_all (int ac, char **av) -{ - char buffer[file_name_size]; - char *s; - - if ((s = grabenv("TEXDVI")) != NULL) - dvi_directory = s; - - if ((s = grabenv("TEXLOG")) != NULL) - log_directory = s; - - if ((s = grabenv("TEXAUX")) != NULL) - aux_directory = s; - - if ((s = grabenv("TEXFMT")) != NULL) - fmt_directory = s; - - if ((s = grabenv("TEXPDF")) != NULL) - pdf_directory = s; - - strcpy(buffer, av[0]); - - if ((s = strrchr(buffer, '\\')) != NULL) - *(s + 1) = '\0'; - else if ((s = strrchr(buffer, '/')) != NULL) - *(s + 1) = '\0'; - else if ((s = strrchr(buffer, ':')) != NULL) - *(s + 1) = '\0'; - - s = buffer + strlen(buffer) - 1; - - if (*s == '\\' || *s == '/') - *s = '\0'; - - if (strcmp(dvi_directory, "") != 0) - flush_trailing_slash(dvi_directory); - - if (strcmp(log_directory, "") != 0) - flush_trailing_slash(log_directory); - - if (strcmp(aux_directory, "") != 0) - flush_trailing_slash(aux_directory); - - if (strcmp(fmt_directory, "") != 0) - flush_trailing_slash(fmt_directory); - - if (strcmp(pdf_directory, "") != 0) - flush_trailing_slash(pdf_directory); - - if (deslash) - { - if (strcmp(dvi_directory, "") != 0) - unixify(dvi_directory); - - if (strcmp(log_directory, "") != 0) - unixify(log_directory); - - if (strcmp(aux_directory, "") != 0) - unixify(aux_directory); - - if (strcmp(fmt_directory, "") != 0) - unixify(fmt_directory); - - if (strcmp(pdf_directory, "") != 0) - unixify(pdf_directory); - } - - format_spec = false; - - if (optind < ac && optind > 0) - { - if (deslash) - { - if (trace_flag) - printf("deslash: k %d argv[k] %s (argc %d)\n", optind, av[optind], ac); - - unixify(av[optind]); - } - - if (pseudo_tilde != 0 || pseudo_space != 0) - hidetwiddle(av[optind]); - - if (*av[optind] == '&' || *av[optind] == '+') - { - format_spec = true; - format_name = xstrdup(av[optind] + 1); - - if (optind + 1 < ac) - { - if (deslash) - { - if (trace_flag) - printf("deslash: k %d argv[k] %s (argc %d)\n", optind + 1, av[optind + 1], ac); - - unixify(av[optind + 1]); - } - - if (pseudo_tilde != 0 || pseudo_space != 0) - hidetwiddle(av[optind + 1]); - } - } - } -} - -int main_init (int ac, char ** av) -{ - kpse_set_program_name(av[0], "dvipdfmx"); - xputenv("engine", "yandytex"); - - if (sizeof(memory_word) != sizeof(halfword) * 2) - printf("ERROR: Bad word size %ld!\n", sizeof(memory_word)); - - start_time = clock(); - main_time = start_time; - -/* reset all allocatable memory pointers to NULL - in case we drop out */ - main_memory = NULL; - font_info = NULL; - str_pool = NULL; - str_start = NULL; - -#ifdef ALLOCATESAVESTACK - save_stack = NULL; -#endif - -#ifdef ALLOCATEBUFFER - buffer = NULL; - current_buf_size = 0; - buffer = realloc_buffer(initial_buf_size); -#endif - - hyph_list = NULL; - hyph_word = NULL; - trie_taken = NULL; - trie_hash = NULL; - trie_r = NULL; - trie_c = NULL; - trie_o = NULL; - trie_l = NULL; - trie_trc = NULL; - trie_tro = NULL; - trie_trl = NULL; - - log_opened = false; /* so can tell whether opened */ - interaction = -1; /* default state => 3 */ - missing_characters = 0; /* none yet! */ - ignore_frozen = false; /* default is not to ignore 98/Oct/5 */ - suppress_f_ligs = false; /* default is not to ignore f-ligs */ - - if (ac > 1 && !strncmp(av[1], "-Y", 2)) - reorder_arg_flag = false; - - if (reorder_arg_flag) - reorderargs(ac, av); - - if (init_commands(ac, av)) - return -1; - - check_fixed_align(trace_flag); - - format_file = NULL; - source_direct = NULL; - dvi_file_name = NULL; - log_file_name = NULL; - pdf_file_name = NULL; - - first_pass_count = 0; - second_pass_count = 0; - final_pass_count = 0; - paragraph_failed = 0; - single_line = 0; - overfull_hbox = 0; - underfull_hbox = 0; - overfull_vbox = 0; - underfull_vbox = 0; - - if (trace_flag) - puts("Entering main_init() (local.c)."); - - probe_memory(); - ini_max_address = max_address; - - if (trace_flag) - show_maximums(stdout); - - initial_memory(); - deslash_all(ac, av); - - if (format_spec && mem_spec_flag) - puts("WARNING: Cannot change initial main_memory size when format specified"); - - if (allocate_memory() != 0) - return -1; - - check_alloc_align(trace_flag); - - if (trace_flag) - puts("Leaving main_init() (local.c)."); - - return 0; -} - -#define CLK_TCK CLOCKS_PER_SEC - -void show_inter_val (clock_t inter_val) -{ - int seconds, tenths, hundredth, thousands; - - if (inter_val >= CLK_TCK * 10) - { - tenths = (inter_val * 10 + CLK_TCK / 2) / CLK_TCK; - seconds = tenths / 10; - tenths = tenths % 10; - printf("%d.%d", seconds, tenths); - } - else if (inter_val >= CLK_TCK) - { - hundredth = (inter_val * 100 + CLK_TCK / 2) / CLK_TCK; - seconds = hundredth / 100; - hundredth = hundredth % 100; - printf("%d.%02d", seconds, hundredth); - } - else if (inter_val > 0) - { - thousands = (inter_val * 1000 + CLK_TCK / 2) / CLK_TCK; - seconds = thousands / 1000; - thousands = thousands % 1000; - printf("%d.%03d", seconds, thousands); - } - else - show_line("0", 0); -} - -int endit(int flag) -{ - finish_time = clock(); - - if (missing_characters != 0) - flag = 1; - - if (missing_characters) - printf("! There %s %d missing character%s --- see log file\n", - (missing_characters == 1) ? "was" : "were", missing_characters, - (missing_characters == 1) ? "" : "s"); - - if (free_memory() != 0) - flag++; - - if (verbose_flag) - { - printf("Total "); - show_inter_val(finish_time - start_time); - printf(" sec ("); - show_inter_val(main_time - start_time); - printf(" format load + "); - show_inter_val(finish_time - main_time); - printf(" processing) "); - - if (total_pages > 0) - { - show_inter_val((finish_time - main_time) / total_pages); - printf(" sec per page.\n"); - } - } - - return flag; -} -// printf control sequences' name -void print_cs_name (FILE * output, int h) -{ - int c, textof, n; - - memset(log_line, 0, sizeof(log_line)); - - textof = hash[h].rh; - - if (textof == 0) - return; - - c = sprintf(log_line, "(%d), ", h); - n = length(textof); - - memmove(log_line + c, str_pool + str_start[textof], n); - memmove(log_line + c + n, "\n", 2); - - if (output == stderr) - show_line(log_line, 1); - else if (output == stdout) - show_line(log_line, 0); - else - fprintf(output, "%s", log_line); -} -// prototype -int compare_strn (int, int, int, int); -/* compare two csnames in qsort */ -int compare_cs (const void *cp1, const void *cp2) -{ - int c1, c2, l1, l2, k1, k2, textof1, textof2; - - c1 = *(int *)cp1; - c2 = *(int *)cp2; - textof1 = hash[c1].rh; - textof2 = hash[c2].rh; - l1 = length(textof1); - l2 = length(textof2); - k1 = str_start[textof1]; - k2 = str_start[textof2]; - - return compare_strn(k1, l1, k2, l2); -} - -char * csused = NULL; - -/* Allocate table of indeces to allow sorting on csname */ -/* Allocate flags to remember which ones already listed at start */ -/* pass = 0 --> fmt */ -/* pass = 1 --> after */ -void print_cs_names (FILE *output, int pass) -{ - int h, k, ccount, repeatflag; - int *cnumtable; - int nfcs = frozen_control_sequence; - - if (pass == 0 && csused == NULL) - { - csused = (char *) malloc (nfcs); - - if (csused == NULL) - return; - -#ifdef USEMEMSET - memset(csused, 0, nfcs); -#else - for (h = 0; h < (hash_size + 780); h++) - csused[h] = 0; -#endif - } - - ccount = 0; - - for (h = hash_base + 1; h < nfcs; h++) - { - if (pass == 1 && csused[h]) - continue; - - if (text(h) != 0) - { - if (pass == 0) - csused[h] = 1; - - ccount++; - } - } - - sprintf(log_line, "\n%d %s multiletter control sequences:\n", - ccount, (pass == 1) ? "new" : ""); - - if (output == stderr) - show_line(log_line, 1); - else if (output == stdout) - show_line(log_line, 0); - else - fprintf(output, "%s", log_line); - - if (ccount > 0) - { - cnumtable = (int *) malloc (ccount * sizeof(int)); - - if (cnumtable == NULL) - return; - - ccount = 0; - - for (h = hash_base + 1; h < nfcs; h++) - { - if (pass == 1 && csused[h]) - continue; - - if (hash[h].rh != 0) - cnumtable[ccount++] = h; - } - - //qsort ((void *)cnumtable, ccount, sizeof (int), &compare_cs); - - repeatflag = 0; - - for (k = 0; k < ccount; k++) - { - h = cnumtable[k]; - - if (pass == 1 && csused[h]) - continue; - - print_cs_name(output, h); - } - - sprintf(log_line, "\n"); - - if (output == stderr) - show_line(log_line, 1); - else if (output == stdout) - show_line(log_line, 0); - else - fprintf(output, "%s", log_line); - - free((void *)cnumtable); - } - - if (pass == 1 && csused != NULL) - { - free(csused); - csused = NULL; - } -} - -/* k1 and k2 are positions in string pool */ -/* l1 and l2 are lengths of strings */ -int compare_strn (int k1, int l1, int k2, int l2) -{ - int c1, c2; - - while (l1 > 0 && l2 > 0) - { - c1 = str_pool[k1]; - c2 = str_pool[k2]; - - if (c1 > c2) - return 1; - else if (c2 > c1) - return -1; - - l1--; l2--; - k1++; k2++; - } - - if (l1 > 0) - return 1; /* first string longer */ - else if (l2 > 0) - return -1; /* second string longer */ - - return 0; /* strings match */ -} -/* compare two font names and their at sizes in qsort */ -int compare_fnt (const void * fp1, const void * fp2) -{ - int f1, f2, l1, l2, k1, k2, s; - - f1 = *(short *)fp1; - f2 = *(short *)fp2; - l1 = length(font_name[f1]); - l2 = length(font_name[f2]); - k1 = str_start[font_name[f1]]; - k2 = str_start[font_name[f2]]; - - s = compare_strn (k1, l1, k2, l2); - - if (s != 0) - return s; - - if (font_size[f1] > font_size[f2]) - return 1; - else if (font_size[f1] < font_size[f2]) - return -1; - - return 0; /* should not ever get here */ -} -/* compare two font names */ -int compare_fnt_name (int f1, int f2) -{ - int l1, l2, k1, k2, s; - - l1 = length(font_name[f1]); - l2 = length(font_name[f2]); - k1 = str_start[font_name[f1]]; - k2 = str_start[font_name[f2]]; - - s = compare_strn (k1, l1, k2, l2); - - return s; -} -/* decode checksum information */ -const unsigned long checkdefault = 0x59265920; -int decode_fourty (unsigned long checksum, char *codingvector) -{ - int c; - int k; - - if (checksum == 0) - { - strcpy(codingvector, "unknwn"); - return 1; - } - else if ((checksum >> 8) == (checkdefault >> 8)) - { - strcpy (codingvector, "fixed "); - return 1; - } - else - { - for (k = 0; k < 6; k++) - { - c = (int) (checksum % 40); - checksum = checksum / 40; - - if (c <= 'z' - 'a') - c = c + 'a'; - else if (c < 36) - c = (c + '0') - ('z' - 'a') - 1; - else if (c == 36) - c = '-'; - else if (c == 37) - c = '&'; - else if (c == 38) - c = '_'; - else - c = '.'; - - codingvector[5-k] = (char) c; - } - - codingvector[6] = '\0'; - } - - return 0; -} - -double sclpnt (long x) -{ - double pt; - - pt = (double) x / 65536.0; - pt = (double) ((int) (pt * 1000.0 + 0.5)) / 1000.0; - - return (pt); -} - -void dvi_font_show (internal_font_number f, int suppressname) -{ - int a, l, k, n; - unsigned long checksum; - char checksumvector[8]; - char buffer[32]; - - putc(' ', log_file); - - if (suppressname == 0) - { - a = length(font_area[f]); - l = length(font_name[f]); - - k = str_start[font_area[f]]; - - memcpy(buffer, str_pool + k, length(font_area[f])); - fwrite(buffer, sizeof(char), length(font_area[f]), log_file); - - k = str_start[font_name[f]]; - - memcpy(buffer, str_pool + k, length(font_name[f])); - fwrite(buffer, sizeof(char), length(font_name[f]), log_file); - } - else a = l = 0; - - for (k = a + l; k < 16; k++) - putc(' ', log_file); - - sprintf(buffer, "at %lgpt ", sclpnt(font_size[f])); - fputs(buffer, log_file); - - if (suppressname == 0) - { - n = strlen(buffer); - - for (k = n; k < 16; k++) - putc(' ', log_file); - - checksum = (((font_check[f].b0) << 8 | font_check[f].b1) << 8 | font_check[f].b2) << 8 | font_check[f].b3; - decode_fourty(checksum, checksumvector); - fprintf(log_file, "encoding: %s..", checksumvector); - } - - putc('\n', log_file); -} -/* Allocate table of indeces to allow sorting on font name */ -void show_font_info (void) -{ - int k, m, fcount, repeatflag; - short *fnumtable; - - fcount = 0; - - for (k = 1; k <= font_ptr; k++) - if (font_used[k]) - fcount++; - - if (fcount == 0) - return; - - fnumtable = (short *) malloc(fcount * sizeof(short)); - - fprintf(log_file, "\nUsed %d font%s:\n", fcount, (fcount == 1) ? "" : "s"); - - fcount = 0; - - for (k = 1; k <= font_ptr; k++) - if (font_used[k]) - fnumtable[fcount++] = (short) k; - - qsort ((void *)fnumtable, fcount, sizeof(short), &compare_fnt); - - repeatflag = 0; - - for (m = 0; m < fcount; m++) - { - if (m > 0) - { - if (compare_fnt_name(fnumtable[m - 1], fnumtable[m]) == 0) - repeatflag = 1; - else - repeatflag = 0; - } - - dvi_font_show(fnumtable[m], repeatflag); - } - - free((void *)fnumtable); -} +/* Copyright 2007 TeX Users Group + Copyright 2014 Clerk Ma + + 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ + +#define EXTERN extern + +#include "yandytex.h" + +#define USEOUREALLOC +#define USEMEMSET + +#ifdef USEOUREALLOC + #define REALLOC ourrealloc +#else + #define REALLOC realloc +#endif + +#if defined (__ANDROID__) + #define malloc_usable_size dlmalloc_usable_size +#elif defined (__APPLE__) + #define malloc_usable_size malloc_size +#endif + +#if defined (__clang__) +const char * compiler = "Clang/LLVM"; +#elif defined (__GNUC__) || defined(__GNUG__) +const char * compiler = "GCC"; +#elif defined (_MSC_VER) +const char * compiler = "MSVC"; +#endif + +#if defined (_WIN64) +const char * dist = "Win64"; +#elif defined (_WIN32) +const char * dist = "Win32"; +#elif defined (__ANDROID__) +const char * dist = "Android"; +#elif defined (__APPLE__) +const char * dist = "Darwin"; +#elif defined (__gnu_linux__) +const char * dist = "Linux"; +#else +const char * dist = "Unknown"; +#endif + +const char * compiletime = __TIME__; +const char * compiledate = __DATE__; +const char * yandyversion = "2.3.0"; +const char * application = "Y&Y TeX"; +const char * banner = "This is TeX, Version 3.14159265"; + +void print_banner (void) +{ + char dist_ver[256]; + memset(dist_ver, 0, sizeof(dist_ver)); + sprintf(dist_ver, "%s (%s %s/%s)", banner, application, yandyversion, dist); + prints(dist_ver); +} + +clock_t start_time, main_time, finish_time; + +char * dvi_directory = ""; +char * log_directory = ""; +char * aux_directory = ""; +char * fmt_directory = ""; +char * pdf_directory = ""; + +char log_line[256]; + +boolean mem_spec_flag = false; +boolean format_spec = false; +boolean reorder_arg_flag = true; /* put command line flags/arguments first */ + +/* Mapping from Windows ANSI to DOS code page 850 96/Jan/20 */ + +unsigned char wintodos[128] = +{ + 0, 0, 0, 159, 0, 0, 0, 0, + 94, 0, 0, 0, 0, 0, 0, 0, + 0, 96, 39, 0, 0, 7, 0, 0, + 126, 0, 0, 0, 0, 0, 0, 0, + 32, 173, 189, 156, 207, 190, 221, 21, + 0, 184, 166, 174, 170, 45, 169, 0, + 248, 241, 253, 252, 0, 230, 20, 250, + 0, 251, 167, 175, 172, 171, 243, 168, + 183, 181, 182, 199, 142, 143, 146, 128, + 212, 144, 210, 211, 222, 214, 215, 216, + 209, 165, 227, 224, 226, 229, 153, 158, + 157, 235, 233, 234, 154, 237, 232, 225, + 133, 160, 131, 198, 132, 134, 145, 135, + 138, 130, 136, 137, 141, 161, 140, 139, + 208, 164, 149, 162, 147, 228, 148, 246, + 155, 151, 163, 150, 129, 236, 231, 152 +}; + +void show_usage (void) +{ + printf("\n" + "Useage: yandytex [OPTION]... [+format_file] [tex_file]\n\n" + "--help -? show this usage summary\n" + "--initex -i start up as initex (create format file)\n" + "--verbose -v be verbose (show implementation version number)\n" + "--ascii -n do not allow `non ASCII' characters in input files\n" + " (complain instead)\n" + "--showhex -w do not show `non ASCII' characters in hexadecimal\n" + " (show as is)\n" + "--nodos -d do not allow DOS style file names - i.e. do not convert\n" + " \\ to /\n" + "--nomac -r do not allow Mac style termination - i.e. do not convert\n" + " \\r to \\n\n" + "--patterns -p allow use of \\patterns after loading format (initex only)\n" + "--knuthify -K disable all extensions to basic TeX\n" + "--main-mem -m initial main memory size in kilo words (initex only)\n" + "--hyph-size -e hyphenation exception dictionary size (initex only)\n" + "--trie-size -h hyphenation pattern trie size (initex only)\n" + "--xchr-file -x use `non ASCII' character mapping (xchr[]) defined in file\n" + "--key-file -k use `key replacement' defined in file\n" + "--dvi-dir -o write DVI file in specified directory (default '.')\n" + "--log-dir -l write LOG file in specified directory (default '.')\n" + "--aux-dir -a write AUX file in specified directory (default '.')\n"); + uexit(EXIT_FAILURE); +} + +// Sep 27 1990 => 1990 Sep 27 +// 0123456789 0123456789 +void scivilize (char * date) +{ + int k; + char pyear[6]; + + strcpy(pyear, date + 7); + + for (k = 5; k >= 0; k--) + date[k + 5] = date[k]; + + for (k = 0; k < 4; k++) + date[k] = pyear[k]; + + date[4] = ' '; + + if (date[9] == ' ') + date[9] = '0'; +} + +// Thu Sep 27 06:26:35 1990 => 1990 Sep 27 06:26:35 +void lcivilize (char * date) +{ + int k; + char pyear[6]; + + strcpy(pyear, date + 20); + + for (k = 18; k >= 0; k--) + date[k + 1] = date[k]; + + date[20] = '\0'; + + for (k = 0; k < 4; k++) + date[k] = pyear[k]; + + date[4] = ' '; +} + +void stamp_it (char * s) +{ + char date[11 + 1]; + + strcpy(date, compiledate); + scivilize(date); + sprintf(s, "%s %s (compiled time: %s %s with %s)", + application, yandyversion, date, compiletime, compiler); + s += strlen(s); +} + +#define MAXCHRS 256 +#define NOTDEF 127 + +void read_xchr_sub (FILE * xchr_input) +{ + char buffer[file_name_size]; + int k, from, to, count = 0; + char * s; + + memset(xchr, NOTDEF, MAXCHRS); + memset(xord, NOTDEF, MAXCHRS); + +#ifdef ALLOCATEBUFFER + while (fgets(buffer, current_buf_size, xchr_input) != NULL) +#else + while (fgets(buffer, sizeof(buffer), xchr_input) != NULL) +#endif + { + if (*buffer == '%' || *buffer == ';' || *buffer == '\n') + continue; + + from = (int) strtol (buffer, &s, 0); + to = (int) strtol (s, NULL, 0); + + if (from >= 0 && from < MAXCHRS && to >= 0 && to < MAXCHRS) + { + if (xchr[from] == NOTDEF) + xchr[from] = (unsigned char) to; + else + printf("NOTE: %s collision: %d => %d, %d\n", "xchr", from, xchr[from], to); + + if (xord[to] == NOTDEF) + xord[to] = (unsigned char) from; + else + printf("NOTE: %s collision: %d => %d, %d\n", "xord", to, xord[to], from); + + count++; + } + } + + for (k = 0; k < MAXCHRS; k++) + { + if (xchr[k] == NOTDEF) /* if it has not been filled */ + { + if (xord[k] == NOTDEF) /* see whether used already */ + { + xchr[k] = (unsigned char) k; /* no, so make identity */ + xord[k] = (unsigned char) k; /* no, so make identity */ + } + } + } + + xchr[NOTDEF] = NOTDEF; /* fixed point of mapping */ + + if (trace_flag) + { + printf("Read %d xchr[] pairs:\n", count); + + for (k = 0; k < MAXCHRS; k++) + { + if (xchr[k] != NOTDEF) + printf("%d => %d\n", k, xchr[k]); + } + } +} + +char * replacement[MAXCHRS]; /* pointers to replacement strings */ + +void read_repl_sub (FILE * repl_input) +{ + int k, n, m, chrs; + char buffer[file_name_size]; + char charname[128]; + int charnum[10]; + char * s, * t; + + memset(replacement, 0, MAXCHRS * sizeof(replacement[0])); + + while (fgets(buffer, file_name_size, repl_input) != NULL) + { + if (*buffer == '%' || *buffer == ';' || *buffer == '\n') + continue; + + if ((m = sscanf(buffer, "%d%n %s", &chrs, &n, (char *)&charname)) == 0) + continue; + else if (m == 2) + { + if (*charname == '"') /* deal with quoted string "..." */ + { + s = buffer + n; + t = charname; + + while (*s != '"' && *s != '\0') + s++; /* step up to " */ + + if (*s++ == '\0') + continue; /* sanity check */ + + while (*s != '\0') + { + if (*s == '"') + { + s++; /* is it "" perhaps ? */ + + if (*s != '"') + break; /* no, end of string */ + } + + *t++ = *s++; /* copy over */ + } + + *t = '\0'; /* and terminate */ + } + + if (chrs >= 0 && chrs < MAXCHRS) + replacement[chrs] = xstrdup(charname); + } +/* presently the following can never get triggered */ +/* which is good, because it is perhaps not right ... */ + else if ((m = sscanf (buffer, "%d %d %d %d %d %d %d %d %d %d %d", + &chrs, charnum, charnum+1, charnum+2, charnum+3, charnum+4, + charnum+5, charnum+6, charnum+7, charnum+8, charnum+9)) > 1) { +/* for (k = 0; k < n-1; k++) charname[k] = (char) charnum; */ + for (k = 0; k < n-1; k++) charname[k] = (char) charnum[k]; + charname[m] = '\0'; + if (chrs >= 0 && chrs < MAXCHRS) + replacement[chrs] = xstrdup(charname); + } + else + printf("ERROR: don't understand %s", buffer); + } + + if (trace_flag) + { + puts("Key replacement table"); + + for (k = 0; k < MAXCHRS; k++) + { + if (replacement[k] != NULL) + printf("%d\t%s\n", k, replacement[k]); + } + } +} + +/* Following used both to read xchr[] file and key replacement file */ +/* the flag is 0 for -x=... and the flag is 1 for -k=... */ +int read_xchr_file (char *filename, int flag, char *argv[]) +{ + FILE *xchr_input; + char infile[file_name_size]; + char *s; + + if (filename == NULL) + return -1; + + if (trace_flag) + printf("Reading xchr/repl %s\n", filename); + + /* first try using file as specified */ + strcpy(infile, filename); + + if (trace_flag) + printf("Trying %s\n", infile); + + xchr_input = fopen (infile, "r"); + + if (xchr_input == NULL) + { + if (strrchr(infile, '.') == NULL) + { + if (flag == 0) + strcat(infile, ".map"); + else + strcat(infile, ".key"); + + if (trace_flag) + printf("Trying %s\n", infile); + + xchr_input = fopen(infile, "r"); + } + } + + if (xchr_input == NULL) + { + strcpy(infile, argv[0]); /* try TeX program path */ + + if ((s = strrchr (infile, '\\')) != NULL) + *(s+1) = '\0'; + else if ((s = strrchr (infile, '/')) != NULL) + *(s+1) = '\0'; + else if ((s = strrchr (infile, ':')) != NULL) + *(s+1) = '\0'; + + strcat (infile, filename); + + if (trace_flag) + printf("Trying %s\n", infile); + + xchr_input = fopen (infile, "r"); + + if (xchr_input == NULL) + { + if (strchr(infile, '.') == NULL) + { + if (flag == 0) + strcat(infile, ".map"); + else + strcat(infile, ".key"); + + if (trace_flag) + printf("Trying %s\n", infile); + + xchr_input = fopen (infile, "r"); + } + } + } + + if (xchr_input == NULL) + { + strcpy(infile, argv[0]); /* try TeX program path */ + + if ((s = strrchr (infile, '\\')) != NULL) + *(s + 1) = '\0'; + else if ((s = strrchr (infile, '/')) != NULL) + *(s + 1) = '\0'; + else if ((s = strrchr (infile, ':')) != NULL) + *(s + 1) = '\0'; + + strcat(infile, "keyboard\\"); + strcat(infile, filename); + + if (trace_flag) + printf("Trying %s\n", infile); + + xchr_input = fopen (infile, "r"); + + if (xchr_input == NULL) + { + if (strchr(infile, '.') == NULL) + { + if (flag == 0) + strcat(infile, ".map"); + else + strcat(infile, ".key"); + + if (trace_flag) + printf("Trying %s\n", infile); + + xchr_input = fopen (infile, "r"); + } + } + } + + /* Note: can't look in TeX source file dir, since that is not known yet */ + if (xchr_input == NULL) + { + printf("ERROR: Sorry, cannot find %s file %s", + flag ? " xchr[]" : "key mapping", filename); + perrormod (filename); + return 0; + } + + if (flag == 0) + read_xchr_sub(xchr_input); + else + read_repl_sub(xchr_input); + + (void) fclose(xchr_input); + + return 1; +} + +/* need to also set `key_replace' here based on command line */ +/* need to also allocate `buffercopy' here and free at end */ +/* need to call `readreplace' in appropriate place */ + +#define MAXSPLITS 3 + +/* ad hoc default minimum growth in memory realloc is 62% */ +/* golden ratio (1 + \sqrt{5}) / 2 = 1.618033989... */ +int percent_grow = 62; /* default minimum growth in memory realloc is 62% */ +int total_allocated = 0; /* total memory allocated so far */ +int ini_max_address = 0; /* maximum address when starting */ +int max_address = 0; /* maximum address seen in allocated memory */ + + +void show_maximums (FILE * output) +{ + sprintf(log_line, "Max allocated %d --- max address %d\n", total_allocated, max_address); + fputs(log_line, output); +} + +/* our own version of realloc --- avoid supposed MicroSoft version bug */ +/* also tries _expand first, which can avoid address growth ... */ + +#ifdef USEOUREALLOC +void * ourrealloc (void * old, size_t new_size) +{ + void * mnew; + size_t old_size, overlap; + + /* round up to nearest multiple of four bytes */ + /* avoid unlikely alignment */ + if ((new_size % 4) != 0) + new_size = ((new_size / 4) + 1) * 4; + + if (old == NULL) + return malloc (new_size); /* no old block - use malloc */ + +#ifdef _WIN32 + old_size = _msize (old); +#else + old_size = malloc_usable_size (old); +#endif + + if (old_size >= new_size && old_size < new_size + 4) + return old; + +#ifdef _WIN32 + mnew = _expand (old, new_size); /* first try and expand in place MSVC */ +#else + mnew = realloc (old, new_size); +#endif + + if (mnew != NULL) + { + if (trace_flag) + printf("EXPANDED! %p (%ld) == %p (%ld)\n", + mnew, new_size, old, old_size); + + return mnew; + } + + /* do this if you want to call the real realloc next - */ + mnew = realloc (old, new_size); + + if (mnew != NULL) + return mnew; + + /* we are screwed typically if we ever drop through here - no more space */ + mnew = malloc (new_size); /* otherwise find new space */ + + if (mnew == NULL) + return mnew; /* if unable to allocate */ + + if (old_size < new_size) + overlap = old_size; + else + overlap = new_size; + + memcpy (mnew, old, overlap); /* copy old data to new area */ + free(old); /* free the old area */ + + return mnew; +} +#endif + +void memory_error (const char * s, int n) +{ + if (log_opened) + { + fprintf(log_file, "\n! Unable to allocate %d bytes for %s\n", n, s); + show_maximums(log_file); + } + + printf("\n! Unable to allocate %d bytes for %s\n", n, s); + show_maximums(stderr); +} + +void trace_memory (const char * s, int n) +{ + printf("Allocating %d bytes for %s\n", n, s); +} + +void update_statistics (long address, int size, int old_size) +{ + if (address + size > max_address) + max_address = address + size; + + total_allocated = total_allocated + size - old_size; +} + +void probe_memory (void) +{ + char * s = (char *) malloc(sizeof(void *)); + free(s); + update_statistics ((long) s, 0, 0); +} + +void probe_show (void) +{ + probe_memory(); + show_maximums(stdout); +} + +size_t roundup (size_t n) +{ + if ((n % sizeof(void *)) == 0) + return n; + else + return ((n / sizeof(void *)) + 1) * sizeof(void *); +} + +#ifdef ALLOCATETRIES +/* returns -1 if it fails */ + +int allocate_tries (int trie_max) +{ + int n, nl, no, nc; + + if (trie_max > 1000000) + trie_max = 1000000; + + nl = (trie_max + 1) * sizeof(halfword); + no = (trie_max + 1) * sizeof(halfword); + nc = (trie_max + 1) * sizeof(quarterword); + n = nl + no + nc; + + if (trace_flag) + trace_memory("hyphen trie", n); + + trie_trl = (halfword *) malloc(roundup(nl)); + trie_tro = (halfword *) malloc(roundup(no)); + trie_trc = (quarterword *) malloc(roundup(nc)); + + if (trie_trl == NULL || trie_tro == NULL || trie_trc == NULL) + { + memory_error("hyphen trie", n); + return -1; + } + + if (trace_flag) + printf("Addresses trie_trl %p trie_tro %p trie_trc %p\n", trie_trl, trie_tro, trie_trc); + + update_statistics((long) trie_trl, nl, 0); + update_statistics((long) trie_tro, no, 0); + update_statistics((long) trie_trc, nc, 0); + + trie_size = trie_max; + + if (trace_flag) + probe_show(); + + return 0; // success +} +#endif + +#ifdef ALLOCATEHYPHEN +int current_prime = 0; /* remember in case reallocated later */ + +/* we don't return an address here, since TWO memory regions allocated */ +/* plus, we don't really reallocate, we FLUSH the old information totally */ +/* returns -1 if it fails */ + +int realloc_hyphen (int hyphen_prime) +{ + int n, nw, nl; + + if (!prime(hyphen_prime)) + { + printf("ERROR: non-prime hyphen exception number (%d)\n", hyphen_prime); + return -1; + } + +/* need not/cannot preserve old contents when hyphen prime is changed */ +/* if (hyph_list != NULL) free(hyph_list); */ +/* if (hyph_word != NULL) free(hyph_word); */ + nw = (hyphen_prime + 1) * sizeof(str_number); + nl = (hyphen_prime + 1) * sizeof(halfword); + n = nw + nl; + + if (trace_flag) + trace_memory("hyphen exception", n); + + hyph_word = (str_number *) REALLOC (hyph_word, nw); + hyph_list = (halfword *) REALLOC (hyph_list, nl); + + if (hyph_word == NULL || hyph_list == NULL) + { + memory_error("hyphen exception", n); + return -1; + } + + if (trace_flag) + printf("Addresses hyph_word %p hyph_list %p\n", hyph_word, hyph_list); + +/* cannot preserve old contents when hyphen prime is changed */ +#ifdef USEMEMSET + memset(hyph_word, 0, (hyphen_prime + 1) * sizeof (hyph_word[0])); +#else + for (k = 0; k <= hyphen_prime; k++) + hyph_word[k]= 0; +#endif + +#ifdef USEMEMSET + memset(hyph_list, 0, (hyphen_prime + 1) * sizeof (hyph_list[0])); +#else + for (k = 0; k <= hyphen_prime; k++) + hyph_list[k]= 0; +#endif + + hyph_count = 0; + + if (current_prime != 0) + { + update_statistics((long) hyph_word, nw, (current_prime + 1) * sizeof(str_number)); + update_statistics((long) hyph_list, nl, (current_prime + 1) * sizeof(halfword)); + } + else + { + update_statistics((long) hyph_word, nw, 0); + update_statistics((long) hyph_list, nl, 0); + } + + current_prime = hyphen_prime; + + if (trace_flag) + probe_show(); + + return 0; // success +} +#endif + +int current_mem_size = 0; /* current total words in main mem allocated -1 */ + +/* this gets called from itex.c when it figures out what mem_top is */ +/* or gets called from here when in ini_TeX mode */ /* and nowhere else */ +/* initial allocation only, may get expanded later */ +/* NOTE: we DON't use ALLOCATEHIGH & ALLOCATELOW anymore */ +/* returns NULL if it fails */ + +#ifdef ALLOCATEMAIN +/* initial main memory alloc - mem_top */ +memory_word * allocate_main_memory (int size) +{ + int n; + + if (main_memory != NULL) + { + if (trace_flag) + puts("Reallocating initial memory allocation"); + } + + mem_top = mem_bot + size; + mem_max = mem_top; + mem_start = 0; /* bottom of memory allocated by system */ + mem_min = 0; /* bottom of area made available to TeX */ + n = (mem_max - mem_start + 1) * sizeof (memory_word); + + if (trace_flag) + trace_memory("main memory", n); + + main_memory = (memory_word *) REALLOC (main_memory, n); + + if (main_memory == NULL) + { + memory_error("initial main memory", n); + return NULL; + } + + if (trace_flag) + printf("Address main memory == %p\n", main_memory); + + mem = main_memory; + + if (mem_start != 0 && !is_initex) + mem = main_memory - mem_start; + + if (trace_flag) + printf("Offset address main memory == %p\n", mem); + + update_statistics((long) main_memory, n, (current_mem_size + 1) * sizeof (memory_word)); +/* current_mem_size = (mem_max - mem_start + 1); */ + current_mem_size = mem_max - mem_start; /* total number of words - 1 */ + + if (trace_flag) + probe_show(); + + return mem; +} +#endif + +#ifdef ALLOCATEMAIN +/* int firstallocation = 1; */ + +/* increase main memory allocation at low end and high end */ +/* called only from tex0.c *//* called with one of lo_size or hi_size == 0 */ +/* returns NULL if it fails */ + +memory_word * realloc_main (int lo_size, int hi_size) +{ + int k, min_size; + int new_size = 0; + int n = 0; + memory_word * new_memory = NULL; + + if (trace_flag) + printf("WARNING: Entering realloc_main lo %d hi %d\n", lo_size, hi_size); + + if (is_initex) + { + puts("ERROR: Cannot extent main memory in initex"); + + if (!knuth_flag) + puts("Please use `-m=...' on command line"); + + return NULL; + } + + if (trace_flag) + printf("Old Address %s == %p\n", "main memory", main_memory); + + /* if we REALLY run up to limit ! */ + if (current_mem_size + 1 == max_mem_size) + { + memory_error("main memory", (max_mem_size + 1) * sizeof(memory_word)); + return NULL; + } + +/* first allocation should expand *both* lo and hi */ + if (hi_size == 0 && mem_end == mem_max) + hi_size = lo_size; + + if (lo_size == 0 && mem_start == mem_min) + lo_size = hi_size; + +/* try and prevent excessive frequent reallocations */ +/* while avoiding over allocation by too much */ + min_size = current_mem_size / 100 * percent_grow; + + if (lo_size + hi_size < min_size) + { + if (lo_size > 0 && hi_size > 0) + { + lo_size = min_size / 2; + hi_size = min_size / 2; + } + else if (lo_size > 0) + lo_size = min_size; + else if (hi_size > 0) + hi_size = min_size; + } + + if (lo_size > 0 && lo_size < mem_top / 2) + lo_size = mem_top / 2; + + if (hi_size > 0 && hi_size < mem_top / 2) + hi_size = mem_top / 2; + + for (k = 0; k < MAXSPLITS; k++) + { + new_size = current_mem_size + lo_size + hi_size; + + if (new_size >= max_mem_size) /* bump against limit - ha ha ha */ + { + while (new_size >= max_mem_size) + { + lo_size = lo_size / 2; + hi_size = hi_size / 2; + new_size = current_mem_size + lo_size + hi_size; + } + } + + n = (new_size + 1) * sizeof (memory_word); + + if (trace_flag) + trace_memory("main memory", n); + + new_memory = (memory_word *) REALLOC (main_memory, n); + + if (new_memory != NULL) + break; /* did we get it ? */ + + if (current_mem_size == 0) + break; /* in case we ever use for initial */ + + lo_size = lo_size / 2; hi_size = hi_size / 2; + } + + if (new_memory == NULL) + { + memory_error("main memory", n); + return mem; + } + + if (trace_flag) + printf("New Address %s == %p\n", "main memory", new_memory); + + if (lo_size > 0) + { +/* shift everything upward to make space for new low area */ + if (trace_flag) + printf("memmove %p %p %ld \n", new_memory + lo_size, + new_memory, (current_mem_size + 1) * sizeof(memory_word)); + + memmove (new_memory + lo_size, new_memory, + (current_mem_size + 1) * sizeof(memory_word)); +/* could reduce words moved by (mem_max - mem_end) */ + } + + main_memory = new_memory; /* remember for free later */ + + if (lo_size > 0) + mem_start = mem_start - lo_size; /* update lower limit */ + + if (hi_size > 0) + mem_max = mem_max + hi_size; /* update upper limit */ + + update_statistics ((long) main_memory, n, + (current_mem_size + 1) * sizeof (memory_word)); + current_mem_size = new_size; + + if (current_mem_size != mem_max - mem_start) + puts("ERROR: Impossible Memory Error"); + + if (mem_start != 0) + mem = main_memory - mem_start; + else + mem = main_memory; + + if (trace_flag) + probe_show(); + + return mem; +} +#endif + +#ifdef ALLOCATEFONT +int current_font_mem_size = 0; + +memory_word * realloc_font_info (int size) +{ + memory_word * new_font_info = NULL; + int k, min_size; + int new_size = 0; + int n = 0; + + if (trace_flag) + printf("Old Address %s == %p\n", "font_info", font_info); + + /* during initial allocation, font_info == NULL - realloc acts like malloc */ + /* during initial allocation current_font_mem_size == 0 */ + if (current_font_mem_size == font_mem_size) /* if we REALLY run up to limit */ + { + /* memory_error("font", (font_mem_size + 1) * sizeof(memory_word)); */ + return font_info; /* pass it back to TeX 99/Fabe/4 */ + } + /* try and prevent excessive frequent reallocations */ + /* while avoiding over allocation by too much */ + /* min_size = current_font_mem_size / 2; */ + min_size = current_font_mem_size / 100 * percent_grow; + + if (size < min_size) + size = min_size; + + if (size < initial_font_mem_size) + size = initial_font_mem_size; + + for (k=0; k < MAXSPLITS; k++) + { + new_size = current_font_mem_size + size; + + if (new_size > font_mem_size) + new_size = font_mem_size; /* bump against limit */ + +/* important + 1 since fmemoryword font_info[font_mem_size + 1] original */ + n = (new_size + 1) * sizeof (memory_word); + + if (trace_flag) + trace_memory("font_info", n); + + new_font_info = (memory_word *) REALLOC (font_info, n); + + if (new_font_info != NULL) + break; /* did we get it ? */ + + if (current_font_mem_size == 0) + break; /* initial allocation must work */ + + size = size / 2; + } + + if (new_font_info == NULL) + { + memory_error("font", n); + return font_info; /* try and continue !!! */ + } + + font_info = new_font_info; + + if (trace_flag) + printf("New Address %s == %p\n", "font_info", font_info); + + update_statistics ((long) font_info, n, current_font_mem_size * sizeof(memory_word)); + current_font_mem_size = new_size; + + if (trace_flag) + probe_show(); + + return font_info; +} +#endif + +#ifdef ALLOCATESTRING +int current_pool_size = 0; + +packed_ASCII_code * realloc_str_pool (int size) +{ + int k, min_size; + int new_size = 0; + int n = 0; + packed_ASCII_code * new_str_pool = NULL; + + if (trace_flag) + printf("Old Address %s == %p\n", "string pool", str_pool); + + if (current_pool_size == pool_size) + { +/* memory_error ("string pool", (pool_size + 1) * sizeof(packed_ASCII_code)); */ +/* exit (1); */ + return str_pool; /* pass it back to TeX 99/Fabe/4 */ + } + + min_size = current_pool_size / 100 * percent_grow; + + if (size < min_size) + size = min_size; + + if (size < initial_pool_size) + size = initial_pool_size; + + for (k = 0; k < MAXSPLITS; k++) + { + new_size = current_pool_size + size; + + if (new_size > pool_size) + new_size = pool_size; +/* important + 1 since packed_ASCII_code str_pool[pool_size + 1]; in original */ + n = (new_size + 1) * sizeof (packed_ASCII_code); + + if (trace_flag) + trace_memory("str_pool", n); + + new_str_pool = (packed_ASCII_code *) REALLOC (str_pool, n); /* 95/Sep/24 */ + + if (new_str_pool != NULL) + break; /* did we get it ? */ + + if (current_pool_size == 0) + break; /* initial allocation must work */ + + size = size / 2; /* else can retry smaller */ + } + + if (new_str_pool == NULL) + { + memory_error("string pool", n); + return str_pool; /* try and continue !!! */ + } + + str_pool = new_str_pool; + update_statistics ((long) str_pool, n, current_pool_size); + current_pool_size = new_size; + + if (trace_flag) + printf("New Address %s == %p\n", "string pool", str_pool); + + if (trace_flag) + probe_show(); + + return str_pool; +} +#endif + +#ifdef ALLOCATESTRING +int current_max_strings = 0; + +pool_pointer * realloc_str_start (int size) +{ + int k, min_size; + int n = 0; + int new_size = 0; + pool_pointer * new_str_start = NULL; + + if (trace_flag) + printf("Old Address %s == %p\n", "string start", str_start); + + if (current_max_strings == max_strings) + { +/* memory_error ("string pointer", (max_strings + 1) * sizeof(pool_pointer)); */ +/* exit (1); */ + return str_start; /* pass it back to TeX 99/Fabe/4 */ + } + + min_size = current_max_strings / 100 * percent_grow; + + if (size < min_size) + size = min_size; + + if (size < initial_max_strings) + size = initial_max_strings; + + for (k = 0; k < MAXSPLITS; k++) + { + new_size = current_max_strings + size; + + if (new_size > max_strings) + new_size = max_strings; +/* important + 1 since str_start[maxstring + 1] originally */ + n = (new_size + 1) * sizeof (pool_pointer); + + if (trace_flag) + trace_memory("str_start", n); + + new_str_start = (pool_pointer *) REALLOC (str_start, n); + + if (new_str_start != NULL) + break; /* did we get it ? */ + + if (current_max_strings == 0) + break; /* initial allocation must work */ + + size = size / 2; /* otherwise can try smaller */ + } + + if (new_str_start == NULL) + { + memory_error("string pointer", n); + return str_start; /* try and continue */ + } + + str_start = new_str_start; + update_statistics((long) str_start, n, current_max_strings * sizeof (pool_pointer)); + current_max_strings = new_size; + + if (trace_flag) + printf("New Address %s == %p\n", "string start", str_start); + + if (trace_flag) + probe_show(); + + return str_start; +} +#endif + +#ifdef ALLOCATEINI +/* returns -1 if it fails */ +/* size == trie_size */ +int allocate_ini (int size) +{ + int n, nl, no, nc, nr, nh, nt; + + nh = (size + 1) * sizeof(trie_pointer); + nr = (size + 1) * sizeof(trie_pointer); + nl = (size + 1) * sizeof(trie_pointer); + no = (size + 1) * sizeof(trie_op_code); + nc = (size + 1) * sizeof(packed_ASCII_code); + nt = (size + 1) * sizeof(char); + n = nl + no + nc + nr + nh + nt; + + if (trace_flag) + trace_memory ("initex hyphen trie", n); + + trie_l = (trie_pointer *) malloc (roundup(nl)); + trie_o = (trie_op_code *) malloc (roundup(no)); + trie_c = (packed_ASCII_code *) malloc (roundup(nc)); + trie_r = (trie_pointer *) malloc (roundup(nr)); + trie_hash = (trie_pointer *) malloc (roundup(nh)); + trie_taken = (char *) malloc (roundup(nt)); + + if (trie_c == NULL || trie_o == NULL || trie_l == NULL || trie_r == NULL || + trie_hash == NULL || trie_taken == NULL) + { + memory_error("initex hyphen trie", n); + return -1; + } + + if (trace_flag) + { + printf("Addresses: trie_l %p trie_o %p trie_c %p\n", trie_l, trie_o, trie_c); + printf("Addresses: trie_r %p trie_hash %p trie_taken %p\n", trie_r, trie_hash, trie_taken); + } + + update_statistics ((long) trie_l, nl, 0); + update_statistics ((long) trie_o, no, 0); + update_statistics ((long) trie_c, nc, 0); + update_statistics ((long) trie_r, nr, 0); + update_statistics ((long) trie_hash, nh, 0); + update_statistics ((long) trie_taken, nt, 0); + + if (trace_flag) + probe_show(); + + return 0; // success +} +#endif + +#ifdef ALLOCATESAVESTACK +int current_save_size = 0; + +memory_word * realloc_save_stack (int size) +{ + int k, min_size; + int n = 0, new_size = 0; + memory_word * new_save_stack = NULL; + + if (trace_flag) + printf("Old Address %s == %p\n", "save stack", save_stack); + + if (current_save_size == save_size) + { + return save_stack; /* let TeX handle the error */ + } + + min_size = current_save_size / 100 * percent_grow; + + if (size < min_size) + size = min_size; + + if (size < initial_save_size) + size = initial_save_size; + + for (k = 0; k < MAXSPLITS; k++) + { + new_size = current_save_size + size; + + if (new_size > save_size) + new_size = save_size; + + n = (new_size + 1) * sizeof (memory_word); + + if (trace_flag) + trace_memory("save_stack", n); + + new_save_stack = (memory_word *) REALLOC (save_stack, n); + + if (new_save_stack != NULL) + break; /* did we get it ? */ + + if (current_save_size == 0) + break; /* initial allocation must work */ + + size = size / 2; /* else can retry smaller */ + } + + if (new_save_stack == NULL) + { + memory_error("save_stack", n); + return save_stack; /* try and continue !!! */ + } + + save_stack = new_save_stack; + update_statistics ((long) save_stack, n, current_save_size); + current_save_size = new_size; + + if (trace_flag) + { + printf("Current %s %d\n", "save_size", current_save_size); + printf("New Address %s == %p\n", "save stack", save_stack); + } + + if (trace_flag) + probe_show(); + + return save_stack; +} +#endif + +#ifdef ALLOCATEINPUTSTACK +int current_stack_size = 0; /* input stack size */ + +in_state_record * realloc_input_stack (int size) +{ + int k, min_size; + int n = 0, new_size = 0; + in_state_record * new_input_stack = NULL; + + if (trace_flag) + printf("Old Address %s == %p\n", "input stack", input_stack); + + if (current_stack_size == stack_size) + { + return input_stack; + } + + min_size = current_stack_size / 100 * percent_grow; + + if (size < min_size) + size = min_size; + + if (size < initial_stack_size) + size = initial_stack_size; + + for (k = 0; k < MAXSPLITS; k++) + { + new_size = current_stack_size + size; + + if (new_size > stack_size) + new_size = stack_size; + + n = (new_size + 1) * sizeof(in_state_record); + + if (trace_flag) + trace_memory("input_stack", n); + + new_input_stack = (in_state_record *) REALLOC (input_stack, n); + + if (new_input_stack != NULL) + break; /* did we get it ? */ + + if (current_stack_size == 0) + break; /* initial allocation must work */ + + size = size / 2; /* else can retry smaller */ + } + + if (new_input_stack == NULL) + { + memory_error("input stack", n); + return input_stack; /* try and continue !!! */ + } + + input_stack = new_input_stack; + update_statistics ((long) input_stack, n, current_stack_size); + current_stack_size = new_size; + + if (trace_flag) + { + printf("Current %s %d\n", "stack_size", current_stack_size); + printf("New Address %s == %p\n", "input stack", input_stack); + } + + if (trace_flag) + probe_show(); + + return input_stack; +} +#endif + +#ifdef ALLOCATENESTSTACK +int current_nest_size = 0; /* current nest size */ + +list_state_record * realloc_nest_stack (int size) +{ + int k, min_size; + int n = 0, new_size = 0; + list_state_record * new_nest = NULL; + + if (trace_flag) + printf("Old Address %s == %p\n", "nest stack", nest); + + if (current_nest_size == nest_size) + { + return nest; + } + + min_size = current_nest_size / 100 * percent_grow; + + if (size < min_size) + size = min_size; + + if (size < initial_nest_size) + size = initial_nest_size; + + for (k = 0; k < MAXSPLITS; k++) + { + new_size = current_nest_size + size; + + if (new_size > nest_size) + new_size = nest_size; + + n = (new_size + 1) * sizeof (list_state_record); + + if (trace_flag) + trace_memory("nest stack", n); + + new_nest = (list_state_record *) REALLOC (nest, n); + + if (new_nest != NULL) + break; /* did we get it ? */ + + if (current_nest_size == 0) + break; /* initial allocation must work */ + + size = size / 2; /* else can retry smaller */ + } + + if (new_nest == NULL) + { + memory_error("nest stack", n); + return nest; /* try and continue !!! */ + } + + nest = new_nest; + update_statistics ((long) nest, n, current_nest_size); + current_nest_size = new_size; + + if (trace_flag) + { + printf("Current %s %d\n", "nest_size", current_nest_size); + printf("New Address %s == %p\n", "nest stack", nest); + } + + if (trace_flag) + probe_show(); + + return nest; +} +#endif + +#ifdef ALLOCATEPARAMSTACK +int current_param_size = 0; + +halfword *realloc_param_stack (int size) +{ + int k, min_size; + int n = 0, new_size = 0; + halfword * new_param = NULL; + + if (trace_flag) + printf("Old Address %s == %p\n", "param stack", param_stack); + + if (current_param_size == param_size) + { + return param_stack; + } + + min_size = current_param_size / 100 * percent_grow; + + if (size < min_size) + size = min_size; + + if (size < initial_param_size) + size = initial_param_size; + + for (k = 0; k < MAXSPLITS; k++) + { + new_size = current_param_size + size; + + if (new_size > param_size) + new_size = param_size; + + n = (new_size + 1) * sizeof(pointer); + + if (trace_flag) + trace_memory("param stack", n); + + new_param = (pointer *) REALLOC (param_stack, n); + + if (new_param != NULL) + break; /* did we get it ? */ + + if (current_param_size == 0) + break; /* initial allocation must work */ + + size = size / 2; /* else can retry smaller */ + } + + if (new_param == NULL) + { + memory_error("param stack", n); + return param_stack; /* try and continue !!! */ + } + + param_stack = new_param; + update_statistics((long) param_stack, n, current_param_size); + current_param_size = new_size; + + if (trace_flag) + { + printf("Current %s %d\n", "param_size", current_param_size); + printf("New Address %s == %p\n", "param stack", param_stack); + } + + if (trace_flag) + probe_show(); + + return param_stack; +} +#endif + +#ifdef ALLOCATEBUFFER +int current_buf_size = 0; + +ASCII_code * realloc_buffer (int size) +{ + int k, min_size; + int n = 0, new_size = 0; + ASCII_code * new_buffer = NULL; + + if (trace_flag) + printf("Old Address %s == %p\n", "buffer", buffer); + + if (current_buf_size == buf_size) + { + return buffer; + } + + min_size = current_buf_size / 100 * percent_grow; + + if (size < min_size) + size = min_size; + + if (size < initial_buf_size) + size = initial_buf_size; + + for (k = 0; k < MAXSPLITS; k++) + { + new_size = current_buf_size + size; + + if (new_size > buf_size) + new_size = buf_size; + + n = (new_size + 1) * sizeof(ASCII_code); + + if (trace_flag) + trace_memory("buffer", n); + + new_buffer = (ASCII_code *) REALLOC (buffer, n); + + if (new_buffer != NULL) + break; /* did we get it ? */ + + if (current_buf_size == 0) + break; /* initial allocation must work */ + + size = size / 2; + } + + if (new_buffer == NULL) + { + memory_error("buffer", n); + return buffer; /* try and continue !!! */ + } + + buffer = new_buffer; + update_statistics ((long) buffer, n, current_buf_size); + +#ifdef USEMEMSET + memset(buffer + current_buf_size, 0, new_size - current_buf_size); +#else + for (k = current_buf_size; k < new_size; k++) + buffer[k] = 0; +#endif + + current_buf_size = new_size; + + if (trace_flag) + { + printf("Current %s %d\n", "buffer", current_buf_size); + printf("New Address %s == %p\n", "buffer", buffer); + } + + if (trace_flag) + probe_show(); + + return buffer; +} +#endif + +/* here is the main memory allocation routine -- calls the above */ +/* returns -1 if it fails */ +/* allocate rather than static 93/Nov/26 */ +int allocate_memory (void) +{ +#ifdef ALLOCATEINPUTSTACK + input_stack = NULL; + current_stack_size = 0; + input_stack = realloc_input_stack(initial_stack_size); +#endif + +#ifdef ALLOCATENESTSTACK + nest = NULL; + current_nest_size = 0; + nest = realloc_nest_stack(initial_nest_size); +#endif + +#ifdef ALLOCATEPARAMSTACK + param_stack = NULL; + current_param_size = 0; + param_stack = realloc_param_stack(initial_param_size); +#endif + +#ifdef ALLOCATESAVESTACK + save_stack = NULL; + current_save_size = 0; + save_stack = realloc_save_stack (initial_save_size); +#endif + +#ifdef IGNORED + buffer = NULL; /* need to do earlier */ + current_buf_size = 0; + buffer = realloc_buffer (initial_buf_size); +#endif + +#ifdef ALLOCATESTRING + str_pool = NULL; + current_pool_size = 0; + str_start = NULL; + current_max_strings = 0; + +/* maybe taylor allocations to actual pool file 1300 strings 27000 bytes ? */ + if (is_initex) + { + if (trace_flag) + puts("ini TeX pool and string allocation"); + + str_pool = realloc_str_pool(initial_pool_size); + str_start = realloc_str_start(initial_max_strings); + } +#endif + +/* the following can save a lot of the usual 800k fixed allocation */ +#ifdef ALLOCATEFONT + font_info = NULL; + current_font_mem_size = 0; +/* if not iniTeX, then do initial allocation on fmt file read in itex.c */ +/* if ini-TeX we need to do it here - no format file read later */ + if (is_initex) + font_info = realloc_font_info(initial_font_mem_size); +#endif + +#ifdef ALLOCATEMAIN + main_memory = NULL; + mem = NULL; + mem_min = mem_bot; /* just to avoid complaints in texbody */ + mem_top = mem_initex; + mem_max = mem_top; +/* allocate main memory here if this is iniTeX */ +/* otherwise wait for format undumping in itex.c ... */ + if (is_initex) + { + /* avoid this if format specified on command line ??? */ + mem = allocate_main_memory(mem_initex); /* made variable ! */ + + if (mem == NULL) + return -1; + } +#endif + +/* now for the hyphenation exception stuff */ +#ifdef ALLOCATEHYPHEN + hyph_word = NULL; + hyph_list = NULL; +/* this will be overridden later by what is in format file */ + hyphen_prime = default_hyphen_prime; +/* non ini-TeX use assumes format will be read and that specifies size */ + if (is_initex) + { + if (new_hyphen_prime) + hyphen_prime = new_hyphen_prime; + + if (realloc_hyphen(hyphen_prime)) /* allocate just in case no format */ + return -1; + } +#endif + +/* now for memory for the part of the hyphenation stuff that always needed */ +/* if iniTeX, need to allocate pre-determined fixed amount - trie_size */ +/* if iniTeX not selected, allocate only enough later - undump in itex.c ! */ +#ifdef ALLOCATETRIES + if (is_initex) + { + if (allocate_tries (trie_size)) + return -1; + } +#endif + +/* now for memory for hyphenation stuff needed only when running iniTeX */ +#ifdef ALLOCATEINI + if (is_initex) + { + if (allocate_ini(trie_size)) + return -1; + } + else + { + trie_l = NULL; + trie_r = NULL; + trie_o = NULL; + trie_hash = NULL; + trie_c = NULL; + trie_taken = NULL; + } +#endif + + return 0; // success +} + +/* returns non-zero if error - done to test integrity of stack mostly */ +int free_memory (void) +{ + unsigned int heap_total = 0; + + if (trace_flag) + puts("free_memory "); + + if (verbose_flag || trace_flag) + show_maximums(stdout); + + if (trace_flag) + { + printf("Heap total: %u bytes --- max address %u\n", + heap_total, max_address); + printf("Main Memory: variable node %lld (%lld - %d);\n" + " one word %d (%d - %d)\n", + lo_mem_max - mem_min, mem_min, lo_mem_max, + mem_end - hi_mem_min, hi_mem_min, mem_end); + puts("Freeing memory again"); + } + +/* only free memory if safe ... additional check */ +#ifdef ALLOCATEINI + if (is_initex) + { + if (trie_taken != NULL) + free(trie_taken); + + if (trie_hash != NULL) + free(trie_hash); + + if (trie_r != NULL) + free(trie_r); + + if (trie_c != NULL) + free(trie_c); + + if (trie_o != NULL) + free(trie_o); + + if (trie_l != NULL) + free(trie_l); + + trie_taken = NULL; + trie_hash = NULL; + trie_l = NULL; + trie_r = NULL; + trie_c = NULL; + trie_o = NULL; + } +#endif + +#ifdef ALLOCATETRIES + if (trie_trc != NULL) + free(trie_trc); + + if (trie_tro != NULL) + free(trie_tro); + + if (trie_trl != NULL) + free(trie_trl); + + trie_trc = NULL; + trie_tro = NULL; + trie_trl = NULL; +#endif + +#ifdef ALLOCATEHYPHEN + if (hyph_list != NULL) + free(hyph_list); + + if (hyph_word != NULL) + free(hyph_word); + + hyph_list = NULL; + hyph_word = NULL; +#endif + +#ifdef ALLOCATEMAIN + if (main_memory != NULL) + free(main_memory); + + main_memory = NULL; +#endif + +#ifdef ALLOCATEFONT + if (font_info != NULL) + free(font_info); + + font_info = NULL; +#endif + +#ifdef ALLOCATESTRING + if (str_start != NULL) + free(str_start); + + if (str_pool != NULL) + free(str_pool); + + str_start = NULL; + str_pool = NULL; +#endif + +#ifdef ALLOCATEPARAMSTACK + if (param_stack != NULL) + free(param_stack); + + param_stack = NULL; +#endif + +#ifdef ALLOCATENESTSTACK + if (nest != NULL) + free(nest); + + nest = NULL; +#endif + +#ifdef ALLOCATEINPUTSTACK + if (input_stack != NULL) + free(input_stack); + + input_stack = NULL; +#endif + +#ifdef ALLOCATESAVESTACK + if (save_stack != NULL) + free(save_stack); + + save_stack = NULL; +#endif + + if (format_file != NULL) + free(format_file); + + if (source_direct != NULL) + free(source_direct); + + format_file = NULL; + source_direct = NULL; + + if (dvi_file_name != NULL) + free(dvi_file_name); + + if (log_file_name != NULL) + free(log_file_name); + + if (pdf_file_name != NULL) + free(pdf_file_name); + + pdf_file_name = NULL; + log_file_name = NULL; + dvi_file_name = NULL; + + return 0; +} + +boolean prime (int x) +{ + int k; + int sum = 1; /* 1 + 3 + 5 + k = (k + 1) * (k + 1) / 4 */ + + if (x % 2 == 0) + return false; + + for (k = 3; k < x; k = k + 2) + { + if (x % k == 0) + return false; + + if (sum * 4 > x) + return true; + + sum += k; + } + + return true; +} + +int quitflag = 0; +boolean show_use = false; + +void complainarg (int c, char *s) +{ + printf("ERROR: Do not understand `%c' argument value `%s'\n", c, s); + show_use = true; +} + +/* following is list of allowed command line flags and args */ + +char *allowedargs = "+bcdfijnpqrstvwyzABCDFGIJKLMNOPQRSTVWXYZ023456789?a=e=g=h=k=l=m=o=u=x=E=H=P=U="; + +void reorderargs (int ac, char **av) +{ + int n, m; + char *s, *t; + char takeargs[256]; /* large enough for all command line arg chars */ + + if (ac < 3) + { + return; /* no args ! */ + } + + s = allowedargs; + t = takeargs; /* list of those that take args */ + + while (*s != '\0' && *(s + 1) != '\0') + { + if (*(s + 1) == '=') + *t++ = *s++; /* copy over --- without the = */ + + s++; + } + + *t = '\0'; + + if (trace_flag) + { + show_line(takeargs, 0); + wterm_cr(); + } + + n = 1; + + for (;;) + { + if (*av[n] != '-') + break; + + if (n + 1 < ac && *(av[n] + 2) == '\0' && + strchr(takeargs, *(av[n] + 1)) != NULL) + n += 2; /* step over it */ + else + n++; + + if (n == ac) + break; + } + + for (;;) + { + if (n == ac) + break; + + m = n; + + while (m < ac && *av[m] != '-') + m++; /* first command */ + + if (m == ac) + break; +/* does it take an argument ? and is this argument next ? */ +/* check first whether the `-x' is isolated, or arg follows directly */ +/* then check whether this is one of those that takes an argument */ + if (m+1 < ac && *(av[m] + 2) == '\0' && + strchr(takeargs, *(av[m] + 1)) != NULL) + { + s = av[m]; /* move command down before non-command */ + t = av[m + 1]; + + for (; m > n; m--) + av[m + 1] = av[m - 1]; + + av[n] = s; + av[n + 1] = t; + n += 2; /* step over moved args */ + } + else + { + s = av[m]; /* move command down before non-command */ + + for (; m > n; m--) + av[m] = av[m - 1]; + + av[n] = s; + n++; /* step over moved args */ + } + } +} + +int test_align (long address, int size, const char *str) +{ + int n; + + if (size > sizeof(void *)) + n = address % sizeof(void *); + else + n = address % size; + + if (n != 0) + printf("OFFSET %d (ELEMENT %d) in %s\n", n, size, str); + + return n; +} + +/* activate detailed checking of alignment when trace_flag is set */ + +void check_fixed_align (int flag) +{ + (void) flag; + + if (test_align ((long) &mem_top, 4, "FIXED ALIGNMENT")) + { + puts("PLEASE RECOMPILE ME!"); + } + +#ifdef CHECKALIGNMENT + if (!flag) + return; + + test_align ((long) &mem_top, 4, "mem_top"); + test_align ((long) &mem_max, 4, "mem_max"); + test_align ((long) &mem_min, 4, "mem_min"); + test_align ((long) &bad, 4, "bad"); + test_align ((long) &trie_size, 4, "trie_size"); + test_align ((long) &xord, sizeof(xord[0]), "xord"); + test_align ((long) &xchr, sizeof(xchr[0]), "xchr"); + test_align ((long) &name_length, 4, "name_length"); + test_align ((long) &first, 4, "first"); + test_align ((long) &last, 4, "last"); + test_align ((long) &max_buf_stack, 4, "max_buf_stack"); + test_align ((long) &pool_ptr, 4, "pool_ptr"); + test_align ((long) &str_ptr, 4, "str_ptr"); + test_align ((long) &init_pool_ptr, 4, "init_pool_ptr"); + test_align ((long) &init_str_ptr, 4, "init_str_ptr"); + test_align ((long) &log_file, 4, "log_file"); + test_align ((long) &tally, 4, "tally"); + test_align ((long) &term_offset, 4, "term_offset"); + test_align ((long) &file_offset, 4, "file_offset"); + test_align ((long) &trick_count, 4, "trick_count"); + test_align ((long) &first_count, 4, "first_count"); + test_align ((long) &deletions_allowed, 4, "deletions_allowed"); + test_align ((long) &set_box_allowed, 4, "set_box_allowed"); + test_align ((long) &help_line, sizeof(help_line[0]), "help_line"); + test_align ((long) &use_err_help, 4, "use_err_help"); + test_align ((long) &interrupt, 4, "interrupt"); + test_align ((long) &OK_to_interrupt, 4, "OK_to_interrupt"); + test_align ((long) &arith_error, 4, "arith_error"); + test_align ((long) &tex_remainder, 4, "tex_remainder"); + test_align ((long) &temp_ptr, 4, "temp_ptr"); + test_align ((long) &lo_mem_max, 4, "lo_mem_max"); + test_align ((long) &hi_mem_min, 4, "hi_mem_min"); + test_align ((long) &var_used, 4, "var_used"); + test_align ((long) &dyn_used, 4, "dyn_used"); + test_align ((long) &avail, 4, "avail"); + test_align ((long) &mem_end, 4, "mem_end"); + test_align ((long) &mem_start, 4, "mem_start"); + test_align ((long) &rover, 4, "rover"); + test_align ((long) &font_in_short_display, 4, "font_in_short_display"); + test_align ((long) &depth_threshold, 4, "depth_threshold"); + test_align ((long) &breadth_max, 4, "breadth_max"); + test_align ((long) &nest, sizeof(nest[0]), "nest"); + // test_align ((long) &xeq_level, sizeof(xeq_level[0]), "xeq_level"); + test_align ((long) &zzzad, sizeof(zzzad[0]), "zzzad"); + // test_align ((long) &hash, sizeof(hash[0]), "hash"); + test_align ((long) &zzzae, sizeof(zzzae[0]), "zzzae"); + test_align ((long) &save_stack, sizeof(save_stack[0]), "save_stack"); + test_align ((long) &input_stack, sizeof(input_stack[0]), "input_stack"); + test_align ((long) &input_file, sizeof(input_file[0]), "input_file"); + test_align ((long) &line_stack, sizeof(line_stack[0]), "line_stack"); + test_align ((long) ¶m_stack, sizeof(param_stack[0]), "param_stack"); + test_align ((long) &cur_mark, sizeof(cur_mark[0]), "cur_mark"); + test_align ((long) &pstack, sizeof(pstack[0]), "pstack"); + test_align ((long) &read_file, sizeof(read_file[0]), "read_file"); + test_align ((long) &font_check, sizeof(font_check[0]), "font_check"); + test_align ((long) &font_size, sizeof(font_size[0]), "font_size"); + test_align ((long) &font_dsize, sizeof(font_dsize[0]), "font_dsize"); + test_align ((long) &font_params, sizeof(font_params[0]), "font_params"); + test_align ((long) &font_name, sizeof(font_name[0]), "font_name"); + test_align ((long) &font_area, sizeof(font_area[0]), "font_area"); + test_align ((long) &font_bc, sizeof(font_bc[0]), "font_bc"); + test_align ((long) &font_ec, sizeof(font_ec[0]), "font_ec"); + test_align ((long) &font_glue, sizeof(font_glue[0]), "font_glue"); + test_align ((long) &font_used, sizeof(font_used[0]), "font_used"); + test_align ((long) &hyphen_char, sizeof(hyphen_char[0]), "hyphen_char"); + test_align ((long) &skew_char, sizeof(skew_char[0]), "skew_char"); + test_align ((long) &bchar_label, sizeof(bchar_label[0]), "bchar_label"); + test_align ((long) &font_bchar, sizeof(font_bchar[0]), "font_bchar"); + test_align ((long) &font_false_bchar, sizeof(font_false_bchar[0]), "font_false_bchar"); + test_align ((long) &char_base, sizeof(char_base[0]), "char_base"); + test_align ((long) &width_base, sizeof(width_base[0]), "width_base"); + test_align ((long) &height_base, sizeof(height_base[0]), "height_base"); + test_align ((long) &depth_base, sizeof(depth_base[0]), "depth_base"); + test_align ((long) &italic_base, sizeof(italic_base[0]), "italic_base"); + test_align ((long) &lig_kern_base, sizeof(lig_kern_base[0]), "lig_kern_base"); + test_align ((long) &kern_base, sizeof(kern_base[0]), "kern_base"); + test_align ((long) &exten_base, sizeof(exten_base[0]), "exten_base"); + test_align ((long) ¶m_base, sizeof(param_base[0]), "param_base"); + test_align ((long) &total_stretch, sizeof(total_stretch[0]), "total_stretch"); + test_align ((long) &total_shrink, sizeof(total_shrink[0]), "total_shrink"); + test_align ((long) &active_width, sizeof(active_width[0]), "active_width"); + test_align ((long) &cur_active_width, sizeof(cur_active_width[0]), "cur_active_width"); + test_align ((long) &background, sizeof(background[0]), "background"); + test_align ((long) &break_width, sizeof(break_width[0]), "break_width"); + test_align ((long) &minimal_demerits, sizeof(minimal_demerits[0]), "minimal_demerits"); + test_align ((long) &best_place, sizeof(best_place[0]), "best_place"); + test_align ((long) &best_pl_line, sizeof(best_pl_line[0]), "best_pl_line"); + test_align ((long) &hc, sizeof(hc[0]), "hc"); + test_align ((long) &hu, sizeof(hu[0]), "hu"); + test_align ((long) &hyf, sizeof(hyf[0]), "hyf"); + // test_align ((long) &x, sizeof(x[0]), "x"); + test_align ((long) &hyf_distance, sizeof(hyf_distance[0]), "hyf_distance"); + test_align ((long) &hyf_num, sizeof(hyf_num[0]), "hyf_num"); + test_align ((long) &hyf_next, sizeof(hyf_next[0]), "hyf_next"); + test_align ((long) &op_start, sizeof(op_start[0]), "op_start"); + // test_align ((long) &trie_op_hash, sizeof(trie_op_hash[0]), "trie_op_hash"); + test_align ((long) &trie_used, sizeof(trie_used[0]), "trie_used"); +/* test_align ((long) &trie_op_lang, sizeof(trie_op_lang[0]), "trie_op_lang");*/ + test_align ((long) &trie_op_val, sizeof(trie_op_val[0]), "trie_op_val"); + test_align ((long) &trie_min, sizeof(trie_min[0]), "trie_min"); + test_align ((long) &page_so_far, sizeof(page_so_far[0]), "page_so_far"); + test_align ((long) &write_file, sizeof(write_file[0]), "write_file"); + test_align ((long) &write_open, sizeof(write_open[0]), "write_open"); +#endif +} + +void check_alloc_align (int flag) +{ + (void) flag; + + if (test_align((long) eqtb, sizeof(eqtb[0]), "ALLOCATED ALIGNMENT")) + puts("PLEASE RECOMPILE ME!"); + +#ifdef CHECKALIGNMENT + if (!flag) + return; + +#ifndef ALLOCZEQTB + test_align ((long) eqtb, sizeof(eqtb[0]), "eqtb"); +#endif + + test_align ((long) str_pool, sizeof(str_pool[0]), "str_pool"); /* no op */ + test_align ((long) str_start, sizeof(str_start[0]), "str_start"); + test_align ((long) mem, sizeof(mem[0]), "main memory"); + test_align ((long) font_info, sizeof(font_info[0]), "font memory"); + test_align ((long) trie_trl, sizeof(trie_trl[0]), "trie_trl"); + test_align ((long) trie_tro, sizeof(trie_tro[0]), "trie_tro"); + test_align ((long) trie_trc, sizeof(trie_trc[0]), "trie_trc"); + test_align ((long) hyph_word, sizeof(hyph_word[0]), "hyph_word"); + test_align ((long) hyph_list, sizeof(hyph_list[0]), "hyph_list"); +/* test_align ((long) trie_c, sizeof(trie_c[0]), "trie_c"); *//* no op */ + test_align ((long) trie_o, sizeof(trie_o[0]), "trie_o"); + test_align ((long) trie_l, sizeof(trie_l[0]), "trie_l"); + test_align ((long) trie_r, sizeof(trie_r[0]), "trie_r"); + test_align ((long) trie_hash, sizeof(trie_hash[0]), "trie_hash"); + test_align ((long) trie_taken, sizeof(trie_taken[0]), "trie_taken"); +#endif +} + +boolean shorten_file_name = false; /* don't shorten file names to 8+3 for DOS */ + +/* cache to prevent allocating twice in a row */ + +char * lastname = NULL; +char * lastvalue = NULL; + +/* returns allocated string -- these strings are not freed again */ +/* is it safe to do that now ? 98/Jan/31 */ +char * grabenv (const char * varname) +{ + char * s; + + if (varname == NULL) + return NULL; + + if (*varname == '\0') + return NULL; + + if (lastname != NULL && strcasecmp(lastname, varname) == 0) + { + if (trace_flag) + printf("Cache hit: %s=%s\n", lastname, lastvalue); + + return xstrdup(lastvalue); + } + + s = getenv(varname); + + if (s != NULL) + { + if (lastname != NULL) + free(lastname); + + lastname = xstrdup(varname); + + if (lastvalue != NULL) + free(lastvalue); + + lastvalue = xstrdup(s); + + return xstrdup(s); + } + else + return NULL; +} + +void flush_trailing_slash (char * directory) +{ + char * s; + + if (strcmp(directory, "") != 0) + { + s = directory + strlen(directory) - 1; + + if (*s == '\\' || *s == '/') + *s = '\0'; + } +} + +void knuthify (void) +{ + restrict_to_ascii = false; /* don't complain non ASCII */ + allow_patterns = false; /* don't allow pattern redefinition */ + show_in_hex = true; /* show character code in hex */ + show_in_dos = false; /* redundant with previous */ + show_numeric = false; /* don't show character code decimal */ + show_missing = false; /* don't show missing characters */ + civilize_flag = false; /* don't reorder date fields */ + c_style_flag = false; /* don't add file name to error msg */ + show_fmt_flag = false; /* don't show format file in log */ + show_tfm_flag = false; /* don't show metric file in log */ + tab_step = 0; + show_line_break_stats = false; /* do not show line break stats */ + show_fonts_used = false; + default_rule = 26214; /* revert to default rule thickness */ + pseudo_tilde = false; + pseudo_space = false; + truncate_long_lines = false; + allow_quoted_names = false; + show_cs_names = false; + ignore_frozen = false; + suppress_f_ligs = false; + full_file_name_flag = false; + knuth_flag = true; /* so other code can know about this */ +} + +/* following made global so analyze_flag can be made separate procedure */ + +char * xchr_file = NULL; +char * repl_file = NULL; + +const char * short_options = "m:e:h:0:H:g:P:o:l:a:r:kwvpiKLZMd2t?u"; + +static struct option long_options[] = +{ + {"main-memory", required_argument, NULL, 'm'}, + {"hyph-size", required_argument, NULL, 'e'}, + {"trie-size", required_argument, NULL, 'h'}, + {"backend", required_argument, NULL, '0'}, + {"tab-step", required_argument, NULL, 'H'}, + {"percent-grow", required_argument, NULL, 'g'}, + {"default-rule", required_argument, NULL, 'P'}, + {"dvi-dir", required_argument, NULL, 'o'}, + {"log-dir", required_argument, NULL, 'l'}, + {"aux-dir", required_argument, NULL, 'a'}, + {"key-file", required_argument, NULL, 'k'}, + {"jobname", required_argument, NULL, 'r'}, + {"showhex", no_argument, NULL, 'w'}, + {"verbose", no_argument, NULL, 'v'}, + {"patterns", no_argument, NULL, 'p'}, + {"initex", no_argument, NULL, 'i'}, + {"knuthify", no_argument, NULL, 'K'}, + {"cstyle", no_argument, NULL, 'L'}, + {"showtfm", no_argument, NULL, 'Z'}, + {"showmissing", no_argument, NULL, 'M'}, + {"deslash", no_argument, NULL, 'd'}, + {"suppressflig", no_argument, NULL, '2'}, + {"trace", no_argument, NULL, 't'}, + {"help", no_argument, NULL, '?'}, + {"usage", no_argument, NULL, 'u'}, + {NULL, 0, 0, 0} +}; + +int analyze_flag (int c, char * optarg) +{ + switch (c) + { + case 'r': + c_job_name = optarg; + break; + case 'v': + verbose_flag = true; + break; + case 'i': + is_initex = true; + break; + case 'Q': + interaction = batch_mode; + break; + case 'R': + interaction = nonstop_mode; + break; + case 'S': + interaction = scroll_mode; + break; + case 'T': + interaction = error_stop_mode; + break; + case 'K': + knuthify(); + break; + case 'L': + c_style_flag = true; + break; + case 'Z': + show_tfm_flag = true; + break; + case 'M': + show_missing = false; + break; + case 'd': + deslash = false; + break; + case 'p': + allow_patterns = true; + break; + case 'w': + show_in_hex = true; + break; + case 'j': + show_in_dos = true; + break; + case 'n': + restrict_to_ascii = true; /* 0 - 127 1994/Jan/21 */ + break; + case 'f': + show_fonts_used = false; + break; + case '8': + shorten_file_name = true; + break; + case '9': + show_cs_names = true; + break; + case '4': + ignore_frozen = true; + break; + case 'J': + show_line_break_stats = false; /* 96/Feb/8 */ + break; + case 'O': + show_fmt_flag = false; /* 94/Jun/21 */ + break; + case '2': + suppress_f_ligs = true; /* 99/Jan/5 f-lig */ + break; + case 'z': + full_file_name_flag = false; // 00 Jun 18 + break; + case 't': + trace_flag = true; + break; + case 'q': + quitflag++; /* 93/Dec/16 */ + break; +/* The following are really obscure and should not be advertized */ + case 's': + show_current = false; + break; + case 'N': + show_numeric = false; + break; + case 'A': + civilize_flag = false; + break; + case 'B': + open_trace_flag = true; + break; + case 'Y': + reorder_arg_flag = false; /* local */ + break; + + case 'm': + if (optarg == 0) + mem_initex = mem_top; + else + mem_initex = atoi(optarg) * 1024; + + if (mem_initex == 0) + complainarg(c, optarg); + + mem_spec_flag = true; + break; + +#ifdef VARIABLETRIESIZE + case 'h': + if (optarg == 0) + { + //trie_size = atoi(kpse_var_value("trie_size")); + trie_size = default_trie_size; + } + else + trie_size = atoi(optarg); + + if (trie_size == 0) + complainarg(c, optarg); + break; +#endif + +#ifdef ALLOCATEHYPHEN + case 'e': + if (optarg == 0) + new_hyphen_prime = hyphen_prime * 2; + else + new_hyphen_prime = atoi(optarg); + + if (new_hyphen_prime == 0) + complainarg(c, optarg); + + break; +#endif + case 'g': + if (optarg == 0) + percent_grow = 62; + else + percent_grow = atoi(optarg); + + if (percent_grow == 0) + complainarg(c, optarg); + + break; + + case 'U': + if (optarg == 0) + pseudo_tilde = 0; + else + pseudo_tilde = atoi(optarg); + + if (pseudo_tilde > 255) + pseudo_tilde = 255; + else if (pseudo_tilde < 128) + pseudo_tilde = 128; + + break; + + case 'H': + if (optarg == 0) + tab_step = 8; + else + tab_step = atoi(optarg); + if (tab_step == 0) + complainarg(c, optarg); + break; + + case 'x': + if (optarg == 0) + xchr_file = xstrdup("xchr.map"); + else + xchr_file = xstrdup(optarg); + + if (xchr_file == NULL || *xchr_file == '\0') + complainarg(c, optarg); + break; + + case 'k': + if (optarg == 0) + repl_file = xstrdup("repl.key"); + else + repl_file = xstrdup(optarg); + + if (repl_file == NULL || *repl_file == '\0') + complainarg(c, optarg); + break; + + case 'P': + if (optarg == 0) + default_rule = 26214; + else + default_rule = atoi(optarg); + + if (default_rule == 0) + complainarg(c, optarg); + break; + + case 'E': + if (optarg != 0) + putenv(optarg); + else + complainarg(c, optarg); + break; + + case 'o': + if (optarg == 0) + dvi_directory = ""; + else + dvi_directory = xstrdup(optarg); + + if (strcmp(dvi_directory, "") == 0) + complainarg(c, optarg); + + break; + + case 'l': + if (optarg == 0) + log_directory = ""; + else + log_directory = xstrdup(optarg); + + if (strcmp(log_directory, "") == 0) + complainarg(c, optarg); + + break; + + case 'a': + if (optarg == 0) + aux_directory = ""; + else + aux_directory = xstrdup(optarg); + + if (strcmp(aux_directory, "") == 0) + complainarg(c, optarg); + + break; + + case '?': + default: + show_use = true; + return -1; + break; + } + + return 0; +} + +void strip_name (char *pathname) +{ + char *s; + + if ((s = strrchr(pathname, '\\')) != NULL) + ; + else if ((s = strrchr(pathname, '/')) != NULL) + ; + else if ((s = strrchr(pathname, ':')) != NULL) + s++; + else + s = pathname; + + *s = '\0'; +} + +int read_command_line (int ac, char **av) +{ + int c; + char *optargnew; + int option_idx = 0; + + if (ac < 2) + return 0; + + while ((c = getopt_long_only(ac, av, short_options, long_options, &option_idx)) != EOF) + { + if (optarg != 0 && *optarg == '=') + optargnew = optarg + 1; + else + optargnew = optarg; + + analyze_flag(c, optargnew); + } + + if (show_use || quitflag == 3) + { + stamp_it(log_line); + strcat(log_line, "\n"); + show_line(log_line, 0); + + if (show_use) + show_usage(); + else if (quitflag == 3) + { + strcat(log_line, "\n"); + show_line(log_line, 0); + } + + return -1; // failure + } + + if (repl_file != NULL && *repl_file != '\0') + { + if (read_xchr_file(repl_file, 1, av)) + { + if (trace_flag) + puts("KEY REPLACE ON"); + + key_replace = true; + } + } + + if (xchr_file != NULL && *xchr_file != '\0') + { + if (read_xchr_file(xchr_file, 0, av)) + { + if (trace_flag) + puts("NON ASCII ON"); + + non_ascii = true; + } + } + + return 0; +} + +int init_commands (int ac, char **av) +{ + shipout_flag = out_dvi_flag; + is_initex = false; + allow_patterns = false; + reset_exceptions = false; + non_ascii = false; + key_replace = false; + open_trace_flag = false; + trace_flag = false; + verbose_flag = false; + restrict_to_ascii = false; + show_in_hex = false; /* default is not to show as hex code ^^ 00/Jun/18 */ + show_in_dos = false; /* default is not to translate to DOS 850 */ + return_flag = true; // hard wired now + trimeof = true; // hard wired now + deslash = true; + pseudo_tilde = 254; /* default '~' replace 95/Sep/26 filledbox DOS 850 */ + pseudo_space = 255; /* default ' ' replace 97/June/5 nbspace DOS 850 */ + default_rule = 26214; + show_current = true; + civilize_flag = true; + show_numeric = true; + show_missing = true; + c_style_flag = false; + show_fmt_flag = true; + show_tfm_flag = false; /* don't show metric file in log */ + shorten_file_name = false; /* don't shorten file names to 8+3 */ + truncate_long_lines = true; /* truncate long lines */ + tab_step = 0; /* do not replace tabs with spaces */ + show_line_break_stats = true; /* show line break statistics 96/Feb/8 */ + show_fonts_used = true; /* show fonts used in LOG file 97/Dec/24 */ + allow_quoted_names = true; /* allow quoted names with spaces 98/Mar/15 */ + show_cs_names = false; + knuth_flag = false; + full_file_name_flag = true; /* new default 2000 June 18 */ + errout = stdout; /* as opposed to stderr say --- used ??? */ + new_hyphen_prime = 0; + +#ifdef VARIABLETRIESIZE + // trie_size = default_trie_size; + trie_size = 0; +#endif + + mem_extra_high = 0; + mem_extra_low = 0; + mem_initex = 0; + format_name = "plain"; + + if (read_command_line(ac, av) < 0) + return -1; + + if (optind == 0) + optind = ac; + + return 0; +} + +void initial_memory (void) +{ + /* set initial memory allocations */ + if (mem_extra_high < 0) + mem_extra_high = 0; + + if (mem_extra_low < 0) + mem_extra_low = 0; + + if (mem_initex < 0) + mem_initex = 0; + + if (is_initex) + { + #if defined(ALLOCATEHIGH) || defined(ALLOCATELOW) + if (mem_extra_high != 0 || mem_extra_low != 0) + { + puts("ERROR: Cannot extend main memory in initex"); + mem_extra_high = 0; + mem_extra_low = 0; + } +#endif + } + else + { + if (mem_initex != 0) + { + puts("ERROR: Can only set initial main memory size in initex"); + mem_initex = 0; + } + + if (trie_size != 0) + { + puts("ERROR: Need only set hyphenation trie size in initex"); +/* trie_size = 0; */ + } + } + if (mem_initex == 0) + mem_initex = default_mem_top; + + if (trie_size == 0) + trie_size = default_trie_size; + +/* Just in case user mistakenly specified words instead of kilo words */ + if (mem_extra_high > 10000L * 1024L) + mem_extra_high = mem_extra_high / 1024; + + if (mem_extra_low > 10000L * 1024L) + mem_extra_low = mem_extra_low / 1024; + + if (mem_initex > 10000L * 1024L) + mem_initex = mem_initex / 1024; + + if (mem_initex > 2048L * 1024L) /* extend main memory by 16 mega byte! */ + { + puts("WARNING: There may be no benefit to asking for so much memory"); +/* mem_initex = 2048 * 1024; */ + } + + if (new_hyphen_prime < 0) + new_hyphen_prime = 0; + + if (new_hyphen_prime > 0) + { + if (! is_initex) + puts("ERROR: Can only set hyphen prime in initex"); + else + { + if (new_hyphen_prime % 2 == 0) + new_hyphen_prime++; + + while (!prime(new_hyphen_prime)) + new_hyphen_prime = new_hyphen_prime + 2; + + if (trace_flag) + printf("Using %d as hyphen prime\n", new_hyphen_prime); + } + } + + if (percent_grow > 100) + percent_grow = percent_grow - 100; + + if (percent_grow > 100) + percent_grow = 100; /* upper limit - double */ + + if (percent_grow < 10) + percent_grow = 10; /* lower limit - 10% */ +} + +void perrormod (const char * s) +{ + printf("`%s': %s\n", s, strerror(errno)); +} + +/* convert tilde to pseudo_tilde to hide it from TeX --- 95/Sep/26 */ +/* convert space to pseudo_space to hide it from TeX --- 97/Jun/5 */ +/* called only if pseudo_tilde != 0 or pseudo_space != 0 */ +/* this is then undone in tex3.c both for fopen input and output */ +/* not ideal, since pseudo name appears in log and in error messages ... */ + +void hidetwiddle (char *tname) +{ + char *s = tname; + +#ifdef DEBUGTWIDDLE + if (trace_flag) + printf("Hidetwiddle %s", tname); +#endif + + while (*s != '\0') + { + if (*s == '~' && pseudo_tilde != 0) + *s = (char) pseudo_tilde; /* typically 254 */ + else if (*s == ' ' && pseudo_space != 0) + *s = (char) pseudo_space; /* typically 255 */ + s++; + } + +#ifdef DEBUGTWIDDLE + if (trace_flag) + printf("=> %s\n", tname); +#endif +} + +void deslash_all (int ac, char **av) +{ + char buffer[file_name_size]; + char *s; + + if ((s = grabenv("TEXDVI")) != NULL) + dvi_directory = s; + + if ((s = grabenv("TEXLOG")) != NULL) + log_directory = s; + + if ((s = grabenv("TEXAUX")) != NULL) + aux_directory = s; + + if ((s = grabenv("TEXFMT")) != NULL) + fmt_directory = s; + + if ((s = grabenv("TEXPDF")) != NULL) + pdf_directory = s; + + strcpy(buffer, av[0]); + + if ((s = strrchr(buffer, '\\')) != NULL) + *(s + 1) = '\0'; + else if ((s = strrchr(buffer, '/')) != NULL) + *(s + 1) = '\0'; + else if ((s = strrchr(buffer, ':')) != NULL) + *(s + 1) = '\0'; + + s = buffer + strlen(buffer) - 1; + + if (*s == '\\' || *s == '/') + *s = '\0'; + + if (strcmp(dvi_directory, "") != 0) + flush_trailing_slash(dvi_directory); + + if (strcmp(log_directory, "") != 0) + flush_trailing_slash(log_directory); + + if (strcmp(aux_directory, "") != 0) + flush_trailing_slash(aux_directory); + + if (strcmp(fmt_directory, "") != 0) + flush_trailing_slash(fmt_directory); + + if (strcmp(pdf_directory, "") != 0) + flush_trailing_slash(pdf_directory); + + if (deslash) + { + if (strcmp(dvi_directory, "") != 0) + unixify(dvi_directory); + + if (strcmp(log_directory, "") != 0) + unixify(log_directory); + + if (strcmp(aux_directory, "") != 0) + unixify(aux_directory); + + if (strcmp(fmt_directory, "") != 0) + unixify(fmt_directory); + + if (strcmp(pdf_directory, "") != 0) + unixify(pdf_directory); + } + + format_spec = false; + + if (optind < ac && optind > 0) + { + if (deslash) + { + if (trace_flag) + printf("deslash: k %d argv[k] %s (argc %d)\n", optind, av[optind], ac); + + unixify(av[optind]); + } + + if (pseudo_tilde != 0 || pseudo_space != 0) + hidetwiddle(av[optind]); + + if (*av[optind] == '&' || *av[optind] == '+') + { + format_spec = true; + format_name = xstrdup(av[optind] + 1); + + if (optind + 1 < ac) + { + if (deslash) + { + if (trace_flag) + printf("deslash: k %d argv[k] %s (argc %d)\n", optind + 1, av[optind + 1], ac); + + unixify(av[optind + 1]); + } + + if (pseudo_tilde != 0 || pseudo_space != 0) + hidetwiddle(av[optind + 1]); + } + } + } +} + +int main_init (int ac, char ** av) +{ + kpse_set_program_name(av[0], "dvipdfmx"); + xputenv("engine", "yandytex"); + + if (sizeof(memory_word) != sizeof(halfword) * 2) + printf("ERROR: Bad word size %ld!\n", sizeof(memory_word)); + + start_time = clock(); + main_time = start_time; + +/* reset all allocatable memory pointers to NULL - in case we drop out */ + main_memory = NULL; + font_info = NULL; + str_pool = NULL; + str_start = NULL; + +#ifdef ALLOCATESAVESTACK + save_stack = NULL; +#endif + +#ifdef ALLOCATEBUFFER + buffer = NULL; + current_buf_size = 0; + buffer = realloc_buffer(initial_buf_size); +#endif + + hyph_list = NULL; + hyph_word = NULL; + trie_taken = NULL; + trie_hash = NULL; + trie_r = NULL; + trie_c = NULL; + trie_o = NULL; + trie_l = NULL; + trie_trc = NULL; + trie_tro = NULL; + trie_trl = NULL; + + log_opened = false; /* so can tell whether opened */ + interaction = -1; /* default state => 3 */ + missing_characters = 0; /* none yet! */ + ignore_frozen = false; /* default is not to ignore 98/Oct/5 */ + suppress_f_ligs = false; /* default is not to ignore f-ligs */ + + if (ac > 1 && !strncmp(av[1], "-Y", 2)) + reorder_arg_flag = false; + + if (reorder_arg_flag) + reorderargs(ac, av); + + if (init_commands(ac, av)) + return -1; + + check_fixed_align(trace_flag); + + format_file = NULL; + source_direct = NULL; + dvi_file_name = NULL; + log_file_name = NULL; + pdf_file_name = NULL; + + first_pass_count = 0; + second_pass_count = 0; + final_pass_count = 0; + paragraph_failed = 0; + single_line = 0; + overfull_hbox = 0; + underfull_hbox = 0; + overfull_vbox = 0; + underfull_vbox = 0; + + if (trace_flag) + puts("Entering main_init() (local.c)."); + + probe_memory(); + ini_max_address = max_address; + + if (trace_flag) + show_maximums(stdout); + + initial_memory(); + deslash_all(ac, av); + + if (format_spec && mem_spec_flag) + puts("WARNING: Cannot change initial main_memory size when format specified"); + + if (allocate_memory() != 0) + return -1; + + check_alloc_align(trace_flag); + + if (trace_flag) + puts("Leaving main_init() (local.c)."); + + return 0; +} + +#define CLK_TCK CLOCKS_PER_SEC + +void show_inter_val (clock_t inter_val) +{ + int seconds, tenths, hundredth, thousands; + + if (inter_val >= CLK_TCK * 10) + { + tenths = (inter_val * 10 + CLK_TCK / 2) / CLK_TCK; + seconds = tenths / 10; + tenths = tenths % 10; + printf("%d.%d", seconds, tenths); + } + else if (inter_val >= CLK_TCK) + { + hundredth = (inter_val * 100 + CLK_TCK / 2) / CLK_TCK; + seconds = hundredth / 100; + hundredth = hundredth % 100; + printf("%d.%02d", seconds, hundredth); + } + else if (inter_val > 0) + { + thousands = (inter_val * 1000 + CLK_TCK / 2) / CLK_TCK; + seconds = thousands / 1000; + thousands = thousands % 1000; + printf("%d.%03d", seconds, thousands); + } + else + show_line("0", 0); +} + +int endit(int flag) +{ + finish_time = clock(); + + if (missing_characters != 0) + flag = 1; + + if (missing_characters) + printf("! There %s %d missing character%s --- see log file\n", + (missing_characters == 1) ? "was" : "were", missing_characters, + (missing_characters == 1) ? "" : "s"); + + if (free_memory() != 0) + flag++; + + if (verbose_flag) + { + printf("Total "); + show_inter_val(finish_time - start_time); + printf(" sec ("); + show_inter_val(main_time - start_time); + printf(" format load + "); + show_inter_val(finish_time - main_time); + printf(" processing) "); + + if (total_pages > 0) + { + show_inter_val((finish_time - main_time) / total_pages); + printf(" sec per page.\n"); + } + } + + return flag; +} +// printf control sequences' name +void print_cs_name (FILE * output, int h) +{ + int c, textof, n; + + memset(log_line, 0, sizeof(log_line)); + + textof = hash[h].rh; + + if (textof == 0) + return; + + c = sprintf(log_line, "(%d), ", h); + n = length(textof); + + memmove(log_line + c, str_pool + str_start[textof], n); + memmove(log_line + c + n, "\n", 2); + + if (output == stderr) + show_line(log_line, 1); + else if (output == stdout) + show_line(log_line, 0); + else + fprintf(output, "%s", log_line); +} +// prototype +int compare_strn (int, int, int, int); +/* compare two csnames in qsort */ +int compare_cs (const void *cp1, const void *cp2) +{ + int c1, c2, l1, l2, k1, k2, textof1, textof2; + + c1 = *(int *)cp1; + c2 = *(int *)cp2; + textof1 = hash[c1].rh; + textof2 = hash[c2].rh; + l1 = length(textof1); + l2 = length(textof2); + k1 = str_start[textof1]; + k2 = str_start[textof2]; + + return compare_strn(k1, l1, k2, l2); +} + +char * csused = NULL; + +/* Allocate table of indeces to allow sorting on csname */ +/* Allocate flags to remember which ones already listed at start */ +/* pass = 0 --> fmt */ +/* pass = 1 --> after */ +void print_cs_names (FILE *output, int pass) +{ + int h, k, ccount, repeatflag; + int *cnumtable; + int nfcs = frozen_control_sequence; + + if (pass == 0 && csused == NULL) + { + csused = (char *) malloc (nfcs); + + if (csused == NULL) + return; + +#ifdef USEMEMSET + memset(csused, 0, nfcs); +#else + for (h = 0; h < (hash_size + 780); h++) + csused[h] = 0; +#endif + } + + ccount = 0; + + for (h = hash_base + 1; h < nfcs; h++) + { + if (pass == 1 && csused[h]) + continue; + + if (text(h) != 0) + { + if (pass == 0) + csused[h] = 1; + + ccount++; + } + } + + sprintf(log_line, "\n%d %s multiletter control sequences:\n", + ccount, (pass == 1) ? "new" : ""); + + if (output == stderr) + show_line(log_line, 1); + else if (output == stdout) + show_line(log_line, 0); + else + fprintf(output, "%s", log_line); + + if (ccount > 0) + { + cnumtable = (int *) malloc (ccount * sizeof(int)); + + if (cnumtable == NULL) + return; + + ccount = 0; + + for (h = hash_base + 1; h < nfcs; h++) + { + if (pass == 1 && csused[h]) + continue; + + if (hash[h].rh != 0) + cnumtable[ccount++] = h; + } + + //qsort ((void *)cnumtable, ccount, sizeof (int), &compare_cs); + + repeatflag = 0; + + for (k = 0; k < ccount; k++) + { + h = cnumtable[k]; + + if (pass == 1 && csused[h]) + continue; + + print_cs_name(output, h); + } + + sprintf(log_line, "\n"); + + if (output == stderr) + show_line(log_line, 1); + else if (output == stdout) + show_line(log_line, 0); + else + fprintf(output, "%s", log_line); + + free((void *)cnumtable); + } + + if (pass == 1 && csused != NULL) + { + free(csused); + csused = NULL; + } +} + +/* k1 and k2 are positions in string pool */ +/* l1 and l2 are lengths of strings */ +int compare_strn (int k1, int l1, int k2, int l2) +{ + int c1, c2; + + while (l1 > 0 && l2 > 0) + { + c1 = str_pool[k1]; + c2 = str_pool[k2]; + + if (c1 > c2) + return 1; + else if (c2 > c1) + return -1; + + l1--; l2--; + k1++; k2++; + } + + if (l1 > 0) + return 1; /* first string longer */ + else if (l2 > 0) + return -1; /* second string longer */ + + return 0; /* strings match */ +} +/* compare two font names and their at sizes in qsort */ +int compare_fnt (const void * fp1, const void * fp2) +{ + int f1, f2, l1, l2, k1, k2, s; + + f1 = *(short *)fp1; + f2 = *(short *)fp2; + l1 = length(font_name[f1]); + l2 = length(font_name[f2]); + k1 = str_start[font_name[f1]]; + k2 = str_start[font_name[f2]]; + + s = compare_strn (k1, l1, k2, l2); + + if (s != 0) + return s; + + if (font_size[f1] > font_size[f2]) + return 1; + else if (font_size[f1] < font_size[f2]) + return -1; + + return 0; /* should not ever get here */ +} +/* compare two font names */ +int compare_fnt_name (int f1, int f2) +{ + int l1, l2, k1, k2, s; + + l1 = length(font_name[f1]); + l2 = length(font_name[f2]); + k1 = str_start[font_name[f1]]; + k2 = str_start[font_name[f2]]; + + s = compare_strn (k1, l1, k2, l2); + + return s; +} +/* decode checksum information */ +const unsigned long checkdefault = 0x59265920; +int decode_fourty (unsigned long checksum, char *codingvector) +{ + int c; + int k; + + if (checksum == 0) + { + strcpy(codingvector, "unknwn"); + return 1; + } + else if ((checksum >> 8) == (checkdefault >> 8)) + { + strcpy (codingvector, "fixed "); + return 1; + } + else + { + for (k = 0; k < 6; k++) + { + c = (int) (checksum % 40); + checksum = checksum / 40; + + if (c <= 'z' - 'a') + c = c + 'a'; + else if (c < 36) + c = (c + '0') - ('z' - 'a') - 1; + else if (c == 36) + c = '-'; + else if (c == 37) + c = '&'; + else if (c == 38) + c = '_'; + else + c = '.'; + + codingvector[5-k] = (char) c; + } + + codingvector[6] = '\0'; + } + + return 0; +} + +double sclpnt (long x) +{ + double pt; + + pt = (double) x / 65536.0; + pt = (double) ((int) (pt * 1000.0 + 0.5)) / 1000.0; + + return (pt); +} + +void dvi_font_show (internal_font_number f, int suppressname) +{ + int a, l, k, n; + unsigned long checksum; + char checksumvector[8]; + char buffer[32]; + + putc(' ', log_file); + + if (suppressname == 0) + { + a = length(font_area[f]); + l = length(font_name[f]); + + k = str_start[font_area[f]]; + + memcpy(buffer, str_pool + k, length(font_area[f])); + fwrite(buffer, sizeof(char), length(font_area[f]), log_file); + + k = str_start[font_name[f]]; + + memcpy(buffer, str_pool + k, length(font_name[f])); + fwrite(buffer, sizeof(char), length(font_name[f]), log_file); + } + else a = l = 0; + + for (k = a + l; k < 16; k++) + putc(' ', log_file); + + sprintf(buffer, "at %lgpt ", sclpnt(font_size[f])); + fputs(buffer, log_file); + + if (suppressname == 0) + { + n = strlen(buffer); + + for (k = n; k < 16; k++) + putc(' ', log_file); + + checksum = (((font_check[f].b0) << 8 | font_check[f].b1) << 8 | font_check[f].b2) << 8 | font_check[f].b3; + decode_fourty(checksum, checksumvector); + fprintf(log_file, "encoding: %s..", checksumvector); + } + + putc('\n', log_file); +} +/* Allocate table of indeces to allow sorting on font name */ +void show_font_info (void) +{ + int k, m, fcount, repeatflag; + short *fnumtable; + + fcount = 0; + + for (k = 1; k <= font_ptr; k++) + if (font_used[k]) + fcount++; + + if (fcount == 0) + return; + + fnumtable = (short *) malloc(fcount * sizeof(short)); + + fprintf(log_file, "\nUsed %d font%s:\n", fcount, (fcount == 1) ? "" : "s"); + + fcount = 0; + + for (k = 1; k <= font_ptr; k++) + if (font_used[k]) + fnumtable[fcount++] = (short) k; + + qsort ((void *)fnumtable, fcount, sizeof(short), &compare_fnt); + + repeatflag = 0; + + for (m = 0; m < fcount; m++) + { + if (m > 0) + { + if (compare_fnt_name(fnumtable[m - 1], fnumtable[m]) == 0) + repeatflag = 1; + else + repeatflag = 0; + } + + dvi_font_show(fnumtable[m], repeatflag); + } + + free((void *)fnumtable); +} diff --git a/src/texsourc/macros.h b/src/texsourc/macros.h index 3823bc9..b10dd3f 100644 --- a/src/texsourc/macros.h +++ b/src/texsourc/macros.h @@ -1,1652 +1,1652 @@ -/* Copyright 2014 Clerk Ma - - 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ -#ifndef _YANDYTEX_MACROS_H -#define _YANDYTEX_MACROS_H - -#define font_base 0 -/* sec 0022 */ -#define null_code 0 // 0 -#define carriage_return 015 // 13 -#define invalid_code 0177 // 127 -/* sec 0036 */ -#define loc cur_input.loc_field -/* sec 0040 */ -#define length(s) (str_start[(s) + 1] - str_start[(s)]) -/* sec 0041 */ -#define cur_length (pool_ptr - str_start[str_ptr]) -/* sec 0054 */ -enum -{ - no_print = 16, - term_only = 17, - log_only = 18, - term_and_log = 19, - pseudo = 20, - new_string = 21, - max_selector = 21, -}; -/* sec 0073 */ -enum -{ - batch_mode = 0, - nonstop_mode = 1, - scroll_mode = 2, - error_stop_mode = 3, -}; -/* sec 0076 */ -enum -{ - spotless = 0, - warning_issued = 1, - error_message_issued = 2, - fatal_error_stop = 3, -}; -/* sec 0096 */ -#define check_interrupt() \ -do \ -{ \ - if (interrupt != 0) \ - pause_for_instructions(); \ -} \ -while (0) -/* sec 0101 */ -#define unity 0200000 -#define two 0400000 -/* sec 0105 */ -#define nx_plus_y(a, b, c) mult_and_add(a, b, c, 07777777777L) -#define mult_integers(a, b) mult_and_add(a, b, 0, 017777777777L) -/* sec 0108 */ -#define inf_bad 10000L -/* sec 0109 */ -#define set_glue_ratio_zero(a) (a) = 0.0 -#define set_glue_ratio_one(a) (a) = 1.0 -#define tex_float(a) (a) -#define unfloat(a) (a) -#define float_constant(a) (float) (a) -/* sec 0115 */ -//#define pointer halfword -#define null min_halfword -/* sec 0118 */ -#define link(p) mem[p].hh.rh -#define info(p) mem[p].hh.lh -/* sec 0122 */ -#ifdef STAT -#define fast_get_avail(a) \ - do \ - { \ - a = avail; \ - \ - if (a == 0) \ - a = get_avail(); \ - else \ - { \ - avail = link(a); \ - link(a) = 0; \ - incr(dyn_used); \ - } \ - } \ - while (0) -#else -#define fast_get_avail(a) \ - do \ - { \ - a = avail; \ - \ - if (a == 0) \ - a = get_avail(); \ - else \ - { \ - avail = link(a); \ - link(a) = 0; \ - } \ - } \ - while (0) -#endif -/* sec 0124 */ -#define empty_flag max_halfword -#define is_empty(a) (link(a) == empty_flag) -#define node_size info -#define llink(a) info(a+1) -#define rlink(a) link(a+1) -/* sec 0133 */ -#define type(a) mem[a].hh.b0 -#define subtype(a) mem[a].hh.b1 -/* sec 0134 */ -#define is_char_node(a) (a >= hi_mem_min) -#define font type -#define character subtype -/* sec 0135 */ -#define hlist_node 0 -#define box_node_size 7 -#define width_offset 1 -#define depth_offset 2 -#define height_offset 3 -#define width(a) mem[a + width_offset].cint -#define depth(a) mem[a + depth_offset].cint -#define height(a) mem[a + height_offset].cint -#define shift_amount(a) mem[a + 4].cint -#define list_offset 5 -#define list_ptr(a) link(a + list_offset) -#define glue_order(a) subtype(a + list_offset) -#define glue_sign(a) type(a + list_offset) -#define normal 0 -#define stretching 1 -#define shrinking 2 -#define glue_offset 6 -#define glue_set(a) mem[a + glue_offset].gr -/* sec 0137 */ -#define vlist_node 1 -/* sec 0138 */ -#define rule_node 2 -#define rule_node_size 4 -#define null_flag -010000000000L -#define is_running(a) (a == null_flag) -/* sec 0140 */ -#define ins_node 3 -#define ins_node_size 5 -#define float_cost(a) mem[a + 1].cint -#define ins_ptr(a) info(a + 4) -#define split_top_ptr(a) link(a + 4) -/* sec 0141 */ -#define mark_node 4 -#define small_node_size 2 -#define mark_ptr(a) mem[a + 1].cint -/* sec 0142 */ -#define adjust_node 5 -#define adjust_ptr mark_ptr -/* sec 0143 */ -#define ligature_node 6 -#define lig_char(a) (a + 1) -#define lig_ptr(a) link(lig_char(a)) -/* sec 0145 */ -#define disc_node 7 -#define replace_count subtype -#define pre_break llink -#define post_break rlink -/* sec 0146 */ -#define whatsit_node 8 -/* sec 0147 */ -#define math_node 9 -#define before 0 -#define after 1 -/* sec 0148 */ -#define precedes_break(a) (type(a) < math_node) -#define non_discardable(a) (type(a) < math_node) -/* sec 0149 */ -#define glue_node 10 -#define cond_math_glue 98 -#define mu_glue 99 -#define a_leaders 100 -#define c_leaders 101 -#define x_leaders 102 -#define glue_ptr llink -#define leader_ptr rlink -/* sec 0150 */ -#define glue_spec_size 4 -#define glue_ref_count(a) link(a) -#define stretch(a) mem[a + 2].cint -#define shrink(a) mem[a + 3].cint -#define stretch_order type -#define shrink_order subtype -#define fil 1 -#define fill 2 -#define filll 3 -/* sec 0155 */ -#define kern_node 11 -#define explicit 1 -#define acc_kern 2 -/* sec 0157 */ -#define penalty_node 12 -#define inf_penalty inf_bad -#define eject_penalty -inf_bad -#define penalty(a) mem[a + 1].cint -/* sec 0159 */ -#define unset_node 13 -#define glue_stretch(a) mem[a + glue_offset].cint -#define glue_shrink shift_amount -#define span_count subtype -/* sec 0162 */ -#define zero_glue mem_bot // 0 -#define fil_glue (zero_glue + glue_spec_size) // 4 -#define fill_glue (fil_glue + glue_spec_size) // 8 -#define ss_glue (fill_glue + glue_spec_size) // 12 -#define fil_neg_glue (ss_glue + glue_spec_size) // 16 -#define lo_mem_stat_max (fil_neg_glue + glue_spec_size - 1) // 19 -#define page_ins_head mem_top -#define contrib_head (mem_top - 1) -#define page_head (mem_top - 2) -#define temp_head (mem_top - 3) -#define hold_head (mem_top - 4) -#define adjust_head (mem_top - 5) -#define active (mem_top - 7) -#define align_head (mem_top - 8) -#define end_span (mem_top - 9) -#define omit_template (mem_top - 10) -#define null_list (mem_top - 11) -#define lig_trick (mem_top - 12) -#define garbage (mem_top - 12) -#define backup_head (mem_top - 13) -#define hi_mem_stat_min (mem_top - 13) -#define hi_mem_stat_usage 14 -/* sec 0200 */ -#define token_ref_count(a) info(a) -/* sec 0203 */ -#define add_token_ref(a) incr(token_ref_count(a)) -#define add_glue_ref(a) incr(glue_ref_count(a)) -/* sec 0207 */ -#define escape 0 -#define relax 0 -#define left_brace 1 -#define right_brace 2 -#define math_shift 3 -#define tab_mark 4 -#define car_ret 5 -#define out_param 5 -#define mac_param 6 -#define sup_mark 7 -#define sub_mark 8 -#define ignore 9 -#define endv 9 -#define spacer 10 -#define letter 11 -#define other_char 12 -#define active_char 13 -#define par_end 13 -#define match 13 -#define comment 14 -#define end_match 14 -#define stop 14 -#define invalid_char 15 -#define delim_num 15 -#define max_char_code 15 -/* sec 0208 */ -#define char_num 16 -#define math_char_num 17 -#define mark 18 -#define xray 19 -#define make_box 20 -#define hmove 21 -#define vmove 22 -#define un_hbox 23 -#define un_vbox 24 -#define remove_item 25 -#define hskip 26 -#define vskip 27 -#define mskip 28 -#define kern 29 -#define mkern 30 -#define leader_ship 31 -#define halign 32 -#define valign 33 -#define no_align 34 -#define vrule 35 -#define hrule 36 -#define insert 37 -#define vadjust 38 -#define ignore_spaces 39 -#define after_assignment 40 -#define after_group 41 -#define break_penalty 42 -#define start_par 43 -#define ital_corr 44 -#define accent 45 -#define math_accent 46 -#define discretionary 47 -#define eq_no 48 -#define left_right 49 -#define math_comp 50 -#define limit_switch 51 -#define above 52 -#define math_style 53 -#define math_choice 54 -#define non_script 55 -#define vcenter 56 -#define case_shift 57 -#define message 58 -#define extension 59 -#define in_stream 60 -#define begin_group 61 -#define end_group 62 -#define omit 63 -#define ex_space 64 -#define no_boundary 65 -#define radical 66 -#define end_cs_name 67 -#define min_internal 68 -#define char_given 68 -#define math_given 69 -#define last_item 70 -#define max_non_prefixed_command 70 -/* sec 0209 */ -#define toks_register 71 -#define assign_toks 72 -#define assign_int 73 -#define assign_dimen 74 -#define assign_glue 75 -#define assign_mu_glue 76 -#define assign_font_dimen 77 -#define assign_font_int 78 -#define set_aux 79 -#define set_prev_graf 80 -#define set_page_dimen 81 -#define set_page_int 82 -#define set_box_dimen 83 -#define set_shape 84 -#define def_code 85 -#define def_family 86 -#define set_font 87 -#define def_font 88 -#define tex_register 89 -#define max_internal 89 -#define advance 90 -#define multiply 91 -#define divide 92 -#define prefix 93 -#define let 94 -#define shorthand_def 95 -#define read_to_cs 96 -#define def 97 -#define set_box 98 -#define hyph_data 99 -#define set_interaction 100 -#define max_command 100 -/* sec 0210 */ -#define undefined_cs (max_command + 1 ) -#define expand_after (max_command + 2 ) -#define no_expand (max_command + 3 ) -#define input (max_command + 4 ) -#define if_test (max_command + 5 ) -#define fi_or_else (max_command + 6 ) -#define cs_name (max_command + 7 ) -#define convert (max_command + 8 ) -#define the (max_command + 9 ) -#define top_bot_mark (max_command + 10) -#define call (max_command + 11) -#define long_call (max_command + 12) -#define outer_call (max_command + 13) -#define long_outer_call (max_command + 14) -#define end_template (max_command + 15) -#define dont_expand (max_command + 16) -#define glue_ref (max_command + 17) -#define shape_ref (max_command + 18) -#define box_ref (max_command + 19) -#define data (max_command + 20) -/* sec 0211 */ -#define vmode 1 -#define hmode (vmode + max_command + 1) -#define mmode (hmode + max_command + 1) -/* sec 0212 */ -#define ignore_depth -65536000L -/* sec 0213 */ -#define mode cur_list.mode_field -#define head cur_list.head_field -#define tail cur_list.tail_field -#define aux cur_list.aux_field -#define prev_depth aux.cint -#define space_factor aux.hh.lh -#define clang aux.hh.rh -#define incompleat_noad aux.cint -#define prev_graf cur_list.pg_field -#define mode_line cur_list.ml_field -/* sec 0221 */ -#define eq_level_field(a) a.hh.b1 -#define eq_type_field(a) a.hh.b0 -#define equiv_field(a) a.hh.rh -#define eq_level(a) eq_level_field(eqtb[a]) -#define eq_type(a) eq_type_field(eqtb[a]) -#define equiv(a) equiv_field(eqtb[a]) -#define level_zero min_quarterword -#define level_one level_zero + 1 -/* sec 0222 */ -#define active_base 1 // 1 -#define single_base (active_base + 256) // 257 -#define null_cs (single_base + 256) // 513 -#define hash_base (null_cs + 1) // 514 -#define frozen_control_sequence (hash_base + hash_size + hash_extra) // (hash_size + hash_extra + 514) -#define frozen_protection frozen_control_sequence // (hash_size + hash_extra + 514) -#define frozen_cr (frozen_control_sequence + 1) // (hash_size + hash_extra + 515) -#define frozen_end_group (frozen_control_sequence + 2) // (hash_size + hash_extra + 516) -#define frozen_right (frozen_control_sequence + 3) // (hash_size + hash_extra + 517) -#define frozen_fi (frozen_control_sequence + 4) // (hash_size + hash_extra + 518) -#define frozen_end_template (frozen_control_sequence + 5) // (hash_size + hash_extra + 519) -#define frozen_endv (frozen_control_sequence + 6) // (hash_size + hash_extra + 520) -#define frozen_relax (frozen_control_sequence + 7) // (hash_size + hash_extra + 521) -#define end_write (frozen_control_sequence + 8) // (hash_size + hash_extra + 522) -#define frozen_dont_expand (frozen_control_sequence + 9) // (hash_size + hash_extra + 523) -#define frozen_null_font (frozen_control_sequence + 10) // (hash_size + hash_extra + 524) -#define font_id_base (frozen_null_font - font_base) // (hash_size + hash_extra + 524) -#define undefined_control_sequence (frozen_null_font + font_max + 2) // (hash_size + 781) -#define glue_base (undefined_control_sequence + 1) // (hash_size + 782) -/* sec 0224 */ -#define line_skip_code 0 // 782 -#define baseline_skip_code 1 // 783 -#define par_skip_code 2 // 784 -#define above_display_skip_code 3 // 785 -#define below_display_skip_code 4 // 786 -#define above_display_short_skip_code 5 // 787 -#define below_display_short_skip_code 6 // 788 -#define left_skip_code 7 // 789 -#define right_skip_code 8 // 790 -#define top_skip_code 9 // 791 -#define split_top_skip_code 10 // 792 -#define tab_skip_code 11 // 793 -#define space_skip_code 12 // 794 -#define xspace_skip_code 13 // 795 -#define par_fill_skip_code 14 // 796 -#define thin_mu_skip_code 15 // 797 -#define med_mu_skip_code 16 // 798 -#define thick_mu_skip_code 17 // 799 -#define glue_pars 18 // 800 -#define skip_base (glue_base + glue_pars) // 800 -#define mu_skip_base (skip_base + 256) // 1056 -#define local_base (mu_skip_base + 256) // 1312 -// # -#define skip(a) equiv(skip_base + a) -#define mu_skip(a) equiv(mu_skip_base + a) -#define glue_par(a) equiv(glue_base + a) -#define line_skip glue_par(line_skip_code) -#define baseline_skip glue_par(baseline_skip_code) -#define par_skip glue_par(par_skip_code) -#define above_display_skip glue_par(above_display_skip_code) -#define below_display_skip glue_par(below_display_skip_code) -#define above_display_short_skip glue_par(above_display_short_skip_code) -#define below_display_short_skip glue_par(below_display_short_skip_code) -#define left_skip glue_par(left_skip_code) -#define right_skip glue_par(right_skip_code) -#define top_skip glue_par(top_skip_code) -#define split_top_skip glue_par(split_top_skip_code) -#define tab_skip glue_par(tab_skip_code) -#define space_skip glue_par(space_skip_code) -#define xspace_skip glue_par(xspace_skip_code) -#define par_fill_skip glue_par(par_fill_skip_code) -#define thin_mu_skip glue_par(thin_mu_skip_code) -#define med_mu_skip glue_par(med_mu_skip_code) -#define thick_mu_skip glue_par(thick_mu_skip_code) -/* sec 0230 */ -#define par_shape_loc local_base // 1312 -#define output_routine_loc (local_base + 1) // 1313 -#define every_par_loc (local_base + 2) // 1314 -#define every_math_loc (local_base + 3) // 1315 -#define every_display_loc (local_base + 4) // 1316 -#define every_hbox_loc (local_base + 5) // 1317 -#define every_vbox_loc (local_base + 6) // 1318 -#define every_job_loc (local_base + 7) // 1319 -#define every_cr_loc (local_base + 8) // 1320 -#define err_help_loc (local_base + 9) // 1321 -#define toks_base (local_base + 10) // 1322 -#define box_base (toks_base + 256) // 1578 -#define cur_font_loc (box_base + 256) // 1834 -#define math_font_base (cur_font_loc + 1) // 1835 -#define cat_code_base (math_font_base + 48) // 1883 -#define lc_code_base (cat_code_base + 256) // 2139 -#define uc_code_base (lc_code_base + 256) // 2395 -#define sf_code_base (uc_code_base + 256) // 2651 -#define math_code_base (sf_code_base + 256) // 2907 -#define int_base (math_code_base + 256) // 3163 -// # -#define par_shape_ptr equiv(par_shape_loc) -#define output_routine equiv(output_routine_loc) -#define every_par equiv(every_par_loc) -#define every_math equiv(every_math_loc) -#define every_display equiv(every_display_loc) -#define every_hbox equiv(every_hbox_loc) -#define every_vbox equiv(every_vbox_loc) -#define every_job equiv(every_job_loc) -#define every_cr equiv(every_cr_loc) -#define err_help equiv(err_help_loc) -#define toks(a) equiv(toks_base + a) -#define box(a) equiv(box_base + a) -#define cur_font equiv(cur_font_loc) -#define fam_fnt(a) equiv(math_font_base + a) -#define cat_code(a) equiv(cat_code_base + a) -#define lc_code(a) equiv(lc_code_base + a) -#define uc_code(a) equiv(uc_code_base + a) -#define sf_code(a) equiv(sf_code_base + a) -#define math_code(a) equiv(math_code_base + a) -/* sec 0232 */ -#define null_font font_base -#define var_code 070000 -/* sec 0236 */ -#define pretolerance_code 0 // 3163 -#define tolerance_code 1 // 3164 -#define line_penalty_code 2 // 3165 -#define hyphen_penalty_code 3 // 3166 -#define ex_hyphen_penalty_code 4 // 3167 -#define club_penalty_code 5 // 3168 -#define widow_penalty_code 6 // 3169 -#define display_widow_penalty_code 7 // 3170 -#define broken_penalty_code 8 // 3171 -#define bin_op_penalty_code 9 // 3172 -#define rel_penalty_code 10 // 3173 -#define pre_display_penalty_code 11 // 3174 -#define post_display_penalty_code 12 // 3175 -#define inter_line_penalty_code 13 // 3176 -#define double_hyphen_demerits_code 14 // 3177 -#define final_hyphen_demerits_code 15 // 3178 -#define adj_demerits_code 16 // 3179 -#define mag_code 17 // 3180 -#define delimiter_factor_code 18 // 3181 -#define looseness_code 19 // 3182 -#define time_code 20 // 3183 -#define day_code 21 // 3184 -#define month_code 22 // 3185 -#define year_code 23 // 3186 -#define show_box_breadth_code 24 // 3187 -#define show_box_depth_code 25 // 3188 -#define hbadness_code 26 // 3189 -#define vbadness_code 27 // 3190 -#define pausing_code 28 // 3191 -#define tracing_online_code 29 // 3192 -#define tracing_macros_code 30 // 3193 -#define tracing_stats_code 31 // 3194 -#define tracing_paragraphs_code 32 // 3195 -#define tracing_pages_code 33 // 3196 -#define tracing_output_code 34 // 3197 -#define tracing_lost_chars_code 35 // 3198 -#define tracing_commands_code 36 // 3199 -#define tracing_restores_code 37 // 3200 -#define uc_hyph_code 38 // 3201 -#define output_penalty_code 39 // 3202 -#define max_dead_cycles_code 40 // 3203 -#define hang_after_code 41 // 3204 -#define floating_penalty_code 42 // 3205 -#define global_defs_code 43 // 3206 -#define cur_fam_code 44 // 3207 -#define escape_char_code 45 // 3208 -#define default_hyphen_char_code 46 // 3209 -#define default_skew_char_code 47 // 3210 -#define end_line_char_code 48 // 3211 -#define new_line_char_code 49 // 3212 -#define language_code 50 // 3213 -#define left_hyphen_min_code 51 // 3214 -#define right_hyphen_min_code 52 // 3215 -#define holding_inserts_code 53 // 3216 -#define error_context_lines_code 54 // 3217 -#define int_pars 55 -#define count_base (int_base + int_pars) // 3218 -#define del_code_base (count_base + 256) // 3474 -#define dimen_base (del_code_base + 256) // 3730 -// # -#define del_code(a) eqtb[del_code_base + a].cint -#define count(a) eqtb[count_base + a].cint -#define int_par(a) eqtb[int_base + a].cint -#define pretolerance int_par(pretolerance_code) -#define tolerance int_par(tolerance_code) -#define line_penalty int_par(line_penalty_code) -#define hyphen_penalty int_par(hyphen_penalty_code) -#define ex_hyphen_penalty int_par(ex_hyphen_penalty_code) -#define club_penalty int_par(club_penalty_code) -#define widow_penalty int_par(widow_penalty_code) -#define display_widow_penalty int_par(display_widow_penalty_code) -#define broken_penalty int_par(broken_penalty_code) -#define bin_op_penalty int_par(bin_op_penalty_code) -#define rel_penalty int_par(rel_penalty_code) -#define pre_display_penalty int_par(pre_display_penalty_code) -#define post_display_penalty int_par(post_display_penalty_code) -#define inter_line_penalty int_par(inter_line_penalty_code) -#define double_hyphen_demerits int_par(double_hyphen_demerits_code) -#define final_hyphen_demerits int_par(final_hyphen_demerits_code) -#define adj_demerits int_par(adj_demerits_code) -#define mag int_par(mag_code) -#define delimiter_factor int_par(delimiter_factor_code) -#define looseness int_par(looseness_code) -#define tex_time int_par(time_code) -#define day int_par(day_code) -#define month int_par(month_code) -#define year int_par(year_code) -#define show_box_breadth int_par(show_box_breadth_code) -#define show_box_depth int_par(show_box_depth_code) -#define hbadness int_par(hbadness_code) -#define vbadness int_par(vbadness_code) -#define pausing int_par(pausing_code) -#define tracing_online int_par(tracing_online_code) -#define tracing_macros int_par(tracing_macros_code) -#define tracing_stats int_par(tracing_stats_code) -#define tracing_paragraphs int_par(tracing_paragraphs_code) -#define tracing_pages int_par(tracing_pages_code) -#define tracing_output int_par(tracing_output_code) -#define tracing_lost_chars int_par(tracing_lost_chars_code) -#define tracing_commands int_par(tracing_commands_code) -#define tracing_restores int_par(tracing_restores_code) -#define uc_hyph int_par(uc_hyph_code) -#define output_penalty int_par(output_penalty_code) -#define max_dead_cycles int_par(max_dead_cycles_code) -#define hang_after int_par(hang_after_code) -#define floating_penalty int_par(floating_penalty_code) -#define global_defs int_par(global_defs_code) -#define cur_fam int_par(cur_fam_code) -#define escape_char int_par(escape_char_code) -#define default_hyphen_char int_par(default_hyphen_char_code) -#define default_skew_char int_par(default_skew_char_code) -#define end_line_char int_par(end_line_char_code) -#define new_line_char int_par(new_line_char_code) -#define language int_par(language_code) -#define left_hyphen_min int_par(left_hyphen_min_code) -#define right_hyphen_min int_par(right_hyphen_min_code) -#define holding_inserts int_par(holding_inserts_code) -#define error_context_lines int_par(error_context_lines_code) -/* sec 0247 */ -#define par_indent_code 0 // 3730 -#define math_surround_code 1 // 3731 -#define line_skip_limit_code 2 // 3732 -#define hsize_code 3 // 3733 -#define vsize_code 4 // 3734 -#define max_depth_code 5 // 3735 -#define split_max_depth_code 6 // 3736 -#define box_max_depth_code 7 // 3737 -#define hfuzz_code 8 // 3738 -#define vfuzz_code 9 // 3739 -#define delimiter_shortfall_code 10 // 3740 -#define null_delimiter_space_code 11 // 3741 -#define script_space_code 12 // 3742 -#define pre_display_size_code 13 // 3743 -#define display_width_code 14 // 3744 -#define display_indent_code 15 // 3745 -#define overfull_rule_code 16 // 3746 -#define hang_indent_code 17 // 3747 -#define h_offset_code 18 // 3748 -#define v_offset_code 19 // 3749 -#define emergency_stretch_code 20 // 3750 -#define dimen_pars 21 -#define scaled_base (dimen_base + dimen_pars) // 3751 -#define eqtb_size (scaled_base + 255) // 4006 -// # -#define dimen(a) eqtb[scaled_base + a].cint -#define dimen_par(a) eqtb[dimen_base + a].cint -#define par_indent dimen_par(par_indent_code) -#define math_surround dimen_par(math_surround_code) -#define line_skip_limit dimen_par(line_skip_limit_code) -#define hsize dimen_par(hsize_code) -#define vsize dimen_par(vsize_code) -#define max_depth dimen_par(max_depth_code) -#define split_max_depth dimen_par(split_max_depth_code) -#define box_max_depth dimen_par(box_max_depth_code) -#define hfuzz dimen_par(hfuzz_code) -#define vfuzz dimen_par(vfuzz_code) -#define delimiter_shortfall dimen_par(delimiter_shortfall_code) -#define null_delimiter_space dimen_par(null_delimiter_space_code) -#define script_space dimen_par(script_space_code) -#define pre_display_size dimen_par(pre_display_size_code) -#define display_width dimen_par(display_width_code) -#define display_indent dimen_par(display_indent_code) -#define overfull_rule dimen_par(overfull_rule_code) -#define hang_indent dimen_par(hang_indent_code) -#define h_offset dimen_par(h_offset_code) -#define v_offset dimen_par(v_offset_code) -#define emergency_stretch dimen_par(emergency_stretch_code) -/* sec 0256 */ -#define text(a) hash[a].rh -#define next(a) hash[a].lh -#define hash_is_full (hash_used == hash_base) -#define font_id_text(a) text(font_id_base + a) -/* sec 0268 */ -#define save_type(a) save_stack[a].hh.b0 -#define save_level(a) save_stack[a].hh.b1 -#define save_index(a) save_stack[a].hh.rh -#define restore_old_value 0 -#define restore_zero 1 -#define insert_token 2 -#define level_boundary 3 -/* sec 0269 */ -#define bottom_level 0 -#define simple_group 1 -#define hbox_group 2 -#define adjust_hbox_group 3 -#define vbox_group 4 -#define vtop_group 5 -#define align_group 6 -#define no_align_group 7 -#define output_group 8 -#define math_group 9 -#define disc_group 10 -#define insert_group 11 -#define vcenter_group 12 -#define math_choice_group 13 -#define semi_simple_group 14 -#define math_shift_group 15 -#define math_left_group 16 -#define max_group_code 16 -/* sec 0274 */ -#define saved(a) save_stack[save_ptr + (a)].cint -/* sec 0289 */ -#define cs_token_flag 07777 // 4095 -#define left_brace_token 0400 // 256 = 2^8 * left_brace -#define left_brace_limit 01000 // 512 = 2^8 * (left_brace + 1) -#define right_brace_token 01000 // 512 = 2^8 * right_brace -#define right_brace_limit 01400 // 768 = 2^8 * (right_brace + 1) -#define math_shift_token 01400 // 768 = 2^8 * math_shift -#define tab_token 02000 // 1024 = 2^8 * tab_mark -#define out_param_token 02400 // 1280 = 2^8 * out_param -#define space_token 05040 // 2592 = 2^8 * spacer + ' ' -#define letter_token 05400 // 2816 = 2^8 * letter -#define other_token 06000 // 3072 = 2^8 * other_char -#define match_token 06400 // 3328 = 2^8 * match -#define end_match_token 07000 // 3584 = 2^8 * end_match -/* sec 0298 */ -#define chr_cmd(s) \ -do \ -{ \ - prints(s); \ - print(chr_code); \ -} \ -while (0) -/* sec 0302 */ -#define state cur_input.state_field -#define index cur_input.index_field -#define start cur_input.start_field -#define limit cur_input.limit_field -#define name cur_input.name_field -/* sec 0303 */ -#define mid_line 1 -#define skip_blanks 2 + max_char_code // 17 -#define new_line 3 + max_char_code + max_char_code // 33 -/* sec 0304 */ -#define cur_file input_file[index] -/* sec 0305 */ -#define skipping 1 -#define defining 2 -#define matching 3 -#define aligning 4 -#define absorbing 5 -/* sec 0307 */ -#define token_list 0 -#define token_type index -#define param_start limit -#define parameter 0 -#define u_template 1 -#define v_template 2 -#define backed_up 3 -#define inserted 4 -#define macro 5 -#define output_text 6 -#define every_par_text 7 -#define every_math_text 8 -#define every_display_text 9 -#define every_hbox_text 10 -#define every_vbox_text 11 -#define every_job_text 12 -#define every_cr_text 13 -#define mark_text 14 -#define write_text 15 -/* sec 0316 */ -#define begin_pseudoprint() \ -do \ -{ \ - l = tally; \ - tally = 0; \ - selector = pseudo; \ - trick_count = 1000000L; \ -} \ -while (0) -#define set_trick_count() \ -do \ -{ \ - first_count = tally; \ - trick_count = tally + 1 + error_line - half_error_line; \ - \ - if (trick_count < error_line) \ - trick_count = error_line; \ -} \ -while (0) -/* sec 0322 */ -/* sec 0323 */ -#define back_list(a) begin_token_list(a, backed_up) -#define ins_list(a) begin_token_list(a, inserted) -/* sec 0344 */ -#define any_state_plus(a) mid_line + (a): case skip_blanks + (a): case new_line + (a) -/* sec 0347 */ -#define add_delims_to(a) \ - (a) + math_shift: \ - case (a) + tab_mark: \ - case (a) + mac_param: \ - case (a) + sub_mark: \ - case (a) + letter: \ - case (a) + other_char -/* sec 0352 */ -#define is_hex(a) \ - (((a >= '0') && (a <= '9')) || ((a >= 'a') && (a <= 'f'))) -#define hex_to_cur_chr() \ -do \ -{ \ - if (c <= '9') \ - cur_chr = c - '0'; \ - else \ - cur_chr = c - 'a' + 10; \ - \ - if (cc <= '9') \ - cur_chr = 16 * cur_chr + cc - '0'; \ - else \ - cur_chr = 16 * cur_chr + cc - 'a' + 10; \ -} \ -while (0) -/* sec 0360 */ -#define end_line_char_inactive() \ - (end_line_char < 0) || (end_line_char > 255) -/* sec 0358 */ -/* sec 0371 */ -#define store_new_token(a) \ - do \ - { \ - q = get_avail(); \ - link(p) = q; \ - info(q) = a; \ - p = q; \ - } \ - while (0) -#define fast_store_new_token(a) \ - do \ - { \ - fast_get_avail(q); \ - link(p) = q; \ - info(q) = a; \ - p = q; \ - } \ - while (0) -#define no_expand_flag 257 -/* sec 0382 */ -#define top_mark_code 0 -#define first_mark_code 1 -#define bot_mark_code 2 -#define split_first_mark_code 3 -#define split_bot_mark_code 4 -#define top_mark cur_mark[top_mark_code] -#define first_mark cur_mark[first_mark_code] -#define bot_mark cur_mark[bot_mark_code] -#define split_first_mark cur_mark[split_first_mark_code] -#define split_bot_mark cur_mark[split_bot_mark_code] -/* sec 0400 */ -#define int_val 0 -#define dimen_val 1 -#define glue_val 2 -#define mu_val 3 -#define ident_val 4 -#define tok_val 5 -/* sec 0413 */ -#define scanned_result(va, vb) \ -do \ - { \ - cur_val = va; \ - cur_val_level = vb; \ - } \ -while (0) -/* sec 0416 */ -#define input_line_no_code (glue_val + 1) -#define badness_code (glue_val + 2) -/* sec 0421 */ -#define max_dimen 07777777777 -/* sec 0438 */ -#define octal_token (other_token + '\'') // 3111 -#define hex_token (other_token + '"' ) // 3106 -#define alpha_token (other_token + '`' ) // 3168 -#define point_token (other_token + '.' ) // 3118 -#define continental_point_token (other_token + ',' ) // 3116 -/* sec 0445 */ -#define zero_token (other_token + '0') // 3120 -#define A_token (letter_token + 'A') // 2881 -#define other_A_token (other_token + 'A') // 3137 -/* sec 0458 */ -#define set_conversion(a, b) \ - do \ - { \ - num = a; \ - denom = b; \ - } while (0) -/* sec 0468 */ -#define number_code 0 -#define roman_numeral_code 1 -#define string_code 2 -#define meaning_code 3 -#define font_name_code 4 -#define job_name_code 5 -/* sec 0480 */ -#define closed 2 -#define just_open 1 -/* sec 0487 */ -#define if_char_code 0 -#define if_cat_code 1 -#define if_int_code 2 -#define if_dim_code 3 -#define if_odd_code 4 -#define if_vmode_code 5 -#define if_hmode_code 6 -#define if_mmode_code 7 -#define if_inner_code 8 -#define if_void_code 9 -#define if_hbox_code 10 -#define if_vbox_code 11 -#define ifx_code 12 -#define if_eof_code 13 -#define if_true_code 14 -#define if_false_code 15 -#define if_case_code 16 -/* sec 0489 */ -#define if_node_size 2 -#define if_line_field(a) mem[(a) + 1].cint -#define if_code 1 -#define fi_code 2 -#define else_code 3 -#define or_code 4 -/* sec 0506 */ -#define get_x_token_or_active_char() \ -do \ -{ \ - get_x_token(); \ - \ - if (cur_cmd == relax) \ - if (cur_chr == no_expand_flag) \ - { \ - cur_cmd = active_char; \ - cur_chr = cur_tok - cs_token_flag - active_base; \ - } \ -} \ -while (0) -/* sec 0519 */ -#define append_to_name(a) \ -do \ -{ \ - c = a; incr(k); \ - \ - if (k < file_name_size) \ - name_of_file[k] = xchr[c]; \ -} \ -while (0) -/* sec 0544 */ -#define no_tag 0 -#define lig_tag 1 -#define list_tag 2 -#define ext_tag 3 -/* sec 0545 */ -#define stop_flag 128 -#define kern_flag 128 -#define skip_byte(a) a.b0 -#define next_char(a) a.b1 -#define op_byte(a) a.b2 -#define rem_byte(a) a.b3 -/* sec 0546 */ -#define ext_top(a) a.b0 -#define ext_mid(a) a.b1 -#define ext_bot(a) a.b2 -#define ext_rep(a) a.b3 -/* sec 0547 */ -#define slant_code 1 -#define space_code 2 -#define space_stretch_code 3 -#define space_shrink_code 4 -#define x_height_code 5 -#define quad_code 6 -#define extra_space_code 7 -/* sec 0549 */ -#define non_char 256 -#define non_address 0 -/* sec 0554 */ -#define char_info(a, b) font_info[char_base[a] + b].qqqq -#define char_width(a, b) font_info[width_base[a] + b.b0].cint -#define char_exists(a) (a.b0 > min_quarterword) -#define char_italic(a, b) font_info[italic_base[a] + (b.b2) / 4].cint -#define height_depth(a) (a.b1) -#define char_height(a, b) font_info[height_base[a] + (b) / 16].cint -#define char_depth(a, b) font_info[depth_base[a] + (b) % 16].cint -#define char_tag(a) (a.b2 % 4) -/* sec 0557 */ -#define char_kern(a, b) font_info[kern_base[a] + 256 * op_byte(b) + rem_byte(b)].cint -#define kern_base_offset (256 * (128 + min_quarterword)) -#define lig_kern_start(a, b) lig_kern_base[a] + rem_byte(b) -#define lig_kern_restart(a, b) lig_kern_base[a] + 256 * op_byte(b) + rem_byte(b) + 32768 - kern_base_offset -/* sec 0558 */ -#define param(a, b) font_info[a + param_base[b]].cint -#define slant(f) param(slant_code, f) -#define space(f) param(space_code, f) -#define space_stretch(f) param(space_stretch_code, f) -#define space_shrink(f) param(space_shrink_code, f) -#define x_height(f) param(x_height_code, f) -#define quad(f) param(quad_code, f) -#define extra_space(f) param(extra_space_code, f) -/* sec 0561 */ -#define start_font_error_message() \ -do \ -{ \ - print_err("Font "); \ - sprint_cs(u); \ - print_char('='); \ - print_file_name(nom, aire, 335); \ - \ - if (s >= 0) \ - { \ - prints(" at "); \ - print_scaled(s); \ - prints("pt"); \ - } \ - else if (s != -1000) \ - { \ - prints(" scaled "); \ - print_int(-(integer)s); \ - } \ -} \ -while (0) -/* sec 0564 */ -#define read_sixteen(a) \ -do \ - { \ - a = fbyte; \ - \ - if (a > 127) \ - goto bad_tfm; \ - \ - fget(); \ - a = a * 256 + fbyte;\ - } \ -while (0) -#define store_four_quarters(val) \ -do \ - { \ - fget(); a = fbyte; qw.b0 = a; \ - fget(); b = fbyte; qw.b1 = b; \ - fget(); c = fbyte; qw.b2 = c; \ - fget(); d = fbyte; qw.b3 = d; \ - val = qw; \ - } \ -while (0) -/* sec 0570 */ -#define check_byte_range(a) \ -do \ -{ \ - if ((a < bc) || (a > ec)) \ - goto bad_tfm; \ -} \ - while (0) -/* sec 0571 */ -#define store_scaled(a) \ -do \ -{ \ - fget(); a = fbyte; fget(); b = fbyte; \ - fget(); c = fbyte; fget(); d = fbyte; \ - sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;\ - \ - if (a == 0) \ - a = sw; \ - else if (a == 255) \ - a = sw - alpha; \ - else \ - goto bad_tfm; \ -} \ -while (0) -/* sec 0573 */ -#define check_existence(a) \ -do \ -{ \ - check_byte_range(a); \ - \ - qw = char_info(f, a); \ - \ - if (!char_exists(qw)) \ - goto bad_tfm; \ -} \ -while (0) -/* sec 0576 */ -#define adjust(a) a[f] = a[f] -/* sec 0585 */ -#define set1 128 // c[1] -#define set2 129 // c[2] -#define set3 130 // c[3] -#define set4 131 // c[4] -#define set_rule 132 // a[4] b[4] -#define put1 133 // c[1] -#define put2 134 // c[2] -#define put3 135 // c[3] -#define put4 136 // c[4] -#define put_rule 137 // a[4] b[4] -#define nop 138 // NULL -#define bop 139 // c0[4] c1[4] ... c9[4] p[4] -#define eop 140 // NULL -#define push 141 -#define pop 142 -#define right1 143 // b[1] -#define right2 144 // b[2] -#define right3 145 // b[3] -#define right4 146 // b[4] -#define w0 147 // -#define w1 148 // b[1] -#define w2 149 // b[2] -#define w3 150 // b[3] -#define w4 151 // b[4] -#define x0 152 // -#define x1 153 // b[1] -#define x2 154 // b[2] -#define x3 155 // b[3] -#define x4 156 // b[4] -#define down1 157 // a[1] -#define down2 158 // a[2] -#define down3 159 // a[3] -#define down4 160 // a[4] -#define y0 161 // -#define y1 162 // a[1] -#define y2 163 // a[2] -#define y3 164 // a[3] -#define y4 165 // a[4] -#define z0 166 // -#define z1 167 // a[1] -#define z2 168 // a[2] -#define z3 169 // a[3] -#define z4 170 // a[4] -#define fnt_num_0 171 // -#define fnt1 235 // k[1] -#define fnt2 236 // k[2] -#define fnt3 237 // k[3] -#define fnt4 238 // k[4] -#define xxx1 239 // k[1] x[k] -#define xxx2 240 // k[2] x[k] -#define xxx3 241 // k[3] x[k] -#define xxx4 242 // k[4] x[k] -#define fnt_def1 243 // k[1] c[4] s[4] d[4] a[1] l[1] n[a + l] -#define fnt_def2 244 // k[2] c[4] s[4] d[4] a[1] l[1] n[a + l] -#define fnt_def3 245 // k[3] c[4] s[4] d[4] a[1] l[1] n[a + l] -#define fnt_def4 246 // k[4] c[4] s[4] d[4] a[1] l[1] n[a + l] -#define pre 247 // i[1] num[4] den[4] mag[4] k[1] x[k] -#define post 248 // -#define post_post 249 // -/* sec 0587 */ -#define id_byte 2 -/* sec 0605 */ -#define movement_node_size 3 -#define location(a) mem[a + 2].cint -/* sec 0608 */ -#define y_here 1 -#define z_here 2 -#define yz_OK 3 -#define y_OK 4 -#define z_OK 5 -#define d_fixed 6 -/* sec 0611 */ -#define none_seen 0 -#define y_seen 6 -#define z_seen 12 -/* sec 0625 */ -#define billion 1000000000.0 -#define vet_glue(a) \ -do \ -{ \ - glue_temp = a; \ - if (glue_temp > billion) \ - glue_temp = billion; \ - else if (glue_temp < -billion)\ - glue_temp = -billion; \ -} \ -while (0) -/* sec 0644 */ -#define exactly 0 -#define additional 1 -#define natural 0, additional -/* sec 0769 */ -#define u_part(a) mem[(a) + height_offset].cint -#define v_part(a) mem[(a) + depth_offset].cint -#define extra_info(a) info((a) + list_offset) -/* sec 0681 */ -#define noad_size 4 -#define nucleus(a) ((a) + 1) -#define supscr(a) ((a) + 2) -#define subscr(a) ((a) + 3) -#define math_type link -#define fam font -#define math_char 1 -#define sub_box 2 -#define sub_mlist 3 -#define math_text_char 4 -/* sec 0682 */ -#define ord_noad (unset_node + 3) // 16 -#define op_noad (ord_noad + 1 ) // 17 -#define bin_noad (ord_noad + 2 ) // 18 -#define rel_noad (ord_noad + 3 ) // 19 -#define open_noad (ord_noad + 4 ) // 20 -#define close_noad (ord_noad + 5 ) // 21 -#define punct_noad (ord_noad + 6 ) // 22 -#define inner_noad (ord_noad + 7 ) // 23 -#define limits 1 -#define no_limits 2 -/* sec 0683 */ -#define left_delimiter(a) ((a) + 4) -#define right_delimiter(a) ((a) + 5) -#define radical_noad (inner_noad + 1) // 24 -#define radical_noad_size 5 -#define fraction_noad (radical_noad + 1) // 25 -#define fraction_noad_size 6 -#define small_fam(a) mem[(a)].qqqq.b0 -#define small_char(a) mem[(a)].qqqq.b1 -#define large_fam(a) mem[(a)].qqqq.b2 -#define large_char(a) mem[(a)].qqqq.b3 -#define thickness width -#define default_code 010000000000L -#define numerator supscr -#define denominator subscr -/* sec 0687 */ -#define under_noad (fraction_noad + 1) // 26 -#define over_noad (under_noad + 1 ) // 27 -#define accent_noad (over_noad + 1 ) // 28 -#define accent_noad_size 5 -#define accent_chr(a) (a) + 4 -#define vcenter_noad (accent_noad + 1 ) // 29 -#define left_noad (vcenter_noad + 1 ) // 30 -#define right_noad (left_noad + 1 ) // 31 -#define delimiter nucleus -#define script_allowed(a) ((type(a) >= ord_noad) && (type(a) < left_noad)) -/* sec 0688 */ -#define style_node (unset_node + 1) -#define style_node_size 3 -#define display_style 0 -#define text_style 2 -#define script_style 4 -#define script_script_style 6 -#define cramped 1 -/* sec 0689 */ -#define choice_node (unset_node + 2) -#define display_mlist(a) info(a + 1) -#define text_mlist(a) link(a + 1) -#define script_mlist(a) info(a + 2) -#define script_script_mlist(a) link(a + 2) -/* sec 0699 */ -#define text_size 0 -#define script_size 16 -#define script_script_size 32 -/* sec 0700 */ -#define mathsy(a, b) font_info[a + param_base[fam_fnt(2 + b)]].cint -#define math_x_height(a) mathsy(5, a) -#define math_quad(a) mathsy(6, a) -#define num1(a) mathsy(8, a) -#define num2(a) mathsy(9, a) -#define num3(a) mathsy(10, a) -#define denom1(a) mathsy(11, a) -#define denom2(a) mathsy(12, a) -#define sup1(a) mathsy(13, a) -#define sup2(a) mathsy(14, a) -#define sup3(a) mathsy(15, a) -#define sub1(a) mathsy(16, a) -#define sub2(a) mathsy(17, a) -#define sup_drop(a) mathsy(18, a) -#define sub_drop(a) mathsy(19, a) -#define delim1(a) mathsy(20, a) -#define delim2(a) mathsy(21, a) -#define axis_height(a) mathsy(22, a) -#define total_mathsy_params 22 -/* sec 0701 */ -#define mathex(a) font_info[(a) + param_base[fam_fnt(3 + cur_size)]].cint -#define default_rule_thickness mathex(8) -#define big_op_spacing1 mathex(9) -#define big_op_spacing2 mathex(10) -#define big_op_spacing3 mathex(11) -#define big_op_spacing4 mathex(12) -#define big_op_spacing5 mathex(13) -#define total_mathex_params 13 -/* sec 0702 */ -#define cramped_style(a) (2 * ((a) / 2) + cramped) -#define sub_style(a) (2 * ((a) / 4) + script_style + cramped) -#define sup_style(a) (2 * ((a) / 4) + script_style + ((a) % 2)) -#define num_style(a) ((a) + 2 - 2 * ((a) / 6)) -#define denom_style(a) (2 * ((a) / 2) + cramped + 2 - 2 * ((a) / 6)) -/* sec 0716 */ -#define mu_mult(a) nx_plus_y(n, a, xn_over_d(a, f, 0200000)) -/* sec 0725 */ -#define new_hlist(a) mem[nucleus(a)].cint -/* sec 0731 */ -#define choose_mlist(a) \ -do \ -{ \ - p = a(q); \ - a(q) = 0; \ -} \ -while (0) -/* sec 0770 */ -#define preamble link(align_head) -#define align_stack_node_size 5 -/* sec 0780 */ -#define span_code 256 -#define cr_code 257 -#define cr_cr_code (cr_code + 1) -#define end_template_token (cs_token_flag + frozen_end_template) -/* sec 0797 */ -#define span_node_size 2 -/* sec 0817 */ -#define tight_fit 3 -#define loose_fit 1 -#define very_loose_fit 0 -#define decent_fit 2 -/* sec 0819 */ -#define active_node_size 3 -#define fitness subtype -#define break_node rlink -#define line_number llink -#define total_demerits(a) mem[a + 2].cint -#define unhyphenated 0 -#define hyphenated 1 -#define last_active active -/* sec 0821 */ -#define passive_node_size 2 -#define cur_break rlink -#define prev_break llink -#define serial info -/* sec 0822 */ -#define delta_node_size 7 -#define delta_node 2 -/* sec 0823 */ -#define do_all_six(a) \ -do \ -{ \ - a(1); a(2); a(3); \ - a(4); a(5); a(6); \ -} \ -while (0) -/* sec 0825 */ -#define check_shrinkage(s) \ -do \ -{ \ - if ((shrink_order(s) != normal) && (shrink(s) != 0))\ - s = finite_shrink(s); \ -} \ -while (0) -/* sec 0829 */ -#define copy_to_cur_active(a) cur_active_width[a] = active_width[a] -/* sec 0832 */ -#define update_width(a) cur_active_width[a] = cur_active_width[a] + mem[r + (a)].cint -/* sec 0833 */ -#define awful_bad 07777777777 -/* sec 0837 */ -#define set_break_width_to_background(a) break_width[a] = background[a] -/* sec 0843 */ -#define convert_to_break_width(a) mem[prev_r + (a)].cint = mem[prev_r + (a)].cint - cur_active_width[a] + break_width[a] -#define store_break_width(a) active_width[a] = break_width[a] -#define new_delta_to_break_width(a) mem[q + (a)].cint = break_width[(a)] - cur_active_width[(a)] -/* sec 0844 */ -#define new_delta_from_break_width(a) mem[q + (a)].cint = cur_active_width[(a)] - break_width[(a)] -/* sec 0860 */ -#define combine_two_deltas(a) mem[prev_r + (a)].cint = mem[prev_r + (a)].cint + mem[r + (a)].cint -#define downdate_width(a) cur_active_width[(a)] = cur_active_width[(a)] - mem[prev_r + (a)].cint -/* sec 0861 */ -#define update_active(a) active_width[(a)] = active_width[(a)] + mem[r + (a)].cint -/* sec 0864 */ -#define store_background(a) active_width[a] = background[a] -/* sec 0866 */ -#define act_width active_width[1] -#define kern_break() \ -do \ -{ \ - if (!is_char_node(link(cur_p)) && auto_breaking) \ - if (type(link(cur_p)) == glue_node) \ - try_break(0, unhyphenated); \ - \ - act_width = act_width + width(cur_p); \ -} \ -while (0) -/* sec 0877 */ -#define next_break prev_break -/* sec 0908 */ -#define append_charnode_to_t(a) \ -do \ - { \ - link(t) = get_avail(); \ - t = link(t); \ - font(t) = hf; \ - character(t) = (a); \ - } \ -while (0) -#define set_cur_r() \ -do \ - { \ - if (j < n) \ - cur_r = hu[j + 1]; \ - else \ - cur_r = bchar; \ - \ - if (odd(hyf[j])) \ - cur_rh = hchar; \ - else \ - cur_rh = non_char; \ - } \ -while (0) -/* sec 0910 */ -#define wrap_lig(a) \ -do \ -{ \ - if (ligature_present) \ - { \ - p = new_ligature(hf, cur_l, link(cur_q)); \ - \ - if (lft_hit) \ - { \ - subtype(p) = 2; \ - lft_hit = false; \ - } \ - \ - if ((a)) \ - if (lig_stack == 0) \ - { \ - incr(subtype(p)); \ - rt_hit = false; \ - } \ - \ - link(cur_q) = p; \ - t = p; \ - ligature_present = false; \ - } \ -} \ -while (0) -#define pop_lig_stack() \ -do \ - { \ - if (lig_ptr(lig_stack) != 0) \ - { \ - link(t) = lig_ptr(lig_stack); \ - t = link(t); \ - incr(j); \ - } \ - \ - p = lig_stack; \ - lig_stack = link(p); \ - free_node(p, small_node_size); \ - \ - if (lig_stack == 0) \ - { \ - set_cur_r(); \ - } \ - else \ - cur_r = character(lig_stack); \ - } \ -while (0) -/* sec 0914 */ -#define advance_major_tail() \ -do \ - { \ - major_tail = link(major_tail); \ - incr(r_count); \ - } \ -while (0) -/* sec 0970 */ -#define active_height active_width -#define cur_height active_height[1] -#define set_height_zero(a) active_width[(a)] = 0 -/* sec 0974 */ -#define deplorable 100000L -/* sec 0980 */ -#define inserts_only 1 -#define box_there 2 -/* sec 0981 */ -#define page_ins_node_size 4 -#define inserting 0 -#define split_up 1 -#define broken_ptr(a) link(a + 1) -#define broken_ins(a) info(a + 1) -#define last_ins_ptr(a) link(a + 2) -#define best_ins_ptr(a) info(a + 2) -/* sec 0982 */ -#define page_goal page_so_far[0] -#define page_total page_so_far[1] -#define page_shrink page_so_far[6] -#define page_depth page_so_far[7] -/* sec 0987 */ -#define set_page_so_far_zero(a) page_so_far[(a)] = 0 -/* sec 1034 */ -#define adjust_space_factor() \ -do \ -{ \ - main_s = sf_code(cur_chr); \ - if (main_s == 1000) \ - space_factor = 1000; \ - else if (main_s < 1000) \ - { \ - if (main_s > 0) \ - space_factor = main_s; \ - } \ - else if (space_factor < 1000) \ - space_factor = 1000; \ - else \ - space_factor = main_s; \ -} \ -while (0) -/* sec 1035 */ -/* -> false */ -#define wrapup(a) \ -do \ -{ \ - if (cur_l < non_char) \ - { \ - if (link(cur_q) != 0) \ - if (character(tail) == hyphen_char[main_f]) \ - ins_disc = true; \ - \ - if (ligature_present) \ - { \ - main_p = new_ligature(main_f, cur_l, link(cur_q)); \ - \ - if (lft_hit) \ - { \ - subtype(main_p) = 2; \ - lft_hit = false; \ - } \ - \ - if (a) \ - if (lig_stack == 0) \ - { \ - incr(subtype(main_p)); \ - rt_hit = false; \ - } \ - \ - link(cur_q) = main_p; \ - tail = main_p; \ - ligature_present = false; \ - } \ - \ - if (ins_disc) \ - { \ - ins_disc = false; \ - \ - if (mode > 0) \ - { \ - tail_append(new_disc()); \ - } \ - } \ - } \ -} \ -while (0) -/* sec 1045 */ -#define any_mode(a) vmode + a: case hmode + a: case mmode + a -/* sec 1046 */ -#define non_math(a) vmode + a: case hmode + a -/* sec 1058 */ -#define fil_code 0 -#define fill_code 1 -#define ss_code 2 -#define fil_neg_code 3 -#define skip_code 4 -#define mskip_code 5 -/* sec 1071 */ -#define box_flag 010000000000 -#define ship_out_flag (box_flag + 512) -#define leader_flag (box_flag + 513) -#define box_code 0 -#define copy_code 1 -#define last_box_code 2 -#define vsplit_code 3 -#define vtop_code 4 -/* sec 1178 */ -#define above_code 0 -#define over_code 1 -#define atop_code 2 -#define delimited_code 3 -/* sec 1214 */ -#define define(p, t, e) \ -do \ -{ \ - if (a >= 4) \ - geq_define(p, t, e);\ - else \ - eq_define(p, t, e); \ -} \ -while (0) -#define word_define(p, w) \ -do \ -{ \ - if (a >= 4) \ - geq_word_define(p, w);\ - else \ - eq_word_define(p, w); \ -} \ -while (0) -/* sec 1222 */ -#define char_def_code 0 -#define math_char_def_code 1 -#define count_def_code 2 -#define dimen_def_code 3 -#define skip_def_code 4 -#define mu_skip_def_code 5 -#define toks_def_code 6 -/* sec 1290 */ -#define show_code 0 -#define show_box_code 1 -#define show_the_code 2 -#define show_lists 3 -/* sec 1306 */ -#define undump(va, vb, vc) \ -do \ - { \ - undump_int(x); \ - \ - if ((x < (va)) || (x > (vb))) \ - goto bad_fmt; \ - else \ - vc = x; \ - } \ -while (0) -/* sec 1342 */ -#define write_node_size 2 -#define open_node_size 3 -#define open_node 0 -#define write_node 1 -#define close_node 2 -#define special_node 3 -#define language_node 4 -#define what_lang(s) link(s+1) -#define what_lhm(s) type(s+1) -#define what_rhm(s) subtype(s+1) -#define write_tokens(s) link(s+1) -#define write_stream(s) info(s+1) -#define open_name(s) link(s+1) -#define open_area(s) info(s+2) -#define open_ext(s) link(s+2) -/* sec 1344 */ -#define immediate_code 4 -#define set_language_code 5 -/* sec 1371 */ -#define end_write_token (cs_token_flag + end_write) - +/* Copyright 2014 Clerk Ma + + 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ +#ifndef _YANDYTEX_MACROS_H +#define _YANDYTEX_MACROS_H + +#define font_base 0 +/* sec 0022 */ +#define null_code 0 // 0 +#define carriage_return 015 // 13 +#define invalid_code 0177 // 127 +/* sec 0036 */ +#define loc cur_input.loc_field +/* sec 0040 */ +#define length(s) (str_start[(s) + 1] - str_start[(s)]) +/* sec 0041 */ +#define cur_length (pool_ptr - str_start[str_ptr]) +/* sec 0054 */ +enum +{ + no_print = 16, + term_only = 17, + log_only = 18, + term_and_log = 19, + pseudo = 20, + new_string = 21, + max_selector = 21, +}; +/* sec 0073 */ +enum +{ + batch_mode = 0, + nonstop_mode = 1, + scroll_mode = 2, + error_stop_mode = 3, +}; +/* sec 0076 */ +enum +{ + spotless = 0, + warning_issued = 1, + error_message_issued = 2, + fatal_error_stop = 3, +}; +/* sec 0096 */ +#define check_interrupt() \ +do \ +{ \ + if (interrupt != 0) \ + pause_for_instructions(); \ +} \ +while (0) +/* sec 0101 */ +#define unity 0200000 +#define two 0400000 +/* sec 0105 */ +#define nx_plus_y(a, b, c) mult_and_add(a, b, c, 07777777777L) +#define mult_integers(a, b) mult_and_add(a, b, 0, 017777777777L) +/* sec 0108 */ +#define inf_bad 10000L +/* sec 0109 */ +#define set_glue_ratio_zero(a) (a) = 0.0 +#define set_glue_ratio_one(a) (a) = 1.0 +#define tex_float(a) (a) +#define unfloat(a) (a) +#define float_constant(a) (float) (a) +/* sec 0115 */ +//#define pointer halfword +#define null min_halfword +/* sec 0118 */ +#define link(p) mem[p].hh.rh +#define info(p) mem[p].hh.lh +/* sec 0122 */ +#ifdef STAT +#define fast_get_avail(a) \ + do \ + { \ + a = avail; \ + \ + if (a == 0) \ + a = get_avail(); \ + else \ + { \ + avail = link(a); \ + link(a) = 0; \ + incr(dyn_used); \ + } \ + } \ + while (0) +#else +#define fast_get_avail(a) \ + do \ + { \ + a = avail; \ + \ + if (a == 0) \ + a = get_avail(); \ + else \ + { \ + avail = link(a); \ + link(a) = 0; \ + } \ + } \ + while (0) +#endif +/* sec 0124 */ +#define empty_flag max_halfword +#define is_empty(a) (link(a) == empty_flag) +#define node_size info +#define llink(a) info(a+1) +#define rlink(a) link(a+1) +/* sec 0133 */ +#define type(a) mem[a].hh.b0 +#define subtype(a) mem[a].hh.b1 +/* sec 0134 */ +#define is_char_node(a) (a >= hi_mem_min) +#define font type +#define character subtype +/* sec 0135 */ +#define hlist_node 0 +#define box_node_size 7 +#define width_offset 1 +#define depth_offset 2 +#define height_offset 3 +#define width(a) mem[a + width_offset].cint +#define depth(a) mem[a + depth_offset].cint +#define height(a) mem[a + height_offset].cint +#define shift_amount(a) mem[a + 4].cint +#define list_offset 5 +#define list_ptr(a) link(a + list_offset) +#define glue_order(a) subtype(a + list_offset) +#define glue_sign(a) type(a + list_offset) +#define normal 0 +#define stretching 1 +#define shrinking 2 +#define glue_offset 6 +#define glue_set(a) mem[a + glue_offset].gr +/* sec 0137 */ +#define vlist_node 1 +/* sec 0138 */ +#define rule_node 2 +#define rule_node_size 4 +#define null_flag -010000000000L +#define is_running(a) (a == null_flag) +/* sec 0140 */ +#define ins_node 3 +#define ins_node_size 5 +#define float_cost(a) mem[a + 1].cint +#define ins_ptr(a) info(a + 4) +#define split_top_ptr(a) link(a + 4) +/* sec 0141 */ +#define mark_node 4 +#define small_node_size 2 +#define mark_ptr(a) mem[a + 1].cint +/* sec 0142 */ +#define adjust_node 5 +#define adjust_ptr mark_ptr +/* sec 0143 */ +#define ligature_node 6 +#define lig_char(a) (a + 1) +#define lig_ptr(a) link(lig_char(a)) +/* sec 0145 */ +#define disc_node 7 +#define replace_count subtype +#define pre_break llink +#define post_break rlink +/* sec 0146 */ +#define whatsit_node 8 +/* sec 0147 */ +#define math_node 9 +#define before 0 +#define after 1 +/* sec 0148 */ +#define precedes_break(a) (type(a) < math_node) +#define non_discardable(a) (type(a) < math_node) +/* sec 0149 */ +#define glue_node 10 +#define cond_math_glue 98 +#define mu_glue 99 +#define a_leaders 100 +#define c_leaders 101 +#define x_leaders 102 +#define glue_ptr llink +#define leader_ptr rlink +/* sec 0150 */ +#define glue_spec_size 4 +#define glue_ref_count(a) link(a) +#define stretch(a) mem[a + 2].cint +#define shrink(a) mem[a + 3].cint +#define stretch_order type +#define shrink_order subtype +#define fil 1 +#define fill 2 +#define filll 3 +/* sec 0155 */ +#define kern_node 11 +#define explicit 1 +#define acc_kern 2 +/* sec 0157 */ +#define penalty_node 12 +#define inf_penalty inf_bad +#define eject_penalty -inf_bad +#define penalty(a) mem[a + 1].cint +/* sec 0159 */ +#define unset_node 13 +#define glue_stretch(a) mem[a + glue_offset].cint +#define glue_shrink shift_amount +#define span_count subtype +/* sec 0162 */ +#define zero_glue mem_bot // 0 +#define fil_glue (zero_glue + glue_spec_size) // 4 +#define fill_glue (fil_glue + glue_spec_size) // 8 +#define ss_glue (fill_glue + glue_spec_size) // 12 +#define fil_neg_glue (ss_glue + glue_spec_size) // 16 +#define lo_mem_stat_max (fil_neg_glue + glue_spec_size - 1) // 19 +#define page_ins_head mem_top +#define contrib_head (mem_top - 1) +#define page_head (mem_top - 2) +#define temp_head (mem_top - 3) +#define hold_head (mem_top - 4) +#define adjust_head (mem_top - 5) +#define active (mem_top - 7) +#define align_head (mem_top - 8) +#define end_span (mem_top - 9) +#define omit_template (mem_top - 10) +#define null_list (mem_top - 11) +#define lig_trick (mem_top - 12) +#define garbage (mem_top - 12) +#define backup_head (mem_top - 13) +#define hi_mem_stat_min (mem_top - 13) +#define hi_mem_stat_usage 14 +/* sec 0200 */ +#define token_ref_count(a) info(a) +/* sec 0203 */ +#define add_token_ref(a) incr(token_ref_count(a)) +#define add_glue_ref(a) incr(glue_ref_count(a)) +/* sec 0207 */ +#define escape 0 +#define relax 0 +#define left_brace 1 +#define right_brace 2 +#define math_shift 3 +#define tab_mark 4 +#define car_ret 5 +#define out_param 5 +#define mac_param 6 +#define sup_mark 7 +#define sub_mark 8 +#define ignore 9 +#define endv 9 +#define spacer 10 +#define letter 11 +#define other_char 12 +#define active_char 13 +#define par_end 13 +#define match 13 +#define comment 14 +#define end_match 14 +#define stop 14 +#define invalid_char 15 +#define delim_num 15 +#define max_char_code 15 +/* sec 0208 */ +#define char_num 16 +#define math_char_num 17 +#define mark 18 +#define xray 19 +#define make_box 20 +#define hmove 21 +#define vmove 22 +#define un_hbox 23 +#define un_vbox 24 +#define remove_item 25 +#define hskip 26 +#define vskip 27 +#define mskip 28 +#define kern 29 +#define mkern 30 +#define leader_ship 31 +#define halign 32 +#define valign 33 +#define no_align 34 +#define vrule 35 +#define hrule 36 +#define insert 37 +#define vadjust 38 +#define ignore_spaces 39 +#define after_assignment 40 +#define after_group 41 +#define break_penalty 42 +#define start_par 43 +#define ital_corr 44 +#define accent 45 +#define math_accent 46 +#define discretionary 47 +#define eq_no 48 +#define left_right 49 +#define math_comp 50 +#define limit_switch 51 +#define above 52 +#define math_style 53 +#define math_choice 54 +#define non_script 55 +#define vcenter 56 +#define case_shift 57 +#define message 58 +#define extension 59 +#define in_stream 60 +#define begin_group 61 +#define end_group 62 +#define omit 63 +#define ex_space 64 +#define no_boundary 65 +#define radical 66 +#define end_cs_name 67 +#define min_internal 68 +#define char_given 68 +#define math_given 69 +#define last_item 70 +#define max_non_prefixed_command 70 +/* sec 0209 */ +#define toks_register 71 +#define assign_toks 72 +#define assign_int 73 +#define assign_dimen 74 +#define assign_glue 75 +#define assign_mu_glue 76 +#define assign_font_dimen 77 +#define assign_font_int 78 +#define set_aux 79 +#define set_prev_graf 80 +#define set_page_dimen 81 +#define set_page_int 82 +#define set_box_dimen 83 +#define set_shape 84 +#define def_code 85 +#define def_family 86 +#define set_font 87 +#define def_font 88 +#define tex_register 89 +#define max_internal 89 +#define advance 90 +#define multiply 91 +#define divide 92 +#define prefix 93 +#define let 94 +#define shorthand_def 95 +#define read_to_cs 96 +#define def 97 +#define set_box 98 +#define hyph_data 99 +#define set_interaction 100 +#define max_command 100 +/* sec 0210 */ +#define undefined_cs (max_command + 1 ) +#define expand_after (max_command + 2 ) +#define no_expand (max_command + 3 ) +#define input (max_command + 4 ) +#define if_test (max_command + 5 ) +#define fi_or_else (max_command + 6 ) +#define cs_name (max_command + 7 ) +#define convert (max_command + 8 ) +#define the (max_command + 9 ) +#define top_bot_mark (max_command + 10) +#define call (max_command + 11) +#define long_call (max_command + 12) +#define outer_call (max_command + 13) +#define long_outer_call (max_command + 14) +#define end_template (max_command + 15) +#define dont_expand (max_command + 16) +#define glue_ref (max_command + 17) +#define shape_ref (max_command + 18) +#define box_ref (max_command + 19) +#define data (max_command + 20) +/* sec 0211 */ +#define vmode 1 +#define hmode (vmode + max_command + 1) +#define mmode (hmode + max_command + 1) +/* sec 0212 */ +#define ignore_depth -65536000L +/* sec 0213 */ +#define mode cur_list.mode_field +#define head cur_list.head_field +#define tail cur_list.tail_field +#define aux cur_list.aux_field +#define prev_depth aux.cint +#define space_factor aux.hh.lh +#define clang aux.hh.rh +#define incompleat_noad aux.cint +#define prev_graf cur_list.pg_field +#define mode_line cur_list.ml_field +/* sec 0221 */ +#define eq_level_field(a) a.hh.b1 +#define eq_type_field(a) a.hh.b0 +#define equiv_field(a) a.hh.rh +#define eq_level(a) eq_level_field(eqtb[a]) +#define eq_type(a) eq_type_field(eqtb[a]) +#define equiv(a) equiv_field(eqtb[a]) +#define level_zero min_quarterword +#define level_one level_zero + 1 +/* sec 0222 */ +#define active_base 1 // 1 +#define single_base (active_base + 256) // 257 +#define null_cs (single_base + 256) // 513 +#define hash_base (null_cs + 1) // 514 +#define frozen_control_sequence (hash_base + hash_size + hash_extra) // (hash_size + hash_extra + 514) +#define frozen_protection frozen_control_sequence // (hash_size + hash_extra + 514) +#define frozen_cr (frozen_control_sequence + 1) // (hash_size + hash_extra + 515) +#define frozen_end_group (frozen_control_sequence + 2) // (hash_size + hash_extra + 516) +#define frozen_right (frozen_control_sequence + 3) // (hash_size + hash_extra + 517) +#define frozen_fi (frozen_control_sequence + 4) // (hash_size + hash_extra + 518) +#define frozen_end_template (frozen_control_sequence + 5) // (hash_size + hash_extra + 519) +#define frozen_endv (frozen_control_sequence + 6) // (hash_size + hash_extra + 520) +#define frozen_relax (frozen_control_sequence + 7) // (hash_size + hash_extra + 521) +#define end_write (frozen_control_sequence + 8) // (hash_size + hash_extra + 522) +#define frozen_dont_expand (frozen_control_sequence + 9) // (hash_size + hash_extra + 523) +#define frozen_null_font (frozen_control_sequence + 10) // (hash_size + hash_extra + 524) +#define font_id_base (frozen_null_font - font_base) // (hash_size + hash_extra + 524) +#define undefined_control_sequence (frozen_null_font + font_max + 2) // (hash_size + 781) +#define glue_base (undefined_control_sequence + 1) // (hash_size + 782) +/* sec 0224 */ +#define line_skip_code 0 // 782 +#define baseline_skip_code 1 // 783 +#define par_skip_code 2 // 784 +#define above_display_skip_code 3 // 785 +#define below_display_skip_code 4 // 786 +#define above_display_short_skip_code 5 // 787 +#define below_display_short_skip_code 6 // 788 +#define left_skip_code 7 // 789 +#define right_skip_code 8 // 790 +#define top_skip_code 9 // 791 +#define split_top_skip_code 10 // 792 +#define tab_skip_code 11 // 793 +#define space_skip_code 12 // 794 +#define xspace_skip_code 13 // 795 +#define par_fill_skip_code 14 // 796 +#define thin_mu_skip_code 15 // 797 +#define med_mu_skip_code 16 // 798 +#define thick_mu_skip_code 17 // 799 +#define glue_pars 18 // 800 +#define skip_base (glue_base + glue_pars) // 800 +#define mu_skip_base (skip_base + 256) // 1056 +#define local_base (mu_skip_base + 256) // 1312 +// # +#define skip(a) equiv(skip_base + a) +#define mu_skip(a) equiv(mu_skip_base + a) +#define glue_par(a) equiv(glue_base + a) +#define line_skip glue_par(line_skip_code) +#define baseline_skip glue_par(baseline_skip_code) +#define par_skip glue_par(par_skip_code) +#define above_display_skip glue_par(above_display_skip_code) +#define below_display_skip glue_par(below_display_skip_code) +#define above_display_short_skip glue_par(above_display_short_skip_code) +#define below_display_short_skip glue_par(below_display_short_skip_code) +#define left_skip glue_par(left_skip_code) +#define right_skip glue_par(right_skip_code) +#define top_skip glue_par(top_skip_code) +#define split_top_skip glue_par(split_top_skip_code) +#define tab_skip glue_par(tab_skip_code) +#define space_skip glue_par(space_skip_code) +#define xspace_skip glue_par(xspace_skip_code) +#define par_fill_skip glue_par(par_fill_skip_code) +#define thin_mu_skip glue_par(thin_mu_skip_code) +#define med_mu_skip glue_par(med_mu_skip_code) +#define thick_mu_skip glue_par(thick_mu_skip_code) +/* sec 0230 */ +#define par_shape_loc local_base // 1312 +#define output_routine_loc (local_base + 1) // 1313 +#define every_par_loc (local_base + 2) // 1314 +#define every_math_loc (local_base + 3) // 1315 +#define every_display_loc (local_base + 4) // 1316 +#define every_hbox_loc (local_base + 5) // 1317 +#define every_vbox_loc (local_base + 6) // 1318 +#define every_job_loc (local_base + 7) // 1319 +#define every_cr_loc (local_base + 8) // 1320 +#define err_help_loc (local_base + 9) // 1321 +#define toks_base (local_base + 10) // 1322 +#define box_base (toks_base + 256) // 1578 +#define cur_font_loc (box_base + 256) // 1834 +#define math_font_base (cur_font_loc + 1) // 1835 +#define cat_code_base (math_font_base + 48) // 1883 +#define lc_code_base (cat_code_base + 256) // 2139 +#define uc_code_base (lc_code_base + 256) // 2395 +#define sf_code_base (uc_code_base + 256) // 2651 +#define math_code_base (sf_code_base + 256) // 2907 +#define int_base (math_code_base + 256) // 3163 +// # +#define par_shape_ptr equiv(par_shape_loc) +#define output_routine equiv(output_routine_loc) +#define every_par equiv(every_par_loc) +#define every_math equiv(every_math_loc) +#define every_display equiv(every_display_loc) +#define every_hbox equiv(every_hbox_loc) +#define every_vbox equiv(every_vbox_loc) +#define every_job equiv(every_job_loc) +#define every_cr equiv(every_cr_loc) +#define err_help equiv(err_help_loc) +#define toks(a) equiv(toks_base + a) +#define box(a) equiv(box_base + a) +#define cur_font equiv(cur_font_loc) +#define fam_fnt(a) equiv(math_font_base + a) +#define cat_code(a) equiv(cat_code_base + a) +#define lc_code(a) equiv(lc_code_base + a) +#define uc_code(a) equiv(uc_code_base + a) +#define sf_code(a) equiv(sf_code_base + a) +#define math_code(a) equiv(math_code_base + a) +/* sec 0232 */ +#define null_font font_base +#define var_code 070000 +/* sec 0236 */ +#define pretolerance_code 0 // 3163 +#define tolerance_code 1 // 3164 +#define line_penalty_code 2 // 3165 +#define hyphen_penalty_code 3 // 3166 +#define ex_hyphen_penalty_code 4 // 3167 +#define club_penalty_code 5 // 3168 +#define widow_penalty_code 6 // 3169 +#define display_widow_penalty_code 7 // 3170 +#define broken_penalty_code 8 // 3171 +#define bin_op_penalty_code 9 // 3172 +#define rel_penalty_code 10 // 3173 +#define pre_display_penalty_code 11 // 3174 +#define post_display_penalty_code 12 // 3175 +#define inter_line_penalty_code 13 // 3176 +#define double_hyphen_demerits_code 14 // 3177 +#define final_hyphen_demerits_code 15 // 3178 +#define adj_demerits_code 16 // 3179 +#define mag_code 17 // 3180 +#define delimiter_factor_code 18 // 3181 +#define looseness_code 19 // 3182 +#define time_code 20 // 3183 +#define day_code 21 // 3184 +#define month_code 22 // 3185 +#define year_code 23 // 3186 +#define show_box_breadth_code 24 // 3187 +#define show_box_depth_code 25 // 3188 +#define hbadness_code 26 // 3189 +#define vbadness_code 27 // 3190 +#define pausing_code 28 // 3191 +#define tracing_online_code 29 // 3192 +#define tracing_macros_code 30 // 3193 +#define tracing_stats_code 31 // 3194 +#define tracing_paragraphs_code 32 // 3195 +#define tracing_pages_code 33 // 3196 +#define tracing_output_code 34 // 3197 +#define tracing_lost_chars_code 35 // 3198 +#define tracing_commands_code 36 // 3199 +#define tracing_restores_code 37 // 3200 +#define uc_hyph_code 38 // 3201 +#define output_penalty_code 39 // 3202 +#define max_dead_cycles_code 40 // 3203 +#define hang_after_code 41 // 3204 +#define floating_penalty_code 42 // 3205 +#define global_defs_code 43 // 3206 +#define cur_fam_code 44 // 3207 +#define escape_char_code 45 // 3208 +#define default_hyphen_char_code 46 // 3209 +#define default_skew_char_code 47 // 3210 +#define end_line_char_code 48 // 3211 +#define new_line_char_code 49 // 3212 +#define language_code 50 // 3213 +#define left_hyphen_min_code 51 // 3214 +#define right_hyphen_min_code 52 // 3215 +#define holding_inserts_code 53 // 3216 +#define error_context_lines_code 54 // 3217 +#define int_pars 55 +#define count_base (int_base + int_pars) // 3218 +#define del_code_base (count_base + 256) // 3474 +#define dimen_base (del_code_base + 256) // 3730 +// # +#define del_code(a) eqtb[del_code_base + a].cint +#define count(a) eqtb[count_base + a].cint +#define int_par(a) eqtb[int_base + a].cint +#define pretolerance int_par(pretolerance_code) +#define tolerance int_par(tolerance_code) +#define line_penalty int_par(line_penalty_code) +#define hyphen_penalty int_par(hyphen_penalty_code) +#define ex_hyphen_penalty int_par(ex_hyphen_penalty_code) +#define club_penalty int_par(club_penalty_code) +#define widow_penalty int_par(widow_penalty_code) +#define display_widow_penalty int_par(display_widow_penalty_code) +#define broken_penalty int_par(broken_penalty_code) +#define bin_op_penalty int_par(bin_op_penalty_code) +#define rel_penalty int_par(rel_penalty_code) +#define pre_display_penalty int_par(pre_display_penalty_code) +#define post_display_penalty int_par(post_display_penalty_code) +#define inter_line_penalty int_par(inter_line_penalty_code) +#define double_hyphen_demerits int_par(double_hyphen_demerits_code) +#define final_hyphen_demerits int_par(final_hyphen_demerits_code) +#define adj_demerits int_par(adj_demerits_code) +#define mag int_par(mag_code) +#define delimiter_factor int_par(delimiter_factor_code) +#define looseness int_par(looseness_code) +#define tex_time int_par(time_code) +#define day int_par(day_code) +#define month int_par(month_code) +#define year int_par(year_code) +#define show_box_breadth int_par(show_box_breadth_code) +#define show_box_depth int_par(show_box_depth_code) +#define hbadness int_par(hbadness_code) +#define vbadness int_par(vbadness_code) +#define pausing int_par(pausing_code) +#define tracing_online int_par(tracing_online_code) +#define tracing_macros int_par(tracing_macros_code) +#define tracing_stats int_par(tracing_stats_code) +#define tracing_paragraphs int_par(tracing_paragraphs_code) +#define tracing_pages int_par(tracing_pages_code) +#define tracing_output int_par(tracing_output_code) +#define tracing_lost_chars int_par(tracing_lost_chars_code) +#define tracing_commands int_par(tracing_commands_code) +#define tracing_restores int_par(tracing_restores_code) +#define uc_hyph int_par(uc_hyph_code) +#define output_penalty int_par(output_penalty_code) +#define max_dead_cycles int_par(max_dead_cycles_code) +#define hang_after int_par(hang_after_code) +#define floating_penalty int_par(floating_penalty_code) +#define global_defs int_par(global_defs_code) +#define cur_fam int_par(cur_fam_code) +#define escape_char int_par(escape_char_code) +#define default_hyphen_char int_par(default_hyphen_char_code) +#define default_skew_char int_par(default_skew_char_code) +#define end_line_char int_par(end_line_char_code) +#define new_line_char int_par(new_line_char_code) +#define language int_par(language_code) +#define left_hyphen_min int_par(left_hyphen_min_code) +#define right_hyphen_min int_par(right_hyphen_min_code) +#define holding_inserts int_par(holding_inserts_code) +#define error_context_lines int_par(error_context_lines_code) +/* sec 0247 */ +#define par_indent_code 0 // 3730 +#define math_surround_code 1 // 3731 +#define line_skip_limit_code 2 // 3732 +#define hsize_code 3 // 3733 +#define vsize_code 4 // 3734 +#define max_depth_code 5 // 3735 +#define split_max_depth_code 6 // 3736 +#define box_max_depth_code 7 // 3737 +#define hfuzz_code 8 // 3738 +#define vfuzz_code 9 // 3739 +#define delimiter_shortfall_code 10 // 3740 +#define null_delimiter_space_code 11 // 3741 +#define script_space_code 12 // 3742 +#define pre_display_size_code 13 // 3743 +#define display_width_code 14 // 3744 +#define display_indent_code 15 // 3745 +#define overfull_rule_code 16 // 3746 +#define hang_indent_code 17 // 3747 +#define h_offset_code 18 // 3748 +#define v_offset_code 19 // 3749 +#define emergency_stretch_code 20 // 3750 +#define dimen_pars 21 +#define scaled_base (dimen_base + dimen_pars) // 3751 +#define eqtb_size (scaled_base + 255) // 4006 +// # +#define dimen(a) eqtb[scaled_base + a].cint +#define dimen_par(a) eqtb[dimen_base + a].cint +#define par_indent dimen_par(par_indent_code) +#define math_surround dimen_par(math_surround_code) +#define line_skip_limit dimen_par(line_skip_limit_code) +#define hsize dimen_par(hsize_code) +#define vsize dimen_par(vsize_code) +#define max_depth dimen_par(max_depth_code) +#define split_max_depth dimen_par(split_max_depth_code) +#define box_max_depth dimen_par(box_max_depth_code) +#define hfuzz dimen_par(hfuzz_code) +#define vfuzz dimen_par(vfuzz_code) +#define delimiter_shortfall dimen_par(delimiter_shortfall_code) +#define null_delimiter_space dimen_par(null_delimiter_space_code) +#define script_space dimen_par(script_space_code) +#define pre_display_size dimen_par(pre_display_size_code) +#define display_width dimen_par(display_width_code) +#define display_indent dimen_par(display_indent_code) +#define overfull_rule dimen_par(overfull_rule_code) +#define hang_indent dimen_par(hang_indent_code) +#define h_offset dimen_par(h_offset_code) +#define v_offset dimen_par(v_offset_code) +#define emergency_stretch dimen_par(emergency_stretch_code) +/* sec 0256 */ +#define text(a) hash[a].rh +#define next(a) hash[a].lh +#define hash_is_full (hash_used == hash_base) +#define font_id_text(a) text(font_id_base + a) +/* sec 0268 */ +#define save_type(a) save_stack[a].hh.b0 +#define save_level(a) save_stack[a].hh.b1 +#define save_index(a) save_stack[a].hh.rh +#define restore_old_value 0 +#define restore_zero 1 +#define insert_token 2 +#define level_boundary 3 +/* sec 0269 */ +#define bottom_level 0 +#define simple_group 1 +#define hbox_group 2 +#define adjust_hbox_group 3 +#define vbox_group 4 +#define vtop_group 5 +#define align_group 6 +#define no_align_group 7 +#define output_group 8 +#define math_group 9 +#define disc_group 10 +#define insert_group 11 +#define vcenter_group 12 +#define math_choice_group 13 +#define semi_simple_group 14 +#define math_shift_group 15 +#define math_left_group 16 +#define max_group_code 16 +/* sec 0274 */ +#define saved(a) save_stack[save_ptr + (a)].cint +/* sec 0289 */ +#define cs_token_flag 07777 // 4095 +#define left_brace_token 0400 // 256 = 2^8 * left_brace +#define left_brace_limit 01000 // 512 = 2^8 * (left_brace + 1) +#define right_brace_token 01000 // 512 = 2^8 * right_brace +#define right_brace_limit 01400 // 768 = 2^8 * (right_brace + 1) +#define math_shift_token 01400 // 768 = 2^8 * math_shift +#define tab_token 02000 // 1024 = 2^8 * tab_mark +#define out_param_token 02400 // 1280 = 2^8 * out_param +#define space_token 05040 // 2592 = 2^8 * spacer + ' ' +#define letter_token 05400 // 2816 = 2^8 * letter +#define other_token 06000 // 3072 = 2^8 * other_char +#define match_token 06400 // 3328 = 2^8 * match +#define end_match_token 07000 // 3584 = 2^8 * end_match +/* sec 0298 */ +#define chr_cmd(s) \ +do \ +{ \ + prints(s); \ + print(chr_code); \ +} \ +while (0) +/* sec 0302 */ +#define state cur_input.state_field +#define index cur_input.index_field +#define start cur_input.start_field +#define limit cur_input.limit_field +#define name cur_input.name_field +/* sec 0303 */ +#define mid_line 1 +#define skip_blanks 2 + max_char_code // 17 +#define new_line 3 + max_char_code + max_char_code // 33 +/* sec 0304 */ +#define cur_file input_file[index] +/* sec 0305 */ +#define skipping 1 +#define defining 2 +#define matching 3 +#define aligning 4 +#define absorbing 5 +/* sec 0307 */ +#define token_list 0 +#define token_type index +#define param_start limit +#define parameter 0 +#define u_template 1 +#define v_template 2 +#define backed_up 3 +#define inserted 4 +#define macro 5 +#define output_text 6 +#define every_par_text 7 +#define every_math_text 8 +#define every_display_text 9 +#define every_hbox_text 10 +#define every_vbox_text 11 +#define every_job_text 12 +#define every_cr_text 13 +#define mark_text 14 +#define write_text 15 +/* sec 0316 */ +#define begin_pseudoprint() \ +do \ +{ \ + l = tally; \ + tally = 0; \ + selector = pseudo; \ + trick_count = 1000000L; \ +} \ +while (0) +#define set_trick_count() \ +do \ +{ \ + first_count = tally; \ + trick_count = tally + 1 + error_line - half_error_line; \ + \ + if (trick_count < error_line) \ + trick_count = error_line; \ +} \ +while (0) +/* sec 0322 */ +/* sec 0323 */ +#define back_list(a) begin_token_list(a, backed_up) +#define ins_list(a) begin_token_list(a, inserted) +/* sec 0344 */ +#define any_state_plus(a) mid_line + (a): case skip_blanks + (a): case new_line + (a) +/* sec 0347 */ +#define add_delims_to(a) \ + (a) + math_shift: \ + case (a) + tab_mark: \ + case (a) + mac_param: \ + case (a) + sub_mark: \ + case (a) + letter: \ + case (a) + other_char +/* sec 0352 */ +#define is_hex(a) \ + (((a >= '0') && (a <= '9')) || ((a >= 'a') && (a <= 'f'))) +#define hex_to_cur_chr() \ +do \ +{ \ + if (c <= '9') \ + cur_chr = c - '0'; \ + else \ + cur_chr = c - 'a' + 10; \ + \ + if (cc <= '9') \ + cur_chr = 16 * cur_chr + cc - '0'; \ + else \ + cur_chr = 16 * cur_chr + cc - 'a' + 10; \ +} \ +while (0) +/* sec 0360 */ +#define end_line_char_inactive() \ + (end_line_char < 0) || (end_line_char > 255) +/* sec 0358 */ +/* sec 0371 */ +#define store_new_token(a) \ + do \ + { \ + q = get_avail(); \ + link(p) = q; \ + info(q) = a; \ + p = q; \ + } \ + while (0) +#define fast_store_new_token(a) \ + do \ + { \ + fast_get_avail(q); \ + link(p) = q; \ + info(q) = a; \ + p = q; \ + } \ + while (0) +#define no_expand_flag 257 +/* sec 0382 */ +#define top_mark_code 0 +#define first_mark_code 1 +#define bot_mark_code 2 +#define split_first_mark_code 3 +#define split_bot_mark_code 4 +#define top_mark cur_mark[top_mark_code] +#define first_mark cur_mark[first_mark_code] +#define bot_mark cur_mark[bot_mark_code] +#define split_first_mark cur_mark[split_first_mark_code] +#define split_bot_mark cur_mark[split_bot_mark_code] +/* sec 0400 */ +#define int_val 0 +#define dimen_val 1 +#define glue_val 2 +#define mu_val 3 +#define ident_val 4 +#define tok_val 5 +/* sec 0413 */ +#define scanned_result(va, vb) \ +do \ + { \ + cur_val = va; \ + cur_val_level = vb; \ + } \ +while (0) +/* sec 0416 */ +#define input_line_no_code (glue_val + 1) +#define badness_code (glue_val + 2) +/* sec 0421 */ +#define max_dimen 07777777777 +/* sec 0438 */ +#define octal_token (other_token + '\'') // 3111 +#define hex_token (other_token + '"' ) // 3106 +#define alpha_token (other_token + '`' ) // 3168 +#define point_token (other_token + '.' ) // 3118 +#define continental_point_token (other_token + ',' ) // 3116 +/* sec 0445 */ +#define zero_token (other_token + '0') // 3120 +#define A_token (letter_token + 'A') // 2881 +#define other_A_token (other_token + 'A') // 3137 +/* sec 0458 */ +#define set_conversion(a, b) \ + do \ + { \ + num = a; \ + denom = b; \ + } while (0) +/* sec 0468 */ +#define number_code 0 +#define roman_numeral_code 1 +#define string_code 2 +#define meaning_code 3 +#define font_name_code 4 +#define job_name_code 5 +/* sec 0480 */ +#define closed 2 +#define just_open 1 +/* sec 0487 */ +#define if_char_code 0 +#define if_cat_code 1 +#define if_int_code 2 +#define if_dim_code 3 +#define if_odd_code 4 +#define if_vmode_code 5 +#define if_hmode_code 6 +#define if_mmode_code 7 +#define if_inner_code 8 +#define if_void_code 9 +#define if_hbox_code 10 +#define if_vbox_code 11 +#define ifx_code 12 +#define if_eof_code 13 +#define if_true_code 14 +#define if_false_code 15 +#define if_case_code 16 +/* sec 0489 */ +#define if_node_size 2 +#define if_line_field(a) mem[(a) + 1].cint +#define if_code 1 +#define fi_code 2 +#define else_code 3 +#define or_code 4 +/* sec 0506 */ +#define get_x_token_or_active_char() \ +do \ +{ \ + get_x_token(); \ + \ + if (cur_cmd == relax) \ + if (cur_chr == no_expand_flag) \ + { \ + cur_cmd = active_char; \ + cur_chr = cur_tok - cs_token_flag - active_base; \ + } \ +} \ +while (0) +/* sec 0519 */ +#define append_to_name(a) \ +do \ +{ \ + c = a; incr(k); \ + \ + if (k < file_name_size) \ + name_of_file[k] = xchr[c]; \ +} \ +while (0) +/* sec 0544 */ +#define no_tag 0 +#define lig_tag 1 +#define list_tag 2 +#define ext_tag 3 +/* sec 0545 */ +#define stop_flag 128 +#define kern_flag 128 +#define skip_byte(a) a.b0 +#define next_char(a) a.b1 +#define op_byte(a) a.b2 +#define rem_byte(a) a.b3 +/* sec 0546 */ +#define ext_top(a) a.b0 +#define ext_mid(a) a.b1 +#define ext_bot(a) a.b2 +#define ext_rep(a) a.b3 +/* sec 0547 */ +#define slant_code 1 +#define space_code 2 +#define space_stretch_code 3 +#define space_shrink_code 4 +#define x_height_code 5 +#define quad_code 6 +#define extra_space_code 7 +/* sec 0549 */ +#define non_char 256 +#define non_address 0 +/* sec 0554 */ +#define char_info(a, b) font_info[char_base[a] + b].qqqq +#define char_width(a, b) font_info[width_base[a] + b.b0].cint +#define char_exists(a) (a.b0 > min_quarterword) +#define char_italic(a, b) font_info[italic_base[a] + (b.b2) / 4].cint +#define height_depth(a) (a.b1) +#define char_height(a, b) font_info[height_base[a] + (b) / 16].cint +#define char_depth(a, b) font_info[depth_base[a] + (b) % 16].cint +#define char_tag(a) (a.b2 % 4) +/* sec 0557 */ +#define char_kern(a, b) font_info[kern_base[a] + 256 * op_byte(b) + rem_byte(b)].cint +#define kern_base_offset (256 * (128 + min_quarterword)) +#define lig_kern_start(a, b) lig_kern_base[a] + rem_byte(b) +#define lig_kern_restart(a, b) lig_kern_base[a] + 256 * op_byte(b) + rem_byte(b) + 32768 - kern_base_offset +/* sec 0558 */ +#define param(a, b) font_info[a + param_base[b]].cint +#define slant(f) param(slant_code, f) +#define space(f) param(space_code, f) +#define space_stretch(f) param(space_stretch_code, f) +#define space_shrink(f) param(space_shrink_code, f) +#define x_height(f) param(x_height_code, f) +#define quad(f) param(quad_code, f) +#define extra_space(f) param(extra_space_code, f) +/* sec 0561 */ +#define start_font_error_message() \ +do \ +{ \ + print_err("Font "); \ + sprint_cs(u); \ + print_char('='); \ + print_file_name(nom, aire, 335); \ + \ + if (s >= 0) \ + { \ + prints(" at "); \ + print_scaled(s); \ + prints("pt"); \ + } \ + else if (s != -1000) \ + { \ + prints(" scaled "); \ + print_int(-(integer)s); \ + } \ +} \ +while (0) +/* sec 0564 */ +#define read_sixteen(a) \ +do \ + { \ + a = fbyte; \ + \ + if (a > 127) \ + goto bad_tfm; \ + \ + fget(); \ + a = a * 256 + fbyte;\ + } \ +while (0) +#define store_four_quarters(val) \ +do \ + { \ + fget(); a = fbyte; qw.b0 = a; \ + fget(); b = fbyte; qw.b1 = b; \ + fget(); c = fbyte; qw.b2 = c; \ + fget(); d = fbyte; qw.b3 = d; \ + val = qw; \ + } \ +while (0) +/* sec 0570 */ +#define check_byte_range(a) \ +do \ +{ \ + if ((a < bc) || (a > ec)) \ + goto bad_tfm; \ +} \ + while (0) +/* sec 0571 */ +#define store_scaled(a) \ +do \ +{ \ + fget(); a = fbyte; fget(); b = fbyte; \ + fget(); c = fbyte; fget(); d = fbyte; \ + sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;\ + \ + if (a == 0) \ + a = sw; \ + else if (a == 255) \ + a = sw - alpha; \ + else \ + goto bad_tfm; \ +} \ +while (0) +/* sec 0573 */ +#define check_existence(a) \ +do \ +{ \ + check_byte_range(a); \ + \ + qw = char_info(f, a); \ + \ + if (!char_exists(qw)) \ + goto bad_tfm; \ +} \ +while (0) +/* sec 0576 */ +#define adjust(a) a[f] = a[f] +/* sec 0585 */ +#define set1 128 // c[1] +#define set2 129 // c[2] +#define set3 130 // c[3] +#define set4 131 // c[4] +#define set_rule 132 // a[4] b[4] +#define put1 133 // c[1] +#define put2 134 // c[2] +#define put3 135 // c[3] +#define put4 136 // c[4] +#define put_rule 137 // a[4] b[4] +#define nop 138 // NULL +#define bop 139 // c0[4] c1[4] ... c9[4] p[4] +#define eop 140 // NULL +#define push 141 +#define pop 142 +#define right1 143 // b[1] +#define right2 144 // b[2] +#define right3 145 // b[3] +#define right4 146 // b[4] +#define w0 147 // +#define w1 148 // b[1] +#define w2 149 // b[2] +#define w3 150 // b[3] +#define w4 151 // b[4] +#define x0 152 // +#define x1 153 // b[1] +#define x2 154 // b[2] +#define x3 155 // b[3] +#define x4 156 // b[4] +#define down1 157 // a[1] +#define down2 158 // a[2] +#define down3 159 // a[3] +#define down4 160 // a[4] +#define y0 161 // +#define y1 162 // a[1] +#define y2 163 // a[2] +#define y3 164 // a[3] +#define y4 165 // a[4] +#define z0 166 // +#define z1 167 // a[1] +#define z2 168 // a[2] +#define z3 169 // a[3] +#define z4 170 // a[4] +#define fnt_num_0 171 // +#define fnt1 235 // k[1] +#define fnt2 236 // k[2] +#define fnt3 237 // k[3] +#define fnt4 238 // k[4] +#define xxx1 239 // k[1] x[k] +#define xxx2 240 // k[2] x[k] +#define xxx3 241 // k[3] x[k] +#define xxx4 242 // k[4] x[k] +#define fnt_def1 243 // k[1] c[4] s[4] d[4] a[1] l[1] n[a + l] +#define fnt_def2 244 // k[2] c[4] s[4] d[4] a[1] l[1] n[a + l] +#define fnt_def3 245 // k[3] c[4] s[4] d[4] a[1] l[1] n[a + l] +#define fnt_def4 246 // k[4] c[4] s[4] d[4] a[1] l[1] n[a + l] +#define pre 247 // i[1] num[4] den[4] mag[4] k[1] x[k] +#define post 248 // +#define post_post 249 // +/* sec 0587 */ +#define id_byte 2 +/* sec 0605 */ +#define movement_node_size 3 +#define location(a) mem[a + 2].cint +/* sec 0608 */ +#define y_here 1 +#define z_here 2 +#define yz_OK 3 +#define y_OK 4 +#define z_OK 5 +#define d_fixed 6 +/* sec 0611 */ +#define none_seen 0 +#define y_seen 6 +#define z_seen 12 +/* sec 0625 */ +#define billion 1000000000.0 +#define vet_glue(a) \ +do \ +{ \ + glue_temp = a; \ + if (glue_temp > billion) \ + glue_temp = billion; \ + else if (glue_temp < -billion)\ + glue_temp = -billion; \ +} \ +while (0) +/* sec 0644 */ +#define exactly 0 +#define additional 1 +#define natural 0, additional +/* sec 0769 */ +#define u_part(a) mem[(a) + height_offset].cint +#define v_part(a) mem[(a) + depth_offset].cint +#define extra_info(a) info((a) + list_offset) +/* sec 0681 */ +#define noad_size 4 +#define nucleus(a) ((a) + 1) +#define supscr(a) ((a) + 2) +#define subscr(a) ((a) + 3) +#define math_type link +#define fam font +#define math_char 1 +#define sub_box 2 +#define sub_mlist 3 +#define math_text_char 4 +/* sec 0682 */ +#define ord_noad (unset_node + 3) // 16 +#define op_noad (ord_noad + 1 ) // 17 +#define bin_noad (ord_noad + 2 ) // 18 +#define rel_noad (ord_noad + 3 ) // 19 +#define open_noad (ord_noad + 4 ) // 20 +#define close_noad (ord_noad + 5 ) // 21 +#define punct_noad (ord_noad + 6 ) // 22 +#define inner_noad (ord_noad + 7 ) // 23 +#define limits 1 +#define no_limits 2 +/* sec 0683 */ +#define left_delimiter(a) ((a) + 4) +#define right_delimiter(a) ((a) + 5) +#define radical_noad (inner_noad + 1) // 24 +#define radical_noad_size 5 +#define fraction_noad (radical_noad + 1) // 25 +#define fraction_noad_size 6 +#define small_fam(a) mem[(a)].qqqq.b0 +#define small_char(a) mem[(a)].qqqq.b1 +#define large_fam(a) mem[(a)].qqqq.b2 +#define large_char(a) mem[(a)].qqqq.b3 +#define thickness width +#define default_code 010000000000L +#define numerator supscr +#define denominator subscr +/* sec 0687 */ +#define under_noad (fraction_noad + 1) // 26 +#define over_noad (under_noad + 1 ) // 27 +#define accent_noad (over_noad + 1 ) // 28 +#define accent_noad_size 5 +#define accent_chr(a) (a) + 4 +#define vcenter_noad (accent_noad + 1 ) // 29 +#define left_noad (vcenter_noad + 1 ) // 30 +#define right_noad (left_noad + 1 ) // 31 +#define delimiter nucleus +#define script_allowed(a) ((type(a) >= ord_noad) && (type(a) < left_noad)) +/* sec 0688 */ +#define style_node (unset_node + 1) +#define style_node_size 3 +#define display_style 0 +#define text_style 2 +#define script_style 4 +#define script_script_style 6 +#define cramped 1 +/* sec 0689 */ +#define choice_node (unset_node + 2) +#define display_mlist(a) info(a + 1) +#define text_mlist(a) link(a + 1) +#define script_mlist(a) info(a + 2) +#define script_script_mlist(a) link(a + 2) +/* sec 0699 */ +#define text_size 0 +#define script_size 16 +#define script_script_size 32 +/* sec 0700 */ +#define mathsy(a, b) font_info[a + param_base[fam_fnt(2 + b)]].cint +#define math_x_height(a) mathsy(5, a) +#define math_quad(a) mathsy(6, a) +#define num1(a) mathsy(8, a) +#define num2(a) mathsy(9, a) +#define num3(a) mathsy(10, a) +#define denom1(a) mathsy(11, a) +#define denom2(a) mathsy(12, a) +#define sup1(a) mathsy(13, a) +#define sup2(a) mathsy(14, a) +#define sup3(a) mathsy(15, a) +#define sub1(a) mathsy(16, a) +#define sub2(a) mathsy(17, a) +#define sup_drop(a) mathsy(18, a) +#define sub_drop(a) mathsy(19, a) +#define delim1(a) mathsy(20, a) +#define delim2(a) mathsy(21, a) +#define axis_height(a) mathsy(22, a) +#define total_mathsy_params 22 +/* sec 0701 */ +#define mathex(a) font_info[(a) + param_base[fam_fnt(3 + cur_size)]].cint +#define default_rule_thickness mathex(8) +#define big_op_spacing1 mathex(9) +#define big_op_spacing2 mathex(10) +#define big_op_spacing3 mathex(11) +#define big_op_spacing4 mathex(12) +#define big_op_spacing5 mathex(13) +#define total_mathex_params 13 +/* sec 0702 */ +#define cramped_style(a) (2 * ((a) / 2) + cramped) +#define sub_style(a) (2 * ((a) / 4) + script_style + cramped) +#define sup_style(a) (2 * ((a) / 4) + script_style + ((a) % 2)) +#define num_style(a) ((a) + 2 - 2 * ((a) / 6)) +#define denom_style(a) (2 * ((a) / 2) + cramped + 2 - 2 * ((a) / 6)) +/* sec 0716 */ +#define mu_mult(a) nx_plus_y(n, a, xn_over_d(a, f, 0200000)) +/* sec 0725 */ +#define new_hlist(a) mem[nucleus(a)].cint +/* sec 0731 */ +#define choose_mlist(a) \ +do \ +{ \ + p = a(q); \ + a(q) = 0; \ +} \ +while (0) +/* sec 0770 */ +#define preamble link(align_head) +#define align_stack_node_size 5 +/* sec 0780 */ +#define span_code 256 +#define cr_code 257 +#define cr_cr_code (cr_code + 1) +#define end_template_token (cs_token_flag + frozen_end_template) +/* sec 0797 */ +#define span_node_size 2 +/* sec 0817 */ +#define tight_fit 3 +#define loose_fit 1 +#define very_loose_fit 0 +#define decent_fit 2 +/* sec 0819 */ +#define active_node_size 3 +#define fitness subtype +#define break_node rlink +#define line_number llink +#define total_demerits(a) mem[a + 2].cint +#define unhyphenated 0 +#define hyphenated 1 +#define last_active active +/* sec 0821 */ +#define passive_node_size 2 +#define cur_break rlink +#define prev_break llink +#define serial info +/* sec 0822 */ +#define delta_node_size 7 +#define delta_node 2 +/* sec 0823 */ +#define do_all_six(a) \ +do \ +{ \ + a(1); a(2); a(3); \ + a(4); a(5); a(6); \ +} \ +while (0) +/* sec 0825 */ +#define check_shrinkage(s) \ +do \ +{ \ + if ((shrink_order(s) != normal) && (shrink(s) != 0))\ + s = finite_shrink(s); \ +} \ +while (0) +/* sec 0829 */ +#define copy_to_cur_active(a) cur_active_width[a] = active_width[a] +/* sec 0832 */ +#define update_width(a) cur_active_width[a] = cur_active_width[a] + mem[r + (a)].cint +/* sec 0833 */ +#define awful_bad 07777777777 +/* sec 0837 */ +#define set_break_width_to_background(a) break_width[a] = background[a] +/* sec 0843 */ +#define convert_to_break_width(a) mem[prev_r + (a)].cint = mem[prev_r + (a)].cint - cur_active_width[a] + break_width[a] +#define store_break_width(a) active_width[a] = break_width[a] +#define new_delta_to_break_width(a) mem[q + (a)].cint = break_width[(a)] - cur_active_width[(a)] +/* sec 0844 */ +#define new_delta_from_break_width(a) mem[q + (a)].cint = cur_active_width[(a)] - break_width[(a)] +/* sec 0860 */ +#define combine_two_deltas(a) mem[prev_r + (a)].cint = mem[prev_r + (a)].cint + mem[r + (a)].cint +#define downdate_width(a) cur_active_width[(a)] = cur_active_width[(a)] - mem[prev_r + (a)].cint +/* sec 0861 */ +#define update_active(a) active_width[(a)] = active_width[(a)] + mem[r + (a)].cint +/* sec 0864 */ +#define store_background(a) active_width[a] = background[a] +/* sec 0866 */ +#define act_width active_width[1] +#define kern_break() \ +do \ +{ \ + if (!is_char_node(link(cur_p)) && auto_breaking) \ + if (type(link(cur_p)) == glue_node) \ + try_break(0, unhyphenated); \ + \ + act_width = act_width + width(cur_p); \ +} \ +while (0) +/* sec 0877 */ +#define next_break prev_break +/* sec 0908 */ +#define append_charnode_to_t(a) \ +do \ + { \ + link(t) = get_avail(); \ + t = link(t); \ + font(t) = hf; \ + character(t) = (a); \ + } \ +while (0) +#define set_cur_r() \ +do \ + { \ + if (j < n) \ + cur_r = hu[j + 1]; \ + else \ + cur_r = bchar; \ + \ + if (odd(hyf[j])) \ + cur_rh = hchar; \ + else \ + cur_rh = non_char; \ + } \ +while (0) +/* sec 0910 */ +#define wrap_lig(a) \ +do \ +{ \ + if (ligature_present) \ + { \ + p = new_ligature(hf, cur_l, link(cur_q)); \ + \ + if (lft_hit) \ + { \ + subtype(p) = 2; \ + lft_hit = false; \ + } \ + \ + if ((a)) \ + if (lig_stack == 0) \ + { \ + incr(subtype(p)); \ + rt_hit = false; \ + } \ + \ + link(cur_q) = p; \ + t = p; \ + ligature_present = false; \ + } \ +} \ +while (0) +#define pop_lig_stack() \ +do \ + { \ + if (lig_ptr(lig_stack) != 0) \ + { \ + link(t) = lig_ptr(lig_stack); \ + t = link(t); \ + incr(j); \ + } \ + \ + p = lig_stack; \ + lig_stack = link(p); \ + free_node(p, small_node_size); \ + \ + if (lig_stack == 0) \ + { \ + set_cur_r(); \ + } \ + else \ + cur_r = character(lig_stack); \ + } \ +while (0) +/* sec 0914 */ +#define advance_major_tail() \ +do \ + { \ + major_tail = link(major_tail); \ + incr(r_count); \ + } \ +while (0) +/* sec 0970 */ +#define active_height active_width +#define cur_height active_height[1] +#define set_height_zero(a) active_width[(a)] = 0 +/* sec 0974 */ +#define deplorable 100000L +/* sec 0980 */ +#define inserts_only 1 +#define box_there 2 +/* sec 0981 */ +#define page_ins_node_size 4 +#define inserting 0 +#define split_up 1 +#define broken_ptr(a) link(a + 1) +#define broken_ins(a) info(a + 1) +#define last_ins_ptr(a) link(a + 2) +#define best_ins_ptr(a) info(a + 2) +/* sec 0982 */ +#define page_goal page_so_far[0] +#define page_total page_so_far[1] +#define page_shrink page_so_far[6] +#define page_depth page_so_far[7] +/* sec 0987 */ +#define set_page_so_far_zero(a) page_so_far[(a)] = 0 +/* sec 1034 */ +#define adjust_space_factor() \ +do \ +{ \ + main_s = sf_code(cur_chr); \ + if (main_s == 1000) \ + space_factor = 1000; \ + else if (main_s < 1000) \ + { \ + if (main_s > 0) \ + space_factor = main_s; \ + } \ + else if (space_factor < 1000) \ + space_factor = 1000; \ + else \ + space_factor = main_s; \ +} \ +while (0) +/* sec 1035 */ +/* -> false */ +#define wrapup(a) \ +do \ +{ \ + if (cur_l < non_char) \ + { \ + if (link(cur_q) != 0) \ + if (character(tail) == hyphen_char[main_f]) \ + ins_disc = true; \ + \ + if (ligature_present) \ + { \ + main_p = new_ligature(main_f, cur_l, link(cur_q)); \ + \ + if (lft_hit) \ + { \ + subtype(main_p) = 2; \ + lft_hit = false; \ + } \ + \ + if (a) \ + if (lig_stack == 0) \ + { \ + incr(subtype(main_p)); \ + rt_hit = false; \ + } \ + \ + link(cur_q) = main_p; \ + tail = main_p; \ + ligature_present = false; \ + } \ + \ + if (ins_disc) \ + { \ + ins_disc = false; \ + \ + if (mode > 0) \ + { \ + tail_append(new_disc()); \ + } \ + } \ + } \ +} \ +while (0) +/* sec 1045 */ +#define any_mode(a) vmode + a: case hmode + a: case mmode + a +/* sec 1046 */ +#define non_math(a) vmode + a: case hmode + a +/* sec 1058 */ +#define fil_code 0 +#define fill_code 1 +#define ss_code 2 +#define fil_neg_code 3 +#define skip_code 4 +#define mskip_code 5 +/* sec 1071 */ +#define box_flag 010000000000 +#define ship_out_flag (box_flag + 512) +#define leader_flag (box_flag + 513) +#define box_code 0 +#define copy_code 1 +#define last_box_code 2 +#define vsplit_code 3 +#define vtop_code 4 +/* sec 1178 */ +#define above_code 0 +#define over_code 1 +#define atop_code 2 +#define delimited_code 3 +/* sec 1214 */ +#define define(p, t, e) \ +do \ +{ \ + if (a >= 4) \ + geq_define(p, t, e);\ + else \ + eq_define(p, t, e); \ +} \ +while (0) +#define word_define(p, w) \ +do \ +{ \ + if (a >= 4) \ + geq_word_define(p, w);\ + else \ + eq_word_define(p, w); \ +} \ +while (0) +/* sec 1222 */ +#define char_def_code 0 +#define math_char_def_code 1 +#define count_def_code 2 +#define dimen_def_code 3 +#define skip_def_code 4 +#define mu_skip_def_code 5 +#define toks_def_code 6 +/* sec 1290 */ +#define show_code 0 +#define show_box_code 1 +#define show_the_code 2 +#define show_lists 3 +/* sec 1306 */ +#define undump(va, vb, vc) \ +do \ + { \ + undump_int(x); \ + \ + if ((x < (va)) || (x > (vb))) \ + goto bad_fmt; \ + else \ + vc = x; \ + } \ +while (0) +/* sec 1342 */ +#define write_node_size 2 +#define open_node_size 3 +#define open_node 0 +#define write_node 1 +#define close_node 2 +#define special_node 3 +#define language_node 4 +#define what_lang(s) link(s+1) +#define what_lhm(s) type(s+1) +#define what_rhm(s) subtype(s+1) +#define write_tokens(s) link(s+1) +#define write_stream(s) info(s+1) +#define open_name(s) link(s+1) +#define open_area(s) info(s+2) +#define open_ext(s) link(s+2) +/* sec 1344 */ +#define immediate_code 4 +#define set_language_code 5 +/* sec 1371 */ +#define end_write_token (cs_token_flag + end_write) + #endif \ No newline at end of file diff --git a/src/texsourc/makefile.txt b/src/texsourc/makefile.txt index b06ac29..82b8b63 100644 --- a/src/texsourc/makefile.txt +++ b/src/texsourc/makefile.txt @@ -1,17 +1,17 @@ -Copyright 2007 TeX Users Group. -Copyright 2014 Clerk Ma. -You may freely use, modify and/or distribute this file. - - makefile 9945 1-09-95 8:20a current selected - makefile.ms 9843 1-09-95 7:42a MS LINK - makefile.dbg 10449 1-09-95 8:11a debugging version MS LINK WINICE - makefile.tnt 9262 1-08-95 9:49a 386 | LINK - -Note: WINICE DBG2MAP only works on NT style PE files - -Note: WINICE MSYM needs loads of memory - -Note: MS LINK needs /DEBUG and /DEBUGSTYLE{CV|COFF|BOTH} for debugging info - -Note: Can't run as NT style because if INT 21h calls (_dos_find...) - or maybe other reasons also... (pharlap.h, pldos32.h) +Copyright 2007 TeX Users Group. +Copyright 2014 Clerk Ma. +You may freely use, modify and/or distribute this file. + + makefile 9945 1-09-95 8:20a current selected + makefile.ms 9843 1-09-95 7:42a MS LINK + makefile.dbg 10449 1-09-95 8:11a debugging version MS LINK WINICE + makefile.tnt 9262 1-08-95 9:49a 386 | LINK + +Note: WINICE DBG2MAP only works on NT style PE files + +Note: WINICE MSYM needs loads of memory + +Note: MS LINK needs /DEBUG and /DEBUGSTYLE{CV|COFF|BOTH} for debugging info + +Note: Can't run as NT style because if INT 21h calls (_dos_find...) + or maybe other reasons also... (pharlap.h, pldos32.h) diff --git a/src/texsourc/memory.h b/src/texsourc/memory.h index ead6eff..77cd1ec 100644 --- a/src/texsourc/memory.h +++ b/src/texsourc/memory.h @@ -1,73 +1,73 @@ -/* Copyright 1992 Karl Berry - Copyright 2007 TeX Users Group - Copyright 2014 Clerk Ma - - 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -/* - meaning structure TeX Y&Y TeX - ---------------------------------------------------------------------- - integer | int || 4: long | 8: long long | min_quarterword 0 - ---------------------------------------------------------------------- max_quarterword FFFF - scaled | sc || 4: long | 8: long long | min_halfword - ---------------------------------------------------------------------- - glue_ratio | gr || 4: float | 8: double | - ---------------------------------------------------------------------- - halfword | lh | rh || 2: unsigned short | 4: unsigned long | - ---------------------------------------------------------------------- - half+quarter | b0 | b1 | rh || | - ---------------------------------------------------------------------- - quarter | b0 | b1 | b2 | b3 || 1: unsigned char | 2: unsigned short | - ---------------------------------------------------------------------- -*/ -#ifndef _YANDYTEX_MEMORY_H -#define _YANDYTEX_MEMORY_H - -typedef struct -{ -#ifdef WORDS_BIGENDIAN - halfword rh; - - union - { - halfword lh; - - struct - { - quarterword b0, b1; - }; - }; -#endif -} two_halves; - -typedef struct -{ -#ifdef WORDS_BIGENDIAN - quarterword b0, b1, b2, b3; -#else - quarterword b3, b2, b1, b0; -#endif -} four_quarters; - -typedef union -{ - glue_ratio gr; - two_halves hh; - integer cint; - four_quarters qqqq; -} memory_word; - +/* Copyright 1992 Karl Berry + Copyright 2007 TeX Users Group + Copyright 2014 Clerk Ma + + 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ + +/* + meaning structure TeX Y&Y TeX + ---------------------------------------------------------------------- + integer | int || 4: long | 8: long long | min_quarterword 0 + ---------------------------------------------------------------------- max_quarterword FFFF + scaled | sc || 4: long | 8: long long | min_halfword + ---------------------------------------------------------------------- + glue_ratio | gr || 4: float | 8: double | + ---------------------------------------------------------------------- + halfword | lh | rh || 2: unsigned short | 4: unsigned long | + ---------------------------------------------------------------------- + half+quarter | b0 | b1 | rh || | + ---------------------------------------------------------------------- + quarter | b0 | b1 | b2 | b3 || 1: unsigned char | 2: unsigned short | + ---------------------------------------------------------------------- +*/ +#ifndef _YANDYTEX_MEMORY_H +#define _YANDYTEX_MEMORY_H + +typedef struct +{ +#ifdef WORDS_BIGENDIAN + halfword rh; + + union + { + halfword lh; + + struct + { + quarterword b0, b1; + }; + }; +#endif +} two_halves; + +typedef struct +{ +#ifdef WORDS_BIGENDIAN + quarterword b0, b1, b2, b3; +#else + quarterword b3, b2, b1, b0; +#endif +} four_quarters; + +typedef union +{ + glue_ratio gr; + two_halves hh; + integer cint; + four_quarters qqqq; +} memory_word; + #endif \ No newline at end of file diff --git a/src/texsourc/notes.txt b/src/texsourc/notes.txt index 17d7099..99ef573 100644 --- a/src/texsourc/notes.txt +++ b/src/texsourc/notes.txt @@ -1,39 +1,39 @@ -Copyright 2007 TeX Users Group. -Copyright 2014 Clerk Ma. -You may freely use, modify and/or distribute this file. - -use \write18{...} to execute system commmands? - -use openany_out to allow opening `special' files that should -otherwise be prohibited (on Unix, files starting with .)? - -********************************************************************** - -Notes: Making adjustable hash-table version: - -win web2c twice with different hash_size and hash_prime - -collection the *.c and *.h files in each case - -run comaptex.exe on these files to mark all uses of hash_size and hash_prime - -reconcile difference with existing *.c and *.h files - -********************************************************************** - -Notes: there are still a few places where we may be able to -go from 256 to (maxquarterword + 1) (or 255 to maxquarterword): -itex.c (info(end_span) <- null p.797) -tex1.c (overflow of grouping levels p.274), -tex5.c (confusion(256 spans) p.798), -tex7.c (replace_count(tail) p.1120) - -********************************************************************** - -internal_font_number --> true name --> HPDF_Font -1 | cmr10 | 1 -2 | cmr10 | 1 -3 | cmmi10 | 2 - -BOX -> BOX -> BOX -> BOX -BT -> FONT -> CUR_XY -> ET +Copyright 2007 TeX Users Group. +Copyright 2014 Clerk Ma. +You may freely use, modify and/or distribute this file. + +use \write18{...} to execute system commmands? + +use openany_out to allow opening `special' files that should +otherwise be prohibited (on Unix, files starting with .)? + +********************************************************************** + +Notes: Making adjustable hash-table version: + +win web2c twice with different hash_size and hash_prime + +collection the *.c and *.h files in each case + +run comaptex.exe on these files to mark all uses of hash_size and hash_prime + +reconcile difference with existing *.c and *.h files + +********************************************************************** + +Notes: there are still a few places where we may be able to +go from 256 to (maxquarterword + 1) (or 255 to maxquarterword): +itex.c (info(end_span) <- null p.797) +tex1.c (overflow of grouping levels p.274), +tex5.c (confusion(256 spans) p.798), +tex7.c (replace_count(tail) p.1120) + +********************************************************************** + +internal_font_number --> true name --> HPDF_Font +1 | cmr10 | 1 +2 | cmr10 | 1 +3 | cmmi10 | 2 + +BOX -> BOX -> BOX -> BOX +BT -> FONT -> CUR_XY -> ET diff --git a/src/texsourc/openinou.c b/src/texsourc/openinou.c index 80db414..a8a2227 100644 --- a/src/texsourc/openinou.c +++ b/src/texsourc/openinou.c @@ -1,398 +1,398 @@ -/* Copyright 1992 Karl Berry - Copyright 2007 TeX Users Group - Copyright 2014 Clerk Ma - - 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#define EXTERN extern - -#include "yandytex.h" -#undef name - -#define PATH_SEP '/' -#define PATH_SEP_STRING "/" - -#define BUILDNAMEDIRECT - -extern int shorten_file_name; - -#ifdef FUNNY_CORE_DUMP - extern void funny_core_dump(void); -#endif - -#ifdef BUILDNAMEDIRECT -char * xconcat (char * buffer, char * s1, char * s2) -{ - int n1 = strlen(s1); - int n2 = strlen(s2); - - if (buffer == s2) - { - memmove(buffer + n1, buffer, n2 + 1); - strncpy(buffer, s1, n1); - } - else - { - strcpy(buffer, s1); - strcat(buffer + n1, s2); - } - - return buffer; -} -char * xconcat3 (char *buffer, char *s1, char *s2, char *s3) -{ - int n1 = strlen(s1); - int n2 = strlen(s2); - int n3 = strlen(s3); - - if (buffer == s3) - { - memmove(buffer + n1 + n2, buffer, n3 + 1); - strncpy(buffer, s1, n1); - strncpy(buffer + n1, s2, n2); - } - else - { - strcpy(buffer, s1); - strcat(buffer + n1, s2); - strcat(buffer + n1 + n2, s3); - } - - return buffer; -} -#endif - -void patch_in_path (ASCII_code * buffer, ASCII_code *name, ASCII_code * path) -{ - if (*path == '\0') - strcpy((char *) buffer, (char *) name); - else - xconcat3((char *) buffer, (char *) path, "/", (char *) name); -} - -int qualified (ASCII_code * name) -{ - if (strchr((char *) name, '/') != NULL || - strchr((char *) name, '\\') != NULL || - strchr((char *) name, ':') != NULL) - return 1; - else - return 0; -} -/* patch path if - (i) path not empty - (ii) name not qualified - (iii) ext match -*/ -int prepend_path_if(ASCII_code * buffer, ASCII_code * name, const char * ext, char *path) -{ - if (path == NULL) - return 0; - - if (*path == '\0') - return 0; - - if (qualified(name)) - return 0; - - if (strstr((char *) name, ext) == NULL) - return 0; - - patch_in_path(buffer, name, (ASCII_code *)path); - - return 1; -} - -// Following works on null-terminated strings -void check_short_name (unsigned char *s) -{ - unsigned char *star, *sdot; - int n; - - if ((star = (unsigned char *) strrchr((char *) s, '\\')) != NULL) - star++; - else if ((star = (unsigned char *) strrchr((char *) s, '/')) != NULL) - star++; - else if ((star = (unsigned char *) strchr((char *) s, ':')) != NULL) - star++; - else - star = s; - - if ((sdot = (unsigned char *) strchr((char *) star, '.')) != NULL) - n = sdot - star; - else - n = strlen((char *) star); - - if (n > 8) - strcpy((char *) star + 8, (char *) star + n); - - if ((sdot = (unsigned char *) strchr((char *) star, '.')) != NULL) - { - star = sdot + 1; - - n = strlen((char *) star); - - if (n > 3) - *(star + 3) = '\0'; - } -} - -/* Following works on both null-terminated names */ - -void retwiddle (unsigned char *s) -{ - while (*s != '\0') - { - if (*s == (unsigned char) pseudo_tilde) - *s = '~'; - else if (*s == (unsigned char) pseudo_space) - *s = ' '; - - s++; - } -} - -boolean open_input (FILE ** f, kpse_file_format_type file_fmt, const char * fopen_mode) -{ - boolean openable = false; - char * file_name = NULL; - -#if defined (FUNNY_CORE_DUMP) && !defined (BibTeX) - if (file_fmt == kpse_tex_format && - strncmp(name_of_file + 1, "HackyInputFileNameForCoreDump.tex", 33) == 0) - funny_core_dump(); -#endif - - if (return_flag) - { - if (strcmp(fopen_mode, "r") == 0) - fopen_mode = "rb"; - } - - name_of_file[name_length + 1] = '\0'; - - /* reinsert '~' and ' ' in file names */ - if (pseudo_tilde != 0 || pseudo_space != 0) - retwiddle(name_of_file + 1); - - if (shorten_file_name) - check_short_name(name_of_file + 1); - - if (open_trace_flag) - printf(" Open `%s' for input ", name_of_file + 1); - - file_name = kpse_find_file((const_string) name_of_file + 1, file_fmt, false); - - if (file_name != NULL) - { - strcpy ((char *) name_of_file + 1, file_name); - *f = xfopen((char *) file_name, fopen_mode); - -#ifdef _WIN32 - if (name_of_file[1] == '.' && (name_of_file[2] == PATH_SEP || name_of_file[2] == '\\')) -#else - if (name_of_file[1] == '.' && name_of_file[2] == PATH_SEP) -#endif - { - unsigned i = 1; - - while (name_of_file[i + 2] != '\0') - { - name_of_file[i] = name_of_file[i + 2]; - i++; - } - - name_of_file[i] = '\0'; - name_length = i - 1; - } - else - name_length = strlen((char *) name_of_file + 1); - - if (file_fmt == kpse_tfm_format) - { - fbyte = getc(*f); - } - - if (strstr((char *) name_of_file + 1, ".fmt") != NULL) - { - if (format_file == NULL) - format_file = xstrdup((char *) name_of_file + 1); - -#ifdef COMPACTFORMAT - gz_fmt_file = gzdopen(fileno(*f), "rb9"); -#endif - } - else if (strstr((char *) name_of_file + 1, ".tfm") != NULL) - { - if (show_tfm_flag && log_opened) - { - int n; - n = strlen((char *) name_of_file + 1); - - if (file_offset + n > max_print_line) - { - (void) putc('\n', log_file); - file_offset = 0; - } - else - (void) putc(' ', log_file); - - fprintf(log_file, "(%s)", name_of_file + 1); - file_offset += n + 3; - } - } - else if (source_direct == NULL) - { - char *s; - - source_direct = xstrdup((char *) name_of_file + 1); - - if (trace_flag) - printf("Methinks the source %s is `%s'\n", "file", source_direct); - - if ((s = strrchr(source_direct, '/')) == NULL) - *source_direct = '\0'; - else - *(s + 1) = '\0'; - - if (trace_flag) - printf("Methinks the source %s is `%s'\n", "directory", source_direct); - } - - openable = true; - } - - { - unsigned temp_length = strlen((char *) name_of_file + 1); - name_of_file[temp_length + 1] = ' '; - } - - return openable; -} - -/* At least check for I/O error (such as disk full) when closing */ -/* Would be better to check while writing - but this is better than nothing */ -/* This is used for both input and output files, but never mind ... */ - -/* now a_close returns -1 on error --- which could be used by caller */ -/* probably want to ignore on input files ... */ - -// check_fclose not used by anything -int check_fclose (FILE * f) -{ - if (f == NULL) - return 0; - - if (ferror(f) || fclose (f)) - { - perrormod("\n! I/O Error"); - uexit(EXIT_FAILURE); - } - - return 0; -} - -char * xstrdup_name (void) -{ - if (qualified(name_of_file + 1)) - *log_line = '\0'; - else - { - (void) getcwd(log_line, sizeof(log_line)); - strcat(log_line, PATH_SEP_STRING); - } - - strcat(log_line, (char *) name_of_file + 1); - unixify(log_line); - return xstrdup(log_line); -} - -boolean open_output (FILE ** f, const char * fopen_mode) -{ - unsigned temp_length; - - name_of_file[name_length + 1] = '\0'; - - if (pseudo_tilde != 0 || pseudo_space != 0) - retwiddle(name_of_file + 1); - - /* 8 + 3 file names on Windows NT 95/Feb/20 */ - if (shorten_file_name) - check_short_name(name_of_file + 1); - - if (prepend_path_if(name_of_file + 1, name_of_file + 1, ".dvi", dvi_directory) || - prepend_path_if(name_of_file + 1, name_of_file + 1, ".log", log_directory) || - prepend_path_if(name_of_file + 1, name_of_file + 1, ".aux", aux_directory) || - prepend_path_if(name_of_file + 1, name_of_file + 1, ".fmt", fmt_directory) || - prepend_path_if(name_of_file + 1, name_of_file + 1, ".pdf", pdf_directory)) - { - if (open_trace_flag) - printf("After prepend %s\n", name_of_file + 1); - } - - if (open_trace_flag) - printf(" Open `%s' for output ", name_of_file + 1); - - *f = fopen((char *) name_of_file + 1, fopen_mode); - - if (*f == NULL) - { - string temp_dir = kpse_var_value("TEXMFOUTPUT"); - - if (temp_dir != NULL) - { -#ifdef BUILDNAMEDIRECT - unsigned char temp_name[file_name_size]; - xconcat3((char *) temp_name, temp_dir, PATH_SEP_STRING, (char *) name_of_file + 1); -#else - string temp_name = concat3(temp_dir, PATH_SEP_STRING, name_of_file + 1); -#endif - - if (deslash) - unixify((char *) temp_name); - - /* but we can assume this is opening here for *output* */ - *f = fopen((char *) temp_name, fopen_mode); - /* If this succeeded, change name_of_file accordingly. */ - if (*f) - strcpy((char *) name_of_file + 1, (char *) temp_name); - -#ifndef BUILDNAMEDIRECT - free (temp_name); -#endif - } - } - -#ifdef COMPACTFORMAT - if (strstr((char *) name_of_file + 1, ".fmt") != NULL) - gz_fmt_file = gzdopen(fileno(*f), "wb9"); -#endif - - if (strstr((char *) name_of_file + 1, ".dvi") != NULL) - dvi_file_name = xstrdup_name(); - else if (strstr((char *) name_of_file + 1, ".pdf") != NULL) - pdf_file_name = xstrdup_name(); - else if (strstr((char *) name_of_file + 1, ".log") != NULL) - log_file_name = xstrdup_name(); - - temp_length = strlen((char *) name_of_file + 1); - name_of_file[temp_length + 1] = ' '; - - if (*f) - name_length = temp_length; - - return (*f != NULL); +/* Copyright 1992 Karl Berry + Copyright 2007 TeX Users Group + Copyright 2014 Clerk Ma + + 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ + +#define EXTERN extern + +#include "yandytex.h" +#undef name + +#define PATH_SEP '/' +#define PATH_SEP_STRING "/" + +#define BUILDNAMEDIRECT + +extern int shorten_file_name; + +#ifdef FUNNY_CORE_DUMP + extern void funny_core_dump(void); +#endif + +#ifdef BUILDNAMEDIRECT +char * xconcat (char * buffer, char * s1, char * s2) +{ + int n1 = strlen(s1); + int n2 = strlen(s2); + + if (buffer == s2) + { + memmove(buffer + n1, buffer, n2 + 1); + strncpy(buffer, s1, n1); + } + else + { + strcpy(buffer, s1); + strcat(buffer + n1, s2); + } + + return buffer; +} +char * xconcat3 (char *buffer, char *s1, char *s2, char *s3) +{ + int n1 = strlen(s1); + int n2 = strlen(s2); + int n3 = strlen(s3); + + if (buffer == s3) + { + memmove(buffer + n1 + n2, buffer, n3 + 1); + strncpy(buffer, s1, n1); + strncpy(buffer + n1, s2, n2); + } + else + { + strcpy(buffer, s1); + strcat(buffer + n1, s2); + strcat(buffer + n1 + n2, s3); + } + + return buffer; +} +#endif + +void patch_in_path (ASCII_code * buffer, ASCII_code *name, ASCII_code * path) +{ + if (*path == '\0') + strcpy((char *) buffer, (char *) name); + else + xconcat3((char *) buffer, (char *) path, "/", (char *) name); +} + +int qualified (ASCII_code * name) +{ + if (strchr((char *) name, '/') != NULL || + strchr((char *) name, '\\') != NULL || + strchr((char *) name, ':') != NULL) + return 1; + else + return 0; +} +/* patch path if + (i) path not empty + (ii) name not qualified + (iii) ext match +*/ +int prepend_path_if(ASCII_code * buffer, ASCII_code * name, const char * ext, char *path) +{ + if (path == NULL) + return 0; + + if (*path == '\0') + return 0; + + if (qualified(name)) + return 0; + + if (strstr((char *) name, ext) == NULL) + return 0; + + patch_in_path(buffer, name, (ASCII_code *)path); + + return 1; +} + +// Following works on null-terminated strings +void check_short_name (unsigned char *s) +{ + unsigned char *star, *sdot; + int n; + + if ((star = (unsigned char *) strrchr((char *) s, '\\')) != NULL) + star++; + else if ((star = (unsigned char *) strrchr((char *) s, '/')) != NULL) + star++; + else if ((star = (unsigned char *) strchr((char *) s, ':')) != NULL) + star++; + else + star = s; + + if ((sdot = (unsigned char *) strchr((char *) star, '.')) != NULL) + n = sdot - star; + else + n = strlen((char *) star); + + if (n > 8) + strcpy((char *) star + 8, (char *) star + n); + + if ((sdot = (unsigned char *) strchr((char *) star, '.')) != NULL) + { + star = sdot + 1; + + n = strlen((char *) star); + + if (n > 3) + *(star + 3) = '\0'; + } +} + +/* Following works on both null-terminated names */ + +void retwiddle (unsigned char *s) +{ + while (*s != '\0') + { + if (*s == (unsigned char) pseudo_tilde) + *s = '~'; + else if (*s == (unsigned char) pseudo_space) + *s = ' '; + + s++; + } +} + +boolean open_input (FILE ** f, kpse_file_format_type file_fmt, const char * fopen_mode) +{ + boolean openable = false; + char * file_name = NULL; + +#if defined (FUNNY_CORE_DUMP) && !defined (BibTeX) + if (file_fmt == kpse_tex_format && + strncmp(name_of_file + 1, "HackyInputFileNameForCoreDump.tex", 33) == 0) + funny_core_dump(); +#endif + + if (return_flag) + { + if (strcmp(fopen_mode, "r") == 0) + fopen_mode = "rb"; + } + + name_of_file[name_length + 1] = '\0'; + + /* reinsert '~' and ' ' in file names */ + if (pseudo_tilde != 0 || pseudo_space != 0) + retwiddle(name_of_file + 1); + + if (shorten_file_name) + check_short_name(name_of_file + 1); + + if (open_trace_flag) + printf(" Open `%s' for input ", name_of_file + 1); + + file_name = kpse_find_file((const_string) name_of_file + 1, file_fmt, false); + + if (file_name != NULL) + { + strcpy ((char *) name_of_file + 1, file_name); + *f = xfopen((char *) file_name, fopen_mode); + +#ifdef _WIN32 + if (name_of_file[1] == '.' && (name_of_file[2] == PATH_SEP || name_of_file[2] == '\\')) +#else + if (name_of_file[1] == '.' && name_of_file[2] == PATH_SEP) +#endif + { + unsigned i = 1; + + while (name_of_file[i + 2] != '\0') + { + name_of_file[i] = name_of_file[i + 2]; + i++; + } + + name_of_file[i] = '\0'; + name_length = i - 1; + } + else + name_length = strlen((char *) name_of_file + 1); + + if (file_fmt == kpse_tfm_format) + { + fbyte = getc(*f); + } + + if (strstr((char *) name_of_file + 1, ".fmt") != NULL) + { + if (format_file == NULL) + format_file = xstrdup((char *) name_of_file + 1); + +#ifdef COMPACTFORMAT + gz_fmt_file = gzdopen(fileno(*f), "rb9"); +#endif + } + else if (strstr((char *) name_of_file + 1, ".tfm") != NULL) + { + if (show_tfm_flag && log_opened) + { + int n; + n = strlen((char *) name_of_file + 1); + + if (file_offset + n > max_print_line) + { + (void) putc('\n', log_file); + file_offset = 0; + } + else + (void) putc(' ', log_file); + + fprintf(log_file, "(%s)", name_of_file + 1); + file_offset += n + 3; + } + } + else if (source_direct == NULL) + { + char *s; + + source_direct = xstrdup((char *) name_of_file + 1); + + if (trace_flag) + printf("Methinks the source %s is `%s'\n", "file", source_direct); + + if ((s = strrchr(source_direct, '/')) == NULL) + *source_direct = '\0'; + else + *(s + 1) = '\0'; + + if (trace_flag) + printf("Methinks the source %s is `%s'\n", "directory", source_direct); + } + + openable = true; + } + + { + unsigned temp_length = strlen((char *) name_of_file + 1); + name_of_file[temp_length + 1] = ' '; + } + + return openable; +} + +/* At least check for I/O error (such as disk full) when closing */ +/* Would be better to check while writing - but this is better than nothing */ +/* This is used for both input and output files, but never mind ... */ + +/* now a_close returns -1 on error --- which could be used by caller */ +/* probably want to ignore on input files ... */ + +// check_fclose not used by anything +int check_fclose (FILE * f) +{ + if (f == NULL) + return 0; + + if (ferror(f) || fclose (f)) + { + perrormod("\n! I/O Error"); + uexit(EXIT_FAILURE); + } + + return 0; +} + +char * xstrdup_name (void) +{ + if (qualified(name_of_file + 1)) + *log_line = '\0'; + else + { + (void) getcwd(log_line, sizeof(log_line)); + strcat(log_line, PATH_SEP_STRING); + } + + strcat(log_line, (char *) name_of_file + 1); + unixify(log_line); + return xstrdup(log_line); +} + +boolean open_output (FILE ** f, const char * fopen_mode) +{ + unsigned temp_length; + + name_of_file[name_length + 1] = '\0'; + + if (pseudo_tilde != 0 || pseudo_space != 0) + retwiddle(name_of_file + 1); + + /* 8 + 3 file names on Windows NT 95/Feb/20 */ + if (shorten_file_name) + check_short_name(name_of_file + 1); + + if (prepend_path_if(name_of_file + 1, name_of_file + 1, ".dvi", dvi_directory) || + prepend_path_if(name_of_file + 1, name_of_file + 1, ".log", log_directory) || + prepend_path_if(name_of_file + 1, name_of_file + 1, ".aux", aux_directory) || + prepend_path_if(name_of_file + 1, name_of_file + 1, ".fmt", fmt_directory) || + prepend_path_if(name_of_file + 1, name_of_file + 1, ".pdf", pdf_directory)) + { + if (open_trace_flag) + printf("After prepend %s\n", name_of_file + 1); + } + + if (open_trace_flag) + printf(" Open `%s' for output ", name_of_file + 1); + + *f = fopen((char *) name_of_file + 1, fopen_mode); + + if (*f == NULL) + { + string temp_dir = kpse_var_value("TEXMFOUTPUT"); + + if (temp_dir != NULL) + { +#ifdef BUILDNAMEDIRECT + unsigned char temp_name[file_name_size]; + xconcat3((char *) temp_name, temp_dir, PATH_SEP_STRING, (char *) name_of_file + 1); +#else + string temp_name = concat3(temp_dir, PATH_SEP_STRING, name_of_file + 1); +#endif + + if (deslash) + unixify((char *) temp_name); + + /* but we can assume this is opening here for *output* */ + *f = fopen((char *) temp_name, fopen_mode); + /* If this succeeded, change name_of_file accordingly. */ + if (*f) + strcpy((char *) name_of_file + 1, (char *) temp_name); + +#ifndef BUILDNAMEDIRECT + free (temp_name); +#endif + } + } + +#ifdef COMPACTFORMAT + if (strstr((char *) name_of_file + 1, ".fmt") != NULL) + gz_fmt_file = gzdopen(fileno(*f), "wb9"); +#endif + + if (strstr((char *) name_of_file + 1, ".dvi") != NULL) + dvi_file_name = xstrdup_name(); + else if (strstr((char *) name_of_file + 1, ".pdf") != NULL) + pdf_file_name = xstrdup_name(); + else if (strstr((char *) name_of_file + 1, ".log") != NULL) + log_file_name = xstrdup_name(); + + temp_length = strlen((char *) name_of_file + 1); + name_of_file[temp_length + 1] = ' '; + + if (*f) + name_length = temp_length; + + return (*f != NULL); } \ No newline at end of file diff --git a/src/texsourc/pool.c b/src/texsourc/pool.c index 980fb76..1248619 100644 --- a/src/texsourc/pool.c +++ b/src/texsourc/pool.c @@ -1,1110 +1,1110 @@ -/* Copyright 2014 Clerk Ma - - 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#define EXTERN extern - -#include "yandytex.h" - -static const char * pool_file_arr[] = -{ -/* 0256 */ "", //"buffer size", -/* 0257 */ "", //"pool size", -/* 0258 */ "", //"number of strings", -/* 0259 */ "" "?" "?" "?", -/* 0260 */ "m2d5c2l5x2v5i", -/* 0261 */ "", //"End of file on the terminal!", -/* 0262 */ "", //"! ", -/* 0263 */ "", //"(That makes 100 errors; please try again.)", -/* 0264 */ "", // "? ", -/* 0265 */ "", //"Type to proceed, S to scroll future error messages,", -/* 0266 */ "", //"R to run without stopping, Q to run quietly,", -/* 0267 */ "", //"I to insert something, ", -/* 0268 */ "", //"E to edit your file,", -/* 0269 */ "", //"1 or ... or 9 to ignore the next 1 to 9 tokens of input,", -/* 0270 */ "", //"H for help, X to quit.", -/* 0271 */ "", //"OK, entering ", -/* 0272 */ "", //"batchmode", -/* 0273 */ "", //"nonstopmode", -/* 0274 */ "", //"scrollmode", -/* 0275 */ "", //"...", -/* 0276 */ "", //"insert>", -/* 0277 */ "", //"I have just deleted some text, as you asked.", -/* 0278 */ "", //"You can now delete more, or insert, or whatever.", -/* 0279 */ "", //"Sorry, I don't know how to help in this situation.", -/* 0280 */ "", //"Maybe you should try asking a human" "?", -/* 0281 */ "", //"Sorry, I already gave what help I could...", -/* 0282 */ "", //"An error might have occurred before I noticed any problems.", -/* 0283 */ "", //"``If all else fails, read the instructions.''", -/* 0284 */ "", //" (", -/* 0285 */ "", //"Emergency stop", -/* 0286 */ "", //"TeX capacity exceeded, sorry [", -/* 0287 */ "", //"If you really absolutely need more capacity,", -/* 0288 */ "", //"you can ask a wizard to enlarge me.", -/* 0289 */ "", //"This can't happen (", -/* 0290 */ "", //"I'm broken. Please show this to someone who can fix can fix", -/* 0291 */ "", //"I can't go on meeting you like this", -/* 0292 */ "", //"One of your faux pas seems to have wounded me deeply...", -/* 0293 */ "", //"in fact, I'm barely conscious. Please fix it and try again.", -/* 0294 */ "", //"Interruption", -/* 0295 */ "", //"You rang" "?", -/* 0296 */ "", //"Try to insert some instructions for me (e.g.,`I\\showlists'),", -/* 0297 */ "", //"unless you just want to quit by typing `X'.", -/* 0298 */ "", //"main memory size", -/* 0299 */ "", //"AVAIL list clobbered at ", -/* 0300 */ "", //"Double-AVAIL list clobbered at ", -/* 0301 */ "", //"Doubly free location at ", -/* 0302 */ "", //"Bad flag at ", -/* 0303 */ "", //"New busy locs:", -/* 0304 */ "", //"LINK(", -/* 0305 */ "", //"INFO(", -/* 0306 */ "", //"[]", -/* 0307 */ "", //"CLOBBERED.", -/* 0308 */ "", //"foul", -/* 0309 */ "", //"fil", -/* 0310 */ "", //" plus ", -/* 0311 */ "", //" minus ", -/* 0312 */ "", //" []", -/* 0313 */ "", //"Bad link, display aborted.", -/* 0314 */ "", //"etc.", -/* 0315 */ "", //"Unknown node type!", -/* 0316 */ "", //"unset", -/* 0317 */ "", //"box(", -/* 0318 */ "", //")x", -/* 0319 */ "", //", shifted ", -/* 0320 */ "", //" columns)", -/* 0321 */ "", //", stretch ", -/* 0322 */ "", //", shrink ", -/* 0323 */ "", //", glue set ", -/* 0324 */ "", //"- ", -/* 0325 */ "", //"< -", -/* 0326 */ "", //"rule(", -/* 0327 */ "", //"insert", -/* 0328 */ "", //", natural size ", -/* 0329 */ "", //"; split(", -/* 0330 */ "", //"); float cost ", -/* 0331 */ "", //"glue", -/* 0332 */ "", //"nonscript", -/* 0333 */ "", //"mskip", -/* 0334 */ "", //"mu", -/* 0335 */ "", -/* 0336 */ "", //"leaders ", -/* 0337 */ "", //"kern", -/* 0338 */ "", //" (for accent)", -/* 0339 */ "", //"mkern", -/* 0340 */ "", //"math", -/* 0341 */ "", //"on", -/* 0342 */ "", //"off", -/* 0343 */ "", //", surrounded ", -/* 0344 */ "", //" (ligature ", -/* 0345 */ "", //"penalty ", -/* 0346 */ "", //"discretionary", -/* 0347 */ "", //" replacing ", -/* 0348 */ "", //"mark", -/* 0349 */ "", //"vadjust", -/* 0350 */ "", //"flushing", -/* 0351 */ "", //"copying", -/* 0352 */ "", //"vertical", -/* 0353 */ "", //"horizontal", -/* 0354 */ "", //"display math", -/* 0355 */ "", //"no", -/* 0356 */ "", //"internal vertical", -/* 0357 */ "", //"restricted horizontal", -/* 0358 */ "", //" mode", -/* 0359 */ "", //"semantic nest size", -/* 0360 */ "", //"### ", -/* 0361 */ "", //" entered at line ", -/* 0362 */ "", //" (language", -/* 0363 */ "", //":hyphenmin", -/* 0364 */ "", //" (\\output routine)", -/* 0365 */ "", //"### recent contributions:", -/* 0366 */ "", //"prevdepth ", -/* 0367 */ "", //"ignored", -/* 0368 */ "", //", prevgraf ", -/* 0369 */ "", //" line", -/* 0370 */ "", //"spacefactor ", -/* 0371 */ "", //", current language ", -/* 0372 */ "", //"this will be denominator of:", -/* 0373 */ "", //"lineskip", -/* 0374 */ "", //"baselineskip", -/* 0375 */ "", //"parskip", -/* 0376 */ "", //"abovedisplayskip", -/* 0377 */ "", //"belowdisplayskip", -/* 0378 */ "", //"abovedisplayshortskip", -/* 0379 */ "", //"belowdisplayshortskip", -/* 0380 */ "", //"leftskip", -/* 0381 */ "", //"rightskip", -/* 0382 */ "", //"topskip", -/* 0383 */ "", //"splittopskip", -/* 0384 */ "", //"tabskip", -/* 0385 */ "", //"spaceskip", -/* 0386 */ "", //"xspaceskip", -/* 0387 */ "", //"parfillskip", -/* 0388 */ "", //"thinmuskip", -/* 0389 */ "", //"medmuskip", -/* 0390 */ "", //"thickmuskip", -/* 0391 */ "", //"[unknown glue parameter!]", -/* 0392 */ "", //"skip", -/* 0393 */ "", //"muskip", -/* 0394 */ "", //"pt", -/* 0395 */ "", //"output", -/* 0396 */ "", //"everypar", -/* 0397 */ "", //"everymath", -/* 0398 */ "", //"everydisplay", -/* 0399 */ "", //"everyhbox", -/* 0400 */ "", //"everyvbox", -/* 0401 */ "", //"everyjob", -/* 0402 */ "", //"everycr", -/* 0403 */ "", //"errhelp", -/* 0404 */ "", //"toks", -/* 0405 */ "", //"parshape", -/* 0406 */ "", //"box", -/* 0407 */ "", //"void", -/* 0408 */ "", //"current font", -/* 0409 */ "", //"textfont", -/* 0410 */ "", //"scriptfont", -/* 0411 */ "", //"scriptscriptfont", -/* 0412 */ "", //"catcode", -/* 0413 */ "", //"lccode", -/* 0414 */ "", //"uccode", -/* 0415 */ "", //"sfcode", -/* 0416 */ "", //"mathcode", -/* 0417 */ "", //"pretolerance", -/* 0418 */ "", //"tolerance", -/* 0419 */ "", //"linepenalty", -/* 0420 */ "", //"hyphenpenalty", -/* 0421 */ "", //"exhyphenpenalty", -/* 0422 */ "", //"clubpenalty", -/* 0423 */ "", //"widowpenalty", -/* 0424 */ "", //"displaywidowpenalty", -/* 0425 */ "", //"brokenpenalty", -/* 0426 */ "", //"binoppenalty", -/* 0427 */ "", //"relpenalty", -/* 0428 */ "", //"predisplaypenalty", -/* 0429 */ "", //"postdisplaypenalty", -/* 0430 */ "", //"interlinepenalty", -/* 0431 */ "", //"doublehyphendemerits", -/* 0432 */ "", //"finalhyphendemerits", -/* 0433 */ "", //"adjdemerits", -/* 0434 */ "", //"mag", -/* 0435 */ "", //"delimiterfactor", -/* 0436 */ "", //"looseness", -/* 0437 */ "", //"time", -/* 0438 */ "", //"day", -/* 0439 */ "", //"month", -/* 0440 */ "", //"year", -/* 0441 */ "", //"showboxbreadth", -/* 0442 */ "", //"showboxdepth", -/* 0443 */ "", //"hbadness", -/* 0444 */ "", //"vbadness", -/* 0445 */ "", //"pausing", -/* 0446 */ "", //"tracingonline", -/* 0447 */ "", //"tracingmacros", -/* 0448 */ "", //"tracingstats", -/* 0449 */ "", //"tracingparagraphs", -/* 0450 */ "", //"tracingpages", -/* 0451 */ "", //"tracingoutput", -/* 0452 */ "", //"tracinglostchars", -/* 0453 */ "", //"tracingcommands", -/* 0454 */ "", //"tracingrestores", -/* 0455 */ "", //"uchyph", -/* 0456 */ "", //"outputpenalty", -/* 0457 */ "", //"maxdeadcycles", -/* 0458 */ "", //"hangafter", -/* 0459 */ "", //"floatingpenalty", -/* 0460 */ "", //"globaldefs", -/* 0461 */ "", //"fam", -/* 0462 */ "", //"escapechar", -/* 0463 */ "", //defaulthyphenchar", -/* 0464 */ "", //"defaultskewchar", -/* 0465 */ "", //"endlinechar", -/* 0466 */ "", //"newlinechar", -/* 0467 */ "", //"language", -/* 0468 */ "", //"lefthyphenmin", -/* 0469 */ "", //"righthyphenmin", -/* 0470 */ "", //"holdinginserts", -/* 0471 */ "", //"errorcontextlines", -/* 0472 */ "", //"[unknown integer parameter!]", -/* 0473 */ "", //"count", -/* 0474 */ "", //"delcode", -/* 0475 */ "", //"parindent", -/* 0476 */ "", //"mathsurround", -/* 0477 */ "", //"lineskiplimit", -/* 0478 */ "", //"hsize", -/* 0479 */ "", //"vsize", -/* 0480 */ "", //"maxdepth", -/* 0481 */ "", //"splitmaxdepth", -/* 0482 */ "", //"boxmaxdepth", -/* 0483 */ "", //"hfuzz", -/* 0484 */ "", //"vfuzz", -/* 0485 */ "", //"delimitershortfall", -/* 0486 */ "", //"nulldelimiterspace", -/* 0487 */ "", //"scriptspace", -/* 0488 */ "", //"predisplaysize", -/* 0489 */ "", //"displaywidth", -/* 0490 */ "", //"displayindent", -/* 0491 */ "", //"overfullrule", -/* 0492 */ "", //"hangindent", -/* 0493 */ "", //"hoffset", -/* 0494 */ "", //"voffset", -/* 0495 */ "", //"emergencystretch", -/* 0496 */ "", //"[unknown dimen parameter!]", -/* 0497 */ "", //"dimen", -/* 0498 */ "", //"EQUIV(", -/* 0499 */ "notexpanded:", -/* 0500 */ "", //"hash size", -/* 0501 */ "", //"csname", -/* 0502 */ "", //"endcsname", -/* 0503 */ "", //"IMPOSSIBLE.", -/* 0504 */ "", //"NONEXISTENT.", -/* 0505 */ "", //"accent", -/* 0506 */ "", //"advance", -/* 0507 */ "", //"afterassignment", -/* 0508 */ "", //"aftergroup", -/* 0509 */ "", //"begingroup", -/* 0510 */ "", //"char", -/* 0511 */ "", //"delimiter", -/* 0512 */ "", //"divide", -/* 0513 */ "", //"endgroup", -/* 0514 */ "", //"expandafter", -/* 0515 */ "", //"font", -/* 0516 */ "", //"fontdimen", -/* 0517 */ "", //"halign", -/* 0518 */ "", //"hrule", -/* 0519 */ "", //"ignorespaces", -/* 0520 */ "", //"mathaccent", -/* 0521 */ "", //"mathchar", -/* 0522 */ "", //"mathchoice", -/* 0523 */ "", //"multiply", -/* 0524 */ "", //"noalign", -/* 0525 */ "", //"noboundary", -/* 0526 */ "", //"noexpand", -/* 0527 */ "", //"omit", -/* 0528 */ "", //"penalty", -/* 0529 */ "", //"prevgraf", -/* 0530 */ "", //"radical", -/* 0531 */ "", //"read", -/* 0532 */ "", //"relax", -/* 0533 */ "", //"setbox", -/* 0534 */ "", //"the", -/* 0535 */ "", //"valign", -/* 0536 */ "", //"vcenter", -/* 0537 */ "", //"vrule", -/* 0538 */ "", //"save size", -/* 0539 */ "", //"grouping levels", -/* 0540 */ "", //"curlevel", -/* 0541 */ "", //"retaining", -/* 0542 */ "", //"restoring", -/* 0543 */ "", //"SAVE(", -/* 0544 */ "", //"Incompatible magnification (", -/* 0545 */ "", //");", -/* 0546 */ "", //" the previous value will be retained", -/* 0547 */ "", //"I can handle only one magnification ratio per job. So I've", -/* 0548 */ "", //"reverted to the magnification you used earlier on this run.", -/* 0549 */ "", //"Illegal magnification has been changed to 1000", -/* 0550 */ "", //"The magnification ratio must be between 1 and 32768.", -/* 0551 */ "", //"ETC.", -/* 0552 */ "", //"BAD.", -/* 0553 */ "", //"->", -/* 0554 */ "", //"begin-group character ", -/* 0555 */ "", //"end-group character ", -/* 0556 */ "", //"math shift character ", -/* 0557 */ "", //"macro parameter character ", -/* 0558 */ "", //"superscript character ", -/* 0559 */ "", //"subscript character ", -/* 0560 */ "", //"end of alignment template", -/* 0561 */ "", //"blank space ", -/* 0562 */ "", //"the letter ", -/* 0563 */ "", //"the character ", -/* 0564 */ "", //"[unknown command code!]", -/* 0565 */ "", //": ", -/* 0566 */ "", //"Runaway ", -/* 0567 */ "", //"definition", -/* 0568 */ "", //"argument", -/* 0569 */ "", //"preamble", -/* 0570 */ "", //"text", -/* 0571 */ "", //"<*>", -/* 0572 */ "", //" ", -/* 0573 */ "", //" ", -/* 0576 */ "", //"