probably finished
This commit is contained in:
parent
c52dab536e
commit
1c1c25f5d6
46
Wip/dj/dj.c
46
Wip/dj/dj.c
@ -124,7 +124,10 @@ static int
|
|||||||
Io_fdopen(struct Io *io, char *fn){
|
Io_fdopen(struct Io *io, char *fn){
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if((fd = open(fn, io->fl)) != -1
|
if((fd = open(fn, io->fl,
|
||||||
|
/* these are the flags used by touch(1p) */
|
||||||
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH))
|
||||||
|
!= -1
|
||||||
&& Io_fdclose(io) == 0){
|
&& Io_fdclose(io) == 0){
|
||||||
io->fd = fd;
|
io->fd = fd;
|
||||||
io->fn = fn;
|
io->fn = fn;
|
||||||
@ -247,7 +250,7 @@ output(struct Io io[2]){
|
|||||||
static int
|
static int
|
||||||
usage(char *argv0){
|
usage(char *argv0){
|
||||||
|
|
||||||
fprintf(stderr, "Usage: %s (-fAH) (-a [byte]) (-c [count])\n"
|
fprintf(stderr, "Usage: %s (-dfAH) (-a [byte]) (-c [count])\n"
|
||||||
"\t(-i [input file]) (-b [input block size]) (-s [input offset])\n"
|
"\t(-i [input file]) (-b [input block size]) (-s [input offset])\n"
|
||||||
"\t(-o [output file]) (-B [output block size]) (-S [output offset])\n",
|
"\t(-o [output file]) (-B [output block size]) (-S [output offset])\n",
|
||||||
ARGV0(argv0));
|
ARGV0(argv0));
|
||||||
@ -258,6 +261,7 @@ usage(char *argv0){
|
|||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
char align;
|
char align;
|
||||||
|
char debug;
|
||||||
char noerror;
|
char noerror;
|
||||||
int c;
|
int c;
|
||||||
int count;
|
int count;
|
||||||
@ -267,6 +271,7 @@ int main(int argc, char *argv[]){
|
|||||||
/* defaults */
|
/* defaults */
|
||||||
align = -1;
|
align = -1;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
debug = 2;
|
||||||
fmt_output = fmt_asv;
|
fmt_output = fmt_asv;
|
||||||
noerror = 0;
|
noerror = 0;
|
||||||
io[0].fl = read_flags;
|
io[0].fl = read_flags;
|
||||||
@ -275,19 +280,23 @@ int main(int argc, char *argv[]){
|
|||||||
Io_setdefaults(&io[1]);
|
Io_setdefaults(&io[1]);
|
||||||
|
|
||||||
if(argc > 0)
|
if(argc > 0)
|
||||||
while((c = getopt(argc, argv, "a:Ac:i:b:fHs:o:B:S:")) != -1)
|
while((c = getopt(argc, argv, "a:Ab:B:c:i:fHqQs:S:o:")) != -1)
|
||||||
if(c == 'i' || c == 'o'){
|
if(c == 'i' || c == 'o'){
|
||||||
if(Io_fdopen(&io[c == 'o'], optarg) == -1){
|
if(Io_fdopen(&io[c == 'o'], optarg) == -1){
|
||||||
terminate(io);
|
terminate(io);
|
||||||
return oserr(argv[0], optarg);
|
return oserr(argv[0], optarg);
|
||||||
}
|
}
|
||||||
/* boolean/flag arguments */
|
/* boolean/flag arguments */
|
||||||
}else if(c == 'f')
|
}else if(c == 'A')
|
||||||
noerror = 1;
|
|
||||||
else if(c == 'A')
|
|
||||||
align = '\0';
|
align = '\0';
|
||||||
|
else if(c == 'f')
|
||||||
|
noerror = 1;
|
||||||
else if(c == 'H')
|
else if(c == 'H')
|
||||||
fmt_output = fmt_human;
|
fmt_output = fmt_human;
|
||||||
|
else if(c == 'q')
|
||||||
|
debug = 1;
|
||||||
|
else if(c == 'Q')
|
||||||
|
debug = 0;
|
||||||
/* optarg */
|
/* optarg */
|
||||||
else if(c == 'a' && optarg[0] != '\0' && optarg[1] == '\0')
|
else if(c == 'a' && optarg[0] != '\0' && optarg[1] == '\0')
|
||||||
align = optarg[0];
|
align = optarg[0];
|
||||||
@ -314,7 +323,11 @@ int main(int argc, char *argv[]){
|
|||||||
return EX_OSERR;
|
return EX_OSERR;
|
||||||
}else if(io[p].seek > 0) /* seek */
|
}else if(io[p].seek > 0) /* seek */
|
||||||
switch(Io_seek(&io[p])){
|
switch(Io_seek(&io[p])){
|
||||||
case EX_OK: output(io); terminate(io); return EX_OK;
|
case EX_OK:
|
||||||
|
if(debug >= 1)
|
||||||
|
output(io);
|
||||||
|
terminate(io);
|
||||||
|
return EX_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,9 +339,11 @@ int main(int argc, char *argv[]){
|
|||||||
break;
|
break;
|
||||||
else if(io[0].bufuse < io[0].bs){
|
else if(io[0].bufuse < io[0].bs){
|
||||||
++io[0].prec;
|
++io[0].prec;
|
||||||
if(noerror){
|
if(debug >= 2){
|
||||||
|
fprintf(stderr, "%s: Partial write:\n\t", ARGV0(argv[0]));
|
||||||
}else
|
output(io);
|
||||||
|
}
|
||||||
|
if(!noerror)
|
||||||
count = 1;
|
count = 1;
|
||||||
if(align >= 0)
|
if(align >= 0)
|
||||||
Io_bufrpad(&io[0], align);
|
Io_bufrpad(&io[0], align);
|
||||||
@ -351,9 +366,11 @@ int main(int argc, char *argv[]){
|
|||||||
count = 1;
|
count = 1;
|
||||||
else if(c > io[1].bufuse && io[1].bufuse > 0){
|
else if(c > io[1].bufuse && io[1].bufuse > 0){
|
||||||
io[1].prec += 1;
|
io[1].prec += 1;
|
||||||
if(noerror){
|
if(debug >= 2){
|
||||||
|
fprintf(stderr, "%s: Partial write:\n\t", ARGV0(argv[0]));
|
||||||
}else
|
output(io);
|
||||||
|
}
|
||||||
|
if(!noerror)
|
||||||
count = 1;
|
count = 1;
|
||||||
}else if(io[1].bufuse == 0 && c < io[1].bs)
|
}else if(io[1].bufuse == 0 && c < io[1].bs)
|
||||||
++io[1].prec;
|
++io[1].prec;
|
||||||
@ -362,7 +379,8 @@ int main(int argc, char *argv[]){
|
|||||||
}while(io[0].bufuse > 0);
|
}while(io[0].bufuse > 0);
|
||||||
}while(count == 0 || --count > 0);
|
}while(count == 0 || --count > 0);
|
||||||
|
|
||||||
output(io);
|
if(debug >= 1)
|
||||||
|
output(io);
|
||||||
terminate(io);
|
terminate(io);
|
||||||
|
|
||||||
return EX_OK;
|
return EX_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user