author | Florian Pose <fp@igh-essen.com> |
Mon, 05 May 2014 13:55:00 +0200 | |
branch | stable-1.5 |
changeset 2542 | 8dd49f6f6d32 |
parent 2012 | ee4782738e30 |
permissions | -rw-r--r-- |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/***************************************************************************** |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* published by the Free Software Foundation. |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* Public License for more details. |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* --- |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
#include <cstring> |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
#include <sstream> |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
#include <stdexcept> |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
using namespace std; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
#include "NumberListParser.h" |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
NumberListParser::NumberListParser(): |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
max(0U), |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
hasMax(false) |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
{ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
NumberListParser::~NumberListParser() |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
{ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
53 |
NumberListParser::List NumberListParser::parse(const char *data) |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
54 |
{ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
55 |
List ret; |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
unsigned int i = 0, size = strlen(data), firstNum = 0U, secondNum = 0U; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
typedef enum { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
SectionStart, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
FirstNumber, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
Range, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
SecondNumber, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
Finished |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
} State; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
State state = SectionStart; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
while (state != Finished) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
switch (state) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
case SectionStart: |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
if (i >= size) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
state = Finished; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
} else if (isNumeric(data[i])) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
firstNum = parseNumber(data, &i, size); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
state = FirstNumber; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
} else if (data[i] == '-') { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
firstNum = 0U; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
i++; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
state = Range; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
} else if (data[i] == ',') { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
i++; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
} else { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
stringstream err; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
err << "Invalid character " << data[i] |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
<< " at position " << i << "in state " |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
<< state << "." << endl; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
throw runtime_error(err.str()); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
break; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
case FirstNumber: |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
if (i >= size) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
ret.push_back(firstNum); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
state = Finished; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
} else if (data[i] == '-') { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
i++; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
state = Range; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
} else if (data[i] == ',') { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
i++; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
ret.push_back(firstNum); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
state = SectionStart; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
} else { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
stringstream err; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
err << "Invalid character " << data[i] |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
<< " at position " << i << "in state " |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
<< state << "." << endl; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
throw runtime_error(err.str()); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
break; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
case Range: |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
if (i >= size) { |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
111 |
int max = maximum(); |
2012
ee4782738e30
Assume increasing ranges if second number is omitted.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
112 |
// only increasing ranges if second number omitted |
ee4782738e30
Assume increasing ranges if second number is omitted.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
113 |
if (max >= 0 && firstNum <= (unsigned int) max) { |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
114 |
List r = range(firstNum, max); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
115 |
ret.splice(ret.end(), r); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
116 |
} |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
state = Finished; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
} else if (isNumeric(data[i])) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
secondNum = parseNumber(data, &i, size); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
state = SecondNumber; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
} else if (data[i] == ',') { |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
122 |
int max = maximum(); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
123 |
i++; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
124 |
if (max >= 0) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
125 |
List r = range(firstNum, max); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
126 |
ret.splice(ret.end(), r); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
127 |
} |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
128 |
state = SectionStart; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
129 |
} else { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
130 |
stringstream err; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
131 |
err << "Invalid character " << data[i] |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
132 |
<< " at position " << i << "in state " |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
133 |
<< state << "." << endl; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
134 |
throw runtime_error(err.str()); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
135 |
} |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
136 |
break; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
137 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
138 |
case SecondNumber: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
139 |
if (i >= size) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
140 |
List r = range(firstNum, secondNum); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
141 |
ret.splice(ret.end(), r); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
142 |
state = Finished; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
143 |
} else if (data[i] == ',') { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
144 |
i++; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
145 |
List r = range(firstNum, secondNum); |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
ret.splice(ret.end(), r); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
state = SectionStart; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
} else { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
stringstream err; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
err << "Invalid character " << data[i] |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
<< " at position " << i << "in state " |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
<< state << "." << endl; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
throw runtime_error(err.str()); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
break; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
default: |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
{ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
stringstream err; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
err << "Invalid state " << state << "."; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
throw runtime_error(err.str()); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
return ret; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
170 |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
171 |
int NumberListParser::maximum() |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
{ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
if (!hasMax) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
max = getMax(); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
return max; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
182 |
bool NumberListParser::isNumeric(char c) |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
183 |
{ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
184 |
return c >= '0' && c <= '9'; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
185 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
unsigned int NumberListParser::parseNumber( |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
const char *data, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
unsigned int *i, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
unsigned int size |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
) |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
{ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
195 |
unsigned int numSize = 0U, ret; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
196 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
197 |
while (*i + numSize < size && isNumeric(data[*i + numSize])) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
198 |
numSize++; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
if (numSize) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
stringstream str; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
203 |
str << string(data + *i, numSize); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
204 |
str >> ret; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
205 |
} else { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
206 |
throw runtime_error("EOF"); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
207 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
208 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
209 |
*i = *i + numSize; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
210 |
return ret; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
211 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
212 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
213 |
/****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
214 |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
215 |
NumberListParser::List NumberListParser::range( |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
216 |
unsigned int i, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
217 |
unsigned int j |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
218 |
) |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
219 |
{ |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1828
diff
changeset
|
220 |
List ret; |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
221 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
222 |
if (i <= j) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
223 |
for (; i <= j; i++) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
224 |
ret.push_back(i); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
225 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
226 |
} else { |
1828
651e9cfb244b
Fixed endless loop if negative master index range ends at zero.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
227 |
for (; j <= i; j++) { |
651e9cfb244b
Fixed endless loop if negative master index range ends at zero.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
228 |
ret.push_front(j); |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
229 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
230 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
231 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
232 |
return ret; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
233 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
234 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
235 |
/****************************************************************************/ |