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