X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/blobdiff_plain/c4efa11c1a060884e0d2f3c61a769d1e51396ae6..bce8c6eed8bd2fb91fc505a26483e449aefac819:/xscsize.c diff --git a/xscsize.c b/xscsize.c index bae703d..dcdbbd1 100644 --- a/xscsize.c +++ b/xscsize.c @@ -1,13 +1,11 @@ /* -*-c-*- * - * $Id: xscsize.c,v 1.3 1998/12/11 09:50:05 mdw Exp $ - * * Return X display size to shell script * * (c) 1998 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the Edgeware X tools collection. * @@ -15,32 +13,17 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * X tools is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with X tools; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: xscsize.c,v $ - * Revision 1.3 1998/12/11 09:50:05 mdw - * Minor modifications to work with mLib and mgLib. - * - * Revision 1.2 1998/11/21 22:30:22 mdw - * Support GNU-style long options throughout, and introduce proper help - * text to all programs. Update manual pages to match. - * - * Revision 1.1 1998/11/16 23:00:49 mdw - * Initial versions. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -55,27 +38,47 @@ /*----- Main code ---------------------------------------------------------*/ static void version(FILE *fp) -{ - fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS); -} + { fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS); } static void usage(FILE *fp) + { fprintf(fp, "Usage: %s [-bcx] [-d display]\n", QUIS); } + +static void help(FILE *fp) { - fprintf(fp, "Usage: %s [-bcx] [-d display]\n", QUIS); + version(fp); + fputc('\n', fp); + usage(stdout); + fputs("\n" +"Reads the size of the X root window and outputs it in a form suitable\n" +"for use as a shell assignment statement, defining variables XWIDTH and\n" +"XHEIGHT.\n" +"\n" +"Options:\n" +"\n" +"-h, --help Display this help text\n" +"-u, --usage Display a short usage summary\n" +"-v, --version Display the program's version number\n" +"\n" +"-d, --display=DISPLAY Choose X display to connect to\n" +"-b, --bourne-shell Output text suitable for a Bourne shell\n" +"-c, --c-shell Output text suitable for a C shell\n" +"-x, --export Export the variables into the environment\n", + fp); } int main(int argc, char *argv[]) { + Display *dpy; + const char *s; const char *display = 0; unsigned f = 0; unsigned long wd, ht; + int sc; - enum { - f_sh = 1, - f_csh = 2, - f_shell = 3, - f_export = 4 - }; +#define f_sh 1u +#define f_csh 2u +#define f_shell 3u +#define f_export 4u /* --- Parse command line options --- */ @@ -83,14 +86,14 @@ int main(int argc, char *argv[]) for (;;) { static struct option opt[] = { - { "help", 0, 0, 'h' }, - { "usage", 0, 0, 'u' }, - { "version", 0, 0, 'v' }, - { "display", required_argument, 0, 'd' }, - { "bourne-shell", 0, 0, 'b' }, - { "c-shell", 0, 0, 'c' }, - { "export", 0, 0, 'x' }, - { 0, 0, 0, 0 } + { "help", 0, 0, 'h' }, + { "usage", 0, 0, 'u' }, + { "version", 0, 0, 'v' }, + { "display", OPTF_ARGREQ, 0, 'd' }, + { "bourne-shell", 0, 0, 'b' }, + { "c-shell", 0, 0, 'c' }, + { "export", 0, 0, 'x' }, + { 0, 0, 0, 0 } }; int i = getopt_long(argc, argv, "huv d:bcx", opt, 0); @@ -98,26 +101,7 @@ int main(int argc, char *argv[]) break; switch (i) { case 'h': - version(stdout); - fputs("\n", stdout); - usage(stdout); - fputs( -"\n" -"Reads the size of the X root window and outputs it in a form suitable\n" -"for use as a shell assignment statement, defining variables XWIDTH and\n" -"XHEIGHT.\n" -"\n" -"Options:\n" -"\n" -"-h, --help Display this help text\n" -"-u, --usage Display a short usage summary\n" -"-v, --version Display the program's version number\n" -"\n" -"-d, --display=DISPLAY Choose X display to connect to\n" -"-b, --bourne-shell Output text suitable for a Bourne shell\n" -"-c, --c-shell Output text suitable for a C shell\n" -"-x, --export Export the variables into the environment\n", - stdout); + help(stdout); exit(0); break; case 'u': @@ -128,7 +112,7 @@ int main(int argc, char *argv[]) version(stdout); exit(0); break; - + case 'd': display = optarg; break; @@ -155,7 +139,7 @@ int main(int argc, char *argv[]) */ if (!(f & f_shell)) { - const char *s = getenv("SHELL"); + s = getenv("SHELL"); if (!s) f |= f_sh; if (strstr(s, "csh")) @@ -171,18 +155,15 @@ int main(int argc, char *argv[]) /* --- Get the important information --- */ - { - Display *dpy = XOpenDisplay(display); - int sc; - if (!dpy) { - fprintf(stderr, "xscsize: couldn't open display\n"); - exit(EXIT_FAILURE); - } - sc = DefaultScreen(dpy); - wd = DisplayWidth(dpy, sc); - ht = DisplayHeight(dpy, sc); - XCloseDisplay(dpy); + dpy = XOpenDisplay(display); + if (!dpy) { + fprintf(stderr, "xscsize: couldn't open display\n"); + exit(EXIT_FAILURE); } + sc = DefaultScreen(dpy); + wd = DisplayWidth(dpy, sc); + ht = DisplayHeight(dpy, sc); + XCloseDisplay(dpy); /* --- Do the output thing --- */