File: pbc_info.c

package info (click to toggle)
parrot 6.6.0-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,164 kB
  • ctags: 16,050
  • sloc: ansic: 110,715; perl: 94,382; yacc: 1,911; lex: 1,529; lisp: 1,163; cpp: 782; python: 646; ruby: 335; sh: 140; makefile: 129; cs: 49; asm: 30
file content (112 lines) | stat: -rw-r--r-- 2,076 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
Copyright (C) 2001-2010, Parrot Foundation.

=head1 NAME

pbc_info - PackFile demo

=head1 SYNOPSIS

 pbc_info file.pbc

=head1 DESCRIPTION

Sample program for dumping PackFile segment names by iterating
over the main directory.

=head2 Functions

=over 4

=cut

*/

#include "parrot/parrot.h"

/*
=item C<static INTVAL iter(PARROT_INTERP, PackFile_Segment *seg, void
*user_data)>

=item C<static INTVAL iter(PARROT_INTERP, PackFile_Segment *seg, void *user_data)>

This function is passed the callback to PackFile_map_segments() to print out
the name of each segment in the directory.

=cut

*/

static INTVAL
iter(PARROT_INTERP, PackFile_Segment *seg, void *user_data)
{
    long ident = (long)user_data;
    int length = ident;
    printf("%*.0s%s\n", length, "", seg->name);
    if (seg->type == PF_DIR_SEG)
        PackFile_map_segments(interp, (PackFile_Directory*)seg,
                iter, (void*)(ident+2));
    return 0;
}

/*

=item C<int main(int argc, char *argv[])>

Reads the PBC from argv[1], adds a few extra sections, and then iterates over
the directory using PackFile_map_segments() and iter().

=cut

*/

int
main(SHIM(int argc), char *argv[])
{
    PackFile *pf;
    Interp *interp;
    PackFile_Segment *seg;

    interp = Parrot_new(NULL);

    pf = Parrot_pbc_read(interp, argv[1], PFOPT_UTILS);

    /*
     * add some more segments
     */
    seg = PackFile_Segment_new_seg(interp,
                    &pf->directory, PF_DIR_SEG, "dir2", 1);
    seg = PackFile_Segment_new_seg(interp,
                    (PackFile_Directory*)seg, PF_BYTEC_SEG, "code", 1);
    seg = PackFile_Segment_new_seg(interp,
                    &pf->directory, PF_DIR_SEG, "dir3", 1);

    /*
     * show these
     */
    printf("%s\n", pf->directory.base.name);
    PackFile_map_segments(interp, &pf->directory, iter, (void*)2);

    Parrot_x_exit(interp, 0);
}

/*

=back

=head1 SEE ALSO

F<src/packfile.c>, F<include/parrot/packfile.h>.

=cut

*/


/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
 */