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)  

main.c
Go to the documentation of this file.
1 /* main.c - LaTeX to RTF conversion program
2 
3 Copyright (C) 1995-2002 The Free Software Foundation
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 This file is available from http://sourceforge.net/projects/latex2rtf/
20 
21 Authors:
22  1995 Fernando Dorner, Andreas Granzer, Freidrich Polzer, Gerhard Trisko
23  1995-1997 Ralf Schlatterbeck
24  1998-2000 Georg Lehner
25  2001-2002 Scott Prahl
26 */
27 
28 #include <stdio.h>
29 #include <ctype.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <errno.h>
34 #include "main.h"
35 #include "mygetopt.h"
36 #include "convert.h"
37 #include "commands.h"
38 #include "chars.h"
39 #include "l2r_fonts.h"
40 #include "stack.h"
41 #include "direct.h"
42 #include "ignore.h"
43 #include "version.h"
44 #include "funct1.h"
45 #include "cfg.h"
46 #include "encode.h"
47 #include "util.h"
48 #include "parser.h"
49 #include "lengths.h"
50 #include "counters.h"
51 #include "preamble.h"
52 #include "xref.h"
53 
54 FILE *fRtf = NULL; /* file pointer to RTF file */
55 char *g_tex_name = NULL;
56 char *g_rtf_name = NULL;
57 char *g_aux_name = NULL;
58 char *g_bbl_name = NULL;
59 char *g_home_dir = NULL;
60 
61 /*** interpret comment lines that follow the '%' with this string ***/
62 const char * InterpretCommentString = "latex2rtf:";
63 
64 char *progname; /* name of the executable file */
65 bool GermanMode = FALSE; /* support germanstyle */
66 bool FrenchMode = FALSE; /* support frenchstyle */
67 bool RussianMode = FALSE; /* support russianstyle */
68 bool CzechMode = FALSE; /* support czech */
69 
70 char g_charset_encoding_name[20] = "cp1252";
72 
73 bool twoside = FALSE;
75 bool g_little_endian = FALSE; /* set properly in main() */
76 int g_dots_per_inch = 300;
77 
78 bool pagenumbering = TRUE; /* by default use plain style */
80 
81 bool g_processing_preamble = TRUE; /* flag set until \begin{document} */
82 bool g_processing_figure = FALSE; /* flag, set for figures and not tables */
83 bool g_processing_eqnarray = FALSE; /* flag set when in an eqnarry */
86 
90 bool g_aux_file_missing = FALSE; /* assume that it exists */
91 
94 
97 
103 char *g_tmp_path = NULL;
104 char *g_preamble = NULL;
105 char g_field_separator = ',';
107 
113 
114 double g_png_equation_scale=1.22;
115 double g_png_figure_scale=1.35;
117 
118 int indent = 0;
119 char alignment = JUSTIFIED; /* default for justified: */
123 static void OpenRtfFile(char *filename, FILE ** f);
124 static void CloseRtf(FILE ** f);
125 static void ConvertLatexPreamble(void);
126 static void InitializeLatexLengths(void);
127 static void SetEndianness(void);
128 static void ConvertWholeDocument(void);
129 static void print_usage(void);
130 static void print_version(void);
131 #ifdef KPATHSEA
132 #include <kpathsea/kpathsea.h>
133 #endif
134 
135 int main(int argc, char **argv)
136 {
137  int c,x;
138  char *p;
139  char *basename = NULL;
140  double xx;
141 
142 #ifdef KPATHSEA
143  kpse_set_program_name(argv[0], NULL);
145 #else
146  progname = argv[0];
147 #endif
148  SetEndianness();
149  InitializeStack();
151  while ((c = getopt(argc, argv, "lhpvFSWZ:o:a:b:d:f:i:s:C:D:M:P:T:")) != EOF) {
152  switch (c) {
153  case 'a':
154  g_aux_name = optarg;
155  break;
156  case 'b':
157  g_bbl_name = optarg;
158  break;
159  case 'd':
160  g_verbosity_level = *optarg - '0';
161  if (g_verbosity_level < 0 || g_verbosity_level > 7) {
162  diagnostics(WARNING__, "debug level (-d# option) must be 0-7");
163  print_usage();
164  }
165  break;
166  case 'f':
167  sscanf(optarg, "%d", &x);
168  diagnostics(2, "Field option = %s x=%d",optarg,x);
169  g_fields_use_EQ = (x & 1) ? TRUE : FALSE;
170  g_fields_use_REF = (x & 2) ? TRUE : FALSE;
171  break;
172  case 'i':
174  break;
175  case 'l':
176  setPackageBabel("latin1");
177  break;
178  case 'o':
180  break;
181  case 'p':
183  break;
184  case 'v':
185  print_version();
186  return (0);
187  case 'C':
189  break;
190  case 'D':
191  sscanf(optarg, "%d", &g_dots_per_inch);
192  if (g_dots_per_inch < 25 || g_dots_per_inch >600)
193  fprintf(stderr, "Dots per inch must be between 25 and 600 dpi\n");
194  break;
195  case 'F':
197  break;
198  case 'M':
199  sscanf(optarg, "%d", &x);
200  diagnostics(2, "Math option = %s x=%d",optarg,x);
201  g_equation_display_rtf = (x & 1) ? TRUE : FALSE;
202  g_equation_inline_rtf = (x & 2) ? TRUE : FALSE;
204  g_equation_inline_bitmap = (x & 8) ? TRUE : FALSE;
205  g_equation_comment = (x & 16)? TRUE : FALSE;
206  diagnostics(2, "Math option g_equation_display_rtf = %d",g_equation_display_rtf);
207  diagnostics(2, "Math option g_equation_inline_rtf = %d",g_equation_inline_rtf);
208  diagnostics(2, "Math option g_equation_display_bitmap = %d",g_equation_display_bitmap);
209  diagnostics(2, "Math option g_equation_inline_bitmap = %d",g_equation_inline_bitmap);
210  diagnostics(2, "Math option g_equation_comment = %d",g_equation_comment);
215  break;
216 
217  case 'P': /* -P path/to/cfg:path/to/script or -P path/to/cfg or -P :path/to/script */
218  p=strchr(optarg,':');
219  if (p) {*p='\0';g_script_path = strdup(p+1);}
221  diagnostics(2, "cfg=%s, script=%s",g_config_path,g_script_path);
222  break;
223  case 's':
224  if (optarg && optarg[0]=='e') {
225  if(sscanf(optarg,"e%lf",&xx)==1 && xx>0)
227  else
228  diagnostics(WARNING__, "Equation scale (-se #) is not positive, ignoring");
229  }
230  if (optarg && optarg[0]=='f') {
231  if(sscanf(optarg,"f%lf",&xx)==1 && xx>0)
233  else
234  diagnostics(WARNING__, "Figure scale (-sf #) is not positive, ignoring");
235  }
236  break;
237  case 'S':
238  g_field_separator = ';';
239  break;
240  case 'T':
242  break;
243  case 'W':
245  break;
246  case 'Z':
248  g_safety_braces = *optarg - '0';
249  if (g_safety_braces < 0 || g_safety_braces > 9) {
250  diagnostics(WARNING__, "Number of safety braces (-Z#) must be 0-9");
251  print_usage();
252  }
253  break;
254 
255  case 'h':
256  case '?':
257  default:
258  print_usage();
259  }
260  }
261 
262  argc -= optind;
263  argv += optind;
264 
265  if (argc > 1) {
266  diagnostics(WARNING__, "Only a single file can be processed at a time");
267  diagnostics(ERROR, " Type \"latex2rtf -h\" for help");
268  }
269 
270 /* Parse filename. Extract directory if possible. Beware of stdin cases */
271 
272  if (argc == 1 && strcmp(*argv,"-")!=0) { /* filename exists and != "-" */
273  char *s, *t;
274 
275  basename = strdup(*argv); /* parse filename */
277  if (s != NULL) {
278  g_home_dir = strdup(basename); /* parse /tmp/file.tex */
279  t = strdup(s+1);
280  free(basename);
281  basename = t; /* basename = file.tex */
283  *(s+1) = '\0'; /* g_home_dir = /tmp/ */
284  }
285 
286  t = strstr(basename, ".ltx"); /* remove .ltx if present */
287  if (t != NULL) {
288  *t = '\0';
290 
291  } else {
292 
293  t = strstr(basename, ".tex"); /* remove .tex if present */
294  if (t != NULL)
295  *t = '\0';
296 
298  }
299 
300  if (g_rtf_name==NULL)
302  }
303 
304  if (g_aux_name == NULL && basename != NULL)
306 
307  if (g_bbl_name == NULL && basename != NULL)
309 
310  if (basename) {
311  diagnostics(3, "latex filename is <%s>", g_tex_name);
312  diagnostics(3, " rtf filename is <%s>", g_rtf_name);
313  diagnostics(3, " aux filename is <%s>", g_aux_name);
314  diagnostics(3, " bbl filename is <%s>", g_bbl_name);
315  diagnostics(3, "home directory is <%s>", (g_home_dir) ? g_home_dir : "");
316  }
317 
318  ReadCfg();
319 
320  if (PushSource(g_tex_name, NULL)==0) {
322 
325 
327  PopSource();
328  CloseRtf(&fRtf);
329  printf("\n");
330 /* debug_malloc();*/
331 
332  return 0;
333  } else {
334  printf("\n");
335  return 1;
336  }
337 }
338 
339 static void
341 /*
342 purpose : Figure out endianness of machine. Needed for graphics support
343 */
344 {
345  unsigned int endian_test = (unsigned int) 0xaabbccdd;
346  unsigned char endian_test_char = *(unsigned char *)&endian_test;
347 
348  if (endian_test_char == 0xdd)
350 }
351 
352 
353 static void
355 {
356  char * body, *sec_head, *sec_head2, *label;
357  char t[] = "\\begin{document}";
358 
359  PushEnvironment(DOCUMENT); /* because we use ConvertString in preamble.c */
363  WriteRtfHeader();
364  ConvertString(t);
365 
367  getSection(&body,&sec_head,&label);
368 
369  diagnostics(2,"*******************\nbody=%s",(body) ? body : "<empty>");
370  diagnostics(2,"*******************\nsec_head=%s",(sec_head) ? sec_head : "<none>");
371  diagnostics(2,"*******************\nlabel=%s",(g_section_label) ? g_section_label : "<none>");
373  free(body);
374  if (label) free(label);
375 
376  while(sec_head) {
377  getSection(&body,&sec_head2,&g_section_label);
378  label = ExtractLabelTag(sec_head);
379  if (label) {
382  }
383  diagnostics(2,"\n========this section head==========\n%s",(sec_head)?sec_head:"<none>");
384  diagnostics(2,"\n============ label ================\nlabel=%s",(g_section_label) ? g_section_label : "<none>");
385  diagnostics(2,"\n==============body=================\n%s\n=========end body=================",(body) ? body : "<empty>");
386  diagnostics(2,"\n========next section head==========\n%s",(sec_head2) ? sec_head2 : "<none>");
387  ConvertString(sec_head);
389  free(body);
390  free(sec_head);
391  sec_head = sec_head2;
392  }
393 }
394 
395 static void
397 {
398  fprintf(stdout, "latex2rtf %s\n\n", Version);
399  fprintf(stdout, "Copyright (C) 2002 Free Software Foundation, Inc.\n");
400  fprintf(stdout, "This is free software; see the source for copying conditions. There is NO\n");
401  fprintf(stdout, "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
402  fprintf(stdout, "Written by Prahl, Lehner, Granzer, Dorner, Polzer, Trisko, Schlatterbeck.\n");
403 
404 /* fprintf(stdout, "RTFPATH = '%s'\n", getenv("RTFPATH"));*/
405 }
406 
407 static void
409 {
410  char *s;
411  fprintf(stdout, "`%s' converts text files in LaTeX format to rich text format (RTF).\n\n",progname);
412  fprintf(stdout, "Usage: %s [options] input[.tex]\n\n", progname);
413  fprintf(stdout, "Options:\n");
414  fprintf(stdout, " -a auxfile use LaTeX auxfile rather than input.aux\n");
415  fprintf(stdout, " -b bblfile use BibTex bblfile rather than input.bbl)\n");
416  fprintf(stdout, " -C codepage latex encoding charset (latin1, cp850, raw, etc.)\n");
417  fprintf(stdout, " -d level debugging output (level is 0-6)\n");
418  fprintf(stdout, " -f# field handling\n");
419  fprintf(stdout, " -f0 do not use fields\n");
420  fprintf(stdout, " -f1 use fields for equations but not \\ref{} & \\cite{}\n");
421  fprintf(stdout, " -f2 use fields for \\cite{} & \\ref{}, but not equations\n");
422  fprintf(stdout, " -f3 use fields when possible (default)\n");
423  fprintf(stdout, " -F use LaTeX to convert all figures to bitmaps\n");
424  fprintf(stdout, " -D dpi number of dots per inch for bitmaps\n");
425  fprintf(stdout, " -h display help\n");
426  fprintf(stdout, " -i language idiom or language (e.g., german, french)\n");
427  fprintf(stdout, " -l use latin1 encoding (default)\n");
428  fprintf(stdout, " -M# math equation handling\n");
429  fprintf(stdout, " -M1 displayed equations to RTF\n");
430  fprintf(stdout, " -M2 inline equations to RTF\n");
431  fprintf(stdout, " -M3 inline and displayed equations to RTF (default)\n");
432  fprintf(stdout, " -M4 displayed equations to bitmap\n");
433  fprintf(stdout, " -M6 inline equations to RTF and displayed equations to bitmaps\n");
434  fprintf(stdout, " -M8 inline equations to bitmap\n");
435  fprintf(stdout, " -M12 inline and displayed equations to bitmaps\n");
436  fprintf(stdout, " -M16 insert Word comment field that the original equation text\n");
437  fprintf(stdout, " -o outputfile file for RTF output\n");
438  fprintf(stdout, " -p option to avoid bug in Word for some equations\n");
439  fprintf(stdout, " -P path paths to *.cfg & latex2png\n");
440  fprintf(stdout, " -S use ';' to separate args in RTF fields\n");
441  fprintf(stdout, " -se# scale factor for bitmap equations\n");
442  fprintf(stdout, " -sf# scale factor for bitmap figures\n");
443  fprintf(stdout, " -T /path/to/tmp temporary directory\n");
444  fprintf(stdout, " -v version information\n");
445  fprintf(stdout, " -V version information\n");
446  fprintf(stdout, " -W include warnings in RTF\n");
447  fprintf(stdout, " -Z# add # of '}'s at end of rtf file (# is 0-9)\n\n");
448  fprintf(stdout, "Examples:\n");
449  fprintf(stdout, " latex2rtf foo convert foo.tex to foo.rtf\n");
450  fprintf(stdout, " latex2rtf <foo >foo.RTF convert foo to foo.RTF\n");
451  fprintf(stdout, " latex2rtf -P ./cfg/:./scripts/ foo use alternate cfg and latex2png files\n");
452  fprintf(stdout, " latex2rtf -M12 foo replace equations with bitmaps\n");
453  fprintf(stdout, " latex2rtf -i russian foo assume russian tex conventions\n");
454  fprintf(stdout, " latex2rtf -C raw foo retain font encoding in rtf file\n");
455  fprintf(stdout, " latex2rtf -f0 foo create foo.rtf without fields\n");
456  fprintf(stdout, " latex2rtf -d4 foo lots of debugging information\n\n");
457  fprintf(stdout, "Report bugs to <latex2rtf-developers@lists.sourceforge.net>\n\n");
458  fprintf(stdout, "$RTFPATH designates the directory for configuration files (*.cfg)\n");
459  s=getenv("RTFPATH");
460  fprintf(stdout, "$RTFPATH = '%s'\n\n", (s) ? s : "not defined");
461  s=CFGDIR;
462  fprintf(stdout, "CFGDIR compiled-in directory for configuration files (*.cfg)\n");
463  fprintf(stdout, "CFGDIR = '%s'\n\n", (s) ? s : "not defined");
464  fprintf(stdout, "latex2rtf %s\n", Version);
465  exit(1);
466 }
467 
468 void
469 diagnostics(int level, char *format,...)
470 /****************************************************************************
471 purpose: Writes the message to stderr depending on debugging level
472  ****************************************************************************/
473 {
474  char buffer[512], *buff_ptr;
475  va_list apf;
476  int i,linenumber, iEnvCount;
477  char *input;
478 
479  buff_ptr = buffer;
480 
481  va_start(apf, format);
482 
483  if (level <= g_verbosity_level) {
484 
488 
489  switch (level) {
490  case 0:
491  fprintf(stderr, "\nError! line=%d ", linenumber);
492  break;
493  case 1:
494  fprintf(stderr, "\nWarning line=%d ", linenumber);
495  if (g_RTF_warnings) {
496  vsprintf(buffer, format, apf);
497  fprintRTF("{\\plain\\cf2 [latex2rtf:");
498  while (*buff_ptr){putRtfChar(*buff_ptr);buff_ptr++;}
499  fprintRTF("]}");
500  }
501  break;
502  case 2:
503  case 3:
504  case 4:
505  case 5:
506  case 6:
507  fprintf(stderr, "\n%s %4d rec=%d ", input, linenumber, RecursionLevel);
508  for (i=0; i<BraceLevel; i++)
509  fprintf(stderr, "{");
510  for (i=8; i>BraceLevel; i--)
511  fprintf(stderr, " ");
512 
513  for (i=0; i<RecursionLevel; i++)
514  fprintf(stderr, " ");
515  break;
516  default:
517  fprintf(stderr, "\nline=%d ", linenumber);
518  break;
519  }
520  vfprintf(stderr, format, apf);
521  }
522  va_end(apf);
523 
524  if (level == 0) {
525  fprintf(stderr, "\n");
526  fflush(stderr);
527  if (fRtf) {
528  fflush(fRtf);
529  CloseRtf(&fRtf);
530  }
532  }
533 }
534 
535 static void
537 {
538  /* Default Page Sizes */
539  setLength("pageheight", 795*20);
540  setLength("hoffset", 0*20);
541  setLength("oddsidemargin",62*20);
542  setLength("headheight", 12*20);
543  setLength("textheight", 550*20);
544  setLength("footskip", 30*20);
545  setLength("marginparpush", 5*20);
546 
547  setLength("pagewidth", 614*20);
548  setLength("voffset", 0*20);
549  setLength("topmargin", 18*20);
550  setLength("headsep", 25*20);
551  setLength("textwidth", 345*20);
552  setLength("columnsep", 10*20);
553  setLength("evensidemargin",11*20);
554 
555  /* Default Paragraph Sizes */
556  setLength("baselineskip",12*20);
557  setLength("parindent", 15*20);
558  setLength("parskip", 0*20);
559 
560  setCounter("page", 0);
561  setCounter("chapter", 0);
562  setCounter("section", 0);
563  setCounter("subsection", 0);
564  setCounter("subsubsection", 0);
565  setCounter("paragraph", 0);
566  setCounter("subparagraph", 0);
567  setCounter("figure", 0);
568  setCounter("table", 0);
569  setCounter("equation", 0);
570  setCounter("footnote", 0);
571  setCounter("mpfootnote", 0);
572  setCounter("secnumdepth", 2);
573 
574 /* vertical separation lengths */
575  setLength("topsep", 3*20);
576  setLength("partopsep", 2*20);
577  setLength("parsep", (int) (2.5*20));
578  setLength("itemsep", 0*20);
579  setLength("labelwidth", 0*20);
580  setLength("labelsep", 0*20);
581  setLength("itemindent", 0*20);
582  setLength("listparindent", 0*20);
583  setLength("leftmargin", 0*20);
584  setLength("floatsep", 0*20);
585  setLength("intextsep", 0*20);
586  setLength("textfloatsep", 0*20);
587  setLength("abovedisplayskip", 0*20);
588  setLength("belowdisplayskip", 0*20);
589  setLength("abovecaptionskip", 0*20);
590  setLength("belowcaptionskip", 0*20);
591  setLength("intextsep", 0*20);
592 
593  setLength("smallskipamount",3*20);
594  setLength("medskipamount", 6*20);
595  setLength("bigskipamount", 12*20);
596 
597  setLength("marginparsep", 10*20);
598  }
599 
600 /****************************************************************************
601 purpose: removes %InterpretCommentString from preamble (usually "%latex2rtf:")
602  ****************************************************************************/
603 static void
605 {
606  char *p,*t;
608 
609  t=s;
610  while ((p=strstr(t,InterpretCommentString))) {
611  t = p-1;
612  if (*t == '%')
613  strcpy(t,t+n+1);
614  else
615  t += n + 1;
616  }
617 }
618 
619 static void
621 /****************************************************************************
622 purpose: reads the LaTeX preamble (to \begin{document} ) for the file
623  ****************************************************************************/
624 {
625  FILE * hidden;
626  char t[] = "\\begin{document}";
627 
628  diagnostics(4, "Reading LaTeX Preamble");
629  hidden = fRtf;
630  fRtf = stderr;
631 
632  g_preamble = getTexUntil(t,1);
634 
635  diagnostics(4, "Entering ConvertString() from ConvertLatexPreamble <%s>",g_preamble);
637  diagnostics(4, "Exiting ConvertString() from ConvertLatexPreamble");
638 
639  fRtf = hidden;
640 }
641 
642 
643 void
645 /****************************************************************************
646 purpose: creates output file and writes RTF-header.
647 params: filename - name of outputfile, possibly NULL for already open file
648  f - pointer to filepointer to store file ID
649  ****************************************************************************/
650 {
651  char * name;
652 
653  if (filename == NULL) {
654  diagnostics(4, "Writing RTF to stdout");
655  *f = stdout;
656 
657  } else {
658 
659  if (g_home_dir)
661  else
662  name = strdup(filename);
663 
664  diagnostics(3, "Opening RTF file <%s>", name);
665  *f = fopen(name, "wb");
666 
667  if (*f == NULL)
668  diagnostics(ERROR, "Error opening RTF file <%s>\n", name);
669 
670  free(name);
671  }
672 }
673 
674 void
676 /****************************************************************************
677 purpose: closes output file.
678 params: f - pointer to filepointer to invalidate
679 globals: g_tex_name;
680  ****************************************************************************/
681 {
682  int i;
683  CmdEndParagraph(0);
684  if (BraceLevel>1)
685  diagnostics(WARNING__,"Mismatched '{' in RTF file, Conversion may cause problems.");
686 
688  diagnostics(WARNING__,"Try translating with 'latex2rtf -Z%d %s'", BraceLevel-1, g_tex_name);
689 
690  fprintf(*f, "}\n");
691  for (i=0; i<g_safety_braces; i++)
692  fprintf(*f, "}");
693  if (*f != stdout) {
694  if (fclose(*f) == EOF) {
695  diagnostics(WARNING__, "Error closing RTF-File");
696  }
697  }
698  *f = NULL;
699  diagnostics(4,"Closed RTF file");
700 }
701 
702 void
703 putRtfChar(char cThis)
704 /****************************************************************************
705 purpose: output filter to escape characters written to an RTF file
706  all output to the RTF file passes through this routine or the one below
707  ****************************************************************************/
708 {
709  if (cThis == '\\')
710  fprintf(fRtf, "\\\\");
711  else if (cThis == '{')
712  fprintf(fRtf, "\\{");
713  else if (cThis == '}')
714  fprintf(fRtf, "\\}");
715  else if (cThis == '\n')
716  fprintf(fRtf, "\n\\par ");
717  else
718  fputc(cThis, fRtf);
719 }
720 
721 void
722 fprintRTF(char *format, ...)
723 /****************************************************************************
724 purpose: output filter to track of brace depth and font settings
725  all output to the RTF file passes through this routine or the one above
726  ****************************************************************************/
727 {
728  char buffer[1024];
729  char *text;
730  va_list apf;
731  va_start(apf, format);
732  vsprintf(buffer, format, apf);
733  va_end(apf);
734  text = buffer;
735  while ( *text ) {
736  if(isknj(*text)) {
737  fputc(*text++, fRtf);
738  fputc(*text++, fRtf);
739  continue;
740  }
741  if ((unsigned char) *text > 127) {
742 
744 
745  } else {
746  fputc(*text, fRtf);
747 
748  if (*text == '{')
750 
751  if (*text == '}')
752  PopFontSettings();
753 
754  if (*text == '\\')
756  }
757  text++;
758  }
759 }
760 
761 char *
763 /****************************************************************************
764 purpose: return the directory to store temporary files
765  ****************************************************************************/
766 {
767 #if defined(MSDOS) || defined(MACINTOSH) || defined(__MWERKS__)
768 
769  return strdup("");
770 
771 #else
772 
773  char * t, *u;
774  char pathsep_str[2]={PATHSEP,0}; /* for os2 or w32 "unix" compiler */
775 
776  /* first use any temporary directory specified as an option */
777  if (g_tmp_path)
778  t= strdup(g_tmp_path);
779 
780  /* next try the environment variable TMPDIR */
781  else if ((u = getenv("TMPDIR"))!=NULL)
782  t= strdup(u);
783  /* finally just return "/tmp/" */
784  else
785  t = strdup("/tmp/");
786  /* append a final '/' if missing */
787  if (*(t+strlen(t)-1) != PATHSEP) {
788  u = strdup_together(t,pathsep_str);
789  free(t);
790  return u;
791  }
792 
793  return t;
794 #endif
795 }
796 
797 char *
798 my_strdup(const char *str)
799 /****************************************************************************
800 purpose: duplicate string --- exists to ease porting
801  ****************************************************************************/
802 {
803  char *s=NULL;
804  unsigned long strsize;
805 
806  strsize = strlen(str);
807  s = (char *) malloc(strsize+1);
808  *s = '\0';
809  if (s == NULL)
810  diagnostics(ERROR,"Cannot allocate memory to duplicate string");
811  strcpy(s, str);
812 /* diagnostics(3,"ptr %x",(unsigned long)s);*/
813  return s;
814 }
815 
816 FILE *
817 my_fopen(char *path, char *mode)
818 /****************************************************************************
819 purpose: opens "g_home_dir/path" and
820  ****************************************************************************/
821 {
822  char *name;
823  FILE *p;
824 
825  diagnostics(3,"Opening <%s>, mode=[%s]",path,mode);
826 
827  if (path == NULL || mode == NULL)
828  return(NULL);
829 
830  if (g_home_dir==NULL)
831  name = strdup(path);
832  else
834 
835  diagnostics(3,"Opening <%s>",name);
836  p = fopen(name, mode);
837 
838  if (p==NULL && strstr(path,".tex") )
839  p = (FILE *) open_cfg(path, FALSE);
840 
841  if (p==NULL) {
842  diagnostics(WARNING__, "Cannot open <%s>", name);
843  fflush(NULL);
844  }
845 
846  free(name);
847  return p;
848 }
849 
850 void debug_malloc(void)
851 {
852  char c;
853  diagnostics(1,"Malloc Debugging --- press return to continue");
854  fflush(NULL);
855  fscanf(stdin,"%c",&c);
856 }
#define strdup
Definition: Utility.h:167
int level
Definition: afm2pl.c:1694
static int isknj(int c)
Definition: allow5c.c:29
#define name
#define text(a)
Definition: aptex-macros.h:925
#define mode
Definition: aptex-macros.h:510
void * open_cfg(const char *name, int quit_on_error)
Definition: cfg.c:117
void ReadCfg(void)
Definition: cfg.c:278
#define CFGDIR
Definition: cfg.h:8
#define n
Definition: t4ht.c:1290
#define MODE_VERTICAL
Definition: convert.h:6
void setCounter(char *s, int n)
Definition: counters.c:93
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
#define PREAMBLE
Definition: dd.h:231
#define free(a)
Definition: decNumber.cpp:310
#define strrchr
Definition: detex.c:67
int linenumber
Definition: devnag.c:401
#define fopen
Definition: xxstdio.h:21
#define fflush
Definition: xxstdio.h:24
static int xx[600]
Definition: psspecial.c:35
int strcmp()
Definition: coll.cpp:143
int sscanf()
int printf()
char * strcpy()
#define PATHSEP
Definition: dvidvi.c:105
void CmdEndParagraph(int code)
Definition: funct1.c:146
mpz_t * f
Definition: gen-fib.c:34
#define s
Definition: afcover.h:80
#define t
Definition: afcover.h:96
#define c(n)
Definition: gpos-common.c:150
#define strchr
Definition: gsftopk.c:59
#define EXIT_FAILURE
Definition: cdjpeg.h:169
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific f u
Definition: afcover.h:88
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
static const void * body(MD5_CTX *ctx, const void *data, unsigned long size)
Definition: md5.c:100
#define EOF
Definition: afmparse.c:59
int getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.c:53
int optind
Definition: getopt.c:39
char * optarg
Definition: getopt.c:42
char * getenv()
int main(int argc, char **argv)
Definition: main.c:197
#define ERROR(string)
Definition: error.h:36
#define basename
Definition: dvi.c:33
char * strstr()
#define fclose
Definition: debug.h:100
#define kpse_program_name
Definition: types.h:322
int CurrentEnvironmentCount(void)
Definition: commands.c:803
static int iEnvCount
Definition: commands.c:53
void PushEnvironment(int code)
Definition: commands.c:812
#define DOCUMENT
Definition: commands.h:4
void ConvertString(char *string)
Definition: convert.c:103
void SetTexMode(int mode)
Definition: convert.c:78
void WriteEightBitChar(char cThis)
Definition: encode.c:1825
bool g_suppress_equation_number
Definition: main.c:89
static void RemoveInterpretCommentString(char *s)
Definition: main.c:604
FILE * my_fopen(char *path, char *mode)
Definition: main.c:817
static void print_usage(void)
Definition: main.c:408
void diagnostics(int level, char *format,...)
Definition: main.c:469
bool g_processing_equation
Definition: main.c:99
char * g_tex_name
Definition: main.c:55
bool g_equation_inline_rtf
Definition: main.c:109
bool g_escape_parent
Definition: main.c:106
int g_document_bibstyle
Definition: main.c:93
bool g_show_equation_number
Definition: main.c:87
char * g_home_dir
Definition: main.c:59
double g_png_figure_scale
Definition: main.c:115
void fprintRTF(char *format,...)
Definition: main.c:722
bool RussianMode
Definition: main.c:67
bool g_aux_file_missing
Definition: main.c:90
char * my_strdup(const char *str)
Definition: main.c:798
bool g_equation_display_rtf
Definition: main.c:108
int g_fcharset_number
Definition: main.c:71
bool twoside
Definition: main.c:73
char g_charset_encoding_name[20]
Definition: main.c:70
static void print_version(void)
Definition: main.c:396
static void CloseRtf(FILE **f)
Definition: main.c:675
bool g_little_endian
Definition: main.c:75
bool g_processing_figure
Definition: main.c:82
bool GermanMode
Definition: main.c:65
int g_processing_fields
Definition: main.c:85
bool CzechMode
Definition: main.c:68
char g_field_separator
Definition: main.c:105
char alignment
Definition: main.c:119
int g_dots_per_inch
Definition: main.c:76
bool g_equation_display_bitmap
Definition: main.c:111
static void InitializeLatexLengths(void)
Definition: main.c:536
double g_png_equation_scale
Definition: main.c:114
char * g_preamble
Definition: main.c:104
bool g_equation_inline_bitmap
Definition: main.c:110
static void ConvertLatexPreamble(void)
Definition: main.c:620
void debug_malloc(void)
Definition: main.c:850
bool FrenchMode
Definition: main.c:66
int g_verbosity_level
Definition: main.c:74
char * g_aux_name
Definition: main.c:57
bool g_latex_figures
Definition: main.c:116
bool g_equation_comment
Definition: main.c:112
bool g_document_type
Definition: main.c:92
bool g_processing_eqnarray
Definition: main.c:83
int indent
Definition: main.c:118
bool twocolumn
Definition: main.c:121
int RecursionLevel
Definition: main.c:120
bool g_fields_use_REF
Definition: main.c:96
char * g_config_path
Definition: main.c:101
bool g_RTF_warnings
Definition: main.c:100
char * g_bbl_name
Definition: main.c:58
static void SetEndianness(void)
Definition: main.c:340
char * getTmpPath(void)
Definition: main.c:762
bool pagenumbering
Definition: main.c:78
int g_enumerate_depth
Definition: main.c:88
char * progname
Definition: main.c:64
char * g_rtf_name
Definition: main.c:56
char * g_script_path
Definition: main.c:102
int g_processing_arrays
Definition: main.c:84
char * g_tmp_path
Definition: main.c:103
bool titlepage
Definition: main.c:122
bool g_fields_use_EQ
Definition: main.c:95
static void ConvertWholeDocument(void)
Definition: main.c:354
int g_safety_braces
Definition: main.c:98
void putRtfChar(char cThis)
Definition: main.c:703
const char * InterpretCommentString
Definition: main.c:62
FILE * fRtf
Definition: main.c:54
static void OpenRtfFile(char *filename, FILE **f)
Definition: main.c:644
bool g_processing_preamble
Definition: main.c:81
int headings
Definition: main.c:79
#define WARNING__
Definition: main.h:32
#define JUSTIFIED
Definition: main.h:40
char * g_section_label
Definition: xref.c:42
int CurrentLineNumber(void)
Definition: parser.c:98
char * CurrentFileName(void)
Definition: parser.c:121
void PushTrackLineNumber(int flag)
Definition: parser.c:73
int PushSource(char *filename, char *string)
Definition: parser.c:139
void PopSource(void)
Definition: parser.c:243
char * Version
Definition: version.h:1
#define fprintf
Definition: mendex.h:64
#define input
Definition: cpascal.h:53
#define malloc
Definition: alloca.c:91
int argc
Definition: main.c:9
char ** argv
Definition: main.c:8
void exit(int)
void MonitorFontChanges(char *text)
Definition: l2r_fonts.c:717
void PopFontSettings(void)
Definition: l2r_fonts.c:704
void InitializeDocumentFont(int family, int size, int shape, int series)
Definition: l2r_fonts.c:560
int TexFontNumber(char *Fname)
Definition: l2r_fonts.c:123
void PushFontSettings(void)
Definition: l2r_fonts.c:686
#define F_SERIES_MEDIUM
Definition: l2r_fonts.h:43
#define F_SHAPE_UPRIGHT
Definition: l2r_fonts.h:38
void getSection(char **body, char **header, char **label)
char * getTexUntil(char *target, int raw)
void setLength(char *s, int d)
Definition: lengths.c:84
float x
Definition: cordic.py:15
static int format
Definition: pbmclean.c:15
char * filename[256]
Definition: pbmtopk.c:46
#define str(s)
Definition: sh6.c:399
Definition: utils.c:300
Definition: execute.c:108
Definition: tpic.c:45
Definition: dvips.h:235
struct def_label label[1024]
Definition: t1part.c:286
#define FILE
Definition: t1stdio.h:34
*job_name strlen((char *) job_name) - 4)
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
void WriteRtfHeader(void)
Definition: preamble.c:1066
void setPackageInputenc(char *option)
Definition: preamble.c:104
void setPackageBabel(char *option)
Definition: preamble.c:68
#define FORMAT_ARTICLE
Definition: preamble.h:1
void InitializeStack(void)
Definition: stack.c:59
int BraceLevel
Definition: stack.c:36
char * ExtractLabelTag(char *text)
Definition: util.c:211
char * strdup_together(char *s, char *t)
Definition: util.c:95
#define va_start(pvar)
Definition: varargs.h:30
#define va_end(pvar)
Definition: varargs.h:38
char * va_list
Definition: varargs.h:22
#define buffer
Definition: xmlparse.c:611
#define BIBSTYLE_STANDARD
Definition: xref.h:15