Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Movie Database Scripts v1.5

47 views
Skip to first unread message

Colin Needham

unread,
Dec 13, 1990, 1:41:11 AM12/13/90
to
MOVIE DATABASE SCRIPTS v1.5
===========================

Welcome to the latest version of the database scripts which now includes
a link to the Movie Ratings Report and THE WRITERS LIST. If you are familiar
with the previous version of the scripts, you need only read the sections
entitled "MOVIE RATINGS REPORT", "WRITERS OPTIONS FOR USERS OF VERSION 1.1"
and "ADVANCED GENDB OPTIONS".

If you would like to receive updates in advance of their publication, send
me a mail message and I'll add you to the list of users.


INSTRUCTIONS FOR NEW USERS
==========================

There are now five lists posted at regular intervals to r.a.movies (actors,
actresses, directors, dead and writers). They contain over 25,000 entries and
cover more than 10,000 different movies between them. I have written some Unix
scripts to setup an online movie database with tools to search for all the
movies someone has been involved with or all the cast, director & writers of a
particular movie. There are also scripts to extract other information from the
database. The programs are contained in a shell archive at the end of this
message.

The following table gives details of list availability:

List | Last Post | Maintained by | Next Post
----------|-----------|---------------------------------------|----------
Directors | 11/??/90 | Dave Knight <dkn...@elm.sdd.trw.com> | Dec wk 3
Actresses | 11/20/90 | Andy Krieg <kr...@jupiter.med.ge.com> | UNKNOWN
Dead | 11/26/90 | Col Needham <c...@otter.hpl.hp.com> | Dec wk 3
Writers | 12/07/90 | Jeff Sullivan <j...@venera.isi.edu> | Jan wk 1
Actors | 12/10/90 | Col Needham <c...@otter.hpl.hp.com> | Jan wk 2

You do not need all five lists to use the scripts. I suggest you wait for
the next posting of any lists you don't have. If you absolutely cannot wait,
please e-mail the appropriate person in the above table. UNDER NO CIRCUMSTANCES
SHOULD YOU POST A NOTE TO REC.ARTS.MOVIES REQUESTING A COPY OF A LIST.


PHASE ONE: Creating the database
--------------------------------

(1) Unpack the shell archive at the end of this message into a directory. If
you already have saved copies of the lists, unpack it in the same
directory. Otherwise, create a new one. The archive contains four
main scripts: 'gendb' to generate the databases and 'list', 'listall' and
'lindex' to search them. The other programs are used internally by the
main scripts.

(2) Place a copy of each list in a file as outlined below:

List | File
---------------|---------
Actors List | actors
Actress List | actress
Directors List | directs
Dead List | dead
Writers List | writers

You should remove *all* headers and trailing lines from each file. All
lines in the files should either be blank or of the form:

<name> <movie/tv>

or:

<movie/tv>

(3) To create the databases, enter the following command at the shell prompt:

gendb

This will create five database files (actors.dbs, actress.dbs, dead.dbs,
writers.dbs and directs.dbs) corresponding to the lists. You can browse
these files using your favourite editor.

(4) Each time a new release of one of the lists is posted, strip off the
headers, save it to the appropriate file and re-run 'gendb'.

(5) You can delete the original list files if you are short of disk space. See
the section at the end entitled "ADVANCED GENDB OPTIONS" for details of how
to make the update process faster.


PHASE TWO: Searching the databases
----------------------------------

A Quick Guide
-------------

To use the basic features of the 'list' script, use one of the following forms:

* list -a "<actor>"

Lists all appearances by a particular actor or actress. For example,

list -a "Biehn, Michael"
list -a "Davis, Geena"
list -a "Grant, Cary"

The command is the same regardless of whether it is the actors, actress
or dead list that you are searching.

* list -d "<director>"

List all movies directed by a particular director. For example,

list -d "Hitchcock, Alfred"

* list -w "<writer>"

List all movies written by a particular writer. For example,

list -w "Hecht, Ben"

* list -t "<title>"

List all the cast, director and writers of a particular movie. The director
is marked by a "(d)" after her/his name and writers are marked with "(w)".
For example,

list -t "Terminator, The"

list -t "Hunt for Red October, The"

Please note that an exact match is required in all the above cases. See the
next section for details on searching for substrings. I recommend that you
try the above commands a few times before moving onto the more advanced options.


Advanced Options
----------------

* -s Allow partial match with -a/-d/-w/-t options. This option is useful if
you can't remember the precise spelling of a name or title. Examples:

list -s -d "Hitch" searches for directors containing substring "Hitch")

list -s -a "John" searches for films with actors/actresses whose
names include the substring "John"

To see which entries have been matched, use "-r" in combination
with this option (see below).

