mirror of http://shamusworld.gotdns.org/git/rmac
Expand \~ in .REPTs to unique label names as in macros. (issue #75)
This commit is contained in:
parent
58c0626339
commit
721ff28e66
6
macro.c
6
macro.c
|
@ -22,11 +22,12 @@ int macnum; // Unique number for macro definition
|
|||
|
||||
static LONG macuniq; // Unique-per-macro number
|
||||
static SYM * curmac; // Macro currently being defined
|
||||
static uint32_t argno; // Formal argument count
|
||||
static uint32_t argno; // Formal argument count
|
||||
LONG reptuniq; // Unique-per-rept number
|
||||
|
||||
static LLIST * firstrpt; // First .rept line
|
||||
static LLIST * nextrpt; // Last .rept line
|
||||
static int rptlevel; // .rept nesting level
|
||||
int rptlevel; // .rept nesting level
|
||||
|
||||
// Function prototypes
|
||||
static int KWMatch(char *, char *);
|
||||
|
@ -40,6 +41,7 @@ void InitMacro(void)
|
|||
{
|
||||
macuniq = 0;
|
||||
macnum = 1;
|
||||
reptuniq = 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
2
macro.h
2
macro.h
|
@ -14,6 +14,8 @@
|
|||
// Exported variables
|
||||
extern LONG curuniq;
|
||||
extern TOKEN * argPtrs[];
|
||||
extern LONG reptuniq;
|
||||
extern int rptlevel;
|
||||
|
||||
// Exported functions
|
||||
void InitMacro(void);
|
||||
|
|
31
token.c
31
token.c
|
@ -699,7 +699,7 @@ char * GetNextRepeatLine(void)
|
|||
DEBUG { printf("end-repeat-block\n"); }
|
||||
return NULL;
|
||||
}
|
||||
|
||||
reptuniq++;
|
||||
// strp = irept->ir_nextln;
|
||||
}
|
||||
// Mark the current macro line in the irept object
|
||||
|
@ -708,8 +708,33 @@ char * GetNextRepeatLine(void)
|
|||
// error reporting anyway)
|
||||
irept->lineno = irept->ir_nextln->lineno;
|
||||
|
||||
// strcpy(irbuf, (char *)(irept->ir_nextln + 1));
|
||||
strcpy(irbuf, irept->ir_nextln->line);
|
||||
// Copy the rept lines verbatim, unless we're in nest level 0.
|
||||
// Then, expand any \~ labels to unique numbers (Rn)
|
||||
if (rptlevel)
|
||||
{
|
||||
strcpy(irbuf, irept->ir_nextln->line);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t linelen = strlen(irept->ir_nextln->line);
|
||||
uint8_t *p_line = irept->ir_nextln->line;
|
||||
char *irbufwrite = irbuf;
|
||||
for (int i = 0; i <= linelen; i++)
|
||||
{
|
||||
uint8_t c;
|
||||
c = *p_line++;
|
||||
if (c == '\\' && *p_line == '~')
|
||||
{
|
||||
p_line++;
|
||||
irbufwrite += sprintf(irbufwrite, "R%u", reptuniq);
|
||||
}
|
||||
else
|
||||
{
|
||||
*irbufwrite++ = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG { printf("repeat line='%s'\n", irbuf); }
|
||||
// irept->ir_nextln = (LONG *)*strp;
|
||||
irept->ir_nextln = irept->ir_nextln->next;
|
||||
|
|
Loading…
Reference in New Issue