Ticket #1911: read_urandom.pir

File read_urandom.pir, 0.7 KB (added by plobsing, 4 years ago)

PIR reading 256 characters from urandom with pretty formatting

Line 
1# Copyright (C) 2006-2009, Parrot Foundation.
2# $Id$
3
4.macro_const BUFLEN 256
5
6.sub 'main' :main
7    .local pmc fh, striter
8    fh = new ['FileHandle']
9    fh.'encoding'('binary')
10    fh.'open'('/dev/urandom', 'r')
11    $S0 = fh.'read'(.BUFLEN)
12    $P0 = box $S0
13    striter = iter $P0
14    $I1 = 1
15  loop:
16    unless striter goto endloop
17    $I0 = shift striter
18    'printf'('%2x ', $I0)
19
20    $I2 = $I1 % 8
21    inc $I1
22    if $I2 goto loop
23    print "\n"
24    goto loop
25  endloop:
26.end
27
28.sub 'printf'
29    .param string fmt
30    .param pmc args :slurpy
31    $S0 = sprintf fmt, args
32    print $S0
33.end
34
35# Local Variables:
36#   mode: pir
37#   fill-column: 100
38# End:
39# vim: expandtab shiftwidth=4 ft=pir:
40