File: txeqtb.h

package info (click to toggle)
tralics 2.14.4-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 17,152 kB
  • ctags: 8,260
  • sloc: cpp: 49,403; xml: 18,145; sh: 140; makefile: 118
file content (358 lines) | stat: -rw-r--r-- 11,273 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
// -*- C++ -*-
// $Id: txeqtb.h,v 2.11 2008/11/12 09:43:56 grimm Exp $
// Copyright INRIA/apics (Jose' Grimm) 2002-2004, 2006, 2007,2008

// This software is governed by the CeCILL license under French law and
// abiding by the rules of distribution of free software.  You can  use, 
// modify and/ or redistribute the software under the terms of the CeCILL
// license as circulated by CEA, CNRS and INRIA at the following URL
// "http://www.cecill.info". 
// (See the file COPYING in the main directory for details)

// Contains:
//   equivalent, restore_vb_space, save_catcode, InLoadHandler,
//  InUrlHandler, SaveState
//   SaveAux, and derived types
//     SaveAuxBoundary , SaveAuxInt , SaveAuxDim , SaveAuxCmd 
//     SaveAuxBox , SaveAuxBoxend, SaveAuxToken, SaveAuxGlue 
//     SaveAuxEnv , SaveAuxFont , SaveAuxAftergroup 
// the 5 types for eqtb:
//   eqtb_int eqtb_dim eqtb_glue eqtb_token eqtb_box

// Defined EQTB, the table of equivalents
// EQTB for commands. No Ctor(?) but reset() is called for every object.
// The values is a (symcodes, subtype) pair
class Equivalent {
  int level;      // level at which this is defined
  CmdChr value; // the modifier
 public:
  int get_level() const { return level; }
  CmdChr get_cmdchr() const { return value; }
  symcodes get_cmd() const { return value.get_cmd(); }
  subtypes get_chr() const { return value.get_chr(); }
  bool must_push(int l) const { return level !=l && l> level_one;}
  void reset() { level = level_zero; value.reset(); }
  void special_prim(CmdChr b) {
    value = b;
    if(!b.is_undef()) level = level_one;
  }
  void primitive (CmdChr b) {
    value = b;  level = level_one;
  }
  void set (CmdChr c,int lvl) {
    value = c;  level = lvl;
  }
  void setnl (CmdChr c) {
    value = c;
  }
  bool is_undefined() const { return value.is_undef();}
  bool is_user() const { return value.is_user(); }
  bool is_undef_or_relax() const { return is_undefined() || value.is_relax();}
};

class RestoreVbSpace {
  Token value;  // value to restore
  Parser* P ;   // this object has a pointer to the parser
 public:
  RestoreVbSpace(Parser*p);
  ~RestoreVbSpace();
  void operator()(Token T);
};

class SaveCatcode {
 private:
  int character; // a character
  int code;      // the code of the character to restore
 public:
  SaveCatcode(int c, int nc);
  ~SaveCatcode();
};

class SaveScannerStatus {
 private:
  scan_stat code;
 public:
  SaveScannerStatus(scan_stat c);
  ~SaveScannerStatus();
};


class SaveLongState {
 private:
  l_state code;
 public:
  SaveLongState(l_state c);
  ~SaveLongState();
};


class InLoadHandler {
  bool in_load; // a boolean value to restore
 public:
  static bool global_in_load;
  InLoadHandler(): in_load(global_in_load) {global_in_load= true;}
  ~InLoadHandler() {global_in_load= in_load;}
};

class InUrlHandler {
  bool in_url; // a boolean value to restore
 public:
  static bool global_in_url;
  InUrlHandler(): in_url(global_in_url) {global_in_url= true;}
  ~InUrlHandler() {global_in_url= in_url;}
};

// this saves two values
class SaveState {
  TokenList L;     // the token list to be restored
  bool restricted;  // the restricted flag to be restored
 public:
  void copy_and_reset(TokenList&X) { L.clear(); L.splice(L.begin(), X); }
  void restore(TokenList&X) { X.clear(); X.splice(X.begin(), L); }
  void set_restricted(bool b) { restricted = b;}
  bool get_restricted() const { return restricted; }
};

