<..header functions..>+
static INTEGER insert_ch( ARG_I(int) );
-_-_-
<..functions..>+
static INTEGER insert_ch(ch) int ch
;{
if( !ignore_chs ){
BOOL flag;
<.flag = empty next-str?.>
if( !flag ){
try_new_line();
<.insert ch to text.>
text_on = TRUE;
} }
<.return char width.>
}
-_-_-
/* if (ch � 0) ch+=256; /*NEW */
<..flag = empty next-str?..>
flag = FALSE;
if( <.next-str.> ) {
if( eq_str(next_str, "") ) {
flag = TRUE;
free((void *) next_str);
next_str = (char *) 0;
} }
-_-_-
<..header functions..>+
static void put_char( ARG_I(int) );
-_-_-
<..functions..>+
static void put_char( ch ) int ch
;{
if( !ignore_chs
&& !( ((ch==’ ’) || (ch==’\n’)) && no_root_file )
){
<.open output file.>
if( ch_map_flag ){
if( special_on || ((ch != ’\n’) && (ch != ’ ’)) ){
<.insert ch to ch-map.> }
}else {
if ( ch == ’\n’ ){ <.insert eoln ch.> }
else if ( ch == ’ ’ ){ <.insert space ch.> }
else { (IGNORED) put_4ht_ch( ch, cur_o_file ); }
} } }
-_-_-
<..vars..>+
static BOOL special_on = FALSE;
-_-_-
<..header functions..>+
static void print_f( ARG_I(const char*) );
-_-_-
<..functions..>+
static void print_f(str) const char* str
;{
<.open output file.>
if( ch_map_flag ){
while( *str ){ put_char( *str ); str++; }
}else {
(IGNORED) print_f_4ht( str );
} }
-_-_-
<..header functions..>+
static void print_f_4ht( ARG_I(const char*) );
-_-_-
<..functions..>+
static void print_f_4ht(str) const char* str
;{
<.open output file.>
if( ch_map_flag ){
while( *str ){ put_char( *str ); str++; }
} else {
while( *str ){
(IGNORED) put_4ht_ch( *str, cur_o_file );
str++;
} } }
-_-_-
<..header functions..>+
static int get_char( ARG_I(void) );
-_-_-
<..functions..>+
static int get_char(MYVOID)
{
return (int) getc(dvi_file);
}
-_-_-
<..header functions..>+
static int get_noop( ARG_I(void) );
-_-_-
<..functions..>+
static int get_noop(MYVOID)
{ int ch;
while( (ch = get_char()) == <.no op.> ){;}
return ch;
}
-_-_-
<..header functions..>+
static char* get_str( ARG_I(int) );
-_-_-
<..functions..>+
static char* get_str(n) int n
;{ U_CHAR *q, *p;
p = q = m_alloc(char,n+1);
while( n-- ) *q++ = get_char();
*q = ’\0’;
return p;
}
-_-_-
<..defines..>+
#define get_unt(n) fget_unt(dvi_file,n)
-_-_-
<..header functions..>+
static long fget_unt( ARG_II(FILE*, int) );
-_-_-
<..functions..>+
static long fget_unt( file, n )
FILE* file;
register int n
;{ register long val = 0;
while( n-- ){ val = (val << 8) + (unsigned INTEGER) getc(file) ; }
return val;
}
-_-_-
<..defines..>+
#define get_int(n) fget_int(dvi_file,n)
-_-_-
<..header functions..>+
static long fget_int( ARG_II(FILE *, int) );
-_-_-
<..functions..>+
static long fget_int( file, n )
FILE *file;
int n
;{ register long val;
val = (unsigned INTEGER) getc(file);
if( val & 0x80 ) val -= 0x100;
while( --n ){ val = (val << 8) + (unsigned INTEGER) getc(file); }
return val;
}
-_-_-
The implementation in dvi2ps takes the following form with the comment “This code assumes that the right-shift is an arithmetic, rather than logical, shift which will propagate the sign bit right. According to Kernighan and Ritchie, this is compiler dependent!”.
<..header functions..>+
static long cond_int( ARG_I(register INTEGER) );
-_-_-
<..functions..>+
static long cond_int( n )
register INTEGER n
;{ register long val;
int ch;
val = (unsigned int) (ch = get_char());
cond_idv_char( ch );
if( val & 0x80 ) val -= 0x100;
while( --n ){
val = (val << 8) + (unsigned int) (ch = get_char());
cond_idv_char( ch );
}
return val;
}
-_-_-
<..defines..>+
#define eq_str(x,y) (!strcmp(x,y))
#define gt_str(x,y) (strcmp(x,y)>0)
-_-_-
<..warn and err messages..>
<.command line options.>, 0
"Can’t find/open file ‘%s’\n", 1
"Can’t open output file for ‘%s’\n", 2
"Can’t close file ‘%s’ (file is not open)\n", 3
"Insufficient memory\n", 4
"Bad character code: %d\n", 5
"Can’t find font number %d\n", 6
"Improper dvi file\n", 7
"Improper op while scanning font defs in postamble\n",8
"Problem with command line\n", 9
"Font definition repeated in postamble\n", 10
"Empty entry in font environment variable\n", 11
"Can’t access directory ‘%s\n’", 12
"Too many directories in font environment variable\n",13
"Missing fonts, can’t proceed\n", 14
"Invalid header in file ‘%s’\n", 15
"Checksum inconsistent\n", 16
"MAXFONTS too small: %d\n", 17
"Improper signature at end of file ‘%s.htf’\n", 18
"Improper signature at start of file ‘%s.htf’\n", 19
"Improper file ‘%s.htf’\n", 20
"Couldn’t find font ‘%s.htf’ (char codes: ", 21
"File ‘%s.htf’ starts/ends with character code %d (instead of %d)\n",22
"Implementation problem\n", 23
"Improper groups in \\special{t4ht+}... idv[%d]\n", 24
"Too many characters (> %d) for map line: ‘%c’\n", 25
"Extra characters in \\special{t4ht%c...", 26
"Page break within a ch map/picture\n", 27
"Char code >255 in htf file: %d\n", 28
"Improper char for code in htf file: %c\n", 29
<.signals messages: 30-32.> 30-32
#ifdef DOS_WIN32
"%c-script too long in tex4ht.env \n", 33
#else
"%c-script too long in tex4ht.env (.tex4ht)\n", 33
#endif
"Too many rows (> %d) for map: ‘%c’\n", 34
"More than 256 strings in font\n", 35
"\\special{t4ht;%c...}?\n", 36
"\\special{t4ht;|%s}?\n", 37
"\\special{t4ht~!%s}?\n", 38
"\\special{t4ht\"...%s}?\n", 39
"System error 40\n", 40
"‘%c’ in \\special{t4ht@...} or \\special{t4ht@-...}?\n", 41
"\\special{t4ht~...} without \\special{t4ht~}\n", 42
"Ignoring \\special{t4ht.%s}\n", 43
"PUSH for \\special{t4ht<...%s}?\n", 44
"Bad character code (%d) in \\special{t4h~}...\n", 45
"Page break in \\special{t4h~}...\n", 46
"tex4ht.fls: Couldn’t find file ‘%s’\n", 47
"Improper entry (line %d)\n", 48
"Improper environment variable %s: ‘%s’\n", 49
"Missing %s\n", 50
"Can’t back from file ‘%s\n’", 51
"\\special{t4ht%s}?\n", 52
"Improper -v option\n", 53
-_-_-
<..vars..>+
static const U_CHAR *warn_err_mssg[]={ <.warn and err messages.> "" };
-_-_-
<..header functions..>+
static void warn_i( ARG_I(int) );
-_-_-
<..functions..>+
static void warn_i(n) int n
;{ (IGNORED) fprintf(stderr,"--- warning --- ");
(IGNORED) fprintf(stderr, "%s", warn_err_mssg[n]);
show_err_context();
}
-_-_-
<..warning(22..>
(IGNORED) fprintf(stderr,"--- warning --- ");
(IGNORED) fprintf(stderr, warn_err_mssg[22]
-_-_-
<..header functions..>+
static void warn_i_int( ARG_II(int,int) );
-_-_-
<..functions..>+
static void warn_i_int(n,i) int n; int i
;{ (IGNORED) fprintf(stderr,"--- warning --- ");
(IGNORED) fprintf(stderr, warn_err_mssg[n], i);
show_err_context();
}
-_-_-
<..header functions..>+
static void warn_i_int_2( ARG_III(int,int,int) );
-_-_-
<..functions..>+
static void warn_i_int_2(n,i,j) int n; int i; int j
;{ (IGNORED) fprintf(stderr,"--- warning --- ");
(IGNORED) fprintf(stderr, warn_err_mssg[n], i, j);
show_err_context();
}
-_-_-
<..header functions..>+
static void warn_i_str( ARG_II(int,const char *) );
-_-_-
<..functions..>+
static void warn_i_str(n,str)
int n;
const char *str
;{
(IGNORED) fprintf(stderr,"--- warning --- ");
(IGNORED) fprintf(stderr,warn_err_mssg[n], str);
show_err_context();
}
-_-_-
<..header functions..>+
static void warn_i_str2( ARG_III(int,const char *,const char *) );
-_-_-
<..functions..>+
static void warn_i_str2(n,str1,str2)
int n;
const char *str1;
const char *str2
;{ (IGNORED) fprintf(stderr,"--- warning --- ");
(IGNORED) fprintf(stderr,warn_err_mssg[n], str1,str2);
show_err_context();
}
-_-_-
<..defines..>+
#define bad_arg err_i(0)
#define bad_in_file(name) err_i_str(1,name)
#define bad_out_file(name) err_i_str(2,name)
#define bad_special(name) warn_i_str(3,name)
#define bad_mem err_i(4)
#define bad_char(chr) warn_i_int(5,chr)
#define bad_dvi err_i(7)
-_-_-
<..header functions..>+
static void err_i( ARG_I(int) );
-_-_-
<..functions..>+
static void err_i(n) int n
;{ (IGNORED) fprintf(stderr,"--- error --- ");
(IGNORED) fprintf(stderr, "%s", warn_err_mssg[n]);
show_err_context();
exit(EXIT_FAILURE);
}
-_-_-
REPLACE EXIT with somthing that DOS also accept.
<..header functions..>+
static void err_i_int( ARG_II(int,int) );
-_-_-
<..functions..>+
static void err_i_int(n,i) int n; int i
;{ (IGNORED) fprintf(stderr,"--- error --- ");
(IGNORED) fprintf(stderr, warn_err_mssg[n], i);
show_err_context();
exit(EXIT_FAILURE);
}
-_-_-
<..header functions..>+
static void err_i_str( ARG_II(int,char *) );
-_-_-
<..functions..>+
static void err_i_str(n,str)
int n;
U_CHAR *str
;{ (IGNORED) fprintf(stderr,"--- error --- ");
(IGNORED) fprintf(stderr, warn_err_mssg[n], str);
show_err_context();
exit(EXIT_FAILURE);
}
-_-_-
<..check for extra special chars..>
if( special_n > 0 ){
warn_i_int( 26, sv);
while( special_n-- ) (IGNORED) putc( get_char(), stderr);
}
-_-_-
<..special resolution err..>
warn_i_int( 26, ’!’);
(IGNORED) putc( ch, stderr);
while( special_n-- ) (IGNORED) putc( get_char(), stderr);
-_-_-
<..consume unused specials..>
while( special_n-- ) (void) get_char();
-_-_-
<..unused special..>
;
-_-_-
<..header functions..>+
static void show_err_context( ARG_I(void) );
-_-_-
<..functions..>+
static void show_err_context(MYVOID)
{ long curr_pos;
int n, i;
U_CHAR ch;
if( err_context ){
curr_pos = ftell(dvi_file);
for(n=6; n--;){
(IGNORED) putc( ’\n’, stderr );
for(i=70; i--;){
ch = get_char();
(IGNORED) putc(( (ch>31) && (ch<127))? ch : ’ ’, stderr);
}
}
(IGNORED) fseek(dvi_file, curr_pos, <.abs file addr.>);
(IGNORED) putc( ’\n’, stderr ); (IGNORED) putc( ’\n’, stderr );
if( err_mark ){ print_f( err_mark ); }
} }
-_-_-
A static informs that the function is defined just locally, preventing possible errors when the linker detects name conflicts with definitions that use the same names in other libraries.
<..vars..>+
static BOOL err_context = FALSE;
-_-_-
<..context for warn and errs..>
err_context = TRUE;
-_-_-
<..vars..>+
static U_CHAR *err_mark = (char *) 0;
-_-_-
<..get err str..>
if( err_mark ){ free((void *) err_mark); }
if( special_n ){
err_mark = get_str( (int) special_n ); special_n=0;
} else { err_mark = (char *) 0; }
-_-_-
<..trace specials in dvi..>
trace_special = TRUE;
-_-_-
<..vars..>+
static BOOL trace_special = FALSE;
-_-_-
On off with \special{t4ht@/}
<..on/off special trace..>
trace_special = !trace_special;
-_-_-
<..trace specials..>
{ long curr_pos;
int n, i;
U_CHAR ch;
curr_pos = ftell(dvi_file);
print_f("\nSPECIAL: "); ch = special_hd[8]; i=60;
for( n=*special_n - 3; n--;){
if( !i ){ (IGNORED) putc( ’\n’, cur_o_file ); i=70; }
else i--;
(IGNORED) putc(( (ch>31) && (ch<127))? ch : ’ ’, cur_o_file);
ch = get_char();
}
(IGNORED) putc( ’\n’, cur_o_file );
(IGNORED) fseek(dvi_file, curr_pos, <.abs file addr.>);
}
-_-_-
Unix doesn’t differentiate between binary binary and text files.
In general, the rule of thumb is that DOS/Windows ports should recognize both back- and forward-slashes in their input (such as command-line arguments), but can construct file names by using forward slashes alone (since DOS/Windows kernels support both styles).
On the subject of the .lg file: you open the tex4ht.env file in binary mode (”rb”), which results in strange line endings in the .lg file (CR/CR/LF). Changing the mode to ”r” fixes this.
(WRITE_BIN_FLAGS, READ_BIN_FLAGS): Use binary mode with DJGPP. —captured with the __MSDOS__.
<..defines..>+
#if defined(DOS_WIN32) || defined(__MSDOS__)
#define READ_BIN_FLAGS "rb"
#define READ_TEXT_FLAGS "r"
#define WRITE_BIN_FLAGS "wb"
#ifdef WIN32
#define WRITE_TEXT_FLAGS "wb"
#else
#define WRITE_TEXT_FLAGS "w"
#endif
#else
#define READ_BIN_FLAGS "r"
#define READ_TEXT_FLAGS "r"
#define WRITE_BIN_FLAGS "w"
#define WRITE_TEXT_FLAGS "w"
#endif
-_-_-
Function prototypes
<..tex4ht.h..>+
#ifdef DOS
#define PROTOTYP
#endif
#ifdef ANSI
#define PROTOTYP
#endif
#ifdef KWIN32
#define PROTOTYP
#endif
-_-_-
<..defines..>+
#ifdef PROTOTYP
#define MYVOID void
#define ARG_I(x) x
#define ARG_II(x,y) x,y
#define ARG_III(x,y,z) x,y,z
#define ARG_IV(x,y,z,w) x,y,z,w
#define ARG_V(x,y,z,w,v) x,y,z,w,v
#define ARG_VI(x,y,z,w,v,u) x,y,z,w,v,u
#define ARG_VII(x,y,z,w,v,u,t) x,y,z,w,v,u,t
#else
#define MYVOID
#define ARG_I(x)
#define ARG_II(x,y)
#define ARG_III(x,y,z)
#define ARG_IV(x,y,z,w)
#define ARG_V(x,y,z,w,v)
#define ARG_VI(x,y,z,w,v,u)
#define ARG_VII(x,y,z,w,v,u,t)
#endif
-_-_-
<..insert rule + move op..>
132 -_-_-
<..insert rule + nomove op..>
137 -_-_-
<..start page op..>
139 -_-_-
<..end page op..>
140 -_-_-
<..retrieve loc op..>
142 -_-_-
<..mv hor 1-byte..>
143 -_-_-
<..mv hor 2-byte..>
144 -_-_-
<..mv hor 3-byte..>
145 -_-_-
<..mv hor 4-byte..>
146 -_-_-
<..mv hor dist dx.1..>
147 -_-_-
<..dx.1 store and mv hor 1-byte..>
148 -_-_-
<..dx.1 store and mv hor 2-byte..>
149 -_-_-
<..dx.1 store and mv hor 3-byte..>
150 -_-_-
<..dx.1 store and mv hor 4-byte..>
151 -_-_-
<..mv hor dist dx.2..>
152 -_-_-
<..dx.2 store and mv hor 1-byte..>
153 -_-_-
<..dx.2 store and mv hor 2-byte..>
154 -_-_-
<..dx.2 store and mv hor 3-byte..>
155 -_-_-
<..dx.2 store and mv hor 4-byte..>
156 -_-_-
<..mv ver 1-byte..>
157 -_-_-
<..mv ver 2-byte..>
158 -_-_-
<..mv ver 3-byte..>
159 -_-_-
<..mv ver 4-byte..>
160 -_-_-
<..mv ver dist dy.1..>
161 -_-_-
<..dy.1 store and mv ver 1-byte..>
162 -_-_-
<..dy.1 store and mv ver 2-byte..>
163 -_-_-
<..dy.1 store and mv ver 3-byte..>
164 -_-_-
<..dy.1 store and mv ver 4-byte..>
165 -_-_-
<..mv ver dist dy.2..>
166 -_-_-
<..dy.2 store and mv ver 1-byte..>
167 -_-_-
<..dy.2 store and mv ver 2-byte..>
168 -_-_-
<..dy.2 store and mv ver 3-byte..>
169 -_-_-
<..dy.2 store and mv ver 4-byte..>
170 -_-_-
<..number of direct fonts..>
63 -_-_-
<..font 1-byte..>
235 -_-_-
<..font 2-bytes..>
236 -_-_-
<..font 3-bytes..>
237 -_-_-
<..def 1 byte font..>
243 -_-_-
<..def 2 byte font..>
244 -_-_-
<..def 3 byte font..>
245 -_-_-
<..def 4 byte font..>
246 -_-_-
<..start preamble op..>
247 -_-_-
<..begin-postamble op..>
248 -_-_-
<..end-postamble op..>
249 -_-_-
<..start of preamble op..>
247 -_-_-
The ops 250–255 have no meaning in dvi.
<..xdv-pic-file op..>
251
-_-_-
<..xdv-native-font-def op..>
252
-_-_-
<..xdv-glyph-array op..>
253
-_-_-
<..xdv-glyph-string op..>
254
-_-_-