@@ -13,6 +13,7 @@ import (
1313 "os/exec"
1414 "path/filepath"
1515 "strings"
16+ "time"
1617)
1718
1819const (
@@ -111,23 +112,46 @@ func RunNeverscript(arguments CommandLineArguments) error {
111112 return errors .New ("ERROR - Target game must be thps3/thps4/thug1/thug2" )
112113 }
113114
114- compilationError := compiler .Compile (* arguments .FileToCompile , outputFilename , & lexer , & parser , & bytecodeCompiler )
115+ compilationChannel := make (chan compiler.Error , 1 )
116+ go func () {
117+ compilationError := compiler .Compile (* arguments .FileToCompile , outputFilename , & lexer , & parser , & bytecodeCompiler )
118+ compilationChannel <- compilationError
119+ }()
120+ var compilationError compiler.Error
121+ select {
122+ case result := <- compilationChannel :
123+ compilationError = result
124+ case <- time .After (3 * time .Second ):
125+ return errors .New ("ERROR - Compiler took too long. It probably went into an infinite loop because of a bug or an unimplemented feature" )
126+ fmt .Println ("\n WARNING - Roq decompiler froze. Some QB cannot be decompiled, e.g. adjacent line ending bytes (0x01 0x01)" )
127+ }
115128 if compilationError != nil {
116129 return errors .New (fmt .Sprintf ("ERROR %s(line %d) - %s" , filepath .Base (* arguments .FileToCompile ), compilationError .GetLineNumber (), compilationError .GetMessage ()))
117130 }
118- fmt .Printf (" Created '%s'.\n " , outputFilename )
131+ fmt .Printf ("\n Created '%s'.\n " , outputFilename )
119132
120133 if * arguments .ShowHexDump {
121- fmt .Printf ("\n %s\n " , hex .Dump (bytecodeCompiler .Bytes ))
122- } else {
123- fmt .Println ()
134+ fmt .Printf ("\n %s" , hex .Dump (bytecodeCompiler .Bytes ))
124135 }
125136
126137 if * arguments .ShowDecompiledRoq {
127- fmt .Println ("Roq decompiler output (may freeze):" )
128- roqCmd := exec .Command ("roq.exe" , "-d" , outputFilename )
129- decompiledCode , _ := roqCmd .Output ()
130- fmt .Println (string (decompiledCode ))
138+ fmt .Println ("\n Roq decompiler output:" )
139+
140+ roqChannel := make (chan string , 1 )
141+
142+ go func () {
143+ roqCmd := exec .Command ("roq.exe" , "-d" , outputFilename )
144+ decompiledCode , _ := roqCmd .Output ()
145+ roqChannel <- "\n " + strings .TrimSpace (string (decompiledCode ))
146+ }()
147+
148+ select {
149+ case decompiledRoq := <- roqChannel :
150+ fmt .Println (decompiledRoq )
151+ case <- time .After (3 * time .Second ):
152+ fmt .Println ("\n WARNING - Roq decompiler froze. Some QB cannot be decompiled, e.g. adjacent line ending bytes (0x01 0x01)" )
153+ }
154+
131155 }
132156 } else if * arguments .FileToDecompile != "" {
133157 argumentsWereSupplied = true
0 commit comments