aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-07-27 19:15:59 -0400
committerNathan Vance <nathav63@gmail.com>2015-07-27 19:15:59 -0400
commit06818a49b337ef5d3277ebf6ed0b3f13a88239d3 (patch)
tree500f311c25ac68fc9a3b8429bf0747572e4d3e69 /util.c
parentfixed bugs and formatting errors (diff)
download7w-06818a49b337ef5d3277ebf6ed0b3f13a88239d3.tar.gz
7w-06818a49b337ef5d3277ebf6ed0b3f13a88239d3.tar.bz2
7w-06818a49b337ef5d3277ebf6ed0b3f13a88239d3.zip
Updated to work with gcc 5.X
Diffstat (limited to 'util.c')
-rw-r--r--util.c114
1 files changed, 50 insertions, 64 deletions
diff --git a/util.c b/util.c
index fcb67d2..73a8105 100644
--- a/util.c
+++ b/util.c
@@ -3,82 +3,68 @@
#include <stdlib.h>
#include <time.h>
-static void replace(char a[], char b[], int x, int y);
-
#define POOLSIZE 100000
-static int ipool[POOLSIZE];
-static int *ipoolp = ipool;
-
-int* get_intarray(int size)
-{
- if(ipoolp + size > ipool + POOLSIZE) ipoolp = ipool;
- int* ret = ipoolp;
- ipoolp += size;
- return ret;
-}
static char cpool[POOLSIZE];
static char *cpoolp = cpool;
-char* get_chararray(int size)
-{
- if(cpoolp + size > cpool + POOLSIZE) cpoolp = cpool;
- char* ret = cpoolp;
- cpoolp += size;
- return ret;
-}
-
-void arraycpy(int *from, int *to, int len)
-{
- int i;
- for(i = 0; i < len; i++) to[i] = from[i];
+char* get_chararray(int size) {
+ if (cpoolp + size > cpool + POOLSIZE)
+ cpoolp = cpool;
+ char* ret = cpoolp;
+ cpoolp += size;
+ return ret;
}
/* Concatinates a and b and returns a different
- string. Only use when returned string can be recycled. */
+ string. Only use when returned string can be recycled. */
char* cat(char a[], char b[]) {
- int len = strlen(a) + strlen(b) + 1;
-/* if(len > RET) return "error";
- if(len + retindex > RET) retindex = 0;
- char* p = ret + retindex;
-*/
- char *p = get_chararray(len);
- int i, j;
- i = j = 0;
- while((p[i++] = a[j++]) != '\0');
- i--;
- j = 0;
- while((p[i++] = b[j++]) != '\0');
- return p;
+ int len = strlen(a) + strlen(b) + 1;
+ /* if(len > RET) return "error";
+ if(len + retindex > RET) retindex = 0;
+ char* p = ret + retindex;
+ */
+ char *p = get_chararray(len);
+ int i, j;
+ i = j = 0;
+ while ((p[i++] = a[j++]) != '\0')
+ ;
+ i--;
+ j = 0;
+ while ((p[i++] = b[j++]) != '\0')
+ ;
+ return p;
}
-char* itoa(int i)
-{
- char *num = get_chararray(5);
- int j;
- for(j = 0; j < 5; num[j++] = ' ');
- num[3] = '0';
- int o = 3;
- int negative = 0;
- if(i < 0) {
- negative = 1;
- i *= -1;
- }
- while(o >= 0 && i > 0) {
- num[o--] = i % 10 + '0';
- i /= 10;
- }
- if(o >= 0 && negative) num[o] = '-';
- num[4] = '\0';
- for(i = 0; num[i] == ' '; i++);
- return &num[i];
+char* itoa(int i) {
+ if(i == 0) return "0";
+ char *num = get_chararray(5);
+ int j;
+ for (j = 0; j < 5; num[j++] = ' ')
+ ;
+ num[3] = '0';
+ int o = 3;
+ int negative = 0;
+ if (i < 0) {
+ negative = 1;
+ i *= -1;
+ }
+ while (o >= 0 && i > 0) {
+ num[o--] = i % 10 + '0';
+ i /= 10;
+ }
+ if (o >= 0 && negative)
+ num[o] = '-';
+ num[4] = '\0';
+ for (i = 0; num[i] == ' '; i++)
+ ;
+ return &num[i];
}
//sleep in tenths of a second
-int bettersleep(int ds)
-{
- struct timespec tim, tim2;
- tim.tv_sec = ds/10;
- tim.tv_nsec = (ds%10)*100000000L;
- return nanosleep(&tim , &tim2);
+int bettersleep(int ds) {
+ struct timespec tim, tim2;
+ tim.tv_sec = ds / 10;
+ tim.tv_nsec = (ds % 10) * 100000000L;
+ return nanosleep(&tim, &tim2);
}
bgstack15