My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
#include "Core.h"

#ifdef PLATFORM_WIN32
# include <winnls.h>
#endif

NAMESPACE_UPP

bool PanicMode;

bool IsPanicMode() { return PanicMode; }

static void (*sPanicMessageBox)(const char *title, const char *text);

void InstallPanicMessageBox(void (*mb)(const char *title, const char *text))
{
sPanicMessageBox = mb;
}

void PanicMessageBox(const char *title, const char *text)
{
PanicMode = true;
if(sPanicMessageBox)
(*sPanicMessageBox)(title, text);
else {
IGNORE_RESULT(
write(2, text, (int)strlen(text))
);
IGNORE_RESULT(
write(2, "\n", 1)
);
}
}

void Panic(const char *msg)
{
#ifdef PLATFORM_POSIX
signal(SIGILL, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGBUS, SIG_DFL);
signal(SIGFPE, SIG_DFL);
#endif
if(PanicMode)
return;
PanicMode = true;
LOG(msg);
BugLog() << "PANIC: " << msg << "\n";
UsrLogT("===== PANIC ================================================");
UsrLogT(msg);
PanicMessageBox("Fatal error", msg);

#ifdef PLATFORM_WIN32
# ifdef __NOASSEMBLY__
# if defined(PLATFORM_WINCE) || defined(WIN64)
DebugBreak();
# endif
# else
# if defined(_DEBUG) && defined(CPU_X86)
# ifdef COMPILER_MSC
_asm int 3
# endif
# ifdef COMPILER_GCC
asm("int $3");
# endif
# endif
# endif
#else
#endif
#ifdef _DEBUG
__BREAK__;
#endif
abort();
}

static void (*s_assert_hook)(const char *);

void SetAssertFailedHook(void (*h)(const char *))
{
s_assert_hook = h;
}

void AssertFailed(const char *file, int line, const char *cond)
{
if(PanicMode)
return;
PanicMode = true;
char s[2048];
sprintf(s, "Assertion failed in %s, line %d\n%s\n", file, line, cond);
LOG(s);
LOG(GetLastErrorMessage());
if(s_assert_hook)
(*s_assert_hook)(s);
BugLog() << "ASSERT FAILED: " << s << "\n";
UsrLogT("===== ASSERT FAILED ================================================");
UsrLogT(s);

PanicMessageBox("Fatal error", s);

#ifdef PLATFORM_WIN32
# ifdef __NOASSEMBLY__
# if defined(PLATFORM_WINCE) || defined(WIN64)
DebugBreak();
# endif
# else
# if defined(_DEBUG) && defined(CPU_X86)
# ifdef COMPILER_MSC
_asm int 3
# endif
# ifdef COMPILER_GCC
asm("int $3");
# endif
# endif
# endif
#else
#endif
__BREAK__;
abort();
}

#ifdef PLATFORM_POSIX
dword GetTickCount() {
struct timeval tv[1];
struct timezone tz[1];
memset(tz, 0, sizeof(tz));
gettimeofday(tv, tz);
return (dword)tv->tv_sec * 1000 + tv->tv_usec / 1000;
}

#endif

int msecs(int from) { return GetTickCount() - (dword)from; }

void TimeStop::Reset()
{
starttime = GetTickCount();
}

TimeStop::TimeStop()
{
Reset();
}

String TimeStop::ToString() const
{
dword time = Elapsed();
return Format("%d.%03d", int(time / 1000), int(time % 1000));
}

int RegisterTypeNo__(const char *type)
{
INTERLOCKED {
static Index<String> types;
return types.FindAdd(type);
}
return -1;
}

char *PermanentCopy(const char *s)
{
char *t = (char *)MemoryAllocPermanent(strlen(s) + 1);
strcpy(t, s);
return t;
}

#ifndef PLATFORM_WIN32
void Sleep(int msec)
{
::timespec tval;
tval.tv_sec = msec / 1000;
tval.tv_nsec = (msec % 1000) * 1000000;
nanosleep(&tval, NULL);
}
#endif

