Removed the inline.h module and removed the use of macros instead of "static
inline".
This commit is contained in:
@@ -38,11 +38,6 @@
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "inline.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -40,8 +40,6 @@
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
/* common */
|
||||
#include "inline.h"
|
||||
|
||||
|
||||
/* This module contains replacements for functions in ctype.h besides other
|
||||
@@ -73,15 +71,11 @@ int IsAscii (char C);
|
||||
int IsBlank (char C);
|
||||
/* Check for a space or tab */
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int IsControl (char C)
|
||||
static inline int IsControl (char C)
|
||||
/* Check for control chars */
|
||||
{
|
||||
return iscntrl ((unsigned char) C);
|
||||
}
|
||||
#else
|
||||
# define IsControl(C) iscntrl (C)
|
||||
#endif
|
||||
|
||||
int IsSpace (char C);
|
||||
/* Check for any white space characters */
|
||||
|
||||
@@ -155,89 +155,6 @@ void CollInsert (Collection* C, void* Item, unsigned Index)
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void CollAppend (Collection* C, void* Item)
|
||||
/* Append an item to the end of the collection */
|
||||
{
|
||||
/* Insert the item at the end of the current list */
|
||||
CollInsert (C, Item, C->Count);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void* CollAt (const Collection* C, unsigned Index)
|
||||
/* Return the item at the given index */
|
||||
{
|
||||
/* Check the index */
|
||||
PRECONDITION (Index < C->Count);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[Index];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
const void* CollConstAt (const Collection* C, unsigned Index)
|
||||
/* Return the item at the given index */
|
||||
{
|
||||
/* Check the index */
|
||||
PRECONDITION (Index < C->Count);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[Index];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void* CollLast (Collection* C)
|
||||
/* Return the last item in a collection */
|
||||
{
|
||||
/* We must have at least one entry */
|
||||
PRECONDITION (C->Count > 0);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[C->Count-1];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
const void* CollConstLast (const Collection* C)
|
||||
/* Return the last item in a collection */
|
||||
{
|
||||
/* We must have at least one entry */
|
||||
PRECONDITION (C->Count > 0);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[C->Count-1];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void* CollPop (Collection* C)
|
||||
/* Remove the last segment from the stack and return it. Calls FAIL if the
|
||||
** collection is empty.
|
||||
*/
|
||||
{
|
||||
/* We must have at least one entry */
|
||||
PRECONDITION (C->Count > 0);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[--C->Count];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int CollIndex (Collection* C, const void* Item)
|
||||
/* Return the index of the given item in the collection. Return -1 if the
|
||||
** item was not found in the collection.
|
||||
@@ -290,22 +207,6 @@ void CollDeleteItem (Collection* C, const void* Item)
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void CollReplace (Collection* C, void* Item, unsigned Index)
|
||||
/* Replace the item at the given position. The old item will not be freed,
|
||||
** just the pointer will get replaced.
|
||||
*/
|
||||
{
|
||||
/* Check the index */
|
||||
PRECONDITION (Index < C->Count);
|
||||
|
||||
/* Replace the item pointer */
|
||||
C->Items[Index] = Item;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void CollReplaceExpand (Collection* C, void* Item, unsigned Index)
|
||||
/* If Index is a valid index for the collection, replace the item at this
|
||||
** position by the one passed. If the collection is too small, expand it,
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
/* common */
|
||||
#include "attrib.h"
|
||||
#include "check.h"
|
||||
#include "inline.h"
|
||||
|
||||
|
||||
|
||||
@@ -96,33 +95,23 @@ void CollGrow (Collection* C, unsigned Size);
|
||||
** of items to be placed in the collection is known in advance.
|
||||
*/
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned CollCount (const Collection* C)
|
||||
static inline unsigned CollCount (const Collection* C)
|
||||
/* Return the number of items in the collection */
|
||||
{
|
||||
return C->Count;
|
||||
}
|
||||
#else
|
||||
# define CollCount(C) (C)->Count
|
||||
#endif
|
||||
|
||||
void CollInsert (Collection* C, void* Item, unsigned Index);
|
||||
/* Insert the data at the given position in the collection */
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void CollAppend (Collection* C, void* Item)
|
||||
static inline void CollAppend (Collection* C, void* Item)
|
||||
/* Append an item to the end of the collection */
|
||||
{
|
||||
/* Insert the item at the end of the current list */
|
||||
CollInsert (C, Item, C->Count);
|
||||
}
|
||||
#else
|
||||
void CollAppend (Collection* C, void* Item);
|
||||
/* Append an item to the end of the collection */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void* CollAt (const Collection* C, unsigned Index)
|
||||
static inline void* CollAt (const Collection* C, unsigned Index)
|
||||
/* Return the item at the given index */
|
||||
{
|
||||
/* Check the index */
|
||||
@@ -131,24 +120,15 @@ INLINE void* CollAt (const Collection* C, unsigned Index)
|
||||
/* Return the element */
|
||||
return C->Items[Index];
|
||||
}
|
||||
#else
|
||||
void* CollAt (const Collection* C, unsigned Index);
|
||||
/* Return the item at the given index */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void* CollAtUnchecked (const Collection* C, unsigned Index)
|
||||
static inline void* CollAtUnchecked (const Collection* C, unsigned Index)
|
||||
/* Return the item at the given index */
|
||||
{
|
||||
/* Return the element */
|
||||
return C->Items[Index];
|
||||
}
|
||||
#else
|
||||
# define CollAtUnchecked(C, Index) ((C)->Items[(Index)])
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE const void* CollConstAt (const Collection* C, unsigned Index)
|
||||
static inline const void* CollConstAt (const Collection* C, unsigned Index)
|
||||
/* Return the item at the given index */
|
||||
{
|
||||
/* Check the index */
|
||||
@@ -157,13 +137,8 @@ INLINE const void* CollConstAt (const Collection* C, unsigned Index)
|
||||
/* Return the element */
|
||||
return C->Items[Index];
|
||||
}
|
||||
#else
|
||||
const void* CollConstAt (const Collection* C, unsigned Index);
|
||||
/* Return the item at the given index */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void* CollLast (Collection* C)
|
||||
static inline void* CollLast (Collection* C)
|
||||
/* Return the last item in a collection */
|
||||
{
|
||||
/* We must have at least one entry */
|
||||
@@ -172,13 +147,8 @@ INLINE void* CollLast (Collection* C)
|
||||
/* Return the element */
|
||||
return C->Items[C->Count-1];
|
||||
}
|
||||
#else
|
||||
void* CollLast (Collection* C);
|
||||
/* Return the last item in a collection */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE const void* CollConstLast (const Collection* C)
|
||||
static inline const void* CollConstLast (const Collection* C)
|
||||
/* Return the last item in a collection */
|
||||
{
|
||||
/* We must have at least one entry */
|
||||
@@ -187,13 +157,8 @@ INLINE const void* CollConstLast (const Collection* C)
|
||||
/* Return the element */
|
||||
return C->Items[C->Count-1];
|
||||
}
|
||||
#else
|
||||
const void* CollConstLast (const Collection* C);
|
||||
/* Return the last item in a collection */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void* CollPop (Collection* C)
|
||||
static inline void* CollPop (Collection* C)
|
||||
/* Remove the last segment from the stack and return it. Calls FAIL if the
|
||||
** collection is empty.
|
||||
*/
|
||||
@@ -204,12 +169,6 @@ INLINE void* CollPop (Collection* C)
|
||||
/* Return the element */
|
||||
return C->Items[--C->Count];
|
||||
}
|
||||
#else
|
||||
void* CollPop (Collection* C);
|
||||
/* Remove the last segment from the stack and return it. Calls FAIL if the
|
||||
** collection is empty.
|
||||
*/
|
||||
#endif
|
||||
|
||||
int CollIndex (Collection* C, const void* Item);
|
||||
/* Return the index of the given item in the collection. Return -1 if the
|
||||
@@ -227,8 +186,7 @@ void CollDeleteItem (Collection* C, const void* Item);
|
||||
** collection, otherwise FAIL will be called.
|
||||
*/
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void CollDeleteAll (Collection* C)
|
||||
static inline void CollDeleteAll (Collection* C)
|
||||
/* Delete all items from the given collection. This will not free the items
|
||||
** itself, it will only remove the pointers.
|
||||
*/
|
||||
@@ -236,12 +194,8 @@ INLINE void CollDeleteAll (Collection* C)
|
||||
/* This one is easy... */
|
||||
C->Count = 0;
|
||||
}
|
||||
#else
|
||||
# define CollDeleteAll(C) ((C)->Count = 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void CollReplace (Collection* C, void* Item, unsigned Index)
|
||||
static inline void CollReplace (Collection* C, void* Item, unsigned Index)
|
||||
/* Replace the item at the given position. The old item will not be freed,
|
||||
** just the pointer will get replaced.
|
||||
*/
|
||||
@@ -252,12 +206,6 @@ INLINE void CollReplace (Collection* C, void* Item, unsigned Index)
|
||||
/* Replace the item pointer */
|
||||
C->Items[Index] = Item;
|
||||
}
|
||||
#else
|
||||
void CollReplace (Collection* C, void* Item, unsigned Index);
|
||||
/* Replace the item at the given position. The old item will not be freed,
|
||||
** just the pointer will get replaced.
|
||||
*/
|
||||
#endif
|
||||
|
||||
void CollReplaceExpand (Collection* C, void* Item, unsigned Index);
|
||||
/* If Index is a valid index for the collection, replace the item at this
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
|
||||
|
||||
/* common */
|
||||
#include "inline.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
|
||||
@@ -99,15 +98,11 @@ struct HashTable {
|
||||
|
||||
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void InitHashNode (HashNode* N)
|
||||
static inline void InitHashNode (HashNode* N)
|
||||
/* Initialize a hash node. */
|
||||
{
|
||||
N->Next = 0;
|
||||
}
|
||||
#else
|
||||
#define InitHashNode(N) do { (N)->Next = 0; } while (0)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -125,29 +120,21 @@ void DoneHashTable (HashTable* T);
|
||||
** in the table!
|
||||
*/
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE HashTable* NewHashTable (unsigned Slots, const HashFunctions* Func)
|
||||
static inline HashTable* NewHashTable (unsigned Slots, const HashFunctions* Func)
|
||||
/* Create a new hash table and return it. */
|
||||
{
|
||||
/* Allocate memory, initialize and return it */
|
||||
return InitHashTable (xmalloc (sizeof (HashTable)), Slots, Func);
|
||||
}
|
||||
#else
|
||||
#define NewHashTable(Slots, Func) InitHashTable(xmalloc (sizeof (HashTable)), Slots, Func)
|
||||
#endif
|
||||
|
||||
void FreeHashTable (HashTable* T);
|
||||
/* Free a hash table. Note: This will not free the entries in the table! */
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned HT_GetCount (const HashTable* T)
|
||||
static inline unsigned HT_GetCount (const HashTable* T)
|
||||
/* Return the number of items in the table. */
|
||||
{
|
||||
return T->Count;
|
||||
}
|
||||
#else
|
||||
#define HT_GetCount(T) ((T)->Count)
|
||||
#endif
|
||||
|
||||
HashNode* HT_FindHash (const HashTable* T, const void* Key, unsigned Hash);
|
||||
/* Find the node with the given key. Differs from HT_Find in that the hash
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* inline.h */
|
||||
/* */
|
||||
/* Definitions to use the inline compiler feature */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001-2005 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
/* warranty. In no event will the authors be held liable for any damages */
|
||||
/* arising from the use of this software. */
|
||||
/* */
|
||||
/* Permission is granted to anyone to use this software for any purpose, */
|
||||
/* including commercial applications, and to alter it and redistribute it */
|
||||
/* freely, subject to the following restrictions: */
|
||||
/* */
|
||||
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||
/* claim that you wrote the original software. If you use this software */
|
||||
/* in a product, an acknowledgment in the product documentation would be */
|
||||
/* appreciated but is not required. */
|
||||
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||
/* be misrepresented as being the original software. */
|
||||
/* 3. This notice may not be removed or altered from any source */
|
||||
/* distribution. */
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef INLINE_H
|
||||
#define INLINE_H
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Defines */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#if defined(__GNUC__) && !defined(DISABLE_INLINE)
|
||||
# define HAVE_INLINE 1
|
||||
# define INLINE static __inline__
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* End of inline.h */
|
||||
|
||||
#endif
|
||||
@@ -35,10 +35,6 @@
|
||||
|
||||
|
||||
|
||||
#include "inline.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
@@ -56,10 +52,16 @@ struct IntPtrStack {
|
||||
};
|
||||
|
||||
/* An initializer for an empty int stack */
|
||||
#define STATIC_INTPTRSTACK_INITIALIZER { 0, { 0, 0 }, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }
|
||||
#define STATIC_INTPTRSTACK_INITIALIZER { \
|
||||
0, \
|
||||
{ 0, 0 }, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } \
|
||||
}
|
||||
|
||||
/* Declare an int stack with the given value as first element */
|
||||
#define INTPTRSTACK(Val, Ptr) { 1, { {Val, Ptr}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }
|
||||
#define INTPTRSTACK(Val, Ptr) { \
|
||||
1, \
|
||||
{ {Val, Ptr}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } \
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -69,35 +71,23 @@ struct IntPtrStack {
|
||||
|
||||
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int IPS_IsFull (const IntPtrStack* S)
|
||||
static inline int IPS_IsFull (const IntPtrStack* S)
|
||||
/* Return true if there is no space left on the given int stack */
|
||||
{
|
||||
return (S->Count >= sizeof (S->Stack) / sizeof (S->Stack[0]));
|
||||
}
|
||||
#else
|
||||
# define IPS_IsFull(S) ((S)->Count >= sizeof ((S)->Stack) / sizeof ((S)->Stack[0]))
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int IPS_IsEmpty (const IntPtrStack* S)
|
||||
static inline int IPS_IsEmpty (const IntPtrStack* S)
|
||||
/* Return true if there are no values on the given int stack */
|
||||
{
|
||||
return (S->Count == 0);
|
||||
}
|
||||
#else
|
||||
# define IPS_IsEmpty(S) ((S)->Count == 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned IPS_GetCount (const IntPtrStack* S)
|
||||
static inline unsigned IPS_GetCount (const IntPtrStack* S)
|
||||
/* Return the number of elements on the given int stack */
|
||||
{
|
||||
return S->Count;
|
||||
}
|
||||
#else
|
||||
# define IPS_GetCount(S) (S)->Count
|
||||
#endif
|
||||
|
||||
void IPS_Get (const IntPtrStack* S, long *Val, void **Ptr);
|
||||
/* Get the value on top of an int stack */
|
||||
|
||||
@@ -38,10 +38,6 @@
|
||||
|
||||
|
||||
|
||||
#include "inline.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
@@ -68,35 +64,23 @@ struct IntStack {
|
||||
|
||||
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int IS_IsFull (const IntStack* S)
|
||||
static inline int IS_IsFull (const IntStack* S)
|
||||
/* Return true if there is no space left on the given int stack */
|
||||
{
|
||||
return (S->Count >= sizeof (S->Stack) / sizeof (S->Stack[0]));
|
||||
}
|
||||
#else
|
||||
# define IS_IsFull(S) ((S)->Count >= sizeof ((S)->Stack) / sizeof ((S)->Stack[0]))
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int IS_IsEmpty (const IntStack* S)
|
||||
static inline int IS_IsEmpty (const IntStack* S)
|
||||
/* Return true if there are no values on the given int stack */
|
||||
{
|
||||
return (S->Count == 0);
|
||||
}
|
||||
#else
|
||||
# define IS_IsEmpty(S) ((S)->Count == 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned IS_GetCount (const IntStack* S)
|
||||
static inline unsigned IS_GetCount (const IntStack* S)
|
||||
/* Return the number of elements on the given int stack */
|
||||
{
|
||||
return S->Count;
|
||||
}
|
||||
#else
|
||||
# define IS_GetCount(S) (S)->Count
|
||||
#endif
|
||||
|
||||
long IS_Get (const IntStack* S);
|
||||
/* Get the value on top of an int stack */
|
||||
|
||||
@@ -62,17 +62,6 @@ const StrBuf EmptyStrBuf = STATIC_STRBUF_INITIALIZER;
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
StrBuf* SB_Init (StrBuf* B)
|
||||
/* Initialize a string buffer */
|
||||
{
|
||||
*B = EmptyStrBuf;
|
||||
return B;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
StrBuf* SB_InitFromString (StrBuf* B, const char* S)
|
||||
/* Initialize a string buffer from a literal string. Beware: The buffer won't
|
||||
** store a copy but a pointer to the actual string.
|
||||
@@ -195,17 +184,6 @@ static void SB_CheapRealloc (StrBuf* B, unsigned NewSize)
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
char SB_At (const StrBuf* B, unsigned Index)
|
||||
/* Get a character from the buffer */
|
||||
{
|
||||
PRECONDITION (Index < B->Len);
|
||||
return B->Buf[Index];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void SB_Drop (StrBuf* B, unsigned Count)
|
||||
/* Drop characters from the end of the string. */
|
||||
{
|
||||
@@ -263,27 +241,6 @@ void SB_CopyBufCooked (StrBuf* Target, const char* Buf, const char* Cooked, unsi
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void SB_CopyStr (StrBuf* Target, const char* S)
|
||||
/* Copy S to Target, discarding the old contents of Target */
|
||||
{
|
||||
SB_CopyBuf (Target, S, strlen (S));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void SB_Copy (StrBuf* Target, const StrBuf* Source)
|
||||
/* Copy Source to Target, discarding the old contents of Target */
|
||||
{
|
||||
SB_CopyBufCooked (Target, Source->Buf, Source->Cooked, Source->Len);
|
||||
Target->Index = Source->Index;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void SB_AppendChar (StrBuf* B, int C)
|
||||
/* Append a character to a string buffer */
|
||||
{
|
||||
@@ -326,46 +283,6 @@ void SB_AppendBuf (StrBuf* B, const char* S, unsigned Size)
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void SB_AppendStr (StrBuf* B, const char* S)
|
||||
/* Append a string to the end of the string buffer */
|
||||
{
|
||||
SB_AppendBuf (B, S, strlen (S));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void SB_Append (StrBuf* Target, const StrBuf* Source)
|
||||
/* Append the contents of Source to Target */
|
||||
{
|
||||
unsigned NewLen = Target->Len + Source->Len;
|
||||
if (NewLen > Target->Allocated) {
|
||||
SB_Realloc (Target, NewLen);
|
||||
}
|
||||
memcpy (Target->Buf + Target->Len, Source->Buf, Source->Len);
|
||||
memcpy (Target->Cooked + Target->Len, Source->Cooked, Source->Len);
|
||||
Target->Len = NewLen;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void SB_Cut (StrBuf* B, unsigned Len)
|
||||
/* Cut the contents of B at the given length. If the current length of the
|
||||
** buffer is smaller than Len, nothing will happen.
|
||||
*/
|
||||
{
|
||||
if (Len < B->Len) {
|
||||
B->Len = Len;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void SB_Slice (StrBuf* Target, const StrBuf* Source, unsigned Start, unsigned Len)
|
||||
/* Copy a slice from Source into Target. The current contents of Target are
|
||||
** destroyed. If Start is greater than the length of Source, or if Len
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
/* common */
|
||||
#include "attrib.h"
|
||||
#include "check.h"
|
||||
#include "inline.h"
|
||||
|
||||
|
||||
|
||||
@@ -89,16 +88,12 @@ extern const StrBuf EmptyStrBuf;
|
||||
|
||||
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE StrBuf* SB_Init (StrBuf* B)
|
||||
static inline StrBuf* SB_Init (StrBuf* B)
|
||||
/* Initialize a string buffer */
|
||||
{
|
||||
*B = EmptyStrBuf;
|
||||
return B;
|
||||
}
|
||||
#else
|
||||
StrBuf* SB_Init (StrBuf* B);
|
||||
#endif
|
||||
|
||||
StrBuf* SB_InitFromString (StrBuf* B, const char* S);
|
||||
/* Initialize a string buffer from a literal string. Beware: The buffer won't
|
||||
@@ -121,200 +116,126 @@ void SB_Realloc (StrBuf* B, unsigned NewSize);
|
||||
** available.
|
||||
*/
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned SB_GetLen (const StrBuf* B)
|
||||
static inline unsigned SB_GetLen (const StrBuf* B)
|
||||
/* Return the length of the buffer contents */
|
||||
{
|
||||
return B->Len;
|
||||
}
|
||||
#else
|
||||
# define SB_GetLen(B) (B)->Len
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned SB_GetIndex (const StrBuf* B)
|
||||
static inline unsigned SB_GetIndex (const StrBuf* B)
|
||||
/* Return the user index of the string buffer */
|
||||
{
|
||||
return B->Index;
|
||||
}
|
||||
#else
|
||||
# define SB_GetIndex(B) (B)->Index
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_SetIndex (StrBuf* B, unsigned Index)
|
||||
static inline void SB_SetIndex (StrBuf* B, unsigned Index)
|
||||
/* Set the user index of the string buffer */
|
||||
{
|
||||
B->Index = Index;
|
||||
}
|
||||
#else
|
||||
# define SB_SetIndex(B, Idx) ((B)->Index = (Idx))
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE const char* SB_GetConstBuf (const StrBuf* B)
|
||||
static inline const char* SB_GetConstBuf (const StrBuf* B)
|
||||
/* Return a buffer pointer */
|
||||
{
|
||||
return B->Buf;
|
||||
}
|
||||
#else
|
||||
# define SB_GetConstBuf(B) (B)->Buf
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char* SB_GetBuf (StrBuf* B)
|
||||
static inline char* SB_GetBuf (StrBuf* B)
|
||||
/* Return a buffer pointer */
|
||||
{
|
||||
return B->Buf;
|
||||
}
|
||||
#else
|
||||
# define SB_GetBuf(B) (B)->Buf
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char* SB_GetCooked (StrBuf* B)
|
||||
static inline char* SB_GetCooked (StrBuf* B)
|
||||
/* Return a cooked pointer */
|
||||
{
|
||||
return B->Cooked;
|
||||
}
|
||||
#else
|
||||
# define SB_GetCooked(B) (B)->Cooked
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_At (const StrBuf* B, unsigned Index)
|
||||
static inline char SB_At (const StrBuf* B, unsigned Index)
|
||||
/* Get a character from the buffer */
|
||||
{
|
||||
PRECONDITION (Index < B->Len);
|
||||
return B->Buf[Index];
|
||||
}
|
||||
#else
|
||||
char SB_At (const StrBuf* B, unsigned Index);
|
||||
/* Get a character from the buffer */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_AtUnchecked (const StrBuf* B, unsigned Index)
|
||||
static inline char SB_AtUnchecked (const StrBuf* B, unsigned Index)
|
||||
/* Get a character from the buffer */
|
||||
{
|
||||
return B->Buf[Index];
|
||||
}
|
||||
#else
|
||||
# define SB_AtUnchecked(B, Index) ((B)->Buf[Index])
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int SB_IsEmpty (const StrBuf* B)
|
||||
static inline int SB_IsEmpty (const StrBuf* B)
|
||||
/* Return true if the string buffer is empty */
|
||||
{
|
||||
return (B->Len == 0);
|
||||
}
|
||||
#else
|
||||
# define SB_IsEmpty(B) ((B)->Len == 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int SB_NotEmpty (const StrBuf* B)
|
||||
static inline int SB_NotEmpty (const StrBuf* B)
|
||||
/* Return true if the string buffer is not empty */
|
||||
{
|
||||
return (B->Len > 0);
|
||||
}
|
||||
#else
|
||||
# define SB_NotEmpty(B) ((B)->Len > 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Clear (StrBuf* B)
|
||||
static inline void SB_Clear (StrBuf* B)
|
||||
/* Clear the string buffer (make it empty) */
|
||||
{
|
||||
B->Len = B->Index = 0;
|
||||
}
|
||||
#else
|
||||
# define SB_Clear(B) ((B)->Len = (B)->Index = 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Reset (StrBuf* B)
|
||||
static inline void SB_Reset (StrBuf* B)
|
||||
/* Reset the string buffer index to zero */
|
||||
{
|
||||
B->Index = 0;
|
||||
}
|
||||
#else
|
||||
# define SB_Reset(B) ((B)->Index = 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_Get (StrBuf* B)
|
||||
static inline char SB_Get (StrBuf* B)
|
||||
/* Return the next character from the string incrementing Index. Returns NUL
|
||||
** if the end of the string is reached.
|
||||
*/
|
||||
{
|
||||
return (B->Index < B->Len)? B->Buf[B->Index++] : '\0';
|
||||
}
|
||||
#else
|
||||
# define SB_Get(B) (((B)->Index < (B)->Len)? (B)->Buf[(B)->Index++] : '\0')
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_Peek (const StrBuf* B)
|
||||
static inline char SB_Peek (const StrBuf* B)
|
||||
/* Look at the next character from the string without incrementing Index.
|
||||
** Returns NUL if the end of the string is reached.
|
||||
*/
|
||||
{
|
||||
return (B->Index < B->Len)? B->Buf[B->Index] : '\0';
|
||||
}
|
||||
#else
|
||||
# define SB_Peek(B) (((B)->Index < (B)->Len)? (B)->Buf[(B)->Index] : '\0')
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_LookAt (const StrBuf* B, unsigned Index)
|
||||
static inline char SB_LookAt (const StrBuf* B, unsigned Index)
|
||||
/* Look at a specific character from the string. Returns NUL if the given
|
||||
** index is greater than the size of the string.
|
||||
*/
|
||||
{
|
||||
return (Index < B->Len)? B->Buf[Index] : '\0';
|
||||
}
|
||||
#else
|
||||
# define SB_LookAt(B,Index) (((Index) < (B)->Len)? (B)->Buf[(Index)] : '\0')
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_LookAtLast (const StrBuf* B)
|
||||
static inline char SB_LookAtLast (const StrBuf* B)
|
||||
/* Look at the last character from the string. Returns NUL if the string buffer
|
||||
** is empty.
|
||||
*/
|
||||
{
|
||||
return (B->Len > 0)? B->Buf[B->Len-1] : '\0';
|
||||
}
|
||||
#else
|
||||
# define SB_LookAtLast(B) (((B)->Len > 0)? (B)->Buf[(B)->Len-1] : '\0')
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Skip (StrBuf* B)
|
||||
static inline void SB_Skip (StrBuf* B)
|
||||
/* Skip the next character in the string buffer if this is possible. */
|
||||
{
|
||||
if (B->Index < B->Len) {
|
||||
++B->Index;
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define SB_Skip(B) do { if ((B)->Index < (B)->Len) ++(B)->Index; } while (0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_SkipMultiple (StrBuf* B, unsigned Count)
|
||||
static inline void SB_SkipMultiple (StrBuf* B, unsigned Count)
|
||||
/* Skip a number of characters in the string buffer if this is possible. */
|
||||
{
|
||||
if ((B->Index += Count) > B->Len) {
|
||||
B->Index = B->Len;
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define SB_SkipMultiple(B, Count) \
|
||||
do { if (((B)->Index += (Count)) > (B)->Len) (B)->Index = (B)->Len; } while (0)
|
||||
#endif
|
||||
|
||||
void SB_Drop (StrBuf* B, unsigned Count);
|
||||
/* Drop characters from the end of the string. */
|
||||
@@ -330,28 +251,18 @@ void SB_CopyBuf (StrBuf* Target, const char* Buf, unsigned Size);
|
||||
void SB_CopyBufCooked (StrBuf* Target, const char* Buf, const char *Cooked, unsigned Size);
|
||||
/* Copy Buf and Cooked to Target, discarding the old contents of Target */
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_CopyStr (StrBuf* Target, const char* S)
|
||||
static inline void SB_CopyStr (StrBuf* Target, const char* S)
|
||||
/* Copy S to Target, discarding the old contents of Target */
|
||||
{
|
||||
SB_CopyBuf (Target, S, strlen (S));
|
||||
SB_CopyBuf (Target, S, (unsigned)strlen (S));
|
||||
}
|
||||
#else
|
||||
void SB_CopyStr (StrBuf* Target, const char* S);
|
||||
/* Copy S to Target, discarding the old contents of Target */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Copy (StrBuf* Target, const StrBuf* Source)
|
||||
static inline void SB_Copy (StrBuf* Target, const StrBuf* Source)
|
||||
/* Copy Source to Target, discarding the old contents of Target */
|
||||
{
|
||||
SB_CopyBufCooked (Target, Source->Buf, Source->Cooked, Source->Len);
|
||||
Target->Index = Source->Index;
|
||||
}
|
||||
#else
|
||||
void SB_Copy (StrBuf* Target, const StrBuf* Source);
|
||||
/* Copy Source to Target, discarding the old contents of Target */
|
||||
#endif
|
||||
|
||||
void SB_AppendChar (StrBuf* B, int C);
|
||||
/* Append a character to a string buffer */
|
||||
@@ -362,19 +273,13 @@ void SB_AppendCharCooked (StrBuf* B, int C, int Cooked);
|
||||
void SB_AppendBuf (StrBuf* B, const char* S, unsigned Size);
|
||||
/* Append a character buffer to the end of the string buffer */
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_AppendStr (StrBuf* B, const char* S)
|
||||
static inline void SB_AppendStr (StrBuf* B, const char* S)
|
||||
/* Append a string to the end of the string buffer */
|
||||
{
|
||||
SB_AppendBuf (B, S, strlen (S));
|
||||
SB_AppendBuf (B, S, (unsigned)strlen (S));
|
||||
}
|
||||
#else
|
||||
void SB_AppendStr (StrBuf* B, const char* S);
|
||||
/* Append a string to the end of the string buffer */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Append (StrBuf* Target, const StrBuf* Source)
|
||||
static inline void SB_Append (StrBuf* Target, const StrBuf* Source)
|
||||
/* Append the contents of Source to Target */
|
||||
{
|
||||
unsigned NewLen = Target->Len + Source->Len;
|
||||
@@ -385,13 +290,8 @@ INLINE void SB_Append (StrBuf* Target, const StrBuf* Source)
|
||||
memcpy (Target->Cooked + Target->Len, Source->Cooked, Source->Len);
|
||||
Target->Len = NewLen;
|
||||
}
|
||||
#else
|
||||
void SB_Append (StrBuf* Target, const StrBuf* Source);
|
||||
/* Append the contents of Source to Target */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Cut (StrBuf* B, unsigned Len)
|
||||
static inline void SB_Cut (StrBuf* B, unsigned Len)
|
||||
/* Cut the contents of B at the given length. If the current length of the
|
||||
** buffer is smaller than Len, nothing will happen.
|
||||
*/
|
||||
@@ -400,12 +300,6 @@ INLINE void SB_Cut (StrBuf* B, unsigned Len)
|
||||
B->Len = Len;
|
||||
}
|
||||
}
|
||||
#else
|
||||
void SB_Cut (StrBuf* B, unsigned Len);
|
||||
/* Cut the contents of B at the given length. If the current length of the
|
||||
** buffer is smaller than Len, nothing will happen.
|
||||
*/
|
||||
#endif
|
||||
|
||||
void SB_Slice (StrBuf* Target, const StrBuf* Source, unsigned Start, unsigned Len);
|
||||
/* Copy a slice from Source into Target. The current contents of Target are
|
||||
|
||||
@@ -38,10 +38,6 @@
|
||||
|
||||
|
||||
|
||||
#include "inline.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
@@ -65,25 +61,17 @@ struct StrStack {
|
||||
|
||||
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int SS_IsFull (const StrStack* S)
|
||||
static inline int SS_IsFull (const StrStack* S)
|
||||
/* Return true if there is no space left on the given string stack */
|
||||
{
|
||||
return (S->Count >= sizeof (S->Stack) / sizeof (S->Stack[0]));
|
||||
}
|
||||
#else
|
||||
# define SS_IsFull(S) ((S)->Count >= sizeof ((S)->Stack) / sizeof ((S)->Stack[0]))
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned SS_GetCount (const StrStack* S)
|
||||
static inline unsigned SS_GetCount (const StrStack* S)
|
||||
/* Return the number of elements on the given string stack */
|
||||
{
|
||||
return S->Count;
|
||||
}
|
||||
#else
|
||||
# define SS_GetCount(S) (S)->Count
|
||||
#endif
|
||||
|
||||
const char* SS_Get (const StrStack* S);
|
||||
/* Get the value on top of a string stack */
|
||||
|
||||
Reference in New Issue
Block a user