Changed the GDI driver interface to pass an opaque PHYSDEV pointer
[wine] / dlls / setupapi / infparse.c
1 /*
2  * SetupX .inf file parsing functions
3  *
4  * Copyright 2000 Andreas Mohr for Codeweavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * FIXME:
21  * - return values ???
22  * - this should be reimplemented at some point to have its own
23  *   file parsing instead of using profile functions,
24  *   as some SETUPX exports probably demand that
25  *   (IpSaveRestorePosition, IpFindNextMatchLine, ...).
26  */
27
28 #include <string.h>
29 #include "wine/debug.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wine/winbase16.h"
33 #include "setupx16.h"
34 #include "setupapi_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
37
38 WORD InfNumEntries = 0;
39 INF_FILE *InfList = NULL;
40 HINF16 IP_curr_handle = 0;
41
42 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
43 {
44     HFILE hFile = _lopen(lpInfFileName, OF_READ);
45
46     if (!lphInf)
47         return IP_ERROR;
48
49     /* this could be improved by checking for already freed handles */
50     if (IP_curr_handle == 0xffff) 
51         return ERR_IP_OUT_OF_HANDLES; 
52
53     if (hFile != HFILE_ERROR)
54     {
55         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
56         InfList[InfNumEntries].hInf = IP_curr_handle++;
57         InfList[InfNumEntries].hInfFile = hFile;
58         InfList[InfNumEntries].lpInfFileName = HeapAlloc( GetProcessHeap(), 0,
59                                                           strlen(lpInfFileName)+1);
60         strcpy( InfList[InfNumEntries].lpInfFileName, lpInfFileName );
61         *lphInf = InfList[InfNumEntries].hInf;
62         InfNumEntries++;
63         TRACE("ret handle %d.\n", *lphInf);
64         return OK;
65     }
66     *lphInf = 0xffff;
67     return ERR_IP_INVALID_INFFILE;
68 }
69
70 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
71 {
72     WORD n;
73
74     for (n=0; n < InfNumEntries; n++)
75         if (InfList[n].hInf == hInf)
76         {
77             *ret = n;
78             return TRUE;
79         }
80     return FALSE;
81 }
82         
83
84 LPCSTR IP_GetFileName(HINF16 hInf)
85 {
86     WORD n;
87     if (IP_FindInf(hInf, &n))
88     {
89         return InfList[n].lpInfFileName;
90     }
91     return NULL;
92 }
93
94 RETERR16 IP_CloseInf(HINF16 hInf)
95 {
96     int i;
97     WORD n;
98     RETERR16 res = ERR_IP_INVALID_HINF;
99
100     if (IP_FindInf(hInf, &n))
101     {
102         _lclose(InfList[n].hInfFile);
103         HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName);
104         for (i=n; i < InfNumEntries-1; i++)
105             InfList[i] = InfList[i+1];
106         InfNumEntries--;
107         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
108         res = OK;
109     }
110     return res;
111 }
112
113 /***********************************************************************
114  *              IpOpen (SETUPX.2)
115  *
116  */
117 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
118 {
119     TRACE("('%s', %p)\n", lpInfFileName, lphInf);
120     return IP_OpenInf(lpInfFileName, lphInf);
121 }
122
123 /***********************************************************************
124  *              IpClose (SETUPX.4)
125  */
126 RETERR16 WINAPI IpClose16(HINF16 hInf)
127 {
128     return IP_CloseInf(hInf);
129 }
130
131 /***********************************************************************
132  *              IpGetProfileString (SETUPX.210)
133  */
134 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen) 
135 {
136     TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
137     GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
138     return 0;
139 }