int MemICmp(const void *dest, const void *src, int count)
{

const byte *a = (const byte *)dest;
const byte *b = (const byte *)src;
const byte *l = a + count;
while(a < l) {
if(ToUpper(*a) != ToUpper(*b))
return ToUpper(*a) - ToUpper(*b);
a++;
b++;
}
return 0;
}

Stream& Pack16(Stream& s, Point& p) {
return Pack16(s, p.x, p.y);
}

Stream& Pack16(Stream& s, Size& sz) {
return Pack16(s, sz.cx, sz.cy);
}

Stream& Pack16(Stream& s, Rect& r) {
return Pack16(s, r.left, r.top, r.right, r.bottom);
}

int InScListIndex(const char *s, const char *list)
{
int ii = 0;
for(;;) {
const char *q = s;
for(;;) {
if(*q == '\0' && *list == '\0') return ii;
if(*q != *list) {
if(*q == '\0' && *list == ';') return ii;
if(*list == '\0') return -1;
break;
}
q++;
list++;
}
while(*list && *list != ';') list++;
if(*list == '\0') return -1;
list++;
ii++;
}
}

bool InScList(const char *s, const char *list)
{
return InScListIndex(s, list) >= 0;
}

void StringC::Free() {
if(IsString()) delete (String *) bap.GetPtr();
}

StringC::~StringC() {
Free();
}

StringC::operator const char *() const {
if(IsEmpty()) return NULL;
if(IsString()) return *(String *) bap.GetPtr();
return (const char *)bap.GetPtr();
}

StringC::operator String() const {
if(IsEmpty()) return (const char *)NULL;
if(IsString()) return *(String *) bap.GetPtr();
return (const char *)bap.GetPtr();
}

bool StringC::IsEmpty() const {
if(IsString()) return (*(String *) bap.GetPtr()).IsEmpty();
if(!bap.GetPtr()) return true;
return !*(const char *)bap.GetPtr();
}

void StringC::SetString(const String& s) {
Free();
String *ptr = new String;
*ptr = s;
bap.Set1(ptr);
}

void StringC::SetCharPtr(const char *s) {
Free();
bap.Set0((void *)s);
}

CharFilterTextTest::CharFilterTextTest(int (*filter)(int)) : filter(filter) {}
CharFilterTextTest::~CharFilterTextTest() {}

const char *CharFilterTextTest::Accept(const char *s) const {
if(!(*filter)((byte)*s++)) return NULL;
return s;
}

Vector<String> Split(const char *s, const TextTest& delim, bool ignoreempty) {
Vector<String> r;
const char *t = s;
while(*t) {
const char *q = delim.Accept(t);
if(q) {
if(!ignoreempty || t > s)
r.Add(String(s, t));
t = s = q;
}
else
t++;
}
if(!ignoreempty || t > s)
r.Add(String(s, t));
return r;
}

Vector<String> Split(const char *s, int (*filter)(int), bool ignoreempty) {
return Split(s, CharFilterTextTest(filter), ignoreempty);
}

struct chrTextTest : public TextTest {
int chr;
virtual const char *Accept(const char *s) const { return chr == *s ? s + 1 : NULL; }
};

Vector<String> Split(const char *s, int chr, bool ignoreempty) {
chrTextTest ct;
ct.chr = chr;
return Split(s, ct, ignoreempty);
}

struct StringSplit : TextTest {
String test;

virtual const char *Accept(const char *s) const {
int l = test.GetCount();
if(l && memcmp(~test, s, l) == 0)
return s + l;
return NULL;
}
};

Vector<String> Split(const char *s, const String& delim, bool ignoreempty)
{
StringSplit ss;
ss.test = delim;
return Split(s, ss, ignoreempty);
}

String Join(const Vector<String>& im, const String& delim) {
String r;
for(int i = 0; i < im.GetCount(); i++) {
if(i) r.Cat(delim);
r.Cat(im[i]);
}
return r;
}