* -r Raw mode. Output results of search in full and unsorted. This is
useful with -s when you want to know what entries have been
matched. Example:

list -r -s -d "Reiner"

* -i Ignore case in search. This option is most useful when you're not sure
of which words in a title start with capital letters. Examples:

list -i -t "man with the golden gun, the"

list -i -d "HITCHCOCK, Alfred"

* -y Disregard year information in title search. In order to distinguish
different movies with the same title, some movies are marked with their
year of release in brackets. This option ignores anything in brackets
when performing a title search. Example:

list -y -t "Streetcar Named Desire, A"

This lists the casts, writers and directors of both versions of this movie.
The option provides a useful side-effect in that it also ignores any
"(aka ....)" information too.

* -m Movies only. Removes TV-series information from results of a search.
Example:

list -m -d "Lynch, David"

* -c Cat results. Uses 'cat' to display results instead of 'more'. Example:

list -c -a "Nicholson, Jack"


Once you are familiar with how the scripts work, you can continue into the
section for experienced users below.

-------------------------------------------------------------------------------

INSTRUCTIONS FOR EXPERIENCED USERS
==================================

(1) multiple queries
--------------------

There is no limit on the number of "-a" options in the same query. Examples:

list -a "Grant, Cary" -a "Bergman, Ingrid"
-- lists all movies in which Cary Grant *and* Ingrid Bergman co-starred

list -a "Biehn, Michael" -a "Paxton, Bill" -a "Henriksen, Lance"
-- lists all movies featuring all three of Biehn, Paxton & Henriksen

One "-d" option may also be included. Examples:

list -d "Hitchcock, Alfred" -a "Grant, Cary"
-- lists all Hitchcock movies featuring Cary Grant

list -d "Hitchcock, Alfred" -a "Grant, Cary" -a "Bergman, Ingrid"
-- lists all Hitchcock movies featuring both Grant & Bergman

One "-w" option may also be included. Examples:

list -w "Hecht, Ben" -a "Grant, Cary"
-- lists all movies written by Hecht featuring Grant

list -d "Hitchcock, Alfred" -w "Hecht, Ben" -a "Grant, Cary"
-- lists all Hitchcock movies written by Hecht featuring Grant


All of the standard options (-m, -s, -c, -r & -i) can be used as before with
one exception: The "-r" option can only be used when there is only one
search string. Example:

list -r -a "Davis, Geena"
-- this is still okay

list -r -a "Davis, Geena" -a "Goldblum, Jeff"
-- this is an invalid combination


(2) listall script
------------------

'listall' takes a movie title as an argument and for each cast member of
that movie, lists all the other movies they have appeared in. The director's
other credits are also listed (name marked with "(d)" ) and similarly for
writers (name marked with "(w)"). Example:

listall "Abyss, The"

I forgot to mention in the original instructions that to search for a TV
series, it has to be enclosed in single quotes. Example:

listall '"Twin Peaks"'
-- list all entries for the cast of "Twin Peaks"


(3) lindex script
-----------------

I have also added an indexing script for the lists. You can use this to
generate a list of all the actors, actresses, directors, writers and titles
on the lists. The options available are:

lindex -acr
-- generate list of actors

lindex -acs
-- generate list of actresses

lindex -dead
-- generate list of dead actors/actresses

lindex -cast
-- generate combined list of dead & alive actors & actresses

lindex -dir
-- generate list of directors

lindex -write
-- generate list of writers

lindex -title
-- generate list of titles from all 5 lists

The following options can be combined with those above:

-s <substring> restrict search to names/titles containing <substring>

-m list movies only, no TV-series

-i ignore case with -s

-c use 'cat' to display results instead of 'more'

Examples:

lindex -acr -s "Michael"
-- generate list of actors containing the substring "Michael"

lindex -title -s "Alien"
-- generate list of all movie/tv titles containing "Alien"

lindex -title -m -s "Law" -i
-- generate list of all movie titles containing "Law" (ignoring case)

-------------------------------------------------------------------------------

MOVIE RATINGS REPORT
====================

Notes
-----

(1) If you are not interested in the ratings report, the scripts will still
work OK as long as you don't use any of the options below.

(2) Users of version 1.1 should note that the archive contains a new version
of the 'explist' script. The actress list no longer needs to be edited
before running 'gendb'.


PHASE ONE: Creating the ratings database
----------------------------------------

(1) The archive includes a 'C' program to search the Movie Ratings database
efficiently. Enter the following command to compile the program:

cc mrr.c -o mrr

(2) Save the latest version of the Movie Ratings Report in a file called
'ratings'. Note: there is no need to strip the headers from this file.

(3) To create the ratings database enter:

genrdb ratings

at the shell prompt. This will create a file called 'ratings.dbs' which
you can browse using your favourite editor.

