1: /*
   2:  * Copyright 1985, Cognition Inc.
   3:  * This software is not supported by Cognition Inc. and is
   4:  * provided "as is".  To keep the X revolution growing, please forward
   5:  * enhancements and bug fixes to anyone who is interested.
   6:  */
   7: #ifndef lint
   8: static char *rcsid_xshell_c = "$Header: xutils.c,v 10.3 86/02/01 16:19:44 tony Rel $";
   9: #endif
  10: 
  11: #include <stdio.h>
  12: #include <strings.h>
  13: #include <ctype.h>
  14: 
  15: /****************************************************************************
  16:  * XParse_Window_Geometry - parses a standard X dimension string like
  17:  *
  18:  *			=WIDTHxHEIGHT+XOFF+YOFF
  19:  *			=WIDTHxHEIGHT-XOFF-YOFF
  20:  *
  21:  * and returns 1 if everything goes okay, else 0 so that you can use the
  22:  * routine in an if statement.  Note that it will not touch the integer input
  23:  * arguments but does mung the geometry.
  24:  */
  25: 
  26: 
  27: #define bomb(msg) return(0)
  28: 
  29: int XParse_Window_Geometry (geometry, widthp, heightp,
  30:                 xsignp, xoffp, ysignp, yoffp)
  31:     char *geometry;
  32:     int *widthp, *heightp, *xsignp, *xoffp, *ysignp, *yoffp;
  33: {
  34:     register char *cp;
  35:     int xoff, yoff, xsign, ysign, width, height;
  36: 
  37:     xoff = yoff = -1;   /* put it in the lower right hand corner */
  38:     xsign = ysign = 0;  /* so that we can see if it is set or not */
  39:     width = height = -1;    /* ditto */
  40: 
  41:     if (geometry != (char *) NULL) {/* normal =XxY+w+h or =XxY-w-h etc. */
  42:         if (*geometry == '=') geometry++;   /* skip = sign */
  43:         switch (*geometry) {    /* what is the first char we see? */
  44:         case '+':       /* it is the positive XOFF */
  45:             xsign = 1;
  46:             goto get_xoff;
  47:         case '-':       /* it is the negative XOFF */
  48:             xsign = -1;
  49:             goto get_xoff;
  50:         case 'x':       /* it is the HEIGHT */
  51:             goto get_height;
  52:         default:        /* it is the WIDTH */
  53:             break;
  54:         } /*end switch*/
  55:         cp = index (geometry, 'x');         /* find the x */
  56:         if (cp == (char *) NULL) bomb ("width");
  57:         *cp = '\0';
  58:         width = atoi (geometry);
  59:         geometry = cp;      /* skip to WIDTH */
  60:     get_height:
  61:         for (cp = ++geometry; isdigit (*cp); cp++) ;
  62:         switch (*cp) {
  63:         case '\0':
  64:             height = atoi (geometry);
  65:             goto done;
  66:         case '+':
  67:             xsign = 1;
  68:             break;
  69:         case '-':
  70:             xsign = -1;
  71:             break;
  72:         default:
  73:             bomb ("height");
  74:         } /*end switch*/
  75:         *cp = '\0';
  76:         height = atoi (geometry);
  77:         geometry = cp;
  78:     get_xoff:
  79:         for (cp = ++geometry; isdigit (*cp); cp++) ;
  80:         switch (*cp) {
  81:         case '\0':
  82:             xoff = atoi (geometry);
  83:             goto done;
  84:         case '+':
  85:             ysign = 1;
  86:             break;
  87:         case '-':
  88:             ysign = -1;
  89:             break;
  90:         default:
  91:             bomb ("X position");
  92:         } /*end switch*/
  93:         *cp = '\0';
  94:         xoff = atoi (geometry);
  95:         geometry = cp;
  96:         for (cp = ++geometry; isdigit (*cp); cp++) ;
  97:         if (*cp != '\0') bomb ("Y position");
  98:         yoff = atoi (geometry);
  99:     } /*end if*/
 100: 
 101:     done:
 102:     if (width != -1) *widthp = width;
 103:     if (height != -1) *heightp = height;
 104: 
 105:     if (xsign != 0) *xsignp = xsign;
 106:     if (ysign != 0) *ysignp = ysign;
 107: 
 108:     if (xoff != -1) *xoffp = xoff;
 109:     if (yoff != -1) *yoffp = yoff;
 110: 
 111:     return (1);
 112: 
 113: } /*end XParse_Window_Geometry*/

Defined functions

XParse_Window_Geometry defined in line 29; used 2 times

Defined variables

rcsid_xshell_c defined in line 8; never used

Defined macros

bomb defined in line 27; used 4 times
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1150
Valid CSS Valid XHTML 1.0 Strict