CHANGED: using Makemaker instead of self-written code in Makefile.PL

for installation. No more dependency checks built-in because
                note runs out-of-the-box without additional modules, as a matter fact.
ADDED:          if a search matches exactly on one note it will be displayed
                directly, which avoids typing.
CHANGED:        the main if-else contruct for calling the several subs has
                been replaced by a simple closure call.
CHANGED:        notes will now displayed in a slightly simpler fashion in interactive
                mode, without the separator line between the title and the note.
ADDED:          note can now determine automatically the width and height of
                the terminal window it runs in (in interactive mode only) and
                sets the width/height of what it prints accordingly. the config
                variable "MaxLen" must be set to "auto" (which is the default
                from now on) to get this to work.
ADDED:          any interactive command will now clear the screen before it does
                anything. this look much more uncluttered.
ADDED:          if multiple notes are printed at once (i.e. note 1,2) then the
                separator line between them will no more being printed because
                every notes title is preceded by a line anyway.
CHANGED:        by default the default operation mode is now interactive mode,
                which is somewhat kindlier to new users.
CHANGED:        changed to order which editor note tries to find. vi got now
                higher precedence, because it is likely installed on almost
                any unix system.
CHANGED:        cosmetics.
NOTE:           increased minor version number from 1 to 2 to indicate that
                development begun after 2 1/2 years pause again :-)
This commit is contained in:
TLINDEN
2012-02-10 20:27:05 +01:00
parent 62ede07799
commit 3f3206e506
10 changed files with 1009 additions and 253 deletions

251
bin/note
View File