(4) Each time a new version of the report is published, repeat steps (2) and
(3). The scripts only require the 'ratings.dbs' file so you can delete
'ratings' if you wish.


PHASE TWO: Using the new features
---------------------------------

list
----

All the options to 'list' work exactly as before. Two new options have been
added for use in combination with -a (cast search), -w (writer search) and
-d (director search).

-mrr Movie Ratings Report. Takes each title produced by the search and adds
the ratings information. Examples:

list -mrr -a "Biehn, Michael"

Produces:

0000012210 99 6.7 Abyss, The
0000012210 220 7.2 Aliens
China Rose (TV)
Coach
Deadly Intentions (TV)
Fan, The (1981)
0000121100 123 5.3 Grease
In a Shallow Grave (TV)
.1.022110. 24 5.6 Lords of Discipline, The
Navy Seals
Rampage (1988)
001002100. 33 5.3 Seventh Sign, The
0.00002310 191 7.5 Terminator, The
Zuma Beach (TV)

NOTES
-----
A blank area before a title means that it is not yet on the Movie
Ratings Report or alternatively, there is a slight difference in the
title format between the list and the MRR. I have been working with
the other list maintainers and Chuck to make our titles as consistent
as possible.

Use of -mrr automatically switches on the -m (movies only) option, as
the MRR does not contain TV-series ratings.

Further examples (without results):

list -mrr -a "Keaton, Diane"

list -mrr -a "Grant, Cary"

list -mrr -d "Allen, Woody"


-smrr Sorted movie ratings report. Works exactly like -mrr except the
results are sorted in descending order by average rating (i.e. most
highly rated film first).

list -smrr -a "Biehn, Michael"

Produces:

0.00002310 191 7.5 Terminator, The
0000012210 220 7.2 Aliens
0000012210 99 6.7 Abyss, The
.1.022110. 24 5.6 Lords of Discipline, The
0000121100 123 5.3 Grease
001002100. 33 5.3 Seventh Sign, The
China Rose (TV)
Coach
Deadly Intentions (TV)
Fan, The (1981)
In a Shallow Grave (TV)
Navy Seals
Rampage (1988)
Zuma Beach (TV)

For details on the format of the Movie Ratings data and how to take part in
the poll, see the section at the end of Chuck's weekly report.

lindex
------

The -mrr and -smrr options may also be used with 'lindex' in combination
with the -title option. Examples:

lindex -title -mrr -s "Alien"

produces:

0000012220 230 7.6 Alien
Alien Dead, The
0.01221000 101 5.6 Alien Nation
Alien Predator
Alien Prey
Alien Thunder
Alien from L.A.
Alienator
0000012210 220 7.2 Aliens
Aliens Are Coming, The
Dr. Alien (aka I Was a Teenage Sex Mutant)
00.212100. 57 5.0 My Stepmother Is an Alien
Resident Alien
Voyage of the Rock Aliens


I would be very pleased to hear any feedback on the new scripts. The
'mrr' program is my first real attempt at a 'C' program so please let me
know if there are any problems.

-------------------------------------------------------------------------------

WRITERS OPTIONS FOR USERS OF VERSION 1.1
========================================

This section is a summary of the writers options for users of version 1.1
of the scripts.

gendb
-----
Place a copy of the list in the file 'writers' and run the new version.

list
----
The "-w" option searches the list & can be used in combination with the other
options. Examples:

list -w "Goldman, William"
-- search for movies written by William Goldman

list -a "Grant, Cary" -w "Hecht, Ben"
-- search for movies written by Hecht & starring Grant

list -a "Grant, Cary" -w "Hecht, Ben" -d "Hitchcock, Alfred"
-- search for movies written by Hecht, starring Grant & directed by Hitchcock

The -t search will include the writer information if available. Writers are
marked with "(w)". Example:

list -t "Terminator, The"


listall
-------
The script automatically includes the writer information.

lindex
------
To produce an index of writers, use "-write". Example:

lindex -write

-------------------------------------------------------------------------------

ADVANCED GENDB OPTIONS
======================

I've had mail from David Moor pointing out that the requirement to keep copies
of the original lists as well as the database files is a problem for people who
are short of disk space. I have modified 'gendb' so that the requirement no
longer applies. The new version has the advantage that you don't have to
wait for it to process every database file if only one list has been updated.

The new options are:

-acr update actors database

-acs update actress database

-dead update dead database

-cast update all cast databases (comibination of -acr -acs -dead)

-dir update directors database

-write update writers database

The options can be used in any combination and in any order. If you do not
specify any options, the script will update all the databases for which
there is a list file in the directory. Once you have updated the appropriate
databases you may delete the corresponding list files if you wish.

-------------------------------------------------------------------------------

