-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGS_RESBF.CPP
More file actions
1876 lines (1607 loc) · 55.7 KB
/
GS_RESBF.CPP
File metadata and controls
1876 lines (1607 loc) · 55.7 KB
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
/**********************************************************
Name: GS_RESBF
Module description: File funzioni di base per la gestione
delle liste (resbuf).
Author: Roberto Poltini
(c) Copyright 1995-2012 by IREN ACQUA GAS S.p.A.
**********************************************************/
/**********************************************************/
/* INCLUDE */
/**********************************************************/
#include "stdafx.h" // MFC core and standard components
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include "adslib.h"
#include "asiappl.h"
#include "..\gs_def.h" // definizioni globali
#include "gs_error.h"
#include "gs_init.h"
#include "gs_utily.h"
#include "gs_resbf.h"
/****************************************************************************/
/* GLOBALS */
/****************************************************************************/
presbuf GS_RESBUF = NULL; // resbuf pubblico
/*************************************************************************/
/*.doc gsc_copybuf (internal)*/
/*+
Copia il contenuto del 'resbuf' puntato parametro in ingresso in un
'resbuf' allocato all'interno della funzione e ne ritorna il puntatore .
(WARNING: Alloca memoria)
-*/
/*************************************************************************/
struct resbuf *gsc_copybuf(struct resbuf *sorc)
{
struct resbuf *dest;
if (!sorc) { GS_ERR_COD = eGSInvalidArg; return NULL; }
switch (sorc->restype)
{
case RTLB :
if ((dest = ads_newrb(RTLB)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
case RTPOINT :
if ((dest = ads_newrb(RTPOINT)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
ads_point_set(sorc->resval.rpoint, dest->resval.rpoint);
break;
case RT3DPOINT :
if ((dest = ads_newrb(RT3DPOINT)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
ads_point_set(sorc->resval.rpoint, dest->resval.rpoint);
break;
case RTREAL :
if ((dest = ads_newrb(RTREAL)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
dest->resval.rreal = sorc->resval.rreal;
break;
case RTSHORT:
if ((dest = ads_newrb(RTSHORT)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
dest->resval.rint = sorc->resval.rint;
break;
case RTANG:
if ((dest = ads_newrb(RTANG)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
dest->resval.rreal = sorc->resval.rreal;
break;
case RTSTR:
if ((dest = acutBuildList(RTSTR,sorc->resval.rstring,0))==NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
case RTENAME :
if ((dest = ads_newrb(RTENAME)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
dest->resval.rlname[0] = sorc->resval.rlname[0];
dest->resval.rlname[1] = sorc->resval.rlname[1];
break;
case RTPICKS :
if ((dest = ads_newrb(RTPICKS)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
dest->resval.rlname[0] = sorc->resval.rlname[0];
dest->resval.rlname[1] = sorc->resval.rlname[1];
break;
case RTORINT :
if ((dest = ads_newrb(RTORINT)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
dest->resval.rreal = sorc->resval.rreal;
break;
case RTLONG :
if ((dest = ads_newrb(RTLONG))==NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
dest->resval.rlong = sorc->resval.rlong;
break;
case RTLE :
if ((dest = ads_newrb(RTLE)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
case RTDOTE :
if ((dest = ads_newrb(RTDOTE)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
case RTNIL :
if ((dest = ads_newrb(RTNIL)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
case RTVOID :
if ((dest = ads_newrb(RTVOID)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
case RTNONE :
if ((dest = ads_newrb(RTNONE)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
case RTDXF0 :
if ((dest = acutBuildList(RTDXF0,sorc->resval.rstring,0))==NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
case RTT :
if ((dest = ads_newrb(RTT)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
break;
}
return dest;
}
/*************************************************************************/
/*.doc gsc_rblistcopy (internal)*/
/*+
Riceve in input il puntatore ad un 'resbuf' di una lista e restituisce il
puntatore ad una lista contenente la copia della prima.
Alloca memoria !!.
-*/
/*************************************************************************/
presbuf gsc_rblistcopy(presbuf lista)
{
presbuf pindex=lista, result=NULL, prbcopia;
while (pindex != NULL)
{
if (result==NULL) // prima volta
{
if ((result = prbcopia = gsc_copybuf(pindex)) == NULL) return NULL;
}
else
{
if ((prbcopia->rbnext = gsc_copybuf(pindex)) == NULL)
{ acutRelRb(result); return NULL; }
prbcopia = prbcopia->rbnext;
}
pindex = pindex->rbnext;
}
return (result);
}
/*************************************************************************/
/*.doc gsc_sostitutebuf (internal)*/
/*+
Sostituisce il contenuto del 'resbuf' puntato dal parametro in ingresso con
quello di un altro resbuf (dest già allocato).
-*/
/*************************************************************************/
int gsc_sostitutebuf(presbuf sorc, presbuf dest)
{
if (sorc == NULL || dest == NULL) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
if (dest->restype == RTSTR || dest->restype == RTDXF0)
{
if (dest->resval.rstring != NULL) free(dest->resval.rstring);
}
else
if (dest->restype == RTPICKS)
if (!ads_name_nil(dest->resval.rlname)) ads_ssfree(dest->resval.rlname);
switch (sorc->restype)
{
case RTLB :
dest->restype = RTLB;
break;
case RTPOINT :
dest->restype = RTPOINT;
ads_point_set(sorc->resval.rpoint, dest->resval.rpoint);
break;
case RT3DPOINT :
dest->restype = RT3DPOINT;
ads_point_set(sorc->resval.rpoint, dest->resval.rpoint);
break;
case RTREAL :
dest->restype = RTREAL;
dest->resval.rreal = sorc->resval.rreal;
break;
case RTSHORT:
dest->restype = RTSHORT;
dest->resval.rint = sorc->resval.rint;
break;
case RTANG:
dest->restype = RTANG;
dest->resval.rreal = sorc->resval.rreal;
break;
case RTSTR:
dest->restype = RTSTR;
if (sorc->resval.rstring != NULL)
{
if ((dest->resval.rstring = gsc_tostring(sorc->resval.rstring)) == NULL)
{ GS_ERR_COD=eGSOutOfMem; return GS_BAD; }
}
else dest->resval.rstring = NULL;
break;
case RTENAME :
dest->restype = RTENAME;
dest->resval.rlname[0] = sorc->resval.rlname[0];
dest->resval.rlname[1] = sorc->resval.rlname[1];
break;
case RTPICKS :
dest->restype = RTPICKS;
dest->resval.rlname[0] = sorc->resval.rlname[0];
dest->resval.rlname[1] = sorc->resval.rlname[1];
break;
case RTORINT :
dest->restype = RTORINT;
dest->resval.rreal = sorc->resval.rreal;
break;
case RTLONG :
dest->restype = RTLONG;
dest->resval.rlong = sorc->resval.rlong;
break;
case RTLE :
dest->restype = RTLE;
break;
case RTDOTE :
dest->restype = RTDOTE;
break;
case RTNIL :
dest->restype = RTNIL;
break;
case RTVOID :
dest->restype = RTVOID;
break;
case RTDXF0 :
dest->restype = RTDXF0;
if (sorc->resval.rstring != NULL)
{
if ((dest->resval.rstring = gsc_tostring(sorc->resval.rstring)) == NULL)
{ GS_ERR_COD=eGSOutOfMem; return GS_BAD; }
}
else dest->resval.rstring = NULL;
break;
case RTT :
dest->restype = RTT;
break;
}
return GS_GOOD;
}
/*************************************************************************/
/*.doc gsc_scorri (internal)*/
/*+
Riceve in input il puntatore ad un 'resbuf' di una lista e restituisce il
puntatore al termine della lista corrispondente, definito normalmente da un
elemento RTLE o RTDOTE (coppie puntate).
La funzione e' ricorsiva.
-*/
/*************************************************************************/
presbuf gsc_scorri(presbuf lista)
{
if (!lista) return NULL;
// Se l'elemento è un punto allora è una lista che inizia e finisce
// nello stesso elemento
switch (lista->restype)
{
case RTPOINT: case RT3DPOINT:
case 10: case 11: case 12: case 13: case 14: case 15:
case 16: case 17: case 18: case 19:
case 1010: case 1011: case 1012: case 1013: case 1014: case 1015:
case 1016: case 1017: case 1018: case 1019:
return lista;
}
while ((lista = lista->rbnext) != NULL)
{
switch (lista->restype)
{
case RTLE: case RTDOTE:
return lista;
case RTLB :
lista = gsc_scorri(lista);
break ;
}
}
return (lista);
}
/*************************************************************************/
/*.doc gsc_listcopy */
/*+
La funzione copia una lista di resbuf partendo da RTLB (a cui ci si
deve trovare) fino al relativo RTLE.
Parametri:
presbuf lista; Lista di resbuf
presbuf *p; opzionale; puntatore alla fine della lista (RTLE)
(default = NULL)
Ritorna il puntatore alla lista copiata in caso di successo altrimenti NULL.
-*/
/*************************************************************************/
presbuf gsc_listcopy(presbuf lista, presbuf *p)
{
C_RB_LIST new_list;
presbuf p_ndx = lista;
int count = 0;
if (!lista || lista->restype != RTLB) { GS_ERR_COD = eGSInvalidArg; return NULL; }
while (p_ndx)
{
if ((new_list += gsc_copybuf(p_ndx)) == NULL) return NULL;
switch (p_ndx->restype)
{
case RTLB :
count++;
break;
case RTLE :
case RTDOTE :
count--;
break;
}
if (count == 0) break;
p_ndx = p_ndx->rbnext;
}
if (count != 0) { GS_ERR_COD = eGSListError; return NULL; }
new_list.ReleaseAllAtDistruction(GS_BAD);
if (p) *p = p_ndx;
return new_list.get_head();
}
/*************************************************************************/
/*.doc gsc_scorcopy (internal)*/
/*+
Scorre il contenuto di una lista analogamente a gsc_scorri()
ricopiandolo in coda ad un'altra.
Il primo parametro e` il puntatore al primo 'resbuf' della lista da copiare.
(NB: il primo elemento non viene copiato, si parte dal successivo).
Il secondo parametro e` il puntatore all'ultimo 'resbuf' della lista a cui
appendere la copia della lista sorgente. La funzione e' ricorsiva.
Ritorna il puntatore all'ultimo 'resbuf' della lista di destinazione.
(WARNING: Alloca memoria)
-*/
/*************************************************************************/
struct resbuf *gsc_scorcopy(struct resbuf *aaa, struct resbuf *bbb)
{
int error = 0;
while ((aaa = aaa->rbnext) != NULL)
{
if (bbb==NULL)
return NULL;
switch(aaa->restype)
{
case RTLE :
case RTDOTE :
bbb=bbb->rbnext=gsc_copybuf(aaa);
return bbb;
case RTLB :
if ( (bbb=bbb->rbnext=gsc_copybuf(aaa))==NULL )
return NULL;
if ( (bbb = gsc_scorcopy(aaa,bbb))==NULL )
return NULL;
aaa = gsc_scorri(aaa);
break;
default :
if ( (bbb=bbb->rbnext=gsc_copybuf(aaa))==NULL)
return NULL;
break;
} /* END SWITCH */
} /* END WHILE */
GS_ERR_COD=eGSListError;
return NULL;
}
/*************************************************************************/
/*.doc gsc_length (external)*/
/*+
Riceve in input il puntatore ad una lista e restituisce il
numero di elementi contenuti nella lista (-1 se non e' una lista).
Siamo in presenza di una lista se il tipo dell'elemento passato
e` RTLB, RTPOINT o RT3DPOINT (in questi due ultimi casi ritorna
sempre rispettivamente 2 e 3).
-*/
/*************************************************************************/
int gsc_length(struct resbuf *lista)
{
int lungh = 0;
if (lista == NULL) return -1;
switch (lista->restype)
{
case RTPOINT :
return 2;
case RT3DPOINT :
return 3;
case RTLB :
while ((lista = lista->rbnext) != NULL &&
lista->restype != RTLE && lista->restype != RTDOTE)
{
if (lista->restype == RTLB) lista = gsc_scorri(lista);
lungh++;
}
return (lungh);
default :
GS_ERR_COD = eGSListError;
return -2;
}
}
/*************************************************************************/
/*.doc gsc_nth (external)*/
/*+
Restituisce il putatore all'ennesimo elemento della lista.
La funzione ha due parametri.
Il primo e` l'indice (n) dell'elemento da cercare. Questo parametro deve
essere >= 0 (NB: 0 indica il primo elemento).
Il secondo parametro e` il puntatore all'inizio della lista in cui
cercare.
I tipi permessi per il primo elemento della lista sono RTLB, RTPOINT e
RT3DPOINT.
La funzione ritorna NULL in caso di errore.
-*/
/*************************************************************************/
struct resbuf *gsc_nth(int indice,struct resbuf *lista)
{
int cont = 0;
if (indice < 0 || indice >= gsc_length(lista)) return NULL;
while ((lista = lista->rbnext) != NULL)
{
if (cont == indice) break;
if (lista->restype == RTLB) lista = gsc_scorri(lista);
cont++;
}
return lista;
}
/*************************************************************************/
/*.doc gsc_nthcopy (external)*/
/*+
Restituisce il puntatore alla copia dell'n-esimo elemento della lista.
La funzione ha due parametri.
Il primo e` l'indice (n) dell'elemento da copiare. Questo parametro deve
essere >= 0 (NB: 0 indica il primo elemento).
Il secondo parametro e` il puntatore all'inizio della lista da cui copiare.
I tipi permessi per il primo elemento della lista sono RTLB, RTPOINT e
RT3DPOINT.
La funzione restituisce NULL in caso di errore.
(WARNING: Alloca memoria)
-*/
/*************************************************************************/
struct resbuf *gsc_nthcopy(int indice,struct resbuf *lista)
{
int cont = 0;
struct resbuf *target;
if ( (indice<0) || (indice>=gsc_length(lista)) )
{ GS_ERR_COD=eGSInvalidArg; return NULL; }
while ( (lista=lista->rbnext)!=NULL)
{
if (cont==indice)
break;
if (lista->restype==RTLB)
lista=gsc_scorri(lista);
cont++;
}
if ((target = gsc_copybuf(lista)) == NULL)
{ GS_ERR_COD=eGSOutOfMem; return NULL; }
if (lista->restype==RTLB)
{
if (gsc_scorcopy(lista,target)==NULL)
return NULL;
}
return target;
}
/*************************************************************************/
/*.doc gsc_car (external)*/
/*+
Restituisce il puntatore alla copia del primo elemento della lista
puntata da puntatore passato come parametro.
I tipo accettati per il primo elemento della lista sono RTLB, RTPOINT e
RT3DPOINT.
In caso di errore nei parametri la funzione ritorna NULL.
(WARNING: Alloca memoria)
-*/
/*************************************************************************/
struct resbuf *gsc_car(struct resbuf *rb)
{
struct resbuf *temp;
if (rb == NULL)
{ GS_ERR_COD=eGSListError; return NULL; }
switch (rb->restype)
{
case RTPOINT :
case RT3DPOINT :
if ( (temp=acutBuildList(RTREAL,rb->resval.rpoint[0],0))==NULL)
{ GS_ERR_COD=eGSOutOfMem; return NULL; }
return(temp);
case RTLB :
if ( (temp=gsc_nthcopy(0,rb))==NULL)
return NULL;
return temp;
default :
GS_ERR_COD=eGSListError;
return NULL;
}
}
/*************************************************************************/
/*.doc gsc_cdr (external)*/
/*+
Restituisce il puntatore alla lista contenente la copia di tutti gli
elementi della lista passata come parametro escluso il primo.
I tipo accettati per il primo elemento della lista passata come parametro
sono RTLB, RTPOINT e RT3DPOINT.
In caso di errore nei parametri la funzione ritorna NULL.
(WARNING: Alloca memoria)
-*/
/*************************************************************************/
struct resbuf *gsc_cdr(struct resbuf *lista)
{
struct resbuf *temp;
switch (lista->restype)
{
case RTPOINT :
if ((temp=acutBuildList(RTLB,
RTREAL,lista->resval.rpoint[1],
RTLE,0)) == NULL)
GS_ERR_COD=eGSOutOfMem;
return(temp);
case RT3DPOINT :
if ((temp=acutBuildList(RTLB,
RTREAL,lista->resval.rpoint[1],
RTREAL,lista->resval.rpoint[2],
RTLE,0)) == NULL)
GS_ERR_COD=eGSOutOfMem;
return(temp);
case RTLB :
/*** Vai alla fine del primo elemto ***/
lista=lista->rbnext;
if (lista->restype==RTLB)
lista=gsc_scorri(lista);
/*** Copia la lista da qui' in poi ***/
if ((temp = ads_newrb(RTLB)) == NULL)
{ GS_ERR_COD=eGSOutOfMem; return NULL; }
if (gsc_scorcopy(lista,temp)==NULL)
return NULL;
return temp;
default :
GS_ERR_COD=eGSListError;
return NULL;
}
}
/*************************************************************************/
/*.doc gsc_equal (external)*/
/*+
Confronta il contenuto di due elementi di un resbuf.
Parametri:
presbuf a; primo resbuf
presbuf b; secondo resbuf
int sensitive; usato solo per stringhe; sensibile al maiuscolo (default = TRUE)
Restituisce TRUE se sono uguali altrimenti FALSE.
-*/
/*************************************************************************/
int gsc_equal(presbuf a, presbuf b, int sensitive)
{
if (a == NULL && b == NULL) return TRUE;
if (a == NULL || b == NULL) return FALSE;
switch (a->restype)
{
case RTNONE: return (b->restype == RTNONE) ? TRUE : FALSE;
case RTLB : return (b->restype == RTLB) ? TRUE : FALSE;
case RTLE : return (b->restype == RTLE) ? TRUE : FALSE;
case RTDOTE: return (b->restype == RTDOTE) ? TRUE : FALSE;
case RTVOID: return (b->restype == RTVOID) ? TRUE : FALSE;
case RTNIL : return (b->restype == RTNIL) ? TRUE : FALSE;
case RTT : return (b->restype == RTT) ? TRUE : FALSE;
case RTPOINT:
if (b->restype == RTPOINT &&
ads_2Dpoint_equal(a->resval.rpoint, b->resval.rpoint))
return TRUE;
else return FALSE;
case RT3DPOINT:
if (b->restype == RT3DPOINT &&
gsc_point_equal(a->resval.rpoint, b->resval.rpoint))
return TRUE;
else return FALSE;
case RTREAL :
case RTANG :
case RTORINT:
switch (b->restype)
{
case RTREAL :
case RTANG :
case RTORINT:
return (a->resval.rreal == b->resval.rreal) ? TRUE : FALSE;
case RTSHORT:
return (a->resval.rreal == b->resval.rint) ? TRUE : FALSE;
case RTLONG:
return (a->resval.rreal == b->resval.rlong) ? TRUE : FALSE;
default: return FALSE;
}
case RTSHORT:
switch (b->restype)
{
case RTREAL :
case RTANG :
case RTORINT:
return (a->resval.rint == b->resval.rreal) ? TRUE : FALSE;
case RTSHORT:
return (a->resval.rint == b->resval.rint) ? TRUE : FALSE;
case RTLONG:
return (a->resval.rint == b->resval.rlong) ? TRUE : FALSE;
default: return FALSE;
}
case RTLONG:
switch (b->restype)
{
case RTREAL :
case RTANG :
case RTORINT:
return (a->resval.rlong == b->resval.rreal) ? TRUE : FALSE;
case RTSHORT:
return (a->resval.rlong == b->resval.rint) ? TRUE : FALSE;
case RTLONG:
return (a->resval.rlong == b->resval.rlong) ? TRUE : FALSE;
default: return FALSE;
}
case RTSTR :
case RTDXF0:
if ((b->restype == RTSTR || b->restype == RTDXF0) &&
gsc_strcmp(a->resval.rstring, b->resval.rstring, sensitive) == 0)
return TRUE;
else return FALSE;
case RTENAME:
case RTPICKS:
if ((b->restype == RTENAME || b->restype == RTPICKS) &&
(a->resval.rlname[0] == b->resval.rlname[0]) &&
(a->resval.rlname[1] == b->resval.rlname[1]))
return TRUE;
else return FALSE;
default : return FALSE;
}
}
/*************************************************************************/
/*.doc gsc_assoccopy (external)*/
/*+
Riceve due parametri una lista di ricerca (lista) ed un puntatore ad
una chiave da ricercare (indice).
La lista deve a sua volta contenere delle sottoliste.
La funzione restituisce la copia della sottolista (di lista) il cui primo
elemento sia uguale a (indice).
La funzione ritorna il puntatore alla copia della sottolista o NULL nel caso
di errore nei parametri o nel caso non trovi la chiave di ricerca.
(WARNING: Alloca memoria)
-*/
/*************************************************************************/
struct resbuf *gsc_assoccopy(struct resbuf *indice, struct resbuf *lista)
{
int i;
struct resbuf *buf,*first;
if ((lista == NULL) || (indice == NULL))
return (NULL);
for (i=0;i<gsc_length(lista);i++)
{
if ( (buf=gsc_nthcopy(i,lista))==NULL) return NULL;
if ( buf->restype==RTPOINT || buf->restype==RT3DPOINT ||
buf->restype==RTLB )
{
if ( (first=gsc_car(buf))==NULL)
{ acutRelRb(buf); return NULL; }
if (gsc_equal(first,indice))
{
acutRelRb(first);
return buf;
}
acutRelRb(first);
}
acutRelRb(buf);
}
return NULL;
}
struct resbuf *gsc_assoccopy(char *stringa, struct resbuf *lista)
{
TCHAR *UnicodeString = gsc_CharToUnicode(stringa);
struct resbuf *res = gsc_assoccopy(UnicodeString, lista);
if (UnicodeString) free(UnicodeString);
return res;
}
struct resbuf *gsc_assoccopy(TCHAR *stringa, struct resbuf *lista)
{
presbuf p_key, p_ret;
if ((p_key = acutBuildList(RTSTR, stringa, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
p_ret = gsc_assoccopy(p_key, lista);
acutRelRb(p_key);
return p_ret;
}
/*************************************************************************/
/*.doc gsc_assoc (external)*/
/*+
Riceve due parametri una lista di ricerca (lista) ed un puntatore ad
una chiave da ricercare (Key).
La lista deve a sua volta contenere delle sottoliste.
Parametri:
presbuf Key; resbuf da cercare
presbuf lista; lista in cui cercare
int sensitive; usato solo per stringhe; sensibile al maiuscolo (default = TRUE)
La funzione restituisce la sottolista (di lista) il cui primo
elemento sia uguale a (Key) o NULL nel caso
di errore nei parametri o nel caso non trovi la chiave di ricerca.
-*/
/*************************************************************************/
struct resbuf *gsc_assoc(presbuf Key, presbuf lista, int sensitive)
{
presbuf p, pItem = lista;
if (!lista || !Key) return NULL;
while ((pItem = pItem->rbnext))
{
if (pItem->restype == RTLB)
{
if ((p = pItem->rbnext) == NULL) return NULL;
if (gsc_equal(p, Key, sensitive)) return pItem;
pItem = gsc_scorri(pItem); // vado all'elemento successivo
}
else if (pItem->restype != RTNIL)
return NULL;
}
return NULL;
}
struct resbuf *gsc_assoc(const char *stringa, presbuf lista, int sensitive)
{
TCHAR *UnicodeString = gsc_CharToUnicode(stringa);
struct resbuf *res = gsc_assoc(UnicodeString, lista, sensitive);
if (UnicodeString) free(UnicodeString);
return res;
}
struct resbuf *gsc_assoc(const TCHAR *stringa, presbuf lista, int sensitive)
{
presbuf p_key, p_ret;
if (!stringa) return NULL;
if ((p_key = acutBuildList(RTSTR, stringa, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
p_ret = gsc_assoc(p_key, lista, sensitive);
acutRelRb(p_key);
return p_ret;
}
struct resbuf *gsc_CdrAssoc(const TCHAR *stringa, presbuf lista, int sensitive)
{ return gsc_nth(1, gsc_assoc(stringa, lista, sensitive)); }
/*************************************************************************/
/*.doc gsc_RbSubst (external)*/
/*+
Riceve due parametri: un puntatore a resbuf e il nuovo valore che verrà inserito
sostituendo quello vecchio
Parametri:
presbuf p_rb; resbuf
long new_value; nuovo valore da inserire
La funzione ritorna GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*************************************************************************/
int gsc_RbSubst(presbuf p_rb, long new_value)
{
if (!p_rb) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
switch (p_rb->restype)
{
case RTPICKS: // gruppo di selezione
ads_ssfree(p_rb->resval.rlname);
p_rb->restype = RTLONG;
break;
case RTSTR: // stringa
if (p_rb->resval.rstring) free(p_rb->resval.rstring);
p_rb->restype = RTLONG;
break;
case 1004: // dato binario
if (p_rb->resval.rbinary.buf) free(p_rb->resval.rbinary.buf);
p_rb->restype = RTLONG;
break;
case RTLONG: break;
default:
p_rb->restype = RTLONG;
}
p_rb->resval.rlong = new_value;
return GS_GOOD;
}
int gsc_RbSubst(presbuf p_rb, int new_value)
{
if (!p_rb) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
switch (p_rb->restype)
{
case RTPICKS: // gruppo di selezione
ads_ssfree(p_rb->resval.rlname);
p_rb->restype = RTSHORT;
break;
case RTSTR: // stringa
if (p_rb->resval.rstring) free(p_rb->resval.rstring);
p_rb->restype = RTSHORT;
break;
case 1004: // dato binario
if (p_rb->resval.rbinary.buf) free(p_rb->resval.rbinary.buf);
p_rb->restype = RTSHORT;
break;
case RTSHORT: break;
default:
p_rb->restype = RTSHORT;
}
p_rb->resval.rint = new_value;
return GS_GOOD;
}
int gsc_RbSubst(presbuf p_rb, double new_value)
{
if (!p_rb) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
switch (p_rb->restype)
{
case RTPICKS: // gruppo di selezione
ads_ssfree(p_rb->resval.rlname);
p_rb->restype = RTREAL;
break;
case RTSTR: // stringa
if (p_rb->resval.rstring) free(p_rb->resval.rstring);
p_rb->restype = RTREAL;
break;
case 1004: // dato binario
if (p_rb->resval.rbinary.buf) free(p_rb->resval.rbinary.buf);
p_rb->restype = RTREAL;
break;
case RTREAL: break;
default:
p_rb->restype = RTREAL;
}
p_rb->resval.rreal = new_value;
return GS_GOOD;
}
int gsc_RbSubst(presbuf p_rb, const char *new_value)
{
TCHAR *UnicodeString = gsc_CharToUnicode(new_value);
int res = gsc_RbSubst(p_rb, UnicodeString);
if (UnicodeString) free(UnicodeString);
return res;
}
int gsc_RbSubst(presbuf p_rb, const TCHAR *new_value)
{
if (!p_rb) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
switch (p_rb->restype)
{
case RTPICKS: // gruppo di selezione
ads_ssfree(p_rb->resval.rlname);
p_rb->restype = RTSTR;
break;
case RTSTR: // stringa
if (p_rb->resval.rstring) free(p_rb->resval.rstring);
break;
case 1004: // dato binario
if (p_rb->resval.rbinary.buf) free(p_rb->resval.rbinary.buf);
p_rb->restype = RTSTR;