static int abmfP_set_action_names_for_obj(ABObj rootObj) { int return_value = 0; int actionNum = -1; AB_TRAVERSAL actionTrav; ABObj action = NULL; ABObj fromObj = NULL; char buf[256]; if (mfobj_data(rootObj) == NULL) { return -1; } for (trav_open(&actionTrav, rootObj, AB_TRAV_ACTIONS_FOR_OBJ); (action = trav_next(&actionTrav)) != NULL;) { if ( (obj_get_func_type(action) != AB_FUNC_USER_DEF) && ((fromObj = obj_get_from(action)) != NULL) ) { action->info.action.auto_named = TRUE; actionNum = mfobj_data(fromObj)->num_auto_callbacks + 1; mfobj_data(fromObj)->num_auto_callbacks = actionNum; sprintf(buf, "_CB%d", actionNum); obj_set_func_name_suffix(action, buf); } } trav_close(&actionTrav); return return_value; }
/* * Write the project.c file. */ int abmfP_write_project_c_file( GenCodeInfo genCodeInfo, STRING codeFileName, BOOL prepareForMerge, ABObj project ) { File codeFile = genCodeInfo->code_file; STRING errmsg = NULL; STRING *p = NULL; ABObj win_obj = NULL; ABObj obj = NULL; ABObj action = NULL; AB_ACTION_INFO *action_info = NULL; AB_TRAVERSAL trav; ABObj module = NULL; int numFuncsWritten = 0; char projectName[1024]; *projectName = 0; /* * Write file header. */ abmfP_write_user_header_seg(genCodeInfo); abio_puts(codeFile, nlstr); sprintf(projectName, "project %s", obj_get_name(project)); abmfP_write_file_header( genCodeInfo, codeFileName, FALSE, projectName, util_get_program_name(), ABMF_MODIFY_USER_SEGS, " * Contains: main() and cross-module connections" ); /* * Write includes. */ write_includes(genCodeInfo, project); /* * Write user segment */ abmfP_write_user_file_top_seg(genCodeInfo); /* i18n variable declarations */ if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) write_i18n_var_declrs(genCodeInfo, project); write_option_desc_list(genCodeInfo, project); write_app_resources(genCodeInfo, project); write_app_resource_var(genCodeInfo, project); /* * Write main(). */ write_main(genCodeInfo, project); /* * Write callback funcs. */ numFuncsWritten = 0; for (trav_open(&trav, project, AB_TRAV_ACTIONS); (action = trav_next(&trav)) != NULL;) { action_info = &(action->info.action); /* If the function name for the action is not NULL AND * the action is a cross-module connection OR the action * is a shared connection, then write it out. */ if ( (abmfP_get_action_name(action) != NULL) && ( obj_is_cross_module(action) || ( (!mfobj_has_flags(action, CGenFlagIsDuplicateDef)) && (mfobj_has_flags(action, CGenFlagWriteDefToProjFile)) && (obj_get_func_type(action) == AB_FUNC_USER_DEF) ) ) ) { ++numFuncsWritten; abmfP_write_action_function(genCodeInfo, action); } } trav_close(&trav); if (numFuncsWritten > 0) { abio_puts(codeFile, nlstr); } abmfP_write_user_file_bottom_seg(genCodeInfo); return OK; }
int abmfP_write_action_function( GenCodeInfo genCodeInfo, ABObj action ) { int rc = 0; /* return code */ BOOL isTTCB = FALSE; BOOL ss_cb = FALSE; File codeFile = genCodeInfo->code_file; BOOL topUserSegWritten = FALSE; BOOL bottomUserSegWritten = FALSE; BOOL funcBodyWritten = FALSE; BOOL funcEndWritten = FALSE; BOOL actionPrintfWritten = FALSE; int return_value = 0; ABObj fromObj = obj_get_from(action); ABObj actualFromObj = NULL; ABObj toObj = obj_get_to(action); ABObj module = NULL; char actionName[1024]; char actionPrintf[1024]; abmfP_gencode_enter_func(genCodeInfo); abmfP_ip_obj(genCodeInfo) = obj_get_to(action); util_strncpy(actionName, abmfP_get_action_name(action), 1024); sprintf(actionPrintf, "printf(\"action: %s()\\n\");\n", actionName); /*** *** START OF FUNCTION ***/ switch (obj_get_when(action)) { case AB_WHEN_AFTER_CREATED: /* * post-create procs have the signature of an Xt Callback, * although they are called as conventional functions. */ fromObj = obj_get_from(action); actualFromObj = get_actual_from_obj(action); abmfP_write_xm_callback_begin(genCodeInfo, FALSE, actionName); write_instance_ptr_var(genCodeInfo, actualFromObj, get_from_var_name(), "callData", TRUE, NULL); abio_puts(genCodeInfo->code_file, nlstr); break; case AB_WHEN_DRAGGED_FROM: { abio_printf(genCodeInfo->code_file, abmfP_lib_default_dragCB->def, /* this is a format string */ actionName,actionName,actionName, actionName,actionName, actionName); abio_puts(genCodeInfo->code_file, "\n\n"); /* these are all in the "library" definition */ topUserSegWritten = TRUE; bottomUserSegWritten = TRUE; funcBodyWritten = TRUE; funcEndWritten = TRUE; actionPrintfWritten = TRUE; } break; case AB_WHEN_DROPPED_ON: { abio_printf(genCodeInfo->code_file, abmfP_lib_default_dropCB->def, /* this is a format string */ actionName,actionName,actionName,actionName); abio_puts(genCodeInfo->code_file, "\n\n"); /* these are all in the "library" definition */ topUserSegWritten = TRUE; bottomUserSegWritten = TRUE; funcBodyWritten = TRUE; funcEndWritten = TRUE; actionPrintfWritten = TRUE; } break; case AB_WHEN_TOOLTALK_QUIT: case AB_WHEN_TOOLTALK_DO_COMMAND: case AB_WHEN_TOOLTALK_GET_STATUS: case AB_WHEN_TOOLTALK_PAUSE_RESUME: isTTCB = TRUE; abio_printf(codeFile, begin_tt_callback_body, actionName); abmfP_write_c_block_begin(genCodeInfo); write_tooltalk_cb_vars(genCodeInfo, action); break; case AB_WHEN_SESSION_RESTORE: ss_cb = TRUE; abio_printf(codeFile, begin_ss_restore_callback_body, abmfP_get_action_name(action)); abmfP_write_c_block_begin(genCodeInfo); write_ss_cb_vars(genCodeInfo, action); break; case AB_WHEN_SESSION_SAVE: ss_cb = TRUE; abio_printf(codeFile, begin_ss_save_callback_body, abmfP_get_action_name(action)); abmfP_write_c_block_begin(genCodeInfo); write_ss_cb_vars(genCodeInfo, action); break; default: abmfP_write_xm_callback_begin(genCodeInfo, FALSE, actionName); break; } /* switch obj_get_when() */ /***** ***** TOP USER SEGMENT *****/ if (!topUserSegWritten) { STRING contents = (actionPrintfWritten? NULL:(isTTCB? actionPrintf:NULL)); abmfP_write_user_var_and_code_seg(genCodeInfo, contents); abio_puts(codeFile, nlstr); topUserSegWritten = TRUE; if (contents != NULL) { actionPrintfWritten = TRUE; } } /*** *** FUNCTION BODY ***/ if (isTTCB) { write_tooltalk_cb_body1(genCodeInfo, action); abmfP_write_user_code_seg(genCodeInfo, NULL); write_tooltalk_cb_body2(genCodeInfo, action); funcBodyWritten = TRUE; bottomUserSegWritten = TRUE; } else if (ss_cb) { write_ss_cb_body1(genCodeInfo, action); abmfP_write_user_code_seg(genCodeInfo, NULL); write_ss_cb_body2(genCodeInfo, action); funcBodyWritten = TRUE; bottomUserSegWritten = TRUE; } else if (!funcBodyWritten) switch (obj_get_func_type(action)) { case AB_FUNC_BUILTIN: rc = abmfP_write_builtin_action(genCodeInfo, action, TRUE); return_if_err(rc,rc); funcBodyWritten = TRUE; break; case AB_FUNC_USER_DEF: abmfP_write_user_start_comment(genCodeInfo, "vvv Add C code below vvv"); abmfP_write_user_end_comment(genCodeInfo, "^^^ Add C code above ^^^"); bottomUserSegWritten = TRUE; funcBodyWritten = TRUE; break; case AB_FUNC_CODE_FRAG: abio_puts(codeFile, obj_get_func_code(action)); funcBodyWritten = TRUE; break; case AB_FUNC_ON_ITEM_HELP: abio_printf(codeFile, "dtb_do_onitem_help();\n"); funcBodyWritten = TRUE; break; case AB_FUNC_HELP_VOLUME: abio_printf(codeFile, "dtb_show_help_volume_info(\"%s\", \"%s\");\n", istr_string(action->info.action.volume_id), istr_string(action->info.action.location)); funcBodyWritten = TRUE; break; default: { char *obj_name_string = obj_get_name(fromObj); util_printf_err(catgets(Dtb_project_catd, 1, 78, "unknown function type for action from object, %s"), obj_name_string); return_code(ERR); } break; } /***** ***** BOTTOM USER SEGMENT *****/ if (!bottomUserSegWritten) { STRING contents = (actionPrintfWritten? NULL:actionPrintf); abmfP_write_user_code_seg(genCodeInfo, contents); bottomUserSegWritten = TRUE; if (contents != NULL) { actionPrintfWritten = TRUE; } } /***** ***** FUNCTION END *****/ if (!funcEndWritten) { abmfP_write_c_func_end(genCodeInfo, NULL); funcEndWritten = TRUE; } epilogue: abmfP_gencode_exit_func(genCodeInfo); return return_value; }
/* * Get the operation. */ static int get_operation(FILE * inFile, ABObj action) { int return_value = 0; int rc = 0; /* r turn code */ ISTRING string = NULL; ISTRING name = NULL; int intval; if (!abio_get_list_begin(inFile)) { return (abil_print_load_err(ERR_WANT_LIST), -1); } switch (obj_get_func_type(action)) { case AB_FUNC_CODE_FRAG: /* code fragment */ if (!abio_get_string(inFile, &string)) { rc = abil_print_load_err(ERR_WANT_STRING); goto abort; } obj_set_func_code(action, istr_string(string)); break; case AB_FUNC_USER_DEF: /* function name (user defined) */ if (!abio_gil_get_name(inFile, &name)) { rc = abil_print_load_err(ERR_WANT_NAME); goto abort; } obj_set_func_name(action, istr_string(name)); break; case AB_FUNC_BUILTIN: /* predefined function */ if (!abio_gil_get_name(inFile, &name)) { return (abil_print_load_err(ERR_WANT_NAME), -1); } obj_set_func_builtin(action, gilP_string_to_builtin_action(istr_string(name))); if (obj_get_func_builtin(action) != AB_STDACT_UNDEF) { if (abio_get_list_end(inFile)) return return_value; switch (obj_get_arg_type(action)) { case AB_ARG_STRING: if (!abio_get_string(inFile, &string)) return (abil_print_load_err(ERR_WANT_STRING), -1); obj_set_arg_string(action, istr_string(string)); break; case AB_ARG_INT: if (!abio_get_integer(inFile, &intval)) return (abil_print_load_err(ERR_WANT_INTEGER), -1); obj_set_arg_int(action, intval); break; case AB_ARG_FLOAT: rc = abil_print_load_err(ERR_UNKNOWN); break; default: rc = abil_print_load_err(ERR_WANT_ARG); break; } } break; default: break; } if (rc < 0) { return_value = rc; } else { if (!abio_get_list_end(inFile)) { return (abil_print_load_err(ERR_WANT_LIST), -1); } } abort: istr_destroy(string); istr_destroy(name); return return_value; }
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; }