From 263045888faed24f9a0be0b34d5105080cdd49a6 Mon Sep 17 00:00:00 2001 From: sabetts Date: Sun, 16 Sep 2001 10:28:01 +0000 Subject: (format_window_name): Use 2 character escape codes, like printf. Dependant code updated. --- src/list.c | 98 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 39 deletions(-) (limited to 'src/list.c') diff --git a/src/list.c b/src/list.c index 619c907..d6d2bca 100644 --- a/src/list.c +++ b/src/list.c @@ -610,60 +610,80 @@ print_window_information (rp_window *win) } /* format options - N - Window number - - - Window status (current window, last window, etc) - W - Window Name - w - Window res name - c - Window res class - n - X11 Window ID + %n - Window number + %s - Window status (current window, last window, etc) + %t - Window Name + %a - application name + %c - resource class + %i - X11 Window ID */ static void format_window_name (char *fmt, rp_window *win, rp_window *other_win, struct sbuf *buffer) { + int esc = 0; char dbuf[10]; for(; *fmt; fmt++) { - switch (*fmt) + if (*fmt == '%' && !esc) { - case 'N': - snprintf (dbuf, 10, "%d", win->number); - sbuf_concat (buffer, dbuf); - break; - - case '-': - if (win == current_window()) - sbuf_concat (buffer, "*"); - else if (win == other_win) - sbuf_concat (buffer, "+"); - else - sbuf_concat (buffer, "-"); - break; - - case 'W': - sbuf_concat (buffer, window_name (win)); - break; - - case 'w': - sbuf_concat (buffer, win->res_name); - break; - - case 'c': - sbuf_concat (buffer, win->res_class); - break; - - case 'n': - snprintf (dbuf, 9, "%ld", (unsigned long)win->w); - sbuf_concat (buffer, dbuf); - break; + esc = 1; + continue; + } - default: + if (esc) + { + switch (*fmt) + { + case 'n': + snprintf (dbuf, 10, "%d", win->number); + sbuf_concat (buffer, dbuf); + break; + + case 's': + if (win == current_window()) + sbuf_concat (buffer, "*"); + else if (win == other_win) + sbuf_concat (buffer, "+"); + else + sbuf_concat (buffer, "-"); + break; + + case 't': + sbuf_concat (buffer, window_name (win)); + break; + + case 'a': + sbuf_concat (buffer, win->res_name); + break; + + case 'c': + sbuf_concat (buffer, win->res_class); + break; + + case 'i': + snprintf (dbuf, 9, "%ld", (unsigned long)win->w); + sbuf_concat (buffer, dbuf); + break; + + case '%': + dbuf[0] = '%'; + dbuf[1] = 0; + sbuf_concat (buffer, dbuf); + break; + } + + /* Reset the 'escape' state. */ + esc = 0; + } + else + { + /* Insert the character. */ dbuf[0] = *fmt; dbuf[1] = 0; sbuf_concat (buffer, dbuf); - break; } } } -- cgit v1.2.3