home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 4 Drivers / 04-Drivers.zip / scsiopt2.zip / cmdparse.h < prev    next >
Text File  |  1997-12-08  |  16KB  |  490 lines

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