PageRenderTime 215ms CodeModel.GetById 25ms app.highlight 169ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-26/SWIG/Source/Modules/main.cxx

#
C++ | 980 lines | 807 code | 88 blank | 85 comment | 349 complexity | 902cfd62ebe1d6ffc22ace01b546ea5f MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1/* -----------------------------------------------------------------------------
  2 * main.cxx
  3 *
  4 *     Main entry point to the SWIG core.
  5 *
  6 * Author(s) : David Beazley (beazley@cs.uchicago.edu)
  7 *
  8 * Copyright (C) 1998-2000.  The University of Chicago
  9 * Copyright (C) 1995-1998.  The University of Utah and The Regents of the
 10 *                           University of California.
 11 *
 12 * See the file LICENSE for information on usage and redistribution.
 13 * ----------------------------------------------------------------------------- */
 14
 15char cvsroot_main_cxx[] = "$Header$";
 16
 17#if defined(_WIN32)
 18#define WIN32_LEAN_AND_MEAN
 19#include <windows.h>
 20#endif
 21
 22#include "swigmod.h"
 23
 24#include "swigwarn.h"
 25#include "cparse.h"
 26#include <ctype.h>
 27
 28// Global variables
 29
 30    char       LibDir[512];                     // Library directory
 31    Language  *lang;                            // Language method
 32    int        CPlusPlus = 0;
 33    int        Extend = 0;                      // Extend flag
 34    int        ForceExtern = 0;                 // Force extern mode
 35    int        GenerateDefault = 1;             // Generate default constructors
 36    char      *Config = 0;
 37    int        Verbose = 0;
 38    int        AddExtern = 0;
 39    int        NoExcept = 0;
 40    char      *SwigLib;
 41    int        SwigRuntime = 0;                 // 0 = no option, 1 = -c or -runtime, 2 = -noruntime
 42
 43
 44extern "C" {
 45extern String  *ModuleName;
 46}
 47
 48static const char *usage1 = (const char*)"\
 49\nGeneral Options\n\
 50     -c++            - Enable C++ processing\n\
 51     -co <file>      - Check <file> out of the SWIG library\n\
 52     -directors      - Turn on director mode for all the classes, mainly for testing \n\
 53     -dirprot        - Turn on wrapping of protected members for director classes\n\
 54     -D<symbol>      - Define a symbol <symbol> (for conditional compilation)\n\
 55     -E              - Preprocess only, does not generate wrapper code\n\
 56     -external-runtime [file] - Export the swig runtime stack \n\
 57     -fcompact       - Compile in compact mode\n\
 58     -features list  - Set a list of global features, where the syntax list is \n\
 59                       -features directors,autodoc=1      \n\
 60                       if not explicit value is given to the feature, a '1' is used \n\
 61     -fvirtual       - Compile in virtual elimination mode\n\
 62     -Fstandard      - Display error/warning messages in commonly used format\n\
 63     -Fmicrosoft     - Display error/warning messages in Microsoft format\n\
 64     -help           - This output\n\
 65     -I<dir>         - Look for SWIG files in <dir>\n\
 66     -I-             - Don't search the current directory\n\
 67     -ignoremissing  - Ignore missing include files\n\
 68     -importall      - Follow all #include statements as imports\n\
 69     -includeall     - Follow all #include statements\n\
 70     -l<ifile>       - Include SWIG library file <ifile>\n\
 71     -M              - List all dependencies \n\
 72     -MD             - Is equivalent to `-M -MF <file>', except `-E' is not implied\n\
 73     -MF <file>      - Generate dependencies into <file> and continue generating wrappers \n\
 74     -MM             - List dependencies, but omit files in SWIG library\n\
 75     -MMD            - Like `-MD', but omit files in SWIG library\n\
 76";
 77// usage string split in two otherwise string is too big for some compilers
 78static const char *usage2 = (const char*)"\
 79     -makedefault    - Create default constructors/destructors (the default)\n\
 80     -module <name>  - Set module name to <name>\n\
 81     -nocontract     - Turn off contract checking \n\
 82     -nodefault      - Do not generate constructors/destructors\n\
 83     -nodirprot      - Do not wrap director protected members\n\
 84     -noexcept       - Do not wrap exception specifiers\n\
 85     -addextern      - Add extra extern declarations\n\
 86     -nopreprocess   - Skip the preprocessor step\n\
 87     -notemplatereduce - Disable reduction of the typedefs in templates \n\
 88     -o <outfile>    - Set name of the output file to <outfile>\n\
 89     -oh <headfile>  - Set name of the output header file to <headfile>\n\
 90     -outdir <dir>   - Set language specific files output directory\n\
 91     -small          - Compile in virtual elimination & compact mode\n\
 92     -swiglib        - Report location of SWIG library and exit\n\
 93     -templatereduce - Reduce all the typedefs in templates \n\
 94     -v              - Run in verbose mode\n\
 95     -version        - Print SWIG version number\n\
 96     -Wall           - Enable all warning messages\n\
 97     -Wallkw         - Enable keyword warnings for all the supported languages\n\
 98     -Werror         - Treat warnings as errors\n\
 99     -w<list>        - Suppress/add warning messages eg -w401,+321 - see Warnings.html\n\
100     -xmlout <file>  - Write XML version of the parse tree to <file> after normal processing\n\
101\n";
102
103// Local variables
104static int     freeze = 0;
105static String  *lang_config = 0;
106static char    *hpp_extension = (char *) "h";
107static char    *cpp_extension = (char *) "cxx";
108static char    *depends_extension = (char *) "d";
109static String  *outdir = 0;
110static String  *xmlout = 0;
111static int     help = 0;
112static int     checkout = 0;
113static int     cpp_only = 0;
114static int     no_cpp = 0;
115static char   *outfile_name = 0;
116static char   *outfile_name_h = 0;
117static int     tm_debug = 0;
118static int     dump_tags = 0;
119static int     dump_tree = 0;
120static int     dump_xml = 0;
121static int     browse = 0;
122static int     dump_typedef = 0;
123static int     dump_classes = 0;
124static int     werror = 0;
125static int     depend = 0;
126static int     depend_only = 0;
127static int     memory_debug = 0;
128static int     allkw = 0;
129static DOH    *libfiles = 0;
130static DOH    *cpps = 0 ;
131static String  *dependencies_file = 0;
132static File    *f_dependencies_file = 0;
133static int     external_runtime = 0;
134static String *external_runtime_name = 0;
135
136// -----------------------------------------------------------------------------
137// check_suffix(char *name)
138//
139// Checks the suffix of a file to see if we should emit extern declarations.
140// -----------------------------------------------------------------------------
141
142static int check_suffix(char *name) {
143  char *c;
144  if (!name) return 0;
145  c = Swig_file_suffix(name);
146  if ((strcmp(c,".c") == 0) ||
147      (strcmp(c,".C") == 0) ||
148      (strcmp(c,".cc") == 0) ||
149      (strcmp(c,".cxx") == 0) ||
150      (strcmp(c,".c++") == 0) ||
151      (strcmp(c,".cpp") == 0)) {
152    return 1;
153  }
154  return 0;
155}
156
157// -----------------------------------------------------------------------------
158// install_opts(int argc, char *argv[])
159// Install all command line options as preprocessor symbols
160// ----------------------------------------------------------------------------- 
161
162static void install_opts(int argc, char *argv[]) {
163  int i;
164  int noopt = 0;
165  char *c;
166  for (i = 1; i < (argc-1); i++) {
167    if (argv[i]) {
168      if ((*argv[i] == '-') && (!isupper(*(argv[i]+1)))) {
169	String *opt = NewStringf("SWIGOPT%(upper)s", argv[i]);
170	Replaceall(opt,"-","_");
171	c = Char(opt);
172	noopt = 0;
173	while (*c) {
174	  if (!(isalnum(*c) || (*c == '_'))) {
175	    noopt = 1;
176	    break;
177	  }
178	  c++;
179	}
180	if (((i+1) < (argc-1)) && (argv[i+1]) && (*argv[i+1] != '-')) {
181	  Printf(opt," %s", argv[i+1]);
182	  i++;
183	} else {
184	  Printf(opt," 1");
185	}
186	if (!noopt) {
187	  /*	  Printf(stdout,"%s\n", opt); */
188	  Preprocessor_define(opt, 0);
189	}
190      }
191    }
192  }
193}
194
195// -----------------------------------------------------------------------------
196// Sets the output directory for language specific (proxy) files if not set and 
197// adds trailing file separator if necessary.
198// ----------------------------------------------------------------------------- 
199
200static void set_outdir(const String *c_wrapper_file_dir) {
201
202    // Add file delimiter if not present in output directory name
203    if (outdir && Len(outdir) != 0) {
204        const char* outd = Char(outdir);
205        if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMETER), SWIG_FILE_DELIMETER) != 0)
206            Printv(outdir, SWIG_FILE_DELIMETER, NIL);
207    }
208    // Use the C wrapper file's directory if the output directory has not been set by user
209    if (!outdir)
210        outdir = NewString(c_wrapper_file_dir);
211}
212
213//-----------------------------------------------------------------
214// main()
215//
216// Main program.    Initializes the files and starts the parser.
217//-----------------------------------------------------------------
218
219/* This function sets the name of the configuration file */
220
221void SWIG_config_file(const String_or_char *filename) {
222  lang_config = NewString(filename);
223}
224
225void SWIG_library_directory(const char *filename) {
226  strcpy(LibDir,filename);
227}
228
229// Returns the directory for generating language specific files (non C/C++ files)
230const String *SWIG_output_directory() {
231    assert(outdir);
232    return outdir;
233}
234
235void SWIG_config_cppext(const char *ext) {
236  cpp_extension = (char *) ext;
237}
238
239void SWIG_getfeatures(const char *c) 
240{
241  char feature[64];
242  char *fb = feature;
243  char *fe = fb + 63;
244  Hash *features_hash = Swig_cparse_features();
245  String *name = NewString("");
246  /* Printf(stderr,"all features %s\n", c); */
247  while (*c) {
248    char *f = fb;
249    String *fname = NewString("feature:");
250    String *fvalue = NewString("");
251    while ((f != fe) && *c != '=' && *c != ',' && *c) {
252      *(f++) = *(c++);
253    }
254    *f = 0;
255    Printf(fname,"%s",feature);
256    if (*c && *(c++) == '=') {
257      char value[64];
258      char *v = value;
259      char *ve = v + 63;
260      while ((v != ve) &&  *c != ',' && *c && !isspace(*c)) {
261	*(v++) = *(c++);
262      }
263      *v = 0;
264      Printf(fvalue,"%s",value);
265    } else {
266      Printf(fvalue,"1");
267    }    
268    /* Printf(stderr,"%s %s\n", fname, fvalue);  */
269    Swig_feature_set(features_hash,name,0,fname,fvalue,0);
270    Delete(fname);
271    Delete(fvalue);
272  }
273  Delete(name);
274}
275
276/* This function handles the -external-runtime command option */
277static void SWIG_dump_runtime() {
278  String *outfile;
279  File *runtime;
280  String *s;
281
282  outfile = external_runtime_name;
283  if (!outfile) {
284    outfile = lang->defaultExternalRuntimeFilename();
285    if (!outfile) {
286      Printf(stderr, "*** Please provide a filename for the external runtime\n");
287      SWIG_exit(EXIT_FAILURE);
288    }
289  }
290
291  runtime = NewFile(outfile, "w");
292  if (!runtime) {
293    FileErrorDisplay(outfile);
294    SWIG_exit(EXIT_FAILURE);
295  }
296
297  Swig_banner(runtime);
298
299  s = Swig_include_sys("swiglabels.swg");
300  if (!s) {
301    Printf(stderr, "*** Unable to open 'swiglabels.swg'\n");
302    Close(runtime);
303    SWIG_exit(EXIT_FAILURE);
304  }
305  Printf(runtime, "%s", s);
306  Delete(s);
307  
308  s = Swig_include_sys("swigrun.swg");
309  if (!s) {
310    Printf(stderr, "*** Unable to open 'swigrun.swg'\n");
311    Close(runtime);
312    SWIG_exit(EXIT_FAILURE);
313  }
314  Printf(runtime, "%s", s);
315  Delete(s);
316
317  s = lang->runtimeCode();
318  Printf(runtime, "%s", s);
319  Delete(s);
320
321  s = Swig_include_sys("runtime.swg");
322  if (!s) {
323    Printf(stderr, "*** Unable to open 'runtime.swg'\n");
324    Close(runtime);
325    SWIG_exit(EXIT_FAILURE);
326  }
327  Printf(runtime, "%s", s);
328  Delete(s);
329  
330  Close(runtime);
331  SWIG_exit(EXIT_SUCCESS);
332}
333
334void SWIG_getoptions(int argc, char *argv[]) 
335{
336  int    i;
337  char   *includefiles[256];
338  int     includecount = 0;
339  // Get options
340  for (i = 1; i < argc; i++) {
341      if (argv[i] && !Swig_check_marked(i)) {
342	  if (strncmp(argv[i],"-I-",3) == 0) {
343	    // Don't push/pop directories
344	    Swig_set_push_dir(0);
345	    Swig_mark_arg(i);
346	  } else if (strncmp(argv[i],"-I",2) == 0) {
347	    // Add a new directory search path
348	    includefiles[includecount++] = Swig_copy_string(argv[i]+2);
349	    Swig_mark_arg(i);
350	  } else if (strncmp(argv[i],"-D",2) == 0) {
351	    DOH *d = NewString(argv[i]+2);
352	    Replace(d,(char*)"=",(char*)" ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
353	    Preprocessor_define((DOH *) d,0);
354	    // Create a symbol
355	    Swig_mark_arg(i);
356	  } else if (strcmp(argv[i],"-E") == 0) {
357	    cpp_only = 1;
358	    Swig_mark_arg(i);
359	  } else if (strcmp(argv[i],"-nopreprocess") == 0) {
360	    no_cpp = 1;
361	    Swig_mark_arg(i);
362	  } else if ((strcmp(argv[i],"-verbose") == 0) ||
363		     (strcmp(argv[i],"-v") == 0)) {
364	      Verbose = 1;
365	      Swig_mark_arg(i);
366	  } else if (strcmp(argv[i],"-c++") == 0) {
367	      CPlusPlus=1;
368	      Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
369	      Swig_cparse_cplusplus(1);
370	      Swig_mark_arg(i);
371	  } else if (strcmp(argv[i],"-fcompact") == 0) {
372	    Wrapper_compact_print_mode_set(1);
373	    Swig_mark_arg(i);
374	  } else if (strcmp(argv[i],"-fvirtual") == 0) {
375	    Wrapper_virtual_elimination_mode_set(1);
376	    Swig_mark_arg(i);
377	  } else if (strcmp(argv[i],"-directors") == 0) {
378	    Hash *features_hash = Swig_cparse_features();
379	    String *name = NewString("");
380	    String *fname = NewString("feature:director");
381	    String *fvalue = NewString("1");
382	    Swig_feature_set(features_hash,name,0,fname,fvalue,0);
383	    Wrapper_director_mode_set(1);
384	    Swig_mark_arg(i);
385	    Delete(name);
386	    Delete(fname);
387	    Delete(fvalue);
388	  } else if (strcmp(argv[i],"-dirprot") == 0) {
389	    Wrapper_director_protected_mode_set(1);
390	    Swig_mark_arg(i);
391	  } else if (strcmp(argv[i],"-nodirprot") == 0) {
392	    Wrapper_director_protected_mode_set(0);
393	    Swig_mark_arg(i);
394	  } else if (strcmp(argv[i],"-small") == 0) {
395	    Wrapper_compact_print_mode_set(1);
396	    Wrapper_virtual_elimination_mode_set(1);
397	    Swig_mark_arg(i);
398	  } else if (strcmp(argv[i], "-runtime") == 0) {
399	      Swig_mark_arg(i);
400	      Swig_warning(WARN_DEPRECATED_OPTC, "SWIG",1, "-c, -runtime, -noruntime command line options are deprecated.\n");
401	      SwigRuntime = 1;
402	  } else if ((strcmp(argv[i],"-c") == 0) || (strcmp(argv[i],"-noruntime") == 0)) {
403	      Swig_mark_arg(i);
404	      Swig_warning(WARN_DEPRECATED_OPTC, "SWIG",1, "-c, -runtime, -noruntime command line options are deprecated.\n");
405	      SwigRuntime = 2;
406	  } else if (strcmp(argv[i], "-external-runtime") == 0) {
407              external_runtime = 1;
408              Swig_mark_arg(i);
409              if (argv[i+1]) {
410                external_runtime_name = NewString(argv[i+1]);
411                Swig_mark_arg(i+1);
412                i++;
413              }
414          } else if ((strcmp(argv[i],"-make_default") == 0) || (strcmp(argv[i],"-makedefault") == 0)) {
415	    GenerateDefault = 1;
416	    Swig_mark_arg(i);
417          } else if ((strcmp(argv[i],"-no_default") == 0) || (strcmp(argv[i],"-nodefault") == 0)) {
418	    GenerateDefault = 0;
419	    Swig_mark_arg(i);
420	  } else if (strcmp(argv[i],"-noexcept") == 0) {
421	    NoExcept = 1;
422	    Swig_mark_arg(i);
423	  } else if (strcmp(argv[i],"-noextern") == 0) {
424	    Swig_warning(WARN_DEPRECATED_NOEXTERN, "SWIG",1, "-noextern command line option is deprecated; extern is no longer generated by default.\n");
425	    AddExtern = 0;
426	    Swig_mark_arg(i);
427	  } else if (strcmp(argv[i],"-addextern") == 0) {
428	    AddExtern = 1;
429	    Swig_mark_arg(i);
430	  } else if (strcmp(argv[i],"-show_templates") == 0) {
431	    Swig_cparse_debug_templates(1);
432	    Swig_mark_arg(i);
433	  } else if (strcmp(argv[i],"-templatereduce") == 0) {
434	    SWIG_cparse_template_reduce(1);
435	    Swig_mark_arg(i);
436	  } else if (strcmp(argv[i],"-notemplatereduce") == 0) {
437	    SWIG_cparse_template_reduce(0);
438	    Swig_mark_arg(i);
439          } else if (strcmp(argv[i],"-swiglib") == 0) {
440	    printf("%s\n", LibDir);
441	    SWIG_exit (EXIT_SUCCESS);
442	  } else if (strcmp(argv[i],"-o") == 0) {
443	    Swig_mark_arg(i);
444	    if (argv[i+1]) {
445	      outfile_name = Swig_copy_string(argv[i+1]);
446	      if (!outfile_name_h || !dependencies_file) {
447		char *ext = strrchr(outfile_name, '.');
448		String *basename = ext ? NewStringWithSize(outfile_name,ext-outfile_name) : NewString(outfile_name);
449                if (!dependencies_file) {
450                  dependencies_file = NewStringf("%s.%s", basename, depends_extension);
451                }
452                if (!outfile_name_h) {
453                  Printf(basename, ".%s", hpp_extension);
454                  outfile_name_h = Swig_copy_string(Char(basename));
455                  Delete(basename);
456                }
457	      }
458	      Swig_mark_arg(i+1);
459	      i++;
460	    } else {
461	      Swig_arg_error();
462	    }
463	  } else if (strcmp(argv[i],"-oh") == 0) {
464	    Swig_mark_arg(i);
465	    if (argv[i+1]) {
466	      outfile_name_h = Swig_copy_string(argv[i+1]);
467	      Swig_mark_arg(i+1);
468	      i++;
469	    } else {
470	      Swig_arg_error();
471	    }
472	  } else if (strcmp(argv[i],"-version") == 0) {
473	      fprintf(stdout,"\nSWIG Version %s\n", PACKAGE_VERSION);
474	      fprintf(stdout,"Copyright (c) 1995-1998\n");
475	      fprintf(stdout,"University of Utah and the Regents of the University of California\n");
476	      fprintf(stdout,"Copyright (c) 1998-2005\n");
477	      fprintf(stdout,"University of Chicago\n");
478	      fprintf(stdout,"Compiled with %s [%s]\n", SWIG_CXX, SWIG_PLATFORM);
479	      fprintf(stdout,"\nPlease see %s for reporting bugs and further information\n", PACKAGE_BUGREPORT);
480	      SWIG_exit (EXIT_SUCCESS);
481	  } else if (strncmp(argv[i],"-l",2) == 0) {
482	    // Add a new directory search path
483	    Append(libfiles,argv[i]+2);
484	    Swig_mark_arg(i);
485          } else if (strcmp(argv[i],"-co") == 0) {
486	    checkout = 1;
487	    Swig_mark_arg(i);
488	  } else if (strcmp(argv[i],"-features") == 0) {
489	    Swig_mark_arg(i);
490	    if (argv[i+1]) {
491	      SWIG_getfeatures(argv[i+1]);
492	      Swig_mark_arg(i+1);
493	    } else {
494	      Swig_arg_error();
495	    }
496	  } else if (strcmp(argv[i],"-freeze") == 0) {
497	    freeze = 1;
498	    Swig_mark_arg(i);
499	  } else if (strcmp(argv[i],"-includeall") == 0) {
500	    Preprocessor_include_all(1);
501	    Swig_mark_arg(i);
502	  } else if (strcmp(argv[i],"-importall") == 0) {
503	    Preprocessor_import_all(1);
504	    Swig_mark_arg(i);
505	  } else if (strcmp(argv[i],"-ignoremissing") == 0) {
506	    Preprocessor_ignore_missing(1);
507	    Swig_mark_arg(i);
508	  } else if (strcmp(argv[i],"-tm_debug") == 0) {
509	    tm_debug = 1;
510	    Swig_mark_arg(i);
511	  } else if (strcmp(argv[i],"-module") == 0) {
512	    Swig_mark_arg(i);
513	    if (argv[i+1]) {
514	      ModuleName = NewString(argv[i+1]);	    
515	      Swig_mark_arg(i+1);
516	    } else {
517	      Swig_arg_error();
518	    }
519	  } else if (strcmp(argv[i],"-M") == 0) {
520	    depend = 1;
521	    depend_only = 1;
522	    Swig_mark_arg(i);
523	  } else if (strcmp(argv[i],"-MM") == 0) {
524	    depend = 2;
525	    depend_only = 1;
526	    Swig_mark_arg(i);
527	  } else if (strcmp(argv[i],"-MF") == 0) {
528	    Swig_mark_arg(i);
529	    if (argv[i+1]) {
530	      dependencies_file = NewString(argv[i+1]);	    
531	      Swig_mark_arg(i+1);
532	    } else {
533	      Swig_arg_error();
534	    }
535	  } else if (strcmp(argv[i],"-MD") == 0) {
536	    depend = 1;
537	    Swig_mark_arg(i);
538	  } else if (strcmp(argv[i],"-MMD") == 0) {
539	    depend = 2;
540	    Swig_mark_arg(i);
541	  } else if (strcmp(argv[i],"-outdir") == 0) {
542	    Swig_mark_arg(i);
543	    if (argv[i+1]) {
544	      outdir = NewString(argv[i+1]);	    
545	      Swig_mark_arg(i+1);
546	    } else {
547	      Swig_arg_error();
548	    }
549	  } else if (strcmp(argv[i],"-Wall") == 0) {
550	    Swig_mark_arg(i);
551	    Swig_warnall();
552	  } else if (strcmp(argv[i],"-Wallkw") == 0) {
553	    allkw = 1;
554	    Swig_mark_arg(i);
555	  } else if (strcmp(argv[i],"-Werror") == 0) {
556	    werror = 1;
557	    Swig_mark_arg(i);
558	  } else if (strncmp(argv[i],"-w",2) == 0) {
559	    Swig_mark_arg(i);
560	    Swig_warnfilter(argv[i]+2,1);
561	  } else if (strcmp(argv[i],"-dump_tags") == 0) {
562	    dump_tags = 1;
563	    Swig_mark_arg(i);
564	  } else if (strcmp(argv[i],"-dump_tree") == 0) {
565	    dump_tree = 1;
566	    Swig_mark_arg(i);
567	  } else if (strcmp(argv[i],"-dump_xml") == 0) {
568	    dump_xml = 1;
569	    Swig_mark_arg(i);
570	  } else if (strcmp(argv[i],"-xmlout") == 0) {
571	    dump_xml = 1;
572	    Swig_mark_arg(i);
573	    if (argv[i+1]) {
574	      xmlout = NewString(argv[i+1]);	    
575	      Swig_mark_arg(i+1);
576	    } else {
577	      Swig_arg_error();
578	    }
579	  } else if (strcmp(argv[i],"-nocontract") == 0) {
580	    Swig_mark_arg(i);
581	    Swig_contract_mode_set(0);
582	  } else if (strcmp(argv[i],"-browse") == 0) {
583	    browse = 1;
584	    Swig_mark_arg(i);
585	  } else if (strcmp(argv[i],"-dump_typedef") == 0) {
586	    dump_typedef = 1;
587	    Swig_mark_arg(i);
588	  } else if (strcmp(argv[i],"-dump_classes") == 0) {
589	    dump_classes = 1;
590	    Swig_mark_arg(i);
591	  } else if (strcmp(argv[i],"-dump_memory") == 0) {
592	    memory_debug =1;
593	    Swig_mark_arg(i);
594	  } else if (strcmp(argv[i],"-Fstandard") == 0) {
595            Swig_error_msg_format(EMF_STANDARD);
596	    Swig_mark_arg(i);
597	  } else if (strcmp(argv[i],"-Fmicrosoft") == 0) {
598            Swig_error_msg_format(EMF_MICROSOFT);
599	    Swig_mark_arg(i);
600	  } else if (strcmp(argv[i],"-help") == 0) {
601	    fputs(usage1,stdout);
602	    fputs(usage2,stdout);
603	    Swig_mark_arg(i);
604	    help = 1;
605	  }
606      }
607  }
608
609  for (i = 0; i < includecount; i++) {
610    Swig_add_directory((DOH *) includefiles[i]);
611  }
612}
613
614
615
616
617
618int SWIG_main(int argc, char *argv[], Language *l) {
619  char   *c;
620  char    temp[512];
621
622  /* Initialize the SWIG core */
623  Swig_init();
624  
625  /* Suppress warning messages for private inheritance, preprocessor
626     evaluation, might be abstract, overloaded const, and ...
627
628     WARN_PP_EVALUATION            202
629     WARN_PARSE_PRIVATE_INHERIT    309
630     WARN_TYPE_ABSTRACT            403
631     WARN_LANG_OVERLOAD_CONST      512
632     WARN_PARSE_BUILTIN_NAME       321
633     WARN_PARSE_REDUNDANT          322
634  */
635  Swig_warnfilter("202,309,403,512,321,322",1);
636
637  // Initialize the preprocessor
638  Preprocessor_init();
639
640  lang = l;
641
642  // Set up some default symbols (available in both SWIG interface files
643  // and C files)
644
645  Preprocessor_define((DOH *) "SWIG 1", 0);
646  Preprocessor_define((DOH *) "__STDC__", 0);
647#ifdef MACSWIG
648  Preprocessor_define((DOH *) "SWIGMAC 1", 0);
649#endif
650#ifdef SWIGWIN32
651  Preprocessor_define((DOH *) "SWIGWIN32 1", 0);
652#endif
653
654  // Set the SWIG version value in format 0xAABBCC from package version expected to be in format A.B.C
655  String *package_version = NewString(PACKAGE_VERSION);
656  char *token = strtok(Char(package_version), ".");
657  String *vers = NewString("SWIG_VERSION 0x");
658  int count = 0;
659  while (token) {
660    int len = strlen(token);
661    assert(len == 1 || len == 2);
662    Printf(vers, "%s%s", (len == 1) ? "0" : "", token);
663    token = strtok(NULL, ".");
664    count++;
665  }
666  Delete(package_version);
667  assert(count == 3); // Check version format is correct
668
669  /* Turn on contracts */
670
671  Swig_contract_mode_set(1);
672  Preprocessor_define(vers,0);
673
674  /* Turn off directors mode */
675  Wrapper_director_mode_set(0);
676  Wrapper_director_protected_mode_set(0);
677
678  // Check for SWIG_LIB environment variable
679
680  if ((c = getenv("SWIG_LIB")) == (char *) 0) {
681#if defined(_WIN32)
682      char buf[MAX_PATH];
683      char *p;
684      if (GetModuleFileName(0, buf, MAX_PATH) == 0
685	  || (p = strrchr(buf, '\\')) == 0) {
686       Printf(stderr, "Warning: Could not determine SWIG library location. Assuming " SWIG_LIB "\n");
687       sprintf(LibDir,"%s",SWIG_LIB);    // Build up search paths
688      } else {
689       strcpy(p+1, "Lib");
690       strcpy(LibDir, buf);
691      }
692#else
693       sprintf(LibDir,"%s",SWIG_LIB);    // Build up search paths
694#endif                                        
695  } else {
696      strcpy(LibDir,c);
697  }
698
699  SwigLib = Swig_copy_string(LibDir);        // Make a copy of the real library location
700  
701  libfiles = NewList();
702
703  /* Check for SWIG_FEATURES environment variable */
704
705  SWIG_getoptions(argc, argv);
706
707  // Define the __cplusplus symbol
708  if (CPlusPlus)
709    Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
710
711  // Parse language dependent options
712  lang->main(argc,argv);
713
714  
715  if (help) {
716    Printf(stdout,"\nNote: 'swig -<lang> -help' displays options for a specific target language.\n\n");
717    SWIG_exit (EXIT_SUCCESS);    // Exit if we're in help mode
718  }
719
720  // Check all of the options to make sure we're cool.
721  // Don't check for an input file if -external-runtime is passed
722  Swig_check_options(external_runtime ? 0 : 1);
723
724  install_opts(argc, argv);
725
726  // Add language dependent directory to the search path
727  {
728    DOH *rl = NewString("");
729    Printf(rl,"%s%s%s", SwigLib, SWIG_FILE_DELIMETER, LibDir);
730    Swig_add_directory(rl);
731    rl = NewString("");
732    Printf(rl,".%sswig_lib%s%s", SWIG_FILE_DELIMETER, SWIG_FILE_DELIMETER, LibDir);
733    Swig_add_directory(rl);
734  }
735
736  sprintf(temp,"%s%sconfig", SwigLib, SWIG_FILE_DELIMETER);
737  Swig_add_directory((DOH *) temp);
738  Swig_add_directory((DOH *) "." SWIG_FILE_DELIMETER "swig_lib" SWIG_FILE_DELIMETER "config");
739  Swig_add_directory((DOH *) SwigLib);
740  Swig_add_directory((DOH *) "." SWIG_FILE_DELIMETER "swig_lib");
741
742  if (Verbose) {
743    printf ("LibDir: %s\n", LibDir);
744    List *sp = Swig_search_path();
745    Iterator s;
746    for (s = First(sp); s.item; s = Next(s)) {
747      Printf(stdout,"   %s\n", s.item);
748    }
749  }
750
751  // handle the -external-runtime argument
752  if (external_runtime)
753    SWIG_dump_runtime();
754
755  // If we made it this far, looks good. go for it....
756
757  input_file = argv[argc-1];
758
759  // If the user has requested to check out a file, handle that
760  if (checkout) {
761    DOH *s;
762    char *outfile = input_file;
763    if (outfile_name)
764      outfile = outfile_name;
765
766    if (Verbose)
767      printf ("Handling checkout...\n");
768
769    s = Swig_include(input_file);
770    if (!s) {
771      fprintf(stderr,"Unable to locate '%s' in the SWIG library.\n", input_file);
772    } else {
773      FILE *f = fopen(outfile,"r");
774      if (f) {
775	fclose(f);
776	fprintf(stderr,"File '%s' already exists. Checkout aborted.\n", outfile);
777      } else {
778	f = fopen(outfile,"w");
779	if (!f) {
780	  fprintf(stderr,"Unable to create file '%s'\n", outfile);
781	} else {
782	  if (Verbose)
783	    fprintf(stdout,"'%s' checked out from the SWIG library.\n", input_file);
784	  fputs(Char(s),f);
785	  fclose(f);
786	}
787      }
788    }
789  } else {
790    // Check the suffix for a .c file.  If so, we're going to
791    // declare everything we see as "extern"
792
793    ForceExtern = check_suffix(input_file);
794
795    // Run the preprocessor
796    if (Verbose)
797      printf ("Preprocessing...\n");
798    {
799      int i;
800      String *fs = NewString("");
801      FILE *df = Swig_open(input_file);
802      if (!df) {
803	Printf(stderr,"Unable to find '%s'\n", input_file);
804	SWIG_exit (EXIT_FAILURE);
805      }
806      fclose(df);
807      if(!no_cpp) {
808        Printf(fs,"%%include <swig.swg>\n");
809        if (allkw) {
810          Printf(fs,"%%include <allkw.swg>\n");
811        }
812        if (lang_config) {
813          Printf(fs,"\n%%include <%s>\n", lang_config);
814        }
815        Printf(fs,"%%include \"%s\"\n", Swig_last_file());
816        for (i = 0; i < Len(libfiles); i++) {
817          Printf(fs,"\n%%include \"%s\"\n", Getitem(libfiles,i));
818        }
819        Seek(fs,0,SEEK_SET);
820        cpps = Preprocessor_parse(fs);
821      } else {
822        df = Swig_open(input_file);
823        cpps = NewFileFromFile(df);
824      }
825      if (Swig_error_count()) {
826        SWIG_exit(EXIT_FAILURE);
827      }
828      if (cpp_only) {
829	Printf(stdout,"%s", cpps);
830	while (freeze);
831	SWIG_exit (EXIT_SUCCESS);
832      }
833      if (depend) {
834	String *outfile;
835	if (!outfile_name) {
836	  if (CPlusPlus) {
837	    outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file),cpp_extension);
838	  } else {
839	    outfile = NewStringf("%s_wrap.c", Swig_file_basename(input_file));
840	  }
841	} else {
842	  outfile = NewString(outfile_name);
843	}
844	if (dependencies_file && Len(dependencies_file) != 0) {
845	  f_dependencies_file = NewFile(dependencies_file,"w");
846	  if (!f_dependencies_file) {
847	    FileErrorDisplay(dependencies_file);
848	    SWIG_exit(EXIT_FAILURE);
849	  }
850	} else if (!depend_only) {
851	  String *filename = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), depends_extension);
852	  f_dependencies_file = NewFile(filename,"w");
853	  if (!f_dependencies_file) {
854	    FileErrorDisplay(filename);
855	    SWIG_exit(EXIT_FAILURE);
856	  }
857	} 
858	else
859	  f_dependencies_file = stdout;
860	Printf(f_dependencies_file,"%s: ", outfile);
861	List *files = Preprocessor_depend();
862	for (int i = 0; i < Len(files); i++) {
863	  if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files,i),SwigLib, Len(SwigLib)) != 0))) {
864	    Printf(f_dependencies_file,"\\\n %s ", Getitem(files,i));
865	  }
866	}
867	Printf(f_dependencies_file,"\n");
868	if (f_dependencies_file != stdout)
869	  Close(f_dependencies_file);
870	if (depend_only)
871	  SWIG_exit(EXIT_SUCCESS);
872      }
873      Seek(cpps, 0, SEEK_SET);
874    }
875
876    /* Register a null file with the file handler */
877    Swig_register_filebyname("null", NewString(""));
878
879    // Pass control over to the specific language interpreter
880    if (Verbose) {
881      fprintf (stdout, "Starting language-specific parse...\n");
882      fflush (stdout);
883    }
884
885    Node *top = Swig_cparse(cpps);
886
887
888    if (Verbose) {
889      Printf(stdout,"Processing types...\n");
890    }
891    Swig_process_types(top);
892
893    if (Verbose) {
894      Printf(stdout,"C++ analysis...\n");
895    }
896    Swig_default_allocators(top);
897
898    if (Verbose) {
899      Printf(stdout,"Generating wrappers...\n");
900    }
901
902    if (dump_classes) {
903      Hash *classes = Getattr(top,"classes");
904      if (classes) {
905	Printf(stdout,"Classes\n");
906	Printf(stdout,"------------\n");
907	Iterator ki;
908	for (ki = First(classes); ki.key; ki = Next(ki)) {
909	  Printf(stdout,"%s\n", ki.key);
910	}
911      }	       
912    }
913
914    if (dump_typedef) {
915      SwigType_print_scope(0);
916    }
917
918    if (dump_tags) {
919      Swig_print_tags(top,0);
920    }
921    if (top) {
922      if (!Getattr(top,"name")) {
923	Printf(stderr,"*** No module name specified using %%module or -module.\n");
924	SWIG_exit(EXIT_FAILURE);
925      } else {
926	/* Set some filename information on the object */
927	Setattr(top,"infile", input_file);
928	if (!outfile_name) {
929	  if (CPlusPlus) {
930	    Setattr(top,"outfile", NewStringf("%s_wrap.%s", Swig_file_basename(input_file),cpp_extension));
931	  } else {
932	    Setattr(top,"outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file)));
933	  }
934	} else {
935	  Setattr(top,"outfile", outfile_name);
936	}
937	if (!outfile_name_h) {
938	  Setattr(top,"outfile_h", NewStringf("%s_wrap.%s", Swig_file_basename(input_file),hpp_extension));
939	} else {
940	  Setattr(top,"outfile_h", outfile_name_h);
941	}
942        set_outdir(Swig_file_dirname(Getattr(top,"outfile")));
943	if (Swig_contract_mode_get()) {
944	  Swig_contracts(top);
945	}
946	lang->top(top);
947	if (browse) {
948	  Swig_browser(top,0);
949	}
950      }
951    }
952    if (dump_tree) {
953      Swig_print_tree(top);
954    }
955    if (dump_xml) {
956      Swig_print_xml(top, xmlout);
957    }
958  }
959  if (tm_debug) Swig_typemap_debug();
960  if (memory_debug) DohMemoryDebug();
961  while (freeze);
962
963
964  if ((werror) && (Swig_warn_count())) {
965    return Swig_warn_count();
966  }
967  return Swig_error_count();
968}
969
970// --------------------------------------------------------------------------
971// SWIG_exit(int exit_code)
972//
973// Cleanup and either freeze or exit
974// --------------------------------------------------------------------------
975
976void SWIG_exit(int exit_code) {
977  while (freeze);
978  exit (exit_code);
979}
980