Beispiel #1
0
/*
 * Traverse object list and write out callback decls, for those
 * connections with the proper value of auto_named.
 */
static int
write_user_or_auto_decls(
			GenCodeInfo genCodeInfo, 
			ABObj project, 
			BOOL auto_named)
{
    AB_TRAVERSAL        trav;
    ABObj               action = NULL;
    AB_ACTION_INFO     *actinfo = NULL;
    STRING              func_name = NULL;

    for (trav_open(&trav, project, AB_TRAV_ACTIONS);
	 (action = trav_next(&trav)) != NULL;)
    {
	/* If action is not a cross-module connection AND it
	 * is not a shared connection, continue.
	 */
	if ( !obj_is_cross_module(action) &&
	     ( mfobj_has_flags(action, CGenFlagIsDuplicateDef) ||
	       (!mfobj_has_flags(action, CGenFlagWriteDefToProjFile))
	     )
	   )
	{
	    continue;
	}

	actinfo = &(action->info.action);
	func_name = abmfP_get_action_name(action);
	if (!util_xor(actinfo->auto_named, auto_named))
	{
	    abmfP_write_action_func_decl(genCodeInfo, action);
	    abio_puts(genCodeInfo->code_file, nlstr);
	}
    }
    trav_close(&trav);
    return 0;
}
Beispiel #2
0
/*
 * 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;
}
Beispiel #3
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;
}