1 /**********************************************************************
3 FILENAME: uiuc_parsefile.cpp
5 ----------------------------------------------------------------------
7 DESCRIPTION: Reads the input file and stores data in a list
8 gets tokens from each line of the list
10 ----------------------------------------------------------------------
14 ----------------------------------------------------------------------
18 ----------------------------------------------------------------------
20 HISTORY: 01/30/2000 initial release
22 ----------------------------------------------------------------------
24 AUTHOR(S): Bipin Sehgal <bsehgal@uiuc.edu>
26 ----------------------------------------------------------------------
30 ----------------------------------------------------------------------
34 ----------------------------------------------------------------------
38 ----------------------------------------------------------------------
42 ----------------------------------------------------------------------
46 ----------------------------------------------------------------------
48 COPYRIGHT: (C) 2000 by Michael Selig
50 This program is free software; you can redistribute it and/or
51 modify it under the terms of the GNU General Public License
52 as published by the Free Software Foundation.
54 This program is distributed in the hope that it will be useful,
55 but WITHOUT ANY WARRANTY; without even the implied warranty of
56 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 GNU General Public License for more details.
59 You should have received a copy of the GNU General Public License
60 along with this program; if not, write to the Free Software
61 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
62 USA or view http://www.gnu.org/copyleft/gpl.html.
64 **********************************************************************/
65 #include <simgear/compiler.h>
67 #include "uiuc_parsefile.h"
69 FG_USING_NAMESPACE(std);
71 ParseFile :: ParseFile (const string fileName)
73 file.open(fileName.c_str());
77 ParseFile :: ~ParseFile ()
82 void ParseFile :: removeComments(string& inputLine)
84 int pos = inputLine.find_first_of(COMMENT);
86 if (pos != inputLine.npos) // a "#" exists in the line
88 if (inputLine.find_first_not_of(DELIMITERS) == pos)
89 inputLine = ""; // Complete line a comment
91 inputLine = inputLine.substr(0,pos); //Truncate the comment from the line
96 string ParseFile :: getToken(string inputLine, int tokenNo)
100 int tokencounter = 0;
102 while (tokencounter < tokenNo)
104 if ((pos1 == inputLine.npos) || (pos1 == -1) || (pos == -1) )
105 return ""; //return an empty string if tokenNo exceeds the No of tokens in the line
107 inputLine = inputLine.substr(pos1 , MAXLINE);
108 pos = inputLine.find_first_not_of(DELIMITERS);
109 pos1 = inputLine.find_first_of(DELIMITERS , pos);
113 if (pos1== -1 || pos == -1)
116 return inputLine.substr(pos , pos1-pos); // return the desired token
120 void ParseFile :: storeCommands(string inputLine)
127 inputLine += " "; // To take care of the case when last character is not a blank
128 pos = inputLine.find_first_not_of(DELIMITERS);
129 pos1 = inputLine.find_first_of(DELIMITERS);
131 while ((pos != inputLine.npos) && (pos1 != inputLine.npos))
133 line += inputLine.substr(pos , pos1 - pos)+ " ";
134 inputLine = inputLine.substr(pos1, inputLine.size()- (pos1 - pos));
135 pos = inputLine.find_first_not_of(DELIMITERS);
136 pos1 = inputLine.find_first_of(DELIMITERS , pos);
139 line += inputLine; // Add the last word to the line
140 commands.push_back(line);
143 void ParseFile :: readFile()
147 while (getline(file , line))
149 removeComments(line);
150 if (line.find_first_not_of(DELIMITERS) != line.npos) // strip off blank lines
155 stack ParseFile :: getCommands()
160 //end uiuc_parsefile.cpp