xref: /titanic_41/usr/src/lib/libast/common/include/cmdarg.h (revision 450396635f70344c58b6b1e4db38cf17ff34445c)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 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 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Research
26  *
27  * xargs/tw command arg list interface definitions
28  */
29 
30 #ifndef _CMDARG_H
31 #define _CMDARG_H
32 
33 #define CMD_CHECKED	(1<<9)		/* cmdopen() argv[0] ok		*/
34 #define CMD_EMPTY	(1<<0)		/* run once, even if no args	*/
35 #define CMD_EXACT	(1<<1)		/* last command must have argmax*/
36 #define CMD_IGNORE	(1<<2)		/* ignore EXIT_QUIT exit	*/
37 #define CMD_INSERT	(1<<3)		/* argpat for insertion		*/
38 #define CMD_MINIMUM	(1<<4)		/* argmax is a minimum		*/
39 #define CMD_NEWLINE	(1<<5)		/* echo separator is newline	*/
40 #define CMD_POST	(1<<6)		/* argpat is post arg position	*/
41 #define CMD_QUERY	(1<<7)		/* trace and query each command	*/
42 #define CMD_SILENT	(1<<10)		/* no error messages		*/
43 #define CMD_TRACE	(1<<8)		/* trace each command		*/
44 
45 #define CMD_USER	(1<<12)
46 
47 typedef struct				/* cmd + args info		*/
48 {
49 	struct
50 	{
51 	size_t		args;		/* total args			*/
52 	size_t		commands;	/* total commands		*/
53 	}		total;
54 
55 	int		argcount;	/* current arg count		*/
56 	int		argmax;		/* max # args			*/
57 	int		echo;		/* just an echo			*/
58 	int		flags;		/* CMD_* flags			*/
59 	int		insertlen;	/* strlen(insert)		*/
60 	int		offset;		/* post arg offset		*/
61 
62 	char**		argv;		/* exec argv			*/
63 	char**		firstarg;	/* first argv file arg		*/
64 	char**		insertarg;	/* argv before insert		*/
65 	char**		postarg;	/* start of post arg list	*/
66 	char**		nextarg;	/* next argv file arg		*/
67 	char*		nextstr;	/* next string ends before here	*/
68 	char*		laststr;	/* last string ends before here	*/
69 	char*		insert;		/* replace with current arg	*/
70 	char		buf[1];		/* argv and arg buffer		*/
71 } Cmdarg_t;
72 
73 #if _BLD_ast && defined(__EXPORT__)
74 #define extern		__EXPORT__
75 #endif
76 
77 extern Cmdarg_t*	cmdopen(char**, int, int, const char*, int);
78 extern int		cmdflush(Cmdarg_t*);
79 extern int		cmdarg(Cmdarg_t*, const char*, int);
80 extern int		cmdclose(Cmdarg_t*);
81 
82 #undef	extern
83 
84 #endif
85