9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] h for sam
@ 2000-11-23 10:17 cLIeNUX user
  2000-12-01  9:34 ` [9fans] " Douglas A. Gwyn
  0 siblings, 1 reply; 3+ messages in thread
From: cLIeNUX user @ 2000-11-23 10:17 UTC (permalink / raw)
  To: 9fans


This has various molestations in it for my Linux distro, but the 
help command should be no biggie if you want to occupy the h 
vacancy in the sam command namespace............ 


xec.c......

/* Copyright (c) 1992 AT&T - All rights reserved. */
#include "sam.h"
#include "parse.h"

int	Glooping;
int	nest;

int	append(File*, Cmd*, Posn);
int	display(File*);

char cheatstring[] = "
____________________________________________________________________________
cLIeNUX sam/tp text processing language cheatsheet
cheatsheet markup...		
  refNAME  `default'  \"virtual\"  /delimited/  0_or_more...  <variable> 

syntax operators		(in commands, not patterns or strings) 		
  delimiter			any punctuation, paired or with EOL
  next character is literal	\\ 

text location operators		(address elements)
  linefeed (unix newline)	\\n
  \"empty line\" at End Of File	$
  current text segment		.
  MARKed text segment		'
  scanning DIRection		- or `+'
  Line Number			<digits>
  Character Number		#<digits>
  match scan PATtern		/regular expression, \\n allowed/
  OFFset			<DIR>LN or CN or PAT or `1' 
  HALF address			<LN or CN or PAT or MARK or `.'><OFF...>
  full ADDRess			<HALF>,<HALF>    just  ,  is whole buffer

text inputs
  INTERactive			accept typed text up to . alone on line 
  Whole Match Backreference	&
  SUBmatch backreference	\\<digit>    nth match ()-delimited in PAT
  LITeral string		/literal text and|or WMB... and|or SUB.../ 
  INPUT				LIT or INTER

commands and thier PHRASE syntaxes, some multi-buffer phrases omitted
  <ADDR>a<INPUT>		_append_ INPUT after address  
        b<buffer>		make buffer the current buffer
  <ADDR>c<INPUT>		_clobber_ address with INPUT      
  <ADDR>d			_delete_ addressed range of text
        e<file>			_edit_ file, make file current buffer
        f<name>			rename current buffer
  <ADDR>g<PAT> PHRASE		do PHRASE _if_ PAT matches in ADDR
        h			You're soaking in it. 
  <ADDR>i<INPUT>		_insert_ INPUT before address
  <ADDR>k			mark address for reference as '      
  <ADDR>m<ADDR>			move, not copy 
        n			list buffers
  <ADDR>p			_print_ to stdout. usual default command.
        q			_quit_. Always works the second time.
  <ADDR>r<file>			_read_ file into buffer after ADDR
  <ADDR>s<PAT><LIT>		use <ADDR>x<PAT>c<INPUT> instead  
  <ADDR>t<ADDR>			copy
        u			undo. Unlimited, but one-way. 
  <ADDR>v<PAT> PHRASE		do PHRASE if PAT _doesn't_ match in ADDR
  <ADDR>w<file>			_write_ out ADDR. default is whole buffer.	
  <ADDR>x<PAT> PHRASE		for each match of PAT in ADDR do PHRASE
  <ADDR>y<PAT> PHRASE		do PHRASE on text between each PAT in ADDR 	
............................................................................


\n";



void	looper(File*, Cmd*, int);
void	filelooper(Cmd*, int);
void	linelooper(File*, Cmd*);




void
resetxec(void)
{
	Glooping = nest = 0;
}

int
cmdexec(File *f, Cmd *cp)
{
	int i;
	Addr *ap;
	Address a;

	if(f && f->state==Unread)
		load(f);
	if(f==0 && (cp->addr==0 || cp->addr->type!='"') &&
	    !utfrune("bBnqUXY!{", cp->cmdc) &&
	    cp->cmdc!=('c'|0x100) && !(cp->cmdc=='D' && cp->ctext))
		error(Enofile);
	i = lookup(cp->cmdc);
	if(cmdtab[i].defaddr != aNo){
		if((ap=cp->addr)==0 && cp->cmdc!='\n'){
			cp->addr = ap = newaddr();
			ap->type = '.';
			if(cmdtab[i].defaddr == aAll)
				ap->type = '*';
		}else if(ap && ap->type=='"' && ap->next==0 && cp->cmdc!='\n'){
			ap->next = newaddr();
			ap->next->type = '.';
			if(cmdtab[i].defaddr == aAll)
				ap->next->type = '*';
		}
		if(cp->addr){	/* may be false for '\n' (only) */
			static Address none = {0,0,0};
			if(f)
				addr = address(ap, f->dot, 0);
			else	/* a " */
				addr = address(ap, none, 0);
			f = addr.f;
		}
	}
	current(f);
	switch(cp->cmdc){
	case '{':
		a = cp->addr? address(cp->addr, f->dot, 0): f->dot;
		for(cp = cp->ccmd; cp; cp = cp->next){
			a.f->dot = a;
			cmdexec(a.f, cp);
		}
		break;
	default:
		i=(*cmdtab[i].fn)(f, cp);
		return i;
	}
	return 1;
}


int
a_cmd(File *f, Cmd *cp)
{
	return append(f, cp, addr.r.p2);
}

int
b_cmd(File *f, Cmd *cp)
{
	USED(f);
	f = cp->cmdc=='b'? tofile(cp->ctext) : getfile(cp->ctext);
	if(f->state == Unread)
		load(f);
	else if(nest == 0)
		filename(f);
	return TRUE;
}

int
c_cmd(File *f, Cmd *cp)
{
	Fdelete(f, addr.r.p1, addr.r.p2);
	f->ndot.r.p1 = f->ndot.r.p2 = addr.r.p2;
	return append(f, cp, addr.r.p2);
}

int
d_cmd(File *f, Cmd *cp)
{
	USED(cp);
	Fdelete(f, addr.r.p1, addr.r.p2);
	f->ndot.r.p1 = f->ndot.r.p2 = addr.r.p1;
	return TRUE;
}

int
D_cmd(File *f, Cmd *cp)
{
	closefiles(f, cp->ctext);
	return TRUE;
}

int
e_cmd(File *f, Cmd *cp)
{
	if(getname(f, cp->ctext, cp->cmdc=='e')==0)
		error(Enoname);
	edit(f, cp->cmdc);
	return TRUE;
}

int
f_cmd(File *f, Cmd *cp)
{
	getname(f, cp->ctext, TRUE);
	filename(f);
	return TRUE;
}

int
g_cmd(File *f, Cmd *cp)
{
	if(f!=addr.f)panic("g_cmd f!=addr.f");
	compile(cp->re);
	if(execute(f, addr.r.p1, addr.r.p2) ^ cp->cmdc=='v'){
		f->dot = addr;
		return cmdexec(f, cp->ccmd);
	}
	return TRUE;
}




int
h_cmd (File *f, Cmd *cp){
write(2,&cheatstring,sizeof(cheatstring));
}


SNIP****************


Rick Hohensee
Forth, unix, cLIeNUX


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [9fans] Re: h for sam
  2000-11-23 10:17 [9fans] h for sam cLIeNUX user
@ 2000-12-01  9:34 ` Douglas A. Gwyn
  2000-12-04  9:49   ` cLIeNUX user
  0 siblings, 1 reply; 3+ messages in thread
From: Douglas A. Gwyn @ 2000-12-01  9:34 UTC (permalink / raw)
  To: 9fans

Hm, if you *have* to have a "help" command in sam,
why not have it just open a window attached to the
appropriate help-document path on the host?
Otherwise a lot of the process space is occupied
with an embedded, hard-to-update help file.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [9fans] Re: h for sam
  2000-12-01  9:34 ` [9fans] " Douglas A. Gwyn
@ 2000-12-04  9:49   ` cLIeNUX user
  0 siblings, 0 replies; 3+ messages in thread
From: cLIeNUX user @ 2000-12-04  9:49 UTC (permalink / raw)
  To: 9fans

gwyn@arl.army.mil... 
>Hm, if you *have* to have a "help" command in sam,
>why not have it just open a window attached to the
>appropriate help-document path on the host?

sam doesn't have windows. That's samterm. I built just the sam part for my
Linux distro, which has an X-less "Core" that I basically live in.

>Otherwise a lot of the process space is occupied
>with an embedded, hard-to-update help file.

My tastes for online docs are definitely as presented, in contrast to ed,
sam and so on. My tastes for interdependancies leaves Plan9 interesting
for reasons other than it's distributed-ness. Tastes obviously vary. Even
on Plan9, I'm sure I'd personally go with the simplicity of an h key as
presented as, in addition to whatever.

Rick Hohensee
Forth, unix, cLIeNUX
www.clienux.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-12-04  9:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-23 10:17 [9fans] h for sam cLIeNUX user
2000-12-01  9:34 ` [9fans] " Douglas A. Gwyn
2000-12-04  9:49   ` cLIeNUX user

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).