+ int i;
+ struct macro_definition *loc = (struct macro_definition *) ptr;
+
+ for (i = 0; i < loc->argc; ++i)
+ xfree ((char *) loc->argv[i]);
+ xfree ((char *) loc->argv);
+ /* Note that the 'replacement' field is not allocated. */
+}
+
+static void
+macro_define_command (const char *exp, int from_tty)
+{
+ struct macro_definition new_macro;
+ char *name = NULL;
+ struct cleanup *cleanup_chain;
+
+ if (!exp)
+ error (_("usage: macro define NAME[(ARGUMENT-LIST)] [REPLACEMENT-LIST]"));
+
+ cleanup_chain = make_cleanup (free_macro_definition_ptr, &new_macro);
+ make_cleanup (free_current_contents, &name);
+
+ memset (&new_macro, 0, sizeof (struct macro_definition));
+
+ skip_ws (&exp);
+ name = extract_identifier (&exp, 0);
+ if (! name)
+ error (_("Invalid macro name."));
+ if (*exp == '(')
+ {
+ /* Function-like macro. */
+ int alloced = 5;
+ char **argv = XNEWVEC (char *, alloced);
+
+ new_macro.kind = macro_function_like;
+ new_macro.argc = 0;
+ new_macro.argv = (const char * const *) argv;
+
+ /* Skip the '(' and whitespace. */
+ ++exp;
+ skip_ws (&exp);
+
+ while (*exp != ')')
+ {
+ int i;
+
+ if (new_macro.argc == alloced)
+ {
+ alloced *= 2;
+ argv = (char **) xrealloc (argv, alloced * sizeof (char *));
+ /* Must update new_macro as well... */
+ new_macro.argv = (const char * const *) argv;
+ }
+ argv[new_macro.argc] = extract_identifier (&exp, 1);
+ if (! argv[new_macro.argc])
+ error (_("Macro is missing an argument."));
+ ++new_macro.argc;
+
+ for (i = new_macro.argc - 2; i >= 0; --i)
+ {
+ if (! strcmp (argv[i], argv[new_macro.argc - 1]))
+ error (_("Two macro arguments with identical names."));
+ }
+
+ skip_ws (&exp);
+ if (*exp == ',')
+ {
+ ++exp;
+ skip_ws (&exp);
+ }
+ else if (*exp != ')')
+ error (_("',' or ')' expected at end of macro arguments."));
+ }
+ /* Skip the closing paren. */
+ ++exp;
+ skip_ws (&exp);
+
+ macro_define_function (macro_main (macro_user_macros), -1, name,
+ new_macro.argc, (const char **) new_macro.argv,
+ exp);
+ }
+ else
+ {
+ skip_ws (&exp);
+ macro_define_object (macro_main (macro_user_macros), -1, name, exp);
+ }
+
+ do_cleanups (cleanup_chain);