Files
discount/cstring.h
T
david parsons c27ea14dd6 Import a mass of changes from boobook
1. Add the new method mkd_string(), which assembles a list from a string.
2. Add a tests directory and three test files.
3. Move the smartypants code out into a separate function, so I can
   (eventually) pass a /don't_be_clever/ flag in to the markdown()
   function.
4. Redo the mail address mangler so I can mangle the
   mailto: as well as the address.
5. Fix a bug in the DELETE() macro in cstring.h
6. Fix dependencies in the Makefile so that a reconfigure forces a
   complete recompile.
7. Code tweaks to make gcc stfu
8. Tweak the build dependencies again.
2007-12-21 12:03:00 -08:00

50 lines
1.5 KiB
C

/* two template types: STRING(t) which defines a pascal-style string
* of element (t) [STRING(char) is the closest to the pascal string],
* and ANCHOR(t) which defines a baseplate that a linked list can be
* built up from. [The linked list /must/ contain a ->next pointer
* for linking the list together with.]
*/
#ifndef _CSTRING_D
#define _CSTRING_D
#include <stdlib.h>
/* expandable Pascal-style string.
*/
#define STRING(type) struct { type *text; int size, alloc; }
#define RESERVE(x,c) (x).text = malloc(sizeof T(x)[0] * (((x).size=0),((x).alloc=(c))) )
#define CREATE(x) RESERVE(x,100)
#define EXPAND(x) (x).text[((x).size < (x).alloc \
? 0 \
: !((x).text = realloc((x).text, sizeof T(x)[0] * ((x).alloc += 100)))), \
(x).size++]
#define DELETE(x) (x).alloc ? (free(T(x)), S(x) = (x).alloc = 0) \
: ( S(x) = 0 )
#define CLIP(t,i,sz) \
( ((i) >= 0) && ((sz) > 0) && (((i)+(sz)) <= S(t)) ) ? \
(memmove(&T(t)[i], &T(t)[i+sz], (S(t)-(i+sz)+1)*sizeof(T(t)[0])), \
S(t) -= (sz)) : -1
/* reference-style links (and images) are stored in an array
*/
#define T(x) (x).text
#define S(x) (x).size
/* abstract anchor type that defines a list base
* with a function that attaches an element to
* the end of the list.
*
* the list base field is named .text so that the T()
* macro will work with it.
*/
#define ANCHOR(t) struct { t *text, *end; }
#define ATTACH(t, p) ( (t).text ?( ((t).end->next = (p)), ((t).end = (p)) ) \
:( ((t).text = (t).end = (p)) ) )
typedef STRING(char) Cstring;
#endif/*_CSTRING_D*/