*2 1,,,,,,,,i, - apps.dtic.mil · this document reviews two baseline im- plemntations taken...
TRANSCRIPT
AD-Al 757 NAVAL POSTGRADUATE SCHOOL ONTEREY CA F/ 5/8BASELINE IMPLEMENTATIONS OF THE STANDARD LINE EnITOR (SLED ( d)
OCT 80 L A COX, . J ¢ JTEA. C F TAYLO
UNCLASSIFIED NPS52-80-012 NL*2 lfl//fl/////2,
1,,,,,,,,I,mmhmhhhhhmhmhu
EhI-EIIIIIElElliiiiiii
F--i
NPS52-80-01 2
NAVAL POSTGRADUATE SCHOOLMonterey, California
%IT
IN.AUR TS 9EST QU&LIIY ?R&CIC&DIAM,?Y 5'LMSII TO WC 00U!LZ A
SRIGN1OCMEYZ3LTo z nw w
Baseline Implementations of theStandard Line Editor (SLED)
L. Cox, R. Coulter,3 a C. Taylor, R. Burnham, and S. Smart
October 19 0
Approved for public release; distribution unlimited. " W j2
Prepared for Naval Postgraduate School, MontereyCalifornia 93940
82 o'12 089
OW.
NAVAL POSTGRADUATE SCHOOLMore, Calliforni a
Rear Admiral T. F. Ekelund D. A. Schra4ySuperintendent Acting Provost
Reproduction of all or part of this report is authorized.
This report was prepared by:
Revieed bReleased by:
R Wi ,LA M.nLEepa tinent of C er Science Dean of Research
LI
DISCLAIMER NOTICE
THIS DOCUMENT IS BEST QUALITY
PRACTICABLE. THE COPY FURNISHEDTO DTIC CONTAINED A SIGNIFICANTNUMBER OF PAGES WHICH DO NOTREPRODUCE LEGIBLY.
i ~
UnclassifiedsMCumTV CtLM"ICAsTW 0, ItwSS 0e60 1Mm owe
REM IOINTATON PAGE 3* USUUClflUI
NPS52-80-01 2 ____________
4. TItFL[ (ai HWtl, .ITv" op 060seW a Vee coveutwo
Baseline Implementations of the Standard LineEDitor (SLED) Technical Report
6. peft9o"We "&s SuOWet @Msao
1. *utJw@Urj . GMTRACT OW GRNT NUNMtSW4I
Lyle Ashton Cox, Jr., et. al.
S. MgmF0eueuS 64"tZATION %AN& AND LASSUIS PS P3 I'E651 T"MC?
Naval Postgraduate SchoolMonterey, CA 93940
11 coest.iarns OPPIcs "M Awo aesM is. me6Pse DATI
Naval Postgraduate School October 1980Monterey, CA 93940 IL 4WumOeOF 08413117
,t. uo70=4 aZEV Mwte 6 3s05uh61, ,i,,sn am C NG om.j 117 SMu,- MM& (.,O.
Unclassi fled
Approved for public release; distribution unlimited.
11F. 019TWOUTION 5?A"Nft? f~e. Oft a umsUW UsuWW inN f ~m dWu6I
IS. uPei.55mSAVaf &30'A*5
ii. sly meII m su I.. gm.p-ef B bw
Text EditorSoftware EngineeringComputer Networks
I n response to a r nmore uniform man machine inter-face, especially in multiple machine networks, a standardized text editor was pro-
posed (1). This editor, SLED$ was destgned to be easily implemntable in severaltommonly available higher level languages. This document reviews two baseline im-
plemntations taken directly from the SLED standards which users may want to con-
sider when implemnting SLED upon local systems. These baseline programs werewritten and documented with portability and understandability as goats---
OI U1 MIef G I now to 66"
sm " Unclassified(Page 1) -', ,n, - e- e _ _... .... .. .. .
P - II I i i III III II I I I I II I.L I Im y II s .auuwc ....... i i e m i I e.
Baseline Implementations of theStandard Line EDitor (SLED)
Lyle A. Cox Jr.Editor
Department of Computer ScienceNaval Postgraduate School
Monterey, Cal ifornia
, ABSTRACT
In response to a recognized requirement for a more uniform manmachine interface, especially in multiple machine networks, a standard-ized text editor was proposed (1). This editor, "SLED" was designed tobe easily implementable in several commonly available higher levellanguages. This document reviews two baseline implementations takendirectly from the SLED standards which users may want to consider whenimplementing SLED upon local systems. These baseline programs werewritten and documented with portability and understandability as goals.
BACKGROUND
During the Winter of 1979 and Spring of 1980, shortly after theStandard Line EDitor definition was first developed, several persons atthe Naval Postgraduate School undertook implementations of SLED. Two ofthese implementations -- the documentation and the code -- are repro-duced here.
Appendix A contains the SLED implementation developed by C. F.Taylor, Jr. *on an IBM 360 system in FORTRAN. Appendix B-contains analternate implementation developed by R. M. Burnham, R. J. Coulter, andS. W. Smart in the PASCAL language.
Neither of these Implementations should be considered "off theshelf" commercial -quality software ready for installation. These sys-tems do however provide two critical portions of the implementation:
1. Each contains the basic code in a "portable" higher levellanguage, and
2. The code of each Implementation is written for readability,
2
-I .... i
!q . ~ m~m ..... ~ -.-- .. . |,,.J,,.J ........ ....- ... -.-.- -mm-
and the documentation has been written to allow the program to beadapted to any system with a minimum of difficulty.
It is hoped that these baseline programs will serve to facili-tate the implementation of the SLED man machine interface on a varietyof machines.
Acknowledgments:
I would like to thank the authors of the included codes, C. Tay-lor, R. Burnham, R. Coulter, and S. Smart for their particularly out-standing work on this project. I would also like to acknowledge theassistance of many of their contemporaries who attempted alternativeimplementations, and who helped in the evolution of the SLED standards.I would also like to thank Dr. R. W. Hamming and LTCOL. R. R. Schell fortheir comments and interest.
Lyle A. Cox Jr.15 August, 1980
AI
(1) "The Text Editor As A Uniform Man/Machine Interface. A Proposal fora Standard Editor." L. A. Cox Jr., Naval Postgraduate School ReportNPS52-80-001 (Feb. 1980).
Aeoo..jn 0 'orNTSGIA&IDTIc TABUzrnounoedJustifloat.
Distribution/
Availability Cod.,Avalllt u14/o
Dist Special_
IL " -Ili
.. . . ...-I. ........... . .. . . . .
Appendix ASLED FORTRAN Implementation
(by C. F. Taylor Jr.)
The purpose of these notes is to briefly describe the accompany-ing FORTRAN implementation of SLED.
SLED FORTRAN Version FORT1.1 was implemented on an IBM 360/67computer under the CP/CMS time-sharing operating system at the W. R.Church Computer Center at the Naval Postgraduate School, in a supersetof IBM FORTRAN IV, Level G, which included the."IF-THEN-ELSE" and"WHILE-DO" constructs of WATFIV-S. The addition of these two constructsgreatly simplified the writing of the program and were implemented withthe aid of a preprocessor written by this author. Standard FORTRAN ver-sion (the output of the preprocessor) is shown on the following pages.
This version was compiled using an IBM FORTRAN IV/G compiler.
The package was implemented using the utility routines shown onpages A37-A40 of the listings, The 'TDISK EXEC" module was used toobtain the required disk space for the 4000 line (32OK byte) temporarywork file. It is assumed that this work space would be provided at thesystem level in any actual implementation of SLED. Because it is adirect-access disk file, sufficient space must be availabe in advancefor the maximum capacity of the editor, which in this case is 4000lines. This figure was selected somewhat arbitrarily; CP/CMS gives theuser 800 bytes per track (IBM 2314), using the remaining space for over-head, so at 80 bytes per line, 4000 lines represents 400 tracks.Installations which do not need to edit such large files could reducedisk requirements by further limiting the capacity of the editor as fol-lows:
1. Do a global substitution to replace the string '4000' in theprogram by the new capacity.
2. Modify the 'DEFINE FILE' statement in subroutine MEMORY asnecessary.
3. Alter the FILEDEF statement in 'SLED1 EXEC' (or theequivalent action on another system) to request less disk space.
The basic data structures used are as follows: The file to beedited (unless a new file is being established) Is read in sequentiallyby subroutine OPEN and stored in the work file (described above) whichis conceptually a 4000 line by 80 column array. All references to thework file are made through calls to subroutine MEMORY. The lines of thework file are not necessarily kept In order. A 4000 element from thefile is determined by popping the to element from the stack. Thisvalue is then recorded in the 401 element array LPTR. LPTR(I) thenalways gives the address in the work file of the Ith line of the textfile. As l1nir are deleted, their addresses are pushed back onto
r ' . ./4
I. - ~ -7
additions and deletions of lines by manipulating pointers rather thanthe text itself. Still, the work file may be accessed sequentially byusing LPTR(I) as the index.
Input from the terminal is buffered in a circular queue in sub-routine GETLIN. This permits the "stacking" of more than one commandper line at the terminal. Calls to GETLIN return a line from the headof the queue or, if the queue is empty it reads in a new line from theterminal.
The QUIT subroutine writes the work file sequentially (usingLPTR as an index) to the output file.
Additional notes which may be of interest to the local implemen-tor follow: (including deviations from the SLED standard).
I. Integer*2 variables were used for all character storage (andfor the two large arrays STACK and LPTR). Only one character was storedper word.
2. Because FORTRAN reads only fixed-length formatted recordsfrom the terminal, the carriage return cannot be used to terminate astring. This means that 'DS' and 'RS' commands must use the logicalterminator character (default '$) to terminate strings and that the'RS' command should be used as follows: RSSstrl$str2$.
3. The 'RS' command replaces only the first occurrence of astring in a line because of this author's firm conviction that to allowonly multiple substitution would be dangerous. In an editor such asthis without a TAB function, a common string substitution would be to Ireplace one blank with two blanks on a line. What would happen if thiswere done for every occurrrence of a blank on the line is too horribleto contempl ate.
4. The CP/CMS operating system and IBM FORTRAN required thatfilenames be handled external to the program itself. The routine 'SLEDEXEC' executes the simple program 'SLEDVERS' when 'SLED' is typed toalert the user to the required entry procedure, 'SLEDL <filename> (file-type>'. SLEDI EXEC then invokes the actual edit program, SLED2. Thefilename given the program internally is meaningless and provided onlyfor cosmetic reasons. This system requires that only one file be openedper session.
5. Another limitation of FORTRAN required that the program readinput from the line following the program prompt, not a serious problem.
_ . . . i I , I )5
SLED -STRUCTURED FORTRAN
LO/02/RO 12 .ZO.
FILE: SLED FGRTR4N T I NAVAL ,f)jTf;RAiu'rL SLII"PL
C S'ANOARO LINE EUITLJR--FORTRAN IMPLEMENTATIJNCL SLEU VERSIN FORT1.1 NPS MONTEREY 4004 1C PRJGRA.4ME.) BY: L. F. TAYLUR, JR., C'JI). 55TA
* c FUR FURTHER INFURMATION SEE NP. TECHNICAL RFPJRTC NPS 52-80-UOI BY L. A. COX t JR.CC(c MAIN PROGRAM:
C PEA0DS IN COMMANDS AND CALLS THE APPROPRIATE SUBRiAITI14rC I4PLFMFNTS THE "EDIT" M'OniEC
CUM(]N /BLK1/If4vtjUTI. /3LK5/MFLAGERRCTgCURLININTFGER*2 LIvCZ#APCPDOLM,tQRtSTtV, rNL[NEnLNKINTE('Ei( IUIlJT,ERRCTCURLINNCCIMENSION I'4LINt( 8U)LOGICAL FLAGOPENFLMFLAG
I SI'S'/,T/'T/I.V/'V'/,BLNK/' '1'000 FiJiMAT ( E>911OL0 FORMAT I' -INVALID COMMAND- ',2A[)2020 FORMAT (' -NO TEXT FILE OPEN-')2030 FURMAT (' -UNLY GNE FILE CAN BE OPENED PER SESiION IN THIS ',
L 'VERSI)N OF SLED-')C EDIT MODE--WRITE PROMPT
WRITE (4UT,2.)00)CALL GETLIN(IN4LINE*NC)Cl = INLINE(L)C2 I'LINE(2I
C FLAG GOES I-ALSE AFTER 'QUIT'FLAG = .TRUE.
c OPENFL GOES TRUE AFTER FILE IS OPENEDOPENFL .FALSE.
C MAIN EDIT LOOPW I E IFLAG) 00• NOT.(OPENFL .OR. ,CI.EQ.O) .OR. (CI.EQ.M)
I .UR. ICL.EQ.V))) THEN 0C FILE NOT OPEN AND THIS IS NOT AN 'QPEN' COMMANDC OR A 'MENU' OR *VCRSION' REQUEST
wRITE (OUT,20Z0)ELSE 30C EMULATE CASE (SWITCH) STATEMENT TO PRJCESS COMAANDS
IF (CL .. Q. BLNK) Gi TO 730IF (CI.NE.L) ??T3 IQ
CALL LIS ,NLINF)GO TO 200
10 CON T I NUEIF (CL.NL.$I GO Ti 20
CALL SCREENI NLINE)G"} ILI 20020 ONTINUF
IF((Cl.NE.Rl.0R.(C2.NE.S)) GO TO 30
• . 7
FILE: SLEO FORTRAN TI NAVAL P)OSTGRAOUATE SCH4'i.
CALL RS(INLINEIGO TO 200
30 CUi T INUEIF (tCl.NE.R).JR.(C2.NF.LI GO T17 40
CALL RL(INLI'4E)GO TO 200
40 CJNTINUEIF ((C1.NE.IJ.OR.(C2.NE.L)) GO TO 50
tALL AL(INLINE)GO T. 200
50 CONrINueIF (ICI.NE.DI.OR.(C2.NE.SI GO TO 60
CALL US(INLINE)GO TO 200
60 CONTINUEIF (CL.NE.o) GO TO 70
CALL JUITFLAG = .FALSE.GO TO 200
70 CONTINUEIF (CI.NE.Vl GO TJ 80
CALL VERSGO TO 200
80 CONTINUEIF (CL.NE.4) GO TO 90
CALL MENUGO TO 200
90 CONTINUEIF (CI.NE.O) GO TO 100
IF (OPENFL) THEN DOWRITE (OUT*2030J
ELSE 00CALL OPENOPENFL s.TRUE.
ENO IFGO TO 200
100 CONTINUEIF ((CL.NE.CI.OR.(CZ,NE.T)) GO TO ILO
CALL CT(UNLINE1GO TO 200
110 CONTINUECC IF PROGRAM GETS HEREp COMMAND IS INVALIO
WKITE (OUTZUiOICLtC2ERRCT = ERRCT41
C END CASE200 %UNTINUE
IF(ERRCT.GE.Z) THEN 00CALL MENUERRC- 0
NDIFEND IF
IF (FLAG) THEN OC GET NEXT LINE
IF (.N(IT.MFLAGI WRITE (oUT,20001
Im I 1_1_li 1
FILE: 51Ff) FUR rR AN ri. kl. VAL VCST,4Af)UATf: SC11,0t,
CALL GETLIN(INLINFNC)CI = NLINE( IICZ z INLINEM2
ENO I FENO WH4ILESTOPEND
BLOCK DATAc COMMON /3LKI/ LNO)UT
2 /iJLK3/ TFILE2 IJLI(4/ TCH-AR3 I4LK5/ :FLAGPERCTCURLIN
tNTEGER*2 TCHARINTEGER~ I'jtQUrTFIL6,ERgCTCURL(NLOGICAL 4FLAG3DATA IN/5/,DUT/6/,TCHAR/'S'/,,ERRCT/,/.MFLAGu/.FALSE./,J' L IN/if,
I TFILE/2/END
SUBROUT[NE LIST(CLINEICC DISPLAYS TEXT TO THE TERMINAL
cCC#4MON /F3LKL/ MNOUTI /iaLK2/ LPTR,,4AXLIN,EJF2 /B3LK5/ VFLAGERRCTCJRLIN
INTEGER*Z 8LNKvLPTR,COMMAv0UTLIN, CLIMEINTEGER IN,OUJI ,J,N1.,N2,MAXL['4,EOF,ERP.CT,CURLIN,FETCHLOGICAL 'FLALEFLAGwUIMENSION CLINE(8o),OUTLIN(81,LPTR(4)QOiDATA 8LNK/f *I CO,4MA/*O0/3FETCM/0/
2100 FORMAT (l -1 N VLID CQMMANtI-1)2110 FORSAT (' 'r14#lX980Al)
2120 FOR-4AT (I -EUF-')
IF COL 2 IS BLANKt PR[,4T CURL I' AND EXITIF (CLINEM2 *EJ. dLNK) THEN DO
CALL MEMORY (FETCHtOUTLINLPTR(CUPLI?4)woRITE (OUTt2110) CURLIN, DfJTLIN
ELSE 00C NOW CHECK FOR LINE NUMBERS IN COMMAND
CALL COMLIN2,CLINENIN2,EFLAr,)IF (11,I .E. 0) Ni IIF (NI, GT. N21 EFLAG .IKUE.IF (N. .GE. EOF) EFLAG = TPUF.IF IEFLAG) THEN 00
ERRCT a ERRST IWRITE (OUT, 100)
ELSE DOEi4RCT 0I NI.
FILE% SLED FORTRAN TI, NAVAL POSTM.%Il)UATE SCH'1 Of
WHILE ((I.LE.NZ).ANO.j( .LT.FQOFl OUjCALL ME'40RY 4FE CHv0UTLI'kJ,LPTK( I))4R0T6 fJUT,2i:J, 1, i1IJTLINCURLIN *II1 a
END WHILEIF (I.GE.EOF) WRITE (fUTr21201
END I FEND I F
RETURNEND
C SU8RCUTIN4E SCREENICLINE)c OISPLAYS ZC0 LINES BEG14NUNG WITH COPLIN OR MliiER SPECI~li-, LINE
I /6LK / LPTR ?4AXLIN,EI3F
kAT BLK/ '/,ETH// NZLII
IF (CLLNIZ 2?.NEvLPLNK) THEN 00NLGCAL ML C0,I.LAG~,L~ENIZELGDAT (LNI .L/vE 0) I.
IF12 (ORMA - GE OF-*) ELG .IFAG FALSEU.ELG ULN
C FIEND OUI HTEFSRSPCF~.ALNIF (CEA).N.LK TTHEN DO
WIT (UT A: 001I
EFLSEFL D HEOD
ERRCT a0LI-41T a MINOICURLIP4419tEOF-tiDO 1 1 - CURLINILIMIT
CALL. ME4ORY FETCHirlUTLIN;LPTR( 1))LO ~WRITE (OUT.ZLIOI1I,OUJTLKN
10 CONTINUECURLIN a LIMITIF (LIMIT EfQ, EOF-L1 WRITE Mllrt.Z120)
END IFRETURN
END
10
FILE: SLED FOR4TRAN TI NjAVAL P)r1STISA&)UATE )ir1ii 1
SUBROUJTINE RLICLINE)
c REPLACES CURRENT LINE JR THE SPECIFIED) L14jE fR LINES m[TtiC ANY NU4tiER UF LINESC ~ CCMM1ON /BLKI/ INvOUT
I /13L12/ LPTR A4XLIN,EJ)F2 /i3LK5/ .MFLA6, ERRCTPCJQLIN4INTE(;EA IN9JUJ,4AXLINqEOF 9ERACTq CURL it 4941 9429 It JL1-11To
I STOJREINTEVuEt*2 LLINELPTRBLNKLUGLCAL 'FLAi,EFLAG0I?4lNSIUiN CLINE( 80 PTR(40JOIDATA dLNK/f /,S TQR /I/
2100 FORM4AT I' -INVALID COM'4AND-0)C
NI =CURLINN2s N1
L 0ETERI4INE WHICH LINE(S) TO REPLACEIF (CLINE(3)*NEeBLNK) THEN 00
CALL COMLIN(3,CLINEINNLNI EFLAG)IF (NI .LE. 0l EFL AG 2 VW~ E.IF (N1 .,E. EOF) EFLAG .TRUE.IF I(.NOT. iFLAG) CURLIN 141
ENO IFIF (EFLAG) THEN 00
ERRCT -ERqCT + IARITE (UUr,2L00)
ELSE 00ERRCT - 0IF (42 GE6. EOFI NZ a EOJF.- I
C REMOVE UESIGNATED LINESN in NZ NL +I I00 20 1 a IN
LIMITF EO-Fp-CALL PU S4L T RiNl)00 L0 J NItLIbIT
LPT;(J) = LPTR(J~1)LO CONTINUE10 EOF a EOF - I
CALL INPUT
ENO IFRETURNEND
SUBROUTINE ALICLINE)C INJ TEXT AFTER LINE 4
COMM1ON /811(1/ INOUT
FILE: SLEf) FoRrRAN rtI NAVAL PfJSr;R&UArE i;c'lOt
L /t3Lr,5/ 14FLAG#ERikCT,CJRLliNINTEGER*2 8IL4K,CLINEINTEGER IN,O)UT,[,j NNlN2,ERR% TCU7LINLiJGICAL r4FLA" EFLA~QIMENSION CLINEI 80)DATA BLNK/f I/
C2100 FORI4Ar ( ' -INVALIrD COMAIANO-#)
C EXTR~ACT LINE NUARER FROM COMMAND LINECALL COMLIN13,CLINE, NI,N2 EFLA2I)IF (NI .LT. U) EFLAG = .TAUE.N -NiIF (EFLAG) THEN Do
ERRCT = ERRCT + IWRITE (OUTt21001
ELSE 00ERiACT 0CURLIN N +4 eL
EN CALL INPUT
RETURNEND
C SUBROUTINE OS(CLINE)
C PART OF SLED PACKAGEC DISPLAYS ALL LINES CONTAINING THE DESIGNATEJ STRING, PJSSISLYC LIMITED TO LINES N THROUGH M4.C
COMMON /8LKI/ IN,OUTI. /BLKZ/ LPTR MAXLIN,EOF-
2 /f3LK5/ MFtAGERRCT ,CURL ININTEGER INOUITrMAXLINEOF:ERRCTCURLiNN1 ,N2,NICFETCH,94C1
LOGICAL MFLAG,EFLAGMATCH, FOUNDDIMENSL034 CLINE(80) ,LINE( 8O)tLPTR(40O0),STRING(80IDATA SLNK/f I/iFETCH/0/
2100 FORMAT 11 -IN VALID COMM'AND-112L10 FORMAT 4' 9 14 LX 80A1)22J0 FOR14AT (1 01D iTRING.?)')2 0 FORMAT 4' -NO STRING FOUND-$)
2 DEFAULT VALUESFOUND * FALSE.EFLAG : *FAL SE,NI -INZ w EOF - I
C DETERMINE WHETHER N19NZ WER~E SPECIFIED 63Y USERIF (CLINE(3) .NE9 BLN1K) THEN DO
CALL COMLIN(3,CLINE.NIN2,EFLAG)IF (4I .GE. EOF) EFLAG =.TRUE.IF (NZ2 *GE: EOFI ?4Z2 EOF IIF (I .LE. 01 NI L
END IF
12
FILE: SLEa F6RT R A 4 T I 'AVAL P!ISI.RAflUAfE SCH(f'Ct
IF (EFLAG) THEN 00IERR(:r = ERRCT +WR(FT (rIUr,2100)
ELSEL) =ERRCT=
C, FETCH STRIN1G; ISSJE PROM4PT [F NECESSARYIF (.Nor. 4FLAG) WRITF (OtJT922Z0)CALL GETLI4 (STRING0NCIF 04C .LE. 0) THENI 1)0
ERACT = ERRr.T + IWRITE (OUT,2LO0I
ELSE 0000 20 1 A N19NZ
CALL 40r4RY(FETCHLNEL't()CALL SEARCH( LINE, TRING,NC,?*4AT;i4,MCt)IF (MATCH) THEN no
FOUND z rTRuE.WRITE IOUr,2110) ILINECURLIN 2I
END IF20 CONTINUE
IF I.NUT. FOUN01 WRITE ((OUTt2Z501END IF
END IFRE TURNENDsut3ikouTINE RS(CL[NE)
CC PART OF SLED PACKAGEc REPLACES THE F~IRST OCCJRRENCE OF STRINGL WITH STRING2 JU THE
C CURRENT LINE UR WITHIN THE SPECIFIEO RANGE OF LINES
C COM-40N /BLKj./ INOUTL /13LKZI LPTRPMAXLIN.EGP2 /a3LK5/ DFLAG ERtRCTpCURLN
INTEGER INOUTP4AXfNEOF ERRCT C:URLIN,Nl,N2,I,1JKL,4,I 4mct~c 2FEY eN$OAE
DIMEN41OM LPTRl400) CLIN (80),STRI q0)vSTR2Ia0)tL'4E()DATA 13LNK/I It FE rCH 0/tSTOREf/LOGICAL YFLAGJIOUND MATcm LA
2100 FOR14AT (f -INVALID tCOM4AN 6 !.)2110 FORMAT P914 LX .80A1)2230 FORMAT P LU 9TR 1G?>'2240 FORMAT (I NEW STRING?>)2250 FORMAT (I -NO STRING FOUND-*)CC DEFAULT CONDITIONS
NI a CURLINNZ NI
EFLAG u FALSE.C INTERPRET COMtMAmnO N
[F (CLINE(31 NE.8LNK I THE N 00CALL CO;iLIN( 3,CLINE,NLqN2vEFLAGlIF (NI *LE- 11 EFLAG TRUE*
13
FILE: SLED FOJRTRAN TI NAVAL f'oSt-;4A~tJATC C4fI
IF (NL :bE. E0F) EFLAG .TRUE*IF tP42 %sE. EOF) 1 2 -aEUF - I
~NU IFIF (EFLAG3) THIEN DO
ERRCT - lRRCT +IWRITE (LUT,2100)
ELSE 00ERi4CT s0
C READ IN TWO STRINSS; PROMPT IF NECESSA-kYIF (04Ue -IFLAG) W4RITE (OUT,22301
9 AL ETLIN(STRLONCL)(Ni :LE FLAG x .TRUE*
IF f.NU. *LA1) WRITE (OUTP2240)CALL GETLIN(STZN2
ERI4CT - ERRCT + 1WRITE (OUT#ZIOO)
E T RN6?C
IN F R MTH HNDCNO (N STIIMAESJSTUIN
FOOUND = FTLSE.
DOO ZO K - IlNN2CALL M O 10 TC jL4E 9LPTR(K)
c 4OW MKE 51COTTIUTUEFCO - TRUE
C DOELETE SROO FR TRNG
DO201 I0 11 1 ,CDO 0
LNE( 82-13 LINE8N-I13O CONTINUE
20CONTNTNC NOW NSFOTMNF W STRIi.I
00 45 19iNC2
LINE;I-11 STR2EI)35 CNTI NUE
ENO IFC STGRE REVISED LI NE
CALL ME'IORYI STORE ,LINEpLPTR(KJ)G UISPLAY REVISED LINEC WiRITE IjUT,2112) K'hIFABV IETENtC REMOVE OC" IN IFAOELETON6Ec OISPLAY OF EAC14 LINE IN iAIlH A STRIfiG IAS B-ENC R~EPLACED
CURLIN *K
14
FILE: SLED FL4TRAN Ti NAVAL iloSTRAUiJ.r, scrm ni
END IF50 ci 1r I NuE
IF I.NLJT. FnUNUI WiRITE (9UTt2250)END IF
RE TURN
SU8RUUTINFf CrCC PAPT OF SLED PACKAGEC CHANGES THE MESSAGE TERMINATOR TO ANY VALID) Citi-RACTERC
CrM'40N /E3LKI/ I.NT,OUTI PiLK4/ TCHAR
2 /d3LK5/ 4ILAGgERACTICURL["4INTEGER I-4#JUT,*A4RCrC:JRL INNINTEGER*2 rCHARfINLZNv8LNKLOGICAL AFLAt'DIMLNSIJ'i IW4IN(80)DATA WLaK/l I/
2100 FOR:4AT (I -INVALID COMMAND-1)2200 FORMAT (9 TERMINATOR?>' J
CIF I.NOT. ?FLAG) THEN DO
C ISSIJE PRO-4PTWRITE IOUTt22001
END IFCALL GETLIN(INLIN tNC)iF ((NC.EQ.01.OR. lNL14(l).EQ.BLNK)) THE4 00
ERPcr -l ERRS T #- IWRITIE (OUT. 100)
ELSE QUTCHAR aINLINfl)
END IF&E TURNENDSUBROUTINE MENU
CC PART OF SLED PAJKAGEC PRflVIDES USER WITH A SJMMARY OF AVAILABLE Cnl4'4AWJflC AND THEIR FORMATS*C
COMi4UN IBLKI/ INO'JTINTEGER IN iUT
200 FORMAT LED) CO'4-.4AND SU'4MARY:*//' L104F/TExT INjSEfR',T319L OSTRING EPL4CE4jENT 1/3X;'ALN',TLO,'LNSERT <#%>FrR <1>1'4E N's2 T40 aS~P &Q,' T4 St ok EPLACE STRI3,fv3,6KLNtrLJ)3 *<R>EPLACt (L)INE N .Oq.',T40,'RSNIPItjs'T5t,'"P"owt "'" P4v/4 3X,'RLNm T15LNEN IR 'T,'5iP$sri,
5 INDIKAHLE LIN4 S.'/' OUTPUT C04MANDIt 3,'ST~I G SICA4' H-/6 3X6"LlrLU,'OOISPLAV CURRENT <I.~NE'T40,')SSwb', iqI -< >ISPLAY LINES -/3X,'LN',TlO,'OR LINE %4.,T5),8 WiITH <S>TRING " PW,'f3Xv'N4*qTIO,'LINbS 4 1~440 49TWo,9 lDSNvMPSP$'T4991UR SHOW ANY LI4ES')
201 FORMAT 13JXtOSIgTIOr'SHOW A I,X '"SCREEN 0FLINES' 91509.-4 CONTAINING -P-11/3X,'SN',Tl )v
FILE: SLED F(ORTRAN TI NAVAL Pf)ST'R&AJU, 1 ',rl,:r)L
I. IHU4 A SCELr4 FROM LINE N' ,T383plC0NTR)L Cj:4:4A4;+ S/2. 3Xro.4v.Tl')rv° HO,4 C044,A4D <i>EN-J ITHIS)' tTI°' kl 9 |at T '49 .
3 (U>PE A FILE JR'/Xt, T .V._Lt0- SHJO <V>RiI J N ;, e 0Is iS FJA ATI. N4 T5 F Ti: A FILt FR LT"IN, /T4091CT >H4,NGL TL U 'LtA of
5 5Xv, TO <>UJT TlE EDIT TYPF ltQ<ET>1v ,T'.#0,' 4F SAt;F ,r>.; iNll
6 0 ATIJKI)wRITE (OUT,2JJ)wAITE (ur,29)RETURNENDSUBROUTINE VERS
CC PAPT OF SLEO PACKAGEC
WMMON /BLKL/ [N913(TNTEGER IN(jUT
220 FORMAT P SLED VERSIUN FORT,., NPS MONTEREY '1004011/I I LOCAL EXPERT IS C. TAYLOR 4 O8-646-Z1ql 04J)U-LT.)O PST/PUTO/
Z : LINE DELEfE KEY IS < > (ASCII) OR <CENT SIGN> %3 (EdCOICl/9 CHARACTER DELETE KEY IS <0>//4 * EOITIR LOGICAL MESSAGE TERMINATORS ARE:@/5 9 iM) <RETURN> AND (2) <$>/16 * AND LAN BE CHANGED r3 ANY STANOARO FORTRAN CHARACTEk.
l/
7 # ALL INPUT IS TRANSLATED TO UPPER CASE.$/8 * THE FOLLOWING OEVIATIONS FROM SLED STANDARD WERE REQUIRED=)'
221 FORMAT t9 o l) THE UNIVERSAL ENTRY OACNAND "SLEDN INVOKES INSTRUCTIPNS'
FOR A NON-STANDARD NTRY: 11SLEI)1 <FILENA .iE> <FILFTVP9>
INSo/ 1 2) ONLY ONE FILE PER SESSION CAN BE UPENF)o.'/2 0 (3) MAXIMUM FILESIZE IS 4000 LINES.'/3 4 14) THE USER IS ASKED TO INDICATE WHETHER 14E I3 EJITING A I/
4 0 NEW FILE IN ORDER TO PREVENT A DISK READ ERR I4R IN FrRTRA
SN.'/6 (5) WHEN <RETURN> IS USED AS A LOGICAL 'ESSAGE I/6 a TEAMINATIRt THE LINE OR STRING IS PADUFD WITH fALANKS UN'
U1 o THE RIGHT. THIS AFFECTS THE RS FUNCTIUN ONLY.')222 FORMAT (
2 . (61 ONLY THE FIRST OCCURRENCE OF A STRING IN EACH LINE'/S * IS REPLACEU TO PERMIT FREE SUBSTITUTIIINS OF LAIKS)
WRITE IOUT 220wAITE (13UT, zzlWRIT6 IOUT#2221RE TURNENDSUBROUTINE OPEN
CC OPENS TEXT FILE AND WORKSPACE FILEC READI TEXT FILE INTO WORKSPACE IF IT ALREA3Y EXISTSC INIT ALILES PUITERS ETC.C
CC, 4CN IBLKI/ IN OUT
I /dtLK21 PTA MAXLIN,vEF2 /SLKJ/ TFILI32 /1 LK/ MFLAG9ERRCTACIJRLIN
4 /SLK6/ STACKS TKPTRINTEGER INvOUT9TFIL ,LINEERRCTCURLtiNdSTORE-AXLIN9'F,3P
16
0 -
V I LE: SLEU Ff(T RANI r I NidAVAL PrirSTJlA1UA rF L~v
I STRkTRio~cINTk:GER(s2 L Ptk.,.TACKF'4AME, [NL[NYE3,r;,'lPLY,:iL1NL-LOGLAL 4FLA(LGIMENSL4JJ' LPTR 1 1030) 98 INE( 40 9 TC(m00 F1-4F 31 N NI p)I'.ATA 'ES/f'V/vdtLINE/80*' '1 eNlI'N. S4 ~ i
Loo00 FCP 4A I ( 3)AL I* ZU4Z FOR44r I' -',14,' LINES IN F~ILE: '.40AI)
2050~ FCfR4AT (I KCEATINMG FILE2. RUA 1
.2413) FC14iA t (0 IS THIS A NE4i FILE?>*)242U FOPi4AT (I -AX CAPACITY 4003 LINES FXCEE3-s)
CC INITIALIZE
MAXLIN = 4000CURLIN = I.
c t&EAU IN FILENAM~E (COS4tETIC)IF I.NJT* 4FLAG) WRITE. (OUT92400)CALL GrFTLINIFNA4.EtNC)
c ASK 4H-fTMIER IT IS A NE~d FILS (TO PRFVENT FJKTRAN REA,) EQRf3R)5 WdRITE 00)~T92410)
kEAt) tIN 1000) INLINREPLY x NLLNUiIF ((REPLY.NkE.YES).ANO.(PEPLY.NE.N01I GU TO 5IF CREPt.Y.E.J.YEi) THEN DO)
WI~TE (JIJT,2050) FNA?4E
Sdr-PTR a IC ACrIVATE FILE WITH AN ACCESS
LPTR(1) =ICALL ME'OAYfST0RE,-BLINELPTRtll I
ELSEL )C NOw RLAu IN TEXT FILE
LINE v 0WHILE I.TRUE) DO
CALL MEMORY(STREvINLINtLPTR(LINE,1iILINE = LINE +. I
ENV 4HILEla CUNTINUE
IF (INE.GE.M4AXLIN) THEN 00WRITE (OUT,24Z01
C TELL USER FILE OPEN~4TE IOUT,2040) LINEPFNA4E
ENO IF90 20 1 = t AXLIN
STACKM1 I
EN
17
FILE: SLED FORTRAN TI NA~VAL PJSTt;R~nUATr. Sr.lut
cC PARr OF THE SLED PACKAGEC CLOSE$ iJUF 1HE viORK FILE ANI) 4RITES THF '4Evw oi UPflATEOC TEXT FILEC
COMMON /iLK2/ LPTRjMAXLINvEJFI /i3LK3/ TFtL~
2 /aLK1/ INrOIJTINTEGER NAXLIN#INOUTvEOF9TFILEL9LI MITINTEGER0Z LINE LPTRDIMEN45IGN LPTU4'.OOO.1LINE(SO)
20oO FORAT I 4%AI)2450 FORM4AT l. -104o LINES URITTE4-*)
CRWINO TFILEL M4IT aEOF - IOC 90 L Z ~ LLItT
CALL 14MURY (FETCHiLI'EPLPTR(LI)wR~ TE (TFILE,20001 LINE
WRITE (OUTt2450) LIM4ITRETUKN
SUBROUTINdE 4EMORY(ACTIONLINErPTRZ)
C PART OF SLFD PACKAGEC lIANOLES ALL ME ORY REFERENCES JSING OrRECr-ACCESS OISK FILE
CUJRR4ENT CAPCNT IS 408Q LINESREQJUIRES AT LEAST 3 DEuICA ED CYLINDERS OF DISK( SPACL FOR
C WORK FILE UNUER CP/CMS UN AN ION 360/67C COM4ON /'dLK3/ TFLE
INTgGER WF ILEITFILEACT IONP STORE,9PTRPAVAR,E RRS
DINENjION dINElSO03DATA TORE It/
1000 FORM4AT IaOAL)CC DEFINE WORK FILE
WFILELDEFINE FILE 13(40009801E, AVARIC CONiERT PrRZ FROM I NTEIER *2 TO INTEGERPi~p TRJC INITIALIZE READ ERROR COUNTER AND BEGINERRS a 0IF (ACTION .EQ. STREO THEN DO
WKITE (i-LE 'PTRtIOOO) L14EFLSE Of)
C FETCHf5 REAJ (wFILE@PrR9IOOOERRw99) LINE
RE TWI4N E4
IF (EAR4S .LT. 101 GO T3) 5iTop
FILE: SLED FAT~RAN 11 -*4AVAL PflSTM(RAU)'ATE 4.l'lL
ENDSUiBR!urINt: [.4PLT
IMPLE4ENTS TIIf: INPUT 4i3DE
COMiON /3LKL/ INtOUTI /tSLK2/ LiTR1 9AXLIN,EOF
2 /f3LK5/ 4FLAkvvERqCTtCURLINIINT~iER*2 Pt) LPrRABLNKxOUTI[4INTEI<E 'XLINtEO ,ERR%,TCURLIN,9ST1I, tIJitl.,9jiTNCLQGLCAL .FLAGUIMENSIN LPTR(4000)gOUTLIN(90)IDaT% P!)/'.*/,STURE/[/,iBLNK/*'
2111 FORA4AT (I 1>)C lf: .40 INPuJT IN QUUE P~ompr JSER
IF L.iLJI.I4FLAG) WRITE (OUT#2113)CALL GETLIN(OUTLIN*NC)
IF :',4C G(T. 'l THEN 00C UNJLESS IT AAS A NULL LINEC AAKE ROOM FOR NEW INPUT
IF ICURLIN.LT.EOF) THEN DOJ mEUF -CURLIN
00 10 I *jJLPTR(EOF + I - 1) LPTR(EOF 1 )
10 CONTINUEELSE DO
CURLIN aEOFC KEEPS INPUT TEXT CONTIGUOUS
END IFEOF a EOF + I
c GET A NUMBEP FOR NEW LINE FROM STACKCALL POP(LPTR(CURLINI)
c NOW STORE THE NEW LINECAL M4E4qRYISTOREOUTLINLPTR(CURLIN))CURLIN - CURLIN + I
ENO IFC IF NOTHING IN QUEUE4PROMPT USER
IF ( N&14lFLAG) WRIf (OUTiZIL0)CALL GETLIN iOUTLIN.Nq
ENO WHILERE TURN
s'JIItrUrINE GETLIN(OUTLINNC)CC 4FTS A LINE FRO4 TERMINAL; QUEUES UP ?ULTIPLF LINFSC
C(M,40N /BLKI/ INvnuT/t3LK4I TCHAR/SLK5/ MF LAGERRCTtCJRLIN
INTEGER*2 INLIN OIITLINQtJEUE, BLNKPTCHAR4INTi.,'4I4.UTERRCT #CURL INPuI, 9J9 ,KLINELNP si4,E-'h) hN1C,'4LH4RI
LOGICAL "FLAt.,NFLAG
'19
FILE~: SLED) FlIRTRAN TI 'JAVAL V1,%T~>ADUArE jCW'iIL
01!4EN31IJN [NLIN(801 OUTLIN(8OJ,4QUEUE( 40#1))J,~kCAAR(1 )IOATA dLNK/-',(,/LI NEN~O R40
1010 F0AAT (q3AII2Go U FOZRIAf r ( -TRONCATEU; ONLY 10 1 TE4S PFF< LINF-1 I207u FOFC4AT (I *-ILLE-;AL CHARACTER OR BLANK C0'4 1440-1
Cc t4FLAG .(JES TRUE WHEN MULTIPLE INPUT LINES ARE ST4(CK[FJ
IF (.4Ur.M4FIAG) THEN D3READ ClNvLJ10#ERRam99vEN0z98) INLIN
OtJTLIN(I) -INLIN(I)I1=I+1L
EN!) WHILENC a I - IIF (INL[N(fl.EQ.TCHAR) NIFLAC, .TRUF.IF (I.LE.LINELN) THEN 10O
00 23 K ZuIiL[NELNOUTLIN K) = 3LNK
20 CONTINUEENU IFWHILE (INE.N(l).EQ.TC4ARI 00
[F IE l0Q.GEi0J THE4 DOdiRITE (OIJTZO60)INLIN(I a 8LNK
ELSE 00ENO ENDO + 1
NFLAG a TRUE.WHILE I (I.LE L44NELN) .N.(NLIN( I .NE.T'API On
QUEUE (J ENOQ) z INLINII)IF lINLiNUI).NE.3LNKI NFLAG = .FALSE.Ia I1+1j j +
END WHILENCHARS(ENOQ) - J - IIF((I.GT.LINELNI.ANO.NFLAGf NCHARS(ENJOQ)=0IF (J.LE.LiNELNi rHEq Do
00 30 K a JL[NELNQUEUE(KtENr)Q) z 8INK
30) CONTINUEEND IF
ENO IFr:10 W41LE
ELSE OLEC, GET LIN4E FROM QUEUE INSTECD
89 B Q + I.NqC NCHARS(SO)001 40 1 1 LINELNf
OUTLIN 1) * rUEIJE(li,:Q)40 CONT I NUE
IF EBU.Eg.ENOO) THEN 0:3BQ-
END') 0
20
Iii:~~ ~~ (,A FTRAN T 1-VL TAA)~~ESHii
P4FLAG a .FALSF.E'v) I F
END IF4E TUR~N9n CONT I NF
REWN IN9 cuN rI'4;JL
WRITE (60iT,2070)OUTLIN(1) 3LNK(
RE TUPN'END
SUOCUTINJt PISHIXIc
C PIJSiFS A POhINTER TO A FREE LINE ONT11 THE- STACKC
CCM'rp4 /dLKI/ MNOUTI /dLK5/ STACK,STKPrRlNTE5EI STKPTAI~,Nt0UTINTLL;E*2 STACK( XJIMENSION S TACK 4000)
2080 FQR:4AT (I -FREE LINE LIST STACK OVERFLQa-ll
IF (SrKPTR.GT.1) THEN 0OSrKPTR -STKPTR - 1STALK(srKPtRl X
ELSE 00C sTACK OVERFLOW
oiRITE (OUT#2080)END IF
RETURNEND
SuBRCUrUNE POPM,
POPS A POINTER TO A FREE LINE FROM4 THE STACK(
cCCMM4ON /BLKL/ IN OUTI /8LK2/ LPfR,1'4AXLIN,EOF2 /dLgb/ STACKPSTKPTR
INTEGER STKPrR,' 4AXLIP4,401%INCJTINTIER*ZST&CKjLPTR,X
.36M NSI!JN STACK.4000ILPTR140001Z090 F A-44T I I -ALL 5YSTE4 BUFFEqS FULL-')
IF (- ~CK1STKPTr)IFItKPTR LT*. MAXhINI THEN 00SrKPTR aSTKP + t
EILSE 00)4RITE (OUT#2090)
END IFRE TuRNENO~
21
rILE: SLEDl F rTRAN TI NdAVAL PjSTk;tPA i'jTi- S;-,4 ')I
sur3knUriNE C.'jVRT (STRINGl ,Jv N)
CCrNVERTS CHARACTERS I THRnUGH J OF ;rIINT['4 AN JTFEIZI- -J
INTr=GErt*Z STRINIGO[GITXNTEGE4 ItJvNv(,LUIME"NSIJA STRIN-'(801 QIGIT( 10)
DO 20 K = 1,JL =wi-41LF (STRING(K).NE..OIGIT(L)) 00O
L -L + IENO) WHILEIF (L .LE . 10) THEN 00n
N N +(L-Ii*(1Q'*(J-K))ELSE DU
N -99999999RET URN
E-1D I F20 CONTINUE
RE TURNEND
SUBROUTINE CO1MLIN(CI.,CLINEN19N2,EFLAG)CC FINDS AND INTERPRETS THE LINE NUMBERS COJNTAIN4ED ON AC CCMM4AN3 LINE* CHECKS FOR ERR34So
I NTE GER CIN I rN2, I tJINTEGER*2 CLINE913LNK,COM'ALOGICAL EFLAGDIMENSIUN CLINE(801DATA tBLNK/l '/vCO9PAl'r*/EFLAG a FALSE.
C FINU FIkcST DIGITI -CIj- IWHILE ((CLINE(JJ.NE.8LNK).ANO.(CLINE(J).NECM.A)) 003
END WHIJLEIF (J*GE .90) THEN DO
EFL4G a .TRUE.ELSE 00
C CONVERT FIRST NUMBER Tn AN INTEGERCALL CNVRT(CLINE, iJ-iNt)
C LOIlK FOR SECOND NUMBERI +4
WHd(CLINEfJ).NE.8LNK) DO
ENI) WHILEIF i .GE. 801 THEN DO
22
r Y: cLLO t) rR AN T I .'VAL '13ST.JvRAU.%E SCHC;ll
EFLAG = .TRUE.EL SE )J
[F (I .EQ. J) THFN 93C -40 SEU-NO NUJqPF4 EXTjTS
%42 -NIELSE JO
C CUNVERT SECJNf) NJMKFCALL CNVRT (CLI'4EvItJ-IN121
E N) I FIF (N1 .GT. 421 FFLAJ; .TRUF.
ENV) IFENO IF
RE TURNENOsi9RCUr I 4E SEARCH(LINE9STR INGtC9'4ATC1, MCI)
CC PA'T O]F SLE0) PACKAGEC SEAr4CH[S *LIfl~f FUR THE FIRST lCtREC JF $STRING'.C 'I4ATCd'l IS ScT TO 0.TRUE.l IF- 4 M4ATCH IS PlUNO)C INC 1 THE NUM13ER OF CIARACTE'S INJ STrU'4d3' (REUIRED INP'IT)c 14(.I8 1, 4.4 OUTPUT INDICATING; FIRST M~L OiF 4ATCHC
INTEGER [,JLvNC MCIINTE;ER*2 "LINE,S TRINGLOGI(..AL M'ATCHDIMENSIUN LINE U8O) STRING(80)
M4ATCH = FALSE*WHILE U(.N(T.$%ATCH).AND.(J.LE.~l-NC)) Oil
WHILE ((STRING(1).NE.LlINE(J)).%N).(J.LE. li-NC)) 13J=Jx.i
ENO WHILE-IF (J.LE.81-NC) THEN 00
I LL JWHkILE f((STRING( 1+11 EQ.L INEI 14-1 )) .AND.
(141) .LT.80).ANO. (1*I.Lt--. 4C)) ifl1 14 1
ENO WHILEIF ( I *EQ. NC) THEN 00
MATCH = TRUE.ELSE 00
J = +, IEND) IF
EN.) I FEND) 4HILE
RETURNEND
s
23
SLED -FORTRAN IV
24
10/02/qO 12 .Zi.,)2
FILE: SLE02 1 WR RA4t T I JIAVAL ,,lSr.,pp W4IJAT.J S;C1411I~
C SrANOARO LINE EDITOR-FORTRAN ILF4ENT.Af 1A
L SLEi) V:ASI(-,I FORUL.1 NI'S 4ONT" 0CY qojj4jIc PRfl(RA44E0 3Y: C. F, TAYLOR, jk*, Cow 5)r,
c FOR FURiTHFA INFOR*MA7IO1 SEE NOS IECHN!CAL KE.-)lRTc NP S 52 -31- ) U F3 Y L. A.* C 3Xv JR .
C. MAIN P~t;R4M:
2 Ec&J0 I'l C.43I'-ANJS AND CALLS THF A0PRO'PRITE Sj~ii~'jTi,4EC I MPLEmL:NTS rTi4 "ICalT"# MCJOEC,
CU IiMON /'LKl/INOUT /8LK5/MFLAGE'V'CTCURiLI'
OIAiFNSfLnN INLINE(30)LOGICAL FLAG,OPENFL,M4FLAG
*'fqT/fT@/qV/felvd,LNK/' I/2000 FORMAT (1 Q012ULU FIJU4AT (I -INVALID COMMAND- *2Al)2020 FORMAT (I -NO TEXT FILE OPiN-I2030 FORMAT (I -ONLY GNE FILE CAN BE OPENED PER SESSION IN THIS 49 OVFR
*SIGN OF SLEJ-41C. WOIT 14JE--WH ITE PROMPT
WRITE (UUT9200)CALL GETLINI INLINEiNC)CL (NLlIJE41)CZ2 INLINE.( )
C FLAG GOES FALSE AFTER 'QUIT'FLAG - TRUE.
C OPE4FL GOS TRUE AFTER FILE IS OPENEDGPENFL -. FALSE.
C MAIN EI)IT LOOP9000 IF ( .NOT. I FLAG) )GO TO 9001
IF I.N(]T.(.NOT.(OPENFL .OR. ICL.EQ.QI .OR. (CL.FQ.9i) .3R. (CL.F'*Q.Vfl) ) GO) TU 9002
C FILE NOT OPEN AND THIS IS 49T AN q0PEN* CfJ4VANi)C, OR A 14ENUs OR 'VERSION' RE:JJEST
wRITE (OUT9230)0%,O TO 9003
90a2 CCNTINUFC E14ULATE CASE (SWITCH) STATEMENT TO PROCESS CJ M-A'l.)S
IF (CI. *E-4. BLNK) G3 TO 200F (CL.NE.L) GO TO 1.0
CALL 1151 INLINE)10 GOl TO 200
IF (ClANE.Sl GO TO 20CALL SCREEN(INLINEIids TfO 2?0020 C0N T I N4EIF ((Ct.NE.PJ.OR.(C2.NE.Sll ;rl TO 30
25
FILE: SLED2 FC,2TRAN T1 *1AVAL, PJST:;RAJOUATt S..-, :L
CALL ;k(ILI NE)GO TO] 100
30 CONTI'NUEIF (lCL.NE.HI.f3R.(C2.NE.L)) ,0 T) 40CALL RL(INLINE);U TO 200
4'0 CUNT INJEIF U(CI.NE.AI.OR.IC2.NE.L)) GO TO.50CALL &L(INLINE)GO TO 100
50 CGNTINUEIF (ICL.NE.).OR.fC2.NE.S)) GO TO 60CALL DSIINLINF)GO TO 200
60 CONrINUEIF (IC.NE.Q) GO TO 70CALL QUITFLAG = .FALSE.GO TV 200
70 CONTINUEIF (CI.NE.V) GO TO 80CALL VERSGO TJ ZOO
80 CONTINUEIF (CL.NE.M) GO TO QOCALL MENUGO TO 00
90 CONTINUEIF (Cl.NE.O) GO TO 100IF (.N'T.(IPENFL) ) GO TO 9004
PITE (OUT,2030)rU TO 9005
9004 CONTINUE • "CALL OPENUJPENFL = .TRUE.
9005 CONTINUEGO TO 200
100 CONTINUEIF ((CI.NE.C).OR.fC2.NE-T)) GO TO 110CALL CT(INLINE)GO TO 200
110 CONTINUEC IF PROGRAM GETS HERE, COMM40 IS INVALID
WRITE (OU,210 ClCZERRCT a ERRCT + L
C END CASE200 CONTINUE
IF (.NOT.IERRCT.GE.2) ) GO TO 9006CALL MENUERRLT s 0
900b CUNTINUE9003 CONTINUE
IF (,'4JT,(FLAG) I GO TO 9008C GET 4EAT LINE
26
FILE: SLk)2 14 R TA' I 'JAVAL 110ST ;R AJAT. rI 4fif! I
I F (.'4 IT.FLAG R ~I TE WtXUT,200 0
%L 2 IN.L 14 E( L)
900O8 CCNTINUFGO TO J0J.)
9001 CONTINUEST, j
C. Cijk'Wrj /dLKI/ IN9JUT /BLK3/ TFILE /BL.K4/ TC~/.ALK5/ 1*i A;I'r,C LIKL I N
I~TLF~*~rCfIARINrE-;L-A IN,-hJT9TFILIEP.RCTCUPLINLt)ACAL 4FLAt,DATA IN5@.)//@CA/$/tRCTOt4IA, 4~E )I %l Tr
* ILF/2/END
SUbROUTINE LISr(CLINE)cC DISPLAYS TFXT TO THE TERMINAL
CLP4MUN /KLKI/ 1*49OUT /R1K2/ LPTRvMA(LINg,jF /-i11K5/ - FLASjPR-CT,*CUR&L ININTEGEA*2 JL-KLPTRtCOMM'I' OUTLIN CLINE1'4fE'FR INiijUJL ,JNL.N2,MAXLIN,&OF,ERHCT.CJRLIN,FET-iLOGICAL MFLAGvEFLAG31 MENSION CLINE( 81) , UTLI14(80) tLPTUk 4000ODATA BLNK/' '/,CUV4A/ ,l/,FETCI4/0/ 7
2100 FORMAT ( INVAL 10 COMMAND-')I2110 FORMAT 0 '14 LX,'30A1)2120 FORMAT ('I -9f)F!- )
C IF COL 2 IS ILANK, PRINT CURLIN A'40 EXITIF (.N)IT.(CLINE(2I .EQ. BINK) ) GO TO 9010
CALL ME~lfhY (I-ETCHOUTLINiLPTR(CURLP0)wRITE (dUT,211,0 CURL1'J, UUTLIN
.. r~j 40119010 C'NrIIiE
C % Ai C -it ,KC FOR LINE 4UM9IERS IN COMMANtI)LALL s.tJML[N( 2,CLINE,NlN2vEFLAG)IF (NI, .E. Of .41 = I.IF ('1 .GTo 4'21 EFLAG TRUE-.IF 4NI .-,E. ELF) EFLAG .TRJE.I F (.N0 todFF L Ara) GO TO 901L2
FRRT =ERikCT + L
ti'J Tu 10O139012 CO(NrINUf
27
FILE: SLE02 ru-4TRA4 T I NAVAL I'ijr:T~A0iA(F ,i(lf~'I':
9014 IF (4o f~).(41.LE.N2) .ANi).( IT .t5'F)J 1 .'0 10 01CALL ,1EM'JRY (FETCHtOIJTLP1,tLPT (IflVKiITr- lijdT,Zltu) It UUJJLINGURLIN
Go ro -)OL490151 CCNT INUE
IF I ..;E.EU2Fi WRITE (OUT #2120 19013 CPNrINUE9011 CONTIN~JE
RE TURNENO
SUBROUTINE SCREEN(CLINEICc I)ISPLAYS 20 LINES 4EGINNING WIT11 ZCRLIN OP OTHER SPIECIFIZf) LINF
C CJMP4ON /I3LKL/ INOUT /BLK2/ LPTR,MAXLIN,EJF /flLK(5f ?FLA 'v9RPCTv*CURL ININTEGER IN*fUTt,MAXLINEOFERRCTCJRLINII4NL,4tLIM1T, FETCH,,vIN4TE.,El4' CLINE LPTR#UUTLI NPFLNKLOGICAL MFLA ; 'EFLAGDIMENSION CLINE(80)q0UTLIN(80)qLPTR(4000)DATA BLNK/' '/9FETCH/0/
2130 FORMAT (s -INVALID CUOMMANU-')2110 FORMAT 0' #g14jlX,4~0Al)2120 FORMAT If - UF-0)
EFLAG = FAISE-C FIND OUT wHeTHER USER SPECIFIED A LINE
IF (.NkOT.(LLINE(2J.NEeL'MI I GflFo qO1'sCALL COMLINI2,CLINEvNIN2uEFLAGlIF (NI, LE 0) NI, aLIF (NI. .GE. EflF) EFLAG -TRUE.IF I.NOT. EFLAG) CURLIN aNI
9016 CONTINUEIF (.NOT.(EFLAG) I GO TO 90IR
ERRCT w ERRCT + LWRITE (GUT,21001GO TO 9O14
9018 CONTINUEERRC.T *0LIMIT = MI1NO(CURLIN4I9tEOF-1)0)0 10 1 aCLRLINLIMITCALL 4EMORYlFbTCH OUTLIN LPTR(I))WRirE (Jur,21,10) i,13UTLIN
L0 CONTINUECURLIN aLIMITIF ILIIT .EQ. EOF-1) WRITE tJUT#212?0J
9019 CONTINUERE TURNEND
28
r1 F SL E32 F~lVArk AN Ti LPA VAI P,) iT; Oi ',JT F s; C Hl
SIJ(RCUT1NE qL(CLINE)
L REPLACES CJRqRFAT LINE 13K THE SPECIFIFL) LINE OZ 1 INFS 4[TAC_ AN~Y NUMBiER OF L[INES
CJ4oN lq~ /t3LKI/ I~jt.IUT IaLK(2/ LPTRpMAXL,E)F /Th'K5/ 'FLAGP RRCTv*CtJKL IN4INTEGER !N4,OUTt4AXLI'4,EOFIRPCTCJRLINNIfLP,I ,,J,ilil I, ST! ;1.%TE-rvFR (.LINtLPTIkaLNKLj'(ICAL MFLAG,EJfLAG0IMENSt0N I-LINE(S0),LPTR(4000)DA~TA EILNK/l 0/tSTURE/I/
ZLOO FORM4AT (I -[NVALIJ COMktIANU0h)
,NI = CJRLI.'4NZ= NI
D ETERMINE W111CH LIEMS TO REPLACEIF (N).(CLINEfJ).NE.BLNK) I GO TO 9020
CALL C0MLINI3,CLI,4E6N1,N2,EFAG)IF (NI -LE- 0J EFLA~ = .TRUFIF (NI G~E. E(JFl EFLAG - .TRUE*IF (.NOT. EFLAGI CURLIA = NI
9020 CONTINUEIF (.N0i?.(kFLAG) ) GO TrV )022
ERRCT a FRCT + IwRITE f60J,21001GO TO 9023
9022 CJNIINUEE:RCT v'3IF LNZ .GE. EOF) 42 a EOF I
C REMO'VE DESiIIrMTEfl LINESN - N2 -Ni +. 100 20 1 lvINLIMIT -a EOF - 2C4LL PUSI(PTR 141)I00 10 J a N1 L1tI1TLPTRIJ) a LPfRJI
to CCNT[NUEEOF a EuF - t
20 CONT INUFC NOW INPUT REPLACEM4ENT LINES
CALL INPUT90Z3 CONTINUE
RETURNEND
SUBROUTINE AL(CLINE)
INPUT TEXT AFTER LINE NC
COMMON /31K1/ INtUUT 1131K5/ MFLAGERPCTvCJRLF%
29
F ILE SL f-02 FfJ4R RA:4 T I NAVAL P )STt;-RA 1 UATF Si~1
i.NrEGER*Z tIL4Kv~CLI'4EINIEG.FiR IN,;JUTI ,JtNtNlPNZPERRCT#CL)RLI'qLJGICAL .4FLA(;qEFLA,DIM ENSIOlN (.LINE(00CATA BLNK/I I/
2100 FORM'AT 0' -INVAL It. COM4ANU-91CC EXTRACT L1INE NU?4AIER FROM COMM4AND LINE
CALL LOMLIN( 3,CLIN~iN102iPEFLAG)IF 4N1 .LT. 0) EFLAG a T1RUE.N aNiIF (.,NOT.IEFLAG) I GO TO t)024
ERPLT = EARCT +IWR~rf ojjr9ZLUo)GG TO 9025
9024 CONFINUEERP;: -CURLIN zN + L.CALL INI'UT
9025 CONrINUERE TURNENO
SUJBRCUTINE JS(CLINE)
C PART OF SLEU PACKAGEC JISPLAYS ALL LINES CONTAINING THE OESIGNATEO STRING, PflSSISLYC LIMITE) TO LINES N THROUGH MeC
COMMON /FILKI/ ii9our /BLKZ/ LPTRv4AXLINEOF /BLK5/ 4FL,E:-'CTCUl*LININTEGER IN,OUrMAXLINEOF:ERRCrCURL [N,NlIN2,NCFETCH,4ICIINTFGEL*2 CLLNE,LPI'RB0LNK STRI. " LINFLJt.,ICAi. 4FL AGE FLAG ipMATCHi FOUNODIMENSION CLINEte4')1,LINEI 40)#LPTR(4000),STRI4IGy)DATA SLNK/8 l/#FETC.H//
2100 FORM4AT (0 -INVALID COMMAND-*)2110 F'.RMAT (1 0 14 LX, 30AL)ZZ20 FORMAT (I Oi) STRING?>')2250 FORMAT (I -NO STRING FOUND-')
CC OEFAULr VALUJES
FJUND - FALSE.EFLAG m FALSE.NI INZ EL)F - I
C QETEPHIfdE O#i4THER NIN2 WERE SPECIFIE) BY JSIRIF (.NUTJI(LLINE(3) o N E. LNKI) Grl TO 9026
CALL COMLItiIS.CLINE,MINZEFLAC;IIF (NI .Gf. EOF) EFLAG - T1RUE.IF INZ .GE.* EUFI N2 a EOF L IIF IN1 .LE. 0) NI I
9026 CONTIN'JE
IF (~t)T(EFLG) IGO T 102
30
-ILE: SLF02 Frb4IRAN TI 'IAVAL P'1Sr.;RAIJOATE SCWI
ERRCT -z ERRCT + 1WRITE (7UJT#2100)GO ri '4021
9028 CONTINUEERRCT m0
C FETCH ilRING; ISSUE PROMPT IF IECESSARYIF t.NIJT. 4FLAG) WR~ITE (OUTP2220)CALL GETLIN ISTRINGINCIIF C .,4'JT.(NC .LE, 0~ GO(. TOJ 9030
E.RLT = ERkCT + IWR~ITE ('JUT92L.00)
9030 C ON T INO F-11 ?0 1 - tiiN2CALL 4E-MURY(FETCHtLINErLPTR(I))LALL SEARCH(LZN'ESTI[NGNCIATCi4CI)If (.Nf]T.(,4ArCH) 1 5 TO 9032
Frhj?4U = .TRUE.CtJRLIN = I
9032 CONTINUE20 CONrINUE
IF (.NUT. FOUND) WRITE (OUT92250)9031 CCNTINUE9029 CONTINUE
RE TLRNEN DsuaHourINE RS(CLINE)
C PART OF SLED PACKAGEC REPLACES T14E FIR4ST OCCURRENCE OF STRING!, hIP-i STlING2 i)" THEC CURRENT LINE' OR WITHIN THE SPECIltIED) RANGE OF L1INES
COMMON /81KL/ INUUT /13LK2/ LPTRtf4XLI 3 Jl,EOF /f3LK5/ 4FL.A3,ERPCTClJP*LIN
INTFGEtR IN tQUTpMAXLI N,EOF ERRCTiCURL INN1,N2,I1 ,J,9K9LrM IM4Clip,,'C*NCZ 'F:ETCH,STlREINTEGER*2 CLINE#LPTR,8LNK.STRI#STR2tLINEnIMENSION LPTR(4W,)Ol CLINE(80) STRI 1801 ,STR2(30),LINEPO0)JATA BLNKl l/ FETCH/0/,STOREff/LOGiICAL MFLAC ,C)UNC) MATCH,EFLAG
2 L-0 izORMAT I -IN4V~AL1I) &JOMANj3-112110 FURT I' I.4 l I4#Xv3OA12230 F0W'4AT I# UL"1 STRING?>')224*0 F-11K MAT 7Pf NEW 5JH P4G?>)2250 FJR:AT I# -Nil STRIN4G FOUN3-0)
CC aEFAULT CONJITIONS
f4l a CO'JIANZ - NIEFLAG -a FALSE.
C INTSAP-Ef C )MMAND LINEIF (.N~r.(LLlNE(3).NFBLNK) I GU TO Q031+
CALL ClJMLIN(3,CLINEtNIN2;EFLAG)IF (NI .LL. 01 EFLA G T .TUE.
31
I
FILE: SLED2 FORTRAN TI NAVAL PUST ;RAJUATE SCHf'1L
IF INI .. ,E. EUF) EFLAG a .TAUE.IF 142 .GF. ELF) NZ a EOF - 1
9034 CONTINUEIF I.NUT.(EFLAG) I GO TO 9036
ERP;T 2 EkRCT + IWRIrE tQ.JT,21i)O)GO T.J 9U37
9036 CONTINOEERRC T - 0
C REAJ IN T,40 STRINGS' PROMPT IF NECFSSARYIF (.NOJT. MFLAI WRITE (OUT,2230)CALL GETLIN(STRLNCLIIF NCL .LE. 01 EFLAG IC.JE.
IF (.NOT. MFLAG) WRITE (OUT,2240)CALL GETLIN (STR2,NCZlIF (.NOTo(EFLAG) I GO TO 9038
ERRCT A ERRCT + LWRITE IOUT,200)RETURN
903)8 CCNTINUEC NOW FINI) STRINI
FOUNO -. FALSE.DO 50 K = NWNZCALL MEMORY(f TCHiLINE4LPTR(K))CALL SEARCH(LIN, TRI NClMATCH, MCI)IF t.NOT.(MATCH) I GO TO 9040
C NOW MAKE SUBSTITUTIONJa MCLFOUNO = .TRUE.
C OELETE STRINGL00 20 I a LNCLDL l0 M'4 a J T79LINE(") a LINEI/*I)
10 CONTINUE20 CONTINUE
C NOW MAKE ROOM FOR STRING2IF (.NOT.(NCZ .GT. 0) 1 GO TO 9042
0U 40 L a 19NC2M m SL - JOU 30 1 a 2011
INE(82-11 a LINE(81-I)30 U]NTINUE40 C,]NTINUE
C NO1W INSERT NEW STRING00 45 I * LtNCZLINFE(J I-1) a STR21I)
45 CJNTINUE9042 CONrINUJE
C STORE REVISED LINECALL "EMORYISIORE LINELPT IK)0ISPLAY REVISED LINEWIT 1 Ortzl KJNEREMOVE C IN C ABOVE LINE TO ENARLEUISPLAY OF EACH LINE IN WHICH A STRINIG HAS BEEN
C REPLACEO
32
FILE: SLFA)2 FfIRTRAN T L NAVAL POST,;RAJUATcj SCIA'IlLCUIRLIN =K
9040) CN r INJE5o CVN rI NUE
If tSIF rJUNO) WRITE (UIJT,225O)19037 CONr INJE
'RETJRNENDSURRCUTINE CT
cPART OF SLE.) PACKAGE
C CkiANGFi rr4E MESSAGE TERM14ATOR TO ANY VALIU CHARA~CTERC COMMON /BLKL/ INT,0UT /BL,(4/ TCHA /BLK5/ t4FLAG,ER&CT,CJ41.ItJ
INIE~jFR IN.0'J[EKRr-TeCURLINtNCINTIGEiR2 TCHAR, INL[Nt8LNKLOGICAL .MFLAG;N ' AENSION INLI?4(80)LOATA BLNK/I I/
21,00 FOR*4AT (# -INVALID COMMAND-')2200 FORMAT (t TERMIN~ATOR?>91C
IF (sJllT.(.N0r. MFLAG) ) GO TO 9044C ISSUE PROMPT
WRITE IOUT9220019044 C&JNTINIJE
CALL GETLIN(INLIN*NCIIF (.NU)T.(NC.EtJ.0).CR.(INLINIII.EQ.BLNK)) )GO TO 9046
ERPLT - ERiRCT *IWRITE (UJT#21OOIGO TO 90'4r
9046 CONTINUETCHAR a INLINII)
9047 CONTINUERETURNENDSUBROUTINE MENU
CC PART OF SLEO PACKAGEC PROVIDES USER WITH A SUMMARY OF AVAILABLE LOV4MANDSC AND THEIR FORMATS.C
COMMON /BLKI/ INOUTINTEGEA 114 OUT
200 FORMAT I LED L04'4AND SUMMARY:f/f' IINE/Ti-XT ItjSE'9TlqT3s, *STRpI~AN KEPLA(.EMENr'/3x ,ALNI TV3,INSERT <A>I-rEk <L>1141 Nl, r4U),IRSPC,26*lvT48o,<RlPLACE..i>TRI NG' ,/3X,lRLN' ,TI0, '<A>EPLACi (L>1%F tj*',T4O,'RSN$P$Q%'vT50,11#P"l WITH " INN/ 3X,'RLl4r4',Tl5,'LlNPS N T;4
,RjM .40,'ASNvlSP5QS' ,T52, 'I1DICATE) LINES.'I, OUJTPUT CIM'1ANOSI'*T38 TSRIN~ SEARCHI/ 3X '* *')I31SPLAY CUmRENT <L>IN~' r,4)lfs:?S 8 A.P<>IPLAY LINEi '/3Xr'L4*,TlD,'0R LINJE N.,''.'WITH <S>
* Ti IN vl3ftLNvM'vTlO,'LINFS 4 THRJ 4',T4+) 'IJSN*,'4SP~,T44v,'-'0 SHOW ANY L INES'
201 FORMAT (3X,'S( ,rvo,<S>HOW A *9 '"SCREEN" UF LINFrS',T,J,'i-4 CON'T.A*INING "P"0/ 3X1 SN',TLO, 'SnW A S'REEN FRrlM LINL N',TlAl,'LNTirL C
*OM?4ANOS'/ 3X914 v.TO,'SOW COMMAN6 <M>FN0 (T'4ISllvT',09'f'lT *8, 4<-.
33
FILE: SLE0Z FCJRTRA:4 T I 4IAAL 0I'Si-,KAJ(%TL SCHI,r'L
*>PFN A FILL RO/3X, VlvTIUSHI <V)EP-I0N I 1l1'4ATIOV %fiT52-,'C')A*TE 4 FILE FOR A)IT NG I/140tOCT <(Z>HANGr-- THE LOGICALI/ IX'r r'*IT THE F01 T TYPE: "lJ<Rc-T>"'T4J,'MFSS4GE <T>F!fVll', '.AtR 1 1
WRI 1TE I titT, 20))%'RITE ((JUT92f)11R TURNENDSUBROUTINE VFPS
CC PART (IF SLEJ PACKAGE
C COMMO0N hILKI/ INOUT,2 NT EGER lN1JI'T22I~RMAT (I SLEU VERSION FORT1.1 NPS 4MNTEREY 4flU4.J1/ I Lfl-'L EX(P!-R*r 15 C. TAYLOiR 406I-646-2691 0800-1700 I)STIJT// I LINE O)FLETE KE-Y*IS < > (ASCII) OR <CENT S[G04 *, *(EdCQiC)e/$ C14ARACFFP JhLPETF KsEY IS <4>4)// 1EDITOR LOGICAL MESSAGE TERM4ATOIRS AqF:I/ I MI*<RETURN> %NO (2) <$>I// I A!40 CA-11 FF CiiAN';ED TA ANY STANiIA~l" FORrf(AN CtiARACrER.I/ 0 ALL IAIOIJT IS TPANSLATEt) TL) U'PEM CASE.'/" THE FOLLOWING DEVIATIONS FROMI SLED STANDARJ mERE i4F'.UIF:')
221 FORMAT * (1) THE UNIVERSAL ENTRY COMMANO 143LEc:)" INIGK- S IJ4STRUC*TIJNSI /0 FOR A NON-STANUARD) ENTRY: '1SLL0L (FILEilA'4r <FlirT*YPE> "s/ (2) ONLY ONE FILE PER SESSLW;4 CAm tiE I (~i)u*3) MAXIMUM FILESIZE IS 4000 L[NFS.'/ 1 (4) THE UjSER~ I ASKFO1 T-I*IN3ICATE WHETHER HE IS EDITINS A S/I NEW FILE IN ORJFR T RP*EVENT A DISK READ ERROR IN FURTRA 4.4/0 (5) mHEN <RET:PR'4> IS USF')* AS A LOGICAL MESSAGE f/ I TERMINATflRP THE LINE UR STqIN'v IS*PADDEO WITH BLANKS ON' THiE RIGHT. THIS AFFFCTS THF RS F*UNCTION ONLY.')
222 FORMAT I 1 (6) ONLY THE FIRST (CCJRRENCE OF A SrRING 14I EACti LINF*@/ I IS REPLACED TO PERMIT FREE SUBSTIrUT IONS JF -LA&.IKSI)
WRITE (our,2/ZJIWRITE IIUT922L)WRITE (')UT9222)RETURNENDSUBROUTINE UI'EN
CC OPENS TEXT FILE AND WORKSPACE FILEC REAuS rEXT FILE INTO WORKSPACE IF IT ALREAOY EXI.TSC INITIALIZES POINTERS ETC*C
COMMON /BLKI/ INtOUT /BLK2/ LPTR.'4AXLIN,EOF /BLK.3/ TFILE /ALK5/ %Mp*LAGOCRCTOCR LLN IBLK6I STACK STK;TRINTEGER I I~U ,rF[LEtLINEtERRtr,CLIRLINPSTORE,4AXLI,EOF, STKPTRPI#
*NCINTEGER*2 LPTR9STACK vFNAME, INL IN 9YES 0!IflREPLY 9BLINELOGICAL MFLAGDIMENSION LPTR(4O)00),BLINE(80),STACK(40O)FNAME(3)IN1INUM((I)OAT& YES/9Y1/v8LLNEf80* I/NO/4*N/vST't3RE/1/
1.00) FORMAT (80AI)2040 FO3RMAT (@ -' ,14 L INES I4 FILE: ItROAl)2050) FORMAT (I -CREATLNI, F LE: ',SO)AI)2400 FORMAT @ FI-LENAlAE?>*I2410) FORMIAT 4' 1S rHIS A NEW FILE?>)
34
FILE: SLEDZ FIIRT RAN TL 14AVAL P1 STI;RAD'.JA TE S HC'1t
24Z0 FORMAT It -MAX CAPACITY 4O0 LINES EXCEE'JED-0CC INITIALIZE
MAXLIN = 40OUCUPLIN -L
C REAO IUl FILE-NAME (COSMETIC)IF (.N0T. MILA.;) W4RITE (LJOT,2'.OO3CALL GETLINI1-NAML,4C)
C ASK ,HETE- IT IS A NEW FILE (TO PREVENT FoRrAI READ ER')4)5 WRITE iOJUT,2'1#O)
READ (INluJO) [NLINREPLY = 'LLIN(I )IF I IPEPLY.NE.Y-S).AND.(REPLY.NE.NOI 3 GJ TO 5IF (.NIJT.(REPLY. EQ.YES) ) GO TO 9048
WRITE (UUTZO,UI FNAMEEOF - ISTKPTR =ACTIVATE FILE WITH AN ACCESS
PTR( 1) -aALL MEORY(STURE,8LINELPTR(1))
GO TJ 4049J9048 CONTINUE
C NOW REA IN TEXT FILELINE = 0
9050 IF (.NOT. (.TRUE.) I GO TO 9051READ (rFILE|L1,00ENO-1O) INLINLPrk(LINE•L - LINE + 1CALL MEMORY(STOREvINLINtLPTRILINE+I))LINE -t LINE + IGO TO 105U
9051 CCNTINUEi0 CONrINUE
IF (.NOT.(LINE.;E.MAXLIN) GO TO q052WRITE (OUT,2420)STOP
905Z CONTINUESTKPTR = LINE + IEOF a STKPTR
C TELL USER FILE OPENWRITE (JUT,#24O) LINEPFNAME
9049 CONTINUE00 20 1 I*MAXLIN2TACKl) 1,
20 CONTINUEME TURNENDSUBROUrINE QUIT
c. PART (IF THE SLED PACKAGEC CLOSES UUT THE WORK FILE. ANO WRITES THE NEW OR 40OATED)C TEXT FIL:C
COMMON 18LKZ/ LPTRPMAXLIN,EOF /fBL(3/ TFILE /dLKI/ I'J,flJTINTEGER '4AXLIJN INtOUrEOF, TFILEtLL IMITINTEGER*2 LI'ELPTK,
35
FILE: SLEnz FdRTRA4 TI NJAVAL PJ:)T!;kAnJATF S (H..'.I
OIMi:NSIGN LPTR(40')'J)LINE(8))2000 FOR4AT (40AL)2450 FORMAT (1 -9, ,1 LINES WRITrEN-11
CREWIND TFILELIMIT = E1F - 100 90 L = I,LII["CALL MEMt]RY(FETCHLINEgLPTR(L))WRITE (TFILE,20001 LINE
90 CJNTINUEWRITE (OUT,24SO) LIMITRE TURNENDSUOROUTINE 4E.4kY(ACTIONtLINEtPTR2l
CC PART OF SLFD PACKAGEC HANDLES ALL MEMURY REFERENCES USIG DIRECT-ACCESS OISK FILEC CURRENT CAPACITY 13 4000 LINESC REqUIkeS AT LEAST 3 DEDICATED CYLINDERS OF UISK SPACE FFp.C WORK FILE IN;)ER CP/C.IS ON AN IRtM 360/67C
COMMUN /BLK3/ TFILEINTEGER WF I LE TF ILE# ACTIONtSTQREt PTR AVAR ERRSINTEGER*2 LINEPTRZ0IMENSION LINE(80)DATA STORE/I
LO00 FORMAT (SUAl)CC DEFINE WORK FILE
WFILE - 13DEFINE FILE 13(40009806EAVAR)
C CONVERT PTR2 FROM INTEGER*2 TO INTEGERPTR = PTR2
C INITIALIZE RFAO ERROR COUNTER AND BEGINERRS - 0IF (NUT.(ACTION .EQ. STORE) ) GO TO 9054
WRITE 4WFILE'PTRl00) LINEGO TO 9055
9054 CONTINUEC FETCH
5 REAJ ('FILE'PTRtLO0OvERR=991 LINE9055 CUNTINUE
RETURN99 ERRS - ERRS + I
IF (ERRS .LT. LO) GO TO 5STOPENDSUBROUTINE INPUT
CC IMPLEMENTS THE INPUT MODEC
COMMON /%ILKI/ INOUT /BLKZI LPTR,'AXLINEOF /IBLK/ MFLAGr.C'Tj.t P
*LINNTrEGfR*2 PDLPTRLNKOUTLININTEGER ,AXLINEOFvERRCTtCURLINtSTOREilJtINJLUTtNC
36
FILF: SLED? FuR TRAN T 1 [-lVAL *"JIST ,RAO~UATr S'w4 i;i
LOG-ICAL 4FLA'DIMENSIOIN LPTRC4UJU),UUTL 1,N( 90wATA P ')/l.l/,STOPE/l/t6VlK/ '/
2110 FORM AT (I i> 0)C IF NC INPUIT IN 'JUEJE, PROMPT USEP
IF (.NUT.MFLAtJI iRITE (OUT9211O)CALL GLeTLIabiUTL[N,NCJ
9056 IF i.Nfir. (.'4T (,'T I I I E)P ) A U (iT I42 . t~3%K I*TO 105 f
IF ( NJT.(Nr_ .%;T. 0) 1 GO TO 9058~JALES IT WAS A NULL LINE4AKI: RfiUM FOR NEW 14PUTIF~ (.NIT.(LURLIN*LT.EOF) ) SO TO 906.1~
J = EOF -CURL INDI') io I IjL 3TR(EUF 1. - 11 = Lf)TQ(EOF - 1)
I0 '60NTINUE(. d TJ 9061
9060 CONTIN4UFCURL IN = EOF
C KEEPS INPUT TEXT CONT[GJOUS9061 CONTINUE
EF= EOF #.1C GET A NUMER FOR NEW LINE FR)M STACK
CALL POPILe'rRICURLINI)C lOW STORE TH-E NEW LINE
CALL -If MOIY STOREOUTL IN LPTR (CURL IN))CURLIN = CURLIN f 1
9058 CONrlNIFC IF NOTHING IN QUEJEt PROMPT USER
[F (-.NOT.'IFLAG) WRITE (OUT921101CALL GETLIN4OUrLINNC)G~O TO 4056
9057 CONTINUERE TURNEND
c SUBROUTINE GETLIN(OUTLINNCIC GETS A LINE FRO4i TERMINAL; QUEUES UP MULTIPLE LIFS
COMMON /3LK1/ [N,9OUT /BLK4/ TCIAR /gLK5/ 4Fi. ;,o~kR~r,CJOLININTE(,ER*2 INLL 0ULNQUEUEif HARKINTEGEA INPOIJTt RRCT ,CURLIN, !JrK LINELN,'J, -4;.JCtCHArvLOGICAL AFLAGiNFLGDIMENSION INL NU3O1,OUTLIJ(8O3,QUEUE(80,loI,N.J41MS(LU,)DATA IILNK/l f/,LINELN/80/,13Q/0/,qnOQ/o/
1010 FORMAT (30ALI2060 FORMAT 0' -TRUNCATED; ONLY 10 ITF*IS PER LI'IE-')c2070 FOR(MAT (I -ILLEGAL CHARACTER OR HLANK COMM'AN--1
c 5FLAG GUES TRUE WHEN MULTIPLE (NPUT LIPJFS A~RE STA~.KF0IF l.N-jT.f.k40T.Ml-LAG) ) GO TO 9062
REAl) IINrl~iJ,ERR=Q9,E'4D=93) IlLIN
37
FILE: SLEUZ FORT RAN rTI NAVAL PlbrST';RAfUATE >['l
9064 IF i.NflT. (i.LE.LINEL4).ANO.(INLIN(I)i:k.rcHiU) G1 TiOtJTLIN(Il = INL[N(l)
G-' TO 90649065 CCNTINUE
NC =I - LIF I[NL IN ( I EQ. T CAR I MFL( G .TRUE .IF (.N(JT.(I.LfL.LI,.JELNI ) GO TO 9066
UO 20 K 19LINELNOJUTLIN(KT = '3LNK
20 CONTINUJE9066 C ON T INUE9068 IF (.NOT. ([VJLV4(I).EQ.TCHAR) I GO TO 90)64
IF (.NUT.(LNJQ.GE.L3) ) GO TO 9070WRITE MLUT,20601IIL[N(I) x BLNKGO TO V07L
9070 CONTINUEENQ ENOQ + L
NFLAG = TRUE.9012 IF (.NOT. ((I.LE.LINELN).ANO.(INLINII).NETCHfAR)) IGCl T9
*9073QUEUE(JiENDQ) -INLIN(I)IF IINL N(I).'4E.8LNK) P4FLAG = .FALSE.
GO To 90729073 C04~TINUE
NCHARS(EN)Q) a J -1IF((I.GT.LINELN).AND.NFihA") NCHARS(ENDQ)=0IF (.NOT.(J.LE.LINELN) GO TO 9074
00O 30 K J6LINELNIJUEUEIKENO I BLNK
30 CONTINUE9074 CONTINUE907L CONTINUE
GO TO 90689069 CCNTZNUE
GO TO 90639062 CONTINUE
C GET LINE FROM4 QUEUE INSTEADLIQ a BQ + INC = CHARS(aQ)00 40 1 a ILINELNOUTLIN(I) x QUEUE(I.BQ)
40 C ON I AUEIF .NOT.(BQ.Eg.ENOQ) IGO TO 9016
EI4DtJ 0?4FLAG .FALSE.
9076 CCNTINUE9063 CONTINUE
38
FILE: SLFO?2 FuRTRAN T 1 JAVAL PfJST ;R!JUAThF ,rH,, r;I
RETURN98 CONTINUE
R.w.iINO IN'99 CON~TINUE
WRITF (JUT,207O)OUTLIN(&) aBLNKRE TURN
SUBiROUTINE PJSHIX)Cc PUSHES A POINTER~ rl) A FREE LINE INTO THE STALK
c COMMO4N /3LKI/ INOUT /RLK6/ STACKSTKPTR
INTEGEA STK~fr1v,i,OUTIN4TE(FR*2 STACK,Xr)I4ENSION STACK(4000J1
2010O FOR4AT 0 -FREE LIAE LIST STACK( OVF.RFLOW-1)IF (.NOT.(srKPTR.GT.1J) GO TO Q018
STKPTR =SrKPTA -1STACKfSTKPTR) v XGO TO 907Q
9078 CONTINUEC STACK OVERFLO~W
WRITE (OUT92O8JI9079 CONTINUE
RF TIRNEND
SUBRCUTINE PtJP(XJ
C POPS A POINTER Tub A FREE LI.NE FRIM THE STAQKC
CJ.J'9MN /BLKI/ IN,OUT /B3LK2I LPTRP?4AXLINtEi)F /'4LK6/ S3TAZK,,TVPTPINTEGER STKPTR.'4AXLINtEOF, INYOUT[NTEGER*2 STACK LPTRXDIMENSION STACKd401O J,LPTR(400U)
2090 FORMAT 0' -ALL SYSTEM1 BUFFERS FULL-')X a STACKISTKPTR)IF I.NUT.ISTKPTR .LT. PAXLIN) )GO TO 908U
STKPTR = SrKPTR +GOl TO 9081
9080 CONTINUEWRITE (OIJTP2O901
9081 CONTINUERE TURNE40
SUBROUTINE CNVRT(srtNGivJNI
c CONVERTS CHARACYERS I THROUGH J OF STRING INTJ A~4 INI-E-E '4
39
FILE: SLEJ0 FORTRAN 11 'I4VAL P.ISTGA)UTE CilW'"ll
C INTEGkR *2 STIINGPDIGITINTEG.& IJ ,N.KLDIME'NSION sTf[ 4G(40),D[GIT(iO)UATA OLGIT/'0', 1' ,2 3, *41,e5w *~l, 7*,I J6 t4 /N = 000 20 K t I,-IL =9O8Z iF (.Nr, (TRI'4GIK).NE.DIGIT(L)) ) GO TO 90A3
L - L I9O TO 9082
9093 CUNTINUEIF (.NO3To(L -LE. 131 1 Gn TO 9084N m N * (L-LI=(LO**(J-KIlGO TU 938
9084 CONTINUEN a -99q99999
RETURN9085 CONT INUE20 CUNT INUE
' RETURN
END
SUBROUTINE CUNLIN(CI#CLINE#NloN2,EFLAG)CC FINDS AND INTERPRETS THE LINE NU'BERS CONTAINED ON AC COMMAND LINE. CHECKS FOR ERRORS.C
INTEGER CLvllN2#IvJINTEGER*Z LLINEtLNKCOMMALOGICAL EFLAGUIMENSION CLINE( 80)DATA 8LNK/' '/.COiMMA/*#'/EFLAG = .FALSE.
C FIND FIRST DIlITI Cl
9086 IF (.NOT. |(CLINE(JI.NE.BLNKI.ANO.(CLINE(J)NE.Cr)MMA)) I SO TO v)l
J-, J + LGO TO 9086
908? CONTINUEIF N.N r.(J.GE.80) ) GO TO 9088
EFLAG -. TRUE.GO TU 9089
9088 CONTINUEC CONVERT FIRST NUMBER TO AN INTEGER
CALL CNVRT(CLINE9IJ-ltNI)C LOOK FOR SECOND NUMBER
I = + I
9040 IF I.NOT. ICLINEIJ).NE.BLNK) S GO TO 9091J 34 J jGO TO 9090
40
FILE: SLE? frRTRAN TI NAVAL POSTGRADUATE SCItwi'It
9qOq CCNTINUEIF (.NUT.(J .6E. 40) GO TO 9092
kFLAG = TRUE.GO TO -093
102 CONTINOFIF (.NUT.(I .EQ. J) I GO TI 90q4
C NO SECUND NUMBER EXISTSN2 = NLGc TO 9095
9094 CONTINUEC CLNVERT SECONO NUMBER
CALL CNVRT (CLINEIJ-"102)9095 CO0,N T U JUE
IF (NI .GT. NZ) EFLAG = .TAJE.9093 CCNTINUE9089 CUNTINUE
RETURNENDSUilRcUTINE SEARCH(L INESTUINGNC ,vATCH, MC )
CC PART OF SLEO PACKAGEC SEARCHES ILI;4E1 FUR THE FIRST OCCURRENCE OF 'STRING'.C a'ATCH' IS SET TO '.TRUE.' IF A MATCH IS FOUN).C INC9 IS THE NUMBER OF CHARACTERS IN 'STRING' (REQUIRED INPUT)C 0MCI' IS AN OUTPUT INOICATING FIRST COL (IF MATCHC
INTEGER IJL NCfMCIINTEGER*2 LIN PSTRINGLOGICAL MATCHDIMENSION LINE(SO,STRING(80)
MATCH .FALSE.qo96 IF (.NOT. ((.NUTo,4ATCH),ANDo(J.LE.8i-NCII I GO T3 90979098 IF (.NUT. ((STRING(LI.'4E.LINE(JiJ.ANO.(J.LE.81-NCII) GO Tm !)q
.9 Ja"J 4.3.
Gd TO 9098909Q CCNIINUE
IF (.NUTo(J.LE.81-NCI I GO TO 9100
L uJ9102 IF (.NUT. ((STRING(4I ).EQ.LINE(L+III .AN0. ((L LI.LT.dOJ.AN
*O.(.I .LE.NCI) ) GO TO 9103L L + II "I + LGO TO 9102
9103 CCNTINUEIF (.NOT.1i .EQ. NCI I GO TO 9104
4ATCH = .TRUE.GU r3 9105
9104 CONTINUE
91it)5 COI6TINOJF900 CONT INUF
41
FILE: SLEiJ2 FORTRAN TI "!AVAL r)lS[;AIliJATF S-)HCA.L
GO TO 90969097 CONTINIJE
M4CI 2 JRETURNENU
42
Appendix BSLED PASCAL Implementation
(by R. Burnham, R. Coulter, and S. Smart)CONCEPTS
The purpose of this programming project was to implement a sim-ple text editor to run under standard PASCAL as defined in Wirth [1972).The specifications for the program are fairly extensive and seek todefine the program in specific enough terms to ensure portability. Indesigning and implementing this program, the following two goals wereutilized:
a. PORTABILITY. The finished program should be capable of runningunder any implementation of standard PASCAL.
b. STANDARDIZATION. The finished program should abide by thedetailed specifications provided for the user interaction with any
implementation dependent features fully documented to facilitate use byboth inexperienced and experienced users.
SYSTEM DESIGN
The overall design for the text editor was heavily influenced bythe strict requirements of the specification document. This specifica-tion delineated the commands that were to be implemented and their for-mat. The primary design task involved creating an efficient systemwhich included the required commands in an implementation independentprogram.
FILE MANAGEMENT. The primary purpose of any text editor is tocreate and modify text (character) files in an interactive manner. Thisproblem can be separated into several functional areas. The first ofthese is file manipulation and management. In as much as PASCAL wasdesigned primarily as a pedagological aid, the language lacks extensiveinput/output operations. This in turn allows the various implementa-tions to define these operations. Since this would necessarily resultin operations which were not portable, it was decided to design the pro-gram to meet the requirement that the user be able to access externaltext files from within the program and that the program not fail if theuser attempted to access a non existant file.
The Berkeley Pascal implementation for the UNIX operating system(which was used for this effort) defines three types of files, in addi-tion to the standard input and output files. The first of these con-cerns explicit naming. In this case, the file name is placed in theprogram heading and acts as a passing "parameter" from the UNIX operat-ing system into the program. The file so named must exist as a UNIX
43
. . . .. .. ..-
fil e.
The second type is an implicitly defined file. These files aredeclared in variable declaration sections of program blocks and havescope in the same manner as variables. When a block is entered, thefile is created with the UNIX filename tmp.x where x is an integerrepresenting the chronological order in which the file is used. Whenthe block is exited, the file is destroyed.
The third type of file uses a dummy file name convention. Thefile name is declared in the variable declaration section but can beequivalenced to an existing file by the system functions reset andrewrite. These functions create a UNIX path between the dummy file nameand the actual UNIX name, which may be supplied during execution. Inthe case of rewrite, if no UNIX file exists, it is created.
The dummy file name seemed ideally suited to the programrequirement that the user be able to create and access files at will.However, it is necessary to know whether the file which is to be openedhas been previously created. Since it is impossible for the program toaccess the UNIX user's directory to determine if files exist, it wasdecided to create a SLED directory containing the file names and sizesof all files created in the SLED environment. In the event that theuser desired to edit a file which existed in his UNIX directory but notin the SLED directory, the SLED directory could be edited to includethis filename. To implement this feature, it was decided to explicitlyname this directory <directory> as a UNIX file. Any additional filesneeded as temporary storage locations to be utilized while a file wasbeing edited could then be implemented as implicitly named files, sincetheir existance is not important to the user (unless the amount of filespace allocated to the user by the operating system is limited).
TEXT MANIPULATION. As a text editor, SLED has to carry out twobasic functions. The editor must insert and delete lines of text in thefile, and must search lines for pattern matching and replacement.These functions are related and are the dominant factor in the choice ofan effective data structure.
PASCAL has several data structure constructors in the languagewhich can be used to fulfil these tasks. These include the lineararray, record, and pointer. The salient features of these constructorsin regards to the tasks involved will now be discussed.
The PASCAL array is similar to arrays in other languages with
- 4
the exception that the elements of the array may be complex data typessuch as records. Since the array must be statically defined, thestorage can be highly efficient. Lines of text can be stored as charac-ter arrays. This has the advantage that locating a given line or char-acter can be accomplished by simply subscripting a variable. In addi-tion, overhead is at a minimum since no pointers, links or other devicesare required. The array suffers from the disadvantage that insertionsand deletions are expensive as they require copying on the average halfof the array. Furthermore, since the array must be defined staticly, itis likely that much of the array will be empty at any one time.
The record data structure is similar to the array except thatthe elements of the record need not be of the same data type. Byitself, the record offers no advantages as compared to the array. How-ever, the record fields can be used to act as pointers or links to otherrecords thus allowing the creation of lists or trees. Trees offer theadvantage that sorting, inserting, and deleting can be carried out quiteefficiently. In addition, searching is easier and more efficient thanwith linked lists (although not as efficiently as an array). The majordisadvantage of the tree is the large amount of overhead required sinceeach interior node must contain a link to each descendant. The linkedlist can be considered as a compromise of the tree structure. Inser-tions and deletions are still efficient, but searching requires follow-ing a string of pointers through the list. Since only one pointer isrequired for each node, the amount of overhead is approximately halvedcompared to the tree.
The pointer type represents a method of dynamic allocation ofrecords to a linked list or tree structure. This offers the advantagethat space need not be allocated until actually required. Unfor-tunately, the methods for allocating and de..allocating memory space viapointers is poorly defined in the language, resulting in implementationdependent designs. In particular, standard PASCAL allows pointers torecords to be destroyed resulting in the creation of garbage. No gar-bage collection is carried out by the language to recover this memory.Therefore, a common technique is to place unused records into a "free"list. This, however, defeats the idea of dynamic allocation.
Based on these considerations, it was decided that lines withinthe text file would be treated as a linked list. This would facilitatethe line append and line replace operations. The overhead for thisstructure would then be one pointer per line, which was not consideredexcessive. Rather than depend on the pointer type to create and managelist elements, it was decided that the list would consist of an array ofline records, with each record consisting of a pointer to the next lineand the contents of the line.
In representing the characters of a given line, it was necessary todecide between using another linked ,ist for elements of a line or acharacter array. Again, the linked list would make char;:ter insertions
45
and deletions efficient. Since this would require a pointer for eachcharacter, about half of the memory space allocated would be overhead.A possible compromise would be to have each list node consist of severalcharacters. This would create difficulties in insertion and deletionand would require a complicated algorithm to implement. It was decidedto represent the line as a character array. This had the benefit ofmaking the pattern matching algorithm easier to implement as well asreducing overhead.
PARAMETERIZATION. To allow for adaptations of the program toother systems, the parameters for the data structure are defined in aconstant declaration block in the main program. This allows implementa-tions to scale the size of the data structure to the amount of memoryavailable. To further enhance portability, it was decided to localizethe input/output procedures in separate routines which could be replacedwhen implementing the system on other machines.
IMPLEMENTATION
The linked line list was implemented as an array of line recordsnamed <buff>. Each line record consists of an integer pointer to thearray element (record) of the next line and a 120 character packedarray. This size allows the creation of a line which will cover thelinesize of most standard output devices. In addition, a separaterecord, (head>, serves as a pointer into the line list and contains thenumber of the first line presently in the buffer.
GENERAL STRUCTURE OF SLED. The editor basically has fivecategories of text processing procedures. The first of these are thecontrol commands. There are three types of control commands: a changeof logical message terminator so that the user may select the symbol orcharacter he desires to indicate an end of a line or command, a commandto exit the editor mode which will write the text file to the user'sfile as well as terminate the program, and a command to open a file forthe user, either a new file or an existing file from his directory andclose any previously opened file. As discussed in the section ondesign, this was implemented as a separate SLED directory. The contentsof the directory consist of the UNIX file name along the total number oftext lines in the file. In addition to this, a scratch file is main-tained to allow updating of the directory contents.
To implement the logical terminator, it was decided to limit theterminators to printable characters. This allowed the terminator toserve as an end of line signal In the text buffer, eliminating the needfor creating a separate list of line lengths or employing some otherline length algorithm.
The second group of comands consists of those commands
46
concerned with output of the text file to the CRT scree. These commandsare divided into those which display a specific portion of text andthose which display large blocks of text. These commands, called outputcommands, consist of routines to display the current line, a specificline or a designated number of lines. The user optionally selects afrom-line/to-line pair of numbers for display and defaults to thecurrent line (defined as the last line displayed or last line operatedupon). Another output command screens a large block of text for theuser by using a from-line input. These display commands allow the userto edit large portions of his text. Two other commands, which do notprocess or handle text, and are considered output commands are a pro-cedure to display a command menu to assist the user with SLED proceduresand a display of the version listing for a more sophisticated user.
The third type of commands are those which handle insertion oftext into the file. The line insertion commands cause the editor toenter the insert mode (all other procedures are in the edit mode).These commands allow insertion of new lines into the text as well asreplacing a specific line or a group of lines in the text. In this way,the user can create or destroy portions of his text file by linking thenew lines into the buffer list.
A fourth command searches the text for a particular character orstring of characters and displays them to the user. Closely related tothis is the command to replace these characters and strings in the bodyof the text, either in a specific line, a group of lines or throughoutthe entire text. These two types of commands along with the line inser-tion commands form the basis of the text processing procedures, whilethe output and control commands form the basis of the text handling pro-cedures. To implement the pattern matching routine the Knuth, Morris,Pratt algorithm (as discussed in Knuth and elsewhere) was utilized.This algorithm uses the concept of a finite automation to determine howfar to advance the pattern along the target line in the event of amismatch between the pattern and its target. This is done by creating atable of edges which represent failure in the automaton. As an example,if the pattern consists of three identical letters and the first twomatch but the third one does not, instead of advancing the pattern byone position relative to the target the pattern can be moved threeplaces since the first character cannot possibly match the third charac-ter of the target. The next table determines how far to advance dthepattern if matching fails with the ith character of the pattern. Inthis way, no back-tracking in the target is required and the algorithmis O(n). The diagram attached as Figure B1.1 shows the general scope ofSLED as defined in the specification document. It basically shows theeditor commands required by the system grouped into the five primarycommand areas; output, control, line insertion, string serch and stringreplacement. The diagram also shows the different editor command modes.
SPECIFIC STRUCTURE OF SLED. Based on the general structure ofSLED as proposed by the problem specification and as diagramed above,
47
the programming team made a detailed study of the basic routines needed,how these routines would interact and the data structures and file han-dling procedures that would be needed. The Figure B1.2 is a schematicof the implementation of SLED as described in this documentation. Inimplementing the SLED program, a top-down methodology was utilized indefining the program processes needed to meet the requirements statedabove.
There are four general sections or levels to the program. Thefirst level acts as a traffic controller for the entire program. Itreads each of the user input commands and branches to the appropriatesubroutine. The main program dunctions as this first level and screensthe commands, eliminating the incorrect ones and processing the properlyentered ones. It is the framework in which SLED performs its functions.
At this same level, the change terminator is located primarilybecause it does not handle the user data except to place the new termi-nator symbol in the text file (see procedure Changeterm documentation).It is properly classified as a special procedure in program controlrather than text processing or text handling.
The second level of the program contains the bulk of the textprocessing procedures and consequently, the bulk of the coding. Onesubgroup contains the pro-edures which display the lines of text fromthe user's file. In many ways, it is similar to the output section out-lined in the original evaluation. In addition to the screen line anddisplay line procedures, we have included the string search procedure inthis subgroup because it functions in a similar manner in that it isinvolved in the display of strings within the lines of text. This sub-group interfaces with a major subgroup of the third level, namely thecommands which read the user's line number designations, translate them,and fetch the lines from the text file.
The second major subgroup of this level consists of the commandswhich handle the majority of the text insertions, deletions and stringprocessing. These include appending lines, replacing lines and replac-ing or changing strings. These commands were grouped together due totheir similarity of function and commonality of coding. They each havemajor subprocedures at this level and interface with the primary texthandling procedures at the fourth level.
Also found at the second level are two other groups of pro-cedures which are of less importance than the text processing proceduresbut are useful and necessary segments of the SLED program. The first ofthese are the control commands which open and close the file. They areobviously required file handling procedures and perform the functionsnormally opected of a text editor. They interface with key implementa-tion dependent procedures at the third level.
The last major subgroup of the second level is the required
48
command menu and version document. The call to these procedures israther simple and uncomplicated. Rather than palce the documents in thePASCAL program, we decided to employ the existing UNIX directory to holdthem. These files are explicitly named in the program as <menu> and<version>. The file contains the current command menu as well as theversion and any changes to either of these to facilitate assisting theuser can be made quickly and efficiently.
The third level of programming of SLED contains two subgroups,each of which are subroutines for major procedures in level two. Thefirst subgroup are theroutines which transform the user line numberrequests into from-line/to-line pairs and fetch the appropriate linesfrom the user's text. They are text handling commands and are part ofthe output section in the original specification.
The second subgroup interacts with the open and close file rou-tines and are key text handling procedures. They are dependent upon theimplementaion of PASCAL in use on the computer system. The proceduresutilize a directory file which, like the menu and version, is located inthe UNIX directory.
The fourth level of SLED contains the key text hadling commandsto move data in and out of the buffer when required. All of the majorprocedures of SLED call the read buffer and write buffer routines tomove through the user's file. These procedures are also implementationdependent.
A minor orocedure of the program is also found at this levelwhich causes the command menu to be printed when the user makes two con-secutive errors, a requirement of the SLED specification.
TESTING AND EVALUATION
The constraints of time prohibited an exhaustive and thoroughevaluation of SLED. There has, however, been extensive and continuoustesting of the modules of SLED in the initial programing phases and asthe program took its finished form. While not exhaustive the testingand evaluation performed by the programming team has resulted in a fullyoperational and effective editor.
Once the major operating bugs were identified and removed fromthe program, the task of specific debugging of each comman and itsinteraction with the other commands of SLED was undertaken, includingthe testing of pathelogical errors where purposely erroneous andimproper commands were input with the express purpose of causing thesystem to perform incorrectly or fail.
While we are satisfied that the program will function as required,
4i
there is further room for testing of the system. The limited timeavailable precluded the testing of large files and extensive directoriesand the actual production of useable and functional files. Besides thetesting of large files, a period of time should be spent by disin-terested parties (actual users) in using SLED to produce files and test-ing the system. From this evaluation, any remaining system bugs shouldbe easily identified and corrected.
5o
SLED -PASCAL
51
I
SLED
*****AAA*hA** A *A***AAAA***AAAA*IaAAAAA**a*A.**AAIaaa*&AIAA*
Proqrammed by: Robert M. Burnham
Ronald J. Coulter
Scott W. Smart
Naval Postqraduate School# Monterey, California
Specification: 20 February 1980
U'
Written: 12 March 1980
Compiled: 14 March 1980
Source Computer: POP 11-50
Object Comouter: POP 11-50
Lanquaqe: PASCAL
Teolementation: UC Berkeley PASCAL
File Location: IINIX PRh /work/csS0U/smart/sled.o
Editor File Namp: sld.p
Documentation File Name: sled.doc
ProQram Access: tyoe " SLED "
Project Soecification: Issued Separately
Abstract: SLED is a very Simple general purpose text
editor implemented in PASCAL and designed
to be relatively transportable to other
PASCAL systems. It performs a minimum of
the usual text editing and display features
found in a typical text editor.
L'
(ecclciacciecaiccececc BEGIN SLLD iiaccei,*cceecc*iciciicii**liieiii ic
* DOCUMENTATION FOR THE OPERATION OF ** THL BODY OF THE MAIN PROGRAM CAN h* BE FOUND AT LINE 2376 *
program sled(inout menuoversionoutput directory);
label 10100;
const
bufsize = 50;linesie : 120;nill = -I;namesi~e = 6;errmsg ' INVALID COMMAND*;blank
comma S e ICerror ' cc DATA ENTRY ERRORE.cPLEASE REENTER DATA cc '
type
line = recordnextline : -I..bufsize;
linestrinQ : Packed arrayll..linesize| of char;end;
buffer z array l..bufsizel of line;oatstrina z oacked arreyvl..linesizel of char;header z record
firstline: inteqer;ptr : -I.. hufstre;end;
var
letter, c. Ch. Ct : char ;errcnt, toxtsizeo curline t Integer Imenu, version, mfile, tempfileo directory* tempd 2 text I
buff : taffer;free ; -l..wufsie;head : header;
J[
- -
filtopen :boolean;fAaume I vockedt array fI..namesfiel of char;
cwederror benolean;
41
I
PHOCEI1f4 WRI If uhF
PURPOSE: this procedure writes the contents of the linebuffer to the currently open file. mfile isa dummy file name. Ourina execution, thisfile name is replaced by a *path" to theUNIA file name snecified uurinq a rewriteor reset oneration. File temptile is a temporaryfile used durinq read and write operations torestore the user's UNIX file. the temp fileexists durinq execution as UNIX file top.2. Ifexecution terminates normally, this file is removedfrom the system.
The procedure reads from the user's file (utile)to the temp file until the point where the bufferis to be inserted is reached. At this point, thecontents of the butter are written to the tempfile. After the buffer lines have been transfered#the remainino lines of the user file are read andwritten out to the temp file. The teamp file nowcontains the complete file. lhe entire temp fileis then read and written to the user's file.
u'0 VARIABLES: temofile: scratch file
ftile: dummy name for user's UNIX filefname: actual IXN| file namepoint: pointer to the buffer
procedure writehuf;
type Pointer = inteoer;
var I ! intecer;ch : char;point : oo.fnter;
benin
I
read all lines preceedino the first line of the buffer fromthe user's file to the scratch file)
I I.
rewrlte(tempfi le)i
re,.efltl1.,fname);
fto i I to (head.firStlinf -I) doheqinwhile not eoln(mfile) do
beginread(mfilevch);write(temofile#ch);enrl;
end;
set the list pointer to the first element of the buffer
and read all lines in the list from the buffer to the scratch fileI
point :2 head.ote;while ooint C< hill do
henini :: I;while (i c linesize) end (hufflpontl.lineatrino(i)
43 ct) doheninwrite~tempfiterbuff~pointilinestrtnqit])S
1 : + Iend;
writeln(tempfile);#. Point bufftPointJ.nextline;
end;
(reset the buffer status record)
head.ptr := nill;head.firstine := 0;free 1;for i I to hufsfze -1 do
ouffhii.nextline := i + 1;
buffibufsitel.nextline :: nill;
read Pest the lines of the user's file which were written to the
buffer previously
for 1 :2 I to 40 dobeuli nwhile not cof(afile) do
readlnf i le);end;
i-U---
tread all romainina lines from the user's file to the Scratch file)
while not Poofffile) dSobecinwhile not eoln~ofive) do
beginread(of ile,ch);writt(temofi lech)Iend;
it not eof~mfile)then beoinreadinfmfi le);wri teln(temnfi I.)Ondl
end;
1write the entire scratch file into the user's file)
rewrite(mf I e~fnaee);reset (tewnof ile)lwhile not eof(teofile) do
becinwhile not eoln(tempfile) do
beginCO reed(tempf ile,ch)B
write(af iletch);end;
Of not eof(tempfIle)then beginreadln(temof 1 1.1writeln(efil*)i
end;I
end I writebuf
K4
PROCEDURE IEADhUf
PURPOSE: This procedure reads a block of 40 lines from a userfile into the buffer. Mfile is a dummy file namewhich is replaced durinq execution by a "path" toa UNIX file. Strtline is the first line of thefile to be placel in the buffer. This line andthe next 3q (if they exist) are read from the user'sfile and linked into the list.
VARIABLES: mfile: duimy filename for user's text filefname: actuall UNIX file namestrtline: first line to be Placed in buffertextsize: total number of lines in user's file
procedure readbuf(strtlitne lnteqer);
var ch t char;itk : integer;numline : inteqer;
begin%.0
(determine number of lines to be placed in buffer)
numline := 4O;if (textsire +1 - strtline) < numline
then numline := textsize +1 - strtline;reset(mfilefname);for i :z I to (strtline - 1) do
readln(oflle);
( Insert lines into buffer I
for I I i to nueline dobeqink :a
9while not eoln(mfile) dobeinrpad(efilech);buffliJ.linestrinqlkJ 2: ch;k := k + I;end;
4-4
-
if J ;. I then huff il-Il .next i ne f2reerflnoffIle'J
bufflnuNilinel.nextllfl@ :z niltifree :2 numlinte t 1;for k :=numline * I to bufsize -Ido
bufftki.lexttifl := k+llhuff(butsirel.neutlifle :2 nill;
lupdate buffer status record)
head.otP :9 1;head.firstline :2 strtline;
and I reedbuf
at
CD
Ns-
PROCEDUkE FETCHLINE
PURPOSE: This Procedure takes the number values produced by------- the Lineoet orocedure and causes the appropriate number
of lines to he printed on the CRT screen. It is called bythse Procedures whjch need to enter the users buffer
and extract Dart of the text. It, in turn, calls the proceduresReadbuf and Writebuf which are part of text-bufferstorage system. If the users request for text exceedsthe actual size of the text# this procedure will printall the text that is available.
VARIABLES: The follwing variables are used in Fetchline:---------- x, p: countino numbers for iterative routines
nointer: number pointer to the next linefline: from-line valuetline: to-line value
Global variables include:textsize: the number of lines in the users textcurline: current line valuehead.firstline: first line of the users text'head.ptr: pointer to the first linebufflpointer].nextline: number value of the next
line in the bufferbufflpointerl.linestrinqlpl: character value of the
line In the buffer
Procedure fetchline C fline, tline : inteqer ) ;
var
x.y. o. pointer 3 integer I
beoin
if fline ' textsiiethen
fline %X textsite I
if tine • textsie
- * I--
t hen
t~ine ::textsi*if fline 4 head.first line
t hen
beQin
writebufreadbuf Ifln. )
end;pointer tz hthad.otr
Isearches for the frog-line valuein the users text. If not In thebuffer# then the rest of the fileis searched.
for x head.firstllfl* to ( fline - I ) do
beamn
pointer :z bufflpointerionltlin@ Iif pointer 2 Rill
then
beqln
writabufreadbuf Cx 8pointer :2 head.ptr
end
end;
4 print out each line, Charet~r byCharactere from the buffer to theCRT for the from-Iine/tolIflC values.It the buffer is exceeded# then thenewt block of text is read to the
for #lie totlfn dobuffer. )
for :: une o tue ~begin
write C le' y: Sol ')
while (tbufflpointerl.linCtting
1. <*1>
end (o 4 linesze) dobeqin
write( buffIPointerJ.lIneStrfnq(oJ )
. == p * I
end 1writeln ;
if x tline then heqinpointer buff pointerl.nextlino Iif pointer =nil)
then
beginwritebuf Ireodbuf ( y ) ;pointer :2 head.ptP
end 3end;
end I
I reset the Value of the current line
end: ffetchline)
0l
" i
-M~ ..... MOP ,1 7,17 7
Ii
PROCFDtIIF LINEGETeaiislaai**i**ihhili.l*iliihaalaiaialaiibis**i*i.aslaaiiaai*ii**il
PURPOSE: This Procedure. called by some of the main procedures of------- SLFO, reads the line number of the user input instructionS,
Constructs a " from-line/to-line " pair of variables andchecks for errors in user input. The user can designate thecurrent line with a carriaqe return or a change terminatorcommand, insert a value for any other line desired orspecify lines from one number to another.
The values produced by this procedure are passed back tothe callino command. This procedure is called by Displaylineand Screenline.
VARIABLES: The followina local variables are used:--------.- line: the from-line value
toline: the to-line valuescreencheek: boolean check value to detect an error
and signal the callinq procedure to take specificaction
num: value of the first number read ( to-line value )tnum: value of the second number read'( from-line Itemp: tempory variable for numberscheck: boolean checker for an end-of-line character
Global variable reference:curline: current linect: chanqe terminator charactererrcnt: the current user error count for the
Erroroutine procedure
procedure lineqet I var lineetoltne : inteqee; var screencheck : boolean i V"
ver
num. tnum, temp.: integer Icheck : boolean
beoan
-- - - ... . ,_,__i______.. .....
w ii
9 \ [- -- .-- -. -. .e -.- I
I Heads in the first number andconverts it to the from-line value
check :f $alsescreencheck := trueteiD :0 ;line :: curline ;toline := line
beginif not eoln(inaut) then begin
reed (c) ;if c in ('0'**'9'1
then
begin
reoeatif eoln (input)
then
check : true ;temp := 10 * temo + ord (c) - ord ('0') ;num := temp ;
if not eoin(inout) thenread (c)until not c € in P'O'..'9'1) or C check ) or c C 2 ct
end;
if C check ) or C = ct
thenbegin
line := numtoline :: line ;
end ;temo := 0 5
end;
I Reads in the second hume"rand converts it to the 0-linedigit )
if not (check) an'1 I c commathen
begim
it c Commathen
i •
thenread (c) Iuntil (eoln(input) ) or C c 3 ¢t )
end Iend;if line > toline
thenbegin
writeln(error) Iwriteln(* Data is entered" frooline, toline" ') ;line := curline ;errcnt :2 errcnt t | Itoline := line ;
end 1errcnt := 0 ;
if line - 0then
line curline ;
end I C lineget I
P) _
(
PRnCrUURE DISPLAYLINE
PURPOSE: rhis orocedure dleys ies of test trom the users------- file. The user reQuests the current line# a specific
line or a group of lines with a starting value andan endinq value. The input command is < L value(tvalue) >.
The number commands are read by calling Lineget andthe actual lines are fetched and printed by Fetchline.This procedure is merely a vehicle for the interactionof these two procedures.
VARIABLES: The followinn variables are used:linefrom: from-line value
lineto: to-line valuecheck: error detectlnq variable
procedure displayline ;
var
Ilnefrom, lineto integer I
check : boolean0o
begin
lineqet ( linefrom, lineto, check ) ;if linefrom 0 then linefror := 1;
if textsize 4) 0 thenfetchllne ( linefromp lineto )else wrteln('O lines in file');
if eoln(innut) then heninreadin;write(C ' );eni;
end I 4 displavline I
{x*t*ax II A**S*** **** * **** ***5*&*At e ,x*A**eex*i*ih*
PNtOCEDUIRF SCREENLINk
PURPOSE: This procedure displays P0 lines of text to the user. it
Can be started at the current line or at any linedesiqnnted hy the user. If the request exceeds the textsize, then the screen will terminate with the lest lineline of the text. The input command for displayline isA S value 3. If Improper date values are input, the Checkerwill print only the current line with the error dleqnosticprinted by the Lineqet procedure.
The procedure calls thq procedures Lineget afldFetchline.
VARIABLES: Tit followina local variables are used:......... linefrom: from-line value
lineto: to-line valuechecker: boolean value Possed by Lineget which
causes only the current line to Print insteadof 20 lines. Done on error only
Global variable used:
curline: current line
i**ax***i~xi*i*llillixiabiii**ftx*th***Aii*i***iA**5***xAlxA*ii&sai*
ICh
procedure screenline 5
var
linefrom. lineto : Inteqer I
checker h hoolean
beoin
finervet I linefro%, lineto. checker I Iif I nefrom it
thenlinefrom !5 linefrom * I I
it linefrom <= linptothenlineto ;= linefrom 2 0C I
I Error routine for Invaliddot* in Lineget procedure I
if checker = falsethen
!-a
bem linefrom :2 curltne
ed lineto :zX lineffom
if textaize <', 0 thenfetchline (linefrom, lineto
*Is* writelnVO lines in file');it- eoln(inout) then beqin
readin;
end;
end 1 4screeoline
6*A *aaa a 4 t la A*&***t **** bA 4A* **A* A A***Aa*
PROCFDIIRE AIPPENDLINLA A, A, 0ik*4 I*I* ** 1**A AA*A,*hI*a ** A,*A,*0AA,4* *A *6* * ** rA0a*A,
PURPOSE: This Procedure inserts lines into the buffer.The Parameter strtline is the line which theinserted line(*) is to follow. If this lineis not currently in the buffer, the contentsof the buffer are written out and the bufferis relilled hegininq with the line strtllne.The oroceaured then continues to insert linesuntil the end of input symbol is reached.If the buffer is filled during this operationthe contents of the, buffer are written outand the last line inserted becomes the first(only) line in the buffer.
VARIAKLLS:Point: Pointer to the line in the buffer the
inserted lines are to followeoointt pointer to the line iiemediately following
the lines insertedbufline: cotinter to keep track of the line number
which Point is pointing to
procedurei aopendline (var strtfine :Inteaer);
type Pointer z-I..hufsfze;
var text : acked array illinesizel of chartpoint~enwoint : ointer;done :boolean;
bufline !integer;inoch: char;
begin
(test if inserted lines are to be Placed before the first lineof text. If so* Pointer is nill. If the file is emoty thofirst inserted line becomes the first line of text and thebuffer status is undated
if strtline Qthen beom
if heau.firstline ),Ithen beqin
wri tebuf I
readhuf (I);end;
if head.firstline = 0then begin head.otr nill;head.firstline := 1;end;
eoOint :2 head.Dtr;Point := nil);
end
(find the start line in the buffer)
else beainif head.firstline • strtline
then beginwritebuftreadbuf(strtline);Point :: head.otr
endelse begin
Point := head.otr;bufline : head.firstline;while huflfne < strtine do
beninPoint :z bufflpointJ.nextlfnel
(if start line not in file, get start line)
N Itf point a nil)then heqinwritebuf;
readbuf(strtline);Point :z head.ptr;hufline :z strtline;endelse beginlufline := bufline + 1;end;
end;end;
(after the start lied is found, set epoint tothe next line)
if buff(pointl.nextline 41 nill thenepolnt :: buffluointi.nextlineelse epoint :z nil);
end;done :2 false;
! p
- -...-.-..1--.
(real inserted text lines until the line contains
the end of input symbol (.). )
while not done dohenini := 1;
if not eolniinput) thenread(inoch)else inpch :2 *
text II) := inpchl
if inoch 2 (check for end of Inout)then beqin
if not eoln(input)then beqinread(inach);
i = I,1text (it l= noch;end;
lend of input, link epoint line tolast Inserted line)
if ( 1) or (inpch = ct)then beqin
LO if ooint <2 nillthen beqin
bufflooint).nextline := epoint$end;
done t= true;end;
endl
(write text line into buffer)
if not donethen heqintextsie :: textsiRe # I;-
whilt not eoln(inout) and (inOch 42 ct)*nd(i 4 lineslie) do
heoin
I :X I Iread(inpch);tentll :: inpchs*Rd;
if coin (thout)then bean
J¢
readingwritoII1text Ii f 11 :2 Ctlend;
fif no free lines available, write outcontents of buffer)
it free a nil)then beginif point <30 nill then
bufftoointl.nextllne := @point;writehuf;rtedbuf (atat line);point :2buff Ihead.ptrJ.nextlinei*Pomnt := bufflpointi.nexthineiend;
if point c nillthen buft(point).nexthine := freeelse head.ptr := free;
point I= free;strtline %= strtline * 1;free :=buffifree).nexthine;buffipointl.linestring :2text;(update c.,wrent line)curline :~curline + 1;
-4 end;4Ph end;
end s opendline
PROCEDURE RFPLACEL IE
PURPOSF: This procedure serves two Purposes. first it deletesall lines between the parameters strtline andendline (inclusive). Next procedure callsprocedure aopendline allowinq the user to addany lines in place of the deleted ones.If the lines to be deleted are not currently inthe buffers the buffer is written out and thefirst line to he deleted becomes the first line ofthe buffer.
VARIABLES:
Point: Points to the first line to be deletedepoint: points to the line after the lest line to
be deletedbufline: the line to which Point is pointing
Procedure replaceline(var strtline, endline : integer);
4" type Pointer z ol..bufsize;
var Pointwenoint : Pointer;bufline : integer;temp : inteqer;
begin(find startline in buffer. If not in buffer write contents of
buffer to output file end input 40 lines beginning with startline.)
if head.firstline • strtline
then beginwritehuf;readbuf(strtline);point := head.ptr;end
else beoanpoint :: head.otr;
bufline head.firstline:
while bufline ( strtline -I do
l i5
HIed-
beginpoint :h buff pointl.neotline1if hufline 4 textsize then
if point a nill thenbeoinwritebuffreaubuf(strtline);Doint Is head.ptr;hufline := strtlineiendelse beginhufline := bufline + I;end;
end;'end$
(determine which lines are to be replace end link these lines to thefree list. If no new lines are to be added* reconnect the linesin the buffer without the deleted lines. (i.e. connect strtline - Ito endline). It new lines are to he added, replace the startlinewith the first new line and append any followinq lines to it, thenreconnect the following lines heginning with endline.I
ecolnt :a point; Ifind the endline)for bufline := strtline -1 to (endline -I) do
beginoileoint :a buffIepointl.nextline;
if bufline 4 textsize thenif epoint a nil|
then heoin
buffloointi.nextline := nill;writ euf;readbuf(bufltne);point := 0l;epoint := head.Ptr;end;
end;
(update the textsize and buffer status record)
teatsize :2 tewtslae - (endline - strtline ) -1iteme, := buff(pointl.nextline;bufflpointl.nestline := btfflepointl.nextline;bufflepointl.nextline := free;tree := te-r';surtline :: strtline -I;appendlinetstrtline)
end I I reolacelime I
4
PROCFDURE STRINGOISPiia**aiai* ahha*.A*A**itaaaaeiaaaiali*iaiiliai61aiiaialaaaiaiiia*
PURPOSE: This procedure searches the text between the parameters
strtline and endline for any lines containing anoccurence of the string <Pattern>. If the stringis found# the line containing it is displayed bycallinq procedure fetchline.the Procedure first Comoutes the next table toimplement the Knuth, Morris, Pratt strina searchalgnrithm. This table is then used in determininghow far to move the Pattern along the line of textin the event of a non-match.
VARIABLES:next : next tablePoint: Pointer to the textline currently beinq
evaluated.oatlenoth: the length of the Pattern
ii***A****&**Aii**iAii*A&*h**********i*iAiA A*A****ia*A**a********i*a)
Procedure strinQdisp(var strtlinerendline : integer; varpattern: natstrina; var natlenqth:integer);
type Pointer z -I..bufsize;
var
i, Jo bufline : integer I
next : array (1..linesize| of inteqer;point pointer;text : packed arrayfl..linesizel of char;
0 done : boolean;
begin
(comPute next table for strinq matchino Procedure )
next [I) := 0:
while I ' oatlength dobegindine :2fse;
j __ ___ ___ ____ ___ ___ ___ _ __ ___ ___ __
I,
itI 1 0 It..nit costtern If 42, oafternfil
then i := nest il)
until Ci(3 0r')enrxdone
if netternill pattern IlIth *n neztljl :3 nextlil*ls* newt Iji :2 iS
end$
4find strt line in the buffer I
if head.firstlin. 3, scrtlinethen begin
wri tebuf;readhuf(stptl ing);point := heed.ntr;
endelse begin
point :z head.otr;outline ;a head.firstlin*lwhile but line 4strt line do
beqinpoint :xbufflPoitl.n~xt)Ene
fit line is not in butter, write out buffer
a:nd ed in current line)
it oInt nillthen beoin
writebuf Ireadbuf(strtlinelpoint :X head.ptgIbutline := strtlin*D
endelse beamn
hutlin* :2 butline f 1;end;I
end;Iend;Iwhile but line (3 Cr101 ine do
text :2 buf Ipointl~linestringlI zIsI ~It
(beqin Pattern matching)
while (i <z oatlenath) *nd(j < linesize)and (text ji <) Ct) do
beQinif oatterntii] text MII
then begini := i t l
: j * I; ikeep matching)
endImatch not foundadvance patternas determined bynext tablel
else begin
if nextl|l 31 0then i :2 next~i]else begin
1 ::) 1;Iendi
end;
and;end;
opattern matches)
if 13 patlenoth then fetchline(buflinepbufline);
point :2 buff|nointl.nextline;%4 :bufline buline + 1;40 if bufline < endline then
if point = nill
then beginwritebuf;reaohuf(hufline);
Point := head.otr;
end;
endeend 1 4 Strinodiso I
.11
PROCEDIIHE SIRINC#REPL
PURPOSE: This Procedure searches the user's text file betweenthe Parameters strtline and endline for any occurancesof the strino <Pattern>. If <Pattern) is found in aline, it is replaced by the strinq <strinq> and theresulting line is displayed. The procedure usesthe Knuth, Morris, Pratt algorithm to match thePattern in the line. The next table is firstcomputed. This table is then used in computinghow far to move the Pattern along the text linein event of a non-match.
VARIABLES: ratlenqth: length of the string <pattern)strienoth: lenath of the new string <string>text: a line buffer for the current linenext: next tablepoint: pointer to the curren.t line
Procedure strinareDl (var strtline, endline : integer;var Pattern# strinQ : patstrinq;var oatlenothe strlenqth : integer);
tyoe pointer 2 -l..bufsize;
varitjkreotemotemP2 : integer;oufline : integer;next : arrav|l..lineslzel of integer;
point : oointer;text : Oacked arravll..lineslizel of char;found : boolean;done : boolean;
beainI compute next table )
i 0;
nextill :z 0;while j < ovatlenath do
begindone :z false;repeat
ift 1 0 then
if 1 ;%rerf mi <> natternlil then i znextlii
Ist- .1nne trkje;until (i (~U) or a " ne;
j i * 1;
if patterniii patternilthen nextiitl next Ii)else next il i;
end;
I find start line in buffer
if heari-firstlifle ), strtlinethen beninwri tehuf Sreadbuf(strt line);Point :=head.ptr;endelse berlinpoint :=head.firstline;
00 while btuline ( strtline diobeginPoint :=buffinninti.nextline;it point z nill
then beoinwri tebuf;rearlbut(strtl ine);Point :=head.0tor:biufline :=strtline;endelse beginbufline :=bufline + t;end
end;end;I
I try to match pattern in text line
while buflifle <= endflne dobeginfound false;text 1=buff (voonti.linostrflq;
temo 1;teO,: 1;while (i <= ratlenoth) and (I linesize)
a?
and (text(J (I 3 ct) do
ipatteC'fl = te'ctM)then beami
i Z * 1;
I :z j *(keep Matching)
end n mthelse begin
nmet1
if newxtil1) 0
then i : next!3 )
else begin
end;end;
loattern match found-rePl*CC pattern with
st rinaW
if i ' Oatleflath
then vegifl
found 'ztrue; d
for k :=teMPZ -to ( (patleflath *1)d
hufftOOit))ifetrinqltemp : textl~c))
00 tem temp U
end;
m := 1
for k (I- atlenqth) to (( v at lenoth)+
(strieflgth -))do
boa inif temo < linesize then
temp tevep + 1;
end;
end; Icofltllue to search for pattern)
end;if found then bewif
if tema < linesize then
On t~ :=~ temp to (temp t . temp?)) elo
hea i nIt kIC llineSlZe then
buff ipointillnestringiki : text(iIJ
end;
(dl solay new line
fetchli nethufIline,bufli ne);end;
Point : buff~point).nentline;btjfline :2 hufline + 1;if bufline < endline
then if point =nillthen heqinW Ii tehufireadbuf (buf 1 me) Ianint :2head.ptr;end;
end;I
end; istrinareol)
c00
a**Aa~** ***aA****.aaa;~*A M ,.aaaaeeaaaPROCEDURE APPENOCOM
PURPOSE: This Procedure computes the start line forthe insert procedure (aoPendline). If theline number is defaulted, the current line isused. If the line numher exceeds the number oflines in the text, or is otherwise invalid, anapprooriate error messaqe is returned.
VARIABLES:
lineno : start line for text insertioninv true if invalid command
A*AAAA****AA*R**A*A**AAAI**AAAIAAA*AAAA**tA*AA***AAA*A)
Procedure anpendcom;
var cam: char;lineno : inteoer;inv boolean;
b egin
lineno .0t.ocm := *;
inv := false;if eoln(inout) or (eoo S ct) then if textsize > 0
then lineno := curline;while not eoln(input) and (com <> ct) do
heninread(com);if not (com in (0'..'9') + (ctl))
then bpqin (compute line number)if not eoln(inout) then repeat read(com) until eoln(input);writeln(errmsa);errcnt := errcnt t 1;inv := true;endelse if com <> ct then
lin eno (10 A lineno) #(ord(com) - ord(VO'));end;
if not inv thenif (textsize ( lineno)
then beoinwriteln(textsize:t,' lines in file');if not eoln(lnput) then repeat read(com) until eoln(input);end
else heoinif eoln(input)
then heqintreau~lnj
end;aooendl ine~i ineno);errcnt 0eno;
if eoln(inotit)then beoinread)n;write( El )5endS;
curline lineno;eo; 4opendcom)
****4*,**.AA*.*A A** A*ib* AA* ****6A*&*A******* t*
pURppnSF: ThiS oroceriutre cornnuter- the start line andenct line for the line delete procedure trenlaCeline).If the line nt'nor is defaulted, the ciorrent line
is clplete:1. If the ene line is not specified, thentArtlins? is delted. If an invalid line number is
innuteil, and errnr vassane is returned. If the%tart line or en line is oreater than the text siretn- last text line is deleted.
V API AIL LS :lintest start line for deletion
injnn tn-n line for deletion
l v truot if invalid line number is inputod
procedure r-nlcnv
varCo.": char;first : koolfan;
inest, lien entrkr -sr; rrun . h
inv :t'onlean;
beint
inv :=false;lines es = ;linend :z e;first tro|
while not eoln(inrul) and (cown 4> ct) dohen in
I f nnt lron in ( I*'. J *) I (#,I ctl)tntnn tn:zin
if nn t ,nln(input) then repent read(eom) until eoln(innut);
rrrcnt := orrcnt 4 1;
' * f >... ( Ct
th ian if first Icomtite start line)the" if crm=
thn 'irSt A lse
- -
else linest :z (loalinest) *(ord(com)ord('O')
pile if com 's,then heoinif not eolp(input) then repeat
read(cnst) until eoln(input);6riteln(errsl);errcflt :=errcnt t 1;mnv :=true;end 4compkite endt line1else linend :=(l0*lmnend) + (ord(com)
if nnt imv then heoinit linest =(1 then linest := curlinel* (start line becomes
current line)itfitrt z true then linend :=llnest;if (tewtsize < linost) or (textsie < linend)
or (llnenrt < linest)then beninwriteln(textsize:I,' lines in file');
4 else heninif en~n(lnrput) and (textsize > 0)
then heamnreadin;w~rite( b);end;
if textslzo 11 (I thenroplace1 ine Ilinostplimend)else writeln('U linps in file');
if eoln(inout)then heovinreall n
curline ln4t
PROCFD#RF DISPCUM
PURPOSE: This orocedure computes the start line, end lineand pattern for the string search procedure (strinqdiso)If the line number is defaulted, all lines in theuser'q file ape searched. If the pattern string isdefaulted, the nrncedure Prompts the user. If aninvalid line number is entered, an error message isreturned. The rrocPdure also computes the lengtho4 the pattern qtrinq.
VARIABLES:linest : start linelinend : end linestrinq : vattarn to be matchedstsire : lonvth of the Pattern4l At ti A a4 * * *l A A 0 I * A A* A ft *A l*It0It 4 0 kl**l
procedure oisOcne;0OC0
varcorn char;lineste linenc. stsire integer;
%trinr : pftatrino;first, sto : honlean;inv : honlpan;
lifest :z 0;irv:= f alIso;
Ilnendicom :=stsizeflret :2 trie;stri : false;whilp nt enin finout) and co <11 ct) do
heI in
it not stathen it cns = Ct
then t-ocainn : true;
'l -tr if not (co* in f 1O..Q1 * P,'l))then t,e .iif not oin(inrint) then repeat read(com)
. 1€
* I
JIn t op I.~n( i nnu t%Pi tel n(errmiso)or rent :=errent + Iimv :=t ria
6-1so i f f i rt fcomoute start linethen if conm z ',' then first :=false-ise linent (lO*linest) #(nrd(co'n)-ord('O'))
Oise if cot"then heninif not ooln(jnput) then repeat read(com)
until eoln(innut);writeln(errmso);errent := ercrt + 1;inv :=true;end icomputp end line)else linend := (10linendc) +
else if conm> e ctthen (coltnute PAttern strinn and strinq lenqthl beqmn
Stsie :=Stsize + 1;Gostrinnistsirel :=cornS
enend
if not inv then, heoinif stsizo=
then tit no strinq p-ompt user) beamnp r p ( q ttpno?) ;
i4 volnhjnvoit) then readlin;,,hile not enln(inrut) and (con -c)- ct) do
t-Pnin
if ').c <> Ctt'pn te-linqtqi~o := tqize. t 1;
stfrinnfstsizej : come
4cheCk fo~r lint- lefits Anti sot to current line. If line isnoater ttAfl to-)t %ip, aet to last line of text)
tt -1e. t fl-
OnIe. if first
then linend : linest;if linend > tewtsi?e then linend :ztextsize;if linm-st )t#-wt-;ire then linest := text-sirejif (linend ' linest)
thon to!.oinif me~t c',ln(inout) 'then repeat read(com)
until ooln(imout);wri tpln(orrmnQc)errcnt :=ercnt # J;endPiqe if tewtoiire > 0 then henln
st rinn.) sn( linest. linend.at ringat size)Ieercnt :=0;
else writelrd0O lines in file');end;
if eoinlinput) then honinPeadl n;
ened;curline lineno;
%0
end f disr'eom
Pikn(:El)i#RF S YR )Cm
Pt.ppOSF: This oroe'edure comolutes the qtae't line, end line#Pattpe'rn ntrin, ano' new %te'jnf toe be insertedfor' the SIei'eu rfL'lace Proc-edure (stringrePll.If the line number is defauilted, the current lineis usedl. If no Poni line is spocified, the startline i~t lispe. If the new strinq or Pattern stringQ
isi detaultej1e tth. user is nrnmnoe. If an invalidline nuniher is entered, an error mes-saoe is returned.
VARIObLES:linest :startlinplinpnr4 :endlineoldstrino pattern strina to be replaceonewstrin.1 : ne.w strinn to be inserted
oli~stsi~e nattern stringQ lengthnewstsire new strini length
proc elure S t ro-vcom.
var
line-;t. lineni,. nldstsire. newnsize ifltPQ~e
'First, nlrintn, no-vstn : boolemn;%e.4strin-i natstrifi;ir.v : o l in
ivnv :z f.35p;linesf
con, :z01 i~t I Ie 0;
fil,
lirtC1t tr'e.ni,0. t)d
if nnt olctqtnthen if com ct Icompute start, end line)
then heamnol~istn true;cnmOnI.else If nnt (co"m In (1'0..19'1 (9)
then heninif not eolnlinput) then repeat read(Con)
until enin(lnnut);wri teln(errffsa);errcnt :=errcnt Unv :=trute;
endelse if first fcornoute start line)
then if eoon ' then first := falseelse linest (lO'lineSti*(ord(com)-ord'O'))else if coon
then heainif not eoinfinput) then repeat readfcom)
until eoln(input)Iwri reln(errmso);errcnt :=errcnt *SInv :=true;a nd 1comoute end lineelse linend :=(lO*linend) +(ord(coml'-ord( 0'))
elso if not newstqi Iinnut Pattern Rtring)then If con <', ct
then heninnliIstsi~e : l-istsize + 1;ol 1stri,jrol.dstsi~el :=corn;enl.else bertinpwo true;
Cormenl'Ol'.i -oq. <> Ct linout new string)
rt.en hesjPi: newstsizp + I;n,'etrincnewstsirel :=corn;
eend;
rD~ ,t-, I I 1f f o o~i t orn 'rompt ousor I
if "l(in )then readi1n;
cornwhile not eolnhlnotit) and (Corn <> ct) do
hen inreaf( cnm);i f c^Wo <> ct
ol~isqi.ie := oldstsize *$1;0olistrinololidstq;ize) := corn;end.
if newstsite = 0 fif no new strino aromot user)then he'qjnif eoln(inDUt) then readln;wiIt e ('newstr in *'
comx :z ,while nnt ealn(innut) and (Corn <> ct) do
hp'1in
'0 if rlco ) C
C-) then hecjinn, wstsi~e := newstsize + 1;npwstrinca(newstsizel := com;end*
end;end(;
4check for line 'fef,)ults iindl set depf.ult values. If line numberis larner than text Sir.-, Ret line numher to the last lineof text.)
if lin-st = A then line-st := curline;it first
if liras~t ts~xtsiz then linest :2textsize;
it lineni toxtsi--e then linend :2tewtsize;
if ilirn1' <line-st)
if rv't vnnkinniitl then reneat rearihcom)tontil Poln( ino'ot l;wrtolnlerrmsi);
Percnt := errcnt t 1:
en i
:i i I tgpxt %i/ po 30( thon beqinst rinnir,,il i nest linendoo l'ist rino
newstrino,oltlstsizepnewstsize);eminent 0;end
else writelnCO lines in fl~
end:
curlime linemaSif eoln(inotot) then berlin
4ri tee'W);
end ; Istreocom
VIP0
AO-AL16 757 NAVAL POSTGRADUATE SCHOOL MONTEREY CA F/6 5/8BASELINE IMPLEMENTATIONS OF THE STANDARD LINE EnITOR (SLED IItfOCT 80 L A COX. R .j COUJLTER. C F TAYLOR
UNCLASSIFIED NPS52-80-012 NL
2 2ffffffffffff*bumINmuu
PROODURllF GE TF ILF
PURQPOSE: This orocedure inouts tho user's file name. The SLEDdirectory is then searched for that file nano. Ifthe file name Is founS, the file is opened and textuize,is 80-t to the numsber of lines in the file. It thefile nis- is nrst foundo a new file is created and thefile nvp* is ent-re-1 in the directory.' The file<Jirectory), is an exolicit UNIX file which contains thecurront SLEI) dire ctorv. The file <tempd) is a scratchfile 4hiCh i% created during execution as IINTX filetMndl. leir contants of the directory are read to thescratch file surina the directory search (less the fileto bp oopne-1, if found). This scratch ft* is thenre^,i tf' tne directory with the undateo number of textlinei foe th- urr-ntly openpo file in Procedure close.
VAR IAI3LLS:dirocIrv SO.V) directory file. The format for the file
is <text sire), (ile "ameli.tomrc.1 scraitch filetn4-e : usqr's IIhiI? file name to be onenedtoatsize n~.,qher of lines in the file
var ch nrflun1 t~nnleanJ
Index, it k, i:iter
ch :3 'tentslze :2 0;
Isnout th .1ser I il n- M
f7 I '0 x',,sl#.do
* "3
while not eoln(innut) and (ch ct) dobenin
rene~t rpad(eh) until (ch 42 ' ) or *oIr,(lnout)lit Cn = 2
then
&Is* htain
if 1 <= naemesize then fnamelil lz ch$enhl;
end;
(search for the user filqe #namei n the directory)
if fn*$* C",I then beginreset 4.11pectory);founI : false;
WhilA not eof (directory) and not found dobe-uinteltql~e :2 a;5
'Clif the file Iq focann, coeoute textsize)
rea'i(di recevoch) Iif en in 1041..1911 then
until Ch 2 '
while i c namesizo do
reiN.ifi rpctoryoch) Iif fmamolil CO ch
than beqIfti I= namesize f 21in-leg Saindex~ t Is
endS
it I 2nheesirp ti then found k% trueelse. if not *Of~jdriuectry) then.
roadin(di uectory)i*nlIfI na,"sire t I
*1 then I-qfuneritelnftpxtsl9* :1#0 lines in file lpfnemo)l
reset (directarv)f
...K '............7,A,
fi~i I tn inde. doheni n
l..,ite th~e contentq rf the diiectory. minus thefile just noenel ti tho scratch filet
ereoeatrenfi(d1i ectorvech)5wri te(:emodsch);
until Polntdiropctory)ireac21n(di iectosry) I
rea'4(dieectorypich) until eolntdirectory)grea4ln(di rectory);while not *nf(dieectory) do
while not voln(dierectory) do%0 beamn14 rexd(dIreeCtorv~ch)I
en,,;rtadi n(4i rectory) I
end#kt :2 11Iftewtire ', 0 then
fread the first 40 lines of text Into the buffer)
reaftuffk);*noelso t'cqInwrit.?n('.Cr*AtI " filef.e,)tewrttso 12 0
e.jl n#nt eo #(di rectory) 1o.
wit" n " ot "oln(directory) dobepoin
re %II f(tiI-~ lt or I
irr iIv Ieef lnaq)
A
7000
A aW N -4 . -, ---- -
fuod~t* tfl. hvffer statul reCorl1 and freP li400
free :z 1for I 31to to..t*t@ - db
butfII1.lExtlifloe :a *3hit#ffltittsi #ICnelwt) ifl :x nill;
fend;': vte
.lebedinwvt.In#-fnCOrr@ct file ne-I)i
Iend A qa2tfilo I
-I7
fp
.17
r
dr
PNdOCFW9I4E CLOSF
PUPPOSF: This Procedture close% a orevlotisly coened textfile, the contents of the scratch file temod~Are reil into the qLFl) directory <directory.%The text Size of the open file and the filenave are then entered1 as the last line of theli rectory.
VARIAO)L(S:firectnrv SLFlP file directoryteisor : scratch filefnqiep currently ooen file nametextsire nuambor of lines in currently ooen filehuint : charncter renresentation of lnt~a~r teutaize
Droce-lurt close;
Var ch ChartAlilt. It inteorniomther, 2 %rry I.'lof char;
beamn
for I 3I to % dboSnUvt)t(jl ta, " 5
writel.,I-closino file ,ftname,I )s
ftonvqpt imt-i-r toxtsiso to ASChI reveeqentationi
if tewltl?' a 0 then nusbori Ix3 1
l,,it la towtsigo Mod lotlj'ujt ts 1halt *rs~
Ch :2 ChrIii~ligsb~jerjjl 12 Chi
fimnsert *evst sil. lnw scratch fit.)i
for X 3 t' % Ia
It~ 217 1
if Auqhfreij l then
(insert file nao,- into scq*teb fulfor i :r t o flhmesip* do
VIP i to (trend" In no i )I
(write scrot Ch. fi to to $LCI) dlrectepyl
while not pofttopj dohejinwhile not eoln(teiand) do
CD resell nt *vd);o wrttv~ltdirectory)l
wijr I tehuf I
end £ ICl,..
4 pt t
-04
7 .rrk-Oq
PeROCMDIRE OPFN
VAQIAALES: .t~~ha~a**~t.********
Deocedure oneni
war cam, choir:Inv : hotaleon;
beqin
Icloe a arevtousiv eo-nel file)
if fileoDafl
fileo"Ift :2 false;
.4 rewrit(tpuodi)5com :2 1*1Inv : falsofwhile not onln(lnout) and (too 4)- ct) do
if cnm <i- rtthan tinif nnt enintinnut) them reneat re,d(coal uantil
Inv :2 tea
N- onIrumbo
47311
if not fmv
(if no file name# voromet u~er)
thpn bie~n,it eolp(itrut)
then henin.. 1 te(Ifjilenase?3 ) I
cPd'tflo
endelsob otfie;
if eolp(inn'ut)then tbpcin
andS 4open
A,'4 7 ,
NO4
PROCFDURF QUIT
.PUQPOSF: This Procedure closes the CUrrnntlV open file if oneexists by eatllina Procodiorp cinse.
VARIAOLES:Inv true if commandi is Invalid
Peocelup. quit;3
Vet Ch % char;Inv t hoolean;
begin
44 ch IsInv :2 false;while not toln(ineut) and (ch 41P ct) 'to
if not -ol.,finout) th~n repeat read(Ch) Until
wtitInerin)I~
*Vrrcnt IS ernt f 1Inv :1 truelOn~ 18
end;it not Inv an.-a filooen then boqim
co ns*$
*rec-* :2 fl;
ifoilist than et
A *-'W
*j
PftelCrOURF WRTTEMENU
PURPflSE: This procedure provides the RLFD user with a desCrip-tion of the various commands available in SLED, It canhe called by the user typing 0M" or is automaticallyrailed if two invalid commands in a row are sub-wittptd. the urocedure functions by utilizing afile "menu* which contains the SLE command summary.1he file is reset# a character is read, then writtenetc. until coin is reached. then skip down to thenext line of "menu" write the line just read and rep-eat the Process until eof is reached.
A cooy of the command menu is included In theProgram docuventat ion.
-P. Procedure writemenu;
begin
reset (menu);while not enf(menial do heoin
wailo not Poln(ments) do bt enr. a.(*enurch);4ritefch)
end;reauln(vents)writeln
end;if not cmderror then hon
if nnt aqlntinnut) thenre. t ",,,4 (ch) until (ch a ct) or eotn(inout)S
re iOn:
end;
en, 3 t .rst~-n'u a
" I M.14 -r-.0101
;~efta
orV
_'k
PRflLEQIIRF dRITEVEPS
PUPPI'SE: This procedure Provides the SLFI) user with a des-cription of the program version. In SLED it can becalled hv the user typfno a "V*. The Procedurefunctions~ hv utilifina a file 'Version" whichcontains5 the version documentation. the file isreset# a character is read then written etc. untilPoin is reachedI. then skip down to the next lineof *version", write the line just read1 and repeat theProcess until 4-of Is reached.
A cony of the version format is included, in thenrn.qram tdocu-pentat ion.
procedure writevers;
beqin
raset (varqjrnn);while not entfversion) d~o toeoJin
.ihfl- not Poln(versin dfo beinreail(v~rsionsch) 5write(cli)
end;lremiln(vornienl;
if net -nn(j'il then rep.;,troe4-ttrh) uintil (c"' = el or enln(inrnut);
it e-oin inrittl thon bacoinrenol n:
wrt *to
Nor'"
PHOCFDUIRE CHANGETERM
PURPOSe: This Procedure is used to chenge the value of theInaical terminator from its ontional value of S.This is done by inputinq the new value of the log-ical terminator from the console and assionino it tothe variable "ct". At the same timer the 50 linebuffer is scanned and the logical terminatorswithin oach line of the buffer are scannedana chanoeo to the new value.
VARIABLESV'riables i and i are used as counters in reoetitivestatempnts. Subi is used as a temoorary holder ofthe new loqical terminator.
i*t* AA*I A*A*AIA **AeAA AA A*AA A *I*~*5****h**A****akAI*A)
Ch
orocedure chanoeterm;
var i:inteoer;j :intaer;sug,j :Cha r;
begin
writelniwriteln(LNlFIJ 1Hi CHAPACFFH OFSWRFD*);writeln(*AR A Nf.m LUCIeAI. MSSAGF TERMINATOR');writeln('IMlSI 'Q i PPINIAMI.F CHAQACTEI4);
NOi tpl1*,F TCt )
rea'llniwrite( 'I');
re 1:sI- tt r i;
for i I to hufsize Aoteqinfor i I t- lintsie ,In
"ii.- ':= 11,1t * llirn,trFin iljl;
hufflil.linestrinsil Iotterend;
1 n,1
c 2lett ter
reaellmn
and; I chanoeter- I
PROC FD*N.I FRROUUT W
PURPOSE :This oroce'lure is Called whenever there are two consec-------- utive input mistakes made by the operator. The command
menu will be Prirnted1 on the CRT screen to inform theuser of the oroner orncoaures for data display andinotst. Thi- Prrorcount is reset to zero whenever thisProcelure is calleil I errent Is a globhal variable ).jhen a r'roper commnand is entered by the operator# theerrorgrount Is also set to zero. Ihis parameter can he changedto display the commani menu less frequently by a small chanaein tti^ -main tironram.
peocedfure errrotat Ine.
beginw r i t erentoerrcnt z0
en-fl errrnutine I
r.' Pkf
PURPOSE: The Wrain Prooram is utilized tn select the apPron-riate text aditio procedure utilizna the inoutsfrom tebe console. Tt also Performs the initiale'titinq of those inputs. ]he pronra. will read thefirst I or P letters input to the console (dependingon commpand innut) and determine which Procedure musttbp entered to evecute tho desired command. This isacnnIC'lishetd with a sequen~tial scan of a series of
if ntateffenta ine which the first letter ano ifnecpssrv th~e second letter of the command inout toth~e cons~ole is checked aqaurest the authorized initialletter or letters of SL,"D commands. If thejolti-ti edlitinq is nuccessfully completed in one ofthe if statements, the Procedure associated wl'ththat if statement is entered. The remainder of thecommani in edited in the calledi Procedure. If the
staetial scan cptels through the last If0 statement ano nn match is found with a valid command#.0 tose fillowinq is done:
1. Frror messacle Printed
2. Increment error counter
3. Check value of the error counter!it larne enough enter Procedure to write comomand
m4'. n U
ii. Check if more commands follow; if not, read a *in*
S. 'Octurn to staterent 10 in the main oronram
Andl renil the next Command.
I- aacn tf sta~tement associatedl with commands whichwould "AV" follow-on parameters after the initial
leter~),the stattes of the error count is cheeked toiotrr-ine the siscms of editina In the procedure,1r-s if no eqsatrv tti,# error oressALwe or qpntj is upri14tod.,. 41r o vHrr, ratiorn 4 mew a) *roc,.due, the nrn-s,'" nos in
t t ~ t I l r0w ..Jj t ht nex t eCw-pnI (bxier't
- s-' fi ror,*tt wnis rdltsos t he (ro.ntae
..... 44r , Wt-
044
*Via
VAPIAbLLS The foll',wjnev Qlnb&I woriahlea are used in the mainProaraw
errcnt :count of user generated input errorscmerror : hoolean used to check for Proper input
commandsfileopen : hoolean check to ensure that a file is
opened before allowing the ProceoureSto operate
latter character input of the user
begin
ct : ,fileoroen := false;
wri tel.'.un telm:
-. ~writelni ; tN)
writein0P~Ii IF( TYPF *04" FOR CUMA4V) VIENU')I
errcnt :: fl3cwdorror :=true.;
10: reauICIttgertz
if (letter z 1 *I) ten becin if f'ileopeft then displavilne,else hortin writiin(O-no file open-');
radln
if &rrcnt I thlen orreoutine;hlot* 10
end;it Fiettmr x 15) then b'egin if fileorion then scritenline
ocoqe Iteqfir &irite~ntl'no 'ffle COMO-');
if errrnt 1, 1 then' erroutln*l
Ono; I.
it lette -,0- U ne bo~in coiderror :r- false;
I io!1 .,
wri1teumenu3cuderun trueSef9tto.
Gate toend$
if letter a IV' then benin writieveraleprcnt is 9S
endfif letter x '0' then tneQin ooeni
vrrcnt :z 0;got.*t
endlit letter I Q' thn npqin ouiti fltot 10;
end;it letter A* then
it (letter a ILI) then begin if fileooen then [email protected] heoinwqite~n(lno file *peo-,);readingwriteOE2.0I
end$if Orrent 1 then *rreout lee;
end t.1
t vIse boainvrrcnt :2errCnt # 1;
5 hirteln(errmes);if erecnt )Ithen srrutin*
@I~ d S rtOl )
Goto 10end
ifl4, 0.t. tV' top) $
if (letterm 13) then becin If tileqoen then disocoe*lse beqinwriteln(I-o IIe open-*);
it errent i, I then Ceroul
end Ot f
*too boqlnerpent ;a eV9cnt t 11
wri topn(w,..ga) 3it eptct * I then recrutineat$* writelOW)i
.adI00t0 10
end011.95
it lottor I 'C' then"~nin
read lot tep) IIt (letter a OT11 then begin chanaetermi
errcnt :a 0;qato 10
end
errent 1: *rrcnt * 1;writeln(erpmsci);
if Prrcnt 1, 1 the" errroutineelse weite(10E1);
read In;gate 10
end
It lptter IR then
If (letter a It*) then begin if I ileaon then repicomelse hirainwriteln(-nn file open-')I
eno;
It errcnt 3o I then eeueeutin*1gato to
end;if (l4fer = q,) then hopin if fileopen then strencom
olse heciin4,riteinterno file nuenv)Irehilut2
ena;It *Prcnt UIthen aepoutile;
noto Iend
-1 crt : frrcnt 9I
if ̂ Prcnt v I t%ent eeproutine
*~ -
else witeVOE2,)reedli
got* Isend
end;5*Prcnt :errcflt *
if e.rrnt 2, 1 then *.irvoutineelIse Wraitei,I)5
if lattpr <% thpn readfln;
tOO: writainO )
eni. f ma.~in pro!nram I
4011n,'1Ar,1%AQ,) 6P6SCAL IISFS Ift TIS VFUSJO Uf SLEItfainecs frow, tno 11C der~relev PASCAL tfaSlateg pi -a option )
s 2414 - .o sri.j-i.nt tvf~r of ppg arvd vcwrit-a Ae nnst44a
% ?9 va ',-.e tev*s- of v-spir *.4 rewrilo ae. fton-%tarudaed
9 I9?Q Iwo a.astsont frapS of eS#'t &^a r,*Wit. at* non-Wt~fiad
w -Two~ amuvnopent fn..s n1 rvet anrA pewit. aro nmon-standard
44,-
to! vr M- M! Ol.
INITIAL DISTRIBUTION LIST
No. Copies
1. Defense Documentation Center 2Cameron StationAlexandria, Virginia 22314
2. Library, Code 0142 2Naval Postgraduate SchoolMonterey, Callforni a 93940
3. Office of Research Admlnistration ICode 012ANaval Postgraduate SchoolMonterey, California 93940
4. Chairman, Code 52Bz 30Computer Science DepartmentNaval Postgraduate SchoolMonterey, California 93940
I
5. Lyle A. Cox, Jr., Code 52C1 10Computer Science DepartmentNaval Postgraduate SchoolMonterey, California 93940
6. 1. Larry AvruninDavid Taylor Naval Ship Researchand Development Center (Code 18)Carderock LaboratoryBethesda, MD 2004
7. R. P. Crabb, Code 9134 3San Diego, CA 92152
8. G. H. lelssnerDavid Taylor Naval Ship Researchand Development Center (Code 18)Carderock LaboratoryBethesda, ND 20084
9. Kathryn Heninger, Code 7503 3Naval Research LabWashington D. C. 20375
10. Ronald P. Kasik, Code 4451 3Naval Underwater System Centerlmlprt, Al 02B40
114
. ' . . ' .
11. Commander, Code 503 3Naval Sir Development CenterWarmi nster, Pennsylvania 18974
12. Mark Underwood, Code P204 3NPRqWSan Diego, California 92152
13. Michael Wallace, Code 1828 3DTMSRDCBethesda, MD 20084
14. Walter P. Warner, Code K70 3NSWCDahlgren, Virginia 22448
15. John Zenor, Code 31302 3Naval Weapons CenterChina Lake, Ca1ifornia 96555
I
''7
"-"W
IL