update debug log usage and add fanciness to log printing
This commit is contained in:
parent
91498926d5
commit
1f192607b2
8 changed files with 27 additions and 25 deletions
|
|
@ -17,7 +17,10 @@
|
||||||
|
|
||||||
package ast
|
package ast
|
||||||
|
|
||||||
import "gitlab.com/whom/shs/log"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"gitlab.com/whom/shs/log"
|
||||||
|
)
|
||||||
|
|
||||||
/* expected function header for any stdlib function
|
/* expected function header for any stdlib function
|
||||||
*/
|
*/
|
||||||
|
|
@ -63,6 +66,10 @@ func (f Function) ParseFunction(args *Token) bool {
|
||||||
log.Log(log.ERR,
|
log.Log(log.ERR,
|
||||||
"Incorrect number of arguments",
|
"Incorrect number of arguments",
|
||||||
"eval")
|
"eval")
|
||||||
|
log.Log(log.DEBUG,
|
||||||
|
fmt.Sprintf("Function %s expects %d arguments. You've provided %d arguments.",
|
||||||
|
f.Name, f.Args, f.Args - i),
|
||||||
|
"eval")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +96,7 @@ func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token {
|
||||||
func GetFunction(arg string, table FuncTable) *Function {
|
func GetFunction(arg string, table FuncTable) *Function {
|
||||||
target, ok := (*table)[arg]
|
target, ok := (*table)[arg]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Log(log.DEBUG,
|
log.Log(log.INFO,
|
||||||
"function " + arg + " not found",
|
"function " + arg + " not found",
|
||||||
"ftable")
|
"ftable")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func InitFromConfig(configFile string) (ast.VarTable, ast.FuncTable) {
|
||||||
|
|
||||||
util.LoadScript(configFile, vars, funcs)
|
util.LoadScript(configFile, vars, funcs)
|
||||||
|
|
||||||
log.Log(log.DEBUG,
|
log.Log(log.INFO,
|
||||||
"config file fully evaluated",
|
"config file fully evaluated",
|
||||||
"config")
|
"config")
|
||||||
return vars, funcs
|
return vars, funcs
|
||||||
|
|
|
||||||
|
|
@ -51,5 +51,5 @@ func Log(lvl int, msg, context string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("[" + context + "] " + msg)
|
fmt.Println("\033[3m[" + context + "] " + msg + "\033[0m")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ func ShsProgn(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
* (if (eq (number "3") 3) (print "test passed") (print "test failed"))
|
* (if (eq (number "3") 3) (print "test passed") (print "test failed"))
|
||||||
*/
|
*/
|
||||||
func ShsIf(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
func ShsIf(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
cond := in
|
cond := in.Copy()
|
||||||
t := cond.Next
|
t := cond.Next.Copy()
|
||||||
f := t.Next
|
f := t.Next
|
||||||
cond.Next = nil
|
cond.Next = nil
|
||||||
t.Next = nil
|
t.Next = nil
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
*/
|
*/
|
||||||
func Expand(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Token {
|
func Expand(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Token {
|
||||||
if input.Tag != ast.LIST {
|
if input.Tag != ast.LIST {
|
||||||
log.Log(log.DEBUG, "expand called on not a list", "expand")
|
log.Log(log.INFO, "expand called on not a list", "expand")
|
||||||
return input
|
return input
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ var LastExitCode int
|
||||||
func signalHandler() {
|
func signalHandler() {
|
||||||
for {
|
for {
|
||||||
<- sigChan
|
<- sigChan
|
||||||
log.Log(log.DEBUG,
|
log.Log(log.INFO,
|
||||||
"caught SIGINT",
|
"caught SIGINT",
|
||||||
"jobctl")
|
"jobctl")
|
||||||
|
|
||||||
|
|
@ -174,7 +174,11 @@ func LaunchProcess(
|
||||||
stderr io.Writer ) {
|
stderr io.Writer ) {
|
||||||
c, cancel := context.WithCancel(context.Background())
|
c, cancel := context.WithCancel(context.Background())
|
||||||
cmd := exec.CommandContext(c, path, args...)
|
cmd := exec.CommandContext(c, path, args...)
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{Foreground: !background, Setpgid: true}
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||||
|
|
||||||
|
if !background {
|
||||||
|
cmd.SysProcAttr.Foreground = true
|
||||||
|
}
|
||||||
|
|
||||||
if stdin == nil {
|
if stdin == nil {
|
||||||
stdin = os.Stdin
|
stdin = os.Stdin
|
||||||
|
|
@ -201,6 +205,7 @@ func LaunchProcess(
|
||||||
CurCancel = &cancel
|
CurCancel = &cancel
|
||||||
|
|
||||||
if background {
|
if background {
|
||||||
|
cmd.Process.Signal(syscall.SIGTSTP)
|
||||||
go func(){
|
go func(){
|
||||||
waitChan <- cmd.Wait()
|
waitChan <- cmd.Wait()
|
||||||
delete(JobMap, cpid)
|
delete(JobMap, cpid)
|
||||||
|
|
@ -317,7 +322,7 @@ func Fg(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
ipid := int(pid)
|
ipid := int(pid)
|
||||||
proc, ok := JobMap[ipid]
|
_, ok := JobMap[ipid]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Log(log.ERR,
|
log.Log(log.ERR,
|
||||||
"Process not found, was it started by this shell?",
|
"Process not found, was it started by this shell?",
|
||||||
|
|
@ -325,17 +330,7 @@ func Fg(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := proc.Ctl
|
tcsetpgrp(0, ipid)
|
||||||
cmd.Process.Signal(syscall.SIGCONT)
|
|
||||||
err = cmd.Wait()
|
|
||||||
if err != nil {
|
|
||||||
if exitError, ok := err.(*exec.ExitError); ok {
|
|
||||||
LastExitCode = exitError.ExitCode()
|
|
||||||
} else {
|
|
||||||
log.Log(log.ERR, "Execution step returned error: " + err.Error(), "call")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ func GenFuncTable() ast.FuncTable {
|
||||||
Function: Fg,
|
Function: Fg,
|
||||||
Name: "foreground",
|
Name: "foreground",
|
||||||
TimesCalled: 0,
|
TimesCalled: 0,
|
||||||
Args: 0,
|
Args: 1,
|
||||||
},
|
},
|
||||||
|
|
||||||
"$": &ast.Function{
|
"$": &ast.Function{
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ func ShellCompleter(line string, vt ast.VarTable, ft ast.FuncTable) []string {
|
||||||
|
|
||||||
fobjs, err := ioutil.ReadDir(dir)
|
fobjs, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(log.DEBUG,
|
log.Log(log.INFO,
|
||||||
"couldnt read dir " + dir + ": " + err.Error(),
|
"couldnt read dir " + dir + ": " + err.Error(),
|
||||||
"complete")
|
"complete")
|
||||||
if path {
|
if path {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue