File: fxparsegeometry.cpp

package info (click to toggle)
gogglesmm 1.2.5-6
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 16,812 kB
  • sloc: cpp: 231,960; ansic: 893; xml: 222; makefile: 33
file content (124 lines) | stat: -rw-r--r-- 4,053 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/********************************************************************************
*                                                                               *
*         P a r s e   G e o m e t r y   F r o m   C o m m a n d   L i n e       *
*                                                                               *
*********************************************************************************
* Copyright (C) 2002,2022 by Jeroen van der Zijp.   All Rights Reserved.        *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify          *
* it under the terms of the GNU Lesser General Public License as published by   *
* the Free Software Foundation; either version 3 of the License, or             *
* (at your option) any later version.                                           *
*                                                                               *
* This library 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 Lesser General Public License for more details.                           *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public License      *
* along with this program.  If not, see <http://www.gnu.org/licenses/>          *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"


/*
  Notes:
  - Programmer must call this to parse geometry from command
    line parameter "-g" or "--geometry"; first initialize input/output
    arguments to their default values, the ones parsed will be
    overridden.
*/

using namespace FX;

/*******************************************************************************/

namespace FX {

// Parse string of the form:
//
//      [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]
//
// Return or of flags:
//
//      1       x was assigned
//      2       y was assigned
//      4       width was assigned
//      8       height was assigned
FXint fxparsegeometry(const FXchar *string,FXint& x,FXint& y,FXint& w,FXint& h){
  FXint result=0;

  // Got string?
  if(string && *string!='\0'){
    FXint tw=0;
    FXint th=0;
    FXint tx=0;
    FXint ty=0;
    FXint mul;

    // Parse white space
    while(*string==' ' || *string=='\t'){
      string++;
      }

    // Skip leading '=', if any
    if(*string=='=') string++;

    // Start with width
    if(*string!='+' && *string!='-' && *string!='x' && *string!='X'){
      while('0'<=*string && *string<='9'){
        tw=tw*10+(*string++-'0');
        result|=4;                      // At least one digit found
        }
      }

    // Then height
    if(*string=='x' || *string=='X'){
      string++;
      while('0'<=*string && *string<='9'){
        th=th*10+(*string++-'0');
        result|=8;                      // At least one digit found
        }
      }

    // Then x
    if(*string=='+' || *string== '-'){
      if(*string++ == '-') mul=-1; else mul=1;
      while('0'<=*string && *string<='9'){
        tx=tx*10+(*string++-'0');
        result|=1;                      // At least one digit found
        }
      tx*=mul;
      }

    // Then y
    if(*string=='+' || *string == '-'){
      if(*string++ == '-') mul=-1; else mul=1;
      while('0'<=*string && *string<='9'){
        ty=ty*10+(*string++-'0');
        result|=2;                      // At least one digit found
        }
      ty*=mul;
      }

    // Parse white space
    while(*string==' ' || *string=='\t'){
      string++;
      }

    // Got the whole string
    if(*string=='\0'){

      // Return what was found
      if(result&1) x=tx;
      if(result&2) y=ty;
      if(result&4) w=tw;
      if(result&8) h=th;
      }
    }
  return result;
  }

}