]>
git.cameronkatri.com Git - mandoc.git/blob - prologue.c
b9dac28a67fe3032689f87196c1c2e935b7dee85
1 /* $Id: prologue.c,v 1.4 2009/01/05 17:57:08 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
27 /* FIXME: deprecate into actions.c! */
29 static int prologue_dt(MACRO_PROT_ARGS
);
30 static int prologue_dd(MACRO_PROT_ARGS
);
31 static int prologue_os(MACRO_PROT_ARGS
);
34 prologue_dt(MACRO_PROT_ARGS
)
37 char *args
[MDOC_LINEARG_MAX
];
39 if (SEC_PROLOGUE
!= mdoc
->sec_lastn
)
40 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_NPROLOGUE
));
41 if (0 == mdoc
->meta
.date
)
42 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_PROLOGUE_OO
));
43 if (mdoc
->meta
.title
[0])
44 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_PROLOGUE_REP
));
50 if (j
== MDOC_LINEARG_MAX
)
51 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_ARGS_MANY
));
55 switch (mdoc_args(mdoc
, tok
, pos
, buf
, 0, &args
[++j
])) {
59 if ( ! mdoc_warn(mdoc
, tok
, ppos
, WARN_ARGS_GE1
))
61 (void)xstrlcpy(mdoc
->meta
.title
,
62 "UNTITLED", META_TITLE_SZ
);
71 if (xstrlcpy(mdoc
->meta
.title
, args
[0], META_TITLE_SZ
))
73 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_SYNTAX_ARGFORM
));
76 mdoc
->meta
.msec
= mdoc_atomsec(args
[1]);
77 if (MSEC_DEFAULT
!= mdoc
->meta
.msec
)
79 return(mdoc_err(mdoc
, tok
, -1, ERR_SYNTAX_ARGFORM
));
82 mdoc
->meta
.vol
= mdoc_atovol(args
[2]);
83 if (VOL_DEFAULT
!= mdoc
->meta
.vol
)
85 mdoc
->meta
.arch
= mdoc_atoarch(args
[2]);
86 if (ARCH_DEFAULT
!= mdoc
->meta
.arch
)
88 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_SYNTAX_ARGFORM
));
91 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_ARGS_MANY
));
96 prologue_os(MACRO_PROT_ARGS
)
99 char *args
[MDOC_LINEARG_MAX
];
101 /* FIXME: if we use `Os' again... ? */
103 if (SEC_PROLOGUE
!= mdoc
->sec_lastn
)
104 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_NPROLOGUE
));
105 if (0 == mdoc
->meta
.title
[0])
106 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_PROLOGUE_OO
));
107 if (mdoc
->meta
.os
[0])
108 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_PROLOGUE_REP
));
114 if (j
== MDOC_LINEARG_MAX
)
115 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_ARGS_MANY
));
119 switch (mdoc_args(mdoc
, tok
, pos
, buf
,
120 ARGS_QUOTED
, &args
[++j
])) {
122 mdoc
->sec_lastn
= mdoc
->sec_last
= SEC_BODY
;
130 if ( ! xstrlcat(mdoc
->meta
.os
, args
[j
], sizeof(mdoc
->meta
.os
)))
131 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_SYNTAX_ARGFORM
));
132 if ( ! xstrlcat(mdoc
->meta
.os
, " ", sizeof(mdoc
->meta
.os
)))
133 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_SYNTAX_ARGFORM
));
141 prologue_dd(MACRO_PROT_ARGS
)
144 char *args
[MDOC_LINEARG_MAX
], date
[64];
146 if (SEC_PROLOGUE
!= mdoc
->sec_lastn
)
147 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_NPROLOGUE
));
148 if (mdoc
->meta
.title
[0])
149 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_PROLOGUE_OO
));
151 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SEC_PROLOGUE_REP
));
158 if (j
== MDOC_LINEARG_MAX
)
159 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_ARGS_MANY
));
162 switch (mdoc_args(mdoc
, tok
, pos
, buf
, 0, &args
[++j
])) {
166 mdoc
->meta
.date
= mdoc_atotime(date
);
169 return(mdoc_err(mdoc
, tok
, ppos
, ERR_SYNTAX_ARGFORM
));
176 if (MDOC_MAX
!= mdoc_find(mdoc
, args
[j
]) && ! mdoc_warn
177 (mdoc
, tok
, lastarg
, WARN_SYNTAX_MACLIKE
))
181 if (xstrcmp("$Mdocdate: January 5 2009 $", args
[j
])) {
182 mdoc
->meta
.date
= time(NULL
);
184 } else if (xstrcmp("$Mdocdate:", args
[j
]))
187 if ( ! xstrcmp("$", args
[j
]))
190 if ( ! xstrlcat(date
, args
[j
], sizeof(date
)))
191 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_SYNTAX_ARGFORM
));
192 if ( ! xstrlcat(date
, " ", sizeof(date
)))
193 return(mdoc_err(mdoc
, tok
, lastarg
, ERR_SYNTAX_ARGFORM
));
201 macro_prologue(MACRO_PROT_ARGS
)
206 return(prologue_dt(mdoc
, tok
, ppos
, pos
, buf
));
208 return(prologue_dd(mdoc
, tok
, ppos
, pos
, buf
));
210 return(prologue_os(mdoc
, tok
, ppos
, pos
, buf
));