// This is a virtual class for saving an object that is in an EQTB table
// In general we have a level field, a position field and a value field
class SaveAux {
 public:
  save_type type; // the type of the real thing
  int line_no;   // current line number at start
 public:
  virtual void unsave(bool,Parser&)=0;
  virtual ~SaveAux() {}
  SaveAux(save_type t) : type(t), line_no(0) {}
  void set_line(int l) { line_no = l; }
  int get_line() const { return line_no; }
  void unsave_trace_aux(String s, int pos, bool rt);
  void restore_or_retain(bool) const;
};

// A boundary object is created when we see an open brace, or something
// like that.
class SaveAuxBoundary : public SaveAux {
  boundary_type val; // explains why we opened a new group
 public:
  boundary_type get_val() const { return val; }
  void unsave(bool,Parser&);
  SaveAuxBoundary(boundary_type v) : SaveAux(st_boundary), val(v) {}
  ~SaveAuxBoundary() {}
  void dump(int);
};

// This restores an integer value.
class SaveAuxInt : public SaveAux {
  int level; // the level that was active when this was pushed
  int pos; // the position in eqbt_int_table
  int val; // the value to be restored
 public:
  SaveAuxInt(int l, int a, int b) :  SaveAux(st_int), level(l), pos(a),val(b) {}
  void unsave(bool,Parser&);
  ~SaveAuxInt() {}
};


// This restores a dimension
class SaveAuxDim : public SaveAux {
  int level; // the level that was active when this was pushed
  int pos; // the position in eqbt_dim_table
  ScaledInt val; // the value to be restored
 public:
  SaveAuxDim(int l, int a, ScaledInt b) :  SaveAux(st_int), level(l), pos(a),val(b) {}
  void unsave(bool,Parser&);
  ~SaveAuxDim() {}
};

// data structure for restoring a command
class SaveAuxCmd : public SaveAux{
  int level; // the level that was active when this was pushed
  int cs; // ths position in eqtb to be restored
  CmdChr val; // the CmdChr to be restored
 public:
  SaveAuxCmd(int a, Equivalent X) : SaveAux(st_cmd),
    level(X.get_level()),cs(a),val(X.get_cmdchr()) {}
  void unsave(bool,Parser&);
  ~SaveAuxCmd() {}
};

// data structure fopr restoring a box
class SaveAuxBox : public SaveAux {
  int level; // the level that was active when this was pushed
  int pos;  // the position in box_table to be restored
  Xmlp val; // the value to be restored
 public:
  SaveAuxBox(int l, int a, Xmlp b) : SaveAux(st_box),level(l), pos(a),val(b) {}
  void unsave(bool,Parser&);
  ~SaveAuxBox() {}
};

// case of \setbox0=\hbox{...} , remember the number and the box
class SaveAuxBoxend : public SaveAux {
  int pos;  // the box number
  Xmlp val; // the value of the box
 public:
  SaveAuxBoxend(int a, Xmlp b) :  SaveAux(st_box_end),pos(a),val(b) {}
  void unsave(bool,Parser&);
  ~SaveAuxBoxend() {}
};

// data structure for restoring a token list
class SaveAuxToken : public SaveAux {
  int level; // the level that was active when this was pushed
  int pos; // pthe position in toks_registers
  TokenList val; // the value to be restored
 public:
  SaveAuxToken(int l, int p, TokenList v) :
    SaveAux(st_token),level(l),pos(p), val(v) {}
  void unsave(bool,Parser&);  
  ~SaveAuxToken() {}
};

// data structure for restoring glue
class SaveAuxGlue : public SaveAux {
  int level; // the level that was active when this was pushed
  int pos; // the position in glue_table
  Glue val; // the value to be restored
 public:
  SaveAuxGlue(int l, int p, Glue g) :  SaveAux(st_glue),level(l),pos(p), val(g) {}
  void unsave(bool,Parser&);
  ~SaveAuxGlue(){}
};

// data structure for restoring glue
class SaveAuxString : public SaveAux {
  int level;
  int pos; // the position in glue_table
  string val; // the value to be restored
 public:
  SaveAuxString(int l,int p, string s) :  SaveAux(st_string),level(l),pos(p), val(s) {}
  void unsave(bool,Parser&);
  ~SaveAuxString(){}
};

