rework usage a bit.
This commit is contained in:
parent
b9025a01db
commit
13eb71f4ee
6
makefile
6
makefile
|
@ -8,8 +8,8 @@ CC=gcc
|
|||
# CC=tcc # <= faster compilation
|
||||
|
||||
# Main file
|
||||
SRC=wc.c
|
||||
OUT=wc
|
||||
SRC=ww.c
|
||||
OUT=ww
|
||||
|
||||
## Flags
|
||||
DEBUG= #'-g'
|
||||
|
@ -31,7 +31,7 @@ format: $(SRC)
|
|||
|
||||
test: $(OUT)
|
||||
/bin/echo -e "123\n45 67" | ./$(OUT)
|
||||
/bin/echo -n "" | ./wc
|
||||
/bin/echo -n "" | ./ww
|
||||
/bin/echo " xx x" | ./$(OUT) -w
|
||||
./$(OUT) $(SRC)
|
||||
./$(OUT) nonexistent_file || true
|
||||
|
|
13
wc.c → ww.c
13
wc.c → ww.c
|
@ -31,9 +31,17 @@ int process_fn(int fn)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void usage(){
|
||||
printf("Usage: ww file.txt\n");
|
||||
printf(" or: cat file.txt | ww\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (!isatty(STDIN_FILENO)) {
|
||||
if(argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h'){
|
||||
usage();
|
||||
return 0;
|
||||
} else if (!isatty(STDIN_FILENO)) {
|
||||
return process_fn(STDIN_FILENO);
|
||||
} else if (argc > 1) {
|
||||
FILE* fp = fopen(argv[1], "r");
|
||||
|
@ -43,8 +51,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
return process_fn(fileno(fp));
|
||||
} else {
|
||||
printf("Usage: ww file.txt\n");
|
||||
printf(" or: cat file.txt | ww\n");
|
||||
usage();
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user