NOTES
=====

(1) I welcome feedback on the scripts. If you have any gripes or would like
to see a particular feature added, please let me know by e-mail.

(2) I will be adding some new features in the near future. If you would like
to receive updates by e-mail, send me a mail message.

(3) The scripts are not completely idiot-proof. It is possible to
specify certain invalid option combinations. I will fix this in a later
release.

(4) Options to the scripts can be specified in any order.

(5) I have been working with the other list keepers to ensure titles are
consistent between lists (year info, capitalization, spelling etc.),
however, there are bound to be a few discrepencies here and there.
This may lead to some titles/people not being located in a search,
even though the information is essentially in the database. Please let
me know if you come across any instances of this.

(6) If you are interested in taking part in Chuck Musciano's Movie Ratings
poll, I have a set of vote management scripts. They can generate a ballot
for the whole report and make voting in the weekly ballots easier by
keeping track of which movies you have already voted for. Available by
e-mail from me.

Cheers,

Col

------------------------------------------------------------
"Look at it this way, in a hundred years who's gonna care ?"
-- The Terminator
------------------------------------------------------------
Col Needham | Phone: +44 272 799910 x 24131
HP Labs | c...@hplb.hpl.hp.com
Bristol | c...@hplabs.hpl.hp.com
U.K. | c...@otter.hpl.hp.com
------------------------------------------------------------

THE ARCHIVE
===========

#---------------------------------- cut here ----------------------------------
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by Col Needham <cn@otter> on Thu Nov 29 11:59:06 1990
#
# This archive contains:
# castgrep explist gendb genrdb
# lindex list listall mrr.c
# prcast lcase.sed writes.sed
#
# Error checking via wc(1) will be performed.

LANG=""; export LANG
PATH=/bin:/usr/bin:$PATH; export PATH

echo x - castgrep
cat >castgrep <<'@EOF'
#!/bin/sh

# Script: castgrep

# Purpose: Used by 'list' to scan castlist for actors & actresses

# Author: Col Needham <c...@otter.hpl.hp.com>

lcount=0
while [ $lcount -lt $actidx ]
do
read cast
case "${raw}${substring}" in
nn) cat $acrdb $acsdb $deadb | $greper "^${cast}|" | awk -F\| '{print $2}' > "$tmp.$lcount" ;;
ny) cat $acrdb $acsdb $deadb | $greper "${cast}.*|" | awk -F\| '{print $2}' > "$tmp.$lcount" ;;
yn) cat $acrdb $acsdb $deadb | $greper "^${cast}|" > "$tmp.$lcount" ;;
yy) cat $acrdb $acsdb $deadb | $greper "${cast}.*|" > "$tmp.$lcount" ;;
esac
lcount=`expr $lcount + 1`
done
@EOF
set `wc -lwc <castgrep`
if test $1$2$3 != 2094610
then
echo ERROR: wc results of castgrep are $* should be 20 94 610
fi

chmod 751 castgrep

echo x - explist
cat >explist <<'@EOF'
#!/bin/sh

# Script: explist

# Purpose: read in a list & produce a list database on the standard output

# Authors: Col Needham <c...@otter.hpl.hp.com>
# & Owen Beckley <owen_d_...@att.com>

sed -e '/^$/d' -e 's/ * */ /' $1 | \
awk -F\t '/^[A-Za-z]/ {s1 = $1} {print s1 "|" $2}'

@EOF
set `wc -lwc <explist`
if test $1$2$3 != 1250294
then
echo ERROR: wc results of explist are $* should be 12 50 294
fi

chmod 751 explist

echo x - gendb
cat >gendb <<'@EOF'
#!/bin/sh

# Script : gendb

# Purpose: generate the database files for the 'list' script

# Author: Col Needham <c...@otter.hpl.hp.com>

acrdb=actors.dbs
acsdb=actress.dbs
deaddb=dead.dbs
dirdb=directs.dbs
writedb=writers.dbs

actors=actors
directs=directs
writers=writers
dead=dead
actress=actress

edwriters="writes.sed"

if [ $# -eq 0 ]
then
addwrite=y
addacr=y
addacs=y
adddir=y
adddead=y
fi

while [ -n "$1" ]
do case $1 in
-acr) addacr=y
shift ;;
-acs) addacs=y
shift ;;
-dead) adddead=y
shift ;;
-cast) addacr=y
addacs=y
adddead=y
shift ;;
-dir) adddir=y
shift ;;
-write) addwrite=y
shift ;;
*) echo "gendb: unrecognised option"
echo "usage: gendb [-acr -acs -dead -cast -dir -write]"
exit 1 ;;
esac
done

if [ -n "$addacr" -a -r $actors ]
then
echo "Adding actors"
explist $actors | sort > $acrdb
fi

