1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <fli.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int fli_parse_geometry (char const *geom, int *xp, int *yp, int *wp, int *hp)
{
int
x, y, w, h; /* parsed width/height/x/y */
char
xsign [1],
ysign [1];
/* match 30x100+123+456 or - instead of + */
if (sscanf (geom, "%dx%d%1[-+]%d%1[-+]%d",
&w, &h, xsign, &x, ysign, &y) == 6)
{
if (xsign [0] == '-')
x = -x;
if (ysign [0] == '-')
y = -y;
*wp = w;
*hp = h;
*xp = x;
*yp = y;
return (FLI_WHXY_PARSED);
}
/* match 30x100 */
if (sscanf (geom, "%dx%d", &w, &h) == 2)
{
*wp = w;
*hp = h;
return (FLI_WH_PARSED);
}
/* match +400+600 or - instead of + */
if (sscanf (geom, "%1[-+]%d%1[-+]%d", xsign, &x, ysign, &y) == 4)
{
if (xsign [0] == '-')
x = -x;
if (ysign [0] == '-')
y = -y;
*xp = x;
*yp = y;
return (FLI_XY_PARSED);
}
/* all failed */
return (0);
}
|