Skip to content

Instantly share code, notes, and snippets.

@khanhduytran0
Created June 22, 2020 03:54

Revisions

  1. khanhduytran0 created this gist Jun 22, 2020.
    71 changes: 71 additions & 0 deletions GLSCommandFinder.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    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_", ""));
    }
    }
    }
    }