' Generated by Deepseek chat bot 2026/09/21 ' https://chat.deepseek.com/ ' ' PUBLIC DOMAIN BECAUSE GENERATED CODE CANNOT ' BE COPYRIGHTED OR COPYLEFTED ' ' Since I was pestered to "really try" "AI" (LLM is not AI), ' I had it generate an epub reader written in FreeBASIC that ' works in Linux terminal and MS-DOS/FreeDOS. ' ' I completed the task of having the LLM generate something ' sort of like what I wanted... ' ' It was a painfully stupid process of the machine trying to ' use reserved words as variables and other such mistakes that ' even beginners would not make. This is because the LLM does ' not know anything, it merely generates based on statistics. ' ' I have tried. I have found the process and output wanting. ' ' Every LLM is trash that produces garbage. ' ' However, since I hate to waste the resources, here's the source ' code for anyone who wants it. I have, sadly, already boiled oceans ' and burned forests for this experiment. People might as well have ' the product made from the ill-collected data mined by these LLM ' companies. ' ' Modified 2026/09/22 So it saves the place you've read to in the ' book, in a bookmark file next to the epub. ' ' Modified 2026/09/29 CP437 substitution for DOS: em/en dashes, ' curly quotes, and ellipsis map to ASCII; accented Latin letters ' map to native CP437 bytes. Linux output remains UTF-8. ' ' Modified 2026/09/30 Added `goto_section` and `next_section`, ' both keyed to the table of contents. Added a persistent ' bookmark file. `show`, `goto_section`, `next_section`, and ' the interactive TOC screen all take or display TOC indexes. ' `toc` opens the TOC screen. Added `toc_print` and `meta_print` ' for non-interactive use. Removed the old `list` command. ' Image alt text is now emitted inline in brackets. When a TOC ' entry has an anchor, the anchor wins over any explicit skip ' argument. Bookmark stores TOC index, spine section, and skip. ' ' --------------------------------------------------------------------- ' ' "Bugfix" attempt by kimi.ai code generation ' ' Modified 2026/10/01 Bug fixes (see the comments at each change): ' CP437 case labels for e-acute/e-grave were &h00A9/&h00A8 instead of ' &h00E9/&h00E8. Empty stored DEFLATE blocks underflowed the copy loop. ' hlit/hdist were not capped at 286/30 (one-byte stack overwrite). ' Malformed numeric character references could reach chr() with an ' illegal value or emit an overlong UTF-8 NUL. The last buffered line ' kept its newline and printed a spurious blank row. Whitespace-only ' source lines vanished, merging paragraphs. CR bytes survived into ' the output. Unterminated script/style blocks rendered as text. ' Percent-encoded hrefs were not decoded, and TOC hrefs were resolved ' against the OPF directory instead of the NCX / nav file's directory. ' Anchor search could false-match data-id attributes. A named-entity ' table now covers Latin-1 letters and common symbols. Fixed a ' next_section/bookmark mixup that could store a TOC index in the ' bookmark's spine-section field. Removed dead skip/total variables. ' ' ===================================================================== ' epubrd.bas - Minimal EPUB reader in FreeBASIC ' ===================================================================== ' Self-contained DEFLATE (RFC 1951). No external libraries. ' Portable across 32-bit MS-DOS and 64-bit Linux/host. ' ' Build (Linux/host): fbc epubrd.bas ' Build Cross Compile (MS-DOS): fbc -target dos epubrd.bas ' Build (MS-DOS): fbc epubrd.bas ' ' Commands: ' epubrd resume from bookmark ' epubrd meta title and author, paged ' epubrd meta_print title and author, plain ' epubrd toc interactive TOC screen ' epubrd toc_print TOC listing, plain ' epubrd show [n] [skip] read TOC entry n ' epubrd goto_section same as `show ` ' epubrd next_section [skip] ' ' Reader keys: ' [space] or [Enter] next page ' [b] or [B] previous page ' [t] or [T] table of contents screen ' [q] or [Q] quit ' [ctrl-C] quit ' any other key ignored ' On quit, prints the command to resume at the top line on ' screen and writes the bookmark file. ' ' TOC screen keys: ' digits then [Enter] jump to that entry ' [space], [Enter] next page of TOC (empty buffer) ' [b], [B] previous page of TOC ' [q], [Q], [Esc] return to the reader at the same page ' [ctrl-C] quit the program ' any other key ignored ' ' Resume and skip: ' `show [skip]`: read TOC entry n as text. If the entry has ' an anchor (`file.xhtml#frag`), jumps to it and ignores `skip`. ' If the entry has no anchor, starts at line 0 or at `skip`. ' `show` with no argument reads the bookmark, if any. ' ' next_section: ' Read TOC entry n, then continue into n+1, n+2, and so on ' until the end of the TOC or until you quit. `skip` applies ' only to the first entry, and only if that entry has no ' anchor. On quit, the resume hint names the TOC entry you ' were in. ' ' Bookmark: ' On quit, writes `.bmk` next to the epub: ' line 1 TOC index of the reading position ' line 2 spine section index ' line 3 line skip within the section ' `epubrd ` with no command, or `show` with no ' arguments, resumes from the bookmark in spine terms, ' bypassing TOC resolution. Delete the .bmk to start over. ' For `book.epub` the bookmark is `book.bmk`. ' ' Text extraction: ' Tags are stripped, entities decoded, and block-level tags ' (`

`, `

`, `
`, headings, list items, table rows, ' block quotes, preformatted blocks, and sectioning tags) ' produce newlines. `