@@ -1,9 +1,7 @@
#!/usr/bin/perl
# $Id: note,v 1.10 2000/08/19 13:38:33 zarahg Exp $
#
#
# note - console notes management with database and encryption support.
# Copyright (C) 1999-2000 Thomas Linden (see README for details!)
# Copyright (C) 1999-2003 Thomas Linden (see README for details!)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -22,33 +20,33 @@
# - Thomas Linden <tom@daemon.de>
#
# latest version on:
# http://www.daemon.de/software.html
# ftp://www.0x49.org/pub/scip/note/
# http://www.daemon.de/note/
#
use strict;
no strict 'refs';
use Data::Dumper;
use Getopt::Long;
#
# prototypes
#
sub usage; # print usage message for us thumb userz :-)
sub find_editor; # returns an external editor for use
sub output; # used by &list and &display
sub C; # print colourized
sub num_bereich; # returns array from "1-4" (1,2,3,4)
sub getdate; # return pretty formatted day
sub new; # crate new note
sub edit; # edit a note
sub del; # delete a note
sub display; # display one or more notes
sub list; # note-listing
sub help; # interactive help screen
sub import; # import from notedb-dump
sub display_tree; # show nice tree-view
sub tree; # build the tree
sub print_tree; # print the tree, contributed by Jens Heunemann <Jens.Heunemann@consol.de>. THX!
sub usage; # print usage message for us thumb userz :-)
sub find_editor; # returns an external editor for use
sub output; # used by &list and &display
sub C; # print colourized
sub num_bereich; # returns array from "1-4" (1,2,3,4)
sub getdate; # return pretty formatted day
sub new; # crate new note
sub edit; # edit a note
sub del; # delete a note
sub display; # display one or more notes
sub list; # note-listing
sub help; # interactive help screen
sub import; # import from notedb-dump
sub display_tree; # show nice tree-view
sub tree; # build the tree
sub print_tree; # print the tree, contributed by Jens Heunemann <Jens.Heunemann@consol.de>. THX!
#
@@ -97,17 +95,18 @@ my (
# internals
#
$TYPE, $mode, $NoteKey, $TempDir, %Color, @LastTopic,
$version, $CurTopic, $CurDepth, $WantTopic,
$version, $CurTopic, $CurDepth, $WantTopic,$time_format,
$sizeof, %TP, $TreeType, $ListType, $SetTitle,
@ArgTopics, $key, $typedef, @NumBlock, $has_nothing,
);
#
# DEFAULTS, allows one to use note without a config
# DEFAULTS, allows one to use note without a config
# don't change them, instead use the config file!
#
$maxlen = 30;
$maxlen = 50;
my $keepmaxlen = "auto";
$timelen = 22;
$date = &getdate;
$USER = getlogin || getpwuid($<);
@@ -127,7 +126,7 @@ $TIME_COLOR = "blue";
$TOPIC_COLOR = "bold";
$TOPIC = 1;
$TopicSep = '/';
$version = "1.1.1";
$version = "1.2.0";
if ($TOPIC) {
$CurDepth = 1; # the current depth inside the topic "directory" structure...
}
@@ -138,6 +137,7 @@ $table = "note";
$fnote = "note";
$fdate = "date";
$fnum = "number";
$ALWAYS_INT = "YES";
# colors available
# \033[1m%30s\033[0m
@@ -365,7 +365,7 @@ if ($DEFAULT_LIST eq "LONG") {
# *if* loading of the config was successful, try to load the
# configured database backend. Currently supported:
# configured database backend. Currently supported:
# mysql, dbm and binary.
unshift @INC, $libpath;
@@ -373,14 +373,14 @@ if ($dbdriver eq "binary") {
eval {
require NOTEDB::binary;
$db = new NOTEDB($dbdriver, $NOTEDB, $MAX_NOTE, $MAX_TIME, $dbdriver);
}
};
}
elsif ($dbdriver eq "mysql") {
# do the new() later because of the encrypted password!
eval {
require "NOTEDB/mysql.pm";
};
die $@ if($@);
die "mysql backend unsupported: $@\n" if($@);
}
else {
eval {
@@ -389,9 +389,7 @@ else {
};
}
if ($@) {
print "Unsupported database backend: NOTEDB::$dbdriver!\n";
print "The following error has occured:\n------------------------\n" . $@ . "\n------------------------\n";
exit 1;
die "$dbdriver backend unsupported: $@\n";
}
@@ -487,45 +485,23 @@ $version .= " " . $db->version();
# main loop: ###############
if ($mode eq "display") {
&display;
}
elsif ($mode eq "search") {
&search;
}
elsif ($mode eq "list") {
&list;
}
elsif ($mode eq "tree") {
&display_tree;
}
elsif ($mode eq "new") {
&new;
}
elsif ($mode eq "delete") {
del;
}
elsif ($mode eq "edit") {
&edit;
}
elsif ($mode eq "dump") {
&dump;
}
elsif ($mode eq "import") {
&import;
}
elsif ($mode eq "interactive") {
&interactive;
}
else {
#undefined :-(
}
&$mode;
exit(0);
################## EOP ################
############ encrypt a given password ##############
sub encrypt_passwd {
my($key, $crypt_string);
@@ -559,12 +535,12 @@ sub encrypt_passwd {
############################### DISPLAY ##################################
sub display
{
sub display {
my($N,$match,$note,$date,$num);
# display a certain note
print "\n";
&num_bereich; # get @NumBlock from $numer
my $count = scalar @NumBlock;
foreach $N (@NumBlock) {
($note, $date) = $db->get_single($N);
if ($note) {
@@ -572,11 +548,12 @@ sub display
print "$N\n$date\n$note\n\n";
}
else {
output($N, $note, $date, "SINGLE");
output($N, $note, $date, "SINGLE", $count);
print "\n";
}
$match = 1;
}
$count--;
}
if (!$match) {
print "no note with that number found!\n";
@@ -584,8 +561,7 @@ sub display
}
############################### SEARCH ##################################
sub search
{
sub search {
my($n,$match,$note,$date,$num,%res);
if ($searchstring eq "") {
print "No searchstring specified!\n";
@@ -594,9 +570,14 @@ sub search
print "searching the database $dbname for \"$searchstring\"...\n\n";
%res = $db->get_search($searchstring);
my $nummatches = scalar keys %res;
foreach $num (sort { $a <=> $b } keys %res) {
output($num, $res{$num}->{'note'}, $res{$num}->{'date'}, "search");
if ($nummatches == 1) {
output($num, $res{$num}->{'note'}, $res{$num}->{'date'}, "SINGLE");
}
else {
output($num, $res{$num}->{'note'}, $res{$num}->{'date'}, "search");
}
$match = 1;
}
if (!$match) {
@@ -681,7 +662,6 @@ sub list {
}
else {
# it is an empty topic, no notes here
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$PATH = join $TopicSep, @LastTopic;
$PATH .= $TopicSep . $CurTopic . $TopicSep;
$PATH =~ s/^\Q$TopicSep$TopicSep\E/$TopicSep/;
@@ -707,8 +687,7 @@ sub list {
}
############################### NEW ##################################
sub new
{
sub new {
my($TEMP,$editor, $date, $note, $WARN, $c, $line, $num, @topic);
$date = &getdate;
if ($ALWAYS_EDIT eq "YES") {
@@ -717,7 +696,7 @@ sub new
$editor = &find_editor;
if ($editor) {
# create the temp file
open NEW, "> $TEMP" or die $!;
open NEW, "> $TEMP" or die "Could not write $TEMP: $!\n";
close NEW;
system "chattr", "+s", $TEMP; # ignore errors, since only on ext2 supported!
system $editor, $TEMP;
@@ -754,7 +733,7 @@ sub new
}
}
else {
print "enter the text of the note, end with .\n";
print "enter the text of the note, end with a single .\n";
do
{
$line = <STDIN>;
@@ -765,8 +744,12 @@ sub new
chop $note;
}
}
# since we have not number, look for the next available:
# look if the note was empty, so don't store it!
if ($note =~ /^\s*$/) {
print "...your note was empty and will not be saved.\n";
return;
}
# since we have not a number, look for the next one available:
$number = $db->get_nextnum();
if ($TOPIC && $CurTopic ne "") {
@topic = split(/$TopicSep/,$note);
@@ -774,18 +757,14 @@ sub new
$note = $PATH . "\n$note";
}
}
$db->set_new($number,$note,$date);
# everything ok until here!
print "note stored. it has been assigned the number $number.\n\n";
}
############################### DELETE ##################################
sub del
{
sub del {
my($i,@count, $setnum, $pos, $ERR);
# delete a note
&num_bereich; # get @NumBlock from $number
@@ -805,8 +784,7 @@ sub del
}
############################### EDIT ##################################
sub edit
{
sub edit {
my($keeptime, $date, $editor, $TEMP, $note, $t, $num, $match);
# edit a note
$date = &getdate;
@@ -825,8 +803,9 @@ sub edit
close NOTE;
select STDOUT;
$editor = &find_editor;
if ($editor) {
system $editor, $TEMP;
system ($editor, $TEMP) and die "Could not execute $editor: $!\n";
}
else {
print "Could not find an editor to use!\n";
@@ -856,8 +835,7 @@ sub edit
}
sub dump
{
sub dump {
my(%res, $num, $DUMP);
# $dump_file
if ($dump_file eq "-") {
@@ -880,8 +858,7 @@ sub dump
select STDOUT;
}
sub import
{
sub import {
my($num, $start, $complete, $dummi, $note, $date, $time, $number, $stdin, $DUMP);
# open $dump_file and import it into the notedb
$stdin = 1 if($dump_file eq "-");
@@ -931,10 +908,39 @@ sub import
}
}
sub determine_width {
# determine terminal wide, if possible
if ($keepmaxlen eq "auto") {
eval {
my $wide = `stty -a`;
if ($wide =~ /columns (\d+?);/) {
$maxlen = $1 - 33; # (33 = timestamp + borders)
}
else {
# stty didn't work
$maxlen = 80 - 33;
}
};
}
}
sub clear {
# first, try to determine the terminal height
my $hoch;
eval {
my $height = `stty -a`;
if ($height =~ /rows (\d+?);/) {
$hoch = $1;
}
};
if (!$hoch) {
# stty didn't work
$hoch = 25;
}
print "\n" x $hoch;
}
sub interactive
{
sub interactive {
my($B, $BB, $menu, $char, $Channel);
$Channel = $|;
# create menu:
@@ -952,6 +958,7 @@ sub interactive
. $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!
&determine_width;
$ListType = ($DEFAULT_LIST eq "LONG") ? "LONG" : "";
&list;
@@ -966,8 +973,10 @@ sub interactive
}
# endless until user press "Q" or "q"!
$char = <STDIN>;
#$char = $term->readline('');
chomp $char;
&determine_width;
&clear;
if ($char =~ /^\d+\s*[\di*?,*?\-*?]*$/) {
$ListType = ""; #overrun
# display notes
@@ -1132,7 +1141,7 @@ Read the note(1) manpage for more details.
}
sub find_editor {
return $PreferredEditor || $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
return $PreferredEditor || $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vi" || "vim" || "pico";
}
#/
@@ -1158,11 +1167,11 @@ sub format {
$note;
}
sub output
{
sub output {
my($SSS, $LINE, $num, $note, $time, $TYPE, $L, $LONGSPC, $R, $PathLen, $SP, $title, $CUTSPACE,
$len, $diff, $Space, $nlen, $txtlen);
($num, $note, $time, $TYPE) = @_;
$len, $diff, $Space, $nlen, $txtlen, $count);
($num, $note, $time, $TYPE, $count) = @_;
$txtlen = ($ListType eq "LONG") ? $maxlen : $timelen + $maxlen;
$note = &format($note);
@@ -1178,8 +1187,8 @@ sub output
$SP = "";
# print only if it is the first line!
$SP = " " x ($maxlen - 2 - $PathLen);
if (!$Raw) {
# no title in raw-mode!
if (!$Raw) {
# no title in raw-mode!
print C $LINE;
print C "$L $NUMC#$_NUMC ";
if ($ListType eq "LONG") {
@@ -1250,16 +1259,15 @@ sub output
$Space = " " x (($maxlen + $timelen) - 16);
print C $LINE;
print C "$L $NUMC$num$_NUMC $R$L$TIMEC$time$_TIMEC $Space$R\n";
print C $LINE;
print "\n";
print C $NOTEC . $note . $_NOTEC . "\n";
print C $LINE;
print C $LINE if ($count == 1);
}
}
sub C
{
sub C {
my($default, $S, $Col, $NC, $T);
$default = "\033[0m";
$S = $_[0];
@@ -1281,11 +1289,10 @@ sub C
sub num_bereich
{
sub num_bereich {
my($m,@LR,@Sorted_LR,$i);
# $number is the one we want to delete!
# But does it contain kommas?
# But does it contain commas?
@NumBlock = (); #reset
$m = 0;
if ($number =~ /\,/) {
@@ -1320,8 +1327,7 @@ sub num_bereich
}
sub getdate
{
sub getdate {
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon += 1;
@@ -1330,12 +1336,22 @@ sub getdate
$min =~ s/^(\d)$/0$1/;
$sec =~ s/^(\d)$/0$1/;
$mday =~ s/^(\d)$/0$1/;
if ($time_format) {
my $back = $time_format;
$back =~ s/YYYY/$year/;
$back =~ s/YY/substr($year, 1, 2)/e;
$back =~ s/MM/$mon/;
$back =~ s/DD/$mday/;
$back =~ s/mm/$min/;
$back =~ s/hh/$hour/;
$back =~ s/ss/$sec/;
return $back;
}
return "$mday.$mon.$year $hour:$min:$sec";
}
sub gettemp
{
sub gettemp {
my($random, @range);
@range=('0'..'9','a'..'z','A'..'Z');
srand(time||$$);
@@ -1352,8 +1368,7 @@ sub gettemp
sub help
{
sub help {
my $B = "<white_black>";
my $BB = "</white_black>";
my($S, $L, $T, $Q, $H, $N, $D, $E);
@@ -1506,7 +1521,7 @@ sub getconfig
$COLOR = "YES" if (/^UseColors/ && $value == 1);
$COLOR = "NO" if (/^UseColors/ && $value == 0);
$TopicSep = $value if (/^TopicSeparator/);
$maxlen = $value if (/^MaxLen/);
$maxlen = $keepmaxlen = $value if (/^MaxLen/);
$BORDER_COLOR = $value if (/^BorderColor/);
$NUM_COLOR = $value if (/^NumberColor/);
$NOTE_COLOR = $value if (/^NoteColor/);
@@ -1516,6 +1531,7 @@ sub getconfig
$FormatText = $value if (/^FormatText/);
$TempDir = $value if (/^TempDirectory/);
$USE_CACHE = $value if (/^Cache/);
$time_format = $value if (/^TimeFormat/);
}
chomp $home;
$home =~ s/\/*$//; # cut eventually / at the end
@@ -1534,6 +1550,9 @@ sub getconfig
__END__
#
# $Log: note,v $
# Revision 1.11 2000/12/09 21:56:08 zarahg
# cvs update to 1.1.2, but incomplete, more to come
#
# Revision 1.10 2000/08/19 13:38:33 zarahg
# .
#

55
bin/stresstest.sh Executable file
View File

@@ -0,0 +1,55 @@
#!/bin/sh
# create notes with topics which then represents the corresponding
# directory structure. Depending on how many files the directory
# contains, the resulting note-database may become very large.
# It will then have thousands of notes!
STARTDIR=$1
case $STARTDIR in
"")
echo "usage: stresstest.sh <directory>"
exit 1
;;
*)
LOCPFAD=`echo $STARTDIR | grep "^[a-zA-Z0-9.]"`
case $LOCPFAD in
"")
#echo nix
;;
*)
STARTDIR=`echo $STARTDIR | sed 's/^\.*//'`
STARTDIR="`pwd`/$STARTDIR"
STARTDIR=`echo $STARTDIR | sed 's/\/\//\//g'`
;;
esac
;;
esac
stress ()
{
FILES=""
for file in `ls $1|sort`
do
echo "$1/$file"
if [ -d "$1/$file" ] ; then
stress "$1/$file"
else
#echo "$1/" > /tmp/$$
#echo $file >> /tmp/$$
#`cat /tmp/$$ | note -`
FILES="$FILES $file"
fi
done
echo "$1/" > /tmp/$$
echo "$FILES" >> /tmp/$$
case $FILES in
"")
;;
*)
RES=`cat /tmp/$$ | note -`
;;
esac
FILES=""
}
stress $STARTDIR