| 1 | # | ||
| 2 | # $Id: Handler.pm,v 1.1.1.1 1998/02/25 21:13:00 schwartz Exp $ | ||
| 3 | # | ||
| 4 | # OLE::Storage::Handler | ||
| 5 | # | ||
| 6 | # Copyright (C) 1996, 1997, 1998 Martin Schwartz | ||
| 7 | # | ||
| 8 | # This program is free software; you can redistribute it and/or modify | ||
| 9 | # it under the terms of the GNU General Public License as published by | ||
| 10 | # the Free Software Foundation; either version 2 of the License, or | ||
| 11 | # (at your option) any later version. | ||
| 12 | # | ||
| 13 | # This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License | ||
| 19 | # along with this program; if not, you should find it at: | ||
| 20 | # | ||
| 21 | # http://wwwwbs.cs.tu-berlin.de/~schwartz/pmh/COPYING | ||
| 22 | # | ||
| 23 | # Contact: schwartz@cs.tu-berlin.de | ||
| 24 | # | ||
| 25 | |||
| 26 | package OLE::Storage::Handler; | ||
| 27 | use strict; | ||
| 28 | my $VERSION=do{my@R=('$Revision: 1.1.1.1 $'=~/\d+/g);sprintf"%d."."%d"x$#R,@R}; | ||
| 29 | my $debug=0; | ||
| 30 | |||
| 31 | # $types = { | ||
| 32 | # 0x1e => { | ||
| 33 | # NAME => "lpstr", | ||
| 34 | # FUNC => { | ||
| 35 | # 0x1e => {CODE => \&store, PAR => undef}, | ||
| 36 | # string => {CODE => \&0x1e_string, PAR => undef}, | ||
| 37 | # } | ||
| 38 | # } | ||
| 39 | # 0x1f => { | ||
| 40 | # NAME => "lpwstr", | ||
| 41 | # FUNC => { | ||
| 42 | # 0x1f => {CODE => \&store, PAR => undef}, | ||
| 43 | # string => {CODE => \&0x1f_string, PAR => undef}, | ||
| 44 | # } | ||
| 45 | # } | ||
| 46 | # string => { | ||
| 47 | # NAME => "string", | ||
| 48 | # FUNC => { | ||
| 49 | # 0x1e => {CODE => \&string_0x1e, PAR => undef}, | ||
| 50 | # 0x1f => {CODE => \&string_0x1f, PAR => undef}, | ||
| 51 | # } | ||
| 52 | # } | ||
| 53 | # } | ||
| 54 | |||
| 55 | sub new { bless ({}, ref($_[0]) || $_[0]) } | ||
| 56 | |||
| 57 | sub add { | ||
| 58 | # | ||
| 59 | # add ($from_type, $from_typestr||"", $to_type, \&sub, $parameter) | ||
| 60 | # add ([$from_type, $from_typestr||"" (,$to_type, \&sub, $parameter)+ ]) | ||
| 61 | # | ||
| 62 | my $S = shift; | ||
| 63 | if (!ref($_[0])) { | ||
| 64 | my ($from, $fromstr, $to, $Sub, $par) = splice(@_, 0, 5); | ||
| 65 | $S -> typestr ($from, $fromstr); | ||
| 66 | $S -> func ($from, $to, $Sub, $par); | ||
| 67 | } else { | ||
| 68 | my $P = shift; | ||
| 69 | my ($from, $fromstr) = splice(@$P, 0, 2); | ||
| 70 | $S -> typestr ($from, $fromstr); | ||
| 71 | while (@$P) { | ||
| 72 | $S->func ($from, splice(@$P, 0, 3)); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | sub convert { | ||
| 78 | my ($S, $from, $to, $bufR, $oR) = splice(@_, 0, 5); | ||
| 79 | my $code; | ||
| 80 | if (!ref($from) && !ref($to)) { | ||
| 81 | $code = $S->code($from, $to); | ||
| 82 | } elsif (!ref($to)) { | ||
| 83 | for (@$from) { | ||
| 84 | $from = $_; | ||
| 85 | last if $code = $S->code($from, $to); | ||
| 86 | } | ||
| 87 | } elsif (!ref($from)) { | ||
| 88 | for (@$to) { | ||
| 89 | $to = $_; | ||
| 90 | last if $code = $S->code($from, $to); | ||
| 91 | } | ||
| 92 | } else { | ||
| 93 | my $fromR = $from; $from = undef; | ||
| 94 | for (@$to) { | ||
| 95 | $to = $_; | ||
| 96 | for (@$fromR) { | ||
| 97 | if ($code = $S->code($_, $to)) { | ||
| 98 | $from = $_; last; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | last if $from; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | if ($code) { | ||
| 105 | &$code ($bufR, $oR, $S->par($from, $to), @_); | ||
| 106 | } else { | ||
| 107 | if ($debug) { | ||
| 108 | # The line number will not be correctly for access without "tie"... | ||
| 109 | my ($package, $filename, $line) = caller(3); | ||
| 110 | print "$filename line $line: Cannot convert \"$from\" to \"$to\".\n"; | ||
| 111 | } | ||
| 112 | ""; | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | # | ||
| 117 | # Member methods | ||
| 118 | # | ||
| 119 | |||
| 120 | sub func { | ||
| 121 | my ($S, $from, $to, $Sub, $par) = @_; | ||
| 122 | $S->par ($from, $to, $par); | ||
| 123 | $S->code ($from, $to, $Sub); | ||
| 124 | } | ||
| 125 | |||
| 126 | sub code { | ||
| 127 | my ($S, $from, $to, $Sub) = @_; | ||
| 128 | $S->{$from}->{FUNC}->{$to}->{CODE} = $Sub if defined $Sub; | ||
| 129 | $S->{$from}->{FUNC}->{$to}->{CODE}; | ||
| 130 | } | ||
| 131 | |||
| 132 | sub par { | ||
| 133 | my ($S, $from, $to, $par) = @_; | ||
| 134 | $S->{$from}->{FUNC}->{$to}->{PAR} = $par if defined $par; | ||
| 135 | $S->{$from}->{FUNC}->{$to}->{PAR}; | ||
| 136 | } | ||
| 137 | |||
| 138 | sub typestr { | ||
| 139 | # | ||
| 140 | # typestr ($type, $typestr||"") | ||
| 141 | # | ||
| 142 | my ($S, $type, $typestr) = @_; | ||
| 143 | $S->{$type}->{NAME} = $typestr if $typestr; | ||
| 144 | $S->{$type}->{NAME}; | ||
| 145 | } | ||
| 146 | |||
| 147 | "Atomkraft? Nein, danke!" | ||
| 148 | |||
| 149 | __END__ |