> i looked at modifying rc to write commands to a history file but it
> didn't seem to fit very well. maybe a hook would be better as in

it's not hard.  perhaps you object to rc's reformatting of
what you typed?

diff -c ./exec.c h/exec.c
./exec.c:9,14 - h/exec.c:9,16
  #include "exec.h"
  #include "io.h"
  #include "fns.h"
+
+ tree *line;
  /*
   * Start executing the given code at the given pc with the given redirection
   */
./exec.c:112,118 - h/exec.c:114,120
  {
        code bootstrap[32];
        char num[12], *rcmain;
-       int i;
+       int i, fd;
        
        /* needed for rcmain later */
        putenv("PLAN9", unsharp("#9"));
./exec.c:123,128 - h/exec.c:125,132
        if(flag['I']) flag['i'] = 0;
        else if(flag['i']==0 && argc==1 && Isatty(0)) flag['i'] = flagset;
        rcmain=flag['m']?flag['m'][0]:Rcmain();
+       if((fd = open("/tmp/history", OWRITE)) >= 0)
+               history=openfd(fd);
        err=openfd(2);
        kinit();
        Trapinit();
./exec.c:773,778 - h/exec.c:777,788
                }
        }
        else{
+               if(p->iflag && history && line){
+                       char buf[30];
+                       strcpy(buf, ctime(time(0)));
+                       buf[28] = 0;
+                       pfmt(history, "%s %t\n", buf, line);
+               }
                ntrap = 0;      /* avoid double-interrupts during blocked 
writes */
                --p->pc;        /* re-execute Xrdcmds after codebuf runs */
                start(codebuf, 1, runq->local);
diff -c ./io.h h/io.h
./io.h:11,16 - h/io.h:11,17
        char *bufp, *ebuf, *strp, buf[NBUF];
  };
  io *err;
+ io *history;
  io *openfd(int), *openstr(void), *opencore(char *, int);
  int emptybuf(io*);
  void pchr(io*, int);
diff -c ./rc.h h/rc.h
./rc.h:143,145 - h/rc.h:143,146
  int lastc;
  int lastword;
  int kidpid;
+ extern tree *line;
diff -c ./syn.y h/syn.y
./syn.y:21,28 - h/syn.y:21,28
  %type<tree> NOT FOR IN WHILE IF TWIDDLE BANG SUBSHELL SWITCH FN
  %type<tree> WORD REDIR DUP PIPE
  %%
- rc:                           { return 1;}
- |     line '\n'               {return !compile($1);}
+ rc:                           { line = nil; return 1;}
+ |     line '\n'               { line = $1; return !compile($1);}
  line: cmd
  |     cmdsa line              {$$=tree2(';', $1, $2);}
  body: cmd

Reply via email to