diff --git a/bsnes/Makefile b/bsnes/Makefile index ea8ea462..1e08781e 100755 --- a/bsnes/Makefile +++ b/bsnes/Makefile @@ -62,9 +62,11 @@ endif install: ifeq ($(platform),x) install -D -m 755 out/bsnes $(DESTDIR)$(prefix)/bin/bsnes - install -D -m 644 ui-qt/data/bsnes.png $(DESTDIR)$(prefix)/share/pixmaps/bsnes.png - install -D -m 644 ui-qt/data/bsnes.desktop $(DESTDIR)$(prefix)/share/applications/bsnes.desktop -# gconftool-2 --type bool --set /desktop/gnome/interface/menus_have_icons true + install -D -m 644 data/bsnes.png $(DESTDIR)$(prefix)/share/pixmaps/bsnes.png + install -D -m 644 data/bsnes.desktop $(DESTDIR)$(prefix)/share/applications/bsnes.desktop + test -d ~/.bsnes || mkdir ~/.bsnes + cp data/cheats.xml ~/.bsnes/cheats.xml + chmod 777 ~/.bsnes ~/.bsnes/cheats.xml endif uninstall: @@ -88,6 +90,6 @@ clean: ui_clean -@$(call delete,*.manifest) archive-all: - tar -cjf bsnes.tar.bz2 launcher libco nall obj out phoenix ruby snes ui-phoenix ui-qt Makefile cc.bat clean.bat sync.sh + tar -cjf bsnes.tar.bz2 data launcher libco nall obj out phoenix ruby snes ui-phoenix ui-qt Makefile cc.bat clean.bat sync.sh help:; diff --git a/bsnes/ui-qt/data/bsnes.Manifest b/bsnes/data/bsnes.Manifest similarity index 71% rename from bsnes/ui-qt/data/bsnes.Manifest rename to bsnes/data/bsnes.Manifest index 4602d4fe..e415f87a 100755 --- a/bsnes/ui-qt/data/bsnes.Manifest +++ b/bsnes/data/bsnes.Manifest @@ -1,9 +1,9 @@ - + - + diff --git a/bsnes/ui-qt/data/bsnes.desktop b/bsnes/data/bsnes.desktop similarity index 100% rename from bsnes/ui-qt/data/bsnes.desktop rename to bsnes/data/bsnes.desktop diff --git a/bsnes/ui-phoenix/data/bsnes.ico b/bsnes/data/bsnes.ico similarity index 100% rename from bsnes/ui-phoenix/data/bsnes.ico rename to bsnes/data/bsnes.ico diff --git a/bsnes/ui-qt/data/bsnes.png b/bsnes/data/bsnes.png similarity index 100% rename from bsnes/ui-qt/data/bsnes.png rename to bsnes/data/bsnes.png diff --git a/bsnes/ui-qt/data/cheats.xml b/bsnes/data/cheats.xml similarity index 100% rename from bsnes/ui-qt/data/cheats.xml rename to bsnes/data/cheats.xml diff --git a/bsnes/nall/dictionary.hpp b/bsnes/nall/dictionary.hpp index 1bdc87dc..dcb04151 100755 --- a/bsnes/nall/dictionary.hpp +++ b/bsnes/nall/dictionary.hpp @@ -27,7 +27,7 @@ namespace nall { bool import(const char *filename) { string data; if(data.readfile(filename) == false) return false; - data.ltrim_once("\xef\xbb\xbf"); //remove UTF-8 marker, if it exists + data.ltrim<1>("\xef\xbb\xbf"); //remove UTF-8 marker, if it exists data.replace("\r", ""); lstring line; @@ -43,8 +43,8 @@ namespace nall { part[1].trim(); //remove quotes - part[0].trim_once("\""); - part[1].trim_once("\""); + part[0].trim<1>("\""); + part[1].trim<1>("\""); unsigned n = index_input.size(); index_input[n] = part[0]; diff --git a/bsnes/nall/directory.hpp b/bsnes/nall/directory.hpp index d6ab5cc7..7ee3398f 100755 --- a/bsnes/nall/directory.hpp +++ b/bsnes/nall/directory.hpp @@ -16,13 +16,13 @@ namespace nall { struct directory { - static lstring folders(const char *pathname); - static lstring files(const char *pathname); - static lstring contents(const char *pathname); + static lstring folders(const string &pathname, const string &pattern = "*"); + static lstring files(const string &pathname, const string &pattern = "*"); + static lstring contents(const string &pathname, const string &pattern = "*"); }; #if defined(_WIN32) - inline lstring directory::folders(const char *pathname) { + inline lstring directory::folders(const string &pathname, const string &pattern) { lstring list; string path = pathname; path.transform("/", "\\"); @@ -34,13 +34,15 @@ struct directory { if(handle != INVALID_HANDLE_VALUE) { if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - list.append(string(utf8_t(data.cFileName), "/")); + string name = utf8_t(data.cFileName); + if(wildcard(name, pattern)) list.append(string(name, "/")); } } while(FindNextFile(handle, &data) != false) { if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - list.append(string(utf8_t(data.cFileName), "/")); + string name = utf8_t(data.cFileName); + if(wildcard(name, pattern)) list.append(string(name, "/")); } } } @@ -50,7 +52,7 @@ struct directory { return list; } - inline lstring directory::files(const char *pathname) { + inline lstring directory::files(const string &pathname, const string &pattern) { lstring list; string path = pathname; path.transform("/", "\\"); @@ -61,11 +63,13 @@ struct directory { handle = FindFirstFile(utf16_t(path), &data); if(handle != INVALID_HANDLE_VALUE) { if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - list.append(utf8_t(data.cFileName)); + string name = utf8_t(data.cFileName); + if(wildcard(name, pattern)) list.append(name); } while(FindNextFile(handle, &data) != false) { if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - list.append(utf8_t(data.cFileName)); + string name = utf8_t(data.cFileName); + if(wildcard(name, pattern)) list.append(name); } } FindClose(handle); @@ -74,14 +78,14 @@ struct directory { return list; } - inline lstring directory::contents(const char *pathname) { - lstring folders = directory::folders(pathname); - lstring files = directory::files(pathname); - foreach(file, files) folders.append(file); + inline lstring directory::contents(const string &pathname, const string &pattern) { + lstring folders = directory::folders(pathname); //pattern search of contents() should only filter files + lstring files = directory::files(pathname, pattern); + foreach(file, files) folders.append(file, pattern); return folders; } #else - inline lstring directory::folders(const char *pathname) { + inline lstring directory::folders(const string &pathname, const string &pattern) { lstring list; DIR *dp; struct dirent *ep; @@ -90,7 +94,9 @@ struct directory { while(ep = readdir(dp)) { if(!strcmp(ep->d_name, ".")) continue; if(!strcmp(ep->d_name, "..")) continue; - if(ep->d_type & DT_DIR) list.append(string(ep->d_name, "/")); + if(ep->d_type & DT_DIR) { + if(wildcard(ep->d_name, pattern)) list.append(string(ep->d_name, "/")); + } } closedir(dp); } @@ -99,7 +105,7 @@ struct directory { } - inline lstring directory::files(const char *pathname) { + inline lstring directory::files(const string &pathname, const string &pattern) { lstring list; DIR *dp; struct dirent *ep; @@ -108,7 +114,9 @@ struct directory { while(ep = readdir(dp)) { if(!strcmp(ep->d_name, ".")) continue; if(!strcmp(ep->d_name, "..")) continue; - if((ep->d_type & DT_DIR) == 0) list.append(ep->d_name); + if((ep->d_type & DT_DIR) == 0) { + if(wildcard(ep->d_name, pattern)) list.append(ep->d_name); + } } closedir(dp); } @@ -116,9 +124,9 @@ struct directory { return list; } - inline lstring directory::contents(const char *pathname) { - lstring folders = directory::folders(pathname); - lstring files = directory::files(pathname); + inline lstring directory::contents(const string &pathname, const string &pattern) { + lstring folders = directory::folders(pathname); //pattern search of contents() should only filter files + lstring files = directory::files(pathname, pattern); foreach(file, files) folders.append(file); return folders; } diff --git a/bsnes/nall/string/base.hpp b/bsnes/nall/string/base.hpp index fbdcc3c9..f4556e70 100755 --- a/bsnes/nall/string/base.hpp +++ b/bsnes/nall/string/base.hpp @@ -55,12 +55,9 @@ namespace nall { inline string& lower(); inline string& upper(); inline string& transform(const char *before, const char *after); - inline string& ltrim(const char *key = " "); - inline string& rtrim(const char *key = " "); - inline string& trim (const char *key = " "); - inline string& ltrim_once(const char *key = " "); - inline string& rtrim_once(const char *key = " "); - inline string& trim_once (const char *key = " "); + template inline string& ltrim(const char *key = " "); + template inline string& rtrim(const char *key = " "); + template inline string& trim (const char *key = " "); protected: char *data; @@ -77,8 +74,8 @@ namespace nall { template inline lstring& operator<<(T value); inline optional find(const char*); - inline void split (const char*, const char*, unsigned = 0); - inline void qsplit(const char*, const char*, unsigned = 0); + template inline void split (const char*, const char*); + template inline void qsplit(const char*, const char*); lstring(); lstring(std::initializer_list); @@ -88,6 +85,10 @@ namespace nall { inline char chrlower(char c); inline char chrupper(char c); inline int stricmp(const char *dest, const char *src); + inline int strwcmp(const char *str, const char *pattern, unsigned length); + inline int strwicmp(const char *str, const char *pattern, unsigned length); + inline bool wildcard(const char *str, const char *pattern); + inline bool iwildcard(const char *str, const char *pattern); inline bool strbegin (const char *str, const char *key); inline bool stribegin(const char *str, const char *key); inline bool strend (const char *str, const char *key); @@ -115,12 +116,9 @@ namespace nall { inline unsigned strlcat(char *dest, const char *src, unsigned length); //trim.hpp - inline char* ltrim(char *str, const char *key = " "); - inline char* rtrim(char *str, const char *key = " "); - inline char* trim (char *str, const char *key = " "); - inline char* ltrim_once(char *str, const char *key = " "); - inline char* rtrim_once(char *str, const char *key = " "); - inline char* trim_once (char *str, const char *key = " "); + template inline char* ltrim(char *str, const char *key = " "); + template inline char* rtrim(char *str, const char *key = " "); + template inline char* trim (char *str, const char *key = " "); //utility.hpp inline unsigned strlcpy(string &dest, const char *src, unsigned length); diff --git a/bsnes/nall/string/compare.hpp b/bsnes/nall/string/compare.hpp index bd289753..45f22a06 100755 --- a/bsnes/nall/string/compare.hpp +++ b/bsnes/nall/string/compare.hpp @@ -21,6 +21,74 @@ int stricmp(const char *dest, const char *src) { return (int)chrlower(*dest) - (int)chrlower(*src); } +int strwcmp(const char *str, const char *pattern, unsigned length) { + while(length && *str) { + if(*pattern != '?' && *str != *pattern) break; + pattern++, str++, length--; + } + + if(length == 0 || *pattern == '?') return 0; + return (int)chrlower(*str) - (int)chrlower(*pattern); +} + +int strwicmp(const char *str, const char *pattern, unsigned length) { + while(length && *str) { + if(*pattern != '?' && chrlower(*str) != chrlower(*pattern)) break; + pattern++, str++, length--; + } + + if(length == 0 || *pattern == '?') return 0; + return (int)chrlower(*str) - (int)chrlower(*pattern); +} + +bool wildcard(const char *str, const char *pattern) { + while(*pattern) { + char n = *pattern++; + if(n == '*') { + unsigned length = 0; + while(true) { + n = pattern[length]; + if(n == 0 || n == '*') break; + length++; + } + if(length) while(true) { + if(*str == 0) return false; + if(!strwcmp(str, pattern, length)) break; + str++; + } + } else if(n == '?') { + str++; + } else { + if(*str++ != n) return false; + } + } + return true; +} + +bool iwildcard(const char *str, const char *pattern) { + while(*pattern) { + char n = *pattern++; + if(n == '*') { + unsigned length = 0; + while(true) { + n = pattern[length]; + if(n == 0 || n == '*') break; + length++; + } + if(length) while(true) { + if(*str == 0) return false; + if(!strwicmp(str, pattern, length)) break; + str++; + } + } else if(n == '?') { + str++; + } else { + if(chrlower(*str++) != chrlower(n)) return false; + } + } + return true; +} + bool strbegin(const char *str, const char *key) { int i, ssl = strlen(str), ksl = strlen(key); diff --git a/bsnes/nall/string/split.hpp b/bsnes/nall/string/split.hpp index bb77dfcd..8d3ca877 100755 --- a/bsnes/nall/string/split.hpp +++ b/bsnes/nall/string/split.hpp @@ -3,7 +3,8 @@ namespace nall { -void lstring::split(const char *key, const char *src, unsigned limit) { +template void lstring::split(const char *key, const char *src) { + unsigned limit = Limit; reset(); int ssl = strlen(src), ksl = strlen(key); @@ -21,7 +22,8 @@ void lstring::split(const char *key, const char *src, unsigned limit) { operator[](split_count++) = src + lp; } -void lstring::qsplit(const char *key, const char *src, unsigned limit) { +template void lstring::qsplit(const char *key, const char *src) { + unsigned limit = Limit; reset(); int ssl = strlen(src), ksl = strlen(key); diff --git a/bsnes/nall/string/trim.hpp b/bsnes/nall/string/trim.hpp index 4fda05ec..ba577856 100755 --- a/bsnes/nall/string/trim.hpp +++ b/bsnes/nall/string/trim.hpp @@ -3,7 +3,9 @@ namespace nall { -char* ltrim(char *str, const char *key) { +//limit defaults to zero, which will underflow on first compare; equivalent to no limit +template char* ltrim(char *str, const char *key) { + unsigned limit = Limit; if(!key || !*key) return str; while(strbegin(str, key)) { char *dest = str, *src = str + strlen(key); @@ -12,49 +14,28 @@ char* ltrim(char *str, const char *key) { if(!*dest) break; dest++; } + if(--limit == 0) break; } return str; } -char* rtrim(char *str, const char *key) { +template char* rtrim(char *str, const char *key) { + unsigned limit = Limit; if(!key || !*key) return str; - while(strend(str, key)) str[strlen(str) - strlen(key)] = 0; - return str; -} - -char* trim(char *str, const char *key) { - return ltrim(rtrim(str, key), key); -} - -char* ltrim_once(char *str, const char *key) { - if(!key || !*key) return str; - if(strbegin(str, key)) { - char *dest = str, *src = str + strlen(key); - while(true) { - *dest = *src++; - if(!*dest) break; - dest++; - } + while(strend(str, key)) { + str[strlen(str) - strlen(key)] = 0; + if(--limit == 0) break; } return str; } -char* rtrim_once(char *str, const char *key) { - if(!key || !*key) return str; - if(strend(str, key)) str[strlen(str) - strlen(key)] = 0; - return str; +template char* trim(char *str, const char *key) { + return ltrim(rtrim(str, key), key); } -char* trim_once(char *str, const char *key) { - return ltrim_once(rtrim_once(str, key), key); -} - -string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } -string& string::rtrim(const char *key) { nall::rtrim(data, key); return *this; } -string& string::trim (const char *key) { nall::trim (data, key); return *this; } -string& string::ltrim_once(const char *key) { nall::ltrim_once(data, key); return *this; } -string& string::rtrim_once(const char *key) { nall::rtrim_once(data, key); return *this; } -string& string::trim_once (const char *key) { nall::trim_once (data, key); return *this; } +template string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } +template string& string::rtrim(const char *key) { nall::rtrim(data, key); return *this; } +template string& string::trim (const char *key) { nall::trim (data, key); return *this; } } diff --git a/bsnes/nall/string/xml.hpp b/bsnes/nall/string/xml.hpp index e6f3a81c..185a89f9 100755 --- a/bsnes/nall/string/xml.hpp +++ b/bsnes/nall/string/xml.hpp @@ -139,8 +139,8 @@ inline bool xml_element::parse_head(string data) { xml_attribute attr; attr.name = side[0]; attr.content = side[1]; - if(strbegin(attr.content, "\"") && strend(attr.content, "\"")) attr.content.trim_once("\""); - else if(strbegin(attr.content, "'") && strend(attr.content, "'")) attr.content.trim_once("'"); + if(strbegin(attr.content, "\"") && strend(attr.content, "\"")) attr.content.trim<1>("\""); + else if(strbegin(attr.content, "'") && strend(attr.content, "'")) attr.content.trim<1>("'"); else throw "..."; attribute.append(attr); } @@ -186,10 +186,10 @@ inline bool xml_element::parse_body(const char *&data) { if(strend(tag, "?") == true) { self_terminating = true; - tag.rtrim_once("?"); + tag.rtrim<1>("?"); } else if(strend(tag, "/") == true) { self_terminating = true; - tag.rtrim_once("/"); + tag.rtrim<1>("/"); } parse_head(tag); diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index d6f3bff0..c0db3ba3 100755 --- a/bsnes/snes/snes.hpp +++ b/bsnes/snes/snes.hpp @@ -1,7 +1,7 @@ namespace SNES { namespace Info { static const char Name[] = "bsnes"; - static const char Version[] = "070.12"; + static const char Version[] = "070.14"; static const unsigned SerializerVersion = 14; } } diff --git a/bsnes/ui-phoenix/general/file-browser.cpp b/bsnes/ui-phoenix/general/file-browser.cpp index a8fac4e2..9218bc44 100755 --- a/bsnes/ui-phoenix/general/file-browser.cpp +++ b/bsnes/ui-phoenix/general/file-browser.cpp @@ -101,7 +101,7 @@ void FileBrowser::folderBrowse() { void FileBrowser::folderUp() { string path = folder; - path.rtrim_once("/"); + path.rtrim<1>("/"); if(path != "") setFolder(dir(path)); } diff --git a/bsnes/ui-phoenix/resource.rc b/bsnes/ui-phoenix/resource.rc index af394337..7fc5b0e3 100755 --- a/bsnes/ui-phoenix/resource.rc +++ b/bsnes/ui-phoenix/resource.rc @@ -1,2 +1,2 @@ -1 24 "../phoenix/windows/phoenix.Manifest" -2 ICON DISCARDABLE "data/bsnes.ico" +1 24 "../data/bsnes.Manifest" +2 ICON DISCARDABLE "../data/bsnes.ico" diff --git a/bsnes/ui-phoenix/tools/cheat-editor.cpp b/bsnes/ui-phoenix/tools/cheat-editor.cpp index 8b55ee02..4747a6c0 100755 --- a/bsnes/ui-phoenix/tools/cheat-editor.cpp +++ b/bsnes/ui-phoenix/tools/cheat-editor.cpp @@ -218,7 +218,7 @@ void CheatEditor::findCodes() { if(element.name == "description") description = element.parse(); else if(element.name == "code") code.append(string(element.parse(), "+")); } - code.rtrim_once("+"); + code.rtrim<1>("+"); code.append("\t"); code.append(description); databaseList.addItem(description); diff --git a/bsnes/ui-qt/Makefile b/bsnes/ui-qt/Makefile index fb4b74e0..2e61fa01 100755 --- a/bsnes/ui-qt/Makefile +++ b/bsnes/ui-qt/Makefile @@ -1,5 +1,5 @@ qtlibs := $(strip QtCore QtGui $(if $(findstring osx,$(platform)),QtOpenGL)) -include nall/qt/Makefile +include $(ui)/template/Makefile ui_objects := ui-main ui-base ui-cartridge ui-debugger ui-input ui-movie ui-settings ui-state ui-tools ui_objects += ruby diff --git a/bsnes/ui-qt/data/bsnes.ico b/bsnes/ui-qt/data/bsnes.ico deleted file mode 100755 index 54acded4..00000000 Binary files a/bsnes/ui-qt/data/bsnes.ico and /dev/null differ diff --git a/bsnes/ui-qt/resource/resource.qrc b/bsnes/ui-qt/resource/resource.qrc index 02b0fc36..a0254613 100755 --- a/bsnes/ui-qt/resource/resource.qrc +++ b/bsnes/ui-qt/resource/resource.qrc @@ -1,11 +1,12 @@ - ../data/bsnes.png + ../../data/bsnes.png + ../../data/cheats.xml + ../data/logo.png ../data/documentation.html ../data/license.html - ../data/cheats.xml ../data/icons-16x16/item-check-on.png ../data/icons-16x16/item-check-off.png diff --git a/bsnes/ui-qt/resource/resource.rc b/bsnes/ui-qt/resource/resource.rc index c5a86429..63dfef44 100755 --- a/bsnes/ui-qt/resource/resource.rc +++ b/bsnes/ui-qt/resource/resource.rc @@ -1,2 +1,2 @@ -1 24 "ui-qt/data/bsnes.Manifest" -IDI_ICON1 ICON DISCARDABLE "ui-qt/data/bsnes.ico" +1 24 "data/bsnes.Manifest" +IDI_ICON1 ICON DISCARDABLE "data/bsnes.ico" diff --git a/bsnes/nall/qt/Makefile b/bsnes/ui-qt/template/Makefile similarity index 100% rename from bsnes/nall/qt/Makefile rename to bsnes/ui-qt/template/Makefile diff --git a/bsnes/nall/qt/check-action.moc.hpp b/bsnes/ui-qt/template/check-action.moc.hpp similarity index 100% rename from bsnes/nall/qt/check-action.moc.hpp rename to bsnes/ui-qt/template/check-action.moc.hpp diff --git a/bsnes/nall/qt/concept.hpp b/bsnes/ui-qt/template/concept.hpp similarity index 100% rename from bsnes/nall/qt/concept.hpp rename to bsnes/ui-qt/template/concept.hpp diff --git a/bsnes/nall/qt/file-dialog.moc.hpp b/bsnes/ui-qt/template/file-dialog.moc.hpp similarity index 99% rename from bsnes/nall/qt/file-dialog.moc.hpp rename to bsnes/ui-qt/template/file-dialog.moc.hpp index 3cb8989e..34a7655b 100755 --- a/bsnes/nall/qt/file-dialog.moc.hpp +++ b/bsnes/ui-qt/template/file-dialog.moc.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include "window.moc.hpp" namespace nall { diff --git a/bsnes/nall/qt/hex-editor.moc.hpp b/bsnes/ui-qt/template/hex-editor.moc.hpp similarity index 100% rename from bsnes/nall/qt/hex-editor.moc.hpp rename to bsnes/ui-qt/template/hex-editor.moc.hpp diff --git a/bsnes/nall/qt/radio-action.moc.hpp b/bsnes/ui-qt/template/radio-action.moc.hpp similarity index 100% rename from bsnes/nall/qt/radio-action.moc.hpp rename to bsnes/ui-qt/template/radio-action.moc.hpp diff --git a/bsnes/nall/qt/window.moc.hpp b/bsnes/ui-qt/template/window.moc.hpp similarity index 100% rename from bsnes/nall/qt/window.moc.hpp rename to bsnes/ui-qt/template/window.moc.hpp diff --git a/bsnes/ui-qt/ui-base.hpp b/bsnes/ui-qt/ui-base.hpp index 544d3230..05b3b6b2 100755 --- a/bsnes/ui-qt/ui-base.hpp +++ b/bsnes/ui-qt/ui-base.hpp @@ -14,12 +14,12 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include "template/concept.hpp" +#include "template/check-action.moc.hpp" +#include "template/file-dialog.moc.hpp" +#include "template/hex-editor.moc.hpp" +#include "template/radio-action.moc.hpp" +#include "template/window.moc.hpp" using namespace nall; #include