Changeset 1962 for Whitix/trunk/user/sdk/console/tab.c
- Timestamp:
- 03/01/09 11:43:05 (3 years ago)
- Files:
-
- 1 modified
-
Whitix/trunk/user/sdk/console/tab.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/trunk/user/sdk/console/tab.c
r1668 r1962 22 22 } 23 23 24 int stringCompare(const void* p1, const void* p2) 25 { 26 return strcasecmp(*(char**)p1, *(char**)p2); 27 } 28 24 29 void ConsDoTabComplete(struct ConsReadContext* context, int i, char* prompt, int promptColor) 25 30 { … … 28 33 char* readBuffer=context->readBuffer; 29 34 char* start, *end; 35 char* tabInput; 30 36 31 37 ConsTokenGetStr(readBuffer, i, &start, &end); … … 40 46 memset(results, 0, TABS_TOTAL*sizeof(char*)); 41 47 42 char* tabInput; 43 44 tabInput=strndup(start, end-start); 48 /* Keep a copy for manipulation. */ 49 tabInput = strndup(start, end-start); 45 50 46 51 /* Copy the output from tabCompleter, which consists of strdup'ed strings, 47 52 * until it returns NULL or we run out of results. */ 48 while (total < TABS_TOTAL && (results[total] =context->tabCompleter(context, tabInput, total)))53 while (total < TABS_TOTAL && (results[total] = context->tabCompleter(context, tabInput, total))) 49 54 total++; 50 55 51 56 if (total > 1) 52 57 { 58 int start = 0; 59 53 60 /* If there's more than one possible completion, print the results to 54 61 * the console. */ 55 62 fputc('\n', stdout); 63 64 /* Sort into alphabetical order. */ 65 qsort(results, total, sizeof(char*), stringCompare); 56 66 57 67 for (j=0; j<total; j++) … … 62 72 puts(results[j]); 63 73 } 64 65 #if 066 int dist;67 74 68 /* TODO: MCSS of string. compare to previous string. */ 69 70 int lCd=dist; 71 72 for (j=1; j<total; j++) 73 { 74 int dist=0; 75 char* str=start; 76 77 while (results[j][dist++] == *str++); 78 79 if (dist < lCd) 80 lCd=dist; 81 } 82 83 printf("lCd = %d\n", lCd); 84 85 if (lCd > 0) 86 /* TODO: Insert string. */ 87 strcat(readBuffer, results[0]+strlen(start)); 88 #endif 75 /* Find the longest common prefix of the string, so we can update the 76 * prompt and help the user out. 77 */ 89 78 90 79 /* Render the prompt and readBuffer again. TODO: Call bufferUpdate? */ 91 ConsSetForeColor(promptColor);80 ConsSetForeColor(promptColor); 92 81 fputs(prompt, stdout); 93 82 ConsSetForeColor(CONS_COLOR_WHITE); 94 int start=0;95 83 84 /* Go through and render the prefix line of text? TODO: Bug here. 85 * Type 'm' and the line won't render again properly. 86 */ 96 87 for (j=0; j < strlen(readBuffer); j++) 97 88 { … … 99 90 { 100 91 context->tabSetup(context, readBuffer, start, j-1); 92 101 93 ConsBufferUpdate(context, j-1, -1); 102 94 putchar(' '); … … 115 107 /* Complete the only result, and render it to the console. */ 116 108 char* begin=start+strlen(start); 117 // int numChars=strlen(results[0])-(end-start);118 119 /* Insert the results[0]+strlen(start) string at start+strlen(start) */120 // memmove(121 122 // printf("start = %s, %d, %s\n", start, strlen(start), end);123 124 /* Move the rest of the string to the right by the number of new characters125 * from results[0] */126 #if 0127 memmove(end+numChars, end, numChars);128 129 printf("numChars = %d, readBuffer = '%s'\n", numChars, readBuffer);130 while (1);131 #endif132 109 133 110 strcpy(end-1, results[0]+(end-start-1)); 134 111 135 112 ConsBufferUpdate(context, begin-readBuffer, 1); 136 137 113 ConsCursorMoveRel(strlen(readBuffer)-(begin-readBuffer), 0); 138 114
