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