home *** CD-ROM | disk | FTP | other *** search
-
- CMDPARSE David K. Rich Page 1
-
- When writing programs which take parameters from the DOS call line, I found
- myself constantly re-inventing a way to determine what was on the command
- line. Finally, I decided that it was time to build that wheel
- once-and-for-all. This set of functions for Turbo (ANSI?) C is the result.
-
- In the ZIP file for CMDPARSE you should find:
-
- CMDPARSE.C The source code for the functions. It could
- probably be tightened, but has the benefit
- that it works. Please don't fiddle with it
- and then distribute the modified version as
- CMDPARSE, give any modified version another
- name and claim it yourself (with
- acknowledgement)
-
- CMDPARSE.OBJ The TurboC 2.0 OBJ file which can be linked
- with your program or placed in your LIB file.
-
- CMDPARSE.H A header file which should be included in
- any code that references CMDPARSE.
-
- CMDPARSE.DOC This file.
-
- CPDEMO.EXE A program which demonstrates these functions.
- Try it with various command parameters &
- options.
-
-
-
- CMDPARSE David K. Rich Page 2
-
-
- What follows was excerpted from the comments in the code. It should
- adequately document things.
-
- First, several assumptions are made by these functions:
-
- All parameters are separated by one or more spaces. The
- number of spaces is not significant and the spaces are
- not a part of the parameter.
-
- No more than 20 parameters and options will be passed.
-
- Options are indicated by a leading switch character,
- either a slash (/) or a dash (-).
-
- Slash-delimited options may be appended to a field without
- a separating space, vis.
-
- param/n command/c
-
- Dash-delimited options will always be preceded by a space.
-
- Options always are terminated by a space.
-
- Options can take one of three forms:
-
- Switch+character example: /n
- Switch+string example: /noi
- Switch+expression example: /VIDEO=MONO
-
- The switch+expression options may NOT have spaces before &/or
- after the = sign.
-
- No case conversions are done.
-
- Two global arrays are defined, which can be referred to in your code because
- of extern declarations in CMDPARSE.H
-
- char *cmd_arg[22] Pointers to the READ-ONLY strings for each
- parameter. These are read-only because
- the pointers are all to substrings of
- combined_cmd.
-
- int arg_type[22] A parallel array to cmd_arg, one entry for
- each item in cmd_arg. arg_type[] will be
-
- 0 = a parameter
- 1 = an option
-
- You may never have to directly refer to these arrays because of the
- functions included.
-
-
-
- CMDPARSE David K. Rich Page 3
-
- The functions are as follows:
-
- int cmd_init(void) This function MUST be called before any
- of the other functions. It retrieves the
- call line and parses it into the arrays.
-
- char *get_param(int param_number)
-
- This function will return a pointer to the
- READ-ONLY string for the parameter whose
- number is passed. Note that parameter #0
- is the program name, parameter #1 is the
- first parameter after the program name,
- etc.
-
- Returns NULL if parameter doesn't exist.
-
- If options are interspersed with parameters
- they are not counted as parameter numbers.
-
- Execute CPDEMO with parameters, etc. to
- see the effect of various command lines.
-
- int if_option(char *search_string)
-
- Scans all option fields and tests the first
- character(s) following the switch to see if
- they match. The number of characters checked is determined
- by the number of characers in the test
- string passed.
-
- The comparison is case sensitive.
-
- Returns:
-
- 0 if not found
- array subscript in cmd_arg[] if found
-
- int if_optioni(char *search_string)
-
- Same as if_option(), except the comparison
- is case-insensitive.
-
-
-
- CMDPARSE David K. Rich Page 4
-
-
- char *opt_value(char *search_string)
-
- Returns a pointer to the READ-ONLY string
- containing the rvalue of a /optname=value
- option type. Scans all option fields and
- tests the first character(s) following the
- switch to see if they match. The number of
- characters checked is determined by the
- number of characers in the test string
- passed.
-
- The comparison is case sensitive.
-
- char *opt_valuei(char *search_string)
-
- Same as opt_value(), except the comparison
- is case-insensitive.
-
-
-