CHANGED: ok, mysql support is back again (upon requests). therefore there

are two different version of the script in the same time with
                the same features, one for mysql and the other one for the binary
                database.
ADDED:          Dump to textfile capability. Later on I want to dump it into a
                palm readable format, any help is welcome!
ADDED:          interactive mode.
CHANGED:        Better modularity, better code.
CHANGED:        note can now run without the need of a config file. If does not
                exist, it will try to work with default values.
ADDED:          sub num_bereich(), which allows one to specify more then one
                number for deletion or displaying (i.e.: "-d 1,4,7" or "-d 4-9")
This commit is contained in:
TLINDEN
2012-02-10 20:03:20 +01:00
parent ff1414cd3a
commit ee0797bad6
11 changed files with 2092 additions and 14 deletions

View File

@@ -1,15 +1,30 @@
0.4:
CHANGED: ok, mysql support is back again (upon requests). therefore there
are two different version of the script in the same time with
the same features, one for mysql and the other one for the binary
database.
ADDED: Dump to textfile capability. Later on I want to dump it into a
palm readable format, any help is welcome!
ADDED: interactive mode.
CHANGED: Better modularity, better code.
CHANGED: note can now run without the need of a config file. If does not
exist, it will try to work with default values.
ADDED: sub num_bereich(), which allows one to specify more then one
number for deletion or displaying (i.e.: "-d 1,4,7" or "-d 4-9")
0.3: 0.3:
CHANGED: it uses no more a mysql database, but a binary file instead. CHANGED: it uses no more a mysql database, but a binary file instead.
This is much faster! This is much faster!
ADDED: note can display the notes with colors, it is turned off by default 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.
FIXED: now numbers of notes will be recounted, if one delete one note, FIXED: now numbers of notes will be recounted, if one delete one note,
so the list of notes will everytime start with 1,2,3,... so the list of notes will everytime start with 1,2,3,...
CHANGED: the look of the list output has been changed, similar to a table CHANGED: the look of the list output has been changed, similar to a table

57
README
View File

@@ -1,4 +1,4 @@
note note-0.3 by Thomas Linden, 01/2000 note 0.4 by Thomas Linden, 13/01/2000
Introduction Introduction
@@ -12,11 +12,22 @@ Introduction
able to display colored output. 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 binary as you want. You can run note from the commandline
database. Unlike previous versions of note this or interactive from within your console.
version don't need a database server. All you need
is perl and this script (and, of course, some free There are now two version of note in one package:
disk space for the file...). o (binary) the binary version resists in the
subdirectory "binary-db".
It uses a binary file for data storage.
The format of this file will be described
later on.
o (mysql) the mysql version resists in the
subdirectory mysql-db. It uses a mysql
database as backend. There are some
special installation steps required in
order to run the mysql version which are
documented in the README within this
subdirectory.
@@ -27,7 +38,7 @@ Requirements
o perl installed (5.004x) o perl installed (5.004x)
o The module IO::Seekable, which should be o The module IO::Seekable, which should be
already installed with your perl distributuion. already installed with your perl distributuion.
o Mysql.pm if you want to use the mysql version.
Installation Installation
@@ -36,6 +47,9 @@ Installation
Simple: Copy it to a place inside your $PATH, Simple: Copy it to a place inside your $PATH,
probably as root. (for example to /usr/bin). probably as root. (for example to /usr/bin).
For installation instructions for the mysql version see
mysql-db/README.
Configuration Configuration
@@ -43,14 +57,19 @@ Configuration
This version of note doesn't neccessarily need This version of note doesn't neccessarily need
a configuration file. But you can have one and change a configuration file. But you can have one and change
some default values. Take a look to the file noterc some default values. Take a look to the file config/noterc
provided with this tarball. There are detailed instructions provided with this tarball. There are detailed instructions
about every available parameter. about every available parameter.
Simply copy this file into your home-directory and name it
.noterc
Usage Usage
===== =====
Usage of the mysql and binary version is similar, there
are only differences between the database backends of
each other.
If you don't know, how to run note, try "note -h" first. If you don't know, how to run note, try "note -h" first.
It will tell you all available commandline options. It will tell you all available commandline options.
@@ -88,7 +107,7 @@ Usage
Format of the notedb Format of the notedb (binary version)
==================== ====================
The database where the notes are stored is a binary file of The database where the notes are stored is a binary file of
@@ -111,6 +130,11 @@ Format of the notedb
Security Security
======== ========
You can't use the following hints with the mysql version!
Refer to the mysql manual for more informations about
security of mysql databases:
http://www.mysql.org/Manual_chapter/manual_Privilege_system.html
If you want to protect the notedb against unauthorized persons If you want to protect the notedb against unauthorized persons
(even root), you might want to use pgp. I use gpg (GNU privacy (even root), you might want to use pgp. I use gpg (GNU privacy
guard), which is compatible to pgp, usage should be similar. guard), which is compatible to pgp, usage should be similar.
@@ -134,6 +158,19 @@ Security
funcion: funcion:
"gpg -e ~/.notedb --yes -r username" "gpg -e ~/.notedb --yes -r username"
Here is, how to do it with pgp, create a shell script with the following
content:
--- snip ---
#!/bin/sh
/bin/echo -n "passphrase:"
pgp -o ~/.notedb -d ~/.notedb.pgp > /dev/null 2>&1
rm -f ~/.notedb.pgp > /dev/null 2>&1
note.pl $1 $2 $3
pgp -e ~/.notedb tlinden > /dev/null 2>&1
rm -f ~/.notedb > /dev/null 2>&1
--- snip ---
Do "chmod 700 whatevername". That's it.
If you don't make use of encryption, I suggest you to chmod it: If you don't make use of encryption, I suggest you to chmod it:
"chmod 600 .notedb" "chmod 600 .notedb"
So, only you can read the file (and root or any intruder who became root). So, only you can read the file (and root or any intruder who became root).
@@ -167,4 +204,4 @@ Author
Last changed Last changed
============ ============
09.01.2000 13.01.2000

