2 Copyright (C) 2001-2003, The Perl Foundation.
7 pbc_info - PacFile demo
15 Sample program for dumping PackFile segment names by iterating
16 over the main directory.
24 #include "parrot/parrot.h"
25 #include "parrot/embed.h"
29 =item C<static INTVAL iter(Interp*, struct PackFile_Segment *seg, void
32 This function is passed the callback to PackFile_map_segments() to print out
33 the name of each segment in the directory.
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));
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().
63 main(int argc
, char * argv
[] )
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);
86 printf("%s\n", pf
->directory
.base
.name
);
87 PackFile_map_segments(interp
, &pf
->directory
, iter
, (void*)2);
89 Parrot_exit(interp
, 0);
99 F<src/pbc.c>, F<include/parrot/pbc.h>.
108 * c-file-style: "parrot"
110 * vim: expandtab shiftwidth=4: