FIXED: oops - the new suptopic feature confused the commandline-mode of

note! quickly corrected! so subtopics also available from command-
                line.
FIXED:          a small bug fiyed, it was impossible to use -D or -I from command-
                line, if $ALWAYS_INT was turned on, now it is.
FIXED:          fixed problem with local/global variable $time, which confused
                the script under certain circumstances, now $time is no more global,
                it will be read in (using &getdate) locally by &new and &edit.
CHANGED:        The Topic separator is no longer hardcoded, one can customize
                it using the $TopicSep variable, the default is now /, the backslash
                will no mor work!
CHANGED:        use perl buildin localtime() function instead of
                GNU date, which is possibly not installed on every target
                system (i.e. win32), therefore better portability!
CHANGED:        use now the strict module
ADDED:          Support for subtopics added (and sub-sub-..-topics).
CHANGED:        Removed the "T" command, it is now obsolete.
CHANGED:        behavior of list command changed, now shows topics as well as
                notes under the current topic(if there are some).
CHANGED:        The ".." command takes you now one level higher in your topic-
                structure.
ADDED:          A new config option $PreferredEditor, which you can use to
                specify your own choice of editor.
FIXED:          A bug at line 769 causing single note where smaller than note-
                listings
This commit is contained in:
TLINDEN
2012-02-10 20:11:22 +01:00
parent 6c5db55b5e
commit 142ff12b12
7 changed files with 636 additions and 320 deletions

View File

@@ -1,3 +1,39 @@
==================================================================================
0.6:
FIXED: oops - the new suptopic feature confused the commandline-mode of
note! quickly corrected! so subtopics also available from command-
line.
FIXED: a small bug fiyed, it was impossible to use -D or -I from command-
line, if $ALWAYS_INT was turned on, now it is.
FIXED: fixed problem with local/global variable $time, which confused
the script under certain circumstances, now $time is no more global,
it will be read in (using &getdate) locally by &new and &edit.
CHANGED: The Topic separator is no longer hardcoded, one can customize
it using the $TopicSep variable, the default is now /, the backslash
will no mor work!
CHANGED: use perl buildin localtime() function instead of
GNU date, which is possibly not installed on every target
system (i.e. win32), therefore better portability!
CHANGED: use now the strict module
ADDED: Support for subtopics added (and sub-sub-..-topics).
CHANGED: Removed the "T" command, it is now obsolete.
CHANGED: behavior of list command changed, now shows topics as well as
notes under the current topic(if there are some).
CHANGED: The ".." command takes you now one level higher in your topic-
structure.
ADDED: A new config option $PreferredEditor, which you can use to
specify your own choice of editor.
FIXED: A bug at line 769 causing single note where smaller than note-
listings
==================================================================================
0.5:
ADDED: Topic support(requested). You can sort the various notes under
different topics now.
@@ -5,6 +41,11 @@ FIXED: There was another bug, which caused the list command to display
the notes with a too high value of $maxlen.
==================================================================================
0.4.2:
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.
@@ -14,6 +55,10 @@ FIXED: Some more vars will be resetted during each loop in interactive mode.
==================================================================================
0.4.1:
ADDED: The install.sh script for the mysql version is no able to install the
required Mysql module directly from CPAN, thanks to David A. Bandel!
@@ -28,6 +73,11 @@ FIXED: the function num_bereich() had a bug, which caused ot to ignore under
some circumstances one number (i.e. "note -d 4-13" did nothing).
==================================================================================
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
@@ -43,12 +93,20 @@ 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:
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:
FIXED: now any occurence of ' will be masked with \' before storage
to the mysql database.
@@ -57,5 +115,7 @@ FIXED: now numbers of notes will be recounted, if one delete one note,
CHANGED: the look of the list output has been changed, similar to a table
==================================================================================
0.1:
INITIAL RELEASE.

68
README
View File

@@ -1,4 +1,4 @@
note 0.5 by Thomas Linden, 23/01/2000
note 0.6 by Thomas Linden, 21/02/2000
Introduction
@@ -89,11 +89,11 @@ Usage
If you want to get an overview of all notes, type "note -l".
You will get a list of all notes, containing the number,
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".
turned on (which is by default), then all subtopics under the
current topic will be displayed first.
If you want to get a listing of all
If you want to see the timestamps, 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
editor (vi or pico). You can edit it, after saving, note
@@ -137,30 +137,62 @@ Topics
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 the first line of your note contains some text bordered by slashes
(or whatever you prefer, set $TopicSep in your config! default is slash),
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).
"/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
You can create at any time from any point a new topic. Just create a new
note and type the name of the new topic bordered by slashes (or $TopicSep)
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 create as many subtopics as you like, the format is similar to a
filesystem-path. An example, say, you want to create such a structure:
(root - top level)
|
|----test
| |----subtopic
| | |--note 1
| | |--note 2
| |
| |--note 4
|
|--note 3
Then you may create those 4 new notes:
--- snip ---
/test/subtopic/
note 1
--- snip ---
/test/subtopic/
note 2
--- snip ---
note 3
--- snip ---
/test/
note 4
--- snip ---
I hope, you got the point ;-)
If a note does not contain the "magic" /topic/ construction on the first
line, it will be listed under the "root" of note, that is the point you are
at the startup of note.
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.
Note: Please don't forget the prepending and appending a slash of a topic.
You will get strange results without it!
@@ -303,4 +335,4 @@ Author
Last changed
============
23.01.2000
21.02.2000

