Use XDG instead of R2_HOME_CACHEDIR and R2_HOME_HISTORY ##core

* Implement and use the new `r_xdg` apis
* Remove R2_HOME_RC, R2_HOME_RC_DIR and R2_HOME_CONFIGDIR
* R2_HOME_THEMES, R2_HOME_ZIGNS R2_HOME_PDB R2_HOME_HUD R2_HOME_BINRC and R2_HOME_BIN
* Disable the bin-specific user scripts
* Massage the help messages and reduce and review all the env vars used
This commit is contained in:
pancake 2022-09-29 12:07:28 +02:00 committed by pancake
parent adb7c1388a
commit c2851a6f46
22 changed files with 125 additions and 134 deletions

View File

@ -63,8 +63,6 @@ fi
if [ "${R2PMCACHE_LOADED}" != 1 ]; then
export LIBEXT="$R2_LIBEXT"
LIBDIR="$R2_LIBDIR"
export R2CONFIGHOME="$R2_RCONFIGHOME"
export R2DATAHOME="$R2_RDATAHOME"
PREFIX="$R2_PREFIX"
fi
BINDIR="${PREFIX}/bin/"
@ -104,7 +102,7 @@ export LDFLAGS="-L${R2PM_HOMEPREFIX}/lib"
export R2PM_PYPATH="${R2PM_PREFIX}/python"
export R2PM_OLDPWD="${PWD}"
export RHOMEDIR="$R2_RCONFIGHOME"
export R2_CONFIG_HOME="$R2_CONFIG_HOME"
if [ "`uname`" = Darwin ]; then
export LD_LIBRARY_PATH="${R2PM_HOMEPREFIX}/lib"
@ -217,10 +215,10 @@ thePurge() {
exit 1
fi
countDown "Self destroying in" 3
confirm "> Delete $RHOMEDIR" && (
rm -rf "$RHOMEDIR"
)
R2PATHS="${PREFIX}:/usr:/usr/local:/opt/radare2:${RHOMEDIR}/prefix:/"
if [ -n "${R2_CONFIG_HOME}" ]; then
confirm "> Delete $R2_CONFIG_HOME" && ( rm -rf "$R2_CONFIG_HOME" )
fi
R2PATHS="${PREFIX}:/usr:/usr/local:/opt/radare2:${R2_CONFIG_HOME}/prefix:/"
IFS=:
for a in $R2PATHS ; do
if [ -x "${a}/bin/radare2" ]; then

View File

@ -1,8 +1,5 @@
/* radare - LGPL - Copyright 2009-2021 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2022 - pancake, nibble */
#include <r_anal.h>
#include <r_sign.h>
#include <r_search.h>
#include <r_core.h>
R_LIB_VERSION (r_sign);
@ -2897,8 +2894,8 @@ R_API char *r_sign_path(RAnal *a, const char *file) {
}
free (abs);
} else {
char *home = r_str_home (R2_HOME_ZIGNS);
abs = r_str_newf ("%s%s%s", home, R_SYS_DIR, file);
char *home = r_xdg_datadir ("zigns");
abs = r_file_new (home, file, NULL);
free (home);
if (r_file_is_regular (abs)) {
return abs;

View File

@ -792,8 +792,9 @@ R_API void r_core_anal_cc_init(RCore *core) {
const char *dir_prefix = r_config_get (core->config, "dir.prefix");
char *dbpath = r_str_newf (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "cc-%s-%d.sdb"),
dir_prefix, anal_arch, bits);
char *dbhomepath = r_str_newf (R_JOIN_3_PATHS ("~", R2_HOME_SDB_FCNSIGN, "cc-%s-%d.sdb"),
anal_arch, bits);
char *fcnsigndir = r_xdg_datadir ("fcnsign");
char *dbhomepath = r_str_newf ("%s/cc-%s-%d.sdb", fcnsigndir, anal_arch, bits);
free (fcnsigndir);
Sdb *cc = core->anal->sdb_cc;
// Avoid sdb reloading
if (cc->path && (!strcmp (cc->path, dbpath) || !strcmp (cc->path, dbhomepath))) {

View File

@ -3326,8 +3326,8 @@ R_API int r_core_config_init(RCore *core) {
SETPREF ("pdb.useragent", "microsoft-symbol-server/6.11.0001.402", "User agent for Microsoft symbol server");
SETPREF ("pdb.server", "https://msdl.microsoft.com/download/symbols", "Semi-colon separated list of base URLs for Microsoft symbol servers");
{
char *pdb_path = r_str_home (R2_HOME_PDB);
SETPREF ("pdb.symstore", pdb_path, "path to downstream symbol store");
char *pdb_path = r_xdg_datadir ("pdb");
SETPREF ("pdb.symstore", pdb_path, "path to downstream symbol store"); // XXX rename to dir.pdb
R_FREE(pdb_path);
}
SETI ("pdb.extract", 1, "avoid extract of the pdb file, just download");
@ -3761,7 +3761,7 @@ R_API int r_core_config_init(RCore *core) {
SETBPREF ("zign.refs", "true", "use references for matching");
SETBPREF ("zign.hash", "true", "use Hash for matching");
SETBPREF ("zign.types", "true", "use types for matching");
SETBPREF ("zign.autoload", "false", "autoload all zignatures located in " R_JOIN_2_PATHS ("~", R2_HOME_ZIGNS));
SETBPREF ("zign.autoload", "false", "autoload all zignatures located in dir.zigns");
SETPREF ("zign.diff.bthresh", "1.0", "threshold for diffing zign bytes [0, 1] (see zc?)");
SETPREF ("zign.diff.gthresh", "1.0", "threshold for diffing zign graphs [0, 1] (see zc?)");
SETPREF ("zign.threshold", "0.0", "minimum similarity required for inclusion in zb output");
@ -3796,8 +3796,12 @@ R_API int r_core_config_init(RCore *core) {
p = r_sys_getenv (R_SYS_TMP);
SETCB ("dir.tmp", r_str_get (p), &cb_dirtmp, "path of the tmp directory");
free (p);
SETCB ("dir.projects", R_JOIN_2_PATHS ("~", R2_HOME_PROJECTS), &cb_dir_projects, "default path for projects");
SETCB ("dir.zigns", R_JOIN_2_PATHS ("~", R2_HOME_ZIGNS), &cb_dirzigns, "default path for zignatures (see zo command)");
char *prjdir = r_xdg_datadir ("projects");
SETCB ("dir.projects", prjdir, &cb_dir_projects, "default path for projects");
free (prjdir);
char *zigndir = r_xdg_datadir ("zigns");
SETCB ("dir.zigns", zigndir, &cb_dirzigns, "default path for zignatures (see zo command)");
free (zigndir);
SETPREF ("stack.reg", "SP", "which register to use as stack pointer in the visual debug");
SETBPREF ("stack.bytes", "true", "show bytes instead of words in stack");
SETBPREF ("stack.anotated", "false", "show anotated hexdump in visual debug");
@ -3965,7 +3969,11 @@ R_API int r_core_config_init(RCore *core) {
SETI ("http.maxsize", 0, "maximum file size for upload");
SETPREF ("http.index", "index.html", "main html file to check in directory");
SETPREF ("http.bind", "localhost", "server address (use 'public' for binding to 0.0.0.0)");
SETPREF ("http.homeroot", R_JOIN_2_PATHS ("~", R2_HOME_WWWROOT), "http home root directory");
char *www = r_xdg_datadir ("www");
if (www) {
SETPREF ("http.homeroot", www, "http home root directory");
free (www);
}
#if __WINDOWS__
{
char *wwwroot = r_str_newf ("%s\\share\\www", r_sys_prefix (NULL));
@ -4263,7 +4271,6 @@ R_API int r_core_config_init(RCore *core) {
}
R_API void r_core_parse_radare2rc(RCore *r) {
bool has_debug = r_sys_getenv_asbool ("R2_DEBUG");
char *rcfile = r_sys_getenv ("R2_RCFILE");
char *homerc = NULL;
if (!R_STR_ISEMPTY (rcfile)) {
@ -4273,21 +4280,19 @@ R_API void r_core_parse_radare2rc(RCore *r) {
homerc = r_str_home (".radare2rc");
}
if (homerc && r_file_is_regular (homerc)) {
if (has_debug) {
eprintf ("USER CONFIG loaded from %s\n", homerc);
}
R_LOG_DEBUG ("user script loaded from %s", homerc);
r_core_cmd_file (r, homerc);
}
free (homerc);
homerc = r_str_home (R2_HOME_RC);
char *configdir = r_xdg_configdir (NULL);
homerc = r_file_new (configdir, "radare2rc", NULL);
if (homerc && r_file_is_regular (homerc)) {
if (has_debug) {
eprintf ("USER CONFIG loaded from %s\n", homerc);
}
R_LOG_DEBUG ("user script loaded from %s", homerc);
r_core_cmd_file (r, homerc);
}
free (homerc);
homerc = r_str_home (R2_HOME_RC_DIR);
homerc = r_file_new (configdir, "radare2rc.d", NULL);
free (configdir);
if (homerc) {
if (r_file_is_directory (homerc)) {
char *file;
@ -4295,11 +4300,9 @@ R_API void r_core_parse_radare2rc(RCore *r) {
RList *files = r_sys_dir (homerc);
r_list_foreach (files, iter, file) {
if (*file != '.') {
char *path = r_str_newf ("%s/%s", homerc, file);
char *path = r_file_new (homerc, file, NULL);
if (r_file_is_regular (path)) {
if (has_debug) {
eprintf ("USER CONFIG loaded from %s\n", homerc);
}
R_LOG_DEBUG ("user script loaded from %s", homerc);
r_core_cmd_file (r, path);
}
free (path);

View File

@ -541,7 +541,9 @@ R_API bool r_core_file_loadlib(RCore *core, const char *lib, ut64 libaddr) {
return ret;
}
#if 0
static void load_scripts_for(RCore *core, const char *name) {
// imho nobody uses this: run scripts depending on a specific filetype
char *file;
RListIter *iter;
char *hdir = r_str_newf (R_JOIN_2_PATHS (R2_HOME_BINRC, "bin-%s"), name);
@ -560,6 +562,7 @@ static void load_scripts_for(RCore *core, const char *name) {
free (path);
free (hdir);
}
#endif
typedef struct {
const char *name;
@ -656,11 +659,13 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
msg[1] = 0;
r_config_set (r->config, "bin.str.filter", msg);
}
//r_core_bin_set_env (r, binfile);
plugin = r_bin_file_cur_plugin (binfile);
#if 0
//r_core_bin_set_env (r, binfile);
if (plugin && plugin->name) {
load_scripts_for (r, plugin->name);
}
#endif
r_core_bin_export_info (r, R_MODE_SET);
cmd_load = r_config_get (r->config, "cmd.load");
if (cmd_load && *cmd_load) {

View File

@ -2979,7 +2979,9 @@ static int cmd_system(void *data, const char *input) {
case '-': //!-
if (input[1]) {
r_line_hist_free ();
r_line_hist_save (R2_HOME_HISTORY);
char *history_file = r_xdg_cachedir ("history");
r_line_hist_save (history_file);
free (history_file);
} else {
r_line_hist_free ();
}
@ -3021,8 +3023,10 @@ static int cmd_system(void *data, const char *input) {
free (cmd);
}
} else {
R_LOG_INFO ("History saved to "R2_HOME_HISTORY);
r_line_hist_save (R2_HOME_HISTORY);
char *history_file = r_xdg_cachedir ("history");
R_LOG_INFO ("History saved to %s", history_file);
r_line_hist_save (history_file);
free (history_file);
}
}
break;

View File

@ -54,13 +54,13 @@ static const char *help_msg_ec[] = {
"Vars:", "", "",
"colors:", "", "rgb:000, red, green, blue, #ff0000, ...",
"e scr.color", "=0", "use more colors (0: no color 1: ansi 16, 2: 256, 3: 16M)",
"$DATADIR/radare2/cons", "", R_JOIN_2_PATHS ("~", R2_HOME_THEMES) " ./",
"$DATADIR/radare2/cons", "", "~/.local/share/radare2/cons", // XXX should be themes
NULL
};
static const char *help_msg_eco[] = {
"Usage: eco[jc] [theme]", "", "load theme (cf. Path and dir.prefix)",
"eco", "", "list available themes",
"eco", "", "list available themes (See e dir.themes)",
"eco.", "", "display current theme name",
"eco*", "", "show current theme script",
"eco!", "", "edit and reload current theme",
@ -68,7 +68,7 @@ static const char *help_msg_eco[] = {
"ecoq", "", "list available themes without showing the current one",
"ecoj", "", "list available themes in JSON",
"Path:", "", "",
"$DATADIR/radare2/cons", "", R_JOIN_2_PATHS ("~", R2_HOME_THEMES) " ./",
"$DATADIR/radare2/cons", "", "~/.local/share/radare2/cons", // XXX should be themes
NULL
};
@ -154,18 +154,17 @@ static bool cmd_load_theme(RCore *core, const char *_arg) {
if (!_arg || !*_arg) {
return false;
}
if (!r_str_cmp (_arg, "default", strlen (_arg))) {
if (!strcmp (_arg, "default")) {
core->theme = r_str_dup (core->theme, _arg);
r_cons_pal_init (core->cons->context);
return true;
}
char *arg = strdup (_arg);
// system themes directory
char *home = r_xdg_datadir ("cons");
char *tmp = r_str_newf (R_JOIN_2_PATHS (R2_HOME_THEMES, "%s"), arg);
char *home = tmp ? r_str_home (tmp) : NULL;
free (tmp);
tmp = r_str_newf (R_JOIN_2_PATHS (R2_THEMES, "%s"), arg);
// system themes directory
char *tmp = r_str_newf (R_JOIN_2_PATHS (R2_THEMES, "%s"), arg);
path = tmp ? r_str_r2_prefix (tmp) : NULL;
free (tmp);
@ -221,7 +220,7 @@ R_API RList *r_core_list_themes(RCore *core) {
getNext = false;
char *tmp = strdup ("default");
r_list_append (list, tmp);
char *path = r_str_home (R2_HOME_THEMES R_SYS_DIR);
char *path = r_xdg_datadir ("cons");
if (path) {
list_themes_in_path (list, path);
R_FREE (path);
@ -251,7 +250,7 @@ static void nextpal(RCore *core, int mode) {
}
pj_a (pj);
}
char *home = r_str_home (R2_HOME_THEMES R_SYS_DIR);
char *home = r_xdg_datadir ("cons");
getNext = false;
// spaguetti!

View File

@ -1513,16 +1513,9 @@ static void cmd_print_gadget(RCore *core, const char *_input) {
static void cmd_pfo_help(RCore *core) {
const char *help[] = {
"Usage:", "pfo [format-file]", "# List all format definition files (fdf)",
/* literally, whitespaces to prevent help system rendering rows as headers */
R_JOIN_3_PATHS ("~", R2_HOME_SDB_FORMAT, ""), " ", " ",
"<insert sys prefix path here>", " ", " ",
NULL
};
char *buf = r_str_newf ("%s"R_SYS_DIR"%s", R2_SDB_FORMAT, r_sys_prefix (NULL));
help[6] = buf;
r_core_cmd_help (core, help);
free (buf);
}
static ut64 read_val(RBitmap *bm, int pos, int sz) {
@ -1800,10 +1793,7 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block,
cmd_pfo_help (core);
} else if (_input[2] == ' ') {
const char *fname = r_str_trim_head_ro (_input + 3);
char *tmp = r_str_newf (R_JOIN_2_PATHS (R2_HOME_SDB_FORMAT, "%s"), fname);
char *home = r_str_home (tmp);
free (tmp);
tmp = r_str_newf (R_JOIN_2_PATHS (R2_SDB_FORMAT, "%s"), fname);
char *tmp = r_str_newf (R_JOIN_2_PATHS (R2_SDB_FORMAT, "%s"), fname);
char *path = r_str_r2_prefix (tmp);
if (r_str_endswith (_input, ".h")) {
char *error_msg = NULL;
@ -1817,20 +1807,22 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block,
R_LOG_ERROR ("Cannot parse: %s", error_msg);
}
} else {
/// XXX not sure what this code is suposed to be used for
char *home = r_xdg_datadir ("format");
if (!r_core_cmd_file (core, home) && !r_core_cmd_file (core, path)) {
if (!r_core_cmd_file (core, _input + 3)) {
R_LOG_ERROR ("pfo: cannot open format file at '%s'", path);
}
}
free (home);
}
free (home);
free (path);
free (tmp);
} else {
RList *files;
RListIter *iter;
const char *fn;
char *home = r_str_home (R2_HOME_SDB_FORMAT R_SYS_DIR);
char *home = r_xdg_datadir ("format");
if (home) {
files = r_sys_dir (home);
r_list_foreach (files, iter, fn) {

View File

@ -22,7 +22,7 @@ static RCoreHelpMessage help_msg_P = {
"Px", "-", "close the opened project (R2_580 -> Pc)",
"NOTE:", "", "the 'e prj.name' evar can save/open/rename/list projects.",
"NOTE:", "", "see the other 'e??prj.' evars for more options.",
"NOTE:", "", "project are stored in " R_JOIN_2_PATHS ("~", R2_HOME_PROJECTS),
"NOTE:", "", "project are stored in dir.projects",
NULL
};

View File

@ -2663,7 +2663,7 @@ R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, ut8 ch, bo
static void r_core_setenv(RCore *core) {
char *e = r_sys_getenv ("PATH");
char *h = r_str_home (R2_HOME_BIN);
char *h = r_xdg_datadir ("prefix/bin"); // support \\ on windows :?
char *n = r_str_newf ("%s%s%s", h, R_SYS_ENVSEP, e);
r_sys_setenv ("PATH", n);
free (n);

View File

@ -3,9 +3,11 @@
#include <r_core.h>
static char *getFortuneFile(RCore *core, const char *type) {
char *ft = r_str_newf(R_JOIN_2_PATHS (R2_HOME_FORTUNES, "fortunes.%s"), type);
char *fortunedir = r_xdg_datadir ("fortunes");
char *ft = r_str_newf ("%s/fortunes.%s", fortunedir, type);
char *path = r_str_home (ft);
free (ft);
free (fortunedir);
if (path && r_file_exists (path)) {
return path;
}
@ -51,7 +53,7 @@ R_IPI RList *r_core_fortune_types(void) { // R_API 5.8
return NULL;
}
free (fortune_dir);
fortune_dir = r_str_home (R2_HOME_FORTUNES);
fortune_dir = r_xdg_datadir ("fortunes");
if (fortune_dir) {
_push_types (types, fortune_dir);
free (fortune_dir);

View File

@ -80,7 +80,7 @@ static void __loadSystemPlugins(RCore *core, int where, const char *path) {
free (p);
}
if (where & R_CORE_LOADLIBS_HOME) {
char *hpd = r_str_home (R2_HOME_PLUGINS);
char *hpd = r_xdg_datadir ("plugins");
if (hpd) {
r_lib_opendir (core->lib, hpd);
free (hpd);
@ -143,7 +143,7 @@ R_API bool r_core_loadlibs(RCore *core, int where, const char *path) {
return false;
}
// load script plugins
char *homeplugindir = r_str_home (R2_HOME_PLUGINS);
char *homeplugindir = r_xdg_datadir ("plugins");
RList *files = r_sys_dir (homeplugindir);
RListIter *iter;
char *file;

View File

@ -5054,7 +5054,7 @@ static void __update_menu(RCore *core, const char *parent, R_NULLABLE RPanelMenu
}
static char *__get_panels_config_dir_path(void) {
return r_str_home (R_JOIN_2_PATHS (R2_HOME_DATADIR, ".r2panels"));
return r_xdg_datadir ("r2panels");
}
static void __add_menu(RCore *core, const char *parent, const char *name, RPanelsMenuCallback cb) {

View File

@ -500,7 +500,7 @@ R_API bool r_core_visual_hud(RCore *core) {
char *f = r_str_newf (R_JOIN_3_PATHS ("%s", R2_HUD, "main"),
r_sys_prefix (NULL));
int use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
char *homehud = r_str_home (R2_HOME_HUD);
char *homehud = r_xdg_datadir ("hud");
bool ready = false;
char *res = NULL;
r_cons_context ()->color_mode = use_color;

View File

@ -79,27 +79,6 @@ extern "C" {
#define R2_SDB_MAGIC R_JOIN_2_PATHS (R2_SDB, "magic")
#define R2_SDB_FORMAT R_JOIN_2_PATHS (R2_SDB, "format")
#define R2_HOME_CONFIGDIR R_JOIN_2_PATHS (".config", "radare2")
#define R2_HOME_DATADIR R_JOIN_3_PATHS (".local", "share", "radare2")
#define R2_HOME_CACHEDIR R_JOIN_2_PATHS (".cache", "radare2")
#define R2_HOME_THEMES R_JOIN_2_PATHS (R2_HOME_DATADIR, "cons")
#define R2_HOME_FORTUNES R_JOIN_2_PATHS (R2_HOME_DATADIR, "fortunes")
#define R2_HOME_PLUGINS R_JOIN_2_PATHS (R2_HOME_DATADIR, "plugins")
#define R2_HOME_ZIGNS R_JOIN_2_PATHS (R2_HOME_DATADIR, "zigns")
#define R2_HOME_PDB R_JOIN_2_PATHS (R2_HOME_DATADIR, "pdb")
#define R2_HOME_PROJECTS R_JOIN_2_PATHS (R2_HOME_DATADIR, "projects")
#define R2_HOME_WWWROOT R_JOIN_2_PATHS (R2_HOME_DATADIR, "www")
#define R2_HOME_SDB_FCNSIGN R_JOIN_2_PATHS (R2_HOME_DATADIR, "fcnsign")
#define R2_HOME_SDB_FORMAT R_JOIN_2_PATHS (R2_HOME_DATADIR, "format")
#define R2_HOME_HUD R_JOIN_2_PATHS (R2_HOME_DATADIR, "hud")
#define R2_HOME_BINRC R_JOIN_2_PATHS (R2_HOME_DATADIR, "rc.d")
#define R2_HOME_BIN R_JOIN_3_PATHS (R2_HOME_DATADIR, "prefix", "bin")
#define R2_HOME_HISTORY R_JOIN_2_PATHS (R2_HOME_CACHEDIR, "history")
#define R2_HOME_RC R_JOIN_2_PATHS (R2_HOME_CONFIGDIR, "radare2rc")
#define R2_HOME_RC_DIR R_JOIN_2_PATHS (R2_HOME_CONFIGDIR, "radare2rc.d")
#define R2_GLOBAL_RC R_JOIN_2_PATHS (R2_DATDIR_R2, "radare2rc")
#define HAVE_LIB_MAGIC @HAVE_LIB_MAGIC@

View File

@ -319,7 +319,7 @@ static void r2pm_setenv(void) {
r_sys_setenv ("MAKE", "make");
}
free (gmake);
char *r2_plugdir = r_str_home (R2_HOME_PLUGINS);
char *r2_plugdir = r_xdg_datadir ("plugins");
r_sys_setenv ("R2PM_PLUGDIR", r2_plugdir);
free (r2_plugdir);
@ -336,7 +336,7 @@ static void r2pm_setenv(void) {
r_sys_setenv ("R2_USER_PLUGINS", pd);
free (pd);
char *r2_prefix = r_str_home (R2_HOME_DATADIR "/prefix");
char *r2_prefix = r_xdg_datadir ("prefix");
r_sys_setenv ("R2PM_PREFIX", r2_prefix);
char *r2pm_bindir = r_str_newf ("%s/bin", r2_prefix);

View File

@ -587,7 +587,7 @@ R_API int r_main_rabin2(int argc, const char **argv) {
bin = core.bin;
if (!(tmp = r_sys_getenv ("RABIN2_NOPLUGINS"))) {
char *homeplugindir = r_str_home (R2_HOME_PLUGINS);
char *homeplugindir = r_xdg_datadir ("plugins");
char *plugindir = r_str_r2_prefix (R2_PLUGINS);
char *extrasdir = r_str_r2_prefix (R2_EXTRAS);
char *bindingsdir = r_str_r2_prefix (R2_BINDINGS);

View File

@ -157,53 +157,52 @@ static int main_help(int line) {
" -z, -zz do not load strings or load them even in raw\n");
}
if (line == 2) {
char *datahome = r_str_home (R2_HOME_DATADIR);
const char *dirPrefix = r_sys_prefix (NULL);
printf (
"Scripts:\n"
" system ${R2_PREFIX}/share/radare2/radare2rc\n"
" user ~/.radare2rc " R_JOIN_2_PATHS ("~", R2_HOME_RC) " (and " R_JOIN_3_PATHS ("~", R2_HOME_RC_DIR,"") ")\n"
" file ${filename}.r2\n"
"Plugins:\n"
" binrc " R_JOIN_4_PATHS ("~", R2_HOME_BINRC, "bin-<format>", "") " (elf, elf64, mach0, ..)\n"
" R2_LIBR_PLUGINS " R_JOIN_2_PATHS ("%s", R2_PLUGINS) "\n"
" R2_USER_PLUGINS " R_JOIN_2_PATHS ("~", R2_HOME_PLUGINS) "\n"
" R2_USER_ZIGNS " R_JOIN_2_PATHS ("~", R2_HOME_ZIGNS) "\n"
char *datahome = r_xdg_datadir (NULL);
const char *dirPrefix = R2_PREFIX;
RStrBuf *sb = r_strbuf_new ("");
r_strbuf_append (sb, "Scripts:\n");
r_strbuf_appendf (sb, " system %s/share/radare2/radare2rc\n", dirPrefix);
r_strbuf_append (sb, " user ~/.radare2rc ${XDG_CONFIG_DIR:=~/.local/share/}/radare2/radare2rc{.d/}\n");
r_strbuf_append (sb, " file ${filename}.r2\n");
r_strbuf_append (sb, "Plugins:\n");
r_strbuf_appendf (sb, " R2_LIBR_PLUGINS " R_JOIN_2_PATHS ("%s", R2_PLUGINS) "\n"
" R2_USER_PLUGINS ${XDG_DATA_DIR:=~/.local/share/radare2}/plugins\n"
" R2_USER_ZIGNS ${XDG_DATA_DIR:=~/.local/share/radare2}/zigns\n"
"Environment:\n"
" R2_COLOR sets the initial value for 'scr.color'. set to 0 for no color\n"
" R2_DEBUG if defined, show error messages and crash signal.\n"
" R2_DEBUG_ASSERT set a breakpoint when hitting an assert.\n"
" R2_IGNVER load plugins ignoring the specified version. (be careful)\n"
" R2_MAGICPATH " R_JOIN_2_PATHS ("%s", R2_SDB_MAGIC) "\n"
" R2_NOPLUGINS do not load r2 shared plugins\n"
" R2_HISTORY " R2_HOME_HISTORY "\n"
" R2_RCFILE ~/.radare2rc (user preferences, batch script)\n" // TOO GENERIC
" R2_MAGICPATH %s/"R2_SDB_MAGIC"\n"
" R2_NOPLUGINS do not load r2 shared plugins\n", dirPrefix, dirPrefix);
r_strbuf_append (sb, " R2_HISTORY ${XDG_CACHE_DIR:=~/.cache/radare2}/history\n");
r_strbuf_append (sb, " R2_RCFILE ~/.radare2rc (user preferences, batch script)\n" // TOO GENERIC
" R2_CURL set to '1' to use system curl program instead of r2 apis\n"
" R2_RDATAHOME %s\n" // TODO: rename to RHOME R2HOME?
);
r_strbuf_appendf (sb, " R2_DATA_HOME %s\n"
" R2_VERSION contains the current version of r2\n"
" R2_LOG_LEVEL numeric value of the max level of messages to show\n"
" R2_LOG_FILE dump all logs to a file\n"
#if 0
" R2_COLOR \n"
#endif
"Paths:\n"
" R2_INCDIR "R2_INCDIR"\n"
" R2_LIBDIR "R2_LIBDIR"\n"
" R2_LIBEXT "R_LIB_EXT"\n"
" R2_PREFIX "R2_PREFIX"\n"
, dirPrefix, datahome, dirPrefix);
, datahome);
free (datahome);
char *helpmsg = r_strbuf_drain (sb);
if (helpmsg) {
printf ("%s", helpmsg);
free (helpmsg);
}
}
return 0;
}
static int main_print_var(const char *var_name) {
int i = 0;
#if 0
XDG_DATA_HOME si no existeix hauria de ser ~/.local/share/
XDG_CONFIG_HOME si no existeix hauria de ser ~/.config/
XDG_CACHE_HOME si no existeix hauria de ser ~/.cache/
#endif
#ifdef __WINDOWS__
char *incdir = r_str_r2_prefix (R2_INCDIR);
char *libdir = r_str_r2_prefix (R2_LIBDIR);
@ -211,14 +210,14 @@ XDG_CACHE_HOME si no existeix hauria de ser ~/.cache/
char *incdir = strdup (R2_INCDIR);
char *libdir = strdup (R2_LIBDIR);
#endif
char *confighome = r_str_home (R2_HOME_CONFIGDIR);
char *datahome = r_str_home (R2_HOME_DATADIR);
char *cachehome = r_str_home (R2_HOME_CACHEDIR);
char *homeplugins = r_str_home (R2_HOME_PLUGINS);
char *homezigns = r_str_home (R2_HOME_ZIGNS);
char *confighome = r_xdg_configdir (NULL);
char *datahome = r_xdg_datadir (NULL);
char *cachehome = r_xdg_cachedir (NULL);
char *homeplugins = r_xdg_datadir ("plugins");
char *homezigns = r_xdg_datadir ("zigns");
char *plugins = r_str_r2_prefix (R2_PLUGINS);
char *magicpath = r_str_r2_prefix (R2_SDB_MAGIC);
char *historyhome = r_str_home (R2_HOME_HISTORY);
char *historyhome = r_xdg_cachedir ("history");
struct {
const char *name;
const char *value;
@ -229,13 +228,13 @@ XDG_CACHE_HOME si no existeix hauria de ser ~/.cache/
{ "R2_INCDIR", incdir },
{ "R2_LIBDIR", libdir },
{ "R2_LIBEXT", R_LIB_EXT },
{ "R2_RCONFIGHOME", confighome },
{ "R2_RDATAHOME", datahome },
{ "R2_HISTORY", historyhome },
{ "R2_RCACHEHOME", cachehome },
{ "R2_CONFIG_HOME", confighome }, // from xdg
{ "R2_CACHE_HOME", cachehome }, // fro xdg
{ "R2_LIBR_PLUGINS", plugins },
{ "R2_USER_PLUGINS", homeplugins },
{ "R2_USER_ZIGNS", homezigns },
{ "R2_ZIGNS_HOME", homezigns },
{ NULL, NULL }
};
int delta = 0;
@ -540,6 +539,7 @@ R_API int r_main_radare2(int argc, const char **argv) {
char *envprofile = r_run_get_environ_profile (env);
if (r_sys_getenv_asbool ("R2_DEBUG")) {
r_log_set_level (R_LOGLVL_DEBUG);
char *sysdbg = r_sys_getenv ("R2_DEBUG_TOOL");
char *fmt = (sysdbg && *sysdbg)
? strdup (sysdbg)
@ -1713,7 +1713,11 @@ R_API int r_main_radare2(int argc, const char **argv) {
}
if (mustSaveHistory (r->config)) {
r_line_hist_save (R2_HOME_HISTORY);
char *history_file = r_xdg_cachedir ("history");
if (history_file) {
r_line_hist_save (history_file);
free (history_file);
}
}
ret = r->rc;

View File

@ -57,7 +57,7 @@ static void __load_plugins(REggState *es) {
}
// load plugins from the home directory
char *homeplugindir = r_str_home (R2_HOME_PLUGINS);
char *homeplugindir = r_xdg_datadir ("plugins");
r_lib_opendir (es->l, homeplugindir);
free (homeplugindir);

View File

@ -690,7 +690,7 @@ static void __load_plugins(RAsmState *as) {
}
// load plugins from the home directory
char *homeplugindir = r_str_home (R2_HOME_PLUGINS);
char *homeplugindir = r_xdg_datadir ("plugins");
r_lib_opendir (as->l, homeplugindir);
free (homeplugindir);

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2012-2021 - pancake */
/* radare - LGPL - Copyright 2012-2022 - pancake */
#include <r_util.h>
#include <signal.h>
@ -24,7 +24,7 @@ static R_TH_LOCAL int G_graintype = R_SANDBOX_GRAIN_NONE;
static bool inHomeWww(const char *path) {
r_return_val_if_fail (path, false);
bool ret = false;
char *homeWww = r_str_home (R2_HOME_WWWROOT R_SYS_DIR);
char *homeWww = r_xdg_datadir ("www");
if (homeWww) {
if (r_str_startswith (path, homeWww)) {
ret = true;

View File

@ -2,6 +2,13 @@
// move into file.c ?
#include <r_util.h>
#if 0
macOS:
* ~/Library/radare2?
Windows
* %AppData% ?= XDG_DATA_HOME
* %LocalAppData% ?= XDG_CACHE_HOME
#endif
static char *xdg(const char *env, const char *a, const char *s) {
char *dir = r_sys_getenv (env);