# Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: krishnan.parthasarathi@example.com-20110420152047-\ # ae8yvprabok84rc7 # target_branch: bzr://bzr.savannah.gnu.org/pdf/libgnupdf/trunk/ # testament_sha1: c388ae2035ea99e4feb589517bd7b2d07b3f350b # timestamp: 2011-04-20 20:51:02 +0530 # base_revision_id: aleksander@gnu.org-20110418183910-9fyb0s6ts29twsze # # Begin patch === modified file 'src/base/pdf-fsys-disk.c' --- src/base/pdf-fsys-disk.c 2011-04-03 04:01:51 +0000 +++ src/base/pdf-fsys-disk.c 2011-04-20 15:20:47 +0000 @@ -100,6 +100,20 @@ static const pdf_char_t *__pdf_fsys_disk_get_mode_string (const enum pdf_fsys_file_mode_e mode); +static pdf_char_t* +__pdf_fsys_disk_build_host_path(const pdf_char_t *host_path1, + const pdf_char_t *host_path2); + +static pdf_bool_t +__pdf_fsys_disk_is_absolute_host_path(const pdf_char_t *host_path); + +static const pdf_char_t* +__pdf_fsys_disk_skip_root(const pdf_char_t* host_path); + +static pdf_char_t* +__pdf_fsys_disk_get_canonical_parent_path(const pdf_char_t *host_path); + + #ifdef PDF_HOST_WIN32 static pdf_bool_t __pdf_fsys_disk_win32_device_p (const pdf_text_t *path, pdf_error_t **error); @@ -589,13 +603,39 @@ PDF_ASSERT_POINTER_RETURN_VAL (path_name, PDF_EBADDATA); PDF_ASSERT_POINTER_RETURN_VAL (parent_path, PDF_EBADDATA); - /* TODO: This involves getting an absolute path from a relative path */ - -#warning Function 'pdf_fsys_disk_get_parent' not yet implemented - - return PDF_ERROR; + /* Get host encoding of the path */ + pdf_char_t *host_path, *host_parent_path; + pdf_error_t *inner_error; + host_path = __pdf_fsys_disk_get_host_path (path_name, &inner_error); + + if(!host_path) + { + /* TODO: Propagate error */ + pdf_error_destroy(inner_error); + return PDF_ERROR; + } + + host_parent_path = __pdf_fsys_disk_get_canonical_parent_path (host_path); + + *parent_path = __pdf_fsys_disk_set_host_path (host_parent_path, + strlen(host_parent_path), + &inner_error); + + if(!(*parent_path)) + { + /* TODO: Propagate error */ + pdf_error_destroy (inner_error); + pdf_dealloc (host_path); + pdf_dealloc (host_parent_path); + return PDF_ERROR; + } + + pdf_dealloc (host_path); + pdf_dealloc (host_parent_path); + return PDF_OK; } + /* Host-dependent rmdir() */ #ifdef PDF_HOST_WIN32 #define PDF_RMDIR(f) _wrmdir((wchar_t *)f) @@ -1504,4 +1544,139 @@ } } +#ifdef PDF_HOST_WIN32 +#define DIR_SEPARATOR '\\' +#define DIR_SEPARATOR_S "\\" +#define IS_DIR_SEPARATOR(c) (((c) == '/') || ((c) == '\\')) + +#else /* !PDF_HOST_WIN32 */ +#define DIR_SEPARATOR '/' +#define DIR_SEPARATOR_S "//" +#define IS_DIR_SEPARATOR(c) ((c) == '/') +#endif + +static pdf_char_t* +__pdf_fsys_disk_build_host_path (const pdf_char_t *a, const pdf_char_t *b) +{ + pdf_char_t *full_path = (pdf_char_t*) pdf_alloc (strlen (a)+strlen (b)+2); + + strncpy (full_path, a, strlen (a)); + strncat (full_path, DIR_SEPARATOR_S, 1); + strncat (full_path, b, strlen (b)); + + return full_path; +} + +static pdf_bool_t +__pdf_fsys_disk_is_absolute_host_path (const pdf_char_t *host_path) +{ + //TODO: Does not work on windows + if (!host_path) + return PDF_FALSE; + + if (IS_DIR_SEPARATOR (*host_path)) + return PDF_TRUE; + + return PDF_FALSE; +} + +static const pdf_char_t* +__pdf_fsys_disk_skip_root (const pdf_char_t* host_path) +{ + const pdf_char_t *p = host_path; + while (p != 0 && IS_DIR_SEPARATOR (*p)) + p++; + + return p; +} + +static pdf_char_t* +__pdf_fsys_disk_get_canonical_parent_path (const pdf_char_t *host_path) +{ + pdf_char_t *begin, *prev, *cur; + pdf_char_t *canon_path; + + if (!__pdf_fsys_disk_is_absolute_host_path (host_path)) + { + pdf_char_t *cwd = getcwd(NULL, 0); + canon_path = __pdf_fsys_disk_build_host_path (cwd, host_path); + pdf_dealloc (cwd); + } + else + { + canon_path = strdup (host_path); + } + + begin = __pdf_fsys_disk_skip_root (canon_path); + + /* Collapse all leading '/' */ + cur = begin-1; + while (cur > canon_path+1 && IS_DIR_SEPARATOR (*cur)) cur--; + if(cur != begin-1) + { + memmove (cur, begin, strlen (begin)+1); + begin = cur; + } + + while (*cur != 0) + { + if (cur[0] == '.' && (cur[1] == 0 + || IS_DIR_SEPARATOR (cur[1]))) + { + memmove (cur, cur+1, strlen (cur+1)+1); + } + else if (cur[0] == '.' && cur[1] == '.' + && (cur[2] == 0 || IS_DIR_SEPARATOR (cur[2]))) + { + prev = cur - 2; + cur = cur + 2; + if (prev < begin) + prev = begin; + while (prev > begin && !IS_DIR_SEPARATOR (*prev)) + prev--; + if (IS_DIR_SEPARATOR (*prev)) + *prev++ = DIR_SEPARATOR; + memmove (prev, cur, strlen (cur)+1); + cur = prev; + } + else + { + while (*cur != 0 && !IS_DIR_SEPARATOR (*cur)) + cur++; + if (*cur != 0) + *cur++ = DIR_SEPARATOR; + } + /* Collapse '/'s that occur together in path_name*/ + prev = cur; + while (*cur != 0 && IS_DIR_SEPARATOR (*cur)) + cur++; + if (prev != cur) + memmove (prev, cur, strlen (cur)+1); + cur = prev; + } + + /* Removing trailing '/'s */ + cur--; + while (cur > begin && IS_DIR_SEPARATOR (*cur)) + { + *cur = 0; + cur--; + } + + /* Now get parent path */ + while (cur > begin && !IS_DIR_SEPARATOR (*cur)) + { + *cur = 0; + cur--; + } + + if (cur > begin) + { + *cur = 0; + cur--; + } + + return canon_path; +} + /* End of pdf-fsys-disk.c */ === modified file 'torture/unit/Makefile.am' --- torture/unit/Makefile.am 2011-03-29 21:12:24 +0000 +++ torture/unit/Makefile.am 2011-04-20 15:20:47 +0000 @@ -213,7 +213,8 @@ base/fsys/pdf-fsys-file-open.c \ base/fsys/pdf-fsys-file-open-tmp.c \ base/fsys/pdf-fsys-file-close.c \ - base/fsys/pdf-fsys-build-path.c + base/fsys/pdf-fsys-build-path.c \ + base/fsys/pdf-fsys-get-parent.c TEST_SUITE_TOKEN = base/token/pdf-token-read.c \ === added file 'torture/unit/base/fsys/pdf-fsys-get-parent.c' --- torture/unit/base/fsys/pdf-fsys-get-parent.c 1970-01-01 00:00:00 +0000 +++ torture/unit/base/fsys/pdf-fsys-get-parent.c 2011-04-20 15:20:47 +0000 @@ -0,0 +1,96 @@ +#include + + +#include +#include +#include + +#include +#include + +static void _helper_routine(const char *host_path, + const char *host_parent_path) +{ + + pdf_text_t *path_name, *expected_parent_path, + *actual_parent_path; + pdf_error_t *inner_error; + + path_name = pdf_text_new_from_host (host_path, + strlen (host_path), + pdf_text_get_host_encoding (), + &inner_error); + if (!path_name) + { + pdf_error_destroy (inner_error); + } + + fail_if (path_name == NULL); + + expected_parent_path = pdf_text_new_from_host (host_parent_path, + strlen (host_parent_path), + pdf_text_get_host_encoding (), + &inner_error); + if (!expected_parent_path) + { + pdf_error_destroy (inner_error); + } + + fail_if (expected_parent_path == NULL); + + + actual_parent_path = pdf_text_new (&inner_error); + if (!actual_parent_path) + { + pdf_error_destroy (inner_error); + } + + fail_if (pdf_fsys_disk_get_parent (NULL, path_name, &actual_parent_path) != PDF_OK); + fail_if (pdf_text_cmp (actual_parent_path, expected_parent_path, PDF_TRUE, &inner_error) != 0); + + pdf_dealloc(path_name); + pdf_dealloc(expected_parent_path); + pdf_dealloc(actual_parent_path); +} + + +START_TEST (pdf_fsys_get_parent_001) +{ + pdf_char_t *host_path = "///aa/b/../c/d/./././/////"; + pdf_char_t *host_parent_path = "/aa/c"; + + _helper_routine(host_path, host_parent_path); + +} +END_TEST + +/* + Test +*/ +START_TEST (pdf_fsys_get_parent_002) +{ + pdf_char_t *host_path = "/"; + pdf_char_t *host_parent_path = "/"; + + _helper_routine(host_path, host_parent_path); + +} +END_TEST + + +/* + * Test case creation function + */ +TCase * +test_pdf_fsys_get_parent (void) +{ + TCase *tc = tcase_create ("pdf_fsys_get_parent"); + + tcase_add_test (tc, pdf_fsys_get_parent_001); + tcase_add_test (tc, pdf_fsys_get_parent_002); + tcase_add_checked_fixture (tc, + pdf_test_setup, + pdf_test_teardown); + return tc; +} + === modified file 'torture/unit/base/fsys/tsuite-fsys.c' --- torture/unit/base/fsys/tsuite-fsys.c 2011-02-24 22:52:23 +0000 +++ torture/unit/base/fsys/tsuite-fsys.c 2011-04-20 15:20:47 +0000 @@ -32,6 +32,7 @@ extern TCase *test_pdf_fsys_file_open_tmp (void); extern TCase *test_pdf_fsys_file_close (void); extern TCase *test_pdf_fsys_build_path (void); +extern TCase *test_pdf_fsys_get_parent (void); Suite * tsuite_fsys () @@ -45,6 +46,7 @@ suite_add_tcase (s, test_pdf_fsys_file_open_tmp ()); suite_add_tcase (s, test_pdf_fsys_file_close ()); suite_add_tcase (s, test_pdf_fsys_build_path ()); + suite_add_tcase (s, test_pdf_fsys_get_parent ()); return s; } # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWRab3F8AB4n/gF1RIGF5//// f+/ejr////5gDhwfLrD0NZt1WmhJFWUj1l3GnYMKa0gjK2ktMrCKSI0NGRoEwFT8iameo9U8iGAm ajI0ADQNBoJREMmjJoTVNqfqEaDQNqAaDQaAGgNAAGg01MhT1Eyepo0AMgAD1AAAAADQDQAk1IRC GpptSeIyh6jaTxEaA0A0GmmhoAyZDCHA0GmQ00aGEDIaGCNDTJo0AyDEAAaCRIIExRiaZATT0Cnp T8oemqepptINBpoMgGmmnqG3M2EnVSE4xhJadg5/o9M5L0mGgVD0MOLPGbPZ6/Li/g0WUbf1lr5x 19HP2dJ4XaZvRTZN6MSWCWNkKFlFSozqFFkpvgqFMxVUNsXCud3O/YswN7g11x7Rz2mLbht3DcXU nkbAuVKJlWEuiNUVHZVPFipq8Vt3oOY0auP1O23G/lbGs04is+bbPk1lMjgDAbkCK8t2UY9MbrKy pU0UypF9+2UmXbIMZnA2M2CmQkkiSPsbz2S5a1JMLWQhySQsJvjSQhECEQiEA8p5EwP++7HuO2cC isBeRJZKzQrbkcnB8mC4NbtoN/d5x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