7374405b7fbe172c8384494d9f88615707e8dfab
[mate.git] / ffi / native.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 static char ascii(char s) {
6         if(s < 0x20) return '.';
7         if(s > 0x7E) return '.';
8         return s;
9 }
10
11 void hexdump(void *d, int len) {
12         unsigned char *data;
13         int i, off;
14         data = (unsigned char*)d;
15         for (off=0; off<len; off += 16) {
16                 printf("%08x  ",off);
17                 for(i=0; i<16; i++)
18                         if((i+off)>=len) printf("   ");
19                         else printf("%02x ",data[off+i]);
20
21                 printf(" ");
22                 for(i=0; i<16; i++)
23                         if((i+off)>=len) printf(" ");
24                         else printf("%c",ascii(data[off+i]));
25                 printf("\n");
26         }
27 }
28
29 void tests_Native1__printSomething____V(void)
30 {
31         printf("printSomething: woot \\o/\n");
32 }
33
34 void tests_Native1__printSomething___I_V(int a)
35 {
36         printf("printSomething: 0x%08x\n", a);
37 }
38
39 void tests_Instance5__printX___I_V(int a)
40 {
41         printf("printX: 0x%08x\n", a);
42 }
43
44 void java_io_PrintStream__printf___I_V(int a)
45 {
46         printf("printstream: 0x%08x\n", a);
47 }
48
49 struct integer {
50         unsigned int method_table_ptr;
51         int value;
52 };
53
54 struct string {
55         unsigned int method_table_ptr;
56         struct chararray *value;
57 };
58
59 struct chararray {
60         unsigned int length;
61         char str;
62 };
63
64 void jmate_io_PrintStream__printf_0___Ljava_lang_String__V
65         (struct string *fmt)
66 {
67         printf("%s", &fmt->value->str);
68 }
69
70 void jmate_io_PrintStream__printf_1___Ljava_lang_String_Ljava_lang_Object__V
71         (struct integer *a1, struct string *fmt)
72 {
73 #if 0
74         printf("fmt:        0x%08x\n", (unsigned int) fmt);
75         printf("fmt->value: 0x%08x\n", (unsigned int) fmt->value);
76         printf("fmt->val.len: 0x%08x\n", (unsigned int) (*fmt->value).length);
77         printf("first: %d\n", fmt->value->length);
78         printf("*fmt: %s\n", &fmt->value->str);
79 #endif
80         printf(&fmt->value->str, a1->value);
81 }
82
83 void jmate_io_PrintStream__printf_2___Ljava_lang_String_Ljava_lang_Object_Ljava_lang_Object__V
84         (struct integer *a2, struct integer *a1, struct string *fmt)
85 {
86         printf(&fmt->value->str, a1->value, a2->value);
87 }
88
89 void
90 jmate_io_PrintStream__printf_3___Ljava_lang_String_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object__V
91         (struct integer *a3, struct integer *a2, struct integer *a1, struct string *fmt)
92 {
93         printf(&fmt->value->str, a1->value, a2->value, a3->value);
94 }
95
96 void jmate_io_PrintStream__printf_4___Ljava_lang_String_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object__V
97         (struct integer *a4, struct integer *a3, struct integer *a2, struct integer *a1, struct string *fmt)
98 {
99         printf(&fmt->value->str, a1->value, a2->value, a3->value, a4->value);
100 }
101
102 void jmate_io_PrintStream__printf_5___Ljava_lang_String_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object__V
103         (struct integer *a5, struct integer *a4, struct integer *a3, struct integer *a2, struct integer *a1, struct string *fmt)
104 {
105         printf(&fmt->value->str, a1->value, a2->value, a3->value, a4->value, a5->value);
106 }
107
108 void gnu_classpath_VMSystemProperties__preInit___Ljava_util_Properties__V() {
109         return;
110 }
111
112 void java_lang_VMSystem__arraycopy___Ljava_lang_Object_ILjava_lang_Object_II_V(
113                 int len, int dest_start, struct chararray *dest,
114                 int src_start, struct chararray *src)
115 #if 0
116                 /* original */
117                 struct chararray *src, int src_start,
118                 struct chararray *dest, int dest_start, int len)
119 #endif
120 {
121         memcpy(&dest->str, &src->str + src_start, len);
122         dest->length = len;
123 #if 0
124         hexdump(src, len + 4);
125         hexdump(dest, len + 4);
126 #endif
127 }