xref: /titanic_50/usr/src/lib/libcmd/common/cmdinit.c (revision d6114e2d100d9ec3b45f9968d45ac2e3a0827af0)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1992-2009 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                                                                      *
20 ***********************************************************************/
21 #pragma prototyped
22 /*
23  * command initialization
24  */
25 
26 #include <cmd.h>
27 #include <shcmd.h>
28 
29 int
30 _cmd_init(int argc, char** argv, void* context, const char* catalog, int flags)
31 {
32 	register char*	cp;
33 
34 	if (argc <= 0)
35 		return -1;
36 	if (context)
37 	{
38 		if (flags & ERROR_CALLBACK)
39 		{
40 			flags &= ~ERROR_CALLBACK;
41 			flags |= ERROR_NOTIFY;
42 		}
43 		else if (flags & ERROR_NOTIFY)
44 		{
45 			((Shbltin_t*)(context))->notify = 1;
46 			flags &= ~ERROR_NOTIFY;
47 		}
48 		error_info.flags |= flags;
49 	}
50 	if (cp = strrchr(argv[0], '/'))
51 		cp++;
52 	else
53 		cp = argv[0];
54 	error_info.id = cp;
55 	if (!error_info.catalog)
56 		error_info.catalog = catalog;
57 	opt_info.index = 0;
58 	return 0;
59 }
60 
61 #if __OBSOLETE__ < 20080101
62 
63 #if defined(__EXPORT__)
64 #define extern	__EXPORT__
65 #endif
66 
67 #undef	cmdinit
68 
69 extern void
70 cmdinit(char** argv, void* context, const char* catalog, int flags)
71 {
72 	_cmd_init(0, argv, context, catalog, flags);
73 }
74 
75 #endif
76