From: "adr via 9fans" <9fans@9fans.net>
To: 9fans@9fans.net
Subject: [9fans] sam label and rio snarf buffer
Date: Tue, 20 Jul 2021 12:35:39 +0000 (UTC) [thread overview]
Message-ID: <f3e52beb-53e5-7838-15ae-4f7ca5985ed@SDF.ORG> (raw)
Hi,
I changed the last patch so sam wont change the label at startup.
I added a new option '-l' to set the label, it's more flexible and
doesn't chage the normal behavior. If samriosnarf is in /env, sam will
use rio's snarf buffer instead of the internal one.
This patch should apply to 9legacy, if you use the lab's distro
apply first sam-wheel.diff from 9legacy.
Regards,
adr.
--- sys/src/cmd/sam/cmd.c Wed Apr 24 00:06:05 2013
+++ /sys/src/cmd/sam/cmd.c Sun Jul 18 18:23:06 2021
@@ -17,6 +17,7 @@
'g', 0, 1, 0, 'p', aDot, 0, 0, g_cmd,
'i', 1, 0, 0, 0, aDot, 0, 0, i_cmd,
'k', 0, 0, 0, 0, aDot, 0, 0, k_cmd,
+ 'l', 0, 0, 0, 0, aNo, 0, linex, l_cmd,
'm', 0, 0, 1, 0, aDot, 0, 0, m_cmd,
'n', 0, 0, 0, 0, aNo, 0, 0, n_cmd,
'p', 0, 0, 0, 0, aDot, 0, 0, p_cmd,
--- sys/src/cmd/sam/mesg.c Fri Jan 12 17:02:55 2007
+++ /sys/src/cmd/sam/mesg.c Tue Jul 20 12:10:43 2021
@@ -1,4 +1,5 @@
#include "sam.h"
+#include <bio.h>
Header h;
uchar indata[DATASIZE];
@@ -348,17 +349,26 @@
f = whichfile(inshort());
p0 = inlong();
journaln(0, p0);
- for(l=0; l<snarfbuf.nc; l+=m){
- m = snarfbuf.nc-l;
- if(m>BLOCKSIZE)
- m = BLOCKSIZE;
- bufread(&snarfbuf, l, genbuf, m);
- loginsert(f, p0, tmprstr(genbuf, m)->s, m);
+
+ if(*(char*)inp != 0){
+ str = tmpcstr((char*)inp);
+ m = str->n;
+ loginsert(f, p0, str->s, m);
+ freetmpstr(str);
+ }else{
+ for(l=0; l<snarfbuf.nc; l+=m){
+ m = snarfbuf.nc-l;
+ if(m>BLOCKSIZE)
+ m = BLOCKSIZE;
+ bufread(&snarfbuf, l, genbuf, m);
+ loginsert(f, p0, tmprstr(genbuf, m)->s, m);
+ }
+ m = snarfbuf.nc;
}
if(fileupdate(f, FALSE, TRUE))
seq++;
f->dot.r.p1 = p0;
- f->dot.r.p2 = p0+snarfbuf.nc;
+ f->dot.r.p2 = p0+m;
f->tdot.p1 = -1; /* force telldot to tell (arguably a BUG) */
telldot(f);
outTs(Hunlockfile, f->tag);
--- sys/src/cmd/sam/mesg.h Fri Mar 18 22:33:33 2005
+++ /sys/src/cmd/sam/mesg.h Sun Jul 18 18:25:36 2021
@@ -67,6 +67,7 @@
Hack, /* request acknowledgement */
Hexit,
Hplumb, /* return plumb message to terminal - version 1 */
+ Hlabel, /* change /dev/label */
HMAX,
}Hmesg;
typedef struct Header{
--- sys/src/cmd/sam/parse.h Thu Oct 27 15:36:34 2005
+++ /sys/src/cmd/sam/parse.h Sat Jul 17 19:55:51 2021
@@ -55,13 +55,12 @@
int nl_cmd(File*, Cmd*), a_cmd(File*, Cmd*), b_cmd(File*, Cmd*);
int c_cmd(File*, Cmd*), cd_cmd(File*, Cmd*), d_cmd(File*, Cmd*);
-int D_cmd(File*, Cmd*), e_cmd(File*, Cmd*);
-int f_cmd(File*, Cmd*), g_cmd(File*, Cmd*), i_cmd(File*, Cmd*);
-int k_cmd(File*, Cmd*), m_cmd(File*, Cmd*), n_cmd(File*, Cmd*);
-int p_cmd(File*, Cmd*), q_cmd(File*, Cmd*);
-int s_cmd(File*, Cmd*), u_cmd(File*, Cmd*), w_cmd(File*, Cmd*);
-int x_cmd(File*, Cmd*), X_cmd(File*, Cmd*), plan9_cmd(File*, Cmd*);
-int eq_cmd(File*, Cmd*);
+int D_cmd(File*, Cmd*), e_cmd(File*, Cmd*), f_cmd(File*, Cmd*);
+int g_cmd(File*, Cmd*), i_cmd(File*, Cmd*), k_cmd(File*, Cmd*);
+int l_cmd(File*, Cmd*), m_cmd(File*, Cmd*), n_cmd(File*, Cmd*);
+int p_cmd(File*, Cmd*), q_cmd(File*, Cmd*), s_cmd(File*, Cmd*);
+int u_cmd(File*, Cmd*), w_cmd(File*, Cmd*), x_cmd(File*, Cmd*);
+int X_cmd(File*, Cmd*), plan9_cmd(File*, Cmd*), eq_cmd(File*, Cmd*);
String *getregexp(int);
--- sys/src/cmd/sam/sam.c Tue Dec 6 17:05:45 2005
+++ /sys/src/cmd/sam/sam.c Tue Jul 20 12:23:28 2021
@@ -25,6 +25,7 @@
int termlocked;
char *samterm = SAMTERM;
char *rsamname = RSAM;
+char *samtermlabel = nil;
File *lastfile;
Disk *disk;
long seq;
@@ -57,6 +58,9 @@
case 's':
rsamname = EARGF(usage());
break;
+ case 'l':
+ samtermlabel = EARGF(usage());
+ break;
default:
dprint("sam: unknown flag %c\n", ARGC());
usage();
@@ -82,6 +86,11 @@
startup(machine, Rflag, termargs, argv);
notify(notifyf);
getcurwd();
+ if(samtermlabel){
+ t=tmpcstr(samtermlabel);
+ outTS(Hlabel, t);
+ freetmpstr(t);
+ }
if(argc>0){
for(i=0; i<argc; i++){
if(!setjmp(mainloop)){
@@ -107,7 +116,7 @@
void
usage(void)
{
- dprint("usage: sam [-d] [-t samterm] [-s sam name] -r machine\n");
+ dprint("usage: sam [-d] [-t samterm] [-s sam name] -r machine -l label\n");
exits("usage");
}
--- sys/src/cmd/sam/xec.c Tue Jun 6 02:55:54 2000
+++ /sys/src/cmd/sam/xec.c Tue Jul 20 12:34:09 2021
@@ -26,7 +26,7 @@
if(f && f->unread)
load(f);
if(f==0 && (cp->addr==0 || cp->addr->type!='"') &&
- !utfrune("bBnqUXY!", cp->cmdc) &&
+ !utfrune("bBnqUXY!l", cp->cmdc) &&
cp->cmdc!=('c'|0x100) && !(cp->cmdc=='D' && cp->ctext))
error(Enofile);
i = lookup(cp->cmdc);
@@ -150,6 +150,14 @@
{
USED(cp);
f->mark = addr.r;
+ return TRUE;
+}
+
+int
+l_cmd(File *f, Cmd *cp)
+{
+ USED(f);
+ outTS(Hlabel, cp->ctext);
return TRUE;
}
--- sys/src/cmd/samterm/main.c Sat Jun 26 21:12:44 2021
+++ /sys/src/cmd/samterm/main.c Tue Jul 20 13:25:09 2021
@@ -1,5 +1,6 @@
#include <u.h>
#include <libc.h>
+#include <bio.h>
#include <draw.h>
#include <thread.h>
#include <cursor.h>
@@ -24,6 +25,7 @@
long modified = 0; /* strange lookahead for menus */
char hostlock = 1;
char hasunlocked = 0;
+char riosnarf = 0;
int maxtab = 8;
int autoindent;
@@ -35,6 +37,8 @@
Rectangle r;
Flayer *nwhich;
+ if(getenv("samriosnarf"))
+ riosnarf = 1;
getscreen(argc, argv);
iconinit();
initio();
@@ -250,10 +254,20 @@
snarf(Text *t, int w)
{
Flayer *l = &t->l[w];
-
+ Biobuf *bp;
if(l->p1>l->p0){
snarflen = l->p1-l->p0;
- outTsll(Tsnarf, t->tag, l->p0, l->p1);
+ if(riosnarf){
+ t = l->user1;
+ rload(&t->rasp, l->origin+l->p0, l->origin+l->p1, nil);
+ if((bp=Bopen("/dev/snarf", OWRITE)) == 0){
+ fprint(2, "samterm:snarf: can't open /dev/snarf for writing");
+ return;
+ }
+ Bprint(bp, "%S", scratch);
+ Bterm(bp);
+ }else
+ outTsll(Tsnarf, t->tag, l->p0, l->p1);
}
}
@@ -283,11 +297,39 @@
void
paste(Text *t, int w)
{
- if(snarflen){
- cut(t, w, 0, 0);
- t->lock++;
- outTsl(Tpaste, t->tag, t->l[w].p0);
+ Rune *rstr, *rp;
+ char *cstr, *cp;
+ Biobuf *bp;
+ int len;
+
+ if(riosnarf){
+ if((bp=Bopen("/dev/snarf", OREAD)) == 0){
+ fprint(2, "samterm:paste: can't open /dev/snarf");
+ return;
+ }
+ cstr = Brdstr(bp, '\0', 1);
+ if((len=Blinelen(bp)) == 0)
+ return;
+ rstr = malloc((len+1)*sizeof(Rune));
+ Bterm(bp);
+ if(rstr == 0){
+ fprint(2, "samterm:paste: can't allocate memory");
+ return;
+ }
+ rp = rstr;
+ cp = cstr;
+ while(*cp != '\0')
+ chartorune(rp++, cp++);
+ free(cstr);
+ *rp = L'\0';
+ }else{
+ if(!snarflen)
+ return;
+ rstr = L"";
}
+ cut(t, w, 0, 0);
+ t->lock++;
+ outTslS(Tpaste, t->tag, t->l[w].p0, rstr);
}
void
--- sys/src/cmd/samterm/menu.c Mon Feb 17 18:27:02 2003
+++ /sys/src/cmd/samterm/menu.c Tue Jul 20 13:01:39 2021
@@ -75,6 +75,8 @@
if(hversion==0 || plumbfd<0)
menu2str[Plumb] = "(plumb)";
+ if(riosnarf)
+ menu2str[Exch] = "(<rio>)";
m = menuhit(2, mousectl, t==&cmd? &menu2c : &menu2, nil);
if(hostlock || t->lock)
return;
@@ -98,6 +100,8 @@
break;
case Exch:
+ if(riosnarf)
+ break;
snarf(t, w);
outT0(Tstartsnarf);
setlock();
--- sys/src/cmd/samterm/mesg.c Thu Mar 29 19:35:49 2012
+++ /sys/src/cmd/samterm/mesg.c Tue Jul 20 11:57:48 2021
@@ -97,6 +97,7 @@
int i, m;
long l;
Flayer *lp;
+ char *str, c;
m = inshort(0);
l = inlong(2);
@@ -106,6 +107,18 @@
default:
fprint(2, "type %d\n", type);
panic("rcv unknown");
+
+ case Hlabel:
+ str = (char *)indata;
+ if((i = open("/dev/label", OWRITE)) < 0){
+ fprint(2, "samterm:label: can't open /dev/label for writing");
+ break;
+ }
+ while((c=*str) == ' ' || c=='\t')
+ str++;
+ fprint(i, "%s", str);
+ close(i);
+ break;
case Hversion:
hversion = m;
--- /n/dump/2021/0627/sys/src/cmd/samterm/samterm.h Sat Jun 26 21:13:32 2021
+++ /sys/src/cmd/samterm/samterm.h Tue Jul 20 12:57:48 2021
@@ -72,6 +72,7 @@
extern long nscralloc;
extern char hostlock;
extern char hasunlocked;
+extern char riosnarf;
extern long snarflen;
extern Mousectl* mousectl;
extern Keyboardctl* keyboardctl;
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Tc809ad6007ccd2bd-M59fa74810ca5d9af98fce3fb
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
next reply other threads:[~2021-07-20 12:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 12:35 adr via 9fans [this message]
2021-07-20 18:01 ` Skip Tavakkolian
2021-07-20 19:21 ` adr via 9fans
2021-07-20 20:23 ` Skip Tavakkolian
2021-07-20 20:49 ` adr via 9fans
2021-07-20 21:27 ` Stuart Morrow
2021-07-20 21:36 ` Peter Mikkelsen
2021-07-20 22:35 ` Stuart Morrow
2021-07-20 22:12 ` Ethan Gardener
2021-07-20 23:01 ` ori
2021-07-20 23:39 ` adr via 9fans
2021-07-21 3:32 ` Lucio De Re
2021-07-21 8:00 ` hiro
2021-07-23 21:44 ` adr via 9fans
2021-07-23 22:25 ` umbraticus
2021-07-20 21:27 ` adr via 9fans
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=f3e52beb-53e5-7838-15ae-4f7ca5985ed@SDF.ORG \
--to=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).