Changeset 2641
- Timestamp:
- 25/02/2010 23:20:27 (2 years ago)
- Location:
- box/trunk/bin/bbackupquery
- Files:
-
- 3 edited
-
BackupQueries.cpp (modified) (3 diffs)
-
BackupQueries.h (modified) (1 diff)
-
bbackupquery.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbackupquery/BackupQueries.cpp
r2636 r2641 64 64 #define COMMAND_RETURN_ERROR 4 65 65 66 // Data about commands 67 QueryCommandSpecification commands[] = 68 { 69 { "quit", "" }, 70 { "exit", "" }, 71 { "list", "rodIFtTash", }, 72 { "pwd", "" }, 73 { "cd", "od" }, 74 { "lcd", "" }, 75 { "sh", "" }, 76 { "getobject", "" }, 77 { "get", "i" }, 78 { "compare", "alcqAEQ" }, 79 { "restore", "drif" }, 80 { "help", "" }, 81 { "usage", "m" }, 82 { "undelete", "" }, 83 { "delete", "" }, 84 { NULL, NULL } 85 }; 86 87 const char *alias[] = {"ls", 0}; 88 const int aliasIs[] = {Command_List, 0}; 89 66 90 // -------------------------------------------------------------------------- 67 91 // … … 100 124 { 101 125 } 102 103 typedef struct104 {105 const char* name;106 const char* opts;107 } QueryCommandSpecification;108 126 109 127 // -------------------------------------------------------------------------- … … 207 225 return; 208 226 } 209 210 // Data about commands 211 static QueryCommandSpecification commands[] = 212 { 213 { "quit", "" }, 214 { "exit", "" }, 215 { "list", "rodIFtTash", }, 216 { "pwd", "" }, 217 { "cd", "od" }, 218 { "lcd", "" }, 219 { "sh", "" }, 220 { "getobject", "" }, 221 { "get", "i" }, 222 { "compare", "alcqAEQ" }, 223 { "restore", "drif" }, 224 { "help", "" }, 225 { "usage", "m" }, 226 { "undelete", "" }, 227 { "delete", "" }, 228 { NULL, NULL } 229 }; 230 231 typedef enum 232 { 233 Command_Quit = 0, 234 Command_Exit, 235 Command_List, 236 Command_pwd, 237 Command_cd, 238 Command_lcd, 239 Command_sh, 240 Command_GetObject, 241 Command_Get, 242 Command_Compare, 243 Command_Restore, 244 Command_Help, 245 Command_Usage, 246 Command_Undelete, 247 Command_Delete, 248 } 249 CommandType; 250 251 static const char *alias[] = {"ls", 0}; 252 static const int aliasIs[] = {Command_List, 0}; 253 227 254 228 // Work out which command it is... 255 229 int cmd = 0; -
box/trunk/bin/bbackupquery/BackupQueries.h
r2430 r2641 20 20 class Configuration; 21 21 class ExcludeList; 22 23 typedef struct 24 { 25 const char* name; 26 const char* opts; 27 } 28 QueryCommandSpecification; 29 30 // Data about commands 31 extern QueryCommandSpecification commands[]; 32 33 typedef enum 34 { 35 Command_Quit = 0, 36 Command_Exit, 37 Command_List, 38 Command_pwd, 39 Command_cd, 40 Command_lcd, 41 Command_sh, 42 Command_GetObject, 43 Command_Get, 44 Command_Compare, 45 Command_Restore, 46 Command_Help, 47 Command_Usage, 48 Command_Undelete, 49 Command_Delete, 50 } 51 CommandType; 52 53 extern const char *alias[]; 54 extern const int aliasIs[]; 22 55 23 56 // -------------------------------------------------------------------------- -
box/trunk/bin/bbackupquery/bbackupquery.cpp
r2604 r2641 75 75 } 76 76 77 #ifdef HAVE_LIBREADLINE 78 // copied from: http://tiswww.case.edu/php/chet/readline/readline.html#SEC44 79 80 char * command_generator(const char *text, int state) 81 { 82 static int list_index, len; 83 const char *name; 84 85 /* 86 * If this is a new word to complete, initialize now. This includes 87 * saving the length of TEXT for efficiency, and initializing the index 88 * variable to 0. 89 */ 90 if(!state) 91 { 92 list_index = 0; 93 len = strlen(text); 94 } 95 96 /* Return the next name which partially matches from the command list. */ 97 while((name = commands[list_index].name)) 98 { 99 list_index++; 100 101 if(::strncmp(name, text, len) == 0 && !(state--)) 102 { 103 return ::strdup(name); 104 } 105 } 106 107 list_index = 0; 108 109 while((name = alias[list_index])) 110 { 111 list_index++; 112 113 if(::strncmp(name, text, len) == 0 && !(state--)) 114 { 115 return ::strdup(name); 116 } 117 } 118 119 /* If no names matched, then return NULL. */ 120 return (char *) NULL; 121 } 122 123 char ** bbackupquery_completion(const char *text, int start, int end) 124 { 125 char **matches; 126 127 matches = (char **)NULL; 128 129 /* If this word is at the start of the line, then it is a command 130 * to complete. Otherwise it is the name of a file in the current 131 * directory. 132 */ 133 if (start == 0) 134 { 135 matches = rl_completion_matches(text, command_generator); 136 } 137 138 return matches; 139 } 140 141 #endif // HAVE_LIBREADLINE 142 77 143 int main(int argc, const char *argv[]) 78 144 { … … 370 436 using_history(); 371 437 #endif 438 /* Allow conditional parsing of the ~/.inputrc file. */ 439 rl_readline_name = "bbackupquery"; 440 441 /* Tell the completer that we want a crack first. */ 442 rl_attempted_completion_function = bbackupquery_completion; 443 372 444 char *last_cmd = 0; 373 445 while(!context.Stop())
Note: See TracChangeset
for help on using the changeset viewer.
