38FILE_RCSID(
"@(#)$File: ascmagic.c,v 1.116 2023/05/21 16:08:50 christos Exp $")
50#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
51 || (x) == 0x85 || (x) == '\f')
64 while (nbytes > 1 &&
buf[nbytes - 1] ==
'\0')
78 const char *code =
NULL;
79 const char *code_mime =
NULL;
110 const unsigned char *
buf =
CAST(
const unsigned char *, b->
fbuf);
111 size_t nbytes = b->
flen;
112 unsigned char *utf8_buf =
NULL, *utf8_end;
116 int need_separator = 0;
118 const char *subtype =
NULL;
121 int has_backspace = 0;
130 size_t last_line_end =
CAST(
size_t, -1);
131 size_t has_long_lines = 0;
150 if ((utf8_end =
encode_utf8(utf8_buf, mlen, ubuf, ulen))
156 CAST(
size_t, utf8_end - utf8_buf));
165 rv =
rv == -1 ? 0 : 1;
176 for (i = 0; i < ulen; i++) {
177 if (ubuf[i] ==
'\n') {
186 seen_cr = (ubuf[i] ==
'\r');
190 if (ubuf[i] == 0x85) {
197 size_t ll = i - last_line_end;
198 if (ll > has_long_lines)
202 if (ubuf[i] ==
'\033')
270 if (
file_printf(ms,
", with very long lines (%zu)",
271 has_long_lines) == -1)
278 if ((n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) ||
279 (n_crlf != 0 || n_cr != 0 || n_nel != 0)) {
283 if (n_crlf == 0 && n_cr == 0 &&
284 n_nel == 0 && n_lf == 0) {
291 if (n_cr || n_lf || n_nel)
319 if (
file_printf(ms,
", with escape sequences") == -1)
343 for (i = 0; i < ulen; i++) {
344 if (ubuf[i] <= 0x7f) {
347 *
buf++ =
CAST(
unsigned char, ubuf[i]);
350 if (ubuf[i] <= 0x7ff) {
353 *
buf++ =
CAST(
unsigned char, (ubuf[i] >> 6) + 0xc0);
356 if (ubuf[i] <= 0xffff) {
359 *
buf++ =
CAST(
unsigned char, (ubuf[i] >> 12) + 0xe0);
362 if (ubuf[i] <= 0x1fffff) {
365 *
buf++ =
CAST(
unsigned char, (ubuf[i] >> 18) + 0xf0);
368 if (ubuf[i] <= 0x3ffffff) {
371 *
buf++ =
CAST(
unsigned char, (ubuf[i] >> 24) + 0xf8);
374 if (ubuf[i] <= 0x7fffffff) {
377 *
buf++ =
CAST(
unsigned char, (ubuf[i] >> 30) + 0xfc);
382 out5: *
buf++ =
CAST(
unsigned char, ((ubuf[i] >> 24) & 0x3f) + 0x80);
383 out4: *
buf++ =
CAST(
unsigned char, ((ubuf[i] >> 18) & 0x3f) + 0x80);
384 out3: *
buf++ =
CAST(
unsigned char, ((ubuf[i] >> 12) & 0x3f) + 0x80);
385 out2: *
buf++ =
CAST(
unsigned char, ((ubuf[i] >> 6) & 0x3f) + 0x80);
386 out1: *
buf++ =
CAST(
unsigned char, ((ubuf[i] >> 0) & 0x3f) + 0x80);
file_protected int file_ascmagic(struct magic_set *ms, const struct buffer *b, int text)
file_private unsigned char * encode_utf8(unsigned char *, size_t, file_unichar_t *, size_t)
file_private size_t trim_nuls(const unsigned char *, size_t)
file_protected int file_ascmagic_with_encoding(struct magic_set *ms, const struct buffer *b, file_unichar_t *ubuf, size_t ulen, const char *code, const char *type, int text)
void buffer_fini(struct buffer *b)
void buffer_init(struct buffer *b, int fd, const zend_stat_t *st, const void *data, size_t len)
zend_ffi_ctype_name_buf buf
file_protected int file_encoding(struct magic_set *ms, const struct buffer *b, file_unichar_t **ubuf, size_t *ulen, const char **code, const char **code_mime, const char **type)
unsigned long file_unichar_t
file_protected int file_printf(struct magic_set *, const char *,...) __attribute__((__format__(__printf__
file_protected int file_softmagic(struct magic_set *, const struct buffer *, uint16_t *, uint16_t *, int, int)
file_protected void file_oomem(struct magic_set *, size_t)
file_protected int file_protected int file_separator(struct magic_set *)
file_protected size_t file_printedlen(const struct magic_set *)
file_protected int file_replace(struct magic_set *, const char *, const char *)
#define MAGIC_NO_CHECK_SOFT
unsigned const char * end
unsigned const char * text
strcmp(string $string1, string $string2)