1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-06-02 07:20:47 +00:00

use the builtin config also as a default one

This depends on fopencookie, which is linux-specific. For BSD, there is
a similar function called funopen, which can be used as a drop-in
replacement.
This commit is contained in:
Phil Sutter 2008-12-14 14:36:44 +01:00
parent 7dca22a41b
commit 1ddb6a88b9
6 changed files with 78 additions and 13 deletions

View File

@ -101,6 +101,7 @@ AC_ARG_ENABLE([config_output],
AM_CONDITIONAL(BUILD_CONFIG_OUTPUT, test x$want_config_output = xyes)
if test x$want_config_output = xyes; then
AC_DEFINE(CONFIG_OUTPUT, 1, [Define if you want conky to output a default config (with -C)])
AC_CHECK_FUNCS(fopencookie, AM_CONDITIONAL(BUILD_FOR_FOPENCOOKIE, true))
fi
dnl

View File

@ -29,6 +29,9 @@ bin_PROGRAMS = conky
if BUILD_CONFIG_OUTPUT
config_output = defconfig.h
if BUILD_FOR_FOPENCOOKIE
config_cookie = conf_cookie.c conf_cookie.h
endif
conky_DEPENDENCIES = $(config_output)
BUILT_SOURCES = $(config_output)
CLEANFILES = $(config_output)
@ -110,6 +113,7 @@ endif
conky_SOURCES = \
$(config_output) \
$(config_cookie) \
$(audacious) \
$(bmpx) \
common.c \
@ -146,6 +150,7 @@ conky_LDFLAGS = \
EXTRA_DIST = \
$(config_output) \
$(config_cookie) \
audacious.c \
audacious.h \
bmpx.c \

33
src/conf_cookie.c Normal file
View File

@ -0,0 +1,33 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include "defconfig.h"
ssize_t conf_read(void *cookie, char *buf, size_t size)
{
static int col = 0, row = 0;
size_t i = 0;
const char *conf[] = defconfig;
(void)cookie;
while (i < size) {
if (!(conf[row])) /* end of rows */
break;
if (!(conf[row][col])) { /* end of line */
row++;
col = 0;
continue;
}
buf[i++] = conf[row][col++];
}
return i;
}
cookie_io_functions_t conf_cookie = {
.read = &conf_read,
.write = NULL,
.seek = NULL,
.close = NULL,
};

8
src/conf_cookie.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _CONF_COOKIE_H
#define _CONF_COOKIE_H
#include <stdio.h>
extern cookie_io_functions_t conf_cookie;
#endif /* _CONF_COOKIE_H */

View File

@ -60,6 +60,9 @@
#ifdef CONFIG_OUTPUT
#include "defconfig.h"
#ifdef HAVE_FOPENCOOKIE
#include "conf_cookie.h"
#endif
#endif
#include "build.h"
@ -7761,10 +7764,19 @@ static void load_config_file(const char *f)
FILE *fp;
set_default_configurations();
fp = fopen(f, "r");
#ifdef CONFIG_OUTPUT
if (!strcmp(f, "==builtin==")) {
#ifdef HAVE_FOPENCOOKIE
fp = fopencookie(NULL, "r", conf_cookie);
#endif
} else
#endif /* CONFIG_OUTPUT */
fp = fopen(f, "r");
if (!fp) {
return;
}
DBGP("reading contents from config file '%s'", f);
while (!feof(fp)) {
char buf[256], *p, *p2, *name, *value;
@ -8649,7 +8661,13 @@ int main(int argc, char **argv)
/* No readable config found */
if (!current_config) {
#ifdef CONFIG_OUTPUT
current_config = strdup("==builtin==");
ERR("no readable personal or system-wide config file found,"
" using builtin default");
#else
CRIT_ERR("no readable personal or system-wide config file found");
#endif /* ! CONF_OUTPUT */
}
}

View File

@ -23,9 +23,9 @@
# $2: output file
# $3: name of variable
#
# The output will be a char **, with each field containing a single line of $1
# additionally, a macro with the name print_$3 will be defined, with acts as
# a parameter-less function, printing the text to stdout
# The output will be a char **, with each field containing a single line of $1.
# Additionally, a macro with the name print_$3 will be defined, with acts as
# a parameter-less function, printing the text to stdout.
[ $# -eq 3 ] || {
echo "Usage: `basename $0` <inputfile> <outputfile> <variablename>"
@ -37,14 +37,14 @@ outupper="`basename "$2" | tr '[a-z-.]' '[A-Z__]'`"
(
printf "#ifndef __%s\n" "$outupper"
printf "#define __%s\n" "$outupper"
printf "const char *%s[] = {\n" "$3"
sed -e 's/"/\\"/g' -e 's/^/"/' -e 's/$/",/' $1
printf "NULL };\n"
printf "#define print_%s() { \\" $3
printf "\n\tconst char **__s = %s; \\" $3
printf "\n\tfor (; *__s; __s++) \\"
printf "\n\t\tputs(*__s); \\"
printf "\n}\n"
printf "\n#define %s { \\" $3
printf "\n"
sed -e 's/"/\\"/g' -e 's/^/"/' -e 's/$/\\n", \\/' $1
printf "NULL }\n"
printf "\n#define print_%s() { \\" $3
printf "\n\tconst char **__sp, *__s[] = %s; \\" $3
printf "\n\tfor (__sp = __s; *__sp; __sp++) \\"
printf "\n\t\tprintf(\"%s\", *__sp); \\" "%s"
printf "\n}\n\n"
printf "#endif /* __%s */\n" "$outupper"
) > $2