Merge pull request #1011 from psychon/commandline-search

Commandline option to add a directory to Lua's search path.
This commit is contained in:
Daniel Hahler 2016-08-20 18:58:11 +02:00 committed by GitHub
commit e723d183e8
10 changed files with 65 additions and 25 deletions

View file

@ -429,6 +429,7 @@ exit_help(int exit_code)
-h, --help show help\n\
-v, --version show version\n\
-c, --config FILE configuration file to use\n\
--search DIR add a directory to the library search path\n\
-k, --check check configuration file syntax\n\
-a, --no-argb disable client transparency support\n\
-r, --replace replace an existing window manager\n");
@ -444,6 +445,7 @@ int
main(int argc, char **argv)
{
char *confpath = NULL;
string_array_t searchpath;
int xfd, i, opt;
ssize_t cmdlen = 1;
xdgHandle xdg;
@ -457,6 +459,7 @@ main(int argc, char **argv)
{ "version", 0, NULL, 'v' },
{ "config", 1, NULL, 'c' },
{ "check", 0, NULL, 'k' },
{ "search", 1, NULL, 's' },
{ "no-argb", 0, NULL, 'a' },
{ "replace", 0, NULL, 'r' },
{ NULL, 0, NULL, 0 }
@ -471,6 +474,7 @@ main(int argc, char **argv)
globalconf.keygrabber = LUA_REFNIL;
globalconf.mousegrabber = LUA_REFNIL;
buffer_init(&globalconf.startup_errors);
string_array_init(&searchpath);
/* save argv */
for(i = 0; i < argc; i++)
@ -488,12 +492,6 @@ main(int argc, char **argv)
/* Text won't be printed correctly otherwise */
setlocale(LC_CTYPE, "");
/* Get XDG basedir data */
xdgInitHandle(&xdg);
/* init lua */
luaA_init(&xdg);
/* check args */
while((opt = getopt_long(argc, argv, "vhkc:ar",
long_options, NULL)) != -1)
@ -514,6 +512,12 @@ main(int argc, char **argv)
else
fatal("-c option requires a file name");
break;
case 's':
if(a_strlen(optarg))
string_array_append(&searchpath, a_strdup(optarg));
else
fatal("-s option requires a directory name");
break;
case 'a':
no_argb = true;
break;
@ -522,6 +526,13 @@ main(int argc, char **argv)
break;
}
/* Get XDG basedir data */
xdgInitHandle(&xdg);
/* init lua */
luaA_init(&xdg, &searchpath);
string_array_wipe(&searchpath);
if (run_test)
{
if(!luaA_parserc(&xdg, confpath, false))

29
luaa.c
View file

@ -590,7 +590,7 @@ setup_awesome_signals(lua_State *L)
* \param xdg An xdg handle to use to get XDG basedir.
*/
void
luaA_init(xdgHandle* xdg)
luaA_init(xdgHandle* xdg, string_array_t *searchpath)
{
lua_State *L;
static const struct luaL_Reg awesome_lib[] =
@ -681,6 +681,19 @@ luaA_init(xdgHandle* xdg)
/* Export keys */
key_class_setup(L);
/* add XDG_CONFIG_DIR as include path */
const char * const *xdgconfigdirs = xdgSearchableConfigDirectories(xdg);
for(; *xdgconfigdirs; xdgconfigdirs++)
{
/* Append /awesome to *xdgconfigdirs */
const char *suffix = "/awesome";
size_t len = a_strlen(*xdgconfigdirs) + a_strlen(suffix) + 1;
char *entry = p_new(char, len);
a_strcat(entry, len, *xdgconfigdirs);
a_strcat(entry, len, suffix);
string_array_append(searchpath, entry);
}
/* add Lua search paths */
lua_getglobal(L, "package");
if (LUA_TTABLE != lua_type(L, 1))
@ -696,19 +709,17 @@ luaA_init(xdgHandle* xdg)
return;
}
/* add XDG_CONFIG_DIR as include path */
const char * const *xdgconfigdirs = xdgSearchableConfigDirectories(xdg);
for(; *xdgconfigdirs; xdgconfigdirs++)
foreach(entry, *searchpath)
{
size_t len = a_strlen(*xdgconfigdirs);
size_t len = a_strlen(*entry);
lua_pushliteral(L, ";");
lua_pushlstring(L, *xdgconfigdirs, len);
lua_pushliteral(L, "/awesome/?.lua");
lua_pushlstring(L, *entry, len);
lua_pushliteral(L, "/?.lua");
lua_concat(L, 3);
lua_pushliteral(L, ";");
lua_pushlstring(L, *xdgconfigdirs, len);
lua_pushliteral(L, "/awesome/?/init.lua");
lua_pushlstring(L, *entry, len);
lua_pushliteral(L, "/?/init.lua");
lua_concat(L, 3);
lua_concat(L, 3); /* concatenate with package.path */

9
luaa.h
View file

@ -39,6 +39,13 @@
signal_object_emit(L, &global_signals, "debug::deprecation", 1); \
} while(0)
static inline void free_string(char **c)
{
p_delete(c);
}
DO_ARRAY(char*, string, free_string)
/** Print a warning about some Lua code.
* This is less mean than luaL_error() which setjmp via lua_error() and kills
* everything. This only warn, it's up to you to then do what's should be done.
@ -296,7 +303,7 @@ luaA_registerfct(lua_State *L, int idx, int *fct)
return luaA_register(L, idx, fct);
}
void luaA_init(xdgHandle *);
void luaA_init(xdgHandle *, string_array_t *);
bool luaA_parserc(xdgHandle *, const char *, bool);
/** Global signals */

View file

@ -9,7 +9,7 @@ awesome - awesome Fenstermanager
SYNTAX
--------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'Datei'] [*-k* | *--check*]
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'Datei'] [*-k* | *--check*] [*--search* 'Verzeichnis'] [*-a* | *--no-argb*] [*-r* | *--replace]
BESCHREIBUNG
-----------
@ -33,6 +33,8 @@ OPTIONEN
Nutzung einer alternativen Konfigurationsdatei, statt '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*::
Überprüft die Konfigurationsdatei auf Syntaxfehler.
*--search*::
Füge ein Verzeichnis zum Bibliothekssuchpfad hinzu.
*-a*, *--no-argb*::
Verwende keine ARGB-Visuals
*-r*, *--replace*::

