zsh-workers
 help / color / mirror / code / Atom feed
From: Dave Yost <Dave@Yost.com>
To: Peter Stephenson <pws@csr.com>
Cc: zsh-workers@sunsite.dk
Subject: Re: zsh malloc bug
Date: Wed, 16 Jun 2004 12:16:55 -0700	[thread overview]
Message-ID: <pdy988306110437bcf64c4a8575@[192.168.1.2]> (raw)

A real example follows.

1283 Z% touch ,x
1284 Z% echo '  
import blah.*;
' | ./prepend ,x      
,x.TMP-prepend-21041
zsh: done       echo ' import '$package'.*; ' | 
zsh: bus error  ./prepend ,x
1285 Z% 

======= prepend
#!/bin/zsh

commandName=${0##*/}

usage() {
	if [[ $1 != '' ]] ; then echo 1>&2 "\n$1" ; fi
	echo 1>&2 "
Usage: $commandName [ -t ] file ...

Prepends stdin to each of the given files.
Reads stdin only once.

The -t option preserves each file's modify time.
"
	exit 2
}

zparseopts -D -K - -help=argHelp v=argVerbose t=argPreserveMtime

if [[ $#argHelp != 0 ]] ; then
	usage
fi

case $1 in
-*) usage "Unknown option: $1"
	;;
esac

#-----------------------------------------

sourceTemp=/tmp/$commandName.$$
cat > $sourceTemp
# I would have preferred this, but it discards trailing newlines:
# source=`cat`

TRAPINT() {
	echo 1>&2 "$commandName aborting: interrupted at file $file"
	rm -f $tmp
	exit 2
}

TRAPEXIT() {
	rm -f $sourceTemp
}

for file in $*
do
	if [[ -d $file ]] ; then
		echo 1>&2 "$commandName: skipping directory $file"
	else
		fileDir=${0%/*}
		fileName=${0##*/}
		tmp=$file.TMP-$commandName-$$
		echo $tmp
		cat $sourceTemp >  $tmp \
		&& cat $file	>> $tmp
		if [[ $? != 0 ]] ; then
			echo 1>&2 "$commandName aborting: trouble at file $file"
			rm -f $tmp
			exit 2
		else
			if [[ $#argPreserveMtime != 0 ]] ; then
				cpt -N $file $tmp
			fi
			mv -f $tmp $file
			if [[ $? != 0 ]] ; then
				echo 1>&2 "$commandName aborting: trouble at file $file"
				rm -f $tmp
				exit 2
			fi
			if [[ $#argVerbose != 0 ]] ; then
				echo $file
			fi
		fi
	fi
done


             reply	other threads:[~2004-06-16 19:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-16 19:16 Dave Yost [this message]
2004-07-26 13:05 ` Peter Stephenson
2004-07-26 16:48   ` Bart Schaefer
2004-07-26 16:57     ` Peter Stephenson
  -- strict thread matches above, loose matches on Subject: below --
2004-06-01 18:01 Dave Yost
2004-06-02  9:32 ` Peter Stephenson
2004-06-02 18:21   ` Dave Yost
2004-06-08 13:20     ` Peter Stephenson
2004-06-16 19:13       ` Dave Yost

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='pdy988306110437bcf64c4a8575@[192.168.1.2]' \
    --to=dave@yost.com \
    --cc=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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