2 * SetupX .inf file parsing functions
4 * Copyright 2000 Andreas Mohr for Codeweavers
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.
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.
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
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, ...).
29 #include "wine/debug.h"
32 #include "wine/winbase16.h"
34 #include "setupapi_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
38 WORD InfNumEntries = 0;
39 INF_FILE *InfList = NULL;
40 HINF16 IP_curr_handle = 0;
42 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
44 HFILE hFile = _lopen(lpInfFileName, OF_READ);
49 /* this could be improved by checking for already freed handles */
50 if (IP_curr_handle == 0xffff)
51 return ERR_IP_OUT_OF_HANDLES;
53 if (hFile != HFILE_ERROR)
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;
63 TRACE("ret handle %d.\n", *lphInf);
67 return ERR_IP_INVALID_INFFILE;
70 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
74 for (n=0; n < InfNumEntries; n++)
75 if (InfList[n].hInf == hInf)
84 LPCSTR IP_GetFileName(HINF16 hInf)
87 if (IP_FindInf(hInf, &n))
89 return InfList[n].lpInfFileName;
94 RETERR16 IP_CloseInf(HINF16 hInf)
98 RETERR16 res = ERR_IP_INVALID_HINF;
100 if (IP_FindInf(hInf, &n))
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];
107 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
113 /***********************************************************************
117 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
119 TRACE("('%s', %p)\n", lpInfFileName, lphInf);
120 return IP_OpenInf(lpInfFileName, lphInf);
123 /***********************************************************************
126 RETERR16 WINAPI IpClose16(HINF16 hInf)
128 return IP_CloseInf(hInf);
131 /***********************************************************************
132 * IpGetProfileString (SETUPX.210)
134 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen)
136 TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
137 GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));