#include #include #include #include #include #include #include #include /* called when we encounter an error. an error message is */ /* displayed, and the program is terminated. */ static void error_return(char *msg) { fprintf(stderr,"\n+++ERROR : %s.\n\n",msg); exit(1); } /* this routine receives a UG error code, and uses UF_get_fail_message */ /* to translate the code into a string. this string is passed to the */ /* ret routine above. if the UG error code could NOT be translated, */ /* the alternative message which was passed in will be passed to ret. */ static void report_error(int result,char *alt_msg) { char err_message[200]; int found = UF_get_fail_message(result,err_message); if (found != 0) error_return(alt_msg); else error_return(err_message); } /***********************************************************************/ /************ MAIN ***************/ /***********************************************************************/ extern int main(int argc, char **argv) { UF_PART_load_status_t error_status; int result; int num_parts; tag_t part_tag; tag_t object; /* initialize user function */ result = UF_initialize(); if (result) report_error(result,"failed in UF_initialize"); /* open up specified part */ result = UF_PART_open("spreadsheet.prt",&part_tag,&error_status); if (result) report_error(result,"failed in UF_PART_open"); object = NULL_TAG; result = UF_OBJ_cycle_objs_in_part(part_tag, UF_spreadsheet_type, &object); while( object != NULL_TAG ) { char name[UF_OBJ_NAME_LEN+1]; char spreadname[UF_OBJ_NAME_LEN+5]; UF_OBJ_ask_name(object, name); strcpy(spreadname,name); strcat(spreadname,".xss"); if( strcmp(name,"MODELING_SHEET") == 0) printf("Extracting the modeling spreadsheet %s\n", spreadname); else if( strcmp(name,"DEFAULT_SHEET") == 0) printf("Extracting the gateway spreadsheet %s\n", spreadname); else printf("Extracting the part families spreadsheet %s\n", spreadname); result = UF_XS_extract_spreadsheet(name,spreadname); if (result) report_error(result,"failed in UF_XS_extract_spreadsheet"); printf("Extracted %s\n",spreadname); /* Code to manipulate the spreadsheet could go here */ result = UF_XS_store_spreadsheet(name,spreadname); if (result) report_error(result,"failed in UF_XS_store_spreadsheet"); result = UF_OBJ_cycle_objs_in_part(part_tag, UF_spreadsheet_type, &object); } num_parts = error_status.n_parts; UF_free_string_array(num_parts,error_status.file_names); printf("\nEND\n"); return(0); }