Пример #1
0
static STRING
convert_int_to_string(int value, 
	ISTRING *table, int num_values, ISTRING default_value)
{
	if ((value < 0) || (value >= num_values))
	{
		return istr_string(default_value);
	}
	return istr_string(table[value]);
}
Пример #2
0
static int
add_user_handler(ABObj obj, ABObj module,
                 ISTRING handler, AB_WHEN when)
{
    int                 retval = 0;
    ABObj               project = NULL;
    ABObj               action = NULL;

    if (handler == NULL)
    {
        return 0;
    }
    project = obj_get_project(module);

    /*
     * With "callbacks," the to field is irrelevant.  The target is generally
     * whatever widget calls the callback, so we set the "to" field to NULL,
     * so that this action may be used by multiple widgets.  I.e., if the
     * function type, name and to fields match, an action will be shared.
     */
    action = obj_create(AB_TYPE_ACTION, NULL);
    obj_set_func_type(action, AB_FUNC_USER_DEF);
    obj_set_func_name(action, istr_string(handler));
    obj_set_arg_type(action, AB_ARG_VOID_PTR);
    action->info.action.to = NULL;

    obj_set_from(action, obj);
    obj_set_when(action, when);

    install_action(obj, module, action);
    return 0;
}
Пример #3
0
/*
 * Get the arg_type of an action_holder
 */
static int
get_arg_type(FILE * inFile, ABObj action)
{
    int                 return_value = 0;
    ISTRING             type_name = NULL;

    obj_set_arg_type(action, AB_ARG_VOID_PTR);

    if (!abio_get_list_begin(inFile))
        return (abil_print_load_err(ERR_WANT_LIST), -1);

    if (abio_get_list_end(inFile))
    {
        return return_value;
    }

    while (!abio_get_list_end(inFile))
    {
        if (!abio_gil_get_name(inFile, &type_name))
            return (abil_print_load_err(ERR_WANT_NAME), -1);

        obj_set_arg_type(action, 
		gilP_string_to_arg_type(istr_string(type_name)));
    }

    return return_value;
}
Пример #4
0
/*
 * Get the when part of a connection.
 */
static int
get_when(FILE * inFile, ABObj obj, ABObj action)
{
    int                 return_value = 0;
    ISTRING             string = NULL;
    AB_WHEN             when = AB_WHEN_UNDEF;
    int			numWhens = 0;

    if (!abio_get_list_begin(inFile))
        return (abil_print_load_err(ERR_WANT_LIST), -1);

    while (!abio_get_list_end(inFile))
    {
        if (!abio_gil_get_name(inFile, &string))
            return (abil_print_load_err(ERR_WANT_NAME), -1);

        when = gilP_string_to_when(istr_string(string));
	if (when == AB_WHEN_UNDEF)
	{
	    if (util_be_verbose())
	    {
	        util_printf("WARNING: ignoring unsupported when: %s\n",
		    istr_string(string));
	    }
	}
	else
	{
	    obj_set_when(action, when);
            istr_destroy(string);
	    ++numWhens;
	    if (numWhens > 1)
	    {
	        util_printf_err(
		    "WARNING: multiple :when values not supported. "
		    "Using first value\n");
	    }
	}
    }
    return return_value;
}
Пример #5
0
/*
 * Load an action.
 */
