-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjag.cxx
executable file
·4252 lines (3757 loc) · 129 KB
/
jag.cxx
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
/*
* Tamgu (탐구)
*
* Copyright 2019-present NAVER Corp.
* under BSD 3-clause
*/
/* --- CONTENTS ---
Project : Tamgu (탐구)
Version : See tamgu.cxx for the version number
filename : jag.cxx
Date : 2019/03/25
Purpose : Main of Jag (작) executable
Programmer : Claude ROUX (claude.roux@naverlabs.com)
Reviewer :
*/
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
#ifdef WIN32
#include "conversion.h"
#include <conio.h>
#include <ctype.h>
//Handling console tune up
#ifdef DOSOUTPUT
static bool dosoutput = false;
void Setdosoutput(bool d) { dosoutput = d; }
bool isDosOutput() {
return dosoutput;
}
string conversiontodos(char* c) {
if (dosoutput)
return s_utf8_to_dos(c);
return c;
}
#endif
#else
#include <unistd.h> //_getch
#include <termios.h> //_getch
#include <sys/ioctl.h>
#endif
#include <signal.h>
#include <iomanip>
#include <string>
#include "conversion.h"
#include "x_tokenize.h"
#include "jagrgx.h"
#include <iomanip>
#include "jag.h"
bool check_large_char(wchar_t* src, long lensrc, long& i);
#ifdef WIN32
//these methods have been implemented in tamgusys.cxx
void ResetWindowsConsole();
void Getscreensizes();
bool checkresize();
void Returnscreensize(long& rs, long& cs, long& sr, long& sc);
#endif
#ifdef APPLE_COPY
void quoted_string(string& value) {
if (value == "")
return;
value = s_replacestrings(value, "\\", "\\\\");
value = s_replacestrings(value, "\"", "\\\"");
value = s_replacestrings(value, "\\t", "\\\\t");
value = s_replacestrings(value, "\\n", "\\\\n");
value = s_replacestrings(value, "\\r", "\\\\r");
}
string exec_command(const char* cmd) {
FILE* pipe = popen(cmd, "r");
if (!pipe)
return "";
char buffer[256];
string result = "";
while(!feof(pipe))
{
if(fgets(buffer, 256, pipe) != NULL)
{
result += buffer;
}
}
pclose(pipe);
return result;
}
string paste_from_clipboard() {
return exec_command("pbpaste");
}
void copy_to_clipboard(string buffer) {
quoted_string(buffer);
stringstream cmd;
cmd << "echo \"" << STR(buffer) << "\" | pbcopy";
exec_command(cmd.str().c_str());
}
#else
string paste_from_clipboard() {
return "";
}
void copy_to_clipboard(string buffer) {}
#endif
static char m_scrollmargin[] = { 27, 91, '0', '0', '0', ';', '0', '0','0', 'r', 0 };
static char m_right[] = {27, '[', '0', '0', '1', 67, 0};
char m_down[] = {27, '[', '0', '0', '1', 66, 0};
//Moving to a specific line/column
char sys_row_column[] = { 27, 91, '0', '0', '0', ';', '0', '0','0', 'H', 0 };
static const char* localn999[] = { "000","001","002","003","004","005","006","007","008","009","010","011","012","013","014","015","016","017","018","019","020","021","022","023","024","025","026","027","028","029","030","031","032","033","034","035","036","037","038","039","040","041","042","043","044","045","046","047","048","049","050","051","052","053","054","055","056","057","058","059","060","061","062","063","064","065","066","067","068","069","070","071","072","073","074","075","076","077","078","079","080","081","082","083","084","085","086","087","088","089","090","091","092","093","094","095","096","097","098","099","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" };
static const char* _keywords[] = { "GPSdistance","True", "False","None","def","char","import","double","wstring","Maybe","Nothing","_breakpoint","_dependencies","_erroronkey","_eval","_evalfunction","_exit","_forcelocks","_getdefaulttokenizerules","_info","_initial","_mirrordisplay","_nbthreads","_poolstats","_setenv","_setmaxrange","_setmaxthreads","_setstacksize","_setvalidfeatures","_stdin","_symbols","_threadhandle","_threadid","a_bool","a_change","a_delete","a_features","a_first","a_float","a_fvector","a_insert","a_int","a_ivector","a_longest","a_mapff","a_mapfi","a_mapfs","a_mapfu","a_mapif","a_mapii","a_mapis","a_mapiu","a_mapsf","a_mapsi","a_mapss","a_mapuf","a_mapui","a_mapuu","a_nocase","a_offsets","a_random","a_repetition","a_string","a_surface","a_svector","a_switch","a_ustring","a_uvector","a_vector","a_vowel","abs","absent","acos","acosh","activate","add","addchild","addnext","addprevious","addstyle","after","alert","align","all","allobjects","and","annotate","annotator","any","aopen","append","apply","arc","asin","asinh","ask","assert","asserta","assertz","atan","atanh","attributes","autorun","backgroundcolor","barcolor","base","before","begin","begincomplexpolygon","beginline","beginloop","beginpoints","beginpolygon","binmap","binmapf","binmapi","binmapl","binmaps","binmapu","bit","bitmap","bits","block","blocking","bloop","bool","border","boundaries","bounds","box","boxtype","break","browser","buffersize","build","button","bvector","byte","byteposition","bytes","call","case","cast","catch","cbrt","cell","cellalign","cellalignheadercol","cellalignheaderrow","charposition","check","checklabel","checkword","child","children","choice","chr","circle","clear","close","color","colorbg","colorfg","column","columnchar","columnheader","columnheaderwidth","columnwidth","command","commit","common","compact","compile","compilelexicons","compilergx","concept","connect","const","constmap","constvector","content","continue","copy","cos","cosh","count","counter","create","created","createdirectory","createserver","curl","current","cursor","cursorchar","cursorstyle","curve","cut","cycle","data","date","day","deaccentuate","decimal","decode","default","definitions","degree","delete","dependencies","dependency","deriving","deselect","determinant","dimension","dloop","do","document","dos","dostoutf8","doublemetaphone","drawcolor","drawtext","drop","dropWhile","dthrough","dvector","e_arabic","e_baltic","e_celtic","e_cp1252","e_cyrillic","e_greek","e_hebrew","e_latin_ce","e_latin_ffe","e_latin_ne","e_latin_se","e_latin_see","e_latin_we","e_nordic","e_thai","e_turkish","e_windows","editdistance","editor","elif","else","emoji","emojis","empty","encode","end","endcomplexpolygon","endian","endline","endloop","endpoints","endpolygon","env","eof","erf","erfc","evaluate","even","exclusive","execute","exit","exp","exp2","expm1","exponent","extension","extract","factorize","factors","fail","false","features","fibre","file","filebrowser","fileinfo","fill","filter","find","findall","first","flatten","flip","float","floop","floor","flush","fmatrix","focus","foldl","foldr","font","fontnumber","fontsize","for","format","formatchar","fraction","frame","frameinstance","from","fthrough","function","fvector","gap","get","geterr","getfont","getfontsizes","gethostname","getpeername","getstd","getstyle","gotoline","grammar","grammar_macros","group","hash","hide","highlight","hour","html","hvector","id","if","ifnot","iloop","image","imatrix","in","indent","info","initializefonts","insert","insertbind","int","invert","is","isa","isalpha","isconsonant","iscontainer","isdigit","isdirectory","isemoji","ishangul","isjamo","islower","ismap","isnumber","isprime","ispunctuation","isstring","isupper","isutf8","isvector","isvowel","items","iterator","ithrough","ivector","jamo","join","joined","json","key","keys","kget","label","labelcolor","labelfont","labels","labelsize","labeltype","last","latin","leaves","left","length","let","levenshtein","lexicon","lgamma","line","linebounds","linecharbounds","lineshape","lisp","list","listdirectory","lloop","ln","load","loadfacts","loadgif","loadin","loadjpeg","lock","log","log1p","log2","logb","long","lookdown","lookup","loop","lower","ls","lstep","lthrough","lvector","mantissa","map","mapf","mapff","mapfi","mapfl","mapfs","mapfu","mapi","mapif","mapii","mapis","mapiu","mapl","maplf","mapll","mapls","maplu","mapsf","mapsi","mapsl","mapss","mapu","mapuf","mapui","mapul","mapuu","mark","match","max","maximum","memory","menu","merge","method","methods","mid","min","minimum","minute","mkdir","modal","month","mp3","mthrough","multisplit","multmatrix","name","namespace","nbchildren","nd","nearbyint","new","next","ngrams","node","nope","normalizehangul","not","notin","null","odd","of","ok","onclose","onclosing","ondragdrop","onhscroll","onkey","onmouse","ontime","ontology","onvscroll","open","openappend","openread","openwrite","options","or","ord","otherwise","padding","parameters","parent","parse","password","paste","pause","permute","pie","play","plot","plotcoords","point","polygon","polynomial","ponder","pop","popclip","popfirst","poplast","popmatrix","port","position","post","precede","pred","predicate","predicatedump","predicatevar","preg","previous","primemap","primemapf","primemapff","primemapfi","primemapfl","primemapfs","primemapfu","primemapi","primemapif","primemapii","primemapis","primemapiu","primemapl","primemaplf","primemapll","primemapls","primemaplu","primemapsf","primemapsi","primemapsl","primemapss","primemapu","primemapuf","primemapui","primemapul","primemapuu","print","printerr","printj","printjerr","printjln","printjlnerr","println","printlnerr","private","product","progress","properties","property","protected","proxy","push","pushclip","pushfirst","pushlast","pushmatrix","radian","raise","random","range","rawstring","read","readline","real","realpath","receive","rectangle","rectanglefill","redirectoutput","redraw","redrawing","remove","removefirst","removelast","repeat","replace","replaceall","replicate","reserve","reset","resizable","resize","restateoutput","retract","retractall","return","reverse","rfind","rgbcolor","right","ring","rint","role","romanization","root","ropen","rotate","rotation","round","row","rowheader","rowheaderheight","rowheight","rule","run","save","scale","scan","scanl","scanr","scrollbar","second","seek","select","selection","selectioncolor","self","send","serialize","serializestring","setdate","setstyle","settimeout","short","shortcut","show","shuffle","sibling","signature","simplify","sin","sinh","sisters","size","sizeb","sizerange","sleep","slice","slider","sloop","socket","sort","sortfloat","sortint","sortstring","sortustring","sound","spans","split","splite","sqlite","sqrt","static","step","steps","sthrough","stokenize","stop","store","strict","string","succ","succeed","sum","svector","switch","synode","sys","table","tabs","tags","take","takeWhile","tamgu","tan","tanh","tell","term","test","textcolor","textsize","tgamma","this","thread","time","tohtml","token","tokenize","tokens","tooltip","toxml","trace","transducer","transformdx","transformdy","transformedvertex","transformx","transformy","translate","transpose","treemap","treemapf","treemapff","treemapfi","treemapfl","treemapfs","treemapfu","treemapi","treemapif","treemapii","treemapis","treemapiu","treemapl","treemaplf","treemapll","treemapls","treemaplu","treemapsf","treemapsi","treemapsl","treemapss","treemapu","treemapuf","treemapui","treemapul","treemapuu","treg","trim","trimleft","trimright","true","trunc","try","type","ufile","uloop","unblock","unget","unhighlight","unique","unlink","unlock","unmark","upper","url","use","ustring","utf8","uthrough","uvector","value","values","vector","version","vertex","vthrough","wait","waitonfalse","waitonjoined","weekday","wfile","when","where","while","window","winput","with","wopen","word","words","woutput","wrap","write","writebin","writeln","writeutf16","wtable","xml","xmldoc","xmlstring","xmltype","xor","xpath","year","yearday","zip","zipWith","∏","∑","√","∛","define", "ifdef", "endif", "include", "defun", "lambda", "cons", "cond", "eq", "car", "cdr", "list", "append", ""};
static void moveto_row_column(long r, long c) {
sys_row_column[2] = localn999[r][0];
sys_row_column[3] = localn999[r][1];
sys_row_column[4] = localn999[r][2];
sys_row_column[6] = localn999[c][0];
sys_row_column[7] = localn999[c][1];
sys_row_column[8] = localn999[c][2];
cout << sys_row_column;
}
void jag_editor::displaythehelp(long noclear) {
if (!noclear) {
cout << m_clear << m_clear_scrolling << m_home;
cerr << m_redital << "jag editor help" << m_current << endl << endl;
}
cerr << " " << m_redbold << "Commands" << m_current << endl;
cerr << " \t- " << m_redbold << "Ctrl-k:" << m_current << " delete from cursor up to the end of the line" << endl;
cerr << " \t- " << m_redbold << "Ctrl-d:" << m_current << " delete a full line" << endl;
cerr << " \t- " << m_redbold << "Ctrl-p:" << m_current << " insert k-buffer (from Ctrl-d or Ctrl-k)" << endl;
cerr << " \t- " << m_redbold << "Ctrl-u:" << m_current << " undo last modifications" << endl;
cerr << " \t- " << m_redbold << "Ctrl-r:" << m_current << " redo last modifications" << endl;
cerr << " \t- " << m_redbold << "Ctrl-f:" << m_current << " find a string (on the same line: " << m_redital << "Ctrl-r" << m_current <<" for replacement)" << endl;
cerr << " \t- " << m_redbold << "Ctrl-n:" << m_current << " find next" << endl;
cerr << " \t- " << m_redbold << "Ctrl-g:" << m_current << " move to a specific line, '$' is the end of the code" << endl;
cerr << " \t- " << m_redbold << "Ctrl-l:" << m_current << " toggle between top and bottom of the screen" << endl;
cerr << " \t- " << m_redbold << "Ctrl-t:" << m_current << " reindent the code" << endl;
cerr << " \t- " << m_redbold << "Ctrl-h:" << m_current << " local help" << endl;
cerr << " \t- " << m_redbold << "Ctrl-w:" << m_current << " write file to disk" << endl;
cerr << " \t- " << m_redbold << "Ctrl-c:" << m_current << " exit the editor" << endl;
cerr << " \t- " << m_redbold << "Ctrl-x:" << m_redital << " Combined Commands" << m_current << endl;
cerr << " \t\t- " << m_redital << "C:" << m_current << " count a pattern" << endl;
cerr << " \t\t- " << m_redital << "P:" << m_current << " find with a POSIX Regular Expression" << endl;
cerr << " \t\t- " << m_redital << "R:" << m_current << " find with a Tamgu Regular Expression" << endl;
cerr << " \t\t- " << m_redital << "f:" << m_current << " find with previous find string" << endl;
cerr << " \t\t- " << m_redital << "m:" << m_current << " toggle mouse on/off" << endl;
cerr << " \t\t- " << m_redital << "H:" << m_current << " convert HTML entities to Unicode characters" << endl;
cerr << " \t\t- " << m_redital << "D:" << m_current << " delete a bloc of lines" << endl;
cerr << " \t\t- " << m_redital << "n:" << m_current << " hide/display line numbers" << endl;
cerr << " \t\t- " << m_redital << "c:" << m_current << " copy a bloc of lines" << endl;
cerr << " \t\t- " << m_redital << "x:" << m_current << " cut a bloc of lines" << endl;
cerr << " \t\t- " << m_redital << "v:" << m_current << " paste a bloc of lines" << endl;
cerr << " \t\t- " << m_redital << "w:" << m_current << " write and quit" << endl;
cerr << " \t\t- " << m_redital << "l:" << m_current << " load a file" << endl;
cerr << " \t\t- " << m_redital << "b:" << m_current << " black mode (better suited for black background)" << endl;
cerr << " \t\t- " << m_redital << "h:" << m_current << " full help" << endl;
cerr << " \t\t- " << m_redital << "q:" << m_current << " quit" << endl << endl;
cerr << " " << m_redbold << e_regular_expressions_for << m_redital << "'find'" << m_current << endl;
cerr << " \t- " << m_redbold << "%d" << m_current <<"\t\tstands for any digit" << m_current << endl;
cerr << " \t- " << m_redbold << "%x" << m_current <<"\t\tstands for a hexadecimal digit (abcdef0123456789ABCDEF)" << m_current << endl;
cerr << " \t- " << m_redbold << "%p" << m_current <<"\t\tstands for any punctuation" << m_current << endl;
cerr << " \t- " << m_redbold << "%c" << m_current <<"\t\tstands for any lower case letter" << m_current << endl;
cerr << " \t- " << m_redbold << "%C" << m_current <<"\t\tstands for any upper case letter" << m_current << endl;
cerr << " \t- " << m_redbold << "%a" << m_current <<"\t\tstands for any letter" << m_current << endl;
cerr << " \t- " << m_redbold << "?" << m_current <<"\t\tstands for any character" << m_current << endl;
cerr << " \t- " << m_redbold << "%?" << m_current <<"\t\tstand for the character “?” itself" << m_current << endl;
cerr << " \t- " << m_redbold << "%%" << m_current <<"\t\tstand for the character “%” itself" << m_current << endl;
cerr << " \t- " << m_redbold << "%s" << m_current <<"\t\tstand for any space character include the non-breaking space" << m_current << endl;
cerr << " \t- " << m_redbold << "%r" << m_current <<"\t\tstand a carriage return" << m_current << endl;
cerr << " \t- " << m_redbold << "%n" << m_current <<"\t\tstand for a non-breaking space" << m_current << endl;
cerr << " \t- " << m_redbold << "~" << m_current <<"\t\tnegation" << m_current << endl;
cerr << " \t- " << m_redbold << "\\x" << m_current <<"\t\tescape character" << m_current << endl;
cerr << " \t- " << m_redbold << "\\ddd" << m_current <<"\t\tcharacter code across 3 digits exactly" << m_current << endl;
cerr << " \t- " << m_redbold << "\\xFFFF" << m_current <<"\tcharacter code across 4 hexas exactly" << m_current << endl;
cerr << " \t- " << m_redbold << "{a-z}" << m_current <<"\t\tbetween a and z included" << m_current << endl;
cerr << " \t- " << m_redbold << "[a-z]" << m_current <<"\t\tsequence of characters" << m_current << endl;
cerr << " \t- " << m_redbold << "^" << m_current <<"\t\tthe expression should start at the beginning of the string" << m_current << endl;
cerr << " \t- " << m_redbold << "$" << m_current <<"\t\tthe expression should match up to the end of the string" << m_current << endl << endl;
cerr << " " << m_redbold << "Examples:" << m_current << endl;
cerr << " \t- " << m_redbold << "dog%c matches dogs or dogg" << m_current << endl;
cerr << " \t- " << m_redbold << "m%d matches m0, m1,…,m9" << m_current << endl;
cerr << " \t- " << m_redbold << "{%dab} matches 1, a, 2, b" << m_current << endl;
cerr << " \t- " << m_redbold << "{%dab}+ matches 1111a, a22a90ab" << m_current << endl;
}
//--------------------------------------------------------
static void keywords(hmap<string,bool>& names) {
for (int i = 0; _keywords[i][0] != 0; i++)
names[_keywords[i]]=true;
}
//--------------------------------------------------------
static const short _getbuffsize = 128;
static int xcursor = 0, ycursor = 0;
static int getxcursor() {
return xcursor;
}
static int getycursor() {
return ycursor;
}
static bool checkcar(wchar_t c) {
if (c <= 32)
return false;
switch (c) {
case '(':
case ')':
case ']':
case '{':
case '}':
case '"':
case ':':
case ',':
case ';':
return false;
default:
return true;
}
}
static void scrollingdown(long rowsize) {
char buff[] = { 0,0,0,0,0,0 };
sprintf_s(buff, 4, "%0.3ld", rowsize + 1);
m_scrollmargin[6] = buff[0];
m_scrollmargin[7] = buff[1];
m_scrollmargin[8] = buff[2];
cout << m_scrollmargin << m_scrolldown;
sprintf_s(buff, 4, "%0.3ld", rowsize + 2);
m_scrollmargin[6] = buff[0];
m_scrollmargin[7] = buff[1];
m_scrollmargin[8] = buff[2];
cout << m_scrollmargin;
}
#ifdef WIN32
static char check_size_utf8(int utf) {
if ((utf & 0xF0) == 0xF0)
return 3;
if ((utf & 0xE0) == 0xE0)
return 2;
if ((utf & 0xC0) == 0xC0)
return 1;
return 0;
}
string getwinchar(void(*f)());
void resizewindow();
string jag_editor::getch() {
return getwinchar(resizewindow);
}
#else
string jag_editor::getch(){
static char buf[_getbuffsize+2];
memset(buf,0, _getbuffsize);
struct termios old={0};
fflush(stdout);
if(tcgetattr(0, &old)<0) {
perror("tcsetattr()");
exit(-1);
}
old.c_lflag&=~ICANON;
old.c_lflag&=~ECHO;
old.c_cc[VMIN]=1;
old.c_cc[VTIME]=0;
if(tcsetattr(0, TCSANOW, &old)<0) {
perror("tcsetattr ICANON");
return "";
}
//If you need to get the absolute cursor position, you can decomment these lines
//cout << cursor_position;
//scanf("\033[%d;%dR", &xcursor, &ycursor);
string res;
long nb;
do {
nb = read(0,buf,_getbuffsize);
if (nb < 0)
perror("read()");
buf[nb] = 0;
res += buf;
memset(buf,0, _getbuffsize);
}
while (nb == _getbuffsize);
old.c_lflag|=ICANON;
if (!isMouseAction(res))
old.c_lflag|=ECHO;
if(tcsetattr(0, TCSADRAIN, &old)<0) {
perror ("tcsetattr ~ICANON");
return "";
}
return res;
}
#endif
//--------------------------------------------------------
void jag_editor::indentplus() {
wstring blanks(GetBlankSize(), ' ');
tobesaved = true;
if (selected_pos != -1 && selected_posnext > selected_pos) {
uchar modif = u_modif;
for (long i = selected_posnext - 1; i >= selected_pos; i--) {
line = lines[i];
line = blanks + line;
undo(lines[i],i, modif);
modif = u_modif_linked;
lines[i] = line;
}
selectlines(selected_pos, selected_posnext, selected_x, selected_y);
return;
}
line = lines[pos];
line = blanks + line;
undo(lines[pos],pos, u_modif);
lines[pos] = line;
printline(pos, line, -1);
movetoline(currentline);
movetoposition();
}
void jag_editor::deindentminus() {
//We remove some blanks from lines...
long nb = GetBlankSize();
long u = 0;
if (selected_pos != -1 && selected_posnext > selected_pos) {
uchar modif = u_modif;
for (long i = selected_posnext - 1; i >= selected_pos; i--) {
line = lines[i];
//can we remove nb blanks from the beginning of the line
u = 0;
for (; u < line.size() && line[u] == ' '; u++) {}
if (u >= nb) {
tobesaved = true;
line = line.substr(nb, line.size());
undo(lines[i],i, modif);
modif = u_modif_linked;
lines[i] = line;
}
}
selectlines(selected_pos, selected_posnext, selected_x, selected_y);
return;
}
line = lines[pos];
for (; u < line.size() && line[u] == ' '; u++) {}
if (u >= nb) {
tobesaved = true;
long sz = line.size();
line = line.substr(nb, line.size());
undo(lines[pos],pos, u_modif);
lines[pos] = line;
wstring blanks(sz, ' ');
printline(pos, blanks, -1);
printline(pos, line, -1);
movetoline(currentline);
movetoposition();
}
}
void jag_editor::colorring(string& txt, vector<long>& limits) {
static hmap<string,bool> keys;
static x_coloringrule color_tok;
static tokenizer_result<string> xr;
static bool init=false;
if (txt == "")
return;
if (!init) {
init=true;
keywords(keys);
}
long sztxt = txt.size();
txt += "\n";
color_tok.tokenize<string>(txt, xr);
txt.pop_back();
char type;
long gauche,droite,i;
long sz=xr.stack.size();
string sub;
for (i=0;i<sz;i++) {
type=xr.stacktype[i];
gauche=xr.bpos[i];
droite = gauche + xr.stack[i].size();
if (droite > sztxt)
droite = sztxt;
switch(type) {
case 1:
case 2:
case 3:
//strings
limits.push_back(type);
limits.push_back(gauche);
limits.push_back(droite);
break;
case 4://regular token
if (keys.find(xr.stack[i])!=keys.end()) {
limits.push_back(5);
limits.push_back(gauche);
limits.push_back(droite);
break;
}
break;
case 5://comments
limits.push_back(7);
limits.push_back(gauche);
limits.push_back(droite);
break;
case 10:
//special variables: #d+ ?label $d+
limits.push_back(8);
limits.push_back(gauche);
limits.push_back(droite);
break;
case 11:
// .method(
limits.push_back(4);
limits.push_back(gauche+1);
limits.push_back(droite-1);
break;
case 12:
// function(
sub=xr.stack[i].substr(0,xr.stack[i].size()-1);
if (keys.find(sub)!=keys.end()) {
limits.push_back(5);
limits.push_back(gauche);
limits.push_back(droite-1);
break;
}
limits.push_back(6);
limits.push_back(gauche);
limits.push_back(droite-1);
break;
case 13:
// <function
sub=xr.stack[i].substr(1,xr.stack[i].size()-1);
if (keys.find(sub)!=keys.end()) {
limits.push_back(5);
limits.push_back(gauche);
limits.push_back(droite-1);
break;
}
limits.push_back(6);
limits.push_back(gauche+1);
limits.push_back(droite);
break;
case 14:
//annotation lexicon head rule
sub=xr.stack[i];
limits.push_back(6);
limits.push_back(gauche);
limits.push_back(droite);
break;
}
}
}
///------------------------------------------------------------------------------------
//We check if the buffer ends in an incomplete utf8 character...
//In that case, we remove the ending and return it as a value to be added later
bool jag_editor::check_utf8(string& buff, string& buffer) {
long sz = buff.size()-1;
unsigned char utf[4];
utf[2] = buff[sz];
utf[1] = buff[sz-1];
utf[0] = buff[sz-2];
if (utf[2] < 0x80)
return false;
if ((utf[2] & 0xF0)== 0xF0 || (utf[2] & 0xE0) == 0xE0 || (utf[2] & 0xC0) == 0xC0) {
buff = buff.substr(0, sz);
buffer = utf[2];
return true;
}
if ((utf[2] & 0xC0) == 0xC0)
return false;
if ((utf[1] & 0xF0) == 0xF0 || (utf[1] & 0xE0) == 0xE0) {
buff = buff.substr(0, sz - 1);
buffer = utf[1];
buffer += utf[2];
return true;
}
if ((utf[0] & 0xE0)== 0xE0)
return false;
if ((utf[0] & 0xF0)== 0xF0) {
buff = buff.substr(0, sz - 2);
buffer = utf[1];
buffer += utf[2];
buffer += utf[3];
return true;
}
return false;
}
static void convertmeta(wstring& w, wstring& wsub) {
Au_automate a("{[%%%x%x][&%c+;][&#%d+;][u%x%x%x%x][\\u%x%x%x%x][\\%d%d%d][\\?]}");
vector<long> vectr;
a.searchall(wsub,vectr);
if (vectr.size()==0) {
w=wsub;
return;
}
w=wsub;
wstring s;
for (long i=vectr.size()-2;i>=0; i-=2) {
s=wsub.substr(vectr[i], vectr[i+1]-vectr[i]);
s_EvaluateMetaCharacters(s);
w=w.substr(0,vectr[i])+s+w.substr(vectr[i+1],w.size()-vectr[i+1]);
}
}
//The actual size of the displayed string, the problem here is that multibyte characters are sometimes displayed with an extra-space...
//Especially for CJK characters.... (Chinese, Japanese, Korean)... We need to integrate this extra-space into our calculus...
//Lines extracted from the function "mk_wcwidth": https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
static inline bool ckjchar(wchar_t ucs) {
return
(ucs >= 0x1100 &&
(ucs <= 0x115f || /* Hangul Jamo init. consonants */
ucs == 0x2329 || ucs == 0x232a ||
(ucs >= 0x2e80 && ucs <= 0xa4cf &&
ucs != 0x303f) || /* CJK ... Yi */
(ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */
(ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */
(ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */
(ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
(ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */
(ucs >= 0xffe0 && ucs <= 0xffe6) ||
(ucs >= 0x20000 && ucs <= 0x2fffd) ||
(ucs >= 0x30000 && ucs <= 0x3fffd)));
}
///------------------------------------------------------------------------------------
void jag_editor::vsplit(wstring& thestr, wstring thesplitter, vector<wstring>& vs) {
s_split(thestr, thesplitter, vs, true);
}
///------------------------------------------------------------------------------------
static void displaychar(string& bf) {
for (int i=0; i < bf.size(); i++)
cout << (int)bf[i] << " ";
cout << endl;
}
///------------------------------------------------------------------------------------
jag_editor* JAGEDITOR = NULL;
///------------------------------------------------------------------------------------
#ifdef WIN32
void resizewindow() {
JAGEDITOR->resetscreen();
}
#else
void resizewindow(int theSignal) {
JAGEDITOR->resetscreen();
}
#endif
///------------------------------------------------------------------------------------
jag_editor::jag_editor() : lines(this) {
#ifndef WIN32
//we reset the input stream
freopen("/dev/tty", "rw", stdin);
tcgetattr(0, &oldterm);
promptmode = false;
//We enable ctrl-s and ctrl-q within the editor
termios theterm;
tcgetattr(0, &theterm);
theterm.c_iflag &= ~IXON;
theterm.c_iflag |= IXOFF;
theterm.c_cc[VSTART] = NULL;
theterm.c_cc[VSTOP] = NULL;
theterm.c_cc[VSUSP] = NULL;
tcsetattr(0, TCSADRAIN, &theterm);
#endif
activate_mouse = false;
vt100 = false;
mouse_status = false;
linematch = -1;
selected_x = -1;
selected_firstline = -1;
selected_y = -1;
selected_pos = -1;
selected_posnext = -1;
double_click = 0;
nbclicks = 0;
insertaline = false;
margin = 3;
noprefix = false;
current_no_prefix = false;
tooglehelp = false;
regularexpressionfind = false;
findrgx = NULL;
#ifdef Tamgu_REGEX
wpattern = NULL;
#endif
prefixsize = 1;
xcursor = 0;
ycursor = 0;
#ifndef WIN32
signal(SIGWINCH, resizewindow);
#endif
colors.push_back(m_red);
colors.push_back(m_dore);
colors.push_back(m_blue);
colors.push_back(m_gray);
colors.push_back(m_green);
colors.push_back(m_selectgray);
poscommand = 0;
echochar = false;
option = x_none;
pos = 0;
posinstring = 0;
currentline = 0;
currentfindpos = 0;
currentposinstring = -1;
#ifdef WIN32
prefix = "<>";
wprefix = L"<>";
#else
prefix = "작";
wprefix = L"작";
#endif
replaceall = false;
modified = true;
tobesaved = false;
inittableutf8();
row_size = -1;
col_size = -1;
screensizes();
localhelp << m_red<< "^xh" << m_current << ":help " << m_red<< "^k" << m_current << ":del after " << m_red<< "^p" << m_current << ":k-buffer " << m_red<< "^d" << m_current << ":del line " << m_red<< "^uz/^r" << m_current << ":un/redo " << m_red<< "^f" << m_current << ":find " << m_red<< "^n" << m_current << ":next " << m_red<< "^g" << m_current << ":go " << m_red<< "^l" << m_current << ":top/bottom " << m_red<< "^t" << m_current << ":indent " << m_red<< "^s/w" << m_current << ":write " << m_red<< "^x" << m_current << ":commands ";
updateline = true;
taskel = true;
JAGEDITOR = this;
}
jag_editor::jag_editor(string prf) : lines(this) {
activate_mouse = false;
vt100 = false;
mouse_status = false;
linematch = -1;
selected_x = -1;
selected_firstline = -1;
selected_y = -1;
selected_pos = -1;
selected_posnext = -1;
double_click = 0;
nbclicks = 0;
insertaline = false;
margin = 3;
noprefix = false;
current_no_prefix = false;
tooglehelp = false;
regularexpressionfind = false;
findrgx = NULL;
#ifdef Tamgu_REGEX
wpattern = NULL;
#endif
promptmode = true;
xcursor = 0;
ycursor = 0;
colors.push_back(m_red);
colors.push_back(m_dore);
colors.push_back(m_blue);
colors.push_back(m_gray);
colors.push_back(m_green);
colors.push_back(m_selectgray);
poscommand = 0;
echochar = false;
option = x_none;
pos = 0;
posinstring = 0;
currentline = 0;
currentfindpos = 0;
currentposinstring = -1;
prefix = prf;
wprefix = wconvert(prf);
prefixsize = (int)size_of_prefix();
replaceall = false;
modified = true;
tobesaved = false;
inittableutf8();
row_size = -1;
col_size = -1;
screensizes();
updateline = true;
taskel = true;
}
jag_editor::~jag_editor() {
#ifdef Tamgu_REGEX
if (wpattern != NULL)
delete wpattern;
#endif
if (findrgx != NULL)
delete findrgx;
}
//------------------------------------------------------------------------------------
void jag_editor::deleteselection() {
if (selected_pos == -1)
return;
if (selected_pos == selected_posnext) {
if (selected_x == 0 && selected_y == line.size()) {
deleteline(0);
resetselection();
return;
}
undo(lines[pos],pos, u_modif);
deleteachar(line, false, selected_x);
lines[selected_pos] = line;
clearline();
printline(pos+1, line, -1);
posinstring = selected_x;
movetoposition();
resetselection();
return;
}
long first = selected_pos;
long last = selected_posnext;
wstring savedline = lines[selected_posnext];
if (selected_x == 0) {
//first line must be deleted, last line is modified or deleted
if (selected_y < savedline.size()) {
undo(savedline, selected_posnext, u_modif);
last--;
}
else {
undo(savedline, selected_posnext, u_del);
last--;
}
}
else {
undo(savedline, selected_posnext, u_del);
last--;
}
while (last > first) {
undo(lines[last], last, u_del_linked);
last--;
}
if (selected_x == 0)
undo(lines[selected_pos], selected_pos, u_del_linked);
else
undo(lines[selected_pos], selected_pos, u_modif_linked);
last = selected_posnext;
posinstring = 0;
if (selected_y >= savedline.size())
selected_y = savedline.size();
if (selected_x == 0) {
if (selected_y != savedline.size()) {
lines[selected_posnext] = savedline.substr(selected_y,savedline.size());
posinstring = selected_y;
last--;
}
}
else {
lines[selected_pos] = lines[selected_pos].substr(0, selected_x);
if (selected_y != savedline.size()) {
lines[selected_pos] += savedline.substr(selected_y,savedline.size());
}
posinstring = lines[selected_pos].size();
first++;
}
lines.erase(first, last+1);
displaylist(poslines[0]);
movetoline(selected_firstline);
movetoposition();
resetselection();
double_click = 0;
}
void jag_editor::displayextract(wstring& sub, long pos, long from_pos, long to_pos, bool select) {
if (from_pos > sub.size())
return;
if (to_pos > sub.size())
to_pos = sub.size();
posinstring = to_pos;
clearline();
if (select) {
wstring start = sub.substr(0, from_pos);
wstring middle = sub.substr(from_pos, to_pos-from_pos);
wstring end = sub.substr(to_pos, sub.size());
kbuffer += middle;
string inter = convert(start);
inter += colors[5];
inter += convert(middle);
inter += m_current;
inter += convert(end);
printline(pos + 1, inter);
}
else
printline(pos + 1, sub, -1);
}
void jag_editor::selectlines(long from_line, long to_line, long from_pos, long to_pos) {
wstring sub;
if (to_line < from_line)
return;
kbuffer = L"";
sub = lines[from_line];
char stat = lines.Status(from_line);
if (from_line == to_line) {
movetoline(currentline);
displayextract(sub, from_line, from_pos, to_pos);
if (stat == solo_line || lines.Status(from_line+1)!= concat_line) {
if (to_pos == sub.size())
kbuffer += L"\n";
}
movetoposition();
return;
}
long current = selected_firstline;
//Else we display first, the missing part
movetoline(current++);
displayextract(sub, from_line++, from_pos, sub.size());
if (stat == solo_line || lines.Status(from_line)!= concat_line)
kbuffer += L"\n";
while (from_line < to_line) {
sub = lines[from_line];
movetoline(current++);
stat = lines.Status(from_line);
displayextract(sub, from_line++, 0, sub.size());
if (stat == solo_line || lines.Status(from_line) != concat_line) {
kbuffer += L"\n";
}
}
stat = lines.Status(from_line);
movetoline(current);
sub = lines[from_line];
displayextract(sub, from_line, 0, to_pos);
if (stat == solo_line || lines.Status(from_line+1) != concat_line) {
if (to_pos == sub.size())
kbuffer += L"\n";
}
movetoposition();
}
void jag_editor::unselectlines(long from_line, long to_line, long from_pos, long to_pos) {
wstring sub;
if (to_line < from_line)
return;
sub = lines[from_line];
if (from_line == to_line) {
movetoline(currentline);
displayextract(sub, from_line, from_pos, to_pos, false);
return;
}
long current = currentline;
//Else we display first, the missing part
movetoline(current++);
displayextract(sub, from_line++, from_pos, sub.size(), false);
while (from_line < to_line) {
sub = lines[from_line];
movetoline(current++);
displayextract(sub, from_line++, 0, sub.size(), false);
}
movetoline(current);
sub = lines[from_line];
displayextract(sub, from_line, 0, to_pos, false);
}
void jag_editor::computeposition(int& p, long position) {
wstring s = lines[position];
p -= prefixe() + 1;
long i = 0;
int pos = 0;
TAMGUCHAR c;
while (pos < p) {
if (scan_emoji(s, i))
pos+=2;
else {
c = getachar(s, i);
if (ckjchar(c)) {
pos+=2;
}
else {
if (c == 9) //tab position
pos += 8;
else
pos++;
}
}
i++;
}
p = i;
}
void jag_editor::handlemousectrl(string& mousectrl) {
vector<int> location;
if (isScrollingUp(location,mousectrl)) {
if (selected_pos != -1) {
unselectlines(selected_pos, selected_posnext, selected_x, selected_y);
resetselection();
double_click = 0;
}
pos = poslines[0];
currentline = 0;
updown(is_up, pos);
return;
}
if (isScrollingDown(location,mousectrl)) {