1
0
Fork 0
Browse Source

Refactoring, part 2

Now with conditional compilation macros.
master
Alison Watson 6 years ago
parent
commit
0446080176
  1. 4
      lithos_c/inc/Lth_hashmap.h
  2. 32
      lithos_c/inc/Lth_libinfo.h
  3. 106
      lithos_c/inc/Lth_linklist.h
  4. 4
      lithos_c/inc/Lth_manifest.h
  5. 4
      lithos_c/inc/Lth_stdlib.h
  6. 4
      lithos_c/inc/Lth_token.h
  7. 4
      lithos_c/inc/Lth_tokenstream.h
  8. 5
      lithos_c/src/manifest.c
  9. 6
      lithos_c/src/stdlib.c
  10. 6
      lithos_c/src/token.c
  11. 6
      lithos_c/src/tokenstream.c

4
lithos_c/inc/Lth_hashmap.h

@ -12,7 +12,9 @@
//
//-----------------------------------------------------------------------------
#ifndef lithos3__Lth_hashmap_h
#include "Lth_libinfo.h"
#if !defined(lithos3__Lth_hashmap_h) && !LITHOS3_NO_HASHMAP
#define lithos3__Lth_hashmap_h
#include "Lth_stdlib.h"

32
lithos_c/inc/Lth_libinfo.h

@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
//
// Copyright © 2017 Project Golan
//
// See "LICENSE.lithos3" for more information.
//
//-----------------------------------------------------------------------------
//
// Library setup.
//
//-----------------------------------------------------------------------------
#if LITHOS3_NO_STDLIB
# define LITHOS3_NO_HASHMAP 1
# define LITHOS3_NO_TOKEN 1
# define LITHOS3_NO_TOKENSTREAM 1
# define LITHOS3_NO_MANIFEST 1
#endif
#if LITHOS3_NO_HASHMAP
# define LITHOS3_NO_MANIFEST 1
#endif
#if LITHOS3_NO_TOKEN
# define LITHOS3_NO_TOKENSTREAM 1
#endif
#if LITHOS3_NO_TOKENSTREAM
# define LITHOS3_NO_MANIFEST 1
#endif
// EOF

106
lithos_c/inc/Lth_linklist.h

@ -1,106 +0,0 @@
//-----------------------------------------------------------------------------
//
// Copyright © 2016-2017 Project Golan
//
// See "LICENSE.lithos3" for more information.
//
//-----------------------------------------------------------------------------
//
// Doubly linked list structure.
//
//-----------------------------------------------------------------------------
#ifndef lithos3__Lth_linklist_h
#define lithos3__Lth_linklist_h
#define Lth_ListForEach(tmpv, lst) \
for(Lth_LinkList *list = (lst); list; list = list->next) \
__with(tmpv = list->owner;)
#define Lth_ListFor(tmpv, lst) \
for(Lth_LinkList *list = (lst); list;) \
__with(Lth_LinkList *next = list->next, **prev = list->prev; \
tmpv = list->owner;)
#define Lth_ListInsert(list, object, head) \
(void) \
( \
Lth_ListLink((list), (head)), \
(list)->owner = object \
)
#define Lth_ListInsertTail(list, object, head, tail) \
(void) \
( \
Lth_ListLinkTail((list), (head), (tail)), \
(list)->owner = object \
)
#define Lth_ListMove(list, head) \
(void) \
( \
Lth_ListRemove((list)), \
Lth_ListLink((list), (head)) \
)
// Type Definitions ----------------------------------------------------------|
//
// Lth_LinkList
//
typedef struct Lth_LinkList
{
struct Lth_LinkList *next, **prev;
void *owner;
} Lth_LinkList;
// Static Functions ----------------------------------------------------------|
//
// Lth_ListLink
//
static inline void Lth_ListLink(Lth_LinkList *list, Lth_LinkList **head)
{
Lth_LinkList *next = *head;
if((list->next = next))
next->prev = &list->next;
list->prev = head;
*head = list;
}
//
// Lth_ListLinkTail
//
static inline void Lth_ListLinkTail(Lth_LinkList *list, Lth_LinkList **head,
Lth_LinkList **tail)
{
Lth_LinkList *prev = *tail;
if(*(list->prev = head))
list->prev = &prev->next;
else
*head = list;
prev->next = list;
*tail = list;
}
//
// Lth_ListRemove
//
static inline void Lth_ListRemove(Lth_LinkList *list)
{
Lth_LinkList *next = list->next, **prev = list->prev;
if(prev && (*prev = next))
next->prev = prev;
list->next = NULL;
list->prev = NULL;
}
#endif//lithos3__Lth_linklist_h

