Convert MRULists to Unicode.
[wine/testsucceed.git] / dlls / setupapi / infparse.c
blob25e2f184be9c744f177d822a370498677b1def43
1 /*
2 * SetupX .inf file parsing functions
4 * FIXME:
5 * - return values ???
6 * - this should be reimplemented at some point to have its own
7 * file parsing instead of using profile functions,
8 * as some SETUPX exports probably demand that
9 * (IpSaveRestorePosition, IpFindNextMatchLine, ...).
12 #include <string.h>
13 #include "debugtools.h"
14 #include "windef.h"
15 #include "winbase.h"
16 #include "wine/winbase16.h"
17 #include "setupx16.h"
18 #include "setupapi_private.h"
20 DEFAULT_DEBUG_CHANNEL(setupapi);
22 WORD InfNumEntries = 0;
23 INF_FILE *InfList = NULL;
24 HINF16 IP_curr_handle = 0;
26 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
28 HFILE hFile = _lopen(lpInfFileName, OF_READ);
30 if (!lphInf)
31 return IP_ERROR;
33 /* this could be improved by checking for already freed handles */
34 if (IP_curr_handle == 0xffff)
35 return ERR_IP_OUT_OF_HANDLES;
37 if (hFile != HFILE_ERROR)
39 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
40 InfList[InfNumEntries].hInf = IP_curr_handle++;
41 InfList[InfNumEntries].hInfFile = hFile;
42 InfList[InfNumEntries].lpInfFileName = HeapAlloc( GetProcessHeap(), 0,
43 strlen(lpInfFileName)+1);
44 strcpy( InfList[InfNumEntries].lpInfFileName, lpInfFileName );
45 *lphInf = InfList[InfNumEntries].hInf;
46 InfNumEntries++;
47 TRACE("ret handle %d.\n", *lphInf);
48 return OK;
50 *lphInf = 0xffff;
51 return ERR_IP_INVALID_INFFILE;
54 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
56 WORD n;
58 for (n=0; n < InfNumEntries; n++)
59 if (InfList[n].hInf == hInf)
61 *ret = n;
62 return TRUE;
64 return FALSE;
68 LPCSTR IP_GetFileName(HINF16 hInf)
70 WORD n;
71 if (IP_FindInf(hInf, &n))
73 return InfList[n].lpInfFileName;
75 return NULL;
78 RETERR16 IP_CloseInf(HINF16 hInf)
80 int i;
81 WORD n;
82 RETERR16 res = ERR_IP_INVALID_HINF;
84 if (IP_FindInf(hInf, &n))
86 _lclose(InfList[n].hInfFile);
87 HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName);
88 for (i=n; i < InfNumEntries-1; i++)
89 InfList[i] = InfList[i+1];
90 InfNumEntries--;
91 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
92 res = OK;
94 return res;
97 /***********************************************************************
98 * IpOpen (SETUPX.2)
101 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
103 TRACE("('%s', %p)\n", lpInfFileName, lphInf);
104 return IP_OpenInf(lpInfFileName, lphInf);
107 /***********************************************************************
108 * IpClose (SETUPX.4)
110 RETERR16 WINAPI IpClose16(HINF16 hInf)
112 return IP_CloseInf(hInf);
115 /***********************************************************************
116 * IpGetProfileString (SETUPX.210)
118 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen)
120 TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
121 GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
122 return 0;