WhiteWater.ru конференцияe-mailна главную WW.ru
родео слалом туризм рафтинг снаряжение разное SHOP
 
байдарки | катамараны
  WhiteWater.ru  
   главная  >>  WhiteWater forum


место для вашей рекламы Предыдущие сообщения (до 26.10.00)
за две недели | за месяц | за всё время
#!/usr/bin/perl # # whitewater.ru forum # # wwwindex.pl # List messages within given date range # # Input CGI params: # history -- defines age of messages to show. # History format is: # 'XXd' or 'YYw' or 'ZZm' or 'all' # # Which is: # 'XXd' -- display messages not older than XX DAYS ago # 'YYw' -- .... YY weeks ago # 'ZZm' -- .... ZZ months ago # # If 'history' parameter is omitted, default value # is used. # use strict; use POSIX qw(strftime); # Directory on the server where scripts resides: my $cgidir = extract_path( $0 ); # Load global parameters require "$cgidir/config.pl"; use vars qw($basedir $msgindexfile); # Script specific settings my $default_history = '2d'; ########################################################################### my %cgi_params; my $timestamp; my $history; print "Content-type: text/html\n\n"; %cgi_params = get_cgi_params(); if ( ! defined($cgi_params{'history'}) ) { $history = $default_history; } else { $history = $cgi_params{'history'}; } # check history format if ( $history !~ /^((\d?\dd)|(\d?\dw)|(\d?\dm)|(all))$/ ) { error ("Invalid history format : $history"); } # check prefix number (must be 1 or greater) if ( $history =~ /(\d+)/ ) { if ( $1 <= 0 ) { error ("Invalid history format : $history"); } } # calculate timestamp to limit older messages $timestamp = get_timestamp(); if ( $history =~ /(\d+)d/ ) { $timestamp = timestamp_sub_d( $timestamp, $1 ); } if ( $history =~ /(\d+)w/ ) { $timestamp = timestamp_sub_d( $timestamp, $1*7 ); } if ( $history =~ /(\d+)m/ ) { $timestamp = timestamp_sub_m( $timestamp, $1 ); } # Open message index and list only messages that fit given 'history' open (MSGINDEX, "<$msgindexfile") or error("Failed to open file $msgindexfile"); if ( $history eq 'all' ) { while () { chomp; print "$_\n"; } } else { my $eof = 0; my $str; #мой код my $u1=0; #/мой код while (not $eof) { #мой код ++$u1; if ($u1>1000) { $eof = 1; } #/мой код $str = ; if ( defined $str ) { chomp $str; if ( $str =~ // ) { if (( $1 eq $timestamp ) or ( $1 lt $timestamp )) { $eof = 1; } } print "$str\n"; } else { $eof = 1; } } } close (MSGINDEX); exit; ########################################################################## # extract_path( filename ) # Extract and return path to file 'filename' # NOT including last '/'. # sub extract_path { my $filename; ( $filename ) = @_; $filename =~ s/\/[^\/]*$//; return $filename; } # get_cgi_params() # Read CGI params passed by server # to this script. # # Returns: # a hash set containing cgi params # sub get_cgi_params { my $name; my $value; my $buffer; my $pair; my @pairs; my %params; # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); $buffer .= $ENV{'QUERY_STRING'}; # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Remove any NULL characters $value =~ s/\0//g; $params{$name} = $value; } return %params; } # get_timestamp() # Return current date in the timestamp format (YYYYMMDD) # # Returns: # a timestamp string # sub get_timestamp() { my $ts; $ts = strftime "%Y%m%d", localtime; return $ts; } # timestamp_sub_d( timestamp, num ) # Substract num days from the timestamp. # num must be positive. # # Returns: # string -- modified timestamp # sub timestamp_sub_d { my $timestamp; my $num; ( $timestamp, $num ) = @_; my $year = timestamp_year( $timestamp ); my $month = timestamp_month( $timestamp ); my $day = timestamp_day( $timestamp ); while ( $num > 0 ) { if ( $num < $day ) { $day -= $num; $num = 0; } else { $num -= $day; $month--; if ( $month == 0 ) { $year--; $month = 12; } $day = days_in_month( $year, $month ); } } $timestamp = sprintf "%04u%02u%02u", $year, $month, $day; return $timestamp; } # timestamp_sub_m( timestamp, num ) # Substract num months from the timestamp. # num must be positive. # # Returns: # string -- modified timestamp # sub timestamp_sub_m { my $timestamp; my $num; ( $timestamp, $num ) = @_; my $year = timestamp_year( $timestamp ); my $month = timestamp_month( $timestamp ); my $day = timestamp_day( $timestamp ); while ( $num > 0 ) { if ( $num < $month ) { $month -= $num; $num = 0; } else { $num -= $month; $year--; $month = 12; } } if ( $day > days_in_month( $year, $month ) ) { $day = days_in_month( $year, $month ); } $timestamp = sprintf "%04u%02u%02u", $year, $month, $day; return $timestamp; } # days_in_month( year, month ) # year is a 4 digit year, # month is an integer number (1 -- Jan, .., 12 -- Dec) # # Returns: # number of days in given month of a given year # sub days_in_month { my $year; my $month; ( $year, $month ) = @_; my @days = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); if ( $month != 2 ) { return $days[$month-1]; } if ( ($year % 4) == 0 ) { return 29; } return 28; } # timestamp_year( timestamp ) # # Returns: # year part of timestamp # sub timestamp_year { my $timestamp; ( $timestamp ) = @_; return substr( $timestamp, 0, 4 ); } # timestamp_month( timestamp ) # # Returns: # month part of timestamp # sub timestamp_month { my $timestamp; ( $timestamp ) = @_; return substr( $timestamp, 4, 2 ); } # timestamp_day( timestamp ) # # Returns: # day part of timestamp # sub timestamp_day { my $timestamp; ( $timestamp ) = @_; return substr( $timestamp, 6, 2 ); } # error( msg ) # Report error and exit # sub error { my $msg; ( $msg ) = @_; print "Error: $msg\n"; exit; }

 


обращение
к читателям

форум
куплю/продам

реки