Home Libraries Author Links

getopts.h

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the SysToMath C Libraries package (LibStmC).
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Tom Michaelis, SysToMath.
00018  * Portions created by the Initial Developer are Copyright (C) 1992-2006
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /******************************************************************************
00038  *                       First Release 1992-10-17
00039  ******************************************************************************/
00040 
00041 
00077 #ifndef STM_GETOPTS_H
00078 #define STM_GETOPTS_H
00079 
00080 
00081 #ifdef __cplusplus
00082    extern "C" {
00083 #endif
00084 
00085 
00086 #include <stdio.h>
00087 #include <stm/basetype.h>
00088 
00089 
00160 StmAbstractType (StmCmdLine)  /* CmdLine */
00161 
00162 
00163 
00167 enum StmCmdOptSpecFlags
00168 {
00169     StmCmdOptSpecHasArg         = 0x00000001,  
00171     StmCmdOptSpecRequiresArg    = 0x00000003,  
00173     StmCmdOptSpecArgsEnvOption  = 0x00000004,  
00176     StmCmdOptSpecArgsFromOption = 0x00000008,  
00178     StmCmdOptSpecFirstOption    = 0x00000010,  
00180     StmCmdOptSpecLastOption     = 0x00000020,  
00182     StmCmdOptSpecOnlyOption     = 0x00000030,  
00184 };
00185 
00186 
00189 typedef struct StmCmdOptSpec StmCmdOptSpec;
00190 
00191 
00198 struct StmCmdOptSpec
00199 {
00205     StmDword id;
00206 
00213     const char *names;
00214 
00220     StmDword flags;
00221 };
00222 
00223 
00262 StmDllSpec
00263 StmCmdLine stmCmdLineCreate (int argc, const char **argv,
00264                              const StmCmdOptSpec *optSpec);
00265 
00266 
00278 StmDllSpec
00279 void stmCmdLineDestroy (StmCmdLine cmdLine);
00280 
00281 
00293 enum StmCmdLineFlags
00294 {
00298     StmCmdLineAllowDirectlyFollowingOptArgs = 0x00000001
00299 };
00300 
00301 
00314 StmDllSpec
00315 StmDword stmCmdLineGetFlags (StmCmdLine cmdLine);
00316 
00317 
00334 StmDllSpec
00335 int stmCmdLineSetFlags (StmCmdLine cmdLine, StmDword flags);
00336 
00337 
00343 enum StmCmdLineErrors
00344 {
00345     StmCmdLineSystemError    = -1,   
00346     StmCmdLineOk             =  0,   
00347     StmCmdLineOptionError    =  1,   
00348     StmCmdLineOptionArgError =  2,   
00349     StmCmdLineArgumentError  =  3,   
00350     StmCmdLineWrongUsage     =  4    
00351 };
00352 
00353 
00359 #define stmCmdLineGetOpterr stmCmdLineGetError
00360 
00361 
00375 StmDllSpec
00376 int stmCmdLineGetError (StmCmdLine cmdLine);
00377 
00378 
00384 #define stmCmdLineSetOpterr stmCmdLineSetError
00385 
00386 
00407 StmDllSpec
00408 int stmCmdLineSetError (StmCmdLine cmdLine, int error);
00409 
00410 
00423 StmDllSpec
00424 const char *stmCmdLineGetErrbuf (StmCmdLine cmdLine);
00425 
00426 
00446 StmDllSpec
00447 int stmCmdLinePrintfErrbuf (StmCmdLine cmdLine, const char *format, ...);
00448 
00449 
00468 StmDllSpec
00469 FILE *stmCmdLineGetErrfp (StmCmdLine cmdLine);
00470 
00471 
00493 StmDllSpec
00494 int stmCmdLineSetErrfp (StmCmdLine cmdLine, FILE *errfp);
00495 
00496 
00517 StmDllSpec
00518 StmDword stmCmdLineGetFirstOptionId (StmCmdLine cmdLine);
00519 
00520 
00534 StmDllSpec
00535 StmDword stmCmdLineGetCurrentOptionId (StmCmdLine cmdLine);
00536 
00537 
00558 StmDllSpec
00559 StmDword stmCmdLineGetNextOptionId (StmCmdLine cmdLine);
00560 
00561 
00575 StmDllSpec
00576 const char *stmCmdLineGetProg (StmCmdLine cmdLine);
00577 
00578 
00592 StmDllSpec
00593 size_t stmCmdLineGetCurrentArgIndex (StmCmdLine cmdLine);
00594 
00595 
00609 StmDllSpec
00610 size_t stmCmdLineGetCurrentOptionIndex (StmCmdLine cmdLine);
00611 
00612 
00626 StmDllSpec
00627 const char *stmCmdLineGetCurrentOptionName (StmCmdLine cmdLine);
00628 
00629 
00647 StmDllSpec
00648 const char *stmCmdLineGetCurrentOptionArg (StmCmdLine cmdLine);
00649 
00650 
00664 StmDllSpec
00665 size_t stmCmdLineGetArgCount (StmCmdLine cmdLine);
00666 
00667 
00688 StmDllSpec
00689 const char *stmCmdLineGetArg (StmCmdLine cmdLine, size_t argIndex);
00690 
00691 
00740 StmDllSpec
00741 int stmPrintManText (FILE *fp, int width, const char *text);
00742 
00743 
00769 StmDllSpec
00770 int stmPrintManualHeader (FILE *fp, int width,
00771                           const char *version,
00772                           int dim, const char **man);
00773 
00774 
00797 StmDllSpec
00798 int stmPrintManualFooter (FILE *fp, int width, int indent,
00799                           const char *copyRight);
00800 
00801 
00827 StmDllSpec
00828 int stmPrintOptionHelp (FILE *fp, int width,
00829                         const char *optionName,
00830                         int dim, const char **man);
00831 
00832 
00858 StmDllSpec
00859 int stmPrintManualSection (FILE *fp, int width,
00860                            const char *sectionName,
00861                            int dim, const char **man);
00862 
00863 
00886 StmDllSpec
00887 int stmPrintSynopsis (FILE *fp, int width, int dim, const char **man);
00888 
00889 
00917 StmDllSpec
00918 int stmPrintManual (FILE *fp, int width,
00919                     const char *version, const char *copyRight,
00920                     int dim, const char **man);
00921 
00922 
00938 enum StmGetoptsErrnos
00939 {
00940     StmGetoptsSystemError    = -1,   
00941     StmGetoptsOk             =  0,   
00942     StmGetoptsOptionError    =  1,   
00943     StmGetoptsOptionArgError =  2,   
00944     StmGetoptsArgumentError  =  3,   
00945     StmGetoptsWrongUsage     =  4    
00946 };
00947 
00948 
00954 enum StmGetoptsResults
00955 {
00956     StmGetoptsQuestion = (int) '?',  
00957     StmGetoptsEnd      = EOF         
00958 };
00959 
00960 
00968 StmDllSpec
00969 extern const char *stmGetoptsProg;
00970 
00971 
00979 StmDllSpec
00980 extern const char *stmGetoptsOptarg;
00981 
00982 
00990 StmDllSpec
00991 extern int stmGetoptsOptind;
00992 
00993 
01001 StmDllSpec
01002 extern int stmGetoptsOpterr;
01003 
01004 
01013 StmDllSpec
01014 extern char *stmGetoptsErrbuf;
01015 
01016 
01025 StmDllSpec
01026 extern FILE *stmGetoptsOptfp;
01027 
01028 
01039 StmDllSpec
01040 extern StmBool stmGetoptsStrict;
01041 
01042 
01097 StmDllSpec
01098 int stmGetopts (int argc, const char **argv, const char *optSpec);
01099 
01100 
01125 StmDllSpec
01126 int stmFprintfStrArray (FILE *fp, int width, int dim, const char **strArray);
01127 
01128 
01132 #ifdef __cplusplus
01133   }
01134 #endif
01135 
01136 
01137 #endif

© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).