mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Update kernel/linebuffer.{cpp,h} to current coding conventions.
This commit is contained in:
parent
bb3b6b0260
commit
3fa5fff3f5
2 changed files with 137 additions and 125 deletions
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -22,14 +22,16 @@
|
|||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sortix/kernel/kernel.h>
|
||||
|
||||
#include "linebuffer.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace Sortix {
|
||||
|
||||
static size_t OffsetIndex(size_t offset, size_t index, size_t length)
|
||||
{
|
||||
// TODO: Possible overflow here.
|
||||
|
@ -58,7 +60,8 @@ namespace Sortix
|
|||
{
|
||||
size_t newbufferlength = (bufferlength) ? bufferlength * 2 : 32UL;
|
||||
uint32_t* newbuffer = new uint32_t[newbufferlength];
|
||||
if ( !newbuffer ) { return false; }
|
||||
if ( !newbuffer )
|
||||
return false;
|
||||
size_t elemsize = sizeof(*buffer);
|
||||
size_t leadingavai = bufferlength-bufferoffset;
|
||||
size_t leading = (leadingavai < bufferused) ? leadingavai : bufferused;
|
||||
|
@ -78,7 +81,8 @@ namespace Sortix
|
|||
|
||||
uint32_t LineBuffer::Pop()
|
||||
{
|
||||
if ( !CanPop() ) { return 0; }
|
||||
if ( !CanPop() )
|
||||
return 0;
|
||||
uint32_t result = Peek();
|
||||
bufferoffset = (bufferoffset+1) % bufferlength;
|
||||
buffercommitted--;
|
||||
|
@ -89,21 +93,24 @@ namespace Sortix
|
|||
|
||||
uint32_t LineBuffer::Peek() const
|
||||
{
|
||||
if ( !CanPop() ) { return 0; }
|
||||
if ( !CanPop() )
|
||||
return 0;
|
||||
size_t index = OffsetIndex(bufferoffset, 0, bufferlength);
|
||||
return buffer[index];
|
||||
}
|
||||
|
||||
uint32_t LineBuffer::Backspace()
|
||||
{
|
||||
if ( !CanBackspace() ) { return 0; }
|
||||
if ( !CanBackspace() )
|
||||
return 0;
|
||||
size_t index = OffsetIndex(bufferoffset, --bufferused, bufferlength);
|
||||
return buffer[index];
|
||||
}
|
||||
|
||||
uint32_t LineBuffer::WouldBackspace() const
|
||||
{
|
||||
if ( !CanBackspace() ) { return 0; }
|
||||
if ( !CanBackspace() )
|
||||
return 0;
|
||||
size_t index = OffsetIndex(bufferoffset, bufferused-1, bufferlength);
|
||||
return buffer[index];
|
||||
}
|
||||
|
@ -127,4 +134,5 @@ namespace Sortix
|
|||
{
|
||||
return bufferused - bufferfrozen;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Sortix
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -25,8 +25,11 @@
|
|||
#ifndef SORTIX_LINEBUFFER_H
|
||||
#define SORTIX_LINEBUFFER_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Sortix {
|
||||
|
||||
class LineBuffer
|
||||
{
|
||||
public:
|
||||
|
@ -53,6 +56,7 @@ namespace Sortix
|
|||
size_t bufferused;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Sortix
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue