-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbuf_edit.cpp
1887 lines (1776 loc) · 83.8 KB
/
fbuf_edit.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
//
// Copyright 2015-2022 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved
//
// This file is part of K.
//
// K is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// K is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with K. If not, see <http://www.gnu.org/licenses/>.
//
#include "ed_main.h"
#include "my_fio.h"
//******************************* BEGIN TABS *******************************
//******************************* BEGIN TABS *******************************
//******************************* BEGIN TABS *******************************
class Tabber {
const int d_tabWidth;
int FillCountToNextTabStop ( int col ) const { return d_tabWidth - (col % d_tabWidth) ; }
public:
Tabber( int tabWidth ) : d_tabWidth(tabWidth) {}
int ColOfNextTabStop ( int col ) const { return col + FillCountToNextTabStop( col ); }
int ColOfPrevTabStop ( int col ) const { return col - (1 + ((col - 1) % d_tabWidth)); }
bool ColAtTabStop ( int col ) const { return (col % d_tabWidth) == 0; }
};
void FBUF::SetTabWidth_( COL newTabWidth, PCChar funcnm_ ) { enum { SD=0 }; SD && DBG( "%s:%s %d <- %s", __func__, Name(), newTabWidth, funcnm_ );
const auto inRange( newTabWidth >= MIN_TAB_WIDTH && newTabWidth <= MAX_TAB_WIDTH );
if( inRange ) {
d_TabWidth = newTabWidth;
}
}
STATIC_FXN bool spacesonly( stref::const_iterator ptr, stref::const_iterator eos ) {
return std::all_of( ptr, eos, []( char ch ){ return ch == ' '; } );
}
template <typename T>
void PrettifyWriter
( std::string &dest, T dit, const COL dofs
, const size_t maxCharsToWrite
, const stref src, const COL src_xMin
, const COL tabWidth, const char chTabExpand, const char chTrailSpcs
) { // proper tabx requires walking src from its beginning, even though we aren't necessarily _copying_ from the beginning.
auto sit( src.cbegin() );
COL xCol( 0 ); COL dix( 0 );
const auto wr_char = [&]( char ch ) { if( xCol++ >= src_xMin ) { *dit++ = ch; ++dix; } };
const Tabber tabr( tabWidth );
// certain chTabExpand values have magical side-effects:
#if defined(BIG_BULLET)
STATIC_CONST char bsbullet[] = { BIG_BULLET, SMALL_BULLET, '\0' };
#endif
const stref srTabExpand( // srTabExpand (instead of chTabExpand) could be passed in, but mind the chTabExpand == '\0' case below!
#if defined(BIG_BULLET)
chTabExpand == BIG_BULLET ? stref( bsbullet ) :
#endif
chTabExpand == '>' ? stref( ">-" ) :
chTabExpand == '*' ? stref( "*." ) :
chTabExpand == '-' ? stref( "-->" ) :
chTabExpand == '<' ? stref( "<->" ) :
chTabExpand == '^' ? stref( "^`" ) :
stref( &chTabExpand, sizeof(chTabExpand) )
);
const auto chLast( srTabExpand[ srTabExpand.length() - 1 ] );
const auto chFill( srTabExpand[ srTabExpand.length() > 1 ? 1 : 0 ] );
while( sit != src.cend() && dix < maxCharsToWrite ) {
if( const auto ch = *sit++ ; ch != HTAB || chTabExpand == '\0' ) {
wr_char( ch );
}
else { // expand an HTAB-spring
const auto tgt( tabr.ColOfNextTabStop( xCol ) );
wr_char( (xCol == tgt-1) ? chLast : srTabExpand[0] );
while( xCol < tgt && dix < maxCharsToWrite ) {
wr_char( (xCol == tgt-1) ? chLast : chFill );
}
}
}
if( chTrailSpcs && (sit == src.cend() || spacesonly( sit, src.cend() )) ) { // _trailing_ spaces on the source side
stref destseg( dest.data() + dofs, dix ); // what we wrote above
const auto ix_last_non_white( destseg.find_last_not_of( SPCTAB ) );
if( ix_last_non_white != dix-1 ) { // any trailing blanks at all?
// ix_last_non_white==eosr means ALL are blanks
const auto rlen( ix_last_non_white==eosr ? dix : dix-1 - ix_last_non_white );
for( auto iy( dofs + (dix-rlen) ); iy < dofs + dix ; ++iy ) {
if( dest[iy] == ' ' ) { // don't touch tab-replacement done above
dest[iy] = chTrailSpcs;
}
}
}
}
}
void PrettifyMemcpy
( std::string &dest, COL xLeft
, size_t maxCharsToWrite
, stref src, COL src_xMin
, COL tabWidth, char chTabExpand, char chTrailSpcs
) {
PrettifyWriter< decltype( begin(dest) ) > ( dest , begin(dest) + xLeft, xLeft, maxCharsToWrite, src, src_xMin, tabWidth, chTabExpand, chTrailSpcs );
}
STATIC_FXN void PrettifyInsert
( std::string &dest
, size_t maxCharsToWrite
, stref src, COL src_xMin
, COL tabWidth, char chTabExpand, char chTrailSpcs
) {
PrettifyWriter< decltype(back_inserter(dest)) > ( dest, back_inserter(dest) , 0, maxCharsToWrite, src, src_xMin, tabWidth, chTabExpand, chTrailSpcs );
}
void FormatExpandedSeg // more efficient version: recycles (but clear()s) dest, should hit the heap less frequently
( std::string &dest, size_t maxCharsToWrite
, stref src, COL src_xMin, COL tabWidth, char chTabExpand, char chTrailSpcs
) {
dest.clear();
PrettifyInsert( dest, maxCharsToWrite, src, src_xMin, tabWidth, chTabExpand, chTrailSpcs );
}
std::string FormatExpandedSeg // less efficient version: uses virgin dest each call, thus hits the heap each time
( size_t maxCharsToWrite
, stref src, COL src_xMin, COL tabWidth, char chTabExpand, char chTrailSpcs
) {
std::string dest;
PrettifyInsert( dest, maxCharsToWrite, src, src_xMin, tabWidth, chTabExpand, chTrailSpcs );
return dest;
}
COL ColPrevTabstop( COL tabWidth, COL xCol ) { return Tabber( tabWidth ).ColOfPrevTabStop( xCol ); }
COL ColNextTabstop( COL tabWidth, COL xCol ) { return Tabber( tabWidth ).ColOfNextTabStop( xCol ); }
bool FBOP::IsLineBlank( PCFBUF fb, LINE yLine ) {
return IsStringBlank( fb->PeekRawLine( yLine ) );
}
bool FBOP::IsBlank( PCFBUF fb ) {
for( auto iy( 0 ); iy < fb->LineCount() ; ++iy ) {
if( !FBOP::IsLineBlank( fb, iy ) ) {
return false;
}
}
return true;
}
// const Tabber &TabberParam;
typedef const Tabber TabberParam; // 3 calls using this type take less code (-512 byte GCC incr)
STATIC_FXN void spcs2tabs_outside_quotes( string_back_inserter dit, stref src, TabberParam tabr ) {
auto quoteCh( '\0' );
auto destCol( 0 );
auto fNxtChEscaped( false );
auto fInQuotedRgn( false );
auto sit( src.cbegin() );
while( sit != src.cend() ) {
if( !fInQuotedRgn ) {
if( !fNxtChEscaped ) {
auto x_Cx( 0 );
while( sit != src.cend() && (*sit == ' ' || *sit == HTAB) ) {
if( *sit == HTAB ) {
x_Cx = 0;
destCol = tabr.ColOfNextTabStop( destCol );
*dit++ = HTAB;
}
else {
++x_Cx;
++destCol;
if( tabr.ColAtTabStop(destCol) ) {
*dit++ = (x_Cx == 1) ? ' ' : HTAB;
x_Cx = 0;
}
}
++sit;
}
while( x_Cx-- ) {
*dit++ = ' ';
}
}
if( sit != src.cend() && !fNxtChEscaped ) {
switch( *sit ) {
break; case chQuot1:
break; case chQuot2: fInQuotedRgn = true;
quoteCh = *sit;
break; case chESC: fNxtChEscaped = true; // ESCAPE char, not PathSepCh!
break; default: ;
}
}
else {
fNxtChEscaped = false;
}
}
else {
if( sit != src.cend() && !fNxtChEscaped ) {
if( *sit == quoteCh ) { fInQuotedRgn = false; }
else if( *sit == chESC ) { fNxtChEscaped = true; } // ESCAPE char, not PathSepCh!
}
else {
fNxtChEscaped = false;
}
}
if( sit != src.cend() ) {
*dit++ = *sit++;
++destCol;
}
}
}
STATIC_FXN void spcs2tabs_all( string_back_inserter dit, stref src, TabberParam tabr ) {
auto xCol(0);
auto sit( src.cbegin() );
while( sit != src.cend() ) {
auto ix(0);
while( sit != src.cend() && (*sit == ' ' || *sit == HTAB) ) {
if( *sit == HTAB ) {
ix = 0;
xCol = tabr.ColOfNextTabStop( xCol );
*dit++ = HTAB;
}
else {
++ix;
++xCol;
if( tabr.ColAtTabStop(xCol) ) {
*dit++ = (--ix == 0) ? ' ' : HTAB;
ix = 0;
}
}
++sit;
}
while( ix-- ) {
*dit++ = ' ';
}
if( sit != src.cend() ) {
*dit++ = *sit++;
++xCol;
}
}
}
STATIC_FXN void spcs2tabs_leading( string_back_inserter dit, stref src, TabberParam tabr ) {
auto xCol( 0 );
auto ix(0);
auto sit( src.cbegin() );
for( ; sit != src.cend() && (*sit == ' ' || *sit == HTAB) ; ++sit ) {
if( *sit == HTAB ) {
ix = 0;
xCol = tabr.ColOfNextTabStop( xCol );
*dit++ = HTAB;
}
else {
++ix;
++xCol;
if( tabr.ColAtTabStop(xCol) ) {
*dit++ = (--ix == 0) ? ' ' : HTAB;
ix = 0;
}
}
}
while( ix-- ) {
*dit++ = ' ';
}
for( ; sit != src.cend() ; ++sit ) {
*dit++ = *sit;
}
}
//******************************* END TABS *******************************
//******************************* END TABS *******************************
//******************************* END TABS *******************************
void FBUF::cat( PCChar pszNewLineData ) { // used by Lua's method of same name
BoolOneShot first;
lineIterator li( pszNewLineData );
while( !li.empty() ) {
auto ln( li.next() );
if( first && !ln.empty() ) {
const auto rl( PeekRawLine( LastLine() ) );
std::string lbuf; lbuf.reserve( rl.length() + ln.length() );
lbuf.assign( rl );
lbuf.append( ln );
PutLineRaw( LastLine(), lbuf );
}
else {
PutLastLineRaw( ln );
}
}
}
int FBUF::PutLastMultilineRaw( stref sr ) {
lineIterator li( sr );
auto lineCount( 0 );
while( !li.empty() ) {
PutLastLineRaw( li.next() );
++lineCount;
}
return lineCount;
}
STATIC_FXN int Vsprintf_to_FBUF_LastLine( PFBUF fb, PCChar format, va_list val ) {
Xbuf xb; xb.vFmtStr( format, val );
return fb->PutLastMultilineRaw( xb.sr() );
}
int FBUF::FmtLastLine( PCChar format, ... ) {
va_list val; va_start( val, format );
const auto rv( Vsprintf_to_FBUF_LastLine( this, format, val ) );
va_end( val );
return rv;
}
void FBUF::PutLineRaw( LINE yLine, stref srSrc ) {
0 && IsNoEdit() && DBG( "%s on noedit=%s", __PRETTY_FUNCTION__, Name() );
BadParamIf( , IsNoEdit() );
if( !TrailSpcsKept() ) {
auto trailSpcs = 0;
for( auto it( srSrc.crbegin() ) ; it != srSrc.crend() && isblank( *it ) ; ++it ) {
++trailSpcs;
}
srSrc.remove_suffix( trailSpcs );
}
if( yLine > LastLine() // no existing content?
|| srSrc != PeekRawLine( yLine ) // new content != existing content?
) {
DirtyFBufAndDisplay();
const auto minLineCount( yLine + 1 );
if( LineCount() < minLineCount ) { 0 && DBG("%s Linecount=%d", __func__, minLineCount );
FBOP::PrimeRedrawLineRangeAllWin( this, LastLine(), yLine ); // needed with addition of g_chTrailLineDisp; past-EOL lines need to be overwritten
LineInfoReserve( minLineCount );
SetLineCount ( minLineCount );
}
else {
FBOP::PrimeRedrawLineRangeAllWin( this, yLine, yLine );
}
UndoIns_EditLine( yLine, srSrc ); // actually perform the write to this FBUF
}
}
void FBUF::PutLineEntab( LINE yLine, stref srSrc, std::string &tmpbuf ) {
0 && IsNoEdit() && DBG( "%s on noedit=%s", __PRETTY_FUNCTION__, Name() );
BadParamIf( , IsNoEdit() );
if( ENTAB_0_NO_CONV != Entab() ) {
tmpbuf.clear();
const Tabber tabr( this->TabWidth() );
switch( Entab() ) { // compress spaces into tabs per this->Entab()
break;default:
break;case ENTAB_0_NO_CONV: Assert( 0 );
break;case ENTAB_1_LEADING_SPCS_TO_TABS: spcs2tabs_leading ( back_inserter(tmpbuf), srSrc, tabr );
break;case ENTAB_2_SPCS_NOTIN_QUOTES_TO_TABS: spcs2tabs_outside_quotes( back_inserter(tmpbuf), srSrc, tabr );
break;case ENTAB_3_ALL_SPC_TO_TABS: spcs2tabs_all ( back_inserter(tmpbuf), srSrc, tabr );
}
srSrc = tmpbuf;
}
PutLineRaw( yLine, srSrc );
}
COL ColOfFreeIdx( COL tabWidth, stref content, sridx offset, sridx startIx, COL colOfStartIx ) {
const Tabber tabr( tabWidth );
COL xCol;
if( startIx > offset ) {
startIx = 0;
xCol = 0;
}
else {
xCol = colOfStartIx;
}
for( decltype( content.length() ) ix( startIx ) ; ix < content.length() ; ++ix ) {
if( ix == offset ) {
return xCol;
}
switch( content[ix] ) {
break;default : ++xCol;
break;case HTAB: xCol = tabr.ColOfNextTabStop( xCol );
}
}
return xCol + (offset - content.length()); // 'offset' indexes _past_ content: assume all chars past EOL are spaces (non-tabs)
}
STATIC_FXN bool DeletePrevChar( const bool fEmacsmode ) { PCFV;
const auto yLine( pcv->Cursor().lin );
if( pcv->Cursor().col == 0 ) { // cursor @ beginning of line?
if( yLine == 0 ) {
return false; // no prev char
}
auto xCol( FBOP::LineCols( pcf, yLine-1 ) );
if( fEmacsmode ) { // join current and prev lines
pcf->DelStream( xCol, yLine-1, 0, yLine );
}
pcv->MoveCursor( yLine-1, xCol );
return true;
}
const auto x0( pcv->Cursor().col );
const auto colsDeld( FBOP::DelChar( pcf, yLine, x0 - 1 ) );
pcv->MoveCursor( yLine, x0 - std::max( colsDeld, 1 ) );
return true;
}
bool ARG::cdelete () { return DeletePrevChar( false ); }
bool ARG::emacscdel() { return DeletePrevChar( true ); }
//------------------------------------------------------------------------------
STATIC_FXN void GetLineWithSegRemoved( PFBUF pf, std::string &dest, const LINE yLine, const COL xLeft, const COL boxWidth, bool fCollapse ) {
pf->DupLineTabs2Spcs( dest, yLine );
const auto tw( pf->TabWidth() );
const auto xEolNul( StrCols( tw, dest ) );
if( xEolNul <= xLeft ) { 0 && DBG( "%s xEolNul(%d) <= xLeft(%d)", __func__, xEolNul, xLeft );
return;
}
IdxCol_cached conv( tw, dest );
const auto ixLeft( conv.c2ci( xLeft ) );
const auto xRight( xLeft + boxWidth ); // dest[xRight] will be 0th char of kept 2nd segment
if( xRight >= xEolNul ) { // trailing segment of line is being deleted?
0 && DBG( "%s trim, %u <= %d '%c'", __func__, xEolNul, xRight, dest[ixLeft] );
dest.resize( ixLeft ); // the first (leftmost) char in the selected box
return;
}
const auto ixRight( conv.c2ci( xRight ) );
if( ixRight > ixLeft ) {
const auto charsInGap( ixRight - ixLeft );
if( fCollapse ) { /* Collapse */ 0 && DBG( "b4:%s'", dest.c_str() );
dest.erase( ixLeft, charsInGap ); 0 && DBG( "af:%s'", dest.c_str() );
}
else { // fill Gap w/blanks
dest.replace( ixLeft, charsInGap, charsInGap, ' ' );
}
}
}
void FBUF::DelBox( COL xLeft, LINE yTop, COL xRight, LINE yBottom, bool fCollapse ) {
if( xRight < xLeft ) {
return;
} 0 && DBG( "%s Y:[%d,%d] X:[%d,%d]", __func__, yTop, yBottom, xLeft, xRight );
AdjMarksForBoxDeletion( this, xLeft, yTop, xRight, yBottom );
const auto boxWidth( xRight - xLeft + 1 );
std::string src; std::string stmp;
for( auto yLine( yTop ); yLine <= yBottom; ++yLine ) {
GetLineWithSegRemoved( this, src, yLine, xLeft, boxWidth, fCollapse );
PutLineEntab( yLine, src, stmp );
}
}
// NB: See "STREAM definition" in ARG::FillArgStruct to understand parameters!
// Nutshell: LAST CHAR OF STREAM IS EXCLUDED from operation!
//
void FBUF::DelStream( COL xStart, LINE yStart, COL xEnd, LINE yEnd ) {
if( yStart == yEnd ) { 0 && DBG( "%s [%d..%d]", __func__, xStart, xEnd-1 );
DelBox( xStart, yStart, xEnd-1, yStart ); // xEnd-1 because "LAST CHAR OF STREAM IS EXCLUDED from operation!"
return;
}
std::string stFirst; DupLineSeg( stFirst, yStart, 0, xStart-1 );
DelLines( yStart, yEnd - 1 );
std::string stLast; DupLineSeg( stLast, yStart, xEnd, COL_MAX );
stFirst += stLast;
PutLineEntab( yStart, stFirst, stLast );
AdjMarksForInsertion( this, this, xEnd, yStart, COL_MAX, yStart, xStart, yStart );
}
//====================================================================================================
// BUGBUG: multi-clipboard support; not yet used.
// TBD:
// 1. How to show clip-select menu? (Use LUA!)
// 2. Hiding MULTIPLE clips: use regex /<clip[0-9]>/ ?
//
struct clipInfo {
PFBUF pFBuf;
int contentType;
};
STATIC_VAR struct {
int curIdx;
clipInfo info[5];
} s_Clip;
PFBUF GetClipFBufToRead( int *pClipboardArgType ) {
const auto &cinfo( s_Clip.info[ s_Clip.curIdx ] );
if( cinfo.pFBuf ) {
*pClipboardArgType = cinfo.contentType;
}
return cinfo.pFBuf;
}
PFBUF GetNextClipFBufToWrite( int clipboardArgType ) {
const auto start( s_Clip.curIdx );
while( start != (s_Clip.curIdx = (s_Clip.curIdx + 1) % ELEMENTS( s_Clip.info )) ) {
auto &cinfo( s_Clip.info[ s_Clip.curIdx ] );
if( cinfo.pFBuf ) {
if( !cinfo.pFBuf->IsNoEdit() ) {
cinfo.pFBuf->MakeEmpty();
cinfo.pFBuf->MoveCursorToBofAllViews();
cinfo.contentType = clipboardArgType;
return cinfo.pFBuf;
}
}
else {
cinfo.contentType = clipboardArgType;
return FBOP::FindOrAddFBuf( FmtStr<12>( "<clip%d>", s_Clip.curIdx ).c_str(), &cinfo.pFBuf );
}
}
// _ALL_ aClipFBufs have been made readonly! User has to pick one to overwrite, OR cancel the copy-to-clip op
// MenuChooseClip( "Choose <clip> to overwrite" );
const auto menuChoice( -1 );
if( menuChoice < 0 ) {
return nullptr;
}
s_Clip.curIdx = menuChoice;
auto &cinfo( s_Clip.info[ s_Clip.curIdx ] );
cinfo.pFBuf->ClrNoEdit();
cinfo.pFBuf->MakeEmpty();
cinfo.pFBuf->MoveCursorToBofAllViews();
cinfo.contentType = clipboardArgType;
return cinfo.pFBuf;
}
//====================================================================================================
STIL void Clipboard_Prep( int clipboardArgType ) {
g_pFbufClipboard->MakeEmpty();
g_ClipboardType = clipboardArgType;
}
// PCFV_ fxns operate on the current View/FBUF, using ARG::-typed params
// intended mostly for use within ARG:: methods
STATIC_FXN void PCFV_Copy_STREAMARG_ToClipboard( ARG::STREAMARG_t const &d_streamarg ) {
Clipboard_Prep( STREAMARG ); FBOP::CopyStream( g_pFbufClipboard, 0, 0, g_CurFBuf(), d_streamarg.flMin.col, d_streamarg.flMin.lin, d_streamarg.flMax.col, d_streamarg.flMax.lin );
}
STATIC_FXN void PCFV_Copy_BOXARG_ToClipboard( ARG::BOXARG_t const &d_boxarg ) {
Clipboard_Prep( BOXARG ); FBOP::CopyBox ( g_pFbufClipboard, 0, 0, g_CurFBuf(), d_boxarg.flMin.col, d_boxarg.flMin.lin, d_boxarg.flMax.col, d_boxarg.flMax.lin );
}
STATIC_FXN void PCFV_Copy_LINEARG_ToClipboard( ARG::LINEARG_t const &d_linearg ) {
Clipboard_Prep( LINEARG ); FBOP::CopyLines( g_pFbufClipboard, 0, g_CurFBuf(), d_linearg.yMin, d_linearg.yMax );
}
STATIC_FXN void PCFV_delete_STREAMARG( ARG::STREAMARG_t const &d_streamarg, bool copyToClipboard ) { PCFV;
if( copyToClipboard ) { PCFV_Copy_STREAMARG_ToClipboard( d_streamarg ); }
pcf->DelStream( d_streamarg.flMin.col, d_streamarg.flMin.lin, d_streamarg.flMax.col, d_streamarg.flMax.lin );
pcv->MoveCursor( d_streamarg.flMin.lin, d_streamarg.flMin.col );
}
STATIC_FXN void PCFV_BoxInsertBlanks( ARG::BOXARG_t const &d_boxarg ) { PCFV;
FBOP::CopyBox( pcf,
d_boxarg.flMin.col, d_boxarg.flMin.lin, nullptr
, d_boxarg.flMin.col, d_boxarg.flMin.lin
, d_boxarg.flMax.col, d_boxarg.flMax.lin
);
}
STATIC_FXN void PCFV_delete_LINEARG( ARG::LINEARG_t const &d_linearg, bool copyToClipboard ) { PCFV;
// LINEARG or BOXARG: Deletes the specified text and copies it to the
// clipboard. The argument is a LINEARG or BOXARG regardless of the
// current selection mode. The argument is a LINEARG if the starting
// and ending points are in the same column.
if( copyToClipboard ) { PCFV_Copy_LINEARG_ToClipboard( d_linearg ); }
pcf->DelLines( d_linearg.yMin, d_linearg.yMax );
pcv->MoveCursor( d_linearg.yMin, g_CursorCol() );
}
STATIC_FXN void PCFV_delete_BOXARG( ARG::BOXARG_t const &d_boxarg, bool copyToClipboard, bool fCollapse=true ) { PCFV;
if( copyToClipboard ) { PCFV_Copy_BOXARG_ToClipboard( d_boxarg ); }
pcf->DelBox( d_boxarg.flMin.col, d_boxarg.flMin.lin, d_boxarg.flMax.col, d_boxarg.flMax.lin, fCollapse );
pcv->MoveCursor( d_boxarg.flMin.lin, d_boxarg.flMin.col );
}
STATIC_FXN void DelArgRegion( const ARG &arg ) {
switch( arg.d_argType ) {
break;case LINEARG: PCFV_delete_LINEARG ( arg.d_linearg , false );
break;case BOXARG: PCFV_delete_BOXARG ( arg.d_boxarg , false );
break;case STREAMARG: PCFV_delete_STREAMARG( arg.d_streamarg, false );
break;default: ;
}
}
STATIC_FXN void PCFV_delete_ToEOL( Point const &curpos, bool copyToClipboard ) { PCFV;
auto xMax( FBOP::LineCols( pcf, curpos.lin ) );
if( xMax >= curpos.col ) {
PCFV_delete_BOXARG( {curpos.lin, curpos.col, curpos.lin, xMax }, copyToClipboard );
}
}
bool ARG::sdelete() { PCFV;
switch( d_argType ) {
break;default: return BadArg();
break;case NOARG: FBOP::DelChar( pcf, pcv->Cursor().lin, pcv->Cursor().col ); // Delete the CHARACTER at the cursor w/o saving it to <clipboard>
break;case NULLARG: PCFV_delete_STREAMARG( { d_nullarg.cursor.lin, d_nullarg.cursor.col, d_nullarg.cursor.lin+1, 0 }, !d_fMeta ); // Deletes text from the cursor to the end of the line, INCLUDING THE LINE BREAK.
// STREAMARG ³ BOXARG ³ LINEARG: Deletes the selected stream of text
// from the starting point of the selection to the cursor and copies
// it to the clipboard. This always deletes a stream of text,
// regardless of the current selection mode.
break;case BOXARG: ConvertLineOrBoxArgToStreamArg(); PCFV_delete_STREAMARG( d_streamarg, !d_fMeta );
break;case LINEARG: ConvertLineOrBoxArgToStreamArg(); PCFV_delete_STREAMARG( d_streamarg, !d_fMeta );
break;case STREAMARG: PCFV_delete_STREAMARG( d_streamarg, !d_fMeta );
}
return true;
}
bool ARG::ldelete() { PCFV;
if( d_argType == STREAMARG ) {
ConvertStreamargToLineargOrBoxarg();
}
switch( d_argType ) {
break;default: return BadArg();
break;case NOARG: PCFV_delete_LINEARG( { d_noarg.cursor.lin, d_noarg.cursor.lin }, !d_fMeta ); // Deletes the line at the cursor
break;case NULLARG: PCFV_delete_ToEOL( d_nullarg.cursor, !d_fMeta ); // Deletes text from the cursor to the end of the line
break;case LINEARG: PCFV_delete_LINEARG( d_linearg, !d_fMeta );
break;case BOXARG: PCFV_delete_BOXARG( d_boxarg, !d_fMeta );
}
return true;
}
bool ARG::udelete() { // "user interface" delete; does not convert BOX/LINE/STREAM ARGs; intended to replace ldelete on user's keyboard
switch( d_argType ) {
break;default: return BadArg();
break;case NOARG: PCFV_delete_LINEARG( { d_noarg.cursor.lin, d_noarg.cursor.lin }, !d_fMeta ); // Deletes the line at the cursor
break;case NULLARG: PCFV_delete_ToEOL( d_nullarg.cursor, !d_fMeta ); // Deletes text from the cursor to the end of the line
break;case STREAMARG: PCFV_delete_STREAMARG( d_streamarg, !d_fMeta );
break;case LINEARG: PCFV_delete_LINEARG( d_linearg, !d_fMeta );
break;case BOXARG: PCFV_delete_BOXARG( d_boxarg, !d_fMeta, d_cArg < 2 );
}
return true;
}
bool ARG::delete_() { // BUGBUG make this NOT save to clipboard!!! (current workaround: del key assigned to "meta delete")
switch( d_argType ) {
break;default: sdelete();
break;case LINEARG: ldelete();
break;case BOXARG: ldelete();
}
return true;
}
bool ARG::sinsert() { PCF;
switch( d_argType ) {
default: return BadArg();
case NOARG: FBOP::CopyBox( pcf,
d_noarg.cursor.col, d_noarg.cursor.lin, nullptr
, d_noarg.cursor.col, d_noarg.cursor.lin
, d_noarg.cursor.col, d_noarg.cursor.lin
);
return true;
case NULLARG: FBOP::CopyStream( pcf,
d_nullarg.cursor.col, d_nullarg.cursor.lin
, nullptr
, d_nullarg.cursor.col, d_nullarg.cursor.lin
, 0 , d_nullarg.cursor.lin + 1
);
return true;
case BOXARG: ATTR_FALLTHRU;
case LINEARG: ConvertLineOrBoxArgToStreamArg();
ATTR_FALLTHRU;
case STREAMARG: FBOP::CopyStream( pcf,
d_streamarg.flMin.col, d_streamarg.flMin.lin
, nullptr
, d_streamarg.flMin.col, d_streamarg.flMin.lin
, d_streamarg.flMax.col, d_streamarg.flMax.lin
);
return true;
}
}
bool ARG::copy() {
switch( d_argType ) {
break;default: return BadArg();
break;case NOARG: PCFV_Copy_LINEARG_ToClipboard ( { d_noarg.cursor.lin, d_noarg.cursor.lin } ); // Copies the line at the cursor to the clipboard.
break;case LINEARG: PCFV_Copy_LINEARG_ToClipboard ( d_linearg );
break;case STREAMARG: PCFV_Copy_STREAMARG_ToClipboard( d_streamarg );
break;case BOXARG: PCFV_Copy_BOXARG_ToClipboard ( d_boxarg );
break;case TEXTARG: 0 && DBG( "%s: textarg.len=%d", __func__, Strlen( d_textarg.pText ) );
if( d_textarg.pText[0] == 0 ) {
Clipboard_Prep( 0 ); // 0 == EMPTY
}
else {
Clipboard_Prep( BOXARG );
g_pFbufClipboard->PutLineRaw( 0, d_textarg.pText );
}
}
return true;
}
bool ARG::linsert() { PCF;
if( d_argType == STREAMARG ) {
ConvertStreamargToLineargOrBoxarg();
}
switch( d_argType ) {
break;default: return BadArg();
break;case NULLARG: {
// Inserts or deletes blanks at the beginning of a line to move the
// first nonblank character to the cursor.
// (same as NOARG aligncol?)
const auto rl( pcf->PeekRawLine( d_nullarg.cursor.lin ) );
const auto ixNonb( FirstNonBlankOrEnd( rl ) );
const auto xNonb( CaptiveIdxOfCol( pcf->TabWidth(), rl, ixNonb ) );
std::string sbuf;
if ( xNonb > d_nullarg.cursor.col ) {
GetLineWithSegRemoved( pcf, sbuf, d_nullarg.cursor.lin, d_nullarg.cursor.col, xNonb - d_nullarg.cursor.col, true );
}
else if( xNonb < d_nullarg.cursor.col ) {
pcf->DupLineForInsert( sbuf, d_nullarg.cursor.lin, xNonb, d_nullarg.cursor.col - xNonb );
}
if( sbuf.length() ) {
std::string stmp;
pcf->PutLineEntab( d_nullarg.cursor.lin, sbuf, stmp );
}
}
break;case NOARG: pcf->InsBlankLinesBefore( d_noarg.cursor.lin ); // Inserts one blank line above the current line.
break;case LINEARG: // LINEARG or BOXARG: Inserts blanks within the specified area. The
// argument is a linearg or boxarg regardless of the current selection
// mode. The argument is a linearg if the starting and ending points are
// in the same column.
pcf->InsBlankLinesBefore( d_linearg.yMin, d_linearg.yMax - d_linearg.yMin + 1 );
break;case BOXARG: PCFV_BoxInsertBlanks( d_boxarg );
}
return true; // Linsert always returns true.
}
COL FBOP::DelChar( PFBUF fb, LINE yPt, COL xPt ) {
const auto tw( fb->TabWidth() );
const auto rl( fb->PeekRawLine( yPt ) );
const auto lc0( StrCols( tw, rl ) );
xPt = TabAlignedCol( tw, rl, xPt );
if( xPt >= lc0 ) { // xPt to right of line content?
return 0; // this is a nop
}
// Here we are deleting a CHARACTER, whereas DelBox deletes COLUMNS; if the character is an HTAB,
// the # of COLUMNS to be deleted in order to delete the underlying CHARACTER is variable:
// NB: xNxtChar != xPt+1 iff realtabs and (HTAB==rl[ ix(xPt) ])
const auto xNxtChar( ColOfNextChar( tw, rl, xPt ) );
fb->DelBox( xPt, yPt, xNxtChar-1, yPt );
const auto rv( xNxtChar - xPt ); 0 && DBG( "%s returns %d-%d= %d", __func__, xNxtChar, xPt, rv );
return rv;
}
COL FBOP::PutChar_( PFBUF fb, LINE yLine, COL xCol, char theChar, bool fInsert, std::string &tmp1, std::string &tmp2 ) {
const auto lc0( FBOP::LineCols( fb, yLine ) );
fb->DupLineForInsert( tmp1, yLine, xCol, fInsert ? 1 : 0 ); 0 && DBG( "%s 1=%" PR_BSR "'", __func__, BSR(tmp1) );
const auto tw( fb->TabWidth() );
const auto destIx( CaptiveIdxOfCol( tw, tmp1, xCol ) );
if( !fInsert && theChar == tmp1[ destIx ] ) {
return 0; // this is a nop
}
tmp1[ destIx ] = theChar; 0 && DBG( "%s 2=%" PR_BSR "'", __func__, BSR(tmp1) );
fb->PutLineEntab( yLine, tmp1, tmp2 );
// everything that follows is to determine the number of columns added by the insertion of theChar
// (which is used to determine the new cursor position if a user keystroke op caused us to be doing this)
// BUGBUG: this might be WRONG in the case of overwrite (replace, !fInsert) if theChar or what is replaces is an HTAB!
const auto colsInserted( ColOfNextChar( tw, tmp1, xCol ) - xCol );
if( xCol < lc0 ) { // actual content added?
AdjMarksForInsertion( fb, fb, xCol, yLine, COL_MAX, yLine, xCol+colsInserted, yLine );
}
return colsInserted;
}
#ifdef fn_xquote
STATIC_FXN PCCMD GetGraphic() {
CPCCMD pCmd( CmdFromKbdForExec() );
if( !pCmd || !pCmd->IsFnGraphic() ) {
return nullptr;
}
return pCmd;
}
STATIC_FXN int GetHexDigit() {
PCCMD pCmd;
while( !(pCmd=GetGraphic()) || !isxdigit( pCmd->d_argData.chAscii() ) ) {
continue;
}
const char ch( tolower( pCmd->d_argData.chAscii() ) );
return (ch <= '9') ? ch - '0' : ch + 10 - 'a';
}
bool ARG::xquote() { // Xquote
fnMsg( "hit 2 hex chars" ); auto val( GetHexDigit() );
fnMsg( "hit 1 more hex char" ); val = GetHexDigit() + (val * 16);
const char buf[2] = { char(val & 0xFF), 0 };
fnMsg( "0x%02X (%c)", val, val );
return PushVariableMacro( buf );
}
#endif
bool ARG::graphic() { enum { SD=0 };
const char usrChar( d_pCmd->d_argData.chAscii() );
// <000612> klg Finally did this! Been needing it for YEARS!
// g_delims, g_delimMirrors
// m4 `quoting'
// |
STATIC_CONST char chOpeningDelim[] = "*_%'\"(<{[`";
STATIC_CONST char chClosingDelim[] = "*_%'\")>}]`";
STATIC_CONST char chClosingDelim_m4[] = "*_%'\")>}]'";
const auto ixMatch( stref(chOpeningDelim).find( usrChar ) );
const char chClosing( ixMatch==eosr ? '\0' : (g_fM4backtickquote ? chClosingDelim_m4 : chClosingDelim)[ ixMatch ] );
std::string tmp1, tmp2;
if( d_argType == BOXARG ) {
if( usrChar == ' ' ) { // insert spaces
PCFV_BoxInsertBlanks( d_boxarg );
return true;
}
if( chClosing ) {
const auto fConformRight( (d_cArg > 1 || (usrChar == chQuot2 || usrChar == chQuot1 || usrChar == chBackTick)) ); // word-conforming bracketing of a BOXARG?
// if certain chars are hit when a BOX selection is current, surround the
// selected text with matching delimiters (depending on the char hit)
//
const auto pf( g_CurFBuf() );
const auto tw( pf->TabWidth() );
for( auto curLine( d_boxarg.flMin.lin ); curLine <= d_boxarg.flMax.lin ; ++curLine ) {
auto xMax( d_boxarg.flMax.col+1 );
if( fConformRight ) {
const auto rl( pf->PeekRawLine( curLine ) ); SD && DBG( "rl='%" PR_BSR "'", BSR(rl) );
IdxCol_cached conv( tw, rl );
const auto ixMin( conv.c2fi( d_boxarg.flMin.col ) );
if( ixMin < rl.length() ) {
const auto ixMax( conv.c2fi( xMax ) );
auto rlSeg( rl.substr( ixMin, ixMax-ixMin ) ); SD && DBG( "rlSeg='%" PR_BSR "'", BSR(rlSeg) );
rmv_trail_blanks( rlSeg ); SD && DBG( "rlSeg='%" PR_BSR "'", BSR(rlSeg) );
xMax = conv.i2c( ixMin + rlSeg.length() );
}
}
FBOP::InsertChar( pf, curLine, xMax , chClosing, tmp1, tmp2 );
FBOP::InsertChar( pf, curLine, d_boxarg.flMin.col, usrChar , tmp1, tmp2 );
}
return true;
}
else if( 0 && (',' == usrChar) ) {
// TBD: loop looking for spacey regions, replacing first char of each spacey region with a comma
}
}
else if( d_argType == STREAMARG ) {
if( chClosing ) {
const auto pf( g_CurFBuf() );
FBOP::InsertChar( pf, d_streamarg.flMax.lin, d_streamarg.flMax.col, chClosing, tmp1, tmp2 );
FBOP::InsertChar( pf, d_streamarg.flMin.lin, d_streamarg.flMin.col, usrChar , tmp1, tmp2 );
return true;
}
}
::DelArgRegion( *this );
return PutCharIntoCurfileAtCursor( usrChar, tmp1, tmp2 );
}
bool ARG::insert() {
switch( d_argType ) {
break;case BOXARG: linsert();
break;case LINEARG: linsert();
break;default: sinsert();
}
return true;
}
bool ARG::emacsnewl() {
if( Get_g_ArgCount() > 0 ) {
return newline();
}
const auto pfb( g_CurFBuf() );
const auto xIndent( FBOP::GetSoftcrIndent( pfb ) );
// Original bug report 20070305:
//
// "emacsnewl "touches" the current line even when the cursor is beyond
// EOL and thus the content of said line is unchanged (this causes
// tab-replacement changes). Investigation shows that maybe
// CopyStream should not be used, or that DupLineForInsert needs to be
// modified to use the entab settings from the dest?"
//
// 20090228 kgoodwin My fix: avoid CopyStream if cursor at/past EoL:
// CopyStream always touches (rewrites) the current line in this case,
// modifying tabs, etc.
//
// PCChar bos, eos;
// if( pfb->PeekRawLineExists( g_CursorLine(), &bos, &eos ) && ColOfPtr( pfb->TabWidth(), bos, eos-1, eos ) < g_CursorCol() ) {
// pfb->InsLineEntab( g_CursorLine() + 1, "" );
// }
// else {
FBOP::CopyStream( pfb,
g_CursorCol(), g_CursorLine() // dest
, nullptr // space-fill
, g_CursorCol(), g_CursorLine() // src
, xIndent , g_CursorLine() + 1 // src
);
// }
g_CurView()->MoveCursor( g_CursorLine() + 1, xIndent );
return true;
}
bool ARG::paste() {
switch( d_argType ) {
break;default:
break;case STREAMARG: ::DelArgRegion( *this ); // Replace the selected text with the contents of <clipboard>
break;case BOXARG: ::DelArgRegion( *this ); // Replace the selected text with the contents of <clipboard>
break;case LINEARG: ::DelArgRegion( *this ); // Replace the selected text with the contents of <clipboard>
break;case TEXTARG: {
g_pFbufClipboard->MakeEmpty();
if( d_cArg < 2 ) {
Clipboard_PutText( d_textarg.pText );
}
else {
#if 0
// Arg Arg <textarg> Paste
//
// Copies the contents of the file specified by <textarg> to the
// current file above the current line.
//
// Arg Arg !<textarg> Paste
//
// Runs <textarg> as an operating-system command, capturing the
// command's output to standard output. The output is copied to the
// clipboard and inserted above the current line.
//
pathbuf tmpfilenamebuf;
Pathbuf cmdstrbuf;
tmpfilenamebuf[0] = '\0'; // init to 'no tmpfile created'
auto pSrcFnm( StrPastAnyBlanks( d_textarg.pText ) ); // arg arg "!dir" paste
if( *pSrcFnm == '!' ) {
NOAUTO CPCChar pszCmd( pSrcFnm + 1 );
const auto tmpx( CompletelyExpandFName_wEnvVars( "$TMP:" DIRSEP_STR "paste.$k$" ) );
bcpy( tmpfilenamebuf, tmpx.c_str() );
0 && DBG( "tmp '%s'", tmpfilenamebuf );
pSrcFnm = tmpfilenamebuf;
cmdstrbuf.Sprintf( "%s >\"%s\" 2>&1", pszCmd, tmpfilenamebuf );
RunChildSpawnOrSystem( cmdstrbuf );
}
if( FBUF::FnmIsPseudo( pSrcFnm ) ) {
cmdstrbuf.Strcpy( pSrcFnm );
}
else {
CompletelyExpandFName_wEnvVars( BSOB(cmdstrbuf), pSrcFnm );
}
const auto pFBuf( FindFBufByName( cmdstrbuf ) );
if( pFBuf ) {
if( pFBuf->RefreshFailedShowError() ) {
return false;
}
FBOP::CopyLines( g_pFbufClipboard, 0, pFBuf, 0, pFBuf->LastLine() );
}
else { // couldntFindFile
g_pFbufClipboard->ReadOtherDiskFileNoCreateFailed( cmdstrbuf );
}
if( tmpfilenamebuf[0] ) {
unlinkOk( tmpfilenamebuf );
}
g_ClipboardType = LINEARG;
#endif
}
}
} // switch
0 && DBG( "g_ClipboardType = %04X", g_ClipboardType );
switch( g_ClipboardType ) {
default: return false;
case LINEARG: FBOP::CopyLines( g_CurFBuf(), g_CursorLine(), g_pFbufClipboard, 0, g_pFbufClipboard->LastLine() );
return true;
case STREAMARG: FBOP::CopyStream( g_CurFBuf(),
g_CursorCol() , g_CursorLine()
, g_pFbufClipboard
, 0 , 0
, FBOP::LineCols( g_pFbufClipboard, g_pFbufClipboard->LastLine() ), g_pFbufClipboard->LastLine()
);
return true;
case BOXARG: {
const COL boxWidth( FBOP::LineCols( g_pFbufClipboard, 0 ) ); // w/clipboard in BOXARG mode is assumed that all lines have sm len
if( boxWidth == 0 ) { return false; }
FBOP::CopyBox( g_CurFBuf(),
g_CursorCol(), g_CursorLine()
, g_pFbufClipboard
, 0, 0
, boxWidth - 1 , g_pFbufClipboard->LastLine()
);
}
return true;
}
}
GLOBAL_VAR ARG noargNoMeta; // s!b modified!
bool PutCharIntoCurfileAtCursor( char theChar, std::string &tmp1, std::string &tmp2 ) { PCFV;
if( pcf->CantModify() ) {
return false;
}
auto yLine( pcv->Cursor().lin );
auto xCol ( pcv->Cursor().col );
if( g_fWordwrap && g_iRmargin > 0 ) {
if( theChar == ' ' && xCol >= g_iRmargin ) {
const auto xIndent( FBOP::GetSoftcrIndent( pcf ) );
FBOP::CopyStream( pcf
, xCol , yLine
, nullptr
, xCol , yLine
, xIndent, yLine + 1
);
pcv->MoveCursor( yLine + 1, xIndent );
return true;
}