Update to v070r14 release.

(there was no r13 release posted to the WIP thread)

byuu says:

- nall/string: trim and split functions now take the limit as a template
  parameter for clarity, trim_once variants are removed
  - quotable.trim<1>("\""); //remove quotes from string
  - cheatcode.split<3>(","); //split up to three times, third one is
    a description that may have commas
  - foobar.trim(" "); //remove any and all spaces
- nall/string: added wildcard() and iwildcard() functions for pattern
  matching
- nall/directory: accepts an optional pattern parameter to perform
  wildcard matching
  - lstring cartridges = directory::contents(path, "*.sfc");
  - some people may prefer directory::contents("/path/to/files/*.sfc"),
    but I like not having to build a string when you have the path
    separated already
- nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do
  intend to replace the check/radio actions with native Qt versions
  later
- bsnes/data: new folder, share the parts that both UIs use; bsnes.ico,
  bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target
- Makefile: install target now creates .bsnes folder and copies
  cheats.xml there for you
- Makefile: gconftool hack removed, not needed for phoenix, will work
  around with Qt later
- will probably make bsnes/Qt read the cheats.xml file externally as
  well, as that file makes each profile 1MB bigger when embedded
  - as such, will probably make bsnes also look in the binary directory
    for that file, so Windows users don't have to copy it to their
    userdata folder
This commit is contained in:
Tim Allen 2010-10-11 21:39:14 +11:00
parent 1a29b59225
commit ce2b543679
29 changed files with 159 additions and 99 deletions

View File

@ -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:;

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="bsnes" version="1.0.0.0" processorArchitecture="x86"/>
<assemblyIdentity type="win32" name="bsnes" version="1.0.0.0" processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"/>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
</assembly>

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -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];

View File

@ -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;
}

View File

@ -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<unsigned limit = 0> inline string& ltrim(const char *key = " ");
template<unsigned limit = 0> inline string& rtrim(const char *key = " ");
template<unsigned limit = 0> inline string& trim (const char *key = " ");
protected:
char *data;
@ -77,8 +74,8 @@ namespace nall {
template<typename T> inline lstring& operator<<(T value);
inline optional<unsigned> find(const char*);
inline void split (const char*, const char*, unsigned = 0);
inline void qsplit(const char*, const char*, unsigned = 0);
template<unsigned limit = 0> inline void split (const char*, const char*);
template<unsigned limit = 0> inline void qsplit(const char*, const char*);
lstring();
lstring(std::initializer_list<string>);
@ -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<unsigned limit = 0> inline char* ltrim(char *str, const char *key = " ");
template<unsigned limit = 0> inline char* rtrim(char *str, const char *key = " ");
template<unsigned limit = 0> inline char* trim (char *str, const char *key = " ");
//utility.hpp
inline unsigned strlcpy(string &dest, const char *src, unsigned length);

View File

@ -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);

View File

@ -3,7 +3,8 @@
namespace nall {
void lstring::split(const char *key, const char *src, unsigned limit) {
template<unsigned Limit> 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<unsigned Limit> void lstring::qsplit(const char *key, const char *src) {
unsigned limit = Limit;
reset();
int ssl = strlen(src), ksl = strlen(key);

View File

@ -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<unsigned Limit> 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<unsigned Limit> 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<unsigned limit> char* trim(char *str, const char *key) {
return ltrim<limit>(rtrim<limit>(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<unsigned limit> string& string::ltrim(const char *key) { nall::ltrim<limit>(data, key); return *this; }
template<unsigned limit> string& string::rtrim(const char *key) { nall::rtrim<limit>(data, key); return *this; }
template<unsigned limit> string& string::trim (const char *key) { nall::trim <limit>(data, key); return *this; }
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -101,7 +101,7 @@ void FileBrowser::folderBrowse() {
void FileBrowser::folderUp() {
string path = folder;
path.rtrim_once("/");
path.rtrim<1>("/");
if(path != "") setFolder(dir(path));
}

View File

@ -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"

View File

@ -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);

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View File

@ -1,11 +1,12 @@
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file alias="bsnes.png">../data/bsnes.png</file>
<file alias="bsnes.png">../../data/bsnes.png</file>
<file alias="cheats.xml">../../data/cheats.xml</file>
<file alias="logo.png">../data/logo.png</file>
<file alias="documentation.html">../data/documentation.html</file>
<file alias="license.html">../data/license.html</file>
<file alias="cheats.xml">../data/cheats.xml</file>
<file alias="16x16/item-check-on.png">../data/icons-16x16/item-check-on.png</file>
<file alias="16x16/item-check-off.png">../data/icons-16x16/item-check-off.png</file>

View File

@ -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"

View File

@ -3,7 +3,7 @@
#include <nall/platform.hpp>
#include <nall/string.hpp>
#include <nall/qt/window.moc.hpp>
#include "window.moc.hpp"
namespace nall {

View File

@ -14,12 +14,12 @@
#include <nall/input.hpp>
#include <nall/ups.hpp>
#include <nall/snes/info.hpp>
#include <nall/qt/concept.hpp>
#include <nall/qt/check-action.moc.hpp>
#include <nall/qt/file-dialog.moc.hpp>
#include <nall/qt/hex-editor.moc.hpp>
#include <nall/qt/radio-action.moc.hpp>
#include <nall/qt/window.moc.hpp>
#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 <ruby/ruby.hpp>