diff --git a/README.md b/README.md index 191cce6..042fc04 100644 --- a/README.md +++ b/README.md @@ -8,22 +8,23 @@ of other businesses, but for me it's more than enough. # Usage Usage: ./on-stock [-l] [-s [name]] [-m [name (a/s)quantity]] - [-d [name]] [-n] [-f filename] + [-d [name]] [-n] [-h] [-f filename] -l = list the articles in the database -s = search for an article in the database - If no name is given as argument, you will be prompted for a name. + If no name is given as argument, you will be prompted for a name. -m = modify a article - If no name is given as argument, you will be prompted for a - name. You'll then have the choice to change name, quantity and price. - If a name is given as argument, the quantity can be changed from the - command line, such as subtracting the stock by three: - ./on-stock -m "Nailgun" s3 + If no name is given as argument, you will be prompted for a + name. You'll then have the choice to change name, quantity and price. + If a name is given as argument, the quantity can be changed from the + command line, such as subtracting the stock by three: + ./on-stock -m "Nailgun" s3 -d = delete a article - If no name is given as argument, you will be prompted for an article - to delete. - If a name is given as argument, no confirmation will be required to - delete the article from the database. + If no name is given as argument, you will be prompted for an article + to delete. + If a name is given as argument, no confirmation will be required to + delete the article from the database. -n = create new articles (interactive mode only) + -h = display this help message -f = specifiy a filename for the database diff --git a/on-stock.c b/on-stock.c index bf5ab2c..a622019 100644 --- a/on-stock.c +++ b/on-stock.c @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) } /* Process command line arugments */ - while ((opt = getopt(argc, argv, "lsmdnf:")) != -1) + while ((opt = getopt(argc, argv, "hlsmdnf:")) != -1) { switch (opt) { @@ -68,6 +68,9 @@ int main(int argc, char* argv[]) case 'f': strncpy(filename, optarg, FILEMAXLENGTH-1); break; + case 'h': + printUsage(argv[0]); + return 0; default: printUsage(argv[0]); return 1; @@ -357,13 +360,25 @@ int new(struct myData *datap, int numRec) void printUsage(char *arg) { - fprintf(stderr, "Usage: %s [-l] [-s] [-m [-d [-n] [-f filename]\n" - "-l = list the articles in the database\n" - "-s = search for an article in the database\n" - "-m = modify a article\n" - "-d = delete a article\n" - "-n = create a new article\n" - "-f = specifiy a filename for the database\n", arg); + fprintf(stderr, "Usage: %s [-l] [-s [name]] [-m [name (a/s)quantity]]\n" + "[-d [name]] [-n] [-h] [-f filename]\n\n" + "-l = list the articles in the database\n" + "-s = search for an article in the database\n" + " If no name is given as argument, you will be prompted for a name.\n" + "-m = modify a article\n" + " If no name is given as argument, you will be prompted for a\n" + " name. You'll then have the choice to change name, quantity and price.\n" + " If a name is given as argument, the quantity can be changed from the\n" + " command line, such as subtracting the stock by three:\n" + " ./on-stock -m 'Nailgun' s3\n" + "-d = delete a article\n" + " If no name is given as argument, you will be prompted for an article\n" + " to delete.\n" + " If a name is given as argument, no confirmation will be required to\n" + " delete the article from the database.\n" + "-n = create new articles (interactive mode only)\n" + "-h = display this help message\n" + "-f = specifiy a filename for the database\n", arg); } void printHeader(void)