ADDED: Topic support(requested). You can sort the various notes under

different topics now.
FIXED:          There was another bug, which caused the list command to display
                the notes with a too high value of $maxlen.
This commit is contained in:
TLINDEN
2012-02-10 20:09:11 +01:00
parent a9ee40e5c2
commit 6c5db55b5e
7 changed files with 432 additions and 105 deletions

View File

@@ -1,3 +1,10 @@
0.5:
ADDED: Topic support(requested). You can sort the various notes under
different topics now.
FIXED: There was another bug, which caused the list command to display
the notes with a too high value of $maxlen.
0.4.2: 0.4.2:
ADDED: If run in interactive mode, note will at first do a list command. ADDED: If run in interactive mode, note will at first do a list command.
FIXED: A bug caused note to save bogus timestamps after editing a note. FIXED: A bug caused note to save bogus timestamps after editing a note.

53
README
View File

@@ -1,4 +1,4 @@
note 0.4.2 by Thomas Linden, 23/01/2000 note 0.5 by Thomas Linden, 23/01/2000
Introduction Introduction
@@ -13,7 +13,9 @@ Introduction
You can add, edit, list and delete as many notes You can add, edit, list and delete as many notes
as you want. You can run note from the commandline as you want. You can run note from the commandline
or interactive from within your console. or interactive from within your console. You can
sort your notes in different topics, which is usefull
if you have a lot of them.
There are now two version of note in one package: There are now two version of note in one package:
o (binary) the binary version resists in the o (binary) the binary version resists in the
@@ -86,7 +88,12 @@ Usage
If you want to get an overview of all notes, type "note -l". If you want to get an overview of all notes, type "note -l".
You will get a list of all notes, containing the number, You will get a list of all notes, containing the number,
the first line and the creation date. the first line and the creation date. If topic-support is
turned on (which is by default), then "-l" will display a list
of all existing topics. If you want to get a listing of all
notes under a certain topic, use "-l topicname". You will get
timestamps, if you use "-L" instead of "-l". Read more about
topics below in the section "Topics".
To edit a certain note, type "note -e 1". It will invoke your To edit a certain note, type "note -e 1". It will invoke your
editor (vi or pico). You can edit it, after saving, note editor (vi or pico). You can edit it, after saving, note
@@ -98,6 +105,9 @@ Usage
existent notes. For example there are 3 notes, number 1, 2 existent notes. For example there are 3 notes, number 1, 2
and 3. If you delete number 2, then number 3 will become and 3. If you delete number 2, then number 3 will become
number 2. number 2.
You can also make use of the extended delete-syntax:
To delete note 1 and 2, use "-d 1,2"
To delete note 1,2 and 3, use "-d 1-3".
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>".
@@ -107,7 +117,7 @@ Usage
Instead of using note from the commandline you can use the Instead of using note from the commandline you can use the
interactive mode. Run note with "note -i". If you need assistance interactive mode. Run note with "note -i". If you need assistance
type "?" or "h" at the "command>" prompt. The interactive mode type "?" or "h" at the ">" prompt. The interactive mode
provides you the most functions of note. provides you the most functions of note.
You can also dump the contents of your note-database into a You can also dump the contents of your note-database into a
@@ -120,6 +130,41 @@ Usage
Topics
======
If topic-support is turned on (which is by default), the various
notes are sorted under various topics. There is no special database
field for the topic. Instead the topic will be stored right in the
note.
If the first line of your note contains some text bordered by back-
slashes, then note will consider it as the topic of this certain
note. For examle:
\TodoList\
If you are in interactive mode, you can "cd" to a different note simply
by typing it's name at the command-prompt. The list-command will only
show you notes under this topic. If you create a new note, it will auto-
magically inserted under the current topic (note will prepend the string
"\topicname\" to the text of your note).
You can create at any time form any point a new topic. Just create a new
note and type yourself the name of the new topic bordered by backslashes
at the first line of this note. After saving, there will be available a
new topic with one note in it.
If a note does not contain the "magic" \topic\ construction on the first
line, it will be listed under the topic "default". Therefore never use the
word "default" as a topic-name :-)
You can subsequently move a note without a topic to a certain topic. Simply
edit it and insert at the first line the above mentioned construction.
Note: Please don't forget the prepending and appending backslash of a topic.
You will get strange results without it!
Format of the notedb (binary version) Format of the notedb (binary version)
===================================== =====================================

