#!/usr/bin/perl 
$css_file = "style.css.org";
$img_dir  = 'img/';
$fc_img_dir = "http://templates.blog.fc2.com/template/sky_cube/";
%conv = ();
$conv{$fc_img_dir} = $img_dir;
$conv{"container"} = "wrapper";
$conv{"#header"} = "\.pageHeader";
$conv{"#main"} = "\.bPosts";
$conv{"#sidemenu1"} = "\.bSideBarLeft";
$conv{"#sidemenu2"} = "\.bSideBarRight";
$conv{"#sidemenu"} = "\.bSideBar";
$conv{"#footer"}   = "\.pageFooter";
$conv{"\.content"} = "\.bPost";
$conv{"h.\.entry_header"} = "\.bTitle";
$conv{"\.entry_body"} = "\.bText";
$conv{"(ul)?\.entry_footer"} = "\.bSmallPrint";
$conv{"p?\.sub_header"} = "\.bCommentTitle";
$conv{"\.sub_body"} = "\.bCommentText";
$conv{"(ul)?\.sub_footer"} = "\.bCommentSmallPrint";
$conv{"\.sidemenu_body"} = "\.bSideItem";
$conv{"\.plg_title"} = "\.sideItemTitle";
$conv{"dl\."} = "\.";

if (! -d $img_dir) {
  mkdir($img_dir);
} else {
  system ("rm $img_dir/*");
}

open LOGF, "< $css_file";
my @lines = <LOGF>;
close(LOGF);


open LOGF, "> style.css";

while ($line = shift @lines) {
   foreach $k (keys %conv) {
      $v = $conv{$k};

      if ($line =~ /$k([^\s|^\)]+)?/ig) {
         if ($k eq $fc_img_dir) {
            $img = $1;
            $url = $k.$img."\n";         
            system("fetch $url"); system("mv $img $img_dir/");
#            print ("fetch $url; mv $img $img_dir/");
         }
         $line =~ s/$k/$v/ig;
      }
      
   }
   print LOGF $line;
}
close(LOGF);

close(LOGF);
