]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_parsefile.cpp
Make yasim accept the launchbar and hook properties. They are not tied to anything...
[flightgear.git] / src / FDM / UIUCModel / uiuc_parsefile.cpp
1 /**********************************************************************
2
3  FILENAME:     uiuc_parsefile.cpp
4
5 ----------------------------------------------------------------------
6
7  DESCRIPTION:  Reads the input file and stores data in a list
8                gets tokens from each line of the list
9               
10 ----------------------------------------------------------------------
11
12  STATUS:       alpha version
13
14 ----------------------------------------------------------------------
15
16  REFERENCES:   
17
18 ----------------------------------------------------------------------
19
20  HISTORY:      01/30/2000   (BS) initial release
21                09/19/2002   (MSS) appended zeros to lines w/ comments
22
23 ----------------------------------------------------------------------
24
25  AUTHOR(S):    Bipin Sehgal       <bsehgal@uiuc.edu>
26                Michael Selig
27
28 ----------------------------------------------------------------------
29
30  VARIABLES:
31
32 ----------------------------------------------------------------------
33
34  INPUTS:       *
35
36 ----------------------------------------------------------------------
37
38  OUTPUTS:      *
39
40 ----------------------------------------------------------------------
41
42  CALLED BY:    *
43
44 ----------------------------------------------------------------------
45
46  CALLS TO:     *
47
48 ----------------------------------------------------------------------
49
50  COPYRIGHT:    (C) 2000 by Michael Selig
51
52  This program is free software; you can redistribute it and/or
53  modify it under the terms of the GNU General Public License
54  as published by the Free Software Foundation.
55
56  This program is distributed in the hope that it will be useful,
57  but WITHOUT ANY WARRANTY; without even the implied warranty of
58  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
59  GNU General Public License for more details.
60
61  You should have received a copy of the GNU General Public License
62  along with this program; if not, write to the Free Software
63  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
64  USA or view http://www.gnu.org/copyleft/gpl.html.
65
66 **********************************************************************/
67
68
69 #include "uiuc_parsefile.h"
70
71
72 ParseFile :: ParseFile (const string fileName)
73 {
74   file.open(fileName.c_str());
75   readFile();
76 }
77
78 ParseFile :: ~ParseFile ()
79 {
80   file.close();
81 }
82
83 void ParseFile :: removeComments(string& inputLine)
84 {
85   string::size_type pos = inputLine.find_first_of(COMMENT);
86   
87   if (pos != inputLine.npos) // a "#" exists in the line 
88   {
89         if (inputLine.find_first_not_of(DELIMITERS) == pos)
90           {
91             inputLine = ""; // Complete line a comment
92           }
93         else
94           {
95             inputLine = inputLine.substr(0,pos); //Truncate the comment from the line
96             // append zeros to the input line after stripping off the comments
97             // mss added from Bipin email of 9/3/02
98             //      inputLine += " 0 0 0 0 0 0";
99           }
100   }
101 }
102
103
104 string ParseFile :: getToken(string inputLine, int tokenNo)
105 {
106   string::size_type pos = 0;
107   string::size_type pos1 = 0;
108   int tokencounter = 0;
109
110   while (tokencounter < tokenNo)
111   {
112     if ((pos1 == inputLine.npos) || (pos1 == -1) || (pos == -1) )
113           return ""; //return an empty string if tokenNo exceeds the No of tokens in the line
114         
115         inputLine = inputLine.substr(pos1 , MAXLINE);
116         pos = inputLine.find_first_not_of(DELIMITERS);
117         pos1 = inputLine.find_first_of(DELIMITERS , pos);
118         tokencounter ++;
119   }
120
121   if (pos1== -1 || pos == -1)
122     return "";
123   else
124       return inputLine.substr(pos , pos1-pos); // return the desired token 
125 }
126
127
128 void ParseFile :: storeCommands(string inputLine)
129 {
130   string::size_type pos;
131   string::size_type pos1;
132   // int wordlength;
133   string line;
134  
135   inputLine += " ";  // To take care of the case when last character is not a blank
136   pos = inputLine.find_first_not_of(DELIMITERS);
137   pos1 = inputLine.find_first_of(DELIMITERS);
138   
139   while ((pos != inputLine.npos) && (pos1 != inputLine.npos))
140   {
141         line += inputLine.substr(pos , pos1 - pos)+ " ";
142         inputLine = inputLine.substr(pos1, inputLine.size()- (pos1 - pos));
143         pos = inputLine.find_first_not_of(DELIMITERS);
144         pos1 = inputLine.find_first_of(DELIMITERS , pos);
145   }
146   
147   line += inputLine; // Add the last word to the line
148   commands.push_back(line);
149 }
150
151 //  void ParseFile :: readFile()
152 //  {
153 //    string line;
154
155 //    while (getline(file , line))
156 //    {
157 //     removeComments(line);
158 //     if (line.find_first_not_of(DELIMITERS) != line.npos) // strip off blank lines
159 //     {
160 //      line += "     0 0 0 0 0";
161 //          storeCommands(line);
162 //     }
163 //    }
164 //  }
165
166 void ParseFile :: readFile()
167 {
168   string line;
169
170   while (getline(file , line))
171     {
172       removeComments(line);
173       if (line.find_first_not_of(DELIMITERS) != line.npos) // strip off blank lines
174         {
175           line += "     ";
176           // append some zeros, but this is doing something strange!
177           //              line += "  0 0 0 0 0   ";
178           storeCommands(line);
179         }
180     }
181 }
182 stack ParseFile :: getCommands()
183 {
184   return commands;
185 }
186
187 //end uiuc_parsefile.cpp