w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

dvispc.c
Go to the documentation of this file.
1 /*
2  * <<< dvispc >>>
3  *
4  * A program to modify DVI file to be page-independent
5  * Support the following specials
6  * color specials: push, pop, background
7  * pdf specials: pdf:bcolor, pdf:ecolor, pdf:bgcolor
8  * tpic specials: pn
9  *
10  * Originally written by SHIMA
11  * January 2003
12  */
13 
14 #ifdef __GNUC__
15 /* Validate in case of UNIX */
16 #define UNIX 1
17 #else
18 /* Validate if SHIFT JIS is used for a filename */
19 /* Win32 MSVC is assumed */
20 #define SHIFT_JIS 1
21 #endif
22 
23 /* %%% Contents of an extended DVI file %%%
24  * PRE(247)
25  * ... % PREAMBRE %
26  * ...
27  *
28  * BOP(139)
29  * c[10][4]
30  * p[4] -1
31  * ... % Contents of the first pages
32  * EOP(140)
33  *
34  * BOP(139)
35  * ... % Contents of pages
36  * ...
37  *
38  * BOP(139) % top of the last page
39  * c[10][4]
40  * p[4] address of BOP at the top of the former page
41  * ... % Contents of the last page
42  * EOP(140) % end of the last page
43  */
44 
45  /* % Added part %
46  * POST(248)
47  * Data[num_add][?] series of data
48  * FileNames[num_add][?] series of strings NULL terminated
49  * pt_Data[num_add][BOD[4], LOD[4]] pointer and length of data
50  *
51  * % 20 byte
52  * BOF[4] top of series of strings
53  * EOF[4] end of series of strings
54  * num_add[4] number of data
55  * top_add[4] address of POST at the top of added part
56  * AdID[3] 'A', 'd', 'I'
57  * EOP(140) % End of Added part %
58  */
59 
60  /*
61  * POST(248) % Top of POSTAMBRE %
62  * p[4] address of BOP at the top of the last page
63  * ....
64  * POST_POST(249)
65  * top_post[4] address of POST at the top of POSTAMBRE
66  * 2 (or 3), 223,...,223 4 - 7 times 223
67  */
68 
69 /*
70  * The extended DVI file should be the following
71  *
72  * 1. The 8 byte preceeding to the top of the POSTAMBRE:
73  * top_add[4], 'A', 'd', 'O', 140(=EOP)
74  *
75  * 2. DVI[top_add[4]] 140(=EOP)
76  * DVI[top_add[4]-1] 248(=POS)
77  */
78 
79 #include <stdio.h>
80 #include <stdlib.h>
81 #include <string.h>
82 #include <ctype.h>
83 
84 #ifdef UNIX /* for mkstemp(), umask() etc. */
85 #include <unistd.h> /* for mkstemp(), umask() etc. */
86 #include <sys/types.h>
87 #include <sys/stat.h>
88 #else
89 #include <io.h>
90 #include <fcntl.h>
91 #endif
92 
93 #include <config.h>
94 #ifdef PTEXENC
95 #include <ptexenc/ptexenc.h>
96 #include <ptexenc/unicode.h>
97 #endif
98 
99 #include "common.h"
100 
101 #define uchar unsigned char
102 #define uint unsigned int
103 #define Long int
104 
105 #ifdef UNIX
106 #define PATH_SEP '/'
107 #define READ_TEXT "r"
108 #define READ_BINARY "r"
109 #define WRITE_BINARY "w"
110 #define WRITE_TEXT "w"
111 #define StrCmp strcmp
112 #else
113 #define PATH_SEP '\\'
114 #define PATH_SEPU '/'
115 #define READ_TEXT "rt"
116 #define READ_BINARY "rb"
117 #define WRITE_BINARY "wb"
118 #define WRITE_TEXT "wt"
119 #define StrCmp stricmp
120 #endif
121 
122 #define PIXEL int
123 #define SIZE_PARA int
124 #define PAGE_INDEX int
125 #define SCALED_PT int
126 
127 #define DIMENSION struct DIMENSION_REC
128 /* Information about device-output
129  */
130 
131 struct DIMENSION_REC {
133  /* These are the maxmum size directed in DVI-file.
134  */
135  int mag;
136  /* is the magnification for output. This is the same value as 'mag' in
137  * DVI-file ( so equal the one in DVI_INFO ), when no '-mag' & '-half'
138  * options directed.
139  */
141  /* is size-parameter for conversion pixel<-->scaled pt.
142  * ( equal "num * den / mag" )
143  */
145  /* the index of file-offset of pages in dvifile
146  */
147  int total_page;
148  /* same as 'total_page' in DVI_INFO.
149  */
150 #if 0
151  int start_page, end_page;
152  /* the starting and the ending page to print.
153  */
154 #endif
155  int max_nombre_page;
156  /* the maximal nombre page
157  */
159 
160 
161 #define MAX_INCL 2048 /* maximal number of embedded files */
162 #ifndef MAX_PATH
163 #define MAX_PATH 0x200 /* maximal length of path name */
164 #endif
165 
166 #define ID 2
167 #define IDP 3
168 #define END_DVI 223
169 
170 #define SET_CHAR_0 0
171 #define SET1 128
172 #define SET_RULE 132
173 #define PUT1 133
174 #define PUT_RULE 137
175 #define NOP 138
176 #define BOP 139
177 #define EOP 140
178 #define PUSH 141
179 #define POP 142
180 #define RIGHT1 143
181 #define W0 147
182 #define W1 148
183 #define X0 152
184 #define X1 153
185 #define DOWN1 157
186 #define Y0 161
187 #define Y1 162
188 #define Z0 166
189 #define Z1 167
190 #define FNT_NUM_0 171
191 #define FNT1 235
192 #define XXX1 239
193 #define FNT_DEF_1 243
194 #define PRE 247
195 #define POST 248
196 #define POST_POST 249
197 #define OPCODE 250
198 #define EOFNC 255 /* end of func */
199 
200 #define DVIFILE_INFO struct DVIFILE_INFO_REC
201 
202 #define MAX_LEN 128
203 #define MAX_COLOR 512
204 #define COLOR_BUF_SIZE MAX_COLOR*32
205 #define MAX_ANNOT 8
206 #define ANNOT_BUF_SIZE MAX_ANNOT*512
207 #define COMMON_SIZE 0x4000
208 #define MAX_FONT 256
209 
210 #define DTL_STRING 1 /* 0 \' \\ */
211 #define DTL_CHAR 2 /* 1 (...) */
212 #define DTL_CHAR2 4 /* 2 character code by dig/hex */
213 #define DTL_CMD 8 /* 3 compact command name */
214 #define DTL_FNTDEF 0x10 /* 4 checksum is in octal */
215 #define DTL_FNTNAME 0x20 /* 5 dir/name */
216 #define DTL_ILL 0x40 /* 6 opcode/illegal */
217 #define DTL_PAGE 0x80 /* 7 */
218 #define DTL_OCT 0x100 /* 8 */
219 #define DTL_EXACT 0x200 /* 9 -> DVI according to string */
220 #define DTL_FNTDFN 0x400 /* 1 check used font definition */
221 #define DTL_VARIETY 0x800 /* 2 ignore variety */
222 #define DTL_FORM 0x8000 /* the first line: variety */
223 int f_dtl = 0;
224 
225 enum {
227 };
228 
229 int f_mode = EXE2MODIFY; /* 0: -c modify
230  1: -d report only
231  2: -s specials
232  3: -a to_Text
233  4: -x to_DVI */
234 
235 int f_debug = 0; /* -v */
236 int f_overwrite = 0;
237 int f_backup = 0; /* -b */
238 
239 #ifdef PTEXENC
240 int f_jstr = 0; /* -J */
241 #else
242 #ifdef UNIX
243 int f_sjis = 0; /* -j */
244 #else
245 int f_sjis = 1;
246 #endif
247 #endif
248 int f_pos = 0; /* position */
249 int f_book = 0; /* multiple of four pages */
250 
251 int f_ptex = 0;
252 int f_prescan = 0;
253 int f_last = 0;
255 char *out_pages ="T-L";
257 
258 /* non-stack specials */
261 int f_background = 0; /* in each page, 0: not found; 1: found */
264 int f_pdf_bgcolor = 0; /* in each page, 0: not found; 1: found */
267 int f_pn = 0; /* in each page, 0: not found and not actually used;
268  1: found before actual use
269  -1: not found before actual use */
270 
271 /* stack specials */
284 
285 int f_needs_corr; /* flag to determine if correction is needed */
286 char color_buf[COLOR_BUF_SIZE]; /* common buffer for color/pdf_color */
288 
292 
293 #define DVIFILE_INFO struct DVIFILE_INFO_REC
294  /* Information about Preamble of DVI-file. ( to say the truth, this is
295  * the same thing as Preamble itself. So, you'd better see
296  * "TeX : The Program." )
297  */
298 struct DVIFILE_INFO_REC {
299  FILE *file_ptr;
300  char *file_name;
304  int stack_depth;
305  int total_page;
307 
311 
312 const int AdID = (('A'<<24)+('d'<<16)+('O'<<8)+EOP);
313 
314 #ifndef PTEXENC
315 // #define issjis1(c) ((c)>=0x81&&(c)<=0xfc&&((c)<=0x9f||(c)>=0xe0))
316 // #define issjis2(c) ((c)>=0x40 && (c)<=0xfc && (c)!=0x7f)
317 #define isjis(c) (((c)>=0x21 && (c)<=0x7e))
318 #endif
319 #define is_hex(c) ((c>='0'&&c<='9')||(c>='a'&&c<='f')||(c>='A'&&c<='F'))
320 #define is_oct(c) (c>='0'&&c<='7')
321 // #define is_dig(c) (c>='0'&&c<='9')
322 #define hex_to_dig(c) ((c>='0'&&c<='9')?(c-'0'):(toupper(c)-('A'-10)))
323 #define MSG(x) (f_debug?(x):"")
324 #define read_byte(x) getc(x)
325 #define write_byte(x,y) putc(x,y)
326 #define read_short(x) signed_read_n(x,2)
327 
328 uint work(FILE *);
329 uint s_work(FILE *);
330 int strsubcmp(char *s, char *t);
331 int strsubcmp_n(char *s, char *t);
332 void sp_color(char *sp);
333 void sp_pdf_bcolor(char *sp);
334 void sp_pdf_ecolor(char *sp);
335 void sp_pdf_bann(char *sp);
336 void sp_pdf_eann(char *sp);
337 void read_post(DVIFILE_INFO *dvi);
338 uint interpret(FILE *);
341 void transpre(FILE *);
342 void transpost(FILE *);
343 void trans2dvi(void);
344 void replace(char *, char *);
345 
346 Long read_n(FILE * fp, int n)
347 {
348  long d;
349 
350  if(n--)
351  d = (unsigned char)getc(fp);
352  else
353  return 0;
354  while (n-- > 0)
355  d = (d<<8) + (unsigned char)getc(fp);
356  return d;
357 }
358 
359 
361 {
362  long d;
363 
364  if(n--)
365  d = (signed char)getc(fp);
366  else
367  return 0;
368  while (n-- > 0)
369  d = (d<<8) + (unsigned char)getc(fp);
370  return d;
371 }
372 
373 
374 void Exit(int code)
375 {
376  if(fp_out != stdout && fp_out != stderr && *outfile){
377  if(fp_out){
378  fclose(fp_out);
379  unlink(outfile);
380  }
381  }
382  exit(code);
383 }
384 
385 
386 void error(char *msg)
387 {
388  fprintf(stderr, "%s\n", msg);
389  Exit(1);
390 }
391 
392 
393 void write_long(int x, FILE *fp)
394 {
395  write_byte(x >> 24, fp);
396  write_byte((x >> 16) & 0xff, fp);
397  write_byte((x >> 8) & 0xff, fp);
398  write_byte(x & 0xff, fp);
399 }
400 
401 
403 {
404  int i;
405 
406  i = read_byte(fp) << 24;
407  i += read_byte(fp) << 16;
408  i += read_byte(fp) << 8;
409  return i + read_byte(fp);
410 }
411 
412 
413 void write_word(int x, FILE *fp)
414 {
415  write_byte((x >> 8) & 0xff, fp);
416  write_byte(x & 0xff, fp);
417 }
418 
419 
421 {
422  int i;
423 
424  i = read_byte(fp) << 8;
425  return i + read_byte(fp);
426 }
427 
428 
429 void usage(int ex)
430 {
431  fprintf(stderr,
432  "\t Modify a DVI file to be page-independent in specials\n"
433  "\t Translation between DVI file <-> Text file\n"
434  "\t Originally written by SHIMA, Jan. 2003\n"
435  "\t Ver.%s (%s)\n\n", VERSION, TL_VERSION);
436  fprintf(stderr,
437  "Usage: dvispc [-c] [-bvz] input_dvi_file [output_dvi_file]\n"
438  " dvispc -d input_dvi_file\n"
439  " dvispc -s [-p..] input_dvi_file [output_text_file]\n"
440 #ifdef PTEXENC
441  " dvispc -a [-ltv][-J..][-p..][-r..] input_dvi_file [output_text_file]\n"
442 #else
443  " dvispc -a [-jltv][-p..][-r..] input_dvi_file [output_text_file]\n"
444 #endif
445  " dvispc -x[..] [-ltv][-r..] [input_text_file] output_dvi_file\n\n"
446  "Mode options:\n"
447  " -c: correct input DVI to be page-indepent in specials (default)\n"
448  " -d: dry run to check page-independence\n"
449  " -s: show specials\n"
450  " -a: translate DVI to Text\n"
451  " -x: translate Text to DVI (-x0:str0 1:chkfnt 2:variety)\n\n"
452  "Other options:\n"
453 #ifdef PTEXENC
454  " -v: verbose -l: location\n"
455 #else
456  " -v: verbose -j: Japanese characters -l: location\n"
457 #endif
458  " -b: backup original even if output_dvi_file is not given\n"
459  " -z: append empty pages if necessary to have multiple of 4 pages for book\n"
460  " -p: T:preamble L:postamble pages with - (eg: -pT-L -pT2/4-8L -p-4 etc.)\n"
461  " -r: replace (-rorg_1=new_1/org_2=new_2... eg. -rxxx=special/fnt=font)\n"
462  " -t: compatible to DTL (the followings are suboptions if necessary eg. -t02)\n"
463  " 0:str 1:ch 2:ch2 3:cmd 4:c-sum 5:dir/name 6:err 7:page 8:oct 9:str0\n"
464 #ifdef PTEXENC
465  " -J: set Japanese characters output with a suboption:\n"
466  " e:EUC-JP s:Shift_JIS u:UTF-8 for pTeX or U:UTF-8 for upTeX.\n"
467 #endif
468  " output_dvi_file : overwrite if it is not specified.\n"
469  " output_text_file : stdout if it is not specified.\n"
470  " input_text_file : stdin if it is not specified.\n\n"
471  "Supported specials:\n"
472  " color specials: push, pop, background\n"
473  " pdf specials: pdf:bcolor, pdf:ecolor, pdf:bgcolor\n"
474  " tpic specials: pn\n"
475  );
476  fprintf(stderr, "\nEmail bug reports to %s.\n", BUG_ADDRESS);
477  exit(ex);
478 }
479 
480 
481 int main(int argc, char **argv)
482 {
483  int i, len, ch, fnum;
484  char *o_name, *n_name, *s;
485 
486  if(argc <= 1)
487  usage(0);
488 
489  for(i = 1; i < argc && argv[i][0] == '-'; i++){
490  for(len = 1; argv[i][len]; len++){
491  switch(argv[i][len]){
492  case 'c':
493  f_mode = EXE2MODIFY;
494  break;
495 
496  case 's':
498  break;
499 
500  case 'a':
501  f_mode = EXE2TEXT;
502  break;
503 
504  case 'd':
505  f_mode = EXE2CHECK;
506  case 'v':
507  f_debug = 1;
508  break;
509 
510  case 'x':
511  f_mode = EXE2DVI;
512  if(isdigit(argv[i][len+1])){
513  while(isdigit(ch = argv[i][++len]))
514  f_dtl ^= (1 << (ch - ('0'-9)));
515  len--;
516  }
517  break;
518 
519  case 'b':
520  f_backup = 1;
521  break;
522 
523 #ifdef PTEXENC
524  case 'J':
525  f_jstr = 1;
526  switch(argv[i][len+1]){
527  case 'e':
528  set_enc_string ("euc", "default"); break;
529  case 's':
530  set_enc_string ("sjis", "default"); break;
531  case 'u':
532  set_enc_string ("utf8", "default"); break;
533  case 'U':
534  enable_UPTEX(true);
535  set_enc_string ("utf8", "uptex"); break;
536  default:
537  fprintf(stderr, "Unknown option:%s\n", argv[i]);
538  exit(1);
539  }
540  len++;
541  break;
542 #else
543  case 'j':
544  f_sjis = 1 - f_sjis;
545  break;
546 #endif
547 
548  case 'p':
549  s = out_pages = argv[i]+len+1;
550  if(!*out_pages)
551  out_pages = "T-L";
552  else{
553  while(*s){
554  if((*s >= '0' && *s <= '9')
555  || *s == 'T' || *s == 'L' || *s == '-'){
556  s++;
557  continue;
558  }
559 error: fprintf(stderr, "Error in parameter %s\n", argv[i]);
560  exit(1);
561  }
562  }
563  goto skip;
564 
565  case 'r':
566  if(strlen(argv[i]+len+1) > COMMON_SIZE-2){
567  fprintf(stderr, "Too long argument %s\n", argv[i]);
568  exit(1);
569  }
570  strcpy(tmp_buf, argv[i]+len+1);
571  for(o_name = n_name = tmp_buf; *o_name; ){
572  while(*++n_name != 0 && *n_name != '=');
573  if(!*n_name){
574  fprintf(stderr, "Wrong argument %s\n", argv[i]);
575  exit(1);
576  }
577  *n_name++ = 0;
578  for(s = n_name; *++s && *s != '/';);
579  if(!*s)
580  s[1] = 0;
581  *s = 0;
582  if(*o_name < 'a' || *o_name > 'z' || !*n_name)
583  goto error;
584  replace(o_name, n_name);
585  o_name = n_name = s+1;
586  }
587  goto skip;
588 
589  case 't':
590  if(isdigit(argv[i][len+1])){
591  while(isdigit(ch = argv[i][++len]))
592  f_dtl ^= (1 << (ch - '0'));
593  len--;
594  }else{
595 #ifndef PTEXENC
596  f_sjis = 1-f_sjis;
597 #endif
598  f_dtl = 0x00ffffff;
599  }
600  break;
601 
602  case 'l':
603  f_pos = 1;
604  break;
605 
606  case 'z':
607  f_book = 1;
608  break;
609 
610  default:
611  fprintf(stderr, "Unknown option:%s\n", argv[i]);
612  exit(1);
613  }
614  }
615 skip: ;
616  }
617  /* now, i = (number of optional arguments) + 1
618  cf. argc = (number of all arguments) + 1
619  {argv[0] is the program name itself} ^^^ */
620 
621  fnum = 0;
622  if(!isatty(fileno(stdin))){ /* if stdin is redirected from a file */
623  fp_in = stdin;
624  fnum++;
625  }
626  if(!isatty(fileno(stdout))){ /* if stdout is redirected to a file */
627  fp_out = stdout;
628  fnum++;
629  }
630  if(fnum != 2){
631  len = strlen(argv[argc-1]);
632  if(len >= MAX_PATH-5 || strlen(argv[i-1]) >= MAX_PATH-5)
633  error("Too long filename");
634  }
635 
636  switch(argc - i){ /* number of non-optional arguments */
637  case 0:
638  if(fp_in == NULL)
639  /* infile not given, empty stdin; nothing I can do */
640  usage(1);
641  if(fp_out == NULL){
642  /* outfile not given, free stdout;
643  binary cannot be written, text is fine */
644  if(f_mode == EXE2MODIFY || f_mode == EXE2DVI)
645  usage(1);
646  fp_out = stdout;
647  }
648  break;
649 
650  case 1:
651  /* if(fnum == 2)
652  usage(1); */
653  if(!fnum){ /* empty stdin, free stdout */
654  /* if EXE2DVI, the only argument might be outfile,
655  but no input available; nothing I can do */
656  if(f_mode == EXE2DVI)
657  usage(1);
658  /* otherwise, the only argument should be infile */
659  strcpy(infile, argv[argc-1]);
660  /* outfile not given;
661  nonetheless binary should be written to a file,
662  text is fine with free stdout */
663  if(f_mode == EXE2MODIFY)
664  strcpy(outfile, argv[argc-1]);
665  else
666  fp_out = stdout;
667  }else
668  /* [TODO] this may not work well? (especially for EXE2DVI) */
669  /* if fp_out == NULL, non-empty stdin and free stdout
670  -> the only argument = outfile (input from stdin)
671  otherwise, redirected stdout
672  -> the only argument = infile
673  if fnum == 2, non-empty stdin will be discarded but don't care!
674  (output to overwrite for EXE2MODIFY, stdout for others) */
676  break;
677 
678  case 2:
679  /* prioritize filename arguments;
680  if fp_in != NULL, non-empty stdin will be discarded but don't care! */
681  strcpy(infile, argv[argc-2]);
682  strcpy(outfile, argv[argc-1]);
683  break;
684  default:
685  usage(1);
686  }
687 #ifndef UNIX
688  if(fp_out && !*outfile && (f_mode == EXE2DVI || f_mode == EXE2MODIFY))
690 #endif
691  if(fp_in && !*infile && f_mode != EXE2DVI){
692  fprintf(stderr, "*** stdin is a DVI file. ***\n"
693  "*** Random Access may not be supported! ***\n");
694 #ifndef UNIX
695  setmode( fileno( stdin ), O_BINARY);
696 #endif
697  }
698 
699  /* append .dvi suffix if input/output is DVI */
700  if(f_mode == EXE2DVI || f_mode == EXE2MODIFY){
701  len = strlen(outfile);
702  if(len){
703  if(len < 4 || StrCmp(outfile + len - 4, ".dvi"))
704  strcat(outfile, ".dvi");
705  }
706  }
707  if(f_mode != EXE2DVI){
708  len = strlen(infile);
709  if(len){
710  if(len < 4 || StrCmp(infile + len - 4, ".dvi")){
711  strcat(infile, ".dvi");
712  len += 4; /* will be reused later while preparing overwrite */
713  }
715  }
716  }
717 
718  /* -x : text -> DVI */
719  if(f_mode == EXE2DVI){
720  /* use infile if given, otherwise use existing fp_in (= non-empty stdin)
721  note that fp_in and infile are exclusive (already checked above) */
722  if(fp_in == NULL || *infile){
724  if(fp_in == NULL){
725  fprintf(stderr, "Cannot open %s for input\n", infile);
726  exit(1);
727  }
728  }
729  /* use outfile if given */
730  if(fp_out == NULL || *outfile){
732  if(fp_out == NULL){
733  fprintf(stderr, "Cannot open %s for output\n", outfile);
734  exit(1);
735  }
736  }
737  trans2dvi(); /* files will be closed */
738  return 0;
739  }
740 
741  /* dvi->dvi or -d or -s or -a */
742  /* [TODO] comments not added yet */
743  if(argc - i == 1){
744  if(f_mode == EXE2MODIFY && !fnum){
745 #ifdef UNIX
746  static char tmpfile[] = "/tmp/dvispcXXXXXX";
747  int fd;
748  mode_t mask;
749 
750 same: mask = umask(077);
751  fd = mkstemp(tmpfile);
752  /* better to use tmpfile() */
753  umask(mask);
754  if(fd == -1){
755  fprintf(stderr, "Cannot open temporary file\n");
756  exit(1);
757  }
758  strcpy(outfile, tmpfile);
759  close(fd); /* will be fopen-ed again afterward */
760 #else
762  strcpy(outfile + len - 3, "$$$");
763 #endif
764  f_overwrite = 1;
765  }
766  }else if(argc - i == 2){
767 #ifdef UNIX
768  struct stat infstat, outfstat;
769  if(stat(infile, &infstat) == 0 && stat(outfile, &outfstat) == 0 &&
770  infstat.st_dev == outfstat.st_dev && infstat.st_ino == outfstat.st_ino)
771 #else
772  if(!StrCmp(infile,outfile))
773 #endif
774  goto same;
775  }
776  if(fp_in && !*infile){
778  dvi_info.file_name = "stdin";
780  fprintf(stderr, "Cannot open %s for input\n", infile);
781  exit(1);
782  }
783  /* [TODO] I'd like to use outfile if given */
784  if(fp_out == NULL || *outfile){
785  if(!*outfile)
786  fp_out = (f_mode == EXE2TEXT || f_mode == EXE2SPECIAL)?stdout:stderr;
787  else if(f_mode == EXE2MODIFY)
788  fp_out = stderr;
789  else{
790 #ifdef _MSC_VER
792 #else
794 #endif
795  if(fp_out == NULL){
796  fprintf(stderr, "Cannot open %s for output\n", outfile);
797  exit(1);
798  }
799  }
800  }
804  return 0;
805 }
806 
807 
808 void write_sp(FILE *fp, char *sp)
809 {
810  int len;
811  len = strlen(sp);
812 
813  if(f_debug)
814  fprintf(fp_out, "%s", sp);
815  if(f_mode != EXE2MODIFY || f_last)
816  return; /* dry-run for EXE2CHECK */
817  if(len <= 0xff)
818  fprintf(fp, "%c%c%s", XXX1, len, sp);
819  else if(len <= 0xffffffff){
820  fprintf(fp, "%c", XXX1+3);
821  write_long(len, fp);
822  fprintf(fp, "%s", sp);
823  }else{
824  fprintf(stderr, "Too long special:\n%s\n", sp);
825  Exit(1);
826  }
827 }
828 void write_sp_nodebug(FILE *fp, char *sp)
829 { /* omit debug message (for backward compatibility) */
830  if(f_debug){
831  f_debug = 0; /* disable debug printing temporarily */
832  write_sp(fp, sp);
833  f_debug = 1;
834  }else
835  write_sp(fp, sp);
836 }
837 
838 
840 {
841  int page, page2, pos, count, size, former, current, flag;
842  FILE *fp;
843 
844  if(f_mode == EXE2MODIFY){
845  fp = (*outfile)?fopen(outfile, WRITE_BINARY):fp_out;
846  if(fp == NULL){
847  fprintf(stderr, "Cannot open %s for output\n", outfile);
848  exit(4);
849  }else if(fp==stdout)
850  f_debug = 0; /* ignore -v option, as debug output goes there, sigh */
851  }else
852  fp = NULL;
853 
854  f_needs_corr = flag = 0;
855  f_last = 0;
856 
857  if(f_mode == EXE2TEXT || f_mode == EXE2SPECIAL){
858  while(out_pages && *out_pages){
859  if(*out_pages == 'T'){
860  if(f_mode == EXE2TEXT){
861  fseek(dvi->file_ptr, dvi->post, SEEK_SET);
862  transpre(dvi->file_ptr);
863  }
864  out_pages++;
865  }else if(*out_pages == 'L'){
866  if(f_mode == EXE2TEXT){
867  fseek(dvi->file_ptr, dvi->post, SEEK_SET);
868  transpost(dvi->file_ptr);
869  }
870  out_pages++;
871  }else if(*out_pages == '-'){
872  page = 1;
873  goto lastpage;
874  }else if(isdigit(*out_pages)){
875  page = atoi(out_pages);
876  while(isdigit(*++out_pages));
877  if(*out_pages == '-'){
878 lastpage: if(isdigit(*++out_pages)){
879  page2 = atoi(out_pages);
880  while(isdigit(*++out_pages));
881  }else
882  page2 = dim->total_page;
883  }else
884  page2 = page;
885  if(page < 1 || page > page2 || page2 > dim->total_page){
886  fprintf(stderr, "Page instruction %d-%d by -p is out of range (1-%d)\n",
887  page, page2, dim->total_page);
888  exit(1);
889  }
890  for( ; page <= page2; page++){
891  if(!(f_dtl&DTL_PAGE)){
892  if(f_mode == EXE2TEXT)
893  putc(' ', fp_out);
894  fprintf(fp_out, "[%d]\n", page);
895  }
896  fseek(dvi->file_ptr, dim->page_index[page], SEEK_SET);
897  interpret(dvi->file_ptr);
898  }
899  }else
900  out_pages++;
901  }
902  fclose(dvi->file_ptr);
903  fclose(fp_out);
904  dvi->file_ptr = fp_out = NULL;
905  return;
906  } /* done for if(f_mode == EXE2TEXT || f_mode == EXE2SPECIAL),
907  the rest of translate() is meant for
908  if((f_mode == EXE2MODIFY) and (f_mode == EXE2CHECK)) */
909 
910  /* Prior scanning. This ensures page independence in reverse order too,
911  (e.g. Page 1 & 2 without background (= white) and Page 3 with background)
912  by checking whether non-stack specials (except tpic_pn) appears somewhere in DVI.
913  Specials with paired syntax (push/pop, bcolor/ecolor) are already safe
914  without pre-scanning, so these are skipped due to f_prescan = 1.
915  Other specials (background, pdf_bgcolor) are handled in this scanning. */
916  f_prescan = 1; /* change behavior of interpret(dvi) */
917  for(page = 1; page <= dim->total_page; page++){
918  fseek(dvi->file_ptr, dim->page_index[page], SEEK_SET);
919  interpret(dvi->file_ptr);
920  }
921  f_prescan = 0; /* restore interpret(dvi) */
922 
923  former = current = -1;
924  if(fp){ /* f_mode == EXE2MODIFY and can be opened */
925  fseek(dvi->file_ptr, 0, SEEK_SET);
926  for(size = dim->page_index[1]; size > 0; size--)
927  write_byte(read_byte(dvi->file_ptr), fp); /* Write preamble */
928  /* [Process 1] Start writing the first page. */
929  current = ftell(fp); /* position of 1-st BOP */
930  for(size = 41; size > 0; size--) /* Write BOP and c[] */
931  write_byte(read_byte(dvi->file_ptr), fp);
932  write_long(former, fp); /* ptr to the former page = -1 */
933  }
934 
935  for(page = 1; page <= dim->total_page; page++){ /* page loop start */
936  fseek(dvi->file_ptr, dim->page_index[page], SEEK_SET);
937  pos = interpret(dvi->file_ptr); /* scanned the whole page content; now
938  pos = position of EOP + 1 */
939  if(f_debug){ /* EXE2CHECK always falls into this */
940  fprintf(fp_out, "[%d]", page);
941  flag = f_needs_corr; /* reserved for later check */
942  }
943 
944  /* [Process 2] Before writing the current page, handle non-stack specials.
945  * If not found but necessary, put one.
946  * If found, save current status before going back to the loop head
947  for the next page (= scanning the whole next page might overwrite it!).
948  Also, if the page is suffering from stack underflow,
949  open lacking stacks beforehand. */
950  while(color_under > 0){ /* recover underflow of color stack */
951  write_sp_nodebug(fp, "color push Black");
952  f_needs_corr++;
953  color_under--;
954  }
955  while(pdf_color_under > 0){ /* recover underflow of pdf:bcolor ... pdf:ecolor stack */
956  write_sp_nodebug(fp, "pdf:bcolor [0]");
957  f_needs_corr++;
958  pdf_color_under--;
959  }
960  if(background[0]){ /* background used somewhere */
961  if(!f_background){ /* no background in this page */
962  if(f_debug) fprintf(fp_out, "\n");
963  if(!background_prev[0]) /* assume white */
964  write_sp(fp, "background gray 1");
965  else
967  f_needs_corr++;
968  }else /* this page had one! */
969  strncpy(background_prev, background, MAX_LEN); /* save current */
970  }
971  if(pdf_bgcolor[0]){ /* pdf:bgcolor used somewhere */
972  if(!f_pdf_bgcolor){ /* no pdf:bgcolor in this page */
973  if(f_debug) fprintf(fp_out, "\n");
974  if(!pdf_bgcolor_prev[0]) /* assume white */
975  write_sp(fp, "pdf:bgcolor [1]");
976  else
978  f_needs_corr++;
979  }else /* this page had one! */
980  strncpy(pdf_bgcolor_prev, pdf_bgcolor, MAX_LEN); /* save current */
981  }
982 // while(pdf_annot_under > 0){ /* recover underflow of pdf:bann ... pdf:eann stack */
983 // /* [TODO] what should we do here? */
984 // f_needs_corr++;
985 // pdf_annot_under--;
986 // }
987  if(f_pn < 0) { /* tpic_pn from the former page should be effective ... */
988  if(!tpic_pn_prev[0]) /* ... but nothing found before */
989  fprintf(stderr, "\nCannot find valid tpic pn."
990  "\nPlease check your LaTeX source.");
991  else{ /* ... OK */
992  if(f_debug) fprintf(fp_out, "\n");
994  f_needs_corr++;
995  }
996  }
997  if(tpic_pn[0] && f_pn) /* tpic_pn used in this page */
998  strncpy(tpic_pn_prev, tpic_pn, MAX_LEN); /* save current */
999 
1000  /* [Process 3] Write contents of the current page. */
1001  if(f_mode == EXE2MODIFY){
1002  fseek(dvi->file_ptr, dim->page_index[page]+45, SEEK_SET);
1003  for(size = pos - dim->page_index[page] - 46; size > 0; size--)
1004  write_byte(read_byte(dvi->file_ptr), fp);
1005  }
1006 
1007  /* [Process 4] After writing the current page,
1008  close not-yet-closed stacks. */
1009  for(count = 0; count < color_depth; count++){
1010  write_sp_nodebug(fp, "color pop");
1011  f_needs_corr++;
1012  }
1013  for(count = 0; count < pdf_color_depth; count++){
1014  write_sp_nodebug(fp, "pdf:ecolor");
1015  f_needs_corr++;
1016  }
1017 // for(count = 0; count < pdf_annot_depth; count++){
1018 // write_sp_nodebug(fp, "pdf:eann");
1019 // f_needs_corr++;
1020 // }
1021  if(f_mode == EXE2MODIFY){
1022  write_byte((uchar)EOP, fp); /* write EOP */
1023  former = current;
1024  current = ftell(fp); /* get position of BOP/POST */
1025  }
1026 
1027  if(page == dim->total_page)
1028  f_last = 1; /* reached the last page, change behavior of write_sp(fp,sp) */
1029 
1030  /* [Process 5] Except for the last page,
1031  start the next page with passing not-yet-closed stacks. */
1032  if(f_mode == EXE2MODIFY && !f_last){
1033  fseek(dvi->file_ptr, dim->page_index[page+1], SEEK_SET);
1034  for(size = 41; size > 0; size--) /* write BOP and c[] */
1035  write_byte(read_byte(dvi->file_ptr), fp);
1036  write_long(former, fp); /* position of BOP of the former page */
1037  }
1038  for(count = 0; count < color_depth; count++){
1039  if(f_debug) fprintf(fp_out, "\n%d:", count+1);
1041  }
1042  for(count = 0; count < pdf_color_depth; count++){
1043  if(f_debug) fprintf(fp_out, "\n%d:", count+1);
1045  }
1046 // for(count = 0; count < pdf_annot_depth; count++){
1047 // if(f_debug) fprintf(fp_out, "\n%d:", count+1);
1048 // write_sp(fp, pdf_annot_pt[count]);
1049 // }
1050  /* f_needs_corr already set properly in [Process 4] */
1051 
1052  if(f_debug){ /* EXE2CHECK always falls into this */
1053  if(flag != f_needs_corr) /* at least one special printed for debug */
1054  fprintf(fp_out, "\n");
1055  }
1056  f_last = 0; /* restore write_sp(fp,sp) */
1057  } /* page loop end */
1058 
1059  if(f_debug) { /* EXE2CHECK always falls into this */
1060  if(color_depth_max)
1061  fprintf(fp_out, "\nMaximal depth of color stack:%d", color_depth_max);
1063  fprintf(fp_out, "\nMaximal depth of pdf:bcolor ... pdf:ecolor stack:%d", pdf_color_depth_max);
1065  fprintf(fp_out, "\nMaximal depth of pdf:bann ... pdf:eann stack:%d", pdf_annot_depth_max);
1066  }
1067  if(f_mode == EXE2CHECK){
1068  fclose(dvi->file_ptr);
1070  "\nSome corrections are necessary!\n":
1071  "\nNo modification is necessary\n");
1072  fclose(fp_out);
1073  dvi->file_ptr = fp_out = NULL;
1074  return;
1075  } /* done for EXE2CHECK; remainings are for EXE2MODIFY */
1076 
1077  /* if -z option is given, add empty pages to make multiple of 4 pages */
1078  if(f_book && dim->total_page%4 == 0)
1079  f_book = 0; /* modification unnecessary */
1080  if(f_book){
1081  total_book_page = dim->total_page + (4 - dim->total_page%4)%4;
1082  for(page = dim->total_page; page < total_book_page; page++){
1083  write_byte((uchar)BOP,fp);
1084  write_long(-1, fp);
1085  for (count = 1; count < 10; count++) /* set all sub counts to 0 */
1086  write_long(0, fp);
1087  write_long(former, fp);
1088  /* always white page */
1089  if(background[0]) /* background is used somewhere */
1090  write_sp(fp, "background gray 1");
1091  if(pdf_bgcolor[0]) /* pdf:bgcolor is used somewhere */
1092  write_sp(fp, "pdf:bgcolor [1]");
1093  write_byte((uchar)EOP,fp);
1094  former = current;
1095  current = ftell(fp); /* get position of BOP/POST */
1096  }
1097  }
1098 
1099  write_byte((uchar)POST,fp); /* write POST */
1100  write_long(former, fp); /* position of the last BOP */
1101 
1102  fseek(dvi->file_ptr, dvi->post + 5, SEEK_SET);
1103  if(f_book){
1104  write_long(read_long(dvi->file_ptr), fp); /* numerator */
1105  write_long(read_long(dvi->file_ptr), fp); /* denominator */
1106  write_long(read_long(dvi->file_ptr), fp); /* magnification */
1107  write_long(read_long(dvi->file_ptr), fp); /* tallest page height */
1108  write_long(read_long(dvi->file_ptr), fp); /* widest page width */
1109  write_word(read_word(dvi->file_ptr), fp); /* DVI stack size */
1110  read_word(dvi->file_ptr); /* skip original number of pages */
1111  write_word(total_book_page, fp); /* new number of pages */
1112  for(size = dvi->pt_post - dvi->post - 29; size-- > 0; )
1113  write_byte(read_byte(dvi->file_ptr), fp); /* write postamble upto post_post */
1114  }
1115  else{
1116  for(size = dvi->pt_post - dvi->post - 5; size-- > 0; )
1117  write_byte(read_byte(dvi->file_ptr), fp); /* write postamble upto post_post */
1118  }
1119  write_long(current, fp); /* position of POST */
1120  read_long(dvi->file_ptr); /* skip old position of POST */
1121  write_byte(read_byte(dvi->file_ptr), fp); /* write id = 2/3 */
1122 
1123  for(size = 4; size > 0; size--)
1124  write_byte((uchar)END_DVI, fp); /* write END_DVI */
1125  size = ftell(fp);
1126  while(size++ & 3) /* fill END_DVI */
1128  fclose(fp);
1129  fclose(dvi->file_ptr);
1130  fp = dvi->file_ptr = NULL;
1131  if(!f_needs_corr && !f_book){
1132  unlink(outfile);
1133  fprintf(stderr, "\nNo correction is done.\n");
1134  return;
1135  }
1136  if(f_overwrite){
1137  if(f_backup){
1138  sprintf(tmp_buf, "%s.bak", infile);
1139  if(rename(infile, tmp_buf) == -1){
1140  fprintf(stderr, "Cannot backup %s to %s\n", infile, tmp_buf);
1141  Exit(1);
1142  }
1143  }else
1144  unlink(infile);
1145  if(rename(outfile, infile) == -1){
1146  fprintf(stderr, "Cannot overwrite %s\n", infile);
1147  Exit(1);
1148  }
1149  fprintf(stderr, "\nDVI file %s is corrected\n", infile);
1150  }else
1151  fprintf(stderr, "\nCreate a new DVI file %s\n", (fp_out==stdout)?"(stdout)":outfile);
1152 }
1153 
1154 
1156 {
1157  int i, tmp;
1158  Long offset;
1159 
1160  dim->page_index =
1161  (PAGE_INDEX *)malloc(sizeof(PAGE_INDEX) * (
1162  (dim->total_page = dvi->total_page) + 2));
1163 
1164  dim->max_nombre_page = 0;
1165  for (offset = dvi->last_bop, i = dvi->total_page; i > 0; i--) {
1166  fseek(dvi->file_ptr, offset, SEEK_SET);
1167  if ((uchar)read_byte(dvi->file_ptr) != BOP){
1168  fprintf(stderr, "No BOP command in page %d\n", i);
1169  Exit(1);
1170  }
1171  dim->page_index[i] = offset;
1172  if((tmp = read_long(dvi->file_ptr))
1173  > dim->max_nombre_page)
1174  dim->max_nombre_page = tmp;
1175 
1176  /* Read count[0] */
1177  fseek(dvi->file_ptr, 36L, SEEK_CUR);
1178  /* Skip other 'count' values */
1179  offset = read_long(dvi->file_ptr);
1180  }
1181 }
1182 
1184 {
1185  int i;
1186 
1187 /*
1188  font = NULL;
1189 
1190  H0 = output->h_0;
1191  V0 = output->v_0;
1192 */
1193  if ((uchar)read_byte(dvi) != BOP)
1194  error("No BOP");
1195  if(f_mode == EXE2TEXT){
1196  if(f_pos)
1197  fprintf(fp_out, "%ld: ", ftell(dvi)-1);
1198  fputs("bop", fp_out);
1199  fprintf(fp_out, " %d%s", read_long(dvi), MSG("/page"));
1200  for(i = 1; i < 10; i++)
1201  fprintf(fp_out, " %d", read_long(dvi));
1202  fprintf(fp_out, " %d%s\n", read_long(dvi), MSG("/former_bop"));
1203  }else
1204  fseek(dvi, 44L, SEEK_CUR);
1205  return (f_mode == EXE2TEXT)?work(dvi):s_work(dvi);
1206 }
1207 
1208  /* set_char_0, 0 SET_CHAR_0 */
1209 static uchar cmd128_mode[] =
1210 {
1211  0x31, /* 128 SET1 */
1212  0x32, /* 129 */
1213  0x33, /* 130 */
1214  0x34, /* 131 */
1215  8, /* 132 SET_RULE */
1216  0x31, /* 133 PUT1 */
1217  0x32, /* 134 */
1218  0x33, /* 135 */
1219  0x34, /* 136 */
1220  8, /* 137 PUT_RULE */
1221  0, /* 138 NOP */
1222  0x10, /* 139 BOP */
1223  0x10, /* 140 */
1224  0, /* 141 PUSH */
1225  0, /* 142 POP */
1226  1, /* 143 RIGHT1 */
1227  2, /* 144 */
1228  3, /* 145 */
1229  4, /* 146 */
1230  0, /* 147 W0 */
1231  1, /* 148 W1 */
1232  2, /* 149 */
1233  3, /* 150 */
1234  4, /* 151 */
1235  0, /* 152 X0 */
1236  1, /* 153 X1 */
1237  2, /* 154 */
1238  3, /* 155 */
1239  4, /* 156 */
1240  1, /* 157 DOWN1 */
1241  2, /* 158 */
1242  3, /* 159 */
1243  4, /* 160 */
1244  0, /* 161 Y0 */
1245  1, /* 162 Y1 */
1246  2, /* 163 */
1247  3, /* 164 */
1248  4, /* 165 */
1249  0, /* 166 Z0 */
1250  1, /* 167 Z1 */
1251  2, /* 168 */
1252  3, /* 169 */
1253  4 /* 170 */
1254 };
1255 
1256  /* fnt_num_0, 171 FNT_NUM_0 */
1257 static uchar cmd235_mode[] =
1258 {
1259  0x41, /* 235 FNT1 */
1260  0x42, /* 236 */
1261  0x43, /* 237 */
1262  0x44, /* 238 */
1263 
1264  0x51, /* 239 XXX1 */
1265  0x52, /* 240 */
1266  0x53, /* 241 */
1267  0x54, /* 242 */
1268 
1269  0x21, /* 243 FNT_DEF_1 */
1270  0x22, /* 244 */
1271  0x23, /* 245 */
1272  0x24, /* 246 */
1273 
1274  0x10, /* 247 PRE */
1275  0x10, /* 248 */
1276  0x10, /* 249 */
1277  0x10, /* 250 */
1278  0x10, /* 251 */
1279  0x10, /* 252 */
1280  0x10, /* 253 */
1281  0x10, /* 254 */
1282  0x10 /* 255 EOFNC */
1283 };
1284 
1285 
1286 int strsubcmp(char *s, char *t)
1287 {
1288  while(*s == *t){
1289  if(!*t)
1290  return 0;
1291  s++;
1292  t++;
1293  }
1294  return(!*t && (uchar)(*s) <= ' ')?0:1;
1295 }
1296 
1297 /* without space separator (e.g. pdf:bann<<...>>, instead of pdf:bann <<...>>) */
1298 int strsubcmp_n(char *s, char *t)
1299 {
1300  while(*s == *t){
1301  if(!*t)
1302  return 0;
1303  s++;
1304  t++;
1305  }
1306  return(!*t)?0:1;
1307 }
1308 
1310 {
1311  int code, mode, tmp = 0;
1312  f_background = 0;
1313  f_pdf_bgcolor = 0;
1314  f_pn = 0;
1315 
1316  while ((code = (uchar)read_byte(dvi)) != EOP){
1317  if(code >= 128){
1318  if (code < FNT_NUM_0){
1319  mode = cmd128_mode[code - 128];
1320  goto work;
1321  }else if (code >= FNT1){
1322  mode = cmd235_mode[code - FNT1];
1323 work: if (mode >= 0x30)
1324  tmp = read_n(dvi, mode & 0xf);
1325  switch (mode >> 4) {
1326  case (0):
1327  while(mode-- > 0)
1328  (void)read_byte(dvi);
1329  break;
1330 
1331  case (1):
1332  if(!f_ptex || code != EOFNC){
1333  fprintf(stderr, "illegal code(%d)\n", code);
1334  Exit(1);
1335  }
1336  (void)read_byte(dvi);
1337  break;
1338 
1339  case (2):
1340  fseek(dvi, (Long)((mode & 0xf) + 12), SEEK_CUR);
1341  tmp = (uchar)read_byte(dvi) + (uchar)read_byte(dvi);
1342 skip: while (tmp--)
1343  (void)read_byte(dvi);
1344  break;
1345 /*
1346  case (3):
1347  break;
1348 
1349  case (4):
1350  break;
1351 */
1352  case (5):
1353  if(tmp < COMMON_SIZE-1){
1354  char *special;
1355 
1356  special = tmp_buf;
1357  while (tmp-- > 0)
1358  *special++ = (uchar)getc(dvi);
1359  *special = '\0';
1360  if(f_mode == EXE2SPECIAL){
1361  fprintf(fp_out, "{%s}\n", tmp_buf);
1362  break;
1363  }
1364  special = tmp_buf;
1365  while(*special && ((uchar)*special) <= ' ')
1366  special++;
1367  if(!strsubcmp(special, "pn")){ /* pn: tpic pen size */
1369  if(!f_pn)
1370  f_pn = 1;
1371  }else if(!f_pn &&
1372  (!strsubcmp(special, "pa") || /* pa: tpic pen at */
1373  !strsubcmp(special, "ar")) ) /* ar: draw circle */
1374  f_pn = -1;
1375  else if(!strsubcmp(special, "color")) /* color push/pop */
1376  sp_color(special);
1377  else if(!strsubcmp(special, "pdf:bcolor")) /* pdf:bcolor */
1379  else if(!strsubcmp(special, "pdf:ecolor")) /* pdf:ecolor */
1381  else if(!strsubcmp(special, "background")){ /* background */
1383  f_background = 1;
1384  }
1385  else if(!strsubcmp(special, "pdf:bgcolor")){ /* pdf:bgcolor */
1387  f_pdf_bgcolor = 1;
1388  }
1389 // else if(!strsubcmp_n(special, "pdf:bann")) /* pdf:bann */
1390 // sp_pdf_bann(special);
1391 // else if(!strsubcmp(special, "pdf:eann")) /* pdf:eann */
1392 // sp_pdf_eann(special);
1393  break;
1394  }
1395  goto skip;
1396  }
1397  }
1398  }
1399  }
1400  return ftell(dvi);
1401 }
1402 
1403 /* color specials */
1404 void sp_color(char *sp)
1405 {
1406  char *s;
1407  if(f_prescan) return;
1408 
1409  if(strstr(sp, "pop")){
1410  if(--color_depth < 0){
1411  fprintf(stderr, "color stack underflow\n");
1412  color_under++;
1413  f_needs_corr++;
1414  color_depth = 0;
1415  }
1416  return;
1417  }
1418  if(strstr(sp, "push")){
1419  if(color_depth >= MAX_COLOR){
1420  fprintf(stderr, "Too many color push > %d\n", MAX_COLOR);
1421  Exit(1);
1422  }
1423  if(color_depth){
1424  s = color_pt[color_depth-1];
1425  s += strlen(s) + 1;
1426  }
1427  else
1428  s = color_buf;
1429  if(s - color_buf + strlen(sp) >= COLOR_BUF_SIZE - 2)
1430  error("Too much color definitions");
1431  else{
1432  strcpy(s, sp);
1433  color_pt[color_depth++] = s;
1434  }
1437  }
1438 }
1439 
1440 /* pdf:bcolor special */
1441 void sp_pdf_bcolor(char *sp)
1442 {
1443  char *s;
1444  if(f_prescan) return;
1445 
1446  /* copied from "color push" routine of sp_color */
1447  if(pdf_color_depth >= MAX_COLOR){
1448  fprintf(stderr, "Too many pdf:bcolor > %d\n", MAX_COLOR);
1449  Exit(1);
1450  }
1451  if(pdf_color_depth){
1453  s += strlen(s) + 1;
1454  }
1455  else
1456  s = color_buf;
1457  if(s - color_buf + strlen(sp) >= COLOR_BUF_SIZE - 2)
1458  error("Too much color definitions");
1459  else{
1460  strcpy(s, sp);
1462  }
1465 }
1466 
1467 /* pdf:ecolor special */
1468 void sp_pdf_ecolor(char *sp)
1469 {
1470  char *s;
1471  if(f_prescan) return;
1472 
1473  /* copied from "color pop" routine of sp_color */
1474  if(--pdf_color_depth < 0){
1475  fprintf(stderr, "pdf:bcolor ... pdf:ecolor stack underflow\n");
1476  pdf_color_under++;
1477  f_needs_corr++;
1478  pdf_color_depth = 0;
1479  }
1480  return;
1481 }
1482 
1483 /* pdf:bann special */
1484 void sp_pdf_bann(char *sp)
1485 {
1486  char *s;
1487  if(f_prescan) return;
1488  if(pdf_annot_depth >= MAX_ANNOT){
1489  fprintf(stderr, "Too many pdf:bann > %d\n", MAX_ANNOT);
1490  Exit(1);
1491  }
1492  if(pdf_annot_depth){
1494  s += strlen(s) + 1;
1495  }
1496  else
1497  s = annot_buf;
1498  if(s - annot_buf + strlen(sp) >= ANNOT_BUF_SIZE - 2)
1499  error("Too much annot definitions");
1500  else{
1501  strcpy(s, sp);
1503  }
1506 }
1507 
1508 /* pdf:eann special */
1509 void sp_pdf_eann(char *sp)
1510 {
1511  char *s;
1512  if(f_prescan) return;
1513  if(--pdf_annot_depth < 0){
1514  fprintf(stderr, "pdf:bann ... pdf:eann stack underflow\n");
1515  pdf_annot_under++;
1516 // f_needs_corr++;
1517  pdf_annot_depth = 0;
1518  }
1519  return;
1520 }
1521 
1524 
1526  /* read POSTAMBLE */
1527 {
1528  int code, endofs, top_add;
1529 
1530  if ( read_byte(dvi->file_ptr) != PRE ||
1531  ((code = read_byte(dvi->file_ptr)) != ID && code != IDP) ){
1532 err: fprintf(stderr, "%s is not correct DVI file\n", dvi->file_name);
1533  Exit(254);
1534  }
1535  for (endofs = -3L; fseek(dvi->file_ptr, endofs, SEEK_END),
1536  (code = read_byte(dvi->file_ptr)) != ID && code != IDP; endofs--){
1537  /* Search id number */
1538  if (code == EOF || code != END_DVI)
1539  goto err;
1540  }
1541  f_ptex = (code==IDP)?1:0;
1542  fseek(dvi->file_ptr, endofs - 4L, SEEK_END);
1543  dvi->pt_post = ftell(dvi->file_ptr); /* get POST_POST */
1544  if ((top_add = dvi->post = read_long(dvi->file_ptr)) <= 0) /* get POST */
1545  goto err;
1546  /* Read the position of POSTAMBLE */
1547 
1548  fseek(dvi->file_ptr, dvi->post - 4, SEEK_SET);
1549  /* Set file-ptr at POSTAMBLE */
1550 
1551  if(AdID == read_long(dvi->file_ptr))
1552  num_add = 1;
1553  if((code = read_byte(dvi->file_ptr)) != POST) /* at POST */
1554  goto err;
1555  if((dvi->last_bop = read_long(dvi->file_ptr)) <= 0) /* get LAST_BOP */
1556  goto err;
1557 #if 0
1558  /* for extended DVI file of dviout */
1559  fseek(dvi->file_ptr, dvi->post - 20, SEEK_SET);
1560  if(num_add){
1561  int i, j, size;
1562  char *s;
1563 
1564  bofn = read_long(dvi->file_ptr);
1565  eofn = read_long(dvi->file_ptr);
1566  num_add = last_add = read_long(dvi->file_ptr);
1567  top_add = read_long(dvi->file_ptr);
1568  fseek(dvi->file_ptr, dvi->post - 20 - 8*num_add, SEEK_SET);
1569  for(i = 0; i < num_add; i++){
1570  pt_bod[i] = read_long(dvi->file_ptr);
1571  lod[i] = read_long(dvi->file_ptr);
1572  }
1573  fseek(dvi->file_ptr, bofn, SEEK_SET);
1574  size = eofn - bofn;
1575  s = malloc(size);
1576  for(i = 0; i < size; i++)
1577  s[i] = read_byte(dvi->file_ptr);
1578  pt_name[0] = s;
1579  for(i = j = 0; i < size; ){
1580  if(!s[i++])
1581  pt_name[++j] = s + i;
1582  }
1583  }
1584 #endif
1585  fseek(dvi->file_ptr, dvi->post, SEEK_SET);
1586 
1587  /* Set file-ptr at POSTAMBLE */
1588  if ((uchar)read_byte(dvi->file_ptr) != POST)
1589  error("No Postamble");
1590 
1591  if ((dvi->last_bop = read_long(dvi->file_ptr)) <= 0)
1592  error("Negative Pointer(Last BOP)");
1593 
1594  dvi->num = read_long(dvi->file_ptr);
1595  dvi->den = read_long(dvi->file_ptr);
1596  dvi->mag = read_long(dvi->file_ptr);
1597  dvi->l = read_long(dvi->file_ptr);
1598  dvi->u = read_long(dvi->file_ptr);
1599  dvi->stack_depth = read_short(dvi->file_ptr);
1600  dvi->total_page = read_short(dvi->file_ptr);
1601 
1602  if (dvi->num <= 0 || dvi->den <= 0 || dvi->mag <= 0)
1603  error("Reading Illegal Long");
1604  if (dvi->stack_depth < 0 || dvi->total_page <= 0)
1605  error("Reading Illegal Integer");
1606 }
1607 
1608 /************** dvi -> text ******************/
1609 
1610 static char *SETCHAR = "setchar";
1611 
1612 static char *cmd128_name[] =
1613 {
1614  "set1", /* 128 SET1 */
1615  "set2", /* 129 */
1616  "set3", /* 130 */
1617  "set4", /* 131 */
1618  "setrule", /* 132 SET_RULE */
1619  "put1", /* 133 PUT1 */
1620  "put2", /* 134 */
1621  "put3", /* 135 */
1622  "put4", /* 136 */
1623  "putrule", /* 137 PUT_RULE */
1624  "nop", /* 138 NOP */
1625  "bop", /* 139 BOP */
1626  "eop", /* 140 EOP */
1627  "push", /* 141 PUSH */
1628  "pop", /* 142 POP */
1629  "right1", /* 143 RIGHT1 */
1630  "right2", /* 144 */
1631  "right3", /* 145 */
1632  "right4", /* 146 */
1633  "w0", /* 147 W0 */
1634  "w1", /* 148 W1 */
1635  "w2", /* 149 */
1636  "w3", /* 150 */
1637  "w4", /* 151 */
1638  "x0", /* 152 X0 */
1639  "x1", /* 153 X1 */
1640  "x2", /* 154 */
1641  "x3", /* 155 */
1642  "x4", /* 156 */
1643  "down1", /* 157 DOWN1 */
1644  "down2", /* 158 */
1645  "down3", /* 159 */
1646  "down4", /* 160 */
1647  "y0", /* 161 Y0 */
1648  "y1", /* 162 Y1 */
1649  "y2", /* 163 */
1650  "y3", /* 164 */
1651  "y4", /* 165 */
1652  "z0", /* 166 Z0 */
1653  "z1", /* 167 Z1 */
1654  "z2", /* 168 */
1655  "z3", /* 169 */
1656  "z4" /* 170 */
1657 };
1658 
1659 static char *cmd235_name[] =
1660 {
1661  "fnt1", /* 235 FNT1 */
1662  "fnt2", /* 236 */
1663  "fnt3", /* 237 */
1664  "fnt4", /* 238 */
1665 
1666  "xxx1", /* 239 XXX1 */
1667  "xxx2", /* 240 */
1668  "xxx3", /* 241 */
1669  "xxx4", /* 242 */
1670 
1671  "fntdef1", /* 243 FNT_DEF_1 */
1672  "fntdef2", /* 244 */
1673  "fntdef3", /* 245 */
1674  "fntdef4", /* 246 */
1675 
1676  "pre", /* 247 PRE */
1677  "illegal", /* 248 */
1678  "illegal", /* 249 */
1679  "illegal", /* 250 */
1680  "illegal", /* 251 */
1681  "illegal", /* 252 */
1682  "illegal", /* 253 */
1683  "illegal", /* 254 */
1684  "dir" /* 255 EOFNC */
1685 };
1686 
1687 static char *c128_name[] =
1688 {
1689  "s1", /* 128 SET1 */
1690  "s2", /* 129 */
1691  "s3", /* 130 */
1692  "s4", /* 131 */
1693  "sr", /* 132 SET_RULE */
1694  "p1", /* 133 PUT1 */
1695  "p2", /* 134 */
1696  "p3", /* 135 */
1697  "p4", /* 136 */
1698  "pr", /* 137 PUT_RULE */
1699  "nop", /* 138 NOP */
1700  "bop", /* 139 BOP */
1701  "eop", /* 140 EOP */
1702  "[", /* 141 PUSH */
1703  "]", /* 142 POP */
1704  "r1", /* 143 RIGHT1 */
1705  "r2", /* 144 */
1706  "r3", /* 145 */
1707  "r4", /* 146 */
1708  "w0", /* 147 W0 */
1709  "w1", /* 148 W1 */
1710  "w2", /* 149 */
1711  "w3", /* 150 */
1712  "w4", /* 151 */
1713  "x0", /* 152 X0 */
1714  "x1", /* 153 X1 */
1715  "x2", /* 154 */
1716  "x3", /* 155 */
1717  "x4", /* 156 */
1718  "d1", /* 157 DOWN1 */
1719  "d2", /* 158 */
1720  "d3", /* 159 */
1721  "d4", /* 160 */
1722  "y0", /* 161 Y0 */
1723  "y1", /* 162 Y1 */
1724  "y2", /* 163 */
1725  "y3", /* 164 */
1726  "y4", /* 165 */
1727  "z0", /* 166 Z0 */
1728  "z1", /* 167 Z1 */
1729  "z2", /* 168 */
1730  "z3", /* 169 */
1731  "z4" /* 170 */
1732 };
1733 
1734 static char *c235_name[] =
1735 {
1736  "f1", /* 235 FNT1 */
1737  "f2", /* 236 */
1738  "f3", /* 237 */
1739  "f4", /* 238 */
1740 
1741  "special1", /* 239 XXX1 */
1742  "special2", /* 240 */
1743  "special3", /* 241 */
1744  "special4", /* 242 */
1745 
1746  "fd1", /* 243 FNT_DEF_1 */
1747  "fd2", /* 244 */
1748  "fd3", /* 245 */
1749  "fd4", /* 246 */
1750 
1751  "pre", /* 247 PRE */
1752  "opcode", /* 248 */
1753  "opcode", /* 249 */
1754  "opcode", /* 250 */
1755  "opcode", /* 251 */
1756  "opcode", /* 252 */
1757  "opcode", /* 253 */
1758  "opcode", /* 254 */
1759  "dir" /* 255 EOFNC */
1760 };
1761 
1762 
1763 #define MAX_STR 0x60
1764 
1766 int len = 0;
1767 
1768 void flush_str(void)
1769 {
1770  if(!len)
1771  return;
1772  str_buf[len] = 0;
1773  if(f_dtl&DTL_CHAR)
1774  fprintf(fp_out, "(%s)\n", str_buf);
1775  else
1776  fprintf(fp_out, " \"%s\"\n", str_buf);
1777  len = 0;
1778 }
1779 
1780 #ifndef PTEXENC
1781 #ifndef UNIX
1782 void jis2sjis(int *h, int *l)
1783 {
1784  if (*h & 1) {
1785  if (*l < 0x60) *l += 0x1f;
1786  else *l += 0x20;
1787  }else *l += 0x7e;
1788  if (*h < 0x5f) *h = (*h + 0xe1) >> 1;
1789  else *h = (*h + 0x161) >> 1;
1790 }
1791 #endif
1792 #endif
1793 
1794 void out_string(FILE *in, FILE *out, int len)
1795 {
1796  int ch;
1797 
1798  while(len-- > 0){
1799  ch = getc(in);
1800  if(f_dtl & DTL_STRING){
1801  if(ch < ' ' || ch > 0x7e){
1802  fprintf(out, "\\%02X", ch & 0xff);
1803  continue;
1804  }
1805  if(ch == '\'' || ch == '\\')
1806  putc('\\', out);
1807  }
1808  putc(ch, out);
1809  }
1810 }
1811 
1812 /* preamble */
1814 {
1815  int len;
1816  fseek(dvi, 1, SEEK_SET);
1817  if(f_dtl & DTL_FORM)
1818  fprintf(fp_out, "variety sequences-6\n");
1819  if(f_pos)
1820  fputs("0: ", fp_out);
1821  fprintf(fp_out, "pre %u%s ", getc(dvi), MSG("/id")); /* id */
1822  fprintf(fp_out, "%u%s ", read_long(dvi), MSG("/num")); /* num */
1823  fprintf(fp_out, "%u%s ", read_long(dvi), MSG("/den")); /* den */
1824  fprintf(fp_out, "%u%s ", read_long(dvi), MSG("/mag")); /* mag */
1825  fprintf(fp_out, "%u%s ", len = getc(dvi),MSG("/len")); /* len */
1826  putc('\'', fp_out);
1827  out_string(dvi, fp_out, len);
1828  fputs("\'\n", fp_out);
1829 }
1830 
1831 
1832 /* postamble */
1834 {
1835  int code;
1836 
1837  if(f_pos)
1838  fprintf(fp_out, "%ld: ", ftell(dvi));
1839  getc(dvi);
1840  fprintf(fp_out, "post %u%s ", read_long(dvi), MSG("/final_bop")); /* pointer to the last bop*/
1841  fprintf(fp_out, "%u%s ", read_long(dvi), MSG("/num")); /* num */
1842  fprintf(fp_out, "%u%s ", read_long(dvi), MSG("/den")); /* den */
1843  fprintf(fp_out, "%u%s ", read_long(dvi), MSG("/mag")); /* mag */
1844  fprintf(fp_out, "%u%s ", read_long(dvi), MSG("/h+d")); /* h+d */
1845  fprintf(fp_out, "%u%s ", read_long(dvi), MSG("/w")); /* w */
1846  fprintf(fp_out, "%u%s ", read_n(dvi, 2), MSG("/stack")); /* stack */
1847  fprintf(fp_out, "%u%s\n", read_n(dvi, 2), MSG("/pages")); /* pages */
1848  work(dvi); /* definiton of fonts */
1849  fprintf(fp_out, " %u%s", read_long(dvi), MSG("/post")); /* pointer to post */
1850  fprintf(fp_out, " %u%s", getc(dvi), MSG("/id")); /* id */
1851  while( (code = getc(dvi)) != EOF)
1852  fprintf(fp_out, " %u", code);
1853  putc('\n', fp_out);
1854 }
1855 
1856 
1857 /* content of a page */
1859 {
1860  int code, mode, tmp = 0;
1861  long pos = 0;
1862  uint csum;
1863 #ifdef PTEXENC
1864  int imb;
1865  long wch;
1866  char mbstr[4];
1867 #else
1868  int h_code, l_code;
1869 #endif
1870 
1871  while( (code = (uchar)read_byte(dvi)) != EOP && code != POST_POST){
1872  if(f_pos)
1873  pos = ftell(dvi)-1;
1874  if(code < 128){
1875  if(f_pos && (!len || !(f_dtl&DTL_CHAR)))
1876  fprintf(fp_out, "%ld: ", pos);
1877  if(code >= 0x20 && code < 0x7f){
1878  if(len > MAX_STR-2){
1879  flush_str();
1880  len = 0;
1881  if(f_pos)
1882  fprintf(fp_out, "%ld: ", pos);
1883  }
1884  if((f_dtl & DTL_CHAR) &&
1885  (code == '(' || code == ')' || code == '\\' || code == '"'))
1886  str_buf[len++] = '\\';
1887  str_buf[len++] = (uchar)code;
1888  }else{
1889  if(len && f_pos)
1890  fprintf(fp_out, "%ld: ", pos);
1891  len = 0;
1892  flush_str();
1893  if(f_dtl & DTL_CHAR)
1894  fprintf(fp_out, "\\%02X\n", code);
1895  }
1896  if(!(f_dtl & DTL_CHAR))
1897  fprintf(fp_out, "%s%d\n", SETCHAR, code);
1898  }else{
1899  if(len)
1900  flush_str();
1901  if(f_pos)
1902  fprintf(fp_out, "%ld: ", pos);
1903  if (code < FNT_NUM_0){
1904  mode = cmd128_mode[code - 128];
1905  fprintf(fp_out, "%s", (f_dtl&DTL_CMD)?
1906  c128_name[code-128]:cmd128_name[code-128]);
1907  if(!(mode & 0xf)){
1908  putc('\n', fp_out);
1909  continue;
1910  }
1911  if((mode & 0xf) > 4){
1912  fprintf(fp_out, " %d", read_long(dvi));
1913  mode -= 4;
1914  }
1915  if(mode > 0x30){
1916  code = read_n(dvi, mode & 0xf);
1917 #ifdef PTEXENC
1918  if(f_jstr){
1919  wch = fromDVI(code);
1920  if (is_internalUPTEX()) wch = UCStoUTF8(wch);
1921  imb = 0; memset(mbstr, '\0', 4);
1922  if (BYTE1(wch) != 0) mbstr[imb++]=BYTE1(wch);
1923  if (BYTE2(wch) != 0) mbstr[imb++]=BYTE2(wch);
1924  if (BYTE3(wch) != 0) mbstr[imb++]=BYTE3(wch);
1925  /* always */ mbstr[imb++]=BYTE4(wch);
1926  fprintf(fp_out,
1927  (f_dtl&DTL_CHAR2)?" %u \"":" 0x%x \"", code);
1928  fputs2(mbstr, fp_out);
1929  fprintf(fp_out, "\"\n");
1930  continue;
1931  }
1932 #else
1933  if(f_sjis){
1934  l_code = code & 0xff;
1935  h_code = code >> 8;
1936  if(isjis(h_code) && isjis(l_code)){
1937 #ifdef UNIX
1938  h_code |= 0x80;
1939  l_code |= 0x80;
1940 #else
1941  jis2sjis(&h_code, &l_code);
1942 #endif
1943  fprintf(fp_out,
1944  (f_dtl&DTL_CHAR2)?" %u \"%c%c\"\n":" 0x%x \"%c%c\"\n",
1945  code, h_code, l_code);
1946  continue;
1947  }
1948  }
1949 #endif
1950  fprintf(fp_out, (f_dtl&DTL_CHAR2)?" %u\n":" 0x%x\n", code);
1951  }else
1952  fprintf(fp_out, " %d\n", signed_read_n(dvi, mode & 0xf));
1953  continue;
1954  }else if (code< FNT1){
1955  fprintf(fp_out, (f_dtl&DTL_CMD)?"fn%d\n":"fntnum%d\n", code - FNT_NUM_0);
1956  continue;
1957  }else{
1958  mode = cmd235_mode[code - FNT1];
1960  if (mode >= 0x30)
1961  tmp = (long)read_n(dvi, mode & 0xf);
1962  switch (mode >> 4) {
1963 /*
1964  case (0):
1965 skip_m: while(mode-- > 0)
1966  (void)read_byte(dvi);
1967  break;
1968 */
1969  case (1):
1970  if(!f_ptex || code != EOFNC){
1971  fprintf(stderr, "illegal code(%d)", code);
1972  if((f_dtl&DTL_ILL))
1973  fprintf(stderr, " %d\n", code);
1974  else
1975  Exit(1);
1976  }else
1977  fprintf(fp_out, " %d\n", read_byte(dvi));
1978  continue;
1979 
1980  case (2): /* fntdef */
1981  fprintf(fp_out, " %d", read_n(dvi, mode & 0xf)); /* code */
1982  csum = read_n(dvi, 4);
1983  if(csum)
1984  fprintf(fp_out,
1985  (f_dtl&DTL_FNTDEF)?((f_dtl&DTL_OCT)?" %o%s":" 0%o%s"):
1986  " 0x%X%s", csum, MSG("/c-sum")); /* chksum */
1987  else
1988  fprintf(fp_out, " 0%s", MSG("/c-sum"));
1989  fprintf(fp_out, " %u%s", read_long(dvi), MSG("/s-size")); /* scaled size */
1990  fprintf(fp_out, " %u%s", read_long(dvi), MSG("/d-size")); /* design size */
1991  tmp = (uchar)read_byte(dvi);
1992  fprintf(fp_out, " %d%s", tmp, MSG("/dir")); /* len:directry */
1993  code = (uchar)read_byte(dvi);
1994  fprintf(fp_out, " %d%s '", code, MSG("/name")); /* len:name */
1995  while (tmp-- > 0)
1996  putc(read_byte(dvi), fp_out);
1997  if((f_dtl&DTL_FNTNAME))
1998  fputs("' '", fp_out);
1999  while(code-- > 0)
2000  putc(read_byte(dvi), fp_out);
2001  fputs("'\n", fp_out);
2002  continue;
2003 /*
2004  case (3):
2005  break;
2006 */
2007 
2008  case (4): /* fntnum */
2009  fprintf(fp_out, " %u\n", tmp);
2010  continue;
2011 
2012  case (5): /* specials */
2013  fprintf(fp_out, " %d%s '", tmp, MSG("/len"));
2014  out_string(dvi, fp_out, tmp);
2015  putc('\'', fp_out);
2016  putc('\n', fp_out);
2017  continue;
2018  }
2019  while(tmp-- > 0)
2020  getc(dvi);
2021  }
2022  }
2023  }
2024  if(f_pos)
2025  fprintf(fp_out, "%ld: ", ftell(dvi)-1);
2026  fputs((code==EOP)?"eop\n":"post_post", fp_out);
2027  return ftell(dvi);
2028 }
2029 
2030 
2031 /************************* text -> dvi *************************************/
2032 struct KEY_LIST {
2033  char *name;
2034  short int code;
2035  short int len;
2036 };
2037 
2038 struct KEY_LIST key[] = {
2039  {"bop", BOP, 1},
2040  {"d", DOWN1, 4},
2041  {"dir", EOFNC, 1},
2042  {"down", DOWN1, 4},
2043  {"eop", EOP, 1},
2044  {"f", FNT1, 4},
2045  {"fd", FNT_DEF_1, 4},
2046  {"fn", FNT_NUM_0, 64},
2047  {"fnt", FNT1, 4},
2048  {"fntdef", FNT_DEF_1, 4},
2049  {"fntnum", FNT_NUM_0, 64},
2050  {"nop", NOP, 1},
2051  {"opcode", OPCODE, 1},
2052  {"p", PUT1, 4},
2053  {"pop", POP, 1},
2054  {"post", POST, 1},
2055  {"post_post",POST_POST, 1},
2056  {"pr", PUT_RULE, 1},
2057  {"pre", PRE, 1},
2058  {"push", PUSH, 1},
2059  {"put", PUT1, 4},
2060  {"putrule", PUT_RULE, 1},
2061  {"r", RIGHT1, 4},
2062  {"right", RIGHT1, 4},
2063  {"s", SET1, 4},
2064  {"set", SET1, 4},
2065  {"setchar", SET_CHAR_0,128},
2066  {"setrule", SET_RULE, 1},
2067  {"special", XXX1, 4},
2068  {"sr", SET_RULE, 1},
2069  {"w", W0, 5},
2070  {"x", X0, 5},
2071  {"xxx", XXX1, 4},
2072  {"y", Y0, 5},
2073  {"z", Z0, 5}
2074 };
2075 
2076 void key_swap(int i, int j)
2077 {
2078  char tmp[sizeof(struct KEY_LIST)];
2079 
2080  memcpy(tmp, &key[i], sizeof(struct KEY_LIST));
2081  memcpy(&key[i], &key[j], sizeof(struct KEY_LIST));
2082  memcpy(&key[j], tmp, sizeof(struct KEY_LIST));
2083 }
2084 
2085 void sort_key(void)
2086 {
2087  int i, j;
2088 
2089  for(i = 1; i < sizeof(key)/sizeof(struct KEY_LIST); i++){
2090  if(strcmp(key[i-1].name, key[i].name) > 0){
2091  j = i;
2092  do{
2093  key_swap(j-1, j);
2094  j--;
2095  }while(j >= 1 && strcmp(key[j-1].name, key[j].name) > 0);
2096  }
2097  }
2098 }
2099 
2100 void replace(char *o_name, char *n_name)
2101 {
2102  int i, j, count;
2103  char *s, **cmd;
2104 
2105  if(!strcmp(o_name, SETCHAR)){
2106  SETCHAR = n_name;
2107  count = 1;
2108  }else{
2109  count = 0;
2110  cmd = cmd128_name;
2111  i = sizeof(cmd128_name)/sizeof(char *);
2112 again: while(--i >= 0){
2113  for(j = 0; cmd[i][j] == o_name[j] && o_name[j]; j++);
2114  if(!o_name[j]){
2115  if(!cmd[i][j] || (cmd[i][j] >= '0' && cmd[i][j] <= '9')){
2116  s = malloc(strlen(cmd[i]) + j + 1);
2117  strcpy(s, n_name);
2118  strcat(s, cmd[i]+j);
2119  cmd[i] = s;
2120  count++;
2121  }
2122  }
2123  }
2124  if(cmd == cmd128_name){
2125  cmd = cmd235_name;
2126  i = sizeof(cmd235_name)/sizeof(char *) - 1;
2127  goto again;
2128  }
2129  }
2130  if(!count){
2131  fprintf(stderr, "%s is not a keyword\n", o_name);
2132  exit(1);
2133  }
2134  for(i = sizeof(key)/sizeof(struct KEY_LIST)-1; i >= 0 && strcmp(o_name, key[i].name); i--);
2135  if(i >= 0){
2136  key[i].name = malloc(strlen(n_name)+1);
2137  strcpy(key[i].name, n_name);
2138  sort_key();
2139  }
2140 }
2141 
2143 
2144 int find_key(char *s0)
2145 {
2146  int top, end, pt, num;
2147  char *s, *t;
2148 
2149  top = 0;
2150  end = sizeof(key)/sizeof(struct KEY_LIST)-1;
2151 
2152  while(top <= end){
2153  s = s0;
2154  t = key[pt = (top+end)/2].name;
2155  while(*s == *t && *t){
2156  s++;
2157  t++;
2158  }
2159  if(!*t){
2160  if((num = key[pt].len) == 1){
2161  if(*s <= ' '){
2162  sub_number = 0;
2163  return pt;
2164  }
2165  }else if(*s >= '0' && *s <= '9'){
2166  sub_number = atoi(s);
2167  if(num == 4){
2168  if(sub_number > 0 && sub_number <= 4)
2169  return pt;
2170  }else{
2171  if(sub_number < num)
2172  return pt;
2173  }
2174  }
2175  }
2176  if(*s > *t)
2177  top = pt+1;
2178  else
2179  end = pt-1;
2180  }
2181  return -1;
2182 }
2183 
2184 void write_n(int num, int byte)
2185 {
2186  switch(byte){
2187  case 4:
2188  putc((num>>24) & 0xff, fp_out);
2189  case 3:
2190  putc((num>>16)& 0xff, fp_out);
2191  case 2:
2192  putc((num>>8) & 0xff, fp_out);
2193  case 1:
2194  putc(num & 0xff, fp_out);
2195  }
2196 }
2197 
2198 uchar *get_next(unsigned char *pt)
2199 {
2200  while(*pt > ' ')
2201  pt++;
2202  while(*pt <= ' ' && *pt)
2203  pt++;
2204  return pt;
2205 }
2206 
2207 
2208 uint a2i(unsigned char *s)
2209 {
2210  uint num;
2211 /* strtol(s, &pt, 0) will overflow for unsigned */
2212 
2213  if(!*s)
2214  return 0;
2215  if(*s != '0'){
2216  if(*s == '-' && isdigit(s[1]))
2217  return((uint)0xffffffff - ((uint)atoi((char *)s+1) - 1));
2218  return((uint)atoi((char *)s));
2219  }
2220  if(s[1] == 'x' || s[1] == 'X'){
2221  num = 0;
2222  for(s += 2; is_hex(*s); s++)
2223  num = (num << 4) + hex_to_dig(*s);
2224  return num;
2225  }else{
2226  num = 0;
2227  for(s += 1; is_oct(*s); s++)
2228  num = (num << 3) + *s - '0';
2229  return num;
2230  }
2231 }
2232 
2233 
2235 {
2236  uchar *s;
2237 
2238  for(s = pt; *s && *s != '\''; s++){
2239  if(*s == '\\' && (f_dtl&DTL_STRING)){
2240  if(is_hex(s[1]))
2241  s++;
2242  if(*s)
2243  s++;
2244  }
2245  }
2246  return s - pt;
2247 }
2248 
2249 
2250 void trans2dvi(void)
2251 {
2252  int num, pt, num0, pos0, len;
2253  int code = -1, pos = -1, page = 0, line = 0, f_in = 0, f_proc = 0, stack = 0;
2254  uchar *s, *base;
2255  static char hex[6] = "0x00";
2256 
2257  s = (uchar *)tmp_buf; /* for Warning of compiler */
2258  while(fgets(tmp_buf, COMMON_SIZE, fp_in) != NULL){
2259  if(!line++ && !strncmp(tmp_buf, "variety ", 8)){
2260  if(!(f_dtl&DTL_VARIETY))
2261  f_dtl = 0x0ffff;
2262  continue;
2263  }
2264  base = (uchar *)tmp_buf;
2265  if(f_pos){ /* position: */
2266  if(*base <= ' ')
2267  continue;
2268 skp: while(*base++ > ' ');
2269  }
2270  if(*base < 'a' || *base > 'z'){
2271  if(!f_in){
2272  if(!f_proc && !f_pos && !strncmp(tmp_buf, "0: pre 2 ", 9)){
2273  f_pos = 1;
2274  goto skp;
2275  }
2276  continue;
2277  }else if(*base == '['){ /* PUSH by DTL */
2278  code = PUSH;
2279  goto cmd;
2280  }else if(*base == ']'){ /* POP by DTL */
2281  code = POP;
2282  goto cmd;
2283  }else if(*base == '\\' && (f_dtl&DTL_CHAR)){
2284  if(is_hex(base[1]) && is_hex(base[2])){ /* char \XY by DTL */
2285  if(f_proc != 1){
2286  if(!f_proc)
2287  goto er0;
2288  if(f_proc == 2)
2289  goto er3;
2290  goto er1;
2291  }
2292  if(!f_in)
2293  goto er2;
2294  hex[2] = base[1];
2295  hex[3] = base[2];
2296  putc(a2i((uchar *)hex), fp_out);
2297  }
2298  }else if(*base == '(' && (f_dtl&DTL_CHAR)){ /* char (...) by DTL */
2299  if(f_proc != 1){
2300  if(!f_proc)
2301  goto er0;
2302  if(f_proc == 2)
2303  goto er3;
2304  goto er1;
2305  }
2306  if(!f_in)
2307  goto er2;
2308  for(s = base; *++s != ')' && *s; ){ /* for DTL */
2309  if(*s != '\\')
2310  putc(*s, fp_out);
2311  else{
2312  s++;
2313  if(is_hex(*s) && is_hex(s[1])){
2314  hex[2] = *s;
2315  hex[3] = *s++;
2316  putc(a2i((uchar *)hex), fp_out);
2317  }else
2318  putc(*s, fp_out);
2319  }
2320  }
2321  }
2322  continue;
2323  }
2324  pt = find_key((char *)base);
2325  if(pt < 0){
2326  fprintf(stderr, "No key!\n");
2327  goto err;
2328  }
2329  code = key[pt].code;
2330 cmd: if(!page && code != PRE){
2331 er0: fprintf(stderr, "Need PRE comamnd at the top\n");
2332  goto err;
2333  }
2334  if(f_proc > 2){
2335 er1: fprintf(stderr, "Command after POST_POST\n");
2336  goto err;
2337  }
2338  if(!f_in){
2339 er2: if(code < FNT_DEF_1 && code != BOP){
2340  fprintf(stderr, "This command shoud be after BOP\n");
2341  goto err;
2342  }
2343  }
2344  if(f_proc == 2 && (code < FNT_DEF_1 || code > POST_POST)){
2345 er3: /* POST and PRE will be checked later */
2346  fprintf(stderr, "This command shoud be not be after POST\n");
2347  goto err;
2348  }
2349  switch(code){
2350  case PRE:
2351  if(f_proc){
2352  fprintf(stderr, "Multiple PRE command\n");
2353  goto err;
2354  }
2355  f_proc = 1;
2356  putc(code, fp_out); /* pre */
2357  page++;
2358  s = get_next(base);
2359  code = a2i(s);
2360  putc(code, fp_out); /* id */
2361  for(num=0; num <3; num++){
2362  s = get_next(s);
2363  code = a2i(s);
2364  write_n(code, 4);
2365  }
2366  s = get_next(s);
2367  code = a2i(s);
2368  s = get_next(s) + 1;
2369  if(f_dtl&DTL_EXACT){
2370  len = StrLen(s);
2371  if(len > 255)
2372  fprintf(stderr, "string length is too wrong (%d) in line %d\n%s\n",
2373  len, line, tmp_buf);
2374  else if(code != len)
2375  fprintf(stderr, "string length in [%d:%s]: %d -> %d:\n",
2376  line, tmp_buf, code, len);
2377  }else
2378  len = code;
2379  putc(len, fp_out); /* length of string */
2380 strout: if(len >= COMMON_SIZE/2){
2381  fprintf(stderr, "Too long data: %d\n", len);
2382  Exit(1);
2383  }
2384  while(len-- > 0){
2385  if((f_dtl&DTL_STRING) && *s == '\\'){
2386  s++;
2387  if(is_hex(*s)){
2388  code = hex_to_dig(*s) << 4;
2389  s++;
2390  code += hex_to_dig(*s);
2391  putc(code, fp_out);
2392  continue;
2393  }
2394  }
2395  putc(*s++, fp_out);
2396  }
2397  if(f_debug){
2398  if(*s != '\'' || s[1] > ' '){
2399  fprintf(stderr, "String length is not correct!\n");
2400  goto err;
2401  }
2402  }
2403  break;
2404 
2405  case BOP:
2406  f_in = 1;
2407  pos0 = ftell(fp_out);
2408  putc(code, fp_out);
2409  s = base;
2410  for(num = 0; num < 10; num++){ /* c[] */
2411  s = get_next(s);
2412  write_n(a2i(s), 4);
2413  }
2414  if(f_debug){
2415  num0 = a2i(get_next(s));
2416  if(pos != num0)
2417  fprintf(stderr,
2418  "Address of BOP of page %d: %d -> %d\n",
2419  page-1, num0, pos);
2420  }
2421  write_n(pos, 4); /* position of the former bop */
2422  pos = pos0;
2423  break;
2424 
2425  case FNT_NUM_0:
2426  font_use[sub_number] = 1;
2427  case SET_CHAR_0:
2429  break;
2430 
2431  case EOP:
2432  if(!f_in){
2433  fprintf(stderr, "EOP without BOP\n");
2434  goto err;
2435  }
2436  f_in = 0;
2437  if(stack > 0){
2438  fprintf(stderr, "Stack remains at page %d. It is corrected\n", stack);
2439  while(stack--)
2440  putc(code, fp_out);
2441  }
2442  page++;
2443  putc(code, fp_out);
2444  break;
2445 
2446  case POP:
2447  if(--stack < 0){
2448  fprintf(stderr, "Stack underflow\n");
2449  goto err;
2450  }
2451  putc(code, fp_out);
2452  break;
2453 
2454  case PUSH:
2455  if(++stack > max_stack)
2456  max_stack = stack;
2457  putc(code, fp_out);
2458  break;
2459 
2460  case FNT1:
2461  putc(code+sub_number-1, fp_out);
2462  num = a2i(get_next(base));
2463  if(num >= 0 && num < MAX_FONT)
2464  font_use[num] = 1;
2466  break;
2467 
2468  case PUT1:
2469  case SET1:
2470  case DOWN1:
2471  case RIGHT1:
2472  putc(code+sub_number-1, fp_out);
2474  break;
2475 
2476  case XXX1:
2477  s = get_next(base);
2478  num = a2i(s);
2479  s = get_next(s) + 1;
2480  if(f_dtl&DTL_EXACT){
2481  len = StrLen(s);
2482  if(num != len)
2483  fprintf(stderr, "string length in %d:[%s]: %d -> %d\n",
2484  line, tmp_buf, num, len);
2485  num0 = (len < 0x100)?1:2;
2486  if(sub_number != num0)
2487  fprintf(stderr, "Code is changed at line %d: xxx%d -> xxx%d\n",
2488  line, sub_number, num0);
2489  sub_number = num0;
2490  }else
2491  len = num;
2492  putc(code+sub_number-1, fp_out);
2494  goto strout;
2495 
2496  case EOFNC:
2497  putc(code, fp_out);
2498  sub_number = 1;
2499  goto put_num;
2500 
2501  case W0:
2502  case X0:
2503  case Y0:
2504  case Z0:
2506  if(sub_number)
2507  goto put_num;
2508  break;
2509 
2510  case SET_RULE:
2511  case PUT_RULE:
2512  putc(code, fp_out);
2513  s = get_next(base);
2514  write_n(a2i(s), 4);
2515  s = get_next(s);
2516  write_n(a2i(s), 4);
2517  break;
2518 
2519  case POST:
2520  if(f_in){
2521  fprintf(stderr, "Need EOP before POST\n");
2522  goto err;
2523  }
2524  if(f_proc > 1){
2525  fprintf(stderr, "Multiple POST\n");
2526  goto err;
2527  }
2528  f_proc = 2;
2529  pos0 = ftell(fp_out);
2530  putc(code, fp_out);
2531  s = get_next(base);
2532  if(f_debug){
2533  num0 = a2i(s);
2534  if(pos != num0)
2535  fprintf(stderr,
2536  "Address of BOP of the last page: %d -> %d\n",
2537  num0, pos);
2538  }
2539  write_n(pos, 4); /* position of the last bop */
2540  pos = pos0;
2541  s = get_next(s);
2542  for(num = 5; num-->0; ){
2543  write_n(a2i(s), 4);
2544  s = get_next(s);
2545  }
2546  num0 = a2i(s);
2547  if(max_stack != num0)
2548  fprintf(stderr, "Max stack depth: %d -> %d\n",
2549  num0, max_stack);
2550  write_n(max_stack, 2);
2551  s = get_next(s);
2552  num0 = a2i(s);
2553  if(num0 != --page)
2554  fprintf(stderr, "The number of total pages: %d -> %d\n",
2555  num0, page);
2556  write_n(page, 2);
2557  break;
2558 
2559  case FNT_DEF_1:
2560  s = get_next(base);
2561  num0 = a2i(s);
2562  if(f_dtl & DTL_FNTDFN){
2563  if(num0 >= 0 && num0 < MAX_FONT){
2564  if(f_proc == 2){
2565  if(!font_use[num0]){
2566  fprintf(stderr, "The definition of font %d is deleted\n",
2567  num0);
2568  break;
2569  }else
2570  font_use[num0] = 1;
2571  }
2572  }
2573  }
2574  putc(code+sub_number-1, fp_out);
2575  write_n(num0, sub_number);
2576  s = get_next(s);
2577  for(num = 0; num < 3; num++){ /* checksum/s-size/d-size */
2578  if((f_dtl&DTL_FNTDEF) && !num && (s[1] != 'x' && s[1] != 'X')){
2579  num0 = *(s-1);
2580  *(s-1) = '0';
2581  write_n(a2i(s-1), 4);
2582  *(s-1) = (uchar)num0;
2583  }else
2584  write_n(a2i(s), 4);
2585  s = get_next(s);
2586  }
2587  num = a2i(s);
2588  s = get_next(s); /* directory */
2589  putc(num, fp_out);
2590  code = a2i(s);
2591  s = get_next(s) + 1; /* directory/name */
2592  putc(code, fp_out);
2593  while(num-- > 0)
2594  putc(*s++, fp_out); /* directory */
2595  if((*s == '\'' && s[1] <= ' ') || (f_dtl&DTL_FNTNAME))
2596  s = get_next(s) + 1;
2597  while(code-- > 0)
2598  putc(*s++, fp_out); /* name */
2599  break;
2600 
2601  case POST_POST:
2602  if(f_proc++ != 2){
2603  fprintf(stderr, "Need POST before POST_POST!\n");
2604  goto err;
2605  }
2606  putc(code, fp_out);
2607  s = get_next(base);
2608  write_n(pos, 4); /* position of post */
2609  if(f_debug){
2610  num0 = a2i(s);
2611  if(pos != num0)
2612  fprintf(stderr, "Address of POST: %d -> %d\n",
2613  num0, pos);
2614  }
2615  for(num = 5; num-- > 0; ){
2616  s = get_next(s);
2617  code = a2i(s);
2618  if(num == 4){
2619  if(code != 2 && code != 3){
2620  fprintf(stderr, "Last id (%d) should be 2 or 3\n", code);
2621  goto err;
2622  }
2623  }else{
2624  if(code != END_DVI)
2625  fprintf(stderr, "Last code: %d -> %d\n", code, END_DVI);
2626  code = END_DVI;
2627  }
2628  putc(code, fp_out);
2629  }
2630  num = ftell(fp_out);
2631  while(num++ & 3)
2632  putc((uchar)END_DVI, fp_out);
2633  break;
2634 
2635  case OPCODE:
2636  putc(a2i(get_next(s)), fp_out);
2637  break;
2638 
2639  default:
2640 err: fprintf(stderr, "Error(line %d, code %d): %s\n", line, code, tmp_buf);
2641  Exit(1);
2642  }
2643  }
2644  num = ftell(fp_out);
2645  fprintf(stderr, "Write %d byte (%d page): %s\n", num, page,
2646  (fp_out==stdout)?"(stdout)":outfile);
2647  fclose(fp_in);
2648  fclose(fp_out);
2649  fp_in = fp_out = NULL;
2650 }
int code
Definition: aftopl.c:52
#define count(a)
Definition: aptex-macros.h:781
#define name
#define mode
Definition: aptex-macros.h:510
#define n
Definition: t4ht.c:1290
#define special
Definition: devnag.c:330
FILE * f_in
Definition: devnag.c:355
int mkstemp()
int h
Definition: dviconv.c:9
#define hex(c)
Definition: kanji.c:63
#define fopen
Definition: xxstdio.h:21
#define fseek
Definition: xxstdio.h:30
#define fgets
Definition: xxstdio.h:29
#define ftell
Definition: xxstdio.h:31
#define skip(p, c)
Definition: ptexmac.h:70
printlisttype * lastpage
Definition: dvi2tty.c:97
char * strncpy()
int strcmp()
Definition: coll.cpp:143
char * strcpy()
#define BUG_ADDRESS
Definition: dvidvi.c:40
struct dvi_data * dvi
char * out_pages
Definition: dvispc.c:255
int top_add
Definition: dvispc.c:1523
#define MAX_COLOR
Definition: dvispc.c:203
int num_add
Definition: dvispc.c:1522
int f_background
Definition: dvispc.c:261
#define POST_POST
Definition: dvispc.c:196
#define POP
Definition: dvispc.c:179
#define Y0
Definition: dvispc.c:186
FILE * fp_out
Definition: dvispc.c:291
char annot_buf[8 *512]
Definition: dvispc.c:287
char pdf_bgcolor_prev[128]
Definition: dvispc.c:263
unsigned int a2i(unsigned char *s)
Definition: dvispc.c:2208
void write_long(int x, FILE *fp)
Definition: dvispc.c:393
#define ANNOT_BUF_SIZE
Definition: dvispc.c:206
int f_debug
Definition: dvispc.c:235
int pdf_color_depth
Definition: dvispc.c:276
char tpic_pn_prev[128]
Definition: dvispc.c:266
FILE * fp_in
Definition: dvispc.c:290
char * color_pt[512]
Definition: dvispc.c:275
#define DTL_FNTDEF
Definition: dvispc.c:214
void replace(char *, char *)
Definition: dvispc.c:2100
int signed_read_n(FILE *fp, int n)
Definition: dvispc.c:360
unsigned int interpret(FILE *)
Definition: dvispc.c:1183
void flush_str(void)
Definition: dvispc.c:1768
#define DTL_FORM
Definition: dvispc.c:222
#define PIXEL
Definition: dvispc.c:122
int color_under
Definition: dvispc.c:274
#define write_byte(x, y)
Definition: dvispc.c:325
void write_sp_nodebug(FILE *fp, char *sp)
Definition: dvispc.c:828
#define MAX_FONT
Definition: dvispc.c:208
#define COMMON_SIZE
Definition: dvispc.c:207
#define PRE
Definition: dvispc.c:194
char outfile[0x200]
Definition: dvispc.c:309
void sp_pdf_ecolor(char *sp)
Definition: dvispc.c:1468
void jis2sjis(int *h, int *l)
Definition: dvispc.c:1782
char str_buf[0x60]
Definition: dvispc.c:1765
int main(int argc, char **argv)
Definition: dvispc.c:481
void read_post(struct DVIFILE_INFO_REC *dvi)
Definition: dvispc.c:1525
void write_sp(FILE *fp, char *sp)
Definition: dvispc.c:808
int read_long(FILE *fp)
Definition: dvispc.c:402
void usage(int ex)
Definition: dvispc.c:429
int f_ptex
Definition: dvispc.c:251
void Exit(int code)
Definition: dvispc.c:374
void key_swap(int i, int j)
Definition: dvispc.c:2076
struct DVIFILE_INFO_REC dvi_info
int pdf_annot_depth
Definition: dvispc.c:280
#define DTL_STRING
Definition: dvispc.c:210
#define PUSH
Definition: dvispc.c:178
void sort_key(void)
Definition: dvispc.c:2085
#define DTL_ILL
Definition: dvispc.c:216
#define Z0
Definition: dvispc.c:188
#define END_DVI
Definition: dvispc.c:168
#define FNT1
Definition: dvispc.c:191
#define SET_CHAR_0
Definition: dvispc.c:170
static char * c235_name[]
Definition: dvispc.c:1734
int f_pos
Definition: dvispc.c:248
void transpost(FILE *)
Definition: dvispc.c:1833
#define DTL_CHAR2
Definition: dvispc.c:212
char infile[0x200]
Definition: dvispc.c:308
#define isjis(c)
Definition: dvispc.c:317
#define MAX_ANNOT
Definition: dvispc.c:205
#define SIZE_PARA
Definition: dvispc.c:123
#define DTL_CHAR
Definition: dvispc.c:211
int f_needs_corr
Definition: dvispc.c:285
#define is_oct(c)
Definition: dvispc.c:320
#define DTL_VARIETY
Definition: dvispc.c:221
#define W0
Definition: dvispc.c:181
#define SCALED_PT
Definition: dvispc.c:125
static char * cmd235_name[]
Definition: dvispc.c:1659
int strsubcmp_n(char *s, char *t)
Definition: dvispc.c:1298
void sp_color(char *sp)
Definition: dvispc.c:1404
char background[128]
Definition: dvispc.c:259
#define DTL_FNTDFN
Definition: dvispc.c:220
#define NOP
Definition: dvispc.c:175
#define READ_BINARY
Definition: dvispc.c:116
int f_mode
Definition: dvispc.c:229
#define WRITE_TEXT
Definition: dvispc.c:118
#define EOP
Definition: dvispc.c:177
int pdf_annot_under
Definition: dvispc.c:282
unsigned char * get_next(unsigned char *pt)
Definition: dvispc.c:2198
void translate(struct DVIFILE_INFO_REC *dvi, struct DIMENSION_REC *dim)
Definition: dvispc.c:839
#define ID
Definition: dvispc.c:166
#define RIGHT1
Definition: dvispc.c:180
#define read_byte(x)
Definition: dvispc.c:324
int f_overwrite
Definition: dvispc.c:236
#define COLOR_BUF_SIZE
Definition: dvispc.c:204
#define DVIFILE_INFO
Definition: dvispc.c:293
char tpic_pn[128]
Definition: dvispc.c:265
#define WRITE_BINARY
Definition: dvispc.c:117
void write_n(int num, int byte)
Definition: dvispc.c:2184
#define X0
Definition: dvispc.c:183
void sp_pdf_bann(char *sp)
Definition: dvispc.c:1484
#define DTL_PAGE
Definition: dvispc.c:217
#define BOP
Definition: dvispc.c:176
char tmp_buf[0x4000]
Definition: dvispc.c:289
#define MAX_STR
Definition: dvispc.c:1763
#define IDP
Definition: dvispc.c:167
int find_key(char *s0)
Definition: dvispc.c:2144
int f_pdf_bgcolor
Definition: dvispc.c:264
static char * cmd128_name[]
Definition: dvispc.c:1612
#define read_short(x)
Definition: dvispc.c:326
struct KEY_LIST key[]
Definition: dvispc.c:2038
#define EOFNC
Definition: dvispc.c:198
@ EXE2MODIFY
Definition: dvispc.c:226
@ EXE2DVI
Definition: dvispc.c:226
@ EXE2TEXT
Definition: dvispc.c:226
@ EXE2SPECIAL
Definition: dvispc.c:226
@ EXE2CHECK
Definition: dvispc.c:226
int f_backup
Definition: dvispc.c:237
int read_n(FILE *fp, int n)
Definition: dvispc.c:346
char color_buf[512 *32]
Definition: dvispc.c:286
#define FNT_DEF_1
Definition: dvispc.c:193
#define FNT_NUM_0
Definition: dvispc.c:190
int pdf_color_depth_max
Definition: dvispc.c:277
char * pdf_color_pt[512]
Definition: dvispc.c:279
int f_sjis
Definition: dvispc.c:245
int f_pn
Definition: dvispc.c:267
struct DIMENSION_REC dvi_dim
#define SET1
Definition: dvispc.c:171
unsigned int work(FILE *)
Definition: dvispc.c:1858
#define DIMENSION
Definition: dvispc.c:127
int pdf_color_under
Definition: dvispc.c:278
int strsubcmp(char *s, char *t)
Definition: dvispc.c:1286
unsigned int s_work(FILE *)
Definition: dvispc.c:1309
#define StrCmp
Definition: dvispc.c:119
#define uchar
Definition: dvispc.c:101
#define POST
Definition: dvispc.c:195
#define DTL_OCT
Definition: dvispc.c:218
#define MAX_LEN
Definition: dvispc.c:202
#define DTL_EXACT
Definition: dvispc.c:219
int pdf_annot_depth_max
Definition: dvispc.c:281
static char * SETCHAR
Definition: dvispc.c:1610
void error(char *msg)
Definition: dvispc.c:386
const int AdID
Definition: dvispc.c:312
char background_prev[128]
Definition: dvispc.c:260
#define PUT_RULE
Definition: dvispc.c:174
void make_page_index(struct DVIFILE_INFO_REC *dvi, struct DIMENSION_REC *dim)
Definition: dvispc.c:1155
int total_book_page
Definition: dvispc.c:256
void sp_pdf_bcolor(char *sp)
Definition: dvispc.c:1441
int color_depth_max
Definition: dvispc.c:273
#define XXX1
Definition: dvispc.c:192
int color_depth
Definition: dvispc.c:272
#define MAX_PATH
Definition: dvispc.c:163
#define OPCODE
Definition: dvispc.c:197
static unsigned char cmd128_mode[]
Definition: dvispc.c:1209
#define PUT1
Definition: dvispc.c:173
#define DOWN1
Definition: dvispc.c:185
int max_stack
Definition: dvispc.c:254
int f_prescan
Definition: dvispc.c:252
void sp_pdf_eann(char *sp)
Definition: dvispc.c:1509
#define DTL_FNTNAME
Definition: dvispc.c:215
int f_dtl
Definition: dvispc.c:223
void out_string(FILE *in, FILE *out, int len)
Definition: dvispc.c:1794
#define is_hex(c)
Definition: dvispc.c:319
#define MSG(x)
Definition: dvispc.c:323
int f_book
Definition: dvispc.c:249
#define hex_to_dig(c)
Definition: dvispc.c:322
int read_word(FILE *fp)
Definition: dvispc.c:420
int sub_number
Definition: dvispc.c:2142
char pdf_bgcolor[128]
Definition: dvispc.c:262
static unsigned char cmd235_mode[]
Definition: dvispc.c:1257
#define SET_RULE
Definition: dvispc.c:172
static char * c128_name[]
Definition: dvispc.c:1687
int f_last
Definition: dvispc.c:253
int StrLen(unsigned char *pt)
Definition: dvispc.c:2234
void trans2dvi(void)
Definition: dvispc.c:2250
#define READ_TEXT
Definition: dvispc.c:115
char * pdf_annot_pt[8]
Definition: dvispc.c:283
void write_word(int x, FILE *fp)
Definition: dvispc.c:413
#define DTL_CMD
Definition: dvispc.c:213
void transpre(FILE *)
Definition: dvispc.c:1813
int len
Definition: dvispc.c:1766
char font_use[256]
Definition: dvispc.c:310
long int flag
Definition: f2c.h:53
static void
Definition: fpif.c:118
int fnum
Definition: gen-fib.c:35
#define s
Definition: afcover.h:80
#define t
Definition: afcover.h:96
@ VERSION
Definition: genrb.cpp:69
#define d(n)
Definition: gpos-common.c:151
int base
Definition: gsftopk.c:1502
#define memcpy(d, s, n)
Definition: gsftopk.c:64
FILE * out
Definition: hbf2gf.c:286
unsigned long dim
Definition: hpcdtoppm.c:62
#define putc
Definition: jbib.h:20
#define SEEK_SET
Definition: jmemansi.c:26
unsigned char uchar
Definition: unzcrash.c:37
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
#define SEEK_CUR
Definition: ftzconf.h:250
#define SEEK_END
Definition: ftzconf.h:251
void exit()
#define EOF
Definition: afmparse.c:59
long Long
Definition: ftraster.c:311
int int double double double char double char * top
Definition: gdfx.h:19
int atoi(const char *)
#define TL_VERSION
Definition: config.h:131
int num
Definition: disdvi.c:621
#define O_BINARY
Definition: config.h:393
#define unlink(file)
Definition: config.h:413
char * strstr()
#define fclose
Definition: debug.h:100
#define getc
Definition: line.c:39
#define fileno
Definition: win32lib.h:72
#define close
Definition: win32lib.h:63
#define umask
Definition: win32lib.h:101
#define isatty
Definition: win32lib.h:80
#define fputs
Definition: mendex.h:67
#define fprintf
Definition: mendex.h:64
long UCStoUTF8(long ucs)
Definition: unicode.c:99
#define BYTE4(x)
Definition: unicode.h:27
#define BYTE2(x)
Definition: unicode.h:25
#define BYTE3(x)
Definition: unicode.h:26
#define BYTE1(x)
Definition: unicode.h:24
boolean is_internalUPTEX(void)
Definition: ptexenc.c:212
void enable_UPTEX(boolean enable)
Definition: ptexenc.c:149
boolean set_enc_string(const_string file_str, const_string internal_str)
Definition: ptexenc.c:185
int fputs2(const char *s, FILE *fp)
Definition: ptexenc.c:529
long fromDVI(long kcode)
Definition: ptexenc.c:311
#define malloc
Definition: alloca.c:91
#define put_num(t, n)
Definition: writettf.h:69
ushort mode_t
Definition: types.h:80
unsigned int uint
Definition: types.h:72
int setmode()
int stat(const char *path, struct stat *sbuf)
int strncmp()
#define sprintf
Definition: snprintf.c:44
#define isdigit(c)
Definition: snprintf.c:177
const int * pos
Definition: combiners.h:905
#define cmd(arg)
Definition: mitsu.h:44
@ err
Definition: mtxline.h:24
float x
Definition: cordic.py:15
static struct Point current
Definition: picttoppm.c:134
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld endif[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if
#define fp
logical rename
Definition: pmxab.c:724
static int size
Definition: ppmlabel.c:24
static int offset
Definition: ppmtogif.c:642
bstring c int memset(void *s, int c, int length)
#define mask(n)
Definition: lbitlib.c:93
#define same(n, f, k)
Definition: pdffont.c:103
#define flag
Definition: round_prec.c:45
static void strout(char *s)
Definition: squeeze.c:57
static FILE * in
Definition: squeeze.c:36
int mag
Definition: dd.h:342
int * page_index
Definition: dvispc.c:144
int max_nombre_page
Definition: dd.h:373
int text_width
Definition: dd.h:339
int total_page
Definition: dd.h:367
int size_para
Definition: dvispc.c:140
int end_page
Definition: dd.h:370
int start_page
Definition: dd.h:370
int text_height
Definition: dd.h:339
char * file_name
Definition: dd.h:309
long num
Definition: dd.h:311
long post
Definition: dd.h:310
int stack_depth
Definition: dd.h:313
FILE * file_ptr
Definition: dd.h:308
long u
Definition: dd.h:312
long mag
Definition: dd.h:311
int total_page
Definition: dd.h:314
short int len
Definition: dvispc.c:2035
short int code
Definition: dvispc.c:2034
char * name
Definition: dvispc.c:2033
Definition: dd.h:287
Definition: tables.h:434
Definition: inftrees.h:24
uint32_t num
Definition: dvipng.h:130
uint32_t mag
Definition: dvipng.h:130
uint32_t den
Definition: dvipng.h:130
Definition: bdf.c:133
Definition: texview.c:48
Definition: mendex.h:14
Definition: spc_misc.c:56
Definition: dvips.h:235
#define FILE
Definition: t1stdio.h:34
ch
Definition: t4ht.c:1443
int j
Definition: t4ht.c:1589
*job_name strlen((char *) job_name) - 4)
page
Definition: tex4ht.c:3916
#define sp
Definition: stack.c:11
#define stack
Definition: stack.c:10
#define s0
Definition: tokst.h:45
PATTERN * pt
Definition: vlna.c:74
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
#define end(cp)
Definition: zic.c:71