3 #include "forb-idl-c-backend.h"
11 #include <glib/gstdio.h>
13 static FILE *out_for_pass(const char *input_filename, int pass,
14 OIDL_Run_Info *rinfo);
17 forb_idl_output_c (IDL_tree tree,
24 ci.base_name = g_path_get_basename(rinfo->input_filename);
25 ctmp = strrchr(ci.base_name, '.');
29 ci.c_base_name = g_strdup(ci.base_name);
30 if(!isalpha((guchar)ci.c_base_name[0]))
31 ci.c_base_name[0] = '_';
32 for(i = 0; ci.c_base_name[i]; i++) {
33 if(!isalnum((guchar)ci.c_base_name[i])) ci.c_base_name[i] = '_';
36 ci.ext_dcls = g_string_new(NULL);
39 ci.do_skel_defs = rinfo->do_skel_defs;
40 for(i = 0; i < OUTPUT_NUM_PASSES; i++) {
41 if( (1 << i) & rinfo->enabled_passes) {
42 ci.fh = out_for_pass(rinfo->input_filename, 1 << i, rinfo);
46 forb_idl_output_c_stubs(tree, rinfo, &ci);
49 forb_idl_output_c_skeletons(tree, rinfo, &ci);
52 forb_idl_output_c_common(tree, rinfo, &ci);
55 forb_idl_output_c_headers(tree, rinfo, &ci);
58 forb_idl_output_c_skelimpl(tree, rinfo, &ci);
61 forb_idl_output_c_imodule(tree, rinfo, &ci);
64 forb_idl_output_c_deps(tree, rinfo, &ci);
70 g_string_free(ci.ext_dcls,TRUE);
76 forb_idl_c_filename_for_pass (const char *input_filename,
82 const char *tack_on = NULL;
84 basename = g_path_get_basename (input_filename);
85 dot = strrchr (basename, '.');
97 tack_on = "-common.c";
102 case OUTPUT_SKELIMPL:
103 tack_on = "-skelimpl.c";
106 tack_on = "-imodule.c";
109 g_error("Unknown output pass");
113 filename = g_strconcat (basename, tack_on, NULL);
120 out_for_pass (const char *input_filename,
122 OIDL_Run_Info *rinfo)
125 char *output_filename;
126 gchar *output_full_path = NULL;
129 if ((strlen(rinfo->output_directory)) && (!g_file_test (rinfo->output_directory, G_FILE_TEST_IS_DIR))) {
130 g_error ("ouput directory '%s' does not exist",
131 rinfo->output_directory);
135 if (pass == OUTPUT_DEPS) {
136 if (!g_file_test (".deps", G_FILE_TEST_IS_DIR)) {
137 if (g_mkdir (".deps", 0775) < 0) {
138 g_warning ("failed to create '.deps' directory '%s'",
144 if (rinfo->deps_file)
145 fp = g_fopen (rinfo->deps_file, "w");
150 g_warning ("failed to open '%s': %s\n",
151 rinfo->deps_file, g_strerror (errno));
154 output_filename = forb_idl_c_filename_for_pass (input_filename, pass);
155 output_full_path = g_build_path (G_DIR_SEPARATOR_S, rinfo->output_directory, output_filename, NULL);
156 g_free (output_filename);
158 fp = g_fopen (output_full_path, "w+");
160 g_error ("failed to fopen '%s': %s\n", output_full_path, g_strerror(errno));
162 g_free (output_full_path);