home *** CD-ROM | disk | FTP | other *** search
EPOC OPL Source | 1998-08-30 | 2.9 KB | 105 lines |
-
-
- Rem putclip, an addon command for Shell5
- Rem Write to the system clipboard
- Rem
- Rem Copyright (C) 1998 Nick Murray
- Rem This routine was made possible by Cliplib.opl v 1.0
- Rem by Russ Spooner (psion@labrat.demon.co.uk)
- Rem
- Rem This program is free software; you can redistribute it and/or
- Rem modify it under the terms of the GNU General Public License
- Rem as published by the Free Software Foundation; either version 2
- Rem of the License, or (at your option) any later version.
- Rem
- Rem This program is distributed in the hope that it will be useful,
- Rem but WITHOUT ANY WARRANTY; without even the implied warranty of
- Rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Rem See the GNU General Public License for more details.
- Rem
- Rem You should have received a copy of the GNU General Public License
- Rem along with this program; if not, write to the Free Software Foundation,
- Rem Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- Rem
- PROC putclip%:(n%)
- LOCAL h%,Hdr&(4),Ftr&(3),pos&,id%,length&,ret%,txt$(255),dummy%
- Rem dummy is needed in case txt$ overflows with "6"
- ONERR ErrTrap::
- IF n%<2 AND _in%=0
- PRINT "Usage: putclip <filename>"
- RETURN -2
- ENDIF
- IF n%=1 AND _in% Rem only stdin
- h%=_in%
- GOTO Common::
- ENDIF
- ret%=Fparse%:(ADDR(txt$),PEEK$(argv&(2)))
- IF ret%<0
- RAISE ret%
- ELSEIF ret% AND 16 Rem this is a directory
- RAISE 3
- ENDIF
- REM open=$0000, text=$0020, share=$0400
- ret%=IOOPEN(h%,txt$,$0420)
- IF ret%<0
- RAISE ret%
- ENDIF
- Common:: Rem h%=-in% or an open file
-
- Hdr&(1)=&10000037 : Hdr&(2)=&1000003b
- Hdr&(3)=&00000000 : Hdr&(4)=&4739d53b
- Ftr&(1)=&00330200 : Ftr&(2)=&00141000
- Ftr&(3)=&00000000
-
- IOOPEN (id%,"c:\system\data\clpboard.cbd",$302)
- IOWRITE (id%,ADDR(Hdr&(1)),16)
- IOWRITE (id%,ADDR(txt$),8) Rem write junk, will be written later
- WHILE 1
- IOYIELD
- IF _stat%<>-46
- IF _key%(1)=27
- BREAK Rem this should ensure something is written!!
- ELSE
- KEYA(_stat%,_key%())
- ENDIF
- ENDIF
- ret%=IOREAD(h%,ADDR(txt$)+1,255)
- IF ret%<0
- IF ret%<>-36 REM not EOF
- RAISE ret%
- ENDIF
- BREAK
- ENDIF
- POKEB ADDR(txt$),ret%
- POKEB ADDR(txt$)+ret%+1,6 Rem newline
- IOWRITE (id%,ADDR(txt$)+1,ret%+1)
- length&=length&+ret%+1 Rem include newline
- ENDWH
- IF length&>1
- length&=length&-1 Rem supress last newline
- pos&=-1 Rem rewind by 1
- IOSEEK(id%,3,pos&)
- ENDIF
-
- IOWRITE (id%,ADDR(Ftr&(1)),10)
- pos&=16 Rem rewind to write in size
- IOSEEK(id%,1,pos&)
- pos&=&19+length&
- IOWRITE (id%,ADDR(pos&),4)
- IOWRITE (id%,ADDR(length&),4)
- GOTO Cleanup::
- ErrTrap::
- ONERR off
- PRINT err$:(ERR)
- Cleanup::
- IF h% AND h%<>_in%
- IOCLOSE(h%)
- ENDIF
- IF id%
- IOCLOSE(id%)
- ENDIF
- RETURN ERR
- ENDP
-
-
-