New option -return_with
This commit is contained in:
@ -2731,6 +2731,11 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
|
||||
Xorriso__text_to_sev(m->abort_on_text, &m->abort_on_severity, 0);
|
||||
m->problem_status= 0;
|
||||
m->problem_status_text[0]= 0;
|
||||
strcpy(m->return_with_text, "SORRY");
|
||||
Xorriso__text_to_sev(m->return_with_text, &m->return_with_severity, 0);
|
||||
m->return_with_value= 32;
|
||||
m->eternal_problem_status= 0;
|
||||
m->eternal_problem_status_text[0]= 0;
|
||||
#ifdef Xorriso_with_regeX
|
||||
m->re= NULL;
|
||||
/* >>> ??? how to initialize m->match[0] ? */
|
||||
@ -3964,6 +3969,11 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
|
||||
if(!(is_default && no_defaults))
|
||||
Xorriso_status_result(xorriso,filter,fp,flag&2);
|
||||
|
||||
is_default= (strcmp(xorriso->return_with_text,"SORRY")==0);
|
||||
sprintf(line,"-return_with %s\n",xorriso->return_with_text);
|
||||
if(!(is_default && no_defaults))
|
||||
Xorriso_status_result(xorriso,filter,fp,flag&2);
|
||||
|
||||
is_default= (strcmp(xorriso->abort_on_text,"FATAL")==0);
|
||||
sprintf(line,"-abort_on %s\n",xorriso->abort_on_text);
|
||||
if(!(is_default && no_defaults))
|
||||
@ -4682,6 +4692,10 @@ int Xorriso_set_problem_status(struct XorrisO *xorriso, char *severity,
|
||||
return(0);
|
||||
xorriso->problem_status= sev;
|
||||
strcpy(xorriso->problem_status_text, sev_text);
|
||||
if(sev > xorriso->eternal_problem_status) {
|
||||
xorriso->eternal_problem_status= sev;
|
||||
strcpy(xorriso->eternal_problem_status_text, sev_text);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
@ -4717,6 +4731,10 @@ int Xorriso_msgs_submit(struct XorrisO *xorriso,
|
||||
xorriso->problem_status= sev;
|
||||
strcpy(xorriso->problem_status_text, sev_text);
|
||||
}
|
||||
if(xorriso->eternal_problem_status<sev) {
|
||||
xorriso->eternal_problem_status= sev;
|
||||
strcpy(xorriso->eternal_problem_status_text, sev_text);
|
||||
}
|
||||
|
||||
/* Report problem event */
|
||||
if(sev<xorriso->report_about_severity && sev<xorriso->abort_on_severity)
|
||||
@ -7279,6 +7297,9 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
|
||||
" -help Print this text",
|
||||
" -abort_on severity Set the threshhold for events to abort the program.",
|
||||
" Useful severities: NEVER, ABORT, FATAL, FAILURE, SORRY, WARNING",
|
||||
" -return_with severity exit_value Set the threshhold for events to return",
|
||||
" at program end the given exit_value even if not aborted.",
|
||||
" exit_value may be 0 or 32 to 63.",
|
||||
" -report_about severity Set the threshhold for events to be reported.",
|
||||
" Use -abort_on severities or: HINT, NOTE, UPDATE, DEBUG, ALL",
|
||||
" -dialog after all arguments are processed, enter dialog mode.",
|
||||
@ -8078,6 +8099,34 @@ int Xorriso_option_report_about(struct XorrisO *xorriso, char *severity,
|
||||
}
|
||||
|
||||
|
||||
/* Option -return_with */
|
||||
int Xorriso_option_return_with(struct XorrisO *xorriso, char *severity,
|
||||
int exit_value, int flag)
|
||||
{
|
||||
int ret, sev;
|
||||
char sfe[5*SfileadrL];
|
||||
|
||||
ret= Xorriso__text_to_sev(severity, &sev, 0);
|
||||
if(ret<=0) {
|
||||
sprintf(xorriso->info_text,
|
||||
"-return_with: Not a known severity name : %s",
|
||||
Text_shellsafe(severity, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
return(ret);
|
||||
}
|
||||
if(exit_value && (exit_value < 32 || exit_value > 63)) {
|
||||
sprintf(xorriso->info_text,
|
||||
"-return_with: Not an allowed exit_value. Use 0, or 32 to 63.");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
return(0);
|
||||
}
|
||||
if(Sfile_str(xorriso->return_with_text,severity,0)<=0)
|
||||
return(-1);
|
||||
xorriso->return_with_severity= sev;
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* Options -rm alias -rmi , -rm_r alias -rm_ri , -rmdir alias -rmdiri */
|
||||
/* @param flag bit0=recursive , bit2= remove empty directory: rmdir */
|
||||
int Xorriso_option_rmi(struct XorrisO *xorriso, int argc, char **argv,
|
||||
@ -8724,6 +8773,12 @@ next_command:;
|
||||
(*idx)++;
|
||||
ret= Xorriso_option_report_about(xorriso, arg1, 0);
|
||||
|
||||
} else if(strcmp(cmd,"return_with")==0) {
|
||||
(*idx)+= 2;
|
||||
num2= 0;
|
||||
sscanf(arg2,"%d",&num2);
|
||||
ret= Xorriso_option_return_with(xorriso, arg1, num2, 0);
|
||||
|
||||
} else if(strcmp(cmd,"rm")==0 || strcmp(cmd,"rmi")==0) {
|
||||
ret= Xorriso_option_rmi(xorriso, argc, argv, idx, 0);
|
||||
|
||||
@ -8975,8 +9030,9 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv,
|
||||
1 ok, go on
|
||||
*/
|
||||
{
|
||||
int i, ret, was_dashed, was_report_about= 0, was_abort_on;
|
||||
char *cmd, *arg1;
|
||||
int i, ret, was_dashed, num2;
|
||||
int was_report_about= 0, was_abort_on= 0, was_return_with= 0;
|
||||
char *cmd, *arg1, *arg2;
|
||||
|
||||
for(i=1+(flag&1);i<argc;i++) {
|
||||
cmd= argv[i];
|
||||
@ -8988,6 +9044,9 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv,
|
||||
arg1= "";
|
||||
if(i+1<argc)
|
||||
arg1= argv[i+1];
|
||||
arg2= "";
|
||||
if(i+2<argc)
|
||||
arg2= argv[2+1];
|
||||
if(i>1)
|
||||
xorriso->did_something_useful= 1;
|
||||
if(i==1 && argc==2) {
|
||||
@ -9044,6 +9103,14 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv,
|
||||
Xorriso_option_report_about(xorriso, arg1, 0);
|
||||
was_report_about= 1;
|
||||
|
||||
} else if(strcmp(cmd,"return_with")==0 && was_dashed) {
|
||||
i+= 2;
|
||||
num2= 0;
|
||||
sscanf(arg2,"%d",&num2);
|
||||
if(!was_return_with)
|
||||
Xorriso_option_return_with(xorriso, arg1, num2, 0);
|
||||
was_return_with= 1;
|
||||
|
||||
}
|
||||
}
|
||||
return(1);
|
||||
@ -9077,6 +9144,23 @@ int Xorriso_read_rc(struct XorrisO *xorriso, int flag)
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_make_return_value(struct XorrisO *xorriso, int flag)
|
||||
{
|
||||
int exit_value= 0;
|
||||
|
||||
if(xorriso->eternal_problem_status >= xorriso->return_with_severity)
|
||||
exit_value= xorriso->return_with_value;
|
||||
if(exit_value) {
|
||||
sprintf(xorriso->info_text,
|
||||
"-return_with %s %d triggered by problem severity %s",
|
||||
xorriso->return_with_text, exit_value,
|
||||
xorriso->eternal_problem_status_text);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
||||
}
|
||||
return(exit_value);
|
||||
}
|
||||
|
||||
|
||||
#ifdef Xorriso_with_maiN
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -9151,7 +9235,8 @@ end_sucessfully:;
|
||||
if(xorriso->volset_change_pending)
|
||||
Xorriso_option_end(xorriso, 2);
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
ret= Xorriso_make_return_value(xorriso, 0);
|
||||
Xorriso_destroy(&xorriso,1);
|
||||
exit(0);
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user