Changeset 133
- Timestamp:
- Jun 3, 2010 7:36:15 PM (3 years ago)
- Location:
- trunk/filo
- Files:
-
- 2 edited
-
fs/vfs.c (modified) (1 diff)
-
main/grub/completions.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/filo/fs/vfs.c
r105 r133 241 241 devclose(); 242 242 } 243 244 int dir(char *dirname) 245 { 246 char *dev = 0; 247 const char *path; 248 int len; 249 int retval = 0; 250 int reopen; 251 252 path = strchr(dirname, ':'); 253 if (path) { 254 len = path - dirname; 255 path++; 256 dev = malloc(len + 1); 257 memcpy(dev, dirname, len); 258 dev[len] = '\0'; 259 } else { 260 /* No colon is given. Is this device or dirname? */ 261 if (dirname[0] == '/') { 262 /* Anything starts with '/' must be a dirname */ 263 dev = 0; 264 path = dirname; 265 } else { 266 dev = strdup(dirname); 267 path = 0; 268 } 269 } 270 debug("dev=%s, path=%s\n", dev, path); 271 272 if (dev && dev[0]) { 273 if (!devopen(dev, &reopen)) { 274 fsys = 0; 275 goto out; 276 } 277 if (!reopen) 278 fsys = 0; 279 } 280 281 if (path) { 282 if (!fsys || fsys == &nullfs) { 283 if (!mount_fs()) 284 goto out; 285 } 286 using_devsize = 0; 287 if (!path[0]) { 288 printf("No dirname is given.\n"); 289 goto out; 290 } 291 } else { 292 fsys = &nullfs; 293 } 294 295 filepos = 0; 296 errnum = 0; 297 298 /* set "dir" function to list completions */ 299 print_possibilities = 1; 300 301 retval = fsys->dir_func((char *) path); 302 303 out: 304 if (dev) 305 free(dev); 306 307 return retval; 308 } 309 310 -
trunk/filo/main/grub/completions.c
r103 r133 23 23 #include <config.h> 24 24 #include <grub/shared.h> 25 #define current_slice 0 25 26 26 27 static int do_completion; … … 28 29 static char *unique_string; 29 30 31 static int incomplete, disk_choice; 32 static enum 33 { 34 PART_UNSPECIFIED = 0, 35 PART_DISK, 36 PART_CHOSEN, 37 } part_choice; 38 39 int 40 real_open_partition (int flags) 41 { 42 errnum = ERR_NONE; 43 return 1; 44 } 45 46 int 47 open_partition (void) 48 { 49 return real_open_partition (0); 50 } 51 52 char * 53 set_device (char *device) 54 { 55 int result = 0; 56 57 if (result) { 58 return device + 1; 59 } else { 60 if (!*device) 61 incomplete = 1; 62 errnum = ERR_DEV_FORMAT; 63 } 64 return 0; 65 } 30 66 31 67 /* If DO_COMPLETION is true, just print NAME. Otherwise save the unique … … 63 99 int print_completions(int is_filename, int is_completion) 64 100 { 65 #ifdef CONFIG_EXPERIMENTAL66 101 char *buf = (char *) COMPLETION_BUF; 67 102 char *ptr = buf; … … 72 107 do_completion = is_completion; 73 108 74 #warning FIXME implement print_completions 75 // FIXME: This function is a dummy, returning an error. 76 errnum = ERR_BAD_FILENAME; 77 109 if (!is_filename) { 110 /* Print the completions of builtin commands. */ 111 struct builtin **builtin; 112 113 if (!is_completion) 114 grub_printf (" Possible commands are:"); 115 116 for (builtin = builtin_table; (*builtin); builtin++) { 117 /* If *builtin cannot be run in the command-line, skip it. */ 118 if (!((*builtin)->flags & BUILTIN_CMDLINE)) 119 continue; 120 if (substring (buf, (*builtin)->name) <= 0) 121 print_a_completion ((*builtin)->name); 122 } 123 124 if (is_completion && *unique_string) { 125 if (unique == 1) { 126 char *u = unique_string + strlen (unique_string); 127 *u++ = ' '; 128 *u = 0; 129 } 130 strcpy (buf, unique_string); 131 } 132 133 if (!is_completion) 134 grub_putchar ('\n'); 135 136 print_error(); 137 do_completion = 0; 138 if (errnum) 139 return -1; 140 else 141 return unique - 1; 142 } 143 144 if (*buf == '/' || (ptr = set_device (buf)) || incomplete) { 145 errnum = 0; 146 if (*buf == '(' && (incomplete || ! *ptr)) { 147 if (!part_choice) { 148 /* disk completions */ 149 int disk_no, i, j; 150 151 if (!is_completion) 152 grub_printf (" Possible disks are: "); 153 154 if (!ptr 155 || *(ptr-1) != 'd' 156 || *(ptr-2) != 'n' /* netboot? */ 157 || *(ptr-2) != 'c') { 158 for (i = (ptr && (*(ptr-1) == 'd' && *(ptr-2) == 'h') ? 1:0); 159 i < (ptr && (*(ptr-1) == 'd' && *(ptr-2) == 'f') ? 1:2); 160 i++) { 161 for (j = 0; j < 8; j++) { 162 if ((disk_choice)) { // TODO check geometry 163 char dev_name[8]; 164 sprintf (dev_name, "%cd%d", i ? 'h':'f', j); 165 print_a_completion(dev_name); 166 } 167 } 168 } 169 } 170 171 #if 0 172 if (cdrom_drive != GRUB_INVALID_DRIVE 173 && (disk_choice || cdrom_drive == current_drive) 174 && (!ptr 175 || *(ptr-1) == '(' 176 || (*(ptr-1) == 'd' && *(ptr-2) == 'c'))) 177 print_a_completion("cd"); 178 #endif 179 180 if (is_completion && *unique_string) { 181 ptr = buf; 182 while (*ptr != '(') 183 ptr--; 184 ptr++; 185 strcpy (ptr, unique_string); 186 if (unique == 1) { 187 ptr += strlen (ptr); 188 if (*unique_string == 'h') { 189 *ptr++ = ','; 190 *ptr = 0; 191 } else { 192 *ptr++ = ')'; 193 *ptr = 0; 194 } 195 } 196 } 197 198 if (!is_completion) 199 grub_putchar('\n'); 200 } else { 201 /* Partition completions */ 202 if (part_choice == PART_CHOSEN 203 && open_partition() 204 && ! IS_PC_SLICE_TYPE_BSD(current_slice)) { 205 unique = 1; 206 ptr = buf + strlen(buf); 207 if (*(ptr - 1) != ')') { 208 *ptr++ = ')'; 209 *ptr = 0; 210 } 211 } else { 212 if (!is_completion) 213 grub_printf (" Possible partitions are:\n"); 214 real_open_partition(1); 215 if (is_completion && *unique_string) { 216 ptr = buf; 217 while (*ptr++ != ',') 218 ; 219 strcpy (ptr, unique_string); 220 } 221 } 222 } 223 } else if (ptr && *ptr == '/') { 224 /* filename completions */ 225 if (!is_completion) 226 grub_printf (" Possible files are:"); 227 dir(buf); 228 229 if (is_completion && *unique_string) { 230 ptr += strlen (ptr); 231 while (*ptr != '/') 232 ptr--; 233 ptr++; 234 235 strcpy(ptr, unique_string); 236 237 if (unique == 1) { 238 ptr += strlen (unique_string); 239 240 /* Check if the file UNIQUE_STRING is a directory. */ 241 *ptr = '/'; 242 *(ptr + 1) = 0; 243 244 dir (buf); 245 246 /* Restore the original unique value. */ 247 unique = 1; 248 249 if (errnum) { 250 /* regular file */ 251 errnum = 0; 252 *ptr = ' '; 253 *(ptr + 1) = 0; 254 } 255 } 256 } 257 258 if (!is_completion) 259 grub_putchar ('\n'); 260 261 } else { 262 errnum = ERR_BAD_FILENAME; 263 } 264 } 78 265 79 266 print_error(); … … 83 270 else 84 271 return unique - 1; 85 #else 86 errnum = ERR_BAD_FILENAME; 87 print_error(); 88 return -1; 89 #endif 90 } 272 }
Note: See TracChangeset
for help on using the changeset viewer.
