From: Mark Wooding Date: Thu, 21 Apr 2016 16:24:30 +0000 (+0100) Subject: xscsize.c: Move reporting variables to a separate function. X-Git-Tag: 1.6.0~3 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/xtoys/commitdiff_plain/e5c4fa9dfaf1e867d13c5926c677e32eb4cb8e6b xscsize.c: Move reporting variables to a separate function. There are going to me more of them, and we won't know in advance how many, so it'll be handy to have the output formatting in just one place. This changes the detailed format of the output, but not in a way that any actual shells will care about. Specifically, each variable is now output on a separate line; and for Bourne shells, the `export' command is on the same line. --- diff --git a/xscsize.c b/xscsize.c index 0cd4cbd..46d58f7 100644 --- a/xscsize.c +++ b/xscsize.c @@ -74,6 +74,23 @@ Options:\n\ fp); } +static void print_var(const char *name, unsigned long value) +{ + if (index >= 0) { + dstr_putf(&d, "XSCR%d_%s", index, name); + name = d.buf; + } + if (flags & F_SH) { + printf("%s=%lu", name, value); + if (flags & F_EXPORT) printf("; export %s", name); + } else if (flags & F_CSH) { + if (flags & F_EXPORT) printf("setenv %s %lu", name, value); + else printf("set %s=%lu", name, value); + } + putchar('\n'); + dstr_destroy(&d); +} + int main(int argc, char *argv[]) { Display *dpy; @@ -150,18 +167,8 @@ int main(int argc, char *argv[]) /* --- Do the output thing --- */ - if (f & f_sh) { - printf("XWIDTH=%lu XHEIGHT=%lu", wd, ht); - if (f & f_export) - printf("; export XWIDTH XHEIGHT"); - } - if (f & f_csh) { - if (f & f_export) - printf("setenv XWIDTH %lu; setenv XHEIGHT %lu", wd, ht); - else - printf("set XWIDTH=%lu XHEIGHT=%lu", wd, ht); - } - putchar('\n'); + print_var("XWIDTH", wd); + print_var("XHEIGHT", ht); /* --- Done --- */