正常外观的文本文件,由文件检测为 ASCII Pascal 程序文本

use*_*107 7 files

我有一个看起来“正常”的文本文件(包含英文句子),它被file命令检测为ASCII Pascal program text.

Pascal 程序文本如何与普通的 ASCII 英文文本区分开来?

我做了 head -10 file > tmp

file tmp仍然显示Pascaltmp在 VI 中打开时:set list

HELEN'S BABIES$
$
With some account of their ways, innocent, crafty, angelic, impish,$
witching and impulsive; also a partial record of their actions during$
ten days of their existence$
$
By JOHN HABBERTON$
$
$
$
Run Code Online (Sandbox Code Playgroud)

输出 head file | od -c

0000000   H   E   L   E   N   '   S       B   A   B   I   E   S  \n  \n
0000020   W   i   t   h       s   o   m   e       a   c   c   o   u   n
0000040   t       o   f       t   h   e   i   r       w   a   y   s   ,
0000060       i   n   n   o   c   e   n   t   ,       c   r   a   f   t
0000100   y   ,       a   n   g   e   l   i   c   ,       i   m   p   i
0000120   s   h   ,  \n   w   i   t   c   h   i   n   g       a   n   d
0000140       i   m   p   u   l   s   i   v   e   ;       a   l   s   o
0000160       a       p   a   r   t   i   a   l       r   e   c   o   r
0000200   d       o   f       t   h   e   i   r       a   c   t   i   o
0000220   n   s       d   u   r   i   n   g  \n   t   e   n       d   a
0000240   y   s       o   f       t   h   e   i   r       e   x   i   s
0000260   t   e   n   c   e  \n  \n   B   y       J   O   H   N       H
0000300   A   B   B   E   R   T   O   N  \n  \n  \n  \n
0000314
Run Code Online (Sandbox Code Playgroud)

文件上传到这里:http : //www.fileswap.com/dl/L0eCWJTvy/

我在CentOS release 6.5file版本5.04

第 4 行有一些东西。从第 4 行开始删除将其检测为仅文本文件

dam*_*ien 7

我能够在 OS X 10.6.8 和 OpenBSD 5.5-current 上重现这一点。

使用 打印出调试信息file -D tmp,结果表明您的文本文件在file(1)识别 Pascal 关键字之前未能通过大约 2000 次测试,record并决定它必须是 Pascal 程序文本。

可以通过以下方式获得最小的工作示例:

$ echo record > test
$ file test
test: ASCII Pascal program text
Run Code Online (Sandbox Code Playgroud)

经过无数次启发,只有ascmagic.c 中的“基于硬连线假设的第三组和最后一组测试”适用。这些测试识别“我们根据可以出现在文件中任何位置的关键字知道的文件类型”。因此,对文件的最小更改会导致正确标识为ASCII English text,例如在第三行更改theirthe