home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / DASD / CDROM / ATAPI / CMDPARSE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  28.7 KB  |  440 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /**************************************************************************
  13.  *
  14.  * SOURCE FILE NAME =  CMDPARSE.H
  15.  *
  16.  *
  17.  *
  18.  *
  19.  * VERSION = V2.0
  20.  *
  21.  * DATE
  22.  *
  23.  * DESCRIPTION : Basic data types for Command Parser
  24.  *
  25.  * Purpose:  This file is automatically included in the files
  26.  *           which generate the parser tables:
  27.  *
  28.  *
  29.  *
  30. */
  31.  
  32.  
  33. /*  Typedefs  */
  34.  
  35. typedef unsigned char BYTE;
  36.  
  37. typedef struct _tbytes {
  38.     BYTE   byte1;
  39.     BYTE   byte2;
  40. } TBYTES;
  41.  
  42. typedef union _number {
  43.     USHORT n;
  44.     TBYTES two_bytes;
  45. } NUMBER;
  46.  
  47. typedef union _charbyte {
  48.     BYTE   byte_value;
  49.     CHAR   char_value;
  50. } CHARBYTE;
  51.  
  52. typedef struct _cc {
  53.   USHORT     ret_code;
  54.   USHORT     err_index;
  55. } CC;
  56.  
  57.  
  58. /* list of Command_Parser Completion Codes (ret_code) */
  59.  
  60. #define NO_ERR              0
  61. #define SYNTAX_ERR          1
  62. #define BUF_TOO_SMALL_ERR   2
  63. #define UNDEFINED_TYPE_ERR  3
  64. #define UNDEFINED_STATE_ERR 4
  65. #define NO_OPTIONS_FND_ERR  5
  66. #define REQ_OPT_ERR         6
  67. #define INVALID_OPT_ERR     7
  68.  
  69.  
  70.  
  71. /*----------------------------------------------------------------------------*/
  72. /*                                                                            */
  73. /*   Description of OPTIONTABLE Structure                                     */
  74. /*   ------------------------------------                                     */
  75. /*                                                                            */
  76. /*   The OPTIONTABLE allows the ADD to define the rules to be followed        */
  77. /*   by the Command_Parser.  In general, the table contains an entry          */
  78. /*   for each valid command line option.  Each entry defines the              */
  79. /*   command line option's syntax, unique id, and output buffer format.       */
  80. /*   The command line option syntax is made up of:                            */
  81. /*                                                                            */
  82. /*   1)  A character string field, which defines the option.                  */
  83. /*   2)  A type field - which defines the format of the value assigned to     */
  84. /*       an option.                                                           */
  85. /*   3)  A state table - which defines an option's positional relationship,   */
  86. /*       relative to the other options.                                       */
  87. /*                                                                            */
  88. /*                                                                            */
  89. /*   Specificly, the OPTIONTABLE consists of the following fields:            */
  90. /*                                                                            */
  91. /*     entry_state   = This field tells the Command_Parser which element      */
  92. /*                     in the poption -> opt.state[] contains the entry       */
  93. /*                     position into the state table.                         */
  94. /*                                                                            */
  95. /*     max_state     = This field tells the Command_Parser the                */
  96. /*                     number of elements in the poption -> opt.state[]       */
  97. /*                     state table.                                           */
  98. /*                                                                            */
  99. /*      poption[] =  This field contains an array of OPT pointers.            */
  100. /*                   An entry exists for each valid command line option.      */
  101. /*                   Please note that the order of the elements in the        */
  102. /*                   array is important.  For example: if you have 2 options  */
  103. /*                   with similar option strings, say, "/DM" and "/DM:"       */
  104. /*                   then a pointer to "/DM:" OPT structure must appear       */
  105. /*                   before the "/DM" option pointer.                         */
  106. /*                                                                            */
  107. /*                   The end of the array is denoted by                       */
  108. /*                   poption -> opt.id = TOK_ID_END                           */
  109. /*                                                                            */
  110. /*                                                                            */
  111. /*   Description of OPT Structure                                             */
  112. /*   ----------------------------                                             */
  113. /*   The OPT structure defines the rules associated with a specific           */
  114. /*   command line option.  It consists of the following fields:               */
  115. /*                                                                            */
  116. /*            id  =  This field contains a unique id for its associated       */
  117. /*                   command line option.  It is used by the parser to        */
  118. /*                   identify the option in the output buffer.                */
  119. /*                   (TOK_ID_END denotes the end of the table)                */
  120. /*                                                                            */
  121. /*        string  =  This field contains a pointer to the valid command       */
  122. /*                   line option string. This field is not case sensitive.    */
  123. /*                   The option string must start with the "/" char and,      */
  124. /*                   if a value can be assigned to the command opt, then      */
  125. /*                   the option string must end with the ":" char,            */
  126. /*                   followed by the assigned value.                          */
  127. /*                   The parser uses this field to identify the option in     */
  128. /*                   the command line.                                        */
  129. /*                                                                            */
  130. /*          type  =  This field defines the format of the options assigned    */
  131. /*                   value, for both parsing and setting up the output        */
  132. /*                   buffer. There are 9 pre-defined formats that the         */
  133. /*                   parser accepts, all of which are not case sensitive      */
  134. /*                   (exception: TYPE_CHAR.)  The predefined formats are:     */
  135. /*                                                                            */
  136. /*OutBuf Value                                                                */
  137. /*Field Length Type      Description                                          */
  138. /*------------ ------    ------------------------------                       */
  139. /*        0    TYPE_0    no associated valued allowed                         */
  140. /*                                                                            */
  141. /*                      In the output buffer the TYPE_0 token                 */
  142. /*                      contains a 0 byte field value.                        */
  143. /*                                                                            */
  144. /*   varies    TYPE_CHAR characters until / char, new line,                   */
  145. /*                       carriage return or null string detected              */
  146. /*                                                                            */
  147. /*                      In the output buffer the TYPE_CHAR token              */
  148. /*                      contains a varying number of byte field value.        */
  149. /*                      Each byte is in char format and consists of           */
  150. /*                      char as entered on the command line.                  */
  151. /*                                                                            */
  152. /*                      To determine the number of 1 byte char                */
  153. /*                      fields, in the token string -- subtract               */
  154. /*                      TOK_MIN_LENGTH from the contents of the token         */
  155. /*                      length field.                                         */
  156. /*                                                                            */
  157. /*        1    TYPE_D    one decimal digit (d)                                */
  158. /*                                                                            */
  159. /*                      In the output buffer the TYPE_D token                 */
  160. /*                      contains a 1 byte field value,                        */
  161. /*                      containing the char to integer conversion             */
  162. /*                      of the d decimal characters.                          */
  163. /*                                                                            */
  164. /*        2    TYPE_DD   two decimal digits (dd)                              */
  165. /*                                                                            */
  166. /*                      In the output buffer the TYPE_DD token                */
  167. /*                      contains a 1 byte field value,                        */
  168. /*                      containing the char to integer conversion             */
  169. /*                      of the dd decimal characters.                         */
  170. /*                                                                            */
  171. /*        2    TYPE_HH   hh,hh hexidecimal digits                             */
  172. /*                                                                            */
  173. /*                      In the output buffer the TYPE_HH token                */
  174. /*                      contains 2, 1 byte field values.  Each                */
  175. /*                      containing the char to hex conversion                 */
  176. /*                      of the hh hex characters.                             */
  177. /*                                                                            */
  178. /*        2    TYPE_HHHH hhhh hexidecimal digits                              */
  179. /*                                                                            */
  180. /*                      In the output buffer the TYPE_HHHH token              */
  181. /*                      contains a 2 byte field value consisting              */
  182. /*                      of 1 unsign short field set to char to hex            */
  183. /*                      conversion of the hhhh hex characters.                */
  184. /*                                                                            */
  185. /*        2    TYPE_FORMAT valid command line format strings are:             */
  186. /*                          360,260K,360KB                                    */
  187. /*                          720,720K,720KB                                    */
  188. /*                          1200,1200K,1200KB,1.2,1.2M,1.2MB                  */
  189. /*                          1440,1440K,1440KB,1.44,1.44M,1.44MB               */
  190. /*                          2880,2880K,2880KB,2.88,2.88M,2.88MB               */
  191. /*                                                                            */
  192. /*                      In the output buffer the TYPE_FORMAT token            */
  193. /*                      contains a 2 byte field value consisting              */
  194. /*                      of 1 unsign short field set to either                 */
  195. /*                      360, 720, 1200, 1440 or 2880.                         */
  196. /*                                                                            */
  197. /*   varies    TYPE_GEOMETRY  dd or (dddd,dddd,dddd) physical geometry        */
  198. /*                                                                            */
  199. /*                      In the output buffer the TYPE_GEOMETRY token          */
  200. /*                      contains either a 1 byte field value or 6 byte        */
  201. /*                      field value, consisting of 3 unsign short fields.     */
  202. /*                                                                            */
  203. /*                      To determine the format of this field (1 or 6),       */
  204. /*                      in the token string -- subtract                       */
  205. /*                      TOK_MIN_LENGTH from the contents of the token         */
  206. /*                      length field (results will be either 1 or 6).         */
  207. /*                                                                            */
  208. /*   varies    TYPE_SCSI      d,... and (d,d),... scsi target id              */
  209. /*                                   where d = 0-7                            */
  210. /*                                                                            */
  211. /*                      In the output buffer the TYPE_SCSI token              */
  212. /*                      contains varying number of 2 byte field values.       */
  213. /*                      The first contains the SCSI Target Id and the         */
  214. /*                      second contains the LUN id (0 if the d format         */
  215. /*                      is used.)                                             */
  216. /*                                                                            */
  217. /*                      To determine the number of 2 byte fields, in          */
  218. /*                      the token string -- subtract TOK_MIN_LENGTH           */
  219. /*                      from the contents of the token length field and       */
  220. /*                      then divide by 2.                                     */
  221. /*                                                                            */
  222. /*         state[1] =  This field defines a command line option's syntax,     */
  223. /*                     relative to the other command line options.            */
  224. /*                     It is designed as a state table with the initial       */
  225. /*                     state (entry_state) as the starting point and the      */
  226. /*                     size of the table (array) defined by max_states.       */
  227. /*                     The parser uses this table to syntax check the         */
  228. /*                     command line option.                                   */
  229. /*                                                                            */
  230. /*                     Based on the valid options (field != E) within a given */
  231. /*                     state the parser locates the next option in the        */
  232. /*                     command line.  Once located, the next state (col2)     */
  233. /*                     assigned is specified in the option (row) (col1)       */
  234. /*                     field.  Then col1 = col2, and the parsing continues    */
  235. /*                     until either an error or the end of command line is    */
  236. /*                     detected.                                              */
  237. /*                                                                            */
  238. /*                     NOTE:  The last row (id = TOK_ID_END), is uniquely     */
  239. /*                            defined.  Its state[] array, contains:          */
  240. /*                                                                            */
  241. /*                            -- R - if one of the valid options within the   */
  242. /*                                   state (col) is a required option         */
  243. /*                                                                            */
  244. /*                            -- O - if none of the options within the        */
  245. /*                                   state (col) are required option.         */
  246. /*                                                                            */
  247. /*                                                                            */
  248. /*----------------------------------------------------------------------------*/
  249.  
  250. typedef struct _opt {
  251.   SHORT      id;           /* user defined                   */
  252.   PSZ        string;       /* user defined                   */
  253.   BYTE       type;         /* user selected from list below  */
  254.   SHORT      state[];      /* user selected                  */
  255. } OPT, FAR *POPT;
  256.  
  257. typedef struct _optiontable {
  258.   USHORT     entry_state;
  259.   USHORT     max_states;
  260.   POPT       poption[];
  261. } OPTIONTABLE, FAR *POPTIONTABLE;
  262.  
  263.  
  264. /* SPECIAL TOKEN ID - OPT.id value */
  265.  
  266. #define TOK_ID_END        -1       /* denotes end of token string */
  267. #define TOKL_ID_END        2       /* length of end token         */
  268.  
  269.  
  270.  
  271. /*  OPT.type values and associate token length and output info  */
  272.  
  273. #define TYPE_0            1      /* no associates values allowed      0      */
  274. #define TYPE_CHAR         2      /* chars till '/' char/cr/nl/null   varies  */
  275. #define TYPE_D            3      /* d digit                           1      */
  276. #define TYPE_DD           4      /* dd digit                          2      */
  277. #define TYPE_HH           5      /* hh,hh  h-hexidemical              2      */
  278. #define TYPE_HHHH         6      /* hhhh   h-hexidemical              2      */
  279. #define TYPE_FORMAT       7      /* drive capacity                    2      */
  280. #define TYPE_SCSI_ID      8      /* d, and (d,d) SCSI Target ID       varies */
  281. #define TYPE_GEOMETRY     9      /* dd or (dddd, dddd, dddd)          varies */
  282.                                  /* drive type or cyln,head,sector           */
  283. #define TYPE_CHGLINE     10      /* "PS2", "AT", "NONE"                      */
  284. #define TYPE_DDDD        11      /* dddd                              2      */
  285.  
  286. /*  Diskette ChangeLine Types  */
  287.  
  288.  #define CHGLINETYPE_NONE       1
  289.  #define CHGLINETYPE_AT         2
  290.  #define CHGLINETYPE_PS2        3
  291.  
  292. /*  Geometry Format Types  */
  293.  
  294.  #define GEOTYPE_DRIVETYPE      0x01
  295.  #define GEOTYPE_DRIVESPEC      0x02
  296.  
  297.  
  298. /*  SPECIAL OPT.state values */
  299.  
  300. #define E               -1      /* identifies an invalid state                */
  301. #define O               -2      /* identifies that no option is required      */
  302. #define R               -3      /* identifies that an valid option is required*/
  303.  
  304.  
  305. /* Output Buffer Token Layout */
  306.  
  307. #define TOKL_LEN               0            /* offset of length in token      */
  308. #define TOKL_ID                1            /* offset of id in token          */
  309. #define TOKL_VALUE             2            /* offset of value in token       */
  310. #define TOK_MIN_LENGTH     TOKL_VALUE       /* length field + id field        */
  311.  
  312.  
  313. /*******************************************************************************
  314. *                                                                              *
  315. *   FUNCTION:  The Command_Parser ADD help routine, assists ADDs with          *
  316. *              parsing the CONFIG.SYS command line options. Using the          *
  317. *              rules defined by the ADD supplied OPTIONTABLE, the command      *
  318. *              parser:                                                         *
  319. *                                                                              *
  320. *              1) Parses the CONFIG.SYS command line (pCmdLine).               *
  321. *                                                                              *
  322. *              2) Sets up the ADD supplied output buffer (pOutBuf) with        *
  323. *                 the parsed command line options.                             *
  324. *                                                                              *
  325. *              3) Returns to the ADD with a completion code in the function    *
  326. *                 name.                                                        *
  327. *                                                                              *
  328. *   SETUP:     To call the Command_Parser routine, include the "CMDPHDR.H"     *
  329. *              file in your calling module and  define the necessary parms by  *
  330. *              using one of the supplied tables as a based. The supplied       *
  331. *              tables reside in the following files:                           *
  332. *                                                                              *
  333. *                 CMDPDSKT.C/CMDPDSKT.H --> diskette type ADD parm definitions *
  334. *                 CMDPDISK.C/CMDPDISK.H --> disk type ADD parm definitions     *
  335. *                 CMDPSCSI.C/CMDPSCSI.H --> SCSI type ADD parm definitions     *
  336. *                                                                              *
  337. *                                                                              *
  338. *   PROTOTYPE:   CC  FAR Command_Parser(PSZ pCmdLine, POPTIONTABLE pOptTable,  *
  339. *                                       BYTE *pOutBuf, USHORT OutBuf_Len);     *
  340. *                                                                              *
  341. *   ENTRY:     pCmdLine     = Far pointer to an array of characters, which     *
  342. *                             contains the CONFIG.SYS command line.            *
  343. *                                                                              *
  344. *              pOptTable    = Far pointer to the OPTIONTABLE structure, which  *
  345. *                             contains the ADD defined rules for the           *
  346. *                             Command_Parser to follow.  It includes a list    *
  347. *                             of the valid options and each for each option the*
  348. *                             command line syntax and output buffer format.    *
  349. *                                                                              *
  350. *               pOutBuf      = Pointer to an ADD supplied buffer (array of     *
  351. *                             unsign characters), for the Command_Parser       *
  352. *                             to return the parsed command options and         *
  353. *                             their associated values.                         *
  354. *                                                                              *
  355. *              OutBuf_Len   = Size, in bytes of the ADD supplied output        *
  356. *                             buffer (pOutBuf).  This value is relative to 1.  *
  357. *                                                                              *
  358. *                                                                              *
  359. *   RETURN:    CC           = The function name contains the completion        *
  360. *                             code information in the CC structure. Which      *
  361. *                             consists of the following 2 fields:              *
  362. *                                                                              *
  363. *             ret_code = Completion Code                                       *
  364. *                                                                              *
  365. *                        Value                 Description                     *
  366. *                        -----------------     --------------------------------*
  367. *                        NO_ERR              - Successful                      *
  368. *                                                                              *
  369. *                        SYNTAX_ERR          - Based on Option Table, type     *
  370. *                                              field, a syntax error was found *
  371. *                                              parsing the value assigned to   *
  372. *                                              option.                         *
  373. *                                                                              *
  374. *                        BUF_TOO_SMALL_ERR   - OutBuf_Len value is too small.  *
  375. *                                                                              *
  376. *                        UNDEFINED_TYPE_ERR  - Option Table, type field is     *
  377. *                                              undefined.                      *
  378. *                                                                              *
  379. *                        UNDEFINED_STATE_ERR - Option Table state table field  *
  380. *                                              contains an invalid state.      *
  381. *                                                                              *
  382. *                        NO_OPTIONS_FND_ERR  - No options as defined in the    *
  383. *                                              Option Table were found.        *
  384. *                                                                              *
  385. *                        REQ_OPT_ERR         - Based on Option Table last entry*
  386. *                                              a required option was not found *
  387. *                                                                              *
  388. *                        INVALID_OPT_ERR     - A / was found, but the option   *
  389. *                                              was not in the Option Table     *
  390. *                                                                              *
  391. *                                                                              *
  392. *               err_index = This field contains an index into the              *
  393. *                           command line (pCmdLine) of the character           *
  394. *                           being parsed when an error was detected.           *
  395. *                           The index returned in this field is valid          *
  396. *                           only when ret_code != NO_ERR.                      *
  397. *                                                                              *
  398. *              pOutBuf      = The ADD supplied buffer pointed to by pOutBuf    *
  399. *                             contains the successfully parsed command line    *
  400. *                             options and their associated values, in the      *
  401. *                             following format:                                *
  402. *                                                                              *
  403. *                                                                              *
  404. *                             -------------------------------------------------*
  405. *           OutBuf Format --> |option token| option token| ...| end of tokens |*
  406. *                             -------------------------------------------------*
  407. *                                  |                              |            *
  408. *                                  |                              |            *
  409. *                                  v                              v TOK_END    *
  410. *                           ----------------------            ---------------  *
  411. *   Option Token Format --> |length | id | value |            |  2    | -1  |  *
  412. *                           ----------------------            ---------------  *
  413. *                                                              length    id    *
  414. *                                                                              *
  415. *                             length    =  This field contains the total       *
  416. *                                          length of the token, in bytes.      *
  417. *                                                                              *
  418. *                                          length (1) + id (1) + value         *
  419. *                                                                              *
  420. *                                          Note: The length of the value field *
  421. *                                                varies, based on the type     *
  422. *                                                assigned to the option in     *
  423. *                                                the OPTIONTABLE.              *
  424. *                                                                              *
  425. *                             id        =  This field contains the unique id   *
  426. *                                          assigned to the option in the       *
  427. *                                          OPTIONTABLE. opt_id = TOK_END,      *
  428. *                                          denotes the end of the token string.*
  429. *                                                                              *
  430. *                             value     =  This field contains the value       *
  431. *                                          assigned to a option on the command *
  432. *                                          line.  The format and meaning       *
  433. *                                          of this field varies based on the   *
  434. *                                          type assigned to the option in      *
  435. *                                          the OPTIONTABLE.                    *
  436. *                                                                              *
  437. *******************************************************************************/
  438. CC FAR Command_Parser(PSZ,POPTIONTABLE,PBYTE,USHORT);
  439.  
  440.