[BACK]Return to tcfsmng.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tcfs

Annotation of src/usr.bin/tcfs/tcfsmng.c, Revision 1.3

1.3     ! aaron       1: /*     $OpenBSD: tcfsmng.c,v 1.2 2000/06/19 20:35:48 fgsch Exp $       */
1.2       fgsch       2:
1.1       provos      3: /*
                      4:  * Copyright 2000 Niels Provos <provos@citi.umich.edu>
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. The name of the author may not be used to endorse or promote products
                     16:  *    derived from this software without specific prior written permission.
                     17:  *
                     18:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     19:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     20:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     21:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     22:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     23:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     24:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     25:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     26:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     27:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     28:  */
                     29:
                     30: #include <stdio.h>
                     31: #include <stdlib.h>
                     32:
                     33: extern int adduser_main(int argc, char **argv);
                     34: extern int rmuser_main(int argc, char **argv);
                     35: extern int addgroup_main(int argc, char **argv);
                     36: extern int rmgroup_main(int argc, char **argv);
                     37:
                     38: struct subprg {
                     39:        char *name;
                     40:        int (*function)(int, char **);
                     41: };
                     42:
                     43: struct subprg subcmds[] = {
                     44:        {"adduser", adduser_main},
                     45:        {"rmuser", rmuser_main},
                     46:        {"addgroup", addgroup_main},
                     47:        {"rmgroup", rmgroup_main}
                     48: };
                     49:
                     50: void
                     51: usage(char *name)
                     52: {
                     53:        int i;
                     54:        fprintf(stderr, "Usage: %s <subcmd> [arguments]\n", name);
                     55:
                     56:        fprintf(stderr, "Possible sub commands:");
                     57:        for (i = sizeof(subcmds)/sizeof(struct subprg) - 1; i >= 0; i--)
                     58:                fprintf(stderr, " %s", subcmds[i].name);
                     59:        fprintf(stderr, "\n");
                     60: }
                     61:
                     62:
                     63: int
                     64: main (int argc, char **argv)
                     65: {
                     66:        int i;
                     67:
                     68:        if (argc < 2) {
                     69:                usage(argv[0]);
                     70:                exit(1);
                     71:        }
                     72:
                     73:        for (i = sizeof(subcmds)/sizeof(struct subprg) - 1; i >= 0; i--) {
                     74:                if (!strcmp(argv[1], subcmds[i].name))
                     75:                        return (*subcmds[i].function)(argc - 1, argv + 1);
                     76:        }
                     77:
                     78:        fprintf(stderr, "%s: unknown command %s\n\n", argv[0], argv[1]);
                     79:        usage(argv[0]);
1.3     ! aaron      80:        exit(1);
1.1       provos     81: }