diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 13f6369ab9..f560bbc0e1 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -3,6 +3,8 @@ #include +#include + #ifdef EAPI # undef EAPI #endif @@ -38,6 +40,20 @@ extern "C" { * @brief These routines are used for interacting with files using Elm Code. */ +typedef struct _Elm_Code_Line +{ + const char *content; + const char *modified; + +} Elm_Code_Line; + +typedef struct _Elm_Code_File +{ + Elm_Code_Line *lines; + Eina_File *file; + +} Elm_Code_File; + /** * @brief Init / shutdown functions. * @defgroup Init Init / Shutdown @@ -84,6 +100,14 @@ EAPI int elm_code_init(void); */ EAPI int elm_code_shutdown(void); +EAPI Elm_Code_File *elm_code_open(const char *path); + +EAPI void elm_code_close(Elm_Code_File *file); + +EAPI const char *elm_code_filename_get(Elm_Code_File *file); + +EAPI const char *elm_code_path_get(Elm_Code_File *file); + /** * @} */ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 0532ce6eac..44b251a36c 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -56,3 +56,31 @@ elm_code_shutdown(void) return _elm_code_init; } + +EAPI Elm_Code_File *elm_code_open(const char *path) +{ + Elm_Code_File *ret; + Eina_File *file; + + file = eina_file_open(path, EINA_FALSE); + ret = calloc(1, sizeof(ret)); + ret->file = file; + + return ret; +} + +EAPI void elm_code_close(Elm_Code_File *file) +{ + eina_file_close(file->file); + free(file); +} + +EAPI const char *elm_code_filename_get(Elm_Code_File *file) +{ + return basename(eina_file_filename_get(file->file)); +} + +EAPI const char *elm_code_path_get(Elm_Code_File *file) +{ + return eina_file_filename_get(file->file); +} \ No newline at end of file diff --git a/legacy/elm_code/tests/elm_code_test_load.c b/legacy/elm_code/tests/elm_code_test_load.c index 807e06ec52..926b2aaa1d 100644 --- a/legacy/elm_code/tests/elm_code_test_load.c +++ b/legacy/elm_code/tests/elm_code_test_load.c @@ -6,7 +6,16 @@ START_TEST (elm_code_load) { - ck_assert(1); + char *path = "elm_code/tests/testfile.txt"; + char real[EINA_PATH_MAX]; + Elm_Code_File *file; + + file = elm_code_open(path); + realpath(path, real); + + ck_assert_str_eq(basename(path), elm_code_filename_get(file)); + ck_assert_str_eq(real, elm_code_path_get(file)); + elm_code_close(file); } END_TEST diff --git a/legacy/elm_code/tests/testfile.txt b/legacy/elm_code/tests/testfile.txt new file mode 100644 index 0000000000..246d68ea4a --- /dev/null +++ b/legacy/elm_code/tests/testfile.txt @@ -0,0 +1,5 @@ +line 1 +line2 + +another line +5