void delete_macro (const char *name) { char *copy; size_t i, len; macro_entry *macro; len = strlen (name); copy = (char *) alloca (len + 1); for (i = 0; i < len; ++i) copy[i] = TOLOWER (name[i]); copy[i] = '\0'; /* Since hash_delete doesn't free memory, just clear out the entry. */ if ((macro = hash_find (macro_hash, copy)) != NULL) { hash_jam (macro_hash, copy, NULL); free_macro (macro); } else as_warn (_("Attempt to purge non-existant macro `%s'"), copy); }
void delete_macro (const char *name) { char *copy; size_t i, len; macro_entry *macro; len = strlen (name); copy = (char *) alloca (len + 1); for (i = 0; i < len; ++i) copy[i] = TOLOWER (name[i]); copy[i] = '\0'; /* We can only ask hash_delete to free memory if we are deleting macros in reverse order to their definition. So just clear out the entry. */ if ((macro = (macro_entry *) hash_find (macro_hash, copy)) != NULL) { hash_jam (macro_hash, copy, NULL); free_macro (macro); } else as_warn (_("Attempt to purge non-existant macro `%s'"), copy); }
const char * define_macro (int idx, sb *in, sb *label, int (*get_line) (sb *), char *file, unsigned int line, const char **namep) { macro_entry *macro; sb name; const char *error = NULL; macro = (macro_entry *) xmalloc (sizeof (macro_entry)); sb_new (¯o->sub); sb_new (&name); macro->file = file; macro->line = line; macro->formal_count = 0; macro->formals = 0; macro->formal_hash = hash_new (); idx = sb_skip_white (idx, in); if (! buffer_and_nest ("MACRO", "ENDM", ¯o->sub, get_line)) error = _("unexpected end of file in macro `%s' definition"); if (label != NULL && label->len != 0) { sb_add_sb (&name, label); macro->name = sb_terminate (&name); if (idx < in->len && in->ptr[idx] == '(') { /* It's the label: MACRO (formals,...) sort */ idx = do_formals (macro, idx + 1, in); if (idx < in->len && in->ptr[idx] == ')') idx = sb_skip_white (idx + 1, in); else if (!error) error = _("missing `)' after formals in macro definition `%s'"); } else { /* It's the label: MACRO formals,... sort */ idx = do_formals (macro, idx, in); } } else { int cidx; idx = get_token (idx, in, &name); macro->name = sb_terminate (&name); if (name.len == 0) error = _("Missing macro name"); cidx = sb_skip_white (idx, in); idx = sb_skip_comma (cidx, in); if (idx == cidx || idx < in->len) idx = do_formals (macro, idx, in); else idx = cidx; } if (!error && idx < in->len) error = _("Bad parameter list for macro `%s'"); /* And stick it in the macro hash table. */ for (idx = 0; idx < name.len; idx++) name.ptr[idx] = TOLOWER (name.ptr[idx]); if (hash_find (macro_hash, macro->name)) error = _("Macro `%s' was already defined"); if (!error) error = hash_jam (macro_hash, macro->name, (PTR) macro); if (namep != NULL) *namep = macro->name; if (!error) macro_defined = 1; else free_macro (macro); return error; }