summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Zoulas <christos@zoulas.com>2023-02-20 17:09:30 +0000
committerChristos Zoulas <christos@zoulas.com>2023-02-20 17:09:30 +0000
commitf2bc45dd3565d064bd08563f7e22282f0c30a6a0 (patch)
treee774746e5dca24440ba783d1c7bf688aeaa49560
parent0f1835b2dad51da5f5da3f87677a7827830a46ea (diff)
downloadfile-git-f2bc45dd3565d064bd08563f7e22282f0c30a6a0.tar.gz
For CSV print more info about what kind of text file it is if we have it.
(William Chen)
-rw-r--r--src/file.h5
-rw-r--r--src/funcs.c4
-rw-r--r--src/is_csv.c7
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 <string.h>
@@ -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;