aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-08-06 16:46:37 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-08-06 16:46:37 +0300
commit280cb9da39fc7b5357f6071926d511394f6d0152 (patch)
treecdca852694fd3e4cc9293c374d16ac69d9be01ea /lib
parentc5510d684e4879ab9a5295b4a1981888a4268627 (diff)
downloadsciteco-280cb9da39fc7b5357f6071926d511394f6d0152.tar.gz
command-line arguments are no longer passed via the unnamed buffer, but via special Q-registers ^Ax
* The unnamed buffer is also used for reading from --stdin, so you couldn't practically combine --stdin with passing command-line arguments to macros. * The old approach of passing command-line arguments via lines in the unnamed buffer was flawed anyway as it wouldn't work with filenames containing LF. This is just a very ancient feature, written when there weren't even long Q-reg names in SciTECO. * You can now e.g. pipe into SciTECO and edit what was read interactively, e.g. `dmesg | sciteco -i`. You can practically use SciTECO as a pager. * htbl.tes is now a command-line filter (uses -qio). * grosciteco.tes reads Troff intermediate code from stdin, so we no longer need "*.intermediate" temporary files. * added a getopt.tes test case to the testsuite. * This change unfortunately breaks most macros accepting command-line arguments, even if they used getopt.tes. It also requires updating ~/.teco_ini - see fallback.teco_ini.
Diffstat (limited to 'lib')
-rw-r--r--lib/getopt.tes52
-rw-r--r--lib/opener.tes30
2 files changed, 45 insertions, 37 deletions
diff --git a/lib/getopt.tes b/lib/getopt.tes
index 46c813f..4ecfa3f 100644
--- a/lib/getopt.tes
+++ b/lib/getopt.tes
@@ -1,5 +1,5 @@
!*$
- * M[getopt] -> Success|Failure -- Parse options
+ * M[getopt] -> First non-flag argument -- Parse options
*
* Parses command line options according to the string
* \(lqoptstring\(rq, similar to \fBgetopt\P(3).
@@ -14,37 +14,47 @@
* 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.
+ * Returns the index of the first command-line argument that does not
+ * belong to a flag or -1 in case of parsing errors.
*!
[optstring]
-@[getopt]{ [:
- <
- .-Z"= 1; ' 0A-^^-"N :L; F< '
+@[getopt]{
+ <%.j
+ :Q[\.j]:;
+ 0Q[\.j]--"N 1; '
+ !next!
- 1A-^^-"= K 1; '
+ 1Q[\.j]U.f
+ Q.f--"= !* -- *! Q.j+1 '
+ !* j-th argument is -f *!
0U.i <
- :Q[optstring]-Q.i"= ]: 0 '
- Q.iQ[optstring]U.c
+ Q.iQ[optstring]U.o Q.o"< -1 '
- 0U.#ar <
- %.i-:Q[optstring]"= 1; '
- Q.iQ[optstring]-^^:"N 1; '
- %.#ar>
+ !* count number of : after o *!
+ 0U.#ar <%.iQ[optstring]-:"N 1; ' %.#ar>
- 1A-Q.c"=
- -U[getopt.U.c]
+ Q.f-Q.o"=
+ -U[getopt.U.o]
Q.#ar">
- 2A-10"=
- K Q.#ar-1"> 0A-^^-"= 0U.i F< ' '
+ 2Q[\.j]"<
+ !* -f arg *!
+ %.j
+ Q.#ar-1"> !* optional arg *!
+ :Q[\.j]"< Q.j '
+ 0Q[\.j]--"= Onext '
+ |
+ :Q[\.j]"< -1 '
+ '
+ EU[getopt.U.o]Q[\.j]
|
- 2D
+ !* -farg *!
+ EU[getopt.U.o]Q[\.j]
+ [* EQ[getopt.U.o] 2D ]*
'
- LR 0X[getopt.U.c] 0L
'
- K 1;
+ 1;
'
>
>
-]: -1}
+Q.j}
diff --git a/lib/opener.tes b/lib/opener.tes
index 98ce631..c0183c8 100644
--- a/lib/opener.tes
+++ b/lib/opener.tes
@@ -1,40 +1,38 @@
!*$
- * M[opener] -- Open a number of files from the current buffer
+ * M[opener] -- Open files, specified on the command line
*
- * This is usually the unnamed buffer as initialized from the command line.
* It supports both the +line[,column] and filename:line[:column] syntaxes.
* Since this may make it hard to open files with certain file names, all
* filenames after "--" are interpreted verbatim.
+ * It does not change the current buffer.
*!
-@[opener]{
- <.-Z;
+@[opener]{ [*
+ <%.i :Q[\.i]:; EQ[\.i]
!* --/-S stops processing of special arguments *!
- 0A--"= 1A--"= 2A-10"=
- L <:L;R 0X.f [* EBN.f ]* L> 1;
+ 0A--"= 1A--"= 2A"<
+ <%.i :Q[\.i]:; EBN[\.i]> 1;
'''
1U.l 1U.c
!* +line[,column] *!
0A-+"= C 0A"D
\U.l <0A"DC|1;'> 0A-,"= C \U.c <0A"DC|1;'> '
- 0A-10"= 2LR Oopen '
- ' '
+ 0A"< %.i Oopen '
+ ''
!* filename:line[:column][:] *!
- LR -A-:"=R'
+ ZJ -A-:"=R'
0U.p <-%.pA"D|1;'> Q.pA-:"=
Q.p+1C \U.a R 0U.p <-%.pA"D|1;'> Q.pA-:"=
Q.p+1C \U.l Q.aU.c R
|
Q.aU.l 1U.c
'
- |
- LR
+ !* FIXME: modifies the i *!
+ .,ZD
'
!open!
- 0X.f [*
- EBN.f Q.c-1,Q.l-1ESFINDCOLUMN:J
- ]*
- L>
-}
+ EBN[\.i] Q.c-1,Q.l-1ESFINDCOLUMN:J
+ >
+]* }