View file

@ -9,7 +9,7 @@ awesome - gestor de ventanas awesome
SINOPSIS
--------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FICHERO'] [*-k* | *--check*]
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FICHERO'] [*-k* | *--check*] [*--search* 'DIRECTORIO'] [*-a* | *--no-argb*] [*-r* | *--replace]
DESCRIPCIÓN
-----------
@ -50,6 +50,8 @@ OPCIONES
'$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*::
Verifica la sintaxis del archivo de configuración.
*--search*::
Añadir un directorio a la ruta de búsqueda de biblioteca.
*-a*, *--no-argb*::
No utilice colores ARGB.
*-r*, *--replace*::

View file

@ -9,7 +9,7 @@ awesome - gestionnaire de fenêtres awesome
SYNOPSIS
--------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*]
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*--search* 'DIRECTORY'] [*-a* | *--no-argb*] [*-r* | *--replace]
DESCRIPTION
-----------
@ -43,6 +43,8 @@ OPTIONS
'$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*::
Vérifie la syntaxe du fichier de configuration.
*--search*::
Ajouter un répertoire au chemin de recherche de bibliothèque.
*-a*, *--no-argb*::
N'utilise pas le codage ARGB.
*-r*, *--replace*::

View file

@ -10,7 +10,7 @@ awesome - gestore di finestre awesome
SINOSSI
--------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*]
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*--search* 'DIRECTORY'] [*-a* | *--no-argb*] [*-r* | *--replace]
DESCRIZIONE
-----------
@ -50,6 +50,8 @@ OPZIONI
'$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*::
Verifica la sintassi del file di configurazione.
*--search*::
Aggiungere una directory al percorso di ricerca della libreria.
*-a*, *--no-argb*::
Non usare visuali ARGB.
*-r*, *--replace*::

View file

@ -9,7 +9,7 @@ awesome - потрясающий оконный менеджер
СИНОПСИС
--------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*]
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*--search* 'DIRECTORY'] [*-a* | *--no-argb*] [*-r* | *--replace]
ОПИСАНИЕ
--------
@ -45,6 +45,8 @@ awesome - потрясающий оконный менеджер
Использовать альтернативный конфигурационный файл вместо '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*::
Проверить синтаксис конфигурационного файла.
*--search*::
Добавить каталог в пути поиска библиотеки.
*-a*, *--no-argb*::
Не использовать ARGB.
*-r*, *--replace*::

View file

@ -9,7 +9,7 @@ awesome - awesome window manager
SYNOPSIS
--------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*]
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*--search* 'DIRECTORY'] [*-a* | *--no-argb*] [*-r* | *--replace]
DESCRIPTION
-----------
@ -42,6 +42,8 @@ OPTIONS
Use an alternate configuration file instead of '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*::
Check configuration file syntax.
*--search*::
Add a directory to the library search path.
*-a*, *--no-argb*::
Don't use ARGB visuals.
*-r*, *--replace*::

View file

@ -82,11 +82,10 @@ fi
cd $build_dir
LUA_PATH="$(lua -e 'print(package.path)');lib/?.lua;lib/?/init.lua"
AWESOME_OPTIONS="$AWESOME_OPTIONS --search lib/"
# Add test dir (for _runner.lua).
LUA_PATH="$LUA_PATH;$this_dir/?.lua"
AWESOME_OPTIONS="$AWESOME_OPTIONS --search $this_dir"
XDG_CONFIG_HOME="./"
export LUA_PATH
export XDG_CONFIG_HOME
cd - >/dev/null