From 4ff35b52a557307265c20e66f7a226c8b4879468 Mon Sep 17 00:00:00 2001 From: "Dimitrie O. Paun" Date: Wed, 1 Oct 2003 03:13:31 +0000 Subject: [PATCH] Teach bin2res to deal with one file at a time. --- tools/bin2res.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/tools/bin2res.c b/tools/bin2res.c index 5297b2655ef..4688203c109 100644 --- a/tools/bin2res.c +++ b/tools/bin2res.c @@ -33,9 +33,11 @@ #endif static const char* help = - "Usage: bin2res [-x] | [-a] [-f] [-h] \n" + "Usage: bin2res [OPTIONS] \n" " -a archive binaries into the file\n" " -x extract binaries from the file\n" + " -i archive the named file into the file\n" + " -o extract the named file from the file\n" " -f force processing of older resources\n" " -h print this help screen and exit\n" "\n" @@ -55,7 +57,8 @@ static const char* help = " bin2res -x myrsrc.rc\n" "Binary files newer than the .rc file are not overwritten.\n" "\n" - "To force processing of all resources, use the -f flag.\n"; + "To force processing of all resources, use the -f flag.\n" + "To process a particular file, use the -i/-o options.\n"; void usage(void) { @@ -118,7 +121,7 @@ const char* parse_marker(const char *line, time_t* last_updated) return res_file_name; } -int process_resources(const char* input_file_name, int inserting, int force_processing) +int process_resources(const char* input_file_name, const char* specific_file_name, int inserting, int force_processing) { char buffer[2048], tmp_file_name[PATH_MAX]; const char *res_file_name; @@ -147,7 +150,8 @@ int process_resources(const char* input_file_name, int inserting, int force_proc { if (inserting) fprintf(ftmp, "%s", buffer); if (!(res_file_name = parse_marker(buffer, &res_last_update))) continue; - if (!force_processing && ((rc_last_update < res_last_update) == !inserting)) + if ( (specific_file_name && strcmp(specific_file_name, res_file_name)) || + (!force_processing && ((rc_last_update < res_last_update) == !inserting)) ) { printf("skipping '%s'\n", res_file_name); continue; @@ -188,9 +192,10 @@ int main(int argc, char **argv) { int convert_dir = 0, optc; int force_overwrite = 0; - const char* input_file_name; + const char* input_file_name = 0; + const char* specific_file_name = 0; - while((optc = getopt(argc, argv, "axfh")) != EOF) + while((optc = getopt(argc, argv, "axi:o:fh")) != EOF) { switch(optc) { @@ -199,6 +204,14 @@ int main(int argc, char **argv) if (convert_dir) usage(); convert_dir = optc; break; + case 'i': + case 'o': + if (specific_file_name) usage(); + specific_file_name = optarg; + optc = ((optc == 'i') ? 'a' : 'x'); + if (convert_dir && convert_dir != optc) usage(); + convert_dir = optc; + break; case 'f': force_overwrite = 1; break; @@ -216,7 +229,8 @@ int main(int argc, char **argv) if (!convert_dir) usage(); - if (!process_resources(input_file_name, convert_dir == 'a', force_overwrite)) + if (!process_resources(input_file_name, specific_file_name, + convert_dir == 'a', force_overwrite)) { perror("Processing failed"); exit(1);