home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / HARDDISK / BADCLU.ZIP / INC.ZIP / GETARGS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-15  |  2.2 KB  |  88 lines

  1. /*------------------------------------------------------------
  2.  * 
  3.  *  getargs.h
  4.  * 
  5.  *  defs for getargs()
  6.  * 
  7.  *  by J. Alan Eldridge
  8.  *
  9.  *  this code is placed in the public domain
  10.  *  
  11.  *  jae ???         created
  12.  *  jae 07/28/89    added ARG_FOUND bitmask
  13.  *  jae 04/09/90    added multi-char options, validation functions
  14.  *  
  15.  *----------------------------------------------------------*/
  16.  
  17. #ifndef __GETARGS__
  18.  
  19. #define __GETARGS__
  20.  
  21. /* ARGUMENT TYPES */
  22.  
  23. #define ARG_BOOL    0x01    /* arg is boolean */
  24. #define ARG_INT     0x02    /* arg is integer */
  25. #define ARG_STR     0x04    /* arg is string */
  26.  
  27. /* FLAGS */
  28.  
  29. #define ARG_FOUND   0x40    /* internal, so each args occurs <= 1 time */
  30. #define ARG_REQD    0x80    /* says arg must be found or it's an error */
  31.  
  32. #define ARG_IP(vp)  ((int*)(vp))
  33. #define ARG_CPP(vp) ((char**)(vp))
  34.  
  35. typedef int (*ARG_FUNC)();
  36.  
  37. typedef struct {
  38.     char    *optstr;    /* option string e.g., -pr (case sens.) */
  39.     int     argtype;    /* type of arg: bool, int, or string */
  40.                         /* may have ARG_REQD or'ed in to indicate */
  41.                         /* that the arg's absence is an error */
  42.     void    *ptr;       /* pointer to loc'n to recieve value */
  43.                         /* for ints & bools, ptr to int ... */
  44.                         /* for strings, ptr to ptr to char */
  45.     ARG_FUNC    valfun; /* validation function, 0 == OK, -1 == error */
  46. } CMD_ARG;
  47.  
  48. #define ARG_CNT(arg_arr)    (sizeof(arg_arr)/sizeof(CMD_ARG))
  49.  
  50. #define ARG_NOFUNC  ((ARG_FUNC)0)
  51.  
  52. #ifndef NO_PROTO
  53.  
  54. int getargs(
  55.     int             *argc_ptr,
  56.     char            **argv_ptr,
  57.     int             num_args,
  58.     CMD_ARG         arg_list[]);
  59.  
  60. int _getargs(
  61.     int             *argc_ptr,
  62.     char            **argv_ptr,
  63.     int             num_args,
  64.     CMD_ARG         arg_list[],
  65.     int             ignorebad);
  66.  
  67. int show_txt_w_pause(
  68.     char    **msg_arr,
  69.     int     nlines);
  70.  
  71. void usage(
  72.     char    **msg_arr,
  73.     int     nlines,
  74.     int     ecode);
  75.  
  76. int argfound(
  77.     CMD_ARG *arr,
  78.     int     nopts,
  79.     char    *opt);
  80.  
  81. void argfixbl(
  82.     char    *str,
  83.     int     c);
  84.  
  85. #endif
  86.  
  87. #endif
  88.