Kevin Veroneau avatar Kevin Veroneau committed 434107e Draft

Initial import of code.

Comments (0)

Files changed (7)

compile-example.sh

+#!/bin/sh
+
+echo "Compiling static example binary..."
+gcc example.c -L. -lamos -o example_static -lm
+echo "Testing..."
+./example_static
+echo "Compiling dynamic example binary..."
+gcc -o example_dynamic example.c libamos.so.1
+echo "Testing..."
+export LD_LIBRARY_PATH=.
+./example_dynamic
+ldd example_dynamic
+#!/bin/sh
+
+echo "Compiling static library..."
+gcc -c membank.c -o membank.o
+gcc -c strings.c -o strings.o -lm
+gcc -c math.c -o math.o -lm
+#gcc -c file.c -o file.o
+ar rcs libamos.a membank.o strings.o math.o
+ranlib libamos.a
+echo "Building shared library..."
+#gcc -c -fPIC libamos.c -o libamos.o
+gcc -shared -Wl,-soname,libamos.so.1 -o libamos.so.1 membank.o strings.o math.o -lm
+./compile-example.sh
+#include <stdio.h>
+#include "libamos.h"
+
+
+int main(int argc, char* argv[]){
+	if(loadbank("test.bnk",1)==-1){
+		printf("Error description: %s\n", error_description);
+		return 0;
+	}
+	printf("Bank size: %d\n",sizebank(1));
+	freebank(1);
+	printf("A=%d\n",asc("A"));
+	randomize(-1);
+	printf("Random number: %f\n",rnd(100));
+	return 0;
+}
+//-- membank ---------------------------------------------------------------------------------------
+#define NUM_MEMBANKS 255
+
+extern char *membank[NUM_MEMBANKS];
+extern int banksize[NUM_MEMBANKS];
+extern int curbank;
+
+/*----- Error system ---*/
+char *error_description;
+int error_type;
+
+//--Internal ---------------------------------------------------
+extern void init_membank();
+
+//--Base ---------------------------------------------------
+extern int reservebank(int bank,int size);
+extern int baseimage(int bank,int n);
+extern int baseimageCC(int bank,int n);
+extern int basescreen(int bank,int n);
+extern int basesound(int bank,int n);
+
+extern int freebase(int bank);
+extern int freebank(int bank);
+extern int copybank(int s,int d);
+extern int loadbank(char *filename,int bank);
+extern int savebank(char *filename,int bank);
+
+extern int setbank(int bank);
+extern int sizebank(int bank);
+
+//--poke ---------------------------------------------------
+extern int poke(int bank,int address,unsigned char byte);
+extern int doke(int bank,int address,unsigned short byte);
+extern int loke(int bank,int address,unsigned int byte);
+
+//--peek ---------------------------------------------------
+extern int peek(int bank,int address);
+extern int deek(int bank,int address);
+extern int leek(int bank,int address);
+
+//--fastcopy ---------------------------------------------------
+extern int memcopy(int sbank,int s ,int dbank,int d,int size);
+//--------------------------------------------------------------------------------------------------
+
+//- strings ----------------------------------------------------------------------------------------
+
+//STRINGS RUTINES
+extern int asc(char *string);
+extern char *chr(int v);
+extern void format();
+extern char *insert(char *source, char *target,int position);
+extern int instr(int start,char *find, char *search);
+extern char *lcase(char *string);
+extern char *left(char *string,int pos);
+extern int len(char *string);
+extern char *ltrim(char *string);
+extern char *mid(char *string,int i,int n);
+extern char *replace(char *src,char *rep, int i);
+extern char *replacesubstr(int start,char *source,char *replace, char *with);
+extern char *reverse(char *string);
+extern char *right(char *string,int pos);
+extern int rinstr(char *search,char *find,int start);
+extern char *rtrim(char *string);
+extern char *space(int n);
+extern char *str(int v);
+extern char *string(int n, char *string);
+extern int tally(char *src,char *sub,int start);
+extern char *trim( char *string);
+extern char *ucase(char *string);
+extern int val(char *string);
+
+//--------------------------------------------------------------------------------------------------
+
+//- math -------------------------------------------------------
+
+extern char *bin(int i);
+extern char *hex(int i);
+extern void randomize(int seed);
+extern double rnd(int upper);
+extern double round(double n1);
+extern int sgn(double  n);
+extern double Min( double a, double b );
+extern double Max( double a, double b );
+extern int bitwiseand(int a, int b);
+extern int bitwiseor(int a, int b);
+extern int bitwisexor(int a, int b);
+
+//--------------------------------------------------------------------------------------------------
+
+/*
+    Name:                string.c
+    Purpose:             string operation rutines
+    Author:              Kevin Veroneau __chronoboy__
+    Original Author:     Viola Roberto __vroby__
+    Copyright:           (c) 2003 Viola Roberto <__vroby__@libero.it>
+                         (c) 2011 Kevin Veroneau <__kveroneau__@gmail.com>
+    Licence:             LGPL
+*/
+//_______________________________________________________________________________________________________________________
+
+//header
+
+#include <math.h>
+#include <string.h>
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libamos.h"
+
+
+/* bin: returns binary representation of number */
+char *bin(int i)
+{
+    int l;
+    char    *buffer ,*ret;
+
+    buffer = (char *)malloc(1024);
+    strcpy(buffer,"");
+
+    if (i==0)strcat(buffer,"0");
+
+    while(i>0){
+	if ((i%2)==0)
+	    strcat(buffer,"0");
+	else
+	    strcat(buffer,"1");
+	i=i /2;
+    }
+    l=strlen(buffer);
+
+    ret = (char *)malloc(l+1);
+    for (i=0;i<l;i++)
+	ret[i]=buffer[l-i-1];
+    ret[l]='\0';
+    free(buffer);
+    return ret;
+}
+//_______________________________________________________________________________________________________________________
+
+/* hex: returns hexidecimal representation of number */
+char *hex(int i)
+{
+    char *buffer;
+
+    buffer = (char *)malloc(16);
+    sprintf( buffer, "%x", i);
+    return buffer;
+}
+//_______________________________________________________________________________________________________________________
+
+/* randomize: reseed the random number generator */
+void randomize(int seed)
+{
+    if (seed<0)
+        seed = time(NULL);
+    srand( seed );
+}
+//_______________________________________________________________________________________________________________________
+
+/* rnd: return an random number */
+double rnd(int upper)
+{
+    int result;
+
+    result = rand();
+    if (upper>0) {
+        result = (result % (upper-1))+1;
+    }
+    return( (float)result );
+}
+//_______________________________________________________________________________________________________________________
+
+/* round: round to nearest integer */
+double round(double n1)
+{
+    double n2;
+    n2 = floor(n1);
+    if (n2 == 0) {
+        /* leave it alone */
+
+    } else if (n2 > 0) {
+        if ((n1 - n2) > 0.5) {
+            n2++;
+        }
+    } else {
+        if (-(n2 - n1) > 0.5) {
+            n2++;
+        }
+    }
+    return( n2 );
+}
+//_______________________________________________________________________________________________________________________
+
+/* sgn: returns sign of numeric expression */
+int sgn(double  n)
+{
+    if (n < 0) {
+        return(-1);
+    } else if (n > 0) {
+        return(1);
+    } else {
+        return(0);
+    }
+}
+//_______________________________________________________________________________________________________________________
+
+/* min: return min number of the operands */
+double Min(double a, double b)
+{
+    if (b>a)
+	return a;
+    else
+	return b;
+}
+//_______________________________________________________________________________________________________________________
+
+/* max: return max number of the operands */
+double Max(double a, double b)
+{
+    if (b<a)
+	return a;
+    else
+	return b;
+}
+//_______________________________________________________________________________________________________________________
+
+/* bitwiseand: return the logic and of the operands */
+int bitwiseand(int a, int b)
+{
+    return(a & b);
+}
+//_______________________________________________________________________________________________________________________
+
+/* bitwiseor: return the logic or of the operands */
+int bitwiseor(int a, int b)
+{
+    return(a | b);
+}
+//_______________________________________________________________________________________________________________________
+
+/* bitwisexor: return the logic xor of the operands */
+int bitwisexor(int a, int b)
+{
+    return(a ^ b);
+}
+/*
+    Name:                membank.c
+    Purpose:             memory bank support for libamos
+    Author:              Kevin Veroneau __chronoboy__
+    Original Author:     Viola Roberto __vroby__
+    Copyright:           (c) 2003 Viola Roberto <__vroby__@libero.it>
+                         (c) 2011 Kevin Veroneau <__kveroneau__@gmail.com>
+    Licence:             LGPL
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "libamos.h"
+
+
+char *membank[NUM_MEMBANKS];
+int banksize[NUM_MEMBANKS];
+int curbank;
+
+
+//--Internal ---------------------------------------------------
+void init_membank()
+{
+    int i;
+    for(i=0;i<NUM_MEMBANKS;i++)
+	    banksize[i]=0;
+    curbank=0;
+}
+
+//--Base ---------------------------------------------------
+
+int reservebank(int bank,int size)
+{
+
+    if (banksize[bank]!=0)
+      free(membank[bank]);
+    membank[bank]=(char *) malloc(size);
+    banksize[bank]=size;
+    curbank=bank;
+    if (membank[bank]==NULL){
+   	error_description="membank Error:memory bank not allocated. Fill all memory?  ";
+		error_type=1;
+   	return -1;
+    }
+    memset(membank[bank],0,size);
+    return 0;
+}
+//______________________________________________________________________________________________
+
+
+int freebank(int bank)
+{
+    free(membank[bank]);
+    banksize[bank]=0;
+    if (curbank==bank)curbank=0;
+    return 0;
+}
+//______________________________________________________________________________________________
+
+
+int copybank(int s,int d)
+{
+    if (membank[s]==NULL){
+ 		error_description="membank Error:source bank not found ";
+		error_type=1;
+   	return -1;
+    }
+    if (banksize[d]!=0)
+   	free(membank[d]);
+
+    membank[d]=(char *) malloc(banksize[s]);
+    banksize[d]=banksize[s];
+
+    memcpy(membank[d],membank[s],banksize[s]);
+    if (membank[d]==NULL){
+  		error_description="membank Error:could not copy bank or memory bank not allocated ";
+		error_type=1;
+   	return -1;
+    }
+    else
+   	return 0;
+}
+//______________________________________________________________________________________________
+
+int loadbank(char *filename,int bank)
+{
+    int err;
+    int len;
+    int adv;
+    unsigned int len1;
+    FILE *handle;
+
+    len1=0xfffe;
+    adv=0;
+    if (bank==-1)bank=curbank;
+
+
+    handle=fopen(filename,"rb");
+    if (handle==NULL){
+  		error_description="membank Error:cold not open the file for loading ";
+		error_type=1;
+   	return -1;
+    }
+    fseek(handle,0,SEEK_END);
+    len=ftell(handle);
+    fseek(handle,0,SEEK_SET);
+
+    if (banksize[bank]!=0)
+   	free(membank[bank]);
+
+    membank[bank]=(char *) malloc(len);
+    banksize[bank]=len;
+
+    while (len1<len)
+    {
+   	err=fread(membank[bank]+adv,len1,1,handle);
+   	len=len-len1;
+   	adv=adv+len1;
+    };
+
+    err=fread(membank[bank]+adv,len,1,handle);
+    fclose(handle);
+    return err;
+}
+//______________________________________________________________________________________________
+
+int savebank(char *filename,int bank)
+{
+    int err;
+    int len;
+    int adv;
+    unsigned int len1;
+    FILE *handle;
+
+    if (bank==-1)bank=curbank;
+
+    handle=fopen(filename,"wb");
+    if (handle==NULL){
+  		error_description="membank Error:cold not open the file for saving ";
+		error_type=1;
+   	return -1;
+    }
+
+    len=banksize[bank];
+    len1=0xfffe;
+    adv=0;
+    while (len1<len)
+    {
+   	err=fwrite(membank[bank]+adv,1,len1,handle);
+   	len=len-len1;
+   	adv=adv+len1;
+    }
+
+    err=fwrite(membank[bank]+adv,len,1,handle);
+    fclose(handle);
+    return err;
+}
+//______________________________________________________________________________________________
+
+int setbank(int bank)
+{
+    if (bank==-1){
+   	return curbank;
+    }
+    else{
+   	curbank=bank;
+   	if (membank[bank]==NULL){
+	    error_description="membank Error:bank not used or not allocated ";
+	    error_type=1;
+	    return -1;
+   	}
+	else
+	    return 0;
+    }
+}
+//______________________________________________________________________________________________
+
+int sizebank(int bank)
+{
+    if (bank==-1)bank=curbank;
+    return banksize[bank];
+}
+
+
+//--poke ---------------------------------------------------
+//______________________________________________________________________________________________
+
+int poke(int bank,int address,unsigned char byte)
+{
+    if (bank==-1)bank=curbank;
+
+    if (address <0){
+  		error_description="membank Error:poke must be used  with positive address ";
+		error_type=1;
+   	return -1;
+    }
+    if (address >banksize[bank]-1){
+  		error_description="membank Error:poke address out of bank ";
+		error_type=1;
+   	return -1;
+    }
+    membank[bank][address]=byte & 255;
+
+    return 0;
+}
+//______________________________________________________________________________________________
+
+int doke(int bank,int address,unsigned short byte)
+{
+    if (bank==-1)bank=curbank;
+
+    if (address <0){
+  		error_description="membank Error:doke must be used  with positive address ";
+		error_type=1;
+   	return -1;
+    }
+    if (address+1 >banksize[bank]-1){
+		error_description="membank Error:doke address out of bank ";
+		error_type=1;
+   	return -1;
+    }
+
+    membank[bank][address]=byte & 255;
+    membank[bank][address+1]=byte / 256;
+
+    return 0;
+}
+//______________________________________________________________________________________________
+
+int loke(int bank,int address,unsigned int byte)
+{
+    if (bank==-1)bank=curbank;
+
+
+    if (address <0){
+		error_description="membank Error:loke must be used  with positive address ";
+		error_type=1;
+   	return -1;
+    }
+    if (address+3 >banksize[bank]-1){
+		error_description="membank Error:loke address out of bank ";
+		error_type=1;
+   	return -1;
+    }
+
+    membank[bank][address]=byte & 255;
+    membank[bank][address+1]=(byte / 256)&255;
+    membank[bank][address+2]=(byte/256/256) & 255;
+    membank[bank][address+3]=(byte/256/256/256) & 255;
+
+    return 0;
+}
+
+
+//--peek ---------------------------------------------------
+//______________________________________________________________________________________________
+
+int peek(int bank,int address)
+{
+    if (bank==-1)bank=curbank;
+
+    if (address <0){
+		error_description="membank Error:peek must be used with positive address ";
+		error_type=1;
+   	return -1;
+    }
+    if (address >banksize[bank]-1){
+  		error_description="membank Error:peek address out of bank ";
+		error_type=1;
+   	return -1;
+    }
+
+    return  (unsigned char)membank[bank][address];
+}
+//______________________________________________________________________________________________
+
+int deek(int bank,int address)
+{
+     unsigned char lo,hi;
+
+    if (bank==-1)bank=curbank;
+
+    if (address <0){
+		error_description="membank Error:deek must be used with positive address ";
+		error_type=1;
+   	return -1;
+    }
+    if (address+1 >banksize[bank]-1){
+		error_description="membank Error:deek address out of bank ";
+		error_type=1;
+   	return -1;
+    }
+
+    lo=(unsigned char)membank[bank][address];
+    hi=(unsigned char)membank[bank][address+1];
+    return lo+(hi*256);
+}
+//______________________________________________________________________________________________
+
+int leek(int bank,int address)
+{
+    unsigned char lo,hi,lohi,hihi;
+
+    if (bank==-1)bank=curbank;
+
+    if (address <0){
+		error_description="membank Error:leek must be used with positive address ";
+		error_type=1;
+   	return -1;
+    }
+    if (address+3 >banksize[bank]-1){
+		error_description="membank Error:leek address out of bank ";
+		error_type=1;
+   	return -1;
+    }
+
+    lo=(unsigned char)membank[bank][address];
+    hi=(unsigned char)membank[bank][address+1];
+    lohi=(unsigned char)membank[bank][address+2];
+    hihi=(unsigned char)membank[bank][address+3];
+    return lo+(hi*256)+(lohi*256*256)+(hihi*256*256*256);
+}
+
+//______________________________________________________________________________________________
+
+//--fastcopy ---------------------------------------------------
+
+int memcopy(int sbank,int s ,int dbank,int d,int size)
+{
+    if (banksize[sbank]-1 <s+size){
+		error_description="membank Error:copy source read out of bank ";
+		error_type=1;
+   	return -1;
+    }
+    if (banksize[dbank]-1 <d+size){
+		error_description="membank Error:copy dest write out of bank ";
+		error_type=1;
+   	return -1;
+    }
+
+    memcpy(&membank[dbank][d],&membank[sbank][s],size);
+    return 0;
+}
+/*
+    Name:                string.c
+    Purpose:             string operation rutines
+    Author:              Kevin Veroneau __chronoboy__
+    Original Author:     Viola Roberto __vroby__
+    Copyright:           (c) 2003 Viola Roberto <__vroby__@libero.it>
+                         (c) 2011 Kevin Veroneau <__kveroneau__@gmail.com>
+    Licence:             LGPL
+*/
+//_______________________________________________________________________________________________________________________
+
+//header
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <ctype.h>
+#include <string.h>
+//#include "strings.h"
+#include "libamos.h"
+//_______________________________________________________________________________________________________________________
+
+/* asc: returns ascii value of first char in string */
+int asc(char *string)
+{
+    return(unsigned char)string[0];
+}
+//_______________________________________________________________________________________________________________________
+
+/* chr: return string corresponding to ascii key value */
+char *chr(int v)
+{
+    char    *buffer = (char *)malloc(sizeof(char)*2);
+    buffer[0] = (char)v;
+    buffer[1] = '\0';
+    return buffer;
+}
+//_______________________________________________________________________________________________________________________
+
+/* format: returns formatted string with embedded args */
+void format()
+{
+}
+//_______________________________________________________________________________________________________________________
+/* insert: insert source string to target at index */
+char *insert(char *source, char *target,int position)
+{
+    char    *dest;
+    dest = (char *) malloc(strlen(source)+strlen(target)+1);
+
+	//strcpy(dest,"");
+	strncpy(dest,source,position);
+	strcpy(&dest[position],target);
+	strcat(dest,source+position);
+	return dest;
+}
+//_______________________________________________________________________________________________________________________
+
+/* instr: returns position in source that target was found */
+int instr(int start,char *find, char *search)
+{
+    int     searchLen, findLen, i;
+
+    if (start < 0) {
+	start = 0;
+    }
+
+    searchLen = strlen( search );
+    findLen = strlen( find );
+
+    /* searching for empty string? */
+    if (searchLen == 0 || findLen == 0) {
+        return 0;
+    }
+
+    start = (int)floor( start );
+    for ( i = start; i < searchLen; i++ ) {
+        if (strncmp( search+i, find, findLen ) == 0) {
+            return( i+1 );
+        }
+    }
+
+    /* not found */
+    return 0 ;
+}
+//_______________________________________________________________________________________________________________________
+
+/* lcase: convert string to lower case */
+char *lcase(char *string)
+{
+    int     len, i;
+
+    len = strlen( string );
+    for ( i = 0; i<len; i++){
+        string[i] = (char)tolower( (int)string[i] );
+    }
+    return string;
+}
+//_______________________________________________________________________________________________________________________
+
+/* left: returns leftmost chars in string */
+char *left(char *string,int pos)
+{
+    int     len, newLen;
+    char    *left;
+
+    len = strlen(string);
+
+    if (pos > len-1) {
+        return string;
+    }
+
+    if (pos < 1) {
+        return "";
+    }
+
+    newLen = (pos);
+    left = (char *) malloc(newLen+1);
+    for (pos=newLen;pos>0;pos--)left[pos]='\0';
+    strncpy(left,string,newLen);
+    left[newLen] = '\0';
+    return left;
+}
+//_______________________________________________________________________________________________________________________
+
+/* basLen: return length of string */
+int len(char *string)
+{
+    return (strlen( string ) );
+}
+//_______________________________________________________________________________________________________________________
+
+/* ltrim: returns string with left whitespace removed */
+char *ltrim(char *string)
+{
+    char *trimmed;
+
+    trimmed = string;
+    while ( trimmed[0] != '\0' ) {
+        if (!isspace(trimmed[0])) {
+            break;
+        }
+        trimmed++;
+    }
+    // debug al limite: da testare
+    return( trimmed );
+}
+//_______________________________________________________________________________________________________________________
+
+/* mid: returns string with chars 1..n from source */
+char *mid(char *string,int i,int n)
+{
+    int     j,len;
+    char    *buffer;
+
+    if (n<=0)
+	n=strlen(string)+1-i;
+
+    /* early outs */
+    len = strlen( string ) - i;
+    if ( i < 1 || len < 0 ) {
+        return "";
+    }
+
+    buffer = (char *)malloc(len+2);
+    for ( j = 0; j < n; j++ ) {
+        if (string[i+j-1] == '\0' ) {
+            break;
+        }
+        buffer[j] = string[i+j-1];
+    }
+    buffer[j] = '\0';
+    return buffer;
+}
+//_______________________________________________________________________________________________________________________
+
+/* replace: replace string from source with replace starting at index */
+char *replace(char *src,char *rep, int i)
+{
+    int        a;
+    char    *dest;
+
+    if (i<0)i = 0;
+
+    dest=(char *) malloc(strlen(src)+1);
+    strcpy(dest,src);
+    for(a=0;a<strlen(rep);a++){
+	if ((a+i)>=strlen(dest))break;
+	dest[i+a]=rep[a];
+    }
+
+
+    return(dest);
+}
+//_______________________________________________________________________________________________________________________
+
+/* replacesubstr: replace substring in source with withstring */
+char *replacesubstr(int start, char *source, char *replace, char *with)
+{
+    unsigned int i;
+    char    *dest;
+    if (start<0)
+	start=0;
+
+    i=start;
+    while (i<strlen(source)){
+		if (strncmp(source+i,replace,strlen(replace))==0){
+			dest = (char *) malloc( strlen(source)+ strlen(with)+1 );
+			strcpy(dest,"");
+			strncpy(dest,source,i);
+			dest[i] = '\0';
+			strcat(dest,with);
+			strcat(dest,source+i+strlen(replace));
+			source = (char *) malloc(strlen(dest)+1);
+			strcpy(source,dest);
+			i+=strlen(with);
+		}
+		i++;
+	}
+    return(source);
+}
+//_______________________________________________________________________________________________________________________
+
+/* reverse: reverse a string */
+char *reverse(char *string)
+{
+    int     len, i, j;
+    char    *buffer;
+
+    len = strlen( string );
+
+    buffer = (char *)malloc(len+1);
+    j = len-1;
+    for( i = 0; i < len; i++ ) {
+        buffer[j--] = string[i];
+    }
+    buffer[len] = '\0';
+
+    return(buffer);
+}
+//_______________________________________________________________________________________________________________________
+
+/* right: returns rightmost chars in string */
+char *right(char *string,int pos)
+{
+    int     len, newlen;
+    char    *right;
+
+    len = strlen(string);
+
+    if (pos >= len) {
+        return( string );
+    }
+
+    if (pos < 1) {
+        return( "" );
+    }
+
+    newlen = pos+1;
+    right = (char *)malloc((newlen+1));
+    memcpy(right,string+(len-pos),newlen);
+    right[newlen]=0;
+    return( right );
+}
+//_______________________________________________________________________________________________________________________
+
+/* rinstr: reverse Instr function, search from end to start */
+int rinstr(char *search,char *find,int start)
+{
+    int      searchLen, findLen, i;
+
+    findLen = strlen( find );
+    searchLen = strlen( search );
+
+    if (start<=0)
+    start = searchLen-1;
+
+    /* searching for empty string? */
+    if (searchLen == 0 || findLen == 0) {
+        return( 0 );
+    }
+
+
+    /* search */
+    for ( i = start; i >= 0; i-- ) {
+        if (strncmp( search+i, find, findLen ) == 0) {
+            return( i+1 );
+        }
+    }
+
+    /* not found */
+    return( 0 );
+}
+//_______________________________________________________________________________________________________________________
+
+/* rtrim: right trim string */
+char *rtrim(char *string)
+{
+    int     len, i;
+    len = strlen(string);
+    for ( i = len-1; i > -1; i-- ) {
+        if (!isspace(string[i])) {
+            string[i+1] = '\0';
+            return( string );
+        }
+    }
+    string[0] = '\0';
+    return(string );
+}
+//_______________________________________________________________________________________________________________________
+
+/* space: return string with n spaces in it */
+char *space(int n)
+{
+    char    *string;
+    if (n<0) {
+        n = 0;
+    }
+    string = (char *)malloc((unsigned int)n+1);
+    memset(string,' ',n);
+    string[n] = '\0';
+    return(string);
+}
+//_______________________________________________________________________________________________________________________
+
+/* str: return string representation of numeric expression */
+char *str(int v)
+{
+    char    *string;
+    string = (char *)malloc(32);
+    sprintf(string,"%d",v);
+    return(string);
+}
+//_______________________________________________________________________________________________________________________
+
+/* string: returns string m chars wide with n in it */
+char *string(int n, char *string)
+{
+    int     l,i;
+    char    *buffer;
+
+    l=strlen(string)+1;
+
+    buffer = (char *)malloc((l*n)+1);
+    strcpy(buffer,"");
+    for (i=0;i<n;i++)
+	strcat(buffer,string);
+    buffer[(l*n)] = '\0';
+    return( buffer );
+}
+//_______________________________________________________________________________________________________________________
+
+/* basTally:  returns number of occurances of matchstring */
+int tally(char *src,char *sub,int start)
+{
+    int		i,ret;
+
+    if (start<0)start = 0;
+    ret=0;
+    for(i=start;i<strlen(src);i++)
+        if (strncmp(src+i,sub,strlen(sub))==0)
+            ret++;
+
+    return(ret);
+}
+//_______________________________________________________________________________________________________________________
+
+/* trim: returns string with left and right whitespace removed */
+char *trim( char *string)
+{
+      int     len, i;
+      char    *trimmed;
+
+    len = strlen(string);
+    for ( i = len-1; i > -1; i-- ) {
+        if (!isspace(string[i])) {
+            string[i+1] = '\0';
+            break;
+        }
+    }
+
+    if (i==0)
+	    string[0] = '\0';
+
+    trimmed=string;
+    while ( trimmed[0] != '\0' ) {
+        if (!isspace(trimmed[0])) {
+            break;
+        }
+        trimmed++;
+    }
+
+    return( trimmed );
+}
+//_______________________________________________________________________________________________________________________
+
+/* ucase: convert string to upper case */
+char *ucase(char *string)
+{
+    int     len, i;
+
+    len = strlen( string );
+    for ( i = 0; i<len; i++){
+        string[i] = toupper( string[i] );
+    }
+    return( string );
+}
+//_______________________________________________________________________________________________________________________
+
+/* val: returns closest numeric representation of number */
+int val(char *string)
+{
+    return( atof(string) );
+}
+//_______________________________________________________________________________________________________________________
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.