From 28e870966007f50e300ce12666e85af367b94f98 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 13 May 2008 18:08:53 +0000 Subject: [PATCH] Eat up leading dashes with command options, convert inner dashes to underscores --- libisoburn/trunk/xorriso/xorriso.1 | 3 + libisoburn/trunk/xorriso/xorriso.c | 88 ++++++++++++++++---- libisoburn/trunk/xorriso/xorriso.h | 2 +- libisoburn/trunk/xorriso/xorriso_timestamp.h | 2 +- 4 files changed, 79 insertions(+), 16 deletions(-) diff --git a/libisoburn/trunk/xorriso/xorriso.1 b/libisoburn/trunk/xorriso/xorriso.1 index 2f0caf11..455e5911 100644 --- a/libisoburn/trunk/xorriso/xorriso.1 +++ b/libisoburn/trunk/xorriso/xorriso.1 @@ -399,6 +399,9 @@ All command words are shown with a leading dash although this dash is not mandatory for the option to be recognized. There may be future emulation modes, where dashes may become mandatory in order to distinguish options from file addresses. +.br +Normally any number of leading dashes is ignored with command words and +inner dashes are interpreted as underscores. .TP .B Aquiring source and target drive: .TP diff --git a/libisoburn/trunk/xorriso/xorriso.c b/libisoburn/trunk/xorriso/xorriso.c index 30b26102..cd32b914 100644 --- a/libisoburn/trunk/xorriso/xorriso.c +++ b/libisoburn/trunk/xorriso/xorriso.c @@ -9040,7 +9040,7 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag) "", " -list_formats Show media specific list of format descriptors.", "", -" -print-size Print the foreseeable consumption by next -commit.", +" -print_size Print the foreseeable consumption by next -commit.", "", " -tell_media_space", " Print foreseeable available space on output media", @@ -10198,7 +10198,7 @@ int Xorriso_option_print(struct XorrisO *xorriso, char *text, int flag) } -/* Option -print-size +/* Option -print_size @param flag bit0= report in mkisofs compatible form on real stdout */ int Xorriso_option_print_size(struct XorrisO *xorriso, int flag) @@ -10206,7 +10206,7 @@ int Xorriso_option_print_size(struct XorrisO *xorriso, int flag) int ret, fd; if(!xorriso->volset_change_pending) { - sprintf(xorriso->info_text,"-print-size: No image modifications pending"); + sprintf(xorriso->info_text,"-print_size: No image modifications pending"); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0); sprintf(xorriso->result_line,"Image size : 0s\n"); Xorriso_result(xorriso,0); @@ -10214,7 +10214,7 @@ int Xorriso_option_print_size(struct XorrisO *xorriso, int flag) } ret= Xorriso_write_session(xorriso, 1); if(ret<=0) { - sprintf(xorriso->info_text,"-print-size: Failed to set up virtual -commit"); + sprintf(xorriso->info_text,"-print_size: Failed to set up virtual -commit"); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); return(0); } @@ -10897,6 +10897,41 @@ int Xorriso_option_volid(struct XorrisO *xorriso, char *volid, int flag) /* ---------------------------- End Options API ------------------------ */ +/* @return <0 error , >=0 number of skipped dashes +*/ +int Xorriso_normalize_command(struct XorrisO *xorriso, char *original_cmd, + int argno, char *cmd_data, int sizeof_cmd_data, + char **cmd, int flag) +{ + int was_dashed= 0; + char *dash_pt; + + if(strlen(original_cmd)>= sizeof_cmd_data) { + if(argno>=0) + sprintf(xorriso->info_text, "Oversized argument #%d (length %d)\n", + argno, (int) strlen(original_cmd)); + else + sprintf(xorriso->info_text, "Oversized option (length %d)\n", + (int) strlen(original_cmd)); + return(-1); + } + strcpy(cmd_data, original_cmd); + *cmd= cmd_data; + if(strcmp(*cmd, "--")==0) + return(1); + while((*cmd)[0]=='-') { + if((*cmd)[1]==0) + break; + was_dashed++; + (*cmd)++; + } + for(dash_pt= *cmd; *dash_pt!=0; dash_pt++) + if(*dash_pt=='-') + *dash_pt= '_'; + return(1); +} + + int Xorriso_interpreter(struct XorrisO *xorriso, int argc, char **argv, int *idx, int flag) /* @@ -10909,7 +10944,7 @@ return: { int ret, was_dashed, end_ret; int num1, num2; - char *cmd, *arg1, *arg2; + char *cmd, *original_cmd, cmd_data[2*SfileadrL], *arg1, *arg2; if(xorriso==NULL) return(0); @@ -10924,18 +10959,32 @@ next_command:; xorriso->request_to_abort= xorriso->request_not_to_ask= 0; Xorriso_set_problem_status(xorriso, "", 0); if((*idx)add_plainly==3 && cmd[0] && !xorriso->is_dialog) { (*idx)++; goto add_plain_argument; } was_dashed= 0; + +#ifdef NIX + if(cmd[0]=='-' && cmd[1]!='-' && cmd[1]!=0) { was_dashed= 1; cmd++; } + +#else /* NIX */ + + ret= Xorriso_normalize_command(xorriso, original_cmd, -1, + cmd_data, sizeof(cmd_data), &cmd, 0); + if(ret<0) + goto eval_any_problems; + was_dashed= ret; + +#endif /* ! NIX */ + (*idx)++; if((*idx)add_plainly>1) goto add_plain_argument; unknown_option:; - sprintf(xorriso->info_text, - "=== Not a known option:\n"); - sprintf(xorriso->info_text+strlen(xorriso->info_text), - "=== '%s%s'\n",(was_dashed ? "-" : ""), cmd); + sprintf(xorriso->info_text, "=== Not a known option:\n === '%s'\n", + original_cmd); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); {ret= 0; goto eval_any_problems;} @@ -11514,15 +11561,28 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv, { int i, ret, was_dashed, num2; int was_report_about= 0, was_abort_on= 0, was_return_with= 0; - char *cmd, *arg1, *arg2; + char *cmd, *original_cmd, cmd_data[5*SfileadrL], *arg1, *arg2; for(i=1+(flag&1);i