summaryrefslogtreecommitdiffstats
path: root/printf.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-04-23 00:00:37 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-04-23 00:17:49 -0400
commit1efa932e4aeb007eddb6424a90bf0fc05dba7e4d (patch)
tree288ae5aa5385f985cbd4818497e01cf845591617 /printf.c
parent8df078ada9045ffceb541e224985a4e4191e1526 (diff)
downloadbfs-1efa932e4aeb007eddb6424a90bf0fc05dba7e4d.tar.xz
Implement -fstype
Fixes #6!
Diffstat (limited to 'printf.c')
-rw-r--r--printf.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/printf.c b/printf.c
index cc8989f..50a9dcf 100644
--- a/printf.c
+++ b/printf.c
@@ -13,6 +13,7 @@
#include "bfs.h"
#include "color.h"
#include "dstring.h"
+#include "mtab.h"
#include "util.h"
#include <assert.h>
#include <errno.h>
@@ -39,6 +40,8 @@ struct bfs_printf_directive {
enum time_field time_field;
/** Character data associated with this directive. */
char c;
+ /** The current mount table. */
+ const struct bfs_mtab *mtab;
/** The next printf directive in the chain. */
struct bfs_printf_directive *next;
};
@@ -175,6 +178,12 @@ static int bfs_printf_f(FILE *file, const struct bfs_printf_directive *directive
return fprintf(file, directive->str, ftwbuf->path + ftwbuf->nameoff);
}
+/** %F: file system type */
+static int bfs_printf_F(FILE *file, const struct bfs_printf_directive *directive, const struct BFTW *ftwbuf) {
+ const char *type = bfs_fstype(directive->mtab, ftwbuf->statbuf);
+ return fprintf(file, directive->str, type);
+}
+
/** %G: gid */
static int bfs_printf_G(FILE *file, const struct bfs_printf_directive *directive, const struct BFTW *ftwbuf) {
BFS_PRINTF_BUF(buf, "%ju", (uintmax_t)ftwbuf->statbuf->st_gid);
@@ -393,6 +402,7 @@ static struct bfs_printf_directive *new_directive() {
}
directive->time_field = 0;
directive->c = 0;
+ directive->mtab = NULL;
directive->next = NULL;
return directive;
@@ -433,7 +443,9 @@ static int append_literal(struct bfs_printf_directive ***tail, struct bfs_printf
return 0;
}
-struct bfs_printf *parse_bfs_printf(const char *format, CFILE *cerr) {
+struct bfs_printf *parse_bfs_printf(const char *format, const struct cmdline *cmdline) {
+ CFILE *cerr = cmdline->cerr;
+
struct bfs_printf *command = malloc(sizeof(*command));
if (!command) {
perror("malloc()");
@@ -584,6 +596,15 @@ struct bfs_printf *parse_bfs_printf(const char *format, CFILE *cerr) {
case 'f':
directive->fn = bfs_printf_f;
break;
+ case 'F':
+ if (!cmdline->mtab) {
+ cfprintf(cerr, "%{er}error: '%s': Couldn't parse the mount table.%{rs}\n", format);
+ goto directive_error;
+ }
+ directive->fn = bfs_printf_F;
+ directive->mtab = cmdline->mtab;
+ command->needs_stat = true;
+ break;
case 'g':
directive->fn = bfs_printf_g;
command->needs_stat = true;