// data structure for a \begin{something}
class SaveAuxEnv : public SaveAux {
  string oldname;
  string newname;
  int line;
  int val;
  Token T;
  CmdChr cc;
 public:
  void set_line(int x) { line = x; }
  CmdChr get_val() const { return cc; }
  Token get_token() const { return T; }
  string get_name() { return newname; }
  void unsave(bool,Parser&);
  SaveAuxEnv(string a, string aa, int ll, Token b, CmdChr c) :
    SaveAux(st_env),oldname(a),newname(aa),line(ll), T(b), cc(c) {}
  ~SaveAuxEnv(){}
};

// data structure for a font change
class SaveAuxFont : public SaveAux {
  int level; // the level that was active when this was pushed
  int value; // the value to be restored
  Istring color; // the color to restore
  public :
    void unsave(bool,Parser&);
  SaveAuxFont(int l, int v,Istring c) : SaveAux(st_font), level(l), value (v),color(c) {}
  ~SaveAuxFont(){}
};

// This pops a token at the end of the group. Does not depend on a level
class SaveAuxAftergroup : public SaveAux {
  Token value; // the token to pop
  public :
  SaveAuxAftergroup(Token v) : SaveAux(st_save),value (v) {}
  void unsave(bool,Parser&);
  ~SaveAuxAftergroup(){}
};



// EQBT entry for an integer
// Every eqtb entry has a level. Level_zero means undefined
// Level_one is the outer level. The old value must be saved in case
// the current level is different fron the old one, and is greater than one.
// These objects are defined at level_one
class EqtbInt {
  int val; // value of the object
  int level; // level at which this is defined
 public:
  EqtbInt() :val(0), level(level_one) {}
  int get_val() const { return val; }
  void set_val(int x) { val = x; }
  void set_level(int x) { level = x; }
  int get_level()const { return level; }
  void val_and_level(int a, int b) { val = a; level = b; }
  bool must_push(int l) const { return level != l&& l>level_one;}
};

class EqtbString {
  string val; // value of the object
  int level; // level at which this is defined
 public:
  EqtbString() :val(""), level(level_one) {}
  string get_val() const { return val; }
  void set_val(string x) { val = x; }
  void set_level(int x) { level = x; }
  int get_level()const { return level; }
  void val_and_level(string a, int b) { val = a; level = b; }
  bool must_push(int l) const { return level != l&& l>level_one;}
};



// EQBT entry for a dimension.
class EqtbDim {
  ScaledInt val; // value of the object
  int level; // level at which this is defined
 public:
  EqtbDim() :val(0), level(level_one) {}
  ScaledInt get_val() const { return val; }
  void set_val(ScaledInt x) { val = x; }
  void set_level(int x) { level = x; }
  int get_level() const { return level; }
  void val_and_level(ScaledInt a, int b) { val = a; level = b; }
  bool must_push(int l) const { return level != l&& l>level_one;}
};

// EQTB entry for a glue
class EqtbGlue {
  Glue val;  // value of the object
  int level; // level at which this is defined
 public:
  EqtbGlue() : level(level_one) {}
  int get_level() const { return level; }
  Glue get_val() const { return val; }
  void val_and_level(Glue a, int b) { val = a; level = b; }
  bool must_push(int l) const { return level != l&& l>level_one;}
};

// EQTB entry for a token list
class EqtbToken {
  TokenList val;  // value of the object
  int level; // level at which this is defined
 public:
  EqtbToken(): level(level_one) {}
  TokenList get_val()const { return val; }
  int get_level() const { return level; }
  void val_and_level(TokenList a, int b) { val = a; level = b; }
  bool must_push(int l) const { return level != l&& l>level_one;}
};

// EQTB entry for a box
class EqtbBox {
  int level;  // level at which this is defined
  Xmlp val; // value of the object
 public:
  void set_val(Xmlp X) { val = X; }
  Xmlp get_val() const { return val; }
  int get_level() const { return level; }
  EqtbBox() : level(level_one) {}
  void val_and_level(Xmlp a, int b) { val = a; level = b; }
  bool must_push(int l) const { return level != l&& l>level_one;}
};