1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
#!/usr/bin/perl -w
# Copyright (c) 2000, 2002, 2020 Stephen Montgomery-Smith
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of Stephen Montgomery-Smith nor the names of his
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE STEPHEN MONTGOMERY-SMITH AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STEPHEN MONTGOMERY-SMITH OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
open(PRINTC,">print.c");
open(CONFIG,"config_print");
$output = '';
$outputline = '';
$last_needs_mask = '';
$last_needs_enum = '';
while ($line = <CONFIG>) {
next if $line =~ /^\#/ || $line =~ /^\s*$/;
if ($line =~ /^[A-Z]/) {
($type,$field,@title) = split ' ',$line;
$title = join ' ',@title;
if ($type =~ /^MASK\_(.*)$/) {
$output .= "printf(\"$title = %s\\n\", (ctrls->$field & $1)?\"On\":\"Off\");\n";
die "mask error\n" if !$last_needs_mask;
$last_needs_mask_head = substr $last_needs_mask, 0, 1;
$last_needs_mask_tail = substr $last_needs_mask, 1;
$outputline .= "printf(\" %s%s\", ctrls->$field & $1?\"\":\"$last_needs_mask_head\", \"$last_needs_mask_tail\");\n";
$last_needs_mask = '';
}
elsif ($last_needs_mask) {
die "mask error\n";
}
elsif ($type =~/^(USHORT|SHORT|UCHAR)$/) {
$output .= "printf(\"$title = %d\\n\", ctrls->$field);\n";
$outputline .= "printf(\" %d\", ctrls->$field);\n";
}
elsif ($type eq 'CHAR_ARRAY_32') {
$output .= "printf(\"$title =\");\n" .
"for (i=0;i<32;i++) {\n" .
" if (i%8==0) printf(\"\\n \");\n" .
" printf(\"%x%x\",ctrls->$field\[i]>>4,ctrls->$field\[i]&15);\n" .
"}\n" .
"printf(\"\\n\");\n";
$outputline .= "printf(\" \");\n" .
"for (i=0;i<32;i++)\n" .
" printf(\"%x%x\",ctrls->$field\[i]>>4,ctrls->$field\[i]&15);\n";
}
elsif ($type eq 'HIGH_NIBBLE_ENUM') {
die "enum error\n" if !$last_needs_enum;
$output .= "printf(\"$title = \");\n";
$outputline .= "s = NULL;\n";
$line = <CONFIG>;
$line =~ s/\s//g;
$first = 1;
foreach $enum (split ',',$line) {
($code,$value) = split '=',$enum;
$output .= (!$first?"else ":"") .
"if ((ctrls->$field & 0xF0) == $value) printf(\"$code\\n\");\n";
$outputline .= (!$first?"else ":"") .
"if ((ctrls->$field & 0xF0)== $value) s = \"$code\";\n";
$first = 0;
}
$output .= "else printf(\"undefined\\n\");\n";
$outputline .= "if (s!=NULL) printf(\" " . substr($last_needs_enum,1) . " %s\",s);\n";
$last_needs_enum = 0;
}
elsif ($type eq 'LOW_NIBBLE_IF_HIGH_NIBBLE_ENUM') {
$output .= "printf(\"$title = %d\\n\", ctrls->$field & 0x0F);\n";
$outputline .= "print_nibble = 0;\n";
$line = <CONFIG>;
$line =~ s/\s//g;
$first = 1;
foreach $enum (split ',',$line) {
($code,$value) = split '=',$enum;
$outputline .= (!$first?"else ":"") .
"if ((ctrls->$field & 0xF0)== $value) print_nibble = 1;\n";
$first = 0;
}
$outputline .= "if (print_nibble) printf(\" %d\", ctrls->$field & 0x0F);\n";
$last_needs_enum = 0;
}
else {
die "syntax error";
}
}
else {
chomp($line);
if ($line =~ /^\-/) {
$last_needs_mask = $line;
}
elsif ($line =~ /^\+/) {
$last_needs_enum = $line;
}
else {
$outputline .= "printf(\" $line\");\n";
}
}
}
$output =~ s/^/ /gm;
$outputline =~ s/^/ /gm;
close CONFIG;
open(COPY,"COPYRIGHT");
$copy = join '',<COPY>;
print PRINTC <<EOM;
/*
$copy
*/
#include "xkbset.h"
void print_controls(XkbControlsPtr ctrls) {
int i;
$output
}
void print_controls_in_line(XkbControlsPtr ctrls) {
int i;
char *s;
int print_nibble;
printf(\"xkbset\");
$outputline
printf(\"\\n\");
}
EOM
########
open(CONFIG,"config_print");
$output = '';
$outputline = '';
$last_needs_mask = '';
while ($line = <CONFIG>) {
next if $line =~ /^\#/ || $line =~ /^\s*$/;
if ($line =~ /^[A-Z]/) {
($type,$field,@title) = split ' ',$line;
$title = join ' ',@title;
if ($type =~ /^MASK\_(.*)$/) {
if ($field eq 'enabled_ctrls') {
($axmask,$axvalues) = ('axt_ctrls_mask','axt_ctrls_values');
}
elsif ($field eq 'ax_options') {
($axmask,$axvalues) = ('axt_opts_mask','axt_opts_values');
}
else {
($axmask,$axvalues) = ('','');
}
if ($axmask) {
$output .= "printf(\"Upon Expiry $title will be: %s\\n\",\n" .
" (ctrls->$axmask & $1)?((ctrls->$axvalues & $1)?\"On\":\"Off\"):\"Unchanged\");\n";
$t = substr $last_needs_mask,1;
$outputline .= "printf(\" %s$t\",\n" .
" (ctrls->$axmask & $1)?((ctrls->$axvalues & $1)?\"\":\"-\"):\"=\");\n";
$last_needs_mask = '';
}
}
elsif ($last_needs_mask) {
die "mask error\n";
}
}
else {
chomp($line);
if ($line =~ /^\-/) {
$last_needs_mask = $line;
}
}
}
$output =~ s/^/ /gm;
$outputline =~ s/^/ /gm;
close CONFIG;
print PRINTC <<EOM
void print_expire_controls(XkbControlsPtr ctrls) {
printf(\"AccessX Timeout = %d\\n\",ctrls->ax_timeout);
$output
}
void print_expire_controls_in_line(XkbControlsPtr ctrls) {
printf(\"xkbset exp %d\",ctrls->ax_timeout);
$outputline
printf(\"\\n\");
}
EOM
|