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.
26 #include "parrot/parrot.h"
27 #include "parrot/embed.h"
31 =item C<static INTVAL iter(PARROT_INTERP, PackFile_Segment *seg, void
34 This function is passed the callback to PackFile_map_segments() to print out
35 the name of each segment in the directory.
42 iter(PARROT_INTERP
, PackFile_Segment
*seg
, void *user_data
)
44 long ident
= (long)user_data
;
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));
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().
65 main(int argc
, char *argv
[])
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);
88 printf("%s\n", pf
->directory
.base
.name
);
89 PackFile_map_segments(interp
, &pf
->directory
, iter
, (void*)2);
91 Parrot_exit(interp
, 0);
100 F<src/pbc.c>, F<include/parrot/pbc.h>.
109 * c-file-style: "parrot"
111 * vim: expandtab shiftwidth=4: