home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 283 / Shell5SourceCode.sis / putclip (.txt) < prev    next >
Encoding:
EPOC OPL Source  |  1998-08-30  |  2.9 KB  |  105 lines

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