root/trunk/cifm3.c

Revision 389, 129.6 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1 /* file CIFM3.C */
2#define RETIRAR 1   /* Usado para colocar em rotina alocacao de var  char  */
3#include <stdio.h>
4#include <ctype.h>
5#include <string.h>
6#include <time.h>
7#if TESTFREE
8#include <conio.h>
9#endif
10
11#include "cisis.h"
12#include "cifmt.h"
13
14#ifndef FUNPROCX
15#define FUNPROCX 0
16#endif
17
18#if CICPP
19#include "cicgi.hpp"
20#include "cifmt.hpp"
21#endif /* CICPP */
22
23#define DEBUG_REF 0
24#define MICRO_ISIS_COMPATIBLE 0
25
26#if !CICPP /* otherwise DINALLOC is #defined in cifmt.hpp */
27#define DINALLOC 1 /* p/ alocar areas originalmente estaticas - AOT 29/12/90 */
28#endif /* CICPP */
29
30#define TRACE_REPLACE    0
31#define TRACE_STRFUN     0
32#define TRACE_REPF       0
33#define TRACE_INTER_X    0              /* printf instruction in execution */
34#define TRACE_INTER_L    0              /* printf debug in lookup() */
35#define TRACE_INTER_2    0              /* printf Apos fmt_load_all_occ */
36#define DEB_FLOAT        0
37#define TRACE_COMP_M    00              /* printf msg in trata_md() */
38
39#if FATRAP
40#define IFERR_GOTO
41#define IFERR_RET
42#else
43#define IFERR_GOTO      if (fmterror) goto ERROR_LABEL
44#define IFERR_RET       if (fmterror) return
45#endif /* FATRAP */
46
47/* Modificacoes:
48   A05 - 19/07/96
49    Problema:
50     A funcao REF nao esta liberando corretamente as prateleiras onde sao
51     lidos os registros do MasterFile, quando um Ref e' utilizado dentro
52     de outro Ref.
53     Exemplo: REF(val(ref(1,'3'),...)
54     Se aplicarmos esse REF para varios registros, dara erro FATAL de
55     alocacao.
56    Identificacao:
57     Sempre que um novo REF e encontrado em um formato, e gurdado no
58     vetor "vprats" apontado por "currprat" o numero da prateleira
59     disponivel de 255 ..0.
60     Quando termina o REF, a prateleira vprats[currprat] devera ser
61     liberada.
62     O problema acontecia porque "currprat" estava apontando para a proxima
63     entrada disponivel de "vprats" e nao para a ultima usada. No momento
64     de liberar os apontadores estavam defasados. A rotina de leitura do
65     master era  feita numa prateleira(rec_prateleira) que nao estava
66     alocada forcando a alocacao. Esse registro nao era liberado.
67   Correcao:
68     Corridos os apontadores. Para compatibilizacao, a prateleira de
69     entrada do formato e' guardada na primeira posicao de vprats para
70     sinalizar o registro em uso.
71     Foram inseridos alguns traces para achar o erro.
72*/
73
74
75
76/*--------------------------------------------------------------------------*/
77/*                 E e S variaveis                                          */
78/*--------------------------------------------------------------------------*/
79#if !CICPP
80static float_x  E_var[NMAXVAR];
81static char    *S_var[NMAXVAR];
82#endif /* CICPP */
83
84
85/*--------------------------------------------------------------------------*/
86/*                   NewLine                                                */
87/*--------------------------------------------------------------------------*/
88/* A07*/
89#if !CICPP
90char *nl_STR;  /* Armazena o string para tratar caracteres de newline */
91int nl_LEN;
92int nl_ALLOC;
93#endif /* CICPP */
94
95/*-----------------------------------------------------------------------*/
96#define ispunctuation(x) \
97   ((x==';'||x=='.' || x==':' || x== ',' || x=='!'|| x=='?' )?true:false )
98/*-----------------------------------------------------------------------*/
99#define NO_INTERVAL(x) (x ? ((x->lower==NO_MIN_OCC) && (x->upper==NO_MAX_OCC)) : false)
100/*-----------------------------------------------------------------------*/
101
102/* error - AOT 29/12/90 */
103/* #define MAXERRL      60 */
104
105#if !CICPP
106#if FATRAP
107jmp_buf fmtjumper;
108#endif /* FATRAP */
109char fmterrxy[MAXERRL+1] = { "" } ;
110int  fmterror;
111/*A06*/
112ALLOPARM literal_len;
113char *literal;
114/*A06*/
115#if ANSI
116/*float_x convert_to_float(stack_node *top); */
117int  fmt_type_pattern(char *patt,char *fmt);
118int  fmt_type_number(int tipo,char *fmt);
119void fmt_init_E_S(void);
120void free_S(int from,int to);
121char *fmt_copy_realloc(char *dest,ALLOPARM *dest_mxlen,char *cte_str);
122char *fmt_alloc_char(ALLOPARM tam,char *msg);
123int fmt_instr(char *str_source,char *str_sub);
124char *fmt_type(char *p);
125void trace_field(field_definition_node *i,char *p);     /* AOT 27/12/91 */
126LONGX number_of_lines(char *p);
127static void sub_field_string(char *q, char sub);
128/* char *long_to_char(LONGX valor, int n); substituida*/
129char *trata_md( instruction_code mode , char *s,int *final_added,char **p);
130void upcase_mode(char *s);
131void out_put_str(char out[],LONGX maxsize,int *pout,LONGX lw,
132                 int id1,int id2,LONGX *ncc,char s[]);
133#else
134
135float_x convert_to_float();
136int  fmt_type_pattern();
137int  fmt_type_number();
138
139void fmt_init_E_S();
140void free_S();
141
142char *fmt_copy_realloc();
143char *fmt_alloc_char();
144int fmt_instr();
145char *fmt_type();
146void trace_field();                                     /* AOT 27/12/91 */
147LONGX number_of_lines();
148static void sub_field_string();
149/* char *long_to_char(); substituida */
150char *trata_md();
151void upcase_mode();
152void out_put_str();
153#endif
154#endif /* CICPP */
155
156/*--------------------------------------------------------------------------*/
157/*                   global types                                           */
158/*--------------------------------------------------------------------------*/
159#if !CICPP
160typedef union stack_operands {
161    int i;
162        float_x r;
163    int boolean;
164    char *s;
165    char *address;
166    LONGX l;
167#if CICPP  /*ifcmm*/
168    RECSTRU *lrecp;
169#endif /*CICPP*/  /*endcmm*/
170    } ustackopnd;
171typedef struct stack_nodex{
172   enum classe_operandos classe;
173   union stack_operands op;
174
175   }stack_node;
176
177/* prototypes */
178#if ANSI
179int exec_percent(char *out,int *outs,LONGX *ncc);
180void retrieve_two_numeric_operands (void);
181stack_node *pop(void);
182void inter_error (char *err);
183void restore_context(void);
184void push ( stack_node  *e);
185int  cast_to_int (stack_node  *e);
186char *field_value(char *p,LONGX n,int dd);
187void retrieve_determine_class(void);
188void take_numeric_operands_value(class_operand new_class);
189char *sub_string(char source[],int offset,int length);
190void  save_context(int modify_pointers);
191char *store_tmp_string (char *str);
192int is_numeric(class_operand x);
193void retrieve_two_operands (void);
194#else
195int exec_percent();
196void retrieve_two_numeric_operands ();
197stack_node *pop();
198void inter_error();
199void restore_context();
200void push ();
201int  cast_to_int ();
202char *field_value();
203void retrieve_determine_class();
204void take_numeric_operands_value();
205char *sub_string();
206void  save_context();
207char *store_tmp_string ();
208int is_numeric();
209void retrieve_two_operands ();
210#endif
211#endif /* CICPP */
212
213
214/*--------------------------------------------------------------------------*/
215/*                   global_variables                                       */
216/*--------------------------------------------------------------------------*/
217#if !CICPP
218
219#define max_stack       MAXSTACK
220#define MAX_TMP_STR     (MAXMFRL/2)
221#define MAX_SFIELD      (MAXMFRL/2)
222#define MAX_FD_VALUE    (MAXMFRL/2)
223#define MAX_FD_TMP      (MAXMFRL/2)
224
225LONGX erro_fatal;
226stack_node stack[max_stack];
227int    stack_pt;
228stack_node op1_node,op2_node,top_node;
229stack_node *top,elem,*op1,*op2,*auxpop;
230
231#if DINALLOC
232//LONGX fmt_fsiz=MAXMFRL;               /* fmt_inter() - to set max field length - deslocado para cidbx.c */
233static LONGX din_fsiz;           /* fmt_inter() - current max field length */
234static char *tmp_str;
235static LONGX max_tmp_str;
236static LONGX max_fd_value;
237static LONGX max_fd_tmp;
238#else
239static char tmp_str[MAX_TMP_STR+1];
240static LONGX max_tmp_str=MAX_TMP_STR;
241static LONGX max_fd_value=MAX_FD_VALUE;
242static LONGX max_fd_tmp=MAX_FD_TMP;
243#endif
244
245int  tmp_str_index;
246class_operand  new_class,class_of_the_both;
247int result;
248int cond_code;
249instruction_code instruction;
250int tempint;
251int int_value_1,int_value_2;
252
253float_x tempfloat,float_value_1,float_value_2 ;
254LONGX templong ,long_value_1,long_value_2;
255
256int there_is_fd_value;
257int there_is_suf;
258int rep_group;
259int next_rep_occ;
260int modify_fmt_pointers=true;
261int no_modify_fmt_pointers=false;
262
263#define infoi(i)        i->info.instr
264#define ilab(i)         i->info.lab
265#define iadd(i)         i->m_add
266#define next_infoi(i)   i->next
267
268#define fld_def_ptr(i)  i->m_add
269#define str_const_ptr(i) i->m_add
270
271
272/* mudar de local para global */
273char *out;
274LONGX lw_inter;
275int pout;
276
277char *address_out,*tmp_ptr;
278LONGX  nextcc;
279
280
281/* incio para achar bug de ref */
282#if  DEBUG_REF
283int iii;
284LONGX iix;
285#endif
286/* fim para achar bug de ref */
287/* getc_char */
288#define get_char  /* getchar() */
289/* 04-02-95 Existia um problema quando havia sufixo e este era
290            colocado no fim de linha e logo apos um crlf.
291            Mesmo o n sendo zero, isto e, nao tendo sido colocado
292            um final do isis padrao pois havia sufixo, por causa
293            do crlf eram retirados 2 caracteres. O crlf so pode
294            ser levado em conta se tiverem sido acrescentados
295            caracteres no final (n>0)
296 */
297
298#endif /* CICPP */
299
300#define delete_chars(out,pout,next,n,lw) \
301     if(n>0)                            \
302     {                                  \
303       if(fmt_CRLF(out,pout)) n=n+nl_LEN; /* mudar junto com crlf */ \
304       pout=pout-n;                       \
305       out[pout]=null_char;                    \
306       next=next-n;                       \
307       if(next<1) next=lw-n+1;            \
308     }                                  \
309/*--------------------------------------------------------------------------*/
310/*                   retrieve_two_logical_operands                          */
311/*--------------------------------------------------------------------------*/
312#define  retrieve_two_logical_operands                                \
313     auxpop = pop();                                                  \
314     if (!fmterror)                                                   \
315     {                                                                \
316      op2=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));  \
317      auxpop = pop();                                                 \
318      if (!fmterror)                                                  \
319      {                                                               \
320       op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node)); \
321       if (op1->classe!=op2->classe || op1->classe != logical)        \
322        inter_error(" Program error two logical operands expected");  \
323       else                                                           \
324        elem.classe=logical;                                          \
325      }                                                               \
326     }
327
328/*----------------------------------------------------- AOT 27/12/91 -------*/
329/*--------------------------------------------------------------------------*/
330/*                   sc                                                     */
331/* Conversao de strings do tipo "\n" em caracter especial "lf"              */
332/*--------------------------------------------------------------------------*/
333
334#if !CICPP
335
336struct tbc {
337 char s_esp[3];
338 int  c_esp;
339/* } tb_espec[]={"\\r",'R',"\\t",'T',"\\b",'B',"\\n",'N',"\\0",'0'};*/
340#if BEFORE20000518
341 } tb_espec[]={"\\r",'\r',"\\t",'\t',"\\b",'\b',"\\n",'\n',"\\0",'\0'};
342#else
343#if BEFORE20000914
344 } tb_espec[]={{"\\r",'\r'},{"\\t",'\t'},{"\\b",'\b'},{"\\n",'\n'},{"\\0",'\0'}};
345#else
346 } tb_espec[]={{"\\\r",'\r'},{"\\\t",'\t'},{"\\\b",'\b'},{"\\\n",'\n'},{"\\\0",'\0'}};
347#endif
348#endif
349
350#endif /* CICPP */
351
352
353#if CICPP
354void FMTSTRU :: sc(char *pp)
355#else /* CICPP */
356#if ANSI
357void sc(char *pp)
358#else /* ANSI */
359void sc(pp)
360char *pp;
361#endif /* ANSI */
362#endif /* CICPP */
363{
364 char *tmp,*p,*r;
365 int k;
366 ALLOPARM cte_siz;
367 cte_siz=(ALLOPARM) strlen((char *)pp);
368 tmp=fmt_alloc_char( (ALLOPARM)(cte_siz+1),"cifm2/sc/alloc");
369 /* if (tmp == NULL) IFERR_GOTO; Label ERROR_LABEL is defined at fmt_inter */
370 if (tmp == NULL) fatal("cifm2/sc/alloc/2");
371 strcpy(tmp,pp);
372 p=pp;
373 r=tmp;
374 for (; *tmp ;p++,tmp++) {
375   if (*tmp!='\\') {
376    *p=*tmp;
377   }else{
378   for (k=0; tb_espec[k].c_esp;k++){
379#if BEFORE20000914
380      if (strncmp(tb_espec[k].s_esp,(char *)tmp,2)==0) {
381#else
382      if (strncmp(tb_espec[k].s_esp,(char *)tmp,strlen(tb_espec[k].s_esp))==0) {
383#endif
384         *p=(char)tb_espec[k].c_esp;
385         tmp++;
386#if 01
387#ifndef CICPP
388          printf("\n++ achou|%s|", tb_espec[k].s_esp);
389#endif /* CICPP */
390#endif
391         break;
392      }
393   }
394   }
395 }
396 *p=null_char;
397#if 0
398 printf ("\nDentro sc=|%s|",q);
399 printf ("\nDentro tmp=|%s|",tmp);
400#endif
401#if CICPP
402        delete [] r;
403#else
404        FREE(r);
405#endif
406
407}
408
409/*--------------------------------------------------------------------------*/
410/*                   trace_field                                            */
411/*--------------------------------------------------------------------------*/
412#if CICPP
413void FMTSTRU :: trace_field(field_definition_node *i,
414                            char *p)
415#else /* CICPP */
416#if ANSI
417void trace_field(field_definition_node *i,
418                 char *p)
419#else /*ANSI*/
420void trace_field(i,p)
421field_definition_node *i;
422char *p;
423#endif /*ANSI*/
424#endif /* CICPP */
425{
426int n=0;
427printf(
428"#%d[tag=%d,subf=%c,id1=%d,id2=%d,off=%d,len=%d,max=%d,last=%d\n=%s,\n",
429             n,
430             i->tag,
431             i->sub_field,
432             i->indent1,
433             i->indent2,
434             i->offset,
435             i->length,
436             i->max_occ,
437             i->last_occ,p);
438printf(
439"act=%d,first=%d\n",
440             i->actual_occ,
441             i->first_occ);
442 }
443
444/*--------------------------------------------------------------------------*/
445/*                   fmt_type_number                                        */
446/*--------------------------------------------------------------------------*/
447/* type(tipo,formato)
448  tipo =1 alphanumeric
449  tipo =2 alphabetic
450  tipo =3 numeric
451  tipo =4 inteiro decimal. Opcional sinal
452  tipo =5 numero decimal incluindo scientific
453
454*/
455#if CICPP
456int FMTSTRU :: fmt_type_number(int tipo,
457                               char *fmt)
458#else /* CICPP */
459#if ANSI
460int  fmt_type_number(int tipo,char *fmt)
461#else
462int  fmt_type_number(tipo,fmt)
463int  tipo;
464char *fmt;
465#endif /*ANSI*/
466#endif /* CICPP */
467{ char *p,*pt_num;
468  int res,a,n,len,scien;
469  res= 0;
470  p=fmt;
471  len=strlen(p);
472  if (len==0) return(1); /* Vazio retorna sempre 1 */
473
474 switch (tipo) {
475  case 1 :
476  case 2 :
477  case 3 :
478       a=0;n=0;
479       while (*p) {
480         if (isiswctab[*p]) a++;
481         if (isdigit(*p)) n++;
482         p++;
483       }
484       if (tipo == 1 &&  a+n == len) res=1 ;
485         else if (tipo == 2 &&  a == len) res=1;
486                else if (tipo == 3 && n == len) res=1;
487
488       break;
489  case 4 :
490  case 5 :
491      a=0;
492      scien=0;
493      n=0; /* supor numero inteiro */
494      pt_num=find_numeric_string(p,&a);
495      if ( (strchr(pt_num,'e') != nulo) ||
496           (strchr(pt_num,'E') !=nulo ) )  scien=1;
497      if (strchr(pt_num,'.') !=nulo) n=1;
498
499      p=fmt;
500      a=1;
501      while (a) {  /* Micro isis aceita espacos `a esqueda */
502        if (*p != space_char || *p == null_char )a=0;
503        else p++ ;
504      }
505      if ((size_t)strlen(pt_num)==(size_t)strlen(p)){
506        if (tipo==4  && scien == 0 && n==0 ) res=1;
507          else if (tipo == 5) res=1;
508      }
509      break;
510
511 }
512 return(res);
513}
514/*--------------------------------------------------------------------------*/
515/*                   fmt_type_pattern                                       */
516/*--------------------------------------------------------------------------*/
517/* Compara um string com um padrao  do tipo
518   patt=xx-xx-99-xx-aa
519   str =ca-dd-11-1a-bb
520   Se tamanhos s~ao difentes, entao resultado falso
521   Senao compara caracter a caracter
522*/
523#if CICPP
524int FMTSTRU :: fmt_type_pattern(char *patt,
525                                char *fmt)
526#else /* CICPP */
527#if ANSI
528int  fmt_type_pattern(char *patt,char *fmt)
529#else
530int  fmt_type_pattern(patt,fmt)
531char *patt;
532char *fmt;
533#endif /*ANSI*/
534#endif /* CICPP */
535{ char *p,*q;
536  int res,l;
537  p=patt; q=fmt; res=1;
538  l=strlen(patt);
539  if (l != strlen(fmt)) return(0);
540  while(res && *p ) {
541    switch ( toupper(*p)) {
542     case 'A' :
543         res = isiswctab[*q];
544         break;
545     case 'X' :
546         res = 1;
547         break;
548    case '9' :
549        if ( !isdigit(*q)) res=0;
550        break;
551    default :
552        res = (*q == *p);
553    }
554    p++;q++;
555  }
556  return (res);
557
558}
559/*----------------------------------------------------- AOT 27/12/91 -------*/
560/*--------------------------------------------------------------------------*/
561/*                   fmt_type                                               */
562/*--------------------------------------------------------------------------*/
563/* Usa rotina que separa dentro de um string o proximo numero
564   Se o tamanho do numero separado e igual ao tamanho do string e'porque
565   o string e numerico.
566   Caso contrario verifica se contem apenas letras para ser
567   alfabetico.
568   Caso contrario e alfanumerico
569*/
570#if CICPP
571char * FMTSTRU :: fmt_type(char *p)
572#else /* CICPP */
573#if ANSI
574char *fmt_type(char *p)
575#else /*ANSI*/
576char *fmt_type(p)
577char *p;
578#endif /*ANSI*/
579#endif /* CICPP */
580{
581  static char tmp_ty[2];
582  int i;
583  char *q,*pt_num;
584  q=p;
585  tmp_ty[1]=null_char;
586  tmp_ty[0]=TY_X;
587  i=0;
588  pt_num=find_numeric_string(p,&i);
589  if ((size_t)strlen(pt_num)==(size_t)strlen(p)){
590      tmp_ty[0]=TY_N;
591  }else{
592      while (isiswctab[*q] || *q==' ') q++;
593      if (*q==null_char)tmp_ty[0]=TY_A;
594  }
595  /*03-11-99 Alterar para retornar ''  quando string vazio */
596  if ( (size_t)strlen(p) == (size_t)0 ) tmp_ty[0]=null_char;
597  return (char *)tmp_ty;
598}
599/*--------------------------------------------------------------------------*/
600/*                fmt_init_E_S                                               */
601/*--------------------------------------------------------------------------*/
602#if CICPP
603void FMTSTRU :: fmt_init_E_S(void)
604#else /* CICPP */
605#if ANSI
606void fmt_init_E_S()
607#else /*ANSI*/
608void fmt_init_E_S()
609#endif
610#endif /* CICPP */
611{ int i;
612  for (i=0;i<NMAXVAR;i++) {
613      E_var[i]= (float_x) 0;
614      S_var[i]= NULL;
615  }
616}
617/*--------------------------------------------------------------------------*/
618/*                  fmt_free_S                                            */
619/*--------------------------------------------------------------------------*/
620#if CICPP
621void FMTSTRU :: fmt_free_S(int from,
622                           int to)
623#else /* CICPP */
624#if ANSI
625void fmt_free_S(int from, int to)
626#else /*ANSI*/
627void fmt_free_S(from ,to)
628int from, to;
629#endif
630#endif /* CICPP */
631{ int i;
632
633  for (i=from;i<=to;i++) {
634
635      if  (S_var[i] != NULL)
636#if 0
637       printf("Lib=[%p]\n", S_var[i]);
638#endif
639#if CICPP
640                delete [] (char *)S_var[i];
641#else /* CICPP */
642                FREE(S_var[i]);
643#endif /* CICPP */
644      S_var[i]=NULL;
645  }
646}
647
648
649/*--------------------------------------------------------------------------*/
650/*                   fmt_copy_realloc                                       */
651/*--------------------------------------------------------------------------*/
652#if CICPP
653char * FMTSTRU :: fmt_copy_realloc(char *pdest,
654                                   ALLOPARM *dest_mxlen,
655                                   char *cte_str)
656#else /* CICPP */
657#if ANSI
658char *fmt_copy_realloc(char *pdest,ALLOPARM *dest_mxlen,char *cte_str)
659#else /*ANSI*/
660char *fmt_copy_realloc(pdest,dest_mxlen,cte_str)
661                            /*Armazena cte_str em pdest        */
662  char *pdest;               /*Se necessario realloca pdest para*/
663  ALLOPARM *dest_mxlen;     /*que str_cte caiba e muda tamanho   */
664  char *cte_str;            /* max do pdest.Retorna novo endereco*/
665#endif /*ANSI*/
666#endif /* CICPP */
667 {
668      char *p;
669      ALLOPARM cte_siz;
670      cte_siz=(ALLOPARM) strlen((char *)cte_str);
671      if (*dest_mxlen<cte_siz){ /* realloca string */
672        p=fmt_alloc_char( (ALLOPARM)(cte_siz+1),"cifm3/fmt_realloc");
673        /* if (p == NULL) IFERR_GOTO; Label ERROR_LABEL is defined at fmt_inter */
674        if (p == NULL) fatal("cifm3/fmt_realloc/2");
675        strcpy(p,cte_str);
676#if CICPP
677        delete [] pdest;
678#else
679        FREE(pdest);
680#endif
681
682        *dest_mxlen=cte_siz;
683        return p;
684      }else {  /* copia apenas cte_str */
685        strcpy(pdest,cte_str);
686        return pdest; /*para efeito de compatibilizar */
687      }
688}
689/*--------------------------------------------------------------------------*/
690/*                   fmt_alloc_char                                         */
691/*--------------------------------------------------------------------------*/
692
693#if CICPP
694char * FMTSTRU :: fmt_alloc_char(ALLOPARM tam,
695                                 char *msg)
696#else /* CICPP */
697#if ANSI
698char *fmt_alloc_char(ALLOPARM tam,char *msg)
699#else /*ANSI*/
700char *fmt_alloc_char(tam,msg)
701ALLOPARM tam;
702char *msg;
703#endif /*ANSI*/
704#endif /* CICPP */
705{
706 char *t;
707#if CICPP
708  try
709  { t=(char *)new char [(tam)]; }
710  catch (BAD_ALLOC)
711  { t=(char *)ALLONULL; }
712#else /* CICPP */
713  t=(char *)ALLOC((ALLOPARM)(tam));
714#endif /* CICPP */
715  if (t == (char *)ALLONULL) {inter_error(msg); return NULL; }
716  return t;
717}
718
719
720/*--------------------------------------------------------------------------*/
721/*                   fmt_instr                                              */
722/*--------------------------------------------------------------------------*/
723#if CICPP
724int FMTSTRU :: fmt_instr(char *str_source,
725                         char *str_sub)
726#else /* CICPP */
727#if ANSI
728int fmt_instr(char *str_source,char *str_sub)
729#else /*ANSI*/
730int fmt_instr(str_source,str_sub)
731char *str_source,*str_sub;
732#endif /*ANSI*/
733#endif /* CICPP */
734{
735  char *p,*res;
736  int  pos;
737  pos=0;
738  res=NULL;
739  p=str_source;
740  res = strstr(p,str_sub);
741  if  (res!=NULL && p!=NULL && str_sub!=NULL ) {
742    if (*res && *str_sub) {
743      int ll;
744      ll=strlen(str_sub);
745      pos=1;
746      while (memcmp(p,str_sub,ll)!=0)  {
747        p++; pos++;
748     }
749   }
750 }
751  return pos;
752}
753/*--------------------------------------------------------------------------*/
754/*                   retrieve_two_numeric_operands                          */
755/*--------------------------------------------------------------------------*/
756#if CICPP
757void FMTSTRU :: take_numeric_operands_value(class_operand new_class)
758#else /* CICPP */
759#if ANSI
760void take_numeric_operands_value(class_operand new_class)
761#else /*ANSI*/
762void take_numeric_operands_value(new_class)
763class_operand new_class;
764#endif /*ANSI*/
765#endif /* CICPP */
766{
767  int_value_1=0;
768  int_value_2=0;
769  long_value_1=0L;
770  long_value_2=0L;
771  float_value_1=0.0;
772  float_value_2=0.0;
773
774
775 switch(new_class)
776 { case integer :
777        int_value_1=op1->op.i;
778        int_value_2=op2->op.i;
779        break;
780   case long_n :
781        if(op1->classe==integer) long_value_1=(LONGX) op1->op.i;
782        if(op1->classe==long_n)  long_value_1=op1->op.l;
783        if(op2->classe==integer) long_value_2=(LONGX) op2->op.i;
784        if(op2->classe==long_n)  long_value_2=op2->op.l;
785        break;
786   case float_n :
787        if(op1->classe==integer)    float_value_1=(float) op1->op.i;
788        if(op1->classe==long_n)     float_value_1=(float) op1->op.l;
789        if(op1->classe==float_n)    float_value_1=op1->op.r;
790        if(op2->classe==integer)    float_value_2=(float) op2->op.i;
791        if(op2->classe==long_n)     float_value_2=(float) op2->op.l;
792        if(op2->classe==float_n)    float_value_2=op2->op.r;
793
794        break;
795
796}
797}
798
799#if CICPP
800void FMTSTRU :: retrieve_determine_class(void)
801#else /* CICPP */
802void retrieve_determine_class()
803#endif /* CICPP */
804{
805 auxpop = pop(); IFERR_RET;
806 op2=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));
807 auxpop = pop(); IFERR_RET;
808 op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
809 if (op1->classe==string && op2->classe==string){new_class=string;}
810  else
811  { if ( (op1->classe==integer||op1->classe==float_n ||
812          op1->classe==long_n
813         ) &&
814      (op2->classe==integer || op2->classe==float_n || op2->classe==long_n) )
815      {if (op1->classe == op2->classe)
816          { new_class=op1->classe ; }
817       else {if (( op1->classe == integer || op1->classe == long_n ) &&
818                 (op2->classe == integer  || op2->classe == long_n)
819                ) new_class=long_n ;
820                else new_class=float_n;
821             }
822      }
823      else
824      {
825       inter_error("Invalid class of operands for aritmetic/string operators");
826       return;
827      }
828 }
829}
830
831/*-----------------------------------------------------------------------*/
832#if CICPP
833void  FMTSTRU :: retrieve_two_numeric_operands (void)
834#else /* CICPP */
835void  retrieve_two_numeric_operands ()
836#endif /* CICPP */
837{
838 retrieve_determine_class();
839 IFERR_RET;
840 if(new_class==string)
841 {
842    inter_error("Invalid class of operands for aritmetic operators");
843    return;
844 }
845 else  take_numeric_operands_value(new_class);
846
847} /* precedure */
848/*--------------------------------------------------------------------------*/
849/*                   retrieve_two_operands                                  */
850/*--------------------------------------------------------------------------*/
851#if CICPP
852void FMTSTRU :: retrieve_two_operands(void)
853#else /* CICPP */
854void retrieve_two_operands()
855#endif /* CICPP */
856{
857retrieve_determine_class();
858IFERR_RET;
859class_of_the_both=new_class;
860if (new_class!=string) take_numeric_operands_value(new_class);
861
862}
863
864
865/*-------------------------------------------------------------------------*/
866/*                   is_not_of_class                                       */
867/*-------------------------------------------------------------------------*/
868#define is_not_of_class(x,cl)                                    \
869  if(x!=cl) inter_error("Invalid operand class ");                 \
870
871
872/*--------------------------------------------------------------------------*/
873/*                   is_numeric                                             */
874/*--------------------------------------------------------------------------*/
875
876#if CICPP
877int FMTSTRU :: is_numeric(class_operand x)
878#else /* CICPP */
879#if ANSI
880int is_numeric(class_operand x)
881#else /*ANSI*/
882int is_numeric(x)
883class_operand x;
884#endif /*ANSI*/
885#endif /* CICPP */
886{
887   if ( !( x==integer || x==float_n || x==long_n) )
888      { inter_error("Aritmetic operand expected "); }
889 return(1);
890}
891
892
893/*--------------------------------------------------------------------------*/
894/*                   convert_to_float                                       */
895/*--------------------------------------------------------------------------*/
896#if CICPP
897float_x FMTSTRU :: convert_to_float(stack_node *top)
898#else /* CICPP */
899#if ANSI
900float_x convert_to_float(stack_node *top)
901#else /*ANSI*/
902float_x convert_to_float(top)
903stack_node *top;
904#endif /*ANSI*/
905#endif /* CICPP */
906{ float_x x;
907   is_numeric(top->classe);
908   if (top->classe == integer) x = (float_x) top->op.i;
909   if (top->classe == float_n) x = (float_x) top->op.r;
910   if (top->classe == long_n)  x = (float_x) top->op.l;
911   return (x);
912}
913
914
915
916/*------------------------------------------------------------------------*/
917/*                   save_context                                         */
918/*------------------------------------------------------------------------*/
919
920#if CICPP
921void  FMTSTRU :: save_context(int modify_pointers)
922#else /* CICPP */
923#if ANSI
924void  save_context(int modify_pointers)
925#else /*ANSI*/
926void  save_context(modify_pointers)
927int modify_pointers;
928#endif /*ANSI*/
929#endif /* CICPP */
930{
931
932#if DEB_FLOAT
933   printf("\n++Save_context l_w=%"_LD_" nextcc=%"_LD_" pout=%d \nout=%s|",
934          lw_inter,nextcc,pout,out);
935#endif
936      elem.classe=next_cc;
937      elem.op.l=nextcc;
938      push(&elem);
939      IFERR_RET;
940
941      elem.classe=xindex;
942      elem.op.i=pout;
943      push(&elem);
944      IFERR_RET;
945
946      elem.classe=l_w;
947      elem.op.l=lw_inter;
948      push(&elem);
949      IFERR_RET;
950
951      elem.classe=ptr;
952      elem.op.address= &out[0];
953      push(&elem);
954      IFERR_RET;
955
956      /* define new context */
957
958        out= &out[pout];
959        pout=0;
960#if TRACESINDO
961      address_out=out;
962#endif
963       /* These pointers must not be modified for the REF function */
964      if (modify_pointers==true)
965       {
966                 lw_inter= MAXMFRL; /* no limits*/ /* aot - svd 8000L */
967                 nextcc=1;
968       }
969
970}
971
972/*--------------------------------------------------------------------------*/
973/*                   restore_context                                        */
974/*--------------------------------------------------------------------------*/
975
976#if CICPP
977void FMTSTRU :: restore_context(void)
978#else /* CICPP */
979void restore_context()
980#endif /* CICPP */
981{
982#if DEB_FLOAT
983     int i;
984#endif
985     tmp_ptr= &out[0];  /*save old string */
986
987      /*restore  the  context */
988     auxpop = pop(); IFERR_RET;
989     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
990     is_not_of_class(top->classe,ptr);
991     IFERR_RET;
992     out=top->op.address;
993     address_out=out;
994
995     auxpop = pop(); IFERR_RET;
996     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
997     is_not_of_class(top->classe,l_w);
998     IFERR_RET;
999     lw_inter=top->op.l;
1000
1001     auxpop = pop(); IFERR_RET;
1002     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
1003     is_not_of_class(top->classe,xindex);
1004     if (fmt_error) return;
1005     pout=top->op.i;
1006
1007     auxpop = pop(); IFERR_RET;
1008     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
1009     is_not_of_class(top->classe,next_cc);
1010     IFERR_RET;
1011      nextcc=top->op.l;
1012#if DEB_FLOAT
1013printf("\n++Rest_ctext l_w=%"_LD_" nextcc=%"_LD_" pout=%d \nout=%s|\n",
1014          lw_inter,nextcc,pout,out);
1015
1016     if (pout>5) {
1017            for (i=pout-5;i<=pout;i++)printf("%c",out[i]);
1018                  printf("*");
1019     }
1020#endif
1021
1022}
1023
1024/*--------------------------------------------------------------------------*/
1025/*                   sub_string                                             */
1026/*--------------------------------------------------------------------------*/
1027#if CICPP
1028char * FMTSTRU :: sub_string(char source[],
1029                             int offset,
1030                             int length)
1031#else /* CICPP */
1032#if ANSI
1033char *sub_string(char source[],
1034                 int offset,
1035                 int length)
1036#else /*ANSI*/
1037char *sub_string(source,offset,length)
1038char source[];
1039int offset;
1040int length;
1041#endif /*ANSI*/
1042#endif /* CICPP */
1043{
1044int fd_len;
1045char *q;
1046
1047q=source;
1048
1049fd_len=strlen(source);
1050if(offset<0 || length<0) return(q);
1051if(offset >= fd_len) *q=null_char;
1052 else
1053  {
1054  q= &source[offset];
1055  fd_len=fd_len-offset;
1056  if(fd_len>length)q[length]=null_char;
1057  }
1058 return q;
1059 }
1060
1061#if !CICPP
1062static char *retorno;
1063#endif /* CICPP */
1064
1065
1066/*--------------------------------------------------------------------------*/
1067/*                   store tmp_string                                       */
1068/*--------------------------------------------------------------------------*/
1069#if CICPP
1070char * FMTSTRU :: store_tmp_string (char *str)
1071#else /* CICPP */
1072#if ANSI
1073char *store_tmp_string (char *str)
1074#else /*ANSI*/
1075char *store_tmp_string (str)
1076char *str;
1077#endif /*ANSI*/
1078#endif /* CICPP */
1079{
1080 int len;
1081
1082 if (!str) str=""; /* AOT 04/03/97 */
1083 len=strlen(str);
1084#if DEB_FLOAT
1085  printf("\n--Storetmp str=%s|\nlen=%d",str,len);
1086#endif
1087 if(tmp_str_index+len > max_tmp_str)
1088 {
1089   inter_error("No room to store temporary strings - change MAX_TMP_STR");
1090   return NULL;
1091 }
1092 strcpy(&tmp_str[tmp_str_index],str);
1093 retorno= &tmp_str[tmp_str_index];
1094 tmp_str_index += len+1;
1095 return retorno;
1096 }
1097
1098
1099
1100
1101/*--------------------------------------------------------------------------*/
1102/*                   cast_to_int                                            */
1103/*--------------------------------------------------------------------------*/
1104#if CICPP
1105int FMTSTRU :: cast_to_int (stack_node *e)
1106#else /* CICPP */
1107#if ANSI
1108int cast_to_int (stack_node *e)
1109#else /*ANSI*/
1110int cast_to_int (e)
1111stack_node *e;
1112#endif /*ANSI*/
1113#endif /* CICPP */
1114{int tmp;
1115 if (e->classe == integer) tmp=e->op.i;
1116 if (e->classe == long_n ) tmp=(int )e->op.l;
1117 if (e->classe == float_n) tmp= (int) e->op.r;
1118 return (tmp);
1119}
1120/*--------------------------------------------------------------------------*/
1121/*                   push                                                   */
1122/*--------------------------------------------------------------------------*/
1123#if CICPP
1124void FMTSTRU :: push (stack_node *e)
1125#else /* CICPP */
1126#if ANSI
1127void push (stack_node *e)
1128#else /*ANSI*/
1129void push (e)
1130stack_node *e;
1131#endif /*ANSI*/
1132#endif /* CICPP */
1133{
1134 stack_pt++;
1135 if(stack_pt >= max_stack)                              /* AOT - 27/11/91 */
1136 {
1137   inter_error("Stack overflow - expression too complex ");
1138   return;
1139 }
1140 stack[stack_pt].classe=e->classe;
1141 stack[stack_pt].op=e->op;
1142 }
1143
1144/*--------------------------------------------------------------------------*/
1145/*                   pop                                                    */
1146/*--------------------------------------------------------------------------*/
1147#if CICPP
1148FMTSTRU :: stack_node * FMTSTRU :: pop(void)
1149#else /* CICPP */
1150stack_node *pop()
1151#endif /* CICPP */
1152{
1153  static stack_node rr;
1154  static stack_node *prr;
1155 prr= &rr;
1156 if(stack_pt<1){inter_error("Stack underflow"); return NULL;}
1157 rr.classe=stack[stack_pt].classe;
1158 rr.op=stack[stack_pt].op;
1159 stack_pt--;
1160 return prr;
1161}
1162
1163
1164/*--------------------------------------------------------------------------*/
1165/*                   exec_percent                                           */
1166/* Applies de % rules to the output string "out" pointed by "outs"          */
1167/* A07 - Rotina com erro: retirava todos os "newline" do fim da linha e     */
1168/*       na verdade tem que deixar apenas um                                */
1169/*       Retorna 0 se nao ficaram caracteres de "muda-linha"                */
1170/*              >0 caso contrario                                           */
1171/*--------------------------------------------------------------------------*/
1172
1173#if CICPP
1174int FMTSTRU :: exec_percent(char *out,
1175                            int  *outs,
1176                            LONGX *ncc)
1177#else /* CICPP */
1178#if ANSI
1179int exec_percent(char *out,
1180                  int  *outs,
1181                  LONGX *ncc)
1182#else /*ANSI*/
1183int exec_percent(out,outs,ncc)
1184char *out;
1185int *outs;
1186LONGX *ncc;
1187#endif /*ANSI*/
1188#endif /* CICPP */
1189{
1190 int nnl,k,noend;
1191 k= *outs;
1192 noend=true;
1193 nnl=0;
1194
1195 /* Determina quantos "muda_linha existem no string" */
1196 while( noend==true && k>nl_LEN){
1197   noend=fmt_CRLF(out,k);
1198   if (noend==true){
1199       k=k-nl_LEN;
1200       nnl++;
1201   }
1202 } /*while*/
1203
1204 if (nnl>1) {
1205#if MICRO_ISIS_COMPATIBLE
1206   /* Retira os nnl-1 "muda-linha" excedentes */
1207   nnl--;
1208#endif
1209   k=*outs-nnl*nl_LEN;
1210   out[k]=null_char;
1211   *outs=k;
1212   *ncc=1;
1213 }
1214 return nnl;
1215#if 0
1216 *outs=k;
1217 /* end string and modify pointer */
1218 /* calculate the  lentgh of the last line to set up nextcc */
1219 nnl=1;
1220 while( !fmt_CRLF(out,k) &&k>1)
1221 { l++;k--;}
1222 *ncc=l;
1223#endif
1224} /*percent */
1225
1226
1227
1228/*--------------------------------------------------------------------------*/
1229/*                   trata_md                                               */
1230/*--------------------------------------------------------------------------*/
1231
1232#if CICPP
1233char * FMTSTRU :: trata_md(instruction_code mode,
1234                           char            *s,
1235                           int             *final_added,
1236                           char           **tofreep)
1237#else /* CICPP */
1238#if ANSI
1239char *trata_md(instruction_code mode,
1240               char            *s,
1241               int             *final_added,
1242               char           **tofreep)
1243#else /*ANSI*/
1244char *trata_md(mode,s,final_added,tofreep)
1245instruction_code mode;
1246char *s;
1247int *final_added;
1248char **tofreep;
1249#endif /*ANSI*/
1250#endif /* CICPP */
1251{
1252 char *q;               /* now via ALLOC() */
1253 char *pq;
1254
1255 char c;
1256 int i,j,k,fim,len;
1257 int menor;
1258
1259 *tofreep=NULL;
1260
1261 /* for mpl and mpu modes there's no change in the filling information */
1262
1263 if(mode==mpu_par || mode==mpl_par)
1264 {
1265  return s;
1266 }
1267
1268 if((len=strlen(s))==0) return s;
1269#if !RETIRAR
1270  Consultar Adalberto/Piva
1271  #if CICPP
1272    try
1273    { q=(char *)new char [(len+3+9+1)]; }
1274    catch (BAD_ALLOC)
1275    { q=(char *)ALLONULL; }
1276  #else /* CICPP */
1277    q=(char *)ALLOC((ALLOPARM)(len+3+9+1));
1278  #endif /* CICPP */
1279  if (q == (char *)ALLONULL) {inter_error("trata_md/ALLOC"); return NULL; }
1280#else
1281  q=fmt_alloc_char((ALLOPARM)(len+3+9+1),"trata_md/ALLOC");
1282#endif /*RETIRAR */
1283
1284 *tofreep=q;
1285
1286 pq=q;
1287 i=0;
1288 j=0;
1289 menor=false;
1290 fim=false;
1291 *final_added=0;
1292 q[0]=null_char;
1293
1294while (fim==false)
1295{
1296#if TRACE_COMP_M
1297if( s[i]==null_char ) if (fmttrace) printf(" \n achou null no comeco mode");
1298#endif /* TRACE_COMP_M */
1299c= s[i];
1300
1301/* first stores a character into the output; then verifies if the
1302   character had to be stored or must be eliminated */
1303
1304 q[j]=c;
1305 i++;
1306 j++;
1307
1308if (c==null_char)
1309 { /* string analisis has finished
1310      for mdu and mdl two blanks and a punctuation mark( if none)
1311      has to be added;
1312      for mhu and mhl nothing is added
1313   */
1314
1315
1316  if(mode==mhl_par || mode==mhu_par)
1317       {
1318         pq= sub_field_change(pq);
1319         return pq;
1320       }
1321  /* aplica pontuacao */
1322  fim=false;
1323  for (k=j-1;k>=0 && fim==false; k--)
1324   {if(q[k]!=' ') fim=true;}
1325  if( !ispunctuation(q[k]) )
1326      {
1327      *final_added=1;
1328       k++;
1329       q[k]='.';
1330      }
1331  k++;
1332  q[k++]=' ';
1333  q[k++]=' ';
1334  q[k]=null_char;
1335  *final_added= *final_added+2;
1336   pq= sub_field_change(pq);
1337   return pq;
1338  }
1339
1340  if ((c==equal_char) && (menor==true))
1341   {  /* ignores the string after "="
1342                                for the constructions like <100=hundred> */
1343     while (( s[i]!=null_char) && (s[i]!=greater_char)) {
1344           i=i+1;}
1345     /* ignore all chars befor e < */
1346    if (s[i]==greater_char)
1347       {
1348         if (s[i+1]==less_char)
1349           { q[j-1]=';' ;
1350             q[j]=' ';
1351             j++;
1352             i++;
1353           }
1354          else {
1355                menor=false;
1356                j--;
1357                }
1358       }
1359      else {  /* s[i]=null_char. Retira o "=" */
1360            j--;
1361            q[j]=null_char;
1362            fim=true;
1363            fim=false; /* SVD - 25/09/94  Erro Mas Aceita */
1364           }
1365    } /*c=eql_char..*/
1366  else { if (c==less_char)
1367          {  menor=true;
1368            j--;
1369           }
1370          else
1371             { if (c==greater_char)
1372                   {
1373                    if (s[i]==less_char)
1374                      { q[j-1]=';';
1375                        q[j]=' ';
1376                        j++;
1377                        i++;
1378                        menor=true;
1379                        }
1380                       else {
1381                              j--;
1382                             }
1383                 }
1384             }
1385        }
1386
1387   }
1388
1389/* 25-09-94
1390  Esta dando erro quando um string tem no fim uma sequencia  do tipo "<x=y"
1391   O MicroIsis assume um ">" e eu estava indicando erro.
1392   Para deixar como ISIS , retorna o string que foi conseguido  enquanto
1393   procurava o ">".
1394  ( Acho que a  parte de tratamento de sequencias  "..><.." pelo MicroIsis
1395    esta incoerente com a  documentacao .
1396    Nao vou mexer na minha implementacao sem saber qual a implementacao correta
1397  )
1398    E importante notar que se o campo contem ">" ou "<"estes sao sempre
1399   ignorados.
1400
1401   Precisa forcar a colocar a pontuacao e tratamento de subfield.
1402   Para isso basta mudar a condicao de fim=true  para fim=false quando
1403   nao achou   o ">". Assim forca a repetir o loop e o proximo caracter
1404   a ser tratado e'c=null_char o que vai fazer com que execute a pontuacao
1405
1406   return("rot.c/trata_md/<100=hundred>");
1407*/
1408
1409   return(s);   /* AOT/RP - 21/10/94 (ver com Sindo) */
1410}
1411
1412
1413/*------------------------------------------------------------------------*/
1414/*                  sub_field_string                                      */
1415/*------------------------------------------------------------------------*/
1416#if CICPP
1417void FMTSTRU :: sub_field_string(char *q,
1418                                 char sub)
1419#else /* CICPP */
1420#if ANSI
1421static void sub_field_string(char *q,char sub)
1422#else /*ANSI*/
1423static void sub_field_string(q,sub)
1424char *q;
1425char sub;
1426#endif /*ANSI*/
1427#endif /* CICPP */
1428{
1429char *ss,*p;
1430char *t,r[3];
1431int len;
1432
1433len=strlen(q);
1434
1435if(len==0) return;
1436
1437if(sub==subfield_null) return;
1438#if !RETIRAR
1439#if CICPP
1440 try
1441 { ss=(char *)new char [(len+1)]; }
1442  catch (BAD_ALLOC)
1443 { ss=(char *)ALLONULL; }
1444#else /* CICPP */
1445ss=(char *)ALLOC((ALLOPARM)(len+1));
1446#endif /* CICPP */
1447 if (ss == (char *)ALLONULL) {inter_error("sub_field_string/ALLOC"); return; }
1448#else
1449 ss=fmt_alloc_char((ALLOPARM)(len+1),"sub_field_string/ALLOC");
1450#endif
1451 if (ss == (char *)ALLONULL) return;
1452
1453ss[0]=null_char;
1454r[0]=SFLDCHR;
1455r[1]=' ';
1456r[2]=null_char;
1457t=q;
1458
1459if(sub==multiply_char)     /* any subfield */
1460 {
1461 if (len >=2 )
1462   {
1463   if (*t==SFLDCHR) {t++; t++;}  /* ignores 2 char " ^char" */
1464   }
1465   /*  len < 2  or not SFLDCHR => It is not a field with subfield */
1466 }
1467 else
1468 { /* search the substring "^char"  using upper and lower cases */
1469  r[1]=tolower(sub);
1470  t=strstr(q,r);
1471  if(t==nulo)
1472   {
1473     r[1]=toupper(sub);
1474     t=strstr(q,r);
1475   }
1476
1477   if(t==nulo) {
1478       q[0]=null_char;
1479#if CICPP  /*ifcmm*/
1480      delete [] ss;
1481#else /*elsecmm*/
1482      FREE(ss);
1483#endif /*CICPP*/  /*endcmm*/
1484      return;
1485  }
1486
1487   /* copies the substring from t to the end or until another substring delimiter */
1488   t++;
1489   t++;  /* ignores the delimiters */
1490 }
1491
1492 p=ss;
1493 while ( (*t!=null_char) && (*t!=SFLDCHR) ) {
1494        if (*t == '\\') if (*(t+1) == SFLDCHR) t++;
1495        if (*t == null_char) break;
1496        *p++ = *t++;
1497 }
1498
1499 /* string termination */
1500 *p=null_char;
1501 strcpy(q,ss);
1502#if CICPP
1503 delete [] (char *)ss;
1504#else /* CICPP */
1505 FREE(ss);
1506#endif /* CICPP */
1507 return;
1508}
1509
1510
1511#if !CICPP
1512
1513/* rotinas aritmeticas */
1514static char str_num[30],*pstr_num;
1515static LONGX ref_mfn_number;
1516/* end rotinas aritmeticas */
1517
1518/* f function variables*/
1519static int min_width;
1520static int dec_places;
1521/* end f-function variables */
1522
1523#if DINALLOC
1524static char *v_fd_value;
1525static char *v_fd_tmp;
1526#else
1527static char v_fd_value[MAX_FD_VALUE+1];
1528static char v_fd_tmp[MAX_FD_TMP+1];
1529#endif
1530
1531static char *fd_value,*fd_tmp;
1532
1533static LONGX lineqtt; /* RPIVA/AOT/HB - 16/11/98 */
1534
1535#endif /* CICPP */
1536
1537/* ----------------------------- cifm3h.c --------------------------- */
1538
1539/*------------------------------------------------------------------------*/
1540/*    file: cifm3h.c                                                      */
1541/*------------------------------------------------------------------------*/
1542#if !CICPP
1543
1544#define PRT_DBNAME 0
1545#define DEB_NOCC   0
1546/* Continue em grupos repetitivos  17-7-94 */
1547static int continue_rgroup_maxocc;
1548static int continue_rgroup;
1549static char cc;
1550static int pos;
1551static int fmt_fim;
1552static int fmt_n_ref;
1553static int must_repeat;
1554static l_code *ni;
1555static l_code *rpni; /*repf*/
1556static float_x float_exp_value;
1557static field_definition_node *itf;
1558static RECSTRU *recp;
1559#if !CICPP /*if!cmm*/
1560#define MAXREFS 16
1561static LONGX vprats[MAXREFS];
1562static int currprat=0;
1563static LONGX trm_prat;
1564static LONGX irec;
1565#endif /*CICPP*/  /*endcmm*/
1566static char *firstdbnp;
1567
1568#if ANSI
1569static  char *fmt_get_date(int parmdate, LONGX secs0);
1570static  float_x fmt_cnv_to_float(stack_node *top);
1571static  LONGX    fmt_cnv_to_long(stack_node *top);
1572static  void fmt_init_vinstr(l_code *pins,int nnested );
1573static  int fmt_load_all_occ(void);
1574static  void fmt_load_next_occ(void);
1575static  void fmt_comum_ref_beg(void);
1576static  void fmt_comum_ref_end(void);
1577static   void   fmt_inicio_grupos_vfields(instruction_code instr_inicial,
1578                                          instruction_code instr_final);
1579#else
1580static  char *fmt_get_date();
1581static  float_x fmt_cnv_to_float();
1582static  LONGX    fmt_cnv_to_long();
1583static  void fmt_init_vinstr();
1584static  int fmt_load_all_occ();
1585static  void fmt_load_next_occ();
1586static  void fmt_comum_ref_beg();
1587static  void  fmt_comum_ref_end();
1588static  void  fmt_inicio_grupos_vfields();
1589#endif
1590
1591#endif /* CICPP */
1592
1593/* ------------------------field value  ----------------------------- */
1594
1595#if CICPP
1596char * FMTSTRU :: field_value(char *sfieldvalue,
1597                              LONGX  max_sfield,
1598                              int   dd)
1599#else /* CICPP */
1600#if ANSI
1601char *field_value(char *sfieldvalue,
1602                  LONGX  max_sfield,
1603                  int   dd)
1604#else /*ANSI*/
1605char *field_value(sfieldvalue,max_sfield,dd)
1606char *sfieldvalue;
1607LONGX max_sfield;
1608int dd;
1609#endif /*ANSI*/
1610#endif /* CICPP */
1611{
1612    int slen;
1613
1614    if (dd < 0 || dd >= (int)(MFRnvf) ) {
1615      sfieldvalue[0]=null_char;
1616      if (fmttrace)
1617        printf("field_value - dd=%d tag=undefined '%s'\n",
1618                                        dd,sfieldvalue);
1619      return (sfieldvalue);
1620    }
1621
1622    slen=DIRlen(dd);
1623
1624    if (slen > max_sfield) {
1625        slen=max_sfield-3;
1626        memcpy(sfieldvalue,FIELDP(dd),slen);
1627        sprintf(sfieldvalue+slen,"+++");
1628        if (fmttrace) printf("%s MAX_SFIELD=%"_LD_"\n",sfieldvalue+slen,slen);
1629    }
1630    else {
1631        memcpy(sfieldvalue,FIELDP(dd),slen);
1632        sfieldvalue[slen]='\0';
1633    }
1634    if (fmttrace)
1635        printf("field_value - dd=%d tag=%u '%s'\n",
1636                                        dd,DIRtag(dd),sfieldvalue);
1637    return (sfieldvalue);
1638}
1639
1640
1641/*-------------------------------------------------------------------------*/
1642/*          fmt_get_date                                                   */
1643/*-------------------------------------------------------------------------*/
1644#if CICPP
1645char  * FMTSTRU :: fmt_get_date(int parmdate, LONGX secs0)
1646#else /* CICPP */
1647#if ANSI
1648char  *fmt_get_date(int parmdate, LONGX secs0)
1649#else /*ANSI*/
1650char  *fmt_get_date(parmdate,secs0)
1651int parmdate;
1652LONGX secs0;
1653#endif /*ANSI*/
1654#endif /* CICPP */
1655{
1656 static char fmt_date[21+1]; /* aaaammdd hhmmss WDAY YDAY */
1657                             /* 1234567890123456 7  8 901 */
1658 time_t secs_now;
1659 struct tm *tp;
1660#if BEFORE20010216
1661#else
1662 if (secs0 >= 0) {
1663/*The allowable range of calendar times is Jan 1 1970 00:00:00 to Jan 19 2038 03:14:07.
1664*/
1665     if (secs0 < 86400)      secs0=86400;      /* seconds('19700102 000000') */
1666     if (secs0 > 2147408047) secs0=2147408047; /* seconds('20380118 031407') */
1667     secs_now=secs0;
1668 } else
1669#endif
1670 time(&secs_now);
1671/*time gives the current time, in seconds, elapsed since 00:00:00 GMT, January 1, 1970,
1672 and stores that value in the location pointed to by timer, provided that timer is not a NULL pointer.
1673*/
1674 tp=localtime(&secs_now);
1675/*localtime accepts the address of a value returned by time and returns a pointer to the structure of type tm containing the time elements.
1676It corrects for the time zone and possible daylight saving time.
1677The global LONGX variable _timezone contains the difference in seconds between GMT and local standard time (in PST, _timezone is 8 x 60 x 60). The global variable daylight contains nonzero only if the standard U.S. daylight saving time conversion should be applied. These values are set by tzset, not by the user program directly.
1678*/
1679 switch (parmdate) {
1680 case DATEONLY:
1681   sprintf(fmt_date,"%02d/%02d/%02d",
1682                     tp->tm_mday,tp->tm_mon+1,tp->tm_year%100);
1683 break;
1684 case DATETIME:
1685   sprintf(fmt_date,"%02d/%02d/%02d %02d:%02d:%02d",
1686                     tp->tm_mday,tp->tm_mon+1,tp->tm_year%100,
1687                     tp->tm_hour,tp->tm_min,tp->tm_sec);
1688   break;
1689 case 1:   /*A11 compatibilidade com microisis */
1690   sprintf(fmt_date,"%02d-%02d-%02d  %02d:%02d:%02d",
1691                     tp->tm_mon+1,tp->tm_mday,tp->tm_year%100,
1692                     tp->tm_hour,tp->tm_min,tp->tm_sec);
1693
1694   break;
1695 case 2:
1696   sprintf(fmt_date,"%02d-%02d-%02d",
1697                     tp->tm_mon+1,tp->tm_mday,tp->tm_year%100);
1698   break;
1699 case 3:
1700    sprintf(fmt_date,"%02d:%02d:%02d",
1701                     tp->tm_hour,tp->tm_min,tp->tm_sec);
1702    break;
1703 default:
1704 sprintf(fmt_date,"%04d%02d%02d %02d%02d%02d %1d %3d",
1705                   1900+tp->tm_year,tp->tm_mon+1,tp->tm_mday,
1706                   tp->tm_hour,tp->tm_min,tp->tm_sec,
1707                   tp->tm_wday,tp->tm_yday);
1708 }
1709 return (char *)fmt_date;
1710
1711}
1712/*-------------------------------------------------------------------------*/
1713/*          fmt_cnv_to_long                                                */
1714/*-------------------------------------------------------------------------*/
1715#if CICPP
1716LONGX FMTSTRU :: fmt_cnv_to_long(stack_node *top)
1717#else /* CICPP */
1718#if ANSI
1719LONGX fmt_cnv_to_long(stack_node *top)
1720#else /*ANSI*/
1721LONGX fmt_cnv_to_long(top)
1722stack_node *top;
1723#endif /*ANSI*/
1724#endif /* CICPP */
1725{ static LONGX tmp_long;
1726
1727 if (top->classe==long_n) tmp_long=top->op.l;
1728   else
1729    if (top->classe==float_n) tmp_long=(LONGX) top->op.r;
1730      else if(top->classe==integer) tmp_long =(LONGX )top->op.i;
1731          else fatal("fmt_inter/Invalid number type ");
1732 return tmp_long;
1733}
1734/*-------------------------------------------------------------------------*/
1735/*          fmt_cnv_to_float                                               */
1736/*-------------------------------------------------------------------------*/
1737#if CICPP
1738float_x FMTSTRU :: fmt_cnv_to_float(stack_node *top)
1739#else /* CICPP */
1740#if ANSI
1741float_x fmt_cnv_to_float(stack_node *top)
1742#else /*ANSI*/
1743float_x fmt_cnv_to_float(top)
1744stack_node *top;
1745#endif /*ANSI*/
1746#endif /* CICPP */
1747{ static float_x tmp_float;
1748
1749 if (top->classe==long_n) tmp_float=(float_x ) (top->op.l);
1750   else
1751    if (top->classe==float_n) tmp_float=(float_x) top->op.r;
1752      else if(top->classe==integer) tmp_float=(float_x )top->op.i;
1753          else fatal("fmt_inter/Invalid number type ");
1754 return tmp_float;
1755}
1756
1757/*-------------------------------------------------------------------------*/
1758/*          fmt_init_vinstr                                                */
1759/*-------------------------------------------------------------------------*/
1760#if CICPP
1761void FMTSTRU :: fmt_init_vinstr(l_code *ptr_ins,
1762                                int     nnested)
1763#else /* CICPP */
1764#if ANSI
1765void fmt_init_vinstr(l_code *ptr_ins,
1766                     int     nnested)
1767#else /*ANSI*/
1768void fmt_init_vinstr(ptr_ins, nnested )
1769l_code *ptr_ins;
1770int  nnested;
1771#endif /*ANSI*/
1772#endif /* CICPP */
1773{
1774  int tmp_occ;
1775  if ( (infoi(ptr_ins)==test_occ)  ||  (infoi(ptr_ins)==load_field_all) ||
1776       (infoi(ptr_ins)==absent)    ||  (infoi(ptr_ins)==load_field_occ) ||
1777       (infoi(ptr_ins)==present)   ||  (infoi(ptr_ins)==print_field)    ||
1778       (infoi(ptr_ins)==noccins)   )
1779  { itf=(field_definition_node *) iadd(ptr_ins);
1780    itf->max_occ= -1;
1781    itf->actual_occ=0;
1782    itf->last_occ=0;
1783    itf->first_occ=0;
1784    /* Implementar continue dentro de groupo repetitivo  17-7-94*/
1785     if(nnested==1){
1786#if CICPP  /*ifcmm*/
1787       tmp_occ=recp->xnocc(itf->tag);
1788#else /*elsecmm*/
1789       tmp_occ=nocc(irec,itf->tag);
1790#endif /*CICPP*/  /*endcmm*/
1791       if (tmp_occ>continue_rgroup_maxocc)continue_rgroup_maxocc=tmp_occ;
1792    }
1793   }
1794}
1795/*-------------------------------------------------------------------------*/
1796/*          fmt_inicio_grupos_vfields                                      */
1797/*-------------------------------------------------------------------------*/
1798/*DOC 010:
1799 No inicio de um novo grupo e' necesario guardar o contexto
1800 em que o formato esta sendo executado e inicializar essas
1801 variaveis. Esse contexto e representado pelas variaveis
1802  rep_group
1803  next_rep_occ
1804  must_repeat.
1805 Os contadores das  instrucoes que referenciam Fields (Vfields)
1806 devem ser inicializados para permitir repeticao dentro
1807 de repeticao para implementar o novo conceito de fields repetitivos.
1808 O grupo de instrucoes que deve ser inicializado e' delemitado pelas
1809 variaveis (instrucao_inicial, instrucao_final).
1810 No caso de grupo repetitivo  a proxima instrucao gerada vai incializar
1811 as variaveis do contexto.
1812*/
1813#if CICPP
1814void   FMTSTRU :: fmt_inicio_grupos_vfields(instruction_code instr_inicial,
1815                                            instruction_code instr_final)
1816#else /* CICPP */
1817#if ANSI
1818void   fmt_inicio_grupos_vfields(instruction_code instr_inicial,
1819                                 instruction_code instr_final)
1820#else /*ANSI*/
1821void   fmt_inicio_grupos_vfields(instr_inicial,instr_final)
1822instruction_code instr_inicial,instr_final;
1823#endif /*ANSI*/
1824#endif /* CICPP */
1825{
1826   elem.classe=logical;
1827   elem.op.l=rep_group;
1828   push(&elem);
1829   IFERR_RET;
1830   rep_group=false;
1831
1832   elem.classe=integer;
1833   elem.op.i=next_rep_occ;
1834   push(&elem);
1835   IFERR_RET;
1836   next_rep_occ=0;
1837
1838   elem.classe=logical;
1839   elem.op.boolean=must_repeat;
1840   push(&elem);
1841   IFERR_RET;
1842   must_repeat=false;
1843/* Continue em grupos repetitivos  17-7-94 */
1844
1845   elem.classe=integer;
1846   elem.op.i=continue_rgroup_maxocc;
1847   push(&elem);
1848   IFERR_RET;
1849   continue_rgroup_maxocc=0;
1850#if TRACE_REPF
1851       printf("\n [Beg_init_rep <push>] rep_goup=%d next_rep_occ=%d",
1852               rep_group,next_rep_occ);
1853#endif
1854   fmt_fim=false;
1855   fmt_n_ref=1;
1856   /* Continue em grupos repetitivos 17-7-94 */
1857   continue_rgroup_maxocc=0;
1858   rpni=(l_code *)ni->next;
1859   while (fmt_fim==false) {
1860      if(infoi(rpni)==instr_inicial) fmt_n_ref++;
1861      if(infoi(rpni)==instr_final  ) fmt_n_ref--;
1862      if(fmt_n_ref==0)  fmt_fim=true;
1863        else {
1864           /* Continue em grupos repetitivos 17-7-94 */
1865           /* Inicializa contadores de instrucoes que referenciam fields
1866              para determinar o numero maximo de ocorrencias dos campos
1867              Notar que quando funcionar grupos repetitivos aninhados
1868              so interessam o do primeiro nivel. Para o microsisis
1869              original , esse aninhamento nao e possivel. */
1870           fmt_init_vinstr(rpni,fmt_n_ref);
1871      }
1872      rpni=(l_code *)rpni->next;
1873    }
1874}
1875/*-------------------------------------------------------------------------*/
1876/*          fmt_fim_grupos_vfields                                         */
1877/*-------------------------------------------------------------------------*/
1878#if CICPP
1879void    FMTSTRU :: fmt_fim_grupos_vfields(void)
1880#else /* CICPP */
1881void    fmt_fim_grupos_vfields()
1882#endif /* CICPP */
1883{
1884  /* Implementacao de continue 17-7-94 */
1885  auxpop = pop(); IFERR_RET;
1886  op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
1887  is_not_of_class(op1->classe,integer);
1888  IFERR_RET;
1889  continue_rgroup_maxocc=op1->op.i ;
1890
1891  auxpop = pop(); IFERR_RET;
1892  op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
1893  is_not_of_class(op1->classe,logical);
1894  IFERR_RET;
1895  must_repeat=op1->op.boolean ;
1896
1897  auxpop = pop(); IFERR_RET;
1898  op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
1899  is_not_of_class(op1->classe,integer);
1900  IFERR_RET;
1901  next_rep_occ=op1->op.i ;
1902
1903  auxpop = pop(); IFERR_RET;
1904  op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
1905  is_not_of_class(op1->classe,logical);
1906  IFERR_RET;
1907  rep_group=op1->op.boolean ;
1908}
1909
1910/*-------------------------------------------------------------------------*/
1911/*          fmt_load_all_occ                                            */
1912/*-------------------------------------------------------------------------*/
1913#if CICPP
1914int FMTSTRU :: fmt_load_all_occ(void)
1915#else /* CICPP */
1916int fmt_load_all_occ()
1917#endif /* CICPP */
1918{
1919   int occ;
1920   occ=0;
1921   *fd_value=null_char;
1922   itf=(field_definition_node *) iadd(ni);
1923#if CICPP  /*ifcmm*/
1924   itf->max_occ=recp->xnocc(itf->tag);
1925#else /*elsecmm*/
1926   itf->max_occ=nocc(irec,itf->tag);
1927#endif /*CICPP*/  /*endcmm*/
1928   /* inicio implementacao [x:y] */
1929   itf->execlower=abs(itf->lower);
1930   itf->execupper=abs(itf->upper);
1931   if (itf->lower==LASTVAL) itf->execlower=itf->max_occ;
1932   if (itf->upper==LASTVAL) itf->execupper=itf->max_occ;
1933   /* fim  implementacao [x:y] */
1934   /* we must verify in which occurrences the subfield appears */
1935   while (itf->max_occ > itf->actual_occ ) {
1936        if ( ( itf->actual_occ+1 < itf->execlower)  ||
1937             ( itf->actual_occ+1> itf->execupper) ) {
1938             itf->actual_occ ++;
1939             continue ;
1940        }
1941      *fd_tmp=null_char;
1942      itf->actual_occ++;
1943#if CICPP  /*ifcmm*/
1944      pos=recp->xfieldx(itf->tag,itf->actual_occ );
1945#else /*elsecmm*/
1946      pos=fieldx(irec,itf->tag,itf->actual_occ );
1947#endif /*CICPP*/  /*endcmm*/
1948      field_value(fd_tmp,max_fd_tmp,pos);
1949#if DEB_NOCC
1950      printf("\n fd_tmp=%s",fd_tmp);
1951#endif
1952      sub_field_string(fd_tmp,itf->sub_field);
1953#if !FATRAP
1954      if (fmterror) return -1;
1955#endif
1956#if DEB_NOCC
1957      printf("\n fd_tmp=%s",fd_tmp);
1958#endif
1959      if (itf->offset != -1 && itf->length != -1)
1960         fd_tmp=sub_string(fd_tmp,itf->offset,itf->length);
1961#if DEB_NOCC
1962      printf("\n fd_tmp=%s",fd_tmp);
1963#endif
1964       if(strlen(fd_tmp)!=0) {
1965         occ++;
1966         if(itf->first_occ==0) itf->first_occ=itf->actual_occ;
1967         itf->last_occ=itf->actual_occ;
1968       }
1969       strcat(fd_value,fd_tmp);
1970#if DEB_NOCC
1971      printf("\n fd_value=%s occ=%d",fd_value,occ);
1972#endif
1973#if DEB_FLOAT
1974       trace_field(itf,fd_tmp);
1975       trace_field(itf,fd_value);
1976#endif
1977   }
1978   itf->actual_occ=0;
1979
1980   if (fmttrace) trace_field(itf,fd_tmp);        /* AOT 26/12/91 */
1981   return occ;
1982}
1983/*-------------------------------------------------------------------------*/
1984/*          fmt_load_next_occ                                             */
1985/*-------------------------------------------------------------------------*/
1986#if CICPP
1987void FMTSTRU :: fmt_load_next_occ(void)
1988#else /* CICPP */
1989void fmt_load_next_occ()
1990#endif /* CICPP */
1991{ /*[:] Para grupo repetitivo pega somente e sempre o limite
1992        inferior da ocorrencia
1993  */
1994  int occx;
1995  *fd_value=null_char;
1996  occx=itf->actual_occ;
1997  if (rep_group==true && !NO_INTERVAL(itf) ) occx=itf->execlower;
1998  if ( (occx < itf->execlower) || (occx > itf->execupper) ) return;
1999  /*[:]*/
2000#if CICPP  /*ifcmm*/
2001  pos=recp->xfieldx(itf->tag,occx);
2002#else /*elsecmm*/
2003  pos=fieldx(irec,itf->tag,occx);
2004#endif /*CICPP*/  /*endcmm*/
2005  field_value(fd_value,max_fd_value,pos);
2006  /* subfields */
2007  cc=itf->sub_field;
2008  if (cc!=subfield_null){
2009     sub_field_string(fd_value,cc);
2010     IFERR_RET;
2011  }
2012  /*substring*/
2013  if(itf->offset!= -1 && itf->length!= -1)
2014          strcpy(fd_value,sub_string(fd_value,itf->offset,itf->length));
2015}
2016/*-------------------------------------------------------------------------*/
2017/*          fmt_comum_ref_beg                                              */
2018/*-------------------------------------------------------------------------*/
2019#if CICPP  /*ifcmm*/
2020void FMTSTRU :: fmt_comum_ref_beg(void)
2021{
2022     try { recp=new RECSTRU(cisisxp); }
2023     catch (BAD_ALLOC) { fatal("fmt/inter/refrec/ALLOC"); }
2024     recp->xrecalloc(MAXMFRL); /* p/ manter check: pode nao usar */
2025     /* recp is global */
2026}
2027#else /*elsecmm*/
2028void fmt_comum_ref_beg()
2029{
2030     if (currprat >= MAXREFS) fatal("fmt/inter/refrec/MAXREFS");
2031     if (!nrecs) fatal("fmt/inter/refrec/recinit");
2032     for (irec=maxnrec; irec--; )
2033       if (!vrecp[irec]) /* ja' decrementado */ break;
2034     if (irec < 0) fatal("fmt/inter/refrec/next");
2035     currprat++;
2036     vprats[currprat]=irec;
2037     recallok(irec,MAXMFRL); /* p/ manter check: pode nao usar */
2038     recp=vrecp[irec]; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */
2039}
2040#endif /*CICPP*/  /*endcmm*/
2041/*-------------------------------------------------------------------------*/
2042/*          fmt_comum_ref_end                                              */
2043/*-------------------------------------------------------------------------*/
2044#if CICPP  /*ifcmm*/
2045void FMTSTRU :: fmt_comum_ref_end(void)
2046{
2047      auxpop = pop(); IFERR_RET;
2048      top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
2049      is_not_of_class(top->classe,type_recstru);
2050      IFERR_RET;
2051#if BEFORE990414
2052      // nao liberava nada! - AOT/HB
2053#else
2054      if (ref_mfn_number>0){
2055          delete recp;
2056      }
2057#endif
2058      recp=top->op.lrecp;
2059}
2060#else /*elsecmm*/
2061void fmt_comum_ref_end()
2062{
2063 LONGX trec;
2064      auxpop = pop(); IFERR_RET;
2065      top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
2066      is_not_of_class(top->classe,long_n);
2067      IFERR_RET;
2068      trec=top->op.l;
2069      /* A alocacao so foi  feita se foi gerado mfn valido(>0) pelo ref  */
2070      if (ref_mfn_number>0){
2071         /* recp=vrecp[trec];*/   /* e' necessario? */     /* YES */
2072         if (currprat < 0 || !vrecp[vprats[currprat]]) fatal("fmt/inter/refrec/free");
2073         irec=vprats[currprat];
2074         FREE(vrecp[irec]); vrecp[irec]=NULL; nrecs--;
2075         currprat--;   /*Posiciona na  prateleira anterior */
2076
2077       /*  irec=vprats[currprat];*/
2078      }
2079      irec=trec;
2080      recp=vrecp[irec];/* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */
2081}
2082#endif /* CICPP */  /*endcmm*/
2083
2084/*----------- inter --------------------------------------*/
2085#if CICPP
2086LONGX FMTSTRU :: xfmt_inter(RECSTRU *parmrecp,
2087                           LONGX par_lw,
2088                           char *par_out,
2089                           LONGX outsize)
2090#else /* CICPP */
2091LONGX fmt_inter(pgm,parmirec,par_lw,par_out,outsize)
2092l_code *pgm;
2093LONGX parmirec;
2094LONGX par_lw;
2095char *par_out;
2096LONGX outsize;
2097#endif /* CICPP */
2098{
2099 char v_mfn_str[20],*mfn_str;
2100/*A06*/
2101/* char literal[MAX_LITER+1]; virou dinamico e global*/
2102 char *new_dbname;
2103 instruction_code actual_mode;
2104 int fim_pgm;
2105 int i;
2106/* para colocar string na saida */
2107 char *pre_literal,*suf_literal,nothing;
2108 char *s;
2109 int id1;
2110 int id2;
2111 int final_added;
2112 LONGX qty;
2113 instruction_code next_ins;
2114 l_code *next_ni;
2115#if DINALLOC
2116 int xdir;
2117 LONGX xfsiz;
2118#endif
2119
2120    if (!ndbxs) dbxinit();  /* init vdbxp/vrecp/vtrmp if not yet init - AOT, 28/10/2005 */
2121
2122#if CICPP
2123    l_code *pgm = fmt_pgmp;
2124#endif /* CICPP */
2125/*--------------------------------------------------------------------------*/
2126/*                   NewLine-Valor default                                  */
2127/*--------------------------------------------------------------------------*/
2128/* A07*/
2129
2130#if UNIX | WWWISIS
2131nl_LEN=1;
2132nl_STR=fmt_alloc_char((ALLOPARM)(nl_LEN+1),"cifm3/alloc/nl_STR");
2133nl_STR[0]=lf; nl_STR[1]=null_char;
2134#else
2135nl_LEN=2;
2136nl_STR=fmt_alloc_char((ALLOPARM)(nl_LEN+1),"cifm3/alloc/nl_STR");
2137nl_STR[0]=cr; nl_STR[1]=lf; nl_STR[2]=null_char;
2138#endif
2139    if (fmttrace) printf("+++ fmt_inter - begin \n");   /* AOT 27/12/91 */
2140    strcpy(fmterrxy,"");
2141#if FATRAP
2142    fmterror = setjmp(fmtjumper);
2143#else /* FATRAP */
2144    fmterror = 0;
2145ERROR_LABEL:
2146#endif /* FATRAP */
2147    if (fmterror != 0) {
2148        return((fmterror < 0) ? (LONGX)fmterror : (LONGX)(-fmterror));
2149    }
2150
2151    if (par_lw <= 0)       par_lw=MAXMFRL-1;  /* AOT, 07/06/2005 */
2152    if (par_lw >= outsize) par_lw=outsize-1;  /* AOT, 07/06/2005 */
2153
2154    /* set current master file record */
2155#if CICPP  /*ifcmm*/
2156    recp=parmrecp;
2157#else /*elsecmm*/
2158    irec=parmirec;
2159    recp=vrecp[irec];
2160    vprats[currprat]=irec;
2161#endif /*CICPP*/  /*endcmm*/
2162
2163    firstdbnp=RDBname;
2164
2165/* Alocacao das maiores areas originalmente estaticas - AOT 29/12/90 */
2166#if DINALLOC
2167    max_tmp_str=outsize; /* parm asize */
2168#if !RETIRAR
2169#if CICPP
2170    try
2171    { tmp_str= (char *)new char [(max_tmp_str+1)]; }
2172    catch (BAD_ALLOC)
2173    { tmp_str= (char *) NULL; }
2174#else /* CICPP */
2175    tmp_str=(char *)ALLOC((ALLOPARM)(max_tmp_str+1));
2176#endif /* CICPP */
2177#else /*RETIRAR */
2178    tmp_str=fmt_alloc_char((ALLOPARM)(max_tmp_str+1),"1001");
2179#endif /*RETIRAR */
2180    if (tmp_str == NULL)
2181    {
2182#if !RETIRAR
2183        inter_error("1001");
2184#endif
2185        IFERR_GOTO;
2186    }
2187/*A06*/
2188    literal_len =(ALLOPARM)MAX_LITER;
2189    literal=fmt_alloc_char((ALLOPARM)(literal_len+1),"cifm3/alloc/literal");
2190    if (literal == NULL) IFERR_GOTO;
2191
2192    if (fmt_fsiz) {
2193        max_fd_value=fmt_fsiz;
2194        max_fd_tmp=fmt_fsiz;
2195    }
2196    else {
2197        for (xdir=MFRnvf, din_fsiz=0; xdir--; )
2198            if (DIRlen(xdir) > din_fsiz) din_fsiz=DIRlen(xdir);
2199        if (fmttrace) printf("+++ fmt_inter - din_fsiz=%"_LD_"\n",din_fsiz);
2200        if (din_fsiz < par_lw) din_fsiz=par_lw; /* bug lw=999 */
2201        if (fmttrace) printf("+++ fmt_inter - din_fsiz=%"_LD_"\n",din_fsiz);
2202        max_fd_value=din_fsiz;
2203        max_fd_tmp=din_fsiz;
2204    }
2205
2206#if CICPP
2207    try
2208    { v_fd_value= (char *) new char [(max_fd_value+1)]; }
2209    catch (BAD_ALLOC)
2210    { v_fd_value= NULL; }
2211#else /* CICPP */
2212    v_fd_value= (char *)ALLOC((ALLOPARM)(max_fd_value+1));
2213#endif /* CICPP */
2214    if (v_fd_value==(char *)NULL)
2215    {
2216        inter_error("1003");
2217        IFERR_GOTO;
2218    }
2219#if CICPP
2220    try
2221    { v_fd_tmp= (char *) new char [(max_fd_tmp+1)]; }
2222    catch (BAD_ALLOC)
2223    { v_fd_tmp= (char *) NULL;}
2224#else /* CICPP */
2225    v_fd_tmp=   (char *)ALLOC((ALLOPARM)(max_fd_tmp+1));
2226#endif /* CICPP */
2227    if (v_fd_tmp==   (char *)NULL)
2228    {
2229        inter_error("1004");
2230        IFERR_GOTO;
2231    }
2232#endif
2233
2234/* Sindo's code */
2235 continue_rgroup_maxocc=0;
2236 continue_rgroup=false;
2237
2238/* Inicializacao do stack[] - AOT 27/11/91 */
2239stack_pt=0;     /* push() e pop() usam a partir de 1 - comunicar */
2240
2241op1= &op1_node;
2242op2= &op2_node;
2243top= &top_node;
2244out= &par_out[0];
2245lw_inter=par_lw;
2246
2247/* incializacoes */
2248fd_value=v_fd_value;    /* DINALLOC */
2249mfn_str=v_mfn_str;
2250must_repeat=false;
2251rep_group=false;
2252next_rep_occ=0;
2253pstr_num=str_num;
2254
2255nextcc=1;
2256tmp_str_index=0;
2257nothing=null_char;
2258pre_literal= &nothing;
2259suf_literal= &nothing;
2260erro_fatal=0;
2261
2262out[0]=null_char;
2263pout= 0;
2264address_out=out;
2265
2266/* defaults */
2267
2268actual_mode=mpl_par;
2269final_added=0;
2270
2271fim_pgm= ~false;
2272if (pgm)
2273if (pgm->next) {
2274   /* inicializa A tabela de definicao de fields */
2275   ni=(l_code *)pgm->next; /* next instruction */
2276   for (;next_infoi(ni)!=(int)nulo;){
2277      fmt_init_vinstr(ni,0);
2278      ni=(l_code *)ni->next;
2279   }
2280   fim_pgm=false;
2281   ni=(l_code *)pgm->next; /* next intruction */
2282}
2283
2284/* 22/10/99 Inicializa  as variaveis E e S */
2285fmt_init_E_S();
2286
2287
2288while (fim_pgm==false){
2289  fd_tmp=v_fd_tmp;
2290
2291#if TRACE_INTER_X
2292  if (fmttrace)
2293  printf(" #%d[%d,%s,%d]\n",0,ni->info.lab,
2294     inst_cnv[ni->info.instr], ni->info.add);
2295#endif /* TRACE_INTER_X */
2296#if DEBUG_REF
2297    printf("\n #%d[%d,%s,%d]\n",0,ni->info.lab,
2298     inst_cnv[ni->info.instr], ni->info.add);
2299
2300 printf("\n---- ESTADO         da pilha ----- termos %d \n",ntrms);
2301 for (iii=stack_pt;iii>0;iii--) {
2302    printf("\n  %d  %d   %d ",iii,stack[iii].classe, stack[iii].op);
2303    if (stack[iii].classe==string) printf(" string");
2304    if (stack[iii].classe==long_n) printf(" long_n %"_LD_" ",stack[iii].op.l);
2305    if (stack[iii].classe==integer) printf(" integer");
2306    if (stack[iii].classe==float_n) printf(" float_n  ");
2307    if (stack[iii].classe==logical) printf(" logical %d ",stack[iii].op.i);
2308    if (stack[iii].classe==ptr) printf(" ptr %"_LD_" (%p)",
2309                                 stack[iii].op.address,stack[iii].op.address);
2310    if (stack[iii].classe==l_w) printf(" l_w =%"_LD_" ",stack[iii].op.l);
2311    if (stack[iii].classe==xindex) printf(" index %d ",stack[iii].op.i);
2312    if (stack[iii].classe==next_cc) printf(" next_cc %"_LD_,stack[iii].op.l);
2313
2314 }
2315#if 0
2316 printf("\n ---- Alocacoes  invertido --- ntrms=%d",
2317        ntrms);
2318 for (iix=maxntrm; iix>=trm_prat; iix--) {
2319    printf ("\n vtrmp[%"_LD_"]= %"_LD_" (%p )", iix,vtrmp[iix],vtrmp[iix]);
2320 }
2321#endif
2322#endif
2323/*loop*/
2324 switch(infoi(ni))
2325  {
2326  case  test_occ:
2327    {
2328      itf=(field_definition_node *) iadd(ni);
2329      there_is_fd_value=false;
2330      *fd_value=null_char;                                      /* 08/05/92 */
2331      *fd_tmp=null_char;                                        /* 08/05/92 */
2332      if (itf->max_occ == -1)
2333      { fmt_load_all_occ(); IFERR_GOTO; }
2334
2335      if(rep_group==true)itf->actual_occ=next_rep_occ;
2336                    else itf->actual_occ++;
2337      /* Tentativa de Implementar v70[1] dentro de repetitivo */
2338      /* 30-12-94 */
2339      if (rep_group==true   &&  !NO_INTERVAL(itf)) {
2340        /* Intervalo dentro de repetitivo so pega  o lower
2341           O comando abaixo forca o valor de itf->actual_occ
2342           somente com o objetivo de entrar no proximo teste,
2343           pois de qualquer forma o numero da ocorrencia sera
2344           aquele especificado no lower.
2345           Esta implementacao e muito suja. No caso de um
2346           formato do tipo ( v70[2],c20,v26[3]) se nocc(70)=5
2347           serao geradas 5 linhas iguais !!!!
2348        */
2349        itf->actual_occ=itf->max_occ;
2350       }
2351
2352      if (itf->max_occ >= itf->actual_occ){
2353         there_is_fd_value=false;
2354         elem.classe=logical;
2355         elem.op.boolean=true;
2356         fmt_load_next_occ();
2357         IFERR_GOTO;
2358         if(strlen(fd_value)!=0)there_is_fd_value=true;
2359
2360         if (fmttrace) trace_field(itf,fd_value);/* AOT 26/12/91 */
2361      }
2362      else {
2363        *fd_value=null_char;
2364        elem.classe=logical;
2365        elem.op.boolean=false;
2366        if (fmttrace) trace_field(itf,"");      /* AOT 26/12/91 */
2367      }
2368
2369    push(&elem);
2370    IFERR_GOTO;
2371    ni=(l_code *) next_infoi(ni); /* proxima instrucao */
2372    break;
2373   }
2374 case suf_cond :
2375 case suf_cond_null :
2376 case suf_r_lit :
2377 case suf_r_lit_plus :
2378 {
2379   ni=(l_code *) next_infoi(ni);
2380   break;
2381  }
2382
2383 case ign_cond :
2384 {
2385   there_is_fd_value=false;
2386   ni=(l_code *) next_infoi(ni);
2387   break;
2388  }
2389
2390 case pre_cond :
2391  {
2392   if (there_is_fd_value==true)
2393   {
2394   if(itf->actual_occ==itf->first_occ)
2395     {
2396      literal[0]=null_char;
2397#if !RETIRAR
2398      strcpy(literal, (char *) iadd(ni) );
2399#else
2400     literal=fmt_copy_realloc((char *)literal, &literal_len,
2401                                               (char *)iadd(ni));
2402#endif
2403       if(is_upper_mode(actual_mode)) upcase_mode(literal);
2404       id1=0;
2405       id2=0;
2406      out_put_str(out,outsize, &pout,lw_inter,id1,id2, &nextcc,literal);
2407     }  /* actual_occ=... */
2408     }
2409
2410   ni=(l_code *) next_infoi(ni);
2411   break;
2412  }
2413
2414 case pre_r_lit_plus :
2415  {
2416   pre_literal= &nothing;
2417
2418   if(itf->actual_occ!=itf->first_occ && there_is_fd_value==true)
2419     {
2420      pre_literal=(char *) iadd(ni);
2421
2422     }  /* actual_occ=... */
2423   ni=(l_code *) next_infoi(ni);
2424   break;
2425  }
2426
2427 case pre_r_lit :
2428  {
2429
2430      if(there_is_fd_value==true) pre_literal=(char *) iadd(ni);
2431   ni=(l_code *) next_infoi(ni);
2432   break;
2433  }
2434
2435
2436 case u_cond :
2437  {   /*A06*/
2438
2439/*       literal[0]=null_char;
2440         strcpy(literal,(char *) iadd(ni) );
2441*/
2442      literal=fmt_copy_realloc((char *)literal, &literal_len,
2443                                               (char *)iadd(ni));
2444      if(is_upper_mode(actual_mode)) upcase_mode(literal);
2445      id1=0;
2446      id2=0;
2447      out_put_str(out,outsize, &pout,lw_inter,id1,id2, &nextcc,literal);
2448      ni=(l_code *) next_infoi(ni);
2449      break;
2450  }
2451
2452 case escape_seq :
2453  {
2454      literal[0]=(char)27; /*escape sequence */
2455      literal[1]=null_char;
2456 /*A06*/
2457       id1=0;
2458       id2=0;
2459      out_put_str(out,outsize, &pout,lw_inter,id1,id2, &nextcc,literal);
2460
2461/* A06      strcat(literal, (char *) iadd(ni) );
2462*/
2463      literal=fmt_copy_realloc((char *)literal, &literal_len,
2464                                               (char *)iadd(ni));
2465      out_put_str(out,outsize, &pout,lw_inter,id1,id2, &nextcc,literal);
2466      ni=(l_code *) next_infoi(ni);
2467      break;
2468
2469  }
2470   case fmt_beg:
2471     {
2472     save_context(modify_fmt_pointers);
2473     IFERR_GOTO;
2474     ni=(l_code *) next_infoi(ni);
2475     break;
2476     }
2477
2478   case fmt_end:
2479   {
2480
2481
2482   ni=(l_code *) next_infoi(ni);
2483
2484   break;
2485  }
2486 case print_mfn :
2487  {
2488/*   strcpy(mfn_str,long_to_char(MFRmfn,(int )iadd(ni)) );*/
2489   float_exp_value= (float_x ) MFRmfn;
2490   strcpy((char *)mfn_str,
2491      fmt_float_numb(float_exp_value,(int )iadd(ni) ,(int) 0,'0'));
2492   id1=0;
2493   id2=0;
2494   out_put_str(out,outsize, &pout,lw_inter,id1,id2, &nextcc,mfn_str);
2495   ni=(l_code *) next_infoi(ni);
2496   break;
2497  }
2498
2499 case print_maxmfn :
2500  {
2501   float_exp_value= (float_x ) 0;
2502   if (RECdbxp) float_exp_value= (float_x ) RDBmsmfn; /* il fault faire.. */
2503   strcpy((char *)mfn_str,
2504      fmt_float_numb(float_exp_value,(int )iadd(ni) ,(int) 0,'0'));
2505   id1=0;
2506   id2=0;
2507   out_put_str(out,outsize, &pout,lw_inter,id1,id2, &nextcc,mfn_str);
2508   ni=(l_code *) next_infoi(ni);
2509   break;
2510  }
2511
2512 case print_core :
2513  {
2514#if CICPP
2515   float_exp_value= (float_x ) 0;
2516#else /* CICPP */
2517   float_exp_value= (float_x ) CORELEFT();
2518#endif /* CICPP */
2519   strcpy((char *)mfn_str,
2520   fmt_float_numb(float_exp_value,(int )iadd(ni) ,(int) 0,'0'));
2521   id1=0;
2522   id2=0;
2523   out_put_str(out,outsize, &pout,lw_inter,id1,id2, &nextcc,mfn_str);
2524   ni=(l_code *) next_infoi(ni);
2525   break;
2526  }
2527
2528  case print_field:
2529  {
2530     char *tofree;
2531
2532     if(itf->max_occ>itf->actual_occ) must_repeat=true;
2533     if (there_is_fd_value==true)
2534    {
2535        *fd_tmp=null_char;
2536        strcpy(fd_tmp,pre_literal);
2537        strcat(fd_tmp,fd_value);
2538/*      exec_suf_literal; */
2539        next_ni=(l_code *)next_infoi(ni); /* precisa ver 1 passo a frente*/
2540        next_ins=infoi(next_ni);
2541        there_is_suf=false;
2542
2543        if (next_ins==suf_r_lit )
2544         {
2545           ni=(l_code *) next_infoi(ni);
2546           suf_literal=(char *) iadd(ni);
2547           there_is_suf=true;
2548         }
2549
2550        next_ni=(l_code *)next_infoi(ni); /* precisa ver 1 passo a frente*/
2551        next_ins=infoi(next_ni);
2552
2553         if (next_ins==suf_r_lit_plus)
2554       { ni=(l_code *) next_infoi(ni);
2555                /* ignores the last  occurrence */
2556                if(itf->actual_occ!=itf->last_occ)
2557                 {
2558                  suf_literal= (char *) iadd(ni);
2559                 there_is_suf=true;
2560             }
2561       }
2562      strcat(fd_tmp,suf_literal);
2563      literal[0]=null_char;
2564          next_ni=(l_code *)next_infoi(ni); /* precisa ver 1 passo a frente*/
2565          next_ins=infoi(next_ni);
2566
2567      if (next_ins==suf_cond_null || next_ins==suf_cond)
2568          { ni=(l_code *) next_infoi(ni);
2569                if(itf->actual_occ==itf->last_occ )
2570                  {
2571/*A06                strcpy(literal, (char *) iadd(ni) );
2572*/
2573                     literal=fmt_copy_realloc((char *)literal, &literal_len,
2574                                                          (char *)iadd(ni));
2575                     there_is_suf=true;
2576                   }  /* else ignores command */
2577          }  /* suf_cond */
2578          strcat(fd_tmp,literal);
2579          s=trata_md(actual_mode,fd_tmp,&final_added,&tofree);
2580          IFERR_GOTO;
2581          if(is_upper_mode(actual_mode)) upcase_mode(s);
2582          id1=itf->indent1;
2583          id2=itf->indent2;
2584          out_put_str(out,outsize, &pout,lw_inter,id1,id2, &nextcc,s);
2585          if (tofree) {
2586
2587#if CICPP
2588                delete [] (char *)tofree;
2589#else /* CICPP */
2590                FREE(tofree);
2591#endif /* CICPP */
2592
2593          }
2594          if(there_is_suf==true)
2595          {
2596           delete_chars(out,pout,nextcc,final_added,lw_inter);
2597          }
2598
2599    }
2600        pre_literal= &nothing;
2601        suf_literal= &nothing;
2602        ni=(l_code *) next_infoi(ni);
2603        break;
2604
2605   }
2606
2607   case load_field_all:
2608  {
2609        fmt_load_all_occ();
2610        IFERR_GOTO;
2611#if TRACE_INTER_2
2612        printf("\n Apos fmt_load_all_occ/1 fd_value=%s",fd_value);
2613#endif
2614        /* copia para temporaria */
2615
2616        elem.op.s=store_tmp_string(fd_value);
2617        IFERR_GOTO;
2618        elem.classe=string;
2619        push(&elem);
2620        IFERR_GOTO;
2621        ni=(l_code *) next_infoi(ni);
2622        break;
2623   }
2624   case load_field_occ:
2625  {
2626     itf=(field_definition_node  *)iadd(ni);
2627      if( itf->max_occ == -1)
2628        {
2629#if CICPP  /*ifcmm*/
2630         itf->max_occ=recp->xnocc(itf->tag);
2631#else /*elsecmm*/
2632         itf->max_occ=nocc(irec,itf->tag);
2633#endif /*CICPP*/  /*endcmm*/
2634         itf->execlower=abs(itf->lower);
2635         itf->execupper=abs(itf->upper);
2636         if (itf->lower==LASTVAL) itf->execlower=itf->max_occ;
2637         if (itf->upper==LASTVAL) itf->execupper=itf->max_occ;
2638         /* fim  implementacao [x:y] */
2639
2640         itf->actual_occ=0;
2641         }
2642       *fd_value=null_char;
2643       if (rep_group==true)itf->actual_occ=next_rep_occ;
2644                      else itf->actual_occ++;
2645
2646       if (itf->max_occ > itf->actual_occ) must_repeat=true; /* SVD 11/11/91 */
2647
2648       if (itf->max_occ >= itf->actual_occ || !NO_INTERVAL(itf)){
2649          *fd_value=null_char;
2650           fmt_load_next_occ();
2651           IFERR_GOTO;
2652       }
2653
2654       elem.op.s=store_tmp_string(fd_value);
2655       IFERR_GOTO;
2656       elem.classe=string;
2657       push(&elem);
2658       IFERR_GOTO;
2659       ni=(l_code *) next_infoi(ni);
2660       break;
2661   }
2662
2663   case load_string:
2664  {
2665        elem.op.s=(char *) iadd(ni);
2666        elem.classe=string;
2667        push(&elem);
2668        IFERR_GOTO;
2669        ni=(l_code *) next_infoi(ni);
2670        break;
2671   }
2672   case load_mstnam:
2673  {
2674      tmp_ptr=store_tmp_string(RDBname);
2675      IFERR_GOTO;
2676      if(is_upper_mode(actual_mode)) upcase_mode(tmp_ptr);
2677
2678      elem.op.s=tmp_ptr;
2679      elem.classe=string;
2680      push(&elem);
2681      IFERR_GOTO;
2682      ni=(l_code *) next_infoi(ni);
2683      break;
2684   }
2685   case load_date:
2686  {
2687      char *tmp_ptr;
2688      int parmdate;
2689      parmdate=(int)iadd(ni);
2690
2691      tmp_ptr=fmt_get_date(parmdate,-1L);
2692      if(is_upper_mode(actual_mode)) upcase_mode(tmp_ptr);
2693
2694      elem.op.s=store_tmp_string(tmp_ptr);
2695      IFERR_GOTO;
2696      elem.classe=string;
2697      push(&elem);
2698      IFERR_GOTO;
2699      ni=(l_code *) next_infoi(ni);
2700      break;
2701   }
2702  case load_number:
2703  {                        /* Only implemented for LONGX numbers */
2704        elem.op.l=(LONGX)iadd(ni);
2705        elem.classe=long_n;
2706        push(&elem);
2707        IFERR_GOTO;
2708        ni=(l_code *) next_infoi(ni);
2709        break;
2710   }
2711  case intvvalue:
2712  {                        /* Only implemented for LONGX numbers */
2713        elem.op.r=E_var[(LONGX)iadd(ni)];
2714        elem.classe=float_n;
2715        push(&elem);
2716        IFERR_GOTO;
2717        ni=(l_code *) next_infoi(ni);
2718        break;
2719   }
2720   case load_float:
2721  {
2722        elem.op.r= *(float_x *)(iadd(ni)) ;
2723#if DEB_FLOAT
2724        printf("\n Empilhando float=%f",elem.op.r);
2725#endif
2726        elem.classe=float_n;
2727        push(&elem);
2728        IFERR_GOTO;
2729        ni=(l_code *) next_infoi(ni);
2730        break;
2731   }
2732   case load_mfn:
2733  {                        /* tamanho de caracteres sao ignorados  */
2734        elem.op.l=(LONGX)MFRmfn;
2735        elem.classe=long_n;
2736        push(&elem);
2737        IFERR_GOTO;
2738        ni=(l_code *) next_infoi(ni);
2739        break;
2740   }
2741
2742   case load_maxmfn:
2743  {                        /* tamanho de caracteres sao ignorados  */
2744        elem.op.l= (float_x ) 0;
2745        if (RECdbxp) elem.op.l= (float_x ) RDBmsmfn; /* il fault faire.. */
2746        elem.classe=long_n;
2747        push(&elem);
2748        IFERR_GOTO;
2749        ni=(l_code *) next_infoi(ni);
2750        break;
2751   }
2752   case load_core:
2753  {                        /* tamanho de caracteres sao ignorados  */
2754#if CICPP
2755        elem.op.l= (float_x ) 0;
2756#else /* CICPP */
2757        elem.op.l= (float_x ) CORELEFT();
2758#endif /* CICPP */
2759        elem.classe=long_n;
2760        push(&elem);
2761        IFERR_GOTO;
2762        ni=(l_code *) next_infoi(ni);
2763        break;
2764   }
2765
2766   case noccins:
2767  {
2768        elem.op.l=fmt_load_all_occ();
2769        IFERR_GOTO;
2770        elem.classe=long_n;
2771        push(&elem);
2772        IFERR_GOTO;
2773#if DEB_NOCC
2774        printf("\n Numero de ocorrencias=%d\n",elem.op.l);
2775#endif
2776        ni=(l_code *) next_infoi(ni);
2777        break;
2778   }
2779
2780   case ioccins:
2781  {
2782        elem.op.l=(LONGX )next_rep_occ;
2783        elem.classe=long_n;
2784        push(&elem);
2785        IFERR_GOTO;
2786#if DEB_NOCC
2787        printf("\n Numero de ocorrencias=%d\n",elem.op.l);
2788#endif
2789        ni=(l_code *) next_infoi(ni);
2790        break;
2791   }
2792
2793   case present :
2794   case absent :
2795  {
2796#if ONE_MORE_OCCS
2797       if (itf->max_occ>itf->actual_occ) must_repeat=true; /* SVD 21/11/91 */
2798#endif
2799        if (rep_group==true)
2800    {
2801        /* copia para temporaria */
2802     itf=(field_definition_node *)iadd(ni);
2803      if( itf->max_occ == -1)
2804        {
2805          fmt_load_all_occ(); /* para inicializar intervalos 27-12-94 */
2806          IFERR_GOTO;
2807          itf->actual_occ=0;
2808         }
2809       *fd_value=null_char;
2810       itf->actual_occ=next_rep_occ;
2811#if !ONE_MORE_OCCS
2812       if (itf->max_occ>itf->actual_occ) must_repeat=true; /* SVD 21/11/91 */
2813#endif
2814       if (itf->max_occ >= itf->actual_occ) {fmt_load_next_occ();IFERR_GOTO;}
2815     }
2816     else {
2817        fmt_load_all_occ();
2818        IFERR_GOTO;
2819#if TRACE_INTER_2
2820        printf("\n Apos fmt_load_all_occ/2 fd_value=%s",fd_value);
2821#endif
2822     }
2823     elem.classe=logical;
2824     if (infoi(ni)==absent)  elem.op.boolean= *fd_value==null_char?true:false;
2825     if (infoi(ni)==present) elem.op.boolean= *fd_value==null_char?false:true;
2826     push(&elem);
2827     IFERR_GOTO;
2828     ni=(l_code *) next_infoi(ni);
2829     break;
2830   }
2831
2832 case duptop: /*duplica a expressao do select para testar com cases */
2833  {
2834   auxpop = pop(); IFERR_GOTO;
2835   push(auxpop);   IFERR_GOTO;
2836   push(auxpop);   IFERR_GOTO;
2837   ni=(l_code *) next_infoi(ni);
2838   break;
2839  }
2840 case end_select: /* retira a expressao do select do topo */
2841 {
2842  auxpop =pop(); IFERR_GOTO;
2843   ni=(l_code *) next_infoi(ni);
2844
2845  break;
2846 }
2847 case jumpf:
2848  {
2849   auxpop = pop(); IFERR_GOTO;
2850   top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
2851   is_not_of_class(top->classe,logical);
2852   IFERR_GOTO;
2853   if(top->op.boolean==false) ni=(l_code *) iadd(ni);
2854                       else ni=(l_code *) next_infoi(ni);
2855   break;
2856
2857  }
2858
2859 case jumpt:
2860  {
2861   auxpop = pop(); IFERR_GOTO;
2862   top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
2863   is_not_of_class(top->classe,logical);
2864   IFERR_GOTO;
2865
2866   if(top->op.boolean==true) ni=(l_code *) iadd(ni);
2867                    else ni=(l_code *) next_infoi(ni);
2868
2869   break;
2870  }
2871
2872 case jump:
2873 case breakins:    /* pulo incondicional */
2874  {
2875    ni=(l_code *) iadd(ni);
2876   break;
2877  }
2878 case or_op :
2879 case and_op:
2880  {
2881   retrieve_two_logical_operands;
2882   IFERR_GOTO;
2883   if(infoi(ni)==and_op)elem.op.boolean=op1->op.boolean && op2->op.boolean;
2884   if(infoi(ni)==or_op )elem.op.boolean=op1->op.boolean || op2->op.boolean;
2885   push(&elem);
2886   IFERR_GOTO;
2887   ni=(l_code *) next_infoi(ni);
2888   break;
2889  }
2890 case not_op:
2891  {
2892   auxpop = pop(); IFERR_GOTO;
2893   op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
2894   is_not_of_class(op1->classe,logical);
2895   IFERR_GOTO;
2896   elem.classe=logical;
2897   elem.op.boolean=!op1->op.boolean ;
2898   push(&elem);
2899   IFERR_GOTO;
2900   ni=(l_code *) next_infoi(ni);
2901   break;
2902  }
2903 case neq_op :
2904 case gtr_op :
2905 case lss_op :
2906 case leq_op :
2907 case geq_op :
2908 case eql_op :
2909  {
2910   instruction=infoi(ni);
2911   retrieve_two_operands ();
2912   IFERR_GOTO;
2913   switch (class_of_the_both)
2914   {
2915
2916   case string :
2917    {
2918    result=strcmp(op1->op.s,op2->op.s);
2919    switch (instruction) {
2920    case neq_op: cond_code= (result != 0)?true:false; break;
2921    case gtr_op: cond_code= (result  > 0)?true:false; break;
2922    case lss_op: cond_code= (result  < 0)?true:false; break;
2923    case leq_op: cond_code= (result <= 0)?true:false; break;
2924    case geq_op: cond_code= (result >= 0)?true:false; break;
2925    case eql_op: cond_code= (result == 0)?true:false; break;
2926    }
2927    break;
2928    }/* string */
2929   case long_n  :
2930    {
2931    switch (instruction) {
2932    case neq_op: cond_code= (long_value_1 != long_value_2 )?true:false; break;
2933    case gtr_op: cond_code= (long_value_1 >  long_value_2 )?true:false; break;
2934    case lss_op: cond_code= (long_value_1 <  long_value_2 )?true:false; break;
2935    case leq_op: cond_code= (long_value_1 <= long_value_2 )?true:false; break;
2936    case geq_op: cond_code= (long_value_1 >= long_value_2 )?true:false; break;
2937    case eql_op: cond_code= (long_value_1 == long_value_2 )?true:false; break;
2938    }
2939    break;
2940    }/*integer */
2941   case float_n   :
2942    {
2943#if DEB_FLOAT
2944    printf("\n Vai comparar (%f) com (%f)",float_value_1,float_value_2);
2945#endif
2946    switch (instruction) {
2947    case neq_op: cond_code=(float_value_1 != float_value_2)?true:false; break;
2948    case gtr_op: cond_code=(float_value_1 >  float_value_2)?true:false; break;
2949    case lss_op: cond_code=(float_value_1 <  float_value_2)?true:false; break;
2950    case leq_op: cond_code=(float_value_1 <= float_value_2)?true:false; break;
2951    case geq_op: cond_code=(float_value_1 >= float_value_2)?true:false; break;
2952    case eql_op: cond_code=(float_value_1 == float_value_2)?true:false; break;
2953    }
2954    break;
2955    }/*integer */
2956
2957   case integer :
2958
2959    {
2960    switch (instruction) {
2961    case neq_op: cond_code= (int_value_1 != int_value_2 )?true:false; break;
2962    case gtr_op: cond_code= (int_value_1 >  int_value_2 )?true:false; break;
2963    case lss_op: cond_code= (int_value_1 <  int_value_2 )?true:false; break;
2964    case leq_op: cond_code= (int_value_1 <= int_value_2 )?true:false; break;
2965    case geq_op: cond_code= (int_value_1 >= int_value_2 )?true:false; break;
2966    case eql_op: cond_code= (int_value_1 == int_value_2 )?true:false; break;
2967    }
2968    break;
2969    }/*integer */
2970
2971   default:
2972   {
2973   inter_error("Operations for these classes of operands not implemented");
2974   IFERR_GOTO;
2975   }
2976   }  /* switch */
2977   elem.classe=logical;
2978   elem.op.boolean=cond_code;
2979   push(&elem);
2980   IFERR_GOTO;
2981   ni=(l_code *) next_infoi(ni);
2982   break;
2983
2984  }
2985 case plus_op :
2986 case minus_op :
2987 case divide_op :
2988 case times_op :
2989  {
2990   instruction=infoi(ni);
2991   retrieve_two_numeric_operands();
2992   IFERR_GOTO;
2993
2994
2995   switch(new_class)
2996   {
2997   case integer:
2998      {
2999      if (instruction==plus_op)  tempint=int_value_1 + int_value_2;
3000      if (instruction==minus_op) tempint=int_value_1 - int_value_2;
3001      if (instruction==times_op) tempint=int_value_1 * int_value_2;
3002      if (instruction==divide_op)tempint=int_value_1 / int_value_2;
3003      elem.classe=new_class;
3004      elem.op.i=tempint;
3005      break;
3006      }
3007   case long_n:
3008      {
3009      if (instruction==plus_op)  templong=long_value_1 + long_value_2;
3010      if (instruction==minus_op) templong=long_value_1 - long_value_2;
3011      if (instruction==times_op) templong=long_value_1 * long_value_2;
3012      if (instruction==divide_op)templong=long_value_1 / long_value_2;
3013      elem.classe=long_n;
3014      elem.op.l=templong;
3015      break;
3016      }
3017
3018   case float_n:
3019      {
3020      if (instruction==plus_op)  tempfloat=float_value_1 + float_value_2;
3021      if (instruction==minus_op) tempfloat=float_value_1 - float_value_2;
3022      if (instruction==times_op) tempfloat=float_value_1 * float_value_2;
3023      if (instruction==divide_op)tempfloat=float_value_1 / float_value_2;
3024
3025      elem.classe=float_n;
3026      elem.op.r=tempfloat;
3027      break;
3028      }
3029
3030   default:
3031   {
3032   inter_error("Operations for these classes of operands not implemented");
3033   IFERR_GOTO;
3034   break;
3035   }
3036  }  /* switch */
3037   push(&elem);
3038   IFERR_GOTO;
3039   ni=(l_code *) next_infoi(ni);
3040   break;
3041 }
3042
3043case x_spac:
3044 {
3045  qty=iadd(ni);
3046  if( (lw_inter-nextcc)>qty )  /* is room */
3047   {
3048    /* repeat_space(out,pout,qty) */
3049    memset(out+pout,' ',qty); pout+=qty;
3050    nextcc=nextcc+qty;
3051    out[pout]=null_char;
3052   }
3053   else
3054    { /* there's no room */
3055     /*A07  new_line(out,pout); */
3056     new_line(out,pout,outsize);
3057     nextcc=1;
3058    }
3059
3060
3061
3062  ni=(l_code *) next_infoi(ni);
3063  break;
3064 }
3065
3066case c_spac:
3067 {
3068  qty=iadd(ni);
3069  if(qty<=lw_inter)
3070  {
3071
3072    if( nextcc > qty  )
3073      {
3074        /*A07 new_line(out,pout); */
3075        new_line(out,pout,outsize);
3076        nextcc=1;
3077      }
3078    while (nextcc<qty )
3079      { out[pout++]=' ';
3080        out[pout]=null_char;
3081        nextcc++;
3082       } /*while*/
3083  }  /* number spaces > lw_inter - ignores the command */
3084    ni=(l_code *) next_infoi(ni);
3085    break;
3086 }
3087
3088case percent_spac:
3089 {
3090#if MICRO_ISIS_COMPATIBLE
3091   int nn;
3092    nn=exec_percent(out,&pout,&nextcc);
3093#endif
3094    ni=(l_code *) next_infoi(ni);
3095#if MICRO_ISIS_COMPATIBLE
3096    /* se ja existe mudanca de linha e prox instrucao #, ignora-a */
3097    if ( (nn>0) && (infoi(ni)==n_sign_spac) )
3098             ni=(l_code *) next_infoi(ni);
3099#endif
3100    break;
3101 }
3102
3103case n_sigx_spac:
3104/* see case x_spac: */
3105 {
3106  qty=iadd(ni);
3107  while (qty > 0) {
3108         char *p,*q;
3109         int mlen,hlen,qlen;
3110         mlen=RECnbytes-(MFRmfrl+sizeof(DIRSTRU));
3111         if (mlen <= (hlen=1+6+1+9+1)+2) break;
3112         p=MFX+(MFRmfrl+sizeof(DIRSTRU));
3113         sprintf(p,"H%6"_LD_" %9"_LD_" ",(LONGX)qty,0L);
3114         q=p+hlen; if (!fgets(q, mlen-hlen, stdin)) break;
3115         qlen=strlen(q); if (!qlen) break;
3116         if (q[--qlen] != '\n') break;
3117         sprintf(p+hlen-(9+1),"%9"_LD_,(LONGX)qlen); p[hlen-1]=' ';
3118#if CICPP
3119         p=recp->xfldupdat(p);
3120#else /* CICPP */
3121         p=fldupdat(irec,p);
3122#endif /* CICPP */
3123         if (p) fatal(p);
3124         qty=0;
3125  }
3126  ni=(l_code *) next_infoi(ni);
3127  break;
3128 }
3129
3130case n_sign_spac:
3131 {
3132  /*A07  new_line(out,pout); */
3133  new_line(out,pout,outsize);
3134  nextcc=1; /* upadtes next position  avaialble in line */
3135  ni=(l_code *) next_infoi(ni);
3136  break;
3137 }
3138case slash_spac:
3139 {
3140  if(! (fmt_CRLF(out,pout) || pout==0) )
3141    {
3142     /*A07 new_line(out,pout); */
3143     new_line(out,pout,outsize);
3144     nextcc=1; /* updates next position available in the output */
3145    }
3146  ni=(l_code *) next_infoi(ni);
3147  break;
3148
3149 }
3150
3151 case test_rep:
3152  {
3153   /* Implementacao do continue 17-7-94 */
3154   if (continue_rgroup==true){
3155     if (next_rep_occ <= /* ou < ?*/ continue_rgroup_maxocc)
3156            must_repeat=true;
3157   }
3158
3159   /* Tentativa de Implementar v70[1] dentro de repetitivo */
3160   /* 30-12-94 */
3161   if (rep_group==true   &&  !NO_INTERVAL(itf)) {
3162     if (next_rep_occ <  /* ou <= ?*/ continue_rgroup_maxocc)
3163            must_repeat=true;
3164   }
3165   elem.classe=logical;
3166   elem.op.boolean=must_repeat;
3167   push(&elem);
3168   IFERR_GOTO;
3169   ni=(l_code *) next_infoi(ni);
3170   break;
3171  }
3172
3173 case set_true_rep:
3174  {
3175   must_repeat=true;
3176   ni=(l_code *) next_infoi(ni);
3177   break;
3178  }
3179 case set_false_rep:
3180  {
3181   must_repeat=false;
3182   /* Implementar continue 17-7-94 */
3183   continue_rgroup=false;
3184   ni=(l_code *) next_infoi(ni);
3185   break;
3186  }
3187  case mpl_par:
3188  case mpu_par:
3189  case mdl_par:
3190  case mdu_par:
3191  case mhl_par:
3192  case mhu_par:
3193  {
3194   actual_mode=infoi(ni);
3195   ni=(l_code *) next_infoi(ni);
3196   break;
3197  }
3198
3199  case contains:
3200  {
3201   auxpop = pop(); IFERR_GOTO;
3202   op2=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));
3203   auxpop = pop(); IFERR_GOTO;
3204   op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
3205   elem.classe=logical;
3206   if (op1->classe!=op2->classe || op1->classe!=string)
3207     {inter_error("Invalid operands for ':' operator ");
3208      IFERR_GOTO;
3209     }
3210    else
3211    {if(strstr(op1->op.s,op2->op.s)!=null_char)elem.op.boolean=true;
3212       else elem.op.boolean=false;
3213
3214    }
3215    push(&elem);
3216    IFERR_GOTO;
3217    ni=(l_code *) next_infoi(ni);
3218   break;
3219
3220  }
3221
3222  case instr_end:
3223  {
3224   auxpop = pop(); IFERR_GOTO;
3225   op2=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));
3226   auxpop = pop(); IFERR_GOTO;
3227   op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
3228   if (op1->classe!=op2->classe || op1->classe!=string)
3229     {inter_error("Invalid operands for 'instr' operator ");
3230      IFERR_GOTO;
3231     }
3232    else{
3233     restore_context();
3234     elem.classe=long_n;
3235     elem.op.l= (LONGX) fmt_instr(op1->op.s,op2->op.s);
3236    }
3237    push(&elem);
3238    IFERR_GOTO;
3239    ni=(l_code *) next_infoi(ni);
3240   break;
3241
3242  }
3243
3244  case right_end:
3245  case left_end:
3246  {
3247   int lng,xn;
3248   char *tt;
3249   auxpop = pop(); IFERR_GOTO;
3250   op2=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));
3251   auxpop = pop(); IFERR_GOTO;
3252   op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
3253   if (op1->classe!=string || !is_numeric(op2->classe)){
3254      inter_error("Invalid operands for ':' operator ");
3255      IFERR_GOTO;
3256   }else{
3257      tt=(char *)op1->op.s;
3258      lng=strlen(tt);
3259      xn=cast_to_int(op2);
3260      if (xn<0) xn=0;
3261      if (infoi(ni)==right_end){
3262#if TRACE_STRFUN
3263         printf( "\n lng=%d caracters a direita de =%s=",xn,op1->op.s);
3264#endif
3265         lng=lng-xn;
3266         if (lng<0) lng=0;
3267         tt= (char *) (tt + lng);
3268#if TRACE_STRFUN
3269          printf ("%s\n",tt);
3270#endif
3271      }
3272      if (infoi(ni)==left_end){
3273#if TRACE_STRFUN
3274        printf( "\n lng=%d caracters a esquerda de =%s=",xn,op1->op.s);
3275#endif
3276        if ( lng> xn) lng=xn;
3277        if (lng <0) lng=0;
3278        tt[lng]=null_char;
3279#if TRACE_STRFUN
3280        printf ("%s\n",tt);
3281#endif
3282      }
3283   }
3284    restore_context();
3285    elem.op.s=tt;
3286    elem.classe=string;
3287    push(&elem);
3288    IFERR_GOTO;
3289    ni=(l_code *) next_infoi(ni);
3290   break;
3291  }
3292
3293 case mid_end:   /*    mid(string,start,lenght) */
3294 case ss_end:    /*A10* ss(pos,length,string) */
3295  {
3296       /* op1 - string
3297          op2 - start
3298          op3 -length
3299       */
3300   int lng,xn_inic,xn_fim;
3301   stack_node op3_node;
3302   stack_node *op3;
3303   char *tt;
3304   if (infoi(ni)==mid_end){
3305     auxpop = pop(); IFERR_GOTO;
3306     op3=(stack_node *)memcpy(&op3_node,auxpop,sizeof(stack_node));
3307     auxpop = pop(); IFERR_GOTO;
3308     op2=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));
3309     auxpop = pop(); IFERR_GOTO;
3310     op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
3311   }
3312   if (infoi(ni)==ss_end) {
3313     auxpop = pop(); IFERR_GOTO;
3314     op1=(stack_node *)memcpy(&op3_node,auxpop,sizeof(stack_node));
3315     auxpop = pop(); IFERR_GOTO;
3316     op3=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));
3317     auxpop = pop(); IFERR_GOTO;
3318     op2=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
3319   }
3320   if (op1->classe!=string || !is_numeric(op2->classe) ||
3321                              !is_numeric(op3->classe )){
3322      inter_error("Invalid operands for ':' operator ");
3323      IFERR_GOTO;
3324   }else{
3325      tt=(char *)op1->op.s;
3326      lng=strlen(tt);
3327      xn_inic=cast_to_int(op2);
3328      xn_fim=cast_to_int(op3);
3329#if TRACE_STRFUN
3330         printf( "\n inic=%d fim=%d a direita de =%s=",xn_inic,xn_fim,tt);
3331#endif
3332         if (xn_inic<=0) xn_inic=1;
3333         if (xn_inic>lng) xn_inic=lng+1;
3334         tt=(char *) (tt + xn_inic-1);
3335         lng=strlen(tt);
3336         if (xn_fim<0) xn_fim=0;
3337         if (xn_fim>lng) xn_fim=lng;
3338         tt[xn_fim]=null_char;
3339#if TRACE_STRFUN
3340         printf ("%s\n",tt);
3341#endif
3342        restore_context();
3343        elem.op.s=tt;
3344        elem.classe=string;
3345        push(&elem);
3346        IFERR_GOTO;
3347        ni=(l_code *) next_infoi(ni);
3348       break;
3349  }
3350  }
3351
3352#if CI_XMLELEM
3353#include "exmlelem.c"
3354#endif
3355
3356 case replac_end:
3357  {
3358   int lng,nx,lngfrom,lngto,difflen;
3359   stack_node op3_node;
3360   stack_node *op3;
3361   char *strtorep,*strfrom,*strto,*p1,*p2,*pnew;
3362   /* sintaxe: REPLACE(strtorep,strfrom,strto)     */
3363    nx=0;
3364   auxpop = pop(); IFERR_GOTO;
3365   op3=(stack_node *)memcpy(&op3_node,auxpop,sizeof(stack_node));
3366   auxpop = pop(); IFERR_GOTO;
3367   op2=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));
3368   auxpop = pop(); IFERR_GOTO;
3369   op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
3370   if (op1->classe!=string || op2->classe!=string  ||
3371                              op3->classe!=string ){
3372      inter_error("Invalid operands for 'replace' function ");
3373      IFERR_GOTO;
3374   }else{
3375      strtorep=(char *)op1->op.s;
3376      strfrom=(char *)op2->op.s;
3377      strto=(char *)op3->op.s;
3378      lng=strlen(strtorep);
3379      lngfrom=strlen(strfrom);
3380      lngto=strlen(strto);
3381      difflen=0;
3382      if (lngto>lngfrom) difflen=lngto-lngfrom;
3383#if TRACE_REPLACE
3384         printf( "\nRepl_str= |%d| |%s|",lng,strtorep);
3385         printf("\n Repl_from=|%d| |%s|",lngfrom,strfrom);
3386         printf("\n Repl_to=  |%d| |%s|",lngto,strto);
3387#endif
3388      nx=0;
3389      p1=strtorep;
3390      if (lngfrom <=0) p1=NULL; /* Nao tem o que substituir. O
3391                                Algoritmo entraria em loop  */
3392     /* Deternina a quantidade de substituicoes a serem feitas para
3393         calcular o tamanho do novo string a ser alocado */
3394      while (p1!=NULL){
3395#if TRACE_REPLACE
3396        printf("\n Testando oc nx:|%d| em:|%s|",nx,p1);
3397#endif
3398        p2=strstr(p1,strfrom);
3399        if (p2 !=NULL) {
3400           p2=p2+lngfrom;
3401           nx++;
3402        }
3403        p1=p2;
3404      }
3405     if (nx ==0 ) {
3406      pnew=strtorep;  /* Nao tem nada a substituir */
3407     }else {
3408       pnew=fmt_alloc_char( (ALLOPARM)(lng+1+nx*difflen),
3409                                         "cifm3/replace/alloc");
3410       if (pnew == NULL) IFERR_GOTO;
3411       *pnew=null_char;
3412       p1=strtorep;
3413       while (p1!=NULL) {
3414#if TRACE_REPLACE
3415          printf("\n Substiutindo orig:|%s|",p1);
3416          printf("\n Substituindo new :|%s|",pnew);
3417#endif
3418          p2=strstr(p1,strfrom);
3419          if (p2!=NULL) {
3420             *p2=null_char;
3421             strcat(pnew,p1);
3422             strcat(pnew,strto);
3423             p2=p2+lngfrom;
3424          }else strcat(pnew,p1); /* concatena ultimo pedaco */
3425          p1=p2;
3426       }/*while */
3427     } /* else */
3428     restore_context();
3429     elem.op.s=store_tmp_string(pnew);
3430     elem.classe=string;
3431     push(&elem);
3432     IFERR_GOTO;
3433   if (nx > 0) { /* houve alocacao  de memoria */
3434#if CICPP
3435        delete [] (char *)pnew;;
3436#else
3437        FREE(pnew);
3438#endif
3439    }
3440        ni=(l_code *) next_infoi(ni);
3441       break;
3442  }
3443  }
3444
3445
3446
3447   case begin_rep_gr:
3448      {
3449      if(rep_group==false)
3450       {rep_group=true;
3451        next_rep_occ=1;
3452       }
3453      else next_rep_occ++;
3454#if FMT_OPTIMIZE
3455      must_repeat=false;
3456      /* Implementar continue 17-7-94 */
3457      continue_rgroup=false;
3458#endif
3459      ni=(l_code *) next_infoi(ni);
3460      break;
3461      }
3462   case ref_beg:
3463     {
3464#if CICPP  /*ifcmm*/
3465      elem.classe=type_recstru;
3466      elem.op.lrecp=recp;
3467#else /*elsecmm*/
3468      elem.classe=long_n;
3469      elem.op.l=irec;
3470#endif /*CICPP*/  /*endcmm*/
3471      push(&elem);
3472      IFERR_GOTO;
3473#if 0 /* AOT+RP -  15/01/97 - read_mfn ja' chama fmt_comum_ref_beg() */
3474      fmt_comum_ref_beg();
3475#endif
3476      ni=(l_code *) next_infoi(ni);
3477      break;
3478     }
3479
3480   case ref_end:
3481   {
3482    fmt_comum_ref_end();
3483    IFERR_GOTO;
3484    ni=(l_code *) next_infoi(ni);
3485    break;
3486   }
3487   case refu_beg:
3488    {
3489     save_context(no_modify_fmt_pointers);
3490     IFERR_GOTO;
3491#if CICPP  /*ifcmm*/
3492     elem.classe=type_recstru;
3493     elem.op.lrecp=recp;
3494#else /*elsecmm*/
3495     elem.classe=long_n;
3496     elem.op.l=irec;
3497#endif /*CICPP*/  /*endcmm*/
3498     push(&elem);
3499     IFERR_GOTO;
3500#if 0 /* AOT+RP -  15/01/97 - read_mfn ja' chama fmt_comum_ref_beg() */
3501     fmt_comum_ref_beg();
3502#endif
3503     ni=(l_code *) next_infoi(ni);
3504     break;
3505     }
3506
3507   case refu_end:
3508   {
3509    fmt_comum_ref_end();
3510    IFERR_GOTO;
3511    restore_context();
3512    IFERR_GOTO;
3513    tmp_ptr=store_tmp_string(tmp_ptr);
3514    IFERR_GOTO;
3515    out[pout]=null_char;
3516    elem.op.s=tmp_ptr;
3517    elem.classe=string;
3518    push(&elem);
3519    IFERR_GOTO;
3520    ni=(l_code *) next_infoi(ni);
3521    break;
3522   }
3523
3524   case read_mfn:
3525   {
3526    auxpop = pop(); IFERR_GOTO;
3527    top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
3528    ref_mfn_number=fmt_cnv_to_long(top);
3529    /* se mfn=0; nao ha registro para formatar
3530       precisa ignorar todas as instrucoes relativas ao formato do ref
3531       deixando como instrucao a ultima ref_end
3532        Quando existe base de dados, o nome dela  esta na pilha
3533        campo iadd(i), vale 1L. Caso contrario vale 0L
3534    */
3535    literal[0]=null_char;
3536    if ((LONGX )iadd(ni) ==1L){
3537          auxpop = pop(); IFERR_GOTO;
3538          top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
3539          strcpy(literal, (char *) top->op.s );
3540 /*A06 Nao realoquei porque o nome do dbn tem que ser menor que 255*/
3541    }else strcpy(literal, firstdbnp);
3542#if BEFORE20030514
3543    if (ref_mfn_number==0L){
3544#else
3545    if (ref_mfn_number<=0L){
3546#endif
3547     fmt_fim=false;
3548     fmt_n_ref=1;
3549     while (fmt_fim==false){
3550       if(infoi(ni)==ref_beg || infoi(ni)==refu_beg) fmt_n_ref++;
3551       if(infoi(ni)==ref_end || infoi(ni)==refu_end) fmt_n_ref--;
3552       if(fmt_n_ref==0) fmt_fim=true; else ni=(l_code *) next_infoi(ni);
3553     }
3554    }else{
3555#define KEEPDBXR 0
3556#if KEEPDBXR
3557      LONGX idbx,keepndbx=ndbxs;
3558#endif /* KEEPDBXR */
3559
3560      fmt_comum_ref_beg();
3561
3562#if CICPP  /*ifcmm*/
3563      recp->xrecord(literal,ref_mfn_number);
3564#else /*elsecmm*/
3565      RECORD(irec,literal,ref_mfn_number);
3566#endif /*CICPP*/  /*endcmm*/
3567
3568#define FMTMFLUSH 0
3569#if FMTMFLUSH
3570      if (strcmp(firstdbnp,literal)) mstflush(literal);
3571#endif
3572
3573#if KEEPDBXR
3574      for (idbx=ndbxs-1; idbx>=keepndbx; idbx--)
3575          dbxflush(vdbxp[idbx]->dbxname);
3576#endif /* KEEPDBXR */
3577
3578/* Alocacao das maiores areas originalmente estaticas - AOT 29/12/90 */
3579#if DINALLOC
3580    if (!fmt_fsiz) {
3581      for (xdir=MFRnvf, xfsiz=0; xdir--; )
3582        if (DIRlen(xdir) > xfsiz) xfsiz=DIRlen(xdir);
3583      if (xfsiz > din_fsiz) {
3584        din_fsiz=xfsiz;
3585        if (fmttrace) printf("+++ fmt_inter - din_fsiz=%"_LD_"\n",din_fsiz);
3586        max_fd_value=din_fsiz;
3587        max_fd_tmp=din_fsiz;
3588#if CICPP
3589        delete [] (char *)v_fd_value;
3590        delete [] (char *)v_fd_tmp;
3591#else /* CICPP */
3592        FREE(v_fd_value);
3593        FREE(v_fd_tmp);
3594#endif /* CICPP */
3595#if CICPP
3596        try
3597        { v_fd_value= (char *)new char [(max_fd_value+1)]; }
3598        catch (BAD_ALLOC)
3599        { v_fd_value= (char *)NULL; }
3600#else /* CICPP */
3601        v_fd_value= (char *)ALLOC((ALLOPARM)(max_fd_value+1));
3602#endif /* CICPP */
3603        if (v_fd_value== (char *)NULL)
3604        {
3605          inter_error("1003");
3606          IFERR_GOTO;
3607        }
3608#if CICPP
3609        try
3610        { v_fd_tmp= (char *) new char[(max_fd_tmp+1)]; }
3611        catch (BAD_ALLOC)
3612        { v_fd_tmp= (char *)NULL; }
3613#else /* CICPP */
3614        v_fd_tmp=   (char *)ALLOC((ALLOPARM)(max_fd_tmp+1));
3615#endif /* CICPP */
3616        if (v_fd_tmp==   (char *)NULL)
3617        {
3618          inter_error("1004");
3619          IFERR_GOTO;
3620        }
3621        fd_value=v_fd_value;    /* DINALLOC */
3622      }
3623    }
3624#endif
3625      ni=(l_code *) next_infoi(ni);
3626     }
3627   break;
3628   }
3629
3630   case rupd_beg:
3631   case rupx_beg:
3632   case syst_beg:
3633   case date_mktime_beg:
3634   case l_beg:
3635   case np_beg:
3636   {
3637    save_context(modify_fmt_pointers);
3638    IFERR_GOTO;
3639    /* o formato a ser processado devera ser usado na lookup */
3640    ni=(l_code *)next_infoi(ni);
3641    break;
3642   }
3643
3644   case rupd_end:
3645   case rupx_end:
3646   case syst_end:
3647   case date_mktime_end:
3648   case l_end:
3649   case np_end:
3650   {
3651    LONGX p_mfn_lookup;
3652    LONGX nord;
3653
3654    /* Se houve referencia a database ele esta na pilha */
3655     new_dbname=NULL;
3656     if ((LONGX )iadd(ni) ==1L){
3657          auxpop = pop(); IFERR_GOTO;
3658          top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
3659          new_dbname=top->op.s; /* antes copiava para outra area*/
3660     }
3661
3662    /*copia para tmp_str e restaura contexto */
3663     restore_context();
3664     IFERR_GOTO;
3665     tmp_ptr=store_tmp_string(tmp_ptr);
3666     IFERR_GOTO;
3667     out[pout]=null_char;
3668
3669     if (infoi(ni) == rupd_end) {
3670         char *p;
3671#if CICPP
3672         p=recp->xfldupdat(tmp_ptr);
3673#else /* CICPP */
3674         p=fldupdat(irec,tmp_ptr);
3675#endif /* CICPP */
3676         if (p) fatal(p);
3677         ni=(l_code *)next_infoi(ni);
3678         break;
3679     }
3680     if (infoi(ni) == rupx_end) {
3681         /* procx.c */
3682#if FUNPROCX
3683#if MXFUN || IFLOADFUN
3684        char *p=tmp_ptr;
3685        while (isspace(*p)) p++;
3686#if MXFUN
3687        if (strncmp(p,"mx",2) == 0 && isspace(*(p+2))) { cisis_mx(p+2+1); }
3688#endif /* MXFUN */
3689#if IFLOADFUN
3690        if (strncmp(p,"ifload",6) == 0 && isspace(*(p+6))) { cisis_ifload(p+6+1); }
3691#endif /* IFLOADFUN */
3692#endif /* MXFUN || IFLOADFUN */
3693#endif /* FUNPROCX */
3694         ni=(l_code *)next_infoi(ni);
3695         break;
3696     }
3697
3698     if (infoi(ni) == syst_end) {
3699         /* system(tmp_ptr); AOT - 19/03/97 */
3700         char *shp,*p;
3701         for (shp=tmp_ptr; *shp; ) {
3702             for (p=shp; *p; p++)
3703                 if (*p == '\n' || *p == '\r') {
3704                     *p++ = '\0';
3705                     if (*p == '\n' || *p == '\r') *p++ = '\0';
3706                     break;
3707                 }
3708             if (*shp) system(shp);
3709             shp = p;
3710         }
3711         ni=(l_code *)next_infoi(ni);
3712         break;
3713     }
3714
3715     if (infoi(ni) == date_mktime_end) {
3716         /* mktime(<fmt>) AOT - 16/02/2001 */
3717         int year,mon,day,hour,min,sec;
3718         struct tm tpx;
3719         struct tm *tp= &tpx;
3720         char *p;
3721/*The allowable range of calendar times is Jan 1 1970 00:00:00 to Jan 19 2038 03:14:07.
3722*/
3723         if (strcmp(tmp_ptr,(p="19700102 000000")) < 0) strcpy(tmp_str,p);
3724         if (strcmp(tmp_ptr,(p="20380118 031407")) > 0) strcpy(tmp_str,p);
3725         sscanf(tmp_ptr,"%4d%2d%2d",&year,&mon,&day);
3726         hour=min=sec=0;
3727         if (strlen(tmp_ptr)>=11) sscanf(tmp_ptr+8, "%*c%2d",&hour);
3728         if (strlen(tmp_ptr)>=13) sscanf(tmp_ptr+11,"%2d",&min);
3729         if (strlen(tmp_ptr)>=15) sscanf(tmp_ptr+13,"%2d",&sec);
3730         tpx.tm_year=year-1900;
3731         tpx.tm_mon=mon-1;
3732         tpx.tm_mday=day;
3733         tpx.tm_hour=hour;
3734         tpx.tm_min=min;
3735         tpx.tm_sec=sec;
3736         tpx.tm_wday=tpx.tm_yday=0;
3737#if 0
3738time_t mktime(struct tm *t);
3739Converts the time in the structure pointed to by t
3740into a calendar time with the same format used by the time function.
3741#endif
3742         elem.op.l=mktime(tp);
3743         elem.classe=long_n;
3744         push(&elem);
3745         IFERR_GOTO;
3746         ni=(l_code *)next_infoi(ni);
3747         break;
3748     }
3749
3750
3751#if CICPP
3752     TRMSTRU *trmp;
3753     try { trmp=new TRMSTRU(cisisxp); }
3754     catch (BAD_ALLOC) { fatal("fmt/inter/reftrm/next"); }
3755#else /* CICPP */
3756     for (trm_prat=maxntrm; trm_prat--; ){
3757        if (!vtrmp[trm_prat]) /* ja' decrementado */
3758            break;
3759     }
3760     if (!trm_prat) fatal("fmt/inter/reftrm/next");
3761#endif /* CICPP */
3762     /*A03*/
3763     /*A04*/
3764     /* Modifica o tipo de acesso de posting para pedir total de
3765       posting  para instrucao NP ou o primeiro MFN em caso de
3766       da instrucao LOOKUP
3767     */
3768     nord=0L; /* supoe NP */
3769     if ( infoi(ni)==l_end)nord=1L;
3770
3771     if (new_dbname==NULL) new_dbname=firstdbnp; /* nao muda o acesso */
3772
3773     upcase_mode(tmp_ptr);
3774#if CICPP
3775     p_mfn_lookup=lookup(tmp_ptr,trmp,new_dbname,nord);
3776#else /* CICPP */
3777     p_mfn_lookup=lookup(tmp_ptr,trm_prat,new_dbname,nord);
3778#endif /* CICPP */
3779
3780    /*A03*/
3781#if CICPP
3782     delete trmp;
3783#else /* CICPP */
3784     if (vtrmp[trm_prat]!=NULL) { /* SVD 14-05-92 */
3785          FREE(vtrmp[trm_prat]); vtrmp[trm_prat]=NULL; ntrms--;
3786     }                           /* SVD 14-05-92 */
3787#endif /* CICPP */
3788
3789     if (p_mfn_lookup <0) p_mfn_lookup=0;
3790
3791     elem.op.l=p_mfn_lookup;
3792     elem.classe=long_n;
3793     push(&elem);
3794     IFERR_GOTO;
3795
3796     ni=(l_code *)next_infoi(ni);
3797     break;
3798   }
3799
3800   case lw_beg:
3801     {
3802     ni=(l_code *) next_infoi(ni);
3803     break;
3804     }
3805
3806   case lw_end:
3807        { /* valor do numero gerado da pilha  */
3808         fd_value[0]=null_char;
3809     auxpop = pop(); IFERR_GOTO;
3810     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
3811     is_numeric(top->classe);
3812     IFERR_GOTO;
3813         lw_inter=(LONGX)top->op.l;
3814         ni=(l_code *) next_infoi(ni);
3815         break;
3816        }
3817   case f_beg:
3818   case instr_beg:
3819   case left_beg:
3820   case right_beg:
3821   case mid_beg:
3822   case replac_beg:
3823#if CI_XMLELEM
3824   case xmlelem_beg:
3825#endif
3826   case ss_beg:        /*A10*/
3827   case datex_beg:
3828     {
3829     save_context(modify_fmt_pointers);
3830     IFERR_GOTO;
3831     ni=(l_code *) next_infoi(ni);
3832     break;
3833     }
3834
3835   case datex_end:
3836    {
3837     char *tmpch;
3838     fd_value[0]=null_char;
3839     auxpop = pop(); IFERR_GOTO;
3840     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
3841     is_numeric(top->classe);
3842     IFERR_GOTO;
3843     float_exp_value =  fmt_cnv_to_float(top);
3844      tmpch=fmt_get_date(0,float_exp_value);
3845      if(is_upper_mode(actual_mode)) upcase_mode(tmpch);
3846/*
3847   tmpch=store_tmp_string(tmp_ptr);
3848   IFERR_GOTO;
3849*/
3850   restore_context();
3851   IFERR_GOTO;
3852        elem.op.s=tmpch;
3853        elem.classe=string;
3854        push(&elem);
3855        IFERR_GOTO;
3856   ni=(l_code *) next_infoi(ni);
3857   break;
3858   }
3859
3860   case f_end:                          /* SVD alterado em 25/11/90 */
3861    { /* retirar os tres parametros da pilha */
3862     char *tmpch;
3863     fd_value[0]=null_char;
3864                   /* AOT - Correcao SVD 21/08/90 */
3865     auxpop = pop(); IFERR_GOTO;
3866     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
3867         is_not_of_class(top->classe,long_n);
3868         IFERR_GOTO;
3869     is_numeric(top->classe);
3870     IFERR_GOTO;
3871         dec_places=(int)top->op.l;
3872
3873     auxpop = pop(); IFERR_GOTO;
3874     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
3875         is_not_of_class(top->classe,long_n);
3876         IFERR_GOTO;
3877     is_numeric(top->classe);
3878     IFERR_GOTO;
3879         min_width=(int)top->op.l;
3880
3881
3882     auxpop = pop(); IFERR_GOTO;
3883     top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
3884     is_numeric(top->classe);
3885     IFERR_GOTO;
3886     float_exp_value =  fmt_cnv_to_float(top);
3887#if DEB_FLOAT
3888 printf("\n++Antes de formatar out=");
3889 for (i=0;i<=pout;i++)printf("%c",out+i);
3890  printf("|");
3891
3892#endif
3893#if MPE || VAX || UNIX
3894    tmpch=fmt_float_numb(float_exp_value,min_width,dec_places,space_char);
3895#else
3896    tmpch=fmt_float_numb(float_exp_value,min_width,dec_places,space_char);
3897#endif
3898
3899#if DEB_FLOAT
3900 printf("\n++Apos formatar out=");
3901  for (i=0;i<=pout;i++)printf("%c",out+i);
3902  printf("|");
3903
3904 printf("\ntmpch=%s|",tmpch);
3905#endif
3906
3907   restore_context();
3908   IFERR_GOTO;
3909   tmp_ptr=store_tmp_string(tmpch);
3910   IFERR_GOTO;
3911        elem.op.s=tmp_ptr;
3912        elem.classe=string;
3913        push(&elem);
3914        IFERR_GOTO;
3915
3916/*     strcpy(out,ss); agora ja gerou um print-string,load-string ou nada */
3917   ni=(l_code *) next_infoi(ni);
3918   break;
3919   }
3920   case s_beg:
3921   case getenv_beg:
3922   case putenv_beg:
3923   case citype_beg:
3924   case cat_beg:
3925   case nl_beg:
3926   case sattrib_beg:
3927   case type_beg:
3928     {
3929     save_context(modify_fmt_pointers);
3930     IFERR_GOTO;
3931     ni=(l_code *) next_infoi(ni);
3932     break;
3933     }
3934
3935   case s_end:
3936   {
3937      restore_context();
3938      IFERR_GOTO;
3939      /* substring em S */
3940      itf=(field_definition_node *) iadd(ni);
3941      if(itf->offset!= -1 && itf->length!= -1)
3942          strcpy(tmp_ptr,sub_string(tmp_ptr,itf->offset,itf->length));
3943      tmp_ptr=store_tmp_string(tmp_ptr);
3944      IFERR_GOTO;
3945      out[pout]=null_char;
3946      elem.op.s=tmp_ptr;
3947      elem.classe=string;
3948      push(&elem);
3949      IFERR_GOTO;
3950      ni=(l_code *) next_infoi(ni);
3951      break;
3952   }
3953
3954   case sattrib_end:
3955   {  char *q;
3956      int ind;
3957      restore_context();
3958      IFERR_GOTO;
3959      ind= (int)iadd(ni);
3960      fmt_free_S(ind,ind);
3961      q=strdup(tmp_ptr); /*??? como testar retorno */
3962      IFERR_GOTO;
3963      S_var[ind] = q;
3964#if DEB_ATTRIB
3965  printf("\ntmp_ptr=|%s|,S_var[%d]=%s",tmp_ptr,(int)iadd(ni),S_var[(int) iadd(ni)]);
3966#endif
3967      out[pout]=null_char;
3968
3969      ni=(l_code *) next_infoi(ni);
3970      break;
3971   }
3972   case strvvalue:
3973   {  char *t;
3974      t=store_tmp_string(S_var[(int) iadd(ni)]);
3975      elem.op.s=t;
3976      elem.classe=string;
3977      push(&elem);
3978      IFERR_GOTO;
3979      ni=(l_code *) next_infoi(ni);
3980      break;
3981   }
3982
3983   case getenv_end:
3984   {
3985      char *ep;
3986      restore_context();
3987      IFERR_GOTO;
3988      /* substring em S */
3989      itf=(field_definition_node *) iadd(ni);
3990      ep=NULL; if (*tmp_ptr) ep=getenv(tmp_ptr); /* AOT 04/03/97 */
3991      if (ep) {
3992          tmp_ptr=store_tmp_string(ep);
3993      }
3994      else
3995      if (strncmp(tmp_ptr,"tmp=",4) == 0) {
3996          tmp_ptr+=4; /* tmp= */
3997          ep=dbxtmpnm(NULL/*"CI_TEMPDIR"*/,0,tmp_ptr);
3998          tmp_ptr=store_tmp_string(ep);
3999      }
4000#if CICGI /* get cgi - AOT 12/09/2000 */
4001      else
4002      if (strncmp(tmp_ptr,"cgi=",4) == 0) {
4003#if CICPP
4004        //CGIClass *cgi = new CGIClass(cisisxp);
4005        //cgi->cicgi0(NULL, NULL, &wwwp, (UWORD)1, "tag"); /* H1 10 ^ndbn^vcdsH1 10 ^ncount^v2H1 7 ^nnow^vH1 10 ^nbtell^v0H1 20 ^nbool^vplants*waterH1 15 ^npft^vmfn/v24/ */
4006        //delete cgi;
4007#else /* CICPP */
4008#if CIWTF                                /* WTFUN support */
4009        tmp_ptr+=4; /* cgi= */
4010        if (!ciahcgi) {
4011            char *wwwp=NULL;
4012            cicgi0(NULL, NULL, &wwwp, (UWORD)2000, "tag"); /* H2000 10 ^ndbn^vcdsH2000 10 ^ncount^v2H2000 7 ^nnow^vH2000 10 ^nbtell^v0H2000 20 ^nbool^vplants*waterH2000 15 ^npft^vmfn/v24/ */
4013            ciahcgi=wwwp;
4014        }
4015        if (ciahcgi) {
4016            char *p,cnam[3+LE2+2+1]; //.^nxxx^v
4017            int cnamlen;
4018            if (strlen(tmp_ptr)>LE2) tmp_ptr[LE2]='\0'; sprintf(cnam," ^n%s^v",tmp_ptr); cnamlen=strlen(cnam);
4019            for (p=ciahcgi; (p=strstr(p,"H2000 ")) != NULL; ) {
4020                int s;
4021                char k;
4022                p+=6; for (s=0; *p && isdigit(*p); p++) s=s*10+(int)(*p)-(int)'0';
4023                if (!s) continue;
4024                if (strncmp(p,cnam,cnamlen)) continue;
4025                p+=cnamlen; ep=p;
4026                k=ep[s]; ep[s]='\0'; tmp_ptr=store_tmp_string(ep); ep[s]=k;
4027                break;
4028            }
4029        }
4030#else /* CIWTF */
4031        static char *fmtwwwp=NULL;
4032        char *wwwp=NULL;
4033        int len,qn=0;
4034        FFI ffilen;
4035        char *p,*vp,*q;
4036        tmp_ptr+=4; /* cgi= */
4037        if (!fmtwwwp) {
4038            cicgi0(NULL, NULL, &wwwp, (UWORD)1, "tag"); /* H1 10 ^ndbn^vcdsH1 10 ^ncount^v2H1 7 ^nnow^vH1 10 ^nbtell^v0H1 20 ^nbool^vplants*waterH1 15 ^npft^vmfn/v24/ */
4039            fmtwwwp=wwwp;
4040        }
4041        wwwp=fmtwwwp;
4042        for (q=p=wwwp; *p; ) {
4043          if (*p++ != 'H') break; if (*p++ != '1') break; if (*p++ != ' ') break;
4044          len=atoi(p); while(isdigit(*p)) p++; if (len < 5) break; if (*p++ != ' ') break;
4045          ffilen=(FFI)len; vp=(char *)subfldp((unsigned char *)p,'v',&ffilen); if (!vp) break;
4046          *(vp-2)='\0';
4047          if (strcmp(p+2,tmp_ptr) == 0) {
4048              /* if (!ffilen) ep=p+2; else { ep=vp; ep[ffilen]='\0'; } break; */
4049              if (!ffilen) { ep=p+2; ffilen=strlen(ep); } else ep=vp;
4050              if (qn) *q++='%'; strncpy(q,ep,ffilen); q+=ffilen; *q='\0'; qn++;
4051          }
4052          p+=len;
4053        }
4054        if (qn) strcpy(ep=tmp_ptr,wwwp);
4055        tmp_ptr=store_tmp_string(ep);
4056#endif /* CIWTF */
4057#endif /* CICPP */
4058      }
4059#endif /* get cgi - AOT 12/09/2000 */
4060      if (!ep) tmp_ptr=store_tmp_string(ep);
4061      IFERR_GOTO;
4062      out[pout]=null_char;
4063      elem.op.s=tmp_ptr;
4064      elem.classe=string;
4065      push(&elem);
4066      IFERR_GOTO;
4067      ni=(l_code *) next_infoi(ni);
4068      break;
4069   }
4070
4071   case putenv_end:
4072   {
4073      char *ep;
4074      restore_context();
4075      IFERR_GOTO;
4076      /* substring em S */
4077      itf=(field_definition_node *) iadd(ni);
4078#if BEFORE20000913
4079      /* bug: vai alocar e nao liberar antes do fim de exec. - AOT 03/09/97 */
4080      ep=NULL; if (*tmp_ptr) ep=putenv(strdup(tmp_ptr)) ? tmp_ptr : NULL;
4081#else
4082      ep=NULL;
4083      if (*tmp_ptr) {
4084          char *ip,*op;
4085          ip=strchr(tmp_ptr,'=');
4086          if (ip) {
4087              *ip='\0'; op=getenv(tmp_ptr); *ip='=';
4088              if (op) {
4089                  char c;
4090                  /* To delete the variable from the environment, use getenv("name=") */
4091                  ip++; c= *ip; *ip='\0'; getenv(tmp_ptr); *ip=c;
4092              }
4093          }
4094          ep=putenv(strdup(tmp_ptr)) ? tmp_ptr : NULL;
4095      }
4096#endif
4097      tmp_ptr=store_tmp_string(ep);
4098      IFERR_GOTO;
4099      out[pout]=null_char;
4100      elem.op.s=tmp_ptr;
4101      elem.classe=string;
4102      push(&elem);
4103      IFERR_GOTO;
4104      ni=(l_code *) next_infoi(ni);
4105      break;
4106   }
4107
4108   case citype_end:
4109   {
4110     char *tt;
4111     restore_context(); /* Temporario tem que analizar o resultado */
4112     IFERR_GOTO;
4113     tt=fmt_type(tmp_ptr);
4114     tmp_ptr=store_tmp_string(tt);
4115     IFERR_GOTO;
4116     out[pout]=null_char;
4117     elem.op.s=tmp_ptr;
4118     elem.classe=string;
4119     push(&elem);
4120     IFERR_GOTO;
4121     ni=(l_code *) next_infoi(ni);
4122     break;
4123   }
4124
4125   case type_end:
4126   {
4127     LONGX rr ;
4128     rr=0;
4129     /* pattern ou valor numerico */
4130     auxpop = pop(); IFERR_GOTO;
4131     op1=(stack_node *)memcpy(&op1_node,auxpop,sizeof(stack_node));
4132
4133     /* como deve ser interpretado o operador 1 */
4134     auxpop = pop(); IFERR_GOTO;
4135     op2=(stack_node *)memcpy(&op2_node,auxpop,sizeof(stack_node));
4136     is_not_of_class(op2->classe,long_n);
4137      IFERR_GOTO;
4138     tmp_ptr= &out[0];
4139     if(op2->op.l == TYPE_PATTERN ){
4140      rr = fmt_type_pattern(op1->op.s,tmp_ptr);
4141     }else {
4142       if ( op2->op.l == TYPE_NUM ){
4143        rr = fmt_type_number(op1->op.l,tmp_ptr);
4144       }
4145
4146     }
4147     restore_context();
4148     IFERR_GOTO;
4149
4150     out[pout]=null_char;
4151     elem.op.l=rr;
4152     elem.classe=long_n;
4153     push(&elem);
4154     IFERR_GOTO;
4155     ni=(l_code *) next_infoi(ni);
4156     break;
4157   }
4158
4159   case cat_end:
4160   {
4161    /* Para poder usar cat como funcao e como elemento de formato
4162       e' necessario gerar um resultado para ser testado ou formatado
4163       na proxima instrucao. Por enquanto um valor "\0" esta sendo
4164       armzenado. Os testes de if nao funcionarao porque sempre
4165       sera esse valor armazenado. Deve ser discutido com AOT/ABEL
4166       Solucao: No cifm1
4167          - Quando for elemento gerar "\0" .
4168          - Quando for if/expre/ gerar 0 se erro e 1 se ok.
4169    */
4170
4171     int  fp;
4172     char ch[2];
4173     int keep_ordwr; /* AOT, 28/05/99 */
4174
4175     restore_context(); /* Temporario tem que analizar o resultado */
4176     IFERR_GOTO;
4177     if (strcmp(tmp_str,"+fields") == 0) {
4178#if 0
4179       char line..
4180       ch[1]=null_char;
4181       while (CIREAD(fp,&ch[0],sizeof(char))> 0)
4182          out_put_str(out,outsize, &pout,lw_inter,0,0, &nextcc,(char *)&ch);
4183#endif
4184     }
4185     else { /* AOT 05/10/02 */
4186     dbxopt_fatal=0;
4187     keep_ordwr=dbxopt_ordwr; dbxopt_ordwr=O_RDONLY; /* AOT 28/05/99 */
4188     fp=dbxopen(NULL,tmp_ptr,NULL);
4189     dbxopt_ordwr=keep_ordwr; /* AOT 28/05/99 */
4190     ch[1]=null_char;
4191     if (fp >= 0){
4192       while (CIREAD(fp,&ch[0],sizeof(char))> 0) {
4193          out_put_str(out,outsize, &pout,lw_inter,0,0, &nextcc,(char *)&ch);
4194       }
4195       CLOSE(fp);
4196     }else{
4197
4198         erro(1708);
4199/*       elem.op.s=store_tmp_string("\0"); */
4200      }
4201     } /* AOT 05/10/02 */
4202     IFERR_GOTO;
4203     out[pout]=null_char;
4204     elem.op.s=store_tmp_string("\0");
4205     elem.classe=string;
4206     push(&elem);
4207     IFERR_GOTO;
4208
4209     ni=(l_code *) next_infoi(ni);
4210     break;
4211   }
4212   case nl_end:
4213   {
4214     int len;
4215     restore_context(); /* Temporario tem que analizar o resultado */
4216     IFERR_GOTO;
4217#if TRACESINDO
4218     printf("\n Valor gerado de tmp_ptr=|%s|",tmp_ptr);
4219#endif
4220     len=strlen(tmp_ptr);
4221     if (len > nl_LEN) {
4222#if CICPP
4223        delete [] (char *)nl_STR;
4224#else
4225        FREE(nl_STR);
4226#endif
4227        nl_STR=fmt_alloc_char((ALLOPARM)(len+1),"cifm3/alloc/nl_end");
4228     }
4229/*     strcpy((char *)nl_STR,(char *)tmp_ptr); */
4230/*        sprintf((char *)nl_STR,(char *)tmp_ptr,"");  Nao funcionou porque
4231          (eu acho) que o c traduz \n diretamente para 1 caracter e nao
4232          dois carcteres \ seguido de n */
4233#if 1
4234     sc((char *)tmp_ptr);
4235#endif
4236     strcpy(nl_STR,tmp_ptr);
4237     nl_LEN=strlen(nl_STR);
4238#if TRACESINDO
4239     printf("\n Novo Valor gerado de nl_STR=|%s|",(char *)nl_STR);
4240#endif
4241
4242     out[pout]=null_char;
4243     ni=(l_code *) next_infoi(ni);
4244     break;
4245   }
4246
4247   case dbname_beg:
4248     {
4249     save_context(modify_fmt_pointers);
4250     IFERR_GOTO;
4251     ni=(l_code *) next_infoi(ni);
4252     break;
4253     }
4254
4255   case dbname_end:
4256   {
4257      restore_context();
4258      IFERR_GOTO;
4259      tmp_ptr=store_tmp_string(tmp_ptr);
4260      IFERR_GOTO;
4261      out[pout]=null_char;
4262      elem.op.s=tmp_ptr;
4263      elem.classe=string;
4264      push(&elem);
4265      IFERR_GOTO;
4266      ni=(l_code *) next_infoi(ni);
4267      break;
4268   }
4269
4270   case str_cat:
4271   {
4272   auxpop = pop(); IFERR_GOTO;
4273   top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
4274   is_not_of_class(top->classe,string);
4275   IFERR_GOTO;
4276   out_put_str(out,outsize, &pout,lw_inter,0,0, &nextcc,top->op.s);
4277   ni=(l_code *) next_infoi(ni);
4278   break;
4279   }
4280   case prt_str_f:
4281   {
4282
4283/* Quem chama deve inicializar os pointers de acordo . Acho que o nextcc
4284   tem que ser sempre o mesmo entre todas as chamadas. Quem deve tomar
4285   conta e o usuario. Inicialmente eu achava que ao retornar deveria
4286   formatar nas condicoes que estava ANTEs da chamada , mas agora acho que
4287   tem apenas que concatenar . Ver no isis e depois testar
4288
4289      out_put_str(out,outsize, &pout,lw_inter,0,0, &nextcc,top->op.s);
4290*/
4291/*   strcat(out,top->op.s); */            /* SVD correcao 20/11/90*/
4292
4293/*   nextcc=deve_ser o ultimo chamado; */
4294   auxpop = pop(); IFERR_GOTO;
4295   top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
4296   is_not_of_class(top->classe,string);
4297   IFERR_GOTO;
4298#if DEB_FLOAT
4299   printf("\n--Desempilhou=%s|",top->op.s);
4300   printf("\n--out=%s|",out);
4301#endif
4302      out_put_str(out,outsize, &pout,lw_inter,0,0, &nextcc,top->op.s);
4303
4304   ni=(l_code *) next_infoi(ni);
4305   break;
4306   }
4307/*    case load_str_f: */
4308
4309   case rsum_beg:
4310   case ravr_beg:
4311   case rmin_beg:
4312   case rmax_beg:
4313   case val_beg:
4314   case size_beg:
4315   case eattrib_beg:
4316  {
4317     save_context(modify_fmt_pointers);
4318     IFERR_GOTO;
4319     ni=(l_code *) next_infoi(ni);
4320     break;
4321     }
4322   case rsum_end:
4323   case ravr_end:
4324  {    float_x sum;
4325#if !PC
4326       float_x x;
4327#endif
4328       int k;
4329
4330        restore_context();
4331        IFERR_GOTO;
4332        sum=(float_x ) 0;
4333        i=0;
4334        k=0;
4335        pstr_num=find_numeric_string(tmp_ptr,&i);
4336        while ((size_t)strlen(pstr_num)>(size_t)0 )
4337        {
4338         k++;
4339/* HB 20080901 - a funcao fmt_float_numb nao converte corretamente se float_x for float
4340#if PC
4341*/
4342#if 1
4343         sum=sum+ (float_x) atof(pstr_num);
4344#else
4345         sscanf(pstr_num,float_x_fmt,&x);
4346         sum=sum+ x;
4347#endif
4348         pstr_num=find_numeric_string(tmp_ptr,&i);
4349        }
4350
4351        if (infoi(ni)==ravr_end && k!=0)sum=sum/k;
4352
4353        elem.op.r=sum;
4354        elem.classe=float_n;
4355        push(&elem);
4356        IFERR_GOTO;
4357
4358        out[pout]=null_char;
4359        ni=(l_code *) next_infoi(ni);
4360        break;
4361   }
4362   case rmin_end:
4363   case rmax_end:
4364  {
4365        float_x sum,min_value,max_value;
4366
4367        restore_context();
4368        IFERR_GOTO;
4369        i=0;
4370        pstr_num=find_numeric_string(tmp_ptr,&i);
4371/* HB 20080901 - a funcao fmt_float_numb nao converte corretamente se float_x for float
4372#if PC
4373*/
4374#if 1
4375        sum=(float_x) atof(pstr_num);
4376#else
4377        sscanf(pstr_num,float_x_fmt,&sum);
4378#endif
4379        min_value=sum;
4380        if (infoi(ni)==rmax_end) max_value=sum;
4381        while ((size_t)strlen(pstr_num)>(size_t)0 )
4382        {
4383/* HB 20080901 - a funcao fmt_float_numb nao converte corretamente se float_x for float
4384#if PC
4385*/
4386#if 1         
4387         sum=(float_x) atof(pstr_num);
4388#else
4389         sscanf(pstr_num,float_x_fmt,&sum);
4390#endif
4391         if( infoi(ni)==rmin_end && min_value>sum)min_value=sum;
4392         if( infoi(ni)==rmax_end && max_value<sum)max_value=sum;
4393         pstr_num=find_numeric_string(tmp_ptr,&i);
4394        }
4395        elem.op.r=min_value;
4396        if (infoi(ni)==rmax_end) elem.op.r=max_value;
4397        elem.classe=float_n;
4398        push(&elem);
4399        IFERR_GOTO;
4400
4401        out[pout]=null_char;
4402        ni=(l_code *) next_infoi(ni);
4403        break;
4404   }
4405   case val_end:
4406  {
4407/*
4408         auxpop = pop(); IFERR_GOTO;
4409        top=(stack_node *)memcpy(&top_node,auxpop,sizeof(stack_node));
4410        is_not_of_class(top->classe,string)
4411        IFERR_GOTO;
4412*/
4413        tmp_ptr=out;
4414        i=0; /* pointer inicial dentro da string */
4415        pstr_num=find_numeric_string(tmp_ptr,&i);
4416/* HB 20080901 - a funcao fmt_float_numb nao converte corretamente se float_x for float
4417#if PC
4418*/
4419#if 1
4420        elem.op.r=(float_x) atof(pstr_num);
4421#else
4422        sscanf(pstr_num,float_x_fmt,&(elem.op.r));
4423        /* elem.op.r = strtod(pstr_num,NULL); */
4424#endif
4425        elem.classe=float_n;
4426
4427        restore_context();
4428        IFERR_GOTO;
4429        out[pout]=null_char;
4430        push(&elem);
4431        IFERR_GOTO;
4432
4433        ni=(l_code *) next_infoi(ni);
4434        break;
4435   }
4436
4437   case size_end:
4438  {
4439        elem.op.l= (LONGX ) strlen(out);
4440        elem.classe=long_n;
4441        restore_context();
4442        IFERR_GOTO;
4443        push(&elem);
4444        IFERR_GOTO;
4445        out[pout]=null_char;
4446        ni=(l_code *) next_infoi(ni);
4447        break;
4448   }
4449
4450   case eattrib_end:
4451  {
4452     float_x x;
4453     auxpop = pop(); IFERR_GOTO;
4454     x = convert_to_float(auxpop);
4455     E_var[(int) iadd(ni)]= x;
4456
4457     restore_context();
4458     IFERR_GOTO;
4459     out[pout]=null_char;
4460     ni=(l_code *) next_infoi(ni);
4461     break;
4462   }
4463
4464   case end_rep_gr:
4465      {
4466        rep_group=false;
4467        next_rep_occ=0;
4468        ni=(l_code *) next_infoi(ni);
4469        break;
4470      }
4471   case beg_init_not_rep:
4472      {
4473       fmt_inicio_grupos_vfields(beg_init_not_rep,end_init_not_rep);
4474       IFERR_GOTO;
4475       ni=(l_code *)ni->next;
4476       break;
4477      }
4478   case end_init_not_rep:
4479      {
4480        fmt_fim_grupos_vfields();
4481        IFERR_GOTO;
4482
4483#if TRACE_REPF
4484      printf("\n [out=]%s",out);
4485      printf("\n [End_init_not_rep <pop>] rep_goup=%d next_rep_occ=%d",
4486               rep_group,next_rep_occ);
4487#endif
4488        ni=(l_code *)ni->next;
4489        break;
4490      }
4491   case beg_init_rep:
4492      {
4493       fmt_inicio_grupos_vfields(beg_init_rep,end_init_rep);
4494       IFERR_GOTO;
4495#if DEB_NOCC
4496       printf("\n processando ocorrenci=%"_LD_,next_rep_occ);
4497#endif
4498       ni=(l_code *)ni->next;
4499       break;
4500      }
4501   case end_init_rep:
4502      {
4503        fmt_fim_grupos_vfields();
4504        IFERR_GOTO;
4505#if TRACE_REPF
4506      printf("\n [out=]%s",out);
4507      printf("\n [End_init_rep <pop>] rep_goup=%d next_rep_occ=%d",
4508               rep_group,next_rep_occ);
4509#endif
4510        ni=(l_code *)ni->next;
4511        break;
4512      }
4513/* Continue em grupos repetitivos  17-7-94 */
4514   case continueins:
4515      {
4516        continue_rgroup=true;
4517        ni=(l_code *)ni->next;
4518        break;
4519      }
4520 default:
4521  {
4522     ni=(l_code *) next_infoi(ni);
4523     break;
4524  }
4525}  /* switch */
4526  if (ni==nulo) fim_pgm=true;
4527}  /* while */
4528
4529
4530/* Liberacao das maiores areas originalmente estaticas - AOT 29/12/90 */
4531#if DINALLOC
4532#if CICPP
4533    delete [] (char *)tmp_str;
4534    delete [] (char *)v_fd_value;
4535    delete [] (char *)v_fd_tmp;
4536/*A06*/
4537    if (literal !=NULL) delete [] (char *)literal;
4538/*A07*/
4539    lineqtt = number_of_lines(out); /* RPIVA - use nl_STR before FREE */
4540    delete [] (char *)nl_STR;
4541#else /* CICPP */
4542    FREE(tmp_str);
4543    FREE(v_fd_value);
4544    FREE(v_fd_tmp);
4545/*A06*/
4546    if (literal != NULL) {
4547       FREE(literal);
4548    }
4549#if BEFORE20000405
4550    fmt_free_S(0,NMAXVAR);
4551#else
4552    fmt_free_S(0,NMAXVAR-1); /* AOT/HB - pois fmt_free_S assume from e to */
4553#endif
4554/*A07*/
4555    lineqtt = number_of_lines(out); /* RPIVA - use nl_STR before FREE */
4556    FREE(nl_STR);
4557#endif /* CICPP */
4558#endif
4559    if (fmttrace) printf("+++ fmt_inter - success \n"); /* AOT 27/12/91 */
4560
4561if (erro_fatal==0 )
4562  {
4563    return (lineqtt);
4564  }
4565  else return(erro_fatal);
4566
4567}
4568
4569/*-------------------------------------------------------------------------*/
4570
4571/*--------------------------------------------------------------------------*/
4572/*                   inter_error                                            */
4573/*--------------------------------------------------------------------------*/
4574
4575#if CICPP
4576void FMTSTRU :: inter_error(char *err)
4577#else /* CICPP */
4578#if ANSI
4579void inter_error(char *err)
4580#else /* ANSI */
4581void inter_error(err)
4582char *err;
4583#endif /* ANSI */
4584#endif /* CICPP */
4585{
4586    int errl;
4587#if TRACE_REPF
4588    printf("\n *** INTER -%s",err);
4589#endif
4590
4591#if DINALLOC
4592#if CICPP
4593    delete [] (char *)tmp_str;
4594    delete [] (char *)v_fd_value;
4595    delete [] (char *)v_fd_tmp;
4596/*A06*/
4597    if (literal != NULL) delete [] (char *)literal;
4598/*A07*/
4599    delete [] (char *)nl_STR;
4600#else /* CICPP */
4601    FREE(tmp_str);
4602    FREE(v_fd_value);
4603    FREE(v_fd_tmp);
4604/*A06*/
4605    if (literal != NULL) FREE(literal);
4606/*A07*/
4607    FREE(nl_STR);
4608#endif /* CICPP */
4609#endif
4610
4611    errl=strlen(err);
4612    if (errl >= MAXERRL) errl=MAXERRL;
4613
4614    strncpy(fmterrxy,err,errl); fmterrxy[errl]='\0';
4615
4616#if FATRAP
4617    longjmp(fmtjumper,-1);
4618#else  /* FATRAP */
4619    fmterror = -1;
4620    return;
4621#endif /* FATRAP */
4622    fatal("inter_error"); /* just in case */
4623}
4624
4625
4626/* --------------------LOOKUP.C --------------------------------*/
4627
4628#if CICPP
4629LONGX FMTSTRU :: lookup(char *keyp,
4630                       TRMSTRU *trmp,
4631                       char *dbnp,
4632                       LONGX nord)
4633#else /* CICPP */
4634#if ANSI
4635LONGX lookup(char *keyp,LONGX next_inverted_prat,char *dbnp,LONGX nord)
4636#else /* ANSI */
4637LONGX lookup(keyp,next_inverted_prat,dbnp,nord)
4638char *keyp;
4639LONGX next_inverted_prat;
4640char *dbnp;
4641LONGX nord;
4642#endif /* ANSI */
4643#endif /* CICPP */
4644{
4645#if !CICPP
4646    TRMSTRU *trmp;
4647#endif
4648    LONGX pmfn;
4649    pmfn=0;
4650        if (*keyp)
4651        {
4652#define KEEPDBXT 0
4653#if KEEPDBXT
4654            LONGX idbx,keepndbx=ndbxs;
4655#endif /* KEEPDBXT */
4656#if CICPP
4657            trmp->xterm((UCHR *)dbnp,(UCHR *)keyp);
4658#else /* CICPP */
4659            TERM(next_inverted_prat,(UCHR *)dbnp,(UCHR *)keyp);
4660#endif /* CICPP */
4661            if (TRMrc == RCNORMAL) {
4662#if CICPP
4663                pmfn=trmp->xposting(nord);
4664#else /* CICPP */
4665                pmfn=posting(next_inverted_prat,nord);
4666#endif /* CICPP */
4667            }
4668#define FMTIFLUSH 0
4669#if FMTIFLUSH
4670            if (strcmp(firstdbnp,dbnp)) invflush(dbnp);
4671#endif
4672#if KEEPDBXT
4673            for (idbx=ndbxs-1; idbx>=keepndbx; idbx--)
4674                dbxflush(vdbxp[idbx]->dbxname);
4675#endif /* KEEPDBXT */
4676        }
4677  return pmfn;
4678}
4679
4680
4681
4682/*--------------------------------------------------------------------------*/
4683/*                   recfmt.c                                               */
4684/*--------------------------------------------------------------------------*/
4685
4686#if !CICPP || CIAPI_SOURCE
4687#if CIAPI_SOURCE
4688LONGX recfmtcmp(RECSTRU* recp, LONGX lw, char *fmt, char *area, LONGX asize,
4689                    FMTSTRU **ptpgm, int flagfree)
4690#else /* CIAPI_SOURCE */
4691LONGX recfmtcmp (idx,lw,fmt,area,asize,ptpgm,flagfree)
4692LONGX idx;
4693LONGX lw;
4694char *fmt;
4695char *area;
4696LONGX asize;
4697l_code **ptpgm;
4698int flagfree;
4699#endif /* CIAPI_SOURCE */
4700{
4701        LONGX lines;
4702        if (!*ptpgm)
4703#if CIAPI_SOURCE
4704                if ((*ptpgm)->xfmt_gener(fmt)) {
4705                        return (-(*ptpgm)->fmt_error);
4706#else /* CIAPI_SOURCE */
4707                if (fmt_gener (ptpgm, fmt)) {
4708                        return (-fmt_error);
4709#endif /* CIAPI_SOURCE */
4710                        /* printf ("\n Deu erro de formato"); */
4711                }
4712#if PRINT_CODE
4713/*svd 15-05-92 */ print_inter_din(fmt,*ptpgm);
4714#endif
4715
4716#if CIAPI_SOURCE
4717        lines = (*ptpgm)->xfmt_inter (recp, lw, area, asize);
4718#else /* CIAPI_SOURCE */
4719        lines = fmt_inter (*ptpgm, idx, lw, area, asize);
4720#endif /* CIAPI_SOURCE */
4721        if (flagfree) {
4722#if CIAPI_SOURCE
4723                (*ptpgm)->xfmt_free();
4724#else /* CIAPI_SOURCE */
4725                fmt_free (*ptpgm);
4726                *ptpgm = NULL;
4727#endif /* CIAPI_SOURCE */
4728        }
4729        return (lines);
4730}
4731
4732#if CIAPI_SOURCE
4733LONGX recfmt( RECSTRU* recp, LONGX lw, char *fmt, char *area, LONGX asize)
4734#else /* CIAPI_SOURCE */
4735LONGX recfmt (idx,lw,fmt,area,asize)
4736LONGX idx;
4737LONGX lw;
4738char *fmt;
4739char *area;
4740LONGX asize;
4741#endif /* CIAPI_SOURCE */
4742{
4743#if CIAPI_SOURCE
4744                        FMTSTRU *lc = NULL;
4745#else /* CIAPI_SOURCE */
4746        l_code *lc = NULL;
4747#endif /* CIAPI_SOURCE */
4748        LONGX n;
4749#if TESTFREE
4750        unsigned LONGX m1,m2,x;
4751        UCHR  *pantes,*pdepois;
4752
4753        pantes= (UCHR *)ALLOC((ALLOPARM) sizeof(UCHR));
4754        cprintf("pantesALL(%Fp)\n",pantes);getch();
4755
4756        m1 = CORELEFT();
4757#if CIAPI_SOURCE
4758        n=recfmtcmp(recp, lw, fmt, area, asize, &lc, 1);
4759#else /* CIAPI_SOURCE */
4760        n=recfmtcmp(idx, lw, fmt, area, asize, &lc, 1);
4761#endif /* CIAPI_SOURCE */
4762
4763        m2 = CORELEFT();
4764        x = m1-m2;
4765        pdepois= (UCHR *)ALLOC((ALLOPARM) sizeof(UCHR));
4766        cprintf("pdepois ALL(%Fp)\n Diferenca=%lu",pdepois,
4767         (unsigned)pdepois-(unsigned)pantes);getch();
4768        FREE(pantes);
4769        FREE(pdepois);
4770        if (m1 != m2) {
4771                clrscr();
4772        cprintf("\n\r*** coreleft=%lu-%lu=%lu\n\rfmt:\n\r%s", m1, m2, x ,fmt);
4773        }
4774#else
4775#if CIAPI_SOURCE
4776        n=recfmtcmp(recp, lw, fmt, area, asize, &lc, 1);
4777#else /* CIAPI_SOURCE */
4778        n=recfmtcmp(idx, lw, fmt, area, asize, &lc, 1);
4779#endif /* CIAPI_SOURCE */
4780#endif
4781        return (n);
4782}
4783#endif /* CICPP || CIAPI_SOURCE */
4784
4785#if CICPP
4786FMTSTRU :: FMTSTRU (CISISX *cpx)
4787{
4788 cisisxp = cpx;
4789
4790//---------------------- CIFM1.C ----------------------------------
4791 fmt_pgmp = NULL;
4792 separa_nome_base=0;
4793 string_length=MAX_LITER;
4794 classe_numero_procurado=0;
4795 nopn_fmtfiles= -1;
4796 ch = space_char;
4797 sub_field_value = 0;
4798 source_index=0;
4799 last_source_index=0;
4800 fmt_error=0;
4801#if ERRORET
4802 fmt_errof=0;
4803#endif
4804 p_nulo=nulo;
4805 top_repeat=0;
4806 last_format=is_not_rep;
4807 pf_look_ahead= -1;
4808 pi_look_ahead=0;
4809 buff_look_ahead=NULL;
4810 LOOKING_AHEAD=0;
4811 first_time=1;
4812
4813//---------------------- CIFM3.C ----------------------------------
4814 memset(fmterrxy, 0x00, sizeof(fmterrxy));
4815#if DINALLOC
4816 fmt_fsiz = MAXMFRL;
4817#else /* DINALLOC */
4818 max_tmp_str=MAX_TMP_STR;
4819 max_fd_value=MAX_FD_VALUE;
4820 max_fd_tmp=MAX_FD_TMP;
4821#endif /* DINALLOC */
4822 modify_fmt_pointers=true;
4823 no_modify_fmt_pointers=false;
4824
4825 /*
4826 tb_espec[0]={"\\r",'\r'};
4827 tb_espec[1]={"\\t",'\t'};
4828 tb_espec[2]={"\\b",'\b'};
4829 tb_espec[3]={"\\n",'\n'};
4830 tb_espec[4]={"\\0",'\0'}; */
4831
4832 strcpy(tb_espec[0].s_esp, "\\r");
4833 tb_espec[0].c_esp = '\r';  /* 'R' */
4834 strcpy(tb_espec[1].s_esp, "\\t");
4835 tb_espec[1].c_esp = '\t';  /* 'T' */
4836 strcpy(tb_espec[2].s_esp, "\\b");
4837 tb_espec[2].c_esp = '\b';  /* 'B' */
4838 strcpy(tb_espec[3].s_esp, "\\n");
4839 tb_espec[3].c_esp = '\n';  /* 'N' */
4840 strcpy(tb_espec[4].s_esp, "\\0");
4841 tb_espec[4].c_esp = '\0';  /* '0' */
4842}
4843
4844#if 0
4845FMTSTRU :: FMTSTRU(void): fmt_pgmp(NULL),
4846#if NACLASSE
4847                          fmt_error(0), fmt_errof(0) ,
4848#endif
4849                          fmt_fsiz(MAXMFRL) {};
4850#endif // 0
4851
4852FMTSTRU :: ~FMTSTRU(void)
4853{
4854 xfmt_free();
4855}
4856
4857#endif /* CICPP */
Note: See TracBrowser for help on using the browser.