diff --git a/bazaar/Functions4U/Functions4U.cpp b/bazaar/Functions4U/Functions4U.cpp index c224ba5f8..c6ce2df79 100644 --- a/bazaar/Functions4U/Functions4U.cpp +++ b/bazaar/Functions4U/Functions4U.cpp @@ -1967,6 +1967,33 @@ void *Dl::GetFunction(const String &functionName) { #endif + +Image Rotate180(const Image& orig) { + Size sz = orig.GetSize(); + ImageBuffer dest(sz); + for(int rw = 0; rw < sz.cy; rw++) + for(int cl = 0; cl < sz.cx; cl++) + dest[rw][cl] = orig[sz.cy - rw - 1][sz.cx - cl - 1]; + return dest; +} + +Image GetRect(const Image& orig, const Rect &r) { + if(r.IsEmpty()) + return Image(); + ImageBuffer ib(r.GetSize()); + for(int y = r.top; y < r.bottom; y++) { + const RGBA *s = orig[y] + r.left; + const RGBA *e = orig[y] + r.right; + RGBA *t = ib[y - r.top]; + while(s < e) { + *t = *s; + t++; + s++; + } + } + return ib; +} + #ifdef flagAES static String sXMLFile(const char *file) diff --git a/bazaar/Functions4U/Functions4U.h b/bazaar/Functions4U/Functions4U.h index cd4229068..a2b7ade0d 100644 --- a/bazaar/Functions4U/Functions4U.h +++ b/bazaar/Functions4U/Functions4U.h @@ -1,514 +1,520 @@ -#ifndef _Functions4U_Functions4U_h -#define _Functions4U_Functions4U_h - -#include -#include -#include "GatherTpp.h" -#include "SvgColors.h" - -enum EXT_FILE_FLAGS {USE_TRASH_BIN = 1, - BROWSE_LINKS = 2, - DELETE_READ_ONLY = 4, - ASK_BEFORE_DELETE = 8 -}; - -bool LaunchFile(const char *file); - -bool FileCat(const char *file, const char *appendFile); - -bool FileStrAppend(const char *file, const char *str); -bool AppendFile(const char *filename, const char *str); - -String AppendFileName(const String& path1, const char *path2, const char *path3); - -inline String Trim(const String& s) {return TrimLeft(TrimRight(s));}; - -///////// -bool DirectoryExistsX(const char *path, int flags = 0); -/////////////////////////////// -bool DirectoryDeleteX(const char *path, int flags = 0); -bool DirectoryDeleteDeepX(const char *path, int flags = 0); -bool DeleteFolderDeepX(const char *dir, int flags = 0); -bool DirectoryCopyX(const char *dir, const char *newPlace); -bool DeleteFolderDeepWildcards(const char *dir, int flags = 0); -/////////////////////////////// - -bool UpperFolder(String folderName); -String GetUpperFolder(String folderName); -String GetNextFolder(String folder, String lastFolder); -String GetRealName(String fileName); - -//bool GetSymLinkPath(const char *linkPath, String &filePath); -bool IsSymLink(const char *path); - -bool CreateFolderDeep(const char *dir); - -///////// -bool FileMoveX(const char *oldpath, const char *newpath, int flags = 0); -bool FileDeleteX(const char *path, int flags = 0); -///////// - - -//bool FileSetReadOnly(const char *fileName, bool readOnly); -bool FileSetReadOnly(const char *fileName, bool usr, bool grp = false, bool oth = false); -bool IsReadOnly(const char *fileName, bool &usr, bool &grp, bool &oth); - -String LoadFile_Safe(String fileName); - -int64 GetLength(String fileDirName); -int64 GetDirectoryLength(String directoryName); - -/////////////////////////////// -Array SearchFile(String dir, String condFile, String text, Array &errorList);//, int flags = 0); -Array SearchFile(String dir, String condFile, String text = "");//, int flags = 0); -/////////////////////////////// - -bool FileToTrashBin(const char *path); -int64 TrashBinGetCount(); -bool TrashBinClear(); - -//String GetDesktopFolder(); -//String GetProgramsFolder(); -//String GetAppDataFolder(); -//String GetMusicFolder(); -//String GetPicturesFolder(); -//String GetVideoFolder(); -String GetPersonalFolder(); -//String GetTemplatesFolder(); -//String GetDownloadFolder(); -String GetRootFolder(); -String GetTempFolder(); -String GetOsFolder(); -String GetSystemFolder(); - - -struct FileData : Moveable { - bool isFolder; - String fileName; - String relFilename; - int64 length; - struct Upp::Time t; - int64 id; - - String ToString() const { return Format("%s %0n", fileName, length); } - - FileData(bool isFolder, String fileName, String relFilename, int64 length, struct Upp::Time t, uint64 id) : isFolder(isFolder), fileName(fileName), relFilename(relFilename), length(length), t(t), id(id) {} - FileData() {} -}; - -struct FileDiff { - char action; // 'n': New, 'u': Update, 'd': Delete, 'p': Problem - bool isFolder; - String relPath; - String fileName; - uint64 idMaster, idSecondary; - struct Upp::Time tMaster, tSecondary; - uint64 lengthMaster, lengthSecondary; -}; - -class ErrorHandling -{ -public: - void SetLastError(String _lastError) {lastError = _lastError;}; - String GetLastError() {return lastError;}; - -private: - String lastError; -}; - -class FileDiffArray; - -class FileDataArray : public ErrorHandling -{ -public: - FileDataArray(bool use = false, int fileFlags = 0); - bool Init(String folder, FileDataArray &orig, FileDiffArray &diff); - void Clear(); - bool Search(String dir, String condFile, bool recurse = false, String text = ""); - FileData& operator[](long i) {return fileList[i];} - long GetFileCount() {return fileCount;}; - long GetFolderCount() {return folderCount;}; - long GetCount() {return fileCount + folderCount;}; - int64 GetSize() {return fileSize;}; - inline bool UseId() {return useId;}; - void SortByName(bool ascending = true); - void SortByDate(bool ascending = true); - void SortBySize(bool ascending = true); - Array &GetLastError() {return errorList;}; - int Find(String &relFileName, String &fileName, bool isFolder); - int Find(FileDataArray &data, int id); - String FullFileName(int i) {return AppendFileName(basePath, fileList[i].fileName);}; - bool SaveFile(const char *fileName); - bool AppendFile(const char *fileName); - bool LoadFile(const char *fileName); - -private: - void Search_Each(String dir, String condFile, bool recurse, String text); - int64 GetFileId(String fileName); - String GetRelativePath(String fullPath); - String GetFileText(); - - Array fileList; - Array errorList; - String basePath; - long fileCount, folderCount; - int64 fileSize; - bool useId; - int fileFlags; -}; - -class FileDiffArray : public ErrorHandling -{ -public: - FileDiffArray(); - void Clear(); - FileDiff& operator[](long i) {return diffList[i];} - bool Compare(FileDataArray &master, FileDataArray &secondary, String &folderFrom, Array &excepFolders, Array &excepFiles); - bool Apply(String toFolder, String fromFolder, int flags = 0); - long GetCount() {return diffList.GetCount();}; - bool SaveFile(const char *fileName); - bool LoadFile(const char *fileName); - String ToString(); - -private: - Array diffList; -}; - - -String Replace(String str, String find, String replace); -String Replace(String str, char find, char replace); - -int ReverseFind(const String& s, const String& toFind, int from = 0); - -String FormatLong(long a); - -const char *StrToTime(struct Upp::Time& d, const char *s); -::Time StrToTime(const char *s); -::Date StrToDate(const char *s); - -String BytesToString(uint64 bytes); - -String SecondsToString(double seconds, bool units = false); -String HMSToString(int hour, int min, double seconds, bool units = false); -double StringToSeconds(String str); // The opposite -void StringToHMS(String durat, int &hour, int &min, double &seconds); - -String FormatDoubleAdjust(double d, double range); - -String RemoveAccents(String str); -bool IsPunctuation(wchar c); - -inline double ToRad(double angle) {return angle*M_PI/180;} -inline double ToDeg(double angle) {return angle*180/M_PI;} - -inline bool Odd(int val) {return val%2;} -inline bool Even(int val) {return !Odd(val);} -inline int RoundEven(int val) {return Even(val) ? val : val+1;} -template -inline int Sign(T a) {return (a > 0) - (a < 0);} -template -inline T Average(T a, T b) {return T((a+b)/2);} -template -inline T Average(T a, T b, T c) {return T((a+b+c)/3);} -template -inline T Average(T a, T b, T c, T d){return T((a+b+c+d)/4);} -template -inline const T& min(const T& a, const T& b, const T& c) { - return a < b ? (a < c ? a : c) : ((b < c) ? b : c); } -template -inline const T& min(const T& a, const T& b, const T& c, const T& d) { - T ab = min(a, b); - T cd = min(c, d); - return ab < cd ? ab : cd; -} -template -inline const T& max(const T& a, const T& b, const T& c) { - return a > b ? (a > c ? a : c) : ((b > c) ? b : c); } -template -inline const T& max(const T& a, const T& b, const T& c, const T& d) { - T ab = max(a, b); - T cd = max(c, d); - return ab > cd ? ab : cd; -} - -int DayOfYear(Date d); - -// Fits object centered into frame maintaining the aspect -template -Rect_ FitInFrame(const Size_ &frame, const Size_ &object) -{ - double frameAspect = frame.cx/(double)frame.cy; - double objectAspect = object.cx/(double)object.cy; - - if (frameAspect > objectAspect) { - double x = (frame.cx - objectAspect*frame.cy)/2.; - return Rect_((T)x, 0, (T)(x + objectAspect*frame.cy), frame.cy); - } else { - double y = (frame.cy - frame.cx/objectAspect)/2.; - return Rect_(0, (T)y, frame.cx, (T)(y + frame.cx/objectAspect)); - } -} - -Color RandomColor(); - -// A String based class to parse into -class StringParse : public String { -public: - void GoInit() {pos = 0; lastSeparator='\0';}; - StringParse():String("") {GoInit();}; - StringParse(String s): String(s) {GoInit();}; - bool GoBefore(const String text) - { - if (pos >= GetLength()) { - pos = GetLength()-1; - return false; - } - int newpos = String::Find(text, pos); - if (newpos < 0) - return false; // If it does not find it, it does not move - pos = newpos; - return true; - }; - bool GoAfter(const String text) - { - if(!GoBefore(text)) - return false; - pos += strlen(text); - return true; - }; - bool GoAfter(const String text, const String text2) - { - if(!GoAfter(text)) - return false; - if(!GoAfter(text2)) - return false; - return true; - }; - bool GoAfter(const String text, const String text2, const String text3) - { - if(!GoAfter(text)) - return false; - if(!GoAfter(text2)) - return false; - if(!GoAfter(text3)) - return false; - return true; - }; - bool GoAfter_Init(const String text) {GoInit(); return GoAfter(text);}; - bool GoAfter_Init(const String text, const String text2) {GoInit(); return GoAfter(text, text2);}; - bool GoAfter_Init(const String text, const String text2, const String text3) {GoInit(); return GoAfter(text, text2, text3);}; - - void GoBeginLine() - { - for (; pos >= 0; --pos) { - if ((ToString()[pos-1] == '\r') || (ToString()[pos-1] == '\n')) - return; - } - } - bool IsBeginLine() - { - if (pos == 0) - return true; - if ((ToString()[pos-1] == '\r') || (ToString()[pos-1] == '\n')) - return true; - return false; - } - bool IsSpaceRN(int c) - { - if (IsSpace(c)) - return true; - if ((c == '\r') || (c == '\n')) - return true; - return false; - } - // Gets text between "" or just a word until an space - // It considers special characters with \ if between "" - // If not between "" it gets the word when it finds one of the separator characters - String GetText(String separators = "") - { - String ret = ""; - if (pos > GetCount()) - return ret; - int newpos = pos; - - while ((IsSpaceRN(ToString()[newpos]) && (ToString()[newpos] != '\"') && - (ToString()[newpos] != '\0'))) - newpos++; - if (ToString()[newpos] == '\0') { - pos = newpos; - return ""; - } - - if (ToString()[newpos] == '\"') { // Between "" - newpos++; - while (ToString()[newpos] != '\"' && ToString()[newpos] != '\0') { - if (ToString()[newpos] == '\\') { - newpos++; - if (ToString()[newpos] == '\0') - return ""; - } - ret.Cat(ToString()[newpos]); - newpos++; - } - lastSeparator = '"'; - } else if (separators == "") { // Simple word - while (!IsSpaceRN(ToString()[newpos]) && ToString()[newpos] != '\0') { - if (ToString()[newpos] == '\"') { - newpos--; // This " belongs to the next - break; - } - ret.Cat(ToString()[newpos]); - newpos++; - } - lastSeparator = ToString()[newpos]; - } else { // Simple word, special separator - while (ToString()[newpos] != '\0') {// Only consider included spaces (!IsSpaceRN(ToString()[newpos]) && ToString()[newpos] != '\0') { - if (ToString()[newpos] == '\"') { - newpos--; // This " belongs to the next - break; - } - if (separators.Find(ToString()[newpos]) >= 0) { - lastSeparator = ToString()[newpos]; - break; - } - ret.Cat(ToString()[newpos]); - newpos++; - } - lastSeparator = ToString()[newpos]; - } - pos = ++newpos; // After the separator: ", space or separator - return ret; - } - String GetLine() - { - return GetText("\r\n"); - } - double GetDouble(String separators = "") {return atof(GetText(separators));}; - int GetInt(String separators = "") {return atoi(GetText(separators));}; - long GetLong(String separators = "") {return atol(GetText(separators));}; - uint64 GetUInt64(String separators = "") -#if defined(PLATFORM_WIN32) - {return _atoi64(GetText(separators));}; -#endif -#ifdef PLATFORM_POSIX - {return atoll(GetText(separators));}; -#endif - - String Right() {return String::Mid(pos+1);} - int GetLastSeparator() {return lastSeparator;} - void MoveRel(int val) - { - pos += val; - if (pos < 0) - pos = 0; - else if (pos >= GetCount()) - pos = GetCount() - 1; - } - int GetPos() {return pos;}; - bool SetPos(int i) - { - if (i < 0 || i >= GetCount()) - return false; - else { - pos = i; - return true; - } - } - bool Eof() - { - return pos >= GetCount(); - } - unsigned Count(String s) - { - int from = 0; - unsigned count = 0; - - while ((from = ToString().Find(s, from)) >= 0) { - count++; - from++; - } - return count; - } -private: - int pos; - int lastSeparator; -}; - -#if defined(PLATFORM_WIN32) -Value GetVARIANT(VARIANT &result); -String WideToString(LPCWSTR wcs, int len = -1); -#endif - -#ifdef CTRLLIB_H - #include "Functions4U/Functions4U_Gui.h" -#endif - -/* -// A ProcessEvents than can be used in non gui programs -inline void DoEvents() { -#ifdef CTRLLIB_H - Ctrl::ProcessEvents(); -#endif -} -*/ - -String GetExtExecutable(String ext); - -Array GetDriveList(); - -String Getcwd(); -bool Chdir (const String &folder); - -//String Format(Time time, const char*fmt = "%2d:%2d"); - -class Dl { -public: - Dl(); - ~Dl(); - bool Load(const String &fileDll); - void *GetFunction(const String &functionName); - -private: -#if defined(PLATFORM_WIN32) - HINSTANCE hinstLib; -#else - void *hinstLib; -#endif -}; - -typedef Dl Dll; - -//bool RunFromMemory(const String &progBuffer, const String &name); - - -String BsGetLastError(); -bool BSPatch(String oldfile, String newfile, String patchfile); -bool BSDiff(String oldfile, String newfile, String patchfile); - -bool LoadFromXMLFileAES(Callback1 xmlize, const char *file, const char *key); -template -bool LoadFromXMLFileAES(T& data, const char *file, const char *key) -{ - ParamHelper__ p(data); - return LoadFromXMLFileAES(callback(&p, &ParamHelper__::Invoke), file, key); -} - -bool StoreAsXMLFileAES(Callback1 xmlize, const char *name, const char *file, const char *key); -template -bool StoreAsXMLFileAES(T& data, const char *name, const char *file, const char *key) -{ - ParamHelper__ p(data); - return StoreAsXMLFileAES(callback(&p, &ParamHelper__::Invoke), name, file, key); -} - -#ifdef flagAES - -#include -#include - -bool LoadFromXMLFileAES(Callback1 xmlize, const char *file, const char *key); -bool StoreAsXMLFileAES(Callback1 xmlize, const char *name, const char *file, const char *key); - -#endif - -#endif +#ifndef _Functions4U_Functions4U_h +#define _Functions4U_Functions4U_h + +#include +#ifdef flagGUI +#include +#include +#include "GatherTpp.h" +#endif +#include "SvgColors.h" + +enum EXT_FILE_FLAGS {USE_TRASH_BIN = 1, + BROWSE_LINKS = 2, + DELETE_READ_ONLY = 4, + ASK_BEFORE_DELETE = 8 +}; + +bool LaunchFile(const char *file); + +bool FileCat(const char *file, const char *appendFile); + +bool FileStrAppend(const char *file, const char *str); +bool AppendFile(const char *filename, const char *str); + +String AppendFileName(const String& path1, const char *path2, const char *path3); + +inline String Trim(const String& s) {return TrimLeft(TrimRight(s));}; + +///////// +bool DirectoryExistsX(const char *path, int flags = 0); +/////////////////////////////// +bool DirectoryDeleteX(const char *path, int flags = 0); +bool DirectoryDeleteDeepX(const char *path, int flags = 0); +bool DeleteFolderDeepX(const char *dir, int flags = 0); +bool DirectoryCopyX(const char *dir, const char *newPlace); +bool DeleteFolderDeepWildcards(const char *dir, int flags = 0); +/////////////////////////////// + +bool UpperFolder(String folderName); +String GetUpperFolder(String folderName); +String GetNextFolder(String folder, String lastFolder); +String GetRealName(String fileName); + +//bool GetSymLinkPath(const char *linkPath, String &filePath); +bool IsSymLink(const char *path); + +bool CreateFolderDeep(const char *dir); + +///////// +bool FileMoveX(const char *oldpath, const char *newpath, int flags = 0); +bool FileDeleteX(const char *path, int flags = 0); +///////// + + +//bool FileSetReadOnly(const char *fileName, bool readOnly); +bool FileSetReadOnly(const char *fileName, bool usr, bool grp = false, bool oth = false); +bool IsReadOnly(const char *fileName, bool &usr, bool &grp, bool &oth); + +String LoadFile_Safe(String fileName); + +int64 GetLength(String fileDirName); +int64 GetDirectoryLength(String directoryName); + +/////////////////////////////// +Array SearchFile(String dir, String condFile, String text, Array &errorList);//, int flags = 0); +Array SearchFile(String dir, String condFile, String text = "");//, int flags = 0); +/////////////////////////////// + +bool FileToTrashBin(const char *path); +int64 TrashBinGetCount(); +bool TrashBinClear(); + +//String GetDesktopFolder(); +//String GetProgramsFolder(); +//String GetAppDataFolder(); +//String GetMusicFolder(); +//String GetPicturesFolder(); +//String GetVideoFolder(); +String GetPersonalFolder(); +//String GetTemplatesFolder(); +//String GetDownloadFolder(); +String GetRootFolder(); +String GetTempFolder(); +String GetOsFolder(); +String GetSystemFolder(); + + +struct FileData : Moveable { + bool isFolder; + String fileName; + String relFilename; + int64 length; + struct Upp::Time t; + int64 id; + + String ToString() const { return Format("%s %0n", fileName, length); } + + FileData(bool isFolder, String fileName, String relFilename, int64 length, struct Upp::Time t, uint64 id) : isFolder(isFolder), fileName(fileName), relFilename(relFilename), length(length), t(t), id(id) {} + FileData() {} +}; + +struct FileDiff { + char action; // 'n': New, 'u': Update, 'd': Delete, 'p': Problem + bool isFolder; + String relPath; + String fileName; + uint64 idMaster, idSecondary; + struct Upp::Time tMaster, tSecondary; + uint64 lengthMaster, lengthSecondary; +}; + +class ErrorHandling +{ +public: + void SetLastError(String _lastError) {lastError = _lastError;}; + String GetLastError() {return lastError;}; + +private: + String lastError; +}; + +class FileDiffArray; + +class FileDataArray : public ErrorHandling +{ +public: + FileDataArray(bool use = false, int fileFlags = 0); + bool Init(String folder, FileDataArray &orig, FileDiffArray &diff); + void Clear(); + bool Search(String dir, String condFile, bool recurse = false, String text = ""); + FileData& operator[](long i) {return fileList[i];} + long GetFileCount() {return fileCount;}; + long GetFolderCount() {return folderCount;}; + long GetCount() {return fileCount + folderCount;}; + int64 GetSize() {return fileSize;}; + inline bool UseId() {return useId;}; + void SortByName(bool ascending = true); + void SortByDate(bool ascending = true); + void SortBySize(bool ascending = true); + Array &GetLastError() {return errorList;}; + int Find(String &relFileName, String &fileName, bool isFolder); + int Find(FileDataArray &data, int id); + String FullFileName(int i) {return AppendFileName(basePath, fileList[i].fileName);}; + bool SaveFile(const char *fileName); + bool AppendFile(const char *fileName); + bool LoadFile(const char *fileName); + +private: + void Search_Each(String dir, String condFile, bool recurse, String text); + int64 GetFileId(String fileName); + String GetRelativePath(String fullPath); + String GetFileText(); + + Array fileList; + Array errorList; + String basePath; + long fileCount, folderCount; + int64 fileSize; + bool useId; + int fileFlags; +}; + +class FileDiffArray : public ErrorHandling +{ +public: + FileDiffArray(); + void Clear(); + FileDiff& operator[](long i) {return diffList[i];} + bool Compare(FileDataArray &master, FileDataArray &secondary, String &folderFrom, Array &excepFolders, Array &excepFiles); + bool Apply(String toFolder, String fromFolder, int flags = 0); + long GetCount() {return diffList.GetCount();}; + bool SaveFile(const char *fileName); + bool LoadFile(const char *fileName); + String ToString(); + +private: + Array diffList; +}; + + +String Replace(String str, String find, String replace); +String Replace(String str, char find, char replace); + +int ReverseFind(const String& s, const String& toFind, int from = 0); + +String FormatLong(long a); + +const char *StrToTime(struct Upp::Time& d, const char *s); +::Time StrToTime(const char *s); +::Date StrToDate(const char *s); + +String BytesToString(uint64 bytes); + +String SecondsToString(double seconds, bool units = false); +String HMSToString(int hour, int min, double seconds, bool units = false); +double StringToSeconds(String str); // The opposite +void StringToHMS(String durat, int &hour, int &min, double &seconds); + +String FormatDoubleAdjust(double d, double range); + +String RemoveAccents(String str); +bool IsPunctuation(wchar c); + +inline double ToRad(double angle) {return angle*M_PI/180;} +inline double ToDeg(double angle) {return angle*180/M_PI;} + +inline bool Odd(int val) {return val%2;} +inline bool Even(int val) {return !Odd(val);} +inline int RoundEven(int val) {return Even(val) ? val : val+1;} +template +inline int Sign(T a) {return (a > 0) - (a < 0);} +template +inline T Average(T a, T b) {return T((a+b)/2);} +template +inline T Average(T a, T b, T c) {return T((a+b+c)/3);} +template +inline T Average(T a, T b, T c, T d){return T((a+b+c+d)/4);} +template +inline const T& min(const T& a, const T& b, const T& c) { + return a < b ? (a < c ? a : c) : ((b < c) ? b : c); } +template +inline const T& min(const T& a, const T& b, const T& c, const T& d) { + T ab = min(a, b); + T cd = min(c, d); + return ab < cd ? ab : cd; +} +template +inline const T& max(const T& a, const T& b, const T& c) { + return a > b ? (a > c ? a : c) : ((b > c) ? b : c); } +template +inline const T& max(const T& a, const T& b, const T& c, const T& d) { + T ab = max(a, b); + T cd = max(c, d); + return ab > cd ? ab : cd; +} + +int DayOfYear(Date d); + +// Fits object centered into frame maintaining the aspect +template +Rect_ FitInFrame(const Size_ &frame, const Size_ &object) +{ + double frameAspect = frame.cx/(double)frame.cy; + double objectAspect = object.cx/(double)object.cy; + + if (frameAspect > objectAspect) { + double x = (frame.cx - objectAspect*frame.cy)/2.; + return Rect_((T)x, 0, (T)(x + objectAspect*frame.cy), frame.cy); + } else { + double y = (frame.cy - frame.cx/objectAspect)/2.; + return Rect_(0, (T)y, frame.cx, (T)(y + frame.cx/objectAspect)); + } +} + +Color RandomColor(); + +// A String based class to parse into +class StringParse : public String { +public: + void GoInit() {pos = 0; lastSeparator='\0';}; + StringParse():String("") {GoInit();}; + StringParse(String s): String(s) {GoInit();}; + bool GoBefore(const String text) + { + if (pos >= GetLength()) { + pos = GetLength()-1; + return false; + } + int newpos = String::Find(text, pos); + if (newpos < 0) + return false; // If it does not find it, it does not move + pos = newpos; + return true; + }; + bool GoAfter(const String text) + { + if(!GoBefore(text)) + return false; + pos += strlen(text); + return true; + }; + bool GoAfter(const String text, const String text2) + { + if(!GoAfter(text)) + return false; + if(!GoAfter(text2)) + return false; + return true; + }; + bool GoAfter(const String text, const String text2, const String text3) + { + if(!GoAfter(text)) + return false; + if(!GoAfter(text2)) + return false; + if(!GoAfter(text3)) + return false; + return true; + }; + bool GoAfter_Init(const String text) {GoInit(); return GoAfter(text);}; + bool GoAfter_Init(const String text, const String text2) {GoInit(); return GoAfter(text, text2);}; + bool GoAfter_Init(const String text, const String text2, const String text3) {GoInit(); return GoAfter(text, text2, text3);}; + + void GoBeginLine() + { + for (; pos >= 0; --pos) { + if ((ToString()[pos-1] == '\r') || (ToString()[pos-1] == '\n')) + return; + } + } + bool IsBeginLine() + { + if (pos == 0) + return true; + if ((ToString()[pos-1] == '\r') || (ToString()[pos-1] == '\n')) + return true; + return false; + } + bool IsSpaceRN(int c) + { + if (IsSpace(c)) + return true; + if ((c == '\r') || (c == '\n')) + return true; + return false; + } + // Gets text between "" or just a word until an space + // It considers special characters with \ if between "" + // If not between "" it gets the word when it finds one of the separator characters + String GetText(String separators = "") + { + String ret = ""; + if (pos > GetCount()) + return ret; + int newpos = pos; + + while ((IsSpaceRN(ToString()[newpos]) && (ToString()[newpos] != '\"') && + (ToString()[newpos] != '\0'))) + newpos++; + if (ToString()[newpos] == '\0') { + pos = newpos; + return ""; + } + + if (ToString()[newpos] == '\"') { // Between "" + newpos++; + while (ToString()[newpos] != '\"' && ToString()[newpos] != '\0') { + if (ToString()[newpos] == '\\') { + newpos++; + if (ToString()[newpos] == '\0') + return ""; + } + ret.Cat(ToString()[newpos]); + newpos++; + } + lastSeparator = '"'; + } else if (separators == "") { // Simple word + while (!IsSpaceRN(ToString()[newpos]) && ToString()[newpos] != '\0') { + if (ToString()[newpos] == '\"') { + newpos--; // This " belongs to the next + break; + } + ret.Cat(ToString()[newpos]); + newpos++; + } + lastSeparator = ToString()[newpos]; + } else { // Simple word, special separator + while (ToString()[newpos] != '\0') {// Only consider included spaces (!IsSpaceRN(ToString()[newpos]) && ToString()[newpos] != '\0') { + if (ToString()[newpos] == '\"') { + newpos--; // This " belongs to the next + break; + } + if (separators.Find(ToString()[newpos]) >= 0) { + lastSeparator = ToString()[newpos]; + break; + } + ret.Cat(ToString()[newpos]); + newpos++; + } + lastSeparator = ToString()[newpos]; + } + pos = ++newpos; // After the separator: ", space or separator + return ret; + } + String GetLine() + { + return GetText("\r\n"); + } + double GetDouble(String separators = "") {return atof(GetText(separators));}; + int GetInt(String separators = "") {return atoi(GetText(separators));}; + long GetLong(String separators = "") {return atol(GetText(separators));}; + uint64 GetUInt64(String separators = "") +#if defined(PLATFORM_WIN32) + {return _atoi64(GetText(separators));}; +#endif +#ifdef PLATFORM_POSIX + {return atoll(GetText(separators));}; +#endif + + String Right() {return String::Mid(pos+1);} + int GetLastSeparator() {return lastSeparator;} + void MoveRel(int val) + { + pos += val; + if (pos < 0) + pos = 0; + else if (pos >= GetCount()) + pos = GetCount() - 1; + } + int GetPos() {return pos;}; + bool SetPos(int i) + { + if (i < 0 || i >= GetCount()) + return false; + else { + pos = i; + return true; + } + } + bool Eof() + { + return pos >= GetCount(); + } + unsigned Count(String s) + { + int from = 0; + unsigned count = 0; + + while ((from = ToString().Find(s, from)) >= 0) { + count++; + from++; + } + return count; + } +private: + int pos; + int lastSeparator; +}; + +#if defined(PLATFORM_WIN32) +Value GetVARIANT(VARIANT &result); +String WideToString(LPCWSTR wcs, int len = -1); +#endif + +#ifdef CTRLLIB_H + #include "Functions4U/Functions4U_Gui.h" +#endif + +/* +// A ProcessEvents than can be used in non gui programs +inline void DoEvents() { +#ifdef CTRLLIB_H + Ctrl::ProcessEvents(); +#endif +} +*/ + +String GetExtExecutable(String ext); + +Array GetDriveList(); + +String Getcwd(); +bool Chdir (const String &folder); + +//String Format(Time time, const char*fmt = "%2d:%2d"); + +class Dl { +public: + Dl(); + ~Dl(); + bool Load(const String &fileDll); + void *GetFunction(const String &functionName); + +private: +#if defined(PLATFORM_WIN32) + HINSTANCE hinstLib; +#else + void *hinstLib; +#endif +}; + +typedef Dl Dll; + +//bool RunFromMemory(const String &progBuffer, const String &name); + + +String BsGetLastError(); +bool BSPatch(String oldfile, String newfile, String patchfile); +bool BSDiff(String oldfile, String newfile, String patchfile); + +bool LoadFromXMLFileAES(Callback1 xmlize, const char *file, const char *key); +template +bool LoadFromXMLFileAES(T& data, const char *file, const char *key) +{ + ParamHelper__ p(data); + return LoadFromXMLFileAES(callback(&p, &ParamHelper__::Invoke), file, key); +} + +bool StoreAsXMLFileAES(Callback1 xmlize, const char *name, const char *file, const char *key); +template +bool StoreAsXMLFileAES(T& data, const char *name, const char *file, const char *key) +{ + ParamHelper__ p(data); + return StoreAsXMLFileAES(callback(&p, &ParamHelper__::Invoke), name, file, key); +} + +Image Rotate180(const Image& img); +Image GetRect(const Image& orig, const Rect &r); + +#ifdef flagAES + +#include +#include + +bool LoadFromXMLFileAES(Callback1 xmlize, const char *file, const char *key); +bool StoreAsXMLFileAES(Callback1 xmlize, const char *name, const char *file, const char *key); + +#endif + +#endif diff --git a/bazaar/Functions4U/Functions4U.upp b/bazaar/Functions4U/Functions4U.upp index 704c4cc32..456579265 100644 --- a/bazaar/Functions4U/Functions4U.upp +++ b/bazaar/Functions4U/Functions4U.upp @@ -3,8 +3,10 @@ description "Functions and classes for general use\377B255,170,0"; uses Core, plugin\bz2, - ide/Browser, - Web; + Web, + Draw; + +uses(GUI) ide/Browser; uses(AES) AESStream; diff --git a/bazaar/Functions4U/Functions4U_Gui.cpp b/bazaar/Functions4U/Functions4U_Gui.cpp index 68513a21f..5195b42ef 100644 --- a/bazaar/Functions4U/Functions4U_Gui.cpp +++ b/bazaar/Functions4U/Functions4U_Gui.cpp @@ -1,36 +1,9 @@ #ifdef flagGUI #include -//#include #include "Functions4U.h" -Image Rotate180(const Image& orig) { - Size sz = orig.GetSize(); - ImageBuffer dest(sz); - for(int rw = 0; rw < sz.cy; rw++) - for(int cl = 0; cl < sz.cx; cl++) - dest[rw][cl] = orig[sz.cy - rw - 1][sz.cx - cl - 1]; - return dest; -} - -Image GetRect(const Image& orig, const Rect &r) { - if(r.IsEmpty()) - return Image(); - ImageBuffer ib(r.GetSize()); - for(int y = r.top; y < r.bottom; y++) { - const RGBA *s = orig[y] + r.left; - const RGBA *e = orig[y] + r.right; - RGBA *t = ib[y - r.top]; - while(s < e) { - *t = *s; - t++; - s++; - } - } - return ib; -} - Image NativePathIconX(const char *path, bool folder, int flags) { if (!(flags & BROWSE_LINKS)) diff --git a/bazaar/Functions4U/Functions4U_Gui.h b/bazaar/Functions4U/Functions4U_Gui.h index 8d04efda8..22e2ae257 100644 --- a/bazaar/Functions4U/Functions4U_Gui.h +++ b/bazaar/Functions4U/Functions4U_Gui.h @@ -11,9 +11,6 @@ inline RGBA *GetPixel(ImageBuffer &img, int x, int y) { return img + x + y*img.GetWidth(); } -Image Rotate180(const Image& img); -Image GetRect(const Image& orig, const Rect &r); - Drawing DrawEquation(String str); QtfRichObject QtfEquation(String str); diff --git a/bazaar/Functions4U/GatherTpp.cpp b/bazaar/Functions4U/GatherTpp.cpp index 6501e12ed..cb3fced73 100644 --- a/bazaar/Functions4U/GatherTpp.cpp +++ b/bazaar/Functions4U/GatherTpp.cpp @@ -1,341 +1,343 @@ -#include -#include - -using namespace Upp; - -#include "Functions4U/Functions4U.h" -#include "GatherTpp.h" - -struct ScanTopicIterator : RichText::Iterator { - VectorMap *reflink; - String link; - StaticCriticalSection reflink_lock; - - ScanTopicIterator(VectorMap *reflink) : reflink(reflink) {}; - virtual bool operator()(int pos, const RichPara& para) - { - if(!IsNull(para.format.label)) - reflink->Add(para.format.label, link); - return false; - } -}; - -void GatherTpp::GatherRefLinks(const char *upp) -{ - for(FindFile pff(AppendFileName(upp, "*.*")); pff; pff.Next()) { - if(pff.IsFolder()) { - String package = pff.GetName(); - String pdir = AppendFileName(upp, package); - TopicLink tl; - tl.package = package; - for(FindFile ff(AppendFileName(pdir, "*.tpp")); ff; ff.Next()) { - if(ff.IsFolder()) { - String group = GetFileTitle(ff.GetName() ); - tl.group = group; - String dir = AppendFileName(pdir, ff.GetName()); - for(FindFile ft(AppendFileName(dir, "*.tpp")); ft; ft.Next()) { - if(ft.IsFile()) { - String path = AppendFileName(dir, ft.GetName()); - tl.topic = GetFileTitle(ft.GetName()); - String link = TopicLinkString(tl); - ScanTopicIterator sti(&reflink); - sti.link = link; - ParseQTF(ReadTopic(LoadFile(path))).Iterate(sti); - } - } - } - } - } - } -} - -struct GatherLinkIterator : RichText::Iterator { - VectorMap *reflink; - Index link; - - GatherLinkIterator(VectorMap *reflink) : reflink(reflink) {}; - virtual bool operator()(int pos, const RichPara& para) - { - for(int i = 0; i < para.GetCount(); i++) { - String l = para[i].format.link; - if(!IsNull(l)) { - if(l[0] == ':') { - int q = reflink->Find(l); - int w = q; - if(q < 0) - q = reflink->Find(l + "::class"); - if(q < 0) - q = reflink->Find(l + "::struct"); - if(q < 0) - q = reflink->Find(l + "::union"); - if(q >= 0) - l = (*reflink)[q]; - } - link.FindAdd(Nvl(reflink->Get(l, Null), l)); - } - } - return false; - } -}; - -String GetIndexTopic(String file) -{ - String topic = GetFileTitle(file); - String folder = GetFileFolder(file); - String topicLocation = GetFileTitle(folder); - folder = GetUpperFolder(folder); - topicLocation = GetFileTitle(folder) + "/" + topicLocation; - - return "topic://" + topicLocation + "/" + topic; -} - -int CharFilterLbl(int c) -{ - return IsAlNum(c) ? c : '.'; -} - -void QtfAsPdf(PdfDraw &pdf, const char *qtf) -{ - RichText txt = ParseQTF(qtf); - Size page = Size(3968, 6074); - UPP::Print(pdf, txt, page); -} - -Htmls RoundFrame(Htmls data, String border, Color bg) -{ - return HtmlPackedTable().BgColor(bg).Width(-100) - .Attr("style", "border-style: solid; border-width: 1px; border-color: #" + border + ";") - / HtmlLine() / data; -} - -bool ContainsAt(const String &source, const String &pattern, int pos) -{ - return pos >= 0 - && pos + pattern.GetLength() <= source.GetLength() - && 0 == memcmp(source.Begin() + pos, pattern.Begin(), pattern.GetLength()); -} - -bool StartsWith(const String &source, const String &pattern) -{ - return ContainsAt(source, pattern, 0); -} - -bool EndsWith(const String &source, const String &pattern) -{ - return ContainsAt(source, pattern, source.GetLength() - pattern.GetLength()); -} - -String GatherTpp::QtfAsHtml(const char *qtf, Index& css, - const VectorMap& links, - const VectorMap& labels, - const String& outdir, const String& fn) -{ - return EncodeHtml(ParseQTF(qtf), css, links, labels, outdir, fn, Zoom(8, 40), escape, 40); -} - -String GetText(const char *s) -{ - return GetTopic(s).text; -} - -void GatherTpp::ExportPage(int i, String htmlFolder) -{ - Index css; - String path = links.GetKey(i); - - String text = GetText(path); - int h; - h = ParseQTF(tt[i].text).GetHeight(1000); - - String qtflangs; - String strlang; - - String page = tt[i]; - page = QtfAsHtml(page, css, links, labels, htmlFolder, links[i]); - - Color paper = SWhite; - Color bg = Color(210, 217, 210); - - Htmls html; - html << - HtmlPackedTable().Width(-100) / - HtmlLine().ColSpan(3) + - HtmlPackedTable().Width(-100) / ( - HtmlLine().ColSpan(3).BgColor(bg).Height(6) / "" + - HtmlRow() / ( - HtmlTCell().Width(-100).BgColor(bg) / ( - RoundFrame(page , "6E89AE;padding: 10px;", White) - ) - ) - ); - - String topicTitle = tt.GetKey(i); - String pageTitle = tt[i].title; - if(IsNull(pageTitle)) - pageTitle = title; -/* - if(StartsWith(topicTitle, "examples$")) - pageTitle = "Demos / " + pageTitle; - else if(StartsWith(topicTitle, "reference$")) - pageTitle = "Examples / " + pageTitle; -*/ - if(pageTitle != title) - pageTitle << " :: " << title; - - Htmls content = - "\n" + - HtmlHeader(pageTitle, AsCss(css) + - "a.l1 { text-decoration:none; font-size: 8pt; font-family: sans-serif; " - "font-weight: normal; }\n" - "a.l1:link { color:#000000; }\n" - "a.l1:visited { color:#000080; }\n" - "a.l1:hover { color:#9933CC; }\n" - "a.l1:active { color:#000000; }\n" - "a.l2 { text-decoration:none; font-size: 12pt; font-family: sans-serif; " - "font-variant: small-caps; }\n" - "a.l2:link { color:#0066FF; }\n" - "a.l2:visited { color:#FF6600; }\n" - "a.l2:hover { color:#BC0624; }\n" - "a.l2:active { color:#BC0024; }\n", - "" - "" - ) - .BgColor(bg) - .Alink(Red).Link(Black).Vlink(Blue) - / html; - SaveFile(AppendFileName(htmlFolder, links[i]), content); -} - -String GatherTpp::TopicFileName(const char *topic) -{ - TopicLink tl = ParseTopicLink(topic); - String file = AppendFileName(dir, AppendFileName(tl.group + ".tpp", tl.topic + ".tpp")); - if (FileExists(file)) - return file; - - for (int i = 0; i < rootFolders.GetCount(); ++i) { - if (rootFolders[i] != dir) { - file = AppendFileName(rootFolders[i], AppendFileName(tl.package , AppendFileName(tl.group + ".tpp", tl.topic + ".tpp"))); - if (FileExists(file)) - return file; - } - } - return ""; -} - -String TopicFileNameHtml(const char *topic) -{ - TopicLink tl = ParseTopicLink(topic); - return tl.group + "$" + tl.package+ "$" + tl.topic + ".html"; -} - -String GatherTpp::GatherTopics(const char *topic, String& title) -{ - int q = tt.Find(topic); - if(q < 0) { - Topic p = ReadTopic(LoadFile(TopicFileName(topic))); - title = p.title; - String t = p; - if(IsNull(t)) - return "index.html"; - tt.Add(topic) = p; - GatherLinkIterator ti(&(reflink)); - ParseQTF(t).Iterate(ti); - for(int i = 0; i < ti.link.GetCount(); i++) { - String dummy; - GatherTopics(ti.link[i], dummy); - } - } else - title = tt[q].title; - return TopicFileNameHtml(topic); -} - - -String GatherTpp::GatherTopics(const char *topic) -{ - String dummy; - return GatherTopics(topic, dummy); -} - -bool GatherTpp::Load(String indexFile, Gate2 progress) { - indexTopic = GetIndexTopic(indexFile); - for (int i = 0; i < rootFolders.GetCount(); ++i) { - if (progress(i+1, rootFolders.GetCount())) - return false; - dir = rootFolders[i]; - - if (!DirectoryExists(dir)) - return false; - - GatherRefLinks(dir); - - if (i == 0) - GatherTopics(indexTopic); - } - return true; -} - -bool GatherTpp::MakeHtml(const char *folder, Gate2 progress) { - DeleteFolderDeep(folder); - DirectoryCreate(folder); - - for(int i = 0; i < tt.GetCount(); i++) { - String topic = tt.GetKey(i); - links.Add(topic, topic == indexTopic ? "index.html" : - memcmp(topic, "topic://", 8) ? topic : TopicFileNameHtml(topic)); - } - for(int i = 0; i < reflink.GetCount(); i++) { - String l = reflink.GetKey(i); - String lbl = Filter(l, CharFilterLbl); - String f = links.Get(reflink[i], Null) + '#' + lbl; - links.Add(l, f); - static const char *x[] = { "::struct", "::class", "::union" }; - for(int ii = 0; ii < 3; ii++) { - String e = x[ii]; - if(EndsWith(l, e)) { - links.Add(l.Mid(0, l.GetLength() - e.GetLength()), f); - } - } - labels.Add(l, lbl); - } - - for(int i = 0; i < tt.GetCount(); i++) { - if (progress(i+1, tt.GetCount())) - return false; - ExportPage(i, folder); - } - return true; -} - -bool GatherTpp::MakePdf(const char *filename, Gate2 progress) { - PdfDraw pdf; - for(int i = 0; i < tt.GetCount(); i++) { - if (progress(i+1, tt.GetCount())) - return false; - bool dopdf = true; - for (int j = 0; j < i; ++j) { - if (tt[j].text == tt[i].text) { - dopdf = false; - break; - } - } - if (dopdf) - QtfAsPdf(pdf, tt[i]); - } - SaveFile(filename, pdf.Finish()); - return true; -} - -int GatherTpp::FindTopic(const String name) { - return tt.Find(name); -} - -Topic &GatherTpp::GetTopic(int id) { - return tt[id]; -} - -Topic &GatherTpp::AddTopic(const String name) { - return tt.Add(name); -} - +#ifdef flagGUI +#include +#include + +using namespace Upp; + +#include "Functions4U/Functions4U.h" +#include "GatherTpp.h" + +struct ScanTopicIterator : RichText::Iterator { + VectorMap *reflink; + String link; + StaticCriticalSection reflink_lock; + + ScanTopicIterator(VectorMap *reflink) : reflink(reflink) {}; + virtual bool operator()(int pos, const RichPara& para) + { + if(!IsNull(para.format.label)) + reflink->Add(para.format.label, link); + return false; + } +}; + +void GatherTpp::GatherRefLinks(const char *upp) +{ + for(FindFile pff(AppendFileName(upp, "*.*")); pff; pff.Next()) { + if(pff.IsFolder()) { + String package = pff.GetName(); + String pdir = AppendFileName(upp, package); + TopicLink tl; + tl.package = package; + for(FindFile ff(AppendFileName(pdir, "*.tpp")); ff; ff.Next()) { + if(ff.IsFolder()) { + String group = GetFileTitle(ff.GetName() ); + tl.group = group; + String dir = AppendFileName(pdir, ff.GetName()); + for(FindFile ft(AppendFileName(dir, "*.tpp")); ft; ft.Next()) { + if(ft.IsFile()) { + String path = AppendFileName(dir, ft.GetName()); + tl.topic = GetFileTitle(ft.GetName()); + String link = TopicLinkString(tl); + ScanTopicIterator sti(&reflink); + sti.link = link; + ParseQTF(ReadTopic(LoadFile(path))).Iterate(sti); + } + } + } + } + } + } +} + +struct GatherLinkIterator : RichText::Iterator { + VectorMap *reflink; + Index link; + + GatherLinkIterator(VectorMap *reflink) : reflink(reflink) {}; + virtual bool operator()(int pos, const RichPara& para) + { + for(int i = 0; i < para.GetCount(); i++) { + String l = para[i].format.link; + if(!IsNull(l)) { + if(l[0] == ':') { + int q = reflink->Find(l); + int w = q; + if(q < 0) + q = reflink->Find(l + "::class"); + if(q < 0) + q = reflink->Find(l + "::struct"); + if(q < 0) + q = reflink->Find(l + "::union"); + if(q >= 0) + l = (*reflink)[q]; + } + link.FindAdd(Nvl(reflink->Get(l, Null), l)); + } + } + return false; + } +}; + +String GetIndexTopic(String file) +{ + String topic = GetFileTitle(file); + String folder = GetFileFolder(file); + String topicLocation = GetFileTitle(folder); + folder = GetUpperFolder(folder); + topicLocation = GetFileTitle(folder) + "/" + topicLocation; + + return "topic://" + topicLocation + "/" + topic; +} + +int CharFilterLbl(int c) +{ + return IsAlNum(c) ? c : '.'; +} + +void QtfAsPdf(PdfDraw &pdf, const char *qtf) +{ + RichText txt = ParseQTF(qtf); + Size page = Size(3968, 6074); + UPP::Print(pdf, txt, page); +} + +Htmls RoundFrame(Htmls data, String border, Color bg) +{ + return HtmlPackedTable().BgColor(bg).Width(-100) + .Attr("style", "border-style: solid; border-width: 1px; border-color: #" + border + ";") + / HtmlLine() / data; +} + +bool ContainsAt(const String &source, const String &pattern, int pos) +{ + return pos >= 0 + && pos + pattern.GetLength() <= source.GetLength() + && 0 == memcmp(source.Begin() + pos, pattern.Begin(), pattern.GetLength()); +} + +bool StartsWith(const String &source, const String &pattern) +{ + return ContainsAt(source, pattern, 0); +} + +bool EndsWith(const String &source, const String &pattern) +{ + return ContainsAt(source, pattern, source.GetLength() - pattern.GetLength()); +} + +String GatherTpp::QtfAsHtml(const char *qtf, Index& css, + const VectorMap& links, + const VectorMap& labels, + const String& outdir, const String& fn) +{ + return EncodeHtml(ParseQTF(qtf), css, links, labels, outdir, fn, Zoom(8, 40), escape, 40); +} + +String GetText(const char *s) +{ + return GetTopic(s).text; +} + +void GatherTpp::ExportPage(int i, String htmlFolder) +{ + Index css; + String path = links.GetKey(i); + + String text = GetText(path); + int h; + h = ParseQTF(tt[i].text).GetHeight(1000); + + String qtflangs; + String strlang; + + String page = tt[i]; + page = QtfAsHtml(page, css, links, labels, htmlFolder, links[i]); + + Color paper = SWhite; + Color bg = Color(210, 217, 210); + + Htmls html; + html << + HtmlPackedTable().Width(-100) / + HtmlLine().ColSpan(3) + + HtmlPackedTable().Width(-100) / ( + HtmlLine().ColSpan(3).BgColor(bg).Height(6) / "" + + HtmlRow() / ( + HtmlTCell().Width(-100).BgColor(bg) / ( + RoundFrame(page , "6E89AE;padding: 10px;", White) + ) + ) + ); + + String topicTitle = tt.GetKey(i); + String pageTitle = tt[i].title; + if(IsNull(pageTitle)) + pageTitle = title; +/* + if(StartsWith(topicTitle, "examples$")) + pageTitle = "Demos / " + pageTitle; + else if(StartsWith(topicTitle, "reference$")) + pageTitle = "Examples / " + pageTitle; +*/ + if(pageTitle != title) + pageTitle << " :: " << title; + + Htmls content = + "\n" + + HtmlHeader(pageTitle, AsCss(css) + + "a.l1 { text-decoration:none; font-size: 8pt; font-family: sans-serif; " + "font-weight: normal; }\n" + "a.l1:link { color:#000000; }\n" + "a.l1:visited { color:#000080; }\n" + "a.l1:hover { color:#9933CC; }\n" + "a.l1:active { color:#000000; }\n" + "a.l2 { text-decoration:none; font-size: 12pt; font-family: sans-serif; " + "font-variant: small-caps; }\n" + "a.l2:link { color:#0066FF; }\n" + "a.l2:visited { color:#FF6600; }\n" + "a.l2:hover { color:#BC0624; }\n" + "a.l2:active { color:#BC0024; }\n", + "" + "" + ) + .BgColor(bg) + .Alink(Red).Link(Black).Vlink(Blue) + / html; + SaveFile(AppendFileName(htmlFolder, links[i]), content); +} + +String GatherTpp::TopicFileName(const char *topic) +{ + TopicLink tl = ParseTopicLink(topic); + String file = AppendFileName(dir, AppendFileName(tl.group + ".tpp", tl.topic + ".tpp")); + if (FileExists(file)) + return file; + + for (int i = 0; i < rootFolders.GetCount(); ++i) { + if (rootFolders[i] != dir) { + file = AppendFileName(rootFolders[i], AppendFileName(tl.package , AppendFileName(tl.group + ".tpp", tl.topic + ".tpp"))); + if (FileExists(file)) + return file; + } + } + return ""; +} + +String TopicFileNameHtml(const char *topic) +{ + TopicLink tl = ParseTopicLink(topic); + return tl.group + "$" + tl.package+ "$" + tl.topic + ".html"; +} + +String GatherTpp::GatherTopics(const char *topic, String& title) +{ + int q = tt.Find(topic); + if(q < 0) { + Topic p = ReadTopic(LoadFile(TopicFileName(topic))); + title = p.title; + String t = p; + if(IsNull(t)) + return "index.html"; + tt.Add(topic) = p; + GatherLinkIterator ti(&(reflink)); + ParseQTF(t).Iterate(ti); + for(int i = 0; i < ti.link.GetCount(); i++) { + String dummy; + GatherTopics(ti.link[i], dummy); + } + } else + title = tt[q].title; + return TopicFileNameHtml(topic); +} + + +String GatherTpp::GatherTopics(const char *topic) +{ + String dummy; + return GatherTopics(topic, dummy); +} + +bool GatherTpp::Load(String indexFile, Gate2 progress) { + indexTopic = GetIndexTopic(indexFile); + for (int i = 0; i < rootFolders.GetCount(); ++i) { + if (progress(i+1, rootFolders.GetCount())) + return false; + dir = rootFolders[i]; + + if (!DirectoryExists(dir)) + return false; + + GatherRefLinks(dir); + + if (i == 0) + GatherTopics(indexTopic); + } + return true; +} + +bool GatherTpp::MakeHtml(const char *folder, Gate2 progress) { + DeleteFolderDeep(folder); + DirectoryCreate(folder); + + for(int i = 0; i < tt.GetCount(); i++) { + String topic = tt.GetKey(i); + links.Add(topic, topic == indexTopic ? "index.html" : + memcmp(topic, "topic://", 8) ? topic : TopicFileNameHtml(topic)); + } + for(int i = 0; i < reflink.GetCount(); i++) { + String l = reflink.GetKey(i); + String lbl = Filter(l, CharFilterLbl); + String f = links.Get(reflink[i], Null) + '#' + lbl; + links.Add(l, f); + static const char *x[] = { "::struct", "::class", "::union" }; + for(int ii = 0; ii < 3; ii++) { + String e = x[ii]; + if(EndsWith(l, e)) { + links.Add(l.Mid(0, l.GetLength() - e.GetLength()), f); + } + } + labels.Add(l, lbl); + } + + for(int i = 0; i < tt.GetCount(); i++) { + if (progress(i+1, tt.GetCount())) + return false; + ExportPage(i, folder); + } + return true; +} + +bool GatherTpp::MakePdf(const char *filename, Gate2 progress) { + PdfDraw pdf; + for(int i = 0; i < tt.GetCount(); i++) { + if (progress(i+1, tt.GetCount())) + return false; + bool dopdf = true; + for (int j = 0; j < i; ++j) { + if (tt[j].text == tt[i].text) { + dopdf = false; + break; + } + } + if (dopdf) + QtfAsPdf(pdf, tt[i]); + } + SaveFile(filename, pdf.Finish()); + return true; +} + +int GatherTpp::FindTopic(const String name) { + return tt.Find(name); +} + +Topic &GatherTpp::GetTopic(int id) { + return tt[id]; +} + +Topic &GatherTpp::AddTopic(const String name) { + return tt.Add(name); +} + +#endif \ No newline at end of file diff --git a/bazaar/Functions4U/init b/bazaar/Functions4U/init index 872513445..13ae0af25 100644 --- a/bazaar/Functions4U/init +++ b/bazaar/Functions4U/init @@ -2,7 +2,8 @@ #define _Functions4U_icpp_init_stub #include "Core/init" #include "plugin\bz2/init" -#include "ide/Browser/init" #include "Web/init" +#include "ide/Browser/init" #include "AESStream/init" +#include "Draw/init" #endif