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"
15 DEFAULT_DEBUG_CHANNEL(gdi
);
22 static ENVTABLE EnvTable
[20];
24 static ENVTABLE
*SearchEnvTable(ATOM atom
)
28 for (i
= 19; i
>= 0; i
--) {
29 if (EnvTable
[i
].atom
== atom
)
35 static ATOM
GDI_GetNullPortAtom(void)
37 static ATOM NullPortAtom
= 0;
42 GetProfileStringA( "windows", "nullport", "none",
43 NullPort
, sizeof(NullPort
) );
44 NullPortAtom
= AddAtomA( NullPort
);
49 static ATOM
PortNameToAtom(LPCSTR lpPortName
, BOOL16 add
)
53 strncpy( buffer
, lpPortName
, sizeof(buffer
) );
54 buffer
[sizeof(buffer
)-1] = 0;
56 if (buffer
[0] && buffer
[strlen(buffer
)-1] == ':') buffer
[strlen(buffer
)-1] = 0;
59 return AddAtomA(buffer
);
61 return FindAtomA(buffer
);
65 /***********************************************************************
66 * GetEnvironment (GDI.133)
68 INT16 WINAPI
GetEnvironment16(LPCSTR lpPortName
, LPDEVMODEA lpdev
, UINT16 nMaxSize
)
75 TRACE("('%s', %p, %d)\n", lpPortName
, lpdev
, nMaxSize
);
77 if (!(atom
= PortNameToAtom(lpPortName
, FALSE
)))
79 if (atom
== GDI_GetNullPortAtom())
80 if (!(atom
= FindAtomA((LPCSTR
)lpdev
)))
82 if (!(env
= SearchEnvTable(atom
)))
84 size
= GlobalSize16(env
->handle
);
86 if (size
< nMaxSize
) nMaxSize
= size
;
87 if (!(p
= GlobalLock16(env
->handle
))) return 0;
88 memcpy(lpdev
, p
, nMaxSize
);
89 GlobalUnlock16(env
->handle
);
94 /***********************************************************************
95 * SetEnvironment (GDI.132)
97 INT16 WINAPI
SetEnvironment16(LPCSTR lpPortName
, LPDEVMODEA lpdev
, UINT16 nCount
)
100 BOOL16 nullport
= FALSE
;
105 TRACE("('%s', %p, %d)\n", lpPortName
, lpdev
, nCount
);
107 if ((atom
= PortNameToAtom(lpPortName
, FALSE
))) {
108 if (atom
== GDI_GetNullPortAtom()) {
110 atom
= FindAtomA((LPCSTR
)lpdev
);
112 env
= SearchEnvTable(atom
);
113 GlobalFree16(env
->handle
);
116 if (nCount
) { /* store DEVMODE struct */
120 p
= (LPSTR
)lpPortName
;
122 if ((atom
= PortNameToAtom(p
, TRUE
))
123 && (env
= SearchEnvTable(0))
124 && (handle
= GlobalAlloc16(GMEM_SHARE
|GMEM_MOVEABLE
, nCount
))) {
125 if (!(p
= GlobalLock16(handle
))) {
126 GlobalFree16(handle
);
130 env
->handle
= handle
;
131 memcpy(p
, lpdev
, nCount
);
132 GlobalUnlock16(handle
);