1 /**************************************************************************
3 orte-idl-main.c (Driver program for the IDL parser & backend)
5 Copyright (C) 1999 Elliot Lee
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.
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.
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.
21 $Id: orte-idl-main.c,v 1.2 2005/03/11 16:46:22 smolik Exp $
23 ***************************************************************************/
30 #include <libIDL/IDL.h>
33 #include "orte-idl2.h"
35 /* Settings made from the command line (prefaced with cl_) */
36 static gboolean cl_disable_headers = FALSE,
37 cl_disable_impls = FALSE;
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;
47 #define BASE_CPP_ARGS "-D__ORTE_IDL__ "
48 static GString *cl_cpp_args;
50 #define INDENT_COMMAND "cat"
52 static char *c_output_formatter = INDENT_COMMAND;
54 /* Callbacks for popt */
56 cl_libIDL_version_callback(poptContext con, enum poptCallbackReason reason,
57 const struct poptOption *opt, char *arg,
60 g_print("libIDL %s (CORBA %s)",
61 IDL_get_libver_string(),
62 IDL_get_IDLver_string());
68 cl_cpp_callback(poptContext con, enum poptCallbackReason reason,
69 const struct poptOption *opt, char *arg,
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");
79 g_string_append(cl_cpp_args, arg);
80 g_string_append_c(cl_cpp_args, ' ');
84 struct poptOption cl_libIDL_callback_options[] = {
85 {NULL, '\0', POPT_ARG_CALLBACK, (void *)cl_libIDL_version_callback,
87 {"libIDL-version", '\0', POPT_ARG_NONE, NULL, 0,
88 "Show version of libIDL used.", NULL},
89 {NULL, '\0', 0, NULL, 0, NULL, NULL}
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}
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},
117 {NULL, '\0', 0, NULL, 0, NULL, NULL}
121 /********** main routines **********/
122 int main(int argc, const char *argv[])
129 /* Argument parsing, etc. */
130 cl_cpp_args = g_string_new("-D__ORTE_IDL__ ");
132 if(getenv("C_OUTPUT_FORMATTER"))
133 c_output_formatter = getenv("C_OUTPUT_FORMATTER");
135 pcon = poptGetContext ("orte-idl", argc, argv, options, 0);
136 poptSetOtherOptionHelp (pcon, "<IDL files>");
139 poptPrintUsage(pcon, stdout, 0);
143 if((rc=poptGetNextOpt(pcon)) < -1) {
144 g_print ("orte-idl: bad argument %s: %s\n",
145 poptBadOption(pcon, POPT_BADOPTION_NOALIAS),
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);
159 rinfo.deps_file = cl_deps_file;
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;
166 printf (" %s mode, passes: %s%s\n\n",
167 rinfo.is_pidl ? "pidl" : "",
168 cl_disable_headers ? "" : "headers ",
169 cl_disable_impls ? "" : "impls ");
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);
178 g_free(rinfo.input_filename);