00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <string.h>
00010 #include <stdlib.h>
00011 #include <stdarg.h>
00012 #include "DeskLib:Error.h"
00013 #include "DeskLib:SWI.h"
00014 #include "antiword.h"
00015
00016 #if !defined(DrawFile_Render)
00017 #define DrawFile_Render 0x045540
00018 #endif
00019 #if !defined(JPEG_Info)
00020 #define JPEG_Info 0x049980
00021 #endif
00022
00023
00024
00025
00026 void
00027 werr(int iFatal, const char *szFormat, ...)
00028 {
00029 va_list tArg;
00030
00031 va_start(tArg, szFormat);
00032 Error_Report(iFatal, (char *)szFormat, tArg);
00033 va_end(tArg);
00034 switch (iFatal) {
00035 case 0:
00036 return;
00037 case 1:
00038 exit(EXIT_FAILURE);
00039 default:
00040 exit(iFatal);
00041 }
00042 }
00043
00044
00045
00046
00047
00048
00049 int
00050 iGetFiletype(const char *szFilename)
00051 {
00052 os_error *e;
00053 int iType;
00054
00055 fail(szFilename == NULL || szFilename[0] == '\0');
00056
00057 e = SWI(2, 7, SWI_OS_File | XOS_Bit,
00058 23, szFilename,
00059 NULL, NULL, NULL, NULL, NULL, NULL, &iType);
00060 if (e == NULL) {
00061 return iType;
00062 }
00063 werr(0, "Get Filetype error %d: %s", e->errnum, e->errmess);
00064 return -1;
00065 }
00066
00067
00068
00069
00070
00071
00072 void
00073 vSetFiletype(const char *szFilename, int iFiletype)
00074 {
00075 os_error *e;
00076
00077 fail(szFilename == NULL || szFilename[0] == '\0');
00078
00079 if (iFiletype < 0x000 || iFiletype > 0xfff) {
00080 return;
00081 }
00082 e = SWI(3, 0, SWI_OS_File | XOS_Bit,
00083 18, szFilename, iFiletype);
00084 if (e != NULL) {
00085 switch (e->errnum) {
00086 case 0x000113:
00087 case 0x0104e1:
00088 case 0x0108c9:
00089 case 0x013803:
00090 case 0x80344a:
00091 break;
00092 default:
00093 werr(0, "Set Filetype error %d: %s",
00094 e->errnum, e->errmess);
00095 break;
00096 }
00097 }
00098 }
00099
00100
00101
00102
00103
00104
00105 BOOL
00106 bMakeDirectory(const char *szFilename)
00107 {
00108 os_error *e;
00109 char *pcLastDot;
00110 int iObjectType;
00111 char szDirectory[PATH_MAX+1];
00112
00113 DBG_MSG("bMakeDirectory");
00114 fail(szFilename == NULL || szFilename[0] == '\0');
00115 DBG_MSG(szFilename);
00116
00117 if (strlen(szFilename) >= sizeof(szDirectory)) {
00118 DBG_DEC(strlen(szFilename));
00119 return FALSE;
00120 }
00121 strcpy(szDirectory, szFilename);
00122 pcLastDot = strrchr(szDirectory, '.');
00123 if (pcLastDot == NULL) {
00124
00125 DBG_MSG("No directory part given");
00126 return TRUE;
00127 }
00128 *pcLastDot = '\0';
00129 DBG_MSG(szDirectory);
00130
00131 e = SWI(2, 1, SWI_OS_File | XOS_Bit,
00132 17, szDirectory,
00133 &iObjectType);
00134 if (e != NULL) {
00135 werr(0, "Directory check %d: %s", e->errnum, e->errmess);
00136 return FALSE;
00137 }
00138 if (iObjectType == 2) {
00139
00140 DBG_MSG("The directory already exists");
00141 return TRUE;
00142 }
00143 if (iObjectType != 0) {
00144
00145 DBG_DEC(iObjectType);
00146 return FALSE;
00147 }
00148
00149 e = SWI(5, 0, SWI_OS_File | XOS_Bit,
00150 8, szDirectory, 0, 0, 0);
00151 if (e != NULL) {
00152 werr(0, "I can't make a directory %d: %s",
00153 e->errnum, e->errmess);
00154 return FALSE;
00155 }
00156 return TRUE;
00157 }
00158
00159
00160
00161
00162
00163
00164 int
00165 iReadCurrentAlphabetNumber(void)
00166 {
00167 os_error *e;
00168 int iAlphabetNumber;
00169
00170 e = SWI(2, 2, SWI_OS_Byte | XOS_Bit,
00171 71, 127,
00172 NULL, &iAlphabetNumber);
00173 if (e == NULL) {
00174 return iAlphabetNumber;
00175 }
00176 werr(0, "Read alphabet error %d: %s", e->errnum, e->errmess);
00177 return -1;
00178 }
00179
00180
00181
00182
00183
00184
00185 int
00186 iGetRiscOsVersion(void)
00187 {
00188 os_error *e;
00189 int iVersion;
00190
00191 e = SWI(3, 2, SWI_OS_Byte | XOS_Bit,
00192 129, 0, 0xff,
00193 NULL, &iVersion);
00194 if (e != NULL) {
00195 werr(0, "Read RISC OS version error %d: %s",
00196 e->errnum, e->errmess);
00197 return 0;
00198 }
00199 switch (iVersion) {
00200 case 0xa0:
00201 return 120;
00202 case 0xa1:
00203 return 200;
00204 case 0xa2:
00205 return 201;
00206 case 0xa3:
00207 return 300;
00208 case 0xa4:
00209 return 310;
00210 case 0xa5:
00211 return 350;
00212 case 0xa6:
00213 return 360;
00214 case 0xa7:
00215 return 370;
00216 case 0xa8:
00217 return 400;
00218 default:
00219 if (iVersion >= 0xa9 && iVersion <= 0xaf) {
00220
00221 return 410;
00222 }
00223
00224 return 0;
00225 }
00226 }
00227
00228 #if defined(DEBUG)
00229 BOOL
00230 bGetJpegInfo(UCHAR *pucJpeg, size_t tJpegSize)
00231 {
00232 os_error *e;
00233 int iReg0, iReg4, iReg5;
00234
00235 e = SWI(3, 6, JPEG_Info | XOS_Bit,
00236 0x00, pucJpeg, tJpegSize,
00237 &iReg0, NULL, NULL, NULL, &iReg4, &iReg5);
00238 if (e == NULL) {
00239 if (iReg0 & BIT(2)) {
00240 DBG_MSG("Pixel density is a simple ratio");
00241 } else {
00242 DBG_MSG("Pixel density is in dpi");
00243 }
00244 DBG_DEC(iReg4);
00245 DBG_DEC(iReg5);
00246 return TRUE;
00247 }
00248 werr(0, "JPEG Info error %d: %s", e->errnum, e->errmess);
00249 return FALSE;
00250 }
00251 #endif