Skip to content

Commit

Permalink
For CSV print more info about what kind of text file it is if we have…
Browse files Browse the repository at this point in the history
… it.

(William Chen)
  • Loading branch information
zoulasc committed Feb 20, 2023
1 parent 0f1835b commit f2bc45d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions src/is_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f2bc45d

Please sign in to comment.