New rules for translating several texi @-commands to man page

This commit is contained in:
Thomas Schmitt 2011-05-17 17:37:00 +00:00
parent f28da0c7ce
commit d810dc7064
3 changed files with 129 additions and 30 deletions

View File

@ -82,12 +82,82 @@ int Mx1__get_word(char *line, char word[256], char **remainder, int flag)
} }
int Mx1_is_wrap(struct Mx1 *m, char wraps[][20], char *start, char **found,
int flag)
{
int i;
for(i= 0; wraps[i][0] != 0; i++)
if(strncmp(start, wraps[i], strlen(wraps[i])) == 0)
break;
if(wraps[i][0] != 0) {
if(found != NULL)
*found= wraps[i];
return(1);
}
return(0);
}
int Mx1_is_bold_wrap(struct Mx1 *m, char *start, char **found, int flag)
{
int ret;
static char bold_wraps[][20]= {
"@b{", "@dfn{", "@emph{", "@strong{", "@command{",
"" };
ret= Mx1_is_wrap(m, bold_wraps, start, found, 0);
return(ret);
}
int Mx1_is_normal_wrap(struct Mx1 *m, char *start, char **found, int flag)
{
int ret;
static char normal_wraps[][20]= {
"@var{", "@code{", "@i{", "@abbr{", "@file{", "@option{", "@samp{", "@r{",
"" };
ret= Mx1_is_wrap(m, normal_wraps, start, found, 0);
return(ret);
}
int Mx1_is_ignored_wrap(struct Mx1 *m, char *start, char **found, int flag)
{
int ret;
static char ignored_wraps[][20]= {
"@ref{", "@xref{",
"" };
ret= Mx1_is_wrap(m, ignored_wraps, start, found, 0);
return(ret);
}
int Mx1_is_any_wrap(struct Mx1 *m, char *start, char **found, int flag)
{
int ret;
ret= Mx1_is_bold_wrap(m, start, found, 0);
if(ret > 0)
return(1);
ret= Mx1_is_normal_wrap(m, start, found, 0);
if(ret > 0)
return(2);
ret= Mx1_is_ignored_wrap(m, start, found, 0);
if(ret > 0)
return(3);
return(0);
}
/* @param flag bit0= recursion /* @param flag bit0= recursion
bit1= drop content of brackets
*/ */
int Mx1_rewrap(struct Mx1 *m, char **read_pt, char **write_pt, int Mx1_rewrap(struct Mx1 *m, char **read_pt, char **write_pt,
char *write_base, char *envelope, char *write_base, char *envelope,
char *front, char *back, char *front, char *back, int flag)
int flag)
{ {
char *rpt, *wpt, *ept, content[256], msg[256]; char *rpt, *wpt, *ept, content[256], msg[256];
int l, ret; int l, ret;
@ -103,16 +173,21 @@ int Mx1_rewrap(struct Mx1 *m, char **read_pt, char **write_pt,
} }
/* Mapped {...} content is subject to the rules except {...} mapping. */ /* Mapped {...} content is subject to the rules except {...} mapping. */
l= ept - rpt; l= ept - rpt;
if(flag & 2)
l= 0;
if(l > 0) {
ret= Mx1_substitute(m, rpt, content, 0, l, 1); ret= Mx1_substitute(m, rpt, content, 0, l, 1);
if(ret <= 0) if(ret <= 0)
return(ret); return(ret);
l= strlen(content); l= strlen(content);
}
if((wpt - write_base) + l + strlen(front) + strlen(back) > 255) { if((wpt - write_base) + l + strlen(front) + strlen(back) > 255) {
Mx1_report_error(m, "Line length overflow while text substitution", 0); Mx1_report_error(m, "Line length overflow while text substitution", 0);
return(-1); return(-1);
} }
strcpy(wpt, front); strcpy(wpt, front);
wpt+= strlen(front); wpt+= strlen(front);
if(l > 0)
strncpy(wpt, content, l); strncpy(wpt, content, l);
wpt+= l; wpt+= l;
strcpy(wpt, back); strcpy(wpt, back);
@ -129,8 +204,8 @@ int Mx1_rewrap(struct Mx1 *m, char **read_pt, char **write_pt,
int Mx1_substitute(struct Mx1 *m, char line_in[256], char line_out[256], int Mx1_substitute(struct Mx1 *m, char line_in[256], char line_out[256],
int raw, int upto, int flag) int raw, int upto, int flag)
{ {
char *rpt, *wpt; char *rpt, *wpt, *found;
int ret; int ret, typ= 0;
wpt= line_out; wpt= line_out;
for(rpt= line_in; rpt - line_in < upto && *rpt != 0; rpt++) { for(rpt= line_in; rpt - line_in < upto && *rpt != 0; rpt++) {
@ -139,19 +214,34 @@ int Mx1_substitute(struct Mx1 *m, char line_in[256], char line_out[256],
continue; continue;
} }
if(*rpt == '@') { if(*rpt == '@') {
if(strncmp(rpt, "@strong{", 8) == 0 && !(flag & 1)) { typ= 0;
/* @strong{...} gets mapped to \fB...\fR . */ if(!(flag & 1))
rpt+= 8; typ= Mx1_is_any_wrap(m, rpt, &found, 0);
if(typ == 1) {
/* @b{...}, @command{...}, @dfn{...}, @emph{...}, @strong{...}
get mapped to \fB...\fR .
*/
rpt+= strlen(found);
ret= Mx1_rewrap(m, &rpt, &wpt, line_out, ret= Mx1_rewrap(m, &rpt, &wpt, line_out,
"@strong{" , "\\fB", "\\fR", 0); found , "\\fB", "\\fR", flag & 1);
if(ret <= 0) if(ret <= 0)
return(ret); return(ret);
} else if(strncmp(rpt, "@command{", 9) == 0 && !(flag & 1)) { } else if(typ == 2) {
/* @command{...} gets mapped to \fB...\fR . */ /* @abbr{...}, @code{...}, @file{...}, @i{...}, @option{...}, @r{...},
rpt+= 9; @ref{...}, @samp{...},@var{...}, get mapped to ... .
ret= Mx1_rewrap(m, &rpt, &wpt, line_out, */
"@command{", "\\fB", "\\fR", 0); rpt+= strlen(found);
ret= Mx1_rewrap(m, &rpt, &wpt, line_out, found, "", "", flag & 1);
if(ret <= 0)
return(ret);
} else if(typ == 3) {
/* @ref{...}, @xref{...} get mapped to empty text.
*/
rpt+= strlen(found);
ret= Mx1_rewrap(m, &rpt, &wpt, line_out, found , "", "",
(flag & 1) | 2);
if(ret <= 0) if(ret <= 0)
return(ret); return(ret);
@ -173,9 +263,16 @@ int Mx1_substitute(struct Mx1 *m, char line_in[256], char line_out[256],
strncmp(rpt, "@{", 2) == 0 || strncmp(rpt, "@{", 2) == 0 ||
strncmp(rpt, "@}", 2) == 0) { strncmp(rpt, "@}", 2) == 0) {
/* @@ , @{, @} will get stripped of their first @. */ /* @@ , @{, @} will get stripped of their first @. */
if((wpt - line_out) + 1 > 255)
goto overflow;
*(wpt++)= *(rpt + 1); *(wpt++)= *(rpt + 1);
rpt++; rpt++;
} else {
if((wpt - line_out) + 1 > 255)
goto overflow;
*(wpt++)= *(rpt);
} }
} else if(*rpt == '\\') { } else if(*rpt == '\\') {
@ -314,10 +411,8 @@ int Mx1_convert(struct Mx1 *m, char line_in[256], char line_out[256], int flag)
/* "\" becomes "\\" */ /* "\" becomes "\\" */
if(line_in[0] != '@' || if(line_in[0] != '@' ||
strncmp(line_in, "@strong{", 8) == 0 || Mx1_is_any_wrap(m, line_in, NULL, 0) > 0 ||
strncmp(line_in, "@command{", 9) == 0 ||
strncmp(line_in, "@minus{}", 8) == 0 || strncmp(line_in, "@minus{}", 8) == 0 ||
strncmp(line_in, "@email{", 7) == 0 ||
strncmp(line_in, "@@", 2) == 0 || strncmp(line_in, "@@", 2) == 0 ||
strncmp(line_in, "@{", 2) == 0 || strncmp(line_in, "@{", 2) == 0 ||
strncmp(line_in, "@}", 2) == 0 ) { strncmp(line_in, "@}", 2) == 0 ) {

View File

@ -24,9 +24,11 @@
@c up to "@c man-ignore-lines end". @c up to "@c man-ignore-lines end".
@c Line blocks of "@menu" "@end menu" will be discarded. @c Line blocks of "@menu" "@end menu" will be discarded.
@c "@item word words" becomes "\fBword\fR words". @c "@item word words" becomes "\fBword\fR words".
@c @strong{-...} gets mapped to \fB\-...\fR . @c @b{...}, @command{...}, @dfn{...}, @emph{...}, @strong{...}
@c @strong{...} gets mapped to \fB...\fR . @c get mapped to \fB...\fR .
@c @command{...} gets mapped to \fB...\fR . @c @abbr{...}, @code{...}, @file{...}, @i{...}, @option{...}, @r{...},
@c @ref{...}, @samp{...},@var{...}, get mapped to ... .
@c @ref{...}, @xref{...} get mapped to empty text.
@c @email{...} gets mapped to <...> . @c @email{...} gets mapped to <...> .
@c Mapped {...} content is subject to the rules except {...} mapping. @c Mapped {...} content is subject to the rules except {...} mapping.
@c @minus{} will become "-". @c @minus{} will become "-".

View File

@ -23,10 +23,12 @@
@c "@c man-ignore-lines begin" discards all following lines @c "@c man-ignore-lines begin" discards all following lines
@c up to "@c man-ignore-lines end". @c up to "@c man-ignore-lines end".
@c Line blocks of "@menu" "@end menu" will be discarded. @c Line blocks of "@menu" "@end menu" will be discarded.
@c "@item -word words" becomes "\fB\-word\fR words".
@c "@item word words" becomes "\fBword\fR words". @c "@item word words" becomes "\fBword\fR words".
@c @strong{...} gets mapped to \fB...\fR . @c @b{...}, @command{...}, @dfn{...}, @emph{...}, @strong{...}
@c @command{...} gets mapped to \fB...\fR . @c get mapped to \fB...\fR .
@c @abbr{...}, @code{...}, @file{...}, @i{...}, @option{...}, @r{...},
@c @ref{...}, @samp{...},@var{...}, get mapped to ... .
@c @ref{...}, @xref{...} get mapped to empty text.
@c @email{...} gets mapped to <...> . @c @email{...} gets mapped to <...> .
@c Mapped {...} content is subject to the rules except {...} mapping. @c Mapped {...} content is subject to the rules except {...} mapping.
@c @minus{} will become "-". @c @minus{} will become "-".