Updated typelib loader. Typelib contents can be stored as multibyte
[wine] / dlls / setupapi / infparse.c
1 /*
2  * SetupX .inf file parsing functions
3  *
4  * FIXME: return values ???
5  */
6
7 #include "debugtools.h"
8 #include "windef.h"
9 #include "winbase.h"
10 #include "wine/winbase16.h"
11 #include "setupx16.h"
12
13 DEFAULT_DEBUG_CHANNEL(setupx);
14
15 WORD InfNumEntries = 0;
16 INF_HANDLE *InfList = NULL;
17
18 #define GET_INF_ENTRY(x) ((InfList - x)/4)
19
20 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
21 {
22     HFILE16 hFile = _lopen16(lpInfFileName, OF_READ);
23
24     if (!lphInf)
25         return IP_ERROR;
26
27     if (hFile != HFILE_ERROR16)
28     {
29         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
30         InfList[InfNumEntries].hInfFile = hFile;
31         InfList[InfNumEntries].lpInfFileName = lpInfFileName;
32         InfNumEntries++;
33         *lphInf = &InfList[InfNumEntries-1] - InfList;
34         return OK;
35     }
36     *lphInf = 0xffff;
37     return ERR_IP_INVALID_INFFILE;
38 }
39
40 LPCSTR IP_GetFileName(HINF16 hInf)
41 {
42     if ((hInf <= (InfNumEntries*sizeof(INF_HANDLE *)))
43     && ((hInf & 3) == 0)) /* aligned ? */
44     {
45         return InfList[hInf/4].lpInfFileName;
46     }
47     return NULL;
48 }
49
50 RETERR16 IP_CloseInf(HINF16 hInf)
51 {
52     int i;
53     HFILE16 res = ERR_IP_INVALID_HINF;
54
55     if ((hInf <= (InfNumEntries*sizeof(INF_HANDLE *)))
56     && ((hInf & 3) == 0)) /* aligned ? */
57     {
58         _lclose16(InfList[hInf/4].hInfFile);
59         res = OK;
60         for (i=hInf/4; i < InfNumEntries-1; i++)
61             InfList[i] = InfList[i+1];
62         InfNumEntries--;
63         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
64     }
65     return res;
66 }
67
68 /***********************************************************************
69  *              IpOpen16
70  *
71  */
72 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
73 {
74     TRACE("('%s', %p)\n", lpInfFileName, lphInf);
75     return IP_OpenInf(lpInfFileName, lphInf);
76 }
77
78 /***********************************************************************
79  *              IpClose16
80  */
81 RETERR16 WINAPI IpClose16(HINF16 hInf)
82 {
83     return IP_CloseInf(hInf);
84 }
85
86 /***********************************************************************
87  *              IpGetProfileString16
88  */
89 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen) 
90 {
91     GetPrivateProfileString16(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
92     return 0;
93 }