[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[COMMITTED 2/3] poked: Respect useful env vars
From: |
Mohammad-Reza Nabipoor |
Subject: |
[COMMITTED 2/3] poked: Respect useful env vars |
Date: |
Thu, 10 Mar 2022 22:56:28 +0330 |
2022-03-10 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* poked/poked.c (poked_init): Handle `POKEDATADIR`, `POKEPICKLESDIR`,
`POKEDAPPDIR` env vars.
* run.in (POKEDAPPDIR): Define.
---
ChangeLog | 6 ++++++
poked/poked.c | 32 ++++++++++++++++++++++++++------
run.in | 5 +++--
3 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9778fdfb..c11aad33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2022-03-10 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
+
+ * poked/poked.c (poked_init): Handle `POKEDATADIR`, `POKEPICKLESDIR`,
+ `POKEDAPPDIR` env vars.
+ * run.in (POKEDAPPDIR): Define.
+
2022-03-10 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* poked/poked.c (main): Add `poked_restart` support.
diff --git a/poked/poked.c b/poked/poked.c
index 705341ee..f8abd596 100644
--- a/poked/poked.c
+++ b/poked/poked.c
@@ -466,14 +466,35 @@ poked_init (void)
};
static const size_t FUNCS_LEN = sizeof (FUNCS) / sizeof (FUNCS[0]);
const char *pk = getenv ("POKED_PK");
+ const char *poke_datadir = getenv ("POKEDATADIR");
+ const char *poke_picklesdir = getenv ("POKEPICKLESDIR");
+ const char *poked_appdir = getenv ("POKEDAPPDIR");
int ret;
pk_val exc;
pk_val pval;
+ poke_datadir = getenv ("POKEDATADIR");
+ if (poke_datadir == NULL)
+ poke_datadir = PKGDATADIR;
+
+ if (poke_picklesdir == NULL)
+ poke_picklesdir = "%DATADIR%/pickles";
+
+ if (poked_appdir == NULL)
+ {
+ poked_appdir = pk_str_concat (poke_datadir, "/poked", NULL);
+ if (poked_appdir == NULL)
+ err (1, "pk_str_concat() failed");
+ }
+
+ // For debug
+ fprintf (stderr, "poke_datadir %s\n", poke_datadir);
+ fprintf (stderr, "poke_pickledir %s\n", poke_picklesdir);
+ fprintf (stderr, "poked_appdir %s\n", poked_appdir);
+
if (pkc)
poked_free ();
- // tifbuf_init(); // FIXME FIXME FIXME
pkc = pk_compiler_new (&tif);
if (pkc == NULL)
errx (1, "pk_compiler_new() failed");
@@ -486,8 +507,9 @@ poked_init (void)
pk_val load_path = pk_decl_val (pkc, "load_path");
char *newpath = pk_str_concat (pk_string_str (load_path),
":",
- PKGDATADIR,
- "/poked",
+ poked_appdir,
+ ":",
+ poke_picklesdir,
NULL);
pk_decl_set_val (pkc, "load_path", pk_make_string (newpath));
@@ -499,9 +521,7 @@ poked_init (void)
ret = pk_compile_file (pkc, pk, &exc);
else
{
- char *fullpk = pk_str_concat (PKGDATADIR,
- "/poked/poked.pk",
- NULL);
+ char *fullpk = pk_str_concat (poked_appdir, "/poked.pk", NULL);
ret = pk_compile_file (pkc, fullpk, &exc);
free (fullpk);
diff --git a/run.in b/run.in
index 1ca98249..7b76ea86 100644
--- a/run.in
+++ b/run.in
@@ -33,13 +33,14 @@ PATH=$b/poke:$PATH
POKEDATADIR=$s/libpoke
POKEINFODIR=$s/doc
POKEAPPDIR=$s/poke
+POKEDAPPDIR=$s/poked
POKEPICKLESDIR=$s/pickles
POKEMAPSDIR=$s/maps
POKEDOCDIR=$s/doc
POKESTYLESDIR=$s/etc
POKE_LOAD_PATH=$s/poke
-export PATH POKEDATADIR POKEPICKLESDIR POKEAPPDIR POKECMDSDIR POKESTYLESDIR
POKEINFODIR
-export POKE_LOAD_PATH POKEDOCDIR POKEMAPSDIR
+export PATH POKEDATADIR POKEPICKLESDIR POKEAPPDIR POKEDAPPDIR POKECMDSDIR
+export POKESTYLESDIR POKEINFODIR POKE_LOAD_PATH POKEDOCDIR POKEMAPSDIR
# Cheap way to find some use-after-free and uninit read problems with glibc
MALLOC_CHECK_=1
--
2.35.1