Commits

Ragnara committed 86fb5c3

1. Additional parameters --help, --version and -h
2. -- allows use of --help, --version, -h or -s as a target filename
3. Error messages for wrong parameters before showing usage

Comments (0)

Files changed (3)

 
 buildcounter: buildcounter.c
 	$(CC) $(CFLAGS) -o buildcounter buildcounter.c
-	@buildcounter buildno.h || echo "No buildcounting"
+	@buildcounter -s buildno.h || echo "No buildcounting"
 
 clean:
 	-rm buildcounter
 {
     fprintf(stderr, "Usage: %s [-s] <filename>\n", argv0);
     fprintf(stderr, "       -s: Silent mode\n\n");
-    fprintf(stderr, "Build: %d (%s)\n", BUILDNO, __DATE__);
+    fprintf(stderr, "Build: %d (compiled on %s)\n", BUILDNO, __DATE__);
+    fprintf(stderr, "Licensed under ISC license\n");
     fprintf(stderr, "https://bitbucket.org/Ragnara/buildcounter\n");
     exit(1);
 }
 static char *parse_parameters(int argc, char **argv, _Bool *silent)
 {
     if (argc < 2 || argc > 3)
+    {
+        fprintf(stderr, "Invalid number of parameters\n\n");
+        print_usage(argv[0]);
+    }
+
+    if (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
         print_usage(argv[0]);
 
     *silent = 0;
 
     if(argc == 3)
     {
-        if (strcmp(argv[1], "-s"))
+        if (!strcmp(argv[1], "-s"))
+        {
+            *silent = 1;
+        }
+        else if (strcmp(argv[1], "--"))
+        {
+            fprintf(stderr, "Invalid parameter '%s'\n\n", argv[1]);
             print_usage(argv[0]);
-        *silent = 1;
+        }
         ++filename_index;
     }
 
-#define BUILDNO 13
+#define BUILDNO 16