This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
EDLIN.ASM
1843 lines (1612 loc) · 41.6 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
PAGE 60,132;
TITLE EDLIN
;======================= START OF SPECIFICATIONS =========================
;
; MODULE NAME: EDLIN.SAL
;
; DESCRIPTIVE NAME: LINE TEXT EDITOR
;
; FUNCTION: EDLIN IS A SIMPLE, LINE ORIENTED TEXT EDITOR. IT PROVIDES
; USERS OF DOS THE ABILITY TO CREATE AND EDIT TEXT FILES.
;
; ENTRY POINT: EDLIN
;
; INPUT: DOS COMMAND LINE
; EDLIN COMMANDS
; TEXT
;
; EXIT NORMAL: NA
;
; EXIT ERROR: NA
;
; INTERNAL REFERENCES:
;
; EXTERNAL REFERENCES:
;
; ROUTINE: EDLCMD1 - CONTAINS ROUTINES CALLED BY EDLIN
; EDLCMD1 - CONTAINS ROUTINES CALLED BY EDLIN
; EDLMES - CONTAINS ROUTINES CALLED BY EDLIN
;
; NOTES: THIS MODULE IS TO BE PREPPED BY SALUT WITH THE "PR" OPTIONS.
; LINK EDLIN+EDLCMD1+EDLCMD2+EDLMES+EDLPARSE
;
; REVISION HISTORY:
;
; AN000 VERSION 4.00 - REVISIONS MADE RELATE TO THE FOLLOWING:
;
; - IMPLEMENT SYSPARSE
; - IMPLEMENT MESSAGE RETRIEVER
; - IMPLEMENT DBCS ENABLING
; - ENHANCED VIDEO SUPPORT
; - EXTENDED OPENS
; - SCROLLING ERROR
;
; COPYRIGHT: "MS DOS EDLIN UTILITY"
; "VERSION 4.00 (C) COPYRIGHT 1988 Microsoft"
; "LICENSED MATERIAL - PROPERTY OF Microsoft"
;
;
; MICROSOFT REVISION HISTORY:
; ;
; V1.02 ;
; ;
; V2.00 9/13/82 M.A.U ;
; ;
; 2/23/82 Rev. 13 N. P ;
; Changed to 2.0 system calls. ;
; Added an error message for READ-ONLY files ;
; ;
; 11/7/83 Rev. 14 N. P ;
; Changed to .EXE format and added Printf ;
; ;
; V2.50 11/15/83 Rev. 1 M.A. U ;
; Official dos 2.50 version. Some random bug ;
; fixes and message changes. ;
; ;
; 11/30/83 Rev. 2 MZ ;
; Close input file before rename. ;
; Jmp to replace after line edit ;
; ;
; 02/01/84 Rev. 3 M.A. U ;
; Now it is called 3.00 dos. Repaired problem ;
; with using printf and having %'s as data. ;
; ;
; 02/15/84 MZ make out of space a fatal error with output;
; ;
; 03/28/84 MZ fixes bogus (totally) code in MOVE/COPY ;
; ;
; 04/02/84 MZ fixes DELETE and changes MOVE/COPY/EDIT ;
; ;
; V3.20 08/29/86 Rev. 1 S.M. G ;
; ;
; 08/29/86 M001 MSKK TAR 593, TAB MOVEMENT ;
; ;
; 08/29/86 M002 MSKK TAR 157, BLKMOVE 1,1,1m, 1,3,1m ;
; ;
; 08/29/86 M003 MSKK TAR 476, EDLCMD2,MAKECAPS,kana char;
; ;
; 08/29/86 M004 MSKK TAR 191, Append load size ;
; ;
; 08/29/86 M005 IBMJ TAR Transfer Load command ;
;
;
;======================= END OF SPECIFICATIONS =========================== ;
include edlequ.asm
SUBTTL Contants and Data areas
PAGE
extrn parser_command:near ;an000;SYSPARSE
CODE SEGMENT PUBLIC
CODE ENDS
CONST SEGMENT PUBLIC WORD
CONST ENDS
cstack segment stack
cstack ends
DATA SEGMENT PUBLIC WORD
DATA ENDS
DG GROUP CODE,CONST,cstack,DATA
CONST SEGMENT PUBLIC WORD
public bak,$$$file,delflg,loadmod,txt1,txt2
EXTRN BADDRV_ptr:word,NDNAME_ptr:word,bad_vers_err:byte,opt_err_ptr:word
EXTRN NOBAK_ptr:word,BADCOM_ptr:word,NEWFIL_ptr:word,DEST_ptr:word,MRGERR_ptr:word
EXTRN NODIR_ptr:word,FILENM_ptr:word,ro_err_ptr:word,bcreat_ptr:word
EXTRN TOO_MANY_ptr:word,lf_ptr:word,prompt_ptr:word
EXTRN MemFul_Ptr:word
BAK DB ".BAK",0
$$$FILE DB ".$$$",0
fourth db 0 ;fourth parameter flag
loadmod db 0 ;Load mode flag, 0 = ^Z marks the
; end of a file, 1 = viceversa.
optchar db "-"
TXT1 DB 0,80H DUP (?)
TXT2 DB 0,80H DUP (?)
DELFLG DB 0
fNew DB 0 ; old file
HAVEOF DB 0
CONST ENDS
cstack segment stack
db stksiz dup (?)
cstack ends
DATA SEGMENT PUBLIC WORD
extrn arg_buf_ptr:word ;an000;
extrn line_num_buf_ptr:word ;an000;
public path_name,ext_ptr,start,line_num,line_flag
public arg_buf,wrt_handle,temp_path
public current,pointer,qflg,editbuf,amnt_req,fname_len,delflg,lastlin
public olddat,oldlen,newlen,srchflg,srchmod
public comline,lstfnd,numpos,lstnum,last,srchcnt
public rd_handle,haveof,ending,three4th,one4th
public lc_adj ;an000;page length adj. factor
public lc_flag ;an000;display cont. flag
public pg_count ;an000;lines left on screen
public Disp_Len ;an000;display length
public Disp_Width ;an000;display width
public continue ;an000;boolean T/F
public temp_path ;an000;pointer to filespec buf
Video_Buffer label word ;an000;buffer for video attr
db 0 ;an000;dms;
db 0 ;an000;dms;
dw 14 ;an000;dms;
dw 0 ;an000;dms;
db ? ;an000;dms;
db 0 ;an000;dms;
dw ? ;an000;dms;# of colors
dw ? ;an000;dms;# of pixels in width
dw ? ;an000;dms;# of pixels in len.
dw ? ;an000;dms;# of chars in width
dw ? ;an000;dms;# of chars in length
video_org db ? ;an000;original video mode on
; entry to EDLIN.
lc_adj db ? ;an000;page length adj. factor
lc_flag db ? ;an000;display cont. flag
pg_count db ? ;an000;lines left on screen
Disp_Len db ? ;an000;display length
Disp_Width db ? ;an000;display width
continue db ? ;an000;boolean T/F
;-----------------------------------------------------------------------;
; This is a table that is sequentially filled via GetNum. Any additions to it
; must be placed in the correct position. Currently Param4 is known to be a
; count and thus is treated specially.
public param1,param2,Param3,param4,ParamCt
PARAM1 DW ?
PARAM2 DW ?
PARAM3 DW ?
PARAM4 DW ?
ParamCt DW ? ; count of passed parameters
if kanji ; Used in TESTKANJ:
LBTbl dd ? ; long pointer to lead byte table
endif ; in the dos (from syscall 63H)
;-----------------------------------------------------------------------;
PUBLIC PTR_1, PTR_2, PTR_3, OLDLEN, NEWLEN, LSTFND, LSTNUM, NUMPOS, SRCHCNT
PUBLIC CURRENT, POINTER, ONE4TH, THREE4TH, LAST, ENDTXT, COPYSIZ
PUBLIC COMLINE, LASTLIN, COMBUF, EDITBUF, EOL, QFLG, ENDING, SRCHFLG
PUBLIC PATH_NAME, FNAME_LEN, RD_HANDLE, TEMP_PATH, WRT_HANDLE, EXT_PTR
PUBLIC MRG_PATH_NAME, MRG_HANDLE, amnt_req, olddat, srchmod, MOVFLG, org_ds
if kanji
public lbtbl
endif
;
; These comprise the known state of the internal buffer. All editing
; functions must preserve these values.
;
CURRENT DW ? ; the 1-based index of the current line
POINTER DW ? ; pointer to the current line
ENDTXT DW ? ; pointer to end of buffer. (at ^Z)
LAST DW ? ; offset of last byte of memory
;
; The label Start is the beginning of the in-core buffer.
;
;
; Internal temporary pointers
;
PTR_1 DW ?
PTR_2 DW ?
PTR_3 DW ?
QFLG DB ? ; TRUE => query for replacement
OLDLEN DW ?
NEWLEN DW ?
LSTFND DW ?
LSTNUM DW ?
NUMPOS DW ?
SRCHCNT DW ?
ONE4TH DW ?
THREE4TH DW ?
COPYSIZ DW ? ; total length to copy
COPYLEN DW ? ; single copy length
COMLINE DW ?
LASTLIN DW ?
COMBUF DB 82H DUP (?)
EDITBUF DB 258 DUP (?)
EOL DB ?
ENDING DB ?
SRCHFLG DB ?
PATH_NAME DB 128 DUP(0)
FNAME_LEN DW ?
RD_HANDLE DW ?
TEMP_PATH DB 128 DUP(?)
WRT_HANDLE DW ?
EXT_PTR DW ?
MRG_PATH_NAME DB 128 DUP(?)
MRG_HANDLE DW ?
amnt_req dw ? ; amount of bytes requested to read
olddat db ? ; Used in replace and search, replace
; by old data flag (1=yes)
srchmod db ? ; Search mode: 1=from current+1 to
; end of buffer, 0=from beg. of
; buffer to the end (old way).
MOVFLG DB ?
org_ds dw ? ;Orginal ds points to header block
arg_buf db 258 dup (?)
EA_Flag db False ;an000; dms;set to false
EA_Buffer_Size dw ? ;an000; dms;EA buffer's size
EA_Parm_List label word ;an000; dms;EA parms
dd dg:Start ;an000; dms;ptr to EA's
dw 0001h ;an000; dms;additional parms
db 06h ;an000; dms;
dw 0002h ;an000; dms;iomode
line_num dw ?
line_flag db ?,0
EVEN ;align on word boundaries
;
; Byte before start of data buffer must be < 40H !!!!!!
;
dw 0 ;we scan backwards looking for
;a character which can't be part
;of a two-byte seqence. This
;double byte sequence will cause the back
;scan to stop here.
START LABEL WORD
DATA ENDS
CODE SEGMENT PUBLIC
ASSUME CS:DG,DS:NOTHING,ES:NOTHING,SS:CStack
extrn pre_load_message:near ;an000;message loader
extrn disp_fatal:near ;an000;fatal message
extrn printf:near ;an000;new PRINTF routine
extrn findlin:near,shownum:near,loadbuf:near,crlf:near,lf:near
extrn abortcom:near,delbak:near,unquote:near,kill_bl:near
extrn make_caps:near,dispone:near,display:near,query:near
extrn quit:near,make_cntrl:near,scanln:near,scaneof:near
extrn fndfirst:near,fndnext:near,replace:near,memerr:near
extrn xerror:near,bad_read:near,append:near
extrn nocom:near,pager:near,list:near,search_from_curr:near
extrn replac_from_curr:near,ewrite:near,wrt:near,delete:near
extrn filespec:byte ;an000;parser's filespec
extrn parse_switch_b:byte ;an000;result of switch scan
public std_printf,command,chkrange,comerr
; exit from EDLIN
IF KANJI
extrn testkanj:near
ENDIF
EDLIN:
JMP SHORT SIMPED
std_printf proc near ;ac000;convert to proc
push dx
call printf
pop dx ;an000;balance the push
ret
std_printf endp ;ac000;end proc
NONAME:
MOV DX,OFFSET DG:NDNAME_ptr
JMP XERROR
SIMPED:
mov org_ds,DS
push ax ;ac000;save for drive compare
push cs ;an000;exchange cs/es
pop es ;an000;
push cs ;an000;exchange cs/ds
pop ds ;an000;
assume ds:dg,es:dg ;an000;establish addressibility
MOV dg:ENDING,0
mov sp,stack
call EDLIN_DISP_GET ;an000;get current video
; mode & set it to
; text
;=========================================================================
; invoke PRE_LOAD_MESSAGE here. If the messages were not loaded we will
; exit with an appropriate error message.
;
; Date : 6/14/87
;=========================================================================
call PRE_LOAD_MESSAGE ;an000;invoke SYSLOADMSG
; $if c ;an000;if the load was unsuccessful
JNC $$IF1
mov ah,exit ;an000;exit EDLIN. PRE_LOAD_MESSAGE
; has said why we are exiting
mov al,00h ;an000
int 21h ;an000;exit
; $endif ;an000;
$$IF1:
VERS_OK:
;----- Check for valid drive specifier --------------------------------;
pop ax
OR AL,AL
JZ get_switch_char
MOV DX,OFFSET DG:BADDRV_ptr
JMP xerror
get_switch_char:
MOV AX,(CHAR_OPER SHL 8) ;GET SWITCH CHARACTER
INT 21H
CMP DL,"/"
JNZ CMD_LINE ;IF NOT / , THEN NOT PC
MOV OPTCHAR,"/" ;IN PC, OPTION CHAR = /
IF KANJI
push ds ; SAVE! all regs destroyed on this
push es
push si ; call !!
mov ax,(ECS_call shl 8) or 00h ; get kanji lead tbl
int 21h
assume ds:nothing
assume es:nothing
mov word ptr [LBTbl],si
mov word ptr [LBTbl+2],ds
pop si
pop es
pop ds
assume ds:dg
assume es:dg
ENDIF
CMD_LINE:
push cs
pop es
ASSUME ES:DG
;----- Process any options ------------------------------------------;
;=========================================================================
; The system parser, called through PARSER_COMMAND, parses external
; command lines. In the case of EDLIN we are looking for two parameters
; on the command line.
;
; Parameter 1 - Filespec (REQUIRED)
; Parameter 2 - \B switch (OPTIONAL)
;
; PARSER_COMMAND - exit_normal : ffffh
; exit_error : not = ffffh
;=========================================================================
call PARSER_COMMAND ;an000;invoke sysparse
; DMS:6/11/87
cmp ax,nrm_parse_exit ;an000;was it a good parse
; $if z ;an000;it was a good parse
JNZ $$IF3
call EDLIN_COMMAND ;an000;interface results
; into EDLIN
; $else ;an000;
JMP SHORT $$EN3
$$IF3:
cmp ax,too_many ;an000;too many operands
; $if z ;an000;we have too many
JNZ $$IF5
jmp badopt ;an000;say why and exit
; $endif
$$IF5:
cmp ax,op_missing ;an000;required parm missing
; $if z ;an000;missing parm
JNZ $$IF7
jmp noname ;an000;say why and exit
; $endif ;an000;
$$IF7:
cmp ax,sw_missing ;an000;is it an invalid switch
; $if z ;an000;invalid switch
JNZ $$IF9
jmp badopt ;an000;say why and exit
; $endif ;an000;
$$IF9:
; $endif ;an000;
$$EN3:
;=========================================================================
;======================= begin .BAK check ================================
; Check for .BAK extension on the filename
push ds ;an000;save reg.
push cs ;an000;set up addressibility
pop ds ;an000;
assume ds:dg ;an000;
push ax ;an000;save reg.
mov ax,offset dg:path_name ;an000;point to path_name
add ax,[fname_len] ;an000;calculate end of path_name
mov si,ax ;an000;point to end of path_name
pop ax ;an000;restore reg.
MOV CX,4 ;compare 4 bytes
SUB SI,4 ;Point 4th to last char
MOV DI,OFFSET DG:BAK ;Point to string ".BAK"
REPE CMPSB ;Compare the two strings
pop ds
ASSUME DS:NOTHING
JNZ NOTBAK
JMP HAVBAK
;======================= end .BAK check ==================================
;======================= begin NOTBAK ====================================
; we have a file without a .BAK extension, try to open it
NOTBAK:
push ds
push cs
pop ds
ASSUME DS:DG
;=========================================================================
; implement EXTENDED OPEN
;=========================================================================
push es ;an000;save reg.
mov bx,RW ;an000;open for read/write
mov cx,ATTR ;an000;file attributes
mov dx,RW_FLAG ;an000;action to take on open
mov di,0ffffh ;an000;nul parm list
call EXT_OPEN1 ;an000;open for R/W;DMS:6/10/87
pop es ;an000;restore reg.
;=========================================================================
pop ds
ASSUME DS:NOTHING
JC CHK_OPEN_ERR ;an open error occurred
MOV RD_HANDLE,AX ;Save the handle
call Calc_Memory_Avail ;an000; dms;enough memory?
mov bx,RD_Handle ;an000; dms;set up for call
call Query_Extend_Attrib ;an000; dms;memory required?
cmp dx,cx ;an000; dms;enough memory for EA's?
; $if b ;an000; dms;no
JNB $$IF12
call EA_Fail_Exit ;an000; dms;say why and exit
; $endif ;an000; dms;
$$IF12:
mov bx,RD_Handle ;an000; dms;set up for call
mov EA_Flag,True ;an000; dms;
call Get_Extended_Attrib ;an000; dms;get attribs
Jmp HavFil ;work with the opened file
;======================= end NOTBAK ======================================
Badopt:
MOV DX,OFFSET DG:OPT_ERR_ptr;Bad option specified
JMP XERROR
;=========================================================================
;
; The open of the file failed. We need to figure out why and report the
; correct message. The circumstances we can handle are:
;
; open returns pathnotfound => bad drive or file name
; open returns toomanyopenfiles => too many open files
; open returns access denied =>
; chmod indicates read-only => cannot edit read only file
; else => file creation error
; open returns filenotfound =>
; creat ok => close, delete, new file
; creat fails => file creation error
; else => file cre
;
CHK_OPEN_ERR:
cmp ax,error_path_not_found
jz BadDriveError
cmp ax,error_too_many_open_files
jz TooManyError
cmp ax,error_access_denied
jnz CheckFNF
push ds
push cs
pop ds
assume ds:dg
mov ax,(chmod shl 8)
MOV DX,OFFSET DG:PATH_NAME
int 21h
jc FileCreationError
test cx,attr_read_only
jz FileCreationError
jmp ReadOnlyError
CheckFNF:
cmp ax,error_file_not_found
jnz FileCreationError
;
; Try to create the file to see if it is OK.
;
push ds
push cs
pop ds
assume ds:dg
;=========================================================================
; implement EXTENDED OPEN
;=========================================================================
mov bx,RW ;an000;open for read/write
mov cx,ATTR ;an000;file attributes
mov dx,CREAT_FLAG ;an000;action to take on open
mov di,0ffffh ;an000;null parm list
call EXT_OPEN1 ;an000;create file;DMS:6/10/87
;=========================================================================
pop ds
assume ds:nothing
jc CreateCheck
mov bx,ax
mov ah,close
int 21h
push ds
push cs
pop ds
assume ds:dg
mov ah,unlink
MOV DX,OFFSET DG:PATH_NAME
int 21h
pop ds
assume ds:nothing
jc FileCreationError ; This should NEVER be taken!!!
MOV HAVEOF,0FFH ; Flag from a system 1.xx call
MOV fNew,-1
JMP HAVFIL
CreateCheck:
cmp ax,error_access_denied
jnz BadDriveError
DiskFull:
MOV DX,OFFSET DG:nodir_ptr
jmp xerror
FileCreationError:
mov dx,offset dg:BCreat_PTR
jmp xerror
ReadOnlyError:
MOV DX,OFFSET DG:RO_ERR_ptr
jmp xerror
BadDriveError:
MOV DX,OFFSET DG:BADDRV_PTR
jmp xerror
TooManyError:
MOV DX,OFFSET DG:TOO_MANY_ptr
jmp xerror
CREAT_ERR:
CMP DELFLG,0
JNZ DiskFull
push cs
pop ds
CALL DELBAK
JMP MAKFIL
HAVBAK:
MOV DX,OFFSET DG:NOBAK_ptr
JMP XERROR
HAVFIL:
push cs
pop ds
ASSUME DS:DG
CMP fNew,0
JZ MakeBak
MOV DX,OFFSET DG:NEWFIL_ptr ; Print new file message
call std_printf
MakeBak:
MOV SI,OFFSET DG:PATH_NAME
MOV CX,[FNAME_LEN]
PUSH CX
MOV DI,OFFSET DG:TEMP_PATH
REP MOVSB
DEC DI
MOV DX,DI
POP CX
MOV AL,"."
STD
REPNE SCASB
JZ FOUND_EXT
MOV DI,DX ;Point to last char in filename
FOUND_EXT:
CLD
INC DI
MOV [EXT_PTR],DI
MOV SI,OFFSET DG:$$$FILE
MOV CX,5
REP MOVSB
;Create .$$$ file to make sure directory has room
MAKFIL:
;=========================================================================
; implement EXTENDED OPEN
;=========================================================================
mov bx,RW ;an000;open for read/write
mov cx,ATTR ;an000;file attributes
mov dx,Creat_Open_Flag ;an000;action to take on open
cmp EA_Flag,True ;an000;EA_Buffer used?
; $if e ;an000;yes
JNE $$IF14
mov di,offset dg:EA_Parm_List ;an000; point to buffer
; $else ;an000;
JMP SHORT $$EN14
$$IF14:
mov di,0ffffh ;an000;nul parm list
; $endif ;an000;
$$EN14:
call EXT_OPEN2 ;an000;create file;DMS:6/10/87
;=========================================================================
JC CREAT_ERR
MOV [WRT_HANDLE],AX
;
; We determine the size of the available memory. Use the word in the PDB at
; [2] to determine the number of paragraphs. Then truncate this to 64K at
; most.
;
push ds ;save ds for size calc
mov ds,[org_ds]
MOV CX,DS:[2]
MOV DI,CS
SUB CX,DI
CMP CX,1000h
JBE GotSize
MOV CX,0FFFh
GotSize:
SHL CX,1
SHL CX,1
SHL CX,1
SHL CX,1
pop ds ;restore ds after size calc
DEC CX
MOV [LAST],CX
MOV DI,OFFSET DG:START
TEST fNew,-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
MOV DX,OFFSET DG:START
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 ParamCt,1
MOV [PARAM1],0 ;M004 Leave room in memory, was -1
TEST fNew,-1
JNZ COMMAND
;
; The above setting of PARAM1 to -1 causes this call to APPEND to try to read
; in as many lines that will fit, BUT.... What we are doing is simulating
; the user issuing an APPEND command, and if the user asks for more lines
; than we get then an "Insufficient memory" error occurs. In this case we
; DO NOT want this error, we just want as many lines as possible read in.
; The twiddle of ENDING suppresses the memory error
;
MOV BYTE PTR [ENDING],1 ;Suppress memory errors
CALL APPEND
MOV ENDING,0 ; restore correct initial value
Break <Main command loop>
;
; Main read/parse/execute loop. We reset the stack all the time as there
; are routines that JMP back here. Don't blame me; Tim Paterson write this.
;
COMMAND:
push cs ;an000;set up addressibility
pop ds ;an000;
push cs ;an000;
pop es ;an000;
assume ds:dg,es:dg ;an000;
MOV SP, STACK
MOV AX,(SET_INTERRUPT_VECTOR SHL 8) OR 23H
MOV DX,OFFSET DG:ABORTCOM
INT 21H
mov dx,offset dg:prompt_ptr
call std_printf
MOV DX,OFFSET DG:COMBUF
MOV AH,STD_CON_STRING_INPUT
INT 21H
MOV [COMLINE],OFFSET DG:COMBUF + 2
mov dx,offset dg:lf_ptr
call std_printf
PARSE:
MOV [PARAM2],0
MOV [PARAM3],0
MOV [PARAM4],0
mov [fourth],0 ;reset the fourth parameter flag
MOV QFLG,0
MOV SI,[COMLINE]
MOV BP,OFFSET DG:PARAM1
XOR DI,DI
CHKLP:
CALL GETNUM
;
; AL has first char after arg
;
MOV ds:[BP+DI],DX
ADD DI,2
MOV ParamCt,DI ; set up count of parameters
SHR ParamCt,1 ; convert to index (1-based)
CALL SKIP1 ; skip to next parameter
CMP AL,"," ; is there a comma?
JZ CHKLP ; if so, then get another arg
DEC SI ; point at char next
CALL Kill_BL ; skip all blanks
CMP AL,"?" ; is there a ?
JNZ DISPATCH ; no, got command letter
MOV QFLG,-1 ; signal query
CALL Kill_BL
DISPATCH:
CMP AL,5FH
JBE UPCASE
cmp al,"z"
ja upcase
AND AL,5FH
UPCASE:
MOV DI,OFFSET DG:COMTAB
MOV CX,NUMCOM
REPNE SCASB
JNZ COMERR
SUB DI,1+OFFSET DG:COMTAB ; convert to index
MOV BX,DI
MOV AX,[PARAM2]
OR AX,AX
JZ PARMOK
CMP AX,[PARAM1]
JB COMERR ; Param. 2 must be >= param 1
PARMOK:
MOV [COMLINE],SI
SHL BX,1
CALL [BX+TABLE]
COMOVER:
MOV SI,[COMLINE]
CALL Kill_BL
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
SKIP1:
DEC SI
CALL Kill_BL
ret1: return
Break <Range Checking and argument parsing>
;
; People call here. we need to reset the stack.
; Inputs: BX has param1
; Outputs: Returns if BX <= Param2
;
CHKRANGE:
CMP [PARAM2],0
retz
CMP BX,[PARAM2]
JBE RET1
POP DX ; clean up return address
COMERR:
MOV DX,OFFSET DG:BADCOM_ptr
COMERR1:
call std_printf
JMP COMMAND
;
; GetNum parses off 1 argument from the command line. Argument forms are:
; nnn a number < 65536
; +nnn current line + number
; -nnn current line - number
; . current line
; # lastline + 1
;
;
GETNUM:
CALL Kill_BL
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
retz
OR DX,DX
JZ COMERR ;Don't allow zero as a parameter
return
CURLIN:
cmp [fourth],1 ;the fourth parameter?
je comerra ;yes, an error
MOV DX,[CURRENT]
LODSB
return
MAXLIN:
cmp [fourth],1 ;the fourth parameter?
je comerra ;yes, an error
MOV DX,1
MOV AL,0Ah
PUSH DI
MOV DI,OFFSET DG:START
MOV CX,EndTxt
SUB CX,DI
MLoop:
JCXZ MDone
REPNZ SCASB
JNZ MDone
INC DX
JMP MLoop
MDone:
POP DI
LODSB
return
FORLIN:
cmp [fourth],1 ;the fourth parameter?
je comerra ;yes, an error
CALL GETNUM
ADD DX,[CURRENT]
return
BACKLIN:
cmp [fourth],1 ;the fourth parameter?
je comerra ;yes, an error
CALL GETNUM
MOV BX,[CURRENT]
SUB BX,DX
JA OkLin ; if negative or zero
MOV BX,1 ; use first line
OkLin:
MOV DX,BX
return
comerra:
jmp comerr
Break <Dispatch Table>
;-----------------------------------------------------------------------;
; Careful changing the order of the next two tables. They are linked and
; changes should be be to both.
COMTAB DB 13,";ACDEILMPQRSTW"