/* */
/* */
/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2001 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
static void DefaultCheckFailed (const char* msg, const char* cond,
- int code, const char* file, unsigned line)
+ const char* file, unsigned line)
attribute ((noreturn));
-void (*CheckFailed) (const char* Msg, const char* Cond, int Code,
+void (*CheckFailed) (const char* Msg, const char* Cond,
const char* File, unsigned Line) attribute ((noreturn))
= DefaultCheckFailed;
/* Function pointer that is called from check if the condition code is true. */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
static void DefaultCheckFailed (const char* Msg, const char* Cond,
- int Code, const char* File, unsigned Line)
+ const char* File, unsigned Line)
{
- /* Log the error */
- if (Code) {
- AbEnd ("%s%s (= %d), file `%s', line %u", Msg, Cond, Code, File, Line);
- } else {
- AbEnd ("%s%s, file `%s', line %u", Msg, Cond, File, Line);
- }
-}
-
-
-
-void Check (const char* Msg, const char* Cond, int Code,
- const char* File, unsigned Line)
-/* This function is called from all check macros (see below). It checks,
- * wether the given Code is true (!= 0). If so, it calls the CheckFailed
- * vector with the given strings. If not, it simply returns.
- */
-{
- if (Code != 0) {
- CheckFailed (Msg, Cond, Code, File, Line);
- }
+ /* Output a diagnostic and abort */
+ AbEnd ("%s%s, file `%s', line %u", Msg, Cond, File, Line);
}
/* */
/* */
/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2001 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
extern void (*CheckFailed) (const char* Msg, const char* Cond,
- int Code, const char* File, unsigned Line)
+ const char* File, unsigned Line)
attribute ((noreturn));
/* Function pointer that is called from check if the condition code is true. */
-void Check (const char* Msg, const char* Cond, int Code,
- const char* File, unsigned Line);
-/* This function is called from all check macros (see below). It checks,
- * wether the given Code is true (!= 0). If so, it calls the CheckFailed
- * vector with the given strings. If not, it simply returns.
- */
-
-
-
-#define FAIL(s) CheckFailed (MsgInternalError, s, 0, __FILE__, __LINE__)
+#define FAIL(s) CheckFailed (MsgInternalError, s, __FILE__, __LINE__)
/* Fail macro. Is used if something evil happens, calls checkfailed directly. */
-#define ABORT(s) CheckFailed (MsgProgramAborted, s, 0, __FILE__, __LINE__)
+#define ABORT(s) CheckFailed (MsgProgramAborted, s, __FILE__, __LINE__)
/* Use this one instead of FAIL if there is no internal program error but an
* error condition that is caused by the user or operating system (FAIL and
* ABORT are essentially the same but the message differs).
*/
-#define PRECONDITION(c) Check (MsgPrecondition, #c, !(c), __FILE__, __LINE__)
-
-#define CHECK(c) Check (MsgCheckFailed, #c, !(c), __FILE__, __LINE__)
+#define PRECONDITION(c) \
+ { if (!(c)) CheckFailed (MsgPrecondition, #c, __FILE__, __LINE__); }
-#define ZCHECK(c) Check (MsgCheckFailed, #c, c, __FILE__, __LINE__)
+#define CHECK(c) \
+ { if (!(c)) CheckFailed (MsgCheckFailed, #c, __FILE__, __LINE__); }
-unsigned CollCount (const Collection* C)
-/* Return the number of items in the collection */
-{
- return C->Count;
-}
-
-
-
void CollInsert (Collection* C, void* Item, unsigned Index)
/* Insert the data at the given position in the collection */
{
-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);
-}
-
-
-
-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];
-}
-
-
-
-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];
-}
-
-
-
-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];
-}
-
-
-
-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];
-}
-
-
-
-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];
-}
-
-
-
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.
-void CollDeleteAll (Collection* C)
-/* Delete all items from the given collection. This will not free the items
- * itself, it will only remove the pointers.
- */
-{
- /* This one is easy... */
- C->Count = 0;
-}
-
-
-
-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 et replaced.
- */
-{
- /* Check the index */
- PRECONDITION (Index < C->Count);
-
- /* Replace the item pointer */
- C->Items[Index] = Item;
-}
-
-
-
static void QuickSort (Collection* C, int Lo, int Hi,
int (*Compare) (void*, const void*, const void*),
void* Data)
+/* common */
#include "attrib.h"
+#include "cfeature.h"
+#include "check.h"
void FreeCollection (Collection* C);
/* Free a collection */
-unsigned CollCount (const Collection* C);
+#if defined(HAVE_INLINE)
+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 */
-void CollAppend (Collection* C, void* Item);
+#if defined(HAVE_INLINE)
+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
+# define CollAppend(C, Item) CollInsert (C, Item, (C)->Count)
+#endif
+
+#if defined(HAVE_INLINE)
+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];
+}
+#else
+# define CollAt(C, Index) \
+ (PRECONDITION ((Index) < (C)->Count), \
+ (C)->Items[(Index)])
+#endif
-void* CollAt (Collection* C, unsigned Index) attribute ((const));
+#if defined(HAVE_INLINE)
+INLINE void* CollAtUnchecked (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
-const void* CollConstAt (const Collection* C, unsigned Index) attribute ((const));
+#if defined(HAVE_INLINE)
+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];
+}
+#else
+# define CollConstAt(C, Index) \
+ (PRECONDITION ((Index) < (C)->Count), \
+ (C)->Items[(Index)])
+#endif
-void* CollLast (Collection* C);
+#if defined(HAVE_INLINE)
+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];
+}
+#else
+# define CollLast(C) \
+ (PRECONDITION ((C)->Count > 0), \
+ (C)->Items[(C)->Count-1])
+#endif
-const void* CollConstLast (const Collection* C);
+#if defined(HAVE_INLINE)
+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];
+}
+#else
+# define CollConstLast(C) \
+ (PRECONDITION ((C)->Count > 0), \
+ (C)->Items[(C)->Count-1])
+#endif
-void* CollPop (Collection* C);
+#if defined(HAVE_INLINE)
+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];
+}
+#else
+# define CollPop(C) \
+ (PRECONDITION ((C)->Count > 0), \
+ (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
* collection, otherwise FAIL will be called.
*/
-void CollDeleteAll (Collection* C);
+#if defined(HAVE_INLINE)
+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.
*/
+{
+ /* This one is easy... */
+ C->Count = 0;
+}
+#else
+# define CollDeleteAll(C) ((C)->Count = 0)
+#endif
-void CollReplace (Collection* C, void* Item, unsigned Index);
+#if defined(HAVE_INLINE)
+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 et replaced.
*/
+{
+ /* Check the index */
+ PRECONDITION (Index < C->Count);
+
+ /* Replace the item pointer */
+ C->Items[Index] = Item;
+}
+#else
+# define CollReplace(C, Item, Index) \
+ (PRECONDITION ((Index) < (C)->Count), \
+ (C)->Items[(Index)] = (Item))
+#endif
void CollSort (Collection* C,
int (*Compare) (void*, const void*, const void*),
--- /dev/null
+/*****************************************************************************/
+/* */
+/* cfeature.h */
+/* */
+/* Define compiler features */
+/* */
+/* */
+/* */
+/* (C) 2001 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* 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 CFEATURE_H
+#define CFEATURE_H
+
+
+
+/*****************************************************************************/
+/* Defines */
+/*****************************************************************************/
+
+
+
+#if defined(__GNUC__)
+# define HAVE_INLINE 1
+# define INLINE static __inline__
+#endif
+
+
+
+/* End of cfeature.h */
+
+#endif
+
+
+