Rename RStr.home() to RFile.home() as part of the Plan ##api

This commit is contained in:
pancake 2022-10-27 16:15:13 +02:00 committed by pancake
parent d13c5757c9
commit 0b90768931
17 changed files with 25 additions and 26 deletions

View File

@ -36,7 +36,7 @@ R_API int r_cons_pipe_open(const char *file, int fdn, int append) {
return -1;
}
char *targetFile = (r_str_startswith (file, "~/") || r_str_startswith (file, "~\\"))
? r_str_home (file + 2): strdup (file);
? r_file_home (file + 2): strdup (file);
const int fd_flags = O_BINARY | O_RDWR | O_CREAT | (append? O_APPEND: O_TRUNC);
int fd = r_sandbox_open (targetFile, fd_flags, 0644);
if (fd == -1) {

View File

@ -4410,7 +4410,7 @@ R_API void r_core_parse_radare2rc(RCore *r) {
homerc = rcfile;
} else {
free (rcfile);
homerc = r_str_home (".radare2rc");
homerc = r_file_home (".radare2rc");
}
if (homerc && r_file_is_regular (homerc)) {
R_LOG_DEBUG ("user script loaded from %s", homerc);

View File

@ -547,7 +547,7 @@ static void load_scripts_for(RCore *core, const char *name) {
char *file;
RListIter *iter;
char *hdir = r_str_newf (R_JOIN_2_PATHS (R2_HOME_BINRC, "bin-%s"), name);
char *path = r_str_home (hdir);
char *path = r_file_home (hdir);
RList *files = r_sys_dir (path);
if (!r_list_empty (files)) {
R_LOG_INFO ("[binrc] path: %s", path);

View File

@ -1205,7 +1205,7 @@ static int cmd_cmp(void *data, const char *input) {
// nothing to do here
}
} else if (input[1] == '~' && input[2] == '/') {
char *homepath = r_str_home (input + 3);
char *homepath = r_file_home (input + 3);
if (homepath) {
if (*homepath) {
free (oldcwd);

View File

@ -651,12 +651,12 @@ static int cmd_eval(void *data, const char *input) {
eprintf (" ed : ${cfg.editor} ~/.radare2rc\n");
eprintf (" ed- : rm ~/.radare2rc\n");
} else if (input[1] == '-') {
char *file = r_str_home (".radare2rc");
char *file = r_file_home (".radare2rc");
r_cons_printf ("rm %s\n", file);
// r_file_rm (file);
free (file);
} else {
char *file = r_str_home (".radare2rc");
char *file = r_file_home (".radare2rc");
if (r_cons_is_interactive ()) {
r_file_touch (file);
char * res = r_cons_editor (file, NULL);

View File

@ -1394,7 +1394,7 @@ static int cmd_type(void *data, const char *input) {
char *homefile = NULL;
if (*filename == '~') {
if (filename[1] && filename[2]) {
homefile = r_str_home (filename + 2);
homefile = r_file_home (filename + 2);
filename = homefile;
}
}

View File

@ -1321,9 +1321,9 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s
dirname = r_str_new (R_SYS_DIR);
#endif
} else if (lpath[0] == '~' && lpath[1]) { // ~/xxx/yyy
dirname = r_str_home (lpath + 2);
dirname = r_file_home (lpath + 2);
} else if (lpath[0] == '~') { // ~/xxx
if (!(home = r_str_home (NULL))) {
if (!(home = r_file_home (NULL))) {
goto out;
}
dirname = r_str_newf ("%s%s", home, R_SYS_DIR);

View File

@ -5,7 +5,7 @@
static char *getFortuneFile(RCore *core, const char *type) {
char *fortunedir = r_xdg_datadir ("fortunes");
char *ft = r_str_newf ("%s/fortunes.%s", fortunedir, type);
char *path = r_str_home (ft);
char *path = r_file_home (ft);
free (ft);
free (fortunedir);
if (path && r_file_exists (path)) {

View File

@ -68,6 +68,8 @@ R_API RList* r_file_glob(const char *globbed_path, int maxdepth);
R_API RMmap *r_file_mmap_arch(RMmap *map, const char *filename, int fd);
R_API RList *r_file_lsrf(const char *dir);
R_API bool r_file_rm_rf(const char *dir);
R_API R_MUSTUSE char *r_file_home(const char *str);
// R2_580: implement r_file_homef() for format string purposes
// XDG
R_API char *r_xdg_configdir(const char *s);

View File

@ -234,8 +234,6 @@ R_API char *r_str_utf16_encode(const char *s, int len);
R_API char *r_str_escape_utf8_for_json(const char *s, int len);
R_API char *r_str_escape_utf8_for_json_strip(const char *buf, int buf_size);
R_API char *r_str_encoded_json(const char *buf, int buf_size, int encoding);
R_API R_MUSTUSE char *r_str_home(const char *str); // R2_580 : rename to r_file_home() ?
// R2_580: implement r_file_homef() for format string purposes
R_API R_MUSTUSE char *r_str_r2_prefix(const char *str);
R_API size_t r_str_nlen(const char *s, int n);
R_API size_t r_str_nlen_w(const char *s, int n);

View File

@ -1074,7 +1074,7 @@ R_API int r_main_radare2(int argc, const char **argv) {
r_config_set_b (r->config, "scr.utf8", false);
}
char *histpath = r_str_home (".cache/radare2/history");
char *histpath = r_file_home (".cache/radare2/history");
if (histpath) {
r_line_hist_load (histpath);
free (histpath);

View File

@ -56,7 +56,7 @@ R_API char *r_file_new(const char *root, ...) {
va_start (ap, root);
RStrBuf *sb = r_strbuf_new ("");
if (!strcmp (root, "~")) {
char *h = r_str_home (NULL);
char *h = r_file_home (NULL);
if (!h) {
va_end (ap);
r_strbuf_free (sb);
@ -232,7 +232,7 @@ R_API char *r_file_abspath_rel(const char *cwd, const char *file) {
return strdup (file);
}
if (!strncmp (file, "~/", 2) || !strncmp (file, "~\\", 2)) {
ret = r_str_home (file + 2);
ret = r_file_home (file + 2);
} else {
#if __UNIX__
if (cwd && *file != '/') {
@ -1432,7 +1432,7 @@ R_API RList* r_file_glob(const char *_globbed_path, int maxdepth) {
glob_ptr = last_slash + 1;
if (globbed_path[0] == '~') {
char *rpath = r_str_newlen (globbed_path + 2, last_slash - globbed_path - 1);
path = r_str_home (r_str_get (rpath));
path = r_file_home (r_str_get (rpath));
free (rpath);
} else {
path = r_str_newlen (globbed_path, last_slash - globbed_path + 1);

View File

@ -326,7 +326,7 @@ R_API bool r_sandbox_creat(const char *path, int mode) {
}
static inline char *expand_home(const char *p) {
return (*p == '~')? r_str_home (p): strdup (p);
return (*p == '~')? r_file_home (p): strdup (p);
}
R_API int r_sandbox_lseek(int fd, ut64 addr, int whence) {

View File

@ -260,7 +260,7 @@ R_API void r_str_case(char *str, bool up) {
}
}
R_API R_MUSTUSE char *r_str_home(const char *str) {
R_API R_MUSTUSE char *r_file_home(const char *str) {
char *dst, *home = r_sys_getenv (R_SYS_HOME);
size_t length;
if (!home) {

View File

@ -199,13 +199,13 @@ R_API char *r_syscmd_ls(const char *input, int cons_width) {
if (!path || !*path) {
path = ".";
} else if (!strncmp (path, "~/", 2)) {
homepath = r_str_home (path + 2);
homepath = r_file_home (path + 2);
if (homepath) {
path = (const char *)homepath;
}
} else if (*path == '$') {
if (!strncmp (path + 1, "home", 4) || !strncmp (path + 1, "HOME", 4)) {
homepath = r_str_home ((strlen (path) > 5)? path + 6: NULL);
homepath = r_file_home ((strlen (path) > 5)? path + 6: NULL);
if (homepath) {
path = (const char *)homepath;
}

View File

@ -14,7 +14,7 @@ static char *xdg(const char *env, const char *a, const char *s) {
char *dir = r_sys_getenv (env);
if (R_STR_ISEMPTY (dir)) {
free (dir);
dir = r_str_home (a);
dir = r_file_home (a);
}
char *res = r_file_new (dir, "radare2", s, NULL);
free (dir);

View File

@ -118,13 +118,12 @@ bool test_r_str_trim(void) {
free (two);
mu_end;
}
//TODO find a way to test r_str_home.
bool test_r_str_bool(void) {
const char* one = r_str_bool(1);
const char* zero = r_str_bool(0);
const char* fifty = r_str_bool(50);
const char* negative = r_str_bool(-1);
const char* one = r_str_bool (1);
const char* zero = r_str_bool (0);
const char* fifty = r_str_bool (50);
const char* negative = r_str_bool (-1);
mu_assert_streq (one, "true", "one");
mu_assert_streq (zero, "false", "zero");
mu_assert_streq (fifty, "true", "large positive value");