1
0
Fork 0

probably finished

This commit is contained in:
dtb 2024-01-06 14:39:47 -07:00
parent c52dab536e
commit 1c1c25f5d6
1 changed files with 32 additions and 14 deletions

View File

@ -124,7 +124,10 @@ static int
Io_fdopen(struct Io *io, char *fn){
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->fd = fd;
io->fn = fn;
@ -247,7 +250,7 @@ output(struct Io io[2]){
static int
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(-o [output file]) (-B [output block size]) (-S [output offset])\n",
ARGV0(argv0));
@ -258,6 +261,7 @@ usage(char *argv0){
int main(int argc, char *argv[]){
char align;
char debug;
char noerror;
int c;
int count;
@ -267,6 +271,7 @@ int main(int argc, char *argv[]){
/* defaults */
align = -1;
count = 0;
debug = 2;
fmt_output = fmt_asv;
noerror = 0;
io[0].fl = read_flags;
@ -275,19 +280,23 @@ int main(int argc, char *argv[]){
Io_setdefaults(&io[1]);
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(Io_fdopen(&io[c == 'o'], optarg) == -1){
terminate(io);
return oserr(argv[0], optarg);
}
/* boolean/flag arguments */
}else if(c == 'f')
noerror = 1;
else if(c == 'A')
}else if(c == 'A')
align = '\0';
else if(c == 'f')
noerror = 1;
else if(c == 'H')
fmt_output = fmt_human;
else if(c == 'q')
debug = 1;
else if(c == 'Q')
debug = 0;
/* optarg */
else if(c == 'a' && optarg[0] != '\0' && optarg[1] == '\0')
align = optarg[0];
@ -314,7 +323,11 @@ int main(int argc, char *argv[]){
return EX_OSERR;
}else if(io[p].seek > 0) /* seek */
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;
else if(io[0].bufuse < io[0].bs){
++io[0].prec;
if(noerror){
}else
if(debug >= 2){
fprintf(stderr, "%s: Partial write:\n\t", ARGV0(argv[0]));
output(io);
}
if(!noerror)
count = 1;
if(align >= 0)
Io_bufrpad(&io[0], align);
@ -351,9 +366,11 @@ int main(int argc, char *argv[]){
count = 1;
else if(c > io[1].bufuse && io[1].bufuse > 0){
io[1].prec += 1;
if(noerror){
}else
if(debug >= 2){
fprintf(stderr, "%s: Partial write:\n\t", ARGV0(argv[0]));
output(io);
}
if(!noerror)
count = 1;
}else if(io[1].bufuse == 0 && c < io[1].bs)
++io[1].prec;
@ -362,7 +379,8 @@ int main(int argc, char *argv[]){
}while(io[0].bufuse > 0);
}while(count == 0 || --count > 0);
output(io);
if(debug >= 1)
output(io);
terminate(io);
return EX_OK;