mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-02-13 17:38:45 +00:00
Properly load config file and print the default one
ps: the new implementation no longer requires fopencookie() and co.
This commit is contained in:
parent
e935a3d107
commit
eeb1a6a0d7
@ -91,11 +91,6 @@ if(BUILD_HTTP)
|
|||||||
set(conky_libs ${conky_libs} -lmicrohttpd)
|
set(conky_libs ${conky_libs} -lmicrohttpd)
|
||||||
endif(BUILD_HTTP)
|
endif(BUILD_HTTP)
|
||||||
|
|
||||||
if(BUILD_BUILTIN_CONFIG)
|
|
||||||
check_function_exists(fopencookie HAVE_FOPENCOOKIE)
|
|
||||||
check_function_exists(funopen HAVE_FUNOPEN)
|
|
||||||
endif(BUILD_BUILTIN_CONFIG)
|
|
||||||
|
|
||||||
if(BUILD_NCURSES)
|
if(BUILD_NCURSES)
|
||||||
check_include_file(ncurses.h NCURSES_H)
|
check_include_file(ncurses.h NCURSES_H)
|
||||||
find_library(NCURSES_LIB NAMES ncurses)
|
find_library(NCURSES_LIB NAMES ncurses)
|
||||||
|
@ -180,10 +180,6 @@ if(BUILD_ICONV)
|
|||||||
set(optional_sources ${optional_sources} ${iconv})
|
set(optional_sources ${optional_sources} ${iconv})
|
||||||
endif(BUILD_ICONV)
|
endif(BUILD_ICONV)
|
||||||
|
|
||||||
if(BUILD_BUILTIN_CONFIG)
|
|
||||||
set(optional_sources ${optional_sources} conf_cookie.cc)
|
|
||||||
endif(BUILD_BUILTIN_CONFIG)
|
|
||||||
|
|
||||||
if(BUILD_NCURSES)
|
if(BUILD_NCURSES)
|
||||||
set(optional_sources ${optional_sources} nc.cc)
|
set(optional_sources ${optional_sources} nc.cc)
|
||||||
endif(BUILD_NCURSES)
|
endif(BUILD_NCURSES)
|
||||||
|
@ -1,80 +0,0 @@
|
|||||||
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
||||||
* vim: ts=4 sw=4 noet ai cindent syntax=c
|
|
||||||
*
|
|
||||||
* Conky, a system monitor, based on torsmo
|
|
||||||
*
|
|
||||||
* Please see COPYING for details
|
|
||||||
*
|
|
||||||
* Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
|
|
||||||
* (see AUTHORS)
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include "defconfig.h"
|
|
||||||
|
|
||||||
#if defined(HAVE_FOPENCOOKIE)
|
|
||||||
#define COOKIE_LEN_T size_t
|
|
||||||
#define COOKIE_RET_T ssize_t
|
|
||||||
#else
|
|
||||||
#define COOKIE_LEN_T int
|
|
||||||
#define COOKIE_RET_T int
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_FOPENCOOKIE) || defined(HAVE_FUNOPEN)
|
|
||||||
static COOKIE_RET_T
|
|
||||||
conf_read(void *cookie, char *buf, COOKIE_LEN_T size)
|
|
||||||
{
|
|
||||||
static int col = 0, row = 0;
|
|
||||||
COOKIE_LEN_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;
|
|
||||||
}
|
|
||||||
#endif /* defined(HAVE_FOPENCOOKIE) || defined(HAVE_FUNOPEN) */
|
|
||||||
|
|
||||||
#if defined(HAVE_FOPENCOOKIE)
|
|
||||||
static cookie_io_functions_t conf_cookie;
|
|
||||||
FILE *conf_cookie_open(void)
|
|
||||||
{
|
|
||||||
conf_cookie.read = &conf_read;
|
|
||||||
conf_cookie.write = NULL;
|
|
||||||
conf_cookie.seek = NULL;
|
|
||||||
conf_cookie.close = NULL;
|
|
||||||
return fopencookie(NULL, "r", conf_cookie);
|
|
||||||
}
|
|
||||||
#elif defined(HAVE_FUNOPEN)
|
|
||||||
FILE *conf_cookie_open(void)
|
|
||||||
{
|
|
||||||
return funopen(NULL, &conf_read, NULL, NULL, NULL);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
FILE *conf_cookie_open(void) { return NULL; }
|
|
||||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||||||
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */
|
|
||||||
|
|
||||||
#ifndef _CONF_COOKIE_H
|
|
||||||
#define _CONF_COOKIE_H
|
|
||||||
|
|
||||||
FILE *conf_cookie_open(void);
|
|
||||||
|
|
||||||
#endif /* _CONF_COOKIE_H */
|
|
17
src/conky.cc
17
src/conky.cc
@ -126,7 +126,8 @@
|
|||||||
|
|
||||||
#ifdef BUILD_BUILTIN_CONFIG
|
#ifdef BUILD_BUILTIN_CONFIG
|
||||||
#include "defconfig.h"
|
#include "defconfig.h"
|
||||||
#include "conf_cookie.h"
|
|
||||||
|
namespace { const char builtin_config_magic[] = "==builtin=="; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef S_ISSOCK
|
#ifndef S_ISSOCK
|
||||||
@ -2687,11 +2688,6 @@ static void X11_create_window(void)
|
|||||||
|
|
||||||
static FILE *open_config_file(const char *f)
|
static FILE *open_config_file(const char *f)
|
||||||
{
|
{
|
||||||
#ifdef BUILD_BUILTIN_CONFIG
|
|
||||||
if (!strcmp(f, "==builtin==")) {
|
|
||||||
return conf_cookie_open();
|
|
||||||
} else
|
|
||||||
#endif /* BUILD_BUILTIN_CONFIG */
|
|
||||||
return fopen(f, "r");
|
return fopen(f, "r");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2956,7 +2952,7 @@ void set_current_config() {
|
|||||||
if (current_config.empty()) {
|
if (current_config.empty()) {
|
||||||
#define NOCFGFILEFOUND "no personal or system-wide config file found"
|
#define NOCFGFILEFOUND "no personal or system-wide config file found"
|
||||||
#ifdef BUILD_BUILTIN_CONFIG
|
#ifdef BUILD_BUILTIN_CONFIG
|
||||||
current_config = "==builtin==";
|
current_config = builtin_config_magic;
|
||||||
NORM_ERR(NOCFGFILEFOUND ", using builtin default");
|
NORM_ERR(NOCFGFILEFOUND ", using builtin default");
|
||||||
#else
|
#else
|
||||||
CRIT_ERR(NULL, NULL, NOCFGFILEFOUND);
|
CRIT_ERR(NULL, NULL, NOCFGFILEFOUND);
|
||||||
@ -3214,7 +3210,7 @@ int main(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
#ifdef BUILD_BUILTIN_CONFIG
|
#ifdef BUILD_BUILTIN_CONFIG
|
||||||
case 'C':
|
case 'C':
|
||||||
print_defconfig();
|
std::cout << defconfig;
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
#ifdef BUILD_X11
|
#ifdef BUILD_X11
|
||||||
@ -3235,7 +3231,10 @@ int main(int argc, char **argv)
|
|||||||
//////////// XXX ////////////////////////////////
|
//////////// XXX ////////////////////////////////
|
||||||
lua::state &l = *state;
|
lua::state &l = *state;
|
||||||
try {
|
try {
|
||||||
l.loadfile(argv[1]);
|
if(current_config == builtin_config_magic)
|
||||||
|
l.loadstring(defconfig);
|
||||||
|
else
|
||||||
|
l.loadfile(current_config.c_str());
|
||||||
l.call(0, 0);
|
l.call(0, 0);
|
||||||
conky::set_config_settings(l);
|
conky::set_config_settings(l);
|
||||||
std::cout << "config.alignment = " << text_alignment.get(l) << std::endl;
|
std::cout << "config.alignment = " << text_alignment.get(l) << std::endl;
|
||||||
|
14
text2c.sh
14
text2c.sh
@ -35,16 +35,6 @@
|
|||||||
outupper="`basename "$2" | tr '[a-z-.]' '[A-Z__]'`"
|
outupper="`basename "$2" | tr '[a-z-.]' '[A-Z__]'`"
|
||||||
|
|
||||||
(
|
(
|
||||||
printf "#ifndef __%s\n" "$outupper"
|
printf "const char %s[] = \n" $3
|
||||||
printf "#define __%s\n" "$outupper"
|
sed -e 's/["\]/\\&/g' -e 's/^/\t"/' -e 's/$/\\n"/' -e '$s/$/;/' $1
|
||||||
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
|
) > $2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user