if [ -n "$addacs" -a -r $actress ]
then
echo "Adding actresses"
explist $actress | sort > $acsdb
fi

if [ -n "$adddead" -a -r $dead ]
then
echo "Adding dead"
explist $dead | sort > $deaddb
fi

if [ -n "$adddir" -a -r $directs ]
then
echo "Adding directors"
explist $directs | sort > $dirdb
fi


if [ -n "$addwrite" -a -r $writers ]
then
echo "Adding writers"
explist $writers | sed -f $edwriters | awk -F\| \
'{if (NF==3) print $0;\
else print $0 "|"}' | sort > $writedb
fi

if [ ! -r $acrdb ]
then
touch $acrdb
fi

if [ ! -r $acsdb ]
then
touch $acsdb
fi

if [ ! -r $deaddb ]
then
touch $deaddb
fi

if [ ! -r $dirdb ]
then
touch $dirdb
fi

if [ ! -r $writedb ]
then
touch $writedb
fi
@EOF
set `wc -lwc <gendb`
if test $1$2$3 != 1102591690
then
echo ERROR: wc results of gendb are $* should be 110 259 1690
fi

chmod 751 gendb

echo x - genrdb
cat >genrdb <<'@EOF'
#!/bin/sh

# Script: genrdb

# Purpose: Generate movie ratings database from weekly report

# Author: Col Needham <c...@otter.hpl.hp.com>

ratedb=ratings.dbs
lcase=lcase.sed
ratings=$1

# Check one argument supplied
if [ $# -ne 1 ]
then
echo "usage: genrdb <ratings>"
fi

# Check ratings file readable
if [ ! -r $ratings ]
then
echo "genrdb: ratings file not found"
fi

# Generate database
awk '/ . [0-9.*]+ +[0-9]+ +[0-9.]+ */ {printf "%10s|%5s|%4s|%s\n", substr($0,7,10), substr($0,20,5), substr($0,27,4), substr($0,33,120)}' $ratings | sed -f $lcase | sort -u +0.22 > $ratedb
@EOF
set `wc -lwc <genrdb`
if test $1$2$3 != 2684586
then
echo ERROR: wc results of genrdb are $* should be 26 84 586
fi

chmod 751 genrdb

echo x - lindex
cat >lindex <<'@EOF'
#!/bin/sh

# Script : lindex

# Purpose: Index list databases

# Author : Col Needham <c...@otter.hpl.hp.com>

# Valid options:
#
# -acr return list of actors in database
# -acs return list of actresses in database
# -dead return list of dead actors/actresses
# -cast combines 3 options above
# -dir return list of directors
# -write return list of writers
# -title return list of titles in all lists
#
# Note these options produce an index for the whole lists. To restrict
# the match see -s
#
# -s substring, follow by substring to restrict search (e.g. -s "John")
# -i ignore case, disregard case in search with -s
# -m movies only, don't display TV series information
# (only valid with -title)
# -c cat, use 'cat' to display results instead of 'more'
# -mrr add movie ratings (only valid with -title)
# -smrr add movie ratings & sort by average ratings (only valid with -title)
#
# Examples:
# lindex -acr
# lindex -cast
# lindex -acr -s "Michael"
# lindex -title -s "Alien"

# names of database files
acrdb=actors.dbs
acsdb=actress.dbs
deaddb=dead.dbs
dirdb=directs.dbs
writedb=writers.dbs

# temporary file
tmp=tmpfile
tmp2=tmpfile2

# default pager for results
pager=more

# default grep command
greper="grep"

# interpret options
while [ -n "$1" ]
do case $1 in
-s) shift
substring=$1
shift ;;
-m) movies=y
shift ;;
-c) pager=cat
shift ;;
-i) greper="grep -i"
shift ;;
-acr) listfile=$acrdb
shift ;;
-acs) listfile=$acsdb
shift ;;
-dead) listfile=$deaddb
shift ;;
-cast) cast=y
shift ;;
-dir) listfile=$dirdb
shift ;;
-write) listfile=$writedb
shift ;;
-title) title=y
shift ;;
-smrr) mrr=y
movies=y
msorter="sort +0.25 -0.30 -r +0.32"
shift ;;
-mrr) mrr=y
movies=y
msorter=cat
shift ;;
*) echo "$1: unrecognized option"
echo "usage: lindex [-m -c -i -acr -acs -dead -cast -dir -write -s <pattern>]"
echo " lindex [-m -c -i -title -mrr -smrr -s <pattern>]"
exit 1 ;;
esac
done

# index for lists
if [ -n "$listfile" ]
then
if [ -n "$substring" ]
then
awk -F\| '{print $1}' $listfile | $greper "$substring" | sort -u > $tmp
else
awk -F\| '{print $1}' $listfile | sort -u > $tmp
fi
fi


