implemented --help

This commit is contained in:
Noah Swerhun 2021-07-02 22:36:32 -05:00
parent 8ea5855715
commit 87aab37e05

View file

@ -10,6 +10,23 @@ void die(char *s) {
fprintf(stderr, "fatal: %s\n", s); fprintf(stderr, "fatal: %s\n", s);
exit(1); exit(1);
} }
void usage(void) {
printf(
"cards: A terminal flashcard program written in C using ncurses.\n"
"Usage:\n"
" cards [filename]\n"
" Read cards from filename. Filename must be a tab separated value file\n"
" containing exactly two fields. The first field should contain the text for\n"
" the \"front\" of the card. The second field should contain the text for the\n"
" back. Each line is read as a separate card. Note that it must be delimited\n"
" by hard tabs (ascii 9), NOT spaces.\n"
" cards --help\n"
" Display this help message.\n"
);
exit(0);
}
char *fgetl(FILE *stream) { size_t s_sz = 1; // +1 for null byte char *fgetl(FILE *stream) { size_t s_sz = 1; // +1 for null byte
char *s = NULL; char *s = NULL;
char c; char c;
@ -42,7 +59,9 @@ int main(int argc, char **argv) {
char k = '\0', *help_message; char k = '\0', *help_message;
if (argc < 2) if (argc < 2)
die("filename required"); die("arg required");
if (!strcmp(argv[1], "--help"))
usage();
cards = card_parse_csv(argv[1], &cards_ct); cards = card_parse_csv(argv[1], &cards_ct);