void DateFormatCommand :: ProcessFlags( ALib::CommandLine & cmd ) { ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) ); CommaListToIndex( cl, mFields ); string fmt = cmd.GetValue( FLAG_FMT, "" ); if ( ALib::IsEmpty( fmt ) ) { CSVTHROW( "Empty date format" ); } BuildFormat( fmt ); }
bool Db2File::Load(string filePath, vector<uint32> format) { uint32 header; //Delete data, if there is data Close(); //Get the name _name = filePath.substr(filePath.find_last_of("/") + 1); //Open the Dbc files FILE *f = fopen(filePath.c_str(), "rb"); if (f == NULL) { printf("WARNING: Can't load '%s' - File Not Found - skipping it!\n", filePath.c_str()); return false; } //Check if that file really is a Dbc file fread(&header, 4, 1, f); // Signature if (header != 843203671) { printf("WARNING: Can't load '%s' - Not A Db2 File - skipping it!\n", filePath.c_str()); fclose(f); return false; // 'WDBC' } uint32 _stringSize; //Read the header fread(&_recordCount, 4, 1, f); // Number of records fread(&_fieldCount, 4, 1, f); // Number of fields fread(&_recordSize, 4, 1, f); // Size of a record fread(&_stringSize, 4, 1, f); // String size // WDB2 specific fields uint32 tableHash, build, unk1; fread(&tableHash, 4, 1, f); fread(&build, 4, 1, f); fread(&unk1, 4, 1, f); if (build > 12880) // new extended header { int MinId, MaxId, locale, unk5; fread(&MinId, 4, 1, f); fread(&MaxId, 4, 1, f); fread(&locale, 4, 1, f); fread(&unk5, 4, 1, f); if (MaxId != 0) { uint32 diff = MaxId - MinId + 1; fseek(f, diff * 4, SEEK_CUR); // an index for rows fseek(f, diff * 2, SEEK_CUR ); // a memory allocation bank } } _dataTable = new uint8[_recordSize * _recordCount]; fread(_dataTable, _recordSize * _recordCount, 1, f); _stringTable = new uint8[_stringSize]; fread(_stringTable, _stringSize, 1, f); _stringOffset = _recordCount * _recordSize; fclose(f); _format = new uint32[_fieldCount]; _fieldOffset = new uint32[_fieldCount]; if(format.size() == 0) { if(_fieldCount * 4 == _recordSize) return BuildFormat(vector<uint32>(_fieldCount, FT_UINT32)); else { printf("WARNING: Can't load '%s' - cannot find a default format - skipping it\n", _name.c_str()); return false; } } return BuildFormat(format); }