cvsuser     04/05/19 05:44:16

  Modified:    classes  parrotio.pmc
               t/pmc    io.t
  Log:
  io_layers 1 - interface to query existing layers
  
  Revision  Changes    Path
  1.20      +37 -1     parrot/classes/parrotio.pmc
  
  Index: parrotio.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/parrotio.pmc,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -w -r1.19 -r1.20
  --- parrotio.pmc      22 Feb 2004 17:48:41 -0000      1.19
  +++ parrotio.pmc      19 May 2004 12:44:11 -0000      1.20
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: parrotio.pmc,v 1.19 2004/02/22 17:48:41 mikescott Exp $
  +$Id: parrotio.pmc,v 1.20 2004/05/19 12:44:11 leo Exp $
   
   =head1 NAME
   
  @@ -138,6 +138,42 @@
           return !PIO_eof(INTERP, SELF);
       }
   
  +/*
  +
  +=item C<STRING* get_string_keyed_int(INTVAL n)>
  +
  +Return the name of the nth layer. B<n> >= 0 returns layer names up
  +from the bottom.
  +If B<n> is negative returns layer names from top down. For non-existing
  +layers an empty string is returned.
  +
  +=cut
  +
  +*/
  +
  +    STRING* get_string_keyed_int(INTVAL n) {
  +        ParrotIO *io = PMC_data(SELF);
  +        ParrotIOLayer *layer;
  +        if (!io)
  +            return const_string(interpreter, "");
  +        layer = io->stack;
  +        if (n >= 0) {
  +            ParrotIOLayer *last;
  +            last = layer;
  +            for (; layer; layer = layer->down)
  +                last = layer;
  +            for (; n && last; --n, last = last->up)
  +                ;
  +            if (last)
  +                return string_from_cstring(interpreter, last->name, 0);
  +            return const_string(interpreter, "");
  +        }
  +        for (++n; n && layer; layer = layer->down, ++n)
  +            ;
  +        if (layer)
  +            return string_from_cstring(interpreter, layer->name, 0);
  +        return const_string(interpreter, "");
  +    }
   }
   
   /*
  
  
  
  1.27      +24 -2     parrot/t/pmc/io.t
  
  Index: io.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/io.t,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -w -r1.26 -r1.27
  --- io.t      16 May 2004 20:19:30 -0000      1.26
  +++ io.t      19 May 2004 12:44:15 -0000      1.27
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: io.t,v 1.26 2004/05/16 20:19:30 boemmels Exp $
  +# $Id: io.t,v 1.27 2004/05/19 12:44:15 leo Exp $
   
   =head1 NAME
   
  @@ -16,7 +16,7 @@
   
   =cut
   
  -use Parrot::Test tests => 23;
  +use Parrot::Test tests => 24;
   use Test::More;
   
   sub file_content_is {
  @@ -409,3 +409,25 @@
   OUTPUT
   
   unlink "temp.file";
  +
  +output_like(<<'CODE', <<'OUTPUT', "layer names");
  +    getstdin P0
  +    set S0, P0[0]
  +    print S0
  +    print "-"
  +    set S0, P0[1]
  +    print S0
  +    print "-"
  +    set S0, P0[-1]
  +    print S0
  +    print "-"
  +    set S0, P0[-2]
  +    print S0
  +    print "-"
  +    set S0, P0[-3]
  +    print S0
  +    print "-"
  +    end
  +CODE
  +/^(unix|win32|stdio)-buf-buf-\1--$/
  +OUTPUT
  
  
  

Reply via email to