xscsize.c: Move reporting variables to a separate function.
[xtoys] / xscsize.c
index 0cd4cbd..46d58f7 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 --- */