* src/pbc_merge.c:
[parrot.git] / src / pbc_info.c
blob93ae10cba88358e0177f74f6ecd62bcb22eddcae
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 =head2 Functions
20 =over 4
22 =cut
26 #include "parrot/parrot.h"
27 #include "parrot/embed.h"
31 =item C<static INTVAL iter(PARROT_INTERP, PackFile_Segment *seg, void
32 *user_data)>
34 This function is passed the callback to PackFile_map_segments() to print out
35 the name of each segment in the directory.
37 =cut
41 static INTVAL
42 iter(PARROT_INTERP, PackFile_Segment *seg, void *user_data)
44 long ident = (long)user_data;
45 int length = ident;
46 printf("%*.0s%s\n", length, "", seg->name);
47 if (seg->type == PF_DIR_SEG)
48 PackFile_map_segments(interp, (PackFile_Directory*)seg,
49 iter, (void*)(ident+2));
50 return 0;
55 =item C<int main(int argc, char *argv[])>
57 Reads the PBC from argv[1], adds a few extra sections, and then iterates over
58 the directory using PackFile_map_segments() and iter().
60 =cut
64 int
65 main(int argc, char *argv[])
67 PackFile *pf;
68 Interp *interp;
69 PackFile_Segment *seg;
71 interp = Parrot_new(NULL);
73 pf = Parrot_readbc(interp, argv[1]);
76 * add some more segments
78 seg = PackFile_Segment_new_seg(interp,
79 &pf->directory, PF_DIR_SEG, "dir2", 1);
80 seg = PackFile_Segment_new_seg(interp,
81 (PackFile_Directory*)seg, PF_BYTEC_SEG, "code", 1);
82 seg = PackFile_Segment_new_seg(interp,
83 &pf->directory, PF_DIR_SEG, "dir3", 1);
86 * show these
88 printf("%s\n", pf->directory.base.name);
89 PackFile_map_segments(interp, &pf->directory, iter, (void*)2);
91 Parrot_exit(interp, 0);
96 =back
98 =head1 SEE ALSO
100 F<src/pbc.c>, F<include/parrot/pbc.h>.
102 =cut
108 * Local variables:
109 * c-file-style: "parrot"
110 * End:
111 * vim: expandtab shiftwidth=4: