Terminal stuff

This commit is contained in:
Julian Barathieu 2019-03-18 14:21:00 +01:00
parent 281964500b
commit d718561a9c
3 changed files with 65 additions and 0 deletions

View File

@ -239,6 +239,30 @@ DEC_CTYPE_FUNC(isalnum, (_AL|_DG));
//------------------------------------------//
#ifndef __min_defined
#define __min_defined
static inline int min(int __x, int __y)
{ return __x < __y ? __x : __y; }
#endif
#ifndef __lmin_defined
#define __lmin_defined
static inline int lmin(long __x, long __y)
{ return __x < __y ? __x : __y; }
#endif
#ifndef __max_defined
#define __max_defined
static inline int max(int __x, int __y)
{ return __x > __y ? __x : __y; }
#endif
#ifndef __lmax_defined
#define __lmax_defined
static inline int lmax(long __x, long __y)
{ return __x > __y ? __x : __y; }
#endif
#ifndef __abs_defined
#define __abs_defined
static inline int abs(int __x)

View File

@ -37,6 +37,11 @@
//
enum { KTABSIZE = 4 };
//
// Upper bound on what a single KernLog() can write
//
enum { KLOG_MAX_BUFSIZE = 4096 };
//
// The VGA colors
//

View File

@ -116,3 +116,39 @@ error_t PrintOnTerm(Terminal_t *term, const char *str)
return retcode;
}
//
// Print formatted string on standard output
// Prints at most KLOG_MAX_BUFSIZE characters
//
error_t KernLog(const char *fmt, ...)
{
va_list ap;
char logbuf[KLOG_MAX_BUFSIZE];
va_start(ap, fmt);
vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap);
va_end(ap);
return PrintOnTerm(stdOut, logbuf);
}
#ifndef _NO_DEBUG
//
// Print formatted string on debug output
// Prints at most KLOG_MAX_BUFSIZE characters
//
error_t DebugLog(const char *fmt, ...)
{
va_list ap;
char logbuf[KLOG_MAX_BUFSIZE];
va_start(ap, fmt);
vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap);
va_end(ap);
return PrintOnTerm(stdDbg, logbuf);
}
#endif