-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.tc
1058 lines (841 loc) · 17 KB
/
utils.tc
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
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "global.th"
static string<16> _hex = "0123456789ABCDEF";
static string<64> _b64e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
string<2>
tohex(unsigned char c)
{
char *hx = _hex;
return chr(hx[(c >> 4) & 0x0F]) + chr(hx[c & 0x0F]);
}
string<8>
tobin(unsigned char c)
{
unsigned char mask;
string<8> res;
for(mask=0x80; mask; mask >>= 1)
res += (c & mask) == 0? "0": "1";
return res;
}
/*! \brief Converts binary string into the readable representation
* \param[in] s Input string
* \returns Readable representation of the passed string
*/
string
dump(string& s)
{
string res = "";
unsigned char i;
char c;
bool hx = false;
char *ps = s;
if(len(s)==0)
return "\"\"";
for(i=0; i<len(s); ++i) {
c = ps[i];
if(c >= 32 && c <= 0x7F) {
if(i == 0)
res += chr('\"');
if(hx) {
res += " \"";
hx = false;
}
res += chr(c);
} else {
if(!hx && i>0)
res += "\"";
if(i > 0)
res += " ";
//res += "0x" + tohex(c);
res += tohex(c);
hx = true;
}
}
if(!hx)
res += chr('\"');
return res;
}
string
sdump(string& s)
{
string res = "\"";
unsigned char i;
char c;
if(len(s)==0)
return "\"\"";
for(i=0; i<len(s); ++i) {
c = s[i];
switch(c) {
case '\'':
res += "\\'";
break;
case '\"':
res += "\\\"";
break;
case '\n':
res += "\\n";
break;
case '\r':
res += "\\r";
break;
case '\t':
res += "\\t";
break;
default:
if(c >= 32 && c <= 0x7F)
res += chr(c);
else
res += "\\x" + tohex(c);
break;
}
}
return res + "\"";
}
string
hexdump(unsigned char *buf, unsigned char cb)
{
string res = "";
unsigned char i;
for(i=0; i<cb; ++i) {
res += tohex(buf[i]);
if(i != (cb-1))
res += chr(' ');
}
return res;
}
void
delay(unsigned int ms)
{
char j;
for(; ms>0; --ms)
for(j=5; j>0; --j) ;
}
void
delay_ms(unsigned int ms)
{
//unsigned long tgt = sys.timercountms + ms;
//while(sys.timercountms != tgt) ;
delay(ms);
}
unsigned char
hexdigit(char c)
{
if(c >= '0' && c <= '9')
return c-'0';
if(c >= 'a' && c <= 'f')
return c-'a'+10;
if(c >= 'A' && c <= 'F')
return c-'A'+10;
return 0;
}
unsigned char
unhex(char& *str)
{
return (hexdigit(*str++) << 4) | hexdigit(*str++);
}
void
halt(unsigned char reason)
{
pat.play("-R~", PL_PAT_NOINT);
beep.play("*b-b-b-", PL_BEEP_NOINT);
// led_bar_set_pattern(reason);
}
int
bit_alloc(unsigned char *buf, unsigned char cb)
{
unsigned char i, mask, j;
if(NULL == buf || 0 == cb)
return -1;
for(i=0; i<cb; ++i) {
if(0xFF != buf[i]) {
for(j=0, mask=0x80; mask!=0; mask>>=1, ++j) {
if(0 == (buf[i] & mask)) {
buf[i] |= mask;
return i*8 + j;
}
}
}
}
return -1;
}
void
bit_free(unsigned char *buf, unsigned char cb, unsigned int bit)
{
unsigned int bi = bit >> 3;
unsigned char msk = 0x80 >> (bit & 0x07);
if(bi < cb && buf != NULL)
buf[bi] &= ~msk;
}
bool
bit_used(unsigned char *buf, unsigned char cb, unsigned int bit)
{
unsigned int bi = bit >> 3;
unsigned char msk = 0x80 >> (bit & 0x07);
if(bi < cb && buf != NULL)
return 0 != (buf[bi] & msk);
return false;
}
/*! \brief Return json-encoded name:value pair
*/
string
j_encode(string& pname, string& pval)
{
return "\"" + pname + "\":\"" + pval + "\"";
}
string
j_encoderaw(string& pname, string& pval)
{
return "\"" + pname + "\":" + pval;
}
string
json_add(string& res, string pname, string pval)
{
if(len(res)>0)
res += ",";
res += "\"" + pname + "\":\"" + pval + "\"";
return res;
}
string
j_error(string msg)
{
return j_encode("status", "error") + "," + j_encode("errmsg", msg);
}
string
query_string()
{
return "&" + sock.httprqstring;
}
/*! \brief Extract argument from http query string
*/
string
query_arg(string& get, string key, string dflt)
{
int p, i, l;
string res = dflt;
key = "&"+key+"=";
p = instr(1, get, key, 1);
if(0 == p)
return dflt; // not found
p += len(key);
l = len(get);
i = instr(p, get, "&", 1);
if(i == 0) {
i = instr(p, get, " ", 1);
if(i == 0)
i = l+1;
}
return mid(get, p, i-p);
}
void
echo(string out)
{
sock.setdata(out);
sock.send();
}
string
htmlspecialchars(string s)
{
word i, l;
string res;
char c;
res = "";
for(i=0, l=len(s); i<l; ++i) {
c = s[i];
switch(c) {
case '<':
res += "<";
break;
case '>':
res += ">";
break;
case '&':
res += "&";
break;
case '\"':
res += """;
break;
case '\'':
res += "'";
break;
default:
res += chr(c);
break;
}
}
return res;
}
void
echo_setting(string& name)
{
string v = stg_get(name, 0);
echo(htmlspecialchars(v));
}
bool
is_space(char c)
{
return (c==' ') || (c=='\t') || (c=='\r') || (c=='\n');
}
string
trim(string s)
{
word i, j, l;
l = 0;
l = len(s);
for(i=0; i<l; ++i)
if(!is_space(s[i]))
break;
for(j=l-1; j>i; --j)
if(!is_space(s[j]))
break;
return mid(s, i+1, j-i+1);
}
/*! \brief Encodes string as URL
*/
string
urlencode(string& s)
{
string res;
word i, l;
l = len(s);
for(res="", i=0; i<l; ++i) {
if(s[i]>='0' && s[i]<0x7F)
res += chr(s[i]);
else
res += "%" + tohex(s[i]);
}
return res;
}
/*! \brief Decodes URL-encoded string
*/
string
urldecode(string& s)
{
string res;
string<4> h;
byte esc;
word i, j, l;
l = len(s);
for(esc=0, i=0; i<l; ++i) {
switch(s[i]) {
case '%':
h = "";
esc = 2;
break;
case '+':
res += " ";
break;
default:
if(esc != 0) {
if(s[i] == 'U' || s[i] == 'u') {
esc += 2;
break;
}
/* if s[i] is not a hex digit, just flush '%' and following characters */
h += chr(s[i]);
if(0 == --esc) {
for(j=0; j<len(h); j+=2)
res += chr((hexdigit(h[j]) << 4) | hexdigit(h[j+1]));
}
} else {
res += chr(s[i]);
}
break;
}
}
return res;
}
string
urlencode_n(string s)
{
string res;
char c;
int i, l;
l = len(s);
for(res = "", i=0; i<l; ++i) {
c = s[i];
if(c >= 33 && s[i] <= c)
res += chr(c);
else if(c == 32)
res += "+";
else if(c == '+')
res += "#" + tohex('+');
else
res += "#" + tohex(c);
}
return res;
}
string
format_serial(string& s)
{
return (tohex(s[0]) + tohex(s[1]) + tohex(s[2]) + tohex(s[3])) + "-" +
(tohex(s[4]) + tohex(s[5]) + tohex(s[6]) + tohex(s[7])) + "-" +
(tohex(s[8]) + tohex(s[9]) + tohex(s[10]) + tohex(s[11]));
}
void
sock_send(string s)
{
byte l;
l = len(s);
if(0 == l)
return;
if(l > sock.txfree) {
sock.send();
while(sock.txlen > 0);
//doevents;
}
sock.setdata(s);
}
void
ser_send(string& data)
{
word sl = len(data); //sock.txlen;
if(ser.txfree < sl) {
ser.send();
while(ser.txlen > 0)
/* doevents */;
}
ser.setdata(data);
}
void
send_setting(string sname)
{
unsigned char ns, i;
string sval;
stg_get_num_members(sname, ns);
sys.debugprint(sname + "=" + str(ns) + "\r\n");
sock_send("\""+sname+"\""+":");
if(ns > 1) {
sock_send("[");
for(i=0; i<ns; ++i) {
sval = stg_get(sname, i);
if ((sname == "O1") || (sname == "O2") || (sname == "O3") || (sname == "O4") || (sname == "O5") || (sname == "O6") || (sname == "O7") || (sname == "O8")) {
string hexStr;
string hexVal = "";
for (int i = 1; i <= 8; i++) {
hexStr = hex(asc(mid(sval, i, 1)));
if (len(hexStr) == 3) {
hexVal += "0" + right(hexStr, 1);
} else {
hexVal += right(hexStr, 2);
}
}
sval = hexVal;
}
sock_send("\""+sval+"\"");
if(i < ns-1)
sock_send(",");
}
sock_send("]");
} else {
sval = stg_get(sname, 0);
sock_send("\""+sval+"\"");
}
}
void send_bp_sensors_list()
{
unsigned char ns, i, j;
string sval;
sock_send("\"BS\":");
sock_send("[");
for(i = 0; i < 4; ++i) {
for (j = 0; j < 16; j++) {
sval = str(bp_get_type(i, j));
sock_send("\""+sval+"\"");
sock_send(",");
sval = str(bp_get_id(i, j));
sock_send("\""+sval+"\"");
if (!((i == 3) && (j == 15)))
sock_send(",");
}
}
sock_send("],");
// send FIND flags
sys.debugprint("Find: ");
sock_send("\"FIND\":");
sock_send("[");
for(i = 0; i < 4; ++i) {
sval = str(bp_get_find(i));
sys.debugprint(bp_get_find(i));
sock_send("\""+sval+"\"");
if (i != 3) {
sys.debugprint(",");
sock_send(",");
}
}
sock_send("]");
sys.debugprint("\n");
}
void send_ow_sensors_list()
{
unsigned char ns, i, j, k;
unsigned char slot, port;
string sval;
string hexStr;
string hexVal;
slot = 0;
port = 0;
for (i = 0; i < 8; i++) {
sock_send("\"O" + str(i + 1) + "\":");
sock_send("[");
for (j = 0; j < 8; j++) {
sval = ow_get_id(slot, port, j);
hexVal = "";
for (int k = 1; k <= 8; k++) {
hexStr = hex(asc(mid(sval, k, 1)));
if (len(hexStr) == 3) {
hexVal += "0" + right(hexStr, 1);
} else {
hexVal += right(hexStr, 2);
}
}
sock_send("\"" + hexVal + "\"");
if (j < 7)
sock_send(",");
}
port++;
if (port == 4) {
slot++;
port = 0;
}
sock_send("],");
}
// send FIND flags
sock_send("\"FIND\":");
sock_send("[");
slot = 0;
port = 0;
for(i = 0; i < 8; ++i) {
sval = str(ow_get_find(slot, port));
sock_send("\""+sval+"\"");
if (i != 7)
sock_send(",");
port++;
if (port == 4) {
slot++;
port = 0;
}
}
sock_send("]");
}
static void
_settings_send_js(void)
{
unsigned int i, j;
string sname;
string<4> comma;
romfile.open(STG_FILE_C); //STG_DESCRIPTOR_FILE);
if(0 == romfile.pointer)
return; // No such file found or other filesystem error
comma = "";
for(;;) {
i = romfile.find(romfile.pointer, ">>", 1);
if(0 == i)
break;
/* Set read pointer right after the >> location */
romfile.pointer = i + 2;
/* Find first space character which ends the name field */
j = romfile.find(romfile.pointer, "\x09", 1);
sname = romfile.getdata(j-i-2);
if (sname != "WK") {
if (sname != "BS") {
sock_send(comma);
send_setting(sname);
comma = ",\n";
} else {
sock_send(comma);
send_bp_sensors_list();
comma = ",\n";
}
}
romfile.pointer = j;
}
}
void
send_settings()
{
#ifdef FIXEDCONFIG
sock_send("{\"fixed\":true,");
#else
sock_send("{\"fixed\":false,");
#endif
#if PLATFORM_ID == TPP3WG2
sock_send("\"options\":{\n\"xtxt\":\"" + STG_FILE_C + "\"\n,\"board\":\"TPP3\"\n},\n\"settings\":{\n");
#endif
#if PLATFORM_ID == TPP2WG2
sock_send("{"options\":{\n\"xtxt\":\"" + STG_FILE_C + "\"\n,\"board\":\"TPP2\"\n},\n\"settings\":{\n");
#endif
_settings_send_js();
sock_send("}\n}\n");
sock.send();
}
void
send_bp()
{
#if PLATFORM_ID == TPP3WG2
sock_send("{\"options\":{\n\"xtxt\":\"" + STG_FILE_C + "\"\n,\"board\":\"TPP3\"\n},\n\"settings\":{\n");
#endif
#if PLATFORM_ID == TPP2WG2
sock_send("{\"options\":{\n\"xtxt\":\"" + STG_FILE_C + "\"\n,\"board\":\"TPP2\"\n},\n\"settings\":{\n");
#endif
send_bp_sensors_list();
sock_send("}\n}\n");
sock.send();
}
void
send_ow()
{
#if PLATFORM_ID == TPP3WG2
sock_send("{\"options\":{\n\"xtxt\":\"" + STG_FILE_C + "\"\n,\"board\":\"TPP3\"\n},\n\"settings\":{\n");
#endif
#if PLATFORM_ID == TPP2WG2
sock_send("{\"options\":{\n\"xtxt\":\"" + STG_FILE_C + "\"\n,\"board\":\"TPP2\"\n},\n\"settings\":{\n");
#endif
send_ow_sensors_list();
sock_send("}\n}\n");
sock.send();
}
void
send_sdf()
{
string tmp;
romfile.open(SDF_FILE_C);
if(0 == romfile.pointer)
return; // File not found or other filesystem error
for(;;) {
tmp = romfile.getdata(200);
if(0 == len(tmp))
break;
sock_send(tmp);
}
sock.send();
}
void
setting_update(string name, string value)
{
byte b;
string n, idx;
b = instr(1, name, "@", 1);
if(b) {
n = left(name, b-1);
idx = mid(name, b+1, 255);
//DBG("Setting "+n+" #" + idx + " = "+value);
if ((name == "O1") || (name == "O2") || (name == "O3") || (name == "O4") || (name == "O5") || (name == "O6") || (name == "O7") || (name == "O8")) {
if (value == "0000000000000000")
stg_set(n, val(idx)-1, chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0));
} else {
stg_set(n, val(idx)-1, value);
}
} else {
//DBG("Setting "+name+"="+value);
stg_set(name, 0, value);
}
}
void
bp_find()
{
bp_start_find();
}
void
ow_find()
{
ow_start_find();
}
string
filesys_errcodestr(pl_fd_status_codes err)
{
switch(err) {
case PL_FD_STATUS_OK:
return "PL_FD_STATUS_OK";
case PL_FD_STATUS_FAIL:
return "PL_FD_STATUS_FAIL";
case PL_FD_STATUS_CHECKSUM_ERR:
return "PL_FD_STATUS_CHECKSUM_ERR";
case PL_FD_STATUS_FORMAT_ERR:
return "PL_FD_STATUS_FORMAT_ERR";
case PL_FD_STATUS_INV_PARAM:
return "PL_FD_STATUS_INV_PARAM";
case PL_FD_STATUS_DUPLICATE_NAME:
return "PL_FD_STATUS_DUPLICATE_NAME";
case PL_FD_STATUS_FILE_TABLE_FULL:
return "PL_FD_STATUS_FILE_TABLE_FULL";
case PL_FD_STATUS_DATA_FULL:
return "PL_FD_STATUS_DATA_FULL";
case PL_FD_STATUS_NOT_READY:
return "PL_FD_STATUS_NOT_READY";
case PL_FD_STATUS_NOT_FOUND:
return "PL_FD_STATUS_NOT_FOUND";
case PL_FD_STATUS_NOT_OPENED:
return "PL_FD_STATUS_NOT_OPENED";
case PL_FD_STATUS_ALREADY_OPENED:
return "PL_FD_STATUS_ALREADY_OPENED";
case PL_FD_STATUS_TRANSACTION_ALREADY_STARTED:
return "PL_FD_STATUS_TRANSACTION_ALREADY_STARTED";
case PL_FD_STATUS_TRANSACTION_NOT_YET_STARTED:
return "PL_FD_STATUS_TRANSACTION_NOT_YET_STARTED";
case PL_FD_STATUS_TRANSACTION_CAPACITY_EXCEEDED:
return "PL_FD_STATUS_TRANSACTION_CAPACITY_EXCEEDED";
case PL_FD_STATUS_TRANSACTIONS_NOT_SUPPORTED:
return "PL_FD_STATUS_TRANSACTIONS_NOT_SUPPORTED";
case PL_FD_STATUS_FLASH_NOT_DETECTED:
return "PL_FD_STATUS_FLASH_NOT_DETECTED";
}
return "ERR "+str(err);
}
void
_memset(void *ptr, unsigned char c, unsigned short cb)
{
for(unsigned short i=0; i<cb; ++i)
((unsigned char *)ptr)[i] = 0;
}
void
_memcpy(void *dst, void *src, unsigned short cb)
{
for(unsigned short i=0; i<cb; ++i)
((unsigned char *)dst)[i] = ((unsigned char *)src)[i];
}
typedef union {
unsigned char b[2];
unsigned short w;
} us_t;
unsigned short
htons(unsigned short v)
{
us_t vt, rt;
vt.w = v;
rt.b[0] = vt.b[1];
rt.b[1] = vt.b[0];
return rt.w;
}
unsigned long
htonl(unsigned long v)
{
return ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) | ((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24);
}
unsigned short
ntohs(unsigned short v)
{
return ((v >> 8) & 0xFF) | (v << 8);
}
unsigned long
ntohl(unsigned long v)
{
return ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) | ((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24);
}
/**
* Calculate string hash using DJB2 algorithm
*
* This algorithm (k=33) was first reported by Dan Bernstein many years ago in
* comp.lang.c. Another version of this algorithm (now favored by Bernstein)
* uses xor:
* hash(i) = hash(i - 1) * 33 ^ str[i];
*
* The magic of number 33 (why it works better than many other constants, prime
* or not) has never been adequately explained.
*/
dword
hash_djb2(byte *str)
{
dword hash = 5381;
int c;
while(c = *str++)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
string
base64_encode(string& s)
{
dword tmp;
byte *ps = (byte *)&s[0];
int ntri, nrem, l, i;
string res = "";
l = len(s);
ntri = l / 3;
nrem = l % 3;
for(i=0, l=0; l < ntri; ++l, i += 3) {
tmp = ((dword)ps[i] << 16) | ((dword)ps[i+1] << 8) | (dword)ps[i+2];
res += chr(_b64e[(tmp >> 18) & 0x3F]);
res += chr(_b64e[(tmp >> 12) & 0x3F]);
res += chr(_b64e[(tmp >> 6) & 0x3F]);
res += chr(_b64e[tmp & 0x3F]);
}
if(nrem == 2) {
tmp = ((dword)ps[i] << 16) | ((dword)ps[i+1] << 8);
res += chr(_b64e[(tmp >> 18) & 0x3F]);
res += chr(_b64e[(tmp >> 12) & 0x3F]);
res += chr(_b64e[(tmp >> 6) & 0x3F]);
res += "=";
} else if(nrem == 1) {
tmp = (dword)ps[i] << 16;
res += chr(_b64e[(tmp >> 18) & 0x3F]);
res += chr(_b64e[(tmp >> 12) & 0x3F]);
res += "==";
}
return res;
}
string
base64_decode(string& s)
{
// To be implemented soon
return s;
}
string
html_option(string& value, string& text, bool sel)
{
return "<option value=\""+value+"\""+(sel? " selected": "")+">"+text+"</option>\r\n";
}
string
html_checked(bool f)
{
return f? "checked=\"checked\"": "";
}
bool
open_always(unsigned char fnum, string& fname)
{
pl_fd_status_codes res;
fd.filenum = fnum;
if(fd.fileopened)
fd.close();
if((res = fd.open(fname)) == PL_FD_STATUS_OK)