~ubuntu-branches/ubuntu/saucy/note/saucy

« back to all changes in this revision

Viewing changes to .pc/03-dbm_manpage_spelling.patch/NOTEDB/dbm.pm

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre De Dommelin
  • Date: 2011-02-12 14:17:24 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110212141724-gpb2zl87jf8z535w
Tags: 1.3.7-1
* New upstream release
* Bump to Standards-Version 3.9.1 (no changes needed)
* Simplified debian/rules file 
* Various cleanup in debian/
* Added DEP-3 headers to debian/patches/*
* Fixed spelling in manpages 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# $Id: dbm.pm,v 1.3 2000/08/11 00:05:58 zarahg Exp $
 
3
# Perl module for note
 
4
# DBM database backend. see docu: perldoc NOTEDB::dbm
 
5
#
 
6
 
 
7
package NOTEDB::dbm;
 
8
 
 
9
$NOTEDB::dbm::VERSION = "1.40";
 
10
 
 
11
use DB_File;
 
12
use NOTEDB;
 
13
use strict;
 
14
use Exporter ();
 
15
use vars qw(@ISA @EXPORT %note %date);
 
16
@ISA = qw(NOTEDB Exporter);
 
17
 
 
18
 
 
19
 
 
20
 
 
21
 
 
22
 
 
23
sub new
 
24
{
 
25
    my($this, %param) = @_;
 
26
    my $class = ref($this) || $this;
 
27
    my $self = {};
 
28
    bless($self,$class);
 
29
 
 
30
    my $notefile = "note.dbm";
 
31
    my $timefile = "date.dbm";
 
32
    my $dbm_dir  = $param{directory} || File::Spec->catfile($ENV{HOME}, ".note_dbm");
 
33
 
 
34
    if (! -d $dbm_dir) {
 
35
      # try to make it
 
36
      mkdir $dbm_dir || die "Could not create $dbm_dir: $!\n";
 
37
    }
 
38
 
 
39
    tie %note,  "DB_File", "$dbm_dir/$notefile"  || die "Could not tie $dbm_dir/$notefile: $!\n";
 
40
    tie %date,  "DB_File", "$dbm_dir/$timefile"  || die "Could not tie $dbm_dir/$timefile: $!\n";
 
41
 
 
42
    $self->{LOCKFILE} = $param{dbname} . "~LOCK";
 
43
 
 
44
    return $self;
 
45
}
 
46
 
 
47
 
 
48
sub DESTROY
 
49
{
 
50
    # clean the desk!
 
51
    untie %note, %date;
 
52
}
 
53
 
 
54
sub version {
 
55
    my $this = shift;
 
56
    return $this->{version};
 
57
}
 
58
 
 
59
 
 
60
sub get_single
 
61
{
 
62
    my($this, $num) = @_;
 
63
    my($note, $date);
 
64
    return $this->ude ($note{$num}), $this->ude($date{$num});
 
65
}
 
66
 
 
67
 
 
68
sub get_all
 
69
{
 
70
    my $this = shift;
 
71
    my($num, $note, $date, %res, $real);
 
72
    foreach $num (sort {$a <=> $b} keys %date) {
 
73
        $res{$num}->{'note'} = $this->ude($note{$num});
 
74
        $res{$num}->{'date'} = $this->ude($date{$num});
 
75
    }
 
76
    return %res;
 
77
}
 
78
 
 
79
sub import_data {
 
80
  my ($this, $data) = @_;
 
81
  foreach my $num (keys %{$data}) {
 
82
    my $pos = $this->get_nextnum();
 
83
    $note{$pos} = $this->ude($note{$num}->{note});
 
84
    $date{$pos} = $this->ude($date{$num}->{date});
 
85
  }
 
86
}
 
87
 
 
88
sub get_nextnum
 
89
{
 
90
    my($this, $num);
 
91
    foreach (sort {$a <=> $b} keys %date) {
 
92
        $num = $_;
 
93
    }
 
94
    $num++;
 
95
    return $num;
 
96
}
 
97
 
 
98
sub get_search
 
99
{
 
100
    my($this, $searchstring) = @_;
 
101
    my($num, $note, $date, %res, $match);
 
102
 
 
103
    my $regex = $this->generate_search($searchstring);
 
104
    eval $regex;
 
105
    if ($@) {
 
106
        print "invalid expression: \"$searchstring\"!\n";
 
107
        return;
 
108
    }
 
109
    $match = 0;
 
110
    foreach $num (sort {$a <=> $b} keys %date) {
 
111
        $_ = $this->ude($note{$num});
 
112
        eval $regex;
 
113
        if ($match) {
 
114
            $res{$num}->{'note'} = $this->ude($note{$num});
 
115
            $res{$num}->{'date'} = $this->ude($date{$num});
 
116
        }
 
117
        $match = 0;
 
118
    }
 
119
 
 
120
    return %res;
 
121
}
 
122
 
 
123
 
 
124
 
 
125
sub set_recountnums
 
126
{
 
127
    my $this = shift;
 
128
    my(%Note, %Date, $num, $setnum);
 
129
    $setnum = 1;
 
130
    foreach $num (sort {$a <=> $b} keys %note) {
 
131
        $Note{$setnum} = $note{$num};
 
132
        $Date{$setnum} = $date{$num};
 
133
        $setnum++;
 
134
    }
 
135
    %note = %Note;
 
136
    %date = %Date;
 
137
}
 
138
 
 
139
 
 
140
 
 
141
sub set_edit
 
142
{
 
143
    my($this, $num, $note, $date) = @_;
 
144
    $note{$num} = $this->uen($note);
 
145
    $date{$num} = $this->uen($date);
 
146
}
 
147
 
 
148
 
 
149
sub set_new
 
150
{
 
151
    my($this, $num, $note, $date) = @_;
 
152
    $this->set_edit($num, $note, $date); # just the same thing
 
153
}
 
154
 
 
155
 
 
156
sub set_del
 
157
{
 
158
    my($this, $num) = @_;
 
159
    my($note, $date, $T);
 
160
    ($note, $date) = $this->get_single($num);
 
161
    return "ERROR"  if ($date !~ /^\d/);
 
162
    delete $note{$num};
 
163
    delete $date{$num};
 
164
}
 
165
 
 
166
sub set_del_all
 
167
{
 
168
    my($this) = @_;
 
169
    %note = ();
 
170
    %date = ();
 
171
    return;
 
172
}
 
173
 
 
174
sub uen
 
175
{
 
176
    my $this = shift;
 
177
    my($T);
 
178
    if($NOTEDB::crypt_supported == 1) {
 
179
        eval {
 
180
            $T = pack("u", $this->{cipher}->encrypt($_[0]));
 
181
        };
 
182
    }
 
183
    else {
 
184
        $T = $_[0];
 
185
    }
 
186
    chomp $T;
 
187
    return $T;
 
188
}
 
189
 
 
190
sub ude
 
191
{
 
192
    my $this = shift;
 
193
    my($T);
 
194
    if($NOTEDB::crypt_supported == 1) {
 
195
        eval {
 
196
            $T = $this->{cipher}->decrypt(unpack("u",$_[0]))
 
197
        };
 
198
        return $T;
 
199
    }
 
200
    else {
 
201
        return $_[0];
 
202
    }
 
203
}
 
204
 
 
205
 
 
206
 
 
207
1; # keep this!
 
208
 
 
209
__END__
 
210
 
 
211
=head1 NAME
 
212
 
 
213
NOTEDB::dbm - module lib for accessing a notedb from perl
 
214
 
 
215
=head1 SYNOPSIS
 
216
 
 
217
        # include the module
 
218
        use NOTEDB;
 
219
        
 
220
        # create a new NOTEDB object (the last 4 params are db table/field names)
 
221
        $db = new NOTEDB("mysql","note","/home/user/.notedb/");
 
222
 
 
223
        # get a single note
 
224
        ($note, $date) = $db->get_single(1);
 
225
 
 
226
        # search for a certain note 
 
227
        %matching_notes = $db->get_search("somewhat");
 
228
        # format of returned hash:
 
229
        #$matching_notes{$numberofnote}->{'note' => 'something', 'date' => '23.12.2000 10:33:02'}
 
230
 
 
231
        # get all existing notes
 
232
        %all_notes = $db->get_all();
 
233
        # format of returnes hash like the one from get_search above
 
234
 
 
235
        # get the next noteid available
 
236
        $next_num = $db->get_nextnum();
 
237
 
 
238
        # recount all noteids starting by 1 (usefull after deleting one!)
 
239
        $db->set_recountnums();
 
240
 
 
241
        # modify a certain note
 
242
        $db->set_edit(1, "any text", "23.12.2000 10:33:02");
 
243
 
 
244
        # create a new note
 
245
        $db->set_new(5, "any new text", "23.12.2000 10:33:02");
 
246
 
 
247
        # delete a certain note
 
248
        $db->set_del(5);
 
249
 
 
250
=head1 DESCRIPTION
 
251
 
 
252
You can use this module for accessing a note database. This is the dbm module.
 
253
It uses the DB_FILE module to store it's data and it uses DBM files for tis purpose.
 
254
 
 
255
Currently, NOTEDB module is only used by note itself. But feel free to use it
 
256
within your own project! Perhaps someone want to implement a webinterface to
 
257
note...
 
258
 
 
259
=head1 USAGE
 
260
 
 
261
please see the section SYNOPSIS, it says it all.
 
262
 
 
263
=head1 AUTHOR
 
264
 
 
265
Thomas Linden <tom@daemon.de>.
 
266
 
 
267
 
 
268
 
 
269
=cut