+ Update 052_Rob_Ennals.pdf, courtesy of Elizabeth Mattijsen.
[parrot.git] / src / pbc_info.c
blobc007ff95b6b8f95e3a063d8af14142a724c0dc5d
1 /*
2 Copyright (C) 2001-2003, The Perl Foundation.
3 $Id$
5 =head1 NAME
7 pbc_info - PacFile demo
9 =head1 SYNOPSIS
11 pbc_info file.pbc
13 =head1 DESCRIPTION
15 Sample program for dumping PackFile segment names by iterating
16 over the main directory.
18 =over 4
20 =cut
24 #include "parrot/parrot.h"
25 #include "parrot/embed.h"
29 =item C<static INTVAL iter(Interp*, struct PackFile_Segment *seg, void
30 *user_data)>
32 This function is passed the callback to PackFile_map_segments() to print out
33 the name of each segment in the directory.
35 =cut
39 static INTVAL
40 iter(Interp* interp,
41 struct PackFile_Segment *seg, void *user_data)
43 int ident = (int)user_data;
44 printf("%*.0s%s\n", ident, "", seg->name);
45 if (seg->type == PF_DIR_SEG)
46 PackFile_map_segments(interp, (struct PackFile_Directory*)seg,
47 iter, (void*)(ident+2));
48 return 0;
53 =item C<int main(int argc, char **argv)>
55 Reads the PBC from argv[1], adds a few extra sections, and then iterates over
56 the directory using PackFile_map_segments() and iter().
58 =cut
62 int
63 main(int argc, char * argv[] )
65 struct PackFile *pf;
66 Interp *interp;
67 struct PackFile_Segment *seg;
69 interp = Parrot_new(NULL);
71 pf = Parrot_readbc(interp, argv[1]);
74 * add some more segments
76 seg = PackFile_Segment_new_seg(interp,
77 &pf->directory, PF_DIR_SEG, "dir2", 1);
78 seg = PackFile_Segment_new_seg(interp,
79 (struct PackFile_Directory*)seg, PF_BYTEC_SEG, "code", 1);
80 seg = PackFile_Segment_new_seg(interp,
81 &pf->directory, PF_DIR_SEG, "dir3", 1);
84 * show these
86 printf("%s\n", pf->directory.base.name);
87 PackFile_map_segments(interp, &pf->directory, iter, (void*)2);
89 Parrot_exit(interp, 0);
90 return 0;
95 =back
97 =head1 SEE ALSO
99 F<src/pbc.c>, F<include/parrot/pbc.h>.
101 =cut
107 * Local variables:
108 * c-file-style: "parrot"
109 * End:
110 * vim: expandtab shiftwidth=4: