shithub: sam

Download patch

ref: 7c078308937f364f85ca6b79371508127510372f
parent: 1e251253cd042dfe9a9392d56dfaf59989df5302
author: Aidan Wiggins <akw@oneiri.one>
date: Tue Apr 29 01:49:49 EDT 2025

Several temporary changes.

--- a/sam/mesg.c
+++ b/sam/mesg.c
@@ -38,7 +38,6 @@
 	[Hcheck]	"Hcheck",
 	[Hunlock]	"Hunlock",
 	[Hdata]		"Hdata",
-	[Horigin]	"Horigin",
 	[Hunlockfile]	"Hunlockfile",
 	[Hsetdot]	"Hsetdot",
 	[Hgrowdata]	"Hgrowdata",
@@ -62,7 +61,6 @@
 	[Tstartcmdfile]	"Tstartcmdfile",
 	[Tcheck]	"Tcheck",
 	[Trequest]	"Trequest",
-	[Torigin]	"Torigin",
 	[Tstartfile]	"Tstartfile",
 	[Tworkfile]	"Tworkfile",
 	[Ttype]		"Ttype",
@@ -168,7 +166,6 @@
 	Rune buf[1025];
 	char cbuf[64];
 	int i, m;
-	short s, s1;
 	long l;
 	vlong v;
 	File *f;
@@ -244,18 +241,6 @@
 		}
 		buf[i] = 0;
 		outTslS(Hdata, f->tag, r.p1, tmprstr(buf, i+1));
-		break;
-
-	case Torigin:
-		s = inshort();
-		l = inlong()-1;
-		s1 = inshort();
-		journaln(0, l1);
-		f = whichfile(s);
-		while(s1--)
-			if(filereadc(f, --l) == '\n')
-				break;
-		outTsl(Horigin, s, ++l);
 		break;
 
 	case Tstartfile:
--- a/sam/mesg.h
+++ b/sam/mesg.h
@@ -2,8 +2,9 @@
 	2 increases SNARFSIZE from 4096 to 32000
 	3 adds a triple click
 	4 adds M command (add b2 menu action)
+	5 refactors scrolling, removes Torigin/Horigin
  */
-#define	VERSION	4
+#define	VERSION	5
 
 #define	TBLOCKSIZE 512		  /* largest piece of text sent to terminal */
 #define	DATASIZE  (UTFmax*TBLOCKSIZE+30) /* ... including protocol header stuff */
@@ -18,7 +19,6 @@
 	Tstartcmdfile,	/* terminal just opened command frame */
 	Tcheck,		/* ask host to poke with Hcheck */
 	Trequest,	/* request data to fill a hole */
-	Torigin,	/* gimme an Horigin near here */
 	Tstartfile,	/* terminal just opened a file's frame */
 	Tworkfile,	/* set file to which commands apply */
 	Ttype,		/* add some characters, but terminal already knows */
@@ -58,7 +58,6 @@
 	Hcheck,		/* ask terminal to check whether it needs more data */
 	Hunlock,	/* command is finished; user can do things */
 	Hdata,		/* store this data in previously allocated space */
-	Horigin,	/* set origin of file/frame in terminal */
 	Hunlockfile,	/* unlock file in terminal */
 	Hsetdot,	/* set dot in terminal */
 	Hgrowdata,	/* Hgrow + Hdata folded together */
--- a/sam/moveto.c
+++ b/sam/moveto.c
@@ -3,13 +3,17 @@
 void
 moveto(File *f, Range r)
 {
-	Posn p1 = r.p1, p2 = r.p2;
+	int i;
 
-	f->dot.r.p1 = p1;
-	f->dot.r.p2 = p2;
+	f->dot.r.p1 = r.p1;
+	f->dot.r.p2 = r.p2;
 	if(f->rasp){
 		telldot(f);
-		outTsl(Hmoveto, f->tag, f->dot.r.p1);
+		/* look back a line */
+		for(i = 0; i < 2; i++)
+			while(r.p1 && filereadc(f, --r.p1) != '\n')
+				;
+		outTsl(Hmoveto, f->tag, r.p1 + (r.p1 != 0));
 	}
 }
 
