mm(1): error out when given positional arguments

This commit is contained in:
dtb 2024-03-31 22:54:03 -06:00
parent 8d9ac33566
commit 61382c34d9
Signed by: trinity
GPG Key ID: 31FF85CCB6DC7641

View File

@ -106,6 +106,15 @@ oserr(char *s, char *r){
} \ } \
return retval return retval
/* Prints a usage text, in which s is the program being run (i.e. argv[0]), and
* returns an exit status appropriate for a usage error. */
int usage(char *s){
fprintf(stderr, "Usage: %s (-aenu) (-i [input])... (-o [output])...\n", s);
return EX_USAGE;
}
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
int c; int c;
struct Files files[2]; /* {read, write} */ struct Files files[2]; /* {read, write} */
@ -178,12 +187,15 @@ int main(int argc, char *argv[]){
k = 1; k = 1;
break; break;
default: default:
fprintf(stderr, "Usage: %s (-aenu) (-i [input])..." retval = usage(argv[0]);
" (-o [output])...\n", argv[0]);
retval = EX_USAGE;
terminate; terminate;
} }
if(optind != argc){
retval = usage(argv[0]);
terminate;
}
files[0].s += files[0].s == 0; files[0].s += files[0].s == 0;
files[1].s += files[1].s == 0; files[1].s += files[1].s == 0;