-
Notifications
You must be signed in to change notification settings - Fork 3
/
cifm3.c
4963 lines (4561 loc) · 132 KB
/
cifm3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* file CIFM3.C */
#define RETIRAR 1 /* Usado para colocar em rotina alocacao de var char */
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#if TESTFREE
#include <conio.h>
#endif
#include "cisis.h"
#include "cifmt.h"
#ifndef FUNPROCX
#define FUNPROCX 0
#endif
#if CICPP
#include "cicgi.hpp"
#include "cifmt.hpp"
#endif /* CICPP */
#define DEBUG_REF 0
#define MICRO_ISIS_COMPATIBLE 0
#if !CICPP /* otherwise DINALLOC is #defined in cifmt.hpp */
#define DINALLOC 1 /* p/ alocar areas originalmente estaticas - AOT 29/12/90 */
#endif /* CICPP */
#define TRACE_REPLACE 0
#define TRACE_STRFUN 0
#define TRACE_REPF 0
#define TRACE_INTER_X 0 /* printf instruction in execution */
#define TRACE_INTER_L 0 /* printf debug in lookup() */
#define TRACE_INTER_2 0 /* printf Apos fmt_load_all_occ */
#define DEB_FLOAT 0
#define TRACE_COMP_M 00 /* printf msg in trata_md() */
#if FATRAP
#define IFERR_GOTO
#define IFERR_RET
#else
#define IFERR_GOTO if (fmterror) goto ERROR_LABEL
#define IFERR_RET if (fmterror) return
#endif /* FATRAP */
/* Modificacoes:
A05 - 19/07/96
Problema:
A funcao REF nao esta liberando corretamente as prateleiras onde sao
lidos os registros do MasterFile, quando um Ref e' utilizado dentro
de outro Ref.
Exemplo: REF(val(ref(1,'3'),...)
Se aplicarmos esse REF para varios registros, dara erro FATAL de
alocacao.
Identificacao:
Sempre que um novo REF e encontrado em um formato, e gurdado no
vetor "vprats" apontado por "currprat" o numero da prateleira
disponivel de 255 ..0.
Quando termina o REF, a prateleira vprats[currprat] devera ser
liberada.
O problema acontecia porque "currprat" estava apontando para a proxima
entrada disponivel de "vprats" e nao para a ultima usada. No momento
de liberar os apontadores estavam defasados. A rotina de leitura do
master era feita numa prateleira(rec_prateleira) que nao estava
alocada forcando a alocacao. Esse registro nao era liberado.
Correcao:
Corridos os apontadores. Para compatibilizacao, a prateleira de
entrada do formato e' guardada na primeira posicao de vprats para
sinalizar o registro em uso.
Foram inseridos alguns traces para achar o erro.
*/
/*--------------------------------------------------------------------------*/
/* E e S variaveis */
/*--------------------------------------------------------------------------*/
#if !CICPP
static float_x E_var[NMAXVAR];
static char *S_var[NMAXVAR];
#endif /* CICPP */
/*--------------------------------------------------------------------------*/
/* NewLine */
/*--------------------------------------------------------------------------*/
/* A07*/
#if !CICPP
char *nl_STR; /* Armazena o string para tratar caracteres de newline */
int nl_LEN;
int nl_ALLOC;
#endif /* CICPP */
/*-----------------------------------------------------------------------*/
#define ispunctuation(x) \
((x==';'||x=='.' || x==':' || x== ',' || x=='!'|| x=='?' )?true:false )
/*-----------------------------------------------------------------------*/
#define NO_INTERVAL(x) (x ? ((x->lower==NO_MIN_OCC) && (x->upper==NO_MAX_OCC)) : false)
/*-----------------------------------------------------------------------*/
/* error - AOT 29/12/90 */
/* #define MAXERRL 60 */
#if !CICPP
#if FATRAP
jmp_buf fmtjumper;
#endif /* FATRAP */
char fmterrxy[MAXERRL+1] = { "" } ;
int fmterror;
/*A06*/
ALLOPARM literal_len;
char *literal;
/*A06*/
#if ANSI
/*float_x convert_to_float(stack_node *top); */
int fmt_type_pattern(char *patt,char *fmt);
int fmt_type_number(int tipo,char *fmt);
void fmt_init_E_S(void);
void free_S(int from,int to);
char *fmt_copy_realloc(char *dest,ALLOPARM *dest_mxlen,char *cte_str);
char *fmt_alloc_char(ALLOPARM tam,char *msg);
int fmt_instr(char *str_source,char *str_sub);
char *fmt_type(char *p);
void trace_field(field_definition_node *i,char *p); /* AOT 27/12/91 */
LONGX number_of_lines(char *p);
static void sub_field_string(char *q, char sub);
/* char *long_to_char(LONGX valor, int n); substituida*/
char *trata_md( instruction_code mode , char *s,int *final_added,char **p);
void upcase_mode(char *s);
void out_put_str(char out[],LONGX maxsize,int *pout,LONGX lw,
int id1,int id2,LONGX *ncc,char s[]);
#if UTF8
size_t strlen_UTF8(const char * str);
char* skipchar_UTF8(const char * str, int qtt);
#else
#endif /*UTF8 */
#else
float_x convert_to_float();
int fmt_type_pattern();
int fmt_type_number();
void fmt_init_E_S();
void free_S();
char *fmt_copy_realloc();
char *fmt_alloc_char();
int fmt_instr();
char *fmt_type();
void trace_field(); /* AOT 27/12/91 */
LONGX number_of_lines();
static void sub_field_string();
/* char *long_to_char(); substituida */
char *trata_md();
void upcase_mode();
void out_put_str();
#if UTF8
size_t strlen_UTF8();
char* skipchar_UTF8();
#else
#endif /* UTF8 */
#endif
#endif /* CICPP */
/*--------------------------------------------------------------------------*/
/* global types */
/*--------------------------------------------------------------------------*/
#if !CICPP
typedef union stack_operands {
int i;
float_x r;
int boolean;
char *s;
char *address;
LONGX l;
#if CICPP /*ifcmm*/
RECSTRU *lrecp;
#endif /*CICPP*/ /*endcmm*/
} ustackopnd;
typedef struct stack_nodex{
enum classe_operandos classe;
union stack_operands op;
}stack_node;
/* prototypes */
#if ANSI
int exec_percent(char *out,int *outs,LONGX *ncc);
void retrieve_two_numeric_operands (void);
stack_node *pop(void);
void inter_error (char *err);
void restore_context(void);
void push ( stack_node *e);
int cast_to_int (stack_node *e);
char *field_value(char *p,LONGX n,int dd);
void retrieve_determine_class(void);
void take_numeric_operands_value(class_operand new_class);
char *sub_string(char source[],int offset,int length);
void save_context(int modify_pointers);
char *store_tmp_string (char *str);
int is_numeric(class_operand x);
void retrieve_two_operands (void);
#else
int exec_percent();
void retrieve_two_numeric_operands ();
stack_node *pop();
void inter_error();
void restore_context();
void push ();
int cast_to_int ();
char *field_value();
void retrieve_determine_class();
void take_numeric_operands_value();
char *sub_string();
void save_context();
char *store_tmp_string ();
int is_numeric();
void retrieve_two_operands ();
#endif
#endif /* CICPP */
/*--------------------------------------------------------------------------*/
/* global_variables */
/*--------------------------------------------------------------------------*/
#if !CICPP
#define max_stack MAXSTACK
<<<<<<< HEAD
#define MAX_TMP_STR (MAXMFRL/2)
#define MAX_SFIELD (MAXMFRL/2)
#define MAX_FD_VALUE (MAXMFRL/2)
#define MAX_FD_TMP (MAXMFRL/2)
=======
#define MAX_TMP_STR (MAXMFRL) /* /2) */
#define MAX_SFIELD (MAXMFRL) /* /2) */
#define MAX_FD_VALUE (MAXMFRL) /* /2) */
#define MAX_FD_TMP (MAXMFRL) /* /2) */
>>>>>>> e661efdc39fdc305c9886453dd9952b3b4c2e48d
LONGX erro_fatal;
stack_node stack[max_stack];
int stack_pt;
stack_node op1_node,op2_node,top_node;
stack_node *top,elem,*op1,*op2,*auxpop;
#if DINALLOC
//LONGX fmt_fsiz=MAXMFRL; /* fmt_inter() - to set max field length - deslocado para cidbx.c */
static LONGX din_fsiz; /* fmt_inter() - current max field length */
static char *tmp_str;
static LONGX max_tmp_str;
static LONGX max_fd_value;
static LONGX max_fd_tmp;
#else
static char tmp_str[MAX_TMP_STR+1];
static LONGX max_tmp_str=MAX_TMP_STR;
static LONGX max_fd_value=MAX_FD_VALUE;
static LONGX max_fd_tmp=MAX_FD_TMP;
#endif
int tmp_str_index;
class_operand new_class,class_of_the_both;
int result;
int cond_code;
instruction_code instruction;
int tempint;
int int_value_1,int_value_2;
float_x tempfloat,float_value_1,float_value_2 ;
LONGX templong ,long_value_1,long_value_2;
int there_is_fd_value;
int there_is_suf;
int rep_group;
int next_rep_occ;
int modify_fmt_pointers=true;
int no_modify_fmt_pointers=false;
#define infoi(i) i->info.instr
#define ilab(i) i->info.lab
#define iadd(i) i->m_add
#define next_infoi(i) i->next
#define fld_def_ptr(i) i->m_add
#define str_const_ptr(i) i->m_add
/* mudar de local para global */
char *out;
LONGX lw_inter;
int pout;
char *address_out,*tmp_ptr;
LONGX nextcc;
/* incio para achar bug de ref */
#if DEBUG_REF
int iii;
LONGX iix;
#endif
/* fim para achar bug de ref */
/* getc_char */
#define get_char /* getchar() */
/* 04-02-95 Existia um problema quando havia sufixo e este era
colocado no fim de linha e logo apos um crlf.
Mesmo o n sendo zero, isto e, nao tendo sido colocado
um final do isis padrao pois havia sufixo, por causa
do crlf eram retirados 2 caracteres. O crlf so pode
ser levado em conta se tiverem sido acrescentados
caracteres no final (n>0)
*/
#endif /* CICPP */
#define delete_chars(out,pout,next,n,lw) \
if(n>0) \
{ \
if(fmt_CRLF(out,pout)) n=n+nl_LEN; /* mudar junto com crlf */ \
pout=pout-n; \
out[pout]=null_char; \
next=next-n; \
if(next<1) next=lw-n+1; \
} \
/*--------------------------------------------------------------------------*/
/* retrieve_two_logical_operands */
/*--------------------------------------------------------------------------*/
#define retrieve_two_logical_operands \
auxpop = pop(); \
if (!fmterror) \
{ \
op2=(stack_node *)memmove(&op2_node,auxpop,sizeof(stack_node)); \
auxpop = pop(); \
if (!fmterror) \
{ \
op1=(stack_node *)memmove(&op1_node,auxpop,sizeof(stack_node)); \
if (op1->classe!=op2->classe || op1->classe != logical) \
inter_error(" Program error two logical operands expected"); \
else \
elem.classe=logical; \
} \
}
/*----------------------------------------------------- AOT 27/12/91 -------*/
/*--------------------------------------------------------------------------*/
/* sc */
/* Conversao de strings do tipo "\n" em caracter especial "lf" */
/*--------------------------------------------------------------------------*/
#if !CICPP
struct tbc {
char s_esp[3];
int c_esp;
/* } tb_espec[]={"\\r",'R',"\\t",'T',"\\b",'B',"\\n",'N',"\\0",'0'};*/
#if BEFORE20000518
} tb_espec[]={"\\r",'\r',"\\t",'\t',"\\b",'\b',"\\n",'\n',"\\0",'\0'};
#else
#if BEFORE20000914
} tb_espec[]={{"\\r",'\r'},{"\\t",'\t'},{"\\b",'\b'},{"\\n",'\n'},{"\\0",'\0'}};
#else
} tb_espec[]={{"\\\r",'\r'},{"\\\t",'\t'},{"\\\b",'\b'},{"\\\n",'\n'},{"\\\0",'\0'}};
#endif
#endif
#endif /* CICPP */
#if CICPP
void FMTSTRU :: sc(char *pp)
#else /* CICPP */
#if ANSI
void sc(char *pp)
#else /* ANSI */
void sc(pp)
char *pp;
#endif /* ANSI */
#endif /* CICPP */
{
char *tmp,*p,*r;
int k;
ALLOPARM cte_siz;
cte_siz=(ALLOPARM) strlen((char *)pp);
tmp=fmt_alloc_char( (ALLOPARM)(cte_siz+1),"cifm2/sc/alloc");
/* if (tmp == NULL) IFERR_GOTO; Label ERROR_LABEL is defined at fmt_inter */
if (tmp == NULL) fatal("cifm2/sc/alloc/2");
strcpy(tmp,pp);
p=pp;
r=tmp;
for (; *tmp ;p++,tmp++) {
if (*tmp!='\\') {
*p=*tmp;
}else{
for (k=0; tb_espec[k].c_esp;k++){
#if BEFORE20000914
if (strncmp(tb_espec[k].s_esp,(char *)tmp,2)==0) {
#else
if (strncmp(tb_espec[k].s_esp,(char *)tmp,strlen(tb_espec[k].s_esp))==0) {
#endif
*p=(char)tb_espec[k].c_esp;
tmp++;
#if 01
#ifndef CICPP
printf("\n++ achou|%s|", tb_espec[k].s_esp);
#endif /* CICPP */
#endif
break;
}
}
}
}
*p=null_char;
#if 0
printf ("\nDentro sc=|%s|",q);
printf ("\nDentro tmp=|%s|",tmp);
#endif
#if CICPP
delete [] r;
#else
FREE(r);
#endif
}
/*--------------------------------------------------------------------------*/
/* trace_field */
/*--------------------------------------------------------------------------*/
#if CICPP
void FMTSTRU :: trace_field(field_definition_node *i,
char *p)
#else /* CICPP */
#if ANSI
void trace_field(field_definition_node *i,
char *p)
#else /*ANSI*/
void trace_field(i,p)
field_definition_node *i;
char *p;
#endif /*ANSI*/
#endif /* CICPP */
{
int n=0;
printf(
"#%d[tag=%d,subf=%c,id1=%d,id2=%d,off=%d,len=%d,max=%d,last=%d\n=%s,\n",
n,
i->tag,
i->sub_field,
i->indent1,
i->indent2,
i->offset,
i->length,
i->max_occ,
i->last_occ,p);
printf(
"act=%d,first=%d\n",
i->actual_occ,
i->first_occ);
}
/*--------------------------------------------------------------------------*/
/* fmt_type_number */
/*--------------------------------------------------------------------------*/
/* type(tipo,formato)
tipo =1 alphanumeric
tipo =2 alphabetic
tipo =3 numeric
tipo =4 inteiro decimal. Opcional sinal
tipo =5 numero decimal incluindo scientific
*/
#if CICPP
int FMTSTRU :: fmt_type_number(int tipo,
char *fmt)
#else /* CICPP */
#if ANSI
int fmt_type_number(int tipo,char *fmt)
#else
int fmt_type_number(tipo,fmt)
int tipo;
char *fmt;
#endif /*ANSI*/
#endif /* CICPP */
{ char *p,*pt_num;
int res,a,n,len,scien;
res= 0;
p=fmt;
#if UTF8
len=strlen_utf8(p);
#else
len=strlen(p);
#endif // UTF8
if (len==0) return(1); /* Vazio retorna sempre 1 */
switch (tipo) {
case 1 :
case 2 :
case 3 :
a=0;n=0;
while (*p) {
#if UTF8
if ( alphabetic_utf8(p) ) a++;
#else
if (isiswctab[*p]) a++;
#endif // UTF8
if (isdigit(*p)) n++;
#if UTF8
p = skipchar_utf8(p,1);
#else
p++;
#endif // UTF8
}
if (tipo == 1 && a+n == len) res=1 ;
else if (tipo == 2 && a == len) res=1;
else if (tipo == 3 && n == len) res=1;
break;
case 4 :
case 5 :
a=0;
scien=0;
n=0; /* supor numero inteiro */
pt_num=find_numeric_string(p,&a);
if ( (strchr(pt_num,'e') != nulo) ||
(strchr(pt_num,'E') !=nulo ) ) scien=1;
if (strchr(pt_num,'.') !=nulo) n=1;
p=fmt;
a=1;
while (a) { /* Micro isis aceita espacos `a esqueda */
if (*p != space_char || *p == null_char )a=0;
else p++ ;
}
if ((size_t)strlen(pt_num)==(size_t)strlen(p)){
if (tipo==4 && scien == 0 && n==0 ) res=1;
else if (tipo == 5) res=1;
}
break;
}
return(res);
}
/*--------------------------------------------------------------------------*/
/* fmt_type_pattern */
/*--------------------------------------------------------------------------*/
/* Compara um string com um padrao do tipo
patt=xx-xx-99-xx-aa
str =ca-dd-11-1a-bb
Se tamanhos s~ao difentes, entao resultado falso
Senao compara caracter a caracter
*/
#if CICPP
int FMTSTRU :: fmt_type_pattern(char *patt,
char *fmt)
#else /* CICPP */
#if ANSI
int fmt_type_pattern(char *patt,char *fmt)
#else
int fmt_type_pattern(patt,fmt)
char *patt;
char *fmt;
#endif /*ANSI*/
#endif /* CICPP */
{ char *p,*q;
int res,l;
p=patt; q=fmt; res=1;
l=strlen(patt);
if (l != strlen(fmt)) return(0);
while(res && *p ) {
switch ( toupper(*p)) {
case 'A' :
#if UTF8
res = alphabetic_utf8(q) ? 1 : 0;
#else
res = isiswctab[*q];
#endif // UTF8
break;
case 'X' :
res = 1;
break;
case '9' :
if ( !isdigit(*q)) res=0;
break;
default :
res = (*q == *p);
}
p++;
#if UTF8
q = skipchar_utf8(q,1);
#else
q++;
#endif // UTF8
}
return (res);
}
/*----------------------------------------------------- AOT 27/12/91 -------*/
/*--------------------------------------------------------------------------*/
/* fmt_type */
/*--------------------------------------------------------------------------*/
/* Usa rotina que separa dentro de um string o proximo numero
Se o tamanho do numero separado e igual ao tamanho do string e'porque
o string e numerico.
Caso contrario verifica se contem apenas letras para ser
alfabetico.
Caso contrario e alfanumerico
*/
#if CICPP
char * FMTSTRU :: fmt_type(char *p)
#else /* CICPP */
#if ANSI
char *fmt_type(char *p)
#else /*ANSI*/
char *fmt_type(p)
char *p;
#endif /*ANSI*/
#endif /* CICPP */
{
static char tmp_ty[2];
int i;
char *q,*pt_num;
q=p;
tmp_ty[1]=null_char;
tmp_ty[0]=TY_X;
i=0;
pt_num=find_numeric_string(p,&i);
if ((size_t)strlen(pt_num)==(size_t)strlen(p)){
tmp_ty[0]=TY_N;
}else{
#if UTF8
while (alphabetic_utf8(q) || *q == ' ') q = skipchar_utf8(q,1);
#else
while (isiswctab[*q] || *q==' ') q++;
#endif // UTF8
if (*q==null_char)tmp_ty[0]=TY_A;
}
/*03-11-99 Alterar para retornar '' quando string vazio */
if ( (size_t)strlen(p) == (size_t)0 ) tmp_ty[0]=null_char;
return (char *)tmp_ty;
}
/*--------------------------------------------------------------------------*/
/* fmt_init_E_S */
/*--------------------------------------------------------------------------*/
#if CICPP
void FMTSTRU :: fmt_init_E_S(void)
#else /* CICPP */
#if ANSI
void fmt_init_E_S()
#else /*ANSI*/
void fmt_init_E_S()
#endif
#endif /* CICPP */
{ int i;
for (i=0;i<NMAXVAR;i++) {
E_var[i]= (float_x) 0;
S_var[i]= NULL;
}
}
/*--------------------------------------------------------------------------*/
/* fmt_free_S */
/*--------------------------------------------------------------------------*/
#if CICPP
void FMTSTRU :: fmt_free_S(int from,
int to)
#else /* CICPP */
#if ANSI
void fmt_free_S(int from, int to)
#else /*ANSI*/
void fmt_free_S(from ,to)
int from, to;
#endif
#endif /* CICPP */
{ int i;
for (i=from;i<=to;i++) {
if (S_var[i] != NULL)
#if 0
printf("Lib=[%p]\n", S_var[i]);
#endif
#if CICPP
delete [] (char *)S_var[i];
#else /* CICPP */
FREE(S_var[i]);
#endif /* CICPP */
S_var[i]=NULL;
}
}
/*--------------------------------------------------------------------------*/
/* fmt_copy_realloc */
/*--------------------------------------------------------------------------*/
#if CICPP
char * FMTSTRU :: fmt_copy_realloc(char *pdest,
ALLOPARM *dest_mxlen,
char *cte_str)
#else /* CICPP */
#if ANSI
char *fmt_copy_realloc(char *pdest,ALLOPARM *dest_mxlen,char *cte_str)
#else /*ANSI*/
char *fmt_copy_realloc(pdest,dest_mxlen,cte_str)
/*Armazena cte_str em pdest */
char *pdest; /*Se necessario realloca pdest para*/
ALLOPARM *dest_mxlen; /*que str_cte caiba e muda tamanho */
char *cte_str; /* max do pdest.Retorna novo endereco*/
#endif /*ANSI*/
#endif /* CICPP */
{
char *p;
ALLOPARM cte_siz;
cte_siz=(ALLOPARM) strlen((char *)cte_str);
if (*dest_mxlen<cte_siz){ /* realloca string */
p=fmt_alloc_char( (ALLOPARM)(cte_siz+1),"cifm3/fmt_realloc");
/* if (p == NULL) IFERR_GOTO; Label ERROR_LABEL is defined at fmt_inter */
if (p == NULL) fatal("cifm3/fmt_realloc/2");
strcpy(p,cte_str);
#if CICPP
delete [] pdest;
#else
FREE(pdest);
#endif
*dest_mxlen=cte_siz;
return p;
}else { /* copia apenas cte_str */
strcpy(pdest,cte_str);
return pdest; /*para efeito de compatibilizar */
}
}
/*--------------------------------------------------------------------------*/
/* fmt_alloc_char */
/*--------------------------------------------------------------------------*/
#if CICPP
char * FMTSTRU :: fmt_alloc_char(ALLOPARM tam,
char *msg)
#else /* CICPP */
#if ANSI
char *fmt_alloc_char(ALLOPARM tam,char *msg)
#else /*ANSI*/
char *fmt_alloc_char(tam,msg)
ALLOPARM tam;
char *msg;
#endif /*ANSI*/
#endif /* CICPP */
{
char *t;
#if CICPP
try
{ t=(char *)new char [(tam)]; }
catch (BAD_ALLOC)
{ t=(char *)ALLONULL; }
#else /* CICPP */
t=(char *)ALLOC((ALLOPARM)(tam));
#endif /* CICPP */
if (t == (char *)ALLONULL) {inter_error(msg); return NULL; }
return t;
}
/*--------------------------------------------------------------------------*/
/* fmt_instr */
/*--------------------------------------------------------------------------*/
#if CICPP
int FMTSTRU :: fmt_instr(char *str_source,
char *str_sub)
#else /* CICPP */
#if ANSI
int fmt_instr(char *str_source,char *str_sub)
#else /*ANSI*/
int fmt_instr(str_source,str_sub)
char *str_source,*str_sub;
#endif /*ANSI*/
#endif /* CICPP */
{
char *p,*res;
int pos;
pos=0;
res=NULL;
p=str_source;
res = strstr(p,str_sub);
if (res!=NULL && p!=NULL && str_sub!=NULL ) {
if (*res && *str_sub) {
int ll;
ll=strlen(str_sub);
pos=1;
while (memcmp(p,str_sub,ll)!=0) {
#if UTF8
p = skipchar_UTF8(p, 1); pos++;
#else
p++; pos++;
#endif /* UTF8 */
}
}
}
return pos;
}
/*--------------------------------------------------------------------------*/
/* retrieve_two_numeric_operands */
/*--------------------------------------------------------------------------*/
#if CICPP
void FMTSTRU :: take_numeric_operands_value(class_operand new_class)
#else /* CICPP */
#if ANSI
void take_numeric_operands_value(class_operand new_class)
#else /*ANSI*/
void take_numeric_operands_value(new_class)
class_operand new_class;
#endif /*ANSI*/
#endif /* CICPP */
{
int_value_1=0;
int_value_2=0;
long_value_1=0L;
long_value_2=0L;
float_value_1=0.0;
float_value_2=0.0;
switch(new_class)
{ case integer :
int_value_1=op1->op.i;
int_value_2=op2->op.i;
break;
case long_n :
if(op1->classe==integer) long_value_1=(LONGX) op1->op.i;
if(op1->classe==long_n) long_value_1=op1->op.l;
if(op2->classe==integer) long_value_2=(LONGX) op2->op.i;
if(op2->classe==long_n) long_value_2=op2->op.l;
break;
case float_n :
if(op1->classe==integer) float_value_1=(float) op1->op.i;
if(op1->classe==long_n) float_value_1=(float) op1->op.l;
if(op1->classe==float_n) float_value_1=op1->op.r;
if(op2->classe==integer) float_value_2=(float) op2->op.i;
if(op2->classe==long_n) float_value_2=(float) op2->op.l;
if(op2->classe==float_n) float_value_2=op2->op.r;
break;
}
}
#if CICPP
void FMTSTRU :: retrieve_determine_class(void)
#else /* CICPP */
void retrieve_determine_class()
#endif /* CICPP */
{
auxpop = pop(); IFERR_RET;
op2=(stack_node *)memmove(&op2_node,auxpop,sizeof(stack_node));
auxpop = pop(); IFERR_RET;
op1=(stack_node *)memmove(&op1_node,auxpop,sizeof(stack_node));
if (op1->classe==string && op2->classe==string){new_class=string;}
else
{ if ( (op1->classe==integer||op1->classe==float_n ||
op1->classe==long_n
) &&
(op2->classe==integer || op2->classe==float_n || op2->classe==long_n) )
{if (op1->classe == op2->classe)
{ new_class=op1->classe ; }
else {if (( op1->classe == integer || op1->classe == long_n ) &&
(op2->classe == integer || op2->classe == long_n)
) new_class=long_n ;
else new_class=float_n;
}
}
else
{
inter_error("Invalid class of operands for aritmetic/string operators");
return;
}
}
}
/*-----------------------------------------------------------------------*/
#if CICPP
void FMTSTRU :: retrieve_two_numeric_operands (void)
#else /* CICPP */
void retrieve_two_numeric_operands ()
#endif /* CICPP */
{
retrieve_determine_class();
IFERR_RET;
if(new_class==string)
{
inter_error("Invalid class of operands for aritmetic operators");
return;
}
else take_numeric_operands_value(new_class);
} /* precedure */
/*--------------------------------------------------------------------------*/
/* retrieve_two_operands */
/*--------------------------------------------------------------------------*/
#if CICPP
void FMTSTRU :: retrieve_two_operands(void)
#else /* CICPP */
void retrieve_two_operands()
#endif /* CICPP */
{
retrieve_determine_class();
IFERR_RET;
class_of_the_both=new_class;
if (new_class!=string) take_numeric_operands_value(new_class);
}
/*-------------------------------------------------------------------------*/
/* is_not_of_class */
/*-------------------------------------------------------------------------*/
#define is_not_of_class(x,cl) \
if(x!=cl) inter_error("Invalid operand class "); \
/*--------------------------------------------------------------------------*/
/* is_numeric */
/*--------------------------------------------------------------------------*/
#if CICPP
int FMTSTRU :: is_numeric(class_operand x)
#else /* CICPP */
#if ANSI
int is_numeric(class_operand x)
#else /*ANSI*/
int is_numeric(x)
class_operand x;
#endif /*ANSI*/
#endif /* CICPP */
{
if ( !( x==integer || x==float_n || x==long_n) )
{ inter_error("Aritmetic operand expected "); }
return(1);
}
/*--------------------------------------------------------------------------*/
/* convert_to_float */
/*--------------------------------------------------------------------------*/
#if CICPP
float_x FMTSTRU :: convert_to_float(stack_node *top)
#else /* CICPP */
#if ANSI
float_x convert_to_float(stack_node *top)
#else /*ANSI*/
float_x convert_to_float(top)
stack_node *top;
#endif /*ANSI*/
#endif /* CICPP */
{ float_x x;
is_numeric(top->classe);
if (top->classe == integer) x = (float_x) top->op.i;
if (top->classe == float_n) x = (float_x) top->op.r;
if (top->classe == long_n) x = (float_x) top->op.l;
return (x);
}
/*------------------------------------------------------------------------*/
/* save_context */
/*------------------------------------------------------------------------*/
#if CICPP
void FMTSTRU :: save_context(int modify_pointers)
#else /* CICPP */
#if ANSI
void save_context(int modify_pointers)
#else /*ANSI*/
void save_context(modify_pointers)
int modify_pointers;
#endif /*ANSI*/
#endif /* CICPP */
{
#if DEB_FLOAT
printf("\n++Save_context l_w=%"_LD_" nextcc=%"_LD_" pout=%d \nout=%s|",
lw_inter,nextcc,pout,out);
#endif
elem.classe=next_cc;
elem.op.l=nextcc;
push(&elem);
IFERR_RET;
elem.classe=xindex;
elem.op.i=pout;
push(&elem);
IFERR_RET;
elem.classe=l_w;
elem.op.l=lw_inter;
push(&elem);
IFERR_RET;
elem.classe=ptr;
elem.op.address= &out[0];
push(&elem);
IFERR_RET;