Removed some unnecessary includes.
[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     HFILE hFile = _lopen(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_ERROR)
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 = HeapAlloc( GetProcessHeap(), 0,
37                                                           strlen(lpInfFileName)+1);
38         strcpy( InfList[InfNumEntries].lpInfFileName, lpInfFileName );
39         *lphInf = InfList[InfNumEntries].hInf;
40         InfNumEntries++;
41         TRACE("ret handle %d.\n", *lphInf);
42         return OK;
43     }
44     *lphInf = 0xffff;
45     return ERR_IP_INVALID_INFFILE;
46 }
47
48 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
49 {
50     WORD n;
51
52     for (n=0; n < InfNumEntries; n++)
53         if (InfList[n].hInf == hInf)
54         {
55             *ret = n;
56             return TRUE;
57         }
58     return FALSE;
59 }
60         
61
62 LPCSTR IP_GetFileName(HINF16 hInf)
63 {
64     WORD n;
65     if (IP_FindInf(hInf, &n))
66     {
67         return InfList[n].lpInfFileName;
68     }
69     return NULL;
70 }
71
72 RETERR16 IP_CloseInf(HINF16 hInf)
73 {
74     int i;
75     WORD n;
76     RETERR16 res = ERR_IP_INVALID_HINF;
77
78     if (IP_FindInf(hInf, &n))
79     {
80         _lclose(InfList[n].hInfFile);
81         HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName);
82         for (i=n; i < InfNumEntries-1; i++)
83             InfList[i] = InfList[i+1];
84         InfNumEntries--;
85         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
86         res = OK;
87     }
88     return res;
89 }
90
91 /***********************************************************************
92  *              IpOpen16
93  *
94  */
95 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
96 {
97     TRACE("('%s', %p)\n", lpInfFileName, lphInf);
98     return IP_OpenInf(lpInfFileName, lphInf);
99 }
100
101 /***********************************************************************
102  *              IpClose16
103  */
104 RETERR16 WINAPI IpClose16(HINF16 hInf)
105 {
106     return IP_CloseInf(hInf);
107 }
108
109 /***********************************************************************
110  *              IpGetProfileString16
111  */
112 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen) 
113 {
114     TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
115     GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
116     return 0;
117 }