baseline.c (2089B)
1 /* 2 * Copyright (c) 2014 Mohamed Aslan <maslan@sce.carleton.ca> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include <stdio.h> 18 #include <stdlib.h> /* EXIT_* */ 19 #include <string.h> /* strcmp(1) */ 20 #include <err.h> /* err(3) */ 21 #include "cmd.h" 22 23 void usage(void) 24 { 25 fprintf(stderr, "usage: baseline <command> [args]\n"); 26 } 27 28 int 29 main(int argc, char **argv) 30 { 31 /* TODO: use getopt(3) */ 32 if (argc < 2) { 33 usage(); 34 return EXIT_FAILURE; 35 } 36 if (!strcmp(argv[1], "add")) { 37 cmd_add(argc - 1, argv + 1); 38 } 39 else if (!strcmp(argv[1], "branch")) { 40 cmd_branch(argc - 1, argv + 1); 41 } 42 else if (!strcmp(argv[1], "cat")) { 43 cmd_cat(argc - 1, argv + 1); 44 } 45 else if (!strcmp(argv[1], "checkout")) { 46 cmd_checkout(argc - 1, argv + 1); 47 } 48 else if (!strcmp(argv[1], "commit")) { 49 cmd_commit(argc - 1, argv + 1); 50 } 51 else if (!strcmp(argv[1], "diff")) { 52 cmd_diff(argc - 1, argv + 1); 53 } 54 else if (!strcmp(argv[1], "help")) { 55 cmd_help(argc - 1, argv + 1); 56 } 57 else if (!strcmp(argv[1], "init")) { 58 cmd_init(argc - 1, argv + 1); 59 } 60 else if (!strcmp(argv[1], "ls")) { 61 cmd_ls(argc - 1, argv + 1); 62 } 63 else if (!strcmp(argv[1], "log")) { 64 cmd_log(argc - 1, argv + 1); 65 } 66 else if (!strcmp(argv[1], "version")) { 67 cmd_version(argc - 1, argv + 1); 68 } 69 else { 70 errx(EXIT_FAILURE, "unkown commad: \'%s\'.\nFor list of available commands, type:\n\tbaseline help", argv[1]); 71 } 72 return EXIT_SUCCESS; 73 } 74