Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2.1 of the GNU Lesser General Public License 00007 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00033 00034 */ 00035 00036 00037 static char USMID[] = "@(#) libcif/cif_conv.c 30.22 12/08/96 14:42:46"; 00038 00039 00040 /* -------------------------------------------------------------------------- 00041 * "cifconv" Compiler Information File reformatter. 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 extern char *getenv (const char *); 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 * global return code value, in case cifconv needs to exit so that the 00083 * correct error flag can be passed back to the caller 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 /* ensure that we don't try to map this to Cif_Cifconv_Vx */ 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 /* --- file names and file descriptors --- */ 00105 static int infd; /* input cif descriptor */ 00106 static int outfd; /* output cif descriptor */ 00107 static int tmpfd = -1; /* temporary file cif descriptor */ 00108 static char *tfile = NULL; /* pointer to temporary file name */ 00109 static long fdirpos; /* file positon of file directory */ 00110 static enum Boolean canpos = False; /* generate positioning info flag */ 00111 static int *global_nuses = (int *) NULL; /* count of use's per usage used in merge_usages */ 00112 static int global_nuses_allocated = 0; 00113 00114 #ifdef DEBUG 00115 static FILE *dfd; /* file descriptor for debug file output */ 00116 static FILE *sfd; /* file descriptor for standard output */ 00117 void dump_patbl (); 00118 int valid_patbl (); 00119 #endif 00120 00121 /* --- id remapping data --- */ 00122 #define ID_BUMP 500 /* amount to increment tbl size */ 00123 static enum Boolean Remap_id; /* set if ids need to be remapped */ 00124 struct Id_tbl { 00125 long *tbl; /* ptr to array of original id values */ 00126 int max; /* current maximum size of tbl */ 00127 int cur; /* index of next available slot in tbl */ 00128 }; 00129 static struct Id_tbl sid; /* symbol id remapping data */ 00130 #ifdef REMAP_FID 00131 static struct Id_tbl fid; /* file id remapping data */ 00132 #endif 00133 00134 static enum Boolean first_time = True; 00135 00136 #ifdef REMAP_FID 00137 /* The mapped srcfid to go into the cif_cifhdr record */ 00138 static int srcfid = 0; 00139 #endif 00140 00141 /* --- pointer array management structure --- */ 00142 static struct { 00143 struct Cif_generic **aptr; /* ptr to array of ptrs to record structs */ 00144 int psize; /* current allocated size of ptr array */ 00145 int next; /* index of next available slot in ptr array */ 00146 } patbl[CIF_MAXRECORD]; 00147 00148 static char *global_outfile; /* 00149 * allows output filename to be printed from 00150 * anywhere when an error condition occurs 00151 */ 00152 /* global_error_report is set to true if the cif_cifconv 00153 * user wants errors reported to stderr. Error such as 00154 * a usage record not having a matching definition record. 00155 * If false, these errors are ignored. 00156 */ 00157 static enum Boolean global_error_report = False; 00158 00159 /* --- pointer array increment values --- */ 00160 static const int pabump[CIF_MAXRECORD] = { 00161 0, /* 00 = unused */ 00162 100, /* 01 = CIF_CALLSITE */ 00163 1, /* 02 = CIF_CIFHDR */ 00164 100, /* 03 = CIF_COMBLK */ 00165 200, /* 04 = CIF_CONST */ 00166 100, /* 05 = CIF_CDIR */ 00167 100, /* 06 = CIF_ENTRY */ 00168 100, /* 07 = CIF_FILE */ 00169 100, /* 08 = CIF_LOOP */ 00170 100, /* 09 = CIF_INCLUDE */ 00171 200, /* 10 = CIF_LABEL */ 00172 100, /* 11 = CIF_MESSAGE */ 00173 100, /* 12 = CIF_NAMELIST */ 00174 400, /* 13 = CIF_OBJECT */ 00175 1, /* 14 = CIF_SRCFILE */ 00176 1, /* 15 = CIF_SUMMARY */ 00177 100, /* 16 = CIF_CDIR_DOSHARED */ 00178 1, /* 17 = CIF_UNIT */ 00179 1, /* 18 = CIF_ENDUNIT */ 00180 1000, /* 19 = CIF_USAGE */ 00181 100, /* 20 = CIF_ND_MSG */ 00182 1, /* 21 = CIF_EDOPTS */ 00183 1, /* 22 = CIF_MACH_CHAR */ 00184 1, /* 23 = CIF_MISC_OPTS */ 00185 1, /* 24 = CIF_OPT_OPTS */ 00186 1000, /* 25 = CIF_STMT_TYPE */ 00187 100, /* 26 = CIF_GEOMETRY */ 00188 100, /* 27 = CIF_CONTINUATION */ 00189 100, /* 28 = CIF_F90_CALLSITE */ 00190 100, /* 29 = CIF_F90_COMBLK */ 00191 200, /* 30 = CIF_F90_CONST */ 00192 100, /* 31 = CIF_F90_ENTRY */ 00193 100, /* 32 = CIF_F90_LOOP */ 00194 100, /* 33 = CIF_F90_DERIVED_TYPE */ 00195 200, /* 34 = CIF_F90_LABEL */ 00196 100, /* 35 = CIF_F90_NAMELIST */ 00197 400, /* 36 = CIF_F90_OBJECT */ 00198 1, /* 37 = CIF_F90_MISC_OPTS */ 00199 1, /* 38 = CIF_F90_OPT_OPTS */ 00200 100, /* 39 = CIF_F90_BEGIN_SCOPE */ 00201 100, /* 40 = CIF_F90_END_SCOPE */ 00202 100, /* 41 = CIF_F90_SCOPE_INFO */ 00203 100, /* 42 = CIF_F90_USE_MODULE */ 00204 100, /* 43 = CIF_F90_RENAME */ 00205 100, /* 44 = CIF_F90_INT_BLOCK */ 00206 100, /* 45 = CIF_F90_VECTORIZATION */ 00207 100, /* 46 = CIF_BE_NODE */ 00208 100, /* 47 = CIF_TRANSFORM */ 00209 1, /* 48 = CIF_FILEDIR */ 00210 1, /* 49 = CIF_UNITDIR */ 00211 100, /* 50 = CIF_BE_FID */ 00212 400, /* 51= CIF_C_TAG */ 00213 1, /* 52= CIF_C_OPTS */ 00214 100, /* 53= CIF_C_MESSAGE */ 00215 200, /* 54= CIF_C_CONST */ 00216 100, /* 55= CIF_C_ENTRY */ 00217 400, /* 56= CIF_C_OBJECT */ 00218 200, /* 57= CIF_C_LINT_DIRECTIVE */ 00219 200, /* 58= CIF_C_MACRO_DEF */ 00220 200, /* 59= CIF_C_MACRO_UNDEF */ 00221 400, /* 60= CIF_C_MACRO_USAGE */ 00222 100, /* 61= CIF_C_ENTRY_END */ 00223 0,0,0,0,0,0,0,0, /* 62-69 */ 00224 1, /* 70= CIF_ORIG_CMD */ 00225 0,0,0,0,0,0,0,0,0, /* 71-79 */ 00226 100, /* 80= CIF_CC_TYPE */ 00227 100, /* 81= CIF_CC_ENTRY */ 00228 100, /* 82= CIF_CC_OBJ */ 00229 100, /* 83= CIF_CC_SUBTYPE */ 00230 100, /* 84= CIF_CC_ENUM */ 00231 100, /* 85= CIF_CC_EXPR */ 00232 100 /* 86= CIF_SRC_POS */ 00233 00234 00235 }; 00236 00237 /* --- function pointer array - qsort structure comparison routines --- */ 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 /* CRAY2 */ 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, /* 00 */ 00299 comp_callsite, /* 01 = CIF_CALLSITE */ 00300 0, /* 02 */ 00301 comp_comblk, /* 03 = CIF_COMBLK */ 00302 comp_const, /* 04 = CIF_CONST */ 00303 comp_cdir, /* 05 = CIF_CDIR */ 00304 comp_entry, /* 06 = CIF_ENTRY */ 00305 comp_file, /* 07 = CIF_FILE */ 00306 comp_loop, /* 08 = CIF_LOOP */ 00307 0, /* 09 */ 00308 comp_label, /* 10 = CIF_LABEL */ 00309 comp_message, /* 11 = CIF_MESSAGE */ 00310 comp_namelist, /* 12 = CIF_NAMELIST */ 00311 comp_object, /* 13 = CIF_OBJECT */ 00312 0,0, /* 14, 15 */ 00313 comp_cdir_doshared, /* 16 = CIF_CDIR_DOSHARED */ 00314 0,0, /* 17, 18 */ 00315 comp_usage, /* 19 = CIF_USAGE */ 00316 0,0,0,0,0, /* 20-24 */ 00317 comp_stmt_type, /* 25 = CIF_STMT_TYPE */ 00318 comp_geometry, /* 26 = CIF_GEOMETRY */ 00319 comp_continuation, /* 27 = CIF_CONTINUATION */ 00320 #ifndef CRAY2 00321 comp_f90_callsite, /* 28 = CIF_F90_CALLSITE */ 00322 comp_f90_comblk, /* 29 = CIF_F90_COMBLK */ 00323 comp_f90_const, /* 30 = CIF_F90_CONST */ 00324 comp_f90_entry, /* 31 = CIF_F90_ENTRY */ 00325 comp_f90_loop, /* 32 = CIF_F90_LOOP */ 00326 comp_f90_derived_type, /* 33 = CIF_F90_DERIVED_TYPE */ 00327 comp_f90_label, /* 34 = CIF_F90_LABEL */ 00328 comp_f90_namelist, /* 35 = CIF_F90_NAMELIST */ 00329 comp_f90_object, /* 36 = CIF_F90_OBJECT */ 00330 #else 00331 0,0,0,0,0,0,0,0,0, 00332 #endif /* CRAY2 */ 00333 0, /* 37 = CIF_F90_MISC_OPTS */ 00334 0, /* 38 = CIF_F90_OPT_OPTS */ 00335 #ifndef CRAY2 00336 comp_f90_begin_scope, /* 39 = CIF_F90_BEGIN_SCOPE */ 00337 comp_f90_end_scope, /* 40 = CIF_F90_END_SCOPE */ 00338 comp_f90_scope_info, /* 41 = CIF_F90_SCOPE_INFO */ 00339 comp_f90_use_module, /* 42 = CIF_F90_USE_MODULE */ 00340 comp_f90_rename, /* 43 = CIF_F90_RENAME */ 00341 comp_f90_int_block, /* 44 = CIF_F90_INT_BLOCK */ 00342 comp_f90_vectorization, /* 45 = CIF_F90_VECTORIZATION */ 00343 #else 00344 0,0,0,0,0,0,0, 00345 #endif /* CRAY2 */ 00346 0, /* 46 = CIF_BE_NODE */ 00347 comp_transform, /* 47 = CIF_TRANSFORM */ 00348 0, 0, /* 48, 49 */ 00349 0, /* 50 = CIF_BE_FID */ 00350 comp_c_tag, /* 51= CIF_C_TAG */ 00351 0, /* 52= CIF_C_OPTS */ 00352 comp_c_message, /* 53= CIF_C_MESSAGE */ 00353 comp_c_const, /* 54= CIF_C_CONST */ 00354 comp_c_entry, /* 55= CIF_C_ENTRY */ 00355 comp_c_object, /* 56= CIF_C_OBJECT */ 00356 comp_c_lint_directive, /* 57= CIF_C_LINT_DIRECTIVE */ 00357 comp_c_macro_def, /* 58= CIF_C_MACRO_DEF */ 00358 comp_c_macro_undef, /* 59= CIF_C_MACRO_UNDEF */ 00359 comp_c_macro_usage, /* 60= CIF_C_MACRO_USAGE*/ 00360 comp_c_entry_end, /* 61= CIF_C_ENTRY_END */ 00361 0,0,0,0,0,0,0,0, /* 62-69 */ 00362 comp_orig_cmd, /* 70= CIF_ORIG_CMD */ 00363 0,0,0,0,0,0,0,0,0, /* 71-79 */ 00364 comp_cc_type, /* 80= CIF_CC_TYPE */ 00365 comp_cc_entry, /* 81= CIF_CC_ENTRY */ 00366 comp_cc_obj, /* 82= CIF_CC_OBJ */ 00367 comp_cc_subtype, /* 83= CIF_CC_SUBTYPE */ 00368 comp_cc_enum, /* 84= CIF_CC_ENUM */ 00369 comp_cc_expr, /* 85= CIF_CC_EXPR */ 00370 comp_src_pos /* 86= CIF_SRC_POS */ 00371 }; 00372 00373 /* --- forward references --- */ 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 /* returns True if file_2 is older than file_1 */ 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 /* Function: cif_next_entry */ 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 * cifconv_type returns true if this file is in cifconv format already 00445 * false otherwise. 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; /* note the source language */ 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 * main opens the input CIF file. If binary format, it just copies it. If 00483 * ASCII format, it organizes the records into order, adds directory 00484 * information, and writes out a binary format file. 00485 * 00486 * Record structures are managed by the an array of pointers to structure 00487 * for each type. As each structure is encountered, a pointer to the 00488 * structure is added to the appropriate pointer array. The pointer arrays 00489 * are dynamically expanded as needed. Before writing out the structures, 00490 * the pointer arrays are sorted in the correct order for that type. 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; /* argument counter */ 00506 struct Cif_generic *cifp; /* CIF structure pointer */ 00507 int ret; 00508 00509 #ifdef DEBUG 00510 dfd = fopen ("debug", "w"); 00511 sfd = stdout; 00512 #endif 00513 00514 /* 00515 * Note the filename to allow it to be printed 00516 * in error messages 00517 */ 00518 global_outfile = infile; 00519 00520 /* Open the input and output files */ 00521 00522 if ((infd = Cif_Open(infile, "r", rtypes, CIF_VERSION)) < 0) { 00523 /* store the return code for returning from Cif_Cifconv */ 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 * Get the header record. If the form is sorted, copy the file. 00546 * Otherwise sort it. 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 /* Make sure the old memory is freed off */ 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 * sortfile will return -1 iff no units are found, 00581 * in which case, just copy the infile to the outfile 00582 * as there's little extra to be done 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 /* Free up any space allocated via Cif_Duplicate calls */ 00597 free_copied_blocks(); 00598 00599 /* Close the files and quit */ 00600 00601 (void) Cif_Close (infd, CIF_MEM_KEEP); 00602 (void) Cif_Close (outfd, CIF_MEM_KEEP); 00603 00604 /* Close the tmp file as necessary */ 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 * An unpublished routine, used by xbrowse to set the location of 00620 * .TT files. xbrowse does all validation of the directory, so no 00621 * need to do any checking here 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 /* Join two strings together */ 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 /* Verify that the directory passed exists and is writable */ 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); /* directory is not writable */ 00674 }; 00675 fclose(fd); 00676 unlink(test_file); 00677 } 00678 else { 00679 return(0); 00680 } 00681 00682 free(test_file); 00683 00684 return(1); /* directory exists and is writable */ 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 /* Assume that a tmp file will not be created, until proved otherwise */ 00707 00708 *tmp_cif = 0; 00709 00710 /* 1. check if the file is already a cifconv file */ 00711 00712 if (cifconv_type( filename ) == 1) 00713 return(strdup(filename)); 00714 00715 00716 /* See if cif_convdir has been called to set the location of .TT files */ 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 /* 2. see if CIFDIR is set */ 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 /* 3. See if the cifconv cif exists next to the original cif */ 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 /* Cifconv does not exist already, so we have to create it */ 00791 00792 /* Only want to create the cif in none-tmp space if keep == True */ 00793 if (keep == 1) { 00794 00795 /* 00796 * 4. See if we need to write into the tt_directory, only used 00797 * by xbrowse through an unpublished function cif_convdir(dir). 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 /* 4. See if we can write to CIFDIR */ 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 /* 5. See if we can write next to the original file */ 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 /* 6. put the cif into /tmp, see of TMPDIR is available */ 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 /* 7. else create a tmp, tmp directory */ 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 * indicate that a tmp cif file is about to be created; it will 00856 * be removed on cif_close 00857 */ 00858 00859 *tmp_cif = 1; 00860 00861 } 00862 00863 create_cif_file = Cif_Make_Cifconv(filename, create_cif_file, rtypes); 00864 00865 /* free up allocated strings */ 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; /* file name */ 00881 char *optype; /* open type */ 00882 int *rtypes; /* ptr to array of selected record types */ 00883 int version; /* CIF version expected by tools */ 00884 int keep; /* keep the file on exit ? */ 00885 #endif 00886 { 00887 00888 char *cif_name; 00889 int tmp_cif; /* 00890 * set by cif_convert_to_cifconv if a tmp file has been 00891 * created to hold the cifconv cif; the cif should be deleted 00892 * by cif_close 00893 */ 00894 int ret; 00895 00896 if (_cif_version == 0) 00897 _cif_version = 1; 00898 00899 /* 00900 * If keep & 0x100 this is a hidden flag to say that cifconv should 00901 * report on any inconsistencies it finds in the cif to stderr 00902 */ 00903 00904 if (keep & 0x100) { 00905 global_error_report = True; 00906 } 00907 00908 /* 00909 * If this is the first time through, we must initialize some 00910 * data structures 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 /* convert filename to cif_cifconv name */ 00926 cif_name = cif_convert_to_cifconv(filename, keep & 0xff, &tmp_cif, rtypes); 00927 00928 /* an empty filename means that the cif is invalid or not there */ 00929 if (cif_name == (char *) NULL) { 00930 return(cifconv_return_code); 00931 } 00932 00933 /* open the file and return */ 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 * If a valid open, set the tmp_cif flag according to indicate if a 00945 * temporary file has been created that should be removed on cif_close 00946 */ 00947 00948 if (ret >= 0) { 00949 _Cif_filetbl[ret].tmp_cif = tmp_cif; 00950 } 00951 00952 /* free up the converted filename, cif_open will have take a copy */ 00953 00954 free(cif_name); 00955 00956 /* Return whatever cif_open returned */ 00957 00958 return(ret); 00959 } 00960 00961 00962 /* 00963 * As above + added a check to see of the cif.h in use matches what this 00964 * library was compiled with...looks at CIF_SUB_VERSION_2 which must match 00965 * the sub_version passed. See cif_open macros in cif.h for more details. 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; /* file name */ 00974 char *optype; /* open type */ 00975 int *rtypes; /* ptr to array of selected record types */ 00976 int version; /* CIF version expected by tools */ 00977 int keep; /* keep the file on exit ? */ 00978 int sub_version; /* version number of the cif.h */ 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 * As above for version 3 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; /* file name */ 01000 char *optype; /* open type */ 01001 int *rtypes; /* ptr to array of selected record types */ 01002 int version; /* CIF version expected by tools */ 01003 int keep; /* keep the file on exit ? */ 01004 int sub_version; /* version number of the cif.h */ 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 * Duplicate a cif record, noting the new new one so that it can be 01018 * freed later to avoid memory leaks. 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 /* Free up all of the space attached to copied records */ 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 * sortfile reorganizes the file into sorted order and adds the directory 01061 * records. 01062 * ------------------------------------------------------------------------ 01063 */ 01064 01065 static int sortfile ( 01066 struct Cif_generic *cifp) /* pointer to input cif header structure */ 01067 { 01068 01069 int i, rtype; 01070 int unit_found = 0; /* previous unit encountered flag */ 01071 struct Cif_generic *fdp; /* pointer to file directory */ 01072 struct Cif_generic *cifp1; /* cif record pointer */ 01073 long sid; 01074 struct Cif_urectbl *urp; 01075 int in_unit = 0; /* not currently processing 01076 * a unit */ 01077 01078 /* Test the output file for ability to position */ 01079 01080 if (Cif_Getpos (outfd) >= 0) 01081 canpos = True; 01082 01083 /* Add header structure to pointer array. Create the unit directory table. 01084 * Read each record and process. 01085 */ 01086 01087 CIFHDR(cifp)->form = CIF_FORM_SORTED; 01088 /* 01089 * We are writing a cifconv mode binary file, so set the bintype 01090 * to show that cifconv wrote this cif file 01091 */ 01092 01093 CIFHDR(cifp)->bintype = CIF_FORM_CIFCONV; 01094 01095 /* Make sure that the record structures are all empty */ 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 /* If one previous unit encountered, create the scratch file. If 01111 * any previous units found, write the unit to the scratch file, 01112 * release the memory used for the previous unit and clear the patbl 01113 * arrays for unit records. Add the unit record. 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 /* Copy the record to new space so it will survive a call to 01157 * Cif_Release and add to the record list. 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 * If we have hit EOF without the endunit, something has gone 01174 * wrong, so flush the unit 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 /* If more than one unit, copy last unit to scratch file. */ 01189 01190 if (unit_found > 1) { 01191 if ((i = write_unit (tmpfd, False, True)) < 0) 01192 return (i); 01193 } 01194 01195 /* Remap the file ids if needed then determine and save the values for 01196 * the file directory. 01197 */ 01198 01199 #ifdef REMAP_FID 01200 if (Remap_id == True) 01201 remap_files (); 01202 #endif 01203 01204 /* If the file directory doesn't exist, create it and the unit table */ 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 /* Write out the header. If a single unit, write it from patbl. If 01221 * multiple units, copy 'em from the scratch file. 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 /* If no units found, something has gone wring */ 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 /* Free up the memory */ 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 * addstruct adds one structure to the appropriate pointer array in patbl. 01285 * -------------------------------------------------------------------------- 01286 */ 01287 01288 static void addstruct ( 01289 struct Cif_generic *cifp) /* pointer to CIF structure */ 01290 { 01291 static int last_line = 0; /* stores the last position of a stmt record */ 01292 static int last_cpos = 0; /* stmt's at the same position need to get 01293 * an extra marker showing their relative 01294 * line positions as qsort is not 01295 * guaranteed to preserve "like" records 01296 * the rectype field is used for this purpose; 01297 * which we ensure is reset after the sort. 01298 */ 01299 static int last_position = 0; /* order for records at some position */ 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 /* this is really bad, but we can get away with 01310 * it because; a) rectype will be reset, 01311 * b) it is not needed for now 01312 * and c) we can't increase the record 01313 * size to do it correctly for 01314 * users already use this struct 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 * addunit adds another unit to the file directory. If the file directory 01350 * doesn't exit, it's created first. 01351 * -------------------------------------------------------------------------- 01352 */ 01353 01354 static void addunit ( 01355 struct Cif_generic *unitp) /* pointer to unit record structure */ 01356 { 01357 01358 # define UTBUMP 100 /* Increment size for unit table */ 01359 static int utsize = 0; /* current allocated size of unit table */ 01360 01361 int i; 01362 struct Cif_generic *fdp; /* pointer to file directory */ 01363 struct Cif_unittbl *ut; /* pointer to unit table */ 01364 01365 /* If the file directory doesn't exist, create it and the unit table */ 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 /* If the unit table is full, increase the size. */ 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 /* add the unit to the unit table */ 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 = /* strdup( */ CIFUNIT(unitp)->name /* ) */; 01396 ut[i].nlen = strlen(ut[i].name); 01397 ut[i].unitpos = 0; 01398 01399 } 01400 01401 /* -------------------------------------------------------------------------- 01402 * The various record compare routines compare two CIF structures for sorting 01403 * by qsort. Structures are sorted as follows: 01404 * 01405 * CIF_CALLSITE comp_callsite by symbol id, file, line, and column 01406 * CIF_COMBLK comp_comblk by symbol id 01407 * CIF_CONST comp_const by symbol id 01408 * CIF_ENTRY comp_entry by symbol id 01409 * CIF_FILE comp_file by file id 01410 * CIF_LABEL comp_label by symbol id 01411 * CIF_LOOP comp_label by file, line, and column 01412 * CIF_MESSAGE comp_message by file, line, and column 01413 * CIF_NAMELIST comp_namelist by symbol id 01414 * CIF_OBJECT comp_object by symbol id 01415 * CIF_STMT_TYPE comp_stmt_type by file, line, and column 01416 * CIF_USAGE comp_usage by symbol id 01417 * CIF_CDIR comp_cdir by file, line and column 01418 * CIF_CDIR_DOSHARED comp_cdir_doshared by file, line and column 01419 # CIF_GEOMETRY comp_geometry by geometry id 01420 * CIF_CONTINUATION comp_continuation by file, line and column 01421 * CIF_TRANSFORM comp_transform by file and line 01422 * CIF_C_TAG comp_c_tag by symbol id 01423 * CIF_C_MESSAGE comp_c_message by file, line 01424 * CIF_C_CONST comp_c_const by symbol id 01425 * CIF_C_ENTRY comp_c_entry by symbol id 01426 * CIF_C_OBJECT comp_c_object by symbol id 01427 * CIF_C_LINT_DIRECTIVE comp_c_lint_directive by object id 01428 * CIF_C_MACRO_DEF comp_c_macro_def by macro id 01429 * CIF_C_MACRO_UNDEF comp_c_macro_undef by macro id 01430 * CIF_C_MACRO_USAGE comp_c_macro_usage by macro id 01431 * CIF_C_ENTRY_END comp_c_entry_end by symbol id 01432 * CIF_F90_CALLSITE comp_f90_callsite, by symbol id, file, line, and column 01433 * CIF_F90_COMBLK comp_f90_comblk, by symbol id 01434 * CIF_F90_CONST comp_f90_const, by symbol id 01435 * CIF_F90_ENTRY comp_f90_entry, by symbol id 01436 * CIF_F90_LOOP comp_f90_loop, by file, line, and column 01437 * CIF_F90_DERIVED_TYPE comp_f90_derived_type, by symbol id 01438 * CIF_F90_LABEL comp_f90_label, by file, line, and colum 01439 * CIF_F90_NAMELIST comp_f90_namelist, by symbol id 01440 * CIF_F90_OBJECT comp_f90_object, by symbol id 01441 * CIF_F90_BEGIN_SCOPE comp_f90_begin_scope, by scope id 01442 * CIF_F90_END_SCOPE comp_f90_end_scope, by scope id 01443 * CIF_F90_SCOPE_INFO comp_f90_scope_info, by scope id 01444 * CIF_F90_USE_MODULE comp_f90_use_module, by symbol id 01445 * CIF_F90_RENAME comp_f90_rename, by symbol id 01446 * CIF_F90_INT_BLOCK comp_f90_int_block, by scope id 01447 * CIF_F90_VECTORIZATION comp_f90_vectorization, ?? 01448 * CIF_CC_TYPE comp_cc_type, by type id 01449 * CIF_CC_ENTRY comp_cc_entry, by symbol id 01450 * CIF_CC_OBJ comp_cc_obj, by symbol id 01451 * CIF_CC_SUBTYPE comp_cc_subtype, by symbol id 01452 * CIF_CC_ENUM comp_cc_enum, by symbol id 01453 * CIF_CC_EXPR comp_cc_expr, by expression id 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 /* F90 V3 has introduced a statement ordering field which 01562 * is stored in the eline field - otherwise unused for f90 - 01563 * this orders statements on the same line as the cpos is 01564 * not guaranteed. 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 /* rectype will contain indicator of original ordering */ 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/* sort on # member id's, if any */ 01588 if ((ret = ( (*p1)->nmembs - (*p2)->nmembs)) != 0) 01589 return (ret); 01590 else 01591 if ((*p1)->nmembs == 0) 01592 return(0); 01593 else { /* sort on each member id in turn */ 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 /* CRAY2 */ 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 * copy_units copies all the units from the scratch file to the output file. 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 /* don't remove the temporary file in debug mode */ 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 * makeudir creates a Cif_unitdir structure to contain entries for each type 02007 * of unit structure present. 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 * merge_usages combines the use tables for usage records of the same id. 02044 * comp_use compares two use entries for sorted by qsort. 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; /* number of usage records */ 02067 int nuses; /* number of uses */ 02068 int si; /* usage array scanning index */ 02069 int ti; /* usage array trailing index */ 02070 struct Cif_usage **up; /* array of pointers to usage records */ 02071 struct Cif_use *use; /* pointer to combined use array */ 02072 struct Cif_use *use1, *use2; /* pointers for moving use entries */ 02073 02074 struct Cif_generic *cifp1; /* cif record pointer */ 02075 struct Cif_urectbl *urp; 02076 02077 /* Check if duplicate usage ids present */ 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 /* Scan usages, merging records where ids are the same */ 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 /* single usage for this id, copy it. */ 02109 global_nuses[ti] = 1; 02110 *up[ti++] = *up[si++]; 02111 02112 } 02113 else { 02114 /* Multiple usages - find number, combine, and sort them */ 02115 nuses = up[si]->nuses;; 02116 for (n = 1; si+n < numu && up[si+n]->symid == up[si]->symid; n++) { 02117 02118 /* 02119 * number of parent symbold ids, eg a in a%b is different, 02120 * so this usage is not identical to the last 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 * If we didn't get to the end, a difference was found, 02133 * so this usage is not idenical to the last 02134 */ 02135 02136 if (i < (int) up[si]->nmembs) 02137 break; 02138 02139 nuses += up[si+n]->nuses; 02140 } 02141 02142 /* Combine all of the usages into one new record */ 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 /* Sort the usages on fid, line number and column position */ 02155 02156 (void) qsort ((char *)use, 02157 nuses, sizeof(struct Cif_use), 02158 (int(*)()) comp_use); 02159 02160 /* 02161 * Put the new usage record back into the list; 02162 * note, ti must be <= si, so never overwrite anything 02163 * that we are about to read 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 /* Update the unitdir record entry */ 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 * write_header writes out the records that go at the head of the file. 02192 * -------------------------------------------------------------------------- 02193 */ 02194 02195 /* --- output order of record types in output file trailer section --- */ 02196 #define HRECORDS 15 /* number of trailer record types */ 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 /* Sort the CIF_FILE records. Write 'em out. */ 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(); /* set the mapped srcfid */ 02232 02233 /* 02234 * We are writing a cifconv mode binary file, so set the bintype 02235 * to show that cifconv wrote this cif file 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 * write_unit writes out all of the records for one unit from memory. 02277 * -------------------------------------------------------------------------- 02278 */ 02279 02280 /* --- output order of record types in each unit of CIF --- */ 02281 #define URECORDS 54 /* number of unit record types */ 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, /* cif output file descriptor */ 02341 enum Boolean markpos, /* set if positioning should be done */ 02342 enum Boolean merge_use) /* set if usage records should be merged */ 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; /* number of usage records */ 02352 struct Cif_usage **up; /* array of pointers to usage records */ 02353 int si; /* usage array scanning index */ 02354 struct Cif_generic **spp; 02355 02356 /* Get the file position of the unit and save in the file directory */ 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 /* Sort the unit records. Merge usage records as needed. */ 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 /* Reset the cif_stmt_type records; ie the rectype back 02380 * to CIF_STMT_TYPE 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 /* Merge the usages records on symbol ids */ 02391 02392 if (merge_use) 02393 (void) merge_usages(); 02394 02395 /* merge_usages always returns 0 02396 if ((i = merge_usages ()) < 0) return (i); 02397 */ 02398 02399 /* Write the records out in order as specified by the uorder table. Get 02400 * the file position at the start of new record type and stick it in the 02401 * unit directory. After the end_unit record, save the file postion, 02402 * rewrite the unit directory and restore the file position. 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 /* Free up space allocated for merged usages */ 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 * dump_patbl displays the contents of patbl for debugging purposes. 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 * valid_patbl checks the validity of the patbl and offers a convenient 02478 * place for the debugger to set a breakpoint. 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 * init_id initializes an Id_tbl so it can start receiving ids via add_id. 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 * add_id adds a new id value to an Id_tbl tbl. The table is expanded if 02514 * neccessary. 02515 * -------------------------------------------------------------------------- 02516 */ 02517 static void add_id ( 02518 struct Id_tbl *idtp, /* ptr to Id_tbl structure that will receive id */ 02519 long id) /* value of id to add */ 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 * comp_ids compares two symbol ids (longs) for use by qsort. 02533 * -------------------------------------------------------------------------- 02534 */ 02535 static int comp_ids ( 02536 long *id1, 02537 long *id2) 02538 { 02539 return (*id1 - *id2); 02540 } 02541 02542 /* -------------------------------------------------------------------------- 02543 * get_id retrieves the new value for a remapped id given the original value. 02544 * The tbl array will contain all original ids in ascending order. get_id 02545 * performs a binary search of the array and returns the array index of the 02546 * original value. 02547 * -------------------------------------------------------------------------- 02548 */ 02549 static long get_id ( 02550 struct Id_tbl *idtp, /* ptr to Id_tbl to scan for id value */ 02551 long id) /* original id value */ 02552 { 02553 02554 int lower = 1; /* tbl search boundaries */ 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 * Now check to see if the lookup was successful; the only way that this 02578 * would not be the case, would be if the compiler has generated invalid 02579 * object id's; not alot we can do about them, but report the error. 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 * remap_symbols scans the patbl contents for the current unit and remaps the 02598 * symbol and file id values. It is assumed that the file ids have already 02599 * been accumulated and sorted. remap_symbols collects all the symbol ids, 02600 * sorts 'em, and then changes all ids (both file and symbol) to the new values. 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 /* Scan patbl for those structure that define symbol ids and add them 02613 * to the symbol table list. 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 add_id (&sid, CIFF90OBJ(*spp)->storageid); 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 /* add_id (&sid, CIFF90BS(*spp++)->symid); */ 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 /* Sort the accumulated ids, then go thru and replace all the ids. */ 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 * get_max_sid scans the patbl contents for the current unit and determines 03288 * what the largest symbol id value is. 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 * remap_files scans the patbl contents for the all non-unit records that 03425 * contain file id values. remap_files collects all the file ids, sorts 'em, 03426 * and then changes the file ids to new values. 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 * get_max_fid scans the patbl contents for the file records and locates 03476 * the largest id value. 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