2
TODO Normal file
View File

@@ -0,0 +1,2 @@
- add topic and subtopic support some day...
- dump to palm compatible format (!) any help out there?

4
binary-db/README Normal file
View File

@@ -0,0 +1,4 @@
This is the binary version of note.
all informations are available in the
main README file!

925
binary-db/note Executable file
View File

@@ -0,0 +1,925 @@
#!/usr/bin/perl
#
# this is the small console program "note" version 0.4
# 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
# ones and, of course display them.
# The notes will be stored in a binary data file (~/.notedb)
#
# Previous versions needed a mysql database. This is no more
# the case.
# If there exists a configfile called ~/.noterc then it will
# be processed. You can overwrite some default values of note.
#
# If you find it usefull or find a bug, please let me know:
# Thomas Linden <tom@daemon.de>
#################################################
# define some default values.
# 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;
$maxlen = 20;
$timelen = 22;
$HOME = `echo \$HOME`;
chomp $HOME;
$CONF = $HOME . "/.noterc";
$NOTEDB = $HOME . "/.notedb";
$COLOR = "NO";
# if $COLOR equals NO, then the following color-definitions
# will be replaced by "".
$BORDER_COLOR = "BLACK";
$NUM_COLOR = "blue";
$NOTE_COLOR = "magenta";
$TIME_COLOR = "black";
#################################################
sub usage;
sub find_editor;
sub output;
sub C;
sub uen;
sub ude;
sub num_bereich;
sub new;
sub edit;
sub del;
sub display;
sub list;
sub help;
use IO::Seekable;
$version = "0.4 (binary database)";
# process command line args
if($ARGV[0] eq "")
{
$mode = "new";
}
else
{
while($ARGV[0] ne "" )
{
if($ARGV[0] =~ /^\d/)
{
# first arg is a digit!
$number = $ARGV[0];
if($mode eq "")
{
# change mode only, if started with an option
# ($mode will be already set)
$mode = "display";
}
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-i" || $ARGV[0] eq "--interactive")
{
$mode = "interactive";
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-l" || $ARGV[0] eq "--list")
{
$mode = "list";
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist")
{
$mode = "list";
$ListType = "LONG";
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-s" || $ARGV[0] eq "--search")
{
# searching
$mode = "search";
$searchstring = $ARGV[1];
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-e" || $ARGV[0] eq "--edit")
{
if($mode eq "edit")
{
# note -e -e !
&usage;
exit(1);
}
else
{
$mode = "edit";
shift;
}
}
elsif($ARGV[0] eq "-d" || $ARGV[0] eq "--delete")
{
if($mode eq "delete")
{
&usage;
exit(1);
}
else
{
$mode = "delete";
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 "-v" || $ARGV[0] eq "--version")
{
print "This is note $version from Thomas Linden <tom\@daemon.de>.\n";
exit(0);
}
elsif($ARGV[0] eq "-h" || $ARGV[0] eq "--help")
{
&usage;
exit(0);
}
else
{
&usage;
exit(0);
}
}
}
###################### CONFIG ~/.noterc exists? #########################
# If not, use the predefined Values!
if(-e $CONF)
{
eval `cat $CONF`;
}
# Always interactive?
if($ALWAYS_INT eq "YES")
{
$mode = "interactive";
}
###################### db exists? #######################################
# if not, create it!
if(! -e $NOTEDB)
{
open(TT,">$NOTEDB") or die "Could not create $NOTEDB: $!\n";
close (TT);
}
elsif(! -w $NOTEDB)
{
print "$NOTEDB is not writable!\n";
exit(1);
}
# 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>";
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
$typedef = "i a$MAX_NOTE a$MAX_TIME";
$sizeof = length pack($typedef, () );
if($ListType ne "LONG")
{
$maxlen += $timelen; # no time will be displayed!
}
# main loop: ###############
if($mode eq "display")
{
&display;
}
elsif($mode eq "search")
{
&search;
}
elsif($mode eq "list")
{
&list;
}
elsif($mode eq "new")
{
&new;
}
elsif($mode eq "delete")
{
del;
}
elsif($mode eq "edit")
{
&edit;
}
elsif($mode eq "dump")
{
&dump;
}
elsif($mode eq "interactive")
{
&interactive;
}
else
{
#undefined :-(
}
exit(0);
################## EOP ################
############################### DISPLAY ##################################
sub display
{
print "\n";
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
&num_bereich; # get @NumBlock from $numer
foreach $N (@NumBlock)
{
$address = ($N -1 ) * $sizeof;
seek(NOTE, $address, SEEK_SET);
read(NOTE, $buffer, $sizeof);
($num, $note, $time) = unpack($typedef, $buffer);
$n = ude($note);
$t = ude($time);
output($num, $n, $t, "SINGLE");
print "\n";
$match = "yes";
}
close(NOTE);
if($match eq "")
{
print "no note with that number found!\n";
}
}
############################### SEARCH ##################################
sub search
{
$maxlen += $timelen;
if($searchstring eq "")
{
&usage;
exit(1);
}
print "searching the database $NOTEDB for \"$searchstring\"...\n";
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
seek(NOTE, 0, 0); # START FROM BEGINNING
while(read(NOTE, $buffer, $sizeof))
{
($num, $note, $time) = unpack($typedef, $buffer);
$n = ude($note);
$t = ude($time);
if($n =~ /$searchstring/i)
{
output($num, $n, $t);
$match = 1;
}
}
if(!$match)
{
print "no matching note found!\n";
}
close(NOTE);
print "\n";
}
############################### LIST ##################################
sub list
{
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
seek(NOTE, 0, 0); # START FROM BEGINNING
#print "listing all existing notes:\n\n";
while(read(NOTE, $buffer, $sizeof))
{
($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";
}
############################### NEW ##################################
sub new
{
if($ALWAYS_EDIT eq "YES")
{
$TEMP = "/tmp/note.$$";
# let the user edit it...
$editor = &find_editor;
if($editor)
{
system $editor, $TEMP;
}
else
{
print "Could not find an editor to use!\n";
exit(0);
}
# read it in ($note)
$note = "";
open E, "<$TEMP" or die "Could not open $TEMP\n";
$c = 0;
while(<E>)
{
$note = $note . $_;
}
chomp $note;
close E;
# privacy!
system "/bin/rm -f $TEMP";
}
else
{
$note = "";
local $line = "";
#local $num = 0;
# create a new note
print "enter the text of the note, end with .\n";
do
{
$line = <STDIN>;
$note = $note . $line;
} until $line eq ".\n";
# remove the . !
chop $note;
chop $note;
}
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 (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
seek(NOTE, 0, SEEK_END); # APPEND
local $n = uen($note);
local $t = uen($time);
$buffer = pack($typedef, $num, $n, $t);
print NOTE $buffer;
close(NOTE);
print "note stored. it has been assigned the number $num.\n\n";
}
############################### DELETE ##################################
sub del
{
&num_bereich; # get @NumBlock from $number
$TEMP = "/tmp/note.$$"; # save temporarily in $TEMP
system("/bin/touch", $TEMP);
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)
foreach $N (@NumBlock)
{
# define $Merk's for the exists() test later on...
$Merk{$N} = "got";
}
while(read(NOTE, $buff, $sizeof))
{
($num, $note, $time) = unpack($typedef, $buff);
if(exists $Merk{$num})
{
# drop it, just ignore the contents.
$droped = 1;
print "note number $num has been deleted.\n";
}
else
{
# no keep it
$buffer = pack($typedef, $count, $note, $time);
seek(TEMP, 0, SEEK_END); # APPEND
print TEMP $buffer;
$count++;
}
}
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);
}
else
{
print "no note with that number found!\n";
}
system "/bin/rm -f $TEMP";
}
############################### EDIT ##################################
sub edit
{
$address = ($number -1 ) * $sizeof;
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
seek(NOTE, $address, SEEK_SET);
read(NOTE, $buff, $sizeof) or die "no note with that number found!\n";
($num, $note, $t) = unpack($typedef, $buff);
$n = ude($note);
# got current enties...
# now edit them
$TEMP = "/tmp/note.$$";
open N, ">$TEMP" or die "Could not open $TEMP\n";
select N;
print $n; # save decoded to $TEMP
close N;
select STDOUT;
# let the user edit it...
$editor = &find_editor;
if($editor)
{
system $editor, $TEMP;
}
else
{
print "Could not find an editor to use!\n";
exit(0);
}
# read it in ($note)
$note = "";
open N, "<$TEMP" or die "Could not open $TEMP\n";
$c = 0;
while(<N>)
{
$note = $note . $_;
}
chomp $note;
close N;
# privacy!
system "/bin/rm -f $TEMP";
# we got it, now save to db
seek(NOTE, $address, SEEK_SET);
$n = "";
$n = uen($note);
local $t = uen($time);
$buffer = pack($typedef, $number, $n, $t);
print NOTE $buffer;
close(NOTE);
print "note number $number has been changed.\n";
}
sub dump
{
# $dump_file
open (DUMP, ">$dump_file") or die "could not open $dump_file\n";
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";
}
close(NOTE);
print "\n";
close(DUMP);
select STDOUT;
}
sub interactive
{
$maxlen_save = $maxlen;
# create menu:
local $B = "<blackI>";
local $BB = "</blackI>";
local $menu = "[ " . $B . "L" . $BB . " List "
. $B . "N" . $BB . " New "
. $B . "D" . $BB . " Delete "
. $B . "S" . $BB . " Search "
. $B . "E" . $BB . " Edit "
. $B . "?" . $BB . " Help "
. $B . "Q" . $BB . " Quit ] command> ";
# per default let's list all the stuff:
for(;;)
{
#&list;
$maxlen = $maxlen_save;
print "\n\n\n";
print C $menu;
# endless until user press "Q" or "q"!
$char = <STDIN>;
chomp $char;
if($char =~ /^\d+/)
{
# display notes
$maxlen += $timelen;
$number = $char;
&display;
}
elsif($char =~ /^n/i)
{
# create a new one
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
&new;
}
elsif($char =~ /^l/ || $char =~ /^$/)
{
# list
print "\n";
$ListType = "";
$maxlen += $timelen;
&list;
undef $SetTitle;
}
elsif($char =~ /^L/)
{
$ListType = "LONG";
&list;
undef $SetTitle;
}
elsif($char =~ /^h/i || $char =~ /^\?/)
{
# zu dumm der Mensch ;-)
&help;
}
elsif($char =~ /^d\s+(\d+\-*\,*\d*)/i)
{
# delete one!
$number = $1;
&del;
}
elsif($char =~ /^d$/i)
{
# we have to ask her:
print "enter number(s) of note(s) you want to delete: ";
$char = <STDIN>;
chomp $char;
$number = $char;
&del;
}
elsif($char =~ /^e\s+(\d+\-*\,*\d*)/i)
{
# edit one!
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
$number = $1;
&edit;
}
elsif($char =~ /^e$/i)
{
# we have to ask her:
$maxlen += $timelen;
print "enter number of the note you want to edit: ";
$char = <STDIN>;
chomp $char;
$number = $char;
&edit;
}
elsif($char =~ /^s\s+/i)
{
# she want's to search
$maxlen += $timelen;
$searchstring = $';
chomp $searchstring;
&search;
}
elsif($char =~ /^s$/i)
{
# we have to ask her:
print "enter the string you want to search for: ";
$char = <STDIN>;
chomp $char;
$char =~ s/^\n//;
$searchstring = $char;
&search;
}
elsif($char =~ /^q/i)
{
# schade!!!
print "\n\ngood bye\n";
exit(0);
}
else
{
# unknown
print "\nunknown command!\n";
}
}
}
sub usage
{
print qq~
usage: note [-i | --interactive] | [ options ] [ number [,number...]]
Options:
-h --help displays this help screen
-v --version displays the version number
-l --list lists all existing notes
-L --longlist the same as -l but prints also the timestamp
-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>
-i --interactive interactive mode
o if you specify only a number (i.e. "note 4"), then the note with that
number will be displayed.
o you can specify more then one number for delete and display, for example:
"note -d 3,4" deletes #3 and #4. "note 5-7" displays #5, #6 and #7.
o if you run note without any parameter and if \$ALWAYS_INT in the config is
not set, then note will create a new note and prompt you for new text.
o If it finds \~/.noterc, it will process it. Refer to the manpage for more
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;
}
sub find_editor {
return $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
}
sub output
{
# 0 = Num, 1 = Note, 2 = Time
if($ListType ne "LONG")
{
$SSS = "-" x ($maxlen + 31 - $timelen);
}
else
{
$SSS = "-" x ($maxlen + 31);
}
local $LINE = "$BORDERC $SSS $_BORDERC\n";
local $num = $_[0];
local $note = $_[1];
local $time = $_[2];
local $TYPE = $_[3];
local $L = $BORDERC . "[" . $_BORDERC;
local $LONGSPC = " " x (22 + 3);
local $R = $BORDERC . "]" . $_BORDERC;
if($TYPE ne "SINGLE")
{
if(!$SetTitle)
{
local $SP = "";
# print only if it is the first line!
if($ListType ne "LONG")
{
$SP = " " x ($maxlen-2 - $timelen);
}
else
{
$SP = " " x ($maxlen-2);
}
print C $LINE;
print C "$L $NUMC#$_NUMC ";
if($ListType eq "LONG")
{
print C " $TIMEC" . "creation date$_TIMEC ";
}
else
{
print $LONGSPC;
}
print C $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";
if($ListType eq "LONG")
{
print C "$L$TIMEC" . $time . " $_TIMEC$R";
}
print C "$L $NOTEC" . $title . "$_NOTEC $R\n";
print C $LINE;
}
else
{
chomp $note;
local $Space = " " x ($maxlen - 16);
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;
}
sub num_bereich
{
# $number is the one we want to delete!
# But does it contain kommas?
local $m = 0;
if($number =~ /\,/)
{
# accept -d 3,4,7
@NumBlock = split(/\,/,$number);
}
elsif($number =~ /^\d+\-\d+$/)
{
# accept -d 3-9
local @LR = split(/\-/,$number);
local @Sorted_LR = sort @LR;
for($i=$Sorted_LR[0]; $i<=$Sorted_LR[1]; $i++)
{
# from 3-6 create @NumBlock (3,4,5,6)
$NumBlock[$m] = $i;
$m++;
}
}
else
{
@NumBlock = ($number);
}
}
sub help
{
print qq~
--------------------------------------------------------------
HELP for interactive note $version
The following commands are available:
L/l List notes. L=long, with timestamp and l=short without
timestamp. You can also just hit <enter> for short list.
N Create a new note.
D Delete a note. You can either hit "d 1" or "d 1-4"
or just hit "d". If you don't specify a number, you
will be asked for.
S Search trough the notes database. Usage is similar to
Delete, use a string instead of a number to search for.
E Edit a note. Usage is similar to Delete but you can
only edit one note a time.
?/H This help screen.
Q Exit the program.
All commands except the List command are case insensitive.
---------------------------------------------------------------
~;
}

88
config/noterc Normal file
View File

@@ -0,0 +1,88 @@
# 0.4
# 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.
#
# 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
# mysql database settings. leave them uncommented
# if you are not using the mysql version of note.
# $dbhost = ""; # mysql server (hostname)
# $dbuser = ""; # mysql username
# $dbpasswd = ""; # her password
# $dbname = ""; # database name
# $table = "note"; # Table and field names.
# $fnum = "number";
# $fnote = "note";
# $fdate = "date";
# uncomment this, if you want to run note always
# in interactive mode
#$ALWAYS_INT = "YES";
# uncomment this, if you want to use always your
# favorite editor (even for creating notes) instead
# of <STDIN>
#$ALWAYS_EDIT = "YES"
# 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;

64
mysql-db/README Normal file
View File

@@ -0,0 +1,64 @@
README for the mysql version of note
Requirements
============
You need the following things:
o perl installed (5.004x)
o mysql database installed and running
o Mysql perlmodule (you can find it on
http://www.mysql.org) PLEASE NOTE:
It needs the Module "Mysql". The install.sh
script will install it for you directly from
CPAN if you like. 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
============
First, make sure all these things above are ok.
You can use the script "install.sh" to create a new
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 user 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.
You can find a sample config file within the subdirectory
"config" named noterc. There are some special values
which you can use to connect to a different database
then the default.
install.sh will create the following database:
name: user_note
Maintable: note
Number: number(int 10)
Note: note(text)
Date: date(text)
You can use the file "permissions" as a template for
modifying a users permissions to her database. Please
note, that there are different version of mysql out
there with different access privilege systems, which
are not compatible, refer to the documentation shipped
with your mysql installation to learn, how many fields
are available and what they are for.
You may also take a look to:
http://www.mysql.org/Manual_chapter/manual_Privilege_system.html
This should be all.

33
mysql-db/install.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
# installs note
# This is the installer for the mysql version only!
echo "Welcome to note `cat VERSION` installation."
echo "the install script will ask you a view questions,"
echo "make sure to answer them correctly!"
echo
/bin/echo -n "creating the note database..."
NAME="_note"
DBNAME="$USER$NAME"
echo "DBNAME=$DBNAME"
mysqladmin create $DBNAME
echo "done."
/bin/echo -n "creating the table structure using defaults..."
mysql $DBNAME < sql
echo "Shall I try to install the required MySQL driver from CPAN?"
read YESNO
case $YESNO in
"y" | "Y")
if [ $UID != 0 ] ; then
echo "You should be root for that!"
exit
fi
perl -MCPAN -e shell cpan> install mysql
;;
esac
echo "done."

901
mysql-db/note.mysql Executable file
View File

@@ -0,0 +1,901 @@
#!/usr/bin/perl
# this is the small console program "note" (MYSQL 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
# ones and, of course display them.
# The notes will be stored in a mysql database. Refer to
# the README of the desitribution for details about
# installation.
# It requires a configfile named .noterc in the users home.
# If it does not exist, note will create one for you, which
# you will have to edit.
#
# If you find it usefull or find a bug, please let me know:
# Thomas Linden <tom@daemon.de>
#
# note is GPL software.
use Mysql;
##################################
# define some default values.
# don't change them, instead use the config file!
$maxlen = 20;
$timelen = 22;
$date = `date +%e\".\"%m\".\"%Y\" \"%T`;
chomp $date;
$USER = getlogin || getpwuid($<);
chomp $USER;
$HOME = `echo \$HOME`;
chomp $HOME;
$CONF = $HOME . "/.noterc";
$DEFAULTDBNAME = $USER . "_note";
# database settings, override them within the config!
$dbname = "$DEFAULTDBNAME";
$dbhost = "localhost";
$dbuser = $USER;
$dbpasswd = "";
$table = "note";
$fnum = "number";
$fnote = "note";
$fdate = "date";
$COLOR = "NO";
# if $COLOR equals NO, then the following color-definitions
# will be replaced by "".
$BORDER_COLOR = "BLACK";
$NUM_COLOR = "blue";
$NOTE_COLOR = "magenta";
$TIME_COLOR = "black";
###################################
sub usage;
sub find_editor;
sub output;
sub C;
sub uen;
sub ude;
sub num_bereich;
sub new;
sub edit;
sub del;
sub display;
sub list;
sub help;
$version = "0.4 (mysql database)";
# process command line args
if($ARGV[0] eq "")
{
$mode = "new";
}
else
{
while($ARGV[0] ne "" )
{
if($ARGV[0] =~ /^\d/)
{
# first arg is a digit!
$number = $ARGV[0];
if($mode eq "")
{
# change mode only, if started with an option
# ($mode will be already set)
$mode = "display";
}
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-i" || $ARGV[0] eq "--interactive")
{
$mode = "interactive";
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-l" || $ARGV[0] eq "--list")
{
$mode = "list";
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist")
{
$mode = "list";
$ListType = "LONG";
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-s" || $ARGV[0] eq "--search")
{
# searching
$mode = "search";
$searchstring = $ARGV[1];
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-e" || $ARGV[0] eq "--edit")
{
if($mode eq "edit")
{
# note -e -e !
&usage;
exit(1);
}
else
{
$mode = "edit";
shift;
}
}
elsif($ARGV[0] eq "-d" || $ARGV[0] eq "--delete")
{
if($mode eq "delete")
{
&usage;
exit(1);
}
else
{
$mode = "delete";
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 "-v" || $ARGV[0] eq "--version")
{
print "This is note $version from Thomas Linden <tom\@daemon.de>.\n";
exit(0);
}
elsif($ARGV[0] eq "-h" || $ARGV[0] eq "--help")
{
&usage;
exit(0);
}
else
{
&usage;
exit(0);
}
}
}
# open the configfile.
if(-e $CONF)
{
eval `cat $CONF`;
}
# Always interactive?
if($ALWAYS_INT eq "YES")
{
$mode = "interactive";
}
# 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>";
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
$typedef = "i a$MAX_NOTE a$MAX_TIME";
$sizeof = length pack($typedef, () );
if($ListType ne "LONG")
{
$maxlen += $timelen; # no time will be displayed!
}
# 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";
# main loop: ###############
if($mode eq "display")
{
&display;
}
elsif($mode eq "search")
{
&search;
}
elsif($mode eq "list")
{
&list;
}
elsif($mode eq "new")
{
&new;
}
elsif($mode eq "delete")
{
del;
}
elsif($mode eq "edit")
{
&edit;
}
elsif($mode eq "dump")
{
&dump;
}
elsif($mode eq "interactive")
{
&interactive;
}
else
{
#undefined :-(
}
exit(0);
################## EOP ################
############################### DISPLAY ##################################
sub display
{
# display a certain note
print "\n";
&num_bereich; # get @NumBlock from $numer
foreach $N (@NumBlock)
{
$res = $db->query("SELECT $fnote,$fdate FROM $table WHERE $fnum = $N")
or die "ERROR: $Mysql::dberrstr\n";
{
output($N, $row[0], $row[1], "SINGLE");
print "\n";
$match = 1;
}
}
if(!$match)
{
print "no note with that number found!\n";
}
}
############################### SEARCH ##################################
sub search
{
$maxlen += $timelen;
if($searchstring eq "")
{
&usage;
exit(1);
}
print "searching the database $dbname for \"$searchstring\"...\n\n";
$sqlstatement = "SELECT DISTINCT $fnum,$fnote,$fdate FROM $table WHERE "
. "$fnote LIKE '%$searchstring%'"
. " ORDER BY $fnum";
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
while(@row = $res->fetchrow)
{
output($row[0], $row[1], $row[2]);
$match = 1;
}
if(!$match)
{
print "no matching note found!\n";
}
print "\n";
}
############################### LIST ##################################
sub list
{
# list all available notes (number and firstline)
$res = $db->query("SELECT $fnum,$fnote,$fdate FROM $table ORDER BY $fnum")
or die "ERROR: $Mysql::dberrstr\n";
while(@row = $res->fetchrow)
{
output($row[0], $row[1], $row[2]);
}
print "\n";
}
############################### NEW ##################################
sub new
{
if($ALWAYS_EDIT eq "YES")
{
$TEMP = "/tmp/note.$$";
# let the user edit it...
$editor = &find_editor;
if($editor)
{
system $editor, $TEMP;
}
else
{
print "Could not find an editor to use!\n";
exit(0);
}
# read it in ($note)
$note = "";
open E, "<$TEMP" or die "Could not open $TEMP\n";
$c = 0;
while(<E>)
{
$_ =~ s/'/\\'/g;
$note = $note . $_;
}
chomp $note;
close E;
# privacy!
system "/bin/rm -f $TEMP";
}
else
{
$note = "";
local $line = "";
#local $num = 0;
# create a new note
print "enter the text of the note, end with .\n";
do
{
$line = <STDIN>;
$_ =~ s/'/\\'/g;
$note = $note . $line;
} until $line eq ".\n";
# remove the . !
chop $note;
chop $note;
}
# since we have not number, look for the next available:
$res = $db->query("SELECT max($fnum) FROM $table") or die "ERROR: $Mysql::dberrstr\n";
while(@row = $res->fetchrow)
{
$number = $row[0];
}
$number++;
$sqlstatement = "INSERT INTO $table VALUES (0,$number,'$note','$date')";
$db->query($sqlstatement)
or die "ERROR: $Mysql::dberrstr\n";
# everything ok until here!
print "note stored. it has been assigned the number $number.\n\n";
}
############################### DELETE ##################################
sub del
{
# delete a note
&num_bereich; # get @NumBlock from $number
foreach $N (@NumBlock)
{
$sqlstatement = "DELETE FROM $table WHERE $fnum = $N";
$res = $db->query($sqlstatement) or $ERR = $Mysql::dberrstr;
# do not exit if an error occurs - good for int mode!
if($ERR)
{
print "no note with number $N found!\n";
}
else
{
print "note number $N has been deleted.\n";
}
}
# recount the notenumbers:
$i = 0;
$pos = 0;
$sqlstatement = "SELECT id FROM $table ORDER BY id";
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
while(@row = $res->fetchrow)
{
$count[$i] = $row[0];
$i++;
}
#have all real id's, now recount it:
for($pos=0;$pos<$i;$pos++)
{
$setnum = $pos +1;
$sqlstatement = "UPDATE $table SET $fnum = '$setnum' WHERE id = $count[$pos]";
$db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
}
}
############################### EDIT ##################################
sub edit
{
# edit a note
$sqlstatement = "SELECT $fnote FROM $table WHERE $fnum = $number";
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
while(@row = $res->fetchrow)
{
$note = $row[0];
$match = "yes";
}
if($match eq "")
{
print "no note with that number found!\n\n";
exit(0);
}
$TEMP = "/tmp/note.$USER.$$";
open NOTE,">$TEMP" or die "Could not open $TEMP\n";
select NOTE;
print $note;
close NOTE;
select STDOUT;
$editor = &find_editor;
if($editor)
{
system $editor, $TEMP;
}
else
{
print "Could not find an editor to use!\n";
exit(0);
}
$note = "";
open NOTE,"<$TEMP" or die "Could not open $TEMP\n";
$c = 0;
while(<NOTE>)
{
$_ =~ s/'/\\'/g;
$note = $note . $_;
}
chomp $note;
close NOTE;
system "/bin/rm -f $TEMP";
# we got it, now save to db
$sqlstatement = "UPDATE $table SET "
. "$fnote = '$note' "
. "WHERE $fnum = $number";
$db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
print "note number $number has been changed.\n";
}
sub dump
{
# $dump_file
open (DUMP, ">$dump_file") or die "could not open $dump_file\n";
select DUMP;
$res = $db->query("SELECT $fnum,$fnote,$fdate FROM $table ORDER BY $fnum")
or die "ERROR: $Mysql::dberrstr\n";
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
print "complete dump of note database from $time.\n\n";
while(@row = $res->fetchrow)
{
print STDOUT "dumping note number $num to $dump_file\n";
print "#$num\ttime: $t\nnote:\n$n\n---------\n\n";
}
print "\n";
close(DUMP);
select STDOUT;
}
sub interactive
{
$maxlen_save = $maxlen;
# create menu:
local $B = "<blackI>";
local $BB = "</blackI>";
local $menu = "[ " . $B . "L" . $BB . " List "
. $B . "N" . $BB . " New "
. $B . "D" . $BB . " Delete "
. $B . "S" . $BB . " Search "
. $B . "E" . $BB . " Edit "
. $B . "?" . $BB . " Help "
. $B . "Q" . $BB . " Quit ] command> ";
# per default let's list all the stuff:
for(;;)
{
#&list;
$maxlen = $maxlen_save;
print "\n\n\n";
print C $menu;
# endless until user press "Q" or "q"!
$char = <STDIN>;
chomp $char;
if($char =~ /^\d+/)
{
# display notes
$maxlen += $timelen;
$number = $char;
&display;
}
elsif($char =~ /^n/i)
{
# create a new one
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
&new;
}
elsif($char =~ /^l/ || $char =~ /^$/)
{
# list
print "\n";
$ListType = "";
$maxlen += $timelen;
&list;
undef $SetTitle;
}
elsif($char =~ /^L/)
{
$ListType = "LONG";
&list;
undef $SetTitle;
}
elsif($char =~ /^h/i || $char =~ /^\?/)
{
# zu dumm der Mensch ;-)
&help;
}
elsif($char =~ /^d\s+(\d+\-*\,*\d*)/i)
{
# delete one!
$number = $1;
&del;
}
elsif($char =~ /^d$/i)
{
# we have to ask her:
print "enter number(s) of note(s) you want to delete: ";
$char = <STDIN>;
chomp $char;
$number = $char;
&del;
}
elsif($char =~ /^e\s+(\d+\-*\,*\d*)/i)
{
# edit one!
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
$number = $1;
&edit;
}
elsif($char =~ /^e$/i)
{
# we have to ask her:
print "enter number of the note you want to edit: ";
$char = <STDIN>;
chomp $char;
$number = $char;
&edit;
}
elsif($char =~ /^s\s+/i)
{
# she want's to search
#$maxlen += $timelen;
$searchstring = $';
chomp $searchstring;
&search;
}
elsif($char =~ /^s$/i)
{
# we have to ask her:
#$maxlen += $timelen;
print "enter the string you want to search for: ";
$char = <STDIN>;
chomp $char;
$char =~ s/^\n//;
$searchstring = $char;
&search;
}
elsif($char =~ /^q/i)
{
# schade!!!
print "\n\ngood bye\n";
exit(0);
}
else
{
# unknown
print "\nunknown command!\n";
}
}
}
sub usage
{
print qq~
usage: note [-i | --interactive] | [ options ] [ number [,number...]]
Options:
-h --help displays this help screen
-v --version displays the version number
-l --list lists all existing notes
-L --longlist the same as -l but prints also the timestamp
-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>
-i --interactive interactive mode
o if you specify only a number (i.e. "note 4"), then the note with that
number will be displayed.
o you can specify more then one number for delete and display, for example:
"note -d 3,4" deletes #3 and #4. "note 5-7" displays #5, #6 and #7.
o if you run note without any parameter and if \$ALWAYS_INT in the config is
not set, then note will create a new note and prompt you for new text.
o If it finds \~/.noterc, it will process it. Refer to the manpage for more
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;
}
sub find_editor {
return $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
}
sub output
{
# 0 = Num, 1 = Note, 2 = Time
if($ListType ne "LONG")
{
$SSS = "-" x ($maxlen + 31 - $timelen);
}
else
{
$SSS = "-" x ($maxlen + 31);
}
local $LINE = "$BORDERC $SSS $_BORDERC\n";
local $num = $_[0];
local $note = $_[1];
local $time = $_[2];
local $TYPE = $_[3];
local $L = $BORDERC . "[" . $_BORDERC;
local $LONGSPC = " " x (22 + 3);
local $R = $BORDERC . "]" . $_BORDERC;
if($TYPE ne "SINGLE")
{
if(!$SetTitle)
{
local $SP = "";
# print only if it is the first line!
if($ListType ne "LONG")
{
$SP = " " x ($maxlen-2 - $timelen);
}
else
{
$SP = " " x ($maxlen-2);
}
print C $LINE;
print C "$L $NUMC#$_NUMC ";
if($ListType eq "LONG")
{
print C " $TIMEC" . "creation date$_TIMEC ";
}
else
{
print $LONGSPC;
}
print C $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";
if($ListType eq "LONG")
{
print C "$L$TIMEC" . $time . " $_TIMEC$R";
}
print C "$L $NOTEC" . $title . "$_NOTEC $R\n";
print C $LINE;
}
else
{
chomp $note;
local $Space = " " x ($maxlen - 16);
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;
}
sub num_bereich
{
# $number is the one we want to delete!
# But does it contain kommas?
local $m = 0;
if($number =~ /\,/)
{
# accept -d 3,4,7
@NumBlock = split(/\,/,$number);
}
elsif($number =~ /^\d+\-\d+$/)
{
# accept -d 3-9
local @LR = split(/\-/,$number);
local @Sorted_LR = sort @LR;
for($i=$Sorted_LR[0]; $i<=$Sorted_LR[1]; $i++)
{
# from 3-6 create @NumBlock (3,4,5,6)
$NumBlock[$m] = $i;
$m++;
}
}
else
{
@NumBlock = ($number);
}
}
sub help
{
print qq~
--------------------------------------------------------------
HELP for interactive note $version
The following commands are available:
L/l List notes. L=long, with timestamp and l=short without
timestamp. You can also just hit <enter> for short list.
N Create a new note.
D Delete a note. You can either hit "d 1" or "d 1-4"
or just hit "d". If you don't specify a number, you
will be asked for.
S Search trough the notes database. Usage is similar to
Delete, use a string instead of a number to search for.
E Edit a note. Usage is similar to Delete but you can
only edit one note a time.
?/H This help screen.
Q Exit the program.
All commands except the List command are case insensitive.
---------------------------------------------------------------
~;
}

2
mysql-db/permissions Normal file
View File

@@ -0,0 +1,2 @@
insert into user values
('localhost','','','Y','Y','Y','Y','Y','Y','N','N','N','N','N','N','N','Y');

7
mysql-db/sql Normal file
View File

@@ -0,0 +1,7 @@
CREATE TABLE note (
id int(10) DEFAULT '0' NOT NULL auto_increment,
number int(10),
note text,
date text,
PRIMARY KEY (id)
);