示例#1
0
/*-------------------------------------------------------------------------
 * 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);
}
示例#2
0
/*-------------------------------------------------------------------------
 * Function:	lite_SC_def_lookup
 *
 * Purpose:	Return a ptr to the object version of LOOKUP.
 *
 * Return:	Success:	ptr to the object version of LOOKUP.
 *
 *		Failure:	NULL
 *
 * Programmer:	Adapted from PACT SCORE
 *		Mar 12, 1996
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
byte *
lite_SC_def_lookup (char *s, HASHTAB *tab) {

    hashel *np;

    if (tab == NULL) return(NULL);

    np = lite_SC_lookup(s, tab);
    if (np != NULL) return(np->def);
    else return(NULL);
}
示例#3
0
defstr *
lite_PD_defstr (PDBfile *file, char *name, ...) {

   char 	*nxt, *ptype;
   int 		doffs;
   HASHTAB 	*fchrt;
   memdes 	*desc, *lst, *prev;
   defstr 	*dp;
   va_list	ap ;

   va_start (ap, name);

   prev  = NULL;
   lst   = NULL;
   fchrt = file->chart;
   doffs = file->default_offset;
   for (nxt = va_arg(ap, char*); (int) *nxt != 0; nxt = va_arg(ap, char*)) {
      desc  = _lite_PD_mk_descriptor(nxt, doffs);
      ptype = desc->base_type;
      if (lite_SC_lookup(ptype, fchrt) == NULL) {
	 if ((strcmp(ptype, name) != 0) || !_lite_PD_indirection(nxt)) {
	    sprintf(lite_PD_err, "ERROR: %s BAD MEMBER TYPE - PD_DEFSTR\n",
		    nxt);
	    return(NULL);
	 }
      }

      if (lst == NULL) lst = desc;
      else prev->next = desc;
      prev = desc;
   }

   va_end (ap) ;

   /*
    * Install the type in both charts.
    */
   dp = _lite_PD_defstr_inst(name, lst, -1, NULL, NULL, fchrt,
			     file->host_chart, file->align, file->host_align,
			     FALSE);
   if (dp == NULL) {
      sprintf(lite_PD_err, "ERROR: CAN'T HANDLE PRIMITIVE TYPE - PD_DEFSTR\n");
   }

   return(dp);
}