home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-05-03 | 149.1 KB | 4,443 lines |
- --::::::::::::::
- --README
- --::::::::::::::
- Suggested Compilation order for Aled (Ada Line Editor):
-
- editor_list.a
- edit_support-spec.a
- edit_worker-spec.a
- edit_worker-body.a
- edit_support-body.a
- editor.a
- ============================================
- Link "editor" (the main pgm) to get the executable.
-
- Documentation for Aled is in "aled.doc" .
- --::::::::::::::
- --aled.doc
- --::::::::::::::
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ALED - Ada Line Editor
-
- A Line-Oriented File Editor written in Ada
-
-
- by Richard Conn
- Texas Instruments
- Advanced Computer Systems Lab
- Ada Technology Branch
-
- 10 December 1984
-
-
- Version 2.0
- 21 January 1985
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- C O N T E N T S
-
- 1. INTRODUCTION...............................................1
-
- 2. USING ALED.................................................2
- 2.1. PRELIMINARIES.........................................4
- 2.1.1. LINE RANGES....................................4
- 2.1.2. LINE REFERENCES................................5
- 2.1.3. STRINGS and LINES..............................5
- 2.1.4. INPUT LINE EDITOR..............................6
- 2.1.5. ABORTING COMMANDS..............................6
- 2.2. COMMANDS..............................................6
-
- 3. SYNOPSIS and COMMENTS......................................9
-
-
-
- APPENDICES
-
- A. SAMPLE SESSION............................................10
-
- Index.....................................................20
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
-
- ALED - Ada Line Editor
-
- A Line-Oriented File Editor written in Ada
-
-
- by Richard Conn
- Texas Instruments
- Advanced Computer Systems Lab
- Ada Technology Branch
-
- 10 December 1984
-
- Version 2.0
- 21 January 1985
-
-
- 1. I N T R O D U C T I O N
-
- ALED is a relatively simple line-oriented file editor which
- is written in the Ada (trademark, United States Department of
- Defense) programming language. It was written to satisfy the
- following needs:
-
- (1) to help the author learn the Ada language by
- writing a useful program whose scope (at a few thousand
- lines) is reasonable
-
- (2) to help others wanting to learn Ada by
- providing a "living example" of an editor written in Ada
-
- (3) to make a transportable editor, written in
- Ada, available for use on a variety of machines; efforts
- were made to isolate any system dependencies to the
- package SYSDEP, so the code should be transportable
- between all machines that have a validated Ada compiler
- and have the routines GET and PUT in the package SYSDEP
- implemented
-
-
- This document is divided into two parts: (1) an overview on
- the operation of the editor from the user's perspective and (2) a
- synopsis of what was learned during its design and comments on
- the design in general.
-
- Version 1.0 of ALED which has been released to the Ada
- Repository is the Engineering Development Model (EDM) of ALED.
- An Advanced Development Model, which was completed some time ago
- and will never be released, was written to learn the basics of
- the problem and to prove that the problem could be solved.
- Version 2.x is the production model of ALED.
-
-
-
-
-
- Page 1
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 2. U S I N G A L E D
-
- ALED was designed and implemented on a Data General MV10000
- under the ROLM Ada Development Environment. It is invoked on
- this system by typing
-
- X EDITOR
-
- where EDITOR.PR is the name of the file containing the object of
- ALED after compilation and linking. This invocation results in
- the following banner being displayed:
-
- ALED - Ada Line Editor by Richard Conn, Version 2.0
- File Name?
-
- The user is expected to enter the name of the file to be edited
- at this time. A file name must be specified, and one will be
- created if the file does not exist. If the indicated text file
- exists, its contents will be read into a doubly-linked list
- created by ALED and made ready for editing. Input line editing
- (see the following section on the Input Line Editor) is allowed,
- so the user can correct any errors he makes while typing the file
- name.
-
- After the indicated file is read in or created, ALED prompts
- the user with
-
- n>
-
- where "n" is 0 if there are no lines in the file (the file is
- empty) or 1 if there are lines in the file. The number in front
- of the ">" character is the number of the current line. As the
- user moves through the file, this number will be updated each
- time the prompt appears.
-
- Once this prompt appears, ALED uses single-character
- commands with command completion and prompting to interface to
- the user. In response to any one of the single-character
- commands recognized by ALED, the ALED editor will complete the
- text of the command, prompt the user for input parameters
- (allowing him to abort by providing no input in most cases), and
- then perform the function of the command. ALED is interactive in
- nature, and the learning curve for ALED is quite short. Built-in
- summary documentation is provided by means of the H (Help)
- Summary command; to illustrate, when the letter "h" is typed
- (case is not significant on letter commands) and the summary
- option is selected, the following display is presented:
-
-
-
-
-
-
-
-
-
- Page 2
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
-
- --- Movement Commands --- ----- Enter Lines -----
- + Advance N Lines A Append after <line>
- - Back Up N Lines I Insert before <line>
- F Find <string> in <range>
- J Jump to <line> ----- Print Lines -----
- N Find Next <string> . Print Current Line
- ----- Delete Command ----- < Print Next Line
- D Delete lines in <range> > Print Next Line
- L List over <range>
- ---- Help and Exits ----
- H This Help Text ---- Substitution ----
- Q Quit without Updating S String Substitute
- X Exit and Update over <range>
-
- ---- File Get/Put ---- -- Miscellaneous --
- G Get <file> after <line> ? Print Statistics
- P Put <file> over <range>
-
- <Range>: % %,%
- First or Second Entries --
- #-Number, .-Current, C-Current, F-First, L-Last
- Singular Entries --
- A-All, P-Page
-
-
- -- Figure 1: ALED Help Command and Display --
-
- To reiterate, the above display was generated as follows:
-
- 1) the prompt "0>" was printed by ALED
- 2) the user typed the letter "h" followed by the
- letter "s" to select the summary
- 3) the command summary was printed by ALED
- command
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Page 3
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 2.1. PRELIMINARIES
-
- 2.1.1. LINE RANGES
- Several of the ALED commands, such as List and Find, perform
- their operations over a range of lines. They prompt the user for
- this line range with the herald "<range>". Examples of this
- prompt are:
-
- 1) list lines in <range>
- 2) find <string>
- over <range>
- 3) substitute for old <string>
- new <string>
- over <range>
-
- Whenever the range prompt ("<range>") is presented, the user
- may enter any of the following responses:
-
- Response Meaning
- -------- -------
- A or a All Lines
- P or p Current Page (next 20 lines)
- . or C or c Current Line
- F or f First Line
- L or l Last Line
-
- #,# A pair of line numbers, like "5,8",
- or relative line references, like
- "-5,+10" for 5 lines before the
- current line to 10 lines after the
- current line, or any combination,
- like "5,+10" for line 5 to 10 lines
- after the current line; the only
- restriction is that the first number
- must evaluate to be less than the
- second number
-
- s,s A mixture of the symbols for Current
- Line, First Line, Last Line, and
- a line number or relative line
- reference, like ".,L" for current
- line to the last line, "1,." for line
- 1 to the current line, "F,." for first
- line to the current line, "-5,." for
- five lines before the current line to
- the current line, etc.
-
-
-
-
-
-
-
-
-
-
- Page 4
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- Examples:
-
- list lines in <range> A <-- all lines
- list lines in <range> .,L <-- current to last
- list lines in <range> 1,5 <-- lines 1 to 5
- list lines in <range> -5,+6 <-- 5 lines before the
- current line to 6
- lines after the
- current line
- list lines in <range> P <-- next 20 lines
- list lines in <range> F,L <-- same as All lines
-
-
- 2.1.2. LINE REFERENCES
- Some commands operate only on a specific line, such as the
- Append and Insert commands. The user is to indicate a specific
- line, as opposed to a range of lines, in response to the "<line>"
- herald printed by these commands; for example:
-
- append after <line>
- insert before <line>
-
- Any of the forms indicated above may be used to define this
- line reference, and the indicated line becomes the first line of
- the range. For instance, if "A" (all lines) is the response to
- the herald, then line 1 is the indicated line since all lines
- references line 1 to the last line. It is usually safer to
- reference only one line in response to the "<line>" herald (like,
- "5" or ".") rather than to use a range specification.
-
-
- 2.1.3. STRINGS and LINES
- Some commands accept a string or a line as input, such as
- the Substitute and Insert commands. In both cases, the text
- which is input by the user is simply a group of characters. No
- quotes or other delimiters are necessary. A blank line is input
- by simply striking the RETURN key or entering any number of space
- characters followed by the RETURN key.
-
- When inputting a group of lines via the Append or Insert
- commands, the lines are prompted for with the herald:
-
- n:
-
- where "n" is the number of the line that is about to be input.
- The user may enter characters as he desires in response to this
- prompt; blank lines may be entered by simply striking the RETURN
- key. To terminate input, the user enters a single dot (".")
- followed by RETURN. See the sample session below and experiment
- with the editor itself for clarification.
-
-
-
-
-
-
- Page 5
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 2.1.4. INPUT LINE EDITOR
- The user has the ability to edit his string or line inputs
- as he enters each character. This is done by striking any one of
- the three input line editor command characters. The following
- table summarizes these characters, giving their default values
- and the functions they perform.
-
- Default
- Value Function
- ------- --------
- <DEL> Delete previous character
- ^U Delete all previous characters and restart input
- ^R Retype the line or string entered so far
-
- These default values may be changed to some other values by
- editing the source code and changing three constants.
-
- 2.1.5. ABORTING COMMANDS
- If the user strikes a command by accident, most commands may
- be aborted by simply doing the following:
-
- 1) not specifying a range of lines (enter a RETURN in
- response to the <range> herald)
- 2) not specifying a line (enter a RETURN in response to
- the <line> herald)
- 3) not specifying a file name for the Get and Put
- commands (enter a RETURN)
-
-
-
-
- 2.2. COMMANDS
- The following presents the various commands of ALED. The
- sample session illustrates their use.
-
- COMMAND: .
- FUNCTION: Print the current line
- The "." command prints the current line.
-
- COMMAND: <
- FUNCTION: Back up to the last line and print it
- The "<" command backs up to the last line and prints it.
-
- COMMAND: >
- FUNCTION: Advance to the next line and print it
- The ">" command advances to the next line and prints it.
-
-
-
-
-
-
-
-
-
-
- Page 6
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
- COMMAND: +
- FUNCTION: Advance n lines from the current line
- The "+" command moves the user an indicated number of lines
- forward from his current position.
-
- COMMAND: -
- FUNCTION: Back up n lines from the current line
- The "-" command moves the user an indicated number of lines
- backward from his current position.
-
- COMMAND: ?
- FUNCTION: Print statistics
- The "?" command prints the name of the file being edited and
- the number of lines in the edit buffer.
-
- COMMAND: A
- FUNCTION: Append lines
- The A command allows the user to enter a group of lines
- after the indicated line. Lines are entered until the user types
- a line containing a single dot (".") in the first column followed
- by a RETURN. The Insert command is like the Append command
- except that it inserts lines BEFORE the indicated line, where
- Append appends lines AFTER the indicated line.
-
- COMMAND: D
- FUNCTION: Delete lines
- The D command deletes all lines over the indicated range of
- lines. There is no recovery from this command.
-
- COMMAND: F
- FUNCTION: Find the first occurance of a string
- The F command searches for the indicated string over the
- indicated range of lines. The first line in the range which
- contains the string is positioned to and the line is printed.
-
- COMMAND: G
- FUNCTION: Get a File
- The G command loads the indicated file into the editor
- buffer after the indicated line. This command can be used to
- read in a file to be included in the edit buffer for paste
- operations, where the Put command is the complementary cut
- operation.
-
- COMMAND: H
- FUNCTION: Print Help Information
- The H command prints a summary of the ALED commands, just
- the names of the ALED commands, or a summary of numeric input
- options to the user.
-
-
-
-
-
-
-
-
-
- Page 7
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- COMMAND: I
- FUNCTION: Insert lines
- The I command allows the user to enter a group of lines
- before the indicated line. Lines are entered until the user
- types a line containing a single dot (".") in the first column
- followed by a RETURN. The Append command is like the Insert
- command except that it appends lines AFTER the indicated line,
- where Insert inserts lines BEFORE the indicated line.
-
- COMMAND: J
- FUNCTION: Jump to the indicated line
- The J command positions the user at the indicated line. The
- line is not printed.
-
- COMMAND: L
- FUNCTION: List lines over a range
- The L command lists all lines over the indicated range of
- lines.
-
- COMMAND: N
- FUNCTION: Find Next occurance of indicated string
- The N command searches for the indicated string starting at
- the next line in the file and proceeding to the end of the file.
- If the user inputs a blank line (a simple RETURN), the last
- string referenced by an F or N command is searched for again.
-
- COMMAND: P
- FUNCTION: Put a range of lines into a file
- The P command writes a group of lines from the edit buffer
- out to a file on disk. This may be used to create desired
- external files or it may be used to cut a section out of the edit
- buffer and paste it in (via the Get command) elsewhere.
-
- COMMAND: Q
- FUNCTION: Quit editor and do not update file
- The Q command allows the user to exit the editor without
- changing the original file on the disk.
-
- COMMAND: S
- FUNCTION: Substitute strings
- The S command substitutes one string for another over the
- indicated range of lines. All occurrances of the old string are
- replaced by the new string over this range.
-
- COMMAND: X
- FUNCTION: Exit the editor and update the file
- The X command exits the editor and updates the file on the
- disk.
-
-
-
-
-
-
-
-
- Page 8
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 3. S Y N O P S I S a n d C O M M E N T S
-
- In summary, the following items were learned from this
- experience:
-
- 1. Ada is feasible; the editor ran with reasonable
- speed
-
- 2. The Ada code was fairly efficient; EDITOR used
- only TEXT_IO for support, and, after a 58K
- initial overhead, the growth of code was
- approximately 9 words/line of code
-
- 3. Standardization under TEXT_IO needs some work;
- some simple, fundamental items, such as an
- input line editor available under GET_LINE,
- are missing (this is why I had to write my
- own input line editor) and GET does not return
- or pass every possible character (the DEL
- character does not pass thru the GET routine
- in my TEXT_IO package, for instance); do all
- GET routines allow single-character input?
-
- 4. Generics are useful and work well; software
- components libraries will be quite beneficial
- in reducing programming overhead once they
- have been developed
-
- 5. Exceptions are very, very useful; note their
- use throughout the code and how they are
- fundamental to the design (note the BEGIN/END
- in the main loop)
-
- 6. Ada code can be written to be quite readable
- and maintainable; I feel that I have successfully
- done this with ALED (assuming that knowledge
- of the generic package in LIST.ADA is known)
-
- 7. In version 2.0 of ALED, the System Dependencies
- were effectively isolated in the package SYSDEP.
- SYSDEP provided only two required routines,
- GET (which input the next character without
- interpretation of any kind) and PUT (which output
- a character without interpretation). This made
- a much more friendly user interface possible.
-
-
-
-
-
-
-
-
-
-
-
- Page 9
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- A. S A M P L E S E S S I O N
- The following is a sample session which illustrates the
- operation of ALED. Comments are placed out to the side, prefixed
- by "<--".
-
-
- ALED - Ada Line Editor by Richard Conn, Version 1.0
- File Name? t.txt <-- File name is selected
- New File <-- File does not already exist
- 0 Lines in File
- Type H for Help
- 0> append after <line> . <-- Append Lines into buffer
- Enter Lines (.<RETURN> to Stop)
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
- 7: A single dot in a line terminates input
- 8: . <-- Input is complete
-
- 7> list lines in <range> all <-- List all lines
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
- 7: A single dot in a line terminates input
-
- 7> list lines in <range> 1,4 <-- List range of lines
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
-
- 4> list lines in <range> -1,+2 <-- List range of lines
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
-
- 6> list lines in <range> 1 <-- List first line
- 1: This is a test and demonstration of ALED
-
-
-
-
-
-
-
-
-
-
-
- Page 10
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
- 1> list lines in <range> p <-- List current page
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
- 7: A single dot in a line terminates input
-
- 7> list lines in <range> a <-- List all lines
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
- 7: A single dot in a line terminates input
-
- 7> Error <-- Invalid Commands
- 7> Error
-
- 7> - back up N lines <line count> 3 <-- Backup 3 lines
- 4> . <-- Print current line
- 4: Note that all commands are single characters;
- 4> + advance N lines <line count> 1 <-- Advance 1 line
- 5> . <-- Print current line
- 5: the editor fills in the prompt with each
-
- 5> substitute for old <string> test <-- substitute
- new <string> xx
- over <range> a
- 1: This is a xx and demonstration of ALED <-- affected
- 2: This is a very short xx, but all commands <-- lines
-
- 7> substitute for old <string> xx <-- change back
- new <string> test
- over <range> 2
- 2: This is a very short test, but all commands
-
- 3> find <string> xx <-- look for "xx"
- over <range> a
- 1: This is a xx and demonstration of ALED
-
- 1> substitute for old <string> xx <-- change it
- new <string> test
- over <range> .
- 1: This is a test and demonstration of ALED
-
- 2> find <string> test <-- look for first
- over <range> a
- 1: This is a test and demonstration of ALED
-
- 1> next Occurrance of <string> <-- look for next
- 2: This is a very short test, but all commands
-
-
-
- Page 11
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 2> list lines in <range> L <-- look at last line
- 7: A single dot in a line terminates input
-
- 7> append after <line> L <-- append lines
- Enter Lines (.<RETURN> to Stop)
- 8: This is yet another test
- 9: These lines are being appended to the
- 10: end of the file.
- 11: I am inserting several instances of
- 12: the word test
- 13: so that there will be something to search for
- 14: in further tests of the Next Occurrance command
- 15: . <-- end input
-
- 14> find <string> test <-- search for "test"
- over <range> a
- 1: This is a test and demonstration of ALED
-
- 1> next Occurrance of <string> <-- search again
- 2: This is a very short test, but all commands
-
- 2> next Occurrance of <string> <-- and again
- 8: This is yet another test
-
- 8> next Occurrance of <string> <-- and again
- 12: the word test
-
- 12> next Occurrance of <string> <-- and again
- 14: in further tests of the Next Occurrance command
-
- 14> next Occurrance of <string> <-- and again
- 14: in further tests of the Next Occurrance command
-
- 14> substitute for old <string> test <-- change string
- new <string> xxxxxxx
- over <range> a
- 1: This is a xxxxxxx and demonstration of ALED
- 2: This is a very short xxxxxxx, but all commands
- 8: This is yet another xxxxxxx
- 12: the word xxxxxxx
- 14: in further xxxxxxxs of the Next Occurrance command
-
- 14> substitute for old <string> xxxxxxx <-- change back
- new <string> test
- over <range> a
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 8: This is yet another test
- 12: the word test
- 14: in further tests of the Next Occurrance command
-
-
-
-
-
-
- Page 12
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 14> substitute for old <string> test
- new <string> "test"
- over <range> 12
- 12: the word "test"
-
- 13> jump to <line> 1 <-- Jump command
-
- 1> jump to <line> L <-- Jump to last line
-
- 14> jump to <line> 1 <-- Jump to first line
-
- 1> list lines in <range> p
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
- 7: A single dot in a line terminates input
- 8: This is yet another test
- 9: These lines are being appended to the
- 10: end of the file.
- 11: I am inserting several instances of
- 12: the word "test"
- 13: so that there will be something to search for
- 14: in further tests of the Next Occurrance command
-
- 14> put <file> q.txt <-- Write lines out
- over <range> 11,L <-- Limit range
- 14> get <file> q.txt <-- Read back in after line 1
- after <line> 1
- 1> list lines in <range> a <-- look at results
- 1: This is a test and demonstration of ALED
- 2: I am inserting several instances of
- 3: the word "test"
- 4: so that there will be something to search for
- 5: in further tests of the Next Occurrance command
- 6: This is a very short test, but all commands
- 7: should be exercised by it
- 8: Note that all commands are single characters;
- 9: the editor fills in the prompt with each
- 10: single character input at the command prompt "n>"
- 11: A single dot in a line terminates input
- 12: This is yet another test
- 13: These lines are being appended to the
- 14: end of the file.
- 15: I am inserting several instances of
- 16: the word "test"
- 17: so that there will be something to search for
- 18: in further tests of the Next Occurrance command
-
- 18> get <file> q.txt <-- read lines back in
- after <line> 7
-
-
-
- Page 13
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 7> list lines in <range> p <-- list page of lines
- 7: should be exercised by it
- 8: I am inserting several instances of
- 9: the word "test"
- 10: so that there will be something to search for
- 11: in further tests of the Next Occurrance command
- 12: Note that all commands are single characters;
- 13: the editor fills in the prompt with each
- 14: single character input at the command prompt "n>"
- 15: A single dot in a line terminates input
- 16: This is yet another test
- 17: These lines are being appended to the
- 18: end of the file.
- 19: I am inserting several instances of
- 20: the word "test"
- 21: so that there will be something to search for
- 22: in further tests of the Next Occurrance command
-
- 22> insert before <line> 16 <-- insert line
- Enter Lines (.<RETURN> to Stop)
- 16: testtesttesttest
- 17: . <-- end input
-
- 17> < <-- backup
- 16: testtesttesttest
-
- 16> <
- 15: A single dot in a line terminates input
-
- 15> >
- 16: testtesttesttest
-
- 16> >
- 17: This is yet another test
-
- 17> <
- 16: testtesttesttest
-
- 16> .
- 16: testtesttesttest
-
- 16> substitute for old <string> test <-- substitute
- new <string> xxxx
- over <range> .
- 16: xxxxtesttesttest <-- observe progress of
- 16: xxxxxxxxtesttest <-- substitute command
- 16: xxxxxxxxxxxxtest
- 16: xxxxxxxxxxxxxxxx
-
- 17> <
- 16: xxxxxxxxxxxxxxxx
-
-
-
-
-
- Page 14
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 16> substitute for old <string> xxxx <-- and again
- new <string> test
- over <range> .
- 16: testxxxxxxxxxxxx
- 16: testtestxxxxxxxx
- 16: testtesttestxxxx
- 16: testtesttesttest
-
- 17> jump to <line> 1
-
- 1> ? <-- statistics
- Edit File Name: t.txt
- 23 Lines in File
- 1> jump to <line> L <-- verify line count
-
- 23> jump to <line> 1
-
- 1> list lines in <range> .
- 1: This is a test and demonstration of ALED
-
- 1> .
- 1: This is a test and demonstration of ALED
-
- 1> list lines in <range> p
- 1: This is a test and demonstration of ALED
- 2: I am inserting several instances of
- 3: the word "test"
- 4: so that there will be something to search for
- 5: in further tests of the Next Occurrance command
- 6: This is a very short test, but all commands
- 7: should be exercised by it
- 8: I am inserting several instances of
- 9: the word "test"
- 10: so that there will be something to search for
- 11: in further tests of the Next Occurrance command
- 12: Note that all commands are single characters;
- 13: the editor fills in the prompt with each
- 14: single character input at the command prompt "n>"
- 15: A single dot in a line terminates input
- 16: testtesttesttest
- 17: This is yet another test
- 18: These lines are being appended to the
- 19: end of the file.
- 20: I am inserting several instances of
- 21: the word "test"
-
- 21> delete lines in <range> 8,11 <-- delete lines
-
- 8> jump to <line> 1
-
-
-
-
-
-
-
- Page 15
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- 1> list lines in <range> p
- 1: This is a test and demonstration of ALED
- 2: I am inserting several instances of
- 3: the word "test"
- 4: so that there will be something to search for
- 5: in further tests of the Next Occurrance command
- 6: This is a very short test, but all commands
- 7: should be exercised by it
- 8: Note that all commands are single characters;
- 9: the editor fills in the prompt with each
- 10: single character input at the command prompt "n>"
- 11: A single dot in a line terminates input
- 12: testtesttesttest
- 13: This is yet another test
- 14: These lines are being appended to the
- 15: end of the file.
- 16: I am inserting several instances of
- 17: the word "test"
- 18: so that there will be something to search for
- 19: in further tests of the Next Occurrance command
-
- 19> delete lines in <range> 2,5 <-- delete more lines
-
- 2> list lines in <range> a
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
- 7: A single dot in a line terminates input
- 8: testtesttesttest
- 9: This is yet another test
- 10: These lines are being appended to the
- 11: end of the file.
- 12: I am inserting several instances of
- 13: the word "test"
- 14: so that there will be something to search for
- 15: in further tests of the Next Occurrance command
-
- 15> Exit and update file (Y/N)? n
-
- 15> quit without File Update (Y/N)? n
-
- 15> Exit and update file (Y/N)? y
-
-
-
-
-
-
-
-
-
-
-
- Page 16
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- -) type t.txt <-- final file
- This is a test and demonstration of ALED
- This is a very short test, but all commands
- should be exercised by it
- Note that all commands are single characters;
- the editor fills in the prompt with each
- single character input at the command prompt "n>"
- A single dot in a line terminates input
- testtesttesttest
- This is yet another test
- These lines are being appended to the
- end of the file.
- I am inserting several instances of
- the word "test"
- so that there will be something to search for
- in further tests of the Next Occurrance command
-
- -) type q.txt <-- Q.TXT file
- I am inserting several instances of
- the word "test"
- so that there will be something to search for
- in further tests of the Next Occurrance command
-
- -) delete q.txt
-
- -) x editor
- ALED - Ada Line Editor by Richard Conn, Version 1.0
- File Name? t.txt <-- reedit file
- 15 Lines in File
- Type H for Help
- 1> list lines in <range> a
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
- 7: A single dot in a line terminates input
- 8: testtesttesttest
- 9: This is yet another test
- 10: These lines are being appended to the
- 11: end of the file.
- 12: I am inserting several instances of
- 13: the word "test"
- 14: so that there will be something to search for
- 15: in further tests of the Next Occurrance command
-
- 15> delete lines in <range> 8
-
- 8> quit without File Update (Y/N)? y <-- demo QUIT
-
-
-
-
-
-
- Page 17
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
-
- -) x editor
- ALED - Ada Line Editor by Richard Conn, Version 1.0
- File Name? t.txt <-- reedit file
- 15 Lines in File
- Type H for Help
- 1> list lines in <range> a
- 1: This is a test and demonstration of ALED
- 2: This is a very short test, but all commands
- 3: should be exercised by it
- 4: Note that all commands are single characters;
- 5: the editor fills in the prompt with each
- 6: single character input at the command prompt "n>"
- 7: A single dot in a line terminates input
- 8: testtesttesttest
- 9: This is yet another test
- 10: These lines are being appended to the
- 11: end of the file.
- 12: I am inserting several instances of
- 13: the word "test"
- 14: so that there will be something to search for
- 15: in further tests of the Next Occurrance command
-
- 15> delete lines in <range> 8 <-- remove line from file
-
- 8> Exit and update file (Y/N)? y <-- demo EXIT
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Page 18
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- -) type t.txt <-- show result
- This is a test and demonstration of ALED
- This is a very short test, but all commands
- should be exercised by it
- Note that all commands are single characters;
- the editor fills in the prompt with each
- single character input at the command prompt "n>"
- A single dot in a line terminates input
- This is yet another test
- These lines are being appended to the
- end of the file.
- I am inserting several instances of
- the word "test"
- so that there will be something to search for
- in further tests of the Next Occurrance command
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Page 19
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
-
- I n d e x
-
-
- +
- + Command, 7
-
- -
- - Command, 7
-
- <
- < Command, 6
-
- >
- > Command, 6
-
- ?
- ? Command, 7
-
- A
- A Command, 7
- Aborting Commands, 6
- Ada, 1
- Advance Line, 6
- Advance N Lines, 7
- Advanced Development Model, 1
- ALED
- Aborting Commands, 6
- ADM, 1
- Advanced Development Model, 1
- EDM, 1
- Engineering Development Model, 1
- Help Command, 3
- Input Line Editor, 6
- Line Input, 5
- Line Ranges, 4
- Line References, 5
- Prompt, 2
- Purpose, 1
- String Input, 5
- Append Lines, 7
-
- B
- Back Up Line, 6
- Back Up N Lines, 7
-
- C
- Command
- +, 7
- -, 7
- ., 6
- <, 6
- >, 6
- ?, 7
- A, 7
-
-
- Page 20
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
- D, 7
- F, 7
- G, 7
- H, 7
- I, 8
- J, 8
- L, 8
- N, 8
- P, 8
- Q, 8
- S, 8
- X, 8
- COMMANDS, 6
-
- D
- D Command, 7
- Delete Lines, 7
- Dot Command, 6
-
- E
- Engineering Development Model, 1
- Exit, 8
-
- F
- F Command, 7
- File
- Get, 7
- Put, 8
- Find Next String, 8
- Find String, 7
-
- G
- G Command, 7
- Get File, 7
-
- H
- H Command, 7
- Help, 3, 7
-
- I
- I Command, 8
- Input Line Editor, 6
- Insert Lines, 8
- INTRODUCTION, 1
-
- J
- J Command, 8
- Jump to Line, 8
-
- L
- L Command, 8
- Line Range Specification, 4
- Line Reference Specification, 5
- List Lines, 8
-
-
-
- Page 21
-
-
-
-
-
- ALED - A Line-Oriented File Editor Written in Ada
-
-
- N
- N Command, 8
- Next String, 8
-
- P
- P Command, 8
- PRELIMINARIES, 4
- Print Current Line, 6
- Print Statistics, 7
- Put File, 8
-
- Q
- Q Command, 8
- Quit, 8
-
- S
- S Command, 8
- SAMPLE SESSION, 10
- Substitute Strings, 8
- SYNOPSIS and COMMENTS, 9
-
- U
- USING ALED, 2
-
- X
- X Command, 8
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Page 22
-
-
-
-
-
- --::::::::::::::
- --edit_support-body.a
- --::::::::::::::
- -- Package body EDIT_SUPPORT
- -- Written by Richard Conn, TI Ada Technology Branch
- -- Version 2.0, Date 31 Jan 85
- -- Version 2.1, Date 15 Feb 85
- -- CAIS Version 3.0, Date 22 August 85
- -- CAIS Version 3.1, Date 13 Feb 86
- --
- -- NB: changes for the CAIS port are indicated by one of the
- -- following on each affected line:
- -- --!Rem Comments, remarks
- -- --!Add Lines added to the code
- -- --!Del Lines deleted from the code
- -- --!Cha Lines changed in the code
- -- (It is a bit subjective; when does a big change become
- -- a delete and an add ?)
-
- with Cais; use Cais; --!Cha was with Sysdep
- package body EDIT_SUPPORT is
-
- --!Rem The Keys declaration is used only as a placeholder in
- --!Rem the Scroll_Terminal.Get calls; it is NOT used.
- Keys : Scroll_Terminal.Function_Key_Descriptor(1); --!Add
- --
- -- Editor constants
- --
- EDIT_DEL_CHAR : constant CHARACTER := ASCII.DEL;
- EDIT_DEL_LINE : constant CHARACTER := ASCII.NAK;
- EDIT_RETYPE_LINE : constant CHARACTER := ASCII.DC2;
- EDIT_QUOTE : constant CHARACTER := '\';
- TAB_SIZE : constant NATURAL := 8; -- for indenting
-
- --
- -- Initialize console
- --
- procedure CONSOLE_INIT is
- begin
- Scroll_Terminal.Set_Echo(False); --!Cha (was Sysdep.Open_Console)
- end CONSOLE_INIT;
-
- --
- -- Deinitialize console
- --
- procedure CONSOLE_DEINIT is
- begin
- Scroll_Terminal.Set_Echo(True); --!Cha (was Sysdep.Close_Console)
- end CONSOLE_DEINIT;
-
- --
- -- PRINTING_CHARACTER indicates if the character presented to it is printable
- -- (ie, occupies a position on the screen)
- --
- function PRINTING_CHARACTER (INCHAR : CHARACTER) return BOOLEAN is
- begin
- if INCHAR >= ' ' and INCHAR < ASCII.DEL then
- return TRUE;
- else
- return FALSE;
- end if;
- end PRINTING_CHARACTER;
-
- --
- -- INPUT_LINE is the input line editor
- -- Customization can be done via the constant declarations
- --
- function INPUT_LINE return LINE_STRING is
-
- WORK_LINE : LINE_STRING;
- INCHAR : CHARACTER;
- INDEX : NATURAL;
- POSITION : NATURAL;
-
- procedure BACKUP is -- erase previous character from display
- begin
- Scroll_Terminal.PUT (ASCII.BS); --!Cha
- Scroll_Terminal.PUT (' '); --!Cha
- Scroll_Terminal.PUT (ASCII.BS); --!Cha
- end BACKUP;
-
- procedure BACKUP_CHARACTER is -- backup over last char w/tab processing
- INCHAR : CHARACTER;
- BACKUP_POSITION : NATURAL;
- begin
- INCHAR := WORK_LINE (INDEX); -- extract target character
- if INCHAR = ASCII.HT then
- -- back up over tab
- -- compute position prior to this tab
- POSITION := 1;
- for I in 1 .. INDEX - 1 loop
- if WORK_LINE (I) /= ASCII.HT then
- POSITION := POSITION + 1;
- else
- POSITION := POSITION + 1;
- while POSITION mod TAB_SIZE /= 1 loop
- POSITION := POSITION + 1;
- end loop;
- end if;
- end loop;
- -- BACKUP required number of character positions
- BACKUP_POSITION := POSITION;
- BACKUP;
- BACKUP_POSITION := BACKUP_POSITION + 1;
- while BACKUP_POSITION mod TAB_SIZE /= 1 loop
- BACKUP;
- BACKUP_POSITION := BACKUP_POSITION + 1;
- end loop;
- else
- -- back up over normal char
- if PRINTING_CHARACTER (INCHAR) then
- -- printing char
- BACKUP;
- POSITION := POSITION - 1;
- end if;
- end if;
- end BACKUP_CHARACTER;
-
- procedure STORE_CHARACTER (INCHAR : CHARACTER) is -- store char
- begin
- if INDEX < WORK_LINE'LAST then
- -- room for char
- WORK_LINE (INDEX) := INCHAR;
- INDEX := INDEX + 1;
- else
- -- no room
- Scroll_Terminal.PUT (ASCII.BEL); -- alarm --!Cha
- end if;
- end STORE_CHARACTER;
-
- begin
- INDEX := 1;
- POSITION := 1;
- loop
- Scroll_Terminal.GET (INCHAR, Keys); --!Cha
- exit when INCHAR = ASCII.Lf; --!Cha was Ascii.CR
- case INCHAR is
- when EDIT_DEL_CHAR => -- delete previous character
- if INDEX /= 1 then
- INDEX := INDEX - 1;
- BACKUP_CHARACTER;
- else
- Scroll_Terminal.PUT (ASCII.BEL); --!Cha
- end if;
- when EDIT_DEL_LINE => -- delete line typed so far
- for I in 1 .. INDEX - 1 loop
- INDEX := INDEX - 1;
- BACKUP_CHARACTER;
- end loop;
- INDEX := 1;
- POSITION := 1;
- when EDIT_RETYPE_LINE => -- retype line input so far
- NEW_LINE; -- next line
- WORK_LINE (INDEX) := ASCII.NUL; -- mark end of line
- OUTPUT_LINE (WORK_LINE);
- when EDIT_QUOTE => -- quote next char
- Scroll_Terminal.PUT (EDIT_QUOTE); --!Cha echo EDIT_QUOTE
- POSITION := POSITION + 1; -- EDIT_QUOTE is printing char
- Scroll_Terminal.GET (INCHAR, Keys); --!Cha get quoted char
- STORE_CHARACTER (INCHAR);
- if PRINTING_CHARACTER (INCHAR) then
- Scroll_Terminal.PUT (INCHAR); -- echo it
- POSITION := POSITION + 1;
- end if;
- when ASCII.HT => -- tabulate
- STORE_CHARACTER (INCHAR);
- Scroll_Terminal.PUT (' '); --!Cha
- POSITION := POSITION + 1;
- while POSITION mod TAB_SIZE /= 1 loop
- Scroll_Terminal.PUT (' '); --!Cha
- POSITION := POSITION + 1;
- end loop;
- when others => -- process next char
- STORE_CHARACTER (INCHAR); -- store char
- if PRINTING_CHARACTER (INCHAR) then
- Scroll_Terminal.PUT (INCHAR); --!Cha
- POSITION := POSITION + 1;
- end if;
- end case;
- end loop;
- NEW_LINE;
- --
- -- NUL-fill line
- --
- for I in INDEX .. WORK_LINE'LAST loop
- WORK_LINE (I) := ASCII.NUL;
- end loop;
- --
- -- test for empty line and set BLANK_INPUT
- --
- BLANK_INPUT := TRUE;
- for I in 1 .. INDEX loop
- if WORK_LINE (I) > ' ' then
- BLANK_INPUT := FALSE;
- exit;
- end if;
- end loop;
- --
- -- return line
- --
- return WORK_LINE;
- --
- end INPUT_LINE;
-
-
- --
- -- OUTPUT_LINE outputs the string input to the user's terminal.
- --
- procedure OUTPUT_LINE (STR : LINE_STRING) is
-
- INDEX : NATURAL := 1;
- POSITION : NATURAL := 1;
-
- begin
- loop
- exit when STR (INDEX) = ASCII.NUL;
- if STR (INDEX) = ASCII.HT then
- -- tabulate
- Scroll_Terminal.PUT (' '); --!Cha
- POSITION := POSITION + 1;
- while (POSITION mod TAB_SIZE) /= 1 loop
- Scroll_Terminal.PUT (' '); --!Cha
- POSITION := POSITION + 1;
- end loop;
- else
- -- output character
- Scroll_Terminal.PUT (STR (INDEX)); --!Cha
- if PRINTING_CHARACTER (STR (INDEX)) then
- POSITION := POSITION + 1;
- end if;
- end if;
- INDEX := INDEX + 1;
- end loop;
- end OUTPUT_LINE;
-
-
- --
- -- GETCH returns the next character without echo
- -- GETCH_WITH_ECHO returns the next character with echo if
- -- ' ' <= ch < DEL
- --
- function GETCH return CHARACTER is
- INCHAR : CHARACTER;
- begin
- Scroll_Terminal.GET (INCHAR, Keys); --!Cha
- return INCHAR;
- end GETCH;
-
- function GETCH_WITH_ECHO return CHARACTER is
- INCHAR : CHARACTER;
- begin
- INCHAR := GETCH;
- if ' ' <= INCHAR and INCHAR < ASCII.DEL then
- Scroll_Terminal.PUT (INCHAR); --!Cha
- end if;
- return INCHAR;
- end GETCH_WITH_ECHO;
-
-
- --
- -- PUT outputs a string
- --
- procedure PUT (INSTR : STRING) is
- begin
- for I in 1 .. INSTR'LAST loop
- Scroll_Terminal.PUT (INSTR (I)); --!Cha
- end loop;
- end PUT;
-
-
- --
- -- NEW_LINE outputs CRLF to the console
- --
- procedure NEW_LINE is
- begin
- Scroll_Terminal.PUT (ASCII.CR); --!Cha
- Scroll_Terminal.PUT (ASCII.LF); --!Cha
- end NEW_LINE;
-
-
- --
- -- CONVERT_TO_NUMBER converts the number represented by ASCII
- -- digit chars to type NATURAL and returns its value. VALID_NUMBER
- -- and CTN_INDEX (an I/O value) are returned as side effects.
- --
- function CONVERT_TO_NUMBER (STR : LINE_STRING) return NATURAL is
-
- INTERNAL_VALUE : NATURAL;
- INDEX : NATURAL;
- DONE : BOOLEAN;
-
- function IS_DIGIT (IN_CHAR : CHARACTER) return BOOLEAN is
- begin
- if IN_CHAR in '0' .. '9' then
- return TRUE;
- else
- return FALSE;
- end if;
- end IS_DIGIT;
-
- begin
- INTERNAL_VALUE := 0; -- set accumulated value
- INDEX := CTN_INDEX; -- set start index
-
- if IS_DIGIT (STR (INDEX)) then
- VALID_NUMBER := TRUE; -- input is a number
- else
- VALID_NUMBER := FALSE; -- input is not valid
- return 0; -- return value of 0
- end if;
-
- loop
- exit when not IS_DIGIT (STR (INDEX));
- case STR (INDEX) is
-
- when '0' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 0;
-
- when '1' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 1;
-
- when '2' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 2;
-
- when '3' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 3;
-
- when '4' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 4;
-
- when '5' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 5;
-
- when '6' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 6;
-
- when '7' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 7;
-
- when '8' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 8;
-
- when '9' => INTERNAL_VALUE := INTERNAL_VALUE * 10 + 9;
-
- when others => null; -- this will not be selected
- end case;
- INDEX := INDEX + 1;
- end loop;
-
- CTN_INDEX := INDEX; -- return index of invalid digit
- return INTERNAL_VALUE;
-
- exception
- when others => -- any type of numeric error trapped
- CTN_INDEX := INDEX; -- index set
- VALID_NUMBER := FALSE; -- not valid
- return 0; -- return 0 value
-
- end CONVERT_TO_NUMBER;
-
- end EDIT_SUPPORT;
-
-
- --::::::::::::::
- --edit_support-spec.a
- --::::::::::::::
- --
- -- PACKAGE edit_support
- -- by Richard Conn, TI Ada Technology Branch
- -- Version 1.0, 9 Nov 84
- -- Version 2.0, 29 Jan 85
- -- Version 2.1, 15 Feb 85
- -- CAIS Version 3.0, 21 August 85
- -- CAIS Version 3.1, 13 Feb 86
- -- NB: changes for the CAIS port are indicated by one of the
- -- following on each affected line:
- -- --!Rem Comments, remarks
- -- --!Add Lines added to the code
- -- --!Del Lines deleted from the code
- -- --!Cha Lines changed in the code
- -- (It is a bit subjective; when does a big change become
- -- a delete and an add ?)
- --
- -- EDIT_SUPPORT provides a group of low-level support routines
- -- for the editor. These are basic routines which can be used
- -- by programs other than the editor.
- --
- with Editor_List; --!Cha Renamed from Generic_List to avoid
- --!Cha name collision with CAIS Prototype
- --!Cha package named Generic_List (a
- --!Cha modified version Of R. Conn's orig).
- --!Cha TEXT_IO; used only for Integer_IO; see below...
- package EDIT_SUPPORT is
-
- --
- -- The following establishes the basic set of types, objects,
- -- and linked-list manipulation and numeric I/O routines.
- --
- LINE_LENGTH : constant := 256; -- allow 256 chars/line
- subtype LINE_STRING is STRING (1 .. LINE_LENGTH);
- package LINE_LIST is new Editor_List (ELEMENT_OBJECT => LINE_STRING);
-
- --!Rem The following instantiation was commented out, because it was
- --!Rem felt it would be better to not use multiple methods of accessing
- --!Rem the terminal (e.g Scroll_Terminal AND Num_IO). Use of Num_IO.Put
- --!Rem has been replaced with Edit_Support.Put (Integer'image(x))
-
- --!Del package NAT_IO is new TEXT_IO.INTEGER_IO (NATURAL);
-
- --
- -- The following are global values which are set by the low-level
- -- support routines.
- --
-
- --
- -- BLANK_INPUT is set by the input line editor INPUT_LINE.
- -- If the line just input contained nothing but space characters
- -- (ie, is a blank line), INPUT_LINE sets BLANK_LINE to TRUE.
- -- Else, BLANK_LINE is FALSE.
- --
- BLANK_INPUT : BOOLEAN := TRUE;
-
- --
- -- VALID_NUMBER is set by the string-to-natural conversion routine
- -- CONVERT_TO_NUMBER. If the string passed in does not begin with
- -- a valid digit character ('0' to '9'), VALID_NUMBER is set to FALSE
- -- and the value of 0 is returned by CONVERT_TO_NUMBER. Else,
- -- VALID_NUMBER is set to TRUE and the converted number is returned.
- --
- VALID_NUMBER : BOOLEAN := FALSE;
-
- --
- -- CTN_INDEX is set by the caller of CONVERT_TO_NUMBER to tell it
- -- where to begin the conversion. This number is the index
- -- of the first character at which to begin conversion. On exit,
- -- CTN_INDEX is the index of the character at which conversion was
- -- halted.
- --
- CTN_INDEX : NATURAL;
-
- --
- -- The following are the workhorse routines of this package.
- --
-
- --
- -- These routines initialize and deinitialize the
- -- console. They should be called at the beginning and at
- -- the end of the edit session.
- --
- procedure CONSOLE_INIT;
- procedure CONSOLE_DEINIT;
-
- --
- -- INPUT_LINE is a function which provides an input line editor.
- -- It accepts characters from the user until an end-of-line
- -- character is received, at which point INPUT_LINE terminates and
- -- returns an object of type LINE_STRING to the caller. INPUT_LINE
- -- allows simple editing of the input text as it is typed, permitting
- -- the user to delete previous characters, delete input entered so
- -- far, retype the line as entered so far, and quote a character for
- -- literal input. INPUT_LINE will not permit the limit of the input
- -- buffer to be exceeded.
- --
- -- BLANK_LINE is set to TRUE if only blank characters are
- -- contained in the line.
- --
- -- The following constants may be changed as desired:
- --
- -- Constant Meaning
- -- EDIT_DEL_CHAR Delete previous character in buffer
- -- EDIT_DEL_LINE Restart buffer entry
- -- EDIT_RETYPE_LINE Retype input line as entered so far
- -- EDIT_QUOTE Quote following character
- --
- function INPUT_LINE return LINE_STRING;
-
- --
- -- Return next char without echo
- -- Return next char with echo if >= ' ' and < DEL
- --
- function GETCH return CHARACTER;
- function GETCH_WITH_ECHO return CHARACTER;
-
-
- --
- -- Provides put string routine
- --
- procedure PUT (INSTR : STRING);
-
-
- --
- -- Echo CRLF
- --
- procedure NEW_LINE;
-
-
- --
- -- OUTPUT_LINE is a procedure which outputs an object of type
- -- LINE_STRING to the user's terminal. Tab expansion is supported,
- -- and no trailing nulls are output.
- --
- procedure OUTPUT_LINE (STR : LINE_STRING);
-
-
- --
- -- CONVERT_TO_NUMBER accepts as input an object of type
- -- LINE_STRING and converts the ASCII characters starting at
- -- the global index CTN_INDEX to a natural number. The value
- -- of this number is returned, and CTN_INDEX is updated to
- -- indicate the index of the character which stopped the number
- -- scan.
- --
- -- VALID_NUMBER is set to TRUE if the first character is an
- -- ASCII digit character ('0' to '9'); VALID_NUMBER is set to
- -- FALSE if the first character is not a digit
- --
- -- CTN_INDEX is returned with the index of the character which
- -- stopped the scan/conversion process.
- --
- function CONVERT_TO_NUMBER (STR : LINE_STRING) return NATURAL;
-
- end EDIT_SUPPORT;
-
-
- --::::::::::::::
- --edit_worker-body.a
- --::::::::::::::
- -- Package Body of EDIT_WORKER
- -- by Richard Conn, Texas Instruments, Ada Technology Branch
- -- Version 1.0, Date 20 Nov 84
- -- Version 2.0, Date 31 Jan 85
- -- Version 2.1, Date 15 Feb 85
- -- CAIS Version 3.0, 21 August 85
- -- CAIS Version 3.1, 13 Feb 86
- -- NB: changes for the port are indicated by one of the
- -- following on each affected line:
- -- --!Rem Comments, remarks
- -- --!Add Lines added to the code
- -- --!Del Lines deleted from the code
- -- --!Cha Lines changed in the code
- -- (it is a bit subjective; when does a big change become
- -- a delete and an add ?)
- --
- --!Rem Instantiation of Integer_IO was commented out, because it was
- --!Rem felt it would be better to not use multiple methods of accessing
- --!Rem the terminal (e.g Scroll_Terminal AND Num_IO). Use of Integer_IO.Put
- --!Rem has been replaced with Edit_Support.Put (Integer'image(x))
- --
- -- This package contains all of the procedures which implement
- -- the major commands of the editor. EDIT_WORKER is divided into
- -- functional sections (more or less), with each section separated
- -- from the others by lines like "--=============".
- --
- -- The package is divided into the following sections:
- --
- -- SECTION FUNCTION
- --!Del Package NUM_IO Provide numeric output for NATURAL numbers
- -- RANGE_INPUT Provide general-purpose line range input
- -- CURRENT_LINE Returns the number of the current line
- -- LAST_LINE Returns the number of the last line
- -- ADVANCE_LINE Advances to the next line
- -- BACKUP_LINE Back ups to the last line
- -- Line Output Print lines and info to the terminal
- -- INPUT_LINE_PROMPT
- -- NUMBER_PREFIX
- -- PREFIX_PRINT
- -- COMMAND_GOTO Implements the Jump (J) Command and Used Internally
- -- COMMAND_APPEND Implements the Append (A) Command
- -- COMMAND_INSERT Implements the Insert (I) Command
- -- COMMAND_LIST Implements the List (L) Command
- -- COMMAND_DELETE Implements the Delete (D) Command
- -- Scanning Aids Lower-level functions/procedures for Substitute
- -- SUB_STRING and Find
- -- COUNT_CHARS
- -- SUBSTITUTE
- -- COMMAND_SUBSTITUTE Implements the Substitute (S) Command
- -- COMMAND_FIND Implements the Find (F) Command
- -- GET and PUT Support Routines to Support File Input/Output
- -- WRITE_FLINE
- -- PUT_RANGE
- -- READ_FILE
- -- COMMAND_GET Implements the Get (G) Command
- -- COMMAND_PUT Implements the Put (P) Command
- --
-
- with Cais;
- with EDIT_SUPPORT;
- use EDIT_SUPPORT;
-
- package body EDIT_WORKER is
-
- --
- -- LINE_EXIT_CHAR is the character which, when it appears as the first
- -- character of a line and it is the only character on that line, indicates
- -- that the last line has been input for the Append and Insert Commands.
- --
- LINE_EXIT_CHAR : constant CHARACTER := '.';
-
- --===================================================================
- -- Package NUM_IO
- -- Generic Instantiation of TEXT_IO.INTEGER_IO for NATURAL numbers
- --
- --!Del package NUM_IO is new TEXT_IO.INTEGER_IO (NATURAL);
-
- --===================================================================
- -- RANGE_INPUT inputs one or two values, and it always returns with
- -- LINE_START containing the first value and LINE_STOP containing the
- -- second. LINE_START <= LINE_STOP, and if there was any error in
- -- the input, the exception RANGE_ERROR is raised
- --
- procedure RANGE_INPUT is
-
- INTERNAL_ERROR : exception;
- PAGE_SIZE : constant NATURAL := 20; -- number of lines/"page"
- RANGE_LINE : LINE_STRING;
- I : NATURAL; -- index of next char in input line
- DONE : BOOLEAN := FALSE;
-
- --
- -- Local procedure FLUSH_SPACES - skip over spaces until non-space,
- -- including end-of-line (ASCII.nul), is encountered
- --
- procedure FLUSH_SPACES is
- begin
- loop
- exit when RANGE_LINE (I) /= ' ';
- I := I + 1;
- end loop;
- end FLUSH_SPACES;
-
- --
- -- The body of RANGE_INPUT
- --
- begin
- I := 1; -- index of first char
- PUT (" "); -- space (prompt)
- RANGE_LINE := INPUT_LINE; -- input line (with editing)
- if BLANK_INPUT then
- LINE_START := LINE_LIST.CURRENT_INDEX; -- set first and last to .
- LINE_STOP := LINE_START;
- return; -- done
- end if;
-
- FLUSH_SPACES; -- get rid of leading spaces
-
- --
- -- Check for an process the First Argument
- --
- case RANGE_LINE (I) is
- -- first of one or two arguments
- when '+' => -- current line + offset
- CTN_INDEX := I + 1; -- set starting index
- LINE_START := LINE_LIST.CURRENT_INDEX +
- CONVERT_TO_NUMBER (RANGE_LINE);
- LINE_STOP := LINE_START;
- I := CTN_INDEX; -- restore index
- when '-' => -- current line - offset
- CTN_INDEX := I + 1; -- set starting index
- LINE_START := LINE_LIST.CURRENT_INDEX -
- CONVERT_TO_NUMBER (RANGE_LINE);
- LINE_STOP := LINE_START;
- I := CTN_INDEX; -- restore index
- when 'a' | 'A' => -- all lines
- LINE_START := 1;
- LINE_STOP := LINE_LIST.LAST_INDEX;
- I := I + 1; -- next char
- when 'c' | 'C' | '.' => -- current line
- LINE_START := LINE_LIST.CURRENT_INDEX;
- LINE_STOP := LINE_START;
- I := I + 1; -- next char
- when 'f' | 'F' => -- first line
- LINE_START := 1;
- LINE_STOP := LINE_START;
- I := I + 1; -- next char
- when 'l' | 'L' => -- last line
- LINE_START := LINE_LIST.LAST_INDEX;
- LINE_STOP := LINE_START;
- I := I + 1; -- next char
- when 'p' | 'P' => -- page
- LINE_START := LINE_LIST.CURRENT_INDEX;
- if LINE_START + PAGE_SIZE > LINE_LIST.LAST_INDEX then
- LINE_STOP := LINE_LIST.LAST_INDEX;
- else
- LINE_STOP := LINE_START + PAGE_SIZE;
- end if;
- I := I + 1; -- next char
- when '0' .. '9' =>
- CTN_INDEX := I;
- LINE_START := CONVERT_TO_NUMBER (RANGE_LINE);
- LINE_STOP := LINE_START;
- I := CTN_INDEX;
- when others =>
- raise INTERNAL_ERROR;
- end case;
-
- --
- -- Check for possible range errors
- --
- if LINE_START > LINE_LIST.LAST_INDEX then raise RANGE_ERROR; end if;
- if LINE_STOP > LINE_LIST.LAST_INDEX then raise RANGE_ERROR; end if;
-
- --
- -- Advance to next token
- --
- FLUSH_SPACES; -- flush spaces between entires
-
- --
- -- Done if no next token
- --
- if RANGE_LINE (I) = ASCII.NUL then
- return;
- end if;
-
- --
- -- If a comma is present, a second argument is given
- --
- if RANGE_LINE (I) = ',' then
- I := I + 1;
- FLUSH_SPACES;
- if RANGE_LINE (I) = ASCII.NUL then
- raise INTERNAL_ERROR;
- end if;
- end if;
-
- --
- -- Process Second Argument of an argument pair
- -- The value of this argument is assigned to LINE_STOP
- --
- case RANGE_LINE (I) is
- -- second of two arguments
- when '+' => -- current line + offset
- CTN_INDEX := I + 1;
- LINE_STOP := LINE_LIST.CURRENT_INDEX +
- CONVERT_TO_NUMBER (RANGE_LINE);
- I := CTN_INDEX;
- when '-' => -- current line - offset
- CTN_INDEX := I + 1;
- LINE_STOP := LINE_LIST.CURRENT_INDEX -
- CONVERT_TO_NUMBER (RANGE_LINE);
- I := CTN_INDEX;
- when 'c' | 'C' | '.' => -- current line
- LINE_STOP := LINE_LIST.CURRENT_INDEX;
- when 'f' | 'F' => -- first line
- LINE_STOP := 1;
- when 'l' | 'L' => -- last line
- LINE_STOP := LINE_LIST.LAST_INDEX;
- when '0' .. '9' =>
- CTN_INDEX := I;
- LINE_STOP := CONVERT_TO_NUMBER (RANGE_LINE);
- I := CTN_INDEX;
- when others =>
- raise INTERNAL_ERROR;
- end case;
-
- --
- -- Check out possible range errors
- --
- if LINE_STOP > LINE_LIST.LAST_INDEX then raise RANGE_ERROR; end if;
-
- --
- -- Handle Exceptions Raised within the procedure RANGE_INPUT
- --
- exception
- when NUMERIC_ERROR =>
- NEW_LINE;
- PUT (" Numeric Value Error");
- LINE_START := 0;
- LINE_STOP := 0;
- raise RANGE_ERROR;
- when INTERNAL_ERROR =>
- NEW_LINE;
- PUT (" Range Syntax Error");
- LINE_START := 0;
- LINE_STOP := 0;
- raise RANGE_ERROR;
- when RANGE_ERROR =>
- NEW_LINE;
- PUT (" Range Value Error");
- LINE_START := 0;
- LINE_STOP := 0;
- raise RANGE_ERROR;
- when others =>
- NEW_LINE;
- PUT (" Unknown Error in RANGE_INPUT");
- LINE_START := 0;
- LINE_STOP := 0;
- raise RANGE_ERROR;
-
- end RANGE_INPUT;
-
-
- --===================================================================
- --
- -- CURRENT_LINE
- -- This function returns the number of the current line
- --
-
- function CURRENT_LINE return NATURAL is
- begin
- return LINE_LIST.CURRENT_INDEX;
- end CURRENT_LINE;
-
-
- --===================================================================
- --
- -- LAST_LINE
- -- This function returns the number of the last line
- --
-
- function LAST_LINE return NATURAL is
- begin
- return LINE_LIST.LAST_INDEX;
- end LAST_LINE;
-
-
- --===================================================================
- --
- -- ADVANCE_LINE
- -- This function advances the current line by one
- --
-
- procedure ADVANCE_LINE is
- DUMMY : BOOLEAN;
- begin
- DUMMY := LINE_LIST.CURRENT_NEXT;
- end ADVANCE_LINE;
-
-
- --===================================================================
- --
- -- BACKUP_LINE
- -- This procedure back ups the current line by one
- --
-
- procedure BACKUP_LINE is
- DUMMY : BOOLEAN;
- begin
- DUMMY := LINE_LIST.CURRENT_PREVIOUS;
- end BACKUP_LINE;
-
-
-
- --===================================================================
- --
- -->> Procedure INPUT_LINE_PROMPT
- -- This procedure simply prints the prompt for the Append and Insert
- -- commands.
- --
-
- procedure INPUT_LINE_PROMPT is
- begin
- PUT ("Enter Lines (");
- --!Rem ?Why was Text_IO used instead of Edit_Support?
- --!Rem TEXT_IO.PUT (LINE_EXIT_CHAR); <<= original code
- PUT ("" & LINE_EXIT_CHAR); --!Cha (cheating to make it a string)
- PUT ("<RETURN> to Stop)");
- NEW_LINE;
- end INPUT_LINE_PROMPT;
-
- --
- -->> Procedure NUMBER_PREFIX
- -- This routine prints the prefix number ("nnnnn: ") for lines
- -- that are displayed or input.
- --
- procedure NUMBER_PREFIX (NUM : NATURAL) is
- begin
- --!Rem original line: NUM_IO.PUT (INTEGER (NUM), 5);
- PUT (Integer'image(Num)); --!Cha
- PUT (": "); -- trailing prompt
- end NUMBER_PREFIX;
-
- --
- -->> Procedure PREFIX_PRINT
- -- This routine prints a line prefixed by a number ("nnnnn: text").
- --
- procedure PREFIX_PRINT (NUM : NATURAL; STR : LINE_STRING) is
- begin
- NUMBER_PREFIX (NUM);
- OUTPUT_LINE (STR);
- end PREFIX_PRINT;
-
- --===================================================================
- -- Procedure INITIALIZE_EDIT
- -- This procedure initializes the editor for future processing
- --
- procedure INITIALIZE_EDIT is
- begin
- LINE_LIST.INITIALIZE_LIST;
- end INITIALIZE_EDIT;
-
-
- --===================================================================
- -- Procedure COMMAND_GOTO
- -- This procedure positions the current line to the indicated index.
- -- That is, if NUM = 5, the fifth line in the file becomes the current line.
- --
- procedure COMMAND_GOTO (NUM : NATURAL) is
- I : NATURAL;
- DUMMY : BOOLEAN;
- begin
- if NUM <= LINE_LIST.LAST_INDEX then
- I := NUM;
- else
- I := LINE_LIST.LAST_INDEX;
- end if;
- DUMMY := LINE_LIST.SET_CURRENT_INDEX (I); -- return code is a don't care
- end COMMAND_GOTO;
-
- --===================================================================
- -- Procedure COMMAND_APPEND
- -- This procedure implements the Append command. It accepts a group of
- -- lines one at a time, appends the new line after the current line, makes
- -- the new line the current line, and continues until a line consisting of
- -- only a LINE_EXIT_CHAR is input.
- --
- procedure COMMAND_APPEND is
- INLINE : LINE_STRING;
- begin
- INPUT_LINE_PROMPT; -- print prompt
- loop
- NUMBER_PREFIX (LINE_LIST.CURRENT_INDEX + 1); -- print number of line
- INLINE := INPUT_LINE; -- get input line
- exit when (INLINE (1) = LINE_EXIT_CHAR) and
- (INLINE (2) = ASCII.NUL); -- test for exit condition
- LINE_LIST.APPEND_ELEMENT (INLINE); -- append line after current
- end loop;
- end COMMAND_APPEND;
-
- --===================================================================
- -- Procedure COMMAND_INSERT
- -- This procedure is like COMMAND_APPEND, but the input lines are inserted
- -- before the current line.
- --
- procedure COMMAND_INSERT is
- INLINE : LINE_STRING;
- begin
- INPUT_LINE_PROMPT; -- print prompt
- loop
- NUMBER_PREFIX (LINE_LIST.CURRENT_INDEX); -- print line number
- INLINE := INPUT_LINE; -- get new line
- exit when (INLINE (1) = LINE_EXIT_CHAR) and
- (INLINE (2) = ASCII.NUL); -- test for exit condition
- LINE_LIST.INSERT_ELEMENT (INLINE); -- perform insertion
- end loop;
- end COMMAND_INSERT;
-
- --===================================================================
- -- Procedure COMMAND_LIST
- -- This procedure lists a group of lines over a range. The range is
- -- indicated by the global variables LINE_START and LINE_STOP, which are
- -- set by the RANGE_INPUT routine and may be set by other routines as well.
- --
- procedure COMMAND_LIST is
- --Del Not needed I : NATURAL;
- DUMMY : BOOLEAN;
- begin
- COMMAND_GOTO (LINE_START); -- position at first line
- for I in 1 .. LINE_STOP - LINE_START + 1 loop
- -- over lines in range
- PREFIX_PRINT (LINE_LIST.CURRENT_INDEX,
- LINE_LIST.RETURN_CURRENT_ELEMENT); -- print line
- NEW_LINE;
- exit when not LINE_LIST.CURRENT_NEXT; -- adv to next line, check end
- -- of list and exit if done
- end loop;
- if LINE_STOP /= LINE_LIST.LAST_INDEX then
- DUMMY := LINE_LIST.CURRENT_PREVIOUS; -- back up, for we have
- -- gone too far
- end if;
- end COMMAND_LIST;
-
- --===================================================================
- -- Procedure COMMAND_DELETE
- -- This procedure deletes lines over the range from LINE_START to LINE_STOP.
- -- This range is a pair of global values which are set by RANGE_INPUT and
- -- possibly by other routines.
- --
- procedure COMMAND_DELETE is
- --Del Not needed I : NATURAL;
- DUMMY : BOOLEAN;
- begin
- COMMAND_GOTO (LINE_START); -- position to first line
- for I in 1 .. LINE_STOP - LINE_START + 1 loop
- LINE_LIST.DELETE_ELEMENT; -- delete current line
- end loop;
- end COMMAND_DELETE;
-
- --===================================================================
- -- COMMAND_SUBSTITUTE requires the following support routines, which are
- -- contained within this functional area.
- --
- -- ROUTINE FUNCTION
- -- SUB_STRING Determine if SUB_LINE is a substring of TARGET_LINE
- -- starting at position START_POS
- -- COUNT_CHARS Count the number of characters in the passed string,
- -- up to but not including the terminating ASCII.nul
- -- SUBSTITUTE Substitute NEW_STRING for OLD_STRING in TARGET_LINE
- -- starting at position FOUND_LOC (which is returned
- --
-
-
- --
- -->> Function SUB_STRING
- -- This function scans for the string SUB_LINE in the string TARGET_LINE
- -- starting at the position START_POS. Both strings are character sequences
- -- terminated by ASCII.nul. If found, SUB_STRING returns a positive number
- -- which is the index in TARGET_LINE of the first character of the substring
- -- SUB_LINE; the procedure SUBSTITUTE may be used to actually perform the
- -- substitution, given this return value. If not found, SUB_STRING returns
- -- the number 0.
- --
- function SUB_STRING (TARGET_LINE, SUB_LINE : LINE_STRING;
- START_POS : NATURAL) return NATURAL is
- FOUND_POS : NATURAL;
- TI : NATURAL; --!Cha SI was deleted (not used)
- ANSWER : BOOLEAN;
-
- begin
- --
- -- This initialization could have been done in the declarations above.
- -- Old habits (from Pascal) are sometimes hard to break.
- --
- TI := START_POS; -- set index in target line
- FOUND_POS := 0; -- initialize value to not found
- ANSWER := FALSE; -- ANSWER=TRUE if substring found
- --
- -- This is the major loop of SUB_STRING. It advances through the TARGET_LINE
- -- one character at a time, checking to see if SUB_LINE is duplicated in
- -- TARGET_LINE starting at the current position.
- --
- loop
- exit when TARGET_LINE (TI) = ASCII.NUL; -- done if at end of target
- --
- -- This is the minor loop of SUB_STRING. It advances through SUB_LINE,
- -- comparing each character in SUB_LINE to the corresponding (relative)
- -- character in TARGET_LINE until either the end of SUB_LINE is reached
- -- (in which case the substring has been found at TI, the current position
- -- in TARGET_LINE) or the current character in SUB_LINE does not match
- -- the current character in TARGET_LINE (in which case we advance to the
- -- next character in TARGET_LINE and try again if the end of TARGET_LINE
- -- has not been reached).
- --
- for SI in 1 .. LINE_LENGTH loop
- if SUB_LINE (SI) = ASCII.NUL then
- -- exit if complete match
- ANSWER := TRUE;
- exit;
- end if;
- exit when TARGET_LINE (TI + SI - 1) /= SUB_LINE (SI);
- end loop;
- --
- -- We are now out of the preceeding FOR loop. If ANSWER is TRUE, we got here
- -- from the IF, which means we found a match.
- --
- if ANSWER then
- FOUND_POS := TI; -- mark position in target line and ...
- exit; -- ... exit major loop
- end if;
- --
- -- We have not matched the SUB_LINE yet; advance to the next character in
- -- the TARGET_LINE.
- --
- TI := TI + 1; -- advance to next char in target line
- end loop;
- --
- -- If the substring was found, FOUND_POS is non-zero. If not, FOUND_POS
- -- still retains its original value of zero.
- --
- return (FOUND_POS);
-
- end SUB_STRING;
-
- --
- -->> Function COUNT_CHARS
- -- The following function determines the number of characters in the
- -- string (which is terminated by an ASCII.nul) passed to it. This
- -- character count does not include the terminating ASCII.nul.
- --
- function COUNT_CHARS (STR : LINE_STRING) return NATURAL is
- J, K : NATURAL; --!Cha declaration for I removed (not used)
- begin
- J := LINE_LENGTH + 1;
- K := 0;
- for I in 1 .. J loop
- exit when STR (I) = ASCII.NUL;
- K := I;
- end loop;
- return (K); -- the loop exits on the ASCII.nul
- exception
- when others => -- must have exceeded dimension of STR
- return (LINE_LENGTH);
- end COUNT_CHARS;
-
- --
- -->> Procedure SUBSTITUTE
- -- This procedure substitutes NEW_STRING for OLD_STRING in TARGET_LINE
- -- starting at the position indicated by FOUND_LOC. The value of FOUND_LOC
- -- was determined by the routine SUB_STRING and is assumed to be correct
- -- (ie, OLD_STRING starts at index FOUND_LOC in TARGET_LINE).
- --
- procedure SUBSTITUTE (TARGET_LINE : in out LINE_STRING;
- OLD_STRING, NEW_STRING : LINE_STRING;
- FOUND_LOC : in out NATURAL) is
-
- SIZE_NEW, SIZE_OLD, SIZE_TARGET : NATURAL;
- I, NEXT_CHAR : NATURAL;
- RETURN_LOC : NATURAL;
- TEMP_LINE : LINE_STRING;
-
- --
- -- This is the mainline of SUBSTITUTE
- --
- begin
- --
- -- Determine sizes of the three strings -- TARGET, OLD, and NEW
- --
- SIZE_TARGET := COUNT_CHARS (TARGET_LINE);
- SIZE_OLD := COUNT_CHARS (OLD_STRING);
- SIZE_NEW := COUNT_CHARS (NEW_STRING);
-
- --
- -- Copy the TARGET_LINE up to but not including the point of substitution
- --
- if FOUND_LOC /= 1 then
- TEMP_LINE (1 .. FOUND_LOC - 1) := TARGET_LINE (1 .. FOUND_LOC - 1);
- NEXT_CHAR := FOUND_LOC;
- else
- NEXT_CHAR := 1;
- end if;
-
- --
- -- Append the NEW_STRING to the end of the line being built
- --
- if SIZE_NEW /= 0 then
- for Tmp in 1 .. SIZE_NEW loop --!Cha I changed to Tmp
- TEMP_LINE (NEXT_CHAR) := NEW_STRING (Tmp);--!Cha ditto
- NEXT_CHAR := NEXT_CHAR + 1;
- end loop;
- end if;
-
- --
- -- Determine the index of the next character after the OLD_STRING in TARGET_LINE
- --
- I := FOUND_LOC + SIZE_OLD;
-
- --
- -- Append the characters after OLD_STRING in TARGET_LINE to the end of the
- -- line being built.
- --
- loop
- exit when TARGET_LINE (I) = ASCII.NUL;
- TEMP_LINE (NEXT_CHAR) := TARGET_LINE (I);
- NEXT_CHAR := NEXT_CHAR + 1;
- I := I + 1;
- end loop;
-
- --
- -- Fill out the rest of the line which is being built with ASCII.nul chars
- --
- for Tmp in NEXT_CHAR .. LINE_LENGTH loop --!Cha I changed to Tmp
- TEMP_LINE (Tmp) := ASCII.NUL; --!Cha I changed to Tmp
- end loop;
-
- --
- -- Replace the original TARGET_LINE with the line being built.
- -- Also return the position to resume the scan in the TARGET_LINE in case
- -- there is more than one occurrance of the substring.
- --
- TARGET_LINE := TEMP_LINE;
- FOUND_LOC := FOUND_LOC + SIZE_NEW;
-
- end SUBSTITUTE;
-
- --===================================================================
- -- Procedure COMMAND_SUBSTITUTE
- -- This procedure implements the Substitute command. The range of lines
- -- over which to perform the substitution is provided by RANGE_INPUT as
- -- the global variables LINE_START and LINE_STOP, and the string OLD_STRING
- -- contains the string to be substituted while the string NEW_STRING contains
- -- the string to substitute for OLD_STRING.
- --
- procedure COMMAND_SUBSTITUTE (OLD_STRING, NEW_STRING : LINE_STRING) is
- FOUND_LOC : NATURAL;
- TEMP_LINE : LINE_STRING;
- begin
- COMMAND_GOTO (LINE_START); -- goto first line in range
- FOUND_LOC := 1; -- start at position 1 in first line
-
- --
- -- Major loop for substitution. Each line is examined at least once, and,
- -- if a substitution is performed, the line is passed over again to see
- -- if the OLD_STRING occurrs in the line twice.
- --
- loop
- exit when LINE_LIST.CURRENT_INDEX > LINE_STOP;
- --
- -- See if OLD_STRING is contained in the current line.
- --
- FOUND_LOC := SUB_STRING
- (LINE_LIST.RETURN_CURRENT_ELEMENT, OLD_STRING,
- FOUND_LOC);
- --
- -- Replace OLD_STRING with NEW_STRING and look again after last character
- -- in NEW_STRING within the current line if found; reset starting position
- -- of search and advance to next line if not found.
- --
- if FOUND_LOC /= 0 then
- TEMP_LINE := LINE_LIST.RETURN_CURRENT_ELEMENT;
- SUBSTITUTE (TEMP_LINE, OLD_STRING, NEW_STRING, FOUND_LOC);
- LINE_LIST.RETURN_CURRENT_ELEMENT.CONTENT := TEMP_LINE;
- PREFIX_PRINT (LINE_LIST.CURRENT_INDEX,
- LINE_LIST.RETURN_CURRENT_ELEMENT);
- NEW_LINE;
- else
- FOUND_LOC := 1;
- exit when not LINE_LIST.CURRENT_NEXT;
- end if;
-
- end loop;
-
- end COMMAND_SUBSTITUTE;
-
- --===================================================================
- -- Procedure COMMAND_FIND
- -- This procedure implements the Find command. It searches for the passed
- -- string over a range of lines and stops at the first line in that range
- -- which contains the indicated string. LINE_START and LINE_STOP are
- -- global values set by RANGE_INPUT which indicate the indexes of the first
- -- and last lines in the range.
- --
- -- The routine SUB_STRING is used to determine if the passed string is
- -- contained in the current line.
- --
- procedure COMMAND_FIND (STR : LINE_STRING) is
- TEMP_LINE : LINE_STRING;
- I : NATURAL;
- begin
- COMMAND_GOTO (LINE_START); -- position at first line
- --
- -- Exit when String is found, else advance to next line
- --
- for Tmp in LINE_START .. LINE_STOP loop --!Cha I changed to Tmp
- TEMP_LINE := LINE_LIST.RETURN_CURRENT_ELEMENT;
- exit when SUB_STRING (TEMP_LINE, STR, 1) /= 0;
- exit when not LINE_LIST.CURRENT_NEXT; -- never hit this exit
- end loop;
- end COMMAND_FIND;
-
- --===================================================================
- -- File I/O Support Routines
- --
- -- This set of routines provides the basic support required to perform file
- -- input/output with the editor. These routines and their functions are:
- --
- -- ROUTINE FUNCTION
- -- WRITE_FLINE Write the current line to the output file
- -- PUT_RANGE Write a group of lines to the output file
- -- READ_FILE Read a file into the edit buffer after the
- -- current line
- --
-
- --
- -->> Procedure WRITE_FLINE
- -- This procedure writes the current line out to the file whose descriptor
- -- is passed as an argument. The number of characters in the line is first
- -- counted, and then TEXT_IO.PUT_LINE is used to write the line.
- --
- procedure WRITE_FLINE (LOC_FILE : Cais.TEXT_IO.FILE_TYPE) is
- LEN : NATURAL;
- begin
- LEN := COUNT_CHARS (LINE_LIST.RETURN_CURRENT_ELEMENT);
- Cais.TEXT_IO.PUT_LINE (LOC_FILE,
- LINE_LIST.RETURN_CURRENT_ELEMENT.CONTENT (1 .. LEN));
- end WRITE_FLINE;
-
- --
- -->> Procedure PUT_RANGE
- -- PUT_RANGE positions to the first line, indexed by START, and writes lines
- -- to the file via repeated calls to WRITE_FLINE until the line indexed by
- -- STOP is written.
- --
- procedure PUT_RANGE (FD : Cais.TEXT_IO.FILE_TYPE; START, STOP : NATURAL) is
- --!Del not used I : NATURAL;
- begin
- COMMAND_GOTO (START); -- position at first line
- for I in START .. STOP loop
- WRITE_FLINE (FD); -- write current line
- exit when not LINE_LIST.CURRENT_NEXT; -- advance to next line
- end loop;
- end PUT_RANGE;
-
- --
- -->> Procedure READ_FILE
- -- This procedure reads the file named by FILE_NAME into the edit buffer.
- -- If the file is not found and CREATE_FLAG is TRUE, an empty file is
- -- created; if the file is not found and CREATE_FLAG is FALSE, only an error
- -- message is issued.
- --
- procedure READ_FILE (FILE_NAME : STRING; CREATE_FLAG : BOOLEAN) is
- LOC_FILE : Cais.TEXT_IO.FILE_TYPE;
- INLINE : LINE_STRING;
- LEN : NATURAL;
-
- begin
- --
- -- Try to open the file for input. If this fails because the file is not
- -- found, the exception NAME_ERROR is raised.
- --
- --!Rem No change is required here except that CAIS.Text_IO.Open
- --!Rem has differing order of Parms than Text_IO.Open
- Cais.TEXT_IO.OPEN (LOC_FILE, File_Name, Cais.TEXT_IO.IN_FILE ); --!Cha
-
- --
- -- Append lines after the current line until the end of the input file is
- -- reached.
- --
- loop
- exit when Cais.TEXT_IO.END_OF_FILE (LOC_FILE);
- Cais.TEXT_IO.GET_LINE (LOC_FILE, INLINE, LEN);
- for I in LEN + 1 .. LINE_LENGTH loop
- INLINE (I) := ASCII.NUL;
- end loop;
- LINE_LIST.APPEND_ELEMENT (INLINE);
- end loop;
-
- --
- -- Close the Input File (generally, a good practice)
- --
- Cais.TEXT_IO.CLOSE (LOC_FILE);
-
- --
- -- Handle problems; the big problem to look for is when the file is not
- -- found (the exception NAME_ERROR is raised by TEXT_IO.OPEN).
- --
- exception
-
- when Cais.Node_Definitions.Name_Error =>
- --!Rem ^^^^^^^^^^^^^^^^ was Text_Io
- --
- -- If the CREATE_FLAG is TRUE, create an empty file; else, say that file
- -- was not found.
- --
- if CREATE_FLAG then
- --!Cha only change is order of Create parameters
- Cais.TEXT_IO.CREATE (LOC_FILE, File_Name, Cais.TEXT_IO.OUT_FILE);
- Cais.TEXT_IO.CLOSE (LOC_FILE);
- PUT ("New File");
- NEW_LINE;
- else
- PUT ("File not Found");
- NEW_LINE;
- end if;
-
- end READ_FILE;
-
-
- --===================================================================
- -- Procedure COMMAND_GET
- -- This procedure implements the Get command. The file indicated by the
- -- passed FILE_NAME is read into the edit buffer after the indicated line
- -- (if any).
- --
- procedure COMMAND_GET (FILE_NAME : LINE_STRING) is
- CURRENT_SAVE : NATURAL;
- DUMMY : BOOLEAN;
- FILE_NAME_LENGTH : NATURAL;
- begin
- FILE_NAME_LENGTH := FILE_NAME'LAST;
- for I in 1 .. FILE_NAME'LAST loop
- if FILE_NAME (I) = ASCII.NUL then
- FILE_NAME_LENGTH := I - 1;
- exit;
- end if;
- end loop;
- COMMAND_GOTO (LINE_START); -- position at indicated line
- CURRENT_SAVE := LINE_LIST.CURRENT_INDEX; -- save index of current line
- READ_FILE (FILE_NAME (1 .. FILE_NAME_LENGTH), FALSE); -- read file
- DUMMY := LINE_LIST.SET_CURRENT_INDEX (CURRENT_SAVE); -- restore current
- end COMMAND_GET;
-
- --===================================================================
- -- Procedure COMMAND_PUT
- -- This procedure implements the Put command. It writes out lines over
- -- the range from LINE_START to LINE_STOP (input via RANGE_INPUT) to the file
- -- named in the passed parameter.
- --
- procedure COMMAND_PUT (FILE_NAME : LINE_STRING) is
- LOC_FILE : Cais.TEXT_IO.FILE_TYPE;
- I : NATURAL;
- FILE_NAME_LENGTH : NATURAL;
-
- begin
- --
- -- Compute length of file name
- --
- FILE_NAME_LENGTH := FILE_NAME'LAST;
- for Tmp in 1 .. FILE_NAME'LAST loop --!Cha I changed to Tmp
- if FILE_NAME (Tmp) = ASCII.NUL then --!Cha I changed to Tmp
- FILE_NAME_LENGTH := Tmp - 1; --!Cha I changed to Tmp
- exit;
- end if;
- end loop;
- --
- -- Delete the original file, if any
- --
- --!Cha Only change is order of Open parameters
- Cais.TEXT_IO.OPEN (LOC_FILE, FILE_NAME (1 .. FILE_NAME_LENGTH),
- Cais.Text_Io.In_File);
- Cais.TEXT_IO.DELETE (LOC_FILE);
- --
- -- Create the new file
- --
- --!Cha Only change is order of Create parameters
- Cais.TEXT_IO.CREATE (LOC_FILE, FILE_NAME (1 .. FILE_NAME_LENGTH),
- Cais.Text_Io.Out_File);
-
- PUT_RANGE (LOC_FILE, LINE_START, LINE_STOP);
- Cais.TEXT_IO.CLOSE (LOC_FILE);
- --
- -- If the original file did not already exist, the above TEXT_IO.OPEN would
- -- have raised the exception NAME_ERROR. The following handler traps this
- -- and goes ahead to create the file and write to it.
- --
- exception
- when Cais.Node_Definitions.Name_Error =>
- --!Cha ^^^^^^^^^^^^^^^^ was Text_Io
-
- --!Cha Only change is order of Create parameters
- Cais.TEXT_IO.CREATE (LOC_FILE, FILE_NAME (1 .. FILE_NAME_LENGTH),
- Cais.Text_Io.Out_File);
-
- PUT_RANGE (LOC_FILE, LINE_START, LINE_STOP);
- Cais.Text_Io.Close (LOC_FILE);
-
- end COMMAND_PUT;
-
- --===================================================================
-
- end EDIT_WORKER;
- --::::::::::::::
- --edit_worker-spec.a
- --::::::::::::::
- -- Package EDIT_WORKER
- -- Written by Richard Conn, TI Ada Technology Branch
- -- Version 2.0, Date 31 Jan 85
- -- Version 2.1, Date 15 Feb 85
- -- CAIS Version 3.0, 21 August 85
- -- CAIS Version 3.1, 13 Feb 86
- -- NB: changes for the CAIS port are indicated by one of the
- -- following on each affected line:
- -- --!Rem Comments, remarks
- -- --!Add Lines added to the code
- -- --!Del Lines deleted from the code
- -- --!Cha Lines changed in the code
- -- (It is a bit subjective; when does a big change become
- -- a delete and an add ?)
- --
-
- --!Del with TEXT_IO; ?Not used in the Specification of this package
- with EDIT_SUPPORT;
- use EDIT_SUPPORT;
- package EDIT_WORKER is
-
- --
- -- EDIT_WORKER is the set of procedures which implement the various
- -- commands available through the EDITOR. These are the workhorse
- -- routines.
- --
-
- --===================================================================
- --
- -- The following global data buffers are used by several of the routines.
- -- LINE_START and LINE_STOP are the numbers of the lines indicated by
- -- input to RANGE_INPUT, and these values are set by RANGE_INPUT and read
- -- by the routines which call RANGE_INPUT. The exception RANGE_ERROR indicates
- -- if there is an error in the input values received from RANGE_INPUT.
- --
- LINE_START, LINE_STOP : NATURAL;
- RANGE_ERROR : exception;
-
- --===================================================================
- --
- -- Procedure RANGE_INPUT
- --
- -- RANGE_INPUT is used to input a range specification of the following
- -- forms:
- -- x -- reference a single line or one of the special ranges
- -- x,x -- reference a group of lines
- -- x x -- reference a group of lines (same as x,x)
- --
- -- A single line reference may be any of the following:
- --
- -- # -- a line number, such as 1, 245, etc
- -- +# -- the line which is n lines after the current line, such as +23
- -- -# -- the line which is n lines before the current line, such as -45
- -- A -- all lines in the file
- -- C -- the current line
- -- F -- the first line
- -- L -- the last line
- -- P -- 20 consecutive lines, starting at the current line
- --
- -- A group of lines may be referenced by any combination of the following:
- --
- -- # +# -# C F L
- --
- -- If the first entry of the pair references a line which is after the
- -- line referenced by the second entry of the pair, then the RANGE_ERROR
- -- flag will be raised.
- --
- -- EXCEPTIONS RAISED: RANGE_ERROR
- --
- -- SIDE EFFECTS:
- -- The values of LINE_START and LINE_STOP are always set. If an error
- -- is encountered, RANGE_ERROR is raised (error message is also printed).
- --
-
- procedure RANGE_INPUT;
-
-
- --===================================================================
- --
- -- The following routines return the indexes (natural numbers) of
- -- the current and last lines (CURRENT_LINE, LAST_LINE) and advance
- -- to the next line or backup to the previous line (ADVANCE_LINE,
- -- BACKUP_LINE)
- --
-
- function CURRENT_LINE return NATURAL;
- function LAST_LINE return NATURAL;
- procedure ADVANCE_LINE;
- procedure BACKUP_LINE;
-
-
- --===================================================================
- --
- -- The following file read routine is used to read the initial
- -- file when the editor starts up
- --
-
- procedure READ_FILE (FILE_NAME : STRING; CREATE_FLAG : BOOLEAN);
-
-
-
- --===================================================================
- --
- -- The following routines implement the indicated commands:
- --
- -- ROUTINE NAME COMMAND MEANING OF COMMAND
- -- initialize_edit Initialize the Editor
- -- command_append A Append Lines After Current Line
- -- command_delete D Delete One or More Lines
- -- command_find F Search for String
- -- command_get G Read in File after Current Line
- -- command_goto J Jump to (Position to) Indicated Line
- -- command_insert I Insert Lines Before Current line
- -- command_list L List One or More Lines
- -- command_put P Write Out Range of Lines to File
- -- command_substitute S Substitute Strings in One or More Lines
- --
-
- procedure INITIALIZE_EDIT;
-
- procedure COMMAND_APPEND;
-
- procedure COMMAND_DELETE;
-
- procedure COMMAND_FIND (STR : EDIT_SUPPORT.LINE_STRING);
-
- procedure COMMAND_GET (FILE_NAME : EDIT_SUPPORT.LINE_STRING);
-
- procedure COMMAND_GOTO (NUM : NATURAL);
-
- procedure COMMAND_INSERT;
-
- procedure COMMAND_LIST;
-
- procedure COMMAND_PUT (FILE_NAME : EDIT_SUPPORT.LINE_STRING);
-
- procedure COMMAND_SUBSTITUTE
- (OLD_STRING, NEW_STRING : EDIT_SUPPORT.LINE_STRING);
-
- --===================================================================
-
- end EDIT_WORKER;
-
- --::::::::::::::
- --editor.a
- --::::::::::::::
- -------- SIMTEL20 Ada Software Repository Prologue ------------
- -- -*
- -- Unit name : EDITOR (ALED - Ada Line Editor)
- -- Version : 3.1
- -- Author : Richard Conn
- -- : Texas Instruments
- -- : PO Box 801, MS 8007
- -- : McKinney, TX 75069
- -- DDN Address : RCONN at SIMTEL20
- -- Copyright : (c) 1984, 1985 Richard Conn
- -- Date created : 9 Nov 84
- -- Release date : 5 Dec 84
- -- Last update : 13 Feb 86
- -- Machine/System Compiled/Run on : VAX 8600 ULTRIX, Sun2 UNIX 4.2
- -- : All system-specific features are isolated in
- -- : the package SYSDEP, so I believe
- -- : that the editor is transportable between a
- -- : a wide variety of environments; I encountered
- -- : a number of "surprises" when I programmed the
- -- : editor, and I don't know if they were caused
- -- : by the ROLM ADE implementation of TEXT_IO or if
- -- : they were intentional; see the documentation
- -- -*
- ---------------------------------------------------------------
- -- -*
- -- Keywords : EDITOR
- ----------------: LINE-ORIENTED EDITOR
- ----------------: INPUT-LINE EDITOR
- --
- -- Abstract : ALED - Ada Line Editor
- ----------------: A Line-Oriented File Editor Written in Ada
- ----------------: by Richard Conn
- ----------------:
- ----------------: ALED is designed to edit text files. Upon invocation,
- ----------------: ALED prompts the user for a file name. If the file
- ----------------: exists, its contents (lines) are read in and prepared
- ----------------: for editing; if the file does not exist, the file is
- ----------------: created and the empty buffer is prepared for editing.
- ----------------: ALED is an interactive editor, accepting single-char
- ----------------: commands, filling in a command prompt (for more info
- ----------------: as needed), and performing its functions in real-time
- ----------------: while the user watches. The functions provided include
- ----------------: (but are not limited to) the following:
- ----------------:
- ----------------: * List Lines
- ----------------: * Insert a Group of Lines into the Edit Buffer
- ----------------: * Delete Lines
- ----------------: * String Search and String Substitution
- ----------------: * Movement Within the Edit Buffer
- ----------------: * Reading in a File After a Specified Line
- ----------------: * Writing out a Range of Lines to a File
- ----------------: * Built-in, online Documentation (Summary)
- ----------------:
- ----------------: ALED's design includes an input line editor, which allows
- ----------------: the user to edit text as he types it. I was surprised
- ----------------: NOT to find such a basic function available in TEXT_IO.
- ----------------: Did I miss something?
- ----------------:
- ----------------: ALED is divided into the following files. The order
- ----------------: in which they are listed is the compilation order.
- ----------------:
- ----------------: SIMTEL20 Ada Package/Procedure Comments
- ----------------:
- ----------------: SYSDEP.ADA sysdep Components library
- ----------------: of single-character
- ----------------: I/O routines
- ----------------:
- ----------------: LIST.ADA editor_list Components library
- ----------------: of linked-list routines
- ----------------:
- ----------------: ED-SPT.ADA edit_support Visible section
- ----------------: of editor support
- ----------------: package (which contains
- ----------------: a few basic routines,
- ----------------: such as the input line
- ----------------: editor)
- ----------------:
- ----------------: ED-SPTB.ADA edit_support Body of editor support
- ----------------: package
- ----------------:
- ----------------: ED-WRK.ADA edit_worker Visible seciton of
- ----------------: workhorse routines
- ----------------: for the editor;
- ----------------: all major editor
- ----------------: functions and their
- ----------------: related support
- ----------------: routines are here
- ----------------: (such as list lines)
- ----------------:
- ----------------: ED-WRKB.ADA edit_worker Body of editor
- ----------------: workhorse routines
- ----------------:
- ----------------: ED.ADA editor Mainline of ALED
- ----------------:
- ----------------:
- -- -*
- ------------------ Revision history ---------------------------
- -- -*
- -- DATE VERSION AUTHOR HISTORY
- -- 12/5/84 1.0 Richard Conn Initial Release
- -- 1/21/85 2.0 Richard Conn Production version
- -- 2/15/85 2.1 Richard Conn Minor bug fix
- -- 8/21/85 3.0 Chuck Howell Port to CAIS
- -- 2/13/86 3.1 Chuck Howell Change CAIS Version
- -- NB: changes for the CAIS port are indicated by one of the following
- -- on each affected line:
- -- --!Rem Comments, remarks
- -- --!Add Lines added to the code
- -- --!Del Lines deleted from the code
- -- --!Cha Lines changed in the code
- -- (It is a bit subjective; when does a big change become
- -- a delete and an add ?)
- -- -*
- ------------------ Distribution and Copyright -----------------
- -- -*
- -- This prologue must be included in all copies of this software.
- --
- -- This software is copyright by the author.
- --
- -- This software is released to the Ada community.
- -- This software is released to the Public Domain (note:
- -- software released to the Public Domain is not subject
- -- to copyright protection).
- -- Restrictions on use or distribution: NONE
- -- -*
- ------------------ Disclaimer ---------------------------------
- -- -*
- -- This software and its documentation are provided "AS IS" and
- -- without any expressed or implied warranties whatsoever.
- -- No warranties as to performance, merchantability, or fitness
- -- for a particular purpose exist.
- --
- -- Because of the diversity of conditions and hardware under
- -- which this software may be used, no warranty of fitness for
- -- a particular purpose is offered. The user is advised to
- -- test the software thoroughly before relying on it. The user
- -- must assume the entire risk and liability of using this
- -- software.
- --
- -- In no event shall any person or organization of people be
- -- held responsible for any direct, indirect, consequential
- -- or inconsequential damages or lost profits.
- -- -*
- -------------------END-PROLOGUE--------------------------------
-
- --
- -- MAIN BODY OF ALED -- Ada Line Editor
- -- Program Written by Richard Conn, TI Ada Technology Branch
- -- Completion Date: 12/5/84
- -- Completion Date of 2.0: 1/31/85
- -- Completion Date of 2.1: 2/15/85
- --
-
- --
- -- The following packages are used throughout the editor and constitute
- -- a set of basic support functions.
- --
- with --!Cha TEXT_IO, used only for Integer_IO.
- EDIT_SUPPORT,
- EDIT_WORKER;
- use EDIT_SUPPORT, EDIT_WORKER;
-
- --
- -- This is the main body of the editor
- --
- procedure EDITOR is
- --!Del package NUM_IO is new TEXT_IO.INTEGER_IO (NATURAL);
- --!Rem the use of version number, integer division, mod, and Integer_IO
- --!Rem to print a version has been replaced by a string constant
- --!Rem representing the current version.
- --!Del VERSION_NUMBER : constant := 21; -- major=2, minor=1
- VERSION : constant String := "(MITRE CAIS) 3.1"; --!Add
- EDIT_FILE : LINE_STRING;
- FILE_NAME_LENGTH : NATURAL;
- NEW_STRING : LINE_STRING;
- SSTRING : LINE_STRING;
- DONE : BOOLEAN;
- RESP_CHAR, CMD_CHAR : CHARACTER;
-
- --
- -- HELP_SUMMARY prints a summary of commands to the user
- --
- procedure HELP_SUMMARY is
- begin
- NEW_LINE;
- NEW_LINE;
- PUT ("--- Movement Commands --- ");
- PUT ("----- Enter Lines -----");
- NEW_LINE;
- PUT (" + Advance N Lines ");
- PUT (" A Append after <line> ");
- NEW_LINE;
- PUT (" - Back Up N Lines ");
- PUT (" I Insert before <line>");
- NEW_LINE;
- PUT (" F Find <string> in <range>");
- PUT (" ");
- NEW_LINE;
- PUT (" J Jump to <line> ");
- PUT ("----- Print Lines -----");
- NEW_LINE;
- PUT (" N Find Next <string> ");
- PUT (" . Print Current Line ");
- NEW_LINE;
- PUT ("----- Delete Command ----- ");
- PUT (" < Print Next Line ");
- NEW_LINE;
- PUT (" D Delete lines in <range> ");
- PUT (" > Print Next Line ");
- NEW_LINE;
- PUT (" ");
- PUT (" L List over <range> ");
- NEW_LINE;
- PUT ("---- Help and Exits ---- ");
- PUT (" ");
- NEW_LINE;
- PUT (" H This Help Text ");
- PUT ("---- Substitution ---- ");
- NEW_LINE;
- PUT (" Q Quit without Updating ");
- PUT (" S String Substitute ");
- NEW_LINE;
- PUT (" X Exit and Update ");
- PUT (" over <range> ");
- NEW_LINE;
- NEW_LINE;
- PUT ("---- File Get/Put ---- ");
- PUT ("-- Miscellaneous -- ");
- NEW_LINE;
- PUT (" G Get <file> after <line> ");
- PUT (" ? Print Statistics ");
- NEW_LINE;
- PUT (" P Put <file> over <range> ");
- PUT (" ");
- NEW_LINE;
- NEW_LINE;
- PUT ("<Range>: % %,%");
- NEW_LINE;
- PUT ("First or Second Entries --");
- NEW_LINE;
- PUT (" #-Number, .-Current, C-Current, F-First,");
- PUT (" L-Last");
- NEW_LINE;
- PUT ("Singular Entries --");
- NEW_LINE;
- PUT (" A-All, P-Page");
- NEW_LINE;
- end HELP_SUMMARY;
-
- --
- -- HELP prints help information to the user
- --
- procedure HELP (INCHAR : CHARACTER) is
- begin
- NEW_LINE;
- case INCHAR is
- when 'c' | 'C' =>
- PUT ("Command Names:");
- NEW_LINE;
- PUT ("+ (Advance) - (Backup) . (Current)");
- NEW_LINE;
- PUT ("< (Previous) > (Next) ? (Statistics)");
- NEW_LINE;
- PUT ("Append Delete Find Get Help Insert");
- NEW_LINE;
- PUT ("Jump List Next Put Quit Substitute");
- NEW_LINE;
- PUT ("X(Exit)");
- NEW_LINE;
- when 'n' | 'N' =>
- PUT ("Number Values:");
- NEW_LINE;
- PUT (". or C Current Line");
- NEW_LINE;
- PUT (" F First Line");
- NEW_LINE;
- PUT (" L Last Line");
- NEW_LINE;
- PUT (" 25 Absolute Line Number");
- NEW_LINE;
- PUT ("+7 or -5 Relative Line Number");
- NEW_LINE;
- PUT (" A All Lines in File (only one argument)");
- NEW_LINE;
- PUT (" P Next Page of Lines (only one argument)");
- NEW_LINE;
- when 's' | 'S' =>
- HELP_SUMMARY;
- when others =>
- null;
- end case;
- end HELP;
-
- --
- -- The mainline of the editor
- --
- begin
- INITIALIZE_EDIT; -- initialize the Worker Functions
- CONSOLE_INIT; -- initialize the console
- --
- PUT ("ALED - Ada Line Editor by Richard Conn, Version ");
- --!Rem See comment above re use of Version string vs. Version_Number
- Put (Version); --!Add
- --!Del NUM_IO.PUT (VERSION_NUMBER / 10, 2);
- --!Del PUT (".");
- --!Del NUM_IO.PUT (VERSION_NUMBER mod 10, 1);
- NEW_LINE;
- --
- -- Enter File Name and Trap All Exceptions as File Name Errors
- --
- loop
- begin
- PUT ("File Name? ");
- EDIT_FILE := INPUT_LINE;
- SSTRING := EDIT_FILE; -- initial value for SSTRING
- FILE_NAME_LENGTH := EDIT_FILE'LAST;
- for I in 1 .. EDIT_FILE'LAST loop
- if EDIT_FILE (I) = ASCII.NUL then
- FILE_NAME_LENGTH := I - 1;
- exit;
- end if;
- end loop;
- READ_FILE (EDIT_FILE (1 .. FILE_NAME_LENGTH), TRUE);
- exit; -- no exceptions raised
- exception
- when others =>
- NEW_LINE;
- PUT ("File Name Error -- ");
- end;
- end loop;
- --
- --!Del NUM_IO.PUT (LAST_LINE, 5);
- Put (Integer'image (Last_Line)); --!Add
- PUT (" Lines in File");
- --
- COMMAND_GOTO (1); -- position at first line
- NEW_LINE;
- PUT (" Type H for Help");
- DONE := FALSE; -- this flag indicates when the editor is to be exited
- NEW_LINE;
- --
- loop
- begin
- exit when DONE;
- --
- -- Print Prompt to User and Get Single-Char Command
- --
- --!del NUM_IO.PUT (CURRENT_LINE, 5);
- Put (Integer'image (Current_Line)); --!Add
- PUT ("> ");
- CMD_CHAR := GETCH; -- input command character without echo
- --
- -- Process Single-Char Commands
- --
- case CMD_CHAR is
- --
- -- Null Commands (Just Echo New Line)
- --
- when ASCII.CR | ASCII.DEL | ASCII.BS =>
- NEW_LINE;
- --
- -- Print Current Line
- --
- when '.' =>
- NEW_LINE; -- no prompt
- LINE_START := CURRENT_LINE; -- list lines over current line
- LINE_STOP := CURRENT_LINE;
- COMMAND_LIST;
- --
- -- Backup and Print Previous Line
- --
- when '<' =>
- NEW_LINE; -- no prompt
- if CURRENT_LINE >= 1 then
- -- trap errors
- BACKUP_LINE;
- end if;
- LINE_START := CURRENT_LINE; -- list current line
- LINE_STOP := LINE_START;
- COMMAND_LIST;
- --
- -- Advance and Print Next Line
- --
- when '>' =>
- NEW_LINE; -- no prompt
- if CURRENT_LINE < LAST_LINE then
- -- trap errors
- ADVANCE_LINE;
- end if;
- LINE_START := CURRENT_LINE; -- list current line
- LINE_STOP := LINE_START;
- COMMAND_LIST;
- --
- -- Advance N Lines
- --
- when '+' =>
- PUT ("Advance N Lines <line count>");
- RANGE_INPUT; -- pay attention to 1st value
- if CURRENT_LINE + LINE_START <= LAST_LINE then
- COMMAND_GOTO (CURRENT_LINE + LINE_START);
- else
- COMMAND_GOTO (LAST_LINE);
- end if;
- --
- -- Backup N Lines
- --
- when '-' =>
- PUT ("Back Up N Lines <line count>");
- RANGE_INPUT; -- pay attention to 1st value
- if CURRENT_LINE - LINE_START < 1 then
- COMMAND_GOTO (1);
- else
- COMMAND_GOTO (CURRENT_LINE - LINE_START);
- end if;
- --
- -- Print Status Info
- --
- when '?' =>
- NEW_LINE; -- no prompt
- PUT (" Edit File Name: ");
- OUTPUT_LINE (EDIT_FILE);
- NEW_LINE;
- PUT (" ");
- --!Del NUM_IO.PUT (LAST_LINE, 5);
- Put (Integer'image(Last_Line)); --!Add
- PUT (" Lines in File");
- NEW_LINE;
- --
- -- Append a Group of Lines after the Indicated Line
- --
- when 'a' | 'A' =>
- PUT ("Append after <line>");
- RANGE_INPUT; -- 1 or 2 args used
- if not BLANK_INPUT then
- -- abort if no input
- COMMAND_GOTO (LINE_START);
- COMMAND_APPEND;
- end if;
- --
- -- Delete a Group of Lines
- --
- when 'd' | 'D' =>
- PUT ("Delete lines in <range>");
- RANGE_INPUT; -- 1 or 2 args used
- if not BLANK_INPUT then
- -- abort if no input
- COMMAND_DELETE;
- end if;
- --
- -- Find the First Occurrance of a String over a Range of Lines
- --
- when 'f' | 'F' =>
- PUT ("Find <string> ");
- SSTRING := INPUT_LINE;
- PUT (" over <range>");
- RANGE_INPUT; -- abort if no range input
- if not BLANK_INPUT then
- COMMAND_FIND (SSTRING);
- LINE_START := CURRENT_LINE;
- LINE_STOP := LINE_START;
- COMMAND_LIST;
- end if;
- --
- -- Load File into Current File After Indicated Line
- --
- when 'g' | 'G' =>
- PUT ("Get <file> ");
- SSTRING := INPUT_LINE;
- if not BLANK_INPUT then
- -- abort if no input
- PUT (" after <line>");
- RANGE_INPUT;
- if not BLANK_INPUT then
- COMMAND_GET (SSTRING);
- end if;
- end if;
- --
- -- Print Help Message
- --
- when 'h' | 'H' =>
- PUT ("Help on the Following:");
- NEW_LINE;
- PUT (" ");
- PUT ("C - Command Names, N - Numbering, S - Summary > ");
- RESP_CHAR := GETCH_WITH_ECHO;
- HELP (RESP_CHAR); -- help routine above
- --
- -- Insert a Group of Lines Before the Indicated Line
- --
- when 'i' | 'I' =>
- PUT ("Insert before <line>");
- RANGE_INPUT;
- if not BLANK_INPUT then
- -- abort if no input
- COMMAND_GOTO (LINE_START);
- COMMAND_INSERT;
- end if;
- --
- -- Jump to a line
- --
- when 'j' | 'J' =>
- PUT ("Jump to <line>");
- RANGE_INPUT;
- if not BLANK_INPUT then
- -- abort if no input
- COMMAND_GOTO (LINE_START);
- end if;
- --
- -- List a Group of Lines Over a Range
- --
- when 'l' | 'L' =>
- PUT ("List Lines in <range>");
- RANGE_INPUT;
- if not BLANK_INPUT then
- -- abort if no input
- COMMAND_LIST;
- end if;
- --
- -- Find Next Occurrance of String
- --
- when 'n' | 'N' =>
- PUT ("Next Occurrance of <string> ");
- NEW_STRING := INPUT_LINE; -- get string
- if BLANK_INPUT then
- -- if no input
- NEW_STRING := SSTRING; -- use old string
- end if;
- LINE_START := CURRENT_LINE + 1; -- start at next line
- LINE_STOP := LAST_LINE;
- if LINE_START > LINE_STOP then
- LINE_START := LINE_STOP;
- end if;
- SSTRING := NEW_STRING; -- set old string
- COMMAND_FIND (SSTRING); -- search
- LINE_START := CURRENT_LINE; -- mark place and print
- LINE_STOP := LINE_START;
- COMMAND_LIST;
- --
- -- Write a Group of Lines Out to a File
- --
- when 'p' | 'P' =>
- PUT ("Put <file> ");
- SSTRING := INPUT_LINE;
- if not BLANK_INPUT then
- -- abort if no input
- PUT (" over <range>");
- RANGE_INPUT;
- if not BLANK_INPUT then
- COMMAND_PUT (SSTRING);
- end if;
- end if;
- --
- -- Quit -- Exit Editor and Throw Away Contents
- --
- when 'q' | 'Q' =>
- PUT ("Quit without File Update (Y/N)? ");
- RESP_CHAR := GETCH_WITH_ECHO;
- if RESP_CHAR = 'y' or RESP_CHAR = 'Y' then
- DONE := TRUE;
- end if;
- NEW_LINE; -- CRLF is good, indicates activity
- --
- -- Substitute One String for Another Over a Range
- --
- when 's' | 'S' =>
- PUT ("Substitute for Old <string> ");
- SSTRING := INPUT_LINE;
- if not BLANK_INPUT then
- -- abort if no input
- PUT (" New <string> ");
- NEW_STRING := INPUT_LINE;
- PUT (" over <range>");
- RANGE_INPUT;
- if not BLANK_INPUT then
- COMMAND_SUBSTITUTE (SSTRING, NEW_STRING);
- end if;
- end if;
- --
- -- Exit Editor and Update File
- --
- when 'x' | 'X' =>
- PUT ("Exit and Update File (Y/N)? ");
- RESP_CHAR := GETCH_WITH_ECHO;
- if RESP_CHAR = 'y' or RESP_CHAR = 'Y' then
- DONE := TRUE;
- end if;
- NEW_LINE; -- CRLF shows activity
- --
- -- Invalid Command
- --
- when others =>
- PUT ("Error");
- NEW_LINE;
- end case;
- --
- -- Exception Handlers
- --
- exception
- when RANGE_ERROR =>
- NEW_LINE;
- when others =>
- NEW_LINE;
- PUT (" Unknown Error Trapped");
- NEW_LINE;
- --
- end;
- -- command body
- --
- end loop;
-
- --
- -- Write File on Exit
- --
- if CMD_CHAR = 'x' or CMD_CHAR = 'X' then
- LINE_START := 1; -- write file on way out
- LINE_STOP := LAST_LINE;
- COMMAND_PUT (EDIT_FILE);
- end if;
- --
- CONSOLE_DEINIT; -- deinitialize the console
- --
- end EDITOR;
-
-
- --::::::::::::::
- --editor.pro
- --::::::::::::::
- -------- SIMTEL20 Ada Software Repository Prologue ------------
- -- -*
- -- Unit name : EDITOR (ALED - Ada Line Editor)
- -- Version : 3.1
- -- Author : Richard Conn
- -- : Texas Instruments
- -- : PO Box 801, MS 8007
- -- : McKinney, TX 75069
- -- DDN Address : RCONN at SIMTEL20
- -- Copyright : (c) 1984, 1985 Richard Conn
- -- Date created : 9 Nov 84
- -- Release date : 5 Dec 84
- -- Last update : 13 Feb 86
- -- Machine/System Compiled/Run on : VAX 8600 ULTRIX, Sun2 UNIX 4.2
- -- -*
- ---------------------------------------------------------------
- -- -*
- -- Keywords : EDITOR
- ----------------: LINE-ORIENTED EDITOR
- ----------------: INPUT-LINE EDITOR
- --
- -- Abstract : ALED - Ada Line Editor
- ----------------: A Line-Oriented File Editor Written in Ada
- ----------------: by Richard Conn
- ----------------:
- ----------------: ALED is designed to edit text files. Upon invocation,
- ----------------: ALED prompts the user for a file name. If the file
- ----------------: exists, its contents (lines) are read in and prepared
- ----------------: for editing; if the file does not exist, the file is
- ----------------: created and the empty buffer is prepared for editing.
- ----------------: ALED is an interactive editor, accepting single-char
- ----------------: commands, filling in a command prompt (for more info
- ----------------: as needed), and performing its functions in real-time
- ----------------: while the user watches. The functions provided include
- ----------------: (but are not limited to) the following:
- ----------------:
- ----------------: * List Lines
- ----------------: * Insert a Group of Lines into the Edit Buffer
- ----------------: * Delete Lines
- ----------------: * String Search and String Substitution
- ----------------: * Movement Within the Edit Buffer
- ----------------: * Reading in a File After a Specified Line
- ----------------: * Writing out a Range of Lines to a File
- ----------------: * Built-in, online Documentation (Summary)
- ----------------:
- ----------------: ALED's design includes an input line editor, which allows
- ----------------: the user to edit text as he types it. I was surprised
- ----------------: NOT to find such a basic function available in TEXT_IO.
- ----------------: Did I miss something?
- ----------------:
- ----------------: ALED is divided into the following files. The order
- ----------------: in which they are listed is the compilation order.
- ----------------:
- ----------------: SIMTEL20 Ada Package/Procedure Comments
- ----------------:
- ----------------: LIST.ADA generic_list Components library
- ----------------: of linked-list routines
- ----------------:
- ----------------: ED-SPT.ADA edit_support Visible section
- ----------------: of editor support
- ----------------: package (which contains
- ----------------: a few basic routines,
- ----------------: such as the input line
- ----------------: editor)
- ----------------:
- ----------------: ED-SPTB.ADA edit_support Body of editor support
- ----------------: package
- ----------------:
- ----------------: ED-WRK.ADA edit_worker Visible seciton of
- ----------------: workhorse routines
- ----------------: for the editor;
- ----------------: all major editor
- ----------------: functions and their
- ----------------: related support
- ----------------: routines are here
- ----------------: (such as list lines)
- ----------------:
- ----------------: ED-WRKB.ADA edit_worker Body of editor
- ----------------: workhorse routines
- ----------------:
- ----------------: ED.ADA editor Mainline of ALED
- ----------------:
- ----------------:
- -- -*
- ------------------ Revision history ---------------------------
- -- -*
- -- DATE VERSION AUTHOR HISTORY
- -- 12/5/84 1.0 Richard Conn Initial Release
- -- 1/21/85 2.0 Richard Conn Production version
- -- 2/15/85 2.1 Richard Conn Minor bug fix
- -- 8/21/85 3.0 Chuck Howell Port to CAIS
- -- 2/13/86 3.1 Chuck Howell Change CAIS Version
- -- NB: changes for the CAIS port are indicated by one of the following
- -- on each affected line:
- -- --!Rem Comments, remarks
- -- --!Add Lines added to the code
- -- --!Del Lines deleted from the code
- -- --!Cha Lines changed in the code
- -- (It is a bit subjective; when does a big change become
- -- a delete and an add ?)
- -- -*
- ------------------ Distribution and Copyright -----------------
- -- -*
- -- This prologue must be included in all copies of this software.
- --
- -- This software is copyright by the author.
- --
- -- This software is released to the Ada community.
- -- This software is released to the Public Domain (note:
- -- software released to the Public Domain is not subject
- -- to copyright protection).
- -- Restrictions on use or distribution: NONE
- -- -*
- ------------------ Disclaimer ---------------------------------
- -- -*
- -- This software and its documentation are provided "AS IS" and
- -- without any expressed or implied warranties whatsoever.
- -- No warranties as to performance, merchantability, or fitness
- -- for a particular purpose exist.
- --
- -- Because of the diversity of conditions and hardware under
- -- which this software may be used, no warranty of fitness for
- -- a particular purpose is offered. The user is advised to
- -- test the software thoroughly before relying on it. The user
- -- must assume the entire risk and liability of using this
- -- software.
- --
- -- In no event shall any person or organization of people be
- -- held responsible for any direct, indirect, consequential
- -- or inconsequential damages or lost profits.
- -- -*
- -------------------END-PROLOGUE--------------------------------
- --::::::::::::::
- --editor_list.a
- --::::::::::::::
-
- -------- SIMTEL20 Ada Software Repository Prologue ------------
- -- -*
- -- Unit name : generic package EDITOR_LIST
- -- Version : 1.1
- -- Author : Richard Conn
- -- : Texas Instruments
- -- : PO Box 801, Mail Stop 8007
- -- : McKinney, TX 75069
- -- DDN Address : RCONN@SIMTEL20
- -- Copyright : (c) 1984 Richard Conn
- -- Date created : OCTOBER 2, 1984
- -- Release date : NOVEMBER 29, 1984
- -- Last update : C. Howell August 21, 1985
- -- (renamed to Editor_List only).
- -- -*
- ---------------------------------------------------------------
- -- -*
- -- Keywords : DOUBLY-LINKED LIST
- ----------------: LIST MANIPULATION
- --
- -- Abstract : This package provides a number of routines
- ----------------: which can be used to manipulate a doubly-
- ----------------: linked list. See the visible section for
- ----------------: a rather complete set of documentation on
- ----------------: the routines.
- ----------------:
- ----------------: Each element of the list is of the following
- ----------------: structure:
- ----------------: RECORD
- ----------------: contents: element_object; -- data
- ----------------: next: element_pointer; -- ptr
- ----------------: previous: element_pointer; -- ptr
- ----------------: END RECORD;
- ----------------:
- -- -*
- ------------------ Revision history ---------------------------
- -- -*
- -- DATE VERSION AUTHOR HISTORY
- -- 11/29/84 1.0 Richard Conn Initial Release
- -- 08/21/85 1.1 Chuck Howell Renamed to Editor_List
- -- -*
- ------------------ Distribution and Copyright -----------------
- -- -*
- -- This prologue must be included in all copies of this software.
- --
- -- This software is copyright by the author.
- --
- -- This software is released to the Ada community.
- -- This software is released to the Public Domain (note:
- -- software released to the Public Domain is not subject
- -- to copyright protection).
- -- Restrictions on use or distribution: NONE
- -- -*
- ------------------ Disclaimer ---------------------------------
- -- -*
- -- This software and its documentation are provided "AS IS" and
- -- without any expressed or implied warranties whatsoever.
- -- No warranties as to performance, merchantability, or fitness
- -- for a particular purpose exist.
- --
- -- Because of the diversity of conditions and hardware under
- -- which this software may be used, no warranty of fitness for
- -- a particular purpose is offered. The user is advised to
- -- test the software thoroughly before relying on it. The user
- -- must assume the entire risk and liability of using this
- -- software.
- --
- -- In no event shall any person or organization of people be
- -- held responsible for any direct, indirect, consequential
- -- or inconsequential damages or lost profits.
- -- -*
- -------------------END-PROLOGUE--------------------------------
-
- --
- -- Generic Package to Handle Doubly-Linked Lists
- -- by Richard Conn, TI Ada Technology Branch
- --
- -- The purpose of this package is to provide a software component
- -- which can be generically instantiated to handle any type of
- -- doubly-linked list. The set of routines provided in this package
- -- are general-purpose in nature and manipulate the elements of a
- -- doubly-linked list without regard to their contents. Each element
- -- of the list is of the following structure:
- --
- -- record
- -- content : element_object; -- the data in the list element
- -- next : element_pointer; -- pointer to the next element
- -- previous : element_pointer; -- pointer to the previous element
- -- end record;
- --
-
- generic
- type element_object is private;
-
-
- package Editor_List is
-
- --
- -- The following type declarations are used throughout is package
- -- and are needed by the programs which WITH this package.
- --
-
- type list_element;
- type element_pointer is access list_element;
- type list_element is
- record
- content : element_object; -- the generic object
- next : element_pointer;
- previous : element_pointer;
- end record;
-
-
- --
- -- The following procedures and functions initialize the list and
- -- return pointers to the three list elements which are continuously
- -- tracked by the routines in this package. These list elements
- -- are:
- --
- -- first_element the first element in the list
- -- last_element the last element in the list
- -- current_element the current element in the list
- --
-
- procedure initialize_list;
- function return_first_element return element_pointer;
- function return_last_element return element_pointer;
- function return_current_element return element_pointer;
- function return_first_element return element_object;
- function return_last_element return element_object;
- function return_current_element return element_object;
-
- --
- -- The following procedures and functions manipulate the current
- -- element pointer. The following table outlines their functions:
- --
- -- set_first the first element becomes the current element
- -- set_last the last element becomes the current element
- -- current_index return the number of the current element
- -- (ordinal); 0 returned if list is empty
- -- current_next set current element to next element in the
- -- list; return TRUE if done or FALSE if
- -- already at end of list
- -- current_previous set current element to previous element in the
- -- list; return TRUE if done or FALSE if
- -- already at front of list
- -- set_current_index set the Nth element as the current element;
- -- return TRUE if done or FALSE if end of list
- -- encountered, in which case the last element
- -- becomes the current element
- --
-
- procedure set_first;
- procedure set_last;
- function current_index return natural;
- function current_next return boolean;
- function current_previous return boolean;
- function set_current_index (index : natural) return boolean;
-
- --
- -- The following functions return the index of the last element in
- -- the list and indicate if the list is empty or not.
- --
- -- last_index return the number of the last element
- -- (ordinal); 0 returned if list is empty
- -- list_empty return TRUE if the list is empty; FALSE if
- -- the list is not empty
- -- at_end_of_list return TRUE if the current_element is also
- -- the last_element; return FALSE if not
- -- at_front_of_list return TRUE if the current_element is also
- -- the first_element; return FALSE if not
- --
-
- function last_index return natural;
- function list_empty return boolean;
- function at_end_of_list return boolean;
- function at_front_of_list return boolean;
-
- --
- -- The following procedures and functions are used to manipulate
- -- the elements in the list.
- --
- -- append_element append the indicated element after the
- -- current_element in the list; the
- -- current_element is set to the new
- -- element
- -- insert_element insert the indicated element before the
- -- current_element in the list; the
- -- current_element is unchanged
- -- delete_element delete the current_element from the list;
- -- the next element is the new current_element
- -- unless there is no next element, in which
- -- case the previous element is the new
- -- current_element
- --
-
- procedure append_element (element : element_pointer);
- procedure append_element (element : element_object);
- procedure insert_element (element : element_pointer);
- procedure insert_element (element : element_object);
- procedure delete_element;
-
- --
- -- The following function and procedure are used to dynamically
- -- create new elements and to free the space occupied by unneeded
- -- elements.
- --
- -- new_element returns a pointer to a new list_element
- -- free_element frees the indicated list_element
- --
-
- function new_element return element_pointer;
- procedure free_element (element : element_pointer);
-
- end Editor_List;
-
-
- --
- -- BODY of Editor_List
- --
- package body Editor_List is
-
- --
- -- Definition of the three element pointers
- --
- first_element, last_element, current_element : element_pointer;
-
- --
- -- Procedure to initialize the list
- -- All element pointers are initialized to null
- --
- procedure initialize_list is
- begin
- first_element := null;
- last_element := null;
- current_element := null;
- end initialize_list;
-
- --
- -- Functions to return element pointers
- --
- function return_first_element return element_pointer is
- begin
- return first_element;
- end return_first_element;
-
- function return_first_element return element_object is
- begin
- return first_element.content;
- end return_first_element;
-
- function return_last_element return element_pointer is
- begin
- return last_element;
- end return_last_element;
-
- function return_last_element return element_object is
- begin
- return last_element.content;
- end return_last_element;
-
- function return_current_element return element_pointer is
- begin
- return current_element;
- end return_current_element;
-
- function return_current_element return element_object is
- begin
- return current_element.content;
- end return_current_element;
-
- --
- -- Current element pointer manipulation
- --
- procedure set_first is
- begin
- current_element := first_element;
- end set_first;
-
- procedure set_last is
- begin
- current_element := last_element;
- end set_last;
-
- function current_index return natural is
- local_element : element_pointer;
- index : natural;
- begin
- index := 0; -- initialize counter and set empty list return
- if current_element /= null then
- local_element := first_element; -- point to first element
- index := 1;
- while local_element /= current_element loop
- exit when local_element = null; -- error trap
- local_element := local_element.next;
- index := index + 1;
- end loop;
- end if;
- return index;
- end current_index;
-
- function current_next return boolean is
- begin
- if current_element = last_element then
- return FALSE;
- else
- current_element := current_element.next;
- return TRUE;
- end if;
- end current_next;
-
- function current_previous return boolean is
- begin
- if current_element = first_element then
- return FALSE;
- else
- current_element := current_element.previous;
- return TRUE;
- end if;
- end current_previous;
-
- function set_current_index (index : natural) return boolean is
- counter : natural;
- begin
- current_element := first_element; -- start at first element
- if index <= 1 then
- return TRUE;
- else
- for counter in 1 .. index - 1 loop
- if current_element = last_element then
- return FALSE;
- exit; -- this exit may not be necessary
- else
- current_element := current_element.next;
- end if;
- end loop;
- return TRUE;
- end if;
- end set_current_index;
-
- --
- -- Return the index of the last element in the list
- --
- function last_index return natural is
- current_save : element_pointer;
- index : natural;
- begin
- current_save := current_element;
- current_element := last_element;
- index := current_index;
- current_element := current_save;
- return index;
- end last_index;
-
- --
- -- Determine if the list is empty; return TRUE if so, FALSE if not
- --
- function list_empty return boolean is
- begin
- if first_element = null then
- return TRUE; -- list is empty
- else
- return FALSE; -- list is not empty
- end if;
- end list_empty;
-
- --
- -- Determine if at first element in list; return TRUE if so
- --
- function at_front_of_list return boolean is
- begin
- if current_element = first_element then
- return TRUE;
- else
- return FALSE;
- end if;
- end at_front_of_list;
-
- --
- -- Determine if at last element in list; return TRUE if so
- --
- function at_end_of_list return boolean is
- begin
- if current_element = last_element then
- return TRUE;
- else
- return FALSE;
- end if;
- end at_end_of_list;
-
- --
- -- Procedures to manipulate elements in list
- -- These procedures insert elements into the list and
- -- delete elements from the list
- --
- procedure append_element (element : element_pointer) is
- begin
- if list_empty then
- first_element := element;
- last_element := element;
- current_element := element;
- element.next := null;
- element.previous := null;
- else
- element.next := current_element.next;
- current_element.next := element;
- element.previous := current_element;
- if element.next /= null then
- element.next.previous := element;
- else
- last_element := element;
- end if;
- end if;
- current_element := element;
- end append_element;
-
- procedure append_element (element : element_object) is
- loc_element : element_pointer;
- begin
- loc_element := new_element;
- loc_element.content := element;
- append_element (loc_element);
- end append_element;
-
- procedure insert_element (element : element_pointer) is
- begin
- if list_empty then
- first_element := element;
- last_element := element;
- current_element := element;
- element.next := null;
- element.previous := null;
- else
- element.previous := current_element.previous;
- current_element.previous := element;
- element.next := current_element;
- if element.previous /= null then
- element.previous.next := element;
- else
- first_element := element;
- end if;
- end if;
- end insert_element;
-
- procedure insert_element (element : element_object) is
- loc_element : element_pointer;
- begin
- loc_element := new_element;
- loc_element.content := element;
- insert_element (loc_element);
- end insert_element;
-
- procedure delete_element is
- temp_element : element_pointer;
- begin
- if not list_empty then
-
- if current_element = first_element then
- first_element := current_element.next;
- else
- current_element.previous.next := current_element.next;
- end if;
-
- if current_element = last_element then
- last_element := current_element.previous;
- temp_element := last_element;
- else
- current_element.next.previous := current_element.previous;
- temp_element := current_element.next;
- end if;
-
- free_element (current_element);
- current_element := temp_element;
- end if;
- end delete_element;
-
- --
- -- Memory management routines
- -- Obtain a new list element and free old, unneeded list elements
- --
- function new_element return element_pointer is
- begin
- return (new list_element);
- end new_element;
-
- procedure free_element (element : element_pointer) is
- --
- -- This procedure is a dummy for now; the following generic
- -- instantiation is what it should be, but there is a bug in my
- -- Ada compiler which prevents this instatiation from working
- --
- -- procedure free_element is new unchecked_deallocation
- -- (list_element, element_pointer);
- --
- begin
- null;
- end free_element;
-
- end Editor_List;
-