1 /**********************************************************************
2 text.datatype - (c) 2000 by Sebastian Bauer
4 This module provides some support functions
5 ***********************************************************************/
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <proto/iffparse.h>
16 /* sprintf replacements for SAS C (shorter code, currently not used
17 anywhere in the code) */
19 STATIC VOID
SR_CopyFunc(VOID
)
21 __emit(0x16c0); /* MOVE.B D0,(A3)+ */
24 int sprintf(char *buf
, const char *fmt
,...)
26 RawDoFmt((STRPTR
) fmt
, (STRPTR
*) & fmt
+ 1, (void (*)()) SR_CopyFunc
, buf
);
33 /**************************************************************************************************/
35 struct MinNode
*Node_Next(APTR node
)
37 if(node
== NULL
) return NULL
;
38 if(((struct MinNode
*)node
)->mln_Succ
== NULL
) return NULL
;
39 if(((struct MinNode
*)node
)->mln_Succ
->mln_Succ
== NULL
)
42 return ((struct MinNode
*)node
)->mln_Succ
;
45 /**************************************************************************************************/
47 struct MinNode
*Node_Prev(APTR node
)
49 if(node
== NULL
) return NULL
;
50 if(((struct MinNode
*)node
)->mln_Pred
== NULL
) return NULL
;
51 if(((struct MinNode
*)node
)->mln_Pred
->mln_Pred
== NULL
)
54 return ((struct MinNode
*)node
)->mln_Pred
;
58 /**************************************************************************************************/
60 struct MinNode
*List_First(APTR list
)
62 if( !((struct MinList
*)list
)->mlh_Head
) return NULL
;
63 if(((struct MinList
*)list
)->mlh_Head
->mln_Succ
== NULL
) return NULL
;
65 return ((struct MinList
*)list
)->mlh_Head
;
68 /**************************************************************************************************/
72 struct MinNode
*List_Last(APTR list
)
74 if( !((struct MinList
*)list
)->mlh_TailPred
) return NULL
;
75 if(((struct MinList
*)list
)->mlh_TailPred
->mln_Pred
== NULL
) return NULL
;
77 return ((struct MinList
*)list
)->mlh_TailPred
;
82 /**************************************************************************************************/
86 ULONG
List_Length(APTR list
)
88 struct MinNode
*node
= List_First(list
);
94 node
= Node_Next(node
);
102 /**************************************************************************************************/
106 struct MinNode
*List_Find(APTR list
, ULONG num
)
108 struct MinNode
*node
= List_First(list
);
112 if(!(node
= Node_Next(node
))) break;
121 /**************************************************************************
123 **************************************************************************/
124 STRPTR
StrCopy( const STRPTR str
)
128 if( !str
) return NULL
;
129 if( !*str
) return NULL
;
131 dst
= (STRPTR
)AllocVec(strlen(str
) + 1, 0);
132 if(dst
) strcpy(dst
, str
);
137 /**************************************************************************
138 Returns the size of a file
139 **************************************************************************/
140 LONG
GetFileSize( BPTR fileh
)
142 struct FileInfoBlock
*fib
= (struct FileInfoBlock
*)AllocDosObject( DOS_FIB
, NULL
);
147 if (ExamineFH( fileh
, fib
))
149 if ((fib
->fib_DirEntryType
> 0) && (fib
->fib_DirEntryType
!= ST_SOFTLINK
))
153 size
= fib
->fib_Size
;
155 FreeDosObject( DOS_FIB
, fib
);
161 /**************************************************************************
162 Prepares the clipboard so that text can be written into it
163 **************************************************************************/
164 struct IFFHandle
*PrepareClipboard(void)
166 struct IFFHandle
*iff
= AllocIFF();
170 if((iff
->iff_Stream
= (ULONG
) OpenClipboard (0)))
173 if(!OpenIFF(iff
,IFFF_WRITE
))
175 if(!PushChunk(iff
, MAKE_ID('F','T','X','T'), MAKE_ID('F','O','R','M'), IFFSIZE_UNKNOWN
))
177 if(!PushChunk(iff
, 0, MAKE_ID('C','H','R','S'), IFFSIZE_UNKNOWN
))
185 CloseClipboard((struct ClipboardHandle
*)iff
->iff_Stream
);
193 /**************************************************************************
194 Free all resources allocated in PrepareClipboard
195 **************************************************************************/
196 VOID
FreeClipboard(struct IFFHandle
*iff
)
201 CloseClipboard((struct ClipboardHandle
*)iff
->iff_Stream
);