diff --git a/uppsrc/Core/Bom.cpp b/uppsrc/Core/Bom.cpp index 9af61853d..7c7ff9e5c 100644 --- a/uppsrc/Core/Bom.cpp +++ b/uppsrc/Core/Bom.cpp @@ -89,7 +89,7 @@ bool SaveFileBOM(const char *path, const WString& data) bool SaveStreamBOMUtf8(Stream& out, const String& data) { if(!out.IsOpen() || out.IsError()) return false; - unsigned char bom[] = {0xEF, 0xBB, 0xBF}; + static unsigned char bom[] = {0xEF, 0xBB, 0xBF}; out.Put(bom, 3); out.Put(ToCharset(CHARSET_UTF8, data)); out.Close(); diff --git a/uppsrc/CtrlLib/DocEdit.cpp b/uppsrc/CtrlLib/DocEdit.cpp index bb94596fc..66bf7ed1f 100644 --- a/uppsrc/CtrlLib/DocEdit.cpp +++ b/uppsrc/CtrlLib/DocEdit.cpp @@ -438,7 +438,7 @@ bool DocEdit::Key(dword key, int cnt) if(key >= ' ' && key < 65536 || key == '\n' || key == '\t' || key == K_SHIFT_SPACE) { if(key == K_TAB && !processtab) return false; - if(key >= 128 && key < 65536 && charset != CHARSET_UNICODE + if(key >= 128 && key < 65536 && (charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) && FromUnicode((wchar)key, charset) == DEFAULTCHAR) return true; RemoveSelection(); diff --git a/uppsrc/CtrlLib/LineEdit.cpp b/uppsrc/CtrlLib/LineEdit.cpp index 42aa72922..53ed8097f 100644 --- a/uppsrc/CtrlLib/LineEdit.cpp +++ b/uppsrc/CtrlLib/LineEdit.cpp @@ -558,7 +558,7 @@ bool LineEdit::InsertChar(dword key, int count, bool canow) { key = (*filter)(key); if(!IsReadOnly() && (key >= 32 && key < 65536 || key == '\t' || key == '\n' || key == K_ENTER && processenter || key == K_SHIFT_SPACE)) { - if(key >= 128 && key < 65536 && charset != CHARSET_UNICODE + if(key >= 128 && key < 65536 && (charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) && FromUnicode((wchar)key, charset) == DEFAULTCHAR) return true; if(!RemoveSelection() && overwrite && key != '\n' && key != K_ENTER && canow) { diff --git a/uppsrc/CtrlLib/Text.cpp b/uppsrc/CtrlLib/Text.cpp index 735254ae5..689c8f926 100644 --- a/uppsrc/CtrlLib/Text.cpp +++ b/uppsrc/CtrlLib/Text.cpp @@ -92,6 +92,14 @@ void TextCtrl::Load(Stream& s, byte charset) { ClearLines(); String ln; total = 0; + SetCharset(charset); + if(charset == CHARSET_UTF8_BOM && s.GetLeft() >= 3) { + int64 pos = s.GetPos(); + char h[3]; + if(!(s.Get(h, 3) == 3 && h[0] == 0xEF && h[1] == 0xBB && h[2] == 0xBF)) + s.Seek(pos); + charset = CHARSET_UTF8; + } while(!s.IsEof()) { int c = s.Get(); if(c == '\n') { @@ -111,11 +119,15 @@ void TextCtrl::Load(Stream& s, byte charset) { InsertLines(0, line.GetCount()); Update(); SetSb(); - SetCharset(charset); PlaceCaret(0); } void TextCtrl::Save(Stream& s, byte charset, bool crlf) const { + if(charset == CHARSET_UTF8_BOM) { + static byte bom[] = { 0xEF, 0xBB, 0xBF }; + s.Put(bom, 3); + charset = CHARSET_UTF8; + } charset = ResolveCharset(charset); for(int i = 0; i < line.GetCount(); i++) { if(i) @@ -146,7 +158,7 @@ String TextCtrl::Get(byte charset) const int TextCtrl::GetInvalidCharPos(byte charset) const { int q = 0; - if(charset != CHARSET_UTF8) + if(charset != CHARSET_UTF8 && charset != CHARSET_UTF8_BOM) for(int i = 0; i < line.GetCount(); i++) { WString txt = line[i]; WString ctxt = ToUnicode(FromUnicode(txt, charset), charset); @@ -201,7 +213,7 @@ Value TextCtrl::GetData() const String TextCtrl::GetEncodedLine(int i, byte charset) const { charset = ResolveCharset(charset); - if(charset == CHARSET_UTF8) + if(charset == CHARSET_UTF8 && charset != CHARSET_UTF8_BOM) return line[i].text; return FromUnicode(FromUtf8(line[i].text), charset); } @@ -456,7 +468,7 @@ void TextCtrl::RemoveU(int pos, int size) { int TextCtrl::Insert(int pos, const WString& _txt, bool typing) { WString txt = _txt; - if(charset != CHARSET_UNICODE) + if(charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) for(int i = 0; i < txt.GetCount(); i++) if(FromUnicode(txt[i], charset) == DEFAULTCHAR) txt.Set(i, '?'); diff --git a/uppsrc/CtrlLib/TextEdit.h b/uppsrc/CtrlLib/TextEdit.h index 241eea191..2eb97fc9d 100644 --- a/uppsrc/CtrlLib/TextEdit.h +++ b/uppsrc/CtrlLib/TextEdit.h @@ -101,6 +101,8 @@ public: void CachePos(int pos); + enum { CHARSET_UTF8_BOM = 250 }; + void Load(Stream& s, byte charset = CHARSET_DEFAULT); void Save(Stream& s, byte charset = CHARSET_DEFAULT, bool crlf = false) const; diff --git a/uppsrc/CtrlLib/init b/uppsrc/CtrlLib/init index 96a6bf8a2..9fa6c0a8d 100644 --- a/uppsrc/CtrlLib/init +++ b/uppsrc/CtrlLib/init @@ -2,7 +2,7 @@ #define _CtrlLib_icpp_init_stub #include "CtrlCore/init" #include "PdfDraw/init" -#define BLITZ_INDEX__ FCDD3B5FE626C4BABB0CB85A8DE59D2BC +#define BLITZ_INDEX__ FFAA79F95F953AAC96883EC967C32C291 #include "CtrlLib.icpp" #undef BLITZ_INDEX__ #endif diff --git a/uppsrc/ide/Core/Core.h b/uppsrc/ide/Core/Core.h index fe58e9de4..c0c23f172 100644 --- a/uppsrc/ide/Core/Core.h +++ b/uppsrc/ide/Core/Core.h @@ -1,411 +1,413 @@ -#ifndef COMMON_H -#define COMMON_H - -#include -#include - -using namespace Upp; - -int CharFilterCid(int c); - -int ReadLNG(CParser& p); -String MakeLNG(int lang); - -bool OldLang(); - -String PrintTime(int msecs); -inline String GetPrintTime(dword time0) { return PrintTime(msecs(time0)); } - -bool SaveChangedFile(const char *path, String data, bool delete_empty = false); - -bool IsDoc(String s); -void CopyFolder(const char *_dst, const char *_src, Index& used, bool all); - -class Workspace; - -struct Ide; - -namespace Upp { -class Ctrl; -class Image; -}; - -class IdeContext -{ -public: - virtual void PutConsole(const char *s) = 0; - virtual void PutVerbose(const char *s) = 0; - - virtual const Workspace& IdeWorkspace() const = 0; - virtual bool IdeIsBuilding() const = 0; - virtual String IdeGetOneFile() const = 0; - virtual int IdeConsoleExecute(const char *cmdline, Stream *out = NULL, const char *envptr = NULL, bool quiet = false) = 0; - virtual int IdeConsoleExecuteWithInput(const char *cmdline, Stream *out, const char *envptr, bool quiet) = 0; - virtual int IdeConsoleExecute(One process, const char *cmdline, Stream *out = NULL, bool quiet = false) = 0; - virtual int IdeConsoleAllocSlot() = 0; - virtual bool IdeConsoleRun(const char *cmdline, Stream *out = NULL, const char *envptr = NULL, bool quiet = false, int slot = 0, String key = Null, int blitz_count = 1) = 0; - virtual bool IdeConsoleRun(One process, const char *cmdline, Stream *out = NULL, bool quiet = false, int slot = 0, String key = Null, int blitz_count = 1) = 0; - virtual void IdeConsoleFlush() = 0; - virtual void IdeConsoleBeginGroup(String group) = 0; - virtual void IdeConsoleEndGroup() = 0; - virtual bool IdeConsoleWait() = 0; - - virtual bool IdeIsDebug() const = 0; - virtual void IdeEndDebug() = 0; - virtual void IdeSetBottom(Ctrl& ctrl) = 0; - virtual void IdeActivateBottom() = 0; - virtual void IdeRemoveBottom(Ctrl& ctrl) = 0; - virtual void IdeSetRight(Ctrl& ctrl) = 0; - virtual void IdeRemoveRight(Ctrl& ctrl) = 0; - - virtual String IdeGetFileName() const = 0; - virtual int IdeGetFileLine() = 0; - virtual String IdeGetLine(int i) const = 0; - - virtual void IdeSetDebugPos(const String& fn, int line, const Image& img, int i) = 0; - virtual void IdeHidePtr() = 0; - virtual bool IdeDebugLock() = 0; - virtual bool IdeDebugUnLock() = 0; - virtual bool IdeIsDebugLock() const = 0; - virtual void IdeSetBar() = 0; - virtual void IdeGotoCodeRef(String link) = 0; - virtual void IdeOpenTopicFile(const String& file) = 0; - virtual void IdeFlushFile() = 0; - virtual String IdeGetFileName() = 0; - virtual String IdeGetNestFolder() = 0; - - virtual String GetDefaultMethod(); - virtual VectorMap GetMethodVars(const String& method); - - virtual ~IdeContext() {} -}; - -IdeContext *TheIde(); -void TheIde(IdeContext *context); - -void PutConsole(const char *s); -void PutVerbose(const char *s); - -const Workspace& GetIdeWorkspace(); -bool IdeIsBuilding(); -String IdeGetOneFile(); -int IdeConsoleExecute(const char *cmdline, Stream *out = NULL, const char *envptr = NULL, bool quiet = false); -int IdeConsoleExecuteWithInput(const char *cmdline, Stream *out, const char *envptr, bool quiet); -int IdeConsoleExecute(One process, const char *cmdline, Stream *out = NULL, bool quiet = false); -int IdeConsoleAllocSlot(); -bool IdeConsoleRun(const char *cmdline, Stream *out = NULL, const char *envptr = NULL, bool quiet = false, int slot = 0, String key = Null, int blitz_count = 1); -bool IdeConsoleRun(One process, const char *cmdline, Stream *out = NULL, bool quiet = false, int slot = 0, String key = Null, int blitz_count = 1); -void IdeConsoleFlush(); -void IdeConsoleBeginGroup(String group); -void IdeConsoleEndGroup(); -bool IdeConsoleWait(); -void IdeGotoCodeRef(String s); - -String GetDefaultMethod(); -VectorMap GetMethodVars(const String& method); - -bool IdeIsDebug(); -void IdeEndDebug(); -void IdeSetBottom(Ctrl& ctrl); -void IdeActivateBottom(); -void IdeRemoveBottom(Ctrl& ctrl); -void IdeSetRight(Ctrl& ctrl); -void IdeRemoveRight(Ctrl& ctrl); - -String IdeGetFileName(); -int IdeGetFileLine(); -String IdeGetLine(int i); - -void IdeSetDebugPos(const String& fn, int line, const Image& img, int i); -void IdeHidePtr(); -bool IdeDebugLock(); -bool IdeDebugUnLock(); -bool IdeIsDebugLock(); - -void IdeSetBar(); - -#include "Host.h" - -struct IdeMacro { - IdeMacro(); - - int hotkey; - String menu; - String submenu; - EscValue code; -}; - -ArrayMap& UscGlobal(); -Array& UscMacros(); - -void UscSetCleanModules(void (*CleanModules)()); -void SetIdeModuleUsc(bool (*IdeModuleUsc)(CParser& p)); -void UscSetReadMacro(void (*ReadMacro)(CParser& p)); - -void CleanUsc(); -void ParseUscFile(const char *filename) throw(CParser::Error); - -Point ReadNums(CParser& p); -Point ReadPoint(CParser& p); - -struct SemiTextTest : public TextTest { - virtual const char *Accept(const char *s) const; -}; - -Vector SplitDirs(const char *s); - -class Nest { - VectorMap var; - VectorMap package_cache; - - String PackagePath0(const String& name); - -public: - bool Save(const char *path); - bool Load(const char *path); - String Get(const String& id); - void Set(const String& id, const String& val); - - void InvalidatePackageCache(); - String PackagePath(const String& name); -}; - -String VarFilePath(); -String VarFilePath(String name); - -bool SaveVarFile(const char *filename, const VectorMap& var); -bool LoadVarFile(const char *name, VectorMap& var); -bool SaveVars(const char *name); -bool LoadVars(const char *name); -String GetVar(const String& var); -String GetVarsName(); -String VarFilePath(); -Vector GetUppDirs(); -String GetUppDir(); -void SetVar(const String& var, const String& val, bool save = true); - -String GetAnyFileName(const char *path); -String GetAnyFileTitle(const char *path); -String CatAnyPath(String path, const char *more); - -void InvalidatePackageCache(); -String PackagePath(const String& name); -String SourcePath(const String& package, const String& name); -inline -String PackageDirectory(const String& name) { return GetFileDirectory(PackagePath(name)); } -bool IsNestReadOnly(const String& path); - -String GetLocalDir(); -String LocalPath(const String& filename); - -Vector IgnoreList(); - -bool IsFullDirectory(const String& d); -bool IsFolder(const String& path); - -bool IsCSourceFile(const char *path); -bool IsCHeaderFile(const char *path); - -String FollowCygwinSymlink(const String& filename); - -void SplitPathMap(const char *path_map, Vector& local, Vector& remote); -String JoinPathMap(const Vector& local, const Vector& remote); -void SplitHostName(const char *hostname, String& host, int& port); - -Vector SplitFlags0(const char *flags); -Vector SplitFlags(const char *flags, bool main = false); -Vector SplitFlags(const char *flags, bool main, const Vector& accepts); - -bool MatchWhen(const String& when, const Vector& flag); -String ReadWhen(CParser& p); -String AsStringWhen(const String& when); - -struct OptItem { - String when; - String text; - - String ToString() const { return when + ": " + text ; } -}; - -struct CustomStep { - String when; - String ext; - String command; - String output; - - void Load(CParser& p) throw(CParser::Error); - String AsString() const; - - String GetExt() const; - bool MatchExt(const char *fn) const; -}; - -Vector Combine(const Vector& conf, const char *flags); -String Gather(const Array& set, const Vector& conf, bool nospace = false); - -bool HasFlag(const Vector& conf, const char *flag); - -enum { - FLAG_MISMATCH = -2, - FLAG_UNDEFINED = -1, -}; - -int GetType(const Vector& conf, const char *flags); -int GetType(const Vector& conf, const char *flags, int def); -bool GetFlag(const Vector& conf, const char *flag); -String RemoveType(Vector& conf, const char *flags); - -class Package { - void Reset(); - -public: - struct File : public String { - Array option; - Array depends; - bool readonly; - bool separator; - int tabsize; - byte charset; - int font; - String highlight; - int optimize_speed; - - void operator=(const String& s) { String::operator=(s); readonly = separator = false; } - void Init() { readonly = separator = false; tabsize = Null; charset = 0; font = 0; - optimize_speed = false; } - - File() { Init(); } - File(const String& s) : String(s) { Init(); } - }; - struct Config { - String name; - String param; - }; - byte charset; - bool optimize_speed; - bool noblitz; - String description; - Vector accepts; - Array flag; - Array uses; - Array target; - Array library; - Array link; - Array option; - Array include; - Array file; - Array config; - Array custom; - Time time; - bool bold, italic; - Color ink; - - int GetCount() const { return file.GetCount(); } - File& operator[](int i) { return file[i]; } - const File& operator[](int i) const { return file[i]; } - - void Load(const char *path); - bool Save(const char *file) const; - - static void SetPackageResolver(bool (*Resolve)(const String& error, const String& path, int line)); - - Package(); -}; - -class Workspace { - void AddUses(Package& p, bool match, const Vector& flag); - void AddLoad(const String& name, bool match, const Vector& flag); - -public: - ArrayMap package; - - void Clear() { package.Clear(); } - String operator[](int i) const { return package.GetKey(i); } - Package& GetPackage(int i) { return package[i]; } - const Package& GetPackage(int i) const { return package[i]; } - int GetCount() const { return package.GetCount(); } - - void Scan(const char *prjname); - void Scan(const char *prjname, const Vector& flag); - - Vector GetAllAccepts(int pk) const; - - void Dump(); -}; - -struct Ide; - -String FindInDirs(const Vector& dir, const String& file); -String FindCommand(const Vector& exedir, const String& cmdline); - -struct MakeFile { - String outdir; - String outfile; - String output; - String config; - String install; - String rules; - String linkdep; - String linkfiles; - String linkfileend; -}; - -String GetMakePath(String fn, bool win32); -String AdjustMakePath(const char *fn); - -enum { - R_OPTIMAL, - R_SPEED, - R_SIZE -}; - -struct Builder { - Host *host; - Index config; - String compiler; - String method; - String outdir; - Vector include; - Vector libpath; - String target; - String debug_options; - String release_options; - String release_size_options; - String debug_link; - String release_link; - String version; - String script; - bool doall; - - virtual bool BuildPackage(const String& package, Vector& linkfile, String& linkoptions, - const Vector& all_uses, const Vector& all_libraries, int optimize) - { return false; } - virtual bool Link(const Vector& linkfile, const String& linkoptions, bool createmap) - { return false; } - virtual bool Preprocess(const String& package, const String& file, const String& result, bool asmout) - { return false; } - virtual void AddFlags(Index& cfg) {} - virtual void AddMakeFile(MakeFile& mfinfo, String package, - const Vector& all_uses, const Vector& all_libraries, - const Index& common_config, bool exporting) {} - virtual String GetTargetExt() const = 0; - - Builder() { doall = false; } - virtual ~Builder() {} -}; - -VectorMap& BuilderMap(); -void RegisterBuilder(const char *name, Builder *(*create)()); - -void HdependSetDirs(pick_ Vector& id); -void HdependTimeDirty(); -void HdependClearDependencies(); -void HdependAddDependency(const String& file, const String& depends); -Time HdependFileTime(const String& path); -Vector HdependGetDependencies(const String& path); -String FindIncludeFile(const char *s, const String& filedir); -bool HdependBlitzApproved(const String& path); -const Vector& HdependGetDefines(const String& path); -const Vector& HdependGetAllFiles(); - -#endif +#ifndef COMMON_H +#define COMMON_H + +#include +#include + +using namespace Upp; + +int CharFilterCid(int c); + +int ReadLNG(CParser& p); +String MakeLNG(int lang); + +bool OldLang(); + +String PrintTime(int msecs); +inline String GetPrintTime(dword time0) { return PrintTime(msecs(time0)); } + +bool SaveChangedFile(const char *path, String data, bool delete_empty = false); + +bool IsDoc(String s); +void CopyFolder(const char *_dst, const char *_src, Index& used, bool all); + +class Workspace; + +struct Ide; + +namespace Upp { +class Ctrl; +class Image; +}; + +class IdeContext +{ +public: + virtual void PutConsole(const char *s) = 0; + virtual void PutVerbose(const char *s) = 0; + + virtual const Workspace& IdeWorkspace() const = 0; + virtual bool IdeIsBuilding() const = 0; + virtual String IdeGetOneFile() const = 0; + virtual int IdeConsoleExecute(const char *cmdline, Stream *out = NULL, const char *envptr = NULL, bool quiet = false) = 0; + virtual int IdeConsoleExecuteWithInput(const char *cmdline, Stream *out, const char *envptr, bool quiet) = 0; + virtual int IdeConsoleExecute(One process, const char *cmdline, Stream *out = NULL, bool quiet = false) = 0; + virtual int IdeConsoleAllocSlot() = 0; + virtual bool IdeConsoleRun(const char *cmdline, Stream *out = NULL, const char *envptr = NULL, bool quiet = false, int slot = 0, String key = Null, int blitz_count = 1) = 0; + virtual bool IdeConsoleRun(One process, const char *cmdline, Stream *out = NULL, bool quiet = false, int slot = 0, String key = Null, int blitz_count = 1) = 0; + virtual void IdeConsoleFlush() = 0; + virtual void IdeConsoleBeginGroup(String group) = 0; + virtual void IdeConsoleEndGroup() = 0; + virtual bool IdeConsoleWait() = 0; + + virtual bool IdeIsDebug() const = 0; + virtual void IdeEndDebug() = 0; + virtual void IdeSetBottom(Ctrl& ctrl) = 0; + virtual void IdeActivateBottom() = 0; + virtual void IdeRemoveBottom(Ctrl& ctrl) = 0; + virtual void IdeSetRight(Ctrl& ctrl) = 0; + virtual void IdeRemoveRight(Ctrl& ctrl) = 0; + + virtual String IdeGetFileName() const = 0; + virtual int IdeGetFileLine() = 0; + virtual String IdeGetLine(int i) const = 0; + + virtual void IdeSetDebugPos(const String& fn, int line, const Image& img, int i) = 0; + virtual void IdeHidePtr() = 0; + virtual bool IdeDebugLock() = 0; + virtual bool IdeDebugUnLock() = 0; + virtual bool IdeIsDebugLock() const = 0; + virtual void IdeSetBar() = 0; + virtual void IdeGotoCodeRef(String link) = 0; + virtual void IdeOpenTopicFile(const String& file) = 0; + virtual void IdeFlushFile() = 0; + virtual String IdeGetFileName() = 0; + virtual String IdeGetNestFolder() = 0; + + virtual String GetDefaultMethod(); + virtual VectorMap GetMethodVars(const String& method); + + virtual ~IdeContext() {} +}; + +IdeContext *TheIde(); +void TheIde(IdeContext *context); + +void PutConsole(const char *s); +void PutVerbose(const char *s); + +const Workspace& GetIdeWorkspace(); +bool IdeIsBuilding(); +String IdeGetOneFile(); +int IdeConsoleExecute(const char *cmdline, Stream *out = NULL, const char *envptr = NULL, bool quiet = false); +int IdeConsoleExecuteWithInput(const char *cmdline, Stream *out, const char *envptr, bool quiet); +int IdeConsoleExecute(One process, const char *cmdline, Stream *out = NULL, bool quiet = false); +int IdeConsoleAllocSlot(); +bool IdeConsoleRun(const char *cmdline, Stream *out = NULL, const char *envptr = NULL, bool quiet = false, int slot = 0, String key = Null, int blitz_count = 1); +bool IdeConsoleRun(One process, const char *cmdline, Stream *out = NULL, bool quiet = false, int slot = 0, String key = Null, int blitz_count = 1); +void IdeConsoleFlush(); +void IdeConsoleBeginGroup(String group); +void IdeConsoleEndGroup(); +bool IdeConsoleWait(); +void IdeGotoCodeRef(String s); + +String GetDefaultMethod(); +VectorMap GetMethodVars(const String& method); + +bool IdeIsDebug(); +void IdeEndDebug(); +void IdeSetBottom(Ctrl& ctrl); +void IdeActivateBottom(); +void IdeRemoveBottom(Ctrl& ctrl); +void IdeSetRight(Ctrl& ctrl); +void IdeRemoveRight(Ctrl& ctrl); + +String IdeGetFileName(); +int IdeGetFileLine(); +String IdeGetLine(int i); + +void IdeSetDebugPos(const String& fn, int line, const Image& img, int i); +void IdeHidePtr(); +bool IdeDebugLock(); +bool IdeDebugUnLock(); +bool IdeIsDebugLock(); + +void IdeSetBar(); + +#include "Host.h" + +struct IdeMacro { + IdeMacro(); + + int hotkey; + String menu; + String submenu; + EscValue code; +}; + +ArrayMap& UscGlobal(); +Array& UscMacros(); + +void UscSetCleanModules(void (*CleanModules)()); +void SetIdeModuleUsc(bool (*IdeModuleUsc)(CParser& p)); +void UscSetReadMacro(void (*ReadMacro)(CParser& p)); + +void CleanUsc(); +void ParseUscFile(const char *filename) throw(CParser::Error); + +Point ReadNums(CParser& p); +Point ReadPoint(CParser& p); + +struct SemiTextTest : public TextTest { + virtual const char *Accept(const char *s) const; +}; + +Vector SplitDirs(const char *s); + +class Nest { + VectorMap var; + VectorMap package_cache; + + String PackagePath0(const String& name); + +public: + bool Save(const char *path); + bool Load(const char *path); + String Get(const String& id); + void Set(const String& id, const String& val); + + void InvalidatePackageCache(); + String PackagePath(const String& name); +}; + +String VarFilePath(); +String VarFilePath(String name); + +bool SaveVarFile(const char *filename, const VectorMap& var); +bool LoadVarFile(const char *name, VectorMap& var); +bool SaveVars(const char *name); +bool LoadVars(const char *name); +String GetVar(const String& var); +String GetVarsName(); +String VarFilePath(); +Vector GetUppDirs(); +String GetUppDir(); +void SetVar(const String& var, const String& val, bool save = true); + +String GetAnyFileName(const char *path); +String GetAnyFileTitle(const char *path); +String CatAnyPath(String path, const char *more); + +void InvalidatePackageCache(); +String PackagePath(const String& name); +String SourcePath(const String& package, const String& name); +inline +String PackageDirectory(const String& name) { return GetFileDirectory(PackagePath(name)); } +bool IsNestReadOnly(const String& path); + +String GetLocalDir(); +String LocalPath(const String& filename); + +Vector IgnoreList(); + +bool IsFullDirectory(const String& d); +bool IsFolder(const String& path); + +bool IsCSourceFile(const char *path); +bool IsCHeaderFile(const char *path); + +String FollowCygwinSymlink(const String& filename); + +void SplitPathMap(const char *path_map, Vector& local, Vector& remote); +String JoinPathMap(const Vector& local, const Vector& remote); +void SplitHostName(const char *hostname, String& host, int& port); + +Vector SplitFlags0(const char *flags); +Vector SplitFlags(const char *flags, bool main = false); +Vector SplitFlags(const char *flags, bool main, const Vector& accepts); + +bool MatchWhen(const String& when, const Vector& flag); +String ReadWhen(CParser& p); +String AsStringWhen(const String& when); + +struct OptItem { + String when; + String text; + + String ToString() const { return when + ": " + text ; } +}; + +struct CustomStep { + String when; + String ext; + String command; + String output; + + void Load(CParser& p) throw(CParser::Error); + String AsString() const; + + String GetExt() const; + bool MatchExt(const char *fn) const; +}; + +Vector Combine(const Vector& conf, const char *flags); +String Gather(const Array& set, const Vector& conf, bool nospace = false); + +bool HasFlag(const Vector& conf, const char *flag); + +enum { + FLAG_MISMATCH = -2, + FLAG_UNDEFINED = -1, +}; + +int GetType(const Vector& conf, const char *flags); +int GetType(const Vector& conf, const char *flags, int def); +bool GetFlag(const Vector& conf, const char *flag); +String RemoveType(Vector& conf, const char *flags); + +enum { CHARSET_UTF8_BOM = 250 }; // Same as TextCtrl::CHARSET_UTF8_BOM + +class Package { + void Reset(); + +public: + struct File : public String { + Array option; + Array depends; + bool readonly; + bool separator; + int tabsize; + byte charset; + int font; + String highlight; + int optimize_speed; + + void operator=(const String& s) { String::operator=(s); readonly = separator = false; } + void Init() { readonly = separator = false; tabsize = Null; charset = 0; font = 0; + optimize_speed = false; } + + File() { Init(); } + File(const String& s) : String(s) { Init(); } + }; + struct Config { + String name; + String param; + }; + byte charset; + bool optimize_speed; + bool noblitz; + String description; + Vector accepts; + Array flag; + Array uses; + Array target; + Array library; + Array link; + Array option; + Array include; + Array file; + Array config; + Array custom; + Time time; + bool bold, italic; + Color ink; + + int GetCount() const { return file.GetCount(); } + File& operator[](int i) { return file[i]; } + const File& operator[](int i) const { return file[i]; } + + void Load(const char *path); + bool Save(const char *file) const; + + static void SetPackageResolver(bool (*Resolve)(const String& error, const String& path, int line)); + + Package(); +}; + +class Workspace { + void AddUses(Package& p, bool match, const Vector& flag); + void AddLoad(const String& name, bool match, const Vector& flag); + +public: + ArrayMap package; + + void Clear() { package.Clear(); } + String operator[](int i) const { return package.GetKey(i); } + Package& GetPackage(int i) { return package[i]; } + const Package& GetPackage(int i) const { return package[i]; } + int GetCount() const { return package.GetCount(); } + + void Scan(const char *prjname); + void Scan(const char *prjname, const Vector& flag); + + Vector GetAllAccepts(int pk) const; + + void Dump(); +}; + +struct Ide; + +String FindInDirs(const Vector& dir, const String& file); +String FindCommand(const Vector& exedir, const String& cmdline); + +struct MakeFile { + String outdir; + String outfile; + String output; + String config; + String install; + String rules; + String linkdep; + String linkfiles; + String linkfileend; +}; + +String GetMakePath(String fn, bool win32); +String AdjustMakePath(const char *fn); + +enum { + R_OPTIMAL, + R_SPEED, + R_SIZE +}; + +struct Builder { + Host *host; + Index config; + String compiler; + String method; + String outdir; + Vector include; + Vector libpath; + String target; + String debug_options; + String release_options; + String release_size_options; + String debug_link; + String release_link; + String version; + String script; + bool doall; + + virtual bool BuildPackage(const String& package, Vector& linkfile, String& linkoptions, + const Vector& all_uses, const Vector& all_libraries, int optimize) + { return false; } + virtual bool Link(const Vector& linkfile, const String& linkoptions, bool createmap) + { return false; } + virtual bool Preprocess(const String& package, const String& file, const String& result, bool asmout) + { return false; } + virtual void AddFlags(Index& cfg) {} + virtual void AddMakeFile(MakeFile& mfinfo, String package, + const Vector& all_uses, const Vector& all_libraries, + const Index& common_config, bool exporting) {} + virtual String GetTargetExt() const = 0; + + Builder() { doall = false; } + virtual ~Builder() {} +}; + +VectorMap& BuilderMap(); +void RegisterBuilder(const char *name, Builder *(*create)()); + +void HdependSetDirs(pick_ Vector& id); +void HdependTimeDirty(); +void HdependClearDependencies(); +void HdependAddDependency(const String& file, const String& depends); +Time HdependFileTime(const String& path); +Vector HdependGetDependencies(const String& path); +String FindIncludeFile(const char *s, const String& filedir); +bool HdependBlitzApproved(const String& path); +const Vector& HdependGetDefines(const String& path); +const Vector& HdependGetAllFiles(); + +#endif diff --git a/uppsrc/ide/Core/Package.cpp b/uppsrc/ide/Core/Package.cpp index 84ff470ef..1a95fc79c 100644 --- a/uppsrc/ide/Core/Package.cpp +++ b/uppsrc/ide/Core/Package.cpp @@ -184,6 +184,11 @@ void Package::SetPackageResolver(bool (*Resolve)(const String& error, const Stri sResolve = Resolve; } +byte CharsetByNameX(const String& s) +{ + return s == "UTF-8-BOM" ? CHARSET_UTF8_BOM : CharsetByName(s); +} + void Package::Load(const char *path) { for(;;) { @@ -213,7 +218,7 @@ void Package::Load(const char *path) !LoadOpt(p, "uses", uses) && !LoadOpt(p, "include", include)) if(p.Id("charset")) - charset = CharsetByName(p.ReadString()); + charset = CharsetByNameX(p.ReadString()); else if(p.Id("description")) { description = p.ReadString(); @@ -273,7 +278,7 @@ void Package::Load(const char *path) file.Top().separator = true; else if(p.Id("charset")) - file.Top().charset = CharsetByName(p.ReadString()); + file.Top().charset = CharsetByNameX(p.ReadString()); else if(p.Id("tabsize")) file.Top().tabsize = minmax(p.ReadInt(), 1, 20); @@ -381,6 +386,9 @@ bool Package::Save(const char *path) const { } if(charset > 0 && charset < CharsetCount() || charset == CHARSET_UTF8) out << "charset " << AsCString(CharsetName(charset)) << ";\n\n"; + else + if(charset == CHARSET_UTF8_BOM) + out << "charset \"UTF-8-BOM\";\n\n"; if(optimize_speed) out << "optimize_speed;\n\n"; if(noblitz) @@ -412,6 +420,9 @@ bool Package::Save(const char *path) const { out << " optimize_speed"; if(f.charset > 0 && f.charset < CharsetCount() || f.charset == CHARSET_UTF8) out << " charset " << AsCString(CharsetName(f.charset)); + else + if(f.charset == CHARSET_UTF8_BOM) + out << " charset \"UTF-8-BOM\""; if(!IsNull(f.highlight)) out << " highlight " << f.highlight; putfopt(out, "options", f.option); diff --git a/uppsrc/ide/Setup.cpp b/uppsrc/ide/Setup.cpp index fcbbe86bd..86f9fcad7 100644 --- a/uppsrc/ide/Setup.cpp +++ b/uppsrc/ide/Setup.cpp @@ -10,6 +10,7 @@ int CharFilterVar(int c) void DlCharset(DropList& d) { d.Add(CHARSET_UTF8, "UTF8"); + d.Add(TextCtrl::CHARSET_UTF8_BOM, "UTF8 BOM"); for(int i = 1; i < CharsetCount(); i++) d.Add(i, CharsetName(i)); } diff --git a/uppsrc/ide/ide.cpp b/uppsrc/ide/ide.cpp index f8a3a490f..479156da1 100644 --- a/uppsrc/ide/ide.cpp +++ b/uppsrc/ide/ide.cpp @@ -23,7 +23,8 @@ void Ide::MakeTitle() else if(!editfile.IsEmpty()) { title << " - [" << editfile; - title << " " << CharsetName(editor.GetCharset()); + int chrset = editor.GetCharset(); + title << " " << (chrset == TextCtrl::CHARSET_UTF8_BOM ? "UTF-8 BOM" : CharsetName(chrset)); if(editor.IsReadOnly()) title << " (Read Only)"; if(editor.IsDirty())