# index for all cast
if [ -n "$cast" ]
then
if [ -n "$substring" ]
then
awk -F\| '{print $1}' $acrdb $acsdb $deaddb | $greper "$substring" | sort -u > $tmp
else
awk -F\| '{print $1}' $acrdb $acsdb $deaddb | sort -u > $tmp
fi
fi

# index by title
if [ -n "$title" ]
then
if [ -n "$substring" ]
then
awk -F\| '{print $2}' $acrdb $acsdb $deaddb $dirdb $writedb | $greper "$substring" | sort -u > $tmp
else
awk -F\| '{print $2}' $acrdb $acsdb $deaddb $dirdb $writedb | sort -u > $tmp
fi
fi

# output results
if [ -r $tmp ]
then
# remove TV info?
if [ -n "$movies" ]
then
grep -v '^"' $tmp > $tmp2
mv $tmp2 $tmp
fi
if [ -n "$title" -a -n "$mrr" ]
then
sort -f $tmp | mrr | $msorter | $pager
else
sed -e 's/"/~/g' $tmp | sort | sed -e 's/~/"/g' | $pager
fi
if [ -s $tmp ]
then
rm $tmp
exit 1
else
rm $tmp
exit 0
fi
fi
@EOF
set `wc -lwc <lindex`
if test $1$2$3 != 1515313378
then
echo ERROR: wc results of lindex are $* should be 151 531 3378
fi

chmod 751 lindex

echo x - list
cat >list <<'@EOF'
#!/bin/sh

# Script : list version 1.5

# Purpose: Search list databases

# Author : Col Needham <c...@otter.hpl.hp.com> based on an idea by Grant Mason

# Valid options:
#
# -a <name> return list of movies with actor/actress <name>
# -d <name> return list of movies directed by <name>
# -w <name> return list of movies written by <name>
# -t <title> list stars of movie <title>, director marked by (d)
# if known.
#
# Note these options require an exact name/title match, for softer
# matches see -s and -i
#
# Also, any number of "-a" options maybe combined to search for movies
# featuring all of the stars. One "-d" option may be included to restrict
# the search to only movies directed by a particular director
#
# -s substring, allow partial match with -a -t -d options
# -i ignore case, disregard case in search with -a -t -d
# -r raw mode, output results in full & unsorted (useful with -s)
# -y year, disregard any year info in title search (or anything else
# in brackets after title)
# -m movies only, don't display TV series information (not valid with -t)
# -c cat, use 'cat' to display results instead of 'more'
# -mrr add movie ratings information
# -smrr add movie ratings information & sort by average rating
#
# Examples:
# list -a "Biehn, Michael"
# list -d "Cameron, James"
# list -w "Cameron, James"
# list -t "Abyss, The"
# list -a "Biehn, Michael" -a "Paxton, Bill"
# list -a "Biehn, Michael" -d "Cameron, James"

# names of database files
acrdb=actors.dbs
acsdb=actress.dbs
deaddb=dead.dbs
dirdb=directs.dbs
writedb=writers.dbs

# temporary files
tmp=tmpfile
tmp2=tmpfile2
names=tmpfile3

# delete old names file
if [ -r $names ]
then
rm $names
fi

# default pager for results
pager=more

# default grep command
greper="grep"

# initialize counters
scnt=0
actidx=0
lcount=0

# set default options
raw=n
substring=n
movies=n
noyear=n

export greper actidx tmp acrdb acsdb deaddb raw substring

# interpret options
while [ -n "$1" ]
do case $1 in
-s) substring=y
shift ;;
-m) movies=y
shift ;;
-r) raw=y
shift ;;
-y) noyear=y
shift ;;
-c) pager=cat
shift ;;
-i) greper="grep -i"
shift ;;
-a) shift
echo $1 >> $names
scnt=`expr $scnt + 1`
actidx=`expr $actidx + 1`
shift ;;
-d) shift
dir=$1
scnt=`expr $scnt + 1`
shift ;;
-w) shift
write=$1
scnt=`expr $scnt + 1`
shift ;;
-t) shift
title=$1
shift ;;
-smrr) mrr=y
movies=y
msorter="sort +0.25 -0.30 -r +0.32"
shift ;;
-mrr) mrr=y
movies=y
msorter=cat
shift ;;
*) echo "$1: unrecognized option"
echo "usage: list [-m -s -r -c -i -mrr -smrr] [-a <actor>]* [-d <director>] [-w <writer>]"
echo " list [-y -s -r -c -i] -t <title>"
exit 1 ;;
esac
done

# remove any old temporary files
if [ -r tmpfile.0 ]
then
rm tmpfile.*
fi

