Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Shell wildcard tokenizer
    primarykey
    data
    text
    <p>My Java is extremely rusty and I'm stuck trying to make a user interface that simplifies the execution of shell scripts or batch files depending on whether it's Linus or Win32 respectively. The files have the following naming convention.</p> <pre><code> module-verb-object-etc [args-list] mysql-connect-grid mysql-connect-rds mysql-dump-grid mysql-dump-grid-se314 </code></pre> <p>ultimately I would like it to parse unambiguous terms so I can:</p> <ol> <li>tokenize the commands (e.g delimited by "-") &amp; shorten them into simplified terms soemthing like foxpro's command window or cisco's IOS (eg "my co gr" executes "mysql-connect-grid" in unix and *.cmd in win32)</li> <li>and also in the style of IOS allow the user to enter abbreviated commands so that they can type in a question mark (?) and it will give them a hint as to the unique remaining (or next) command options (e.g. "my?" returns mysql &amp; "my ?" returns connect, or dump). Othr return values would be "ambiguous" or "unknown" for commands that are not unique or could not be matched. It may seem trivial but there are many hundreds of commands in each folder and my users don't want to think... </li> </ol> <p>I wrote a function to pull the list of files from a directory &amp; retun an array of fileanmes. Then I convert that into a 2 dimensional array using the method below which returns a dynamicly sized grid of potential commands.</p> <pre><code> /********************************************************************************** * MAKE GRID: Parses array of filenames and tokenizes AWS cmds. * @param strs Array of filenames **********************************************************************************/ public static String [][] makeGrid(String strs[], boolean bPrint) { String tmpGrid[][]; int nMaxCols = 0; int nRows = uniqueCount(strs); int nGridRow = 0; tmpGrid = new String [nRows][]; for (int nRow=0; nRow&lt;nRows; nRow++) { String cFilename = strs[nRow]; if (!cFilename.endsWith(".cmd") // just list unix files (filter for batch files) &amp;&amp; cFilename.indexOf("-") &gt; 0 ) // make sure there's a dash in the filename { String strTokens[] = tokenize(strs[nRow], "-"); // the dash is our token deliminator int nCols = strTokens.length; if (nCols&gt;nMaxCols) nMaxCols=nCols; tmpGrid[nGridRow] = new String [nCols]; for (int nCol=0; nCol&lt;nCols; nCol++) { tmpGrid[nGridRow][nCol] = strTokens[nCol]; if (bPrint) System.out.print(" "+tmpGrid[nGridRow][nCol]); } nGridRow++; if (bPrint) System.out.println(""); } //end-if } String[][] cmdGrid = new String[nGridRow][nMaxCols]; System.arraycopy(tmpGrid, 0, cmdGrid, 0, nGridRow); // removes null rows (&amp;NPEs!) return cmdGrid; } </code></pre> <p>This returns a 2-d array (below), so <code>grid[Row-N][Col-0]</code> is a match. I'd like to pull only distinct values where <code>row[0]</code> is a wildcard match for <code>cmdToken[0] &amp;&amp; row[1]</code> is "like" <code>cmdToken[1]</code> so that my users can piece together a command until <code>"my du gr ?"</code> returns <code>"ENTER, [se314]"</code> - if that makes sense...</p> <pre><code>String[][] makeGrid: mysql dump grid se314 mysql connect grid mysql dump grid mysql connect rds </code></pre> <p>My Challenge: I cant seem to get my head around my matcher function in java. If it was SQL it would be something like: </p> <pre><code>"SELECT DISTINCT col2 FROM cmd_Grid WHERE col1 LIKE 'cmdToken1%' " </code></pre> <p>or even better: recursively setting a int depthmark for each consecutive column</p> <pre><code>`SELECT DISTINCT col+str(depthmark+1) FROM cmd_Grid WHERE col+str(depthmark) LIKE 'cmdMatchedTokens%' " </code></pre> <p>until you have an exact match. </p> <p>I found a package called joSQL that I tried out of desperation but I cant seem to get it to work in Java6. Anyway: I was also hoping for a pure java solution so that everything could be contained in a single class... </p> <p>Maybe using scanner or something to parse my multidimentional array for unique values... I know I'm probably making it way more complex than it needs to be. </p> <p>a gentle nudge in the right direction would be appreciated.</p> <p>TIA</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload