Initial commit

This commit is contained in:
diegocr
2010-07-27 16:58:17 +00:00
commit 27365e3686
329 changed files with 16486 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
[Dolphin]
AdditionalInfo=39
SortOrder=1
Sorting=2
Timestamp=2010,7,3,23,6,33
ViewMode=1
+5
View File
@@ -0,0 +1,5 @@
#include <exec/types.h>
ULONG _MSTEP=16384;
/* suggestion of Gerhard Müller to be more SAS alike */
+10
View File
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void abort(void)
{
raise(SIGABRT);
fputs("Program aborted\n",stderr);
exit(20);
}
+2
View File
@@ -0,0 +1,2 @@
int abs(int j)
{ return j>=0?j:-j; }
+35
View File
@@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "stabs.h"
struct atexitnode
{
struct atexitnode *next;
void (*func)(void);
};
static struct atexitnode *__funclist=NULL; /* List of functions to call at exit */
int atexit(void (*func)(void))
{
struct atexitnode *node;
if((node=(struct atexitnode *)malloc(sizeof(struct atexitnode)))==NULL)
{ errno=ENOMEM;
return -1; }
else
{ node->next=__funclist;
node->func=func;
__funclist=node;
return 0; }
}
void __exitatexit(void)
{
struct atexitnode *thisf=__funclist;
while(thisf!=NULL)
{ (*thisf->func)();
thisf=thisf->next; }
}
ADD2EXIT(__exitatexit,0);
+5
View File
@@ -0,0 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
int atoi(const char *nptr)
{ return strtol(nptr,NULL,10); }
+5
View File
@@ -0,0 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
long atol(const char *nptr)
{ return strtol(nptr,NULL,10); }
+27
View File
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
/* sample compar function: int cmp(void *a,void *b){ return *(int *)a-*(int *)b; } */
void *bsearch
(const void *key,const void *base,size_t nmemb,size_t size,
int (*compar)(const void *,const void *))
{ char *base2=(char *)base;
size_t a=0;
size_t b=nmemb;
size_t c;
int d;
if(nmemb!=0)
for(;;)
{ c=(a+b)/2;
if((d=(*compar)(key,&base2[size*c]))==0)
return &base2[size*c];
if(c==a)
break;
if(d<0)
b=c;
else
a=c;
}
return NULL;
}
+43
View File
@@ -0,0 +1,43 @@
#if 0
/* $NetBSD: bswap16.c,v 1.3 2003/12/04 13:57:31 keihan Exp $ */
/*
* Written by Manuel Bouyer <bouyer@NetBSD.org>.
* Public domain.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: bswap16.c,v 1.3 2003/12/04 13:57:31 keihan Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#if 0
#include <machine/bswap.h>
#undef bswap16
u_int16_t
bswap16(x)
u_int16_t x;
{
return ((x << 8) & 0xff00) | ((x >> 8) & 0x00ff);
}
#else
#undef bswap16
u_int16_t bswap16(u_int16_t var)
{
__asm__ __volatile ("rorw #8, %0" : "=d" (var) : "0" (var));
return (var);
}
#endif
#else
asm("\n\
.text; .even; .globl _bswap16 ; .type _bswap16 ,@function; _bswap16 :\n\
movl %sp@(4),%d0\n\
rolw #8,%d0\n\
rts\n\
");
#endif
+48
View File
@@ -0,0 +1,48 @@
#if 0
/* $NetBSD: bswap32.c,v 1.3 2003/12/04 13:57:31 keihan Exp $ */
/*
* Written by Manuel Bouyer <bouyer@NetBSD.org>.
* Public domain.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: bswap32.c,v 1.3 2003/12/04 13:57:31 keihan Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#if 0
#include <machine/bswap.h>
#undef bswap32
u_int32_t
bswap32(x)
u_int32_t x;
{
return ((x << 24) & 0xff000000 ) |
((x << 8) & 0x00ff0000 ) |
((x >> 8) & 0x0000ff00 ) |
((x >> 24) & 0x000000ff );
}
#else
#undef bswap32
u_int32_t bswap32(u_int32_t var)
{
__asm__ __volatile (
"rorw #8, %0; swap %0; rorw #8, %0" : "=d" (var) : "0" (var));
return (var);
}
#endif
#else
asm("\n\
.text; .even; .globl _bswap32 ; .type _bswap32 ,@function; _bswap32 :\n\
movl %sp@(4),%d0\n\
rolw #8,%d0\n\
swap %d0\n\
rolw #8,%d0\n\
rts\n\
");
#endif
+69
View File
@@ -0,0 +1,69 @@
#if 0
/* $NetBSD: bswap64.c,v 1.5 2003/12/04 13:57:31 keihan Exp $ */
/*
* Written by Manuel Bouyer <bouyer@NetBSD.org>.
* Public domain.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: bswap64.c,v 1.5 2003/12/04 13:57:31 keihan Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <machine/bswap.h>
#undef bswap64
#ifndef bswap32
static __inline__ u_int32_t bswap32(u_int32_t var)
{
__asm__ __volatile (
"rorw #8, %0; swap %0; rorw #8, %0" : "=d" (var) : "0" (var));
return (var);
}
#endif
u_int64_t
bswap64(x)
u_int64_t x;
{
#ifdef _LP64
/*
* Assume we have wide enough registers to do it without touching
* memory.
*/
return ( (x << 56) & 0xff00000000000000UL ) |
( (x << 40) & 0x00ff000000000000UL ) |
( (x << 24) & 0x0000ff0000000000UL ) |
( (x << 8) & 0x000000ff00000000UL ) |
( (x >> 8) & 0x00000000ff000000UL ) |
( (x >> 24) & 0x0000000000ff0000UL ) |
( (x >> 40) & 0x000000000000ff00UL ) |
( (x >> 56) & 0x00000000000000ffUL );
#else
/*
* Split the operation in two 32bit steps.
*/
u_int32_t tl, th;
th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL));
tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL));
return ((u_int64_t)th << 32) | tl;
#endif
}
#else
asm("\n\
.text; .even; .globl _bswap64 ; .type _bswap64 ,@function; _bswap64 :\n\
movl %sp@(4),%d1\n\
movl %sp@(8),%d0\n\
rolw #8,%d1\n\
rolw #8,%d0\n\
swap %d1\n\
swap %d0\n\
rolw #8,%d0\n\
rolw #8,%d1\n\
rts\n\
");
#endif
+17
View File
@@ -0,0 +1,17 @@
#include <stdlib.h>
void *calloc(size_t nmemb,size_t size)
{
size_t l;
size_t *a;
void *b;
l=(nmemb*size+(sizeof(size_t)-1))&~(sizeof(size_t)-1);
a=(size_t *)(b=malloc(l));
if(b!=NULL)
{
do
*a++=0;
while((l-=sizeof(size_t))!=0);
}
return b;
}
+30
View File
@@ -0,0 +1,30 @@
#ifndef SMALL_DATA
#define A4(x) #x
#elif defined(mc68020)
#define A4(x) "a4@(" #x ":L)"
#else
#define A4(x) "a4@(" #x ":W)"
#endif
asm(
" .globl _div;"
" .globl _ldiv;"
" .globl ___modsi3;"
" .globl ___divsi3;"
/* D1.L = D0.L % D1.L signed */
"___modsi3: moveml sp@(4:W),d0/d1;"
" jbsr ___divsi4;"
" movel d1,d0;"
" rts;"
/* D0.L = D0.L / D1.L signed */
"_div:"
"_ldiv:"
"___divsi3: moveml sp@(4:W),d0/d1;"
"___divsi4: movel "A4(_UtilityBase)",a0;"
" jmp a0@(-150:W);"
);
+28
View File
@@ -0,0 +1,28 @@
#include <stdlib.h>
#include <dos/dos.h>
#include <dos/var.h>
#include <proto/dos.h>
char *getenv(const char *name)
{ static char *var=NULL;
size_t len,i=0;
do
{ i+=64;
if(var!=NULL) /* free old buffer */
free(var);
var=malloc(i); /* and get a new one */
if(var==NULL) /* Oh, dear */
return NULL;
len=GetVar((char *)name,var,i,GVF_BINARY_VAR)+1;
}while(len>=i); /* just to be sure we got everything, we _require_ 1 unused byte */
if(len!=0) /* Variable does exist */
return var;
if((name[0]=='H'||name[0]=='h')
&& (name[1]=='O'||name[1]=='o')
&& (name[2]=='M'||name[2]=='m')
&& (name[3]=='E'||name[3]=='e') && !name[4])
{
return("SYS:Prefs/Env-Archive");
}
return NULL;
}
+2
View File
@@ -0,0 +1,2 @@
long labs(long j)
{ return j>=0?j:-j; }
+182
View File
@@ -0,0 +1,182 @@
/* 10-Apr-94 bug fix M. Fleischer
* 11-Apr-94 bug fix & readjustment G. Nikl
* 14-Apr-94 readjustment M. Fleischer
* 24-Apr-94 cleanup for malloc changed
*/
#include <stdlib.h>
#include <stdio.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/alib.h>
#include "stabs.h"
#include "debuglib.h"
extern ULONG _MSTEP;
static struct MinList __memorylist;
#define USE_SEMAPHORE 0
#if USE_SEMAPHORE
static struct SignalSemaphore *__memsema;
#endif
void *malloc(size_t size)
{
register struct MinNode *node;
struct MemHeader *b;
ULONG size2/*,f*/,*a = NULL;
if((signed)size < 1) {
PrintFault(ERROR_OBJECT_TOO_LARGE,"malloc");
abort();
}
#if USE_SEMAPHORE
ObtainSemaphore(__memsema);
#endif
node=__memorylist.mlh_Head;
size+=sizeof(ULONG);
while(node->mln_Succ) /* yet some memory in my list ? */
{
if((a=Allocate((struct MemHeader *)node,size))!=NULL)
{
*a++=size;
#if USE_SEMAPHORE
goto end;
#else
return a;
#endif
}
node=node->mln_Succ;
}
size2=sizeof(struct MemHeader)+sizeof(ULONG)+size; /* Total memory needed */
if(size2<_MSTEP)
{ size2=_MSTEP; /* Allocate a _MSTEP bytes large block if possible */
//f=MEMF_PUBLIC|MEMF_CLEAR;
} //else { f=MEMF_PUBLIC;}
size2=(size2+4095)&~4095; /* Blow up to full MMU Page */
if((b=(struct MemHeader *)AllocMem(size2,MEMF_ANY))!=NULL)
{
b->mh_Lower=b->mh_First=(struct MemChunk *)(b+1);
b->mh_First->mc_Next=NULL;
b->mh_Free=b->mh_First->mc_Bytes=size2-sizeof(struct MemHeader);
b->mh_Upper=(char *)b+size2;
AddHead((struct List *)&__memorylist,&b->mh_Node);
a=Allocate(b,size); /* It has to work this time */
if (a != NULL) {
*a++=size;
}
}
#if USE_SEMAPHORE
end:
ReleaseSemaphore(__memsema);
#endif
return a;
}
void free(void *ptr)
{ struct MemHeader *a;
if(!ptr) /* What does that mean ????? */
{ DB( BUG("NULL pointer free'd\n"); )
return; }
#if USE_SEMAPHORE
ObtainSemaphore(__memsema);
#endif
a=(struct MemHeader *)__memorylist.mlh_Head;
for(;;)
{
if(((struct MinNode *)a)->mln_Succ==NULL) /* Is not in list ????? */
{ DB( BUG("Fake memory free'd\n"); )
return; }
if(ptr>=a->mh_Lower&&ptr<a->mh_Upper) /* Entry found */
break;
a=(struct MemHeader *)((struct MinNode *)a)->mln_Succ;
}
DB( memset(ptr,0xcc,((ULONG *)ptr)[-1]); ) /* Destroy contents */
Deallocate(a,(ULONG *)ptr-1,((ULONG *)ptr)[-1]);
if(a->mh_Free==(char *)a->mh_Upper-(char *)a->mh_Lower) /* All free ? */
{ Remove(&a->mh_Node);
FreeMem(a,(char *)a->mh_Upper-(char *)a);
}
#if USE_SEMAPHORE
ReleaseSemaphore(__memsema);
#endif
}
extern char __dosname[];
extern char *__procname;
void __initmalloc(void)
{
struct Library *DOSBase = OpenLibrary(__dosname, 0);
NewList((struct List *)&__memorylist);
#if USE_SEMAPHORE
__memsema = AllocMem(sizeof(struct SignalSemaphore), MEMF_PUBLIC | MEMF_CLEAR);
if(!__memsema)exit(1234);
InitSemaphore(__memsema);
#endif
if(__procname[0]=='B'&&__procname[10]==' ')
{
struct Task *ThisTask;
struct Process *ThisProcess;
char *name=NULL;
ThisProcess = (struct Process *)(ThisTask = FindTask(NULL));
if((ThisTask->tc_Node.ln_Succ &&
(ThisTask->tc_Node.ln_Type==NT_PROCESS||
ThisTask->tc_Node.ln_Type==NT_TASK)))
{
if(ThisTask->tc_Node.ln_Type==NT_PROCESS && ThisProcess->pr_CLI)
{
struct CommandLineInterface *cli =
(struct CommandLineInterface *)BADDR(ThisProcess->pr_CLI);
if( cli && cli->cli_Module && cli->cli_CommandName )
{
char *taskname = (char *)(cli->cli_CommandName<<2);
int tnl = *taskname++;
if( tnl > 0 )
{
name = taskname;
}
}
}
if(!(name && *name))
name = ThisTask->tc_Node.ln_Name;
}
if(name && *name > 31)
name = FilePart(name);
if(name&&*name)
__procname=name;
}
CloseLibrary(DOSBase);
DOSBase = NULL;
}
void __exitmalloc(void)
{ struct MemHeader *a;
while((a=(struct MemHeader *)RemHead((struct List *)&__memorylist))!=NULL)
FreeMem(a,(char *)a->mh_Upper-(char *)a); /* free all memory */
#if USE_SEMAPHORE
FreeMem(__memsema, sizeof(struct SignalSemaphore));
#endif
}
ADD2EXIT(__exitmalloc,-50);
ADD2INIT(__initmalloc,-50);
+38
View File
@@ -0,0 +1,38 @@
#include <stdlib.h>
#include <string.h>
#include <dos/var.h>
#include <proto/dos.h>
int setenv(const char *name, const char *value, int overwrite) {
char *old = getenv(name);
int retval = 0;
if (old == NULL || overwrite) {
retval = SetVar(name, value, strlen(value), GVF_LOCAL_ONLY) == TRUE ? 0 : -1;
}
return retval;
}
void unsetenv(const char *name) {
DeleteVar(name, GVF_LOCAL_ONLY);
}
int putenv(const char *str) {
char *tmp = malloc(strlen(str) + 1);
int retval = -1;
char *pos;
if (tmp == NULL) {
goto end;
}
strcpy(tmp, str);
pos = strchr(tmp, '=');
if (pos == NULL)
goto end;
*pos++ = '\0';
retval = setenv(str, pos, 1);
end:
if (tmp != NULL)
free(tmp);
return retval;
}
+51
View File
@@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
/* sample compar function: int cmp(void *a,void *b){ return *(int *)a-*(int *)b; } */
/* This qsort function does a little trick:
* To reduce stackspace it iterates the larger interval instead of doing
* the recursion on both intervals.
* So stackspace is limited to 32*stack_for_1_iteration =
* 32*4*(4 arguments+1 returnaddress+11 stored registers) = 2048 Bytes,
* which is small enough for everybodys use.
* (And this is the worst case if you own 4GB and sort an array of chars.)
* Sparing the function calling overhead does improve performance, too.
*/
void qsort
(void *base,size_t nmemb,size_t size,int (*compar)(const void *,const void *))
{ char *base2=(char *)base;
size_t i,a,b,c;
while(nmemb>1)
{ a=0;
b=nmemb-1;
c=(a+b)/2; /* Middle element */
for(;;)
{ while((*compar)(&base2[size*c],&base2[size*a])>0)
a++; /* Look for one >= middle */
while((*compar)(&base2[size*c],&base2[size*b])<0)
b--; /* Look for one <= middle */
if(a>=b)
break; /* We found no pair */
for(i=0;i<size;i++) /* swap them */
{ char tmp=base2[size*a+i];
base2[size*a+i]=base2[size*b+i];
base2[size*b+i]=tmp; }
if(c==a) /* Keep track of middle element */
c=b;
else if(c==b)
c=a;
a++; /* These two are already sorted */
b--;
} /* a points to first element of right intervall now (b to last of left) */
b++;
if(b<nmemb-b) /* do recursion on smaller intervall and iteration on larger one */
{ qsort(base2,b,size,compar);
base2=&base2[size*b];
nmemb=nmemb-b; }
else
{ qsort(&base2[size*b],nmemb-b,size,compar);
nmemb=b; }
}
}
+9
View File
@@ -0,0 +1,9 @@
#include <stdlib.h>
static unsigned int a=1;
int rand(void)
{ return (a=a*1103515245+12345)%RAND_MAX; }
void srand(unsigned int seed)
{ a=seed; }
+24
View File
@@ -0,0 +1,24 @@
#include <stdlib.h>
#include <proto/exec.h>
#include <string.h>
void *realloc(void *ptr,size_t size)
{
void *a;
size_t l;
if(size)
a=malloc(size);
else
a=NULL;
if(ptr!=NULL)
{ if(a!=NULL)
{ l=((ULONG *)ptr)[-1]-sizeof(ULONG);
l=l<size?l:size;
// CopyMem(ptr,a,l);
bcopy(ptr,a,l);
}
if(size==0||a!=NULL)
free(ptr);
}
return a;
}
+37
View File
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
signed long strtol(const char *nptr,char **endptr,int base)
{ const char *p=nptr;
char *q;
unsigned long r;
if(!(nptr && *nptr))
{ errno=EINVAL;
return 0;
}
while(isspace(*p))
p++;
r=strtoul(p,&q,base);
if(endptr!=NULL)
{ if(q==p)
*endptr=(char *)nptr;
else
*endptr=q;
}
if(*p=='-')
{ if((signed long)r>0)
{ errno=ERANGE;
return LONG_MIN; }
else
return r;
}else
{ if((signed long)r<0)
{ errno=ERANGE;
return LONG_MAX; }
else
return r;
}
}
+59
View File
@@ -0,0 +1,59 @@
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
unsigned long strtoul(const char *nptr,char **endptr,int base)
{ const char *p=nptr,*q;
char c=0;
unsigned long r=0;
if(base<0||base==1||base>36)
{ if(endptr!=NULL)
*endptr=(char *)nptr;
return 0;
}
if(!(nptr && *nptr))
{ errno=EINVAL;
return 0;
}
while(isspace(*p))
p++;
if(*p=='-'||*p=='+')
c=*p++;
if(base==0)
{ if(p[0]=='0')
{ if(tolower(p[1])=='x'&&isxdigit(p[2]))
{ p+=2;
base=16; }
else
base=8;
}else
base=10;
}
q=p;
for(;;)
{ int a;
if(!isalnum(*q))
break;
a=isdigit(*q)?*q-'0':tolower(*q)-('a'-10);
if(a>=base)
break;
if(r>(ULONG_MAX-a)/base||r*base>ULONG_MAX-a)
{ errno=ERANGE; /* overflow */
r=ULONG_MAX; }
else
r=r*base+a;
q++;
}
if(q==p) /* Not a single number read */
{ if(endptr!=NULL)
*endptr=(char *)nptr;
return 0;
}
if(c=='-')
r=-r;
if(endptr!=NULL)
*endptr=(char *)q;
return r;
}
+12
View File
@@ -0,0 +1,12 @@
#include <dos/dos.h>
#include <utility/tagitem.h>
#include <proto/dos.h>
int system(const char *string)
{ static struct TagItem notags[]={ { TAG_END,0 } };
if(!string)
return 1;
else
return SystemTagList((char *)string,notags);
}