/* $Header$ * * This is GAT, something like GIT. * It's a VCS which is easy to use, fast and secure. * * This is release early code. Use at own risk. * * It is meant as a replacement of CVS for my file repositories, to * make it more easy to distribute the code between all my machines * and gather back all those changes. Very soon it shall compile * under Linux and Cygwin, such that it can be used under Windows, * too. * * Copyright (C)2005 by Valentin Hilbig * Based on ideas presented in GIT from Linus Torvalds. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Log$ */ #include "tino/file.h" #include "tino/fatal.h" #include "tino/ex.h" #include "tino/filetool.h" #include "gat-lib.h" #include #include #include #include #include #include #define CMD(X,A,B,C,S) static int cmd_##X(GAT, int, char **); #include "gat-cmds.h" static struct gat_cmd { const char *name; int minargs, maxargs; const char *arghelp, *shorthelp; int (*fn)(GAT g, int argc, char **argv); } cmds[] = { #define CMD(X,A,B,C,S) { #X, A,B, C,S, cmd_##X }, #include "gat-cmds.h" }; static int find_cmd(const char *s) { int i; for (i=sizeof cmds/sizeof *cmds; --i>=0; ) if (!strcmp(s, cmds[i].name)) return i; tino_exit("unknown command, try `help'"); return -1; } static void usage(const char *arg0) { const char *tmp; if ((tmp=strrchr(arg0, '/'))!=0 || (tmp=strrchr(arg0, '\\'))!=0) arg0 = tmp; fprintf(stderr, "Usage: %s command [args...]\n" "\ttry command `help' for help\n" , arg0); exit(GAT_EXIT_USAGE); } int main(int argc, char **argv) { int i; GAT g; if (argc<2) usage(argv[0]); g = GAT_init("gat", NULL, NULL); i = find_cmd(argv[1]); argc -= 2; if (argc=0 && argc>cmds[i].maxargs)) tino_err("wrong number of arguments for %s", argv[1]); return cmds[i].fn(g, argc, argv+2); } static int cmd_help(GAT g, int argc, char **argv) { int i; for (i=sizeof cmds/sizeof *cmds; --i>=0; ) printf("%s %s\n\t%s\n", cmds[i].name, cmds[i].arghelp, cmds[i].shorthelp); return 0; } static int cmd_add(GAT g, int argc, char **argv) { int i; for (i=0; i