1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/* eptexextra.c: Hand-coded routines for e-pTeX.
This file is public domain. */
#define EXTERN /* Instantiate data from eptexd.h here. */
#define DLLPROC dlleptexmain
/* This file defines TeX and epTeX. */
#include <eptexd.h>
/* Hand-coded routines for TeX or Metafont in C. */
#include <lib/texmfmp.c>
void getfiledump(int s, int offset, int length)
{
FILE *f;
int read, i;
poolpointer data_ptr;
poolpointer data_end;
char *file_name;
if (length == 0) {
/* empty result string */
return;
}
if (poolptr + 2 * length + 1 >= poolsize) {
/* no place for result */
poolptr = poolsize;
/* error by str_toks that calls str_room(1) */
return;
}
file_name = kpse_find_tex(makecfilename(s));
if (file_name == NULL) {
return; /* empty string */
}
/* read file data */
f = fopen(file_name, FOPEN_RBIN_MODE);
if (f == NULL) {
free(file_name);
return;
}
recorder_record_input(file_name);
if (fseek(f, offset, SEEK_SET) != 0) {
free(file_name);
return;
}
/* there is enough space in the string pool, the read
data are put in the upper half of the result, thus
the conversion to hex can be done without overwriting
unconverted bytes. */
data_ptr = poolptr + length;
read = fread(&strpool[data_ptr], sizeof(char), length, f);
fclose(f);
/* convert to hex */
data_end = data_ptr + read;
for (; data_ptr < data_end; data_ptr++) {
i = snprintf((char *) &strpool[poolptr], 3,
"%.2X", (unsigned int) strpool[data_ptr]);
check_nprintf(i, 3);
poolptr += i;
}
free(file_name);
}
|