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
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)
conky_SOURCES = \
$(config_output) \
+ $(config_cookie) \
$(audacious) \
$(bmpx) \
common.c \
EXTRA_DIST = \
$(config_output) \
+ $(config_cookie) \
audacious.c \
audacious.h \
bmpx.c \
--- /dev/null
+#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,
+};
+
--- /dev/null
+#ifndef _CONF_COOKIE_H
+#define _CONF_COOKIE_H
+
+#include <stdio.h>
+
+extern cookie_io_functions_t conf_cookie;
+
+#endif /* _CONF_COOKIE_H */
#ifdef CONFIG_OUTPUT
#include "defconfig.h"
+#ifdef HAVE_FOPENCOOKIE
+#include "conf_cookie.h"
+#endif
#endif
#include "build.h"
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;
/* 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 */
}
}
# $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>"
(
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
-