Implemented -speed and enlarged -status list

This commit is contained in:
Thomas Schmitt 2007-10-13 14:11:20 +00:00
parent bac1d89199
commit a16ed65863
2 changed files with 200 additions and 25 deletions

View File

@ -2,9 +2,16 @@
/*
( cd .. ; libisoburn-develop/test/compile_xorriso.sh -g )
or
cc -g -DXorriso_with_maiN -DXorriso_with_regeX -DXorriso_with_readlinE \
-Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
-o test/xorriso test/xorriso.c -lreadline
-o test/xorriso test/xorriso.c \
-lpthread -lreadline -lburn -lisofs -lisoburn
*/
/* Command line oriented batch and dialog tool which creates, loads,
@ -640,7 +647,7 @@ bit15= with bit1 or bit2: close depicted log file
char *rpt,*npt,ret= 1;
char prefix[16];
static int num_channels= 4;
static char channel_prefixes[4][4]= {"-","R","I","M"};
static char channel_prefixes[4][4]= {".","R","I","M"};
static FILE *logfile_fp[4]= {NULL,NULL,NULL,NULL};
static FILE *pktlog_fp= NULL;
@ -994,6 +1001,38 @@ FILE *Afile_fopen(char *filename, char *mode, int flag)
}
/** Convert a text into a number of type double and multiply it by unit code
[kmgtpe] (2^10 to 2^60) or [s] (2048). (Also accepts capital letters.)
@param text Input like "42", "2k", "3.14m" or "-1g"
@param flag Bitfield for control purposes:
bit0= return -1 rathern than 0 on failure
@return The derived double value
*/
double Scanf_io_size(char *text, int flag)
/*
bit0= default value -1 rather than 0
*/
{
int c;
double ret= 0.0;
if(flag&1)
ret= -1.0;
if(text[0]==0)
return(ret);
sscanf(text,"%lf",&ret);
c= text[strlen(text)-1];
if(c=='k' || c=='K') ret*= 1024.0;
if(c=='m' || c=='M') ret*= 1024.0*1024.0;
if(c=='g' || c=='G') ret*= 1024.0*1024.0*1024.0;
if(c=='t' || c=='T') ret*= 1024.0*1024.0*1024.0*1024.0;
if(c=='p' || c=='P') ret*= 1024.0*1024.0*1024.0*1024.0*1024.0;
if(c=='e' || c=='E') ret*= 1024.0*1024.0*1024.0*1024.0*1024.0*1024.0;
if(c=='s' || c=='S') ret*= 2048.0;
return(ret);
}
/* ------------------------------------------------------------------------ */
@ -1672,7 +1711,7 @@ struct XorrisO { /* the global context of askme */
int ban_stdio_write;
int do_dummy;
int do_close;
int speed; /* in libburn units : 1000 bytes/second , 0 = Max, -1 = Min */
/* XORRISO options */
int allow_graft_points;
@ -1702,6 +1741,7 @@ struct XorrisO { /* the global context of askme */
int result_page_width;
char mark_text[SfileadrL]; /* ( stdout+stderr, M: ) */
int packet_output;
char logfile[4][SfileadrL];
int status_history_max; /* for -status long_history */
@ -1757,7 +1797,7 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag);
int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
{
int ret;
int ret, i;
struct XorrisO *m;
*xorriso= m= TSOB_FELD(struct XorrisO,1);
@ -1774,7 +1814,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->global_uid= 0;
m->volid[0]= 0;
m->do_global_gid= 0;
m->do_overwrite= 0;
m->do_overwrite= 1;
m->do_reassure= 0;
m->global_gid= 0;
m->indev[0]= 0;
@ -1782,6 +1822,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->ban_stdio_write= 0;
m->do_dummy= 0;
m->do_close= 0;
m->speed= 0;
m->allow_graft_points= 0;
m->dialog= 0;
m->search_mode= 0;
@ -1791,6 +1832,8 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->result_page_width= 80;
m->mark_text[0]= 0;
m->packet_output= 0;
for(i=0; i<4; i++)
m->logfile[i][0]= 0;
m->status_history_max= Xorriso_status_history_maX;
#ifdef Xorriso_with_regeX
m->re= NULL;
@ -2719,8 +2762,9 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
-options_from_file:${resume_state_file}_pos
*/
{
int is_default,no_defaults;
int is_default,no_defaults,i;
char *line, sfe[4*SfileadrL];
static char channel_prefixes[4][4]= {".","R","I","M"};
no_defaults= flag&1;
line= xorriso->result_line;
@ -2736,7 +2780,7 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
Xorriso_status_result(xorriso,filter,fp,flag&2);
is_default= (xorriso->result_page_length==0 && xorriso->result_page_width==80);
sprintf(line,"-page:%d:%d\n",
sprintf(line,"-page %d %d\n",
(xorriso->result_page_length>=0?xorriso->result_page_length
:-xorriso->result_page_length),
xorriso->result_page_width);
@ -2758,6 +2802,14 @@ 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);
for(i=0;i<4;i++) {
is_default= (xorriso->logfile[i]!=0);
sprintf(line,"-logfile %s %s\n",
channel_prefixes[i],Text_shellsafe(xorriso->logfile[i],sfe,0));
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
is_default= (xorriso->mark_text[0]==0);
sprintf(line,"-mark %s\n",Text_shellsafe(xorriso->mark_text,sfe,0));
if(!(is_default && no_defaults))
@ -2769,6 +2821,71 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
sprintf(line,"-cd %s\n",
(xorriso->wdi[0] ? Text_shellsafe(xorriso->wdi,sfe,0) : "'/'"));
Xorriso_status_result(xorriso,filter,fp,flag&2);
sprintf(line,"-cdx %s\n",
(xorriso->wdx[0] ? Text_shellsafe(xorriso->wdx,sfe,0) : "'/'"));
Xorriso_status_result(xorriso,filter,fp,flag&2);
if(xorriso->ban_stdio_write) {
sprintf(line,"-ban_stdio_write\n");
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
is_default= (xorriso->volid[0]==0);
sprintf(line,"-V %s\n",Text_shellsafe(xorriso->volid,sfe,0));
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
if(xorriso->do_joliet) {
sprintf(line,"-J\n");
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
if(xorriso->do_global_uid) {
sprintf(line,"-uid %lu\n", (unsigned long) xorriso->global_uid);
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
if(xorriso->do_global_gid) {
sprintf(line,"-gid %lu\n", (unsigned long) xorriso->global_gid);
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
if(xorriso->allow_graft_points) {
sprintf(line,"-graft-points\n");
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
if(xorriso->do_follow_links) {
sprintf(line,"-f\n");
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
is_default= !!xorriso->do_overwrite;
sprintf(line,"-overwrite %s\n",(xorriso->do_overwrite ? "on" : "off"));
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
is_default= !xorriso->do_reassure;
sprintf(line,"-reassure %s\n",(xorriso->do_reassure ? "on" : "off"));
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
is_default= !xorriso->do_close;
sprintf(line,"-close %s\n",(xorriso->do_close ? "on" : "off"));
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
is_default= !xorriso->do_dummy;
sprintf(line,"-dummy %s\n",(xorriso->do_dummy ? "on" : "off"));
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
is_default= (xorriso->speed==0);
sprintf(line,"-speed %dkB/s\n", xorriso->speed);
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
/* >>> BAUSTELLE */
if(xorriso->status_history_max!=Xorriso_status_history_maX || !no_defaults) {
sprintf(line,"-status_history_max %d\n",xorriso->status_history_max);
@ -2800,6 +2917,16 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
#endif /* Xorriso_with_readlinE */
if(strcmp(xorriso->indev,xorriso->outdev)==0) {
sprintf(line,"-dev %s\n", Text_shellsafe(xorriso->indev,sfe,0));
Xorriso_status_result(xorriso,filter,fp,flag&2);
} else {
sprintf(line,"-indev %s\n", Text_shellsafe(xorriso->indev,sfe,0));
Xorriso_status_result(xorriso,filter,fp,flag&2);
sprintf(line,"-outdev %s\n", Text_shellsafe(xorriso->outdev,sfe,0));
Xorriso_status_result(xorriso,filter,fp,flag&2);
}
return(1);
}
@ -2957,8 +3084,8 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
Xorriso_info(xorriso,0);
sprintf(xorriso->result_line,"%s/\n",Text_shellsafe(xorriso->wdi, sfe, 0));
Xorriso_result(xorriso,0);
if(iso_rr_path[0]==0) {
strcpy(xorriso->wdi,"/");
if(strcmp(iso_rr_path,"/")==0) {
strcpy(xorriso->wdi,"");
Xorriso_option_pwdi(xorriso, 0);
return(1);
}
@ -3000,18 +3127,21 @@ int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag)
Xorriso_info(xorriso,0);
sprintf(xorriso->result_line,"%s/\n",Text_shellsafe(xorriso->wdx, sfe, 0));
Xorriso_result(xorriso,0);
if(disk_path[0]==0) {
strcpy(xorriso->wdx,"/");
if(strcmp(disk_path,"/")==0) {
strcpy(xorriso->wdx,"");
Xorriso_option_pwdx(xorriso, 0);
return(1);
}
ret= 1;
/* >>> XORRISO: check whether directory exists on disk */;
if(ret<=0) {
ret= Sfile_type(disk_path,1|4|8);
if(ret<0) {
sprintf(xorriso->info_text,"-cdx: file not found :\n%s\n",disk_path);
return(0);
}
if(ret!=2) {
sprintf(xorriso->info_text,
"-cdx: not found or not a directory :\n%s\n",disk_path);
"-cdx: file is not a directory :\n%s\n",disk_path);
Xorriso_info(xorriso,0);
return(0);
}
@ -3366,8 +3496,8 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" If \"on\" then mark the written media as not appendable.",
" -dummy \"on\"|\"off\"",
" If \"on\" simulate burning. Refuse if media cannot simulate.",
" -speed number[\"k\"|\"m\"]",
" Set the burn speed. Default is maximum speed.",
" -speed number[\"k\"|\"m\"|\"[x]CD\"|\"[x]DVD\"]",
" Set the burn speed. Default is 0 = maximum speed.",
" -fs number[\"k\"|\"m\"]",
" Set the size of the fifo buffer. (Default is 4m)",
" -eject \"in\"|\"out\"|\"all\"",
@ -3573,15 +3703,17 @@ logfile_wrong_form:;
hflag= 4;
else
goto logfile_wrong_form;
if(strcmp(fileadr,"-")==0)
if(strcmp(fileadr,"-")==0 || fileadr[0]==0)
hflag|= (1<<15);
xorriso->logfile[channel_no][0]= 0;
ret= Write_to_channel(fileadr,channel_no,hflag);
if(ret<=0) {
sprintf(xorriso->info_text,
"--- Cannot open logfile: %s\n %s\n",
fileadr,(errno>0?strerror(errno):"-unknown error-"));
Xorriso_info(xorriso,0);
}
} else if(!(hflag&(1<<15)))
strcpy(xorriso->logfile[channel_no], fileadr);
return(ret>0);
}
@ -3730,7 +3862,7 @@ int Xorriso_option_overwrite(struct XorrisO *xorriso, char *mode, int flag)
/* Option -page */
int Xorriso_option_page(struct XorrisO *xorriso, int len, int width, int flag)
{
if(len<=0 || width<=0) {
if(len<0 || width<=0) {
sprintf(xorriso->info_text,
"--- Improper numeric value of arguments of -page: %d %d\n",
len, width);
@ -3903,7 +4035,53 @@ int Xorriso_option_rollback(struct XorrisO *xorriso, int flag)
/* Option -speed */
int Xorriso_option_speed(struct XorrisO *xorriso, char *speed, int flag)
{
fprintf(stderr, ">>> LIBISOFS : -speed %s\n", speed);
int is_cd= 1;
double num;
char *cpt;
if(speed[0]==0) {
xorriso->speed= 0; /* full speed */
return(1);
}
sscanf(speed,"%lf",&num);
for(cpt= speed+strlen(speed)-1; cpt>=speed; cpt--)
if(isdigit(*cpt) || *cpt=='.')
break;
cpt++;
if(*cpt=='k' || *cpt=='K')
/* is merchand kilobyte, stays merchand kilobyte */;
else if(*cpt=='m' || *cpt=='M')
num*= 1000;
else if(*cpt=='x' || *cpt=='X')
cpt++;
if(*cpt=='c' || *cpt=='C') {
cd_speed:;
num*= 176.4;
} else if(*cpt=='d' || *cpt=='D') {
dvd_speed:;
num*= 1385;
} else {
/* >>> try to determine target media */;
if(is_cd)
goto cd_speed;
else
goto dvd_speed;
}
if(num> 2.0e9) {
/* >>> too large */;
return(0);
}
xorriso->speed= num;
if(xorriso->speed<num)
xorriso->speed++;
return(1);
}
@ -4458,9 +4636,6 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv,
}
/* >>>>> BAUSTELLE */
#ifdef Xorriso_with_maiN
int main(int argc, char **argv)

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.13.103645"
#define Xorriso_timestamP "2007.10.13.141503"