+/*****************************************************************************
+ *Function name
+ * printStruct : Generic struct printing function
+ *Input Params
+ * fp : file to be written to
+ * len : number of fields
+ * array : array of field info
+ * name : basic struct name
+ * facName : name of facility
+ * whichTypeFirst : struct or array/sequence first
+ * hasStrSeq : string or sequence present?
+ * structCount : struct postfix
+ ****************************************************************************/
+static void
+printStruct(FILE * fp, int len, void ** array, char * name, char * facName,
+ int * whichTypeFirst, int * hasStrSeq, int * structCount)
+{
+ int flag = 0;
+ int pos;
+ field * fld;
+ type_descriptor * td;
+
+ for (pos = 0; pos < len; pos++) {
+ fld = (field *)array[pos];
+ td = fld->type;
+ if( td->type != STRING && td->type != SEQUENCE &&
+ td->type != ARRAY) {
+ if (*whichTypeFirst == 0) {
+ *whichTypeFirst = 1; //struct first
+ }
+ if (flag == 0) {
+ flag = 1;
+
+ fprintf(fp,"struct %s_%s",
+ name, facName);
+ if (structCount) {
+ fprintf(fp, "_%d {\n",
+ ++*structCount);
+ } else {
+ fprintf(fp, " {\n");
+ }
+ }
+ fprintf(fp, "\t%s %s; /* %s */\n",
+ getTypeStr(td),fld->name,fld->description );
+ } else {
+ if (*whichTypeFirst == 0) {
+ //string or sequence or array first
+ *whichTypeFirst = 2;
+ }
+ (*hasStrSeq)++;
+ if(flag) {
+ fprintf(fp,"} __attribute__ ((packed));\n\n");
+ }
+ flag = 0;
+ }
+ }
+
+ if(flag) {
+ fprintf(fp,"} __attribute__ ((packed));\n\n");
+ }
+}
+
+
+/*****************************************************************************
+ *Function name
+ * generateHfile : Create the typedefs
+ *Input Params
+ * fp : file to be written to
+ ****************************************************************************/
+void
+generateTypeDefs(FILE * fp)
+{
+ int pos, tmp = 1;
+
+ fprintf(fp, "/**** Basic Type Definitions ****/\n\n");
+
+ for (pos = 0; pos < fac->named_types.values.position; pos++) {
+ type_descriptor * type =
+ (type_descriptor*)fac->named_types.values.array[pos];
+ printStruct(fp, type->fields.position, type->fields.array,
+ "", type->type_name, &tmp, &tmp, NULL);
+ fprintf(fp, "typedef struct _%s %s;\n\n",
+ type->type_name, type->type_name);
+ }
+}
+
+