Skip to content

Instantly share code, notes, and snippets.

@khanhduytran0
Created June 22, 2020 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khanhduytran0/78a27f050bf0bc9fb05bb67dfc9b842d to your computer and use it in GitHub Desktop.
Save khanhduytran0/78a27f050bf0bc9fb05bb67dfc9b842d to your computer and use it in GitHub Desktop.
gl-streaming command finder from command index
import java.util.*;
import java.io.*;
public class GLSCommandFinder
{
private static final String glsCmdHeaderPath = "/sdcard/AppProjects/gl-streaming/common/gls_command.h";
private static List<Integer> cmdlineList;
private static List<String> commandList;
public static void main(String[] args)
{
System.out.println("GLStreaming command finder");
System.out.print("Loading commands... ");
try {
loadCommandList();
System.out.println("Loaded " + cmdlineList.size() + " commands!");
} catch (Throwable th) {
System.err.println("Error loading command!");
th.printStackTrace();
return;
}
Scanner input = new Scanner(System.in);
System.out.print("Enter index of command: ");
int index = input.nextInt();
if (index < 0 || index >= cmdlineList.size()) {
throw new ArrayIndexOutOfBoundsException("Index was not inside loaded command list range");
}
System.out.println("Found command:");
System.out.println(" Index : " + cmdlineList.get(index));
System.out.println(" Command: " + commandList.get(index));
}
private static void loadCommandList() throws FileNotFoundException, IOException {
cmdlineList = new ArrayList<Integer>();
commandList = new ArrayList<String>();
BufferedReader bis = new BufferedReader(new FileReader(glsCmdHeaderPath));
String line;
boolean isInsideCmd = false;
int lineNumber = 0;
while ((line = bis.readLine()) != null) {
lineNumber++;
if (line.equals("enum GL_Server_Command")) {
isInsideCmd = true;
continue;
} else if (isInsideCmd) {
if (line.equals("};")) {
isInsideCmd = false;
break;
} else if (line.contains("{")) {
continue;
}
String processedString = line.replaceAll("[\\s||(,)]", "");
if (processedString.isEmpty() || processedString.startsWith("//") || processedString.contains("{")) {
continue;
} else if (!processedString.startsWith("GLSC_")) {
String errorMsg = "Error: Line " + lineNumber + " was not starting with \"GLSC_\".";
System.err.println("\n" + errorMsg);
System.err.println(processedString);
throw new IllegalArgumentException(errorMsg);
}
cmdlineList.add(lineNumber);
commandList.add(processedString.replace("GLSC_", ""));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment