1 /***********************************************************************
2  *                                                                      *
3  *               This software is part of the ast package               *
4  *          Copyright (c) 1992-2012 AT&T Intellectual Property          *
5  *                      and is licensed under the                       *
6  *                 Eclipse Public License, Version 1.0                  *
7  *                    by AT&T Intellectual Property                     *
8  *                                                                      *
9  *                A copy of the License is available at                 *
10  *          http://www.eclipse.org/org/documents/epl-v10.html           *
11  *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12  *                                                                      *
13  *              Information and Software Systems Research               *
14  *                            AT&T Research                             *
15  *                           Florham Park NJ                            *
16  *                                                                      *
17  *               Glenn Fowler <glenn.s.fowler@gmail.com>                *
18  *                    David Korn <dgkorn@gmail.com>                     *
19  *                                                                      *
20  ***********************************************************************/
21 /*
22  * command initialization
23  */
24 #include "config_ast.h"  // IWYU pragma: keep
25 
26 #include <string.h>
27 
28 #include "error.h"
29 #include "option.h"
30 #include "shcmd.h"
31 
cmdinit(int argc,char ** argv,Shbltin_t * context,int flags)32 int cmdinit(int argc, char **argv, Shbltin_t *context, int flags) {
33     char *cp;
34 
35     if (argc <= 0) return -1;
36     if (context) {
37         if (flags & ERROR_NOTIFY) {
38             context->notify = 1;
39             flags &= ~ERROR_NOTIFY;
40         }
41         error_info.flags |= flags;
42     }
43     cp = strrchr(argv[0], '/');
44     if (cp) {
45         cp++;
46     } else {
47         cp = argv[0];
48     }
49     error_info.id = cp;
50     opt_info.index = 0;
51     return 0;
52 }
53