]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
merge to basewiki
[ikiwiki.git] / IkiWiki.pm
index 2d692a9784e67548382e0e5e36252f5992b5eb48..32ca0449fb81c4c59db6a3548f713e86e11b43bf 100644 (file)
@@ -231,9 +231,10 @@ sub srcfile ($) { #{{{
        error("internal error: $file cannot be found");
 } #}}}
 
-sub readfile ($;$) { #{{{
+sub readfile ($;$$) { #{{{
        my $file=shift;
        my $binary=shift;
+       my $wantfd=shift;
 
        if (-l $file) {
                error("cannot read a symlink ($file)");
@@ -242,16 +243,18 @@ sub readfile ($;$) { #{{{
        local $/=undef;
        open (IN, $file) || error("failed to read $file: $!");
        binmode(IN) if ($binary);
+       return \*IN if $wantfd;
        my $ret=<IN>;
        close IN;
        return $ret;
 } #}}}
 
-sub writefile ($$$;$) { #{{{
+sub writefile ($$$;$$) { #{{{
        my $file=shift; # can include subdirs
        my $destdir=shift; # directory to put file in
        my $content=shift;
        my $binary=shift;
+       my $wantfd=shift;
        
        my $test=$file;
        while (length $test) {
@@ -274,6 +277,7 @@ sub writefile ($$$;$) { #{{{
        
        open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!");
        binmode(OUT) if ($binary);
+       return \*OUT if $wantfd;
        print OUT $content;
        close OUT;
 } #}}}
@@ -850,23 +854,35 @@ sub pagespec_translate ($) { #{{{
                        $code.=" match_$1(\$page, ".safequote($2).")";
                }
                else {
-                       $code.=" match_glob(\$page, ".safequote($word).")";
+                       $code.=" match_glob(\$page, ".safequote($word).", \$from)";
                }
        }
 
        return $code;
 } #}}}
 
-sub pagespec_match ($$) { #{{{
+sub pagespec_match ($$;$) { #{{{
        my $page=shift;
        my $spec=shift;
+       my $from=shift;
+       if (! defined $from){
+               $from = "";
+       }
 
        return eval pagespec_translate($spec);
 } #}}}
 
-sub match_glob ($$) { #{{{
+sub match_glob ($$$) { #{{{
        my $page=shift;
        my $glob=shift;
+       my $from=shift;
+
+       # relative matching
+       if ($glob =~ m!^\./!) {
+               $from=~s!/?[^/]+$!!;
+               $glob=~s!^\./!!;
+               $glob="$from/$glob" if length $from;
+       }
 
        # turn glob into safe regexp
        $glob=quotemeta($glob);