version 1.80, 2010/05/16 10:59:36 |
version 1.103, 2010/08/20 01:02:07 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
MDOC_br, |
MDOC_br, |
MDOC_sp, |
MDOC_sp, |
MDOC__U, |
MDOC__U, |
|
MDOC_Ta, |
MDOC_MAX |
MDOC_MAX |
}; |
}; |
|
|
/* What follows is a list of ALL possible macro arguments. */ |
/* What follows is a list of ALL possible macro arguments. */ |
|
|
#define MDOC_Split 0 |
enum mdocargt { |
#define MDOC_Nosplit 1 |
MDOC_Split, |
#define MDOC_Ragged 2 |
MDOC_Nosplit, |
#define MDOC_Unfilled 3 |
MDOC_Ragged, |
#define MDOC_Literal 4 |
MDOC_Unfilled, |
#define MDOC_File 5 |
MDOC_Literal, |
#define MDOC_Offset 6 |
MDOC_File, |
#define MDOC_Bullet 7 |
MDOC_Offset, |
#define MDOC_Dash 8 |
MDOC_Bullet, |
#define MDOC_Hyphen 9 |
MDOC_Dash, |
#define MDOC_Item 10 |
MDOC_Hyphen, |
#define MDOC_Enum 11 |
MDOC_Item, |
#define MDOC_Tag 12 |
MDOC_Enum, |
#define MDOC_Diag 13 |
MDOC_Tag, |
#define MDOC_Hang 14 |
MDOC_Diag, |
#define MDOC_Ohang 15 |
MDOC_Hang, |
#define MDOC_Inset 16 |
MDOC_Ohang, |
#define MDOC_Column 17 |
MDOC_Inset, |
#define MDOC_Width 18 |
MDOC_Column, |
#define MDOC_Compact 19 |
MDOC_Width, |
#define MDOC_Std 20 |
MDOC_Compact, |
#define MDOC_Filled 21 |
MDOC_Std, |
#define MDOC_Words 22 |
MDOC_Filled, |
#define MDOC_Emphasis 23 |
MDOC_Words, |
#define MDOC_Symbolic 24 |
MDOC_Emphasis, |
#define MDOC_Nested 25 |
MDOC_Symbolic, |
#define MDOC_Centred 26 |
MDOC_Nested, |
#define MDOC_ARG_MAX 27 |
MDOC_Centred, |
|
MDOC_ARG_MAX |
|
}; |
|
|
/* Type of a syntax node. */ |
/* Type of a syntax node. */ |
enum mdoc_type { |
enum mdoc_type { |
Line 234 struct mdoc_meta { |
|
Line 237 struct mdoc_meta { |
|
|
|
/* An argument to a macro (multiple values = `It -column'). */ |
/* An argument to a macro (multiple values = `It -column'). */ |
struct mdoc_argv { |
struct mdoc_argv { |
int arg; |
enum mdocargt arg; |
int line; |
int line; |
int pos; |
int pos; |
size_t sz; |
size_t sz; |
Line 247 struct mdoc_arg { |
|
Line 250 struct mdoc_arg { |
|
unsigned int refcnt; |
unsigned int refcnt; |
}; |
}; |
|
|
|
enum mdoc_endbody { |
|
ENDBODY_NOT = 0, |
|
ENDBODY_SPACE, |
|
ENDBODY_NOSPACE |
|
}; |
|
|
|
enum mdoc_list { |
|
LIST__NONE = 0, |
|
LIST_bullet, |
|
LIST_column, |
|
LIST_dash, |
|
LIST_diag, |
|
LIST_enum, |
|
LIST_hang, |
|
LIST_hyphen, |
|
LIST_inset, |
|
LIST_item, |
|
LIST_ohang, |
|
LIST_tag |
|
}; |
|
|
|
enum mdoc_disp { |
|
DISP__NONE = 0, |
|
DISP_centred, |
|
DISP_ragged, |
|
DISP_unfilled, |
|
DISP_filled, |
|
DISP_literal |
|
}; |
|
|
|
enum mdoc_auth { |
|
AUTH__NONE = 0, |
|
AUTH_split, |
|
AUTH_nosplit |
|
}; |
|
|
|
enum mdoc_font { |
|
FONT__NONE = 0, |
|
FONT_Em, |
|
FONT_Li, |
|
FONT_Sy |
|
}; |
|
|
|
struct mdoc_bd { |
|
const char *offs; /* -offset */ |
|
enum mdoc_disp type; /* -ragged, etc. */ |
|
int comp; /* -compact */ |
|
}; |
|
|
|
struct mdoc_bl { |
|
const char *width; /* -width */ |
|
const char *offs; /* -offset */ |
|
enum mdoc_list type; /* -tag, -enum, etc. */ |
|
int comp; /* -compact */ |
|
size_t ncols; /* -column arg count */ |
|
const char **cols; /* -column val ptr */ |
|
}; |
|
|
|
struct mdoc_bf { |
|
enum mdoc_font font; /* font */ |
|
}; |
|
|
|
struct mdoc_an { |
|
enum mdoc_auth auth; /* -split, etc. */ |
|
}; |
|
|
/* Node in AST. */ |
/* Node in AST. */ |
struct mdoc_node { |
struct mdoc_node { |
struct mdoc_node *parent; /* parent AST node */ |
struct mdoc_node *parent; /* parent AST node */ |
Line 262 struct mdoc_node { |
|
Line 331 struct mdoc_node { |
|
#define MDOC_ACTED (1 << 1) /* has been acted upon */ |
#define MDOC_ACTED (1 << 1) /* has been acted upon */ |
#define MDOC_EOS (1 << 2) /* at sentence boundary */ |
#define MDOC_EOS (1 << 2) /* at sentence boundary */ |
#define MDOC_LINE (1 << 3) /* first macro/text on line */ |
#define MDOC_LINE (1 << 3) /* first macro/text on line */ |
|
#define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */ |
|
#define MDOC_ENDED (1 << 5) /* rendering has been ended */ |
enum mdoc_type type; /* AST node type */ |
enum mdoc_type type; /* AST node type */ |
enum mdoc_sec sec; /* current named section */ |
enum mdoc_sec sec; /* current named section */ |
|
/* FIXME: these can be union'd to shave a few bytes. */ |
struct mdoc_arg *args; /* BLOCK/ELEM */ |
struct mdoc_arg *args; /* BLOCK/ELEM */ |
#ifdef UGLY |
|
struct mdoc_node *pending; /* BLOCK */ |
struct mdoc_node *pending; /* BLOCK */ |
#endif |
|
struct mdoc_node *head; /* BLOCK */ |
struct mdoc_node *head; /* BLOCK */ |
struct mdoc_node *body; /* BLOCK */ |
struct mdoc_node *body; /* BLOCK */ |
struct mdoc_node *tail; /* BLOCK */ |
struct mdoc_node *tail; /* BLOCK */ |
char *string; /* TEXT */ |
char *string; /* TEXT */ |
}; |
enum mdoc_endbody end; /* BODY */ |
|
|
#define MDOC_IGN_SCOPE (1 << 0) /* Ignore scope violations. */ |
union { |
#define MDOC_IGN_ESCAPE (1 << 1) /* Ignore bad escape sequences. */ |
struct mdoc_an An; |
#define MDOC_IGN_MACRO (1 << 2) /* Ignore unknown macros. */ |
struct mdoc_bd *Bd; |
|
struct mdoc_bf *Bf; |
/* Call-backs for parse messages. */ |
struct mdoc_bl *Bl; |
|
} data; |
struct mdoc_cb { |
|
int (*mdoc_err)(void *, int, int, const char *); |
|
int (*mdoc_warn)(void *, int, int, const char *); |
|
}; |
}; |
|
|
/* See mdoc.3 for documentation. */ |
/* See mdoc.3 for documentation. */ |
|
|
/* See mdoc.3 for documentation. */ |
/* See mdoc.3 for documentation. */ |
|
|
void mdoc_free(struct mdoc *); |
void mdoc_free(struct mdoc *); |
struct mdoc *mdoc_alloc(void *, int, const struct mdoc_cb *); |
struct mdoc *mdoc_alloc(struct regset *, void *, mandocmsg); |
void mdoc_reset(struct mdoc *); |
void mdoc_reset(struct mdoc *); |
int mdoc_parseln(struct mdoc *, int, char *, int); |
int mdoc_parseln(struct mdoc *, int, char *, int); |
const struct mdoc_node *mdoc_node(const struct mdoc *); |
const struct mdoc_node *mdoc_node(const struct mdoc *); |