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

This commit is contained in:
Thomas Schmitt 2011-05-05 16:38:12 +00:00
parent 5b1ee6d286
commit 7b32a53903
2 changed files with 97 additions and 53 deletions

View File

@ -402,7 +402,10 @@ int Xorriso_option_map(struct XorrisO *xorriso, char *disk_path,
char *iso_path, int flag) char *iso_path, int flag)
{ {
int ret; int ret;
char eff_origin[SfileadrL], eff_dest[SfileadrL], *ipth; char *eff_origin= NULL, *eff_dest= NULL, *ipth;
Xorriso_alloc_meM(eff_origin, char, SfileadrL);
Xorriso_alloc_meM(eff_dest, char, SfileadrL);
if(!(flag&2)) if(!(flag&2))
Xorriso_pacifier_reset(xorriso, 0); Xorriso_pacifier_reset(xorriso, 0);
@ -413,22 +416,22 @@ int Xorriso_option_map(struct XorrisO *xorriso, char *disk_path,
if(disk_path[0]==0) { if(disk_path[0]==0) {
sprintf(xorriso->info_text, "-map: Empty disk_path given"); sprintf(xorriso->info_text, "-map: Empty disk_path given");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 1); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 1);
return(0); {ret= 0; goto ex;}
} }
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_origin, ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_origin,
2|4); 2|4);
if(ret<=0) if(ret<=0)
return(ret); goto ex;
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, ipth, eff_dest, 2); ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, ipth, eff_dest, 2);
if(ret<=0) if(ret<=0)
return(ret); goto ex;
ret= Xorriso_graft_in(xorriso, NULL, eff_origin, eff_dest, ret= Xorriso_graft_in(xorriso, NULL, eff_origin, eff_dest,
(off_t) 0, (off_t) 0, 2|(flag&32)); (off_t) 0, (off_t) 0, 2|(flag&32));
if(!(flag&2)) if(!(flag&2))
Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count, Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
xorriso->pacifier_total, "", 1); xorriso->pacifier_total, "", 1);
if(ret<=0) if(ret<=0)
return(ret); goto ex;
if(!(flag&1)) { if(!(flag&1)) {
sprintf(xorriso->info_text, "Added to ISO image: %s '%s'='%s'\n", sprintf(xorriso->info_text, "Added to ISO image: %s '%s'='%s'\n",
@ -436,7 +439,11 @@ int Xorriso_option_map(struct XorrisO *xorriso, char *disk_path,
eff_origin); eff_origin);
Xorriso_info(xorriso,0); Xorriso_info(xorriso,0);
} }
return(1); ret= 1;
ex:;
Xorriso_free_meM(eff_origin);
Xorriso_free_meM(eff_dest);
return(ret);
} }
@ -453,15 +460,20 @@ int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
{ {
int ret, end_idx, optc= 0, was_failure= 1, i, fret, mode, problem_count; int ret, end_idx, optc= 0, was_failure= 1, i, fret, mode, problem_count;
int ns_flag= 2|4, nt_flag= 2, opt_args_flag= 2, made_di_array= 0; int ns_flag= 2|4, nt_flag= 2, opt_args_flag= 2, made_di_array= 0;
char source_prefix[SfileadrL], target_prefix[SfileadrL], *cmd, **optv= NULL; char *source_prefix= NULL, *target_prefix= NULL, *cmd, **optv= NULL;
char eff_source[SfileadrL], eff_target[SfileadrL], *source_pt, *s_wd, *t_wd; char *eff_source= NULL, *eff_target= NULL, *source_pt, *s_wd, *t_wd;
char sfe[5*SfileadrL], **eff_src_array= NULL, **eff_tgt_array= NULL; char **eff_src_array= NULL, **eff_tgt_array= NULL;
cmd= "-map_l"; cmd= "-map_l";
s_wd= xorriso->wdx; s_wd= xorriso->wdx;
t_wd= xorriso->wdi; t_wd= xorriso->wdi;
Xorriso_pacifier_reset(xorriso, 0); Xorriso_pacifier_reset(xorriso, 0);
mode= (flag>>8) & 15; mode= (flag>>8) & 15;
Xorriso_alloc_meM(source_prefix, char, SfileadrL);
Xorriso_alloc_meM(target_prefix, char, SfileadrL);
Xorriso_alloc_meM(eff_source, char, SfileadrL);
Xorriso_alloc_meM(eff_target, char, SfileadrL);
if(mode==1) if(mode==1)
cmd= "-compare_l"; cmd= "-compare_l";
@ -526,11 +538,10 @@ int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
source_pt= eff_source; source_pt= eff_source;
if(source_prefix[0]) { if(source_prefix[0]) {
if(strncmp(source_prefix, eff_source, strlen(source_prefix))!=0) { if(strncmp(source_prefix, eff_source, strlen(source_prefix))!=0) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text, "%s: disk_path ", cmd);
"%s: disk_path %s does not begin with disk_prefix ", cmd, Text_shellsafe(eff_source, xorriso->info_text, 1);
Text_shellsafe(eff_source, sfe, 0)); strcat(xorriso->info_text, " does not begin with disk_prefix ");
Text_shellsafe(source_prefix, Text_shellsafe(source_prefix, xorriso->info_text, 1);
xorriso->info_text+strlen(xorriso->info_text), 0);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 1); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 1);
ret= 0; goto ex; ret= 0; goto ex;
} }
@ -596,6 +607,10 @@ ex:;
Sfile_destroy_argv(&i, &eff_src_array, 0); Sfile_destroy_argv(&i, &eff_src_array, 0);
i= optc; i= optc;
Sfile_destroy_argv(&i, &eff_tgt_array, 0); Sfile_destroy_argv(&i, &eff_tgt_array, 0);
Xorriso_free_meM(source_prefix);
Xorriso_free_meM(target_prefix);
Xorriso_free_meM(eff_source);
Xorriso_free_meM(eff_target);
(*idx)= end_idx; (*idx)= end_idx;
Xorriso_opt_args(xorriso, cmd, argc, argv, *idx, &end_idx, &optc, &optv, 256); Xorriso_opt_args(xorriso, cmd, argc, argv, *idx, &end_idx, &optc, &optv, 256);
if(ret<=0) if(ret<=0)
@ -766,12 +781,16 @@ int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag) int *idx, int flag)
{ {
int i, end_idx_dummy, ret, is_dir= 0, was_failure= 0, fret; int i, end_idx_dummy, ret, is_dir= 0, was_failure= 0, fret;
char sfe[5*SfileadrL], sfe2[5*SfileadrL]; char *eff_origin= NULL, *eff_dest= NULL, *dest_dir= NULL;
char eff_origin[SfileadrL], eff_dest[SfileadrL], dest_dir[SfileadrL]; char *leafname= NULL;
char leafname[SfileadrL];
int optc= 0; int optc= 0;
char **optv= NULL; char **optv= NULL;
Xorriso_alloc_meM(eff_origin, char, SfileadrL);
Xorriso_alloc_meM(eff_dest, char, SfileadrL);
Xorriso_alloc_meM(dest_dir, char, SfileadrL);
Xorriso_alloc_meM(leafname, char, SfileadrL);
ret= Xorriso_cpmv_args(xorriso, "-mvi", argc, argv, idx, ret= Xorriso_cpmv_args(xorriso, "-mvi", argc, argv, idx,
&optc, &optv, eff_dest, 0); &optc, &optv, eff_dest, 0);
if(ret<=0) if(ret<=0)
@ -801,8 +820,11 @@ int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
ret= Xorriso_rename(xorriso, NULL, eff_origin, eff_dest, 0); ret= Xorriso_rename(xorriso, NULL, eff_origin, eff_dest, 0);
if(ret<=0 || xorriso->request_to_abort) if(ret<=0 || xorriso->request_to_abort)
goto problem_handler; goto problem_handler;
sprintf(xorriso->info_text, "Renamed in ISO image: %s to %s\n", sprintf(xorriso->info_text, "Renamed in ISO image: ");
Text_shellsafe(eff_origin,sfe,0),Text_shellsafe(eff_dest,sfe2,0)); Text_shellsafe(eff_origin, xorriso->info_text, 1);
strcat(xorriso->info_text, " to ");
Text_shellsafe(eff_dest, xorriso->info_text, 1);
strcat(xorriso->info_text, "\n");
Xorriso_info(xorriso, 0); Xorriso_info(xorriso, 0);
continue; /* regular bottom of loop */ continue; /* regular bottom of loop */
@ -815,6 +837,10 @@ problem_handler:;
} }
ret= !was_failure; ret= !was_failure;
ex:; ex:;
Xorriso_free_meM(eff_origin);
Xorriso_free_meM(eff_dest);
Xorriso_free_meM(dest_dir);
Xorriso_free_meM(leafname);
Xorriso_opt_args(xorriso, "-mvi", Xorriso_opt_args(xorriso, "-mvi",
argc, argv, *idx, &end_idx_dummy, &optc, &optv, 256); argc, argv, *idx, &end_idx_dummy, &optc, &optv, 256);
return(ret); return(ret);
@ -836,9 +862,11 @@ int Xorriso_option_no_rc(struct XorrisO *xorriso, int flag)
int Xorriso_option_not_leaf(struct XorrisO *xorriso, char *pattern, int flag) int Xorriso_option_not_leaf(struct XorrisO *xorriso, char *pattern, int flag)
{ {
regex_t re; regex_t re;
char regexpr[2*SfileadrL+2], sfe[5*SfileadrL]; char *regexpr= NULL;
int ret= 0; int ret= 0;
Xorriso_alloc_meM(regexpr, char, 2 * SfileadrL + 2);
if(pattern[0]==0) if(pattern[0]==0)
{ret= 0; goto cannot_add;} {ret= 0; goto cannot_add;}
Xorriso__bourne_to_reg(pattern, regexpr, 0); Xorriso__bourne_to_reg(pattern, regexpr, 0);
@ -860,13 +888,16 @@ int Xorriso_option_not_leaf(struct XorrisO *xorriso, char *pattern, int flag)
} }
if(ret<=0) { if(ret<=0) {
cannot_add:; cannot_add:;
sprintf(xorriso->info_text,"Cannot add pattern: %s %s", sprintf(xorriso->info_text,"Cannot add pattern: %s ",
(flag & 3) ? "-hide_disk_leaf" : "-not_leaf", (flag & 3) ? "-hide_disk_leaf" : "-not_leaf");
Text_shellsafe(pattern, sfe, 0)); Text_shellsafe(pattern, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(ret); goto ex;
} }
return(1); ret= 1;
ex:;
Xorriso_free_meM(regexpr);
return(ret);
} }
@ -876,7 +907,7 @@ int Xorriso_option_not_list(struct XorrisO *xorriso, char *adr, int flag)
{ {
int ret, linecount= 0, insertcount= 0, null= 0, argc= 0, i; int ret, linecount= 0, insertcount= 0, null= 0, argc= 0, i;
FILE *fp= NULL; FILE *fp= NULL;
char sfe[5*SfileadrL], **argv= NULL; char **argv= NULL;
Xorriso_pacifier_reset(xorriso, 0); Xorriso_pacifier_reset(xorriso, 0);
if(adr[0]==0) { if(adr[0]==0) {
@ -914,12 +945,16 @@ ex:;
fclose(fp); fclose(fp);
Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv, 2); Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv, 2);
if(ret<=0) { if(ret<=0) {
sprintf(xorriso->info_text, "Aborted reading of file %s in line number %d", sprintf(xorriso->info_text, "Aborted reading of file ");
Text_shellsafe(adr, sfe, 0), linecount); Text_shellsafe(adr, xorriso->info_text, 1);
sprintf(xorriso->info_text + strlen(xorriso->info_text),
" in line number %d", linecount);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
} }
sprintf(xorriso->info_text, "Added %d exclusion list items from file %s\n", sprintf(xorriso->info_text, "Added %d exclusion list items from file ",
insertcount, Text_shellsafe(adr, sfe, 0)); insertcount);
Text_shellsafe(adr, xorriso->info_text, 1);
strcat(xorriso->info_text, "\n");
Xorriso_info(xorriso,0); Xorriso_info(xorriso,0);
return(ret); return(ret);
} }
@ -929,14 +964,16 @@ ex:;
int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag) int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag)
{ {
int ret; int ret;
char what_data[SfileadrL], *what, *what_next; char *what_data= NULL, *what, *what_next;
Xorriso_alloc_meM(what_data, char, SfileadrL);
if(Sfile_str(what_data, setting, 0)<=0) { if(Sfile_str(what_data, setting, 0)<=0) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"-not_mgt: setting string is much too long (%d)", "-not_mgt: setting string is much too long (%d)",
(int) strlen(setting)); (int) strlen(setting));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0); {ret= 0; goto ex;}
} }
for(what= what_data; what!=NULL; what= what_next) { for(what= what_data; what!=NULL; what= what_next) {
what_next= strchr(what, ':'); what_next= strchr(what, ':');
@ -952,7 +989,7 @@ int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag)
ret= Exclusions_new(&(xorriso->disk_exclusions), 0); ret= Exclusions_new(&(xorriso->disk_exclusions), 0);
if(ret<=0) { if(ret<=0) {
Xorriso_no_malloc_memory(xorriso, NULL, 0); Xorriso_no_malloc_memory(xorriso, NULL, 0);
return(ret); goto ex;
} }
} else if(strcmp(what, "on")==0) { } else if(strcmp(what, "on")==0) {
xorriso->disk_excl_mode|= 1; xorriso->disk_excl_mode|= 1;
@ -973,10 +1010,13 @@ int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag)
} else { } else {
sprintf(xorriso->info_text, "-not_mgt: unknown setting '%s'", what); sprintf(xorriso->info_text, "-not_mgt: unknown setting '%s'", what);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0); {ret= 0; goto ex;}
} }
} }
return(1); ret= 1;
ex:;
Xorriso_free_meM(what_data);
return(ret);
} }
@ -989,19 +1029,20 @@ int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag)
int Xorriso_option_not_paths(struct XorrisO *xorriso, int argc, char **argv, int Xorriso_option_not_paths(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag) int *idx, int flag)
{ {
int ret, end_idx, num_descr, dummy, optc= 0, i; int ret, end_idx, num_descr= 0, dummy, optc= 0, i;
char **descr= NULL, **optv= NULL, sfe[5*SfileadrL], eff_path[SfileadrL]; char **descr= NULL, **optv= NULL, *eff_path= NULL;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx,
(xorriso->do_disk_pattern == 1 || (flag & 4)) | 2); (xorriso->do_disk_pattern == 1 || (flag & 4)) | 2);
if(end_idx<=0) if(end_idx<=0)
return(end_idx); {ret= end_idx; goto ex;}
num_descr= end_idx - *idx; num_descr= end_idx - *idx;
if(num_descr<=0) if(num_descr<=0)
{ret= 1; goto ex;} {ret= 1; goto ex;}
/* produce absolute patterns */ /* produce absolute patterns */
Xorriso_alloc_meM(eff_path, char, SfileadrL);
descr= TSOB_FELD(char *, num_descr); descr= TSOB_FELD(char *, num_descr);
if(descr==NULL) { if(descr==NULL) {
no_memory:; no_memory:;
@ -1032,10 +1073,11 @@ no_memory:;
if(ret<=0) { if(ret<=0) {
no_hide:; no_hide:;
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Cannot add path list: -hide_disk_paths %s %s%s %s", "Cannot add path list: -hide_disk_paths %s ",
Xorriso__hide_mode_text(flag & 3, 0), Xorriso__hide_mode_text(flag & 3, 0));
Text_shellsafe(argv[*idx], sfe, 0), (num_descr>1 ? " ..." : ""), Text_shellsafe(argv[*idx], xorriso->info_text, 1);
xorriso->list_delimiter); strcat(xorriso->info_text, num_descr > 1 ? " ... " : " ");
strcat(xorriso->info_text, xorriso->list_delimiter);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
goto ex; goto ex;
} }
@ -1050,9 +1092,10 @@ no_hide:;
ret= Exclusions_add_not_paths(xorriso->disk_exclusions, ret= Exclusions_add_not_paths(xorriso->disk_exclusions,
num_descr, descr, optc, optv, 0); num_descr, descr, optc, optv, 0);
if(ret<=0) { if(ret<=0) {
sprintf(xorriso->info_text,"Cannot add path list: -not_paths %s%s %s", sprintf(xorriso->info_text,"Cannot add path list: -not_paths ");
Text_shellsafe(argv[*idx], sfe, 0), (num_descr>1 ? " ..." : ""), Text_shellsafe(argv[*idx], xorriso->info_text, 1);
xorriso->list_delimiter); strcat(xorriso->info_text, num_descr > 1 ? " ... " : " ");
strcat(xorriso->info_text, xorriso->list_delimiter);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
} }
} }
@ -1067,6 +1110,7 @@ ex:;
free((char *) descr); free((char *) descr);
descr= NULL; descr= NULL;
} }
Xorriso_free_meM(eff_path);
return(ret); return(ret);
} }
@ -1085,7 +1129,6 @@ return:
{ {
int ret,linecount= 0, argc= 0, was_failure= 0, fret; int ret,linecount= 0, argc= 0, was_failure= 0, fret;
FILE *fp= NULL; FILE *fp= NULL;
char shellsafe[5*SfileadrL];
char **argv= NULL; char **argv= NULL;
int linec= 0; int linec= 0;
char *line= NULL, **linev= NULL; char *line= NULL, **linev= NULL;
@ -1095,10 +1138,10 @@ return:
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0); return(0);
} }
Text_shellsafe(adr,shellsafe,0);
if(xorriso->is_dialog) { if(xorriso->is_dialog) {
sprintf(xorriso->info_text,"+ performing command lines from file %s :\n", sprintf(xorriso->info_text,"+ performing command lines from file ");
shellsafe); Text_shellsafe(adr, xorriso->info_text, 1);
strcat(xorriso->info_text, " :\n");
Xorriso_info(xorriso,1); Xorriso_info(xorriso,1);
} }
ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0); ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
@ -1153,8 +1196,9 @@ ex:;
fclose(fp); fclose(fp);
if(ret<=0) { if(ret<=0) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"error triggered by line %d of file:\n %s\n", "error triggered by line %d of file:\n ", linecount);
linecount,shellsafe); Text_shellsafe(adr, xorriso->info_text, 1);
strcat(xorriso->info_text, "\n");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 1); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 1);
} }
if(ret!=1) if(ret!=1)

View File

@ -1 +1 @@
#define Xorriso_timestamP "2011.05.05.122855" #define Xorriso_timestamP "2011.05.05.163832"