main.go 924 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "bufio"
  4. "flag"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. "src.eruta.nl/beoran/bdjncl/picol"
  9. )
  10. var fname = flag.String("f", "", "file name")
  11. func CommandPuts(i *picol.Interp, argv []string, pd interface{}) (string, error) {
  12. if len(argv) != 2 {
  13. return "", fmt.Errorf("Wrong number of args for %s %s", argv[0], argv)
  14. }
  15. fmt.Println(argv[1])
  16. return "", nil
  17. }
  18. func main() {
  19. flag.Parse()
  20. interp := picol.InitInterp()
  21. interp.RegisterCoreCommands()
  22. interp.RegisterCommand("puts", CommandPuts, nil)
  23. buf, err := ioutil.ReadFile(*fname)
  24. if err == nil {
  25. result, err := interp.Eval(string(buf))
  26. if err != nil {
  27. fmt.Println("ERRROR", result, err)
  28. }
  29. } else {
  30. for {
  31. fmt.Print("picol> ")
  32. scanner := bufio.NewReader(os.Stdin)
  33. clibuf, _ := scanner.ReadString('\n')
  34. result, err := interp.Eval(clibuf[:len(clibuf)-1])
  35. if len(result) != 0 {
  36. fmt.Println("ERRROR", result, err)
  37. }
  38. }
  39. }
  40. }