static int
get_action(
			FILE * inFile, 
			ABObj obj, 
			ABObj module, 
			ABObj action
)
{
    int                 return_value = 0;
    int                 rc = 0; /* r turn code */
    ISTRING             keyword;
    AB_GIL_ATTRIBUTE    action_attr;

    if (!abio_get_list_begin(inFile))
        return (abil_print_load_err(ERR_WANT_LIST), -1);

    while (!abio_get_list_end(inFile))
    {
        if (abio_get_eof(inFile))
        {
            abil_print_load_err(ERR_EOF);
            return -1;
        }

        if (!abio_get_keyword(inFile, &keyword))
        {
            abil_print_load_err(ERR_WANT_KEYWORD);
            return -1;
        }

        action_attr = gilP_string_to_att(istr_string(keyword));
        if ((rc = get_action_attribute(inFile, obj, module,
                                       action, action_attr))
            < 0)
        {
            return_value = rc;
            break;
        }
        abil_loadmsg_set_action_att(NULL);
    }
    abil_loadmsg_set_action_att(NULL);

    return return_value;
}
Пример #6
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;
}
Пример #7
0
int
abmfP_write_builtin_action(
    GenCodeInfo	genCodeInfo,
    ABObj 		action,
    BOOL		setUpVars
)
{
    int			return_value     = 0;
    File                codeFile         = genCodeInfo->code_file;
    ABObj               toObj            = NULL;
    STRING		actionTKResource = NULL;	/* in toolkit */
    STRING		actionResource   = NULL;	/* in source code */
    ISTRING		istr_resource    = NULL;
    AB_BUILTIN_ACTION	builtin_action   = AB_STDACT_UNDEF;

    toObj          = obj_get_to(action);
    builtin_action = obj_get_func_builtin(action);
    if (toObj != NULL)
    {
        toObj = objxm_comp_get_target_for_builtin_action(toObj, builtin_action);
    }
    if (toObj == NULL)
    {
        abmfP_write_c_comment(genCodeInfo, FALSE, "Invalid action ignored.");
        abio_puts(codeFile, nlstr);
        return 0;
    }

    /*
     * We need to convert the resource into a string that can be put
     * in the .c file.
     */
    actionTKResource = objxm_get_resource_for_builtin_action(
                           toObj, builtin_action);
    istr_resource    = objxm_get_res_strname(actionTKResource);
    actionResource   = istr_string(istr_resource);

    if (abmfP_get_c_name(genCodeInfo, toObj) == NULL)
    {
        return_value = write_builtin_action_for_ref(genCodeInfo,
                       action, toObj, setUpVars, builtin_action, actionTKResource,
                       actionResource);
    }
    else
    {
        if (setUpVars)
        {
            set_up_user_type_variables(genCodeInfo, toObj);
        }

        return_value = write_builtin_action(genCodeInfo, action, toObj,
                                            builtin_action, actionTKResource, actionResource);
    }

    if (return_value == 0)
        abio_printf(codeFile, nlstr);

epiloge:
    abio_printf(codeFile, nlstr);
    return return_value;
}
Пример #8
0
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;
}
Пример #9
0
/*
 * Finds the target matching the given description, creating it if necessary.
 * 
 * Assumes: strings are pointers to allocated space. Sets strings to NULL, if
 * the values are used.
 * 
 * Assumes that obj may not be in the object tree yet, and may return it as the
 * target.
 */