View File

@@ -1 +1 @@
0.5
0.6

View File

@@ -1,5 +1,30 @@
#!/usr/bin/perl
#
# $Id: note,v 1.7 2000/02/25 21:00:15 tom Exp tom $ $Author: tom $ $Revision: 1.7 $
#
# $Log: note,v $
# Revision 1.7 2000/02/25 21:00:15 tom
# corrected small timestamp problem in &edit and &new
#
# Revision 1.6 2000/02/25 13:23:25 tom
# fixed a small bug, that caused to use the last line for a note title instead the 2nd.
#
# Revision 1.5 2000/02/25 10:19:58 tom
# help modified about topic sep...
#
# Revision 1.4 2000/02/25 10:13:06 tom
# added $TopicSep
#
# Revision 1.3 2000/02/25 09:46:06 tom
# removed usage of gnu date, use localtime instead
#
# Revision 1.2 2000/02/25 09:24:27 tom
# changed to use strict, seems all still working ;-)
#
# Revision 1.1 2000/02/25 08:23:20 tom
# Initial revision
#
#
# this is the small console program "note" (BINARY version)
# It works similar to some well known GUI note programs,
# but instead of using X11 it uses the UN*X console.
@@ -13,6 +38,41 @@
# If you find it usefull or find a bug, please let me know:
# Thomas Linden <tom@daemon.de>
#use Data::Dumper;
sub usage;
sub find_editor;
sub output;
sub C;
sub uen;
sub ude;
sub num_bereich;
sub getdate;
sub new;
sub edit;
sub del;
sub display;
sub list;
sub help;
sub import;
use IO::Seekable;
use strict;
my (
$maxlen, $timelen, $TOPIC, $TYPE, $mode, $NOTEDB,
$version, $number, $CurTopic, $CurDepth, $PATH, $CONF,
$sizeof, $MAX_TIME, $PreferredEditor, %TP, $TopicSep,
$ListType, $searchstring, $dump_file, $ALWAYS_INT,
$BORDERC, $BORDER_COLOR, $_BORDERC, $NOTEC, $NOTE_COLOR,
$NUMC, $NUM_COLOR, $_NUMC, $_NOTEC, $TIMEC, $TIME_COLOR,
$_TIMEC, $TOPICC, $TOPIC_COLOR, $_TOPICC, $SetTitle, $COLOR,
$typedef, $MAX_NOTE, $MAX_TIME, @NumBlock, $ALWAYS_EDIT, $HOME
);
#################################################
# define some default values.
@@ -42,30 +102,19 @@ $TOPIC_COLOR = "BLACK";
# Turns Topic Support on
$TOPIC = 1;
# Default topic separator: \
$TopicSep = '/';
$version = "0.6 (binary database)";
if($TOPIC)
{
$CurDepth = 1; # the current depth inside the topic "directory" structure...
}
#################################################
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;
sub import;
use IO::Seekable;
$version = "0.5 (binary database)";
# process command line args
if($ARGV[0] eq "")
{
@@ -95,7 +144,9 @@ else
elsif($ARGV[0] eq "-l" || $ARGV[0] eq "--list")
{
$mode = "list";
$CurTopic = $ARGV[1];
my @ArgTopics = split /$TopicSep/,$ARGV[1];
$CurDepth += $#ArgTopics + 1 if $ARGV[1];
$CurTopic = $ArgTopics[$#ArgTopics]; # use the last element everytime...
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist")
@@ -187,7 +238,7 @@ if(-e $CONF)
}
# Always interactive?
if($ALWAYS_INT eq "YES")
if($ALWAYS_INT eq "YES" && $mode ne "dump" && $mode ne "import")
{
$mode = "interactive";
}
@@ -219,8 +270,6 @@ $_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, () );
@@ -232,7 +281,6 @@ if($ListType ne "LONG" && $mode ne "interactive")
}
# main loop: ###############
if($mode eq "display")
{
@@ -284,7 +332,7 @@ exit(0);
############################### DISPLAY ##################################
sub display
{
print "\n";
my($N,$address,$buffer,$n,$t,$match,$note,$time,$num);
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
&num_bereich; # get @NumBlock from $numer
foreach $N (@NumBlock)
@@ -313,6 +361,7 @@ sub display
############################### SEARCH ##################################
sub search
{
my($n,$t,$match,$note,$time,$num,$buffer);
$maxlen += $timelen;
if($searchstring eq "")
{
@@ -345,27 +394,19 @@ sub search
############################### LIST ##################################
sub list
{
#system("clear") or print "\n\n\n\n";
my(@topic,@RealTopic, $i,$buffer,$t,$n,$num,$note,$time,@CurItem,$top,$in);
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";
seek(NOTE, 0, 0); # START FROM BEGINNING
if($TOPIC && $CurTopic eq "")
if($TOPIC)
{
undef %TP;
undef %TP; # the beginning!
}
$i = 0;
while(read(NOTE, $buffer, $sizeof))
{
($num, $note, $time) = unpack($typedef, $buffer);
@@ -374,39 +415,49 @@ sub list
if($TOPIC)
{
# this allows us to have multiple topics (subtopics!)
@topic = split(/\\/,$n);
if($CurTopic eq "")
my ($firstline,$dummy) = split /\n/, $n, 2;
if($firstline =~ /^($TopicSep)/)
{
# looks like: "\topic\"
# collect:
if($topic[1] eq "")
{
$topic[1] = "default";
}
if(exists $TP{$topic[1]})
{
$TP{$topic[1]}++;
@topic = split(/$TopicSep/,$firstline);
}
else
{
$TP{$topic[1]} = 1;
@topic = ();
}
# looks like: "\topic\"
# collect a list of topics under the current topic
if($topic[$CurDepth-1] eq $CurTopic && $topic[$CurDepth] ne "")
{
if(exists $TP{$topic[$CurDepth]})
{
$TP{$topic[$CurDepth]}++;
}
else
{
# only if the next item *is* a topic!
$TP{$topic[$CurDepth]} = 1 if(($CurDepth) <= $#topic);
}
}
elsif($topic[$CurDepth-1] eq $CurTopic || ($topic[$CurDepth] eq "" && $CurDepth ==1))
{
# cut the topic off the note-text
if($n =~ /^($TopicSep)/)
{
$CurItem[$i]->{'note'} = $dummy;
}
else
{
$CurItem[$i]->{'note'} = $n;
}
}
else
# save for later output() call
$CurItem[$i]->{'num'} = $num;
$CurItem[$i]->{'time'} = $t;
$i++;
# use this note for building the $PATH!
if($RealTopic[0] eq "")
{
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);
@RealTopic = @topic;
}
}
}
@@ -415,12 +466,33 @@ sub list
output($num, $n, $t);
}
}
if($TOPIC && $CurTopic eq "")
if($TOPIC)
{
if($CurTopic ne "")
{
undef $PATH;
foreach (@RealTopic)
{
$PATH .= $_ . $TopicSep;
last if($_ eq $CurTopic);
}
}
else
{
$PATH = $TopicSep;
}
# 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";
output("-", " => ". $top . "$TopicSep ($TP{$top} notes)",
" Sub Topic ");
}
for($in=0;$in<$i;$in++)
{
output( $CurItem[$in]->{'num'},
$CurItem[$in]->{'note'},
$CurItem[$in]->{'time'} );
}
}
close(NOTE);
@@ -431,6 +503,8 @@ sub list
############################### NEW ##################################
sub new
{
my($time, $TEMP,$editor, $note, $WARN, $c, $line, $num, $te, $me, $buff,$buffer, @topic,$n,$t);
$time = &getdate;
if($ALWAYS_EDIT eq "YES")
{
$TEMP = "/tmp/note.$$";
@@ -468,7 +542,7 @@ sub new
else
{
$note = "";
local $line = "";
$line = "";
#local $num = 0;
# create a new note
print "enter the text of the note, end with .\n";
@@ -494,18 +568,19 @@ sub new
if($TOPIC && $CurTopic ne "")
{
@topic = split(/\\/,$note);
@topic = split(/$TopicSep/,$note);
if($topic[1] eq "")
{
$note = "\\$CurTopic\\\n$note";
#$note = "\\$CurTopic\\\n$note";
$note = $PATH . "\n$note";
}
}
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
seek(NOTE, 0, SEEK_END); # APPEND
local $n = uen($note);
local $t = uen($time);
$n = uen($note);
$t = uen($time);
$buffer = pack($typedef, $num, $n, $t);
print NOTE $buffer;
@@ -517,6 +592,7 @@ sub new
############################### DELETE ##################################
sub del
{
my($TEMP,$count, $buff, %Merk, $num, $note, $time, $droped, $buffer);
&num_bereich; # get @NumBlock from $number
$TEMP = "/tmp/note.$$"; # save temporarily in $TEMP
system("/bin/touch", $TEMP);
@@ -530,10 +606,10 @@ sub del
# read from notedb and write to temp (without number to
# be deleted, and with recounted numbers)
foreach $N (@NumBlock)
foreach (@NumBlock)
{
# define $Merk's for the exists() test later on...
$Merk{$N} = "got";
$Merk{$_} = "got";
}
while(read(NOTE, $buff, $sizeof))
@@ -578,6 +654,8 @@ sub del
############################### EDIT ##################################
sub edit
{
my($time,$editor, $TEMP, $address, $n, $buff, $c, $note, $t, $buffer, $num);
$time = &getdate;
$address = ($number -1 ) * $sizeof;
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
seek(NOTE, $address, SEEK_SET);
@@ -624,7 +702,7 @@ sub edit
seek(NOTE, $address, SEEK_SET);
$n = "";
$n = uen($note);
local $t = uen($time);
$t = uen($time);
$buffer = pack($typedef, $number, $n, $t);
print NOTE $buffer;
close(NOTE);
@@ -634,6 +712,7 @@ sub edit
sub dump
{
my($buffer,$num, $note, $time,$n, $t);
# $dump_file
open (DUMP, ">$dump_file") or die "could not open $dump_file\n";
select DUMP;
@@ -655,6 +734,7 @@ sub dump
sub import
{
my($buff, $num,$te, $me, $start, $complete, $dummi, $n, $t, $buffer, $note, $time, $date);
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
@@ -668,8 +748,8 @@ sub import
# open $dump_file and import it into the notedb
open (DUMP, "<$dump_file") or die "could not open $dump_file\n";
local $complete=0;
local $start = 0;
$complete=0;
$start = 0;
open (NOTE, "+<$NOTEDB") or die "could not open .notedb\n";
while(<DUMP>)
{
@@ -687,8 +767,8 @@ sub import
# we got a complete record, save it!
seek(NOTE, 0, SEEK_END); # APPEND
local $n = uen($note);
local $t = uen($date);
$n = uen($note);
$t = uen($date);
$buffer = pack($typedef, $num, $n, $t);
print NOTE $buffer;
$num++;
@@ -715,8 +795,8 @@ sub import
{
# the last record, if existent
seek(NOTE, 0, SEEK_END); # APPEND
local $n = uen($note);
local $t = uen($date);
$n = uen($note);
$t = uen($date);
$buffer = pack($typedef, $num, $n, $t);
print NOTE $buffer;
print "note number $number from $dump_file inserted into notedb.\n";
@@ -731,48 +811,51 @@ sub import
sub interactive
{
my($maxlen_save, $B, $BB, $menu, $time, $char, @LastTopic);
$maxlen_save = $maxlen;
# create menu:
local $B = "<blackI>";
local $BB = "</blackI>";
local $menu = "[" . $B . "L" . $BB . " List "
$B = "<blackI>";
$BB = "</blackI>";
$menu = "[" . $B . "L" . $BB . " List "
. $B . "N" . $BB . " New "
. $B . "D" . $BB . " Delete "
. $B . "S" . $BB . " Search "
. $B . "E" . $BB . " Edit ";
if($TOPIC)
{
$menu .= $B . "T" . $BB . " Topic ";
}
$menu .= $B . "?" . $BB . " Help "
. $B . "E" . $BB . " Edit "
. $B . "?" . $BB . " Help "
. $B . "Q" . $BB . " Quit] "; # $CurTopic will be empty if $TOPIC is off!
# Initially do a list command!
$maxlen += $timelen;
print "\n";
&list;
undef $SetTitle;
# per default let's list all the stuff:
for(;;)
{
# reset time
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
$ListType = "";
$maxlen = $maxlen_save;
if($CurDepth > 2)
{
print C $menu . $TOPICC . "../" . $CurTopic . $_TOPICC . ">";
}
else
{
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;
undef $SetTitle;
}
elsif($char =~ /^n$/i)
{
# create a new one
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
&new;
}
elsif($char =~ /^l$/ || $char =~ /^$/)
@@ -814,8 +897,6 @@ sub interactive
elsif($char =~ /^e\s+(\d+\-*\,*\d*)/i)
{
# edit one!
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
$number = $1;
&edit;
}
@@ -852,19 +933,10 @@ sub interactive
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";
$CurDepth-- if ($CurDepth > 1);
$CurTopic = $LastTopic[$CurDepth];
$maxlen += $timelen;
print "\n";
&list;
@@ -875,8 +947,10 @@ sub interactive
# unknown
if(exists $TP{$char})
{
$LastTopic[$CurDepth] = $CurTopic;
$CurTopic = $char;
$maxlen += $timelen;
$CurDepth++;
print "\n";
&list;
undef $SetTitle;
@@ -926,11 +1000,15 @@ Options:
exit 1;
}
sub find_editor {
return $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
return $PreferredEditor || $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
}
#/
sub output
{
my($SSS, $LINE, $num, $note, $time, $TYPE, $L, $LONGSPC, $R, $PathLen, $SP, $title, $CUTSPACE,
$len, $diff, $Space);
# 0 = Num, 1 = Note, 2 = Time
if($ListType ne "LONG")
{
@@ -940,27 +1018,28 @@ sub output
{
$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;
$LINE = "$BORDERC $SSS $_BORDERC\n";
$num = $_[0];
$note = $_[1];
$time = $_[2];
$TYPE = $_[3];
$L = $BORDERC . "[" . $_BORDERC;
$LONGSPC = " " x (22 + 3);
$R = $BORDERC . "]" . $_BORDERC;
$PathLen = length($PATH); # will be ZERO, if not in TOPIC mode!
if($TYPE ne "SINGLE")
{
if(!$SetTitle)
{
local $SP = "";
$SP = "";
# print only if it is the first line!
if($ListType ne "LONG")
{
$SP = " " x ($maxlen-2 - $timelen);
$SP = " " x ($maxlen-2 - $timelen - $PathLen);
}
else
{
$SP = " " x ($maxlen-2);
$SP = " " x ($maxlen-2 - $PathLen);
}
print C $LINE;
@@ -973,27 +1052,47 @@ sub output
{
print $LONGSPC;
}
if($TOPIC)
{
print C $TOPICC . "$PATH $_TOPICC$SP$R\n";
}
else
{
print C $NOTEC . "note$_NOTEC$SP$R\n";
}
print C $LINE;
$SetTitle = 1;
}
local $title = "";
$title = "";
$CUTSPACE = " " x $maxlen;
$note =~ s/\n/$CUTSPACE/g;
local $len = length($note);
$len = length($note);
if($len < $maxlen-3)
{
local $diff = $maxlen - $len;
local $Space = " " x $diff;
$diff = $maxlen - $len;
$Space = " " x $diff;
if($num eq "-")
{
$title = $BORDERC . $TOPICC . "\"" . $note . "\"" . $_TOPICC . $Space . "$_BORDERC";
}
else
{
$title = $BORDERC . $NOTEC . "\"" . $note . "\"" . $_NOTEC . $Space . "$_BORDERC";
}
}
else
{
$title = substr($note,0,$maxlen - 3);
if($num eq "-")
{
$title = $BORDERC . $TOPICC . "\"" . $title . "...\"$_TOPICC$_BORDERC";
}
else
{
$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")
@@ -1008,8 +1107,8 @@ sub output
else
{
chomp $note;
local $Space = " " x ($maxlen - 16);
local $SP = " " x ($maxlen + 13);
$Space = " " x ($maxlen - 16);
$SP = " " x ($maxlen + 13);
#print C $LINE;
#print C "$L $NUMC#$_NUMC " . $TIMEC . "creation date$_TIMEC$SP$R\n";
print C $LINE;
@@ -1025,8 +1124,9 @@ sub output
sub C
{
my(%Color, $default, $S, $Col, $NC, $T);
# \033[1m%30s\033[0m
local %Color = ( 'black' => '0;30',
%Color = ( 'black' => '0;30',
'red' => '0;31',
'green' => '0;32',
'yellow' => '0;33',
@@ -1085,14 +1185,16 @@ sub C
sub uen
{
local $T = pack("u", $_[0]);
my($T);
$T = pack("u", $_[0]);
chomp $T;
return $T;
}
sub ude
{
local $T = unpack("u", $_[0]);
my($T);
$T = unpack("u", $_[0]);
return $T;
}
@@ -1100,7 +1202,7 @@ sub num_bereich
{
# $number is the one we want to delete!
# But does it contain kommas?
local $m = 0;
my($m,@LR,@Sorted_LR,$i);
if($number =~ /\,/)
{
# accept -d 3,4,7
@@ -1109,8 +1211,8 @@ sub num_bereich
elsif($number =~ /^\d+\-\d+$/)
{
# accept -d 3-9
local @LR = split(/\-/,$number);
local @Sorted_LR = ();
@LR = split(/\-/,$number);
@Sorted_LR = ();
if($LR[0] > $LR[1])
{
@@ -1141,6 +1243,19 @@ sub num_bereich
}
sub getdate
{
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon += 1;
$mon =~ s/^(\d)$/0$1/;
$hour =~ s/^(\d)$/0$1/;
$min =~ s/^(\d)$/0$1/;
$sec =~ s/^(\d)$/0$1/;
$mday =~ s/^(\d)$/0$1/;
return "$mday.$mon.$year $hour:$min:$sec";
}
sub help
{
print qq~
@@ -1149,25 +1264,31 @@ 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.
You can also just hit <enter> for short list.~;
if($TOPIC)
{
print qq~
If a "note" starts with a - instead of a number, then it is a
topic. In the brackets you will se, how many notes exists under
that specific topic. Just type the name of the topic to change
to that, it works, just like using cd on a filesystem (without the
cd command). If you type just "..", you will go to the last topic,
you were before (works like "cd ..").
You can create a new topic by creating a new note, the first line
must be the topic borderd by "$TopicSep", i.e.: "/newtopic/". The default
topic separator is "/".
You can have as many subtopics, as you like, i.e.: "/pc/games/x11/".
If you create a new note without a topic-specification, then it
will be put into the current subtopic.~;
}
print qq~
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~
a time.
?/H This help screen.
Q Exit the program.

View File

@@ -1,4 +1,4 @@
# 0.5
# 0.6
# This is a sample config for the note script
# You do not need it, if you keep the values
# here unchanged.
@@ -38,9 +38,13 @@
# uncomment this, if you want to use always your
# favorite editor (even for creating notes) instead
# of <STDIN>
#$ALWAYS_EDIT = "YES"
#$ALWAYS_EDIT = "YES";
# uncomment and edit it, if you want to use another
# editor than the default $EDITOR or as fallback vi.
#$PreferredEditor = "emacs";
# This option turns topic-support on or off
# comment it out, if you don't need it
$TOPIC = 1;

View File

@@ -1,4 +1,20 @@
#!/usr/bin/perl
# $Author: tom $ $Id: note.mysql,v 1.5 2000/02/25 20:59:30 tom Exp tom $ $Revision: 1.5 $
#
# $Log: note.mysql,v $
# Revision 1.5 2000/02/25 20:59:30 tom
# corrected small timestamp problem in &edit and &new
#
# Revision 1.4 2000/02/25 13:24:11 tom
# fixed a small bug, that caused to use the last line for a note title instead the 2nd.
#
# Revision 1.3 2000/02/25 11:28:53 tom
# all changes from bin version applied to sql version
#
# Revision 1.2 2000/02/25 10:30:06 tom
# *** empty log message ***
#
#
# 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.
@@ -17,6 +33,38 @@
# note is GPL software.
use Mysql;
use strict;
use Data::Dumper;
sub usage;
sub find_editor;
sub output;
sub C;
sub uen;
sub ude;
sub num_bereich;
sub getdate;
sub new;
sub edit;
sub del;
sub display;
sub list;
sub help;
sub import;
my (
$maxlen, $timelen, $TOPIC, $TYPE, $mode, $NOTEDB,
$version, $number, $CurTopic, $CurDepth, $PATH, $CONF,
$sizeof, $MAX_TIME, $PreferredEditor, %TP, $TopicSep,
$ListType, $searchstring, $dump_file, $ALWAYS_INT,
$BORDERC, $BORDER_COLOR, $_BORDERC, $NOTEC, $NOTE_COLOR,
$NUMC, $NUM_COLOR, $_NUMC, $_NOTEC, $TIMEC, $TIME_COLOR,
$_TIMEC, $TOPICC, $TOPIC_COLOR, $_TOPICC, $SetTitle, $COLOR,
$typedef, $MAX_NOTE, $MAX_TIME, @NumBlock, $ALWAYS_EDIT, $HOME,
$db, $dbname, $dbhost, $DEFAULTDBNAME, $dbuser, $USER, $dbpasswd,
$table, $fnum, $fnote, $fdate, $date
);
##################################
# define some default values.
@@ -25,8 +73,7 @@ use Mysql;
$maxlen = 20;
$timelen = 22;
$date = `date +%e\".\"%m\".\"%Y\" \"%T`;
chomp $date;
$date = &getdate;
$USER = getlogin || getpwuid($<);
chomp $USER;
@@ -60,27 +107,18 @@ $TOPIC_COLOR = "BLACK";
# Turns Topic Support on
$TOPIC = 1;
# Default topic separator: \
$TopicSep = '/';
$version = "0.6 (mysql database)";
if($TOPIC)
{
$CurDepth = 1; # the current depth inside the topic "directory" structure...
}
###################################
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;
sub import;
$version = "0.5 (mysql database)";
# process command line args
if($ARGV[0] eq "")
{
@@ -110,7 +148,9 @@ else
elsif($ARGV[0] eq "-l" || $ARGV[0] eq "--list")
{
$mode = "list";
$CurTopic = $ARGV[1];
my @ArgTopics = split /$TopicSep/,$ARGV[1];
$CurDepth += $#ArgTopics + 1 if $ARGV[1];
$CurTopic = $ArgTopics[$#ArgTopics]; # use the last element everytime...
$ARGV[0] = "";
}
elsif($ARGV[0] eq "-L" || $ARGV[0] eq "--longlist")
@@ -205,7 +245,7 @@ if(-e $CONF)
# Always interactive?
if($ALWAYS_INT eq "YES")
if($ALWAYS_INT eq "YES" && $mode ne "dump" && $mode ne "import")
{
$mode = "interactive";
}
@@ -223,8 +263,6 @@ $_TIMEC = "</$TIME_COLOR>";
$TOPICC = "<$TOPIC_COLOR>";
$_TOPICC = "</$TOPIC_COLOR>";
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
if($ListType ne "LONG" && $mode ne "interactive")
@@ -233,6 +271,7 @@ if($ListType ne "LONG" && $mode ne "interactive")
}
# 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";
@@ -290,6 +329,7 @@ exit(0);
############################### DISPLAY ##################################
sub display
{
my($N,$address,$buffer,$n,$t,$match,$note,$time,$num,@row,$res);
# display a certain note
print "\n";
&num_bereich; # get @NumBlock from $numer
@@ -312,6 +352,7 @@ sub display
############################### SEARCH ##################################
sub search
{
my($n,$t,$match,$note,$time,$num,$buffer,@row,$res, $sqlstatement);
$maxlen += $timelen;
if($searchstring eq "")
{
@@ -343,26 +384,16 @@ sub search
############################### LIST ##################################
sub list
{
my(@topic,@RealTopic, $i,$buffer,$t,$n,$num,$note,$time,@CurItem,$top,$in, $res, @row);
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 "")
if($TOPIC)
{
undef %TP;
}
@@ -373,38 +404,49 @@ sub list
$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 "")
# this allows us to have multiple topics (subtopics!)
my ($firstline,$dummy) = split /\n/, $n, 2;
if($firstline =~ /^($TopicSep)/)
{
@topic = split(/$TopicSep/,$firstline);
}
else
{
@topic = ();
}
# looks like: "\topic\"
# collect:
if($topic[1] eq "")
# collect a list of topics under the current topic
if($topic[$CurDepth-1] eq $CurTopic && $topic[$CurDepth] ne "")
{
$topic[1] = "default";
}
if(exists $TP{$topic[1]})
if(exists $TP{$topic[$CurDepth]})
{
$TP{$topic[1]}++;
$TP{$topic[$CurDepth]}++;
}
else
{
$TP{$topic[1]} = 1;
# only if the next item *is* a topic!
$TP{$topic[$CurDepth]} = 1 if(($CurDepth) <= $#topic);
}
}
elsif($topic[$CurDepth-1] eq $CurTopic || ($topic[$CurDepth] eq "" && $CurDepth ==1))
{
# cut the topic off the note-text
if($n =~ /^($TopicSep)/)
{
$CurItem[$i]->{'note'} = $dummy;
}
else
{
if($topic[1] eq $CurTopic)
{
# cut the topic from the note-text
if($n =~ /^\\$CurTopic\\\n*/)
{
$n = $';
$CurItem[$i]->{'note'} = $n;
}
output($num, $n, $t);
}
elsif($topic[1] eq "" && $CurTopic eq "default")
# save for later output() call
$CurItem[$i]->{'num'} = $num;
$CurItem[$i]->{'time'} = $t;
$i++;
# use this note for building the $PATH!
if($RealTopic[0] eq "")
{
output($num, $n, $t);
@RealTopic = @topic;
}
}
}
@@ -412,16 +454,35 @@ sub list
{
output($num, $n, $t);
}
}
if($TOPIC)
{
if($CurTopic ne "")
{
undef $PATH;
foreach (@RealTopic)
{
$PATH .= $_ . $TopicSep;
last if($_ eq $CurTopic);
}
}
else
{
$PATH = $TopicSep;
}
}
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";
output("-", " => ". $top . "$TopicSep ($TP{$top} notes)",
" Sub Topic ");
}
#print Dumper(@CurItem);
for($in=0;$in<$i;$in++)
{
output( $CurItem[$in]->{'num'},
$CurItem[$in]->{'note'},
$CurItem[$in]->{'time'} );
}
}
@@ -431,6 +492,8 @@ sub list
############################### NEW ##################################
sub new
{
my($TEMP,$editor, $time, $note, $WARN, $c, $line, $num, $te, $me, $buff,$buffer, @topic,$n,$t,$res, @row,$sqlstatement);
$time = &getdate;
if($ALWAYS_EDIT eq "YES")
{
$TEMP = "/tmp/note.$$";
@@ -458,7 +521,7 @@ sub new
$c = 0;
while(<E>)
{
$_ =~ s/'/\\'/g;
$_ =~ s/'/`/g;
$note = $note . $_;
}
chomp $note;
@@ -469,8 +532,8 @@ sub new
else
{
$note = "";
local $line = "";
#local $num = 0;
$line = "";
#$num = 0;
# create a new note
print "enter the text of the note, end with .\n";
do
@@ -493,10 +556,10 @@ sub new
$number++;
if($TOPIC && $CurTopic ne "")
{
@topic = split(/\\/,$note);
@topic = split(/$TopicSep/,$note);
if($topic[1] eq "")
{
$note = "\\$CurTopic\\\n$note";
$note = $PATH . "\n$note";
}
}
@@ -504,7 +567,6 @@ sub new
$note =~ s/\\/\\\\/g;
$sqlstatement = "INSERT INTO $table VALUES ($number,'$note','$date')";
$db->query($sqlstatement)
or die "ERROR: $Mysql::dberrstr\n";
@@ -516,21 +578,22 @@ sub new
############################### DELETE ##################################
sub del
{
my($i,@count, $setnum, $buff, %Merk, $num, $note, $pos, $droped, $buffer, $sqlstatement,$res, @row, $ERR);
# delete a note
&num_bereich; # get @NumBlock from $number
foreach $N (@NumBlock)
foreach $_ (@NumBlock)
{
$sqlstatement = "DELETE FROM $table WHERE $fnum = $N";
$sqlstatement = "DELETE FROM $table WHERE $fnum = $_";
$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";
print "no note with number $_ found!\n";
}
else
{
print "note number $N has been deleted.\n";
print "note number $_ has been deleted.\n";
}
}
# recount the notenumbers:
@@ -555,7 +618,9 @@ sub del
############################### EDIT ##################################
sub edit
{
my($time, $editor, $TEMP, $address, $n, $buff, $c, $note, $t, $buffer, $num, $sqlstatement, $res, @row, $match);
# edit a note
$time = &getdate;
$sqlstatement = "SELECT $fnote FROM $table WHERE $fnum = $number";
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
while(@row = $res->fetchrow)
@@ -590,7 +655,7 @@ sub edit
$c = 0;
while(<NOTE>)
{
$_ =~ s/'/\\'/g;
$_ =~ s/'/`/g;
$note = $note . $_;
}
chomp $note;
@@ -603,7 +668,8 @@ sub edit
# we got it, now save to db
$sqlstatement = "UPDATE $table SET "
. "$fnote = '$note' "
. "$fnote = '$note', "
. "$fdate = '$time' "
. "WHERE $fnum = $number";
$db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
@@ -613,6 +679,7 @@ sub edit
sub dump
{
my($buffer,$num, $note, $time,$n, $t, $res, @row);
# $dump_file
open (DUMP, ">$dump_file") or die "could not open $dump_file\n";
select DUMP;
@@ -633,10 +700,11 @@ sub dump
sub import
{
my($buff, $num,$te, $me, $start, $complete, $dummi, $n, $t, $buffer, $note, $time, $date);
# open $dump_file and import it into the notedb
open (DUMP, "<$dump_file") or die "could not open $dump_file\n";
local $complete=0;
local $start = 0;
$complete=0;
$start = 0;
while(<DUMP>)
{
chomp $_;
@@ -684,47 +752,51 @@ sub import
sub interactive
{
my($maxlen_save, $B, $BB, $menu, $char, @LastTopic);
$maxlen_save = $maxlen;
# create menu:
local $B = "<blackI>";
local $BB = "</blackI>";
local $menu = "[" . $B . "L" . $BB . " List "
$B = "<blackI>";
$BB = "</blackI>";
$menu = "[" . $B . "L" . $BB . " List "
. $B . "N" . $BB . " New "
. $B . "D" . $BB . " Delete "
. $B . "S" . $BB . " Search "
. $B . "E" . $BB . " Edit ";
if($TOPIC)
{
$menu .= $B . "T" . $BB . " Topic ";
}
$menu .= $B . "?" . $BB . " Help "
. $B . "E" . $BB . " Edit "
. $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;
undef $SetTitle;
for(;;)
{
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
$ListType = "";
$maxlen = $maxlen_save;
if($CurDepth > 2)
{
print C $menu . $TOPICC . "../" . $CurTopic . $_TOPICC . ">";
}
else
{
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;
undef $SetTitle;
}
elsif($char =~ /^n$/i)
{
# create a new one
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
&new;
}
elsif($char =~ /^l$/ || $char =~ /^$/)
@@ -766,8 +838,6 @@ sub interactive
elsif($char =~ /^e\s+(\d+\-*\,*\d*)/i)
{
# edit one!
$time = `date +%d\".\"%m\".\"%Y\" \"%T`;
chomp $time;
$number = $1;
&edit;
}
@@ -803,19 +873,10 @@ sub interactive
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";
$CurDepth-- if ($CurDepth > 1);
$CurTopic = $LastTopic[$CurDepth];
$maxlen += $timelen;
print "\n";
&list;
@@ -826,8 +887,10 @@ sub interactive
# unknown
if(exists $TP{$char})
{
$LastTopic[$CurDepth] = $CurTopic;
$CurTopic = $char;
$maxlen += $timelen;
$CurDepth++;
print "\n";
&list;
undef $SetTitle;
@@ -877,11 +940,13 @@ Options:
exit 1;
}
sub find_editor {
return $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
return $PreferredEditor || $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
}
#/
sub output
{
my($SSS, $LINE, $num, $note, $time, $TYPE, $L, $LONGSPC, $R, $PathLen, $SP, $title, $CUTSPACE,
$len, $diff, $Space);
# 0 = Num, 1 = Note, 2 = Time
if($ListType ne "LONG")
{
@@ -891,27 +956,28 @@ sub output
{
$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;
$LINE = "$BORDERC $SSS $_BORDERC\n";
$num = $_[0];
$note = $_[1];
$time = $_[2];
$TYPE = $_[3];
$L = $BORDERC . "[" . $_BORDERC;
$LONGSPC = " " x (22 + 3);
$R = $BORDERC . "]" . $_BORDERC;
$PathLen = length($PATH); # will be ZERO, if not in TOPIC mode!
if($TYPE ne "SINGLE")
{
if(!$SetTitle)
{
local $SP = "";
$SP = "";
# print only if it is the first line!
if($ListType ne "LONG")
{
$SP = " " x ($maxlen-2 - $timelen);
$SP = " " x ($maxlen-2 - $timelen - $PathLen);
}
else
{
$SP = " " x ($maxlen-2);
$SP = " " x ($maxlen-2 - $PathLen);
}
print C $LINE;
@@ -924,22 +990,36 @@ sub output
{
print $LONGSPC;
}
if($TOPIC)
{
print C $TOPICC . "$PATH $_TOPICC$SP$R\n";
}
else
{
print C $NOTEC . "note$_NOTEC$SP$R\n";
}
print C $LINE;
$SetTitle = 1;
}
local $title = "";
$title = "";
$CUTSPACE = " " x $maxlen;
$note =~ s/\n/$CUTSPACE/g;
local $len = length($note);
$len = length($note);
if($len < $maxlen-3)
{
local $diff = $maxlen - $len;
local $Space = " " x $diff;
$diff = $maxlen - $len;
$Space = " " x $diff;
if($num eq "-")
{
$title = $BORDERC . $TOPICC . "\"" . $note . "\"" . $_TOPICC . $Space . "$_BORDERC";
}
else
{
$title = $BORDERC . $NOTEC . "\"" . $note . "\"" . $_NOTEC . $Space . "$_BORDERC";
}
}
else
{
$title = substr($note,0,$maxlen - 3);
@@ -959,8 +1039,8 @@ sub output
else
{
chomp $note;
local $Space = " " x ($maxlen - 16);
local $SP = " " x ($maxlen + 13);
$Space = " " x ($maxlen - 16);
$SP = " " x ($maxlen + 13);
#print C $LINE;
#print C "$L $NUMC#$_NUMC " . $TIMEC . "creation date$_TIMEC$SP$R\n";
print C $LINE;
@@ -976,8 +1056,9 @@ sub output
sub C
{
my(%Color, $default, $S, $Col, $NC, $T);
# \033[1m%30s\033[0m
local %Color = ( 'black' => '0;30',
%Color = ( 'black' => '0;30',
'red' => '0;31',
'green' => '0;32',
'yellow' => '0;33',
@@ -1036,22 +1117,25 @@ sub C
sub uen
{
local $T = pack("u", $_[0]);
my($T);
$T = pack("u", $_[0]);
chomp $T;
return $T;
}
sub ude
{
local $T = unpack("u", $_[0]);
my($T);
$T = unpack("u", $_[0]);
return $T;
}
sub num_bereich
{
my($m,@LR,@Sorted_LR,$i);
# $number is the one we want to delete!
# But does it contain kommas?
local $m = 0;
$m = 0;
if($number =~ /\,/)
{
# accept -d 3,4,7
@@ -1060,8 +1144,8 @@ sub num_bereich
elsif($number =~ /^\d+\-\d+$/)
{
# accept -d 3-9
local @LR = split(/\-/,$number);
local @Sorted_LR = ();
@LR = split(/\-/,$number);
@Sorted_LR = ();
if($LR[0] > $LR[1])
{
@@ -1091,6 +1175,19 @@ sub num_bereich
}
sub getdate
{
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon += 1;
$mon =~ s/^(\d)$/0$1/;
$hour =~ s/^(\d)$/0$1/;
$min =~ s/^(\d)$/0$1/;
$sec =~ s/^(\d)$/0$1/;
$mday =~ s/^(\d)$/0$1/;
return "$mday.$mon.$year $hour:$min:$sec";
}
sub help
{

View File

@@ -4,3 +4,5 @@ CREATE TABLE note (
date text,
PRIMARY KEY (number)
);
# sample grant statement:
#GRANT ALL PRIVILEGES ON tom_note TO tom@localhost IDENTIFIED BY 'password';