From 9a2d07e0e02947892db367ad0f2778ad7151c262 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Fri, 10 Feb 2012 20:15:05 +0100 Subject: [PATCH] FIXED: the T (and t respectively) printed nothing out since 1.0.3! It does it now again... ADDED: a new database backend added, NOTEDB::dbm, which uses DBM files for storage. FIXED: &display-tree returns now, if there is no note, otherwise it would die because of an undefined refernce. CHANGED: Changed the config file format completely. It is now no more a perl file, instead it is a simple plain text file which note parses. CHANGED: Changed the way, note loads it database backend. It uses now the $dbdriver variable as module-name, which makes it possible easily to write your own backend without the need to change note itself. FIXED: Removed Getopt::Long option "bundling", causes errors with perl 5.6.0 and is not senceful. FIXED: Added the Getopt::Long option "no_ignore_case". In 1.0.4 options were case insensitive causing -i to be interpreted as --import instead of --interactive ;-((( ADDED: a new config option $DEFAULT_LIST, which causes note, \ if turned to "LONG", to use long-listing as default. | But it will still be able to use short-listing if you | explicit specify that. | submitted by FIXED: sub search prints now an appropriate error-message in |==> Peter Palmreuther case no searchstring was given instead of jumping to | thanks a lot! usage. | CHANGED: Changed the text in the interactive help to reflect | changes of verion 1.0.3 (t and T). / --- Changelog | 29 +++ Makefile.PL | 15 +- NOTEDB/dbm.pm | 261 +++++++++++++++++++++++++ README | 114 ++++++++--- UPGRADE | 23 +++ VERSION | 2 +- bin/note | 516 ++++++++++++++++++++++++++++++-------------------- config/noterc | 179 +++++++++-------- 8 files changed, 830 insertions(+), 309 deletions(-) create mode 100644 NOTEDB/dbm.pm diff --git a/Changelog b/Changelog index 6092986..ef05d53 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,34 @@ ================================================================================== +1.0.5: +FIXED: the T (and t respectively) printed nothing out since 1.0.3! It does + it now again... +ADDED: a new database backend added, NOTEDB::dbm, which uses DBM files for + storage. +FIXED: &display-tree returns now, if there is no note, otherwise it + would die because of an undefined refernce. +CHANGED: Changed the config file format completely. It is now no more a perl + file, instead it is a simple plain text file which note parses. +CHANGED: Changed the way, note loads it database backend. It uses now the + $dbdriver variable as module-name, which makes it possible easily + to write your own backend without the need to change note itself. +FIXED: Removed Getopt::Long option "bundling", causes errors with perl + 5.6.0 and is not senceful. +FIXED: Added the Getopt::Long option "no_ignore_case". In 1.0.4 options + were case insensitive causing -i to be interpreted as --import + instead of --interactive ;-((( +ADDED: a new config option $DEFAULT_LIST, which causes note, \ + if turned to "LONG", to use long-listing as default. | + But it will still be able to use short-listing if you | + explicit specify that. | submitted by +FIXED: sub search prints now an appropriate error-message in |==> Peter Palmreuther + case no searchstring was given instead of jumping to | thanks a lot! + usage. | +CHANGED: Changed the text in the interactive help to reflect | + changes of verion 1.0.3 (t and T). / + +================================================================================== + 1.0.4: CHANGED: Moved from @ARGV-parsing to Getopt::Long, adding options is now much easier and I do now understand my own code ;-) diff --git a/Makefile.PL b/Makefile.PL index 1af2635..cc0d712 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -23,6 +23,19 @@ sub chk_mod print "\n"; } +&chk_mod( + "Getopt::Long", + "WARNING: Getopt::Long seems not to be installed on your system!\n" + ."But it is strongly required in order to run note!\n" + ); + +&chk_mod( + "DB_File", + "WARNING: DB_File seems not to be installed on your system!\n" + ."It is required, if you want to use the DBM backend.\n" + ); + + &chk_mod( "DBI", " WARNING: module DBI is not installed on your system.\n" @@ -73,7 +86,7 @@ $install = `which install`; open M, "> Makefile" || die $!; print M qq~BIN = bin/note -LIBS = NOTEDB/mysql.pm NOTEDB/binary.pm +LIBS = NOTEDB/mysql.pm NOTEDB/binary.pm NOTEDB/dbm.pm INSTBIN = $BINDIR INSTLIB = $LIBDIR INSTALL = $install diff --git a/NOTEDB/dbm.pm b/NOTEDB/dbm.pm new file mode 100644 index 0000000..6dbab20 --- /dev/null +++ b/NOTEDB/dbm.pm @@ -0,0 +1,261 @@ +#!/usr/bin/perl +# $Id: dbm.pm,v 1.1 2000/05/14 00:55:28 thomas Exp thomas $ +# Perl module for note +# DBM database backend. see docu: perldoc NOTEDB::dbm +# + +use DB_File; +#use Data::Dumper; +use strict; +package NOTEDB; + +BEGIN { + # make sure, it works, although encryption + # not supported on this system! + eval { require Crypt::CBC; }; + if($@) { + $NOTEDB::crypt_supported = 0; + } + else { + $NOTEDB::crypt_supported = 1; + } +} + +# Globals: +my ($dbm_dir, $notefile, $timefile, $version, $cipher, %note, %date); +$notefile = "note.dbm"; +$timefile = "date.dbm"; + +$version = "(NOTEDB::dbm, 1.1)"; + +sub new +{ + my($this, $dbdriver, $dbm_dir) = @_; + my $class = ref($this) || $this; + my $self = {}; + bless($self,$class); + + tie %note, "DB_File", "$dbm_dir/$notefile" || die $!; + tie %date, "DB_File", "$dbm_dir/$timefile" || die $!; + + return $self; +} + + +sub DESTROY +{ + # clean the desk! + untie %note, %date; +} + +sub version { + return $version; +} + +sub no_crypt { + $NOTEDB::crypt_supported = 0; +} + +sub use_crypt { + my($this, $key, $method) = @_; + if($NOTEDB::crypt_supported == 1) { + eval { + $cipher = new Crypt::CBC($key, $method); + }; + if($@) { + $NOTEDB::crypt_supported == 0; + } + } + else{ + print "warning: Crypt::CBC not supported by system!\n"; + } +} + + +sub get_single +{ + my($this, $num) = @_; + my($note, $date); + return ude ($note{$num}), ude($date{$num}); +} + + +sub get_all +{ + my($this, $num, $note, $date, %res, $real); + foreach $num (sort {$a <=> $b} keys %date) { + $res{$num}->{'note'} = ude($note{$num}); + $res{$num}->{'date'} = ude($date{$num}); + } + return %res; +} + + +sub get_nextnum +{ + my($this, $num); + foreach (sort {$a <=> $b} keys %date) { + $num = $_; + } + $num++; + return $num; +} + +sub get_search +{ + my($this, $searchstring) = @_; + my($num, $note, $date, %res); + + foreach $num (sort {$a <=> $b} keys %date) { + if (ude($note{$num}) =~ /$searchstring/i) { + $res{$num}->{'note'} = ude($note{$num}); + $res{$num}->{'date'} = ude($date{$num}); + } + } + + return %res; +} + + + +sub set_recountnums +{ + my $this = shift; + my(%Note, %Date, $num, $setnum); + $setnum = 1; + foreach $num (sort {$a <=> $b} keys %note) { + $Note{$setnum} = $note{$num}; + $Date{$setnum} = $date{$num}; + $setnum++; + } + %note = %Note; + %date = %Date; +} + + + +sub set_edit +{ + my($this, $num, $note, $date) = @_; + $note{$num} = uen($note); + $date{$num} = uen($date); +} + + +sub set_new +{ + my($this, $num, $note, $date) = @_; + $this->set_edit($num, $note, $date); # just the same thing +} + + +sub set_del +{ + my($this, $num) = @_; + my($note, $date, $T); + ($note, $date) = $this->get_single($num); + return "ERROR" if ($date !~ /^\d/); + delete $note{$num}; + delete $date{$num}; +} + +sub set_del_all +{ + my($this) = @_; + %note = (); + %date = (); + return; +} + +sub uen +{ + my($T); + if($NOTEDB::crypt_supported == 1) { + eval { + $T = pack("u", $cipher->encrypt($_[0])); + }; + } + else { + $T = $_[0]; + } + chomp $T; + return $T; +} + +sub ude +{ + my($T); + if($NOTEDB::crypt_supported == 1) { + eval { + $T = $cipher->decrypt(unpack("u",$_[0])) + }; + return $T; + } + else { + return $_[0]; + } +} + +1; # keep this! + +__END__ + +=head1 NAME + +NOTEDB::dbm - module lib for accessing a notedb from perl + +=head1 SYNOPSIS + + # include the module + use NOTEDB; + + # create a new NOTEDB object (the last 4 params are db table/field names) + $db = new NOTEDB("mysql","note","/home/user/.notedb/"); + + # get a single note + ($note, $date) = $db->get_single(1); + + # search for a certain note + %matching_notes = $db->get_search("somewhat"); + # format of returned hash: + #$matching_notes{$numberofnote}->{'note' => 'something', 'date' => '23.12.2000 10:33:02'} + + # get all existing notes + %all_notes = $db->get_all(); + # format of returnes hash like the one from get_search above + + # get the next noteid available + $next_num = $db->get_nextnum(); + + # recount all noteids starting by 1 (usefull after deleting one!) + $db->set_recountnums(); + + # modify a certain note + $db->set_edit(1, "any text", "23.12.2000 10:33:02"); + + # create a new note + $db->set_new(5, "any new text", "23.12.2000 10:33:02"); + + # delete a certain note + $db->set_del(5); + +=head1 DESCRIPTION + +You can use this module for accessing a note database. This is the dbm module. +It uses the DB_FILE module to store it's data and it uses DBM files for tis purpose. + +Currently, NOTEDB module is only used by note itself. But feel free to use it +within your own project! Perhaps someone want to implement a webinterface to +note... + +=head1 USAGE + +please see the section SYNOPSIS, it says it all. + +=head1 AUTHOR + +Thomas Linden . + + + +=cut diff --git a/README b/README index 6561c3e..1d04c90 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ -note 1.0.4 by Thomas Linden, 12/05/2000 - +note 1.0.5 by Thomas Linden, 14/05/2000 +======================================= Introduction ============ @@ -8,17 +8,7 @@ Introduction perl, which allows you to manage notes similar to programs like "knotes" from commandline. - This version is completely rewritten and it is - able to display colored output. - - You can add, edit, list and delete as many notes - as you want. You can run note from the commandline - or interactive from within your console. You can - sort your notes in different topics, which is usefull - if you have a lot of them. Additional it is possible - to encrypt your notes for protection. - - There are currently two different database backends, + There are currently three different database backends, which you can use with note: o NOTEDB::binary - this is the default backend and uses a binary file to store your notes. @@ -27,6 +17,66 @@ Introduction easily to another DBMS since this module uses the Perl standard module "DBI" for database- access. See below for more info on this topic! + o NOTEDB::dbm - this module uses two DBM files + for data storage and requires the module DB_FILE, + which is part of the perl standard distribution. + See below for more details about the DBM module. + + + +Where to get? +============= + + By now at + http://www.daemon.de/software.html + or + ftp://www.0c49.org/pub/scip/note/ + + You may also try your nearest tucows mirror. + + + + +Features +======== + + o Three different database backends, mysql(DBI), dbm, binary(bin file). + o Commandline interface using the standard perl module + Getopt::Long, which allows you to use short or long + command-line options. + o Interactive interface(pure ascii), the following functions + are available in interactive mode: list, display, topic, + delete, edit, help. + o Highly confiurable using a perlish configfile ~/.noterc. + although it is configurable it is not required, note can + run without a configfile using useful default presets. + o Colourized output is supported using ASCII Escape-Sequences. + o The user can customize the color for each item. + o Data can be stored in various different database backends, + since all database access is excluded from the program itself + in perl modules. + o Notes can be deleted, edited and you can search trough your notes. + o Notes can be categorized. Each category(topic) can contain multiple + notes and even more sup-topics. There is no limitation about + sub topics. + o You can view all notes in a list and it is possible only to view + notes under a certain topic. + o There is a tree-view, which allows you to get an overview of your + topic-hierarchy. + o Notes can be encrypted using DES or IDEA algorythms and Crypt::CBC. + o You can dump the contents of your note database into a plain text + file, which can later be imported. Imports can be appended or it can + overwrite an existing database (-o). + o Note has scripting capabilities, you can create a new note by piping + another commands output to note, you can also import a notedump from + stdin as well es duming to stdout instead a file. Additional, there + is an option --raw available, which prints everything out completely + without formatting. + o It can be installed without root-privileges. + o Last, a while ago a user stated: "... it simply does, what it says ..." + + + Requirements @@ -39,7 +89,8 @@ Requirements you want to use the binary database backend. o DBI module and DBI::mysql if you want to use the mysql database backend. - o Getopt::Long + o The module DB_FILE if you want to use the DBM module. + o Getopt::Long (part of perl std ditribution) @@ -59,11 +110,17 @@ Installation see mysql/README. If want to use another SQL database, i.e. postgresql then set - the option "$DRIVER" to the name of the responding DBI-driver + the option "DbDriver" to the name of the responding DBI-driver and create a symlink of this name like this: /usr/lib/perl5/siteperl/NOTEDB $ ln -s mysql.pm oracle.pm The functionality is the same, but not the name! + The default binary file backend does not need any special installation + procedure, you need only to spceify a filename in your config file. + + The DBM backend(NOTEDB::dbm) requires the existence of a directory, + which you must specify in your config using the option "DbName". + Configuration @@ -154,8 +211,8 @@ Usage What the hell, does it?! Step by step: o "note -D -" creates a note-database dump and prints it out to stantdard output. - o "|" this is the shell's pipe command. It does take the output - of the left program and gives it to the right progrem as standard + o "|" this is the shell's pipe command. It takes the output + of the left program and gives it to the right program as standard input. o "note -o -I -" imports a note-database dump from standard input and overwrites an existing database. @@ -172,7 +229,7 @@ Topics 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 slashes - (or whatever you prefer, set $TopicSep in your config! default is slash), + (or whatever you prefer, set "TopicSeparator" in your config! default is slash), then note will consider it as the topic of this certain note. For examle: /TodoList/ If you are using topics, no data after the topic is allowed, if there @@ -187,7 +244,7 @@ Topics will prepend the string "/topicname/" to the text of your note). 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) + note and type the name of the new topic bordered by slashes (or TopicSeparator) at the first line of this note. After saving, there will be available a new topic with one note in it. @@ -258,7 +315,7 @@ Scripting If the variable is present, note will not ask you for a passphrase! Another thingy you might find useful is the -r (--raw) command-line flag. This - turns note into raw mode being silent, which means it will only print the + turns note into raw mode , which means it will only print the data without any formatting. Raw mode is available for list and display, since it makes no sense, interactive mode doe not support raw mode. @@ -336,7 +393,7 @@ Security the permission 0600 of the file "~/.notedb" is strongly required! Additional, you can turn on encryption from the config file. - Simply set $USE_CRYPT to "YES". Please note, that you need + Simply set UseEncryption to 1. Please note, that you need to decide, if you want to use encryption before the first use of note! If have already a note database and want to "migrate" to encryption, I suggest you to follow the directions in the @@ -411,7 +468,20 @@ Author and Copyright +Contributors / Credits +====================== + + Shouts to those guys who helped me to enhance note: THANKS A LOT! + + Jens Heunemann - sub tree. + Peter Palmreuther - various additions. + + And many other people who sended bug reports, feature requests. If you feel that + I forgot your name in this list, then please send me an email and I'll add you. + + + Last changed ============ - 12/05/2000 + 14/05/2000 diff --git a/UPGRADE b/UPGRADE index 3139389..32611ee 100644 --- a/UPGRADE +++ b/UPGRADE @@ -1,3 +1,26 @@ +1.0.5 important note upgrade information +======================================== + +If you are upgrading from previous versions of note, you +will need to create a new config file, since the format of +that file has completely changed! + +Take a look at the sample in config/noterc for details. + +note will NOT work with an existing database and an old config. +You have to create a new config based on your old settings. + + +Please don't forget to make a backup of your database before +upgrading! I am not responsible for data loss! + +I told ya... + + + + + +Thomas Linden READ THIS FILE, IF YOU ARE UPGRADING FROM 0.9 TO 1.0.x ====================================================== diff --git a/VERSION b/VERSION index ee90284..90a27f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.4 +1.0.5 diff --git a/bin/note b/bin/note index 920ab26..9d0e5c9 100755 --- a/bin/note +++ b/bin/note @@ -1,191 +1,164 @@ #!/usr/bin/perl -# $Author: thomas $ $Id: note,v 1.24 2000/05/10 22:59:44 thomas Exp thomas $ $Revision: 1.24 $ +# $Id: note,v 1.26 2000/05/13 01:05:17 thomas Exp thomas $ # -# $Log: note,v $ -# Revision 1.24 2000/05/10 22:59:44 thomas -# updated usage to reflect --raw and build it into output -# and display subs. # -# Revision 1.23 2000/05/10 22:19:04 thomas -# changed to Getopt::Long, added --raw +# note - console notes management with database and encryption support. +# Copyright (C) 1999-2000 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 +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# Revision 1.22 2000/05/01 18:51:40 thomas -# added "-" to sub dump +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -# Revision 1.21 2000/05/01 00:17:27 thomas -# *** empty log message *** +# - Thomas Linden # -# Revision 1.20 2000/04/30 23:31:38 thomas -# added -o and coloured sub help. +# latest version on: +# http://www.daemon.de/software.html +# ftp://www.0x49.org/pub/scip/note/ # -# Revision 1.19 2000/04/30 16:07:23 thomas -# *** empty log message *** -# -# Revision 1.18 2000/04/30 14:58:21 thomas -# updated the usage and help subs -# -# Revision 1.17 2000/04/30 14:44:38 thomas -# added colors to the tree functions -# -# Revision 1.16 2000/04/30 14:28:38 thomas -# added the t command, which displays a topic-tree. -# and enhanced the list command in interactive mode -# -# Revision 1.15 2000/03/19 23:41:04 thomas -# changed set_del, now no extra TEMP file is required! -# instead I get it from $this->get_all() ! -# -# Revision 1.14 2000/03/19 22:51:49 thomas -# Bug in NOTEDB::binary fixed, recount of nubers was -# incorrect. -# -# Revision 1.13 2000/03/19 11:53:32 thomas -# edit bug fixed (ude => uen) -# -# Revision 1.12 2000/03/19 03:06:51 thomas -# backend support completed. -# mysql and binary backends now excluded in separate files -# -# Revision 1.11 2000/03/18 00:16:47 thomas -# added NOTEDB::mysql and changed note to work with that. -# thus, from now on there is only one script to maintain and -# it is possible to provide more bacjends as well as making -# additional scripts upon them, i.e. cgi script... -# -# Revision 1.8 2000/03/13 22:48:43 thomas -# small width bug fixed -# -# Revision 1.7 2000/03/08 23:11:19 tom -# added cd -# -# Revision 1.6 2000/03/08 22:50:41 tom -# Added the $KEEP_TIMESTAMP option and fixed a bug regarding topic names -# and invalid resolution of them in case it started with "1 name". -# -# 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" -# It works similar to some well known GUI note programs, -# but instead of using X11 it uses the UN*X console. -# You can edit existing notes, delete them, create new -# ones and, of course display them. -# The notes will be stored in a mysql database. Refer to -# the README of the desitribution for details about -# installation. -# It requires a configfile named .noterc in the users home. -# If it does not exist, note will create one for you, which -# you will have to edit. -# -# If you find it usefull or find a bug, please let me know: -# Thomas Linden -# -# note is GPL software. use strict; #use Data::Dumper; use Getopt::Long; -sub usage; -sub find_editor; -sub output; -sub C; -sub uen; -sub ude; -sub num_bereich; -sub getdate; +# +# 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 . THX! -sub new; -sub edit; -sub del; -sub display; -sub list; -sub help; -sub import; -sub display_tree; -sub tree; -sub print_tree; +# +# globals +# my ( - $maxlen, $timelen, $TOPIC, $TYPE, $mode, $NOTEDB, $NoteKey, $ImportType, $NewType, - $version, $number, $CurTopic, $CurDepth, $PATH, $CONF, $WantTopic, - $sizeof, $MAX_TIME, $PreferredEditor, %TP, $TopicSep, - $TreeType, $ListType, $searchstring, $dump_file, $ALWAYS_INT, $KEEP_TIMESTAMP, - $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, $has_nothing, - $db, $dbname, $dbhost, $DEFAULTDBNAME, $dbuser, $USER, $dbpasswd, - $table, $fnum, $fnote, $fdate, $date, $dbdriver, $libpath, $db, @ArgTopics, $Raw, - $USE_CRYPT, $CRYPT_METHOD, $key, - $opt_, $opt_i, $opt_r, $opt_e, $opt_d, $opt_s, - $opt_t, $opt_T, $opt_l, $opt_L, $opt_D, $opt_I, - $opt_o, $opt_h, $opt_n, $opt_v + # + # commandline options + # + $opt_, $opt_i, $opt_r, $opt_e, $opt_d, + $opt_s, $opt_t, $opt_T, $opt_l, $opt_L, + $opt_D, $opt_I, $opt_o, $opt_h, $opt_n, $opt_v, + + # + # set from commandline (or interactive) + # + $number, $searchstring, $dump_file, $ImportType, $NewType, $Raw, + + # + # options from config file .noterc + # + $maxlen, $timelen, $TOPIC, $NOTEDB, $MAX_TIME, $PreferredEditor, + $ALWAYS_INT, $KEEP_TIMESTAMP, $COLOR, $ALWAYS_EDIT, $HOME, + $BORDER_COLOR, $NOTE_COLOR, $NUM_COLOR, $TOPIC_COLOR, $MAX_NOTE, + $USE_CRYPT, $CRYPT_METHOD, $TopicSep, $DEFAULT_LIST, $TIME_COLOR, + + # + # db specifics from .noterc + # + $db, $dbname, $dbhost, $dbuser, $dbpasswd, + $table, $fnum, $fnote, $fdate, $date, $dbdriver, $libpath, + + # + # processed colors + # + $BORDERC, $_BORDERC, $NOTEC, $NUMC, $_NUMC, $_NOTEC, $TIMEC, + $_TIMEC, $TOPICC, $_TOPICC, + + # + # config presets + # + $DEFAULTDBNAME, $USER, $PATH, $CONF, + + # + # internals + # + $TYPE, $mode, $NoteKey, + $version, $number, $CurTopic, $CurDepth, $WantTopic, + $sizeof, %TP, $TreeType, $ListType, $SetTitle, + @ArgTopics, $key, $typedef, @NumBlock, $has_nothing, ); -#################################################################### -# DEFAULTS, allows one to use note without a config ################ -# don't change them, instead use the config file! ################ -#################################################################### -$maxlen = 30; -$timelen = 22; -$date = &getdate; -$USER = getlogin || getpwuid($<); + +# +# DEFAULTS, allows one to use note without a config +# don't change them, instead use the config file! +# +$maxlen = 30; +$timelen = 22; +$date = &getdate; +$USER = getlogin || getpwuid($<); chomp $USER; -$HOME = $ENV{'HOME'}; -$CONF = $HOME . "/.noterc"; -$dbdriver = "binary"; -$libpath = "/usr/local/lib"; -$NOTEDB = $HOME . "/.notedb"; -$MAX_NOTE = 4096; -$MAX_TIME = 64; -$COLOR = "YES"; -$BORDER_COLOR = "BLACK"; -$NUM_COLOR = "blue"; -$NOTE_COLOR = "green"; -$TIME_COLOR = "black"; -$TOPIC_COLOR = "BLACK"; -$TOPIC = 1; -$TopicSep = '/'; -$version = "1.0.4"; +$HOME = $ENV{'HOME'}; +$CONF = $HOME . "/.noterc"; +$dbdriver = "binary"; +$libpath = "/usr/local/lib"; +$NOTEDB = $HOME . "/.notedb"; +$MAX_NOTE = 4096; +$MAX_TIME = 64; +$COLOR = "YES"; +$BORDER_COLOR = "BLACK"; +$NUM_COLOR = "blue"; +$NOTE_COLOR = "green"; +$TIME_COLOR = "black"; +$TOPIC_COLOR = "BLACK"; +$TOPIC = 1; +$TopicSep = '/'; +$version = "1.0.5"; if($TOPIC) { - $CurDepth = 1; # the current depth inside the topic "directory" structure... + $CurDepth = 1; # the current depth inside the topic "directory" structure... } -$USE_CRYPT = "NO"; -#################################################################### +$USE_CRYPT = "NO"; + + + +# # process command line args +# if($ARGV[0] eq "") { $mode = "new"; } elsif($#ARGV == 0 && $ARGV[0] eq "-") { $mode = "new"; - $NewType = 1; + $NewType = 1; # read from STDIN until EOF shift; undef $has_nothing; } else { - Getopt::Long::Configure( qw(bundling)); # allow -lr + Getopt::Long::Configure( qw(no_ignore_case)); GetOptions ( "interactive|i!" => \$opt_i, # no arg "raw|r!" => \$opt_r, # no arg "edit|e=i" => \$opt_e, # integer, required "delete|d=s" => \$opt_d, # integer, required "search|s=s" => \$opt_s, # string, required - "tree|t!" => \$opt_t, # no arg + "tree|topic|t!" => \$opt_t, # no arg "long_tree|T!" => \$opt_T, # no arg "list|l:s" => \$opt_l, # string, optional "long_list|L:s" => \$opt_L, # string, optional @@ -198,7 +171,9 @@ else $opt_n = shift; # after that @ARGV contains eventually # a note-number # $opt_ is a single dash, in case of existence! + # # determine mode + # if($opt_i) { $mode = "interactive"; } @@ -305,10 +280,10 @@ if($has_nothing && $mode eq "") } -# open the configfile. +# read the configfile. if(-e $CONF) { - eval `cat $CONF`; + &getconfig($CONF); } @@ -318,29 +293,40 @@ if($ALWAYS_INT eq "YES" && $mode ne "dump" && $mode ne "import") $mode = "interactive"; } +# OK ... Long-Listing shall be default ... You wanted it!!! +if($DEFAULT_LIST eq "LONG") +{ + # takes only precedence in commandline mode + $ListType="LONG"; +} + + # *if* loading of the config was successful, try to load the # configured database backend. Currently supported: mysql and binary. push @INC, $libpath; -if($dbdriver eq "mysql") { - eval { - require NOTEDB::mysql; - $db = new NOTEDB($dbdriver, $dbname, $dbhost, $dbuser, $dbpasswd, $table, $fnum, $fnote, $fdate); - } -} -elsif($dbdriver eq "binary") { +#if($dbdriver eq "mysql") { +# eval { +# require NOTEDB::mysql; +# $db = new NOTEDB($dbdriver, $dbname, $dbhost, $dbuser, $dbpasswd, $table, $fnum, $fnote, $fdate); +# } +#} +if($dbdriver eq "binary") { eval { require NOTEDB::binary; $db = new NOTEDB($dbdriver, $NOTEDB, $MAX_NOTE, $MAX_TIME, $dbdriver); } } else { - print "Unsupported database backend: NOTEDB::$dbdriver!\n"; - exit 1; + eval { + require "NOTEDB/$dbdriver.pm"; + $db = new NOTEDB($dbdriver, $dbname, $dbhost, $dbuser, $dbpasswd, $table, $fnum, $fnote, $fdate); + }; } if($@) { - print "backend-error: " . $@; - exit 1; + print "Unsupported database backend: NOTEDB::$dbdriver!\n"; + print "The following error has occured:\n------------------------\n" . $@ . "\n------------------------\n"; + exit 1; } # add the backend version to the note version: @@ -490,28 +476,28 @@ sub display ############################### SEARCH ################################## sub search { - my($n,$match,$note,$date,$num,%res); + my($n,$match,$note,$date,$num,%res); $maxlen += $timelen; if($searchstring eq "") { - &usage; + print "No searchstring specified!\n"; } - print "searching the database $dbname for \"$searchstring\"...\n\n"; + else { + print "searching the database $dbname for \"$searchstring\"...\n\n"; - %res = $db->get_search($searchstring); + %res = $db->get_search($searchstring); - foreach $num (sort { $a <=> $b } keys %res) - { - output($num, $res{$num}->{'note'}, $res{$num}->{'date'}); - $match = 1; - } - - - if(!$match) - { - print "no matching note found!\n"; - } - print "\n"; + foreach $num (sort { $a <=> $b } keys %res) + { + output($num, $res{$num}->{'note'}, $res{$num}->{'date'}); + $match = 1; + } + if(!$match) + { + print "no matching note found!\n"; + } + print "\n"; + } } @@ -872,7 +858,8 @@ sub import sub interactive { - my($maxlen_save, $B, $BB, $menu, $char, @LastTopic); + my($maxlen_save, $B, $BB, $menu, $char, @LastTopic, $Channel); + $Channel = $|; $maxlen_save = $maxlen; # create menu: $B = ""; @@ -889,7 +876,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! - $maxlen += $timelen; + $maxlen += $timelen if($DEFAULT_LIST ne "LONG"); print "\n"; &list; undef $SetTitle; @@ -927,8 +914,13 @@ sub interactive { # list print "\n"; - $ListType = ""; - $maxlen += $timelen; + if($DEFAULT_LIST eq "LONG" && $char =~ /^$/) { + $ListType = "LONG"; + } + else { + $ListType = ""; + $maxlen += $timelen; + } &list; undef $SetTitle; } @@ -994,11 +986,13 @@ sub interactive elsif($char =~ /^q$/i) { # schade!!! - print "\n\ngood bye\n"; + $| = $Channel; + print "\n\ngood bye!\n"; exit(0); } elsif($char =~ /^t$/) { + $TreeType = ""; &display_tree; } elsif($char =~ /^T$/) @@ -1092,7 +1086,7 @@ Options: which causes note, silently to read in a dump from STDIN. -o --overwrite only suitable for use with --Import. Overwrites an existing notedb. --r --raw raw mode, out will not be formatted. Works not in interactive +-r --raw raw mode, output will not be formatted. Works not in interactive mode, only on cmd-line for list and display. -i --interactive interactive mode - if you run note only with one dash: "note -", then it will @@ -1103,8 +1097,8 @@ Options: number will be displayed. o you can specify more then one number for delete and display, for example: "note -d 3,4" deletes #3 and #4. "note 5-7" displays #5, #6 and #7. - o if you run note without any parameter and if \$ALWAYS_INT in the config is - not set, then note will create a new note and prompt you for new text. + o if you run note without any parameter and if "AlwaysInteractive" in the config + set off, then note will create a new note and prompt you for new text. o If it finds \~/.noterc, it will process it. Refer to the manpage for more informations about the configuration. o In interactive mode you can get help at any time by typing "?" or "h" at @@ -1308,20 +1302,6 @@ sub C } -sub uen -{ - my($T); - $T = pack("u", $_[0]); - chomp $T; - return $T; -} - -sub ude -{ - my($T); - $T = unpack("u", $_[0]); - return $T; -} sub num_bereich { @@ -1431,7 +1411,7 @@ $T print a list of all existing topics as a tree. T prints the tree } print C qq~ $NOTEC -All commands except the List command are case insensitive. $_NOTEC $BORDERC +All commands except the List and Topic commands are case insensitive. $_NOTEC $BORDERC ----------------------------------------------------------------------$_BORDERC ~; } @@ -1459,10 +1439,10 @@ sub display_tree { } &tree($num, $text, \%TREE, @nodes); } - + #return if ($num == 0); # now that we have build our tree (in %TREE) go on t display it: print C $BORDERC . "\n[" . $TopicSep . $BORDERC . "]\n"; - &print_tree(\%{$TREE{''}},""); + &print_tree(\%{$TREE{''}},"") if(%TREE); print C $BORDERC . $_BORDERC . "\n"; } @@ -1506,3 +1486,135 @@ sub print_tree { } } + +sub getconfig +{ + my($configfile) = @_; + my ($home, $value, $option); + # checks are already done, so trust myself and just open it! + open CONFIG, "<$configfile" || die $!; + while() { + chomp; + next if(/^\s*$/ || /^\s*#/); + my ($option,$value) = split /\s\s*/, $_, 2; + $value =~ s/\s*$//; + $home = $value if (/^Home/); + $libpath = $value if (/^LibPath/); + $dbdriver = $value if (/^DbDriver/); + $dbhost = $value if (/^DbHost/); + $dbuser = $value if (/^DbUser/); + $dbpasswd = $value if (/^DbPasswd/); + $dbname = $value if (/^DbName/); + $table = $value if (/^DbTable/); + $fnum = $value if (/^FieldNumber/); + $fnote = $value if (/^FieldNote/); + $fdate = $value if (/^FieldDate/); + $NOTEDB = $value if (/^NoteDb/); + $MAX_NOTE = $value if (/^MaxNoteByte/); + $MAX_TIME = $value if (/^MaxTimeByte/); + $USE_CRYPT = "YES" if (/^UseEncryption/ && $value == 1); + $CRYPT_METHOD = $value if (/^CryptMethod/); + $ALWAYS_INT = "YES" if (/^AlwaysInteractive/ && $value == 1); + $DEFAULT_LIST = "LONG" if (/^DefaultLong/ && $value == 1); + $ALWAYS_EDIT = "YES" if (/^AlwaysEditor/ && $value == 1); + $KEEP_TIMESTAMP = "YES" if (/^KeepTimeStamp/ && $value == 1); + $TopicSep = $value if (/^TopicSeparator/); + $maxlen = $value if (/^MaxLen/); + $COLOR = "YES" if (/^UseColors/ && $value == 1); + $BORDER_COLOR = $value if (/^BorderColor/); + $NUM_COLOR = $value if (/^NumberColor/); + $NOTE_COLOR = $value if(/^NoteColor/); + $TIME_COLOR = $value if (/^TimeColor/); + $TOPIC_COLOR = $value if (/^TopicColor/); + } + chomp $home; + $home =~ s/\/*$//; + $HOME = eval($home); + if($NOTEDB =~ /^(~\/)(.*)$/) { + $NOTEDB = "/home/" . $USER . "/" . $2; + } + $libpath =~ s/\/*$//; + + close CONFIG; +} + + + + +__END__ +# +# $Log: note,v $ +# Revision 1.26 2000/05/13 01:05:17 thomas +# changed config format and fixed some bugs +# as well as some other additions... +# +# Revision 1.25 2000/05/11 23:42:43 thomas +# --tree changed to --topic +# +# Revision 1.24 2000/05/10 22:59:44 thomas +# updated usage to reflect --raw and build it into output +# and display subs. +# +# Revision 1.23 2000/05/10 22:19:04 thomas +# changed to Getopt::Long, added --raw +# +# Revision 1.22 2000/05/01 18:51:40 thomas +# added "-" to sub dump +# +# Revision 1.21 2000/05/01 00:17:27 thomas +# *** empty log message *** +# +# Revision 1.20 2000/04/30 23:31:38 thomas +# added -o and coloured sub help. +# +# Revision 1.19 2000/04/30 16:07:23 thomas +# *** empty log message *** +# +# Revision 1.18 2000/04/30 14:58:21 thomas +# updated the usage and help subs +# +# Revision 1.17 2000/04/30 14:44:38 thomas +# added colors to the tree functions +# +# Revision 1.16 2000/04/30 14:28:38 thomas +# added the t command, which displays a topic-tree. +# and enhanced the list command in interactive mode +# +# Revision 1.15 2000/03/19 23:41:04 thomas +# changed set_del, now no extra TEMP file is required! +# instead I get it from $this->get_all() ! +# Revision 1.14 2000/03/19 22:51:49 thomas +# Bug in NOTEDB::binary fixed, recount of nubers was +# incorrect. +# +# Revision 1.13 2000/03/19 11:53:32 thomas +# edit bug fixed (ude => uen) +# +# Revision 1.12 2000/03/19 03:06:51 thomas +# backend support completed. +# mysql and binary backends now excluded in separate files +# +# Revision 1.11 2000/03/18 00:16:47 thomas +# added NOTEDB::mysql and changed note to work with that. +# thus, from now on there is only one script to maintain and +# it is possible to provide more bacjends as well as making +# additional scripts upon them, i.e. cgi script... +# +# Revision 1.8 2000/03/13 22:48:43 thomas +# small width bug fixed +# +# Revision 1.7 2000/03/08 23:11:19 tom +# added cd +# +# Revision 1.6 2000/03/08 22:50:41 tom +# Added the $KEEP_TIMESTAMP option and fixed a bug regarding topic names +# and invalid resolution of them in case it started with "1 name". +# +# 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 diff --git a/config/noterc b/config/noterc index 64271d1..2c531dd 100644 --- a/config/noterc +++ b/config/noterc @@ -1,130 +1,143 @@ -# 1.0.0 +# 1.0.5 -*- sh -*- # This is a sample config for the note script -# There are usefully defaults set in note itself. +# There are useful defaults set in note itself. # -# The default database backend is NOTEDB::binary. -# # Copy it to your $HOME as .noterc -# -# This config has to be valid perl code. Therefore -# please be careful! # +# note is Copyright (c) 1999-2000 Thomas Linden. # You can contact me per email: -# -# Thomas Linden, 18/04/2000 +# +# comments start with #, empty lines will be ignored. +# 1 turns an option on, 0 turns it off. +# An option consists of an atribute-value pair separated +# by minimum one space (more spaces and/or tabs are allowed) -# Your home, better do not change it! -$HOME = $ENV{'HOME'}; +# Your home directory, better do not change it! +# can be an environment variable or a path +Home $ENV{'HOME'} -# specify the path, where the NOTEDB directory +# specify the path, where the NOTEDB lib directory # resides. This will only used if it is not # installed inside the perl-lib directory structure! -$libpath = "/usr/local/lib"; - +LibPath /usr/local/lib # you need to decide which database backend you want # to use. Please refer to the corresponding documentation # for closer information about the certain backend! -# Currently supported types: "binary" or "mysql". -$dbdriver = "binary"; +# Currently supported types: "binary", "dbm" or "mysql". +# You must also edit/uncomment one section below for the +# backend you want to use! +DbDriver binary -# backend specific settings: -####### mysql ############### -# sql database settings. -$dbhost = ""; # mysql server (hostname) -$dbuser = ""; # mysql username -$dbpasswd = ""; # her password -$dbname = ""; # database name -$table = "note"; # Table and field names. -$fnum = "number"; -$fnote = "note"; -$fdate = "date"; -######## end mysql ########### +# backend specific settings for sql backend +#DbHost localhost +#DbUser you +#DbPasswd +#DbName mynotes +#DbTable note +#FieldNumber number +#FieldNote note +#FieldDate date +#### specific end ### -####### binary db ################## -# The location of the note-database. If it does -# not exist, it will be created. Only if $driver = "binary" -$NOTEDB = $HOME . "/.notedb"; -# Define the maximum bytes a note can have in a -# note-entry. -$MAX_NOTE = 4096; +# backend specific settings for binary(default) backend +NoteDb ~/.notedb +# Define the maximum bytes fields can have in a +# note-entry. Do not change MaxTimeByte to less than 64! -# Define the maximum bytes a timestamp can have -# in a note-entry. -$MAX_TIME = 64; -####### end binary ################# +MaxNoteByte 4096 +MaxTimeByte 64 +#### specific end ### -# ENCRYPTION -# if you want to encrypt your note-data, turn this on -# by setting to "YES". The default is no. -# if turned on, note will ask you for a passphrase -$USE_CRYPT = "NO"; -# takes only affect if $USE_CRYPT is on! -# Possible values: IDEA or DES -$CRYPT_METHOD = "IDEA"; # requires Crypt::IDEA +# backend specific settings for DBM backend +# this must be an existing directory! +#DbName /home/you/.notedbm +#### specific end ### + +# You can use encryption with note, that means notes and +# timestamps will be stored encrypted. This is supported +# by every db-backend. +# Set to 1 to turn it on. The Default is 0 (off) +UseEncryption 0 + +# Specify the encryption protocol. The appropriate perl +# module needs to be installed. Possible velues are +# IDEA, DES or BLOWFISH, the default is IDEA. +CryptMethod IDEA -# uncomment this, if you want to run note always -# in interactive mode -#$ALWAYS_INT = "YES"; +# You can run note always in interactive mode by simply +# typing "note". Set this option to 1 to turn it on. +# The default is 0 (off). +AlwaysInteractive 0 -# uncomment this, if you want to use always your -# favorite editor (even for creating notes) instead -# of -#$ALWAYS_EDIT = "YES"; +# In interactive mode, note issues a list command if you +# simply hit enter. By turning this on, it will issue a +# longlist command instead if you hit just enter. +# The default is 0 (off) +DefaultLong 0 -# uncomment this, if you dont prefer that note updates -# the timestamp of a note after editing it. It will -# keep the original timestamp if this option is set. -#$KEEP_TIMESTAMP = "YES"; + +# You can use an external editor everytime from note instead +# of STDIN for creating new notes. Set to 1 to turn it on. +# The default is 0 (off). +AlwaysEditor 0 # uncomment and edit it, if you want to use another # editor than the default $EDITOR or as fallback vi. -#$PreferredEditor = "emacs"; +#PreferredEditor emacs -# This option turns topic-support on or off -# comment it out, if you don't need it -$TOPIC = 1; +# If you dont prefer that note updates the timestamp of a +# note after editing, turn this on. It will +# keep the original timestamp if this option is set. +# The default is 0(off), to turn it on set to 1. +KeepTimeStamp 0 # You can specify your own topic separator here. # the default topic separator is a normal slash: "/" -#$TopicSep = '/'; +# see README for details about topics! +TopicSeparator / -# The maximum width for displaying a note. -$maxlen = 30; +# The maximum width for displaying a note, in CHARS. +# Depends on your screen-size. You can set it to +# "auto", if you wish that note sould determine the +# available size, but it experimental, be aware! +MaxLen 30 -# if $COLOR equals NO, then everything will be -# displayed with your default colors (mostly black) -$COLOR = "YES"; +# note can use colors for output, set this option to +# 1, if you don't want it, or if your terminal does +# not support it, set to 0. The default is 1 (on). +UseColors 1 -# Color-definitions of the various fields. Will be -# ignored if $COLOR = "NO". -$BORDER_COLOR = "BLACK"; # Borders -$NUM_COLOR = "blue"; # Note number -$NOTE_COLOR = "green"; # The note itself -$TIME_COLOR = "black"; # The time -$TOPIC_COLOR = "BLACK"; # The topic "prompt" - +# Color-definitions of the various items. Will only +# take effect, if "UseColors" is turned on! +BorderColor BLACK +NumberColor blue +NoteColor green +TimeColor black +TopicColor BLACK # The following colors are available: -# black, red, green, yellow, blue, magenta, cyan and white. -# It will be bold if it is uppercase. -# You can append an underscore, if you like it underscored, -# ie: blue_ -# Or, you can append an "I", if you like it inverted +# black, red, green, yellow, blue, magenta, cyan and white. +# for bold color write it uppercase (BLACK will be bold black) +# for underlined color append an underscore (blue_ will be underlined blue) +# for inverted color append an "I" (greenI will be inverted green) -# keep this "1;" please! -1; + + +# That's all about it for now. +# If you still have any questiosn, please feel free to contact +# me by email: Thomas Linden