mirror of
https://codeberg.org/scip/note.git
synced 2025-12-17 04:31:02 +01:00
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:
244
mysql-db/note
244
mysql-db/note
@@ -56,6 +56,10 @@ $BORDER_COLOR = "BLACK";
|
||||
$NUM_COLOR = "blue";
|
||||
$NOTE_COLOR = "magenta";
|
||||
$TIME_COLOR = "black";
|
||||
$TOPIC_COLOR = "BLACK";
|
||||
|
||||
# Turns Topic Support on
|
||||
$TOPIC = 1;
|
||||
###################################
|
||||
|
||||
|
||||
@@ -75,7 +79,7 @@ sub list;
|
||||
sub help;
|
||||
sub import;
|
||||
|
||||
$version = "0.4.2 (mysql database)";
|
||||
$version = "0.5 (mysql database)";
|
||||
|
||||
# process command line args
|
||||
if($ARGV[0] eq "")
|
||||
@@ -98,22 +102,24 @@ else
|
||||
}
|
||||
$ARGV[0] = "";
|
||||
}
|
||||
elsif($ARGV[0] eq "-i" || $ARGV[0] eq "--interactive")
|
||||
{
|
||||
$mode = "interactive";
|
||||
$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";
|
||||
$CurTopic = $ARGV[1];
|
||||
$ARGV[0] = "";
|
||||
}
|
||||
elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist")
|
||||
{
|
||||
$mode = "list";
|
||||
$ListType = "LONG";
|
||||
$ARGV[0] = "";
|
||||
}
|
||||
elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist")
|
||||
{
|
||||
$mode = "list";
|
||||
$ListType = "LONG";
|
||||
$CurTopic = $ARGV[1];
|
||||
$ARGV[0] = "";
|
||||
}
|
||||
elsif($ARGV[0] eq "-s" || $ARGV[0] eq "--search")
|
||||
{
|
||||
# searching
|
||||
@@ -172,7 +178,7 @@ else
|
||||
}
|
||||
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);
|
||||
}
|
||||
elsif($ARGV[0] eq "-h" || $ARGV[0] eq "--help")
|
||||
@@ -214,15 +220,14 @@ $NOTEC = "<$NOTE_COLOR>";
|
||||
$_NOTEC = "</$NOTE_COLOR>";
|
||||
$TIMEC = "<$TIME_COLOR>";
|
||||
$_TIMEC = "</$TIME_COLOR>";
|
||||
$TOPICC = "<$TOPIC_COLOR>";
|
||||
$_TOPICC = "</$TOPIC_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")
|
||||
if($ListType ne "LONG" && $mode ne "interactive")
|
||||
{
|
||||
$maxlen += $timelen; # no time will be displayed!
|
||||
}
|
||||
@@ -233,6 +238,7 @@ $db = Mysql->connect($dbhost,$dbname,$dbuser,$dbpasswd)
|
||||
or die "ERROR: $Mysql::dberrstr\n";
|
||||
|
||||
|
||||
|
||||
# main loop: ###############
|
||||
if($mode eq "display")
|
||||
{
|
||||
@@ -337,14 +343,87 @@ sub search
|
||||
############################### 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)
|
||||
$res = $db->query("SELECT $fnum,$fnote,$fdate FROM $table ORDER BY $fnum")
|
||||
or die "ERROR: $Mysql::dberrstr\n";
|
||||
if($TOPIC && $CurTopic eq "")
|
||||
{
|
||||
undef %TP;
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
@@ -369,7 +448,13 @@ sub new
|
||||
# read it in ($note)
|
||||
$note = "";
|
||||
#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;
|
||||
while(<E>)
|
||||
{
|
||||
@@ -406,6 +491,18 @@ sub new
|
||||
$number = $row[0];
|
||||
}
|
||||
$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')";
|
||||
|
||||
$db->query($sqlstatement)
|
||||
@@ -500,6 +597,9 @@ sub edit
|
||||
close NOTE;
|
||||
|
||||
system "/bin/rm -f $TEMP";
|
||||
|
||||
# mask all occuring \'s
|
||||
$note =~ s/\\/\\\\/g;
|
||||
|
||||
# we got it, now save to db
|
||||
$sqlstatement = "UPDATE $table SET "
|
||||
@@ -588,43 +688,46 @@ sub interactive
|
||||
# create menu:
|
||||
local $B = "<blackI>";
|
||||
local $BB = "</blackI>";
|
||||
local $menu = "[ " . $B . "L" . $BB . " List "
|
||||
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> ";
|
||||
. $B . "E" . $BB . " Edit ";
|
||||
if($TOPIC)
|
||||
{
|
||||
$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:
|
||||
# Initially do a list command!
|
||||
$maxlen += $timelen;
|
||||
print "\n";
|
||||
&list;
|
||||
for(;;)
|
||||
{
|
||||
#&list;
|
||||
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
|
||||
chomp $time;
|
||||
$ListType = "";
|
||||
$maxlen = $maxlen_save;
|
||||
print C $menu;
|
||||
print C $menu . $TOPICC . $CurTopic . $_TOPICC . ">";
|
||||
# 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)
|
||||
elsif($char =~ /^n$/i)
|
||||
{
|
||||
# create a new one
|
||||
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
|
||||
chomp $time;
|
||||
&new;
|
||||
}
|
||||
elsif($char =~ /^l/ || $char =~ /^$/)
|
||||
elsif($char =~ /^l$/ || $char =~ /^$/)
|
||||
{
|
||||
# list
|
||||
print "\n";
|
||||
@@ -633,13 +736,14 @@ sub interactive
|
||||
&list;
|
||||
undef $SetTitle;
|
||||
}
|
||||
elsif($char =~ /^L/)
|
||||
elsif($char =~ /^L$/)
|
||||
{
|
||||
$ListType = "LONG";
|
||||
print "\n";
|
||||
&list;
|
||||
undef $SetTitle;
|
||||
}
|
||||
elsif($char =~ /^h/i || $char =~ /^\?/)
|
||||
elsif($char =~ /^h$/i || $char =~ /^\?/)
|
||||
{
|
||||
# zu dumm der Mensch ;-)
|
||||
&help;
|
||||
@@ -679,7 +783,6 @@ sub interactive
|
||||
elsif($char =~ /^s\s+/i)
|
||||
{
|
||||
# she want's to search
|
||||
#$maxlen += $timelen;
|
||||
$searchstring = $';
|
||||
chomp $searchstring;
|
||||
&search;
|
||||
@@ -687,7 +790,6 @@ sub interactive
|
||||
elsif($char =~ /^s$/i)
|
||||
{
|
||||
# we have to ask her:
|
||||
#$maxlen += $timelen;
|
||||
print "enter the string you want to search for: ";
|
||||
$char = <STDIN>;
|
||||
chomp $char;
|
||||
@@ -695,16 +797,45 @@ sub interactive
|
||||
$searchstring = $char;
|
||||
&search;
|
||||
}
|
||||
elsif($char =~ /^q/i)
|
||||
elsif($char =~ /^q$/i)
|
||||
{
|
||||
# schade!!!
|
||||
print "\n\ngood bye\n";
|
||||
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
|
||||
{
|
||||
# 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:
|
||||
-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
|
||||
-l --list [<topic>] lists all existing notes If no topic were specified,
|
||||
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
|
||||
-e --edit <number> edit note with <number>
|
||||
-d --delete <number> delete note with <number>
|
||||
@@ -967,24 +1099,30 @@ 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.
|
||||
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 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.
|
||||
Q Exit the program.
|
||||
|
||||
All commands except the List command are case insensitive.
|
||||
---------------------------------------------------------------
|
||||
~;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user