ze-filter  (ze-filter-0.8.0-develop-180218)
dumper.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string.h>
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include <malloc.h>
6 #include <unistd.h>
7 
8 void
9 dump_buf(ptr, l, ni)
10  unsigned char *ptr;
11  int l;
12  long ni;
13 {
14  int n;
15  unsigned char s[81];
16  unsigned char t[81];
17 
18  *s = '\0';
19  for (n = 0; n < l; n++) {
20  if ((n % 16) != 0) {
21  if (((n % 2) == 0) && (n != 0))
22  strcat((char *) s, " ");
23  if (((n % 8) == 0) && (n != 0))
24  strcat((char *) s, " ");
25  } else {
26  *t = '\0';
27  memset(t, 0, sizeof (t));
28  sprintf((char *) s, "%.6X : ", n + ni);
29  }
30  sprintf((char *) s, "%s%.2X", s, *(ptr + n));
31  if ((*(ptr + n) >= 0x20) && (*(ptr + n) <= 0x7F))
32  t[n % 16] = *(ptr + n);
33  else
34  t[n % 16] = '.';
35 
36  if ((((n + 1) % 16) == 0) && (n != 0)) {
37  t[16] = '\0';
38  printf("%-49s - %s\n", s, t);
39  }
40  }
41  if (((n % 16) != 0) && (n != 0)) {
42  printf("%-49s - %s\n", s, t);
43  }
44 }
45 
46 #define buf_size 0x1000
47 
48 int
49 main(argc, argv)
50  int argc;
51  char **argv;
52 {
53  int fin;
54  char *buf;
55  int len;
56  long ni = 0;
57 
58  if ((buf = (char *) malloc(buf_size)) == NULL) {
59  printf("Erreur pendant allocation de buffer\n");
60  return 1;
61  }
62 
63  while (--argc > 0) {
64 #if 0
65  printf("i = %3d, %s\n", argc, argv[argc]);
66 #endif
67  fin = open(argv[argc], O_RDONLY);
68  if (fin != -1) {
69  while ((len = read(fin, buf, buf_size)) > 0) {
70  dump_buf(buf, len, ni);
71  ni += len;
72  }
73  close(fin);
74  } else
75  printf(" erreur pendant ouverture de fichier\n");
76  }
77  free(buf);
78 
79  return 0;
80 }
void dump_buf(unsigned char *ptr, int l, long ni)
Definition: dumper.c:9
int main(int argc, char **argv)
Definition: dumper.c:49
#define buf_size
Definition: dumper.c:46