#include #include #include #include #include #include "nat_dtable.h" #include "nat_vtable.h" using namespace std; /***************************************************************************/ static string getBasename(const string& strSrc) { /* blergh */ const char* szDot = strrchr(strSrc.c_str(), '.'); if(szDot == NULL) { return strSrc; } else { return string(strSrc, 0, szDot - strSrc.c_str()); } } static string toURI(const char* szSrc) { string szRet = "file:///"; szRet += szSrc; for(int i = 0; i< (int)szRet.length(); ++i) if(szRet[i] == '\\') szRet[i] = '/'; return szRet; } static string fromURI(const char* szSrc) { if(strstr(szSrc, "file:///") == NULL) return szSrc; else { string szRet(szSrc, 8, strlen(szSrc)-8); for(int i = 0; i< (int)szRet.length(); ++i) if(szRet[i] == '/') szRet[i] = '\\'; return szRet; } } static void natTypeToStringFormatter(const natTable* pTable, int iRow, int iCol, string& strResult) { natCellType eType = (natCellType)pTable->getInt32(iRow,iCol); strResult = NAT_TYPE_NAME(eType); } int main(int argc, char** argv) { bool bTest = false; bool bVerbose = false; bool bRaw = false; ////////////////////////////////////////////////////////////////////////// string szInput; for(int i = 1; i < argc; i++) { if(strcmp(argv[i], "--raw") == 0) { bRaw = true; } else if(strcmp(argv[i], "-v") == 0) { bVerbose = true; } else if(strcmp(argv[i], "--usage") == 0) { printf( "Usage: ./tablecat filename.dae\n" "\n" " --test for debugging\n" " --raw do not intelligently show vtables\n" "\n\n" ); return EXIT_SUCCESS; } else { szInput = argv[i]; } } if(szInput == "") { fprintf(stderr, "No input given\n"); return EXIT_FAILURE; } ////////////////////////////////////////////////////////////////////////// FILE* f = fopen(szInput.c_str(), "rb"); if(f == NULL) { fprintf(stderr, "Could not open %s\n", szInput.c_str()); return EXIT_FAILURE; } ////////////////////////////////////////////////////////////////////////// natDTable kTable; int iBytesRead = kTable.readFromFile(f); if(iBytesRead == 0) { fprintf(stderr, "Error while loading %s\n", szInput.c_str()); return EXIT_FAILURE; } if(bVerbose) { fprintf(stderr, "%i bytes loaded.\n", iBytesRead); } string szIgnored; if(bRaw == false && natVTable::isFlattenedVTable(kTable,szIgnored)) { natVTable kVTable; bool bOK = kVTable.fromTable(kTable); if(bOK == false) { fprintf(stderr, "I thought this was a vtable but it isn't..."); return EXIT_FAILURE; } if(bVerbose) kVTable.debug(); string szResult; vector kFormatter; kFormatter.push_back(natTypeToStringFormatter); natDTable* pVSchema = kVTable.getVSchema(); pVSchema->toString_Formatted("%r %r %15lx", szResult, kFormatter); printf("%s\n", szResult.c_str()); printf("\n\n"); kVTable.toString_AutoWidth(szResult); printf("%s\n", szResult.c_str()); } else { /* just print this vtable */ string szResult; kTable.toString_AutoWidth(szResult); printf("%s\n", szResult.c_str()); } return EXIT_SUCCESS; }