summaryrefslogtreecommitdiffstats
path: root/contrib/texinfo/makeinfo/macro.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/texinfo/makeinfo/macro.c')
-rw-r--r--contrib/texinfo/makeinfo/macro.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/contrib/texinfo/makeinfo/macro.c b/contrib/texinfo/makeinfo/macro.c
index 357d4ac..ef33a53 100644
--- a/contrib/texinfo/makeinfo/macro.c
+++ b/contrib/texinfo/makeinfo/macro.c
@@ -1,7 +1,7 @@
/* macro.c -- user-defined macros for Texinfo.
- $Id: macro.c,v 1.1 2002/08/25 23:38:38 karl Exp $
+ $Id: macro.c,v 1.2 2003/06/01 23:41:23 karl Exp $
- Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -322,7 +322,7 @@ apply (named, actuals, body)
else
{ /* Snarf parameter name, check against named parameters. */
char *param;
- int param_start, which, len;
+ int param_start, len;
param_start = ++i;
while (body[i] && body[i] != '\\')
@@ -336,29 +336,38 @@ apply (named, actuals, body)
if (body[i]) /* move past \ */
i++;
- /* Now check against named parameters. */
- for (which = 0; named && named[which]; which++)
- if (STREQ (named[which], param))
- break;
-
- if (named && named[which])
- {
- text = which < length_of_actuals ? actuals[which] : NULL;
- if (!text)
- text = "";
- len = strlen (text);
- }
- else
- { /* not a parameter, either it's \\ (if len==0) or an
- error. In either case, restore one \ at least. */
- if (len) {
- warning (_("\\ in macro expansion followed by `%s' instead of \\ or parameter name"),
- param);
- }
+ if (len == 0)
+ { /* \\ always means \, even if macro has no args. */
len++;
text = xmalloc (1 + len);
sprintf (text, "\\%s", param);
}
+ else
+ {
+ int which;
+
+ /* Check against named parameters. */
+ for (which = 0; named && named[which]; which++)
+ if (STREQ (named[which], param))
+ break;
+
+ if (named && named[which])
+ {
+ text = which < length_of_actuals ? actuals[which] : NULL;
+ if (!text)
+ text = "";
+ len = strlen (text);
+ text = xstrdup (text); /* so we can free it */
+ }
+ else
+ { /* not a parameter, so it's an error. */
+ warning (_("\\ in macro expansion followed by `%s' instead of parameter name"),
+ param);
+ len++;
+ text = xmalloc (1 + len);
+ sprintf (text, "\\%s", param);
+ }
+ }
if (strlen (param) + 2 < len)
{
@@ -371,8 +380,7 @@ apply (named, actuals, body)
strcpy (new_body + new_body_index, text);
new_body_index += len;
- if (!named || !named[which])
- free (text);
+ free (text);
}
}
OpenPOWER on IntegriCloud