forked from x/ContextOS
mac opt ctx.Start
This commit is contained in:
parent
9d1d188315
commit
6a09aa3a09
20
Makefile
20
Makefile
@ -46,17 +46,25 @@ DOTS=etc/dotsfile
|
|||||||
back_dotsfile:
|
back_dotsfile:
|
||||||
cp ~/.zshrc $(DOTS)
|
cp ~/.zshrc $(DOTS)
|
||||||
cp ~/.tmux.conf $(DOTS)
|
cp ~/.tmux.conf $(DOTS)
|
||||||
|
cp ~/context/.git/hooks/post-commit $(DOTS)/git_hooks
|
||||||
cp ~/.vimrc $(DOTS)
|
cp ~/.vimrc $(DOTS)
|
||||||
cp ~/.vim/syntax/shy.vim $(DOTS)
|
cp ~/.vim/syntax/shy.vim $(DOTS)
|
||||||
git status -sb $(DOTS)
|
|
||||||
|
|
||||||
load_dotsfile: ~/.zshrc ~/.tmux.conf ~/.vimrc ~/.vim/syntax/shy.vim
|
load_dotsfile:\
|
||||||
|
~/.zshrc\
|
||||||
|
~/.tmux.conf\
|
||||||
|
~/context/.git/hooks/post-commit\
|
||||||
|
~/.vimrc\
|
||||||
|
~/.vim/syntax/shy.vim
|
||||||
|
|
||||||
~/.zshrc: $(DOTS)/.zshrc
|
~/.zshrc: $(DOTS)/.zshrc
|
||||||
cp $(DOTS)/.zshrc ~/
|
cp $< $@
|
||||||
~/.tmux.conf: $(DOTS)/.tmux.conf
|
~/.tmux.conf: $(DOTS)/.tmux.conf
|
||||||
cp $(DOTS)/.tmux.conf ~/
|
cp $< $@
|
||||||
|
~/context/.git/hooks/post-commit: $(DOTS)/git_hooks/post-commit
|
||||||
|
cp $< $@
|
||||||
~/.vimrc: $(DOTS)/.vimrc
|
~/.vimrc: $(DOTS)/.vimrc
|
||||||
cp $(DOTS)/.vimrc ~/
|
cp $< $@
|
||||||
~/.vim/syntax/shy.vim: $(DOTS)/shy.vim
|
~/.vim/syntax/shy.vim: $(DOTS)/shy.vim
|
||||||
cp $(DOTS)/shy.vim ~/.vim/syntax/
|
cp $< $@
|
||||||
|
|
||||||
|
@ -4,4 +4,5 @@
|
|||||||
config load var/counter.json counter
|
config load var/counter.json counter
|
||||||
|
|
||||||
source etc/local.shy
|
source etc/local.shy
|
||||||
|
source etc/demo.shy
|
||||||
|
~shy
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
bench && break
|
bench stdio && break
|
||||||
echo "bench run error"
|
echo "bench run error"
|
||||||
echo "restarting..."
|
echo "restarting..."
|
||||||
sleep 3
|
sleep 3
|
||||||
|
@ -30,57 +30,6 @@ type CLI struct {
|
|||||||
*ctx.Context
|
*ctx.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func init_yac(m *ctx.Message) *ctx.Message {
|
|
||||||
yac := m.Sess("yac")
|
|
||||||
if yac.Cap("status") != "start" {
|
|
||||||
yac.Target().Start(yac)
|
|
||||||
yac.Cmd("train", "void", "void", "[\t ]+")
|
|
||||||
|
|
||||||
yac.Cmd("train", "key", "key", "[A-Za-z_][A-Za-z_0-9]*")
|
|
||||||
yac.Cmd("train", "num", "num", "mul{", "0", "-?[1-9][0-9]*", "0[0-9]+", "0x[0-9]+", "}")
|
|
||||||
yac.Cmd("train", "str", "str", "mul{", "\"[^\"]*\"", "'[^']*'", "}")
|
|
||||||
yac.Cmd("train", "exe", "exe", "mul{", "$", "@", "}", "key")
|
|
||||||
|
|
||||||
yac.Cmd("train", "op1", "op1", "mul{", "-z", "-n", "}")
|
|
||||||
yac.Cmd("train", "op1", "op1", "mul{", "-e", "-f", "-d", "}")
|
|
||||||
yac.Cmd("train", "op1", "op1", "mul{", "-", "+", "}")
|
|
||||||
yac.Cmd("train", "op2", "op2", "mul{", ":=", "=", "+=", "}")
|
|
||||||
yac.Cmd("train", "op2", "op2", "mul{", "+", "-", "*", "/", "%", "}")
|
|
||||||
yac.Cmd("train", "op2", "op2", "mul{", "<", "<=", ">", ">=", "==", "!=", "}")
|
|
||||||
yac.Cmd("train", "op2", "op2", "mul{", "~", "!~", "}")
|
|
||||||
|
|
||||||
yac.Cmd("train", "val", "val", "opt{", "op1", "}", "mul{", "num", "key", "str", "exe", "}")
|
|
||||||
yac.Cmd("train", "exp", "exp", "val", "rep{", "op2", "val", "}")
|
|
||||||
yac.Cmd("train", "map", "map", "key", ":", "\\[", "rep{", "key", "}", "\\]")
|
|
||||||
yac.Cmd("train", "exp", "exp", "\\{", "rep{", "map", "}", "\\}")
|
|
||||||
yac.Cmd("train", "val", "val", "opt{", "op1", "}", "(", "exp", ")")
|
|
||||||
|
|
||||||
yac.Cmd("train", "stm", "var", "var", "key", "opt{", "=", "exp", "}")
|
|
||||||
yac.Cmd("train", "stm", "let", "let", "key", "opt{", "=", "exp", "}")
|
|
||||||
yac.Cmd("train", "stm", "var", "var", "key", "<-")
|
|
||||||
yac.Cmd("train", "stm", "var", "var", "key", "<-", "opt{", "exe", "}")
|
|
||||||
yac.Cmd("train", "stm", "let", "let", "key", "<-", "opt{", "exe", "}")
|
|
||||||
|
|
||||||
yac.Cmd("train", "stm", "if", "if", "exp")
|
|
||||||
yac.Cmd("train", "stm", "else", "else")
|
|
||||||
yac.Cmd("train", "stm", "end", "end")
|
|
||||||
yac.Cmd("train", "stm", "for", "for", "opt{", "exp", ";", "}", "exp")
|
|
||||||
yac.Cmd("train", "stm", "for", "for", "index", "exp", "opt{", "exp", "}", "exp")
|
|
||||||
yac.Cmd("train", "stm", "label", "label", "exp")
|
|
||||||
yac.Cmd("train", "stm", "goto", "goto", "exp", "opt{", "exp", "}", "exp")
|
|
||||||
|
|
||||||
yac.Cmd("train", "stm", "echo", "echo", "rep{", "exp", "}")
|
|
||||||
yac.Cmd("train", "stm", "return", "return", "rep{", "exp", "}")
|
|
||||||
|
|
||||||
yac.Cmd("train", "word", "word", "mul{", "~", "!", "=", "\\?\\?", "\\?", "<", ">$", ">@", ">", "\\|", "%", "exe", "str", "[a-zA-Z0-9_/\\-.:]+", "}")
|
|
||||||
yac.Cmd("train", "cmd", "cmd", "rep{", "word", "}")
|
|
||||||
yac.Cmd("train", "exe", "exe", "$", "(", "cmd", ")")
|
|
||||||
|
|
||||||
yac.Cmd("train", "line", "line", "opt{", "mul{", "stm", "cmd", "}", "}", "mul{", ";", "\n", "#[^\n]*\n", "}")
|
|
||||||
}
|
|
||||||
return yac
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cli *CLI) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server {
|
func (cli *CLI) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server {
|
||||||
c.Caches = map[string]*ctx.Cache{
|
c.Caches = map[string]*ctx.Cache{
|
||||||
"level": &ctx.Cache{Name: "level", Value: "0", Help: "嵌套层级"},
|
"level": &ctx.Cache{Name: "level", Value: "0", Help: "嵌套层级"},
|
||||||
@ -161,13 +110,13 @@ func (cli *CLI) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if m.Option("prompt", cmd.Cmd().Conf("prompt")); cmd.Has("return") {
|
if m.Option("prompt", cmd.Cmd().Conf("prompt")); cmd.Has("return") {
|
||||||
m.Result(0, cmd.Meta["return"])
|
|
||||||
m.Options("scan_end", true)
|
m.Options("scan_end", true)
|
||||||
m.Target().Close(m)
|
m.Target().Close(m)
|
||||||
}
|
}
|
||||||
m.Optionv("ps_target", cli.target)
|
m.Optionv("ps_target", cli.target)
|
||||||
return nil
|
return nil
|
||||||
}, "scan", arg[1]).Target().Name)
|
}, "scan", arg).Target().Name)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (cli *CLI) Close(m *ctx.Message, arg ...string) bool {
|
func (cli *CLI) Close(m *ctx.Message, arg ...string) bool {
|
||||||
@ -175,6 +124,8 @@ func (cli *CLI) Close(m *ctx.Message, arg ...string) bool {
|
|||||||
case m.Target():
|
case m.Target():
|
||||||
case m.Source():
|
case m.Source():
|
||||||
}
|
}
|
||||||
|
msg := cli.Message()
|
||||||
|
msg.Append("last_target", msg.Cap("ps_target"))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,9 +335,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
pipe := m.Spawn().Copy(msg, "option").Copy(msg, "append").Cmd("cmd", rest)
|
pipe := m.Spawn().Copy(msg, "option").Copy(msg, "append").Cmd("cmd", rest)
|
||||||
|
|
||||||
msg.Set("result").Set("append")
|
msg.Set("result").Set("append")
|
||||||
m.Log("fuck", "what %v", msg.Meta)
|
|
||||||
msg.Copy(pipe, "result").Copy(pipe, "append")
|
msg.Copy(pipe, "result").Copy(pipe, "append")
|
||||||
m.Log("fuck", "what %v", msg.Meta)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Target().Message().Set("result").Set("append").Copy(msg, "result").Copy(msg, "append")
|
m.Target().Message().Set("result").Set("append").Copy(msg, "result").Copy(msg, "append")
|
||||||
@ -623,56 +572,55 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
m.Echo("%s", strings.Join(arg[1:], ""))
|
m.Echo("%s", strings.Join(arg[1:], ""))
|
||||||
}},
|
}},
|
||||||
"return": &ctx.Command{Name: "return result...", Help: "结束脚本, result: 返回值", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"return": &ctx.Command{Name: "return result...", Help: "结束脚本, result: 返回值", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
if cli, ok := m.Target().Server.(*CLI); ok {
|
||||||
|
msg := cli.Message()
|
||||||
|
msg.Result(-2, arg[1:])
|
||||||
|
}
|
||||||
m.Add("append", "return", arg[1:])
|
m.Add("append", "return", arg[1:])
|
||||||
}},
|
}},
|
||||||
"source": &ctx.Command{Name: "source [stdio [init.shy [exit.shy]]]|[filename [async]]|string", Help: "解析脚本, filename: 文件名, async: 异步执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"source": &ctx.Command{Name: "source [stdio [init.shy [exit.shy]]]|[filename [async]]|string", Help: "解析脚本, filename: 文件名, async: 异步执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
init_yac(m)
|
|
||||||
|
|
||||||
if arg[0] != "stdio" {
|
|
||||||
if !m.Sess("nfs").Cmd("path", arg[0]).Results(0) {
|
|
||||||
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
|
||||||
switch msg.Cmd().Detail(0) {
|
|
||||||
case "cmd":
|
|
||||||
m.Set("append").Copy(msg, "append").Set("result").Copy(msg, "result")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}, "parse", "line", "void", strings.Join(arg, " "))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := m.Source().Server.(*CLI); ok {
|
if _, ok := m.Source().Server.(*CLI); ok {
|
||||||
msg := m.Spawn(c)
|
msg := m.Spawn(c)
|
||||||
m.Copy(msg, "target")
|
m.Copy(msg, "target")
|
||||||
}
|
}
|
||||||
|
|
||||||
name := fmt.Sprintf("shell%d", m.Capi("nshell", 1))
|
if len(arg) == 0 || arg[0] == "stdio" {
|
||||||
if arg[0] == "stdio" {
|
m.Sess("log", false).Cmd("init")
|
||||||
name = "shy"
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Start(name, "shell", key, arg[0])
|
if m.Start("shy", "shell", "stdio"); m.Sess("nfs").Cmd("path", m.Confx("init.shy", arg, 1)).Results(0) {
|
||||||
|
msg := m.Spawn().Add("option", "scan_end", "false").Cmd("source", m.Conf("init.shy"))
|
||||||
if arg[0] == "stdio" {
|
m.Cap("ps_target", msg.Append("last_target"))
|
||||||
if m.Sess("nfs").Cmd("path", m.Confx("init.shy", arg, 1)).Results(0) {
|
m.Option("prompt", m.Conf("prompt"))
|
||||||
m.Spawn().Add("option", "scan_end", "false").Cmd("source", m.Conf("init.shy"))
|
m.Find("nfs.stdio").Cmd("prompt")
|
||||||
}
|
}
|
||||||
m.Option("prompt", m.Conf("prompt"))
|
if m.Wait(); m.Sess("nfs").Cmd("path", m.Confx("exit.shy", arg, 2)).Results(0) {
|
||||||
m.Find("nfs.file1").Cmd("prompt")
|
m.Spawn().Add("option", "scan_end", "false").Cmd("source", m.Conf("exit.shy"))
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(arg) < 2 || arg[1] != "async" {
|
if m.Sess("nfs").Cmd("path", arg[0]).Results(0) {
|
||||||
if arg[0] == "stdio" && len(arg) > 1 {
|
m.Start(fmt.Sprintf("shell%d", m.Capi("nshell", 1)), "shell", arg...)
|
||||||
fmt.Printf(m.Spawn().Cmd("source", arg[1]).Result(0))
|
if len(arg) < 2 || arg[1] != "async" {
|
||||||
} else {
|
|
||||||
m.Wait()
|
m.Wait()
|
||||||
|
} else {
|
||||||
|
m.Options("async", true)
|
||||||
}
|
}
|
||||||
if arg[0] == "stdio" {
|
return
|
||||||
if m.Sess("nfs").Cmd("path", m.Confx("exit.shy", arg, 2)).Results(0) {
|
}
|
||||||
m.Spawn().Add("option", "scan_end", "false").Cmd("source", m.Conf("exit.shy"))
|
|
||||||
}
|
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
||||||
|
switch msg.Cmd().Detail(0) {
|
||||||
|
case "cmd":
|
||||||
|
m.Set("append").Copy(msg, "append").Set("result").Copy(msg, "result")
|
||||||
}
|
}
|
||||||
m.Target().Close(m)
|
return nil
|
||||||
|
}, "parse", "line", "void", strings.Join(arg, " "))
|
||||||
|
}},
|
||||||
|
"arguments": &ctx.Command{Name: "arguments", Help: "脚本参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
if cli, ok := m.Source().Server.(*CLI); ok {
|
||||||
|
msg := cli.Message().Spawn().Cmd("detail", arg)
|
||||||
|
m.Copy(msg, "append").Copy(msg, "result")
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
@ -262,7 +262,6 @@ func Elect(last interface{}, args ...interface{}) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Array(m *Message, list []string, index int, arg ...interface{}) []string {
|
func Array(m *Message, list []string, index int, arg ...interface{}) []string {
|
||||||
m.Log("fuck", "waht %v %v", list, index)
|
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
if -1 < index && index < len(list) {
|
if -1 < index && index < len(list) {
|
||||||
return []string{list[index]}
|
return []string{list[index]}
|
||||||
@ -862,6 +861,7 @@ func (m *Message) Sess(key string, arg ...interface{}) *Message {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (m *Message) Call(cb func(msg *Message) (sub *Message), arg ...interface{}) *Message {
|
func (m *Message) Call(cb func(msg *Message) (sub *Message), arg ...interface{}) *Message {
|
||||||
|
m.Log("fuck", "arg --- %v", arg)
|
||||||
if m.callback = cb; len(arg) > 0 || len(m.Meta["detail"]) > 0 {
|
if m.callback = cb; len(arg) > 0 || len(m.Meta["detail"]) > 0 {
|
||||||
m.Cmd(arg...)
|
m.Cmd(arg...)
|
||||||
}
|
}
|
||||||
@ -3074,6 +3074,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
for k, v := range val {
|
for k, v := range val {
|
||||||
m.Add("append", k, v)
|
m.Add("append", k, v)
|
||||||
}
|
}
|
||||||
|
sort.Strings(m.Meta["append"])
|
||||||
m.Table()
|
m.Table()
|
||||||
// for k, v := range val {
|
// for k, v := range val {
|
||||||
// m.Add("append", "key", k)
|
// m.Add("append", "key", k)
|
||||||
@ -3084,6 +3085,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
for k, v := range val {
|
for k, v := range val {
|
||||||
m.Add("append", k, v)
|
m.Add("append", k, v)
|
||||||
}
|
}
|
||||||
|
sort.Strings(m.Meta["append"])
|
||||||
m.Table()
|
m.Table()
|
||||||
// for k, v := range val {
|
// for k, v := range val {
|
||||||
// m.Add("append", "key", k)
|
// m.Add("append", "key", k)
|
||||||
@ -3097,10 +3099,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
for k, v := range value {
|
for k, v := range value {
|
||||||
m.Add("append", k, v)
|
m.Add("append", k, v)
|
||||||
}
|
}
|
||||||
|
sort.Strings(m.Meta["append"])
|
||||||
case map[string]string:
|
case map[string]string:
|
||||||
for k, v := range value {
|
for k, v := range value {
|
||||||
m.Add("append", k, v)
|
m.Add("append", k, v)
|
||||||
}
|
}
|
||||||
|
sort.Strings(m.Meta["append"])
|
||||||
default:
|
default:
|
||||||
m.Add("append", "index", i)
|
m.Add("append", "index", i)
|
||||||
m.Add("append", "value", v)
|
m.Add("append", "value", v)
|
||||||
@ -3213,7 +3217,6 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
if m.Meta["parse"][1] != "" {
|
if m.Meta["parse"][1] != "" {
|
||||||
value = Chain(m, value, m.Meta["parse"][1])
|
value = Chain(m, value, m.Meta["parse"][1])
|
||||||
}
|
}
|
||||||
m.Log("fuck", "what %v", value)
|
|
||||||
|
|
||||||
switch val := value.(type) {
|
switch val := value.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
@ -3336,7 +3339,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(args ...string) {
|
func Start() {
|
||||||
Index.root = Index
|
Index.root = Index
|
||||||
Pulse.root = Pulse
|
Pulse.root = Pulse
|
||||||
|
|
||||||
@ -3345,44 +3348,20 @@ func Start(args ...string) {
|
|||||||
m.target.Begin(m)
|
m.target.Begin(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
Pulse.Sess("tcp", "tcp")
|
for k, c := range Index.contexts {
|
||||||
Pulse.Sess("nfs", "nfs")
|
Pulse.Sess(k, c)
|
||||||
Pulse.Sess("lex", "lex")
|
|
||||||
Pulse.Sess("yac", "yac")
|
|
||||||
Pulse.Sess("cli", "cli")
|
|
||||||
|
|
||||||
Pulse.Sess("ssh", "ssh")
|
|
||||||
Pulse.Sess("mdb", "mdb")
|
|
||||||
Pulse.Sess("aaa", "aaa")
|
|
||||||
Pulse.Sess("web", "web")
|
|
||||||
Pulse.Sess("log", "log")
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
|
||||||
if _, e := os.Stat(args[0]); e == nil {
|
|
||||||
Pulse.Sess("cli", false).Conf("init.shy", args[0])
|
|
||||||
args = args[1:]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args := os.Args[1:]
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
if _, e := os.Stat(args[0]); e == nil {
|
if strings.HasSuffix(args[0], ".log") {
|
||||||
Pulse.Sess("log", false).Conf("bench.log", args[0])
|
Pulse.Sess("log", false).Conf("bench.log", args[0])
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) > 0 {
|
Pulse.Sess("yac", false).Cmd("init")
|
||||||
Pulse.Options("log", false)
|
for _, v := range Pulse.Sess("cli", false).Cmd("source", args).Meta["result"] {
|
||||||
|
fmt.Printf("%v", v)
|
||||||
cmd := Pulse.Sess("cli", false).Cmd("source", args)
|
|
||||||
for _, v := range cmd.Meta["result"] {
|
|
||||||
fmt.Printf("%v", v)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Pulse.Options("log", true)
|
|
||||||
|
|
||||||
log := Pulse.Sess("log", false)
|
|
||||||
log.target.Start(log)
|
|
||||||
|
|
||||||
Pulse.Sess("cli", false).Cmd("source", "stdio")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,6 @@ func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
|||||||
return log
|
return log
|
||||||
}
|
}
|
||||||
func (log *LOG) Start(m *ctx.Message, arg ...string) bool {
|
func (log *LOG) Start(m *ctx.Message, arg ...string) bool {
|
||||||
defer func() {
|
|
||||||
e := recover()
|
|
||||||
_ = e
|
|
||||||
}()
|
|
||||||
log.out = m.Sess("nfs").Cmd("open", m.Confx("bench.log", arg, 0)).Optionv("out").(*os.File)
|
|
||||||
log.out.Truncate(0)
|
|
||||||
fmt.Fprintln(log.out, "\n\n")
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (log *LOG) Close(m *ctx.Message, arg ...string) bool {
|
func (log *LOG) Close(m *ctx.Message, arg ...string) bool {
|
||||||
@ -67,6 +60,13 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
|||||||
"log_name": &ctx.Config{Name: "log_name", Value: "dump", Help: "日志屏蔽类型"},
|
"log_name": &ctx.Config{Name: "log_name", Value: "dump", Help: "日志屏蔽类型"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
|
"init": &ctx.Command{Name: "init file", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
if log, ok := m.Target().Server.(*LOG); ok {
|
||||||
|
log.out = m.Sess("nfs").Cmd("open", m.Confx("bench.log", arg, 0)).Optionv("out").(*os.File)
|
||||||
|
log.out.Truncate(0)
|
||||||
|
fmt.Fprintln(log.out, "\n\n")
|
||||||
|
}
|
||||||
|
}},
|
||||||
"log": &ctx.Command{Name: "log level string...", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"log": &ctx.Command{Name: "log level string...", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) && log.out != nil {
|
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) && log.out != nil {
|
||||||
if m.Confs("silent", arg[0]) {
|
if m.Confs("silent", arg[0]) {
|
||||||
|
@ -661,6 +661,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
}
|
}
|
||||||
if msg.Append("file_pos0") != "" {
|
if msg.Append("file_pos0") != "" {
|
||||||
i = msg.Appendi("file_pos0") - 1
|
i = msg.Appendi("file_pos0") - 1
|
||||||
|
msg.Append("file_pos0", "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
line = ""
|
line = ""
|
||||||
@ -897,7 +898,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if p, f, e := open(m, arg[0]); m.Assert(e) {
|
if p, f, e := open(m, arg[0], os.O_RDWR); m.Assert(e) {
|
||||||
m.Optionv("in", f)
|
m.Optionv("in", f)
|
||||||
m.Start(m.Confx("nfs_name", arg, 1), help, key, p)
|
m.Start(m.Confx("nfs_name", arg, 1), help, key, p)
|
||||||
}
|
}
|
||||||
|
@ -140,9 +140,15 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
m := web.Message().Log("info", "").Log("info", "%v %s %s", r.RemoteAddr, r.Method, r.URL)
|
m := web.Message()
|
||||||
|
|
||||||
if m.Confs("logheaders") {
|
index := r.Header.Get("index_module") == ""
|
||||||
|
r.Header.Set("index_module", m.Cap("module"))
|
||||||
|
|
||||||
|
if index {
|
||||||
|
m.Log("info", "").Log("info", "%v %s %s", r.RemoteAddr, r.Method, r.URL)
|
||||||
|
}
|
||||||
|
if index && m.Confs("logheaders") {
|
||||||
for k, v := range r.Header {
|
for k, v := range r.Header {
|
||||||
m.Log("info", "%s: %v", k, v)
|
m.Log("info", "%s: %v", k, v)
|
||||||
}
|
}
|
||||||
@ -155,7 +161,7 @@ func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
web.ServeMux.ServeHTTP(w, r)
|
web.ServeMux.ServeHTTP(w, r)
|
||||||
|
|
||||||
if m.Confs("logheaders") {
|
if index && m.Confs("logheaders") {
|
||||||
for k, v := range w.Header() {
|
for k, v := range w.Header() {
|
||||||
m.Log("info", "%s: %v", k, v)
|
m.Log("info", "%s: %v", k, v)
|
||||||
}
|
}
|
||||||
|
@ -323,6 +323,51 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
"label": &ctx.Config{Name: "嵌套标记", Value: "####################", Help: "嵌套层级日志的标记"},
|
"label": &ctx.Config{Name: "嵌套标记", Value: "####################", Help: "嵌套层级日志的标记"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
|
"init": &ctx.Command{Name: "init", Help: "添加语法规则, page: 语法集合, hash: 语句类型, word: 语法模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
m.Cmd("train", "void", "void", "[\t ]+")
|
||||||
|
|
||||||
|
m.Cmd("train", "key", "key", "[A-Za-z_][A-Za-z_0-9]*")
|
||||||
|
m.Cmd("train", "num", "num", "mul{", "0", "-?[1-9][0-9]*", "0[0-9]+", "0x[0-9]+", "}")
|
||||||
|
m.Cmd("train", "str", "str", "mul{", "\"[^\"]*\"", "'[^']*'", "}")
|
||||||
|
m.Cmd("train", "exe", "exe", "mul{", "$", "@", "}", "key")
|
||||||
|
|
||||||
|
m.Cmd("train", "op1", "op1", "mul{", "-z", "-n", "}")
|
||||||
|
m.Cmd("train", "op1", "op1", "mul{", "-e", "-f", "-d", "}")
|
||||||
|
m.Cmd("train", "op1", "op1", "mul{", "-", "+", "}")
|
||||||
|
m.Cmd("train", "op2", "op2", "mul{", ":=", "=", "+=", "}")
|
||||||
|
m.Cmd("train", "op2", "op2", "mul{", "+", "-", "*", "/", "%", "}")
|
||||||
|
m.Cmd("train", "op2", "op2", "mul{", "<", "<=", ">", ">=", "==", "!=", "}")
|
||||||
|
m.Cmd("train", "op2", "op2", "mul{", "~", "!~", "}")
|
||||||
|
|
||||||
|
m.Cmd("train", "val", "val", "opt{", "op1", "}", "mul{", "num", "key", "str", "exe", "}")
|
||||||
|
m.Cmd("train", "exp", "exp", "val", "rep{", "op2", "val", "}")
|
||||||
|
m.Cmd("train", "map", "map", "key", ":", "\\[", "rep{", "key", "}", "\\]")
|
||||||
|
m.Cmd("train", "exp", "exp", "\\{", "rep{", "map", "}", "\\}")
|
||||||
|
m.Cmd("train", "val", "val", "opt{", "op1", "}", "(", "exp", ")")
|
||||||
|
|
||||||
|
m.Cmd("train", "stm", "var", "var", "key", "opt{", "=", "exp", "}")
|
||||||
|
m.Cmd("train", "stm", "let", "let", "key", "opt{", "=", "exp", "}")
|
||||||
|
m.Cmd("train", "stm", "var", "var", "key", "<-")
|
||||||
|
m.Cmd("train", "stm", "var", "var", "key", "<-", "opt{", "exe", "}")
|
||||||
|
m.Cmd("train", "stm", "let", "let", "key", "<-", "opt{", "exe", "}")
|
||||||
|
|
||||||
|
m.Cmd("train", "stm", "if", "if", "exp")
|
||||||
|
m.Cmd("train", "stm", "else", "else")
|
||||||
|
m.Cmd("train", "stm", "end", "end")
|
||||||
|
m.Cmd("train", "stm", "for", "for", "opt{", "exp", ";", "}", "exp")
|
||||||
|
m.Cmd("train", "stm", "for", "for", "index", "exp", "opt{", "exp", "}", "exp")
|
||||||
|
m.Cmd("train", "stm", "label", "label", "exp")
|
||||||
|
m.Cmd("train", "stm", "goto", "goto", "exp", "opt{", "exp", "}", "exp")
|
||||||
|
|
||||||
|
m.Cmd("train", "stm", "echo", "echo", "rep{", "exp", "}")
|
||||||
|
m.Cmd("train", "stm", "return", "return", "rep{", "exp", "}")
|
||||||
|
|
||||||
|
m.Cmd("train", "word", "word", "mul{", "~", "!", "=", "\\?\\?", "\\?", "<", ">$", ">@", ">", "\\|", "%", "exe", "str", "[a-zA-Z0-9_/\\-.:]+", "}")
|
||||||
|
m.Cmd("train", "cmd", "cmd", "rep{", "word", "}")
|
||||||
|
m.Cmd("train", "exe", "exe", "$", "(", "cmd", ")")
|
||||||
|
|
||||||
|
m.Cmd("train", "line", "line", "opt{", "mul{", "stm", "cmd", "}", "}", "mul{", ";", "\n", "#[^\n]*\n", "}")
|
||||||
|
}},
|
||||||
"train": &ctx.Command{Name: "train page hash word...", Help: "添加语法规则, page: 语法集合, hash: 语句类型, word: 语法模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"train": &ctx.Command{Name: "train page hash word...", Help: "添加语法规则, page: 语法集合, hash: 语句类型, word: 语法模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) {
|
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) {
|
||||||
page, ok := yac.page[arg[0]]
|
page, ok := yac.page[arg[0]]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
// 数据层
|
// 数据层
|
||||||
_ "contexts/mdb" //数据中心
|
_ "contexts/mdb" //数据中心
|
||||||
_ "contexts/nfs" //存储中心
|
_ "contexts/nfs" //存储中心
|
||||||
@ -27,5 +26,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c.Start(os.Args[1:]...)
|
c.Start()
|
||||||
}
|
}
|
||||||
|
@ -155,17 +155,22 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"/counter": &ctx.Command{Name: "/counter", Help: "/counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"/counter": &ctx.Command{Name: "/counter", Help: "/counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if m.Has("name") && m.Has("count") {
|
if len(arg) > 0 {
|
||||||
count := m.Optioni("count")
|
m.Option("name", arg[0])
|
||||||
switch v := m.Confv("counter", m.Option("name")).(type) {
|
|
||||||
case string:
|
|
||||||
i, e := strconv.Atoi(v)
|
|
||||||
m.Assert(e)
|
|
||||||
count += i
|
|
||||||
}
|
|
||||||
m.Log("info", "%v: %v", m.Option("name"), m.Confv("counter", m.Option("name"), fmt.Sprintf("%d", count)))
|
|
||||||
m.Echo("%d", count)
|
|
||||||
}
|
}
|
||||||
|
if len(arg) > 1 {
|
||||||
|
m.Option("count", arg[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
count := m.Optioni("count")
|
||||||
|
switch v := m.Confv("counter", m.Option("name")).(type) {
|
||||||
|
case string:
|
||||||
|
i, e := strconv.Atoi(v)
|
||||||
|
m.Assert(e)
|
||||||
|
count += i
|
||||||
|
}
|
||||||
|
m.Log("info", "%v: %v", m.Option("name"), m.Confv("counter", m.Option("name"), fmt.Sprintf("%d", count)))
|
||||||
|
m.Echo("%d", count)
|
||||||
}},
|
}},
|
||||||
"counter": &ctx.Command{Name: "counter name count", Help: "counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"counter": &ctx.Command{Name: "counter name count", Help: "counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user