Replace <libmaxsi/format.h> with <stdio.h>.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-22 21:09:33 +02:00
parent e9c8b0b669
commit 2c286d6830
15 changed files with 23 additions and 79 deletions

View File

@ -24,7 +24,7 @@
#include <libmaxsi/platform.h> #include <libmaxsi/platform.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <libmaxsi/format.h> #include <stdio.h>
namespace Maxsi namespace Maxsi
{ {
@ -168,7 +168,10 @@ namespace Maxsi
if ( 0 < readylen && callback && callback(user, ready, readylen) != readylen ) { return SIZE_MAX; } \ if ( 0 < readylen && callback && callback(user, ready, readylen) != readylen ) { return SIZE_MAX; } \
written += readylen; readylen = 0; written += readylen; readylen = 0;
size_t Virtual(Callback callback, void* user, const char* format, va_list parameters) extern "C" size_t vprintf_callback(size_t (*callback)(void*, const char*, size_t),
void* user,
const char* restrict format,
va_list parameters)
{ {
size_t written = 0; size_t written = 0;
size_t readylen = 0; size_t readylen = 0;

View File

@ -1,39 +0,0 @@
/******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
This file is part of LibMaxsi.
LibMaxsi is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
format.h
Provides printf formatting functions that uses callbacks.
******************************************************************************/
#ifndef LIBMAXSI_FORMAT_H
#define LIBMAXSI_FORMAT_H
namespace Maxsi
{
namespace Format
{
typedef size_t (*Callback)(void* user, const char* string, size_t stringlen);
size_t Virtual(Callback callback, void* user, const char* format, va_list parameters);
}
}
#endif

View File

@ -180,6 +180,13 @@ extern char* gets(void) asm ("sortix_gets");
/* traditional gets(3) is no longer POSIX, hence removed. */ /* traditional gets(3) is no longer POSIX, hence removed. */
#endif #endif
#if defined(_SORTIX_SOURCE) || defined(_WANT_SORTIX_VPRINTF_CALLBACK)
extern size_t vprintf_callback(size_t (*callback)(void*, const char*, size_t),
void* user,
const char* restrict format,
__gnuc_va_list ap);
#endif
__END_DECLS __END_DECLS
#endif #endif

View File

@ -22,15 +22,11 @@
*******************************************************************************/ *******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/format.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
namespace Maxsi {
static size_t FileWriteCallback(void* user, const char* string, size_t stringlen) static size_t FileWriteCallback(void* user, const char* string, size_t stringlen)
{ {
FILE* fp = (FILE*) user; FILE* fp = (FILE*) user;
@ -39,7 +35,7 @@ static size_t FileWriteCallback(void* user, const char* string, size_t stringlen
extern "C" int vfprintf(FILE* fp, const char* /*restrict*/ format, va_list list) extern "C" int vfprintf(FILE* fp, const char* /*restrict*/ format, va_list list)
{ {
size_t result = Maxsi::Format::Virtual(FileWriteCallback, fp, format, list); size_t result = vprintf_callback(FileWriteCallback, fp, format, list);
return (int) result; return (int) result;
} }
@ -96,7 +92,7 @@ extern "C" int vsnprintf(char* restrict str, size_t size, const char* restrict f
info.size = (size) ? size-1 : 0; info.size = (size) ? size-1 : 0;
info.produced = 0; info.produced = 0;
info.written = 0; info.written = 0;
Maxsi::Format::Virtual(StringPrintCallback, &info, format, list); vprintf_callback(StringPrintCallback, &info, format, list);
if ( size ) { info.str[info.written] = '\0'; } if ( size ) { info.str[info.written] = '\0'; }
return (int) info.produced; return (int) info.produced;
} }
@ -123,5 +119,3 @@ extern "C" int sprintf(char* restrict str, const char* restrict format, ...)
va_end(list); va_end(list);
return result; return result;
} }
} // namespace Maxsi

View File

@ -32,8 +32,6 @@
#include <sortix/kernel/panic.h> #include <sortix/kernel/panic.h>
#include "process.h" #include "process.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
namespace ELF namespace ELF

View File

@ -25,19 +25,19 @@
#ifndef SORTIX_LOG_H #ifndef SORTIX_LOG_H
#define SORTIX_LOG_H #define SORTIX_LOG_H
#include <libmaxsi/string.h> #include <stdio.h>
#include <libmaxsi/format.h> #include <string.h>
namespace Sortix namespace Sortix
{ {
namespace Log namespace Log
{ {
extern Maxsi::Format::Callback deviceCallback; extern size_t (*deviceCallback)(void*, const char*, size_t);
extern size_t (*deviceWidth)(void*); extern size_t (*deviceWidth)(void*);
extern size_t (*deviceHeight)(void*); extern size_t (*deviceHeight)(void*);
extern void* devicePointer; extern void* devicePointer;
void Init(Maxsi::Format::Callback callback, void Init(size_t (*callback)(void*, const char*, size_t),
size_t (*widthfunc)(void*), size_t (*widthfunc)(void*),
size_t (*heightfunc)(void*), size_t (*heightfunc)(void*),
void* user); void* user);
@ -59,9 +59,8 @@ namespace Sortix
inline size_t Print(const char* str) inline size_t Print(const char* str)
{ {
using namespace Maxsi;
if ( !deviceCallback ) { return 0; } if ( !deviceCallback ) { return 0; }
return deviceCallback(devicePointer, str, String::Length(str)); return deviceCallback(devicePointer, str, strlen(str));
} }
inline size_t PrintData(const void* ptr, size_t size) inline size_t PrintData(const void* ptr, size_t size)
@ -72,18 +71,16 @@ namespace Sortix
inline size_t PrintF(const char* format, ...) inline size_t PrintF(const char* format, ...)
{ {
using namespace Maxsi;
va_list list; va_list list;
va_start(list, format); va_start(list, format);
size_t result = Format::Virtual(deviceCallback, devicePointer, format, list); size_t result = vprintf_callback(deviceCallback, devicePointer, format, list);
va_end(list); va_end(list);
return result; return result;
} }
inline size_t PrintFV(const char* format, va_list list) inline size_t PrintFV(const char* format, va_list list)
{ {
using namespace Maxsi; return vprintf_callback(deviceCallback, devicePointer, format, list);
return Format::Virtual(deviceCallback, devicePointer, format, list);
} }
} }
} }

View File

@ -33,8 +33,6 @@
#include "syscall.h" #include "syscall.h"
#include "io.h" #include "io.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
namespace IO namespace IO

View File

@ -34,7 +34,7 @@ namespace Sortix
{ {
namespace Log namespace Log
{ {
Maxsi::Format::Callback deviceCallback = NULL; size_t (*deviceCallback)(void*, const char*, size_t) = NULL;
size_t (*deviceWidth)(void*) = NULL; size_t (*deviceWidth)(void*) = NULL;
size_t (*deviceHeight)(void*) = NULL; size_t (*deviceHeight)(void*) = NULL;
void* devicePointer = NULL; void* devicePointer = NULL;
@ -46,7 +46,7 @@ namespace Sortix
return Print(str); return Print(str);
} }
void Init(Maxsi::Format::Callback callback, void Init(size_t (*callback)(void*, const char*, size_t),
size_t (*widthfunc)(void*), size_t (*widthfunc)(void*),
size_t (*heightfunc)(void*), size_t (*heightfunc)(void*),
void* user) void* user)

View File

@ -34,8 +34,6 @@
#include "terminal.h" #include "terminal.h"
#include "logterminal.h" #include "logterminal.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
const unsigned SUPPORTED_MODES = TERMMODE_KBKEY const unsigned SUPPORTED_MODES = TERMMODE_KBKEY

View File

@ -30,8 +30,6 @@
#include "thread.h" #include "thread.h"
#include "scheduler.h" #include "scheduler.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
namespace Syscall namespace Syscall

View File

@ -29,8 +29,6 @@
#include "process.h" #include "process.h"
#include "terminal.h" #include "terminal.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
int SysSetTermMode(int fd, unsigned mode) int SysSetTermMode(int fd, unsigned mode)

View File

@ -26,8 +26,6 @@
#include <errno.h> #include <errno.h>
#include "utf8.h" #include "utf8.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
namespace UTF8 namespace UTF8

View File

@ -26,8 +26,6 @@
#include <string.h> #include <string.h>
#include "gdt.h" #include "gdt.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
namespace GDT namespace GDT

View File

@ -26,8 +26,6 @@
#include <string.h> #include <string.h>
#include "idt.h" #include "idt.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
namespace IDT namespace IDT

View File

@ -35,8 +35,6 @@
#include "syscall.h" #include "syscall.h"
#include "msr.h" #include "msr.h"
using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
extern size_t end; extern size_t end;