1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 04:32:55 +00:00

append_file output method

This commit is contained in:
Nikolas Garofil 2009-02-12 22:45:18 +01:00
parent 3a11f1469f
commit 65bae86ca7

View File

@ -130,6 +130,7 @@ int top_cpu, top_mem, top_time;
#define TO_STDOUT 2
#define TO_STDERR 4
#define OVERWRITE_FILE 8
#define APPEND_FILE 16
static int output_methods;
static volatile int g_signal_pending;
/* Update interval */
@ -419,6 +420,7 @@ static int cpu_avg_samples, net_avg_samples;
/* filenames for output */
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
char *append_file = NULL; FILE *append_fpointer = NULL;
#ifdef X11
@ -5852,6 +5854,9 @@ static void draw_string(const char *s)
if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer != NULL) {
fprintf(overwrite_fpointer, "%s\n", s);
}
if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer != NULL) {
fprintf(append_fpointer, "%s\n", s);
}
memset(tmpstring1, 0, text_buffer_size);
memset(tmpstring2, 0, text_buffer_size);
strncpy(tmpstring1, s, text_buffer_size - 1);
@ -6436,6 +6441,10 @@ static void draw_stuff(void)
overwrite_fpointer = fopen(overwrite_file, "w");
if(overwrite_fpointer == NULL) ERR("Can't overwrite '%s' anymore", overwrite_file);
}
if(append_file != NULL) {
append_fpointer = fopen(append_file, "a");
if(append_fpointer == NULL) ERR("Can't append '%s' anymore", append_file);
}
#ifdef X11
selected_font = 0;
if (draw_shades && !draw_outline) {
@ -6484,6 +6493,7 @@ static void draw_stuff(void)
#endif
#endif /* X11 */
if(overwrite_fpointer != NULL) fclose(overwrite_fpointer);
if(append_fpointer != NULL) fclose(append_fpointer);
}
#ifdef X11
@ -6833,6 +6843,7 @@ static void main_loop(void)
#endif /* HAVE_XDAMAGE */
#endif /* X11 */
if(overwrite_file != NULL) free(overwrite_file);
if(append_file != NULL) free(append_file);
return; /* return from main_loop */
/* break; */
default:
@ -7167,6 +7178,15 @@ static _Bool overwrite_works(const char *path)
return 1;
}
//returns 1 if you can append or create the file at 'path'
static _Bool append_works(const char *path)
{
FILE *filepointer = fopen(path, "a");
if(filepointer == NULL) return 0;
fclose(filepointer);
return 1;
}
static void load_config_file(const char *f)
{
#define CONF_ERR ERR("%s: %d: config file error", f, line)
@ -7513,6 +7533,13 @@ static void load_config_file(const char *f)
output_methods |= OVERWRITE_FILE;
}else ERR("overwrite_file won't be able to create/overwrite '%s'", value);
}
CONF("append_file") {
if(append_file != NULL) free(append_file);
if(append_works(value) == 1) {
append_file = strdup(value);
output_methods |= APPEND_FILE;
}else ERR("append_file won't be able to create/append '%s'", value);
}
CONF("use_spacer") {
if (value) {
if (strcasecmp(value, "left") == EQUAL) {