Revert f885978c
[lw2-viewer.git] / color-usage-stats.php
blob3a9df233c97a82c1bd6dfea5611d66638124ef0f
1 <?php
3 if (!isset($argv[1]))
4 die;
6 ## Get command line arguments.
7 $stylesheet = file_get_contents($argv[1]);
8 $stylesheet = preg_replace("/\\/\\*.+?\\*\\//", "", $stylesheet);
9 // $stylesheet = preg_replace("/\\s+/", " ", $stylesheet);
11 $style_blocks = [ ];
12 preg_replace_callback("/([^{}]+?){([^}{]+?)}/", 'AggregateStyles', $stylesheet);
13 function AggregateStyles($m) {
14 global $style_blocks;
15 $selectors = explode(",", preg_replace("/,\\s+/", ",", trim($m[1])));
16 $styles = explode(";", preg_replace([ "/\\s+/", "/;\\s+/" ], [ " ", ";" ], rtrim(trim($m[2]), ";")));
17 $style_blocks[] = [ $selectors, $styles ];
18 return $m[0];
21 // print_r($style_blocks);
23 foreach ($style_blocks as $block) {
24 foreach ($block[0] as $selector) {
25 foreach ($block[1] as $style) {
26 list($property, $value) = explode(": ", $style);
27 echo "$selector\t$property\t$value\n";