Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > cd14cddf3b3ceaf1193157472227757a > files > 761

parrot-doc-1.6.0-1mdv2010.0.i586.rpm

# This line will be printed by ./parrot examples/pir/readline.t

# Copyright (C) 2001-2008, Parrot Foundation.
# $Id: readline.pir 37201 2009-03-08 12:07:48Z fperrad $

=head1 NAME

examples/pir/readline.pir - Read,concatenate and print

=head1 SYNOPSIS

    % ./parrot examples/pir/readline.pir

=head1 DESCRIPTION

Reads from C<stdin> and concatenates to a buffer. When an empty line is
received the buffer is printed and the program is terminated.

=cut

.include 'cclass.pasm'

.sub "example" :main
        .local pmc stdin
        .local string buffer, line

	stdin = getstdin
	buffer = ""

AGAIN:
	line = readline stdin
	$I1 = length line
	if $I1 <= 1 goto MAINLOOP
	# test for multi-char newlines
	if $I1 >=3 goto CONCAT
	$I2 = is_cclass .CCLASS_NEWLINE, line, 0
	if $I2, MAINLOOP

CONCAT:
	concat buffer, line
	branch AGAIN

MAINLOOP:
	print buffer
.end

# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: