home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / cais / editor.src < prev   
Encoding:
Text File  |  1988-05-03  |  149.1 KB  |  4,443 lines

  1. --::::::::::::::
  2. --README
  3. --::::::::::::::
  4. Suggested Compilation order for Aled (Ada Line Editor):
  5.  
  6. editor_list.a
  7. edit_support-spec.a
  8. edit_worker-spec.a
  9. edit_worker-body.a
  10. edit_support-body.a
  11. editor.a
  12. ============================================
  13. Link "editor" (the main pgm) to get the executable.
  14.  
  15. Documentation for Aled is in "aled.doc" .
  16. --::::::::::::::
  17. --aled.doc
  18. --::::::::::::::
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.                              ALED - Ada Line Editor
  40.  
  41.                    A Line-Oriented File Editor written in Ada
  42.  
  43.  
  44.                                  by Richard Conn
  45.                                 Texas Instruments
  46.                           Advanced Computer Systems Lab
  47.                               Ada Technology Branch
  48.  
  49.                                 10 December 1984
  50.  
  51.  
  52.                                    Version 2.0
  53.                                  21 January 1985
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.                                 C O N T E N T S 
  89.  
  90.           1. INTRODUCTION...............................................1
  91.  
  92.           2. USING ALED.................................................2
  93.              2.1. PRELIMINARIES.........................................4
  94.                   2.1.1. LINE RANGES....................................4
  95.                   2.1.2. LINE REFERENCES................................5
  96.                   2.1.3. STRINGS and LINES..............................5
  97.                   2.1.4. INPUT LINE EDITOR..............................6
  98.                   2.1.5. ABORTING COMMANDS..............................6
  99.              2.2. COMMANDS..............................................6
  100.  
  101.           3. SYNOPSIS and COMMENTS......................................9
  102.  
  103.  
  104.         
  105.         APPENDICES
  106.  
  107.           A. SAMPLE SESSION............................................10
  108.  
  109.              Index.....................................................20
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.                 ALED - A Line-Oriented File Editor Written in Ada
  152.  
  153.  
  154.  
  155.  
  156.                              ALED - Ada Line Editor
  157.  
  158.                    A Line-Oriented File Editor written in Ada
  159.  
  160.  
  161.                                  by Richard Conn
  162.                                 Texas Instruments
  163.                           Advanced Computer Systems Lab
  164.                               Ada Technology Branch
  165.  
  166.                                 10 December 1984
  167.  
  168.                                    Version 2.0
  169.                                  21 January 1985
  170.  
  171.  
  172.         1. I N T R O D U C T I O N 
  173.  
  174.              ALED  is a relatively simple line-oriented file editor which 
  175.         is  written  in the Ada (trademark,  United States Department  of 
  176.         Defense)  programming language.   It was written to  satisfy  the 
  177.         following needs:
  178.  
  179.                   (1)  to help the author learn the Ada language  by 
  180.             writing  a useful program whose scope (at a few thousand 
  181.             lines) is reasonable
  182.  
  183.                   (2)  to  help  others  wanting  to  learn  Ada  by 
  184.             providing a "living example" of an editor written in Ada
  185.  
  186.                   (3)  to make a transportable  editor,  written  in 
  187.             Ada, available for use on a variety of machines; efforts 
  188.             were  made  to  isolate any system dependencies  to  the 
  189.             package  SYSDEP,  so  the code should  be  transportable 
  190.             between all machines that have a validated Ada  compiler 
  191.             and  have the routines GET and PUT in the package SYSDEP 
  192.             implemented
  193.  
  194.  
  195.              This document is divided into two parts:  (1) an overview on 
  196.         the operation of the editor from the user's perspective and (2) a 
  197.         synopsis  of  what was learned during its design and comments  on 
  198.         the design in general.
  199.  
  200.              Version  1.0  of  ALED which has been released  to  the  Ada 
  201.         Repository  is  the Engineering Development Model (EDM) of  ALED.  
  202.         An Advanced Development Model,  which was completed some time ago 
  203.         and  will never be released,  was written to learn the basics  of 
  204.         the  problem  and  to prove that the  problem  could  be  solved.  
  205.         Version 2.x is the production model of ALED. 
  206.  
  207.  
  208.  
  209.  
  210.  
  211.                                                       Page 1
  212.  
  213.  
  214.  
  215.  
  216.  
  217.                 ALED - A Line-Oriented File Editor Written in Ada
  218.  
  219.  
  220.  
  221.         2. U S I N G   A L E D 
  222.  
  223.              ALED  was designed and implemented on a Data General MV10000 
  224.         under  the ROLM Ada Development Environment.   It is  invoked  on 
  225.         this system by typing
  226.  
  227.                                     X EDITOR
  228.  
  229.         where  EDITOR.PR is the name of the file containing the object of 
  230.         ALED after compilation and linking.   This invocation results  in 
  231.         the following banner being displayed:
  232.  
  233.                ALED - Ada Line Editor by Richard Conn, Version 2.0
  234.                File Name? 
  235.  
  236.         The  user is expected to enter the name of the file to be  edited 
  237.         at  this time.   A file name must be specified,  and one will  be 
  238.         created  if the file does not exist.   If the indicated text file 
  239.         exists,  its  contents  will be read into  a  doubly-linked  list 
  240.         created  by ALED and made ready for editing.   Input line editing 
  241.         (see the following section on the Input Line Editor) is  allowed, 
  242.         so the user can correct any errors he makes while typing the file 
  243.         name.
  244.  
  245.              After the indicated file is read in or created, ALED prompts 
  246.         the user with
  247.  
  248.                   n>
  249.  
  250.         where  "n"  is 0 if there are no lines in the file (the  file  is 
  251.         empty) or 1 if there are lines in the file.   The number in front 
  252.         of  the ">" character is the number of the current line.   As the 
  253.         user  moves through the file,  this number will be  updated  each 
  254.         time the prompt appears.
  255.  
  256.              Once   this  prompt  appears,   ALED  uses  single-character 
  257.         commands  with command completion and prompting to  interface  to 
  258.         the  user.   In  response  to  any one  of  the  single-character 
  259.         commands  recognized by ALED,  the ALED editor will complete  the 
  260.         text  of  the  command,  prompt the  user  for  input  parameters 
  261.         (allowing him to abort by providing no input in most cases),  and 
  262.         then perform the function of the command.  ALED is interactive in 
  263.         nature, and the learning curve for ALED is quite short.  Built-in 
  264.         summary  documentation  is  provided  by means of  the  H  (Help) 
  265.         Summary  command;  to illustrate,  when the letter "h"  is  typed 
  266.         (case  is  not  significant on letter commands) and  the  summary 
  267.         option is selected, the following display is presented:
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.                                                       Page 2
  278.  
  279.  
  280.  
  281.  
  282.  
  283.                 ALED - A Line-Oriented File Editor Written in Ada
  284.  
  285.  
  286.  
  287.  
  288.         --- Movement Commands ---  ----- Enter Lines -----
  289.          + Advance N Lines          A Append after <line> 
  290.          - Back Up N Lines          I Insert before <line>
  291.          F Find <string> in <range>                       
  292.          J Jump to <line>          ----- Print Lines -----
  293.          N Find Next <string>       . Print Current Line  
  294.         ----- Delete Command -----  < Print Next Line     
  295.          D Delete lines in <range>  > Print Next Line     
  296.                                     L List over <range>   
  297.         ---- Help and Exits ----                          
  298.          H This Help Text          ---- Substitution ---- 
  299.          Q Quit without Updating    S String Substitute   
  300.          X Exit and Update              over <range>      
  301.  
  302.         ---- File Get/Put ----     -- Miscellaneous --    
  303.          G Get <file> after <line>  ? Print Statistics    
  304.          P Put <file> over <range>                        
  305.  
  306.         <Range>:  %   %,%
  307.         First or Second Entries --
  308.            #-Number, .-Current, C-Current, F-First, L-Last
  309.         Singular Entries --
  310.            A-All, P-Page
  311.  
  312.  
  313.                   -- Figure 1: ALED Help Command and Display --
  314.  
  315.              To reiterate, the above display was generated as follows:
  316.  
  317.                   1) the prompt "0>" was printed by ALED
  318.                   2) the user typed the letter "h" followed by the
  319.                        letter "s" to select the summary
  320.                   3) the command summary was printed by ALED
  321.                        command
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.                                                       Page 3
  344.  
  345.  
  346.  
  347.  
  348.  
  349.                 ALED - A Line-Oriented File Editor Written in Ada
  350.  
  351.  
  352.  
  353.         2.1. PRELIMINARIES
  354.  
  355.         2.1.1. LINE RANGES
  356.              Several of the ALED commands, such as List and Find, perform 
  357.         their operations over a range of lines.  They prompt the user for 
  358.         this  line  range with the herald "<range>".   Examples  of  this 
  359.         prompt are:
  360.  
  361.                   1) list lines in <range>
  362.                   2) find <string>
  363.                       over <range>
  364.                   3) substitute for old <string>
  365.                       new <string>
  366.                       over <range>
  367.  
  368.              Whenever the range prompt ("<range>") is presented, the user 
  369.         may enter any of the following responses:
  370.  
  371.                   Response       Meaning
  372.                   --------       -------
  373.                   A or a         All Lines
  374.                   P or p         Current Page (next 20 lines)
  375.                   . or C or c    Current Line
  376.                   F or f         First Line
  377.                   L or l         Last Line
  378.  
  379.                   #,#            A pair of line numbers, like "5,8",
  380.                                   or relative line references, like
  381.                                   "-5,+10" for 5 lines before the
  382.                                   current line to 10 lines after the
  383.                                   current line, or any combination,
  384.                                   like "5,+10" for line 5 to 10 lines
  385.                                   after the current line; the only
  386.                                   restriction is that the first number
  387.                                   must evaluate to be less than the
  388.                                   second number
  389.  
  390.                   s,s            A mixture of the symbols for Current
  391.                                   Line, First Line, Last Line, and
  392.                                   a line number or relative line
  393.                                   reference, like ".,L" for current
  394.                                   line to the last line, "1,." for line
  395.                                   1 to the current line, "F,." for first
  396.                                   line to the current line, "-5,." for
  397.                                   five lines before the current line to
  398.                                   the current line, etc.
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.                                                       Page 4
  410.  
  411.  
  412.  
  413.  
  414.  
  415.                 ALED - A Line-Oriented File Editor Written in Ada
  416.  
  417.  
  418.  
  419.              Examples:
  420.  
  421.                   list lines in <range> A       <-- all lines
  422.                   list lines in <range> .,L     <-- current to last
  423.                   list lines in <range> 1,5     <-- lines 1 to 5
  424.                   list lines in <range> -5,+6   <-- 5 lines before the
  425.                                                      current line to 6
  426.                                                      lines after the
  427.                                                      current line
  428.                   list lines in <range> P       <-- next 20 lines
  429.                   list lines in <range> F,L     <-- same as All lines
  430.  
  431.  
  432.         2.1.2. LINE REFERENCES
  433.              Some  commands operate only on a specific line,  such as the 
  434.         Append and Insert commands.   The user is to indicate a  specific 
  435.         line, as opposed to a range of lines, in response to the "<line>" 
  436.         herald printed by these commands; for example:
  437.  
  438.                   append after <line>
  439.                   insert before <line>
  440.  
  441.              Any  of the forms indicated above may be used to define this 
  442.         line reference,  and the indicated line becomes the first line of 
  443.         the range.   For instance,  if "A" (all lines) is the response to 
  444.         the  herald,  then line 1 is the indicated line since  all  lines 
  445.         references  line  1  to the last line.   It is usually  safer  to 
  446.         reference only one line in response to the "<line>" herald (like, 
  447.         "5" or ".") rather than to use a range specification.
  448.  
  449.  
  450.         2.1.3. STRINGS and LINES
  451.              Some  commands accept a string or a line as input,  such  as 
  452.         the  Substitute and Insert commands.   In both  cases,  the  text 
  453.         which  is input by the user is simply a group of characters.   No 
  454.         quotes or other delimiters are necessary.   A blank line is input 
  455.         by simply striking the RETURN key or entering any number of space 
  456.         characters followed by the RETURN key.
  457.  
  458.              When  inputting  a group of lines via the Append  or  Insert 
  459.         commands, the lines are prompted for with the herald:
  460.  
  461.                   n:
  462.  
  463.         where  "n" is the number of the line that is about to  be  input.  
  464.         The  user may enter characters as he desires in response to  this 
  465.         prompt;  blank lines may be entered by simply striking the RETURN 
  466.         key.   To  terminate  input,  the user enters a single dot  (".") 
  467.         followed by RETURN.   See the sample session below and experiment 
  468.         with the editor itself for clarification.
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.                                                       Page 5
  476.  
  477.  
  478.  
  479.  
  480.  
  481.                 ALED - A Line-Oriented File Editor Written in Ada
  482.  
  483.  
  484.  
  485.         2.1.4. INPUT LINE EDITOR
  486.              The  user has the ability to edit his string or line  inputs 
  487.         as he enters each character.  This is done by striking any one of 
  488.         the  three input line editor command characters.   The  following 
  489.         table  summarizes these characters,  giving their default  values 
  490.         and the functions they perform.
  491.  
  492.         Default
  493.          Value    Function
  494.         -------   --------
  495.          <DEL>    Delete previous character
  496.           ^U      Delete all previous characters and restart input
  497.           ^R      Retype the line or string entered so far
  498.  
  499.              These  default values may be changed to some other values by 
  500.         editing the source code and changing three constants.
  501.  
  502.         2.1.5. ABORTING COMMANDS
  503.              If the user strikes a command by accident, most commands may 
  504.         be aborted by simply doing the following:
  505.  
  506.                   1)  not specifying a range of lines (enter a RETURN  in 
  507.         response to the <range> herald)
  508.                   2) not specifying a line (enter a RETURN in response to 
  509.         the <line> herald)
  510.                   3)  not  specifying  a file name for the  Get  and  Put 
  511.         commands (enter a RETURN)
  512.  
  513.  
  514.  
  515.  
  516.         2.2. COMMANDS
  517.              The  following presents the various commands of  ALED.   The 
  518.         sample session illustrates their use.
  519.  
  520.              COMMAND:  .
  521.              FUNCTION: Print the current line
  522.              The "." command prints the current line.
  523.  
  524.              COMMAND:  <
  525.              FUNCTION: Back up to the last line and print it
  526.              The "<" command backs up to the last line and prints it.
  527.  
  528.              COMMAND:  >
  529.              FUNCTION: Advance to the next line and print it
  530.              The ">" command advances to the next line and prints it.
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.                                                       Page 6
  542.  
  543.  
  544.  
  545.  
  546.  
  547.                 ALED - A Line-Oriented File Editor Written in Ada
  548.  
  549.  
  550.              COMMAND:  +
  551.              FUNCTION: Advance n lines from the current line
  552.              The  "+" command moves the user an indicated number of lines 
  553.         forward from his current position.
  554.  
  555.              COMMAND:  -
  556.              FUNCTION: Back up n lines from the current line
  557.              The "-" command moves the user an indicated number of  lines 
  558.         backward from his current position.
  559.  
  560.              COMMAND:  ?
  561.              FUNCTION: Print statistics
  562.              The "?" command prints the name of the file being edited and 
  563.         the number of lines in the edit buffer.
  564.  
  565.              COMMAND:  A
  566.              FUNCTION: Append lines
  567.              The  A  command allows the user to enter a  group  of  lines 
  568.         after the indicated line.  Lines are entered until the user types 
  569.         a line containing a single dot (".") in the first column followed 
  570.         by  a  RETURN.   The Insert command is like  the  Append  command 
  571.         except  that  it inserts lines BEFORE the indicated  line,  where 
  572.         Append appends lines AFTER the indicated line.
  573.  
  574.              COMMAND:  D
  575.              FUNCTION: Delete lines
  576.              The  D command deletes all lines over the indicated range of 
  577.         lines.  There is no recovery from this command.
  578.  
  579.              COMMAND:  F
  580.              FUNCTION: Find the first occurance of a string
  581.              The  F  command searches for the indicated string  over  the 
  582.         indicated  range  of lines.   The first line in the  range  which 
  583.         contains the string is positioned to and the line is printed.
  584.  
  585.              COMMAND:  G
  586.              FUNCTION: Get a File
  587.              The  G  command  loads the indicated file  into  the  editor 
  588.         buffer  after the indicated line.   This command can be  used  to 
  589.         read  in  a  file  to be included in the edit  buffer  for  paste 
  590.         operations,  where  the  Put  command is  the  complementary  cut 
  591.         operation.
  592.  
  593.              COMMAND:  H
  594.              FUNCTION: Print Help Information
  595.              The  H command prints a summary of the ALED  commands,  just 
  596.         the  names of the ALED commands,  or a summary of  numeric  input 
  597.         options to the user.
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.                                                       Page 7
  608.  
  609.  
  610.  
  611.  
  612.  
  613.                 ALED - A Line-Oriented File Editor Written in Ada
  614.  
  615.  
  616.  
  617.              COMMAND:  I
  618.              FUNCTION: Insert lines
  619.              The  I  command allows the user to enter a  group  of  lines 
  620.         before  the  indicated line.   Lines are entered until  the  user 
  621.         types  a  line containing a single dot (".") in the first  column 
  622.         followed  by  a RETURN.   The Append command is like  the  Insert 
  623.         command  except that it appends lines AFTER the  indicated  line, 
  624.         where Insert inserts lines BEFORE the indicated line.
  625.  
  626.              COMMAND:  J
  627.              FUNCTION: Jump to the indicated line
  628.              The J command positions the user at the indicated line.  The 
  629.         line is not printed.
  630.  
  631.              COMMAND:  L
  632.              FUNCTION: List lines over a range
  633.              The  L  command lists all lines over the indicated range  of 
  634.         lines.
  635.  
  636.              COMMAND:  N
  637.              FUNCTION: Find Next occurance of indicated string
  638.              The  N command searches for the indicated string starting at 
  639.         the next line in the file and proceeding to the end of the  file.  
  640.         If  the  user  inputs a blank line (a simple  RETURN),  the  last 
  641.         string referenced by an F or N command is searched for again.
  642.  
  643.              COMMAND:  P
  644.              FUNCTION: Put a range of lines into a file
  645.              The  P command writes a group of lines from the edit  buffer 
  646.         out  to  a  file on disk.   This may be used  to  create  desired 
  647.         external files or it may be used to cut a section out of the edit 
  648.         buffer and paste it in (via the Get command) elsewhere.
  649.  
  650.              COMMAND:  Q
  651.              FUNCTION: Quit editor and do not update file
  652.              The  Q  command allows the user to exit the  editor  without 
  653.         changing the original file on the disk.
  654.  
  655.              COMMAND:  S
  656.              FUNCTION: Substitute strings
  657.              The  S command substitutes one string for another  over  the 
  658.         indicated range of lines.   All occurrances of the old string are 
  659.         replaced by the new string over this range.
  660.  
  661.              COMMAND:  X
  662.              FUNCTION: Exit the editor and update the file
  663.              The  X command exits the editor and updates the file on  the 
  664.         disk.
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.                                                       Page 8
  674.  
  675.  
  676.  
  677.  
  678.  
  679.                 ALED - A Line-Oriented File Editor Written in Ada
  680.  
  681.  
  682.  
  683.         3. S Y N O P S I S   a n d   C O M M E N T S 
  684.  
  685.              In  summary,  the  following  items were learned  from  this 
  686.         experience:
  687.  
  688.                   1. Ada is feasible; the editor ran with reasonable 
  689.                        speed
  690.  
  691.                   2. The Ada code was fairly efficient; EDITOR used
  692.                        only TEXT_IO for support, and, after a 58K
  693.                        initial overhead, the growth of code was
  694.                        approximately 9 words/line of code
  695.  
  696.                   3. Standardization under TEXT_IO needs some work;
  697.                        some simple, fundamental items, such as an
  698.                        input line editor available under GET_LINE,
  699.                        are missing (this is why I had to write my
  700.                        own input line editor) and GET does not return
  701.                        or pass every possible character (the DEL
  702.                        character does not pass thru the GET routine
  703.                        in my TEXT_IO package, for instance); do all
  704.                        GET routines allow single-character input?
  705.  
  706.                   4. Generics are useful and work well; software
  707.                        components libraries will be quite beneficial
  708.                        in reducing programming overhead once they
  709.                        have been developed
  710.  
  711.                   5. Exceptions are very, very useful; note their
  712.                        use throughout the code and how they are
  713.                        fundamental to the design (note the BEGIN/END
  714.                        in the main loop)
  715.  
  716.                   6. Ada code can be written to be quite readable
  717.                        and maintainable; I feel that I have successfully
  718.                        done this with ALED (assuming that knowledge
  719.                        of the generic package in LIST.ADA is known)
  720.  
  721.                   7. In version 2.0 of ALED, the System Dependencies
  722.                        were effectively isolated in the package SYSDEP.
  723.                        SYSDEP provided only two required routines,
  724.                        GET (which input the next character without
  725.                        interpretation of any kind) and PUT (which output
  726.                        a character without interpretation).  This made
  727.                        a much more friendly user interface possible.
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.                                                       Page 9
  740.  
  741.  
  742.  
  743.  
  744.  
  745.                 ALED - A Line-Oriented File Editor Written in Ada
  746.  
  747.  
  748.  
  749.         A. S A M P L E   S E S S I O N 
  750.              The  following  is  a sample session which  illustrates  the 
  751.         operation of ALED.  Comments are placed out to the side, prefixed 
  752.         by "<--".
  753.  
  754.  
  755.         ALED - Ada Line Editor by Richard Conn, Version  1.0
  756.         File Name? t.txt         <-- File name is selected
  757.         New File                 <-- File does not already exist
  758.             0 Lines in File
  759.          Type H for Help
  760.             0> append after <line> .       <-- Append Lines into buffer
  761.         Enter Lines (.<RETURN> to Stop)
  762.             1: This is a test and demonstration of ALED
  763.             2: This is a very short test, but all commands
  764.             3:  should be exercised by it
  765.             4: Note that all commands are single characters;
  766.             5:  the editor fills in the prompt with each
  767.             6:  single character input at the command prompt "n>"
  768.             7: A single dot in a line terminates input
  769.             8: .                           <-- Input is complete
  770.  
  771.             7> list lines in <range> all   <-- List all lines
  772.             1: This is a test and demonstration of ALED
  773.             2: This is a very short test, but all commands
  774.             3:  should be exercised by it
  775.             4: Note that all commands are single characters;
  776.             5:  the editor fills in the prompt with each
  777.             6:  single character input at the command prompt "n>"
  778.             7: A single dot in a line terminates input
  779.  
  780.             7> list lines in <range> 1,4   <-- List range of lines
  781.             1: This is a test and demonstration of ALED
  782.             2: This is a very short test, but all commands
  783.             3:  should be exercised by it
  784.             4: Note that all commands are single characters;
  785.  
  786.             4> list lines in <range> -1,+2 <-- List range of lines
  787.             3:  should be exercised by it
  788.             4: Note that all commands are single characters;
  789.             5:  the editor fills in the prompt with each
  790.             6:  single character input at the command prompt "n>"
  791.  
  792.             6> list lines in <range> 1     <-- List first line
  793.             1: This is a test and demonstration of ALED
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.                                                       Page 10
  806.  
  807.  
  808.  
  809.  
  810.  
  811.                 ALED - A Line-Oriented File Editor Written in Ada
  812.  
  813.  
  814.             1> list lines in <range> p     <-- List current page
  815.             1: This is a test and demonstration of ALED
  816.             2: This is a very short test, but all commands
  817.             3:  should be exercised by it
  818.             4: Note that all commands are single characters;
  819.             5:  the editor fills in the prompt with each
  820.             6:  single character input at the command prompt "n>"
  821.             7: A single dot in a line terminates input
  822.  
  823.             7> list lines in <range> a     <-- List all lines
  824.             1: This is a test and demonstration of ALED
  825.             2: This is a very short test, but all commands
  826.             3:  should be exercised by it
  827.             4: Note that all commands are single characters;
  828.             5:  the editor fills in the prompt with each
  829.             6:  single character input at the command prompt "n>"
  830.             7: A single dot in a line terminates input
  831.  
  832.             7> Error                   <-- Invalid Commands
  833.             7> Error
  834.  
  835.             7> - back up N lines <line count> 3 <-- Backup 3 lines
  836.             4> .                                <-- Print current line
  837.             4: Note that all commands are single characters;
  838.             4> + advance N lines <line count> 1 <-- Advance 1 line
  839.             5> .                                <-- Print current line
  840.             5:  the editor fills in the prompt with each
  841.  
  842.             5> substitute for old <string> test <-- substitute
  843.                 new <string> xx
  844.                 over <range> a
  845.             1: This is a xx and demonstration of ALED     <-- affected
  846.             2: This is a very short xx, but all commands  <--  lines
  847.  
  848.             7> substitute for old <string> xx   <-- change back
  849.                 new <string> test
  850.                 over <range> 2
  851.             2: This is a very short test, but all commands
  852.  
  853.             3> find <string> xx                 <-- look for "xx"
  854.                 over <range> a
  855.             1: This is a xx and demonstration of ALED
  856.  
  857.             1> substitute for old <string> xx   <-- change it
  858.                 new <string> test
  859.                 over <range> .
  860.             1: This is a test and demonstration of ALED
  861.  
  862.             2> find <string> test               <-- look for first
  863.                 over <range> a
  864.             1: This is a test and demonstration of ALED
  865.  
  866.             1> next Occurrance of <string>      <-- look for next
  867.             2: This is a very short test, but all commands
  868.  
  869.  
  870.  
  871.                                                       Page 11
  872.  
  873.  
  874.  
  875.  
  876.  
  877.                 ALED - A Line-Oriented File Editor Written in Ada
  878.  
  879.  
  880.  
  881.             2> list lines in <range> L          <-- look at last line
  882.             7: A single dot in a line terminates input
  883.  
  884.             7> append after <line> L            <-- append lines
  885.         Enter Lines (.<RETURN> to Stop)
  886.             8: This is yet another test
  887.             9: These lines are being appended to the
  888.            10:  end of the file.
  889.            11: I am inserting several instances of
  890.            12:  the word test
  891.            13:  so that there will be something to search for
  892.            14:  in further tests of the Next Occurrance command
  893.            15: .                                <-- end input
  894.  
  895.            14> find <string> test               <-- search for "test"
  896.                 over <range> a
  897.             1: This is a test and demonstration of ALED
  898.  
  899.             1> next Occurrance of <string>      <-- search again
  900.             2: This is a very short test, but all commands
  901.  
  902.             2> next Occurrance of <string>      <-- and again
  903.             8: This is yet another test
  904.  
  905.             8> next Occurrance of <string>      <-- and again
  906.            12:  the word test
  907.  
  908.            12> next Occurrance of <string>      <-- and again
  909.            14:  in further tests of the Next Occurrance command
  910.  
  911.            14> next Occurrance of <string>      <-- and again
  912.            14:  in further tests of the Next Occurrance command
  913.  
  914.            14> substitute for old <string> test <-- change string
  915.                 new <string> xxxxxxx
  916.                 over <range> a
  917.             1: This is a xxxxxxx and demonstration of ALED
  918.             2: This is a very short xxxxxxx, but all commands
  919.             8: This is yet another xxxxxxx
  920.            12:  the word xxxxxxx
  921.            14:  in further xxxxxxxs of the Next Occurrance command
  922.  
  923.            14> substitute for old <string> xxxxxxx   <-- change back
  924.                 new <string> test
  925.                 over <range> a
  926.             1: This is a test and demonstration of ALED
  927.             2: This is a very short test, but all commands
  928.             8: This is yet another test
  929.            12:  the word test
  930.            14:  in further tests of the Next Occurrance command
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.                                                       Page 12
  938.  
  939.  
  940.  
  941.  
  942.  
  943.                 ALED - A Line-Oriented File Editor Written in Ada
  944.  
  945.  
  946.  
  947.            14> substitute for old <string> test
  948.                 new <string> "test"
  949.                 over <range> 12
  950.            12:  the word "test"
  951.  
  952.            13> jump to <line> 1       <-- Jump command
  953.  
  954.             1> jump to <line> L       <-- Jump to last line
  955.  
  956.            14> jump to <line> 1       <-- Jump to first line
  957.  
  958.             1> list lines in <range> p
  959.             1: This is a test and demonstration of ALED
  960.             2: This is a very short test, but all commands
  961.             3:  should be exercised by it
  962.             4: Note that all commands are single characters;
  963.             5:  the editor fills in the prompt with each
  964.             6:  single character input at the command prompt "n>"
  965.             7: A single dot in a line terminates input
  966.             8: This is yet another test
  967.             9: These lines are being appended to the
  968.            10:  end of the file.
  969.            11: I am inserting several instances of
  970.            12:  the word "test"
  971.            13:  so that there will be something to search for
  972.            14:  in further tests of the Next Occurrance command
  973.  
  974.            14> put <file> q.txt       <-- Write lines out
  975.                 over <range> 11,L     <-- Limit range
  976.            14> get <file> q.txt       <-- Read back in after line 1
  977.                 after <line> 1
  978.             1> list lines in <range> a     <-- look at results
  979.             1: This is a test and demonstration of ALED
  980.             2: I am inserting several instances of
  981.             3:  the word "test"
  982.             4:  so that there will be something to search for
  983.             5:  in further tests of the Next Occurrance command
  984.             6: This is a very short test, but all commands
  985.             7:  should be exercised by it
  986.             8: Note that all commands are single characters;
  987.             9:  the editor fills in the prompt with each
  988.            10:  single character input at the command prompt "n>"
  989.            11: A single dot in a line terminates input
  990.            12: This is yet another test
  991.            13: These lines are being appended to the
  992.            14:  end of the file.
  993.            15: I am inserting several instances of
  994.            16:  the word "test"
  995.            17:  so that there will be something to search for
  996.            18:  in further tests of the Next Occurrance command
  997.  
  998.            18> get <file> q.txt       <-- read lines back in
  999.                 after <line> 7
  1000.  
  1001.  
  1002.  
  1003.                                                       Page 13
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.                 ALED - A Line-Oriented File Editor Written in Ada
  1010.  
  1011.  
  1012.  
  1013.             7> list lines in <range> p     <-- list page of lines
  1014.             7:  should be exercised by it
  1015.             8: I am inserting several instances of
  1016.             9:  the word "test"
  1017.            10:  so that there will be something to search for
  1018.            11:  in further tests of the Next Occurrance command
  1019.            12: Note that all commands are single characters;
  1020.            13:  the editor fills in the prompt with each
  1021.            14:  single character input at the command prompt "n>"
  1022.            15: A single dot in a line terminates input
  1023.            16: This is yet another test
  1024.            17: These lines are being appended to the
  1025.            18:  end of the file.
  1026.            19: I am inserting several instances of
  1027.            20:  the word "test"
  1028.            21:  so that there will be something to search for
  1029.            22:  in further tests of the Next Occurrance command
  1030.  
  1031.            22> insert before <line> 16     <-- insert line
  1032.         Enter Lines (.<RETURN> to Stop)
  1033.            16: testtesttesttest
  1034.            17: .                           <-- end input
  1035.  
  1036.            17> <                           <-- backup
  1037.            16: testtesttesttest
  1038.  
  1039.            16> <
  1040.            15: A single dot in a line terminates input
  1041.  
  1042.            15> >
  1043.            16: testtesttesttest
  1044.  
  1045.            16> >
  1046.            17: This is yet another test
  1047.  
  1048.            17> <
  1049.            16: testtesttesttest
  1050.  
  1051.            16> .
  1052.            16: testtesttesttest
  1053.  
  1054.            16> substitute for old <string> test      <-- substitute
  1055.                 new <string> xxxx
  1056.                 over <range> .
  1057.            16: xxxxtesttesttest       <-- observe progress of
  1058.            16: xxxxxxxxtesttest       <-- substitute command
  1059.            16: xxxxxxxxxxxxtest
  1060.            16: xxxxxxxxxxxxxxxx
  1061.  
  1062.            17> <
  1063.            16: xxxxxxxxxxxxxxxx
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.                                                       Page 14
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.                 ALED - A Line-Oriented File Editor Written in Ada
  1076.  
  1077.  
  1078.  
  1079.            16> substitute for old <string> xxxx      <-- and again
  1080.                 new <string> test
  1081.                 over <range> .
  1082.            16: testxxxxxxxxxxxx
  1083.            16: testtestxxxxxxxx
  1084.            16: testtesttestxxxx
  1085.            16: testtesttesttest
  1086.  
  1087.            17> jump to <line> 1
  1088.  
  1089.             1> ?                      <-- statistics
  1090.                Edit File Name: t.txt
  1091.                   23 Lines in File
  1092.             1> jump to <line> L       <-- verify line count
  1093.  
  1094.            23> jump to <line> 1
  1095.  
  1096.             1> list lines in <range> .
  1097.             1: This is a test and demonstration of ALED
  1098.  
  1099.             1> .
  1100.             1: This is a test and demonstration of ALED
  1101.  
  1102.             1> list lines in <range> p
  1103.             1: This is a test and demonstration of ALED
  1104.             2: I am inserting several instances of
  1105.             3:  the word "test"
  1106.             4:  so that there will be something to search for
  1107.             5:  in further tests of the Next Occurrance command
  1108.             6: This is a very short test, but all commands
  1109.             7:  should be exercised by it
  1110.             8: I am inserting several instances of
  1111.             9:  the word "test"
  1112.            10:  so that there will be something to search for
  1113.            11:  in further tests of the Next Occurrance command
  1114.            12: Note that all commands are single characters;
  1115.            13:  the editor fills in the prompt with each
  1116.            14:  single character input at the command prompt "n>"
  1117.            15: A single dot in a line terminates input
  1118.            16: testtesttesttest
  1119.            17: This is yet another test
  1120.            18: These lines are being appended to the
  1121.            19:  end of the file.
  1122.            20: I am inserting several instances of
  1123.            21:  the word "test"
  1124.  
  1125.            21> delete lines in <range> 8,11          <-- delete lines
  1126.  
  1127.             8> jump to <line> 1
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.                                                       Page 15
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.                 ALED - A Line-Oriented File Editor Written in Ada
  1142.  
  1143.  
  1144.  
  1145.             1> list lines in <range> p
  1146.             1: This is a test and demonstration of ALED
  1147.             2: I am inserting several instances of
  1148.             3:  the word "test"
  1149.             4:  so that there will be something to search for
  1150.             5:  in further tests of the Next Occurrance command
  1151.             6: This is a very short test, but all commands
  1152.             7:  should be exercised by it
  1153.             8: Note that all commands are single characters;
  1154.             9:  the editor fills in the prompt with each
  1155.            10:  single character input at the command prompt "n>"
  1156.            11: A single dot in a line terminates input
  1157.            12: testtesttesttest
  1158.            13: This is yet another test
  1159.            14: These lines are being appended to the
  1160.            15:  end of the file.
  1161.            16: I am inserting several instances of
  1162.            17:  the word "test"
  1163.            18:  so that there will be something to search for
  1164.            19:  in further tests of the Next Occurrance command
  1165.  
  1166.            19> delete lines in <range> 2,5      <-- delete more lines
  1167.  
  1168.             2> list lines in <range> a
  1169.             1: This is a test and demonstration of ALED
  1170.             2: This is a very short test, but all commands
  1171.             3:  should be exercised by it
  1172.             4: Note that all commands are single characters;
  1173.             5:  the editor fills in the prompt with each
  1174.             6:  single character input at the command prompt "n>"
  1175.             7: A single dot in a line terminates input
  1176.             8: testtesttesttest
  1177.             9: This is yet another test
  1178.            10: These lines are being appended to the
  1179.            11:  end of the file.
  1180.            12: I am inserting several instances of
  1181.            13:  the word "test"
  1182.            14:  so that there will be something to search for
  1183.            15:  in further tests of the Next Occurrance command
  1184.  
  1185.            15> Exit and update file (Y/N)? n
  1186.  
  1187.            15> quit without File Update (Y/N)? n
  1188.  
  1189.            15> Exit and update file (Y/N)? y
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.                                                       Page 16
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.                 ALED - A Line-Oriented File Editor Written in Ada
  1208.  
  1209.  
  1210.  
  1211.         -) type t.txt                                <-- final file
  1212.         This is a test and demonstration of ALED
  1213.         This is a very short test, but all commands
  1214.          should be exercised by it
  1215.         Note that all commands are single characters;
  1216.          the editor fills in the prompt with each
  1217.          single character input at the command prompt "n>"
  1218.         A single dot in a line terminates input
  1219.         testtesttesttest
  1220.         This is yet another test
  1221.         These lines are being appended to the
  1222.          end of the file.
  1223.         I am inserting several instances of
  1224.          the word "test"
  1225.          so that there will be something to search for
  1226.          in further tests of the Next Occurrance command
  1227.  
  1228.         -) type q.txt                                <-- Q.TXT file
  1229.         I am inserting several instances of
  1230.          the word "test"
  1231.          so that there will be something to search for
  1232.          in further tests of the Next Occurrance command
  1233.  
  1234.         -) delete q.txt
  1235.  
  1236.         -) x editor
  1237.         ALED - Ada Line Editor by Richard Conn, Version  1.0
  1238.         File Name? t.txt                             <-- reedit file
  1239.            15 Lines in File
  1240.          Type H for Help
  1241.             1> list lines in <range> a
  1242.             1: This is a test and demonstration of ALED
  1243.             2: This is a very short test, but all commands
  1244.             3:  should be exercised by it
  1245.             4: Note that all commands are single characters;
  1246.             5:  the editor fills in the prompt with each
  1247.             6:  single character input at the command prompt "n>"
  1248.             7: A single dot in a line terminates input
  1249.             8: testtesttesttest
  1250.             9: This is yet another test
  1251.            10: These lines are being appended to the
  1252.            11:  end of the file.
  1253.            12: I am inserting several instances of
  1254.            13:  the word "test"
  1255.            14:  so that there will be something to search for
  1256.            15:  in further tests of the Next Occurrance command
  1257.  
  1258.            15> delete lines in <range> 8
  1259.  
  1260.             8> quit without File Update (Y/N)? y     <-- demo QUIT
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.                                                       Page 17
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.                 ALED - A Line-Oriented File Editor Written in Ada
  1274.  
  1275.  
  1276.  
  1277.  
  1278.         -) x editor
  1279.         ALED - Ada Line Editor by Richard Conn, Version  1.0
  1280.         File Name? t.txt                        <-- reedit file
  1281.            15 Lines in File
  1282.          Type H for Help
  1283.             1> list lines in <range> a
  1284.             1: This is a test and demonstration of ALED
  1285.             2: This is a very short test, but all commands
  1286.             3:  should be exercised by it
  1287.             4: Note that all commands are single characters;
  1288.             5:  the editor fills in the prompt with each
  1289.             6:  single character input at the command prompt "n>"
  1290.             7: A single dot in a line terminates input
  1291.             8: testtesttesttest
  1292.             9: This is yet another test
  1293.            10: These lines are being appended to the
  1294.            11:  end of the file.
  1295.            12: I am inserting several instances of
  1296.            13:  the word "test"
  1297.            14:  so that there will be something to search for
  1298.            15:  in further tests of the Next Occurrance command
  1299.  
  1300.            15> delete lines in <range> 8        <-- remove line from file
  1301.  
  1302.             8> Exit and update file (Y/N)? y    <-- demo EXIT
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.                                                       Page 18
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.                 ALED - A Line-Oriented File Editor Written in Ada
  1340.  
  1341.  
  1342.  
  1343.         -) type t.txt                           <-- show result
  1344.         This is a test and demonstration of ALED
  1345.         This is a very short test, but all commands
  1346.          should be exercised by it
  1347.         Note that all commands are single characters;
  1348.          the editor fills in the prompt with each
  1349.          single character input at the command prompt "n>"
  1350.         A single dot in a line terminates input
  1351.         This is yet another test
  1352.         These lines are being appended to the
  1353.          end of the file.
  1354.         I am inserting several instances of
  1355.          the word "test"
  1356.          so that there will be something to search for
  1357.          in further tests of the Next Occurrance command
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.                                                       Page 19
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.                 ALED - A Line-Oriented File Editor Written in Ada
  1406.  
  1407.  
  1408.  
  1409.          I n d e x 
  1410.  
  1411.  
  1412.         +
  1413.         + Command, 7
  1414.  
  1415.         -
  1416.         - Command, 7
  1417.  
  1418.         <
  1419.         < Command, 6
  1420.  
  1421.         >
  1422.         > Command, 6
  1423.  
  1424.         ?
  1425.         ? Command, 7
  1426.  
  1427.         A
  1428.         A Command, 7
  1429.         Aborting Commands, 6
  1430.         Ada, 1
  1431.         Advance Line, 6
  1432.         Advance N Lines, 7
  1433.         Advanced Development Model, 1
  1434.         ALED
  1435.           Aborting Commands, 6
  1436.           ADM, 1
  1437.           Advanced Development Model, 1
  1438.           EDM, 1
  1439.           Engineering Development Model, 1
  1440.           Help Command, 3
  1441.           Input Line Editor, 6
  1442.           Line Input, 5
  1443.           Line Ranges, 4
  1444.           Line References, 5
  1445.           Prompt, 2
  1446.           Purpose, 1
  1447.           String Input, 5
  1448.         Append Lines, 7
  1449.  
  1450.         B
  1451.         Back Up Line, 6
  1452.         Back Up N Lines, 7
  1453.  
  1454.         C
  1455.         Command
  1456.           +, 7
  1457.           -, 7
  1458.           ., 6
  1459.           <, 6
  1460.           >, 6
  1461.           ?, 7
  1462.           A, 7
  1463.  
  1464.  
  1465.                                                       Page 20
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.                 ALED - A Line-Oriented File Editor Written in Ada
  1472.  
  1473.  
  1474.           D, 7
  1475.           F, 7
  1476.           G, 7
  1477.           H, 7
  1478.           I, 8
  1479.           J, 8
  1480.           L, 8
  1481.           N, 8
  1482.           P, 8
  1483.           Q, 8
  1484.           S, 8
  1485.           X, 8
  1486.         COMMANDS, 6
  1487.  
  1488.         D
  1489.         D Command, 7
  1490.         Delete Lines, 7
  1491.         Dot Command, 6
  1492.  
  1493.         E
  1494.         Engineering Development Model, 1
  1495.         Exit, 8
  1496.  
  1497.         F
  1498.         F Command, 7
  1499.         File
  1500.           Get, 7
  1501.           Put, 8
  1502.         Find Next String, 8
  1503.         Find String, 7
  1504.  
  1505.         G
  1506.         G Command, 7
  1507.         Get File, 7
  1508.  
  1509.         H
  1510.         H Command, 7
  1511.         Help, 3, 7
  1512.  
  1513.         I
  1514.         I Command, 8
  1515.         Input Line Editor, 6
  1516.         Insert Lines, 8
  1517.         INTRODUCTION, 1
  1518.  
  1519.         J
  1520.         J Command, 8
  1521.         Jump to Line, 8
  1522.  
  1523.         L
  1524.         L Command, 8
  1525.         Line Range Specification, 4
  1526.         Line Reference Specification, 5
  1527.         List Lines, 8
  1528.  
  1529.  
  1530.  
  1531.                                                       Page 21
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.                 ALED - A Line-Oriented File Editor Written in Ada
  1538.  
  1539.  
  1540.         N
  1541.         N Command, 8
  1542.         Next String, 8
  1543.  
  1544.         P
  1545.         P Command, 8
  1546.         PRELIMINARIES, 4
  1547.         Print Current Line, 6
  1548.         Print Statistics, 7
  1549.         Put File, 8
  1550.  
  1551.         Q
  1552.         Q Command, 8
  1553.         Quit, 8
  1554.  
  1555.         S
  1556.         S Command, 8
  1557.         SAMPLE SESSION, 10
  1558.         Substitute Strings, 8
  1559.         SYNOPSIS and COMMENTS, 9
  1560.  
  1561.         U
  1562.         USING ALED, 2
  1563.  
  1564.         X
  1565.         X Command, 8
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.  
  1597.                                                       Page 22
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603. --::::::::::::::
  1604. --edit_support-body.a
  1605. --::::::::::::::
  1606. -- Package body EDIT_SUPPORT
  1607. --  Written by Richard Conn, TI Ada Technology Branch
  1608. --  Version 2.0, Date 31 Jan 85
  1609. --  Version 2.1, Date 15 Feb 85
  1610. --  CAIS Version 3.0, Date 22 August 85
  1611. --  CAIS Version 3.1, Date 13 Feb 86
  1612. -- 
  1613. --    NB: changes for the CAIS port are indicated by one of the 
  1614. --        following on each affected line:
  1615. --        --!Rem   Comments, remarks
  1616. --        --!Add   Lines added to the code
  1617. --        --!Del   Lines deleted from the code
  1618. --        --!Cha   Lines changed in the code
  1619. --        (It is a bit subjective; when does a big change become
  1620. --         a delete and an add ?)
  1621.  
  1622. with Cais; use Cais;   --!Cha  was with Sysdep
  1623. package body EDIT_SUPPORT is
  1624.  
  1625. --!Rem  The Keys declaration is used only as a placeholder in
  1626. --!Rem  the Scroll_Terminal.Get calls; it is NOT used.
  1627.     Keys   : Scroll_Terminal.Function_Key_Descriptor(1);  --!Add
  1628. -- 
  1629. -- Editor constants
  1630. -- 
  1631.     EDIT_DEL_CHAR    : constant CHARACTER := ASCII.DEL;
  1632.     EDIT_DEL_LINE    : constant CHARACTER := ASCII.NAK;
  1633.     EDIT_RETYPE_LINE : constant CHARACTER := ASCII.DC2;
  1634.     EDIT_QUOTE       : constant CHARACTER := '\';
  1635.     TAB_SIZE         : constant NATURAL := 8; -- for indenting
  1636.  
  1637. -- 
  1638. -- Initialize console
  1639. -- 
  1640.    procedure CONSOLE_INIT is
  1641.    begin
  1642.        Scroll_Terminal.Set_Echo(False);  --!Cha  (was Sysdep.Open_Console)
  1643.    end CONSOLE_INIT;
  1644.  
  1645. -- 
  1646. -- Deinitialize console
  1647. -- 
  1648.    procedure CONSOLE_DEINIT is
  1649.    begin
  1650.        Scroll_Terminal.Set_Echo(True);  --!Cha  (was Sysdep.Close_Console)
  1651.    end CONSOLE_DEINIT;
  1652.  
  1653. -- 
  1654. -- PRINTING_CHARACTER indicates if the character presented to it is printable
  1655. -- (ie, occupies a position on the screen)
  1656. -- 
  1657.     function PRINTING_CHARACTER (INCHAR : CHARACTER) return BOOLEAN is
  1658.     begin
  1659.         if INCHAR >= ' ' and INCHAR < ASCII.DEL then
  1660.             return TRUE;
  1661.         else
  1662.             return FALSE;
  1663.         end if;
  1664.     end PRINTING_CHARACTER;
  1665.  
  1666. -- 
  1667. -- INPUT_LINE is the input line editor
  1668. --  Customization can be done via the constant declarations
  1669. -- 
  1670.     function INPUT_LINE return LINE_STRING is
  1671.  
  1672.         WORK_LINE : LINE_STRING;
  1673.         INCHAR    : CHARACTER;
  1674.         INDEX     : NATURAL;
  1675.         POSITION  : NATURAL;
  1676.  
  1677.         procedure BACKUP is -- erase previous character from display
  1678.         begin
  1679.             Scroll_Terminal.PUT (ASCII.BS);  --!Cha
  1680.             Scroll_Terminal.PUT (' ');  --!Cha
  1681.             Scroll_Terminal.PUT (ASCII.BS);  --!Cha
  1682.         end BACKUP;
  1683.  
  1684.         procedure BACKUP_CHARACTER is -- backup over last char w/tab processing
  1685.             INCHAR          : CHARACTER;
  1686.             BACKUP_POSITION : NATURAL;
  1687.         begin
  1688.             INCHAR := WORK_LINE (INDEX); -- extract target character
  1689.             if INCHAR = ASCII.HT then
  1690.                 -- back up over tab
  1691.                 -- compute position prior to this tab
  1692.                 POSITION := 1;
  1693.                 for I in 1 .. INDEX - 1 loop
  1694.                     if WORK_LINE (I) /= ASCII.HT then
  1695.                         POSITION := POSITION + 1;
  1696.                     else
  1697.                         POSITION := POSITION + 1;
  1698.                         while POSITION mod TAB_SIZE /= 1 loop
  1699.                             POSITION := POSITION + 1;
  1700.                         end loop;
  1701.                     end if;
  1702.                 end loop;
  1703.                 -- BACKUP required number of character positions
  1704.                 BACKUP_POSITION := POSITION;
  1705.                 BACKUP;
  1706.                 BACKUP_POSITION := BACKUP_POSITION + 1;
  1707.                 while BACKUP_POSITION mod TAB_SIZE /= 1 loop
  1708.                     BACKUP;
  1709.                     BACKUP_POSITION := BACKUP_POSITION + 1;
  1710.                 end loop;
  1711.             else
  1712. -- back up over normal char
  1713.                 if PRINTING_CHARACTER (INCHAR) then
  1714.                     -- printing char
  1715.                     BACKUP;
  1716.                     POSITION := POSITION - 1;
  1717.                 end if;
  1718.             end if;
  1719.         end BACKUP_CHARACTER;
  1720.  
  1721.         procedure STORE_CHARACTER (INCHAR : CHARACTER) is -- store char
  1722.         begin
  1723.             if INDEX < WORK_LINE'LAST then
  1724.                 -- room for char
  1725.                 WORK_LINE (INDEX) := INCHAR;
  1726.                 INDEX := INDEX + 1;
  1727.             else
  1728.                 -- no room
  1729.                 Scroll_Terminal.PUT (ASCII.BEL);  -- alarm --!Cha
  1730.             end if;
  1731.         end STORE_CHARACTER;
  1732.  
  1733.     begin
  1734.         INDEX := 1;
  1735.         POSITION := 1;
  1736.         loop
  1737.             Scroll_Terminal.GET (INCHAR, Keys);  --!Cha 
  1738.             exit when INCHAR = ASCII.Lf;  --!Cha   was Ascii.CR
  1739.             case INCHAR is
  1740.                 when EDIT_DEL_CHAR =>  -- delete previous character
  1741.                     if INDEX /= 1 then
  1742.                         INDEX := INDEX - 1;
  1743.                         BACKUP_CHARACTER;
  1744.                     else
  1745.                         Scroll_Terminal.PUT (ASCII.BEL);  --!Cha
  1746.                     end if;
  1747.                 when EDIT_DEL_LINE =>  -- delete line typed so far
  1748.                     for I in 1 .. INDEX - 1 loop
  1749.                         INDEX := INDEX - 1;
  1750.                         BACKUP_CHARACTER;
  1751.                     end loop;
  1752.                     INDEX := 1;
  1753.                     POSITION := 1;
  1754.                 when EDIT_RETYPE_LINE =>  -- retype line input so far
  1755.                     NEW_LINE; -- next line
  1756.                     WORK_LINE (INDEX) := ASCII.NUL; -- mark end of line
  1757.                     OUTPUT_LINE (WORK_LINE);
  1758.                 when EDIT_QUOTE =>  -- quote next char
  1759.                     Scroll_Terminal.PUT (EDIT_QUOTE); --!Cha echo EDIT_QUOTE 
  1760.                     POSITION := POSITION + 1; -- EDIT_QUOTE is printing char
  1761.                     Scroll_Terminal.GET (INCHAR, Keys); --!Cha  get quoted char
  1762.                     STORE_CHARACTER (INCHAR);
  1763.                     if PRINTING_CHARACTER (INCHAR) then
  1764.                         Scroll_Terminal.PUT (INCHAR); -- echo it
  1765.                         POSITION := POSITION + 1;
  1766.                     end if;
  1767.                 when ASCII.HT =>  -- tabulate
  1768.                     STORE_CHARACTER (INCHAR);
  1769.                     Scroll_Terminal.PUT (' ');  --!Cha
  1770.                     POSITION := POSITION + 1;
  1771.                     while POSITION mod TAB_SIZE /= 1 loop
  1772.                         Scroll_Terminal.PUT (' ');  --!Cha
  1773.                         POSITION := POSITION + 1;
  1774.                     end loop;
  1775.                 when others =>  -- process next char
  1776.                     STORE_CHARACTER (INCHAR); -- store char
  1777.                     if PRINTING_CHARACTER (INCHAR) then
  1778.                         Scroll_Terminal.PUT (INCHAR);  --!Cha
  1779.                         POSITION := POSITION + 1;
  1780.                     end if;
  1781.             end case;
  1782.         end loop;
  1783.         NEW_LINE;
  1784. -- 
  1785. -- NUL-fill line
  1786. -- 
  1787.         for I in INDEX .. WORK_LINE'LAST loop
  1788.             WORK_LINE (I) := ASCII.NUL;
  1789.         end loop;
  1790. -- 
  1791. -- test for empty line and set BLANK_INPUT
  1792. -- 
  1793.         BLANK_INPUT := TRUE;
  1794.         for I in 1 .. INDEX loop
  1795.             if WORK_LINE (I) > ' ' then
  1796.                 BLANK_INPUT := FALSE;
  1797.                 exit;
  1798.             end if;
  1799.         end loop;
  1800. -- 
  1801. -- return line
  1802. -- 
  1803.         return WORK_LINE;
  1804. -- 
  1805.     end INPUT_LINE;
  1806.  
  1807.  
  1808. -- 
  1809. -- OUTPUT_LINE outputs the string input to the user's terminal.
  1810. -- 
  1811.     procedure OUTPUT_LINE (STR : LINE_STRING) is
  1812.  
  1813.         INDEX    : NATURAL := 1;
  1814.         POSITION : NATURAL := 1;
  1815.  
  1816.     begin
  1817.         loop
  1818.             exit when STR (INDEX) = ASCII.NUL;
  1819.             if STR (INDEX) = ASCII.HT then
  1820.                 -- tabulate
  1821.                 Scroll_Terminal.PUT (' ');  --!Cha
  1822.                 POSITION := POSITION + 1;
  1823.                 while (POSITION mod TAB_SIZE) /= 1 loop
  1824.                     Scroll_Terminal.PUT (' ');  --!Cha
  1825.                     POSITION := POSITION + 1;
  1826.                 end loop;
  1827.             else
  1828.                 -- output character
  1829.                 Scroll_Terminal.PUT (STR (INDEX));  --!Cha
  1830.                 if PRINTING_CHARACTER (STR (INDEX)) then
  1831.                     POSITION := POSITION + 1;
  1832.                 end if;
  1833.             end if;
  1834.             INDEX := INDEX + 1;
  1835.         end loop;
  1836.     end OUTPUT_LINE;
  1837.  
  1838.  
  1839. -- 
  1840. -- GETCH returns the next character without echo
  1841. -- GETCH_WITH_ECHO returns the next character with echo if
  1842. --    ' ' <= ch < DEL
  1843. -- 
  1844.     function GETCH return CHARACTER is
  1845.         INCHAR : CHARACTER;
  1846.     begin
  1847.         Scroll_Terminal.GET (INCHAR, Keys);  --!Cha
  1848.         return INCHAR;
  1849.     end GETCH;
  1850.  
  1851.     function GETCH_WITH_ECHO return CHARACTER is
  1852.         INCHAR : CHARACTER;
  1853.     begin
  1854.         INCHAR := GETCH;
  1855.         if ' ' <= INCHAR and INCHAR < ASCII.DEL then
  1856.             Scroll_Terminal.PUT (INCHAR);  --!Cha
  1857.         end if;
  1858.         return INCHAR;
  1859.     end GETCH_WITH_ECHO;
  1860.  
  1861.  
  1862. -- 
  1863. -- PUT outputs a string
  1864. -- 
  1865.     procedure PUT (INSTR : STRING) is
  1866.     begin
  1867.         for I in 1 .. INSTR'LAST loop
  1868.             Scroll_Terminal.PUT (INSTR (I));  --!Cha
  1869.         end loop;
  1870.     end PUT;
  1871.  
  1872.  
  1873. -- 
  1874. -- NEW_LINE outputs CRLF to the console
  1875. -- 
  1876.     procedure NEW_LINE is
  1877.     begin
  1878.         Scroll_Terminal.PUT (ASCII.CR);  --!Cha
  1879.         Scroll_Terminal.PUT (ASCII.LF);  --!Cha
  1880.     end NEW_LINE;
  1881.  
  1882.  
  1883. -- 
  1884. -- CONVERT_TO_NUMBER converts the number represented by ASCII
  1885. -- digit chars to type NATURAL and returns its value.  VALID_NUMBER
  1886. -- and CTN_INDEX (an I/O value) are returned as side effects.
  1887. -- 
  1888.     function CONVERT_TO_NUMBER (STR : LINE_STRING) return NATURAL is
  1889.  
  1890.         INTERNAL_VALUE : NATURAL;
  1891.         INDEX          : NATURAL;
  1892.         DONE           : BOOLEAN;
  1893.  
  1894.         function IS_DIGIT (IN_CHAR : CHARACTER) return BOOLEAN is
  1895.         begin
  1896.             if IN_CHAR in '0' .. '9' then
  1897.                 return TRUE;
  1898.             else
  1899.                 return FALSE;
  1900.             end if;
  1901.         end IS_DIGIT;
  1902.  
  1903.     begin
  1904.         INTERNAL_VALUE := 0; -- set accumulated value
  1905.         INDEX := CTN_INDEX; -- set start index
  1906.  
  1907.         if IS_DIGIT (STR (INDEX)) then
  1908.             VALID_NUMBER := TRUE; -- input is a number
  1909.         else
  1910.             VALID_NUMBER := FALSE; -- input is not valid
  1911.             return 0; -- return value of 0
  1912.         end if;
  1913.  
  1914.         loop
  1915.             exit when not IS_DIGIT (STR (INDEX));
  1916.             case STR (INDEX) is
  1917.  
  1918.                 when '0'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 0;
  1919.  
  1920.                 when '1'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 1;
  1921.  
  1922.                 when '2'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 2;
  1923.  
  1924.                 when '3'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 3;
  1925.  
  1926.                 when '4'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 4;
  1927.  
  1928.                 when '5'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 5;
  1929.  
  1930.                 when '6'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 6;
  1931.  
  1932.                 when '7'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 7;
  1933.  
  1934.                 when '8'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 8;
  1935.  
  1936.                 when '9'    =>  INTERNAL_VALUE := INTERNAL_VALUE * 10 + 9;
  1937.  
  1938.                 when others =>  null; -- this will not be selected
  1939.             end case;
  1940.             INDEX := INDEX + 1;
  1941.         end loop;
  1942.  
  1943.         CTN_INDEX := INDEX; -- return index of invalid digit
  1944.         return INTERNAL_VALUE;
  1945.  
  1946.     exception
  1947.         when others =>  -- any type of numeric error trapped
  1948.             CTN_INDEX := INDEX; -- index set
  1949.             VALID_NUMBER := FALSE; -- not valid
  1950.             return 0; -- return 0 value
  1951.  
  1952.     end CONVERT_TO_NUMBER;
  1953.  
  1954. end EDIT_SUPPORT;
  1955.  
  1956.  
  1957. --::::::::::::::
  1958. --edit_support-spec.a
  1959. --::::::::::::::
  1960. -- 
  1961. -- PACKAGE edit_support
  1962. --   by Richard Conn, TI Ada Technology Branch
  1963. --   Version 1.0, 9 Nov 84
  1964. --   Version 2.0, 29 Jan 85
  1965. --   Version 2.1, 15 Feb 85
  1966. --   CAIS Version 3.0, 21 August 85
  1967. --   CAIS Version 3.1, 13 Feb 86
  1968. --    NB: changes for the CAIS port are indicated by one of the 
  1969. --        following on each affected line:
  1970. --        --!Rem   Comments, remarks
  1971. --        --!Add   Lines added to the code
  1972. --        --!Del   Lines deleted from the code
  1973. --        --!Cha   Lines changed in the code
  1974. --        (It is a bit subjective; when does a big change become
  1975. --         a delete and an add ?)
  1976. -- 
  1977. -- EDIT_SUPPORT provides a group of low-level support routines
  1978. -- for the editor.  These are basic routines which can be used
  1979. -- by programs other than the editor.
  1980. -- 
  1981. with Editor_List;      --!Cha Renamed from Generic_List to avoid
  1982.             --!Cha name collision with CAIS Prototype
  1983.             --!Cha package named Generic_List (a
  1984.             --!Cha modified version Of R. Conn's orig).
  1985.      --!Cha  TEXT_IO;     used only for Integer_IO; see below...
  1986. package EDIT_SUPPORT is
  1987.  
  1988. -- 
  1989. -- The following establishes the basic set of types, objects,
  1990. -- and linked-list manipulation and numeric I/O routines.
  1991. -- 
  1992.     LINE_LENGTH : constant := 256; -- allow 256 chars/line
  1993.     subtype LINE_STRING is STRING (1 .. LINE_LENGTH);
  1994.     package LINE_LIST is new Editor_List (ELEMENT_OBJECT => LINE_STRING);
  1995.  
  1996.     --!Rem The following instantiation was commented out, because it was
  1997.     --!Rem felt it would be better to not use multiple methods of accessing
  1998.     --!Rem the terminal (e.g Scroll_Terminal AND Num_IO).  Use of Num_IO.Put
  1999.     --!Rem has been replaced with Edit_Support.Put (Integer'image(x))
  2000.  
  2001.     --!Del package NAT_IO is new TEXT_IO.INTEGER_IO (NATURAL);
  2002.  
  2003. -- 
  2004. -- The following are global values which are set by the low-level
  2005. -- support routines.
  2006. -- 
  2007.  
  2008. -- 
  2009. -- BLANK_INPUT is set by the input line editor INPUT_LINE.
  2010. -- If the line just input contained nothing but space characters
  2011. -- (ie, is a blank line), INPUT_LINE sets BLANK_LINE to TRUE.
  2012. -- Else, BLANK_LINE is FALSE.
  2013. -- 
  2014.     BLANK_INPUT : BOOLEAN := TRUE;
  2015.  
  2016. -- 
  2017. -- VALID_NUMBER is set by the string-to-natural conversion routine
  2018. -- CONVERT_TO_NUMBER.  If the string passed in does not begin with
  2019. -- a valid digit character ('0' to '9'), VALID_NUMBER is set to FALSE
  2020. -- and the value of 0 is returned by CONVERT_TO_NUMBER.  Else,
  2021. -- VALID_NUMBER is set to TRUE and the converted number is returned.
  2022. -- 
  2023.     VALID_NUMBER : BOOLEAN := FALSE;
  2024.  
  2025. -- 
  2026. -- CTN_INDEX is set by the caller of CONVERT_TO_NUMBER to tell it
  2027. -- where to begin the conversion.  This number is the index
  2028. -- of the first character at which to begin conversion.  On exit,
  2029. -- CTN_INDEX is the index of the character at which conversion was
  2030. -- halted.
  2031. -- 
  2032.     CTN_INDEX : NATURAL;
  2033.  
  2034. -- 
  2035. -- The following are the workhorse routines of this package.
  2036. -- 
  2037.  
  2038. -- 
  2039. --      These routines initialize and deinitialize the
  2040. -- console.  They should be called at the beginning and at
  2041. -- the end of the edit session.
  2042. -- 
  2043.     procedure CONSOLE_INIT;
  2044.     procedure CONSOLE_DEINIT;
  2045.  
  2046. -- 
  2047. -- INPUT_LINE is a function which provides an input line editor.
  2048. -- It accepts characters from the user until an end-of-line
  2049. -- character is received, at which point INPUT_LINE terminates and
  2050. -- returns an object of type LINE_STRING to the caller.  INPUT_LINE
  2051. -- allows simple editing of the input text as it is typed, permitting
  2052. -- the user to delete previous characters, delete input entered so
  2053. -- far, retype the line as entered so far, and quote a character for
  2054. -- literal input.  INPUT_LINE will not permit the limit of the input
  2055. -- buffer to be exceeded.
  2056. -- 
  2057. --   BLANK_LINE is set to TRUE if only blank characters are
  2058. -- contained in the line.
  2059. -- 
  2060. --   The following constants may be changed as desired:
  2061. -- 
  2062. --      Constant               Meaning
  2063. --     EDIT_DEL_CHAR          Delete previous character in buffer
  2064. --     EDIT_DEL_LINE          Restart buffer entry
  2065. --     EDIT_RETYPE_LINE       Retype input line as entered so far
  2066. --     EDIT_QUOTE             Quote following character
  2067. -- 
  2068.     function INPUT_LINE return LINE_STRING;
  2069.  
  2070. -- 
  2071. --      Return next char without echo
  2072. --      Return next char with echo if >= ' ' and < DEL
  2073. -- 
  2074.     function GETCH           return CHARACTER;
  2075.     function GETCH_WITH_ECHO return CHARACTER;
  2076.  
  2077.  
  2078. -- 
  2079. --      Provides put string routine
  2080. -- 
  2081.     procedure PUT (INSTR : STRING);
  2082.  
  2083.  
  2084. -- 
  2085. --      Echo CRLF
  2086. -- 
  2087.     procedure NEW_LINE;
  2088.  
  2089.  
  2090. -- 
  2091. -- OUTPUT_LINE is a procedure which outputs an object of type
  2092. -- LINE_STRING to the user's terminal.  Tab expansion is supported,
  2093. -- and no trailing nulls are output.
  2094. -- 
  2095.     procedure OUTPUT_LINE (STR : LINE_STRING);
  2096.  
  2097.  
  2098. -- 
  2099. -- CONVERT_TO_NUMBER accepts as input an object of type
  2100. -- LINE_STRING and converts the ASCII characters starting at
  2101. -- the global index CTN_INDEX to a natural number.  The value
  2102. -- of this number is returned, and CTN_INDEX is updated to
  2103. -- indicate the index of the character which stopped the number
  2104. -- scan.
  2105. -- 
  2106. --  VALID_NUMBER is set to TRUE if the first character is an
  2107. -- ASCII digit character ('0' to '9'); VALID_NUMBER is set to
  2108. -- FALSE if the first character is not a digit
  2109. -- 
  2110. --  CTN_INDEX is returned with the index of the character which
  2111. -- stopped the scan/conversion process.
  2112. -- 
  2113.     function CONVERT_TO_NUMBER (STR : LINE_STRING) return NATURAL;
  2114.  
  2115. end EDIT_SUPPORT;
  2116.  
  2117.  
  2118. --::::::::::::::
  2119. --edit_worker-body.a
  2120. --::::::::::::::
  2121. -- Package Body of EDIT_WORKER
  2122. -- by Richard Conn, Texas Instruments, Ada Technology Branch
  2123. -- Version 1.0, Date 20 Nov 84
  2124. -- Version 2.0, Date 31 Jan 85
  2125. -- Version 2.1, Date 15 Feb 85
  2126. --   CAIS Version 3.0, 21 August 85
  2127. --   CAIS Version 3.1, 13 Feb 86
  2128. --    NB: changes for the port are indicated by one of the 
  2129. --        following on each affected line:
  2130. --        --!Rem   Comments, remarks
  2131. --        --!Add   Lines added to the code
  2132. --        --!Del   Lines deleted from the code
  2133. --        --!Cha   Lines changed in the code
  2134. --        (it is a bit subjective; when does a big change become
  2135. --         a delete and an add ?)
  2136. -- 
  2137. --!Rem Instantiation of Integer_IO was commented out, because it was
  2138. --!Rem felt it would be better to not use multiple methods of accessing
  2139. --!Rem the terminal (e.g Scroll_Terminal AND Num_IO).  Use of Integer_IO.Put
  2140. --!Rem has been replaced with Edit_Support.Put (Integer'image(x))
  2141. -- 
  2142. -- This package contains all of the procedures which implement
  2143. -- the major commands of the editor.  EDIT_WORKER is divided into
  2144. -- functional sections (more or less), with each section separated
  2145. -- from the others by lines like "--=============".
  2146. -- 
  2147. -- The package is divided into the following sections:
  2148. -- 
  2149. -- SECTION              FUNCTION
  2150. --!Del  Package NUM_IO       Provide numeric output for NATURAL numbers
  2151. -- RANGE_INPUT          Provide general-purpose line range input
  2152. -- CURRENT_LINE         Returns the number of the current line
  2153. -- LAST_LINE            Returns the number of the last line
  2154. -- ADVANCE_LINE         Advances to the next line
  2155. -- BACKUP_LINE          Back ups to the last line
  2156. -- Line Output          Print lines and info to the terminal
  2157. --   INPUT_LINE_PROMPT
  2158. --   NUMBER_PREFIX
  2159. --   PREFIX_PRINT
  2160. -- COMMAND_GOTO         Implements the Jump (J) Command and Used Internally
  2161. -- COMMAND_APPEND       Implements the Append (A) Command
  2162. -- COMMAND_INSERT       Implements the Insert (I) Command
  2163. -- COMMAND_LIST         Implements the List (L) Command
  2164. -- COMMAND_DELETE       Implements the Delete (D) Command
  2165. -- Scanning Aids        Lower-level functions/procedures for Substitute
  2166. --   SUB_STRING           and Find
  2167. --   COUNT_CHARS
  2168. --   SUBSTITUTE
  2169. -- COMMAND_SUBSTITUTE   Implements the Substitute (S) Command
  2170. -- COMMAND_FIND         Implements the Find (F) Command
  2171. -- GET and PUT Support  Routines to Support File Input/Output
  2172. --   WRITE_FLINE
  2173. --   PUT_RANGE
  2174. --   READ_FILE
  2175. -- COMMAND_GET          Implements the Get (G) Command
  2176. -- COMMAND_PUT          Implements the Put (P) Command
  2177. -- 
  2178.  
  2179. with Cais;
  2180. with EDIT_SUPPORT;
  2181. use EDIT_SUPPORT;
  2182.  
  2183. package body EDIT_WORKER is
  2184.  
  2185. -- 
  2186. -- LINE_EXIT_CHAR is the character which, when it appears as the first
  2187. -- character of a line and it is the only character on that line, indicates
  2188. -- that the last line has been input for the Append and Insert Commands.
  2189. -- 
  2190.     LINE_EXIT_CHAR : constant CHARACTER := '.';
  2191.  
  2192. --===================================================================
  2193. -- Package NUM_IO
  2194. --     Generic Instantiation of TEXT_IO.INTEGER_IO for NATURAL numbers
  2195. -- 
  2196.     --!Del package NUM_IO is new TEXT_IO.INTEGER_IO (NATURAL);
  2197.  
  2198. --===================================================================
  2199. -- RANGE_INPUT inputs one or two values, and it always returns with
  2200. -- LINE_START containing the first value and LINE_STOP containing the
  2201. -- second.  LINE_START <= LINE_STOP, and if there was any error in
  2202. -- the input, the exception RANGE_ERROR is raised
  2203. -- 
  2204.     procedure RANGE_INPUT is
  2205.  
  2206.         INTERNAL_ERROR : exception;
  2207.         PAGE_SIZE  : constant NATURAL := 20; -- number of lines/"page"
  2208.         RANGE_LINE : LINE_STRING;
  2209.         I          : NATURAL; -- index of next char in input line
  2210.         DONE       : BOOLEAN := FALSE;
  2211.  
  2212. -- 
  2213. -- Local procedure FLUSH_SPACES - skip over spaces until non-space,
  2214. -- including end-of-line (ASCII.nul), is encountered
  2215. -- 
  2216.         procedure FLUSH_SPACES is
  2217.         begin
  2218.             loop
  2219.                 exit when RANGE_LINE (I) /= ' ';
  2220.                 I := I + 1;
  2221.             end loop;
  2222.         end FLUSH_SPACES;
  2223.  
  2224. -- 
  2225. -- The body of RANGE_INPUT
  2226. -- 
  2227.     begin
  2228.         I := 1; -- index of first char
  2229.         PUT (" "); -- space (prompt)
  2230.         RANGE_LINE := INPUT_LINE; -- input line (with editing)
  2231.         if BLANK_INPUT then
  2232.             LINE_START := LINE_LIST.CURRENT_INDEX; -- set first and last to .
  2233.             LINE_STOP := LINE_START;
  2234.             return; -- done
  2235.         end if;
  2236.  
  2237.         FLUSH_SPACES; -- get rid of leading spaces
  2238.  
  2239. -- 
  2240. -- Check for an process the First Argument
  2241. -- 
  2242.         case RANGE_LINE (I) is
  2243. -- first of one or two arguments
  2244.             when '+' =>  -- current line + offset
  2245.                 CTN_INDEX := I + 1; -- set starting index
  2246.                 LINE_START := LINE_LIST.CURRENT_INDEX +
  2247.                               CONVERT_TO_NUMBER (RANGE_LINE);
  2248.                 LINE_STOP := LINE_START;
  2249.                 I := CTN_INDEX; -- restore index
  2250.             when '-' =>  -- current line - offset
  2251.                 CTN_INDEX := I + 1; -- set starting index
  2252.                 LINE_START := LINE_LIST.CURRENT_INDEX -
  2253.                               CONVERT_TO_NUMBER (RANGE_LINE);
  2254.                 LINE_STOP := LINE_START;
  2255.                 I := CTN_INDEX; -- restore index
  2256.             when 'a' | 'A' =>  -- all lines
  2257.                 LINE_START := 1;
  2258.                 LINE_STOP := LINE_LIST.LAST_INDEX;
  2259.                 I := I + 1; -- next char
  2260.             when 'c' | 'C' | '.' =>  -- current line
  2261.                 LINE_START := LINE_LIST.CURRENT_INDEX;
  2262.                 LINE_STOP := LINE_START;
  2263.                 I := I + 1; -- next char
  2264.             when 'f' | 'F' =>  -- first line
  2265.                 LINE_START := 1;
  2266.                 LINE_STOP := LINE_START;
  2267.                 I := I + 1; -- next char
  2268.             when 'l' | 'L' =>  -- last line
  2269.                 LINE_START := LINE_LIST.LAST_INDEX;
  2270.                 LINE_STOP := LINE_START;
  2271.                 I := I + 1; -- next char
  2272.             when 'p' | 'P' =>  -- page
  2273.                 LINE_START := LINE_LIST.CURRENT_INDEX;
  2274.                 if LINE_START + PAGE_SIZE > LINE_LIST.LAST_INDEX then
  2275.                     LINE_STOP := LINE_LIST.LAST_INDEX;
  2276.                 else
  2277.                     LINE_STOP := LINE_START + PAGE_SIZE;
  2278.                 end if;
  2279.                 I := I + 1; -- next char
  2280.             when '0' .. '9' => 
  2281.                 CTN_INDEX := I;
  2282.                 LINE_START := CONVERT_TO_NUMBER (RANGE_LINE);
  2283.                 LINE_STOP := LINE_START;
  2284.                 I := CTN_INDEX;
  2285.             when others => 
  2286.                 raise INTERNAL_ERROR;
  2287.         end case;
  2288.  
  2289. -- 
  2290. -- Check for possible range errors
  2291. -- 
  2292.         if LINE_START > LINE_LIST.LAST_INDEX then  raise RANGE_ERROR;  end if;
  2293.         if LINE_STOP > LINE_LIST.LAST_INDEX then  raise RANGE_ERROR;  end if;
  2294.  
  2295. -- 
  2296. -- Advance to next token
  2297. -- 
  2298.         FLUSH_SPACES; -- flush spaces between entires
  2299.  
  2300. -- 
  2301. -- Done if no next token
  2302. -- 
  2303.         if RANGE_LINE (I) = ASCII.NUL then
  2304.             return;
  2305.         end if;
  2306.  
  2307. -- 
  2308. -- If a comma is present, a second argument is given
  2309. -- 
  2310.         if RANGE_LINE (I) = ',' then
  2311.             I := I + 1;
  2312.             FLUSH_SPACES;
  2313.             if RANGE_LINE (I) = ASCII.NUL then
  2314.                 raise INTERNAL_ERROR;
  2315.             end if;
  2316.         end if;
  2317.  
  2318. -- 
  2319. -- Process Second Argument of an argument pair
  2320. -- The value of this argument is assigned to LINE_STOP
  2321. -- 
  2322.         case RANGE_LINE (I) is
  2323. -- second of two arguments
  2324.             when '+' =>  -- current line + offset
  2325.                 CTN_INDEX := I + 1;
  2326.                 LINE_STOP := LINE_LIST.CURRENT_INDEX +
  2327.                              CONVERT_TO_NUMBER (RANGE_LINE);
  2328.                 I := CTN_INDEX;
  2329.             when '-' =>  -- current line - offset
  2330.                 CTN_INDEX := I + 1;
  2331.                 LINE_STOP := LINE_LIST.CURRENT_INDEX -
  2332.                              CONVERT_TO_NUMBER (RANGE_LINE);
  2333.                 I := CTN_INDEX;
  2334.             when 'c' | 'C' | '.' =>  -- current line
  2335.                 LINE_STOP := LINE_LIST.CURRENT_INDEX;
  2336.             when 'f' | 'F' =>  -- first line
  2337.                 LINE_STOP := 1;
  2338.             when 'l' | 'L' =>  -- last line
  2339.                 LINE_STOP := LINE_LIST.LAST_INDEX;
  2340.             when '0' .. '9' => 
  2341.                 CTN_INDEX := I;
  2342.                 LINE_STOP := CONVERT_TO_NUMBER (RANGE_LINE);
  2343.                 I := CTN_INDEX;
  2344.             when others => 
  2345.                 raise INTERNAL_ERROR;
  2346.         end case;
  2347.  
  2348. -- 
  2349. -- Check out possible range errors
  2350. -- 
  2351.         if LINE_STOP > LINE_LIST.LAST_INDEX then  raise RANGE_ERROR;  end if;
  2352.  
  2353. -- 
  2354. -- Handle Exceptions Raised within the procedure RANGE_INPUT
  2355. -- 
  2356.     exception
  2357.         when NUMERIC_ERROR => 
  2358.             NEW_LINE;
  2359.             PUT ("       Numeric Value Error");
  2360.             LINE_START := 0;
  2361.             LINE_STOP := 0;
  2362.             raise RANGE_ERROR;
  2363.         when INTERNAL_ERROR => 
  2364.             NEW_LINE;
  2365.             PUT ("       Range Syntax Error");
  2366.             LINE_START := 0;
  2367.             LINE_STOP := 0;
  2368.             raise RANGE_ERROR;
  2369.         when RANGE_ERROR => 
  2370.             NEW_LINE;
  2371.             PUT ("       Range Value Error");
  2372.             LINE_START := 0;
  2373.             LINE_STOP := 0;
  2374.             raise RANGE_ERROR;
  2375.         when others => 
  2376.             NEW_LINE;
  2377.             PUT ("       Unknown Error in RANGE_INPUT");
  2378.             LINE_START := 0;
  2379.             LINE_STOP := 0;
  2380.             raise RANGE_ERROR;
  2381.  
  2382.     end RANGE_INPUT;
  2383.  
  2384.  
  2385. --===================================================================
  2386. -- 
  2387. -- CURRENT_LINE
  2388. -- This function returns the number of the current line
  2389. -- 
  2390.  
  2391.     function CURRENT_LINE return NATURAL is
  2392.     begin
  2393.         return LINE_LIST.CURRENT_INDEX;
  2394.     end CURRENT_LINE;
  2395.  
  2396.  
  2397. --===================================================================
  2398. -- 
  2399. -- LAST_LINE
  2400. -- This function returns the number of the last line
  2401. -- 
  2402.  
  2403.     function LAST_LINE return NATURAL is
  2404.     begin
  2405.         return LINE_LIST.LAST_INDEX;
  2406.     end LAST_LINE;
  2407.  
  2408.  
  2409. --===================================================================
  2410. -- 
  2411. -- ADVANCE_LINE
  2412. -- This function advances the current line by one
  2413. -- 
  2414.  
  2415.     procedure ADVANCE_LINE is
  2416.         DUMMY : BOOLEAN;
  2417.     begin
  2418.         DUMMY := LINE_LIST.CURRENT_NEXT;
  2419.     end ADVANCE_LINE;
  2420.  
  2421.  
  2422. --===================================================================
  2423. -- 
  2424. -- BACKUP_LINE
  2425. -- This procedure back ups the current line by one
  2426. -- 
  2427.  
  2428.     procedure BACKUP_LINE is
  2429.         DUMMY : BOOLEAN;
  2430.     begin
  2431.         DUMMY := LINE_LIST.CURRENT_PREVIOUS;
  2432.     end BACKUP_LINE;
  2433.  
  2434.  
  2435.  
  2436. --===================================================================
  2437. -- 
  2438. -->> Procedure INPUT_LINE_PROMPT
  2439. -- This procedure simply prints the prompt for the Append and Insert
  2440. --  commands.
  2441. -- 
  2442.  
  2443.     procedure INPUT_LINE_PROMPT is
  2444.     begin
  2445.         PUT ("Enter Lines (");
  2446.         --!Rem ?Why was Text_IO used instead of Edit_Support?
  2447.         --!Rem TEXT_IO.PUT (LINE_EXIT_CHAR);    <<= original code
  2448.         PUT ("" & LINE_EXIT_CHAR);  --!Cha  (cheating to make it a string)
  2449.         PUT ("<RETURN> to Stop)");
  2450.         NEW_LINE;
  2451.     end INPUT_LINE_PROMPT;
  2452.  
  2453. -- 
  2454. -->> Procedure NUMBER_PREFIX
  2455. -- This routine prints the prefix number ("nnnnn: ") for lines
  2456. --  that are displayed or input.
  2457. -- 
  2458.     procedure NUMBER_PREFIX (NUM : NATURAL) is
  2459.     begin
  2460.         --!Rem original line: NUM_IO.PUT (INTEGER (NUM), 5);
  2461.         PUT (Integer'image(Num));  --!Cha
  2462.         PUT (": "); -- trailing prompt
  2463.     end NUMBER_PREFIX;
  2464.  
  2465. -- 
  2466. -->> Procedure PREFIX_PRINT
  2467. -- This routine prints a line prefixed by a number ("nnnnn: text").
  2468. -- 
  2469.     procedure PREFIX_PRINT (NUM : NATURAL; STR : LINE_STRING) is
  2470.     begin
  2471.         NUMBER_PREFIX (NUM);
  2472.         OUTPUT_LINE (STR);
  2473.     end PREFIX_PRINT;
  2474.  
  2475. --===================================================================
  2476. -- Procedure INITIALIZE_EDIT
  2477. -- This procedure initializes the editor for future processing
  2478. -- 
  2479.     procedure INITIALIZE_EDIT is
  2480.     begin
  2481.         LINE_LIST.INITIALIZE_LIST;
  2482.     end INITIALIZE_EDIT;
  2483.  
  2484.  
  2485. --===================================================================
  2486. -- Procedure COMMAND_GOTO
  2487. -- This procedure positions the current line to the indicated index.
  2488. -- That is, if NUM = 5, the fifth line in the file becomes the current line.
  2489. -- 
  2490.     procedure COMMAND_GOTO (NUM : NATURAL) is
  2491.         I     : NATURAL;
  2492.         DUMMY : BOOLEAN;
  2493.     begin
  2494.         if NUM <= LINE_LIST.LAST_INDEX then
  2495.             I := NUM;
  2496.         else
  2497.             I := LINE_LIST.LAST_INDEX;
  2498.         end if;
  2499.         DUMMY := LINE_LIST.SET_CURRENT_INDEX (I); -- return code is a don't care
  2500.     end COMMAND_GOTO;
  2501.  
  2502. --===================================================================
  2503. -- Procedure COMMAND_APPEND
  2504. -- This procedure implements the Append command.  It accepts a group of
  2505. -- lines one at a time, appends the new line after the current line, makes
  2506. -- the new line the current line, and continues until a line consisting of
  2507. -- only a LINE_EXIT_CHAR is input.
  2508. -- 
  2509.     procedure COMMAND_APPEND is
  2510.         INLINE : LINE_STRING;
  2511.     begin
  2512.         INPUT_LINE_PROMPT; -- print prompt
  2513.         loop
  2514.             NUMBER_PREFIX (LINE_LIST.CURRENT_INDEX + 1); -- print number of line
  2515.             INLINE := INPUT_LINE; -- get input line
  2516.             exit when (INLINE (1) = LINE_EXIT_CHAR) and
  2517.                       (INLINE (2) = ASCII.NUL); -- test for exit condition
  2518.             LINE_LIST.APPEND_ELEMENT (INLINE); -- append line after current
  2519.         end loop;
  2520.     end COMMAND_APPEND;
  2521.  
  2522. --===================================================================
  2523. -- Procedure COMMAND_INSERT
  2524. -- This procedure is like COMMAND_APPEND, but the input lines are inserted
  2525. -- before the current line.
  2526. -- 
  2527.     procedure COMMAND_INSERT is
  2528.         INLINE : LINE_STRING;
  2529.     begin
  2530.         INPUT_LINE_PROMPT; -- print prompt
  2531.         loop
  2532.             NUMBER_PREFIX (LINE_LIST.CURRENT_INDEX); -- print line number
  2533.             INLINE := INPUT_LINE; -- get new line
  2534.             exit when (INLINE (1) = LINE_EXIT_CHAR) and
  2535.                       (INLINE (2) = ASCII.NUL); -- test for exit condition
  2536.             LINE_LIST.INSERT_ELEMENT (INLINE); -- perform insertion
  2537.         end loop;
  2538.     end COMMAND_INSERT;
  2539.  
  2540. --===================================================================
  2541. -- Procedure COMMAND_LIST
  2542. -- This procedure lists a group of lines over a range.  The range is
  2543. -- indicated by the global variables LINE_START and LINE_STOP, which are
  2544. -- set by the RANGE_INPUT routine and may be set by other routines as well.
  2545. -- 
  2546.     procedure COMMAND_LIST is
  2547.         --Del Not needed  I     : NATURAL;
  2548.         DUMMY : BOOLEAN;
  2549.     begin
  2550.         COMMAND_GOTO (LINE_START); -- position at first line
  2551.         for I in 1 .. LINE_STOP - LINE_START + 1 loop
  2552.             -- over lines in range
  2553.             PREFIX_PRINT (LINE_LIST.CURRENT_INDEX,
  2554.                           LINE_LIST.RETURN_CURRENT_ELEMENT); -- print line
  2555.             NEW_LINE;
  2556.             exit when not LINE_LIST.CURRENT_NEXT; -- adv to next line, check end
  2557.                                                   -- of list and exit if done
  2558.         end loop;
  2559.         if LINE_STOP /= LINE_LIST.LAST_INDEX then
  2560.             DUMMY := LINE_LIST.CURRENT_PREVIOUS; -- back up, for we have
  2561.                                                  -- gone too far
  2562.         end if;
  2563.     end COMMAND_LIST;
  2564.  
  2565. --===================================================================
  2566. -- Procedure COMMAND_DELETE
  2567. -- This procedure deletes lines over the range from LINE_START to LINE_STOP.
  2568. -- This range is a pair of global values which are set by RANGE_INPUT and
  2569. -- possibly by other routines.
  2570. -- 
  2571.     procedure COMMAND_DELETE is
  2572.         --Del Not needed   I     : NATURAL;
  2573.         DUMMY : BOOLEAN;
  2574.     begin
  2575.         COMMAND_GOTO (LINE_START); -- position to first line
  2576.         for I in 1 .. LINE_STOP - LINE_START + 1 loop
  2577.             LINE_LIST.DELETE_ELEMENT; -- delete current line
  2578.         end loop;
  2579.     end COMMAND_DELETE;
  2580.  
  2581. --===================================================================
  2582. -- COMMAND_SUBSTITUTE requires the following support routines, which are
  2583. -- contained within this functional area.
  2584. -- 
  2585. --      ROUTINE         FUNCTION
  2586. --      SUB_STRING      Determine if SUB_LINE is a substring of TARGET_LINE
  2587. --                        starting at position START_POS
  2588. --      COUNT_CHARS     Count the number of characters in the passed string,
  2589. --                        up to but not including the terminating ASCII.nul
  2590. --      SUBSTITUTE      Substitute NEW_STRING for OLD_STRING in TARGET_LINE
  2591. --                        starting at position FOUND_LOC (which is returned
  2592. -- 
  2593.  
  2594.  
  2595. -- 
  2596. -->> Function SUB_STRING
  2597. -- This function scans for the string SUB_LINE in the string TARGET_LINE
  2598. -- starting at the position START_POS.  Both strings are character sequences
  2599. -- terminated by ASCII.nul.  If found, SUB_STRING returns a positive number
  2600. -- which is the index in TARGET_LINE of the first character of the substring
  2601. -- SUB_LINE; the procedure SUBSTITUTE may be used to actually perform the
  2602. -- substitution, given this return value.  If not found, SUB_STRING returns
  2603. -- the number 0.
  2604. -- 
  2605.     function SUB_STRING (TARGET_LINE, SUB_LINE : LINE_STRING;
  2606.                          START_POS             : NATURAL) return NATURAL is
  2607.         FOUND_POS : NATURAL;
  2608.         TI        : NATURAL; --!Cha   SI was deleted (not used)
  2609.         ANSWER    : BOOLEAN;
  2610.  
  2611.     begin
  2612. -- 
  2613. -- This initialization could have been done in the declarations above.
  2614. -- Old habits (from Pascal) are sometimes hard to break.
  2615. -- 
  2616.         TI := START_POS; -- set index in target line
  2617.         FOUND_POS := 0; -- initialize value to not found
  2618.         ANSWER := FALSE; -- ANSWER=TRUE if substring found
  2619. -- 
  2620. -- This is the major loop of SUB_STRING.  It advances through the TARGET_LINE
  2621. -- one character at a time, checking to see if SUB_LINE is duplicated in
  2622. -- TARGET_LINE starting at the current position.
  2623. -- 
  2624.         loop
  2625.             exit when TARGET_LINE (TI) = ASCII.NUL; -- done if at end of target
  2626. -- 
  2627. -- This is the minor loop of SUB_STRING.  It advances through SUB_LINE,
  2628. -- comparing each character in SUB_LINE to the corresponding (relative)
  2629. -- character in TARGET_LINE until either the end of SUB_LINE is reached
  2630. -- (in which case the substring has been found at TI, the current position
  2631. -- in TARGET_LINE) or the current character in SUB_LINE does not match
  2632. -- the current character in TARGET_LINE (in which case we advance to the
  2633. -- next character in TARGET_LINE and try again if the end of TARGET_LINE
  2634. -- has not been reached).
  2635. -- 
  2636.             for SI in 1 .. LINE_LENGTH loop
  2637.                 if SUB_LINE (SI) = ASCII.NUL then
  2638.                     -- exit if complete match
  2639.                     ANSWER := TRUE;
  2640.                     exit;
  2641.                 end if;
  2642.                 exit when TARGET_LINE (TI + SI - 1) /= SUB_LINE (SI);
  2643.             end loop;
  2644. -- 
  2645. -- We are now out of the preceeding FOR loop.  If ANSWER is TRUE, we got here
  2646. -- from the IF, which means we found a match.
  2647. -- 
  2648.             if ANSWER then
  2649.                 FOUND_POS := TI; -- mark position in target line and ...
  2650.                 exit;      -- ... exit major loop
  2651.             end if;
  2652. -- 
  2653. -- We have not matched the SUB_LINE yet; advance to the next character in
  2654. -- the TARGET_LINE.
  2655. -- 
  2656.             TI := TI + 1; -- advance to next char in target line
  2657.         end loop;
  2658. -- 
  2659. -- If the substring was found, FOUND_POS is non-zero.  If not, FOUND_POS
  2660. -- still retains its original value of zero.
  2661. -- 
  2662.         return (FOUND_POS);
  2663.  
  2664.     end SUB_STRING;
  2665.  
  2666. -- 
  2667. -->> Function COUNT_CHARS
  2668. -- The following function determines the number of characters in the
  2669. -- string (which is terminated by an ASCII.nul) passed to it.  This
  2670. -- character count does not include the terminating ASCII.nul.
  2671. -- 
  2672.     function COUNT_CHARS (STR : LINE_STRING) return NATURAL is
  2673.         J, K : NATURAL;   --!Cha declaration for I removed (not used)
  2674.     begin
  2675.         J := LINE_LENGTH + 1;
  2676.         K := 0;
  2677.         for I in 1 .. J loop
  2678.             exit when STR (I) = ASCII.NUL;
  2679.             K := I;
  2680.         end loop;
  2681.         return (K); -- the loop exits on the ASCII.nul
  2682.     exception
  2683.         when others =>  -- must have exceeded dimension of STR
  2684.             return (LINE_LENGTH);
  2685.     end COUNT_CHARS;
  2686.  
  2687. -- 
  2688. -->> Procedure SUBSTITUTE
  2689. -- This procedure substitutes NEW_STRING for OLD_STRING in TARGET_LINE
  2690. -- starting at the position indicated by FOUND_LOC.  The value of FOUND_LOC
  2691. -- was determined by the routine SUB_STRING and is assumed to be correct
  2692. -- (ie, OLD_STRING starts at index FOUND_LOC in TARGET_LINE).
  2693. -- 
  2694.     procedure SUBSTITUTE (TARGET_LINE            : in out LINE_STRING;
  2695.                           OLD_STRING, NEW_STRING : LINE_STRING;
  2696.                           FOUND_LOC              : in out NATURAL) is
  2697.  
  2698.         SIZE_NEW, SIZE_OLD, SIZE_TARGET : NATURAL;
  2699.         I, NEXT_CHAR                    : NATURAL;
  2700.         RETURN_LOC                      : NATURAL;
  2701.         TEMP_LINE                       : LINE_STRING;
  2702.  
  2703. -- 
  2704. -- This is the mainline of SUBSTITUTE
  2705. -- 
  2706.     begin
  2707. -- 
  2708. -- Determine sizes of the three strings -- TARGET, OLD, and NEW
  2709. -- 
  2710.         SIZE_TARGET := COUNT_CHARS (TARGET_LINE);
  2711.         SIZE_OLD := COUNT_CHARS (OLD_STRING);
  2712.         SIZE_NEW := COUNT_CHARS (NEW_STRING);
  2713.  
  2714. -- 
  2715. -- Copy the TARGET_LINE up to but not including the point of substitution
  2716. -- 
  2717.         if FOUND_LOC /= 1 then
  2718.             TEMP_LINE (1 .. FOUND_LOC - 1) := TARGET_LINE (1 .. FOUND_LOC - 1);
  2719.             NEXT_CHAR := FOUND_LOC;
  2720.         else
  2721.             NEXT_CHAR := 1;
  2722.         end if;
  2723.  
  2724. -- 
  2725. -- Append the NEW_STRING to the end of the line being built
  2726. -- 
  2727.         if SIZE_NEW /= 0 then
  2728.             for Tmp in 1 .. SIZE_NEW loop   --!Cha I changed to Tmp
  2729.                 TEMP_LINE (NEXT_CHAR) := NEW_STRING (Tmp);--!Cha ditto
  2730.                 NEXT_CHAR := NEXT_CHAR + 1;
  2731.             end loop;
  2732.         end if;
  2733.  
  2734. -- 
  2735. -- Determine the index of the next character after the OLD_STRING in TARGET_LINE
  2736. -- 
  2737.         I := FOUND_LOC + SIZE_OLD;
  2738.  
  2739. -- 
  2740. -- Append the characters after OLD_STRING in TARGET_LINE to the end of the
  2741. -- line being built.
  2742. -- 
  2743.         loop
  2744.             exit when TARGET_LINE (I) = ASCII.NUL;
  2745.             TEMP_LINE (NEXT_CHAR) := TARGET_LINE (I);
  2746.             NEXT_CHAR := NEXT_CHAR + 1;
  2747.             I := I + 1;
  2748.         end loop;
  2749.  
  2750. -- 
  2751. -- Fill out the rest of the line which is being built with ASCII.nul chars
  2752. -- 
  2753.         for Tmp in NEXT_CHAR .. LINE_LENGTH loop  --!Cha I changed to Tmp
  2754.             TEMP_LINE (Tmp) := ASCII.NUL;       --!Cha I changed to Tmp
  2755.         end loop;
  2756.  
  2757. -- 
  2758. -- Replace the original TARGET_LINE with the line being built.
  2759. -- Also return the position to resume the scan in the TARGET_LINE in case
  2760. -- there is more than one occurrance of the substring.
  2761. -- 
  2762.         TARGET_LINE := TEMP_LINE;
  2763.         FOUND_LOC := FOUND_LOC + SIZE_NEW;
  2764.  
  2765.     end SUBSTITUTE;
  2766.  
  2767. --===================================================================
  2768. -- Procedure COMMAND_SUBSTITUTE
  2769. -- This procedure implements the Substitute command.  The range of lines
  2770. -- over which to perform the substitution is provided by RANGE_INPUT as
  2771. -- the global variables LINE_START and LINE_STOP, and the string OLD_STRING
  2772. -- contains the string to be substituted while the string NEW_STRING contains
  2773. -- the string to substitute for OLD_STRING.
  2774. -- 
  2775.     procedure COMMAND_SUBSTITUTE (OLD_STRING, NEW_STRING : LINE_STRING) is
  2776.         FOUND_LOC : NATURAL;
  2777.         TEMP_LINE : LINE_STRING;
  2778.     begin
  2779.         COMMAND_GOTO (LINE_START); -- goto first line in range
  2780.         FOUND_LOC := 1;     -- start at position 1 in first line
  2781.  
  2782. -- 
  2783. -- Major loop for substitution.  Each line is examined at least once, and,
  2784. -- if a substitution is performed, the line is passed over again to see
  2785. -- if the OLD_STRING occurrs in the line twice.
  2786. -- 
  2787.         loop
  2788.             exit when LINE_LIST.CURRENT_INDEX > LINE_STOP;
  2789. -- 
  2790. -- See if OLD_STRING is contained in the current line.
  2791. -- 
  2792.             FOUND_LOC := SUB_STRING
  2793.                             (LINE_LIST.RETURN_CURRENT_ELEMENT, OLD_STRING,
  2794.                              FOUND_LOC);
  2795. -- 
  2796. -- Replace OLD_STRING with NEW_STRING and look again after last character
  2797. -- in NEW_STRING within the current line if found; reset starting position
  2798. -- of search and advance to next line if not found.
  2799. -- 
  2800.             if FOUND_LOC /= 0 then
  2801.                 TEMP_LINE := LINE_LIST.RETURN_CURRENT_ELEMENT;
  2802.                 SUBSTITUTE (TEMP_LINE, OLD_STRING, NEW_STRING, FOUND_LOC);
  2803.                 LINE_LIST.RETURN_CURRENT_ELEMENT.CONTENT := TEMP_LINE;
  2804.                 PREFIX_PRINT (LINE_LIST.CURRENT_INDEX,
  2805.                               LINE_LIST.RETURN_CURRENT_ELEMENT);
  2806.                 NEW_LINE;
  2807.             else
  2808.                 FOUND_LOC := 1;
  2809.                 exit when not LINE_LIST.CURRENT_NEXT;
  2810.             end if;
  2811.  
  2812.         end loop;
  2813.  
  2814.     end COMMAND_SUBSTITUTE;
  2815.  
  2816. --===================================================================
  2817. -- Procedure COMMAND_FIND
  2818. -- This procedure implements the Find command.  It searches for the passed
  2819. -- string over a range of lines and stops at the first line in that range
  2820. -- which contains the indicated string.  LINE_START and LINE_STOP are
  2821. -- global values set by RANGE_INPUT which indicate the indexes of the first
  2822. -- and last lines in the range.
  2823. -- 
  2824. -- The routine SUB_STRING is used to determine if the passed string is
  2825. -- contained in the current line.
  2826. -- 
  2827.     procedure COMMAND_FIND (STR : LINE_STRING) is
  2828.         TEMP_LINE : LINE_STRING;
  2829.         I         : NATURAL;
  2830.     begin
  2831.         COMMAND_GOTO (LINE_START); -- position at first line
  2832. -- 
  2833. -- Exit when String is found, else advance to next line
  2834. -- 
  2835.         for Tmp in LINE_START .. LINE_STOP loop   --!Cha  I changed to Tmp
  2836.             TEMP_LINE := LINE_LIST.RETURN_CURRENT_ELEMENT;
  2837.             exit when SUB_STRING (TEMP_LINE, STR, 1) /= 0;
  2838.             exit when not LINE_LIST.CURRENT_NEXT; -- never hit this exit
  2839.         end loop;
  2840.     end COMMAND_FIND;
  2841.  
  2842. --===================================================================
  2843. -- File I/O Support Routines
  2844. -- 
  2845. -- This set of routines provides the basic support required to perform file
  2846. -- input/output with the editor.  These routines and their functions are:
  2847. -- 
  2848. -- ROUTINE              FUNCTION
  2849. -- WRITE_FLINE          Write the current line to the output file
  2850. -- PUT_RANGE            Write a group of lines to the output file
  2851. -- READ_FILE            Read a file into the edit buffer after the
  2852. --                        current line
  2853. -- 
  2854.  
  2855. -- 
  2856. -->> Procedure WRITE_FLINE
  2857. -- This procedure writes the current line out to the file whose descriptor
  2858. -- is passed as an argument.  The number of characters in the line is first
  2859. -- counted, and then TEXT_IO.PUT_LINE is used to write the line.
  2860. -- 
  2861.     procedure WRITE_FLINE (LOC_FILE : Cais.TEXT_IO.FILE_TYPE) is
  2862.         LEN : NATURAL;
  2863.     begin
  2864.         LEN := COUNT_CHARS (LINE_LIST.RETURN_CURRENT_ELEMENT);
  2865.         Cais.TEXT_IO.PUT_LINE (LOC_FILE,
  2866.                           LINE_LIST.RETURN_CURRENT_ELEMENT.CONTENT (1 .. LEN));
  2867.     end WRITE_FLINE;
  2868.  
  2869. -- 
  2870. -->> Procedure PUT_RANGE
  2871. -- PUT_RANGE positions to the first line, indexed by START, and writes lines
  2872. -- to the file via repeated calls to WRITE_FLINE until the line indexed by
  2873. -- STOP is written.
  2874. -- 
  2875.     procedure PUT_RANGE (FD : Cais.TEXT_IO.FILE_TYPE; START, STOP : NATURAL) is
  2876.         --!Del  not used I : NATURAL;
  2877.     begin
  2878.         COMMAND_GOTO (START); -- position at first line
  2879.         for I in START .. STOP loop
  2880.             WRITE_FLINE (FD);           -- write current line
  2881.             exit when not LINE_LIST.CURRENT_NEXT; -- advance to next line
  2882.         end loop;
  2883.     end PUT_RANGE;
  2884.  
  2885. -- 
  2886. -->> Procedure READ_FILE
  2887. -- This procedure reads the file named by FILE_NAME into the edit buffer.
  2888. -- If the file is not found and CREATE_FLAG is TRUE, an empty file is
  2889. -- created; if the file is not found and CREATE_FLAG is FALSE, only an error
  2890. -- message is issued.
  2891. -- 
  2892.     procedure READ_FILE (FILE_NAME : STRING; CREATE_FLAG : BOOLEAN) is
  2893.         LOC_FILE : Cais.TEXT_IO.FILE_TYPE;
  2894.         INLINE   : LINE_STRING;
  2895.         LEN      : NATURAL;
  2896.  
  2897.     begin
  2898. -- 
  2899. -- Try to open the file for input.  If this fails because the file is not
  2900. -- found, the exception NAME_ERROR is raised.
  2901. -- 
  2902.     --!Rem  No change is required here except that CAIS.Text_IO.Open
  2903.     --!Rem has differing order of Parms than Text_IO.Open
  2904.         Cais.TEXT_IO.OPEN (LOC_FILE, File_Name, Cais.TEXT_IO.IN_FILE );  --!Cha
  2905.  
  2906. -- 
  2907. -- Append lines after the current line until the end of the input file is
  2908. -- reached.
  2909. -- 
  2910.         loop
  2911.             exit when Cais.TEXT_IO.END_OF_FILE (LOC_FILE);
  2912.             Cais.TEXT_IO.GET_LINE (LOC_FILE, INLINE, LEN);
  2913.             for I in LEN + 1 .. LINE_LENGTH loop
  2914.                 INLINE (I) := ASCII.NUL;
  2915.             end loop;
  2916.             LINE_LIST.APPEND_ELEMENT (INLINE);
  2917.         end loop;
  2918.  
  2919. -- 
  2920. -- Close the Input File (generally, a good practice)
  2921. -- 
  2922.         Cais.TEXT_IO.CLOSE (LOC_FILE);
  2923.  
  2924. -- 
  2925. -- Handle problems; the big problem to look for is when the file is not
  2926. -- found (the exception NAME_ERROR is raised by TEXT_IO.OPEN).
  2927. -- 
  2928.     exception
  2929.  
  2930.         when    Cais.Node_Definitions.Name_Error => 
  2931.     --!Rem  ^^^^^^^^^^^^^^^^ was Text_Io
  2932. -- 
  2933. -- If the CREATE_FLAG is TRUE, create an empty file; else, say that file
  2934. -- was not found.
  2935. -- 
  2936.             if CREATE_FLAG then
  2937.         --!Cha   only change is order of Create parameters
  2938.                 Cais.TEXT_IO.CREATE (LOC_FILE, File_Name, Cais.TEXT_IO.OUT_FILE);
  2939.                 Cais.TEXT_IO.CLOSE (LOC_FILE);
  2940.                 PUT ("New File");
  2941.                 NEW_LINE;
  2942.             else
  2943.                 PUT ("File not Found");
  2944.                 NEW_LINE;
  2945.             end if;
  2946.  
  2947.     end READ_FILE;
  2948.  
  2949.  
  2950. --===================================================================
  2951. -- Procedure COMMAND_GET
  2952. -- This procedure implements the Get command.  The file indicated by the
  2953. -- passed FILE_NAME is read into the edit buffer after the indicated line
  2954. -- (if any).
  2955. -- 
  2956.     procedure COMMAND_GET (FILE_NAME : LINE_STRING) is
  2957.         CURRENT_SAVE     : NATURAL;
  2958.         DUMMY            : BOOLEAN;
  2959.         FILE_NAME_LENGTH : NATURAL;
  2960.     begin
  2961.         FILE_NAME_LENGTH := FILE_NAME'LAST;
  2962.         for I in 1 .. FILE_NAME'LAST loop
  2963.             if FILE_NAME (I) = ASCII.NUL then
  2964.                 FILE_NAME_LENGTH := I - 1;
  2965.                 exit;
  2966.             end if;
  2967.         end loop;
  2968.         COMMAND_GOTO (LINE_START); -- position at indicated line
  2969.         CURRENT_SAVE := LINE_LIST.CURRENT_INDEX; -- save index of current line
  2970.         READ_FILE (FILE_NAME (1 .. FILE_NAME_LENGTH), FALSE); -- read file
  2971.         DUMMY := LINE_LIST.SET_CURRENT_INDEX (CURRENT_SAVE); -- restore current
  2972.     end COMMAND_GET;
  2973.  
  2974. --===================================================================
  2975. -- Procedure COMMAND_PUT
  2976. -- This procedure implements the Put command.  It writes out lines over
  2977. -- the range from LINE_START to LINE_STOP (input via RANGE_INPUT) to the file
  2978. -- named in the passed parameter.
  2979. -- 
  2980.     procedure COMMAND_PUT (FILE_NAME : LINE_STRING) is
  2981.         LOC_FILE         : Cais.TEXT_IO.FILE_TYPE;
  2982.         I                : NATURAL;
  2983.         FILE_NAME_LENGTH : NATURAL;
  2984.  
  2985.     begin
  2986. -- 
  2987. -- Compute length of file name
  2988. -- 
  2989.         FILE_NAME_LENGTH := FILE_NAME'LAST;
  2990.         for Tmp in 1 .. FILE_NAME'LAST loop     --!Cha  I changed to Tmp
  2991.             if FILE_NAME (Tmp) = ASCII.NUL then --!Cha  I changed to Tmp
  2992.                 FILE_NAME_LENGTH := Tmp - 1;    --!Cha  I changed to Tmp
  2993.                 exit;
  2994.             end if;
  2995.         end loop;
  2996. -- 
  2997. -- Delete the original file, if any
  2998. -- 
  2999.     --!Cha Only change is order of Open parameters
  3000.         Cais.TEXT_IO.OPEN (LOC_FILE, FILE_NAME (1 .. FILE_NAME_LENGTH),
  3001.             Cais.Text_Io.In_File);
  3002.         Cais.TEXT_IO.DELETE (LOC_FILE);
  3003. -- 
  3004. -- Create the new file
  3005. -- 
  3006.     --!Cha Only change is order of Create parameters
  3007.         Cais.TEXT_IO.CREATE (LOC_FILE, FILE_NAME (1 .. FILE_NAME_LENGTH),
  3008.             Cais.Text_Io.Out_File);
  3009.                         
  3010.         PUT_RANGE (LOC_FILE, LINE_START, LINE_STOP);
  3011.         Cais.TEXT_IO.CLOSE (LOC_FILE);
  3012. -- 
  3013. -- If the original file did not already exist, the above TEXT_IO.OPEN would
  3014. -- have raised the exception NAME_ERROR.  The following handler traps this
  3015. -- and goes ahead to create the file and write to it.
  3016. -- 
  3017.     exception
  3018.         when Cais.Node_Definitions.Name_Error => 
  3019.     --!Cha   ^^^^^^^^^^^^^^^^ was Text_Io
  3020.  
  3021.     --!Cha Only change is order of Create parameters
  3022.             Cais.TEXT_IO.CREATE (LOC_FILE, FILE_NAME (1 .. FILE_NAME_LENGTH),
  3023.             Cais.Text_Io.Out_File);
  3024.                             
  3025.             PUT_RANGE (LOC_FILE, LINE_START, LINE_STOP);
  3026.             Cais.Text_Io.Close (LOC_FILE);
  3027.  
  3028.     end COMMAND_PUT;
  3029.  
  3030. --===================================================================
  3031.  
  3032. end EDIT_WORKER;
  3033. --::::::::::::::
  3034. --edit_worker-spec.a
  3035. --::::::::::::::
  3036. -- Package EDIT_WORKER
  3037. --  Written by Richard Conn, TI Ada Technology Branch
  3038. --  Version 2.0, Date 31 Jan 85
  3039. --  Version 2.1, Date 15 Feb 85
  3040. --   CAIS Version 3.0, 21 August 85
  3041. --   CAIS Version 3.1, 13 Feb 86
  3042. --    NB: changes for the CAIS port are indicated by one of the 
  3043. --        following on each affected line:
  3044. --        --!Rem   Comments, remarks
  3045. --        --!Add   Lines added to the code
  3046. --        --!Del   Lines deleted from the code
  3047. --        --!Cha   Lines changed in the code
  3048. --        (It is a bit subjective; when does a big change become
  3049. --         a delete and an add ?)
  3050. -- 
  3051.  
  3052. --!Del with TEXT_IO;  ?Not used in the Specification of this package
  3053. with EDIT_SUPPORT;
  3054. use EDIT_SUPPORT;
  3055. package EDIT_WORKER is
  3056.  
  3057. -- 
  3058. -- EDIT_WORKER is the set of procedures which implement the various
  3059. -- commands available through the EDITOR.  These are the workhorse
  3060. -- routines.
  3061. -- 
  3062.  
  3063. --===================================================================
  3064. -- 
  3065. -- The following global data buffers are used by several of the routines.
  3066. -- LINE_START and LINE_STOP are the numbers of the lines indicated by
  3067. -- input to RANGE_INPUT, and these values are set by RANGE_INPUT and read
  3068. -- by the routines which call RANGE_INPUT.  The exception RANGE_ERROR indicates
  3069. -- if there is an error in the input values received from RANGE_INPUT.
  3070. -- 
  3071.     LINE_START, LINE_STOP : NATURAL;
  3072.     RANGE_ERROR : exception;
  3073.  
  3074. --===================================================================
  3075. -- 
  3076. -- Procedure RANGE_INPUT
  3077. -- 
  3078. -- RANGE_INPUT is used to input a range specification of the following
  3079. -- forms:
  3080. --           x       -- reference a single line or one of the special ranges
  3081. --           x,x     -- reference a group of lines
  3082. --           x x     -- reference a group of lines (same as x,x)
  3083. -- 
  3084. -- A single line reference may be any of the following:
  3085. -- 
  3086. --    #    -- a line number, such as 1, 245, etc
  3087. --   +#    -- the line which is n lines after the current line, such as +23
  3088. --   -#    -- the line which is n lines before the current line, such as -45
  3089. --    A    -- all lines in the file
  3090. --    C    -- the current line
  3091. --    F    -- the first line
  3092. --    L    -- the last line
  3093. --    P    -- 20 consecutive lines, starting at the current line
  3094. -- 
  3095. -- A group of lines may be referenced by any combination of the following:
  3096. -- 
  3097. --    #   +#   -#   C   F   L
  3098. -- 
  3099. -- If the first entry of the pair references a line which is after the
  3100. -- line referenced by the second entry of the pair, then the RANGE_ERROR
  3101. -- flag will be raised.
  3102. -- 
  3103. -- EXCEPTIONS RAISED:  RANGE_ERROR
  3104. -- 
  3105. -- SIDE EFFECTS:
  3106. --  The values of LINE_START and LINE_STOP are always set.  If an error
  3107. -- is encountered, RANGE_ERROR is raised (error message is also printed).
  3108. -- 
  3109.  
  3110.     procedure RANGE_INPUT;
  3111.  
  3112.  
  3113. --===================================================================
  3114. -- 
  3115. -- The following routines return the indexes (natural numbers) of
  3116. -- the current and last lines (CURRENT_LINE, LAST_LINE) and advance
  3117. -- to the next line or backup to the previous line (ADVANCE_LINE,
  3118. -- BACKUP_LINE)
  3119. -- 
  3120.  
  3121.     function  CURRENT_LINE return NATURAL;
  3122.     function  LAST_LINE    return NATURAL;
  3123.     procedure ADVANCE_LINE;
  3124.     procedure BACKUP_LINE;
  3125.  
  3126.  
  3127. --===================================================================
  3128. -- 
  3129. -- The following file read routine is used to read the initial
  3130. -- file when the editor starts up
  3131. -- 
  3132.  
  3133.     procedure READ_FILE (FILE_NAME : STRING; CREATE_FLAG : BOOLEAN);
  3134.  
  3135.  
  3136.  
  3137. --===================================================================
  3138. -- 
  3139. -- The following routines implement the indicated commands:
  3140. -- 
  3141. --   ROUTINE NAME              COMMAND  MEANING OF COMMAND
  3142. --   initialize_edit                    Initialize the Editor
  3143. --   command_append               A     Append Lines After Current Line
  3144. --   command_delete               D     Delete One or More Lines
  3145. --   command_find                 F     Search for String
  3146. --   command_get                  G     Read in File after Current Line
  3147. --   command_goto                 J     Jump to (Position to) Indicated Line
  3148. --   command_insert               I     Insert Lines Before Current line
  3149. --   command_list                 L     List One or More Lines
  3150. --   command_put                  P     Write Out Range of Lines to File
  3151. --   command_substitute           S     Substitute Strings in One or More Lines
  3152. -- 
  3153.  
  3154.     procedure INITIALIZE_EDIT;
  3155.  
  3156.     procedure COMMAND_APPEND;
  3157.  
  3158.     procedure COMMAND_DELETE;
  3159.  
  3160.     procedure COMMAND_FIND (STR : EDIT_SUPPORT.LINE_STRING);
  3161.  
  3162.     procedure COMMAND_GET (FILE_NAME : EDIT_SUPPORT.LINE_STRING);
  3163.  
  3164.     procedure COMMAND_GOTO (NUM : NATURAL);
  3165.  
  3166.     procedure COMMAND_INSERT;
  3167.  
  3168.     procedure COMMAND_LIST;
  3169.  
  3170.     procedure COMMAND_PUT (FILE_NAME : EDIT_SUPPORT.LINE_STRING);
  3171.  
  3172.     procedure COMMAND_SUBSTITUTE
  3173.                  (OLD_STRING, NEW_STRING : EDIT_SUPPORT.LINE_STRING);
  3174.  
  3175. --===================================================================
  3176.  
  3177. end EDIT_WORKER;
  3178.  
  3179. --::::::::::::::
  3180. --editor.a
  3181. --::::::::::::::
  3182. -------- SIMTEL20 Ada Software Repository Prologue ------------
  3183. --                                                           -*
  3184. -- Unit name    : EDITOR (ALED - Ada Line Editor)
  3185. -- Version      : 3.1
  3186. -- Author       : Richard Conn
  3187. --              : Texas Instruments
  3188. --              : PO Box 801, MS 8007
  3189. --              : McKinney, TX  75069
  3190. -- DDN Address  : RCONN at SIMTEL20
  3191. -- Copyright    : (c) 1984, 1985 Richard Conn
  3192. -- Date created :  9 Nov 84
  3193. -- Release date :  5 Dec 84
  3194. -- Last update  :  13 Feb 86
  3195. -- Machine/System Compiled/Run on : VAX 8600 ULTRIX, Sun2 UNIX 4.2
  3196. --              : All system-specific features are isolated in
  3197. --        : the package SYSDEP, so I believe
  3198. --              : that the editor is transportable between a
  3199. --              : a wide variety of environments; I encountered
  3200. --              : a number of "surprises" when I programmed the
  3201. --              : editor, and I don't know if they were caused
  3202. --              : by the ROLM ADE implementation of TEXT_IO or if
  3203. --              : they were intentional; see the documentation
  3204. --                                                           -*
  3205. ---------------------------------------------------------------
  3206. --                                                           -*
  3207. -- Keywords     :  EDITOR
  3208. ----------------:  LINE-ORIENTED EDITOR
  3209. ----------------:  INPUT-LINE EDITOR
  3210. --
  3211. -- Abstract     :  ALED - Ada Line Editor
  3212. ----------------:  A Line-Oriented File Editor Written in Ada
  3213. ----------------:  by Richard Conn
  3214. ----------------:  
  3215. ----------------:  ALED is designed to edit text files.  Upon invocation,
  3216. ----------------:  ALED prompts the user for a file name.  If the file
  3217. ----------------:  exists, its contents (lines) are read in and prepared
  3218. ----------------:  for editing; if the file does not exist, the file is
  3219. ----------------:  created and the empty buffer is prepared for editing.
  3220. ----------------:  ALED is an interactive editor, accepting single-char
  3221. ----------------:  commands, filling in a command prompt (for more info
  3222. ----------------:  as needed), and performing its functions in real-time
  3223. ----------------:  while the user watches.  The functions provided include
  3224. ----------------:  (but are not limited to) the following:
  3225. ----------------:  
  3226. ----------------:     * List Lines
  3227. ----------------:     * Insert a Group of Lines into the Edit Buffer
  3228. ----------------:     * Delete Lines
  3229. ----------------:     * String Search and String Substitution
  3230. ----------------:     * Movement Within the Edit Buffer
  3231. ----------------:     * Reading in a File After a Specified Line
  3232. ----------------:     * Writing out a Range of Lines to a File
  3233. ----------------:     * Built-in, online Documentation (Summary)
  3234. ----------------:  
  3235. ----------------:  ALED's design includes an input line editor, which allows
  3236. ----------------:  the user to edit text as he types it.  I was surprised
  3237. ----------------:  NOT to find such a basic function available in TEXT_IO.
  3238. ----------------:  Did I miss something?
  3239. ----------------:  
  3240. ----------------:  ALED is divided into the following files.  The order
  3241. ----------------:  in which they are listed is the compilation order.
  3242. ----------------:  
  3243. ----------------:  SIMTEL20      Ada Package/Procedure  Comments
  3244. ----------------:  
  3245. ----------------:  SYSDEP.ADA     sysdep            Components library
  3246. ----------------:                    of single-character
  3247. ----------------:                    I/O routines
  3248. ----------------:
  3249. ----------------:  LIST.ADA      editor_list            Components library
  3250. ----------------:                                       of linked-list routines
  3251. ----------------:  
  3252. ----------------:  ED-SPT.ADA    edit_support           Visible section
  3253. ----------------:                                       of editor support
  3254. ----------------:                                       package (which contains
  3255. ----------------:                                       a few basic routines,
  3256. ----------------:                                       such as the input line
  3257. ----------------:                                       editor)
  3258. ----------------:  
  3259. ----------------:  ED-SPTB.ADA   edit_support           Body of editor support
  3260. ----------------:                                       package
  3261. ----------------:  
  3262. ----------------:  ED-WRK.ADA    edit_worker            Visible seciton of
  3263. ----------------:                                       workhorse routines
  3264. ----------------:                                       for the editor;
  3265. ----------------:                                       all major editor
  3266. ----------------:                                       functions and their
  3267. ----------------:                                       related support
  3268. ----------------:                                       routines are here
  3269. ----------------:                                       (such as list lines)
  3270. ----------------:  
  3271. ----------------:  ED-WRKB.ADA   edit_worker            Body of editor
  3272. ----------------:                                       workhorse routines
  3273. ----------------:  
  3274. ----------------:  ED.ADA        editor                 Mainline of ALED
  3275. ----------------:  
  3276. ----------------:  
  3277. --                                                           -*
  3278. ------------------ Revision history ---------------------------
  3279. --                                                           -*
  3280. -- DATE         VERSION    AUTHOR                  HISTORY
  3281. -- 12/5/84        1.0   Richard Conn            Initial Release
  3282. -- 1/21/85        2.0   Richard Conn            Production version
  3283. -- 2/15/85        2.1   Richard Conn            Minor bug fix
  3284. -- 8/21/85        3.0   Chuck Howell            Port to CAIS
  3285. -- 2/13/86        3.1   Chuck Howell            Change CAIS Version
  3286. --    NB: changes for the CAIS port are indicated by one of the following 
  3287. --        on each affected line:
  3288. --        --!Rem   Comments, remarks
  3289. --        --!Add   Lines added to the code
  3290. --        --!Del   Lines deleted from the code
  3291. --        --!Cha   Lines changed in the code
  3292. --        (It is a bit subjective; when does a big change become
  3293. --         a delete and an add ?)
  3294. --                                                           -*
  3295. ------------------ Distribution and Copyright -----------------
  3296. --                                                           -*
  3297. -- This prologue must be included in all copies of this software.
  3298. --
  3299. -- This software is copyright by the author.
  3300. --
  3301. -- This software is released to the Ada community.
  3302. -- This software is released to the Public Domain (note:
  3303. --   software released to the Public Domain is not subject
  3304. --   to copyright protection).
  3305. -- Restrictions on use or distribution:  NONE
  3306. --                                                           -*
  3307. ------------------ Disclaimer ---------------------------------
  3308. --                                                           -*
  3309. -- This software and its documentation are provided "AS IS" and
  3310. -- without any expressed or implied warranties whatsoever.
  3311. -- No warranties as to performance, merchantability, or fitness
  3312. -- for a particular purpose exist.
  3313. --
  3314. -- Because of the diversity of conditions and hardware under
  3315. -- which this software may be used, no warranty of fitness for
  3316. -- a particular purpose is offered.  The user is advised to
  3317. -- test the software thoroughly before relying on it.  The user
  3318. -- must assume the entire risk and liability of using this
  3319. -- software.
  3320. --
  3321. -- In no event shall any person or organization of people be
  3322. -- held responsible for any direct, indirect, consequential
  3323. -- or inconsequential damages or lost profits.
  3324. --                                                           -*
  3325. -------------------END-PROLOGUE--------------------------------
  3326.  
  3327. -- 
  3328. -- MAIN BODY OF ALED -- Ada Line Editor
  3329. -- Program Written by Richard Conn, TI Ada Technology Branch
  3330. -- Completion Date:  12/5/84
  3331. -- Completion Date of 2.0:  1/31/85
  3332. -- Completion Date of 2.1:  2/15/85
  3333. -- 
  3334.  
  3335. -- 
  3336. -- The following packages are used throughout the editor and constitute
  3337. -- a set of basic support functions.
  3338. -- 
  3339. with --!Cha  TEXT_IO,   used only for Integer_IO.
  3340.      EDIT_SUPPORT,
  3341.      EDIT_WORKER;
  3342. use EDIT_SUPPORT, EDIT_WORKER;
  3343.  
  3344. -- 
  3345. -- This is the main body of the editor
  3346. -- 
  3347. procedure EDITOR is
  3348.     --!Del package NUM_IO is new TEXT_IO.INTEGER_IO (NATURAL);
  3349.     --!Rem  the use of version number, integer division, mod, and Integer_IO
  3350.     --!Rem  to print a version has been replaced by a string constant 
  3351.     --!Rem  representing the current version.
  3352.     --!Del VERSION_NUMBER      : constant := 21; -- major=2, minor=1
  3353.     VERSION             : constant String := "(MITRE CAIS) 3.1"; --!Add
  3354.     EDIT_FILE           : LINE_STRING;
  3355.     FILE_NAME_LENGTH    : NATURAL;
  3356.     NEW_STRING          : LINE_STRING;
  3357.     SSTRING             : LINE_STRING;
  3358.     DONE                : BOOLEAN;
  3359.     RESP_CHAR, CMD_CHAR : CHARACTER;
  3360.  
  3361.     -- 
  3362.     -- HELP_SUMMARY prints a summary of commands to the user
  3363.     -- 
  3364.     procedure HELP_SUMMARY is
  3365.     begin
  3366.         NEW_LINE;
  3367.         NEW_LINE;
  3368.         PUT ("--- Movement Commands ---  ");
  3369.         PUT ("----- Enter Lines -----");
  3370.         NEW_LINE;
  3371.         PUT (" + Advance N Lines         ");
  3372.         PUT (" A Append after <line> ");
  3373.         NEW_LINE;
  3374.         PUT (" - Back Up N Lines         ");
  3375.         PUT (" I Insert before <line>");
  3376.         NEW_LINE;
  3377.         PUT (" F Find <string> in <range>");
  3378.         PUT ("                       ");
  3379.         NEW_LINE;
  3380.         PUT (" J Jump to <line>          ");
  3381.         PUT ("----- Print Lines -----");
  3382.         NEW_LINE;
  3383.         PUT (" N Find Next <string>      ");
  3384.         PUT (" . Print Current Line  ");
  3385.         NEW_LINE;
  3386.         PUT ("----- Delete Command ----- ");
  3387.         PUT (" < Print Next Line     ");
  3388.         NEW_LINE;
  3389.         PUT (" D Delete lines in <range> ");
  3390.         PUT (" > Print Next Line     ");
  3391.         NEW_LINE;
  3392.         PUT ("                           ");
  3393.         PUT (" L List over <range>   ");
  3394.         NEW_LINE;
  3395.         PUT ("---- Help and Exits ----   ");
  3396.         PUT ("                       ");
  3397.         NEW_LINE;
  3398.         PUT (" H This Help Text          ");
  3399.         PUT ("---- Substitution ---- ");
  3400.         NEW_LINE;
  3401.         PUT (" Q Quit without Updating   ");
  3402.         PUT (" S String Substitute   ");
  3403.         NEW_LINE;
  3404.         PUT (" X Exit and Update         ");
  3405.         PUT ("     over <range>      ");
  3406.         NEW_LINE;
  3407.         NEW_LINE;
  3408.         PUT ("---- File Get/Put ----     ");
  3409.         PUT ("-- Miscellaneous --    ");
  3410.         NEW_LINE;
  3411.         PUT (" G Get <file> after <line> ");
  3412.         PUT (" ? Print Statistics    ");
  3413.         NEW_LINE;
  3414.         PUT (" P Put <file> over <range> ");
  3415.         PUT ("                       ");
  3416.         NEW_LINE;
  3417.         NEW_LINE;
  3418.         PUT ("<Range>:  %   %,%");
  3419.         NEW_LINE;
  3420.         PUT ("First or Second Entries --");
  3421.         NEW_LINE;
  3422.         PUT ("   #-Number, .-Current, C-Current, F-First,");
  3423.         PUT (" L-Last");
  3424.         NEW_LINE;
  3425.         PUT ("Singular Entries --");
  3426.         NEW_LINE;
  3427.         PUT ("   A-All, P-Page");
  3428.         NEW_LINE;
  3429.     end HELP_SUMMARY;
  3430.  
  3431. -- 
  3432. -- HELP prints help information to the user
  3433. -- 
  3434.     procedure HELP (INCHAR : CHARACTER) is
  3435.     begin
  3436.         NEW_LINE;
  3437.         case INCHAR is
  3438.             when 'c' | 'C' => 
  3439.                 PUT ("Command Names:");
  3440.                 NEW_LINE;
  3441.                 PUT ("+ (Advance)     - (Backup)      . (Current)");
  3442.                 NEW_LINE;
  3443.                 PUT ("< (Previous)    > (Next)        ? (Statistics)");
  3444.                 NEW_LINE;
  3445.                 PUT ("Append  Delete  Find    Get     Help    Insert");
  3446.                 NEW_LINE;
  3447.                 PUT ("Jump    List    Next    Put     Quit    Substitute");
  3448.                 NEW_LINE;
  3449.                 PUT ("X(Exit)");
  3450.                 NEW_LINE;
  3451.             when 'n' | 'N' => 
  3452.                 PUT ("Number Values:");
  3453.                 NEW_LINE;
  3454.                 PUT (". or C    Current Line");
  3455.                 NEW_LINE;
  3456.                 PUT ("  F       First Line");
  3457.                 NEW_LINE;
  3458.                 PUT ("  L       Last Line");
  3459.                 NEW_LINE;
  3460.                 PUT (" 25       Absolute Line Number");
  3461.                 NEW_LINE;
  3462.                 PUT ("+7 or -5  Relative Line Number");
  3463.                 NEW_LINE;
  3464.                 PUT ("  A       All Lines in File (only one argument)");
  3465.                 NEW_LINE;
  3466.                 PUT ("  P       Next Page of Lines (only one argument)");
  3467.                 NEW_LINE;
  3468.             when 's' | 'S' => 
  3469.                 HELP_SUMMARY;
  3470.             when others => 
  3471.                 null;
  3472.         end case;
  3473.     end HELP;
  3474.  
  3475. -- 
  3476. -- The mainline of the editor
  3477. -- 
  3478. begin
  3479.     INITIALIZE_EDIT; -- initialize the Worker Functions
  3480.     CONSOLE_INIT; -- initialize the console
  3481. -- 
  3482.     PUT ("ALED - Ada Line Editor by Richard Conn, Version ");
  3483.     --!Rem  See comment above re use of Version string vs. Version_Number
  3484.     Put (Version);  --!Add
  3485.     --!Del NUM_IO.PUT (VERSION_NUMBER / 10, 2);
  3486.     --!Del PUT (".");
  3487.     --!Del NUM_IO.PUT (VERSION_NUMBER mod 10, 1);
  3488.     NEW_LINE;
  3489. -- 
  3490. -- Enter File Name and Trap All Exceptions as File Name Errors
  3491. -- 
  3492.     loop
  3493.         begin
  3494.             PUT ("File Name? ");
  3495.             EDIT_FILE := INPUT_LINE;
  3496.             SSTRING := EDIT_FILE; -- initial value for SSTRING
  3497.             FILE_NAME_LENGTH := EDIT_FILE'LAST;
  3498.             for I in 1 .. EDIT_FILE'LAST loop
  3499.                 if EDIT_FILE (I) = ASCII.NUL then
  3500.                     FILE_NAME_LENGTH := I - 1;
  3501.                     exit;
  3502.                 end if;
  3503.             end loop;
  3504.             READ_FILE (EDIT_FILE (1 .. FILE_NAME_LENGTH), TRUE);
  3505.             exit; -- no exceptions raised
  3506.         exception
  3507.             when others => 
  3508.                 NEW_LINE;
  3509.                 PUT ("File Name Error -- ");
  3510.         end;
  3511.     end loop;
  3512. -- 
  3513.     --!Del NUM_IO.PUT (LAST_LINE, 5);
  3514.     Put (Integer'image (Last_Line)); --!Add
  3515.     PUT (" Lines in File");
  3516. -- 
  3517.     COMMAND_GOTO (1); -- position at first line
  3518.     NEW_LINE;
  3519.     PUT (" Type H for Help");
  3520.     DONE := FALSE; -- this flag indicates when the editor is to be exited
  3521.     NEW_LINE;
  3522. -- 
  3523.     loop
  3524.         begin
  3525.             exit when DONE;
  3526. -- 
  3527. -- Print Prompt to User and Get Single-Char Command
  3528. -- 
  3529.             --!del  NUM_IO.PUT (CURRENT_LINE, 5);
  3530.         Put (Integer'image (Current_Line)); --!Add
  3531.             PUT ("> ");
  3532.             CMD_CHAR := GETCH; -- input command character without echo
  3533. -- 
  3534. -- Process Single-Char Commands
  3535. -- 
  3536.             case CMD_CHAR is
  3537. -- 
  3538. -- Null Commands (Just Echo New Line)
  3539. -- 
  3540.                 when ASCII.CR | ASCII.DEL | ASCII.BS => 
  3541.                     NEW_LINE;
  3542. -- 
  3543. -- Print Current Line
  3544. -- 
  3545.                 when '.' => 
  3546.                     NEW_LINE; -- no prompt
  3547.                     LINE_START := CURRENT_LINE; -- list lines over current line
  3548.                     LINE_STOP := CURRENT_LINE;
  3549.                     COMMAND_LIST;
  3550. -- 
  3551. -- Backup and Print Previous Line
  3552. -- 
  3553.                 when '<' => 
  3554.                     NEW_LINE; -- no prompt
  3555.                     if CURRENT_LINE >= 1 then
  3556.                         -- trap errors
  3557.                         BACKUP_LINE;
  3558.                     end if;
  3559.                     LINE_START := CURRENT_LINE; -- list current line
  3560.                     LINE_STOP := LINE_START;
  3561.                     COMMAND_LIST;
  3562. -- 
  3563. -- Advance and Print Next Line
  3564. -- 
  3565.                 when '>' => 
  3566.                     NEW_LINE; -- no prompt
  3567.                     if CURRENT_LINE < LAST_LINE then
  3568.                         -- trap errors
  3569.                         ADVANCE_LINE;
  3570.                     end if;
  3571.                     LINE_START := CURRENT_LINE; -- list current line
  3572.                     LINE_STOP := LINE_START;
  3573.                     COMMAND_LIST;
  3574. -- 
  3575. -- Advance N Lines
  3576. -- 
  3577.                 when '+' => 
  3578.                     PUT ("Advance N Lines <line count>");
  3579.                     RANGE_INPUT;     -- pay attention to 1st value
  3580.                     if CURRENT_LINE + LINE_START <= LAST_LINE then
  3581.                         COMMAND_GOTO (CURRENT_LINE + LINE_START);
  3582.                     else
  3583.                         COMMAND_GOTO (LAST_LINE);
  3584.                     end if;
  3585. -- 
  3586. -- Backup N Lines
  3587. -- 
  3588.                 when '-' => 
  3589.                     PUT ("Back Up N Lines <line count>");
  3590.                     RANGE_INPUT;     -- pay attention to 1st value
  3591.                     if CURRENT_LINE - LINE_START < 1 then
  3592.                         COMMAND_GOTO (1);
  3593.                     else
  3594.                         COMMAND_GOTO (CURRENT_LINE - LINE_START);
  3595.                     end if;
  3596. -- 
  3597. -- Print Status Info
  3598. -- 
  3599.                 when '?' => 
  3600.                     NEW_LINE; -- no prompt
  3601.                     PUT ("       Edit File Name: ");
  3602.                     OUTPUT_LINE (EDIT_FILE);
  3603.                     NEW_LINE;
  3604.                     PUT ("       ");
  3605.                     --!Del  NUM_IO.PUT (LAST_LINE, 5);
  3606.             Put (Integer'image(Last_Line));  --!Add
  3607.                     PUT (" Lines in File");
  3608.                     NEW_LINE;
  3609. -- 
  3610. -- Append a Group of Lines after the Indicated Line
  3611. -- 
  3612.                 when 'a' | 'A' => 
  3613.                     PUT ("Append after <line>");
  3614.                     RANGE_INPUT;     -- 1 or 2 args used
  3615.                     if not BLANK_INPUT then
  3616.                         -- abort if no input
  3617.                         COMMAND_GOTO (LINE_START);
  3618.                         COMMAND_APPEND;
  3619.                     end if;
  3620. -- 
  3621. -- Delete a Group of Lines
  3622. -- 
  3623.                 when 'd' | 'D' => 
  3624.                     PUT ("Delete lines in <range>");
  3625.                     RANGE_INPUT;     -- 1 or 2 args used
  3626.                     if not BLANK_INPUT then
  3627.                         -- abort if no input
  3628.                         COMMAND_DELETE;
  3629.                     end if;
  3630. -- 
  3631. -- Find the First Occurrance of a String over a Range of Lines
  3632. -- 
  3633.                 when 'f' | 'F' => 
  3634.                     PUT ("Find <string> ");
  3635.                     SSTRING := INPUT_LINE;
  3636.                     PUT ("        over <range>");
  3637.                     RANGE_INPUT;     -- abort if no range input
  3638.                     if not BLANK_INPUT then
  3639.                         COMMAND_FIND (SSTRING);
  3640.                         LINE_START := CURRENT_LINE;
  3641.                         LINE_STOP := LINE_START;
  3642.                         COMMAND_LIST;
  3643.                     end if;
  3644. -- 
  3645. -- Load File into Current File After Indicated Line
  3646. -- 
  3647.                 when 'g' | 'G' => 
  3648.                     PUT ("Get <file> ");
  3649.                     SSTRING := INPUT_LINE;
  3650.                     if not BLANK_INPUT then
  3651.                         -- abort if no input
  3652.                         PUT ("        after <line>");
  3653.                         RANGE_INPUT;
  3654.                         if not BLANK_INPUT then
  3655.                             COMMAND_GET (SSTRING);
  3656.                         end if;
  3657.                     end if;
  3658. -- 
  3659. -- Print Help Message
  3660. -- 
  3661.                 when 'h' | 'H' => 
  3662.                     PUT ("Help on the Following:");
  3663.                     NEW_LINE;
  3664.                     PUT ("          ");
  3665.                     PUT ("C - Command Names, N - Numbering, S - Summary   > ");
  3666.                     RESP_CHAR := GETCH_WITH_ECHO;
  3667.                     HELP (RESP_CHAR); -- help routine above
  3668. -- 
  3669. -- Insert a Group of Lines Before the Indicated Line
  3670. -- 
  3671.                 when 'i' | 'I' => 
  3672.                     PUT ("Insert before <line>");
  3673.                     RANGE_INPUT;
  3674.                     if not BLANK_INPUT then
  3675.                         -- abort if no input
  3676.                         COMMAND_GOTO (LINE_START);
  3677.                         COMMAND_INSERT;
  3678.                     end if;
  3679. -- 
  3680. -- Jump to a line
  3681. -- 
  3682.                 when 'j' | 'J' => 
  3683.                     PUT ("Jump to <line>");
  3684.                     RANGE_INPUT;
  3685.                     if not BLANK_INPUT then
  3686.                         -- abort if no input
  3687.                         COMMAND_GOTO (LINE_START);
  3688.                     end if;
  3689. -- 
  3690. -- List a Group of Lines Over a Range
  3691. -- 
  3692.                 when 'l' | 'L' => 
  3693.                     PUT ("List Lines in <range>");
  3694.                     RANGE_INPUT;
  3695.                     if not BLANK_INPUT then
  3696.                         -- abort if no input
  3697.                         COMMAND_LIST;
  3698.                     end if;
  3699. -- 
  3700. -- Find Next Occurrance of String
  3701. -- 
  3702.                 when 'n' | 'N' => 
  3703.                     PUT ("Next Occurrance of <string> ");
  3704.                     NEW_STRING := INPUT_LINE; -- get string
  3705.                     if BLANK_INPUT then
  3706.                         -- if no input
  3707.                         NEW_STRING := SSTRING; -- use old string
  3708.                     end if;
  3709.                     LINE_START := CURRENT_LINE + 1; -- start at next line
  3710.                     LINE_STOP := LAST_LINE;
  3711.                     if LINE_START > LINE_STOP then
  3712.                         LINE_START := LINE_STOP;
  3713.                     end if;
  3714.                     SSTRING := NEW_STRING; -- set old string
  3715.                     COMMAND_FIND (SSTRING); -- search
  3716.                     LINE_START := CURRENT_LINE; -- mark place and print
  3717.                     LINE_STOP := LINE_START;
  3718.                     COMMAND_LIST;
  3719. -- 
  3720. -- Write a Group of Lines Out to a File
  3721. -- 
  3722.                 when 'p' | 'P' => 
  3723.                     PUT ("Put <file> ");
  3724.                     SSTRING := INPUT_LINE;
  3725.                     if not BLANK_INPUT then
  3726.                         -- abort if no input
  3727.                         PUT ("        over <range>");
  3728.                         RANGE_INPUT;
  3729.                         if not BLANK_INPUT then
  3730.                             COMMAND_PUT (SSTRING);
  3731.                         end if;
  3732.                     end if;
  3733. -- 
  3734. -- Quit -- Exit Editor and Throw Away Contents
  3735. -- 
  3736.                 when 'q' | 'Q' => 
  3737.                     PUT ("Quit without File Update (Y/N)? ");
  3738.                     RESP_CHAR := GETCH_WITH_ECHO;
  3739.                     if RESP_CHAR = 'y' or RESP_CHAR = 'Y' then
  3740.                         DONE := TRUE;
  3741.                     end if;
  3742.                     NEW_LINE; -- CRLF is good, indicates activity
  3743. -- 
  3744. -- Substitute One String for Another Over a Range
  3745. -- 
  3746.                 when 's' | 'S' => 
  3747.                     PUT ("Substitute for Old <string> ");
  3748.                     SSTRING := INPUT_LINE;
  3749.                     if not BLANK_INPUT then
  3750.                         -- abort if no input
  3751.                         PUT ("        New <string> ");
  3752.                         NEW_STRING := INPUT_LINE;
  3753.                         PUT ("        over <range>");
  3754.                         RANGE_INPUT;
  3755.                         if not BLANK_INPUT then
  3756.                             COMMAND_SUBSTITUTE (SSTRING, NEW_STRING);
  3757.                         end if;
  3758.                     end if;
  3759. -- 
  3760. -- Exit Editor and Update File
  3761. -- 
  3762.                 when 'x' | 'X' => 
  3763.                     PUT ("Exit and Update File (Y/N)? ");
  3764.                     RESP_CHAR := GETCH_WITH_ECHO;
  3765.                     if RESP_CHAR = 'y' or RESP_CHAR = 'Y' then
  3766.                         DONE := TRUE;
  3767.                     end if;
  3768.                     NEW_LINE; -- CRLF shows activity
  3769. -- 
  3770. -- Invalid Command
  3771. -- 
  3772.                 when others => 
  3773.                     PUT ("Error");
  3774.                     NEW_LINE;
  3775.             end case;
  3776. -- 
  3777. -- Exception Handlers
  3778. -- 
  3779.         exception
  3780.             when RANGE_ERROR => 
  3781.                 NEW_LINE;
  3782.             when others => 
  3783.                 NEW_LINE;
  3784.                 PUT ("       Unknown Error Trapped");
  3785.                 NEW_LINE;
  3786. -- 
  3787.         end;
  3788.         -- command body
  3789. -- 
  3790.     end loop;
  3791.  
  3792. -- 
  3793. -- Write File on Exit
  3794. -- 
  3795.     if CMD_CHAR = 'x' or CMD_CHAR = 'X' then
  3796.         LINE_START := 1;         -- write file on way out
  3797.         LINE_STOP := LAST_LINE;
  3798.         COMMAND_PUT (EDIT_FILE);
  3799.     end if;
  3800. -- 
  3801.     CONSOLE_DEINIT;   -- deinitialize the console
  3802. -- 
  3803. end EDITOR;
  3804.  
  3805.  
  3806. --::::::::::::::
  3807. --editor.pro
  3808. --::::::::::::::
  3809. -------- SIMTEL20 Ada Software Repository Prologue ------------
  3810. --                                                           -*
  3811. -- Unit name    : EDITOR (ALED - Ada Line Editor)
  3812. -- Version      : 3.1
  3813. -- Author       : Richard Conn
  3814. --              : Texas Instruments
  3815. --              : PO Box 801, MS 8007
  3816. --              : McKinney, TX  75069
  3817. -- DDN Address  : RCONN at SIMTEL20
  3818. -- Copyright    : (c) 1984, 1985 Richard Conn
  3819. -- Date created :  9 Nov 84
  3820. -- Release date :  5 Dec 84
  3821. -- Last update  :  13 Feb 86
  3822. -- Machine/System Compiled/Run on : VAX 8600 ULTRIX, Sun2 UNIX 4.2
  3823. --                                                           -*
  3824. ---------------------------------------------------------------
  3825. --                                                           -*
  3826. -- Keywords     :  EDITOR
  3827. ----------------:  LINE-ORIENTED EDITOR
  3828. ----------------:  INPUT-LINE EDITOR
  3829. --
  3830. -- Abstract     :  ALED - Ada Line Editor
  3831. ----------------:  A Line-Oriented File Editor Written in Ada
  3832. ----------------:  by Richard Conn
  3833. ----------------:  
  3834. ----------------:  ALED is designed to edit text files.  Upon invocation,
  3835. ----------------:  ALED prompts the user for a file name.  If the file
  3836. ----------------:  exists, its contents (lines) are read in and prepared
  3837. ----------------:  for editing; if the file does not exist, the file is
  3838. ----------------:  created and the empty buffer is prepared for editing.
  3839. ----------------:  ALED is an interactive editor, accepting single-char
  3840. ----------------:  commands, filling in a command prompt (for more info
  3841. ----------------:  as needed), and performing its functions in real-time
  3842. ----------------:  while the user watches.  The functions provided include
  3843. ----------------:  (but are not limited to) the following:
  3844. ----------------:  
  3845. ----------------:     * List Lines
  3846. ----------------:     * Insert a Group of Lines into the Edit Buffer
  3847. ----------------:     * Delete Lines
  3848. ----------------:     * String Search and String Substitution
  3849. ----------------:     * Movement Within the Edit Buffer
  3850. ----------------:     * Reading in a File After a Specified Line
  3851. ----------------:     * Writing out a Range of Lines to a File
  3852. ----------------:     * Built-in, online Documentation (Summary)
  3853. ----------------:  
  3854. ----------------:  ALED's design includes an input line editor, which allows
  3855. ----------------:  the user to edit text as he types it.  I was surprised
  3856. ----------------:  NOT to find such a basic function available in TEXT_IO.
  3857. ----------------:  Did I miss something?
  3858. ----------------:  
  3859. ----------------:  ALED is divided into the following files.  The order
  3860. ----------------:  in which they are listed is the compilation order.
  3861. ----------------:  
  3862. ----------------:  SIMTEL20      Ada Package/Procedure  Comments
  3863. ----------------:
  3864. ----------------:  LIST.ADA      generic_list           Components library
  3865. ----------------:                                       of linked-list routines
  3866. ----------------:  
  3867. ----------------:  ED-SPT.ADA    edit_support           Visible section
  3868. ----------------:                                       of editor support
  3869. ----------------:                                       package (which contains
  3870. ----------------:                                       a few basic routines,
  3871. ----------------:                                       such as the input line
  3872. ----------------:                                       editor)
  3873. ----------------:  
  3874. ----------------:  ED-SPTB.ADA   edit_support           Body of editor support
  3875. ----------------:                                       package
  3876. ----------------:  
  3877. ----------------:  ED-WRK.ADA    edit_worker            Visible seciton of
  3878. ----------------:                                       workhorse routines
  3879. ----------------:                                       for the editor;
  3880. ----------------:                                       all major editor
  3881. ----------------:                                       functions and their
  3882. ----------------:                                       related support
  3883. ----------------:                                       routines are here
  3884. ----------------:                                       (such as list lines)
  3885. ----------------:  
  3886. ----------------:  ED-WRKB.ADA   edit_worker            Body of editor
  3887. ----------------:                                       workhorse routines
  3888. ----------------:  
  3889. ----------------:  ED.ADA        editor                 Mainline of ALED
  3890. ----------------:  
  3891. ----------------:  
  3892. --                                                           -*
  3893. ------------------ Revision history ---------------------------
  3894. --                                                           -*
  3895. -- DATE         VERSION    AUTHOR                  HISTORY
  3896. -- 12/5/84        1.0   Richard Conn            Initial Release
  3897. -- 1/21/85        2.0   Richard Conn            Production version
  3898. -- 2/15/85        2.1   Richard Conn            Minor bug fix
  3899. -- 8/21/85        3.0   Chuck Howell            Port to CAIS
  3900. -- 2/13/86        3.1   Chuck Howell            Change CAIS Version
  3901. --    NB: changes for the CAIS port are indicated by one of the following 
  3902. --        on each affected line:
  3903. --        --!Rem   Comments, remarks
  3904. --        --!Add   Lines added to the code
  3905. --        --!Del   Lines deleted from the code
  3906. --        --!Cha   Lines changed in the code
  3907. --        (It is a bit subjective; when does a big change become
  3908. --         a delete and an add ?)
  3909. --                                                           -*
  3910. ------------------ Distribution and Copyright -----------------
  3911. --                                                           -*
  3912. -- This prologue must be included in all copies of this software.
  3913. --
  3914. -- This software is copyright by the author.
  3915. --
  3916. -- This software is released to the Ada community.
  3917. -- This software is released to the Public Domain (note:
  3918. --   software released to the Public Domain is not subject
  3919. --   to copyright protection).
  3920. -- Restrictions on use or distribution:  NONE
  3921. --                                                           -*
  3922. ------------------ Disclaimer ---------------------------------
  3923. --                                                           -*
  3924. -- This software and its documentation are provided "AS IS" and
  3925. -- without any expressed or implied warranties whatsoever.
  3926. -- No warranties as to performance, merchantability, or fitness
  3927. -- for a particular purpose exist.
  3928. --
  3929. -- Because of the diversity of conditions and hardware under
  3930. -- which this software may be used, no warranty of fitness for
  3931. -- a particular purpose is offered.  The user is advised to
  3932. -- test the software thoroughly before relying on it.  The user
  3933. -- must assume the entire risk and liability of using this
  3934. -- software.
  3935. --
  3936. -- In no event shall any person or organization of people be
  3937. -- held responsible for any direct, indirect, consequential
  3938. -- or inconsequential damages or lost profits.
  3939. --                                                           -*
  3940. -------------------END-PROLOGUE--------------------------------
  3941. --::::::::::::::
  3942. --editor_list.a
  3943. --::::::::::::::
  3944.  
  3945. -------- SIMTEL20 Ada Software Repository Prologue ------------
  3946. --                                                           -*
  3947. -- Unit name    : generic package EDITOR_LIST
  3948. -- Version      : 1.1
  3949. -- Author       : Richard Conn
  3950. --              : Texas Instruments
  3951. --              : PO Box 801, Mail Stop 8007
  3952. --              : McKinney, TX  75069
  3953. -- DDN Address  : RCONN@SIMTEL20
  3954. -- Copyright    : (c) 1984 Richard Conn
  3955. -- Date created :  OCTOBER 2, 1984
  3956. -- Release date :  NOVEMBER 29, 1984
  3957. -- Last update  :  C. Howell  August 21, 1985
  3958. --                 (renamed to Editor_List only).
  3959. --                                                           -*
  3960. ---------------------------------------------------------------
  3961. --                                                           -*
  3962. -- Keywords     :  DOUBLY-LINKED LIST
  3963. ----------------:  LIST MANIPULATION
  3964. --
  3965. -- Abstract     :  This package provides a number of routines
  3966. ----------------:  which can be used to manipulate a doubly-
  3967. ----------------:  linked list.  See the visible section for
  3968. ----------------:  a rather complete set of documentation on
  3969. ----------------:  the routines.
  3970. ----------------:  
  3971. ----------------:  Each element of the list is of the following
  3972. ----------------:  structure:
  3973. ----------------:     RECORD
  3974. ----------------:      contents: element_object;  -- data
  3975. ----------------:      next:     element_pointer; -- ptr
  3976. ----------------:    previous: element_pointer; -- ptr
  3977. ----------------:     END RECORD;
  3978. ----------------:
  3979. --                                                           -*
  3980. ------------------ Revision history ---------------------------
  3981. --                                                           -*
  3982. -- DATE         VERSION    AUTHOR                  HISTORY
  3983. -- 11/29/84       1.0    Richard Conn        Initial Release
  3984. -- 08/21/85       1.1  Chuck Howell     Renamed to Editor_List
  3985. --                                                           -*
  3986. ------------------ Distribution and Copyright -----------------
  3987. --                                                           -*
  3988. -- This prologue must be included in all copies of this software.
  3989. --
  3990. -- This software is copyright by the author.
  3991. --
  3992. -- This software is released to the Ada community.
  3993. -- This software is released to the Public Domain (note:
  3994. --   software released to the Public Domain is not subject
  3995. --   to copyright protection).
  3996. -- Restrictions on use or distribution:  NONE
  3997. --                                                           -*
  3998. ------------------ Disclaimer ---------------------------------
  3999. --                                                           -*
  4000. -- This software and its documentation are provided "AS IS" and
  4001. -- without any expressed or implied warranties whatsoever.
  4002. -- No warranties as to performance, merchantability, or fitness
  4003. -- for a particular purpose exist.
  4004. --
  4005. -- Because of the diversity of conditions and hardware under
  4006. -- which this software may be used, no warranty of fitness for
  4007. -- a particular purpose is offered.  The user is advised to
  4008. -- test the software thoroughly before relying on it.  The user
  4009. -- must assume the entire risk and liability of using this
  4010. -- software.
  4011. --
  4012. -- In no event shall any person or organization of people be
  4013. -- held responsible for any direct, indirect, consequential
  4014. -- or inconsequential damages or lost profits.
  4015. --                                                           -*
  4016. -------------------END-PROLOGUE--------------------------------
  4017.  
  4018. -- 
  4019. -- Generic Package to Handle Doubly-Linked Lists
  4020. --    by Richard Conn, TI Ada Technology Branch
  4021. -- 
  4022. -- The purpose of this package is to provide a software component
  4023. -- which can be generically instantiated to handle any type of
  4024. -- doubly-linked list.  The set of routines provided in this package
  4025. -- are general-purpose in nature and manipulate the elements of a
  4026. -- doubly-linked list without regard to their contents.  Each element
  4027. -- of the list is of the following structure:
  4028. -- 
  4029. --    record
  4030. --      content  : element_object;  -- the data in the list element
  4031. --      next     : element_pointer; -- pointer to the next element
  4032. --      previous : element_pointer; -- pointer to the previous element
  4033. --    end record;
  4034. -- 
  4035.  
  4036. generic
  4037.     type element_object is private;
  4038.  
  4039.  
  4040. package Editor_List is
  4041.  
  4042. -- 
  4043. -- The following type declarations are used throughout is package
  4044. -- and are needed by the programs which WITH this package.
  4045. -- 
  4046.  
  4047.     type list_element;
  4048.     type element_pointer is access list_element;
  4049.     type list_element is
  4050.         record
  4051.             content  : element_object; -- the generic object
  4052.             next     : element_pointer;
  4053.             previous : element_pointer;
  4054.         end record;
  4055.  
  4056.  
  4057. -- 
  4058. -- The following procedures and functions initialize the list and
  4059. -- return pointers to the three list elements which are continuously
  4060. -- tracked by the routines in this package.  These list elements
  4061. -- are:
  4062. -- 
  4063. --    first_element       the first element in the list
  4064. --    last_element        the last element in the list
  4065. --    current_element     the current element in the list
  4066. -- 
  4067.  
  4068.     procedure initialize_list;
  4069.     function  return_first_element   return element_pointer;
  4070.     function  return_last_element    return element_pointer;
  4071.     function  return_current_element return element_pointer;
  4072.     function  return_first_element   return element_object;
  4073.     function  return_last_element    return element_object;
  4074.     function  return_current_element return element_object;
  4075.  
  4076. -- 
  4077. -- The following procedures and functions manipulate the current
  4078. -- element pointer.  The following table outlines their functions:
  4079. -- 
  4080. --    set_first           the first element becomes the current element
  4081. --    set_last            the last element becomes the current element
  4082. --    current_index       return the number of the current element
  4083. --                          (ordinal); 0 returned if list is empty
  4084. --    current_next        set current element to next element in the
  4085. --                          list; return TRUE if done or FALSE if
  4086. --                          already at end of list
  4087. --    current_previous    set current element to previous element in the
  4088. --                          list; return TRUE if done or FALSE if
  4089. --                          already at front of list
  4090. --    set_current_index   set the Nth element as the current element;
  4091. --                          return TRUE if done or FALSE if end of list
  4092. --                          encountered, in which case the last element
  4093. --                          becomes the current element
  4094. -- 
  4095.  
  4096.     procedure set_first;
  4097.     procedure set_last;
  4098.     function  current_index     return natural;
  4099.     function  current_next      return boolean;
  4100.     function  current_previous  return boolean;
  4101.     function  set_current_index (index : natural) return boolean;
  4102.  
  4103. -- 
  4104. -- The following functions return the index of the last element in
  4105. -- the list and indicate if the list is empty or not.
  4106. -- 
  4107. --    last_index          return the number of the last element
  4108. --                          (ordinal); 0 returned if list is empty
  4109. --    list_empty          return TRUE if the list is empty; FALSE if
  4110. --                          the list is not empty
  4111. --    at_end_of_list      return TRUE if the current_element is also
  4112. --                          the last_element; return FALSE if not
  4113. --    at_front_of_list    return TRUE if the current_element is also
  4114. --                          the first_element; return FALSE if not
  4115. -- 
  4116.  
  4117.     function last_index       return natural;
  4118.     function list_empty       return boolean;
  4119.     function at_end_of_list   return boolean;
  4120.     function at_front_of_list return boolean;
  4121.  
  4122. -- 
  4123. -- The following procedures and functions are used to manipulate
  4124. -- the elements in the list.
  4125. -- 
  4126. --    append_element       append the indicated element after the
  4127. --                           current_element in the list; the
  4128. --                           current_element is set to the new
  4129. --                           element
  4130. --    insert_element       insert the indicated element before the
  4131. --                           current_element in the list; the
  4132. --                           current_element is unchanged
  4133. --    delete_element       delete the current_element from the list;
  4134. --                           the next element is the new current_element
  4135. --                           unless there is no next element, in which
  4136. --                           case the previous element is the new
  4137. --                           current_element
  4138. -- 
  4139.  
  4140.     procedure append_element (element : element_pointer);
  4141.     procedure append_element (element : element_object);
  4142.     procedure insert_element (element : element_pointer);
  4143.     procedure insert_element (element : element_object);
  4144.     procedure delete_element;
  4145.  
  4146. -- 
  4147. -- The following function and procedure are used to dynamically
  4148. -- create new elements and to free the space occupied by unneeded
  4149. -- elements.
  4150. -- 
  4151. --    new_element        returns a pointer to a new list_element
  4152. --    free_element       frees the indicated list_element
  4153. -- 
  4154.  
  4155.     function  new_element  return element_pointer;
  4156.     procedure free_element (element : element_pointer);
  4157.  
  4158. end Editor_List;
  4159.  
  4160.  
  4161. -- 
  4162. -- BODY of Editor_List
  4163. -- 
  4164. package body Editor_List is
  4165.  
  4166. -- 
  4167. -- Definition of the three element pointers
  4168. -- 
  4169.     first_element, last_element, current_element : element_pointer;
  4170.  
  4171. -- 
  4172. -- Procedure to initialize the list
  4173. --    All element pointers are initialized to null
  4174. -- 
  4175.     procedure initialize_list is
  4176.     begin
  4177.         first_element := null;
  4178.         last_element := null;
  4179.         current_element := null;
  4180.     end initialize_list;
  4181.  
  4182. -- 
  4183. -- Functions to return element pointers
  4184. -- 
  4185.     function return_first_element return element_pointer is
  4186.     begin
  4187.         return first_element;
  4188.     end return_first_element;
  4189.  
  4190.     function return_first_element return element_object is
  4191.     begin
  4192.         return first_element.content;
  4193.     end return_first_element;
  4194.  
  4195.     function return_last_element return element_pointer is
  4196.     begin
  4197.         return last_element;
  4198.     end return_last_element;
  4199.  
  4200.     function return_last_element return element_object is
  4201.     begin
  4202.         return last_element.content;
  4203.     end return_last_element;
  4204.  
  4205.     function return_current_element return element_pointer is
  4206.     begin
  4207.         return current_element;
  4208.     end return_current_element;
  4209.  
  4210.     function return_current_element return element_object is
  4211.     begin
  4212.         return current_element.content;
  4213.     end return_current_element;
  4214.  
  4215. -- 
  4216. -- Current element pointer manipulation
  4217. -- 
  4218.     procedure set_first is
  4219.     begin
  4220.         current_element := first_element;
  4221.     end set_first;
  4222.  
  4223.     procedure set_last is
  4224.     begin
  4225.         current_element := last_element;
  4226.     end set_last;
  4227.  
  4228.     function current_index return natural is
  4229.         local_element : element_pointer;
  4230.         index         : natural;
  4231.     begin
  4232.         index := 0; -- initialize counter and set empty list return
  4233.         if current_element /= null then
  4234.             local_element := first_element; -- point to first element
  4235.             index := 1;
  4236.             while local_element /= current_element loop
  4237.                 exit when local_element = null; -- error trap
  4238.                 local_element := local_element.next;
  4239.                 index := index + 1;
  4240.             end loop;
  4241.         end if;
  4242.         return index;
  4243.     end current_index;
  4244.  
  4245.     function current_next return boolean is
  4246.     begin
  4247.         if current_element = last_element then
  4248.             return FALSE;
  4249.         else
  4250.             current_element := current_element.next;
  4251.             return TRUE;
  4252.         end if;
  4253.     end current_next;
  4254.  
  4255.     function current_previous return boolean is
  4256.     begin
  4257.         if current_element = first_element then
  4258.             return FALSE;
  4259.         else
  4260.             current_element := current_element.previous;
  4261.             return TRUE;
  4262.         end if;
  4263.     end current_previous;
  4264.  
  4265.     function set_current_index (index : natural) return boolean is
  4266.         counter : natural;
  4267.     begin
  4268.         current_element := first_element; -- start at first element
  4269.         if index <= 1 then
  4270.             return TRUE;
  4271.         else
  4272.             for counter in 1 .. index - 1 loop
  4273.                 if current_element = last_element then
  4274.                     return FALSE;
  4275.                     exit;      -- this exit may not be necessary
  4276.                 else
  4277.                     current_element := current_element.next;
  4278.                 end if;
  4279.             end loop;
  4280.             return TRUE;
  4281.         end if;
  4282.     end set_current_index;
  4283.  
  4284. -- 
  4285. -- Return the index of the last element in the list
  4286. -- 
  4287.     function last_index return natural is
  4288.         current_save : element_pointer;
  4289.         index        : natural;
  4290.     begin
  4291.         current_save := current_element;
  4292.         current_element := last_element;
  4293.         index := current_index;
  4294.         current_element := current_save;
  4295.         return index;
  4296.     end last_index;
  4297.  
  4298. -- 
  4299. -- Determine if the list is empty; return TRUE if so, FALSE if not
  4300. -- 
  4301.     function list_empty return boolean is
  4302.     begin
  4303.         if first_element = null then
  4304.             return TRUE; -- list is empty
  4305.         else
  4306.             return FALSE; -- list is not empty
  4307.         end if;
  4308.     end list_empty;
  4309.  
  4310. -- 
  4311. -- Determine if at first element in list; return TRUE if so
  4312. -- 
  4313.     function at_front_of_list return boolean is
  4314.     begin
  4315.         if current_element = first_element then
  4316.             return TRUE;
  4317.         else
  4318.             return FALSE;
  4319.         end if;
  4320.     end at_front_of_list;
  4321.  
  4322. -- 
  4323. -- Determine if at last element in list; return TRUE if so
  4324. -- 
  4325.     function at_end_of_list return boolean is
  4326.     begin
  4327.         if current_element = last_element then
  4328.             return TRUE;
  4329.         else
  4330.             return FALSE;
  4331.         end if;
  4332.     end at_end_of_list;
  4333.  
  4334. -- 
  4335. -- Procedures to manipulate elements in list
  4336. --  These procedures insert elements into the list and
  4337. --  delete elements from the list
  4338. -- 
  4339.     procedure append_element (element : element_pointer) is
  4340.     begin
  4341.         if list_empty then
  4342.             first_element := element;
  4343.             last_element := element;
  4344.             current_element := element;
  4345.             element.next := null;
  4346.             element.previous := null;
  4347.         else
  4348.             element.next := current_element.next;
  4349.             current_element.next := element;
  4350.             element.previous := current_element;
  4351.             if element.next /= null then
  4352.                 element.next.previous := element;
  4353.             else
  4354.                 last_element := element;
  4355.             end if;
  4356.         end if;
  4357.         current_element := element;
  4358.     end append_element;
  4359.  
  4360.     procedure append_element (element : element_object) is
  4361.         loc_element : element_pointer;
  4362.     begin
  4363.         loc_element := new_element;
  4364.         loc_element.content := element;
  4365.         append_element (loc_element);
  4366.     end append_element;
  4367.  
  4368.     procedure insert_element (element : element_pointer) is
  4369.     begin
  4370.         if list_empty then
  4371.             first_element := element;
  4372.             last_element := element;
  4373.             current_element := element;
  4374.             element.next := null;
  4375.             element.previous := null;
  4376.         else
  4377.             element.previous := current_element.previous;
  4378.             current_element.previous := element;
  4379.             element.next := current_element;
  4380.             if element.previous /= null then
  4381.                 element.previous.next := element;
  4382.             else
  4383.                 first_element := element;
  4384.             end if;
  4385.         end if;
  4386.     end insert_element;
  4387.  
  4388.     procedure insert_element (element : element_object) is
  4389.         loc_element : element_pointer;
  4390.     begin
  4391.         loc_element := new_element;
  4392.         loc_element.content := element;
  4393.         insert_element (loc_element);
  4394.     end insert_element;
  4395.  
  4396.     procedure delete_element is
  4397.         temp_element : element_pointer;
  4398.     begin
  4399.         if not list_empty then
  4400.  
  4401.             if current_element = first_element then
  4402.                 first_element := current_element.next;
  4403.             else
  4404.                 current_element.previous.next := current_element.next;
  4405.             end if;
  4406.  
  4407.             if current_element = last_element then
  4408.                 last_element := current_element.previous;
  4409.                 temp_element := last_element;
  4410.             else
  4411.                 current_element.next.previous := current_element.previous;
  4412.                 temp_element := current_element.next;
  4413.             end if;
  4414.  
  4415.             free_element (current_element);
  4416.             current_element := temp_element;
  4417.         end if;
  4418.     end delete_element;
  4419.  
  4420. -- 
  4421. -- Memory management routines
  4422. --   Obtain a new list element and free old, unneeded list elements
  4423. -- 
  4424.     function new_element return element_pointer is
  4425.     begin
  4426.         return (new list_element);
  4427.     end new_element;
  4428.  
  4429.     procedure free_element (element : element_pointer) is
  4430. -- 
  4431. -- This procedure is a dummy for now; the following generic
  4432. -- instantiation is what it should be, but there is a bug in my
  4433. -- Ada compiler which prevents this instatiation from working
  4434. -- 
  4435. -- procedure free_element is new unchecked_deallocation
  4436. --    (list_element, element_pointer);
  4437. -- 
  4438.     begin
  4439.         null;
  4440.     end free_element;
  4441.  
  4442. end Editor_List;
  4443.