mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-27 20:44:56 +00:00
append_file output method
This commit is contained in:
parent
3a11f1469f
commit
65bae86ca7
27
src/conky.c
27
src/conky.c
@ -130,6 +130,7 @@ int top_cpu, top_mem, top_time;
|
|||||||
#define TO_STDOUT 2
|
#define TO_STDOUT 2
|
||||||
#define TO_STDERR 4
|
#define TO_STDERR 4
|
||||||
#define OVERWRITE_FILE 8
|
#define OVERWRITE_FILE 8
|
||||||
|
#define APPEND_FILE 16
|
||||||
static int output_methods;
|
static int output_methods;
|
||||||
static volatile int g_signal_pending;
|
static volatile int g_signal_pending;
|
||||||
/* Update interval */
|
/* Update interval */
|
||||||
@ -419,6 +420,7 @@ static int cpu_avg_samples, net_avg_samples;
|
|||||||
|
|
||||||
/* filenames for output */
|
/* filenames for output */
|
||||||
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
|
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
|
||||||
|
char *append_file = NULL; FILE *append_fpointer = NULL;
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
|
|
||||||
@ -5852,6 +5854,9 @@ static void draw_string(const char *s)
|
|||||||
if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer != NULL) {
|
if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer != NULL) {
|
||||||
fprintf(overwrite_fpointer, "%s\n", s);
|
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(tmpstring1, 0, text_buffer_size);
|
||||||
memset(tmpstring2, 0, text_buffer_size);
|
memset(tmpstring2, 0, text_buffer_size);
|
||||||
strncpy(tmpstring1, s, text_buffer_size - 1);
|
strncpy(tmpstring1, s, text_buffer_size - 1);
|
||||||
@ -6436,6 +6441,10 @@ static void draw_stuff(void)
|
|||||||
overwrite_fpointer = fopen(overwrite_file, "w");
|
overwrite_fpointer = fopen(overwrite_file, "w");
|
||||||
if(overwrite_fpointer == NULL) ERR("Can't overwrite '%s' anymore", overwrite_file);
|
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
|
#ifdef X11
|
||||||
selected_font = 0;
|
selected_font = 0;
|
||||||
if (draw_shades && !draw_outline) {
|
if (draw_shades && !draw_outline) {
|
||||||
@ -6484,6 +6493,7 @@ static void draw_stuff(void)
|
|||||||
#endif
|
#endif
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
if(overwrite_fpointer != NULL) fclose(overwrite_fpointer);
|
if(overwrite_fpointer != NULL) fclose(overwrite_fpointer);
|
||||||
|
if(append_fpointer != NULL) fclose(append_fpointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
@ -6833,6 +6843,7 @@ static void main_loop(void)
|
|||||||
#endif /* HAVE_XDAMAGE */
|
#endif /* HAVE_XDAMAGE */
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
if(overwrite_file != NULL) free(overwrite_file);
|
if(overwrite_file != NULL) free(overwrite_file);
|
||||||
|
if(append_file != NULL) free(append_file);
|
||||||
return; /* return from main_loop */
|
return; /* return from main_loop */
|
||||||
/* break; */
|
/* break; */
|
||||||
default:
|
default:
|
||||||
@ -7167,6 +7178,15 @@ static _Bool overwrite_works(const char *path)
|
|||||||
return 1;
|
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)
|
static void load_config_file(const char *f)
|
||||||
{
|
{
|
||||||
#define CONF_ERR ERR("%s: %d: config file error", f, line)
|
#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;
|
output_methods |= OVERWRITE_FILE;
|
||||||
}else ERR("overwrite_file won't be able to create/overwrite '%s'", value);
|
}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") {
|
CONF("use_spacer") {
|
||||||
if (value) {
|
if (value) {
|
||||||
if (strcasecmp(value, "left") == EQUAL) {
|
if (strcasecmp(value, "left") == EQUAL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user