File src/menus/menus.c changed (mode: 100644) (index 9bb414656..af313db27) |
... |
... |
static int prompt_error_msg_internalv(const char title[], const char format[], |
66 |
66 |
int prompt_skip, va_list pa); |
int prompt_skip, va_list pa); |
67 |
67 |
static int prompt_error_msg_internal(const char title[], const char message[], |
static int prompt_error_msg_internal(const char title[], const char message[], |
68 |
68 |
int prompt_skip); |
int prompt_skip); |
|
69 |
|
static char * parse_spec(const char spec[], int *line_num); |
69 |
70 |
static void open_selected_file(const char path[], int line_num); |
static void open_selected_file(const char path[], int line_num); |
70 |
71 |
static void navigate_to_selected_file(FileView *view, const char path[]); |
static void navigate_to_selected_file(FileView *view, const char path[]); |
71 |
72 |
static void normalize_top(menu_info *m); |
static void normalize_top(menu_info *m); |
|
... |
... |
void |
455 |
456 |
goto_selected_file(FileView *view, const char spec[], int try_open) |
goto_selected_file(FileView *view, const char spec[], int try_open) |
456 |
457 |
{ |
{ |
457 |
458 |
char *path_buf; |
char *path_buf; |
458 |
|
int line_num = 1; |
|
|
459 |
|
int line_num; |
|
460 |
|
|
|
461 |
|
path_buf = parse_spec(spec, &line_num); |
|
462 |
|
if(path_buf == NULL) |
|
463 |
|
{ |
|
464 |
|
show_error_msg("Memory Error", "Unable to allocate enough memory"); |
|
465 |
|
return; |
|
466 |
|
} |
|
467 |
|
|
|
468 |
|
if(access(path_buf, F_OK) == 0) |
|
469 |
|
{ |
|
470 |
|
if(try_open) |
|
471 |
|
{ |
|
472 |
|
open_selected_file(path_buf, line_num); |
|
473 |
|
} |
|
474 |
|
else |
|
475 |
|
{ |
|
476 |
|
navigate_to_selected_file(view, path_buf); |
|
477 |
|
} |
|
478 |
|
} |
|
479 |
|
else |
|
480 |
|
{ |
|
481 |
|
show_error_msgf("Missing file", "File \"%s\" doesn't exist", path_buf); |
|
482 |
|
} |
|
483 |
|
|
|
484 |
|
free(path_buf); |
|
485 |
|
} |
|
486 |
|
|
|
487 |
|
/* Extracts path and line number from the spec. Returns path and sets *line_num |
|
488 |
|
* to line number, otherwise NULL is returned. */ |
|
489 |
|
static char * |
|
490 |
|
parse_spec(const char spec[], int *line_num) |
|
491 |
|
{ |
|
492 |
|
char *path_buf; |
459 |
493 |
const char *colon; |
const char *colon; |
460 |
494 |
const size_t bufs_len = 2 + strlen(spec) + 1 + 1; |
const size_t bufs_len = 2 + strlen(spec) + 1 + 1; |
461 |
495 |
|
|
462 |
496 |
path_buf = malloc(bufs_len); |
path_buf = malloc(bufs_len); |
463 |
497 |
if(path_buf == NULL) |
if(path_buf == NULL) |
464 |
498 |
{ |
{ |
465 |
|
show_error_msg("Memory Error", "Unable to allocate enough memory"); |
|
466 |
|
return; |
|
|
499 |
|
return NULL; |
467 |
500 |
} |
} |
468 |
501 |
|
|
469 |
502 |
if(is_path_absolute(spec)) |
if(is_path_absolute(spec)) |
|
... |
... |
goto_selected_file(FileView *view, const char spec[], int try_open) |
479 |
512 |
if(colon != NULL) |
if(colon != NULL) |
480 |
513 |
{ |
{ |
481 |
514 |
strncat(path_buf, spec, colon - spec); |
strncat(path_buf, spec, colon - spec); |
482 |
|
line_num = atoi(colon + 1); |
|
|
515 |
|
*line_num = atoi(colon + 1); |
483 |
516 |
} |
} |
484 |
517 |
else |
else |
485 |
518 |
{ |
{ |
486 |
519 |
strcat(path_buf, spec); |
strcat(path_buf, spec); |
|
520 |
|
*line_num = 1; |
487 |
521 |
} |
} |
488 |
522 |
|
|
489 |
523 |
chomp(path_buf); |
chomp(path_buf); |
490 |
524 |
|
|
491 |
|
if(access(path_buf, F_OK) == 0) |
|
492 |
|
{ |
|
493 |
|
if(try_open) |
|
494 |
|
{ |
|
495 |
|
open_selected_file(path_buf, line_num); |
|
496 |
|
} |
|
497 |
|
else |
|
498 |
|
{ |
|
499 |
|
navigate_to_selected_file(view, path_buf); |
|
500 |
|
} |
|
501 |
|
} |
|
502 |
|
else |
|
503 |
|
{ |
|
504 |
|
show_error_msgf("Missing file", "File \"%s\" doesn't exist", path_buf); |
|
505 |
|
} |
|
506 |
|
|
|
507 |
|
free(path_buf); |
|
|
525 |
|
return path_buf; |
508 |
526 |
} |
} |
509 |
527 |
|
|
510 |
528 |
/* Opens file specified by its path on the given line number. */ |
/* Opens file specified by its path on the given line number. */ |