Replaced some large local variables by other means in xorriso/parse_exec.c

This commit is contained in:
Thomas Schmitt 2011-05-06 15:18:39 +00:00
parent 1e4945f483
commit a7c7b42afc
2 changed files with 83 additions and 52 deletions

View File

@ -282,7 +282,6 @@ int Xorriso_cpmv_args(struct XorrisO *xorriso, char *cmd,
{
int destc= 0, is_dir=0, end_idx, ret, i;
char **destv= NULL;
char sfe[5*SfileadrL];
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx,
(xorriso->do_iso_rr_pattern==1)|(flag&2));
@ -318,8 +317,9 @@ int Xorriso_cpmv_args(struct XorrisO *xorriso, char *cmd,
for(i= 0; i<*optc; i++)
Xorriso_msgs_submit(xorriso, 0, (*optv)[i], 0, "ERRFILE", 0);
sprintf(xorriso->info_text,
"%s: more than one origin given, destination is a non-directory: %s",
cmd, Text_shellsafe(destv[0], sfe, 0));
"%s: more than one origin given, destination is a non-directory: ",
cmd);
Text_shellsafe(destv[0], xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
{ret= 0; goto ex;}
}
@ -444,8 +444,8 @@ int Xorriso_normalize_command(struct XorrisO *xorriso, char *original_cmd,
int Xorriso_count_args(struct XorrisO *xorriso, int argc, char **argv,
int *count, int flag)
{
int ret, was_dashed= 0, i;
char *cmd, cmd_data[2*SfileadrL];
int ret, was_dashed= 0, i, cmd_data_size= 2 * SfileadrL;
char *cmd, *cmd_data= NULL;
static char arg0_commands[][40]= {
"ban_stdio_write","close_filter_list","commit","devices","end",
"for_backup", "help",
@ -514,45 +514,47 @@ int Xorriso_count_args(struct XorrisO *xorriso, int argc, char **argv,
""
};
Xorriso_alloc_meM(cmd_data, char, cmd_data_size);
*count= 0;
if(argc<=0)
return(-1);
{ret= -1; goto ex;}
ret= Xorriso_normalize_command(xorriso, argv[0], -1,
cmd_data, sizeof(cmd_data), &cmd, 0);
cmd_data, cmd_data_size, &cmd, 0);
if(ret<0)
return(ret);
goto ex;
was_dashed= (ret>0);
if(cmd[0]=='#' || cmd[0]==0 || strcmp(cmd, xorriso->list_delimiter) == 0) {
/* ignore: comment line , empty option , orphaned list delimiter */
return(1);
{ret= 1; goto ex;}
}
for(i=0; arg0_commands[i][0]!=0; i++)
if(strcmp(arg0_commands[i], cmd)==0)
return(1);
{ret= 1; goto ex;}
*count= 1;
for(i=0; arg1_commands[i][0]!=0; i++)
if(strcmp(arg1_commands[i], cmd)==0)
return(1);
{ret= 1; goto ex;}
*count= 2;
for(i=0; arg2_commands[i][0]!=0; i++)
if(strcmp(arg2_commands[i], cmd)==0)
return(1);
{ret= 1; goto ex;}
*count= 3;
for(i=0; arg3_commands[i][0]!=0; i++)
if(strcmp(arg3_commands[i], cmd)==0)
return(1);
{ret= 1; goto ex;}
*count= 4;
for(i=0; arg4_commands[i][0]!=0; i++)
if(strcmp(arg4_commands[i], cmd)==0)
return(1);
{ret= 1; goto ex;}
*count= 0;
for(i=0; argn_commands[i][0]!=0; i++)
if(strcmp(argn_commands[i], cmd)==0) {
ret= Xorriso_end_idx(xorriso, argc, argv, 1, 1);
if(ret<1)
return(ret);
goto ex;
*count= ret-1;
return(1);
{ret= 1; goto ex;}
}
if(!(flag&1)) {
@ -560,7 +562,10 @@ int Xorriso_count_args(struct XorrisO *xorriso, int argc, char **argv,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
}
return(2+!was_dashed);
ret= 2 + !was_dashed;
ex:
Xorriso_free_meM(cmd_data);
return(ret);
}
@ -575,11 +580,13 @@ return:
<=0 error , 1 = success , 2 = problem event ignored , 3 = end program run
*/
{
int ret, was_dashed, end_ret, num1, num2;
char *cmd, *original_cmd, cmd_data[2*SfileadrL], *arg1, *arg2;
int ret, was_dashed, end_ret, num1, num2, cmd_data_size= 2 * SfileadrL;
char *cmd, *original_cmd, *cmd_data= NULL, *arg1, *arg2;
Xorriso_alloc_meM(cmd_data, char, cmd_data_size);
if(xorriso==NULL)
return(0);
{ret= 0; goto ex;}
if(xorriso->is_dialog) {
xorriso->result_line_counter= xorriso->result_page_counter= 0;
if(xorriso->result_page_length<0)
@ -616,7 +623,7 @@ next_command:;
was_dashed= 0;
ret= Xorriso_normalize_command(xorriso, original_cmd, -1,
cmd_data, sizeof(cmd_data), &cmd, 0);
cmd_data, cmd_data_size, &cmd, 0);
if(ret<0)
goto eval_any_problems;
was_dashed= ret;
@ -866,7 +873,7 @@ next_command:;
end_ret= Xorriso_option_end(xorriso, 0);
ret= Xorriso_eval_problem_status(xorriso, ret, 0);
if(ret<0)
return(ret);
goto ex;
if(end_ret!=2)
{ret= 3; goto ex;}
@ -1231,7 +1238,7 @@ next_command:;
end_ret= Xorriso_option_end(xorriso, 1);
ret= Xorriso_eval_problem_status(xorriso, ret, 0);
if(ret<0)
return(ret);
goto ex;
if(end_ret!=2)
{ret= 3; goto ex;}
@ -1413,13 +1420,14 @@ add_plain_argument:;
eval_any_problems:
ret= Xorriso_eval_problem_status(xorriso, ret, 0);
if(ret<0)
return(ret);
goto ex;
if(*idx<argc)
goto next_command;
ex:;
fflush(stdout);
Xorriso_free_meM(cmd_data);
return(ret);
}
@ -1492,11 +1500,13 @@ ex:;
int Xorriso_dialog(struct XorrisO *xorriso, int flag)
{
int ret,first_round;
char line[2*SfileadrL];
int ret,first_round, line_size= 2 * SfileadrL;
char *line= NULL;
Xorriso_alloc_meM(line, char, line_size);
if(!xorriso->dialog)
return(1);
{ret= 1; goto ex;}
if(xorriso->abort_on_is_default)
Xorriso_option_abort_on(xorriso, "NEVER", 0);
xorriso->is_dialog= 1;
@ -1514,7 +1524,7 @@ int Xorriso_dialog(struct XorrisO *xorriso, int flag)
sprintf(xorriso->info_text,"enter option and arguments :\n");
Xorriso_info(xorriso,0);
Xorriso_mark(xorriso,0);
ret= Xorriso_dialog_input(xorriso,line,sizeof(line),4);
ret= Xorriso_dialog_input(xorriso,line, line_size, 4);
if(ret<=0)
break;
}
@ -1533,6 +1543,7 @@ int Xorriso_dialog(struct XorrisO *xorriso, int flag)
ret= 1;
ex:;
xorriso->is_dialog= 0;
Xorriso_free_meM(line);
return(ret);
}
@ -1551,17 +1562,19 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv,
{
int i, ret, was_dashed, num2, arg_count;
int was_report_about= 0, was_abort_on= 0, was_return_with= 0;
int was_signal_handling= 0, was_scsi_log= 0;
char *cmd, *original_cmd, cmd_data[5*SfileadrL], *arg1, *arg2;
int was_signal_handling= 0, was_scsi_log= 0, cmd_data_size= 5 * SfileadrL;
char *cmd, *original_cmd, *cmd_data= NULL, *arg1, *arg2;
char mem_list_delimiter[81];
Xorriso_alloc_meM(cmd_data, char, cmd_data_size);
strcpy(mem_list_delimiter, xorriso->list_delimiter);
for(i=1+(flag&1);i<argc;i++) {
original_cmd= cmd= argv[i];
was_dashed= 0;
was_dashed= Xorriso_normalize_command(xorriso, original_cmd, i,
cmd_data, sizeof(cmd_data), &cmd, 0);
cmd_data, cmd_data_size, &cmd, 0);
if(was_dashed<0)
{ret= -1; goto ex;}
@ -1669,6 +1682,7 @@ protect_stdout:;
ret= 1;
ex:;
strcpy(xorriso->list_delimiter, mem_list_delimiter);
Xorriso_free_meM(cmd_data);
return(ret);
}
@ -1677,7 +1691,9 @@ int Xorriso_read_as_mkisofsrc(struct XorrisO *xorriso, char *path, int flag)
{
int ret, linecount= 0;
FILE *fp= NULL;
char *sret, line[SfileadrL], *cpt, *wpt;
char *sret, *line= NULL, *cpt, *wpt;
Xorriso_alloc_meM(line, char, SfileadrL);
ret= Xorriso_afile_fopen(xorriso, path, "rb", &fp, 1 | 2);
if(ret <= 0)
@ -1757,6 +1773,7 @@ int Xorriso_read_as_mkisofsrc(struct XorrisO *xorriso, char *path, int flag)
ex:
if(fp != NULL)
fclose(fp);
Xorriso_free_meM(line);
return(ret);
}
@ -1766,19 +1783,21 @@ ex:
*/
int Xorriso_read_mkisofsrc(struct XorrisO *xorriso, int flag)
{
char path[SfileadrL], *cpt;
char *path= NULL, *cpt;
int ret;
Xorriso_alloc_meM(path, char, SfileadrL);
ret= Xorriso_read_as_mkisofsrc(xorriso, "./.mkisofsrc", 0);
if(ret > 0)
return(ret);
goto ex;
cpt= getenv("MKISOFSRC");
if(cpt != NULL) {
strncpy(path, cpt, SfileadrL - 1);
path[SfileadrL - 1]= 0;
ret= Xorriso_read_as_mkisofsrc(xorriso, path, 0);
if(ret > 0)
return(ret);
goto ex;
}
cpt= getenv("HOME");
if(cpt != NULL) {
@ -1787,7 +1806,7 @@ int Xorriso_read_mkisofsrc(struct XorrisO *xorriso, int flag)
strcat(path, "/.mkisofsrc");
ret= Xorriso_read_as_mkisofsrc(xorriso, path, 0);
if(ret > 0)
return(ret);
goto ex;
}
strcpy(path, xorriso->progname);
cpt= strrchr(path, '/');
@ -1795,10 +1814,13 @@ int Xorriso_read_mkisofsrc(struct XorrisO *xorriso, int flag)
strcpy(cpt + 1, ".mkisofsrc");
ret= Xorriso_read_as_mkisofsrc(xorriso, path, 0);
if(ret > 0)
return(ret);
goto ex;
}
/* no .mkisofsrc file found */
return(2);
ret= 2;
ex:;
Xorriso_free_meM(path);
return(ret);
}
@ -1872,9 +1894,11 @@ int Xorriso_program_arg_bsl(struct XorrisO *xorriso, int argc, char ***argv,
int Xorriso_make_abs_adr(struct XorrisO *xorriso, char *wd, char *name,
char adr[], int flag)
{
char norm_adr[SfileadrL];
char *norm_adr= NULL;
int ret;
Xorriso_alloc_meM(norm_adr, char, SfileadrL);
if((wd[0]!=0 || (flag&4)) && !((flag&1) && name[0]=='/')) {
if(strlen(wd)+1>=SfileadrL)
goto much_too_long;
@ -1883,7 +1907,7 @@ int Xorriso_make_abs_adr(struct XorrisO *xorriso, char *wd, char *name,
if(Sfile_add_to_path(adr, name, 0)<=0) {
much_too_long:;
Xorriso_much_too_long(xorriso, (int) (strlen(adr)+strlen(name)+1), 2);
return(0);
{ret= 0; goto ex;}
}
} else {
if(strlen(name)+1>=SfileadrL)
@ -1894,12 +1918,15 @@ much_too_long:;
ret= Xorriso_normalize_img_path(xorriso, "", adr, norm_adr,
1|2|((flag&8)>>1));
if(ret<=0)
return(ret);
goto ex;
if(norm_adr[0]==0)
strcpy(norm_adr, "/");
strcpy(adr, norm_adr);
}
return(1);
ret= 1;
ex:;
Xorriso_free_meM(norm_adr);
return(ret);
}
@ -1971,11 +1998,12 @@ int Xorriso_execv(struct XorrisO *xorriso, char *cmd, char *env_path,
int *status, int flag)
{
int ret, argc= 0;
char **argv= NULL, *pathlist= NULL, *cpt, *npt, prog[SfileadrL];
char sfe[5*SfileadrL];
char **argv= NULL, *pathlist= NULL, *cpt, *npt, *prog= NULL;
pid_t child_pid;
struct stat stbuf;
Xorriso_alloc_meM(prog, char, 5 * SfileadrL);
wait3(NULL,WNOHANG,NULL); /* just to remove any old dead child */
ret= Sfile_make_argv("", cmd, &argc, &argv, 1|4|128);
@ -2005,8 +2033,8 @@ int Xorriso_execv(struct XorrisO *xorriso, char *cmd, char *env_path,
prog[0]= 0;
}
if(prog[0] == 0) {
sprintf(xorriso->info_text, "Cannot find external program %s",
Text_shellsafe(argv[0], sfe, 0));
sprintf(xorriso->info_text, "Cannot find external program ");
Text_shellsafe(argv[0], xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
@ -2019,10 +2047,12 @@ int Xorriso_execv(struct XorrisO *xorriso, char *cmd, char *env_path,
if(child_pid==0) {
/* this is the child process */
sprintf(xorriso->info_text, "Executing external program %s",
Text_shellsafe(prog, sfe, 0));
sprintf(xorriso->info_text, "Executing external program ");
Text_shellsafe(prog, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
Xorriso_destroy(&xorriso, 0); /* reduce memory foot print */
execv(prog, argv); /* should never come back */
fprintf(stderr,"--- execution of shell command failed:\n");
fprintf(stderr," %s\n",cmd);
@ -2062,6 +2092,7 @@ int Xorriso_execv(struct XorrisO *xorriso, char *cmd, char *env_path,
ex:
Sfile_make_argv("", "", &argc, &argv, 2);
Sregex_string(&pathlist, NULL, 0);
Xorriso_free_meM(prog);
return(ret);
}
@ -2071,7 +2102,6 @@ ex:
int Xorriso_path_is_excluded(struct XorrisO *xorriso, char *path, int flag)
{
int ret;
char sfe[5*SfileadrL];
if(!(xorriso->disk_excl_mode&1)) /* exclusion is off */
return(0);
@ -2085,8 +2115,9 @@ int Xorriso_path_is_excluded(struct XorrisO *xorriso, char *path, int flag)
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
}
if(ret>0 && (flag&1)) {
sprintf(xorriso->info_text, "Disk path parameter excluded by %s : %s",
(ret==1 ? "-not_paths" : "-not_leaf"), Text_shellsafe(path, sfe, 0));
sprintf(xorriso->info_text, "Disk path parameter excluded by %s : ",
(ret==1 ? "-not_paths" : "-not_leaf"));
Text_shellsafe(path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
}
return(ret);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2011.05.06.132058"
#define Xorriso_timestamP "2011.05.06.151905"