WString Join(const Vector<WString>& im, const WString& delim) {
WString r;
for(int i = 0; i < im.GetCount(); i++) {
if(i) r.Cat(delim);
r.Cat(im[i]);
}
return r;
}
// ---------------------------

VectorMap<String, String> LoadIniStream(Stream &sin) {
Stream *in = &sin;
FileIn fin;
VectorMap<String, String> key;
int c;
if((c = in->Get()) < 0) return key;
for(;;) {
String k, v;
for(;;) {
if(IsAlNum(c) || c == '_')
k.Cat(c);
else
break;
if((c = in->Get()) < 0) return key;
}
for(;;) {
if(c != '=' && c != ' ') break;
if((c = in->Get()) < 0) return key;
}
for(;;) {
if(c < ' ') break;
v.Cat(c);
if((c = in->Get()) < 0) break;
}
if(!k.IsEmpty())
key.Add(k, v);
if(k == "LINK") {
if(in == &fin)
fin.Close();
if(!fin.Open(v) || (c = in->Get()) < 0) return key;
in = &fin;
}
else
for(;;) {
if(IsAlNum(c) || c == '_') break;
if((c = in->Get()) < 0) return key;
}
}
}

VectorMap<String, String> LoadIniFile(const char *filename) {
FileIn in(filename);
if(!in) return VectorMap<String, String>();
return LoadIniStream(in);
}

static StaticMutex sMtx;
static char sIniFile[256];
static bool s_ini_loaded;

void SetIniFile(const char *name) {
Mutex::Lock __(sMtx);
strcpy(sIniFile, name);
}

String GetIniKey(const char *id, const String& def) {
Mutex::Lock __(sMtx);
static VectorMap<String, String> key;
if(!s_ini_loaded) {
s_ini_loaded = true;
key = LoadIniFile(*sIniFile ? sIniFile : ~ConfigFile("q.ini"));
#ifdef PLATFORM_WIN32
if(key.GetCount() == 0)
key = LoadIniFile(~GetExeDirFile("q.ini"));
if(key.GetCount() == 0)
key = LoadIniFile("c:\\q.ini");
#endif
#ifdef PLATFORM_POSIX
if(key.GetCount() == 0)
key = LoadIniFile(GetHomeDirFile("q.ini"));
#endif
}
return key.Get(id, def);
}

String GetIniKey(const char *id)
{
return GetIniKey(id, String());
}

void TextSettings::Load(const char *filename)
{
FileIn in(filename);
int themei = 0;
settings.Add("");
while(!in.IsEof()) {
String ln = in.GetLine();
const char *s = ln;
if(*s == '[') {
s++;
String theme;
while(*s && *s != ']')
theme.Cat(*s++);
themei = settings.FindAdd(theme);
}
else {
if(themei >= 0) {
String key;
while(*s && *s != '=') {
key.Cat(*s++);
}
if(*s == '=') s++;
String value;
while(*s) {
value.Cat(*s++);
}
if(!IsEmpty(key))
settings[themei].GetAdd(TrimBoth(key)) = TrimBoth(value);
}
}
}
}

String TextSettings::Get(const char *group, const char *key) const
{
int itemi = settings.Find(group);
return itemi < 0 ? Null : settings.Get(group).Get(key, Null);
}

String TextSettings::Get(int groupIndex, const char *key) const
{
return groupIndex >= 0 && groupIndex < settings.GetCount() ?
settings[groupIndex].Get(key, Null) : Null;
}

String TextSettings::Get(int groupIndex, int keyIndex) const
{
if (groupIndex >= 0 && groupIndex < settings.GetCount())
return keyIndex >= 0 && keyIndex < settings[groupIndex].GetCount() ?
settings[groupIndex][keyIndex] : Null;
else
return Null;
}

// --------------------------------------------------------------

String timeFormat(double s) {
if(s < 0.000001) return Sprintf("%5.2f ns", s * 1.0e9);
if(s < 0.001) return Sprintf("%5.2f us", s * 1.0e6);
if(s < 1) return Sprintf("%5.2f ms", s * 1.0e3);
return Sprintf("%5.2f s ", s);
}

