From fe7e08c6a59158ad83f60ce065fde921688881a1 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Wed, 27 Sep 2023 18:31:45 +0800 Subject: [PATCH] Rename to uniform path --- chsrc.c | 16 +++++----------- chsrc.h | 4 +++- test_xy.c | 2 +- xy.h | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/chsrc.c b/chsrc.c index 2149028..73eb723 100644 --- a/chsrc.c +++ b/chsrc.c @@ -434,7 +434,7 @@ pl_java_check_cmd_(bool* maven_exist, bool* gradle_exist) *gradle_exist = does_the_program_exist (check_cmd, "gradle"); if (! *maven_exist && ! *gradle_exist) { - chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在(其一)"); + chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在其一"); exit(1); } } @@ -452,13 +452,7 @@ pl_java_find_maven_config_ () // xy_info (buf); maven_home = xy_str_strip(maven_home); - char* maven_config = NULL; - - if (xy_on_windows) - maven_config = xy_2strjoin(maven_home, "\\conf\\settings.xml"); - else - maven_config = xy_2strjoin(maven_home, "/conf/settings.xml"); - + char* maven_config = xy_uniform_path(xy_2strjoin(maven_home, "/conf/settings.xml")); return maven_config; } @@ -613,15 +607,15 @@ pl_haskell_setsrc(char* option) char* config = NULL; if (xy_on_windows) { - config = xy_2strjoin(xy_os_home, "\\AppData\\Roaming\\cabal\\config"); + config = xy_uniform_path ("~/AppData/Roaming/cabal/config"); } else { - config = xy_2strjoin(xy_os_home, "/.cabal/config"); + config = "~/.cabal/config"; } xy_info(xy_strjoin(3,"chsrc: 请向 ", config, " 中手动添加:")); puts(file); puts(""); - config = xy_2strjoin(xy_os_home, "/.stack/config.yaml"); + config = xy_uniform_path ("~/.stack/config.yaml"); file = xy_strjoin(3, "package-indices:\n" " - download-prefix: ", source.url, "\n hackage-security:\n" diff --git a/chsrc.h b/chsrc.h index 1c7ef71..53f3ee3 100644 --- a/chsrc.h +++ b/chsrc.h @@ -289,8 +289,8 @@ static void chsrc_check_file (const char* path) { char* cmd = NULL; + path = xy_uniform_path (path); if(xy_on_windows) { - path = xy_unix_path_to_win (path); cmd = xy_2strjoin ("type ", path); } else { cmd = xy_2strjoin ("cat ", path); @@ -301,6 +301,7 @@ chsrc_check_file (const char* path) static void chsrc_append_to_file (const char* str, const char* file) { + file = xy_uniform_path (file); char* cmd = NULL; if (xy_on_windows) { cmd = xy_strjoin (4, "echo ", str, " >> ", file); @@ -313,6 +314,7 @@ chsrc_append_to_file (const char* str, const char* file) static void chsrc_overwrite_file (const char* str, const char* file) { + file = xy_uniform_path (file); char* cmd = NULL; if (xy_on_windows) { cmd = xy_strjoin (4, "echo ", str, " > ", file); diff --git a/test_xy.c b/test_xy.c index 1698c09..631df5c 100644 --- a/test_xy.c +++ b/test_xy.c @@ -91,7 +91,7 @@ main (int argc, char const *argv[]) assert(xy_file_exist(xy_win_powershell_profile)); assert(false==xy_file_exist(xy_win_powershellv5_profile)); - puts (xy_unix_path_to_win_if_on_win(" \n ~/haha/test/123 \n\r ")); + puts (xy_uniform_path(" \n ~/haha/test/123 \n\r ")); xy_success("测试全部通过"); return 0; diff --git a/xy.h b/xy.h index feb9f01..c21ae6b 100644 --- a/xy.h +++ b/xy.h @@ -534,7 +534,7 @@ xy_file_exist (const char* path) * 该函数即使在非Windows下也可调用,作用是删除路径左右两边多出来的空白符 */ static char* -xy_unix_path_to_win_if_on_win (const char* path) +xy_uniform_path (const char* path) { char* new = xy_str_strip(path); // 防止开发者多写了空白符