From f2bc45dd3565d064bd08563f7e22282f0c30a6a0 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Mon, 20 Feb 2023 17:09:30 +0000 Subject: For CSV print more info about what kind of text file it is if we have it. (William Chen) --- src/file.h | 5 +++-- src/funcs.c | 4 ++-- src/is_csv.c | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/file.h b/src/file.h index 9e37044f..14d41fb7 100644 --- a/src/file.h +++ b/src/file.h @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$File: file.h,v 1.242 2023/02/09 17:45:19 christos Exp $ + * @(#)$File: file.h,v 1.243 2023/02/20 17:09:30 christos Exp $ */ #ifndef __file_h__ @@ -547,7 +547,8 @@ file_protected int file_ascmagic_with_encoding(struct magic_set *, file_protected int file_encoding(struct magic_set *, const struct buffer *, file_unichar_t **, size_t *, const char **, const char **, const char **); file_protected int file_is_json(struct magic_set *, const struct buffer *); -file_protected int file_is_csv(struct magic_set *, const struct buffer *, int); +file_protected int file_is_csv(struct magic_set *, const struct buffer *, int, + const char *); file_protected int file_is_tar(struct magic_set *, const struct buffer *); file_protected int file_softmagic(struct magic_set *, const struct buffer *, uint16_t *, uint16_t *, int, int); diff --git a/src/funcs.c b/src/funcs.c index 7a34c1ee..e265de8c 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: funcs.c,v 1.137 2022/12/26 18:48:55 christos Exp $") +FILE_RCSID("@(#)$File: funcs.c,v 1.138 2023/02/20 17:09:30 christos Exp $") #endif /* lint */ #include "magic.h" @@ -398,7 +398,7 @@ file_buffer(struct magic_set *ms, int fd, struct stat *st, /* Check if we have a CSV file */ if ((ms->flags & MAGIC_NO_CHECK_CSV) == 0) { - m = file_is_csv(ms, &b, looks_text); + m = file_is_csv(ms, &b, looks_text, code); if ((ms->flags & MAGIC_DEBUG) != 0) (void)fprintf(stderr, "[try csv %d]\n", m); if (m) { diff --git a/src/is_csv.c b/src/is_csv.c index 597d7756..12dc2572 100644 --- a/src/is_csv.c +++ b/src/is_csv.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: is_csv.c,v 1.10 2022/09/24 20:30:13 christos Exp $") +FILE_RCSID("@(#)$File: is_csv.c,v 1.11 2023/02/20 17:09:30 christos Exp $") #endif #include @@ -130,7 +130,8 @@ csv_parse(const unsigned char *uc, const unsigned char *ue) #ifndef TEST int -file_is_csv(struct magic_set *ms, const struct buffer *b, int looks_text) +file_is_csv(struct magic_set *ms, const struct buffer *b, int looks_text, + const char *code) { const unsigned char *uc = CAST(const unsigned char *, b->fbuf); const unsigned char *ue = uc + b->flen; @@ -154,7 +155,7 @@ file_is_csv(struct magic_set *ms, const struct buffer *b, int looks_text) return 1; } - if (file_printf(ms, "CSV text") == -1) + if (file_printf(ms, "CSV %s", code ? code : "text") == -1) return -1; return 1; -- cgit v1.2.1