#!/usr/bin/perl -wT # -*- Mode: perl; tab-width: 4; indent-tabs-mode: nil; -*- # # Numbering: An interface to various numbering libraries # # Copyright (c) 2002 by Ian Hickson # # 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 version 2 of the License, 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 use strict; use diagnostics; use lib '.'; use CGI; use HTML::Entities; my %systems = ( 'decimal' => ['Decimal', 'decimal.pm'], 'hebrew' => ['Hebrew', 'hebrew.pm'], ); # get arguments my $query = CGI->new(); my $system = getParam($query, 'system', 'decimal', '[-a-z]+'); my $mode = getParam($query, 'mode', 'list', '[a-z]+'); my $start = getParam($query, 'start', '1', '-?[0-9]+'); my $length = getParam($query, 'length', '10', '[0-9]+'); my $step = getParam($query, 'step', '1', '[0-9]+'); my $execute = getParam($query, 'execute', '', '.*'); if ($length > 10000) { $length = 10000; } # decide what to do if ($execute ne '') { if ($system !~ /^([-a-z]*)$/os or not exists($systems{$system})) { print <[1]; if ($mode eq 'list') { list($system, $start, $length, $step); } elsif ($mode eq 'table') { table($system, $start, $length, $step); } elsif ($mode eq 'entities') { entities($system, $start, $length, $step); } elsif ($mode eq 'codepoints') { codepoints($system, $start, $length, $step); } else { print < Numbering

Numbering

stop } ######################################################################## # Routines # ######################################################################## sub getParam { my($query, $param, $default, $regexp) = @_; my $value = $query->param($param); if (not defined($value) or $value !~ m/^$regexp$/s) { $value = $default; } return $value; } sub list { my($system, $start, $length, $step) = @_; my $convert = $system->can('convertToCodepoints'); my $systemName = encode_entities($systems{$system}->[0]); my $startText = encode_entities($start); print < Numbering: $systemName

$systemName

    stop my $end = $start+$length*$step; my $number = $start; do { my @codepoints = &$convert($number); my $string = ''; foreach my $codepoint (@codepoints) { $string .= '&#x' . sprintf('%04X', $codepoint) . ';' } # note the U+200E LEFT TO RIGHT MARK below to force the bracket to be with the number print <$string ‎($number) stop $number += $step; } while ($number < $end); print <

    stop } sub table { my($system, $start, $length, $step) = @_; my $convert = $system->can('convertToCodepoints'); my $systemName = encode_entities($systems{$system}->[0]); my $startText = encode_entities($start); print < Numbering: $systemName

    $systemName

    stop my $end = $start+$length*$step; my $number = $start; do { my @codepoints = &$convert($number); my $string = ''; foreach my $codepoint (@codepoints) { $string .= '&#x' . sprintf('%04X', $codepoint) . ';' } print < stop $number += $step; } while ($number < $end); print <

    stop } sub codepoints { my($system, $start, $length, $step) = @_; my $convert = $system->can('convertToCodepoints'); print "Content-Type: text/plain; charset=us-sscii\n\n"; my $end = $start+$length*$step; my $number = $start; do { my @codepoints = &$convert($number); foreach my $codepoint (@codepoints) { print 'U+' . sprintf('%04X', $codepoint) . ' '; } print "\n"; $number += $step; } while ($number < $end); } sub entities { my($system, $start, $length, $step) = @_; my $convert = $system->can('convertToCodepoints'); print "Content-Type: text/plain; charset=us-sscii\n\n"; my $end = $start+$length*$step; my $number = $start; do { my @codepoints = &$convert($number); foreach my $codepoint (@codepoints) { print '&#x' . sprintf('%04X', $codepoint) . ';'; } print "\n"; $number += $step; } while ($number < $end); } ########################################################################
    $number$string