static ABObj
find_or_create_target(
			ABObj	obj, 
			ABObj	module,
		      	ISTRING	interface_name,
                      	ISTRING	parent_name,
                      	ISTRING	obj_name,
                      	ISTRING	item_label
)
{
    ABObj               target = NULL;	/* the real thing, baby! */
    ABObj		target_project = NULL;
    char		target_interface_file[MAXPATHLEN+1];
    char		target_interface_name[GIL_MAX_NAME_SIZE];
    ABObj		target_module = NULL;
    char		target_parent_name[GIL_MAX_NAME_SIZE];
    ABObj		target_parent = NULL;
    char		target_obj_name[GIL_MAX_NAME_SIZE];
    ABObj		target_obj = NULL;
    char		target_item_label[GIL_MAX_NAME_SIZE];
    ABObj		target_item = NULL;
    AB_TRAVERSAL	trav;
    *target_interface_file = 0;
    *target_interface_name = 0;
    *target_parent_name = 0;
    *target_obj_name = 0;
    *target_item_label = 0;
   
    /* must have object name */
    if (debugging()) 
    {
	assert(   (obj_name != NULL)
	       && (obj_is_project(module) || obj_is_module(module)));
    }

    if (obj_is_project(module))
    {
	/* The first string must be an interface file name */
	if (interface_name != NULL)
	{
	    util_strncpy(target_interface_file, istr_string(interface_name),
			GIL_MAX_NAME_SIZE);
	    if (parent_name != NULL)
	    {
		util_strncpy(target_parent_name, istr_string(parent_name),
			GIL_MAX_NAME_SIZE);
	    }
	}
	else if (parent_name != NULL)
	{
	    util_strncpy(target_interface_file, istr_string(parent_name),
			GIL_MAX_NAME_SIZE);
	}
	else
	{
	    abil_print_load_err(ERR_WANT_FULL_NAME);
	    goto epilogue;
	}

	/* derive the name from the file name */
	strcpy(target_interface_name, target_interface_file);
	{
	    int		len = strlen(target_interface_name);
	    if (    (len >= 2) 
		&& (   util_streq(&(target_interface_name[len-2]), ".G")
		    || util_streq(&(target_interface_name[len-2]), ".P")))
	    {
		target_interface_name[len-2] = 0;
	    }
	}

	util_strncpy(target_obj_name, istr_string(obj_name), 
			GIL_MAX_NAME_SIZE);
	if (item_label != NULL)
	{
	    util_strncpy(target_item_label, istr_string(item_label), 
			GIL_MAX_NAME_SIZE);
	}
    }
    else 	/* ! obj_is_project() */
    {
        if (parent_name != NULL)
        {
            /* we have parent name and object name */
            util_strncpy(target_parent_name, istr_string(parent_name), 
			GIL_MAX_NAME_SIZE);
        }

	util_strncpy(target_obj_name, istr_string(obj_name), 
			GIL_MAX_NAME_SIZE);
        if (item_label != NULL)
        {
            /* we have object name and item_label */
            util_strncpy(target_item_label, istr_string(item_label),
		GIL_MAX_NAME_SIZE);
        }
     }

     /*
      * We've got the name broken down into the appropriate pieces.
      * Now find the actual target.
      */
    /*util_dprintf(3, "finding: module:'%s' parent:'%s' obj:'%s' item:'%s'\n",
	target_interface_name, target_parent_name, 
	target_obj_name, target_item_label);*/
    

    /*
     * Find target project
     */
    target_project = obj_get_project(module);

    /*
     * Find target module
     */
    if (util_strempty(target_interface_name))
    {
	target_module = module;
    }
    else
    {
	/* find specified intefarce (module) */
	for (trav_open(&trav, target_project, AB_TRAV_MODULES);
		(target_module = trav_next(&trav)) != NULL; )
	{
	    if (   (target_module != target_project)
		&& (util_streq(
			obj_get_file(target_module), target_interface_file)))
	    {
		break;
	    }
	}
	trav_close(&trav);
	if (target_module == NULL)
	{
	    target_module = obj_create(AB_TYPE_MODULE, target_project);
	    obj_set_is_defined(target_module, FALSE);
	    obj_set_file(target_module, target_interface_file);
	    obj_set_name(target_module, target_interface_name);
	}
    }

    /*
     * Find target parent
     */
    if (util_strempty(target_parent_name))
    {
	target_parent = target_module;
    }
    else
    {
	for (trav_open(&trav, target_module, 
			AB_TRAV_ALL | AB_TRAV_MOD_PARENTS_FIRST);
	    	(target_parent = trav_next(&trav)) != NULL; )
	{
	    if (   (target_parent != target_module)
		&& (util_streq(
			obj_get_name(target_parent), target_parent_name)))
	    {
		break;
	    }
	}
	trav_close(&trav);
	if (target_parent == NULL)
	{
	    target_parent = obj_create(AB_TYPE_UNDEF, target_module);
	    obj_set_is_defined(target_parent, FALSE);
	    obj_set_file(target_parent, target_interface_file);
	    obj_set_name(target_parent, target_parent_name);
	}
    }

    /*
     * Find target obj
     */
    for (trav_open(&trav, target_parent,
			AB_TRAV_ALL | AB_TRAV_MOD_PARENTS_FIRST);
		(target_obj = trav_next(&trav)) != NULL; )
    {
	if (   (target_obj != target_parent)
	   && util_streq(target_obj_name, obj_get_name(target_obj)))
	{
	    break;
	}
    }
    trav_close(&trav);
    if (target_obj == NULL)
    {
        target_obj = obj_create(AB_TYPE_UNDEF, target_parent);
        obj_set_is_defined(target_obj, FALSE);
        obj_set_file(target_obj, target_interface_file);
        obj_set_name(target_obj, target_obj_name);
    }

    /*
     * Find item
     */
    if (util_strempty(target_item_label))
    {
	target_item = NULL;
    }
    else
    {
	for (trav_open(&trav, target_obj, AB_TRAV_ITEMS);
		(target_item = trav_next(&trav)) != NULL; )
	{
	    if (   (target_item != target_obj)
		&& util_streq(obj_get_label(target_item), target_item_label))
	    {
		break;
	    }
	}
	trav_close(&trav);
	if (target_item == NULL)
	{
	    target_item = obj_create(AB_TYPE_ITEM, target_obj);
	    obj_set_is_defined(target_item, FALSE);
	    obj_set_file(target_item, target_interface_file);
	    obj_set_label(target_item, target_item_label);
	    obj_set_name_from_label(target_item, 
				obj_get_name(obj_get_parent(target_item)));
	}
    }

    if (target_item != NULL)
    {
	target = target_item;
    }
    else
    {
	target = target_obj;
    }

epilogue:
    return target;
}
Пример #10
0
/*
 * 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;
}