#define print_localized(x) mmd_print_localized_char_html(out, x, scratch)
+/// strdup() not available on all platforms
+static char * my_strdup(const char * source) {
+ char * result = malloc(strlen(source) + 1);
+
+ if (result) {
+ strcpy(result, source);
+ }
+
+ return result;
+}
+
+
char * epub_mimetype(void) {
- return strdup("application/epub+zip");
+ return my_strdup("application/epub+zip");
}
#define print_token(t) d_string_append_c_array(out, &(source[t->start]), t->len)
#define print_localized(x) mmd_print_localized_char_html(out, x, scratch)
+
+/// strdup() not available on all platforms
+static char * my_strdup(const char * source) {
+ char * result = malloc(strlen(source) + 1);
+
+ if (result) {
+ strcpy(result, source);
+ }
+
+ return result;
+}
+
+
// Use Knuth's pseudo random generator to obfuscate email addresses predictably
long ran_num_next();
char *result;
int i;
- result = strdup(original);
+ result = my_strdup(original);
for (i = 0; result[i]; i++)
result[i] = tolower(result[i]);
if (strcmp(temp_char2, "notcited") == 0) {
free(temp_char);
- temp_char = strdup("");
+ temp_char = my_strdup("");
temp_bool = false;
}
} else {
// This is the actual citation (e.g. `[#foo]`)
// No locator
- temp_char = strdup("");
+ temp_char = my_strdup("");
}
// Classify this use
#define print_localized(x) mmd_print_localized_char_latex(out, x, scratch)
+/// strdup() not available on all platforms
+static char * my_strdup(const char * source) {
+ char * result = malloc(strlen(source) + 1);
+
+ if (result) {
+ strcpy(result, source);
+ }
+
+ return result;
+}
+
+
void mmd_print_char_latex(DString * out, char c) {
switch (c) {
case '\\':
char *result;
int i;
- result = strdup(original);
+ result = my_strdup(original);
for (i = 0; result[i]; i++)
result[i] = tolower(result[i]);
if (strcmp(temp_char2, "notcited") == 0) {
free(temp_char);
- temp_char = strdup("");
+ temp_char = my_strdup("");
temp_bool = false;
}
} else {
// This is the actual citation (e.g. `[#foo]`)
// No locator
- temp_char = strdup("");
+ temp_char = my_strdup("");
}
// Classify this use
void mmd_pair_tokens_in_block(token * block, token_pair_engine * e, stack * s);
+/// strdup() not available on all platforms
+static char * my_strdup(const char * source) {
+ char * result = malloc(strlen(source) + 1);
+
+ if (result) {
+ strcpy(result, source);
+ }
+
+ return result;
+}
+
/// Build MMD Engine
mmd_engine * mmd_engine_create(DString * d, unsigned long extensions) {
char * result;
mmd_engine * e = mmd_engine_create_with_string(source, 0);
- result = strdup(mmd_engine_metavalue_for_key(e, key));
+ result = my_strdup(mmd_engine_metavalue_for_key(e, key));
mmd_engine_free(e, true);
/// Return string containing engine version.
char * mmd_version(void) {
char * result;
- result = strdup(MULTIMARKDOWN_VERSION);
+ result = my_strdup(MULTIMARKDOWN_VERSION);
return result;
}
}
+/// strdup() not available on all platforms
+static char * my_strdup(const char * source) {
+ char * result = malloc(strlen(source) + 1);
+
+ if (result) {
+ strcpy(result, source);
+ }
+
+ return result;
+}
+
+
/// 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) {
slash++;
*dir = my_strndup(path, slash - path);
- *file = strdup(slash);
+ *file = my_strdup(slash);
}
#ifdef TEST
// Add path to manifest
if (add)
- stack_push(manifest, strdup(file_path->str));
+ stack_push(manifest, my_strdup(file_path->str));
}
// Read the file
void store_abbreviation(scratch_pad * scratch, footnote * a);
+
/// strndup not available on all platforms
static char * my_strndup(const char * source, size_t n) {
size_t len = 0;
}
+/// strdup() not available on all platforms
+static char * my_strdup(const char * source) {
+ char * result = malloc(strlen(source) + 1);
+
+ if (result) {
+ strcpy(result, source);
+ }
+
+ return result;
+}
+
+
/// Temporary storage while exporting parse tree to output format
scratch_pad * scratch_pad_new(mmd_engine * e, short format) {
scratch_pad * p = malloc(sizeof(scratch_pad));
if (a) {
a->key = key;
- a->value = strdup(value);
+ a->value = my_strdup(value);
a->next = NULL;
}
l->label_text = NULL;
}
l->url = clean_string(url, false);
- l->title = (title == NULL) ? NULL : strdup(title);
+ l->title = (title == NULL) ? NULL : my_strdup(title);
l->attributes = (attributes == NULL) ? NULL : parse_attributes(attributes);
}
free(temp_char);
} else if (strcmp(m->key, "bibtex") == 0) {
- scratch->bibtex_file = strdup(m->value);
+ scratch->bibtex_file = my_strdup(m->value);
// Trigger complete document unless explicitly denied
if (!(scratch->extensions & EXT_SNIPPET))
scratch->extensions |= EXT_COMPLETE;
asset * a = malloc(sizeof(asset));
if (a) {
- a->url = strdup(url);
+ a->url = my_strdup(url);
// Create a unique local asset path
a->asset_path = uuid_new();