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 LONG macuniq; // Unique-per-macro number
|
||||||
static SYM * curmac; // Macro currently being defined
|
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 * firstrpt; // First .rept line
|
||||||
static LLIST * nextrpt; // Last .rept line
|
static LLIST * nextrpt; // Last .rept line
|
||||||
static int rptlevel; // .rept nesting level
|
int rptlevel; // .rept nesting level
|
||||||
|
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
static int KWMatch(char *, char *);
|
static int KWMatch(char *, char *);
|
||||||
|
@ -40,6 +41,7 @@ void InitMacro(void)
|
||||||
{
|
{
|
||||||
macuniq = 0;
|
macuniq = 0;
|
||||||
macnum = 1;
|
macnum = 1;
|
||||||
|
reptuniq = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
2
macro.h
2
macro.h
|
@ -14,6 +14,8 @@
|
||||||
// Exported variables
|
// Exported variables
|
||||||
extern LONG curuniq;
|
extern LONG curuniq;
|
||||||
extern TOKEN * argPtrs[];
|
extern TOKEN * argPtrs[];
|
||||||
|
extern LONG reptuniq;
|
||||||
|
extern int rptlevel;
|
||||||
|
|
||||||
// Exported functions
|
// Exported functions
|
||||||
void InitMacro(void);
|
void InitMacro(void);
|
||||||
|
|
31
token.c
31
token.c
|
@ -699,7 +699,7 @@ char * GetNextRepeatLine(void)
|
||||||
DEBUG { printf("end-repeat-block\n"); }
|
DEBUG { printf("end-repeat-block\n"); }
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
reptuniq++;
|
||||||
// strp = irept->ir_nextln;
|
// strp = irept->ir_nextln;
|
||||||
}
|
}
|
||||||
// Mark the current macro line in the irept object
|
// Mark the current macro line in the irept object
|
||||||
|
@ -708,8 +708,33 @@ char * GetNextRepeatLine(void)
|
||||||
// error reporting anyway)
|
// error reporting anyway)
|
||||||
irept->lineno = irept->ir_nextln->lineno;
|
irept->lineno = irept->ir_nextln->lineno;
|
||||||
|
|
||||||
// strcpy(irbuf, (char *)(irept->ir_nextln + 1));
|
// Copy the rept lines verbatim, unless we're in nest level 0.
|
||||||
strcpy(irbuf, irept->ir_nextln->line);
|
// 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); }
|
DEBUG { printf("repeat line='%s'\n", irbuf); }
|
||||||
// irept->ir_nextln = (LONG *)*strp;
|
// irept->ir_nextln = (LONG *)*strp;
|
||||||
irept->ir_nextln = irept->ir_nextln->next;
|
irept->ir_nextln = irept->ir_nextln->next;
|
||||||
|
|
Loading…
Reference in New Issue