void cgenP_set_envCB( Widget widget, XtPointer clientData, XtPointer callData ) { /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/ DtbCgenEnvDialogInfo env_dlg = (DtbCgenEnvDialogInfo)clientData; STRING var_name = NULL; STRING var_value = NULL; STRING old_var_value = NULL; var_name = XmTextFieldGetString(env_dlg->name_textf); if (util_strempty(var_name)) return; var_value = XmTextGetString(env_dlg->textpane); if (strlist_str_exists(user_env_vars, var_name)) { /* the user has set this before - we need to deallocate * the string we allocated */ old_var_value = (STRING) strlist_get_str_data(user_env_vars, var_name); util_free(old_var_value); strlist_remove_str(user_env_vars, var_name); } if (!util_strempty(var_value)) strlist_add_str(user_env_vars, var_name, (void *)strdup(var_value)); else strlist_add_str(user_env_vars, var_name, (void *)NULL); /*** DTB_USER_CODE_END ^^^ Add C variables and code above ^^^ ***/ /*** DTB_USER_CODE_START vvv Add C code below vvv ***/ /*** DTB_USER_CODE_END ^^^ Add C code above ^^^ ***/ }
static int write_includes(GenCodeInfo genCodeInfo, ABObj project) { File codeFile = genCodeInfo->code_file; STRING *p = NULL; AB_TRAVERSAL trav; ABObj module = NULL; StringList includes = strlist_create(); char buf[MAXPATHLEN+1]; int i; strlist_set_is_unique(includes, TRUE); *buf = 0; /* standard system includes */ for (p = Includes; *p; p++) { strlist_add_str(includes, *p, NULL); } /* * Includes for sessioning. * These include files are needed only if sessioning * is used. */ if (abmfP_proj_needs_session_save(project) || abmfP_proj_needs_session_restore(project)) { for (p = Session_Includes; *p; p++) { strlist_add_str(includes, *p, NULL); } } /* * Includes for i18n. * These include files are needed only if i18n * is enabled. */ if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) { for (p = I18n_Includes; *p; p++) { strlist_add_str(includes, *p, NULL); } } /* module includes */ for (trav_open(&trav, project, AB_TRAV_MODULES); (module = trav_next(&trav)) != NULL; ) { if (!obj_is_defined(module)) { continue; } sprintf(buf, "\"%s\"", abmfP_get_ui_header_file_name(module)); strlist_add_str(includes, buf, NULL); } trav_close(&trav); /* project include */ sprintf(buf, "\"%s\"", abmfP_get_project_header_file_name(project)); strlist_add_str(includes, buf, NULL); sprintf(buf, "\"%s\"", abmfP_get_utils_header_file_name(project)); strlist_add_str(includes, buf, NULL); abmfP_get_connect_includes(includes, project); /* Write the includes */ for (i = 0; i < strlist_get_num_strs(includes); ++i) { abio_printf(codeFile, "#include %s\n", strlist_get_str(includes, i, NULL)); } abio_puts(codeFile, nlstr); strlist_destroy(includes); return 0; }
/* * Write the callback proc stub file. */ int abmfP_write_stubs_c_file( GenCodeInfo genCodeInfo, STRING codeFileName, ABObj module ) { File codeFile = genCodeInfo->code_file; STRING errmsg = NULL; ABObj win_obj = NULL; ABObj project = obj_get_project(module); char moduleHeaderFileName[MAX_PATH_SIZE]; char moduleName[MAX_PATH_SIZE]; /* * Write file header. */ abmfP_write_user_header_seg(genCodeInfo); abio_puts(codeFile, nlstr); sprintf(moduleName, "module %s", obj_get_name(module)); abmfP_write_file_header( genCodeInfo, codeFileName, FALSE, moduleName, util_get_program_name(), ABMF_MODIFY_USER_SEGS, " * Contains: Module callbacks and connection functions" ); /* * Write includes. */ strcpy(moduleHeaderFileName, abmfP_get_ui_header_file_name(module)); abmfP_write_c_system_include(genCodeInfo, "stdio.h"); abmfP_write_c_system_include(genCodeInfo, "Xm/Xm.h"); abmfP_write_c_local_include(genCodeInfo, abmfP_get_utils_header_file_name(module)); /* * Include project file if i18n is enabled. This file * is needed for the message catalog stuff */ if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) abmfP_write_c_local_include(genCodeInfo, abmfP_get_project_header_file_name(project)); abmfP_write_c_local_include(genCodeInfo, moduleHeaderFileName); /* * Write out includes for modules with connection targets */ { StringListRec connIncludes; int i = 0; int num_strings = 0; strlist_construct(&connIncludes); strlist_add_str(&connIncludes, moduleHeaderFileName, NULL); abmfP_get_connect_includes(&connIncludes, module); num_strings = strlist_get_num_strs(&connIncludes); if (num_strings > 1) /* start at 1 - skip this_ui.h */ { abio_puts(codeFile, nlstr); abmfP_write_c_comment(genCodeInfo, FALSE, "Header files for cross-module connections"); } for (i = 1; i < num_strings; ++i) { abio_printf(codeFile, "#include %s\n", strlist_get_str(&connIncludes, i, NULL)); } strlist_destruct(&connIncludes); } abio_puts(codeFile, nlstr); abmfP_write_user_file_top_seg(genCodeInfo); abio_puts(codeFile, nlstr); if (write_action_functions(genCodeInfo, module) != OK) return ERROR; abmfP_write_user_file_bottom_seg(genCodeInfo); return OK; }
int abmfP_get_connect_includes(StringList includeFiles, ABObj projOrModule) { AB_TRAVERSAL trav; BOOL actionIsCrossModule = FALSE; ABObj project = obj_get_project(projOrModule); ABObj action = NULL; ABObj toObj = NULL; ABObj compRoot = NULL; ABObj toModule = NULL; ABObj win_parent = NULL; ABObj popup_win = NULL; char headerFilename[MAXPATHLEN+1]; *headerFilename = 0; strlist_set_is_unique(includeFiles, TRUE); assert(project != NULL); if (project == NULL) { return 0; } for (trav_open(&trav, projOrModule, AB_TRAV_ACTIONS_FOR_OBJ); (action = trav_next(&trav)) != NULL; ) { actionIsCrossModule = obj_is_cross_module(action); toObj = obj_get_to(action); if (toObj == NULL) { continue; } toModule = obj_get_module(toObj); if (actionIsCrossModule) { sprintf(headerFilename, "\"%s\"", abmfP_get_ui_header_file_name(toModule)); strlist_add_str(includeFiles, headerFilename, NULL); } /* * Check to see if the popup's window parent is in another module */ compRoot = obj_get_root(toObj); popup_win = NULL; if (obj_is_popup_win(compRoot)) { popup_win = compRoot; } if (popup_win == NULL) { popup_win = obj_get_parent_of_type(compRoot, AB_TYPE_DIALOG); } if (popup_win == NULL) { popup_win = obj_get_parent_of_type(compRoot, AB_TYPE_BASE_WINDOW); } if (popup_win != NULL) { win_parent= obj_get_win_parent(popup_win); if (win_parent != NULL) { toModule = obj_get_module(win_parent); if (toModule != NULL) { sprintf(headerFilename, "\"%s\"", abmfP_get_ui_header_file_name(toModule)); strlist_add_str(includeFiles, headerFilename, NULL); } } } /* * For some actions, we need widget-specific convenience * functions and resource strings that exist in the header files. */ if (obj_get_func_type(action) == AB_FUNC_BUILTIN) { switch (obj_get_func_builtin(action)) { case AB_STDACT_SET_LABEL: case AB_STDACT_SET_TEXT: case AB_STDACT_SET_VALUE: abmfP_comp_get_widget_specific_includes( includeFiles, obj_get_root(toObj)); break; } } } trav_close(&trav); return 0; }
int abmfP_write_create_proc_begin_or_decl( GenCodeInfo genCodeInfo, ABObj obj, BOOL declaration ) { #define MAX_CREATE_PARAMS 11 /* need lots for widget return params*/ int return_value = 0; STRING param_types[MAX_CREATE_PARAMS]; STRING param_names[MAX_CREATE_PARAMS]; int num_params = 0; int i = 0; int num_widgets = 0; int first_widget_return_param = -1; int num_submenu_params = 0; int first_submenu_param = -1; for (num_params = 0; num_params < MAX_CREATE_PARAMS; ++num_params) { param_types[num_params] = NULL; param_names[num_params] = NULL; } /* * Set up parameters, in order : instance, name, parent, widget* */ num_params = 0; /* * Instance pointer */ if (abmfP_obj_create_proc_has_instance_param(obj)) { param_types[num_params]= abmfP_obj_get_create_proc_instance_param_type(obj); param_names[num_params]= abmfP_instance_ptr_var_name; ++num_params; if (!declaration) { /* The ipObj field is set, so we don't need to save the var. */ } } /* * Name */ if (abmfP_obj_create_proc_has_name_param(obj)) { param_types[num_params] = abmfP_str_string; param_names[num_params] = "name"; ++num_params; if (!declaration) { abmfP_name_param(genCodeInfo)= istr_const("name"); abmfP_name_param_has_value(genCodeInfo)= TRUE; } } /* * Parent */ if (abmfP_obj_create_proc_has_parent_param(obj)) { param_types[num_params]= abmfP_str_widget; param_names[num_params]= "parent"; ++num_params; if (!declaration) { abmfP_name_param(genCodeInfo)= istr_const("parent"); abmfP_name_param_has_value(genCodeInfo)= TRUE; } } /* * Widget* for returning widget values */ num_widgets = abmfP_obj_get_num_create_proc_return_widgets(obj); if (num_widgets > 0) { first_widget_return_param = num_params; for (i = 0; (i < num_widgets) && (num_params < MAX_CREATE_PARAMS); ++i) { param_types[num_params]= "Widget *"; param_names[num_params]= strdup(abmfP_obj_get_create_proc_return_widget_name(obj, i)); ++num_params; } } /* * submenu id params */ num_submenu_params = abmfP_get_num_cp_submenu_params(obj); if (num_submenu_params > 0) { StringList submenu_param_list = &(abmfP_submenu_params(genCodeInfo)); StringList submenu_param_type_list = &(abmfP_submenu_param_types(genCodeInfo)); int num_strings = 0; strlist_make_empty(submenu_param_list); strlist_make_empty(submenu_param_type_list); for (i = 0; i < num_submenu_params; ++i) { strlist_add_str(submenu_param_type_list, abmfP_get_cp_submenu_param_type_name(obj, i), NULL); strlist_add_str(submenu_param_list, abmfP_get_cp_submenu_param_name(obj, i), NULL); } num_strings = strlist_get_num_strs(submenu_param_list); for (i = 0; (i < num_strings) && (num_params < MAX_CREATE_PARAMS); ++i) { param_types[num_params] = strlist_get_str(submenu_param_type_list, i, NULL); param_names[num_params] = strlist_get_str(submenu_param_list, i, NULL); ++num_params; } } /* * Check for max # params */ assert(num_params < MAX_CREATE_PARAMS); if (declaration) { return_value = abmfP_write_c_func_decl( genCodeInfo, TRUE, abmfP_str_int, abmfP_get_create_proc_name(obj), param_types[0], param_names[0], param_types[1], param_names[1], param_types[2], param_names[2], param_types[3], param_names[3], param_types[4], param_names[4], param_types[5], param_names[5], param_types[6], param_names[6], param_types[7], param_names[7], param_types[8], param_names[8], param_types[9], param_names[9], NULL ); } else { return_value = abmfP_write_c_func_begin( genCodeInfo, TRUE, abmfP_str_int, abmfP_get_create_proc_name(obj), param_types[0], param_names[0], param_types[1], param_names[1], param_types[2], param_names[2], param_types[3], param_names[3], param_types[4], param_names[4], param_types[5], param_names[5], param_types[6], param_names[6], param_types[7], param_names[7], param_types[8], param_names[8], param_types[9], param_names[9], NULL ); } if (first_widget_return_param >= 0) { for (i= first_widget_return_param; i < MAX_CREATE_PARAMS; ++i) { if (param_names[i] != NULL) { util_free(param_names[i]); param_names[i] = NULL; } } } return return_value; #undef MAX_CREATE_PARAMS }