diff --git a/xorriso/xorriso.1 b/xorriso/xorriso.1 index 8f4f4e18..df505b9a 100644 --- a/xorriso/xorriso.1 +++ b/xorriso/xorriso.1 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH XORRISO 1 "Oct 07, 2008" +.TH XORRISO 1 "Oct 10, 2008" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: @@ -1558,10 +1558,13 @@ With occasion "file_extraction" there are three behaviors: .TP .B Dialog mode control: .TP -\fB\-dialog\fR "on"|"off" -Enable or disable to enter dialog mode after all arguments -are processed. In dialog mode input lines get prompted via -readline or from stdin. +\fB\-dialog\fR "on"|"off"|"single_line" +Enable or disable to enter dialog mode after all arguments are processed. +In dialog mode input lines get prompted via readline or from stdin. +.br +Mode "on" supports input of newline characters witing quotation marks and +line continuation by trailing backslash outside quotation marks. +Mode "single_line" does not. .TP \fB\-page\fR length width Describe terminal to the text pager. See also above, paragraph Result pager. diff --git a/xorriso/xorriso.c b/xorriso/xorriso.c index d2c82431..2398ad0c 100644 --- a/xorriso/xorriso.c +++ b/xorriso/xorriso.c @@ -520,6 +520,7 @@ int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv, bit1= just release argument list argv and return bit2= abort with return(0) if incomplete quotes are found bit3= eventually prepend missing '-' to first argument read from line + bit4= like bit2 but only check quote completeness, do not allocate memory */ { int i,pass,maxl=0,l,argzaehl=0,bufl,line_start_argc; @@ -529,6 +530,9 @@ int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv, Sfile_destroy_argv(argc,argv,0); if(flag&2) return(1); + if(flag & 16) + flag|= 4; + for(pass=0;pass<2;pass++) { cpt= line-1; if(!(flag&1)){ @@ -592,6 +596,8 @@ int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv, if(*cpt==0) break; } if(pass==0){ + if(flag & 16) + return(1); *argc= argzaehl; if(argzaehl>0) { *argv= (char **) Smem_malloC(argzaehl*sizeof(char *)); @@ -3554,10 +3560,9 @@ int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize, bit2= do not write to history line which begin with "-history:" or "-history " */ { - char *cpt= NULL; - int ret; + char *cpt= NULL, **argv= NULL, *linept, *why_append= ""; + int ret, argc= 0, base_length= 0, l, append_line; #ifdef Xorriso_with_readlinE - int l; static char last_input[SfileadrL]= {""}; #endif /* ! Xorriso_with_readlinE */ double tdiff; @@ -3568,18 +3573,20 @@ int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize, tdiff= tv.tv_sec+(1.e-6*(double) tv.tv_usec); fflush(stdout); + linept= line; +get_single:; #ifdef Xorriso_with_readlinE if(xorriso->use_stdin || xorriso->dev_fd_1>=0) { if(flag&2) {ret= 1; goto ex;} - if(Sfile_fgets(line,linesize-1,stdin)==NULL) { + if(Sfile_fgets(linept,linesize - base_length - 1,stdin) == NULL) { /* need a very dramatic end */ kill(getpid(),SIGHUP); {ret= -1; goto ex;} } - {ret= 1; goto ex;} + goto process_single; } if(flag&2) { cpt= NULL; @@ -3591,12 +3598,86 @@ int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize, {ret= -1; goto ex;} } l= strlen(cpt); - if(l>=linesize) { - strncpy(line,cpt,linesize-1); + if(l >= linesize - base_length - 1) { + strncpy(linept, cpt, linesize - 1); line[sizeof(line)-1]= 0; + + /* >>> Line overflow. Raise alert */; + /* <<< */ + goto process_history; + } else - strcpy(line,cpt); + strcpy(linept, cpt); } + +#else /* Xorriso_with_readlinE */ + + if(flag&2) + {ret= 1; goto ex;} + if(Sfile_fgets(linept, linesize - base_length - 1, stdin) == NULL) { + /* need a very dramatic end */ + kill(getpid(),SIGHUP); + {ret= -1; goto ex;} + } + +#endif /* ! Xorriso_with_readlinE */ + +process_single:; + if(xorriso->dialog == 2) { + append_line= 0; + if(linept != line && strcmp(linept, "@@@") == 0) { + sprintf(xorriso->info_text, "Incomplete input line cleared by %s", + linept); + line[0]= 0; + linept= line; + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE",0); + sprintf(xorriso->info_text, "-------------------------------------\n"); + Xorriso_info(xorriso,0); + sprintf(xorriso->info_text, "Enter new text for empty input line :\n"); + Xorriso_info(xorriso,0); + goto get_single; + } + ret= Sfile_make_argv("", line, &argc, &argv, 16); + if(ret < 0) + goto ex; + + l= strlen(line); + if(l > 0) + if(line[l - 1] == '\\') { + line[l - 1]= 0; + append_line= 1; + why_append= "Trailing backslash "; + } + if(ret == 0 && strlen(line) < linesize - 1 && !append_line) { + /* append a newline character */ + if(l >= linesize - 1) { + + /* >>> Line overflow. Raise alert */; + /* <<< */ + goto process_history; + + } + line[l]= '\n'; + line[l + 1]= 0; + append_line= 1; + why_append= "Quoted newline char"; + } + if(append_line) { + base_length= strlen(line); + linept= line + base_length; + sprintf(xorriso->info_text, + "---------------------------------------------------------------\n"); + Xorriso_info(xorriso,0); + sprintf(xorriso->info_text, + "%s : Enter rest of line (or @@@ to clear it) :\n", why_append); + Xorriso_info(xorriso,0); + goto get_single; + } + } + +#ifdef Xorriso_with_readlinE + +process_history:; if(line[0]!=0 && strcmp(last_input,line)!=0 && !(flag&1)) if(!((flag&4) && (strncmp(line,"-history:",9)==0 || strncmp(line,"-history ",9)==0))) { @@ -3605,16 +3686,6 @@ int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize, last_input[sizeof(last_input)-1]= 0; } -#else /* Xorriso_with_readlinE */ - - if(flag&2) - {ret= 1; goto ex;} - if(Sfile_fgets(line,linesize-1,stdin)==NULL) { - /* need a very dramatic end */ - kill(getpid(),SIGHUP); - {ret= -1; goto ex;} - } - #endif /* ! Xorriso_with_readlinE */ ret= 1; @@ -4894,8 +4965,10 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag) Xorriso_status_result(xorriso,filter,fp,flag&2); is_default= 0; - if(xorriso->dialog) + if(xorriso->dialog == 2) sprintf(line,"-dialog on\n"); + else if(xorriso->dialog == 1) + sprintf(line,"-dialog single_line\n"); else { sprintf(line,"-dialog off\n"); is_default= 1; @@ -10941,10 +11014,20 @@ int Xorriso_option_devices(struct XorrisO *xorriso, int flag) } -/* Option -dialog "on"|"off" */ +/* Option -dialog "on"|"single_line"|"off" */ int Xorriso_option_dialog(struct XorrisO *xorriso, char *mode, int flag) { - xorriso->dialog= !!strcmp(mode, "off"); + if(strcmp(mode, "on") == 0 || strcmp(mode, "multi_line") == 0) + xorriso->dialog= 2; + else if(strcmp(mode, "single_line") == 0) + xorriso->dialog= 2; + else if(strcmp(mode, "off") == 0) + xorriso->dialog= 0; + else { + sprintf(xorriso->info_text, "-dialog: unknown mode '%s'", mode); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); + return(0); + } return(1); } @@ -11949,10 +12032,10 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag) " -error_behavior \"image_loading\"|\"file_extraction\" behavior", " Behavior \"best_effort\" is most endurant but may produce", " results which are correct only on the first glimpse.", -" -dialog After all arguments are processed, enter dialog mode.", -" In this mode you may enter searchtexts or any of the options", -" described here. One per line.", -" -dialog_reset Revoke -dialog (works only if given as argument)", +" -dialog \"on\"|\"off\"|\"single_line\"", +" After all arguments are processed, enter dialog mode.", +" \"single_line\" does not support newline characters within", +" open quotation marks and no line continuation by trailing \\.", " -page len width Prompt user after len output lines (0=no prompt).", " width (default 80) can adjust line number computation", " to the output terminal's line width.", @@ -14722,8 +14805,17 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag) /* parse line into args */ ret= Sfile_make_argv(xorriso->progname, line, &argc, &argv, 4); - if(ret<=0) + if(ret < 0) { + Xorriso_msgs_submit(xorriso, 0, + "Severe lack of resources during command line parsing", 0, "FATAL", 0); goto ex; + } + if(ret == 0) { + sprintf(xorriso->info_text, "Incomplete quotation in command line: %s", + line); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); + goto ex; + } if(argc<2) {ret= 1; goto ex;} if(argv[1][0]=='#') diff --git a/xorriso/xorriso_private.h b/xorriso/xorriso_private.h index 42dfebeb..c5326f1c 100644 --- a/xorriso/xorriso_private.h +++ b/xorriso/xorriso_private.h @@ -207,7 +207,7 @@ struct XorrisO { /* the global context of xorriso */ of self-owned directories during restore */ - int dialog; + int dialog; /* 0=off , 1=single-line , 2=multi-line */ /* Pattern matching facility. It still carries legacy from scdbackup/askme.c diff --git a/xorriso/xorriso_timestamp.h b/xorriso/xorriso_timestamp.h index 050f7a4a..493e0e90 100644 --- a/xorriso/xorriso_timestamp.h +++ b/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2008.10.09.145926" +#define Xorriso_timestamP "2008.10.10.131102"