// Extended ASCII
-#ifdef USE_EXTENDED_ASCII
+ #ifdef USE_EXTENDED_ASCII
// Punctuation ranges
for (int i = 132; i < 138; ++i) {
punctuation(i);
break;
}
}
-#endif
+ #endif
// Print output as 16 x 16 table
#include <sys/stat.h>
#ifdef USE_CURL
-#include <curl/curl.h>
+ #include <curl/curl.h>
#endif
#include "epub.h"
token * walker = chain->child; // Walk the existing tree
token * remainder; // Hold unparsed tail of chain
-#ifndef NDEBUG
+ #ifndef NDEBUG
ParseTrace(stderr, "parser >>");
-#endif
+ #endif
// Remove existing token tree
e->root = NULL;
if (remainder)
remainder->prev = NULL;
-#ifndef NDEBUG
+ #ifndef NDEBUG
fprintf(stderr, "\nNew line\n");
-#endif
+ #endif
Parse(pParser, walker->type, walker, e);
}
// Signal finish to parser
-#ifndef NDEBUG
+ #ifndef NDEBUG
fprintf(stderr, "\nFinish parse\n");
-#endif
+ #endif
Parse(pParser, 0, NULL, e);
// Disconnect of (now empty) root
if ((block == NULL) || (block->child == NULL))
return;
-#ifndef NDEBUG
+ #ifndef NDEBUG
fprintf(stderr, "Strip line tokens from %d (%lu:%lu) (child %d)\n", block->type, block->start, block->len, block->child->type);
token_tree_describe(block, NULL);
-#endif
+ #endif
token * l = block->child;
pair_emphasis_tokens(doc);
-#ifndef NDEBUG
+ #ifndef NDEBUG
token_tree_describe(doc, e->dstr->str);
-#endif
+ #endif
}
return doc;
*/
#ifdef USE_CURL
-#include <curl/curl.h>
+ #include <curl/curl.h>
#endif
#include "miniz.h"
long ran_x[KK]; /* the generator state */
#ifdef __STDC__
-void ran_array(long aa[],int n)
+ void ran_array(long aa[],int n)
#else
-void ran_array(aa,n) /* put n new random numbers in aa */
-long *aa; /* destination */
-int n; /* array length (must be at least KK) */
+ void ran_array(aa,n) /* put n new random numbers in aa */
+ long *aa; /* destination */
+ int n; /* array length (must be at least KK) */
#endif
{
register int i,j;
#define is_odd(x) ((x)&1) /* units bit of x */
#ifdef __STDC__
-void ran_start(long seed)
+ void ran_start(long seed)
#else
-void ran_start(seed) /* do this before using ran_array */
-long seed; /* selector for different streams */
+ void ran_start(seed) /* do this before using ran_array */
+ long seed; /* selector for different streams */
#endif
{
register int t,j;
#include <sys/stat.h>
#ifdef USE_CURL
-#include <curl/curl.h>
+ #include <curl/curl.h>
#endif
#include "textbundle.h"
token * token_new(unsigned short type, size_t start, size_t len) {
-#ifdef kUseObjectPool
+ #ifdef kUseObjectPool
token * t = pool_allocate_object(token_pool);
-#else
+ #else
token * t = malloc(sizeof(token));
-#endif
+ #endif
if (t) {
t->type = type;
/// Duplicate an existing token
token * token_copy(token * original) {
-#ifdef kUseObjectPool
+ #ifdef kUseObjectPool
token * t = pool_allocate_object(token_pool);
-#else
+ #else
token * t = malloc(sizeof(token));
-#endif
+ #endif
if (t) {
* t = * original;
/// Free token
void token_free(token * t) {
-#ifdef kUseObjectPool
+ #ifdef kUseObjectPool
return;
-#else
+ #else
if (t == NULL)
return;
token_tree_free(t->child);
free(t);
-#endif
+ #endif
}
/// Free token chain
void token_tree_free(token * t) {
-#ifdef kUseObjectPool
+ #ifdef kUseObjectPool
return;
-#else
+ #else
token * n;
while (t != NULL) {
t = n;
}
-#endif
+ #endif
}
peek = stack_pop(s);
opener_count[peek->type]--;
}
-#ifndef NDEBUG
+ #ifndef NDEBUG
fprintf(stderr, "stack now sized %lu\n", s->size);
-#endif
+ #endif
// Prune matched section
if (e->should_prune[pair_type]) {
break;
}
-#ifndef NDEBUG
+ #ifndef NDEBUG
else {
fprintf(stderr, "token type %d failed to match stack element\n", walker->type);
}
-#endif
+ #endif
i--;
}
}
if (walker->can_open && e->can_open_pair[walker->type] && walker->unmatched) {
stack_push(s, walker);
opener_count[walker->type]++;
-#ifndef NDEBUG
+ #ifndef NDEBUG
fprintf(stderr, "push token type %d to stack (%lu elements)\n", walker->type, s->size);
-#endif
+ #endif
}
walker = walker->next;
}
-#ifndef NDEBUG
+ #ifndef NDEBUG
fprintf(stderr, "token stack has %lu elements (of %lu)\n", s->size, s->capacity);
-#endif
+ #endif
// Remove unused tokens from stack and return to parent
s->size = start_counter;
#include "transclude.h"
#if defined(__WIN32)
-#include <windows.h>
+ #include <windows.h>
#endif
#define kBUFFERSIZE 4096 // How many bytes to read at a time
/// Windows can use either `\` or `/` as a separator -- thanks to t-beckmann on github
/// for suggesting a fix for this.
bool is_separator(char c) {
-#if defined(__WIN32)
+ #if defined(__WIN32)
return c == '\\' || c == '/';
-#else
+ #else
return c == '/';
-#endif
+ #endif
}
void Test_is_separator(CuTest* tc) {
char * test = "a/\\";
-#if defined(__WIN32)
+ #if defined(__WIN32)
CuAssertIntEquals(tc, false, is_separator(test[0]));
CuAssertIntEquals(tc, true, is_separator(test[1]));
CuAssertIntEquals(tc, true, is_separator(test[2]));
-#else
+ #else
CuAssertIntEquals(tc, false, is_separator(test[0]));
CuAssertIntEquals(tc, true, is_separator(test[1]));
CuAssertIntEquals(tc, false, is_separator(test[2]));
-#endif
+ #endif
}
#endif
void add_trailing_sep(DString * path) {
-#if defined(__WIN32)
+ #if defined(__WIN32)
char sep = '\\';
-#else
+ #else
char sep = '/';
-#endif
+ #endif
// Ensure that folder ends in separator
if (!is_separator(path->str[path->currentStringLength - 1])) {
char * path = path_from_dir_base(dir, base);
-#if defined(__WIN32)
+ #if defined(__WIN32)
CuAssertStrEquals(tc, "/foo\\bar", path);
-#else
+ #else
CuAssertStrEquals(tc, "/foo/bar", path);
-#endif
+ #endif
free(path);
strcpy(base, "/bar");
void split_path_file(char ** dir, char ** file, const char * path) {
const char * slash = path, * next;
-#if defined(__WIN32)
+ #if defined(__WIN32)
const char sep[] = "\\/"; // Windows allows either variant
-#else
+ #else
const char sep[] = "/";
-#endif
+ #endif
while ((next = strpbrk(slash + 1, sep)))
slash = next;
path = "\\foo\\bar.txt";
split_path_file(&dir, &file, path);
-#if defined(__WIN32)
+ #if defined(__WIN32)
CuAssertStrEquals(tc, "\\foo\\", dir);
CuAssertStrEquals(tc, "bar.txt", file);
-#else
+ #else
CuAssertStrEquals(tc, "", dir);
CuAssertStrEquals(tc, "\\foo\\bar.txt", file);
-#endif
+ #endif
}
#endif
FILE * file;
-#if defined(__WIN32)
+ #if defined(__WIN32)
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, fname, -1, NULL, 0);
wchar_t wstr[wchars_num];
MultiByteToWideChar(CP_UTF8, 0, fname, -1, wstr, wchars_num);
if ((file = _wfopen(wstr, L"r")) == NULL) {
-#else
+ #else
if ((file = fopen(fname, "r")) == NULL ) {
-#endif
+ #endif
return NULL;
}
void footnote_free(footnote * f) {
if (f) {
if (f->free_para) {
-#ifdef kUseObjectPool
+ #ifdef kUseObjectPool
// Nothing to do here
-#else
+ #else
free(f->content);
-#endif
+ #endif
}
free(f->clean_text);
free(f->label_text);
char * output_filename;
// Increment counter and prepare token pool
-#ifdef kUseObjectPool
+ #ifdef kUseObjectPool
token_pool_init();
-#endif
+ #endif
// Seed random numbers
custom_seed_rand();
}
// Increment counter and prepare token pool
-#ifdef kUseObjectPool
+ #ifdef kUseObjectPool
token_pool_init();
-#endif
+ #endif
if (a_meta->count > 0) {
// List metadata keys
char_result = mmd_string_metadata_keys(buffer->str);
// Perform transclusion(s)
// Convert to absolute path for first file to enable proper path resolution
-#ifdef PATH_MAX
+ #ifdef PATH_MAX
// If PATH_MAX defined, use it
char absolute[PATH_MAX + 1];
realpath(a_file->filename[0], absolute);
folder = dirname((char *) a_file->filename[0]);
mmd_transclude_source(buffer, folder, absolute, format, NULL, NULL);
-#else
+ #else
// If undefined, then we *should* be able to use a NULL pointer to allocate
char * absolute = realpath(a_file->filename[0], NULL);
folder = dirname((char *) a_file->filename[0]);
mmd_transclude_source(buffer, folder, absolute, format, NULL, NULL);
free(absolute);
-#endif
+ #endif
// Don't free folder -- owned by dirname
}
// Decrement counter and clean up token pool
token_pool_drain();
-#ifdef kUseObjectPool
+ #ifdef kUseObjectPool
token_pool_free();
-#endif
+ #endif
exit2: