summaryrefslogtreecommitdiff
path: root/minilib
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2018-06-16 12:34:55 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2018-06-16 12:34:55 +0200
commitab9f793cd6d03baf97ca62afa7c42052cafa5ea4 (patch)
treee888bb259c53cb9e00f166d1d5cc023df753daba /minilib
parent8f5b4a6408d9bc5ea372d9d8d2dcc19834068612 (diff)
downloadcompilertests-ab9f793cd6d03baf97ca62afa7c42052cafa5ea4.tar.gz
compilertests-ab9f793cd6d03baf97ca62afa7c42052cafa5ea4.tar.bz2
no extern for function prototypes in header files (no clue, why I always do that :-) )
added itoa from abaos to minilib
Diffstat (limited to 'minilib')
-rw-r--r--minilib/arena.h4
-rw-r--r--minilib/ctype.h8
-rw-r--r--minilib/hash.h12
-rw-r--r--minilib/io.h8
-rw-r--r--minilib/minilib.h2
-rw-r--r--minilib/stddef.h5
-rw-r--r--minilib/stdlib.c46
-rw-r--r--minilib/stdlib.h4
-rw-r--r--minilib/string.h12
-rw-r--r--minilib/utils.h4
10 files changed, 77 insertions, 28 deletions
diff --git a/minilib/arena.h b/minilib/arena.h
index 3f486e4..d781981 100644
--- a/minilib/arena.h
+++ b/minilib/arena.h
@@ -9,5 +9,5 @@ enum {
ARENA_SIZE = 65535
};
-extern void *allocate( int size );
-extern void deallocate( void **p );
+void *allocate( int size );
+void deallocate( void **p );
diff --git a/minilib/ctype.h b/minilib/ctype.h
index f19fbce..1262a37 100644
--- a/minilib/ctype.h
+++ b/minilib/ctype.h
@@ -1,6 +1,6 @@
#pragma once
-extern int isalpha( int c );
-extern int isdigit( int c );
-extern int isalnum( int c );
-extern int isspace( int c );
+int isalpha( int c );
+int isdigit( int c );
+int isalnum( int c );
+int isspace( int c );
diff --git a/minilib/hash.h b/minilib/hash.h
index 4be951c..1aaf8ed 100644
--- a/minilib/hash.h
+++ b/minilib/hash.h
@@ -18,9 +18,9 @@ typedef struct intHashIterator {
intHashTable *ht;
} intHashIterator;
-extern void inthash_init( intHashTable *ht, int size );
-extern void inthash_done( intHashTable *ht );
-extern void inthash_set( intHashTable *ht, char *key, int value );
-extern int inthash_get( intHashTable *ht, char *key );
-extern intHashEntry *inthash_getfirst( intHashTable *ht, intHashIterator *it );
-extern intHashEntry *inthash_getnext( intHashIterator *it );
+void inthash_init( intHashTable *ht, int size );
+void inthash_done( intHashTable *ht );
+void inthash_set( intHashTable *ht, char *key, int value );
+int inthash_get( intHashTable *ht, char *key );
+intHashEntry *inthash_getfirst( intHashTable *ht, intHashIterator *it );
+intHashEntry *inthash_getnext( intHashIterator *it );
diff --git a/minilib/io.h b/minilib/io.h
index b2c8033..5dac1c3 100644
--- a/minilib/io.h
+++ b/minilib/io.h
@@ -1,6 +1,6 @@
#pragma once
-extern void print( char *s );
-extern int readfile( char *filename, char *s, int size );
-extern int writefile( char *filename, char *s, int size );
-extern char *readallfile( char *filename );
+void print( char *s );
+int readfile( char *filename, char *s, int size );
+int writefile( char *filename, char *s, int size );
+char *readallfile( char *filename );
diff --git a/minilib/minilib.h b/minilib/minilib.h
index 2e9dd3d..b815836 100644
--- a/minilib/minilib.h
+++ b/minilib/minilib.h
@@ -1,3 +1,3 @@
#pragma once
-extern void halt( void );
+void halt( void );
diff --git a/minilib/stddef.h b/minilib/stddef.h
index a288c39..8ee8040 100644
--- a/minilib/stddef.h
+++ b/minilib/stddef.h
@@ -1,9 +1,10 @@
#pragma once
+/* TODO: preprocess just to define the NULL pointer?! */
#define NULL ( (void *) 0)
/* TODO: drawn in by using some functions from the host */
-#define size_t int
+typedef int size_t;
/* TODO: drawn in by using some functions from the host */
-#define wchar_t int
+typedef int wchar_t;
diff --git a/minilib/stdlib.c b/minilib/stdlib.c
index 96b9b58..53ae0df 100644
--- a/minilib/stdlib.c
+++ b/minilib/stdlib.c
@@ -1,4 +1,50 @@
#include "stdlib.h"
+#include "stdbool.h"
+#include "string.h"
+#include "stddef.h"
+
+static void strreverse( char *s )
+{
+ char *end = s + strlen( s ) - 1;
+
+ while( s < end ) {
+ // XOR swap;
+ *s ^= *end;
+ *end ^= *s;
+ *s ^= *end;
+ s++;
+ end--;
+ }
+}
+
+char *itoa( int v, char *s, int base )
+{
+ static char digit[] = "0123456789ABCDEF";
+ bool sign = false;
+ char *p = s;
+
+ if( base < 2 || base > 16 ) {
+ return NULL;
+ }
+
+ if( v < 0 ) {
+ v = -v;
+ sign = true;
+ }
+
+ do {
+ *p++ = digit[v % base];
+ } while( ( v /= base ) > 0 );
+
+ if( sign ) {
+ *p++ = '-';
+ }
+ *p = '\0';
+
+ strreverse( s );
+
+ return s;
+}
/* TODO: this is the Linux hosted environment */
#define _GNU_SOURCE
diff --git a/minilib/stdlib.h b/minilib/stdlib.h
index 4300381..67335f7 100644
--- a/minilib/stdlib.h
+++ b/minilib/stdlib.h
@@ -1,3 +1,5 @@
#pragma once
-extern void exit( int status );
+char *itoa( int v, char *s, int base );
+
+void exit( int status );
diff --git a/minilib/string.h b/minilib/string.h
index 60cd785..79f903a 100644
--- a/minilib/string.h
+++ b/minilib/string.h
@@ -1,8 +1,8 @@
#pragma once
-extern char *memset( void *p, int c, int n );
-extern char *strcat( char *d, char *s );
-extern char *strcpy( char *d, char *s );
-extern int strlen( char *s );
-extern int strcmp( char *s1, char *s2 );
-extern char *strdup( char *s );
+char *memset( void *p, int c, int n );
+char *strcat( char *d, char *s );
+char *strcpy( char *d, char *s );
+int strlen( char *s );
+int strcmp( char *s1, char *s2 );
+char *strdup( char *s );
diff --git a/minilib/utils.h b/minilib/utils.h
index 1ab26de..068eaea 100644
--- a/minilib/utils.h
+++ b/minilib/utils.h
@@ -1,4 +1,4 @@
#pragma once
-extern void strtohex( char *p, int len, char *s );
-extern void inttohex( int i, char *s );
+void strtohex( char *p, int len, char *s );
+void inttohex( int i, char *s );