view src/init.c @ 21:7c2adb65ceac

Started working on dynamic memory I have a slightly adapted version of dynamic memory allocation from the H&R book in the program now, I will soon be adding the free function. I fixed sPrint so it will work with large buffers.
author Jonathan Pevarnek <pevarnj@gmail.com>
date Tue, 15 Mar 2011 22:55:36 -0400
parents 525eab23e68a
children 3fb0ec050ff3
line wrap: on
line source

/*
 * This is where everything starts
 */

#include <std.h>
#include <operations.h>
#include <stack.h>

void dumpBuffer(char *a, int b)
{
	int i;
	for(i = 0; i < b; i++) {
		int foo = (int) a[i];
		char c[10];
		itoa(foo, c);
		sPrint(c);
		sPrint(" ");
		if(!((i + 1)%20)) sPrint("\n");
	}
}

void start(u64 __memsize)
{
  int i, n;
  char *buffer;
	char input[30];

	while(1) {
		sPrint("How long do you want the string? ");
		n = atoi(sGet(input, 30));

		buffer = (char*) malloc(n + 2);
		if (!buffer) { //allocation failed, too large
			sPrint("ERROR\n");
			break;
		}

		for (i = 0; i < n; i++)
			buffer[i]='a'; //I need to make rand...
		buffer[n]='\0';

//		dumpBuffer(buffer, n);

		sPrint(append(itoa((int)buffer, input), "\n"));
		sPrint(append(buffer, "\n"));
	}
/*
	struct Stack theStack;
	struct Stack *stack = &theStack;
	initStack(stack);
	while(1) {
		int opVal;
		char input[30];
		sPrint("Please enter an operation or value: ");
		opVal = arrayLookup(sGet(input, 30), operationNames, MAXOP);
		if(opVal != MAXOP) {
			(*operation[opVal]) (stack); //call the function array
		} else {
			push(stack, atof(input));
		}
	}
*/
	for(;;)
		;
}