chreekat / terminfo-hs

A pure-Haskell (no FFI) module for accessing terminfo databases
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Not a terminfo file (bad magic) #3

Open pjones opened 4 years ago

pjones commented 4 years ago

I just noticed this:

Terminfo.acquireDatabase ("xterm-256color")
Left "Not a terminfo file (bad magic) > 26: Failed reading: satisfy"

And here are the first few bytes of the terminfo file:

00000000: 1e02 2500 2600 0f00 9d01 0206 7874 6572  ..%.&.......xter
00000010: 6d2d 3235 3663 6f6c 6f72 7c78 7465 726d  m-256color|xterm
00000020: 2077 6974 6820 3235 3620 636f 6c6f 7273   with 256 colors

Compared to the plain xterm file:

00000000: 1a01 3000 2600 0f00 9d01 b805 7874 6572  ..0.&.......xter
00000010: 6d7c 7874 6572 6d20 7465 726d 696e 616c  m|xterm terminal
00000020: 2065 6d75 6c61 746f 7220 2858 2057 696e   emulator (X Win
00000030: 646f 7720 5379 7374 656d 2900 0001 0000  dow System).....

The "failed reading: satisfy" part makes me think there's a bad parser somewhere. Any suggestions?

chreekat commented 4 years ago

Interesting!

It's indeed a parser failure. Code is at https://github.com/chreekat/terminfo-hs/blob/master/src/System/Terminfo/DBParse.hs#L111-L113 :

-- | the magic number for term files
magic :: Parser Int
magic = shortInt 0o432 <?> "Not a terminfo file (bad magic)"

My source for that number is term man page: https://linux.die.net/man/5/term

Maybe it has been outdated?

If you can figure it out, feel free to let me know and/or open a PR! I admit I have not looked in this lib in a while, but I'd be happy to keep it working.