sam-fans - fans of the sam editor
 help / color / mirror / Atom feed
* ssam, again
@ 2000-03-01 15:04 Bengt Kleberg
  2000-03-01 16:17 ` James A. Robinson
  0 siblings, 1 reply; 4+ messages in thread
From: Bengt Kleberg @ 2000-03-01 15:04 UTC (permalink / raw)
  To: sam-fans, wilyfans

There has been previous incarnations of a stream version of sam. I have used one by Alistair Crooks
agc@westley.demon.co.uk. Here is a new one, implemented as a rc script using sam -d. Since the
fans email list is low volume I hope that you will all survive that I email both the script and the man page
in seperate emails :-)

I have thought about including this script with sam-9libs. Is it sufficiently useful, or does it detract
so much from sam that it should be kept hidden?


Best Wishes, Bengt
===============================================================
Everything aforementioned should be regarded as totally private
opinions, and nothing else. bengt@softwell.se
``His great strength is that he is uncompromising. It would make
him physically ill to think of programming in C++.''


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

* Re: ssam, again
  2000-03-01 15:04 ssam, again Bengt Kleberg
@ 2000-03-01 16:17 ` James A. Robinson
  0 siblings, 0 replies; 4+ messages in thread
From: James A. Robinson @ 2000-03-01 16:17 UTC (permalink / raw)
  To: Bengt Kleberg; +Cc: sam-fans, wilyfans

[-- Attachment #1: Type: text/plain, Size: 828 bytes --]

> There has been previous incarnations of a stream version of sam. I have
> used one by Alistair Crooks agc@westley.demon.co.uk. Here is a new one,
> implemented as a rc script using sam -d. Since the fans email list is
> low volume I hope that you will all survive that I email b oth the script
> and the man page in seperate emails :-)
> 
> I have thought about including this script with sam-9libs. Is it
> sufficiently useful, or does it detract so much from sam that it
> should be kept hidden?

It's always nice to see useful wily scripts.  I don't know if I 
ever posted or sent this one out, but I have a copy of a sam
script someone posted to sam-fans ages ago. It is neat in that
it uses a FIFO instead of a temporary file. It is no where near
as flexibly as what you posted, but I thought you might be
interested...


[-- Attachment #2: FIFO based sam --]
[-- Type: text/plain, Size: 584 bytes --]

#!/opt/plan9/bin/rc

umask 077

if ( ~ $#* 0) {
  echo >[1=2] Usage: wsam commands ...
  builtin exit 1
}

if ( test -d /usr/tmp ) {
	tmp_dir=/usr/tmp
} else if ( test -d /var/tmp ) {
	tmp_dir=/var/tmp
} else if ( test -d /tmp ) {
	tmp_dir=/tmp
} else if ( test -d $HOME ) {
	tmp_dir=$HOME
} else {
	echo >[1=2] wsam: I cannot find a nice place to put my FIFO
	builtin exit 1
}

FIFO=$tmp_dir^'/'^wsam.$pid.rd
mkfifo -m 0700 $FIFO
{
  echo 'r '$FIFO
  while ( ! ~ $#* 0 ) {
    echo $1
    shift
  }
  echo ',p'
} | sam -d >[2=] &

cat >$FIFO

wait $apid

rm -f $FIFO

builtin exit 0

[-- Attachment #3: Type: text/plain, Size: 243 bytes --]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       jim.robinson@stanford.edu
Stanford University HighWire Press      http://highwire.stanford.edu/
650-723-7294 (W) 650-725-9335 (F)   

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

* Re: ssam, again
  2000-03-06 11:06 ` Bengt Kleberg
@ 2000-03-07  0:36   ` James A. Robinson
  0 siblings, 0 replies; 4+ messages in thread
From: James A. Robinson @ 2000-03-07  0:36 UTC (permalink / raw)
  To: sam-fans, wilyfans

> Thanks to suggestion and code by "James A. Robinson"
> <jim.robinson@stanford.edu> I have managed to cut disk usage in 1/2,
> using a fifo instead of a tmp file.

Credit for the original code should go to Alan Watson <alan@oldp.astro.wisc.edu>,
not to me.

Jim

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       jim.robinson@stanford.edu
Stanford University HighWire Press      http://highwire.stanford.edu/
650-723-7294 (W) 650-725-9335 (F)   


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

* Re: ssam, again
@ 2000-03-06 11:06 ` Bengt Kleberg
  2000-03-07  0:36   ` James A. Robinson
  0 siblings, 1 reply; 4+ messages in thread
From: Bengt Kleberg @ 2000-03-06 11:06 UTC (permalink / raw)
  To: sam-fans, wilyfans


Thanks to suggestion and code by "James A. Robinson" <jim.robinson@stanford.edu>
I have managed to cut disk usage in 1/2, using a fifo instead of a tmp file.

I now think it is good enough to ship with sam-9libs. Any one aginst?
(it is still not a stream editor, and would not work if /tmp is 50 MB and
the file to edit is 50 MB, too)

script follows:
#! /usr/local/plan9/bin/rc

cmd_name = $0
fn usage {
	echo Usage: $cmd_name [-n] [-e script ] [-f sfile ] [ script ] [--] [ file ] ...
}

# directory for saving all text to be edited
# use /tmp or TMPDIR if set
tmp_dir=/tmp
if (! ~ $TMPDIR ()) {
	tmp_dir=$TMPDIR
}

# file for saving all text to be edited
tmp_file = $tmp_dir ^ /ssam.$pid.XXXXXXXX
# if OpenBSD mktemp exist, use it
if (test -x /usr/bin/mktemp) {
	tmp_file = `{/usr/bin/mktemp $tmp_file}
	# there is no change-file-into-pipe cmd, so remove it before mkfifo
	# this allows for a denial-of-service attack, but mkfifo -m protect against disclosure
	rm $tmp_file
}
mkfifo -m 0700 $tmp_file
if (! ~ $status 0) {
	echo mkfifo failed, someone is deliberatly "stealing" your filename
	echo this indicates an attempt to read the text you want to edit
	exit 4
}

# clean up on signals
fn sighup {
	rm $tmp_file
	exit 3
}
fn sigint {
	rm $tmp_file
	exit 3
}
fn sigquit {
	rm $tmp_file
	exit 3
}

# default values for variables
printall = 1
edit_script = ()
edit_type = ()

# parse command line arguments
while ({~ $1 -*} && {! ~ $1 --}) {
	switch ($1) {
	case -n
		printall = 0
		shift
	case -e
		shift
		edit_script = ($edit_script $1)
		edit_type = ($edit_type e)
		shift
	case -f
		shift
		if (test -f $1) {
			edit_script = ($edit_script $1)
			edit_type = ($edit_type f)
			shift
		} else {
			echo $0: No such sfile: $1
			exit 2
		}
	case *
		usage
		exit 1
	}
}

# anything left that is not a file is a (single) edit script
if (! test -f $1) {
		edit_script = ($edit_script $1)
		edit_type = ($edit_type e)
		shift
}

# send edit scripts to sam and contents of edit script files
# then print contents, unless -n argument
# quit (twice since file has probably not been saved)
i = 1
max = `{expr $#edit_script + 1}
{
echo r $tmp_file
while (! ~ $i $max) {
	switch ($edit_type($i)) {
	case e
		echo $edit_script($i)
	case f
		cat $edit_script($i)
	}
	i = `{expr $i + 1}
}
if (~ $printall 1) {
	echo '1,$ p'
}
echo q
echo q
} | sam -d >[2] /dev/null &
#}
sam_pid =  $apid

# anything left is file(s) to be edited, otherwise use stdin
if (~ $#* 0) {
	cat >> $tmp_file
} else {
	cat $* >> $tmp_file
}

wait $sam_pid
rm $tmp_file
exit 0


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

end of thread, other threads:[~2000-03-12  2:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-01 15:04 ssam, again Bengt Kleberg
2000-03-01 16:17 ` James A. Robinson
     [not found] <bengt@softwell.se>
2000-03-06 11:06 ` Bengt Kleberg
2000-03-07  0:36   ` James A. Robinson

sam-fans - fans of the sam editor

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/sam-fans

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 sam-fans sam-fans/ http://inbox.vuxu.org/sam-fans \
		sam-fans@hawkwind.utcs.toronto.edu
	public-inbox-index sam-fans

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.sam-fans


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git