static int write_app_resources(GenCodeInfo genCodeInfo, ABObj project) { File codeFile; if (!genCodeInfo || !project) return (0); codeFile = genCodeInfo->code_file; abio_puts(codeFile, "\n"); abio_puts(codeFile, "/*\n"); abio_puts(codeFile, " * Application Resources\n"); abio_puts(codeFile, " */\n"); abio_puts(codeFile, "static XtResource resources[] = {\n"); abio_indent(codeFile); abio_puts(codeFile, "{\"session\", \"Session\", XtRString, sizeof(String),\n"); abio_indent(codeFile); abio_puts(codeFile, "XtOffsetOf(DtbAppResourceRec, session_file), XtRImmediate, (XtPointer)NULL}\n"); abio_outdent(codeFile); abio_puts(codeFile, "\n"); abmfP_write_user_struct_fields_seg(genCodeInfo); abio_outdent(codeFile); abio_puts(codeFile, "};\n"); return (0); }
static int write_main_xt_i18n( GenCodeInfo genCodeInfo, ABObj project ) { File codeFile; int ret_val = 0; if (!genCodeInfo || !project) goto cret; codeFile = genCodeInfo->code_file; abio_puts(codeFile, nlstr); abmfP_write_c_comment(genCodeInfo, TRUE, "NULL language_proc installs the default Xt language procedure"); abio_puts(codeFile, "XtSetLanguageProc((XtAppContext)NULL,\n"); abio_indent(codeFile); abio_puts(codeFile, "language_proc, language_proc_client_data);\n"); abio_outdent(codeFile); abio_puts(codeFile, "\n"); cret: return(ret_val); }
static int write_app_resource_struct( GenCodeInfo genCodeInfo, ABObj project ) { File codeFile; if (!genCodeInfo || !project) return (0); codeFile = genCodeInfo->code_file; abio_puts(codeFile,"\n"); abmfP_write_c_comment(genCodeInfo, FALSE, "Structure to store values for Application Resources"); abio_puts(codeFile,"typedef struct {\n"); abio_indent(codeFile); abio_puts(codeFile,"char *session_file;\n"); abio_puts(codeFile,"\n"); abmfP_write_user_struct_fields_seg(genCodeInfo); abio_outdent(codeFile); abio_puts(codeFile, "} DtbAppResourceRec;\n"); abio_puts(codeFile,"\n"); return (0); }
int abmfP_write_c_block_end(GenCodeInfo genCodeInfo) { abio_outdent(genCodeInfo->code_file); abio_puts(genCodeInfo->code_file, "}\n"); return 0; }
static int write_func_as_strings(FILE *file, FileFuncInfo funcInfo) { char recVarName[256]; char ptrVarName[256]; char *funcNamePtr = NULL; funcNamePtr = funcInfo->funcName; if (strncmp(funcNamePtr, "dtb_", 4) == 0) { funcNamePtr += 4; } sprintf(recVarName, "%%abmfP_lrc_%s", funcNamePtr); sprintf(ptrVarName, "%%abmfP_lib_%s", funcNamePtr); abio_puts(file, "\n"); abio_puts(file, "/*\n"); abio_printf(file, " * %s\n", ptrVarName); abio_puts(file, " */\n"); abio_printf(file, "static LibFuncRec %s = \n", recVarName); abio_printf(file, "{\n"); abio_indent(file); abio_puts(file, "/* name */\n"); write_c_string(file, funcInfo->funcName); abio_puts(file, ",\n"); abio_puts(file, "\n"); abio_printf(file, "/* proto */\n"); write_c_string(file, funcInfo->funcProto); abio_puts(file, ",\n"); abio_puts(file, "\n"); abio_printf(file, "/* def */\n"); write_c_string(file, funcInfo->funcCode); abio_puts(file, "\n"); abio_outdent(file); abio_printf(file, "}; /* %s */\n", recVarName); abio_printf(file, "LibFunc %s = &(%s);\n", ptrVarName, recVarName); return 0; }
static int write_main_msg_i18n( GenCodeInfo genCodeInfo, ABObj project ) { File codeFile; int ret_val = 0; if (!genCodeInfo || !project) goto cret; codeFile = genCodeInfo->code_file; abio_puts(codeFile, "\n"); abio_puts(codeFile, abmfP_comment_begin); abio_puts(codeFile, abmfP_comment_continue); abio_puts(codeFile, "Open the standard message catalog for the project.\n"); abio_puts(codeFile, abmfP_comment_end); abio_puts(codeFile, "Dtb_project_catd = catopen(DTB_PROJECT_CATALOG, NL_CAT_LOCALE);\n"); abio_puts(codeFile, "if (Dtb_project_catd == (nl_catd)-1)\n"); abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "fprintf(stderr, \"WARNING: Could not open message catalog: %s. Messages will be defaults.\\n\",\n"); abio_indent(codeFile); abio_puts(codeFile, "DTB_PROJECT_CATALOG);\n"); abio_outdent(codeFile); abmfP_write_c_block_end(genCodeInfo); abio_puts(codeFile, "\n"); cret: return(ret_val); }
static int write_option_desc_list(GenCodeInfo genCodeInfo, ABObj project) { File codeFile; if (!genCodeInfo || !project) return (0); codeFile = genCodeInfo->code_file; abio_puts(codeFile, "\n"); abio_puts(codeFile, "/*\n"); abio_puts(codeFile, " * command line options...\n"); abio_puts(codeFile, " */\n"); abio_puts(codeFile, "static XrmOptionDescRec optionDescList[] = {\n"); abio_indent(codeFile); abio_puts(codeFile, "{\"-session\", \"*session\", XrmoptionSepArg, (XPointer)NULL}\n"); abio_puts(codeFile, "\n"); abmfP_write_user_struct_fields_seg(genCodeInfo); abio_outdent(codeFile); abio_printf(codeFile, "};\n"); return (0); }
/* * Write main() for the given project. */ static int write_main(GenCodeInfo genCodeInfo, ABObj project) { int returnValue = 0; File codeFile = genCodeInfo->code_file; ABObj window = NULL; int initialized = FALSE; ABObj main_window= NULL; AB_TRAVERSAL trav; BOOL mainWindowHasIcon = FALSE; abmfP_gencode_enter_func(genCodeInfo); main_window = abmfP_get_root_window(project); if (main_window != NULL) { mfobj_set_flags(main_window, CGenFlagTreatAsAppShell); } mainWindowHasIcon = ( (main_window != NULL) && ( (obj_get_icon(main_window) != NULL) || (obj_get_icon_mask(main_window) != NULL)) ); abio_puts(codeFile, "\n\n"); abio_puts(codeFile, abmfP_comment_begin); abio_puts(codeFile, abmfP_comment_continue); abio_printf(codeFile, "main for application %s\n", obj_get_name(project)); abio_puts(codeFile, abmfP_comment_end); /* * Write func declaration. */ abio_puts(codeFile, "int\n"); if (genCodeInfo->prototype_funcs) { abio_puts(codeFile, "main(int argc, char **argv)\n"); } else { abio_puts(codeFile, "main(argc, argv)\n"); abio_indent(codeFile); abio_puts(codeFile, "int\t\targc;\n"); abio_puts(codeFile, "char\t\t**argv;\n"); abio_outdent(codeFile); } abio_puts(codeFile, "{\n"); abio_set_indent(codeFile, 1); /* * Local variables */ abio_puts(codeFile, "Widget\t\ttoplevel = (Widget)NULL;\n"); abio_puts(codeFile, "Display\t\t*display = (Display*)NULL;\n"); abio_puts(codeFile, "XtAppContext\tapp = (XtAppContext)NULL;\n"); abio_puts(codeFile, "String\t\t*fallback_resources = (String*)NULL;\n"); abio_puts(codeFile, "ArgList\t\tinit_args = (ArgList)NULL;\n"); abio_puts(codeFile, "Cardinal\t\tnum_init_args = (Cardinal)0;\n"); abio_puts(codeFile, "ArgList\t\tget_resources_args = (ArgList)NULL;\n"); abio_puts(codeFile, "Cardinal\t\tnum_get_resources_args = (Cardinal)0;\n"); abio_puts(codeFile, "Atom\t\tsave_yourself_atom = (Atom)NULL;\n"); write_main_i18n_local_vars(genCodeInfo, project); write_main_tooltalk_local_vars(genCodeInfo, project); abio_puts(codeFile, nlstr); if (mainWindowHasIcon) { abmfP_icon_pixmap_var(genCodeInfo) = istr_const("icon_pixmap"); abmfP_icon_mask_pixmap_var(genCodeInfo) = istr_const("icon_mask_pixmap"); abio_puts(codeFile, "Pixmap\ticon_pixmap = NULL;\n"); abio_puts(codeFile, "Pixmap\ticon_mask_pixmap = NULL;\n"); } abmfP_write_user_long_seg(genCodeInfo, " No initialization has been done.\n" " ***\n" " *** Add local variables and code." ); if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) write_main_xt_i18n(genCodeInfo, project); /* * Create a parent shell for every other shell and don't realize it. This * way, we can be consistent with our hierarchy. */ abio_printf(codeFile,"toplevel = XtAppInitialize(&app, \"%s\",\n", abmfP_capitalize_first_char(obj_get_name(project))); abio_indent(codeFile); abio_puts(codeFile, "optionDescList, XtNumber(optionDescList),\n"); abio_puts(codeFile, "&argc, argv, fallback_resources,\n"); abio_puts(codeFile, "init_args, num_init_args);\n\n"); abio_outdent(codeFile); abmfP_write_c_comment(genCodeInfo, FALSE, "Get display and verify initialization was successful."); abio_puts(codeFile, "if (toplevel != NULL)\n"); abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "display = XtDisplayOfObject(toplevel);\n"); abmfP_write_c_block_end(genCodeInfo); if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) write_main_msg_i18n(genCodeInfo, project); abio_puts(codeFile, "if (display == NULL)\n"); abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "fprintf(stderr, \"Could not open display.\");\n"); abio_puts(codeFile, "exit(1);\n"); abmfP_write_c_block_end(genCodeInfo); /* Save the toplevel widget so it can be fetched later as needed */ abio_puts(codeFile,"\n"); abmfP_write_c_comment(genCodeInfo, FALSE, "Save the toplevel widget so it can be fetched later as needed."); abio_puts(codeFile, "dtb_save_toplevel_widget(toplevel);\n"); /* Save the command used to invoke the application */ abio_puts(codeFile,"\n"); abmfP_write_c_comment(genCodeInfo, FALSE, "Save the command used to invoke the application."); abio_puts(codeFile, "dtb_save_command(argv[0]);\n"); /* * Get application resources */ abio_puts(codeFile,"\n"); abio_puts(codeFile, "XtGetApplicationResources(toplevel, (XtPointer)&dtb_app_resource_rec,\n"); abio_indent(codeFile); abio_puts(codeFile, "resources, XtNumber(resources),\n"); abio_puts(codeFile, "get_resources_args, num_get_resources_args);\n"); abio_outdent(codeFile); abio_puts(codeFile, nlstr); /* * User segment after initialization */ abmfP_write_user_long_seg(genCodeInfo, " A connection to the X server has been established, and all\n" " *** initialization has been done.\n" " ***\n" " *** Add extra initialization code after this comment." ); /* * Call session restore callback (if needed) */ write_main_session_restore(genCodeInfo, project); /* * Initialize all global variables */ abio_puts(codeFile, nlstr); abmfP_write_c_comment(genCodeInfo, FALSE, "Initialize all global variables."); for (trav_open(&trav, project, AB_TRAV_SALIENT_UI); (window= trav_next(&trav)) != NULL; ) { if (!obj_is_defined(window)) { continue; } if (obj_is_message(window)) { abio_printf(codeFile, "%s(&%s);\n", abmfP_get_msg_clear_proc_name(window), abmfP_get_c_struct_global_name(window)); } else if (obj_is_window(window)) { abio_printf(codeFile, "%s(&%s);\n", abmfP_get_clear_proc_name(window), abmfP_get_c_struct_global_name(window)); } } trav_close(&trav); abio_puts(codeFile, "\n"); if (main_window != NULL) { abmfP_write_c_comment(genCodeInfo, FALSE, "Set up the application's root window."); abio_printf(codeFile, "%s = toplevel;\n", abmfP_get_c_name_global(main_window)); if (obj_get_icon(main_window) != NULL) { abio_printf(codeFile, "%s(%s,\n", abmfP_lib_cvt_image_file_to_pixmap->name, abmfP_get_c_name_global(main_window)); abio_indent(codeFile); abio_put_string(codeFile, obj_get_icon(main_window)); abio_printf(codeFile, ", &%s);\n", istr_string(abmfP_icon_pixmap_var(genCodeInfo))); abio_outdent(codeFile); abmfP_icon_pixmap_var_has_value(genCodeInfo) = TRUE; } if (obj_get_icon_mask(main_window) != NULL) { abio_printf(codeFile, "%s(%s,\n", abmfP_lib_cvt_image_file_to_pixmap->name, abmfP_get_c_name_global(main_window)); abio_indent(codeFile); abio_put_string(codeFile, obj_get_icon_mask(main_window)); abio_printf(codeFile, ", &%s);\n", istr_string(abmfP_icon_mask_pixmap_var(genCodeInfo))); abio_outdent(codeFile); abmfP_icon_mask_pixmap_var_has_value(genCodeInfo) = TRUE; } if (abmfP_get_num_args_of_classes(main_window, ABMF_ARGCLASS_ALL) > 0) { abmfP_xt_va_list_open_setvalues(genCodeInfo, main_window); abmfP_obj_spew_args(genCodeInfo, main_window, ABMF_ARGCLASS_ALL, ABMF_ARGFMT_VA_LIST); if (!obj_get_resizable(main_window)) { abio_printf(codeFile, "XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_RESIZEH,\n"); abio_printf(codeFile, "XmNmwmFunctions, MWM_FUNC_ALL | MWM_FUNC_RESIZE,\n"); } abmfP_xt_va_list_close(genCodeInfo); } } abio_puts(codeFile, nlstr); if ((main_window != NULL) && (obj_is_initially_visible(main_window))) { /* ApplicationShell doesn't require "show" action for mapping */ write_map_window(genCodeInfo, main_window, False); } /* * Display any initially mapped windows */ abio_puts(codeFile, nlstr); abmfP_write_c_comment(genCodeInfo, FALSE, "Map any initially-visible windows"); for (trav_open(&trav, project, AB_TRAV_WINDOWS); (window = trav_next(&trav)) != NULL;) { if ( (window != main_window) && (obj_is_initially_visible(window)) && obj_is_defined(window) ) { write_map_window(genCodeInfo, window, True); } } trav_close(&trav); /* * Get WM_SAVE_YOURSELF atom */ abio_puts(codeFile, "\n"); abio_puts(codeFile, "save_yourself_atom = XmInternAtom(XtDisplay(toplevel),\n"); abio_puts(codeFile, "\t\"WM_SAVE_YOURSELF\", False);\n"); /* * Register callback for WM_SAVE_YOURSELF */ write_main_register_save_yourself(genCodeInfo, project, "save_yourself_atom"); /* * User seg before realize */ abmfP_write_user_long_seg(genCodeInfo, " All initially-mapped widgets have been created, but not\n" " *** realized. Set resources on widgets, or perform other operations\n" " *** that must be completed before the toplevel widget is\n" " *** realized." ); /* * Realize the widget hierarchy */ abio_puts(codeFile, "XtRealizeWidget(toplevel);\n\n"); /* * Write ToolTalk Initialization if needed */ write_main_tooltalk_init(genCodeInfo, project); /* * User seg before event loop */ abmfP_write_user_long_seg(genCodeInfo, " The initially-mapped widgets have all been realized, and\n" " *** the Xt main loop is about to be entered." ); abio_puts(codeFile, nlstr); abmfP_write_c_comment(genCodeInfo, FALSE, "Enter event loop"); abio_puts(codeFile, "XtAppMainLoop(app);\n"); /* * Write func footer. */ abio_printf(codeFile, "return 0;\n"); abio_set_indent(codeFile, 0); abio_puts(codeFile, "}\n\n"); abmfP_gencode_exit_func(genCodeInfo); return returnValue; }
static int write_main_tooltalk_init( GenCodeInfo genCodeInfo, ABObj project ) { AB_TOOLTALK_LEVEL tt_level; AB_TRAVERSAL trav; STRING vendor, version; ABObj action; File codeFile; int ret_val = 0; if (!genCodeInfo || !project || (tt_level = obj_get_tooltalk_level(project)) == AB_TOOLTALK_NONE) return 0; codeFile = genCodeInfo->code_file; abio_puts(codeFile, abmfP_comment_begin); abio_puts(codeFile, abmfP_comment_continue); abio_puts(codeFile, "Initialize ToolTalk to handle Desktop Message Protocol\n"); abio_puts(codeFile, abmfP_comment_end); if (tt_level == AB_TOOLTALK_DESKTOP_ADVANCED) { for (trav_open(&trav, project, AB_TRAV_ACTIONS); (action = trav_next(&trav)) != NULL;) { switch(obj_get_when(action)) { case AB_WHEN_TOOLTALK_QUIT: abio_printf(codeFile, "dtb_set_tt_msg_quitCB((DtbTTMsgHandlerCB)%s);\n", obj_get_func_name(action)); break; case AB_WHEN_TOOLTALK_DO_COMMAND: abio_printf(codeFile, "dtb_set_tt_msg_do_commandCB((DtbTTMsgHandlerCB)%s);\n", obj_get_func_name(action)); break; case AB_WHEN_TOOLTALK_GET_STATUS: abio_printf(codeFile, "dtb_set_tt_msg_get_statusCB((DtbTTMsgHandlerCB)%s);\n", obj_get_func_name(action)); break; case AB_WHEN_TOOLTALK_PAUSE_RESUME: abio_printf(codeFile, "dtb_set_tt_msg_pause_resumeCB((DtbTTMsgHandlerCB)%s);\n", obj_get_func_name(action)); break; default: break; } } trav_close(&trav); abio_puts(codeFile, "\n"); } /* Write out tt init code to deal with possible remote display session */ abio_puts(codeFile, "ttenv = getenv(\"TT_SESSION\");\n"); abio_puts(codeFile, "if (!ttenv || strlen(ttenv) == 0)\n"); abio_indent(codeFile); abio_puts(codeFile,"ttenv = getenv(\"_SUN_TT_SESSION\");\n"); abio_outdent(codeFile); abio_puts(codeFile, "if (!ttenv || strlen(ttenv) == 0)\n"); abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "session = tt_X_session(XDisplayString(display));\n"); abio_puts(codeFile, "tt_default_session_set(session);\n"); abio_puts(codeFile, "tt_free(session);\n"); abmfP_write_c_block_end(genCodeInfo); abio_printf(codeFile, "tt_proc_id = ttdt_open(&tt_fd, \"%s\", ", obj_get_name(project)); vendor = obj_get_vendor(project); version = obj_get_version(project); abio_printf(codeFile, "\"%s\", \"%s\", 1);\n", vendor? vendor : "NULL", version? version : "NULL"); abio_puts(codeFile, "tt_status = tt_ptr_error(tt_proc_id);\n"); abio_puts(codeFile, "if (tt_status != TT_OK)\n"); /* abio_puts(codeFile, "{\n"); abio_indent(codeFile); */ abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "fprintf(stderr,\"ttdt_open(): %s\\n\", tt_status_message(tt_status));\n"); abio_puts(codeFile, "tt_proc_id = NULL;\n"); /* abio_outdent(codeFile); abio_puts(codeFile, "}\n"); */ abmfP_write_c_block_end(genCodeInfo); abio_puts(codeFile, "else\n"); /* abio_puts(codeFile, "{\n"); abio_indent(codeFile); */ abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "XtAppAddInput(app, tt_fd, (XtPointer)XtInputReadMask,\n"); abio_indent(codeFile); abio_puts(codeFile, "tttk_Xt_input_handler, tt_proc_id);\n\n"); abio_outdent(codeFile); abio_printf(codeFile, "tt_session_pattern = ttdt_session_join(NULL, %s,\n", tt_level == AB_TOOLTALK_DESKTOP_ADVANCED? "dtb_tt_contractCB" : "NULL"); abio_indent(codeFile); abio_puts(codeFile, "toplevel, NULL, True);\n\n"); abio_outdent(codeFile); abio_puts(codeFile, "atexit(dtb_tt_close);\n"); /* abio_outdent(codeFile); abio_puts(codeFile, "}\n"); */ abmfP_write_c_block_end(genCodeInfo); return 0; }
static int write_tooltalk_cb_body2( GenCodeInfo genCodeInfo, ABObj action ) { File codeFile; if (!genCodeInfo || !action) return 0; codeFile = genCodeInfo->code_file; abio_puts(codeFile, "\n"); switch(obj_get_when(action)) { case AB_WHEN_TOOLTALK_QUIT: abio_puts(codeFile, "if (cancel == True)\n"); abio_indent(codeFile); abio_puts(codeFile, "tttk_message_fail(msg, TT_DESKTOP_ECANCELED, 0, 1);\n"); abio_outdent(codeFile); abio_puts(codeFile, "else\n"); abio_puts(codeFile, "{\n"); abio_indent(codeFile); write_tooltalk_msg_reply(codeFile); abio_puts(codeFile, "\n"); abmfP_write_c_comment(genCodeInfo, FALSE, "Now that the Message has been replied, process Quit operation"); abmfP_write_user_code_seg(genCodeInfo, NULL); abio_puts(codeFile, nlstr); abio_outdent(codeFile); abio_puts(codeFile, "}\n"); break; case AB_WHEN_TOOLTALK_GET_STATUS: abio_puts(codeFile, "tt_message_arg_val_set(msg, 0, status_string);\n"); write_tooltalk_msg_reply(codeFile); break; case AB_WHEN_TOOLTALK_PAUSE_RESUME: abio_puts(codeFile, "if (already_set == True)\n"); abio_indent(codeFile); abio_puts(codeFile, "tt_message_status_set(msg, TT_DESKTOP_EALREADY);\n"); abio_outdent(codeFile); write_tooltalk_msg_reply(codeFile); break; case AB_WHEN_TOOLTALK_DO_COMMAND: abio_puts(codeFile, "tt_free(command);\n"); abio_puts(codeFile, "tt_message_status_set(msg, status);\n"); abio_puts(codeFile, "if (tt_is_err(status))\n"); abio_indent(codeFile); abio_puts(codeFile, "tttk_message_fail(msg, status, 0, 1);\n"); abio_outdent(codeFile); abio_puts(codeFile, "else\n"); abio_puts(codeFile, "{\n"); abio_indent(codeFile); abio_puts(codeFile, "if (result != NULL)\n"); abio_indent(codeFile); abio_puts(codeFile, "tt_message_arg_val_set(msg, 1, result);\n"); abio_outdent(codeFile); write_tooltalk_msg_reply(codeFile); abio_outdent(codeFile); abio_puts(codeFile, "}\n"); break; default: break; } abio_puts(codeFile, nlstr); abmfP_write_user_code_seg(genCodeInfo, NULL); abio_puts(codeFile, nlstr); abio_puts(codeFile, "return True;\n"); return 0; }
/* * Assumes: function name and opening "(" have been written */ static int write_func_def_params( File file, BOOL use_prototypes, va_list va_params ) { #if defined(__ppc) || defined(linux) #define va_start_params() __va_copy(params, va_params) #elif defined(CSRG_BASED) #define va_start_params() va_copy(params, va_params) #else #define va_start_params() (params = va_params) #endif #define va_end_params() (0) va_list params; int num_params_written= 0; int num_params= 0; BOOL list_params= FALSE; int i= 0; STRING curParamType = NULL; STRING curParamName = NULL; BOOL paramsDone = FALSE; va_start_params(); /* * Count non-NULL string pairs */ num_params = 0; va_start_params(); while ( (va_arg(params, STRING) != NULL) && (va_arg(params, STRING) != NULL)) { ++num_params; } list_params= (num_params > 1); /* use "list" format */ if (num_params > 0) { if (list_params) { abio_puts(file, "\n"); abio_indent(file); } paramsDone = FALSE; va_start_params(); while (!paramsDone) { curParamType = va_arg(params, STRING); if (curParamType != NULL) { curParamName = va_arg(params, STRING); } if ((curParamType == NULL) || (curParamName == NULL)) { paramsDone = TRUE; continue; } if (use_prototypes) { abio_puts(file, curParamType); abio_puts(file, " "); } abio_puts(file, curParamName); ++num_params_written; if (num_params_written < num_params) { abio_puts(file, ","); } if (list_params) { abio_puts(file, "\n"); } } if (list_params) { abio_outdent(file); } } abio_puts(file, ")\n"); /* * Write out old-style parameter types */ num_params_written= 0; if (!use_prototypes) { paramsDone = FALSE; va_start_params(); while (!paramsDone) { curParamType = va_arg(params, STRING); if (curParamType != NULL) { curParamName = va_arg(params, STRING); } if ((curParamType == NULL) || (curParamName == NULL)) { paramsDone = TRUE; continue; } abio_printf(file, "\t%s %s", curParamType, curParamName); ++num_params_written; if (num_params_written < num_params) { abio_puts(file, ","); } abio_puts(file, "\n"); } } va_end_params(); return 0; #undef va_start_params #undef va_end_params }
int abmfP_write_c_func_decl( GenCodeInfo genCodeInfo, BOOL is_static, STRING return_type, STRING func_name, ... ) { #define va_start_params() (va_start(params, func_name)) va_list params; File file= genCodeInfo->code_file; int i= 0; int num_params = 0; int num_params_written= 0; BOOL list_params= TRUE; /* use multiline format for params */ va_start_params(); /* * Count pairs of strings */ num_params= 0; va_start_params(); while ( (va_arg(params, STRING) != NULL) && (va_arg(params, STRING) != NULL)) { ++num_params; } list_params= (num_params > 1); if (is_static) { abio_puts(file, "static "); } if (return_type != NULL) { abio_puts(file, return_type); } if (func_name != NULL) { abio_printf(file, " %s(", func_name); } if ((genCodeInfo->prototype_funcs) && (num_params > 0)) { BOOL paramsDone = FALSE; STRING curParamType = NULL; STRING curParamName = NULL; num_params_written= 0; if (list_params) { abio_puts(file, "\n"); abio_indent(file); } va_start_params(); while (!paramsDone) { curParamType = va_arg(params, STRING); if (curParamType != NULL) { curParamName = va_arg(params, STRING); } if ((curParamType == NULL) || (curParamName == NULL)) { paramsDone = TRUE; continue; } abio_puts(file, curParamType); abio_puts(file, (list_params? "\t":" ")); abio_puts(file, curParamName); ++num_params_written; if (num_params_written < num_params) { abio_puts(file, ","); if (list_params) { abio_puts(file, "\n"); } } } if (list_params) { abio_outdent(file); abio_puts(file, "\n"); } } abio_puts(file, ");\n"); va_end(params); return 0; #undef va_start_params }