#include "dbinc.h" void DBPRTSTR(char *data, char *name, unsigned int *n) { if (!db_ptr->block_strdef_loaded) if (load_block_strdef() != 0) { report_db_error("DBPRTSTR"); return; } if (!db_ptr->formats_matched) if ((db_ptr->error_code = match_formats(db_ptr->block_strdef, db_ptr->format_list)) != 0) { db_ptr->error_data = STRUCTURE_FORMATS; report_db_error("DBPRTSTR"); return; } print_structure(stdout, data, name, *n, db_ptr->struct_def); } /*----------------------------------------------------------------------------- FUNCTION: match_formats It sets the format_ptr fields of the structure element definitions to point to a format specification if found in a linked list of structure printing format definitions pointed to by format_list. PARAMETERS: strdef_list = linked list of structure definitions format_list = linked list of format specifications RETURNS: 0 if okay FORMAT_ERROR if element name in format specification does not match element name in structure definition */ int match_formats(STRUCT_DEF_HDR_TYPE *strdef_list, FORMAT_HDR_TYPE *format_list) { STRUCT_DEF_ENTRY_TYPE *strdef_ptr; FORMAT_ENTRY_TYPE *format_ptr; USHORT nelem, i; strdef_ptr = (STRUCT_DEF_ENTRY_TYPE *) strdef_list; if (format_list) { while (*(strdef_ptr->hdr.name)) { nelem = strdef_ptr->hdr.nelem; if ((format_ptr = (FORMAT_ENTRY_TYPE *) find_format(strdef_ptr->hdr.name, format_list)) != NULL) { for (i = 0; i < nelem; i++) { format_ptr += 1; strdef_ptr += 1; if (!strcmp(strdef_ptr->elem.name, format_ptr->elem.name)) (*(FORMAT_SPEC **) strdef_ptr->elem.format_ptr) = format_ptr->elem.format_ptr; else return(FORMAT_ERROR); } strdef_ptr += 1; } else strdef_ptr += nelem + 1; } } db_ptr->formats_matched = 1; return(0); } /*----------------------------------------------------------------------------- FUNCTION: find_format It searches a linked list of structure printing format definitions for the definition corresponding to a specified structure. PARAMETERS: struct_name = name of structure to search for format_list = pointer to head of linked list RETURNS: pointer to structure printing format definition if found NULL otherwise */ FORMAT_HDR_TYPE *find_format(char *struct_name, FORMAT_HDR_TYPE *format_list) { FORMAT_HDR_TYPE *format_ptr; format_ptr = format_list; while (format_ptr->name) { if (!strcmp(format_ptr->name, struct_name)) return(format_ptr); format_ptr += format_ptr->nelem + 1; } return(NULL); }