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
13 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(gdi
);
23 static ENVTABLE EnvTable
[20];
25 static ENVTABLE
*SearchEnvTable(ATOM atom
)
29 for (i
= 19; i
>= 0; i
--) {
30 if (EnvTable
[i
].atom
== atom
)
36 static ATOM
GDI_GetNullPortAtom(void)
38 static ATOM NullPortAtom
= 0;
43 GetProfileStringA( "windows", "nullport", "none",
44 NullPort
, sizeof(NullPort
) );
45 NullPortAtom
= AddAtomA( NullPort
);
50 static ATOM
PortNameToAtom(LPCSTR lpPortName
, BOOL16 add
)
53 BOOL needfree
= FALSE
;
56 if (lpPortName
[strlen(lpPortName
) - 1] == ':') {
57 p
= HEAP_strdupA(GetProcessHeap(), 0, lpPortName
);
58 p
[strlen(lpPortName
) - 1] = '\0';
62 p
= (char *)lpPortName
;
69 if(needfree
) HeapFree(GetProcessHeap(), 0, p
);
75 /***********************************************************************
76 * GetEnvironment (GDI.133)
78 INT16 WINAPI
GetEnvironment16(LPCSTR lpPortName
, LPDEVMODEA lpdev
, UINT16 nMaxSize
)
85 TRACE("('%s', %p, %d)\n", lpPortName
, lpdev
, nMaxSize
);
87 if (!(atom
= PortNameToAtom(lpPortName
, FALSE
)))
89 if (atom
== GDI_GetNullPortAtom())
90 if (!(atom
= FindAtomA((LPCSTR
)lpdev
)))
92 if (!(env
= SearchEnvTable(atom
)))
94 size
= GlobalSize16(env
->handle
);
96 if (size
< nMaxSize
) nMaxSize
= size
;
97 if (!(p
= GlobalLock16(env
->handle
))) return 0;
98 memcpy(lpdev
, p
, nMaxSize
);
99 GlobalUnlock16(env
->handle
);
104 /***********************************************************************
105 * SetEnvironment (GDI.132)
107 INT16 WINAPI
SetEnvironment16(LPCSTR lpPortName
, LPDEVMODEA lpdev
, UINT16 nCount
)
110 BOOL16 nullport
= FALSE
;
115 TRACE("('%s', %p, %d)\n", lpPortName
, lpdev
, nCount
);
117 if ((atom
= PortNameToAtom(lpPortName
, FALSE
))) {
118 if (atom
== GDI_GetNullPortAtom()) {
120 atom
= FindAtomA((LPCSTR
)lpdev
);
122 env
= SearchEnvTable(atom
);
123 GlobalFree16(env
->handle
);
126 if (nCount
) { /* store DEVMODE struct */
130 p
= (LPSTR
)lpPortName
;
132 if ((atom
= PortNameToAtom(p
, TRUE
))
133 && (env
= SearchEnvTable(0))
134 && (handle
= GlobalAlloc16(GMEM_SHARE
|GMEM_MOVEABLE
, nCount
))) {
135 if (!(p
= GlobalLock16(handle
))) {
136 GlobalFree16(handle
);
140 env
->handle
= handle
;
141 memcpy(p
, lpdev
, nCount
);
142 GlobalUnlock16(handle
);