summaryrefslogtreecommitdiff
path: root/sys/src/cmd/rc/pfnc.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2021-12-31 15:27:10 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2021-12-31 15:27:10 +0000
commitb90036a062ca330ac5f667cd1ee503686cbe0b80 (patch)
treeab9538715188d5017843c6d94e2ee4c5e155448a /sys/src/cmd/rc/pfnc.c
parent855cf4326f5a07d7142c2d8918f5fa856d912b85 (diff)
rc: fix everything
Untangle the lexer and interpreter thread state. Fix the file and line number error reporting, getting rid of Xsrcfile instruction, as the whole code block can only come from a single file, stuff the source file in slot[1] of the code block instead. Remove limitations for globber (path element limits) and be more intelligent about handling globbing by inserting Xglob instruction only when needed and not run it over every Xsimple argument list. Remove fragile ndot magic and make it explicit by adding the -q flag to . builtin command. Add -b flag for full compilation. Make exitnext() smart, so we can speculate thru rcmain and avoid the fork(). Get rid of all print(2) format functions and use io instead. Improve the io library, adding rstr() to handle tokenization, which allows us to look ahead in the already read buffer for the terminators, avoiding alot of string copies. Auto indent pcmd(), to make line number reporting more usefull. Implement here documents properly, so they can work everywhere.
Diffstat (limited to 'sys/src/cmd/rc/pfnc.c')
-rw-r--r--sys/src/cmd/rc/pfnc.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/sys/src/cmd/rc/pfnc.c b/sys/src/cmd/rc/pfnc.c
index 83f871ff8..e975d59af 100644
--- a/sys/src/cmd/rc/pfnc.c
+++ b/sys/src/cmd/rc/pfnc.c
@@ -18,8 +18,10 @@ struct{
Xjump, "Xjump",
Xmark, "Xmark",
Xpopm, "Xpopm",
+ Xpush, "Xpush",
Xrdwr, "Xrdwr",
Xread, "Xread",
+ Xhere, "Xhere",
Xreturn, "Xreturn",
Xtrue, "Xtrue",
Xif, "Xif",
@@ -44,31 +46,33 @@ struct{
Xbackq, "Xbackq",
Xpipefd, "Xpipefd",
Xsubshell, "Xsubshell",
- Xdelhere, "Xdelhere",
Xfor, "Xfor",
Xglob, "Xglob",
- Xglobs, "Xglobs",
- Xrdfn, "Xrdfn",
Xsimple, "Xsimple",
Xqw, "Xqw",
Xsrcline, "Xsrcline",
0};
void
-pfnc(io *fd, thread *t)
+pfun(io *f, void (*fn)(void))
{
int i;
- void (*fn)(void) = t->code[t->pc].f;
- list *a;
-
- pfmt(fd, "%s:%d: pid %d cycle %p %d ", t->cmdfile, t->line, getpid(), t->code, t->pc);
for(i = 0;fname[i].f;i++) if(fname[i].f==fn){
- pstr(fd, fname[i].name);
- break;
+ pstr(f, fname[i].name);
+ return;
}
- if(!fname[i].f)
- pfmt(fd, "%p", fn);
- for(a = t->argv;a;a = a->next) pfmt(fd, " (%v)", a->words);
- pchr(fd, '\n');
- flush(fd);
+ pfmt(f, "%p", fn);
+}
+
+void
+pfnc(io *f, thread *t)
+{
+ list *a;
+
+ pfln(f, srcfile(t), t->line);
+ pfmt(f, " pid %d cycle %p %d ", getpid(), t->code, t->pc);
+ pfun(f, t->code[t->pc].f);
+ for(a = t->argv;a;a = a->next) pfmt(f, " (%v)", a->words);
+ pchr(f, '\n');
+ flushio(f);
}