git-svn-id: svn://db.shs.com.ru/pip@207 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
7
main.cpp
7
main.cpp
@@ -5,6 +5,7 @@
|
||||
#include "piscreen.h"
|
||||
#include "piethernet.h"
|
||||
#include "piintrospection.h"
|
||||
#include "pifile.h"
|
||||
|
||||
//struct MS {
|
||||
// //MS() {i = 0; f = 0.;}
|
||||
@@ -30,6 +31,12 @@ public:
|
||||
};
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
PIFile::setDefaultCharset("utf8");
|
||||
piCout << PIFile::defaultCharset();
|
||||
PIFile::setDefaultCharset("cp1251");
|
||||
piCout << PIFile::defaultCharset();
|
||||
return 0;
|
||||
|
||||
VC<30, double> x(1.5), y(3.3);
|
||||
double r = 0.0;
|
||||
PITimeMeasurer tm;
|
||||
|
||||
@@ -85,6 +85,7 @@ void android_thread_exit_handler(int sig) {
|
||||
PIInit::PIInit() {
|
||||
PISystemInfo * sinfo = PISystemInfo::instance();
|
||||
sinfo->execDateTime = PIDateTime::current();
|
||||
file_charset = 0;
|
||||
#ifndef ANDROID
|
||||
PISignals::setSlot(__sighandler__);
|
||||
PISignals::grabSignals(PISignals::UserDefined1);
|
||||
@@ -253,6 +254,8 @@ PIInit::PIInit() {
|
||||
|
||||
|
||||
PIInit::~PIInit() {
|
||||
if (file_charset) delete file_charset;
|
||||
file_charset = 0;
|
||||
#ifdef WINDOWS
|
||||
WSACleanup();
|
||||
//if (setTimerResolution) setTimerResolutionAddr(prev_res, TRUE, &prev_res);
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include "piincludes.h"
|
||||
|
||||
|
||||
class PIFile;
|
||||
|
||||
|
||||
class __PIInit_Initializer__ {
|
||||
public:
|
||||
__PIInit_Initializer__();
|
||||
@@ -38,6 +41,7 @@ public:
|
||||
|
||||
|
||||
class PIInit {
|
||||
friend class PIFile;
|
||||
public:
|
||||
PIInit();
|
||||
~PIInit();
|
||||
@@ -48,6 +52,7 @@ private:
|
||||
HMODULE ntlib;
|
||||
ULONG prev_res;
|
||||
#endif
|
||||
char * file_charset;
|
||||
};
|
||||
|
||||
static __PIInit_Initializer__ __piinit_initializer__;
|
||||
|
||||
@@ -40,12 +40,12 @@
|
||||
#endif
|
||||
#define S_IFHDN 0x40
|
||||
#if defined(QNX) || defined(ANDROID)
|
||||
# define _fopen_call_ fopen
|
||||
# define _fseek_call_ fseek
|
||||
# define _ftell_call_ ftell
|
||||
# define _stat_struct_ struct stat
|
||||
# define _stat_call_ stat
|
||||
# define _stat_link_ lstat
|
||||
# define _fopen_call_ fopen
|
||||
# define _fseek_call_ fseek
|
||||
# define _ftell_call_ ftell
|
||||
# define _stat_struct_ struct stat
|
||||
# define _stat_call_ stat
|
||||
# define _stat_link_ lstat
|
||||
#else
|
||||
# if defined(MAC_OS)
|
||||
# define _fopen_call_ fopen
|
||||
@@ -56,9 +56,9 @@
|
||||
# define _fseek_call_ fseeko64
|
||||
# define _ftell_call_ ftello64
|
||||
# endif
|
||||
# define _stat_struct_ struct stat64
|
||||
# define _stat_call_ stat64
|
||||
# define _stat_link_ lstat64
|
||||
# define _stat_struct_ struct stat64
|
||||
# define _stat_call_ stat64
|
||||
# define _stat_link_ lstat64
|
||||
#endif
|
||||
|
||||
|
||||
@@ -182,8 +182,8 @@ bool PIFile::closeDevice() {
|
||||
PIString PIFile::readLine() {
|
||||
PIString str;
|
||||
if (!opened_) return str;
|
||||
int cc, cp = 0;
|
||||
while (!isEnd() && cp < 4095) {
|
||||
int cc;
|
||||
while (!isEnd()) {
|
||||
cc = fgetc(fd);
|
||||
if (char(cc) == '\n' || cc == EOF) break;
|
||||
str.push_back(char(cc));
|
||||
@@ -395,6 +395,22 @@ void PIFile::remove() {
|
||||
|
||||
|
||||
|
||||
const char * PIFile::defaultCharset() {
|
||||
return PIInit::instance()->file_charset;
|
||||
}
|
||||
|
||||
|
||||
void PIFile::setDefaultCharset(const char * c) {
|
||||
if (PIInit::instance()->file_charset) delete PIInit::instance()->file_charset;
|
||||
PIInit::instance()->file_charset = 0;
|
||||
if (!c) return;
|
||||
PIInit::instance()->file_charset = new char[1024];
|
||||
memset(PIInit::instance()->file_charset, 0, 1024);
|
||||
strcpy(PIInit::instance()->file_charset, c);
|
||||
piCout << PIInit::instance()->file_charset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
||||
FileInfo ret;
|
||||
|
||||
@@ -247,6 +247,11 @@ public:
|
||||
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
|
||||
EVENT_HANDLER2(void, resize, llong, new_size, uchar, fill);
|
||||
|
||||
//!
|
||||
static const char * defaultCharset();
|
||||
|
||||
//!
|
||||
static void setDefaultCharset(const char * c);
|
||||
|
||||
//! Returns opened temporary file with open mode "mode"
|
||||
static PIFile openTemporary(PIIODevice::DeviceMode mode = PIIODevice::ReadWrite) {return PIFile(PIString(tmpnam(0)), mode);}
|
||||
|
||||
Reference in New Issue
Block a user