/*
    UserSupport.h, Copyright 21.3.97 (c) by C. Conrad,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
 
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/
/*
 	PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 
	
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/User/UserSupport.h,v $
 	Author(s):             C. Conrad 
 	Affiliation:           ETH Zuerich, TIK
 	Version:               $Revision: 2936 $
 	Creation Date:         21.3.97
 	Last Date of Change:   $Date: 2007-03-21 15:23:42 +0100 (Mit, 21 Mär 2007) $      by: $Author: baderma $
	
*/

#ifndef __USERSUPPORT_H
#define __USERSUPPORT_H

#include "../Topsy/Topsy.h"
#include <stdarg.h>


#define MAXCOMMENTSIZE     70
#define EQUAL 1
#define BEFORE 2
#define AFTER 3
#define UNDEFINED -1


/*
 * Copy nbBytes from address srcAddress to address targetAddress.
 * (equivalent to UNIX memcpy(), new name to avoid confusion).
 */
void byteCopy( Address targetAddress,
               Address sourceAddress,
               unsigned long int nbBytes);

//-CJ this is a ugly hack to get it compile without -O2
void memcpy(char *a, char *b, int len);
//inline static void memcpy(char *a, char *b, int len);
//{
//	byteCopy(a, b, len);
//}

/* fill memory with zeros */
void zeroOut(Address target, unsigned long int size);

/* initialize mem with a constant char */
void initmem(Address target, unsigned long int size, char c);

/*
 * Copy a NULL-terminated string from source to target.
 * (equivalent to UNIX strcpy(), new name to avoid confusion).
 */
void stringCopy( char* target, char* source );

/* copies a string or at most the first size-1 bytes
 * and terminates it with 0 
 */
void stringNCopy( char* target, char* source, unsigned long int size);

unsigned long int str_len(register char *s);

int stringLength( char* s);

/* concatenate source 1 and source2 into the string dest */
/* dest needs to bee big enough to contain both */
void stringConcat(char *dest, char *source1, char *source2);

/* translate an integer to a string */
void int2string(char *str, int i);

void display( ThreadId tty, char* s);

int stringCompare(char* a, char* b);
int stringNCompare(const char *s1, const char *s2, int n);

int power(int base, int n);

int atoi(int* intValue, char* string);

void reverse(char s[]);

void itoa(int n, char s[]);

/* Now the fun part ... printf */
/* this is far from complete, no floats and other freaky stuff ...  */
/* kernel must not use floats anyway... (gfa) */
/* but it acts like a real posix printf / vsnprintf. (cj) */
int vsnprintf(char *buffer, unsigned long len, char *fmt, va_list ap);

/* printf supports this flags: %, #, -, +, ' ', 0, . (precision) & field width */
/* 						types: diouXx, c, s, p, DOU, l & h (prefix to diouXx)  */
int vprintf(ThreadId tty, char *fmt, va_list ap);
int printf(ThreadId tty, char *fmt, ...);

/* I only support snprintf because sprintf is the direct way to hell */
int snprintf(char *buf, unsigned long len, char *fmt, ...);



#endif //__USERSUPPORT_H
