예제 #1
0
/* duplicate a basename into a valid C token */
static char *dup_basename_token(const char *name, const char *ext)
{
    char *p, *ret = dup_basename( name, ext );
    /* map invalid characters to '_' */
    for (p = ret; *p; p++) if (!isalnum(*p)) *p = '_';
    return ret;
}
예제 #2
0
파일: wrc.c 프로젝트: howard5888/wineT
int main(int argc,char *argv[])
{
	extern char* optarg;
	extern int   optind;
	int optc;
	int opti = 0;
	int stdinc = 1;
	int lose = 0;
	int ret;
	int i;
	int cmdlen;

	signal(SIGSEGV, segvhandler);
        signal( SIGTERM, exit_on_signal );
        signal( SIGINT, exit_on_signal );
#ifdef SIGHUP
        signal( SIGHUP, exit_on_signal );
#endif

	now = time(NULL);

	/* Set the default defined stuff */
        set_version_defines();
	wpp_add_cmdline_define("RC_INVOKED=1");
	wpp_add_cmdline_define("__WIN32__=1");
	wpp_add_cmdline_define("__FLAT__=1");
	/* Microsoft RC always searches current directory */
	wpp_add_include_path(".");

	/* First rebuild the commandline to put in destination */
	/* Could be done through env[], but not all OS-es support it */
	cmdlen = 4; /* for "wrc " */
	for(i = 1; i < argc; i++)
		cmdlen += strlen(argv[i]) + 1;
	cmdline = (char *)xmalloc(cmdlen);
	strcpy(cmdline, "wrc ");
	for(i = 1; i < argc; i++)
	{
		strcat(cmdline, argv[i]);
		if(i < argc-1)
			strcat(cmdline, " ");
	}

	while((optc = getopt_long(argc, argv, short_options, long_options, &opti)) != EOF)
	{
		switch(optc)
		{
		case 1:
			stdinc = 0;
			break;
		case 2:
			if (debuglevel) warning("--use-temp-file option not yet supported, ignored.\n");
			break;
		case 3:
			if (debuglevel) warning("--no-use-temp-file option not yet supported, ignored.\n");
			break;
		case 4:
			if (strcmp(optarg, "cat") == 0) no_preprocess = 1;
			else fprintf(stderr, "-P option not yet supported, ignored.\n");
			break;
		case 5:
			printf(version_string);
			exit(0);
			break;
		case 6:
			debuglevel = strtol(optarg, NULL, 0);
			break;
		case 7:
			switch(optarg[0])
			{
			case 'n':
			case 'N':
				byteorder = WRC_BO_NATIVE;
				break;
			case 'l':
			case 'L':
				byteorder = WRC_BO_LITTLE;
				break;
			case 'b':
			case 'B':
				byteorder = WRC_BO_BIG;
				break;
			default:
				fprintf(stderr, "Byte ordering must be n[ative], l[ittle] or b[ig]\n");
				lose++;
			}
			break;
		case 8:
			pedantic = 1;
			wpp_set_pedantic(1);
			break;
		case 9:
			verify_translations_mode = 1;
			break;
		case 'D':
			wpp_add_cmdline_define(optarg);
			break;
		case 'E':
			preprocess_only = 1;
			break;
		case 'F':
			/* ignored for compatibility with windres */
			break;
		case 'h':
			printf(usage);
			exit(0);
		case 'i':
			if (!input_name) input_name = strdup(optarg);
			else error("Too many input files.\n");
			break;
		case 'I':
			wpp_add_include_path(optarg);
			break;
		case 'J':
			if (strcmp(optarg, "rc16") == 0)  extensions = 0;
			else if (strcmp(optarg, "rc")) error("Output format %s not supported.\n", optarg);
			break;
		case 'l':
			{
				int lan;
				lan = strtol(optarg, NULL, 0);
				if (get_language_codepage(PRIMARYLANGID(lan), SUBLANGID(lan)) == -1)
					error("Language %04x is not supported\n", lan);
				currentlanguage = new_language(PRIMARYLANGID(lan), SUBLANGID(lan));
			}
			break;
		case 'f':
			if (*optarg != 'o') error("Unknown option: -f%s\n",  optarg);
			optarg++;
			/* fall through */
		case 'o':
			if (!output_name) output_name = strdup(optarg);
			else error("Too many output files.\n");
			break;
		case 'O':
			if (strcmp(optarg, "res16") == 0)
			{
				win32 = 0;
				wpp_del_define("__WIN32__");
				wpp_del_define("__FLAT__");
			}
			else if (strcmp(optarg, "res")) warning("Output format %s not supported.\n", optarg);
			break;
		case 'r':
			/* ignored for compatibility with rc */
			break;
		case 'U':
			wpp_del_define(optarg);
			break;
		case 'v':
			debuglevel = DEBUGLEVEL_CHAT;
			break;
		default:
			lose++;
			break;
		}
	}

	if(lose)
	{
		fprintf(stderr, usage);
		return 1;
	}

	/* If we do need to search standard includes, add them to the path */
	if (stdinc)
	{
		wpp_add_include_path(INCLUDEDIR"/msvcrt");
		wpp_add_include_path(INCLUDEDIR"/windows");
	}
	
	/* Check for input file on command-line */
	if(optind < argc)
	{
		if (!input_name) input_name = argv[optind++];
		else error("Too many input files.\n");
	}

	/* Check for output file on command-line */
	if(optind < argc)
	{
		if (!output_name) output_name = argv[optind++];
		else error("Too many output files.\n");
	}

	/* Kill io buffering when some kind of debuglevel is enabled */
	if(debuglevel)
	{
		setbuf(stdout,0);
		setbuf(stderr,0);
	}

	yydebug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
	yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;

        wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
                       (debuglevel & DEBUGLEVEL_PPTRACE) != 0,
                       (debuglevel & DEBUGLEVEL_PPMSG) != 0 );

	/* Check if the user set a language, else set default */
	if(!currentlanguage)
		currentlanguage = new_language(0, 0);

	/* Generate appropriate outfile names */
	if(!output_name && !preprocess_only)
	{
		output_name = dup_basename(input_name, ".rc");
		strcat(output_name, ".res");
	}
	atexit(cleanup_files);

	/* Run the preprocessor on the input */
	if(!no_preprocess)
	{
		/*
		 * Preprocess the input to a temp-file, or stdout if
		 * no output was given.
		 */

		chat("Starting preprocess");

                if (!preprocess_only)
                {
                    ret = wpp_parse_temp( input_name, output_name, &temp_name );
                }
                else if (output_name)
                {
                    FILE *output;

                    if (!(output = fopen( output_name, "w" )))
                        error( "Could not open %s for writing\n", output_name );
                    ret = wpp_parse( input_name, output );
                    fclose( output );
                }
                else
                {
                    ret = wpp_parse( input_name, stdout );
                }

		if(ret)
			exit(1);	/* Error during preprocess */

		if(preprocess_only)
		{
			output_name = NULL;
			exit(0);
		}

		input_name = temp_name;
	}

	/* Go from .rc to .res */
	chat("Starting parse");

	if(!(yyin = fopen(input_name, "rb")))
		error("Could not open %s for input\n", input_name);

	ret = yyparse();

	if(input_name) fclose(yyin);

	if(ret) exit(1); /* Error during parse */

	if(debuglevel & DEBUGLEVEL_DUMP)
		dump_resources(resource_top);

	if(verify_translations_mode)
	{
		verify_translations(resource_top);
		exit(0);
	}

	/* Convert the internal lists to binary data */
	resources2res(resource_top);

	chat("Writing .res-file");
	write_resfile(output_name, resource_top);
	output_name = NULL;

	return 0;
}
예제 #3
0
int main(int argc,char *argv[])
{
	extern char* optarg;
	extern int   optind;
	int optc;
	int opti = 0;
	int stdinc = 1;
	int lose = 0;
	int nb_files = 0;
	int i;
	int cmdlen;
        int po_mode = 0;
        char *po_dir = NULL;
        char **files = xmalloc( argc * sizeof(*files) );

	signal(SIGSEGV, segvhandler);
        signal( SIGTERM, exit_on_signal );
        signal( SIGINT, exit_on_signal );
#ifdef SIGHUP
        signal( SIGHUP, exit_on_signal );
#endif

	now = time(NULL);

	/* Set the default defined stuff */
        set_version_defines();
	wpp_add_cmdline_define("RC_INVOKED=1");
	/* Microsoft RC always searches current directory */
	wpp_add_include_path(".");

	/* First rebuild the commandline to put in destination */
	/* Could be done through env[], but not all OS-es support it */
	cmdlen = 4; /* for "wrc " */
	for(i = 1; i < argc; i++)
		cmdlen += strlen(argv[i]) + 1;
	cmdline = xmalloc(cmdlen);
	strcpy(cmdline, "wrc ");
	for(i = 1; i < argc; i++)
	{
		strcat(cmdline, argv[i]);
		if(i < argc-1)
			strcat(cmdline, " ");
	}

	while((optc = getopt_long(argc, argv, short_options, long_options, &opti)) != EOF)
	{
		switch(optc)
		{
		case LONG_OPT_NOSTDINC:
			stdinc = 0;
			break;
		case LONG_OPT_TMPFILE:
			if (debuglevel) warning("--use-temp-file option not yet supported, ignored.\n");
			break;
		case LONG_OPT_NOTMPFILE:
			if (debuglevel) warning("--no-use-temp-file option not yet supported, ignored.\n");
			break;
		case LONG_OPT_PO_DIR:
			po_dir = xstrdup( optarg );
			break;
		case LONG_OPT_PREPROCESSOR:
			if (strcmp(optarg, "cat") == 0) no_preprocess = 1;
			else fprintf(stderr, "-P option not yet supported, ignored.\n");
			break;
		case LONG_OPT_VERSION:
			printf(version_string);
			exit(0);
			break;
		case LONG_OPT_DEBUG:
			debuglevel = strtol(optarg, NULL, 0);
			break;
		case LONG_OPT_ENDIANESS:
			switch(optarg[0])
			{
			case 'n':
			case 'N':
				byteorder = WRC_BO_NATIVE;
				break;
			case 'l':
			case 'L':
				byteorder = WRC_BO_LITTLE;
				break;
			case 'b':
			case 'B':
				byteorder = WRC_BO_BIG;
				break;
			default:
				fprintf(stderr, "Byte ordering must be n[ative], l[ittle] or b[ig]\n");
				lose++;
			}
			break;
		case LONG_OPT_PEDANTIC:
			pedantic = 1;
			wpp_set_pedantic(1);
			break;
		case LONG_OPT_VERIFY_TRANSL:
			verify_translations_mode = 1;
			break;
		case 'D':
			wpp_add_cmdline_define(optarg);
			break;
		case 'E':
			preprocess_only = 1;
			break;
		case 'b':
		case 'F':
			set_target( optarg );
			break;
		case 'h':
			printf(usage);
			exit(0);
		case 'i':
			files[nb_files++] = optarg;
			break;
		case 'I':
			wpp_add_include_path(optarg);
			break;
		case 'J':
			if (strcmp(optarg, "rc16") == 0)  extensions = 0;
			else if (strcmp(optarg, "rc")) error("Output format %s not supported.\n", optarg);
			break;
		case 'l':
			{
				int lan;
				lan = strtol(optarg, NULL, 0);
				if (get_language_codepage(PRIMARYLANGID(lan), SUBLANGID(lan)) == -1)
					error("Language %04x is not supported\n", lan);
				defaultlanguage = new_language(PRIMARYLANGID(lan), SUBLANGID(lan));
			}
			break;
                case 'm':
			if (!strcmp( optarg, "16" )) win32 = 0;
			else if (!strcmp( optarg, "32" )) { win32 = 1; pointer_size = 4; }
			else if (!strcmp( optarg, "64" )) { win32 = 1; pointer_size = 8; }
			else error( "Invalid option: -m%s\n", optarg );
			break;
		case 'f':
			if (*optarg != 'o') error("Unknown option: -f%s\n",  optarg);
			optarg++;
			/* fall through */
		case 'o':
			if (!output_name) output_name = strdup(optarg);
			else error("Too many output files.\n");
			break;
		case 'O':
			if (strcmp(optarg, "po") == 0) po_mode = 1;
			else if (strcmp(optarg, "pot") == 0) po_mode = 2;
			else if (strcmp(optarg, "res16") == 0) win32 = 0;
			else if (strcmp(optarg, "res")) warning("Output format %s not supported.\n", optarg);
			break;
		case 'r':
			/* ignored for compatibility with rc */
			break;
		case 'U':
			wpp_del_define(optarg);
			break;
		case 'v':
			debuglevel = DEBUGLEVEL_CHAT;
			break;
		default:
			lose++;
			break;
		}
	}

	if(lose)
	{
		fprintf(stderr, usage);
		return 1;
	}

	if (win32)
	{
		wpp_add_cmdline_define("_WIN32=1");
		if (pointer_size == 8) wpp_add_cmdline_define("_WIN64=1");
	}

	/* If we do need to search standard includes, add them to the path */
	if (stdinc)
	{
        /* Odyssey doesn't use this feature
		wpp_add_include_path(INCLUDEDIR"/msvcrt");
		wpp_add_include_path(INCLUDEDIR"/windows");
        */
	}

	/* Kill io buffering when some kind of debuglevel is enabled */
	if(debuglevel)
	{
		setbuf(stdout, NULL);
		setbuf(stderr, NULL);
	}

	parser_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
	yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;

        wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
                       (debuglevel & DEBUGLEVEL_PPTRACE) != 0,
                       (debuglevel & DEBUGLEVEL_PPMSG) != 0 );

	/* Check if the user set a language, else set default */
	if(!defaultlanguage)
		defaultlanguage = new_language(0, 0);

	atexit(cleanup_files);

        while (optind < argc) files[nb_files++] = argv[optind++];

        for (i = 0; i < nb_files; i++)
        {
            input_name = files[i];
            if (load_file( input_name, output_name )) exit(1);
        }
	/* stdin special case. NULL means "stdin" for wpp. */
        if (nb_files == 0 && load_file( NULL, output_name )) exit(1);

	if(debuglevel & DEBUGLEVEL_DUMP)
		dump_resources(resource_top);

	if(verify_translations_mode)
	{
		verify_translations(resource_top);
		exit(0);
	}
	if (po_mode)
	{
            if (po_mode == 2)  /* pot file */
            {
                if (!output_name)
                {
                    output_name = dup_basename( nb_files ? files[0] : NULL, ".rc" );
                    strcat( output_name, ".pot" );
                }
                write_pot_file( output_name );
            }
            else write_po_files( output_name );
            output_name = NULL;
            exit(0);
	}
        if (po_dir) add_translations( po_dir );

	/* Convert the internal lists to binary data */
	resources2res(resource_top);

	chat("Writing .res-file\n");
        if (!output_name)
        {
            output_name = dup_basename( nb_files ? files[0] : NULL, ".rc" );
            strcat(output_name, ".res");
        }
	write_resfile(output_name, resource_top);
	output_name = NULL;

	return 0;
}
예제 #4
0
static void add_filename_node(struct list *list, const char *name)
{
  filename_node_t *node = xmalloc(sizeof *node);
  node->filename = dup_basename( name, ".idl" );
  list_add_tail(list, &node->link);
}
예제 #5
0
파일: wmc.c 프로젝트: jmalak/owmc
int main(int argc,char *argv[])
{
	extern char* optarg;
	extern int   optind;
	int optc;
	int lose = 0;
	int ret;
	int i;
	int cmdlen;

	atexit( cleanup_files );
	signal(SIGSEGV, segvhandler);
	signal( SIGTERM, exit_on_signal );
	signal( SIGINT, exit_on_signal );
#ifdef SIGHUP
	signal( SIGHUP, exit_on_signal );
#endif

	now = time(NULL);

	/* First rebuild the commandline to put in destination */
	/* Could be done through env[], but not all OS-es support it */
	cmdlen = 5; /* for "wmc " and \0 */
	for(i = 1; i < argc; i++)
		cmdlen += strlen(argv[i]) + 1;
	cmdline = xmalloc(cmdlen);
	strcpy(cmdline, "wmc ");
	for(i = 1; i < argc; i++)
	{
		strcat(cmdline, argv[i]);
		if(i < argc-1)
			strcat(cmdline, " ");
	}

	while((optc = getopt(argc, argv, "B:cdDhH:io:O:P:uUvVW")) != EOF)
	{
		switch(optc)
		{
		case 'B':
			switch(optarg[0])
			{
			case 'n':
			case 'N':
				byteorder = WMC_BO_NATIVE;
				break;
			case 'l':
			case 'L':
				byteorder = WMC_BO_LITTLE;
				break;
			case 'b':
			case 'B':
				byteorder = WMC_BO_BIG;
				break;
			default:
				fprintf(stderr, "Byteordering must be n[ative], l[ittle] or b[ig]\n");
				lose++;
			}
			break;
		case 'c':
			custombit = 1;
			break;
		case 'd':
			decimal = 1;
			break;
		case 'D':
			dodebug = 1;
			break;
		case 'h':
			printf("%s", usage);
			exit(0);
			/* No return */
		case 'H':
			header_name = xstrdup(optarg);
			break;
		case 'i':
			rcinline = 1;
			break;
		case 'o':
			output_name = xstrdup(optarg);
			break;
		case 'O':
			if (!strcmp( optarg, "rc" )) output_format = FORMAT_RC;
			else if (!strcmp( optarg, "res" )) output_format = FORMAT_RES;
			else if (!strcmp( optarg, "pot" )) output_format = FORMAT_POT;
			else
                        {
                            fprintf(stderr, "Output format must be rc or res\n" );
                            lose++;
                        }
                        break;
		case 'P':
			po_dir = xstrdup( optarg );
                        break;
		case 'u':
			unicodein = 1;
			break;
		case 'U':
			unicodeout = 1;
			break;
		case 'v':
			show_languages();
			show_codepages();
			exit(0);
			/* No return */
		case 'V':
			printf(version_string);
			exit(0);
			/* No return */
		case 'W':
			pedantic = 1;
			break;
		default:
			lose++;
			break;
		}
	}

	if(lose)
	{
		fprintf(stderr, "%s", usage);
		return 1;
	}

	mcy_debug = dodebug;
	if(dodebug)
	{
		setbuf(stdout, NULL);
		setbuf(stderr, NULL);
	}

	/* Check for input file on command-line */
	if(optind < argc)
	{
		input_name = argv[optind];
	}

	/* Generate appropriate outfile names */
	if(!output_name)
	{
		output_name = dup_basename(input_name, ".mc");
		strcat(output_name, ".rc");
	}

	if(!header_name)
	{
		header_name = dup_basename(input_name, ".mc");
		strcat(header_name, ".h");
	}

	if(input_name)
	{
		if(!(yyin = fopen(input_name, "rb")))
			error("Could not open %s for input\n", input_name);
	}
	else
		yyin = stdin;

	/* ret = mcy_parse(); */ /* this is not mentioned anywhere else - how should it get a value? */

	if(input_name)
		fclose(yyin);

	if(ret)
	{
		/* Error during parse */
		exit(1);
	}

#ifdef WORDS_BIGENDIAN
	byte_swapped = (byteorder == WMC_BO_LITTLE);
#else
	byte_swapped = (byteorder == WMC_BO_BIG);
#endif

        switch (output_format)
        {
        case FORMAT_RC:
            write_h_file(header_name);
            write_rc_file(output_name);
            if(!rcinline)
		write_bin_files();
            break;
        case FORMAT_RES:
            if (po_dir) add_translations( po_dir );
            write_res_file( output_name );
            break;
        case FORMAT_POT:
            write_pot_file( output_name );
            break;
        }
	output_name = NULL;
	header_name = NULL;
	return 0;
}