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

Fix multiline stuff when build with X11 but output_to_x turned off.

This commit reverts 725a3ba43a and fixes 5967d28511
This commit is contained in:
Nikolas Garofil 2009-07-21 12:39:09 +02:00
parent e973de66cf
commit caf0731565

View File

@ -451,10 +451,10 @@ int check_contains(char *f, char *s)
return ret; return ret;
} }
#ifdef X11
#define SECRIT_MULTILINE_CHAR '\x02' #define SECRIT_MULTILINE_CHAR '\x02'
#ifdef X11
static inline int calc_text_width(const char *s, int l) static inline int calc_text_width(const char *s, int l)
{ {
if ((output_methods & TO_X) == 0) { if ((output_methods & TO_X) == 0) {
@ -3711,7 +3711,6 @@ static inline double get_barnum(char *buf)
return barnum; return barnum;
} }
#ifdef X11
/* substitutes all occurrences of '\n' with SECRIT_MULTILINE_CHAR, which allows /* substitutes all occurrences of '\n' with SECRIT_MULTILINE_CHAR, which allows
* multiline objects like $exec work with $align[rc] and friends * multiline objects like $exec work with $align[rc] and friends
*/ */
@ -3727,7 +3726,6 @@ void substitute_newlines(char *p, long l)
p++; p++;
} }
} }
#endif /* X11 */
static void generate_text_internal(char *p, int p_max_size, static void generate_text_internal(char *p, int p_max_size,
struct text_object root, struct information *cur) struct text_object root, struct information *cur)
@ -6020,11 +6018,9 @@ static void generate_text_internal(char *p, int p_max_size,
a = outptr - p; a = outptr - p;
} }
#endif /* HAVE_ICONV */ #endif /* HAVE_ICONV */
#ifdef X11
if (obj->type != OBJ_text) { if (obj->type != OBJ_text) {
substitute_newlines(p, a - 2); substitute_newlines(p, a - 2);
} }
#endif /* X11 */
p += a; p += a;
p_max_size -= a; p_max_size -= a;
} }
@ -6357,27 +6353,35 @@ static void draw_string(const char *s)
int i, i2, pos, width_of_s; int i, i2, pos, width_of_s;
int max = 0; int max = 0;
int added; int added;
char *s_with_newlines;
if (s[0] == '\0') { if (s[0] == '\0') {
return; return;
} }
width_of_s = get_string_width(s); width_of_s = get_string_width(s);
s_with_newlines = strdup(s);
for(i = 0; i < (int) strlen(s_with_newlines); i++) {
if(s_with_newlines[i] == SECRIT_MULTILINE_CHAR) {
s_with_newlines[i] = '\n';
}
}
if ((output_methods & TO_STDOUT) && draw_mode == FG) { if ((output_methods & TO_STDOUT) && draw_mode == FG) {
printf("%s\n", s); printf("%s\n", s_with_newlines);
if (extra_newline) fputc('\n', stdout); if (extra_newline) fputc('\n', stdout);
fflush(stdout); /* output immediately, don't buffer */ fflush(stdout); /* output immediately, don't buffer */
} }
if ((output_methods & TO_STDERR) && draw_mode == FG) { if ((output_methods & TO_STDERR) && draw_mode == FG) {
fprintf(stderr, "%s\n", s); fprintf(stderr, "%s\n", s_with_newlines);
fflush(stderr); /* output immediately, don't buffer */ fflush(stderr); /* output immediately, don't buffer */
} }
if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) { if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
fprintf(overwrite_fpointer, "%s\n", s); fprintf(overwrite_fpointer, "%s\n", s_with_newlines);
} }
if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) { if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
fprintf(append_fpointer, "%s\n", s); fprintf(append_fpointer, "%s\n", s_with_newlines);
} }
free(s_with_newlines);
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);