1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

Merge branch 'master' of git://nwl.cc/~n0-1/conky

Conflicts:
	configure.ac.in
This commit is contained in:
Brenden Matthews 2008-12-14 22:42:20 -07:00
commit 60fc99ef71
6 changed files with 106 additions and 24 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
@ -716,4 +717,5 @@ $PACKAGE $VERSION configured successfully:
SMAPI: $want_smapi
nvidia: $want_nvidia
eve-online: $want_eve
config-output: $want_config_output
EOF

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"
@ -1948,9 +1951,25 @@ void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
}
}
/* strip a leading /dev/ if any */
#define DEV_NAME(x) x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 \
? x + 5 : x
/* strip a leading /dev/ if any, following symlinks first
*
* BEWARE: this function returns a pointer to static content
* which gets overwritten in consecutive calls. I.e.:
* this function is NOT reentrant.
*/
const char *dev_name(const char *path)
{
static char buf[255]; /* should be enough for pathnames */
ssize_t buflen;
#define DEV_NAME(x) \
x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
if ((buflen = readlink(path, buf, 254)) == -1)
return DEV_NAME(path);
buf[buflen] = '\0';
return DEV_NAME(buf);
#undef DEV_NAME
}
/* construct_text_object() creates a new text_object */
static struct text_object *construct_text_object(const char *s,
@ -2125,7 +2144,7 @@ static struct text_object *construct_text_object(const char *s,
#if defined(__linux__)
END OBJ(disk_protect, 0)
if (arg)
obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
obj->data.s = strndup(dev_name(arg), text_buffer_size);
else
CRIT_ERR("disk_protect needs an argument");
END OBJ(i8k_version, INFO_I8K)
@ -2175,7 +2194,7 @@ static struct text_object *construct_text_object(const char *s,
CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
obj->data.s = 0;
} else
obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
obj->data.s = strndup(dev_name(arg), text_buffer_size);
END OBJ(laptop_mode, 0)
END OBJ(pb_battery, 0)
if (arg && strcmp(arg, "status") == EQUAL) {
@ -2282,24 +2301,24 @@ static struct text_object *construct_text_object(const char *s,
#if defined(__linux__)
END OBJ(diskio, INFO_DISKIO)
if (arg) {
obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
} else {
obj->data.diskio = NULL;
}
END OBJ(diskio_read, INFO_DISKIO)
if (arg) {
obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
} else {
obj->data.diskio = NULL;
}
END OBJ(diskio_write, INFO_DISKIO)
if (arg) {
obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
} else {
obj->data.diskio = NULL;
}
END OBJ(diskiograph, INFO_DISKIO)
char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
char *buf = scan_graph(dev_name(arg), &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog);
if (buf) {
@ -2309,7 +2328,7 @@ static struct text_object *construct_text_object(const char *s,
obj->data.diskio = NULL;
}
END OBJ(diskiograph_read, INFO_DISKIO)
char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
char *buf = scan_graph(dev_name(arg), &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog);
if (buf) {
@ -2319,7 +2338,7 @@ static struct text_object *construct_text_object(const char *s,
obj->data.diskio = NULL;
}
END OBJ(diskiograph_write, INFO_DISKIO)
char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
char *buf = scan_graph(dev_name(arg), &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog);
if (buf) {
@ -7761,10 +7780,19 @@ static void load_config_file(const char *f)
FILE *fp;
set_default_configurations();
#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 +8677,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