home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol076 / ed.prn < prev    next >
Encoding:
Text File  |  1984-04-29  |  8.8 KB  |  175 lines

  1.  
  2.  
  3.             Enhancing the Dr. Dobb's C Screen Editor
  4.  
  5.  
  6.  
  7.                 Alan D. Howard
  8.                 Rt. 3, Box 680
  9.                    Crozet, VA 22932
  10.  
  11.                  July 24, 1982
  12.  
  13.  
  14.  
  15.  
  16.         At the beginning of Edward K. Ream's article introducing his
  17.        Small-C Screen Editor in Dr. Dobbs Journal (#63, January, 1982)
  18.        he asked whether our present editor lacked flexibility,
  19.        transporability, and extensibility.  Although my mainstay editor
  20.        has been PIE from Software Toolworks, I have often been annoyed
  21.        at its inability to edit large files or to make major structural
  22.        changes in text.  On the other hand, Ream's editor as presented
  23.        did not go much beyond PIE and seemed clumsy in its Edit-mode,
  24.        but it does encourage adapting it to fit individual needs since
  25.        it is presented in source code.    Thus, after several nights of
  26.        typing and several more nights of debugging, I had the C editor
  27.        up and running.
  28.        I have been modifying the editor during the last few months and
  29.        it has evolved to the point that I feel some of Dr. Dobb's
  30.        readers may be interested.  The changes are of several types:
  31.         1)    Extensions to the file-handling and buffer management to
  32.        permit editing large files, extracting parts of the text to a
  33.        different file, and moving and copying portions of the text
  34.        within the file.
  35.         2)    Changing the edit mode operation to recognize special
  36.        keys on the H19 Terminal or H89 Computer instead of single-letter
  37.        commands.  As a bonus, the editor now assumes eXchange mode for
  38.        any other typed key.
  39.         3)    Addition of a few new commands to the edit-mode and some
  40.        changes in rules of operation.
  41.         4)    Slight modifications to allow modular compilation using
  42.        the Software Toolworks C/80 compiler.
  43.        These enhancements are discussed below.
  44.        A documentation file is included
  45.        which summarizes the expanded features and all
  46.        commands.
  47.  
  48.           Changes to File Handling and Command-Mode Operation
  49.  
  50.         Most of the changes to the command-mode are concerned with
  51.        adding flexibility to file handling and major buffer alterations.
  52.        Separate read and write files are now maintained, with load
  53.        <nfilename> specifying the read file name, clearing the
  54.        buffer, reading the file, and closing the read file if it all
  55.        fits in the buffer.  Otherwise as much as fits is read in, and
  56.        the read file remains open.  The open <filename> command
  57.        opens the readfile without clearing the buffer or reading
  58.        anything in.  More from the read file can be added to the buffer
  59.        with either the rest or add <n> commands. Rest reads in
  60.        as much more as possible and gives the option of clearing the
  61.        buffer, but add <n> reads only <n> more lines
  62.        without clearing the buffer.  The write file is specified by name
  63.        <filename> for a new file, or delname <filename>
  64.        for writing over an existing file (This replaces the resave
  65.        command).  Write <n> writes n lines from the buffer to
  66.        the write file, deleting those lines.  To balance the existing
  67.        append <filename> command, an extract <from to>
  68.        command has been added to write the indicated line range to a new
  69.        file (the name is requested after the command is entered) without
  70.        deleting those lines from the buffer.  Finally, to allow
  71.        flexibility, the read and write files can be closed by closeread
  72.        and closewrite.
  73.         Major structural changes in the file can now be made using
  74.        the copy <from to n> and move <from to n>
  75.        commands, which take n lines from <from> and copy them to
  76.        before line <to>.  In addition, move deletes the
  77.        <n> lines at <from>.  For speed, these routines
  78.        open up the new space, and then do the copying or moving.  No
  79.        move or copy is allowed if there is not room in the buffer.  If
  80.        buffer space is tight, or if the move or copy is to a part of the
  81.        file not currently in memory, then use the extract and append
  82.        commands, which use the disk as a buffer.
  83.         The following command-mode commands are unaltered from the
  84.        original:  append, change, clear, delete, dos, find, g, list,
  85.        search, and tabs.
  86.  
  87.                Changes to Edit and Insert Modes
  88.  
  89.         The most important change to the edit mode is the
  90.        replacement of the single-letter commands by escape-character
  91.        sequences generated by the special keys on the H19/H89 keyboard.
  92.        Similar keys, but with different escape sequences, are found on
  93.        many other terminals and computers.  This allows default use of
  94.        the eXchange mode (replacing contents of cursor position with the
  95.        typed keystroke) for normal keys, including the space bar.  Most
  96.        special characters and edit mode commands retain their original
  97.        functions (see the documentation portion of the listing for
  98.        details), but two new commands have been created for the edit
  99.        mode:  the HOME key moves alternately to the top and bottom line
  100.        on the screen, and the ERASE key erases from the current cursor
  101.        position to the end of the line.  More subtle changes have also
  102.        been made.  The RETURN key moves to the beginning of the next
  103.        line in Edit mode, but acts as the insert down key in the Insert
  104.        mode.  Both the DC and DELETE keys delete the character at the
  105.        cursor, but BACKSPACE deletes the character to the left of the
  106.        cursor, the same as the original delete character special key.
  107.        The only commands remaining as control codes are split and join.
  108.        There is some room for expansion:  three keys are currently
  109.        assigned to force command mode, but could be reassigned.  Note
  110.        that the ESC key must be pressed twice to be recognized, because
  111.        it is also issued by the special character codes of the keyboard.
  112.        My choice of key assignments and features has admittedly been
  113.        influenced by the PIE editor.
  114.  
  115.                 Implementation Details
  116.  
  117.         I'd like to start out with an unsolicited endorsement of the
  118.        Software Toolworks C/80 Compiler, now in version 2.0 and
  119.        incorporating almost all of the C language.  Its a decendent of
  120.        Small-C and is cheap, fast, and powerful.  Its salient feature in
  121.        the context of the editor is support for modular compilation
  122.        using Microsoft M80 and L80.  Since the editor is broken into 9
  123.        fairly independent modules, changes can be made in one without
  124.        having to recompile everything.    Also, SID can be used for
  125.        debugging using global variable and function names.  The
  126.        disadvantage is that variable and function names must be distinct
  127.        at six characters length.  This has necessitated renaming several
  128.        functions in the editor, as listed in Figure 1.    Also, to
  129.        force the main buffer to be at the end of the program, the short
  130.        program MBUFFER.MAC must be assembled by M80 and be the last
  131.        module linked (after the C/80 CLIBRARY module).
  132.         Most details of the changes are explained in the listing.
  133.  
  134.                   Concluding Remarks
  135.  
  136.         This editor is a very useful addition to my stable of
  137.        inexpensive editors, and is particularly suited to editing large
  138.        files, interleaving text from other files, and breaking up a file
  139.        or portions of a file into smaller pieces.  It doesn't do
  140.        everything, and some of the things it does do go excruciatingly
  141.        slowly. In particular, the default eXchange operation in the Edit
  142.        mode is somewhat slower than typing speed for my 2 Mz H89, as are
  143.        the insert and delete line commands.  I suggest those with H89's
  144.        go through the bothersome task of reassembling their BIOS with
  145.        the type-ahead buffer option.  The search, find, and change
  146.        commands would benefit from some assembly language optimization.
  147.         When I move on to my next system, I will feel secure that I
  148.        have its first editor waiting in the wings, and it won't cost me
  149.        twice as much as my previous editor for the same features.  The
  150.        modified editor is in the public domain.
  151.  
  152.  
  153.                 Altered Function Names
  154.  
  155.        Original            New
  156.  
  157.        search1               suurch
  158.        outgetx               outxget
  159.        outgety               outyget
  160.        outhasdn            outdnhas
  161.        outhasup            outuphas
  162.        pmtmode1            pmt1mode
  163.        pmtfile1            pmt1file
  164.        pmtline1            pmt1line
  165.        pmtcol1               pmt1col
  166.        sysmovdn            sysdnmov
  167.        sysmovup            sysupmov
  168.        bufdeln               bufndel
  169.        bufoutln            buflnout
  170.        bufmovup            bufupmov
  171.        bufmovdn            bufdnmov
  172.        buffer               mbuffer
  173.  
  174.                    Figure 1
  175.