root/tags/5.52/cifmt.hpp

Revision 4, 14.8 kB (checked in by heitor.barbieri, 2 years ago)

Versão 5.52 do cisis (28/04/2010)

Line 
1#ifndef CIFMT_HPP
2#define CIFMT_HPP
3
4#include <cirec.hpp> // RECSTRU
5#include <citrm.hpp> // TRMSTRU
6#include <cisisx.hpp>
7#include <cifmt.h>
8
9class FMTSTRU
10{
11#if !CIAPI_SOURCE
12 protected:
13#else /* !CIAPI_SOURCE */
14 public:
15#endif /* !CIAPI_SOURCE */
16
17//---------------------- CIFM1.C ----------------------------------
18
19#define MAX_NESTED_REPEAT 15
20#define res_words_length  8            /*21-07-94*/
21#define number_length   30
22#define ERRORET         1
23#define MXOPNFMTFILES 16
24#define CUR_FMT_FILE  opn_fmtfiles[nopn_fmtfiles]
25#ifndef MAXPATH
26#define MAXPATH CIMPL
27#endif
28#define length_word_buff 256+50+50+50
29#define MAX_STACK_BREAKS 100   /* Numero maximo de breaks permitido */
30#if PRINT_CODE
31#define inst_name_size 5000
32#endif  /* PRINT_CODE */
33
34//---------------------- CIFM2.C ----------------------------------
35
36#define max_numeric_string 12
37
38//---------------------- CIFM3.C ----------------------------------
39
40#define DINALLOC 1 /* p/ alocar areas originalmente estaticas - AOT 29/12/90 */
41
42#define max_stack       MAXSTACK
43#define MAX_TMP_STR     (MAXMFRL/2)
44#define MAX_SFIELD      (MAXMFRL/2)
45#define MAX_FD_VALUE    (MAXMFRL/2)
46#define MAX_FD_TMP      (MAXMFRL/2)
47
48#define infoi(i)        i->info.instr
49#define ilab(i)         i->info.lab
50#define iadd(i)         i->m_add
51#define next_infoi(i)   i->next
52
53#define fld_def_ptr(i)  i->m_add
54#define str_const_ptr(i) i->m_add
55
56#define PRT_DBNAME 0
57#define DEB_NOCC   0
58
59//-----------------------------------------------------------------
60
61//---------------------- CIFM1.C ----------------------------------
62
63  int separa_nome_base;
64  unsigned int string_length; /* Valor inicial de tamanho de str */
65  int classe_numero_procurado;
66  int opn_fmtfiles[MXOPNFMTFILES];
67  int nopn_fmtfiles;
68
69  char fmtfile[MAXPATH+1];
70  /*fmt_ref_dbname,*/
71  typedef char  alfa[res_words_length+1];
72  /* Atencao: Os extremos (firstsym e zzzsym)do enumerado
73              abaixo NAO  podem ser modificados e nem mudados de posicao.
74              Eles sao usados para e criar vetores .
75  */
76typedef enum symbol_names {
77   firstsym,
78   csym,     xsym,     dsym,     nsym,     vsym,     ifsym,    fisym,
79   thensym,  elsesym,  orsym,    andsym,   notsym,   mfnsym,   mplsym,
80   mpusym,   mhlsym,   mhusym,   mdlsym,   mdusym,   fsym,     s_sym,
81   getenv_sym, putenv_sym,
82   refsym,   asym,     psym,     ravrsym,  valsym,   lsym,     lwsym,
83   rupxsym,
84   rupdsym,  systsym,  coresym,  maxmfnsym, datemktimesym,
85   rsumsym,  rminsym,  rmaxsym,
86   fmtsym,   usym,     isym,
87   abrcolch, fchcolch,
88   comma,    slash,    ponto,
89   number_sigx,
90   number_sign,percent,  lparen,   rparen,   flecha,   times,    plus,
91   minus,    doispontos, eql,    neq,      lss,      leq,      gtr,
92   geq,      space,    u_litsym, c_litsym, esc_strsym,number,  nullsym,
93   s_fieldsym,r_litsym,
94   long_number,float_number,
95   noccsym,  npsym,
96   ioccsym, continuesym,breaksym,
97   sizesym, typesym,
98   mstsym, datesym, date1sym, date2sym,
99   selsym, casesym, elsecasym, endselsym,
100   instrsym,
101   leftsym, datexsym,
102   rightsym,
103   midsym,
104   catsym,
105   replacsym,
106#if CI_XMLELEM
107   xmlelemsym,
108#endif   
109   nl_sym,
110   lastsym,
111   intvarsym,
112   strvarsym,
113   whilesym,
114   occsym,
115   attribsym,
116   dbsym,
117   ss_sym,
118   np2sym,
119   citypesym,
120   textsym,    /*A12*/
121  zzzsym }  symbol;
122
123  instruction_code sym_to_instruction[zzzsym+9];
124  char  *pfmt ;     /* aponta para o formato de entrada  */
125  char ch;          /* last character read */
126  symbol sym;       /* last symbol read */
127  symbol field_fmt_sym;
128  int num ;         /* value of last integer number read */
129  /*f01*/
130  LONGX long_num;
131  char float_num_str[number_length];
132  /*f01*/
133  alfa fmttoken ;        /* word being read */
134  /*A06*/
135  char *str;
136  int indvar;  /* Indice de variaveis numericas  vvv */
137
138  /*  char str[string_length];*/  /*mudado para dinamico */
139  char sub_field_value;       /* value of last sub_field_read */
140  symbol ssym[128];
141  int source_index;       /* index of the source string */
142  int last_source_index;
143  char  *word_names[zzzsym+9];
144  int next_word_buff;
145  char word_buff[length_word_buff];
146  l_code   *head_code ;    /* points to the beginning of the intermediate
147                              code. Used only as the linked list head
148                           */
149  l_code   *last_instr;   /* points to the last instruction generate */
150  l_code   *p_nulo;                                   /* AOT 06/04/92 */
151  LONGX field_address;
152  LONGX address;
153  label next_label;    /* stores the last generated label */
154  int formatting;       /* if true , the heading commands for formatting
155                           a field have already been generated */
156  l_code  actual_inst;  /* To be used to store a temporary instruction */
157#if PRINT_CODE
158  char *inst_cnv[zzzzzz+10];  /*repf*/
159                         /* to convert instr_codes from enumerate to string*/
160#endif
161  int  repeatable;       /* =true means we are processing repeatable format */
162  int n_instructions;   /* keep the number of instructions generated */
163  /* endereco n_fields; */
164
165  /*  int function_in_process; */
166  /*  int if_expr_in_process; */
167  /*  int first_function_in_expression; */
168
169  typedef struct repeat_groups{
170    int repeatable;
171    int last_format;
172  }REPEAT_GROUPS;
173  REPEAT_GROUPS  vet_repeat[MAX_NESTED_REPEAT];
174  int top_repeat;
175  /*   int n_ref=0; */ /*  qtade de refs aninhados - not used */
176  int last_format;
177
178  l_code *stack_breaks[MAX_STACK_BREAKS];
179  int top_stack_breaks ;
180  int pf_look_ahead;
181  int pi_look_ahead;
182  char *buff_look_ahead;
183  int LOOKING_AHEAD;
184
185#if PRINT_CODE
186  char inst_name[inst_name_size];
187  int inst_next;
188#endif  /* PRINT_CODE */
189
190  int first_time;
191
192  char *pnome;
193  char nome[15];
194
195  l_code *fmt_pgmp;     // format pseudo-code
196
197  field_definition_node *tmp_field;
198  l_code *tmp_node;
199  char *tmp_str_aloc;
200 /*f01*/
201  float_x *tmp_float_aloc;
202 /*f01*/
203  LONGX ret_str;
204
205
206//---------------------- CIFM2.C ----------------------------------
207
208  char fmtnumb[3*max_str_num+1];
209  char tmpform[50];
210
211  char strn[max_numeric_string+1];
212  char *ptstr;
213
214//---------------------- CIFM3.C ----------------------------------
215
216  char *nl_STR;  /* Armazena o string para tratar caracteres de newline */
217  int nl_LEN;
218  int nl_ALLOC;
219
220#if FATRAP
221  jmp_buf fmtjumper;
222#endif /* FATRAP */
223  char fmterrxy[MAXERRL+1];
224  int  fmterror;
225/*A06*/
226  ALLOPARM literal_len;
227  char *literal;
228
229  typedef union stack_operands {
230    int i;
231    float_x r;
232    int boolean;
233    char *s;
234    char *address;
235    LONGX l;
236#if CICPP  /*ifcmm*/
237    RECSTRU *lrecp;
238#endif /*CICPP*/  /*endcmm*/
239  } ustackopnd;
240
241  typedef struct stack_nodex{
242    enum classe_operandos classe;
243    union stack_operands op;
244  }stack_node;
245
246  LONGX erro_fatal;
247  stack_node stack[max_stack];
248  int    stack_pt;
249  stack_node op1_node,op2_node,top_node;
250  stack_node *top,elem,*op1,*op2,*auxpop;
251
252#if DINALLOC
253  LONGX fmt_fsiz;           /* fmt_inter() - to set max field length */
254  LONGX din_fsiz;           /* fmt_inter() - current max field length */
255  char *tmp_str;
256  LONGX max_tmp_str;
257  LONGX max_fd_value;
258  LONGX max_fd_tmp;
259#else
260  char tmp_str[MAX_TMP_STR+1];
261  LONGX max_tmp_str;
262  LONGX max_fd_value;
263  LONGX max_fd_tmp;
264#endif
265
266  int  tmp_str_index;
267  class_operand  new_class,class_of_the_both;
268  int result;
269  int cond_code;
270  instruction_code instruction;
271  int tempint;
272  int int_value_1,int_value_2;
273
274  float_x tempfloat,float_value_1,float_value_2 ;
275  LONGX templong ,long_value_1,long_value_2;
276
277  int there_is_fd_value;
278  int there_is_suf;
279  int rep_group;
280  int next_rep_occ;
281  int modify_fmt_pointers;
282  int no_modify_fmt_pointers;
283
284  char *out;
285  LONGX lw_inter;
286  int pout;
287
288  char *address_out,*tmp_ptr;
289  LONGX  nextcc;
290
291/* incio para achar bug de ref */
292#if  DEBUG_REF
293  int iii;
294  LONGX iix;
295#endif
296/* fim para achar bug de ref */
297/* getc_char */
298#define get_char  /* getchar() */
299
300  struct tbc {
301    char s_esp[3];
302    int  c_esp;
303    /* } tb_espec[]={"\\r",'R',"\\t",'T',"\\b",'B',"\\n",'N',"\\0",'0'};*/
304  } tb_espec[5];
305
306  /* rotinas aritmeticas */
307  char str_num[30],*pstr_num;
308  LONGX ref_mfn_number;
309  /* end rotinas aritmeticas */
310
311  /* f function variables*/
312  int min_width;
313  int dec_places;
314  /* end f-function variables */
315
316#if DINALLOC
317  char *v_fd_value;
318  char *v_fd_tmp;
319#else
320  char v_fd_value[MAX_FD_VALUE+1];
321  char v_fd_tmp[MAX_FD_TMP+1];
322#endif
323
324  char *fd_value,*fd_tmp;
325
326  LONGX lineqtt; /* RPIVA/AOT/HB - 16/11/98 */
327
328  /* Continue em grupos repetitivos  17-7-94 */
329  int continue_rgroup_maxocc;
330  int continue_rgroup;
331  char cc;
332  int pos;
333  int fmt_fim;
334  int fmt_n_ref;
335  int must_repeat;
336  l_code *ni;
337  l_code *rpni; /*repf*/
338  float_x float_exp_value;
339  field_definition_node *itf;
340  RECSTRU *recp;
341  char *firstdbnp;
342
343  float_x  E_var[NMAXVAR];
344  char    *S_var[NMAXVAR];
345 
346  char *retorno;
347
348//-----------------------------------------------------------------
349
350// Precisa ser em uma unica linha ou o GCC indica erro em mudanca de linha
351// de define em arquivo *.hpp
352#define new_line(v,i,max) { if (i + nl_LEN < max ){  strcat(v,nl_STR); i=i+nl_LEN; }else {if (fmttrace)printf(" No room for text - truncating");};}
353
354//---------------------- CIFM1.C ----------------------------------
355
356  int cabe_proximo_digito(int x);
357  symbol analisa_short_int(char pstr_num[]);
358  symbol analisa_numero(char pstr_num[]);
359  label fmt_pop_breaks(int pt_stack_breaks);
360  void fmt_push_breaks(l_code *idx);
361  void fmt_pop_repeat (void);
362  void fmt_push_repeat (void);
363  char *store_res_word(char *str);
364  char *store_inst_names(char *str);
365  void get_ch (void);
366  void erro (int nerr);
367  void parse_fmtfile(void);
368  int parse_microisis_dbname(void); 
369  void str_read (char end_ch);
370  void ignora_espacejamento(void);
371
372  void getsymbol (void);
373  void initialize (void);
374
375  int parse_int_number(void);
376  int parse_date(void);
377  int analisa_mfn (void);
378  int parse_datex_function(void);
379  int parse_f_function(void);
380  int parse_ref_function(instruction_code beg_inst,instruction_code end_inst);
381  l_code * fmtel800(label *lb0, label *lb1);
382  void fmtel810(int repeatable, label lab0, label lab1);
383  void fmtel805(l_code *idx, label lab);
384  int verifica_ref_dbname(int cisis_sintaxe);
385  char * translate_instruction(instruction_code i);
386  void print_inter_din(char *fmt, l_code *head);
387  void semantic_initialize(void);
388  void semantic_error(char *msg);
389  LONGX store_field_def(int tag,char subfield,int ind1,int ind2,int off,int len,int low,int upp);
390  int gen(label lab,instruction_code instr,LONGX add,l_code *index);
391  label gen_next_label(void);
392  void change_pre_cond_by_u_cond(l_code *first,l_code *last);
393  int parse_left_right_mid(instruction_code begin,instruction_code end);
394  int parse_ss(void); 
395  int parse_replace(instruction_code begin,instruction_code end);
396#if CI_XMLELEM
397  int parse_xmlelem(instruction_code begin,instruction_code end);
398#endif
399  int function_code_generator(instruction_code begin,instruction_code end);
400  int c_fmt_separator(void);
401  int field_occs(int *fst,int *last);
402  int field_tag(void);
403  int subfield_id(char *sbf);   
404  int field_id(int *tt,char *sbf);
405  int dummy_id (l_code *idx,label lab1);
406  int r_prelit (void);
407  void suffix(void);
408  void field(void);
409  void field_substr(int *off,int *len);
410  void field_indent(int *ind1,int *ind2);
411  int field_fmt (void);
412  int mode_parameter (void);
413  int c_fmt (void);
414  void get_ignore_space (void);
415  void rep_isis_fmt (void);
416  int parse_instr_function(instruction_code first_instr,instruction_code last_instr);
417  int math_factor_function(instruction_code first_instr,instruction_code last_instr);
418  int parse_look_np_function(instruction_code first_instr,instruction_code last_instr);
419  int factor(void);
420  int termo(void);
421  int num_expr (void);
422  int string_expr (void);
423  void relation (void);
424  void boolean_factor (void);
425  void boolean_term (void);
426  void boolean_expr (void);
427  int fmt_elem (void);
428  int spacing_string (void);
429  int separator (void);
430  void isis_fmt ();
431  void fmt_finaliza_fmt(int pt_break);
432  field_definition_node *alloc_field_definition_node (void);
433  l_code *alloc_pgm_node (void);
434  LONGX store_str_const(char *s);
435  LONGX store_float_const(char *s);
436
437//---------------------- CIFM2.C ----------------------------------
438
439  int fmt_CRLF (char *v,int pos);
440  void out_put_str(char out[],LONGX maxsize,int *pout,LONGX lw,int id1,int id2,LONGX *ncc,char s[]);
441  void upcase_mode(char *s);
442  char * sub_field_change(char *q);
443  LONGX number_of_lines(char *p);
444  char * find_numeric_string(char v[],int *p);
445  char * fmt_float_numb (float_x valor,int min,int dec,char leftfill);
446  void fmt_chadd(l_code *pgm);
447
448//---------------------- CIFM3.C ----------------------------------
449
450  void sc(char *pp);
451  void trace_field(field_definition_node *i,char *p);
452  int fmt_type_number(int tipo,char *fmt);
453  int fmt_type_pattern(char *patt,char *fmt);
454  char * fmt_type(char *p);
455  void fmt_init_E_S(void);
456  void fmt_free_S(int from,int to);
457  char * fmt_copy_realloc(char *pdest,ALLOPARM *dest_mxlen,char *cte_str);
458  char * fmt_alloc_char(ALLOPARM tam,char *msg);
459  int fmt_instr(char *str_source,char *str_sub);
460  void take_numeric_operands_value(class_operand new_class);
461  void retrieve_determine_class(void);
462  void  retrieve_two_numeric_operands(void);
463  void retrieve_two_operands(void);
464  int is_numeric(class_operand x);
465  float_x convert_to_float(stack_node *top);
466  void save_context(int modify_pointers);
467  void restore_context(void);
468  char * sub_string(char source[],int offset,int length);
469  char * store_tmp_string (char *str);
470  int cast_to_int (stack_node *e);
471  void push (stack_node *e);
472  stack_node * pop(void);
473  int exec_percent(char *out,int *outs,LONGX *ncc);
474  char * trata_md(instruction_code mode,char *s,int *final_added,char **tofreep);
475  void sub_field_string(char *q,char sub);
476  char * field_value(char *sfieldvalue,LONGX max_sfield,int dd);
477  char  * fmt_get_date(int parmdate, LONGX secs0);
478  LONGX fmt_cnv_to_long(stack_node *top);
479  float_x fmt_cnv_to_float(stack_node *top);
480  void fmt_init_vinstr(l_code *ptr_ins,int nnested);
481  void fmt_inicio_grupos_vfields(instruction_code instr_inicial,instruction_code instr_final);
482  void fmt_fim_grupos_vfields(void);
483  int fmt_load_all_occ(void);
484  void fmt_load_next_occ(void);
485  void fmt_comum_ref_beg(void);
486  void fmt_comum_ref_end(void);
487  LONGX lookup(char *keyp,TRMSTRU *trmp,char *dbnp,LONGX nord);
488
489//-----------------------------------------------------------------
490
491 public:
492
493  CISISX *cisisxp;
494
495//---------------------- CIFM1.C ----------------------------------
496
497  LONGX fmt_error;
498#if ERRORET
499  LONGX fmt_errof;
500#endif
501
502//---------------------- CIFM1.C ----------------------------------
503
504  LONGX xfmt_gener(char *fmt);
505  void xfmt_free(void);
506
507//---------------------- CIFM2.C ----------------------------------
508
509//---------------------- CIFM3.C ----------------------------------
510  LONGX xfmt_inter(RECSTRU *parmrecp,LONGX par_lw,char *par_out,LONGX outsize);
511  void inter_error(char *err);
512  FMTSTRU(CISISX *cpx);
513  ~FMTSTRU(void);
514
515//-----------------------------------------------------------------
516};
517
518#endif // CIFMT_HPP
Note: See TracBrowser for help on using the browser.