-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
1314 lines (1035 loc) · 48.1 KB
/
main.cpp
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 "main.h"
#include "Console.h"
#include "Console_io.h"
//#include "Telnet.h"
#include "T2Input.h"
#include "vmtimer.h"
//Global
int scr_w = 0, scr_h =0;
VMUINT8 *layer_bufs[2] = {0,0};
VMINT layer_hdls[2] = {-1,-1};
VMCHAR command[100] = {};
//VMCHAR ip[100] = {};
VMCHAR portx[100] = {};
VMCHAR login[100] = {};
VMCHAR password[100] = {};
//VMBOOL missingConfigFile = VM_FALSE;
VMBOOL missingConfigFile = VM_TRUE;
VMBOOL flightMode = VM_FALSE;
VMBOOL startup = VM_FALSE;
VMCHAR text[220] = {};
VMCHAR text11[100] = {};
VMCHAR text22[100] = {};
VMCHAR text33[100] = {};
VMCHAR text44[100] = {};
VMCHAR text55[100] = {};
VMCHAR text222[100] = {};
VMCHAR text333[100] = {};
VMCHAR text444[100] = {};
VMCHAR text555[2] = "\n";
VMCHAR my_path[100] = {};
VMCHAR my_file_name[100] = {};
VMINT lenght_555;
VMINT lenght_666;
VMCHAR text6[100];
VMCHAR text3[41] = "MRE console primitive [Version 1.00]\n\n";
VMCHAR text4[150] = "about - show program information\nhelp - list available commands\necho - print string\ndir - list directory content\n";
VMCHAR text5[172] = "cd - change current directory\npath - sets a path\nmkdir - creates a directory\nrmdir - deletes a directory\ncopy - copies a file\n";
VMCHAR text10[232] = "append - joins two text files\nrename - renames a file\nmove - move a file\ndel - deletes a file\ntype - displays file contents\ncls - clear screen\nexit - quits the program\n\n";
VMCHAR text88[44] = "The syntax of the command is incorrect.\n\n";
VMINT hnd;
VMINT test;
VMINT rrrrrrr = 0;
VMINT page11 = 0;
VMINT plus_line = 29; //dirtyhack: compensate 29 lines of ignored first display
struct vm_fileinfo_ext fileInfo;
VMWCHAR fullPath1[100];
VMWCHAR fullPath2[100];
VMWCHAR fullPath3[100];
VMWCHAR fullPath4[100];
VMUINT nread;
VMFILE f_read;
VMFILE f_write;
VMCHAR new_data[2000];
Console console;
//Telnet telnet;
T2Input t2input;
int main_timer_id = -1;
int prompt_timer_id = -1; // Timer for prompt
int timeout_timer_id = -1; // Timer for waiting telnet to connect
int timeout = 0; // Timeout counter
// Telnet host and port
char ip[BUF_SIZE];
int port = -3;
char port1[BUF_SIZE];
#ifndef WIN32
extern "C" void* malloc(int size){
return vm_malloc(size);
}
extern "C" void free(void*prt){
return vm_free(prt);
}
extern "C" void _sbrk(){}
extern "C" void _write(){}
extern "C" void _close(){}
extern "C" void _lseek(){}
extern "C" void _open(){}
extern "C" void _read(){}
extern "C" void _exit(){}
extern "C" void _getpid(){}
extern "C" void _kill(){}
extern "C" void _fstat(){}
extern "C" void _isatty(){}
#endif
void handle_sysevt(VMINT message, VMINT param);
void handle_keyevt(VMINT event, VMINT keycode);
//void handle_penevt(VMINT event, VMINT x, VMINT y);
void create_app_txt_path(VMWSTR text, VMSTR extt);
void checkFileExist(void);
VMINT parseText(VMSTR text);
VMINT parseText1(VMSTR text);
VMINT parseText2(VMSTR text);
void timer1(int a);
void trim(char *reslt_data, char *inp_data);
void create_app_txt_path1(void);
void create_supdir_path(VMWSTR result, VMWSTR source);
void create_search_path(VMWSTR result, VMWSTR source, VMSTR text);
VMINT cb(VMINT act, VMUINT32 total, VMUINT32 completed, VMINT hdl);
void trim_left_symbols(char *reslt_data, char *inp_data);
void extract_path(char *reslt_data, char *inp_data);
void stringReverse(char* str);
void trim_single_spec_symb(char *reslt_data, char *inp_data);
void vm_main(void){
scr_w = vm_graphic_get_screen_width();
scr_h = vm_graphic_get_screen_height();
console.init();
//telnet.init();
t2input.init();
vm_reg_sysevt_callback(handle_sysevt);
vm_reg_keyboard_callback(handle_keyevt);
//vm_reg_pen_callback(handle_penevt);
checkFileExist();
//if (vm_sim_card_count() == 99) { flightMode = VM_TRUE; }
create_app_txt_path1();
}
void draw(){
vm_graphic_fill_rect(layer_bufs[1], 0, 0, scr_w, scr_h, tr_color, tr_color);
vm_graphic_line(layer_bufs[1], console.cursor_x*char_width, (console.cursor_y+1)*char_height,
(console.cursor_x+1)*char_width, (console.cursor_y+1)*char_height, console.cur_textcolor);
t2input.draw();
vm_graphic_flush_layer(layer_hdls, 2);
}
void timer(int tid){
//telnet.update();
draw();
}
void timeout_f(int tid){
//if (telnet.is_connected == 1) {
// // Connected
// t2input.input_mode = 0; // Change the input mode to telnet
// vm_delete_timer(timeout_timer_id); // Delete the timeout counter
//} else {
timeout++; // Increase the timeout counter
//timeout++; // Increase the timeout counter
if(timeout > 22 && timeout < 24) {
// After 30 seconds (you can change this duration) -> timeout and exit
console_str_in("\nTimed out, exiting...");
}
if(timeout > 25) {
// After 25 seconds (you can change this duration) -> timeout and exit
vm_exit_app(); // Exit
}
//}
}
/*
* We use port as the status flag before input it actual value
* If port == -3 -> prompt for host input, then set port = -2
* If port == -2 -> Check if the input has been done and if yes,
* save the ip and prompt for port input, then set port = -1
* If port == -1 -> Check if the input has been done, if yes set
* the actual port value.
*/
void prompt(int tid) {
if (port == -3) {
// Prompt for host input
// console_str_in("\nPlease enter the host name/ip: ");
port = -2;
} else if (port == -2 && t2input.input_done == 1) {
strcpy(ip, t2input.str_buf); // Save the ip
trim(text11, ip);
// console_str_in("\nPlease enter the port: ");
parseText1(text11);
parseText2(text11);
if (vm_string_equals_ignore_case(text22, "echo") == 0 && strlen(text33) == 0) {
console_str_in("ECHO is on.\n\n");
} else if (vm_string_equals_ignore_case(text22, "echo") == 0 && strlen(text55) != 0 && vm_string_equals_ignore_case(text333, ">") == 0) {
create_search_path(fullPath2, fullPath1, text222);
if (vm_file_get_attributes(fullPath2) != -1) {
console_str_in("File exists !\n\n");
} else {
f_read = vm_file_open(fullPath2, MODE_CREATE_ALWAYS_WRITE, FALSE);
vm_file_write(f_read, text444, strlen(text444), &nread);
vm_file_close(f_read);
console_str_in("\n");
}
} else if (vm_string_equals_ignore_case(text22, "echo") == 0 && strlen(text55) != 0 && vm_string_equals_ignore_case(text333, ">>") == 0) {
create_search_path(fullPath2, fullPath1, text222);
if (vm_file_get_attributes(fullPath2) != -1 && vm_file_get_attributes(fullPath2) != VM_FS_ATTR_DIR) {
//if (vm_file_get_attributes(fullPath2) != -1) {
f_read = vm_file_open(fullPath2, MODE_APPEND, FALSE);
vm_file_write(f_read, text444, strlen(text444), &nread);
vm_file_close(f_read);
console_str_in("\n");
} else {console_str_in("File not found !\n\n");}
} else if (vm_string_equals_ignore_case(text22, "echo") == 0 && strlen(text33) != 0) {
strcpy(text22, "");
strncpy(text22, text11 + 5, strlen(text11));
strcpy(text, "");
trim_single_spec_symb(text, text22);
strcat(text, "\n\n");
console_str_in(text);
} else if (vm_string_equals_ignore_case(text22, "echo.") == 0 && strlen(text55) != 0 && vm_string_equals_ignore_case(text333, ">") == 0) {
create_search_path(fullPath2, fullPath1, text222);
if (vm_file_get_attributes(fullPath2) != -1) {
console_str_in("File exists !\n\n");
} else {
f_read = vm_file_open(fullPath2, MODE_CREATE_ALWAYS_WRITE, FALSE);
vm_file_write(f_read, text555, strlen(text555), &nread);
vm_file_write(f_read, text444, strlen(text444), &nread);
vm_file_close(f_read);
console_str_in("\n");
}
} else if (vm_string_equals_ignore_case(text22, "echo.") == 0 && strlen(text55) != 0 && vm_string_equals_ignore_case(text333, ">>") == 0) {
create_search_path(fullPath2, fullPath1, text222);
if (vm_file_get_attributes(fullPath2) != -1 && vm_file_get_attributes(fullPath2) != VM_FS_ATTR_DIR) {
//if (vm_file_get_attributes(fullPath2) != -1) {
f_read = vm_file_open(fullPath2, MODE_APPEND, FALSE);
vm_file_write(f_read, text555, strlen(text555), &nread);
vm_file_write(f_read, text444, strlen(text444), &nread);
vm_file_close(f_read);
console_str_in("\n");
} else {console_str_in("File not found !\n\n");}
} else if (vm_string_equals_ignore_case(text22, "echo.") == 0 && strlen(text33) == 0) {
console_str_in("\n\n");
} else if (vm_string_equals_ignore_case(text22, "echo.") == 0 && strlen(text33) != 0) {
sprintf(text, "%s %s %s", text33, text44, text55);
trim(text, text);
trim_single_spec_symb(text, text);
sprintf(text22, " %s%s", text, "\n\n");
console_str_in(text22);
} else if (vm_string_equals_ignore_case(text22, "line") == 0 && strlen(text33) == 0) {
sprintf(text, "Line: %d\n\n", my_intx + plus_line); //chimka trukstamu 29 pirmojo ekrano eiluciu skaiciaus kompensavimui bendrame kiekyje !
console_str_in(text);
} else if (vm_string_equals_ignore_case(text22, "type") == 0 && strlen(text33) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "type") == 0 && strlen(text33) != 0) {
strcpy(text, "The system cannot find the file specified.");
vm_ascii_to_ucs2(fullPath3, (strlen(text33) + 1) * 2, text33);
vm_wstrcpy(fullPath2, fullPath1);
vm_wstrcat(fullPath2, fullPath3);
f_read = vm_file_open(fullPath2, MODE_READ, FALSE);
if (f_read < 0) {
vm_file_close(f_read);
console_str_in(text);
} else if (rrrrrrr == 1) {
sprintf(text, "Used buffer space: %d/500, need empty !\n\n", my_intx);
console_str_in(text);
} else {
while (!vm_file_is_eof(f_read)) {
vm_file_read(f_read, text, 219, &nread);
text[nread] = '\0';
console_str_in(text);
if (rrrrrrr == 0 && my_intx >= 500 - 5) {
// if (my_intx >= 500 - 5) {
rrrrrrr = 1;
console.clean_history();
console.erase_display(2);
console.reset();
plus_line = 0; //chimka trukstamu 29 pirmojo ekrano eiluciu skaiciaus kompensavimui bendrame kiekyje !
}
}
vm_file_close(f_read);
}
console_str_in("\n\n");
} else if (vm_string_equals_ignore_case(text22, "exit") == 0 && strlen(text33) == 0) {
// vm_delete_timer(prompt_timer_id);
vm_exit_app();
} else if (vm_string_equals_ignore_case(text22, "exit") == 0 && strlen(text33) != 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && strlen(text33) == 0) {
console_str_in(text4);
console_str_in(text5);
console_str_in(text10);
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "help") == 0 && strlen(text44) == 0) {
console_str_in("help - list available commands\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "cls") == 0 && strlen(text44) == 0) {
console_str_in("cls - clear screen\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "cd") == 0 && strlen(text44) == 0) {
console_str_in("cd - change current directory\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "dir") == 0 && strlen(text44) == 0) {
console_str_in("dir - list directory content\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "about") == 0 && strlen(text44) == 0) {
console_str_in("about - show program information\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "exit") == 0 && strlen(text44) == 0) {
console_str_in("exit - quits the program\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "type") == 0 && strlen(text44) == 0) {
console_str_in("type - displays file contents\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "line") == 0 && strlen(text44) == 0) {
console_str_in("line - command description\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "echo") == 0 && strlen(text44) == 0) {
//console_str_in("echo - print string\n\n");
console_str_in("When redirecting to file by > first and\n");
console_str_in("last single quotes simbols from ' text '\n");
console_str_in("was deleted\n");
console_str_in("echo '' > file.txt create empty file\n");
console_str_in("echo. tekst >> file.txt append to file\n");
console_str_in("new line (CR) and tekst\n\n");
//console_str_in("\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "del") == 0 && strlen(text44) == 0) {
console_str_in("del - deletes a file\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "mkdir") == 0 && strlen(text44) == 0) {
console_str_in("mkdir - creates a directory\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "rmdir") == 0 && strlen(text44) == 0) {
console_str_in("rmdir - deletes a directory\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "rename") == 0 && strlen(text44) == 0) {
console_str_in("rename - renames a file\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "copy") == 0 && strlen(text44) == 0) {
//console_str_in("copy - copies a file\n\n");
console_str_in("copy file1.txt file2.txt\n");
console_str_in("crrnt_dir\\file1.txt crrnt_dir\\file2.txt\n");
console_str_in("copy file1.txt e:\\file2.txt\n");
console_str_in("crrnt_dir\\file1.txt e:\\file2.txt\n");
console_str_in("copy file1.txt e:\\\n");
console_str_in("crrnt_dir\\file1.txt e:\\file1.txt\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "move") == 0 && strlen(text44) == 0) { //
//console_str_in("move - move a file\n\n");
console_str_in("move file1.txt file2.txt\n");
console_str_in("crrnt_dir\\file1.txt crrnt_dir\\file2.txt\n");
console_str_in("move file1.txt e:\\file2.txt\n");
console_str_in("crrnt_dir\\file1.txt e:\\file2.txt\n");
console_str_in("move file1.txt e:\\\n");
console_str_in("crrnt_dir\\file1.txt e:\\file1.txt\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "path") == 0 && strlen(text44) == 0) {
console_str_in("path - sets a path\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && vm_string_equals_ignore_case(text33, "append") == 0 && strlen(text44) == 0) {
console_str_in("append - source file text data co\n");
console_str_in(" py to destination file\n\n");
} else if (vm_string_equals_ignore_case(text22, "help") == 0 && strlen(text33) != 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "about") == 0 && strlen(text33) == 0) {
console_str_in(text3);
} else if (vm_string_equals_ignore_case(text22, "about") == 0 && strlen(text33) != 0) {
console_str_in(text88);
//} else if (vm_string_equals_ignore_case(text22, "dir") == 0 && strlen(text33) != 0) {
// dir filename
//} else if (vm_string_equals_ignore_case(text22, "dir") == 0 && strlen(text33) != 0) {
// dir directoryname
} else if (vm_string_equals_ignore_case(text22, "dir") == 0 && strlen(text33) == 0) {
create_search_path(fullPath2, fullPath1, "*.*");
test = 0;
hnd = vm_find_first_ext(fullPath2, &fileInfo);
vm_ucs2_to_ascii(text6, wstrlen(fileInfo.filefullname) + 1, fileInfo.filefullname);
if (fileInfo.attributes == VM_FS_ATTR_DIR) {
strcpy(text, "<DIR> ");
} else {
strcpy(text, "-r--- ");
}
strcat(text, text6);
strcat(text, "\n");
console_str_in(text);
strcpy(text6, "");
while (test == 0) {
test = vm_find_next_ext(hnd, &fileInfo);
if (test == 0) {
vm_ucs2_to_ascii(text6, wstrlen(fileInfo.filefullname) + 1, fileInfo.filefullname);
if (fileInfo.attributes == VM_FS_ATTR_DIR) {
strcpy(text, "<DIR> ");
} else {
strcpy(text, "-r--- ");
}
strcat(text, text6);
strcat(text, "\n");
console_str_in(text);
strcpy(text6, "");
}
}
console_str_in("\n");
vm_find_close_ext(hnd);
vm_find_close_ext(test);
} else if (vm_string_equals_ignore_case(text22, "cd") == 0 && vm_string_equals_ignore_case(text33, ".") == 0 || vm_string_equals_ignore_case(text22, "cd") == 0 && strlen(text33) == 0) {
vm_ucs2_to_ascii(text, wstrlen(fullPath1) + 1, fullPath1);
strcat(text, "\n\n");
console_str_in(text);
} else if (vm_string_equals_ignore_case(text22, "cd") == 0 && vm_string_equals_ignore_case(text33, "..") == 0) {
create_supdir_path(fullPath1, fullPath1);
vm_ucs2_to_ascii(text, wstrlen(fullPath1) + 1, fullPath1);
strcat(text, "\n\n");
console_str_in(text);
} else if (vm_string_equals_ignore_case(text22, "cd") == 0 && strlen(text33) != 0 && vm_string_equals_ignore_case(text33, "..") != 0 && vm_string_equals_ignore_case(text33, ".") != 0) {
strcpy(text, "The system cannot find the path specified.");
trim_left_symbols(text6, text33);
strcat(text6, "\\");
vm_ascii_to_ucs2(fullPath3, (strlen(text6) + 1) * 2, text6);
vm_wstrcpy(fullPath2, fullPath1);
vm_wstrcat(fullPath2, fullPath3);
if (vm_file_get_attributes(fullPath2) == VM_FS_ATTR_DIR) { // -1 file or directory not found
wstrcpy(fullPath1, fullPath2);
vm_ucs2_to_ascii(text, wstrlen(fullPath1) + 1, fullPath1);
}
strcat(text, "\n\n");
console_str_in(text);
} else if (vm_string_equals_ignore_case(text22, "cls") == 0 && strlen(text33) != 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "cls") == 0 && strlen(text33) == 0) {
if (my_intx > 471) {
console.clean_history();
my_intx = 0;
}
console.erase_display(2);
console.reset();
rrrrrrr = 0;
} else if (vm_string_equals_ignore_case(text22, "del") == 0 && strlen(text33) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "del") == 0 && strlen(text33) != 0 && strlen(text44) == 0) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1 || vm_file_get_attributes(fullPath2) != VM_FS_ATTR_DIR) {
vm_file_delete(fullPath2);
vm_ucs2_to_ascii(text, wstrlen(fullPath2) + 1, fullPath2);
strcat(text, " - OK");
strcat(text, "\n\n");
console_str_in(text);
} else {console_str_in("File not found !\n\n");}
} else if (vm_string_equals_ignore_case(text22, "mkdir") == 0 && strlen(text33) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "mkdir") == 0 && strlen(text33) != 0 && strlen(text44) == 0) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) == -1) {
vm_file_mkdir(fullPath2);
vm_ucs2_to_ascii(text, wstrlen(fullPath2) + 1, fullPath2);
strcat(text, " - OK");
strcat(text, "\n\n");
console_str_in(text);
} else {console_str_in("Fail, same directory or file exists !\n\n");}
} else if (vm_string_equals_ignore_case(text22, "rmdir") == 0 && strlen(text33) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "rmdir") == 0 && strlen(text33) != 0 && strlen(text44) == 0) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) == VM_FS_ATTR_DIR) {
vm_file_rmdir(fullPath2);
vm_ucs2_to_ascii(text, wstrlen(fullPath2) + 1, fullPath2);
strcat(text, " - OK");
strcat(text, "\n\n");
console_str_in(text);
} else {console_str_in("Directory not found !\n\n");}
} else if (vm_string_equals_ignore_case(text22, "rename") == 0 && strlen(text33) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "rename") == 0 && strlen(text33) != 0 && strlen(text44) != 0 && strlen(text55) == 0) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1) {
create_search_path(fullPath3, fullPath1, text44);
if (vm_file_get_attributes(fullPath3) == -1) {
vm_file_rename(fullPath2, fullPath3);
vm_ucs2_to_ascii(text, wstrlen(fullPath3) + 1, fullPath3);
strcat(text, " - OK");
strcat(text, "\n\n");
console_str_in(text);
}
} else {console_str_in("Name of source or destination is incorrect !\n\n");}
} else if (vm_string_equals_ignore_case(text22, "move") == 0 && strlen(text33) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "copy") == 0 && strlen(text33) == 0) {
console_str_in(text88);
//} else if (vm_string_equals_ignore_case(text22, "split") == 0 && strlen(text33) == 0) {
// console_str_in(text88);
//some code..
//} else if (vm_string_equals_ignore_case(text22, "start") == 0 && strlen(text33) == 0) {
// console_str_in(text88);
//some code..
//} else if (vm_string_equals_ignore_case(text22, "batch") == 0 && strlen(text33) == 0) {
// console_str_in(text88);
//some code..
} else if (vm_string_equals_ignore_case(text22, "append") == 0 && strlen(text33) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "path") == 0 && strlen(text33) == 0) {
vm_ucs2_to_ascii(text, wstrlen(fullPath1) + 1, fullPath1);
strcat(text, "\n\n");
console_str_in(text);
} else if (vm_string_equals_ignore_case(text22, "path") == 0 && strlen(text33) != 0 && strlen(text44) == 0) {
trim_left_symbols(text6, text33);
strcat(text6, "\\");
vm_ascii_to_ucs2(fullPath2, (strlen(text6) + 1) * 2, text6);
if (vm_file_get_attributes(fullPath2) == VM_FS_ATTR_DIR) {
wstrcpy(fullPath1, fullPath2);
vm_ucs2_to_ascii(text, wstrlen(fullPath1) + 1, fullPath1);
strcat(text, "\n\n");
console_str_in(text);
} else {console_str_in("Directory not found !\n\n");}
} else if (vm_string_equals_ignore_case(text22, "copy") == 0 && strlen(text33) != 0 && strlen(text44) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "copy") == 0 && strlen(text33) != 0 && strlen(text44) != 0 && strlen(text55) == 0) {
extract_path(my_path, text44);
lenght_555 = strlen(my_path);
lenght_666 = strlen(text44);
strcpy(text, "Name of source or destination is incorrect !\n\n");
if (lenght_555 == 0 && vm_string_equals_ignore_case(text33, text44) != 0) { //copy file1.txt file2.txt
create_search_path(fullPath2, fullPath1, text33); //source
if (vm_file_get_attributes(fullPath2) != -1) {
create_search_path(fullPath3, fullPath1, text44); //destination
if (vm_file_get_attributes(fullPath3) == -1) {
vm_file_copy(fullPath3, fullPath2, cb);
vm_ucs2_to_ascii(text, wstrlen(fullPath3) + 1, fullPath3);
strcat(text, " - OK");
strcat(text, "\n\n");
}
}
} else if (lenght_666 == lenght_555) { //copy file1.txt e:\
vm_ascii_to_ucs2(fullPath3, (strlen(my_path) + 1) * 2, my_path);
if (vm_file_get_attributes(fullPath3) == VM_FS_ATTR_DIR) {
create_search_path(fullPath4, fullPath3, text33);
if (vm_file_get_attributes(fullPath4) == -1) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1) {
vm_file_copy(fullPath4, fullPath2, cb);
vm_ucs2_to_ascii(text, wstrlen(fullPath4) + 1, fullPath4);
strcat(text, " - OK");
strcat(text, "\n\n");
}
}
}
} else {
strncpy(my_file_name, text44 + lenght_555, (lenght_666 - lenght_555)); //copy file1.txt e:\file2.txt
vm_ascii_to_ucs2(fullPath3, (strlen(my_path) + 1) * 2, my_path);
if (vm_file_get_attributes(fullPath3) == VM_FS_ATTR_DIR) {
create_search_path(fullPath4, fullPath3, my_file_name);
if (vm_file_get_attributes(fullPath4) == -1) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1) {
vm_file_copy(fullPath4, fullPath2, cb);
vm_ucs2_to_ascii(text, wstrlen(fullPath4) + 1, fullPath4);
strcat(text, " - OK");
strcat(text, "\n\n");
}
}
}
}
console_str_in(text);
} else if (vm_string_equals_ignore_case(text22, "append") == 0 && strlen(text33) != 0 && strlen(text44) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "append") == 0 && strlen(text33) != 0 && strlen(text44) != 0 && strlen(text55) == 0) {
extract_path(my_path, text44);
lenght_555 = strlen(my_path);
lenght_666 = strlen(text44);
strcpy(text, "Source or destination file not found !\n\n");
if (lenght_555 == 0 && vm_string_equals_ignore_case(text33, text44) != 0) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1 && vm_file_get_attributes(fullPath2) != VM_FS_ATTR_DIR) {
create_search_path(fullPath3, fullPath1, text44);
if (vm_file_get_attributes(fullPath3) != -1 && vm_file_get_attributes(fullPath3) != VM_FS_ATTR_DIR) {
f_read = vm_file_open(fullPath2, MODE_READ, FALSE);
f_write = vm_file_open(fullPath3, MODE_APPEND, FALSE);
while (!vm_file_is_eof(f_read)) {
vm_file_read(f_read, new_data, 2000, &nread);
new_data[nread] = '\0';
vm_file_write(f_write, new_data, strlen(new_data), &nread);
}
vm_file_close(f_read);
vm_file_close(f_write);
vm_ucs2_to_ascii(text, wstrlen(fullPath3) + 1, fullPath3);
strcat(text, " - OK");
strcat(text, "\n\n");
}
}
} else {
strncpy(my_file_name, text44 + lenght_555, (lenght_666 - lenght_555));
vm_ascii_to_ucs2(fullPath3, (strlen(my_path) + 1) * 2, my_path);
if (vm_file_get_attributes(fullPath3) == VM_FS_ATTR_DIR) {
create_search_path(fullPath4, fullPath3, my_file_name);
if (vm_file_get_attributes(fullPath4) != -1 && vm_file_get_attributes(fullPath4) != VM_FS_ATTR_DIR) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1 && vm_file_get_attributes(fullPath2) != VM_FS_ATTR_DIR) {
f_read = vm_file_open(fullPath2, MODE_READ, FALSE);
f_write = vm_file_open(fullPath4, MODE_APPEND, FALSE);
while (!vm_file_is_eof(f_read)) {
vm_file_read(f_read, new_data, 2000, &nread);
new_data[nread] = '\0';
vm_file_write(f_write, new_data, strlen(new_data), &nread);
}
vm_file_close(f_read);
vm_file_close(f_write);
vm_ucs2_to_ascii(text, wstrlen(fullPath4) + 1, fullPath4);
strcat(text, " - OK");
strcat(text, "\n\n");
}
}
}
}
console_str_in(text);
} else if (vm_string_equals_ignore_case(text22, "move") == 0 && strlen(text33) != 0 && strlen(text44) == 0) {
console_str_in(text88);
} else if (vm_string_equals_ignore_case(text22, "move") == 0 && strlen(text33) != 0 && strlen(text44) != 0 && strlen(text55) == 0) {
extract_path(my_path, text44);
lenght_555 = strlen(my_path);
lenght_666 = strlen(text44);
strcpy(text, "Name of source or destination is incorrect !\n\n");
if (lenght_555 == 0 && vm_string_equals_ignore_case(text33, text44) != 0) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1) {
create_search_path(fullPath3, fullPath1, text44);
if (vm_file_get_attributes(fullPath3) == -1) {
vm_file_copy(fullPath3, fullPath2, cb);
vm_file_delete(fullPath2);
vm_ucs2_to_ascii(text, wstrlen(fullPath3) + 1, fullPath3);
strcat(text, " - OK");
strcat(text, "\n\n");
}
}
} else if (lenght_666 == lenght_555) {
vm_ascii_to_ucs2(fullPath3, (strlen(my_path) + 1) * 2, my_path);
if (vm_file_get_attributes(fullPath3) == VM_FS_ATTR_DIR) {
create_search_path(fullPath4, fullPath3, text33);
if (vm_file_get_attributes(fullPath4) == -1) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1) {
vm_file_copy(fullPath4, fullPath2, cb);
vm_file_delete(fullPath2);
vm_ucs2_to_ascii(text, wstrlen(fullPath4) + 1, fullPath4);
strcat(text, " - OK");
strcat(text, "\n\n");
}
}
}
} else {
strncpy(my_file_name, text44 + lenght_555, (lenght_666 - lenght_555));
vm_ascii_to_ucs2(fullPath3, (strlen(my_path) + 1) * 2, my_path);
if (vm_file_get_attributes(fullPath3) == VM_FS_ATTR_DIR) {
create_search_path(fullPath4, fullPath3, my_file_name);
if (vm_file_get_attributes(fullPath4) == -1) {
create_search_path(fullPath2, fullPath1, text33);
if (vm_file_get_attributes(fullPath2) != -1) {
vm_file_copy(fullPath4, fullPath2, cb);
vm_file_delete(fullPath2);
vm_ucs2_to_ascii(text, wstrlen(fullPath4) + 1, fullPath4);
strcat(text, " - OK");
strcat(text, "\n\n");
}
}
}
}
console_str_in(text);
} else if (strlen(text11) != 0) {
sprintf(text, "%s is not recognized as an internal or external command, operable program or batch file.\n\n", text11);
console_str_in(text);
} else {
}
// Free the buffer
t2input.free_buffer();
strcpy(text11, "");
strcpy(text, "");
strcpy(text22, "");
strcpy(text33, "");
strcpy(text44, "");
strcpy(text55, "");
strcpy(text222, "");
strcpy(text333, "");
strcpy(text444, "");
strcpy(my_file_name, "");
strcpy(my_path, "");
strcpy(text6, "");
strcpy(new_data, "");
lenght_555 = 0;
lenght_666 = 0;
//vm_wstrcpy(fullPath2, "");
//wvm_wstrcpy(fullPath3, "");
//vm_wstrcpy(fullPath4, "");
port = -3;
// port = -1;
//} else if (port == -1 && t2input.input_done == 1){
// port = strtoi(t2input.str_buf); // Convert port to number
// if (port < 0) {
// Invaild port or number
// console_str_in("\nInvaild port! Please enter the port: ");
// Free the buffer
// t2input.free_buffer();
//} else {
// telnet.connect_to(ip, port); // Try connecting to host
// timeout_timer_id = vm_create_timer(1000, timeout_f);
// vm_delete_timer(prompt_timer_id); // Remove the prompt
//}
}
}
void handle_sysevt(VMINT message, VMINT param) {
switch (message) {
case VM_MSG_CREATE:
case VM_MSG_ACTIVE:
layer_hdls[0] = vm_graphic_create_layer(0, 0, scr_w, scr_h, -1);
layer_hdls[1] = vm_graphic_create_layer(0, 0, scr_w, scr_h, tr_color);
vm_graphic_set_clip(0, 0, scr_w, scr_h);
layer_bufs[0]=vm_graphic_get_layer_buffer(layer_hdls[0]);
layer_bufs[1]=vm_graphic_get_layer_buffer(layer_hdls[1]);
vm_switch_power_saving_mode(turn_off_mode);
console.scr_buf=layer_bufs[0];
console.draw_all();
t2input.scr_buf=layer_bufs[1];
t2input.layer_handle=layer_hdls[1];
if(message == VM_MSG_CREATE){ //only when app start
// Prompt for host & port to connect
t2input.input_mode = 1; // Get input from keyboard to buffer
//console_str_in("Welcome to Telnet Client\n");
//console_str_in("Written by Ximik_Boda & TelnetVXP contributors\n");
if (flightMode == VM_TRUE) {
console_str_in("Turn off flight mode !\n");
vm_create_timer_ex(3000,timer1);
} else if (missingConfigFile == VM_TRUE) {
console_str_in(text3);
prompt_timer_id = vm_create_timer(1000, prompt); // Check the prompt for every 1 second
} else if (missingConfigFile == VM_FALSE) {
prompt_timer_id = vm_create_timer(1000, prompt); // Check the prompt for every 1 second
strcpy(t2input.str_buf, command);
t2input.send_c("\r\n");
} else {
sprintf(port1, "%d", port);
console_str_in("Opening: ");
console_str_in(ip);
console_str_in(":");
console_str_in(port1);
//telnet.connect_to(ip, port); // Try connecting to host
timeout_timer_id = vm_create_timer(1000, timeout_f);
}
}
if(main_timer_id==-1)
main_timer_id = vm_create_timer(1000/15, timer); //15 fps
break;
case VM_MSG_PAINT:
draw();
break;
case VM_MSG_INACTIVE:
vm_switch_power_saving_mode(turn_on_mode);
if( layer_hdls[0] != -1 ){
vm_graphic_delete_layer(layer_hdls[0]);
vm_graphic_delete_layer(layer_hdls[1]);
}
if(main_timer_id!=-1)
vm_delete_timer(main_timer_id);
break; case VM_MSG_QUIT:
if( layer_hdls[0] != -1 ){
vm_graphic_delete_layer(layer_hdls[0]);
vm_graphic_delete_layer(layer_hdls[1]);
}
if(main_timer_id!=-1)
vm_delete_timer(main_timer_id);
break;
}
}
void handle_keyevt(VMINT event, VMINT keycode) {
#ifdef WIN32
if(keycode>=VM_KEY_NUM1&&keycode<=VM_KEY_NUM3)
keycode+=6;
else if(keycode>=VM_KEY_NUM7&&keycode<=VM_KEY_NUM9)
keycode-=6;
#endif
//if (event == VM_KEY_EVENT_UP && keycode == VM_KEY_RIGHT_SOFTKEY) {
// if (layer_hdls[0] != -1) {
// vm_graphic_delete_layer(layer_hdls[0]);
// layer_hdls[0] = -1;
// }
// vm_exit_app();
//}
t2input.handle_keyevt(event, keycode);
}
/*
void handle_penevt(VMINT event, VMINT x, VMINT y){
t2input.handle_penevt(event, x, y);
draw();
}
*/
void create_app_txt_path(VMWSTR text, VMSTR extt) {
VMWCHAR fullPath[100];
VMWCHAR wfile_extension[4];
vm_get_exec_filename(fullPath);
vm_ascii_to_ucs2(wfile_extension, 8, extt);
vm_wstrncpy(text, fullPath, vm_wstrlen(fullPath) - 3);
vm_wstrcat(text, wfile_extension);
}
void checkFileExist(void) {
VMFILE f_read;
VMUINT nread;
VMWCHAR file_pathw[100];
VMCHAR new_data[500];
create_app_txt_path(file_pathw, "txt");
f_read = vm_file_open(file_pathw, MODE_READ, FALSE);
if (f_read < 0) {
vm_file_close(f_read);
missingConfigFile = VM_TRUE;
} else {
vm_file_read(f_read, new_data, 500, &nread);
new_data[nread] = '\0';
vm_file_close(f_read);
if (strlen(new_data) > 1) {
parseText(new_data);
missingConfigFile = VM_FALSE;
} else {
missingConfigFile = VM_TRUE;
}
}
}
VMINT parseText(VMSTR text) {
VMCHAR vns_simbl[2] = {};
VMCHAR nauj_strng[100] = {};
VMINT counter = 0;
VMINT counter1 = 0;
VMCHAR *ptr;
//VMCHAR command[100] = {};
//VMCHAR ip[100] = {};
//VMCHAR portx[100] = {};
//VMCHAR login[100] = {};
//VMCHAR password[100] = {};
ptr = text;
while (*ptr != '\0' || counter1 == 5) {
if (*ptr == '\r') {ptr++;}
if (*ptr == '\n') {
counter = counter + 1;
if (counter == 1) {strcpy(command, nauj_strng);}
if (counter == 2) {strcpy(ip, nauj_strng);}
//if (counter == 3) {port = strtoi(nauj_strng);}
if (counter == 3) {strcpy(portx, nauj_strng);}
if (counter == 4) {strcpy(login, nauj_strng);}
if (counter == 5) {strcpy(password, nauj_strng);}
counter1 = counter;
strcpy(nauj_strng, "");
ptr++;
}
sprintf(vns_simbl, "%c", *ptr);
strcat(nauj_strng, vns_simbl);