String Garble(const char *s, const char *e)
{
int c = 0xAA;
String result;
if(!e)
e = s + strlen(s);
while(s != e)
{
result.Cat(*s++ ^ (char)c);
if((c <<= 1) & 0x100)
c ^= 0x137;
}
return result;
}

String Garble(const String& s)
{
return Garble(~s, ~s + s.GetLength());
}

String Encode64(const String& s)
{
String enc;
int l = s.GetLength();
enc << l << ':';
for(int i = 0; i < l;)
{
char a = 0, b = 0, c = 0;
if(i < l) a = s[i++];
if(i < l) b = s[i++];
if(i < l) c = s[i++];
enc.Cat(' ' + 1 + ((a >> 2) & 0x3F));
enc.Cat(' ' + 1 + ((a << 4) & 0x30) + ((b >> 4) & 0x0F));
enc.Cat(' ' + 1 + ((b << 2) & 0x3C) + ((c >> 6) & 0x03));
enc.Cat(' ' + 1 + (c & 0x3F));
}
return enc;
}

String Decode64(const String& s)
{
if(!IsDigit(*s))
return s;
const char *p = s;
char *h;
int len = strtol(p, &h, 10);
p = h;
if(*p++ != ':' || len < 0 || (len + 2) / 3 * 4 > (s.End() - p))
return s; // invalid encoding
if(len == 0)
return Null;
String dec;
for(;;)
{
byte ea = *p++ - ' ' - 1, eb = *p++ - ' ' - 1, ec = *p++ - ' ' - 1, ed = *p++ - ' ' - 1;
byte out[3] = { byte((ea << 2) | (eb >> 4)), byte((eb << 4) | (ec >> 2)), byte((ec << 6) | (ed >> 0)) };
switch(len)
{
case 1: dec.Cat(out[0]); return dec;
case 2: dec.Cat(out, 2); return dec;
case 3: dec.Cat(out, 3); return dec;
default: dec.Cat(out, 3); len -= 3; break;
}
}
}

String HexString(const byte *s, int count, int sep, int sepchr)
{
ASSERT(count >= 0);
if(count == 0)
return String();
StringBuffer b(2 * count + (count - 1) / sep);
static const char itoc[] = "0123456789abcdef";
int i = 0;
char *t = b;
for(;;) {
for(int q = 0; q < sep; q++) {
if(i >= count)
return b;
*t++ = itoc[(s[i] & 0xf0) >> 4];
*t++ = itoc[s[i] & 0x0f];
i++;
}
if(i >= count)
return b;
*t++ = sepchr;
}
}

String HexString(const String& s, int sep, int sepchr)
{
return HexString(~s, s.GetCount(), sep, sepchr);
}

String ScanHexString(const char *s, const char *lim)
{
String r;
r.Reserve(int(lim - s) / 2);
for(;;) {
byte b = 0;
while(!IsXDigit(*s)) {
if(s >= lim)
return r;
s++;
}
b = ctoi(*s++);
if(s >= lim)
return r;
while(!IsXDigit(*s)) {
if(s >= lim) {
r.Cat(b);
return r;
}
s++;
}
b = (b << 4) + ctoi(*s++);
r.Cat(b);
if(s >= lim)
return r;
}
}

String NormalizeSpaces(const char *s)
{
StringBuffer r;
while(*s && (byte)*s <= ' ')
s++;
while(*s) {
if((byte)*s <= ' ') {
while(*s && (byte)*s <= ' ')
s++;
if(*s)
r.Cat(' ');
}
else
r.Cat(*s++);
}
return r;
}

String NormalizeSpaces(const char *s, const char *end)
{
StringBuffer r;
while(*s && (byte)*s <= ' ')
s++;
while(s < end) {
if((byte)*s <= ' ') {
while(s < end && (byte)*s <= ' ')
s++;
if(*s)
r.Cat(' ');
}
else
r.Cat(*s++);
}
return r;
}

String CsvString(const String& text)
{
String r;
r << '\"';
const char *s = text;
while(*s) {
if(*s == '\"')
r << "\"\"";
else
r.Cat(*s);
s++;
}
r << '\"';
return r;
}

