mirror of
https://codeberg.org/scip/note.git
synced 2025-12-17 12:41:10 +01:00
CHANGED: it uses no more a mysql database, but a binary file instead.
This is much faster! ADDED: note can display the notes with colors, it is turned off by default
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
0.3:
|
||||||
|
CHANGED: it uses no more a mysql database, but a binary file instead.
|
||||||
|
This is much faster!
|
||||||
|
ADDED: note can display the notes with colors, it is turned off by default
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
0.2:
|
0.2:
|
||||||
FIXED: now any occurence of ' will be masked with \' before storage
|
FIXED: now any occurence of ' will be masked with \' before storage
|
||||||
to the mysql database.
|
to the mysql database.
|
||||||
|
|||||||
130
README
130
README
@@ -1,4 +1,4 @@
|
|||||||
note 0.1 by Thomas Linden, 1999
|
note note-0.3 by Thomas Linden, 01/2000
|
||||||
|
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
@@ -8,18 +8,16 @@ Introduction
|
|||||||
perl, which allows you to manage notes similar
|
perl, which allows you to manage notes similar
|
||||||
to programs like "knotes" from commandline.
|
to programs like "knotes" from commandline.
|
||||||
|
|
||||||
|
This version is completely rewritten and it is
|
||||||
|
able to display colored output.
|
||||||
|
|
||||||
You can add, edit, list and delete as many notes
|
You can add, edit, list and delete as many notes
|
||||||
as you want. The notes are stored in a mysql
|
as you want. The notes are stored in a binary
|
||||||
database. You might think, "what an overkill...",
|
database. Unlike previous versions of note this
|
||||||
but doing it this way provides some important
|
version don't need a database server. All you need
|
||||||
advantages:
|
is perl and this script (and, of course, some free
|
||||||
o data integrity
|
disk space for the file...).
|
||||||
o no need of another proprietary file format
|
|
||||||
o no new engine to maintain this file format
|
|
||||||
o speed
|
|
||||||
o portability
|
|
||||||
o availability
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
@@ -27,51 +25,27 @@ Requirements
|
|||||||
|
|
||||||
You need the following things:
|
You need the following things:
|
||||||
o perl installed (5.004x)
|
o perl installed (5.004x)
|
||||||
o mysql database installed and running
|
o The module IO::Seekable, which should be
|
||||||
o Mysql perlmodule (you can find it on
|
already installed with your perl distributuion.
|
||||||
http://www.mysql.org) PLEASE NOTE:
|
|
||||||
It needs the Module "Mysql". Newer versions
|
|
||||||
are DBI, which you can also use to access
|
|
||||||
mysql databases. If you want to use it, you
|
|
||||||
have to rewrite the program. Please let me
|
|
||||||
know, if you did it :-)
|
|
||||||
o permissions to create a new database and
|
|
||||||
to write data to this database.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
============
|
============
|
||||||
|
|
||||||
First, make sure all these things above are ok.
|
Simple: Copy it to a place inside your $PATH,
|
||||||
You can use the script "install.sh" to create a new
|
probably as root. (for example to /usr/bin).
|
||||||
database and the table structure. You might edit
|
|
||||||
the script before running it.
|
|
||||||
|
|
||||||
If you getting trouble, i.e. if you have not the
|
|
||||||
required permissions to do that, please make sure,
|
|
||||||
you can.
|
|
||||||
As user root, you have to give your username the
|
|
||||||
neccessary permissions. Please refer to the mysql
|
|
||||||
documentation, how to do that.
|
|
||||||
After that repeat the step above.
|
|
||||||
|
|
||||||
As root, copy the perl-script "note" to /usr/bin.
|
|
||||||
|
|
||||||
This should be all.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
|
||||||
If you created the database with install.sh, you
|
This version of note doesn't neccessarily need
|
||||||
do not need to do anything further. Simply run
|
a configuration file. But you can have one and change
|
||||||
"note" without any commandline parameters. It will
|
some default values. Take a look to the file noterc
|
||||||
create a configfile ~/.noterc for you.
|
provided with this tarball. There are detailed instructions
|
||||||
You might take a look to this file and change something,
|
about every available parameter.
|
||||||
if neccessary.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -82,7 +56,8 @@ Usage
|
|||||||
It will tell you all available commandline options.
|
It will tell you all available commandline options.
|
||||||
|
|
||||||
To create a new note, simply run "note". You can enter
|
To create a new note, simply run "note". You can enter
|
||||||
the note (there is no limitation on length of the note).
|
the note (the length is by default limited to 1024 bytes,
|
||||||
|
which you can change from your config file).
|
||||||
End by typing a . on a line itself. note will tell you the
|
End by typing a . on a line itself. note will tell you the
|
||||||
number of the note.
|
number of the note.
|
||||||
|
|
||||||
@@ -98,7 +73,11 @@ Usage
|
|||||||
will store the changed note to the database.
|
will store the changed note to the database.
|
||||||
|
|
||||||
Of course you can drop a certain note: "note -d 1" deletes
|
Of course you can drop a certain note: "note -d 1" deletes
|
||||||
note number 1.
|
note number 1. If a note in the middle or the beginning of
|
||||||
|
the database will be deleted, note will recount the other
|
||||||
|
existent notes. For example there are 3 notes, number 1, 2
|
||||||
|
and 3. If you delete number 2, then number 3 will become
|
||||||
|
number 2.
|
||||||
|
|
||||||
If you cannot remember, which note you are looking for, you
|
If you cannot remember, which note you are looking for, you
|
||||||
can use the search capability of note: "note -s <searchstring>".
|
can use the search capability of note: "note -s <searchstring>".
|
||||||
@@ -109,6 +88,58 @@ Usage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Format of the notedb
|
||||||
|
====================
|
||||||
|
|
||||||
|
The database where the notes are stored is a binary file of
|
||||||
|
the following format:
|
||||||
|
It consists of three fixed length fields per entry. The fields
|
||||||
|
have the following types:
|
||||||
|
o Number: Integer (1 byte)
|
||||||
|
o Note: String (default 1024 bytes)
|
||||||
|
o Time: String (default 64 bytes)
|
||||||
|
You can change the sizes of the fields "Note" and "Time" in
|
||||||
|
the configfile "~/.noterc". If it does not exist, the above
|
||||||
|
defaults will be used.
|
||||||
|
If the data to be stored is smaller then the size of the field,
|
||||||
|
it will be filled with ZERO's ("\0"). The Note and the Time
|
||||||
|
fields will be uuencoded before storage. Of course, this is
|
||||||
|
no security, never mind...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Security
|
||||||
|
========
|
||||||
|
|
||||||
|
If you want to protect the notedb against unauthorized persons
|
||||||
|
(even root), you might want to use pgp. I use gpg (GNU privacy
|
||||||
|
guard), which is compatible to pgp, usage should be similar.
|
||||||
|
You could add a function to your .profile or .bashrc or whatever:
|
||||||
|
--- snip ---
|
||||||
|
function note
|
||||||
|
{
|
||||||
|
gpg -o ~/.notedb -d ~/.notedb.gpg
|
||||||
|
note $1 $2 $3
|
||||||
|
gpg -e ~/.notedb --yes -r username
|
||||||
|
rm -rf ~/.notedb
|
||||||
|
}
|
||||||
|
--- snip ---
|
||||||
|
You should replace <username> with your real username. After applying
|
||||||
|
this function to your .profile, issue the following command:
|
||||||
|
"source .profile"
|
||||||
|
You shell will reread the file, so you can try it out without the need
|
||||||
|
of new login.
|
||||||
|
This function assumes, there exists a file called "~/.notedb.gpg",
|
||||||
|
therefore you need to encrypt your notedb once before you can use this
|
||||||
|
funcion:
|
||||||
|
"gpg -e ~/.notedb --yes -r username"
|
||||||
|
|
||||||
|
If you don't make use of encryption, I suggest you to chmod it:
|
||||||
|
"chmod 600 .notedb"
|
||||||
|
So, only you can read the file (and root or any intruder who became root).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Comments
|
Comments
|
||||||
========
|
========
|
||||||
|
|
||||||
@@ -128,7 +159,7 @@ License
|
|||||||
Author
|
Author
|
||||||
======
|
======
|
||||||
|
|
||||||
The author os Thomas Linden.
|
The author is Thomas Linden.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -136,5 +167,4 @@ Author
|
|||||||
Last changed
|
Last changed
|
||||||
============
|
============
|
||||||
|
|
||||||
07.11.1999
|
09.01.2000
|
||||||
|
|
||||||
|
|||||||
491
note
491
note
@@ -1,52 +1,58 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
# this is the small console program "note"
|
#
|
||||||
|
# this is the small console program "note" version 0.3
|
||||||
# It works similar to some well known GUI note programs,
|
# It works similar to some well known GUI note programs,
|
||||||
# but instead of using X11 it uses the UN*X console.
|
# but instead of using X11 it uses the UN*X console.
|
||||||
# You can edit existing notes, delete them, create new
|
# You can edit existing notes, delete them, create new
|
||||||
# ones and, of course display them.
|
# ones and, of course display them.
|
||||||
# The notes will be stored in a mysql database. Refer to
|
# The notes will be stored in a binary data file (~/.notedb)
|
||||||
# the README of the desitribution for details about
|
#
|
||||||
# installation.
|
# Previous versions needed a mysql database. This is no more
|
||||||
# It requires a configfile named .noterc in the users home.
|
# the case.
|
||||||
# If it does not exist, note will create one for you, which
|
# If there exists a configfile called ~/.noterc then it will
|
||||||
# you will have to edit.
|
# be processed. You can overwrite some default values of note.
|
||||||
#
|
#
|
||||||
# If you find it usefull or find a bug, please let me know:
|
# If you find it usefull or find a bug, please let me know:
|
||||||
# Thomas Linden <tom@daemon.de>
|
# Thomas Linden <tom@daemon.de>
|
||||||
#
|
|
||||||
# note is GPL software.
|
|
||||||
|
|
||||||
|
|
||||||
use Mysql;
|
#################################################
|
||||||
|
|
||||||
##################################
|
|
||||||
# define some default values.
|
# define some default values.
|
||||||
# don't change them, instead use the config file!
|
# You can change them, but be carefull!
|
||||||
|
# Instead you can define each of them in a configfile
|
||||||
|
# called ~/.noterc.
|
||||||
|
$MAX_NOTE = 1024;
|
||||||
|
$MAX_TIME = 64;
|
||||||
|
|
||||||
$version = "0.1";
|
$maxlen = 30;
|
||||||
$date = `date +%e\".\"%m\".\"%Y\" \"%T`;
|
|
||||||
chomp $date;
|
|
||||||
|
|
||||||
$USER = getlogin || getpwuid($<);
|
|
||||||
chomp $USER;
|
|
||||||
|
|
||||||
$HOME = `echo \$HOME`;
|
$HOME = `echo \$HOME`;
|
||||||
chomp $HOME;
|
chomp $HOME;
|
||||||
|
|
||||||
$CONF = $HOME . "/.noterc";
|
$CONF = $HOME . "/.noterc";
|
||||||
|
|
||||||
$DEFAULTDBNAME = $USER . "_note";
|
$NOTEDB = $HOME . "/.notedb";
|
||||||
$dbhost = "";
|
|
||||||
$dbuser = "";
|
$COLOR = "NO";
|
||||||
$dbpasswd = "";
|
# if $COLOR equals NO, then the following color-definitions
|
||||||
$dbname = "";
|
# will be replaced by "".
|
||||||
$dbname = "";
|
$BORDER_COLOR = "BLACK";
|
||||||
$searchstring = "";
|
$NUM_COLOR = "blue";
|
||||||
###################################
|
$NOTE_COLOR = "magenta";
|
||||||
|
$TIME_COLOR = "black";
|
||||||
|
#################################################
|
||||||
|
|
||||||
|
|
||||||
sub usage;
|
sub usage;
|
||||||
sub find_editor;
|
sub find_editor;
|
||||||
|
sub output;
|
||||||
|
sub C;
|
||||||
|
sub uen;
|
||||||
|
sub ude;
|
||||||
|
|
||||||
|
use IO::Seekable;
|
||||||
|
|
||||||
|
$version = "0.3 (binary database)";
|
||||||
|
|
||||||
# process command line args
|
# process command line args
|
||||||
if($ARGV[0] eq "")
|
if($ARGV[0] eq "")
|
||||||
@@ -110,7 +116,7 @@ else
|
|||||||
}
|
}
|
||||||
elsif($ARGV[0] eq "-v" || $ARGV[0] eq "--version")
|
elsif($ARGV[0] eq "-v" || $ARGV[0] eq "--version")
|
||||||
{
|
{
|
||||||
print "note $version\nfrom Thomas Linden <tom\@daemon.de>\n";
|
print "This is note $version from Thomas Linden <tom\@daemon.de>.\n";
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
elsif($ARGV[0] eq "-h" || $ARGV[0] eq "--help")
|
elsif($ARGV[0] eq "-h" || $ARGV[0] eq "--help")
|
||||||
@@ -126,75 +132,61 @@ else
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Now we have the following variables set:
|
###################### CONFIG ~/.noterc exists? #########################
|
||||||
# $mode (delete | new | edit | list)
|
# If not, use the predefined Values!
|
||||||
# $number ("", -l was given)
|
|
||||||
|
|
||||||
|
|
||||||
# open the configfile.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(-e $CONF)
|
if(-e $CONF)
|
||||||
{
|
{
|
||||||
eval `cat $CONF`;
|
eval `cat $CONF`;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
|
||||||
|
###################### db exists? #######################################
|
||||||
|
# if not, create it!
|
||||||
|
if(! -e $NOTEDB)
|
||||||
{
|
{
|
||||||
# no config, create one and inform the user.
|
open(TT,">$NOTEDB") or die "Could not create $NOTEDB: $!\n";
|
||||||
open FILE, ">$CONF" or die "Could not create $CONF!\n";
|
close (TT);
|
||||||
select FILE;
|
}
|
||||||
print qq~\#config for note $version
|
elsif(! -w $NOTEDB)
|
||||||
\#automaticallly created by note, $date.
|
{
|
||||||
\#please refer to the man page for more informations!
|
print "$NOTEDB is not writable!\n";
|
||||||
|
exit(1);
|
||||||
\#the database to be used
|
|
||||||
\$dbname = "$DEFAULTDBNAME";
|
|
||||||
|
|
||||||
\#the database host
|
|
||||||
\$dbhost = "localhost";
|
|
||||||
|
|
||||||
\#the user to connect
|
|
||||||
\$dbuser = $USER;
|
|
||||||
|
|
||||||
\#the password to be used
|
|
||||||
\$dbpasswd = "";
|
|
||||||
|
|
||||||
\# db descriptors...
|
|
||||||
\$table = "note";
|
|
||||||
\$fnum = "number";
|
|
||||||
\$ffirst = "firstline";
|
|
||||||
\$fnote = "note";
|
|
||||||
\$fdate = "date";
|
|
||||||
~;
|
|
||||||
close FILE;
|
|
||||||
select STDOUT;
|
|
||||||
print "$CONF has been created for you. Please don't forget to edit it!\n";
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ok, if still here, we got it all, now let's connect to the database
|
|
||||||
$db = Mysql->connect($dbhost,$dbname,$dbuser,$dbpasswd)
|
|
||||||
or die "ERROR: $Mysql::dberrstr\n";
|
|
||||||
|
|
||||||
|
# calculate some constants...
|
||||||
|
$BORDERC = "<$BORDER_COLOR>";
|
||||||
|
$_BORDERC = "</$BORDER_COLOR>";
|
||||||
|
$NUMC = "<$NUM_COLOR>";
|
||||||
|
$_NUMC = "</$NUM_COLOR>";
|
||||||
|
$NOTEC = "<$NOTE_COLOR>";
|
||||||
|
$_NOTEC = "</$NOTE_COLOR>";
|
||||||
|
$TIMEC = "<$TIME_COLOR>";
|
||||||
|
$_TIMEC = "</$TIME_COLOR>";
|
||||||
|
|
||||||
# start processing
|
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
|
||||||
|
chomp $time;
|
||||||
|
|
||||||
|
$typedef = "i a$MAX_NOTE a$MAX_TIME";
|
||||||
|
$sizeof = length pack($typedef, () );
|
||||||
|
|
||||||
|
############################### DISPLAY ##################################
|
||||||
if($mode eq "display")
|
if($mode eq "display")
|
||||||
{
|
{
|
||||||
# display a certain note
|
$address = ($number -1 ) * $sizeof;
|
||||||
print "\ndisplaying note number $number:\n";
|
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
|
||||||
$res = $db->query("SELECT $ffirst,$fnote,$fdate FROM $table WHERE $fnum = $number")
|
print "displaying note number $number:\n\n";
|
||||||
or die "ERROR: $Mysql::dberrstr\n";
|
seek(NOTE, $address, SEEK_SET);
|
||||||
while(@row = $res->fetchrow)
|
read(NOTE, $buffer, $sizeof);
|
||||||
{
|
($num, $note, $time) = unpack($typedef, $buffer);
|
||||||
print "$row[0]\n$row[1]\n\nlast changed: $row[2]\n\n";
|
$n = ude($note);
|
||||||
$match = "yes";
|
$t = ude($time);
|
||||||
}
|
|
||||||
if($match eq "")
|
output($num, $n, $t, "SINGLE");
|
||||||
{
|
print "\n";
|
||||||
print "\nno note with that number found!\n\n";
|
close(NOTE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
############################### SEARCH ##################################
|
||||||
elsif($mode eq "search")
|
elsif($mode eq "search")
|
||||||
{
|
{
|
||||||
if($searchstring eq "")
|
if($searchstring eq "")
|
||||||
@@ -202,46 +194,52 @@ elsif($mode eq "search")
|
|||||||
&usage;
|
&usage;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
print "\nsearching the database $dbname for \"$searchstring\"...\n\n";
|
print "searching the database $NOTEDB for \"$searchstring\"...\n";
|
||||||
$sqlstatement = "SELECT DISTINCT $fnum,$ffirst,$fdate FROM $table WHERE "
|
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
|
||||||
. "$ffirst LIKE '%$searchstring%' OR $fnote LIKE '%$searchstring%'"
|
seek(NOTE, 0, 0); # START FROM BEGINNING
|
||||||
. " ORDER BY $fnum";
|
while(read(NOTE, $buffer, $sizeof))
|
||||||
|
|
||||||
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
|
|
||||||
while(@row = $res->fetchrow)
|
|
||||||
{
|
{
|
||||||
print "[ $row[0]\t\"$row[1]\"\t$row[2] ]\n";
|
($num, $note, $time) = unpack($typedef, $buffer);
|
||||||
$match = "yes";
|
$n = ude($note);
|
||||||
}
|
$t = ude($time);
|
||||||
if($match eq "")
|
if($n =~ /$searchstring/i)
|
||||||
{
|
{
|
||||||
print "\nno matching note found!\n\n";
|
output($num, $n, $t);
|
||||||
exit(0);
|
$match = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!$match)
|
||||||
|
{
|
||||||
|
print "no matching note found!\n";
|
||||||
|
}
|
||||||
|
close(NOTE);
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
|
############################### LIST ##################################
|
||||||
elsif($mode eq "list")
|
elsif($mode eq "list")
|
||||||
{
|
{
|
||||||
print "\nlisting all existing notes:\n";
|
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
|
||||||
# list all available notes (number and firstline)
|
seek(NOTE, 0, 0); # START FROM BEGINNING
|
||||||
$res = $db->query("SELECT $fnum,$ffirst,$fdate FROM $table ORDER BY $fnum")
|
print "listing all existing notes:\n\n";
|
||||||
or die "ERROR: $Mysql::dberrstr\n";
|
while(read(NOTE, $buffer, $sizeof))
|
||||||
while(@row = $res->fetchrow)
|
|
||||||
{
|
{
|
||||||
print "[ $row[0]\t\"$row[1]\"\t$row[2] ]\n";
|
($num, $note, $time) = unpack($typedef, $buffer);
|
||||||
|
$n = ude($note);
|
||||||
|
$t = ude($time);
|
||||||
|
#print "#$num:\t$t\n---\n$n\n\n";
|
||||||
|
output($num, $n, $t);
|
||||||
}
|
}
|
||||||
|
close(NOTE);
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
|
############################### NEW ##################################
|
||||||
elsif($mode eq "new")
|
elsif($mode eq "new")
|
||||||
{
|
{
|
||||||
|
local $note = "";
|
||||||
|
local $line = "";
|
||||||
|
#local $num = 0;
|
||||||
# create a new note
|
# create a new note
|
||||||
print "\nenter the text of the note, end with .\n";
|
print "\nenter the text of the note, end with .\n";
|
||||||
while($linenum != 1)
|
|
||||||
{
|
|
||||||
$line = <STDIN>;
|
|
||||||
$firstline = $line;
|
|
||||||
$linenum = 1;
|
|
||||||
}
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
$line = <STDIN>;
|
$line = <STDIN>;
|
||||||
@@ -250,54 +248,95 @@ elsif($mode eq "new")
|
|||||||
# remove the . !
|
# remove the . !
|
||||||
chop $note;
|
chop $note;
|
||||||
chop $note;
|
chop $note;
|
||||||
chomp $firstline;
|
|
||||||
#print "1: $firstline\n2: $note\n";
|
|
||||||
|
|
||||||
|
open (N, "<$NOTEDB") or die "could not open .notedb\n";
|
||||||
# since we have not number, look for the next available:
|
# since we have not number, look for the next available:
|
||||||
$res = $db->query("SELECT max($fnum) FROM $table") or die "ERROR: $Mysql::dberrstr\n";
|
seek(N, 0, 0); # START FROM BEGINNING
|
||||||
while(@row = $res->fetchrow)
|
while(read(N, $buff, $sizeof))
|
||||||
{
|
{
|
||||||
$number = $row[0];
|
($num, $te, $me) = unpack($typedef, $buff);
|
||||||
}
|
}
|
||||||
$number++;
|
seek(N, 0, 0);
|
||||||
$sqlstatement = "INSERT INTO $table VALUES (0,$number,'$firstline','$note','$date')";
|
close (N);
|
||||||
|
$num++; # use the highest plus 1
|
||||||
|
|
||||||
$db->query($sqlstatement)
|
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
|
||||||
or die "ERROR: $Mysql::dberrstr\n";
|
seek(NOTE, 0, SEEK_END); # APPEND
|
||||||
|
local $n = uen($note);
|
||||||
|
local $t = uen($time);
|
||||||
|
$buffer = pack($typedef, $num, $n, $t);
|
||||||
|
|
||||||
# everything ok until here!
|
print NOTE $buffer;
|
||||||
print "note stored. it has been assigned the number $number.\n\n";
|
close(NOTE);
|
||||||
}
|
}
|
||||||
|
############################### DELETE ##################################
|
||||||
elsif($mode eq "delete")
|
elsif($mode eq "delete")
|
||||||
{
|
{
|
||||||
# delete a note
|
# $number is the one we want to delete!
|
||||||
$sqlstatement = "DELETE FROM $table WHERE $fnum = $number";
|
$TEMP = "/tmp/note.$$"; # save temporarily in $TEMP
|
||||||
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
|
system("/bin/touch", $TEMP);
|
||||||
print "\nnote number $number has been deleted.\n\n";
|
open TEMP, "+<$TEMP" or die "Could not open $TEMP($!)\n";
|
||||||
|
open (NOTE, "<$NOTEDB") or die "could not open .notedb\n";
|
||||||
|
|
||||||
|
seek(TEMP, 0, SEEK_END); # APPEND
|
||||||
|
|
||||||
|
$count = 1;
|
||||||
|
|
||||||
|
# read from notedb and write to temp (without number to
|
||||||
|
# be deleted, and with recounted numbers)
|
||||||
|
while(read(NOTE, $buff, $sizeof))
|
||||||
|
{
|
||||||
|
($num, $note, $time) = unpack($typedef, $buff);
|
||||||
|
if($num != $number)
|
||||||
|
{
|
||||||
|
# no keep it
|
||||||
|
$buffer = pack($typedef, $count, $note, $time);
|
||||||
|
seek(TEMP, 0, SEEK_END); # APPEND
|
||||||
|
print TEMP $buffer;
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
# drop it, just ignore the contents.
|
||||||
|
$droped = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(TEMP);
|
||||||
|
close(NOTE);
|
||||||
|
|
||||||
|
# done, inform the user
|
||||||
|
if($droped eq 1)
|
||||||
|
{
|
||||||
|
# copy the new one over the old one
|
||||||
|
system("/bin/cp",$TEMP, $NOTEDB);
|
||||||
|
print "note number $number has been deleted.\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "no note with that number found!\n";
|
||||||
|
}
|
||||||
|
system "/bin/rm -f $TEMP";
|
||||||
}
|
}
|
||||||
|
############################### EDIT ##################################
|
||||||
elsif($mode eq "edit")
|
elsif($mode eq "edit")
|
||||||
{
|
{
|
||||||
# edit a note
|
$address = ($number -1 ) * $sizeof;
|
||||||
$sqlstatement = "SELECT $ffirst,$fnote FROM $table WHERE $fnum = $number";
|
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
|
||||||
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
|
seek(NOTE, $address, SEEK_SET);
|
||||||
while(@row = $res->fetchrow)
|
read(NOTE, $buff, $sizeof) or die "no note with that number found!\n";
|
||||||
{
|
($num, $note, $t) = unpack($typedef, $buff);
|
||||||
$firstline = $row[0];
|
$n = ude($note);
|
||||||
$note = $row[1];
|
# got current enties...
|
||||||
$match = "yes";
|
|
||||||
}
|
# now edit them
|
||||||
if($match eq "")
|
$TEMP = "/tmp/note.$$";
|
||||||
{
|
open N, ">$TEMP" or die "Could not open $TEMP\n";
|
||||||
print "\nno note with that number found!\n\n";
|
select N;
|
||||||
exit(0);
|
print $n; # save decoded to $TEMP
|
||||||
}
|
close N;
|
||||||
$TEMP = "/tmp/note.$USER.$$";
|
|
||||||
open NOTE,">$TEMP" or die "Could not open $TEMP\n";
|
|
||||||
select NOTE;
|
|
||||||
print $firstline . "\n";
|
|
||||||
print $note . "\n";
|
|
||||||
close NOTE;
|
|
||||||
select STDOUT;
|
select STDOUT;
|
||||||
|
|
||||||
|
# let the user edit it...
|
||||||
$editor = &find_editor;
|
$editor = &find_editor;
|
||||||
if($editor)
|
if($editor)
|
||||||
{
|
{
|
||||||
@@ -308,35 +347,29 @@ elsif($mode eq "edit")
|
|||||||
print "Could not find an editor to use!\n";
|
print "Could not find an editor to use!\n";
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# read it in ($note)
|
||||||
$note = "";
|
$note = "";
|
||||||
open NOTE,"<$TEMP" or die "Could not open $TEMP\n";
|
open N, "<$TEMP" or die "Could not open $TEMP\n";
|
||||||
$c = 0;
|
$c = 0;
|
||||||
while(<NOTE>)
|
while(<N>)
|
||||||
{
|
|
||||||
if($c == 0)
|
|
||||||
{
|
|
||||||
$firstline = $_;
|
|
||||||
chomp $firstline;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$note = $note . $_;
|
$note = $note . $_;
|
||||||
}
|
}
|
||||||
$c++;
|
|
||||||
}
|
|
||||||
chomp $note;
|
chomp $note;
|
||||||
close NOTE;
|
close N;
|
||||||
|
|
||||||
|
# privacy!
|
||||||
system "/bin/rm -f $TEMP";
|
system "/bin/rm -f $TEMP";
|
||||||
|
|
||||||
# we got it, now save to db
|
# we got it, now save to db
|
||||||
$sqlstatement = "UPDATE $table SET "
|
seek(NOTE, $address, SEEK_SET);
|
||||||
. "$ffirst = '$firstline', "
|
$n = "";
|
||||||
. "$fnote = '$note' "
|
$n = uen($note);
|
||||||
. "WHERE $fnum = $number";
|
local $t = uen($time);
|
||||||
$db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
|
$buffer = pack($typedef, $number, $n, $t);
|
||||||
|
print NOTE $buffer;
|
||||||
print "\nnote number $number has been changed.\n\n";
|
close(NOTE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -365,3 +398,133 @@ sub usage
|
|||||||
sub find_editor {
|
sub find_editor {
|
||||||
return $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
|
return $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub output
|
||||||
|
{
|
||||||
|
# 0 = Num, 1 = Note, 2 = Time
|
||||||
|
local $S = "-" x ($maxlen + 31);
|
||||||
|
local $LINE = "$BORDERC $S $_BORDERC\n";
|
||||||
|
local $num = $_[0];
|
||||||
|
local $note = $_[1];
|
||||||
|
local $time = $_[2];
|
||||||
|
local $TYPE = $_[3];
|
||||||
|
local $L = $BORDERC . "[" . $_BORDERC;
|
||||||
|
local $R = $BORDERC . "]" . $_BORDERC;
|
||||||
|
if($TYPE ne "SINGLE")
|
||||||
|
{
|
||||||
|
if(!$SetTitle)
|
||||||
|
{
|
||||||
|
# print only of it is the first line!
|
||||||
|
local $SP = " " x ($maxlen-2);
|
||||||
|
print C $LINE;
|
||||||
|
print C "$L $NUMC#$_NUMC $TIMEC" . "creation date$_TIMEC " . $NOTEC . "note$_NOTEC$SP$R\n";
|
||||||
|
print C $LINE;
|
||||||
|
$SetTitle = 1;
|
||||||
|
}
|
||||||
|
local $title = "";
|
||||||
|
$CUTSPACE = " " x $maxlen;
|
||||||
|
$note =~ s/\n/$CUTSPACE/g;
|
||||||
|
local $len = length($note);
|
||||||
|
if($len < $maxlen-3)
|
||||||
|
{
|
||||||
|
local $diff = $maxlen - $len;
|
||||||
|
local $Space = " " x $diff;
|
||||||
|
$title = $BORDERC . $NOTEC . "\"" . $note . "\"" . $_NOTEC . $Space . "$_BORDERC";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$title = substr($note,0,$maxlen - 3);
|
||||||
|
$title = $BORDERC . $NOTEC . "\"" . $title . "...\"$_NOTEC$_BORDERC";
|
||||||
|
}
|
||||||
|
# $title should now look as: "A sample note "
|
||||||
|
print C "$L $NUMC$num$_NUMC $R$L$TIMEC" . $time . "$_TIMEC $R$L $NOTEC" . $title . "$_NOTEC $R\n";
|
||||||
|
print C $LINE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
local $Space = " " x ($maxlen+6);
|
||||||
|
local $SP = " " x ($maxlen +13);
|
||||||
|
print C $LINE;
|
||||||
|
print C "$L $NUMC#$_NUMC " . $TIMEC . "creation date$_TIMEC$SP$R\n";
|
||||||
|
print C $LINE;
|
||||||
|
print C "$L $NUMC$num$_NUMC $R$L$TIMEC$time$_TIMEC $Space$R\n";
|
||||||
|
print C $LINE;
|
||||||
|
print C $NOTEC . $note . $_NOTEC . "\n";
|
||||||
|
print C $LINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub C
|
||||||
|
{
|
||||||
|
# \033[1m%30s\033[0m
|
||||||
|
local %Color = ( 'black' => '0;30',
|
||||||
|
'red' => '0;31',
|
||||||
|
'green' => '0;32',
|
||||||
|
'yellow' => '0;33',
|
||||||
|
'blue' => '0;34',
|
||||||
|
'magenta' => '0;35',
|
||||||
|
'cyan' => '0;36',
|
||||||
|
'white' => '0;37',
|
||||||
|
'B' => '1;30',
|
||||||
|
'BLACK' => '1;30',
|
||||||
|
'RED' => '1;31',
|
||||||
|
'GREEN' => '1;32',
|
||||||
|
'YELLOW' => '1;33',
|
||||||
|
'BLUE' => '1;34',
|
||||||
|
'MAGENTA' => '1;35',
|
||||||
|
'CYAN' => '1;36',
|
||||||
|
'WHITE' => '1;37',
|
||||||
|
'black_' => '4;30',
|
||||||
|
'red_' => '4;31',
|
||||||
|
'green_' => '4;32',
|
||||||
|
'yellow_' => '4;33',
|
||||||
|
'blue_' => '4;34',
|
||||||
|
'magenta_' => '4;35',
|
||||||
|
'cyan_' => '4;36',
|
||||||
|
'white_' => '4;37',
|
||||||
|
'blackI' => '7;30',
|
||||||
|
'redI' => '7;31',
|
||||||
|
'greenI' => '7;32',
|
||||||
|
'yellowI' => '7;33',
|
||||||
|
'blueI' => '7;34',
|
||||||
|
'magentaI' => '7;35',
|
||||||
|
'cyanI' => '7;36',
|
||||||
|
'whiteI' => '7;37'
|
||||||
|
);
|
||||||
|
$default = "\033[0m";
|
||||||
|
$S = $_[0];
|
||||||
|
foreach $Col (%Color)
|
||||||
|
{
|
||||||
|
if ($S =~ /<$Col>/g)
|
||||||
|
{
|
||||||
|
if($COLOR ne "NO")
|
||||||
|
{
|
||||||
|
$NC = "\033[" . $Color{$Col} . "m";
|
||||||
|
$S =~ s/<$Col>/$NC/g;
|
||||||
|
$S =~ s/<\/$Col>/$default/g;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$S =~ s/<$Col>//g;
|
||||||
|
$S =~ s/<\/$Col>//g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $S;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub uen
|
||||||
|
{
|
||||||
|
local $T = pack("u", $_[0]);
|
||||||
|
chomp $T;
|
||||||
|
return $T;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub ude
|
||||||
|
{
|
||||||
|
local $T = unpack("u", $_[0]);
|
||||||
|
return $T;
|
||||||
|
}
|
||||||
|
|||||||
71
noterc
Normal file
71
noterc
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# 0.3 (binary database)
|
||||||
|
# This is a sample config for the note script
|
||||||
|
# You do not need it, if you keep the values
|
||||||
|
# here unchanged.
|
||||||
|
#
|
||||||
|
# Copy it to your $HOME as .noterc
|
||||||
|
#
|
||||||
|
# IMPORTANT:
|
||||||
|
# If you previously used note 0.1 or 0.2 then
|
||||||
|
# you will already have such a file. This file
|
||||||
|
# is not compatible with the one for note 0.3!
|
||||||
|
# You have to delete it and to create a new one.
|
||||||
|
#
|
||||||
|
# There is no more a mysql database needed. If
|
||||||
|
# want to stay with your note-mysql-database,
|
||||||
|
# use note 0.2.
|
||||||
|
#
|
||||||
|
# This config has to be valid perl code. Therefore
|
||||||
|
# please be carefull!
|
||||||
|
#
|
||||||
|
# You can contact me per email: <tom@daemon.de>
|
||||||
|
#
|
||||||
|
# Thomas Linden, 01/2000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Define the maximum bytes a note can have in a
|
||||||
|
# note-entry.
|
||||||
|
$MAX_NOTE = 1024;
|
||||||
|
|
||||||
|
|
||||||
|
# Define the maximum bytes a timestamp can have
|
||||||
|
# in a note-entry.
|
||||||
|
$MAX_TIME = 64;
|
||||||
|
|
||||||
|
|
||||||
|
# The maximum width for displaying a note.
|
||||||
|
$maxlen = 30;
|
||||||
|
|
||||||
|
|
||||||
|
# Your home, better do not change it!
|
||||||
|
$HOME = `echo \$HOME`;
|
||||||
|
chomp $HOME;
|
||||||
|
|
||||||
|
|
||||||
|
# The location of the note-database. If it does
|
||||||
|
# not exist, it will be created.
|
||||||
|
$NOTEDB = $HOME . "/.notedb";
|
||||||
|
|
||||||
|
|
||||||
|
# if $COLOR equals NO, then everything will be
|
||||||
|
# displayed with your default colors (mostly black)
|
||||||
|
$COLOR = "NO";
|
||||||
|
|
||||||
|
|
||||||
|
# Color-definitions of the various fields. Will be
|
||||||
|
# ignored if $COLOR = "NO".
|
||||||
|
$BORDER_COLOR = "BLACK"; # Borders
|
||||||
|
$NUM_COLOR = "blue"; # Note number
|
||||||
|
$NOTE_COLOR = "magenta"; # The note itself
|
||||||
|
$TIME_COLOR = "black"; # The time
|
||||||
|
|
||||||
|
# The following colors are available:
|
||||||
|
# black, red, green, yellow, blue, magenta, cyan and white.
|
||||||
|
# It will be bold if it is uppercase.
|
||||||
|
# You can append an underscore, if you like it underscored,
|
||||||
|
# ie: blue_
|
||||||
|
# Or, you can append an "I", if you like it inverted
|
||||||
|
|
||||||
|
# keep this "1;" please!
|
||||||
|
1;
|
||||||
Reference in New Issue
Block a user