reformat some code to make it readably

svn path=/trunk/; revision=14530
This commit is contained in:
Thomas Bluemel 2005-04-06 18:30:09 +00:00
parent 237d12dc8e
commit 68c2c91476

View file

@ -28,31 +28,23 @@
/* TYPES */ /* TYPES */
/* Pointer to a callback that handles a particular parameter */ /* Pointer to a callback that handles a particular parameter */
typedef BOOL (*COMMDCB_PARAM_CALLBACK) typedef BOOL (*COMMDCB_PARAM_CALLBACK)(DCB *, COMMTIMEOUTS *, BOOL *, LPWSTR *);
(
DCB *,
COMMTIMEOUTS *,
BOOL *,
LPWSTR *
);
/* Symbolic flag of any length */ /* Symbolic flag of any length */
typedef struct _COMMDCB_PARAM_STRFLAG typedef struct _COMMDCB_PARAM_STRFLAG
{ {
UNICODE_STRING String; UNICODE_STRING String;
ULONG_PTR Value; ULONG_PTR Value;
} COMMDCB_PARAM_STRFLAG; } COMMDCB_PARAM_STRFLAG, *PCOMMDCB_PARAM_STRFLAG;
/* One char long symbolic flag */ /* One char long symbolic flag */
typedef struct _COMMDCB_PARAM_CHARFLAG typedef struct _COMMDCB_PARAM_CHARFLAG
{ {
WCHAR Char; WCHAR Char;
ULONG_PTR Value; ULONG_PTR Value;
} COMMDCB_PARAM_CHARFLAG; } COMMDCB_PARAM_CHARFLAG, *PCOMMDCB_PARAM_CHARFLAG;
/* MACROS */ /* MACROS */
/* stupid Borland C++ requires this */
#define _L(__S__) L ## __S__
/* Declare a parameter handler */ /* Declare a parameter handler */
#define COMMDCB_PARAM_HANDLER(__P__) \ #define COMMDCB_PARAM_HANDLER(__P__) \
@ -69,13 +61,11 @@ typedef struct _COMMDCB_PARAM_CHARFLAG
Lookup a string flag and return its numerical value. The flags array must be Lookup a string flag and return its numerical value. The flags array must be
sorted - a dichotomycal search is performed sorted - a dichotomycal search is performed
*/ */
BOOL COMMDCB_LookupStrFlag static BOOL
( COMMDCB_LookupStrFlag(PUNICODE_STRING Flag,
UNICODE_STRING * Flag, PCOMMDCB_PARAM_STRFLAG Flags,
COMMDCB_PARAM_STRFLAG * Flags,
int FlagCount, int FlagCount,
ULONG_PTR * Value PULONG_PTR Value)
)
{ {
/* Lower and upper bound for dichotomycal search */ /* Lower and upper bound for dichotomycal search */
int nLowerBound = 0; int nLowerBound = 0;
@ -88,12 +78,9 @@ BOOL COMMDCB_LookupStrFlag
int nCurFlag = nLowerBound + (nUpperBound - nLowerBound) / 2; int nCurFlag = nLowerBound + (nUpperBound - nLowerBound) / 2;
/* compare the string with the pivot */ /* compare the string with the pivot */
nComparison = RtlCompareUnicodeString nComparison = RtlCompareUnicodeString(Flag,
(
Flag,
&Flags[nCurFlag].String, &Flags[nCurFlag].String,
TRUE TRUE);
);
/* string is equal */ /* string is equal */
if(nComparison == 0) if(nComparison == 0)
@ -104,29 +91,21 @@ BOOL COMMDCB_LookupStrFlag
/* success */ /* success */
return TRUE; return TRUE;
} }
/* string is less than */
else if(nComparison < 0) else if(nComparison < 0)
{ {
/* /*
restrict the search to the first half of the current slice, minus the pivot * restrict the search to the first half of the current slice, minus the pivot
*/ */
nUpperBound = nCurFlag - 1; nUpperBound = nCurFlag - 1;
/* fallthrough */
} }
/* string is greater than */
else else
{ {
/* /*
restrict the search to the second half of the current slice, minus the pivot * restrict the search to the second half of the current slice, minus the pivot
*/ */
nLowerBound = nCurFlag + 1; nLowerBound = nCurFlag + 1;
/* fallthrough */
} }
} } while(nLowerBound <= nUpperBound);
/* continue until the slice is empty */
while(nLowerBound <= nUpperBound);
/* string not found: failure */ /* string not found: failure */
return FALSE; return FALSE;
@ -137,13 +116,11 @@ BOOL COMMDCB_LookupStrFlag
Find the next character flag and return its numerical value. The flags array Find the next character flag and return its numerical value. The flags array
must be sorted - a dichotomycal search is performed must be sorted - a dichotomycal search is performed
*/ */
BOOL COMMDCB_ParseCharFlag static BOOL
( COMMDCB_ParseCharFlag(LPWSTR *StrTail,
LPWSTR * StrTail, PCOMMDCB_PARAM_CHARFLAG Flags,
COMMDCB_PARAM_CHARFLAG * Flags,
int FlagCount, int FlagCount,
ULONG_PTR * Value PULONG_PTR Value)
)
{ {
/* Lower and upper bound for dichotomycal search */ /* Lower and upper bound for dichotomycal search */
int nLowerBound = 0; int nLowerBound = 0;
@ -153,14 +130,13 @@ BOOL COMMDCB_ParseCharFlag
/* premature end of string, or the character is whitespace */ /* premature end of string, or the character is whitespace */
if(!wcFlag || iswspace(wcFlag)) if(!wcFlag || iswspace(wcFlag))
/* failure */
return FALSE; return FALSE;
/* uppercase the character for case-insensitive search */ /* uppercase the character for case-insensitive search */
wcFlag = towupper(wcFlag); wcFlag = towupper(wcFlag);
/* skip the character flag */ /* skip the character flag */
++ (*StrTail); (*StrTail)++;
/* see COMMDCB_LookupStrFlag for a description of the algorithm */ /* see COMMDCB_LookupStrFlag for a description of the algorithm */
do do
@ -184,8 +160,7 @@ BOOL COMMDCB_ParseCharFlag
{ {
nLowerBound = nCurFlag + 1; nLowerBound = nCurFlag + 1;
} }
} } while(nUpperBound >= nLowerBound);
while(nUpperBound >= nLowerBound);
/* flag not found: failure */ /* flag not found: failure */
return FALSE; return FALSE;
@ -195,24 +170,22 @@ BOOL COMMDCB_ParseCharFlag
Find the next string flag and return its numerical value. The flags array must Find the next string flag and return its numerical value. The flags array must
be sorted - a dichotomycal search is performed be sorted - a dichotomycal search is performed
*/ */
BOOL COMMDCB_ParseStrFlag static BOOL
( COMMDCB_ParseStrFlag(LPWSTR *StrTail,
LPWSTR * StrTail, PCOMMDCB_PARAM_STRFLAG Flags,
COMMDCB_PARAM_STRFLAG * Flags,
int FlagCount, int FlagCount,
ULONG_PTR * Value PULONG_PTR Value)
)
{ {
LPWSTR pwcNewTail = *StrTail; LPWSTR pwcNewTail;
UNICODE_STRING wstrFlag; UNICODE_STRING wstrFlag;
/* scan the string until the first space character or the terminating null */ /* scan the string until the first space character or the terminating null */
while(pwcNewTail[0] && !iswspace(pwcNewTail[0])) for(pwcNewTail = *StrTail;
++ pwcNewTail; pwcNewTail[0] && !iswspace(pwcNewTail[0]);
pwcNewTail++);
/* string flag empty */ /* string flag empty */
if(pwcNewTail == *StrTail) if(pwcNewTail == *StrTail)
/* failure */
return FALSE; return FALSE;
/* build the UNICODE_STRING description of the string flag */ /* build the UNICODE_STRING description of the string flag */
@ -230,43 +203,45 @@ BOOL COMMDCB_ParseStrFlag
/* /*
Parse a boolean value in the symbolic form on/off Parse a boolean value in the symbolic form on/off
*/ */
BOOL COMMDCB_ParseBool(LPWSTR * StrTail, BOOL * Value) static BOOL
COMMDCB_ParseBool(LPWSTR *StrTail,
PBOOL Value)
{ {
BOOL bRetVal; BOOL bRetVal;
ULONG_PTR nValue; ULONG_PTR nValue;
static COMMDCB_PARAM_STRFLAG a_BoolFlags[] = static COMMDCB_PARAM_STRFLAG a_BoolFlags[] = {
{
{ ROS_STRING_INITIALIZER(L"off"), FALSE }, { ROS_STRING_INITIALIZER(L"off"), FALSE },
{ ROS_STRING_INITIALIZER(L"on"), TRUE } { ROS_STRING_INITIALIZER(L"on"), TRUE }
}; };
/* try to recognize the next flag as a boolean */ /* try to recognize the next flag as a boolean */
bRetVal = COMMDCB_ParseStrFlag bRetVal = COMMDCB_ParseStrFlag(StrTail,
(
StrTail,
a_BoolFlags, a_BoolFlags,
sizeof(a_BoolFlags) / sizeof(a_BoolFlags[0]), sizeof(a_BoolFlags) / sizeof(a_BoolFlags[0]),
&nValue &nValue);
);
/* failure */
if(!bRetVal) return FALSE; if(!bRetVal)
return FALSE;
/* success */ /* success */
*Value = nValue ? TRUE : FALSE; *Value = (nValue ? TRUE : FALSE);
return TRUE; return TRUE;
} }
/* /*
Parse a decimal integer Parse a decimal integer
*/ */
BOOL COMMDCB_ParseInt(LPWSTR * StrTail, DWORD * Value) static BOOL
COMMDCB_ParseInt(LPWSTR *StrTail,
DWORD *Value)
{ {
LPWSTR pwcPrevTail = *StrTail; LPWSTR pwcPrevTail = *StrTail;
DWORD nValue = wcstoul(*StrTail, StrTail, 10); DWORD nValue = wcstoul(*StrTail, StrTail, 10);
/* no character was consumed: failure */ /* no character was consumed: failure */
if(pwcPrevTail == *StrTail) return FALSE; if(pwcPrevTail == *StrTail)
return FALSE;
/* success */ /* success */
*Value = nValue; *Value = nValue;
@ -283,32 +258,54 @@ COMMDCB_PARAM_HANDLER(baud)
/* parse the baudrate */ /* parse the baudrate */
if(!COMMDCB_ParseInt(StrTail, &nValue)) if(!COMMDCB_ParseInt(StrTail, &nValue))
/* failure */
return FALSE; return FALSE;
switch(nValue) switch(nValue)
{ {
/* documented abbreviations */ /* documented abbreviations */
case 11: Dcb->BaudRate = 110; break; case 11:
case 15: Dcb->BaudRate = 150; break; Dcb->BaudRate = 110;
case 30: Dcb->BaudRate = 300; break; break;
case 60: Dcb->BaudRate = 600; break; case 15:
case 12: Dcb->BaudRate = 1200; break; Dcb->BaudRate = 150;
case 24: Dcb->BaudRate = 2400; break; break;
case 48: Dcb->BaudRate = 4800; break; case 30:
case 96: Dcb->BaudRate = 9600; break; Dcb->BaudRate = 300;
case 19: Dcb->BaudRate = 19200; break; break;
case 60:
Dcb->BaudRate = 600;
break;
case 12:
Dcb->BaudRate = 1200;
break;
case 24:
Dcb->BaudRate = 2400;
break;
case 48:
Dcb->BaudRate = 4800;
break;
case 96:
Dcb->BaudRate = 9600;
break;
case 19:
Dcb->BaudRate = 19200;
break;
/* literal value */ /* literal value */
default: Dcb->BaudRate = nValue; break; default:
Dcb->BaudRate = nValue;
break;
} }
/* if the stop bits haven't been specified explicitely */ /* if the stop bits haven't been specified explicitely */
if(!(*StopBitsSet)) if(!(*StopBitsSet))
{ {
/* default the stop bits to 2 for 110 baud */ /* default the stop bits to 2 for 110 baud */
if(Dcb->BaudRate == 110) Dcb->StopBits = TWOSTOPBITS; if(Dcb->BaudRate == 110)
Dcb->StopBits = TWOSTOPBITS;
/* else, default the stop bits to 1 */ /* else, default the stop bits to 1 */
else Dcb->StopBits = ONESTOPBIT; else
Dcb->StopBits = ONESTOPBIT;
} }
/* success */ /* success */
@ -325,11 +322,11 @@ COMMDCB_PARAM_HANDLER(data)
/* parse the data bits */ /* parse the data bits */
if(!COMMDCB_ParseInt(StrTail, &nValue)) if(!COMMDCB_ParseInt(StrTail, &nValue))
/* failure */
return FALSE; return FALSE;
/* value out of range: failure */ /* value out of range: failure */
if(nValue < 5 || nValue > 8) return FALSE; if(nValue < 5 || nValue > 8)
return FALSE;
/* success */ /* success */
Dcb->ByteSize = nValue; Dcb->ByteSize = nValue;
@ -341,8 +338,7 @@ COMMDCB_PARAM_HANDLER(dtr)
{ {
BOOL bRetVal; BOOL bRetVal;
ULONG_PTR nValue; ULONG_PTR nValue;
static COMMDCB_PARAM_STRFLAG a_DTRFlags[] = static COMMDCB_PARAM_STRFLAG a_DTRFlags[] = {
{
{ ROS_STRING_INITIALIZER(L"hs"), DTR_CONTROL_HANDSHAKE }, { ROS_STRING_INITIALIZER(L"hs"), DTR_CONTROL_HANDSHAKE },
{ ROS_STRING_INITIALIZER(L"off"), DTR_CONTROL_DISABLE }, { ROS_STRING_INITIALIZER(L"off"), DTR_CONTROL_DISABLE },
{ ROS_STRING_INITIALIZER(L"on"), DTR_CONTROL_ENABLE } { ROS_STRING_INITIALIZER(L"on"), DTR_CONTROL_ENABLE }
@ -352,16 +348,14 @@ COMMDCB_PARAM_HANDLER(dtr)
(void)StopBitsSet; (void)StopBitsSet;
/* parse the flag */ /* parse the flag */
bRetVal = COMMDCB_ParseStrFlag bRetVal = COMMDCB_ParseStrFlag(StrTail,
(
StrTail,
a_DTRFlags, a_DTRFlags,
sizeof(a_DTRFlags) / sizeof(a_DTRFlags[0]), sizeof(a_DTRFlags) / sizeof(a_DTRFlags[0]),
&nValue &nValue);
);
/* failure */ /* failure */
if(!bRetVal) return FALSE; if(!bRetVal)
return FALSE;
/* success */ /* success */
Dcb->fDtrControl = nValue; Dcb->fDtrControl = nValue;
@ -378,7 +372,6 @@ COMMDCB_PARAM_HANDLER(idsr)
/* parse the flag */ /* parse the flag */
if(!COMMDCB_ParseBool(StrTail, &bValue)) if(!COMMDCB_ParseBool(StrTail, &bValue))
/* failure */
return FALSE; return FALSE;
/* success */ /* success */
@ -396,7 +389,6 @@ COMMDCB_PARAM_HANDLER(octs)
/* parse the flag */ /* parse the flag */
if(!COMMDCB_ParseBool(StrTail, &bValue)) if(!COMMDCB_ParseBool(StrTail, &bValue))
/* failure */
return FALSE; return FALSE;
/* success */ /* success */
@ -414,7 +406,6 @@ COMMDCB_PARAM_HANDLER(odsr)
/* parse the flag */ /* parse the flag */
if(!COMMDCB_ParseBool(StrTail, &bValue)) if(!COMMDCB_ParseBool(StrTail, &bValue))
/* failure */
return FALSE; return FALSE;
/* success */ /* success */
@ -427,8 +418,7 @@ COMMDCB_PARAM_HANDLER(parity)
{ {
BOOL bRetVal; BOOL bRetVal;
ULONG_PTR nValue; ULONG_PTR nValue;
static COMMDCB_PARAM_CHARFLAG a_ParityFlags[] = static COMMDCB_PARAM_CHARFLAG a_ParityFlags[] = {
{
{ L'e', EVENPARITY }, { L'e', EVENPARITY },
{ L'm', MARKPARITY }, { L'm', MARKPARITY },
{ L'n', NOPARITY }, { L'n', NOPARITY },
@ -440,16 +430,14 @@ COMMDCB_PARAM_HANDLER(parity)
(void)StopBitsSet; (void)StopBitsSet;
/* parse the flag */ /* parse the flag */
bRetVal = COMMDCB_ParseCharFlag bRetVal = COMMDCB_ParseCharFlag(StrTail,
(
StrTail,
a_ParityFlags, a_ParityFlags,
sizeof(a_ParityFlags) / sizeof(a_ParityFlags[0]), sizeof(a_ParityFlags) / sizeof(a_ParityFlags[0]),
&nValue &nValue);
);
/* failure */ /* failure */
if(!bRetVal) return FALSE; if(!bRetVal)
return FALSE;
/* success */ /* success */
Dcb->Parity = nValue; Dcb->Parity = nValue;
@ -461,8 +449,7 @@ COMMDCB_PARAM_HANDLER(rts)
{ {
DWORD nRetVal; DWORD nRetVal;
ULONG_PTR nValue; ULONG_PTR nValue;
static COMMDCB_PARAM_STRFLAG a_RTSFlags[] = static COMMDCB_PARAM_STRFLAG a_RTSFlags[] = {
{
{ ROS_STRING_INITIALIZER(L"hs"), RTS_CONTROL_HANDSHAKE }, { ROS_STRING_INITIALIZER(L"hs"), RTS_CONTROL_HANDSHAKE },
{ ROS_STRING_INITIALIZER(L"off"), RTS_CONTROL_DISABLE }, { ROS_STRING_INITIALIZER(L"off"), RTS_CONTROL_DISABLE },
{ ROS_STRING_INITIALIZER(L"on"), RTS_CONTROL_ENABLE }, { ROS_STRING_INITIALIZER(L"on"), RTS_CONTROL_ENABLE },
@ -473,16 +460,14 @@ COMMDCB_PARAM_HANDLER(rts)
(void)StopBitsSet; (void)StopBitsSet;
/* parse the flag */ /* parse the flag */
nRetVal = COMMDCB_ParseStrFlag nRetVal = COMMDCB_ParseStrFlag(StrTail,
(
StrTail,
a_RTSFlags, a_RTSFlags,
sizeof(a_RTSFlags) / sizeof(a_RTSFlags[0]), sizeof(a_RTSFlags) / sizeof(a_RTSFlags[0]),
&nValue &nValue);
);
/* failure */ /* failure */
if(!nRetVal) return FALSE; if(!nRetVal)
return FALSE;
/* success */ /* success */
Dcb->fRtsControl = nValue; Dcb->fRtsControl = nValue;
@ -494,8 +479,7 @@ COMMDCB_PARAM_HANDLER(stop)
{ {
BOOL bRetVal; BOOL bRetVal;
ULONG_PTR nValue; ULONG_PTR nValue;
static COMMDCB_PARAM_STRFLAG a_StopFlags[] = static COMMDCB_PARAM_STRFLAG a_StopFlags[] = {
{
{ ROS_STRING_INITIALIZER(L"1"), ONESTOPBIT }, { ROS_STRING_INITIALIZER(L"1"), ONESTOPBIT },
{ ROS_STRING_INITIALIZER(L"1.5"), ONE5STOPBITS }, { ROS_STRING_INITIALIZER(L"1.5"), ONE5STOPBITS },
{ ROS_STRING_INITIALIZER(L"2"), TWOSTOPBITS } { ROS_STRING_INITIALIZER(L"2"), TWOSTOPBITS }
@ -504,16 +488,14 @@ COMMDCB_PARAM_HANDLER(stop)
(void)Timeouts; (void)Timeouts;
/* parse the flag */ /* parse the flag */
bRetVal = COMMDCB_ParseStrFlag bRetVal = COMMDCB_ParseStrFlag(StrTail,
(
StrTail,
a_StopFlags, a_StopFlags,
sizeof(a_StopFlags) / sizeof(a_StopFlags[0]), sizeof(a_StopFlags) / sizeof(a_StopFlags[0]),
&nValue &nValue);
);
/* failure */ /* failure */
if(!bRetVal) return FALSE; if(!bRetVal)
return FALSE;
/* tell the baud= handler that the stop bits have been specified explicitely */ /* tell the baud= handler that the stop bits have been specified explicitely */
*StopBitsSet = TRUE; *StopBitsSet = TRUE;
@ -533,7 +515,6 @@ COMMDCB_PARAM_HANDLER(to)
/* parse the flag */ /* parse the flag */
if(!COMMDCB_ParseBool(StrTail, &bValue)) if(!COMMDCB_ParseBool(StrTail, &bValue))
/* failure */
return FALSE; return FALSE;
/* for BuildCommDCB(), Timeouts is NULL */ /* for BuildCommDCB(), Timeouts is NULL */
@ -545,10 +526,16 @@ COMMDCB_PARAM_HANDLER(to)
Timeouts->ReadTotalTimeoutConstant = 0; Timeouts->ReadTotalTimeoutConstant = 0;
Timeouts->WriteTotalTimeoutMultiplier = 0; Timeouts->WriteTotalTimeoutMultiplier = 0;
if(bValue)
{
/* timeout */ /* timeout */
if(bValue) Timeouts->WriteTotalTimeoutConstant = 60000; Timeouts->WriteTotalTimeoutConstant = 60000;
}
else
{
/* no timeout */ /* no timeout */
else Timeouts->WriteTotalTimeoutConstant = 0; Timeouts->WriteTotalTimeoutConstant = 0;
}
} }
/* success */ /* success */
@ -565,13 +552,18 @@ COMMDCB_PARAM_HANDLER(xon)
/* parse the flag */ /* parse the flag */
if(!COMMDCB_ParseBool(StrTail, &bValue)) if(!COMMDCB_ParseBool(StrTail, &bValue))
/* failure */
return FALSE; return FALSE;
if(bValue)
{
/* XON/XOFF */ /* XON/XOFF */
if(bValue) Dcb->fInX = Dcb->fOutX = TRUE; Dcb->fInX = Dcb->fOutX = TRUE;
}
else
{
/* no XON/XOFF */ /* no XON/XOFF */
else Dcb->fInX = Dcb->fOutX = FALSE; Dcb->fInX = Dcb->fOutX = FALSE;
}
/* success */ /* success */
return TRUE; return TRUE;
@ -580,7 +572,7 @@ COMMDCB_PARAM_HANDLER(xon)
/* FUNCTIONS */ /* FUNCTIONS */
#define COMMDCB_PARAM(__P__) \ #define COMMDCB_PARAM(__P__) \
{ \ { \
ROS_STRING_INITIALIZER(_L(#__P__)), \ ROS_STRING_INITIALIZER( L""#__P__ ), \
(ULONG_PTR)&COMMDCB_ ## __P__ ## Param \ (ULONG_PTR)&COMMDCB_ ## __P__ ## Param \
} }
@ -589,38 +581,33 @@ COMMDCB_PARAM_HANDLER(xon)
*/ */
BOOL BOOL
STDCALL STDCALL
BuildCommDCBAndTimeoutsW BuildCommDCBAndTimeoutsW(LPCWSTR lpDef,
(
LPCWSTR lpDef,
LPDCB lpDCB, LPDCB lpDCB,
LPCOMMTIMEOUTS lpCommTimeouts LPCOMMTIMEOUTS lpCommTimeouts)
)
{ {
/* tell the baud= handler that the stop bits should be defaulted */ /* tell the baud= handler that the stop bits should be defaulted */
BOOL bStopBitsSet = FALSE; BOOL bStopBitsSet = FALSE;
/* parameter validation */ /* parameter validation */
if(lpDCB->DCBlength != sizeof(DCB)) goto InvalidParam; if(lpDCB->DCBlength != sizeof(DCB))
goto InvalidParam;
/* set defaults */ /* set defaults */
lpDCB->StopBits = ONESTOPBIT; lpDCB->StopBits = ONESTOPBIT;
/* /*
The documentation for MODE says that data= defaults to 7, but BuildCommDCB * The documentation for MODE says that data= defaults to 7, but BuildCommDCB
doesn't seem to set it * doesn't seem to set it
*/ */
/* lpDCB->ByteSize = 7; */ /* lpDCB->ByteSize = 7; */
/* skip COMx[n] */ /* skip COMx[n] */
if if(lpDef[0] &&
(
lpDef[0] &&
towupper(lpDef[0]) == L'C' && towupper(lpDef[0]) == L'C' &&
lpDef[1] && lpDef[1] &&
towupper(lpDef[1]) == L'O' && towupper(lpDef[1]) == L'O' &&
lpDef[2] && lpDef[2] &&
towupper(lpDef[2]) == L'M' towupper(lpDef[2]) == L'M')
)
{ {
DWORD nDummy; DWORD nDummy;
@ -628,23 +615,26 @@ BuildCommDCBAndTimeoutsW
lpDef += 3; lpDef += 3;
/* premature end of string */ /* premature end of string */
if(!lpDef[0]) goto InvalidParam; if(!lpDef[0])
goto InvalidParam;
/* skip "x" */ /* skip "x" */
if(!COMMDCB_ParseInt((LPWSTR *)&lpDef, &nDummy)) goto InvalidParam; if(!COMMDCB_ParseInt((LPWSTR *)&lpDef, &nDummy))
goto InvalidParam;
/* skip ":" */ /* skip ":" */
if(lpDef[0] == L':') ++ lpDef; if(lpDef[0] == L':')
lpDef++;
} }
/* skip leading whitespace */ /* skip leading whitespace */
while(lpDef[0] && iswspace(lpDef[0])) ++ lpDef; while(lpDef[0] && iswspace(lpDef[0]))
lpDef++;
/* repeat until the end of the string */ /* repeat until the end of the string */
while(lpDef[0]) while(lpDef[0])
{ {
static COMMDCB_PARAM_STRFLAG a_Params[] = static COMMDCB_PARAM_STRFLAG a_Params[] = {
{
COMMDCB_PARAM(baud), COMMDCB_PARAM(baud),
COMMDCB_PARAM(data), COMMDCB_PARAM(data),
COMMDCB_PARAM(dtr), COMMDCB_PARAM(dtr),
@ -663,10 +653,12 @@ BuildCommDCBAndTimeoutsW
LPWSTR pwcPrevTail = (LPWSTR)lpDef; LPWSTR pwcPrevTail = (LPWSTR)lpDef;
/* get the parameter */ /* get the parameter */
while(lpDef[0] && lpDef[0] != L'=') ++ lpDef; while(lpDef[0] && lpDef[0] != L'=')
lpDef++;
/* premature end of string */ /* premature end of string */
if(!lpDef[0]) goto InvalidParam; if(!lpDef[0])
goto InvalidParam;
/* build the parameter's UNICODE_STRING */ /* build the parameter's UNICODE_STRING */
wstrParam.Buffer = pwcPrevTail; wstrParam.Buffer = pwcPrevTail;
@ -674,34 +666,31 @@ BuildCommDCBAndTimeoutsW
wstrParam.MaximumLength = wstrParam.Length; wstrParam.MaximumLength = wstrParam.Length;
/* skip the "=" */ /* skip the "=" */
++ lpDef; lpDef++;
/* lookup the callback for the parameter */ /* lookup the callback for the parameter */
bRetVal = COMMDCB_LookupStrFlag bRetVal = COMMDCB_LookupStrFlag(&wstrParam,
(
&wstrParam,
a_Params, a_Params,
sizeof(a_Params) / sizeof(a_Params[0]), sizeof(a_Params) / sizeof(a_Params[0]),
(ULONG_PTR *)&pCallback (ULONG_PTR *)&pCallback);
);
/* invalid parameter */ /* invalid parameter */
if(!bRetVal) goto InvalidParam; if(!bRetVal)
goto InvalidParam;
/* call the callback to parse the parameter's argument */ /* call the callback to parse the parameter's argument */
if(!pCallback(lpDCB, lpCommTimeouts, &bStopBitsSet, (LPWSTR *)&lpDef)) if(!pCallback(lpDCB, lpCommTimeouts, &bStopBitsSet, (LPWSTR *)&lpDef))
/* failure */
goto InvalidParam; goto InvalidParam;
/* skip trailing whitespace */ /* skip trailing whitespace */
while(lpDef[0] && iswspace(lpDef[0])) ++ lpDef; while(lpDef[0] && iswspace(lpDef[0]))
lpDef++;
} }
/* success */ /* success */
return TRUE; return TRUE;
InvalidParam: InvalidParam:
/* failure */
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
} }
@ -712,20 +701,22 @@ InvalidParam:
*/ */
BOOL BOOL
STDCALL STDCALL
BuildCommDCBAndTimeoutsA(LPCSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts) BuildCommDCBAndTimeoutsA(LPCSTR lpDef,
LPDCB lpDCB,
LPCOMMTIMEOUTS lpCommTimeouts)
{ {
NTSTATUS nErrCode; NTSTATUS Status;
BOOL bRetVal; BOOL bRetVal;
ANSI_STRING strDef; ANSI_STRING strDef;
UNICODE_STRING wstrDef; UNICODE_STRING wstrDef;
RtlInitAnsiString(&strDef, (LPSTR)lpDef); RtlInitAnsiString(&strDef, (LPSTR)lpDef);
nErrCode = RtlAnsiStringToUnicodeString(&wstrDef, &strDef, TRUE); Status = RtlAnsiStringToUnicodeString(&wstrDef, &strDef, TRUE);
if(!NT_SUCCESS(nErrCode)) if(!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus(nErrCode); SetLastErrorByStatus(Status);
return FALSE; return FALSE;
} }