void ins(DataArchive& a, int argc, char* argv[]) { char sPath[256]; char* pDirSep = 0; for (int i = 0; i < argc; i++) { if (strchr(argv[i], '*')) { strcpy(sPath, argv[i]); if ((pDirSep = strrchr(sPath, '\\')) != 0) *pDirSep = 0; else if ((pDirSep = strrchr(sPath, '/')) != 0) *pDirSep = 0; else sPath[0] = 0; WIN32_FIND_DATA find; LPCWSTR tmp = (LPCWSTR)argv[i]; HANDLE h = FindFirstFile(tmp, &find); if (h != INVALID_HANDLE_VALUE) { insertFile(a, sPath, &find); while (FindNextFile(h,&find)) { insertFile(a, sPath, &find); } FindClose(h); } } else { a.Insert(argv[i]); } } }
static void insertMemberReference(sqlite3 *db, const char*src, const char*dst, const char *file, int line, int column) { #if 0 QCString scope = dst->getScopeString(); QCString src_name = src->name(); QCString dst_name = dst->name(); if (!dst->getScopeString().isEmpty() && dst->getScopeString()!=def->name()) { dst_name.prepend(scope+getLanguageSpecificSeparator(dst->getLanguage())); } if (!src->getScopeString().isEmpty() && src->getScopeString()!=def->name()) { src_name.prepend(scope+getLanguageSpecificSeparator(src->getLanguage())); } #endif // bindTextParameter(i_s_xrefs,":src",src); bindTextParameter(i_s_xrefs,":dst",dst); int id_file = insertFile(db,file); bindIntParameter(i_s_xrefs,":id_file",id_file); bindIntParameter(i_s_xrefs,":line",line); bindIntParameter(i_s_xrefs,":column",column); step(db,i_s_xrefs); }
// --------------------------------------------------------------- int PackageDialog::insertDirectory(const QString& DirName, QDataStream& Stream) { QFile File; QDir myDir(DirName); // Put all files of this directory into the package. QStringList Entries = myDir.entryList("*", QDir::Files, QDir::Name); QStringList::iterator it; for(it = Entries.begin(); it != Entries.end(); ++it) { File.setName(myDir.absFilePath(*it)); Stream << Q_UINT32(CODE_FILE); if(insertFile(*it, File, Stream) < 0) return -1; } // Put all subdirectories into the package. Entries = myDir.entryList("*", QDir::Dirs, QDir::Name); Entries.pop_front(); // delete "." from list Entries.pop_front(); // delete ".." from list for(it = Entries.begin(); it != Entries.end(); ++it) { Stream << Q_UINT32(CODE_DIR) << (*it).latin1(); if(insertDirectory(myDir.absPath()+QDir::separator()+(*it), Stream) < 0) return -1; Stream << Q_UINT32(CODE_DIR_END) << Q_UINT32(0); } return 0; }
Marker* distribute(File* hw, Marker* markers) { double sumRatio; int numHWs; int numHWsParRatio; int numMarkHWs; Marker* it; Marker* tmp; Marker* result; int i; int r; sumRatio = 0; for (it = markers; it; it = it->next) { sumRatio += it->ratio; } numHWs = numFiles(hw); numHWsParRatio = (int)(numHWs / sumRatio + EPSILON); for (it = markers; it; it = it->next) { numMarkHWs = (int)(numHWsParRatio * it->ratio + EPSILON); for (int i = 0; i < numMarkHWs; ++i) { it->files = insertFile(it->files, removeFrontFile(&hw)); } } result = NULL; for (i = numMarkers(markers); hw; --i) { r = rand() % i; tmp = removeMarker(&markers, r); tmp->files = insertFile(tmp->files, removeFrontFile(&hw)); result = insertMarker(result, tmp); } while (markers) { result = insertMarker(result, removeMarker(&markers, 0)); } return result; }
int main() { int choice; char ans = 'y'; char fname[SIZE]; struct linknode *hashTable[TABLESIZE]; initializeHashTable(hashTable); while(ans == 'y') { printf("\n1. Create file\n"); printf("2. Delete File\n"); printf("3. Search File\n"); printf("4. Display Table\n"); printf("5. Exit\n"); printf("6. Write to disk\n"); printf("7. Read from disk\n"); printf("\nEnter choice: "); scanf("%d", &choice); switch(choice) { case 1: printf("Enter file name: "); scanf("%s", fname); insertFile(fname, hashTable); break; case 2: printf("Enter file name: "); scanf("%s", fname); deleteFile(fname, hashTable); break; case 3: printf("Enter file name: "); scanf("%s", fname); searchFile(fname, hashTable); break; case 4: displayTable(hashTable); break; case 5: exit(0); case 6: writeToDisk(hashTable); break; case 7: readFromDisk(hashTable); break; } } return (0); }
//--------------------------------------------------------------------- // create a remote folder bool Server::cmdMkDir(bstring const & remotePath) { bstring cmd = bstring(TEXT("mkdir \"")) + remotePath + TEXT("\""); if (!doCommand(cmd)) return false; // fake update the directory insertFile(remotePath, 0, 0, 0, 'd'); return true; }
static int insertMemberReference(sqlite3 *db, const char*src, const char*dst, const char *file, int line, int column) { int id_file = insertFile(db,file); bindTextParameter(i_s_xrefs,":src",src); bindTextParameter(i_s_xrefs,":dst",dst); bindIntParameter(i_s_xrefs,":id_file",id_file); bindIntParameter(i_s_xrefs,":line",line); bindIntParameter(i_s_xrefs,":column",column); return step(db,i_s_xrefs); }
int main(int argc, const char** argv){ ndb_init(); const char* _tabname = NULL; int _help = 0; struct getargs args[] = { { "usage", '?', arg_flag, &_help, "Print help", "" } }; int num_args = sizeof(args) / sizeof(args[0]); int optind = 0; char desc[] = "tabname\n"\ "This program will bulk copy data from a file to a table in Ndb.\n"; if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL || _help) { arg_printusage(args, num_args, argv[0], desc); return NDBT_ProgramExit(NDBT_WRONGARGS); } _tabname = argv[optind]; ndbout << "Tablename: " << _tabname << endl; // Connect to Ndb Ndb MyNdb( "TEST_DB" ); if(MyNdb.init() != 0){ ERR(MyNdb.getNdbError()); return NDBT_ProgramExit(NDBT_FAILED); } // Connect to Ndb and wait for it to become ready while(MyNdb.waitUntilReady() != 0) ndbout << "Waiting for ndb to become ready..." << endl; // Check if table exists in db const NdbDictionary::Table* pTab = MyNdb.getDictionary()->getTable(_tabname); if(pTab == NULL){ ndbout << " Table " << _tabname << " does not exist!" << endl; return NDBT_ProgramExit(NDBT_WRONGARGS); } char buf[255]; BaseString::snprintf(buf, sizeof(buf), "%s.data", (const char*)_tabname); if (insertFile(&MyNdb, pTab, buf) != 0){ return NDBT_ProgramExit(NDBT_FAILED); } return NDBT_ProgramExit(NDBT_OK); }
// --------------------------------------------------------------- int PackageDialog::insertLibraries(QDataStream& Stream) { QFile File; QDir myDir(QucsSettings.QucsHomeDir.absPath() + QDir::separator() + "user_lib"); QStringList Entries = myDir.entryList("*", QDir::Files, QDir::Name); QStringList::iterator it; for(it = Entries.begin(); it != Entries.end(); ++it) { File.setName(myDir.absFilePath(*it)); Stream << Q_UINT32(CODE_LIBRARY); if(insertFile(*it, File, Stream) < 0) return -1; } return 0; }
le32 LinnCreate::createInode(char *inputFile, struct stat *st) { LinnGroup *group; LinnInode *inode; BitArray inodeMap(super->inodesPerGroup); u32 gn, in; /* Loop all available LinnGroups. */ for (gn = 0; gn < LINN_GROUP_COUNT(super); gn++) { /* Point to the correct LinnGroup. */ group = BLOCKPTR(LinnGroup, super->groupsTable) + gn; /* Does it have any free inodes? */ if (!group->freeInodesCount) { group = ZERO; continue; } else break; } /* Did we find an appropriate group? */ if (!group) { printf("%s: no free inode available for `%s'\n", prog, inputFile); exit(EXIT_FAILURE); } /* Find an empty inode number. */ inodeMap.setArray(BLOCKPTR(u8, group->inodeMap), super->inodesPerGroup); in = inodeMap.setNext(); /* Instantiate the inode. */ inode = createInode(in, FILETYPE_FROM_ST(st), FILEMODE_FROM_ST(st), st->st_uid, st->st_gid); /* Insert file contents. */ if (S_ISREG(st->st_mode)) { insertFile(inputFile, inode, st); } /* Debug out. */ if (verbose) { printf("%s inode=%u size=%u\n", inputFile, in, inode->size); } return in; }
//--------------------------------------------------------------------- // put a local file --> remote bool Server::cmdPut(bstring const & localName, bstring const & remotePath, bool exists) { DBGPRINT(("put '%s' '%s' %b\r\n", localName.c_str(), remotePath.c_str(), exists)); bstring cmd = bstring(exists ? TEXT("reput \"") : TEXT("put \"")) + localName + TEXT("\" \"") + remotePath + TEXT("\""); if (!doCommand(cmd)) return false; FILETIME ft; HANDLE hFile = CreateFile(localName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile == (HANDLE)HFILE_ERROR) return true; // copy succeeded GetFileTime(hFile, 0, 0, &ft); long fsHigh = 0; long fsLow = SetFilePointer(hFile, 0, &fsHigh, FILE_END); CloseHandle(hFile); bstring chmod = TEXT("----"); if (defChMod.length() > 0 || exeChMod.length() > 0) { chmod = defChMod; size_t ldot = remotePath.find_last_of('.'); if (ldot != (size_t)-1) { bstring x = remotePath.substr(ldot); std::map<bstring, bstring>::iterator i = exeExtensions.find(x); if (i != exeExtensions.end()) chmod = exeChMod; } if (chmod.length() > 0) { cmd = bstring(TEXT("chmod ")) + chmod + TEXT(" \"") + remotePath + TEXT("\""); doCommand(cmd); } } // fake update the directory insertFile(remotePath, &ft, fsLow, fsHigh, '-', chmod); // we cannot set the file time if (disableMtime) return true; // if setting the mtime failes, do not try it again if (!this->cmdMtime(remotePath, &ft)) disableMtime = true; // put already succeeded. return true; }
void Test30() { BCPWriter bcp("writetest.bcp"); uint id = bcp.createFile("Adrien", 6); uint id2 = bcp.createFile("^('o')>", 7); char* txt = "This fabulous text file will be compressed to not waste some precious space in the BCP file. I will be unimpressed if it won't."; char* txt2 = "Repeat repeat repeat repeat repeat repeat again and again and again and repeat again and again and repeat again."; uint id3 = bcp.createFile(txt, strlen(txt)); uint id4 = bcp.createFile(txt2, strlen(txt2)); bcp.root.insertFile(id, "author.txt"); auto fd = bcp.root.addDir("Folder"); fd->insertFile(id2, "cool.txt"); bcp.root.insertFile(id3, "compressed.txt"); bcp.root.insertFile(id4, "repeat.txt"); bcp.finalize(); }
void cadastrar(Hashtable *table) { Jogador player; Chave key; readData(&player); strcpy(key.pk, player.pk); key.rrn = (strlen(ARQUIVO) / TAM_REGISTRO); if(buscaLista(table, key)) { printf(ERRO_PK_REPETIDA, key.pk); } else { if(insereLista(table, key)) insertFile(player, key.rrn); printf(REGISTRO_INSERIDO, key.pk); } }
void buildFile(DataArchive& a, const char* sPath, WIN32_FIND_DATA& find) { if (find.cFileName[0] == '.') { } else if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { char subdir[256]; if (sPath && *sPath) sprintf(subdir, "%s/%s", sPath, find.cFileName); else sprintf(subdir, "%s", find.cFileName); build(a, subdir); } else { insertFile(a, sPath, &find); } }
BSONObj GridFS::storeFile( const char* data , size_t length , const string& remoteName , const string& contentType) { char const * const end = data + length; OID id; id.init(); BSONObj idObj = BSON("_id" << id); int chunkNumber = 0; while (data < end) { int chunkLen = MIN(_chunkSize, (unsigned)(end-data)); GridFSChunk c(idObj, chunkNumber, data, chunkLen); _client.insert( _chunksNS.c_str() , c._data ); chunkNumber++; data += chunkLen; } return insertFile(remoteName, id, length, contentType); }
BSONObj GridFS::storeFile( const string& fileName , const string& remoteName , const string& contentType) { uassert( 10012 , "file doesn't exist" , fileName == "-" || boost::filesystem::exists( fileName ) ); FILE* fd; if (fileName == "-") fd = stdin; else fd = fopen( fileName.c_str() , "rb" ); uassert( 10013 , "error opening file", fd); OID id; id.init(); BSONObj idObj = BSON("_id" << id); int chunkNumber = 0; gridfs_offset length = 0; while (!feof(fd)) { //boost::scoped_array<char>buf (new char[_chunkSize+1]); char * buf = new char[_chunkSize+1]; char* bufPos = buf;//.get(); unsigned int chunkLen = 0; // how much in the chunk now while(chunkLen != _chunkSize && !feof(fd)) { int readLen = fread(bufPos, 1, _chunkSize - chunkLen, fd); chunkLen += readLen; bufPos += readLen; assert(chunkLen <= _chunkSize); } GridFSChunk c(idObj, chunkNumber, buf, chunkLen); _client.insert( _chunksNS.c_str() , c._data ); length += chunkLen; chunkNumber++; delete[] buf; } if (fd != stdin) fclose( fd ); return insertFile((remoteName.empty() ? fileName : remoteName), id, length, contentType); }
BSONObj GridFS::storeFile( const string& fileName , const string& remoteName , const string& contentType){ uassert( "file doesn't exist" , fileName == "-" || boost::filesystem::exists( fileName ) ); FILE* fd; if (fileName == "-") fd = stdin; else fd = fopen( fileName.c_str() , "rb" ); uassert("error opening file", fd); OID id; id.init(); BSONObj idObj = BSON("_id" << id); int chunkNumber = 0; gridfs_offset length = 0; while (!feof(fd)){ boost::scoped_array<char>buf (new char[DEFAULT_CHUNK_SIZE]); char* bufPos = buf.get(); unsigned int chunkLen = 0; // how much in the chunk now while(chunkLen != DEFAULT_CHUNK_SIZE && !feof(fd)){ int readLen = fread(bufPos, 1, DEFAULT_CHUNK_SIZE - chunkLen, fd); chunkLen += readLen; bufPos += readLen; assert(chunkLen <= DEFAULT_CHUNK_SIZE); } Chunk c(idObj, chunkNumber, buf.get(), chunkLen); _client.insert( _chunksNS.c_str() , c._data ); length += chunkLen; chunkNumber++; } if (fd != stdin) fclose( fd ); massert("large files not yet implemented", length <= 0xffffffff); return insertFile((remoteName.empty() ? fileName : remoteName), id, length, contentType); }
//--------------------------------------------------------------------- // move a remote file to a remote file bool Server::cmdMove(bstring const & oldRemotePath, bstring const & newRemotePath) { bstring cmd = bstring(TEXT("mv \"")) + oldRemotePath + TEXT("\" \"") + newRemotePath + TEXT("\""); if (!doCommand(cmd)) return false; fxp_name * fn = removeFile(oldRemotePath); if (fn) { FILETIME ft; UnixTimeToFileTime(fn->attrs.mtime, &ft); insertFile(newRemotePath, &ft, fn->attrs.size.lo, fn->attrs.size.hi, fn->longname[0]); freeFn(fn); } else { bstring path; splitPath(path, newRemotePath); invalidateDirContent(path); } return true; }
BSONObj GridFS::storeFile( const char* data , size_t length , const string& remoteName , const string& contentType){ massert("large files not yet implemented", length <= 0xffffffff); char const * const end = data + length; OID id; id.init(); BSONObj idObj = BSON("_id" << id); int chunkNumber = 0; while (data < end){ int chunkLen = MIN(DEFAULT_CHUNK_SIZE, end-data); Chunk c(idObj, chunkNumber, data, chunkLen); _client.insert( _chunksNS.c_str() , c._data ); chunkNumber++; data += chunkLen; } return insertFile(remoteName, id, length, contentType); }
void readFromDisk(struct linknode **hashTable) { FILE *readfiles; int i = 0, count = 0; struct linknode *temp; char file[SIZE]; readfiles = fopen("./hashtable.bin", "rb"); if(!readfiles) { printf("Error: Unable to open file.."); } fread(&count, sizeof(int), 1, readfiles); while(i != count) { fread(file, SIZE, 1, readfiles); insertFile(file, hashTable); i++; } fclose(readfiles); }
void buildFile(DataArchive& a, const char* sPath, WIN32_FIND_DATA& find) { if (find.cFileName[0] == '.') { } else if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { char subdir[256]; std::string sTemp; if (sPath && *sPath) { sTemp = sPath; sTemp += '/'; WideCharToMultiByte(CP_ACP,0,find.cFileName,-1, subdir,260, NULL, NULL); sTemp += subdir; strcpy(subdir, sTemp.c_str()); } else WideCharToMultiByte(CP_ACP,0,find.cFileName,-1, subdir,256, NULL, NULL); build(a, subdir); } else { insertFile(a, sPath, &find); } }
static void generateSqlite3ForMember(sqlite3*db,MemberDef *md,Definition *def) { // + declaration/definition arg lists // + reimplements // + reimplementedBy // + exceptions // + const/volatile specifiers // - examples // + source definition // + source references // + source referenced by // - body code // + template arguments // (templateArguments(), definitionTemplateParameterLists()) // - call graph // enum values are written as part of the enum if (md->memberType()==MemberType_EnumValue) return; if (md->isHidden()) return; //if (md->name().at(0)=='@') return; // anonymous member // group members are only visible in their group //if (def->definitionType()!=Definition::TypeGroup && md->getGroupDef()) return; QCString memType; #if 0 // member idx = sqlite3_bind_parameter_index(stmt, ":refid"); sqlite3_bind_text(stmt, idx, memberOutputFileBase(md).data(),-1,SQLITE_TRANSIENT); idx = sqlite3_bind_parameter_index(stmt,":kind"); sqlite3_bind_int(stmt, idx, md->memberType()); idx = sqlite3_bind_parameter_index(stmt, ":name"); sqlite3_bind_text(stmt, idx, md->name().data(),-1,SQLITE_TRANSIENT); #endif // memberdef bindTextParameter(i_s_memberdef,":refid",md->anchor()); bindIntParameter(i_s_memberdef,":kind",md->memberType()); bindIntParameter(i_s_memberdef,":prot",md->protection()); bindIntParameter(i_s_memberdef,":static",md->isStatic()); bool isFunc=FALSE; switch (md->memberType()) { case MemberType_Function: // fall through case MemberType_Signal: // fall through case MemberType_Friend: // fall through case MemberType_DCOP: // fall through case MemberType_Slot: isFunc=TRUE; break; default: break; } if (isFunc) { LockingPtr<ArgumentList> al = md->argumentList(); if (al!=0 && al->constSpecifier) { bindIntParameter(i_s_memberdef,":const",al->constSpecifier); } bindIntParameter(i_s_memberdef,":explicit",md->isExplicit()); bindIntParameter(i_s_memberdef,":inline",md->isInline()); bindIntParameter(i_s_memberdef,":final",md->isFinal()); bindIntParameter(i_s_memberdef,":sealed",md->isSealed()); bindIntParameter(i_s_memberdef,":new",md->isNew()); bindIntParameter(i_s_memberdef,":optional",md->isOptional()); bindIntParameter(i_s_memberdef,":required",md->isRequired()); bindIntParameter(i_s_memberdef,":virt",md->virtualness()); } // place in the arguments and linkify the arguments if (md->memberType() == MemberType_Variable) { bindIntParameter(i_s_memberdef,":mutable",md->isMutable()); bindIntParameter(i_s_memberdef,":initonly",md->isInitonly()); } else if (md->memberType() == MemberType_Property) { bindIntParameter(i_s_memberdef,":readable",md->isReadable()); bindIntParameter(i_s_memberdef,":writable",md->isWritable()); bindIntParameter(i_s_memberdef,":gettable",md->isGettable()); bindIntParameter(i_s_memberdef,":settable",md->isSettable()); if (md->isAssign() || md->isCopy() || md->isRetain()) { int accessor = md->isAssign() ? md->isAssign() : (md->isCopy() ? md->isCopy() : md->isRetain()) ; bindIntParameter(i_s_memberdef,":accessor",accessor); } } else if (md->memberType() == MemberType_Event) { bindIntParameter(i_s_memberdef,":addable",md->isAddable()); bindIntParameter(i_s_memberdef,":removable",md->isRemovable()); bindIntParameter(i_s_memberdef,":raisable",md->isRaisable()); } if (md->memberType()!=MemberType_Define && md->memberType()!=MemberType_Enumeration ) { QCString typeStr = md->typeString(); stripQualifiers(typeStr); StringList l; linkifyText(TextGeneratorSqlite3Impl(l),def,md->getBodyDef(),md,typeStr); if (typeStr.data()) { bindTextParameter(i_s_memberdef,":type",typeStr); } if (md->definition()) { bindTextParameter(i_s_memberdef,":definition",md->definition()); } if (md->argsString()) { bindTextParameter(i_s_memberdef,":argsstring",md->argsString()); } } bindTextParameter(i_s_memberdef,":name",md->name()); if (md->memberType() == MemberType_Property) { if (md->isReadable()) { DBG_CTX(("<read>\n")); } if (md->isWritable()) { DBG_CTX(("<write>\n")); } } #if 0 if (md->memberType()==MemberType_Variable && md->bitfieldString()) { QCString bitfield = md->bitfieldString(); if (bitfield.at(0)==':') bitfield=bitfield.mid(1); t << " <bitfield>" << bitfield << "</bitfield>" << endl; } MemberDef *rmd = md->reimplements(); if (rmd) { t << " <reimplements refid=\"" << memberOutputFileBase(rmd) << "_1" << rmd->anchor() << "\">" << convertToXML(rmd->name()) << "</reimplements>" << endl; } LockingPtr<MemberList> rbml = md->reimplementedBy(); if (rbml!=0) { MemberListIterator mli(*rbml); for (mli.toFirst();(rmd=mli.current());++mli) { t << " <reimplementedby refid=\"" << memberOutputFileBase(rmd) << "_1" << rmd->anchor() << "\">" << convertToXML(rmd->name()) << "</reimplementedby>" << endl; } } #endif if (isFunc) //function { LockingPtr<ArgumentList> declAl = md->declArgumentList(); LockingPtr<ArgumentList> defAl = md->argumentList(); if (declAl!=0 && declAl->count()>0) { ArgumentListIterator declAli(*declAl); ArgumentListIterator defAli(*defAl); Argument *a; for (declAli.toFirst();(a=declAli.current());++declAli) { Argument *defArg = defAli.current(); DBG_CTX(("<param>\n")); if (!a->attrib.isEmpty()) { DBG_CTX(("<attributes>:%s\n",a->attrib.data())); } if (!a->type.isEmpty()) { StringList l; linkifyText(TextGeneratorSqlite3Impl(l),def,md->getBodyDef(),md,a->type); QCString *s=l.first(); while (s) { insertMemberReference(db,md->anchor().data(),s->data(),def->getDefFileName().data(),md->getDefLine(),1); s=l.next(); } } if (!a->name.isEmpty()) { DBG_CTX(("<declname>%s\n",a->name.data())); } if (defArg && !defArg->name.isEmpty() && defArg->name!=a->name) { DBG_CTX(("<defname>%s\n",defArg->name.data())); } if (!a->array.isEmpty()) { DBG_CTX(("<array>%s",a->array.data())); } if (!a->defval.isEmpty()) { StringList l; linkifyText(TextGeneratorSqlite3Impl(l),def,md->getBodyDef(),md,a->defval); } if (defArg) ++defAli; } } } else if (md->memberType()==MemberType_Define && md->argsString()) // define { if (md->argumentList()->count()==0) // special case for "foo()" to // disguish it from "foo". { DBG_CTX(("no params\n")); } else { ArgumentListIterator ali(*md->argumentList()); Argument *a; for (ali.toFirst();(a=ali.current());++ali) { DBG_CTX(("<param><defname>%s\n",a->type.data())); } } } // Extract references from initializer // avoid that extremely large tables are written to the output. // todo: it's better to adhere to MAX_INITIALIZER_LINES. // drm_mod_register_buffer, if (!md->initializer().isEmpty() && md->initializer().length()<2000) { StringList l; linkifyText(TextGeneratorSqlite3Impl(l),def,md->getBodyDef(),md,md->initializer()); QCString *s=l.first(); while (s) { DBG_CTX(("initializer:%s %s %s %d\n", md->anchor().data(), s->data(), md->getBodyDef()->getDefFileName().data(), md->getStartBodyLine())); insertMemberReference(db,md->anchor().data(),s->data(),md->getBodyDef()->getDefFileName().data(),md->getStartBodyLine(),1); s=l.next(); } } #if 0 if (md->excpString()) { linkifyText(TextGeneratorXMLImpl(t),def,md->getBodyDef(),md,md->excpString()); } #endif if ( md->getScopeString() ) { bindTextParameter(i_s_memberdef,":scope",md->getScopeString()); } // File location if (md->getDefLine() != -1) { int id_file = insertFile(db,md->getDefFileName()); if (id_file!=-1) { bindIntParameter(i_s_memberdef,":id_file",id_file); bindIntParameter(i_s_memberdef,":line",md->getDefLine()); bindIntParameter(i_s_memberdef,":column",md->getDefColumn()); if (md->getStartBodyLine()!=-1) { int id_bfile = insertFile(db,md->getBodyDef()->absFilePath()); if (id_bfile == -1) exit(-1); bindIntParameter(i_s_memberdef,":id_ibfile",id_bfile); bindIntParameter(i_s_memberdef,":bline",md->getStartBodyLine()); // XXX implement getStartBodyColumn bindIntParameter(i_s_memberdef,":bcolumn",1); } } } step(db,i_s_memberdef); /*int id_src =*/ sqlite3_last_insert_rowid(db); // + cross-references // The cross-references in initializers only work when both the src and dst // are defined. LockingPtr<MemberSDict> mdict = md->getReferencesMembers(); // references if (mdict!=0) { MemberSDict::IteratorDict mdi(*mdict); MemberDef *rmd; for (mdi.toFirst();(rmd=mdi.current());++mdi) { insertMemberReference(db,md,rmd,mdi.currentKey()); } } mdict = md->getReferencedByMembers(); // referencedby if (mdict!=0) { MemberSDict::IteratorDict mdi(*mdict); MemberDef *rmd; for (mdi.toFirst();(rmd=mdi.current());++mdi) { insertMemberReference(db,rmd,md,mdi.currentKey()); } } }
static void generateSqlite3ForClass(sqlite3 *db, ClassDef *cd) { // + brief description // + detailed description // + template argument list(s) // - include file // + member groups // + inheritance diagram // + list of direct super classes // + list of direct sub classes // + list of inner classes // + collaboration diagram // + list of all members // + user defined member sections // + standard member sections // + detailed member documentation // - examples using the class if (cd->isReference()) return; // skip external references. if (cd->isHidden()) return; // skip hidden classes. if (cd->name().find('@')!=-1) return; // skip anonymous compounds. if (cd->templateMaster()!=0) return; // skip generated template instances. msg("Generating Sqlite3 output for class %s\n",cd->name().data()); //int idx,rc; //sqlite3_stmt *stmt ; // + compounddef //stmt = i_s_compounddef; bindTextParameter(i_s_compounddef,":name",cd->name()); bindTextParameter(i_s_compounddef,":kind",cd->compoundTypeString()); bindIntParameter(i_s_compounddef,":prot",cd->protection()); bindTextParameter(i_s_compounddef,":refid",cd->getOutputFileBase()); int id_file = insertFile(db,cd->getDefFileName().data()); bindIntParameter(i_s_compounddef,":id_file",id_file); bindIntParameter(i_s_compounddef,":line",cd->getDefLine()); bindIntParameter(i_s_compounddef,":column",cd->getDefColumn()); step(db,i_s_compounddef); sqlite3_int64 id_compound=0 ; id_compound = sqlite3_last_insert_rowid(db); // + basecompoundref if (cd->baseClasses()) { BaseClassListIterator bcli(*cd->baseClasses()); BaseClassDef *bcd; for (bcli.toFirst();(bcd=bcli.current());++bcli) { bindTextParameter(i_s_basecompoundref,":refid",bcd->classDef->getOutputFileBase()); bindIntParameter(i_s_basecompoundref,":prot",bcd->prot); bindIntParameter(i_s_basecompoundref,":virt",bcd->virt); if (!bcd->templSpecifiers.isEmpty()) { bindTextParameter(i_s_basecompoundref,":base",insertTemplateSpecifierInScope(bcd->classDef->name(),bcd->templSpecifiers)); } else { bindTextParameter(i_s_basecompoundref,":base",bcd->classDef->displayName()); } bindTextParameter(i_s_basecompoundref,":derived",cd->displayName()); step(db,i_s_basecompoundref); } } // + derivedcompoundref if (cd->subClasses()) { BaseClassListIterator bcli(*cd->subClasses()); BaseClassDef *bcd; for (bcli.toFirst();(bcd=bcli.current());++bcli) { bindTextParameter(i_s_derivedcompoundref,":base",cd->displayName()); bindTextParameter(i_s_derivedcompoundref,":dervied",bcd->classDef->displayName()); bindTextParameter(i_s_derivedcompoundref,":refid",bcd->classDef->getOutputFileBase()); bindIntParameter(i_s_derivedcompoundref,":prot",bcd->prot); bindIntParameter(i_s_derivedcompoundref,":virt",bcd->virt); step(db,i_s_derivedcompoundref); } } /////////////////////////////////////////////////////////////////// // INCLUDEINFO IncludeInfo *ii=cd->includeInfo(); if (ii) { QCString nm = ii->includeName; if (nm.isEmpty() && ii->fileDef) nm = ii->fileDef->docName(); if (!nm.isEmpty()) { bindTextParameter(c_s_includes,":refid",ii->fileDef->getOutputFileBase()); bindIntParameter(c_s_includes,":local",ii->local); bindTextParameter(c_s_includes,":name",nm); int count=step(db,c_s_includes,TRUE); if ( count==0 ) { bindTextParameter(i_s_includes,":refid",ii->fileDef->getOutputFileBase()); bindIntParameter(i_s_includes,":local",ii->local); bindTextParameter(i_s_includes,":name",nm); step(db,i_s_includes); } } } /////////////////////////////////////////////////////////////////// writeInnerClasses(db,cd->getClassSDict()); writeTemplateList(db,cd); if (cd->getMemberGroupSDict()) { MemberGroupSDict::Iterator mgli(*cd->getMemberGroupSDict()); MemberGroup *mg; for (;(mg=mgli.current());++mgli) { generateSqlite3Section(db,cd,mg->members(),"user-defined",mg->header(), mg->documentation()); } } QListIterator<MemberList> mli(cd->getMemberLists()); MemberList *ml; for (mli.toFirst();(ml=mli.current());++mli) { if ((ml->listType()&MemberListType_detailedLists)==0) { generateSqlite3Section(db,cd,ml,"user-defined");//g_xmlSectionMapper.find(ml->listType())); } } }
int main(int iArgC, char *cArgV[]) { #ifdef __GLIBCXX__ // Set a better exception handler std::set_terminate(__gnu_cxx::__verbose_terminate_handler); #endif // Disable stdin/printf/etc. sync for a speed boost std::ios_base::sync_with_stdio(false); // Declare the supported options. po::options_description poActions("Actions"); poActions.add_options() ("list,l", "list files in the archive") ("extract-all,X", "extract all files in the archive") ("extract,x", po::value<std::string>(), "extract a specific file") ("add,a", po::value<std::string>(), "add a file at the end of the archive") ("insert,i", po::value<std::string>(), "add a file at a specific point in the archive") ("metadata,m", "list archive attributes/metadata") ("set-metadata,e", po::value<std::string>(), "change archive attributes/metadata") ("overwrite,o", po::value<std::string>(), "replace a file in the archive with new data") ("rename,r", po::value<std::string>(), "rename a file inside the archive") ("delete,d", po::value<std::string>(), "remove a file from the archive") ("uncompressed-size,z", po::value<int>(), "[with -u only] specify the uncompressed size to use with -i") ; po::options_description poOptions("Options"); poOptions.add_options() ("type,t", po::value<std::string>(), "specify the archive type (default is autodetect)") ("list-types", "list available formats that can be passed to --type") ("filetype,y", po::value<std::string>(), "specify the file type when inserting (default is generic file)") ("attribute,b", po::value<std::string>(), "specify the file attributes when inserting (optional)") ("unfiltered,u", "do not filter files (no encrypt/decrypt/compress/decompress)") ("script,s", "format output suitable for script parsing") ("force,f", "force open even if the archive is not in the given format") ("create,c", "create a new archive file instead of opening an existing one") ; po::options_description poHidden("Hidden parameters"); poHidden.add_options() ("archive", "archive file to manipulate") ("help", "produce help message") ; po::options_description poVisible(""); poVisible.add(poActions).add(poOptions); po::options_description poComplete("Parameters"); poComplete.add(poActions).add(poOptions).add(poHidden); po::variables_map mpArgs; std::string strFilename; std::string strType; bool bScript = false; // show output suitable for script parsing? bool bForceOpen = false; // open anyway even if archive not in given format? bool bCreate = false; // create a new archive? try { po::parsed_options pa = po::parse_command_line(iArgC, cArgV, poComplete); // Parse the global command line options for (std::vector<po::option>::iterator i = pa.options.begin(); i != pa.options.end(); i++) { if (i->string_key.empty()) { // If we've already got an archive filename, complain that a second one // was given (probably a typo.) if (!strFilename.empty()) { std::cerr << "Error: unexpected extra parameter (multiple archive " "filenames given?!)" << std::endl; return RET_BADARGS; } assert(i->value.size() > 0); // can't have no values with no name! strFilename = i->value[0]; } else if (i->string_key.compare("help") == 0) { std::cout << "Copyright (C) 2010-2016 Adam Nielsen <*****@*****.**>\n" "This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to change and redistribute it under certain conditions;\n" "see <http://www.gnu.org/licenses/> for details.\n" "\n" "Utility to manipulate archive files used by games to store data files.\n" "Build date " __DATE__ " " __TIME__ << "\n" "\n" "Usage: gamearch <archive> <action> [action...]\n" << poVisible << "\n" << std::endl; return RET_OK; } else if ( (i->string_key.compare("list-types") == 0) ) { for (const auto& i : ga::ArchiveManager::formats()) { std::string code = i->code(); std::cout << code; int len = code.length(); if (len < 20) std::cout << std::string(20 - len, ' '); std::cout << ' ' << i->friendlyName() << '\n'; } return RET_OK; } else if ( (i->string_key.compare("t") == 0) || (i->string_key.compare("type") == 0) ) { if (i->value.size() == 0) { std::cerr << PROGNAME ": --type (-t) requires a parameter. Use " "--list-types to see valid values." << std::endl; return RET_BADARGS; } strType = i->value[0]; } else if ( (i->string_key.compare("s") == 0) || (i->string_key.compare("script") == 0) ) { bScript = true; } else if ( (i->string_key.compare("f") == 0) || (i->string_key.compare("force") == 0) ) { bForceOpen = true; } else if ( (i->string_key.compare("u") == 0) || (i->string_key.compare("unfiltered") == 0) ) { bUseFilters = false; } else if ( (i->string_key.compare("c") == 0) || (i->string_key.compare("create") == 0) ) { bCreate = true; } } if (strFilename.empty()) { std::cerr << "Error: no game archive filename given" << std::endl; return RET_BADARGS; } std::unique_ptr<stream::file> psArchive; if (bCreate && strType.empty()) { std::cerr << "Error: You must specify the --type of archive to create" << std::endl; return RET_BADARGS; } std::cout << (bCreate ? "Creating " : "Opening ") << strFilename << " as type " << (strType.empty() ? "<autodetect>" : strType) << std::endl; try { psArchive = std::make_unique<stream::file>(strFilename, bCreate); } catch (const stream::open_error& e) { std::cerr << "Error " << (bCreate ? "creating" : "opening") << " archive file " << strFilename << ": " << e.what() << std::endl; return RET_SHOWSTOPPER; } // Get the format handler for this file format ga::ArchiveManager::handler_t pArchType; if (strType.empty()) { // Need to autodetect the file format. for (const auto& i : ga::ArchiveManager::formats()) { ga::ArchiveType::Certainty cert = i->isInstance(*psArchive); switch (cert) { case ga::ArchiveType::Certainty::DefinitelyNo: // Don't print anything (TODO: Maybe unless verbose?) break; case ga::ArchiveType::Certainty::Unsure: std::cout << "File could be a " << i->friendlyName() << " [" << i->code() << "]" << std::endl; // If we haven't found a match already, use this one if (!pArchType) pArchType = i; break; case ga::ArchiveType::Certainty::PossiblyYes: std::cout << "File is likely to be a " << i->friendlyName() << " [" << i->code() << "]" << std::endl; // Take this one as it's better than an uncertain match pArchType = i; break; case ga::ArchiveType::Certainty::DefinitelyYes: std::cout << "File is definitely a " << i->friendlyName() << " [" << i->code() << "]" << std::endl; pArchType = i; // Don't bother checking any other formats if we got a 100% match goto finishTesting; } if (cert != ga::ArchiveType::Certainty::DefinitelyNo) { // We got a possible match, see if it requires any suppdata auto suppList = i->getRequiredSupps(*psArchive, strFilename); if (suppList.size() > 0) { // It has suppdata, see if it's present std::cout << " * This format requires supplemental files..." << std::endl; bool bSuppOK = true; for (const auto& s : suppList) { try { stream::file test_presence(s.second, false); } catch (const stream::open_error&) { bSuppOK = false; std::cout << " * Could not find/open " << s.second << ", archive is probably not " << i->code() << std::endl; break; } } if (bSuppOK) { // All supp files opened ok std::cout << " * All supp files present, archive is likely " << i->code() << std::endl; // Set this as the most likely format pArchType = i; } } } } finishTesting: if (!pArchType) { std::cerr << "Unable to automatically determine the file type. Use " "the --type option to manually specify the file format." << std::endl; return RET_BE_MORE_SPECIFIC; } } else { auto pTestType = ga::ArchiveManager::byCode(strType); if (!pTestType) { std::cerr << "Unknown file type given to -t/--type: " << strType << std::endl; return RET_BADARGS; } pArchType = pTestType; } assert(pArchType != NULL); if (!bCreate) { // Check to see if the file is actually in this format if (pArchType->isInstance(*psArchive) == ga::ArchiveType::Certainty::DefinitelyNo) { if (bForceOpen) { std::cerr << "Warning: " << strFilename << " is not a " << pArchType->friendlyName() << ", open forced." << std::endl; } else { std::cerr << "Invalid format: " << strFilename << " is not a " << pArchType->friendlyName() << "\n" << "Use the -f option to try anyway." << std::endl; return RET_BE_MORE_SPECIFIC; } } } // See if the format requires any supplemental files auto suppList = pArchType->getRequiredSupps(*psArchive, strFilename); camoto::SuppData suppData; for (const auto& s : suppList) { try { std::cout << "Opening supplemental file " << s.second << std::endl; auto suppStream = std::make_unique<stream::file>(s.second, false); suppData[s.first] = std::move(suppStream); } catch (const stream::open_error& e) { std::cerr << "Error opening supplemental file " << s.second << ": " << e.what() << std::endl; return RET_SHOWSTOPPER; } } // Open the archive file std::shared_ptr<ga::Archive> pArchive; try { if (bCreate) { pArchive = pArchType->create(std::move(psArchive), suppData); } else { pArchive = pArchType->open(std::move(psArchive), suppData); } assert(pArchive); } catch (const camoto::error& e) { std::cerr << "Error " << (bCreate ? "creating" : "opening") << " archive file: " << e.what() << std::endl; return RET_SHOWSTOPPER; } // File type of inserted files defaults to empty, which means 'generic file' std::string strLastFiletype; // Last attribute value set with -b auto iLastAttr = ga::Archive::File::Attribute::Default; // Last value set with -z stream::len lenReal = 0; // Run through the actions on the command line for (auto& i : pa.options) { if (i.string_key.compare("list") == 0) { listFiles(std::string(), std::string(), *pArchive, bScript); } else if (i.string_key.compare("extract-all") == 0) { extractAll(pArchive, bScript); } else if (i.string_key.compare("metadata") == 0) { listAttributes(pArchive.get(), bScript); } else if (i.string_key.compare("set-metadata") == 0) { std::string strIndex, strValue; if (!split(i.value[0], '=', &strIndex, &strValue)) { std::cerr << PROGNAME ": -e/--set-metadata requires an index and " "a value (e.g. --set-metadata 0=example)" << std::endl; return RET_BADARGS; } unsigned int index = strtoul(strIndex.c_str(), nullptr, 0); setAttribute(pArchive.get(), bScript, index, strValue); } else if (i.string_key.compare("extract") == 0) { std::string strArchFile, strLocalFile; bool bAltDest = split(i.value[0], '=', &strArchFile, &strLocalFile); if (!bAltDest) sanitisePath(strLocalFile); std::cout << " extracting: " << strArchFile; if (strArchFile.compare(strLocalFile)) std::cout << " (into " << strLocalFile << ")"; std::cout << std::flush; try { // Find the file auto destArch = pArchive; ga::Archive::FileHandle id; findFile(&destArch, &id, strArchFile); if (!id) { std::cout << " [failed; file not found]"; iRet = RET_NONCRITICAL_FAILURE; // one or more files failed } else { // Found it, open on disk auto pfsIn = destArch->open(id, bUseFilters); try { auto fsOut = std::make_shared<stream::output_file>(strLocalFile, true); try { stream::copy(*fsOut, *pfsIn); } catch (const stream::error& e) { std::cout << " [failed; read/write error: " << e.what() << "]"; iRet = RET_UNCOMMON_FAILURE; // some files failed, but not in a usual way } } catch (const stream::error&) { std::cout << " [failed; unable to create output file]"; iRet = RET_UNCOMMON_FAILURE; // some files failed, but not in a usual way } } } catch (const stream::error& e) { std::cout << " [failed; " << e.what() << "]"; iRet = RET_UNCOMMON_FAILURE; // some files failed, but not in a usual way } std::cout << std::endl; } else if (i.string_key.compare("delete") == 0) { std::string& strArchFile = i.value[0]; std::cout << " deleting: " << strArchFile << std::flush; try { auto destArch = pArchive; ga::Archive::FileHandle id; findFile(&destArch, &id, strArchFile); if (!id) { std::cout << " [failed; file not found]"; iRet = RET_NONCRITICAL_FAILURE; // one or more files failed } else { destArch->remove(id); } } catch (const stream::error& e) { std::cout << " [failed; " << e.what() << "]"; iRet = RET_UNCOMMON_FAILURE; // some files failed, but not in a usual way } std::cout << std::endl; } else if (i.string_key.compare("insert") == 0) { std::string strSource, strInsertBefore; if (!split(i.value[0], ':', &strSource, &strInsertBefore)) { std::cerr << PROGNAME ": -i/--insert requires a file to insert " "before (parameter should end with \":beforeme.xyz\")\n" "Or use --add instead." << std::endl; return RET_BADARGS; } std::string strArchFile, strLocalFile; bool bAltDest = split(strSource, '=', &strArchFile, &strLocalFile); std::cout << " inserting: " << strArchFile; if (!strLastFiletype.empty()) std::cout << " as type " << strLastFiletype; std::cout << " (before " << strInsertBefore; if (bAltDest) std::cout << ", from " << strLocalFile; std::cout << ")"; if (lenReal != 0) std::cout << ", with uncompressed size " << lenReal; std::cout << std::flush; // Try to find strInsertBefore auto destArch = pArchive; ga::Archive::FileHandle idBeforeThis; findFile(&destArch, &idBeforeThis, strInsertBefore); if (!idBeforeThis) { std::cout << " [failed; could not find " << strInsertBefore << "]"; iRet = RET_NONCRITICAL_FAILURE; // one or more files failed continue; } try { insertFile(destArch, strLocalFile, strArchFile, idBeforeThis, strLastFiletype, iLastAttr, lenReal); } catch (const stream::error& e) { std::cout << " [failed; " << e.what() << "]"; iRet = RET_UNCOMMON_FAILURE; // some files failed, but not in a usual way } std::cout << std::endl; // Remember --filetype/-y } else if (i.string_key.compare("filetype") == 0) { //} else if (i.string_key.compare("y") == 0) { strLastFiletype = i.value[0]; // Remember --attributes/-b } else if (i.string_key.compare("attribute") == 0) { //} else if (i.string_key.compare("b") == 0) { std::string nextAttr = i.value[0]; bool disable = (nextAttr[0] == '-'); if (disable) nextAttr = nextAttr.substr(1); ga::Archive::File::Attribute next; if (nextAttr.compare("empty") == 0) next = ga::Archive::File::Attribute::Vacant; else if (nextAttr.compare("hidden") == 0) next = ga::Archive::File::Attribute::Hidden; else if (nextAttr.compare("compressed") == 0) next = ga::Archive::File::Attribute::Compressed; else if (nextAttr.compare("encrypted") == 0) next = ga::Archive::File::Attribute::Encrypted; else { std::cerr << "Unknown attribute " << nextAttr << ", valid values are: empty hidden compressed encrypted" << std::endl; iRet = RET_UNCOMMON_FAILURE; next = ga::Archive::File::Attribute::Default; } if (next != ga::Archive::File::Attribute::Default) { auto allowed = pArchive->getSupportedAttributes(); if (allowed & next) { if (disable) iLastAttr &= ~next; else iLastAttr |= next; } else { std::cerr << "Warning: Attribute unsupported by archive format, " "ignoring: " << nextAttr << std::endl; } } // Remember --uncompressed-size/-z } else if (i.string_key.compare("uncompressed-size") == 0) { //} else if (i.string_key.compare("z") == 0) { if (bUseFilters) { std::cerr << PROGNAME ": -z/--uncompressed-size only needs to be " "specified when it can't be determined automatically (i.e. when " "-u/--unfiltered is in use.)" << std::endl; return RET_BADARGS; } lenReal = strtoul(i.value[0].c_str(), NULL, 0); // Ignore --type/-t } else if (i.string_key.compare("type") == 0) { } else if (i.string_key.compare("t") == 0) { // Ignore --script/-s } else if (i.string_key.compare("script") == 0) { } else if (i.string_key.compare("s") == 0) { // Ignore --force/-f } else if (i.string_key.compare("force") == 0) { } else if (i.string_key.compare("f") == 0) { } else if ((!i.string_key.empty()) && (i.value.size() > 0)) { // None of the above (single param) options matched, so it's probably // an option with up to two filenames (with an equal-sign as a // separator.) It could also be the --type option, which we'll ignore. std::string& strParam = i.value[0]; std::string strArchFile, strLocalFile; bool bAltDest = split(strParam, '=', &strArchFile, &strLocalFile); if (i.string_key.compare("add") == 0) { std::cout << " adding: " << strArchFile; if (!strLastFiletype.empty()) std::cout << " as type " << strLastFiletype; if (bAltDest) std::cout << " (from " << strLocalFile << ")"; if (lenReal != 0) std::cout << ", with uncompressed size set to " << lenReal; std::cout << std::endl; try { insertFile(pArchive, strLocalFile, strArchFile, nullptr, strLastFiletype, iLastAttr, lenReal); } catch (const stream::error& e) { std::cout << " [failed; " << e.what() << "]"; iRet = RET_UNCOMMON_FAILURE; // some files failed, but not in a usual way } } else if (i.string_key.compare("rename") == 0) { if ((!bAltDest) || (boost::equals(strArchFile, strLocalFile))) { std::cout << "ignoring attempt to rename " << strArchFile << " into the same name" << std::endl; } else { std::cout << " renaming: " << strArchFile << " to " << strLocalFile << std::flush; try { auto destArch = pArchive; ga::Archive::FileHandle id; findFile(&destArch, &id, strArchFile); if (!id) { std::cout << " [failed; file not found inside archive]"; iRet = RET_NONCRITICAL_FAILURE; // one or more files failed } else { destArch->rename(id, strLocalFile); } } catch (const stream::error& e) { std::cout << " [failed; " << e.what() << "]"; iRet = RET_UNCOMMON_FAILURE; // some files failed, but not in a common way } std::cout << std::endl; } } else if (i.string_key.compare("overwrite") == 0) { std::cout << "overwriting: " << strArchFile; if (bAltDest) std::cout << " (from " << strLocalFile << ")"; if (lenReal != 0) std::cout << ", with uncompressed size set to " << lenReal; std::cout << std::flush; try { // Find the file auto destArch = pArchive; ga::Archive::FileHandle id; findFile(&destArch, &id, strArchFile); if (!id) { std::cout << " [failed; file not found inside archive]"; iRet = RET_NONCRITICAL_FAILURE; // one or more files failed } else { // Found it, open replacement file auto sSrc = std::make_shared<stream::input_file>(strLocalFile); stream::len lenSource = sSrc->size(); // Note that we are opening the file into an output_sptr (instead // of an inout_sptr) as this is more efficient. By foregoing read // access to the file, it means a compressed file won't be // decompressed in case we want to read it. Which we don't, // because we're about to completely overwrite it. auto psDest = destArch->open(id, bUseFilters); // Set the size of the stream within the archive, so it exactly // holds the data we want to write. psDest->truncate(lenSource); if (!bUseFilters) { if (lenReal) { pArchive->resize(id, lenSource, lenReal); } else { // Leave the prefiltered/decompressed size unchanged pArchive->resize(id, lenSource, id->realSize); } } psDest->seekp(0, stream::start); stream::copy(*psDest, *sSrc); psDest->flush(); } } catch (const stream::open_error&) { std::cout << " [failed; unable to open replacement file]"; iRet = RET_NONCRITICAL_FAILURE; // one or more files failed } catch (const stream::error& e) { std::cout << " [failed; " << e.what() << "]"; iRet = RET_UNCOMMON_FAILURE; // some files failed, but not in a common way } std::cout << std::endl; } // else it's the archive filename, but we already have that } } // for (all command line elements) pArchive->flush(); } catch (const po::unknown_option& e) { std::cerr << PROGNAME ": " << e.what() << ". Use --help for help." << std::endl; return RET_BADARGS; } catch (const po::invalid_command_line_syntax& e) { std::cerr << PROGNAME ": " << e.what() << ". Use --help for help." << std::endl; return RET_BADARGS; } return iRet; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { EdamProtocol *edam = EdamProtocol::GetInstance(); ui->setupUi(this); pdfCache * pdf = new pdfCache(this); CustomNetworkAccessManager *nm = new CustomNetworkAccessManager(ui->editor->page()->networkAccessManager(), this, pdf); edam->setCNAM(nm); ui->editor->page()->setNetworkAccessManager(nm); Speller::setSettings(new DBSpellSettings(this, ui->editor)); ui->editor->setContextMenuPolicy(Qt::CustomContextMenu); ui->editor->load(QUrl("qrc:///html/noteajax.html")); jsB = new jsBridge(this, pdf); jsB->setWebView(ui->editor); enmlWritter = new enml2(this); connect(ui->editor->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject())); loaded = false; editingEnabled = false; tagsActions = new QActionGroup(this); newTag = new TagLabel(this); newTag->hide(); ui->tagsBar->addWidget(newTag); appIcon = QIcon(":img/hippo64.png"); trayIcon = NULL; bool sysTrayEnabled = sql::readSyncStatus("systemTray", true).toBool(); if (QSystemTrayIcon::isSystemTrayAvailable() && sysTrayEnabled) enableSystemTrayIcon(true); connect(edam, SIGNAL(AuthenticateFailed()), this, SLOT(authentificationFailed())); connect(edam, SIGNAL(syncFinished()), this, SLOT(syncFinished())); connect(edam, SIGNAL(syncStarted(int)), this, SLOT(syncStarted(int))); connect(edam, SIGNAL(noteGuidChanged(QString,QString)), this, SLOT(changeNoteGuid(QString,QString))); connect(ui->notebooks, SIGNAL(itemSelectionChanged()), this, SLOT(switchNotebook())); connect(ui->tags, SIGNAL(itemSelectionChanged()), this, SLOT(switchTag())); connect(ui->tags, SIGNAL(tagAdded(QString,QString)), this, SLOT(addTag(QString,QString))); connect(ui->tags, SIGNAL(tagsUpdated()), this, SLOT(updateTagsToolBar())); connect(ui->tags, SIGNAL(tagsUpdated()), this, SLOT(switchTag())); connect(ui->NotesList, SIGNAL(noteSwitched()), this, SLOT(switchNote())); connect(ui->action_Abaut, SIGNAL(triggered()), this, SLOT(loadAboutInfo())); connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(closeWindow())); connect(ui->actionNew_Note, SIGNAL(triggered()), this, SLOT(newNote())); connect(ui->actionSync, SIGNAL(triggered()), this, SLOT(sync())); connect(ui->noteTitle, SIGNAL(textEdited(QString)), this, SLOT(noteTitleChange(QString))); connect(ui->actionAccount_info, SIGNAL(triggered()), this, SLOT(showUserInfo())); connect(ui->editor->page(), SIGNAL(linkClicked(QUrl)), this, SLOT(openURL(QUrl))); connect(ui->editor->page(), SIGNAL(microFocusChanged()), this, SLOT(updateEditButtonsState())); connect(ui->editor, SIGNAL(selectionChanged()), this, SLOT(updateSelectionButtonsState())); connect(ui->editor->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest))); connect(ui->editor, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(editorContextMenuRequested(QPoint))); connect(ui->editor, SIGNAL(fileInserted(QString)), this, SLOT(insertFile(QString))); connect(ui->notebooks, SIGNAL(noteMoved(QString,QString)), this, SLOT(moveNote(QString,QString))); connect(ui->notebooks, SIGNAL(noteDeleted(QString)), this, SLOT(deleteNote(QString))); connect(ui->notebooks, SIGNAL(noteRestored(QString,QString)), this, SLOT(restoreNote(QString,QString))); connect(ui->NotesList, SIGNAL(noteDeleted(QString)), this, SLOT(deleteNote(QString))); connect(ui->NotesList, SIGNAL(noteRestored(QString)), this, SLOT(restoreNote(QString))); connect(ui->NotesList, SIGNAL(noteCreated()), this, SLOT(newNote())); connect(ui->NotesList, SIGNAL(reloaded()), this, SLOT(updateCurrentNoteName())); connect(ui->editButton, SIGNAL(toggled(bool)), this, SLOT(setEditable(bool))); connect(ui->actionDelete_Note, SIGNAL(triggered()), this, SLOT(deleteNote())); connect(ui->toolBox, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int))); connect(ui->editor->page(), SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(linkHovered(QString,QString,QString))); connect(jsB, SIGNAL(hintMessage(QString,int)), ui->statusbar, SLOT(showMessage(QString,int))); connect(jsB, SIGNAL(noteChanged(QString)), this, SLOT(updateTagsToolBar(QString))); connect(jsB, SIGNAL(activeNoteSelectionChanged(bool)), ui->actionDelete_Note, SLOT(setEnabled(bool))); connect(jsB, SIGNAL(activeNoteSelectionChanged(bool)), ui->editButton, SLOT(setEnabled(bool))); connect(jsB, SIGNAL(editingStarted(bool)), ui->editButton, SLOT(setChecked(bool))); connect(jsB, SIGNAL(titleUpdated(QString,QString)), this, SLOT(updateNoteTitle(QString,QString))); connect(jsB, SIGNAL(conflictAdded(qint64,QString,bool)), this, SLOT(addConflict(qint64,QString,bool))); connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionNote_Info, SLOT(setEnabled(bool))); connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionExport, SLOT(setEnabled(bool))); connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionPrint, SLOT(setEnabled(bool))); connect(ui->editor, SIGNAL(tagUpdated(QString,bool)), this, SLOT(updateTag(QString,bool))); connect(tagsActions, SIGNAL(triggered(QAction*)), this, SLOT(tagClicked(QAction*))); connect(newTag, SIGNAL(tagCreated(QString)), this, SLOT(createTag(QString))); connect(ui->actionKeep_only_this_Version, SIGNAL(triggered()), this, SLOT(keepThisVersion())); connect(ui->actionNote_Info, SIGNAL(triggered()), this, SLOT(showNoteInfo())); connect(ui->actionExport, SIGNAL(triggered()), this, SLOT(exportNote())); connect(ui->actionPrint, SIGNAL(triggered()), this, SLOT(print())); connect(this, SIGNAL(titleChanged(QString,QString)), jsB, SIGNAL(titleChanged(QString,QString))); setWindowIcon(appIcon); setWindowTitle("Hippo Notes"); setTabOrder(ui->noteTitle, ui->editor); ui->notebooks->setSortingEnabled(true); ui->notebooks->sortByColumn(0, Qt::AscendingOrder); ui->editBar->setVisible(false); ui->mainToolBar->addAction(ui->actionNew_Note); ui->mainToolBar->addAction(ui->actionSync); QFontComboBox *font = new QFontComboBox(this); font->setDisabled(true); font->setFontFilters(QFontComboBox::ScalableFonts); font->setEditable(false); connect(this, SIGNAL(editButtonsStateChanged(bool)), font, SLOT(setEnabled(bool))); connect(this, SIGNAL(updateFont(QFont)), font, SLOT(setCurrentFont(QFont))); connect(font, SIGNAL(activated(QString)), this, SLOT(changeFont(QString))); ui->editBar->addWidget(font); QComboBox *fontSize = new QComboBox(this); fontSize->setDisabled(true); fontSize->setEditable(false); for (int i = 1; i <= 7; i++) fontSize->addItem(QString::number(i)); connect(this, SIGNAL(editButtonsStateChanged(bool)), fontSize, SLOT(setEnabled(bool))); connect(this, SIGNAL(updateFontSize(int)), fontSize, SLOT(setCurrentIndex(int))); connect(fontSize, SIGNAL(activated(QString)), this, SLOT(changeFontSize(QString))); ui->editBar->addWidget(fontSize); QAction *boldIco = ui->editor->pageAction(QWebPage::ToggleBold); boldIco->setIcon(QIcon::fromTheme("format-text-bold")); ui->editBar->addAction(boldIco); QAction *italicIco = ui->editor->pageAction(QWebPage::ToggleItalic); italicIco->setIcon(QIcon::fromTheme("format-text-italic")); ui->editBar->addAction(italicIco); QAction *underlineIco = ui->editor->pageAction(QWebPage::ToggleUnderline); underlineIco->setIcon(QIcon::fromTheme("format-text-underline")); ui->editBar->addAction(underlineIco); QAction *strikethroughIco = ui->editor->pageAction(QWebPage::ToggleStrikethrough); strikethroughIco->setIcon(QIcon::fromTheme("format-text-strikethrough")); ui->editBar->addAction(strikethroughIco); ui->editBar->addSeparator(); QAction *undoIco = ui->editor->pageAction(QWebPage::Undo); undoIco->setIcon(QIcon::fromTheme("edit-undo")); undoIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z)); ui->editBar->addAction(undoIco); ui->menu_Edit->addAction(undoIco); QAction *redoIco = ui->editor->pageAction(QWebPage::Redo); redoIco->setIcon(QIcon::fromTheme("edit-redo")); redoIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z)); ui->editBar->addAction(redoIco); ui->menu_Edit->addAction(redoIco); ui->editBar->addSeparator(); QAction *rformatIco = ui->editor->pageAction(QWebPage::RemoveFormat); rformatIco->setIcon(QIcon::fromTheme("edit-clear")); ui->editBar->addAction(rformatIco); ui->editBar->addSeparator(); QAction *leftIco = ui->editor->pageAction(QWebPage::AlignLeft); leftIco->setIcon(QIcon::fromTheme("format-justify-left")); ui->editBar->addAction(leftIco); QAction *centerIco = ui->editor->pageAction(QWebPage::AlignCenter); centerIco->setIcon(QIcon::fromTheme("format-justify-center")); ui->editBar->addAction(centerIco); QAction *rightIco = ui->editor->pageAction(QWebPage::AlignRight); rightIco->setIcon(QIcon::fromTheme("format-justify-right")); ui->editBar->addAction(rightIco); QAction *fillIco = ui->editor->pageAction(QWebPage::AlignJustified); fillIco->setIcon(QIcon::fromTheme("format-justify-fill")); ui->editBar->addAction(fillIco); ui->editBar->addSeparator(); QAction *indentIco = ui->editor->pageAction(QWebPage::Indent); indentIco->setIcon(QIcon::fromTheme("format-indent-more")); ui->editBar->addAction(indentIco); QAction *outdentIco = ui->editor->pageAction(QWebPage::Outdent); outdentIco->setIcon(QIcon::fromTheme("format-indent-less")); ui->editBar->addAction(outdentIco); QAction *superscriptIco = ui->editor->pageAction(QWebPage::ToggleSuperscript); superscriptIco->setIcon(QIcon::fromTheme("format-text-superscript")); ui->editBar->addAction(superscriptIco); QAction *subscriptIco = ui->editor->pageAction(QWebPage::ToggleSubscript); subscriptIco->setIcon(QIcon::fromTheme("format-text-subscript")); ui->editBar->addAction(subscriptIco); QAction *unorderedIco = ui->editor->pageAction(QWebPage::InsertUnorderedList); unorderedIco->setIcon(QIcon::fromTheme("format-list-unordered")); ui->editBar->addAction(unorderedIco); QAction *orderedIco = ui->editor->pageAction(QWebPage::InsertOrderedList); orderedIco->setIcon(QIcon::fromTheme("format-list-ordered")); ui->editBar->addAction(orderedIco); QAction *lineIco = new QAction("Insert horizontal line", this); lineIco->setIcon(QIcon::fromTheme("insert-horizontal-rule")); lineIco->setDisabled(true); connect(this, SIGNAL(editButtonsStateChanged(bool)), lineIco, SLOT(setEnabled(bool))); connect(lineIco, SIGNAL(triggered()), this, SLOT(insertHorizontalLine())); ui->editBar->addAction(lineIco); ui->menu_Edit->addSeparator(); QAction *cutIco = ui->editor->pageAction(QWebPage::Cut); cutIco->setIcon(QIcon::fromTheme("edit-cut")); cutIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); ui->menu_Edit->addAction(cutIco); QAction *copyIco = ui->editor->pageAction(QWebPage::Copy); copyIco->setIcon(QIcon::fromTheme("edit-copy")); copyIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C)); ui->menu_Edit->addAction(copyIco); QAction *pasteIco = ui->editor->pageAction(QWebPage::Paste); pasteIco->setIcon(QIcon::fromTheme("edit-paste")); pasteIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_V)); ui->menu_Edit->addAction(pasteIco); QAction *pasteSpecialIco = ui->editor->pageAction(QWebPage::PasteAndMatchStyle); pasteSpecialIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V)); ui->menu_Edit->addAction(pasteSpecialIco); ui->menu_Edit->addSeparator(); QAction *insertUrlIco = new QAction("Create link", this); insertUrlIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); insertUrlIco->setDisabled(true); insertUrlIco->setIcon(QIcon::fromTheme("insert-link")); connect(this, SIGNAL(selectionButtonsStateChanged(bool)), insertUrlIco, SLOT(setDisabled(bool))); connect(insertUrlIco, SIGNAL(triggered()), this, SLOT(insertUrl())); ui->menu_Edit->addAction(insertUrlIco); QAction *todoIco = new QAction("Insert To-do Checkbox", this); todoIco->setIcon(QIcon::fromTheme("checkbox")); todoIco->setDisabled(true); connect(this, SIGNAL(editButtonsStateChanged(bool)), todoIco, SLOT(setEnabled(bool))); connect(todoIco, SIGNAL(triggered()), jsB, SIGNAL(insertToDo())); ui->menu_Edit->addAction(todoIco); QAction *insertImage = new QAction("Insert Image", this); insertImage->setIcon(QIcon::fromTheme("insert-image")); insertImage->setDisabled(true); connect(this, SIGNAL(editButtonsStateChanged(bool)), insertImage, SLOT(setEnabled(bool))); connect(insertImage, SIGNAL(triggered()), this, SLOT(insertImg())); ui->menu_Edit->addAction(insertImage); QAction *insertFile = new QAction("Insert File", this); insertFile->setDisabled(true); connect(this, SIGNAL(editButtonsStateChanged(bool)), insertFile, SLOT(setEnabled(bool))); connect(insertFile, SIGNAL(triggered()), this, SLOT(insertFile())); ui->menu_Edit->addAction(insertFile); QAction *encryptIco = new QAction("Encrypt Selected Text...", this); encryptIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_X)); encryptIco->setDisabled(true); encryptIco->setIcon(QIcon::fromTheme("document-edit-encrypt")); connect(this, SIGNAL(selectionButtonsStateChanged(bool)), encryptIco, SLOT(setDisabled(bool))); connect(encryptIco, SIGNAL(triggered()), jsB, SIGNAL(encryptText())); ui->menu_Edit->addAction(encryptIco); ui->menu_Edit->addSeparator(); QAction *options = new QAction("&Options...", this); options->setIcon(QIcon::fromTheme("preferences-other")); connect(options, SIGNAL(triggered()), this, SLOT(showOptions())); ui->menu_Edit->addAction(options); clearConflictBar(); connect(jsB, SIGNAL(showConflict()), ui->conflictBar, SLOT(show())); connect(jsB, SIGNAL(showConflict()), ui->conflictBarBottom, SLOT(show())); conflictsGroup = new QActionGroup(this); connect(conflictsGroup, SIGNAL(triggered(QAction*)), this, SLOT(changeNoteVersion(QAction*))); searchIndex = new SearchIndex(this); connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(search())); connect(edam, SIGNAL(syncFinished()), searchIndex, SLOT(buildSearchIndex())); connect(jsB, SIGNAL(noteUpdated(QString)), searchIndex, SLOT(updateNoteIndex(QString))); connect(edam, SIGNAL(noteUpdated(QString)), searchIndex, SLOT(dropNoteIndex(QString))); connect(ui->searchInput, SIGNAL(returnPressed()), this, SLOT(search())); QByteArray mainWindowGeometry = sql::readSyncStatus("mainWindowGeometry").toString().toLatin1(); if (!mainWindowGeometry.isEmpty()) restoreGeometry(QByteArray::fromBase64(mainWindowGeometry)); QByteArray mainWidgetsSplitterState = sql::readSyncStatus("mainWidgetsSplitterState").toString().toLatin1(); if (!mainWidgetsSplitterState.isEmpty()) ui->mainWidgetsSplitter->restoreState(QByteArray::fromBase64(mainWidgetsSplitterState)); //showWindow(); edam->init(); }
void tcell_store(MyInfo_t *my_info, int sock_fd, char *store_msg) { FileDesc_t file_desc; char *msg_part, *field, *value, *msg_end; msg_part = strtok_r(store_msg, MSG_SEP, &msg_end); /* Get the file description from the store message */ while(msg_part != NULL) { char *field_end; field = strtok_r(msg_part, FIELD_VALUE_SEP, &field_end); if(field == NULL) { fprintf(stderr, "[ERROR] An error occurred while decrypting the " " message. Unable to process it.\n"); exit(-1); } /* The field is not null we cant get a value */ value = strtok_r(NULL, FIELD_VALUE_SEP, &field_end); if(value == NULL) { fprintf(stderr, "[WARNING] The value of the field < %s > \n" " was not provided.\n", field); } /* Fill in the correct field of the file descriptor */ if(strcmp(field, FIELD_FILE_GID) == 0) { strcpy(file_desc.file_gid, value); } else if(strcmp(field, FIELD_FILE_ID) == 0) { strcpy(file_desc.file_id, value); } else if(strcmp(field, FIELD_SIZE) == 0) { strcpy(file_desc.size, value); } else if(strcmp(field, FIELD_TYPE) == 0) { strcpy(file_desc.type, value); } else if(strcmp(field, FIELD_DESC) == 0) { strcpy(file_desc.description, value); } else if(strcmp(field, FIELD_SYM_KEY) == 0) { strcpy(file_desc.symmetric_key, value); } else if(strcmp(field, FIELD_IV) == 0) { strcpy(file_desc.initialisation_vector, value); } msg_part = strtok_r(NULL, MSG_SEP, &msg_end); } /* Update the file gid to add the time */ char strtime[ARR_SIZE]; time_t t = time(NULL); struct tm s_tm = *localtime(&t); sprintf(strtime, "%d%d%d%d%d%d", s_tm.tm_year + 1900, s_tm.tm_mon + 1, s_tm.tm_mday, s_tm.tm_hour, s_tm.tm_min, s_tm.tm_sec); strcat(file_desc.file_gid, "-"); strcat(file_desc.file_gid, strtime); /* Set the path of the file on the tcell */ char *tcell_files_path = get_tcell_files_path(); char buf_path[ARR_SIZE]; sprintf(buf_path, "%s/%s", tcell_files_path, file_desc.file_gid); strcpy(file_desc.path, buf_path); free(tcell_files_path); /* Insert a new entry in the database */ if(insertFile(&file_desc) != 1) { fprintf(stderr, "[ERROR] Could not insert file into the database.\n"); exit(-1); } /* Everyting went well, send an ack to start the file transfer */ send_msg_to(sock_fd, rsa_encrypt_msg(my_info->my_public_key, MSG_ACK)); /* File transfer! */ recv_file_from(sock_fd, file_desc.size, file_desc.path); /* Send an ack to end the transaction */ send_msg_to(sock_fd, rsa_encrypt_msg(my_info->my_public_key, MSG_ACK)); fprintf(stdout, "[INFO] File successfully transfered!\n"); }
static void generateSqlite3ForFile(sqlite3 *db, FileDef *fd) { // + includes files // + includedby files // - include graph // - included by graph // + contained class definitions // + contained namespace definitions // + member groups // + normal members // - brief desc // - detailed desc // - source code // - location // - number of lines if (fd->isReference()) return; // skip external references // + includes files IncludeInfo *ii; if (fd->includeFileList()) { QListIterator<IncludeInfo> ili(*fd->includeFileList()); for (ili.toFirst();(ii=ili.current());++ili) { int id_file=insertFile(db,fd->absFilePath().data()); bindIntParameter(i_s_includes,":local",ii->local); bindIntParameter(i_s_includes,":id_src",id_file); bindTextParameter(i_s_includes,":dst",ii->includeName.data(),FALSE); if (-1==step(db,i_s_includes)) continue; } } // + includedby files if (fd->includedByFileList()) { QListIterator<IncludeInfo> ili(*fd->includedByFileList()); for (ili.toFirst();(ii=ili.current());++ili) { int id_file=insertFile(db,ii->includeName); bindIntParameter(i_s_includes,":local",ii->local); bindIntParameter(i_s_includes,":id_src",id_file); bindTextParameter(i_s_includes,":dst",fd->absFilePath().data(),FALSE); if (-1==step(db,i_s_includes)) continue; } } // + contained class definitions if (fd->getClassSDict()) { writeInnerClasses(db,fd->getClassSDict()); } // + contained namespace definitions if (fd->getNamespaceSDict()) { writeInnerNamespaces(db,fd->getNamespaceSDict()); } // + member groups if (fd->getMemberGroupSDict()) { MemberGroupSDict::Iterator mgli(*fd->getMemberGroupSDict()); MemberGroup *mg; for (;(mg=mgli.current());++mgli) { generateSqlite3Section(db,fd,mg->members(),"user-defined",mg->header(), mg->documentation()); } } // + normal members QListIterator<MemberList> mli(fd->getMemberLists()); MemberList *ml; for (mli.toFirst();(ml=mli.current());++mli) { if ((ml->listType()&MemberListType_declarationLists)!=0) { generateSqlite3Section(db,fd,ml,"user-defined");//g_xmlSectionMapper.find(ml->listType())); } } }
// see bsa.h bool BSA::open() { QMutexLocker lock( & bsaMutex ); try { if ( ! bsa.open( QIODevice::ReadOnly ) ) throw QString( "file open" ); quint32 magic, version; bsa.read( (char*) &magic, sizeof( magic ) ); if ( magic == OB_BSAHEADER_FILEID ) { bsa.read( (char*) &version, sizeof( version ) ); if ( version != OB_BSAHEADER_VERSION && version != F3_BSAHEADER_VERSION ) throw QString( "file version" ); OBBSAHeader header; if ( bsa.read( (char *) & header, sizeof( header ) ) != sizeof( header ) ) throw QString( "header size" ); //qWarning() << bsaName << header; if ( ( header.ArchiveFlags & OB_BSAARCHIVE_PATHNAMES ) == 0 || ( header.ArchiveFlags & OB_BSAARCHIVE_FILENAMES ) == 0 ) throw QString( "header flags" ); compressToggle = header.ArchiveFlags & OB_BSAARCHIVE_COMPRESSFILES; if (version == F3_BSAHEADER_VERSION) { namePrefix = header.ArchiveFlags & F3_BSAARCHIVE_PREFIXFULLFILENAMES; } else { namePrefix = false; } if ( ! bsa.seek( header.FolderRecordOffset + header.FolderNameLength + header.FolderCount * ( 1 + sizeof( OBBSAFolderInfo ) ) + header.FileCount * sizeof( OBBSAFileInfo ) ) ) throw QString( "file name seek" ); QByteArray fileNames( header.FileNameLength, char(0) ); if ( bsa.read( fileNames.data(), header.FileNameLength ) != header.FileNameLength ) throw QString( "file name read" ); quint32 fileNameIndex = 0; // qDebug() << file.pos() - header.FileNameLength << fileNames; if ( ! bsa.seek( header.FolderRecordOffset ) ) throw QString( "folder info seek" ); QVector<OBBSAFolderInfo> folderInfos( header.FolderCount ); if ( bsa.read( (char *) folderInfos.data(), header.FolderCount * sizeof( OBBSAFolderInfo ) ) != header.FolderCount * sizeof( OBBSAFolderInfo ) ) throw QString( "folder info read" ); quint32 totalFileCount = 0; foreach ( OBBSAFolderInfo folderInfo, folderInfos ) { // useless? /* qDebug() << __LINE__ << "position" << bsa.pos() << "offset" << folderInfo.offset; if ( folderInfo.offset < header.FileNameLength || ! bsa.seek( folderInfo.offset - header.FileNameLength ) ) throw QString( "folder content seek" ); */ QString folderName; if ( ! BSAReadSizedString( bsa, folderName ) || folderName.isEmpty() ) { //qDebug() << "folderName" << folderName; throw QString( "folder name read" ); } // qDebug() << folderName; BSAFolder * folder = insertFolder( folderName ); quint32 fcnt = folderInfo.fileCount; totalFileCount += fcnt; QVector<OBBSAFileInfo> fileInfos( fcnt ); if ( bsa.read( (char *) fileInfos.data(), fcnt * sizeof( OBBSAFileInfo ) ) != fcnt * sizeof( OBBSAFileInfo ) ) throw QString( "file info read" ); foreach ( OBBSAFileInfo fileInfo, fileInfos ) { if ( fileNameIndex >= header.FileNameLength ) throw QString( "file name size" ); QString fileName = ( fileNames.data() + fileNameIndex ); fileNameIndex += fileName.length() + 1; insertFile( folder, fileName, fileInfo.sizeFlags, fileInfo.offset ); } } if ( totalFileCount != header.FileCount ) throw QString( "file count" ); }
static void generateSqlite3ForMember(sqlite3*db,MemberDef *md,Definition *def) { // + declaration/definition arg lists // + reimplements // + reimplementedBy // + exceptions // + const/volatile specifiers // - examples // + source definition // + source references // + source referenced by // - body code // + template arguments // (templateArguments(), definitionTemplateParameterLists()) // - call graph // enum values are written as part of the enum if (md->memberType()==MemberType_EnumValue) return; if (md->isHidden()) return; //if (md->name().at(0)=='@') return; // anonymous member // group members are only visible in their group //if (def->definitionType()!=Definition::TypeGroup && md->getGroupDef()) return; QCString memType; // memberdef bindTextParameter(i_s_memberdef,":refid",md->anchor().data(),FALSE); bindIntParameter(i_s_memberdef,":kind",md->memberType()); bindIntParameter(i_s_memberdef,":prot",md->protection()); bindIntParameter(i_s_memberdef,":static",md->isStatic()); bool isFunc=FALSE; switch (md->memberType()) { case MemberType_Function: // fall through case MemberType_Signal: // fall through case MemberType_Friend: // fall through case MemberType_DCOP: // fall through case MemberType_Slot: isFunc=TRUE; break; default: break; } if (isFunc) { ArgumentList *al = md->argumentList(); if (al!=0 && al->constSpecifier) { bindIntParameter(i_s_memberdef,":const",al->constSpecifier); } bindIntParameter(i_s_memberdef,":explicit",md->isExplicit()); bindIntParameter(i_s_memberdef,":inline",md->isInline()); bindIntParameter(i_s_memberdef,":final",md->isFinal()); bindIntParameter(i_s_memberdef,":sealed",md->isSealed()); bindIntParameter(i_s_memberdef,":new",md->isNew()); bindIntParameter(i_s_memberdef,":optional",md->isOptional()); bindIntParameter(i_s_memberdef,":required",md->isRequired()); bindIntParameter(i_s_memberdef,":virt",md->virtualness()); } // place in the arguments and linkify the arguments if (md->memberType() == MemberType_Variable) { bindIntParameter(i_s_memberdef,":mutable",md->isMutable()); bindIntParameter(i_s_memberdef,":initonly",md->isInitonly()); } else if (md->memberType() == MemberType_Property) { bindIntParameter(i_s_memberdef,":readable",md->isReadable()); bindIntParameter(i_s_memberdef,":writable",md->isWritable()); bindIntParameter(i_s_memberdef,":gettable",md->isGettable()); bindIntParameter(i_s_memberdef,":settable",md->isSettable()); if (md->isAssign() || md->isCopy() || md->isRetain()) { int accessor = md->isAssign() ? md->isAssign() : (md->isCopy() ? md->isCopy() : md->isRetain()) ; bindIntParameter(i_s_memberdef,":accessor",accessor); } } else if (md->memberType() == MemberType_Event) { bindIntParameter(i_s_memberdef,":addable",md->isAddable()); bindIntParameter(i_s_memberdef,":removable",md->isRemovable()); bindIntParameter(i_s_memberdef,":raisable",md->isRaisable()); } // + declaration/definition arg lists if (md->memberType()!=MemberType_Define && md->memberType()!=MemberType_Enumeration ) { QCString typeStr = md->typeString(); stripQualifiers(typeStr); StringList l; linkifyText(TextGeneratorSqlite3Impl(l),def,md->getBodyDef(),md,typeStr); if (typeStr.data()) { bindTextParameter(i_s_memberdef,":type",typeStr.data(),FALSE); } if (md->definition()) { bindTextParameter(i_s_memberdef,":definition",md->definition()); } if (md->argsString()) { bindTextParameter(i_s_memberdef,":argsstring",md->argsString()); } } bindTextParameter(i_s_memberdef,":name",md->name()); if (md->memberType() == MemberType_Property) { if (md->isReadable()) { DBG_CTX(("<read>\n")); } if (md->isWritable()) { DBG_CTX(("<write>\n")); } } if (isFunc) //function { ArgumentList *declAl = md->declArgumentList(); ArgumentList *defAl = md->argumentList(); if (declAl!=0 && declAl->count()>0) { ArgumentListIterator declAli(*declAl); ArgumentListIterator defAli(*defAl); Argument *a; for (declAli.toFirst();(a=declAli.current());++declAli) { Argument *defArg = defAli.current(); DBG_CTX(("<param>\n")); if (!a->attrib.isEmpty()) { DBG_CTX(("<attributes>:%s\n",a->attrib.data())); } if (!a->type.isEmpty()) { StringList l; linkifyText(TextGeneratorSqlite3Impl(l),def,md->getBodyDef(),md,a->type); StringListIterator li(l); QCString *s; while ((s=li.current())) { insertMemberReference(db,md->anchor().data(),s->data(),def->getDefFileName().data(),md->getDefLine(),1); ++li; } } if (!a->name.isEmpty()) { DBG_CTX(("<declname>%s\n",a->name.data())); } if (defArg && !defArg->name.isEmpty() && defArg->name!=a->name) { DBG_CTX(("<defname>%s\n",defArg->name.data())); } if (!a->array.isEmpty()) { DBG_CTX(("<array>%s",a->array.data())); } if (!a->defval.isEmpty()) { StringList l; linkifyText(TextGeneratorSqlite3Impl(l),def,md->getBodyDef(),md,a->defval); } if (defArg) ++defAli; } } } else if (md->memberType()==MemberType_Define && md->argsString()) // define { if (md->argumentList()->count()==0) // special case for "foo()" to // disguish it from "foo". { DBG_CTX(("no params\n")); } else { ArgumentListIterator ali(*md->argumentList()); Argument *a; for (ali.toFirst();(a=ali.current());++ali) { DBG_CTX(("<param><defname>%s\n",a->type.data())); } } } // Extract references from initializer // avoid that extremely large tables are written to the output. // todo: it's better to adhere to MAX_INITIALIZER_LINES. // drm_mod_register_buffer, if (!md->initializer().isEmpty() && md->initializer().length()<2000) { bindTextParameter(i_s_memberdef,":initializer",md->initializer().data()); StringList l; linkifyText(TextGeneratorSqlite3Impl(l),def,md->getBodyDef(),md,md->initializer()); StringListIterator li(l); QCString *s; while ((s=li.current())) { if (md->getBodyDef()) { DBG_CTX(("initializer:%s %s %s %d\n", md->anchor().data(), s->data(), md->getBodyDef()->getDefFileName().data(), md->getStartBodyLine())); insertMemberReference(db,md->anchor().data(),s->data(),md->getBodyDef()->getDefFileName().data(),md->getStartBodyLine(),1); } ++li; } } if ( md->getScopeString() ) { bindTextParameter(i_s_memberdef,":scope",md->getScopeString().data(),FALSE); } // Brief and detail description bindTextParameter(i_s_memberdef,":briefdescription",md->briefDescription(),FALSE); bindTextParameter(i_s_memberdef,":detaileddescription",md->documentation(),FALSE); bindTextParameter(i_s_memberdef,":inbodydescription",md->inbodyDocumentation(),FALSE); // File location if (md->getDefLine() != -1) { int id_file = insertFile(db,md->getDefFileName()); if (id_file!=-1) { bindIntParameter(i_s_memberdef,":id_file",id_file); bindIntParameter(i_s_memberdef,":line",md->getDefLine()); bindIntParameter(i_s_memberdef,":column",md->getDefColumn()); if (md->getStartBodyLine()!=-1) { int id_bodyfile = insertFile(db,md->getBodyDef()->absFilePath()); if (id_bodyfile == -1) { sqlite3_clear_bindings(i_s_memberdef); } else { bindIntParameter(i_s_memberdef,":id_bodyfile",id_bodyfile); bindIntParameter(i_s_memberdef,":bodystart",md->getStartBodyLine()); bindIntParameter(i_s_memberdef,":bodyend",md->getEndBodyLine()); } } } } if (-1==step(db,i_s_memberdef)) { sqlite3_clear_bindings(i_s_memberdef); } sqlite3_last_insert_rowid(db); // + source references // The cross-references in initializers only work when both the src and dst // are defined. MemberSDict *mdict = md->getReferencesMembers(); if (mdict!=0) { MemberSDict::IteratorDict mdi(*mdict); MemberDef *rmd; for (mdi.toFirst();(rmd=mdi.current());++mdi) { insertMemberReference(db,md,rmd,mdi.currentKey()); } } // + source referenced by mdict = md->getReferencedByMembers(); if (mdict!=0) { MemberSDict::IteratorDict mdi(*mdict); MemberDef *rmd; for (mdi.toFirst();(rmd=mdi.current());++mdi) { insertMemberReference(db,rmd,md,mdi.currentKey()); } } }
// slot for insert file void Project::slotInsertFile( const KURL& url ) { insertFile( url, true ); }