From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: cLIeNUX user Message-ID: Subject: [9fans] h for sam Date: Thu, 23 Nov 2000 10:17:48 +0000 Topicbox-Message-UUID: 3059ff2c-eac9-11e9-9e20-41e7f4b1d025 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... 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 Character Number # match scan PATtern /regular expression, \\n allowed/ OFFset LN or CN or PAT or `1' HALF address full ADDRess , just , is whole buffer text inputs INTERactive accept typed text up to . alone on line Whole Match Backreference & SUBmatch backreference \\ 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 a _append_ INPUT after address b make buffer the current buffer c _clobber_ address with INPUT d _delete_ addressed range of text e _edit_ file, make file current buffer f rename current buffer g PHRASE do PHRASE _if_ PAT matches in ADDR h You're soaking in it. i _insert_ INPUT before address k mark address for reference as ' m move, not copy n list buffers p _print_ to stdout. usual default command. q _quit_. Always works the second time. r _read_ file into buffer after ADDR s use xc instead t copy u undo. Unlimited, but one-way. v PHRASE do PHRASE if PAT _doesn't_ match in ADDR w _write_ out ADDR. default is whole buffer. x PHRASE for each match of PAT in ADDR do PHRASE y 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