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
16 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(gdi
);
25 static ENVTABLE EnvTable
[20];
27 static ENVTABLE
*SearchEnvTable(ATOM atom
)
31 for (i
= 19; i
>= 0; i
--) {
32 if (EnvTable
[i
].atom
== atom
)
38 static ATOM
GDI_GetNullPortAtom(void)
40 static ATOM NullPortAtom
= 0;
45 GetProfileStringA( "windows", "nullport", "none",
46 NullPort
, sizeof(NullPort
) );
47 NullPortAtom
= AddAtomA( NullPort
);
52 static ATOM
PortNameToAtom(LPCSTR lpPortName
, BOOL16 add
)
56 strncpy( buffer
, lpPortName
, sizeof(buffer
) );
57 buffer
[sizeof(buffer
)-1] = 0;
59 if (buffer
[0] && buffer
[strlen(buffer
)-1] == ':') buffer
[strlen(buffer
)-1] = 0;
62 return AddAtomA(buffer
);
64 return FindAtomA(buffer
);
68 /***********************************************************************
69 * GetEnvironment (GDI.133)
71 INT16 WINAPI
GetEnvironment16(LPCSTR lpPortName
, LPDEVMODEA lpdev
, UINT16 nMaxSize
)
78 TRACE("('%s', %p, %d)\n", lpPortName
, lpdev
, nMaxSize
);
80 if (!(atom
= PortNameToAtom(lpPortName
, FALSE
)))
82 if (atom
== GDI_GetNullPortAtom())
83 if (!(atom
= FindAtomA((LPCSTR
)lpdev
)))
85 if (!(env
= SearchEnvTable(atom
)))
87 size
= GlobalSize16(env
->handle
);
89 if (size
< nMaxSize
) nMaxSize
= size
;
90 if (!(p
= GlobalLock16(env
->handle
))) return 0;
91 memcpy(lpdev
, p
, nMaxSize
);
92 GlobalUnlock16(env
->handle
);
97 /***********************************************************************
98 * SetEnvironment (GDI.132)
100 INT16 WINAPI
SetEnvironment16(LPCSTR lpPortName
, LPDEVMODEA lpdev
, UINT16 nCount
)
103 BOOL16 nullport
= FALSE
;
108 TRACE("('%s', %p, %d)\n", lpPortName
, lpdev
, nCount
);
110 if ((atom
= PortNameToAtom(lpPortName
, FALSE
))) {
111 if (atom
== GDI_GetNullPortAtom()) {
113 atom
= FindAtomA((LPCSTR
)lpdev
);
115 env
= SearchEnvTable(atom
);
116 GlobalFree16(env
->handle
);
119 if (nCount
) { /* store DEVMODE struct */
123 p
= (LPSTR
)lpPortName
;
125 if ((atom
= PortNameToAtom(p
, TRUE
))
126 && (env
= SearchEnvTable(0))
127 && (handle
= GlobalAlloc16(GMEM_SHARE
|GMEM_MOVEABLE
, nCount
))) {
128 if (!(p
= GlobalLock16(handle
))) {
129 GlobalFree16(handle
);
133 env
->handle
= handle
;
134 memcpy(p
, lpdev
, nCount
);
135 GlobalUnlock16(handle
);