| 1 | #!/usr/bin/perl -w -pi.old |
|---|
| 2 | |
|---|
| 3 | # Convert a sensors.conf file from the old (Linux 2.4, lm-sensors 2) |
|---|
| 4 | # symbol names to the new (Linux 2.6, lm-sensors 3) symbol names. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> |
|---|
| 7 | # |
|---|
| 8 | # This program is free software; you can redistribute it and/or |
|---|
| 9 | # modify it under the terms of the GNU General Public License |
|---|
| 10 | # as published by the Free Software Foundation; either version 2 |
|---|
| 11 | # of the License, or (at your option) any later version. |
|---|
| 12 | # |
|---|
| 13 | # This program is distributed in the hope that it will be useful, |
|---|
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | # GNU General Public License for more details. |
|---|
| 17 | # |
|---|
| 18 | # You should have received a copy of the GNU General Public License |
|---|
| 19 | # along with this program; if not, write to the Free Software |
|---|
| 20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 21 | # MA 02110-1301, USA. |
|---|
| 22 | |
|---|
| 23 | # Implemented conversions: |
|---|
| 24 | # * The "algorithm name" part of bus statements is removed. |
|---|
| 25 | # * Bus statements for the ISA bus are removed. |
|---|
| 26 | # * Chip names containing dashes are removed. |
|---|
| 27 | # * Label, ignore, set and compute statements referencing features |
|---|
| 28 | # which are not part of the new interface are removed. |
|---|
| 29 | # * Label, ignore, set and compute statements referencing features |
|---|
| 30 | # which have been renamed are updated. This includes both general |
|---|
| 31 | # feature name changes and chip-specific feature name changes. |
|---|
| 32 | # |
|---|
| 33 | # Note that we have to look at the commented out lines too, so that |
|---|
| 34 | # the user doesn't have a bad surprise when uncommenting them. |
|---|
| 35 | |
|---|
| 36 | use strict; |
|---|
| 37 | use vars qw($debug $chip %trans @delete %chip_trans %chip_delete); |
|---|
| 38 | |
|---|
| 39 | BEGIN |
|---|
| 40 | { |
|---|
| 41 | $debug = 0; |
|---|
| 42 | |
|---|
| 43 | %trans = ( |
|---|
| 44 | qr/\bvid\b/ => sub { "cpu0_vid" }, |
|---|
| 45 | qr/\bremote_temp\b/ => sub { "temp2" }, |
|---|
| 46 | qr/\bremote_temp_hyst\b/ => sub { "temp2_max_hyst" }, |
|---|
| 47 | qr/\bremote_temp_low\b/ => sub { "temp2_min" }, |
|---|
| 48 | qr/\bremote_temp_over\b/ => sub { "temp2_max" }, |
|---|
| 49 | qr/\btemp\b/ => sub { "temp1" }, |
|---|
| 50 | qr/\btemp_hyst\b/ => sub { "temp1_max_hyst" }, |
|---|
| 51 | qr/\btemp_low\b/ => sub { "temp1_min" }, |
|---|
| 52 | qr/\btemp_over\b/ => sub { "temp1_max" }, |
|---|
| 53 | qr/\btemp_high\b/ => sub { "temp1_max" }, |
|---|
| 54 | qr/\btemp_crit\b/ => sub { "temp1_crit" }, |
|---|
| 55 | |
|---|
| 56 | qr/\bvin(\d+)_max\b/ => sub { "in$1_max" }, |
|---|
| 57 | qr/\bvin(\d+)_min\b/ => sub { "in$1_min" }, |
|---|
| 58 | qr/\bvin(\d+)\b/ => sub { "in$1" }, |
|---|
| 59 | qr/\btemp(\d+)_over\b/ => sub { "temp$1_max" }, |
|---|
| 60 | qr/\btemp(\d+)_hyst\b/ => sub { "temp$1_max_hyst" }, |
|---|
| 61 | qr/\btemp(\d+)_high\b/ => sub { "temp$1_max" }, |
|---|
| 62 | qr/\btemp(\d+)_low\b/ => sub { "temp$1_min" }, |
|---|
| 63 | qr/\bsensor(\d+)\b/ => sub { "temp$1_type" }, |
|---|
| 64 | ); |
|---|
| 65 | |
|---|
| 66 | @delete = ( |
|---|
| 67 | qr/\balarms\b/, |
|---|
| 68 | qr/\bbeeps\b/, |
|---|
| 69 | qr/\bpwm\d*\b/, |
|---|
| 70 | qr/\bpwm\d+_enable\b/, |
|---|
| 71 | qr/\b(in|temp|fan)\d+_(state|status)\b/, |
|---|
| 72 | qr/\banalog_out\b/, |
|---|
| 73 | qr/\balarms_(in|temp|fan)\b/, |
|---|
| 74 | ); |
|---|
| 75 | |
|---|
| 76 | %chip_trans = ( |
|---|
| 77 | "gl518sm" => { |
|---|
| 78 | qr/\bvdd\b/ => sub { "in0" }, |
|---|
| 79 | qr/\bvdd_min\b/ => sub { "in0_min" }, |
|---|
| 80 | qr/\bvdd_max\b/ => sub { "in0_max" }, |
|---|
| 81 | }, |
|---|
| 82 | "gl520sm" => { |
|---|
| 83 | qr/\bvdd\b/ => sub { "in0" }, |
|---|
| 84 | qr/\bvdd_min\b/ => sub { "in0_min" }, |
|---|
| 85 | qr/\bvdd_max\b/ => sub { "in0_max" }, |
|---|
| 86 | }, |
|---|
| 87 | "lm80" => { |
|---|
| 88 | qr/\btemp_hot_hyst\b/ => sub { "temp1_max_hyst" }, |
|---|
| 89 | qr/\btemp_hot_max\b/ => sub { "temp1_max" }, |
|---|
| 90 | qr/\btemp_os_hyst\b/ => sub { "temp1_crit_hyst" }, |
|---|
| 91 | qr/\btemp_os_max\b/ => sub { "temp1_crit" }, |
|---|
| 92 | }, |
|---|
| 93 | "lm83" => { |
|---|
| 94 | qr/\btcrit\b/ => sub { "temp3_crit" }, |
|---|
| 95 | }, |
|---|
| 96 | "lm90" => { |
|---|
| 97 | qr/\btcrit(\d)\b/ => sub { "temp$1_crit" }, |
|---|
| 98 | qr/\bhyst(\d)\b/ => sub { "temp$1_crit_hyst" }, |
|---|
| 99 | }, |
|---|
| 100 | "adm1032" => { |
|---|
| 101 | qr/\btcrit(\d)\b/ => sub { "temp$1_crit" }, |
|---|
| 102 | qr/\bhyst(\d)\b/ => sub { "temp$1_crit_hyst" }, |
|---|
| 103 | }, |
|---|
| 104 | "lm86" => { |
|---|
| 105 | qr/\btcrit(\d)\b/ => sub { "temp$1_crit" }, |
|---|
| 106 | qr/\bhyst(\d)\b/ => sub { "temp$1_crit_hyst" }, |
|---|
| 107 | }, |
|---|
| 108 | "lm99" => { |
|---|
| 109 | qr/\btcrit(\d)\b/ => sub { "temp$1_crit" }, |
|---|
| 110 | qr/\bhyst(\d)\b/ => sub { "temp$1_crit_hyst" }, |
|---|
| 111 | }, |
|---|
| 112 | "adt7461" => { |
|---|
| 113 | qr/\btcrit(\d)\b/ => sub { "temp$1_crit" }, |
|---|
| 114 | qr/\bhyst(\d)\b/ => sub { "temp$1_crit_hyst" }, |
|---|
| 115 | }, |
|---|
| 116 | "max6657" => { |
|---|
| 117 | qr/\btcrit(\d)\b/ => sub { "temp$1_crit" }, |
|---|
| 118 | qr/\bhyst(\d)\b/ => sub { "temp$1_crit_hyst" }, |
|---|
| 119 | }, |
|---|
| 120 | "max6680" => { |
|---|
| 121 | qr/\btcrit(\d)\b/ => sub { "temp$1_crit" }, |
|---|
| 122 | qr/\bhyst(\d)\b/ => sub { "temp$1_crit_hyst" }, |
|---|
| 123 | }, |
|---|
| 124 | "lm93" => { |
|---|
| 125 | qr/\bvid([12])\b/ => sub { "cpu".($1-1)."_vid" }, |
|---|
| 126 | }, |
|---|
| 127 | "adm9240" => { |
|---|
| 128 | qr/"2\.5V(|_min|_max)"/ => sub { "in0$1" }, |
|---|
| 129 | qr/\bVccp1(|_min|_max)\b/ => sub { "in1$1" }, |
|---|
| 130 | qr/"3\.3V(|_min|_max)"/ => sub { "in2$1" }, |
|---|
| 131 | qr/"5V(|_min|_max)"/ => sub { "in3$1" }, |
|---|
| 132 | qr/"12V(|_min|_max)"/ => sub { "in4$1" }, |
|---|
| 133 | qr/\bVccp2(|_min|_max)\b/ => sub { "in5$1" }, |
|---|
| 134 | }, |
|---|
| 135 | "lm81" => { |
|---|
| 136 | qr/"2\.5V(|_min|_max)"/ => sub { "in0$1" }, |
|---|
| 137 | qr/\bVccp1(|_min|_max)\b/ => sub { "in1$1" }, |
|---|
| 138 | qr/"3\.3V(|_min|_max)"/ => sub { "in2$1" }, |
|---|
| 139 | qr/"5V(|_min|_max)"/ => sub { "in3$1" }, |
|---|
| 140 | qr/"12V(|_min|_max)"/ => sub { "in4$1" }, |
|---|
| 141 | qr/\bVccp2(|_min|_max)\b/ => sub { "in5$1" }, |
|---|
| 142 | }, |
|---|
| 143 | "ds1780" => { |
|---|
| 144 | qr/"2\.5V(|_min|_max)"/ => sub { "in0$1" }, |
|---|
| 145 | qr/\bVccp1(|_min|_max)\b/ => sub { "in1$1" }, |
|---|
| 146 | qr/"3\.3V(|_min|_max)"/ => sub { "in2$1" }, |
|---|
| 147 | qr/"5V(|_min|_max)"/ => sub { "in3$1" }, |
|---|
| 148 | qr/"12V(|_min|_max)"/ => sub { "in4$1" }, |
|---|
| 149 | qr/\bVccp2(|_min|_max)\b/ => sub { "in5$1" }, |
|---|
| 150 | }, |
|---|
| 151 | "adm1024" => { |
|---|
| 152 | qr/"2\.5V(|_min|_max)"/ => sub { "in0$1" }, |
|---|
| 153 | qr/\bVccp1(|_min|_max)\b/ => sub { "in1$1" }, |
|---|
| 154 | qr/"3\.3V(|_min|_max)"/ => sub { "in2$1" }, |
|---|
| 155 | qr/"5V(|_min|_max)"/ => sub { "in3$1" }, |
|---|
| 156 | qr/"12V(|_min|_max)"/ => sub { "in4$1" }, |
|---|
| 157 | qr/\bVccp2(|_min|_max)\b/ => sub { "in5$1" }, |
|---|
| 158 | qr/\btemp(\d)\b/ => sub { "temp".($1+1) }, |
|---|
| 159 | qr/\btemp(\d)_hyst\b/ => sub { "temp".($1+1)."_max_hyst" }, |
|---|
| 160 | qr/\btemp(\d)_over\b/ => sub { "temp".($1+1)."_max" }, |
|---|
| 161 | }, |
|---|
| 162 | "maxilife" => { |
|---|
| 163 | qr/\bvid(\d)(|_min|_max)\b/ => sub { "in".($1-1).$2 }, |
|---|
| 164 | }, |
|---|
| 165 | "thmc50" => { |
|---|
| 166 | qr/\btemp_hyst\b/ => sub { "temp1_min" }, |
|---|
| 167 | qr/\bremote_temp_hyst\b/ => sub { "temp2_min" }, |
|---|
| 168 | }, |
|---|
| 169 | "adm1022" => { |
|---|
| 170 | qr/\btemp_hyst\b/ => sub { "temp1_min" }, |
|---|
| 171 | qr/\bremote_temp_hyst\b/ => sub { "temp2_min" }, |
|---|
| 172 | }, |
|---|
| 173 | "adm1026" => { |
|---|
| 174 | qr/\bfan(\d)(|_div|_min)\b/ => sub { "fan".($1+1).$2 }, |
|---|
| 175 | qr/\btemp(\d)_therm\b/ => sub { "temp$1_crit" }, |
|---|
| 176 | }, |
|---|
| 177 | "via686a" => { |
|---|
| 178 | qr/"2\.0V"/ => sub { "in0" }, |
|---|
| 179 | qr/"2\.5V"/ => sub { "in1" }, |
|---|
| 180 | qr/"3\.3V"/ => sub { "in2" }, |
|---|
| 181 | qr/"5\.0V"/ => sub { "in3" }, |
|---|
| 182 | qr/"12V"/ => sub { "in4" }, |
|---|
| 183 | }, |
|---|
| 184 | "lm87" => { |
|---|
| 185 | qr/"2\.5V(|_min|_max)"/ => sub { "in0$1" }, |
|---|
| 186 | qr/\bVccp1(|_min|_max)\b/ => sub { "in1$1" }, |
|---|
| 187 | qr/"3\.3V(|_min|_max)"/ => sub { "in2$1" }, |
|---|
| 188 | qr/"5V(|_min|_max)"/ => sub { "in3$1" }, |
|---|
| 189 | qr/"12V(|_min|_max)"/ => sub { "in4$1" }, |
|---|
| 190 | qr/\bVccp2(|_min|_max)\b/ => sub { "in5$1" }, |
|---|
| 191 | qr/\bAIN1(|_min|_max)\b/ => sub { "in6$1" }, |
|---|
| 192 | qr/\bAIN2(|_min|_max)\b/ => sub { "in7$1" }, |
|---|
| 193 | qr/\bCPU_Temp\b/ => sub { "temp2" }, |
|---|
| 194 | }, |
|---|
| 195 | "fscpos" => { |
|---|
| 196 | qr/\bvolt12\b/ => sub { "in0" }, |
|---|
| 197 | qr/\bvolt5\b/ => sub { "in1" }, |
|---|
| 198 | qr/\bvoltbatt\b/ => sub { "in2" }, |
|---|
| 199 | }, |
|---|
| 200 | "fscscy" => { |
|---|
| 201 | qr/\bvolt12\b/ => sub { "in0" }, |
|---|
| 202 | qr/\bvolt5\b/ => sub { "in1" }, |
|---|
| 203 | qr/\bvoltbatt\b/ => sub { "in2" }, |
|---|
| 204 | }, |
|---|
| 205 | "pcf8591" => { |
|---|
| 206 | qr/\bch(\d)\b/ => sub { "in$1" }, |
|---|
| 207 | }, |
|---|
| 208 | "smsc47m192" => { |
|---|
| 209 | qr/\btemp(\d)_input_fault\b/ => sub { "temp$1_fault" }, |
|---|
| 210 | }, |
|---|
| 211 | "lm92" => { |
|---|
| 212 | qr/\btemp_hyst\b/ => sub { "temp1_crit_hyst" }, |
|---|
| 213 | }, |
|---|
| 214 | "max1619" => { |
|---|
| 215 | qr/\btemp2_hyst\b/ => sub { "temp2_crit_hyst" }, |
|---|
| 216 | }, |
|---|
| 217 | "lm78" => { |
|---|
| 218 | qr/\bin([56])_(min|max)\b/ => sub { "in$1_".($2 eq "max" ? "min" : "max") }, |
|---|
| 219 | }, |
|---|
| 220 | "lm79" => { |
|---|
| 221 | qr/\bin([56])_(min|max)\b/ => sub { "in$1_".($2 eq "max" ? "min" : "max") }, |
|---|
| 222 | }, |
|---|
| 223 | "w83781d" => { |
|---|
| 224 | qr/\bin([56])_(min|max)\b/ => sub { "in$1_".($2 eq "max" ? "min" : "max") }, |
|---|
| 225 | }, |
|---|
| 226 | "as99127f" => { |
|---|
| 227 | qr/\bin([56])_(min|max)\b/ => sub { "in$1_".($2 eq "max" ? "min" : "max") }, |
|---|
| 228 | }, |
|---|
| 229 | ); |
|---|
| 230 | |
|---|
| 231 | %chip_delete = ( |
|---|
| 232 | "adm1021" => [ |
|---|
| 233 | qr/\bdie_code\b/, |
|---|
| 234 | ], |
|---|
| 235 | "lm84" => [ |
|---|
| 236 | qr/\bdie_code\b/, |
|---|
| 237 | ], |
|---|
| 238 | "gl523" => [ |
|---|
| 239 | qr/\bdie_code\b/, |
|---|
| 240 | ], |
|---|
| 241 | "thmc10" => [ |
|---|
| 242 | qr/\bdie_code\b/, |
|---|
| 243 | ], |
|---|
| 244 | "gl518sm" => [ |
|---|
| 245 | qr/\bfan1_off\b/, |
|---|
| 246 | qr/\bfan1_off_pin\b/, |
|---|
| 247 | qr/\biterate\b/, |
|---|
| 248 | ], |
|---|
| 249 | "gl520sm" => [ |
|---|
| 250 | qr/\bfan1_off\b/, |
|---|
| 251 | qr/\btwo_temps\b/, |
|---|
| 252 | ], |
|---|
| 253 | "w83792d" => [ |
|---|
| 254 | qr/\bchassis\b/, |
|---|
| 255 | ], |
|---|
| 256 | "w83793" => [ |
|---|
| 257 | qr/\bchassis\b/, |
|---|
| 258 | ], |
|---|
| 259 | "maxilife" => [ |
|---|
| 260 | qr/\bpll(|_min|_max)\b/, |
|---|
| 261 | ], |
|---|
| 262 | "thmc50" => [ |
|---|
| 263 | qr/\banalog output\b/, |
|---|
| 264 | qr/\binterrupts\b/, |
|---|
| 265 | qr/\binterrupt mask\b/, |
|---|
| 266 | qr/\bdie_code\b/, |
|---|
| 267 | ], |
|---|
| 268 | "adm1022" => [ |
|---|
| 269 | qr/\banalog output\b/, |
|---|
| 270 | qr/\binterrupts\b/, |
|---|
| 271 | qr/\binterrupt mask\b/, |
|---|
| 272 | qr/\bdie_code\b/, |
|---|
| 273 | ], |
|---|
| 274 | "adm1026" => [ |
|---|
| 275 | qr/\balarm_mask\b/, |
|---|
| 276 | qr/\bgpio\b/, |
|---|
| 277 | qr/\bgpio_mask\b/, |
|---|
| 278 | qr/\bafc_pwm\b/, |
|---|
| 279 | qr/\bafc_analog_out\b/, |
|---|
| 280 | qr/\btemp\d_tmin\b/, |
|---|
| 281 | ], |
|---|
| 282 | "lm85" => [ |
|---|
| 283 | qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/, |
|---|
| 284 | qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/, |
|---|
| 285 | qr/\bfan\d_(tach_mode|ppr)\b/, |
|---|
| 286 | ], |
|---|
| 287 | "lm85b" => [ |
|---|
| 288 | qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/, |
|---|
| 289 | qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/, |
|---|
| 290 | qr/\bfan\d_(tach_mode|ppr)\b/, |
|---|
| 291 | ], |
|---|
| 292 | "lm85c" => [ |
|---|
| 293 | qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/, |
|---|
| 294 | qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/, |
|---|
| 295 | qr/\bfan\d_(tach_mode|ppr)\b/, |
|---|
| 296 | ], |
|---|
| 297 | "emc6d100" => [ |
|---|
| 298 | qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/, |
|---|
| 299 | qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/, |
|---|
| 300 | qr/\bfan\d_(tach_mode|ppr)\b/, |
|---|
| 301 | ], |
|---|
| 302 | "emc6d102" => [ |
|---|
| 303 | qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/, |
|---|
| 304 | qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/, |
|---|
| 305 | qr/\bfan\d_(tach_mode|ppr)\b/, |
|---|
| 306 | ], |
|---|
| 307 | "adm1027" => [ |
|---|
| 308 | qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/, |
|---|
| 309 | qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/, |
|---|
| 310 | qr/\bfan\d_(tach_mode|ppr)\b/, |
|---|
| 311 | ], |
|---|
| 312 | "adt7473" => [ |
|---|
| 313 | qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/, |
|---|
| 314 | qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/, |
|---|
| 315 | qr/\bfan\d_(tach_mode|ppr)\b/, |
|---|
| 316 | ], |
|---|
| 317 | "fscpos" => [ |
|---|
| 318 | qr/\brev\b/, |
|---|
| 319 | qr/\bevent\b/, |
|---|
| 320 | qr/\bcontrol\b/, |
|---|
| 321 | qr/\bfan\d_ripple\b/, |
|---|
| 322 | qr/\bwdog_(preset|state|control)\b/, |
|---|
| 323 | ], |
|---|
| 324 | "fscscy" => [ |
|---|
| 325 | qr/\brev\b/, |
|---|
| 326 | qr/\bevent\b/, |
|---|
| 327 | qr/\bcontrol\b/, |
|---|
| 328 | qr/\btemp\d_lim\b/, |
|---|
| 329 | qr/\bfan\d_ripple\b/, |
|---|
| 330 | qr/\bwdog_(preset|state|control)\b/, |
|---|
| 331 | ], |
|---|
| 332 | "fscher" => [ |
|---|
| 333 | qr/\brev\b/, |
|---|
| 334 | qr/\bevent\b/, |
|---|
| 335 | qr/\bcontrol\b/, |
|---|
| 336 | qr/\bfan\d_ripple\b/, |
|---|
| 337 | qr/\bwdog_(preset|state|control)\b/, |
|---|
| 338 | ], |
|---|
| 339 | "pcf8591" => [ |
|---|
| 340 | qr/\bain_conf\b/, |
|---|
| 341 | qr/\baout_enable\b/, |
|---|
| 342 | qr/\baout\b/, |
|---|
| 343 | ], |
|---|
| 344 | "vt1211" => [ |
|---|
| 345 | qr/\bconfig\b/, |
|---|
| 346 | ], |
|---|
| 347 | "vt8231" => [ |
|---|
| 348 | qr/\bconfig\b/, |
|---|
| 349 | ], |
|---|
| 350 | "max6650" => [ |
|---|
| 351 | qr/\bspeed\b/, |
|---|
| 352 | ], |
|---|
| 353 | "max6651" => [ |
|---|
| 354 | qr/\bspeed\b/, |
|---|
| 355 | ], |
|---|
| 356 | "applesmc" => [ |
|---|
| 357 | qr/\bfan\d_(max|safe)\b/, |
|---|
| 358 | ], |
|---|
| 359 | ); |
|---|
| 360 | |
|---|
| 361 | print "# Converted by sensors-conf-convert on ".localtime()."\n"; |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | sub substitute_line($$) |
|---|
| 365 | { |
|---|
| 366 | my ($chip, $line) = @_; |
|---|
| 367 | |
|---|
| 368 | # First the chip-specific ones |
|---|
| 369 | if ($chip && exists $chip_trans{$chip}) { |
|---|
| 370 | foreach my $t (keys %{$chip_trans{$chip}}) { |
|---|
| 371 | $line =~ s/$t/$chip_trans{$chip}->{$t}->()/ge; |
|---|
| 372 | } |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | # Then the general substitutions |
|---|
| 376 | foreach my $t (keys %trans) { |
|---|
| 377 | # Kudos to the nice folks in #perl on freenode :) |
|---|
| 378 | $line =~ s/$t/$trans{$t}->()/ge; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | return $line; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | sub delete_line($) |
|---|
| 385 | { |
|---|
| 386 | my $feature = shift; |
|---|
| 387 | |
|---|
| 388 | # First the general deletions |
|---|
| 389 | foreach my $t (@delete) { |
|---|
| 390 | return 1 if $feature =~ m/$t/; |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | # Then the chip-specific ones |
|---|
| 394 | if ($chip && exists $chip_delete{$chip}) { |
|---|
| 395 | foreach my $t (@{$chip_delete{$chip}}) { |
|---|
| 396 | return 1 if $feature =~ m/$t/; |
|---|
| 397 | } |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | return 0; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | if (m/^# Converted by sensors-conf-convert/) { |
|---|
| 404 | print STDERR "WARNING: Converting an already converted file!\n"; |
|---|
| 405 | print STDERR " Result will be incorrect for some chip types.\n"; |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | # Bus statements |
|---|
| 409 | if (m/^([\s#]*bus\s+"?i2c-\d+"?\s+"([^"]+)")\s+"[^"]*"/) { |
|---|
| 410 | print STDERR "Processing bus statement: $2\n" if $debug; |
|---|
| 411 | |
|---|
| 412 | if ($2 eq "ISA main adapter") { |
|---|
| 413 | $_ = ''; # Drop entirely |
|---|
| 414 | } else { |
|---|
| 415 | $_ = "$1\n"; # Drop algorithm name |
|---|
| 416 | } |
|---|
| 417 | } |
|---|
| 418 | |
|---|
| 419 | # Chip statements |
|---|
| 420 | elsif (m/^[\s#]*chip\s+"([\w\d*-]+)"/) { |
|---|
| 421 | # We only remember the first chip name, assuming that all chips |
|---|
| 422 | # in a given "chip" statement need the same specific processing |
|---|
| 423 | $chip = $1; |
|---|
| 424 | $chip =~ s/-.*//; |
|---|
| 425 | undef $chip if $chip eq "*"; |
|---|
| 426 | |
|---|
| 427 | # Remove dashes from chip names, as this is no longer allowed |
|---|
| 428 | s/(\s+"lm78-)j-/$1/g; |
|---|
| 429 | s/(\s+"maxilife-)(cg|co|as|nba)-/$1/g; |
|---|
| 430 | # Simplify possible duplicates |
|---|
| 431 | s/("lm78-\*")(\s+"lm78-\*")+/$1/g; |
|---|
| 432 | s/("maxilife-\*")(\s+"maxilife-\*")+/$1/g; |
|---|
| 433 | |
|---|
| 434 | # "*" is no longer a valid chip name |
|---|
| 435 | s/"\*"/"\*-\*"/g; |
|---|
| 436 | |
|---|
| 437 | print STDERR "Processing chip section: $chip\n" if $chip and $debug; |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | # Drop references to lm78-j |
|---|
| 441 | elsif (m/^\s*#+.*lm78-?j/i) { |
|---|
| 442 | s/(lm78), lm78-?j/$1/gi; |
|---|
| 443 | s/(lm78)-?j/$1/gi; |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | # Drop references to vrm |
|---|
| 447 | elsif (m/^[\s#]*set\s+vrm\s/i |
|---|
| 448 | || m/^\s*#+\s*adjust this if your vid is wrong/i |
|---|
| 449 | || m/^\s*#+\s*Also, one should set vrm prior to using vid in any formula/) { |
|---|
| 450 | $_ = ''; |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | # Drop references to pwm |
|---|
| 454 | elsif (m/^\s*#+\s*PWM Output/i) { |
|---|
| 455 | $_ = ''; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | # Feature name substitution |
|---|
| 459 | elsif (m/^[\s#]*(?:label|ignore|set|compute)\s+(\S+)\s/) { |
|---|
| 460 | if (delete_line($1)) { |
|---|
| 461 | # Delete references to features that are now gone |
|---|
| 462 | $_ = ''; |
|---|
| 463 | } else { |
|---|
| 464 | # Substitute feature names |
|---|
| 465 | $_ = substitute_line($chip, $_); |
|---|
| 466 | } |
|---|
| 467 | } |
|---|