Debian Codegraph @

texmf-dist/source/generic/tex4ht/tex4ht-t4ht.tex

raw
1 % $Id: tex4ht-t4ht.tex 1556 2024-09-23 10:50:11Z michal_h21 $
2 % tex tex4ht-t4ht or ht tex tex4ht-t4ht
3 %
4 % Copyright 2009-2018 TeX Users Group
5 % Copyright 1998-2009 Eitan M. Gurari
6 % Released under LPPL 1.3c+.
7 % See tex4ht-cpright.tex for license text.
8
9 % bcc32 -DBCC32 t4ht.c
10 % gcc -O2 -DKPATHSEA -I/usr/local/teTeX/include -L/usr/local/teTeX/lib -o t4ht t4ht.c -DHAVE_DIRENT_H -lkpathsea
11
12 \input common.tex
13 \input tex4ht.sty
14
15 \Preamble{xhtml,th4,sections+,xhtml}\EndPreamble
16
17 \input ProTex.sty
18 \AlProTex{c,<<<>>>,`,title,list,_^,CodeLineNo}
19
20 %\input tex4ht-cpright.tex
21
22 \Comment{
23 }{}
24 \def\CodeId#1#2{}
25
26
27 \def\UnderLine#1{\ifHtml
28 \HCode{<strong>}#1\HCode{</strong>}\else\underbar{#1}\fi}
29 \let\CModifyShowCode=\ModifyShowCode
30 \let\CModifyOutputCode=\ModifyOutputCode
31 \def\ModifyShowCode{\def\[##1({##1\UnderLine{(}}\def
32 \;{\UnderLine{;}}\CModifyShowCode}
33 \catcode`\^=7 \catcode`\@=6 \catcode`\#=12 \catcode`\^^M=13\relax%
34 \def\ModifyOutputCode{%
35 \def\;{ SEP }%
36 \def\[@@1(@@2)@@3;{@@1
37 #ifdef ANSI
38 #define SEP ,
39 (@@3)
40 #undef SEP
41 #else
42 #define SEP ;
43 (@@2)@@3;
44 #undef SEP
45 #endif
46 }%
47 \CModifyOutputCode}%
48 \catcode`\^^M=5 \catcode`\@=12 \catcode`\#=6 \catcode`\^=13
49
50
51
52
53 \let\'=\Verb
54 \def\`{\expandafter\expandafter\expandafter\qts\Verb}
55 \def\qts#1{`#1\aftergroup'}
56
57 \def\FTP{http://www.cis.ohio-state.edu/\string~gurari/tpf/}
58
59 \TocAt{Section,SubSection}
60 \CutAt{Section}
61
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64 \LikeChapter{t4ht: postprocessor for tex4ht}
65
66 The compilation of this file requires the packages
67 \Link[\FTP ProTex.sty]{}{}Pro\TeX\EndLink{}
68 and \Link[\FTP AlProTex.sty]{}{}AlPro\TeX\EndLink.
69
70 \TableOfContents[Section,SubSection]
71
72
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 \Section{Outline}
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 \SubSection{The Cases}
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80
81
82 The post-processor \`'tex4ht.c' prepares a \`'.lg' file in which it
83 lists the pictures that need to be generated, and the entries
84 encountered in \''\Needs{...}'. The \`'.log' file contains the entries
85 encountered in the \''\Needs-{...}'. The t4ht program (used to be a
86 Perl script?) treats as commands the entries that are enclosed between
87 double-quote (\''"') characters, and the other entries as comments. It
88 first works on the \`'.lg' file and then on the \`'.log' file.
89 The main output is a new \`'.css'.
90
91
92 \<main's body\><<<
93 `<load env file`>
94 lg_file = open_file(lg_name,LG_EXT);
95 if( lg_file ) {
96 `<mark start lg file`>
97 `<rewind lg file`> `<stop, if tex4ht.c err`>
98 `<rewind lg file`> `<CopyTo files`>
99 `<rewind lg file`> `<htfcss from lg`>
100 `<rewind lg file`> `<font=(...) from lg`>
101 `<rewind lg file`> `<identify the empty pictures`>
102 `<rewind lg file`> `<process gif's`>
103 `<rewind lg file`> `<process css`>
104 `<rewind lg file`> `<post-process ext files`>
105 `<rewind lg file`> `<post-process files`>
106 `<rewind lg file`> `<mv lg/File to dir and chmod`>
107 `<rewind lg file`> `<process user commands`>
108 (IGNORED) fclose(lg_file);
109 }
110 >>>
111
112 \<mv lg/File to dir and chmod\><<<
113 eoln_ch = (int) 'x';
114 while( eoln_ch != EOF ) {
115 status = scan_str("File: ", TRUE, lg_file);
116 status = scan_until_end_str("", 1, status, lg_file);
117 status = status && !eq_str(match[1],tmp_name);
118 if( status ){
119 FILE* file;
120 file = fopen(match[1], READ_TEXT_FLAGS);
121 if( file ){
122 (IGNORED) fclose(file);
123 } else { status = FALSE; }
124 }
125 if( status ){
126 if( dir ){
127 (void) execute_script(copy_script, match[1],
128 dir? dir :"",".","");
129 }
130 if( ch_mod ){
131 (void) execute_script(chmod_script, ch_mod,
132 dir? dir:"",match[1], "");
133 }
134 } }
135 >>>
136
137 % Need to input tex4ht-cpright.tex at this point,
138 % if not, it causes an error while expanding the
139 % macros like `jobname.tex, `version, ...
140 % Still greek to me. :( CVR/2010/02/11
141 %
142 \input tex4ht-cpright.tex
143
144
145 \<t4ht.c\><<<
146 /* t4ht.c (`version), generated from `jobname.tex
147 Copyright (C) 2009-2018 TeX Users Group
148 Copyright (C) `CopyYear.1998. Eitan M. Gurari
149 `<TeX4ht copyright`>
150 */
151 `<t4ht.h`>
152 `<defines`>
153 `<vars`>
154 `<header functions`>
155 `<functions`>
156 `[
157 int `<CDECL`> main(argc, argv)
158 int argc`;
159 Q_CHAR **argv
160 ;{ `<main's vars`>
161 `<resplit argv for windows`>
162 `<set signals`>
163 `<program signature`>
164 `<main's init`>
165
166 `<scan job args`>
167 `<main's body`>
168 return 0;
169 }
170 >>>
171
172
173 \<program signature\><<<
174 (IGNORED) printf("----------------------------\n");
175 #ifndef KPATHSEA
176 #ifdef PLATFORM
177 (IGNORED) printf("t4ht.c (`version %s)\n",PLATFORM);
178 #else
179 (IGNORED) printf("t4ht.c (`version)\n");
180 #endif
181 #else
182 #ifdef PLATFORM
183 (IGNORED) printf("t4ht.c (`version %s kpathsea)\n",PLATFORM);
184 #else
185 (IGNORED) printf("t4ht.c (`version kpathsea)\n");
186 #endif
187 #endif
188
189 `<handle quoted arguments`>
190 { int i;
191 for(i=0; i<argc; i++){
192 (IGNORED) printf("%s%s ", (i>1)?"\n " : "", argv[i]); }
193 (IGNORED) printf("\n");
194 }
195 >>>
196
197
198
199 \SubSection{char, signed char, unsigned char (gcc man)}:
200
201
202 Each kind of machine has a default for what char should
203 be. It is either like unsigned char by default or like
204 signed char by default.
205
206 Ideally, a portable program should always use signed
207 char or unsigned char when it depends on the signedness
208 of an object. But many programs have been written to
209 use plain char and expect it to be signed, or expect it
210 to be unsigned, depending on the machines they were
211 written for. This option, and its inverse, let you
212 make such a program work with the opposite default.
213
214 The type char is always a distinct type from each of
215 signed char and unsigned char, even though its behavior
216 is always just like one of those two.
217
218
219
220
221 \<definesNO\><<<
222 #define Q_CHAR signed char
223 #define U_CHAR unsigned char
224 #define C_CHAR char
225 #define Q_NULL (Q_CHAR *) 0
226 #define U_NULL (U_CHAR *) 0
227 #define C_NULL (C_CHAR *) 0
228 >>>
229
230 Pointers to strings must use \`'C_CHAR', since we don't
231 know how string constants are treated there.
232
233
234 \<defines\><<<
235 #define Q_CHAR char
236 #define U_CHAR char
237 #define C_CHAR char
238 #define Q_NULL (Q_CHAR *) 0
239 #define U_NULL (U_CHAR *) 0
240 #define C_NULL (C_CHAR *) 0
241 >>>
242
243 \SubSection{EOF Character}
244
245
246 \<vars\><<<
247 static int eoln_ch;
248 >>>
249
250 \Verbatim
251 OBTW: when compiling t4ht.c, I get messages about the uselessness of comparing
252 chars (which are unsigned, at least on a IRIX 6.5) to EOF which is defined as
253 -1 in stdio.h).... and indeed it program loops endlessly.
254 Adding the lines
255 #undef EOF
256 #define EOF 255
257 after the last #include gets the effect that you probably want (or perhaps
258 better would be to define a constant EOFCHAR or something.)
259 \EndVerbatim
260
261 The getc returns the next character as an unsigned char converted to int.
262 This is so to allow all characters to be return as well as end-of-file
263 indicators (-1 in stdio) and error indicator.
264
265
266
267
268 %%%%%%%%%%%%%
269 \Section{Stop on tex4ht.c Err}
270 %%%%%%%%%%%%%
271
272
273
274 \<stop, if tex4ht.c err\><<<
275 if( check_tex4ht_c_err ){
276 eoln_ch = (int) 'x';
277 while( eoln_ch != EOF ) {
278 status = scan_str("tex4ht.c error: ", TRUE, lg_file);
279 if( status ){
280 (IGNORED) fprintf(stderr,
281 "--- Error --- tex4ht.c ran into problems\n"
282 );
283 exit(EXIT_FAILURE);
284 }
285 status = scan_until_end_str("", 1, status, lg_file);
286 } }
287 >>>
288
289
290
291
292 \<vars\><<<
293 static BOOL check_tex4ht_c_err = FALSE;
294 >>>
295
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 \Section{Platform-dependent Code}
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321 \SubSection{PreProcessor Directives}
322
323
324 Symantec C++ for wid95:
325 \''sc t4ht.c -mn -o+time -WA -3 -a8 -c -D_CONSOLE=1 -ot4ht.obj'
326
327
328 \<defines\><<<
329 #define IGNORED void
330 >>>
331
332
333
334 \<t4ht.h\><<<
335 /* **********************************************
336 Compiler options *
337 (uncommented | command line) *
338 ------------------------------------------------*
339 Classic C (CC) default
340 #define ANSI ansi-c, c++
341 #define DOS_C
342 #define HAVE_STRING_H <string.h>
343 #define HAVE_DIRENT_H <dirent.h>
344 #define HAVE_SYS_NDIR_H <sys/ndir.h>
345 #define HAVE_SYS_DIR_H <sys/dir.h>
346 #define HAVE_NDIR_H <ndir.h>
347 #define HAVE_IO_H <io.h>
348 #define HAVE_UNISTD_H <unistd.h>
349 #define WIN32
350 #define KPATHSEA
351 #define SYSTEM_FUNCTION_OK
352 #define CDECL ..........
353 #define BCC32 bordland c++
354
355 *************************************************
356 Tex4ht variables *
357 (uncommented | command line) *
358 ----------------------------------------------- */
359 `<h-defines`>
360 /* ******************************************** */
361 `<define MSVC-1-52`>
362 `<bordland: bcc32 -DBCC32 t4ht`>
363 `<bordland: bcc -DBCC tex4ht`>
364 `<DJGPP`>
365 #ifdef DOS_C
366 #define DOS
367 #endif
368 #ifdef DOS
369 #define DOS_WIN32
370 #ifndef HAVE_STRING_H
371 #define HAVE_STRING_H
372 #endif
373 #endif
374 #ifdef WIN32
375 #define DOS_WIN32
376 #endif
377 `<h-defines DOS-WIN32`>
378 `<h-defines KWIN32`>
379 `<h-include`>
380 `<h-defines 2`>
381 >>>
382
383
384 \<bordland: bcc32 -DBCC32 t4ht\><<<
385 #ifdef BCC32
386 #define WIN32
387 #define ANSI
388 #define HAVE_IO_H
389 #define HAVE_STRING_H
390 #define PLATFORM "ms-win32"
391 #endif
392 >>>
393
394 %
395
396 \<bordland: bcc -DBCC tex4ht\><<<
397 #ifdef BCC
398 #define DOS_C
399 #define ANSI
400 #define HAVE_IO_H
401 #define PLATFORM "ms-dos"
402 #endif
403 >>>
404
405
406 \<h-include\><<<
407 #ifdef KPATHSEA
408 #include <kpathsea/config.h>
409 #endif
410 #include <stdio.h> `% EOF, FILE `%
411 #include <stdlib.h> `% EXIT_FAILURE `%
412 >>>
413
414
415
416 Under ANSI C, all malloc stuff is declared in \`'<stdlib.h>' (which you
417 also include), hence this non-standard header is redundant.
418
419
420
421 \<defines\><<<
422 #ifndef EXIT_FAILURE
423 #define EXIT_FAILURE 1
424 #endif
425 >>>
426
427 \<h-include\><<<
428 #ifdef HAVE_STRING_H
429 #include <string.h>
430 #endif
431 >>>
432
433
434
435
436 \<h-defines DOS-WIN32\><<<
437 #ifdef DOS_WIN32
438 #define STRUCT_DIRENT
439 #endif
440 >>>
441
442
443 \<h-include\><<<
444 #ifdef HAVE_DIRENT_H
445 `<needs dirent.h`>
446 #else
447 #ifndef STRUCT_DIRENT
448 #define STRUCT_DIRECT
449 #endif
450 `<needs simulated dirent.h`>
451 #endif
452 >>>
453
454
455
456 \<needs dirent.h\><<<
457 #include <dirent.h>
458 >>>
459
460
461 \<needs simulated dirent.h\><<<
462 #ifdef HAVE_SYS_NDIR_H
463 #include <sys/ndir.h>
464 #endif
465 #ifdef HAVE_SYS_DIR_H
466 #include <sys/dir.h>
467 #endif
468 #ifdef HAVE_NDIR_H
469 #include <ndir.h>
470 #endif
471 >>>
472
473
474 REPLACE EXIT with somthing that DOS also accept.
475
476
477
478
479 \<t4ht.h\><<<
480 #ifdef DOS
481 #define PROTOTYP
482 #endif
483 #ifdef ANSI
484 #define PROTOTYP
485 #endif
486 #ifdef KWIN32
487 #define PROTOTYP
488 #endif
489 >>>
490
491 \<defines\><<<
492 #ifdef PROTOTYP
493 #define MYVOID void
494 #define ARG_I(x) x
495 #define ARG_II(x,y) x,y
496 #define ARG_III(x,y,z) x,y,z
497 #define ARG_IV(x,y,z,w) x,y,z,w
498 #define ARG_V(x,y,z,w,u) x,y,z,w,u
499 #else
500 #define MYVOID
501 #define ARG_I(x)
502 #define ARG_II(x,y)
503 #define ARG_III(x,y,z)
504 #define ARG_IV(x,y,z,w)
505 #define ARG_V(x,y,z,w,u)
506 #endif
507 >>>
508
509
510
511
512
513 \SubSection{KPATHSEA}
514
515 \<h-defines 2NO\><<<
516 `<h-include before KPATHSEA`>
517 #ifdef KPATHSEA
518 #ifndef HAVE_STRCHR
519 #define strchr index
520 #endif
521 #ifndef HAVE_STRRCHR
522 #define strrchr rindex
523 #endif
524 #include <kpathsea/c-errno.h>
525 #include <kpathsea/c-ctype.h>
526 #include <kpathsea/c-fopen.h>
527 #include <kpathsea/c-pathmx.h>
528 #include <kpathsea/proginit.h>
529 #include <kpathsea/tex-file.h>
530 #include <kpathsea/tex-make.h>
531 #include <kpathsea/variable.h>
532 #include <signal.h>
533 #if !defined(_AMIGA) && !defined(WIN32)
534 #include <sys/time.h>
535 #endif
536 #include <fcntl.h>
537 #include <setjmp.h>
538 #endif `%/* KPATHSEA */`%
539 `<h-include after KPATHSEA`>
540 >>>
541
542 \<h-defines 2\><<<
543 `<h-include before KPATHSEA`>
544 #ifdef KPATHSEA
545 #include <kpathsea/c-errno.h>
546 #include <kpathsea/c-ctype.h>
547 #include <kpathsea/c-fopen.h>
548 #include <kpathsea/c-pathmx.h>
549 #include <kpathsea/proginit.h>
550 #include <kpathsea/tex-file.h>
551 #include <kpathsea/tex-make.h>
552 #include <kpathsea/variable.h>
553 #include <signal.h>
554 #if !defined(_AMIGA) && !defined(WIN32)
555 #include <sys/time.h>
556 #endif
557 #include <fcntl.h>
558 #include <setjmp.h>
559 #endif `%/* KPATHSEA */`%
560 `<h-include after KPATHSEA`>
561 >>>
562
563
564 The \`'__cdecl' is defined in KPATHSEA: kpathsea/c-protos.h
565 is defined to nothing for compilers
566 other than MS.
567
568 \<t4ht.h\><<<
569 #ifdef KPATHSEA
570 #ifdef WIN32
571 #undef CDECL
572 #define CDECL __cdecl
573 #else
574 #define CDECL
575 #endif
576 #endif
577 >>>
578
579 \<h-defines KWIN32\><<<
580 #ifdef KPATHSEA
581 #ifdef WIN32
582 #define KWIN32
583 #endif
584 #endif
585 >>>
586
587
588
589
590
591 \SubSection{Compilers}
592
593
594 \List{}
595 \item {BCC32}
596
597 For Win 95.
598
599 Options (\''bcc32' comamnd):
600
601 \Verbatim
602 Borland C++ 5.0 for Win32 Copyright (c) 1993, 1996 Borland International
603 Syntax is: BCC32 [ options ] file[s] * = default; -x- = turn switch x off
604 -3 * 80386 Instructions -4 80486 Instructions
605 -Ax Disable extensions -B Compile via assembly
606 -C Allow nested comments -Dxxx Define macro
607 -Exxx Alternate Assembler name -Hxxx Use pre-compiled headers
608 -Ixxx Include files directory -K Default char is unsigned
609 -Lxxx Libraries directory -M Generate link map
610 -N Check stack overflow -Ox Optimizations
611 -P Force C++ compile -R Produce browser info
612 -RT * Generate RTTI -S Produce assembly output
613 -Txxx Set assembler option -Uxxx Undefine macro
614 -Vx Virtual table control -X Suppress autodep. output
615 -aN Align on N bytes -b * Treat enums as integers
616 -c Compile only -d Merge duplicate strings
617 -exxx Executable file name -fxx Floating point options
618 -gN Stop after N warnings -iN Max. identifier length
619 -jN Stop after N errors -k * Standard stack frame
620 -lx Set linker option -nxxx Output file directory
621 -oxxx Object file name -p Pascal calls
622 -tWxxx Create Windows app -u * Underscores on externs
623 -v Source level debugging -wxxx Warning control
624 -xxxx Exception handling -y Produce line number info
625 -zxxx Set segment names
626 \EndVerbatim
627
628
629 \item {BCC}
630
631 For DOS.
632
633 \item {MSVC++}
634
635 For DOS.
636
637 \`'c:\msvc\bin\cl -Ic:\msvc\include -DDOS t4ht.c'
638
639 In tex-live \`' cl -D_X86_=1 -DWINVER=0x0400 -DWIN32 -D_WIN32
640 -DWIN32_LEAN_AND_MEAN -D_MT -D_DLL -DKPATHSEA
641 -D_IMPORT -DANSI -I. -I. -I.. -IG:\fptex\source\web2c-7.2 -c -W3
642 -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -O2x -G5rs -Gy
643 -c /Fodynamic\t4ht.obj .\t4ht.c'
644
645 The following are the available flags (\''c:\msvc\bin\cl -help').
646
647 \Verbatim
648 C COMPILER OPTIONS
649
650 -MEMORY MODEL-
651 /AS small model (default) /AC compact model
652 /AM medium model /AL large model
653 /AH huge model /AT tiny model (.COM files)
654 /A<string> (custom memory model)
655 -OPTIMIZATION-
656 /O enable optimization (same as /Ot) /O1 minimize space
657 /O2 maximize speed /Oa assume no aliasing
658 /Ob<n> inline expansion (default n=0) /Oc local common subexpression opt.
659 /Od disable optimization (default) /Oe enable registers allocation
660 /Of[-] toggle p-code quoting /Og global common subexpression opt.
661 /Oi enable intrinsic functions /Ol enable loop optimizations
662 /On disable ``unsafe'' optimizations /Oo[-] toggle post code-gen. opt.
663 /Op[-] improve floating-pt consistency /Oq enable maximum p-code optimization
664 /Or gen. common exit code (CodeView) /Os favor code size
665 /Ot favor code speed /Ov[-] toggle p-code frame sorting
666 /OV<n> control inlining by func. size /Ow assume cross-function aliasing
667 /Ox maximum opts. (/Ob1cegilnot /Gs) /Oz enable ``unsafe'' optimizations
668 -CODE GENERATION-
669 /G0 8086 instructions (default) /G1 186 instructions
670 /G2 286 instructions /G3 386 instructions
671 (press <return> to continue)
672 /GA protected-mode Win entry/exit code /GD protected-mode Win entry/exit code
673 /GE<x> customize Windows entry/exit /Gq backwards compatibility with v. 6
674 /Gc Pascal style calling conventions /Gd C style calling conventions
675 /Ge use stack-check calls /Gf enable string pooling
676 /Ge use stack-check calls /Gf enable string pooling
677 /Gs remove stack-check calls /Gn remove p-code native entry points
678 /Gp<num> specify p-code entry tables /Gr _fastcall style calling convention
679 /Gt[num] data size threshold /GW real-mode Windows entry/exit code
680 /Gw real-mode Windows entry/exit code /Gx assume that data is near
681 /Gx- assume that data is far /Gy separate functions for linker
682 /Zr check null pointers (/f only)
683 -OUTPUT FILES-
684 /Fa[file] name assembly listing file /Fc[file] name source/object listing
685 /Fd[file] name .PDB filename /Fe<file> name executable filename
686 /Fl[file] name object listing filename /Fm[file] name map filename
687 /Fo<file> name object filename /Fr[file] name .SBR filename
688 /Fp<file> name .PCH filename /FR[file] name extended .SBR filename
689 /Fs[file] name source listing filename
690 -PREPROCESSOR-
691 /C don't strip comments /D<name>[=|#text] define macro
692 /E preprocess to stdout /EP same as /E but no #line
693 /I<directory> add #include path /P preprocess to file
694 /U<name> remove predefined macro /u remove all defined macros
695 (press <return> to continue)
696 /X ignore "standard places"
697 -LANGUAGE-
698 /vd{0|1} disable/enable vtordisp /vm<x> type of pointers to members
699 /Z7 C 7 style CodeView information /Za disable extensions (implies /Op)
700 /Zd line number information /Ze enable extensions (default)
701 /Zg generate function prototypes /Zi prepare for debugging (CodeView)
702 /Zl omit default library name in .OBJ /Zp[n] pack structs on n-byte boundary
703 /Zs check syntax only
704 -FLOATING POINT-
705 /FPa calls with altmath /FPc calls with emulator
706 /FPc87 calls with 8087 library /FPi inline with emulator (default)
707 /FPi87 inline with 8087
708 -SOURCE LISTING-
709 /Sl<columns> set line width /Sp<lines> set page length
710 /St<string> set title string /Ss<string> set subtitle string
711 -MISCELLANEOUS-
712 /batch specify batch mode compilation /Bm<num> set compiler's available mem.
713 /c compile only, no link /H<num> external name length
714 /J default char type is unsigned /f select fast compiler (default)
715 /f- select optimizing compiler /Yc create .PCH file
716 /Yd put debug info in .PCH file /Yu use .PCH file
717 /YX automatic precompiled header /nologo suppress copyright message
718 (press <return> to continue)
719 /Mq compile for QuickWin /ND<name> name data segment
720 /NM<name> name code segment /NQ<name> combine p-code temp segments
721 /NT<name> name code segment /NV<name> name far v-table segment
722 /Tc<file> compile file without .c /Tp<file> compile file without .cpp
723 /V<string> set version string /W<n> warning level (default n=1)
724 /w disable all warnings /WX treat all warnings as errors
725 /Zn turn off SBRPACK for .SBR files
726 -MASM SUPPORT-
727 /MA<MASM switch> /Ta<file> assemble file without .asm
728 -LINKING-
729 /F <hex_num> stack size (hex. bytes) /Lr append 'r' to default lib in .OBJ
730 /link [lib] give lib name to linker /Ln do not link CRT.LIB
731 /Ld select dynamically-linked library /Lw select statically-linked library
732 \EndVerbatim
733
734
735 \EndList
736
737 \SubSection{DJGPP}
738
739
740
741
742 \Verbatim
743
744 * tex4ht.c [__DJGPP__] (ANSI, DOS_GIF_FILE): Define.
745 (WRITE_BIN_FLAGS, READ_BIN_FLAGS): Use binary mode with DJGPP.
746 (dos_file_names): New variable.
747 (sig_err): If got fatal signal other than SIGINT or SIGQUIT, don't
748 return to caller, since the program will be aborted otherwise.
749 (main) [KPATHSEA]: If input is from stdin which is not a console
750 device, switch it to binary mode. Set dos_file_names to TRUE for
751 all DOS platforms, FALSE on Unix and WIN32, and compute at runtime
752 for DJGPP. Simplify logic of finding the init file by pushing
753 HOME=C: into environment if $HOME isn't defined on DOSISH systems.
754 \EndVerbatim
755
756
757
758 \<DJGPP\><<<
759 #ifdef __DJGPP__
760 #define DOS_WIN32
761 #define ANSI
762 #endif
763 >>>
764
765
766
767
768 \<DJGPP signals\><<<
769 #ifdef __DJGPP__
770 if (s != SIGINT && s != SIGQUIT)
771 exit(EXIT_FAILURE);
772 #endif
773 >>>
774
775
776
777
778 \SubSection{Slashes n Directory Pathes}
779
780
781
782
783 \<defines\><<<
784 #if defined(DOS_WIN32) || defined(__DJGPP__)
785 #define dir_path_slash(str) (is_forward_slash(str)? '/' : '\\')
786 #else
787 #define dir_path_slash(str) '/'
788 #endif
789 >>>
790
791
792
793 \<header functions\><<<
794 #if defined(DOS_WIN32) || defined(__DJGPP__)
795 static BOOL is_forward_slash( ARG_I(Q_CHAR *) );
796 #endif
797 >>>
798
799 \<functions\><<<
800 #if defined(DOS_WIN32) || defined(__DJGPP__)
801 `[
802 static BOOL is_forward_slash(str)
803 Q_CHAR * str
804 ;{
805 while( *str ){ if( *(str++) == '/' ) { return TRUE; } }
806 return FALSE;
807 }
808 #endif
809 >>>
810
811
812
813
814
815
816
817
818 \Section{Command-Line Options}
819
820
821 \SubSection{Available Options}
822
823 \List{disc}
824 \item \`'.../'---Directory where files should be sent
825 \item \`'-mXXX'---\`'chmod XXX' for files
826 \item \`'-e...'---Name of invisible gif
827 \item \`'-d'---Directory for config files
828 \item \`'-p'---Ignore pictures (but not pictorial symbols)
829 \item \`'-i'---Debugging info
830 \item Other---Name of dvi file
831 \EndList
832
833
834 \Verbatim
835 dvips -mode ibmvga -D 110 -f foo.idv -pp 92 > tmp.ps
836 convert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps foo.gif
837 mv foo.gif /WWW/temp/.
838 cp foo.html /WWW/temp/.
839 chmod 644 /WWW/temp/foo.*
840 \EndVerbatim
841
842
843 \<command line options\><<<
844 "\n--------------------------------------------------------------------\n"
845 "t4ht [-f<dir char>]filename ...\n"
846 " -b ignore -d -m -M for bitmaps\n"
847 " -c... choose named segment in env file\n"
848 " -d... directory for output files (default: current)\n"
849 " -e... location of tex4ht.env\n"
850 " -i debugging info\n"
851 " -g ignore errors in system calls\n"
852 " -m... chmod ... of new output files (reused bitmaps excluded)\n"
853 " -p don't convert pictures (default: convert)\n"
854 " -r replace bitmaps of all glyphs (default: reuse old ones)\n"
855 " -M... chmod ... of all output files\n"
856 " -Q quit, if tex4ht.c had problems\n"
857 " -S... permission for system calls: *-always, filter\n"
858 " -X... content for field %%3 in X scripts\n"
859 " -.... content for field %%2 in . scripts\n\n"
860 "Example: \n"
861 " t4ht name -d/WWW/temp/ -etex4ht-32.env -m644\n"
862 "--------------------------------------------------------------------\n"
863 >>>
864
865
866 If option \`'-e' is present, empty pictures are replaced
867 with the named file (e.g., \`'empty.gif').
868
869
870
871
872
873 \SubSection{Scanning the Options}
874
875
876
877
878 \<vars\><<<
879 static Q_CHAR *ch_mod = Q_NULL;
880 static Q_CHAR *debug = Q_NULL;
881 static Q_CHAR *Xfield = Q_NULL;
882 static Q_CHAR *Dotfield = Q_NULL;
883 static Q_CHAR *dir = Q_NULL;
884 static Q_CHAR *lg_name = Q_NULL, tmp_name[255], job_name[255];
885 static Q_CHAR *nopict = Q_NULL;
886 static Q_CHAR *bitmaps_no_dm = Q_NULL;
887 static BOOL newchmod = FALSE;
888 static Q_CHAR *noreuse = Q_NULL;
889 >>>
890
891
892 \<scan job args\><<<
893 { int i;
894 Q_CHAR *p, *q;
895 `<kpathsea arg 0`>
896 `<default args`>
897 if( argc == 1 ){ bad_arg; }
898 for(i=1; i<argc; i++){
899 if( *( p=argv[i] ) == '-' ){ `<scan flaged args`> }
900 else
901 { lg_name = argv[i]; }
902 }
903 if( lg_name == NULL ){ bad_arg; }
904 `<set tmp file name`>
905 `<set job file name`>
906 }
907 >>>
908
909
910 \<handle quoted arguments\><<<
911 { int i, count = 0;
912 for(i=0; i<argc; i++){
913 Q_CHAR *p = argv[i];
914 count++;
915 if( (*p == '\'') || (*p == '\"') ){
916 int cnt;
917 int len = 0;
918 for( cnt=i; cnt < argc; cnt++ ){
919 len += (int) strlen((char *) argv[cnt]);
920 if( *(argv[cnt] + (int) strlen((char *) argv[cnt]) -1) == *p ){
921 Q_CHAR * arg = m_alloc(char, len + cnt - i + 1);
922 Q_CHAR * toArg = arg;
923 Q_CHAR *pp;
924 i--;
925 do {
926 pp = argv[++i];
927 while( *pp != '\0' ){
928 if( *pp != *p ){ *(toArg++) = *pp; }
929 pp++;
930 }
931 *(toArg++) = ' ';
932 } while ( i != cnt );
933 *(toArg-1) = '\0';
934 argv[count-1] = arg;
935 break;
936 } } } }
937 argc = count;
938 }
939 >>>
940
941
942
943
944 \<set tmp file name\><<<
945 { Q_CHAR *p, *q;
946 FILE* file;
947 (IGNORED) strcpy((char *) (char *) tmp_name, (char *) (char *) lg_name);
948 p = q = tmp_name + strlen((char *) tmp_name );
949 while( p != tmp_name ){
950 if( *p == '.' ){
951 if( eq_str( p+1,LG_EXT ) ) { *p = '\0'; }
952 else {
953 (IGNORED) strct( tmp_name, LG_EXT);
954 file = fopen( tmp_name, READ_TEXT_FLAGS );
955 if( file ){
956 (IGNORED) fclose(file); *q = '\0';
957 } else { *p = '\0'; }
958 }
959 break;
960 }
961 p--;
962 }
963 (IGNORED) strct(tmp_name, ".tmp");
964 }
965 >>>
966
967
968 \<set job file name\><<<
969 (IGNORED) strcpy((char *) job_name, (char *) tmp_name);
970 *(job_name + strlen((char *) job_name) - 4) = '\0';
971 >>>
972
973
974
975 \Verbatim
976 I found that I couldn't compile t4ht.c with KPATHSEA defined, and then noticed
977 that it doesn't include any of the kpathsea headers. So I have patched t4ht.c
978 to create two versions: one with the necessary kpathsea headers and one
979 without. This is the output produced by 'diff'. Let me know if you want to
980 merge my changes into your t4ht.c, and/or if you notice any errors! I have
981 changed the second argument of 'kpse_set_program_name' from NULL (which would
982 effectively mean argv[0]) to 'tex4ht', as that saves having to add a
983 'T4HTINPUTS' (or 'T4HTKINPUTS') variable into the kpathsea configuration file
984 'texmf.cnf' pointing to the same place for 'tex4ht.env' as the 'TEX4HTINPUTS'
985 variable.
986
987 For t4ht.c, the kpathsea library is only useful for locating the tex4ht.env
988 configuration file. But as it can be used for this purpose for tex4ht.c, it
989 seems a pity not to enable it for its companion program too.
990
991 > 94a99,102
992 > > #ifdef KPATHSEA
993 > > #include <kpathsea/progname.h>
994 > > #include <kpathsea/tex-file.h>
995 > > #endif
996 > 943c951
997 > < kpse_set_program_name (argv[0], NULL);
998 > ---
999 > > kpse_set_program_name (argv[0], "tex4ht");
1000 \EndVerbatim
1001
1002 \<kpathsea arg 0\><<<
1003 #ifdef KPATHSEA
1004 kpse_set_program_name (argv[0], "tex4ht");
1005 #endif
1006 >>>
1007
1008
1009
1010 If \`'strlen((char *) argv[i] ) == 2' the switch is followed by a
1011 space to be deleted when more input is awaited.
1012
1013
1014 \<scan flaged args\><<<
1015 if( (int) strlen((char *) argv[i] ) == 2 ){
1016 if( `<not a single char option?`> )
1017 { if( ++i == argc ) bad_arg; }
1018 q = argv[i];
1019 } else q = p+2;
1020 switch( *(p+1) ){
1021 case 'M':{ ch_mod = q; newchmod = TRUE; break; }
1022 case 'S':{ `<permission for system calls`> break; }
1023 case 'X':{ Xfield = q; break;}
1024 case 'b':{ bitmaps_no_dm = q-1; break;}
1025 case 'c':{ `<env blocks selector`> break;}
1026 case 'd':{ dir = (*q=='~')? abs_addr(q,NULL) : q; break; }
1027 case 'e':{ `<get .env directory from com ln`> break; }
1028 case 'f':{ `<get file name wo dir`> break; }
1029 case 'i':{ debug = q-1; break;}
1030 case 'g':{ always_call_sys = TRUE; break;}
1031 case 'm':{ ch_mod = q; break; }
1032 case 'p':{ nopict = q-1; break;}
1033 case 'Q':{ check_tex4ht_c_err = TRUE; break;}
1034 case 'r':{ noreuse = q-1; break;}
1035 case '.':{ Dotfield = q; break;}
1036 default:{ bad_arg; }
1037 }
1038 >>>
1039
1040
1041 \<not a single char option?\><<<
1042 (*(p+1) != 'i')
1043 && (*(p+1) != 'p')
1044 && (*(p+1) != 'r')
1045 && (*(p+1) != 'b')
1046 && (*(p+1) != 'g')
1047 && (*(p+1) != 'Q')
1048 >>>
1049
1050
1051
1052 The following is to allow for commands \`'htlatex
1053 -f/../source/foo.tex' which draw files from other directories for
1054 latex, but use the current directory for tex4ht.c (and t4ht.c). The
1055 character immediately after \`'-f' is a directory indicator character.
1056
1057
1058 \<get file name wo dir\><<<
1059 p = p + 2;
1060 lg_name = p + (int) strlen((char *) p );
1061 while( *lg_name != *p ){ lg_name--; }
1062 lg_name++;
1063 >>>
1064
1065
1066
1067
1068
1069 \<header functions\><<<
1070 static char * abs_addr( ARG_II( U_CHAR *, U_CHAR *) );
1071 >>>
1072
1073 \<functions\><<<
1074 `[
1075 static char * abs_addr( dir, base)
1076 U_CHAR *dir`;
1077 U_CHAR *base
1078
1079 ;{ U_CHAR *p;
1080 p = m_alloc(char, (int) strlen((char *) dir ) +
1081 (base? (int) strlen((char *) base ):0) +
1082 (int) strlen((char *) HOME_DIR ));
1083 *p = '\0';
1084 if( (*(dir+1) == '~') && base ){
1085 if( *base == '~' ){
1086 (IGNORED) strct(p, HOME_DIR);
1087 (IGNORED) strct(p, base+1);
1088 } else {
1089 (IGNORED) strct(p, base);
1090 }
1091 (IGNORED) strct(p, dir+2);
1092 } else {
1093 (IGNORED) strct(p, HOME_DIR);
1094 (IGNORED) strct(p, dir+1);
1095 }
1096 return p;
1097 }
1098 >>>
1099
1100 \<vars\><<<
1101 U_CHAR *HOME_DIR;
1102 >>>
1103
1104 \<main's init\><<<
1105 HOME_DIR = getenv("HOME");
1106 >>>
1107
1108
1109
1110
1111 \Section{Identify the Empty Pictures}
1112
1113
1114 Messages about figures that don't exist are treated as requests for
1115 empty figures. Typically, they shouldn't be present unless they are
1116 programmed into \''\setbox'-like commands. tex4ht-c identifies in the
1117 \''.lg' file the empty figures it finds.
1118
1119 The messages in the ``.lg'' file look like
1120 \`'--- empty picture --- aa.idv[1] ---'.
1121
1122
1123
1124 \<identify the empty pictures\><<<
1125 { struct empty_pic_struct *last;
1126 last = empty_pic = (struct empty_pic_struct *) 0;
1127 while( TRUE ) {
1128 status = scan_str("--- empty picture --- ", TRUE, lg_file);
1129 status = scan_until_str( ".idv[" , 1, status, lg_file);
1130 status = scan_until_end_str("] ---", 1, status, lg_file);
1131 if( status ){ `<add empty pic`> }
1132 if ( eoln_ch == EOF ){ break; }
1133 }
1134 `<add empty pic`>
1135 last->next = (struct empty_pic_struct *) 0;
1136 last->n = 100000;
1137 }
1138 >>>
1139
1140
1141 \<add empty pic\><<<
1142 if( last == (struct empty_pic_struct *) 0 ){
1143 last = empty_pic = (struct empty_pic_struct *)
1144 m_alloc(struct empty_pic_struct, (int) 1);
1145 } else {
1146 last = last->next = (struct empty_pic_struct *)
1147 m_alloc(struct empty_pic_struct, (int) 1);
1148 }
1149 last->next = (struct empty_pic_struct *) 0;
1150 last->n = get_long_int(match[1]);
1151 >>>
1152
1153
1154 \<main's vars\><<<
1155 struct empty_pic_struct *empty_pic;
1156 >>>
1157
1158 \<defines\><<<
1159 struct empty_pic_struct{
1160 long int n;
1161 struct empty_pic_struct *next;
1162 };
1163 >>>
1164
1165
1166
1167 The list of empty pictures is stored in \`'emptypic'.
1168
1169 %%%%%%%%%%%%%%%%%%%%%%%
1170 \Section{Process Gifs}
1171 %%%%%%%%%%%%%%%%%%%%%%%
1172
1173
1174
1175 %%%%%%%%%%%%%%%%%%%%%%%
1176 \SubSection{The Scripts}
1177 %%%%%%%%%%%%%%%%%%%%%%%
1178
1179 \<script for dvigif\><<<
1180 if( debug ){ (IGNORED) printf(".......'G' script\n"); }
1181 dvigif_script = add_script(dvigif_script);
1182 >>>
1183
1184
1185 \Verbatim
1186 --- needs --- aa.idv[80] ==> aa79x.gif ---
1187 --- characters ---
1188 --- needs --- aa.idv[81] ==> foo.gif ---
1189 \EndVerbatim
1190
1191
1192 \<process gif's\><<<
1193 { BOOL characters, skip;
1194 characters = skip = FALSE;
1195 while( TRUE ) {
1196 status = scan_until_str("--- ", 1, TRUE, lg_file);
1197 status = scan_until_str( " ---" , 2, status, lg_file);
1198 if( status ) {
1199 if( eq_str(match[1],"--- ") ){
1200 if( eq_str(match[2],"needs ---") ){
1201 `<--- needs ---...`>
1202 } else if( eq_str(match[2],"characters ---") ){
1203 `<--- characters ---...`>
1204 } else { `<--- ??? ---...`> }
1205 } else { `<???--- needs ---...`> }
1206 }
1207 if ( eoln_ch == EOF ){ break; }
1208 } }
1209 >>>
1210
1211
1212 \<--- ??? ---...\><<<
1213 status = scan_until_end_str("", 1, status, lg_file);
1214 >>>
1215
1216 \<???--- ??? ---...\><<<
1217 status = scan_until_end_str("", 1, status, lg_file);
1218 >>>
1219
1220
1221 \<--- characters ---...\><<<
1222 status = scan_until_end_str("", 1, status, lg_file);
1223 characters = eq_str(match[1],"");
1224 >>>
1225
1226
1227 \SubSection{Identifying the requests}
1228
1229
1230
1231 \<--- needs ---...\><<<
1232 status = scan_until_str(" ", 1, status, lg_file);
1233 status = scan_until_str(".idv", 1, status, lg_file);
1234 status = scan_until_str("[", 2, status, lg_file);
1235 status = scan_until_str("] ==> ", 2, status, lg_file);
1236 status = scan_until_str(" ", 3, status, lg_file);
1237 *(match[3] + (int) strlen((char *) match[3]) - 1) = '\0';
1238 status = scan_until_end_str("---", 4, status, lg_file);
1239 if( status ) {
1240 `<dvi2gif vars`>
1241 long int gif_i;
1242 Q_CHAR *p;
1243 gif_i = get_long_int(match[2]);
1244 p = match[2];
1245 *(p + (int) strlen((char *) p) - 6) = '\0';
1246 if( characters ){
1247 `<translate symbol gifs`>
1248 } else { `<translate non-symbol gifs`> }
1249 }
1250 >>>
1251
1252
1253 \SubSection{General Pictures}
1254
1255
1256 \`'--- needs --- aa.idv[80] ==> aa79x.gif ---'
1257
1258 \<translate non-symbol gifs\><<<
1259 if( gif_i == `<empty picture`> ) {
1260 `<insert empty picture`>
1261 } else { `<insert non-empty picture`> }
1262 >>>
1263
1264
1265 \<insert non-empty picture\><<<
1266 if( !nopict && !skip ){
1267 `<dvi into gif`>
1268 }
1269 >>>
1270
1271
1272 \<insert empty picture\><<<
1273 if( !skip ){
1274 (void) execute_script(empty_fig_script,
1275 (dir && !bitmaps_no_dm )? dir :"", match[3],"","");
1276 if( ch_mod && !bitmaps_no_dm && !system_return ){
1277 (void) execute_script(chmod_script, ch_mod,
1278 dir?dir:"",match[3], "");
1279 }
1280 }
1281 empty_pic = empty_pic->next;
1282 >>>
1283
1284
1285
1286 \<empty picture\><<<
1287 empty_pic->n
1288 >>>
1289
1290
1291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1292 \SubSection{Pictorial Symbols}
1293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1294
1295 \<translate symbol gifs\><<<
1296 Q_CHAR filename[255];
1297 FILE* file;
1298 (IGNORED) strcpy((char *) filename, "");
1299 if( dir && !bitmaps_no_dm ){ (IGNORED) strct(filename, dir); }
1300 (IGNORED) strct(filename, match[3]);
1301 file = fopen(filename, READ_TEXT_FLAGS);
1302 if( !file || noreuse ){
1303 `<dvi symbols into gif`>
1304 } else {
1305 (IGNORED) fclose(file);
1306 if( newchmod )
1307 { `<chmod for glyphs`> }
1308 (IGNORED) printf("%s already in %s\n", match[3],
1309 dir? dir : "current directory" );
1310 }
1311 >>>
1312
1313
1314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1315 \SubSection{The Conversion Code}
1316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1317
1318
1319 \<dvi into gif\><<<
1320 filtered_dvigif_script = filterGifScript(dvigif_script, match[3]);
1321 (void) execute_script(
1322 filtered_dvigif_script,match[1],match[2],match[3],job_name);
1323 (void) free_script( filtered_dvigif_script );
1324 if( dir && !bitmaps_no_dm && !system_return ){
1325 (void) execute_script(move_script,match[3],dir,".","");
1326 }
1327 if( ch_mod && !bitmaps_no_dm && !system_return ){
1328 (void) execute_script(chmod_script, ch_mod, dir?dir:"",match[3], "");
1329 }
1330 >>>
1331
1332 \<dvi symbols into gif\><<<
1333 filtered_dvigif_script = dvigif_glyp_script?
1334 filterGifScript(dvigif_glyp_script, match[3]):
1335 filterGifScript(dvigif_script, match[3]);
1336 (void) execute_script(
1337 filtered_dvigif_script,match[1],match[2],match[3],job_name);
1338 (void) free_script( filtered_dvigif_script );
1339 if( dir && !bitmaps_no_dm && !system_return ){
1340 (void) execute_script(move_script,match[3],dir,".","");
1341 `<chmod for glyphs`>
1342 }
1343 >>>
1344
1345
1346 \<chmod for glyphs\><<<
1347 if( ch_mod && !bitmaps_no_dm && !system_return ){
1348 (void) execute_script(chmod_script, ch_mod, dir?dir:"",match[3], "");
1349 }
1350 >>>
1351
1352
1353 \<dvi2gif vars\><<<
1354 struct script_struct
1355 * filtered_dvigif_script = NULL_SCRIPT;
1356 >>>
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379 \<header functions\><<<
1380 static void execute_script(
1381 ARG_V(struct script_struct*,const Q_CHAR *,const Q_CHAR *,const Q_CHAR *,const Q_CHAR *) );
1382 >>>
1383
1384 \<functions\><<<
1385 `[
1386 static void execute_script(script,match_1,match_2,match_3,match_4)
1387 struct script_struct* script`;
1388 const Q_CHAR * match_1`;
1389 const Q_CHAR * match_2`;
1390 const Q_CHAR * match_3`;
1391 const Q_CHAR * match_4
1392
1393 ;{ struct script_struct* temp;
1394 Q_CHAR *p, *q;
1395 const Q_CHAR *t;
1396 `<texmf := ...`>
1397 temp = script; system_return = 0;
1398 while( temp ){
1399 `<command = temp-command`>
1400 if( (command[0] != '\0') && !system_return ){
1401 `<execute system command`> }
1402 temp = temp->next;
1403 } }
1404 >>>
1405
1406
1407 We went to \`'%%%', \`'%%1', ... instead of \`'%%', \`'%1', ...
1408 to accomodate some needds of dos. Example (yet, where exactly the
1409 conflict is?):
1410
1411 \Verbatim
1412 if exist %1.dvi goto yes_dvi
1413 goto end
1414 yes_dvi:
1415 DEL tmp.ps
1416 call dvips32 -f %1 -p %2 -l %2 -o tmp.ps -mode ibmvga -D 110
1417 DEL %3
1418 call convert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps %3
1419 end:
1420 \EndVerbatim
1421
1422
1423
1424 \<command = temp-command\><<<
1425 p = temp->command;
1426 q = command;
1427 while( *p != '\0' ){
1428 *q = *(p++);
1429 if( (*q == '%') && (*p == '%')
1430 && ( (*(p+1) == '%')
1431 || (*(p+1) == '~')
1432 || ( (*(p+1) >= '0') && (*(p+1) < '5') ) )
1433 ){ p++;
1434 switch( *(p++) ){
1435 case '%':{ q++; break; }
1436 case '0':{ t = job_name;
1437 while( *t != '\0' ){ *(q++) = *(t++); } break; }
1438 case '1':{ t = match_1;
1439 while( *t != '\0' ){ *(q++) = *(t++); } break; }
1440 case '2':{ t = match_2;
1441 while( *t != '\0' ){ *(q++) = *(t++); } break; }
1442 case '3':{ t = match_3;
1443 while( *t != '\0' ){ *(q++) = *(t++); } break; }
1444 case '4':{ t = match_4;
1445 while( *t != '\0' ){ *(q++) = *(t++); } break; }
1446 case '~':{ `<q += texmf path`> break; }
1447 default: { }
1448 }} else { q++; }
1449 }
1450 *q = '\0';
1451 >>>
1452
1453 The argument `\Verb=%%~=' is replaced with the value of
1454 \Verb=${TEXMFDIST}= under Kpathsea. If such a value
1455 is not available, the character `\Verb=~=' is used. The variable
1456 offers the parent directory of where tex4ht resides, e.g.,
1457 \Verb=/usr/local/texlive/2018/texmf-dist=. We use TEXMFDIST in
1458 preference to SELFAUTOPARENT (as was done until June 2018), or
1459 TEXMFROOT, because in practice it works on both \TeX\ Live and MiK\TeX,
1460 while the others do not.
1461
1462 \<texmf := ...\><<<
1463 #ifdef KPATHSEA
1464 const char * texmf = kpse_var_value( "TEXMFDIST" );
1465 #endif
1466 >>>
1467
1468 \<q += texmf path\><<<
1469 #ifdef KPATHSEA
1470 if( texmf ){
1471 t = texmf;
1472 while( *t != '\0' ){ *(q++) = *(t++); }
1473 } else {
1474 *(q++) = '~';
1475 }
1476 #else
1477 *(q++) = '~';
1478 #endif
1479 >>>
1480
1481
1482
1483
1484 \Verbatim
1485
1486 > > help tinkering with the code. If you'll have a chance at some
1487 > > point to pass on the kind of changes you are doing, I'll be interested
1488 > > to hardwire them in the code as compile/run-time options.
1489 > for instance, I add -Pem to the dvips command line to access the EM
1490 > fonts instead of EC (faster)
1491 >
1492 > i also change the name of "convert.exe" to "iconvert.exe" because it
1493 > conflicts with a native NT utility to convert file systems :-}
1494
1495 \EndVerbatim
1496
1497 \Verbatim
1498 dvips -mode $mf -D $density -f $_[0] -pp $_[1] > tmp.ps
1499 \EndVerbatim
1500
1501 \<defines\><<<
1502 #ifndef HTFDIR
1503 #define HTFDIR ""
1504 #endif
1505 >>>
1506
1507
1508
1509
1510
1511
1512 %%%%%%%%%%%%%%%%%%%%%%%%
1513 \SubSection{Filter}
1514 %%%%%%%%%%%%%%%%%%%%%%%%
1515
1516
1517
1518 Three cases for `G' and `F' scripts.
1519
1520 \List{}
1521 \item
1522 {The first record doesn't start with a period}
1523 Use the script until its end or a period command
1524 \item
1525 {The first record starts with a period without an extension}
1526 Use the script until its end or a period command
1527 \item
1528 {The first record starts with a period with an extension}
1529 Use the script until its end or a period command, if the extension
1530 fits the output figure.
1531
1532 \EndList
1533
1534
1535 \<header functions\><<<
1536 static struct script_struct * filterGifScript(
1537 ARG_II( struct script_struct *, Q_CHAR *) );
1538 >>>
1539
1540 \<functions\><<<
1541 `[
1542 static struct script_struct * filterGifScript( script, file)
1543 struct script_struct *script`;
1544 Q_CHAR *file
1545 ;{
1546 struct script_struct *filtered_script, *scr,
1547 *old_script,
1548 *new_script;
1549 Q_CHAR *command, *ext;
1550 filtered_script = NULL_SCRIPT;
1551 if( script == NULL_SCRIPT )
1552 return filtered_script;
1553 old_script = script;
1554 command = old_script->command;
1555 if( *command != '.' ){
1556 `<script until dot`>
1557 } else {
1558 `<script from dot`>
1559 }
1560 }
1561 >>>
1562
1563 \<script until dot\><<<
1564 new_script = NULL_SCRIPT;
1565 while( old_script != NULL_SCRIPT ){
1566 command = old_script->command;
1567 if( *command == '.' ){ return filtered_script; }
1568 scr = (struct script_struct *)
1569 m_alloc(struct script_struct, (int) 1);
1570 scr->command = old_script->command;
1571 scr->next = NULL_SCRIPT;
1572 if( new_script == NULL_SCRIPT ){
1573 filtered_script = new_script = scr;
1574 } else {
1575 new_script = new_script->next = scr;
1576 }
1577 old_script = old_script->next;
1578 }
1579 return filtered_script;
1580 >>>
1581
1582 \<script from dot\><<<
1583 `<ext = file ext`>
1584 while( TRUE ){
1585 if( old_script == NULL_SCRIPT ){
1586 return NULL_SCRIPT;
1587 }
1588 command = old_script->command;
1589 if(*command != '.') {
1590 old_script = old_script->next;
1591 continue;
1592 }
1593 old_script = old_script->next;
1594 if( (*(command+1) == '\0') || eq_str(ext,command) ){
1595 break;
1596 }
1597 }
1598 `<script until dot`>
1599 >>>
1600
1601
1602 \<ext = file ext\><<<
1603 ext = file;
1604 while( *ext != '\0' ){ ext++; }
1605 while( (*ext != '.') && (ext != file) ){ ext--; }
1606 >>>
1607
1608
1609 \<header functions\><<<
1610 void free_script(
1611 ARG_I( struct script_struct *) );
1612 >>>
1613
1614 \<functions\><<<
1615 `[
1616 void free_script(script)
1617 struct script_struct *script
1618 ;{
1619 struct script_struct *temp;
1620 while( script != NULL_SCRIPT ){
1621 temp = script;
1622 script = script->next;
1623 free( temp );
1624 }
1625 }
1626 >>>
1627
1628
1629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1630 \SubSection{Ignore/Noignore Commands}
1631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1632
1633
1634 \<???--- ??? ---...\><<<
1635 status = scan_until_end_str("", 1, status, lg_file);
1636 >>>
1637
1638
1639 \Verbatim
1640 l. 10 --- needs --- ignore ---
1641 l. 11 --- needs --- end ignore ---
1642 \EndVerbatim
1643
1644
1645 We didn't check below the \`'l. dddd ' part.
1646
1647 \<???--- needs ---...\><<<
1648 status = scan_until_end_str(" ignore ---", 2, status, lg_file);
1649 if( status ){
1650 skip = eq_str(match[2]," ignore ---") ? TRUE :
1651 ( eq_str(match[2]," end ignore ---") ? FALSE : skip );
1652 }
1653 >>>
1654
1655
1656
1657 %%%%%%%%%%%%%%%%%%%%%%%
1658 \Section{CopyTo files}
1659 %%%%%%%%%%%%%%%%%%%%%%%
1660
1661
1662 There are 6 supporting dvi variations of the
1663 `CopyTo to-file op group'
1664 dvi command:
1665
1666 \List{}
1667 \item{From} Start copying (at current address)
1668 \item{Until} End copying (at current address)
1669 \item{Skip} Start skipping (from current address)
1670 \item{Cont} End skipping (at current-address)
1671 \item{Addr integer-label} Associate current
1672 address with the integer-label of the given group
1673 \item{Set integer-label}
1674 Replace the `current address' in the following Skip/Cont (and
1675 From/Until ?) commands with the address associated to the
1676 integer-label of the given group by an Addr command
1677 \EndList
1678
1679 The code
1680 \Verbatim
1681 B0
1682 \ht:special {t4ht@DCopyTo: \jobname-js.tex From bib }
1683 B1
1684 \ht:special {t4ht@DCopyTo: \jobname-js.tex Skip bib }
1685 B2
1686 \ht:special {t4ht@DCopyTo: \jobname-js.tex Addr1 bib }
1687 B3
1688 \ht:special {t4ht@DCopyTo: \jobname-js.tex Addr2 bib }
1689 B4
1690 \ht:special {t4ht@DCopyTo: \jobname-js.tex Set1 bib }
1691 \ht:special {t4ht@DCopyTo: \jobname-js.tex Cont bib }
1692 \ht:special {t4ht@DCopyTo: \jobname-js.tex Set2 bib }
1693 \ht:special {t4ht@DCopyTo: \jobname-js.tex Skip bib }
1694 B5
1695 \ht:special {t4ht@DCopyTo: \jobname-js.tex Until bib }
1696 B6
1697 \EndVerbatim
1698
1699 produces the string ` B1 B3 '.
1700
1701
1702
1703
1704 \<CopyTo files\><<<
1705 { `<CopyTo vars`>
1706 eoln_ch = (int) 'x';
1707 while( eoln_ch != EOF ) {
1708 status = scan_str("CopyTo: ", TRUE, lg_file);
1709 status = scan_until_str(" ", 1, status, lg_file);
1710 status = scan_until_str(" ", 2, status, lg_file);
1711 status = scan_until_str(" ", 3, status, lg_file);
1712 status = scan_until_str(" ", 4, status, lg_file);
1713 status = scan_until_end_str("", 5, status, lg_file);
1714 if( status ){
1715 if( debug ){
1716 (IGNORED) printf("...CopyTo: %s%s%s%s%s...\n",
1717 match[1], match[2], match[3], match[4], match[5]);
1718 }
1719 rec_op = eq_str(match[2],"From ")? From_op :
1720 ( eq_str(match[2],"Until ")? Until_op :
1721 ( eq_str(match[2],"Skip ")? Skip_op :
1722 ( eq_str(match[2],"Cont ")? Cont_op : No_op )));
1723 if( rec_op == No_op ){ `<try Addr and Set ops`> }
1724 if( rec_op == No_op ){
1725 (IGNORED) fprintf(stderr,"--- warning --- ");
1726 (IGNORED) fprintf(stderr,"CopyTo: %s%s%s%s%s?\n",
1727 match[1], match[2], match[3], match[4], match[5]);
1728 } else {
1729 `<find file records`>
1730 `<find to-from record`>
1731 `<find group record`>
1732 `<enter op record`>
1733 `<act on op`>
1734 } } }
1735 `<release CopyTo resources`>
1736 }
1737 >>>
1738
1739
1740 \<try Addr and Set ops\><<<
1741 ch = match[2];
1742 if( (ch[0]=='S') && (ch[1]=='e') && (ch[2]=='t') ){
1743 ch += 3; rec_op = Set_op;
1744 } else if( (ch[0]=='A') && (ch[1]=='d') && (ch[2]=='d') && (ch[3]=='r') ){
1745 ch += 4; rec_op = Addr_op;
1746 }
1747 if( rec_op != No_op ){
1748 addr = 0; while( (*ch>='0') && (*ch<='9') ){
1749 addr = addr*10 + *ch - '0'; ch++;
1750 } }
1751 >>>
1752
1753 \<release CopyTo resources\><<<
1754 for( p = opened_files; p != (struct files_rec*) 0; ){
1755 (IGNORED) fclose(p->file);
1756 free((void *) p->name);
1757 `<free to-from records`>
1758 p1= p; p = p->right; free((void *) p1);
1759 }
1760 >>>
1761
1762 \<free to-from records\><<<
1763 for( p1 = p->down; p1 != (struct files_rec*) 0; ){
1764 `<free group records`>
1765 p2 = p1; p1 = p1->right; free((void *) p2);
1766 }
1767 >>>
1768
1769 \<free group records\><<<
1770 for( p2 = p1->down; p2 != (struct files_rec*) 0; ){
1771 `<free op records`>
1772 p3 = p2; p2 = p2->right; free((void *) p3);
1773 }
1774 >>>
1775
1776 \<free op records\><<<
1777 for( p3 = p2->down; p3 != (struct files_rec*) 0; ){
1778 p4 = p3; p3 = p3->down; free((void *) p4);
1779 }
1780 >>>
1781
1782
1783
1784
1785
1786 \<act on op\><<<
1787 if( rec_op == Until_op ){
1788 for( p = to_rec->down;
1789 p != (struct files_rec*) 0; p = p->down ){
1790 if( p->op == From_op ){ from_op = p; break; }
1791 }
1792 if( p == (struct files_rec*) 0 ){
1793 `<missing From for CopyTo`>
1794 } else {
1795 `<perform ops`>
1796 `<remove ops`>
1797 }
1798 }
1799 >>>
1800
1801
1802
1803
1804 \<perform ops\><<<
1805 in_file = from_rec->file;
1806 out_file = to_rec->file;
1807 start_loc = from_op->loc;
1808 write_on = TRUE;
1809 (IGNORED) fseek(in_file, (long) start_loc, `<abs file addr`>);
1810 for( p= from_op; p != to_rec; p = p->up ){
1811 switch( p->op ){
1812 case Until_op:{ `<Until op`> break; }
1813 case Skip_op:{ `<Skip op`> break; }
1814 case Cont_op:{ `<Cont op`> break; }
1815 case Set_op:{ `<Set op`> break; }
1816 default: { }
1817 } }
1818 >>>
1819
1820
1821 \<Until op\><<<
1822 if( write_on ){
1823 end_loc = p->loc;
1824 for(; start_loc<end_loc; start_loc++) {
1825 (IGNORED) putc( getc(in_file), out_file );
1826 } }
1827 >>>
1828
1829
1830 \<Skip op\><<<
1831 if( write_on ){
1832 end_loc = p->loc;
1833 for(; start_loc<end_loc; start_loc++) {
1834 (IGNORED) putc( getc(in_file), out_file );
1835 }
1836 }
1837 write_on = FALSE;
1838 >>>
1839
1840
1841 \<Cont op\><<<
1842 end_loc = p->loc;
1843 if( write_on ){
1844 for(; start_loc<end_loc; start_loc++) {
1845 (IGNORED) putc( getc(in_file), out_file );
1846 }
1847 } else {
1848 start_loc = end_loc;
1849 (IGNORED) fseek(in_file, (long) end_loc, `<abs file addr`>);
1850 }
1851 write_on = TRUE;
1852 >>>
1853
1854
1855 \<Set op\><<<
1856 addr = -1;
1857 for( p1 = from_op->up; p1 != to_rec; p1 = p1->up ){
1858 if( (p1->op == Addr_op) && (p1->label == p->label) ){
1859 addr = p1->loc; break;
1860 } }
1861 if( addr != -1 ){ (p->up)->loc = addr; }
1862 >>>
1863
1864
1865 \<remove ops\><<<
1866 to_rec->down = from_op->down;
1867 if( from_op->down != (struct files_rec*) 0){
1868 (from_op->down)->up = to_rec;
1869 }
1870 for( p = from_op; p != to_rec; ){
1871 p1 = p; p = p->up; free((void *) p1);
1872 }
1873 if( to_rec->down == (struct files_rec*) 0){
1874 if( to_rec->left == (struct files_rec*) 0 ){
1875 (to_rec->up)->down = to_rec->right;
1876 } else {
1877 (to_rec->left)->right = to_rec->right;
1878 }
1879 if( to_rec->right != (struct files_rec*) 0 ){
1880 (to_rec->right)->left = to_rec->left;
1881 }
1882 p1 = to_rec; to_rec = to_rec->up; free((void *) p1);
1883 }
1884 >>>
1885
1886 \<missing From for CopyTo\><<<
1887 (IGNORED) fprintf(stderr,"%sMissing ``CopyTo From':\n", "--- warning --- ");
1888 for( p = to_rec->down; p != (struct files_rec*) 0; p = p->down ){
1889 (IGNORED) fprintf(stderr," %s %s%d %s\n", to_rec->name,
1890 p->op == From_op ? "From " :
1891 ( p->op == Until_op ? "Until " :
1892 ( p->op == Skip_op ? "Skip " :
1893 ( p->op == Cont_op? "Cont " :
1894 ( p->op == Addr_op? "Addr " :
1895 ( p->op == Set_op? "Set " : "No_op " ))))),
1896 p->loc, from_rec->name
1897 );
1898 }
1899 >>>
1900
1901
1902
1903
1904 \<enter op record\><<<
1905 p = m_alloc(struct files_rec, 1);
1906 p->down = to_rec->down; to_rec->down = p;
1907 p->up = to_rec;
1908 if( p->down != (struct files_rec*) 0 ){
1909 (p->down)->up = p;
1910 }
1911 *(match[4] + (int) strlen((char *) match[4]) - 1) = '\0';
1912 p->loc = (int) get_long_int(match[4]);
1913 p->op = rec_op;
1914 p->label = addr;
1915 >>>
1916
1917 \<find group record\><<<
1918 if( to_rec->down == (struct files_rec*) 0 ){
1919 `<add first group record`>
1920 } else {
1921 to_rec = to_rec->down;
1922 for( p = to_rec->right; p != (struct files_rec*) 0; p = p->right ){
1923 if( eq_str(to_rec->group,match[3]) ){ break; }
1924 to_rec = p;
1925 }
1926 if( !eq_str(to_rec->group,match[3]) ){
1927 `<add next group record`>
1928 } }
1929 >>>
1930
1931
1932
1933 \<add first group record\><<<
1934 to_rec->down = p = m_alloc(struct files_rec, 1);
1935 p->up = to_rec;
1936 p->right = p->left = p->down = (struct files_rec*) 0;
1937 p->name = to_rec->name;
1938 p->file = to_rec->file;
1939 p->from_rec = from_rec;
1940 p->loc = -1;
1941 p->op = No_op;
1942 p->group = m_alloc(char, (int) strlen((char *) match[3]) + 1);
1943 (IGNORED) strcpy((char *) p->group, (char *) match[3] );
1944 to_rec = p;
1945 >>>
1946
1947 \<add next group record\><<<
1948 to_rec->right = p = m_alloc(struct files_rec, 1);
1949 p->left = to_rec;
1950 p->right = p->down = (struct files_rec*) 0;
1951 p->up = to_rec->up;
1952 p->name = to_rec->name;
1953 p->file = to_rec->file;
1954 p->from_rec = from_rec;
1955 p->loc = -1;
1956 p->group = m_alloc(char, (int) strlen((char *) match[3]) + 1);
1957 (IGNORED) strcpy((char *) p->group, (char *) match[3] );
1958 to_rec = p;
1959 >>>
1960
1961
1962
1963 \<find to-from record\><<<
1964 if( to_rec->down == (struct files_rec*) 0 ){
1965 `<add first to-from record`>
1966 } else {
1967 to_rec = to_rec->down;
1968 for( p = to_rec->right; p != (struct files_rec*) 0; p = p->right ){
1969 if( to_rec->from_rec == from_rec ){ break; }
1970 to_rec = p;
1971 }
1972 if( to_rec->from_rec != from_rec ){
1973 `<add next to-from record`>
1974 } }
1975 >>>
1976
1977 \<add first to-from record\><<<
1978 to_rec->down = p = m_alloc(struct files_rec, 1);
1979 p->up = to_rec;
1980 p->right = p->left = p->down = (struct files_rec*) 0;
1981 p->name = to_rec->name;
1982 p->file = to_rec->file;
1983 p->from_rec = from_rec;
1984 p->loc = -1;
1985 p->op = No_op;
1986 to_rec = p;
1987 >>>
1988
1989 \<add next to-from record\><<<
1990 to_rec->right = p = m_alloc(struct files_rec, 1);
1991 p->left = to_rec;
1992 p->right = p->down = (struct files_rec*) 0;
1993 p->up = to_rec->up;
1994 p->name = to_rec->name;
1995 p->file = to_rec->file;
1996 p->from_rec = from_rec;
1997 p->loc = -1;
1998 to_rec = p;
1999 >>>
2000
2001
2002 \<find file records\><<<
2003 file_name = match[1];
2004 *(file_name + (int) strlen((char *) file_name) - 1) = '\0';
2005 strcpy((char *) file_mode, WRITE_TEXT_FLAGS);
2006 for(i=1; i<=2; i++){
2007 `<search CopyTo file`>
2008 file_name = match[5];
2009 strcpy((char *) file_mode, `<CopyTo read flags`>);
2010 }
2011 >>>
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021 \<search CopyTo file\><<<
2022 for( p = opened_files; p != (struct files_rec*) 0; p = p->right ){
2023 if( eq_str(file_name,p->name) ) { break; }
2024 }
2025 if( p == (struct files_rec*) 0 ){
2026 p = m_alloc(struct files_rec, 1);
2027 p->right = opened_files; opened_files = p;
2028 p->down = (struct files_rec*) 0;
2029 strcpy((char *) p->file_mode, (char *) file_mode);
2030 p->name = m_alloc(char, (int) strlen((char *) file_name) + 1);
2031 (IGNORED) strcpy((char *) p->name, (char *) file_name );
2032 if( (p->file = fopen(file_name, file_mode)) == NULL )
2033 { (IGNORED) warn_i_str(5,file_name); }
2034 }
2035 to_rec = from_rec; from_rec = p;
2036 >>>
2037
2038
2039 \<defines\><<<
2040 struct files_rec{
2041 FILE* file;
2042 char *name, *group, op;
2043 Q_CHAR file_mode[5];
2044 int loc, label;
2045 struct files_rec *from_rec, *right, *left, *down, *up;
2046 };
2047 #define No_op 0
2048 #define From_op 1
2049 #define Until_op 2
2050 #define Skip_op 3
2051 #define Cont_op 4
2052 #define Addr_op 5
2053 #define Set_op 6
2054 >>>
2055
2056 \<CopyTo vars\><<<
2057 Q_CHAR *file_name, file_mode[5];
2058 int i, start_loc, end_loc, addr = 0;
2059 char rec_op, *ch;
2060 static struct files_rec *to_rec, *from_rec,
2061 *opened_files = (struct files_rec *) 0,
2062 *p, *p1, *p2, *p3, *p4, *from_op;
2063 FILE *in_file, *out_file;
2064 BOOL write_on;
2065 >>>
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082 %%%%%%%%%%%%%%%%%%%%%%%
2083 \Section{post-process ext files}
2084 %%%%%%%%%%%%%%%%%%%%%%%
2085
2086 \<post-process ext files\><<<
2087 if( `<ext-script`> ){
2088 eoln_ch = (int) 'x';
2089 while( eoln_ch != EOF ) {
2090 status = scan_str("File: ", TRUE, lg_file);
2091 status = scan_until_str(".", 1, status, lg_file);
2092 status = scan_until_end_str("", 2, status, lg_file);
2093 if( status ){ Q_CHAR *ext;
2094 struct script_struct *cur_script;
2095 ext = match[1];
2096 (IGNORED) strct( ext, match[2] );
2097 ext += strlen((char *) ext);
2098 while( *(--ext) != '.' ){ ; }
2099 *ext = '\0'; ext++;
2100 `<get script for ext`>
2101 (void) execute_script(cur_script,
2102 match[1], Dotfield? Dotfield : "", "", "");
2103 `<release script for ext`>
2104 } } }
2105 >>>
2106
2107
2108 \<get script for ext\><<<
2109 {
2110 struct script_struct *cur, *add, *temp;
2111 Q_CHAR extPlus[256];
2112 cur = `<ext-script`>;
2113 add = cur_script = NULL_SCRIPT;
2114 while( cur ){
2115 `<ext = ext + choise`>
2116 if( strpre(extPlus, cur->command) ){
2117 `<temp = ext command`>
2118 if( cur_script == NULL_SCRIPT ){
2119 cur_script = add = temp;
2120 } else {
2121 add = add->next = temp;
2122 } }
2123 cur = cur->next;
2124 } }
2125 >>>
2126
2127
2128
2129 \<ext = ext + choise\><<<
2130 (IGNORED) strcpy((char *) extPlus, (char *) ext);
2131 /*
2132 if ( envChoice ) {
2133 (IGNORED) strct ( extPlus, envChoice );
2134 }
2135 */
2136 (IGNORED) strct ( extPlus, " " );
2137 >>>
2138
2139 \<temp = ext command\><<<
2140 temp = (struct script_struct *)
2141 m_alloc(struct script_struct, (int) 1);
2142 temp->command = m_alloc(char, (int) strlen((char *) cur->command) + 1);
2143 temp->next = NULL_SCRIPT;
2144 (IGNORED) strcpy((char *) temp->command,
2145 (char *) cur->command + (int) strlen((char *) extPlus) );
2146 >>>
2147
2148 \<release script for ext\><<<
2149 while( cur_script != (struct script_struct*) 0 ){
2150 struct script_struct *temp;
2151 temp = cur_script; cur_script = cur_script->next; free((void *) temp);
2152 }
2153 >>>
2154
2155
2156 \<header functions\><<<
2157 static BOOL strpre( ARG_II(char *,char *) );
2158 >>>
2159
2160 \<functions\><<<
2161 `[
2162 static BOOL strpre(s1,s2)
2163 char * s1`;
2164 char * s2
2165 ;{ int i;
2166 for( i=0; i < (int) strlen((char *) s1); i++){
2167 if( *(s1+i) != *(s2+i) ){ return FALSE; }
2168 }
2169 return TRUE;
2170 }
2171 >>>
2172
2173
2174
2175 \<ext-script\><<<
2176 ext_script
2177 >>>
2178
2179
2180
2181 \<defines\><<<
2182 struct env_c_rec{
2183 Q_CHAR *option;
2184 struct env_c_rec *next;
2185 };
2186 >>>
2187
2188 \<vars\><<<
2189 static struct env_c_rec *envChoice
2190 = (struct env_c_rec*) 0;
2191 >>>
2192
2193
2194 \<env blocks selector\><<<
2195 struct env_c_rec *temp = (struct env_c_rec*)
2196 m_alloc(struct env_c_rec, (int) 1);
2197 temp->option = q;
2198 temp->next = envChoice;
2199 envChoice = temp;
2200 >>>
2201
2202 \<env-skip = skip segment match[1]\><<<
2203 if( envChoice == (struct env_c_rec*) 0 ){
2204 env_skip = !eq_str(match[1], "default" );
2205 } else {
2206 struct env_c_rec *p;
2207 env_skip = TRUE;
2208 for( p=envChoice; p!=(struct env_c_rec*) 0 ; p = p->next ){
2209 if( eq_str(match[1], p->option ) ){ env_skip = FALSE; }
2210 } }
2211 >>>
2212
2213
2214
2215
2216 %%%%%%%%%%%%%%%%%%%%%%%
2217 \Section{post-process files}
2218 %%%%%%%%%%%%%%%%%%%%%%%
2219
2220
2221 \<post-process files\><<<
2222 if( `<file-script`> ){
2223 eoln_ch = (int) 'x';
2224 while( eoln_ch != EOF ) {
2225 status = scan_str("File: ", TRUE, lg_file);
2226 status = scan_until_str(".", 1, status, lg_file);
2227 status = scan_until_end_str("", 2, status, lg_file);
2228 if( status ){ Q_CHAR *p;
2229 p = match[1];
2230 (IGNORED) strct( p, match[2] );
2231 p += strlen((char *) p);
2232 while( *(--p) != '.' ){ ; }
2233 *p = '\0'; p++;
2234 (void) execute_script(file_script, match[1],
2235 p, Xfield? Xfield : "", "");
2236 } } }
2237 >>>
2238
2239 \<file-script\><<<
2240 file_script
2241 >>>
2242
2243 %%%%%%%%%%%%%%%%%%%%%%%
2244 \Section{User Commands}
2245 %%%%%%%%%%%%%%%%%%%%%%%
2246
2247 \`'l. 10 --- needs --- "ls *" ---'
2248
2249 \<process user commands\><<<
2250 eoln_ch = (int) 'x';
2251 while( eoln_ch != EOF ) { Q_CHAR *command, ch;
2252 int n;
2253 struct sys_call_rec *p;
2254 BOOL flag;
2255 status = scan_str("l. ", TRUE, lg_file);
2256 status = scan_until_str(" --- needs --- \"", 1, status, lg_file);
2257 status = scan_until_str("\" ---", 2, status, lg_file);
2258 if( status ){
2259 command = match[2];
2260 *(command + (int) strlen((char *) command) - 5) = '\0';
2261 `<flag = permission for system calls`>
2262 if( flag ){
2263 `<execute system command`>
2264 } else { (IGNORED) printf(
2265 "No permission for system call: %s\n", command); }
2266 } }
2267 >>>
2268
2269
2270 \<env permissions for system calls\><<<
2271 { struct sys_call_rec *q;
2272 q = m_alloc(struct sys_call_rec, 1);
2273 q->next = system_calls;
2274 q->filter = match[1];
2275 match[1] = (Q_CHAR *) malloc(70); max_match[1] = 70;
2276 system_calls = q;
2277 if( debug ){
2278 (IGNORED) printf(".......'S' script: '%s'\n",
2279 q->filter); }
2280 }
2281 >>>
2282
2283 \<permission for system calls\><<<
2284 { struct sys_call_rec *q;
2285 q = m_alloc(struct sys_call_rec, 1);
2286 q->next = system_calls;
2287 q->filter = p + 2;
2288 system_calls = q;
2289 }
2290 >>>
2291
2292
2293 \<flag = permission for system calls\><<<
2294 flag = FALSE;
2295 p = system_calls;
2296 while( p ){
2297 if( (n = (int) strlen((char *) p->filter)) == 1 ) {
2298 if( *(p->filter) == '*' ){
2299 flag = TRUE; break;
2300 }
2301 }
2302 if( strlen((char *) command) >= (unsigned int) n ) {
2303 ch = command[n]; command[n] = '\0';
2304 flag = flag || eq_str(p->filter,command);
2305 command[n] = ch;
2306 }
2307 p = p->next;
2308 }
2309 >>>
2310
2311 \<defines\><<<
2312 struct sys_call_rec{
2313 Q_CHAR * filter;
2314 struct sys_call_rec *next;
2315 };
2316 >>>
2317
2318
2319 \<vars\><<<
2320 static BOOL system_yes;
2321 static struct sys_call_rec *system_calls = (struct sys_call_rec *) 0;
2322 >>>
2323
2324
2325
2326
2327
2328
2329
2330
2331 From log files \`'l. # --- needs --- "command" ---'
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342 %%%%%%%%%%%%%
2343 \Section{CSS}
2344 %%%%%%%%%%%%%
2345
2346
2347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2348 \SubSection{Record HTFCSS Entries from the lg File}
2349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2350
2351
2352 The htfcss records are stored in the following linked list, and used
2353 when the font entries `Font("key","...","...","...")' are loaded
2354 (Section~'\Link{usehtfcc}{}\XRef{usehtfcc}\EndLink').
2355
2356 \<vars\><<<
2357 static struct htf_struct *htf_rec = (struct htf_struct *) 0;
2358 >>>
2359
2360
2361 \<defines\><<<
2362 struct htf_struct{
2363 Q_CHAR *key, *body, *media;
2364 struct htf_struct *next;
2365 };
2366 >>>
2367
2368
2369
2370
2371
2372 \<htfcss from lg\><<<
2373 { struct htf_struct *last_rec, *p;
2374 last_rec = (struct htf_struct *) 0;
2375 eoln_ch = (int) 'x';
2376 while( eoln_ch != EOF ) {
2377 status = scan_str("htfcss: ", TRUE, lg_file);
2378 status = scan_until_end_str("", 1, status, lg_file);
2379 `<remove leading spaces`>
2380 if( status ){ Q_CHAR *key, *body, *media;
2381 media = body = key = match[1];
2382 `<process htfcss line`>
2383 } }
2384 }
2385 >>>
2386
2387 \<remove leading spaces\><<<
2388 if( status ){
2389 Q_CHAR *s, *t;
2390 int i;
2391 s = t = match[1];
2392 for( i=0; *s == ' '; s++ ) { i++; }
2393 if( i>0 ){
2394 while( *s != 0 ){
2395 *(t++) = *(s++);
2396 }
2397 *t = 0;
2398 } }
2399 >>>
2400
2401
2402 ?? How the case `append prev htfcss rec' can be reached ??
2403
2404 \<process htfcss line\><<<
2405 while( *body && (*body != ' ') ){ body++; }
2406 if( *body == ' ' ){ media = body; *(body++) = '\0'; }
2407 `<extract media info`>
2408 if( *body ){
2409 if( *key ){ `<add new htfcss rec`> }
2410 #if 0 /* unreachable */
2411 else if( last_rec ){ `<append prev htfcss rec`> }
2412 #endif /* 0, unreachable */
2413 }
2414 >>>
2415
2416 \<extract media info\><<<
2417 if( (int) strlen((char *) body) > 6 ){
2418 if( (*(body) == '@')
2419 && (*(body+1) == 'm')
2420 && (*(body+2) == 'e')
2421 && (*(body+3) == 'd')
2422 && (*(body+4) == 'i')
2423 && (*(body+5) == 'a') )
2424 {
2425 body += 6;
2426 while( *body == ' ' ){ body++; }
2427 media = body;
2428 while( (*body != ' ') && (*body != '\0') ){ body++; }
2429 if( *body == ' ' ){ *(body++) = '\0'; }
2430 while( *body == ' ' ){ body++; }
2431 } }
2432 >>>
2433
2434 \<add new htfcss rec\><<<
2435 p = m_alloc(struct htf_struct, 1);
2436 p->next = (struct htf_struct *) 0;
2437 p->key = m_alloc(char, (int) strlen((char *) key) + 1);
2438 (IGNORED) strcpy((char *) p->key, (char *) key );
2439 p->media = m_alloc(char, (int) strlen((char *) media) + 1);
2440 (IGNORED) strcpy((char *) p->media, (char *) media );
2441 p->body = m_alloc(char, (int) strlen((char *) body) + 1);
2442 (IGNORED) strcpy((char *) p->body, (char *) body );
2443 if( last_rec ){
2444 last_rec->next = p; last_rec = p;
2445 } else {
2446 htf_rec = last_rec = p;
2447 }
2448 if( debug ){
2449 (IGNORED) printf(".......%s...%s...%s\n", key, media, body);
2450 }
2451 >>>
2452
2453 \<append prev htfcss rec\><<<
2454 last_rec->body = (Q_CHAR *) r_alloc((void *) last_rec->body,
2455 (size_t) strlen((char *) last_rec->body)
2456 + (size_t) strlen((char *) body)
2457 + 2);
2458 (IGNORED) strct(last_rec->body,"\n");
2459 (IGNORED) strct(last_rec->body,body);
2460 if( debug ){
2461 (IGNORED) printf(".......%s\n", body);
2462 }
2463 >>>
2464
2465
2466
2467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2468 \SubSection{Font-Css-Plus Entries from The lg File}
2469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2470
2471 The command \`'\Configure{htf-css}{cmmi}{font-style: italic;}'
2472 provides in the lg file an entry of the form
2473 \`'Font_Css_Plus cmmi font-style: italic;'.
2474
2475 \<font=(...) from lg\><<<
2476 eoln_ch = (int) 'x';
2477 while( eoln_ch != EOF ) {
2478 status = scan_str("Font_Css_Plus ", TRUE, lg_file);
2479 status = scan_until_str(" ", 1, status, lg_file);
2480 status = scan_until_end_str("", 2, status, lg_file);
2481 if( status ){ Q_CHAR *key;
2482 key = match[1];
2483 *(key + (int) strlen((char *) key) - 1) = '\0';
2484 `<store font style of lg`>
2485 } }
2486 >>>
2487
2488
2489
2490 \<store font style of lg\><<<
2491 if( (*key != '\0') && (*key != '\n') ) {
2492 struct htf_struct *p;
2493 p = m_alloc(struct htf_struct, 1);
2494 p->next = htf_rec;
2495 htf_rec = p;
2496 p->key = m_alloc(char, (int) strlen((char *) key) + 1);
2497 (IGNORED) strcpy((char *) p->key, (char *) key );
2498 p->body = m_alloc(char, (int) strlen((char *) match[2]) + 1);
2499 (IGNORED) strcpy((char *) p->body, (char *) match[2] );
2500 if( debug ){
2501 (IGNORED) printf(".......%s...%s\n", key, match[2]);
2502 } }
2503 >>>
2504
2505
2506
2507
2508
2509
2510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2511 \SubSection{Imported Css File}
2512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2513
2514
2515
2516
2517 %Css: TD.caption{white-space: nowrap; }
2518 %Font("cmex","10","100")
2519 %Font("cmmi","10","100")
2520 %Font("cmmi","5","100")
2521 %Font("cmmi","7","100")
2522 %Font("cmr","10","100")
2523 %Font("cmr","5","100")
2524 %Font("cmr","7","100")
2525 %Font("cmsy","10","100")
2526 %Font("cmsy","7","100")
2527 %Font("cmti","10","100")
2528 %Font("cmtt","10","100")
2529 %Font_Class(1,""): <IMG SRC=""ALT=""CLASS="%s%s-%d--%x">
2530 %Font_Class(3,"mva"): <IMG SRC=""ALT=""CLASS="%s-%d--%x"ALIGN="MIDDLE">
2531 %Font_Class(6,"ul"): <SPAN CLASS="underline"></SPAN>
2532 %Font_Css("sc"): .small-caps{font-variant: small-caps; }
2533 % Font_Css("ul"): .underline{text-decoration:underline; }
2534
2535
2536
2537
2538 \<process css\><<<
2539 {
2540 Q_CHAR css_name[255];
2541 FILE *css_file, *tmp_file;
2542 BOOL css_sty;
2543 `<css-file = open file ...`>
2544 if( css_file ){
2545 (IGNORED) printf ("Entering %s\n", css_name);
2546 tmp_file = fopen(tmp_name, WRITE_TEXT_FLAGS);
2547 if( !tmp_file ) {
2548 (IGNORED) warn_i_str(5,tmp_name);
2549 } else { `<c: tex4ht.tmp := css file`> }
2550 tmp_file = open_file(tmp_name, ".tmp");
2551 css_file = fopen(css_name, WRITE_TEXT_FLAGS);
2552 if( !tmp_file ) {
2553 (IGNORED) warn_i_str(5,tmp_name);
2554 } else if( !css_file ) {
2555 (IGNORED) warn_i_str(5,css_name);
2556 } else {
2557 `<c: css file = header of tex4ht.tmp`>
2558 if( css_sty ){
2559 `<css file = css.sty`>
2560 `<css file = tail of tex4ht.tmp`>
2561 }
2562 }
2563 (IGNORED) fclose(tmp_file);
2564 (IGNORED) fclose(css_file);
2565 } }
2566 >>>
2567
2568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2569 \SubSection{Preliminary Processing of the CSS File}
2570 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2571
2572 \<c: tex4ht.tmp := css file\><<<
2573 int ch;
2574 while( (ch = getc(css_file)) != EOF ) {
2575 (IGNORED) putc( ch, tmp_file );
2576 }
2577 (IGNORED) fclose(tmp_file);
2578 (IGNORED) fclose(css_file);
2579 >>>
2580
2581
2582 \<css-file = open file ...\><<<
2583 (IGNORED) strcpy((char *) css_name, (char *) job_name);
2584 (IGNORED) strct(css_name, ".css");
2585 css_file = fopen(css_name, READ_TEXT_FLAGS);
2586 >>>
2587
2588 \SubSection{Cotributors to the Css File}
2589
2590 Copy until insertion point:
2591
2592 \`'/* css.sty */'
2593
2594 \<c: css file = header of tex4ht.tmp\><<<
2595 css_sty = FALSE;
2596 eoln_ch = (int) 'x';
2597 while( eoln_ch != EOF ) {
2598 status = scan_until_end_str("", 1, TRUE, tmp_file);
2599 `<match[2] := compressed match[1]`>
2600 if( eq_str(match[2], "/*css.sty*/") ){ css_sty = TRUE; break; }
2601 (IGNORED) fprintf(css_file, "%s\n", match[1]);
2602 }
2603 >>>
2604
2605 \<vars\><<<
2606 static BOOL status;
2607 >>>
2608
2609
2610
2611 \<match[2] := compressed match[1]\><<<
2612 { Q_CHAR *p, *q;
2613 int n;
2614 n = 0; p = match[1]; q = match[2];
2615 while ( (*p != '\0') ){
2616 if (n == 13) { *(q-10) = '\0'; break;}
2617 if( *p != ' ' ){ *(q++) = *p; n++; }
2618 p++;
2619 }
2620 *q = '\0';
2621 }
2622 >>>
2623
2624 Contribution from lg File
2625
2626
2627
2628 \<css file = css.sty\><<<
2629 (IGNORED) fprintf(css_file, "/* start css.sty */\n");
2630 `<rewind lg file`> `<Font_css_base: ...`>
2631 `<rewind lg file`> `<process Font_Size: ...`>
2632 `<rewind lg file`> `<process Font(...)`>
2633 `<rewind lg file`> `<process Font_Css(...):...`>
2634 `<rewind lg file`> `<process Css:...`>
2635 (IGNORED) fprintf(css_file, "/* end css.sty */\n");
2636 >>>
2637
2638
2639 The \`'<process Css:...>' should be after the other two's to allow
2640 the user to overide with \''\Css' commands the
2641 other contributions.
2642
2643
2644
2645
2646 We want to remove the non-leading \`'/* css.sty */', just
2647 in case t4ht.perl is called consequtively more than once.
2648
2649 \<css file = tail of tex4ht.tmp\><<<
2650 eoln_ch = (int) 'x';
2651 while( eoln_ch != EOF ) {
2652 status = scan_until_end_str("", 1, TRUE, tmp_file);
2653 `<match[2] := compressed match[1]`>
2654 if( !eq_str(match[2], "/*css.sty*/") ){
2655 (IGNORED) fprintf(css_file, "%s\n", match[1]);
2656 }
2657 }
2658 >>>
2659
2660
2661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2662 \SubSection{Contributions from /Css Commands}
2663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2664
2665 \`'Css: P.noindent { text-indent: 0em }'
2666
2667 \<process Css:...\><<<
2668 eoln_ch = (int) 'x';
2669 while( eoln_ch != EOF ) {
2670 status = scan_str("Css: ", TRUE, lg_file);
2671 status = scan_until_end_str("", 1, status, lg_file);
2672 if( status ){
2673 (IGNORED) fprintf(css_file, "%s\n", match[1]);
2674 } }
2675 >>>
2676
2677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2678 \SubSection{Contributions From Font-Size}
2679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2680
2681
2682 \`'\Needs{"Font_Size: 12"}'
2683
2684
2685
2686 \<process Font_Size: ...\><<<
2687 eoln_ch = (int) 'x';
2688 while( eoln_ch != EOF ) {
2689 status = scan_str("Font_Size: ", TRUE, lg_file);
2690 status = scan_until_end_str("", 1, status, lg_file);
2691 if( status ){
2692 base_font_size = (int) get_long_int(match[1]);
2693 } }
2694 >>>
2695
2696
2697
2698
2699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2700 \SubSection{Contributions to Fonts}
2701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2702 \Link{}{usehtfcc}\EndLink\Tag{usehtfcc}{Contributions to Fonts}
2703
2704 \`'Font("family_name", "font_size", "design_sz * 100 / 655360 / 10", "mag")'
2705 (e.g., \`'Font("cmr","10","10","100")',
2706 \`'Font("aptmri","8t",??,"100")',
2707 \`'Font("ecti","1095","10","100")')
2708
2709
2710
2711
2712
2713
2714
2715 \<process Font(...)\><<<
2716 eoln_ch = (int) 'x';
2717 while( eoln_ch != EOF ) {
2718 status = scan_str("Font(\"", TRUE, lg_file);
2719 status = scan_until_str("\",\"", 1, status, lg_file);
2720 status = scan_until_str("\",\"", 2, status, lg_file);
2721 status = scan_until_str("\",\"", 3, status, lg_file);
2722 status = scan_until_end_str("\")", 4, status, lg_file);
2723 if( status ){
2724 Q_CHAR *p;
2725 struct htf_struct *font_sty;
2726 int second;
2727 p = match[1];
2728 *(p + (int) strlen((char *) p) - 3) = '\0';
2729 p = match[2];
2730 *(p + (int) strlen((char *) p) - 3) = '\0';
2731 p = match[3];
2732 *(p + (int) strlen((char *) p) - 3) = '\0';
2733 p = match[4];
2734 *(p + (int) strlen((char *) p) - 2) = '\0';
2735 `<get font size`>
2736 `<get font style`>
2737 } }
2738 >>>
2739
2740
2741
2742
2743
2744 \<get font style\><<<
2745 font_sty = htf_rec;
2746 while ( font_sty ) {
2747 if( eq_str(font_sty->key,match[1]) ){
2748 if( *(font_sty->media) == '\0' ){
2749 `<print font style css`>
2750 second = 100;
2751 } else {
2752 `<print media style`>
2753 }
2754 }
2755 font_sty = font_sty->next;
2756 }
2757 if( second != 100 ){ `<print font style css`> }
2758 >>>
2759
2760
2761
2762
2763 \<get font size\><<<
2764 { Q_CHAR *p;
2765 second = (int)
2766 ( (int) get_long_int(match[3])
2767 * (int) get_long_int(match[4])
2768 / base_font_size
2769 );
2770 while( second > 700 ){ second /= 10; }
2771 p = match[3];
2772 while( *p != '\0' ){
2773 if( (*p < '0') || (*p > '9') ){ second = 100; break; }
2774 p++;
2775 }
2776 `<inspect font-size argument`>
2777 }
2778 >>>
2779
2780 The following case handles cases like that of \`'Font("ecti","1095","10","100")', where
2781 \Verb=base_font_size= is 11.
2782
2783 \<inspect font-size argument\><<<
2784 if( (int) ( (double) get_long_int(match[2])
2785 / (int) get_long_int(match[4])
2786 + 0.5
2787 )
2788 == base_font_size
2789 ){
2790 second = 100;
2791 };
2792 >>>
2793
2794
2795
2796
2797
2798
2799
2800
2801 \<Font_css_base: ...\><<<
2802 eoln_ch = (int) 'x';
2803 while( eoln_ch != EOF ) {
2804 status = scan_str("Font_css_base: ", TRUE, lg_file);
2805 status = scan_until_str("Font_css_mag: ", 1, status, lg_file);
2806 status = scan_until_end_str("", 2, status, lg_file);
2807 if( status ){
2808 Font_css_base = match[1];
2809 *(Font_css_base + (int) strlen((char *) Font_css_base) - 14) = '\0';
2810 match[1] = (Q_CHAR *) malloc(70); max_match[1] = 70;
2811 Font_css_mag = match[2];
2812 match[2] = (Q_CHAR *) malloc(70); max_match[2] = 70;
2813 } }
2814 >>>
2815
2816
2817
2818
2819 \<vars\><<<
2820 static char *Font_css_base = NULL,
2821 *Font_css_mag = NULL;
2822 static int base_font_size = 10;
2823 >>>
2824
2825
2826
2827 \<print font style css\><<<
2828 (IGNORED) fprintf(css_file,
2829 (Font_css_base == NULL)? ".%s-%s" : Font_css_base,
2830 match[1], match[2]);
2831 if( !eq_str(match[4],"100") ){
2832 (IGNORED) fprintf(css_file,
2833 (Font_css_mag == NULL)? "x-x-%s" : Font_css_mag,
2834 match[4]);
2835 }
2836 (IGNORED) fprintf(css_file, "{");
2837 if( (second < 98) || (second > 102) ){
2838 (IGNORED) fprintf(css_file, "font-size:%d%c;", second, '%');
2839 }
2840 if( font_sty ) {
2841 (IGNORED) fprintf(css_file, "%s", font_sty->body);
2842 }
2843 (IGNORED) fprintf(css_file, "}\n");
2844 >>>
2845
2846
2847 \<print media style\><<<
2848 (IGNORED) fprintf(css_file, "@media %s{", font_sty->media);
2849 (IGNORED) fprintf(css_file,
2850 (Font_css_base == NULL)? ".%s-%s" : Font_css_base,
2851 match[1], match[2]);
2852 if( !eq_str(match[4],"100") ){
2853 (IGNORED) fprintf(css_file,
2854 (Font_css_mag == NULL)? "x-x-%s" : Font_css_mag,
2855 match[4]);
2856 }
2857 (IGNORED) fprintf(css_file, "{");
2858 if( font_sty ) {
2859 (IGNORED) fprintf(css_file, "%s", font_sty->body);
2860 }
2861 (IGNORED) fprintf(css_file, "}}\n");
2862 >>>
2863
2864
2865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2866 \SubSection{Font-Css Contributions}
2867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2868
2869 \`'Font_Css("4"): .small-caps{font-variant: small-caps; }'
2870
2871 \<process Font_Css(...):...\><<<
2872 { char *font_class [256];
2873 int last_class;
2874 `<find usage`>
2875 eoln_ch = (int) 'x';
2876 while( eoln_ch != EOF ) {
2877 status = scan_str("Font_Css(\"", TRUE, lg_file);
2878 status = scan_until_str("\"): ", 1, status, lg_file);
2879 status = scan_until_end_str("", 2, status, lg_file);
2880 if( status ){ int i;
2881 for(i=0; i<last_class; i++){
2882 if( eq_str(match[1],font_class[i]) ){
2883 (IGNORED) fprintf(css_file, "%s\n", match[2]);
2884 break;
2885 } } } } }
2886 >>>
2887
2888
2889
2890 \<find usage\><<<
2891 last_class = 0;
2892 eoln_ch = (int) 'x';
2893 while( eoln_ch != EOF ) {
2894 status = scan_str("Font_Class(", TRUE, lg_file);
2895 status = scan_until_str(",\"", 1, status, lg_file);
2896 status = scan_until_str("\"): ", 1, status, lg_file);
2897 status = scan_until_end_str("", 2, status, lg_file);
2898 if( status ){
2899 font_class[last_class++] = match[1];
2900 match[1] = (Q_CHAR *) malloc(7); max_match[1] = 7;
2901 } }
2902 `<rewind lg file`>
2903 >>>
2904
2905
2906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2907 \Section{Load Env File}
2908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2909
2910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2911 \SubSection{Retrieve Info}
2912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2913
2914 \<load env file\><<<
2915 { FILE* file;
2916 U_CHAR env_loc[512];
2917 env_loc[0] = '\0';
2918 `<find tex4ht.env`>
2919 if( file ){
2920 `<get info from env file`>
2921 (IGNORED) fclose(file);
2922 } }
2923 >>>
2924
2925
2926 % (IGNORED) printf("Entering %s\n", env_loc[0]? &env_loc[0]
2927 % :"tex4ht.env");
2928
2929
2930
2931 \<get info from env file\><<<
2932 eoln_ch = (int) 'x';
2933 while( eoln_ch != EOF ) { Q_CHAR ch;
2934 ch = (char) (eoln_ch = getc(file));
2935 if( eoln_ch != (int) '\n' ){
2936 status = scan_until_end_str("", 1, TRUE, file);
2937 if( status ){
2938 switch( ch ){
2939 case 'A':{ `<script for chmod`> break;}
2940 case 'C':{ `<script for copy`> break;}
2941 case 'E':{ `<script for empty gifs`> break;}
2942 case 'F':{ `<script for dvigif of glyps`> break;}
2943 case 'G':{ `<script for dvigif`> break;}
2944 case 'M':{ `<script for move`> break;}
2945 case 'S':{ `<env permissions for system calls`> break;}
2946 case 'X':{ `<script for file`> break;}
2947 case '.':{ `<script for file ext`> break;}
2948 case '<':{ `<env selector`> break;}
2949 default:{ }
2950 } } } }
2951 >>>
2952
2953
2954
2955
2956
2957 \<script for dvigif of glyps\><<<
2958 if( debug ){
2959 (IGNORED) printf(".......'F' script\n"); }
2960 dvigif_glyp_script = add_script(dvigif_glyp_script);
2961 >>>
2962
2963
2964 \<script for move\><<<
2965 if( debug ){
2966 (IGNORED) printf(".......'M' script\n"); }
2967 move_script = add_script(move_script);
2968 >>>
2969
2970
2971 \<script for copy\><<<
2972 if( debug ){
2973 (IGNORED) printf(".......'C' script\n"); }
2974 copy_script = add_script(copy_script);
2975 >>>
2976
2977
2978
2979
2980
2981 \<script for file\><<<
2982 if( debug ){
2983 (IGNORED) printf(".......'X' script\n"); }
2984 `<file-script`> = add_script(`<file-script`>);
2985 >>>
2986
2987 \<script for file ext\><<<
2988 if( debug ){
2989 (IGNORED) printf(".......'.' script\n"); }
2990 `<ext-script`> = add_script(`<ext-script`>);
2991 >>>
2992
2993
2994
2995
2996 \<script for chmod\><<<
2997 if( debug ){
2998 (IGNORED) printf(".......'A' script\n"); }
2999 chmod_script = add_script(chmod_script);
3000 >>>
3001
3002 \<script for empty gifs\><<<
3003 if( debug ){
3004 (IGNORED) printf(".......'E' script\n"); }
3005 empty_fig_script = add_script(empty_fig_script);
3006 >>>
3007
3008
3009 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3010 \SubSection{Utilities for Retrieving Info}
3011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3012
3013 \<env selector\><<<
3014 if( *(match[1]) != '/' ){
3015 U_CHAR *p;
3016 BOOL env_skip;
3017 for( p = match[1];
3018 (*p != '>') && (*p != '\n') && (*p != EOF ) ;
3019 p++ ){}
3020 if( *p == '>' ){ *p = '\0'; }
3021 `<env-skip = skip segment match[1]`>
3022 if( env_skip ){
3023 `<skip env segment`>
3024 } else {
3025 if( debug ){
3026 (IGNORED) printf("....... <%s>\n", match[1]);
3027 }
3028 }
3029 } else if( debug ){
3030 (IGNORED) printf("....... <%s\n", match[1]);
3031 }
3032 >>>
3033
3034 \<skip env segment\><<<
3035 U_CHAR cur_block[90];
3036 if( debug ){
3037 (IGNORED) printf("....... <%s> skipping ...\n", match[1]);
3038 }
3039 (IGNORED) strcpy((char *) cur_block, (char *) match[1]);
3040 status = FALSE;
3041 while( !status && (eoln_ch != EOF) ){
3042 status = scan_str("</", TRUE, file);
3043 status = scan_until_str(">", 1, status, file);
3044 status = scan_until_end_str("", 2, status, file);
3045 if( status ){
3046 *(match[1] + strlen((char *) match[1]) - 1) = '\0';
3047 status = eq_str(match[1], cur_block);
3048 if( debug ){
3049 (IGNORED) printf("....... </%s>\n", match[1]);
3050 } } }
3051 >>>
3052
3053
3054
3055 \<header functions\><<<
3056 static struct script_struct * add_script( ARG_I(struct script_struct *) );
3057 >>>
3058
3059 \<functions\><<<
3060 `[
3061 static struct script_struct * add_script(script)
3062 struct script_struct * script
3063 ;{
3064 struct script_struct* temp, * q;
3065 temp = (struct script_struct *)
3066 m_alloc(struct script_struct, (int) 1);
3067 temp->command = match[1];
3068 if( debug ){
3069 (IGNORED) printf("....... %s\n", temp->command); }
3070 temp->next = NULL_SCRIPT;
3071 match[1] = (Q_CHAR *) malloc(70);
3072 max_match[1] = 70;
3073 if( script ){
3074 q = script;
3075 while( q->next ){ q = q->next; }
3076 q->next = temp;
3077 } else {
3078 script = temp;
3079 }
3080 return script;
3081 }
3082 >>>
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092 \<defines\><<<
3093 struct script_struct{
3094 Q_CHAR *command;
3095 struct script_struct *next;
3096 };
3097 >>>
3098
3099 \<vars\><<<
3100 static struct script_struct
3101 * dvigif_script = NULL_SCRIPT,
3102 * dvigif_glyp_script = NULL_SCRIPT,
3103 * move_script = NULL_SCRIPT,
3104 * empty_fig_script = NULL_SCRIPT,
3105 * copy_script = NULL_SCRIPT,
3106 * `<file-script`> = NULL_SCRIPT,
3107 * `<ext-script`> = NULL_SCRIPT,
3108 * chmod_script = NULL_SCRIPT;
3109 >>>
3110
3111 \<defines\><<<
3112 #define NULL_SCRIPT (struct script_struct *) 0
3113 >>>
3114
3115
3116
3117
3118
3119
3120
3121
3122 % case 'H':{ `<env-htf-sty = htfcss.env file`> break;}
3123 %
3124 % \<env-htf-sty = htfcss.env file\><<<
3125 % env_htf_sty = match[1];
3126 % match[1] = (Q_CHAR *) malloc(70);
3127 % max_match[1] = 70;
3128 % if( debug ){
3129 % (IGNORED) printf(".......'H' script: '%s'\n",
3130 % env_htf_sty); }
3131 % >>>
3132 %
3133 % \<vars\><<<
3134 % static Q_CHAR* env_htf_sty = Q_NULL;
3135 % >>>
3136
3137
3138
3139 \Verbatim
3140 % dvips -mode ibmvga -D 110 -f foo.idv -pp 92 > tmp.ps
3141 % convert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps foo.gif
3142 Gdvips -mode ibmvga -D 110 -f %1 -pp %2 > tmp.ps
3143 Gconvert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps %3
3144 % t4ht -d%2
3145 Mmv %1 %2%3
3146 Ccp %1 %2%3
3147 % t4ht -d%2 -m%1
3148 Achmod %1 %2%3
3149 H/n/gold/5/gurari/tex4ht.dir/
3150 \EndVerbatim
3151
3152
3153
3154 \SubSection{Open Directory}
3155
3156 \<env file at work dir\><<<
3157 if( !file ) {
3158 if( debug ){
3159 (IGNORED) printf("tex4ht.env?\n");
3160 }
3161 file = f_open("tex4ht.env", READ_TEXT_FLAGS);
3162 (IGNORED) strcpy((char *) &env_loc[0], "tex4ht.env");
3163 if( debug && file ){
3164 (IGNORED) printf(".......Open: ./tex4ht.env\n"); }
3165 }
3166 >>>
3167
3168 \<find tex4ht.env\><<<
3169 { Q_CHAR str[512],
3170 *TEX4HTENV;
3171 `<env file from command switch`>
3172 `<env file at work dir`>
3173 `<env file .tex4ht`>
3174 `<TEX4HTENV env`>
3175 `<env file at root dir`>
3176 `<ENVFILE env`>
3177 if( !file ) { `<env file from prog loc`> }
3178 `<kpathsea env file`>
3179 if( !file ) warn_i_str( 5, `<warn 1`>);
3180 }
3181 >>>
3182
3183
3184
3185
3186
3187
3188
3189
3190 \<TEX4HTENV env\><<<
3191 if( !file ){
3192 TEX4HTENV = getenv("TEX4HTENV");
3193 if( TEX4HTENV ){
3194 if( debug ){
3195 (IGNORED) printf("%s?\n", TEX4HTENV);
3196 }
3197 file = f_home_open(TEX4HTENV,READ_TEXT_FLAGS);
3198 }
3199 }
3200 >>>
3201
3202
3203
3204
3205
3206
3207 \<env file .tex4ht\><<<
3208 #ifndef DOS_WIN32
3209 if( !file ) {
3210 if( debug ){
3211 (IGNORED) printf(".tex4ht?\n");
3212 }
3213 file = f_open(".tex4ht", READ_TEXT_FLAGS);
3214 (IGNORED) strcpy((char *) &env_loc[0], ".tex4ht");
3215 if( debug && file ){
3216 (IGNORED) printf(".......Open: ./.tex4ht\n"); }
3217 }
3218 #endif
3219 >>>
3220
3221 \<ENVFILE env\><<<
3222 #ifdef ENVFILE
3223 if( !file ) {
3224 if( debug ){
3225 (IGNORED) printf("%s?\n", ENVFILE);
3226 }
3227 file = f_home_open( ENVFILE,READ_TEXT_FLAGS);
3228 (IGNORED) strcpy((char *) &env_loc[0], (char *) ENVFILE);
3229 if( debug && file ){
3230 (IGNORED) printf(".......Open: %s\n", ENVFILE); }
3231 }
3232 #endif
3233 >>>
3234
3235
3236
3237 \<h-defines\><<<
3238 #ifndef ENVFILE
3239
3240 #endif
3241 >>>
3242
3243
3244
3245 \<warn 1\><<<
3246 #ifdef DOS_WIN32
3247 "tex4ht.env"
3248 #endif
3249 #ifndef DOS_WIN32
3250 "tex4ht.env | .tex4ht"
3251 #endif
3252 >>>
3253
3254
3255
3256
3257 \<kpathsea env file\><<<
3258
3259 #ifdef KPATHSEA
3260 if( !file ) { U_CHAR * envfile;
3261 char *arch, *p, str[256];
3262 `<arch = tail of SELFAUTOLOC`>
3263 envfile = (char *) 0;
3264 `<envfile = kpse-find-file architecture/tex4ht.env`>
3265 if ( !envfile ){ `<envfile = kpse-find-file tex4ht.env`> }
3266 if ( !envfile ){ `<envfile = kpathsea tex4ht.env`> }
3267 if ( envfile ){
3268 file = kpse_open_file (envfile, kpse_program_text_format);
3269 (IGNORED) printf("(%s)\n", envfile);
3270 }
3271 if( debug && file ){
3272 (IGNORED) printf(".......Open kpathsea %s\n", envfile);
3273 }
3274 }
3275 if( debug ){
3276 U_CHAR *p, *q;
3277 `<trace T4HTINPUTS`>
3278 }
3279 #endif
3280 >>>
3281
3282 %%%<--
3283
3284 \<arch = tail of SELFAUTOLOC\><<<
3285 p = arch = (char *) kpse_var_value( "SELFAUTOLOC" );
3286 while( *p != '\0' ){
3287 if( (*p == '/') || (*p == '\\') ){
3288 arch = p;
3289 }
3290 p++;
3291 }
3292 >>>
3293
3294
3295 \<envfile = kpse-find-file architecture/tex4ht.env\><<<
3296 if( arch ){
3297 (IGNORED) sprintf(str,"%s%ctex4ht.env", arch+1, *arch);
3298 if( debug ){
3299 (IGNORED) printf(
3300 "kpse_open_file (\"%s\", kpse_program_text_format)?\n", str );
3301 }
3302 envfile= kpse_find_file (str, kpse_program_text_format, 0);
3303 }
3304 >>>
3305
3306
3307 \<envfile = kpse-find-file tex4ht.env\><<<
3308 if( debug ){
3309 (IGNORED) printf(
3310 "kpse_open_file (\"tex4ht.env\", kpse_program_text_format)?\n");
3311 }
3312 envfile= kpse_find_file ("tex4ht.env", kpse_program_text_format, 0);
3313 >>>
3314
3315
3316 % if( debug ){
3317 % (IGNORED) printf( "kpse_open_file (\"tex4ht.env\", ...)?\n");
3318 % }
3319 % envfile= kpse_find_file ("tex4ht.env", kpse_program_text_format, 0);
3320
3321
3322
3323
3324
3325
3326 \<trace T4HTINPUTS\><<<
3327 p = (U_CHAR *) kpse_var_value( "T4HTINPUTS" );
3328 if( p ){
3329 (IGNORED) printf("T4HTINPUTS = %s\n", p);
3330 }
3331 q = getenv("T4HTINPUTS");
3332 if( q ){ (IGNORED) printf(
3333 "Environmet var T4HTINPUTS: %s\n", q);
3334 }
3335 if( !p && !q ){
3336 (IGNORED) printf( "Missing T4HTINPUTS for kpathsea\n" );
3337 }
3338 >>>
3339
3340
3341
3342
3343
3344
3345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3346 \SubSection{kpathsea vs kpse-find-file}
3347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3348
3349
3350 The kpathsea utility might succeed where kpse-find-file fails. Maybe due to:
3351 ``Kpathsea's subdirectory searching has an
3352 irremediable deficiency: If a directory D being searched for
3353 subdirectories contains plain files and symbolic links to other
3354 directories, but no true subdirectories, D will be considered a
3355 leaf directory, i.e., the symbolic links will not be followed.''
3356 [\Link[http://www.tug.org/svn/texlive/trunk/Build/source/texk/kpathsea/kpathsea.info?view=markup]{}{}kpathsea.info\EndLink]
3357
3358
3359
3360
3361 \<envfile = kpathsea tex4ht.env\><<<
3362 if( system("kpsewhich --progname=tex4ht tex4ht.env > tex4ht.tmp") == 0 ){
3363 `<fileaddr = read tex4ht.tmp`>
3364 envfile= kpse_find_file (fileaddr, kpse_program_text_format, 0);
3365 }
3366 >>>
3367
3368
3369
3370 Don't know how to avoid the use of intermediate file: popen(...) and
3371 fork() are not stadard utilities. Also the redirection \Verb+>+ might
3372 need to be changed, e.g., to \Verb+>&+.
3373
3374 \<fileaddr = read tex4ht.tmp\><<<
3375 char fileaddr [256];
3376 int loc = 0;
3377 FILE* file = f_open("tex4ht.tmp", READ_TEXT_FLAGS);
3378 if( file ){
3379 while( (fileaddr[loc] = getc(file)) >=0 ){
3380 if( fileaddr[loc] == '\n' ){ fileaddr[loc] = '\0'; break; }
3381 loc++;
3382 }
3383 (IGNORED) fclose(file);
3384 }
3385 >>>
3386
3387
3388
3389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3390 \SubSection{Root Directory}
3391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3392
3393
3394 \<env file at root dir\><<<
3395 if( !file ){
3396 if( HOME_DIR ){ (IGNORED) sprintf(str,`<"s/tex4ht.env"`>, HOME_DIR);
3397 if( debug ){
3398 (IGNORED) printf("%s?\n", str);
3399 }
3400 file = f_open(str,READ_TEXT_FLAGS);
3401 (IGNORED) strcpy((char *) &env_loc[0], (char *) str);
3402 if( debug && file ){
3403 (IGNORED) printf(".......Open: %s\n", str); }
3404 }
3405 }
3406 #ifndef DOS_WIN32
3407 if( !file ){
3408 if( HOME_DIR ){
3409 (IGNORED) sprintf(str,"%s/.tex4ht", HOME_DIR);
3410 if( debug ){
3411 (IGNORED) printf("%s?\n", str);
3412 }
3413 file = f_open(str,READ_TEXT_FLAGS);
3414 (IGNORED) strcpy((char *) &env_loc[0], (char *) str);
3415 if( debug && file ){
3416 (IGNORED) printf(".......Open: %s\n", str); }
3417 }
3418 }
3419 #endif
3420 #if defined(DOS_WIN32) || defined(__MSDOS__)
3421 if( !file ){
3422 if( debug ){
3423 (IGNORED) printf("C:/tex4ht.env?\n");
3424 }
3425 file = f_open("C:/tex4ht.env",READ_TEXT_FLAGS);
3426 (IGNORED) strcpy((char *) &env_loc[0], "C:/tex4ht.env");
3427 if( debug && file ){
3428 (IGNORED) printf(".......Open: C:/tex4ht.env\n"); }
3429 }
3430 #endif
3431 >>>
3432
3433 \<"s/tex4ht.env"\><<<
3434 #if defined(DOS_WIN32) || defined(__DJGPP__)
3435 is_forward_slash(HOME_DIR)? "%s/tex4ht.env" : "%s\\tex4ht.env"
3436 #else
3437 "%s/tex4ht.env"
3438 #endif
3439 >>>
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451 \SubSection{Env File from Command Line}
3452
3453 \<env file from command switch\><<<
3454 if( tex4ht_env_file ){
3455 if( debug ){
3456 (IGNORED) printf("%s?\n", tex4ht_env_file);
3457 }
3458 file = f_home_open( tex4ht_env_file, READ_TEXT_FLAGS );
3459 } else {
3460 file = NULL;
3461 }
3462 if( tex4ht_env_file ){
3463 (IGNORED) strcpy((char *) &env_loc[0], (char *) tex4ht_env_file);
3464 }
3465 if( debug && file ){
3466 (IGNORED) printf(".......Open: %s\n", tex4ht_env_file); }
3467 >>>
3468
3469 \<env file from prog loc\><<<
3470 if( dos_env_file ){
3471 if( debug ){
3472 (IGNORED) printf("%s?\n", dos_env_file);
3473 }
3474 file = f_open( dos_env_file, READ_TEXT_FLAGS ) ;
3475 (IGNORED) strcpy((char *) &env_loc[0], (char *) dos_env_file);
3476 if( debug && file ){
3477 (IGNORED) printf(".......Open: %s\n", dos_env_file); }
3478 }
3479 >>>
3480
3481
3482
3483 Search along the path: command line file $\rightarrow$ work
3484 directory $\rightarrow$ home directory $\rightarrow$ system file.
3485
3486 \<get .env directory from com ln\><<<
3487 tex4ht_env_file = q;
3488 >>>
3489
3490 % if( !access(p+2,F_OK) ) tex4ht_env_file = q;
3491 % else warn_i_str(6,q);
3492
3493
3494 The function \`'int access(const char *pathname, int mode)', and the mode
3495 \`'F_OK' that tests for the existence of file, are defined in the
3496 following directory. The function returns 0 if ok and -1 on error .
3497
3498 Where access comes from in dos?
3499
3500 \<h-include before KPATHSEA\><<<
3501 #ifndef __DJGPP__
3502 `<h-include near KPATHSEA`>
3503 #endif
3504 >>>
3505
3506
3507
3508 The following is because \`'<unistd.h>
3509 defines F_OK in DJGPP'.
3510
3511 \<h-include after KPATHSEA\><<<
3512 #ifdef __DJGPP__
3513 `<h-include near KPATHSEA`>
3514 #endif
3515 >>>
3516
3517 \<h-include near KPATHSEANO\><<<
3518 #ifndef F_OK
3519 #ifdef DOS_WIN32
3520 #define F_OK 0 `% does file exist `%
3521 #endif
3522 #ifndef DOS_WIN32
3523 #define HAVE_UNISTD_H
3524 #endif
3525 #endif
3526 #ifdef HAVE_IO_H
3527 #include <io.h>
3528 #endif
3529 #ifdef HAVE_UNISTD_H
3530 #include <unistd.h>
3531 #endif
3532 >>>
3533
3534 \<h-include near KPATHSEA\><<<
3535 #ifndef F_OK
3536 #ifdef DOS_WIN32
3537 #define F_OK 0 `% does file exist `%
3538 #endif
3539 #ifndef KPATHSEA
3540 #ifndef DOS_WIN32
3541 #define HAVE_UNISTD_H
3542 #endif
3543 #endif
3544 #endif
3545 #ifdef HAVE_IO_H
3546 #include <io.h>
3547 #endif
3548 #ifndef KPATHSEA
3549 #ifdef HAVE_UNISTD_H
3550 #include <unistd.h>
3551 #endif
3552 #endif
3553 >>>
3554
3555
3556
3557 \SubSection{Env File from Location of t4ht.c}
3558
3559 \<main's vars\><<<
3560 Q_CHAR * tex4ht_env_file = (Q_CHAR *) 0;
3561 Q_CHAR * dos_env_file =
3562 #if defined(__MSDOS__)
3563 `<get dos env file`>;
3564 #endif
3565 #if !defined(__MSDOS__)
3566 (Q_CHAR *) 0;
3567 #endif
3568
3569 >>>
3570
3571 Under DOS, argv[0] usually includes the full path to the program -
3572 even if it wasn't typed in. This can be used to find the program's own
3573 directory, and hence the configuration file. I've implemented this
3574 already as follows:
3575
3576 \<get dos env file\><<<
3577 get_env_dir(argv[0])
3578 >>>
3579
3580 \<functions\><<<
3581 #if defined(__MSDOS__)
3582 `<get tex4ht.env in dos`>
3583 #endif
3584 >>>
3585
3586 \<get tex4ht.env in dos\><<<
3587 `[
3588 static char *get_env_dir(progname)
3589 Q_CHAR *progname
3590
3591 ;{ int i;
3592 Q_CHAR *p;
3593 if(! progname || ! *progname) return NULL; `% Safety `%
3594 i = (int) strlen((char *) progname);
3595 while( (progname[--i] != (int) dir_path_slash(progname) )
3596 && i > 0) ; `%Search for slash`%
3597 if(i == 0) return NULL; `%Not found? Give up`%
3598 p = (Q_CHAR *) malloc(i+12);
3599 if(p == NULL) return NULL; `%Space for new extention after dot`%
3600 strncpy(p, progname, i+1); `%Copy up to slash`%
3601 (IGNORED) strcpy((char *) &p[i+1],
3602 "tex4ht.env"); `%Append new extention`%
3603 return p;
3604 }
3605 >>>
3606
3607
3608
3609
3610
3611
3612 The 12 above is for accomodating \''tex4ht.env'.
3613
3614 Then, in main(), I changed:
3615
3616 \`''char* tex4ht_env_file = (Q_CHAR *) 0;'
3617
3618 to:
3619
3620 \`'char* tex4ht_env_file = get_env_dir(argv[0]);'
3621
3622 This works like a charm here, and allows me to use tex4ht from a
3623 different directory without typing a single commandline option.
3624
3625
3626
3627
3628 \Section{Open Files}
3629
3630
3631 \<header functions\><<<
3632 static FILE* f_open( ARG_II(const char*,const char*) );
3633 >>>
3634
3635 \<functions\><<<
3636 `[
3637 static FILE* f_open( name, flags )
3638 const char* name `;
3639 const char* flags
3640 ;{ FILE* file;
3641 if( (file = fopen(name,flags) ) != NULL ) {
3642 (IGNORED) printf("(%s)\n",name);
3643 }
3644 return file;
3645 }
3646 >>>
3647
3648
3649
3650
3651
3652 \<header functions\><<<
3653 static FILE* f_home_open( ARG_II(const char*,const char*) );
3654 >>>
3655
3656 \<functions\><<<
3657 `[
3658 static FILE* f_home_open( name, flags )
3659 const char* name `;
3660 const char* flags
3661 ;{ FILE* file;
3662 U_CHAR *str;
3663 if( *name == '~' ){
3664 if( HOME_DIR ){
3665 str = m_alloc(char, strlen((char *) HOME_DIR)+strlen(name));
3666 (IGNORED) sprintf(str,"%s%s", HOME_DIR, name+1);
3667 file = f_open(str,flags);
3668 free((void *) str);
3669 return file;
3670 } else { return NULL; }
3671 } else { return f_open( name, flags ); }
3672 }
3673 >>>
3674
3675
3676
3677
3678
3679
3680 \SubSection{General}
3681
3682 \<header functions\><<<
3683 static FILE* open_file( ARG_II(const C_CHAR *, const C_CHAR *) );
3684 >>>
3685
3686 \<functions\><<<
3687 `[
3688 static FILE* open_file(name,ext)
3689 const C_CHAR *name`; const C_CHAR *ext
3690 ;{ FILE* file;
3691 C_CHAR filename[255], *p;
3692 if( eq_str( ext,LG_EXT ) ) {
3693 (IGNORED) strcpy((char *) filename, (char *) job_name);
3694 (IGNORED) strct(filename, ext);
3695 } else {
3696 (IGNORED) strcpy((char *) filename, name );
3697 p = filename;
3698 while( TRUE ){
3699 if( *p == '.' ){ break; }
3700 if( *p == '\0' ){ (IGNORED) strcpy((char *) p, ext); break; }
3701 p++;
3702 }
3703 }
3704 file = fopen(filename, READ_TEXT_FLAGS);
3705 if( !file ) {
3706 (IGNORED) warn_i_str(5,filename);
3707 } else { (IGNORED) printf ("Entering %s\n", filename); }
3708
3709 return file;
3710 }
3711 >>>
3712
3713
3714 We have here a little inconsistency with tex4ht.c. There the input file
3715 name is appended with the extension .dvi, allowing double extensions.
3716 Here, if an extension is present, we remove it before putting .lg on
3717 top of the name. Should we fix that?
3718
3719
3720
3721
3722 \<defines\><<<
3723 #define LG_EXT ".lg"
3724 >>>
3725
3726
3727
3728
3729
3730 %
3731 % \SubSection{htfcss.env}
3732 %
3733 %
3734 % \<file = open htfcss.env\><<<
3735 % if( htf_cfg ){
3736 % file = open_file(htf_cfg, ".env");
3737 % } else { C_CHAR filename[255];
3738 % file = fopen("htfcss.env", READ_TEXT_FLAGS);
3739 % if ( !file && env_htf_sty ){
3740 % (IGNORED) strcpy((char *) filename, (char *) env_htf_sty);
3741 % (IGNORED) strct(filename, "htfcss.env");
3742 % file = fopen(filename, READ_TEXT_FLAGS);
3743 % }
3744 % if ( !file ){
3745 % (IGNORED) strcpy((char *) filename, (char *) HTFDIR );
3746 % (IGNORED) strct(filename, "htfcss.env");
3747 % file = fopen(filename, READ_TEXT_FLAGS);
3748 % }
3749 % `<htfcss.env in KPATHSEA`>
3750 % if( !file ) { (IGNORED) warn_i_str(5,"htfcss.env"); }
3751 % else { (IGNORED) printf ("Entering htfcss.env\n"); }
3752 % }
3753 % >>>
3754 %
3755 %
3756
3757
3758
3759 \<mark start lg file\><<<
3760 begin_lg_file = ftell(lg_file);
3761 >>>
3762
3763 \<rewind lg file\><<<
3764 (IGNORED) fseek(lg_file, begin_lg_file, `<abs file addr`>);
3765 >>>
3766
3767 \<abs file addr\><<<
3768 0>>>
3769
3770
3771
3772
3773 \<vars\><<<
3774 static FILE* lg_file;
3775 static long begin_lg_file;
3776 >>>
3777
3778
3779
3780
3781
3782 \''open(file, ..._FLAGS)': All
3783 text files should be opened with "r" or "w"; all binary files with "rb"
3784 or "wb". This is the portable way and will work both under Unix and DOS;
3785 as Unix doesn't distinguish between text and binary files, its compilers
3786 will simply ignore the "b" part.
3787
3788 On the subject of the .lg file: you open the tex4ht.env file in binary
3789 mode ("rb"), which results in strange line endings in the .lg file
3790 (CR/CR/LF). Changing the mode to "r" fixes this.
3791
3792
3793 \<t4ht.h\><<<
3794 #if defined(DOS_WIN32) || defined(__MSDOS__)
3795 #define READ_BIN_FLAGS "rb"
3796 #define READ_TEXT_FLAGS "r"
3797 #define WRITE_BIN_FLAGS "wb"
3798 #ifdef WIN32
3799 #define WRITE_TEXT_FLAGS "wb"
3800 #else
3801 #define WRITE_TEXT_FLAGS "w"
3802 #endif
3803 #else
3804 #define READ_BIN_FLAGS "r"
3805 #define READ_TEXT_FLAGS "r"
3806 #define WRITE_BIN_FLAGS "w"
3807 #define WRITE_TEXT_FLAGS "w"
3808 #endif
3809 >>>
3810
3811
3812
3813 \Verbatim
3814 I've been held up a bit by a
3815 bug in tex4ht.c that caused emTeX to complain that the created .idv file
3816 was corrupt:
3817
3818 *** Fatal error 2106: corrupt DVI file (postamble not found)
3819
3820 I found the cause, though: you open it with mode "w", which is text
3821 mode. Changing this to "wb" solved the problem.
3822 \EndVerbatim
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832 \Section{Utilities}
3833
3834
3835 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3836 \SubSection{Error and Warning Messages}
3837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3838
3839 \<signals messages: 2--4\><<<
3840 "Illegal storage address\n", `%2 segmentation`%
3841 "Floating-point\n", `%3 `%
3842 "Interrupt with Cntr-C\n", `%4 `%
3843 >>>
3844
3845 \<warn and err messages\><<<
3846 `<command line options`>, `%0`%
3847 "Insufficient memory\n", `%1`%
3848 `<signals messages: 2--4`>
3849 "Can't find/open file ``%s'\n", `%5`%
3850 >>>
3851
3852
3853
3854 \<defines\><<<
3855 #define bad_arg err_arg(0)
3856 #define bad_mem err_i(1)
3857 >>>
3858
3859
3860
3861
3862
3863
3864 \<header functions\><<<
3865 static void err_i( ARG_I(int) );
3866 >>>
3867
3868 \<functions\><<<
3869 `[
3870 static void err_i(n) int n
3871
3872 ;{ (IGNORED) fprintf(stderr,"--- error --- ");
3873 (IGNORED) fprintf(stderr, "%s", warn_err_mssg[n]);
3874 exit(EXIT_FAILURE);
3875 }
3876 >>>
3877
3878
3879
3880 \<header functions\><<<
3881 static void err_arg( ARG_I(int) );
3882 >>>
3883
3884 \<functions\><<<
3885 `[
3886 static void err_arg(n) int n
3887
3888 ;{ (IGNORED) fprintf(stderr,"--- error --- ");
3889 (IGNORED) fprintf(stderr, "%s", warn_err_mssg[n]);
3890 exit(EXIT_FAILURE);
3891 }
3892 >>>
3893
3894
3895
3896
3897
3898 \<header functions\><<<
3899 static void warn_i_str( ARG_II(int,const Q_CHAR *) );
3900 >>>
3901
3902 \<functions\><<<
3903 `[
3904 static void warn_i_str(n,str)
3905 int n`;
3906 const Q_CHAR *str
3907
3908 ;{ (IGNORED) fprintf(stderr,"--- warning --- ");
3909 (IGNORED) fprintf(stderr,warn_err_mssg[n], str);
3910 }
3911 >>>
3912
3913
3914 %
3915 % \<vars\><<<
3916 % static C_CHAR warning[] = "--- warning --- ";
3917 % >>>
3918
3919
3920
3921
3922
3923 \<vars\><<<
3924 static const C_CHAR *warn_err_mssg[]={ `<warn and err messages`> "" };
3925 >>>
3926
3927 \<resplit argv for windows\><<<
3928 #ifdef WIN32
3929 /* See comments in tex4ht */
3930 if (argc > 2) {
3931 int i, nargc;
3932 char **nargv, **pnargv, **pargv;
3933
3934 nargv = (char **) xmalloc (2 * argc * sizeof (char *));
3935 pnargv = nargv;
3936 pargv = argv;
3937 *pnargv++ = xstrdup (*pargv++);
3938 *pnargv++ = xstrdup (*pargv++);
3939 nargc = 2;
3940
3941 for (i=2; i < argc; i++) {
3942 char *p, *q, *r;
3943 p = q = *pargv++;
3944 while (*p == ' ' || *p == '\t') {
3945 p++;
3946 q++;
3947 }
3948 while (*p != ' ' && *p != '\t' && *p) {
3949 p++;
3950 if (*p == '\0') {
3951 *pnargv++ = xstrdup(q);
3952 nargc++;
3953 } else if (*p == ' ' || *p == '\t') {
3954 r = p;
3955 while (*p == ' ' || *p == '\t')
3956 p++;
3957 if (*p == '-' || *p == '\0') {
3958 *r = '\0';
3959 *pnargv++ = xstrdup(q);
3960 nargc++;
3961 q = p;
3962 }
3963 }
3964 }
3965 }
3966
3967 nargv[nargc] = NULL;
3968 argv = nargv;
3969 argc = nargc;
3970 }
3971 #endif
3972 >>>
3973
3974
3975
3976 \SubSection{Signals}
3977
3978 \<h-include\><<<
3979 #include <signal.h>
3980 >>>
3981
3982 \<header functions\><<<
3983 static void
3984 `<CDECL`>
3985 sig_err(ARG_I(int));
3986 >>>
3987
3988
3989
3990
3991 \<functions\><<<
3992 `[
3993 static void
3994 `<CDECL`>
3995 sig_err(s) int s
3996 ;{
3997 (void) signal(s,SIG_IGN); `%ignore the signal`%
3998 switch( s ){
3999 #ifdef SIGSEGV
4000 case SIGSEGV: err_i(2);
4001 #endif
4002 case SIGFPE : err_i(3);
4003 #if defined(SIGINT) && !defined(WIN32)
4004 case SIGINT : err_i(4);
4005 #endif
4006 }
4007 `<DJGPP signals`>
4008 }
4009 >>>
4010
4011
4012
4013
4014 Forgetting \`'_pascal' and \`'_cdecl' modifiers: Each C function may
4015 be either \`'_pascal' or \`'_cdecl'. This modifier defines how
4016 parameters are passed to it. Default for Smalltalk definition is
4017 \`'_cdecl'. Default for C functions depends on compiler settings, and
4018 you can use other types uncompatible with Smalltalk. In Windows API
4019 16-bit functions are \`'_pascal' and 32-bit \`'_cdecl'.
4020
4021
4022
4023 \<CDECL\><<<
4024 #ifdef CDECL
4025 CDECL
4026 #endif
4027 >>>
4028
4029
4030
4031
4032 \<set signals\><<<
4033
4034 #ifdef SIGSEGV
4035 (void) signal(SIGSEGV,sig_err);
4036 #endif
4037 (void) signal(SIGFPE,sig_err);
4038 #ifdef KWIN32
4039 `<KWIN32 signals`>
4040 #else
4041 #ifdef SIGINT
4042 (void) signal(SIGINT,sig_err); `%Control-c, user interrupt`%
4043 #endif
4044 #endif
4045 >>>
4046
4047
4048
4049 SIGFPE is handled by the C library, SIGSEGV too but not generated by
4050 the system, so it does nothing but is harmless
4051
4052 SetConsoleCtrlHandler is need to catch Ctrl+C and Ctrl+Break under
4053 Windows, SIGINT is not generated by the system.
4054
4055 \<KWIN32 signals\><<<
4056 SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
4057 >>>
4058
4059
4060
4061 SIGSEGV, SIGILL, SIGTERM not implemented in MS-DOS. They are supplied just for
4062 compatibility. Looks like that SIGINT is defined for windows but not for dos.
4063 \ifHtml[\HPage{more}\Verbatim
4064 Eitan> I also wonder whether the WIN32 really needs to discard the
4065 Eitan> following code fragment.
4066
4067 signal() is supported through the standard libc, but is mostly
4068 ineffective. An example of the kind of code needed is attached.
4069
4070
4071 /* Interrupt handler. mt_exit() is a cleanup_and_exit function */
4072 #ifdef _WIN32
4073 BOOL sigint_handler(DWORD dwCtrlType)
4074 {
4075 mt_exit(3);
4076 return FALSE; /* return value obligatory */
4077 }
4078 #else
4079 void sigint_handler (int sig)
4080 {
4081 mt_exit(3);
4082 }
4083 #endif
4084
4085 /* Catch signals, so we clean up if the child is interrupted.
4086 This emulates "trap 'whatever' 1 2 15". */
4087 #ifdef _WIN32
4088 SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
4089 #else
4090 # ifdef SIGINT
4091 signal (SIGINT, sigint_handler);
4092 # endif
4093 # ifdef SIGHUP
4094 signal (SIGHUP, sigint_handler);
4095 # endif
4096 # ifdef SIGTERM
4097 signal (SIGTERM, sigint_handler);
4098 # endif
4099 #endif
4100 \EndVerbatim\EndHPage{}]\fi
4101
4102 Msvc recommends not using printf, but we ignoring this recommendation
4103 here with the assumption that the recommendation relates to I/O
4104 interrupts that are not considered here.
4105
4106
4107
4108
4109 \<header functions\><<<
4110 #ifdef KWIN32
4111 static BOOL sigint_handler(ARG_I(DWORD));
4112 #endif
4113 >>>
4114
4115 \<functions\><<<
4116 #ifdef KWIN32
4117 `[
4118 static BOOL sigint_handler(dwCtrlType) DWORD dwCtrlType
4119 ;{
4120 err_i(32);
4121 return FALSE; `% return value obligatory `%
4122 }
4123 #endif
4124 >>>
4125
4126
4127 \SubSection{System Calls}
4128
4129
4130
4131 \<vars\><<<
4132 static Q_CHAR command[255];
4133 static int system_return;
4134 >>>
4135
4136
4137 The library \`'<stdlib.h>' includes a function
4138 \`'int system(const char *cmdstring);'. When cmdstring is NULL,
4139 the return value is 0 iff the platform does not support system calls.
4140
4141
4142 \<vars\><<<
4143 static BOOL system_yes;
4144 >>>
4145
4146 \<main's init\><<<
4147 { C_CHAR *yes = NULL;
4148 system_yes = (`<system exist?`>);
4149 }
4150 >>>
4151
4152
4153 Solaris-? issues the command \`'-c: bad option(s)' if we check for the
4154 presence of the system function.
4155
4156
4157
4158 \<system exist?\><<<
4159 #ifdef SYSTEM_FUNCTION_OK
4160 0
4161 #else
4162 system( yes ) != 0
4163 #endif
4164 >>>
4165
4166 \<execute system command\><<<
4167 (IGNORED) call_sys(command);
4168 >>>
4169
4170
4171
4172
4173 \<header functions\><<<
4174 static void call_sys(ARG_I(Q_CHAR *));
4175 >>>
4176
4177
4178
4179
4180 \<functions\><<<
4181 `[
4182 static void call_sys(command) Q_CHAR * command
4183 ;{
4184 if( *command ){
4185 (IGNORED) printf("System call: %s\n", command);
4186 system_return = system_yes? (int) system(command) : -1;
4187 (IGNORED) printf("%sSystem return: %d\n",
4188 system_return? "--- Warning --- " : "", system_return );
4189 if( always_call_sys ){ system_return = 0; }
4190 }
4191 }
4192 >>>
4193
4194
4195 \<vars\><<<
4196 static BOOL always_call_sys = FALSE;
4197 >>>
4198
4199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4200 \SubSection{Strings Concat and compare}
4201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4202
4203
4204
4205 \<defines\><<<
4206 #define eq_str(x,y) (!strcmp(x,y))
4207 >>>
4208
4209
4210
4211 strcat should be in string.h, but c++ doesn't find it there.
4212 We use it just for concatenating an extension of
4213 file name. Should have the interface
4214 \`'char *strcat( ARG_II(C_CHAR *, const Q_CHAR *) );'.
4215
4216 \<header functions\><<<
4217 static void strct( ARG_II(C_CHAR *, const C_CHAR *) );
4218 >>>
4219
4220 \<functions\><<<
4221 `[
4222 static void strct( str1, str2 )
4223 C_CHAR * str1`;
4224 const C_CHAR * str2
4225
4226 ;{ Q_CHAR * ch;
4227 ch = str1 + (int) strlen((char *) str1);
4228 (IGNORED) strcpy((char *) ch, str2 );
4229 }
4230 >>>
4231
4232
4233
4234 \SubSection{String into Int}
4235
4236 \<header functions\><<<
4237 static long int get_long_int( ARG_I(Q_CHAR *) );
4238 >>>
4239
4240 \<functions\><<<
4241 `[
4242 static long int get_long_int(str)
4243 Q_CHAR *str
4244 ;{ long int i;
4245 Q_CHAR *ch;
4246 ch = str; i = 0;
4247 while( (*ch>= '0') && (*ch <='9') ){
4248 i = 10*i + *(ch++) - '0';
4249 }
4250 return i;
4251 }
4252 >>>
4253
4254
4255
4256 \SubSection{Dynamic Memory Alloc}
4257
4258
4259 \<defines\><<<
4260 #define m_alloc(typ,n) (typ *) malloc_chk((int) ((n) * sizeof(typ)))
4261 >>>
4262
4263
4264
4265 \<header functions\><<<
4266 static void* malloc_chk(ARG_I(int));
4267 >>>
4268
4269 \<functions\><<<
4270 `[
4271 static void* malloc_chk( n ) int n
4272 ;{ void* p;
4273 if((p = (void *) malloc( (size_t) n)) == NULL ) bad_mem;
4274 return p;
4275 }
4276 >>>
4277
4278
4279
4280
4281
4282 \<header functions\><<<
4283 static void* r_alloc(ARG_II(void *, size_t));
4284 >>>
4285
4286 \<functions\><<<
4287 `[
4288 static void* r_alloc( q, n )
4289 void *q`;
4290 size_t n
4291 ;{ void* p;
4292 if((p = (void *) realloc( q, (size_t) n)) == NULL) bad_mem;
4293 return p;
4294 }
4295 >>>
4296
4297
4298
4299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4300 \SubSection{myfseek}
4301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4302
4303
4304 The ftell() and fseek() are not consistent in ms-windows. The ftell()
4305 accounts for \Verb=<cr>= and \Verb=<lf>= in the byte stream, where
4306 fseek() ignore the <cr> bytes. A \Verb=READ_BIN_FLAGS= instead of
4307 \Verb=READ_TEXT_FLAGS= seems to solve the problem.
4308
4309 \<CopyTo read flags\><<<
4310 READ_BIN_FLAGS
4311 >>>
4312
4313 A possible alternative is to define a private fseek.
4314
4315
4316
4317 %
4318 %
4319 % (IGNORED) myfseek(in_file, (long) end_loc, `<abs file addr`>);
4320 %
4321 %
4322 % \<header functions\><<<
4323 % static BOOL scan_str( ARG_III(C_CHAR *, BOOL, FILE *) );
4324 % >>>
4325 %
4326 % \<functions\><<<
4327 % `[
4328 % static BOOL scan_str(str,flag,file)
4329 % Q_CHAR *str`;
4330 % BOOL flag`;
4331 % FILE* file
4332 % ;{ Q_CHAR *p;
4333 %
4334 % >>>
4335 %
4336
4337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4338 \SubSection{Pattern Recognition Functions}
4339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4340
4341
4342 When failure (false \''status') arises, the input line is consumed to
4343 its end.
4344 The \''_until' functions place in ''match[i]' the string found.
4345
4346 \<header functions\><<<
4347 static BOOL scan_until_end_str( ARG_IV(const C_CHAR *, int, BOOL, FILE *) );
4348 >>>
4349
4350 \<functions\><<<
4351 `[
4352 static BOOL scan_until_end_str(str,n,flag,file)
4353 const C_CHAR *str`;
4354 int n`;
4355 BOOL flag`;
4356 FILE* file
4357 ;{ Q_CHAR *p;
4358 int i;
4359 if( !flag ) { return flag; }
4360 p = match[n]; i = 0;
4361 while( TRUE ){
4362 if( (i+1) >= max_match[n] ){
4363 max_match[n] += 10;
4364 p = match[n] = (Q_CHAR *)
4365 r_alloc((void *) match[n], (size_t) max_match[n]);
4366 }
4367 p[i] = (char) (eoln_ch = getc(file));
4368 if( (eoln_ch == (int) '\n') || (eoln_ch == EOF) ){ break; }
4369 i++;
4370 }
4371 p[i] = '\0';
4372 i -= (int) strlen(str);
4373 if( i>= 0 ){ return eq_str(p+i,str); }
4374 return FALSE;
4375 }
4376 >>>
4377
4378
4379
4380 \<vars\><<<
4381 static Q_CHAR* match[10];
4382 static int max_match[10];
4383 >>>
4384
4385
4386 \<main's init\><<<
4387 { int i;
4388 for( i=0; i<=9; i++){
4389 match[i] = (Q_CHAR *) malloc(70);
4390 max_match[i] = 70;
4391 }
4392 }
4393 >>>
4394
4395
4396 \<header functions\><<<
4397 static BOOL scan_until_str( ARG_IV(const C_CHAR *, int, BOOL, FILE *) );
4398 >>>
4399
4400 \<functions\><<<
4401 `[
4402 static BOOL scan_until_str(str,n,flag,file)
4403 const C_CHAR *str`;
4404 int n`;
4405 BOOL flag`;
4406 FILE* file
4407 ;{ Q_CHAR *p, ch;
4408 int i, j;
4409 if( !flag ) { return flag; }
4410 p = match[n]; i = 0;
4411 while( TRUE ){
4412 ch = (char) (eoln_ch = getc(file));
4413 if( (eoln_ch == (int) '\n') || (eoln_ch == EOF) ){ return FALSE; }
4414 if( (i+1) >= max_match[n] ){
4415 max_match[n] += 10;
4416 p = match[n] = (Q_CHAR *)
4417 r_alloc((void *) match[n], (size_t) max_match[n]);
4418 }
4419 p[i++] = ch;
4420 j = i - (int) strlen(str);
4421 if( j>= 0 ){
4422 p[i] = '\0';
4423 if( eq_str(p+j,str) ) { return TRUE; }
4424 }
4425 }
4426 }
4427 >>>
4428
4429
4430
4431
4432
4433
4434 \<header functions\><<<
4435 static BOOL scan_str( ARG_III(const C_CHAR *, BOOL, FILE *) );
4436 >>>
4437
4438 \<functions\><<<
4439 `[
4440 static BOOL scan_str(str,flag,file)
4441 const C_CHAR *str`;
4442 BOOL flag`;
4443 FILE* file
4444 ;{ const Q_CHAR *p;
4445 int temp_eoln_ch;
4446 if( !flag ) { return flag; }
4447 p = str;
4448 while( *p != '\0' ){
4449 if( *(p++) != (temp_eoln_ch = getc(file)) ) {
4450 while( (temp_eoln_ch != (int) '\n')
4451 && (temp_eoln_ch != EOF) ){ temp_eoln_ch = getc(file); }
4452 eoln_ch = temp_eoln_ch; return FALSE;
4453 }
4454 }
4455 return TRUE;
4456 }
4457 >>>
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490 \SubSection{Shorthands and Mnemonics}
4491
4492
4493
4494 \<defines\><<<
4495 #ifndef TRUE
4496 #define TRUE 1
4497 #endif
4498 #ifndef FALSE
4499 #define FALSE 0
4500 #endif
4501 #ifndef BOOL
4502 #define BOOL int
4503 #endif
4504 >>>
4505
4506
4507
4508 \<defines\><<<
4509 #define eq_str(x,y) (!strcmp(x,y))
4510 >>>
4511
4512
4513
4514 %----------------------------------------------------
4515
4516 \OutputCodE\<t4ht.c\>
4517
4518 \bye
4519
4520
4521