xref: /titanic_41/usr/src/lib/libast/common/include/cmdarg.h (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
17c2fbfb3SApril Chin /***********************************************************************
27c2fbfb3SApril Chin *                                                                      *
37c2fbfb3SApril Chin *               This software is part of the ast package               *
4*3e14f97fSRoger A. Faulkner *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
57c2fbfb3SApril Chin *                      and is licensed under the                       *
67c2fbfb3SApril Chin *                  Common Public License, Version 1.0                  *
77c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
87c2fbfb3SApril Chin *                                                                      *
97c2fbfb3SApril Chin *                A copy of the License is available at                 *
107c2fbfb3SApril Chin *            http://www.opensource.org/licenses/cpl1.0.txt             *
117c2fbfb3SApril Chin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
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
317c2fbfb3SApril Chin #define _CMDARG_H
327c2fbfb3SApril Chin 
337c2fbfb3SApril Chin #define CMD_CHECKED	(1<<9)		/* cmdopen() argv[0] ok		*/
347c2fbfb3SApril Chin #define CMD_EMPTY	(1<<0)		/* run once, even if no args	*/
357c2fbfb3SApril Chin #define CMD_EXACT	(1<<1)		/* last command must have argmax*/
367c2fbfb3SApril Chin #define CMD_IGNORE	(1<<2)		/* ignore EXIT_QUIT exit	*/
377c2fbfb3SApril Chin #define CMD_INSERT	(1<<3)		/* argpat for insertion		*/
387c2fbfb3SApril Chin #define CMD_MINIMUM	(1<<4)		/* argmax is a minimum		*/
397c2fbfb3SApril Chin #define CMD_NEWLINE	(1<<5)		/* echo separator is newline	*/
407c2fbfb3SApril Chin #define CMD_POST	(1<<6)		/* argpat is post arg position	*/
417c2fbfb3SApril Chin #define CMD_QUERY	(1<<7)		/* trace and query each command	*/
427c2fbfb3SApril Chin #define CMD_SILENT	(1<<10)		/* no error messages		*/
437c2fbfb3SApril Chin #define CMD_TRACE	(1<<8)		/* trace each command		*/
447c2fbfb3SApril Chin 
457c2fbfb3SApril Chin #define CMD_USER	(1<<12)
467c2fbfb3SApril Chin 
477c2fbfb3SApril Chin typedef struct				/* cmd + args info		*/
487c2fbfb3SApril Chin {
497c2fbfb3SApril Chin 	struct
507c2fbfb3SApril Chin 	{
517c2fbfb3SApril Chin 	size_t		args;		/* total args			*/
527c2fbfb3SApril Chin 	size_t		commands;	/* total commands		*/
537c2fbfb3SApril Chin 	}		total;
547c2fbfb3SApril Chin 
557c2fbfb3SApril Chin 	int		argcount;	/* current arg count		*/
567c2fbfb3SApril Chin 	int		argmax;		/* max # args			*/
577c2fbfb3SApril Chin 	int		echo;		/* just an echo			*/
587c2fbfb3SApril Chin 	int		flags;		/* CMD_* flags			*/
597c2fbfb3SApril Chin 	int		insertlen;	/* strlen(insert)		*/
607c2fbfb3SApril Chin 	int		offset;		/* post arg offset		*/
617c2fbfb3SApril Chin 
627c2fbfb3SApril Chin 	char**		argv;		/* exec argv			*/
637c2fbfb3SApril Chin 	char**		firstarg;	/* first argv file arg		*/
647c2fbfb3SApril Chin 	char**		insertarg;	/* argv before insert		*/
657c2fbfb3SApril Chin 	char**		postarg;	/* start of post arg list	*/
667c2fbfb3SApril Chin 	char**		nextarg;	/* next argv file arg		*/
677c2fbfb3SApril Chin 	char*		nextstr;	/* next string ends before here	*/
687c2fbfb3SApril Chin 	char*		laststr;	/* last string ends before here	*/
697c2fbfb3SApril Chin 	char*		insert;		/* replace with current arg	*/
707c2fbfb3SApril Chin 	char		buf[1];		/* argv and arg buffer		*/
717c2fbfb3SApril Chin } Cmdarg_t;
727c2fbfb3SApril Chin 
737c2fbfb3SApril Chin #if _BLD_ast && defined(__EXPORT__)
747c2fbfb3SApril Chin #define extern		__EXPORT__
757c2fbfb3SApril Chin #endif
767c2fbfb3SApril Chin 
777c2fbfb3SApril Chin extern Cmdarg_t*	cmdopen(char**, int, int, const char*, int);
787c2fbfb3SApril Chin extern int		cmdflush(Cmdarg_t*);
797c2fbfb3SApril Chin extern int		cmdarg(Cmdarg_t*, const char*, int);
807c2fbfb3SApril Chin extern int		cmdclose(Cmdarg_t*);
817c2fbfb3SApril Chin 
827c2fbfb3SApril Chin #undef	extern
837c2fbfb3SApril Chin 
847c2fbfb3SApril Chin #endif
85