- implement some more virtcopy (VCP) stuff
[wine.git] / dlls / setupapi / infparse.c
blob2582dff5d71c64c8e8937b43f99b61e1522d7517
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 "heap.h"
17 #include "wine/winbase16.h"
18 #include "setupx16.h"
19 #include "setupapi_private.h"
21 DEFAULT_DEBUG_CHANNEL(setupapi);
23 WORD InfNumEntries = 0;
24 INF_FILE *InfList = NULL;
25 HINF16 IP_curr_handle = 0;
27 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
29 HFILE hFile = _lopen(lpInfFileName, OF_READ);
31 if (!lphInf)
32 return IP_ERROR;
34 /* this could be improved by checking for already freed handles */
35 if (IP_curr_handle == 0xffff)
36 return ERR_IP_OUT_OF_HANDLES;
38 if (hFile != HFILE_ERROR)
40 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
41 InfList[InfNumEntries].hInf = IP_curr_handle++;
42 InfList[InfNumEntries].hInfFile = hFile;
43 InfList[InfNumEntries].lpInfFileName = HeapAlloc( GetProcessHeap(), 0,
44 strlen(lpInfFileName)+1);
45 strcpy( InfList[InfNumEntries].lpInfFileName, lpInfFileName );
46 *lphInf = InfList[InfNumEntries].hInf;
47 InfNumEntries++;
48 TRACE("ret handle %d.\n", *lphInf);
49 return OK;
51 *lphInf = 0xffff;
52 return ERR_IP_INVALID_INFFILE;
55 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
57 WORD n;
59 for (n=0; n < InfNumEntries; n++)
60 if (InfList[n].hInf == hInf)
62 *ret = n;
63 return TRUE;
65 return FALSE;
69 LPCSTR IP_GetFileName(HINF16 hInf)
71 WORD n;
72 if (IP_FindInf(hInf, &n))
74 return InfList[n].lpInfFileName;
76 return NULL;
79 RETERR16 IP_CloseInf(HINF16 hInf)
81 int i;
82 WORD n;
83 RETERR16 res = ERR_IP_INVALID_HINF;
85 if (IP_FindInf(hInf, &n))
87 _lclose(InfList[n].hInfFile);
88 HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName);
89 for (i=n; i < InfNumEntries-1; i++)
90 InfList[i] = InfList[i+1];
91 InfNumEntries--;
92 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
93 res = OK;
95 return res;
98 /***********************************************************************
99 * IpOpen16
102 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
104 TRACE("('%s', %p)\n", lpInfFileName, lphInf);
105 return IP_OpenInf(lpInfFileName, lphInf);
108 /***********************************************************************
109 * IpClose16
111 RETERR16 WINAPI IpClose16(HINF16 hInf)
113 return IP_CloseInf(hInf);
116 /***********************************************************************
117 * IpGetProfileString16
119 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen)
121 TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
122 GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
123 return 0;