]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/tput-initc
3382ee5ad818ea479a4c51cd85c7566fa45c3667
[ncurses.git] / test / tput-initc
1 #!/bin/sh
2 ##############################################################################
3 # Copyright (c) 2016 Free Software Foundation, Inc.                          #
4 #                                                                            #
5 # Permission is hereby granted, free of charge, to any person obtaining a    #
6 # copy of this software and associated documentation files (the "Software"), #
7 # to deal in the Software without restriction, including without limitation  #
8 # the rights to use, copy, modify, merge, publish, distribute, distribute    #
9 # with modifications, sublicense, and/or sell copies of the Software, and to #
10 # permit persons to whom the Software is furnished to do so, subject to the  #
11 # following conditions:                                                      #
12 #                                                                            #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software.                        #
15 #                                                                            #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
19 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
22 # DEALINGS IN THE SOFTWARE.                                                  #
23 #                                                                            #
24 # Except as contained in this notice, the name(s) of the above copyright     #
25 # holders shall not be used in advertising or otherwise to promote the sale, #
26 # use or other dealings in this Software without prior written               #
27 # authorization.                                                             #
28 ##############################################################################
29 # $Id: tput-initc,v 1.1 2016/12/10 23:35:46 tom Exp $
30 # Some of the ".dat" files in ncurses' test-directory give r/g/b numbers for
31 # default palettes of xterm and Linux console.  This script reads the numbers
32 # and (assuming the same or compatible terminal) uses tput to (re)initialize
33 # the palette using those numbers.
34
35 failed() {
36         printf "?? $*\n" >&2
37         exit 1
38 }
39
40 if [ $# = 1 ]
41 then
42         file=$1
43 elif [ $# = 0 ]
44 then
45         file=$TERM.dat
46 else
47         failed "expected one parameter or none"
48 fi
49
50 if [ ! -f "$file" ]
51 then
52         if [ -f "$file.dat" ]
53         then
54                 file="$file.dat"
55         else
56                 failed "no such file: $file"
57         fi
58 fi
59
60 myterm=${file%%.dat}
61 colors=$(tput -T $myterm colors 2>/dev/null)
62 if [ ${colors:-0} -le 0 ]
63 then
64         myterm=${myterm%%-color}
65         colors=$(tput -T $myterm colors 2>/dev/null)
66 fi
67 if [ ${colors:-0} -le 0 ]
68 then
69         failed "terminal $myterm does not support color"
70 fi
71
72 cat $file |\
73 awk -v myterm=$myterm '
74 BEGIN { limit=1000; }
75 function scaled(n) {
76         return (n * 1000)/limit;
77 }
78
79 /^scale:[0-9]+/{
80         sub("^scale:","",$0);
81         limit = $0;
82 }
83
84 /^[0-9]+:/{
85         sub(":","",$1);
86         printf "tput -T%s initc %d %d %d %d\n", myterm, $1,scaled($2),scaled($3),scaled($4);
87 }' |sh -