--- a/samterm/main.c
+++ b/samterm/main.c
@@ -9,8 +9,6 @@
 #include "flayer.h"
 #include "samterm.h"
 
-int	mainstacksize = 16*1024;
-
 Text	cmd;
 Rune	*scratch;
 long	nscralloc;
@@ -28,6 +26,8 @@
 int	autoindent;
 int	spacesindent;
 
+int	mainstacksize = 16*1024;
+
 void
 threadmain(int argc, char *argv[])
 {
@@ -42,11 +42,12 @@
 	getscreen(argc, argv);
 	iconinit();
 	initio();
-	scratch = alloc(100*RUNESIZE);
+	scratch = alloc(100*sizeof(Rune));
 	nscralloc = 100;
 	r = screen->r;
 	r.max.y = r.min.y + Dy(r)/5;
 	flstart(screen->clipr);
+
 	rinit(&cmd.rasp);
 	flnew(&cmd.l[0], gettext, 1, &cmd);
 	flinit(&cmd.l[0], r, font, cmdcols);
@@ -53,6 +54,7 @@
 	cmd.nwin = 1;
 	which = &cmd.l[0];
 	cmd.tag = Untagged;
+
 	outTs(Tversion, VERSION);
 	startnewfile(Tstartcmdfile, &cmd);
 
@@ -273,8 +275,9 @@
 void
 snarf(Text *t, int w)
 {
-	Flayer *l = &t->l[w];
+	Flayer *l;
 
+	l = &t->l[w];
 	if(l->p1 > l->p0){
 		snarflen = l->p1 - l->p0;
 		outTsll(Tsnarf, t->tag, l->p0, l->p1);
@@ -456,7 +459,7 @@
 					n += maxtab - (n % maxtab) - 1;
 			}
 	}
-	horigin(t->tag, a);
+	origin(t->tag, a);
 }
 
 void
--- a/samterm/mesg.c
+++ b/samterm/mesg.c
@@ -192,11 +192,6 @@
 		}
 		break;
 
-	case Horigin:
-		if(menu >= 0)
-			horigin(m, l);
-		break;
-
 	case Hunlock:
 		clrlock();
 		break;
@@ -224,7 +219,7 @@
 			for(i = 0; i < NL; i++){
 				lp = &cmd.l[i];
 				if(lp->textfn && l > lp->origin+lp->f.nchars)
-					horigin(m, l >= 0? l: lp->p1);
+					origin(m, l >= 0? l: lp->p1);
 			}
 		break;
 
@@ -523,7 +518,7 @@
 }
 
 void
-horigin(int m, long p)
+origin(int m, long p)
 {
 	Text *t = whichtext(m);
 	Flayer *l = &t->l[t->front];
@@ -561,7 +556,7 @@
 	Flayer *l = &t->l[t->front];
 
 	if(p0 < l->origin || p0-l->origin > l->f.nchars*9/10)
-		horigin(m, p0);
+		origin(m, p0);
 }
 
 void
--- a/samterm/samterm.h
+++ b/samterm/samterm.h
@@ -30,7 +30,7 @@
 	Section	*sect;
 };
 
-#define	Untagged	((ushort)65535)
+#define	Untagged	((ushort) 65535)
 
 struct Text
 {
@@ -105,7 +105,6 @@
 void	hoststart(void);
 int	plumbstart(void);
 int	button(int but);
-int	load(char*, int);
 int	waitforio(int);
 void	frscroll(Frame*, int);
 int	rcvchar(void);
@@ -148,7 +147,7 @@
 Text	*sweeptext(int, int);
 void	setpat(char*);
 void	menucmd(char*);
-void	scrdraw(Flayer*, long tot);
+void	scrdraw(Flayer*, long);
 int	rcontig(Rasp*, ulong, ulong, int);
 int	rmissing(Rasp*, ulong, ulong);
 void	rresize(Rasp*, long, long, long);
@@ -162,6 +161,8 @@
 int	screensize(int*, int*);
 long	bound(Text*, long);
 void	setblock(int);
+void	origin(int, long);
+
 #include "mesg.h"
 
 void	outT0(Tmesg);
--