The XYZ funcs for serials seqs
[koha.git] / C4 / Bull.pm
1 package C4::Bull; #assumes C4/Bull.pm
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 require Exporter;
23
24 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
25
26 # set the version for version checking
27 $VERSION = 0.01;
28
29 =head1 NAME
30
31 C4::Bull - Give functions for serializing.
32
33 =head1 SYNOPSIS
34
35   use C4::Bull;
36
37 =head1 DESCRIPTION
38
39 Give all XYZ functions
40
41 =cut
42
43 @ISA = qw(Exporter);
44 @EXPORT = qw(&Initialize_Sequence &Find_Next_Date, &Get_Next_Seq);
45
46 # FIXME - Retirer ce FIXME il ne sert pas. 
47
48 sub GetValue(@) {
49     my $seq = shift;
50     my $X = shift;
51     my $Y = shift;
52     my $Z = shift;
53
54     return $X if ($seq eq 'X');
55     return $Y if ($seq eq 'Y');
56     return $Z if ($seq eq 'Z');
57     return "5 Syntax Error in Sequence";
58 }
59
60
61 sub Initialize_Sequence(@) {
62     my $sequence = shift;
63     my $X = shift;
64     my $Xstate = shift;
65     my $Xfreq = shift;
66     my $Xstep = shift;
67     my $Y = shift;
68     my $Ystate = shift;
69     my $Yfreq = shift;
70     my $Ystep = shift;
71     my $Z = shift;
72     my $Zstate = shift;
73     my $Zfreq = shift;
74     my $Zstep = shift;
75     my $finalstring = "";
76     my @string = split //, $sequence;
77     my $etat = 0;
78     
79     for (my $i = 0; $i < (scalar @string); $i++)
80     {
81         if ($string[$i] ne '{')
82             {
83                     if (!$etat)
84                             {
85                                 $finalstring .= $string[$i];
86                                     }
87                         else
88                                 {
89                                     return "1 Syntax Error in Sequence";
90                                         }
91                     }
92         else
93             {
94 #     if ($string[$i + 1] eq '\'')
95 #     {
96 # return "2 Syntax Error in Sequence"
97 #     if ($string[$i + 2] ne 'X' && $string[$i + 2] ne 'Y' && $string[$i + 2] ne 'Z');
98
99 # $finalstring .= GetValueAsc($string[$i + 2], $X, $Y, $Z);
100 # $i += 3;
101 #     }
102 #     else
103 #     {
104                 return "3 Syntax Error in Sequence"
105                         if ($string[$i + 1] ne 'X' && $string[$i + 1] ne 'Y' && $string[$i + 1] ne 'Z');
106
107                     
108                 $finalstring .= GetValue($string[$i + 1], $X, $Y, $Z);
109                 $i += 2;
110 #     }
111                 }
112     }
113     return "$finalstring";
114 }
115
116 sub Find_Next_Date(@) {
117     return "2004-29-03";
118 }
119
120 sub Step(@) {
121     my $X = shift;
122     my $Xstate = shift;
123     my $Xfreq = shift;
124     my $Xstep = shift;
125     my $Y = shift;
126     my $Ystate = shift;
127     my $Yfreq = shift;
128     my $Ystep = shift;
129     my $Z = shift;
130     my $Zstate = shift;
131     my $Zfreq = shift;
132     my $Zstep = shift;
133     my $Xpos = shift;
134     my $Ypos = shift;
135     my $Zpos = shift;
136     
137     
138     $X += $Xstep if ($Xstate == 1);
139     if ($Xstate == 2) { $Xpos += 1; if ($Xpos >= $Xfreq) {
140         $Xpos = 0; $X += $Xstep; } }
141
142     $Y += $Ystep if ($Ystate == 1);
143     if ($Ystate == 2) { $Ypos += 1; if ($Ypos >= $Yfreq) {
144         $Ypos = 0; $Y += $Ystep; } }
145
146     $Z += $Zstep if ($Zstate == 1);
147     if ($Zstate == 2) { $Zpos += 1; if ($Zpos >= $Zfreq) {
148         $Zpos = 0; $Z += $Zstep; } }
149     
150 #    $Y += $Ystep; if ($Ystate == 1);
151  #   if ($Ystate == 2) { $Ypos += 1; if ($Ypos >= $Yfreq) {
152         #$Ypos = 0; $Y += $Ystep; } }
153
154
155    # $Z += $Zstep; if ($Zstate == 1);
156    # if ($Zstate == 2) { $Zpos += 1; if ($Zpos >= $Zfreq) {
157 #       $Zpos = 0; $Z += $Zstep; } }
158
159     return ($X, $Y, $Z, $Xpos, $Ypos, $Zpos);
160 }
161
162 sub Get_Next_Seq(@) {
163     my $sequence = shift;
164     my $X = shift;
165     my $Xfreq = shift;
166     my $Xstep = shift;
167     my $Xstate = shift;
168     my $Y = shift;
169     my $Yfreq = shift;
170     my $Ystep = shift;
171     my $Ystate = shift;
172     my $Z = shift;
173     my $Zfreq = shift;
174     my $Zstep = shift;
175     my $Zstate = shift;
176     my $Xpos = shift;
177     my $Ypos = shift;
178     my $Zpos = shift;
179
180     return ("$sequence", $X, $Y, $Z)
181         if (!defined($X) && !defined($Y) && !defined($Z));
182     ($X, $Y, $Z, $Xpos, $Ypos, $Zpos) = 
183         Step($X, $Xstate, $Xfreq, $Xstep, $Y, $Ystate, $Yfreq, 
184                   $Ystep, $Z, $Zstate, $Zfreq, $Zstep, $Xpos, $Ypos, $Zpos);
185     return (Initialize_Sequence($sequence, $X, $Xstate,
186                                 $Xfreq, $Xstep, $Y, $Ystate, $Yfreq,
187                                 $Ystep, $Z, $Zstate, $Zfreq, $Zstep),
188                 $X, $Y, $Z, $Xpos, $Ypos, $Zpos);
189 }
190
191 END { }       # module clean-up code here (global destructor)