Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1186 savelij 1
#ifndef _TEXUTIL_H
2
#define _TEXUTIL_H
3
/* texutil.h */
4
/*****************************************************************************/
5
/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
6
/*                                                                           */
7
/* AS                                                                        */
8
/*                                                                           */
9
/* TeX-->ASCII/HTML Converter: Common Utils/Variables                        */
10
/*                                                                           */
11
/*****************************************************************************/
12
 
13
#include <stdio.h>
14
#include <stdarg.h>
15
#include "datatypes.h"
16
 
17
/*---------------------------------------------------------------------------*/
18
 
19
#define TOKLEN 350
20
 
21
typedef const char *const_char_ptr_t;
22
 
23
typedef struct tex_infile
24
{
25
  struct tex_infile *p_next;
26
  char *p_name;
27
  FILE *p_file;
28
  const char *p_buf_line;
29
  char *p_buf_line_to_free;
30
  int curr_line, curr_column;
31
  char *p_saved_buffer_line;
32
  int saved_buffer_line_ptr;
33
  char save_last_char;
34
} tex_infile_t;
35
 
36
extern tex_infile_t *p_curr_tex_infile;
37
extern char buffer_line[1001], *p_buffer_line_ptr, buffer_last_char;
38
 
39
extern const char *p_infile_name, *p_outfile_name;
40
extern FILE *p_outfile;
41
 
42
 
43
extern char tex_token_sep_string[TOKLEN],
44
            tex_backslash_token_sep_string[TOKLEN];
45
 
46
 
47
typedef struct tex_counter
48
{
49
  struct tex_counter *p_next;
50
  char *p_name;
51
  Word ref_num;
52
  unsigned value;
53
} tex_counter_t;
54
 
55
typedef struct tex_newif
56
{
57
  struct tex_newif *p_next;
58
  char *p_name;
59
  Boolean value;
60
} tex_newif_t;
61
 
62
typedef struct tex_environment
63
{
64
  struct tex_environment *p_next;
65
  char *p_name;
66
  char *p_begin_commands,
67
       *p_end_commands;
68
} tex_environment_t;
69
 
70
typedef struct tex_newcommand
71
{
72
  struct tex_newcommand *p_next;
73
  char *p_name;
74
  char *p_body;
75
  unsigned num_args;
76
} tex_newcommand_t;
77
 
78
typedef enum
79
{
80
  EnvNone, EnvDocument, EnvItemize, EnvEnumerate, EnvDescription, EnvTable,
81
  EnvTabular, EnvRaggedLeft, EnvRaggedRight, EnvCenter, EnvVerbatim,
82
  EnvQuote, EnvTabbing, EnvBiblio, EnvMarginPar, EnvCaption, EnvHeading, EnvUser,
83
  EnvCount
84
} EnvType;
85
 
86
extern const char *tex_env_names[EnvCount];
87
 
88
typedef enum
89
{
90
  AlignNone, AlignCenter, AlignLeft, AlignRight
91
} TAlignment;
92
 
93
typedef struct tex_env_data
94
{
95
  int ListDepth, ActLeftMargin, LeftMargin, RightMargin;
96
  int EnumCounter, FontNest;
97
  Boolean InListItem;
98
  TAlignment Alignment;
99
} tex_env_data_t;
100
 
101
typedef struct tex_env_save
102
{
103
  struct tex_env_save *p_next;
104
  EnvType save_env;
105
  char *p_save_user_env_name;
106
  tex_env_data_t save_env_data;
107
} tex_env_save_t;
108
 
109
 
110
extern tex_env_data_t curr_tex_env_data;
111
extern EnvType curr_tex_env;
112
extern char *p_curr_tex_user_env_name;
113
extern tex_env_save_t *p_env_stack;
114
 
115
 
