| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#ifndef platform_C |
| 7 |
#define platform_C |
| 8 |
|
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
#include <string.h> |
| 12 |
#include <kernel.h> |
| 13 |
#include "input.h" |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#define OS_FILE 0x00008 |
| 20 |
#define XDDEUTILS_THROWBACKSTART 0x62587 |
| 21 |
#define XDDEUTILS_THROWBACKSEND 0x62588 |
| 22 |
#define XDDEUTILS_THROWBACKEND 0x62589 |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
bits RISCOS_flags = 0; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
void RISCOS_exit(void) |
| 31 |
{ |
| 32 |
_kernel_swi_regs regs; |
| 33 |
|
| 34 |
if (RISCOS_flags & RISCOSFLAG_THROWN) { |
| 35 |
_kernel_swi(XDDEUTILS_THROWBACKEND, ®s, ®s); |
| 36 |
RISCOS_flags &= ~RISCOSFLAG_THROWN; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
void RISCOS_entry(void) |
| 43 |
{ |
| 44 |
atexit(RISCOS_exit); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
void platform_convert_path(boolean *is_absolute, char *readptr) |
| 58 |
{ |
| 59 |
char *writeptr, |
| 60 |
previous; |
| 61 |
size_t bytes; |
| 62 |
|
| 63 |
|
| 64 |
*is_absolute = FALSE; |
| 65 |
|
| 66 |
if (*readptr == '/') { |
| 67 |
|
| 68 |
|
| 69 |
*is_absolute = TRUE; |
| 70 |
bytes = strlen(readptr) + 1; |
| 71 |
memmove(readptr + 1, readptr, bytes); |
| 72 |
*(readptr++) = '$'; |
| 73 |
} |
| 74 |
|
| 75 |
writeptr = readptr; |
| 76 |
previous = '/'; |
| 77 |
|
| 78 |
while (*readptr) { |
| 79 |
if ((previous == '/') |
| 80 |
&& (*readptr == '.') |
| 81 |
&& (readptr[1] == '.') |
| 82 |
&& (readptr[2] == '/')) { |
| 83 |
readptr += 2; |
| 84 |
*(writeptr++) = '^'; |
| 85 |
} |
| 86 |
previous = *readptr; |
| 87 |
if ((*readptr == ':') |
| 88 |
|| (*readptr == '$') |
| 89 |
|| (*readptr == '&') |
| 90 |
|| (*readptr == '%')) { |
| 91 |
*is_absolute = TRUE; |
| 92 |
} |
| 93 |
|
| 94 |
if (*readptr == '.') { |
| 95 |
*writeptr = '/'; |
| 96 |
} else if (*readptr == '/') { |
| 97 |
*writeptr = '.'; |
| 98 |
} else if (*readptr == '?') { |
| 99 |
*writeptr = '#'; |
| 100 |
} else if (*readptr == '#') { |
| 101 |
*writeptr = '?'; |
| 102 |
} else { |
| 103 |
*writeptr = *readptr; |
| 104 |
} |
| 105 |
++readptr; |
| 106 |
++writeptr; |
| 107 |
} |
| 108 |
*writeptr = *readptr; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
void RISCOS_set_filetype(const char *filename, int file_type) |
| 114 |
{ |
| 115 |
_kernel_swi_regs regs; |
| 116 |
|
| 117 |
regs.r[0] = 18; |
| 118 |
regs.r[1] = (int) filename; |
| 119 |
regs.r[2] = file_type; |
| 120 |
_kernel_swi(OS_FILE, ®s, ®s); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
void RISCOS_throwback(const char *message, int type) |
| 126 |
{ |
| 127 |
struct location location; |
| 128 |
_kernel_swi_regs regs; |
| 129 |
|
| 130 |
|
| 131 |
if ((RISCOS_flags & RISCOSFLAG_THROWBACK) == 0) |
| 132 |
return; |
| 133 |
|
| 134 |
input_get_location(&location); |
| 135 |
|
| 136 |
|
| 137 |
if ((RISCOS_flags & RISCOSFLAG_THROWN) == 0) { |
| 138 |
RISCOS_flags |= RISCOSFLAG_THROWN; |
| 139 |
_kernel_swi(XDDEUTILS_THROWBACKSTART, ®s, ®s); |
| 140 |
regs.r[0] = 0; |
| 141 |
regs.r[1] = 0; |
| 142 |
|
| 143 |
regs.r[2] = (int) location.plat_filename; |
| 144 |
_kernel_swi(XDDEUTILS_THROWBACKSEND, ®s, ®s); |
| 145 |
} |
| 146 |
|
| 147 |
regs.r[0] = 1; |
| 148 |
regs.r[1] = 0; |
| 149 |
regs.r[2] = (int) location.plat_filename; |
| 150 |
regs.r[3] = location.line_number; |
| 151 |
regs.r[4] = type; |
| 152 |
regs.r[5] = (int) message; |
| 153 |
_kernel_swi(XDDEUTILS_THROWBACKSEND, ®s, ®s); |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
#endif |