3 * Copyright (C) 2001,2002 A.J. van Os; Released under GPL
6 * RISC OS only functions
12 #include "DeskLib:Error.h"
13 #include "DeskLib:SWI.h"
16 #if !defined(DrawFile_Render)
17 #define DrawFile_Render 0x045540
18 #endif /* !DrawFile_Render */
19 #if !defined(JPEG_Info)
20 #define JPEG_Info 0x049980
21 #endif /* !JPEG_Info */
24 * werr - write an error message and exit if needed
27 werr(int iFatal
, const char *szFormat
, ...)
31 va_start(tArg
, szFormat
);
32 Error_Report(iFatal
, (char *)szFormat
, tArg
);
35 case 0: /* The message is just a warning, so no exit */
37 case 1: /* Fatal error with a standard exit */
39 default: /* Fatal error with a non-standard exit */
46 * This function will get the filetype of the given file.
47 * returns the filetype.
50 iGetFiletype(const char *szFilename
)
55 fail(szFilename
== NULL
|| szFilename
[0] == '\0');
57 e
= SWI(2, 7, SWI_OS_File
| XOS_Bit
,
59 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &iType
);
63 werr(0, "Get Filetype error %d: %s", e
->errnum
, e
->errmess
);
65 } /* end of iGetFiletype */
69 * This procedure will set the filetype of the given file to the given
73 vSetFiletype(const char *szFilename
, int iFiletype
)
77 fail(szFilename
== NULL
|| szFilename
[0] == '\0');
79 if (iFiletype
< 0x000 || iFiletype
> 0xfff) {
82 e
= SWI(3, 0, SWI_OS_File
| XOS_Bit
,
83 18, szFilename
, iFiletype
);
86 case 0x000113: /* ROM */
87 case 0x0104e1: /* Read-only floppy DOSFS */
88 case 0x0108c9: /* Read-only floppy ADFS */
89 case 0x013803: /* Read-only ArcFS */
90 case 0x80344a: /* CD-ROM */
93 werr(0, "Set Filetype error %d: %s",
94 e
->errnum
, e
->errmess
);
98 } /* end of vSetFileType */
101 * Check if the directory part of the given file exists, make the directory
102 * if it does not exist yet.
103 * Returns TRUE in case of success, otherwise FALSE.
106 bMakeDirectory(const char *szFilename
)
111 char szDirectory
[PATH_MAX
+1];
113 DBG_MSG("bMakeDirectory");
114 fail(szFilename
== NULL
|| szFilename
[0] == '\0');
117 if (strlen(szFilename
) >= sizeof(szDirectory
)) {
118 DBG_DEC(strlen(szFilename
));
121 strcpy(szDirectory
, szFilename
);
122 pcLastDot
= strrchr(szDirectory
, '.');
123 if (pcLastDot
== NULL
) {
124 /* No directory equals current directory */
125 DBG_MSG("No directory part given");
129 DBG_MSG(szDirectory
);
130 /* Check if the name exists */
131 e
= SWI(2, 1, SWI_OS_File
| XOS_Bit
,
135 werr(0, "Directory check %d: %s", e
->errnum
, e
->errmess
);
138 if (iObjectType
== 2) {
139 /* The name exists and it is a directory */
140 DBG_MSG("The directory already exists");
143 if (iObjectType
!= 0) {
144 /* The name exists and it is not a directory */
145 DBG_DEC(iObjectType
);
148 /* The name does not exist, make the directory */
149 e
= SWI(5, 0, SWI_OS_File
| XOS_Bit
,
150 8, szDirectory
, 0, 0, 0);
152 werr(0, "I can't make a directory %d: %s",
153 e
->errnum
, e
->errmess
);
157 } /* end of bMakeDirectory */
160 * iReadCurrentAlphabetNumber
161 * This function reads the current Alphabet number.
162 * Returns the current Alphabet number when successful, otherwise -1
165 iReadCurrentAlphabetNumber(void)
170 e
= SWI(2, 2, SWI_OS_Byte
| XOS_Bit
,
172 NULL
, &iAlphabetNumber
);
174 return iAlphabetNumber
;
176 werr(0, "Read alphabet error %d: %s", e
->errnum
, e
->errmess
);
178 } /* end of iReadCurrentAlphabetNumber */
181 * iGetRiscOsVersion - get the RISC OS version number
183 * returns the RISC OS version * 100
186 iGetRiscOsVersion(void)
191 e
= SWI(3, 2, SWI_OS_Byte
| XOS_Bit
,
195 werr(0, "Read RISC OS version error %d: %s",
196 e
->errnum
, e
->errmess
);
200 case 0xa0: /* Arthur 1.20 */
202 case 0xa1: /* RISC OS 2.00 */
204 case 0xa2: /* RISC OS 2.01 */
206 case 0xa3: /* RISC OS 3.00 */
208 case 0xa4: /* RISC OS 3.1x */
210 case 0xa5: /* RISC OS 3.50 */
212 case 0xa6: /* RISC OS 3.60 */
214 case 0xa7: /* RISC OS 3.7x */
216 case 0xa8: /* RISC OS 4.0x */
219 if (iVersion
>= 0xa9 && iVersion
<= 0xaf) {
220 /* RISC OS 4.10 and up */
223 /* Unknown version */
226 } /* end of iGetRiscOsVersion */
230 bGetJpegInfo(UCHAR
*pucJpeg
, size_t tJpegSize
)
233 int iReg0
, iReg4
, iReg5
;
235 e
= SWI(3, 6, JPEG_Info
| XOS_Bit
,
236 0x00, pucJpeg
, tJpegSize
,
237 &iReg0
, NULL
, NULL
, NULL
, &iReg4
, &iReg5
);
239 if (iReg0
& BIT(2)) {
240 DBG_MSG("Pixel density is a simple ratio");
242 DBG_MSG("Pixel density is in dpi");
248 werr(0, "JPEG Info error %d: %s", e
->errnum
, e
->errmess
);
250 } /* end of bGetJpegInfo */