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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
64 USA or view http://www.gnu.org/copyleft/gpl.html.
66 **********************************************************************/
69 #include "uiuc_parsefile.h"
72 ParseFile :: ParseFile (const string fileName)
74 file.open(fileName.c_str());
78 ParseFile :: ~ParseFile ()
83 void ParseFile :: removeComments(string& inputLine)
85 string::size_type pos = inputLine.find_first_of(COMMENT);
87 if (pos != inputLine.npos) // a "#" exists in the line
89 if (inputLine.find_first_not_of(DELIMITERS) == pos)
91 inputLine = ""; // Complete line a comment
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";
104 string ParseFile :: getToken(string inputLine, int tokenNo)
106 string::size_type pos = 0;
107 string::size_type pos1 = 0;
108 int tokencounter = 0;
110 while (tokencounter < tokenNo)
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
115 inputLine = inputLine.substr(pos1 , MAXLINE);
116 pos = inputLine.find_first_not_of(DELIMITERS);
117 pos1 = inputLine.find_first_of(DELIMITERS , pos);
121 if (pos1== -1 || pos == -1)
124 return inputLine.substr(pos , pos1-pos); // return the desired token
128 void ParseFile :: storeCommands(string inputLine)
130 string::size_type pos;
131 string::size_type pos1;
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);
139 while ((pos != inputLine.npos) && (pos1 != inputLine.npos))
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);
147 line += inputLine; // Add the last word to the line
148 commands.push_back(line);
151 // void ParseFile :: readFile()
155 // while (getline(file , line))
157 // removeComments(line);
158 // if (line.find_first_not_of(DELIMITERS) != line.npos) // strip off blank lines
160 // line += " 0 0 0 0 0";
161 // storeCommands(line);
166 void ParseFile :: readFile()
170 while (getline(file , line))
172 removeComments(line);
173 if (line.find_first_not_of(DELIMITERS) != line.npos) // strip off blank lines
176 // append some zeros, but this is doing something strange!
177 // line += " 0 0 0 0 0 ";
182 stack ParseFile :: getCommands()
187 //end uiuc_parsefile.cpp