📄 hhp.c
字号:
/*chmdeco -- extract files from ITS/CHM files and decompile CHM filesCopyright (C) 2003 PabsThis program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free Software Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307, USA or visit:http://www.gnu.org*//*hhp.c - this module implements conversion of internal files into a .hhp project.It was written by Pabs.*//* System headers */#include <stdio.h>#include <errno.h>#include <dirent.h>#include <sys/stat.h>#include <stdlib.h>#include <string.h>#include <unistd.h>/* Local headers */#include "chmdeco.h"#include "common.h"#include "convert.h"#include "windows.h"#include "system.h"#include "strings.h"#include "sitemap.h"#include "misc.h"#include "hhp.h"DWORD stamp;LCID os_lcid;LCID compiler_lcid;char* prefix = NULL;size_t prefix_size = 0;size_t prefix_len = 0;#define PREFIX_GROW 50void print_files( char* d );FILE* hhp = NULL;bool hhp_success = false;bool no_files_yet = true;void recreate_hhp( void ){ char* pf = Project_file ? Project_file : HHP_FILE_NAME; if( !open_strings() ) return; if( !open_system() ) return; hhp = recreate( pf ); if( hhp ){ /* Various stuff */ bool got_stuff = false; LCID Language = 0; DWORD DBCS = 0; DWORD Full_text_search = 0; DWORD KLinks = 0; DWORD ALinks = 0; QWORD compilation_FILETIME = 0; { BYTE* stuff = get_system(Language_DBCS_FTS_KLinks_ALinks_FILETIME_CODE); if( stuff ){ got_stuff = true; Language = get_DWORD(stuff); DBCS = get_DWORD(stuff+4); Full_text_search = get_DWORD(stuff+8); KLinks = get_DWORD(stuff+12); ALinks = get_DWORD(stuff+16); compilation_FILETIME = get_QWORD(stuff+20); FREE(stuff); } } if( print_blurb ) fputs( ";This HHP file was recreated by "PROGNAME" "VERSION" (by "AUTHOR" - "WEBSITE")\r\n" ";It is only an approximation of the original project file.\r\n" ";Other files that may have been recreated with it are also only approximations.\r\n" ";See the documentation for parts of the HHP that cannot be recreated.\r\n\r\n", hhp ); if( print_stats ){ /* FIXME: Print something else when we get its dumping */ if( input ){ char* fn = strrchr( input, '/' ); fprintf( hhp, ";Input: %s\r\n", fn ? fn+1 : input ); } { /* Compiler name */ char* compiled_by = (char*)get_system(COMPILED_BY_CODE); if(compiled_by) fprintf( hhp, ";Compiled by: %s\r\n", compiled_by ); FREE(compiled_by); } /* Compiler language */ if( lcid_success ){ char* compiler_lcid_string = get_lcid_string( compiler_lcid ); if(compiler_lcid_string) fprintf( hhp, ";Compiler language: %s (0x%x)\r\n", compiler_lcid_string, compiler_lcid ); else fprintf( hhp, ";Compiler language id: 0x%x \r\n", compiler_lcid ); } { /* Compilation date (time_t) */ DWORD compilation_time_t = 0; if( get_system_DWORD(time_t_STAMP_CODE,&compilation_time_t) ){ char* compilation_time_t_string = make_time_t_string(compilation_time_t); if(compilation_time_t_string) fprintf( hhp, ";Compilation date: %s (%u seconds after 0:00 Jan 1 1970)\r\n", compilation_time_t_string, compilation_time_t ); else fprintf( hhp, ";Compilation date: %u seconds after 0:00 Jan 1 1970\r\n", compilation_time_t ); } }#if 0 /* This QWORD is totally fucked up */ /* Compilation date (FILETIME) */ if(got_stuff){ char* compilation_FILETIME_string = make_FILETIME_string(compilation_FILETIME); if(compilation_FILETIME_string) fprintf( hhp, ";Compilation date: %s (%llu00 nano-seconds after 0:00 Jan 1 1600)\r\n", compilation_FILETIME_string, compilation_FILETIME ); else fprintf( hhp, ";Compilation date: %llu00 nano-seconds after 0:00 Jan 1 1600\r\n", compilation_FILETIME ); /* FREE(compilation_FILETIME_string); */ }#endif /* 0 */ /* Operating system language */ if( lcid_success ){ char* os_lcid_string = get_lcid_string( os_lcid ); if( os_lcid_string ) fprintf( hhp, ";Compilation operating system language: %s (0x%x)\r\n", os_lcid_string, os_lcid ); else fprintf( hhp, ";Compilation operating system language id: 0x%x\r\n", os_lcid ); } } fputs( "\r\n[OPTIONS]\r\n", hhp ); /* Auto Index */ if( got_stuff && (KLinks || print_defaults) ) fprintf( hhp, "Auto Index=%s\r\n", KLinks ? "Yes" : "No" ); /* If an option is commented out it means we can't get it from the internal files yet */ /* Auto TOC */ /* Warning this may be inaccurate if the hhp doesn't have auto toc, but auto-generated is in the hhc, for example by turning it off after a previous compilation */ /* This is CHEATING { FIXME: find a minimalist html parser & flesh this one out : open old hhp if it is present & check for Auto TOC and or open html files & check for h1-h9 matching toc entries (binary or sitemap) old_Contents = find("*.hhc") FILE* old_hhc = fopen(old_Contents,"rb"); if(old_hhc){ parse the hhc looking for Auto Generated in the text/site properties object if( Auto_Generated ){ Auto_TOC = 0; parse the hhc looking for the maximum next level of ul/li elements fprintf( hhp, ";WARNING: The way we get Auto TOC is fairly dodgy\r\nAuto TOC=%u\r\n", Auto_TOC ); } } }*/ { /* Binary Index */ /* Buggy when no HHK */ bool Binary_Index = (system_entries[Binary_Index_CODE].offset >=0); if( !Binary_Index || print_defaults ) fprintf( hhp, "Binary Index=%s\r\n", Binary_Index ? "Yes" : "No" ); } { /* Binary TOC */ /* Buggy when no HHC */ bool Binary_TOC = (system_entries[Binary_TOC_CODE].offset>=0); if( Binary_TOC || print_defaults ) fprintf( hhp, "Binary TOC=%s\r\n", Binary_TOC ? "Yes" : "No" ); } /* fprintf( hhp, "CITATION=%s\r\n", CITATION ); */ /* fprintf( hhp, "COMPRESS=%u\r\n", COMPRESS ); */ /* fprintf( hhp, "COPYRIGHT=%s\r\n", COPYRIGHT ); */ { /* Compatibility */ /* FIXME: take the following into account? absence of system codes 7, 11, 12, 13, 15 and #TOCIDX, $WWKeywordlinks, $WWAssociativeLinks size of the #WINDOWS entries */ bool Compatibility = system_version > 2; if( !Compatibility || print_defaults ) fprintf( hhp, "Compatibility=%s\r\n", Compatibility ? "1.1 or later" : "1.0" ); } /* Compiled file */ if(Compiled_file){ fprintf( hhp, "Compiled file=%s.chm\r\n", Compiled_file ); FREE(Compiled_file); } /* Contents file */ if( Contents_file ) fprintf( hhp, "Contents file=%s\r\n", Contents_file ); /* else { FIXME: Find out how to find files with a particular extension fputs( ";The best guess for the contents file is one of the following\r\n", hhp ); while(f=findfile("*.hhc",case insensitive)) fprintf( hhp, ";Contents file=%s\r\n", f ); } */ { /* Create CHI file */ bool Create_CHI_file = exists("#SYSTEM") && exists("$OBJINST") && exists("$FIftiMain") && !exists("$WWAssociativeLinks") && !exists("$WWKeywordLinks") && !exists("#IDXHDR") && !exists("#TOCIDX") && !exists("#URLSTR") && !exists("#WINDOWS") && !exists("#ITBITS") && !exists("#STRINGS") && !exists("#TOPICS") && !exists("#URLTBL"); if( Create_CHI_file || print_defaults ) fprintf( hhp, "Create CHI file=%s\r\n", Create_CHI_file ? "Yes" : "No" ); } /* DBCS */ if( got_stuff && (DBCS || print_defaults) ) fprintf( hhp, "DBCS=%s\r\n", DBCS ? "Yes" : "No" ); { /* Default Font */ char* Default_Font = (char*)get_system(Default_Font_CODE); if(Default_Font) fprintf( hhp, "Default Font=%s\r\n", Default_Font ); FREE(Default_Font); } { /* Default Window */ char* Default_Window = (char*)get_system(Default_Window_CODE); if(Default_Window) fprintf( hhp, "Default Window=%s\r\n", Default_Window ); FREE(Default_Window); } { /* Default topic */ char* Default_topic = (char*)get_system(Default_topic_CODE); if(Default_topic) fprintf( hhp, "Default topic=%s\r\n", Default_topic ); FREE(Default_topic); } /* fprintf( hhp, "Display compile notes=%s\r\n", Display_compile_notes ? "Yes" : "No" ); */ /* fprintf( hhp, "Display compile progress=%s\r\n", Display_compile_progress ? "Yes" : "No" ); */ /* fprintf( hhp, "Enhanced decompilation=%s\r\n", Enhanced_decompilation ? "Yes" : "No" ); */ /* fprintf( hhp, "Error log file=%s\r\n", Error_log_file ); */ /* FIXME: check if urlstr contains repeated filenames (indicative of path stripping)? and there are no folders other than $WW*Links if( !Flat || print_defaults ) fprintf( hhp, "Flat=%s\r\n", Flat ? "Yes" : "No" ); */ /* Full text search stop list file */ if(stp_success) fprintf( hhp, "Full text search stop list file=%s\r\n", FTS_STOP_LIST_FILE_NAME ); { /* Full-text search */ bool got_fts = got_stuff; if( !got_fts ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -