PITimer important fix! ASCII-art start ...
git-svn-id: svn://db.shs.com.ru/pip@94 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
9
main.cpp
9
main.cpp
@@ -224,16 +224,13 @@ inline PICout operator <<(PICout s, const FixedPoint<Precision, Type> & v) {
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
//char uc[] = "←↑→↓АБВ";
|
||||
char uc[] = "←↑→↓АБВ";
|
||||
char uc[] = "│─┌┐└┘├┤┬┴┼";
|
||||
|
||||
PIString us(uc);
|
||||
PIString us = PIString::fromUTF8(uc);
|
||||
|
||||
//piForeachC (PIChar & c, us)
|
||||
// piCout << PICoutManipulators::Hex << PIByteArray(&c, 4);
|
||||
piCout << uc;
|
||||
std::cout << uc << "\n";
|
||||
printf("%s\n", uc);
|
||||
//piCout << us.toByteArray() << us.size_s();
|
||||
piCout << us << us.toByteArray() << us.size_s();
|
||||
return 0;
|
||||
|
||||
/*FixedPoint<16, long long> a, b;
|
||||
|
||||
@@ -173,6 +173,10 @@ void PIKbdListener::readKeyboard() {
|
||||
case 40: ret = 1; ke.key = DownArrow; break;
|
||||
case 45: ret = 1; ke.key = Insert; break;
|
||||
case 46: ret = 1; ke.key = Delete; break;
|
||||
case '\r':
|
||||
case '\n': ret = 1; ke.key = Return; break;
|
||||
case ' ': ret = 1; ke.key = Space; break;
|
||||
case '\t': ret = 1; ke.key = Tab; break;
|
||||
case 112: ret = 1; ke.key = F1; break;
|
||||
case 113: ret = 1; ke.key = F2; break;
|
||||
case 114: ret = 1; ke.key = F3; break;
|
||||
@@ -185,7 +189,15 @@ void PIKbdListener::readKeyboard() {
|
||||
case 121: ret = 1; ke.key = F10; break;
|
||||
case 122: ret = 1; ke.key = F11; break;
|
||||
case 123: ret = 1; ke.key = F12; break;
|
||||
default: ret = 1; ke.key = rc[0] = (shift ? char(toupper(ker.uChar.AsciiChar)) : ker.uChar.AsciiChar); break;
|
||||
default:
|
||||
ret = 1;
|
||||
rc[0] = 1;
|
||||
{
|
||||
PIChar ch = PIChar::fromConsole(ker.uChar.AsciiChar);
|
||||
if (shift) ch = ch.toUpper();
|
||||
ke.key = ch.unicode16Code();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ke.key == 0) {piMSleep(10); return;}
|
||||
} else {piMSleep(10); return;}
|
||||
@@ -212,7 +224,7 @@ void PIKbdListener::readKeyboard() {
|
||||
cout << endl;*/
|
||||
if (rc[0] == 0) {piMSleep(10); return;}
|
||||
if (ret < 0 || ret > 7) {piMSleep(10); return;}
|
||||
if (ret == 1) ke.key = rc[0];
|
||||
if (ret == 1) ke.key = PIChar::fromConsole(rc[0]).unicode16Code();
|
||||
int mod(0);
|
||||
// 2 - shift 1
|
||||
// 3 - alt 2
|
||||
@@ -257,6 +269,8 @@ void PIKbdListener::readKeyboard() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ke.key == 0 && ret > 1)
|
||||
ke.key = PIChar(rc).unicode16Code();
|
||||
#endif
|
||||
if ((rc[0] == '\n' || rc[0] == '\r') && ret == 1)
|
||||
ke.key = Return;
|
||||
|
||||
@@ -88,6 +88,7 @@ TileList::TileList(const PIString & n): PIScreenTile(n) {
|
||||
focus_flags = CanHasFocus | NextByArrowsHorizontal | NextByTab;
|
||||
lhei = offset = cur = 0;
|
||||
selection_mode = NoSelection;
|
||||
vert_line = PIChar::fromUTF8("│");
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +128,7 @@ void TileList::drawEvent(PIScreenDrawer * d) {
|
||||
d->drawText(rx, y + i - is + 1, r.first, cc, sel ? Blue : Default, cf);
|
||||
}
|
||||
int cx = x + width - 1;
|
||||
d->drawLine(cx, y + 1, cx, y + height - 2, '|', Green);
|
||||
d->drawLine(cx, y + 1, cx, y + height - 2, vert_line, Green);
|
||||
if (content.size_s() > 1)
|
||||
d->drawPixel(cx, y + piRound(float(cur) / (content.size_s() - 1) * (lhei - 1)) + 1, ' ', Green, Green);
|
||||
if (ie < content.size_s()) d->drawText(x, y + height - 1, PIString(" \\/ ").repeat(width / 4), Green, Default, Bold);
|
||||
|
||||
@@ -64,6 +64,7 @@ protected:
|
||||
void drawEvent(PIScreenDrawer * d);
|
||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
||||
int lhei;
|
||||
PIChar vert_line;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -36,10 +36,79 @@ char * __sysoemname__ = 0;
|
||||
|
||||
|
||||
PIChar::PIChar(const char * c) {
|
||||
#ifdef PIP_ICU
|
||||
UErrorCode e((UErrorCode)0);
|
||||
UConverter * cc = ucnv_open(__syslocname__, &e);
|
||||
if (cc) {
|
||||
UChar uc;
|
||||
e = (UErrorCode)0;
|
||||
ucnv_toUChars(cc, &uc, 1, c, 4, &e);
|
||||
ucnv_close(cc);
|
||||
ch = uc;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
ch = *reinterpret_cast<const int * >(c);
|
||||
}
|
||||
|
||||
|
||||
PIChar PIChar::fromConsole(char c) {
|
||||
PIChar ret;
|
||||
#ifdef PIP_ICU
|
||||
UErrorCode e((UErrorCode)0);
|
||||
UConverter * cc = ucnv_open(__sysoemname__, &e);
|
||||
if (cc) {
|
||||
UChar uc;
|
||||
e = (UErrorCode)0;
|
||||
ucnv_toUChars(cc, &uc, 1, &c, 1, &e);
|
||||
ucnv_close(cc);
|
||||
ret.ch = uc;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
ret.ch = c;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIChar PIChar::fromSystem(char c) {
|
||||
PIChar ret;
|
||||
#ifdef PIP_ICU
|
||||
UErrorCode e((UErrorCode)0);
|
||||
UConverter * cc = ucnv_open(__syslocname__, &e);
|
||||
if (cc) {
|
||||
UChar uc;
|
||||
e = (UErrorCode)0;
|
||||
ucnv_toUChars(cc, &uc, 1, &c, 1, &e);
|
||||
ucnv_close(cc);
|
||||
ret.ch = uc;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
ret.ch = c;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIChar PIChar::fromUTF8(const char * c) {
|
||||
PIChar ret;
|
||||
#ifdef PIP_ICU
|
||||
UErrorCode e((UErrorCode)0);
|
||||
UConverter * cc = ucnv_open("UTF-8", &e);
|
||||
if (cc) {
|
||||
UChar uc;
|
||||
e = (UErrorCode)0;
|
||||
ucnv_toUChars(cc, &uc, 1, c, 8, &e);
|
||||
ucnv_close(cc);
|
||||
ret.ch = uc;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
ret.ch = *(ushort*)c;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool PIChar::operator ==(const PIChar & o) const {
|
||||
return strcmp(o.toCharPtr(), toCharPtr()) == 0;
|
||||
}
|
||||
|
||||
@@ -146,6 +146,10 @@ public:
|
||||
|
||||
//! Return symbol in lower case
|
||||
PIChar toLower() const;
|
||||
|
||||
static PIChar fromConsole(char c);
|
||||
static PIChar fromSystem(char c);
|
||||
static PIChar fromUTF8(const char * c);
|
||||
|
||||
private:
|
||||
ushort ch;
|
||||
|
||||
@@ -129,17 +129,18 @@ PIInit::PIInit() {
|
||||
# endif
|
||||
#endif
|
||||
#ifdef PIP_ICU
|
||||
__syslocname__ = new char[256];
|
||||
memset(__syslocname__, 0, 256);
|
||||
__syslocname__ = __sysoemname__ = 0;
|
||||
//__syslocname__ = new char[256];
|
||||
//memset(__syslocname__, 0, 256);
|
||||
# ifdef WINDOWS
|
||||
CPINFOEX cpinfo;
|
||||
GetCPInfoEx(CP_ACP, 0, &cpinfo);
|
||||
int l = 0;
|
||||
/*GetCPInfoEx(CP_ACP, 0, &cpinfo);
|
||||
for (l = 0; l < MAX_PATH; ++l)
|
||||
if (cpinfo.CodePageName[l] == '\0' || cpinfo.CodePageName[l] == ' ')
|
||||
break;
|
||||
memcpy(__syslocname__, "windows-", 8);
|
||||
memcpy(&(__syslocname__[8]), cpinfo.CodePageName, l);
|
||||
memcpy(&(__syslocname__[8]), cpinfo.CodePageName, l);*/
|
||||
GetCPInfoEx(CP_OEMCP, 0, &cpinfo);
|
||||
for (l = 0; l < MAX_PATH; ++l)
|
||||
if (cpinfo.CodePageName[l] == '\0' || cpinfo.CodePageName[l] == ' ')
|
||||
@@ -150,14 +151,14 @@ PIInit::PIInit() {
|
||||
memcpy(&(__sysoemname__[4]), cpinfo.CodePageName, l);
|
||||
//piCout << cpinfo.CodePageName;
|
||||
# else
|
||||
PIString en(getenv("LANG"));
|
||||
/*PIString en(getenv("LANG"));
|
||||
if (!en.isEmpty())
|
||||
en = en.mid(en.find(".") + 1);
|
||||
PIByteArray enba = en.toByteArray();
|
||||
memcpy(__syslocname__, enba.data(), enba.size_s());
|
||||
memcpy(__syslocname__, enba.data(), enba.size_s());*/
|
||||
# endif
|
||||
piCout << __syslocname__;
|
||||
piCout << __sysoemname__;
|
||||
//piCout << __syslocname__;
|
||||
//piCout << __sysoemname__;
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock);
|
||||
|
||||
@@ -97,11 +97,11 @@ PIString PIString::dtos(const double num) {pisprintf("%.8f", num); return PIStri
|
||||
#undef pisprintf
|
||||
|
||||
|
||||
void PIString::appendFromChars(const char * c, int s) {
|
||||
void PIString::appendFromChars(const char * c, int s, const char * cp) {
|
||||
if (s <= 0) return;
|
||||
#ifdef PIP_ICU
|
||||
UErrorCode e((UErrorCode)0);
|
||||
UConverter * cc = ucnv_open(__syslocname__, &e);
|
||||
UConverter * cc = ucnv_open(cp, &e);
|
||||
if (cc) {
|
||||
UChar * ucs = new UChar[s];
|
||||
memset(ucs, 0, s * sizeof(UChar));
|
||||
@@ -146,11 +146,47 @@ void PIString::appendFromChars(const char * c, int s) {
|
||||
}
|
||||
|
||||
|
||||
void PIString::buildData() const {
|
||||
PIString PIString::fromConsole(const char * s) {
|
||||
int l = 0;
|
||||
while (s[l] != '\0') ++l;
|
||||
PIString ret;
|
||||
if (l > 0) ret.appendFromChars(s, l
|
||||
#ifdef PIP_ICU
|
||||
, __sysoemname__
|
||||
#endif
|
||||
);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromSystem(const char * s) {
|
||||
int l = 0;
|
||||
while (s[l] != '\0') ++l;
|
||||
PIString ret;
|
||||
if (l > 0) ret.appendFromChars(s, l);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromUTF8(const char * s) {
|
||||
int l = 0;
|
||||
while (s[l] != '\0') ++l;
|
||||
PIString ret;
|
||||
if (l > 0) ret.appendFromChars(s, l
|
||||
#ifdef PIP_ICU
|
||||
, "UTF-8"
|
||||
#endif
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIString::buildData(const char * cp) const {
|
||||
data_.clear();
|
||||
#ifdef PIP_ICU
|
||||
UErrorCode e((UErrorCode)0);
|
||||
UConverter * cc = ucnv_open(__syslocname__, &e);
|
||||
UConverter * cc = ucnv_open(cp, &e);
|
||||
if (cc) {
|
||||
int rs = 0;//, ol = UCNV_GET_MAX_BYTES_FOR_STRING(size_s(), ucnv_getMaxCharSize(cc));
|
||||
char uc[8];
|
||||
@@ -195,6 +231,26 @@ void PIString::buildData() const {
|
||||
}
|
||||
|
||||
|
||||
const char * PIString::dataConsole() const {
|
||||
buildData(
|
||||
#ifdef PIP_ICU
|
||||
__sysoemname__
|
||||
#endif
|
||||
);
|
||||
return (const char *)(data_.data());
|
||||
}
|
||||
|
||||
|
||||
const char * PIString::dataUTF8() const {
|
||||
buildData(
|
||||
#ifdef PIP_ICU
|
||||
"UTF-8"
|
||||
#endif
|
||||
);
|
||||
return (const char *)(data_.data());
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::operator +=(const char * str) {
|
||||
int l = 0;
|
||||
while (str[l] != '\0') ++l;
|
||||
@@ -810,33 +866,10 @@ PICout operator <<(PICout s, const PIString & v) {
|
||||
s.space();
|
||||
s.quote();
|
||||
s.setControl(0, true);
|
||||
#ifdef PIP_ICU
|
||||
if (__sysoemname__) {
|
||||
PIByteArray oba;
|
||||
UErrorCode e((UErrorCode)0);
|
||||
UConverter * cc = ucnv_open(__sysoemname__, &e);
|
||||
if (cc) {
|
||||
int rs = 0;
|
||||
char uc[8];
|
||||
for (int i = 0; i < v.size_s(); ++i) {
|
||||
if (v[i].isAscii())
|
||||
oba.push_back(uchar(v[i].unicode16Code()));
|
||||
else {
|
||||
e = (UErrorCode)0;
|
||||
rs = ucnv_fromUChars(cc, uc, 8, (const UChar*)(((PIDeque<PIChar>*)(&v))->data(i)), 1, &e);
|
||||
//printf("conv %d\n", rs);
|
||||
for (int j = 0; j < rs; ++j)
|
||||
oba.push_back(uc[j]);
|
||||
}
|
||||
}
|
||||
ucnv_close(cc);
|
||||
oba.push_back('\0');
|
||||
s << (const char *)oba.data();
|
||||
} else
|
||||
s << v.data();
|
||||
} else
|
||||
#endif
|
||||
if (PICout::isBufferActive())
|
||||
s << v.data();
|
||||
else
|
||||
s << v.dataConsole();
|
||||
s.restoreControl();
|
||||
s.quote();
|
||||
return s;
|
||||
|
||||
@@ -458,14 +458,30 @@ public:
|
||||
* \sa \a data() */
|
||||
int lengthAscii() const {buildData(); return data_.size_s() - 1;}
|
||||
|
||||
/*! \brief Return \c char * representation of this string
|
||||
/*! \brief Return \c char * representation of this string in system codepage
|
||||
* \details This function fill buffer by sequence
|
||||
* of chars. Minimum length of this buffer is count
|
||||
* of symbols. Returned \c char * is valid until next
|
||||
* execution of this function.\n
|
||||
* Example: \snippet pistring.cpp PIString::data
|
||||
* \sa \a lengthAscii() */
|
||||
* \sa \a dataConsole(), \a dataUTF8() */
|
||||
const char * data() const {buildData(); return (const char *)(data_.data());}
|
||||
|
||||
/*! \brief Return \c char * representation of this string in terminal codepage
|
||||
* \details This function fill buffer by sequence
|
||||
* of chars. Minimum length of this buffer is count
|
||||
* of symbols. Returned \c char * is valid until next
|
||||
* execution of this function.\n
|
||||
* \sa \a data(), \a dataUTF8() */
|
||||
const char * dataConsole() const;
|
||||
|
||||
/*! \brief Return \c char * representation of this string in UTF-8
|
||||
* \details This function fill buffer by sequence
|
||||
* of chars. Minimum length of this buffer is count
|
||||
* of symbols. Returned \c char * is valid until next
|
||||
* execution of this function.\n
|
||||
* \sa \a data(), \a dataConsole() */
|
||||
const char * dataUTF8() const;
|
||||
|
||||
//! \brief Return \c std::string representation of this string
|
||||
std::string stdString() const {return convertToStd();}
|
||||
@@ -692,6 +708,15 @@ public:
|
||||
//! \brief Return "true" or "false"
|
||||
static PIString fromBool(const bool value) {return PIString(value ? "true" : "false");}
|
||||
|
||||
//! \brief Return string constructed from terminal codepage
|
||||
static PIString fromConsole(const char * s);
|
||||
|
||||
//! \brief Return string constructed from system codepage
|
||||
static PIString fromSystem(const char * s);
|
||||
|
||||
//! \brief Return string constructed from UTF-8
|
||||
static PIString fromUTF8(const char * s);
|
||||
|
||||
//! \brief Return string contains human readable size in B/kB/MB/GB/TB
|
||||
//! \details Example: \snippet pistring.cpp PIString::readableSize
|
||||
static PIString readableSize(llong bytes) {PIString s; s.setReadableSize(bytes); return s;}
|
||||
@@ -779,8 +804,8 @@ private:
|
||||
}*/
|
||||
return ret;
|
||||
}
|
||||
void appendFromChars(const char * c, int s);
|
||||
void buildData() const;
|
||||
void appendFromChars(const char * c, int s, const char * cp = 0);
|
||||
void buildData(const char * cp = 0) const;
|
||||
std::string convertToStd() const;
|
||||
#ifdef HAS_LOCALE
|
||||
wstring convertToWString() const {wstring s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toWChar()); return s;}
|
||||
|
||||
@@ -251,6 +251,16 @@ bool PIFile::isExists(const PIString & path) {
|
||||
}
|
||||
|
||||
|
||||
bool PIFile::remove(const PIString & path) {
|
||||
#ifdef WINDOWS
|
||||
if (PIDir::isExists(path))
|
||||
return RemoveDirectory(path.data()) > 0;
|
||||
else
|
||||
#endif
|
||||
return ::remove(path.data()) == 0;
|
||||
}
|
||||
|
||||
|
||||
PIString PIFile::constructFullPath() const {
|
||||
return fullPathPrefix() + "://" + path();
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ public:
|
||||
static bool isExists(const PIString & path);
|
||||
|
||||
//! Remove file with path "path" and returns if remove was successful
|
||||
static bool remove(const PIString & path) {return std::remove(path.data()) == 0;}
|
||||
static bool remove(const PIString & path);
|
||||
|
||||
//! Rename file with path "from" to path "to" and returns if rename was successful
|
||||
static bool rename(const PIString & from, const PIString & to) {return ::rename(from.data(), to.data()) == 0;}
|
||||
|
||||
@@ -770,7 +770,6 @@ void PIProtocol::send() {
|
||||
//lock();
|
||||
//memcpy(packet, sendDataPtr, sendDataSize);
|
||||
//unlock();
|
||||
//cout << "**send" << endl;
|
||||
if (!aboutSend()) return;
|
||||
if (sendDataPtr == 0 || sendDataSize == 0) return;
|
||||
if (history_write_send) {
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
#define PIP_VERSION_MAJOR 0
|
||||
#define PIP_VERSION_MINOR 5
|
||||
#define PIP_VERSION_REVISION 1
|
||||
#define PIP_VERSION_SUFFIX "_alpha"
|
||||
#define PIP_VERSION_SUFFIX "_alphav[i]"
|
||||
|
||||
#endif // PIVERSION_H
|
||||
|
||||
@@ -372,18 +372,18 @@ PITimer::PITimer(PITimer::TimerImplementation ti): PIObject() {
|
||||
PITimer::PITimer(TimerEvent slot, void * data, PITimer::TimerImplementation ti): PIObject() {
|
||||
piMonitor.timers++;
|
||||
imp_mode = ti;
|
||||
initFirst();
|
||||
data_t = data;
|
||||
ret_func = slot;
|
||||
initFirst();
|
||||
}
|
||||
|
||||
|
||||
PITimer::PITimer(const PITimer & other): PIObject() {
|
||||
piMonitor.timers++;
|
||||
imp_mode = other.imp_mode;
|
||||
initFirst();
|
||||
data_t = other.data_t;
|
||||
ret_func = other.ret_func;
|
||||
initFirst();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -120,13 +120,17 @@ void showInfo(const PIString & t) {
|
||||
void removeFiles(const PIDir & dir, PIStringList l) {
|
||||
l.removeOne("..");
|
||||
PIString ap = dir.absolutePath();
|
||||
//piCout << "remove from" << ap;
|
||||
piForeachC (PIString & s, l) {
|
||||
PIFile::FileInfo fi = PIFile::fileInfo(ap + PIDir::separator + s);
|
||||
if (fi.isDir()) {
|
||||
PIVector<PIFile::FileInfo> el = PIDir::allEntries(fi.path);
|
||||
piForeachCR (PIFile::FileInfo & e, el)
|
||||
piForeachCR (PIFile::FileInfo & e, el) {
|
||||
//piCout << "remove" << e.path;
|
||||
PIFile::remove(e.path);
|
||||
}
|
||||
}
|
||||
//piCout << "remove" << fi.path;
|
||||
PIFile::remove(fi.path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user