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

This commit is contained in:
Thomas Schmitt 2011-05-04 16:58:16 +00:00
parent 5a07bedc5d
commit 2398b7d599
2 changed files with 84 additions and 61 deletions

View File

@ -59,19 +59,21 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *wd,
IsoImage *volume; IsoImage *volume;
IsoDir *dir= NULL; IsoDir *dir= NULL;
IsoNode *node= NULL; IsoNode *node= NULL;
char path[SfileadrL], *apt, *npt, sfe[5*SfileadrL], *cpt; char *path= NULL, *apt, *npt, *cpt;
Xorriso_alloc_meM(path, char, SfileadrL);
if((flag&64) || !(flag&2)) { if((flag&64) || !(flag&2)) {
ret= Xorriso_get_volume(xorriso, &volume, 0); ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0) if(ret<=0)
return(ret); goto ex;
} }
eff_path[0]= 0; eff_path[0]= 0;
if(img_path[0]==0) { if(img_path[0]==0) {
if(flag&8) if(flag&8)
strcpy(eff_path, "/"); strcpy(eff_path, "/");
return(2); /* root directory */ {ret= 2; goto ex;} /* root directory */
} }
apt= npt= path; apt= npt= path;
@ -82,18 +84,18 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *wd,
goto much_too_long; goto much_too_long;
} else } else
if(Sfile_str(path, img_path, 0)<=0) if(Sfile_str(path, img_path, 0)<=0)
return(-1); {ret= -1; goto ex;}
if(path[0]!='/') { if(path[0]!='/') {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Internal error: Unresolvable relative addressing in iso_rr_path '%s'", "Internal error: Unresolvable relative addressing in iso_rr_path '%s'",
img_path); img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FATAL", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FATAL", 0);
return(-1); {ret= -1; goto ex;}
} else if(path[1]==0) { } else if(path[1]==0) {
if(flag&8) if(flag&8)
strcpy(eff_path, "/"); strcpy(eff_path, "/");
return(2); /* root directory */ {ret= 2; goto ex;} /* root directory */
} }
for(npt= apt; !done; apt= npt+1) { for(npt= apt; !done; apt= npt+1) {
@ -120,10 +122,10 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *wd,
if(node==NULL) { if(node==NULL) {
bonked_root:; bonked_root:;
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Relative addressing in path exceeds root directory: %s", "Relative addressing in path exceeds root directory: ");
Text_shellsafe(img_path, sfe, 0)); Text_shellsafe(img_path, 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(-1); {ret= -1; goto ex;}
} }
dir= iso_node_get_parent(node); dir= iso_node_get_parent(node);
} }
@ -141,13 +143,13 @@ much_too_long:;
sprintf(xorriso->info_text, "Effective path gets much too long (%d)", sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
(int) (strlen(eff_path)+strlen(apt)+1)); (int) (strlen(eff_path)+strlen(apt)+1));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(-1); {ret= -1; goto ex;}
} }
if(!(flag&2)) { if(!(flag&2)) {
dir= (IsoDir *) node; dir= (IsoDir *) node;
ret= Xorriso_node_from_path(xorriso, volume, eff_path, &node, flag&1); ret= Xorriso_node_from_path(xorriso, volume, eff_path, &node, flag&1);
if(ret<=0) if(ret<=0)
return(0); {ret= 0; goto ex;}
if(dir==NULL) /* could be false with "/dir/.." */ if(dir==NULL) /* could be false with "/dir/.." */
dir= iso_node_get_parent(node); dir= iso_node_get_parent(node);
is_dir= LIBISO_ISDIR(node); is_dir= LIBISO_ISDIR(node);
@ -158,11 +160,14 @@ much_too_long:;
1|(4*(xorriso->do_follow_links || (xorriso->do_follow_param && !(flag&32))) 1|(4*(xorriso->do_follow_links || (xorriso->do_follow_param && !(flag&32)))
)); ));
if(ret<0) if(ret<0)
return(0); {ret= 0; goto ex;}
if(ret==2) if(ret==2)
is_dir= 1; is_dir= 1;
} }
return(1+!!is_dir); ret= 1+!!is_dir;
ex:;
Xorriso_free_meM(path);
return(ret);
} }
@ -171,21 +176,26 @@ int Xorriso_get_node_by_path(struct XorrisO *xorriso,
IsoNode **node, int flag) IsoNode **node, int flag)
{ {
int ret; int ret;
char path[SfileadrL]; char *path= NULL;
IsoImage *volume; IsoImage *volume;
Xorriso_alloc_meM(path, char, SfileadrL);
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, in_path, path, 0); ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, in_path, path, 0);
if(ret<=0) if(ret<=0)
return(ret); goto ex;
if(eff_path!=NULL) if(eff_path!=NULL)
strcpy(eff_path, path); strcpy(eff_path, path);
ret= Xorriso_get_volume(xorriso, &volume, 0); ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0) if(ret<=0)
return(ret); goto ex;
ret= Xorriso_node_from_path(xorriso, volume, path, node, 0); ret= Xorriso_node_from_path(xorriso, volume, path, node, 0);
if(ret<=0) if(ret<=0)
return(0); {ret= 0; goto ex;}
return(1); ret= 1;
ex:;
Xorriso_free_meM(path);
return(ret);
} }
@ -1345,17 +1355,19 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd,
int i, ret, was_error= 0, dfilec= 0, pass, passes, hidden_state= 0; int i, ret, was_error= 0, dfilec= 0, pass, passes, hidden_state= 0;
IsoNode *node; IsoNode *node;
IsoImage *volume; IsoImage *volume;
char sfe[5*SfileadrL], sfe2[5*SfileadrL], path[SfileadrL]; char *path= NULL, *link_target= NULL, *rpt, **dfilev= NULL;
char link_target[SfileadrL], *rpt, **dfilev= NULL;
char *a_text= NULL, *d_text= NULL; char *a_text= NULL, *d_text= NULL;
off_t size; off_t size;
struct stat stbuf; struct stat stbuf;
Xorriso_alloc_meM(path, char, SfileadrL);
Xorriso_alloc_meM(link_target, char, SfileadrL);
rpt= xorriso->result_line; rpt= xorriso->result_line;
ret= Xorriso_get_volume(xorriso, &volume, 0); ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0) if(ret<=0)
return(ret); goto ex;
Sort_argv(filec, filev, 0); Sort_argv(filec, filev, 0);
@ -1368,8 +1380,8 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd,
} }
ret= Xorriso_node_from_path(xorriso, volume, path, &node, 1); ret= Xorriso_node_from_path(xorriso, volume, path, &node, 1);
if(ret<=0) { if(ret<=0) {
sprintf(xorriso->info_text, "Not found in ISO image: %s", sprintf(xorriso->info_text, "Not found in ISO image: ");
Text_shellsafe(path, sfe, 0)); Text_shellsafe(path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
was_error++; was_error++;
continue; continue;
@ -1380,7 +1392,7 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd,
sprintf(xorriso->info_text, "Valid ISO nodes found: %d\n", filec-was_error); sprintf(xorriso->info_text, "Valid ISO nodes found: %d\n", filec-was_error);
Xorriso_info(xorriso,1); Xorriso_info(xorriso,1);
if(filec-was_error<=0) if(filec-was_error<=0)
return(!was_error); {ret= !was_error; goto ex;}
} }
passes= 1+!(flag&(4|8)); passes= 1+!(flag&(4|8));
@ -1399,7 +1411,8 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd,
if(filec>1) { if(filec>1) {
strcpy(xorriso->result_line, "\n"); strcpy(xorriso->result_line, "\n");
Xorriso_result(xorriso,0); Xorriso_result(xorriso,0);
sprintf(xorriso->result_line, "%s:\n", Text_shellsafe(filev[i], sfe,0)); Text_shellsafe(filev[i], xorriso->result_line, 0);
strcat(xorriso->result_line, ":\n");
Xorriso_result(xorriso,0); Xorriso_result(xorriso,0);
} }
ret= Xorriso_sorted_dir_i(xorriso, ret= Xorriso_sorted_dir_i(xorriso,
@ -1443,22 +1456,27 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd,
ret= Xorriso_show_du_subs(xorriso, (IsoDir *) node, ret= Xorriso_show_du_subs(xorriso, (IsoDir *) node,
path, filev[i], &size, boss_mem, flag&1); path, filev[i], &size, boss_mem, flag&1);
if(ret<0) if(ret<0)
return(-1); {ret= -1; goto ex;}
if(ret==0) if(ret==0)
continue; continue;
} }
sprintf(rpt, "%7.f ",(double) (size/1024)); sprintf(rpt, "%7.f ",(double) (size/1024));
} }
if(link_target[0] && (flag&5)==1) if(link_target[0] && (flag&5)==1) {
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s -> %s\n", Text_shellsafe(filev[i], xorriso->result_line, 1),
Text_shellsafe(filev[i], sfe, 0), strcat(xorriso->result_line, " -> ");
Text_shellsafe(link_target, sfe2, 0)); Text_shellsafe(link_target, xorriso->result_line, 1);
else } else {
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n", Text_shellsafe(filev[i], xorriso->result_line, 1);
Text_shellsafe(filev[i], sfe, 0)); }
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso, 0); Xorriso_result(xorriso, 0);
} }
return(!was_error); ret= !was_error;
ex:;
Xorriso_free_meM(path);
Xorriso_free_meM(link_target);
return(ret);
} }
@ -1476,9 +1494,11 @@ int Xorriso_ls(struct XorrisO *xorriso, int flag)
IsoNode *node, **node_array= NULL; IsoNode *node, **node_array= NULL;
IsoDir *dir_node; IsoDir *dir_node;
IsoDirIter *iter= NULL; IsoDirIter *iter= NULL;
char sfe[5*SfileadrL], sfe2[5*SfileadrL], link_target[SfileadrL], *npt, *rpt; char *link_target= NULL, *npt, *rpt;
struct stat stbuf; struct stat stbuf;
Xorriso_alloc_meM(link_target, char, SfileadrL);
rpt= xorriso->result_line; rpt= xorriso->result_line;
ret= Xorriso_dir_from_path(xorriso, "Working directory", xorriso->wdi, ret= Xorriso_dir_from_path(xorriso, "Working directory", xorriso->wdi,
@ -1552,13 +1572,14 @@ cannot_create_iter:;
if(ret<=0) if(ret<=0)
continue; continue;
} }
if(link_target[0] && (flag&1)) if(link_target[0] && (flag&1)) {
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s -> %s\n", Text_shellsafe(npt, xorriso->result_line, 1);
Text_shellsafe(npt, sfe, 0), strcat(xorriso->result_line, " -> ");
Text_shellsafe(link_target, sfe2, 0)); Text_shellsafe(link_target, xorriso->result_line, 1);
else } else {
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n", Text_shellsafe(npt, xorriso->result_line, 1);
Text_shellsafe(npt, sfe, 0)); }
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso, 0); Xorriso_result(xorriso, 0);
} }
@ -1569,6 +1590,7 @@ ex:;
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
if(node_array!=NULL) if(node_array!=NULL)
free((char *) node_array); free((char *) node_array);
Xorriso_free_meM(link_target);
return(ret); return(ret);
} }
@ -1658,7 +1680,6 @@ int Xorriso_expand_pattern(struct XorrisO *xorriso,
{ {
int ret, count= 0, abs_adr= 0, i, was_count, was_filec; int ret, count= 0, abs_adr= 0, i, was_count, was_filec;
int nonconst_mismatches= 0, dive_count= 0; int nonconst_mismatches= 0, dive_count= 0;
char sfe[5*SfileadrL];
IsoImage *volume; IsoImage *volume;
IsoDir *dir= NULL, *root_dir; IsoDir *dir= NULL, *root_dir;
IsoNode *iso_node; IsoNode *iso_node;
@ -1699,9 +1720,10 @@ int Xorriso_expand_pattern(struct XorrisO *xorriso,
dir= (IsoDir *) iso_node; dir= (IsoDir *) iso_node;
if(ret<=0) { if(ret<=0) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text, sprintf(xorriso->info_text, "While expanding pattern ");
"While expanding pattern %s : Working directory does not exist in ISO image", Text_shellsafe(patterns[i], xorriso->info_text, 1);
Text_shellsafe(patterns[i], sfe, 0)); strcat(xorriso->info_text,
" : Working directory does not exist in ISO image");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex; ret= 0; goto ex;
} }
@ -2002,7 +2024,6 @@ int Xorriso_report_lba(struct XorrisO *xorriso, char *show_path,
{ {
int ret, *start_lbas= NULL, *end_lbas= NULL, lba_count, i; int ret, *start_lbas= NULL, *end_lbas= NULL, lba_count, i;
off_t size; off_t size;
char sfe[5*SfileadrL];
ret= Xorriso__start_end_lbas(node, &lba_count, &start_lbas, &end_lbas, ret= Xorriso__start_end_lbas(node, &lba_count, &start_lbas, &end_lbas,
&size, 0); &size, 0);
@ -2014,9 +2035,10 @@ int Xorriso_report_lba(struct XorrisO *xorriso, char *show_path,
{ret= 1; goto ex;} /* it is ok to ignore other types */ {ret= 1; goto ex;} /* it is ok to ignore other types */
for(i= 0; i < lba_count; i++) { for(i= 0; i < lba_count; i++) {
sprintf(xorriso->result_line, sprintf(xorriso->result_line,
"File data lba: %2d , %8d , %8d , %8.f , %s\n", "File data lba: %2d , %8d , %8d , %8.f , ",
i, start_lbas[i], end_lbas[i] + 1 - start_lbas[i], (double) size, i, start_lbas[i], end_lbas[i] + 1 - start_lbas[i], (double) size);
Text_shellsafe(show_path, sfe, 0)); Text_shellsafe(show_path, xorriso->result_line, 1);
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso, 0); Xorriso_result(xorriso, 0);
} }
ret= 1; ret= 1;
@ -2034,7 +2056,6 @@ int Xorriso_report_damage(struct XorrisO *xorriso, char *show_path,
{ {
int ret; int ret;
off_t size= 0, damage_start, damage_end; off_t size= 0, damage_start, damage_end;
char sfe[5*SfileadrL];
ret= Xorriso_file_eval_damage(xorriso, node, &damage_start, &damage_end, 0); ret= Xorriso_file_eval_damage(xorriso, node, &damage_start, &damage_end, 0);
if(ret < 0) if(ret < 0)
@ -2043,15 +2064,16 @@ int Xorriso_report_damage(struct XorrisO *xorriso, char *show_path,
if(LIBISO_ISREG(node)) if(LIBISO_ISREG(node))
size= iso_file_get_size((IsoFile *) node); size= iso_file_get_size((IsoFile *) node);
if(ret > 0) { if(ret > 0) {
sprintf(xorriso->result_line, "File damaged : %8.f , %8.f , %8.f , %s\n", sprintf(xorriso->result_line, "File damaged : %8.f , %8.f , %8.f , ",
(double) damage_start, (double) (damage_end - damage_start) , (double) damage_start, (double) (damage_end - damage_start) ,
(double) size, Text_shellsafe(show_path, sfe, 0)); (double) size);
Xorriso_result(xorriso, 0);
} else { } else {
sprintf(xorriso->result_line, "File seems ok: %8.f , %8.f , %8.f , %s\n", sprintf(xorriso->result_line, "File seems ok: %8.f , %8.f , %8.f , ",
-1.0, -1.0, (double) size, Text_shellsafe(show_path, sfe, 0)); -1.0, -1.0, (double) size);
Xorriso_result(xorriso, 0);
} }
Text_shellsafe(show_path, xorriso->result_line, 1);
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso, 0);
return(1); return(1);
} }
@ -2111,7 +2133,7 @@ int Xorriso_node_from_path(struct XorrisO *xorriso, IsoImage *volume,
char *path, IsoNode **node, int flag) char *path, IsoNode **node, int flag)
{ {
int ret; int ret;
char sfe[5*SfileadrL], *path_pt; char *path_pt;
path_pt= path; path_pt= path;
if(path[0]==0) if(path[0]==0)
@ -2126,8 +2148,9 @@ int Xorriso_node_from_path(struct XorrisO *xorriso, IsoImage *volume,
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
if(ret<=0 || (*node)==NULL) { if(ret<=0 || (*node)==NULL) {
if(!(flag&1)) { if(!(flag&1)) {
sprintf(xorriso->info_text, "Cannot find path %s in loaded ISO image", sprintf(xorriso->info_text, "Cannot find path ");
Text_shellsafe(path_pt, sfe, 0)); Text_shellsafe(path_pt, xorriso->info_text, 1);
strcat(xorriso->info_text, " in loaded ISO image");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
} }
return(0); return(0);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2011.05.04.152314" #define Xorriso_timestamP "2011.05.04.165840"