diff options
author | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2013-11-17 18:38:27 +0100 |
---|---|---|
committer | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2013-11-17 18:38:27 +0100 |
commit | 2335261cdf8c574331b676c74e9d5299faa82624 (patch) | |
tree | fe725731d9afaf99b0543c69d809d0ddea10abb0 | |
parent | 797796e2d9d4c708668ed05359695c53f8448386 (diff) | |
download | ratpoison-2335261cdf8c574331b676c74e9d5299faa82624.zip |
Use sbuf_chop in fdump() to trim trailing comma.
* those commas shouldn't have been there in the first place. If your
scripts rely on this, watch out!
* code simplified and variables better named, while here.
-rw-r--r-- | src/actions.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/actions.c b/src/actions.c index 2369067..5f6c013 100644 --- a/src/actions.c +++ b/src/actions.c @@ -4868,25 +4868,23 @@ cmd_fselect (int interactive, struct cmdarg **args) static char * fdump (rp_screen *screen) { - struct sbuf *s; - char *tmp; + struct sbuf *dump; rp_frame *cur; - s = sbuf_new (0); + dump = sbuf_new (0); - /* FIXME: Oooh, gross! there's a trailing comma, yuk! */ list_for_each_entry (cur, &(screen->frames), node) { - char *t; + char *frameset; - t = frame_dump (cur, screen); - sbuf_concat (s, t); - sbuf_concat (s, ","); - free (t); + frameset = frame_dump (cur, screen); + sbuf_concat (dump, frameset); + sbuf_concat (dump, ","); + free (frameset); } + sbuf_chop (dump); - tmp = sbuf_free_struct (s); - return tmp; + return sbuf_free_struct (dump); } cmdret * @@ -5490,7 +5488,6 @@ cmd_sfdump (int interactively UNUSED, struct cmdarg **args UNUSED) screens[i].xine_screen_num : screens[i].screen_num); - /* FIXME: Oooh, gross! there's a trailing comma, yuk! */ list_for_each_entry (cur, &(screens[i].frames), node) { char *frameset; @@ -5500,6 +5497,7 @@ cmd_sfdump (int interactively UNUSED, struct cmdarg **args UNUSED) sbuf_concat (dump, screen_suffix); free (frameset); } + sbuf_chop (dump); } ret = cmdret_new (RET_SUCCESS, "%s", sbuf_get (dump)); sbuf_free (dump); @@ -5586,14 +5584,14 @@ cmd_sdump (int interactive UNUSED, struct cmdarg **args UNUSED) int i; s = sbuf_new (0); - for (i=0; i<num_screens; ++i) + for (i = 0; i < num_screens; ++i) { tmp = screen_dump (&screens[i]); sbuf_concat (s, tmp); - if (i + 1 != num_screens) /* No trailing comma. */ - sbuf_concat (s, ","); + sbuf_concat (s, ","); free (tmp); } + sbuf_chop (s); ret = cmdret_new (RET_SUCCESS, "%s", sbuf_get (s)); sbuf_free (s); |