File: getstamps.pl

package info (click to toggle)
muse-el 3.20%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,828 kB
  • sloc: lisp: 12,366; perl: 350; makefile: 222; python: 106; sh: 16
file content (111 lines) | stat: -rw-r--r-- 1,524 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/perl -w --

#
# $Id: getstamps.pl,v 1.3 2007-08-19 13:46:54 welle Exp $
#

# Author: Michael Welle

# This file is available under the terms of the GNU General Public
# License, Version 2.

# Modified by Michael Olson to add Author note. license text, and to
# fix a use of "muse" rather than $muse_file_extension.

#my $tsfile = "/tmp/blog/timestamps";
my $tsfile = "-";
my $muse_file_extension = "muse";

#
#
#
sub process_file {
  my ($file) = @_;


  open( F, "<$file" );

  while ( <F> ) {

    if ( /^#date\s+(.+)$/ ) {

      close ( F );
      my $d = $1;

      $file =~ s/\.${muse_file_extension}$/\.txt/;
      $file =~ s/^\.\///;

      if ( $d =~ /(\d\d\d\d)-(\d\d)-(\d\d)-(\d\d)-(\d\d)/ ) {

	printf TS "${file}=>$2/$3/$1 $4:$5\n";
	return;

      } # if

    } # if

  } # while

  close( F );

} # process_file



#
#
#
sub traverse_directory {
  my ($directory) = @_;
  local *DIR;
  my @files = ();
  my $pfad = "";


  opendir( DIR, $directory );
  @files = readdir( DIR );
  closedir( DIR );


  foreach my $file ( @files ) {

    next if ( !( $file =~ /^.*\.${muse_file_extension}$/ )
	      || ($file eq '.') || ($file eq '..'));


    $path = "$directory/$file";

    if( -d $path ) {

       traverse_directory( $path );

    } else {

      process_file( $path );

    } #if

  } #foreach

} # traverse_directory


#
# Here we go...
#

open( TS, ">${tsfile}" );

if ( @ARGV == 0 ) {

  traverse_directory( "." );

} else {

  traverse_directory( $ARGV[0] );

} #if

close( TS );

exit 0;