github.com/criyle/go-sandbox@v0.10.3/cmd/runprog/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "os" 7 8 "github.com/criyle/go-sandbox/runner" 9 ) 10 11 const ( 12 pathEnv = "PATH=/usr/local/bin:/usr/bin:/bin" 13 ) 14 15 func printUsage() { 16 fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] <args>\n", os.Args[0]) 17 flag.PrintDefaults() 18 os.Exit(2) 19 } 20 21 // Status defines uoj/run_program constants 22 type Status int 23 24 // UOJ run_program constants 25 const ( 26 StatusNormal Status = iota // 0 27 StatusInvalid // 1 28 StatusRE // 2 29 StatusMLE // 3 30 StatusTLE // 4 31 StatusOLE // 5 32 StatusBan // 6 33 StatusFatal // 7 34 ) 35 36 func getStatus(s runner.Status) int { 37 switch s { 38 case runner.StatusNormal: 39 return int(StatusNormal) 40 case runner.StatusInvalid: 41 return int(StatusInvalid) 42 case runner.StatusTimeLimitExceeded: 43 return int(StatusTLE) 44 case runner.StatusMemoryLimitExceeded: 45 return int(StatusMLE) 46 case runner.StatusOutputLimitExceeded: 47 return int(StatusOLE) 48 case runner.StatusDisallowedSyscall: 49 return int(StatusBan) 50 case runner.StatusSignalled, runner.StatusNonzeroExitStatus: 51 return int(StatusRE) 52 default: 53 return int(StatusFatal) 54 } 55 } 56 57 func debug(v ...interface{}) { 58 if showDetails { 59 fmt.Fprintln(os.Stderr, v...) 60 } 61 }