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