riscos.c 5.4 KB

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