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 **********************************************************************/
67 #include "uiuc_parsefile.h"
70 ParseFile :: ParseFile (const string fileName)
72 file.open(fileName.c_str());
76 ParseFile :: ~ParseFile ()
81 void ParseFile :: removeComments(string& inputLine)
83 unsigned int pos = inputLine.find_first_of(COMMENT);
85 if (pos != inputLine.npos) // a "#" exists in the line
87 if (inputLine.find_first_not_of(DELIMITERS) == pos)
88 inputLine = ""; // Complete line a comment
90 inputLine = inputLine.substr(0,pos); //Truncate the comment from the line
95 string ParseFile :: getToken(string inputLine, int tokenNo)
98 unsigned int pos1 = 0;
101 while (tokencounter < tokenNo)
103 if ((pos1 == inputLine.npos) || (pos1 == -1) || (pos == -1) )
104 return ""; //return an empty string if tokenNo exceeds the No of tokens in the line
106 inputLine = inputLine.substr(pos1 , MAXLINE);
107 pos = inputLine.find_first_not_of(DELIMITERS);
108 pos1 = inputLine.find_first_of(DELIMITERS , pos);
112 if (pos1== -1 || pos == -1)
115 return inputLine.substr(pos , pos1-pos); // return the desired token
119 void ParseFile :: storeCommands(string inputLine)
126 inputLine += " "; // To take care of the case when last character is not a blank
127 pos = inputLine.find_first_not_of(DELIMITERS);
128 pos1 = inputLine.find_first_of(DELIMITERS);
130 while ((pos != inputLine.npos) && (pos1 != inputLine.npos))
132 line += inputLine.substr(pos , pos1 - pos)+ " ";
133 inputLine = inputLine.substr(pos1, inputLine.size()- (pos1 - pos));
134 pos = inputLine.find_first_not_of(DELIMITERS);
135 pos1 = inputLine.find_first_of(DELIMITERS , pos);
138 line += inputLine; // Add the last word to the line
139 commands.push_back(line);
142 void ParseFile :: readFile()
146 while (getline(file , line))
148 removeComments(line);
149 if (line.find_first_not_of(DELIMITERS) != line.npos) // strip off blank lines
154 stack ParseFile :: getCommands()
159 //end uiuc_parsefile.cpp