1 | /* $Id: infparse.c,v 1.2 2001-09-05 13:38:23 bird Exp $ */
|
---|
2 | /*
|
---|
3 | * SetupX .inf file parsing functions
|
---|
4 | *
|
---|
5 | * FIXME:
|
---|
6 | * - return values ???
|
---|
7 | * - this should be reimplemented at some point to have its own
|
---|
8 | * file parsing instead of using profile functions,
|
---|
9 | * as some SETUPX exports probably demand that
|
---|
10 | * (IpSaveRestorePosition, IpFindNextMatchLine, ...).
|
---|
11 | */
|
---|
12 |
|
---|
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 "setupx_private.h"
|
---|
20 |
|
---|
21 | DEFAULT_DEBUG_CHANNEL(setupx);
|
---|
22 |
|
---|
23 | WORD InfNumEntries = 0;
|
---|
24 | INF_FILE *InfList = NULL;
|
---|
25 | HINF16 IP_curr_handle = 0;
|
---|
26 |
|
---|
27 | RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
|
---|
28 | {
|
---|
29 | HFILE hFile = _lopen(lpInfFileName, OF_READ);
|
---|
30 |
|
---|
31 | if (!lphInf)
|
---|
32 | return IP_ERROR;
|
---|
33 |
|
---|
34 | /* this could be improved by checking for already freed handles */
|
---|
35 | if (IP_curr_handle == 0xffff)
|
---|
36 | return ERR_IP_OUT_OF_HANDLES;
|
---|
37 |
|
---|
38 | if (hFile != HFILE_ERROR)
|
---|
39 | {
|
---|
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;
|
---|
50 | }
|
---|
51 | *lphInf = 0xffff;
|
---|
52 | return ERR_IP_INVALID_INFFILE;
|
---|
53 | }
|
---|
54 |
|
---|
55 | BOOL IP_FindInf(HINF16 hInf, WORD *ret)
|
---|
56 | {
|
---|
57 | WORD n;
|
---|
58 |
|
---|
59 | for (n=0; n < InfNumEntries; n++)
|
---|
60 | if (InfList[n].hInf == hInf)
|
---|
61 | {
|
---|
62 | *ret = n;
|
---|
63 | return TRUE;
|
---|
64 | }
|
---|
65 | return FALSE;
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | LPCSTR IP_GetFileName(HINF16 hInf)
|
---|
70 | {
|
---|
71 | WORD n;
|
---|
72 | if (IP_FindInf(hInf, &n))
|
---|
73 | {
|
---|
74 | return InfList[n].lpInfFileName;
|
---|
75 | }
|
---|
76 | return NULL;
|
---|
77 | }
|
---|
78 |
|
---|
79 | RETERR16 IP_CloseInf(HINF16 hInf)
|
---|
80 | {
|
---|
81 | int i;
|
---|
82 | WORD n;
|
---|
83 | RETERR16 res = ERR_IP_INVALID_HINF;
|
---|
84 |
|
---|
85 | if (IP_FindInf(hInf, &n))
|
---|
86 | {
|
---|
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;
|
---|
94 | }
|
---|
95 | return res;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /***********************************************************************
|
---|
99 | * IpOpen16
|
---|
100 | *
|
---|
101 | */
|
---|
102 | RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
|
---|
103 | {
|
---|
104 | TRACE("('%s', %p)\n", lpInfFileName, lphInf);
|
---|
105 | return IP_OpenInf(lpInfFileName, lphInf);
|
---|
106 | }
|
---|
107 |
|
---|
108 | /***********************************************************************
|
---|
109 | * IpClose16
|
---|
110 | */
|
---|
111 | RETERR16 WINAPI IpClose16(HINF16 hInf)
|
---|
112 | {
|
---|
113 | return IP_CloseInf(hInf);
|
---|
114 | }
|
---|
115 |
|
---|
116 | /***********************************************************************
|
---|
117 | * IpGetProfileString16
|
---|
118 | */
|
---|
119 | RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen)
|
---|
120 | {
|
---|
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;
|
---|
124 | }
|
---|