wrc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * Copyright 1994 Martin von Loewis
  3. * Copyright 1998 Bertho A. Stultiens (BS)
  4. * Copyright 2003 Dimitrie O. Paun
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. *
  20. */
  21. #include "config.h"
  22. #include "wine/port.h"
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #ifdef HAVE_UNISTD_H
  26. # include <unistd.h>
  27. #endif
  28. #include <string.h>
  29. #include <assert.h>
  30. #include <ctype.h>
  31. #include <signal.h>
  32. #ifdef HAVE_GETOPT_H
  33. # include <getopt.h>
  34. #endif
  35. #include "wrc.h"
  36. #include "utils.h"
  37. #include "dumpres.h"
  38. #include "genres.h"
  39. #include "newstruc.h"
  40. #include "parser.h"
  41. #include "wine/wpp.h"
  42. #ifdef WORDS_BIGENDIAN
  43. #define ENDIAN "big"
  44. #else
  45. #define ENDIAN "little"
  46. #endif
  47. static const char usage[] =
  48. "Usage: wrc [options...] [infile[.rc|.res]]\n"
  49. " -b, --target=TARGET Specify target CPU and platform when cross-compiling\n"
  50. " -D, --define id[=val] Define preprocessor identifier id=val\n"
  51. " --debug=nn Set debug level to 'nn'\n"
  52. " -E Preprocess only\n"
  53. " --endianness=e Set output byte-order e={n[ative], l[ittle], b[ig]}\n"
  54. " (win32 only; default is " ENDIAN "-endian)\n"
  55. " -F TARGET Synonym for -b for compatibility with windres\n"
  56. " -fo FILE Synonym for -o for compatibility with windres\n"
  57. " -h, --help Prints this summary\n"
  58. " -i, --input=FILE The name of the input file\n"
  59. " -I, --include-dir=PATH Set include search dir to path (multiple -I allowed)\n"
  60. " -J, --input-format=FORMAT The input format (either `rc' or `rc16')\n"
  61. " -l, --language=LANG Set default language to LANG (default is neutral {0, 0})\n"
  62. " -m16, -m32, -m64 Build for 16-bit, 32-bit resp. 64-bit platforms\n"
  63. " --nls-dir=DIR Directory containing the NLS codepage mappings\n"
  64. " --no-use-temp-file Ignored for compatibility with windres\n"
  65. " --nostdinc Disables searching the standard include path\n"
  66. " -o, --output=FILE Output to file (default is infile.res)\n"
  67. " -O, --output-format=FORMAT The output format (`po', `pot', `res', or `res16`)\n"
  68. " --pedantic Enable pedantic warnings\n"
  69. " --po-dir=DIR Directory containing po files for translations\n"
  70. " --preprocessor Specifies the preprocessor to use, including arguments\n"
  71. " -r Ignored for compatibility with rc\n"
  72. " --sysroot=DIR Prefix include paths with DIR\n"
  73. " -U, --undefine id Undefine preprocessor identifier id\n"
  74. " --use-temp-file Ignored for compatibility with windres\n"
  75. " -v, --verbose Enable verbose mode\n"
  76. " --verify-translations Check the status of the various translations\n"
  77. " --version Print version and exit\n"
  78. "Input is taken from stdin if no sourcefile specified.\n"
  79. "Debug level 'n' is a bitmask with following meaning:\n"
  80. " * 0x01 Tell which resource is parsed (verbose mode)\n"
  81. " * 0x02 Dump internal structures\n"
  82. " * 0x04 Create a parser trace (yydebug=1)\n"
  83. " * 0x08 Preprocessor messages\n"
  84. " * 0x10 Preprocessor lex messages\n"
  85. " * 0x20 Preprocessor yacc trace\n"
  86. "If no input filename is given and the output name is not overridden\n"
  87. "with -o, then the output is written to \"wrc.tab.res\"\n"
  88. ;
  89. static const char version_string[] = "Wine Resource Compiler version " PACKAGE_VERSION "\n"
  90. "Copyright 1998-2000 Bertho A. Stultiens\n"
  91. " 1994 Martin von Loewis\n";
  92. /*
  93. * Set if compiling in 32bit mode (default).
  94. */
  95. int win32 = 1;
  96. /*
  97. * debuglevel == DEBUGLEVEL_NONE Don't bother
  98. * debuglevel & DEBUGLEVEL_CHAT Say what's done
  99. * debuglevel & DEBUGLEVEL_DUMP Dump internal structures
  100. * debuglevel & DEBUGLEVEL_TRACE Create parser trace
  101. * debuglevel & DEBUGLEVEL_PPMSG Preprocessor messages
  102. * debuglevel & DEBUGLEVEL_PPLEX Preprocessor lex trace
  103. * debuglevel & DEBUGLEVEL_PPTRACE Preprocessor yacc trace
  104. */
  105. int debuglevel = DEBUGLEVEL_NONE;
  106. /*
  107. * Recognize win32 keywords if set (-w 32 enforces this),
  108. * otherwise set with -e option.
  109. */
  110. int extensions = 1;
  111. /*
  112. * Language setting for resources (-l option)
  113. */
  114. static language_t *defaultlanguage;
  115. language_t *currentlanguage = NULL;
  116. /*
  117. * Set when extra warnings should be generated (-W option)
  118. */
  119. int pedantic = 0;
  120. /*
  121. * The output byte-order of resources (set with -B)
  122. */
  123. int byteorder = WRC_BO_NATIVE;
  124. /*
  125. * Set when _only_ to run the preprocessor (-E option)
  126. */
  127. int preprocess_only = 0;
  128. /*
  129. * Set when _not_ to run the preprocessor (-P cat option)
  130. */
  131. int no_preprocess = 0;
  132. int utf8_input = 0;
  133. int check_utf8 = 1; /* whether to check for valid utf8 */
  134. static int pointer_size = sizeof(void *);
  135. static int verify_translations_mode;
  136. static char *output_name; /* The name given by the -o option */
  137. char *input_name = NULL; /* The name given on the command-line */
  138. static char *temp_name = NULL; /* Temporary file for preprocess pipe */
  139. static const char *includedir;
  140. const char *nlsdirs[3] = { NULL, NLSDIR, NULL };
  141. int line_number = 1; /* The current line */
  142. int char_number = 1; /* The current char pos within the line */
  143. char *cmdline; /* The entire commandline */
  144. int parser_debug, yy_flex_debug;
  145. resource_t *resource_top; /* The top of the parsed resources */
  146. static void cleanup_files(void);
  147. static void segvhandler(int sig);
  148. enum long_options_values
  149. {
  150. LONG_OPT_NOSTDINC = 1,
  151. LONG_OPT_TMPFILE,
  152. LONG_OPT_NOTMPFILE,
  153. LONG_OPT_NLS_DIR,
  154. LONG_OPT_PO_DIR,
  155. LONG_OPT_PREPROCESSOR,
  156. LONG_OPT_SYSROOT,
  157. LONG_OPT_VERSION,
  158. LONG_OPT_DEBUG,
  159. LONG_OPT_ENDIANNESS,
  160. LONG_OPT_PEDANTIC,
  161. LONG_OPT_VERIFY_TRANSL
  162. };
  163. static const char short_options[] =
  164. "b:D:Ef:F:hi:I:J:l:m:o:O:ruU:v";
  165. static const struct option long_options[] = {
  166. { "debug", 1, NULL, LONG_OPT_DEBUG },
  167. { "define", 1, NULL, 'D' },
  168. { "endianness", 1, NULL, LONG_OPT_ENDIANNESS },
  169. { "help", 0, NULL, 'h' },
  170. { "include-dir", 1, NULL, 'I' },
  171. { "input", 1, NULL, 'i' },
  172. { "input-format", 1, NULL, 'J' },
  173. { "language", 1, NULL, 'l' },
  174. { "nls-dir", 1, NULL, LONG_OPT_NLS_DIR },
  175. { "no-use-temp-file", 0, NULL, LONG_OPT_NOTMPFILE },
  176. { "nostdinc", 0, NULL, LONG_OPT_NOSTDINC },
  177. { "output", 1, NULL, 'o' },
  178. { "output-format", 1, NULL, 'O' },
  179. { "pedantic", 0, NULL, LONG_OPT_PEDANTIC },
  180. { "po-dir", 1, NULL, LONG_OPT_PO_DIR },
  181. { "preprocessor", 1, NULL, LONG_OPT_PREPROCESSOR },
  182. { "sysroot", 1, NULL, LONG_OPT_SYSROOT },
  183. { "target", 1, NULL, 'F' },
  184. { "utf8", 0, NULL, 'u' },
  185. { "undefine", 1, NULL, 'U' },
  186. { "use-temp-file", 0, NULL, LONG_OPT_TMPFILE },
  187. { "verbose", 0, NULL, 'v' },
  188. { "verify-translations", 0, NULL, LONG_OPT_VERIFY_TRANSL },
  189. { "version", 0, NULL, LONG_OPT_VERSION },
  190. { NULL, 0, NULL, 0 }
  191. };
  192. static void set_version_defines(void)
  193. {
  194. char *version = xstrdup( PACKAGE_VERSION );
  195. char *major, *minor, *patchlevel;
  196. char buffer[100];
  197. if ((minor = strchr( version, '.' )))
  198. {
  199. major = version;
  200. *minor++ = 0;
  201. if ((patchlevel = strchr( minor, '.' ))) *patchlevel++ = 0;
  202. }
  203. else /* pre 0.9 version */
  204. {
  205. major = NULL;
  206. patchlevel = version;
  207. }
  208. sprintf( buffer, "__WRC__=%s", major ? major : "0" );
  209. wpp_add_cmdline_define(buffer);
  210. sprintf( buffer, "__WRC_MINOR__=%s", minor ? minor : "0" );
  211. wpp_add_cmdline_define(buffer);
  212. sprintf( buffer, "__WRC_PATCHLEVEL__=%s", patchlevel ? patchlevel : "0" );
  213. wpp_add_cmdline_define(buffer);
  214. free( version );
  215. }
  216. /* clean things up when aborting on a signal */
  217. static void exit_on_signal( int sig )
  218. {
  219. exit(1); /* this will call the atexit functions */
  220. }
  221. /* load a single input file */
  222. static int load_file( const char *input_name, const char *output_name )
  223. {
  224. int ret;
  225. /* Run the preprocessor on the input */
  226. if(!no_preprocess)
  227. {
  228. FILE *output;
  229. int ret, fd;
  230. char *name;
  231. /*
  232. * Preprocess the input to a temp-file, or stdout if
  233. * no output was given.
  234. */
  235. if (preprocess_only)
  236. {
  237. if (output_name)
  238. {
  239. if (!(output = fopen( output_name, "w" )))
  240. fatal_perror( "Could not open %s for writing", output_name );
  241. ret = wpp_parse( input_name, output );
  242. fclose( output );
  243. }
  244. else ret = wpp_parse( input_name, stdout );
  245. if (ret) return ret;
  246. output_name = NULL;
  247. exit(0);
  248. }
  249. if (output_name && output_name[0]) name = strmake( "%s.XXXXXX", output_name );
  250. else name = xstrdup( "wrc.XXXXXX" );
  251. if ((fd = mkstemps( name, 0 )) == -1)
  252. error("Could not generate a temp name from %s\n", name);
  253. temp_name = name;
  254. if (!(output = fdopen(fd, "wt")))
  255. error("Could not open fd %s for writing\n", name);
  256. ret = wpp_parse( input_name, output );
  257. fclose( output );
  258. if (ret) return ret;
  259. input_name = name;
  260. }
  261. /* Reset the language */
  262. currentlanguage = dup_language( defaultlanguage );
  263. check_utf8 = 1;
  264. /* Go from .rc to .res */
  265. chat("Starting parse\n");
  266. if(!(parser_in = fopen(input_name, "rb")))
  267. fatal_perror("Could not open %s for input", input_name);
  268. ret = parser_parse();
  269. fclose(parser_in);
  270. parser_lex_destroy();
  271. if (temp_name)
  272. {
  273. unlink( temp_name );
  274. temp_name = NULL;
  275. }
  276. free( currentlanguage );
  277. return ret;
  278. }
  279. static void set_target( const char *target )
  280. {
  281. char *p, *cpu = xstrdup( target );
  282. /* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
  283. if (!(p = strchr( cpu, '-' ))) error( "Invalid target specification '%s'\n", target );
  284. *p = 0;
  285. if (!strcmp( cpu, "amd64" ) || !strcmp( cpu, "x86_64" ) ||
  286. !strcmp( cpu, "ia64" ) || !strcmp( cpu, "aarch64" ))
  287. pointer_size = 8;
  288. else
  289. pointer_size = 4;
  290. free( cpu );
  291. }
  292. static void init_argv0_dir( const char *argv0 )
  293. {
  294. #ifndef _WIN32
  295. char *p, *dir;
  296. #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
  297. dir = realpath( "/proc/self/exe", NULL );
  298. #elif defined (__FreeBSD__) || defined(__DragonFly__)
  299. dir = realpath( "/proc/curproc/file", NULL );
  300. #else
  301. dir = realpath( argv0, NULL );
  302. #endif
  303. if (!dir) return;
  304. if (!(p = strrchr( dir, '/' ))) return;
  305. if (p == dir) p++;
  306. *p = 0;
  307. includedir = strmake( "%s/%s", dir, BIN_TO_INCLUDEDIR );
  308. if (strendswith( dir, "/tools/wrc" )) nlsdirs[0] = strmake( "%s/../../nls", dir );
  309. else nlsdirs[0] = strmake( "%s/%s", dir, BIN_TO_NLSDIR );
  310. free( dir );
  311. #endif
  312. }
  313. int main(int argc,char *argv[])
  314. {
  315. int optc;
  316. int opti = 0;
  317. int stdinc = 1;
  318. int lose = 0;
  319. int nb_files = 0;
  320. int i;
  321. int cmdlen;
  322. int po_mode = 0;
  323. char *po_dir = NULL;
  324. const char *sysroot = "";
  325. char **files = xmalloc( argc * sizeof(*files) );
  326. signal(SIGSEGV, segvhandler);
  327. signal( SIGTERM, exit_on_signal );
  328. signal( SIGINT, exit_on_signal );
  329. #ifdef SIGHUP
  330. signal( SIGHUP, exit_on_signal );
  331. #endif
  332. init_argv0_dir( argv[0] );
  333. /* Set the default defined stuff */
  334. set_version_defines();
  335. wpp_add_cmdline_define("RC_INVOKED=1");
  336. /* Microsoft RC always searches current directory */
  337. wpp_add_include_path(".");
  338. /* First rebuild the commandline to put in destination */
  339. /* Could be done through env[], but not all OS-es support it */
  340. cmdlen = 4; /* for "wrc " */
  341. for(i = 1; i < argc; i++)
  342. cmdlen += strlen(argv[i]) + 1;
  343. cmdline = xmalloc(cmdlen);
  344. strcpy(cmdline, "wrc ");
  345. for(i = 1; i < argc; i++)
  346. {
  347. strcat(cmdline, argv[i]);
  348. if(i < argc-1)
  349. strcat(cmdline, " ");
  350. }
  351. while((optc = getopt_long(argc, argv, short_options, long_options, &opti)) != EOF)
  352. {
  353. switch(optc)
  354. {
  355. case LONG_OPT_NOSTDINC:
  356. stdinc = 0;
  357. break;
  358. case LONG_OPT_TMPFILE:
  359. if (debuglevel) warning("--use-temp-file option not yet supported, ignored.\n");
  360. break;
  361. case LONG_OPT_NOTMPFILE:
  362. if (debuglevel) warning("--no-use-temp-file option not yet supported, ignored.\n");
  363. break;
  364. case LONG_OPT_NLS_DIR:
  365. nlsdirs[0] = xstrdup( optarg );
  366. break;
  367. case LONG_OPT_PO_DIR:
  368. po_dir = xstrdup( optarg );
  369. break;
  370. case LONG_OPT_PREPROCESSOR:
  371. if (strcmp(optarg, "cat") == 0) no_preprocess = 1;
  372. else fprintf(stderr, "-P option not yet supported, ignored.\n");
  373. break;
  374. case LONG_OPT_SYSROOT:
  375. sysroot = xstrdup( optarg );
  376. break;
  377. case LONG_OPT_VERSION:
  378. printf(version_string);
  379. exit(0);
  380. break;
  381. case LONG_OPT_DEBUG:
  382. debuglevel = strtol(optarg, NULL, 0);
  383. break;
  384. case LONG_OPT_ENDIANNESS:
  385. switch(optarg[0])
  386. {
  387. case 'n':
  388. case 'N':
  389. byteorder = WRC_BO_NATIVE;
  390. break;
  391. case 'l':
  392. case 'L':
  393. byteorder = WRC_BO_LITTLE;
  394. break;
  395. case 'b':
  396. case 'B':
  397. byteorder = WRC_BO_BIG;
  398. break;
  399. default:
  400. fprintf(stderr, "Byte ordering must be n[ative], l[ittle] or b[ig]\n");
  401. lose++;
  402. }
  403. break;
  404. case LONG_OPT_PEDANTIC:
  405. pedantic = 1;
  406. wpp_set_pedantic(1);
  407. break;
  408. case LONG_OPT_VERIFY_TRANSL:
  409. verify_translations_mode = 1;
  410. break;
  411. case 'D':
  412. wpp_add_cmdline_define(optarg);
  413. break;
  414. case 'E':
  415. preprocess_only = 1;
  416. break;
  417. case 'b':
  418. case 'F':
  419. set_target( optarg );
  420. break;
  421. case 'h':
  422. printf(usage);
  423. exit(0);
  424. case 'i':
  425. files[nb_files++] = optarg;
  426. break;
  427. case 'I':
  428. wpp_add_include_path(optarg);
  429. break;
  430. case 'J':
  431. if (strcmp(optarg, "rc16") == 0) extensions = 0;
  432. else if (strcmp(optarg, "rc")) error("Output format %s not supported.\n", optarg);
  433. break;
  434. case 'l':
  435. {
  436. int lan;
  437. lan = strtol(optarg, NULL, 0);
  438. if (get_language_codepage(PRIMARYLANGID(lan), SUBLANGID(lan)) == -1)
  439. error("Language %04x is not supported\n", lan);
  440. defaultlanguage = new_language(PRIMARYLANGID(lan), SUBLANGID(lan));
  441. }
  442. break;
  443. case 'm':
  444. if (!strcmp( optarg, "16" )) win32 = 0;
  445. else if (!strcmp( optarg, "32" )) { win32 = 1; pointer_size = 4; }
  446. else if (!strcmp( optarg, "64" )) { win32 = 1; pointer_size = 8; }
  447. break;
  448. case 'f':
  449. if (*optarg != 'o') error("Unknown option: -f%s\n", optarg);
  450. optarg++;
  451. /* fall through */
  452. case 'o':
  453. if (!output_name) output_name = strdup(optarg);
  454. else error("Too many output files.\n");
  455. break;
  456. case 'O':
  457. if (strcmp(optarg, "po") == 0) po_mode = 1;
  458. else if (strcmp(optarg, "pot") == 0) po_mode = 2;
  459. else if (strcmp(optarg, "res16") == 0) win32 = 0;
  460. else if (strcmp(optarg, "res")) warning("Output format %s not supported.\n", optarg);
  461. break;
  462. case 'r':
  463. /* ignored for compatibility with rc */
  464. break;
  465. case 'u':
  466. utf8_input = 1;
  467. break;
  468. case 'U':
  469. wpp_del_define(optarg);
  470. break;
  471. case 'v':
  472. debuglevel = DEBUGLEVEL_CHAT;
  473. break;
  474. default:
  475. lose++;
  476. break;
  477. }
  478. }
  479. if(lose)
  480. {
  481. fprintf(stderr, usage);
  482. return 1;
  483. }
  484. if (win32)
  485. {
  486. wpp_add_cmdline_define("_WIN32=1");
  487. if (pointer_size == 8) wpp_add_cmdline_define("_WIN64=1");
  488. }
  489. /* If we do need to search standard includes, add them to the path */
  490. if (stdinc)
  491. {
  492. static const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
  493. if (includedir)
  494. {
  495. wpp_add_include_path( strmake( "%s/wine/msvcrt", includedir ));
  496. wpp_add_include_path( strmake( "%s/wine/windows", includedir ));
  497. }
  498. for (i = 0; i < ARRAY_SIZE(incl_dirs); i++)
  499. {
  500. if (i && !strcmp( incl_dirs[i], incl_dirs[0] )) continue;
  501. wpp_add_include_path( strmake( "%s%s/wine/msvcrt", sysroot, incl_dirs[i] ));
  502. wpp_add_include_path( strmake( "%s%s/wine/windows", sysroot, incl_dirs[i] ));
  503. }
  504. }
  505. /* Kill io buffering when some kind of debuglevel is enabled */
  506. if(debuglevel)
  507. {
  508. setbuf(stdout, NULL);
  509. setbuf(stderr, NULL);
  510. }
  511. parser_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
  512. yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
  513. wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
  514. (debuglevel & DEBUGLEVEL_PPTRACE) != 0,
  515. (debuglevel & DEBUGLEVEL_PPMSG) != 0 );
  516. /* Check if the user set a language, else set default */
  517. if(!defaultlanguage)
  518. defaultlanguage = new_language(0, 0);
  519. atexit(cleanup_files);
  520. while (optind < argc) files[nb_files++] = argv[optind++];
  521. for (i = 0; i < nb_files; i++)
  522. {
  523. input_name = files[i];
  524. if (load_file( input_name, output_name )) exit(1);
  525. }
  526. /* stdin special case. NULL means "stdin" for wpp. */
  527. if (nb_files == 0 && load_file( NULL, output_name )) exit(1);
  528. if(debuglevel & DEBUGLEVEL_DUMP)
  529. dump_resources(resource_top);
  530. if(verify_translations_mode)
  531. {
  532. verify_translations(resource_top);
  533. exit(0);
  534. }
  535. if (!po_mode && output_name)
  536. {
  537. if (strendswith( output_name, ".po" )) po_mode = 1;
  538. else if (strendswith( output_name, ".pot" )) po_mode = 2;
  539. }
  540. if (po_mode)
  541. {
  542. if (!win32) error( "PO files are not supported in 16-bit mode\n" );
  543. if (po_mode == 2) /* pot file */
  544. {
  545. if (!output_name)
  546. {
  547. output_name = dup_basename( nb_files ? files[0] : NULL, ".rc" );
  548. strcat( output_name, ".pot" );
  549. }
  550. write_pot_file( output_name );
  551. }
  552. else write_po_files( output_name );
  553. output_name = NULL;
  554. exit(0);
  555. }
  556. if (win32) add_translations( po_dir );
  557. /* Convert the internal lists to binary data */
  558. resources2res(resource_top);
  559. chat("Writing .res-file\n");
  560. if (!output_name)
  561. {
  562. output_name = dup_basename( nb_files ? files[0] : NULL, ".rc" );
  563. strcat(output_name, ".res");
  564. }
  565. write_resfile(output_name, resource_top);
  566. output_name = NULL;
  567. return 0;
  568. }
  569. static void cleanup_files(void)
  570. {
  571. if (output_name) unlink(output_name);
  572. if (temp_name) unlink(temp_name);
  573. }
  574. static void segvhandler(int sig)
  575. {
  576. fprintf(stderr, "\n%s:%d: Oops, segment violation\n", input_name, line_number);
  577. fflush(stdout);
  578. fflush(stderr);
  579. abort();
  580. }