home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / demos / 134 / pascal / newedt.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-04-17  |  5.5 KB  |  210 lines

  1. {$S5}   { set stack space to 5k... }
  2.  
  3. { -----------------------------------------------------------------------------
  4.  
  5.                                  NOTICE:
  6.  
  7.       THESE MATERIALS are UNSUPPORTED by OSS!  If you do not understand how to
  8.       use them do not contact OSS for help!  We will not teach you how to 
  9.       program in Pascal.  If you find an error in these materials, feel free
  10.       to SEND US A LETTER explaining the error, and how to fix it.
  11.  
  12.       THE BOTTOM LINE:
  13.  
  14.          Use it, enjoy it, but you are on your own when using these materials!
  15.  
  16.  
  17.                                DISCLAIMER:
  18.  
  19.       OSS makes no representations or warranties with respect to the contents
  20.       hereof and specifically disclaim all warranties of merchantability or
  21.       fitness for any particular purpose.   This document is subject to change
  22.       without notice.
  23.       
  24.       OSS provides these materials for use with Personal Pascal.  Use them in
  25.       any way you wish.
  26.  
  27.  
  28.    -------------------------------------------------------------------------- }
  29.  
  30.  
  31. PROGRAM Newedit;
  32.  
  33. {**************************************************************************
  34.  
  35.         PROGRAM COPYRIGHT 1986 OSS.  ALL COMMERCIAL RIGHTS RESERVED.
  36.  
  37.         This program is in the public domain.  You may give away copies of
  38.         this program and/or source code to anyone willing to take it!
  39.  
  40.         Program sets up mouse in cursor key mode then chains original
  41.         editor, passing original command-line args to program.  On exit,
  42.         restore mouse to mouse mode.
  43.  
  44.         Written 10-28-86 M. Curry
  45.  
  46.         To use this program:
  47.  
  48.         1.      Compile this program.  Compile and link for TOS!
  49.  
  50.         2.      Rename EDITOR.PRG to OLDEDIT.PRG.
  51.  
  52.         3.      Rename this program to EDITOR.PRG.
  53.  
  54.         4.      Edit any program and move the mouse!  The cursor should
  55.                 follow the mouse movements.
  56.  
  57.  
  58. ***************************************************************************}
  59.  
  60. CONST
  61.  
  62.    IKBD = 4;     { device number of Keyboard processor }
  63.    LoadAndGo = 0;
  64.  
  65. TYPE
  66.  
  67.    Cstring = PACKED ARRAY [ 1..80 ] OF CHAR;
  68.  
  69. VAR
  70.  
  71.    RetCode : Integer;   { returned value from editor }
  72.  
  73. FUNCTION  Bcostat( Dev : Integer ) : Boolean; Bios( 8 );
  74. PROCEDURE Bconout( Dev : Integer; C : Char ); Bios( 3 );
  75. PROCEDURE Pterm( Retval : Integer ); Gemdos( $4c );
  76.  
  77. FUNCTION Pexec( Mode : Integer;
  78.                 VAR Prog : Cstring;
  79.                 VAR Tail : STRING;
  80.                 Env : Long_Integer ) : Integer;
  81.                                        Gemdos( $4b );
  82.  
  83.  
  84. {**************************************************************************
  85.  
  86.         Make a C string from a Pascal string
  87.  
  88. ***************************************************************************}
  89.  
  90. PROCEDURE Make_Cstr( ps : STRING; VAR cs : Cstring);
  91. { convert pascal string ps to C string cs }
  92.  
  93.   VAR i : Integer;
  94.  
  95.   BEGIN
  96.  
  97.     cs[ 1 ] := Chr( 0 );  { set to null for safety }
  98.  
  99.     FOR i := 1 to Length( ps ) DO
  100.        cs[ i ] := ps[ i ];
  101.  
  102.     cs[ Length( ps )+1 ] := Chr( 0 );
  103.  
  104.   END;
  105.  
  106. {**************************************************************************
  107.  
  108.         Send a key to the keyboard processor
  109.  
  110. ***************************************************************************}
  111.  
  112. PROCEDURE KOUT( C : Char );
  113.  
  114. BEGIN
  115.  
  116.         WHILE NOT Bcostat( IKBD ) DO;      { wait till kbd is ready }
  117.         Bconout( IKBD, C );             { send char to kbd }
  118.  
  119. END;
  120.  
  121.  
  122. {**************************************************************************
  123.  
  124.         Set mouse in cursor key mode
  125.  
  126. ***************************************************************************}
  127.  
  128. PROCEDURE SetCurs;
  129.  
  130. BEGIN
  131.  
  132.    KOUT( #$0A );         { set mouse cursor mode            }
  133.    KOUT( #05  );         {  5 pulses / x movement           }
  134.    KOUT( #10  );         { 10 pulses / y movement           }
  135.                          { Change these to suit your taste! }
  136. END;
  137.  
  138. {**************************************************************************
  139.  
  140.         Set mouse in mouse mode
  141.  
  142. ***************************************************************************}
  143.  
  144. PROCEDURE SetMous;
  145.  
  146. BEGIN
  147.  
  148.    KOUT( #8 );          { set mouse mouse mode }
  149.  
  150. END;
  151.  
  152.  
  153. {*************************************************************************
  154.  
  155.         chain to editor program
  156.  
  157. **************************************************************************}
  158.  
  159. FUNCTION RunProg : INTEGER;
  160.  
  161. VAR
  162.    I : Integer;
  163.    Temp,
  164.    CmdLine,
  165.    Args : STRING;
  166.  
  167.    C_CmdLine : Cstring;
  168.  
  169. BEGIN
  170.  
  171.    CmdLine := 'OLDEDIT.PRG';    { name of original editor program to run }
  172.    Args := '';
  173.  
  174.  
  175.    { grab original arguments from pascal manager... }
  176.  
  177.    FOR I := 1 to Cmd_Args DO
  178.       BEGIN
  179.          Cmd_GetArg( I, Temp );
  180.          Args := Concat( Args, ' ', Temp )
  181.       END;
  182.  
  183.    Make_Cstr( CmdLine, C_CmdLine );     { convert to c flavored string }
  184.  
  185.    Args := Concat( Args, ' ' );
  186.    Args[ Length( Args ) ] := Chr( 0 );
  187.  
  188.    { use Pexec since
  189.    RunProg := Pexec( LoadAndGo, C_Cmdline, Args, 0 ); { do the evil deed }
  190.  
  191. END;
  192.  
  193.  
  194.  
  195. BEGIN
  196.  
  197.   { introduce ourselves... }
  198.  
  199.   Writeln( 'MCursor V1.1 From OSS' );
  200.   Writeln( 'Public Domain -- Free to all!' );
  201.   Writeln( 'Mouse Cursor Active...' );
  202.  
  203.   SetCurs;                 { set mouse cursor-mode. }
  204.   RetCode := RunProg;      { run program, copying command line args to it }
  205.   SetMous;                 { set mouse mouse-mode }
  206.   Writeln( 'Mouse is Mouse...' );
  207.   Pterm( RetCode );        { return value to manager }
  208.  
  209. END.
  210.