Fixed CHECK_STRING display.
[wine/multimedia.git] / graphics / env.c
blob8220a216a90f672829cedf64acda071e2371c7d8
1 /*
2 * Driver Environment functions
4 * Note: This has NOTHING to do with the task/process environment!
6 * Copyright 1997 Marcus Meissner
7 * Copyright 1998 Andreas Mohr
8 */
9 #include <stdio.h>
10 #include <string.h>
11 #include "windows.h"
12 #include "config.h"
13 #include "gdi.h"
14 #include "debug.h"
15 #include "heap.h"
17 typedef struct {
18 ATOM atom;
19 HGLOBAL16 handle;
20 } ENVTABLE;
22 static ENVTABLE EnvTable[20];
24 static ENVTABLE *SearchEnvTable(ATOM atom)
26 INT16 i;
28 for (i = 19; i >= 0; i--) {
29 if (EnvTable[i].atom == atom)
30 return &EnvTable[i];
32 return NULL;
35 static ATOM GDI_GetNullPortAtom(void)
37 static ATOM NullPortAtom = 0;
38 if (!NullPortAtom)
40 char NullPort[256];
42 GetProfileString32A( "windows", "nullport", "none",
43 NullPort, sizeof(NullPort) );
44 NullPortAtom = AddAtom32A( NullPort );
46 return NullPortAtom;
49 static ATOM PortNameToAtom(LPCSTR lpPortName, BOOL16 add)
51 char *p;
52 BOOL32 needfree = FALSE;
53 ATOM ret;
55 if (lpPortName[strlen(lpPortName) - 1] == ':') {
56 p = HEAP_strdupA(GetProcessHeap(), 0, lpPortName);
57 p[strlen(lpPortName) - 1] = '\0';
58 needfree = TRUE;
60 else
61 p = (char *)lpPortName;
63 if (add)
64 ret = AddAtom32A(p);
65 else
66 ret = FindAtom32A(p);
68 if(needfree) HeapFree(GetProcessHeap(), 0, p);
70 return ret;
74 /***********************************************************************
75 * GetEnvironment (GDI.134)
77 INT16 WINAPI GetEnvironment(LPCSTR lpPortName, LPDEVMODE16 lpdev, UINT16 nMaxSize)
79 ATOM atom;
80 LPCSTR p;
81 ENVTABLE *env;
82 WORD size;
84 TRACE(gdi, "('%s', %p, %d)\n", lpPortName, lpdev, nMaxSize);
86 if (!(atom = PortNameToAtom(lpPortName, FALSE)))
87 return 0;
88 if (atom == GDI_GetNullPortAtom())
89 if (!(atom = FindAtom32A((LPCSTR)lpdev)))
90 return 0;
91 if (!(env = SearchEnvTable(atom)))
92 return 0;
93 size = GlobalSize16(env->handle);
94 if (!lpdev) return 0;
95 if (size < nMaxSize) nMaxSize = size;
96 if (!(p = GlobalLock16(env->handle))) return 0;
97 memcpy(lpdev, p, nMaxSize);
98 GlobalUnlock16(env->handle);
99 return nMaxSize;
103 /***********************************************************************
104 * SetEnvironment (GDI.132)
106 INT16 WINAPI SetEnvironment(LPCSTR lpPortName, LPDEVMODE16 lpdev, UINT16 nCount)
108 ATOM atom;
109 BOOL16 nullport = FALSE;
110 LPSTR p;
111 ENVTABLE *env;
112 HGLOBAL16 handle;
114 TRACE(gdi, "('%s', %p, %d)\n", lpPortName, lpdev, nCount);
116 if ((atom = PortNameToAtom(lpPortName, FALSE))) {
117 if (atom == GDI_GetNullPortAtom()) {
118 nullport = TRUE;
119 atom = FindAtom32A((LPCSTR)lpdev);
121 env = SearchEnvTable(atom);
122 GlobalFree16(env->handle);
123 env->atom = 0;
125 if (nCount) { /* store DEVMODE struct */
126 if (nullport)
127 p = (LPSTR)lpdev;
128 else
129 p = (LPSTR)lpPortName;
131 if ((atom = PortNameToAtom(p, TRUE))
132 && (env = SearchEnvTable(0))
133 && (handle = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, nCount))) {
134 if (!(p = GlobalLock16(handle))) {
135 GlobalFree16(handle);
136 return 0;
138 env->atom = atom;
139 env->handle = handle;
140 memcpy(p, lpdev, nCount);
141 GlobalUnlock16(handle);
142 return handle;
144 else return 0;
146 else return -1;