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/string.h>
#include <libmaxsi/format.h>
#include <stdio.h>
namespace Maxsi
{
@ -168,7 +168,10 @@ namespace Maxsi
if ( 0 < readylen && callback && callback(user, ready, readylen) != readylen ) { return SIZE_MAX; } \
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 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. */
#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
#endif

View File

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

View File

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

View File

@ -25,19 +25,19 @@
#ifndef SORTIX_LOG_H
#define SORTIX_LOG_H
#include <libmaxsi/string.h>
#include <libmaxsi/format.h>
#include <stdio.h>
#include <string.h>
namespace Sortix
{
namespace Log
{
extern Maxsi::Format::Callback deviceCallback;
extern size_t (*deviceCallback)(void*, const char*, size_t);
extern size_t (*deviceWidth)(void*);
extern size_t (*deviceHeight)(void*);
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 (*heightfunc)(void*),
void* user);
@ -59,9 +59,8 @@ namespace Sortix
inline size_t Print(const char* str)
{
using namespace Maxsi;
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)
@ -72,18 +71,16 @@ namespace Sortix
inline size_t PrintF(const char* format, ...)
{
using namespace Maxsi;
va_list list;
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);
return result;
}
inline size_t PrintFV(const char* format, va_list list)
{
using namespace Maxsi;
return Format::Virtual(deviceCallback, devicePointer, format, list);
return vprintf_callback(deviceCallback, devicePointer, format, list);
}
}
}

View File

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

View File

@ -34,7 +34,7 @@ namespace Sortix
{
namespace Log
{
Maxsi::Format::Callback deviceCallback = NULL;
size_t (*deviceCallback)(void*, const char*, size_t) = NULL;
size_t (*deviceWidth)(void*) = NULL;
size_t (*deviceHeight)(void*) = NULL;
void* devicePointer = NULL;
@ -46,7 +46,7 @@ namespace Sortix
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 (*heightfunc)(void*),
void* user)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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