Index: class.c ================================================================== --- class.c +++ class.c @@ -1045,23 +1045,37 @@ define_macro(look_hash_mac(),0); goto again; case MAC_EDIT: if(!macros) ParseError("Cannot edit nonexistent macro\n"); nxttok(); - if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n"); - n=glohash[look_hash_mac()].id; - if(n<0xC000 || n>MAX_MACRO+0xC000-1 || !macros[n-0xC000]) ParseError("Undefined macro: {%s}\n",tokenstr); - nxttok(); - n-=0xC000; - if(macros[n]->t&(TF_MACRO|TF_EOF)) ParseError("Invalid edit token\n"); - free(macros[n]->str); - macros[n]->t=tokent; - macros[n]->v=tokenv; - macros[n]->str=0; - if(*tokenstr) { - macros[n]->str=strdup(tokenstr); - if(!macros[n]->str) fatal("Allocation failed\n"); + if(tokent==TF_INT) { + if(!macstack) ParseError("Empty macro stack\n"); + n=tokenv-1; + nxttok(); + if(n<0 || macstack->n<=n || !macstack->args[n]) ParseError("Cannot edit nonexistent argument %u\n",n+1); + macstack->args[n]->t=tokent; + macstack->args[n]->v=tokenv; + macstack->args[n]->str=0; + if(*tokenstr) { + macstack->args[n]->str=strdup(tokenstr); + if(!macstack->args[n]->str) fatal("Allocation failed\n"); + } + } else { + if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n"); + n=glohash[look_hash_mac()].id; + if(n<0xC000 || n>MAX_MACRO+0xC000-1 || !macros[n-0xC000]) ParseError("Undefined macro: {%s}\n",tokenstr); + nxttok(); + n-=0xC000; + if(macros[n]->t&(TF_MACRO|TF_EOF)) ParseError("Invalid edit token\n"); + free(macros[n]->str); + macros[n]->t=tokent; + macros[n]->v=tokenv; + macros[n]->str=0; + if(*tokenstr) { + macros[n]->str=strdup(tokenstr); + if(!macros[n]->str) fatal("Allocation failed\n"); + } } if(main_options['M']) { int i; printf("M= @%4d %04X %08X \"",linenum,tokent,tokenv); for(i=0;tokenstr[i];i++) { Index: class.doc ================================================================== --- class.doc +++ class.doc @@ -182,13 +182,15 @@ with multiple tokens becomes the token with one less backslash. It is permitted to redefine existing macros as well as new ones. {edit } Edit a macro. This changes the first token of the definition of the macro - (which must not be another macro) to the specified token (which also must - not be another macro). The token is expanded, and must be a single token - once it is expanded; that is what it will be replaced with. + (which must not be another macro) to the specified token. The token is + expanded, and must be a single token once it is expanded; that is what it + will be replaced with. There is a variant with a number in place of a + string; this will replace the argument of the macro which is currently + being expanded. {include } Include text from another file into this one. You cannot use {include} inside of another macro or in a macro argument. The file must be in the current directory, and its name must contain only letters, digits, dot,