diff --git a/libmaxsi/Makefile b/libmaxsi/Makefile index b96dad6c..057601aa 100644 --- a/libmaxsi/Makefile +++ b/libmaxsi/Makefile @@ -88,7 +88,6 @@ strcoll.o \ strcpy.o \ strcspn.o \ strdup.o \ -string.o \ strlen.o \ strncasecmp.o \ strncat.o \ diff --git a/libmaxsi/format.cpp b/libmaxsi/format.cpp index 2daa08ff..8b04c6b3 100644 --- a/libmaxsi/format.cpp +++ b/libmaxsi/format.cpp @@ -23,7 +23,6 @@ ******************************************************************************/ #include -#include #include #include diff --git a/libmaxsi/include/libmaxsi/string.h b/libmaxsi/include/libmaxsi/string.h deleted file mode 100644 index cb15b2e9..00000000 --- a/libmaxsi/include/libmaxsi/string.h +++ /dev/null @@ -1,40 +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 . - - string.h - Useful functions for manipulating strings. - -******************************************************************************/ - -#ifndef LIBMAXSI_STRING_H -#define LIBMAXSI_STRING_H - -namespace Maxsi -{ - namespace String - { - char* Clone(const char* Source); - char* Combine(size_t NumParameters, ...); - char* Substring(const char* src, size_t offset, size_t length); - bool StartsWith(const char* Haystack, const char* Needle); - } -} - -#endif - diff --git a/libmaxsi/string.cpp b/libmaxsi/string.cpp deleted file mode 100644 index a88f02aa..00000000 --- a/libmaxsi/string.cpp +++ /dev/null @@ -1,269 +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 . - - string.cpp - Useful functions for manipulating strings. - -******************************************************************************/ - -#include -#include -#include -#include -#include - -namespace Maxsi -{ - namespace String - { - size_t Length(const char* String) - { - size_t Result = 0; - - while ( String[Result] != '\0' ) - { - Result++; - } - - return Result; - } - - char* Copy(char* Dest, const char* Src) - { - char* OriginalDest = Dest; - - while ( *Src != '\0' ) - { - *Dest = *Src; - Dest++; Src++; - } - - *Dest = '\0'; - - return OriginalDest; - } - - char* Cat(char* Dest, const char* Src) - { - char* OriginalDest = Dest; - - while ( *Dest != '\0' ) { Dest++; } - - while ( *Src != '\0' ) - { - *Dest = *Src; - Dest++; Src++; - } - - *Dest = '\0'; - - return OriginalDest; - } - - int Compare(const char* A, const char* B) - { - while ( true ) - { - if ( *A == '\0' && *B == '\0' ) { return 0; } - if ( *A < *B ) { return -1; } - if ( *A > *B ) { return 1; } - A++; B++; - } - } - - int CompareN(const char* A, const char* B, size_t MaxLength) - { - while ( MaxLength-- ) - { - if ( *A == '\0' && *B == '\0' ) { return 0; } - if ( *A < *B ) { return -1; } - if ( *A > *B ) { return 1; } - A++; B++; - } - - return 0; - } - - size_t Accept(const char* str, const char* accept) - { - size_t acceptlen = 0; - while ( accept[acceptlen] ) { acceptlen++; } - for ( size_t result = 0; true; result++ ) - { - char c = str[result]; - if ( !c ) { return result; } - bool matches = false; - for ( size_t i = 0; i < acceptlen; i++ ) - { - if ( str[result] != accept[i] ) { continue; } - matches = true; - break; - } - if ( !matches ) { return result; } - } - } - - size_t Reject(const char* str, const char* reject) - { - size_t rejectlen = 0; - while ( reject[rejectlen] ) { rejectlen++; } - for ( size_t result = 0; true; result++ ) - { - char c = str[result]; - if ( !c ) { return result; } - bool matches = false; - for ( size_t i = 0; i < rejectlen; i++ ) - { - if ( str[result] != reject[i] ) { continue; } - matches = true; - break; - } - if ( matches ) { return result; } - } - } - - char* TokenizeR(char* str, const char* delim, char** saveptr) - { - if ( !str && !*saveptr ) { return NULL; } - if ( !str ) { str = *saveptr; } - str += Accept(str, delim); // Skip leading - if ( !*str ) { return NULL; } - size_t amount = Reject(str, delim); - if ( str[amount] ) { *saveptr = str + amount + 1; } - else { *saveptr = NULL; } - str[amount] = '\0'; - return str; - } - - char* Tokenize(char* str, const char* delim) - { - static char* lasttokensaveptr = NULL; - return TokenizeR(str, delim, &lasttokensaveptr); - } - - char* SeekNul(const char* str, int c) - { - while ( *str ) - { - if ( *str == c ) { return (char*) str; } - str++; - } - return (char*) str; - } - - char* SeekReverse(const char* str, int c) - { - const char* last = NULL; - while ( *str ) - { - if ( *str == c ) { last = str; } - str++; - } - return (char*) last; - } - - char* Seek(const char* str, int c) - { - char* result = SeekNul(str, c); - if ( !*result ) { return NULL; } - return result; - } - - bool StartsWith(const char* haystack, const char* needle) - { - return CompareN(haystack, needle, Length(needle)) == 0; - } - - char* Clone(const char* Input) - { - size_t InputSize = Length(Input); - char* Result = new char[InputSize + 1]; - if ( Result == NULL ) { return NULL; } - memcpy(Result, Input, InputSize + 1); - return Result; - } - - char* Substring(const char* src, size_t offset, size_t length) - { - size_t srclen = Length(src); - char* dest = new char[length + 1]; - if ( !dest ) { return NULL; } - memcpy(dest, src + offset, length * sizeof(char)); - dest[length] = 0; - return dest; - } - - int ToInt(const char* str) - { - bool negative = ( *str == '-' ); - if ( negative ) { str++; } - int result = 0; - int c; - while ( (c = *str++) != 0 ) - { - if ( c < '0' || '9' < c ) { return result; } - result = result * 10 + c - '0'; - } - return (negative) ? -result : result; - } - - char* Combine(size_t NumParameters, ...) - { - va_list param_pt; - - va_start(param_pt, NumParameters); - - // First calculate the string length. - size_t ResultLength = 0; - const char* TMP = 0; - - for ( size_t I = 0; I < NumParameters; I++ ) - { - TMP = va_arg(param_pt, const char*); - - if ( TMP != NULL ) { ResultLength += Length(TMP); } - } - - // Allocate a string with the desired length. - char* Result = new char[ResultLength+1]; - if ( !Result ) { return NULL; } - - Result[0] = 0; - - va_end(param_pt); - va_start(param_pt, NumParameters); - - size_t ResultOffset = 0; - - for ( size_t I = 0; I < NumParameters; I++ ) - { - TMP = va_arg(param_pt, const char*); - - if ( TMP ) - { - size_t TMPLength = Length(TMP); - Copy(Result + ResultOffset, TMP); - ResultOffset += TMPLength; - } - } - - return Result; - } - } -} diff --git a/sortix/Makefile b/sortix/Makefile index 60f66a45..6a8fd28b 100644 --- a/sortix/Makefile +++ b/sortix/Makefile @@ -86,6 +86,7 @@ HEADERS:=$(shell find include -type f) OBJS=$(CPUOBJS) \ kernel.o \ crc32.o \ +string.o \ interrupt.o \ worker.o \ time.o \ diff --git a/sortix/bga.cpp b/sortix/bga.cpp index cecff265..24b17e24 100644 --- a/sortix/bga.cpp +++ b/sortix/bga.cpp @@ -28,8 +28,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -39,8 +39,6 @@ #include "cpu.h" #include "bga.h" -using namespace Maxsi; - namespace Sortix { namespace BGA { diff --git a/sortix/directory.cpp b/sortix/directory.cpp index 22f67536..3389814e 100644 --- a/sortix/directory.cpp +++ b/sortix/directory.cpp @@ -23,7 +23,7 @@ ******************************************************************************/ #include -#include +#include #include #include #include @@ -34,8 +34,6 @@ #include "filesystem.h" #include "mount.h" -using namespace Maxsi; - namespace Sortix { namespace Directory diff --git a/sortix/filesystem.cpp b/sortix/filesystem.cpp index b20214c7..0bc0de21 100644 --- a/sortix/filesystem.cpp +++ b/sortix/filesystem.cpp @@ -23,7 +23,6 @@ ******************************************************************************/ #include -#include #include #include #include "syscall.h" @@ -35,8 +34,6 @@ #include #include -using namespace Maxsi; - namespace Sortix { namespace FileSystem diff --git a/sortix/fs/devfs.cpp b/sortix/fs/devfs.cpp index 82d84760..12a04a1b 100644 --- a/sortix/fs/devfs.cpp +++ b/sortix/fs/devfs.cpp @@ -23,7 +23,7 @@ ******************************************************************************/ #include -#include +#include #include #include #include @@ -36,8 +36,6 @@ #include "devfs.h" #include "videofs.h" -using namespace Maxsi; - namespace Sortix { class DevATA : public DevBuffer diff --git a/sortix/fs/initfs.cpp b/sortix/fs/initfs.cpp index 50b554c7..b1ee0aa8 100644 --- a/sortix/fs/initfs.cpp +++ b/sortix/fs/initfs.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include "../filesystem.h" @@ -33,8 +33,6 @@ #include "initfs.h" #include "../initrd.h" -using namespace Maxsi; - namespace Sortix { class DevInitFSFile : public DevBuffer diff --git a/sortix/fs/ramfs.cpp b/sortix/fs/ramfs.cpp index db1dcb1d..7b7874f7 100644 --- a/sortix/fs/ramfs.cpp +++ b/sortix/fs/ramfs.cpp @@ -23,7 +23,7 @@ ******************************************************************************/ #include -#include +#include #include #include #include @@ -32,8 +32,6 @@ #include "../stream.h" #include "ramfs.h" -using namespace Maxsi; - namespace Sortix { class DevRAMFSFile : public DevBuffer diff --git a/sortix/fs/util.cpp b/sortix/fs/util.cpp index 129f512e..924d24ce 100644 --- a/sortix/fs/util.cpp +++ b/sortix/fs/util.cpp @@ -23,13 +23,10 @@ *******************************************************************************/ #include -#include #include #include #include "util.h" -using namespace Maxsi; - namespace Sortix { DevStringBuffer::DevStringBuffer(char* str) diff --git a/sortix/fs/videofs.cpp b/sortix/fs/videofs.cpp index 2029419f..21b93084 100644 --- a/sortix/fs/videofs.cpp +++ b/sortix/fs/videofs.cpp @@ -24,15 +24,13 @@ #include #include -#include +#include #include #include #include "../directory.h" #include "util.h" #include "videofs.h" -using namespace Maxsi; - namespace Sortix { class DevFrameBuffer : public DevBuffer diff --git a/sortix/include/sortix/kernel/string.h b/sortix/include/sortix/kernel/string.h new file mode 100644 index 00000000..591a8481 --- /dev/null +++ b/sortix/include/sortix/kernel/string.h @@ -0,0 +1,39 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix 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 General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + Sortix. If not, see . + + string.h + Useful functions for manipulating strings that don't belong in libc. + +*******************************************************************************/ + +#ifndef SORTIX_STRING_H +#define SORTIX_STRING_H + +namespace Sortix { +namespace String { + +char* Clone(const char* Source); +char* Combine(size_t NumParameters, ...); +char* Substring(const char* src, size_t offset, size_t length); +bool StartsWith(const char* Haystack, const char* Needle); + +} // namespace String +} // namespace Sortix + +#endif diff --git a/sortix/initrd.cpp b/sortix/initrd.cpp index 90a05dff..0ab08543 100644 --- a/sortix/initrd.cpp +++ b/sortix/initrd.cpp @@ -25,17 +25,15 @@ #include #include #include +#include #include #include #include -#include #include #include #include "initrd.h" #include "syscall.h" -using namespace Maxsi; - namespace Sortix { namespace InitRD { diff --git a/sortix/kernelinfo.cpp b/sortix/kernelinfo.cpp index cf9b0d61..fc55c013 100644 --- a/sortix/kernelinfo.cpp +++ b/sortix/kernelinfo.cpp @@ -23,7 +23,6 @@ *******************************************************************************/ #include -#include #include #include "syscall.h" #include "kernelinfo.h" @@ -32,8 +31,6 @@ #define VERSIONSTR "unknown" #endif -using namespace Maxsi; - namespace Sortix { namespace Info { diff --git a/sortix/log.cpp b/sortix/log.cpp index 2f54efe5..6a3a41b6 100644 --- a/sortix/log.cpp +++ b/sortix/log.cpp @@ -23,13 +23,10 @@ ******************************************************************************/ #include -#include #include #include #include "syscall.h" -using namespace Maxsi; - namespace Sortix { namespace Log diff --git a/sortix/mount.cpp b/sortix/mount.cpp index 22a2ea1f..ff217c27 100644 --- a/sortix/mount.cpp +++ b/sortix/mount.cpp @@ -24,15 +24,13 @@ #include #include -#include +#include #include #include "mount.h" #include "fs/ramfs.h" #include "fs/initfs.h" #include "fs/devfs.h" -using namespace Maxsi; - namespace Sortix { class MountPoint diff --git a/sortix/panic.cpp b/sortix/panic.cpp index 68d02c15..bb44e297 100644 --- a/sortix/panic.cpp +++ b/sortix/panic.cpp @@ -23,15 +23,12 @@ ******************************************************************************/ #include -#include #include #include "interrupt.h" #include #include "calltrace.h" #include -using namespace Maxsi; - namespace Sortix { #if defined(DEBUG) || defined(PANIC_SHORT) diff --git a/sortix/process.cpp b/sortix/process.cpp index f76eb7d4..93095c4a 100644 --- a/sortix/process.cpp +++ b/sortix/process.cpp @@ -26,12 +26,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -47,8 +47,6 @@ #include "elf.h" #include "syscall.h" -using namespace Maxsi; - namespace Sortix { bool ProcessSegment::Intersects(ProcessSegment* segments) diff --git a/sortix/serialterminal.cpp b/sortix/serialterminal.cpp index 7c6e8961..3642712f 100644 --- a/sortix/serialterminal.cpp +++ b/sortix/serialterminal.cpp @@ -23,7 +23,6 @@ ******************************************************************************/ #include -#include #include #include "vga.h" #include "keyboard.h" @@ -31,8 +30,6 @@ #include "serialterminal.h" #include "scheduler.h" -using namespace Maxsi; - namespace Sortix { namespace SerialTerminal diff --git a/sortix/string.cpp b/sortix/string.cpp new file mode 100644 index 00000000..64fee9b0 --- /dev/null +++ b/sortix/string.cpp @@ -0,0 +1,100 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix 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 General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + Sortix. If not, see . + + string.cpp + Useful functions for manipulating strings that don't belong in libc. + +*******************************************************************************/ + +#include +#include +#include + +namespace Sortix { +namespace String { + +bool StartsWith(const char* haystack, const char* needle) +{ + return strncmp(haystack, needle, strlen(needle)) == 0; +} + +char* Clone(const char* Input) +{ + size_t InputSize = strlen(Input); + char* Result = new char[InputSize + 1]; + if ( Result == NULL ) { return NULL; } + memcpy(Result, Input, InputSize + 1); + return Result; +} + +char* Substring(const char* src, size_t offset, size_t length) +{ + size_t srclen = strlen(src); + char* dest = new char[length + 1]; + if ( !dest ) { return NULL; } + memcpy(dest, src + offset, length * sizeof(char)); + dest[length] = 0; + return dest; +} + +char* Combine(size_t NumParameters, ...) +{ + va_list param_pt; + + va_start(param_pt, NumParameters); + + // First calculate the string length. + size_t ResultLength = 0; + const char* TMP = 0; + + for ( size_t I = 0; I < NumParameters; I++ ) + { + TMP = va_arg(param_pt, const char*); + + if ( TMP != NULL ) { ResultLength += strlen(TMP); } + } + + // Allocate a string with the desired length. + char* Result = new char[ResultLength+1]; + if ( !Result ) { return NULL; } + + Result[0] = 0; + + va_end(param_pt); + va_start(param_pt, NumParameters); + + size_t ResultOffset = 0; + + for ( size_t I = 0; I < NumParameters; I++ ) + { + TMP = va_arg(param_pt, const char*); + + if ( TMP ) + { + size_t TMPLength = strlen(TMP); + strcpy(Result + ResultOffset, TMP); + ResultOffset += TMPLength; + } + } + + return Result; +} + +} // namespace String +} // namespace Sortix diff --git a/sortix/uart.cpp b/sortix/uart.cpp index 46ed3f2b..cd2ded30 100644 --- a/sortix/uart.cpp +++ b/sortix/uart.cpp @@ -24,13 +24,10 @@ #include #include "cpu.h" -#include #include #include "vga.h" #include "uart.h" -using namespace Maxsi; - namespace Sortix { namespace UART diff --git a/sortix/video.cpp b/sortix/video.cpp index 4c327aa1..6b3abb3d 100644 --- a/sortix/video.cpp +++ b/sortix/video.cpp @@ -26,13 +26,11 @@ #include #include #include +#include #include #include -#include #include -using namespace Maxsi; - namespace Sortix { bool ReadParamString(const char* str, ...)