1 /*************************************************************************** 2 $RCSfile$ 3 ------------------- 4 cvs : $Id$ 5 begin : Sat Apr 24 2004 6 copyright : (C) 2004 by Martin Preuss 7 email : martin@libchipcard.de 8 9 *************************************************************************** 10 * * 11 * This library is free software; you can redistribute it and/or * 12 * modify it under the terms of the GNU Lesser General Public * 13 * License as published by the Free Software Foundation; either * 14 * version 2.1 of the License, or (at your option) any later version. * 15 * * 16 * This library is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 19 * Lesser General Public License for more details. * 20 * * 21 * You should have received a copy of the GNU Lesser General Public * 22 * License along with this library; if not, write to the Free Software * 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 24 * MA 02111-1307 USA * 25 * * 26 ***************************************************************************/ 27 28 #ifndef GWENHYWFAR_ARGS_H 29 #define GWENHYWFAR_ARGS_H 30 31 #include <gwenhywfar/gwenhywfarapi.h> 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 typedef struct GWEN_ARGS GWEN_ARGS; 37 #ifdef __cplusplus 38 } 39 #endif 40 41 #include <gwenhywfar/types.h> 42 #include <gwenhywfar/buffer.h> 43 #include <gwenhywfar/db.h> 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 50 #define GWEN_ARGS_FLAGS_HAS_ARGUMENT 0x00000001 51 #define GWEN_ARGS_FLAGS_LAST 0x00000002 52 #define GWEN_ARGS_FLAGS_HELP 0x00000004 53 54 #define GWEN_ARGS_MODE_ALLOW_FREEPARAM 0x00000001 55 #define GWEN_ARGS_MODE_STOP_AT_FREEPARAM 0x00000002 56 57 #define GWEN_ARGS_RESULT_ERROR (-1) 58 #define GWEN_ARGS_RESULT_HELP (-2) 59 60 61 typedef enum { 62 GWEN_ArgsType_Char=0, 63 GWEN_ArgsType_Int 64 } 65 GWEN_ARGS_TYPE; 66 67 typedef enum { 68 GWEN_ArgsOutType_Txt=0, 69 GWEN_ArgsOutType_Html 70 } GWEN_ARGS_OUTTYPE; 71 72 73 /** 74 * This is one of the very few structs inside Gwenhywfar whose 75 * contents are available for direct access to the the program. 76 * Developer's note: Please note that any change within this struct will 77 * make it necessary to increment the SO_VERSION of the library ! 78 */ 79 struct GWEN_ARGS { 80 uint32_t flags; 81 GWEN_ARGS_TYPE type; 82 const char *name; 83 unsigned int minNum; 84 unsigned int maxNum; 85 const char *shortOption; 86 const char *longOption; 87 const char *shortDescription; 88 const char *longDescription; 89 }; 90 91 92 /** 93 * This function parses the given argument list. 94 * Known options are stored within the given DB under their respective name. 95 * Free parameters (which are arguments without leading "-"'s) are stored in 96 * the variable "params" of the given db. 97 */ 98 GWENHYWFAR_API 99 int GWEN_Args_Check(int argc, char **argv, 100 int startAt, 101 uint32_t mode, 102 const GWEN_ARGS *args, 103 GWEN_DB_NODE *db); 104 105 /** Print a "usage" message into the given GWEN_BUFFER @c 106 * ubuf. The message lists all available options. The 107 * GWEN_ARGS_OUTTYPE argument is supposed to offer either text or 108 * html as output format, but currently only text is 109 * implemented. */ 110 GWENHYWFAR_API 111 int GWEN_Args_Usage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, 112 GWEN_ARGS_OUTTYPE ot); 113 114 /** Currently unimplemented; does nothing and returns zero. */ 115 GWENHYWFAR_API 116 int GWEN_Args_ShortUsage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, 117 GWEN_ARGS_OUTTYPE ot); 118 119 #ifdef __cplusplus 120 } 121 #endif 122 123 124 #endif /* GWENHYWFAR_ARGS_H */ 125 126 127 128