MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / exportVariables

Method exportVariables

Engine/source/console/consoleInternal.cpp:144–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144void Dictionary::exportVariables(const char *varString, const char *fileName, bool append)
145{
146 const char *searchStr = varString;
147 Vector<Entry *> sortList(__FILE__, __LINE__);
148
149 for (S32 i = 0; i < hashTable->size; i++)
150 {
151 Entry *walk = hashTable->data[i];
152 while (walk)
153 {
154 if (FindMatch::isMatch((char *)searchStr, (char *)walk->name))
155 sortList.push_back(walk);
156
157 walk = walk->nextEntry;
158 }
159 }
160
161 if (!sortList.size())
162 return;
163
164 dQsort((void *)&sortList[0], sortList.size(), sizeof(Entry *), varCompare);
165
166 Vector<Entry *>::iterator s;
167 char expandBuffer[1024];
168 FileStream *strm = NULL;
169
170 if (fileName)
171 {
172 if ((strm = FileStream::createAndOpen(fileName, append ? Torque::FS::File::ReadWrite : Torque::FS::File::Write)) == NULL)
173 {
174 Con::errorf(ConsoleLogEntry::General, "Unable to open file '%s for writing.", fileName);
175 return;
176 }
177 if (append)
178 strm->setPosition(strm->getStreamSize());
179 }
180
181 char buffer[1024];
182 const char *cat = fileName ? "\r\n" : "";
183
184 for (s = sortList.begin(); s != sortList.end(); s++)
185 {
186 switch ((*s)->type)
187 {
188 case Entry::TypeInternalInt:
189 dSprintf(buffer, sizeof(buffer), "%s = %d;%s", (*s)->name, (*s)->ival, cat);
190 break;
191 case Entry::TypeInternalFloat:
192 dSprintf(buffer, sizeof(buffer), "%s = %g;%s", (*s)->name, (*s)->fval, cat);
193 break;
194 default:
195 expandEscape(expandBuffer, (*s)->getStringValue());
196 dSprintf(buffer, sizeof(buffer), "%s = \"%s\";%s", (*s)->name, expandBuffer, cat);
197 break;
198 }
199 if (strm)
200 strm->write(dStrlen(buffer), buffer);
201 else

Callers 2

inspectGroupMethod · 0.80

Calls 15

dQsortFunction · 0.85
dSprintfFunction · 0.85
expandEscapeFunction · 0.85
printfFunction · 0.85
errorfFunction · 0.70
StringClass · 0.70
dStrlenFunction · 0.50
push_backMethod · 0.45
sizeMethod · 0.45
setPositionMethod · 0.45
getStreamSizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected