Commit 73f06869 authored by Alessandro Ghedini's avatar Alessandro Ghedini

Updated version 2.2.3b8 from 'upstream/2.2.3b8'

with Debian dir e5401287011696b795f6389a3f61d39b3cbe8285
parents 732e2a75 349b9407
......@@ -32,6 +32,9 @@ Configure.sh has a few options that can be set:
so the Debian regression tester won't complain
--pkg-config Build & install a pkg-config(1) .pc file for
the discount library.
--h1-title Have theme & mkd2html use the first h1 in a document
as the title if there's no pandoc header or title
specified on the command line.
3) Installing sample programs and manpages
......
......@@ -17,8 +17,12 @@ MKDLIB=libmarkdown
OBJS=mkdio.o markdown.o dumptree.o generate.o \
resource.o docheader.o version.o toc.o css.o \
xml.o Csio.o xmlpage.o basename.o emmatch.o \
github_flavoured.o setup.o tags.o html5.o flags.o @AMALLOC@
TESTFRAMEWORK=echo cols
github_flavoured.o setup.o tags.o html5.o flags.o \
@AMALLOC@ @H1TITLE@
TESTFRAMEWORK=echo cols branch
# modules that markdown, makepage, mkd2html, &tc use
COMMON=pgm_options.o gethopt.o notspecial.o
MAN3PAGES=mkd-callbacks.3 mkd-functions.3 markdown.3 mkd-line.3
......@@ -72,8 +76,8 @@ $(DESTDIR)$(LIBDIR):
@MK_PKGCONFIG@$(DESTDIR)$(PKGDIR):
@MK_PKGCONFIG@ @INSTALL_DIR@ $(DESTDIR)$(PKGDIR)
version.o: version.c VERSION
$(CC) $(CFLAGS) -DVERSION=\"`cat VERSION`\" -c version.c
version.o: version.c VERSION branch
$(CC) $(CFLAGS) -DBRANCH=`./branch` -DVERSION=\"`cat VERSION`\" -c version.c
VERSION:
@true
......@@ -84,22 +88,28 @@ blocktags: mktags
./mktags > blocktags
# example programs
@THEME@theme: theme.o $(MKDLIB) mkdio.h
@THEME@ $(CC) $(CFLAGS) $(LFLAGS) -o theme theme.o pgm_options.o -lmarkdown @LIBS@
@THEME@theme: theme.o $(COMMON) $(MKDLIB) mkdio.h
@THEME@ $(CC) $(CFLAGS) $(LFLAGS) -o theme theme.o $(COMMON) -lmarkdown @LIBS@
mkd2html: mkd2html.o $(MKDLIB) mkdio.h
$(CC) $(CFLAGS) $(LFLAGS) -o mkd2html mkd2html.o -lmarkdown @LIBS@
mkd2html: mkd2html.o $(MKDLIB) mkdio.h gethopt.h $(COMMON)
$(CC) $(CFLAGS) $(LFLAGS) -o mkd2html mkd2html.o $(COMMON) -lmarkdown @LIBS@
markdown: main.o pgm_options.o $(MKDLIB)
$(CC) $(CFLAGS) $(LFLAGS) -o markdown main.o pgm_options.o -lmarkdown @LIBS@
markdown: main.o $(COMMON) $(MKDLIB)
$(CC) $(CFLAGS) $(LFLAGS) -o markdown main.o $(COMMON) -lmarkdown @LIBS@
makepage: makepage.c pgm_options.o $(MKDLIB) mkdio.h
$(CC) $(CFLAGS) $(LFLAGS) -o makepage makepage.c pgm_options.o -lmarkdown @LIBS@
makepage: makepage.c $(COMMON) $(MKDLIB) mkdio.h
$(CC) $(CFLAGS) $(LFLAGS) -o makepage makepage.c $(COMMON) -lmarkdown @LIBS@
pgm_options.o: pgm_options.c mkdio.h config.h
$(CC) $(CFLAGS) -I. -c pgm_options.c
notspecial.o: notspecial.c
$(CC) $(CFLAGS) -I. -c notspecial.c
gethopt.o: gethopt.c
$(CC) $(CFLAGS) -I. -c gethopt.c
main.o: main.c mkdio.h config.h
$(CC) $(CFLAGS) -I. -c main.c
......@@ -114,6 +124,8 @@ test: $(PGMS) $(TESTFRAMEWORK) verify
@LD_LIBRARY_PATH@=`pwd` sh $$x || exit 1; \
done
branch: tools/branch.c config.h
$(CC) -o branch tools/branch.c
cols: tools/cols.c config.h
$(CC) -o cols tools/cols.c
echo: tools/echo.c config.h
......@@ -148,3 +160,6 @@ xml.o: xml.c config.h cstring.h amalloc.h markdown.h
xmlpage.o: xmlpage.c config.h cstring.h amalloc.h markdown.h
setup.o: setup.c config.h cstring.h amalloc.h markdown.h
github_flavoured.o: github_flavoured.c config.h cstring.h amalloc.h markdown.h
gethopt.o: gethopt.c gethopt.h
h1title.o: h1title.c markdown.h
notspecial.o: notspecial.c config.h
......@@ -32,8 +32,11 @@ locals() {
--DEBIAN-GLITCH)
echo DEBIAN_GLITCH=T
;;
--H1-TITLE)
echo H1TITLE=T
;;
--PKG-CONFIG)
echo PKGCONFIG=true
echo PKGCONFIG=T
;;
esac
}
......@@ -109,6 +112,7 @@ AC_CHECK_BASENAME
AC_CHECK_ALLOCA
AC_CHECK_HEADERS sys/types.h pwd.h && AC_CHECK_FUNCS getpwuid
AC_CHECK_HEADERS sys/stat.h && AC_CHECK_FUNCS stat
if AC_CHECK_FUNCS srandom; then
AC_DEFINE 'INITRNG(x)' 'srandom((unsigned int)x)'
......@@ -174,6 +178,14 @@ else
AC_SUB 'AMALLOC' ''
fi
if [ "$H1TITLE" ]; then
AC_SUB 'H1TITLE' h1title.o
AC_DEFINE USE_H1TITLE 1
else
AC_SUB 'H1TITLE' ''
fi
[ "$OS_FREEBSD" -o "$OS_DRAGONFLY" ] || AC_CHECK_HEADERS malloc.h
[ "$WITH_PANDOC_HEADER" ] && AC_DEFINE 'PANDOC_HEADER' '1'
......
......@@ -54,15 +54,13 @@ mkd_css(Document *d, char **res)
stylesheets(d->code, &f);
if ( (size = S(f)) > 0 ) {
/* null-terminate, then strdup() into a free()able memory
* chunk
*/
EXPAND(f) = 0;
/* HACK ALERT! HACK ALERT! HACK ALERT! */
*res = T(f);/* we know that a T(Cstring) is a character pointer */
/* so we can simply pick it up and carry it away, */
/* leaving the husk of the Ctring on the stack */
/* END HACK ALERT */
*res = strdup(T(f));
}
else
DELETE(f);
DELETE(f);
return size;
}
return EOF;
......
......@@ -37,6 +37,7 @@ static struct flagnames flagnames[] = {
{ MKD_GITHUBTAGS, "GITHUBTAGS" },
{ MKD_URLENCODEDANCHOR, "URLENCODEDANCHOR" },
{ MKD_LATEX, "LATEX" },
{ MKD_EXPLICITLIST, "EXPLICITLIST" },
};
#define NR(x) (sizeof x/sizeof x[0])
......
......@@ -108,8 +108,10 @@ isthisnonword(MMIOT *f, int i)
/* return/set the current cursor position
* (when setting the current cursor position we also need to flush the
* last character written cache)
*/
#define mmiotseek(f,x) (f->isp = x)
#define mmiotseek(f,x) ((f->isp = x), (f->last = 0))
#define mmiottell(f) (f->isp)
......@@ -224,6 +226,11 @@ ___mkd_reparse(char *bfr, int size, int flags, MMIOT *f, char *esc)
___mkd_emblock(&sub);
Qwrite(T(sub.out), S(sub.out), f);
/* inherit the last character printed from the reparsed
* text; this way superscripts can work when they're
* applied to something embedded in a link
*/
f->last = sub.last;
___mkd_freemmiot(&sub, f->footnotes);
}
......@@ -1309,7 +1316,9 @@ text(MMIOT *f)
break;
/* A^B -> A<sup>B</sup> */
case '^': if ( (f->flags & (MKD_NOSUPERSCRIPT|MKD_STRICT|MKD_TAGTEXT))
|| (isthisnonword(f,-1) && peek(f,-1) != ')')
|| (f->last == 0)
|| ((ispunct(f->last) || isspace(f->last))
&& f->last != ')')
|| isthisspace(f,1) )
Qchar(c,f);
else {
......@@ -1447,7 +1456,8 @@ text(MMIOT *f)
}
/* fall through to default */
default: Qchar(c, f);
default: f->last = c;
Qchar(c, f);
break;
}
}
......
.\" Copyright (c) 1988, 1991 Regents of the University of California.
.\" Copyright (c) 2017 David Loren Parsons.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd Jan 23, 2017
.Dt GETHOPT 3
.Os Mastodon
.Sh NAME
.Nm gethopt
.Nd get option letter or word from argv
.Sh SYNOPSIS
.Fd #include "gethopt.h"
.Bd -literal -compact
struct h_opt {
int option;
char *optword;
char optchar;
int opthasarg;
char *optdesc;
} ;
.Ed
.Ft char*
.Fn hoptarg "struct h_context* argctx"
.Ft int
.Fn hoptind "struct h_context* argctx"
.Ft int
.Fn hopterr "struct h_context* argctx" "int flag"
.Ft char
.Fn hoptopt "struct h_context* argctx"
.Ft void
.Fn hoptset "struct h_context* argctx" "int argc" "char** argv"
.Ft struct h_opt*
.Fn gethopt "struct h_context* argctx" "struct h_opt* optarray" "int nropts"
.Sh DESCRIPTION
The
.Fn gethopt
function gets
the next
.Em known
option word or character from
.Fa argctx .
An option is
.Em known
if it has been specified in the array of accepted options
.Fa optarray .
.Pp
The option array
.Fa optarray
contains records with either an option word, character, or both,
a flag saying the option needs an argument, a short description
of the option, and an
.Va option
key (which is there for the convenience of the calling program;
.Fn gethopt
does not use it in any way.).
It does not matter to
.Fn getopt
if a following argument has leading white space.
.Pp
On return from
.Fn gethopt ,
.Fn hoptarg
returns an option argument, if it is anticipated,
and the variable
.Fn hoptind
contains the index to the next
.Fa argv
argument for a subsequent call
to
.Fn gethopt .
.Pp
.Fn
gethopt
uses a (semi) opaque data blob to hold the current state, which
must be initialized by the
.Fn hoptset
function.
.Pp
The
.Fn gethopt
function
returns
.Dv HOPTERR
if a non-recognized
option is encountered,
and NULL when it reaches the end of the options on the command line..
.Pp
The interpretation of options in the argument list may be cancelled
by
.Ql -
(single dash) or
.Ql --
(double dash) which causes
.Fn getopt
to signal the end of argument processing and return an
.Dv NULL .
When all options have been processed (i.e., up to the first non-option
argument),
.Fn gethopt
returns
.Dv NULL .
.Sh DIAGNOSTICS
If the
.Fn gethopt
function encounters a character not found in
.Va optarray
or detects
a missing option argument
it returns
.Dv HOPTERR
(and writes an error message to the
.Em stderr
if
.Fn hopterr
is used to turn error reporting on.)
.Sh EXAMPLE
.Bd -literal -compact
struct h_opt opts[] = {
{ 0, "css", 0, 1, "css file" },
{ 1, "header", 0, 1, "header file" },
{ 2, 0, 'a', 0, "option a (no arg)" },
{ 3, 0, 'b', 1, "option B (with arg)" },
{ 4, "help", '?', 0, "help message" },
} ;
#define NROPT (sizeof opts/sizeof opts[0])
int
main(argc, argv)
char **argv;
{
struct h_opt *ret;
struct h_context ctx;
hoptset(&ctx, argc, argv);
hopterr(&ctx, 1);
while (( ret = gethopt(&ctx, opts, NROPT) )) {
if ( ret != HOPTERR ) {
if ( ret->optword )
printf("%s", ret->optword);
else
printf("%c", ret->optchar);
if ( ret->opthasarg ) {
if ( hoptarg(&ctx) )
printf(" = %s", hoptarg(&ctx));
else
printf(" with no argument?");
}
puts(ret->optdesc ? ret->optdesc : "");
}
}
argc -= hoptind(&ctx);
argv += hoptind(&ctx);
.Ed
.Sh HISTORY
The
.Fn gethopt
function was a quick hack to replace manually parsing full-word arguments
in
.Va discount .
/*
* gehopt; options processing with both single-character and whole-word
* options both introduced with -
*/
#include <stdio.h>
#include <string.h>
#include "gethopt.h"
#include "config.h" /* for bzero() macro on systems that don't have it */
void
hoptset(ctx, argc, argv)
struct h_context *ctx;
int argc;
char **argv;
{
bzero(ctx, sizeof *ctx);
ctx->argc = argc;
ctx->argv = argv;
ctx->optind = 1;
}
char *
hoptarg(ctx)
struct h_context *ctx;
{
return ctx->optarg;
}
int
hoptind(ctx)
struct h_context *ctx;
{
return ctx->optind;
}
char
hoptopt(ctx)
struct h_context *ctx;
{
return ctx->optopt;
}
int
hopterr(ctx,val)
struct h_context *ctx;
{
int old = ctx->opterr;
ctx->opterr = !!val;
return old;
}
struct h_opt *
gethopt(ctx, opts, nropts)
struct h_context *ctx;
struct h_opt *opts;
int nropts;
{
int i;
int dashes;
if ( (ctx == 0) || ctx->optend || (ctx->optind >= ctx->argc) )
return 0;
ctx->optarg = 0;
ctx->optopt = 0;
if ( ctx->optchar == 0) {
/* check for leading -
*/
if ( ctx->argv[ctx->optind][0] != '-' ) {
/* out of arguments */
ctx->optend = 1;
return 0;
}
if ( ctx->argv[ctx->optind][1] == 0
|| strcmp(ctx->argv[ctx->optind], "--") == 0 ) {
/* option list finishes with - or -- token
*/
ctx->optend = 1;
ctx->optind++;
return 0;
}
dashes = 1;
if ( ctx->argv[ctx->optind][dashes] == '-' ) {
/* support GNU-style long option double-dash prefix
* (if gethopt is passed an unknown option with a double-dash
* prefix, it won't match a word and then the second dash
* will be scanned as if it was a regular old single-character
* option.)
*/
dashes = 2;
}
for ( i=0; i < nropts; i++ ) {
if ( ! opts[i].optword )
continue;
if (strcmp(opts[i].optword, dashes+(ctx->argv[ctx->optind]) ) == 0 ) {
if ( opts[i].opthasarg ) {
if ( ctx->argc > ctx->optind ) {
ctx->optarg = ctx->argv[ctx->optind+1];
ctx->optind += 2;
}
else {
/* word argument with required arg at end of
*command line
*/
if ( ctx->opterr )
fprintf(stderr,
"%s: option requires an argument -- %s\n",
ctx->argv[0], opts[i].optword);
ctx->optind ++;
return HOPTERR;
}
}
else {
ctx->optind ++;
}
return &opts[i];
}
}
ctx->optchar = 1;
}
ctx->optopt = ctx->argv[ctx->optind][ctx->optchar++];
if ( !ctx->optopt ) {
/* fell off the end of this argument */
ctx->optind ++;
ctx->optchar = 0;
return gethopt(ctx, opts, nropts);
}
for ( i=0; i<nropts; i++ ) {
if ( opts[i].optchar == ctx->optopt ) {
/* found a single-char option!
*/
if ( opts[i].opthasarg ) {
if ( ctx->argv[ctx->optind][ctx->optchar] ) {
/* argument immediately follows this options (-Oc)
*/
ctx->optarg = &ctx->argv[ctx->optind][ctx->optchar];
ctx->optind ++;
ctx->optchar = 0;
}
else if ( ctx->optind < ctx->argc-1 ) {
/* argument is next arg (-O c)
*/
ctx->optarg = &ctx->argv[ctx->optind+1][0];
ctx->optind += 2;
ctx->optchar = 0;
}
else {
/* end of arg string (-O); set optarg to null, return
* (should it opterr on me?)
*/
ctx->optarg = 0;
ctx->optind ++;
ctx->optchar = 0;
if ( ctx->opterr )
fprintf(stderr,
"%s: option requires an argument -- %c\n",
ctx->argv[0], opts[i].optchar);
return HOPTERR;
}
}
else {
if ( !ctx->argv[ctx->optind][ctx->optchar] ) {
ctx->optind ++;
ctx->optchar = 0;
}
}
return &opts[i];
}
}
if ( ctx->opterr )
fprintf(stderr, "%s: illegal option -- %c\n", ctx->argv[0], ctx->optopt);
return HOPTERR;
}
void
hoptusage(char *pgm, struct h_opt opts[], int nropts, char *arguments)
{
int i;
int optcount;
fprintf(stderr, "usage: %s", pgm);
/* print out the options that don't have flags first */
for ( optcount=i=0; i < nropts; i++ ) {
if ( opts[i].optchar && !opts[i].opthasarg) {
if (optcount == 0 )
fputs(" [-", stderr);
fputc(opts[i].optchar, stderr);
optcount++;
}
}
if ( optcount )
fputc(']', stderr);
/* print out the options WITH flags */
for ( i = 0; i < nropts; i++ )
if ( opts[i].optchar && opts[i].opthasarg)
fprintf(stderr, " [-%c %s]", opts[i].optchar, opts[i].opthasarg);
/* print out the long options */
for ( i = 0; i < nropts; i++ )
if ( opts[i].optword ) {
fprintf(stderr, " [-%s", opts[i].optword);
if ( opts[i].opthasarg )
fprintf(stderr, " %s", opts[i].opthasarg);
fputc(']', stderr);
}
/* print out the arguments string, if any */
if ( arguments )
fprintf(stderr, " %s", arguments);
/* and we're done */
fputc('\n', stderr);
}
#if DEBUG
struct h_opt opts[] = {
{ 0, "css", 0, 1, "css file" },
{ 1, "header", 0, 1, "header file" },
{ 2, 0, 'a', 0, "option a (no arg)" },
{ 3, 0, 'b', 1, "option B (with arg)" },
{ 4, "help", '?', 0, "help message" },
} ;
#define NROPT (sizeof opts/sizeof opts[0])
int
main(argc, argv)
char **argv;
{
struct h_opt *ret;
struct h_context ctx;
int i;
hoptset(&ctx, argc, argv);
hopterr(&ctx, 1);
while (( ret = gethopt(&ctx, opts, NROPT) )) {
if ( ret != HOPTERR ) {
if ( ret->optword )
printf("%s", ret->optword);
else
printf("%c", ret->optchar);
if ( ret->opthasarg ) {
if ( hoptarg(&ctx) )
printf(" with argument \"%s\"", hoptarg(&ctx));
else
printf(" with no argument?");
}
printf(" (%s)\n", ret->optdesc);
}
}
argc -= hoptind(&ctx);
argv += hoptind(&ctx);
for ( i=0; i < argc; i++ )
printf("%d: %s\n", i, argv[i]);
return 0;
}
#endif /*DEBUG*/
/*
* gethopt; options processing with both single-character and whole-work
* options both introduced with -
*/
#ifndef __GETHOPT_D
#define __GETHOPT_D
#include <stdio.h>
#include <string.h>
struct h_opt {
int option;
char *optword;
char optchar;
char *opthasarg;
char *optdesc;
} ;
#define HOPTERR ((struct h_opt*)-1)
struct h_context {
char **argv;
int argc;
int optchar;
int optind;
char *optarg;
char optopt;
int opterr:1;
int optend:1;
} ;
extern char *hoptarg(struct h_context *);
extern int hoptind(struct h_context *);
extern char hoptopt(struct h_context *);
extern void hoptset(struct h_context *, int, char **);
extern int hopterr(struct h_context *, int);
extern struct h_opt *gethopt(struct h_context *, struct h_opt*, int);
extern void hoptusage(char *, struct h_opt*, int, char *);
#endif/*__GETHOPT_D*/
#include <stdio.h>
#include "markdown.h"
static Paragraph *
mkd_h1(Paragraph *p)
{
Paragraph *found;
while ( p ) {
if ( p->typ == HDR && p->hnumber == 1 )
return p;
if ( p->down && (found = mkd_h1(p->down)) )
return found;
p = p->next;
}
return 0;
}
char *
mkd_h1_title(Document *doc, int flags)
{
Paragraph *title;
if (doc && (title = mkd_h1(doc->code)) ) {
char *generated;
int size;
/* assert that a H1 header is one line long, so that's
* the only thing needed
*/
size = mkd_line(T(title->text->text),
S(title->text->text), &generated, flags|MKD_TAGTEXT);