PageRenderTime 47ms CodeModel.GetById 1ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Source/Modules/swigmain.cxx

#
C++ | 211 lines | 155 code | 23 blank | 33 comment | 41 complexity | 2f1d9d228e596db6048921fb9b682084 MD5 | raw file
  1/* ----------------------------------------------------------------------------- 
  2 * This file is part of SWIG, which is licensed as a whole under version 3 
  3 * (or any later version) of the GNU General Public License. Some additional
  4 * terms also apply to certain portions of SWIG. The full details of the SWIG
  5 * license and copyrights can be found in the LICENSE and COPYRIGHT files
  6 * included with the SWIG source code as distributed by the SWIG developers
  7 * and at http://www.swig.org/legal.html.
  8 *
  9 * swigmain.cxx
 10 *
 11 * Simplified Wrapper and Interface Generator  (SWIG)
 12 *
 13 * This file is the main entry point to SWIG.  It collects the command
 14 * line options, registers built-in language modules, and instantiates
 15 * a module for code generation.   If adding new language modules
 16 * to SWIG, you would modify this file.
 17 * ----------------------------------------------------------------------------- */
 18
 19char cvsroot_swigmain_cxx[] = "$Id: swigmain.cxx 12299 2010-11-18 00:24:02Z klickverbot $";
 20
 21#include "swigmod.h"
 22#include <ctype.h>
 23
 24/* Module factories.  These functions are used to instantiate
 25   the built-in language modules.    If adding a new language
 26   module to SWIG, place a similar function here. Make sure
 27   the function has "C" linkage.  This is required so that modules
 28   can be dynamically loaded in future versions. */
 29
 30extern "C" {
 31  Language *swig_tcl(void);
 32  Language *swig_python(void);
 33  Language *swig_perl5(void);
 34  Language *swig_ruby(void);
 35  Language *swig_guile(void);
 36  Language *swig_modula3(void);
 37  Language *swig_mzscheme(void);
 38  Language *swig_java(void);
 39  Language *swig_php(void);
 40  Language *swig_php4(void);
 41  Language *swig_ocaml(void);
 42  Language *swig_octave(void);
 43  Language *swig_pike(void);
 44  Language *swig_sexp(void);
 45  Language *swig_xml(void);
 46  Language *swig_chicken(void);
 47  Language *swig_csharp(void);
 48  Language *swig_allegrocl(void);
 49  Language *swig_lua(void);
 50  Language *swig_clisp(void);
 51  Language *swig_cffi(void);
 52  Language *swig_uffi(void);
 53  Language *swig_r(void);
 54  Language *swig_go(void);
 55  Language *swig_d(void);
 56}
 57
 58struct swig_module {
 59  const char *name;
 60  ModuleFactory fac;
 61  const char *help;
 62};
 63
 64/* Association of command line options to language modules.
 65   Place an entry for new language modules here, keeping the
 66   list sorted alphabetically. */
 67
 68static swig_module modules[] = {
 69  {"-allegrocl", swig_allegrocl, "ALLEGROCL"},
 70  {"-chicken", swig_chicken, "CHICKEN"},
 71  {"-clisp", swig_clisp, "CLISP"},
 72  {"-cffi", swig_cffi, "CFFI"},
 73  {"-csharp", swig_csharp, "C#"},
 74  {"-d", swig_d, "D"},
 75  {"-go", swig_go, "Go"},
 76  {"-guile", swig_guile, "Guile"},
 77  {"-java", swig_java, "Java"},
 78  {"-lua", swig_lua, "Lua"},
 79  {"-modula3", swig_modula3, "Modula 3"},
 80  {"-mzscheme", swig_mzscheme, "Mzscheme"},
 81  {"-ocaml", swig_ocaml, "Ocaml"},
 82  {"-octave", swig_octave, "Octave"},
 83  {"-perl", swig_perl5, "Perl"},
 84  {"-perl5", swig_perl5, 0},
 85  {"-php", swig_php, "PHP"},
 86  {"-php4", swig_php4, 0},
 87  {"-php5", swig_php, 0},
 88  {"-pike", swig_pike, "Pike"},
 89  {"-python", swig_python, "Python"},
 90  {"-r", swig_r, "R (aka GNU S)"},
 91  {"-ruby", swig_ruby, "Ruby"},
 92  {"-sexp", swig_sexp, "Lisp S-Expressions"},
 93  {"-tcl", swig_tcl, "Tcl"},
 94  {"-tcl8", swig_tcl, 0},
 95  {"-uffi", swig_uffi, "Common Lisp / UFFI"},
 96  {"-xml", swig_xml, "XML"},
 97  {NULL, NULL, NULL}
 98};
 99
