Implemented setter level of -abort_on, fixed bugs about -f,-no_rc,startup files

This commit is contained in:
Thomas Schmitt 2007-10-14 10:56:01 +00:00
parent 36ba6a1669
commit 58e3a855bd
2 changed files with 133 additions and 59 deletions

View File

@ -632,6 +632,32 @@ int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv,
}
/** Combine environment variable HOME with given filename
@param filename Address relative to $HOME
@param fileadr Resulting combined address
@param fa_size Size of array fileadr
@param flag Unused yet
@return 1=ok , 0=no HOME variable , -1=result address too long
*/
int Sfile_home_adr_s(char *filename, char *fileadr, int fa_size, int flag)
{
char *home;
strcpy(fileadr,filename);
home= getenv("HOME");
if(home==NULL)
return(0);
if(strlen(home)+strlen(filename)+1>=fa_size)
return(-1);
strcpy(fileadr,home);
if(filename[0]!=0){
strcat(fileadr,"/");
strcat(fileadr,filename);
}
return(1);
}
#endif /* Xorriso_sfile_externaL */
@ -1635,43 +1661,6 @@ return:
#endif /* ! Xorriso_dirseq_externaL */
/* ------------------------------------------------------------------------ */
/* registers what options are already preset during Xorriso_prescan_args() */
struct Xorriso_prestatE {
int no_rc;
int pkt_set;
int logfile_set[4];
int logfile_pkt_set;
};
int Xorriso_prestate_new(struct Xorriso_prestatE **pst, int flag)
{
struct Xorriso_prestatE *m;
*pst= m= TSOB_FELD(struct Xorriso_prestatE,1);
if(m==NULL)
return(-1);
m->no_rc= 0;
m->pkt_set= 0;
m->logfile_set[0]= m->logfile_set[1]= m->logfile_set[2]= m->logfile_set[3]= 0;
m->logfile_pkt_set= 0;
return(1);
}
int Xorriso_prestate_destroy(struct Xorriso_prestatE **pst, int flag)
{
if(*pst==NULL)
return(0);
free((char *) *pst);
*pst= NULL;
return(1);
}
/* ------------------------------- Xorriso -------------------------------- */
@ -1681,13 +1670,28 @@ int Xorriso_prestate_destroy(struct Xorriso_prestatE **pst, int flag)
/* try to catch signals and ignore them during abort handling */
#define Xorriso_abort_handler_defaulT (1|(2<<4))
/** The list of startup file names */
#define Xorriso_rc_nuM 4
static char Xorriso_sys_rc_nameS[Xorriso_rc_nuM][80]= {
"/etc/default/xorriso",
"/etc/opt/xorriso/rc",
"/etc/xorriso/xorriso.conf",
"placeholder for $HOME/.xorrisorc"
};
struct XorrisO { /* the global context of askme */
/* source */
char progname[SfileadrL];
char initial_wdx[SfileadrL];
int no_rc;
/** List of startupfiles */
char rc_filenames[Xorriso_rc_nuM][SfileadrL];
int rc_filename_count;
char wdi[SfileadrL];
char wdx[SfileadrL];
int did_something_useful;
@ -1747,8 +1751,8 @@ struct XorrisO { /* the global context of askme */
char logfile[4][SfileadrL];
int status_history_max; /* for -status long_history */
/* >>> put -abort_on severity parameters here <<< */
char abort_on_severity[20];
/* temporary search facilities */
@ -1764,7 +1768,6 @@ struct XorrisO { /* the global context of askme */
/* >>> put overwrite_mode here */
/* run state */
struct Xorriso_prestatE *prescan_state;
int is_dialog;
int bar_is_fresh;
char pending_option[SfileadrL]; /* eventual option entered at page prompt */
@ -1800,7 +1803,7 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag);
int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
{
int ret, i;
int i;
struct XorrisO *m;
*xorriso= m= TSOB_FELD(struct XorrisO,1);
@ -1808,6 +1811,13 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
return(-1);
strcpy(m->progname,progname);
m->initial_wdx[0]= 0;
m->no_rc= 0;
m->rc_filename_count= Xorriso_rc_nuM;
for(i=0;i<m->rc_filename_count-1;i++)
strcpy(m->rc_filenames[i],Xorriso_sys_rc_nameS[i]);
m->rc_filenames[m->rc_filename_count-1][0]= 0;
m->wdi[0]= 0;
m->wdx[0]= 0;
m->did_something_useful= 0;
@ -1839,6 +1849,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
for(i=0; i<4; i++)
m->logfile[i][0]= 0;
m->status_history_max= Xorriso_status_history_maX;
strcpy(m->abort_on_severity,"SORRY");
#ifdef Xorriso_with_regeX
m->re= NULL;
/* >>> ??? how to initialize m->match[0] ? */
@ -1847,7 +1858,6 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->re_count= 0;
m->re_fill= 0;
m->reg_expr[0]= 0;
m->prescan_state= NULL;
m->is_dialog= 0;
m->bar_is_fresh= 0;
m->pending_option[0]= 0;
@ -1864,14 +1874,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->result_open_line_len= 0;
m->info_text[0]= 0;
ret= Xorriso_prestate_new(&(m->prescan_state),0);
if(ret<=0)
goto failed;
return(1);
failed:
Xorriso_destroy(xorriso,0);
return(-1);
}
@ -1913,7 +1916,6 @@ int Xorriso_destroy(struct XorrisO **xorriso, int flag)
if(m==NULL)
return(0);
Xorriso_destroy_re(m,0);
Xorriso_prestate_destroy(&(m->prescan_state),0);
free((char *) m);
*xorriso= NULL;
@ -2773,6 +2775,10 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
no_defaults= flag&1;
line= xorriso->result_line;
if(xorriso->no_rc) {
sprintf(line,"-no_rc\n");
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
is_default= 0;
if(xorriso->dialog)
sprintf(line,"-dialog\n");
@ -2897,7 +2903,10 @@ 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);
/* >>> BAUSTELLE */
is_default= (strcmp(xorriso->abort_on_severity,"SORRY")==0);
sprintf(line,"-abort_on %s\n",xorriso->abort_on_severity);
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
if(xorriso->status_history_max!=Xorriso_status_history_maX || !no_defaults) {
sprintf(line,"-status_history_max %d\n",xorriso->status_history_max);
@ -3019,7 +3028,20 @@ int Xorriso__end_idx(int argc, char **argv, int idx, int flag)
/* Option -abort_on */
int Xorriso_option_abort_on(struct XorrisO *xorriso, char *severity, int flag)
{
fprintf(stderr, ">>> LIBISOBURN : -abort_on %s",severity);
int i;
static char svt[][20]= {"NEVER", "ABORT", "FATAL", "SORRY", "WARNING", "HINT",
"NOTE", "UPDATE", "DEBUG", "ALL", ""};
for(i= 0; svt[i][0]!=0; i++)
if(strcmp(svt[i],severity)==0)
break;
if(svt[i][0]==0) {
/* >>> unknown severity class */;
return(0);
}
strcpy(xorriso->abort_on_severity,severity);
return(1);
}
@ -3281,7 +3303,7 @@ int Xorriso_option_dev(struct XorrisO *xorriso, char *adr, int flag)
if((flag&3)==0)
flag|= 3;
fprintf(stderr, ">>> XORRISO : would execute -%sdev %s",
fprintf(stderr, ">>> XORRISO : would execute -%sdev %s\n",
((flag&3)==1 ? "in" : ((flag&3)==2 ? "out" : "")), adr);
return(1);
@ -3813,7 +3835,7 @@ int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
/* Option -no_rc */
int Xorriso_option_no_rc(struct XorrisO *xorriso, int flag)
{
xorriso->prescan_state->no_rc= 1;
xorriso->no_rc= 1;
return(1);
}
@ -4225,6 +4247,9 @@ int Xorriso_option_v_capital(struct XorrisO *xorriso, char *volid, int flag)
/* Option -version */
int Xorriso_option_version(struct XorrisO *xorriso, int flag)
{
/* >>> print rather to result channel */;
printf("xorriso %s : RockRidge filesystem manipulator\n", PROG_VERSION);
printf("Copyright (C) 2007, Thomas Schmitt <scdbackup@gmx.net>, libburnia project\n");
printf("Version timestamp : %s\n",Xorriso_timestamP);
@ -4233,6 +4258,7 @@ int Xorriso_option_version(struct XorrisO *xorriso, int flag)
return(1);
}
/* ---------------------------- End Options API ------------------------ */
@ -4358,6 +4384,9 @@ next_command:;
Xorriso_option_end(xorriso, 0);
{ret= 3; goto ex;}
} else if(strcmp(cmd,"-f")==0) {
ret= Xorriso_option_f(xorriso, 0);
} else if(strcmp(cmd,"-find")==0 || strcmp(cmd,"-findi")==0) {
(*idx)++;
ret= Xorriso_option_findi(xorriso, arg1, 0);
@ -4416,6 +4445,9 @@ next_command:;
} else if(strcmp(cmd,"-mkdir")==0 || strcmp(cmd,"-mkdiri")==0) {
ret= Xorriso_option_mkdiri(xorriso, argc, argv, idx, 0);
} else if(strcmp(cmd,"-no_rc")==0) {
ret= Xorriso_option_no_rc(xorriso, 0);
} else if(strcmp(cmd,"-options_from_file")==0) {
(*idx)++;
ret= Xorriso_option_options_from_file(xorriso,arg1,0);
@ -4435,6 +4467,10 @@ next_command:;
num1= num2= 0;
sscanf(arg1,"%d",&num1);
sscanf(arg2,"%d",&num2);
if(num1<0)
num1= 0;
if(num2<=0)
num2= 80;
ret= Xorriso_option_page(xorriso, num1, num2, 0);
} else if(strcmp(cmd,"-path-list")==0) {
@ -4702,6 +4738,26 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv,
}
/** Load content startup files into preskin cache */
int Xorriso_read_rc(struct XorrisO *xorriso, int flag)
{
int ret,i;
i= xorriso->rc_filename_count-1;
Sfile_home_adr_s(".xorrisorc", xorriso->rc_filenames[i],
sizeof(xorriso->rc_filenames[i]),0);
for(i=0;i<xorriso->rc_filename_count;i++) {
ret= Sfile_type(xorriso->rc_filenames[i],1|8);
if(ret!=1)
continue;
ret= Xorriso_option_options_from_file(xorriso,xorriso->rc_filenames[i],0);
if(ret!=1)
return(ret);
}
return(1);
}
#ifdef Xorriso_with_maiN
int main(int argc, char **argv)
@ -4710,8 +4766,12 @@ int main(int argc, char **argv)
struct XorrisO *xorriso= NULL;
if(argc<2) {
fprintf(stderr,
"xorriso %s : RockRidge filesystem manipulator, libburnia project.\n\n",
PROG_VERSION);
fprintf(stderr,"usage : %s [options]\n",
argv[0]);
fprintf(stderr," More is told by option -help\n");
exit(2);
}
ret= Xorriso_new(&xorriso,argv[0],0);
@ -4720,18 +4780,32 @@ int main(int argc, char **argv)
exit(3);
}
/* >>> Is a prescan needed at all ?
There is no fixed meaning of the first argument */
/* The prescan of arguments performs actions which have to happen before
the normal processing of startup files and arguments. Currently:
-no_rc and single-argumenti runs like -help or -version.
*/
ret= Xorriso_prescan_args(xorriso,argc,argv,0);
if(ret==0)
goto end_sucessfully;
if(ret<0)
exit(5);
/* >>> startup file */
/* Interpret startup file */
if(!xorriso->no_rc) {
ret= Xorriso_read_rc(xorriso, 0);
if(ret==3)
goto end_sucessfully;
if(ret<=0)
exit(5);
}
/* Interpret program arguments */
i= 1;
ret= Xorriso_interpreter(xorriso,argc,argv,&i,0);
if(ret==3)
goto end_sucessfully;
if(ret<=0)
exit(5);
if(xorriso->dialog) {
ret= Xorriso_dialog(xorriso,0);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.13.152252"
#define Xorriso_timestamP "2007.10.14.110003"