1
TODO
View File

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

View File

@@ -1 +1 @@
0.4.2 0.5

View File

@@ -7,8 +7,6 @@
# ones and, of course display them. # ones and, of course display them.
# The notes will be stored in a binary data file (~/.notedb) # 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 # If there exists a configfile called ~/.noterc then it will
# be processed. You can overwrite some default values of note. # be processed. You can overwrite some default values of note.
# #
@@ -40,6 +38,10 @@ $BORDER_COLOR = "BLACK";
$NUM_COLOR = "blue"; $NUM_COLOR = "blue";
$NOTE_COLOR = "magenta"; $NOTE_COLOR = "magenta";
$TIME_COLOR = "black"; $TIME_COLOR = "black";
$TOPIC_COLOR = "BLACK";
# Turns Topic Support on
$TOPIC = 1;
################################################# #################################################
@@ -61,7 +63,7 @@ sub import;
use IO::Seekable; use IO::Seekable;
$version = "0.4.2 (binary database)"; $version = "0.5 (binary database)";
# process command line args # process command line args
@@ -93,14 +95,16 @@ else
elsif($ARGV[0] eq "-l" || $ARGV[0] eq "--list") elsif($ARGV[0] eq "-l" || $ARGV[0] eq "--list")
{ {
$mode = "list"; $mode = "list";
$CurTopic = $ARGV[1];
$ARGV[0] = ""; $ARGV[0] = "";
} }
elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist") elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist")
{ {
$mode = "list"; $mode = "list";
$ListType = "LONG"; $ListType = "LONG";
$ARGV[0] = ""; $CurTopic = $ARGV[1];
} $ARGV[0] = "";
}
elsif($ARGV[0] eq "-s" || $ARGV[0] eq "--search") elsif($ARGV[0] eq "-s" || $ARGV[0] eq "--search")
{ {
# searching # searching
@@ -159,7 +163,7 @@ else
} }
elsif($ARGV[0] eq "-v" || $ARGV[0] eq "--version") elsif($ARGV[0] eq "-v" || $ARGV[0] eq "--version")
{ {
print "This is note $version from Thomas Linden <tom\@daemon.de>.\n"; print "This is note $version by 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")
@@ -212,6 +216,8 @@ $NOTEC = "<$NOTE_COLOR>";
$_NOTEC = "</$NOTE_COLOR>"; $_NOTEC = "</$NOTE_COLOR>";
$TIMEC = "<$TIME_COLOR>"; $TIMEC = "<$TIME_COLOR>";
$_TIMEC = "</$TIME_COLOR>"; $_TIMEC = "</$TIME_COLOR>";
$TOPICC = "<$TOPIC_COLOR>";
$_TOPICC = "</$TOPIC_COLOR>";
$time = `date +%d\".\"%m\".\"%Y\" \"%T`; $time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time; chomp $time;
@@ -220,7 +226,7 @@ $typedef = "i a$MAX_NOTE a$MAX_TIME";
$sizeof = length pack($typedef, () ); $sizeof = length pack($typedef, () );
if($ListType ne "LONG") if($ListType ne "LONG" && $mode ne "interactive")
{ {
$maxlen += $timelen; # no time will be displayed! $maxlen += $timelen; # no time will be displayed!
} }
@@ -339,17 +345,84 @@ sub search
############################### LIST ################################## ############################### LIST ##################################
sub list sub list
{ {
if($mode ne "interactive")
{
if($TOPIC && $CurTopic eq "")
{
print "List of all available topics:\n\n";
}
elsif($TOPIC && $CurTopic ne "")
{
print "List of all notes under topic \"$CurTopic\":\n\n";
}
else
{
print "List of all existing notes:\n\n";
}
}
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n"; open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
seek(NOTE, 0, 0); # START FROM BEGINNING seek(NOTE, 0, 0); # START FROM BEGINNING
#print "listing all existing notes:\n\n"; if($TOPIC && $CurTopic eq "")
{
undef %TP;
}
while(read(NOTE, $buffer, $sizeof)) while(read(NOTE, $buffer, $sizeof))
{ {
($num, $note, $time) = unpack($typedef, $buffer); ($num, $note, $time) = unpack($typedef, $buffer);
$n = ude($note);
$t = ude($time); $t = ude($time);
#print "#$num:\t$t\n---\n$n\n\n"; $n = ude($note);
output($num, $n, $t); if($TOPIC)
} {
# this allows us to have multiple topics (subtopics!)
@topic = split(/\\/,$n);
if($CurTopic eq "")
{
# looks like: "\topic\"
# collect:
if($topic[1] eq "")
{
$topic[1] = "default";
}
if(exists $TP{$topic[1]})
{
$TP{$topic[1]}++;
}
else
{
$TP{$topic[1]} = 1;
}
}
else
{
if($topic[1] eq $CurTopic)
{
# cut the topic from the note-text
if($n =~ /^\\$CurTopic\\\n*/)
{
$n = $';
}
output($num, $n, $t);
}
elsif($topic[1] eq "" && $CurTopic eq "default")
{
output($num, $n, $t);
}
}
}
else
{
output($num, $n, $t);
}
}
if($TOPIC && $CurTopic eq "")
{
# we are at top level, print a list of topics...
foreach $top (sort(keys %TP))
{
print C " => " . $BORDERC. "[" . $_BORDERC . $TOPICC . $top . $_TOPICC . $BORDERC . "]" .$_BORDERC ." ($TP{$top} notes)\n";
}
}
close(NOTE); close(NOTE);
print "\n"; print "\n";
} }
@@ -375,7 +448,13 @@ sub new
# read it in ($note) # read it in ($note)
$note = ""; $note = "";
#open E, "<$TEMP" or die "Could not open $TEMP\n"; #open E, "<$TEMP" or die "Could not open $TEMP\n";
open E, "<$TEMP" or print "...edit process interupted! No note has been saved.\n"; return; open E, "<$TEMP" or $WARN = 1;
if($WARN)
{
print "...edit process interupted! No note has been saved.\n";
undef $WARN;
return;
}
$c = 0; $c = 0;
while(<E>) while(<E>)
{ {
@@ -413,6 +492,16 @@ sub new
close (N); close (N);
$num++; # use the highest plus 1 $num++; # use the highest plus 1
if($TOPIC && $CurTopic ne "")
{
@topic = split(/\\/,$note);
if($topic[1] eq "")
{
$note = "\\$CurTopic\\\n$note";
}
}
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n"; open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
seek(NOTE, 0, SEEK_END); # APPEND seek(NOTE, 0, SEEK_END); # APPEND
local $n = uen($note); local $n = uen($note);
@@ -646,44 +735,47 @@ sub interactive
# create menu: # create menu:
local $B = "<blackI>"; local $B = "<blackI>";
local $BB = "</blackI>"; local $BB = "</blackI>";
local $menu = "[ " . $B . "L" . $BB . " List " local $menu = "[" . $B . "L" . $BB . " List "
. $B . "N" . $BB . " New " . $B . "N" . $BB . " New "
. $B . "D" . $BB . " Delete " . $B . "D" . $BB . " Delete "
. $B . "S" . $BB . " Search " . $B . "S" . $BB . " Search "
. $B . "E" . $BB . " Edit " . $B . "E" . $BB . " Edit ";
. $B . "?" . $BB . " Help " if($TOPIC)
. $B . "Q" . $BB . " Quit ] command> "; {
$menu .= $B . "T" . $BB . " Topic ";
}
$menu .= $B . "?" . $BB . " Help "
. $B . "Q" . $BB . " Quit] "; # $CurTopic will be empty if $TOPIC is off!
# Initially do a list command! # Initially do a list command!
$maxlen += $timelen; $maxlen += $timelen;
print "\n";
&list; &list;
# per default let's list all the stuff: # per default let's list all the stuff:
for(;;) for(;;)
{ {
#&list;
# reset time # reset time
$time = `date +%d\".\"%m\".\"%Y\" \"%T`; $time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time; chomp $time;
$ListType = ""; $ListType = "";
$maxlen = $maxlen_save; $maxlen = $maxlen_save;
print C $menu; print C $menu . $TOPICC . $CurTopic . $_TOPICC . ">";
# endless until user press "Q" or "q"! # endless until user press "Q" or "q"!
$char = <STDIN>; $char = <STDIN>;
chomp $char; chomp $char;
if($char =~ /^\d+/) if($char =~ /^\d+/)
{ {
# display notes # display notes
$maxlen += $timelen;
$number = $char; $number = $char;
&display; &display;
} }
elsif($char =~ /^n/i) elsif($char =~ /^n$/i)
{ {
# create a new one # create a new one
$time = `date +%d\".\"%m\".\"%Y\" \"%T`; $time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time; chomp $time;
&new; &new;
} }
elsif($char =~ /^l/ || $char =~ /^$/) elsif($char =~ /^l$/ || $char =~ /^$/)
{ {
# list # list
print "\n"; print "\n";
@@ -692,13 +784,14 @@ sub interactive
&list; &list;
undef $SetTitle; undef $SetTitle;
} }
elsif($char =~ /^L/) elsif($char =~ /^L$/)
{ {
$ListType = "LONG"; $ListType = "LONG";
print "\n";
&list; &list;
undef $SetTitle; undef $SetTitle;
} }
elsif($char =~ /^h/i || $char =~ /^\?/) elsif($char =~ /^h$/i || $char =~ /^\?/)
{ {
# zu dumm der Mensch ;-) # zu dumm der Mensch ;-)
&help; &help;
@@ -729,7 +822,7 @@ sub interactive
elsif($char =~ /^e$/i) elsif($char =~ /^e$/i)
{ {
# we have to ask her: # we have to ask her:
$maxlen += $timelen; #$maxlen += $timelen;
print "enter number of the note you want to edit: "; print "enter number of the note you want to edit: ";
$char = <STDIN>; $char = <STDIN>;
chomp $char; chomp $char;
@@ -739,7 +832,6 @@ sub interactive
elsif($char =~ /^s\s+/i) elsif($char =~ /^s\s+/i)
{ {
# she want's to search # she want's to search
$maxlen += $timelen;
$searchstring = $'; $searchstring = $';
chomp $searchstring; chomp $searchstring;
&search; &search;
@@ -754,16 +846,45 @@ sub interactive
$searchstring = $char; $searchstring = $char;
&search; &search;
} }
elsif($char =~ /^q/i) elsif($char =~ /^q$/i)
{ {
# schade!!! # schade!!!
print "\n\ngood bye\n"; print "\n\ngood bye\n";
exit(0); exit(0);
} }
elsif($char =~ /^t$/i && $TOPIC)
{
$SaveTopic = $CurTopic;
$CurTopic = "";
#$maxlen += $timelen;
print "\n";
&list;
$CurTopic = $SaveTopic;
undef $SetTitle;
}
elsif($char =~ /^\.\.$/)
{
$CurTopic = "default";
$maxlen += $timelen;
print "\n";
&list;
undef $SetTitle;
}
else else
{ {
# unknown # unknown
print "\nunknown command!\n"; if(exists $TP{$char})
{
$CurTopic = $char;
$maxlen += $timelen;
print "\n";
&list;
undef $SetTitle;
}
else
{
print "\nunknown command!\n";
}
} }
} }
} }
@@ -779,8 +900,9 @@ Usage: note [-i | --interactive] | [ options ] [ number [,number...]]
Options: Options:
-h --help displays this help screen -h --help displays this help screen
-v --version displays the version number -v --version displays the version number
-l --list lists all existing notes -l --list [<topic>] lists all existing notes. If no topic were specified,
-L --longlist the same as -l but prints also the timestamp it will display a list of all existing topics.
-L --longlist [<topic>] the same as -l but prints also the timestamp
-s --search <string> searches for <string> trough the notes database -s --search <string> searches for <string> trough the notes database
-e --edit <number> edit note with <number> -e --edit <number> edit note with <number>
-d --delete <number> delete note with <number> -d --delete <number> delete note with <number>
@@ -1026,16 +1148,26 @@ print qq~
HELP for interactive note $version HELP for interactive note $version
The following commands are available: The following commands are available:
L/l List notes. L=long, with timestamp and l=short without L/l List notes. L=long, with timestamp and l=short without timestamp.
timestamp. You can also just hit <enter> for short list. You can also just hit <enter> for short list.
N Create a new note. N Create a new note.
D Delete a note. You can either hit "d 1" or "d 1-4" D Delete a note. You can either hit "d 1" or "d 1-4" or just hit "d".
or just hit "d". If you don't specify a number, you If you don't specify a number, you will be asked for.
will be asked for. S Search trough the notes database. Usage is similar to Delete, use
S Search trough the notes database. Usage is similar to a string instead of a number to search for.
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 note
E Edit a note. Usage is similar to Delete but you can a time.~;
only edit one note a time. if($TOPIC)
{
print qq~
T print a list of all existing topics. You can change the actual
topic by simply typing it's name. You can create a new topic by
creating a new note, the first line must be the topic borderd by
backslashes, i.e.: "\\newtopic\\". If you type just ".." instead
of a topic, you will go to the "default" topic, which contains
all notes without a topic.~;
}
print qq~
?/H This help screen. ?/H This help screen.
Q Exit the program. Q Exit the program.

View File

@@ -1,4 +1,4 @@
# 0.4 # 0.5
# This is a sample config for the note script # This is a sample config for the note script
# You do not need it, if you keep the values # You do not need it, if you keep the values
# here unchanged. # here unchanged.
@@ -8,7 +8,7 @@
# IMPORTANT: # IMPORTANT:
# If you previously used note 0.1 or 0.2 then # If you previously used note 0.1 or 0.2 then
# you will already have such a file. This file # you will already have such a file. This file
# is not compatible with the one for note 0.3! # is not compatible with the one for note 0.3 and higher!
# You have to delete it and to create a new one. # You have to delete it and to create a new one.
# #
# This config has to be valid perl code. Therefore # This config has to be valid perl code. Therefore
@@ -16,7 +16,7 @@
# #
# You can contact me per email: <tom@daemon.de> # You can contact me per email: <tom@daemon.de>
# #
# Thomas Linden, 01/2000 # Thomas Linden, 23/2000
# mysql database settings. leave them uncommented # mysql database settings. leave them uncommented
@@ -41,6 +41,11 @@
#$ALWAYS_EDIT = "YES" #$ALWAYS_EDIT = "YES"
# This option turns topic-support on or off
# comment it out, if you don't need it
$TOPIC = 1;
# Define the maximum bytes a note can have in a # Define the maximum bytes a note can have in a
# note-entry. # note-entry.
$MAX_NOTE = 1024; $MAX_NOTE = 1024;
@@ -76,6 +81,7 @@ $BORDER_COLOR = "BLACK"; # Borders
$NUM_COLOR = "blue"; # Note number $NUM_COLOR = "blue"; # Note number
$NOTE_COLOR = "magenta"; # The note itself $NOTE_COLOR = "magenta"; # The note itself
$TIME_COLOR = "black"; # The time $TIME_COLOR = "black"; # The time
$TOPIC_COLOR = "BLACK"; # The topic "prompt"
# The following colors are available: # The following colors are available:
# black, red, green, yellow, blue, magenta, cyan and white. # black, red, green, yellow, blue, magenta, cyan and white.

View File

@@ -56,6 +56,10 @@ $BORDER_COLOR = "BLACK";
$NUM_COLOR = "blue"; $NUM_COLOR = "blue";
$NOTE_COLOR = "magenta"; $NOTE_COLOR = "magenta";
$TIME_COLOR = "black"; $TIME_COLOR = "black";
$TOPIC_COLOR = "BLACK";
# Turns Topic Support on
$TOPIC = 1;
################################### ###################################
@@ -75,7 +79,7 @@ sub list;
sub help; sub help;
sub import; sub import;
$version = "0.4.2 (mysql database)"; $version = "0.5 (mysql database)";
# process command line args # process command line args
if($ARGV[0] eq "") if($ARGV[0] eq "")
@@ -98,22 +102,24 @@ else
} }
$ARGV[0] = ""; $ARGV[0] = "";
} }
elsif($ARGV[0] eq "-i" || $ARGV[0] eq "--interactive") elsif($ARGV[0] eq "-i" || $ARGV[0] eq "--interactive")
{ {
$mode = "interactive"; $mode = "interactive";
$ARGV[0] = ""; $ARGV[0] = "";
} }
elsif($ARGV[0] eq "-l" || $ARGV[0] eq "--list") elsif($ARGV[0] eq "-l" || $ARGV[0] eq "--list")
{ {
$mode = "list"; $mode = "list";
$CurTopic = $ARGV[1];
$ARGV[0] = ""; $ARGV[0] = "";
} }
elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist") elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist")
{ {
$mode = "list"; $mode = "list";
$ListType = "LONG"; $ListType = "LONG";
$ARGV[0] = ""; $CurTopic = $ARGV[1];
} $ARGV[0] = "";
}
elsif($ARGV[0] eq "-s" || $ARGV[0] eq "--search") elsif($ARGV[0] eq "-s" || $ARGV[0] eq "--search")
{ {
# searching # searching
@@ -172,7 +178,7 @@ else
} }
elsif($ARGV[0] eq "-v" || $ARGV[0] eq "--version") elsif($ARGV[0] eq "-v" || $ARGV[0] eq "--version")
{ {
print "This is note $version from Thomas Linden <tom\@daemon.de>.\n"; print "This is note $version by 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")
@@ -214,15 +220,14 @@ $NOTEC = "<$NOTE_COLOR>";
$_NOTEC = "</$NOTE_COLOR>"; $_NOTEC = "</$NOTE_COLOR>";
$TIMEC = "<$TIME_COLOR>"; $TIMEC = "<$TIME_COLOR>";
$_TIMEC = "</$TIME_COLOR>"; $_TIMEC = "</$TIME_COLOR>";
$TOPICC = "<$TOPIC_COLOR>";
$_TOPICC = "</$TOPIC_COLOR>";
$time = `date +%d\".\"%m\".\"%Y\" \"%T`; $time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time; chomp $time;
$typedef = "i a$MAX_NOTE a$MAX_TIME";
$sizeof = length pack($typedef, () );
if($ListType ne "LONG" && $mode ne "interactive")
if($ListType ne "LONG")
{ {
$maxlen += $timelen; # no time will be displayed! $maxlen += $timelen; # no time will be displayed!
} }
@@ -233,6 +238,7 @@ $db = Mysql->connect($dbhost,$dbname,$dbuser,$dbpasswd)
or die "ERROR: $Mysql::dberrstr\n"; or die "ERROR: $Mysql::dberrstr\n";
# main loop: ############### # main loop: ###############
if($mode eq "display") if($mode eq "display")
{ {
@@ -337,14 +343,87 @@ sub search
############################### LIST ################################## ############################### LIST ##################################
sub list sub list
{ {
if($mode ne "interactive")
{
if($TOPIC && $CurTopic eq "")
{
print "List of all available topics:\n\n";
}
elsif($TOPIC && $CurTopic ne "")
{
print "List of all notes under topic \"$CurTopic\":\n\n";
}
else
{
print "List of all existing notes:\n\n";
}
}
# list all available notes (number and firstline) # list all available notes (number and firstline)
$res = $db->query("SELECT $fnum,$fnote,$fdate FROM $table ORDER BY $fnum") $res = $db->query("SELECT $fnum,$fnote,$fdate FROM $table ORDER BY $fnum")
or die "ERROR: $Mysql::dberrstr\n"; or die "ERROR: $Mysql::dberrstr\n";
if($TOPIC && $CurTopic eq "")
{
undef %TP;
}
while(@row = $res->fetchrow) while(@row = $res->fetchrow)
{ {
output($row[0], $row[1], $row[2]); #output($row[0], $row[1], $row[2]);
} $num = $row[0]; $n = $row[1]; $t = $row[2];
if($TOPIC)
{
@topic = split(/\\/,$n); # this allows us to have multiple topics (subtopics!)
if($CurTopic eq "")
{
# looks like: "\topic\"
# collect:
if($topic[1] eq "")
{
$topic[1] = "default";
}
if(exists $TP{$topic[1]})
{
$TP{$topic[1]}++;
}
else
{
$TP{$topic[1]} = 1;
}
}
else
{
if($topic[1] eq $CurTopic)
{
# cut the topic from the note-text
if($n =~ /^\\$CurTopic\\\n*/)
{
$n = $';
}
output($num, $n, $t);
}
elsif($topic[1] eq "" && $CurTopic eq "default")
{
output($num, $n, $t);
}
}
}
else
{
output($num, $n, $t);
}
}
if($TOPIC && $CurTopic eq "")
{
# we are at top level, print a list of topics...
foreach $top (sort(keys %TP))
{
print C " => " . $BORDERC. "[" . $_BORDERC . $TOPICC
. $top . $_TOPICC . $BORDERC . "]"
.$_BORDERC ." ($TP{$top} notes)\n";
}
}
print "\n"; print "\n";
} }
@@ -369,7 +448,13 @@ sub new
# read it in ($note) # read it in ($note)
$note = ""; $note = "";
#open E, "<$TEMP" or die "Could not open $TEMP\n"; #open E, "<$TEMP" or die "Could not open $TEMP\n";
open E, "<$TEMP" or print "...edit process interupted! No note has been saved.\n"; return; open E, "<$TEMP" or $WARN = 1;
if($WARN)
{
print "...edit process interupted! No note has been saved.\n";
undef $WARN;
return;
}
$c = 0; $c = 0;
while(<E>) while(<E>)
{ {
@@ -406,6 +491,18 @@ sub new
$number = $row[0]; $number = $row[0];
} }
$number++; $number++;
if($TOPIC && $CurTopic ne "")
{
@topic = split(/\\/,$note);
if($topic[1] eq "")
{
$note = "\\$CurTopic\\\n$note";
}
}
# mask all occuring \'s
$note =~ s/\\/\\\\/g;
$sqlstatement = "INSERT INTO $table VALUES ($number,'$note','$date')"; $sqlstatement = "INSERT INTO $table VALUES ($number,'$note','$date')";
$db->query($sqlstatement) $db->query($sqlstatement)
@@ -501,6 +598,9 @@ sub edit
system "/bin/rm -f $TEMP"; system "/bin/rm -f $TEMP";
# mask all occuring \'s
$note =~ s/\\/\\\\/g;
# we got it, now save to db # we got it, now save to db
$sqlstatement = "UPDATE $table SET " $sqlstatement = "UPDATE $table SET "
. "$fnote = '$note' " . "$fnote = '$note' "
@@ -588,43 +688,46 @@ sub interactive
# create menu: # create menu:
local $B = "<blackI>"; local $B = "<blackI>";
local $BB = "</blackI>"; local $BB = "</blackI>";
local $menu = "[ " . $B . "L" . $BB . " List " local $menu = "[" . $B . "L" . $BB . " List "
. $B . "N" . $BB . " New " . $B . "N" . $BB . " New "
. $B . "D" . $BB . " Delete " . $B . "D" . $BB . " Delete "
. $B . "S" . $BB . " Search " . $B . "S" . $BB . " Search "
. $B . "E" . $BB . " Edit " . $B . "E" . $BB . " Edit ";
. $B . "?" . $BB . " Help " if($TOPIC)
. $B . "Q" . $BB . " Quit ] command> "; {
$menu .= $B . "T" . $BB . " Topic ";
}
$menu .= $B . "?" . $BB . " Help "
. $B . "Q" . $BB . " Quit] "; # $CurTopic will be empty if $TOPIC is off!
# per default let's list all the stuff: # per default let's list all the stuff:
# Initially do a list command! # Initially do a list command!
$maxlen += $timelen; $maxlen += $timelen;
print "\n";
&list; &list;
for(;;) for(;;)
{ {
#&list;
$time = `date +%d\".\"%m\".\"%Y\" \"%T`; $time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time; chomp $time;
$ListType = ""; $ListType = "";
$maxlen = $maxlen_save; $maxlen = $maxlen_save;
print C $menu; print C $menu . $TOPICC . $CurTopic . $_TOPICC . ">";
# endless until user press "Q" or "q"! # endless until user press "Q" or "q"!
$char = <STDIN>; $char = <STDIN>;
chomp $char; chomp $char;
if($char =~ /^\d+/) if($char =~ /^\d+/)
{ {
# display notes # display notes
$maxlen += $timelen;
$number = $char; $number = $char;
&display; &display;
} }
elsif($char =~ /^n/i) elsif($char =~ /^n$/i)
{ {
# create a new one # create a new one
$time = `date +%d\".\"%m\".\"%Y\" \"%T`; $time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time; chomp $time;
&new; &new;
} }
elsif($char =~ /^l/ || $char =~ /^$/) elsif($char =~ /^l$/ || $char =~ /^$/)
{ {
# list # list
print "\n"; print "\n";
@@ -633,13 +736,14 @@ sub interactive
&list; &list;
undef $SetTitle; undef $SetTitle;
} }
elsif($char =~ /^L/) elsif($char =~ /^L$/)
{ {
$ListType = "LONG"; $ListType = "LONG";
print "\n";
&list; &list;
undef $SetTitle; undef $SetTitle;
} }
elsif($char =~ /^h/i || $char =~ /^\?/) elsif($char =~ /^h$/i || $char =~ /^\?/)
{ {
# zu dumm der Mensch ;-) # zu dumm der Mensch ;-)
&help; &help;
@@ -679,7 +783,6 @@ sub interactive
elsif($char =~ /^s\s+/i) elsif($char =~ /^s\s+/i)
{ {
# she want's to search # she want's to search
#$maxlen += $timelen;
$searchstring = $'; $searchstring = $';
chomp $searchstring; chomp $searchstring;
&search; &search;
@@ -687,7 +790,6 @@ sub interactive
elsif($char =~ /^s$/i) elsif($char =~ /^s$/i)
{ {
# we have to ask her: # we have to ask her:
#$maxlen += $timelen;
print "enter the string you want to search for: "; print "enter the string you want to search for: ";
$char = <STDIN>; $char = <STDIN>;
chomp $char; chomp $char;
@@ -695,16 +797,45 @@ sub interactive
$searchstring = $char; $searchstring = $char;
&search; &search;
} }
elsif($char =~ /^q/i) elsif($char =~ /^q$/i)
{ {
# schade!!! # schade!!!
print "\n\ngood bye\n"; print "\n\ngood bye\n";
exit(0); exit(0);
} }
elsif($char =~ /^t$/i && $TOPIC)
{
$SaveTopic = $CurTopic;
$CurTopic = "";
#$maxlen += $timelen;
print "\n";
&list;
$CurTopic = $SaveTopic;
undef $SetTitle;
}
elsif($char =~ /^\.\.$/)
{
$CurTopic = "default";
$maxlen += $timelen;
print "\n";
&list;
undef $SetTitle;
}
else else
{ {
# unknown # unknown
print "\nunknown command!\n"; if(exists $TP{$char})
{
$CurTopic = $char;
$maxlen += $timelen;
print "\n";
&list;
undef $SetTitle;
}
else
{
print "\nunknown command!\n";
}
} }
} }
} }
@@ -720,8 +851,9 @@ Usage: note [-i | --interactive] | [ options ] [ number [,number...]]
Options: Options:
-h --help displays this help screen -h --help displays this help screen
-v --version displays the version number -v --version displays the version number
-l --list lists all existing notes -l --list [<topic>] lists all existing notes If no topic were specified,
-L --longlist the same as -l but prints also the timestamp it will display a list of all existing topics.
-L --longlist [<topic>] the same as -l but prints also the timestamp
-s --search <string> searches for <string> trough the notes database -s --search <string> searches for <string> trough the notes database
-e --edit <number> edit note with <number> -e --edit <number> edit note with <number>
-d --delete <number> delete note with <number> -d --delete <number> delete note with <number>
@@ -967,24 +1099,30 @@ print qq~
HELP for interactive note $version HELP for interactive note $version
The following commands are available: The following commands are available:
L/l List notes. L=long, with timestamp and l=short without L/l List notes. L=long, with timestamp and l=short without timestamp.
timestamp. You can also just hit <enter> for short list. You can also just hit <enter> for short list.
N Create a new note. N Create a new note.
D Delete a note. You can either hit "d 1" or "d 1-4" D Delete a note. You can either hit "d 1" or "d 1-4" or just hit "d".
or just hit "d". If you don't specify a number, you If you don't specify a number, you will be asked for.
will be asked for. S Search trough the notes database. Usage is similar to Delete, use
S Search trough the notes database. Usage is similar to a string instead of a number to search for.
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 note
E Edit a note. Usage is similar to Delete but you can a time.~;
only edit one note a time. if($TOPIC)
?/H This help screen. {
Q Exit the program. print qq~
T print a list of all existing topics. You can change the actual
topic by simply typing it's name. You can create a new topic by
creating a new note, the first line must be the topic borderd by
backslashes, i.e.: "\\newtopic\\". If you type just ".." instead
of a topic, you will go to the "default" topic, which contains
all notes without a topic.~;
}
print qq~
?/H This help screen.
Q Exit the program.
All commands except the List command are case insensitive. All commands except the List command are case insensitive.
--------------------------------------------------------------- ---------------------------------------------------------------
~; ~;
} }