00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 static char USMID[] = "@(#) libcif/cif_conv.c 30.22 12/08/96 14:42:46";
00038
00039
00040
00041
00042
00043
00044
00045 #define CIF_VERSION 3
00046
00047 #ifdef _ABSOFT
00048 #include "cif.h"
00049 #else
00050 #include <cif.h>
00051 #endif
00052
00053 #include <stdlib.h>
00054 #include <stdio.h>
00055 #include <string.h>
00056 #include <unistd.h>
00057 #include "unitrecord.h"
00058 #include "cif_int.h"
00059
00060 #include <sys/types.h>
00061 #include <sys/stat.h>
00062
00063 extern char *strdup(const char *s);
00064 extern char *tempnam(const char *dir, const char *pfx);
00065
00066 extern void exit (int);
00067
00068
00069
00070 enum Boolean {False, True};
00071
00072
00073 static int sortfile (struct Cif_generic *);
00074 static int copy_units (void);
00075 static int write_header (void);
00076 static int get_srcfid (void);
00077 static int write_unit (int, enum Boolean, enum Boolean);
00078 int cif_VerifyCanWrite( char *file );
00079 static int lang;
00080
00081
00082
00083
00084
00085 static int cifconv_return_code = 0;
00086
00087 static void free_copied_blocks();
00088
00089 #define CIFCONV_INVALID_RECORDS 2
00090
00091 #undef Cif_Cifconv
00092
00093 #define MEM_ERROR { \
00094 (void) fprintf (stderr, "libcif: %s\n", Cif_Errstring(CIF_NOMEM)); \
00095 exit (1); \
00096 }
00097
00098 #define OUT_ERROR(STR,FD,STATUS) { \
00099 (void) fprintf (stderr, "libcif: error %s file %s - %s\n", \
00100 STR, (FD==outfd ? global_outfile : tfile), Cif_Errstring(STATUS)); \
00101 exit (STATUS); \
00102 }
00103
00104
00105 static int infd;
00106 static int outfd;
00107 static int tmpfd = -1;
00108 static char *tfile = NULL;
00109 static long fdirpos;
00110 static enum Boolean canpos = False;
00111 static int *global_nuses = (int *) NULL;
00112 static int global_nuses_allocated = 0;
00113
00114 #ifdef DEBUG
00115 static FILE *dfd;
00116 static FILE *sfd;
00117 void dump_patbl ();
00118 int valid_patbl ();
00119 #endif
00120
00121
00122 #define ID_BUMP 500
00123 static enum Boolean Remap_id;
00124 struct Id_tbl {
00125 long *tbl;
00126 int max;
00127 int cur;
00128 };
00129 static struct Id_tbl sid;
00130 #ifdef REMAP_FID
00131 static struct Id_tbl fid;
00132 #endif
00133
00134 static enum Boolean first_time = True;
00135
00136 #ifdef REMAP_FID
00137
00138 static int srcfid = 0;
00139 #endif
00140
00141
00142 static struct {
00143 struct Cif_generic **aptr;
00144 int psize;
00145 int next;
00146 } patbl[CIF_MAXRECORD];
00147
00148 static char *global_outfile;
00149
00150
00151
00152
00153
00154
00155
00156
00157 static enum Boolean global_error_report = False;
00158
00159
00160 static const int pabump[CIF_MAXRECORD] = {
00161 0,
00162 100,
00163 1,
00164 100,
00165 200,
00166 100,
00167 100,
00168 100,
00169 100,
00170 100,
00171 200,
00172 100,
00173 100,
00174 400,
00175 1,
00176 1,
00177 100,
00178 1,
00179 1,
00180 1000,
00181 100,
00182 1,
00183 1,
00184 1,
00185 1,
00186 1000,
00187 100,
00188 100,
00189 100,
00190 100,
00191 200,
00192 100,
00193 100,
00194 100,
00195 200,
00196 100,
00197 400,
00198 1,
00199 1,
00200 100,
00201 100,
00202 100,
00203 100,
00204 100,
00205 100,
00206 100,
00207 100,
00208 100,
00209 1,
00210 1,
00211 100,
00212 400,
00213 1,
00214 100,
00215 200,
00216 100,
00217 400,
00218 200,
00219 200,
00220 200,
00221 400,
00222 100,
00223 0,0,0,0,0,0,0,0,
00224 1,
00225 0,0,0,0,0,0,0,0,0,
00226 100,
00227 100,
00228 100,
00229 100,
00230 100,
00231 100,
00232 100
00233
00234
00235 };
00236
00237
00238 static int comp_callsite (struct Cif_callsite **, struct Cif_callsite **);
00239 static int comp_comblk (struct Cif_comblk **, struct Cif_comblk **);
00240 static int comp_const (struct Cif_const **, struct Cif_const **);
00241 static int comp_entry (struct Cif_entry **, struct Cif_entry **);
00242 static int comp_file (struct Cif_file **, struct Cif_file **);
00243 static int comp_label (struct Cif_label **, struct Cif_label **);
00244 static int comp_loop (struct Cif_loop **, struct Cif_loop **);
00245 static int comp_message (struct Cif_message **, struct Cif_message **);
00246 static int comp_namelist (struct Cif_namelist **, struct Cif_namelist **);
00247 static int comp_object (struct Cif_object **, struct Cif_object **);
00248 static int comp_stmt_type (struct Cif_stmt_type **,struct Cif_stmt_type **);
00249 static int comp_usage (struct Cif_usage **, struct Cif_usage **);
00250 static int comp_c_tag (struct Cif_c_tag **, struct Cif_c_tag **);
00251 static int comp_c_message (struct Cif_c_message **, struct Cif_c_message **);
00252 static int comp_c_const (struct Cif_c_const **, struct Cif_c_const **);
00253 static int comp_c_entry (struct Cif_c_entry **, struct Cif_c_entry **);
00254 static int comp_c_object (struct Cif_c_object **, struct Cif_c_object **);
00255 static int comp_c_lint_directive (struct Cif_c_lint_directive **, struct Cif_c_lint_directive **);
00256 static int comp_c_macro_def (struct Cif_c_macro_def **, struct Cif_c_macro_def **);
00257 static int comp_c_macro_undef (struct Cif_c_macro_undef **, struct Cif_c_macro_undef **);
00258 static int comp_c_macro_usage (struct Cif_c_macro_usage **, struct Cif_c_macro_usage **);
00259 static int comp_c_entry_end (struct Cif_c_entry_end **, struct Cif_c_entry_end **);
00260
00261 static int comp_cdir (struct Cif_cdir **, struct Cif_cdir **);
00262 static int comp_cdir_doshared (struct Cif_cdir_doshared **, struct Cif_cdir_doshared **);
00263 static int comp_geometry (struct Cif_geometry **, struct Cif_geometry **);
00264 static int comp_continuation (struct Cif_continuation **, struct Cif_continuation **);
00265 static int comp_transform (struct Cif_transform **, struct Cif_transform **);
00266
00267 #ifndef CRAY2
00268 static int comp_f90_callsite (struct Cif_f90_callsite **, struct Cif_f90_callsite **);
00269 static int comp_f90_comblk (struct Cif_f90_comblk **, struct Cif_f90_comblk **);
00270 static int comp_f90_const (struct Cif_f90_const **, struct Cif_f90_const **);
00271 static int comp_f90_entry (struct Cif_f90_entry **, struct Cif_f90_entry **);
00272 static int comp_f90_loop (struct Cif_f90_loop **, struct Cif_f90_loop **);
00273 static int comp_f90_derived_type (struct Cif_f90_derived_type **, struct Cif_f90_derived_type **);
00274 static int comp_f90_label (struct Cif_f90_label **, struct Cif_f90_label **);
00275 static int comp_f90_namelist (struct Cif_f90_namelist **, struct Cif_f90_namelist **);
00276 static int comp_f90_object (struct Cif_f90_object **, struct Cif_f90_object **);
00277 static int comp_f90_begin_scope (struct Cif_f90_begin_scope **, struct Cif_f90_begin_scope **);
00278 static int comp_f90_end_scope (struct Cif_f90_end_scope **, struct Cif_f90_end_scope **);
00279 static int comp_f90_scope_info (struct Cif_f90_scope_info **, struct Cif_f90_scope_info **);
00280 static int comp_f90_use_module (struct Cif_f90_use_module **, struct Cif_f90_use_module **);
00281 static int comp_f90_rename (struct Cif_f90_rename **, struct Cif_f90_rename **);
00282 static int comp_f90_int_block (struct Cif_f90_int_block **, struct Cif_f90_int_block **);
00283 static int comp_f90_vectorization (struct Cif_f90_vectorization **, struct Cif_f90_vectorization **);
00284
00285 #endif
00286
00287 static int comp_cc_type (struct Cif_cc_type **, struct Cif_cc_type **);
00288 static int comp_cc_entry (struct Cif_cc_entry **, struct Cif_cc_entry **);
00289 static int comp_cc_obj (struct Cif_cc_obj **, struct Cif_cc_obj **);
00290 static int comp_cc_subtype (struct Cif_cc_subtype **, struct Cif_cc_subtype **);
00291 static int comp_cc_enum (struct Cif_cc_enum **, struct Cif_cc_enum **);
00292 static int comp_cc_expr (struct Cif_cc_expr **, struct Cif_cc_expr **);
00293
00294 static int comp_src_pos (struct Cif_src_pos **, struct Cif_src_pos **);
00295 static int comp_orig_cmd (struct Cif_orig_cmd **, struct Cif_orig_cmd **);
00296
00297 static int (*qcompare[CIF_MAXRECORD]) () = {
00298 0,
00299 comp_callsite,
00300 0,
00301 comp_comblk,
00302 comp_const,
00303 comp_cdir,
00304 comp_entry,
00305 comp_file,
00306 comp_loop,
00307 0,
00308 comp_label,
00309 comp_message,
00310 comp_namelist,
00311 comp_object,
00312 0,0,
00313 comp_cdir_doshared,
00314 0,0,
00315 comp_usage,
00316 0,0,0,0,0,
00317 comp_stmt_type,
00318 comp_geometry,
00319 comp_continuation,
00320 #ifndef CRAY2
00321 comp_f90_callsite,
00322 comp_f90_comblk,
00323 comp_f90_const,
00324 comp_f90_entry,
00325 comp_f90_loop,
00326 comp_f90_derived_type,
00327 comp_f90_label,
00328 comp_f90_namelist,
00329 comp_f90_object,
00330 #else
00331 0,0,0,0,0,0,0,0,0,
00332 #endif
00333 0,
00334 0,
00335 #ifndef CRAY2
00336 comp_f90_begin_scope,
00337 comp_f90_end_scope,
00338 comp_f90_scope_info,
00339 comp_f90_use_module,
00340 comp_f90_rename,
00341 comp_f90_int_block,
00342 comp_f90_vectorization,
00343 #else
00344 0,0,0,0,0,0,0,
00345 #endif
00346 0,
00347 comp_transform,
00348 0, 0,
00349 0,
00350 comp_c_tag,
00351 0,
00352 comp_c_message,
00353 comp_c_const,
00354 comp_c_entry,
00355 comp_c_object,
00356 comp_c_lint_directive,
00357 comp_c_macro_def,
00358 comp_c_macro_undef,
00359 comp_c_macro_usage,
00360 comp_c_entry_end,
00361 0,0,0,0,0,0,0,0,
00362 comp_orig_cmd,
00363 0,0,0,0,0,0,0,0,0,
00364 comp_cc_type,
00365 comp_cc_entry,
00366 comp_cc_obj,
00367 comp_cc_subtype,
00368 comp_cc_enum,
00369 comp_cc_expr,
00370 comp_src_pos
00371 };
00372
00373
00374 static void addstruct (struct Cif_generic *);
00375 static void addunit (struct Cif_generic *);
00376 static void add_id (struct Id_tbl *, long);
00377 static int comp_ids (long *, long *);
00378 static long get_max_fid (void);
00379 static long get_max_sid (void);
00380 static void init_id (struct Id_tbl *);
00381 static void makeudir (void);
00382 static void remap_files (void);
00383 static void remap_symbols (void);
00384
00385
00386
00387
00388 static int later_date
00389 #ifdef __STDC__
00390 (char *file_1, char *file_2)
00391 #else
00392 (file_1, file_2)
00393 char *file_1, *file_2;
00394 #endif
00395 {
00396 struct stat buf_1, buf_2;
00397
00398 (void) stat(file_1, &buf_1);
00399 (void) stat(file_2, &buf_2);
00400
00401 return(buf_2.st_mtime >= buf_1.st_mtime);
00402 }
00403
00404
00405
00406
00407
00408 static
00409 int cif_next_entry
00410 #ifdef __STDC__
00411 ( int cifd, long *cifpos, struct Cif_generic **cif_record )
00412 #else
00413 ( cifd, cifpos, cif_record )
00414 int cifd;
00415 long *cifpos;
00416 struct Cif_generic **cif_record;
00417 #endif
00418 {
00419 int rtype;
00420
00421 if ((rtype = Cif_Setpos (cifd, *cifpos)) < 0) {
00422 (void) fprintf(stderr, "libcif: set pos returns %d %s for cifd %d %ld\n",
00423 rtype,
00424 Cif_Errstring(rtype),
00425 cifd,
00426 *cifpos);
00427 }
00428
00429 if ((rtype = Cif_Getrecord (cifd, cif_record)) < 0) {
00430 (void) fprintf (stderr, "libcif: Unknown record type at %ld for %d: (%d) %s\n",
00431 *cifpos,
00432 cifd,
00433 rtype,
00434 Cif_Errstring(rtype));
00435 }
00436
00437 *cifpos = Cif_Getpos(cifd);
00438 return(rtype);
00439 }
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449 static int cifconv_type
00450 #ifdef __STDC__
00451 (char *cif_name)
00452 #else
00453 (cif_name)
00454 char *cif_name;
00455 #endif
00456 {
00457 int cifd;
00458 long filepos = CIF_FIRST_RECORD;
00459 int return_code;
00460 struct Cif_generic *cif_record;
00461
00462 cifd = Cif_Open(cif_name, "r", NULL, CIF_VERSION);
00463
00464 if (cifd >= 0 &&
00465 cif_next_entry(cifd, &filepos, &cif_record) == CIF_CIFHDR) {
00466
00467 return_code = (CIFHDR(cif_record)->form == CIF_FORM_SORTED);
00468 return_code &= (CIFHDR(cif_record)->bintype == CIF_FORM_CIFCONV);
00469
00470 lang = CIFHDR(cif_record)->lang;
00471
00472 (void) Cif_Close (cifd, CIF_MEM_FREE);
00473 return(return_code);
00474 }
00475 else {
00476 return(0);
00477 }
00478 }
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 static char *Cif_Make_Cifconv
00495 #ifdef __STDC__
00496 (char *infile, char *outfile, int *rtypes)
00497 #else
00498 (infile, outfile, rtypes)
00499 char *infile;
00500 char *outfile;
00501 int *rtypes;
00502 #endif
00503 {
00504
00505 int arg;
00506 struct Cif_generic *cifp;
00507 int ret;
00508
00509 #ifdef DEBUG
00510 dfd = fopen ("debug", "w");
00511 sfd = stdout;
00512 #endif
00513
00514
00515
00516
00517
00518 global_outfile = infile;
00519
00520
00521
00522 if ((infd = Cif_Open(infile, "r", rtypes, CIF_VERSION)) < 0) {
00523
00524 cifconv_return_code = infd;
00525 return ((char *) NULL);
00526 }
00527
00528
00529 if ((ret = Cif_Memmode(infd,CIF_MEM_MANAGED)) < 0) {
00530 (void) fprintf(stderr,"\nlibcif: Unrecoverable internal error - Cif_Memmode\
00531 (%d,CIF_MEM_MANAGED=%d) returns %d:\n\t Possible cause is memory \
00532 expansion request denial by OS\n\t Note -- Internal CIF-Library \
00533 Message:\n\n\t\t \"%s\"\n",
00534 infd,CIF_MEM_MANAGED,ret,Cif_Errstring(ret));
00535 exit(ret);
00536 }
00537
00538 if ((outfd = Cif_Open(outfile, "w", NULL, CIF_VERSION)) < 0) {
00539 (void) Cif_Close(infd, CIF_MEM_FREE);
00540 cifconv_return_code = outfd;
00541 return ((char *) NULL);
00542 }
00543
00544
00545
00546
00547
00548
00549 if ((arg = Cif_Getrecord (infd, &cifp)) == CIF_CIFHDR) {
00550
00551 if (CIFHDR(cifp)->form == CIF_FORM_SORTED) {
00552 (void) free(outfile);
00553 return(strdup(infile));
00554 }
00555 else {
00556 if (CIFHDR(cifp)->cont_id == CIF_ID_NONCONTIG) {
00557
00558
00559
00560 if (sid.tbl != (long *) NULL)
00561 (void) free(sid.tbl);
00562
00563 if ((sid.tbl = (long *) malloc (sizeof(long)*ID_BUMP)) == NULL)
00564 MEM_ERROR;
00565 sid.max = ID_BUMP;
00566
00567 #ifdef REMAP_FID
00568 if (fid.tbl != (long *) NULL)
00569 (void) free(fid.tbl);
00570
00571 if ((fid.tbl = (long *) malloc (sizeof(long)*ID_BUMP)) == NULL)
00572 MEM_ERROR;
00573 fid.max = ID_BUMP;
00574 #endif
00575 Remap_id = True;
00576 }
00577 else
00578 Remap_id = False;
00579
00580
00581
00582
00583
00584 if (sortfile (cifp) < 0) {
00585 (void) Cif_Close(outfd, CIF_MEM_FREE);
00586 unlink(outfile);
00587 return(strdup(infile));
00588 }
00589 }
00590 }
00591 else {
00592 if (arg > 0)
00593 return((char *) NULL);
00594 }
00595
00596
00597 free_copied_blocks();
00598
00599
00600
00601 (void) Cif_Close (infd, CIF_MEM_KEEP);
00602 (void) Cif_Close (outfd, CIF_MEM_KEEP);
00603
00604
00605
00606 if (tmpfd != -1) {
00607 (void) Cif_Close (tmpfd, CIF_MEM_KEEP);
00608 tmpfd = -1;
00609 }
00610
00611 #ifdef DEBUG
00612 (void) fclose (dfd);
00613 #endif
00614 return(outfile);
00615 }
00616
00617
00618
00619
00620
00621
00622
00623
00624 static char *cif_tt_dir = (char *) NULL;
00625
00626 void Cif_ConvDir
00627 #ifdef __STDC__
00628 (char *dir)
00629 #else
00630 (dir)
00631 char *dir;
00632 #endif
00633 {
00634 cif_tt_dir = dir;
00635 }
00636
00637
00638
00639 static char *concat
00640 #ifdef _STDC__
00641 ( char *str1, char *str2 )
00642 #else
00643 ( str1, str2 )
00644 char *str1, *str2;
00645 #endif
00646 {
00647 char *buf;
00648
00649 buf = (char *) malloc (sizeof(char) * (strlen(str1) + strlen(str2) + 1));
00650 sprintf(buf, "%s%s",str1, str2);
00651 return(buf);
00652 }
00653
00654
00655 int assertCanWriteDir
00656 #ifdef __STDC__
00657 (char *dir)
00658 #else
00659 (dir)
00660 char *dir;
00661 #endif
00662 {
00663 struct stat buf;
00664 int mode;
00665 char * test_file = concat(dir,"/write_test");
00666 FILE * fd;
00667
00668 mode = stat(dir, &buf);
00669
00670 if (mode == 0 &&
00671 S_ISDIR(buf.st_mode)) {
00672 if (NULL == (fd = fopen(test_file,"w"))) {
00673 return(0);
00674 };
00675 fclose(fd);
00676 unlink(test_file);
00677 }
00678 else {
00679 return(0);
00680 }
00681
00682 free(test_file);
00683
00684 return(1);
00685 }
00686
00687 static char *cif_convert_to_cifconv
00688 #ifdef __STDC__
00689 (char *filename, int keep, int *tmp_cif, int *rtypes)
00690 #else
00691 (filename, keep, tmp_cif, rtypes)
00692 char *filename;
00693 int keep;
00694 int *tmp_cif;
00695 int *rtypes;
00696 #endif
00697 {
00698 char *value;
00699 char *cifdir = (char *) NULL;
00700 char *cifdir_file = (char *) NULL;
00701 char *tt_file = (char *) NULL;
00702 char *outfile = (char *) NULL;
00703 char *create_cif_file = (char *) NULL;
00704 char *tmpdir = (char *) NULL;
00705
00706
00707
00708 *tmp_cif = 0;
00709
00710
00711
00712 if (cifconv_type( filename ) == 1)
00713 return(strdup(filename));
00714
00715
00716
00717
00718 if (cif_tt_dir != (char *) NULL) {
00719
00720 cifdir = cif_tt_dir;
00721
00722 tt_file = (char *) malloc(sizeof(char) *
00723 (strlen(cif_tt_dir) +
00724 strlen(cif_basename(filename)) +
00725 3));
00726
00727 (void) sprintf(tt_file, "%s/%sT", cif_tt_dir,
00728 cif_basename(filename));
00729
00730 if (!access(tt_file, R_OK)) {
00731
00732 if (later_date(filename, tt_file) &&
00733 cifconv_type(tt_file) == 1) {
00734 return(tt_file);
00735 }
00736 }
00737 }
00738
00739
00740
00741
00742
00743 value = getenv("CIFDIR");
00744 if (value != (char *) NULL) {
00745 cifdir = value;
00746
00747 cifdir_file = (char *) malloc(sizeof(char) *
00748 (strlen(cifdir) +
00749 strlen(cif_basename(filename)) +
00750 3));
00751
00752 (void) sprintf(cifdir_file, "%s/%sT", cifdir, cif_basename(filename));
00753
00754 if (!access(cifdir_file, R_OK)) {
00755
00756 if (later_date(filename, cifdir_file) &&
00757 cifconv_type(cifdir_file) == 1) {
00758
00759 if (tt_file != (char *) NULL)
00760 free(tt_file);
00761
00762 return(cifdir_file);
00763 }
00764 }
00765 }
00766
00767
00768
00769 outfile = (char *) malloc(sizeof(char) *
00770 (strlen(filename) + 2));
00771 (void) sprintf(outfile, "%sT", filename);
00772
00773 if (!access(outfile, R_OK)) {
00774
00775 if (later_date(filename, outfile) &&
00776 cifconv_type(outfile) == 1) {
00777
00778 if (tt_file != (char *) NULL)
00779 free(tt_file);
00780
00781 if (cifdir_file != (char *) NULL)
00782 free(cifdir_file);
00783
00784 return(outfile);
00785 }
00786 }
00787
00788
00789
00790
00791
00792
00793 if (keep == 1) {
00794
00795
00796
00797
00798
00799
00800 if (tt_file != (char *) NULL &&
00801 cif_VerifyCanWrite(tt_file)) {
00802
00803 create_cif_file = strdup(tt_file);
00804 }
00805 else
00806
00807
00808
00809 if (cifdir_file != (char *) NULL &&
00810 cif_VerifyCanWrite(cifdir_file)) {
00811
00812 create_cif_file = strdup(cifdir_file);
00813 }
00814 else
00815
00816
00817
00818 if (outfile != (char *) NULL &&
00819 cif_VerifyCanWrite(outfile)) {
00820
00821 create_cif_file = strdup(outfile);
00822 }
00823 }
00824
00825 if (create_cif_file == (char *) NULL) {
00826
00827
00828
00829 value = getenv("TMPDIR");
00830 if (value != (char *) NULL && assertCanWriteDir(value) == 1) {
00831 tmpdir = value;
00832 }
00833 else {
00834
00835 create_cif_file = (char *) malloc(sizeof(char) *
00836 (strlen("/tmp/") +
00837 strlen(cif_basename(filename)) +
00838 7));
00839
00840
00841 (void) sprintf(create_cif_file, "/tmp/%sXXXXXX", cif_basename(filename));
00842 (void) mktemp(create_cif_file);
00843 }
00844
00845 if (create_cif_file == (char *) NULL) {
00846 create_cif_file = (char *) malloc(sizeof(char) *
00847 (strlen(tmpdir) +
00848 strlen(cif_basename(filename)) +
00849 3));
00850
00851 (void) sprintf(create_cif_file, "%s/%sT", tmpdir, cif_basename(filename));
00852 }
00853
00854
00855
00856
00857
00858
00859 *tmp_cif = 1;
00860
00861 }
00862
00863 create_cif_file = Cif_Make_Cifconv(filename, create_cif_file, rtypes);
00864
00865
00866
00867 if (cifdir_file != (char *) NULL) (void) free(cifdir_file);
00868 if (tt_file != (char *) NULL) (void) free(tt_file);
00869 if (outfile != (char *) NULL) (void) free(outfile);
00870
00871 return(create_cif_file);
00872 }
00873
00874
00875 int Cif_Cifconv
00876 #ifdef __STDC__
00877 (char *filename, char *optype, int *rtypes, int version, int keep)
00878 #else
00879 (filename, optype, rtypes, version, keep)
00880 char *filename;
00881 char *optype;
00882 int *rtypes;
00883 int version;
00884 int keep;
00885 #endif
00886 {
00887
00888 char *cif_name;
00889 int tmp_cif;
00890
00891
00892
00893
00894 int ret;
00895
00896 if (_cif_version == 0)
00897 _cif_version = 1;
00898
00899
00900
00901
00902
00903
00904 if (keep & 0x100) {
00905 global_error_report = True;
00906 }
00907
00908
00909
00910
00911
00912
00913 if (first_time == True) {
00914 sid.tbl = (long *) NULL;
00915 sid.max = 0;
00916 sid.cur = 0;
00917 #ifdef REMAP_FID
00918 fid.tbl = (long *) NULL;
00919 fid.max = 0;
00920 fid.cur = 0;
00921 #endif
00922 first_time = False;
00923 }
00924
00925
00926 cif_name = cif_convert_to_cifconv(filename, keep & 0xff, &tmp_cif, rtypes);
00927
00928
00929 if (cif_name == (char *) NULL) {
00930 return(cifconv_return_code);
00931 }
00932
00933
00934
00935 if (version == 2) {
00936 ret = Cif_Open_V2(cif_name, optype, rtypes, version);
00937 }
00938 else {
00939 ret = Cif_Open_V3_1(cif_name, optype, rtypes, version,
00940 CIF_SUB_VERSION_3);
00941 }
00942
00943
00944
00945
00946
00947
00948 if (ret >= 0) {
00949 _Cif_filetbl[ret].tmp_cif = tmp_cif;
00950 }
00951
00952
00953
00954 free(cif_name);
00955
00956
00957
00958 return(ret);
00959 }
00960
00961
00962
00963
00964
00965
00966
00967
00968 int Cif_Cifconv_V2_1
00969 #ifdef __STDC__
00970 (char *filename, char *optype, int *rtypes, int version, int keep, int sub_version)
00971 #else
00972 (filename, optype, rtypes, version, keep, sub_version)
00973 char *filename;
00974 char *optype;
00975 int *rtypes;
00976 int version;
00977 int keep;
00978 int sub_version;
00979 #endif
00980 {
00981
00982 _cif_version = 2;
00983 if (sub_version != CIF_SUB_VERSION_2)
00984 return(CIF_SUBVER);
00985
00986 return(Cif_Cifconv(filename, optype, rtypes,
00987 version, keep));
00988 }
00989
00990
00991
00992
00993
00994 int Cif_Cifconv_V3_1
00995 #ifdef __STDC__
00996 (char *filename, char *optype, int *rtypes, int version, int keep, int sub_version)
00997 #else
00998 (filename, optype, rtypes, version, keep, sub_version)
00999 char *filename;
01000 char *optype;
01001 int *rtypes;
01002 int version;
01003 int keep;
01004 int sub_version;
01005 #endif
01006 {
01007 _cif_version = 3;
01008 if (sub_version != CIF_SUB_VERSION_3)
01009 return(CIF_SUBVER);
01010
01011 return(Cif_Cifconv(filename, optype, rtypes,
01012 version, keep));
01013 }
01014
01015
01016
01017
01018
01019
01020
01021 static struct Cif_generic **record_store = (struct Cif_generic **) NULL;
01022 static int current_store_record = 0;
01023 static int max_store_record = 0;
01024
01025 static struct Cif_generic *cif_copy_record(struct Cif_generic *cifp)
01026 {
01027 struct Cif_generic *return_cifp = Cif_Duplicate(cifp);
01028
01029 if (current_store_record == max_store_record) {
01030 max_store_record+=200;
01031 if (record_store == (struct Cif_generic **) NULL)
01032 record_store = (struct Cif_generic **)
01033 malloc(max_store_record * sizeof(struct Cif_generic *));
01034 else
01035 record_store = (struct Cif_generic **)
01036 realloc(record_store,
01037 max_store_record * sizeof(struct Cif_generic *));
01038
01039 }
01040
01041 record_store[current_store_record++] = return_cifp;
01042 return(return_cifp);
01043 }
01044
01045
01046
01047 static void free_copied_blocks()
01048 {
01049 int i;
01050
01051 for (i = 0; i < current_store_record; i++) {
01052 Cif_Free(record_store[i]);
01053 }
01054 current_store_record = 0;
01055 }
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065 static int sortfile (
01066 struct Cif_generic *cifp)
01067 {
01068
01069 int i, rtype;
01070 int unit_found = 0;
01071 struct Cif_generic *fdp;
01072 struct Cif_generic *cifp1;
01073 long sid;
01074 struct Cif_urectbl *urp;
01075 int in_unit = 0;
01076
01077
01078
01079
01080 if (Cif_Getpos (outfd) >= 0)
01081 canpos = True;
01082
01083
01084
01085
01086
01087 CIFHDR(cifp)->form = CIF_FORM_SORTED;
01088
01089
01090
01091
01092
01093 CIFHDR(cifp)->bintype = CIF_FORM_CIFCONV;
01094
01095
01096 for (i = 0; i < CIF_MAXRECORD; i++) {
01097 patbl[i].aptr = NULL;
01098 patbl[i].psize = 0;
01099 patbl[i].next = (int)NULL;
01100 }
01101
01102 if ((cifp1 = cif_copy_record(cifp)) == NULL)
01103 MEM_ERROR;
01104 addstruct (cifp1);
01105 while ((rtype = Cif_Getrecord (infd, &cifp)) >= 0) {
01106 if (rtype == CIF_UNIT) {
01107
01108 in_unit = 1;
01109
01110
01111
01112
01113
01114
01115
01116 if ((cifp = cif_copy_record (cifp)) == NULL) MEM_ERROR;
01117 if (unit_found == 1) {
01118 tfile = tempnam (NULL, "cif.");
01119 if ((tmpfd = Cif_Open (tfile, "w", NULL, CIF_VERSION)) < 0) {
01120 (void) fprintf (stderr, "libcif: cannot create temporary file %s - %s\n",
01121 tfile, Cif_Errstring(tmpfd));
01122 return (tmpfd);
01123 }
01124 }
01125 if (unit_found > 0) {
01126 if ((i = write_unit (tmpfd, False, True)) < 0)
01127 return (i);
01128 (void) Cif_Release (infd, CIF_MEM_KEEP);
01129 for (i = 0; i < CIF_MAXRECORD; i++)
01130 if (unit_record[i]) patbl[i].next = 0;
01131 }
01132 unit_found++;
01133 addstruct (cifp);
01134 addunit(cifp);
01135 makeudir();
01136 }
01137
01138 else if (rtype == CIF_ENDUNIT) {
01139
01140 addstruct (cifp);
01141 cifp1 = *(patbl[CIF_UNITDIR].aptr);
01142 urp = CIFUDIR(cifp1)->ur;
01143 for (i = 0; i < CIF_MAXRECORD; i++) {
01144 if (unit_record[i])
01145 urp[i].nrecords = patbl[i].next;
01146 }
01147
01148 in_unit = 0;
01149 }
01150
01151 else if (unit_record[rtype])
01152 addstruct (cifp);
01153
01154 else {
01155
01156
01157
01158
01159
01160 if ((cifp1 = cif_copy_record (cifp)) == NULL)
01161 MEM_ERROR;
01162 addstruct (cifp1);
01163 }
01164
01165 }
01166 if (rtype != CIF_EOF) {
01167 (void) fprintf (stderr, "libcif: error reading input file - %s\n",
01168 Cif_Errstring(rtype));
01169 return (rtype);
01170 }
01171
01172
01173
01174
01175
01176 if (in_unit == 1) {
01177 struct Cif_urectbl *urp;
01178
01179 addstruct (cifp);
01180 cifp1 = *(patbl[CIF_UNITDIR].aptr);
01181 urp = CIFUDIR(cifp1)->ur;
01182 for (i = 0; i < CIF_MAXRECORD; i++) {
01183 if (unit_record[i])
01184 urp[i].nrecords = patbl[i].next;
01185 }
01186 }
01187
01188
01189
01190 if (unit_found > 1) {
01191 if ((i = write_unit (tmpfd, False, True)) < 0)
01192 return (i);
01193 }
01194
01195
01196
01197
01198
01199 #ifdef REMAP_FID
01200 if (Remap_id == True)
01201 remap_files ();
01202 #endif
01203
01204
01205
01206 if (patbl[CIF_FILEDIR].aptr == NULL) {
01207 if ((fdp = (struct Cif_generic *) malloc (sizeof(struct Cif_filedir)))
01208 == NULL) MEM_ERROR;
01209 (void) memset ((char *)fdp, '\0', sizeof(struct Cif_filedir));
01210 CIFFDIR(fdp)->rectype = CIF_FILEDIR;
01211 CIFFDIR(fdp)->nunits = 0;
01212 addstruct (fdp);
01213 }
01214
01215 cifp1 = *(patbl[CIF_FILEDIR].aptr);
01216 CIFFDIR(cifp1)->maxfid = get_max_fid ();
01217 CIFFDIR(cifp1)->nfiles = patbl[CIF_FILE].next;
01218 CIFFDIR(cifp1)->nincs = patbl[CIF_INCLUDE].next;
01219
01220
01221
01222
01223
01224 if (unit_found == 1) {
01225 if (Remap_id == True)
01226 remap_symbols();
01227 sid = get_max_sid ();
01228 cifp1 = *(patbl[CIF_UNITDIR].aptr);
01229 CIFUDIR(cifp1)->maxsid = sid;
01230 cifp1 = *(patbl[CIF_FILEDIR].aptr);
01231 CIFFDIR(cifp1)->maxsid = sid;
01232 }
01233 if (write_header() != 0)
01234 return(1);
01235
01236
01237 if (unit_found == 0 &&
01238 in_unit == 0)
01239 return(-1);
01240
01241 if (unit_found == 1) {
01242 if ((i = write_unit(outfd, canpos, True)) < 0)
01243 return (i);
01244 }
01245 else {
01246 if (unit_found >= 1) {
01247 if (copy_units () != 0)
01248 return (1);
01249 }
01250 }
01251
01252 if (canpos == True) {
01253 if ((i = Cif_Setpos (outfd, fdirpos)) < 0)
01254 OUT_ERROR ("positioning", outfd, i);
01255 cifp1 = *(patbl[CIF_FILEDIR].aptr);
01256 if ((i = Cif_Putrecord (outfd, cifp1)) < 0)
01257 OUT_ERROR ("writing", outfd, i);
01258 }
01259
01260
01261 for (i = 0; i < CIF_MAXRECORD; i++) {
01262
01263 if (patbl[i].aptr != (struct Cif_generic **) NULL) {
01264
01265 if (i == CIF_FILEDIR) {
01266 if (CIFFDIR(patbl[i].aptr[0])->ut !=
01267 (struct Cif_unittbl *) NULL)
01268 (void) free(CIFFDIR(patbl[i].aptr[0])->ut);
01269
01270 (void) free(CIFFDIR(patbl[i].aptr[0]));
01271 }
01272 (void) free(patbl[i].aptr);
01273 patbl[i].aptr = (struct Cif_generic **) NULL;
01274 }
01275 patbl[i].psize = 0;
01276 patbl[i].next = (int)NULL;
01277 }
01278
01279 return (0);
01280
01281 }
01282
01283
01284
01285
01286
01287
01288 static void addstruct (
01289 struct Cif_generic *cifp)
01290 {
01291 static int last_line = 0;
01292 static int last_cpos = 0;
01293
01294
01295
01296
01297
01298
01299 static int last_position = 0;
01300
01301 register int i, rtype;
01302
01303 rtype = cifp->rectype;
01304 if ((lang == CIF_LG_C || lang == CIF_LG_CC) && rtype == CIF_STMT_TYPE) {
01305 if (CIFSTMT(cifp)->line == last_line &&
01306 CIFSTMT(cifp)->cpos == last_cpos) {
01307 last_position++;
01308 cifp->rectype = last_position;
01309
01310
01311
01312
01313
01314
01315
01316 }
01317 else {
01318 last_line = CIFSTMT(cifp)->line;
01319 last_cpos = CIFSTMT(cifp)->cpos;
01320 last_position = 0;
01321 cifp->rectype = 0;
01322 }
01323
01324 }
01325 if (patbl[rtype].aptr == NULL) {
01326 patbl[rtype].psize = pabump[rtype];
01327 if ((patbl[rtype].aptr = (struct Cif_generic **) malloc (
01328 sizeof(struct Cif_generic *) * patbl[rtype].psize)) == NULL)
01329 {
01330 MEM_ERROR;
01331 }
01332 }
01333 i = patbl[rtype].next++;
01334 if ((i) >= patbl[rtype].psize) {
01335 patbl[rtype].psize += pabump[rtype];
01336
01337 if ((patbl[rtype].aptr = (struct Cif_generic **) realloc (
01338 (char *)patbl[rtype].aptr,
01339 sizeof(struct Cif_generic *)*patbl[rtype].psize)) == NULL)
01340 {
01341 MEM_ERROR;
01342 }
01343 }
01344 (patbl[rtype].aptr)[i] = cifp;
01345 }
01346
01347
01348
01349
01350
01351
01352
01353
01354 static void addunit (
01355 struct Cif_generic *unitp)
01356 {
01357
01358 # define UTBUMP 100
01359 static int utsize = 0;
01360
01361 int i;
01362 struct Cif_generic *fdp;
01363 struct Cif_unittbl *ut;
01364
01365
01366
01367 if (patbl[CIF_FILEDIR].aptr == NULL) {
01368 if ((fdp = (struct Cif_generic *) malloc (sizeof(struct Cif_filedir)))
01369 == NULL) MEM_ERROR;
01370 (void) memset ((char *)fdp, '\0', sizeof(struct Cif_filedir));
01371 CIFFDIR(fdp)->rectype = CIF_FILEDIR;
01372 CIFFDIR(fdp)->nunits = 0;
01373 utsize = UTBUMP;
01374 if ((ut = CIFFDIR(fdp)->ut = (struct Cif_unittbl *) malloc
01375 (sizeof(struct Cif_unittbl)*utsize)) == NULL) MEM_ERROR;
01376 addstruct (fdp);
01377 }
01378
01379
01380
01381 fdp = *(patbl[CIF_FILEDIR].aptr);
01382 if ((int) CIFFDIR(fdp)->nunits >= utsize) {
01383 utsize += UTBUMP;
01384 if ((ut = CIFFDIR(fdp)->ut = (struct Cif_unittbl *) realloc (
01385 (char *) CIFFDIR(fdp)->ut,
01386 sizeof(struct Cif_unittbl)*utsize)) == NULL) MEM_ERROR;
01387
01388 }
01389
01390
01391
01392 i = CIFFDIR(fdp)->nunits++;
01393 ut = CIFFDIR(fdp)->ut;
01394 (void) memset((char *)&ut[i], 0, sizeof(struct Cif_unittbl));
01395 ut[i].name = CIFUNIT(unitp)->name ;
01396 ut[i].nlen = strlen(ut[i].name);
01397 ut[i].unitpos = 0;
01398
01399 }
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457 static int comp_callsite (
01458 struct Cif_callsite **p1,
01459 struct Cif_callsite **p2)
01460 {
01461 register int ret;
01462
01463 if ((ret = ( (*p1)->entryid - (*p2)->entryid )) != 0)
01464 return (ret);
01465 else if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01466 return (ret);
01467 else if ((ret = ( (*p1)->line - (*p2)->line )) != 0)
01468 return (ret);
01469 else
01470 return ( (*p1)->cpos - (*p2)->cpos );
01471 }
01472
01473 static int comp_comblk (
01474 struct Cif_comblk **p1,
01475 struct Cif_comblk **p2)
01476 {
01477 return ( (*p1)->symid - (*p2)->symid );
01478 }
01479
01480 static int comp_const (
01481 struct Cif_const **p1,
01482 struct Cif_const **p2)
01483 {
01484 return ( (*p1)->symid - (*p2)->symid );
01485 }
01486
01487 static int comp_entry (
01488 struct Cif_entry **p1,
01489 struct Cif_entry **p2)
01490 {
01491 return ( (*p1)->symid - (*p2)->symid );
01492 }
01493
01494 static int comp_file (
01495 struct Cif_file **p1,
01496 struct Cif_file **p2)
01497 {
01498 return ( (*p1)->fid - (*p2)->fid );
01499 }
01500
01501 static int comp_label (
01502 struct Cif_label **p1,
01503 struct Cif_label **p2)
01504 {
01505 return ( (*p1)->symid - (*p2)->symid );
01506 }
01507
01508 static int comp_loop (
01509 struct Cif_loop **p1,
01510 struct Cif_loop **p2)
01511 {
01512 register int ret;
01513
01514 if ((ret = ( (*p1)->sfid - (*p2)->sfid )) != 0)
01515 return (ret);
01516 else if ((ret = ( (*p1)->strline - (*p2)->strline )) != 0)
01517 return (ret);
01518 else
01519 return ( (*p1)->strcpos - (*p2)->strcpos );
01520 }
01521
01522 static int comp_message (
01523 struct Cif_message **p1,
01524 struct Cif_message **p2)
01525 {
01526 register int ret;
01527
01528 if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01529 return (ret);
01530 else if ((ret = ( (*p1)->fline - (*p2)->fline )) != 0)
01531 return (ret);
01532 else
01533 return ( (*p1)->cpos - (*p2)->cpos );
01534 }
01535
01536 static int comp_namelist (
01537 struct Cif_namelist **p1,
01538 struct Cif_namelist **p2)
01539 {
01540 return ( (*p1)->symid - (*p2)->symid );
01541 }
01542
01543 static int comp_object (
01544 struct Cif_object **p1,
01545 struct Cif_object **p2)
01546 {
01547 return ( (*p1)->symid - (*p2)->symid );
01548 }
01549
01550 static int comp_stmt_type (
01551 struct Cif_stmt_type **p1,
01552 struct Cif_stmt_type **p2)
01553 {
01554 register int ret;
01555
01556 if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01557 return (ret);
01558 else if ((ret = ( (*p1)->line - (*p2)->line )) != 0)
01559 return (ret);
01560 else if (lang == CIF_LG_F90 && _cif_version >= 3) {
01561
01562
01563
01564
01565
01566 if ((ret = ( (*p1)->eline - (*p2)->eline )) != 0)
01567 return(ret);
01568 else
01569 return((*p1)->cpos - (*p2)->cpos);
01570 }
01571 else if ((ret = ( (*p1)->cpos - (*p2)->cpos )) != 0)
01572 return(ret);
01573 else
01574 return((*p1)->rectype - (*p2)->rectype);
01575 }
01576
01577
01578 static int comp_usage (
01579 struct Cif_usage **p1,
01580 struct Cif_usage **p2)
01581 {
01582 register int ret;
01583 register int i;
01584
01585 if ((ret = ( (*p1)->symid - (*p2)->symid )) != 0)
01586 return (ret);
01587 else
01588 if ((ret = ( (*p1)->nmembs - (*p2)->nmembs)) != 0)
01589 return (ret);
01590 else
01591 if ((*p1)->nmembs == 0)
01592 return(0);
01593 else {
01594 for (i = 0; i < (int) (*p1)->nmembs; i++) {
01595 if ((ret = ( (*p1)->membs[i] - (*p2)->membs[i] )) != 0)
01596 return (ret);
01597 }
01598 }
01599
01600 return(0);
01601 }
01602
01603
01604
01605 #ifndef CRAY2
01606 static int comp_f90_callsite (
01607 struct Cif_f90_callsite **p1,
01608 struct Cif_f90_callsite **p2)
01609 {
01610 register int ret;
01611
01612 if ((ret = ( (*p1)->entryid - (*p2)->entryid )) != 0)
01613 return (ret);
01614 else if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01615 return (ret);
01616 else if ((ret = ( (*p1)->line - (*p2)->line )) != 0)
01617 return (ret);
01618 else
01619 return ( (*p1)->cpos - (*p2)->cpos );
01620 }
01621
01622 static int comp_f90_comblk (
01623 struct Cif_f90_comblk **p1,
01624 struct Cif_f90_comblk **p2)
01625 {
01626 return ( (*p1)->symid - (*p2)->symid );
01627 }
01628
01629 static int comp_f90_const (
01630 struct Cif_f90_const **p1,
01631 struct Cif_f90_const **p2)
01632 {
01633 return ( (*p1)->symid - (*p2)->symid );
01634 }
01635
01636 static int comp_f90_entry (
01637 struct Cif_f90_entry **p1,
01638 struct Cif_f90_entry **p2)
01639 {
01640 return ( (*p1)->symid - (*p2)->symid );
01641 }
01642
01643
01644 static int comp_f90_label (
01645 struct Cif_f90_label **p1,
01646 struct Cif_f90_label **p2)
01647 {
01648 return ( (*p1)->symid - (*p2)->symid );
01649 }
01650
01651 static int comp_f90_loop (
01652 struct Cif_f90_loop **p1,
01653 struct Cif_f90_loop **p2)
01654 {
01655 register int ret;
01656
01657 if ((ret = ( (*p1)->sfid - (*p2)->sfid )) != 0)
01658 return (ret);
01659 else if ((ret = ( (*p1)->strline - (*p2)->strline )) != 0)
01660 return (ret);
01661 else
01662 return ( (*p1)->strcpos - (*p2)->strcpos );
01663 }
01664
01665 static int comp_f90_namelist (
01666 struct Cif_f90_namelist **p1,
01667 struct Cif_f90_namelist **p2)
01668 {
01669 return ( (*p1)->symid - (*p2)->symid );
01670 }
01671
01672 static int comp_f90_object (
01673 struct Cif_f90_object **p1,
01674 struct Cif_f90_object **p2)
01675 {
01676 return ( (*p1)->symid - (*p2)->symid );
01677 }
01678
01679 static int comp_f90_derived_type (
01680 struct Cif_f90_derived_type **p1,
01681 struct Cif_f90_derived_type **p2)
01682 {
01683 return ( (*p1)->symid - (*p2)->symid );
01684 }
01685
01686 static int comp_f90_begin_scope (
01687 struct Cif_f90_begin_scope **p1,
01688 struct Cif_f90_begin_scope **p2)
01689 {
01690 return ( (*p1)->scopeid - (*p2)->scopeid );
01691 }
01692
01693 static int comp_f90_end_scope (
01694 struct Cif_f90_end_scope **p1,
01695 struct Cif_f90_end_scope **p2)
01696 {
01697 return ( (*p1)->scopeid - (*p2)->scopeid );
01698 }
01699
01700 static int comp_f90_scope_info (
01701 struct Cif_f90_scope_info **p1,
01702 struct Cif_f90_scope_info **p2)
01703 {
01704 return ( (*p1)->scopeid - (*p2)->scopeid );
01705 }
01706
01707 static int comp_f90_int_block (
01708 struct Cif_f90_int_block **p1,
01709 struct Cif_f90_int_block **p2)
01710 {
01711 return ( (*p1)->intid - (*p2)->intid );
01712 }
01713
01714 static int comp_f90_use_module (
01715 struct Cif_f90_use_module **p1,
01716 struct Cif_f90_use_module **p2)
01717 {
01718 return ( (*p1)->modid - (*p2)->modid );
01719 }
01720
01721 static int comp_f90_rename (
01722 struct Cif_f90_rename **p1,
01723 struct Cif_f90_rename **p2)
01724 {
01725 return ( (*p1)->modid - (*p2)->modid );
01726 }
01727
01728 static int comp_f90_vectorization (
01729 struct Cif_f90_vectorization **p1,
01730 struct Cif_f90_vectorization **p2)
01731 {
01732 return ( (*p1)->rectype - (*p2)->rectype );
01733 }
01734 #endif
01735
01736
01737 static int comp_cdir (
01738 struct Cif_cdir **p1,
01739 struct Cif_cdir **p2)
01740 {
01741 register int ret;
01742
01743 if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01744 return (ret);
01745 else if ((ret = ( (*p1)->line - (*p2)->line )) != 0)
01746 return (ret);
01747 else
01748 return ( (*p1)->cpos - (*p2)->cpos );
01749 }
01750
01751 static int comp_cdir_doshared (
01752 struct Cif_cdir_doshared **p1,
01753 struct Cif_cdir_doshared **p2)
01754 {
01755 register int ret;
01756
01757 if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01758 return (ret);
01759 else if ((ret = ( (*p1)->line - (*p2)->line )) != 0)
01760 return (ret);
01761 else
01762 return ( (*p1)->cpos - (*p2)->cpos );
01763 }
01764
01765
01766 static int comp_geometry (
01767 struct Cif_geometry **p1,
01768 struct Cif_geometry **p2)
01769 {
01770 return ( (*p1)->geomid - (*p2)->geomid );
01771 }
01772
01773
01774 static int comp_continuation (
01775 struct Cif_continuation **p1,
01776 struct Cif_continuation **p2)
01777 {
01778 register int ret;
01779
01780 if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01781 return (ret);
01782 else if ((ret = ( (*p1)->line - (*p2)->line )) != 0)
01783 return (ret);
01784 else
01785 return ( (*p1)->cpos - (*p2)->cpos );
01786 }
01787
01788 static int comp_transform (
01789 struct Cif_transform **p1,
01790 struct Cif_transform **p2)
01791 {
01792 register int ret;
01793
01794 if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01795 return (ret);
01796 else
01797 return ( (*p1)->line - (*p2)->line );
01798 }
01799
01800
01801 static int comp_c_tag (
01802 struct Cif_c_tag **p1,
01803 struct Cif_c_tag **p2)
01804 {
01805 return ( (*p1)->tagid - (*p2)->tagid );
01806 }
01807
01808 static int comp_c_message (
01809 struct Cif_c_message **p1,
01810 struct Cif_c_message **p2)
01811 {
01812 register int ret;
01813
01814 if ((ret = ( (*p1)->fline - (*p2)->fline )) != 0)
01815 return (ret);
01816 else
01817 return ( (*p1)->iline - (*p2)->iline );
01818 }
01819
01820 static int comp_c_const (
01821 struct Cif_c_const **p1,
01822 struct Cif_c_const **p2)
01823 {
01824 return ( (*p1)->symid - (*p2)->symid );
01825 }
01826
01827 static int comp_c_entry (
01828 struct Cif_c_entry **p1,
01829 struct Cif_c_entry **p2)
01830 {
01831 return ( (*p1)->symid - (*p2)->symid );
01832 }
01833
01834 static int comp_c_object (
01835 struct Cif_c_object **p1,
01836 struct Cif_c_object **p2)
01837 {
01838 return ( (*p1)->symid - (*p2)->symid );
01839 }
01840
01841 static int comp_c_lint_directive (
01842 struct Cif_c_lint_directive **p1,
01843 struct Cif_c_lint_directive **p2)
01844 {
01845 return ( (*p1)->objid - (*p2)->objid );
01846 }
01847
01848 static int comp_c_macro_def (
01849 struct Cif_c_macro_def **p1,
01850 struct Cif_c_macro_def **p2)
01851 {
01852 return ( (*p1)->symid - (*p2)->symid );
01853 }
01854
01855 static int comp_c_macro_undef (
01856 struct Cif_c_macro_undef **p1,
01857 struct Cif_c_macro_undef **p2)
01858 {
01859 return ( (*p1)->symid - (*p2)->symid );
01860 }
01861
01862
01863 static int comp_c_macro_usage (
01864 struct Cif_c_macro_usage **p1,
01865 struct Cif_c_macro_usage **p2)
01866 {
01867 return ( (*p1)->symid - (*p2)->symid );
01868 }
01869
01870 static int comp_c_entry_end (
01871 struct Cif_c_entry_end **p1,
01872 struct Cif_c_entry_end **p2)
01873 {
01874 return ( (*p1)->symid - (*p2)->symid );
01875 }
01876
01877 static int comp_cc_type (
01878 struct Cif_cc_type **p1,
01879 struct Cif_cc_type **p2)
01880 {
01881 return ( (*p1)->typeId - (*p2)->typeId );
01882 }
01883
01884 static int comp_cc_entry (
01885 struct Cif_cc_entry **p1,
01886 struct Cif_cc_entry **p2)
01887 {
01888 return ( (*p1)->symid - (*p2)->symid );
01889 }
01890
01891 static int comp_cc_obj (
01892 struct Cif_cc_obj **p1,
01893 struct Cif_cc_obj **p2)
01894 {
01895 return ( (*p1)->symid - (*p2)->symid );
01896 }
01897
01898 static int comp_cc_subtype (
01899 struct Cif_cc_subtype **p1,
01900 struct Cif_cc_subtype **p2)
01901 {
01902 return ( (*p1)->symid - (*p2)->symid );
01903 }
01904
01905 static int comp_cc_enum (
01906 struct Cif_cc_enum **p1,
01907 struct Cif_cc_enum **p2)
01908 {
01909 return ( (*p1)->symid - (*p2)->symid );
01910 }
01911
01912 static int comp_cc_expr (
01913 struct Cif_cc_expr **p1,
01914 struct Cif_cc_expr **p2)
01915 {
01916 return ( (*p1)->exprid - (*p2)->exprid );
01917 }
01918
01919 static int comp_src_pos (
01920 struct Cif_src_pos **p1,
01921 struct Cif_src_pos **p2)
01922 {
01923 register int ret;
01924
01925 if ((ret = ( (*p1)->kind - (*p2)->kind )) != 0)
01926 return (ret);
01927 else if ((ret = ( (*p1)->fid - (*p2)->fid )) != 0)
01928 return (ret);
01929 else
01930 return ( (*p1)->symid - (*p2)->symid );
01931 }
01932
01933 static int comp_orig_cmd (
01934 struct Cif_orig_cmd **p1,
01935 struct Cif_orig_cmd **p2)
01936 {
01937 return ( (*p1)->nlen - (*p2)->nlen );
01938 }
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948 static int copy_units (
01949 void)
01950 {
01951
01952 int recno=0;
01953 int i, rtype;
01954 long sid;
01955 struct Cif_generic *cifp;
01956
01957 if (tmpfd != -1) {
01958 (void) Cif_Close (tmpfd, CIF_MEM_KEEP);
01959 tmpfd = -1;
01960 }
01961 if ((tmpfd = Cif_Open (tfile, "r", NULL, CIF_VERSION)) < 0) {
01962 (void) fprintf (stderr, "libcif: cannot open temporary file %s - %s\n",
01963 tfile, Cif_Errstring(tmpfd));
01964 return (tmpfd);
01965 }
01966 (void) Cif_Memmode (tmpfd, CIF_MEM_MANAGED);
01967 #ifndef DEBUG
01968
01969 (void) unlink (tfile);
01970 #endif
01971
01972 while ((rtype = Cif_Getrecord (tmpfd, &cifp)) >= 0) {
01973
01974 recno++;
01975 if (rtype == CIF_UNIT) {
01976 for (i = 0; i < CIF_MAXRECORD; i++)
01977 if (unit_record[i]) patbl[i].next = 0;
01978 addstruct (cifp);
01979 }
01980
01981 else if (rtype == CIF_ENDUNIT) {
01982 addstruct (cifp);
01983 if (Remap_id == True)
01984 remap_symbols ();
01985 sid = get_max_sid ();
01986 cifp = *(patbl[CIF_UNITDIR].aptr);
01987 CIFUDIR(cifp)->maxsid = sid;
01988 cifp = *(patbl[CIF_FILEDIR].aptr);
01989 if (sid > (int) CIFFDIR(cifp)->maxsid)
01990 CIFFDIR(cifp)->maxsid = sid;
01991 if ((i = write_unit (outfd, canpos, False)) < 0)
01992 return (i);
01993 (void) Cif_Release (tmpfd, CIF_MEM_KEEP);
01994 }
01995
01996 else
01997 addstruct (cifp);
01998 }
01999 if (rtype != CIF_EOF)
02000 OUT_ERROR ("reading", tmpfd, rtype);
02001
02002 return (0);
02003 }
02004
02005
02006
02007
02008
02009
02010
02011 static void makeudir(
02012 void)
02013 {
02014
02015 int i, n;
02016 static struct Cif_unitdir *udp = (struct Cif_unitdir *) NULL;
02017 static struct Cif_urectbl *urp = (struct Cif_urectbl *) NULL;
02018
02019 if (udp == (struct Cif_unitdir *) NULL) {
02020 if ((udp = (struct Cif_unitdir *) malloc (sizeof(struct Cif_unitdir))) ==
02021 NULL) MEM_ERROR;
02022 }
02023 (void) memset ((char *)udp, '\0', sizeof(struct Cif_unitdir));
02024 udp->rectype = CIF_UNITDIR;
02025 udp->nsections = CIF_MAXRECORD;
02026 n = sizeof(struct Cif_urectbl) * CIF_MAXRECORD;
02027 if (urp == (struct Cif_urectbl *) NULL) {
02028 if ((urp = udp->ur = (struct Cif_urectbl *) malloc (n)) == NULL)
02029 MEM_ERROR;
02030 }
02031 else {
02032 udp->ur = urp;
02033 }
02034 (void) memset ((char *)urp, '\0', n);
02035 for (i = 0; i < CIF_MAXRECORD; i++) {
02036 if (unit_record[i])
02037 urp[i].rectype = i;
02038 }
02039 addstruct (CIFGEN(udp));
02040 }
02041
02042
02043
02044
02045
02046
02047
02048 static int comp_use (
02049 struct Cif_use *u1,
02050 struct Cif_use *u2)
02051 {
02052 register int ret;
02053
02054 if ((ret = ( u1->fid - u2->fid )) != 0)
02055 return (ret);
02056 else if ((ret = ( u1->line - u2->line )) != 0)
02057 return (ret);
02058 else
02059 return ( u1->cpos - u2->cpos );
02060 }
02061
02062 static int merge_usages (
02063 void)
02064 {
02065 int i, j, n;
02066 int numu;
02067 int nuses;
02068 int si;
02069 int ti;
02070 struct Cif_usage **up;
02071 struct Cif_use *use;
02072 struct Cif_use *use1, *use2;
02073
02074 struct Cif_generic *cifp1;
02075 struct Cif_urectbl *urp;
02076
02077
02078
02079 numu = patbl[CIF_USAGE].next;
02080 up = (struct Cif_usage **)patbl[CIF_USAGE].aptr;
02081
02082 if (numu > global_nuses_allocated) {
02083 if (global_nuses == (int *) NULL)
02084 global_nuses = (int *) malloc(numu * sizeof(int));
02085 else {
02086 global_nuses = (int *) realloc(global_nuses,
02087 numu * sizeof(int));
02088 }
02089 global_nuses_allocated = numu;
02090 }
02091 memset((char *) global_nuses, '\0', numu * sizeof(int));
02092
02093 for (si = 0; si < numu-1; si++) {
02094 if ( up[si]->symid == up[si+1]->symid) break;
02095 global_nuses[si] = 1;
02096 }
02097
02098 if (si < numu - 1) {
02099
02100
02101
02102 si = ti = 0;
02103 while (si < numu) {
02104 if (si == numu-1 ||
02105 up[si]->symid != up[si+1]->symid ||
02106 up[si]->nmembs != up[si+1]->nmembs) {
02107
02108
02109 global_nuses[ti] = 1;
02110 *up[ti++] = *up[si++];
02111
02112 }
02113 else {
02114
02115 nuses = up[si]->nuses;;
02116 for (n = 1; si+n < numu && up[si+n]->symid == up[si]->symid; n++) {
02117
02118
02119
02120
02121
02122
02123 if (up[si]->nmembs != up[si+n]->nmembs)
02124 break;
02125
02126 for (i = 0; i < (int) up[si]->nmembs; i++) {
02127 if (up[si]->membs[i] != up[si+n]->membs[i])
02128 break;
02129 }
02130
02131
02132
02133
02134
02135
02136 if (i < (int) up[si]->nmembs)
02137 break;
02138
02139 nuses += up[si+n]->nuses;
02140 }
02141
02142
02143
02144 if ((use = (struct Cif_use *) malloc (sizeof(struct Cif_use)*nuses))
02145 == NULL) MEM_ERROR;
02146
02147 use1 = use;
02148 for (i = 0; i < n; i++) {
02149 use2 = up[si+i]->use;
02150 for (j = 0; j < (int) up[si+i]->nuses; j++)
02151 (use1++)[0] = (use2++)[0];
02152 }
02153
02154
02155
02156 (void) qsort ((char *)use,
02157 nuses, sizeof(struct Cif_use),
02158 (int(*)()) comp_use);
02159
02160
02161
02162
02163
02164
02165
02166 up[ti]->nuses = nuses;
02167 up[ti]->symid = up[si]->symid;
02168 up[ti]->nmembs = up[si]->nmembs;
02169 up[ti]->membs = up[si]->membs;
02170 up[ti]->use = use;
02171
02172 global_nuses[ti] = nuses;
02173
02174 si += n;
02175 ti++;
02176 }
02177 }
02178 patbl[CIF_USAGE].next = ti;
02179
02180
02181
02182 cifp1 = *(patbl[CIF_UNITDIR].aptr);
02183 urp = CIFUDIR(cifp1)->ur;
02184 urp[CIF_USAGE].nrecords = ti;
02185 }
02186
02187 return (0);
02188 }
02189
02190
02191
02192
02193
02194
02195
02196 #define HRECORDS 15
02197 static const int horder[HRECORDS] = {
02198 CIF_CIFHDR,
02199 CIF_FILEDIR,
02200 CIF_SRCFILE,
02201 CIF_FILE,
02202 CIF_INCLUDE,
02203 CIF_SRC_POS,
02204 CIF_ORIG_CMD,
02205 CIF_EDOPTS,
02206 CIF_MACH_CHAR,
02207 CIF_MISC_OPTS,
02208 CIF_F90_MISC_OPTS,
02209 CIF_OPT_OPTS,
02210 CIF_F90_OPT_OPTS,
02211 CIF_C_OPTS,
02212 CIF_SUMMARY
02213 };
02214
02215 static int write_header (
02216 void)
02217 {
02218
02219 int i, j, rtype;
02220 long status;
02221 struct Cif_generic *sp;
02222
02223
02224
02225 if (patbl[CIF_FILE].next > 1)
02226 (void) qsort ((char *)patbl[CIF_FILE].aptr, patbl[CIF_FILE].next,
02227 sizeof(struct Cif_generic *), qcompare[CIF_FILE]);
02228
02229 sp = *(patbl[CIF_CIFHDR].aptr);
02230 CIFHDR(sp)->cont_id = 1;
02231 CIFHDR(sp)->srcfid = get_srcfid();
02232
02233
02234
02235
02236
02237
02238 CIFHDR(sp)->bintype = CIF_FORM_CIFCONV;
02239
02240 if (canpos == True)
02241 CIFHDR(sp)->posinfo = 1;
02242 for (i = 0; i < HRECORDS; i++) {
02243 rtype = horder[i];
02244 if (rtype == CIF_FILEDIR && canpos == True) {
02245 if ((fdirpos = Cif_Getpos (outfd)) < 0)
02246 OUT_ERROR ("positioning", outfd, fdirpos);
02247 }
02248 for (j = 0; j < patbl[rtype].next; j++) {
02249 sp = (patbl[rtype].aptr)[j];
02250 if ((status = Cif_Putrecord(outfd, sp)) < 0)
02251 OUT_ERROR ("writing", outfd, status);
02252 }
02253 }
02254
02255 return (0);
02256
02257 }
02258
02259 static int get_srcfid (
02260 void)
02261 {
02262 struct Cif_generic *sp, **spp;
02263 int rcnt, srcfid;
02264
02265 srcfid = 0;
02266 spp = patbl[CIF_SRCFILE].aptr;
02267 for (rcnt = 0; rcnt < patbl[CIF_SRCFILE].next; rcnt++) {
02268 sp = *spp++;
02269 srcfid = CIFSRC(sp)->fid;
02270 }
02271 return(srcfid);
02272 }
02273
02274
02275
02276
02277
02278
02279
02280
02281 #define URECORDS 54
02282 static const int uorder[URECORDS] = {
02283 CIF_UNIT,
02284 CIF_UNITDIR,
02285 CIF_ENTRY,
02286 CIF_COMBLK,
02287 CIF_OBJECT,
02288 CIF_CONST,
02289 CIF_NAMELIST,
02290 CIF_C_ENTRY,
02291 CIF_C_OBJECT,
02292 CIF_C_LINT_DIRECTIVE,
02293 CIF_C_MACRO_DEF,
02294 CIF_C_MACRO_UNDEF,
02295 CIF_C_MACRO_USAGE,
02296 CIF_C_ENTRY_END,
02297 CIF_C_TAG,
02298 CIF_C_CONST,
02299 CIF_LABEL,
02300 CIF_CALLSITE,
02301 CIF_USAGE,
02302 CIF_STMT_TYPE,
02303 CIF_LOOP,
02304 CIF_MESSAGE,
02305 CIF_ND_MSG,
02306 CIF_CDIR,
02307 CIF_CDIR_DOSHARED,
02308 CIF_GEOMETRY,
02309 CIF_CONTINUATION,
02310 CIF_TRANSFORM,
02311 CIF_F90_CALLSITE,
02312 CIF_F90_COMBLK,
02313 CIF_F90_CONST,
02314 CIF_F90_ENTRY,
02315 CIF_F90_LOOP,
02316 CIF_F90_DERIVED_TYPE,
02317 CIF_F90_LABEL,
02318 CIF_F90_NAMELIST,
02319 CIF_F90_OBJECT,
02320 CIF_F90_BEGIN_SCOPE,
02321 CIF_F90_END_SCOPE,
02322 CIF_F90_SCOPE_INFO,
02323 CIF_F90_USE_MODULE,
02324 CIF_F90_RENAME,
02325 CIF_F90_INT_BLOCK,
02326 CIF_F90_VECTORIZATION,
02327 CIF_CC_TYPE,
02328 CIF_CC_ENTRY,
02329 CIF_CC_OBJ,
02330 CIF_CC_SUBTYPE,
02331 CIF_CC_ENUM,
02332 CIF_CC_EXPR,
02333 CIF_BE_NODE,
02334 CIF_BE_FID,
02335 CIF_C_MESSAGE,
02336 CIF_ENDUNIT
02337 };
02338
02339 static int write_unit (
02340 int fd,
02341 enum Boolean markpos,
02342 enum Boolean merge_use)
02343 {
02344
02345 int i, j, rtype;
02346 long status, savepos;
02347 char *name;
02348 struct Cif_generic *sp;
02349 struct Cif_urectbl *urp;
02350 struct Cif_unittbl *utp;
02351 int numu;
02352 struct Cif_usage **up;
02353 int si;
02354 struct Cif_generic **spp;
02355
02356
02357
02358 if (markpos) {
02359 name = CIFUNIT(*patbl[CIF_UNIT].aptr)->name;
02360 utp = CIFFDIR(*patbl[CIF_FILEDIR].aptr)->ut;
02361 i = CIFFDIR(*patbl[CIF_FILEDIR].aptr)->nunits;
02362 for (j = 0; j < i; j++)
02363 if (strcmp(name,utp[j].name) == 0 &&
02364 utp[j].unitpos == 0) break;
02365
02366 if ((status = utp[j].unitpos = Cif_Getpos(fd)) < 0)
02367 OUT_ERROR ("positioning", fd, status);
02368 }
02369
02370
02371
02372 for (rtype = 0; rtype < CIF_MAXRECORD; rtype++) {
02373 if (unit_record[rtype] && patbl[rtype].next > 1 &&
02374 qcompare[rtype] != 0)
02375 (void) qsort ((char *)patbl[rtype].aptr, patbl[rtype].next,
02376 sizeof(struct Cif_generic *), qcompare[rtype]);
02377 }
02378
02379
02380
02381
02382
02383 if (lang == CIF_LG_C || lang == CIF_LG_CC) {
02384 spp = patbl[CIF_STMT_TYPE].aptr;
02385 for (i = 0; i < patbl[CIF_STMT_TYPE].next; i++) {
02386 CIFSTMT(*spp++)->rectype = CIF_STMT_TYPE;
02387 }
02388 }
02389
02390
02391
02392 if (merge_use)
02393 (void) merge_usages();
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405 sp = *(patbl[CIF_UNITDIR].aptr);
02406 urp = CIFUDIR(sp)->ur;
02407 for (i = 0; i < URECORDS; i++) {
02408 rtype = uorder[i];
02409 if (patbl[rtype].next > 0) {
02410 if (markpos) {
02411 if ((status = Cif_Getpos (fd)) < 0)
02412 OUT_ERROR ("positioning", fd, status);
02413 }
02414 else
02415 status = 0;
02416 urp[rtype].recpos = status;
02417 for (j = 0; j < patbl[rtype].next; j++) {
02418 if ((status = Cif_Putrecord (fd, (patbl[rtype].aptr)[j])) < 0)
02419 OUT_ERROR ("writing", fd, status);
02420 }
02421 }
02422 }
02423
02424
02425
02426 if (merge_use &&
02427 global_nuses != (int *) NULL) {
02428 numu = patbl[CIF_USAGE].next;
02429 up = (struct Cif_usage **)patbl[CIF_USAGE].aptr;
02430 for (si = 0; si < numu; si++) {
02431 if (global_nuses[si] > 1)
02432 free((char *) up[si]->use);
02433 }
02434 }
02435
02436 if (markpos) {
02437 if ((savepos = Cif_Getpos (fd)) < 0)
02438 OUT_ERROR ("positioning", fd, status);
02439 if ((status = Cif_Setpos (fd, urp[CIF_UNITDIR].recpos)) < 0)
02440 OUT_ERROR ("positioning", fd, status);
02441 if ((status = Cif_Putrecord (fd, *(patbl[CIF_UNITDIR].aptr))) < 0)
02442 OUT_ERROR ("writing", fd, status);
02443 if ((status = Cif_Setpos (fd, savepos)) < 0)
02444 OUT_ERROR ("positioning", fd, status);
02445 }
02446
02447 return (0);
02448 }
02449
02450 #ifdef DEBUG
02451
02452
02453
02454
02455 void dump_patbl (
02456 FILE *fd)
02457 {
02458 int i, j;
02459 struct Cif_generic **rptr;
02460
02461 for (i = 0; i < CIF_MAXRECORD; i++) {
02462 if (patbl[i].psize != 0) {
02463 (void) fprintf (fd, "\npatbl[%d] aptr= %d psize= %d next= %d\n",
02464 i, patbl[i].aptr, patbl[i].psize, patbl[i].next);
02465 rptr = patbl[i].aptr;
02466 for (j = 0; j < patbl[i].next; j++) {
02467 (void) fprintf (fd, " item %4d *aptr= %d rtype= %d\n",
02468 j, rptr, (*rptr)->rectype);
02469 rptr++;
02470 }
02471 }
02472 }
02473
02474 }
02475
02476
02477
02478
02479
02480
02481 static int valid_patbl (
02482 void)
02483 {
02484 int i, j;
02485 struct Cif_generic **rptr;
02486
02487 for (i = 0; i < CIF_MAXRECORD; i++) {
02488 if (patbl[i].psize != 0) {
02489 rptr = patbl[i].aptr;
02490 for (j = 0; j < patbl[i].next; j++) {
02491 if ((*rptr)->rectype != i)
02492 return (0);
02493 rptr++;
02494 }
02495 }
02496 }
02497 return (1);
02498 }
02499 #endif
02500
02501
02502
02503
02504
02505 static void init_id (
02506 struct Id_tbl *idtp)
02507 {
02508 idtp->cur = 1;
02509 (idtp->tbl)[0] = 0;
02510 }
02511
02512
02513
02514
02515
02516
02517 static void add_id (
02518 struct Id_tbl *idtp,
02519 long id)
02520 {
02521
02522 if (idtp->cur >= idtp->max) {
02523 idtp->max += ID_BUMP;
02524 if ((idtp->tbl = (long *) realloc ((char *)idtp->tbl,
02525 sizeof(long)*idtp->max)) == NULL)
02526 MEM_ERROR;
02527 }
02528 idtp->tbl[idtp->cur++] = id;
02529 }
02530
02531
02532
02533
02534
02535 static int comp_ids (
02536 long *id1,
02537 long *id2)
02538 {
02539 return (*id1 - *id2);
02540 }
02541
02542
02543
02544
02545
02546
02547
02548
02549 static long get_id (
02550 struct Id_tbl *idtp,
02551 long id)
02552 {
02553
02554 int lower = 1;
02555 int upper = idtp->cur-1;
02556 int mid;
02557
02558 if (id == 0)
02559 return (0);
02560
02561
02562 mid = (upper + lower) / 2;
02563
02564 while (lower < upper) {
02565
02566 if (id < (idtp->tbl)[mid])
02567 upper = mid - 1;
02568 else if (id > (idtp->tbl)[mid])
02569 lower = mid + 1;
02570 else
02571 break;
02572
02573 mid = (upper + lower) / 2;
02574 }
02575
02576
02577
02578
02579
02580
02581
02582 if ((idtp->tbl)[mid] != id) {
02583
02584 if (global_error_report == True) {
02585 (void) fprintf(stderr,
02586 "libcif : Invalid id in cif %s.\nClosest match to %d is %d, so using 0 in output record.\n",
02587 global_outfile, id, (idtp->tbl)[mid]);
02588 }
02589 mid = 0;
02590 }
02591
02592 return (mid);
02593
02594 }
02595
02596
02597
02598
02599
02600
02601
02602
02603 static void remap_symbols (
02604 void)
02605 {
02606
02607 struct Cif_generic *sp, **spp;
02608 int rcnt, i, j;
02609
02610 init_id (&sid);
02611
02612
02613
02614
02615
02616 spp = patbl[CIF_COMBLK].aptr;
02617 for (rcnt = 0; rcnt < patbl[CIF_COMBLK].next; rcnt++)
02618 add_id (&sid, CIFCB(*spp++)->symid);
02619
02620 spp = patbl[CIF_CONST].aptr;
02621 for (rcnt = 0; rcnt < patbl[CIF_CONST].next; rcnt++)
02622 add_id (&sid, CIFCON(*spp++)->symid);
02623
02624 spp = patbl[CIF_ENTRY].aptr;
02625 for (rcnt = 0; rcnt < patbl[CIF_ENTRY].next; rcnt++)
02626 add_id (&sid, CIFENTRY(*spp++)->symid);
02627
02628 spp = patbl[CIF_LABEL].aptr;
02629 for (rcnt = 0; rcnt < patbl[CIF_LABEL].next; rcnt++)
02630 add_id (&sid, CIFLABEL(*spp++)->symid);
02631
02632 spp = patbl[CIF_NAMELIST].aptr;
02633 for (rcnt = 0; rcnt < patbl[CIF_NAMELIST].next; rcnt++)
02634 add_id (&sid, CIFNL(*spp++)->symid);
02635
02636 spp = patbl[CIF_OBJECT].aptr;
02637 for (rcnt = 0; rcnt < patbl[CIF_OBJECT].next; rcnt++)
02638 add_id (&sid, CIFOBJ(*spp++)->symid);
02639
02640 spp = patbl[CIF_C_CONST].aptr;
02641 for (rcnt = 0; rcnt < patbl[CIF_C_CONST].next; rcnt++)
02642 add_id (&sid, CIFCCON(*spp++)->symid);
02643
02644 spp = patbl[CIF_C_ENTRY].aptr;
02645 for (rcnt = 0; rcnt < patbl[CIF_C_ENTRY].next; rcnt++)
02646 add_id (&sid, CIFCENTRY(*spp++)->symid);
02647
02648 spp = patbl[CIF_C_OBJECT].aptr;
02649 for (rcnt = 0; rcnt < patbl[CIF_C_OBJECT].next; rcnt++)
02650 add_id (&sid, CIFCOBJ(*spp++)->symid);
02651
02652 spp = patbl[CIF_C_LINT_DIRECTIVE].aptr;
02653 for (rcnt = 0; rcnt < patbl[CIF_C_LINT_DIRECTIVE].next; rcnt++)
02654 add_id (&sid, CIFCLDIR(*spp++)->objid);
02655
02656 spp = patbl[CIF_C_MACRO_DEF].aptr;
02657 for (rcnt = 0; rcnt < patbl[CIF_C_MACRO_DEF].next; rcnt++)
02658 add_id (&sid, CIFCMDEF(*spp++)->symid);
02659
02660 spp = patbl[CIF_C_TAG].aptr;
02661 for (rcnt = 0; rcnt < patbl[CIF_C_TAG].next; rcnt++)
02662 add_id (&sid, CIFCTAG(*spp++)->tagid);
02663
02664
02665
02666 spp = patbl[CIF_CC_TYPE].aptr;
02667 for (rcnt = 0; rcnt < patbl[CIF_CC_TYPE].next; rcnt++) {
02668 sp = *spp++;
02669 add_id (&sid, CIFCCTYPE(sp)->symid);
02670 j = CIFCCTYPE(sp)->nmem;
02671 for (i = 0; i < j; i++ ) {
02672 add_id (&sid, CIFCCTYPE(sp)->mem[i]);
02673 }
02674 }
02675
02676 spp = patbl[CIF_CC_ENTRY].aptr;
02677 for (rcnt = 0; rcnt < patbl[CIF_CC_ENTRY].next; rcnt++) {
02678 sp = *spp++;
02679 add_id (&sid, CIFCCENT(sp)->symid);
02680 add_id (&sid, CIFCCENT(sp)->fsymid);
02681 j = CIFCCENT(sp)->nparam;
02682 for (i = 0; i < j; i++ ) {
02683 add_id (&sid, CIFCCENT(sp)->param[i]);
02684 }
02685 }
02686
02687 spp = patbl[CIF_CC_OBJ].aptr;
02688 for (rcnt = 0; rcnt < patbl[CIF_CC_OBJ].next; rcnt++)
02689 add_id (&sid, CIFCCOBJ(*spp++)->symid);
02690
02691 spp = patbl[CIF_CC_SUBTYPE].aptr;
02692 for (rcnt = 0; rcnt < patbl[CIF_CC_SUBTYPE].next; rcnt++)
02693 add_id (&sid, CIFCCSUB(*spp++)->symid);
02694
02695 spp = patbl[CIF_CC_ENUM].aptr;
02696 for (rcnt = 0; rcnt < patbl[CIF_CC_ENUM].next; rcnt++)
02697 add_id (&sid, CIFCCENUM(*spp++)->symid);
02698
02699
02700
02701 spp = patbl[CIF_F90_COMBLK].aptr;
02702 for (rcnt = 0; rcnt < patbl[CIF_F90_COMBLK].next; rcnt++)
02703 add_id (&sid, CIFF90CB(*spp++)->symid);
02704
02705 spp = patbl[CIF_F90_CONST].aptr;
02706 for (rcnt = 0; rcnt < patbl[CIF_F90_CONST].next; rcnt++)
02707 add_id (&sid, CIFF90CON(*spp++)->symid);
02708
02709 spp = patbl[CIF_F90_ENTRY].aptr;
02710 for (rcnt = 0; rcnt < patbl[CIF_F90_ENTRY].next; rcnt++) {
02711 add_id (&sid, CIFF90ENTRY(*spp++)->symid);
02712 }
02713
02714 spp = patbl[CIF_F90_LABEL].aptr;
02715 for (rcnt = 0; rcnt < patbl[CIF_F90_LABEL].next; rcnt++)
02716 add_id (&sid, CIFF90LABEL(*spp++)->symid);
02717
02718 spp = patbl[CIF_F90_NAMELIST].aptr;
02719 for (rcnt = 0; rcnt < patbl[CIF_F90_NAMELIST].next; rcnt++)
02720 add_id (&sid, CIFF90NL(*spp++)->symid);
02721
02722 spp = patbl[CIF_F90_OBJECT].aptr;
02723 for (rcnt = 0; rcnt < patbl[CIF_F90_OBJECT].next; rcnt++) {
02724
02725
02726
02727 add_id (&sid, CIFF90OBJ(*spp++)->symid);
02728 }
02729
02730 spp = patbl[CIF_F90_BEGIN_SCOPE].aptr;
02731 for (rcnt = 0; rcnt < patbl[CIF_F90_BEGIN_SCOPE].next; rcnt++) {
02732 add_id (&sid, CIFF90BS(*spp++)->scopeid);
02733
02734 }
02735
02736 spp = patbl[CIF_F90_INT_BLOCK].aptr;
02737 for (rcnt = 0; rcnt < patbl[CIF_F90_INT_BLOCK].next; rcnt++) {
02738 add_id (&sid, CIFF90IB(*spp)->intid);
02739 for (i = 0; i < (int) CIFF90IB(*spp)->numints; i++)
02740 add_id (&sid, CIFF90IB(*spp)->procids[i]);
02741 spp++;
02742 }
02743
02744 spp = patbl[CIF_F90_RENAME].aptr;
02745 for (rcnt = 0; rcnt < patbl[CIF_F90_RENAME].next; rcnt++) {
02746 add_id (&sid, CIFF90RN(*spp)->nameid);
02747 spp++;
02748 }
02749
02750 spp = patbl[CIF_GEOMETRY].aptr;
02751 for (rcnt = 0; rcnt < patbl[CIF_GEOMETRY].next; rcnt++)
02752 add_id (&sid, CIFGEOM(*spp++)->geomid);
02753
02754 spp = patbl[CIF_F90_DERIVED_TYPE].aptr;
02755 for (rcnt = 0; rcnt < patbl[CIF_F90_DERIVED_TYPE].next; rcnt++) {
02756 add_id (&sid, CIFF90DTYPE(*spp++)->symid);
02757 }
02758
02759
02760
02761
02762 (void) qsort ((char *)sid.tbl, sid.cur, sizeof(long), (int(*)()) comp_ids);
02763
02764 spp = patbl[CIF_CALLSITE].aptr;
02765 for (rcnt = 0; rcnt < patbl[CIF_CALLSITE].next; rcnt++) {
02766 sp = *spp++;
02767 CIFCS(sp)->entryid = get_id (&sid, CIFCS(sp)->entryid);
02768 #ifdef REMAP_FID
02769 CIFCS(sp)->fid = get_id (&fid, CIFCS(sp)->fid);
02770 #endif
02771 for (i = 0; i < (int) CIFCS(sp)->nargs; i++)
02772 CIFCS(sp)->argids[i] = get_id (&sid, CIFCS(sp)->argids[i]);
02773 }
02774
02775 spp = patbl[CIF_COMBLK].aptr;
02776 for (rcnt = 0; rcnt < patbl[CIF_COMBLK].next; rcnt++) {
02777 sp = *spp++;
02778 CIFCB(sp)->symid = get_id (&sid, CIFCB(sp)->symid);
02779 }
02780
02781 spp = patbl[CIF_CONST].aptr;
02782 for (rcnt = 0; rcnt < patbl[CIF_CONST].next; rcnt++) {
02783 sp = *spp++;
02784 CIFCON(sp)->symid = get_id (&sid, CIFCON(sp)->symid);
02785 }
02786
02787 spp = patbl[CIF_ENTRY].aptr;
02788 for (rcnt = 0; rcnt < patbl[CIF_ENTRY].next; rcnt++) {
02789 sp = *spp++;
02790 CIFENTRY(sp)->symid = get_id (&sid, CIFENTRY(sp)->symid);
02791 for (i = 0; i < (int) CIFENTRY(sp)->nargs; i++)
02792 CIFENTRY(sp)->argids[i] = get_id (&sid, CIFENTRY(sp)->argids[i]);
02793 }
02794
02795 spp = patbl[CIF_LABEL].aptr;
02796 for (rcnt = 0; rcnt < patbl[CIF_LABEL].next; rcnt++) {
02797 sp = *spp++;
02798 CIFLABEL(sp)->symid = get_id (&sid, CIFLABEL(sp)->symid);
02799 }
02800
02801 spp = patbl[CIF_LOOP].aptr;
02802 for (rcnt = 0; rcnt < patbl[CIF_LOOP].next; rcnt++) {
02803 sp = *spp++;
02804 #ifdef REMAP_FID
02805 CIFLOOP(sp)->sfid = get_id (&fid, CIFLOOP(sp)->sfid);
02806 CIFLOOP(sp)->efid = get_id (&fid, CIFLOOP(sp)->efid);
02807 #endif
02808 CIFLOOP(sp)->labelid = get_id (&sid, CIFLOOP(sp)->labelid);
02809 CIFLOOP(sp)->symid = get_id (&sid, CIFLOOP(sp)->symid);
02810 }
02811
02812 #ifdef REMAP_FID
02813 spp = patbl[CIF_MESSAGE].aptr;
02814 for (rcnt = 0; rcnt < patbl[CIF_MESSAGE].next; rcnt++) {
02815 sp = *spp++;
02816 CIFMSG(sp)->fid = get_id (&fid, CIFMSG(sp)->fid);
02817 CIFMSG(sp)->pfid = get_id (&fid, CIFMSG(sp)->pfid);
02818 }
02819 #endif
02820
02821 spp = patbl[CIF_NAMELIST].aptr;
02822 for (rcnt = 0; rcnt < patbl[CIF_NAMELIST].next; rcnt++) {
02823 sp = *spp++;
02824 CIFNL(sp)->symid = get_id (&sid, CIFNL(sp)->symid);
02825 for (i = 0; i < (int) CIFNL(sp)->nids; i++)
02826 CIFNL(sp)->ids[i] = get_id (&sid, CIFNL(sp)->ids[i]);
02827 }
02828
02829 spp = patbl[CIF_OBJECT].aptr;
02830 for (rcnt = 0; rcnt < patbl[CIF_OBJECT].next; rcnt++) {
02831 sp = *spp++;
02832 CIFOBJ(sp)->symid = get_id (&sid, CIFOBJ(sp)->symid);
02833 CIFOBJ(sp)->geomid = get_id (&sid, CIFOBJ(sp)->geomid);
02834 CIFOBJ(sp)->pointer = get_id (&sid, CIFOBJ(sp)->pointer);
02835 if (CIFOBJ(sp)->symclass == CIF_SC_COMMON || CIFOBJ(sp)->symclass ==
02836 CIF_SC_EQUIV)
02837 {
02838 CIFOBJ(sp)->storage = get_id (&sid, CIFOBJ(sp)->storage);
02839 }
02840 }
02841
02842 #ifdef REMAP_FID
02843 spp = patbl[CIF_STMT_TYPE].aptr;
02844 for (rcnt = 0; rcnt < patbl[CIF_STMT_TYPE].next; rcnt++) {
02845 sp = *spp++;
02846 CIFSTMT(sp)->fid = get_id (&fid, CIFSTMT(sp)->fid);
02847 if (CIFSTMT(sp)->efid > 0) {
02848 CIFSTMT(sp)->efid = get_id (&fid, CIFSTMT(sp)->efid);
02849 }
02850 }
02851
02852 spp = patbl[CIF_UNIT].aptr;
02853 for (rcnt = 0; rcnt < patbl[CIF_UNIT].next; rcnt++) {
02854 sp = *spp++;
02855 CIFUNIT(sp)->fid = get_id (&fid, CIFUNIT(sp)->fid);
02856 }
02857
02858 spp = patbl[CIF_ENDUNIT].aptr;
02859 for (rcnt = 0; rcnt < patbl[CIF_ENDUNIT].next; rcnt++) {
02860 sp = *spp++;
02861 CIFENDU(sp)->fid = get_id (&fid, CIFENDU(sp)->fid);
02862 }
02863 #endif
02864
02865 spp = patbl[CIF_USAGE].aptr;
02866 for (rcnt = 0; rcnt < patbl[CIF_USAGE].next; rcnt++) {
02867 struct Cif_use *use;
02868 sp = *spp++;
02869 CIFUSAGE(sp)->symid = get_id (&sid, CIFUSAGE(sp)->symid);
02870 for (i = 0; i < (int) CIFUSAGE(sp)->nmembs; i++) {
02871 CIFUSAGE(sp)->membs[i] = get_id (&sid, CIFUSAGE(sp)->membs[i]);
02872 }
02873 #ifdef REMAP_FID
02874 use = CIFUSAGE(sp)->use;
02875 for (i = 0; i < (int) CIFUSAGE(sp)->nuses; i++) {
02876 use->fid = get_id (&fid, use->fid);
02877 use++;
02878 }
02879 #endif
02880 }
02881
02882
02883
02884
02885 spp = patbl[CIF_CDIR].aptr;
02886 for (rcnt = 0; rcnt < patbl[CIF_CDIR].next; rcnt++) {
02887 sp = *spp++;
02888 #ifdef REMAP_FID
02889 CIFCDIR(sp)->fid = get_id (&fid, CIFCDIR(sp)->fid);
02890 #endif
02891 for (i = 0; i < (int) CIFCDIR(sp)->nids; i++) {
02892 CIFCDIR(sp)->ids[i] = get_id (&sid, CIFCDIR(sp)->ids[i]);
02893 }
02894 }
02895
02896 spp = patbl[CIF_CDIR_DOSHARED].aptr;
02897 for (rcnt = 0; rcnt < patbl[CIF_CDIR_DOSHARED].next; rcnt++) {
02898 sp = *spp++;
02899 #ifdef REMAP_FID
02900 CIFCDIRDO(sp)->fid = get_id (&fid, CIFCDIRDO(sp)->fid);
02901 CIFCDIRDO(sp)->mfid = get_id (&fid, CIFCDIRDO(sp)->mfid);
02902 #endif
02903 for (i = 0; i < (int) CIFCDIRDO(sp)->nids; i++) {
02904 CIFCDIRDO(sp)->ids[i] = get_id (&sid, CIFCDIRDO(sp)->ids[i]);
02905 }
02906 }
02907
02908
02909 spp = patbl[CIF_GEOMETRY].aptr;
02910 for (rcnt = 0; rcnt < patbl[CIF_GEOMETRY].next; rcnt++) {
02911 struct Cif_geometry_dim *dim;
02912 sp = *spp++;
02913 CIFGEOM(sp)->geomid = get_id (&sid, CIFGEOM(sp)->geomid);
02914 #ifdef REMAP_FID
02915 dim = CIFGEOM(sp)->dim;
02916 for (i = 0; i < (int) CIFGEOM(sp)->ndims; i++) {
02917 dim->wfid = get_id (&fid, dim->wfid);
02918 dim->bfid = get_id (&fid, dim->bfid);
02919 dim++;
02920 }
02921 #endif
02922 }
02923
02924 #ifdef REMAP_FID
02925 spp = patbl[CIF_CONTINUATION].aptr;
02926 for (rcnt = 0; rcnt < patbl[CIF_CONTINUATION].next; rcnt++) {
02927 sp = *spp++;
02928 CIFCONT(sp)->fid = get_id (&fid, CIFCONT(sp)->fid);
02929 }
02930
02931 spp = patbl[CIF_TRANSFORM].aptr;
02932 for (rcnt = 0; rcnt < patbl[CIF_TRANSFORM].next; rcnt++) {
02933 sp = *spp++;
02934 CIFTRAN(sp)->fid = get_id (&fid, CIFTRAN(sp)->fid);
02935 }
02936 #endif
02937
02938
02939 spp = patbl[CIF_F90_CALLSITE].aptr;
02940 for (rcnt = 0; rcnt < patbl[CIF_F90_CALLSITE].next; rcnt++) {
02941 sp = *spp++;
02942 CIFF90CS(sp)->entryid = get_id (&sid, CIFF90CS(sp)->entryid);
02943 #ifdef REMAP_FID
02944 CIFF90CS(sp)->fid = get_id (&fid, CIFF90CS(sp)->fid);
02945 #endif
02946 CIFF90CS(sp)->procid = get_id(&sid, CIFF90CS(sp)->procid);
02947 CIFF90CS(sp)->scopeid = get_id(&sid, CIFF90CS(sp)->scopeid);
02948 for (i = 0; i < (int) CIFF90CS(sp)->nargs; i++) {
02949 CIFF90CS(sp)->argids[i] = get_id (&sid, CIFF90CS(sp)->argids[i]);
02950
02951 for (j = 0; j < CIFF90CS(sp)->nmembs[i]; j++) {
02952
02953 CIFF90CS(sp)->membs[i][j] =
02954 get_id (&sid, CIFF90CS(sp)->membs[i][j]);
02955 }
02956 }
02957 }
02958
02959 spp = patbl[CIF_F90_COMBLK].aptr;
02960 for (rcnt = 0; rcnt < patbl[CIF_F90_COMBLK].next; rcnt++) {
02961 sp = *spp++;
02962 CIFF90CB(sp)->symid = get_id (&sid, CIFF90CB(sp)->symid);
02963 CIFF90CB(sp)->moduleid = get_id (&sid, CIFF90CB(sp)->moduleid);
02964 CIFF90CB(sp)->scopeid = get_id (&sid, CIFF90CB(sp)->scopeid);
02965 }
02966
02967 spp = patbl[CIF_F90_CONST].aptr;
02968 for (rcnt = 0; rcnt < patbl[CIF_F90_CONST].next; rcnt++) {
02969 sp = *spp++;
02970 CIFF90CON(sp)->symid = get_id (&sid, CIFF90CON(sp)->symid);
02971 #ifdef REMAP_FID
02972 CIFF90CON(sp)->fid = get_id (&fid, CIFF90CON(sp)->fid);
02973 #endif
02974 CIFF90CON(sp)->scopeid = get_id (&sid, CIFF90CON(sp)->scopeid);
02975 }
02976
02977 spp = patbl[CIF_F90_ENTRY].aptr;
02978 for (rcnt = 0; rcnt < patbl[CIF_F90_ENTRY].next; rcnt++) {
02979 sp = *spp++;
02980
02981 CIFF90ENTRY(sp)->symid = get_id (&sid, CIFF90ENTRY(sp)->symid);
02982 CIFF90ENTRY(sp)->scopeid = get_id (&sid, CIFF90ENTRY(sp)->scopeid);
02983 CIFF90ENTRY(sp)->moduleid = get_id (&sid, CIFF90ENTRY(sp)->moduleid);
02984 CIFF90ENTRY(sp)->resultid = get_id (&sid, CIFF90ENTRY(sp)->resultid);
02985 for (i = 0; i < (int) CIFF90ENTRY(sp)->nargs; i++)
02986 CIFF90ENTRY(sp)->argids[i] = get_id (&sid, CIFF90ENTRY(sp)->argids[i]);
02987 }
02988
02989 spp = patbl[CIF_F90_LABEL].aptr;
02990 for (rcnt = 0; rcnt < patbl[CIF_F90_LABEL].next; rcnt++) {
02991 sp = *spp++;
02992 CIFF90LABEL(sp)->symid = get_id (&sid, CIFF90LABEL(sp)->symid);
02993 CIFF90LABEL(sp)->scopeid = get_id (&sid, CIFF90LABEL(sp)->scopeid);
02994 }
02995
02996 spp = patbl[CIF_F90_LOOP].aptr;
02997 for (rcnt = 0; rcnt < patbl[CIF_F90_LOOP].next; rcnt++) {
02998 sp = *spp++;
02999 #ifdef REMAP_FID
03000 CIFF90LOOP(sp)->sfid = get_id (&fid, CIFF90LOOP(sp)->sfid);
03001 CIFF90LOOP(sp)->efid = get_id (&fid, CIFF90LOOP(sp)->efid);
03002 #endif
03003 CIFF90LOOP(sp)->labelid = get_id (&sid, CIFF90LOOP(sp)->labelid);
03004 CIFF90LOOP(sp)->symid = get_id (&sid, CIFF90LOOP(sp)->symid);
03005 CIFF90LOOP(sp)->scopeid = get_id (&sid, CIFF90LOOP(sp)->scopeid);
03006 CIFF90LOOP(sp)->nameid = get_id (&sid, CIFF90LOOP(sp)->nameid);
03007 }
03008
03009 spp = patbl[CIF_F90_NAMELIST].aptr;
03010 for (rcnt = 0; rcnt < patbl[CIF_F90_NAMELIST].next; rcnt++) {
03011 sp = *spp++;
03012 CIFF90NL(sp)->symid = get_id (&sid, CIFF90NL(sp)->symid);
03013 CIFF90NL(sp)->scopeid = get_id (&sid, CIFF90NL(sp)->scopeid);
03014 CIFF90NL(sp)->moduleid = get_id (&sid, CIFF90NL(sp)->moduleid);
03015 for (i = 0; i < (int) CIFF90NL(sp)->nids; i++)
03016 CIFF90NL(sp)->ids[i] = get_id (&sid, CIFF90NL(sp)->ids[i]);
03017 }
03018
03019 spp = patbl[CIF_F90_OBJECT].aptr;
03020 for (rcnt = 0; rcnt < patbl[CIF_F90_OBJECT].next; rcnt++) {
03021 sp = *spp++;
03022
03023 CIFF90OBJ(sp)->symid = get_id (&sid, CIFF90OBJ(sp)->symid);
03024 CIFF90OBJ(sp)->scopeid = get_id (&sid, CIFF90OBJ(sp)->scopeid);
03025
03026 if (CIFF90OBJ(sp)->symclass == CIF_F90_SC_COMMON ||
03027 CIFF90OBJ(sp)->symclass == CIF_F90_SC_MODULE ||
03028 CIFF90OBJ(sp)->symclass == CIF_F90_SC_EQUIV ||
03029 CIFF90OBJ(sp)->symclass == CIF_F90_SC_NAMED_CONST)
03030
03031 CIFF90OBJ(sp)->storageid =
03032 get_id (&sid, CIFF90OBJ(sp)->storageid);
03033
03034 CIFF90OBJ(sp)->geomid =
03035 get_id (&sid, CIFF90OBJ(sp)->geomid);
03036 CIFF90OBJ(sp)->pointerid =
03037 get_id (&sid, CIFF90OBJ(sp)->pointerid);
03038 }
03039
03040 spp = patbl[CIF_F90_DERIVED_TYPE].aptr;
03041 for (rcnt = 0; rcnt < patbl[CIF_F90_DERIVED_TYPE].next; rcnt++) {
03042 sp = *spp++;
03043 CIFF90DTYPE(sp)->symid = get_id (&sid, CIFF90DTYPE(sp)->symid);
03044 CIFF90DTYPE(sp)->scopeid = get_id (&sid, CIFF90DTYPE(sp)->scopeid);
03045 CIFF90DTYPE(sp)->moduleid = get_id (&sid, CIFF90DTYPE(sp)->moduleid);
03046 for (i = 0; i < (int) CIFF90DTYPE(sp)->nmembs; i++)
03047 CIFF90DTYPE(sp)->memids[i] = get_id (&sid, CIFF90DTYPE(sp)->memids[i]);
03048 }
03049
03050 spp = patbl[CIF_F90_BEGIN_SCOPE].aptr;
03051 for (rcnt = 0; rcnt < patbl[CIF_F90_BEGIN_SCOPE].next; rcnt++) {
03052 sp = *spp++;
03053 CIFF90BS(sp)->symid = get_id (&sid, CIFF90BS(sp)->symid);
03054 CIFF90BS(sp)->scopeid = get_id (&sid, CIFF90BS(sp)->scopeid);
03055 CIFF90BS(sp)->parentid = get_id (&sid, CIFF90BS(sp)->parentid);
03056 #ifdef REMAP_FID
03057 CIFF90BS(sp)->fid = get_id (&fid, CIFF90BS(sp)->fid);
03058 #endif
03059 }
03060
03061 spp = patbl[CIF_F90_END_SCOPE].aptr;
03062 for (rcnt = 0; rcnt < patbl[CIF_F90_END_SCOPE].next; rcnt++) {
03063 sp = *spp++;
03064 CIFF90ES(sp)->scopeid = get_id (&sid, CIFF90ES(sp)->scopeid);
03065 #ifdef REMAP_FID
03066 CIFF90ES(sp)->fid = get_id (&fid, CIFF90ES(sp)->fid);
03067 #endif
03068 }
03069
03070 spp = patbl[CIF_F90_SCOPE_INFO].aptr;
03071 for (rcnt = 0; rcnt < patbl[CIF_F90_SCOPE_INFO].next; rcnt++) {
03072 sp = *spp++;
03073 CIFF90SI(sp)->scopeid = get_id (&sid, CIFF90SI(sp)->scopeid);
03074 for (i = 0; i < (int) CIFF90SI(sp)->numalts; i++)
03075 CIFF90SI(sp)->entryids[i] = get_id (&sid, CIFF90SI(sp)->entryids[i]);
03076 }
03077
03078 spp = patbl[CIF_F90_USE_MODULE].aptr;
03079 for (rcnt = 0; rcnt < patbl[CIF_F90_USE_MODULE].next; rcnt++) {
03080 sp = *spp++;
03081 CIFF90USE(sp)->modid = get_id (&sid, CIFF90USE(sp)->modid);
03082 #ifdef REMAP_FID
03083 CIFF90USE(sp)->modfid = get_id (&fid, CIFF90USE(sp)->modfid);
03084 #endif
03085 }
03086
03087 spp = patbl[CIF_F90_RENAME].aptr;
03088 for (rcnt = 0; rcnt < patbl[CIF_F90_RENAME].next; rcnt++) {
03089 sp = *spp++;
03090 CIFF90RN(sp)->modid = get_id (&sid, CIFF90RN(sp)->modid);
03091 CIFF90RN(sp)->origmodid = get_id (&sid, CIFF90RN(sp)->origmodid);
03092 CIFF90RN(sp)->nameid = get_id (&sid, CIFF90RN(sp)->nameid);
03093 CIFF90RN(sp)->scopeid = get_id (&sid, CIFF90RN(sp)->scopeid);
03094
03095 for (i = 0; i < (int) CIFF90RN(sp)->nlocalids; i++)
03096 CIFF90RN(sp)->localid[i] =
03097 get_id (&sid, CIFF90RN(sp)->localid[i]);
03098 }
03099
03100 spp = patbl[CIF_F90_INT_BLOCK].aptr;
03101 for (rcnt = 0; rcnt < patbl[CIF_F90_INT_BLOCK].next; rcnt++) {
03102 sp = *spp++;
03103 CIFF90IB(sp)->intid = get_id (&sid, CIFF90IB(sp)->intid);
03104 CIFF90IB(sp)->moduleid = get_id (&sid, CIFF90IB(sp)->moduleid);
03105 CIFF90IB(sp)->scopeid = get_id (&sid, CIFF90IB(sp)->scopeid);
03106 for (i = 0; i < (int) CIFF90IB(sp)->numints; i++)
03107 CIFF90IB(sp)->procids[i] = get_id (&sid, CIFF90IB(sp)->procids[i]);
03108 }
03109
03110
03111 spp = patbl[CIF_C_TAG].aptr;
03112 for (rcnt = 0; rcnt < patbl[CIF_C_TAG].next; rcnt++) {
03113 sp = *spp++;
03114 CIFCTAG(sp)->tagid = get_id (&sid, CIFCTAG(sp)->tagid);
03115 for (i = 0; i < (int) CIFCTAG(sp)->nmems; i++)
03116 CIFCTAG(sp)->memids[i] = get_id (&sid, CIFCTAG(sp)->memids[i]);
03117 }
03118
03119 #ifdef REMAP_FID
03120 spp = patbl[CIF_C_MESSAGE].aptr;
03121 for (rcnt = 0; rcnt < patbl[CIF_C_MESSAGE].next; rcnt++) {
03122 sp = *spp++;
03123 CIFCMSG(sp)->fid = get_id (&fid, CIFCMSG(sp)->fid);
03124 CIFCMSG(sp)->incid = get_id (&fid, CIFCMSG(sp)->incid);
03125 }
03126 #endif
03127
03128 spp = patbl[CIF_C_CONST].aptr;
03129 for (rcnt = 0; rcnt < patbl[CIF_C_CONST].next; rcnt++) {
03130 sp = *spp++;
03131 CIFCCON(sp)->symid = get_id (&sid, CIFCCON(sp)->symid);
03132 }
03133
03134
03135 spp = patbl[CIF_C_ENTRY].aptr;
03136 for (rcnt = 0; rcnt < patbl[CIF_C_ENTRY].next; rcnt++) {
03137 sp = *spp++;
03138
03139 CIFCENTRY(sp)->symid = get_id (&sid, CIFCENTRY(sp)->symid);
03140 CIFCENTRY(sp)->tagid = get_id (&sid, CIFCENTRY(sp)->tagid);
03141 CIFCENTRY(sp)->link = get_id (&sid, CIFCENTRY(sp)->link);
03142
03143 for (i = 0; i < (int) CIFCENTRY(sp)->nargs; i++) {
03144 CIFCENTRY(sp)->argids[i] = get_id (&sid, CIFCENTRY(sp)->argids[i]);
03145 }
03146
03147 }
03148
03149
03150 spp = patbl[CIF_C_OBJECT].aptr;
03151 for (rcnt = 0; rcnt < patbl[CIF_C_OBJECT].next; rcnt++) {
03152 sp = *spp++;
03153 CIFCOBJ(sp)->symid = get_id (&sid, CIFCOBJ(sp)->symid);
03154 CIFCOBJ(sp)->psymid = get_id (&sid, CIFCOBJ(sp)->psymid);
03155 CIFCOBJ(sp)->tagid = get_id (&sid, CIFCOBJ(sp)->tagid);
03156 CIFCOBJ(sp)->link = get_id (&sid, CIFCOBJ(sp)->link);
03157 }
03158
03159
03160 spp = patbl[CIF_C_LINT_DIRECTIVE].aptr;
03161 for (rcnt = 0; rcnt < patbl[CIF_C_LINT_DIRECTIVE].next; rcnt++) {
03162 sp = *spp++;
03163 CIFCLDIR(sp)->objid = get_id (&sid, CIFCLDIR(sp)->objid);
03164 #ifdef REMAP_FID
03165 CIFCLDIR(sp)->fid = get_id (&fid, CIFCLDIR(sp)->fid);
03166 #endif
03167 }
03168
03169 spp = patbl[CIF_C_MACRO_DEF].aptr;
03170 for (rcnt = 0; rcnt < patbl[CIF_C_MACRO_DEF].next; rcnt++) {
03171 sp = *spp++;
03172 CIFCMDEF(sp)->symid = get_id (&sid, CIFCMDEF(sp)->symid);
03173 #ifdef REMAP_FID
03174 CIFCMDEF(sp)->fid = get_id (&fid, CIFCMDEF(sp)->fid);
03175 #endif
03176 }
03177
03178 spp = patbl[CIF_C_MACRO_UNDEF].aptr;
03179 for (rcnt = 0; rcnt < patbl[CIF_C_MACRO_UNDEF].next; rcnt++) {
03180 sp = *spp++;
03181 CIFCMUDEF(sp)->symid = get_id (&sid, CIFCMUDEF(sp)->symid);
03182 #ifdef REMAP_FID
03183 CIFCMUDEF(sp)->fid = get_id (&fid, CIFCMUDEF(sp)->fid);
03184 #endif
03185 }
03186
03187
03188
03189 spp = patbl[CIF_C_MACRO_USAGE].aptr;
03190 for (rcnt = 0; rcnt < patbl[CIF_C_MACRO_USAGE].next; rcnt++) {
03191 sp = *spp++;
03192 CIFCMUSE(sp)->symid = get_id (&sid, CIFCMUSE(sp)->symid);
03193 #ifdef REMAP_FID
03194 CIFCMUSE(sp)->fid = get_id (&fid, CIFCMUSE(sp)->fid);
03195 #endif
03196 }
03197
03198 spp = patbl[CIF_C_ENTRY_END].aptr;
03199 for (rcnt = 0; rcnt < patbl[CIF_C_ENTRY_END].next; rcnt++) {
03200 sp = *spp++;
03201 CIFCEEND(sp)->symid = get_id (&sid, CIFCEEND(sp)->symid);
03202 #ifdef REMAP_FID
03203 CIFCEEND(sp)->fid = get_id (&fid, CIFCEEND(sp)->fid);
03204 #endif
03205 }
03206
03207
03208 spp = patbl[CIF_CC_TYPE].aptr;
03209 for (rcnt = 0; rcnt < patbl[CIF_CC_TYPE].next; rcnt++) {
03210 sp = *spp++;
03211 CIFCCTYPE(sp)->symid = get_id (&sid, CIFCCTYPE(sp)->symid);
03212 CIFCCTYPE(sp)->scopeid = get_id (&sid, CIFCCTYPE(sp)->scopeid);
03213 j = CIFCCTYPE(sp)->nmem;
03214 for (i = 0; i < j; i++ ) {
03215 CIFCCTYPE(sp)->mem[i] = get_id (&sid, CIFCCTYPE(sp)->mem[i]);
03216 }
03217 }
03218
03219 spp = patbl[CIF_CC_ENTRY].aptr;
03220 for (rcnt = 0; rcnt < patbl[CIF_CC_ENTRY].next; rcnt++) {
03221 sp = *spp++;
03222 CIFCCENT(sp)->symid = get_id (&sid, CIFCCENT(sp)->symid);
03223 CIFCCENT(sp)->fsymid = get_id (&sid, CIFCCENT(sp)->fsymid);
03224 CIFCCENT(sp)->scopeid = get_id (&sid, CIFCCENT(sp)->scopeid);
03225 #ifdef REMAP_FID
03226 CIFCCENT(sp)->sfid = get_id (&fid, CIFCCENT(sp)->sfid);
03227 CIFCCENT(sp)->efid = get_id (&fid, CIFCCENT(sp)->efid);
03228 #endif
03229 j = CIFCCENT(sp)->nparam;
03230 for (i = 0; i < j; i++ ) {
03231 CIFCCENT(sp)->param[i] = get_id (&sid, CIFCCENT(sp)->param[i]);
03232 }
03233 }
03234
03235 spp = patbl[CIF_CC_OBJ].aptr;
03236 for (rcnt = 0; rcnt < patbl[CIF_CC_OBJ].next; rcnt++) {
03237 sp = *spp++;
03238 CIFCCOBJ(sp)->symid = get_id (&sid, CIFCCOBJ(sp)->symid);
03239 CIFCCOBJ(sp)->scopeid = get_id (&sid, CIFCCOBJ(sp)->scopeid);
03240 }
03241
03242 spp = patbl[CIF_CC_SUBTYPE].aptr;
03243 for (rcnt = 0; rcnt < patbl[CIF_CC_SUBTYPE].next; rcnt++) {
03244 sp = *spp++;
03245 CIFCCSUB(sp)->symid = get_id (&sid, CIFCCSUB(sp)->symid);
03246 }
03247
03248 spp = patbl[CIF_CC_ENUM].aptr;
03249 for (rcnt = 0; rcnt < patbl[CIF_CC_ENUM].next; rcnt++) {
03250 sp = *spp++;
03251 CIFCCENUM(sp)->symid = get_id (&sid, CIFCCENUM(sp)->symid);
03252 }
03253
03254 #ifdef REMAP_FID
03255 spp = patbl[CIF_CC_EXPR].aptr;
03256 for (rcnt = 0; rcnt < patbl[CIF_CC_EXPR].next; rcnt++) {
03257 sp = *spp++;
03258 CIFCCEXPR(sp)->fid = get_id (&fid, CIFCCEXPR(sp)->fid);
03259 }
03260 #endif
03261
03262
03263 #ifdef REMAP_FID
03264 spp = patbl[CIF_BE_NODE].aptr;
03265 for (rcnt = 0; rcnt < patbl[CIF_BE_NODE].next; rcnt++) {
03266 sp = *spp++;
03267 j = CIFBENODE(sp)->nlines;
03268 for (i = 0; i < j; i++ ) {
03269 CIFBENODE(sp)->fid[i] = get_id (&fid, CIFBENODE(sp)->fid[i]);
03270 }
03271 }
03272
03273 spp = patbl[CIF_BE_FID].aptr;
03274 for (rcnt = 0; rcnt < patbl[CIF_BE_FID].next; rcnt++) {
03275 sp = *spp++;
03276 j = CIFBEFID(sp)->nfid;
03277 for (i = 0; i < j; i++ ) {
03278 CIFBEFID(sp)->fid[i] = get_id (&fid, CIFBEFID(sp)->fid[i]);
03279 }
03280 }
03281 #endif
03282
03283 }
03284
03285
03286
03287
03288
03289
03290
03291 static long get_max_sid (void)
03292 {
03293
03294 struct Cif_generic **spp;
03295 int rcnt;
03296 long sid, maxsid = 0;
03297
03298 spp = patbl[CIF_COMBLK].aptr;
03299 for (rcnt = 0; rcnt < patbl[CIF_COMBLK].next; rcnt++) {
03300 if ((sid = CIFCB(*spp++)->symid) > maxsid)
03301 maxsid = sid;
03302 }
03303
03304 spp = patbl[CIF_CONST].aptr;
03305 for (rcnt = 0; rcnt < patbl[CIF_CONST].next; rcnt++) {
03306 if ((sid = CIFCON(*spp++)->symid) > maxsid)
03307 maxsid = sid;
03308 }
03309
03310 spp = patbl[CIF_ENTRY].aptr;
03311 for (rcnt = 0; rcnt < patbl[CIF_ENTRY].next; rcnt++) {
03312 if ((sid = CIFENTRY(*spp++)->symid) > maxsid)
03313 maxsid = sid;
03314 }
03315
03316 spp = patbl[CIF_LABEL].aptr;
03317 for (rcnt = 0; rcnt < patbl[CIF_LABEL].next; rcnt++) {
03318 if ((sid = CIFLABEL(*spp++)->symid) > maxsid)
03319 maxsid = sid;
03320 }
03321
03322 spp = patbl[CIF_NAMELIST].aptr;
03323 for (rcnt = 0; rcnt < patbl[CIF_NAMELIST].next; rcnt++) {
03324 if ((sid = CIFNL(*spp++)->symid) > maxsid)
03325 maxsid = sid;
03326 }
03327
03328 spp = patbl[CIF_OBJECT].aptr;
03329 for (rcnt = 0; rcnt < patbl[CIF_OBJECT].next; rcnt++) {
03330 if ((sid = CIFOBJ(*spp++)->symid) > maxsid)
03331 maxsid = sid;
03332 }
03333
03334 spp = patbl[CIF_F90_COMBLK].aptr;
03335 for (rcnt = 0; rcnt < patbl[CIF_F90_COMBLK].next; rcnt++) {
03336 if ((sid = CIFF90CB(*spp++)->symid) > maxsid)
03337 maxsid = sid;
03338 }
03339
03340 spp = patbl[CIF_F90_CONST].aptr;
03341 for (rcnt = 0; rcnt < patbl[CIF_F90_CONST].next; rcnt++) {
03342 if ((sid = CIFF90CON(*spp++)->symid) > maxsid)
03343 maxsid = sid;
03344 }
03345
03346 spp = patbl[CIF_F90_ENTRY].aptr;
03347 for (rcnt = 0; rcnt < patbl[CIF_F90_ENTRY].next; rcnt++) {
03348 if ((sid = CIFF90ENTRY(*spp++)->symid) > maxsid)
03349 maxsid = sid;
03350 }
03351
03352 spp = patbl[CIF_F90_LABEL].aptr;
03353 for (rcnt = 0; rcnt < patbl[CIF_F90_LABEL].next; rcnt++) {
03354 if ((sid = CIFF90LABEL(*spp++)->symid) > maxsid)
03355 maxsid = sid;
03356 }
03357
03358 spp = patbl[CIF_F90_NAMELIST].aptr;
03359 for (rcnt = 0; rcnt < patbl[CIF_F90_NAMELIST].next; rcnt++) {
03360 if ((sid = CIFF90NL(*spp++)->symid) > maxsid)
03361 maxsid = sid;
03362 }
03363
03364 spp = patbl[CIF_F90_OBJECT].aptr;
03365 for (rcnt = 0; rcnt < patbl[CIF_F90_OBJECT].next; rcnt++) {
03366 if ((sid = CIFF90OBJ(*spp++)->symid) > maxsid)
03367 maxsid = sid;
03368 }
03369
03370 spp = patbl[CIF_F90_BEGIN_SCOPE].aptr;
03371 for (rcnt = 0; rcnt < patbl[CIF_F90_BEGIN_SCOPE].next; rcnt++) {
03372 if ((sid = CIFF90BS(*spp++)->scopeid) > maxsid)
03373 maxsid = sid;
03374 }
03375
03376 spp = patbl[CIF_GEOMETRY].aptr;
03377 for (rcnt = 0; rcnt < patbl[CIF_GEOMETRY].next; rcnt++) {
03378 if ((sid = CIFGEOM(*spp++)->geomid) > maxsid)
03379 maxsid = sid;
03380 }
03381
03382
03383 spp = patbl[CIF_C_CONST].aptr;
03384 for (rcnt = 0; rcnt < patbl[CIF_C_CONST].next; rcnt++) {
03385 if ((sid = CIFCCON(*spp++)->symid) > maxsid)
03386 maxsid = sid;
03387 }
03388
03389 spp = patbl[CIF_C_ENTRY].aptr;
03390 for (rcnt = 0; rcnt < patbl[CIF_C_ENTRY].next; rcnt++) {
03391 if ((sid = CIFCENTRY(*spp++)->symid) > maxsid)
03392 maxsid = sid;
03393 }
03394
03395 spp = patbl[CIF_C_OBJECT].aptr;
03396 for (rcnt = 0; rcnt < patbl[CIF_C_OBJECT].next; rcnt++) {
03397 if ((sid = CIFCOBJ(*spp++)->symid) > maxsid)
03398 maxsid = sid;
03399 }
03400
03401 spp = patbl[CIF_C_LINT_DIRECTIVE].aptr;
03402 for (rcnt = 0; rcnt < patbl[CIF_C_LINT_DIRECTIVE].next; rcnt++) {
03403 if ((sid = CIFCLDIR(*spp++)->objid) > maxsid)
03404 maxsid = sid;
03405 }
03406
03407 spp = patbl[CIF_C_MACRO_DEF].aptr;
03408 for (rcnt = 0; rcnt < patbl[CIF_C_MACRO_DEF].next; rcnt++) {
03409 if ((sid = CIFCMDEF(*spp++)->symid) > maxsid)
03410 maxsid = sid;
03411 }
03412
03413 spp = patbl[CIF_C_TAG].aptr;
03414 for (rcnt = 0; rcnt < patbl[CIF_C_TAG].next; rcnt++) {
03415 if ((sid = CIFCTAG(*spp++)->tagid) > maxsid)
03416 maxsid = sid;
03417 }
03418
03419 return (maxsid);
03420 }
03421
03422 #ifdef REMAP_FID
03423
03424
03425
03426
03427
03428
03429 static void remap_files (
03430 void)
03431 {
03432 struct Cif_generic *sp, **spp;
03433 int rcnt;
03434
03435 init_id (&fid);
03436
03437 spp = patbl[CIF_FILE].aptr;
03438 for (rcnt = 0; rcnt < patbl[CIF_FILE].next; rcnt++) {
03439 add_id (&fid, CIFFILE(*spp++)->fid);
03440 }
03441
03442 (void) qsort ((char *)fid.tbl, fid.cur, sizeof(long), (int(*)()) comp_ids);
03443
03444 spp = patbl[CIF_FILE].aptr;
03445 for (rcnt = 0; rcnt < patbl[CIF_FILE].next; rcnt++) {
03446 sp = *spp++;
03447 CIFFILE(sp)->fid = get_id (&fid, CIFFILE(sp)->fid);
03448 }
03449
03450 spp = patbl[CIF_INCLUDE].aptr;
03451 for (rcnt = 0; rcnt < patbl[CIF_INCLUDE].next; rcnt++) {
03452 sp = *spp++;
03453 CIFINC(sp)->srcid = get_id (&fid, CIFINC(sp)->srcid);
03454 CIFINC(sp)->incid = get_id (&fid, CIFINC(sp)->incid);
03455 }
03456
03457 spp = patbl[CIF_SRCFILE].aptr;
03458 for (rcnt = 0; rcnt < patbl[CIF_SRCFILE].next; rcnt++) {
03459 sp = *spp++;
03460 CIFSRC(sp)->fid = get_id (&fid, CIFSRC(sp)->fid);
03461 srcfid = CIFSRC(sp)->fid;
03462 }
03463
03464 spp = patbl[CIF_SRC_POS].aptr;
03465 for (rcnt = 0; rcnt < patbl[CIF_SRC_POS].next; rcnt++) {
03466 sp = *spp++;
03467 CIFSPOS(sp)->srcid = get_id (&fid, CIFSPOS(sp)->srcid);
03468 CIFSPOS(sp)->psrcid = get_id (&fid, CIFSPOS(sp)->psrcid);
03469 CIFSPOS(sp)->fid = get_id (&fid, CIFSPOS(sp)->fid);
03470 }
03471 }
03472 #endif
03473
03474
03475
03476
03477
03478
03479 static long get_max_fid (
03480 void)
03481 {
03482
03483 struct Cif_generic **spp;
03484 int rcnt;
03485 long fid, maxfid = 0;
03486
03487 spp = patbl[CIF_FILE].aptr;
03488 for (rcnt = 0; rcnt < patbl[CIF_FILE].next; rcnt++) {
03489 if ((fid = CIFFILE(*spp++)->fid) > maxfid)
03490 maxfid = fid;
03491 }
03492
03493 return (maxfid);
03494 }
03495
03496