-
Notifications
You must be signed in to change notification settings - Fork 138
/
readline.pir
51 lines (36 loc) · 1016 Bytes
/
readline.pir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# This line will be printed by ./parrot examples/pir/readline.t
# Copyright (C) 2001-2010, Parrot Foundation.
=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'
.loadlib 'io_ops'
.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:
buffer = concat buffer, line
branch AGAIN
MAINLOOP:
print buffer
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: