/************************************************************************* * * (c) Copyright 1992,1993,1994 by G & A Technical Software, Inc., * 28 Research Drive, Hampton, Virginia, 23666. * * All Rights Reserved. No part of this software or publication may be * reproduced, stored in a retrieval system, or transmitted, in any form * or by any means, electronic, mechanical, photocopying, recording, or * otherwise without the prior written permission of G & A Technical * Software, Inc. * ************************************************************************* * * Filename: * * Purpose: * * Author: John Burton * * Date: 5/31/94 * ************************************************************************* * * Modification History: * * $Log: s3_parser_pdt_functions.c,v $ * Revision 2.1 1994/07/08 17:52:26 jcburt * Updated typedefs, defines and function protypes to allow recursive * parsing of pct files. Enabled use of sub-PDT files and scoping of * datasets. Datasets used in a pct must be defined either in the * associated pdt file or the pdt file associated with the direct * ancestors of the current pct file. * * DataSet functions and subroutines now have an additional parameter * passed to them, indicating the number of parameters passed in the * dataset list, i.e. was: function(DataSet **dl) * now: function(int nargs, DataSet **dl) * Parameters passed to the dataset routines from the PCT level are all * still contained in the dataset list, nargs is during the function or * subroutine call from s3_exec_enode * * Revision 2.0.0.1 1994/06/28 18:48:28 jcburt * S3 Version 2.0 Initial Source * * ************************************************************************* * * Revision Control Information: * *************************************************************************/ static char rcsid[] = "$Id: s3_parser_pdt_functions.c,v 2.1 1994/07/08 17:52:26 jcburt Exp $"; static char rcsrev[] = "$Revision: 2.1 $"; /************************************************************************* * * Include Files * *************************************************************************/ #include #include #include #include #include #include #include #include "s3_defines.h" #include "s3_typedefs.h" #include "s3_externals.h" #include "s3_globals.h" #include "s3_parser.tab.h" #include "s3_parser_globals.h" /************************************************************************* * * Module: s3_init_char_dataset * * Description: * * Syntax: ST_entry *s3_init_char_dataset(ST_entry *st, Val_list vlist, * int type) * * Inputs: st: * vlist: * type: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry *s3_init_char_dataset(ST_entry *st, Val_list vlist, int type) { int i, j, size, nvals, ndvals, dim1; int len, nv, nch = 0; DataSet *ds = (DataSet *)st; byte *ptr; dim1 = ds->dimlist[0]->co.value; for(i=1,ndvals=1;iNDIMS;i++) ndvals *= ds->dimlist[i]->co.value; size = vlist.size; nvals = vlist.nvals; ptr = ds->d.data; s3_dprint("init_char_dataset: nvals > ndvals: %s %d %d",ds->name,nvals,ndvals); ptr = (byte *) memset(ptr,(int)' ',(dim1*ndvals*size)); for(i=0;i dim1) { s3_parse_warning("string %s too long for dataset %s",vlist.dat.ch_arr[i],ds->name); ptr = (byte *)strncpy((char *)ptr,vlist.dat.ch_arr[i],((dim1-1)*size)); ptr[dim1-1] = '\0'; } else { if(type == CHAR) ptr = (byte *)strncpy((char *)ptr,vlist.dat.ch_arr[i],len); else ptr = (byte *)strcpy((char *)ptr,vlist.dat.ch_arr[i]); } ptr += dim1; } if(nvals > ndvals) s3_parse_warning("Dataset %s too small for number of values specified",ds->name); s3_dprint("init_char_dataset: ds->d.ch = %s",ds->d.ch); return st; } /************************************************************************* * * Module: s3_init_numeric_dataset * * Description: * * Syntax: ST_entry *s3_init_numeric_dataset(ST_entry *st, Val_list vlist, * int type) * * Inputs: st: * vlist: * type: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry *s3_init_numeric_dataset(ST_entry *st, Val_list vlist, int type) { int i, nv, size, nvals, ndvals; int nch = 0; DataSet *ds = (DataSet *)st; byte *dtmp; for(i=0,ndvals=1;iNDIMS;i++) ndvals *= ds->dimlist[i]->co.value; size = vlist.size; nvals = vlist.nvals; if(nvals > ndvals) { s3_dprint("s3_init_numeric_dataset: nvals > ndvals: %p",vlist.dat.by); ds->d.data = (byte *)memcpy(ds->d.data,vlist.dat.by,(ndvals*size)); s3_parse_warning("Dataset %s too small for number of values specified",ds->name); } else { s3_dprint("s3_init_numeric_dataset: nvals <= ndvals: %p",vlist.dat.by); ds->d.data = (byte *)memset(ds->d.data,nch,(ndvals*size)); ds->d.data = (byte *)memcpy(ds->d.data,vlist.dat.by,(nvals*size)); } return st; } /************************************************************************* * * Module: s3_create_dataset * * Description: * * Syntax: void s3_create_dataset(int type,ST_entry **slist, * ST_entry **dlist,Val_list vlist) * * Inputs: type: * dlist: * vlist: * slist: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_create_dataset(int type,ST_entry **slist,ST_entry **dlist,Val_list vlist) { int i,j,ndvals,nv,size,nvals; char tmpbuff[32]; byte *data,*dtmp,nch = 0; for(i=0;ids.type = type; slist[i]->ds.NDIMS = ndims; if(ndims > 0) slist[i]->ds.dimlist = (ST_entry **)xcalloc(ndims,sizeof(ST_entry *)); else slist[i]->ds.dimlist = NULL; for(j=0;jds.dimlist[j] = dlist[j]; if(vlist.nvals > 0) /* Initial values present - need to allocate space */ { s3_dprint("s3_create_dataset: %s",slist[i]->ss.name); slist[i] = (ST_entry *)s3_allocate_dataset((DataSet *)slist[i]); if((type == CHAR)||(type == STRING)) slist[i] = s3_init_char_dataset(slist[i],vlist,type); else slist[i] = s3_init_numeric_dataset(slist[i],vlist,type); } else slist[i]->ds.d.data = NULL; } } /************************************************************************* * * Module: s3_initialize_dataset * * Description: * * Syntax: void s3_initialize_dataset(ST_entry **slist,Val_list vlist) * * Inputs: vlist: * * Outputs: slist: * * Returns: * * Modules Called: * *************************************************************************/ void s3_initialize_dataset(ST_entry **slist,Val_list vlist) { int i,j,ndvals,nv,size,nvals; char tmpbuff[32]; byte *data,*dtmp,nch = 0; int type,ndims; for(i=0;ids.type; ndims = slist[i]->ds.NDIMS; if(slist[i]->ds.d.data == NULL) slist[i] = (ST_entry *)s3_allocate_dataset((DataSet *)slist[i]); if((type == CHAR)||(type == STRING)) slist[i] = s3_init_char_dataset(slist[i],vlist,type); else slist[i] = s3_init_numeric_dataset(slist[i],vlist,type); } }