Debug traces cosmetic fixes.
[wine] / dlls / msacm32 / internal.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4  *      MSACM32 library
5  *
6  *      Copyright 1998  Patrik Stridvall
7  *                1999  Eric Pouech
8  */
9
10 #include <string.h>
11
12 #include "winbase.h"
13 #include "winuser.h"
14 #include "winerror.h"
15 #include "driver.h"
16 #include "heap.h"
17 #include "mmsystem.h"
18 #include "msacm.h"
19 #include "msacmdrv.h"
20 #include "wineacm.h"
21 #include "debugtools.h"
22
23 DEFAULT_DEBUG_CHANNEL(msacm)    
24
25 /**********************************************************************/
26
27 HANDLE MSACM_hHeap = (HANDLE) NULL;
28 PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
29 PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
30
31 /***********************************************************************
32  *           MSACM_RegisterDriver32() 
33  */
34 PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
35                                        HINSTANCE hinstModule)
36
37     PWINE_ACMDRIVERID padid;
38
39     TRACE("('%s', '%s', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule);
40
41     padid = (PWINE_ACMDRIVERID) HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID));
42     padid->pszDriverAlias = HEAP_strdupA(MSACM_hHeap, 0, pszDriverAlias);
43     padid->pszFileName = HEAP_strdupA(MSACM_hHeap, 0, pszFileName);
44     padid->hInstModule = hinstModule;
45     padid->bEnabled = TRUE;
46     padid->pACMDriver = NULL;
47     padid->pNextACMDriverID = NULL;
48     padid->pPreviousACMDriverID = MSACM_pLastACMDriverID;
49     if (MSACM_pLastACMDriverID)
50         MSACM_pLastACMDriverID->pNextACMDriverID = padid;
51     MSACM_pLastACMDriverID = padid;
52     if (!MSACM_pFirstACMDriverID)
53         MSACM_pFirstACMDriverID = padid;
54     
55     return padid;
56 }
57
58 /***********************************************************************
59  *           MSACM_RegisterAllDrivers32() 
60  */
61 void MSACM_RegisterAllDrivers(void)
62 {
63     LPSTR pszBuffer;
64     DWORD dwBufferLength;
65     
66     /* FIXME 
67      *  What if the user edits system.ini while the program is running?
68      *  Does Windows handle that?
69      */
70     if (MSACM_pFirstACMDriverID)
71         return;
72     
73     /* FIXME: Do not work! How do I determine the section length? */
74     dwBufferLength = 1024;
75 /* EPP  GetPrivateProfileSectionA("drivers32", NULL, 0, "system.ini"); */
76     
77     pszBuffer = (LPSTR) HeapAlloc(MSACM_hHeap, 0, dwBufferLength);
78     if (GetPrivateProfileSectionA("drivers32", pszBuffer, dwBufferLength, "system.ini")) {
79         char* s = pszBuffer;
80         while (*s) {
81             if (!lstrncmpiA("MSACM.", s, 6)) {
82                 char *s2 = s;
83                 while (*s2 != '\0' && *s2 != '=') s2++;
84                 if (*s2) {
85                     *s2++ = '\0';
86                     MSACM_RegisterDriver(s, s2, 0);
87                 }
88             }  
89             s += lstrlenA(s) + 1; /* Either next char or \0 */
90         }
91     }
92     
93     HeapFree(MSACM_hHeap, 0, pszBuffer);
94 }
95
96 /***********************************************************************
97  *           MSACM_UnregisterDriver32()
98  */
99 PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
100 {
101     PWINE_ACMDRIVERID pNextACMDriverID;
102     
103     if (p->pACMDriver)
104         acmDriverClose((HACMDRIVER) p->pACMDriver, 0);
105     
106     if (p->pszDriverAlias)
107         HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
108     if (p->pszFileName)
109         HeapFree(MSACM_hHeap, 0, p->pszFileName);
110     
111     if (p == MSACM_pFirstACMDriverID)
112         MSACM_pFirstACMDriverID = p->pNextACMDriverID;
113     if (p == MSACM_pLastACMDriverID)
114         MSACM_pLastACMDriverID = p->pPreviousACMDriverID;
115
116     if (p->pPreviousACMDriverID)
117         p->pPreviousACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
118     if (p->pNextACMDriverID)
119         p->pNextACMDriverID->pPreviousACMDriverID = p->pPreviousACMDriverID;
120     
121     pNextACMDriverID = p->pNextACMDriverID;
122     
123     HeapFree(MSACM_hHeap, 0, p);
124     
125     return pNextACMDriverID;
126 }
127
128 /***********************************************************************
129  *           MSACM_UnregisterAllDrivers32()
130  * FIXME
131  *   Where should this function be called?
132  */
133 void MSACM_UnregisterAllDrivers(void)
134 {
135     PWINE_ACMDRIVERID p;
136
137     for (p = MSACM_pFirstACMDriverID; p; p = MSACM_UnregisterDriver(p));
138 }
139
140 /***********************************************************************
141  *           MSACM_GetDriverID32() 
142  */
143 PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
144 {
145     return (PWINE_ACMDRIVERID)hDriverID;
146 }
147
148 /***********************************************************************
149  *           MSACM_GetDriver32()
150  */
151 PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
152 {
153     return (PWINE_ACMDRIVER)hDriver;
154 }
155
156 /***********************************************************************
157  *           MSACM_GetObj32()
158  */
159 PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj)
160 {
161     return (PWINE_ACMOBJ)hObj;
162 }
163
164