zsh-workers
 help / color / mirror / code / Atom feed
* Unexpected Results/Heisenbug
@ 2000-05-11  0:48 Ken Smith
  2000-05-11  4:04 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Ken Smith @ 2000-05-11  0:48 UTC (permalink / raw)
  To: zsh-workers

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

Attached is a script which surprised me when I tested it.  When run with
DEBUG=0, the output is as I would expect.  When run with DEBUG=1, the
for loop sets ${each} to "continue:" after the debugging code executes. 
Is this a problem with my nubile scripting skills or does this signify a
problem with zsh?  Please cc responses to ken at smith.net as I am not a
subscriber of the zsh-workers mailing list.

Thank you for any tips.

[-- Attachment #2: zsh_for_test --]
[-- Type: text/plain, Size: 1355 bytes --]

#!/bin/zsh

DEBUG=1

function debugging
{
	[[ ${+DEBUG} == 1 && ${DEBUG} == 1 ]]
}
function format_output
{
	function arg_len
	{
		echo $1 | wc -c
	}

	heading_separator=": "
	prefix=${1}${heading_separator}
	prefix_len=`arg_len ${prefix}`
	if [[ ${+COLUMNS} == 1 ]]; then
	columns=${COLUMNS}
	else
		columns=80
	fi

	terminal_position=0
	first_argument=1
	just_wrote_prefix=0
	for each in $*; do
		if [[ ${first_argument} == 1 ]]; then
			first_argument=0
			continue
		fi
		if [[ ${terminal_position} == 0 ]]; then
			echo -n ${prefix}
			just_wrote_prefix=1
		fi
		token_len=`arg_len ${each}`
		((terminal_position += token_len + 1))
		if [[ ${terminal_position} > ${columns} ]]; then
			# If we just wrote the prefix, then we
			# have to write this token where it stands
			# even though it will wrap.
			if [[ ${just_wrote_prefix} == 1 ]]; then
				echo ${each}
				just_wrote_prefix=0
				((terminal_position = 0))
			else
				echo -n "\n${prefix}${each} "
				((terminal_position =
					prefix_len + token_len))
				just_wrote_prefix=0
			fi
		else
			echo -n "${each} "
			just_wrote_prefix=0
		fi
	done
	echo
}

if debugging; then
	format_output DEBUG Executing \"${0} ${*}\"
fi

for each in test1 test2 test3; do
	echo "***each=${each}"
	if debugging; then
		format_output DEBUG press enter to continue:
		read
	fi
	echo "***each=${each}"
done

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

end of thread, other threads:[~2000-05-11  4:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-11  0:48 Unexpected Results/Heisenbug Ken Smith
2000-05-11  4:04 ` Bart Schaefer

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