]> rtime.felk.cvut.cz Git - orte.git/blob - orte/idl-compiler/orte-idl-c-backend.c
JORTE: ignore 'int-to-pointer' and 'pointer-to-int' compiler warnings
[orte.git] / orte / idl-compiler / orte-idl-c-backend.c
1 //#include "config.h"
2
3 #include "orte-idl-c-backend.h"
4 #include <stdio.h>
5 #include <string.h>
6 #include <ctype.h>
7 #include <errno.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10
11 static FILE *out_for_pass(const char *input_filename, int pass, 
12                           OIDL_Run_Info *rinfo);
13
14 gboolean
15 orte_idl_output_c (IDL_tree       tree,
16                     OIDL_Run_Info *rinfo)
17 {
18   int i;
19   char *ctmp;
20   OIDL_C_Info ci;
21
22   ci.base_name = g_path_get_basename(rinfo->input_filename);
23   ctmp = strrchr(ci.base_name, '.');
24   g_assert(ctmp);
25   *ctmp = '\0';
26
27   ci.c_base_name = g_strdup(ci.base_name);
28   if(!isalpha((guchar)ci.c_base_name[0]))
29     ci.c_base_name[0] = '_';
30   for(i = 0; ci.c_base_name[i]; i++) {
31     if(!isalnum((guchar)ci.c_base_name[i])) ci.c_base_name[i] = '_';
32   }
33
34   ci.ext_dcls = g_string_new(NULL);
35
36   ci.do_impl_hack = 1;
37   for(i = 0; i < OUTPUT_NUM_PASSES; i++) {
38     if( (1 << i) & rinfo->enabled_passes) {
39       ci.fh = out_for_pass(rinfo->input_filename, 1 << i, rinfo);
40       
41       switch(1 << i) {
42       case OUTPUT_HEADERS:
43         orte_idl_output_c_headers(tree, rinfo, &ci);
44         break;
45       case OUTPUT_IMPLS:
46         orte_idl_output_c_impls(tree, rinfo, &ci);
47         break;
48       }
49 //      if (1 << i == OUTPUT_DEPS)
50 //      fclose(ci.fh);
51 //      else 
52         pclose(ci.fh);
53     }
54   }
55   g_string_free(ci.ext_dcls,TRUE);
56
57   return TRUE;
58 }
59
60 char *
61 orte_idl_c_filename_for_pass (const char *input_filename, 
62                                int pass)
63 {
64         char *filename;
65         char *basename;
66         char *dot;
67         const char *tack_on = NULL;
68   
69         basename = g_path_get_basename (input_filename);
70         dot = strrchr (basename, '.');
71         if (dot != NULL)
72                 *dot = '\0';
73
74         switch (pass) {
75         case OUTPUT_HEADERS:
76                 tack_on = ".h";
77                 break;
78         case OUTPUT_IMPLS:
79                 tack_on = ".c";
80                 break;
81         default:
82                 g_error("Unknown output pass");
83                 break;
84         }
85
86         filename = g_strconcat (basename, tack_on, NULL);
87         g_free (basename);
88
89         return filename;
90 }
91
92 static FILE *
93 out_for_pass (const char    *input_filename,
94               int            pass,
95               OIDL_Run_Info *rinfo)
96 {
97         FILE *fp;
98         char *output_filename;
99         char *cmdline;
100
101 /*      if (pass == OUTPUT_DEPS) {
102                 if (!g_file_test (".deps", G_FILE_TEST_IS_DIR)) {
103                         if (mkdir (".deps", 0775) < 0) {
104                                 g_warning ("failed to create '.deps' directory '%s'",
105                                            strerror (errno));
106                                 return NULL;
107                         }
108                 }
109                 
110                 if (rinfo->deps_file)
111                         fp =  fopen (rinfo->deps_file, "w");
112                 else
113                         fp = NULL;
114
115                 if (fp == NULL) 
116                         g_warning ("failed to open '%s': %s\n",
117                                    rinfo->deps_file, strerror (errno));
118                 
119         } else {*/
120                 output_filename = orte_idl_c_filename_for_pass (input_filename, pass);
121
122                 cmdline = g_alloca (strlen (rinfo->output_formatter) +
123                                     strlen (output_filename) +
124                                     sizeof(" > "));
125                 sprintf (cmdline, "%s > %s", rinfo->output_formatter, output_filename);
126
127                 g_free (output_filename);
128
129                 /* Many versions of cpp do evil translating internal
130                 * strings, producing bogus output, so clobber LC_ALL */
131                 putenv ("LC_ALL=C");
132                 fp = popen (cmdline, "w");
133
134                 if (fp == NULL)
135                         g_error ("failed to popen '%s': %s\n", cmdline, strerror(errno));
136 //      }
137
138         return fp;
139 }