cs2sq::enResult cs2sq::add_symbols(void) { enResult res; int rc; if (m_db == NULL) return resOTHER_ERR; if (m_csdbp.isFileOpen() == false) return resOTHER_ERR; m_csdbpLastErr = m_csdbp.setup_symbol_read(); if (m_csdbpLastErr != csdbparser::resOK) return resCSDBPError; rc = prepare_stmt(&m_filesstmt, "INSERT INTO filestbl VALUES (?,?);"); if (rc!=0) return resSQLError; rc = prepare_stmt(&m_linesstmt, "INSERT INTO linestbl VALUES (?,?,?,?);"); if (rc!=0) return resSQLError; rc = prepare_stmt(&m_callstmt, "INSERT INTO calltbl VALUES (?,?);"); if (rc!=0) return resSQLError; rc = prepare_stmt(&m_symstmt, "INSERT INTO symtbl VALUES (?,?,?,?);"); if (rc!=0) return resSQLError; rc=sqlite3_exec(m_db, "BEGIN EXCLUSIVE;", NULL, 0, NULL); if (rc != SQLITE_OK) { if (m_debug) printf("SQLErr13: %d, %s\n", rc, sqlite3_errmsg(m_db)); return resSQLError; } idxcounter fileidx; idxcounter symidx; idxcounter lineidx; std::string current_file = ""; std::string s; symdata_pack sp; sp.valid = true; while (sp.valid) { m_csdbpLastErr = m_csdbp.get_next_symbol(&sp); if (m_csdbpLastErr != csdbparser::resOK) return resCSDBPError; if (sp.valid == false) break; //end of symbols if (sp.line_num == -1) continue; // empty line ++lineidx; if (current_file.compare(sp.filename) != 0) { ++fileidx; current_file = sp.filename; rc=execstmt(m_filesstmt, fileidx.getStr(), current_file.c_str()); if (rc!=0) return resSQLError; } rc=execstmt(m_linesstmt, lineidx.getStr(), sp.line_num_str().c_str(), fileidx.getStr(), sp.line_text_replacetab().c_str()); if (rc!=0) return resSQLError; if (sp.symbols.empty() == false) res = add_symdata(sp.symbols, lineidx.getStr(), &symidx); if (res != resOK) return res; } return resOK; }
cs2sq::enResult cs2sq::add_symdata(symdatalist sdlist, const char* lineid, idxcounter* idx) { //enResult res; symdatalist::iterator it; char smallstr[2]; int rc; smallstr[1] = 0; // NULL-terminated for (it = sdlist.begin(); it < sdlist.end(); it++) { ++(*idx); smallstr[0] = it->getTypeChar(); rc=execstmt(m_symstmt, idx->getStr(), it->symbname.c_str(), smallstr, lineid); if (rc!=0) return resSQLError; if ((it->sym_type != sym_data::symMacroDef)&& (it->sym_type != sym_data::symFuncCall)&& (it->sym_type != sym_data::symFuncDef)) continue; switch (it->sym_type) { case sym_data::symMacroDef: m_calling_macro.str = it->symbname; m_calling_macro.id = idx->getStr(); break; case sym_data::symFuncDef: m_calling_func.str = it->symbname; m_calling_func.id = idx->getStr(); break; case sym_data::symFuncCall: if ((it->calling_func.empty() == false) &&(m_calling_func.str.compare(it->calling_func) == 0)) { rc=execstmt(m_callstmt, m_calling_func.id.c_str(), idx->getStr()); if (rc!=0) return resSQLError; } if ((it->calling_macro.empty() == false) &&(m_calling_macro.str.compare(it->calling_macro) == 0)) { rc=execstmt(m_callstmt, m_calling_macro.id.c_str(), idx->getStr()); if (rc!=0) return resSQLError; } break; default: break; }; } return resOK; }
ctagread::enResult ctagread::getListOfSymIDs(sqlite3_stmt* pstmt, strctagIDList* idlist, const char* v1, const char* v2, const char* v3) { int rc; std::string s; idlist->clear(); rc = execstmt(pstmt, v1, v2, v3); while ((rc == SQLITE_ROW)||(rc == SQLITE_BUSY)) { if (rc == SQLITE_ROW) { s = (const char*) sqlite3_column_text(pstmt, 0); idlist->push_back(s); } rc = sqlite3_step(pstmt); } return resOK; }
ctagread::enResult ctagread::process_ctags(void) { tempbuf sym(400), fil(500), classname(400), numtxt(50), linetxt(4001), fil2(500); long int num; int numOfLines=0; char* retval; int scanretval = 0; int rc; char c; char smallstr[2]; char *cp; strctagIDList classIDs, symIDs, parentClassIDs, parentClassIDs_temp; enResult res; std::vector<stClsID> listClsHist; *(fil.get()) = '%'; // for SQL LIKE pattern recognition smallstr[1] = 0; rc = prepare_stmt(&m_insertstmt, "INSERT INTO membertbl VALUES (?,?,?);"); if (rc!=0) return resSQLError; rc = prepare_stmt(&m_insertinheritstmt, "INSERT INTO inherittbl VALUES (?,?);"); if (rc!=0) return resSQLError; rc = prepare_stmt(&m_readclassstmt, "SELECT symID FROM symtbl WHERE symName=? AND symType=\"c\";"); if (rc!=0) return resSQLError; //rc = prepare_stmt(&m_readsymstmt, "SELECT symID FROM symtbl WHERE symName=? AND lineid IN (SELECT lineID FROM linestbl WHERE linenum=? AND fileid IN (SELECT fileID FROM filestbl WHERE filePath LIKE ?));"); rc = prepare_stmt(&m_readsymstmt, "SELECT symtbl.symID FROM symtbl INNER JOIN linestbl ON (symtbl.symName=? AND symtbl.lineID = linestbl.lineID AND linestbl.linenum=?) INNER JOIN filestbl ON (linestbl.fileID = filestbl.fileID AND filePath LIKE ?);"); if (rc!=0) return resSQLError; rc = prepare_stmt(&m_writedeststmt, "UPDATE symtbl SET symName=? WHERE symID=?;"); if (rc!=0) return resSQLError; //rc = prepare_stmt(&m_readsymfstmt, "SELECT symID FROM symtbl WHERE symName=? AND symType=\"$\" AND lineid IN (SELECT lineID FROM linestbl WHERE linenum=? AND fileid IN (SELECT fileID FROM filestbl WHERE filePath LIKE ?));"); rc = prepare_stmt(&m_readsymfstmt, "SELECT symtbl.symID FROM symtbl INNER JOIN linestbl ON (symtbl.symName=? AND symtbl.symType=\"$\" AND symtbl.lineID = linestbl.lineID AND linestbl.linenum=?) INNER JOIN filestbl ON (linestbl.fileID = filestbl.fileID AND filePath LIKE ?);"); if (rc!=0) return resSQLError; rc=sqlite3_exec(m_db, "BEGIN EXCLUSIVE;\ DROP INDEX IF EXISTS memberIDIdx;\ DROP INDEX IF EXISTS groupIDIdx;\ DROP INDEX IF EXISTS parentIDIdx;\ DROP INDEX IF EXISTS childIDIdx;\ DELETE FROM membertbl;\ DELETE FROM inherittbl;\ COMMIT;", NULL, 0, NULL); if (rc != SQLITE_OK) { if (m_debug) printf("SQLErr13: %d, %s\n", rc, sqlite3_errmsg(m_db)); return resSQLError; } do { retval = fgets(linetxt.get(), linetxt.size() - 1, f_tags); if (retval != NULL) { chomp(linetxt.get()); scanretval = sscanf(linetxt.get(), "%s\t%s\t%ld;\"\t%c\tclass:%s", sym.get(), fil2.get(), &num, &c, classname.get()); } if ((retval != NULL)&&(scanretval == 5)) { strcpy(fil.get(), "%"); strcat(fil.get(), extract_filename(fil2.get())); res = getHListOfClassIDs(&classIDs, classname.get(), &listClsHist); if (res != resOK) return res; if (classIDs.empty()) continue; cp = sym.get(); if (*(sym.get()) == '~') { cp = (sym.get()) + 1; //include destructors // which cscope missed out } sprintf(numtxt.get(), "%ld", num); if (c == 'f') res = getListOfSymIDs(m_readsymfstmt, &symIDs, cp, numtxt.get(), fil.get()); else res = getListOfSymIDs(m_readsymstmt, &symIDs, cp, numtxt.get(), fil.get()); if (res != resOK) { return res; } if (symIDs.empty() == false) { for (unsigned int i=0; i < symIDs.size(); i++) { smallstr[0] = c; rc=execstmt(m_insertstmt, classIDs[0].c_str(), symIDs[i].c_str(), smallstr); if (rc!=0) return resSQLError; if (*(sym.get()) == '~') { rc=execstmt(m_writedeststmt, sym.get(), symIDs[i].c_str()); if (rc!=0) return resSQLError; } numOfLines++; } } //else {if (m_debug) {printf("no match found for symbol: %s\n",sym.get());}} } else if (retval != NULL) { scanretval = sscanf(linetxt.get(), "%s\t%s\t%ld;\"\t%c\tinherits:%s", sym.get(), fil2.get(), &num, &c, classname.get()); if ((scanretval == 5)&&(c == 'c')) { res = getHListOfClassIDs(&classIDs, sym.get(), &listClsHist); if (res != resOK) return res; if (classIDs.empty()) continue; parentClassIDs.clear(); parentClassIDs_temp.clear(); std::vector<std::string> vecstr = splitstr(classname.get(), ','); for (unsigned int i=0; i<vecstr.size(); i++) { res = getHListOfClassIDs(&parentClassIDs_temp, vecstr[i].c_str(), &listClsHist); if (res != resOK) return res; while (parentClassIDs_temp.empty() == false) { parentClassIDs.push_back(parentClassIDs_temp.back()); parentClassIDs_temp.pop_back(); } } for (unsigned int i=0; i<parentClassIDs.size(); i++) { rc=execstmt(m_insertinheritstmt, parentClassIDs[i].c_str(), classIDs[0].c_str()); if (rc!=0) return resSQLError; } } } } while (retval != NULL); if (m_debug) printf ("Total membertbl records possible = %d\n", numOfLines); return resOK; }