Esempio n. 1
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
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
}