chiark / gitweb /
xscsize.c: Move reporting variables to a separate function.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 21 Apr 2016 16:24:30 +0000 (17:24 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 21 Apr 2016 16:24:30 +0000 (17:24 +0100)
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.

xscsize.c

index 0cd4cbd1996e50c1ac021933c4f5b47edfe2a16f..46d58f71e509fc06d2372962c16e918b5ccba552 100644 (file)
--- 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 --- */