Added little macros to simplify IsoNode type hierarchy handling.
This commit is contained in:
parent
0beee602b0
commit
04c6bf39b4
10
demo/tree.c
10
demo/tree.c
@ -49,20 +49,20 @@ print_dir(IsoDir *dir, int level)
|
|||||||
iso_dir_get_children(dir, &iter);
|
iso_dir_get_children(dir, &iter);
|
||||||
while (iso_dir_iter_next(iter, &node) == 1) {
|
while (iso_dir_iter_next(iter, &node) == 1) {
|
||||||
|
|
||||||
if (iso_node_get_type(node) == LIBISO_DIR) {
|
if (ISO_NODE_IS_DIR(node)) {
|
||||||
printf("%s+[D] ", sp);
|
printf("%s+[D] ", sp);
|
||||||
print_permissions(iso_node_get_permissions(node));
|
print_permissions(iso_node_get_permissions(node));
|
||||||
printf(" %s\n", iso_node_get_name(node));
|
printf(" %s\n", iso_node_get_name(node));
|
||||||
print_dir((IsoDir*)node, level+1);
|
print_dir(ISO_DIR(node), level+1);
|
||||||
} else if (iso_node_get_type(node) == LIBISO_FILE) {
|
} else if (ISO_NODE_IS_FILE(node)) {
|
||||||
printf("%s-[F] ", sp);
|
printf("%s-[F] ", sp);
|
||||||
print_permissions(iso_node_get_permissions(node));
|
print_permissions(iso_node_get_permissions(node));
|
||||||
printf(" %s\n", iso_node_get_name(node) );
|
printf(" %s\n", iso_node_get_name(node) );
|
||||||
} else if (iso_node_get_type(node) == LIBISO_SYMLINK) {
|
} else if (ISO_NODE_IS_SYMLINK(node)) {
|
||||||
printf("%s-[L] ", sp);
|
printf("%s-[L] ", sp);
|
||||||
print_permissions(iso_node_get_permissions(node));
|
print_permissions(iso_node_get_permissions(node));
|
||||||
printf(" %s -> %s \n", iso_node_get_name(node),
|
printf(" %s -> %s \n", iso_node_get_name(node),
|
||||||
iso_symlink_get_dest((IsoSymlink*)node) );
|
iso_symlink_get_dest(ISO_SYMLINK(node)) );
|
||||||
} else {
|
} else {
|
||||||
printf("%s-[C] ", sp);
|
printf("%s-[C] ", sp);
|
||||||
print_permissions(iso_node_get_permissions(node));
|
print_permissions(iso_node_get_permissions(node));
|
||||||
|
@ -25,6 +25,21 @@ typedef struct Iso_Symlink IsoSymlink;
|
|||||||
typedef struct Iso_File IsoFile;
|
typedef struct Iso_File IsoFile;
|
||||||
typedef struct Iso_Special IsoSpecial;
|
typedef struct Iso_Special IsoSpecial;
|
||||||
|
|
||||||
|
/* macros to check node type */
|
||||||
|
#define ISO_NODE_IS_DIR(n) (iso_node_get_type(n) == LIBISO_DIR)
|
||||||
|
#define ISO_NODE_IS_FILE(n) (iso_node_get_type(n) == LIBISO_FILE)
|
||||||
|
#define ISO_NODE_IS_SYMLINK(n) (iso_node_get_type(n) == LIBISO_SYMLINK)
|
||||||
|
#define ISO_NODE_IS_SPECIAL(n) (iso_node_get_type(n) == LIBISO_SPECIAL)
|
||||||
|
#define ISO_NODE_IS_BOOTCAT(n) (iso_node_get_type(n) == LIBISO_BOOT)
|
||||||
|
|
||||||
|
/* macros for safe downcasting */
|
||||||
|
#define ISO_DIR(n) ((IsoDir*)(ISO_NODE_IS_DIR(n) ? n : NULL))
|
||||||
|
#define ISO_FILE(n) ((IsoFile*)(ISO_NODE_IS_FILE(n) ? n : NULL))
|
||||||
|
#define ISO_SYMLINK(n) ((IsoSymlink*)(ISO_NODE_IS_SYMLINK(n) ? n : NULL))
|
||||||
|
#define ISO_SPECIAL(n) ((IsoSpecial*)(ISO_NODE_IS_SPECIAL(n) ? n : NULL))
|
||||||
|
|
||||||
|
#define ISO_NODE(n) ((IsoNode*)n)
|
||||||
|
|
||||||
typedef struct Iso_Dir_Iter IsoDirIter;
|
typedef struct Iso_Dir_Iter IsoDirIter;
|
||||||
|
|
||||||
typedef struct el_torito_boot_image ElToritoBootImage;
|
typedef struct el_torito_boot_image ElToritoBootImage;
|
||||||
|
Loading…
Reference in New Issue
Block a user