コード例 #1
0
ファイル: pdb.c プロジェクト: markcmiller86/libmesh_silo
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);
}
コード例 #2
0
ファイル: pdb.c プロジェクト: markcmiller86/libmesh_silo
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);
}
コード例 #3
0
/*-------------------------------------------------------------------------
 * 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);
}
コード例 #4
0
ファイル: pdconv.c プロジェクト: drhansj/polymec-dev
/*-------------------------------------------------------------------------
 * Function:    lite_PD_convert
 *
 * Purpose:     Convert from one machine format to another NITEMS of type
 *              TYPE from IN and put them in OUT.  ISTD and OSTD are the
 *              data format standards of IN and OUT respectively.
 *
 * Return:      Success:
 *
 *              Failure:
 *
 * Programmer:  Adapted from PACT PDB
 *              Mar  6, 1996 11:34 AM EST
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
lite_PD_convert (char **out, char **in, char *intype, char *outtype,
                 long nitems, data_standard *istd, data_standard *ostd,
                 data_standard *hstd, long *pin_offs, long *pout_offs,
                 HASHTAB *in_chart, HASHTAB *out_chart, int boffs, int error) {

   int ret = FALSE, tmp;
   long i, mitems, in_incr, out_incr;
   char *mtype;
   defstr *idp, *odp, *midp, *modp;
   memdes *desc;

   if (_lite_PD_indirection(outtype)) {
      in_incr     = _lite_PD_align(*pin_offs, intype, in_chart, &tmp);
      out_incr    = _lite_PD_align(*pout_offs, outtype, out_chart, &tmp);
      *pin_offs  += in_incr;
      *pout_offs += out_incr;
      *in        += istd->ptr_bytes + in_incr;
      *out       += ostd->ptr_bytes + out_incr;
      return(TRUE);
   }

   idp = PD_inquire_table_type(in_chart, intype);
   if (idp == NULL)
      lite_PD_error("BAD TYPE IN_CHART - PD_CONVERT", error);

   odp = PD_inquire_table_type(out_chart, outtype);
   if (odp == NULL)
      lite_PD_error("BAD TYPE OUT_CHART - PD_CONVERT", error);

   /*
    * If members is non-NULL then it is a derived type.
    */
   if (odp->members != NULL) {
      for (i = 0L; i < nitems; i++) {
         in_incr     = _lite_PD_align(*pin_offs, intype, in_chart, &tmp);
         out_incr    = _lite_PD_align(*pout_offs, outtype, out_chart, &tmp);
         *pin_offs  += in_incr;
         *pout_offs += out_incr;
         *in        += in_incr;
         *out       += out_incr;

         for (desc = odp->members; desc != NULL; desc = desc->next) {
            mitems   = desc->number;
            mtype    = desc->type;
            in_incr  = _lite_PD_align(*pin_offs, mtype, in_chart, &tmp);
            out_incr = _lite_PD_align(*pout_offs, mtype, out_chart, &tmp);

            /*
             * Increment the offsets to the alignments.
             */
            *pin_offs  += in_incr;
            *pout_offs += out_incr;
            *in        += in_incr;
            *out       += out_incr;

            if (_lite_PD_indirection(mtype)) {
               /*
                * Don't even think about converting pointers - they will be
                * recomputed. However, don't throw away information about
                * whether or not pointer is null.
                */
               if (!_lite_PD_null_pointer(*in, istd->ptr_bytes)) **out = 1;
               *in        += istd->ptr_bytes;
               *out       += ostd->ptr_bytes;
               *pin_offs  += istd->ptr_bytes;
               *pout_offs += ostd->ptr_bytes;
               ret         = TRUE;

            } else if (_lite_PD_prim_typep(desc->base_type, in_chart, error)) {
               /*
                * Check for direct primitives.
                */
               modp = PD_inquire_table_type(out_chart, mtype);
               if (modp == NULL)
                  lite_PD_error("BAD OUT TYPE IN STRUCT - PD_CONVERT", error);

               midp = PD_inquire_table_type(in_chart, mtype);
               if (midp == NULL)
                  lite_PD_error("BAD IN TYPE IN STRUCT - PD_CONVERT", error);

               ret = _lite_PD_convert((char **) out, in, mitems, boffs,
                                      midp, modp, hstd, pin_offs, pout_offs);

            } else {
               /*
                * Recurse for direct derived types.
                */
               ret = lite_PD_convert(out, in, mtype, mtype, mitems,
                                     istd, ostd, hstd, pin_offs, pout_offs,
                                     in_chart, out_chart, boffs, error);
            }

            if (!ret)
               lite_PD_error("STRUCT CONVERSION FAILED - PD_CONVERT",
                             error);
         }
      }

   } else {
      /*
       * if members is NULL then it is a primitive type.
       */
      ret = _lite_PD_convert((char **) out, in, nitems, boffs, idp, odp,
                             hstd, pin_offs, pout_offs);
      if (!ret)
         lite_PD_error("PRIMITIVE CONVERSION FAILED - PD_CONVERT", error);
   }

   return(ret);
}