diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/getopt.tes | 52 |
2 files changed, 53 insertions, 1 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index a66aaef..69a7c02 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,6 @@ dist_scitecolib_DATA = color.tes lexer.tes session.tes fnkeys.tes -dist_scitecolib_DATA += string.tes +dist_scitecolib_DATA += string.tes getopt.tes # Helper script for creating lexer definitions EXTRA_DIST = scite2co.lua diff --git a/lib/getopt.tes b/lib/getopt.tes new file mode 100644 index 0000000..a2bcb31 --- /dev/null +++ b/lib/getopt.tes @@ -0,0 +1,52 @@ +!*$ + * M[getopt] -> Success|Failure -- Parse options + * + * Parses command line options according to the string + * \(lqoptstring\(rq, similar to \fBgetopt\P(3). + * \(lqoptstring\(rq is a list of single character + * option names. + * If followed by a colon, the option takes an argument + * (which can be part of the same command line argument as in + * \(lq-Ofoo\(rq). + * If followed by two colons, the option argument is optional. + * For every detected option \fIX\fP, a register \fBgetopt.\fIX\fR is + * defined with -1 (true) in its integer part. + * If the option had an argument, it is stored in the register's + * string part. + * + * A condition boolean is returned to signify whether + * there was a parsing error. + *! +[optstring] +@[getopt]{ + .U.d + < + .-Z"= 1; ' 0A-^^-"N :L; F< ' + + 1A-^^-"= K 1; ' + + 0U.i < + :Q[optstring]-Q.i"= Q.dJ 0 ' + Q.iQ[optstring]U.c + + 0U.#ar < + %.i-:Q[optstring]"= 1; ' + Q.iQ[optstring]-^^:"N 1; ' + %.#ar> + + 1A-Q.c"= + -U[getopt.U.c] + Q.#ar"> + 2A-10"= + K Q.#ar-1"> 0A-^^-"= 0U.i F< ' ' + | + 2D + ' + LR 0X[getopt.U.c] 0L + ' + K 1; + ' + > + > + Q.dJ +-1} |