Imported from antiword-0.37.tar.gz.
[antiword.git] / DOS-only / dos.c
blob2dfd3ff0fdb7501411ac41a85f667b6be9694e28
1 /*
2 * dos.c
3 * Copyright (C) 2004 A.J. van Os; Released under GNU GPL
5 * Description:
6 * DOS only functions
7 */
9 #if defined(__DJGPP__)
10 #define _NAIVE_DOS_REGS 1
11 #endif /* __DJGPP__ */
12 #include <dos.h>
13 #include <string.h>
14 #include "antiword.h"
18 * iGetVersion - get the version of DOS
20 * Return the DOS version * 100 or -1 incase of error
22 static int
23 iGetVersion(void)
25 union REGS uRegs;
27 memset(&uRegs, 0, sizeof(uRegs));
28 uRegs.h.ah = 0x30;
29 uRegs.h.al = 0x00;
30 _doserrno = 0;
31 intdos(&uRegs, &uRegs);
32 if (uRegs.x.cflag != 0) {
33 DBG_DEC(uRegs.x.cflag);
34 DBG_DEC(_doserrno);
35 return -1;
37 DBG_DEC(uRegs.h.al);
38 DBG_DEC(uRegs.h.ah);
39 return uRegs.h.al * 100 + uRegs.h.ah;
40 } /* end of iGetVersion */
43 * iGetCodepage - get the DOS codepage
45 * Returns the number of the active codepage (cp437 is DOS ASCII)
47 int
48 iGetCodepage(void)
50 union REGS uRegs;
52 /* DOS function 0x66 first appeared in DOS 3.3 */
53 if (iGetVersion() < 330) {
54 return 437;
56 memset(&uRegs, 0, sizeof(uRegs));
57 uRegs.h.ah = 0x66;
58 uRegs.h.al = 0x01;
59 _doserrno = 0;
60 intdos(&uRegs, &uRegs);
61 if (uRegs.x.cflag != 0) {
62 DBG_DEC(uRegs.x.cflag);
63 DBG_DEC(_doserrno);
64 return 437;
66 DBG_DEC(uRegs.x.bx);
67 DBG_DEC(uRegs.x.dx);
68 return uRegs.x.bx;
69 } /* end of iGetCodepage */