/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */ /* * option.c - command line option processing * * {o >o * \<>) "Process command line options as defined in <option.h>. * Return the number of argv[] elements used up by options, * or -1 if an invalid option flag was given or an argument * was supplied for an option that does not require one." * * 11/04/02 (seiwald) - const-ing for string literals */ # include "jam.h" # include "option.h" int getoptions( int argc, char **argv, const char *opts, option *optv ) { int i; int optc = N_OPTS; memset( (char *)optv, '\0', sizeof( *optv ) * N_OPTS ); for( i = 0; i < argc; i++ ) { char *arg; if( argv[i][0] != '-' || !isalpha( argv[i][1] ) ) break; if( !optc-- ) { printf( "too many options (%d max)\n", N_OPTS ); return -1; } for( arg = &argv[i][1]; *arg; arg++ ) { const char *f; for( f = opts; *f; f++ ) if( *f == *arg ) break; if( !*f ) { printf( "Invalid option: -%c\n", *arg ); return -1; } optv->flag = *f; if( f[1] != ':' ) { optv++->val = "true"; } else if( arg[1] ) { optv++->val = &arg[1]; break; } else if( ++i < argc ) { optv++->val = argv[i]; break; } else { printf( "option: -%c needs argument\n", *f ); return -1; } } } return i; } /* * Name: getoptval() - find an option given its character */ const char * getoptval( option *optv, char opt, int subopt ) { int i; for( i = 0; i < N_OPTS; i++, optv++ ) if( optv->flag == opt && !subopt-- ) return optv->val; return 0; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 26290 | Joel Van Eenwyk | "Forking branch main of perforce_software-jam to joel_van_eenwyk-jam." | ||
//guest/perforce_software/jam/src/option.c | |||||
#4 | 2493 | rmg |
Rewrite the past: update all jam's source with comments to reflect changes since about 2.3, very early 2001. Whitespace only change. === computer:1666: Change 37660 by seiwald@play-seiwald on 2002/11/06 22:41:35 Note: I regenerated jamgram.c on my linux 7.3 system prior to the submit, since patch was so unhappy trying to lay down the changes from Christopher's change. Presumably this is just due to different yacc/bison/whatever particulars on the system where Christopher made the changes originally. - rmg |
||
#3 | 2491 | rmg |
Some consting in jam to make it more compilable by C++ compilers. No functional change. === computer:1666: Change 37433 by perforce@perforce on 2002/10/30 16:08:51 Recreational const-ing of jam, for compilers that don't allow "string" to be passed as a non-const char *. This included a few places where we were modifying what could possibly have been read-only storage, oddly enough. No functional change. === computer:1666: Change 37602 by seiwald@play-seiwald on 2002/11/04 17:25:40 |
||
#2 | 486 | Perforce staff |
Jam 2.3. See RELNOTES for a list of changes from 2.2.x. Just about every source file was touched when jam got ANSI-fied. |
||
#1 | 2 | laura | Add Jam/MR 2.2 source |