@@ -335,12 +335,18 @@ int EBook_CHM::findStringInQuotes( const QString& tag, int offset, QString& valu
335335 int qbegin = tag.indexOf ( ' "' , offset );
336336
337337 if ( qbegin == -1 )
338- qFatal ( " EBook_CHMImpl::findStringInQuotes: cannot find first quote in <param> tag: '%s'" , qPrintable ( tag ) );
338+ {
339+ qWarning ( " EBook_CHMImpl::findStringInQuotes: cannot find first quote in <param> tag: '%s'" , qPrintable ( tag ) );
340+ return -1 ;
341+ }
339342
340343 int qend = firstquote ? tag.indexOf ( ' "' , qbegin + 1 ) : tag.lastIndexOf ( ' "' );
341344
342345 if ( qend == -1 || qend <= qbegin )
343- qFatal ( " EBook_CHMImpl::findStringInQuotes: cannot find last quote in <param> tag: '%s'" , qPrintable ( tag ) );
346+ {
347+ qWarning ( " EBook_CHMImpl::findStringInQuotes: cannot find last quote in <param> tag: '%s'" , qPrintable ( tag ) );
348+ return -1 ;
349+ }
344350
345351 // If we do not need to decode HTML entities, just return.
346352 if ( decodeentities )
@@ -426,13 +432,19 @@ bool EBook_CHM::parseFileAndFillArray( const QString& file, QList< ParsedEntry >
426432 // find where quote ends, either by another quote, or by '>' symbol (some people don't know HTML)
427433 int nextpos = src.indexOf ( src[i], i + 1 );
428434
429- if ( nextpos == -1 && ( nextpos = src. indexOf ( ' > ' , i + 1 ) ) == - 1 )
435+ if ( nextpos == -1 )
430436 {
431- qWarning ( " EBook_CHMImpl::ParseHhcAndFillTree: corrupted TOC: %s" , qPrintable ( src.mid ( i ) ) );
432- return false ;
437+ if ( ( nextpos = src.indexOf ( ' >' , i + 1 ) ) == -1 )
438+ {
439+ qWarning ( " EBook_CHMImpl::ParseHhcAndFillTree: corrupted TOC: %s" , qPrintable ( src.mid ( i ) ) );
440+ return false ;
441+ }
442+ else
443+ // so that we can correctly find next '>' symbol and break in next loop
444+ i = nextpos - 1 ;
433445 }
434-
435- i = nextpos;
446+ else
447+ i = nextpos;
436448 }
437449 else if ( src[i] == ' >' )
438450 break ;
@@ -497,17 +509,28 @@ bool EBook_CHM::parseFileAndFillArray( const QString& file, QList< ParsedEntry >
497509 QString pname, pvalue;
498510
499511 if ( ( offset = tag.indexOf ( name_pattern, 0 , Qt::CaseInsensitive ) ) == -1 )
500- qFatal ( " EBook_CHMImpl::ParseAndFillTopicsTree: bad <param> tag '%s': no name=\n " , qPrintable ( tag ) );
512+ {
513+ qWarning ( " EBook_CHMImpl::ParseAndFillTopicsTree: bad <param> tag '%s': no name=\n " , qPrintable ( tag ) );
514+ continue ;
515+ }
501516
502517 // offset+5 skips 'name='
503518 offset = findStringInQuotes ( tag, offset + name_pattern.length (), pname, true , false );
519+ if ( offset == -1 )
520+ continue ;
504521 pname = pname.toLower ();
505522
506523 if ( ( offset = tag.indexOf ( value_pattern, offset, Qt::CaseInsensitive ) ) == -1 )
507- qFatal ( " EBook_CHMImpl::ParseAndFillTopicsTree: bad <param> tag '%s': no value=\n " , qPrintable ( tag ) );
524+ {
525+ qWarning ( " EBook_CHMImpl::ParseAndFillTopicsTree: bad <param> tag '%s': no value=\n " , qPrintable ( tag ) );
526+ continue ;
527+ }
508528
509529 // offset+6 skips 'value='
510- findStringInQuotes ( tag, offset + value_pattern.length (), pvalue, false , true );
530+ offset = findStringInQuotes ( tag, offset + value_pattern.length (), pvalue, false , true );
531+ qWarning ( " 11111: value=%s" , qUtf8Printable ( pvalue ) );
532+ if ( offset == -1 )
533+ continue ;
511534
512535 // DEBUGPARSER(("<param>: name '%s', value '%s'", qPrintable( pname ), qPrintable( pvalue )));
513536
@@ -562,7 +585,10 @@ bool EBook_CHM::parseFileAndFillArray( const QString& file, QList< ParsedEntry >
562585 {
563586 // Fix for buggy help files
564587 if ( ++indent >= MAX_NEST_DEPTH )
565- qFatal ( " EBook_CHMImpl::ParseAndFillTopicsTree: max nest depth (%d) is reached, error in help file" , MAX_NEST_DEPTH );
588+ {
589+ qWarning ( " EBook_CHMImpl::ParseAndFillTopicsTree: max nest depth (%d) is reached, error in help file" , MAX_NEST_DEPTH );
590+ return false ;
591+ }
566592
567593 DEBUGPARSER ( ( " <ul>: new intent is %d\n " , indent - root_indent_offset ) );
568594 }
@@ -596,7 +622,7 @@ bool EBook_CHM::hasFile( const QString& fileName ) const
596622 chmUnitInfo ui;
597623
598624 return m_chmFile != NULL
599- && ::chm_resolve_object ( m_chmFile, qPrintable ( fileName ), &ui ) ==
625+ && ::chm_resolve_object ( m_chmFile, qUtf8Printable ( fileName ), &ui ) ==
600626 CHM_RESOLVE_SUCCESS ;
601627}
602628
@@ -836,7 +862,7 @@ bool EBook_CHM::guessTextEncoding()
836862{
837863 if ( !m_detectedLCID )
838864 {
839- qFatal ( " Could not detect LCID" );
865+ qWarning ( " Could not detect LCID" );
840866 return false ;
841867 }
842868
0 commit comments