mime.types entries with all fields on same line parsed correctly

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1943 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-03-17 16:25:49 +00:00
parent da7b3583d8
commit 22b4634c61

View File

@ -492,6 +492,16 @@ wxMimeTypesManager::GetFileTypeFromMimeType(const wxString& mimeType)
return m_impl->GetFileTypeFromMimeType(mimeType); return m_impl->GetFileTypeFromMimeType(mimeType);
} }
void wxMimeTypesManager::ReadMailcap(const wxString& filename)
{
m_impl->ReadMailcap(filename);
}
void wxMimeTypesManager::ReadMimeTypes(const wxString& filename)
{
m_impl->ReadMimeTypes(filename);
}
// ============================================================================ // ============================================================================
// real (OS specific) implementation // real (OS specific) implementation
// ============================================================================ // ============================================================================
@ -889,17 +899,27 @@ void wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
wxString strMimeType, strDesc, strExtensions; wxString strMimeType, strDesc, strExtensions;
size_t nLineCount = file.GetLineCount(); size_t nLineCount = file.GetLineCount();
const char *pc = NULL;
for ( size_t nLine = 0; nLine < nLineCount; nLine++ ) { for ( size_t nLine = 0; nLine < nLineCount; nLine++ ) {
// now we're at the start of the line if ( pc == NULL ) {
const char *pc = file[nLine].c_str(); // now we're at the start of the line
pc = file[nLine].c_str();
}
else {
// we didn't finish with the previous line yet
nLine--;
}
// skip whitespace // skip whitespace
while ( isspace(*pc) ) while ( isspace(*pc) )
pc++; pc++;
// comment? // comment?
if ( *pc == '#' ) if ( *pc == '#' ) {
// skip the whole line
pc = NULL;
continue; continue;
}
// detect file format // detect file format
const char *pEqualSign = strchr(pc, '='); const char *pEqualSign = strchr(pc, '=');
@ -944,7 +964,7 @@ void wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
} }
} }
else { else {
// unquoted stringends at the first space // unquoted string ends at the first space
for ( pEnd = pc; !isspace(*pEnd); pEnd++ ) for ( pEnd = pc; !isspace(*pEnd); pEnd++ )
; ;
} }
@ -952,8 +972,7 @@ void wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
// now we have the RHS (field value) // now we have the RHS (field value)
wxString strRHS(pc, pEnd - pc); wxString strRHS(pc, pEnd - pc);
// check that it's more or less what we're waiting for, i.e. that // check what follows this entry
// only '\' is left on the line
if ( *pEnd == '"' ) { if ( *pEnd == '"' ) {
// skip this quote // skip this quote
pEnd++; pEnd++;
@ -962,14 +981,13 @@ void wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
for ( pc = pEnd; isspace(*pc); pc++ ) for ( pc = pEnd; isspace(*pc); pc++ )
; ;
// only '\\' may be left on the line normally // if there is something left, it may be either a '\\' to continue
bool entryEnded = *pc == '\0'; // the line or the next field of the same entry
if ( !entryEnded && ((*pc != '\\') || (*++pc != '\0')) ) { bool entryEnded = *pc == '\0',
wxLogWarning(_("Mime.types file %s, line %d: extra characters " nextFieldOnSameLine = FALSE;
"after the field value ignored."), if ( !entryEnded ) {
strFileName.c_str(), nLine + 1); nextFieldOnSameLine = ((*pc != '\\') || (pc[1] != '\0'));
} }
// if there is a trailing backslash entryEnded = FALSE
// now see what we got // now see what we got
if ( strLHS == "type" ) { if ( strLHS == "type" ) {
@ -987,8 +1005,13 @@ void wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
} }
if ( !entryEnded ) { if ( !entryEnded ) {
// as we don't reset strMimeType, the next line in this entry if ( !nextFieldOnSameLine )
pc = NULL;
//else: don't reset it
// as we don't reset strMimeType, the next field in this entry
// will be interpreted correctly. // will be interpreted correctly.
continue; continue;
} }
} }
@ -1018,6 +1041,9 @@ void wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
} }
m_aExtensions[index] += strExtensions; m_aExtensions[index] += strExtensions;
} }
// finished with this line
pc = NULL;
} }
// check our data integriry // check our data integriry