Changeset 1965 for Whitix/trunk
- Timestamp:
- 03/09/09 17:44:32 (3 years ago)
- Files:
-
- 1 modified
-
Whitix/trunk/user/sdk/console/tab.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/trunk/user/sdk/console/tab.c
r1962 r1965 29 29 void ConsDoTabComplete(struct ConsReadContext* context, int i, char* prompt, int promptColor) 30 30 { 31 int total=0, j;31 int total=0, min, j, k; 32 32 char* results[TABS_TOTAL]; 33 33 char* readBuffer=context->readBuffer; 34 34 char* start, *end; 35 35 char* tabInput; 36 char buffer; 36 37 37 38 ConsTokenGetStr(readBuffer, i, &start, &end); … … 76 77 * prompt and help the user out. 77 78 */ 79 80 /* Get the length of the shortest string. */ 81 min = strlen(results[0]); 82 for(j=1; j<total; j++) 83 { 84 if(strlen(results[j]) < min) 85 min = strlen(results[j]); 86 } 87 88 /* The result. */ 89 char res[min+1]; 90 91 /* Get the longest common prefix. */ 92 for(j=0; j<min; j++) 93 { 94 buffer = results[0][j]; 95 for(k=1; k<total; k++) 96 { 97 if(buffer != results[k][j]) 98 { 99 /* Exit the loops. */ 100 goto out; 101 } 102 } 103 res[j] = buffer; 104 } 78 105 79 /* Render the prompt and readBuffer again. TODO: Call bufferUpdate? */ 106 out: 107 res[j] = '\0'; 108 /* Update the buffer. */ 109 strcpy(context->readBuffer,res); 110 111 /* Render the prompt and readBuffer again. */ 80 112 ConsSetForeColor(promptColor); 81 113 fputs(prompt, stdout); … … 97 129 } 98 130 99 if (j > 0 && j > start+1)131 if (j > 0 && j >= start+1) 100 132 { 101 context->tabSetup(context, readBuffer, start, j); 133 context->tabSetup(context, readBuffer, start, j); 102 134 ConsBufferUpdate(context, j-1, -1); 103 135 }
