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 (BS) initial release
21 09/19/2002 (MSS) appended zeros to lines w/ comments
23 ----------------------------------------------------------------------
25 AUTHOR(S): Bipin Sehgal <bsehgal@uiuc.edu>
28 ----------------------------------------------------------------------
32 ----------------------------------------------------------------------
36 ----------------------------------------------------------------------
40 ----------------------------------------------------------------------
44 ----------------------------------------------------------------------
48 ----------------------------------------------------------------------
50 COPYRIGHT: (C) 2000 by Michael Selig
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
65 **********************************************************************/
68 #include "uiuc_parsefile.h"
71 ParseFile :: ParseFile (const string fileName)
73 file.open(fileName.c_str());
77 ParseFile :: ~ParseFile ()
82 void ParseFile :: removeComments(string& inputLine)
84 string::size_type 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)
90 inputLine = ""; // Complete line a comment
94 inputLine = inputLine.substr(0,pos); //Truncate the comment from the line
95 // append zeros to the input line after stripping off the comments
96 // mss added from Bipin email of 9/3/02
97 // inputLine += " 0 0 0 0 0 0";
103 string ParseFile :: getToken(string inputLine, int tokenNo)
105 string::size_type pos = 0;
106 string::size_type pos1 = 0;
107 int tokencounter = 0;
109 while (tokencounter < tokenNo)
111 if ((pos1 == inputLine.npos) || (pos1 == -1) || (pos == -1) )
112 return ""; //return an empty string if tokenNo exceeds the No of tokens in the line
114 inputLine = inputLine.substr(pos1 , MAXLINE);
115 pos = inputLine.find_first_not_of(DELIMITERS);
116 pos1 = inputLine.find_first_of(DELIMITERS , pos);
120 if (pos1== -1 || pos == -1)
123 return inputLine.substr(pos , pos1-pos); // return the desired token
127 void ParseFile :: storeCommands(string inputLine)
129 string::size_type pos;
130 string::size_type pos1;
134 inputLine += " "; // To take care of the case when last character is not a blank
135 pos = inputLine.find_first_not_of(DELIMITERS);
136 pos1 = inputLine.find_first_of(DELIMITERS);
138 while ((pos != inputLine.npos) && (pos1 != inputLine.npos))
140 line += inputLine.substr(pos , pos1 - pos)+ " ";
141 inputLine = inputLine.substr(pos1, inputLine.size()- (pos1 - pos));
142 pos = inputLine.find_first_not_of(DELIMITERS);
143 pos1 = inputLine.find_first_of(DELIMITERS , pos);
146 line += inputLine; // Add the last word to the line
147 commands.push_back(line);
150 // void ParseFile :: readFile()
154 // while (getline(file , line))
156 // removeComments(line);
157 // if (line.find_first_not_of(DELIMITERS) != line.npos) // strip off blank lines
159 // line += " 0 0 0 0 0";
160 // storeCommands(line);
165 void ParseFile :: readFile()
169 while (getline(file , line))
171 removeComments(line);
172 if (line.find_first_not_of(DELIMITERS) != line.npos) // strip off blank lines
175 // append some zeros, but this is doing something strange!
176 // line += " 0 0 0 0 0 ";
181 stack ParseFile :: getCommands()
186 //end uiuc_parsefile.cpp