Fixed problems with the inline macros
git-svn-id: svn://svn.cc65.org/cc65/trunk@1040 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -116,22 +116,22 @@ void CollInsert (Collection* C, void* Item, unsigned Index)
|
|||||||
|
|
||||||
/* Grow the array if necessary */
|
/* Grow the array if necessary */
|
||||||
if (C->Count >= C->Size) {
|
if (C->Count >= C->Size) {
|
||||||
/* Must grow */
|
/* Must grow */
|
||||||
void** NewItems;
|
void** NewItems;
|
||||||
if (C->Size > 0) {
|
if (C->Size > 0) {
|
||||||
C->Size *= 2;
|
C->Size *= 2;
|
||||||
} else {
|
} else {
|
||||||
C->Size = 8;
|
C->Size = 8;
|
||||||
}
|
}
|
||||||
NewItems = xmalloc (C->Size * sizeof (void*));
|
NewItems = xmalloc (C->Size * sizeof (void*));
|
||||||
memcpy (NewItems, C->Items, C->Count * sizeof (void*));
|
memcpy (NewItems, C->Items, C->Count * sizeof (void*));
|
||||||
xfree (C->Items);
|
xfree (C->Items);
|
||||||
C->Items = NewItems;
|
C->Items = NewItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the existing elements if needed */
|
/* Move the existing elements if needed */
|
||||||
if (C->Count != Index) {
|
if (C->Count != Index) {
|
||||||
memmove (C->Items+Index+1, C->Items+Index, (C->Count-Index) * sizeof (void*));
|
memmove (C->Items+Index+1, C->Items+Index, (C->Count-Index) * sizeof (void*));
|
||||||
}
|
}
|
||||||
++C->Count;
|
++C->Count;
|
||||||
|
|
||||||
@@ -141,6 +141,89 @@ 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 (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)
|
int CollIndex (Collection* C, const void* Item)
|
||||||
/* Return the index of the given item in the collection. Return -1 if the
|
/* Return the index of the given item in the collection. Return -1 if the
|
||||||
* item was not found in the collection.
|
* item was not found in the collection.
|
||||||
@@ -149,9 +232,9 @@ int CollIndex (Collection* C, const void* Item)
|
|||||||
/* Linear search */
|
/* Linear search */
|
||||||
unsigned I;
|
unsigned I;
|
||||||
for (I = 0; I < C->Count; ++I) {
|
for (I = 0; I < C->Count; ++I) {
|
||||||
if (Item == C->Items[I]) {
|
if (Item == C->Items[I]) {
|
||||||
/* Found */
|
/* Found */
|
||||||
return (int)I;
|
return (int)I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +276,22 @@ 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 CollMove (Collection* C, unsigned OldIndex, unsigned NewIndex)
|
void CollMove (Collection* C, unsigned OldIndex, unsigned NewIndex)
|
||||||
/* Move an item from one position in the collection to another. OldIndex
|
/* Move an item from one position in the collection to another. OldIndex
|
||||||
* is the current position of the item, NewIndex is the new index after
|
* is the current position of the item, NewIndex is the new index after
|
||||||
|
|||||||
@@ -111,7 +111,8 @@ INLINE void CollAppend (Collection* C, void* Item)
|
|||||||
CollInsert (C, Item, C->Count);
|
CollInsert (C, Item, C->Count);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define CollAppend(C, Item) CollInsert (C, Item, (C)->Count)
|
void CollAppend (Collection* C, void* Item);
|
||||||
|
/* Append an item to the end of the collection */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -125,9 +126,8 @@ INLINE void* CollAt (Collection* C, unsigned Index)
|
|||||||
return C->Items[Index];
|
return C->Items[Index];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define CollAt(C, Index) \
|
void* CollAt (Collection* C, unsigned Index);
|
||||||
(PRECONDITION ((Index) < (C)->Count), \
|
/* Return the item at the given index */
|
||||||
(C)->Items[(Index)])
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -152,9 +152,8 @@ INLINE const void* CollConstAt (const Collection* C, unsigned Index)
|
|||||||
return C->Items[Index];
|
return C->Items[Index];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define CollConstAt(C, Index) \
|
const void* CollConstAt (const Collection* C, unsigned Index);
|
||||||
(PRECONDITION ((Index) < (C)->Count), \
|
/* Return the item at the given index */
|
||||||
(C)->Items[(Index)])
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -168,9 +167,8 @@ INLINE void* CollLast (Collection* C)
|
|||||||
return C->Items[C->Count-1];
|
return C->Items[C->Count-1];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define CollLast(C) \
|
void* CollLast (Collection* C);
|
||||||
(PRECONDITION ((C)->Count > 0), \
|
/* Return the last item in a collection */
|
||||||
(C)->Items[(C)->Count-1])
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -184,9 +182,8 @@ INLINE const void* CollConstLast (const Collection* C)
|
|||||||
return C->Items[C->Count-1];
|
return C->Items[C->Count-1];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define CollConstLast(C) \
|
const void* CollConstLast (const Collection* C);
|
||||||
(PRECONDITION ((C)->Count > 0), \
|
/* Return the last item in a collection */
|
||||||
(C)->Items[(C)->Count-1])
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -202,9 +199,10 @@ INLINE void* CollPop (Collection* C)
|
|||||||
return C->Items[--C->Count];
|
return C->Items[--C->Count];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define CollPop(C) \
|
void* CollPop (Collection* C);
|
||||||
(PRECONDITION ((C)->Count > 0), \
|
/* Remove the last segment from the stack and return it. Calls FAIL if the
|
||||||
(C)->Items[--(C)->Count])
|
* collection is empty.
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int CollIndex (Collection* C, const void* Item);
|
int CollIndex (Collection* C, const void* Item);
|
||||||
@@ -239,7 +237,7 @@ INLINE void CollDeleteAll (Collection* C)
|
|||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE void CollReplace (Collection* C, void* Item, unsigned Index)
|
INLINE void CollReplace (Collection* C, void* Item, unsigned Index)
|
||||||
/* Replace the item at the given position. The old item will not be freed,
|
/* Replace the item at the given position. The old item will not be freed,
|
||||||
* just the pointer will et replaced.
|
* just the pointer will get replaced.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Check the index */
|
/* Check the index */
|
||||||
@@ -249,9 +247,10 @@ INLINE void CollReplace (Collection* C, void* Item, unsigned Index)
|
|||||||
C->Items[Index] = Item;
|
C->Items[Index] = Item;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define CollReplace(C, Item, Index) \
|
void CollReplace (Collection* C, void* Item, unsigned Index);
|
||||||
(PRECONDITION ((Index) < (C)->Count), \
|
/* Replace the item at the given position. The old item will not be freed,
|
||||||
(C)->Items[(Index)] = (Item))
|
* just the pointer will get replaced.
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CollMove (Collection* C, unsigned OldIndex, unsigned NewIndex);
|
void CollMove (Collection* C, unsigned OldIndex, unsigned NewIndex);
|
||||||
@@ -280,7 +279,7 @@ void CollSort (Collection* C,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of exprlist.h */
|
/* End of coll.h */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,17 @@ void SB_Realloc (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_Terminate (StrBuf* B)
|
void SB_Terminate (StrBuf* B)
|
||||||
/* Zero terminate the given string buffer. NOTE: The terminating zero is not
|
/* Zero terminate the given string buffer. NOTE: The terminating zero is not
|
||||||
* accounted for in B->Len, if you want that, you have to use AppendChar!
|
* accounted for in B->Len, if you want that, you have to use AppendChar!
|
||||||
@@ -150,6 +161,26 @@ void SB_CopyBuf (StrBuf* Target, const char* Buf, unsigned Size)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#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_CopyBuf (Target, Source->Buf, Source->Len);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SB_AppendChar (StrBuf* B, char C)
|
void SB_AppendChar (StrBuf* B, char C)
|
||||||
/* Append a character to a string buffer */
|
/* Append a character to a string buffer */
|
||||||
{
|
{
|
||||||
@@ -176,6 +207,40 @@ 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 */
|
||||||
|
{
|
||||||
|
SB_AppendBuf (Target, Source->Buf, Source->Len);
|
||||||
|
}
|
||||||
|
#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)
|
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
|
/* 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
|
* destroyed. If Start is greater than the length of Source, or if Len
|
||||||
|
|||||||
@@ -132,9 +132,8 @@ INLINE char SB_At (const StrBuf* B, unsigned Index)
|
|||||||
return B->Buf[Index];
|
return B->Buf[Index];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define SB_At(B, Index) \
|
char SB_At (const StrBuf* B, unsigned Index);
|
||||||
(PRECONDITION ((Index) < (B)->Len), \
|
/* Get a character from the buffer */
|
||||||
(B)->Buf[Index])
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -182,7 +181,8 @@ INLINE void SB_CopyStr (StrBuf* Target, const char* S)
|
|||||||
SB_CopyBuf (Target, S, strlen (S));
|
SB_CopyBuf (Target, S, strlen (S));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define SB_CopyStr(Target, S) SB_CopyBuf (Target, S, strlen (S))
|
void SB_CopyStr (StrBuf* Target, const char* S);
|
||||||
|
/* Copy S to Target, discarding the old contents of Target */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -192,7 +192,8 @@ INLINE void SB_Copy (StrBuf* Target, const StrBuf* Source)
|
|||||||
SB_CopyBuf (Target, Source->Buf, Source->Len);
|
SB_CopyBuf (Target, Source->Buf, Source->Len);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define SB_Copy(Target, Source) SB_CopyBuf (Target, (Source)->Buf, (Source)->Len)
|
void SB_Copy (StrBuf* Target, const StrBuf* Source);
|
||||||
|
/* Copy Source to Target, discarding the old contents of Target */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void SB_AppendChar (StrBuf* B, char C);
|
void SB_AppendChar (StrBuf* B, char C);
|
||||||
@@ -208,7 +209,8 @@ INLINE void SB_AppendStr (StrBuf* B, const char* S)
|
|||||||
SB_AppendBuf (B, S, strlen (S));
|
SB_AppendBuf (B, S, strlen (S));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define SB_AppendStr(B, S) SB_AppendBuf (B, S, strlen (S))
|
void SB_AppendStr (StrBuf* B, const char* S);
|
||||||
|
/* Append a string to the end of the string buffer */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -218,7 +220,8 @@ INLINE void SB_Append (StrBuf* Target, const StrBuf* Source)
|
|||||||
SB_AppendBuf (Target, Source->Buf, Source->Len);
|
SB_AppendBuf (Target, Source->Buf, Source->Len);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define SB_Append(Target, Source) SB_AppendBuf (Target, (Source)->Buf, (Source)->Len)
|
void SB_Append (StrBuf* Target, const StrBuf* Source);
|
||||||
|
/* Append the contents of Source to Target */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
@@ -232,7 +235,10 @@ INLINE void SB_Cut (StrBuf* B, unsigned Len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define SB_Cut(B, L) if ((L) < (B)->Len) { (B)->Len = (L); }
|
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
|
#endif
|
||||||
|
|
||||||
void SB_Slice (StrBuf* Target, const StrBuf* Source, unsigned Start, unsigned Len);
|
void SB_Slice (StrBuf* Target, const StrBuf* Source, unsigned Start, unsigned Len);
|
||||||
|
|||||||
Reference in New Issue
Block a user