Subj : announcing getopts.btm - Unix switch parsing for 4DOS To : All From : Eric Pement Date : Sat Jan 12 2002 08:03 am From: pemente@northpark.edu (Eric Pement) I recently completed writing getopts.btm, a 4DOS batch file to allow Unix-style switch parsing on the command-line. I'd like to see if anyone would be interested in downloading and testing it. If so, please e-mail me directly and I'll send you GETOPTS.ZIP which has GETOPTS.BTM, the docs, and 3 sample batch files to show how it can be used. Here is the top portion of the GETOPTS documentation: ---------- GETOPTS.BTM version 1.0 - DOCUMENTATION SUMMARY The purpose of GETOPTS.BTM is to allow 4DOS batch files to support Unix-style option switches on the command line. The idea is that a 4DOS batch file can "call" GETOPTS, which locates and parses each option and sets environment variables, while the parent batch file determines which switches are allowed and handles other details. I wrote GETOPTS to mimic, within reason, the operation of "getopts" in the Unix/GNU/Linux environment. GETOPTS.BTM was written by Eric Pement (pemente@northpark.edu) in December 2001. Your feedback and suggestions for improvement are welcome. It is freely offered to the 4DOS user community under the terms of the GNU General Public License ("copyleft"). SYNTAX: When GETOPTS is active, the following command lines are equivalent: cmd -a -b -C -w foo -W "one two" word1 word2 cmd -ba -wfoo -C -W"one two" -- word1 word2 cmd word1 word2 -abCwfoo -W"one two" cmd -W "one two" word1 -bw foo word2 -aC Given the example above, GETOPTS will create and return the following environment variables to the parent batch file: OPTIONS=a b C! - a list of character switches used STRINGS=LC_w UC_W - a list of string switches used LC_W=foo - each string switch has a separate variable UC_W="one two" - case-sensitivity is kept by LC_ or UC_ Moreover, the command tail %& will be reset to "word1 word2" since all the options and option-arguments have been stripped out. FEATURES SUPPORTED: * Position-independent switch clustering "-a -b -c" equals "-ac -b" equals "-c -ba" equals "-bac". * 3 types of switches: character switches, string switches, and numeric switches. * Case-sensitive character switches "-d" and "-D" are recognized as different options. Character switches are alphabetic only (a-z or A-Z), and cannot take an argument or parameter. * Case-sensitive string switches String switches are one character (a-z or A-Z) which must take an argument or parameter. Thus, -f and -F may accept different arguments which may be passed as '-fhello' or '-F goodbye'. Multi-word arguments are permitted if they are enclosed in double quotes, such as '-g "one or more words"'. * Numeric options Numeric options may be permitted or forbidden. If permitted, -123 will set N=123, and --456 will set N=-456. * Switches and argument removed from the command tail Under GETOPTS, all switches and switch parameters on the command line are placed into appropriate environment variables (see SYNTAX: for examples, above). The switches are then removed from the command tail (%&). If the batch file executes external utilities, the utility's own option syntax can be used (e.g., /opt1, opt2:opt3, word=opt4, etc.). * Halt on invalid options The parent batch file contains a list of permissible letters for character and string options, and tells whether numeric options are allowed. The GETOPTS batch file first checks the list itself and then checks each option on the command-tail for validity. GETOPTS will halt if it detects invalid options, but it can be set to "pass" invalid options through instead. * Switch termination To permit processing filenames which begin with leading hyphens, the switch "--" terminates switch processing, and the rest of the command tail is returned untouched to the parent batch file. Further, a single hyphen "-" by itself is passed without modification to the command tail. [rest of documentation deleted for space] If interested, e-mail me at the address below, replacing the [=at=] with a real "@" symbol. If there's a website that's 4DOS related, feel free to post GETOPTS.ZIP there. Feedback would be welcome. -- Eric Pement - pemente[=at=]northpark.edu --- BBBS/NT v4.01 Flag-2 * Origin: Mach2 Systems (1:342/3) .