2 * Copyright 1993, 1995 Christopher Seiwald.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * option.c - command line option processing
11 * \<>) "Process command line options as defined in <option.h>.
12 * Return the number of argv[] elements used up by options,
13 * or -1 if an invalid option flag was given or an argument
14 * was supplied for an option that does not require one."
16 * 11/04/02 (seiwald) - const-ing for string literals
33 memset( (char *)optv
, '\0', sizeof( *optv
) * N_OPTS
);
36 for( i
= 0; i
< argc
; i
++ )
40 if ( argv
[i
][0] == '-' )
44 printf( "too many options (%d max)\n", N_OPTS
);
48 for( arg
= &argv
[i
][1]; *arg
; arg
++ )
52 for( f
= opts
; *f
; f
++ )
58 printf( "Invalid option: -%c\n", *arg
);
70 optv
++->val
= &arg
[1];
75 optv
++->val
= argv
[i
];
80 printf( "option: -%c needs argument\n", *f
);
87 /* something like VARNAME=.... is treated as an implicit '-s' flag */
88 if ( argv
[i
][0] != '=' && strchr( argv
[i
],'=' ) )
92 printf( "too many options (%d max)\n", N_OPTS
);
97 optv
++->val
= argv
[i
];
101 if ( n
>= N_TARGETS
)
103 printf( "too many targets (%d max)\n", N_TARGETS
);
106 targets
[n
++] = argv
[i
];
115 * Name: getoptval() - find an option given its character
126 for( i
= 0; i
< N_OPTS
; i
++, optv
++ )
127 if( optv
->flag
== opt
&& !subopt
-- )