From c5b8d538c0fc50a783cdce52c10043896f1fe25e Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 16 Mar 2015 16:12:04 +0000 Subject: [PATCH] ide: binary file detection tweaked, CppBase now allows M$ ids with $ git-svn-id: svn://ultimatepp.org/upp/trunk@8273 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CppBase/CppBase.h | 11 +++++++++++ uppsrc/CppBase/Parser.cpp | 28 ++++++++++++++-------------- uppsrc/CppBase/Pre.cpp | 4 ++-- uppsrc/CppBase/Qualify.cpp | 16 ++++++++-------- uppsrc/CppBase/cpplex.cpp | 5 ++--- uppsrc/ide/Designers/HexView.icpp | 12 ++---------- uppsrc/ide/ide.lay | 14 +++++++------- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/uppsrc/CppBase/CppBase.h b/uppsrc/CppBase/CppBase.h index d51e2fc67..d8658f35d 100644 --- a/uppsrc/CppBase/CppBase.h +++ b/uppsrc/CppBase/CppBase.h @@ -5,6 +5,17 @@ NAMESPACE_UPP + +inline bool iscib2(int c) +{ + return iscib(c) || c == '$'; +} + +inline bool iscid2(int c) +{ + return c >= '0' && c <= '9' || iscib2(c); +} + int GetCppFileIndex(const String& path); const String& GetCppFile(int i); Vector GetCppFiles(); diff --git a/uppsrc/CppBase/Parser.cpp b/uppsrc/CppBase/Parser.cpp index 3946910a7..6f6263fcc 100644 --- a/uppsrc/CppBase/Parser.cpp +++ b/uppsrc/CppBase/Parser.cpp @@ -43,7 +43,7 @@ String FnItem(const char *s, const char *pname, const char *qname, const String& String res; while(*s && (byte)*s <= ' ') s++; while(*s) { // Get the name of function into res - while(*s && !iscid(*s) && *s != '~') + while(*s && !iscid2(*s) && *s != '~') s++; int lvl = 0; int plvl = 0; @@ -64,7 +64,7 @@ String FnItem(const char *s, const char *pname, const char *qname, const String& res.Cat(*s++); plvl--; } - if(iscid(*s) || *s == '~' || *s && lvl) + if(iscid2(*s) || *s == '~' || *s && lvl) res.Cat(*s++); else break; @@ -86,19 +86,19 @@ String FnItem(const char *s, const char *pname, const char *qname, const String& while(*s) { const char *w = bew(qname, s); byte c = *s; - if(w && !iscid(*w)) { - if(iscid(*res.Last())) + if(w && !iscid2(*w)) { + if(iscid2(*res.Last())) res.Cat(' '); res.Cat(name); s = w; } else - if(iscid(c)) { + if(iscid2(c)) { const char *b = s++; - while(iscid(*s)) s++; + while(iscid2(*s)) s++; String q(b, s); if(q != s_virtual && q != s_inline && q != s_static && !InScList(q, pname)) { - if(iscid(*res.Last())) + if(iscid2(*res.Last())) res.Cat(' '); res.Cat(q); } @@ -142,9 +142,9 @@ String Purify(const char *s, const char *qname, const String& name) { s = w; } else - if(iscid(*s)) { + if(iscid2(*s)) { const char *b = s++; - while(iscid(*s)) s++; + while(iscid2(*s)) s++; String q(b, s); if(q != s_virtual && q != s_inline && q != s_static) res.Cat(q); @@ -162,9 +162,9 @@ String Purify(const char *s) { String res; while(*s && (byte)*s <= ' ') s++; while(*s) { - if(iscid(*s)) { + if(iscid2(*s)) { const char *b = s++; - while(iscid(*s)) s++; + while(iscid2(*s)) s++; String q(b, s); if(q != s_virtual && q != s_inline) res.Cat(q); @@ -376,7 +376,7 @@ String Parser::ReadOper(bool& castoper) { bool spc = false; while(p < lex.Pos()) { if((byte)*p > ' ') { - if(spc && iscid(*p)) { + if(spc && iscid2(*p)) { castoper = true; r.Cat(' '); } @@ -1450,7 +1450,7 @@ void Parser::Do() String n = lex.GetText(); String name; const char *s = n; - while(*s && iscid(*s)) + while(*s && iscid2(*s)) name.Cat(*s++); CppItem& im = Item(context.scope, n, name); im.kind = MACRO; @@ -1459,7 +1459,7 @@ void Parser::Do() s++; String p; for(;;) { - if(iscid(*s)) + if(iscid2(*s)) p.Cat(*s++); else { ScAdd(im.pname, p); diff --git a/uppsrc/CppBase/Pre.cpp b/uppsrc/CppBase/Pre.cpp index 2fa5855db..556543174 100644 --- a/uppsrc/CppBase/Pre.cpp +++ b/uppsrc/CppBase/Pre.cpp @@ -98,11 +98,11 @@ SrcFile PreProcess(Stream& in) if(*rm == '#') { if(rm[1] == 'd' && rm[2] == 'e' && rm[3] == 'f' && - rm[4] == 'i' && rm[5] == 'n' && rm[6] == 'e' && !iscid(rm[7])) { + rm[4] == 'i' && rm[5] == 'n' && rm[6] == 'e' && !iscid2(rm[7])) { const char *s = rm + 8; while(*s == ' ') s++; String macro; - while(iscid(*s)) + while(iscid2(*s)) macro.Cat(*s++); if(*s == '(') { while(*s != ')' && *s) diff --git a/uppsrc/CppBase/Qualify.cpp b/uppsrc/CppBase/Qualify.cpp index d9e6b641c..288e6bb93 100644 --- a/uppsrc/CppBase/Qualify.cpp +++ b/uppsrc/CppBase/Qualify.cpp @@ -131,9 +131,9 @@ String QualifyIds(Scopefo& nf, const String& k, bool all) int c = *s; if(c == ':') { const char *b = s++; - while(*s == ':' || iscid(*s)) s++; + while(*s == ':' || iscid2(*s)) s++; if(all) { - if(iscid(*r.Last())) + if(iscid2(*r.Last())) r << ' '; Scopefo nnf(nf.GetScope(), nf.base); Qualify(r, nnf, b, s); @@ -142,26 +142,26 @@ String QualifyIds(Scopefo& nf, const String& k, bool all) r.Cat(b, s); } else - if(iscid(c)) { - if(iscid(*r.Last())) + if(iscid2(c)) { + if(iscid2(*r.Last())) r << ' '; - if(s[0] == 'c' && s[1] == 'o' && s[2] == 'n' && s[3] == 's' && s[4] == 't' && !iscid(s[5])) { + if(s[0] == 'c' && s[1] == 'o' && s[2] == 'n' && s[3] == 's' && s[4] == 't' && !iscid2(s[5])) { r << s_const; s += 5; } else - if(s[0] == 'm' && s[1] == 'u' && s[2] == 't' && s[3] == 'a' && s[4] == 'b' && s[5] == 'l' && s[6] == 'e' && !iscid(s[7])) { + if(s[0] == 'm' && s[1] == 'u' && s[2] == 't' && s[3] == 'a' && s[4] == 'b' && s[5] == 'l' && s[6] == 'e' && !iscid2(s[7])) { r << "mutable"; s += 7; } else - if(s[0] == 'v' && s[1] == 'o' && s[2] == 'l' && s[3] == 'a' && s[4] == 't' && s[5] == 'i' && s[6] == 'l' && s[7] == 'e' && !iscid(s[8])) { + if(s[0] == 'v' && s[1] == 'o' && s[2] == 'l' && s[3] == 'a' && s[4] == 't' && s[5] == 'i' && s[6] == 'l' && s[7] == 'e' && !iscid2(s[8])) { r << "volatile"; s += 8; } else { const char *b = s++; - while(*s == ':' || iscid(*s)) s++; + while(*s == ':' || iscid2(*s)) s++; if(all) Qualify(r, nf, b, s); else diff --git a/uppsrc/CppBase/cpplex.cpp b/uppsrc/CppBase/cpplex.cpp index da3bfc42d..10315a053 100644 --- a/uppsrc/CppBase/cpplex.cpp +++ b/uppsrc/CppBase/cpplex.cpp @@ -9,14 +9,13 @@ NAMESPACE_UPP #pragma optimize("t", on) #endif - #define case_id \ case '_':case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':case 'g':case 'h': \ case 'i':case 'j':case 'k':case 'l':case 'm':case 'n':case 'o':case 'p':case 'q': \ case 'r':case 's':case 't':case 'u':case 'v':case 'w':case 'x':case 'y':case 'z': \ case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':case 'G':case 'H':case 'I': \ case 'J':case 'K':case 'L':case 'M':case 'N':case 'O':case 'P':case 'Q':case 'R': \ - case 'S':case 'T':case 'U':case 'V':case 'W':case 'X':case 'Y':case 'Z' + case 'S':case 'T':case 'U':case 'V':case 'W':case 'X':case 'Y':case 'Z':case '$' #define case_nonzero_digit \ case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9' @@ -167,7 +166,7 @@ void Lex::Next() String x; x.Reserve(12); x.Cat(c); - while(iscid(*ptr)) + while(iscid2(*ptr)) x.Cat(*ptr++); int q = id.FindAdd(x); if(q == tk_rval_ - 256) { // simple hack for transitionary macro diff --git a/uppsrc/ide/Designers/HexView.icpp b/uppsrc/ide/Designers/HexView.icpp index da9f1803c..8a8eb74e1 100644 --- a/uppsrc/ide/Designers/HexView.icpp +++ b/uppsrc/ide/Designers/HexView.icpp @@ -8,25 +8,17 @@ bool FileIsBinary(const char *path) if(*data.Last() == '\r') data.Cat(in.Get()); const char *end = data.End(); - int le = -1; const char *s = data; while(s < end) { int c = (byte)*s; if(c < 32) { if(c == '\r') { - if(s[1] != '\n' || le == 0) + if(s[1] != '\n') return true; - le = 1; s += 2; } else - if(c == '\n') { - if(le == 1) - return true; - s++; - } - else - if(c == '\t') + if(c == '\t' || c == '\n') s++; else return true; diff --git a/uppsrc/ide/ide.lay b/uppsrc/ide/ide.lay index cccac9d08..7aec6e38b 100644 --- a/uppsrc/ide/ide.lay +++ b/uppsrc/ide/ide.lay @@ -70,15 +70,15 @@ LAYOUT(RunLayout, 420, 172) ITEM(Option, utf8, SetLabel(t_("Output is UTF-8")).LeftPosZ(316, 104).TopPosZ(76, 20)) END_LAYOUT -LAYOUT(FindInFilesLayout, 492, 152) +LAYOUT(FindInFilesLayout, 568, 152) ITEM(Label, dv___0, SetLabel(t_("&Find")).LeftPosZ(4, 48).TopPosZ(4, 19)) - ITEM(WithDropChoice, find, HSizePosZ(52, 8).TopPosZ(4, 19)) + ITEM(WithDropChoice, find, HSizePosZ(52, 4).TopPosZ(4, 19)) ITEM(Label, dv___2, SetLabel(t_("In fil&es")).LeftPosZ(4, 48).TopPosZ(28, 19)) - ITEM(WithDropChoice, files, HSizePosZ(52, 8).TopPosZ(28, 19)) + ITEM(WithDropChoice, files, HSizePosZ(52, 4).TopPosZ(28, 19)) ITEM(Label, folder_lbl, SetLabel(t_("In f&older")).LeftPosZ(4, 48).TopPosZ(52, 19)) - ITEM(WithDropChoice, folder, HSizePosZ(52, 132).TopPosZ(52, 19)) + ITEM(WithDropChoice, folder, HSizePosZ(52, 144).TopPosZ(52, 19)) ITEM(Label, replace_lbl, SetLabel(t_("&Replace")).LeftPosZ(4, 48).TopPosZ(74, 22)) - ITEM(WithDropChoice, replace, HSizePosZ(248, 8).TopPosZ(76, 19)) + ITEM(WithDropChoice, replace, HSizePosZ(248, 4).TopPosZ(76, 19)) ITEM(Switch, style, SetLabel(t_("&None\nCo&nfirm\n&Auto")).LeftPosZ(52, 164).TopPosZ(78, 15)) ITEM(Label, replace_lbl2, SetLabel(t_("with:")).LeftPosZ(220, 28).TopPosZ(76, 19)) ITEM(Option, wholeword, SetLabel(t_("&Whole word")).LeftPosZ(54, 80).BottomPosZ(34, 18)) @@ -86,10 +86,10 @@ LAYOUT(FindInFilesLayout, 492, 152) ITEM(Option, ignorecase, SetLabel(t_("&Ignore case")).LeftPosZ(208, 84).BottomPosZ(34, 18)) ITEM(Option, samecase, SetLabel(t_("Mimic case")).LeftPosZ(288, 100).BottomPosZ(34, 18)) ITEM(Option, regexp, SetLabel(t_("RegEx")).LeftPosZ(368, 112).BottomPosZ(34, 18)) - ITEM(Option, readonly, ThreeState(true).SetLabel(t_("Read-only files")).LeftPosZ(54, 142).BottomPosZ(14, 16)) + ITEM(Option, readonly, ThreeState(true).SetLabel(t_("Read-only files")).LeftPosZ(464, 142).BottomPosZ(34, 18)) ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(6, 22)) ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(6, 22)) - ITEM(Option, workspace, SetLabel(t_("In workspace folders")).LeftPosZ(364, 136).TopPosZ(52, 20)) + ITEM(Option, workspace, SetLabel(t_("In workspace folders")).LeftPosZ(428, 136).TopPosZ(52, 20)) END_LAYOUT LAYOUT(BatchBuildLayout, 276, 276)