home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 283 / Shell5SourceCode.sis / putclip.txt < prev    next >
Encoding:
Text File  |  1998-08-30  |  2.8 KB  |  100 lines

  1. Rem   putclip, an addon command for Shell5
  2. Rem   Write to the system clipboard
  3. Rem
  4. Rem   Copyright (C) 1998  Nick Murray
  5. Rem   This routine was made possible by Cliplib.opl v 1.0
  6. Rem    by Russ Spooner (psion@labrat.demon.co.uk)
  7. Rem
  8. Rem   This program is free software; you can redistribute it and/or
  9. Rem   modify it under the terms of the GNU General Public License
  10. Rem   as published by the Free Software Foundation; either version 2
  11. Rem   of the License, or (at your option) any later version.
  12. Rem
  13. Rem   This program is distributed in the hope that it will be useful,
  14. Rem   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. Rem   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. Rem   See the GNU General Public License for more details.
  17. Rem
  18. Rem   You should have received a copy of the GNU General Public License
  19. Rem   along with this program; if not, write to the Free Software Foundation,
  20. Rem   Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21. Rem
  22. PROC putclip%:(n%)
  23. LOCAL h%,Hdr&(4),Ftr&(3),pos&,id%,length&,ret%,txt$(255),dummy%
  24. Rem dummy is needed in case txt$ overflows with "6"
  25.     ONERR ErrTrap::
  26.     IF n%<2 AND _in%=0
  27.         PRINT "Usage: putclip <filename>"
  28.         RETURN -2
  29.     ENDIF
  30.     IF n%=1 AND _in%    Rem only stdin
  31.         h%=_in%
  32.         GOTO Common::
  33.     ENDIF
  34.     ret%=Fparse%:(ADDR(txt$),PEEK$(argv&(2)))
  35.         IF ret%<0
  36.             RAISE ret%
  37.         ELSEIF ret% AND 16    Rem this is a directory
  38.             RAISE 3
  39.         ENDIF
  40.         REM open=$0000, text=$0020, share=$0400
  41.         ret%=IOOPEN(h%,txt$,$0420)
  42.         IF ret%<0
  43.             RAISE ret%
  44.         ENDIF
  45. Common::        Rem h%=-in% or an open file
  46.  
  47.     Hdr&(1)=&10000037    :    Hdr&(2)=&1000003b
  48.     Hdr&(3)=&00000000    :    Hdr&(4)=&4739d53b
  49.     Ftr&(1)=&00330200    :    Ftr&(2)=&00141000
  50.     Ftr&(3)=&00000000
  51.  
  52.     IOOPEN (id%,"c:\system\data\clpboard.cbd",$302)
  53.     IOWRITE (id%,ADDR(Hdr&(1)),16)
  54.     IOWRITE (id%,ADDR(txt$),8)        Rem write junk, will be written later
  55.     WHILE 1
  56.         IOYIELD
  57.         IF _stat%<>-46
  58.             IF _key%(1)=27
  59.                 BREAK                    Rem this should ensure something is written!!
  60.             ELSE
  61.                 KEYA(_stat%,_key%())
  62.             ENDIF
  63.         ENDIF
  64.         ret%=IOREAD(h%,ADDR(txt$)+1,255)
  65.         IF ret%<0
  66.             IF ret%<>-36                REM not EOF
  67.                 RAISE ret%
  68.             ENDIF
  69.             BREAK
  70.         ENDIF
  71.         POKEB ADDR(txt$),ret%
  72.         POKEB ADDR(txt$)+ret%+1,6            Rem newline
  73.         IOWRITE (id%,ADDR(txt$)+1,ret%+1)
  74.         length&=length&+ret%+1                        Rem include newline
  75.     ENDWH
  76.     IF length&>1
  77.         length&=length&-1                                            Rem supress last newline
  78.         pos&=-1                                                                Rem rewind by 1
  79.         IOSEEK(id%,3,pos&)
  80.     ENDIF
  81.  
  82.     IOWRITE (id%,ADDR(Ftr&(1)),10)
  83.     pos&=16                                                            Rem rewind to write in size
  84.     IOSEEK(id%,1,pos&)
  85.     pos&=&19+length&
  86.     IOWRITE (id%,ADDR(pos&),4)
  87.     IOWRITE (id%,ADDR(length&),4)
  88.     GOTO Cleanup::    
  89. ErrTrap::
  90.     ONERR off
  91.     PRINT err$:(ERR)
  92. Cleanup::
  93.     IF h% AND h%<>_in%
  94.         IOCLOSE(h%)
  95.     ENDIF
  96.     IF id%
  97.         IOCLOSE(id%)
  98.     ENDIF
  99.     RETURN ERR
  100. ENDP