home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 14 / MA_Cover_14.iso / source / c / pegase_src / argscontrolclass.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-07  |  4.7 KB  |  163 lines

  1. #ifndef _ARGSCONTROL_CLASS_HPP
  2. #define _ARGSCONTROL_CLASS_HPP 1
  3.  
  4. /*
  5. **
  6. ** ArgsControlClass.hpp
  7. **
  8. ** (c) 1998 Didier Levet
  9. **
  10. ** $Revision: 1.3 $
  11. ** $State: Exp $
  12. ** $Date: 1998/10/21 13:52:58 $
  13. **
  14. ** $Log: ArgsControlClass.hpp $
  15. ** Revision 1.3  1998/10/21 13:52:58  kakace
  16. ** Use CStrArray class for ToolTypes strings
  17. **
  18. ** Revision 1.2  1998/10/17 16:22:05  kakace
  19. ** *** empty log message ***
  20. **
  21. ** Revision 1.1  1998/10/03 14:29:23  kakace
  22. ** Initial revision
  23. **
  24. **
  25. */
  26.  
  27. //----------------------------------------------------------------------------------------------------
  28.  
  29. /// Includes
  30.  
  31. #ifndef  _INCLUDE_STDDEF_H
  32. #include <stddef.h>
  33. #endif
  34.  
  35. #ifndef  DOS_RDARGS_H
  36. #include <dos/rdargs.h>
  37. #endif
  38.  
  39. #ifndef  UTILITY_TAGITEM_H
  40. #include <Utility/TagItem.h>
  41. #endif
  42.  
  43. #ifndef  CLIB_DOS_PROTOS_H
  44. #include <clib/dos_protos.h>
  45. #endif
  46.  
  47. #ifndef  CLIB_ICON_PROTOS_H
  48. #include <clib/icon_protos.h>
  49. #endif
  50.  
  51. #ifndef  WORKBENCH_WORKBENCH_H
  52. #include <Workbench/Workbench.h>
  53. #endif
  54.  
  55. #ifndef  _AMIGAOS_HPP
  56. #include "AmigaOS.hpp"
  57. #endif
  58.  
  59. #ifndef  _STRING_CLASS_HPP
  60. #include "StringClass.hpp"
  61. #endif
  62.  
  63. ///
  64.  
  65.  
  66. //----------------------------------------------------------------------------------------------------
  67. //=========================================== Args control ===========================================
  68. //----------------------------------------------------------------------------------------------------
  69.  
  70. #ifndef STRING
  71. typedef const char *STRING;
  72. #endif
  73.  
  74.  
  75. struct CArgsControl { STRING    pcArgName;        // Identifier
  76.                       STRING    pcCLIModifier;    // CLI (ReadArgs) modifier
  77.                       UWORD     wOffset;
  78.                       UBYTE     bArgType;
  79.                       UBYTE     bArgFlags;
  80.                       LONG      iDefaultValue;
  81.                       LONG      iControl;         // Lower bound, or pointer
  82.                       LONG      iUpperBound;
  83.                     };
  84.  
  85. // Arg types :
  86.  
  87. enum EArgType  {ARG_STRING, ARG_STRING_ARRAY, ARG_NUMBER, ARG_BOOL};
  88.  
  89.  
  90. // Arg flags :
  91.  
  92. #define ARGF_CLI             1          // Valid as CLI parameter.
  93. #define ARGF_WB             (1 << 1)    // Valid as ToolType
  94. #define ARGF_DEFAULTVALUE   (1 << 2)    // Use default value.
  95. #define ARGF_CHECKLIMITS    (1 << 3)    // iControl = Lower bound.
  96. //#define ARGF_CALLFUNC     (1 << 6)    // iControl = function pointer.
  97. //#define ARGF_CHECKVALUE   (1 << 7)    // iControl = pointer to an array.
  98.  
  99.  
  100. #define ARGF_CLI_WB_DEF         (ARGF_CLI | ARGF_WB | ARGF_DEFAULTVALUE)
  101. #define ARGF_CLI_WB_DEF_CHECK   (ARGF_CLI_WB_DEF | ARGF_CHECKLIMITS)
  102. #define ARGF_WB_DEF             (ARGF_WB | ARGF_DEFAULTVALUE)
  103. #define ARGF_WB_DEF_CHECK       (ARGF_WB_DEF | ARGF_CHECKLIMITS)
  104.  
  105.  
  106. //----------------------------------------------------------------------------------------------------
  107. // This class is used to read both CLI parameters and ToolTypes using the same
  108. // CArgsControl array. Thus, this array control everything related to the default
  109. // setup.
  110.  
  111. class CStartup
  112. {
  113.     public:
  114.  
  115.         enum Errors{NO_ERROR,           // No error.
  116.                     NO_MEMORY,          // Not enough memory.
  117.                     READARGS_ERROR,     // ReadArgs() failed.
  118.                     BAD_ARGUMENT        // Argument out of range.
  119.                    };
  120.  
  121.          CStartup(const CArgsControl control[], LONG array[], STRING extendedHelp = NULL);
  122.         ~CStartup();
  123.  
  124.         Errors ParseArgs();             // Parse both CLI parameterd and ToolTypes
  125.         Errors ParseCLIArgs();          // Parse CLI parameters only.
  126.         Errors ParseToolTypes(STRING progName = NULL);
  127.                                         // Parse ToolTypes only.
  128.  
  129.     private:
  130.  
  131.         void InitCLITemplate();         // Create pattern for RreadArgs().
  132.         void AllocateNewString(ULONG ctrlIdx, STRING str);
  133.         void InitArrays();              // Allocate the vector to hold ToolTypes strings.
  134.  
  135.         // Global variables.
  136.  
  137.         LONG                *piArgsArray;
  138.         const CArgsControl  *poArgsControl;
  139.         Errors               iStatus;
  140.  
  141.         // CLI related variables.
  142.  
  143.         char         *pcCLITemplate;
  144.         CDOSObject    oRDArgs;
  145.         RDArgs       *pOwnArgs;         // Private RDArgs struct needed for extended help.
  146.         CRDArgs       DOSArgs;          // RDArgs pointer returned by ReadArgs().
  147.  
  148.         // ToolTypes related variables.
  149.  
  150.         CStrArray     oTTStrings;
  151.         LONG         *piTTNumbers;
  152.         ULONG         iMaxNumbers;      // Maximum numbers held in iTTNumbers[]
  153.         LONG          iCurrentNumIndex; // Current index in iTTNumbers array.
  154.  
  155.         CStartup(const CStartup &);         // Not implemented.
  156.         void operator = (const CStartup &); // Ditto.
  157. };
  158.  
  159. //----------------------------------------------------------------------------------------------------
  160.  
  161. #endif // _ARGSCONTROL_CLASS_HPP
  162.  
  163.