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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
/*
* riscos.c
* Copyright (C) 2001,2002 A.J. van Os; Released under GPL
*
* Description:
* RISC OS only functions
*/
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "DeskLib:Error.h"
#include "DeskLib:SWI.h"
#include "antiword.h"
#if !defined(DrawFile_Render)
#define DrawFile_Render 0x045540
#endif /* !DrawFile_Render */
#if !defined(JPEG_Info)
#define JPEG_Info 0x049980
#endif /* !JPEG_Info */
/*
* werr - write an error message and exit if needed
*/
void
werr(int iFatal, const char *szFormat, ...)
{
va_list tArg;
va_start(tArg, szFormat);
Error_Report(iFatal, (char *)szFormat, tArg);
va_end(tArg);
switch (iFatal) {
case 0: /* The message is just a warning, so no exit */
return;
case 1: /* Fatal error with a standard exit */
exit(EXIT_FAILURE);
default: /* Fatal error with a non-standard exit */
exit(iFatal);
}
} /* end of werr */
/*
* iGetFiletype
* This function will get the filetype of the given file.
* returns the filetype.
*/
int
iGetFiletype(const char *szFilename)
{
os_error *e;
int iType;
fail(szFilename == NULL || szFilename[0] == '\0');
e = SWI(2, 7, SWI_OS_File | XOS_Bit,
23, szFilename,
NULL, NULL, NULL, NULL, NULL, NULL, &iType);
if (e == NULL) {
return iType;
}
werr(0, "Get Filetype error %d: %s", e->errnum, e->errmess);
return -1;
} /* end of iGetFiletype */
/*
* vSetFiletype
* This procedure will set the filetype of the given file to the given
* type.
*/
void
vSetFiletype(const char *szFilename, int iFiletype)
{
os_error *e;
fail(szFilename == NULL || szFilename[0] == '\0');
if (iFiletype < 0x000 || iFiletype > 0xfff) {
return;
}
e = SWI(3, 0, SWI_OS_File | XOS_Bit,
18, szFilename, iFiletype);
if (e != NULL) {
switch (e->errnum) {
case 0x000113: /* ROM */
case 0x0104e1: /* Read-only floppy DOSFS */
case 0x0108c9: /* Read-only floppy ADFS */
case 0x013803: /* Read-only ArcFS */
case 0x80344a: /* CD-ROM */
break;
default:
werr(0, "Set Filetype error %d: %s",
e->errnum, e->errmess);
break;
}
}
} /* end of vSetFileType */
/*
* Check if the directory part of the given file exists, make the directory
* if it does not exist yet.
* Returns TRUE in case of success, otherwise FALSE.
*/
BOOL
bMakeDirectory(const char *szFilename)
{
os_error *e;
char *pcLastDot;
int iObjectType;
char szDirectory[PATH_MAX+1];
DBG_MSG("bMakeDirectory");
fail(szFilename == NULL || szFilename[0] == '\0');
DBG_MSG(szFilename);
if (strlen(szFilename) >= sizeof(szDirectory)) {
DBG_DEC(strlen(szFilename));
return FALSE;
}
strcpy(szDirectory, szFilename);
pcLastDot = strrchr(szDirectory, '.');
if (pcLastDot == NULL) {
/* No directory equals current directory */
DBG_MSG("No directory part given");
return TRUE;
}
*pcLastDot = '\0';
DBG_MSG(szDirectory);
/* Check if the name exists */
e = SWI(2, 1, SWI_OS_File | XOS_Bit,
17, szDirectory,
&iObjectType);
if (e != NULL) {
werr(0, "Directory check %d: %s", e->errnum, e->errmess);
return FALSE;
}
if (iObjectType == 2) {
/* The name exists and it is a directory */
DBG_MSG("The directory already exists");
return TRUE;
}
if (iObjectType != 0) {
/* The name exists and it is not a directory */
DBG_DEC(iObjectType);
return FALSE;
}
/* The name does not exist, make the directory */
e = SWI(5, 0, SWI_OS_File | XOS_Bit,
8, szDirectory, 0, 0, 0);
if (e != NULL) {
werr(0, "I can't make a directory %d: %s",
e->errnum, e->errmess);
return FALSE;
}
return TRUE;
} /* end of bMakeDirectory */
/*
* iReadCurrentAlphabetNumber
* This function reads the current Alphabet number.
* Returns the current Alphabet number when successful, otherwise -1
*/
int
iReadCurrentAlphabetNumber(void)
{
os_error *e;
int iAlphabetNumber;
e = SWI(2, 2, SWI_OS_Byte | XOS_Bit,
71, 127,
NULL, &iAlphabetNumber);
if (e == NULL) {
return iAlphabetNumber;
}
werr(0, "Read alphabet error %d: %s", e->errnum, e->errmess);
return -1;
} /* end of iReadCurrentAlphabetNumber */
/*
* iGetRiscOsVersion - get the RISC OS version number
*
* returns the RISC OS version * 100
*/
int
iGetRiscOsVersion(void)
{
os_error *e;
int iVersion;
e = SWI(3, 2, SWI_OS_Byte | XOS_Bit,
129, 0, 0xff,
NULL, &iVersion);
if (e != NULL) {
werr(0, "Read RISC OS version error %d: %s",
e->errnum, e->errmess);
return 0;
}
switch (iVersion) {
case 0xa0: /* Arthur 1.20 */
return 120;
case 0xa1: /* RISC OS 2.00 */
return 200;
case 0xa2: /* RISC OS 2.01 */
return 201;
case 0xa3: /* RISC OS 3.00 */
return 300;
case 0xa4: /* RISC OS 3.1x */
return 310;
case 0xa5: /* RISC OS 3.50 */
return 350;
case 0xa6: /* RISC OS 3.60 */
return 360;
case 0xa7: /* RISC OS 3.7x */
return 370;
case 0xa8: /* RISC OS 4.0x */
return 400;
default:
if (iVersion >= 0xa9 && iVersion <= 0xaf) {
/* RISC OS 4.10 and up */
return 410;
}
/* Unknown version */
return 0;
}
} /* end of iGetRiscOsVersion */
#if defined(DEBUG)
BOOL
bGetJpegInfo(UCHAR *pucJpeg, size_t tJpegSize)
{
os_error *e;
int iReg0, iReg4, iReg5;
e = SWI(3, 6, JPEG_Info | XOS_Bit,
0x00, pucJpeg, tJpegSize,
&iReg0, NULL, NULL, NULL, &iReg4, &iReg5);
if (e == NULL) {
if (iReg0 & BIT(2)) {
DBG_MSG("Pixel density is a simple ratio");
} else {
DBG_MSG("Pixel density is in dpi");
}
DBG_DEC(iReg4);
DBG_DEC(iReg5);
return TRUE;
}
werr(0, "JPEG Info error %d: %s", e->errnum, e->errmess);
return FALSE;
} /* end of bGetJpegInfo */
#endif /* DEBUG */
|