[net.sources] rolo - a rolodex program

israel@umcp-cs.UUCP (Bruce Israel) (07/06/85)

Below is the source and manual entry for a program called 'rolo'.  'rolo'
is a rolodex program that maintains a database of names, addresses and
phone numbers, allowing you to add, delete, edit and get entries.  'rolo'
is written as a 'csh' shell script so it is not tremendously fast.  For
more info, read the manual and/or the code.  To get:

1) save the following text into a file.
2) in a clean directory, do 'sh <file>', where <file> is the above file name.
   This will make the files 'rolo' and 'rolo.1l'.
3) do a 'cp rolo /usr/local/bin' and 'cp rolo.1l /usr/man/man1'.
4) Enjoy!

Address all suggestions, comments, compliments, complaints, etc. to
israel@maryland.arpa, seismo!umcp-cs!israel.

------------------------- Cut Here -------------------------

: Run this shell script with "sh" not "csh"
PATH=:/bin:/usr/bin:/usr/ucb
export PATH
all=FALSE
if [ $1x = -ax ]; then
	all=TRUE
fi
/bin/echo 'Extracting rolo'
sed 's/^X//' <<'//go.sysin dd *' >rolo
#! /bin/csh -f
#
# rolo - A Rolodex program
#	 Written by Bruce Israel, israel@maryland, umcp-cs!israel, June 1985
#
# Usage:
#	"rolo [-f <file>] [-q] [-add || -delete || -edit || -get] [<keys>...]"
#
set usage = "[-f <file>] [-q] [-add || -delete || -edit || -get] [<keys>...]"
#
# Rolo options are:
#	-add:	 add phones entry
#	-delete: delete phones entries
#	-edit:	 edit phones entries
#	-get:	 look up entries
#	-file:	 use alternate phones file
#	-q:	 do deletions quietly
#
# default operation is `get' unless otherwise specified
umask 077
set phbook = ~/.phones
set noglob oper = get contin = 1 askdel = 1
alias getvar 'echo -n \!:1 ; set \!:2 = $< '
#
while ($#argv * $contin)
    switch ("$1")
    case "-f*":
	shift ; set phbook = $1; breaksw
    case "-a*":
	set oper = add; breaksw
    case "-d*":
	set oper = del; breaksw
    case "-e*":
	set oper = edit; breaksw
    case "-g*":
	set oper = get; breaksw
    case "-q":
	set askdel = 1; breaksw
    case "-*":
	set ex = $0
	set curex = $ex:t
	echo "${curex}: Illegal option: $1"
	echo "usage: "; echo "   " $curex $usage
	exit 1
    default:
	set contin = 0
    endsw
    if ($contin) shift
end
# printph - function for prettyprinting phones entry
#
alias printph awk -F\* \'{ if \(\$2 != \"\"\) printf\(\"%s \",\$2\)\; print \$1\; for \(i = 5\; i \<= NF\; i++\) if \(\$i != \"\"\) print \$i\; if \(\$3 != \"\"\) printf\(\"\(h\): %s \" ,\$3\)\; if \(\$4 != \"\"\) printf\(\"\(w\): %s\", \$4\) \; print \"\\n\" }\'
#
# tmp = phone items found, tmp2 = intermediate, new = new file created
set tmp = /tmp/rolo.$$ tmp2 = /tmp/rolo.2.$$ new = /tmp/rolo.n.$$
set fallthrutoadd = 0
alias cleanup rm -f $tmp $tmp2 $new
#
switch ($oper)	
case "del":
case "edit":
case "get":
# restrict file on keys to find matching items
    cp $phbook $tmp
    alias restr 'grep -i \!:1 < $tmp > $tmp2 ; mv $tmp2 $tmp'
    foreach x ( $* )
	restr $x
    end
    switch ($oper)

    case "get":
        printph $tmp; breaksw
    case "del":
	set del = yes count = `wc -l < $tmp` cont = 1 noglob
	if ($askdel) then
	    set del = no
	    while ($count * $cont)
		getvar "$count entries found, delete [ynrl]? " ans
		switch ("$ans")
		    case "y*":
		        set cont = 0 del = yes; breaksw
		    case "n*":
		    case "q*":
		        set cont = 0 del = no; breaksw
		    case "l*":
		        printph $tmp; breaksw
		    case "r*":
		        getvar "Keyword? " ans
			restr "$ans"
			set count = `wc -l < $tmp`; breaksw
		    default:
		        echo "y - yes, delete;  n - no, don't delete;"
			echo "l - list entries; r - restrict further"
		endsw
	    end
	    if ($count == 0) then
		echo "No entries found." ; rm -f $tmp; exit 1
	    endif
	endif
	if ("$del" == "yes") then
	    comm -23 $phbook $tmp > $new
	    cp $new $phbook
	endif
    breaksw

    case "edit":
#
    alias edit-item 'set vara = \!:2 ; echo -n \!:1 \"$vara\" " ==> "; set varb = $<; if ("$varb" == "") set varb = "$vara"; set line = "${line}${varb}*" '
    alias edit-finish 'echo "";echo "$line" | printph; echo "$line" | sort -m - $new -o $new; set line=""'
#
	test -s $tmp
	if ($status == 0) then
	    awk -F* '{ \
		printf("edit-item \"Last name: \" \"%s\"\n",$1); \
		printf("edit-item \"First name: \" \"%s\"\n",$2); \
		printf("edit-item \"Home phone: \" \"%s\"\n",$3); \
		printf("edit-item \"Work Phone: \" \"%s\"\n",$4); \
		printf("echo \"Address: \"\n"); adr = ""; \
		for (i = 5; i <= NF && $i != "" ; i++) { \
		    printf("echo \"         %s\"\n",$i); \
		    adr = adr $i "*"; }\
		print "echo \"\" ; echo \"New Address:\" " ; \
		print "set addr = \"x\" taddr = \"\" " ; \
		print "while (\"$addr\" != \"\")" ; \
		print " echo -n \"         \" ; set addr = $<" ; \
		printf(" if (\"${addr}\" != \"\") "); \
		print "set taddr = \"${taddr}${addr}*\"" ; \
		print " @ ct += 1" ; \
		print "end " ; \
		printf("if (\"${taddr}\" == \"\")set taddr = \"%s\"\n",adr); \
		print "set line = \"${line}${taddr}\" "; \
		print "edit-finish"}' $tmp > $tmp2
	    comm -23 $phbook $tmp > $new; set line = ""
	    source $tmp2; cp $new $phbook
	else
	    getvar "No such entry, add one (y/n)? " ans
	    if ("$ans" == "y" || "$ans" == "yes")  set fallthrutoadd = 1
	endif
    endsw
    if (! $fallthrutoadd) breaksw

case "add":
    set addr = "x" taddr = "" ct = 1 hph = "" 
    getvar "First name? " fname; getvar "Last name? " lname
    if ("$lname" == "") set lname = "$fname" fname = ""
    if ("$fname" != "") then
	getvar "Home phone? " hph
    endif
    getvar "Work phone? " wph
    while ("$addr" != "")
	getvar "Address line $ct? " addr; @ ct += 1
	if ("$addr" != "") set taddr = "${taddr}"*"${addr}"
    end
    touch $phbook
    set line = "${lname}*${fname}*${hph}*${wph}${taddr}"
    echo ""; echo $line | printph
    echo $line | sort -m - $phbook -o $phbook
    breaksw

endsw
cleanup
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 755 rolo
	/bin/echo -n '	'; /bin/ls -ld rolo
fi
/bin/echo 'Extracting rolo.1l'
sed 's/^X//' <<'//go.sysin dd *' >rolo.1l
X.TH ROLO 1 
X.SH NAME
rolo \- A Rolodex program
X.SH SYNOPSIS
X.B rolo
[
X.B \-q
]
[
X.B \-f <file>
]
[
<function>
]
[
<keywords> ...
]
X.PP
Where <function> is one of -edit, -get, -add, or -delete.  These
can be abbreviated as preferred.
X.SH DESCRIPTION
X.IR rolo
maintains a rolodex database of people's names, addresses, and phone
numbers.  It does four functions, add, delete, edit, and get.
The delete, edit, and get operations all accept multiple keywords
and select the entries to be processed as those that contain
all specified keywords.  Keywords are case-insensitive.
X.PP
X.B rolo -add
adds an entry to the database.  It prompts for each of the fields,
i.e. first and last names, home and work phone numbers, and
the address.  The address can be multiple lines, and
X.B rolo
will continue prompting until a blank line is given.
X.PP
If the whole name is in either the first or last
name field, it assumes that it is a company entry, alphabetizes
it as such, and will not ask for a home phone number.
X.PP
X.B rolo -delete [ <keywords> ... ]
will delete entries from the file that contain the specified keywords.
If the
X.B -q
option is specified, 
X.B rolo
will delete all entries without acknowledgement.  Otherwise, it says
how many entries found, and then prompts for one of four possible
responses: yes, delete them and exit; no, don't delete them but exit;
list the entries that have been matched; or restrict them further with
another specfied keyword.
X.PP
X.B rolo -edit [ <keywords> ... ]
will edit all entries that match.  If an entry is edited, each field
will be shown to the user and asked for a new value.  If a different
value is specified, then that field is replaced, otherwise, the old
entry remains.
X.PP
X.B rolo -get [ <keywords> ... ]
will get all entries that match, and display them in a readable
format.  If no operation is specified, the 'get' operation is
assumed.
X.PP
The default phones file database is the file ~/.phones.  The format
of the file is that each line is an entry (which are kept in sorted
order).  A line is made up of a number of fields, separated by
asterisks.  The fields, in order, are: last name, first name, home phone
number, work phone number, address line 1, address line 2, etc.
X.PP
If the
X.B -f <file>
option is used, then an alternate phones file is used instead.  For example,
the command "rolo -f /usr/lib/staff operator" will get the phone number
of all entries with the word operator (which was probably put as a line
of the address field), from the file /usr/lib/staff.  If multiple
X.B -f
files are specified, only the last one is used.
X.SH AUTHOR
Bruce Israel
X.SH FILES
\&.phones which contains the file of phone numbers.
X.br
X.SH BUGS
X.PP
Being a shell script, it is slow.
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 rolo.1l
	/bin/echo -n '	'; /bin/ls -ld rolo.1l
fi
-- 

Bruce Israel

University of Maryland, Computer Science Dept.
{rlgvax,seismo}!umcp-cs!israel (Usenet)    israel@Maryland (Arpanet)