/* * dump_nodes -- * dump the NODEs from `cur', based in the directory `dir'. * if pathlast is none zero, print the path last, otherwise print * it first. */ void dump_nodes(const char *dir, NODE *root, int pathlast) { NODE *cur; char path[MAXPATHLEN]; const char *name; char *str; char *p, *q; for (cur = root; cur != NULL; cur = cur->next) { if (cur->type != F_DIR && !matchtags(cur)) continue; if (snprintf(path, sizeof(path), "%s%s%s", dir, *dir ? "/" : "", cur->name) >= (int)sizeof(path)) mtree_err("Pathname too long."); if (!pathlast) printf("%s", vispath(path)); #define MATCHFLAG(f) ((keys & (f)) && (cur->flags & (f))) if (MATCHFLAG(F_TYPE)) appendfield(pathlast, "type=%s", nodetype(cur->type)); if (MATCHFLAG(F_UID | F_UNAME)) { if (keys & F_UNAME && (name = user_from_uid(cur->st_uid, 1)) != NULL) appendfield(pathlast, "uname=%s", name); else appendfield(pathlast, "uid=%u", cur->st_uid); } if (MATCHFLAG(F_GID | F_GNAME)) { if (keys & F_GNAME && (name = group_from_gid(cur->st_gid, 1)) != NULL) appendfield(pathlast, "gname=%s", name); else appendfield(pathlast, "gid=%u", cur->st_gid); } if (MATCHFLAG(F_MODE)) appendfield(pathlast, "mode=%#o", cur->st_mode); if (MATCHFLAG(F_DEV) && (cur->type == F_BLOCK || cur->type == F_CHAR)) appendfield(pathlast, "device=%#llx", (long long)cur->st_rdev); if (MATCHFLAG(F_NLINK)) appendfield(pathlast, "nlink=%d", cur->st_nlink); if (MATCHFLAG(F_SLINK)) appendfield(pathlast, "link=%s", vispath(cur->slink)); if (MATCHFLAG(F_SIZE)) appendfield(pathlast, "size=%lld", (long long)cur->st_size); if (MATCHFLAG(F_TIME)) appendfield(pathlast, "time=%lld.%09ld", (long long)cur->st_mtimespec.tv_sec, cur->st_mtimespec.tv_nsec); if (MATCHFLAG(F_CKSUM)) appendfield(pathlast, "cksum=%lu", cur->cksum); if (MATCHFLAG(F_MD5)) appendfield(pathlast, "%s=%s", MD5KEY, cur->md5digest); if (MATCHFLAG(F_RMD160)) appendfield(pathlast, "%s=%s", RMD160KEY, cur->rmd160digest); if (MATCHFLAG(F_SHA1)) appendfield(pathlast, "%s=%s", SHA1KEY, cur->sha1digest); if (MATCHFLAG(F_SHA256)) appendfield(pathlast, "%s=%s", SHA256KEY, cur->sha256digest); if (MATCHFLAG(F_SHA384)) appendfield(pathlast, "%s=%s", SHA384KEY, cur->sha384digest); if (MATCHFLAG(F_SHA512)) appendfield(pathlast, "%s=%s", SHA512KEY, cur->sha512digest); if (MATCHFLAG(F_FLAGS)) { str = flags_to_string(cur->st_flags, "none"); appendfield(pathlast, "flags=%s", str); free(str); } if (MATCHFLAG(F_IGN)) appendfield(pathlast, "ignore"); if (MATCHFLAG(F_OPT)) appendfield(pathlast, "optional"); if (MATCHFLAG(F_TAGS)) { /* don't output leading or trailing commas */ p = cur->tags; while (*p == ',') p++; q = p + strlen(p); while(q > p && q[-1] == ',') q--; appendfield(pathlast, "tags=%.*s", (int)(q - p), p); } puts(pathlast ? vispath(path) : ""); if (cur->child) dump_nodes(path, cur->child, pathlast); } }
/* * dump_nodes -- * dump the NODEs from `cur', based in the directory `dir'. * if pathlast is none zero, print the path last, otherwise print * it first. */ void dump_nodes(const char *dir, NODE *root, int pathlast) { NODE *cur; char path[MAXPATHLEN]; const char *name; for (cur = root; cur != NULL; cur = cur->next) { if (cur->type != F_DIR && !matchtags(cur)) continue; if (snprintf(path, sizeof(path), "%s%s%s", dir, *dir ? "/" : "", cur->name) >= sizeof(path)) mtree_err("Pathname too long."); if (!pathlast) printf("%s ", vispath(path)); #define MATCHFLAG(f) ((keys & (f)) && (cur->flags & (f))) if (MATCHFLAG(F_TYPE)) printf("type=%s ", nodetype(cur->type)); if (MATCHFLAG(F_UID | F_UNAME)) { if (keys & F_UNAME && (name = user_from_uid(cur->st_uid, 1)) != NULL) printf("uname=%s ", name); else printf("uid=%u ", cur->st_uid); } if (MATCHFLAG(F_GID | F_GNAME)) { if (keys & F_GNAME && (name = group_from_gid(cur->st_gid, 1)) != NULL) printf("gname=%s ", name); else printf("gid=%u ", cur->st_gid); } if (MATCHFLAG(F_MODE)) printf("mode=%#o ", cur->st_mode); if (MATCHFLAG(F_DEV) && (cur->type == F_BLOCK || cur->type == F_CHAR)) printf("device=%#x ", cur->st_rdev); if (MATCHFLAG(F_NLINK)) printf("nlink=%d ", cur->st_nlink); if (MATCHFLAG(F_SLINK)) printf("link=%s ", cur->slink); if (MATCHFLAG(F_SIZE)) printf("size=%lld ", (long long)cur->st_size); if (MATCHFLAG(F_TIME)) printf("time=%ld.%ld ", (long)cur->st_mtimespec.tv_sec, cur->st_mtimespec.tv_nsec); if (MATCHFLAG(F_CKSUM)) printf("cksum=%lu ", cur->cksum); if (MATCHFLAG(F_MD5)) printf("md5=%s ", cur->md5digest); if (MATCHFLAG(F_RMD160)) printf("rmd160=%s ", cur->rmd160digest); if (MATCHFLAG(F_SHA1)) printf("sha1=%s ", cur->sha1digest); if (MATCHFLAG(F_FLAGS)) printf("flags=%s ", flags_to_string(cur->st_flags, "none")); if (MATCHFLAG(F_IGN)) printf("ignore "); if (MATCHFLAG(F_OPT)) printf("optional "); if (MATCHFLAG(F_TAGS)) printf("tags=%s ", cur->tags); puts(pathlast ? vispath(path) : ""); if (cur->child) dump_nodes(path, cur->child, pathlast); } }