2002-04-24 Emilio Lopes > * list.c (format_window_name): escape sequences now accept an argument. Use `trunc' to truncate the window title to arg characters. (trunc): new function. diff -ur ratpoison-1.1.1/doc/ratpoison.1 ratpoison-1.1.1-ecl/doc/ratpoison.1 --- ratpoison-1.1.1/doc/ratpoison.1 Sat Jul 6 23:20:41 2002 +++ ratpoison-1.1.1-ecl/doc/ratpoison.1 Mon Jul 15 09:09:26 2002 @@ -234,7 +234,11 @@ Window status (current window, last window, etc) `%t' -Window Name +Window Name. If an integer follows the `%', it specifies the number of +characters of the window name to show; zero means the whole name. A +negative integer means start counting characters from the end of the +window name, i.e. %-20t specifies the last 20 characters of the window +name. `%a' Application Name diff -ur ratpoison-1.1.1/doc/ratpoison.texi ratpoison-1.1.1-ecl/doc/ratpoison.texi --- ratpoison-1.1.1/doc/ratpoison.texi Sat Jul 6 23:20:04 2002 +++ ratpoison-1.1.1-ecl/doc/ratpoison.texi Mon Jul 15 09:09:26 2002 @@ -480,7 +480,11 @@ @item %s Window status (current window, last window, etc) @item %t -Window Name +Window Name. If an integer follows the `%', it specifies the number of +characters of the window name to show; zero means the whole name. A +negative integer means start counting characters from the end of the +window name, i.e. %-20t specifies the last 20 characters of the window +name. @item %a Application Name @item %c diff -ur ratpoison-1.1.1/src/list.c ratpoison-1.1.1-ecl/src/list.c --- ratpoison-1.1.1/src/list.c Sun Jan 27 00:58:50 2002 +++ ratpoison-1.1.1-ecl/src/list.c Mon Jul 15 09:09:41 2002 @@ -639,14 +639,17 @@ struct sbuf *buffer) { int esc = 0; + int arg = 0; char dbuf[10]; + char *tmpstr; for(; *fmt; fmt++) { if (*fmt == '%' && !esc) { esc = 1; - continue; + fmt++; + arg = (int)strtol(fmt, &fmt, 10); } if (esc) @@ -668,7 +671,17 @@ break; case 't': - sbuf_concat (buffer, window_name (win)); + if (arg) + { + tmpstr = xmalloc (abs(arg) + 1); + trunc (tmpstr, window_name (win), arg); + sbuf_concat (buffer, tmpstr); + free (tmpstr); + } + else + { + sbuf_concat (buffer, window_name (win)); + } break; case 'a': @@ -767,3 +780,25 @@ sbuf_copy (buffer, MESSAGE_NO_MANAGED_WINDOWS); } } + + +/* Copy SRC to DEST truncated to SIZE chars. If SIZE ist negative + start counting from the end of SRC. */ +void trunc (char* dest, const char *src, int size) +{ + if (abs (size) >= strlen (src)) + { + strcpy(dest, src); + return; + } + + if (size >= 0) + { + strncpy (dest, src, size); + dest[size] = '\0'; + } + else if (size < 0) + { + strcpy(dest, src + strlen (src) + size); + } +} diff -ur ratpoison-1.1.1/src/list.h ratpoison-1.1.1-ecl/src/list.h --- ratpoison-1.1.1/src/list.h Thu Sep 20 09:32:11 2001 +++ ratpoison-1.1.1-ecl/src/list.h Mon Jul 15 09:09:41 2002 @@ -38,6 +38,7 @@ void goto_window (rp_window *win); void set_current_window (rp_window *win); void update_window_gravity (rp_window *win); +void trunc (char* dest, const char *src, int size); char *window_name (rp_window *win); #if 0