# Check for "-r" with > 1 search string
if [ "$raw" = "y" -a $scnt -gt 1 ]
then
echo "$0: -r not available with more than one search string"
exit 1
fi

# Check for "-r" with movie ratings
if [ "$raw" = "y" -a "$mrr" = "y" ]
then
echo "$0: -r not available with -mrr and -smrr"
exit 1
fi

# search for actor/actress?
if [ $actidx -gt 0 ]
then
castgrep < $names
rm $names
fi

# search for director?
if [ -n "$dir" ]
then
case "${raw}${substring}" in
nn) $greper "^${dir}|" $dirdb | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;;
ny) $greper "${dir}.*|" $dirdb | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;;
yn) $greper "^${dir}|" $dirdb > "$tmp.$actidx" ;;
yy) $greper "${dir}.*|" $dirdb > "$tmp.$actidx" ;;
esac
actidx=`expr $actidx + 1`
fi

# search for writer?
if [ -n "$write" ]
then
case "${raw}${substring}" in
nn) $greper "^${write}|" $writedb | awk -F\| \
'{if (length ($3) > 0) print $2 " " $3;\
else print $2}' | sort > "$tmp.$actidx" ;;
ny) $greper "${write}.*|.*|.*" $writedb | awk -F\| \
'{if (length ($3) > 0) print $2 " " $3;\
else print $2}' | sort > "$tmp.$actidx" ;;
yn) $greper "^${write}|" $writedb > "$tmp.$actidx" ;;
yy) $greper "${write}.*|.*|.*" $writedb > "$tmp.$actidx" ;;
esac
fi


# Output results of cast/director/writer search
if [ $scnt -gt 0 ]
then
# find titles common to all searches
cp "$tmp.0" $tmp
for i in tmpfile.*
do
comm -12 $tmp $i > $tmp2
mv $tmp2 $tmp
rm $i
done
# output results
case "${movies}${raw}" in
nn) sed -e 's/"/~/g' $tmp | sort | sed -e 's/~/"/g' | $pager ;;
ny) $pager $tmp ;;
yn) if [ -n "$mrr" ]
then
grep -v '^"' $tmp | sort -f | mrr | $msorter | $pager
else
grep -v '^"' $tmp | $pager
fi ;;
yy) grep -v '|"' $tmp | $pager ;;
esac
# remove temporary file & exit with appropriate status
if [ -s $tmp ]
then
rm $tmp
exit 0
else
rm $tmp
exit 1
fi
fi

# search for title?
if [ -n "$title" ]
then
if [ "$substring" = "y" ]
then
$greper "|.*${title}" $dirdb | awk -F\| '{print $1 " (d)|" $2}' > $tmp
$greper "|.*${title}" $writedb | awk -F\| \
'{if (length($3) > 0) print $1 " " $3 " (w)|" $2;\
else print $1 " (w)|" $2}' >> $tmp
cat $acrdb $acsdb $deadb | $greper "|.*${title}" | sort >> $tmp
elif [ "$noyear" = "y" ]
then
$greper "|${title} (.*)$" $dirdb | awk -F\| '{print $1 " (d)|" $2}' > $tmp
$greper "|${title} (.*)" $writedb | awk -F\| \
'{if (length($3) > 0) print $1 " " $3 " (w)|" $2;\
else print $1 " (w)|" $2}' >> $tmp
cat $acrdb $acsdb $deadb | $greper "|${title} (.*)$" | sort >> $tmp
else
$greper "|${title}$" $dirdb | awk -F\| '{print $1 " (d)|" $2}' > $tmp
$greper "|${title}|" $writedb | awk -F\| \
'{if (length($3) > 0) print $1 " " $3 " (w)|" $2;\
else print $1 " (w)|" $2}' >> $tmp
cat $acrdb $acsdb $deadb | $greper "|${title}$" | sort >> $tmp
fi
# output results
case "${movies}${raw}" in
nn) awk -F\| '{print $1}' $tmp | $pager ;;
ny) $pager $tmp ;;
yn) grep -v '|"' $tmp | awk -F\| '{print $1}' | $pager ;;
yy) grep -v '|"' $tmp | $pager ;;
esac
# remove temporary file & exit with appropriate status
if [ -s $tmp ]
then
rm $tmp
exit 0
else
rm $tmp
exit 1
fi
fi

exit 1
@EOF
set `wc -lwc <list`
if test $1$2$3 != 25610756530
then
echo ERROR: wc results of list are $* should be 256 1075 6530
fi

chmod 751 list

echo x - listall
cat >listall <<'@EOF'
#!/bin/sh

# Script: listall

# Purpose: list all other appearances by the cast of a particular movie

# Author: Col Needham <c...@otter.hpl.hp.com>

