]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_menu_gear.cpp
Fix for bug 1304 - crash loading XML route
[flightgear.git] / src / FDM / UIUCModel / uiuc_menu_gear.cpp
1 /**********************************************************************
2                                                                        
3  FILENAME:     uiuc_menu_gear.cpp
4
5 ----------------------------------------------------------------------
6
7  DESCRIPTION:  reads input data for specified aircraft and creates 
8                approporiate data storage space
9
10 ----------------------------------------------------------------------
11
12  STATUS:       alpha version
13
14 ----------------------------------------------------------------------
15
16  REFERENCES:   based on "menu reader" format of Michael Selig
17
18 ----------------------------------------------------------------------
19
20  HISTORY:      04/04/2003   initial release
21                06/30/2003   (RD) replaced istrstream with istringstream
22                             to get rid of the annoying warning about
23                             using the strstream header
24
25 ----------------------------------------------------------------------
26
27  AUTHOR(S):    Robert Deters      <rdeters@uiuc.edu>
28                Michael Selig      <m-selig@uiuc.edu>
29
30 ----------------------------------------------------------------------
31
32  VARIABLES:
33
34 ----------------------------------------------------------------------
35
36  INPUTS:       n/a
37
38 ----------------------------------------------------------------------
39
40  OUTPUTS:      n/a
41
42 ----------------------------------------------------------------------
43
44  CALLED BY:    uiuc_menu()
45
46 ----------------------------------------------------------------------
47
48  CALLS TO:     check_float() if needed
49                d_2_to_3() if needed
50                d_1_to_2() if needed
51                i_1_to_2() if needed
52                d_1_to_1() if needed
53
54  ----------------------------------------------------------------------
55
56  COPYRIGHT:    (C) 2003 by Michael Selig
57
58  This program is free software; you can redistribute it and/or
59  modify it under the terms of the GNU General Public License
60  as published by the Free Software Foundation.
61
62  This program is distributed in the hope that it will be useful,
63  but WITHOUT ANY WARRANTY; without even the implied warranty of
64  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
65  GNU General Public License for more details.
66
67  You should have received a copy of the GNU General Public License
68  along with this program; if not, write to the Free Software
69  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
70
71 **********************************************************************/
72
73 #include <simgear/compiler.h>
74
75
76 #include <cstdlib>
77 #include <string>
78 #include <iostream>
79
80 #include "uiuc_menu_gear.h"
81
82 using std::cerr;
83 using std::cout;
84 using std::endl;
85
86 #ifndef _MSC_VER
87 using std::exit;
88 #endif
89
90 void parse_gear( const string& linetoken2, const string& linetoken3,
91                  const string& linetoken4, const string& linetoken5, 
92                  const string& linetoken6, const string& linetoken7, 
93                  const string& linetoken8, const string& linetoken9,
94                  const string& linetoken10, const string& aircraft_directory, 
95                  LIST command_line ) {
96     double token_value;
97     istringstream token3(linetoken3.c_str());
98     istringstream token4(linetoken4.c_str());
99     istringstream token5(linetoken5.c_str());
100     istringstream token6(linetoken6.c_str());
101     istringstream token7(linetoken7.c_str());
102     istringstream token8(linetoken8.c_str());
103     istringstream token9(linetoken9.c_str());
104     istringstream token10(linetoken10.c_str());
105
106     switch(gear_map[linetoken2])
107       {
108       case Dx_gear_flag:
109         {
110           int index;
111           token3 >> index;
112           if (index < 0 || index >= 16)
113             uiuc_warnings_errors(1, *command_line);
114           if (check_float(linetoken4))
115             token4 >> token_value;
116           else
117             uiuc_warnings_errors(1, *command_line);
118           D_gear_v[index][0] = token_value;
119           gear_model[index] = true;
120           break;
121         }
122       case Dy_gear_flag:
123         {
124           int index;
125           token3 >> index;
126           if (index < 0 || index >= 16)
127             uiuc_warnings_errors(1, *command_line);
128           if (check_float(linetoken4))
129             token4 >> token_value;
130           else
131             uiuc_warnings_errors(1, *command_line);
132           D_gear_v[index][1] = token_value;
133           gear_model[index] = true;
134           break;
135         }
136       case Dz_gear_flag:
137         {
138           int index;
139           token3 >> index;
140           if (index < 0 || index >= 16)
141             uiuc_warnings_errors(1, *command_line);
142           if (check_float(linetoken4))
143             token4 >> token_value;
144           else
145             uiuc_warnings_errors(1, *command_line);
146           D_gear_v[index][2] = token_value;
147           gear_model[index] = true;
148           break;
149         }
150       case cgear_flag:
151         {
152           int index;
153           token3 >> index;
154           if (index < 0 || index >= 16)
155             uiuc_warnings_errors(1, *command_line);
156           if (check_float(linetoken4))
157             token4 >> token_value;
158           else
159             uiuc_warnings_errors(1, *command_line);
160           cgear[index] = token_value;
161           gear_model[index] = true;
162           break;
163         }
164       case kgear_flag:
165         {
166           int index;
167           token3 >> index;
168           if (index < 0 || index >= 16)
169             uiuc_warnings_errors(1, *command_line);
170           if (check_float(linetoken4))
171             token4 >> token_value;
172           else
173             uiuc_warnings_errors(1, *command_line);
174           kgear[index] = token_value;
175           gear_model[index] = true;
176           break;
177         }
178       case muGear_flag:
179         {
180           int index;
181           token3 >> index;
182           if (index < 0 || index >= 16)
183             uiuc_warnings_errors(1, *command_line);
184           if (check_float(linetoken4))
185             token4 >> token_value;
186           else
187             uiuc_warnings_errors(1, *command_line);
188           muGear[index] = token_value;
189           gear_model[index] = true;
190           break;
191         }
192       case strutLength_flag:
193         {
194           int index;
195           token3 >> index;
196           if (index < 0 || index >= 16)
197             uiuc_warnings_errors(1, *command_line);
198           if (check_float(linetoken4))
199             token4 >> token_value;
200           else
201             uiuc_warnings_errors(1, *command_line);
202           strutLength[index] = token_value;
203           gear_model[index] = true;
204           break;
205         }
206       case gear_max_flag:
207         {
208           if (check_float(linetoken3))
209             token3 >> token_value;
210           else
211             uiuc_warnings_errors(1, *command_line);
212           
213           use_gear = true;
214           gear_max = token_value;
215           break;
216         }
217       case gear_rate_flag:
218         {
219           if (check_float(linetoken3))
220             token3 >> token_value;
221           else
222             uiuc_warnings_errors(1, *command_line);
223           
224           use_gear = true;
225           gear_rate = token_value;
226           break;
227         }
228       default:
229         {
230           if (ignore_unknown_keywords) {
231             // do nothing
232           } else {
233             // print error message
234             uiuc_warnings_errors(2, *command_line);
235           }
236           break;
237         }
238       };
239 }