#
# -*- Perl -*-
# $Id: jeedosaquin.pl,v 1.1.1.1 2008/03/12 10:52:26 makoto Exp $
#
#     This is free software with ABSOLUTELY NO WARRANTY.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either versions 2, or (at your option)
#  any later version.
# 
#  This program is distributed in the hope that it will be useful
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#  02111-1307, USA
#
#  This file must be encoded in EUC-JP encoding
#

package jeedosaquin; # jeedosaquin
use strict;
require 'util.pl';
require 'gfilter.pl';
require 'html.pl';


sub mediatype() {
    return ( 'text/html; x-type=jdsq');
}

sub status() {
    return 'yes';
}

sub recursive() {
    return 0;
}

sub pre_codeconv() {  # Kanji Code conversion is required before this code
    return 1;
}

sub post_codeconv () {
    return 0;
}

sub add_magic ($) {
    my ($magic) = @_;

#    $magic->addSpecials("text/html; x-type=jdsq",
#    '','','','','');

    $magic->addMagicEntry('0	string	\<!--\ jeedosaquin	text/html; x-type=jdsq');
    $magic->addFileExts('\\.jdsq$', 'text/html; x-type=jdsq');
    return;
}


sub filter ($$$$$$$) {
    my ($orig_cfile, $contref, $weighted_str, $headings, $fields, $mother_cfile, $fragment)
      = @_;
    my $cfile = defined $orig_cfile ? $$orig_cfile : '';

#   util::vprint("Processing jeedosaquin,jdsq, file cfile($cfile) mother($mother_cfile) fragment($fragment)...\n");

    get_uri($cfile, $fields,$mother_cfile,$fragment);
#   jdsq_filter($contref, $weighted_str, $fields, $headings, $cfile, 
#	$mark, $end);
    html::html_filter($contref, $weighted_str, $fields, $headings);
#    $fields->{'summary'} = 
#	make_summary($contref, $headings, $cfile, $mark, $end);

    gfilter::line_adjust_filter($contref);
    gfilter::line_adjust_filter($weighted_str);
    gfilter::white_space_adjust_filter($contref);
    gfilter::show_filter_debug_info($contref, $weighted_str,
			   $fields, $headings);
    return undef;
}

# sub hnf_filter ($$$$$$$) {
#    my ($contref, $weighted_str, $fields, $headings, $cfile, $mark, $end) = @_;

#    $$contref =~ s/</&lt;/g;
#    $$contref =~ s/>/&gt;/g;

#    $$contref .= $date;
#}

sub get_uri ($$$$) {

    my ($cfile, $fields,$mother_cfile,$fragment) = @_;

    my ($uri,$dir,$proj);
    my $partial_flag  ;
    if ($cfile =~ /partial.*tmp$/ ) {
	$cfile = $mother_cfile ;
#	$cfile = $mknmz::parent_file_name;  # get previous name
	$partial_flag++;}	
#    }  # use previously  kept name for partial
#    else {  # regular file, not html-split
#	$mknmz::parent_file_name = $cfile;  # keep previous name
#    }
    if ($cfile =~ m|(.*)\.([^/]+)/\d+\.(.*)$|) { # jeedosaquin naming rule
	$dir = $1;
	$proj = $2;
	$uri = $3;

	$fields->{'uri'} = $dir.$proj.'/'.$uri;
	if ($partial_flag) { 
	    $fields->{'uri'} .= '#'.$fragment }
	$fields->{'subject'} = $proj.'/'.$uri;
#    util::vprint("cfile($cfile) uri($uri) fragment($fragment)\n");
    }
#    else {
#    }
}

1;
