File: misc.c

package info (click to toggle)
emile 0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,716 kB
  • ctags: 2,737
  • sloc: ansic: 18,908; makefile: 726; asm: 622; sh: 2
file content (72 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download
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
/*
 *
 * (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
 *
 */

#include <string.h>
#include <unistd.h>
#include <stdio.h>

#include "misc.h"
#include "console.h"

unsigned char *c2pstring(char* s)
{
	int len = strlen(s);
	int i;

	for (i = len; i > 0; i--)
		s[i] = s[i - 1];
	s[0] = len;

	return (unsigned char*)s;
}

static char buffer[256];
unsigned char *p2cstring(unsigned char* s)
{

	memcpy(buffer, s + 1, s[0]);
	buffer[(int)s[0]] = (char)0;

	return buffer;
}

void error(char *x)
{
        console_putstring("\n\n");
        console_putstring(x);
        console_putstring("\n\n -- System halted\n");

        while(1);       /* Halt */
}

void memdump(unsigned char* addr, unsigned long size)
{
	int i = 0;
	int j;

	while ( i < size)
	{
		printf("%08lx  ", (unsigned long)addr + i);

		for (j = 0; (j < 8) && (i + j < size); j++)
			printf("%02x ", addr[i+j]);
		printf(" ");
		for (j = 8; (j < 16) && (i + j < size); j++)
			printf("%02x ", addr[i+j]);

		printf(" |");
		for (j = 0; (j < 16) && (i + j < size); j++)
		{
			if ( (addr[i+j] > 31) && (addr[i+j] < 128) )
				printf("%c", addr[i+j]);
			else
				printf(".");
		}
		printf("|\n");

		i += j;
	}
}