📄 optlib.tpl
字号:
IF (=* (get "arg_default") (string-append Cap-prefix cap-name)) =][= arg_default =][= ELSE =][=(string-append UP-prefix UP-name)=]_[= (string-upcase! (get "arg_default"))=][= ENDIF =])[= =* str =]tSCC z[=(sprintf "%-28s" (string-append cap-name "DefaultArg[]" )) =]= [=(kr-string (get "arg_default"))=];[= * =][= (error (string-append cap-name " has arg_default, but no valid arg_type")) =][= ESAC =][= ENDIF =][= IF (exist? "flags_must") =]static const int a[=(. cap-name)=]MustList[] = {[= FOR flags_must =] INDEX_[= (. UP-prefix) =]OPT_[= (string-upcase! (get "flags_must")) =],[= ENDFOR flags_must =] NO_EQUIVALENT };[= ENDIF =][= IF (exist? "flags_cant") =]static const int a[=(. cap-name)=]CantList[] = {[= FOR flags_cant =] INDEX_[= (. UP-prefix) =]OPT_[= (string-upcase! (get "flags_cant")) =],[= ENDFOR flags_cant =] NO_EQUIVALENT };[= ENDIF =]#define [=(. UP-name)=]_FLAGS ([= CASE arg_type =][= =* num =]OPTST_NUMERIC | [= =* bool =]OPTST_BOOLEAN | [= =* key =]OPTST_ENUMERATION | [= ESAC =][= stack-arg "OPTST_STACKED | " =][= immediate "OPTST_IMM | " =][= immed_disable "OPTST_DISABLE_IMM | " =][= must-set "OPTST_MUST_SET | " =][= ? enabled "OPTST_INITENABLED" "OPTST_DISABLED" =] | [= ? no_preset "OPTST_NO_INIT" "OPTST_INIT" =])[=ENDDEF emit-nondoc-option =][=# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *Define the arrays of values associated with an option (strings, etc.) =][=DEFINE Option_Strings=]/* * [=(. cap-name)=] option description[= IF (or (exist? "flags_must") (exist? "flags_cant")) =] with * "Must also have options" and "Incompatible options"[= ENDIF =]: */[= IF (. skip-ifdef) =][= ELSE =][= IF (exist? "ifdef") =]#ifdef [=(get "ifdef") =][= ELIF (exist? "ifndef") =]#ifndef [=(get "ifndef") =][= ENDIF ifdef/ifndef =][= ENDIF =]tSCC z[=(. cap-name)=]Text[] = [=(kr-string (get "descrip"))=];[= IF (exist? "documentation") =]#define [=(. UP-name)=]_FLAGS (OPTST_DOCUMENT | OPTST_NO_INIT)[= ELSE NOT a doc option: =][= emit-nondoc-option =][= ENDIF (exist? "documentation") =][= IF (. skip-ifdef) =][= ELSE =][= IF (or (exist? "ifdef") (exist? "ifndef")) =]#else /* disable [=(. cap-name)=] */#define VALUE_[=(. UP-prefix)=]OPT_[=(. UP-name)=] NO_EQUIVALENT#define [=(. UP-name)=]_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)[= IF (exist? "arg_default") =]#define z[=(. cap-name)=]DefaultArg NULL[= ENDIF =][= IF (exist? "flags_must") =]#define a[=(. cap-name)=]MustList NULL[= ENDIF =][= IF (exist? "flags_cant") =]#define a[=(. cap-name)=]CantList NULL[= ENDIF =]#define z[=(. cap-name)=]Text NULL#define z[=(. cap-name)=]_NAME NULL#define z[=(. cap-name)=]_Name NULL#define zNot[=(. cap-name)=]_Name NULL#define zNot[=(. cap-name)=]_Pfx NULL#endif /* ifdef/ifndef */[= ENDIF ifdef/ifndef =][= ENDIF (. skip-ifdef) =][=ENDDEF Option_Strings =][=# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #Define the values for an option descriptor =][=DEFINE Option_Descriptor =][= IF (exist? "documentation") =] { /* entry idx, value */ 0, 0, /* equiv idx, value */ 0, 0, /* option argument */ ARG_NONE, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 0, 0, /* opt state flags */ [=(. UP-name)=]_FLAGS, /* last opt argumnt */ NULL, /* arg list/cookie */ NULL, /* must/cannot opts */ NULL, NULL, /* option proc */ [= IF (exist? "call_proc") =][=call_proc=][= ELIF (or (exist? "extract_code") (exist? "flag_code")) =]doOpt[=(. cap-name)=][= ELSE =]NULL[= ENDIF =], /* desc, NAME, name */ z[=(. cap-name)=]Text, NULL, NULL, /* disablement strs */ NULL, NULL },[= ELSE=] { /* entry idx, value */ [=(for-index)=], VALUE_[= (. UP-prefix)=]OPT_[=(. UP-name)=], /* equiv idx, value */ [= IF (== (string-upcase! (get "equivalence")) UP-name) =]NO_EQUIVALENT, 0,[= ELIF (exist? "equivalence") =]NOLIMIT, NOLIMIT,[= ELSE =][=(for-index)=], VALUE_[=(. UP-prefix)=]OPT_[=(. UP-name)=],[= ENDIF=] /* option argument */ ARG_[= IF (not (exist? "arg_type")) =]NONE[= ELIF (exist? "arg_optional") =]MAY[= ELSE =]MUST[= ENDIF =], /* equivalenced to */ [= IF (and (exist? "equivalence") (not (string-ci=? (string-upcase! (get "equivalence")) (. UP-name)) ) ) =]INDEX_[=(. UP-prefix)=]OPT_[=(string-upcase! (get "equivalence"))=][= ELSE =]NO_EQUIVALENT[= ENDIF =], /* min, max, act ct */ [=(if (exist? "min") (get "min") "0")=], [= (if (exist? "max") (get "max") "1")=], 0, /* opt state flags */ [=(. UP-name)=]_FLAGS, /* last opt argumnt */ [= IF (exist? "arg_default") =](char*)z[=(. cap-name)=]DefaultArg[= ELSE =]NULL[= ENDIF =], /* arg list/cookie */ NULL, /* must/cannot opts */ [= IF (exist? "flags_must")=]a[=(. cap-name)=]MustList[= ELSE =]NULL[= ENDIF=], [= IF (exist? "flags_cant")=]a[=(. cap-name)=]CantList[= ELSE =]NULL[= ENDIF=], /* option proc */ [= IF (exist? "call_proc") =][=call_proc=][= ELIF (or (exist? "extract_code") (exist? "flag_code") (exist? "arg_range")) =]doOpt[=(. cap-name)=][= ELIF (exist? "flag_proc") =]doOpt[= (string-capitalize! (get "flag_proc")) =][= ELIF (exist? "stack_arg") =][= IF (or (not (exist? "equivalence")) (= (get "equivalence") (get "name")) ) =]stackOptArg[= ELSE =]unstackOptArg[= ENDIF =][= ELSE =][= CASE arg_type =][= =* bool =]optionBooleanVal[= =* num =]optionNumericVal[= =* key =]doOpt[=(. cap-name)=][= * =]NULL[= ESAC =][= ENDIF=], /* desc, NAME, name */ z[=(. cap-name)=]Text, z[=(. cap-name)=]_NAME, z[=(. cap-name)=]_Name, /* disablement strs */ zNot[=(. cap-name) =]_Name, zNot[=(. cap-name)=]_Pfx },[= ENDIF =][=ENDDEF Option_Descriptor =][=# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #Compute the usage line. It is complex because we are trying toencode as much information as we can and still be comprehensible.The rules are: If any options have a "value" attribute, thenthere are flags allowed, so include "-<flag>" on the usage line.If the program has the "long_opts" attribute set, then we musthave "<option-name>" or "--<name>" on the line, depending onwhether or not there are flag options. If any options take arguments, then append "[<val>]" to the flag description and"[{=| }<val>]" to the option-name/name descriptions. We won'tworry about being correct if every option has a required argument.Finally, if there are no minimum occurrence counts (i.e. alloptions are optional), then we put square brackets around thesyntax. =][=DEFINE USAGE_LINE =][= ;; Compute the option arguments ;; (if (exist? "flag.arg_type") (begin (define flag-arg " [<val>]") (define opt-arg "[{=| }<val>]") ) (begin (define flag-arg "") (define opt-arg "") ) ) (define usage-line (string-append "USAGE: %s " ;; If at least one option has a minimum occurrence count ;; we use curly brackets around the option syntax. ;; (if (not (exist? "flag.min")) "[ " "{ ") (if (exist? "flag.value") (string-append "-<flag>" flag-arg (if (exist? "long_opts") " | " "") ) (if (not (exist? "long_opts")) (string-append "<option-name>" opt-arg)) ) (if (exist? "long_opts") (string-append "--<name>" opt-arg) "" ) (if (not (exist? "flag.min")) " ]..." " }...") ) ) (if (exist? "argument") (set! usage-line (string-append usage-line ;; the USAGE line plus the program name plus the argument goes ;; past 80 columns, then break the line, else separate with space ;; (if (< 80 (+ (string-length usage-line) (len "argument") (len "prog_name") )) " \\\n\t\t" " ") (get "argument") )) ) (kr-string (string-append prog-name " - " (get "prog_title") (if (exist? "version") (string-append " - Ver. " (get "version")) "" ) "\n" usage-line "\n" )) =][=ENDDEF=]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -