sam-fans - fans of the sam editor
 help / color / mirror / Atom feed
* Re:  scripts using 3/12 sam command pipe?
@ 1993-03-17 18:28 rsalz
  0 siblings, 0 replies; 2+ messages in thread
From: rsalz @ 1993-03-17 18:28 UTC (permalink / raw)
  To: ejk, sam-fans

I had a test copy of Boyd's stuff and have been using this for a
while.  Similar but written in rc (uses look and sed).  You'll have
to edit the "sp=" line ...

It is probably just that I haven't been able to really wrap my mind
around structural R.E.'s all that much, but find that I am not using
them all that much.  I use the multi-file aspect all the time; it is
my primary reason for using sam.  As a result, I am often writing little
shell snippets like this:
	for (i in stderr stdout nolog console) {
	    echo 'X/./ ,g/svc_c_' ^ $i ^ '/ {'
	    echo ',x/svc_c_' ^ $i ^ '/ x/svc_c_/ a/route_/'
	    echo '}'
	} >>$h/.sam.rsalz
Actually, I often write those snippets in an "unnamed" window, select
them, and then do ">rc >$sp" where sp is an envvar naming the sam pipe.
	/r$

#! /bin/rc
##  Output a series of commands that will make same go to the tag named on
##  the command line.  If no argument, use the word in the current X
##  selection.  The best way to get the selection is to install xcb; available
##  as contrib/xcb-2.1.tar.Z on export.lcs.mit.edu.

##  Useful variables
~ $#tagspath 0 && tagspath = (. .. /usr/lib/tags)
nl = '
'
tab='	'
cat=()

##  Print usage message and exit.
fn usage {
    echo Usage: $0 '[-o] [-i | tag]' >[1=2]
    exit 1
}

##  Parse flags.
while ( ! ~ $#* 0 ) {
    switch ( $1 ) {
    case -i
	! ~ $#function 0 && usage
	function = `` ($nl) {sed 1q}
    case -o
	cat=cat
    case -*
	usage
    case *
	! ~ $#function 0 && usage
	function = $1
    }
    shift
}

##  Sending to sam?
~ $#cat 0 && {
    ~ $#sp 0 && {
	sp=$home/.sam.$USER
	! ~ $#DISPLAY 0 && sp=$sp.$DISPLAY
    }
    test -r $sp || {
	echo 'No sam fifo' >[1=2]
	usage
    }
    cat='cat >$sp'
}

##  Get the current X selection.
~ $#function 0 && function = `{xcb -p 0}

function = $function ^ $tab

for (dir in $tagspath)
    test -f $dir ^ /tags && {
	line = `` ($nl) { look $function $dir ^ /tags ; echo $status }
	~ $#line 2 && ~ $line(2) 0 && {
	    {
		* = `` ($tab $nl) { echo $line(1) }
		if ( ~ $dir . || ~ $2 /* ) {
		    echo B $2 ^ $nl ^ b $2
		} else {
		    echo B $dir ^ '/' ^ $2 ^ $nl ^ b $dir ^ '/' ^ $2
		}
		shift ; shift
		{
		    echo -n $1
		    while (shift && ! ~ $#* 0)
			echo -n $tab ^ $1
		    echo
		} | sed -e 's/\[/\\[/g' \
			-e 's/[].+?|()*$^]/\\&/g' \
			-e 's/\/\\\^/\/\^/' \
			-e 's/\\\$\/$/\$\//' \
			-e 's/	/	+/g'
	    } | eval $cat
	    exit 0
	}
    }
exit 1


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

* scripts using 3/12 sam command pipe?
@ 1993-03-17 17:59 Ed Kubaitis - CCSO
  0 siblings, 0 replies; 2+ messages in thread
From: Ed Kubaitis - CCSO @ 1993-03-17 17:59 UTC (permalink / raw)
  To: sam-fans

Here's a pretty obvious one. Anyone else have one to share?

Ed
===============================================================================
#! /usr/local/bin/perl
#
#   samtag - generate Sam commands from ctags(1) tags file
#
#   usage: !samtag tag     -OR-    (select-tag-with-mouse)
#                                  >samtag

$user = $ENV{'USER'};
$user = $ENV{'LOGNAME'} unless $user;
$user || die "samtag: no USER or LOGNAME environment variable.\n";

$pipe = ".sam.$user";
$pipe .= ".$ENV{'DISPLAY'}" if $ENV{'DISPLAY'};

$Pipe = "/tmp/$pipe";
$Pipe = "/usr/tmp/$pipe" unless -p $Pipe;
-p $Pipe || die "samtag: no sam pipe($pipe) in /tmp or /usr/tmp\n";

$Tag = shift;
$Tag = <STDIN> unless $Tag;
die "samtag: no tag specified." unless $Tag;

open(Tags, "tags") || die "samtag: tags: $!\n";
while(<Tags>) {
   /^([^\t]+)\t([^\t]+)\t(.+)$/;
   $tag = $1; $file =$2; $re =$3;
   last if $tag eq $Tag
   }
die "samtag: tag <$Tag> not found.\n" unless $tag eq $Tag;
$re =~ s/([()*[\]])/\\$1/g; # escape metacharacters in re

open(Pipe, ">$Pipe") || die "samtag: $Pipe: $!\n";
print Pipe "B $file\n$re\n";
close(Pipe);


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

end of thread, other threads:[~1993-03-17 18:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-03-17 18:28 scripts using 3/12 sam command pipe? rsalz
  -- strict thread matches above, loose matches on Subject: below --
1993-03-17 17:59 Ed Kubaitis - CCSO

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