Hopefully completed -cd alias -cdi

This commit is contained in:
Thomas Schmitt 2007-10-21 15:10:41 +00:00
parent 6a33fc6b52
commit 9ee5534c29
5 changed files with 153 additions and 9 deletions

View File

@ -200,6 +200,8 @@ int Sfile_add_to_path(char path[SfileadrL], char *addon, int flag)
int l; int l;
l= strlen(path); l= strlen(path);
if(l+1>=SfileadrL)
return(0);
if(l==0) { if(l==0) {
strcpy(path,"/"); strcpy(path,"/");
l= 1; l= 1;
@ -3243,8 +3245,8 @@ int Xorriso_option_blank(struct XorrisO *xorriso, char *mode, int flag)
/* Option -cd alias -cdi */ /* Option -cd alias -cdi */
int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag) int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
{ {
char sfe[4*SfileadrL], path[SfileadrL]; char sfe[4*SfileadrL], path[SfileadrL], eff_path[SfileadrL];
int ret, l; int ret;
if (strlen(iso_rr_path)>sizeof(xorriso->wdi)) { if (strlen(iso_rr_path)>sizeof(xorriso->wdi)) {
sprintf(xorriso->info_text,"-cdi: iso_rr_path too long (%d > %d)", sprintf(xorriso->info_text,"-cdi: iso_rr_path too long (%d > %d)",
@ -3256,7 +3258,7 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
Xorriso_info(xorriso,0); Xorriso_info(xorriso,0);
sprintf(xorriso->result_line,"%s/\n",Text_shellsafe(xorriso->wdi, sfe, 0)); sprintf(xorriso->result_line,"%s/\n",Text_shellsafe(xorriso->wdi, sfe, 0));
Xorriso_result(xorriso,0); Xorriso_result(xorriso,0);
if(strcmp(iso_rr_path,"/")==0) { if(strcmp(iso_rr_path,"/")==0 || iso_rr_path[0]==0) {
strcpy(xorriso->wdi,""); strcpy(xorriso->wdi,"");
Xorriso_option_pwdi(xorriso, 0); Xorriso_option_pwdi(xorriso, 0);
return(1); return(1);
@ -3269,7 +3271,11 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
return(-1); return(-1);
} }
ret= 1; #ifdef NIX
int l;
if(Sfile_str(xorriso->wdi,path,0)<=0)
return(-1);
ret= Xorriso_ls(xorriso, 2); /* check existence */ ret= Xorriso_ls(xorriso, 2); /* check existence */
if(ret<=0) { if(ret<=0) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
@ -3278,14 +3284,25 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
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);
} }
if(Sfile_str(xorriso->wdi,path,0)<=0)
return(-1);
l= strlen(xorriso->wdi); l= strlen(xorriso->wdi);
while(l>0) while(l>0)
if(xorriso->wdi[l-1]=='/') if(xorriso->wdi[l-1]=='/')
xorriso->wdi[--l]= 0; xorriso->wdi[--l]= 0;
else else
break; break;
#else
ret= Xorriso_normalize_img_path(xorriso, path, eff_path, 0);
if(ret<=0)
return(ret);
if(ret!=2) {
sprintf(xorriso->info_text, "-cdi: not a directory : %s",
Text_shellsafe(iso_rr_path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
strcpy(xorriso->wdi, eff_path);
#endif
Xorriso_option_pwdi(xorriso, 0); Xorriso_option_pwdi(xorriso, 0);
return(1); return(1);
} }
@ -4296,7 +4313,7 @@ int Xorriso_option_prompt(struct XorrisO *xorriso, char *text, int flag)
/* Option -pwd alias -pwdi */ /* Option -pwd alias -pwdi */
int Xorriso_option_pwdi(struct XorrisO *xorriso, int flag) int Xorriso_option_pwdi(struct XorrisO *xorriso, int flag)
{ {
sprintf(xorriso->info_text,"current working directory:\n"); sprintf(xorriso->info_text,"current working directory in ISO image:\n");
Xorriso_info(xorriso,0); Xorriso_info(xorriso,0);
sprintf(xorriso->result_line,"%s/\n",xorriso->wdi); sprintf(xorriso->result_line,"%s/\n",xorriso->wdi);
Xorriso_result(xorriso,0); Xorriso_result(xorriso,0);

View File

@ -187,6 +187,8 @@ int Sfile_str(char target[SfileadrL], char *source, int flag);
double Sfile_microtime(int flag); double Sfile_microtime(int flag);
int Sfile_add_to_path(char path[SfileadrL], char *addon, int flag);
char *Text_shellsafe(char *in_text, char *out_text, int flag); char *Text_shellsafe(char *in_text, char *out_text, int flag);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.21.124315" #define Xorriso_timestamP "2007.10.21.151124"

View File

@ -428,18 +428,137 @@ int Xorriso_get_volume(struct XorrisO *xorriso, struct iso_volume **volume,
} }
/* @param eff_path returns resulting effective path.
Must provide at least SfileadrL bytes of storage.
@param flag bit0= do not produce problem events (unless internal error)
@return <0 = internal error , 0 = not found ,
1 = found simple node , 2 = found directory
*/
int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
char eff_path[], int flag)
{
int ret, is_dir= 1, done= 0;
struct iso_volume *volume;
struct iso_tree_node_dir *dir= NULL;
struct iso_tree_node *node= NULL;
char path[SfileadrL], *apt, *npt, sfe[4*SfileadrL], *cpt;
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
if(Sfile_str(path, img_path, 0)<=0)
return(-1);
apt= npt= path;
eff_path[0]= 0;
if(path[0]==0)
return(2);
if(path[0]!='/') {
sprintf(xorriso->info_text,
"Unsupported relative addressing in iso_rr_path '%s'", img_path);
if(!(flag&1))
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
return(0);
}
for(npt= apt; !done; apt= npt+1) {
npt= strchr(apt, '/');
if(npt==NULL) {
npt= apt+strlen(apt);
done= 1;
} else
*npt= 0;
if(*apt==0) {
*apt= '/';
apt++;
if(done)
break;
continue;
}
if(strcmp(apt,".")==0)
continue;
if(strcmp(apt,"..")==0) {
node= (struct iso_tree_node *) dir;
if(node==NULL) {
sprintf(xorriso->info_text,
"Relative addressing in path exceeds root directory: %s",
Text_shellsafe(path, sfe, 0));
if(!(flag&1))
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
dir= iso_tree_node_get_parent(node);
/* truncate eff_path */;
cpt= strrchr(eff_path, '/');
if(cpt==NULL) {
sprintf(xorriso->info_text,
"Internal error: less '/' than parent directories in %s",
Text_shellsafe(img_path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
*cpt= 0;
continue;
}
ret= Sfile_add_to_path(eff_path, apt, 0);
if(ret<=0) {
sprintf(xorriso->info_text,
"Effective path in ISO image gets much too long (%d)",
strlen(eff_path)+strlen(apt)+1);
if(!(flag&1))
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
dir= (struct iso_tree_node_dir *) node;
node= iso_tree_volume_path_to_node(volume,eff_path);
if(node==NULL) {
sprintf(xorriso->info_text, "Cannot find in ISO image: %s",
Text_shellsafe(eff_path, sfe, 0));
if(!(flag&1))
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(dir==NULL) /* could be false with "/dir/.." */
dir= iso_tree_node_get_parent(node);
is_dir= LIBISO_ISDIR(node);
}
return(1+!!is_dir);
}
/* @return <=0 = error , 1 = added simple node , 2 = added directory */ /* @return <=0 = error , 1 = added simple node , 2 = added directory */
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path, int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int flag) int flag)
{ {
struct iso_volume *volume; struct iso_volume *volume;
struct iso_tree_radd_dir_behavior behav= {NULL, 0, 0}; struct iso_tree_radd_dir_behavior behav= {NULL, 0, 0};
char path[SfileadrL], *apt, *npt; char path[SfileadrL], *apt, *npt, *cpt;
struct iso_tree_node_dir *dir; struct iso_tree_node_dir *dir;
struct iso_tree_node *node; struct iso_tree_node *node;
int done= 0, is_dir= 0, l, ret; int done= 0, is_dir= 0, l, ret;
struct stat stbuf; struct stat stbuf;
for(cpt= img_path; 1; cpt++) {
if(cpt[0]!='/')
break;
cpt= strstr(cpt,"/.");
if(cpt==NULL)
break;
if(cpt[2]=='.') {
if(cpt[3]=='/' || cpt[3]==0)
break;
} else if(cpt[2]=='/' || cpt[2]==0)
break;
}
if(cpt!=NULL) {
sprintf(xorriso->info_text,
"Unsupported relative addressing in iso_rr_path '%s'", img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
return(0);
}
ret= Xorriso_get_volume(xorriso, &volume, 0); ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0) if(ret<=0)
return(ret); return(ret);

View File

@ -57,6 +57,12 @@ int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag);
/* @param flag bit0= long format , bit1= only check for directory existence */ /* @param flag bit0= long format , bit1= only check for directory existence */
int Xorriso_ls(struct XorrisO *xorriso, int flag); int Xorriso_ls(struct XorrisO *xorriso, int flag);
/* @param flag bit0= do not produce problem events (unless internal error)
@return <0 = internal error , 0 = not found ,
1 = found simple node , 2 = found directory
*/
int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
char eff_path[], int flag);
#endif /* Xorrisoburn_includeD */ #endif /* Xorrisoburn_includeD */