#! /usr/local/bin/perl
#!/usr/bin/perl -w
# -*- perl -*-

#
# $Id: smsbbbike,v 1.4 2006/09/21 18:33:20 eserte Exp $
# Author: Slaven Rezic
#
# Copyright (C) 2001 Slaven Rezic. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# Mail: slaven@rezic.de
# WWW:  http://bbbike.sourceforge.net
#

package BBBikeRouting::SMS;
use FindBin;
use lib ($FindBin::RealBin, "$FindBin::RealBin/lib");
use BBBikeRouting;
@ISA = 'BBBikeRouting::Cmdline';
use strict;
require 'cmdbbbike'; # for BBBikeRouting::Cmdline

sub sms_input {
    shift->SUPER::cmdline_input(@_);
}

sub sms_output {
    my $self = shift;

    my $r = $self->{R};

    my $max_length = 160;
    my $message;

    # XXX Define more abbreviation levels and implement it
    for my $abbrev_level (0) {
	$message = "";
	my $first = 1;
	foreach (@{ $r->RouteInfo }) {
	    if ($_->{Street}) {
		if (defined $_->{Way} && $_->{Way} ne '') {
		    $message .= "*" . substr($_->{Way}, -1) . "*";
		} elsif ($first) {
		    $first = 0;
		} else {
		    $message .= ",";
		}
		$message .= Strasse::short($_->{Street}, 3);
	    } else {
		$message .= ":" . $_->{Whole} . ".\n";
	    }
	}

	last if (length($message) <= 160);
    }

    print $message;
    # ja, nein?
#XXX
#      if (0 && ($multi_from || $multi_to)) {
#  	print "Route von $from_street ($from_citypart) nach $to_street ($to_citypart)\n";
#      }
}

return 1 if caller() or keys %Devel::Trace::; # XXX Tracer bug

{
    my $o = {}; # BBBikeRouting::SMS->parse_options;
    my $routing = BBBikeRouting->factory("bike")->init_context;
    my $cmd = BBBikeRouting::SMS->new($routing);
    $cmd->sms_input($o);
    $cmd->search;
    $cmd->sms_output;
}

__END__
