home *** CD-ROM | disk | FTP | other *** search
- /*-- Rev Header - do NOT edit!
- *
- * Filename : TextClipSupport.c
- * Purpose : Zwei Hilfsroutinen für die Benutzung von Clips
- *
- * Program : -
- * Author : Gerhard Müller
- * Copyright: (c) by Gerhard Müller
- * Creation : Fri Sep 10 00:41:01 1993
- *
- * compile : makefile
- *
- * Compile version : 0.1
- * Ext. Version : 0.1
- *
- * REVISION HISTORY
- *
- * Date Comment
- * ------------------------ -------------------------------------------------
- * Fri Sep 17 00:59:43 1993 Taken from some other source-code, I think it was
- * some of olsens, but I don't remeber exactly
- *
- *
- *
- *-- REV_END --
- */
-
- #include <exec/types.h>
- #include <libraries/iffparse.h>
- #include <dos/dos.h>
- #include <inline/stubs.h>
- #ifdef __OPTIMIZE__
- #include <inline/exec.h>
- #include <inline/dos.h>
- #include <inline/iffparse.h>
- #else
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/iffparse_protos.h>
- #endif
-
- #include "add.h"
-
- /* stellt folgende Funktionen zu verfügung: */
-
- BYTE SaveClip(UBYTE *Buffer,LONG Size);
- LONG LoadClip(UBYTE *Buffer,LONG Size);
-
-
- /* SaveClip(UBYTE *Buffer,LONG Size):
- *
- * Save text data to the clipboard.
- */
-
- BYTE
- SaveClip(UBYTE *Buffer,LONG Size)
- {
- struct IFFHandle *Handle;
- BYTE Success = FALSE;
-
- /* Allocate an IFFHandle... */
-
- if(Handle = AllocIFF())
- {
- /* Make it operate on the clipboard. */
-
- if(Handle -> iff_Stream = (ULONG)OpenClipboard(PRIMARY_CLIP))
- {
- /* Tell iffparse.library that it is to deal
- * with the clipboard, not with an AmigaDOS file.
- */
-
- InitIFFasClip(Handle);
-
- /* Open the handle for writing. */
-
- if(!OpenIFF(Handle,IFFF_WRITE))
- {
- /* Say it's a formatted text form. */
-
- if(!PushChunk(Handle,'FTXT','FORM',IFFSIZE_UNKNOWN))
- {
- /* Create the text chunk. */
-
- if(!PushChunk(Handle,0,'CHRS',Size))
- {
- /* Write the actual data. */
-
- if(WriteChunkBytes(Handle,Buffer,Size) == Size)
- {
- /* Did the chunk get written correctly? */
-
- if(!PopChunk(Handle))
- Success = TRUE;
- }
- }
- }
-
- /* Did our previous actions succeed? */
-
- if(Success)
- {
- /* Did the chunk get written correctly? */
-
- if(PopChunk(Handle))
- Success = FALSE;
- }
-
- /* Close the iff stream. */
-
- CloseIFF(Handle);
- }
-
- /* Flush the data out to the clipboard. */
-
- CloseClipboard((struct ClipboardHandle *)Handle -> iff_Stream);
- }
-
- /* Free the IFFHandle data. */
-
- FreeIFF(Handle);
- }
-
- /* Return whether our actions were successful or not. */
-
- return(Success);
- }
-
- /* LoadClip(UBYTE *Buffer,LONG Size):
- *
- * Fill the buffer with up to `Size' bytes.
- */
-
- LONG
- LoadClip(UBYTE *Buffer,LONG Size)
- {
- struct IFFHandle *Handle;
- LONG Bytes = 0;
-
- /* Allocate an IFFHandle... */
-
- if(Handle = AllocIFF())
- {
- /* Make it operate on the clipboard. */
-
- if(Handle -> iff_Stream = (ULONG)OpenClipboard(PRIMARY_CLIP))
- {
- /* Tell iffparse.library that it is to deal
- * with the clipboard, not with an AmigaDOS file.
- */
-
- InitIFFasClip(Handle);
-
- /* Open the handle for reading. */
-
- if(!OpenIFF(Handle,IFFF_READ))
- {
- /* Tell the parser to stop at the
- * beginning of character data
- * inside formatted text chunks.
- */
-
- if(!StopChunk(Handle,'FTXT','CHRS'))
- {
- /* Start the parser and process
- * the data encountered.
- */
-
- if(!ParseIFF(Handle,IFFPARSE_SCAN))
- {
- struct ContextNode *ContextNode;
-
- /* Determine the current chunk information
- * (we will need it in order to query the
- * size of it).
- */
-
- if(ContextNode = CurrentChunk(Handle))
- {
- LONG BytesRead;
-
- /* Don't read more data
- * than we will be able
- * to handle.
- */
-
- if(Size > ContextNode -> cn_Size)
- Size = ContextNode -> cn_Size;
-
- /* Read as much data as required. */
-
- BytesRead = ReadChunkBytes(Handle,Buffer,Size);
-
- /* If any data was available,
- * remember how much we were
- * able to read.
- */
-
- if(BytesRead > 0)
- Bytes = BytesRead;
- }
- }
- }
-
- /* Close the iff stream. */
-
- CloseIFF(Handle);
- }
-
- /* Free clipboard resources. */
-
- CloseClipboard((struct ClipboardHandle *)Handle -> iff_Stream);
- }
-
- /* Free the IFFHandle data. */
-
- FreeIFF(Handle);
- }
-
- /* Return the number of bytes we were actually able to read. */
-
- return(Bytes);
- }
-