With MUSASHI, method of giving the option with command line we are conformed to the general method of UNIX, "- keyword [ give with type of value ]".
With MUSASHI API, type of next 13 options is supported.
Command option type | Structure name | OptTyoe enumeration body | Feature | Example |
Character string type | OptSTR | OSTR | Simply you set as the character string. When with the general-purpose type, the option which is not applicable in either under is necessary, pass logic is drawn up with each one making use of this character string type. | -c 'day ($date1, $date2) |
Character string selection | OptSEL | OSEL | When it can give the character string other than the plural character strings which are decided it becomes error. | -c sum |
Character string list type | OptSLS | OSLS | Dividing with the comma, it gives the plural character strings which are given | -v abc, def and ghi |
Integer type | OptINT | OINT | It is converted to int type integer. | -v 100 |
Integer list type | OptILS | OILS | Dividing with the comma, the plural values which are given, change are done in Int type integer. | -v 10,15,20 |
Integer range type | OptRNG | ORNG | It is converted as the range of int type integer. (The under bar is utilized in the range sign) | -R 10_100 |
Real number type | OptDBL | ODBL | It is converted to the double type real number. | -v 1.28 |
Real number list type | OptDLS | ODLS | Dividing with the comma, the plural values which are given, change are done in double type integer. | -v 1.28,10.5 |
Input file type | OptINF | OINF | Dividing with the comma, it handles the character string which is given develops the wild card as the file. | -i indat.xt -i in* xt |
Output file type | OptOTF | OOTF | It handles as output file name. | -o outdat.xt |
General item type | OptFLD | OFLD | Dividing with the comma, it handles the character string which is given, as item name. In addition continuing in the colon, new item name, % continuing in the sign, it can appoint item option to each item name. In addition wild card interpretation possibility. | -f amount: Total amount %nr -f * amount |
Key item type | OptKEY | OKEY | Dividing with the comma, it handles the character string which is given, as key item name. | -k customer |
Flag type | OptFLG | OFLG | Functioning it does as the flag which does not take value. | -t |
With MUSASHI-API, "-t", "-X" and "-x" as for option as for the developer, it is not possible with special meaning, to utilize these options. It has following kind of meaning respectively.
Option | Meaning |
-h | Simple help is indicated. |
-t | Not to be XMLtable, it utilizes ÇÂÆãÇÓÇç of plain text as the input/output data. |
-Q | End message and error message are not output altogether. |
-x | Specification and explanation etc. of command are output with XML type. |
-X | The man document is output. |
In addition, it seems that is shown below, as for the option which has common meaning in many commands, other than utilizing at the time of the same meaning the one which is avoided is better, probably will be.
Option | Meaning |
-f | Appointment of item name of processing object. |
-k and -K | Appointment of key item name. |
-s | Appointment of the item name which it sorts |
-i and -I | Input file name |
-o and -u | Output file name |
-v | Appointment of value |
-c | Arithmetic expression and conditional expression etc. |
-q | Sequential totaling |
The flow of utilization of option-related function is as follows.
In order to utilize the option processing which MUSASHI offers, first, definition of the option which is made to appoint to the user is done. At that time, the variable which it should initialize with each option type structure is initialized. At below character string type option it keeps recommending explanation to example.
"Character string type (MssOptFLD)" the structure is as follows.
Struct OptSTR {enum OptType type; /* option type & char *keyWord; /* keyword letter * int must; /* designated necessary flag * char *def; /* default * int minLen; The smallest number of letters of /* element * int maxLen; The maximum number of letters of /* element * char *title; /* parameter title * char *comment; /* parameter comment * int set; It was appointed with respect to /* command line, flag & char *str; /* option character string: Those which argv strdup are done *}; |
Here, the developer must initialize "type" empty "comment", it is the variable. Contents of variable differ, two of beginning (type and keyWord), are the variable which is common to all the option types with the type of option. As shown below, is, the enumeration constant which responds to each option type is appointed to type enumeration type variable.
Enum OptType {OSTR and /* character string type * OSEL and /* character string selection * OSLS and /* character string list type * OINT and /*int type * OILS and /*int list type * ORNG and /*int range type * ODBL and /*double type * ODLS and /*double list type * OINF and /* input file type * OOTF and /* output file type * OFLD and /* item type * OKEY, /*key item type & OFLG /* flag type *}; |
Meaning of other variables is as follows.
Variable identifier | Meaning |
KeyWord | Keyword of option is given to keyWord variable, with alphabet one letter. In the future perhaps, it tries also appointing the plural letters that it is possible, but at present, there is restriction of one letter. |
Must | It is necessary to initialize with flag type option other than all option type. If this option is necessary, if 1, it is abbreviation possible, 0 is given. When designating XMLtable as the input/output data, it is necessary, but when -t designates the plain text data as the input/output data with appointment, there is no designated necessity, if is, 2 is given. For example (like xtcal, command of the type which adds new item appoints new item name with -a, but there is no concept of item name in plain text. 2 is given vis-a-vis this kind of option.) |
Def | It is necessary to initialize with flag type option other than all option type. When must 0 (abbreviation) it is possible, the default it appoints as default the value which it uses (as a character string). When must 1 or 2 being, it makes NULL. |
MinLen MaxLen |
Restriction of length in the character string is appointed. If the option value where the user exceeds this restriction was input, indicating the error message that "length in the character string exceeded restriction", it makes error ends. |
Title Comment |
Title and comment concerning option are given in the character string. This variable is utilized in indication of the help picture. |
Below, example of definition & initialization is shown. Character string option variable "yourName" has been defined.
MssOptSTR yourName= {OSTR and /* option type * "S" and /* keyword (as for plural letters failure) * 1, /* 0: Option, 1: Necessity, with only 2:XMLtable necessity (with txt disregard) * NULL and /* default * minimum length in 1, /* character strings * maximum length in 10, /* character strings * "your name", title of this option of the /* (with Help indication) * "the name which is appointed here is indicated in the picture" comment of this option of the /* (with Help indication) *}; |
And lastly, address of each option variable which is defined is registered to arrangement of general-purpose pointer type, (end of arrangement must appoint the NULL pointer). Performance function of the option which is explained afterwards (mssSetOption), it means to transfer this arrangement.
Void *opt [ ] = {&yourName and NULL}; |
Prescribed form: Void mssHelpDoc (void *opt [ ], struct mssComHelp *comHelp, int argc and char **argv);
First argument: Arrangement of address of option
variable
Second argument:The structure for
the commandhelp which with start and end
processing it is defined & is initialized and
Third argument: The number of arguments which are
given with command line
Fourth argument: The character string pointer to
the argument which is given with command line
If the argument which is given with command line
is investigated and the number of arguments is at one, at the same
time the value "-h", to indicate the help picture, (rough sketch
reference),
If "-x" is, the XML document is output, if and "-X" is,
the man document is output.
$ . /option -h NAME: Option version: 1.0 The start end processing sample USAGE: of MUSASHI Option -S your name SUMMARY: This is the sample program OPTION: EXAMPLES: Option -S myName INFORMATION: <musashi.sourceforge.jp> BUG REPORT: <musashi-users@lists.sourceforge.jp> $ |
Prescribed form: Void mssSetOption (void *opt [ ], int argc and char *argv [ ]);
First argument: Arrangement of address of option
variable
Second argument: The number of arguments which
are given with command line
Third argument: The character string pointer to
the argument which is given with command line
By this function, you appraise the argument which is given with command line, you keep setting each option variable which is defined in command.
Concerning the variable which is set each option classified by type as for detailed explanationpleaserefer to here.
Prescribed form: Void mssFreeOption (void *opt [ ])
First argument: Arrangement of address of option variable
3.3. So, many memories are guaranteed anew when appraising the option which is explained. Those territories it is and it uses mssFreeOption function because it opens to the ÇJ coming.
Below, C source of the sample which makes the
contents reflect which are explained here (option.c) it publishes.
Please refer tothe utilization
method of the sample program and compile and verify operation.
#include <stdio.h> #include <signal.h> #include <musashi.h> struct mssComHelp comHelp= {"init" and /* command name * "1.0", /* version * "the start end processing sample of MUSASHI", /* command title * "this is the sample program,", /* summary * "init a b c", /* utilization example * "optstr" and /* reference command * "hambear" and /* writer information * the information "of musashi-users@lists.sourceforge.jp" and the /* bug report * "the musashi.sourceforge.jp" /* home page *}; Extern struct mssGlobalVariables mssGV; Int main (int argc and char *argv [ ]) {MssOptSTR yourName= {OSTR and /* option type * "S" and /* keyword (as for plural letters failure) * 1, /* 0: Option, 1: Necessity, with only 2:XMLtable necessity (with txt disregard) * NULL and /* default * minimum length in 1, /* character strings * maximum length in 10, /* character strings * "your name", title of this option of the /* (with Help indication) * "the name which is appointed here is indicated in the picture" /* comment (with Help indication) *}; Void *opt [ ] = {&yourName and NULL}; MssInit (argc, argv and &comHelp); Initialization & mssHelpDoc such as /* signal processing (opt, &comHelp, argc and argv); /* help & mssSetOption (opt, argc and argv); Setting & printf of /* command option ("type=%d¢@n" and yourName.type); Printf ("keyWord=%s¢@n" and yourName.keyWord); Printf ("must=%d¢@n" and yourName.must); Printf ("minLen=%d¢@n" and yourName.minLen); Printf ("maxLen=%d¢@n" and yourName.maxLen); Printf ("title=%s¢@n" and yourName.title); Printf ("comment=%s¢@n" and yourName.comment); Printf ("str=%s¢@n" and yourName.str); MssFreeOption (opt); Opening & mssShowEndMsg of /* option territory (); /* completion message * mssEnd (mssExitSuccess); /* end & return (0); /* to avoid warning message *} |
". The result of executing is /option hambear" as follows.
The $ . /option -S str=hambear #END# 24918 2003/08/01 13:25:18 where the name which is appointed hambear type=0 keyWord=S must=1 minLen=1 maxLen=256 title= your name comment= here is indicated in the picture ". /option -S the hambear" in=0 out=0 $ |
Because option "-S" is necessary option, abbreviating, when it starts, following kind of error message is indicated and ends.
$ . /option #ERROR# 24928 ". /option" "option -S is mandatory" $ |
In addition, because designated possible character string length it is within 10 letters with option "-S", exceeding that, when it appoints, following kind of error message is indicated and ends.
$ . /option -S hambearhambear #ERROR# 24929 ". /option -S hambearhambear" "length of option value is out of ran ge: -S hambearhambear (1,10)"$ |