-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_showmem.c
83 lines (72 loc) · 1.4 KB
/
my_showmem.c
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
** my_showmem.c for in /u/epitech_2012/brenne_t/cu/rendu/piscine/1
**
** Made by thomas brennetot
** Login <[email protected]>
**
** Started on Fri Oct 12 16:09:36 2007 thomas brennetot
** Last update Mon Oct 15 20:13:55 2007 thomas brennetot
*/
#include "my.h"
void my_put_nbr_base_pad(unsigned int nbr, char *base,int pad)
{
int base_len;
base_len = my_strlen(base);
if (pad > 0)
{
my_put_nbr_base_pad(nbr / base_len,base,pad - 1);
my_putchar(base[nbr % base_len]);
}
}
void print_addr(char *str)
{
my_put_nbr_base_pad((unsigned int)str,"0123456789abcdef", 8);
my_putchar(':');
}
void print_hexa(char *str,int size)
{
int i;
i = 0;
while (i < 16)
{
if ((i % 2) == 0)
my_putchar(' ');
if (i < size)
my_put_nbr_base_pad(str[i], "0123456789abcdef", 2);
else
my_putstr(" ");
i++;
}
}
void print_ascii(char *str,int size)
{
int i;
my_putstr(" ");
i = 0;
while ((1 < 16) && (i < size))
{
if ((str[i] >= 32) && (str[i] < 127))
my_putchar(str[i]);
else
my_putchar('.');
i++;
}
}
void my_showmem16(char *str,int size)
{
print_addr(str);
print_hexa(str, size);
print_ascii(str, size);
my_putchar('\n');
}
int my_showmem(char *str,int size)
{
int i;
i = 0;
while (i < size)
{
my_showmem16(&str[i], size - i);
i = i + 16;
}
return (0);
}