116
typedef struct tex_output_consumer
117
{
118
  struct tex_output_consumer *p_next;
119
  void (*consume)(struct tex_output_consumer*, const_char_ptr_t *pp_str);
120
  void (*destroy)(struct tex_output_consumer*);
121
} tex_output_consumer_t;
122
 
123
extern tex_output_consumer_t *p_current_tex_output_consumer;
124
 
125
typedef enum { e_tex_if_if, e_tex_if_else } tex_if_state_t;
126
typedef struct tex_if_stack
127
{
128
  struct tex_if_stack *p_next;
129
  tex_if_state_t state;
130
  int condition;
131
} tex_if_stack_t;
132
 
133
extern Boolean DoRepass;
134
 
135
/*---------------------------------------------------------------------------*/
136
 
137
extern void tex_infile_pop(void);
138
extern void tex_infile_pop_all(void);
139
extern void tex_infile_push_file(const char *p_name);
140
extern void tex_infile_push_line(const char *p_src, const char *p_line, Boolean line_dynamic);
141
extern char *tex_infile_gets(char *p_dest, size_t dest_cap, tex_infile_t *p_infile);
142
 
143
extern int tex_get_char(void);
144
extern Boolean tex_issep(char inp);
145
extern Boolean tex_isalphanum(char inp);
146
extern Boolean tex_read_token(char *p_dest);
147
extern void tex_push_back_token(char *p_token);
148
extern void tex_token_reset(void);
149
extern void tex_assert_token(const char *p_ref);
150
extern void tex_collect_token(char *p_dest, const char *p_term);
151
 
152
extern void tex_counter_add(const char *p_name);
153
extern void tex_counters_free(void);
154
extern void tex_counter_set(const char *p_name, unsigned new_value);
155
extern unsigned tex_counter_get(const char *p_name);
156
extern void tex_counter_step(const char *p_name);
157
extern void TeXNewCounter(Word index);
158
extern void TeXStepCounter(Word index);
159
extern void TeXSetCounter(Word index);
160
 
161
extern void tex_newif_add(const char *p_name);
162
extern void tex_newifs_free(void);
163
extern Boolean tex_newif_lookup(const char *p_name);
164
extern void TeXNewIf(Word index);
165
 
166
extern void tex_newcommand_add(const char *p_name, const char *p_body, unsigned num_args);
167
extern void tex_newcommands_free(void);
168
extern const tex_newcommand_t *tex_newcommand_lookup(const char *p_name);
169
extern void tex_newcommand_expand_push(const tex_newcommand_t *p_cmd);
170
extern void TeXNewCommand(Word Index);
171
 
172
extern void tex_environment_add(const char *p_name, const char *p_begin_commands, const char *p_end_commands);
173
extern void tex_environments_free(void);
174
extern const tex_environment_t *tex_environment_lookup(const char *p_name);
175
extern EnvType tex_get_env_type(char *p_name, const tex_environment_t **pp_env);
176
extern void TeXNewEnvironment(Word Index);
177
 
178
extern void tex_verror(const char *p_msg, va_list ap);
179
extern void tex_error(const char *p_msg, ...);
180
extern void tex_vwarning(const char *p_msg, va_list ap);
181
extern void tex_warning(const char *p_msg, ...);
182
 
183
extern void tex_save_env(EnvType new_env, const char *p_user_env_name);
184
extern void tex_restore_env(void);
185
 
186
extern void tex_output_consumer_push(tex_output_consumer_t *p_consumer);
187
extern void tex_output_consumer_pop(void);
188
extern void tex_output_consumer_pop_all(void);
189
 
190
extern void tex_if_push(int condition);
191
extern void tex_if_toggle(void);
192
extern void tex_if_pop(void);
193
extern int tex_if_query(void);
194
extern void tex_if_pop_all(void);
195
extern unsigned tex_if_nest(void);
196
 
197
extern void TeXIfNum(Word index);
198
extern void TeXFi(Word index);
199
 
200
#endif /* _TEXUTIL_H */