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

Method exportVariables

Engine/source/console/consoleInternal.cpp:128–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

inspectGroupMethod · 0.80

Calls 15

dQsortFunction · 0.85
errorfFunction · 0.85
dSprintfFunction · 0.85
expandEscapeFunction · 0.85
printfFunction · 0.85
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