将当前 terminfo 数据库与 terminfo 源文件进行比较

将当前 terminfo 数据库与 terminfo 源文件进行比较

我们如何将所有可用的 terminfo 条目(完整的当前编译数据库)与 terminfo 源文件进行比较?

infocmp实用程序具有该-F选项,但需要比较两个文件,但没有导出所有条目并生成完整当前数据库的文件的选项,需要对每个条目调用它,因此导出每个条目分别条目。如果有一种方法可以一次导出所有条目,则可以分两步完成,调用 infocmp 两次(一次导出所有数据库,另一次比较文件)

答案1

您可以将源代码编译到新目录中并用于infocmp -d比较每个条目。

mkdir -p dir && cd dir
TERMINFO=$PWD tic -x /path/to/terminfo.src
for entry in */*; do
  infocmp -x -d -B "$PWD" "${entry#*/}" "${entry#*/}"
done

要仅打印与相关上下文的差异,您可以这样做:

mkdir -p dir && cd dir
TERMINFO=$PWD tic -x /path/to/terminfo.src
for entry in */*; do
  LC_ALL=C infocmp -x -d -B "$PWD" "${entry#*/}" "${entry#*/}" |
    awk '
      /^comparing/ {entry=$1" "$2; next}
      $1 == "comparing" {section=$0; next}
      entry {print entry; entry = 0}
      section {print section; section = 0}
      {print}'
done

答案2

我用这个脚本来做到这一点(例如在 Debian 上,它假设kbs^?),测试 ncurses 的本地构建:

#!/bin/sh
# $Id: test-terminfo+,v 1.10 2012/04/21 15:52:17 tom Exp $
# vi:sw=4 ts=4
# Compile the given terminfo source-file(s) into a temporary directory, compare
# the compiled files against the system version.
if test $# = 0 ; then
        with-local-ncurses $0 terminfo terminfo.src
else
        OPTS=-x
        MY_NCURSES=/usr/local/ncurses
        MY_TERMINFO=$MY_NCURSES/share/terminfo
        PATH=$MY_NCURSES/bin:$PATH; export PATH
        unset TERMINFO_DIRS
        unset TERMINFO
        TMP=/tmp/term$$
        rm -rf $TMP
        trap "rm -rf $TMP" 0 1 2 3 15
        mkdir $TMP
        rm -f $TMP/terminfo.sed
        cat >$TMP/terminfo.sed <<EOF
s,/usr/share,$MY_NCURSES/share,g
/^xterm+kbs|fragment for backspace key, kbs=/s/kbs=^H,/kbs=^?,/
/^xterm+kbs|fragment for backspace key,\$/,/^#/{
        s/kbs=^H,/kbs=^?,/
}
EOF
        for name in $*
        do
                if test -f "$name" ; then
                        sed -f $TMP/terminfo.sed $name >$TMP/source
                        TERMINFO=$TMP tic -U $OPTS -R ALL $TMP/source
                fi
        done
        TERMINFO=$MY_TERMINFO
        for name in $TMP/?/*
        do
                base=`dirname $name`
                base=`basename $base`
                name=`basename $name`
                case $name in
                ??)     # ignore 2-char termcap names
                        ;;
                *)
                        if test -f "$TERMINFO/$base/$name" ; then
                                infocmp -U $OPTS -q -p -f -A $TERMINFO -B $TMP $name $name
                        else
                                echo missing "$name $base"
                        fi
                        ;;
                esac
        done
fi

日志说明了为什么一些细节很重要:

----------------------------                                                                                
revision 1.10                                                                                               
date: 2012/04/21 15:52:17;  author: tom;  state: Exp;  lines: +2 -3                                         
add -x                                                                                                      
----------------------------                                                                                
revision 1.9                                                                                                
date: 2012/04/14 21:50:23;  author: tom;  state: Exp;  lines: +7 -4                                         
tweak to handle output from terminfo-uses script                                                            
----------------------------                                                                                
revision 1.8                                                                                                
date: 2012/03/17 19:31:02;  author: tom;  state: Exp;  lines: +15 -4                                        
tweaks to make this compare more closely to what I've installed, by                                         
accounting for the pathnames used in cfg-local                                                              
----------------------------                                                                                
revision 1.7                                                                                                
date: 2011/08/10 08:49:23;  author: tom;  state: Exp;  lines: +2 -2                                         
make this work with Solaris                                                                                 
----------------------------                                                                                
revision 1.6                                                                                                
date: 2011/06/11 17:23:15;  author: tom;  state: Exp;  lines: +2 -2                                         
remove spurious "eval" when doing no-args                                                                   
----------------------------                                                                                
revision 1.5                                                                                                
date: 2004/07/05 14:06:46;  author: tom;  state: Exp;  lines: +15 -7                                        
use -U option to simplify comparing termcap                                                                 
ignore 2-char termcap names                                                                                 
----------------------------                                                                                
revision 1.4                                                                                                
date: 2004/01/31 17:42:01;  author: tom;  state: Exp;  lines: +2 -2                                         
ignore padding                                                                                              
----------------------------                                                                                
revision 1.3                                                                                                
date: 2003/05/31 21:00:37;  author: tom;  state: Exp;  lines: +9 -5                                         
use local-ncurses rather than installed version                                                             
----------------------------                                                                                
revision 1.2                                                                                                
date: 2002/06/22 22:31:53;  author: tom;  state: Exp;  lines: +1 -1                                         
add -p option                                                                                               
----------------------------                                                                                
revision 1.1                                                                                                
date: 2001/05/19 20:07:23;  author: tom;  state: Exp

我检查差异(除了丢失的条目)通过查找tab字符。

至于为什么命名为test-terminfo+,这是因为原始脚本(写于 1998 年)仅与系统 terminfo 进行比较(没有任何软件包可以避免污染...)。

像往常一样,阅读手册页会有所帮助:

相关内容