1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

Remove SECRIT_MULTILINE_CHAR hack

Noone knows what it was supposed to do and removing it seems to fix sf.net #3411610 (and probably
a few others). If it turns out it was doing something useful, we will try to reintroduce it
without breaking other things.
This commit is contained in:
Pavel Labath 2011-10-10 20:51:35 +02:00
parent ddaa48a29e
commit f6b38df642
4 changed files with 9 additions and 74 deletions

View File

@ -573,8 +573,6 @@ int get_total_updates(void)
return total_updates; return total_updates;
} }
#define SECRIT_MULTILINE_CHAR '\x02'
int calc_text_width(const char *s) int calc_text_width(const char *s)
{ {
size_t slen = strlen(s); size_t slen = strlen(s);
@ -799,23 +797,6 @@ void parse_conky_vars(struct text_object *root, const char *txt,
generate_text_internal(p, p_max_size, *root); generate_text_internal(p, p_max_size, *root);
} }
/* substitutes all occurrences of '\n' with SECRIT_MULTILINE_CHAR, which allows
* multiline objects like $exec work with $align[rc] and friends
*/
void substitute_newlines(char *p, long l)
{
char *s = p;
if (l < 0) return;
while (p && *p && p < s + l) {
if (*p == '\n') {
/* only substitute if it's not the last newline */
*p = SECRIT_MULTILINE_CHAR;
}
p++;
}
}
/* IFBLOCK jumping algorithm /* IFBLOCK jumping algorithm
* *
* This is easier as it looks like: * This is easier as it looks like:
@ -877,8 +858,6 @@ void generate_text_internal(char *p, int p_max_size, struct text_object root)
#ifdef BUILD_ICONV #ifdef BUILD_ICONV
iconv_convert(&a, buff_in, p, p_max_size); iconv_convert(&a, buff_in, p, p_max_size);
#endif /* BUILD_ICONV */ #endif /* BUILD_ICONV */
if (!obj->verbatim_output)
substitute_newlines(p, a - 2);
p += a; p += a;
p_max_size -= a; p_max_size -= a;
(*p) = 0; (*p) = 0;
@ -1014,9 +993,6 @@ static int get_string_width_special(char *s, int special_index)
} }
idx++; idx++;
current = current->next; current = current->next;
} else if (*p == SECRIT_MULTILINE_CHAR) {
*p = 0;
break;
} else { } else {
p++; p++;
} }
@ -1133,8 +1109,6 @@ static long current_color;
static int text_size_updater(char *s, int special_index) static int text_size_updater(char *s, int special_index)
{ {
int w = 0; int w = 0;
int lw;
int contain_SECRIT_MULTILINE_CHAR = 0;
char *p; char *p;
special_t *current = specials; special_t *current = specials;
@ -1187,24 +1161,12 @@ static int text_size_updater(char *s, int special_index)
special_index++; special_index++;
current = current->next; current = current->next;
s = p + 1; s = p + 1;
} else if (*p == SECRIT_MULTILINE_CHAR) {
contain_SECRIT_MULTILINE_CHAR = 1;
*p = '\0';
lw = get_string_width(s);
*p = SECRIT_MULTILINE_CHAR;
s = p + 1;
w = lw > w ? lw : w;
text_height += last_font_height;
} }
p++; p++;
} }
/* Check also last substring if string contains SECRIT_MULTILINE_CHAR */
if (contain_SECRIT_MULTILINE_CHAR) {
lw = get_string_width(s);
w = lw > w ? lw : w;
} else {
w += get_string_width(s); w += get_string_width(s);
}
if (w > text_width) { if (w > text_width) {
text_width = w; text_width = w;
} }
@ -1260,50 +1222,42 @@ 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 (out_to_stdout.get(*state) && draw_mode == FG) { if (out_to_stdout.get(*state) && draw_mode == FG) {
printf("%s\n", s_with_newlines); printf("%s\n", s);
if (extra_newline.get(*state)) fputc('\n', stdout); if (extra_newline.get(*state)) fputc('\n', stdout);
fflush(stdout); /* output immediately, don't buffer */ fflush(stdout); /* output immediately, don't buffer */
} }
if (out_to_stderr.get(*state) && draw_mode == FG) { if (out_to_stderr.get(*state) && draw_mode == FG) {
fprintf(stderr, "%s\n", s_with_newlines); fprintf(stderr, "%s\n", s);
fflush(stderr); /* output immediately, don't buffer */ fflush(stderr); /* output immediately, don't buffer */
} }
if (draw_mode == FG && overwrite_fpointer) { if (draw_mode == FG && overwrite_fpointer) {
fprintf(overwrite_fpointer, "%s\n", s_with_newlines); fprintf(overwrite_fpointer, "%s\n", s);
} }
if (draw_mode == FG && append_fpointer) { if (draw_mode == FG && append_fpointer) {
fprintf(append_fpointer, "%s\n", s_with_newlines); fprintf(append_fpointer, "%s\n", s);
} }
#ifdef BUILD_NCURSES #ifdef BUILD_NCURSES
if (out_to_ncurses.get(*state) && draw_mode == FG) { if (out_to_ncurses.get(*state) && draw_mode == FG) {
printw("%s", s_with_newlines); printw("%s", s);
} }
#endif #endif
#ifdef BUILD_HTTP #ifdef BUILD_HTTP
if (out_to_http.get(*state) && draw_mode == FG) { if (out_to_http.get(*state) && draw_mode == FG) {
std::string::size_type origlen = webpage.length(); std::string::size_type origlen = webpage.length();
webpage.append(s_with_newlines); webpage.append(s);
webpage = string_replace_all(webpage, "\n", "<br />", origlen); webpage = string_replace_all(webpage, "\n", "<br />", origlen);
webpage = string_replace_all(webpage, " ", "&nbsp;&nbsp;", origlen); webpage = string_replace_all(webpage, " ", "&nbsp;&nbsp;", origlen);
webpage = string_replace_all(webpage, "&nbsp; ", "&nbsp;&nbsp;", origlen); webpage = string_replace_all(webpage, "&nbsp; ", "&nbsp;&nbsp;", origlen);
webpage.append("<br />"); webpage.append("<br />");
} }
#endif #endif
free(s_with_newlines);
int tbs = text_buffer_size.get(*state); int tbs = text_buffer_size.get(*state);
memset(tmpstring1, 0, tbs); memset(tmpstring1, 0, tbs);
memset(tmpstring2, 0, tbs); memset(tmpstring2, 0, tbs);
@ -1395,7 +1349,6 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
int cur_y_add = 0; int cur_y_add = 0;
int mw = maximum_width.get(*state); int mw = maximum_width.get(*state);
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
char *recurse = 0;
char *p = s; char *p = s;
int last_special_needed = -1; int last_special_needed = -1;
int orig_special_index = special_index; int orig_special_index = special_index;
@ -1409,12 +1362,6 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
while (*p) { while (*p) {
if (*p == SECRIT_MULTILINE_CHAR) {
/* special newline marker for multiline objects */
recurse = p + 1;
*p = '\0';
break;
}
if (*p == SPECIAL_CHAR || last_special_applied > -1) { if (*p == SPECIAL_CHAR || last_special_applied > -1) {
#ifdef BUILD_X11 #ifdef BUILD_X11
int w = 0; int w = 0;
@ -1843,10 +1790,6 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
if (out_to_x.get(*state)) if (out_to_x.get(*state))
cur_y += font_descent(); cur_y += font_descent();
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
if (recurse && *recurse) {
special_index = draw_each_line_inner(recurse, special_index, last_special_needed);
*(recurse - 1) = SECRIT_MULTILINE_CHAR;
}
return special_index; return special_index;
} }

View File

@ -740,7 +740,6 @@ struct text_object *construct_text_object(char *s, const char *arg, long
END OBJ(execp, 0) END OBJ(execp, 0)
scan_exec_arg(obj, arg); scan_exec_arg(obj, arg);
obj->parse = true; obj->parse = true;
obj->verbatim_output = true;
obj->thread = false; obj->thread = false;
obj->callbacks.print = &print_exec; obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_exec; obj->callbacks.free = &free_exec;
@ -781,7 +780,6 @@ struct text_object *construct_text_object(char *s, const char *arg, long
END OBJ_ARG(execpi, 0, "execpi needs arguments") END OBJ_ARG(execpi, 0, "execpi needs arguments")
scan_execi_arg(obj, arg); scan_execi_arg(obj, arg);
obj->parse = true; obj->parse = true;
obj->verbatim_output = true;
obj->thread = false; obj->thread = false;
obj->callbacks.print = &print_execi; obj->callbacks.print = &print_execi;
obj->callbacks.free = &free_execi; obj->callbacks.free = &free_execi;
@ -794,7 +792,6 @@ struct text_object *construct_text_object(char *s, const char *arg, long
END OBJ_ARG(texecpi, 0, "texecpi needs arguments") END OBJ_ARG(texecpi, 0, "texecpi needs arguments")
scan_execi_arg(obj, arg); scan_execi_arg(obj, arg);
obj->parse = true; obj->parse = true;
obj->verbatim_output = true;
obj->thread = true; obj->thread = true;
obj->callbacks.print = &print_execi; obj->callbacks.print = &print_execi;
obj->callbacks.free = &free_execi; obj->callbacks.free = &free_execi;
@ -1620,7 +1617,6 @@ struct text_object *construct_text_object(char *s, const char *arg, long
obj->callbacks.free = &gen_free_opaque; obj->callbacks.free = &gen_free_opaque;
END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]") END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
obj->data.s = strndup(arg, text_buffer_size.get(*state)); obj->data.s = strndup(arg, text_buffer_size.get(*state));
obj->verbatim_output = true;
obj->callbacks.print = &print_lua_parse; obj->callbacks.print = &print_lua_parse;
obj->callbacks.free = &gen_free_opaque; obj->callbacks.free = &gen_free_opaque;
END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]") END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")

View File

@ -197,7 +197,6 @@ int ifblock_stack_empty(void **opaque)
void obj_be_plain_text(struct text_object *obj, const char *text) void obj_be_plain_text(struct text_object *obj, const char *text)
{ {
obj->data.s = strdup(text); obj->data.s = strdup(text);
obj->verbatim_output = 1;
memset(&obj->callbacks, 0, sizeof(obj->callbacks)); memset(&obj->callbacks, 0, sizeof(obj->callbacks));
obj->callbacks.print = &gen_print_obj_data_s; obj->callbacks.print = &gen_print_obj_data_s;

View File

@ -100,9 +100,6 @@ struct text_object {
long l; /* some long integer */ long l; /* some long integer */
} data; } data;
/* if non-zero, no substitute_newlines() is applied to object's output */
char verbatim_output;
void *special_data; void *special_data;
long line; long line;
struct obj_cb callbacks; struct obj_cb callbacks;