17c2fbfb3SApril Chin /***********************************************************************
27c2fbfb3SApril Chin *                                                                      *
37c2fbfb3SApril Chin *               This software is part of the ast package               *
4*b30d1939SAndy Fiddaman *          Copyright (c) 1985-2012 AT&T Intellectual Property          *
57c2fbfb3SApril Chin *                      and is licensed under the                       *
6*b30d1939SAndy Fiddaman *                 Eclipse Public License, Version 1.0                  *
77c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
87c2fbfb3SApril Chin *                                                                      *
97c2fbfb3SApril Chin *                A copy of the License is available at                 *
10*b30d1939SAndy Fiddaman *          http://www.eclipse.org/org/documents/epl-v10.html           *
11*b30d1939SAndy Fiddaman *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
127c2fbfb3SApril Chin *                                                                      *
137c2fbfb3SApril Chin *              Information and Software Systems Research               *
147c2fbfb3SApril Chin *                            AT&T Research                             *
157c2fbfb3SApril Chin *                           Florham Park NJ                            *
167c2fbfb3SApril Chin *                                                                      *
177c2fbfb3SApril Chin *                 Glenn Fowler <gsf@research.att.com>                  *
187c2fbfb3SApril Chin *                  David Korn <dgk@research.att.com>                   *
197c2fbfb3SApril Chin *                   Phong Vo <kpv@research.att.com>                    *
207c2fbfb3SApril Chin *                                                                      *
217c2fbfb3SApril Chin ***********************************************************************/
227c2fbfb3SApril Chin #pragma prototyped
237c2fbfb3SApril Chin /*
247c2fbfb3SApril Chin  * Glenn Fowler
257c2fbfb3SApril Chin  * AT&T Research
267c2fbfb3SApril Chin  *
277c2fbfb3SApril Chin  * xargs/tw command arg list interface definitions
287c2fbfb3SApril Chin  */
297c2fbfb3SApril Chin 
307c2fbfb3SApril Chin #ifndef _CMDARG_H
31*b30d1939SAndy Fiddaman #define _CMDARG_H	1
32*b30d1939SAndy Fiddaman 
33*b30d1939SAndy Fiddaman #include <error.h>
34*b30d1939SAndy Fiddaman 
35*b30d1939SAndy Fiddaman #define CMD_VERSION	20120411L
367c2fbfb3SApril Chin 
377c2fbfb3SApril Chin #define CMD_CHECKED	(1<<9)		/* cmdopen() argv[0] ok		*/
387c2fbfb3SApril Chin #define CMD_EMPTY	(1<<0)		/* run once, even if no args	*/
397c2fbfb3SApril Chin #define CMD_EXACT	(1<<1)		/* last command must have argmax*/
40*b30d1939SAndy Fiddaman #define CMD_EXIT	(1<<11)		/* fatal error_info.exit()	*/
417c2fbfb3SApril Chin #define CMD_IGNORE	(1<<2)		/* ignore EXIT_QUIT exit	*/
427c2fbfb3SApril Chin #define CMD_INSERT	(1<<3)		/* argpat for insertion		*/
437c2fbfb3SApril Chin #define CMD_MINIMUM	(1<<4)		/* argmax is a minimum		*/
447c2fbfb3SApril Chin #define CMD_NEWLINE	(1<<5)		/* echo separator is newline	*/
457c2fbfb3SApril Chin #define CMD_POST	(1<<6)		/* argpat is post arg position	*/
467c2fbfb3SApril Chin #define CMD_QUERY	(1<<7)		/* trace and query each command	*/
477c2fbfb3SApril Chin #define CMD_SILENT	(1<<10)		/* no error messages		*/
487c2fbfb3SApril Chin #define CMD_TRACE	(1<<8)		/* trace each command		*/
497c2fbfb3SApril Chin 
507c2fbfb3SApril Chin #define CMD_USER	(1<<12)
517c2fbfb3SApril Chin 
52*b30d1939SAndy Fiddaman #define CMDDISC(d,f,e)	(memset(d,0,sizeof(*(d))),(d)->version=CMD_VERSION,(d)->flags=(f),(d)->errorf=(e))
53*b30d1939SAndy Fiddaman 
54*b30d1939SAndy Fiddaman struct Cmddisc_s;
55*b30d1939SAndy Fiddaman typedef struct Cmddisc_s Cmddisc_t;
56*b30d1939SAndy Fiddaman 
57*b30d1939SAndy Fiddaman typedef int (*Cmdrun_f)(int, char**, Cmddisc_t*);
58*b30d1939SAndy Fiddaman 
59*b30d1939SAndy Fiddaman struct Cmddisc_s
607c2fbfb3SApril Chin {
61*b30d1939SAndy Fiddaman 	uint32_t	version;	/* CMD_VERSION			*/
62*b30d1939SAndy Fiddaman 	uint32_t	flags;		/* CMD_* flags			*/
63*b30d1939SAndy Fiddaman 	Error_f		errorf;		/* optional error function	*/
64*b30d1939SAndy Fiddaman 	Cmdrun_f	runf;		/* optional exec function	*/
65*b30d1939SAndy Fiddaman };
66*b30d1939SAndy Fiddaman 
67*b30d1939SAndy Fiddaman typedef struct Cmdarg_s			/* cmdopen() handle		*/
68*b30d1939SAndy Fiddaman {
69*b30d1939SAndy Fiddaman 	const char*	id;		/* library id string		*/
70*b30d1939SAndy Fiddaman 
71*b30d1939SAndy Fiddaman #ifdef _CMDARG_PRIVATE_
72*b30d1939SAndy Fiddaman 	_CMDARG_PRIVATE_
73*b30d1939SAndy Fiddaman #endif
74*b30d1939SAndy Fiddaman 
757c2fbfb3SApril Chin } Cmdarg_t;
767c2fbfb3SApril Chin 
777c2fbfb3SApril Chin #if _BLD_ast && defined(__EXPORT__)
787c2fbfb3SApril Chin #define extern		__EXPORT__
797c2fbfb3SApril Chin #endif
807c2fbfb3SApril Chin 
81*b30d1939SAndy Fiddaman #ifndef cmdopen
827c2fbfb3SApril Chin extern Cmdarg_t*	cmdopen(char**, int, int, const char*, int);
83*b30d1939SAndy Fiddaman #endif
84*b30d1939SAndy Fiddaman extern Cmdarg_t*	cmdopen_20110505(char**, int, int, const char*, int, Error_f);
85*b30d1939SAndy Fiddaman extern Cmdarg_t*	cmdopen_20120411(char**, int, int, const char*, Cmddisc_t*);
867c2fbfb3SApril Chin extern int		cmdflush(Cmdarg_t*);
877c2fbfb3SApril Chin extern int		cmdarg(Cmdarg_t*, const char*, int);
887c2fbfb3SApril Chin extern int		cmdclose(Cmdarg_t*);
897c2fbfb3SApril Chin 
907c2fbfb3SApril Chin #undef	extern
917c2fbfb3SApril Chin 
927c2fbfb3SApril Chin #endif