1 /*
2  * dvi2tty
3  * Copyright (C) 2003 Marcel J.E. Mol <marcel@mesa.nl>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  */
20 
21 #define VERSION "5.3.4"
22 
23 #define Progname "dvi2tty"
24 #define Copyright "Copyright (C) 1984, 1985, 1986 Svante Lindahl.\n\
25 Copyright (C) 1989-2010 M.J.E. Mol, MESA Consulting B.V."
26 
27 
28 #if defined(KPATHSEA)
29 # define NO_DEBUG 1
30 # include <kpathsea/config.h>
31 # include <kpathsea/readable.h>
32 #if defined(WIN32)
33 # include <kpathsea/variable.h>
34 #endif
35 # include <sys/types.h>
36 # include <sys/stat.h>
37 #else
38 # define TRUE        1
39 # define FALSE       0
40 #endif
41 
42 #include <stdio.h>
43 #include <string.h>
44 #include <stdlib.h>
45 #if defined(MSDOS) || (defined(WIN32) && !defined(__MINGW32__))
46 # include <malloc.h>
47 #else
48 # if !defined(THINK_C)
49 #  include <unistd.h>
50 # endif
51 #endif
52 
53 #define nil         NULL
54 
55 /*
56  * Define the maximum width of the terminal
57  * (this is also used to define the with of the line structure in dvistuff.c)
58  */
59 #define MAXTERMWIDTH	332
60 
61 #include <ptexenc/ptexenc.h>
62 #include <ptexenc/unicode.h>
63 
64 /* internal encoding for NTT JTeX : "euc" */
65 #define JTEX_INTERNAL_ENC  "euc"
66 
67 /* internal encoding for ASCII pTeX : "euc" or "sjis" */
68 #define PTEX_INTERNAL_ENC  "euc"
69 
70 /* internal encoding for upTeX : "uptex" */
71 #define UPTEX_INTERNAL_ENC  "uptex"
72 
73 /*
74  * ERROR CODES , don't start with 0
75  */
76 
77 #define illop    1              /* illegal op-code                   */
78 #define stkof    2              /* stack over-flow                   */
79 #define stkuf    3              /* stack under-flow                  */
80 #define stkrq    4              /* stack requirement                 */
81 #define lnerq    5              /* line allocation                   */
82 #define badid    6              /* id is not right                   */
83 #define bdsgn    7              /* signature is wrong                */
84 #define fwsgn    8              /* too few signatures                */
85 #define nopre    9              /* no pre-amble where expected       */
86 #define nobop   10              /* no bop-command where expected     */
87 #define nopp    11              /* no postpost where expected        */
88 #define bdpre   12              /* unexpected preamble occured       */
89 #define bdbop   13              /* unexpected bop-command occured    */
90 #define bdpst   14              /* unexpected post-command occured   */
91 #define bdpp    15              /* unexpected postpost               */
92 #define nopst   16              /* no post-amble where expected      */
93 #define illch   17              /* character code out of range       */
94 #define filop   18              /* cannot access file                */
95 #define filcr   19              /* cannot creat file                 */
96 #if !defined(MSDOS)
97 #define pipcr   20              /* cannot creat pipe                 */
98 #endif
99 
100 
101 
102 /*
103  * Type definitions
104  */
105 
106 typedef char bool;
107 
108 typedef struct prlistptr {      /* list of pages selected for output         */
109     int       pag;                      /* number of pages                   */
110     bool      all;                      /* pages in interval selected        */
111     struct prlistptr *prv;              /* previous item in list             */
112     struct prlistptr *nxt;              /* next item in list                 */
113 } printlisttype;
114 
115 
116 
117 /*
118  * Variable definitions
119  */
120 
121 extern bool   outputtofile;            /* output to file or stdout(dvi2tty.c)*/
122 extern bool   pageswitchon;            /* user-set pages to print(dvistuff.c)*/
123 extern bool   sequenceon;              /* not TeX pagenrs (dvistuff.c)       */
124 extern bool   scascii;                 /* Scand. nat. chars (dvistuff.c)     */
125 extern bool   latin1;                  /* latin1 chars (dvistuff.c)          */
126 extern bool   accent;                  /* Output accent stuff(dvistuff.c)    */
127 extern bool   ttfont;                  /* tt font assumed   (dvistuff.c)     */
128 extern bool   jautodetect;             /* Autodetect NTT jTeX, ASCII pTeX and upTeX (dvistuff.c) */
129 extern bool   nttj;                    /* NTT jTeX font support (dvistuff.c) */
130 extern bool   asciip;                  /* ASCII pTeX font support (dvistuff.c) */
131 extern bool   uptex;                   /* upTeX font support (dvistuff.c)    */
132 extern bool   japan;                   /* japanized TeX font support (dvistuff.c) */
133 extern bool   noffd;                   /* output ^L or formfeed (dvistuff.c) */
134 extern bool   printfont;               /* include font switches (dvistuff.c) */
135 extern bool   allchar;                 /* output all characters (dvistuff.c  */
136 
137 extern printlisttype *currentpage;     /* current page to print (dvi2tty.c)  */
138 extern printlisttype *firstpage;       /* first page selected (dvi2tty.c)    */
139 extern printlisttype *lastpage;        /* last page selected (dvi2tty.c)     */
140 
141 extern int            ttywidth;        /* screen width (dvi2tty.c)           */
142 extern int            espace;          /* extra screen width (dvi2tty.c)     */
143 extern long           foo;             /* temporary 'register' (dvi2tty.c)   */
144 extern long           lineheight;      /* height of a line (dvistuff.c)      */
145 extern int            opcode;          /* dvi opcode (dvistuff.c)            */
146 extern const char *   delim;           /* printer font delim (dvistuff.c)    */
147 
148 extern FILE *DVIfile;                  /* dvi file (dvi2tty.c)               */
149 extern FILE *output;                   /* output file (dvi2tty.c)            */
150 
151 
152 
153 /*
154  * Funtion declarations
155  */
156 
157 /* dvi2tty.c */
158 #if defined(MSDOS)
159 void errorexit(int);
160 #else
161 void errorexit(int errorcode);
162 #endif
163 
164 /* dvistuff.c */
165 #if defined(MSDOS)
166 void dvimain(void);
167 #else
168 void dvimain(void);
169 #endif
170