/* validateOptionsStruct * * Make sure the option descriptor is there and that we understand it. * This should be called from any user entry point where one needs to * worry about validity. (Some entry points are free to assume that * the call is not the first to the library and, thus, that this has * already been called.) */ LOCAL tSuccess validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) { if (pOpts == NULL) { fputs( zAO_Bad, stderr ); exit( EX_CONFIG ); } /* * IF the client has enabled translation and the translation procedure * is available, then go do it. */ if ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0) && (pOpts->pTransProc != 0) ) { (*pOpts->pTransProc)(); pOpts->fOptSet &= ~OPTPROC_TRANSLATE; } /* * IF the struct version is not the current, and also * either too large (?!) or too small, * THEN emit error message and fail-exit */ if ( ( pOpts->structVersion != OPTIONS_STRUCT_VERSION ) && ( (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) || (pOpts->structVersion < OPTIONS_MINIMUM_VERSION ) ) ) { fprintf( stderr, zAO_Err, pOpts->origArgVect[0], NUM_TO_VER( pOpts->structVersion )); if (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) fputs( zAO_Big, stderr ); else fputs( zAO_Sml, stderr ); return FAILURE; } /* * If the program name hasn't been set, then set the name and the path * and the set of equivalent characters. */ if (pOpts->pzProgName == NULL) { char const* pz = strrchr( pzProgram, DIRCH ); if (pz == NULL) pOpts->pzProgName = pzProgram; else pOpts->pzProgName = pz+1; pOpts->pzProgPath = pzProgram; /* * when comparing long names, these are equivalent */ strequate( zSepChars ); } return SUCCESS; }
/** * Make sure the option descriptor is there and that we understand it. * This should be called from any user entry point where one needs to * worry about validity. (Some entry points are free to assume that * the call is not the first to the library and, thus, that this has * already been called.) * * Upon successful completion, pzProgName and pzProgPath are set. * * @param[in,out] opts program options descriptor * @param[in] pname name of program, from argv[] * @returns SUCCESS or FAILURE */ LOCAL tSuccess validate_struct(tOptions * opts, char const * pname) { if (opts == NULL) { fputs(zno_opt_arg, stderr); return FAILURE; } print_exit = ((opts->fOptSet & OPTPROC_SHELL_OUTPUT) != 0); /* * IF the client has enabled translation and the translation procedure * is available, then go do it. */ if ( ((opts->fOptSet & OPTPROC_TRANSLATE) != 0) && (opts->pTransProc != NULL) && (option_xlateable_txt.field_ct != 0) ) { /* * If option names are not to be translated at all, then do not do * it for configuration parsing either. (That is the bit that really * gets tested anyway.) */ if ((opts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT) opts->fOptSet |= OPTPROC_NXLAT_OPT_CFG; (*opts->pTransProc)(); } /* * IF the struct version is not the current, and also * either too large (?!) or too small, * THEN emit error message and fail-exit */ if ( ( opts->structVersion != OPTIONS_STRUCT_VERSION ) && ( (opts->structVersion > OPTIONS_STRUCT_VERSION ) || (opts->structVersion < OPTIONS_MINIMUM_VERSION ) ) ) { static char const ao_ver_string[] = STR(AO_CURRENT)":"STR(AO_REVISION)":"STR(AO_AGE)"\n"; fprintf(stderr, zwrong_ver, pname, NUM_TO_VER(opts->structVersion)); if (opts->structVersion > OPTIONS_STRUCT_VERSION ) fputs(ztoo_new, stderr); else fputs(ztoo_old, stderr); fwrite(ao_ver_string, sizeof(ao_ver_string) - 1, 1, stderr); return FAILURE; } /* * If the program name hasn't been set, then set the name and the path * and the set of equivalent characters. */ if (opts->pzProgName == NULL) { char const * pz = strrchr(pname, DIRCH); char const ** pp = (char const **)(void **)(intptr_t)&(opts->pzProgName); if (pz != NULL) *pp = pz+1; else *pp = pname; pz = pathfind(getenv("PATH"), (char *)(intptr_t)pname, "rx"); if (pz != NULL) pname = (void *)(intptr_t)pz; pp = (char const **)(void **)(intptr_t)&(opts->pzProgPath); *pp = pname; /* * when comparing long names, these are equivalent */ strequate(zSepChars); } return SUCCESS; }
/** * Make sure the option descriptor is there and that we understand it. * This should be called from any user entry point where one needs to * worry about validity. (Some entry points are free to assume that * the call is not the first to the library and, thus, that this has * already been called.) */ LOCAL tSuccess validateOptionsStruct(tOptions* pOpts, char const* pzProgram) { if (pOpts == NULL) { fputs(zAO_Bad, stderr); exit(EX_CONFIG); } /* * IF the client has enabled translation and the translation procedure * is available, then go do it. */ if ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0) && (pOpts->pTransProc != NULL) ) { /* * If option names are not to be translated at all, then do not do * it for configuration parsing either. (That is the bit that really * gets tested anyway.) */ if ((pOpts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT) pOpts->fOptSet |= OPTPROC_NXLAT_OPT_CFG; (*pOpts->pTransProc)(); pOpts->fOptSet &= ~OPTPROC_TRANSLATE; } /* * IF the struct version is not the current, and also * either too large (?!) or too small, * THEN emit error message and fail-exit */ if ( ( pOpts->structVersion != OPTIONS_STRUCT_VERSION ) && ( (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) || (pOpts->structVersion < OPTIONS_MINIMUM_VERSION ) ) ) { fprintf(stderr, zAO_Err, pzProgram, NUM_TO_VER(pOpts->structVersion)); if (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) fputs(zAO_Big, stderr); else fputs(zAO_Sml, stderr); fputs(ShellAsString(AO_CURRENT) ":" ShellAsString(AO_REVISION) ":" ShellAsString(AO_AGE) "\n", stderr); return FAILURE; } /* * If the program name hasn't been set, then set the name and the path * and the set of equivalent characters. */ if (pOpts->pzProgName == NULL) { char const * pz = strrchr(pzProgram, DIRCH); char const ** pp = (char const **)(void **)&(pOpts->pzProgName); if (pz == NULL) *pp = pzProgram; else *pp = pz+1; pp = (char const **)(void **)&(pOpts->pzProgPath); *pp = pzProgram; /* * when comparing long names, these are equivalent */ strequate(zSepChars); } return SUCCESS; }