#include <mLib/mdwopt.h>
#include <mLib/quis.h>
+/*----- Static variables --------------------------------------------------*/
+
+static unsigned int flags = 0;
+#define F_SH 1u
+#define F_CSH 2u
+#define F_SHELL 3u
+#define F_EXPORT 4u
+
/*----- Main code ---------------------------------------------------------*/
static void version(FILE *fp)
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;
unsigned long wd, ht;
int sc;
-#define f_sh 1u
-#define f_csh 2u
-#define f_shell 3u
-#define f_export 4u
-#define f_bogus 8u
+#define f_bogus 1u
/* --- Parse command line options --- */
case 'u': usage(stdout); exit(0); break;
case 'v': version(stdout); exit(0); break;
case 'd': display = optarg; break;
- case 'b': f |= f_sh; break;
- case 'c': f |= f_csh; break;
- case 'x': f |= f_export; break;
+ case 'b': flags |= F_SH; break;
+ case 'c': flags |= F_CSH; break;
+ case 'x': flags |= F_EXPORT; break;
default: f |= f_bogus; break;
}
}
* Otherwise assume it's Bourne. This seems to work in practice.
*/
- if (!(f & f_shell)) {
+ if (!(flags & F_SHELL)) {
s = getenv("SHELL");
- if (!s)
- f |= f_sh;
- if (strstr(s, "csh"))
- f |= f_csh;
- else
- f |= f_sh;
+ if (!s) flags |= F_SH;
+ if (strstr(s, "csh")) flags |= F_CSH;
+ else flags |= F_SH;
}
- if ((f & f_sh) && (f & f_csh)) {
+ if ((flags & F_SH) && (flags & F_CSH)) {
fprintf(stderr, "xscsize: make your mind up about your shell type\n");
exit(EXIT_FAILURE);
}
/* --- 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 --- */