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)  

ignore.c
Go to the documentation of this file.
1 /* ignore.c - ignore commands found in ignore.cfg
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-1997 Ralf Schlatterbeck
23  1998-2000 Georg Lehner
24  2001-2002 Scott Prahl
25 */
26 
27 #include <stdlib.h>
28 #include <ctype.h>
29 #include <string.h>
30 #include "main.h"
31 #include "direct.h"
32 #include "l2r_fonts.h"
33 #include "cfg.h"
34 #include "ignore.h"
35 #include "funct1.h"
36 #include "commands.h"
37 #include "parser.h"
38 #include "convert.h"
39 
40 static void IgnoreVar(void);
41 static void IgnoreCmd(void);
42 
43 bool
45 /****************************************************************************
46 purpose : ignores variable-formats shown in file "ignore.cfg"
47 returns : TRUE if variable was ignored correctly, otherwise FALSE
48 
49 # NUMBER simple numeric value
50 # MEASURE : numeric value with following unit of measure
51 # OTHER: ignores anything to the first character after '='
52 # and from there to next space. eg. \setbox\bak=\hbox
53 # COMMAND ignores anything to next '\' and from there to occurence
54 # of anything but a letter. eg. \newbox\bak
55 # SINGLE ignore single command. eg. \noindent
56 # PARAMETER ignores a command with one paramter
57 # PACKAGE does not produce a Warning message if PACKAGE is encountered
58 # ENVCMD proceses contents of unknown environment as if it were plain latex
59 # ENVIRONMENT ignores contentents of that environment
60  ****************************************************************************/
61 {
62  const char *RtfCommand;
63  char TexCommand[128];
64  bool result = TRUE;
65 
66  if (strlen(command) >= 100) {
67  diagnostics(WARNING__, "Command <%s> is too long", command);
68  return FALSE; /* command too long */
69  }
70  TexCommand[0] = '\\';
71  TexCommand[1] = '\0';
72  strcat(TexCommand, command);
73 
74  RtfCommand = SearchRtfCmd(TexCommand, IGNORE_A);
75  if (RtfCommand == NULL)
76  result = FALSE;
77  else if (strcmp(RtfCommand, "NUMBER") == 0)
78  IgnoreVar();
79  else if (strcmp(RtfCommand, "MEASURE") == 0)
80  IgnoreVar();
81  else if (strcmp(RtfCommand, "OTHER") == 0)
82  IgnoreVar();
83  else if (strcmp(RtfCommand, "COMMAND") == 0)
84  IgnoreCmd();
85  else if (strcmp(RtfCommand, "SINGLE") == 0)
86  {}
87  else if (strcmp(RtfCommand, "PARAMETER") == 0)
89  else if (strcmp(RtfCommand, "TWOPARAMETER") == 0)
91 /* else if (strcmp(RtfCommand, "LINE") == 0) skipToEOL(); */
92  else if (strcmp(RtfCommand, "ENVIRONMENT") == 0) {
93  char *str;
94  str = malloc(strlen(command) + 5); /* envelope: end{..} */
95  if (str == NULL)
96  diagnostics(ERROR, "malloc error -> out of memory!\n");
97  strcpy(str, "end{");
98  strcat(str, command);
99  strcat(str, "}");
101  free(str);
102  } else if (strcmp(RtfCommand, "ENVCMD") == 0)
104  else if (strcmp(RtfCommand, "PACKAGE") == 0)
105  {}
106  else
107  result = FALSE;
108  return (result);
109 }
110 
111 
112 void
114 /****************************************************************************
115 purpose : ignores anything till a space or a newline
116  ****************************************************************************/
117 {
118  char c;
119  while ((c = getTexChar()) && c != '\n' && c != ' '){}
120 }
121 
122 
123 void
125 /****************************************************************************
126 purpose : ignores anything till an alphanumeric character
127  ****************************************************************************/
128 {
129  char c;
130  while ((c = getTexChar()) && c != '\\'){}
131  while ((c = getTexChar()) && !isalpha((int)c)){}
132  ungetTexChar(c);
133 }
134 
135 void
136 Ignore_Environment(char *cCommand)
137 /******************************************************************************
138  purpose: function, which ignores an unconvertable environment in LaTex
139  and writes text unchanged into the Rtf-file.
140 parameter: searchstring : includes the string to search for
141  example: \begin{unknown} ... \end{unknown}
142  searchstring="end{unknown}"
143  ******************************************************************************/
144 {
145  char unknown_environment[100];
146  char *buffer;
147  int font;
148 
149  diagnostics(4, "Entering IgnoreEnvironment <%s>", cCommand);
150 
151  snprintf(unknown_environment, 100, "\\%s%s%s", "end{", cCommand, "}");
152  font = TexFontNumber("Typewriter");
153  CmdEndParagraph(0);
155  fprintRTF("\\qc [Sorry. Ignored ");
156  fprintRTF("{\\plain\\f%d\\\\begin\\{%s\\} ... \\\\end\\{%s\\}}]", font, cCommand, cCommand);
157  CmdEndParagraph(0);
159 
160  buffer = getTexUntil(unknown_environment,0);
161  ConvertString(unknown_environment);
162  free(buffer);
163 
164  diagnostics(4, "Exiting IgnoreEnvironment");
165 }
#define font
Definition: aptex-macros.h:175
char * SearchRtfCmd(const char *theTexCommand, int WhichCfg)
Definition: cfg.c:344
#define IGNORE_A
Definition: cfg.h:3
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
#define free(a)
Definition: decNumber.cpp:310
int strcmp()
Definition: coll.cpp:143
char * strcpy()
void CmdIndent(int code)
Definition: funct1.c:339
void CmdEndParagraph(int code)
Definition: funct1.c:146
void CmdStartParagraph(int code)
Definition: funct1.c:65
#define INDENT_INHIBIT
Definition: funct1.h:45
#define FIRST_PAR
Definition: funct1.h:40
#define No_Opt_Two_NormParam
Definition: funct1.h:150
#define No_Opt_One_NormParam
Definition: funct1.h:149
#define c(n)
Definition: gpos-common.c:150
static void IgnoreVar(void)
Definition: ignore.c:113
bool TryVariableIgnore(char *command)
Definition: ignore.c:44
static void IgnoreCmd(void)
Definition: ignore.c:124
void Ignore_Environment(char *cCommand)
Definition: ignore.c:136
#define NULL
Definition: ftobjs.h:61
#define ERROR(string)
Definition: error.h:36
void PushEnvironment(int code)
Definition: commands.c:812
#define IGN_ENV_CMD
Definition: commands.h:9
void ConvertString(char *string)
Definition: convert.c:103
void diagnostics(int level, char *format,...)
Definition: main.c:469
void fprintRTF(char *format,...)
Definition: main.c:722
#define WARNING__
Definition: main.h:32
#define malloc
Definition: alloca.c:91
#define snprintf
Definition: snprintf.c:41
int TexFontNumber(char *Fname)
Definition: l2r_fonts.c:123
char getTexChar(void)
void ungetTexChar(char c)
void CmdIgnoreParameter(int)
char * getTexUntil(char *target, int raw)
#define isalpha(ch)
Definition: utype.h:82
#define str(s)
Definition: sh6.c:399
Definition: utils.c:300
Definition: pbmfont.h:11
*job_name strlen((char *) job_name) - 4)
#define buffer
Definition: xmlparse.c:611