36FILE_RCSID(
"@(#)$File: is_simh.c,v 1.10 2023/07/27 19:39:55 christos Exp $")
47#define CAST(a, b) (a)(b)
53#define DPRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
55#define DPRINTF(fmt, ...)
65#define SIMH_TAPEMARKS 10
75#define NEED_SWAP (simh_bo.u == CAST(uint32_t, 0x01020304))
94getlen(
const unsigned char **uc)
110simh_parse(
const unsigned char *uc,
const unsigned char *ue)
112 uint32_t nbytes, cbytes;
113 const unsigned char *orig_uc = uc;
114 size_t nt = 0, nr = 0;
119 nbytes = getlen(&uc);
120 if ((nt > 0 || nr > 0) && nbytes == 0xFFFFFFFF)
135 cbytes = getlen(&uc);
136 if (nbytes != cbytes)
140 if (nt *
sizeof(uint32_t) ==
CAST(
size_t, uc - orig_uc))
151 const unsigned char *uc =
CAST(
const unsigned char *, b->
fbuf);
152 const unsigned char *ue = uc + b->
flen;
158 if (!simh_parse(uc, ue))
165 if (
file_printf(ms,
"application/SIMH-tape-data") == -1)
178#include <sys/types.h>
188main(
int argc,
char *argv[])
194 if ((
fd = open(argv[1], O_RDONLY)) == -1)
195 err(EXIT_FAILURE,
"Can't open `%s'", argv[1]);
198 err(EXIT_FAILURE,
"Can't stat `%s'", argv[1]);
200 if ((
p =
CAST(
char *, malloc(st.st_size))) ==
NULL)
201 err(EXIT_FAILURE,
"Can't allocate %jd bytes",
202 (intmax_t)st.st_size);
203 if (read(
fd,
p, st.st_size) != st.st_size)
204 err(EXIT_FAILURE,
"Can't read %jd bytes",
205 (intmax_t)st.st_size);
206 printf(
"is simh %d\n", simh_parse(
p,
p + st.st_size));
file_private uint32_t swap4(uint32_t)
printf(string $format, mixed ... $values)
file_protected int file_printf(struct magic_set *, const char *,...) __attribute__((__format__(__printf__
int file_is_simh(struct magic_set *ms, const struct buffer *b)
#define MAGIC_MIME_ENCODING
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)