Skip to content

Commit

Permalink
Add ^K ^SPACE. Allow multi-line macro definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhallen committed Mar 24, 2015
1 parent 33dea0c commit a64c51e
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 57 deletions.
50 changes: 36 additions & 14 deletions joe/rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,34 @@ int umode(BW *bw)
}
}

/* Parse a macro- allow it to cross lines */

MACRO *multiparse(JFILE *fd, int *refline, unsigned char *buf, int *ofst, int *referr, unsigned char *name)
{
MACRO *m;
int x = *ofst;
int err = *referr;
int line = *refline;
m = 0;
for (;;) {
m = mparse(m, buf + x, &x, 0);
if (x == -1) { /* Error */
err = -1;
logerror_2((char *)joe_gettext(_("%s %d: Unknown command in macro\n")), name, line);
break;
} else if (x == -2) { /* Get more input */
jfgets(buf, 1024, fd);
++line;
x = 0;
} else /* We're done */
break;
}
*referr = err;
*refline = line;
*ofst = x;
return m;
}

/* Process rc file
* Returns 0 if the rc file was succefully processed
* -1 if the rc file couldn't be opened
Expand All @@ -1368,6 +1396,7 @@ int procrc(CAP *cap, unsigned char *name)
KMAP *context = NULL; /* Current context */
struct rc_menu *current_menu = NULL;
unsigned char buf[1024]; /* Input buffer */
unsigned char buf1[1024]; /* Input buffer */
JFILE *fd; /* rc file */
int line = 0; /* Line number */
int err = 0; /* Set to 1 if there was a syntax error */
Expand Down Expand Up @@ -1462,13 +1491,14 @@ int procrc(CAP *cap, unsigned char *name)
for (y = x; !joe_isspace_eof(locale_map,buf[y]); ++y) ;
c = buf[y];
buf[y] = 0;
zlcpy(buf1, sizeof(buf1), buf + x);
if (y != x) {
int sta;
int sta = y + 1;
MACRO *m;

if (joe_isblank(locale_map,c)
&& (m = mparse(NULL, buf + y + 1, &sta, 0)))
addcmd(buf + x, m);
&& (m = multiparse(fd, &line, buf, &sta, &err, name)))
addcmd(buf1, m);
else {
err = 1;
logerror_2((char *)joe_gettext(_("%s %d: macro missing from :def\n")), name, line);
Expand Down Expand Up @@ -1585,18 +1615,10 @@ int procrc(CAP *cap, unsigned char *name)
break;
}

m = 0;
macroloop:
m = mparse(m, buf, &x, 0);
if (x == -1) {
err = 1;
logerror_2((char *)joe_gettext(_("%s %d: Unknown command in macro\n")), name, line);
x = 0;
m = multiparse(fd, &line, buf, &x, &err, name);
if (x == -1)
break;
} else if (x == -2) {
jfgets(buf, 1024, fd);
++line;
goto macroloop;
}
if (!m)
break;

Expand Down
Loading

0 comments on commit a64c51e

Please sign in to comment.