📄 syntaxmgr.cpp
字号:
#include "syntaxmgr.h"#include "portdef.h"#include "fileutil.hpp"#include <qfileinfo.h>#include <new>#include <fstream>#include <cstdlib>#include <cstring>SyntaxMgr::SyntaxMgr(){ m_LangEntries.setAutoDelete(true); QString kdf = (QString) getenv("HOME") + FILE_SEP + ".hide" + FILE_SEP "conf" + FILE_SEP + "lang.kdf"; QFileInfo fi(kdf); if (!fi.exists()) { QString defkdf = (QString) getenv("HIDEPATH") + FILE_SEP "conf" + FILE_SEP + "lang.kdf"; FileUtil::copy(defkdf, kdf); }}SyntaxMgr::~SyntaxMgr(){ m_LangEntries.clear();}bool SyntaxMgr::load(){ LangEntry *le=NULL; QString path = (QString) getenv("HOME") + FILE_SEP + ".hide" + FILE_SEP "conf" + FILE_SEP + "lang.kdf"; std::fstream in(path); char line[2056], *p=NULL; if (!in) return false; while (!in.eof()) { in.getline(line, sizeof(line)); if (in.eof()) break; if (strstr(line, "[EXT]=")) // Begin lang entry parse... { if (!(le = new LangEntry)) { in.close(); return false; } strtok(line, "="); while ((p = strtok(NULL, ":"))) le->addExtension(((QString) p).stripWhiteSpace()); while (!in.eof() && !strstr(line, "[/KW]")) { in.getline(line, sizeof(line)); if (in.eof()) break; if (strstr(line, "[SLC]=")) { strtok(line, "="); if ((p = strtok(NULL, ":"))) le->setSLC(((QString) p).stripWhiteSpace()); } else if (strstr(line, "[SMLC]=")) { strtok(line, "="); if ((p = strtok(NULL, ":"))) le->setSMLC(((QString) p).stripWhiteSpace()); } else if (strstr(line, "[EMLC]=")) { strtok(line, "="); if ((p = strtok(NULL, ":"))) le->setEMLC(((QString) p).stripWhiteSpace()); } else if (strstr(line, "[KW]")) { memset(line, 0x00, sizeof(line)); in.getline(line, sizeof(line)); while (!in.eof() && !strstr(line, "[/KW]")) { le->addKeyword(((QString) line).stripWhiteSpace()); memset(line, 0x00, sizeof(line)); in.getline(line, sizeof(line)); } } } m_LangEntries.append(le); le = NULL; } } in.close(); return true;}bool SyntaxMgr::save(){ return false;}QStringList *SyntaxMgr::keywords(QString x){ QStringList *exts=NULL; for (LangEntry *l = m_LangEntries.first(); l; l = m_LangEntries.next()) { exts = l->extensions(); for (unsigned i=0; i<exts->count(); i++) { if ((*exts)[i] == x) return l->keywords(); } } return NULL;}QString SyntaxMgr::slc(QString x){ QStringList *exts=NULL; for (LangEntry *l = m_LangEntries.first(); l; l = m_LangEntries.next()) { exts = l->extensions(); for (unsigned i=0; i<exts->count(); i++) { if ((*exts)[i] == x) return l->getSLC(); } } return "";}QString SyntaxMgr::smlc(QString x){ QStringList *exts=NULL; for (LangEntry *l = m_LangEntries.first(); l; l = m_LangEntries.next()) { exts = l->extensions(); for (unsigned i=0; i<exts->count(); i++) { if ((*exts)[i] == x) return l->getSMLC(); } } return "";}QString SyntaxMgr::emlc(QString x){ QStringList *exts=NULL; for (LangEntry *l = m_LangEntries.first(); l; l = m_LangEntries.next()) { exts = l->extensions(); for (unsigned i=0; i<exts->count(); i++) { if ((*exts)[i] == x) return l->getEMLC(); } } return "";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -