!			TECO.INI - Kelvin Smith				!
! Financial Computer Systems, 1 Strawberry Hill Ct., Stamford, CT 06902 !

! This is totally unsupported by FCS and by its author, and no		!
! warranty, express or implied, is made regarding its functions.	!

! This initialization file does a series of loads into q-registers and	!
! executes two user-defined switches, if present.  Note that inside	!
! the q-register routines, local q-registers (name preceded by a ".")	!
! are used.  These do not exist in TECO before version 40.  If you are	!
! running an old TECO, you must change these to regular q-register	!
! names; you should push and pop the registers used at the beginning	!
! and end of the routines.						!

::@S%MUNG%
   "S @O!EXIT!                 ! MUNG command--don't execute this stuff !
   '
@^A/Loading library functions
/                              ! Let user know what's happening !


! MQ - back up a file, returning to same position			!
! 1MQ - exit, marking position such that /FIND returns to that spot	!
! -1MQ - find front of file (useful if past first page)			!
!  Equivalent to VTEDIT commands $1$F, $0$F, and $F respectively.	!

@^UQ}
 +0U.A
 @EW//                                ! Make sure we have right file name !
 Q.A+1">                              ! 0MQ or 1MQ !
        @I%~~/\~~
%     '                               ! Mark position (/FIND compatible) !
 Q.A-1"<                              ! -1MQ or 0MQ !
        EC                            ! Close and !
        @EB%^EQ*%                     !  reopen same file !
        Q.A"=                         ! 0MQ !
             @FN%~~/\~~
%%                                    ! Find marker and delete !
             @^A/File backed up
/
           | Y                        ! -1MQ !
             @^A/At beginning of / :G* 13^T 10^T  ! Verify the file !
           '
      | @^A/Position marked, exiting
/       EX                            ! 1MQ !
      '
}


! [n]M1 - delete n words (default: 1), saving deleted text in q-reg 0.	!
!  "Word" defined as series of printing characters followed by series	!
!  of non-printing and/or space characters (ASCII<=32).			!
!  Reasonably equivalent to VTEDIT [-]^B (may behave differently with	!
!  starting blanks and one-letter words).				!

@^U1~
 +0U.B                                ! Pick up any argument !
 Q.B"=                                ! No argument entered !
      1U.B                            ! Default = 1 !
    '
 Q.B">                                ! Positive direction !
      Z-."=                           ! If at end of buffer !
           @O!M1EXIT!                 ! Nothing to delete !
         '
      0U.A
      Q.B<                            ! For QB words !
           < %.AA-33:;                ! Skip over printing chars !
           >
           < %.AA-33;                 ! Skip over control and space chars !
             Q.AA"<                   ! Have we hit end of buffer? !
                   1;                 ! We can quit !
                 '
           >
           Q.AA"<                     ! Exit main loop at buffer end !
                 1;
               '
         >
    | ."=                             ! If at start of buffer !
         @O!M1EXIT!                   ! Nothing to delete !
       '
      -1U.A                           ! Negative direction - always delete !
      -Q.B<                           !  at least one character !
            < -1%.AA-33;              ! Back over control and space chars !
            >
            < -1%.AA-33:;             ! Back over printing chars !
            >                         ! No check needed for beginning of !
                                      !  buffer: stops automatically (AA=-1) !
            %.A                       ! Correct overrun !
             +.-1:;                   ! Exit loop if at start of buffer !
          >
    '
 .,.+Q.AX0                            ! Save in q-reg 0 before deleting !
 Q.AD                                 ! Delete it !
 !M1EXIT!
~


! [n]M2 - Scrolling TECO for wide screen; n is lines of scrolling	!
!  command region (default: 8).  Set flag so that failing searches	!
!  preserve dot (to avoid repainting the screen), and let user know.	!

@^U2~
 +0U.A                                ! Read in any argument !
 0,16ED                               ! Failing searches preserve dot !
 132,1:W^[                            ! Wide screen !
 Q.A"=
      8U.A                            ! Default of eight lines !
    '
 Q.A,7:W                              ! Set up scrolling TECO !
 @^A/Failing searches preserve dot/ 13^T 10^T
~


! m,nM3 - effective m,nD (or m,nK), but save deleted text in q-reg 0.	!
!  This can work as a cut-and-paste operator, and can also give peace	!
!  of mind when making large deletions. . . .				!

@^U3~
 U.A U.B
 Q.A,Q.BX0                            ! Save text before deleting !
 Q.A,Q.BD                             ! Delete it !
~


! [n]M4: Delete all text until n-th occurrence of character given.	!
!  Store deleted text in q-reg 0; if n<0, append text to q-reg 0.	!
!  Like M3, this is useful as a cut-and-paste tool.			!
!    Note:  This uses the same case-matching procedures as the rest of	!
!  TECO; i.e., if the ^X flag is set non-zero, the exact character must	!
!  be found for a match.  If ^X is zero, either case matches.		!

@^U4~
 +0U.0                                ! Get any argument !
 Q.0"<                                ! Check for negative (append) !
      -1U.B                           ! Flag the append request !
      0-Q.0U.0                        ! Switch argument back to positive !
    | 0U.B                            ! Positive number--no append request !
    '
 Q.0"=
      1U.0                            ! Default: first occurrence !
    '
 .U.A                                 ! Note where we are !
 @^A/Chr? / ^T@^U.A%%                 ! Get character from user; one-char !
 13^T 10^T                            !  input.  Give <CR> after !
 Q.0:@S%^EQ.A%                        ! Find it !
      "S
        Q.B"N                         ! Negative: append to q-reg 0 !
             Q.A,.:X0 Q.A,.D
           | Q.A,.X0  Q.A,.D          ! Positive: stuff it in !
           '
      | Q.AJ                          ! Couldn't find it--restore pointer !
        7^T                           !  and ring bell !
      '
~


! M8:  Print a listing of present capabilities !

@^U8~
Present functions:
MQ - Make backup       1MQ - Quit, position marked    -1MQ - Front of file
[n]M1 - Delete word(s) [n]M2 - 132 col, n line scroll (def: 8)
m,nM3 - Cut to Q0      [n]M4 - Cut until nth occurrence of char (n<0: append)
G0 - Retrieve most recent cut

~


! Check the file name.  If it exists and doesn't include a dot,   !
!  assume a .BAS file type and /B2 editing format.                !

J
:@S%^ES^N/%                   ! Is there a space (not before switch)? !
  "S                          !  Yes -- beginning of file name (TECO filnam) !
    .U.A                      !  mark it !
    :@S%.%                    ! Look for a dot !
      "U                      ! If none... !
        :@S%/%                ! Look for a switch !
          "S                  ! Found one !
            .-Q.A">           ! If it's after the file name !
                   R          !  then position pointer before it !
                 | ZJ         !  else go to end of command line !
                 '
          | ZJ                ! No switches -- go to end of command line !
          '
        @I%.BAS/B2%   ! No dot: assume .BAS type and /B2 continuation format !
   '  '


! Switch operations:  check the buffer to see if any user-defined !
! switches have been invoked.  If so, delete and execute them.    !

! /W[:n] - Wide screen scrolling TECO.  Equivalent to [n]M2 !

J
:@S%/W%
  "S                          ! Found /W switch !
    -2D                       ! Delete it !
    ::@S%:%                   ! A colon modifier? !
       "S
         \U.A ^S-1D           ! Get and delete any number !
       | 0U.A                 ! Else 0 !
       '
    Q.AM2                     ! Execute M2 with appropriate number !
  '


! /X:"..." - The wild card.  Execute the sequence of commands following	!
! once the file has been opened.  No escapes can be embedded, since	!
! they will terminate the CCL command (use @-modified commands if	!
! necessary).  However, the last command is automatically followed by	!
! an escape.  The delimiter (shown above as ") can be any printing	!
! character.  Store the command in a file TECXnn.TMP (placed at the	!
! beginning of the directory), where nn is the job number, zero-filled	!
! (RSTS LOGOUT will automatically kill it on logging out), then EI it,	!
! which won't actually execute until TECO.TEC is done.			!
!   Note that MODE will not work under non-RSTS systems, and the file	!
! naming scheme is only needed if more than one person may use TECO in	!
! the same account simultaneously (to avoid conflicts in file names).	!

J
:@S%/X:%
  "S
    -3D                       ! Delete switch !
    0A@^U.A%%                 ! Store delimiter char !
    C                         ! Move past it !
    .U.A                      ! Mark beginning !
    @S%^EQ.A%                 ! Search for end delimiter !
    Q.A,.-1X.A                ! Store command !
    Q.A-1,.K                  ! Wipe out it & delimiters !

    @^U.B%TECX%               ! Build file name; compatible with TMP killing !
    0EJ-10"<                  !  by RSTS LOGOUT !
            @I%0%             ! Leading zero if necessary for job number !
          '
    0EJ\                      ! Necessary to go through buffer because no !
                              ! other way to make number into characters  !
    .-2,.:X.B -2D             ! Append job number to q-reg B !
    @:^U.B%.TMP/MODE:#3000%   ! Mode 3000 (octal) -- front of directory !
    @EW%^EQ.B%                ! Open it (for output) !
    .U.P
    G.A                       ! The commands !
    @I/@EI\\/                 ! Close off input stream !
    27@I// 27@I//             ! Add double escape to execute it !
    Q.P,.PW Q.P,.K            ! Write to file and clean up !
    EF                        ! Close file !
    @EI%^EQ.B%                !  and execute it !
    @^A/Executing...
/
   '
!EXIT!
