1 /* $XConsortium: getopts.c /main/3 1995/11/01 16:28:23 rswiston $ */
2 /***************************************************************
6 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF *
7 * AT&T BELL LABORATORIES *
8 * AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN *
9 * ACCORDANCE WITH APPLICABLE AGREEMENTS *
11 * Copyright (c) 1995 AT&T Corp. *
12 * Unpublished & Not for Publication *
13 * All Rights Reserved *
15 * The copyright notice above does not evidence any *
16 * actual or intended publication of such source code *
18 * This software was created by the *
19 * Advanced Software Technology Department *
20 * AT&T Bell Laboratories *
22 * For further information contact *
23 * {research,attmail}!dgk *
25 ***************************************************************/
27 /* : : generated by proto : : */
29 #if !defined(__PROTO__)
30 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
31 #if defined(__cplusplus)
32 #define __MANGLE__ "C"
37 #define __PROTO__(x) x
39 #define __PARAM__(n,o) n
40 #if !defined(__STDC__) && !defined(__cplusplus)
41 #if !defined(c_plusplus)
52 #define __PROTO__(x) ()
53 #define __OTORP__(x) x
54 #define __PARAM__(n,o) o
62 #if defined(__cplusplus) || defined(c_plusplus)
63 #define __VARARG__ ...
67 #if defined(__STDARG__)
68 #define __VA_START__(p,a) va_start(p,a)
70 #define __VA_START__(p,a) va_start(p)
74 #include <machine/machlimits.h>
77 #include "variables.h"
82 int b_getopts __PARAM__((int argc,char *argv[],__V_ *extra), (argc, argv, extra)) __OTORP__(int argc;char *argv[];__V_ *extra;){
83 register char *options=error_info.context->id;
84 register Namval_t *np;
85 register int flag, mode, r=0;
86 static char value[2], key[2];
88 while((flag = optget(argv,sh_optgetopts))) switch(flag)
97 error(ERROR_usage(2), opt_arg);
102 if(error_info.errors || argc<2)
103 error(ERROR_usage(2),optusage((char*)0));
104 error_info.context->flags |= ERROR_SILENT;
105 error_info.id = options;
107 np = nv_open(argv[1],sh.var_tree,NV_NOASSIGN|NV_VARNAME);
118 opt_index = sh.st.optindex;
119 opt_char = sh.st.optchar;
120 if(mode= (*options==':'))
122 switch(opt_index<=argc?(opt_num= LONG_MIN,flag=optget(argv,options)):0)
125 error(ERROR_usage(0),opt_arg);
127 *(options = value) = flag;
130 key[0] = opt_option[1];
131 if(strmatch(opt_arg,"*unknown*"))
141 *(options = value) = flag;
154 if(!mode && strchr(options,' '))
155 error(ERROR_usage(0),optusage((char*)0));
164 options = opt_option + (*opt_option!='+');
166 error_info.context->flags &= ~ERROR_SILENT;
167 sh.st.optindex = opt_index;
168 sh.st.optchar = opt_char;
169 nv_putval(np, options, 0);
171 np = nv_search((char*)OPTARGNOD,sh.var_tree,NV_ADD|HASH_BUCKET|HASH_NOSCOPE);
172 if(opt_num != LONG_MIN)
175 nv_putval(np, (char*)&d, NV_INTEGER|NV_RDONLY);
178 nv_putval(np, opt_arg, NV_RDONLY);