From: erik quanstrom <quanstro@coraid.com>
To: 9fans@9fans.net
Subject: Re: [9fans] Practical issue on using rc shell
Date: Fri, 13 Nov 2009 13:52:01 -0500 [thread overview]
Message-ID: <8311b8880d5e66ab863f13666d32ec16@coraid.com> (raw)
In-Reply-To: <hdk999$o4r$1@ger.gmane.org>
what i find i can't live without is a record
of the commands i've typed. sometimes a
one-liner from last week is useful. i use the
commands - and -- (source: /n/sources/contrib/quanstro/src/history.c)
along with the following patch to rc to make it
go.
- erik
; 9diff fns.h
/n/sources/plan9//sys/src/cmd/rc/fns.h:61,66 - fns.h:61,67
void start(code*, int, var*);
int truestatus(void);
void usage(char*);
+ void whistory(tree*);
int wordchr(int);
void yyerror(char*);
int yylex(void);
; 9diff *.y
post...
/n/sources/plan9//sys/src/cmd/rc/syn.y:12,17 - syn.y:12,28
%{
#include "rc.h"
#include "fns.h"
+
+ int
+ hcompile(tree *t)
+ {
+ int i;
+
+ if(i = compile(t))
+ whistory(t);
+ return !i;
+ }
+
%}
%union{
struct tree *tree;
/n/sources/plan9//sys/src/cmd/rc/syn.y:22,28 - syn.y:33,39
%type<tree> WORD REDIR DUP PIPE
%%
rc: { return 1;}
- | line '\n' {return !compile($1);}
+ | line '\n' { return hcompile($1); }
line: cmd
| cmdsa line {$$=tree2(';', $1, $2);}
body: cmd
; cat history.c
#include "rc.h"
#include "exec.h"
#include "fns.h"
#include "io.h"
void
whistory(tree *t){
char* s;
int fd, flags;
io* o;
var* v;
if(!runq->iflag || !t)
return;
v = vlook("history");
if(!v->val || count(v->val) != 1)
return;
if(v->fn)
return; /* fn history {echo $*>>$history_file} ? */
s = v->val->word;
flags = OWRITE;
if((fd=open(s, flags))<0 && (fd=create(s, flags, DMAPPEND|0666L))<0){
/* setvar("history", 0); */
return;
}
o = openfd(fd);
seek(fd, 0, 2);
pfmt(o, "%t\n", t);
closeio(o);
}
next prev parent reply other threads:[~2009-11-13 18:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-13 18:41 Maurício CA
2009-11-13 18:52 ` erik quanstrom [this message]
2009-11-13 18:54 ` Tim Newsham
2009-11-13 19:02 ` David Leimbach
2009-11-13 20:46 ` pmarin
2009-11-13 20:50 ` Venkatesh Srinivas
2009-11-13 20:55 ` Roman Shaposhnik
2009-11-13 21:00 ` Nick LaForge
2009-11-13 21:10 ` pmarin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8311b8880d5e66ab863f13666d32ec16@coraid.com \
--to=quanstro@coraid.com \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).