Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / clipboard.c
blob25694af88213ad3562be922da8b0e1c8c168cf6d
1 /*
2 Copyright © 1999, David Le Corfec.
3 Copyright © 2002, The AROS Development Team.
4 All rights reserved.
6 $Id$
7 */
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdio.h>
14 #include <exec/types.h>
15 #include <exec/memory.h>
17 #include <clib/alib_protos.h>
18 #include <libraries/iffparse.h>
19 #include <datatypes/textclass.h>
20 #include <proto/exec.h>
21 #include <proto/iffparse.h>
22 #include <proto/utility.h>
24 #include "mui.h"
25 #include "clipboard.h"
26 #include "support.h"
28 #include "muimaster_intern.h"
30 //#define MYDEBUG 1
31 #include "debug.h"
33 extern struct Library *MUIMasterBase;
35 void clipboard_write_text(STRPTR text, LONG textlen)
37 struct IFFHandle *iff;
39 if((iff = AllocIFF()))
41 if((iff->iff_Stream = (IPTR)OpenClipboard(0)))
43 InitIFFasClip(iff);
44 if(!OpenIFF(iff,IFFF_WRITE))
46 if(!PushChunk(iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN))
48 if(!PushChunk(iff, ID_FTXT, ID_CHRS, IFFSIZE_UNKNOWN))
50 WriteChunkBytes(iff, text, textlen);
52 PopChunk(iff);
54 } /* if(!PushChunk(iff, ID_FTXT, ID_CHRS, IFFSIZE_UNKNOWN)) */
55 PopChunk(iff);
57 } /* if(!PushChunk(iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN)) */
58 CloseIFF(iff);
60 } /* if(!OpenIFF(iff,IFFF_WRITE)) */
61 CloseClipboard((struct ClipboardHandle*)iff->iff_Stream);
63 } /* if((iff->iff_Stream = (IPTR)OpenClipboard(clipunit))) */
64 FreeIFF(iff);
66 } /* if((iff = AllocIFF()))) */
70 STRPTR clipboard_read_text(void)
72 struct IFFHandle *iff;
73 struct ContextNode *cn;
74 STRPTR retval = 0;
76 if((iff = AllocIFF()))
78 if((iff->iff_Stream = (IPTR)OpenClipboard(0)))
80 InitIFFasClip(iff);
82 if(!OpenIFF(iff, IFFF_READ))
84 if (!(StopChunk(iff, ID_FTXT, ID_CHRS)))
86 if (!ParseIFF(iff, IFFPARSE_SCAN))
88 cn = CurrentChunk(iff);
90 if ((cn->cn_Type == ID_FTXT) && (cn->cn_ID == ID_CHRS) && (cn->cn_Size > 0))
92 if ((retval = mui_alloc(cn->cn_Size + 1)))
94 ReadChunkBytes(iff, retval, cn->cn_Size);
96 retval[cn->cn_Size] = '\0';
99 } /* if ((cn->cn_Type == ID_FTXT) && (cn->cn_ID == ID_CHRS) && (cn->cn_Size > 0)) */
101 } /* if (!ParseIFF(iff, IFFPARSE_SCAN)) */
103 } /* if (!(StopChunk(iff, ID_FTXT, ID_CHRS))) */
105 CloseIFF(iff);
107 } /* if(!OpenIFF(iff, IFFF_READ)) */
108 CloseClipboard((struct ClipboardHandle*)iff->iff_Stream);
110 } /* if((iff->iff_Stream = (IPTR)OpenClipboard(clipunit))) */
111 FreeIFF(iff);
113 } /* if((iff = AllocIFF()))) */
115 return retval;
118 void clipboard_free_text(STRPTR text)
120 mui_free(text);