100#ifdef MACSWIG
101#include <console.h>
102#include <SIOUX.h>
103#endif
104
105#ifndef SWIG_LANG
106#define SWIG_LANG "-python"
107#endif
108
109//-----------------------------------------------------------------
110// main()
111//
112// Main program.    Initializes the files and starts the parser.
113//-----------------------------------------------------------------
114
115void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], int *nargc, char ***nargv) {
116  if (!env) {
117    *nargc = oargc;
118    *nargv = oargv;
119    return;
120  }
121
122  int argc = 1;
123  int arge = oargc + 1024;
124  char **argv = (char **) malloc(sizeof(char *) * (arge));
125  char *buffer = (char *) malloc(2048);
126  char *b = buffer;
127  char *be = b + 1023;
128  const char *c = env;
129  while ((b != be) && *c && (argc < arge)) {
130    while (isspace(*c) && *c)
131      ++c;
132    if (*c) {
133      argv[argc] = b;
134      ++argc;
135    }
136    while ((b != be) && *c && !isspace(*c)) {
137      *(b++) = *(c++);
138    }
139    *b++ = 0;
140  }
141
142  argv[0] = oargv[0];
143  for (int i = 1; (i < oargc) && (argc < arge); ++i, ++argc) {
144    argv[argc] = oargv[i];
145  }
146
147  *nargc = argc;
148  *nargv = argv;
149}
150
151int main(int margc, char **margv) {
152  int i;
153  Language *dl = 0;
154  ModuleFactory fac = 0;
155
156  int argc;
157  char **argv;
158
159  SWIG_merge_envopt(getenv("SWIG_FEATURES"), margc, margv, &argc, &argv);
160
161#ifdef MACSWIG
162  SIOUXSettings.asktosaveonclose = false;
163  argc = ccommand(&argv);
164#endif
165
166  /* Register built-in modules */
167  for (i = 0; modules[i].name; i++) {
168    Swig_register_module(modules[i].name, modules[i].fac);
169  }
170
171  Swig_init_args(argc, argv);
172
173  /* Get options */
174  for (i = 1; i < argc; i++) {
175    if (argv[i]) {
176      fac = Swig_find_module(argv[i]);
177      if (fac) {
178	dl = (fac) ();
179	Swig_mark_arg(i);
180      } else if (strcmp(argv[i], "-nolang") == 0) {
181	dl = new Language;
182	Swig_mark_arg(i);
183      } else if ((strcmp(argv[i], "-dnone") == 0) ||
184		 (strcmp(argv[i], "-dhtml") == 0) ||
185		 (strcmp(argv[i], "-dlatex") == 0) || (strcmp(argv[i], "-dascii") == 0) || (strcmp(argv[i], "-stat") == 0)) {
186	Printf(stderr, "swig: Warning. %s option deprecated.\n", argv[i]);
187	Swig_mark_arg(i);
188      } else if ((strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0)) {
189	if (strcmp(argv[i], "--help") == 0)
190	  strcpy(argv[i], "-help");
191	Printf(stdout, "Target Language Options\n");
192	for (int j = 0; modules[j].name; j++) {
193	  if (modules[j].help) {
194	    Printf(stdout, "     %-15s - Generate %s wrappers\n", modules[j].name, modules[j].help);
195	  }
196	}
197	// Swig_mark_arg not called as the general -help options also need to be displayed later on
198      }
199    }
200  }
201  if (!dl) {
202    fac = Swig_find_module(SWIG_LANG);
203    if (fac) {
204      dl = (fac) ();
205    }
206  }
207
208  int res = SWIG_main(argc, argv, dl);
209
210  return res;
211}