4
lithos_c/inc/Lth_manifest.h

@ -10,7 +10,9 @@
//
//-----------------------------------------------------------------------------
#ifndef lithos3__Lth_manifest_h
#include "Lth_libinfo.h"
#if !defined(lithos3__Lth_manifest_h) && !LITHOS3_NO_MANIFEST
#define lithos3__Lth_manifest_h
#include "Lth_types.h"

4
lithos_c/inc/Lth_stdlib.h

@ -10,7 +10,9 @@
//
//-----------------------------------------------------------------------------
#ifndef lithos3__Lth_stdlib_h
#include "Lth_libinfo.h"
#if !defined(lithos3__Lth_stdlib_h) && !LITHOS3_NO_STDLIB
#define lithos3__Lth_stdlib_h
#include "Lth_types.h"

4
lithos_c/inc/Lth_token.h

@ -14,6 +14,8 @@
//
//-----------------------------------------------------------------------------
#include "Lth_libinfo.h"
#if defined(Lth_X)
Lth_X(ChrSeq)
@ -34,7 +36,7 @@ Lth_X(LnEnd ) // \n
#undef Lth_X
#elif !defined(lithos3__Lth_token_h)
#elif !defined(lithos3__Lth_token_h) && !LITHOS3_NO_TOKEN
#define lithos3__Lth_token_h
#include <stdio.h>

4
lithos_c/inc/Lth_tokenstream.h

@ -10,7 +10,9 @@
//
//-----------------------------------------------------------------------------
#ifndef lithos3__Lth_tokenstream_h
#include "Lth_libinfo.h"
#if !defined(lithos3__Lth_tokenstream_h) && !LITHOS3_NO_TOKENSTREAM
#define lithos3__Lth_tokenstream_h
#include "Lth_token.h"

5
lithos_c/src/manifest.c

@ -10,6 +10,9 @@
//
//-----------------------------------------------------------------------------
#include "Lth_libinfo.h"
#if !LITHOS3_NO_MANIFEST
#include "Lth.h"
#include <stdbool.h>
@ -448,4 +451,4 @@ Lth_Manifest Lth_ManifestNew_Strng(char const *key, char const *value)
return GenManifestValue(Strng, strng, Lth_strdup(value));
}
// EOF
#endif//LITHOS3_NO_MANIFEST

6
lithos_c/src/stdlib.c

@ -10,6 +10,10 @@
//
//-----------------------------------------------------------------------------
#include "Lth_libinfo.h"
#if !LITHOS3_NO_STDLIB
#include "Lth.h"
#include <GDCC.h>
@ -253,4 +257,4 @@ size_t Lth_Hash_wchar(wchar_t const *s)
return ret;
}
// EOF
#endif//LITHOS3_NO_STDLIB

6
lithos_c/src/token.c

@ -12,6 +12,10 @@
//
//-----------------------------------------------------------------------------
#include "Lth_libinfo.h"
#if !LITHOS3_NO_TOKEN
#define _GNU_SOURCE
#include "Lth.h"
@ -149,4 +153,4 @@ char const *Lth_TokenName(Lth_TokenType type)
return names[type];
}
// EOF
#endif//LITHOS3_NO_TOKEN

6
lithos_c/src/tokenstream.c

@ -12,6 +12,10 @@
//
//-----------------------------------------------------------------------------
#include "Lth_libinfo.h"
#if !LITHOS3_NO_TOKENSTREAM
#define _GNU_SOURCE
#include "Lth.h"
@ -215,4 +219,4 @@ bool Lth_TokenStreamDrop(Lth_TokenStream *stream, Lth_TokenType tt)
return false;
}
// EOF
#endif//LITHOS3_NO_TOKENSTREAM

Loading…
Cancel
Save