fixed failure to properly identify styled files with no 'STYL' data, changed plain text identify to search first 64 bytes for unsupported characters
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2290 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -287,20 +287,25 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header,
|
|||||||
if (seekresult < pos)
|
if (seekresult < pos)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// check the STYL header
|
// check the STYL header (not all STXT files have this)
|
||||||
|
ssize_t read = 0;
|
||||||
TranslatorStyledTextStyleHeader stlheader;
|
TranslatorStyledTextStyleHeader stlheader;
|
||||||
if (inSource->Read(buffer, 20) != 20)
|
read = inSource->Read(buffer, 20);
|
||||||
|
if (read != 20 && read != 0)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
memcpy(&stlheader, buffer, 20);
|
// If there is a STYL header
|
||||||
if (swap_data(B_UINT32_TYPE, &stlheader, 20,
|
if (read == 20) {
|
||||||
B_SWAP_BENDIAN_TO_HOST) != B_OK)
|
memcpy(&stlheader, buffer, 20);
|
||||||
return B_ERROR;
|
if (swap_data(B_UINT32_TYPE, &stlheader, 20,
|
||||||
|
B_SWAP_BENDIAN_TO_HOST) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
if (stlheader.header.magic != 'STYL' ||
|
if (stlheader.header.magic != 'STYL' ||
|
||||||
stlheader.header.header_size !=
|
stlheader.header.header_size !=
|
||||||
sizeof(TranslatorStyledTextStyleHeader))
|
sizeof(TranslatorStyledTextStyleHeader))
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
}
|
||||||
|
|
||||||
// return information about the data in the stream
|
// return information about the data in the stream
|
||||||
outInfo->type = B_STYLED_TEXT_FORMAT;
|
outInfo->type = B_STYLED_TEXT_FORMAT;
|
||||||
@@ -313,6 +318,44 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// data must be able to hold at least 64 bytes of data
|
||||||
|
status_t
|
||||||
|
identify_txt_header(uint8 *data, int32 nread,
|
||||||
|
BPositionIO *inSource, translator_info *outInfo, uint32 outType)
|
||||||
|
{
|
||||||
|
uint8 ch;
|
||||||
|
ssize_t readlater = 0;
|
||||||
|
readlater = inSource->Read(data + nread, 64 - nread);
|
||||||
|
if (readlater < 0)
|
||||||
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
|
nread += readlater;
|
||||||
|
for (int32 i = 0; i < nread; i++) {
|
||||||
|
ch = data[i];
|
||||||
|
// if any null characters or
|
||||||
|
// control characters (other than a few)
|
||||||
|
// are found, abort, as the data is
|
||||||
|
// probably not plain text
|
||||||
|
if (ch < 32 &&
|
||||||
|
ch != 0x08 && // backspace
|
||||||
|
ch != 0x09 && // tab
|
||||||
|
ch != 0x0A && // line feed
|
||||||
|
ch != 0x0C && // form feed
|
||||||
|
ch != 0x0D) // carriage return
|
||||||
|
return B_NO_TRANSLATOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return information about the data in the stream
|
||||||
|
outInfo->type = B_TRANSLATOR_TEXT;
|
||||||
|
outInfo->group = B_TRANSLATOR_TEXT;
|
||||||
|
outInfo->quality = TEXT_IN_QUALITY;
|
||||||
|
outInfo->capability = TEXT_IN_CAPABILITY;
|
||||||
|
strcpy(outInfo->name, "Plain text file");
|
||||||
|
strcpy(outInfo->MIME, "text/plain");
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// Identify
|
// Identify
|
||||||
//
|
//
|
||||||
@@ -350,34 +393,6 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header,
|
|||||||
// B_OK, if this translator understand the data and there were
|
// B_OK, if this translator understand the data and there were
|
||||||
// no errors found
|
// no errors found
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
status_t
|
|
||||||
identify_txt_header(const uint8 *data, int32 nread,
|
|
||||||
BPositionIO *inSource, translator_info *outInfo, uint32 outType)
|
|
||||||
{
|
|
||||||
uint8 ch;
|
|
||||||
for (int32 i = 0; i < nread; i++) {
|
|
||||||
ch = data[i];
|
|
||||||
// if any null characters or
|
|
||||||
// control characters (other than a few)
|
|
||||||
// are found, abort, as the data is
|
|
||||||
// probably not plain text
|
|
||||||
if (ch < 32 && ch != '\n' &&
|
|
||||||
ch != '\r' && ch != '\t' &&
|
|
||||||
ch != '\f')
|
|
||||||
return B_NO_TRANSLATOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return information about the data in the stream
|
|
||||||
outInfo->type = B_TRANSLATOR_TEXT;
|
|
||||||
outInfo->group = B_TRANSLATOR_TEXT;
|
|
||||||
outInfo->quality = TEXT_IN_QUALITY;
|
|
||||||
outInfo->capability = TEXT_IN_CAPABILITY;
|
|
||||||
strcpy(outInfo->name, "Plain text file");
|
|
||||||
strcpy(outInfo->MIME, "text/plain");
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
STXTTranslator::Identify(BPositionIO *inSource,
|
STXTTranslator::Identify(BPositionIO *inSource,
|
||||||
const translation_format *inFormat, BMessage *ioExtension,
|
const translation_format *inFormat, BMessage *ioExtension,
|
||||||
@@ -388,7 +403,7 @@ STXTTranslator::Identify(BPositionIO *inSource,
|
|||||||
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
|
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
uint8 buffer[16];
|
uint8 buffer[64];
|
||||||
status_t nread = 0;
|
status_t nread = 0;
|
||||||
// Read in the header to determine
|
// Read in the header to determine
|
||||||
// if the data is supported
|
// if the data is supported
|
||||||
|
|||||||
Reference in New Issue
Block a user