diff options
author | Thomas White <taw@physics.org> | 2018-11-09 20:46:31 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-11-09 20:46:31 +0100 |
commit | d669499b143316318f12c091173196c85e57527f (patch) | |
tree | 93b7bdc0269b1294cb7b0efb8d6c1fcdf38decff /src/utils.c | |
parent | 1869d2648f4461f44350bf5014368117bd1df492 (diff) |
Set furniture values in SS editor
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index 277b3f1..b41f344 100644 --- a/src/utils.c +++ b/src/utils.c @@ -81,3 +81,57 @@ int parse_tuple(const char *a, float v[4]) return 0; } + +static LengthUnits get_units(const char *t) +{ + size_t len = strlen(t); + + if ( t[len-1] == 'f' ) return UNITS_FRAC; + if ( t[len-1] == 'u' ) return UNITS_SLIDE; + + fprintf(stderr, _("Invalid units in '%s'\n"), t); + return UNITS_SLIDE; +} + + +int parse_dims(const char *opt, double *wp, double *hp, + LengthUnits *wup, LengthUnits *hup, + double *xp, double *yp) +{ + char *w; + char *h; + char *x; + char *y; + char *check; + + w = strdup(opt); + h = index(w, 'x'); + h[0] = '\0'; h++; + + x = index(h, '+'); + if ( x == NULL ) goto invalid; + x[0] = '\0'; x++; + + y = index(x, '+'); + if ( x == NULL ) goto invalid; + y[0] = '\0'; y++; + + *wp = strtod(w, &check); + if ( check == w ) goto invalid; + *wup = get_units(w); + + *hp = strtod(h, &check); + if ( check == h ) goto invalid; + *hup = get_units(h); + + *xp= strtod(x, &check); + if ( check == x ) goto invalid; + *yp = strtod(y, &check); + if ( check == y ) goto invalid; + + return 0; + +invalid: + fprintf(stderr, _("Invalid dimensions '%s'\n"), opt); + return 1; +} |