MCPcopy Create free account
hub / github.com/devosoft/avida / loadFile

Method loadFile

avida-core/source/tools/cInitFile.cc:102–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100
101
102bool cInitFile::loadFile(const cString& filename, Apto::Array<sLine*, Apto::Smart>& lines, const cString& working_dir,
103 const Apto::Set<Apto::String>* custom_directives, Feedback& feedback)
104{
105 cString path = cString(Apto::FileSystem::GetAbsolutePath(Apto::String(filename), Apto::String(working_dir)));
106 cFile file(path);
107 if (!file.IsOpen()) {
108 feedback.Error("unable to open file '%s'.", (const char*)filename);
109 return false; // The file must be opened!
110 }
111
112 m_found = true;
113
114 cStringList line_list; // Create a list to load all of the lines into.
115
116 int linenum = 0;
117 cString buf;
118 while (!file.Eof() && file.ReadLine(buf)) {
119 linenum++;
120
121 // Perform variable substitution
122 for (Apto::Map<Apto::String, Apto::String>::Iterator it = m_mappings.Begin(); it.Next() != NULL;) {
123 Apto::String varname = Apto::FormatStr("$%s", (const char*)it.Get()->Value1());
124 buf.Replace((const char*)varname, (const char*)*it.Get()->Value2());
125 }
126
127 // Process the line
128 if (buf.GetSize() && buf[0] == '#') {
129 if (!processCommand(buf, lines, filename, linenum, working_dir, custom_directives, feedback)) return false;
130 } else {
131 lines.Push(new sLine(buf, filename, linenum));
132 }
133 }
134 file.Close();
135
136 return true;
137}
138
139
140bool cInitFile::processCommand(cString cmdstr, Apto::Array<sLine*, Apto::Smart>& lines, const cString& filename, int linenum,

Callers

nothing calls this directly

Calls 13

StringFunction · 0.85
EofMethod · 0.80
ReadLineMethod · 0.80
cStringClass · 0.70
IsOpenMethod · 0.45
ErrorMethod · 0.45
BeginMethod · 0.45
NextMethod · 0.45
GetMethod · 0.45
ReplaceMethod · 0.45
GetSizeMethod · 0.45
PushMethod · 0.45

Tested by

no test coverage detected