This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
/
EDLIN.ASM
1846 lines (1675 loc) · 53.8 KB
/
EDLIN.ASM
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
title EDLIN for MSDOS 2.0
;-----------------------------------------------------------------------;
; REVISION HISTORY: ;
; ;
; V1.02 ;
; ;
; V2.00 9/13/82 M.A. Ulloa ;
; Modified to use Pathnames in command line file ;
; specification, modified REPLACE to use an empty ;
; string intead of the old replace string when this ;
; is missing, and search and replace now start from ;
; first line of buffer (like old version of EDLIN) ;
; instead than current+1 line. Also added the U and ;
; V commands that search (replace) starting from the ;
; current+1 line. ;
; ;
; 9/15/82 M.A. Ulloa ;
; Added the quote character (^V). ;
; ;
; 9/16/82 M.A. Ulloa ;
; Corrected bug about use of quote char when going ;
; into default insert mode. Also corrected the problem ;
; with ^Z being the end of file marker. End of file is ;
; reached when an attempt to read returns less chars ;
; than requested. ;
; ;
; 9/17/82 M.A. Ulloa ;
; Corrected bug about boundaries for Copy ;
; ;
; 10/4/82 Rev. 1 M.A. Ulloa ;
; The IBM version now does NOT have the U and V ;
; commands. The MSDOS version HAS the U and V commands. ;
; Added the B switch, and modified the effect of ;
; the quote char. ;
; ;
; 10/7/82 Rev. 2 M.A. Ulloa ;
; Changed the S and R commands to start from the ;
; current line+1 (as U and V did). Took away U and V in ;
; all versions. ;
; ;
; 10/13/82 Rev. 3 M.A. Ulloa ;
; Now if parameter1 < 1 then parameter1 = 1 ;
; ;
; 10/15/82 Rev. 4 M.A. Ulloa ;
; Param4 if specified must be an absolute number that ;
; reprecents the count. ;
; ;
; 10/18/82 Rev. 5 M.A. Ulloa ;
; Fixed problem with trying to edit files with the ;
; same name as directories. Also, if the end of file is ;
; reached it checks that a LF is the last character, ;
; otherwise it inserts a CRLF pair at the end. ;
; ;
; 10/20/82 Rev. 6 M.A.Ulloa ;
; Changed the text of some error messages for IBM and ;
; rewrite PAGE. ;
; ;
; 10/25/82 Rev. 7 M.A.Ulloa ;
; Made all messages as in the IBM vers. ;
; ;
; 10/28/82 Rev. 8 M.A.Ulloa ;
; Corrected problem with parsing for options. ;
; ;
; Rev. 9 Aaron Reynolds ;
; Made error messages external. ;
; ;
; 12/08/82 Rev. 10 M.A. Ulloa ;
; Corrected problem arising with having to restore ;
; the old directory in case of a file name error. ;
; ;
; 12/17/82 Rev. 11 M.A. Ulloa ;
; Added the ROPROT equate for R/O file protection. ;
; It causes only certain operations (L,P,S,W,A, and Q) ;
; to be allowed on read only files. ;
; ;
; 12/29/82 Rev. 12 M.A. Ulloa :
; Added the creation error message. ;
; ;
; 4/14/83 Rev. 13 N.Panners ;
; Fixed bug in Merge which lost char if not ^Z. ;
; Fixed bug in Copy to correctly check ;
; for full buffers. ;
; ;
; ;
; 7/23/83 Rev. 14 N.Panners ;
; Split EDLIN into two seperate modules to ;
; allow assembly of sources on an IBM PC ;
; EDLIN and EDLPROC ;
; ;
;-----------------------------------------------------------------------;
FALSE EQU 0
TRUE EQU NOT FALSE
KANJI EQU FALSE
roprot equ true ;set to TRUE if protection to r/o files
; desired.
FCB EQU 5CH
Comand_Line_Length equ 128
quote_char equ 16h ;quote character = ^V
PAGE
.xlist
INCLUDE DOSSYM.ASM
.list
SUBTTL Contants and Data areas
PAGE
PROMPT EQU "*"
STKSIZ EQU 80H
CODE SEGMENT PUBLIC
CODE ENDS
CONST SEGMENT PUBLIC WORD
CONST ENDS
DATA SEGMENT PUBLIC WORD
DATA ENDS
DG GROUP CODE,CONST,DATA
CONST SEGMENT PUBLIC WORD
EXTRN BADDRV:BYTE,NDNAME:BYTE,bad_vers_err:BYTE,opt_err:BYTE
EXTRN NOBAK:BYTE,BADCOM:BYTE,NEWFIL:BYTE,DEST:BYTE,MRGERR:BYTE
EXTRN NODIR:BYTE,DSKFUL:BYTE,MEMFUL:BYTE,FILENM:BYTE
EXTRN NOSUCH:BYTE,TOOLNG:BYTE,EOF:BYTE,ro_err:byte,bcreat:byte
PUBLIC TXT1,TXT2,FUDGE,USERDIR,HARDCH
BAK DB "BAK"
make db "***MAUlloa/Microsoft/V20***"
rev db "14"
if roprot ;***** R/O *****
roflag db 0 ; =1 if file is r/o
endif
fourth db 0 ;fourth parameter flag
loadmod db 0 ;Load mode flag, 0 = ^Z marks the
; end of a file, 1 = viceversa.
hardch dd ?
the_root db 0 ;root directory flag
fudge db 0 ;directory changed flag
user_drive db 0
optchar db "-"
dirchar db "/",0
userdir db "/",0
db (dirstrlen) dup(0)
fname_buffer db Comand_Line_Length dup(0)
;-----------------------------------------------------------------------;
TXT1 DB 0,80H DUP (?)
TXT2 DB 0,80H DUP (?)
DELFLG DB 0
CONST ENDS
DATA SEGMENT PUBLIC WORD
PUBLIC QFLG,FCB2,OLDLEN,PARAM1,PARAM2,OLDDAT,SRCHFLG
PUBLIC COMLINE,NEWLEN,SRCHMOD,CURRENT,LSTFND,NUMPOS
PUBLIC LSTNUM,SRCHCNT,POINTER,START,ENDTXT,USER_DRIVE
;-----------------------------------------------------------------------;
; Be carefull when adding parameters, they have to follow the
; order in which they apperar here. (this is a table, ergo it
; is indexed thru a pointer, and random additions will cause the
; wrong item to be accessed). Also param4 is known to be the
; count parameter, and known to be the fourth entry in the table
; so it receives special treatment. (See GETNUM)
PARAM1 DW 1 DUP (?)
PARAM2 DW 1 DUP (?)
PARAM3 DW 1 DUP (?)
PARAM4 DW 1 DUP (?)
;-----------------------------------------------------------------------;
PTR_1 DW 1 DUP (?)
PTR_2 DW 1 DUP (?)
PTR_3 DW 1 DUP (?)
COPYSIZ DW 1 DUP (?)
OLDLEN DW 1 DUP (?)
NEWLEN DW 1 DUP (?)
LSTFND DW 1 DUP (?)
LSTNUM DW 1 DUP (?)
NUMPOS DW 1 DUP (?)
SRCHCNT DW 1 DUP (?)
CURRENT DW 1 DUP (?)
POINTER DW 1 DUP (?)
ONE4TH DW 1 DUP (?)
THREE4TH DW 1 DUP (?)
LAST DW 1 DUP (?)
ENDTXT DW 1 DUP (?)
COMLINE DW 1 DUP (?)
LASTLIN DW 1 DUP (?)
COMBUF DB 82H DUP (?)
EDITBUF DB 258 DUP (?)
EOL DB 1 DUP (?)
FCB2 DB 37 DUP (?)
FCB3 DB 37 DUP (?)
fake_fcb db 37 dup (?) ;fake for size figuring
QFLG DB 1 DUP (?)
HAVEOF DB 1 DUP (?)
ENDING DB 1 DUP (?)
SRCHFLG DB 1 DUP (?)
amnt_req dw 1 dup (?) ;ammount of bytes requested to read
olddat db 1 dup (?) ;Used in replace and search,
; replace by old data flag (1=yes)
srchmod db 1 dup (?) ;Search mode: 1=from current+1 to
; end of buffer, 0=from beg. of
; buffer to the end (old way).
MOVFLG DB 1 DUP (?)
DB STKSIZ DUP (?)
STACK LABEL BYTE
START LABEL WORD
DATA ENDS
SUBTTL Main Body
PAGE
CODE SEGMENT PUBLIC
ASSUME CS:DG,DS:DG,SS:DG,ES:DG
EXTRN QUIT:NEAR,QUERY:NEAR,FNDFIRST:NEAR,FNDNEXT:NEAR
EXTRN UNQUOTE:NEAR,LF:NEAR,CRLF:NEAR,OUT:NEAR
EXTRN REST_DIR:NEAR,KILL_BL:NEAR,INT_24:NEAR
EXTRN FINDLIN:NEAR,SHOWNUM:NEAR,SCANLN:NEAR
if Kanji
EXTRN TESTKANJ:NEAR
endif
PUBLIC CHKRANGE
ORG 100H
EDLIN:
JMP SIMPED
edl_pad db 0e00h dup (?)
HEADER DB "Vers 2.14"
NONAME:
MOV DX,OFFSET DG:NDNAME
ERRJ: JMP xERROR
SIMPED:
MOV BYTE PTR [ENDING],0
MOV SP,OFFSET DG:STACK
;Code to print header
; PUSH AX
; MOV DX,OFFSET DG:HEADER
; MOV AH,STD_CON_STRING_OUTPUT
; INT 21H
; POP AX
;----- Check Version Number --------------------------------------------;
push ax
mov ah,Get_Version
int 21h
cmp al,2
jae vers_ok ; version >= 2, enter editor
mov dx,offset dg:bad_vers_err
jmp short errj
;-----------------------------------------------------------------------;
vers_ok:
;----- Process Pathnames -----------------------------------------------;
mov ax,(char_oper shl 8) ;get switch character
int 21h
cmp dl,"/"
jnz slashok ;if not / , then not PC
mov [dirchar],"\" ;in PC, dir separator = \
mov [userdir],"\"
mov [optchar],"/" ;in PC, option char = /
slashok:
mov si,81h ;point to cammand line
call kill_bl
cmp al,13 ;A carriage return?
je noname ;yes, file name missing
mov di,offset dg:fname_buffer
xor cx,cx ;zero pathname length
next_char:
stosb ;put patname in buffer
inc cx
lodsb
cmp al,' '
je xx1
cmp al,13 ; a CR ?
je name_copied
cmp al,[optchar] ; an option character?
je an_option
jmp short next_char
xx1:
dec si
call kill_bl
cmp al,[optchar]
jne name_copied
an_option:
lodsb ;get the option
cmp al,'B'
je b_opt
cmp al,'b'
je b_opt
mov dx,offset dg:opt_err ;bad option specified
jmp xerror
b_opt:
mov [loadmod],1
name_copied:
mov byte ptr dg:[di],0 ;nul terminate the pathname
if roprot ;***** R/O *****
;----- Check that file is not R/O --------------------------------------;
push cx ;save character count
mov dx,offset dg:fname_buffer
mov al,0 ;get attributes
mov ah,chmod
int 21h
jc attr_are_ok
and cl,00000001b ;mask all but: r/o
jz attr_are_ok ;if all = 0 then file ok to edit,
mov dg:[roflag],01h ;otherwise: Error (GONG!!!)
attr_are_ok:
pop cx ;restore character count
endif
;----- Scan for directory ----------------------------------------------;
dec di ;adjust to the end of the pathname
IF KANJI
mov dx,offset dg: fname_buffer
PUSH DX
PUSH DI
MOV BX,DI
MOV DI,DX
DELLOOP:
CMP DI,BX
Jae GOTDELE
MOV AL,[DI]
INC DI
CALL TESTKANJ
JZ NOTKANJ11
INC DI
JMP DELLOOP
NOTKANJ11:
cmp al,dg:[dirchar]
JNZ DELLOOP
MOV DX,DI ;Point to char after '/'
DEC DX
DEC DX ;Point to char before '/'
JMP DELLOOP
GOTDELE:
MOV DI,DX
POP AX ;Initial DI
POP DX
SUB AX,DI ;Distance moved
SUB CX,AX ;Set correct CX
CMP DX,DI
JB sj1 ;Found a pathsep
JA sj2 ;Started with a pathsep, root
MOV AX,[DI]
CALL TESTKANJ
JNZ same_dirj
XCHG AH,AL
cmp al,dg:[dirchar]
jz sj1 ;One character directory
same_dirj:
ELSE
mov al,dg:[dirchar] ;get directory separator character
std ;scan backwards
repnz scasb ;(cx has the pathname length)
cld ;reset direction, just in case
jz sj1
ENDIF
jmp same_dir ;no dir separator char. found, the
; file is in the current directory
; of the corresponding drive. Ergo,
; the FCB contains the data already.
sj1:
jcxz sj2 ;no more chars left, it refers to root
cmp byte ptr [di],':' ;is the prvious character a disk def?
jne not_root
sj2:
mov dg:[the_root],01h ;file is in the root
not_root:
inc di ;point to dir separator char.
mov al,0
stosb ;nul terminate directory name
pop ax
push di ;save pointer to file name
mov dg:[fudge],01h ;remember that the current directory
; has been changed.
;----- Save current directory for exit ---------------------------------;
mov ah,get_default_drive ;save current drive
int 21h
mov dg:[user_drive],al
mov dl,byte ptr ds:[fcb] ;get specified drive if any
or dl,dl ;default disk?
jz same_drive
dec dl ;adjust to real drive (a=0,b=1,...)
mov ah,set_default_drive ;change disks
int 21h
cmp al,-1 ;error?
jne same_drive
mov dx,offset dg:baddrv
jmp xerror
same_drive:
mov ah,get_default_dpb
int 21h
assume ds:nothing
cmp al,-1 ;bad drive? (should always be ok)
jne drvisok
mov dx,offset dg:baddrv
jmp xerror
drvisok:
cmp [bx.dpb_current_dir],0
je curr_is_root
mov si,bx
add si,dpb_dir_text
mov di,offset dg:userdir + 1
dir_save_loop:
lodsb
stosb
or al,al
jnz dir_save_loop
curr_is_root:
push cs
pop ds
assume ds:dg
;----- Change directories ----------------------------------------------;
cmp [the_root],01h
mov dx,offset dg:[dirchar] ;assume the root
je sj3
mov dx,offset dg:[fname_buffer]
sj3:
mov ah,chdir ;change directory
int 21h
mov dx,offset dg:baddrv
jnc no_errors
jmp xerror
no_errors:
;----- Set Up int 24 intercept -----------------------------------------;
mov ax,(get_interrupt_vector shl 8) or 24h
int 21h
mov word ptr [hardch],bx
mov word ptr [hardch+2],es
mov ax,(set_interrupt_vector shl 8) or 24h
mov dx,offset dg:int_24
int 21h
push cs
pop es
;----- Parse filename to FCB -------------------------------------------;
pop si
mov di,fcb
mov ax,(parse_file_descriptor shl 8) or 1
int 21h
push ax
;-----------------------------------------------------------------------;
same_dir:
pop ax
OR AL,AL
MOV DX,OFFSET DG:BADDRV
jz sj4
jmp xerror
sj4:
CMP BYTE PTR DS:[FCB+1]," "
jnz sj5
jmp noname
sj5:
MOV SI,OFFSET DG:BAK
MOV DI,FCB+9
MOV CX,3
;File must not have .BAK extension
REPE CMPSB
JZ NOTBAK
;Open input file
MOV AH,FCB_OPEN
MOV DX,FCB
INT 21H
MOV [HAVEOF],AL
OR AL,AL
JZ HAVFIL
;----- Check that file is not a directory ------------
mov ah,fcb_create
mov dx,fcb
int 21h
or al,al
jz sj50 ;no error found
mov dx,offset dg:bcreat ;creation error
jmp xerror
sj50:
mov ah,fcb_close ;no error, close the file
mov dx,fcb
int 21h
mov ah,fcb_delete ;delete the file
mov dx,fcb
int 21h
;-----------------------------------------------------
MOV DX,OFFSET DG:NEWFIL
MOV AH,STD_CON_STRING_OUTPUT
INT 21H
HAVFIL:
MOV SI,FCB
MOV DI,OFFSET DG:FCB2
MOV CX,9
REP MOVSB
MOV AL,"$"
STOSB
STOSB
STOSB
MAKFIL:
;Create .$$$ file to make sure directory has room
MOV DX,OFFSET DG:FCB2
MOV AH,FCB_CREATE
INT 21H
OR AL,AL
JZ SETUP
CMP BYTE PTR [DELFLG],0
JNZ NOROOM
CALL DELBAK
JMP MAKFIL
NOROOM:
MOV DX,OFFSET DG:NODIR
JMP xERROR
NOTBAK:
MOV DX,OFFSET DG:NOBAK
JMP xERROR
SETUP:
XOR AX,AX
MOV WORD PTR DS:[FCB+fcb_RR],AX ;Set RR field to zero
MOV WORD PTR DS:[FCB+fcb_RR+2],AX
MOV WORD PTR [FCB2+fcb_RR],AX
MOV WORD PTR [FCB2+fcb_RR+2],AX
INC AX
MOV WORD PTR DS:[FCB+fcb_RECSIZ],AX ;Set record length to 1
MOV WORD PTR [FCB2+fcb_RECSIZ],AX
MOV DX,OFFSET DG:START
MOV DI,DX
MOV AH,SET_DMA
INT 21H
MOV CX,DS:[6]
DEC CX
MOV [LAST],CX
TEST BYTE PTR [HAVEOF],-1
JNZ SAVEND
SUB CX,OFFSET DG:START ;Available memory
SHR CX,1 ;1/2 of available memory
MOV AX,CX
SHR CX,1 ;1/4 of available memory
MOV [ONE4TH],CX ;Save amount of 1/4 full
ADD CX,AX ;3/4 of available memory
MOV DX,CX
ADD DX,OFFSET DG:START
MOV [THREE4TH],DX ;Save pointer to 3/4 full
;Read in input file
MOV DX,FCB
MOV AH,FCB_RANDOM_READ_BLOCK
mov [amnt_req],cx ;save ammount of chars requested
INT 21H
CALL SCANEOF
ADD DI,CX ;Point to last byte
SAVEND:
CLD
MOV BYTE PTR [DI],1AH
MOV [ENDTXT],DI
MOV BYTE PTR [COMBUF],128
MOV BYTE PTR [EDITBUF],255
MOV BYTE PTR [EOL],10
MOV [POINTER],OFFSET DG:START
MOV [CURRENT],1
MOV [PARAM1],1
TEST BYTE PTR [HAVEOF],-1
JNZ COMMAND
CALL APPEND
COMMAND:
MOV SP, OFFSET DG:STACK
MOV AX,(SET_INTERRUPT_VECTOR SHL 8) OR 23H
MOV DX,OFFSET DG:ABORTCOM
INT 21H
MOV AL,PROMPT
CALL OUT
MOV DX,OFFSET DG:COMBUF
MOV AH,STD_CON_STRING_INPUT
INT 21H
MOV [COMLINE],OFFSET DG:COMBUF + 2
MOV AL,10
CALL OUT
PARSE:
MOV [PARAM2],0
MOV [PARAM3],0
MOV [PARAM4],0
mov [fourth],0 ;reset the fourth parameter flag
MOV BYTE PTR [QFLG],0
MOV SI,[COMLINE]
MOV BP,OFFSET DG:PARAM1
XOR DI,DI
CHKLP:
CALL GETNUM
MOV [BP+DI],DX
INC DI
INC DI
CALL SKIP1
CMP AL,","
JNZ CHKNXT
INC SI
CHKNXT:
DEC SI
CMP DI,8
JB CHKLP
CALL SKIP
CMP AL,"?"
JNZ DISPATCH
MOV [QFLG],AL
CALL SKIP
DISPATCH:
CMP AL,5FH
JBE UPCASE
AND AL,5FH
UPCASE:
MOV DI,OFFSET DG:COMTAB
MOV CX,NUMCOM
REPNE SCASB
JNZ COMERR
MOV BX,CX
MOV AX,[PARAM2]
OR AX,AX
JZ PARMOK
CMP AX,[PARAM1]
JB COMERR ;Param. 2 must be >= param 1
PARMOK:
MOV [COMLINE],SI
if roprot ;***** R/O *****
cmp [roflag],01 ;file r/o?
jne paramok2
cmp byte ptr [bx+rotable],01 ;operation allowed?
je paramok2
mov dx,offset dg:ro_err ;error
jmp short comerr1
paramok2:
endif
SHL BX,1
CALL [BX+TABLE]
COMOVER:
MOV SI,[COMLINE]
CALL SKIP
CMP AL,0DH
JZ COMMANDJ
CMP AL,1AH
JZ DELIM
CMP AL,";"
JNZ NODELIM
DELIM:
INC SI
NODELIM:
DEC SI
MOV [COMLINE],SI
JMP PARSE
COMMANDJ:
JMP COMMAND
SKIP:
LODSB
SKIP1:
CMP AL," "
JZ SKIP
RET1: RET
CHKRANGE:
CMP [PARAM2],0
JZ RET1
CMP BX,[PARAM2]
JBE RET1
COMERR:
MOV DX,OFFSET DG:BADCOM
COMERR1:
MOV AH,STD_CON_STRING_OUTPUT
INT 21H
JMP COMMAND
GETNUM:
CALL SKIP
cmp di,6 ;Is this the fourth parameter?
jne sk1
mov [fourth],1 ;yes, set the flag
sk1:
CMP AL,"."
JZ CURLIN
CMP AL,"#"
JZ MAXLIN
CMP AL,"+"
JZ FORLIN
CMP AL,"-"
JZ BACKLIN
MOV DX,0
MOV CL,0 ;Flag no parameter seen yet
NUMLP:
CMP AL,"0"
JB NUMCHK
CMP AL,"9"
JA NUMCHK
CMP DX,6553 ;Max line/10
JAE COMERR ;Ten times this is too big
MOV CL,1 ;Parameter digit has been found
SUB AL,"0"
MOV BX,DX
SHL DX,1
SHL DX,1
ADD DX,BX
SHL DX,1
CBW
ADD DX,AX
LODSB
JMP SHORT NUMLP
NUMCHK:
CMP CL,0
JZ RET1
OR DX,DX
JZ COMERR ;Don't allow zero as a parameter
RET
CURLIN:
cmp [fourth],1 ;the fourth parameter?
je comerra ;yes, an error
MOV DX,[CURRENT]
LODSB
RET
MAXLIN:
cmp [fourth],1 ;the fourth parameter?
je comerra ;yes, an error
MOV DX,-2
LODSB
RET
FORLIN:
cmp [fourth],1 ;the fourth parameter?
je comerra ;yes, an error
CALL GETNUM
ADD DX,[CURRENT]
RET
BACKLIN:
cmp [fourth],1 ;the fourth parameter?
je comerra ;yes, an error
CALL GETNUM
MOV BX,[CURRENT]
SUB BX,DX
jns sk2 ;if below beg of buffer then default to the
mov bx,1 ; beg of buffer (line1)
sk2:
MOV DX,BX
RET
comerra:
jmp comerr
COMTAB DB "QTCMWASRDLPIE;",13
NUMCOM EQU $-COMTAB
;-----------------------------------------------------------------------;
; Carefull changing the order of the next two tables. They are
; linked and chnges should be be to both.
TABLE DW NOCOM ;No command--edit line
DW NOCOM
DW ENDED
DW INSERT
DW PAGE
DW LIST
DW DELETE
dw replac_from_curr ;replace from current+1 line
dw search_from_curr ;search from current+1 line
DW APPEND
DW EWRITE
DW MOVE
DW COPY
DW MERGE
if roprot ;***** R/O *****
DW QUIT1
else
DW QUIT
endif
if roprot ;***** R/O *****
;-----------------------------------------------------------------------;
; If = 1 then the command can be executed with a file that
; is r/o. If = 0 the command can not be executed, and error.
ROTABLE db 0 ;NOCOM
db 0 ;NOCOM
db 0 ;ENDED
db 0 ;INSERT
db 1 ;PAGE
db 1 ;LIST
db 0 ;DELETE
db 0 ;replac_from_curr
db 1 ;search_from_curr
db 1 ;APPEND
db 1 ;EWRITE
db 0 ;MOVE
db 0 ;COPY
db 0 ;MERGE
db 1 ;QUIT
;-----------------------------------------------------------------------;
endif
if roprot ;***** R/O *****
quit1:
cmp [roflag],01 ;are we in r/o mode?
jne q3 ;no query....
MOV DX,OFFSET DG:FCB2 ;yes, quit without query.
MOV AH,FCB_CLOSE
INT 21H
MOV AH,FCB_DELETE
INT 21H
call rest_dir ;restore directory if needed
INT 20H
q3:
call quit
endif
SCANEOF:
cmp [loadmod],0
je sj52
;----- Load till physical end of file
cmp cx,word ptr[amnt_req]
jb sj51
xor al,al
inc al ;reset zero flag
ret
sj51:
jcxz sj51b
push di ;get rid of any ^Z at the end of the file
add di,cx
dec di ;points to last char
cmp byte ptr [di],1ah
pop di
jne sj51b
dec cx
sj51b:
xor al,al ;set zero flag
call check_end ;check that we have a CRLF pair at the end
ret
;----- Load till first ^Z is found
sj52:
PUSH DI
PUSH CX
MOV AL,1AH
or cx,cx
jz not_found ;skip with zero flag set
REPNE SCASB ;Scan for end of file mark
jnz not_found
LAHF ;Save flags momentarily
inc cx ;include the ^Z
SAHF ;Restore flags
not_found:
mov di,cx ;not found at the end
POP CX
LAHF ;Save flags momentarily
SUB CX,DI ;Reduce byte count if EOF found
SAHF ;Restore flags
POP DI
call check_end ;check that we have a CRLF pair at the end
RET2: RET
;-----------------------------------------------------------------------
; If the end of file was found, then check that the last character
; in the file is a LF. If not put a CRLF pair in.
check_end:
jnz not_end ;end was not reached
pushf ;save return flag
push di ;save pointer to buffer
add di,cx ;points to one past end on text
dec di ;points to last character
cmp di,offset dg:start
je check_no
cmp byte ptr[di],0ah ;is a LF the last character?
je check_done ;yes, exit
check_no:
mov byte ptr[di+1],0dh ;no, put a CR
inc cx ;one more char in text
mov byte ptr[di+2],0ah ;put a LF
inc cx ;another character at the end
check_done:
pop di
popf
not_end:
ret
NOMOREJ:JMP NOMORE
APPEND:
TEST BYTE PTR [HAVEOF],-1
JNZ NOMOREJ
MOV DX,[ENDTXT]
CMP [PARAM1],0 ;See if parameter is missing
JNZ PARMAPP
CMP DX,[THREE4TH] ;See if already 3/4ths full
JAE RET2 ;If so, then done already
PARMAPP:
MOV DI,DX
MOV AH,SET_DMA
INT 21H
MOV CX,[LAST]
SUB CX,DX ;Amount of memory available
jnz sj53
jmp memerr
sj53:
MOV DX,FCB
mov [amnt_req],cx ;save ammount of chars requested
MOV AH,FCB_RANDOM_READ_BLOCK
INT 21H ;Fill memory with file data
MOV [HAVEOF],AL
PUSH CX ;Save actual byte count
CALL SCANEOF
JNZ NOTEND
MOV BYTE PTR [HAVEOF],1 ;Set flag if 1AH found in file
NOTEND:
XOR DX,DX
MOV BX,[PARAM1]
OR BX,BX
JNZ COUNTLN
MOV AX,DI
ADD AX,CX ;First byte after loaded text
CMP AX,[THREE4TH] ;See if we made 3/4 full
JBE COUNTLN
MOV DI,[THREE4TH]
MOV CX,AX
SUB CX,DI ;Length remaining over 3/4