Home | History | Annotate | Download | only in include
      1 /*---------------------------------------------------------------------------*
      2  *  duk_args.h  *
      3  *                                                                           *
      4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
      5  *                                                                           *
      6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
      7  *  you may not use this file except in compliance with the License.         *
      8  *                                                                           *
      9  *  You may obtain a copy of the License at                                  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
     11  *                                                                           *
     12  *  Unless required by applicable law or agreed to in writing, software      *
     13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
     15  *  See the License for the specific language governing permissions and      *
     16  *  limitations under the License.                                           *
     17  *                                                                           *
     18  *---------------------------------------------------------------------------*/
     19 
     20 
     21 
     22 #ifndef _h_arg_defs_
     23 #define _h_arg_defs_
     24 
     25 #ifdef SET_RCSID
     26 static const char duk_args_h[] = "$Id: duk_args.h,v 1.3.6.3 2007/08/31 17:44:52 dahan Exp $";
     27 #endif
     28 
     29 #include "all_defs.h"
     30 #ifndef _RTT
     31 #include "duk_io.h"
     32 #endif
     33 
     34 
     35 /* argument types */
     36 #define A_BOO 1  /* A boolean, switch */
     37 #define A_STR 2  /* A string */
     38 #define A_INT 3  /* An integer */
     39 #define A_FLT 4  /* A floating point number */
     40 #define A_FIL 5  /* A file name */
     41 #define A_LIS 6  /* A list of strings */
     42 
     43 #define A_TYP_MASK 0x0f
     44 #define A_TYP(X)        (A_TYP_MASK & (X))
     45 
     46 /* Array flag */
     47 #define A_ARRAY  0x10
     48 #define A_IF_ARRAY(X) (A_ARRAY & (X))
     49 
     50 /* Mandatory arguments info */
     51 #define A_MAND  0x20
     52 #define A_IF_MAND(X) (A_MAND & (X))
     53 
     54 /* flagless arguments */
     55 #define A_NOF  0x40
     56 #define A_IF_NOF(X) (A_NOF & (X))
     57 
     58 /* private info */
     59 #define A_SET  0x80
     60 #define A_IF_SET(X) (A_SET & (X))
     61 
     62 /**
     63  * @todo document
     64  */
     65 typedef union
     66 {
     67   char   *a_string;
     68   int   *a_int;
     69   float  *a_float;
     70 #ifndef _RTT
     71   PFile** a_file;
     72 #endif
     73   char  **a_list;
     74 }
     75 arg_name;
     76 
     77 typedef struct
     78 {
     79   int   typ;
     80   char  *flag;
     81   int   max_args;
     82   arg_name  name;
     83   char  *def;
     84 }
     85 arg_info;
     86 
     87 #define SET_ARG_ENTRY(A,W,X,Y,Z) ((A)->typ=(W), (A)->flag=(X), (A)->name.a_string=(Y), (A)->max_args=1, (A)->def=(Z))
     88 #define SET_ARRAY_ARG_ENTRY(A,W,X,Y,N,Z) ((A)->typ=((W)|A_ARRAY), (A)->flag=(X), (A)->name.a_string=(Y), (A)->max_args=(N), (A)->def=(Z))
     89 
     90 int  parse_single_argument(arg_info *avlist, int avc, char *key, char *value,
     91                            int count, int override, int *success);
     92 int  get_single_argument(arg_info *avlist, int avc, char *key, void *value,
     93                          unsigned long *valueLen, int typ);
     94 int get_string_argument(arg_info *avlist, int avc, char *key, char *value, int valueLen, int *bytes_required, int typ);
     95 #ifdef __cplusplus
     96 extern "C"
     97 {
     98 #endif
     99   int  com_arg_parse(int argc, char **argv, int avc, arg_info *avlist,
    100                      char *module);
    101 #ifdef __cplusplus
    102 }
    103 #endif
    104 int  get_arginfo_flags(arg_info *arglist, int argc, char buffer[], int buflen);
    105 int  is_flag_assigned(char *pattern, int avc, arg_info *avlist);
    106 void help_line(char *problem, int avc, arg_info *avlist);
    107 void statement(char *descinfo);
    108 
    109 #ifndef _RTT
    110 int  resource_arg_parse(const char *resname, char *module, int avc,
    111                         arg_info *avlist);
    112 void save_parsed_args(const char *resname, char *module, int avc,
    113                       arg_info *avlist);
    114 #endif  /* _RTT */
    115 
    116 typedef struct
    117 {
    118   int  value;
    119   char  *entry;
    120 }
    121 list_item;
    122 
    123 int lookup_list(list_item *list_data, int nlist, char *key);
    124 
    125 #endif /* _h_arg_defs_ */
    126