mirror of
https://github.com/hymkor/lispect.git
synced 2026-09-05 16:47:42 -04:00
Read script from argv[1]
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
|||||||
|
(spawn "cmd.exe")
|
||||||
|
(let ((ctrlc (format nil "~A" (convert 3 <character>))))
|
||||||
|
(block main
|
||||||
|
(while t
|
||||||
|
(case (expect* "xxx" "yyy")
|
||||||
|
((0)
|
||||||
|
(sendln (string-append ctrlc "exit"))
|
||||||
|
(return-from main nil)
|
||||||
|
)
|
||||||
|
((1)
|
||||||
|
(sendln (string-append ctrlc "rem"))
|
||||||
|
)
|
||||||
|
))))
|
||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -52,7 +53,7 @@ func (g *Global) expect(ctx context.Context, w *gmnlisp.World, args []gmnlisp.No
|
|||||||
return gmnlisp.Integer(result), nil
|
return gmnlisp.Integer(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mains() error {
|
func mains(args []string) error {
|
||||||
term, err := NewTerm()
|
term, err := NewTerm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -76,24 +77,26 @@ func mains() error {
|
|||||||
gmnlisp.NewSymbol("expect*"): &gmnlisp.Function{Min: 1, F: g.expect},
|
gmnlisp.NewSymbol("expect*"): &gmnlisp.Function{Min: 1, F: g.expect},
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err = lisp.Interpret(context.Background(), `
|
if len(args) <= 0 {
|
||||||
(spawn "cmd.exe")
|
return errors.New("script path required")
|
||||||
(block main
|
}
|
||||||
(while t
|
script, err := os.ReadFile(args[0])
|
||||||
(case (expect* "xxx" "yyy")
|
if err != nil {
|
||||||
((0)
|
return err
|
||||||
(sendln (format nil "~Aexit" (convert 3 <character>)))
|
}
|
||||||
(return-from main nil)
|
|
||||||
)
|
posixArgv := []gmnlisp.Node{}
|
||||||
((1)
|
for _, s := range args {
|
||||||
(sendln (format nil "~Arem" (convert 3 <character>)))
|
posixArgv = append(posixArgv, gmnlisp.String(s))
|
||||||
)
|
}
|
||||||
)))`)
|
lisp = lisp.Let(&gmnlisp.Pair{Key: gmnlisp.NewSymbol("args"), Value: gmnlisp.List(posixArgv...)})
|
||||||
|
|
||||||
|
_, err = lisp.Interpret(context.Background(), string(script))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := mains(); err != nil {
|
if err := mains(os.Args[1:]); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err.Error())
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user