Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/cmd/aux/antiword/riscos.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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