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)  

style.c
Go to the documentation of this file.
1 /* style.c - Convert simple LaTeX commands using direct.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  2004 Scott Prahl
23 */
24 
25 #include <stdlib.h>
26 #include <string.h>
27 #include "main.h"
28 #include "direct.h"
29 #include "l2r_fonts.h"
30 #include "cfg.h"
31 #include "util.h"
32 #include "parser.h"
33 
34 void InsertBasicStyle(const char *rtf, bool include_header_info)
35 /******************************************************************************
36  purpose: uses data from style.cfg to try and insert RTF commands
37  that correspond to the appropriate style sheet or character style
38  for example
39  ApplyStyle("section", FALSE);
40 
41  rtf="\rtfsequence,\rtfheader"
42  ******************************************************************************/
43 {
44  const char *style;
45  char *comma;
46 
47  if (rtf == NULL) return;
48 
49  style=rtf;
50 
51 /* skip over 0,0, */
52  comma = strchr(style,',')+1;
53  style = strchr(comma,',')+1;
54 
55  while (*style==' ') style++; /* skip blanks */
56 
57  comma = strchr(style,',');
58  if (comma==NULL) return;
59  if (include_header_info)
60  *comma = ' ';
61  else
62  *comma = '\0';
63 
64  while (*style != '\0') {
65 
66  if (*style == '*')
68  else
69  fprintRTF("%c", *style);
70 
71  style++;
72  }
73 
74  *comma = ','; /* change back to a comma */
75 }
76 
77 static void
78 StyleCount(char *rtfline, int *optional, int *mandated)
79 {
80  int n;
81 
82  *optional=0;
83  *mandated=0;
84 
85  n=sscanf(rtfline, " %d , %d ,", optional,mandated);
86 
87  if (n!=2) diagnostics(ERROR,"bad rtf line <%s> in style.cfg", rtfline);
88 
89  if (*optional<0 || *optional>9)
90  diagnostics(ERROR,"bad number of optional parameters in rtf command <%s> style.cfg", rtfline);
91 
92  if (*mandated<0 || *mandated>9)
93  diagnostics(ERROR,"bad number of mandatory parameters in rtf command <%s> style.cfg", rtfline);
94 }
95 
96 void
98 {
99  const char * rtf;
100 
101  rtf = SearchRtfCmd(command, STYLE_A);
102  InsertBasicStyle(rtf,FALSE);
103 }
104 
105 
106 bool
108 /******************************************************************************
109  purpose: uses data from style.cfg to try and convert some
110  LaTeX commands into RTF commands using stylesheet info.
111  ******************************************************************************/
112 {
113  char * rtf;
114  char * RtfCommand;
115  char * TexCommand;
116  char * option[9];
117  char * mandatory[9];
118  char * rtf_piece[20];
119  char * comma;
120  int optional;
121  int mandated;
122  int i;
123 
124  TexCommand = strdup_together("\\",command);
125  RtfCommand = SearchRtfCmd(TexCommand, STYLE_A);
126  if (RtfCommand == NULL)
127  return FALSE;
128 
129  rtf=RtfCommand;
130  StyleCount(rtf, &optional, &mandated);
131 
132  /* read all the optional and mandatory parameters */
133  for (i=0; i<optional; i++) {
135  }
136 
137  for (i=0; i<mandated; i++) {
138  mandatory[i]=getBraceParam();
139  }
140 
141  /* read and duplicate the RTF pieces into an array */
142  for (i=0; i<mandated+optional+1; i++) {
143  comma = strchr(rtf,',');
144  if (comma==NULL)
145  diagnostics(ERROR, "Not enough commas in style command <%s>", RtfCommand);
146 
147  *comma = '\0';
148  rtf_piece[i] = strdup(rtf);
149  diagnostics(1,"piece %d is %s",i,rtf_piece[i]);
150  *comma = ',';
151  rtf = comma +1;
152  }
153 
154 
155 /* free all the pieces */
156  for (i=0; i<optional; i++) {
157  if (option[i]) free(option[i]);
158  }
159 
160  for (i=0; i<mandated; i++) {
161  if (mandatory[i]) free(mandatory[i]);
162  }
163 
164  for (i=0; i<mandated+optional+1; i++) {
165  if (rtf_piece[i]) free(rtf_piece[i]);
166  }
167 
168  free(TexCommand);
169  return TRUE;
170 }
171 
172 
#define strdup
Definition: Utility.h:167
char * SearchRtfCmd(const char *theTexCommand, int WhichCfg)
Definition: cfg.c:344
#define STYLE_A
Definition: cfg.h:4
#define n
Definition: t4ht.c:1290
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
#define free(a)
Definition: decNumber.cpp:310
void WriteFontName(const char **buffpoint)
Definition: direct.c:37
int sscanf()
#define comma
Definition: globals.h:57
#define strchr
Definition: gsftopk.c:59
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
Arabic default style
Definition: afstyles.h:94
#define ERROR(string)
Definition: error.h:36
void diagnostics(int level, char *format,...)
Definition: main.c:469
void fprintRTF(char *format,...)
Definition: main.c:722
char * getBraceParam(void)
char * getBracketParam(void)
Definition: getopt.h:95
bool TryStyleConvert(char *command)
Definition: style.c:107
void InsertBasicStyle(const char *rtf, bool include_header_info)
Definition: style.c:34
static void StyleCount(char *rtfline, int *optional, int *mandated)
Definition: style.c:78
void InsertStyle(char *command)
Definition: style.c:97
char * strdup_together(char *s, char *t)
Definition: util.c:95