add autoindent (-a) and chording.
clean up argument parsing.
This commit is contained in:
parent
4ac5f249ad
commit
17ab31aac6
8 changed files with 113 additions and 74 deletions
|
|
@ -176,7 +176,7 @@ int remotefd0 = 0;
|
||||||
int remotefd1 = 1;
|
int remotefd1 = 1;
|
||||||
|
|
||||||
void
|
void
|
||||||
bootterm(char *machine, char **argv, char **end)
|
bootterm(char *machine, char **argv)
|
||||||
{
|
{
|
||||||
int ph2t[2], pt2h[2];
|
int ph2t[2], pt2h[2];
|
||||||
|
|
||||||
|
|
@ -186,7 +186,6 @@ bootterm(char *machine, char **argv, char **end)
|
||||||
close(remotefd0);
|
close(remotefd0);
|
||||||
close(remotefd1);
|
close(remotefd1);
|
||||||
argv[0] = "samterm";
|
argv[0] = "samterm";
|
||||||
*end = 0;
|
|
||||||
execvp(samterm, argv);
|
execvp(samterm, argv);
|
||||||
fprint(2, "can't exec %s: %r\n", samterm);
|
fprint(2, "can't exec %s: %r\n", samterm);
|
||||||
_exits("damn");
|
_exits("damn");
|
||||||
|
|
@ -202,7 +201,6 @@ bootterm(char *machine, char **argv, char **end)
|
||||||
close(pt2h[0]);
|
close(pt2h[0]);
|
||||||
close(pt2h[1]);
|
close(pt2h[1]);
|
||||||
argv[0] = "samterm";
|
argv[0] = "samterm";
|
||||||
*end = 0;
|
|
||||||
execvp(samterm, argv);
|
execvp(samterm, argv);
|
||||||
fprint(2, "can't exec: ");
|
fprint(2, "can't exec: ");
|
||||||
perror(samterm);
|
perror(samterm);
|
||||||
|
|
@ -269,12 +267,12 @@ connectto(char *machine, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
startup(char *machine, int Rflag, char **argv, char **end, char **files)
|
startup(char *machine, int Rflag, char **argv, char **files)
|
||||||
{
|
{
|
||||||
if(machine)
|
if(machine)
|
||||||
connectto(machine, files);
|
connectto(machine, files);
|
||||||
if(!Rflag)
|
if(!Rflag)
|
||||||
bootterm(machine, argv, end);
|
bootterm(machine, argv);
|
||||||
downloaded = 1;
|
downloaded = 1;
|
||||||
outTs(Hversion, VERSION);
|
outTs(Hversion, VERSION);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ typedef enum Hmesg
|
||||||
Hsnarflen, /* report length of implicit snarf */
|
Hsnarflen, /* report length of implicit snarf */
|
||||||
Hack, /* request acknowledgement */
|
Hack, /* request acknowledgement */
|
||||||
Hexit,
|
Hexit,
|
||||||
Hplumb, /* return plumb message to terminal */
|
Hplumb, /* return plumb message to terminal - version 1 */
|
||||||
HMAX,
|
HMAX,
|
||||||
}Hmesg;
|
}Hmesg;
|
||||||
typedef struct Header{
|
typedef struct Header{
|
||||||
|
|
|
||||||
|
|
@ -42,58 +42,40 @@ main(int volatile argc, char **volatile argv)
|
||||||
{
|
{
|
||||||
int volatile i;
|
int volatile i;
|
||||||
String *t;
|
String *t;
|
||||||
char **ap, **arg;
|
char *termargs[10], **ap;
|
||||||
|
|
||||||
|
ap = termargs;
|
||||||
|
*ap++ = "samterm";
|
||||||
|
ARGBEGIN{
|
||||||
|
case 'd':
|
||||||
|
dflag++;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
machine = EARGF(usage());
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
Rflag++;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
samterm = EARGF(usage());
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
rsamname = EARGF(usage());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dprint("sam: unknown flag %c\n", ARGC());
|
||||||
|
usage();
|
||||||
|
/* options for samterm */
|
||||||
|
case 'a':
|
||||||
|
*ap++ = "-a";
|
||||||
|
break;
|
||||||
|
case 'W':
|
||||||
|
*ap++ = "-W";
|
||||||
|
*ap++ = EARGF(usage());
|
||||||
|
break;
|
||||||
|
}ARGEND
|
||||||
|
*ap = nil;
|
||||||
|
|
||||||
arg = argv++;
|
|
||||||
ap = argv;
|
|
||||||
while(argc>1 && argv[0] && argv[0][0]=='-'){
|
|
||||||
switch(argv[0][1]){
|
|
||||||
case 'd':
|
|
||||||
dflag++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'r':
|
|
||||||
--argc, argv++;
|
|
||||||
if(argc == 1)
|
|
||||||
usage();
|
|
||||||
machine = *argv;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'R':
|
|
||||||
Rflag++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 't':
|
|
||||||
--argc, argv++;
|
|
||||||
if(argc == 1)
|
|
||||||
usage();
|
|
||||||
samterm = *argv;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 's':
|
|
||||||
--argc, argv++;
|
|
||||||
if(argc == 1)
|
|
||||||
usage();
|
|
||||||
rsamname = *argv;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'x': /* x11 option - strip the x */
|
|
||||||
strcpy(*argv+1, *argv+2);
|
|
||||||
*ap++ = *argv++;
|
|
||||||
*ap++ = *argv;
|
|
||||||
argc--;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'W':
|
|
||||||
--argc, argv++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dprint("sam: unknown flag %c\n", argv[0][1]);
|
|
||||||
exits("usage");
|
|
||||||
}
|
|
||||||
--argc, argv++;
|
|
||||||
}
|
|
||||||
Strinit(&cmdstr);
|
Strinit(&cmdstr);
|
||||||
Strinit0(&lastpat);
|
Strinit0(&lastpat);
|
||||||
Strinit0(&lastregexp);
|
Strinit0(&lastregexp);
|
||||||
|
|
@ -106,12 +88,13 @@ main(int volatile argc, char **volatile argv)
|
||||||
disk = diskinit();
|
disk = diskinit();
|
||||||
if(home == 0)
|
if(home == 0)
|
||||||
home = "/";
|
home = "/";
|
||||||
|
fprint(2, "argc %d argv %s\n", argc, *argv);
|
||||||
if(!dflag)
|
if(!dflag)
|
||||||
startup(machine, Rflag, arg, ap, argv);
|
startup(machine, Rflag, termargs, argv);
|
||||||
notify(notifyf);
|
notify(notifyf);
|
||||||
getcurwd();
|
getcurwd();
|
||||||
if(argc>1){
|
if(argc>0){
|
||||||
for(i=0; i<argc-1; i++){
|
for(i=0; i<argc; i++){
|
||||||
if(!setjmp(mainloop)){
|
if(!setjmp(mainloop)){
|
||||||
t = tmpcstr(argv[i]);
|
t = tmpcstr(argv[i]);
|
||||||
Straddc(t, '\0');
|
Straddc(t, '\0');
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,7 @@ void settempfile(void);
|
||||||
int skipbl(void);
|
int skipbl(void);
|
||||||
void snarf(File*, Posn, Posn, Buffer*, int);
|
void snarf(File*, Posn, Posn, Buffer*, int);
|
||||||
void sortname(File*);
|
void sortname(File*);
|
||||||
void startup(char*, int, char**, char**, char**);
|
void startup(char*, int, char**, char**);
|
||||||
void state(File*, int);
|
void state(File*, int);
|
||||||
int statfd(int, ulong*, uvlong*, long*, long*, long*);
|
int statfd(int, ulong*, uvlong*, long*, long*, long*);
|
||||||
int statfile(char*, ulong*, uvlong*, long*, long*, long*);
|
int statfile(char*, ulong*, uvlong*, long*, long*, long*);
|
||||||
|
|
|
||||||
|
|
@ -253,10 +253,11 @@ fldelete(Flayer *l, long p0, long p1)
|
||||||
int
|
int
|
||||||
flselect(Flayer *l)
|
flselect(Flayer *l)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret;
|
||||||
if(l->visible!=All)
|
if(l->visible!=All)
|
||||||
flupfront(l);
|
flupfront(l);
|
||||||
frselect(&l->f, mousectl);
|
frselect(&l->f, mousectl);
|
||||||
|
ret = 0;
|
||||||
if(l->f.p0==l->f.p1){
|
if(l->f.p0==l->f.p1){
|
||||||
if(mousep->msec-l->click<Clicktime && l->f.p0+l->origin==l->p0){
|
if(mousep->msec-l->click<Clicktime && l->f.p0+l->origin==l->p0){
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,13 @@ long modified = 0; /* strange lookahead for menus */
|
||||||
char hostlock = 1;
|
char hostlock = 1;
|
||||||
char hasunlocked = 0;
|
char hasunlocked = 0;
|
||||||
int maxtab = 8;
|
int maxtab = 8;
|
||||||
|
int chord;
|
||||||
|
int autoindent;
|
||||||
|
|
||||||
void
|
void
|
||||||
threadmain(int argc, char *argv[])
|
threadmain(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, got, scr;
|
int i, got, scr, w;
|
||||||
Text *t;
|
Text *t;
|
||||||
Rectangle r;
|
Rectangle r;
|
||||||
Flayer *nwhich;
|
Flayer *nwhich;
|
||||||
|
|
@ -98,7 +100,11 @@ dup(2, 1);
|
||||||
scr = which && ptinrect(mousep->xy, which->scroll);
|
scr = which && ptinrect(mousep->xy, which->scroll);
|
||||||
if(mousep->buttons)
|
if(mousep->buttons)
|
||||||
flushtyping(1);
|
flushtyping(1);
|
||||||
if(mousep->buttons&1){
|
if(chord==1 && !mousep->buttons)
|
||||||
|
chord = 0;
|
||||||
|
if(chord)
|
||||||
|
chord |= mousep->buttons;
|
||||||
|
else if(mousep->buttons&1){
|
||||||
if(nwhich){
|
if(nwhich){
|
||||||
if(nwhich!=which)
|
if(nwhich!=which)
|
||||||
current(nwhich);
|
current(nwhich);
|
||||||
|
|
@ -111,6 +117,8 @@ dup(2, 1);
|
||||||
t->lock++;
|
t->lock++;
|
||||||
}else if(t!=&cmd)
|
}else if(t!=&cmd)
|
||||||
outcmd();
|
outcmd();
|
||||||
|
if(mousep->buttons&1)
|
||||||
|
chord = mousep->buttons;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if((mousep->buttons&2) && which){
|
}else if((mousep->buttons&2) && which){
|
||||||
|
|
@ -126,10 +134,22 @@ dup(2, 1);
|
||||||
}
|
}
|
||||||
mouseunblock();
|
mouseunblock();
|
||||||
}
|
}
|
||||||
|
if(chord){
|
||||||
|
t = (Text*)which->user1;
|
||||||
|
if(!t->lock && !hostlock){
|
||||||
|
w = which-t->l;
|
||||||
|
if(chord&2){
|
||||||
|
cut(t, w, 1, 1);
|
||||||
|
chord &= ~2;
|
||||||
|
}else if(chord&4){
|
||||||
|
paste(t, w);
|
||||||
|
chord &= ~4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
resize(void)
|
resize(void)
|
||||||
{
|
{
|
||||||
|
|
@ -394,7 +414,7 @@ center(Flayer *l, long a)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
onethird(Flayer *l, long a)
|
thirds(Flayer *l, long a, int n)
|
||||||
{
|
{
|
||||||
Text *t;
|
Text *t;
|
||||||
Rectangle s;
|
Rectangle s;
|
||||||
|
|
@ -405,7 +425,7 @@ onethird(Flayer *l, long a)
|
||||||
if(a > t->rasp.nrunes)
|
if(a > t->rasp.nrunes)
|
||||||
a = t->rasp.nrunes;
|
a = t->rasp.nrunes;
|
||||||
s = insetrect(l->scroll, 1);
|
s = insetrect(l->scroll, 1);
|
||||||
lines = ((s.max.y-s.min.y)/l->f.font->height+1)/3;
|
lines = (n*(s.max.y-s.min.y)/l->f.font->height+1)/3;
|
||||||
if (lines < 2)
|
if (lines < 2)
|
||||||
lines = 2;
|
lines = 2;
|
||||||
outTsll(Torigin, t->tag, a, lines);
|
outTsll(Torigin, t->tag, a, lines);
|
||||||
|
|
@ -414,6 +434,18 @@ onethird(Flayer *l, long a)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
onethird(Flayer *l, long a)
|
||||||
|
{
|
||||||
|
return thirds(l, a, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
twothirds(Flayer *l, long a)
|
||||||
|
{
|
||||||
|
return thirds(l, a, 2);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
flushtyping(int clearesc)
|
flushtyping(int clearesc)
|
||||||
{
|
{
|
||||||
|
|
@ -495,7 +527,20 @@ type(Flayer *l, int res) /* what a bloody mess this is */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*p++ = c;
|
*p++ = c;
|
||||||
if(c == '\n' || p >= buf+sizeof(buf)/sizeof(buf[0]))
|
if(autoindent)
|
||||||
|
if(c == '\n'){
|
||||||
|
/* autoindent */
|
||||||
|
int cursor, ch;
|
||||||
|
cursor = ctlu(&t->rasp, 0, a+(p-buf)-1);
|
||||||
|
while(p < buf+nelem(buf)){
|
||||||
|
ch = raspc(&t->rasp, cursor++);
|
||||||
|
if(ch == ' ' || ch == '\t')
|
||||||
|
*p++ = ch;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(c == '\n' || p >= buf+nelem(buf))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(p > buf){
|
if(p > buf){
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,28 @@ static char *exname;
|
||||||
|
|
||||||
#define STACK 16384
|
#define STACK 16384
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
fprint(2, "usage: samterm -a -W winsize\n");
|
||||||
|
threadexitsall("usage");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
getscreen(int argc, char **argv)
|
getscreen(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
char *t;
|
char *t;
|
||||||
|
|
||||||
/* not exactly right */
|
ARGBEGIN{
|
||||||
for(i=0; i<argc-1; i++){
|
case 'a':
|
||||||
if(strcmp(argv[i], "-W") == 0)
|
autoindent = 1;
|
||||||
winsize = argv[i+1];
|
break;
|
||||||
}
|
case 'W':
|
||||||
|
winsize = EARGF(usage());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
}ARGEND
|
||||||
|
|
||||||
if(initdraw(panic1, nil, "sam") < 0){
|
if(initdraw(panic1, nil, "sam") < 0){
|
||||||
fprint(2, "samterm: initdraw: %r\n");
|
fprint(2, "samterm: initdraw: %r\n");
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ extern int hversion;
|
||||||
extern int plumbfd;
|
extern int plumbfd;
|
||||||
extern int hostfd[2];
|
extern int hostfd[2];
|
||||||
extern int exiting;
|
extern int exiting;
|
||||||
|
extern int autoindent;
|
||||||
|
|
||||||
#define gettext sam_gettext /* stupid gcc built-in functions */
|
#define gettext sam_gettext /* stupid gcc built-in functions */
|
||||||
Rune *gettext(Flayer*, long, ulong*);
|
Rune *gettext(Flayer*, long, ulong*);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue