mirror of
https://codeberg.org/scip/note.git
synced 2025-12-17 12:41:10 +01:00
ADDED: The install.sh script for the mysql version is no able to install the
required Mysql module directly from CPAN, thanks to David A. Bandel!
FIXED: The mysql version did not display notes (i.e.: "note 3" did nothing)
CHANGED: Again, the sql-format of the mysql database has been changed. Now
there are only 3 fields, the number filed is the primary key, the id
field in previous versions was a waste of diskspace...
CHANGED: The format of the dump-output has been changed.
ADDED: It is now possible to import previously dumped notes into the notedb
(dumps from both versions are compatible with each other)
FIXED: the function num_bereich() had a bug, which caused ot to ignore under
some circumstances one number (i.e. "note -d 4-13" did nothing).
This commit is contained in:
161
binary-db/note
161
binary-db/note
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# this is the small console program "note" version 0.4
|
||||
# this is the small console program "note" (BINARY version)
|
||||
# It works similar to some well known GUI note programs,
|
||||
# but instead of using X11 it uses the UN*X console.
|
||||
# You can edit existing notes, delete them, create new
|
||||
@@ -57,11 +57,11 @@ sub del;
|
||||
sub display;
|
||||
sub list;
|
||||
sub help;
|
||||
|
||||
sub import;
|
||||
|
||||
use IO::Seekable;
|
||||
|
||||
$version = "0.4 (binary database)";
|
||||
$version = "0.4.1 (binary database)";
|
||||
|
||||
|
||||
# process command line args
|
||||
@@ -135,12 +135,28 @@ else
|
||||
shift;
|
||||
}
|
||||
}
|
||||
elsif($ARGV[0] eq "-D" || $ARGV[0] eq "--Dump" || $ARGV[0] eq "--dump")
|
||||
{
|
||||
$mode = "dump";
|
||||
$dump_file = $ARGV[1];
|
||||
$ARGV[0] = "";
|
||||
}
|
||||
elsif($ARGV[0] eq "-D" || $ARGV[0] eq "--Dump" || $ARGV[0] eq "--dump")
|
||||
{
|
||||
$mode = "dump";
|
||||
$dump_file = $ARGV[1];
|
||||
$ARGV[0] = "";
|
||||
if($dump_file eq "")
|
||||
{
|
||||
$dump_file = "note.dump.$$";
|
||||
print "not dumpfile specified, using $dump_file.\n";
|
||||
}
|
||||
}
|
||||
elsif($ARGV[0] eq "-I" || $ARGV[0] eq "--Import" || $ARGV[0] eq "--import")
|
||||
{
|
||||
$mode = "import";
|
||||
$dump_file = $ARGV[1];
|
||||
$ARGV[0] = "";
|
||||
if($dump_file eq "")
|
||||
{
|
||||
print "No dumpfile specified.\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
elsif($ARGV[0] eq "-v" || $ARGV[0] eq "--version")
|
||||
{
|
||||
print "This is note $version from Thomas Linden <tom\@daemon.de>.\n";
|
||||
@@ -240,6 +256,10 @@ elsif($mode eq "dump")
|
||||
{
|
||||
&dump;
|
||||
}
|
||||
elsif($mode eq "import")
|
||||
{
|
||||
&import;
|
||||
}
|
||||
elsif($mode eq "interactive")
|
||||
{
|
||||
&interactive;
|
||||
@@ -269,12 +289,15 @@ sub display
|
||||
($num, $note, $time) = unpack($typedef, $buffer);
|
||||
$n = ude($note);
|
||||
$t = ude($time);
|
||||
output($num, $n, $t, "SINGLE");
|
||||
print "\n";
|
||||
$match = "yes";
|
||||
if($num)
|
||||
{
|
||||
output($num, $n, $t, "SINGLE");
|
||||
print "\n";
|
||||
$match = 1;
|
||||
}
|
||||
}
|
||||
close(NOTE);
|
||||
if($match eq "")
|
||||
if(!$match)
|
||||
{
|
||||
print "no note with that number found!\n";
|
||||
}
|
||||
@@ -526,14 +549,13 @@ sub dump
|
||||
select DUMP;
|
||||
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
|
||||
seek(NOTE, 0, 0); # START FROM BEGINNING
|
||||
print "complete dump of note database from $time.\n\n";
|
||||
while(read(NOTE, $buffer, $sizeof))
|
||||
{
|
||||
($num, $note, $time) = unpack($typedef, $buffer);
|
||||
$n = ude($note);
|
||||
$t = ude($time);
|
||||
print STDOUT "dumping note number $num to $dump_file\n";
|
||||
print "#$num\ttime: $t\nnote:\n$n\n---------\n\n";
|
||||
print "Number: $num\nTimestamp: $t\n$n\n";
|
||||
}
|
||||
close(NOTE);
|
||||
print "\n";
|
||||
@@ -541,6 +563,80 @@ sub dump
|
||||
select STDOUT;
|
||||
}
|
||||
|
||||
sub import
|
||||
{
|
||||
open (N, "<$NOTEDB") or die "could not open .notedb\n";
|
||||
# since we have not number, look for the next available:
|
||||
seek(N, 0, 0); # START FROM BEGINNING
|
||||
while(read(N, $buff, $sizeof))
|
||||
{
|
||||
($num, $te, $me) = unpack($typedef, $buff);
|
||||
}
|
||||
seek(N, 0, 0);
|
||||
close (N);
|
||||
$num++; # use the highest plus 1
|
||||
|
||||
# open $dump_file and import it into the notedb
|
||||
open (DUMP, "<$dump_file") or die "could not open $dump_file\n";
|
||||
local $complete=0;
|
||||
local $start = 0;
|
||||
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
|
||||
while(<DUMP>)
|
||||
{
|
||||
chomp $_;
|
||||
if($_ =~ /^Number:\s\d+/)
|
||||
{
|
||||
if($start == 0)
|
||||
{
|
||||
# we have no previous record
|
||||
($dummi,$number) = split(/\s/,$_);
|
||||
$start = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
# we got a complete record, save it!
|
||||
|
||||
seek(NOTE, 0, SEEK_END); # APPEND
|
||||
local $n = uen($note);
|
||||
local $t = uen($date);
|
||||
$buffer = pack($typedef, $num, $n, $t);
|
||||
print NOTE $buffer;
|
||||
$num++;
|
||||
|
||||
print "note number $number from $dump_file inserted into notedb.\n";
|
||||
$complete = 0; # restet $complete
|
||||
$note = ""; # reset $note
|
||||
$date = ""; # reset $date
|
||||
($dummi,$number) = split(/\s/,$_);
|
||||
}
|
||||
}
|
||||
elsif($_ =~ /^Timestamp:\s\d+/ && $complete == 0)
|
||||
{
|
||||
($dummi,$date,$time) = split(/\s/,$_);
|
||||
$date = "$date $time";
|
||||
$complete = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$note .= $_ . "\n";
|
||||
}
|
||||
}
|
||||
if($note ne "" && $date ne "")
|
||||
{
|
||||
# the last record, if existent
|
||||
seek(NOTE, 0, SEEK_END); # APPEND
|
||||
local $n = uen($note);
|
||||
local $t = uen($date);
|
||||
$buffer = pack($typedef, $num, $n, $t);
|
||||
print NOTE $buffer;
|
||||
print "note number $number from $dump_file inserted into notedb.\n";
|
||||
close(NOTE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sub interactive
|
||||
@@ -669,8 +765,10 @@ sub interactive
|
||||
|
||||
sub usage
|
||||
{
|
||||
print qq~
|
||||
usage: note [-i | --interactive] | [ options ] [ number [,number...]]
|
||||
print qq~This is the program note $version by Thomas Linden (c) 1999-2000.
|
||||
It comes with absolutely NO WARRANTY. It is distributed under the
|
||||
terms of the GNU General Public License. Use it at your own risk :-)
|
||||
Usage: note [-i | --interactive] | [ options ] [ number [,number...]]
|
||||
Options:
|
||||
-h --help displays this help screen
|
||||
-v --version displays the version number
|
||||
@@ -679,7 +777,10 @@ Options:
|
||||
-s --search <string> searches for <string> trough the notes database
|
||||
-e --edit <number> edit note with <number>
|
||||
-d --delete <number> delete note with <number>
|
||||
-D --Dump <file> dumps the notes to the textfile <file>
|
||||
-D --Dump [<file>] dumps the notes to the textfile <file>
|
||||
-I --Import <file> imports a previously dumped textfile into the
|
||||
note-database. Dumps from the mysql and the binary
|
||||
version are in the same format.
|
||||
-i --interactive interactive mode
|
||||
|
||||
o if you specify only a number (i.e. "note 4"), then the note with that
|
||||
@@ -692,9 +793,6 @@ Options:
|
||||
informations about the configuration.
|
||||
o In interactive mode you can get help at any time by typing "?" or "h" at
|
||||
the prompt.
|
||||
|
||||
This is the program note $version by Thomas Linden (c) 1999-2000. GPL.
|
||||
|
||||
~;
|
||||
exit 1;
|
||||
}
|
||||
@@ -871,9 +969,9 @@ sub ude
|
||||
|
||||
sub num_bereich
|
||||
{
|
||||
# $number is the one we want to delete!
|
||||
# $number is the one we want to delete!
|
||||
# But does it contain kommas?
|
||||
local $m = 0;
|
||||
local $m = 0;
|
||||
if($number =~ /\,/)
|
||||
{
|
||||
# accept -d 3,4,7
|
||||
@@ -883,7 +981,22 @@ sub num_bereich
|
||||
{
|
||||
# accept -d 3-9
|
||||
local @LR = split(/\-/,$number);
|
||||
local @Sorted_LR = sort @LR;
|
||||
local @Sorted_LR = ();
|
||||
|
||||
if($LR[0] > $LR[1])
|
||||
{
|
||||
@Sorted_LR = ($LR[1], $LR[0]);
|
||||
}
|
||||
elsif($LR[0] == $LR[1])
|
||||
{
|
||||
# 0 and 1 are the same
|
||||
@Sorted_LR = ($LR[0], $LR[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@Sorted_LR = ($LR[0], $LR[1]);
|
||||
}
|
||||
|
||||
for($i=$Sorted_LR[0]; $i<=$Sorted_LR[1]; $i++)
|
||||
{
|
||||
# from 3-6 create @NumBlock (3,4,5,6)
|
||||
|
||||
Reference in New Issue
Block a user