summaryrefslogtreecommitdiff
path: root/frontends/amiga/os3support.c
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2016-11-19 21:40:32 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2016-11-19 21:40:32 +0000
commit05fa29ba8bc2dbfaa9af7ed1263554c7cdc9214d (patch)
tree4dfcf8af6868400d5464e61cd625609f1cf5001a /frontends/amiga/os3support.c
parent4f0c9b6c610d1eb9a5bcccf6dbf3f53410df9432 (diff)
downloadnetsurf-05fa29ba8bc2dbfaa9af7ed1263554c7cdc9214d.tar.gz
netsurf-05fa29ba8bc2dbfaa9af7ed1263554c7cdc9214d.tar.bz2
more allocvec/malloc changes
Diffstat (limited to 'frontends/amiga/os3support.c')
-rw-r--r--frontends/amiga/os3support.c317
1 files changed, 158 insertions, 159 deletions
diff --git a/frontends/amiga/os3support.c b/frontends/amiga/os3support.c
index bdf633316..c08260209 100644
--- a/frontends/amiga/os3support.c
+++ b/frontends/amiga/os3support.c
@@ -46,6 +46,155 @@
#define FAILURE (FALSE)
#define NO !
+/* Utility */
+struct FormatContext
+{
+ STRPTR Index;
+ LONG Size;
+ BOOL Overflow;
+};
+
+STATIC VOID ASM
+StuffChar(
+ REG(a3, struct FormatContext * Context),
+ REG(d0, UBYTE Char))
+{
+ /* Is there still room? */
+ if(Context->Size > 0)
+ {
+ (*Context->Index) = Char;
+
+ Context->Index++;
+ Context->Size--;
+
+ /* Is there only a single character left? */
+ if(Context->Size == 1)
+ {
+ /* Provide null-termination. */
+ (*Context->Index) = '\0';
+
+ /* Don't store any further characters. */
+ Context->Size = 0;
+ }
+ }
+ else
+ {
+ Context->Overflow = TRUE;
+ }
+}
+
+BOOL
+VSPrintfN(
+ LONG MaxLen,
+ STRPTR Buffer,
+ const STRPTR FormatString,
+ const va_list VarArgs)
+{
+ BOOL result = FAILURE;
+
+ /* format a text, but place only up to MaxLen
+ * characters in the output buffer (including
+ * the terminating NUL)
+ */
+
+ if (Buffer == NULL || FormatString == NULL) return(result);
+
+ if(MaxLen > 1)
+ {
+ struct FormatContext Context;
+
+ Context.Index = Buffer;
+ Context.Size = MaxLen;
+ Context.Overflow = FALSE;
+
+ RawDoFmt(FormatString,(APTR)VarArgs,(VOID (*)())StuffChar,(APTR)&Context);
+
+ if(NO Context.Overflow)
+ result = SUCCESS;
+ }
+
+ return(result);
+}
+
+BOOL
+SPrintfN(
+ LONG MaxLen,
+ STRPTR Buffer,
+ const STRPTR FormatString,
+ ...)
+{
+ va_list VarArgs;
+ BOOL result = FAILURE;
+
+ /* format a text, varargs version */
+
+ if (Buffer == NULL && FormatString == NULL) return result;
+
+ va_start(VarArgs,FormatString);
+ result = VSPrintfN(MaxLen,Buffer,FormatString,VarArgs);
+ va_end(VarArgs);
+
+ return(result);
+}
+
+char *ASPrintf(const char *fmt, ...)
+{
+ int r;
+ va_list ap;
+ static char buffer[2048];
+ char *rbuf;
+
+ va_start(ap, fmt);
+ r = VSPrintfN(2048, buffer, (const STRPTR)fmt, ap);
+ va_end(ap);
+
+ r = strlen(buffer);
+ rbuf = AllocVec(r+1, MEMF_CLEAR);
+ if (rbuf != NULL)
+ {
+ strncpy(rbuf, buffer, r);
+ }
+ return rbuf;
+}
+
+/* C */
+char *strlwr(char *str)
+{
+ size_t i;
+ size_t len = strlen(str);
+
+ for(i=0; i<len; i++)
+ str[i] = tolower((unsigned char)str[i]);
+
+ return str;
+}
+
+char *strsep(char **s1, const char *s2)
+{
+ char *const p1 = *s1;
+
+ if (p1 != NULL) {
+ *s1 = strpbrk(p1, s2);
+ if (*s1 != NULL) {
+ *(*s1)++ = '\0';
+ }
+ }
+ return p1;
+}
+
+int scandir(const char *dir, struct dirent ***namelist,
+ int (*filter)(const struct dirent *),
+ int (*compar)(const struct dirent **, const struct dirent **))
+{
+ /*\todo stub function, needs writing, preferably into clib2 */
+ return 0;
+}
+
+long long int strtoll(const char *nptr, char **endptr, int base)
+{
+ return (long long int)strtol(nptr, endptr, base);
+}
+
/* Diskfont */
struct OutlineFont *OpenOutlineFont(STRPTR fileName, struct List *list, ULONG flags)
{
@@ -99,7 +248,7 @@ struct OutlineFont *OpenOutlineFont(STRPTR fileName, struct List *list, ULONG fl
}
size = GetFileSize(fh);
- buffer = (UBYTE *)AllocVec(size, MEMF_ANY);
+ buffer = (UBYTE *)malloc(size);
if(buffer == NULL) {
LOG("Unable to allocate memory");
Close(fh);
@@ -114,7 +263,7 @@ struct OutlineFont *OpenOutlineFont(STRPTR fileName, struct List *list, ULONG fl
struct TagItem *tag = (struct TagItem *)buffer;
if((tag->ti_Tag != OT_FileIdent) || (tag->ti_Data != (ULONG)size)) {
LOG("Invalid OTAG file");
- FreeVec(buffer);
+ free(buffer);
FreeVec(otagpath);
return NULL;
}
@@ -132,7 +281,7 @@ struct OutlineFont *OpenOutlineFont(STRPTR fileName, struct List *list, ULONG fl
fname = ASPrintf("%s.library", ti->ti_Data);
} else {
LOG("Cannot find OT_Engine tag");
- FreeVec(buffer);
+ free(buffer);
FreeVec(otagpath);
return NULL;
}
@@ -141,7 +290,7 @@ struct OutlineFont *OpenOutlineFont(STRPTR fileName, struct List *list, ULONG fl
if(BulletBase == NULL) {
LOG("Unable to open font engine %s", fname);
- FreeVec(buffer);
+ free(buffer);
FreeVec(fname);
FreeVec(otagpath);
}
@@ -155,7 +304,7 @@ struct OutlineFont *OpenOutlineFont(STRPTR fileName, struct List *list, ULONG fl
OT_OTagList, (ULONG)buffer,
TAG_DONE);
- of = AllocVec(sizeof(struct OutlineFont), MEMF_CLEAR);
+ of = calloc(1, sizeof(struct OutlineFont));
if(of == NULL) return NULL;
of->BulletBase = BulletBase;
@@ -174,8 +323,8 @@ void CloseOutlineFont(struct OutlineFont *of, struct List *list)
CloseLibrary((struct Library *)BulletBase);
FreeVec(of->OTagPath);
- FreeVec(of->olf_OTagList);
- FreeVec(of);
+ free(of->olf_OTagList);
+ free(of);
}
@@ -183,13 +332,13 @@ void CloseOutlineFont(struct OutlineFont *of, struct List *list)
int64 GetFileSize(BPTR fh)
{
int32 size = 0;
- struct FileInfoBlock *fib = AllocVec(sizeof(struct FileInfoBlock), MEMF_ANY);
+ struct FileInfoBlock *fib = malloc(sizeof(struct FileInfoBlock));
if(fib == NULL) return 0;
ExamineFH(fh, fib);
size = fib->fib_Size;
- FreeVec(fib);
+ free(fib);
return (int64)size;
}
@@ -280,155 +429,5 @@ APTR NewObject(struct IClass * classPtr, CONST_STRPTR classID, ULONG tagList, ..
{
return NewObjectA(classPtr, classID, (const struct TagItem *) &tagList);
}
-
-/* Utility */
-struct FormatContext
-{
- STRPTR Index;
- LONG Size;
- BOOL Overflow;
-};
-
-STATIC VOID ASM
-StuffChar(
- REG(a3, struct FormatContext * Context),
- REG(d0, UBYTE Char))
-{
- /* Is there still room? */
- if(Context->Size > 0)
- {
- (*Context->Index) = Char;
-
- Context->Index++;
- Context->Size--;
-
- /* Is there only a single character left? */
- if(Context->Size == 1)
- {
- /* Provide null-termination. */
- (*Context->Index) = '\0';
-
- /* Don't store any further characters. */
- Context->Size = 0;
- }
- }
- else
- {
- Context->Overflow = TRUE;
- }
-}
-
-BOOL
-VSPrintfN(
- LONG MaxLen,
- STRPTR Buffer,
- const STRPTR FormatString,
- const va_list VarArgs)
-{
- BOOL result = FAILURE;
-
- /* format a text, but place only up to MaxLen
- * characters in the output buffer (including
- * the terminating NUL)
- */
-
- if (Buffer == NULL || FormatString == NULL) return(result);
-
- if(MaxLen > 1)
- {
- struct FormatContext Context;
-
- Context.Index = Buffer;
- Context.Size = MaxLen;
- Context.Overflow = FALSE;
-
- RawDoFmt(FormatString,(APTR)VarArgs,(VOID (*)())StuffChar,(APTR)&Context);
-
- if(NO Context.Overflow)
- result = SUCCESS;
- }
-
- return(result);
-}
-
-BOOL
-SPrintfN(
- LONG MaxLen,
- STRPTR Buffer,
- const STRPTR FormatString,
- ...)
-{
- va_list VarArgs;
- BOOL result = FAILURE;
-
- /* format a text, varargs version */
-
- if (Buffer == NULL && FormatString == NULL) return result;
-
- va_start(VarArgs,FormatString);
- result = VSPrintfN(MaxLen,Buffer,FormatString,VarArgs);
- va_end(VarArgs);
-
- return(result);
-}
-
-char *ASPrintf(const char *fmt, ...)
-{
- int r;
- va_list ap;
- static char buffer[2048];
- char *rbuf;
-
- va_start(ap, fmt);
- r = VSPrintfN(2048, buffer, (const STRPTR)fmt, ap);
- va_end(ap);
-
- r = strlen(buffer);
- rbuf = AllocVec(r+1, MEMF_CLEAR);
- if (rbuf != NULL)
- {
- strncpy(rbuf, buffer, r);
- }
- return rbuf;
-}
-
-/* C */
-char *strlwr(char *str)
-{
- size_t i;
- size_t len = strlen(str);
-
- for(i=0; i<len; i++)
- str[i] = tolower((unsigned char)str[i]);
-
- return str;
-}
-
-char *strsep(char **s1, const char *s2)
-{
- char *const p1 = *s1;
-
- if (p1 != NULL) {
- *s1 = strpbrk(p1, s2);
- if (*s1 != NULL) {
- *(*s1)++ = '\0';
- }
- }
- return p1;
-}
-
-int scandir(const char *dir, struct dirent ***namelist,
- int (*filter)(const struct dirent *),
- int (*compar)(const struct dirent **, const struct dirent **))
-{
- /*\todo stub function, needs writing, preferably into clib2 */
- return 0;
-}
-
-long long int strtoll(const char *nptr, char **endptr, int base)
-{
- return (long long int)strtol(nptr, endptr, base);
-}
-
#endif