#!/usr/local/bin/perl require './config.ph'; $DEBUG = 0; $localtimeshift = '9'; # 時間のシフト @arg = @ARGV; # 引数の保存 if( $ARGV[0] ne '' ){ # 何らかの引数がある print join( ":" , @ARGV ) , "\n" if( $DEBUG ); $write = ">"; while( ( $ARGV[0] ne '' ) && ( $ARGV[0] !~ /^\d/ ) ){ if( $ARGV[0] =~ /^-d$/ ){ # makeup.pl -d DIARY ... print "Prog -d DIA ..\n" if( $DEBUG ); shift @ARGV; $file = shift @ARGV; } elsif( $ARGV[0] =~ /-d(.*)/ ){ # makeup.pl -dDIARY ... print "Prog -dDIA ..\n" if( $DEBUG ); $file = $1; shift @ARGV; } elsif( $ARGV[0] =~ /-f/ ){ # 強制上書きモード $write = ""; } else { # if( $ARGV[0] =~ /\D*/ ){ # makeup.pl DIARY ... # 頭のファイルは日記ファイル print "Prog DIA ..\n" if( $DEBUG ); $file = shift @ARGV; } } print join( ":" , @ARGV ) , "\n" if( $DEBUG ); # 日付の確定 if( $ARGV[0] eq '' ){ # 本日のを更新 ($year , $mon , $day) = newdiarytime(); } else { # 引数の日を更新 ($year , $mon , $day) = @ARGV; if( $year == 0 ){ ($year , $mon , $day) = newdiarytime(); } elsif( $mon == 0 ){ ($tmp1 , $mon , $day) = newdiarytime(); } elsif( $day == 0 ){ ($tmp1 , $tmp2 , $day) = newdiarytime(); } } print ">$file: $year $mon $day\n" if( $DEBUG ); if( ! (-e $file ) ){ # ファイルが存在しないので、エラー print "No File\n" if( $DEBUG ); $ARGV[0] = ''; } else { # ファイルのコピー $dir = $GETDIR; if( $dir !~ /\/$/ ){ $dir .= '/'; } $dir .= $year; if( ! ( -d $dir ) ){ # ディレクトリは存在しない mkdir( $dir , 0755 ); } if($mon<10){$mon2="0".$mon;}else{$mon2=$mon;} if($day<10){$day2="0".$day;}else{$day2=$day;} print "Copy File $file\t-> $year/$mon2$day2\n" if( $DEBUG ); $diary = $dir . "/" . $mon2 . $day2 . ".html" ; # ファイルのコピー open( READ , "< $file" ); open( WRITE , ">$write $diary" ); while( ){ print WRITE; } close( READ ); close( WRITE ); } } else { ($year , $mon , $day) = newdiarytime(); } print "$year $mon $day\n" if( $DEBUG ); exit if ( $DEBUG ); print "$AWKCMD -f config.awk -f mkd.awk $year $mon $day"; exec "$AWKCMD -f config.awk -f mkd.awk $year $mon $day"; # 日記の更新 exit; # ここにはこない sub newdiarytime() { if( $date[5] != 0 ){ return ( $date[5] + 1900 , $date[4] + 1 , $date[3] ); } $time_sec = time(); @date = gmtime( $time_sec + ( $localtimeshift * 3600 ) ); return ( $date[5] + 1900 , $date[4] + 1 , $date[3] ); }