forked from enlightenment/edi
Adding support to open at a specific line when opening files or switching tabs.edi-0.8
parent
a3a4f5fce6
commit
c3185b2225
14 changed files with 361 additions and 61 deletions
@ -0,0 +1,45 @@ |
||||
#ifdef HAVE_CONFIG |
||||
# include "config.h" |
||||
#endif |
||||
|
||||
#include "Edi.h" |
||||
#include "edi_path.h" |
||||
|
||||
#include "edi_private.h" |
||||
|
||||
EAPI Edi_Path_Options * |
||||
edi_path_options_create(const char *input) |
||||
{ |
||||
Edi_Path_Options *ret; |
||||
const char *path, *pos1, *pos2; |
||||
int line = 0, col = 0; |
||||
|
||||
path = input; |
||||
ret = calloc(1, sizeof(Edi_Path_Options)); |
||||
|
||||
pos1 = strstr(path, ":"); |
||||
if (pos1) |
||||
{ |
||||
path = eina_stringshare_add_length(path, strlen(path) - strlen(pos1)); |
||||
pos1++; |
||||
pos2 = strstr(pos1, ":"); |
||||
if (pos2) |
||||
{ |
||||
line = atoi(eina_stringshare_add_length(pos1, strlen(pos1) - strlen(pos2))); |
||||
|
||||
col = atoi(pos2 + 1); |
||||
} |
||||
else |
||||
{ |
||||
line = atoi(pos1); |
||||
} |
||||
} |
||||
|
||||
ret->path = path; |
||||
ret->line = line; |
||||
ret->character = col; |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
|
@ -0,0 +1,51 @@ |
||||
#ifndef EDI_PATH_H_ |
||||
# define EDI_PATH_H_ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/**
|
||||
* @file |
||||
* @brief These routines are used for Edi path handling. |
||||
*/ |
||||
|
||||
typedef struct _Edi_Path_Options |
||||
{ |
||||
const char *path; |
||||
const char *type; |
||||
int line, character; |
||||
} Edi_Path_Options; |
||||
|
||||
/**
|
||||
* @brief Path options |
||||
* @defgroup Options |
||||
* |
||||
* @{ |
||||
* |
||||
* Manipulation of various path options. |
||||
* |
||||
*/ |
||||
|
||||
/**
|
||||
* Create an options based on parsing a string input. |
||||
* String will be of the format <path>[:<line>[:<character>]] |
||||
* |
||||
* @param input The string formatted to have a path with optional line and character parameters |
||||
* If only one of line or character is provided it's assumed to be the line number. |
||||
* |
||||
* @return A newly allocated options struct. |
||||
* |
||||
* @ingroup Options |
||||
*/ |
||||
EAPI Edi_Path_Options *edi_path_options_create(const char *input); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* EDI_PATH_H_ */ |
@ -0,0 +1,36 @@ |
||||
#ifdef HAVE_CONFIG_H |
||||
# include "config.h" |
||||
#endif |
||||
|
||||
#include "edi_suite.h" |
||||
|
||||
START_TEST (edi_path_parse_plain_options) |
||||
{ |
||||
Edi_Path_Options *options; |
||||
|
||||
options = edi_path_options_create("test"); |
||||
|
||||
ck_assert_str_eq(options->path, "test"); |
||||
ck_assert(options->line == 0); |
||||
ck_assert(options->character == 0); |
||||
} |
||||
END_TEST |
||||
|
||||
START_TEST (edi_path_parse_line_options) |
||||
{ |
||||
Edi_Path_Options *options; |
||||
|
||||
options = edi_path_options_create("test:5:5"); |
||||
|
||||
ck_assert_str_eq(options->path, "test"); |
||||
ck_assert(options->line == 5); |
||||
ck_assert(options->character == 5); |
||||
} |
||||
END_TEST |
||||
|
||||
void edi_test_path(TCase *tc) |
||||
{ |
||||
tcase_add_test(tc, edi_path_parse_plain_options); |
||||
tcase_add_test(tc, edi_path_parse_line_options); |
||||
} |
||||
|
Loading…
Reference in new issue