/* * Xailer source code: * * XHtmlHelp.prg * Xailer HTML Help System * * Copyright 2022 Jose F. Gimenez * Copyright 2022 Xailer.com * All rights reserved * * Formato de los archivos .xhlp - Cabecera (30 bytes): "Xailer HTML Help System v1.00" + Chr( 26 ) - Bloques de informacion: - L2Bin( ) - Chr( ) - HB_ZCompress( ) Segun el tipo de bloque, pueden ser: 0: Informacion de la ayuda - Es un texto libre con el copyright, autor, version, etc. 1: TOC (Tabla de contenidos). Cada entrada tiene este formato: - L2Bin( ) - - + "|" + + CRLF 2: Indice (por determinar) 3: Keywords (por determinar) 4: CSS ... NOTA: El ultimo bloque es L2Bin( 0 ) y sin tipo ni contenido - Bloques de ayudas (variable) - Todos los bloques van uno a continuacion del otro, sin separadores, y comprimidos con HB_ZCompress( ) * .xhlp file format - Header (30 bytes): "Xailer HTML Help System v1.00" + Chr( 26 ) - Blocks of information: - L2Bin( ) - Chr( ) - HB_ZCompress( ) Acording to the block type, it could be: 0: Help file information - Free text with copyright info, author, version, etc. 1: TOC (Table of contents). Every element has this format: - L2Bin( ) - - + "|" + + CRLF 2: Index (to be specified) 3: Keywords (to be specified) 4: CSS ... NOTA: The last block is L2Bin( 0 ), without type nor content - Help blocks (variable) - All the blocks go one after the other, without separators, and compressed by HB_ZCompress( ) */ #include "Xailer.ch" //------------------------------------------------------------------------------ FUNCTION XHtmlHelpTopics( cFile ) LOCAL aTopics := {}, cId, cTopic LOCAL hFile, cBuffer, n, i IF ( hFile := FOpen( cFile, 64 ) ) != -1 cBuffer := Space( 30 ) IF FRead( hFile, @cBuffer, 30 ) == 30 // Leer la cabecera IF cBuffer == "Xailer HTML Help System v1.00" + Chr( 26 ) // Leer los bloques de informacion - Read all info blocks WHILE Empty( cBuffer := Space( 4 ) ) .AND. FRead( hFile, @cBuffer, 4 ) == 4 .AND. !Empty( n := Bin2L( cBuffer ) ) // Leer el bloque - Read the block cBuffer := Space( n ) IF FRead( hFile, @cBuffer, n ) == n IF Left( cBuffer, 1 ) == Chr( 1 ) // Es la TOC - It's the TOC cBuffer := HB_ZUncompress( Substr( cBuffer, 2 ) ) // Obtener los topics WHILE ( n := HB_At( CRLF, cBuffer, 5 ) ) > 0 cId := "" cTopic := Substr( cBuffer, 5, n - 5 ) IF ( i := At( "|", cTopic ) ) > 0 cId := Left( cTopic, i - 1 ) cTopic := Substr( cTopic, i + 1 ) ENDIF IF Left( cId, 1 ) == " " AAdd( aTopics, { cId, cTopic } ) ENDIF cBuffer := Substr( cBuffer, n + 2 ) ENDDO EXIT ENDIF ENDIF ENDDO ENDIF ENDIF FClose( hFile ) ENDIF RETURN aTopics //------------------------------------------------------------------------------ FUNCTION XHtmlHelpTopic( cFile, cId, cTopic ) LOCAL cText := "", cTitle := "" LOCAL hFile, cBuffer, n, i, nPos := 30 LOCAL cItemId, cItem, nHelpSize IF ( hFile := FOpen( cFile, 64 ) ) != -1 cBuffer := Space( 30 ) IF FRead( hFile, @cBuffer, 30 ) == 30 // Leer la cabecera IF cBuffer == "Xailer HTML Help System v1.00" + Chr( 26 ) // Leer los bloques de informacion - Read all info blocks WHILE !Empty( nPos += Len( cBuffer := Space( 4 ) ) ) .AND. FRead( hFile, @cBuffer, 4 ) == 4 .AND. !Empty( n := Bin2L( cBuffer ) ) // Leer el bloque - Read the block nPos += n cBuffer := Space( n ) IF FRead( hFile, @cBuffer, n ) == n IF Left( cBuffer, 1 ) == Chr( 1 ) // Es la TOC - It's the TOC cBuffer := HB_ZUncompress( Substr( cBuffer, 2 ) ) // Buscar el topic, calculando la posicion y tamaņo del contenido // Search for the topic, calculating the position and content's size WHILE ( n := HB_At( CRLF, cBuffer, 5 ) ) > 0 cItemId := "" cItem := LTrim( Substr( cBuffer, 5, n - 5 ) ) IF ( i := At( "|", cItem ) ) > 0 cItemId := Left( cItem, i - 1 ) cItem := Substr( cItem, i + 1 ) ENDIF IF ( !Empty( cId ) .AND. cId == cItemId ) .OR. ( !Empty( cTopic ) .AND. cItem == cTopic ) cTitle := cItem nHelpSize := Bin2L( Left( cBuffer, 4 ) ) EXIT ENDIF nPos += Bin2L( Left( cBuffer, 4 ) ) cBuffer := Substr( cBuffer, n + 2 ) ENDDO ENDIF ELSE EXIT ENDIF ENDDO // Obtener el texto de la ayuda - Get the Help's text IF !Empty( nHelpSize ) FSeek( hFile, nPos, 0 ) cBuffer := Space( nHelpSize ) IF FRead( hFile, @cBuffer, nHelpSize ) == nHelpSize cText := HB_ZUncompress( cBuffer ) ENDIF ENDIF ENDIF ENDIF FClose( hFile ) ENDIF cTopic := cTitle RETURN cText //------------------------------------------------------------------------------