67 lines
1.1 KiB
C
67 lines
1.1 KiB
C
#include "ft_nm.h"
|
|
|
|
char ft_get_hex_digit(char c) {
|
|
if (c > 9) {
|
|
return c + 'W';
|
|
} else {
|
|
return c + '0';
|
|
}
|
|
}
|
|
|
|
void ft_print_hex_digit(char c) {
|
|
if (c > 9) {
|
|
ft_putchar(c + 'W');
|
|
} else {
|
|
ft_putchar(c + '0');
|
|
}
|
|
}
|
|
|
|
void ft_put_address_32(uint32_t addr) {
|
|
for (char i = 7; i >= 0; i--) {
|
|
ft_print_hex_digit((addr >> i * 4) & 0xF);
|
|
}
|
|
}
|
|
|
|
void ft_put_address_64(uint64_t addr) {
|
|
for (char i = 15; i >= 0; i--) {
|
|
ft_print_hex_digit((addr >> i * 4) & 0xF);
|
|
}
|
|
}
|
|
|
|
void ft_printf(const char *format, ...) {
|
|
va_list ap;
|
|
int argc = ft_strlen(format);
|
|
|
|
va_start(ap, format);
|
|
for (int i = 0; i < argc; i++) {
|
|
switch (format[i]) {
|
|
case 's':
|
|
ft_putstr(va_arg(ap, char *));
|
|
break;
|
|
case 'd':
|
|
ft_putnbr(va_arg(ap, int));
|
|
break;
|
|
case 'x':
|
|
ft_put_address_32(va_arg(ap, uint32_t));
|
|
break;
|
|
case 'X':
|
|
ft_put_address_64(va_arg(ap, uint64_t));
|
|
break;
|
|
case ' ':
|
|
ft_putchar(' ');
|
|
break;
|
|
case 'p':
|
|
ft_putstr(" ");
|
|
break;
|
|
case 'P':
|
|
ft_putstr(" ");
|
|
break;
|
|
default:
|
|
ft_putchar(format[i]);
|
|
break;
|
|
}
|
|
}
|
|
va_end(ap);
|
|
}
|
|
|