]> rtime.felk.cvut.cz Git - orte.git/blob - orte/idl-compiler/orte-idl-main.c
JORTE: ignore 'int-to-pointer' and 'pointer-to-int' compiler warnings
[orte.git] / orte / idl-compiler / orte-idl-main.c
1 /**************************************************************************
2
3     orte-idl-main.c (Driver program for the IDL parser & backend)
4
5     Copyright (C) 1999 Elliot Lee
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21     $Id: orte-idl-main.c,v 1.2 2005/03/11 16:46:22 smolik Exp $
22
23 ***************************************************************************/
24
25 #include <unistd.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #include <glib.h>
30 #include <libIDL/IDL.h>
31 #include <popt.h>
32
33 #include "orte-idl2.h"
34
35 /* Settings made from the command line (prefaced with cl_) */
36 static gboolean cl_disable_headers = FALSE,
37   cl_disable_impls = FALSE;
38
39 static int cl_idlwarnlevel = 2;
40 static int cl_debuglevel = 0;
41 static int cl_is_pidl = 0;
42 static char *cl_output_lang = "c";
43 static char *cl_header_guard_prefix = "";
44 static char *cl_deps_file = NULL;
45 static gboolean cl_onlytop = FALSE;
46
47 #define BASE_CPP_ARGS "-D__ORTE_IDL__ "
48 static GString *cl_cpp_args;
49
50 #define INDENT_COMMAND "cat"
51
52 static char *c_output_formatter = INDENT_COMMAND;
53
54 /* Callbacks for popt */
55 static void
56 cl_libIDL_version_callback(poptContext con, enum poptCallbackReason reason,
57                            const struct poptOption *opt, char *arg,
58                            void *data)
59 {
60   g_print("libIDL %s (CORBA %s)",
61           IDL_get_libver_string(),
62           IDL_get_IDLver_string());
63
64   exit(0);
65 }
66
67 static void
68 cl_cpp_callback(poptContext con, enum poptCallbackReason reason,
69                 const struct poptOption *opt, char *arg,
70                 void *data)
71 {
72   g_assert(opt!=NULL);
73
74   if(opt->shortName=='D')
75     g_string_append(cl_cpp_args, "-D");
76   else if(opt->shortName=='I')
77     g_string_append(cl_cpp_args, "-I");
78
79   g_string_append(cl_cpp_args, arg);
80   g_string_append_c(cl_cpp_args, ' ');
81 }
82
83 static const
84 struct poptOption cl_libIDL_callback_options[] = {
85   {NULL, '\0', POPT_ARG_CALLBACK, (void *)cl_libIDL_version_callback,
86    0, NULL, NULL},
87   {"libIDL-version", '\0', POPT_ARG_NONE, NULL, 0,
88    "Show version of libIDL used.", NULL},
89   {NULL, '\0', 0, NULL, 0, NULL, NULL}
90 };
91
92 static const
93 struct poptOption cl_cpp_callback_options[] = {
94   {NULL, '\0', POPT_ARG_CALLBACK, (void *)cl_cpp_callback, 0, NULL, NULL},
95   {"define", 'D', POPT_ARGFLAG_ONEDASH | POPT_ARG_STRING, NULL, 0,
96    "Define value in preprocessor", NULL},
97   {"include", 'I', POPT_ARGFLAG_ONEDASH | POPT_ARG_STRING, NULL, 0,
98    "Add search path for include files", NULL},
99   {NULL, '\0', 0, NULL, 0, NULL, NULL}
100 };
101
102 static const
103 struct poptOption options[] = {
104   {NULL, '\0', POPT_ARG_INCLUDE_TABLE, &cl_cpp_callback_options, 0, NULL, NULL},
105   {NULL, '\0', POPT_ARG_INCLUDE_TABLE, &cl_libIDL_callback_options, 0, NULL, NULL},
106   {"lang", 'l', POPT_ARG_STRING, &cl_output_lang, 0, "Output language (default is C)", NULL},
107   {"debug", 'd', POPT_ARG_INT, &cl_debuglevel, 0, "Debug level 0 to 4", NULL},
108   {"idlwarnlevel", '\0', POPT_ARG_INT, &cl_idlwarnlevel, 0, "IDL warning level 0 to 4, default is 2", NULL},
109   {"noheaders", '\0', POPT_ARG_NONE, &cl_disable_headers, 0, "Don't output headers", NULL},
110   {"noimpls", '\0', POPT_ARG_NONE, &cl_disable_impls, 0, "Don't output implementations", NULL},
111   {"c-output-formatter", '\0', POPT_ARG_STRING, &c_output_formatter, 0, "Program to use to format output (normally, indent)", "PROGRAM"},
112   {"onlytop", '\0', POPT_ARG_NONE, &cl_onlytop, 0, "Inhibit includes", NULL},
113   {"pidl", '\0', POPT_ARG_NONE, &cl_is_pidl, 0, "Treat as Pseudo IDL", NULL},
114   {"deps", '\0', POPT_ARG_STRING, &cl_deps_file, 0, "Generate dependency info suitable for inclusion in Makefile", "FILENAME"},
115   {"headerguardprefix", '\0', POPT_ARG_STRING, &cl_header_guard_prefix, 0, "Prefix for #ifdef header guards. Sometimes useful to avoid conflicts.", NULL},
116   POPT_AUTOHELP
117   {NULL, '\0', 0, NULL, 0, NULL, NULL}
118 };
119
120
121 /********** main routines **********/
122 int main(int argc, const char *argv[])
123 {
124   poptContext pcon;
125   int rc, retval = 0;
126   const char *arg;
127   OIDL_Run_Info rinfo;
128
129   /* Argument parsing, etc. */
130   cl_cpp_args = g_string_new("-D__ORTE_IDL__ ");
131
132   if(getenv("C_OUTPUT_FORMATTER"))
133     c_output_formatter = getenv("C_OUTPUT_FORMATTER");
134
135   pcon = poptGetContext ("orte-idl", argc, argv, options, 0);
136   poptSetOtherOptionHelp (pcon, "<IDL files>");
137
138   if(argc < 2) {
139         poptPrintUsage(pcon, stdout, 0);
140         return 0;
141   }
142
143   if((rc=poptGetNextOpt(pcon)) < -1) {
144     g_print ("orte-idl: bad argument %s: %s\n", 
145                 poptBadOption(pcon, POPT_BADOPTION_NOALIAS),
146                 poptStrerror(rc));
147     exit(0);
148   }
149
150   /* Prep our run info for the backend */
151   rinfo.cpp_args = cl_cpp_args->str;
152   rinfo.debug_level = cl_debuglevel;
153   rinfo.idl_warn_level = cl_idlwarnlevel;
154   rinfo.is_pidl = cl_is_pidl;
155   rinfo.enabled_passes =
156      (cl_disable_headers?0:OUTPUT_HEADERS)
157     |(cl_disable_impls?0:OUTPUT_IMPLS);
158
159   rinfo.deps_file = cl_deps_file;
160
161   rinfo.output_formatter = c_output_formatter;
162   rinfo.output_language = cl_output_lang;
163   rinfo.header_guard_prefix = cl_header_guard_prefix;
164   rinfo.onlytop = cl_onlytop;
165   
166   printf (" %s mode, passes: %s%s\n\n",
167           rinfo.is_pidl ? "pidl" : "",
168           cl_disable_headers ? "" : "headers ",
169           cl_disable_impls ? "" : "impls ");
170            
171   /* Do it */
172   while((arg=poptGetArg(pcon))!=NULL) {
173     rinfo.input_filename = g_strdup (arg); /* g_path_get_basename(arg); - what !? */
174     if (!orte_idl_to_backend(arg, &rinfo)) {
175       g_warning("%s compilation failed", arg);
176       retval = 1;
177     }
178     g_free(rinfo.input_filename);
179   }
180
181   return retval;
182 }