Diverse Wiimotegerelateerde aanpassingen. Projectinstellingen Wiiuse en Wiiusej nogmaals aangepast. Getracht Wiiscan te compileren, maar dit geeft vooralsnog problemen. De bedoeling is om bij de -c -d en -a argumenten ook waarden met spaties (op een of andere manier) te accepteren. Dit zou het mogelijk maken om behalve wiimotes ook het balance board te pairen. Voorlopig opgelost door een handmatige aanpassing in wiiscan.exe, opgeslagen als wiiscan-bb.exe.
This commit is contained in:
143
cpp/wiiscan/src/args.h
Normal file
143
cpp/wiiscan/src/args.h
Normal file
@@ -0,0 +1,143 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __ARGS_H__
|
||||
#define __ARGS_H__
|
||||
|
||||
class args{
|
||||
private:
|
||||
typedef vector<string> t_args;
|
||||
t_args m_args;
|
||||
|
||||
void Remove(t_args::iterator itt1,int n)
|
||||
{
|
||||
t_args args2;
|
||||
for(t_args::iterator itt2=m_args.begin();itt2!=m_args.end();++itt2) {
|
||||
if(itt2!=itt1) args2.push_back(*itt2);
|
||||
else {if (--n>0) ++itt1;}
|
||||
}
|
||||
m_args=args2;
|
||||
}
|
||||
|
||||
t_args::iterator Find(const string& v)
|
||||
{
|
||||
for(t_args::iterator itt=m_args.begin();itt!=m_args.end();++itt) {
|
||||
if (v==*itt) return itt;
|
||||
}
|
||||
return m_args.end();
|
||||
}
|
||||
|
||||
t_args::const_iterator Find(const string& v) const
|
||||
{
|
||||
for(t_args::const_iterator itt=m_args.begin();itt!=m_args.end();++itt) {
|
||||
if (v==*itt) return itt;
|
||||
}
|
||||
return m_args.end();
|
||||
}
|
||||
|
||||
public:
|
||||
args(const int argc,char **argv,const bool printargs=false)
|
||||
{
|
||||
for(int i=0;i<argc;++i) {m_args.push_back(argv[i]);}
|
||||
if (printargs) cout << "% Call args: " << *this << endl;
|
||||
}
|
||||
|
||||
string operator[](const size_t i) const
|
||||
{
|
||||
if(i>=size()) throw_("argument[] out of range");
|
||||
return m_args[i];
|
||||
}
|
||||
|
||||
size_t size() const {return m_args.size();}
|
||||
bool hasopt(const string& tag) const {return Find(tag)!=m_args.end();}
|
||||
template<class T> T Totype(const size_t i) const {return totype<T>((*this)[i]);}
|
||||
template<class T> T Tounit(const size_t i) const {
|
||||
const string& s=(*this)[i+1];
|
||||
#ifndef USE_UNITS
|
||||
// fake test of units, primitive test, must be one-of: kpc, per_kpc and msun1E10
|
||||
if (s!="kpc/h" && s!="h/kpc" && s!="msun1E10/h") throw_("bad unit=<" + s + ">, can only handle units of type: kpc/h, h/kpc, and msun1E10/h");
|
||||
#endif
|
||||
return totype<T>((*this)[i] + " " + s);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T parseval(const string& tag,const T& defaultval)
|
||||
{
|
||||
t_args::iterator itt=Find(tag);
|
||||
if (itt==m_args.end() || itt+1==m_args.end()) return defaultval;
|
||||
|
||||
const T v=totype<T>(*(++itt));
|
||||
Remove(--itt,2);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
template<class T,class R>
|
||||
pair<T,R> parseval(const string& tag,const T& defaultval1,const R& defaultval2)
|
||||
{
|
||||
t_args::iterator itt=Find(tag);
|
||||
if (itt==m_args.end() || itt+1==m_args.end() || itt+2==m_args.end()) return make_pair(defaultval1,defaultval2);
|
||||
|
||||
const T v1=totype<T>(*(++itt));
|
||||
const R v2=totype<R>(*(++itt));
|
||||
Remove(----itt,3);
|
||||
|
||||
return make_pair(v1,v2);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T parseunit(const string& tag,const T& defaultval)
|
||||
{
|
||||
t_args::iterator itt=Find(tag);
|
||||
if (itt==m_args.end() || itt+2==m_args.end()) return defaultval;
|
||||
|
||||
const string s1=*(++itt);
|
||||
const string s2=*(++itt);
|
||||
const T v=totype<T>(s1 + " " + s2);
|
||||
Remove(----itt,3);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
bool parseopt(const string& tag)
|
||||
{
|
||||
t_args::iterator itt=Find(tag);
|
||||
if (itt==m_args.end()) return false;
|
||||
Remove(itt,1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int getoptindex(const string& tag) const
|
||||
{
|
||||
int n=0;
|
||||
for(t_args::const_iterator itt=m_args.begin();itt!=m_args.end();++itt,++n) {
|
||||
if (tag==*itt) {
|
||||
assert( n>=0 && size_t(n)<m_args.size());
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void remove(const size_t i,const size_t n=1)
|
||||
{
|
||||
if (i>m_args.size() || i+n>m_args.size()) throw_("out of range");
|
||||
m_args.erase(m_args.begin()+i,m_args.begin()+i+n);
|
||||
}
|
||||
|
||||
friend ostream& operator<<(ostream& s,const args& v)
|
||||
{
|
||||
for(t_args::const_iterator itt=v.m_args.begin();itt!=v.m_args.end();++itt){
|
||||
s << *itt << " ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __ARGS_H__
|
||||
143
cpp/wiiscan/src/configfile.h
Normal file
143
cpp/wiiscan/src/configfile.h
Normal file
@@ -0,0 +1,143 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __CONFIGFILE_H__
|
||||
#define __CONFIGFILE_H__
|
||||
|
||||
class Configfile {
|
||||
private:
|
||||
typedef vector<string> t_value;
|
||||
t_value m_text;
|
||||
map<string,t_value> m_vals;
|
||||
string m_rem;
|
||||
string m_strip;
|
||||
string m_file;
|
||||
|
||||
void Load(istream &s)
|
||||
{
|
||||
if (!s) throw_("bad stream in configfile input operator");
|
||||
char buff[32*1024];
|
||||
bool ini=true;
|
||||
while(s.getline(buff,32*1024)) {
|
||||
const string b(strip(buff));
|
||||
if (ini && b!=m_rem + " Configfile_begin") throw_("bad stream in configfile input operator, missing begin tag");
|
||||
if (b==m_rem + " Configfile_end") return;
|
||||
const string t(strip(removerems(b,m_rem)));
|
||||
if (t.size()>0){
|
||||
m_text.push_back(t);
|
||||
const size_t n=t.find_first_of("=");
|
||||
istringstream s2(t.substr(0,n) + " " + (n==string::npos ? "" : t.substr(n+1)));
|
||||
string v,k;
|
||||
s2 >> k;
|
||||
while ((s2 >> v)) m_vals[k].push_back(v);
|
||||
}
|
||||
ini=false;
|
||||
}
|
||||
throw_("bad stream in configfile input operator, missing end tag");
|
||||
}
|
||||
|
||||
void Strip(const string& s) const
|
||||
{
|
||||
for(size_t i=0;i<m_strip.size();++i){
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
Configfile() : m_rem("%") {}
|
||||
|
||||
Configfile(const string& filename,const string rem="%") : m_rem(rem), m_file(filename)
|
||||
{
|
||||
ifstream s(filename.c_str());
|
||||
if (!s) throw_("File <" + filename + "> does not exist");
|
||||
Load(s);
|
||||
}
|
||||
|
||||
Configfile(istream& s,const string rem="%") : m_rem(rem)
|
||||
{
|
||||
if (!s) throw_("stream is invalid");
|
||||
Load(s);
|
||||
}
|
||||
|
||||
size_t size() const {return m_text.size();}
|
||||
const string& operator[](const size_t n) const {assert(n<m_text.size()); return m_text[n];}
|
||||
const t_value& operator()(const string& key) const {return Get(key);}
|
||||
bool hasEntry (const string& key) const {map<string,t_value >::const_iterator itt=m_vals.find(key); return itt!=m_vals.end();}
|
||||
void Save(const string& filename) {ofstream s(filename.c_str()); s << *this;}
|
||||
|
||||
bool operator==(const Configfile& c) const
|
||||
{
|
||||
if (m_text!=c.m_text) return false;
|
||||
else if (m_vals!=c.m_vals) return false;
|
||||
else if (m_rem!=c.m_rem) return false;
|
||||
else if (m_strip!=c.m_strip) return false;
|
||||
else if (m_file!=c.m_file) return false;
|
||||
return true;
|
||||
}
|
||||
bool operator!=(const Configfile& c) const {return !this->operator==(c);}
|
||||
|
||||
void Checkfilechange()
|
||||
{
|
||||
if (m_file.empty()) return;
|
||||
Configfile c(m_file);
|
||||
if (c!=*this) *this=c;
|
||||
}
|
||||
|
||||
const t_value& Get(const string& key) const
|
||||
{
|
||||
map<string,t_value >::const_iterator itt=m_vals.find(key);
|
||||
if (itt==m_vals.end()) throw_("No such entry, <" + key + ">, in configfile");
|
||||
return itt->second;
|
||||
}
|
||||
|
||||
template<class T> const T Get(const string& key,const bool fullline=false) const
|
||||
{
|
||||
const t_value& v=Get(key);
|
||||
assert( v.size()>0 );
|
||||
string s=v[0];
|
||||
if (fullline) for(size_t i=1;i<v.size();++i) s += " " + v[i];
|
||||
T t=totype<T>(s);
|
||||
return t;
|
||||
}
|
||||
|
||||
template<class T> const T Initialize(const string& key,const T valiueifnotfound,const bool fullline=false) const
|
||||
{
|
||||
if (!hasEntry(key)) return valiueifnotfound;
|
||||
else return Get<T>(key,fullline);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
pair<bool,T> GetConfig(const string& e) const
|
||||
{
|
||||
if (!hasEntry(e)) return make_pair(false,T());
|
||||
else return make_pair(true,Get<T>(e,true));
|
||||
}
|
||||
|
||||
template<class T> void Set(const string& key,const T& v)
|
||||
{
|
||||
t_value val;
|
||||
val.push_back(tostring(v));
|
||||
m_vals[key]=val;
|
||||
m_text.push_back(key + " " + val[0]);
|
||||
}
|
||||
|
||||
friend ostream& operator<<(ostream& s,const Configfile& x)
|
||||
{
|
||||
s << x.m_rem << " Configfile_begin\n";
|
||||
for(map<string,t_value>::const_iterator itt1=x.m_vals.begin();itt1!=x.m_vals.end();++itt1){
|
||||
s << "\t" << itt1->first << " = ";
|
||||
for(t_value::const_iterator itt2=itt1->second.begin();itt2!=itt1->second.end();++itt2) s << *itt2 << " ";
|
||||
s << "\n";
|
||||
}
|
||||
s << x.m_rem << " Configfile_end\n";
|
||||
// if (!s) throw_("bad stream in configfile output operator");, XXX throws in cout!?
|
||||
return s;
|
||||
}
|
||||
|
||||
friend istream& operator>>(istream& s,Configfile& x){x.Load(s); return s;}
|
||||
};
|
||||
#endif // __CONFIGFILE_H__
|
||||
197
cpp/wiiscan/src/exception.h
Normal file
197
cpp/wiiscan/src/exception.h
Normal file
@@ -0,0 +1,197 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __EXCEPTION_H__
|
||||
#define __EXCEPTION_H__
|
||||
|
||||
// forward defs to funs.h
|
||||
string Getlocaltime();
|
||||
size_t GetThreadId();
|
||||
int Message(const string& title,const string& msg,const int type=0);
|
||||
|
||||
// simple class for debugging call stack
|
||||
#ifdef _DEBUG
|
||||
struct Stackinfo : public vector<string> {
|
||||
friend ostream& operator<<(ostream& s,const Stackinfo& x)
|
||||
{
|
||||
s << "Function stack {" << endl;
|
||||
for(int i=x.size();i>0;--i){
|
||||
const string& f=x[i-1];
|
||||
s << " [" << i-1 << "]: " << f << "(...)" << endl;
|
||||
}
|
||||
return s << "}" << endl;
|
||||
}
|
||||
};
|
||||
|
||||
class Funstack {
|
||||
private:
|
||||
const string m_f;
|
||||
static map<size_t,Stackinfo> m_s;
|
||||
|
||||
Funstack(const Funstack&);
|
||||
void operator=(const Funstack&);
|
||||
|
||||
public:
|
||||
Funstack(const string& f,const int line,const string& file) : m_f(f) {m_s[GetThreadId()].push_back(f);}
|
||||
~Funstack()
|
||||
{
|
||||
const size_t tid=GetThreadId();
|
||||
assert(m_s.find(tid)!=m_s.end());
|
||||
assert(m_s[tid].size()>0 && m_s[tid].back()==m_f);
|
||||
m_s[tid].pop_back();
|
||||
}
|
||||
|
||||
static const Stackinfo GetStack()
|
||||
{
|
||||
const size_t tid=GetThreadId();
|
||||
if (m_s.find(tid)==m_s.end()) return Stackinfo();
|
||||
else return m_s[tid];
|
||||
}
|
||||
};
|
||||
map<size_t,Stackinfo> Funstack::m_s; // initialize static var
|
||||
#define FUNSTACK Funstack __f_stack__(__FUNCTION__,__LINE__,__FILE__)
|
||||
#else
|
||||
#define FUNSTACK
|
||||
#define DUMPSTACK(s)
|
||||
struct Stackinfo {
|
||||
friend ostream& operator<<(ostream& s,const Stackinfo& x) {return s;}
|
||||
};
|
||||
class Funstack {
|
||||
public:
|
||||
static Stackinfo GetStack() {return Stackinfo();}
|
||||
};
|
||||
#endif
|
||||
|
||||
// tee like logger class
|
||||
class Logger
|
||||
{
|
||||
private:
|
||||
//ostream* m_log;
|
||||
string m_logfilename;
|
||||
ofstream m_logfile;
|
||||
ostream* m_log;
|
||||
const bool m_logstdout,m_logstderr;
|
||||
|
||||
Logger(const Logger&);
|
||||
void operator=(const Logger&);
|
||||
|
||||
public:
|
||||
Logger(ostream* log,const bool logstdout=true,const bool logstderr=false) : m_log(log), m_logstdout(logstdout), m_logstderr(logstderr) {}
|
||||
|
||||
void operator=(ostream* log){m_logfilename=""; m_logfile.close(); m_log=log;}
|
||||
void open(const string& logfilename,const ios_base::openmode mode)
|
||||
{
|
||||
m_log=0;
|
||||
if (m_logfile.is_open()) m_logfile.close();
|
||||
m_logfilename=logfilename;
|
||||
m_logfile.open(m_logfilename.c_str(),mode);
|
||||
if (!m_logfile) throw("cannot write to logfile <" + logfilename + ">"); // Exception uses logger class, so do not throw a nice Exception class here, use a plain throw
|
||||
m_log=&m_logfile;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
if (m_logfile.is_open()) m_logfile.close();
|
||||
m_logfile.open(m_logfilename.c_str());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
friend Logger& operator<<(Logger& log,const T& t)
|
||||
{
|
||||
if(log.m_logstdout) cout << t;
|
||||
if(log.m_logstderr) cerr << t;
|
||||
if(log.m_log!=0) (*(log.m_log)) << t;
|
||||
return log;
|
||||
}
|
||||
|
||||
// handle endl and like
|
||||
friend Logger& operator<<(Logger& log,std::ostream& (*fn)(std::ostream&))
|
||||
{
|
||||
if(log.m_logstdout) fn(cout);
|
||||
if(log.m_logstderr) fn(cerr);
|
||||
if(log.m_log!=0) fn(*(log.m_log));
|
||||
return log;
|
||||
}
|
||||
|
||||
void writelogheader(const string& msg)
|
||||
{
|
||||
if(m_log==0) return;
|
||||
else{
|
||||
(*m_log) << "********************************************************" << endl;
|
||||
(*m_log) << "** Logentry: " << msg << endl;
|
||||
(*m_log) << "** Time: " << Getlocaltime();
|
||||
(*m_log) << "********************************************************" << endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// static global logging, default standand out
|
||||
static Logger g_log(0,true,false);
|
||||
|
||||
class Exception{
|
||||
private:
|
||||
const string m_msg;
|
||||
const string m_file;
|
||||
const int m_line;
|
||||
const Stackinfo m_stack;
|
||||
|
||||
public:
|
||||
Exception(const string msg,const string file,const int line,const Stackinfo s) : m_msg(msg), m_file(file), m_line(line), m_stack(s) {}
|
||||
Exception(const char* msg,const string file,const int line,const Stackinfo s) : m_msg(msg), m_file(file), m_line(line), m_stack(s) {}
|
||||
|
||||
inline static string FormatCompilerMsg(const string& file,const int line,const bool warnonly=false)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return file + "(" + Exception::tostring(line) + ") : " + (warnonly ? "warning : " : "error : ");
|
||||
#else
|
||||
return file + ":" + Exception::tostring(line) + ": " + (warnonly ? "warning: " : "error: ");
|
||||
#endif
|
||||
}
|
||||
|
||||
inline static void throw_fun(const string& msg,const string& file,const int line)
|
||||
{
|
||||
const string msg2=Exception::FormatCompilerMsg(file,line) + "throwing exception: " + msg;
|
||||
g_log << msg2;
|
||||
#ifdef _WINDOWS_
|
||||
const string f=tostring(Funstack::GetStack());
|
||||
const string msg3=msg2 + (f.size()>0 ? "\n\n" : "") + f.substr(0,300) + (f.size()>300 ? "\n..." : "");
|
||||
Message("Exception encountered...",msg3,0);
|
||||
#endif
|
||||
throw Exception(msg,file,line,Funstack::GetStack());
|
||||
}
|
||||
|
||||
inline string Msg() const
|
||||
{
|
||||
return FormatCompilerMsg(m_file,m_line) + "Exception: " + m_msg;
|
||||
}
|
||||
|
||||
friend ostream& operator<<(ostream& os,const Exception& e)
|
||||
{
|
||||
return os << e.Msg() << endl << e.m_stack;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static string tostring(const T& x)
|
||||
{
|
||||
ostringstream os;
|
||||
os << x;
|
||||
return os.str();
|
||||
}
|
||||
};
|
||||
|
||||
#define throw_(msg) Exception::throw_fun(msg,__FILE__, __LINE__)
|
||||
#define warn_(msg) cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__,true) << msg << endl;
|
||||
|
||||
#define CATCH_ALL\
|
||||
catch(const char* s) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught exception chars: " << s;}\
|
||||
catch(const string& s) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught exception string: " << s;}\
|
||||
catch(const Exception& s){cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught Exception class: " << s;}\
|
||||
catch(...) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught unknown exception";}\
|
||||
cerr << "...aborting" << endl;
|
||||
|
||||
#endif // __EXCEPTION_H__
|
||||
208
cpp/wiiscan/src/file.h
Normal file
208
cpp/wiiscan/src/file.h
Normal file
@@ -0,0 +1,208 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __FILE_H__
|
||||
#define __FILE_H__
|
||||
|
||||
inline bool FileExists(const std::string& f)
|
||||
{
|
||||
ifstream s(f.c_str());
|
||||
return (!s)==false;
|
||||
}
|
||||
|
||||
inline void AssertFileExists(const std::string& f)
|
||||
{
|
||||
if (!FileExists(f)) throw_("File <" + f + "> does not exist");
|
||||
}
|
||||
|
||||
inline size_t FileSize(const std::string& f)
|
||||
{
|
||||
AssertFileExists(f);
|
||||
ifstream s(f.c_str());
|
||||
if (!s) throw_("Stream is bad (file <" + f + ">)");
|
||||
s.seekg(0,ios::end);
|
||||
if (!s) throw_("Stream is bad (file <" + f + ">)");
|
||||
return s.tellg();
|
||||
}
|
||||
|
||||
inline void AssertFileNotEmpty(const std::string& f)
|
||||
{
|
||||
if (FileSize(f)==0) throw_("File <" + f + "> is empty");
|
||||
}
|
||||
|
||||
inline size_t FileTime(const string& file)
|
||||
{
|
||||
AssertFileExists(file);
|
||||
const string t=System("date -r " + file + " +%s",true,true); // seconds since 1970-01-01 00:00:00 UTC
|
||||
return totype<size_t>(t);
|
||||
// #include <sys/stat.h>
|
||||
// #include <unistd.h>
|
||||
// struct stat s;
|
||||
// int n=stat(file.c_str(),&s);
|
||||
// if (n!=0) throw_("cannot stat file <" + file + ">");
|
||||
// assert( sizeof(time_t)==sizeof(size_t) );
|
||||
// return s.st_mtime;
|
||||
}
|
||||
|
||||
inline bool isFileNewer(const string& file0,const string& file1)
|
||||
{
|
||||
return FileTime(file0)>FileTime(file1);
|
||||
}
|
||||
|
||||
inline bool DirExists(const std::string& f)
|
||||
{
|
||||
const string file=f + "/.dummy.txt";
|
||||
ofstream s(file.c_str());
|
||||
if(!s) return false;
|
||||
s << "testfile";
|
||||
if(!s) return false;
|
||||
s.close();
|
||||
return FileSize(file)==8;
|
||||
}
|
||||
|
||||
inline string MakeSuffix(const int n)
|
||||
{
|
||||
assert(n>=0);
|
||||
if (n<=9) return "00" + tostring(n);
|
||||
else if (n<=99) return "0" + tostring(n);
|
||||
else return tostring(n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Readdata(const string& tok,istream& is,T& t)
|
||||
{
|
||||
if (!is) throw_("Stream is bad");
|
||||
is >> t;
|
||||
if (!is) throw_("Reading {" + tok + "} settings");
|
||||
}
|
||||
|
||||
inline string Readline(istream& is)
|
||||
{
|
||||
char buff[16*1024];
|
||||
is.getline(buff,16*1024);
|
||||
return string(buff);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T Readtyp(ifstream& s){
|
||||
T x;
|
||||
s.read(reinterpret_cast<char*>(&x),sizeof(x));
|
||||
if(!s) throw_("bad stream");
|
||||
return x;
|
||||
}
|
||||
|
||||
inline string Readstring(ifstream& s){
|
||||
char c=0;
|
||||
string t;
|
||||
do{
|
||||
c=Readtyp<char>(s);
|
||||
if(c!=0) t+=c;
|
||||
}
|
||||
while (c!=0);
|
||||
return t;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline vector<T> Readbin(std::ifstream& s,const int size)
|
||||
{
|
||||
if(!s) throw_("bad stream");
|
||||
vector<T> x(size);
|
||||
s.read(reinterpret_cast<char*>(&x.front()),x.size()*sizeof(T));
|
||||
if(!s) throw_( "bad write");
|
||||
return x;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Writetyp(ofstream& s,const T& x){
|
||||
s.write(reinterpret_cast<const char*>(&x),sizeof(x));
|
||||
if(!s) throw_( "bad stream");
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Writebin(std::ofstream& s,const std::vector<T>& x,const bool writetag)
|
||||
{
|
||||
if(!s) throw_("bad stream");
|
||||
const size_t sz=x.size()*sizeof(T);
|
||||
if(writetag){
|
||||
Writetyp(s,sz);
|
||||
}
|
||||
if(!s) throw_( "bad stream" );
|
||||
s.write(reinterpret_cast<const char*>(&x.front()),sz);
|
||||
if(!s) throw_( "bad write");
|
||||
if (writetag) Writetyp(s,sz);
|
||||
if(!s) throw_( "bad stream");
|
||||
}
|
||||
|
||||
template<class T,class R>
|
||||
inline void Writebin(std::ofstream& s,const std::map<T,R>& x,const bool writetag)
|
||||
{
|
||||
vector<T> t;
|
||||
vector<R> r;
|
||||
t.reserve(x.size());
|
||||
r.reserve(x.size());
|
||||
for(typename std::map<T,R>::const_iterator itt=x.begin();itt!=x.end();++itt){
|
||||
t.push_back(itt->first);
|
||||
r.push_back(itt->second);
|
||||
}
|
||||
if (writetag) {
|
||||
Writetyp(s,x.size());
|
||||
Writetyp(s,static_cast<unsigned int>(sizeof(T)));
|
||||
Writetyp(s,static_cast<unsigned int>(sizeof(R)));
|
||||
}
|
||||
Writebin(s,t,writetag);
|
||||
Writebin(s,r,writetag);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Readbin(std::ifstream& s,vector<T>& x)
|
||||
{
|
||||
if(!s) throw_("bad stream");
|
||||
const size_t sz=Readtyp<size_t>(s);
|
||||
if(!s) throw_( "bad stream" );
|
||||
if(sz%sizeof(T)!=0) throw_("bad size tag");
|
||||
x.resize(sz/sizeof(T));
|
||||
s.read(reinterpret_cast<char*>(&x.front()),sz);
|
||||
if(!s) throw_( "bad write");
|
||||
if (Readtyp<size_t>(s)!=sz) throw_("bad size tag");
|
||||
if(!s) throw_( "bad stream");
|
||||
}
|
||||
|
||||
template<class T,class R>
|
||||
inline void Readbin(std::ifstream& s,map<T,R>& x)
|
||||
{
|
||||
vector<T> t;
|
||||
vector<R> r;
|
||||
|
||||
const size_t sz=Readtyp<size_t>(s);
|
||||
const size_t szT=Readtyp<unsigned int>(s);
|
||||
const size_t szR=Readtyp<unsigned int>(s);
|
||||
|
||||
if (szT!=sizeof(T)) throw_("type T size mismatch in Readbin (map)");
|
||||
if (szR!=sizeof(R)) throw_("type R size mismatch in Readbin (map)");
|
||||
|
||||
Readbin(s,t);
|
||||
Readbin(s,r);
|
||||
if (t.size()!=r.size()) throw_("size mismatch in Readbin (map)");
|
||||
x.clear();
|
||||
for(size_t i=0;i<t.size();++i){
|
||||
x[t[i]]=r[i];
|
||||
}
|
||||
if (x.size()!=sz) throw_("map size mismatch in Readbin (map)");
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Writeascii(const string& filename,const std::vector<T>& x,const string& comment="",const char& newline='\n')
|
||||
{
|
||||
ofstream s(filename.c_str());
|
||||
if(!s) throw_("bad file <" + filename + ">");
|
||||
s << "% Writeascii: size=" << x.size() << " " << comment << "\n";
|
||||
for(size_t i=0;i<x.size();++i) s << x[i] << newline;
|
||||
if(!s) throw_( "bad writing to file <" + filename + ">");
|
||||
}
|
||||
|
||||
#endif // __FILE_H__
|
||||
413
cpp/wiiscan/src/funs.h
Normal file
413
cpp/wiiscan/src/funs.h
Normal file
@@ -0,0 +1,413 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __FUNS_H__
|
||||
#define __FUNS_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#define Unimplemented throw_("Function unimplemented")
|
||||
#define Dontgethere throw_("Dontgethere")
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ON_DEBUG(a) a
|
||||
#else
|
||||
#define ON_DEBUG(a)
|
||||
#endif
|
||||
|
||||
#ifdef USE_FFTW
|
||||
extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
|
||||
#endif
|
||||
|
||||
// Small template funs
|
||||
template<class T,class R> bool isinmap (const map<T,R>& m,const T& t) {return m.size()>=2 && m.begin()->first<=t && t<(--m.end())->first;}
|
||||
template<class T> const size_t getsteps(const T& r0,const T& r1,const T& rstep,const bool logarithmic) {size_t N=0; for(T r=r0;r<r1;logarithmic ? r*=rstep/T(1) : r+=rstep) ++N; return N;}
|
||||
|
||||
inline std::string Version(){return string("VERSION: ") + VERSION + "." + VERSION_REV;}
|
||||
|
||||
inline std::string Config()
|
||||
{
|
||||
std::string s;
|
||||
#ifdef NDEBUG
|
||||
s+="NDEBUG";
|
||||
#else
|
||||
#ifdef PROFILE
|
||||
s+="PROFILE";
|
||||
#else
|
||||
s+="DEBUG";
|
||||
#endif
|
||||
#endif
|
||||
#ifdef USE_UNITS
|
||||
s+= " USE_UNITS";
|
||||
#endif
|
||||
#ifdef USE_FLOAT_CHECKS
|
||||
s+= " USE_FLOAT_CHECKS";
|
||||
#endif
|
||||
#ifdef USE_FFTW_IC
|
||||
s+= " USE_FFTW_IC";
|
||||
#endif
|
||||
#ifdef USE_FFTW
|
||||
s+= " USE_FFTW";
|
||||
#endif
|
||||
#ifdef USE_MPI
|
||||
s+= " USE_MPI";
|
||||
#endif
|
||||
if (sizeof(void*)==4) s+=" 32BIT";
|
||||
else if (sizeof(void*)==8) s+=" 64BIT";
|
||||
else s+=" XXBIT";
|
||||
|
||||
const long one= 1;
|
||||
const int big=!(*(reinterpret_cast<const char *>(&one)));
|
||||
if (big) s+=" BIGENDIAN";
|
||||
else s+=" LITENDIAN";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
inline string FormatCompilerMsg(const string& file,const int line)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return file + ":" + line + ":";
|
||||
#else
|
||||
return file + "(" + line + ")";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
extern "C"{
|
||||
#ifdef _UNICODE
|
||||
#pragma message("ERROR: toolsfun cannot handle unicode...giving up compilation");
|
||||
ERROR_complier
|
||||
#endif
|
||||
|
||||
#ifdef _AFXDLL
|
||||
__declspec(dllimport) void* __stdcall GetCurrentThread();
|
||||
__declspec(dllimport) void* __stdcall GetCurrentThreadId();
|
||||
__declspec(dllimport) int __stdcall SetThreadPriority(void* hThread,int nPriority);
|
||||
#else
|
||||
//void* __stdcall GetCurrentThread();
|
||||
//void* __stdcall GetCurrentThreadId();
|
||||
//int __stdcall SetThreadPriority(void* hThread,int nPriority);
|
||||
__declspec(dllimport) void* __stdcall GetCurrentThread();
|
||||
__declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
|
||||
__declspec(dllimport) int __stdcall SetThreadPriority(void* hThread,int nPriority);
|
||||
__declspec(dllimport) int __stdcall GetThreadPriority(void* hThread);
|
||||
__declspec(dllimport) unsigned int __stdcall WinExec(const char* lpCmdLine,unsigned int uCmdShow);
|
||||
#ifndef _WINDOWS_
|
||||
__declspec(dllimport) unsigned int __stdcall MessageBox(void* hWnd,const char* lpText,const char* lpCaption,unsigned int Type);
|
||||
__declspec(dllimport) unsigned long __stdcall GetCurrentDirectory(unsigned long nBufferLength,char* lpBuffer);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
int nice(int inc);
|
||||
#endif
|
||||
|
||||
inline int Message(const string& title,const string& msg,const int type)
|
||||
{
|
||||
#ifdef WIN32
|
||||
// 0 = MB_OK
|
||||
// 1 = MB_OKCANCEL
|
||||
// 2 = MB_ABORTRETRYIGNORE
|
||||
// 3 = MB_YESNOCANCEL
|
||||
// 4 = MB_YESNO
|
||||
// 5 = MB_RETRYCANCEL
|
||||
// 6 = MB_CANCELTRYCONTINUE: if(WINVER >= 0x0500)
|
||||
MessageBox(NULL,msg.c_str(),title.c_str(),type);
|
||||
#else
|
||||
Unimplemented;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
string GetCurrentDir()
|
||||
{
|
||||
#ifdef WIN32
|
||||
char buff[16*1024];
|
||||
if(GetCurrentDirectory(16*1024,buff)==0) throw_("GetCurrentDirectory() failed");
|
||||
return tostring(buff);
|
||||
#else
|
||||
Unimplemented;
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
inline void SetNiceLevel(const int level)
|
||||
{
|
||||
#ifdef WIN32
|
||||
// THREAD_PRIORITY_ABOVE_NORMAL 1 Priority 1 point above the priority class.
|
||||
// THREAD_PRIORITY_BELOW_NORMAL -1 Priority 1 point below the priority class.
|
||||
// THREAD_PRIORITY_HIGHEST 2 Priority 2 points above the priority class.
|
||||
// THREAD_PRIORITY_IDLE -15 Base priority of 1 for IDLE_PRIORITY_CLASS,...
|
||||
// THREAD_PRIORITY_LOWEST -2 Priority 2 points below the priority class.
|
||||
// THREAD_PRIORITY_NORMAL 0 Normal priority for the priority class.
|
||||
// THREAD_PRIORITY_TIME_CRITICAL 15 Base priority of 15 for IDLE_PRIORITY_CLASS,...
|
||||
if (level!=0 && level!=1 && level!=-1 && level!=2 && level!=-2 && level!=15 && level!=-15) throw_("wrong Win32 nice level, must be oneof -15,-2,-1,0,1,2,15");
|
||||
SetThreadPriority(GetCurrentThread(),-level);
|
||||
assert( GetThreadPriority(GetCurrentThread())==-level );
|
||||
#else
|
||||
const int n=nice(level);
|
||||
if (n<0) throw_("Could not set nice level");
|
||||
#endif
|
||||
}
|
||||
|
||||
inline size_t GetThreadId()
|
||||
{
|
||||
#ifdef WIN32
|
||||
assert( sizeof(size_t)==sizeof(unsigned long) );
|
||||
return GetCurrentThreadId();
|
||||
#else
|
||||
// may be replaced by return 0; if phtread not found!
|
||||
assert( sizeof(size_t)==sizeof(pthread_t) );
|
||||
const pthread_t p=pthread_self();
|
||||
size_t q=0;
|
||||
memcpy(&q,&p,sizeof(q));
|
||||
return q;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TOOLSFUN_QUIET_WIN32_SYSTEM
|
||||
#ifdef WIN32
|
||||
// make a special non-console system call, instead of the standard system()
|
||||
// XXX SystemWin, does not wait for process to finish, CreatProc still create window
|
||||
|
||||
int SystemWin(const string& cmd)
|
||||
{
|
||||
//ShellExecute, CreateProcess, WinExec or system
|
||||
// HINSTANCE hi=ShellExecute(NULL,NULL,cmdx,"","",SW_SHOSNOACTIVATE);
|
||||
// if (reinterpret_cast<int>(hi)<32) MessageBox(NULL,(string("ShellExecute <") + cmd + "> failed").c_str(),"Error",0);
|
||||
|
||||
// const string cmd2="\\\"" + cmd + "\\\""; // fix problem with spaces in executable, not working yet
|
||||
unsigned int r=WinExec(cmd.c_str(),4);
|
||||
return r<32 ? -1 : 0;
|
||||
}
|
||||
|
||||
bool CreateProc(const string& cmd,const bool throwexception=true,const bool waitforprocesstofinish=true)
|
||||
{
|
||||
STARTUPINFO s;
|
||||
PROCESS_INFORMATION p;
|
||||
memset(&s,0,sizeof(s));
|
||||
memset(&p,0,sizeof(p));
|
||||
s.cb=sizeof(s);
|
||||
|
||||
// to avoid const cast of char* in CreateProcess
|
||||
char cmdx[16*1024];
|
||||
strcpy_s(cmdx,16*1024,cmd.c_str());
|
||||
|
||||
const int r=CreateProcess(0,cmdx,0,0,false,CREATE_DEFAULT_ERROR_MODE,0,0,&s,&p);
|
||||
if (r!=0) {if(waitforprocesstofinish) WaitForSingleObject(p.hProcess,INFINITE);}
|
||||
else {
|
||||
if (throwexception) throw_(string("CreateProcess() failed with return code <") + GetLastError() + ">");
|
||||
else return false;
|
||||
}
|
||||
|
||||
// Release handles
|
||||
assert(r!=0);
|
||||
CloseHandle(p.hProcess);
|
||||
CloseHandle(p.hThread);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inline string System(const string& cmd,const bool throwexception=true,const bool captureoutput=false,int* pret=0)
|
||||
{
|
||||
if (!captureoutput){
|
||||
#ifdef TOOLSFUN_QUIET_WIN32_SYSTEM
|
||||
const int n=SystemWin(cmd);
|
||||
#else
|
||||
const int n=system(cmd.c_str());
|
||||
#endif
|
||||
if (n!=0 && throwexception) throw_(string("system command failed with code=") + n + " cmd=<" + cmd + ">");
|
||||
if (pret!=0) *pret=n;
|
||||
return "";
|
||||
} else {
|
||||
#ifdef WIN32
|
||||
const string rm="del ";
|
||||
char tmp[1024];
|
||||
if (tmpnam(tmp)) throw_("error in creating win32 temp name");
|
||||
const string file(tmp);
|
||||
#else
|
||||
const string rm="rm ";
|
||||
const string file=tmpnam("tempfile");
|
||||
#endif
|
||||
ifstream s1(file.c_str());
|
||||
if(s1) {
|
||||
s1.close();
|
||||
System((rm + file).c_str(),true,false);
|
||||
}
|
||||
System(cmd + " > " + file,throwexception,false,pret);
|
||||
|
||||
string t;
|
||||
char buff[16*1024];
|
||||
ifstream s2(file.c_str());
|
||||
while(s2) {
|
||||
s2.getline(buff,16*1024);
|
||||
if (s2) t += buff;
|
||||
}
|
||||
s2.close();
|
||||
System((rm + file).c_str(),true,false);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
string Getlocaltime()
|
||||
{
|
||||
FUNSTACK;
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
struct tm* timeinfo;
|
||||
timeinfo = localtime(&rawtime);
|
||||
return asctime(timeinfo);
|
||||
}
|
||||
|
||||
class timer
|
||||
{
|
||||
private:
|
||||
double m_t,m_cpu_t;
|
||||
double* m_addt;
|
||||
mutable double m_last_t,m_last_eta;
|
||||
|
||||
static double gettime()
|
||||
{
|
||||
#ifdef WIN32
|
||||
return 1.0*clock()/CLOCKS_PER_SEC; // use low-res clock
|
||||
// FILETIME ft;
|
||||
// unsigned __int64 tmpres = 0;
|
||||
//
|
||||
// GetSystemTimeAsFileTime(&ft);
|
||||
//
|
||||
// tmpres |= ft.dwHighDateTime;
|
||||
// tmpres <<= 32;
|
||||
// tmpres |= ft.dwLowDateTime;
|
||||
//
|
||||
// converting file time to unix epoch
|
||||
// tmpres -= DELTA_EPOCH_IN_MICROSECS;
|
||||
// tmpres /= 10; // convert into microseconds
|
||||
// tv->tv_sec = (long)(tmpres / 1000000UL);
|
||||
// tv->tv_usec = (long)(tmpres % 1000000UL);
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,NULL);
|
||||
return tv.tv_sec + static_cast<double>(tv.tv_usec)/1000000;
|
||||
#endif
|
||||
}
|
||||
|
||||
static double getcputime()
|
||||
{
|
||||
static const double f=1.0/CLOCKS_PER_SEC;
|
||||
return f*clock();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static double Remaining(const double t,const T& n,const T& N)
|
||||
{
|
||||
if (n>=N || N<=T(0)) throw_("value out of range in timer::Remaining, n>=N or N<=0, n=" + tostring(n) + " N=" + tostring(N));
|
||||
const double p=static_cast<double>(n/T(1)+1)/(N/T(1));
|
||||
const double p2=p>0 ? t/p : 0;
|
||||
return p2>t ? p2-t : 0;
|
||||
}
|
||||
|
||||
public:
|
||||
timer() : m_t(gettime()), m_cpu_t(getcputime()), m_addt(0), m_last_t(-1), m_last_eta(-1) {}
|
||||
timer(double& t) : m_t(gettime()), m_cpu_t(getcputime()), m_addt(&t), m_last_t(-1), m_last_eta(-1) {}
|
||||
~timer() {if (m_addt!=0) (*m_addt) += elapsed();}
|
||||
|
||||
void reset () {m_t=gettime(); m_cpu_t=getcputime(); m_last_t=-1; m_last_eta=-1;}
|
||||
double elapsed() const {return gettime()-m_t;}
|
||||
double cputime() const {return getcputime()-m_cpu_t;}
|
||||
|
||||
static string ToHMS(const double& t)
|
||||
{
|
||||
assert( t>=0 );
|
||||
const unsigned int it=static_cast<unsigned int>(t+.5);
|
||||
const unsigned int hours=it/(60*60);
|
||||
const unsigned int mins=(it-hours*60*60)/(60);
|
||||
const unsigned int secs=(it-hours*60*60-mins*60);
|
||||
assert( secs<60 && mins<60);
|
||||
return tostring(hours) + ":" + (mins<10 ? "0": "") + tostring(mins) + ":" + (secs<10 ? "0": "") + tostring(secs);
|
||||
}
|
||||
|
||||
template<class T> static inline int Topercent(const T x,const T N,const int decimals=-1)
|
||||
{
|
||||
assert(x<N && N!=T(0));
|
||||
float pf=static_cast<float>(x/T(1))/(N/T(1));
|
||||
if (decimals>0) pf=static_cast<int>(pf*decimals)/(1.0*decimals);
|
||||
return static_cast<int>(pf*100+.5);
|
||||
}
|
||||
|
||||
template<class T> void ToEta(const T& n,const T& N,ostream& s,const double timeprintsteps=30,const bool verboseprint=false) const
|
||||
{
|
||||
if (n>=N) return;
|
||||
assert( n<N );
|
||||
|
||||
const double t=gettime()-m_t;
|
||||
if (n==T(0)) {
|
||||
m_last_t=t;
|
||||
return;
|
||||
}
|
||||
|
||||
const double e=(t-m_last_t);
|
||||
if (e>timeprintsteps) {
|
||||
const double f=timeprintsteps*60;
|
||||
const double r=Remaining(t,n,N);
|
||||
if (m_last_eta<0 || r<f || (r>f && e>f) /*|| (m_last_eta>0 && r>1.2*m_last_eta) */ ){
|
||||
time_t tm;
|
||||
time(&tm);
|
||||
const string systime=ctime(&tm);
|
||||
if (m_last_eta<0) s << "Current system time: " << systime;
|
||||
tm += static_cast<time_t>(r);
|
||||
const string eta=ctime(&tm);
|
||||
const bool extraday=(eta.substr(0,3)!=systime.substr(0,3));
|
||||
const string eday=extraday ? " "+eta.substr(0,3)+" " : "";
|
||||
s << "Time [h:m:s]=" << ToHMS(t) << ", R=" << ToHMS(r) << ", ETA=" << eday << eta.substr(11,8);
|
||||
if(verboseprint) {
|
||||
const string t=", n/N=" + tostring(n) + "/" + tostring(N) + "=" + tostring(Topercent(n,N,10)) + " percent,";
|
||||
s << t;
|
||||
for(size_t i=t.size();i<42;++i) s << " ";
|
||||
s << " CPU=" << ToHMS(cputime());
|
||||
}
|
||||
s << endl;
|
||||
|
||||
m_last_t=t;
|
||||
m_last_eta=r;
|
||||
}
|
||||
}
|
||||
}
|
||||
friend ostream& operator<<(ostream& s,const timer x)
|
||||
{
|
||||
return s << "Time [h:m:s]= " << x.ToHMS(x.elapsed()) << " CPU=" << x.ToHMS(x.cputime());
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
int SwapEndian(void *data,const size_t size) {
|
||||
|
||||
short xs;
|
||||
long xl;
|
||||
|
||||
switch (size){
|
||||
case 2:
|
||||
xs = *(short *)data;
|
||||
*(short *)data = ( ((xs & 0x0000ff00) >> 8) | ((xs & 0x000000ff) << 8) );
|
||||
break;
|
||||
case 4:
|
||||
xl = *(long *)data;
|
||||
*(long *)data = ( ((xl & 0xff000000) >> 24) | ((xl & 0x00ff0000) >> 8) |
|
||||
((xl & 0x0000ff00) << 8) | ((xl & 0x000000ff) << 24) );
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif // __FUNS_H__
|
||||
282
cpp/wiiscan/src/process.h
Normal file
282
cpp/wiiscan/src/process.h
Normal file
@@ -0,0 +1,282 @@
|
||||
#ifndef __PROCESS_H__
|
||||
#define __PROCESS_H__
|
||||
|
||||
#include <tlhelp32.h>
|
||||
|
||||
pair<HANDLE,PROCESSENTRY32> ProcessWalkInit()
|
||||
{
|
||||
// Take a snapshot of all processes in the system.
|
||||
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
||||
if( hProcessSnap == INVALID_HANDLE_VALUE ) throw_("CreateToolhelp32Snapshot() returned invalid handle");
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
PROCESSENTRY32 pe32;
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
// Retrieve information about the first process,
|
||||
// and exit if unsuccessful
|
||||
if(!Process32First(hProcessSnap,&pe32)) {
|
||||
CloseHandle(hProcessSnap); // clean the snapshot object
|
||||
throw_("Process32First"); // show cause of failure
|
||||
}
|
||||
|
||||
return make_pair(hProcessSnap,pe32);
|
||||
}
|
||||
|
||||
DWORD GetProcessID(const string& processname)
|
||||
{
|
||||
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
|
||||
HANDLE hProcessSnap=h.first;
|
||||
PROCESSENTRY32 pe32=h.second;
|
||||
|
||||
do {
|
||||
if (pe32.szExeFile==processname) {
|
||||
CloseHandle(hProcessSnap);
|
||||
return pe32.th32ProcessID;
|
||||
}
|
||||
} while( Process32Next(hProcessSnap,&pe32) );
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PROCESSENTRY32 GetProcessInfo(const DWORD id)
|
||||
{
|
||||
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
|
||||
HANDLE hProcessSnap=h.first;
|
||||
PROCESSENTRY32 pe32=h.second;
|
||||
|
||||
int n=0;
|
||||
do {
|
||||
if (pe32.th32ProcessID==id) {
|
||||
CloseHandle(hProcessSnap);
|
||||
return pe32;
|
||||
}
|
||||
} while( Process32Next(hProcessSnap,&pe32) );
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
ZeroMemory( &pe32, sizeof(pe32) );
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
return pe32;
|
||||
}
|
||||
|
||||
DWORD GetProcessCount(const string& processname)
|
||||
{
|
||||
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
|
||||
HANDLE hProcessSnap=h.first;
|
||||
PROCESSENTRY32 pe32=h.second;
|
||||
int n=0;
|
||||
do {
|
||||
if (pe32.szExeFile==processname) ++n;
|
||||
} while( Process32Next(hProcessSnap,&pe32) );
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
return n;
|
||||
}
|
||||
|
||||
bool KillProcessID(const DWORD id)
|
||||
{
|
||||
HANDLE hProcess = OpenProcess( PROCESS_TERMINATE, FALSE, id);
|
||||
if(hProcess==NULL) return false; // might have gone in the meantime, so no throw_("OpenProcess() got null handle");
|
||||
|
||||
const BOOL t=TerminateProcess(hProcess,-1);
|
||||
CloseHandle(hProcess);
|
||||
return t!=0;
|
||||
}
|
||||
|
||||
void KillAllProcesses(const string& exe)
|
||||
{
|
||||
// kill existing polls
|
||||
DWORD id=GetProcessID(exe);
|
||||
while(id!=0){
|
||||
KillProcessID(id);
|
||||
id=GetProcessID(exe);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#include <tchar.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
BOOL GetProcessList( );
|
||||
BOOL ListProcessModules( DWORD dwPID );
|
||||
BOOL ListProcessThreads( DWORD dwOwnerPID );
|
||||
void printError( TCHAR* msg );
|
||||
|
||||
FILE* log=fopen("d:\\plog.txt","w");
|
||||
|
||||
BOOL GetProcessList( )
|
||||
{
|
||||
HANDLE hProcessSnap;
|
||||
HANDLE hProcess;
|
||||
PROCESSENTRY32 pe32;
|
||||
DWORD dwPriorityClass;
|
||||
|
||||
// Take a snapshot of all processes in the system.
|
||||
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
|
||||
if( hProcessSnap == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
printError( TEXT("CreateToolhelp32Snapshot (of processes)") );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
pe32.dwSize = sizeof( PROCESSENTRY32 );
|
||||
|
||||
// Retrieve information about the first process,
|
||||
// and exit if unsuccessful
|
||||
if( !Process32First( hProcessSnap, &pe32 ) )
|
||||
{
|
||||
printError( TEXT("Process32First") ); // show cause of failure
|
||||
CloseHandle( hProcessSnap ); // clean the snapshot object
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Now walk the snapshot of processes, and
|
||||
// display information about each process in turn
|
||||
do
|
||||
{
|
||||
fprintf(log, "\n\n=====================================================" );
|
||||
fprintf(log, TEXT("\nPROCESS NAME: %s"), pe32.szExeFile );
|
||||
fprintf(log, "\n-----------------------------------------------------" );
|
||||
|
||||
// Retrieve the priority class.
|
||||
dwPriorityClass = 0;
|
||||
hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
|
||||
if( hProcess == NULL )
|
||||
printError( TEXT("OpenProcess") );
|
||||
else
|
||||
{
|
||||
dwPriorityClass = GetPriorityClass( hProcess );
|
||||
if( !dwPriorityClass )
|
||||
printError( TEXT("GetPriorityClass") );
|
||||
CloseHandle( hProcess );
|
||||
}
|
||||
|
||||
fprintf(log, "\n Process ID = 0x%08X", pe32.th32ProcessID );
|
||||
fprintf(log, "\n Thread count = %d", pe32.cntThreads );
|
||||
fprintf(log, "\n Parent process ID = 0x%08X", pe32.th32ParentProcessID );
|
||||
fprintf(log, "\n Priority base = %d", pe32.pcPriClassBase );
|
||||
if( dwPriorityClass )
|
||||
fprintf(log, "\n Priority class = %d", dwPriorityClass );
|
||||
|
||||
// List the modules and threads associated with this process
|
||||
ListProcessModules( pe32.th32ProcessID );
|
||||
ListProcessThreads( pe32.th32ProcessID );
|
||||
|
||||
} while( Process32Next( hProcessSnap, &pe32 ) );
|
||||
|
||||
CloseHandle( hProcessSnap );
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
|
||||
BOOL ListProcessModules( DWORD dwPID )
|
||||
{
|
||||
HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
|
||||
MODULEENTRY32 me32;
|
||||
|
||||
// Take a snapshot of all modules in the specified process.
|
||||
hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwPID );
|
||||
if( hModuleSnap == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
printError( TEXT("CreateToolhelp32Snapshot (of modules)") );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
me32.dwSize = sizeof( MODULEENTRY32 );
|
||||
|
||||
// Retrieve information about the first module,
|
||||
// and exit if unsuccessful
|
||||
if( !Module32First( hModuleSnap, &me32 ) )
|
||||
{
|
||||
printError( TEXT("Module32First") ); // show cause of failure
|
||||
CloseHandle( hModuleSnap ); // clean the snapshot object
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Now walk the module list of the process,
|
||||
// and display information about each module
|
||||
do
|
||||
{
|
||||
fprintf(log, TEXT("\n\n MODULE NAME: %s"), me32.szModule );
|
||||
fprintf(log, TEXT("\n Executable = %s"), me32.szExePath );
|
||||
fprintf(log, "\n Process ID = 0x%08X", me32.th32ProcessID );
|
||||
fprintf(log, "\n Ref count (g) = 0x%04X", me32.GlblcntUsage );
|
||||
fprintf(log, "\n Ref count (p) = 0x%04X", me32.ProccntUsage );
|
||||
fprintf(log, "\n Base address = 0x%08X", (DWORD) me32.modBaseAddr );
|
||||
fprintf(log, "\n Base size = %d", me32.modBaseSize );
|
||||
|
||||
} while( Module32Next( hModuleSnap, &me32 ) );
|
||||
|
||||
CloseHandle( hModuleSnap );
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
BOOL ListProcessThreads( DWORD dwOwnerPID )
|
||||
{
|
||||
HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
|
||||
THREADENTRY32 te32;
|
||||
|
||||
// Take a snapshot of all running threads
|
||||
hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
|
||||
if( hThreadSnap == INVALID_HANDLE_VALUE )
|
||||
return( FALSE );
|
||||
|
||||
// Fill in the size of the structure before using it.
|
||||
te32.dwSize = sizeof(THREADENTRY32);
|
||||
|
||||
// Retrieve information about the first thread,
|
||||
// and exit if unsuccessful
|
||||
if( !Thread32First( hThreadSnap, &te32 ) )
|
||||
{
|
||||
printError( TEXT("Thread32First") ); // show cause of failure
|
||||
CloseHandle( hThreadSnap ); // clean the snapshot object
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Now walk the thread list of the system,
|
||||
// and display information about each thread
|
||||
// associated with the specified process
|
||||
do
|
||||
{
|
||||
if( te32.th32OwnerProcessID == dwOwnerPID )
|
||||
{
|
||||
fprintf(log, "\n\n THREAD ID = 0x%08X", te32.th32ThreadID );
|
||||
fprintf(log, "\n Base priority = %d", te32.tpBasePri );
|
||||
fprintf(log, "\n Delta priority = %d", te32.tpDeltaPri );
|
||||
}
|
||||
} while( Thread32Next(hThreadSnap, &te32 ) );
|
||||
|
||||
CloseHandle( hThreadSnap );
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
void printError( TCHAR* msg )
|
||||
{
|
||||
DWORD eNum;
|
||||
TCHAR sysMsg[256];
|
||||
TCHAR* p;
|
||||
|
||||
eNum = GetLastError( );
|
||||
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, eNum,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
||||
sysMsg, 256, NULL );
|
||||
|
||||
// Trim the end of the line and terminate it with a null
|
||||
p = sysMsg;
|
||||
while( ( *p > 31 ) || ( *p == 9 ) )
|
||||
++p;
|
||||
do { *p-- = 0; } while( ( p >= sysMsg ) &&
|
||||
( ( *p == '.' ) || ( *p < 33 ) ) );
|
||||
|
||||
// Display the message
|
||||
fprintf(log, TEXT("\n WARNING: %s failed with error %d (%s)"), msg, eNum, sysMsg );
|
||||
}
|
||||
*/
|
||||
|
||||
#endif // __PROCESS_H__
|
||||
95
cpp/wiiscan/src/reg.h
Normal file
95
cpp/wiiscan/src/reg.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#ifndef __REGISTRY_H__
|
||||
#define __REGISTRY_H__
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WINDOWS
|
||||
|
||||
namespace Registry{
|
||||
void* StringtoRoot(const string& t)
|
||||
{
|
||||
if (t=="HKEY_CLASSES_ROOT") return HKEY_CLASSES_ROOT;
|
||||
else if (t=="HKEY_CURRENT_USER") return HKEY_CURRENT_USER;
|
||||
else if (t=="HKEY_LOCAL_MACHINE") return HKEY_LOCAL_MACHINE;
|
||||
else if (t=="HKEY_USERS") return HKEY_USERS;
|
||||
else {throw_("bad root path in registry"); return 0;}
|
||||
}
|
||||
|
||||
pair<void*,pair<string,string> > GetPath(const string& fullpath)
|
||||
{
|
||||
const int n=fullpath.find_first_of('\\');
|
||||
if (n==string::npos) throw_("mallformated registry entry");
|
||||
const string t=fullpath.substr(0,n);
|
||||
void* root=StringtoRoot(t);
|
||||
|
||||
const string r=fullpath.substr(n+1,-1);
|
||||
const int m=r.find_last_of('\\');
|
||||
if (m==string::npos) throw_("mallformated registry entry");
|
||||
|
||||
const string path=r.substr(0,m);
|
||||
const string key =r.substr(m+1,-1);
|
||||
|
||||
return make_pair(root,make_pair(path,key));
|
||||
}
|
||||
|
||||
bool hasKey(void* root,const string& path,const string& key,string* val=0)
|
||||
{
|
||||
assert( sizeof(void*)==sizeof(HKEY) && root!=0 );
|
||||
if (root!=HKEY_CLASSES_ROOT && root!=HKEY_CURRENT_USER && root!=HKEY_LOCAL_MACHINE && root!=HKEY_USERS) throw_("unknown root path in registry");
|
||||
|
||||
DWORD buffersize=1024*16;
|
||||
char buff[1024*16];
|
||||
buff[0]=0;
|
||||
|
||||
HKEY hKey;
|
||||
if (ERROR_SUCCESS!=RegOpenKeyEx(static_cast<HKEY>(root),path.c_str(),NULL,KEY_READ,&hKey)) return false;
|
||||
if (ERROR_SUCCESS!=RegQueryValueEx(hKey,key.c_str(),NULL,NULL,(LPBYTE)buff,&buffersize)) return false;
|
||||
if (ERROR_SUCCESS!=RegCloseKey(hKey)) return false;
|
||||
|
||||
if (val!=0) *val=buff;
|
||||
return true;
|
||||
}
|
||||
|
||||
string GetKey(void* root,const string& path,const string& key)
|
||||
{
|
||||
string val;
|
||||
if (!hasKey(root,path,key,&val)) throw_("could not read registry entry");
|
||||
return val;
|
||||
}
|
||||
|
||||
string GetKey(const string& fullpath)
|
||||
{
|
||||
const pair<void*,pair<string,string> > p=GetPath(fullpath);
|
||||
return GetKey(p.first,p.second.first,p.second.second);
|
||||
}
|
||||
|
||||
bool SetKey(void* root,const string& path,const string& key,const string& val)
|
||||
{
|
||||
assert( sizeof(void*)==sizeof(HKEY) && root!=0 );
|
||||
if (root!=HKEY_CLASSES_ROOT && root!=HKEY_CURRENT_USER && root!=HKEY_LOCAL_MACHINE && root!=HKEY_USERS) throw_("unknown root path in registry");
|
||||
if (val.size()+1>1024*16) throw_("lenght of value to long");
|
||||
|
||||
char buff[1024*16];
|
||||
size_t i;
|
||||
for(i=0;i<val.size();++i) buff[i]=val[i];
|
||||
buff[i]=0;
|
||||
const DWORD buffersize=i;
|
||||
|
||||
HKEY hKey;
|
||||
if (ERROR_SUCCESS!=RegCreateKeyEx(static_cast<HKEY>(root),path.c_str(),0,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,NULL)) return false;
|
||||
if (ERROR_SUCCESS!=RegSetValueEx(hKey,key.c_str(),NULL,REG_SZ,(LPBYTE)buff,buffersize)) return false;
|
||||
if (ERROR_SUCCESS!=RegCloseKey(hKey)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetKey(const string& fullpath,const string& val)
|
||||
{
|
||||
const pair<void*,pair<string,string> > p=GetPath(fullpath);
|
||||
return SetKey(p.first,p.second.first,p.second.second,val);
|
||||
}
|
||||
|
||||
}; // namespace Registry
|
||||
|
||||
#endif // _WINDOWS
|
||||
#endif // WIN32
|
||||
#endif // __REGISTRY_H__
|
||||
284
cpp/wiiscan/src/stringfun.h
Normal file
284
cpp/wiiscan/src/stringfun.h
Normal file
@@ -0,0 +1,284 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __STRINGFUN_H__
|
||||
#define __STRINGFUN_H__
|
||||
|
||||
struct outputoperator_tags
|
||||
{
|
||||
string preline,endline;
|
||||
int prewidth,postwidth,precision;
|
||||
bool maptags,printnumbers,serialize;
|
||||
|
||||
outputoperator_tags()
|
||||
: endline("\n"), prewidth(-1), postwidth(-1), precision(-1), maptags(false), printnumbers(false), serialize(false) {}
|
||||
};
|
||||
|
||||
static outputoperator_tags g_tags;
|
||||
|
||||
inline ostream& operator<<(ostream& os,const outputoperator_tags& x){
|
||||
g_tags=x;
|
||||
if (g_tags.precision>0) os.precision(g_tags.precision);
|
||||
return os;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline string tostring(const T& x)
|
||||
{
|
||||
ostringstream os;
|
||||
outputoperator_tags t1=g_tags;
|
||||
g_tags=outputoperator_tags();
|
||||
g_tags.serialize=true;
|
||||
g_tags.endline="";
|
||||
os << x;
|
||||
g_tags=t1;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T totype(const string& s)
|
||||
{
|
||||
istringstream is(s);
|
||||
T x;
|
||||
is >> x;
|
||||
return x;
|
||||
}
|
||||
|
||||
inline string operator+ (const string& s,const char* c) {return s+string(c);}
|
||||
inline string operator+ (const string& s,const short& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const unsigned short& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const int& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const long& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const unsigned long& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const float& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const double& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const long double& c) {return s+tostring(c);}
|
||||
inline string operator+ (const char* a ,const string& b) {return string(a)+b;}
|
||||
|
||||
#ifdef OS_Linux
|
||||
#ifdef __GCC_V4__
|
||||
// does not work under some compilers where size_t==unsigned int
|
||||
inline string operator+ (const string& s,const size_t& c) {return s+tostring(c);}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inline string tostring(const int argc,char** argv)
|
||||
{
|
||||
string s;
|
||||
for(int i=0;i<argc;++i) s += string(argv[i]) + " ";
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline string fwidth2(const T& x,const size_t wdt,const bool prefix)
|
||||
{
|
||||
string s=tostring(x);
|
||||
if(wdt>1024 || s.size()>=wdt) return s;
|
||||
size_t n=wdt-s.size();
|
||||
while(n>0) {
|
||||
if (prefix) s=' '+ s;
|
||||
else s+=' ';
|
||||
--n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline string fwidth(const T& x,const size_t wdt=8,const size_t tailwdt=4)
|
||||
{
|
||||
string s=tostring(x);
|
||||
if(wdt>1024 || tailwdt>1024 || s.size()>wdt+tailwdt) return s;
|
||||
|
||||
const size_t m=min(s.find('.'),s.find(' '));
|
||||
if (m==string::npos) {
|
||||
s=fwidth2(s,wdt,true);
|
||||
return fwidth2(s,wdt+tailwdt,false);
|
||||
}
|
||||
else{
|
||||
if(wdt<m) {
|
||||
return s;
|
||||
}
|
||||
assert( wdt>=m );
|
||||
size_t n1=wdt-m;
|
||||
while(n1>0) {s= ' ' + s; --n1;}
|
||||
return fwidth2(s,wdt+tailwdt,false);
|
||||
}
|
||||
}
|
||||
|
||||
inline string strip(const string& s,const char ch=' ')
|
||||
{
|
||||
const size_t n=s.find_first_not_of(ch);
|
||||
const size_t m=s.find_last_not_of (ch);
|
||||
|
||||
if (n==string::npos || m==string::npos) return "";
|
||||
return s.substr(n,m-n+1);
|
||||
}
|
||||
|
||||
inline string replace(const string& s,const string& f,const string& r)
|
||||
{
|
||||
if (f.size()==0) return s;
|
||||
const size_t n=s.find(f);
|
||||
if (n==string::npos) return s;
|
||||
else return replace(s.substr(0,n) + r + s.substr(n+f.size()),f,r);
|
||||
}
|
||||
|
||||
inline string indent(const string& s,const string& indent)
|
||||
{
|
||||
string t,q=s;
|
||||
while(q.size()){
|
||||
const string::size_type n=q.find_first_of("\n");
|
||||
t += indent + q.substr(0,n) + "\n";
|
||||
if (n==string::npos) break;
|
||||
assert(n+1<=q.size());
|
||||
q = q.substr(n+1,q.size());
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
inline string removerems(const string& s,const string rem)
|
||||
{
|
||||
const size_t n=s.find_first_of(rem);
|
||||
return s.substr(0,n);
|
||||
}
|
||||
|
||||
inline string suffix(const int n)
|
||||
{
|
||||
assert(n>=0 && n<999);
|
||||
if (n<=9) return "00" + tostring(n);
|
||||
else if (n<=99) return "0" + tostring(n);
|
||||
else return tostring(n);
|
||||
}
|
||||
|
||||
string tail(const string& s,const string& delimiter)
|
||||
{
|
||||
const size_t n=s.find_last_of(delimiter);
|
||||
if (n==string::npos) return s;
|
||||
else return s.substr(n+delimiter.size(),-1);
|
||||
}
|
||||
|
||||
string tail(const string& s,const char c) {
|
||||
string t;
|
||||
t.resize(1);
|
||||
t[0]=c;
|
||||
return tail(s,t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ostream& operator<<(ostream& os,const pair<T*,int> x)
|
||||
{
|
||||
for(int i=0;i<x.second;++i) os << x.first[i] << " ";
|
||||
return os;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline istream& operator>>(istream& is,pair<T*,int> x)
|
||||
{
|
||||
for(int i=0;i<x.second;++i) is >> x.first[i];
|
||||
return is;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ostream& operator<<(ostream& s,const vector<T>& x)
|
||||
{
|
||||
int i=0;
|
||||
if (g_tags.serialize) s << "vector: " << x.size() << " { ";
|
||||
for(typename vector<T>::const_iterator itt=x.begin();itt!=x.end();++itt) {
|
||||
s << g_tags.preline;
|
||||
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
|
||||
s << *itt << " " << g_tags.endline;
|
||||
}
|
||||
if (g_tags.serialize) s << "} ";
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline istream& operator>>(istream& s,vector<T>& x)
|
||||
{
|
||||
size_t n=0;
|
||||
string t;
|
||||
s >> t;
|
||||
if (t!="vector:") throw_("bad format in vector serialization stream, tag missing");
|
||||
s >> n >> t;
|
||||
if (t!="{") throw_("bad format in vector serialization stream, missing begin brace");
|
||||
x.resize(n);
|
||||
for(size_t i=0;i<n;++i) s >> x[i];
|
||||
s >> t;
|
||||
if (t!="}") throw_("bad format in vector serialization stream, missing end brace");
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ostream& operator<<(ostream& s,const list<T>& x)
|
||||
{
|
||||
if (g_tags.serialize) s << "list: " << x.size() << " { ";
|
||||
int i=0;
|
||||
for(typename list<T>::const_iterator itt=x.begin();itt!=x.end();++itt){
|
||||
s << g_tags.preline;
|
||||
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
|
||||
s << *itt << " " << g_tags.endline;
|
||||
}
|
||||
if (g_tags.serialize) s << "} ";
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline istream& operator>>(istream& s,list<T>& x)
|
||||
{
|
||||
size_t n=0;
|
||||
string t;
|
||||
s >> t;
|
||||
if (t!="list:") throw_("bad format in list serialization stream, tag missing");
|
||||
s >> n >> t;
|
||||
if (t!="{") throw_("bad format in list serialization stream, missing begin brace");
|
||||
for(size_t i=0;i<n;++i) {
|
||||
T y;
|
||||
s >> y;
|
||||
x.push_back(y);
|
||||
}
|
||||
s >> t;
|
||||
if (t!="}") throw_("bad format in list serialization stream, missing end brace");
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T,typename R>
|
||||
inline ostream& operator<<(ostream& s,const map<T,R>& x)
|
||||
{
|
||||
if (g_tags.serialize) s << "map: " << x.size() << " { ";
|
||||
int i=0;
|
||||
for(typename map<T,R>::const_iterator itt=x.begin();itt!=x.end();++itt) {
|
||||
s << g_tags.preline;
|
||||
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
|
||||
s << fwidth(itt->first,g_tags.prewidth,g_tags.postwidth) << (g_tags.maptags ? " |-> " : " ");
|
||||
s << fwidth(itt->second,g_tags.prewidth,g_tags.postwidth) << " " << g_tags.endline;
|
||||
}
|
||||
if (g_tags.serialize) s << "} ";
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T,typename R>
|
||||
inline istream& operator>>(istream& s,map<T,R>& x)
|
||||
{
|
||||
size_t n=0;
|
||||
string t;
|
||||
s >> t;
|
||||
if (t!="map:") throw_("bad format in map serialization stream, tag missing");
|
||||
s >> n >> t;
|
||||
if (t!="{") throw_("bad format in map serialization stream, missing begin brace");
|
||||
for(size_t i=0;i<n;++i) {
|
||||
T y;
|
||||
R z;
|
||||
s >> y >> z;
|
||||
if (x.find(y)!=x.end()) throw_("bad stream, key value no unique");
|
||||
x[y]=z;
|
||||
}
|
||||
s >> t;
|
||||
if (t!="}") throw_("bad format in map serialization stream, missing end brace");
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // __STRINGFUNS_H__
|
||||
54
cpp/wiiscan/src/templatefun.h
Normal file
54
cpp/wiiscan/src/templatefun.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef __TEMPLATE_FUN__
|
||||
#define __TEMPLATE_FUN__
|
||||
|
||||
#define __stdcall
|
||||
|
||||
template<class T>
|
||||
class Autobool
|
||||
{
|
||||
private:
|
||||
volatile T* m_b;
|
||||
Autobool(const Autobool&);
|
||||
void operator=(const Autobool&);
|
||||
public:
|
||||
Autobool(volatile T* b) : m_b(b) {assert(m_b && *m_b==false); *m_b=true;}
|
||||
~Autobool() {assert(m_b && *m_b==true); *m_b=false; m_b=0;}
|
||||
};
|
||||
|
||||
template<class T,class R>
|
||||
class DeviceAutoClose
|
||||
{
|
||||
private:
|
||||
T m_dev;
|
||||
R (__stdcall *m_fun)(void *);
|
||||
bool m_init;
|
||||
|
||||
// private Copy CTOR and assignment operator
|
||||
DeviceAutoClose(const DeviceAutoClose<T,R>&);
|
||||
void operator=(const DeviceAutoClose<T,R>&);
|
||||
|
||||
public:
|
||||
DeviceAutoClose(T dev,R(__stdcall *fun)(void*)) : m_dev(dev), m_fun(fun), m_init(true)
|
||||
{
|
||||
FUNSTACK;
|
||||
assert(m_fun!=NULL);
|
||||
}
|
||||
~DeviceAutoClose()
|
||||
{
|
||||
FUNSTACK;
|
||||
assert(m_init);
|
||||
assert(m_fun!=NULL);
|
||||
if (m_dev!=NULL){
|
||||
R r=m_fun(m_dev);
|
||||
if (!r) throw_("DeviceClose() failed"); // throw in DTOR -> bad, bad!
|
||||
}
|
||||
m_dev=NULL;
|
||||
m_fun=NULL;
|
||||
m_init=false;
|
||||
}
|
||||
const T& operator()() const {FUNSTACK; assert(m_init); return m_dev;}
|
||||
T& operator()() {FUNSTACK; assert(m_init); return m_dev;}
|
||||
};
|
||||
|
||||
|
||||
#endif // __TEMPLATE_FUN__
|
||||
34
cpp/wiiscan/src/toolsfun.h
Normal file
34
cpp/wiiscan/src/toolsfun.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __TOOLSFUN_H__
|
||||
#define __TOOLSFUN__H__
|
||||
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "exception.h"
|
||||
#include "stringfun.h"
|
||||
#include "args.h"
|
||||
#include "funs.h"
|
||||
#include "file.h"
|
||||
#include "configfile.h"
|
||||
#include "templatefun.h"
|
||||
#include "reg.h"
|
||||
|
||||
#endif // __TOOLSFUN_H__
|
||||
204
cpp/wiiscan/src/usbm.h
Normal file
204
cpp/wiiscan/src/usbm.h
Normal file
@@ -0,0 +1,204 @@
|
||||
#ifndef __USBM_H__
|
||||
#define __USBM_H__
|
||||
|
||||
class USBio
|
||||
{
|
||||
private:
|
||||
HINSTANCE m_hDll;
|
||||
|
||||
// Discovery routine
|
||||
typedef int (__stdcall *USBm_FindDevices_type) ();
|
||||
|
||||
// Info about devices
|
||||
typedef int (__stdcall *USBm_NumberOfDevices_type) (void);
|
||||
typedef int (__stdcall *USBm_DeviceValid_type) (unsigned char);
|
||||
typedef int (__stdcall *USBm_DeviceVID_type) (unsigned char device);
|
||||
typedef int (__stdcall *USBm_DevicePID_type) (unsigned char device);
|
||||
typedef int (__stdcall *USBm_DeviceDID_type) (unsigned char device);
|
||||
typedef int (__stdcall *USBm_DeviceMfr_type) (unsigned char, char *);
|
||||
typedef int (__stdcall *USBm_DeviceProd_type) (unsigned char, char *);
|
||||
typedef int (__stdcall *USBm_DeviceSer_type) (unsigned char, char *);
|
||||
|
||||
// General U4xx functions
|
||||
typedef int (__stdcall *USBm_InitPorts_type) (unsigned char);
|
||||
typedef int (__stdcall *USBm_WriteA_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_WriteB_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_WriteABit_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_WriteBBit_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_ReadA_type) (unsigned char, unsigned char *);
|
||||
typedef int (__stdcall *USBm_ReadB_type) (unsigned char, unsigned char *);
|
||||
typedef int (__stdcall *USBm_SetBit_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_ResetBit_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_DirectionA_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_DirectionB_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeWrite_type) (unsigned char, unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeRead_type) (unsigned char, unsigned char *, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeWrite2_type) (unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeRead2_type) (unsigned char, unsigned char *, unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeWrites_type) (unsigned char, unsigned char *, unsigned char *);
|
||||
typedef int (__stdcall *USBm_StrobeReads_type) (unsigned char, unsigned char *, unsigned char *);
|
||||
typedef int (__stdcall *USBm_InitLCD_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_LCDCmd_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_LCDData_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_InitSPI_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_SPIMaster_type) (unsigned char, unsigned char *, unsigned char *);
|
||||
typedef int (__stdcall *USBm_SPISlaveWrite_type) (unsigned char, unsigned char, unsigned char *);
|
||||
typedef int (__stdcall *USBm_SPISlaveRead_type) (unsigned char, unsigned char *, unsigned char *);
|
||||
typedef int (__stdcall *USBm_Stepper_type) (unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_Reset1Wire_type) (unsigned char, unsigned char *);
|
||||
typedef int (__stdcall *USBm_Write1Wire_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_Read1Wire_type) (unsigned char, unsigned char *);
|
||||
|
||||
// DLL string info access
|
||||
typedef int (__stdcall *USBm_RecentError_type) (char *);
|
||||
typedef int (__stdcall *USBm_ClearRecentError_type) (void);
|
||||
typedef int (__stdcall *USBm_DebugString_type) (char *);
|
||||
typedef int (__stdcall *USBm_Copyright_type) (char *);
|
||||
typedef int (__stdcall *USBm_About_type) (char *);
|
||||
typedef int (__stdcall *USBm_Version_type) (char *);
|
||||
|
||||
public:
|
||||
USBio() : m_hDll(0)
|
||||
{
|
||||
m_hDll = LoadLibrary("USBm.dll");
|
||||
if (m_hDll==0) throw_("could not locate USBm.dll");
|
||||
|
||||
USBm_FindDevices = (USBm_FindDevices_type)GetProcAddress(m_hDll, "USBm_FindDevices");
|
||||
USBm_NumberOfDevices = (USBm_NumberOfDevices_type)GetProcAddress(m_hDll, "USBm_NumberOfDevices");
|
||||
USBm_DeviceValid = (USBm_DeviceValid_type)GetProcAddress(m_hDll, "USBm_DeviceValid");
|
||||
USBm_DeviceVID = (USBm_DeviceVID_type)GetProcAddress(m_hDll, "USBm_DeviceVID");
|
||||
USBm_DevicePID = (USBm_DevicePID_type)GetProcAddress(m_hDll, "USBm_DevicePID");
|
||||
USBm_DeviceDID = (USBm_DeviceDID_type)GetProcAddress(m_hDll, "USBm_DeviceDID");
|
||||
USBm_DeviceMfr = (USBm_DeviceMfr_type)GetProcAddress(m_hDll, "USBm_DeviceMfr");
|
||||
USBm_DeviceProd = (USBm_DeviceProd_type)GetProcAddress(m_hDll, "USBm_DeviceProd");
|
||||
USBm_DeviceSer = (USBm_DeviceSer_type)GetProcAddress(m_hDll, "USBm_DeviceSer");
|
||||
USBm_InitPorts = (USBm_InitPorts_type)GetProcAddress(m_hDll, "USBm_InitPorts");
|
||||
USBm_WriteA = (USBm_WriteA_type)GetProcAddress(m_hDll, "USBm_WriteA");
|
||||
USBm_WriteB = (USBm_WriteB_type)GetProcAddress(m_hDll, "USBm_WriteB");
|
||||
USBm_WriteABit = (USBm_WriteABit_type)GetProcAddress(m_hDll, "USBm_WriteABit");
|
||||
USBm_WriteBBit = (USBm_WriteBBit_type)GetProcAddress(m_hDll, "USBm_WriteBBit");
|
||||
USBm_ReadA = (USBm_ReadA_type)GetProcAddress(m_hDll, "USBm_ReadA");
|
||||
USBm_ReadB = (USBm_ReadB_type)GetProcAddress(m_hDll, "USBm_ReadB");
|
||||
USBm_SetBit = (USBm_SetBit_type)GetProcAddress(m_hDll, "USBm_SetBit");
|
||||
USBm_ResetBit = (USBm_ResetBit_type)GetProcAddress(m_hDll, "USBm_ResetBit");
|
||||
USBm_DirectionA = (USBm_DirectionA_type)GetProcAddress(m_hDll, "USBm_DirectionA");
|
||||
USBm_DirectionB = (USBm_DirectionB_type)GetProcAddress(m_hDll, "USBm_DirectionB");
|
||||
USBm_StrobeWrite = (USBm_StrobeWrite_type)GetProcAddress(m_hDll, "USBm_StrobeWrite");
|
||||
USBm_StrobeRead = (USBm_StrobeRead_type)GetProcAddress(m_hDll, "USBm_StrobeRead");
|
||||
USBm_StrobeWrite2 = (USBm_StrobeWrite2_type)GetProcAddress(m_hDll, "USBm_StrobeWrite2");
|
||||
USBm_StrobeRead2 = (USBm_StrobeRead2_type)GetProcAddress(m_hDll, "USBm_StrobeRead2");
|
||||
USBm_StrobeWrites = (USBm_StrobeWrites_type)GetProcAddress(m_hDll, "USBm_StrobeWrites");
|
||||
USBm_StrobeReads = (USBm_StrobeReads_type)GetProcAddress(m_hDll, "USBm_StrobeReads");
|
||||
USBm_InitLCD = (USBm_InitLCD_type)GetProcAddress(m_hDll, "USBm_InitLCD");
|
||||
USBm_LCDCmd = (USBm_LCDCmd_type)GetProcAddress(m_hDll, "USBm_LCDCmd");
|
||||
USBm_LCDData = (USBm_LCDData_type)GetProcAddress(m_hDll, "USBm_LCDData");
|
||||
USBm_InitSPI = (USBm_InitSPI_type)GetProcAddress(m_hDll, "USBm_InitSPI");
|
||||
USBm_SPIMaster = (USBm_SPIMaster_type)GetProcAddress(m_hDll, "USBm_SPIMaster");
|
||||
USBm_SPISlaveWrite = (USBm_SPISlaveWrite_type)GetProcAddress(m_hDll, "USBm_SPISlaveWrite");
|
||||
USBm_SPISlaveRead = (USBm_SPISlaveRead_type)GetProcAddress(m_hDll, "USBm_SPISlaveRead");
|
||||
USBm_Stepper = (USBm_Stepper_type)GetProcAddress(m_hDll, "USBm_Stepper");
|
||||
USBm_Reset1Wire = (USBm_Reset1Wire_type)GetProcAddress(m_hDll, "USBm_Reset1Wire");
|
||||
USBm_Write1Wire = (USBm_Write1Wire_type)GetProcAddress(m_hDll, "USBm_Write1Wire");
|
||||
USBm_Read1Wire = (USBm_Read1Wire_type)GetProcAddress(m_hDll, "USBm_Read1Wire");
|
||||
USBm_RecentError = (USBm_RecentError_type)GetProcAddress(m_hDll, "USBm_RecentError");
|
||||
USBm_ClearRecentError = (USBm_ClearRecentError_type)GetProcAddress(m_hDll, "USBm_ClearRecentError");
|
||||
USBm_DebugString = (USBm_DebugString_type)GetProcAddress(m_hDll, "USBm_DebugString");
|
||||
USBm_Copyright = (USBm_Copyright_type)GetProcAddress(m_hDll, "USBm_Copyright");
|
||||
USBm_About = (USBm_About_type)GetProcAddress(m_hDll, "USBm_About");
|
||||
USBm_Version = (USBm_Version_type)GetProcAddress(m_hDll, "USBm_Version");
|
||||
}
|
||||
|
||||
~USBio()
|
||||
{
|
||||
assert( m_hDll );
|
||||
// XXX FreeLibrary(m_hDll);
|
||||
m_hDll=0;
|
||||
}
|
||||
|
||||
int Devices() const
|
||||
{
|
||||
assert( m_hDll );
|
||||
unsigned char numdev=USBm_NumberOfDevices();
|
||||
return numdev;
|
||||
}
|
||||
|
||||
string version() const
|
||||
{
|
||||
assert( m_hDll );
|
||||
|
||||
string s;
|
||||
char textstr[300];
|
||||
const int d=Devices();
|
||||
|
||||
s = string(" USBm.dll version = ") + USBm_Version(textstr) + "\n";
|
||||
s += string(" USBm.dll version = ") + textstr + "\n";
|
||||
|
||||
USBm_Copyright(textstr);
|
||||
s += string(" Copyright = ") + textstr + "\n";
|
||||
|
||||
USBm_About(textstr);
|
||||
s += string(" About =") + textstr + "\n";
|
||||
s += string(" Number of devices = ") + d + "\n";
|
||||
|
||||
// Gather info from each discovered device
|
||||
for(int i=0;i<d;++i){
|
||||
s += string(" Device[") + i + "]:\n";
|
||||
s += string(" VID = ") + USBm_DeviceVID(i) + "\n";
|
||||
USBm_DeviceMfr(i,textstr);
|
||||
s += string(" Manuf = ") + textstr + "\n";
|
||||
s += string(" PID = ") + USBm_DevicePID(i) + "\n";
|
||||
USBm_DeviceProd(i,textstr);
|
||||
s += string(" Prod = ") + textstr + "\n";
|
||||
s += string(" DID = ") + USBm_DeviceDID(i) + "\n";
|
||||
USBm_DeviceSer(i,textstr);
|
||||
s += string(" Serial = ") + textstr + "\n";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
USBm_FindDevices_type USBm_FindDevices;
|
||||
USBm_NumberOfDevices_type USBm_NumberOfDevices;
|
||||
USBm_DeviceValid_type USBm_DeviceValid;
|
||||
USBm_DeviceVID_type USBm_DeviceVID;
|
||||
USBm_DevicePID_type USBm_DevicePID;
|
||||
USBm_DeviceDID_type USBm_DeviceDID;
|
||||
USBm_DeviceMfr_type USBm_DeviceMfr;
|
||||
USBm_DeviceProd_type USBm_DeviceProd;
|
||||
USBm_DeviceSer_type USBm_DeviceSer;
|
||||
USBm_InitPorts_type USBm_InitPorts;
|
||||
USBm_WriteA_type USBm_WriteA;
|
||||
USBm_WriteB_type USBm_WriteB;
|
||||
USBm_WriteABit_type USBm_WriteABit;
|
||||
USBm_WriteBBit_type USBm_WriteBBit;
|
||||
USBm_ReadA_type USBm_ReadA;
|
||||
USBm_ReadB_type USBm_ReadB;
|
||||
USBm_SetBit_type USBm_SetBit;
|
||||
USBm_ResetBit_type USBm_ResetBit;
|
||||
USBm_DirectionA_type USBm_DirectionA;
|
||||
USBm_DirectionB_type USBm_DirectionB;
|
||||
USBm_StrobeWrite_type USBm_StrobeWrite;
|
||||
USBm_StrobeRead_type USBm_StrobeRead;
|
||||
USBm_StrobeWrite2_type USBm_StrobeWrite2;
|
||||
USBm_StrobeRead2_type USBm_StrobeRead2;
|
||||
USBm_StrobeWrites_type USBm_StrobeWrites;
|
||||
USBm_StrobeReads_type USBm_StrobeReads;
|
||||
USBm_InitLCD_type USBm_InitLCD;
|
||||
USBm_LCDCmd_type USBm_LCDCmd;
|
||||
USBm_LCDData_type USBm_LCDData;
|
||||
USBm_InitSPI_type USBm_InitSPI;
|
||||
USBm_SPIMaster_type USBm_SPIMaster;
|
||||
USBm_SPISlaveWrite_type USBm_SPISlaveWrite;
|
||||
USBm_SPISlaveRead_type USBm_SPISlaveRead;
|
||||
USBm_Stepper_type USBm_Stepper;
|
||||
USBm_Reset1Wire_type USBm_Reset1Wire;
|
||||
USBm_Write1Wire_type USBm_Write1Wire;
|
||||
USBm_Read1Wire_type USBm_Read1Wire;
|
||||
USBm_RecentError_type USBm_RecentError;
|
||||
USBm_ClearRecentError_type USBm_ClearRecentError;
|
||||
USBm_DebugString_type USBm_DebugString;
|
||||
USBm_Copyright_type USBm_Copyright;
|
||||
USBm_About_type USBm_About;
|
||||
USBm_Version_type USBm_Version;
|
||||
};
|
||||
|
||||
#endif // __USBM_H__
|
||||
27
cpp/wiiscan/src/wiiscan.cpp
Normal file
27
cpp/wiiscan/src/wiiscan.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright © 2009 MergeIt, Aps.
|
||||
//
|
||||
// License LGPLv3+: GNU lesser LGPL version 3 or later <http://gnu.org/licenses/lgpl.html>.
|
||||
// This is free software: you are free to change and redistribute it.
|
||||
// There is NO WARRANTY, to the extent permitted by law.
|
||||
//
|
||||
// This file is part of wiiscan.
|
||||
//
|
||||
// wiiscan is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// wiiscan is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with wiiscan. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "wiiscan.h"
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
return Wiiscan::main(argc,argv);
|
||||
}
|
||||
1114
cpp/wiiscan/src/wiiscan.h
Normal file
1114
cpp/wiiscan/src/wiiscan.h
Normal file
File diff suppressed because it is too large
Load Diff
1662
cpp/wiiscan/src/wiiscan.test.h
Normal file
1662
cpp/wiiscan/src/wiiscan.test.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user