xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 22a9528d8d402f6af8d220aa3674425c093e7236

Extract menus/menus.c:parse_spec() function
Extracts path and line number from the spec. Returns path and
sets *line_num to line number, otherwise NULL is returned.
Author: xaizek
Author date (UTC): 2014-05-06 17:51
Committer name: xaizek
Committer date (UTC): 2014-05-06 17:51
Parent(s): 434c5148c6b249ca63016a1087a3a2650b34726c
Signing key:
Tree: f15ee919c2252bfd1463e6380c1e92f8b43a773d
File Lines added Lines deleted
src/menus/menus.c 39 21
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. */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master