if [ $# -ne 1 ]
then
echo "usage: listall <title>"
exit 1
fi

list -t "$1" | prcast | more
@EOF
set `wc -lwc <listall`
if test $1$2$3 != 1543243
then
echo ERROR: wc results of listall are $* should be 15 43 243
fi

chmod 751 listall

echo x - mrr.c
cat >mrr.c <<'@EOF'
/*
* Program: mrr
*
* Function: Read a sorted list of titles from stdin and output their
* ratings on stdout.
*
* Author: Col Needham <c...@otter.hpl.hp.com>
*
* Notes: My first real 'C' program so I expect there is a better way to do it!
*
*/

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>

titlecpy(s,t) /* copy title, convert to lowercase & remove bracketed info */
char s[], t[];
{
int i=0, flag=1; /* loop counter & continuation flag */

while (s[i] && flag)
{
flag = s[i] != '(' || (s[i+1] == '1' && s[i+2] == '9');
t[i++]=tolower(s[i]);
}
if (flag) /* ordinary title, terminate string */
t[i] = '\0';
else /* terminate title before bracketed information */
{
t[i-2] = '\n';
t[i-1]='\0';
}
}

main()
{
char title[120]; /* title */
char stitle[120]; /* lowercase title minus bracketed info */
char ratings[120]; /* current line from MRR */
int flag; /* continuation flag */

FILE *fopen(), *fp;

fp = fopen("ratings.dbs","r"); /* open MRR database */
fgets(ratings,160,fp);
while (fgets(title,80,stdin) != NULL)
{
titlecpy(title, stitle);
flag = strcmp(ratings+22,stitle);
while (flag < 0 && fgets(ratings, 160, fp) != NULL)
flag = strcmp(ratings+22,stitle);
if (flag) /* no match, output blank ratings */
printf(" %s", title);
else
{
strcpy(ratings+22, title); /* overwrite title with full title */
ratings[10]='\0';
ratings[16]='\0';
ratings[21]='\0';
printf(" %s %s %s %s",ratings,ratings+11,ratings+17,ratings+22);
}
}
}
@EOF
set `wc -lwc <mrr.c`
if test $1$2$3 != 652281815
then
echo ERROR: wc results of mrr.c are $* should be 65 228 1815
fi

chmod 644 mrr.c

echo x - prcast
cat >prcast <<'@EOF'
#!/bin/sh

# Script: prcast

# Purpose: Used by 'listall' script to generate formatted movie lists

# Author: Col Needham <c...@otter.hpl.hp.com>

read iline
while [ -n "$iline" ]
do
echo "----------------------------------------------------------------------------"
echo $iline
echo
dir=`expr "$iline" : '\(.*\) (d)' \| "$iline"`
if [ "$iline" != "$dir" ]
then
list -d "$dir"
else
wri=`expr "$iline" : '\(.*\) (w)' \| "$iline"`
if [ "$iline" != "$wri" ]
then
list -w "$wri"
else
list -a "$iline"
fi
fi
echo
read iline
done
@EOF
set `wc -lwc <prcast`
if test $1$2$3 != 3078602
then
echo ERROR: wc results of prcast are $* should be 30 78 602
fi

chmod 751 prcast

echo x - lcase.sed
cat >lcase.sed <<'@EOF'
s/A/a/g
s/B/b/g
s/C/c/g
s/D/d/g
s/E/e/g
s/F/f/g
s/G/g/g
s/H/h/g
s/I/i/g
s/J/j/g
s/K/k/g
s/L/l/g
s/M/m/g
s/N/n/g
s/O/o/g
s/P/p/g
s/Q/q/g
s/R/r/g
s/S/s/g
s/T/t/g
s/U/u/g
s/V/v/g
s/W/w/g
s/X/x/g
s/Y/y/g
s/Z/z/g
@EOF
set `wc -lwc <lcase.sed`
if test $1$2$3 != 2626208
then
echo ERROR: wc results of lcase.sed are $* should be 26 26 208
fi

chmod 644 lcase.sed

echo x - writes.sed
cat >writes.sed <<'@EOF'
s/ (book)$/|(book)/
s/ (novel)$/|(novel)/
s/ (play)$/|(play)/
s/ (story)$/|(story)/
s/ (screenplay)$/|(screenplay)/
s/ (poem)$/|(poem)/
s/ (article)$/|(article)/
s/ (memoir)$/|(memoir)/
s/ (also book)$/|(also book)/
s/ (also novel)$/|(also novel)/
s/ (also play)$/|(also play)/
s/ (also story)$/|(also story)/
@EOF
set `wc -lwc <writes.sed`
if test $1$2$3 != 1232310
then
echo ERROR: wc results of writes.sed are $* should be 12 32 310
fi

chmod 640 writes.sed

exit 0

0 new messages