Implemented texi-to-man translation rule about {...} recursion

This commit is contained in:
Thomas Schmitt 2011-05-17 09:18:18 +00:00
parent b9d2858bf4
commit b0b584305f

View File

@ -38,6 +38,10 @@ struct Mx1 {
};
int Mx1_substitute(struct Mx1 *m, char line_in[256], char line_out[256],
int raw, int upto, int flag);
int Mx1_init(struct Mx1 *m, char *prog, int flag)
{
@ -78,81 +82,116 @@ int Mx1__get_word(char *line, char word[256], char **remainder, int flag)
}
int Mx1_substitute(struct Mx1 *m, char line_in[256], char line_out[256],
int raw, int flag)
/* @param flag bit0= recursion
*/
int Mx1_rewrap(struct Mx1 *m, char **read_pt, char **write_pt,
char *write_base, char *envelope,
char *front, char *back,
int flag)
{
char *rpt, *wpt, *ept;
int l;
char *rpt, *wpt, *ept, content[256], msg[256];
int l, ret;
rpt= *read_pt;
wpt= *write_pt;
ept= strchr(rpt, '}');
if(ept == NULL) {
sprintf(msg, "No closing bracket found for '%s'", envelope);
Mx1_report_error(m, msg, 0);
return(-1);
}
/* Mapped {...} content is subject to the rules except {...} mapping. */
l= ept - rpt;
ret= Mx1_substitute(m, rpt, content, 0, l, 1);
if(ret <= 0)
return(ret);
l= strlen(content);
if((wpt - write_base) + l + strlen(front) + strlen(back) > 255) {
Mx1_report_error(m, "Line length overflow while text substitution", 0);
return(-1);
}
strcpy(wpt, front);
wpt+= strlen(front);
strncpy(wpt, content, l);
wpt+= l;
strcpy(wpt, back);
wpt+= strlen(back);
(*read_pt)+= ept - rpt;
(*write_pt)= wpt;
return(1);
}
/* @param flag bit0= recursion
*/
int Mx1_substitute(struct Mx1 *m, char line_in[256], char line_out[256],
int raw, int upto, int flag)
{
char *rpt, *wpt;
int ret;
wpt= line_out;
for(rpt= line_in; *rpt != 0; rpt++) {
for(rpt= line_in; rpt - line_in < upto && *rpt != 0; rpt++) {
if(rpt - line_in < raw) {
*(wpt++)= *rpt;
continue;
}
if(*rpt == '@') {
if(strncmp(rpt, "@strong{", 8) == 0) {
/* @strong{-...} gets mapped to \fB\-...\fR . */;
if(strncmp(rpt, "@strong{", 8) == 0 && !(flag & 1)) {
/* @strong{...} gets mapped to \fB...\fR . */
ept= strchr(rpt, '}');
if(ept == NULL) {
Mx1_report_error(m, "No closing bracket found for '@strong{'", 0);
return(-1);
}
l= ept - rpt - 8;
if((wpt - line_out) + l + 6 + (rpt[8] == '-') > 255)
goto overflow;
strcpy(wpt, "\\fB");
wpt+= 3;
if(rpt[8] == '-')
*(wpt++)= '\\';
strncpy(wpt, rpt + 8, l);
wpt+= l;
strcpy(wpt, "\\fR");
wpt+= 3;
rpt+= ept - rpt;
} else if(strncmp(rpt, "@command{}", 9) == 0) {
rpt+= 8;
ret= Mx1_rewrap(m, &rpt, &wpt, line_out,
"@strong{" , "\\fB", "\\fR", 0);
if(ret <= 0)
return(ret);
} else if(strncmp(rpt, "@command{", 9) == 0 && !(flag & 1)) {
/* @command{...} gets mapped to \fB...\fR . */
ept= strchr(rpt, '}');
if(ept == NULL) {
Mx1_report_error(m, "No closing bracket found for '@command{'", 0);
return(-1);
}
l= ept - rpt - 9;
if((wpt - line_out) + l + 6 + (rpt[9] == '-') > 255)
goto overflow;
strcpy(wpt, "\\fB");
wpt+= 3;
strncpy(wpt, rpt + 9, l);
wpt+= l;
strcpy(wpt, "\\fR");
wpt+= 3;
rpt+= ept - rpt;
rpt+= 9;
ret= Mx1_rewrap(m, &rpt, &wpt, line_out,
"@command{", "\\fB", "\\fR", 0);
if(ret <= 0)
return(ret);
} else if(strncmp(rpt, "@email{", 7) == 0 && !(flag & 1)) {
/* @email{...} gets mapped to <...> . */
rpt+= 7;
ret= Mx1_rewrap(m, &rpt, &wpt, line_out, "@email{", "<", ">", 0);
if(ret <= 0)
return(ret);
} else if(strncmp(rpt, "@minus{}", 8) == 0) {
/* @minus{} will become "-". */
if((wpt - line_out) + 1 > 255)
goto overflow;
*(wpt++)= '-';
rpt+= 7;
} else if(strncmp(rpt, "@@", 2) == 0 ||
strncmp(rpt, "@{", 2) == 0 ||
strncmp(rpt, "@}", 2) == 0) {
/* @@ , @{, @} will get stripped of their first @. */
*(wpt++)= *(rpt + 1);
rpt++;
}
} else if(*rpt == '\\') {
/* "\" becomes "\\" */
if((wpt - line_out) + 2 > 255)
goto overflow;
*(wpt++)= '\\';
*(wpt++)= '\\';
} else if((wpt - line_out) + 1 > 255) {
overflow:;
Mx1_report_error(m, "Line length overflow while text substitution", 0);
return(-1);
} else
*(wpt++)= *rpt;
}
*wpt= 0;
return(1);
@ -250,7 +289,7 @@ int Mx1_convert(struct Mx1 *m, char line_in[256], char line_out[256], int flag)
/* Substitute option text */
raw= strlen(buf);
strcat(buf, word);
ret= Mx1_substitute(m, buf, line_out, raw, 0);
ret= Mx1_substitute(m, buf, line_out, raw, strlen(buf), 0);
if(ret <= 0)
return(-1);
strcpy(buf, line_out);
@ -260,28 +299,30 @@ int Mx1_convert(struct Mx1 *m, char line_in[256], char line_out[256], int flag)
strcat(buf, remainder);
/* Substitute arguments text */
ret= Mx1_substitute(m, buf, line_out, raw, 0);
ret= Mx1_substitute(m, buf, line_out, raw, strlen(buf), 0);
if(ret <= 0)
return(-1);
m->count_out++;
return(1);
}
/* @strong{-...} gets mapped to \fB\-...\fR . */
/* @strong{... } gets mapped to \fB...\fR . */
/* @command{... } gets mapped to \fB...\fR . */
/* @minus{} will become "-". */
/* Mapped {...} content is subject to the rules except {...} mapping. */
/* @@ , @{, @} will get stripped of their first @. */
/* "\" becomes "\\" */
if(line_in[0] != '@' ||
strncmp(line_in, "@strong{", 8) == 0 ||
strncmp(line_in, "@command{", 9) == 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 ) {
keep= 1;
ret= Mx1_substitute(m, line_in, line_out, 0, 0);
ret= Mx1_substitute(m, line_in, line_out, 0, strlen(line_in), 0);
if(ret <= 0)
return(-1);
}
@ -330,7 +371,7 @@ int main(int argc, char **argv)
if(argc < 2) {
usage:;
fprintf(stderr, "usage: %s -auto|-filter|[-xorrisofs]\n", argv[0]);
fprintf(stderr, "usage: %s -auto|-filter [-xorrisofs]\n", argv[0]);
fprintf(stderr, " -auto xorriso/xorriso.texi -> xorriso/xorriso.1\n");
fprintf(stderr, " -filter stdin -> stdout\n");
fprintf(stderr, " -xorrisofs process xorriso/xorrisofs.texi\n");