9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: cLIeNUX user <r@your_host.com>
To: 9fans@cse.psu.edu
Subject: [9fans] h for sam
Date: Thu, 23 Nov 2000 10:17:48 +0000	[thread overview]
Message-ID: <t1m9hgck9i6c8d@corp.supernews.com> (raw)


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


             reply	other threads:[~2000-11-23 10:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-23 10:17 cLIeNUX user [this message]
2000-12-01  9:34 ` [9fans] " Douglas A. Gwyn
2000-12-04  9:49   ` cLIeNUX user

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=t1m9hgck9i6c8d@corp.supernews.com \
    --to=r@your_host.com \
    --cc=9fans@cse.psu.edu \
    /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).