/*------------------------------------------------------------------------- * Function: lite_PD_copy_members * * Purpose: Copy a linked list of members. * * Return: Success: ptr to the new list * * Failure: * * Programmer: Adapted from PACT PDB * Mar 6, 1996 11:38 AM EST * * Modifications: * Eric Brugger, Tue Dec 8 15:16:07 PST 1998 * Remove unnecessary calls to lite_SC_mark, since reference count now * set when allocated. * *------------------------------------------------------------------------- */ memdes * lite_PD_copy_members (memdes *desc) { memdes *newm, *nnxt, *thism, *prevm; char *ms, *ts, *bs, *ns, *cs; dimdes *nd; newm = NULL; prevm = NULL; for (thism = desc; thism != NULL; thism = thism->next) { nnxt = FMAKE(memdes, "PD_COPY_MEMBERS:nnxt"); ms = lite_SC_strsavef(thism->member, "char*:PD_COPY_MEMBERS:member"); ts = lite_SC_strsavef(thism->type, "char*:PD_COPY_MEMBERS:type"); bs = lite_SC_strsavef(thism->base_type, "char*:PD_COPY_MEMBERS:base_type"); ns = lite_SC_strsavef(thism->name, "char*:PD_COPY_MEMBERS:name"); nd = lite_PD_copy_dims(thism->dimensions); nnxt->member = ms; nnxt->type = ts; nnxt->base_type = bs; nnxt->name = ns; nnxt->dimensions = nd; nnxt->next = NULL; nnxt->member_offs = thism->member_offs; nnxt->cast_offs = thism->cast_offs; nnxt->number = thism->number; if (thism->cast_memb != NULL) { cs = lite_SC_strsavef(thism->cast_memb, "char*:PD_COPY_MEMBERS:cast_memb"); nnxt->cast_memb = cs; } else { nnxt->cast_memb = NULL; } if (newm == NULL) { newm = nnxt; } else { prevm->next = nnxt; } prevm = nnxt; } return(newm); }
/*------------------------------------------------------------------------- * Function: _lite_PD_mk_descriptor * * Purpose: Build a member descriptor out of the given string. * * Return: Success: * * Failure: * * Programmer: Adapted from PACT PDB * Mar 5, 1996 2:06 PM EST * * Modifications: * Eric Brugger, Tue Dec 8 15:16:07 PST 1998 * Remove unnecessary calls to lite_SC_mark, since reference count now * set when allocated. * *------------------------------------------------------------------------- */ memdes * _lite_PD_mk_descriptor (char *member, int defoff) { memdes *desc; char *ms, *ts, *bs, *ns, *p; dimdes *nd; desc = FMAKE(memdes, "_PD_MK_DESCRIPTOR:desc"); /* * Get rid of any leading white space. */ for (p = member; strchr(" \t\n\r\f", *p) != NULL; p++) /*void*/ ; ms = lite_SC_strsavef(p, "char*:_PD_MK_DESCRIPTOR:member"); ts = _lite_PD_member_type(p); bs = _lite_PD_member_base_type(p); ns = _lite_PD_member_name(p); nd = _lite_PD_ex_dims(p, defoff, FALSE); desc->member = ms; desc->type = ts; desc->base_type = bs; desc->name = ns; desc->dimensions = nd; desc->number = _lite_PD_comp_num(desc->dimensions); desc->member_offs = -1L; desc->cast_offs = -1L; desc->cast_memb = NULL; desc->next = NULL; return(desc); }
/*------------------------------------------------------------------------- * Function: lite_PD_copy_syment * * Purpose: Make and return a copy of the given syment. * * Return: Success: a new syment * * Failure: * * Programmer: Adapted from PACT PDB * Mar 6, 1996 11:39 AM EST * * Modifications: * Eric Brugger, Tue Dec 8 15:16:07 PST 1998 * Remove unnecessary calls to lite_SC_mark, since reference count now * set when allocated. * *------------------------------------------------------------------------- */ syment * lite_PD_copy_syment (syment *osym) { int i, n; char *ntype; syment *nsym; symblock *nsp, *osp; dimdes *ndims; if (osym == NULL) return(NULL); nsym = FMAKE(syment, "PD_COPY_SYMENT:nsym"); n = PD_n_blocks(osym); osp = PD_entry_blocks(osym); nsp = FMAKE_N(symblock, n, "PD_COPY_SYMENT:blocks"); for (i = 0; i < n; i++) nsp[i] = osp[i]; ntype = lite_SC_strsavef(PD_entry_type(osym), "char*:PD_COPY_SYMENT:type"); ndims = lite_PD_copy_dims(PD_entry_dimensions(osym)); PD_entry_blocks(nsym) = nsp; PD_entry_type(nsym) = ntype; PD_entry_dimensions(nsym) = ndims; PD_entry_number(nsym) = PD_entry_number(osym); PD_entry_indirects(nsym) = PD_entry_indirects(osym); return(nsym); }
/*------------------------------------------------------------------------- * Function: _lite_SC_install * * Purpose: Install an object in the hash table. The object type is * defined in hash.h and is generic to enhance the * portability of this code. WARNING: do NOT use litereals * or volatiles for the type--for efficiency they are * not strsave'd!!! * * Return: Success: * * Failure: * * Programmer: Adapted from PACT SCORE * Mar 12, 1996 * * Modifications: * Eric Brugger, Tue Dec 8 16:57:20 PST 1998 * Remove unnecessary calls to lite_SC_mark, since reference count now * set when allocated. The mark flag is now rendered useless since * the memory will always be marked when it is allocated. * * Eric Brugger, Thu Sep 23 10:16:30 PDT 1999 * Remove the mark flag from the argument list. * *------------------------------------------------------------------------- */ hashel * _lite_SC_install (char *name, byte *obj, char *type, HASHTAB *tab) { hashel *np, **tb; int hashval, sz; sz = tab->size; tb = tab->table; np = lite_SC_lookup(name, tab); /* * If not found install it. */ if (np == NULL) { np = FMAKE(hashel, "SC_INSTALL:np"); if (np == NULL) return(NULL); np->name = lite_SC_strsavef(name, "char*:SC_INSTALL:name"); if (np->name == NULL) return(NULL); hashval = lite_SC_hash(np->name, sz); np->next = tb[hashval]; tb[hashval] = np; (tab->nelements)++; } np->type = type; np->def = obj; return(np); }
int lite_PD_cast (PDBfile *file, char *type, char *memb, char *contr) { HASHTAB *tab; hashel *hp; defstr *dp; memdes *desc, *lst; /* * Add the cast to the file->chart. */ tab = file->chart; for (hp = *(tab->table); hp != NULL; hp = hp->next) { dp = (defstr *) hp->def; if (strcmp(type, dp->type) != 0) continue; /* * Check that the contr is right. */ for (desc = dp->members; desc != NULL; desc = desc->next) { if (strcmp(contr, desc->name) != 0) continue; /* * Do this once, don't repeat in other chart. */ if ((strcmp(desc->base_type, "char") != 0) || !_lite_PD_indirection(desc->type)) { sprintf(lite_PD_err, "BAD CAST CONTROLLER - PD_CAST"); return(FALSE); } break; } } /* * Add the cast to the file->host_chart. */ tab = file->host_chart; for (hp = *(tab->table); hp != NULL; hp = hp->next) { dp = (defstr *) hp->def; if (strcmp(type, dp->type) != 0) continue; for (desc = dp->members; desc != NULL; desc = desc->next) { if (strcmp(memb, desc->name) != 0) continue; /* * Make an independent copy in case the one in the file * chart is released. */ desc->cast_memb = lite_SC_strsavef(contr, "char*:PD_CAST:membh"); desc->cast_offs = _lite_PD_member_location(contr, tab, dp, &lst); } } return(TRUE); }
/*------------------------------------------------------------------------- * Function: _lite_PD_mk_pdb * * Purpose: Construct and return a pointer to a PDBFile * * Return: Success: Ptr to a new PDB file * * Failure: NULL * * Programmer: Adapted from PACT PDB * Mar 5, 1996 11:45 AM EST * * Modifications: * Eric Brugger, Mon Dec 7 09:50:45 PST 1998 * Remove the caching of pointer references. * * Eric Brugger, Tue Dec 8 15:16:07 PST 1998 * Remove unnecessary calls to lite_SC_mark, since reference count now * set when allocated. * * Mark C. Miller, Fri Apr 13 22:35:57 PDT 2012 * Added options arg and S,M,L,XL hash table size options. Added * ignore_apersand_ia_ptr_syms option. *------------------------------------------------------------------------- */ PDBfile * _lite_PD_mk_pdb (char *name, const char *options) { PDBfile *file; int symtsz = HSZMEDIUM; file = FMAKE(PDBfile, "_PD_MK_PDB:file"); if (file == NULL) return(NULL); file->stream = NULL; file->name = lite_SC_strsavef(name, "char*:_PD_MK_PDB:name"); file->type = NULL; if (strchr(options, 's')) symtsz = HSZSMALL; else if (strchr(options, 'm')) symtsz = HSZMEDIUM; else if (strchr(options, 'l')) symtsz = HSZLARGE; else if (strchr(options, 'x')) symtsz = HSZXLARGE; else symtsz = HSZMEDIUM; file->symtab = lite_SC_make_hash_table(symtsz, NODOC); file->chart = lite_SC_make_hash_table(1, NODOC); file->host_chart = lite_SC_make_hash_table(1, NODOC); file->attrtab = NULL; file->mode = 0; /* read only, write only, read-write ? */ file->maximum_size = LONG_MAX; /* family info */ file->previous_file = NULL; file->flushed = FALSE; /* born unflushed */ file->virtual_internal = FALSE; /* disk file by default */ file->current_prefix = NULL; /* read/write variable name prefix */ file->system_version = 0; file->default_offset = 0; /* default offset for array indexes */ file->major_order = ROW_MAJOR_ORDER; file->std = NULL; file->align = NULL; file->host_std = _lite_PD_copy_standard(lite_INT_STANDARD); file->host_align = _lite_PD_copy_alignment(lite_INT_ALIGNMENT); file->symtaddr = 0L; file->chrtaddr = 0L; file->headaddr = 0L; file->ignore_apersand_ptr_ia_syms = 0; if (strchr(options, 'i')) file->ignore_apersand_ptr_ia_syms = 1; return(file); }
/*------------------------------------------------------------------------- * Function: lite_PD_cd * * Purpose: Change the current working directory. The directory * may be specified by an absolute or relative path. * * Return: Success: TRUE * * Failure: FALSE * * Programmer: Adapted from PACT PDB * Mar 4, 1996 11:41 AM EST * * Modifications: * *------------------------------------------------------------------------- */ int lite_PD_cd (PDBfile *file, char *dirname) { char name[MAXLINE]; syment *ep; lite_PD_err[0] = '\0'; if (file == NULL) { sprintf(lite_PD_err, "ERROR: BAD FILE ID - PD_CD\n"); return(FALSE); } if (dirname == NULL) { strcpy(name, "/"); } else { strcpy(name, _lite_PD_fixname(file, dirname)); if (name[strlen(name) - 1] != '/') strcat(name, "/"); } ep = lite_PD_inquire_entry(file, name, FALSE, NULL); if (ep == NULL) { if (dirname == NULL) { return(FALSE); } else { if (strcmp(name, "/") != 0) { name[strlen(name) - 1] = '\0'; ep = lite_PD_inquire_entry(file, name, FALSE, NULL); strcat(name, "/"); } if (ep == NULL) { sprintf(lite_PD_err, "ERROR: DIRECTORY %s NOT FOUND - PD_CD\n", dirname); return(FALSE); } } } if (strcmp(ep->type, "Directory") != 0) { sprintf(lite_PD_err, "ERROR: BAD DIRECTORY %s - PD_CD\n", dirname); return(FALSE); } else { if (file->current_prefix) SFREE(file->current_prefix); file->current_prefix = lite_SC_strsavef(name, "char*:PD_CD:name"); } return(TRUE); }
/*------------------------------------------------------------------------- * Function: _lite_PD_mk_defstr * * Purpose: Make a defstr entry for the structure chart. * * Return: Success: * * Failure: * * Programmer: Adapted from PACT PDB * Mar 5, 1996 4:45 PM EST * * Modifications: * Eric Brugger, Tue Dec 8 15:16:07 PST 1998 * Remove unnecessary calls to lite_SC_mark, since reference count now * set when allocated. * *------------------------------------------------------------------------- */ defstr * _lite_PD_mk_defstr (char *type, memdes *lst, long sz, int align, int flg, int conv, int *ordr, long *formt) { defstr *dp; memdes *desc; int n; dp = FMAKE(defstr, "_PD_MK_DEFSTR:dp"); dp->type = lite_SC_strsavef(type, "char*:_PD_MK_DEFSTR:type"); dp->alignment = align; dp->convert = conv; dp->onescmp = 0; dp->unsgned = 0; dp->order_flag = flg; dp->order = ordr; dp->format = formt; dp->members = lst; if (sz >= 0) { dp->size_bits = 0L; dp->size = sz; } else { dp->size_bits = -sz; dp->size = (-sz + 7) >> 3L; dp->unsgned = TRUE; } /* * Find the number of indirects. */ for (n = 0, desc = lst; desc != NULL; desc = desc->next) { if (_lite_PD_indirection(desc->type)) n++; } dp->n_indirects = n; return(dp); }
/*------------------------------------------------------------------------- * Function: _lite_PD_mk_syment * * Purpose: Make and return a pointer to an entry for the symbol table. * * Return: Success: * * Failure: * * Programmer: Adapted from PACT PDB * Mar 5, 1996 2:16 PM EST * * Modifications: * Eric Brugger, Tue Dec 8 15:16:07 PST 1998 * Remove unnecessary calls to lite_SC_mark, since reference count now * set when allocated. * *------------------------------------------------------------------------- */ syment * _lite_PD_mk_syment (char *type, long numb, long addr, symindir *indr, dimdes *dims) { syment *ep; symblock *sp; char *t; ep = FMAKE(syment, "_PD_MK_SYMENT:ep"); sp = FMAKE(symblock, "_PD_MK_SYMENT:sp"); PD_entry_blocks(ep) = sp; sp->number = numb; sp->diskaddr = addr; if (type == NULL) { t = NULL; } else { t = lite_SC_strsavef(type, "char*:_PD_MK_SYMENT:type"); } PD_entry_type(ep) = t; PD_entry_number(ep) = numb; PD_entry_dimensions(ep) = dims; if (indr == NULL) { symindir iloc; iloc.addr = 0L; iloc.n_ind_type = 0L; iloc.arr_offs = 0L; PD_entry_indirects(ep) = iloc; } else { PD_entry_indirects(ep) = *indr; } return(ep); }