main.c (discount-2.2.4.tar.bz2) | : | main.c (discount-2.2.6.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
* The redistribution terms are provided in the COPYRIGHT file that must | * The redistribution terms are provided in the COPYRIGHT file that must | |||
* be distributed with this source code. | * be distributed with this source code. | |||
*/ | */ | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <limits.h> | #include <limits.h> | |||
#include <mkdio.h> | #include <mkdio.h> | |||
#include <errno.h> | #include <errno.h> | |||
#include <string.h> | #include <string.h> | |||
#include <stdarg.h> | #include <stdarg.h> | |||
#include <ctype.h> | ||||
#include "config.h" | #include "config.h" | |||
#include "amalloc.h" | #include "amalloc.h" | |||
#include "pgm_options.h" | #include "pgm_options.h" | |||
#include "tags.h" | #include "tags.h" | |||
#include "gethopt.h" | #include "gethopt.h" | |||
#if HAVE_LIBGEN_H | #if HAVE_LIBGEN_H | |||
#include <libgen.h> | #include <libgen.h> | |||
#endif | #endif | |||
skipping to change at line 60 | skipping to change at line 61 | |||
va_list ptr; | va_list ptr; | |||
fprintf(stderr, "%s: ", pgm); | fprintf(stderr, "%s: ", pgm); | |||
va_start(ptr, fmt); | va_start(ptr, fmt); | |||
vfprintf(stderr, fmt, ptr); | vfprintf(stderr, fmt, ptr); | |||
va_end(ptr); | va_end(ptr); | |||
fputc('\n', stderr); | fputc('\n', stderr); | |||
fflush(stderr); | fflush(stderr); | |||
} | } | |||
char * | ||||
anchor_format(char *input, void *ctx) | ||||
{ | ||||
int i, j, size; | ||||
char* ret; | ||||
if ( !input ) | ||||
return NULL; | ||||
size = strlen(input); | ||||
ret = malloc(1+size); | ||||
if ( !ret ) | ||||
return NULL; | ||||
while ( size && isspace(input[size-1]) ) | ||||
--size; | ||||
for ( j=i=0; i < size; i++ ) { | ||||
if (isalnum(input[i]) || strchr("-_+", input[i]) ) | ||||
ret[j++] = input[i]; | ||||
else if ( input[i] == ' ' ) | ||||
ret[j++] = '-'; | ||||
} | ||||
ret[j++] = 0; | ||||
return ret; | ||||
} | ||||
void | ||||
free_it(char *object, void *ctx) | ||||
{ | ||||
if ( object ) | ||||
free(object); | ||||
} | ||||
char * | ||||
external_codefmt(char *src, int len, char *lang) | ||||
{ | ||||
int extra = 0; | ||||
int i, x; | ||||
char *res; | ||||
if ( lang == 0 ) | ||||
lang = "generic_code"; | ||||
for ( i=0; i < len; i++) { | ||||
if ( src[i] == '&' ) | ||||
extra += 5; | ||||
else if ( src[i] == '<' || src[i] == '>' ) | ||||
extra += 4; | ||||
} | ||||
/* 80 characters for the format wrappers */ | ||||
if ( (res = malloc(len+extra+80+strlen(lang))) ==0 ) | ||||
/* out of memory? drat! */ | ||||
return 0; | ||||
sprintf(res, "<pre><code class=\"%s\">\n", lang); | ||||
x = strlen(res); | ||||
for ( i=0; i < len; i++ ) { | ||||
switch (src[i]) { | ||||
case '&': strcpy(&src[x], "&"); | ||||
x += 5 /*strlen(&)*/ ; | ||||
break; | ||||
case '<': strcpy(&src[x], "<"); | ||||
x += 4 /*strlen(<)*/ ; | ||||
break; | ||||
case '>': strcpy(&src[x], ">"); | ||||
x += 4 /*strlen(>)*/ ; | ||||
break; | ||||
default: res[x++] = src[i]; | ||||
break; | ||||
} | ||||
} | ||||
strcpy(&res[x], "</code></pre>\n"); | ||||
return res; | ||||
} | ||||
struct h_opt opts[] = { | struct h_opt opts[] = { | |||
{ 0, "html5", '5', 0, "recognise html5 block elements" }, | { 0, "html5", '5', 0, "recognise html5 block elements" }, | |||
{ 0, "base", 'b', "url-base", "URL prefix" }, | { 0, "base", 'b', "url-base", "URL prefix" }, | |||
{ 0, "debug", 'd', 0, "debugging" }, | { 0, "debug", 'd', 0, "debugging" }, | |||
{ 0, "version",'V', 0, "show version info" }, | { 0, "version",'V', 0, "show version info" }, | |||
{ 0, 0, 'E', "flags", "url flags" }, | { 0, 0, 'E', "flags", "url flags" }, | |||
{ 0, 0, 'F', "bitmap", "set/show hex flags" }, | { 0, 0, 'F', "bitmap", "set/show hex flags" }, | |||
{ 0, 0, 'f', "{+-}flags", "set/show named flags" }, | { 0, 0, 'f', "{+-}flags", "set/show named flags" }, | |||
{ 0, 0, 'G', 0, "github flavoured markdown" }, | { 0, 0, 'G', 0, "github flavoured markdown" }, | |||
{ 0, 0, 'n', 0, "don't write generated html" }, | { 0, 0, 'n', 0, "don't write generated html" }, | |||
{ 0, 0, 's', "text", "format `text`" }, | { 0, 0, 's', "text", "format `text`" }, | |||
{ 0, "style", 'S', 0, "output <style> blocks" }, | { 0, "style", 'S', 0, "output <style> blocks" }, | |||
{ 0, 0, 't', "text", "format `text` with mkd_line()" }, | { 0, 0, 't', "text", "format `text` with mkd_line()" }, | |||
{ 0, "toc", 'T', 0, "output a TOC" }, | { 0, "toc", 'T', 0, "output a TOC" }, | |||
{ 0, 0, 'C', "prefix", "prefix for markdown extra footnotes" }, | { 0, 0, 'C', "prefix", "prefix for markdown extra footnotes" }, | |||
{ 0, 0, 'o', "file", "write output to file" }, | { 0, 0, 'o', "file", "write output to file" }, | |||
{ 0, "squash", 'x', 0, "squash toc labels to be more like github" | ||||
}, | ||||
{ 0, "codefmt",'X', 0, "use an external code formatter" }, | ||||
}; | }; | |||
#define NROPTS (sizeof opts/sizeof opts[0]) | #define NROPTS (sizeof opts/sizeof opts[0]) | |||
int | int | |||
main(int argc, char **argv) | main(int argc, char **argv) | |||
{ | { | |||
int rc; | int rc; | |||
mkd_flag_t flags = 0; | mkd_flag_t flags = 0; | |||
int debug = 0; | int debug = 0; | |||
int toc = 0; | int toc = 0; | |||
int content = 1; | int content = 1; | |||
int version = 0; | int version = 0; | |||
int with_html5 = 0; | int with_html5 = 0; | |||
int styles = 0; | int styles = 0; | |||
int use_mkd_line = 0; | int use_mkd_line = 0; | |||
int use_e_codefmt = 0; | ||||
int github_flavoured = 0; | int github_flavoured = 0; | |||
int squash = 0; | ||||
char *extra_footnote_prefix = 0; | char *extra_footnote_prefix = 0; | |||
char *urlflags = 0; | char *urlflags = 0; | |||
char *text = 0; | char *text = 0; | |||
char *ofile = 0; | char *ofile = 0; | |||
char *urlbase = 0; | char *urlbase = 0; | |||
char *q; | char *q; | |||
MMIOT *doc; | MMIOT *doc; | |||
struct h_context blob; | struct h_context blob; | |||
struct h_opt *opt; | struct h_opt *opt; | |||
skipping to change at line 165 | skipping to change at line 250 | |||
break; | break; | |||
case 'o': if ( ofile ) { | case 'o': if ( ofile ) { | |||
complain("Too many -o options"); | complain("Too many -o options"); | |||
exit(1); | exit(1); | |||
} | } | |||
if ( !freopen(ofile = hoptarg(&blob), "w", stdout) ) { | if ( !freopen(ofile = hoptarg(&blob), "w", stdout) ) { | |||
perror(ofile); | perror(ofile); | |||
exit(1); | exit(1); | |||
} | } | |||
break; | break; | |||
case 'x': squash = 1; | ||||
break; | ||||
case 'X': use_e_codefmt = 1; | ||||
set_flag(&flags, "fencedcode"); | ||||
break; | ||||
} | } | |||
} | } | |||
if ( version ) { | if ( version ) { | |||
printf("%s: discount %s%s", pgm, markdown_version, | printf("%s: discount %s%s", pgm, markdown_version, | |||
with_html5 ? " +html5":""); | with_html5 ? " +html5":""); | |||
if ( version > 1 ) | if ( version > 1 ) | |||
mkd_flags_are(stdout, flags, 0); | mkd_flags_are(stdout, flags, 0); | |||
putchar('\n'); | putchar('\n'); | |||
exit(0); | exit(0); | |||
skipping to change at line 213 | skipping to change at line 303 | |||
perror(argc ? argv[0] : "stdin"); | perror(argc ? argv[0] : "stdin"); | |||
exit(1); | exit(1); | |||
} | } | |||
} | } | |||
if ( urlbase ) | if ( urlbase ) | |||
mkd_basename(doc, urlbase); | mkd_basename(doc, urlbase); | |||
if ( urlflags ) { | if ( urlflags ) { | |||
mkd_e_data(doc, urlflags); | mkd_e_data(doc, urlflags); | |||
mkd_e_flags(doc, e_flags); | mkd_e_flags(doc, e_flags); | |||
} | } | |||
if ( squash ) | ||||
mkd_e_anchor(doc, (mkd_callback_t) anchor_format); | ||||
if ( use_e_codefmt ) | ||||
mkd_e_code_format(doc, external_codefmt); | ||||
if ( use_e_codefmt || squash ) | ||||
mkd_e_free(doc, free_it); | ||||
if ( extra_footnote_prefix ) | if ( extra_footnote_prefix ) | |||
mkd_ref_prefix(doc, extra_footnote_prefix); | mkd_ref_prefix(doc, extra_footnote_prefix); | |||
if ( debug ) | if ( debug ) | |||
rc = mkd_dump(doc, stdout, 0, argc ? basename(argv[0]) : "stdin"); | rc = mkd_dump(doc, stdout, 0, argc ? basename(argv[0]) : "stdin"); | |||
else { | else { | |||
rc = 1; | rc = 1; | |||
if ( mkd_compile(doc, flags) ) { | if ( mkd_compile(doc, flags) ) { | |||
rc = 0; | rc = 0; | |||
if ( styles ) | if ( styles ) | |||
End of changes. 8 change blocks. | ||||
3 lines changed or deleted | 102 lines changed or added |