-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDITO.PRG
533 lines (482 loc) · 21.1 KB
/
EDITO.PRG
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
STATIC filedit:=NIL
function myeditor(menuparam)
local choice,color_buff,screen_buff,oldfile,old_scre,Myexit,dir,fildir
color_buff:=setcolor()
filedit=if(filedit==NIL,TextDir+'Noname.txt',filedit)
if menuparam==NIL
// do p_edit
else
desc=fopen(filedit)
len=fseek(desc,0,2)
fclose(desc)
do case
case menuparam=1
desc=fopen(filedit)
len=fseek(desc,0,2)
fclose(desc)
if len>=30000
al_box({" ‚ë¡à ë© ä ©« ®ç¥ì ¡®«ì让 ¤«ï í⮣® । ªâ®à "})
else
save screen to old_scre
SET COLOR TO N/BG
colorwin(10,25,14,63,'n/n')
@ 09,23,13,61 BOX " "
@ 09,23 SAY "ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ·"
@ 10,23 SAY "³ ’¨¯ । ªâ¨à㥬®£® ⥪áâ º"
@ 11,23 SAY "³"+space(37)+"º"
@ 12,23 SAY "³ ‘â ¤ àâë© ˜¨à®ª¨© º"
@ 13,23 SAY "ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
do while .t.
SET COLOR TO N/BG,n/g
@ 12,24 prompt " ‘â ¤ àâë© "
@ 12,48 prompt " ˜¨à®ª¨© "
menu to choice
do case
case choice=2
Keditor(filedit,200)
case choice=1
Keditor(filedit,79)
otherwise
exit
endcase
enddo
choice=1
restore screen from old_scre
setcolor(color_buff)
endif
case menuparam=11
if len>=30000
al_box({" ‚ë¡à ë© ä ©« ®ç¥ì ¡®«ì让 ¤«ï í⮣® । ªâ®à "})
else
Keditor(filedit,79)
endif
case menuparam=12
if len>=30000
al_box({" ‚ë¡à ë© ä ©« ®ç¥ì ¡®«ì让 ¤«ï í⮣® । ªâ®à "})
else
Keditor(filedit,200)
endif
case menuparam=2
save screen
colorwin(11,25,14,61,'n/n')
@ 10,23,13,59 BOX " "
@ 10,23 SAY "ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ·"
@ 11,23 SAY "³ “ª ¦¨â¥ ⥪áâ ¤«ï à ¡®âë º"
@ 12,23 SAY "³"+space(35)+"º"
@ 13,23 SAY "ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
oldfile=MYupper(filedit)
oldfile=oldfile+space(35-len(oldfile))
set color to w+/bg
set cursor on
set confirm on
@ 12,24 get oldfile
read
set cursor off
set confir off
Clear Typeahead
if updated()
filedit=alltrim(MYUpper(oldfile))
if .not.file(filedit)
if yes_or_not(' â®â ä ©« ¤¨áª¥ ®âáãâá¢ã¥â ! ',;
' •®â¨â¥ ᮧ¤ âì ®¢ë© ⥪áâ ?')
keyboard chr(5)
endif
else
keyboard chr(5)
endif
endif
restore screen
setcolor(color_buff)
case menuparam=3
if al_box({'‚ë ¤¥©áâ¢¨â¥«ì® å®â¨â¥ 㤠«¨âì ä ©«',;
''+filedit+' ?'},2,,,,,,,,"gr+/r+,w/b+,,,gr/r+")=1
deletefile(filedit)
Al_Box({'” ©« "'+filedit+'" 㤠«¥'},1)
filedit=diskname()+':'+dirname(diskname())+'\TEXT`S\Noname.txt'
setcolor(color_buff)
endif
case menuparam=4
tmpfile=GetFile(dir,5)
filedit=MYupper(if(empty(tmpfile),filedit,tmpfile))
if .not.empty(tmpfile)
keyboard chr(5)+chr(5)+chr(5)+chr(13)+chr(13)
endif
setcolor(color_buff)
endcase
endif
return NIL
//----------------- ’¥ªáâ®¢ë© à¥¤ ªâ®à
func Keditor(memofile,line_length)
set key 141 to rusH
private prev_val,deja_vu,eresume,altered,update,browse,;
use_func,ufunc,ins_on,word_wrap,tabsize,prev_scr,prev_col,first,;
altered_,bell,desc,len,memofil:=memofile
prev_col=setcolor()
prev_scr=win_save(0,0,maxrow(),maxcol())
desc=fopen(memofile)
len=fseek(desc,0,2)
fclose(desc)
//IF len>30000
// Al_Box({"ˆ§¢¨¨â¥, ® íâ®â ä ©« ᫨誮¬ ¢¥«¨ª"},1,{" ‡ ª®ç¨âì "})
// Return NIL
//ENDIF
setcursor(6,7,.t.)
setlastkey(19)
prev_memo = ""
ret_val = 0
deja_vu = .F.
eresume = .F.
altered = .F.
update = .T.
browse = .T.
&& line_length = 200
use_func = .T.
ufunc = "mfunc"
ins_on = .F.
scrl_on = .F.
word_wrap = .T.
tabsize = 8
set cursor on
Myexit=.f.
if .not.csetbell()
SET BELL ON
bell=.f.
endif
*SET SCOREBOARD OFF
DO WHILE .T.
altered=.f.
IF .NOT. eresume
IF MyExit = .t.
exit
ENDIF
IF use_func
ufunc = "mfunc"
ELSE
IF browse
ufunc = ""
ELSE
ufunc = .F.
ENDIF
ENDIF
IF .NOT. (prev_memo == memofile)
usr_memo = MEMOREAD(memofile)
prev_memo = memofile
line_num = 1
col_num = 0
rel_row = 0
rel_col = 0
altered = .F.
ENDIF
set color to n/w
@ 0,0 say space(80)
@ maxrow(),00 say space(80)
@ maxrow(),0 SAY center(LOWER(memofile),80,' ',.t.)
if line_length>79
@ 0,68 say '[‘ªà®««¨£]'
else
@ 0,68 say '[ ]'
endif
set color to +w/b
@ 1,0 clear to maxrow()-1,maxcol()
ENDIF
init_count = 1
deja_vu = .F.
eresume = .F.
altered=.f.
altered_=.f.
usr_memo = MEMOEDIT(usr_memo,1,0,maxrow()-1,maxcol(), update, ufunc,line_length,;
tabsize,line_num, 0, rel_row, rel_col)
IF .NOT. memofile == "none" .AND. .NOT. EMPTY(usr_memo) .AND. ret_val = 23
altered = .F.
IF .NOT. MEMOWRIT(memofile,hardcr(usr_memo))
al_box({'Žè¨¡ª § ¯¨á¨ ä ©« '+MemoFile})
// al_box({'Žè¨¡ª § ¯¨á¨ ¤¨áª '+diskname()})
exit
ENDIF
if Myexit=.f.
set color to n/w
@ 0,0 say space(80)
set color to +w/b
keyboard chr(19)
endif
ENDIF
if lastkey()=27
exit
endif
ENDDO
if .not.bell
set bell off
endif
setcursor(2,7,.t.)
win_rest(prev_scr)
setcolor(prev_col)
set cursor off
set key 141 to
return NIL
****
* mfunc()
*
* memoedit user function
****
FUNCTION mfunc
PARAMETERS mode, line, col
PRIVATE keypress
keypress=lastkey()
if isdata(keypress).or.keypress=32.or.keypress=7.or.keypress=8.or.keypress=13;
.or.keypress=25.or.keypress=20
if !altered_
if keypress#13
set cursor off
set color to g+/w
@ 00,37 say chr(16)+chr(15)+chr(17)
colorwin(0,38,0,38,'*r+/w')
set color to w+/b
set cursor on
altered_=.t.
else
if ins_on
set cursor off
set color to g+/w
@ 00,37 say chr(16)+chr(15)+chr(17)
colorwin(0,38,0,38,'*r+/w')
set color to w+/b
set cursor on
altered_=.t.
endif
endif
endif
endif
ret_val = 0
DO CASE
CASE mode = 3
* initialization..global variables "init_count" and "deja_vu"
* control the initialization process..note that this is
* much simpler when the parameters passed to MEMOEDIT
* are known in advance (which is usually true)
IF init_count = 1
* set initial insert mode
ins_mode = READINSERT()
IF (ins_on .AND. .NOT. ins_mode) .OR.;
(.NOT. ins_on .AND. ins_mode)
* toggle insert mode
ret_val = 22
ELSE
* insert mode correct
init_count = 2
set color to n/w
@ 0,58 SAY IF(ins_on,"<‚áâ ¢ª >", "<‡ ¬¥ > ")
set color to +w/b
ENDIF
ENDIF
IF init_count = 2
* set initial scroll state (defaults ON if update OFF)
IF ((.NOT. scrl_on .AND. .NOT. update) .OR.;
(scrl_on .AND. update)) .AND. .NOT. deja_vu
* need to toggle
deja_vu = .T.
ret_val = 35
ELSE
* scroll state correct
set color to n+/w
init_count = 3
deja_vu = .F.
@ 0,49 SAY IF(scrl_on,chr(23),chr(25))
set color to +w/b
ENDIF
ENDIF
IF init_count = 3
* set initial word wrap..always defaults ON
IF .NOT. word_wrap .AND. .NOT. deja_vu
* need to toggle
deja_vu = .T.
ret_val = 34
ELSE
* word wrap correct
set color to n+/w
init_count = 4
deja_vu = .F.
@ 0,45 SAY IF(word_wrap,chr(31),chr(4))
set color to +w/b
ENDIF
ENDIF
IF init_count = 4
* finished initialization..note that if all defaults are
* correct we reach this point on the first call
if col_num#0
keyboard replicate(chr(4),col_num)
endif
ret_val = 0
ENDIF
CASE mode = 0
* idle
set cursor off
set color to n/w
@ 0,0 SAY "Line " + pad1(LTRIM(STR(line)), 4)
@ 0,10 SAY "Col " + pad1(LTRIM(STR(col+1)), 3)
set color to +w/b
set cursor on
OTHERWISE
* ®¡à ¡®âª ¦ âëå ª« ¢¨è
* § ¯®¬¨ î ¯¥à¥¬¥ë¥ ¤«ï ¢®§¬®¦®£® ¢®§¢à â ¢ । ªâ®à
line_num = line
col_num = col
rel_row = ROW()-1
rel_col = COL()-1
IF mode = 2
altered = .T.
ENDIF
Clear Typeahead
DO CASE
CASE keypress=2
ret_val=100
* keyboard chr(100)
CASE keypress=26
ret_val=26
* keyboard chr(26)
CASE keypress =28
save screen
set color to n/w
set cursor off
colorwin(7,4,18,76,"n+/n")
@ 06,03,17,75 BOX " "
@ 06,03 SAY "ÚÄÄÄÄÄÄÄÄÄÄ ‚ । ªâ®à¥ ¯®¤¤¥à¦¨¢ îâáï á«¥¤ãî騥 ª« ¢¨è¨ : ÄÄÄÄÄÄÄÄÄÄÄÄÄ¿"
@ 07,03 SAY "³"+space(71)+"³"
@ 08,03 SAY "³ Ctrl+Y - “¤ «¨âì áâபã F2 - ‡ ¯¨á âì ⥪áâ ¨ ¯à®¤®«¦¨âì ³"
@ 09,03 SAY "³ CtrL+T - “¤ «¨âì áâபã á¯à ¢ । ªâ¨à®¢ ¨¥ ³"
@ 10,03 SAY "³ Ctrl+I - ‚áâ ¢¨âì áâபã F5 - ¥ç âì ⥪ã饣® ⥪áâ ³"
@ 11,03 SAY "³ Ctrl+"+chr(27)+"- - ‘«®¢® ¢«¥¢® F6 - –¨ª«¨ç¥áª¨© ᤢ¨£ ¢ª«/¢ëª«. ³"
@ 12,03 SAY "³ Ctrl+-"+chr(26)+" - ‘«®¢® ¢¯à ¢® F7 - ¥à¥®á á«®¢ ¢ª«/¢ëª« ³"
@ 13,03 SAY "³"+space(71)+"³"
@ 14,03 SAY "³ "+chr(24)+" - ‘âà®çªã ¢¢¥àå "+chr(27)+" - ‘¨¬¢®« ¢«¥¢® Ins - ¥¦¨¬ ¢áâ ¢ª¨/§ ¬¥ë ³"
@ 15,03 SAY "³ "+chr(25)+" - ‘âà®çªã ¢¨§ "+chr(26)+" - ‘¨¬¢®« ¢¯à ¢® Esc - § ª®ç¨âì à ¡®âã ³"
@ 16,03 SAY "³"+space(71)+"³"
@ 17,03 SAY "ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
hot_inkey(0)
set cursor on
set color to +w/b
restore screen
CASE keypress =-4
set cursor off
if !altered
* ^W..ignore (disable)
Clear Typeahead
print_fi(,memofil)
ret_val = 32
Keyboard chr(27)
// response:=al_box({" ‚ë¡¥à¨â¥ ⨯ ¯¥ç ⨠⥪áâ "},;
// 3,{"®à¬ «ì ï","«®â ï","‚ë室"})
// do case
// case response=1
// copy_(memofil,'prn',1)
// case response=2
// copy_(memofil,'prn')
// endcase
else
Myerror(' ’¥ªáâ ¥ § ¯¨á ! ¥ç âì ¥¢®§¬®¦ ! ')
endif
restore screen
set color to w+/b
set cursor on
CASE keypress = -1
* Alt-W..write file
IF .NOT. altered_
* no changes to write
set color to n/w
@ maxrow(),0 SAY SPACE(80)
@ maxrow(),0 SAY center("‡ ¯¨á " + LOWER(memofil) + "",80,' ',.t.)
set color to w+/b
ret_val=32
ELSE
* write and resume
set color to n/w
@ maxrow(),0 SAY SPACE(80)
@ maxrow(),0 SAY center("‡ ¯¨áë¢ î " + LOWER(memofil) + "...",80,' ',.t.)
set color to w+/b
ret_val = 23
ENDIF
CASE keypress = 301 .OR. keypress = 27
* Esc/Alt-X..exit
IF .NOT. altered_
* no change
ret_val = 27
Myexit=.t.
ELSE
* changes have been made to memo
set cursor off
response:=al_box({"’¥ªáâ ¡ë« ¨§¬¥¥, ¢ë¡¥à¨â¥ ¤ «ì¥©è¥¥ ¤¥©á⢨¥"};
,3,{" ‘®åà ¨âì "," ¥ á®åà ïâì "," ¥ ¢ë室¨âì "})
DO CASE
CASE response = 3
* ignore
ret_val = 32
case response = 1
* save and exit
Myexit=.t.
Myerror(' ‡ ¯¨áë¢ î । ªâ¨àã¥¬ë© ä ©« ...',1)
ret_val = 23
setlastkey(27)
case response = 2
* abort
ret_val = 27
setlastkey(27)
ENDCASE
restore screen
set color to w+/b
set cursor on
ENDIF
CASE keypress = 289
* Alt-F..display file name
set color to n/w
@ maxrow(),0 SAY center(LOWER(memofil),80,' ',.t.)
CASE keypress = 25
* F3..delete line
altered_=.t.
ret_val = 25
CASE keypress = 9
* Ctrl+I - insert line
altered_=.t.
ret_val = 14
CASE keypress=20
altered_=.t.
ret_val=20
CASE keypress = -5 .AND. update
* F5..toggle word wrap
word_wrap = .NOT. word_wrap
ret_val = 34
set color to n+/w
@ 0,45 SAY IF(word_wrap,chr(31),chr(4))
set color to +w/b
CASE keypress = -6
* F6..toggle scroll lock
scrl_on = .NOT. scrl_on
ret_val = 35
set color to n+/w
@ 0,49 SAY IF(scrl_on,chr(23),chr(25))
set color to +w/b
CASE (keypress = 279 .OR. keypress = 22) .AND. update
* ^V/Ins/Alt-I..toggle insert mode
ins_on = .NOT. ins_on
ret_val = 22
set color to n/w
@ 0,58 SAY IF(ins_on,"<‚áâ ¢ª >", "<‡ ¬¥ > ")
set color to +w/b
ENDCASE
ENDCASE
RETURN ret_val
****
* pad()
*
* pad with spaces
****
FUNCTION pad1
PARAMETERS string, length
RETURN SUBSTR(string + SPACE(length), 1, length)
proc rusH
keyboard chr(72)
return
Function SetLastKey(KeyNum)
clear typeahead
keyboard chr(KeyNum)
Return NIL
* eof me.prg