📄 tree.c
字号:
/* * Copyright (C) 2008 dhewg, #wiidev efnet * based on code by: * Copyright (C) 2005 Janusz Dziemidowicz (rraptorr@nails.eu.org) * * this file is part of wiifuse * http://wiibrew.org/index.php?title=Wiifuse * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <sys/types.h>#include <stdlib.h>#include <unistd.h>#include <stdio.h>#include <string.h>#include "io.h"#include "tree.h"#include "image.h"struct tree *tree_add_entry (u32 part, struct tree *root, enum tree_type type, const char *name, u64 v1, u64 v2) { struct tree *node = (struct tree *) malloc (sizeof (struct tree)); memset (node, 0, (sizeof (struct tree))); node->part = part; node->type = type; node->name = strdup (name); node->next = root->sub; root->sub = node; node->v1 = v1; node->v2 = v2; if (type == TREE_DIR) root->nsubdirs++; return node;}struct tree *tree_add_filler (u32 part, struct tree *root, const char *name) { return tree_add_entry (part, root, TREE_FILE, name, 0, 0);}struct tree *tree_add_dir (u32 part, struct tree *root, const char *name) { return tree_add_entry (part, root, TREE_DIR, name, 0, 0);}struct tree *tree_add_file (u32 part, struct tree *root, const char *name, u64 offset, u64 size) { return tree_add_entry (part, root, TREE_FILE, name, offset, size);}struct tree *tree_add_raw_file (u32 part, struct tree *root, const char *name, u64 offset, u64 size) { return tree_add_entry (part, root, TREE_RAW_FILE, name, offset, size);}struct tree *tree_add_mem (u32 part, struct tree *root, const char *name, void *ptr, size_t size) { return tree_add_entry (part, root, TREE_MEM, name, ptr, size);}struct tree *tree_add_uint (u32 part, struct tree *root, const char *name, const u64 value) { char str[22]; sprintf (str, "%llu", value); return tree_add_entry (part, root, TREE_UINT, name, value, g_strnlen (str, 22) + 1);}struct tree *tree_add_hex_uint8 (u32 part, struct tree *root, const char *name, const u8 value) { return tree_add_entry (part, root, TREE_HEX_UINT8, name, value, 5);}struct tree *tree_add_hex_uint16 (u32 part, struct tree *root, const char *name, const u16 value) { return tree_add_entry (part, root, TREE_HEX_UINT16, name, value, 7);}struct tree *tree_add_hex_uint32 (u32 part, struct tree *root, const char *name, const u32 value) { return tree_add_entry (part, root, TREE_HEX_UINT32, name, value, 11);}struct tree *tree_add_hex_uint64 (u32 part, struct tree *root, const char *name, const u64 value) { return tree_add_entry (part, root, TREE_HEX_UINT64, name, value, 19);}struct tree *tree_add_char (u32 part, struct tree *root, const char *name, const char c) { return tree_add_entry (part, root, TREE_CHAR, name, c, 2);}struct tree *tree_add_bool (u32 part, struct tree *root, const char *name, const u8 b) { return tree_add_char (part, root, name, b ? '1' : '0');}struct tree *tree_add_string (u32 part, struct tree *root, const char *name, const char *str, size_t size) { return tree_add_entry (part, root, TREE_STRING, name, str, g_strnlen (str, size) + 1);}struct tree *tree_add_symlink (u32 part, struct tree *root, const char *name, const char *dst) { return tree_add_entry (part, root, TREE_SYMLINK, name, strdup (dst), strlen (dst));}struct tree *tree_find_entry (struct tree *root, const char *path) { struct tree *node, *ret; const char *next; if (!root) return NULL; if (!strcmp (path, root->name)) return root; if (strncmp (path, root->name, strlen (root->name))) return NULL; next = path + strlen (root->name); if (*next != '/') return NULL; next++; if (!*next) return root; node = root->sub; while (node) { ret = tree_find_entry (node, next); if (ret) return ret; node = node->next; } return NULL;}void tree_free (struct tree *root) { struct tree *node, *next; node = root->sub; while (node) { next = node->next; tree_free (node); node = next; } if (root->type == TREE_SYMLINK) free ((char *) ((size_t) root->v1)); free (root->name); free (root);}struct tree *tree_empty (void) { struct tree *ret; ret = (struct tree *) malloc (sizeof (struct tree)); memset (ret, 0, (sizeof (struct tree))); ret->name = strdup (""); ret->type = TREE_DIR; return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -