MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / StripCRCFileName

Function StripCRCFileName

Descent3/pilot.cpp:2143–2182  ·  view source on GitHub ↗

StripCRCFileName Given a filename that has the _ in it at the end of the name, it will fill in dest with just the filename part (without the trailing _ ).

Source from the content-addressed store, hash-verified

2141// Given a filename that has the _<CRC> in it at the end of the name, it will fill
2142// in dest with just the filename part (without the trailing _<CRC>).
2143void StripCRCFileName(const char *src, char *dest) {
2144 ASSERT(src);
2145 ASSERT(dest);
2146
2147 int full_strlen = strlen(src);
2148 char ext[256];
2149 ddio_SplitPath(src, NULL, NULL, ext);
2150 int extstrlen = strlen(ext);
2151 int eon = full_strlen - 9 - extstrlen;
2152
2153 if (eon < 1) {
2154 // this filename doesn't have a trailing CRC
2155 strcpy(dest, src);
2156 return;
2157 }
2158
2159 // check to make sure the [eon] is '_'
2160 if (src[eon] != '_') {
2161 // it wasn't so it must not have a CRC at the end
2162 strcpy(dest, src);
2163 return;
2164 }
2165
2166 char hexstring[9];
2167 strncpy(hexstring, &src[eon + 1], 8);
2168 hexstring[8] = '\0';
2169 uint32_t crc;
2170 crc = axtoi(hexstring);
2171
2172 if (crc == 0) {
2173 // crc can't be 0?
2174 strcpy(dest, src);
2175 return;
2176 }
2177
2178 // strip the filename
2179 strncpy(dest, src, eon);
2180 dest[eon] = '\0';
2181 strcat(dest, ext); // put back the extension
2182}
2183
2184// CreateCRCFileName
2185//

Callers 4

CreateCRCFileNameFunction · 0.85
ImportGraphicFunction · 0.85
UpdateGraphicsListboxFunction · 0.85
UpdateAudioTauntBoxesFunction · 0.85

Calls 2

axtoiFunction · 0.70
ddio_SplitPathFunction · 0.50

Tested by

no test coverage detected