Commit 2c9653fd authored by saalen's avatar saalen

enhanced filetypes.conf config options

git-svn-id: https://svn.code.sf.net/p/syntaxhighlight/code@197 b214f192-c5d8-4e29-a392-b12ed3af51bf
parent 650693a1
......@@ -35,6 +35,12 @@ A. Aniruddha (GDB, Yang)
Roland Hieber (PDF)
Conrad Steenberg (Crack)
Victor Ananjevsky (conf.lang)
Raphael Droz (Ansible YAML)
Lydia Duncan (Chapel)
Tristano Ajmone (GDScript)
Max Christian Pohle (VIMScript)
Jess Austin (Coffeescript)
Tristano Ajmone (PureBasic, GDScript)
Colour themes:
David (matlab)
......@@ -43,6 +49,8 @@ Alexandre Bonneau (Acid)
Sunrise Telephone Systems Ltd. (ide-xcode)
Joerg Walter (moe)
Roger Sperberg (andes, oxygenated)
Tristano Ajmone (edit-godot)
Patches:
Marc Duponcheel (gcc 3.x compatibility)
......
CHANGELOG Highlight
highlight 3.36
xx.03.2017
-fixed code folding plugin to support more Ruby conditional modifiers (thanks to Jens Schleusener)
-fixed Perl quoted string highlighting (thanks to Jens Schleusener)
-added Filenames parameter in filetypes.conf to assign input filenames to syntax types
(suggested by Andy)
-added FASM definition and edit-fasm theme (thanks to Tristano Ajmone)
-GUI: file extensions can be configured for multiple languages, triggers syntax selection prompt
---
highlight 3.35
28.02.2017
......
......@@ -756,18 +756,26 @@ See README_PLUGINS for a detailed description and examples of packaged plugins.
The script filetypes.conf assigns file extensions and shebang descriptions to
language definitions.
A configuration is mandatory only if multiple file extensions are linked to
one syntax or if a extension is ambiguous. Otherwise the syntax definition whose
name corresponds to the input file extension will be applied.
Format:
FileMapping={
{ Lang, Extensions|Shebang },
{ Lang, Filenames|Extensions|Shebang },
}
Lang: String, name of language definition
Filenames: list of strings, contains filenames referring to "Lang"
Extensions: list of strings, contains file extensions referring to "Lang"
Shebang: String, Regular expression which matches the first line of the input
file
Behaviour upon ambiguous file extensions:
- CLI: the first association listed here will be used
- GUI: a syntax selection prompt will be shown
Edit the file gui_files/ext/fileopenfilter.conf to add new syntax types to
the GUI's file open filter.
......@@ -857,7 +865,7 @@ There is also a Sourceforge project:
http://sourceforge.net/projects/syntaxhighlight/
Source tarball
Windows executables
Windows and MacOS executables
http://www.andre-simon.de
Arch Linux
......
......@@ -776,20 +776,29 @@ Siehe README_PLUGINS um mehr darueber zu erfahren.
-------------------------------------------------------------------------------
In filetypes.conf werden Dateizuordnungen und Shebang-Definitionen eingetragen.
Eine Konfiguration ist nur dann zwingend notwendig, wenn es mehrere Dateiendungen
fuer eine Syntax gibt oder eine Endung nicht eindeutig zugewiesen werden kann.
Ansonsten wird die Syntax geladen, deren Name mit der Dateiendung der Eingabedatei
uebereinstimmt.
Format:
FileMapping={
{ Lang, Extensions|Shebang },
{ Lang, Filenames|Extensions|Shebang },
}
Lang: String, Name der Sprachdefinition
Filenames: Liste, enthaelt alle Dateinamen, die "Lang" zugeordnet werden
Extensions: Liste, enthaelt alle Dateiendungen, die "Lang" zugeordnet werden
Shebang: String, Regulaerer Ausdruck der mit der ersten Zeile der Eingabe
verglichen wird
Verhalten der Software bei mehrdeutigen Endungen:
- CLI: die erste eingetragene Verknuepfung wird angewandt
- GUI: eine Syntax-Auswahl wird angezeigt
Tragen Sie neue Dateiendungen auch in gui_files/ext/fileopenfilter.conf ein,
damit diese im GUI-Dateiauswahldialog als Filter angezeigt werden
damit diese im GUI-Dateiauswahldialog als Filter angezeigt werden.
3.8 PFADE DER KONFIG-DATEIEN
......@@ -877,7 +886,7 @@ FreeBSD).
Auf der Website sind immer die aktuellsten Source-Pakete (upstream) verfuegbar.
Source tarball
Windows executables
Windows und MacOS executables
http://www.andre-simon.de
Arch Linux
......
-- File extension and shebang mapping
-- Add an entry for a language syntax which is occupied by multiple source file extensions
-- If a filename has no extension by convention (ie. makefile), it also may be listed here
-- Add an entry for a language syntax which is occupied by multiple source file extensions.
-- Extensions can be configured for multiple languages (see "asm"):
-- - CLI: the first association listed here will be used
-- - GUI: a syntax selection prompt will be shown
-- If a filename has no extension by convention (ie. makefile), it also may be listed as "Shebang"
-- Since release 3.36 you can assign filenames to syntax types:
-- { Lang="abc", Filenames={"test.xyz"} }
-- The first filetypes.conf found in a highlight search directory wins.
FileMapping = {
......@@ -10,6 +19,7 @@ FileMapping = {
{ Lang="ampl", Extensions={"dat", "run"} },
{ Lang="amtrix", Extensions={"s4", "s4t", "s4h", "hnd", "t4"} },
{ Lang="assembler", Extensions={"asm", "a51", "29k", "68s", "68x", "x86"} },
{ Lang="fasm", Extensions={"asm", "inc"} },
{ Lang="asp", Extensions={"aspx", "ashx", "ascx"} },
{ Lang="ats", Extensions={"dats"} },
{ Lang="aspect", Extensions={"was", "wud"} },
......@@ -109,7 +119,7 @@ FileMapping = {
{ Lang="yaml", Extensions={"yml"} },
{ Lang="vimscript", Extensions={"vim", "vimrc"} },
{ Lang="purebasic", Extensions={"pb", "pbi"} },
{ Lang="xml", Shebang=[[^\s*<\?xml\s+version=\"1\.0\"\s+[^(\?>)]*?>\s*$]] },
{ Lang="sh", Shebang=[[^#!\s*(/usr)?(/local)?/bin/(env\s+)?([bd]ash|t?csh|[akz]?sh)]] },
{ Lang="make",Shebang=[[^#!\s*(/usr)?(/local)?/bin/(env\s+)?make]] },
......
......@@ -62,6 +62,7 @@ Erlang (*.erl)
Euphoria (*.ex *.exw *.exu *.ew *.eu)
Express (*.exp)
Fame (*.fame)
FASM (*.asm *.inc)
Felix (*.flx)
F# (*.fs *.fsx)
Fortran77 (*.f *.f77 *.for *.ftn)
......
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
Description="Assembler"
Description="Generic Assembler"
Digits=[[ (?:0x|0X|\$)[0-9a-fA-F]+|\d*[\.\_]?\d+(?:[eE][\-\+]\d+)?[bBhHlLuU]* ]]
......@@ -18,10 +18,10 @@ Keywords={
"fnstenv", "fnstsw", "fpatan", "fprem", "fprem1", "fptan", "frndint", "frstor",
"fsave", "fscale", "fsetpm", "fsin", "fsincos", "fsqrt", "fst", "fstcw",
"fstenv", "fstp", "fstsw", "fsub", "fsubp", "fsubr", "fsubrp", "ftst", "fucom",
"fucomp", "fucompp", "fwait", "fxam", "fxch", "fxtract", "fyl2x", "fyl2xp1", "hlt", "idiv", "imul",
"fucomp", "fucompp", "fwait", "fxam", "fxch", "fxtract", "fyl2x", "fyl2xp1", "hlt", "idiv",
"in", "inc", "insb", "insd", "insw", "int", "into", "invd", "invlpg", "iret",
"iretd", "ja", "jae", "jb", "jbe", "jc", "jcxz", "je", "jecxz", "jg", "jge",
"jl", "jle", "jmp", "jna", "jnae", "jnb", "jnbe", "", "jnc", "jne", "jng",
"jl", "jle", "jmp", "jna", "jnae", "jnb", "jnbe", "jnc", "jne", "jng",
"jnge", "jnl", "jnle", "jno", "jnp", "jns", "jnz", "jo", "jp", "jpe", "jpo",
"js", "jz", "lahf", "lar", "lds", "lea", "leave", "les", "lfs", "lgdt", "lgs",
"lidt", "lldt", "lmsw", "lock", "lods", "lodsb", "lodsd", "lodsw", "loop",
......@@ -43,7 +43,8 @@ Keywords={
"le", "length", "local", "lt", "macro", "mask", "name", "near", "org", "page",
"proc", "public", "purge", "record", "rept", "seg", "segment", "short", "size",
"small", "struc", "subttl", "symtype", "this", "title", "width", "section",
"global", "align", "invoke" , "struct", "import", "entry"},
"global", "align", "invoke" , "struct", "import", "entry"
},
},
{ Id=2,
List={"ah", "al", "and", "ax", "bh", "bl", "bp", "bx", "byte", "ch", "cl",
......
This diff is collapsed.
......@@ -40,7 +40,7 @@ Keywords={
"getprotobyname", "getprotobynumber", "getservbyname",
"getservbyport", "getpwuid", "getpwnam", "getgrgid", "getgrnam", "getlogin",
"getpwent", "getgrent", "gmtime", "localtime", "time", "warn", "formline",
"reset", "scalar", "prototype", "lock", "tied", "untie", "qw", "qq", "qx", "q", "eval" },
"reset", "scalar", "prototype", "lock", "tied", "untie", "qq", "qx", "eval" },
},
{ Id=4,
Regex=[[->([a-zA-Z0-9_]+)]],
......@@ -53,6 +53,10 @@ Keywords={
Regex=[[\/.*?\/[msixpodualgc]*|m\/.*?\/[msixpodualgc]*|qr\/.*?\/[msixpodual]*|s\/.*?\/.*?\/[msixpodualgcer]*|(?:tr|y)\/.*?\/.*?\/[cdsr]*|m!.*?![msixpodualgc]*|qr!.*?![msixpodual]*|s!.*?!.*?![msixpodualgcer]*|(?:tr|y)!.*?!.*?![cdsr]*|m\?.*?\?[msixpodualgc]*|m\{.*?\}[msixpodualgc]*|qr\{.*?\}[msixpodual]*|s\{.*?\}\s*\{.*?\}[msixpodualgcer]*|(?:tr|y)\{.*?\}\s*\{.*?\}[cdsr]*]],
Group=0
},
{ Id=4,
Regex=[[q[qxwr]?\{|qw\(]]
},
}
-- hereDoc opening delimiter, see OnStateChange to handle end of string
......@@ -60,6 +64,7 @@ Keywords={
Strings={
Delimiter=[=["|'|`|<<["']?[[:alpha:]]+["']?]=],
Interpolation=[[ [@\$%]\w+ ]],
}
IgnoreCase=false
......@@ -75,7 +80,7 @@ Comments={
Operators=[[\(|\)|\[|\]|\{|\}|\,|\;|\:|\&|<|>|\!|~|\=|\/|\*|\+|\-|\$|\.|\^|\~|\%|\|]]
-- fix recognition of $
-- fix recognition of $ and other Perl perversions
function OnStateChange(oldState, newState, token, groupID)
-- resolve issue with regex expression which spans strings like "</i>" + VAR + "</i>"
......@@ -99,5 +104,25 @@ function OnStateChange(oldState, newState, token, groupID)
return HL_STRING_END
end
if newState==HL_KEYWORD and token=="q{" then
qString=1
return HL_STRING
end
if newState==HL_KEYWORD and token=="qw(" then
qString=2
return HL_STRING
end
if oldState==HL_STRING and qString==1 and token=="}" then
qString=0
return HL_STRING_END
end
if oldState==HL_STRING and qString==2 and token==")" then
qString=0
return HL_STRING_END
end
return newState
end
......@@ -107,6 +107,12 @@ function syntaxUpdate(desc)
blockBegin["until"] = true
blockEnd["end"] = true
blockStates[HL_KEYWORD] = true
-- fix self.class == other.class && @ops == other.ops
Identifiers=[[ [a-zA-Z_\.][\w\-]* ]]
table.insert( Keywords,
{ Id=3, List={".class"}
} )
end
HeaderInjection=[=[
......@@ -224,7 +230,9 @@ function syntaxUpdate(desc)
if (not blockStates[state] or notEmbedded==false) then
return
end
--io.write("TRC "..trace.." ")
-- FIX conditional modifiers: add condition to avoid recognition of delimiters
-- if the last state before is a statement
if langDesc=="Ruby" and string.len(trace)>1
......@@ -233,6 +241,7 @@ function syntaxUpdate(desc)
or string.ends(trace, ";"..math.floor(HL_IDENTIFIER_BEGIN)..";")
or string.ends(trace, ";"..math.floor(HL_NUMBER)..";")
or string.ends(trace, ";"..math.floor(HL_STRING)..";")
or string.ends(trace, ";"..math.floor(HL_STANDARD)..";")
or string.ends(trace, ";"..math.floor(HL_OPERATOR)..";") ) )
then
return
......
......@@ -19,7 +19,7 @@ function syntaxUpdate(desc)
function_items = Set {"chomp", "chop", "chr", "crypt", "hex", "index", "lc",
"lcfirst", "length", "oct", "ord", "pack", "qq", "reverse", "rindex", "sprintf",
"substr", "tr", "uc", "ucfirst,", "", "pos", "quotemeta", "split", "study",
"substr", "tr", "uc", "ucfirst,", "pos", "quotemeta", "split", "study",
"qr", "abs", "atan2", "cos", "exp", "hex", "int", "log", "oct", "rand", "sin",
"sqrt", "srand", "each", "keys", "pop", "push", "shift", "splice", "unshift",
"values", "grep", "join", "map", "qw", "reverse", "sort", "unpack", "delete",
......@@ -32,7 +32,7 @@ function syntaxUpdate(desc)
"mkdir", "open", "opendir", "readlink", "rename", "rmdir", "stat", "symlink",
"sysopen", "umask", "unlink", "utime", "caller", "continue", "die", "do",
"dump", "eval", "exit", "goto", "last", "next", "redo", "return", "sub",
"wantarray", "", "continue", "", "caller", "import", "local", "my", "our",
"wantarray", "continue", "caller", "import", "local", "my", "our",
"package", "state", "use", "defined", "dump", "eval", "formline", "local", "my",
"our", "reset", "scalar", "state", "undef", "wantarray", "alarm", "exec",
"fork", "getpgrp", "getppid", "getpriority", "kill", "pipe", "qx", "setpgrp",
......@@ -83,7 +83,7 @@ function syntaxUpdate(desc)
function Decorate(token, state)
if (state ~= HL_STANDARD and state ~= HL_KEYWORD) then
if (state ~= HL_STANDARD and state ~= HL_KEYWORD) then
return
end
......
......@@ -131,7 +131,7 @@ int HLCmdLineApp::printInstalledLanguages()
suffix = suffix.substr ( 1, suffix.length()- wildcard.length() );
cout << setw ( 30 ) <<setiosflags ( ios::left ) <<desc<<": "<<suffix;
int extCnt=0;
for (StringMap::iterator it=extensions.begin(); it!=extensions.end(); it++) {
for (StringMap::iterator it=assocByExtension.begin(); it!=assocByExtension.end(); it++) {
if (it->second==suffix ) {
cout << ((++extCnt==1)?" ( ":" ")<<it->first;
}
......@@ -211,6 +211,11 @@ void HLCmdLineApp::printConfigInfo ( )
cout << endl;
}
string HLCmdLineApp::getFileBaseName(const string& fileName){
size_t psPos = fileName.rfind ( /*Platform::pathSeparator*/ '/' );
return (psPos==string::npos) ? fileName : fileName.substr(psPos+1, fileName.length());
}
string HLCmdLineApp::getFileSuffix(const string& fileName)
{
size_t ptPos=fileName.rfind(".");
......@@ -221,9 +226,18 @@ string HLCmdLineApp::getFileSuffix(const string& fileName)
return (psPos!=string::npos && psPos>ptPos) ? "" : fileName.substr(ptPos+1, fileName.length());
}
bool HLCmdLineApp::loadFileTypeConfig ( const string& confName, StringMap* extMap, StringMap* shebangMap )
void HLCmdLineApp::readLuaList(const string& paramName, const string& langName,Diluculum::LuaValue &luaVal, StringMap* extMap){
int extIdx=1;
string val;
while (luaVal[paramName][extIdx] !=Diluculum::Nil) {
val = luaVal[paramName][extIdx].asString();
extMap->insert ( make_pair ( val, langName ) );
extIdx++;
}
}
bool HLCmdLineApp::loadFileTypeConfig ( const string& confName)
{
if ( !extMap || !shebangMap ) return false;
string confPath=dataDir.getFiletypesConfPath(confName);
try {
Diluculum::LuaState ls;
......@@ -235,13 +249,11 @@ bool HLCmdLineApp::loadFileTypeConfig ( const string& confName, StringMap* extMa
while ((mapEntry = ls["FileMapping"][idx].value()) !=Diluculum::Nil) {
langName = mapEntry["Lang"].asString();
if (mapEntry["Extensions"] !=Diluculum::Nil) {
int extIdx=1;
while (mapEntry["Extensions"][extIdx] !=Diluculum::Nil) {
extMap->insert ( make_pair ( mapEntry["Extensions"][extIdx].asString(), langName ) );
extIdx++;
}
readLuaList("Extensions", langName, mapEntry, &assocByExtension);
} else if (mapEntry["Filenames"] !=Diluculum::Nil) {
readLuaList("Filenames", langName, mapEntry, &assocByFilename);
} else if (mapEntry["Shebang"] !=Diluculum::Nil) {
shebangMap->insert ( make_pair ( mapEntry["Shebang"].asString(), langName ) );
assocByShebang.insert ( make_pair ( mapEntry["Shebang"].asString(), langName ) );
}
idx++;
}
......@@ -328,7 +340,7 @@ string HLCmdLineApp::analyzeFile ( const string& file )
StringMap::iterator it;
boost::xpressive::sregex rex;
boost::xpressive::smatch what;
for ( it=scriptShebangs.begin(); it!=scriptShebangs.end(); it++ ) {
for ( it=assocByShebang.begin(); it!=assocByShebang.end(); it++ ) {
rex = boost::xpressive::sregex::compile( it->first );
if ( boost::xpressive::regex_search( firstLine, what, rex ) ) return it->second;
}
......@@ -337,9 +349,12 @@ string HLCmdLineApp::analyzeFile ( const string& file )
string HLCmdLineApp::guessFileType ( const string& suffix, const string &inputFile, bool useUserSuffix )
{
string baseName = getFileBaseName(inputFile);
if (assocByFilename.count(baseName)) return assocByFilename.find(baseName)->second;
string lcSuffix = StringTools::change_case(suffix);
if (extensions.count(lcSuffix)) {
return extensions[lcSuffix];
if (assocByExtension.count(lcSuffix)) {
return assocByExtension[lcSuffix];
}
if (!useUserSuffix) {
......@@ -394,7 +409,7 @@ int HLCmdLineApp::run ( const int argc, const char*argv[] )
}
//call before printInstalledLanguages!
loadFileTypeConfig ( "filetypes", &extensions, &scriptShebangs );
loadFileTypeConfig ( "filetypes" );
if ( options.showLangdefs() ) {
return printInstalledLanguages();
......
......@@ -61,8 +61,7 @@ public:
private:
DataDir dataDir;
StringMap extensions;
StringMap scriptShebangs;
StringMap assocByExtension, assocByFilename, assocByShebang;
stringstream cin_bufcopy;
/** print version info*/
......@@ -98,6 +97,10 @@ private:
*/
string getFileSuffix ( const string &fileName );
/** \return base filename
*/
string getFileBaseName(const string& fileName);
/** \return file type deferred from extension or file shebang comment
*/
string guessFileType ( const string &suffix, const string &inputFile, bool useUserSuffix=false );
......@@ -112,11 +115,13 @@ private:
bool recursiveSearch );
string analyzeFile ( const string& file );
bool loadFileTypeConfig ( const string& name, StringMap* map, StringMap* shebangMap );
bool loadFileTypeConfig ( const string& name);
void printInstalledFiles();
vector <string> collectPluginPaths(const vector<string>& plugins);
void readLuaList(const string& paramName, const string& langName,Diluculum::LuaValue &luaVal, StringMap* extMap);
};
#endif
......@@ -594,18 +594,18 @@ State CodeGenerator::validateState(State newState, State oldState, unsigned int
token=token.substr(0, 1);
return oldState;
}
if (validatedState!=STANDARD) {
// if (validatedState!=STANDARD) {
stateTrace.push_back(validatedState);
if (stateTrace.size()>200) stateTrace.erase(stateTrace.begin(), stateTrace.begin() + 100 );
}
// }
return validatedState;
}
}
resultOfHook = false;
if (newState!=STANDARD) {
// if (newState!=STANDARD) {
stateTrace.push_back(newState);
if (stateTrace.size()>200) stateTrace.erase(stateTrace.begin(), stateTrace.begin() + 100 );
}
// }
return newState;
}
......@@ -624,7 +624,7 @@ Diluculum::LuaValueList CodeGenerator::callDecorateFct(const string&token)
params.push_back(Diluculum::LuaValue(token));
params.push_back(Diluculum::LuaValue(currentState));
params.push_back(Diluculum::LuaValue(currentKeywordClass));
string trace;
string trace(";");
if (stateTrace.size()>1){
for (size_t i=0; i<stateTrace.size()-1;i++){
trace += std::to_string (stateTrace[i]);
......
......@@ -15,16 +15,19 @@ DEFINES += O2 QT
SOURCES += main.cpp \
mainwindow.cpp \
io_report.cpp \
showtextfile.cpp
showtextfile.cpp \
syntax_chooser.cpp
HEADERS += mainwindow.h \
precomp.h \
io_report.h \
showtextfile.h
showtextfile.h \
syntax_chooser.h
FORMS += mainwindow.ui \
io_report.ui \
showtextfile.ui
showtextfile.ui \
syntax_chooser.ui
RESOURCES = highlight-gui.qrc
TRANSLATIONS = highlight_de_DE.ts highlight_es_ES.ts highlight_cs_CZ.ts highlight_zh_CN.ts
......
......@@ -973,6 +973,10 @@ Tyto stylové listy můžete vybrat ve svém textovém editoru, abyste přeform
<source>I&amp;mage width:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Plug-Ins</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ShowTextFile</name>
......@@ -1012,4 +1016,36 @@ Tyto stylové listy můžete vybrat ve svém textovém editoru, abyste přeform
<translation>Přeformátování není možné:</translation>
</message>
</context>
<context>
<name>syntax_chooser</name>
<message>
<source>Syntax selection</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Select correct syntax</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TextLabel</source>
<translation type="unfinished">Textový štítek</translation>
</message>
<message>
<source>These entries are configured in filetypes.conf.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>The selection will be remembered for this session.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remember selection</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>The file extension %1 is assigned to multiple syntax definitions.
Select the correct one:</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -34,6 +34,7 @@ along with Highlight. If not, see <http://www.gnu.org/licenses/>.
#include "showtextfile.h"
#include "io_report.h"
#include "syntax_chooser.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass), getDataFromCP(false)
......@@ -98,7 +99,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->comboReformat->addItems(fmts);
// load syntax mappings
if (!loadFileTypeConfig(&extensions, &shebangs)) {
if (!loadFileTypeConfig()) {
QMessageBox::warning(this, tr("Initialization error"),
tr("Could not find syntax definitions. Check installation."));
}
......@@ -183,7 +184,6 @@ MainWindow::~MainWindow()
void MainWindow::openFiles()
{
QStringList files = QFileDialog::getOpenFileNames(
this,
tr("Select one or more files to open"),
......@@ -470,10 +470,18 @@ void MainWindow::readSettings()
settings.endGroup();
}
bool MainWindow::loadFileTypeConfig(StringMap* extMap, StringMap* shebangMap)
{
if (!extMap || !shebangMap) return false;
void MainWindow::readLuaList(const string& paramName, const string& langName,Diluculum::LuaValue &luaVal, MMap* extMap){
int extIdx=1;
string val;
while (luaVal[paramName][extIdx] !=Diluculum::Nil) {
val = luaVal[paramName][extIdx].asString();
extMap->insert ( make_pair ( val, langName ) );
extIdx++;
}
}
bool MainWindow::loadFileTypeConfig()
{
#ifdef Q_OS_OSX
QString filetypesPath = QDir::toNativeSeparators(QString("%1/../Resources/filetypes.conf").arg(QCoreApplication::applicationDirPath()));
#else
......@@ -493,13 +501,11 @@ bool MainWindow::loadFileTypeConfig(StringMap* extMap, StringMap* shebangMap)
while ((mapEntry = ls["FileMapping"][idx].value()) !=Diluculum::Nil) {
langName = mapEntry["Lang"].asString();
if (mapEntry["Extensions"] !=Diluculum::Nil) {
int extIdx=1;
while (mapEntry["Extensions"][extIdx] !=Diluculum::Nil) {
extMap->insert ( make_pair ( mapEntry["Extensions"][extIdx].asString(), langName ) );
extIdx++;
}
readLuaList("Extensions", langName, mapEntry, &assocByExtension);
} else if (mapEntry["Filenames"] !=Diluculum::Nil) {
readLuaList("Filenames", langName, mapEntry, &assocByFilename);
} else if (mapEntry["Shebang"] !=Diluculum::Nil) {
shebangMap->insert ( make_pair ( mapEntry["Shebang"].asString(), langName ) );
assocByShebang.insert ( make_pair ( mapEntry["Shebang"].asString(), langName ) );
}
idx++;
}
......@@ -515,11 +521,11 @@ string MainWindow::analyzeFile(const string& file)
ifstream inFile(file.c_str());
string firstLine;
getline (inFile, firstLine);
StringMap::iterator it;
SMap::iterator it;
boost::xpressive::sregex rex;
boost::xpressive::smatch what;
for ( it=shebangs.begin(); it!=shebangs.end(); it++ ) {
for ( it=assocByShebang.begin(); it!=assocByShebang.end(); it++ ) {
rex = boost::xpressive::sregex::compile( it->first );
if ( boost::xpressive::regex_search( firstLine, what, rex ) ) return it->second;
}
......@@ -528,16 +534,56 @@ string MainWindow::analyzeFile(const string& file)
string MainWindow::getFileType(const string& suffix, const string &inputFile)
{
string baseName = getFileBaseName(inputFile);
if (assocByFilename.count(baseName)) return assocByFilename.find(baseName)->second;
string lcSuffix = StringTools::change_case(suffix);
if (extensions.count(lcSuffix)) {
return extensions[lcSuffix];
if (assocByExtension.count(lcSuffix)) {
string langAssociation;
MMap::iterator it = assocByExtension.find(lcSuffix);
if (it!=assocByExtension.end()) langAssociation = it->second;
std::pair <MMap::iterator, MMap::iterator> ret;
ret = assocByExtension.equal_range(lcSuffix);
std::list<std::string> lst;
for (MMap::iterator it=ret.first; it!=ret.second; ++it){
lst.push_back( it->second );
}
if (lst.size() > 1){
if (rememberedAssoc.count(lcSuffix)) return rememberedAssoc[lcSuffix];
syntax_chooser chooser;
chooser.setUnclearExtension(QString(lcSuffix.c_str()));
for (std::list<string>::iterator it=lst.begin(); it != lst.end(); ++it){
chooser.addSyntaxName(QString((*it).c_str()));
}
chooser.exec();
string selectedLang = chooser.getSelection().toStdString();
if (chooser.getRememberFlag()){
rememberedAssoc[lcSuffix]=selectedLang;
}
return selectedLang;
}
return langAssociation;
}
string shebang = analyzeFile(inputFile);
// Not configured in filetypes.conf, try shebang and finally the unmodified extension
string shebang = analyzeFile(inputFile);
if (!shebang.empty()) return shebang;
return lcSuffix;
}
string MainWindow::getFileBaseName(const string& fileName){
size_t psPos = fileName.rfind ( /*Platform::pathSeparator*/ '/' );
return (psPos==string::npos) ? fileName : fileName.substr(psPos+1, fileName.length());
}
string MainWindow::getFileSuffix(const string& fileName)
{
size_t ptPos=fileName.rfind(".");
......
......@@ -2,7 +2,7 @@
mainwindow.h
-------------------
begin : Mo 16.03.2009
copyright : (C) 2009 by Andre Simon
copyright : (C) 2009-2017 by Andre Simon
email : andre.simon1@gmx.de
***************************************************************************/
......@@ -60,10 +60,11 @@ along with Highlight. If not, see <http://www.gnu.org/licenses/>.
#include "codegenerator.h"
#include "htmlgenerator.h"
#include <map>
#include "enums.h"
typedef map<string, string> StringMap;
typedef multimap<string, string> MMap;
typedef map<string, string> SMap;
namespace Ui
{
......@@ -81,7 +82,8 @@ public:
void addToView(const QStringList& list