numeric.c revision 181834
1142425Snectar 2160814Ssimon/* 3142425Snectar * $Id: numeric.c,v 4.11 2007/02/04 17:44:12 bkorb Exp $ 4142425Snectar * Time-stamp: "2007-01-13 10:28:20 bkorb" 5142425Snectar */ 6142425Snectar 7142425Snectar/* 8142425Snectar * Automated Options copyright 1992-2007 Bruce Korb 9142425Snectar * 10142425Snectar * Automated Options is free software. 11142425Snectar * You may redistribute it and/or modify it under the terms of the 12142425Snectar * GNU General Public License, as published by the Free Software 13142425Snectar * Foundation; either version 2, or (at your option) any later version. 14142425Snectar * 15142425Snectar * Automated Options is distributed in the hope that it will be useful, 16142425Snectar * but WITHOUT ANY WARRANTY; without even the implied warranty of 17142425Snectar * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18142425Snectar * GNU General Public License for more details. 19142425Snectar * 20142425Snectar * You should have received a copy of the GNU General Public License 21142425Snectar * along with Automated Options. See the file "COPYING". If not, 22142425Snectar * write to: The Free Software Foundation, Inc., 23142425Snectar * 51 Franklin Street, Fifth Floor, 24142425Snectar * Boston, MA 02110-1301, USA. 25142425Snectar * 26142425Snectar * As a special exception, Bruce Korb gives permission for additional 27142425Snectar * uses of the text contained in his release of AutoOpts. 28142425Snectar * 29142425Snectar * The exception is that, if you link the AutoOpts library with other 30142425Snectar * files to produce an executable, this does not by itself cause the 31142425Snectar * resulting executable to be covered by the GNU General Public License. 32142425Snectar * Your use of that executable is in no way restricted on account of 33142425Snectar * linking the AutoOpts library code into it. 34142425Snectar * 35142425Snectar * This exception does not however invalidate any other reasons why 36142425Snectar * the executable file might be covered by the GNU General Public License. 37142425Snectar * 38142425Snectar * This exception applies only to the code released by Bruce Korb under 39142425Snectar * the name AutoOpts. If you copy code from other sources under the 40142425Snectar * General Public License into a copy of AutoOpts, as the General Public 41142425Snectar * License permits, the exception does not apply to the code that you add 42142425Snectar * in this way. To avoid misleading anyone as to the status of such 43142425Snectar * modified files, you must delete this exception notice from them. 44142425Snectar * 45142425Snectar * If you write modifications of your own for AutoOpts, it is your choice 46142425Snectar * whether to permit this exception to apply to your modifications. 47142425Snectar * If you do not wish that, delete this exception notice. 48142425Snectar */ 49142425Snectar 50142425Snectar/*=export_func optionNumericVal 51160814Ssimon * private: 52160814Ssimon * 53142425Snectar * what: Decipher a boolean value 54142425Snectar * arg: + tOptions* + pOpts + program options descriptor + 55142425Snectar * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + 56142425Snectar * 57142425Snectar * doc: 58142425Snectar * Decipher a numeric value. 59142425Snectar=*/ 60142425Snectarvoid 61142425SnectaroptionNumericVal( tOptions* pOpts, tOptDesc* pOD ) 62142425Snectar{ 63142425Snectar char* pz; 64142425Snectar long val; 65142425Snectar 66142425Snectar /* 67160814Ssimon * Numeric options may have a range associated with it. 68142425Snectar * If it does, the usage procedure requests that it be 69142425Snectar * emitted by passing a NULL pOD pointer. 70142425Snectar */ 71142425Snectar if ((pOD == NULL) || (pOD->optArg.argString == NULL)) 72142425Snectar return; 73142425Snectar 74142425Snectar val = strtol( pOD->optArg.argString, &pz, 0 ); 75142425Snectar if (*pz != NUL) { 76142425Snectar fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString ); 77142425Snectar (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); 78142425Snectar } 79142425Snectar 80142425Snectar if (pOD->fOptState & OPTST_ALLOC_ARG) { 81142425Snectar AGFREE(pOD->optArg.argString); 82142425Snectar pOD->fOptState &= ~OPTST_ALLOC_ARG; 83142425Snectar } 84160814Ssimon 85160814Ssimon pOD->optArg.argInt = val; 86160814Ssimon} 87142425Snectar/* 88142425Snectar * Local Variables: 89142425Snectar * mode: C 90142425Snectar * c-file-style: "stroustrup" 91142425Snectar * indent-tabs-mode: nil 92160814Ssimon * End: 93160814Ssimon * end of autoopts/numeric.c */ 94160814Ssimon