Vector<String> GetCsvLine(Stream& s, int separator, byte charset)
{
Vector<String> r;
bool instring = false;
String val;
byte dcs = GetDefaultCharset();
for(;;) {
int c = s.Get();
if(c == '\n' || c < 0) {
if(val.GetCount())
r.Add(ToCharset(dcs, val, charset));
return r;
}
else
if(c == separator && !instring) {
r.Add(ToCharset(dcs, val, charset));
val.Clear();
}
else
if(c == '\"') {
if(instring && s.Term() == '\"') {
s.Get();
val.Cat('\"');
}
else
instring = !instring;
}
else
if(c != '\r')
val.Cat(c);
}
}

int ChNoInvalid(int c)
{
return c == DEFAULTCHAR ? '_' : c;
}

#ifdef PLATFORM_WINCE
WString ToSystemCharset(const String& src)
{
return src.ToWString();
}

String FromSystemCharset(const WString& src)
{
return src.ToString();
}
#else

#ifdef PLATFORM_WIN32
String ToSystemCharset(const String& src)
{
WString s = src.ToWString();
int l = s.GetLength() * 5;
StringBuffer b(l);
int q = WideCharToMultiByte(CP_ACP, 0, (const WCHAR *)~s, s.GetLength(), b, l, NULL, NULL);
if(q <= 0)
return src;
b.SetCount(q);
return b;
}

String FromWin32Charset(const String& src, int cp)
{
WStringBuffer b(src.GetLength());
int q = MultiByteToWideChar(cp, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength());
if(q <= 0)
return src;
b.SetCount(q);
return WString(b).ToString();
}

String FromOEMCharset(const String& src)
{
return FromWin32Charset(src, CP_OEMCP);
}

String FromSystemCharset(const String& src)
{
return FromWin32Charset(src, CP_ACP);
}

WString ToSystemCharsetW(const char *src)
{
return String(src).ToWString();
}

String FromSystemCharsetW(const wchar *src)
{
return WString(src).ToString();
}

#else
String ToSystemCharset(const String& src)
{
return IsMainRunning() ? Filter(ToCharset(GetLNGCharset(GetSystemLNG()), src), ChNoInvalid)
: src;
}

String FromSystemCharset(const String& src)
{
return IsMainRunning() ? Filter(ToCharset(CHARSET_DEFAULT, src, GetLNGCharset(GetSystemLNG())), ChNoInvalid) : src;
}
#endif
#endif

static VectorMap<String, String>& sGCfg()
{
static VectorMap<String, String> m;
return m;
}

static StaticCriticalSection sGCfgLock;

static Vector<Callback>& sGFlush()
{
static Vector<Callback> m;
return m;
}

static StaticCriticalSection sGFlushLock;

void RegisterGlobalConfig(const char *name)
{
INTERLOCKED_(sGCfgLock) {
ASSERT(sGCfg().Find(name) < 0);
sGCfg().Add(name);
}
}

void RegisterGlobalConfig(const char *name, Callback WhenFlush)
{
RegisterGlobalConfig(name);
INTERLOCKED_(sGFlushLock) {
sGFlush().Add(WhenFlush);
}
}

String GetGlobalConfigData(const char *name)
{
INTERLOCKED_(sGCfgLock) {
return sGCfg().GetAdd(name);
}
return String();
}

void SetGlobalConfigData(const char *name, const String& data)
{
INTERLOCKED_(sGCfgLock) {
sGCfg().GetAdd(name) = data;
}
}

void SerializeGlobalConfigs(Stream& s)
{
INTERLOCKED_(sGFlushLock) {
for(int i = 0; i < sGFlush().GetCount(); i++)
sGFlush()[i]();
}
INTERLOCKED_(sGCfgLock) {
VectorMap<String, String>& cfg = sGCfg();
int version = 0;
s / version;
int count = cfg.GetCount();
s / count;
for(int i = 0; i < count; i++) {
String name;
if(s.IsStoring())
name = cfg.GetKey(i);
s % name;
int q = cfg.Find(name);
if(q >= 0)
s % cfg[q];
else
{
String dummy;
s % dummy;
}
}
s.Magic();
}
}

