Commit e5df1b2e authored by Fabian Maurer's avatar Fabian Maurer Committed by Alexandre Julliard

coml2: Move PropStgNameToFmtId from ole32.

parent ce60cfeb
......@@ -14,7 +14,7 @@
@ stdcall FmtIdToPropStgName(ptr wstr)
@ stdcall GetConvertStg(ptr)
@ stdcall GetHGlobalFromILockBytes(ptr ptr)
@ stub PropStgNameToFmtId
@ stdcall PropStgNameToFmtId(wstr ptr)
@ stdcall ReadClassStg(ptr ptr)
@ stdcall ReadClassStm(ptr ptr)
@ stub StgCreateDocfile
......
......@@ -122,3 +122,78 @@ HRESULT WINAPI FmtIdToPropStgName(const FMTID *rfmtid, LPOLESTR str)
TRACE("returning %s\n", debugstr_w(str));
return S_OK;
}
/***********************************************************************
* PropStgNameToFmtId [coml2.@]
*/
HRESULT WINAPI PropStgNameToFmtId(const LPOLESTR str, FMTID *rfmtid)
{
HRESULT hr = STG_E_INVALIDNAME;
TRACE("%s, %p\n", debugstr_w(str), rfmtid);
if (!rfmtid) return E_INVALIDARG;
if (!str) return STG_E_INVALIDNAME;
if (!lstrcmpiW(str, szDocSummaryInfo))
{
*rfmtid = FMTID_DocSummaryInformation;
hr = S_OK;
}
else if (!lstrcmpiW(str, szSummaryInfo))
{
*rfmtid = FMTID_SummaryInformation;
hr = S_OK;
}
else
{
ULONG bits;
BYTE *fmtptr = (BYTE *)rfmtid - 1;
const WCHAR *pstr = str;
memset(rfmtid, 0, sizeof(*rfmtid));
for (bits = 0; bits < sizeof(FMTID) * BITS_PER_BYTE;
bits += BITS_IN_CHARMASK)
{
ULONG bitsUsed = bits % BITS_PER_BYTE, bitsStored;
WCHAR wc;
if (bitsUsed == 0)
fmtptr++;
wc = *++pstr - 'A';
if (wc > NUM_ALPHA_CHARS)
{
wc += 'A' - 'a';
if (wc > NUM_ALPHA_CHARS)
{
wc += 'a' - '0' + NUM_ALPHA_CHARS;
if (wc > CHARMASK)
{
WARN("invalid character (%d)\n", *pstr);
goto end;
}
}
}
*fmtptr |= wc << bitsUsed;
bitsStored = min(BITS_PER_BYTE - bitsUsed, BITS_IN_CHARMASK);
if (bitsStored < BITS_IN_CHARMASK)
{
wc >>= BITS_PER_BYTE - bitsUsed;
if (bits + bitsStored == sizeof(FMTID) * BITS_PER_BYTE)
{
if (wc != 0)
{
WARN("extra bits\n");
goto end;
}
break;
}
fmtptr++;
*fmtptr |= (BYTE)wc;
}
}
hr = S_OK;
}
end:
return hr;
}
......@@ -2994,100 +2994,6 @@ static const IPropertyStorageVtbl IPropertyStorage_Vtbl =
IPropertyStorage_fnStat,
};
/***********************************************************************
* Format ID <-> name conversion
*/
static const WCHAR szSummaryInfo[] = L"\5SummaryInformation";
static const WCHAR szDocSummaryInfo[] = L"\5DocumentSummaryInformation";
#define BITS_PER_BYTE 8
#define CHARMASK 0x1f
#define BITS_IN_CHARMASK 5
#define NUM_ALPHA_CHARS 26
/***********************************************************************
* PropStgNameToFmtId [ole32.@]
* Returns the format ID corresponding to the given name.
* PARAMS
* str [I] Storage name to convert to a format ID.
* rfmtid [O] Format ID corresponding to str.
*
* RETURNS
* E_INVALIDARG if rfmtid or str is NULL or if str can't be converted to
* a format ID, S_OK otherwise.
*/
HRESULT WINAPI PropStgNameToFmtId(const LPOLESTR str, FMTID *rfmtid)
{
HRESULT hr = STG_E_INVALIDNAME;
TRACE("%s, %p\n", debugstr_w(str), rfmtid);
if (!rfmtid) return E_INVALIDARG;
if (!str) return STG_E_INVALIDNAME;
if (!lstrcmpiW(str, szDocSummaryInfo))
{
*rfmtid = FMTID_DocSummaryInformation;
hr = S_OK;
}
else if (!lstrcmpiW(str, szSummaryInfo))
{
*rfmtid = FMTID_SummaryInformation;
hr = S_OK;
}
else
{
ULONG bits;
BYTE *fmtptr = (BYTE *)rfmtid - 1;
const WCHAR *pstr = str;
memset(rfmtid, 0, sizeof(*rfmtid));
for (bits = 0; bits < sizeof(FMTID) * BITS_PER_BYTE;
bits += BITS_IN_CHARMASK)
{
ULONG bitsUsed = bits % BITS_PER_BYTE, bitsStored;
WCHAR wc;
if (bitsUsed == 0)
fmtptr++;
wc = *++pstr - 'A';
if (wc > NUM_ALPHA_CHARS)
{
wc += 'A' - 'a';
if (wc > NUM_ALPHA_CHARS)
{
wc += 'a' - '0' + NUM_ALPHA_CHARS;
if (wc > CHARMASK)
{
WARN("invalid character (%d)\n", *pstr);
goto end;
}
}
}
*fmtptr |= wc << bitsUsed;
bitsStored = min(BITS_PER_BYTE - bitsUsed, BITS_IN_CHARMASK);
if (bitsStored < BITS_IN_CHARMASK)
{
wc >>= BITS_PER_BYTE - bitsUsed;
if (bits + bitsStored == sizeof(FMTID) * BITS_PER_BYTE)
{
if (wc != 0)
{
WARN("extra bits\n");
goto end;
}
break;
}
fmtptr++;
*fmtptr |= (BYTE)wc;
}
}
hr = S_OK;
}
end:
return hr;
}
#ifdef __i386__ /* thiscall functions are i386-specific */
#define DEFINE_STDCALL_WRAPPER(num,func,args) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment