1290001Sglebius 2290001Sglebius/** 3290001Sglebius * \file alias.c 4290001Sglebius * 5290001Sglebius * Handle options that are aliases for another option. 6290001Sglebius * 7290001Sglebius * @addtogroup autoopts 8290001Sglebius * @{ 9290001Sglebius */ 10290001Sglebius/* 11290001Sglebius * This routine will forward an option alias to the correct option code. 12290001Sglebius * 13290001Sglebius * This file is part of AutoOpts, a companion to AutoGen. 14290001Sglebius * AutoOpts is free software. 15290001Sglebius * AutoOpts is Copyright (C) 1992-2015 by Bruce Korb - all rights reserved 16290001Sglebius * 17290001Sglebius * AutoOpts is available under any one of two licenses. The license 18290001Sglebius * in use must be one of these two and the choice is under the control 19290001Sglebius * of the user of the license. 20290001Sglebius * 21290001Sglebius * The GNU Lesser General Public License, version 3 or later 22290001Sglebius * See the files "COPYING.lgplv3" and "COPYING.gplv3" 23290001Sglebius * 24290001Sglebius * The Modified Berkeley Software Distribution License 25290001Sglebius * See the file "COPYING.mbsd" 26290001Sglebius * 27290001Sglebius * These files have the following sha256 sums: 28290001Sglebius * 29290001Sglebius * 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3 30290001Sglebius * 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3 31290001Sglebius * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd 32290001Sglebius */ 33290001Sglebius 34290001SglebiusLOCAL tSuccess 35290001Sglebiustoo_many_occurrences(tOptions * opts, tOptDesc * od) 36290001Sglebius{ 37290001Sglebius if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) { 38290001Sglebius char const * eqv = (od->optEquivIndex != NO_EQUIVALENT) ? zequiv : zNil; 39290001Sglebius 40290001Sglebius fprintf(stderr, ztoo_often_fmt, opts->pzProgName); 41290001Sglebius 42290001Sglebius if (od->optMaxCt > 1) 43290001Sglebius fprintf(stderr, zat_most, od->optMaxCt, od->pz_Name, eqv); 44290001Sglebius else 45290001Sglebius fprintf(stderr, zonly_one, od->pz_Name, eqv); 46290001Sglebius (*opts->pUsageProc)(opts, EXIT_FAILURE); 47290001Sglebius /* NOTREACHED */ 48290001Sglebius } 49290001Sglebius 50290001Sglebius return FAILURE; 51290001Sglebius} 52290001Sglebius 53290001Sglebius/*=export_func optionAlias 54290001Sglebius * private: 55290001Sglebius * 56290001Sglebius * what: relay an option to its alias 57290001Sglebius * arg: + tOptions * + opts + program options descriptor + 58290001Sglebius * arg: + tOptDesc * + old_od + the descriptor for this arg + 59290001Sglebius * arg: + unsigned int + alias + the aliased-to option index + 60290001Sglebius * ret-type: int 61290001Sglebius * 62290001Sglebius * doc: 63290001Sglebius * Handle one option as if it had been specified as another. Exactly. 64290001Sglebius * Returns "-1" if the aliased-to option has appeared too many times. 65290001Sglebius=*/ 66290001Sglebiusint 67290001SglebiusoptionAlias(tOptions * opts, tOptDesc * old_od, unsigned int alias) 68290001Sglebius{ 69290001Sglebius tOptDesc * new_od; 70290001Sglebius 71290001Sglebius if (opts <= OPTPROC_EMIT_LIMIT) 72290001Sglebius return 0; 73290001Sglebius 74290001Sglebius new_od = opts->pOptDesc + alias; 75290001Sglebius if ((unsigned)opts->optCt <= alias) { 76290001Sglebius fputs(zbad_alias_id, stderr); 77290001Sglebius option_exits(EXIT_FAILURE); 78290001Sglebius } 79290001Sglebius 80290001Sglebius /* 81290001Sglebius * Copy over the option instance flags 82290001Sglebius */ 83290001Sglebius new_od->fOptState &= OPTST_PERSISTENT_MASK; 84290001Sglebius new_od->fOptState |= (old_od->fOptState & ~OPTST_PERSISTENT_MASK); 85290001Sglebius new_od->optArg.argString = old_od->optArg.argString; 86290001Sglebius 87290001Sglebius /* 88290001Sglebius * Keep track of count only for DEFINED (command line) options. 89290001Sglebius * IF we have too many, build up an error message and bail. 90290001Sglebius */ 91290001Sglebius if ( (new_od->fOptState & OPTST_DEFINED) 92290001Sglebius && (++new_od->optOccCt > new_od->optMaxCt) ) 93290001Sglebius return too_many_occurrences(opts, new_od); 94290001Sglebius 95290001Sglebius /* 96290001Sglebius * Clear the state bits and counters 97290001Sglebius */ 98290001Sglebius old_od->fOptState &= OPTST_PERSISTENT_MASK; 99290001Sglebius old_od->optOccCt = 0; 100290001Sglebius 101290001Sglebius /* 102290001Sglebius * If there is a procedure to call, call it 103290001Sglebius */ 104290001Sglebius if (new_od->pOptProc != NULL) 105290001Sglebius (*new_od->pOptProc)(opts, new_od); 106290001Sglebius return 0; 107290001Sglebius} 108290001Sglebius 109290001Sglebius/** @} 110290001Sglebius * 111290001Sglebius * Local Variables: 112290001Sglebius * mode: C 113290001Sglebius * c-file-style: "stroustrup" 114290001Sglebius * indent-tabs-mode: nil 115290001Sglebius * End: 116290001Sglebius * end of autoopts/alias.c */ 117