Exc::Exc() : String(GetLastErrorMessage()) {}
/*
#ifdef PLATFORM_WIN32
void Exc::Show() const {
if(IsEmpty()) return;
MessageBox(GetActiveWindow(), *this, "Chyba", MB_OK);
}
#endif

#ifdef PLATFORM_POSIX
void Exc::Show() const {
printf(*this);
}
#endif
*/
AbortExc::AbortExc() :
Exc(t_("Aborted by user.")) {}

#ifdef PLATFORM_WIN32

String GetErrorMessage(DWORD dwError) {
char h[2048];
sprintf(h, "%08x", dwError);
#ifdef PLATFORM_WINCE //TODO
return h;
#else
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dwError, 0, h, 2048, NULL);
String result = h;
String modf;
const char* s = result;
BYTE c;
while((c = *s++) != 0)
if(c <= ' ') {
if(!modf.IsEmpty() && modf[modf.GetLength() - 1] != ' ')
modf += ' ';
}
else if(c == '%' && *s >= '0' && *s <= '9') {
s++;
modf += "<###>";
}
else
modf += (char)c;
const char* p = modf;
for(s = p + modf.GetLength(); s > p && s[-1] == ' '; s--);
return FromSystemCharset(modf.Left((int)(s - p)));
#endif
}

String GetLastErrorMessage() {
return GetErrorMessage(GetLastError());
}

#endif

#ifdef PLATFORM_POSIX

String GetErrorMessage(int errorno)
{
// Linux strerror_r declaration might be different than posix
// hence we are using strerror with mutex... (cxl 2008-07-17)
static StaticMutex m;
Mutex::Lock __(m);
return FromSystemCharset(strerror(errorno));
}

String GetLastErrorMessage() {
return GetErrorMessage(errno);
}

#endif

#ifdef PLATFORM_POSIX
static void LinuxBeep(const char *fn)
{
return;
// This is not the right way to do that... (causes zombies, ignores Gnome settings)
char h[100];
strcpy(h, "aplay /usr/share/sounds/");
strcat(h, fn);
#ifdef CPU_BLACKFIN
if(vfork()) return;
#else
if(fork()) return;
#endif
IGNORE_RESULT(
system(h)
);
_exit(EXIT_SUCCESS);
}
#endif

void BeepInformation()
{
#ifdef PLATFORM_WIN32
MessageBeep(MB_ICONINFORMATION);
#else
LinuxBeep("info.wav");
#endif
}

void BeepExclamation()
{
#ifdef PLATFORM_WIN32
MessageBeep(MB_ICONEXCLAMATION);
#else
LinuxBeep("warning.wav");
#endif
}

void BeepQuestion()
{
#ifdef PLATFORM_WIN32
MessageBeep(MB_ICONQUESTION);
#else
LinuxBeep("question.wav");
// write(1, "\a", 1); //??
#endif
}

#if defined(COMPILER_MSC) && (_MSC_VER < 1300)
//hack for linking libraries built using VC7 with VC6 standard lib's
extern "C" long _ftol( double );
extern "C" long _ftol2( double dblSource ) { return _ftol( dblSource ); }
#endif

#ifdef PLATFORM_WINCE
int errno; // missing and zlib needs it
#endif

END_UPP_NAMESPACE

Change log

r4917 by cxl on May 9, 2012   Diff
Core: Fixed issue with Null in Json
Go to: 
Project members, sign in to write a code review

Older revisions

r4818 by cxl on Apr 19, 2012   Diff
U++: fixed sources to support c++0x
(rm #269)
r4798 by cxl on Apr 17, 2012   Diff
*Core: Fixed msecs issues
r4790 by cxl on Apr 15, 2012   Diff
*Core: msecs issue fixed
All revisions of this file

File info

Size: 18818 bytes, 976 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting