Root/userspace/application/test.ccp

1#pypp 0
2// Iris: micro-kernel for a capability-based operating system.
3// source/test.ccp: Testing program.
4// Copyright 2009 Bas Wijnen <wijnen@debian.org>
5//
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19#include <iris.hh>
20#include <devices.hh>
21
22bool match (char const *a, char const *b, unsigned l1, unsigned l2):
23    if l1 != l2:
24        return false
25    for unsigned i = 0; i < l1; ++i:
26        if a[i] != b[i]:
27            return false
28    return true
29
30static bool print_name (Iris::String name, unsigned indent):
31    unsigned l = name.get_size ().l
32    for unsigned i = 0; i < indent; ++i:
33        kdebug_char (' ')
34    char part[16]
35    for unsigned i = 0; i < l; i += 16:
36        name.get_chars (i, part)
37        for unsigned k = 0; k < 16 && i * 16 + k < l; ++k:
38            kdebug_char (part[k])
39    kdebug_char ('\n')
40    return match (part, ".", l, 1) || match (part, "..", l, 2)
41
42static void print_dir (Iris::Directory dir, unsigned indent):
43    dir.lock_ro ()
44    Iris::Num files = dir.get_size ()
45    for Iris::Num i = 0; i.value () < files.value (); i = i.value () + 1:
46        Iris::String f = dir.get_name (i)
47        bool ignore = print_name (f, indent)
48        if !ignore && dir.get_file_info (i, 0).l & 1:
49            Iris::Directory d = dir.get_file_ro (i)
50            print_dir (d, indent + 4)
51            Iris::free_cap (d)
52        Iris::free_cap (f)
53    dir.unlock_ro ()
54
55Iris::Num start ():
56    Iris::Directory dir = Iris::my_parent.get_capability <Iris::Directory> ()
57    print_dir (dir, 0)
58    return 0
59

Archive Download this file

Branches:
master



interactive