- reorganized DInput DLL
[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 "heap.h"
11 #include "wine/winbase16.h"
12 #include "setupx16.h"
13
14 DEFAULT_DEBUG_CHANNEL(setupx);
15
16 WORD InfNumEntries = 0;
17 INF_FILE *InfList = NULL;
18 HINF16 IP_curr_handle = 0;
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     /* this could be improved by checking for already freed handles */
28     if (IP_curr_handle == 0xffff) 
29         return ERR_IP_OUT_OF_HANDLES; 
30
31     if (hFile != HFILE_ERROR16)
32     {
33         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
34         InfList[InfNumEntries].hInf = IP_curr_handle++;
35         InfList[InfNumEntries].hInfFile = hFile;
36         InfList[InfNumEntries].lpInfFileName = HEAP_strdupA(GetProcessHeap(), 0, lpInfFileName);
37         *lphInf = InfList[InfNumEntries].hInf;
38         InfNumEntries++;
39         TRACE("ret handle %d.\n", *lphInf);
40         return OK;
41     }
42     *lphInf = 0xffff;
43     return ERR_IP_INVALID_INFFILE;
44 }
45
46 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
47 {
48     WORD n;
49
50     for (n=0; n < InfNumEntries; n++)
51         if (InfList[n].hInf == hInf)
52         {
53             *ret = n;
54             return TRUE;
55         }
56     return FALSE;
57 }
58         
59
60 LPCSTR IP_GetFileName(HINF16 hInf)
61 {
62     WORD n;
63     if (IP_FindInf(hInf, &n))
64     {
65         return InfList[n].lpInfFileName;
66     }
67     return NULL;
68 }
69
70 RETERR16 IP_CloseInf(HINF16 hInf)
71 {
72     int i;
73     WORD n;
74     HFILE16 res = ERR_IP_INVALID_HINF;
75
76     if (IP_FindInf(hInf, &n))
77     {
78         _lclose16(InfList[n].hInfFile);
79         HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName);
80         for (i=n; i < InfNumEntries-1; i++)
81             InfList[i] = InfList[i+1];
82         InfNumEntries--;
83         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
84         res = OK;
85     }
86     return res;
87 }
88
89 /***********************************************************************
90  *              IpOpen16
91  *
92  */
93 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
94 {
95     TRACE("('%s', %p)\n", lpInfFileName, lphInf);
96     return IP_OpenInf(lpInfFileName, lphInf);
97 }
98
99 /***********************************************************************
100  *              IpClose16
101  */
102 RETERR16 WINAPI IpClose16(HINF16 hInf)
103 {
104     return IP_CloseInf(hInf);
105 }
106
107 /***********************************************************************
108  *              IpGetProfileString16
109  */
110 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen) 
111 {
112     TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
113     GetPrivateProfileString16(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
114     return 0;
115 }