Article 104058 of rec.arts.movies: From: cn@otter.hpl.hp.com (Colin Needham) Date: Thu, 5 Nov 1992 12:37:50 GMT Subject: Movie Database (v2.3) Part II: Archive Message-ID: <28040475@otter.hpl.hp.com> Organization: Hewlett-Packard Laboratories, Bristol, UK. Path: nntp-server.caltech.edu!elroy.jpl.nasa.gov!sdd.hp.com!scd.hp.com!hpscdm!hplextra!otter.hpl.hp.com!otter!cn Newsgroups: rec.arts.movies Lines: 4635 MOVIE DATABASE SCRIPTS v2.3 PART II: The Archive ================================================ 20. 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 Colin Needham on Wed Nov 4 12:47:22 1992 # # This archive contains: # explist gendb lindex list # title listall mrr.c ltrace # updateaka akaextract.awk attribute.awk alist # alist.awk mkballot lguide format.awk # bin_chop.c linstall person yr.c # mguide yrf.c ldebug lformat # akaprint corrects.mrr mgde.c akamap.c # lseen votechk # # Error checking via wc(1) will be performed. LANG=""; export LANG PATH=/bin:/usr/bin:$PATH; export PATH echo x - explist cat >explist <<'@EOF' #!/bin/sh # Script: explist version 1.95 # Purpose: read in a list & produce a list database on the standard output # Authors: Col Needham # & Owen Beckley listid=$1 listfile=$2 sed -e '/^$/d' -e 's/ * */ /' $listfile | \ awk -F\t '/^[A-Za-z]/ {s1 = $1} {print s1 "|" $2}' | \ awk -F\| -f akaextract.awk id=$listid - | \ awk -F\| -f attribute.awk - @EOF set `wc -lwc gendb <<'@EOF' #!/bin/sh # Script : gendb version 2.3 # Purpose: generate database files from posted lists # Author: Col Needham PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" # database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs ratedb=ratings.dbs akadb=aka.dbs moviedb=movies.dbs # list files actors=actors directs=directs writers=writers dead=dead actress=actress cine=cine composers=composers ratings=ratings akafile=akafile mrrcors=corrects.mrr akalist=akalist greper=cat trap "rm -f $tmp; exit" 1 2 15 if [ $# -eq 0 ] then addwrite=y addacr=y addacs=y adddir=y adddead=y addrate=y addcomp=y addcine=y addaka=y addmovie=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 ;; -comp) addcomp=y shift ;; -cine) addcine=y shift ;; -mrr) addrate=y shift ;; -aka) addaka=y shift ;; -movie) addmovie=y shift ;; -m) greper='grep -v ''|"''' shift ;; *) echo "gendb: unrecognised option" echo "usage: gendb [-acr -acs -dead -cast -dir -write -comp -cine -mrr -aka -movie -m]" exit 1 ;; esac done if [ -r $akalist ] then rm $akalist fi if [ -n "$addacr" -a -r $actors ] then echo "Adding actors" explist 01 $actors | $greper | sort -t\| -f +0 -1 +1 -2 > $acrdb updateaka 01 fi if [ -n "$addacs" -a -r $actress ] then echo "Adding actresses" explist 02 $actress | $greper | sort -t\| -f +0 -1 +1 -2 > $acsdb updateaka 02 fi if [ -n "$adddead" -a -r $dead ] then echo "Adding dead" explist 03 $dead | $greper | sort -t\| -f +0 -1 +1 -2 > $deaddb updateaka 03 fi if [ -n "$adddir" -a -r $directs ] then echo "Adding directors" explist 04 $directs | $greper | sort -t\| -f +0 -1 +1 -2 > $dirdb updateaka 04 fi if [ -n "$addwrite" -a -r $writers ] then echo "Adding writers" explist 05 $writers | $greper | sort -t\| -f +0 -1 +1 -2 > $writedb updateaka 05 fi if [ -n "$addcomp" -a -r $composers ] then echo "Adding composers" explist 06 $composers | $greper | sort -t\| -f +0 -1 +1 -2 > $compdb updateaka 06 fi if [ -n "$addcine" -a -r $cine ] then echo "Adding cinematographers" explist 07 $cine | $greper | sort -t\| -f +0 -1 +1 -2 > $cinedb updateaka 07 fi if [ -n "$addrate" -a -r $ratings ] then echo "Adding Movie Ratings Report" 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 |\ tr [A-Z] [a-z] > $tmp if [ -r $mrrcors ] then sed -f $mrrcors $tmp | sort -u +0.22 > $ratedb else sort -u +0.22 $tmp > $ratedb fi rm -f $tmp fi if [ -n "$addaka" -a -r $akafile ] then echo "Adding aka file" awk -F\| '{print "AK|" $1 "|" $2}' $akafile > $akalist updateaka AK fi if [ -n "$addmovie" -a -r $moviedb ] then echo "Sorting movies list" sort -t\| -f +0 -1 -o $moviedb $moviedb 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 if [ ! -r $compdb ] then touch $compdb fi if [ ! -r $cinedb ] then touch $cinedb fi if [ ! -r $akadb ] then touch $akadb fi if [ ! -r $ratedb ] then touch $ratedb fi @EOF set `wc -lwc lindex <<'@EOF' #!/bin/sh # Script : lindex version 2.3 # Purpose: Index list databases # Author : Col Needham # Valid options: # # Database opts: # # -acr select actors in database # -acs select actresses in database # -dead select dead actors/actresses # -cast combines 3 options above # -dir select directors database # -write select writers database # -comp select composers database # -cine select cinematographers database # # Note: if no database options are given, the query is assumed to # apply to all the lists # # Index type opts: # # -name index names # -title index titles # -aka index aka database # -invaka inverted index of aka database # # Output opts: # # -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 # (not valid with -name) # -cat cat, use 'cat' to display results instead of 'more' # # Ratings Report opts: # # -mrr add movie ratings (only valid with -title) # -smrr add movie ratings & sort by average ratings (only valid with -title) # -vmrr add movie ratings & sort by total votes (only valid with -title) # # Year-of-release opts: # # -yr add year of release to a title index & sort chronologically # -yru add year of release to a title index # # -yrfrom use with -yr{u}, only list movies made during or after # -yrto use with -yr{u}, only list movies made upto and including # -yreq use with -yr{u}, only list movies made during # # Examples: # lindex -acr -name # lindex -dir -title # lindex -cast -name # lindex -acr -name -s "Michael" # lindex -title -s "Alien" # lindex -title -cine -yr # lindex -title -yr -yreq 1945 # lindex -title -yr -yrfrom 1920 -yrto 1925 PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" tmp2="$MOVIESTMPDIR/tmp2.$$" # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs akadb=aka.dbs cater=cat yrfrom=1800 yrto=9999 trap "rm -f $tmp $tmp2; exit" 1 2 15 # default pager for results pager=more # default grep command greper="grep -i" if [ $# -eq 0 ] then err=y fi # interpret options while [ -n "$1" ] do case $1 in -s) shift substring=$1 shift ;; -m) movies=y shift ;; -cat) pager=cat shift ;; -i) greper="grep" shift ;; -acr) listfile="$listfile $acrdb" shift ;; -acs) listfile="$listfile $acsdb" shift ;; -dead) listfile="$listfile $deaddb" shift ;; -cast) listfile="$listfile $acrdb $acsdb $deaddb" shift ;; -dir) listfile="$listfile $dirdb" shift ;; -write) listfile="$listfile $writedb" shift ;; -comp) listfile="$listfile $compdb" shift ;; -cine) listfile="$listfile $cinedb" shift ;; -title) title=y shift ;; -name) name=y shift ;; -vmrr) mrr=y movies=y msorter="sort +0.19 -0.24 -r +0.32" shift ;; -smrr) mrr=y movies=y msorter="sort +0.25 -0.30 -r +0.32" shift ;; -mrr) mrr=y movies=y msorter=cat shift ;; -yr) yr=y yrsorter="sort -t| -f +2 -3" shift ;; -yru) yr=y yrsorter=cat shift ;; -yrto) yrto=$2 yrange=y shift shift ;; -yrfrom) yrfrom=$2 yrange=y shift shift ;; -yreq) yrfrom=$2 yrto=$2 yrange=y shift shift ;; -invaka) invaka=y shift ;; -aka) aka=y shift ;; -a) shift substring=$1 name=y listfile="$acrdb $acsdb $deaddb" shift ;; -d) shift substring=$1 name=y listfile="$dirdb" shift ;; -w) shift substring=$1 name=y listfile="$writedb" shift ;; -c) shift substring=$1 name=y listfile="$compdb" shift ;; -ph) shift substring=$1 name=y listfile="$cinedb" shift ;; -t) shift substring=$1 title=y shift ;; *) echo "$1: unrecognized option" err=y shift ;; esac done # need one index option if [ -z "$aka$invaka$title$name$err" ] then echo "You must specify one of -title -name -aka -invaka" err=y fi # any errors? if [ -n "$err" ] then echo "usage: lindex {-acr -acs -dead -cast -dir -write -comp -cine}+" echo " [-name|-title|-aka|-invaka] [-m -i -cat -s ]" echo " [-mrr|-smrr|-vmrr|-yr|-yru]" echo " [-yreq ] [-yrfrom ] [-yrto ]" exit 1 fi # check for option mismatch if [ "$yr$mrr" = "yy" ] then echo "lindex: ratings report options not available with year options" exit 1 fi # if no databases specified, select 'em all! if [ -z "$listfile" ] then listfile="$acrdb $acsdb $deaddb $dirdb $writedb $compdb $cinedb" fi # index by name if [ -n "$name" ] then if [ -n "$substring" ] then $cater $listfile | awk -F\| '{print $1}' | $greper "$substring" | sort -u > $tmp else $cater $listfile | awk -F\| '{print $1}' | sort -u > $tmp fi fi # index by title if [ -n "$title" ] then if [ -n "$substring" ] then $cater $listfile | awk -F\| '{print $2}' | $greper "$substring" | sort -f -u > $tmp else $cater $listfile | awk -F\| '{print $2}' | sort -f -u > $tmp fi fi # index aka database if [ -n "$aka" ] then if [ -n "$substring" ] then $greper "^..|.*${substring}.*|" $akadb | awk -F\| '{print $2 " (aka " $3 ")"}' > $tmp else awk -F\| '{print $2 " (aka " $3 ")"}' $akadb > $tmp fi fi # index aka database (inverted) if [ -n "$invaka" ] then if [ -n "$substring" ] then $greper "^..|.*|.*${substring}" $akadb | awk -F\| '{print $3 " (aka " $2 ")"}' > $tmp else awk -F\| '{print $3 " (aka " $2 ")"}' $akadb > $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" ] then if [ -n "$mrr" ] then sort -f $tmp | mrr | $msorter | $pager else if [ -n "$yr" ] then if [ -z "$yrange" ] then yr < $tmp | $yrsorter | awk -F\| '{print $2}'| $pager else yr < $tmp | $yrsorter | awk -F\| '{if (($3 >= yrf) && ($3 <= yrt)) print $2}' yrf=$yrfrom yrt=$yrto - | $pager fi else sed -e 's/"/~/g' $tmp | sort | sed -e 's/~/"/g' | $pager fi fi else $pager $tmp fi if [ -s $tmp ] then rm $tmp exit 0 else rm $tmp exit 1 fi fi @EOF set `wc -lwc list <<'@EOF' #!/bin/sh # Script : list version 2.3 # Purpose: Search list databases # Author : Col Needham based on an idea by Grant Mason # with binary chop interface by Ken Kirkwood and Andrew Rae # Valid options: # # -a return list of movies with actor/actress # -d return list of movies directed by # -w return list of movies written by # -c return list of movies with score composed by # -ph return list of movies photographed by # # Note these options require an exact name/title match, for softer # matches see -s # # 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 case sensitive, check case in search with -a -t -d # -r raw mode, output results in full & unsorted (useful with -s) # -m movies only, don't display TV series information (not valid with -t) # -cat cat, use 'cat' to display results instead of 'more' # -noattr discard attribute field when displaying results # -mrr add movie ratings information # -smrr add movie ratings information & sort by average rating # -vmrr add movie ratings information & sort by number of votes # # -yr add year of release to results list & sort in chronological order # -yru add year of release & sort in alphabetical order # # Examples: # list -a "Biehn, Michael" # list -d "Cameron, James" # list -w "Cameron, James" # list -c "Herrmann, Bernard" # list -a "Biehn, Michael" -a "Paxton, Bill" # list -a "Biehn, Michael" -d "Cameron, James" PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" tmp2="$MOVIESTMPDIR/tmp2.$$" names="$MOVIESTMPDIR/tmp3.$$" # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs cater=cat # C name of binary chop executable prog bc_exe=bin_chop # C name and first arg of binary-chop prog bin_chop="$bc_exe i" trap "rm -f $tmp* $tmp2* $names; exit" 1 2 15 # default pager for results pager=more # default grep command greper="grep -i" # initialize counters scnt=0 actidx=0 lcount=0 # set default options raw=n substring=n movies=n attr=y err=n yr=n if [ $# -eq 0 ] then err=yes fi # interpret options while [ -n "$1" ] do case $1 in -s) substring=y shift ;; -m) movies=y shift ;; -r) raw=y shift ;; -cat) pager=cat shift ;; -yr) yr=y shift ;; -yru) yr=y yrunsort=y shift ;; -i) greper="grep" bin_chop="$bc_exe s" 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 ;; -c) shift composer=$1 scnt=`expr $scnt + 1` shift ;; -ph) shift cinephr=$1 scnt=`expr $scnt + 1` shift ;; -smrr) mrr=y movies=y msorter="sort +0.25 -0.30 -r +0.32" shift ;; -vmrr) mrr=y movies=y msorter="sort +0.19 -0.24 -r +0.32" shift ;; -mrr) mrr=y movies=y msorter=cat shift ;; -noattr) attr=n shift ;; *) echo "$1: unrecognized option" shift err=yes ;; esac done if [ $err = yes ] then echo "usage: list [-m -s -r -cat -i -mrr -smrr -yr -yru] [-a ]* [-d ]" echo " [-w ] [-c ] [-ph ]" rm -f $names exit 1 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" rm $names 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 # turn off attributes if > 1 search string if [ $scnt -gt 1 ] then attr=n fi if [ "$yr" = "y" -a "$raw" = "y" ] then echo "$0: -r not available with -yr" exit 1 fi # search for actor/actress? if [ $actidx -gt 0 ] then cat $names |\ ( lcount=0 while [ $lcount -lt $actidx ] do read cast case "${raw}${substring}${attr}" in nnn) $bin_chop "${cast}" $acrdb $acsdb $deaddb | awk -F\| '{print $2}' > "$tmp.$lcount" ;; nyn) $cater $acrdb $acsdb $deaddb | $greper "${cast}.*|.*|.*" | awk -F\| '{print $2}' > "$tmp.$lcount" ;; nny) $bin_chop "${cast}" $acrdb $acsdb $deaddb | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$lcount" ;; nyy) $cater $acrdb $acsdb $deaddb | $greper "${cast}.*|.*|.*" | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$lcount" ;; yn?) $bin_chop "${cast}" $acrdb $acsdb $deaddb > "$tmp.$lcount" ;; yy?) $cater $acrdb $acsdb $deaddb | $greper "${cast}.*|" > "$tmp.$lcount" ;; esac lcount=`expr $lcount + 1` done ) rm $names fi # search for director? if [ -n "$dir" ] then case "${raw}${substring}${attr}" in nnn) $bin_chop "${dir}" $dirdb | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;; nyn) $cater $dirdb | $greper "${dir}.*|.*|.*" | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;; nny) $bin_chop "${dir}" $dirdb | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$actidx" ;; nyy) $cater $dirdb | $greper "${dir}.*|.*|.*" | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$actidx" ;; yn?) $bin_chop "${dir}" $dirdb > "$tmp.$actidx" ;; yy?) $cater $dirdb | $greper "${dir}.*|" > "$tmp.$actidx" ;; esac actidx=`expr $actidx + 1` fi # search for writer? if [ -n "$write" ] then case "${raw}${substring}${attr}" in nnn) $bin_chop "${write}" $writedb | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;; nyn) $cater $writedb | $greper "${write}.*|.*|.*" | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;; nny) $bin_chop "${write}" $writedb | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$actidx" ;; nyy) $cater $writedb | $greper "${write}.*|.*|.*" | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$actidx" ;; yn?) $bin_chop "${write}" $writedb > "$tmp.$actidx" ;; yy?) $cater $writedb | $greper "${write}.*|.*|.*" > "$tmp.$actidx" ;; esac actidx=`expr $actidx + 1` fi # search for composer? if [ -n "$composer" ] then case "${raw}${substring}${attr}" in nnn) $bin_chop "${composer}" $compdb | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;; nyn) $cater $compdb | $greper "${composer}.*|.*|.*" | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;; nny) $bin_chop "${composer}" $compdb | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$actidx" ;; nyy) $cater $compdb | $greper "${composer}.*|.*|.*" | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$actidx" ;; yn?) $bin_chop "${composer}" $compdb > "$tmp.$actidx" ;; yy?) $cater $compdb | $greper "${composer}.*|" > "$tmp.$actidx" ;; esac actidx=`expr $actidx + 1` fi # search for cinematographer? if [ -n "$cinephr" ] then case "${raw}${substring}${attr}" in nnn) $bin_chop "${cinephr}" $cinedb | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;; nyn) $cater $cinedb | $greper "${cinephr}.*|.*|.*" | awk -F\| '{print $2}' | sort > "$tmp.$actidx" ;; nny) $bin_chop "${cinephr}" $cinedb | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$actidx" ;; nyy) $cater $cinedb | $greper "${cinephr}.*|.*|.*" | awk -F\| \ '{if (length ($3) > 0) print $2 " " $3;\ else print $2}' | sort > "$tmp.$actidx" ;; yn?) $bin_chop "${cinephr}" $cinedb > "$tmp.$actidx" ;; yy?) $cater $cinedb | $greper "${cinephr}.*|" > "$tmp.$actidx" ;; esac actidx=`expr $actidx + 1` fi # Output results of cast/director/writer/composer search if [ $scnt -gt 0 ] then # find titles common to all searches cp "$tmp.0" $tmp for i in $tmp.* do comm -12 $tmp $i > $tmp2 mv $tmp2 $tmp rm $i done sort -f -o $tmp $tmp # output results case "${movies}${raw}${yr}" in nnn) sed -e 's/"/~/g' $tmp | sort | sed -e 's/~/"/g' | $pager ;; nyn) $pager $tmp ;; ynn) if [ -n "$mrr" ] then grep -v '^"' $tmp | mrr | $msorter | $pager else grep -v '^"' $tmp | $pager fi ;; yyn) grep -v '|"' $tmp | $pager ;; nny) if [ -n "$yrunsort" ] then yr < $tmp | awk -F\| '{print $2}' | sed -e 's/"/~/g' | sort -f | sed -e 's/~/"/g' | $pager else yr < $tmp | sort -t\| -f +2 -3 | awk -F\| '{print $2}'| $pager fi ;; yny) grep -v '^"' $tmp | yr | sort -t\| -f +1 -2 | awk -F\| '{print $2}' | $pager esac # remove temporary file & exit with appropriate status if [ -s $tmp ] then rm $tmp exit 0 else rm $tmp exit 1 fi fi @EOF set `wc -lwc title <<'@EOF' #!/bin/sh # Script : title version 2.1 # Purpose: Search list databases for info on a particular title # Author : Col Needham # Valid options: # # -t list stars of movie <title>, director marked by (d), # writer (w), composer (m) & cinematographer (ph) # # -s substring, allow partial title match # -i case sensitive, check case in title search # -r raw mode, output results in full & unsorted (useful with -s) # -cat cat, use 'cat' to display results instead of 'more' # -aka check if title is an alternative title # -noattr discard attribute field when displaying results # -p plain, search for plain title (i.e. no "(TV)" or year information # is needed to get a match) # -yr display information from titles database at head of results # # -noacr don't search actors database # -noacs don't search actress database # -nodead don't search dead database # -nocast combination of the above three options # -nodir don't search directors database # -nowrite don't search writers database # -nocomp don't search composers database # -nocine don't search cinematographers database # -nocrew comibines -nodir -nowrite -nocomp -nocine # Examples: # title -t "Abyss, The" # # title -t "Aliens" -nocast PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" tmp2="$MOVIESTMPDIR/tmp2.$$" names="$MOVIESTMPDIR/tmp3.$$" # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs akadb=aka.dbs cater=cat trap "rm -f $tmp* $tmp2* $names; exit" 1 2 15 # default pager for results pager=more # default grep command greper="grep -i" # initialize counters lcount=0 tcnt=0 # set default options raw=n substring=n attr=y err=n plain=n if [ $# -eq 0 ] then err=yes fi # interpret options while [ -n "$1" ] do case $1 in -s) substring=y shift ;; -r) raw=y shift ;; -p) plain=y shift ;; -yr) yr=y shift ;; -cat) pager=cat shift ;; -i) greper="grep" shift ;; -t) shift echo $1 >> $names tcnt=`expr $tcnt + 1` shift ;; -noattr) attr=n shift ;; -nocine) cinedb=/dev/null shift ;; -nocomp) compdb=/dev/null shift ;; -nodir) dirdb=/dev/null shift ;; -nowrite) writedb=/dev/null shift ;; -nocast) acrdb=/dev/null acsdb=/dev/null deaddb=/dev/null shift ;; -noacr) acrdb=/dev/null shift ;; -noacs) acsdb=/dev/null shift ;; -nodead) deaddb=/dev/null shift ;; -nocrew) cinedb=/dev/null compdb=/dev/null dirdb=/dev/null writedb=/dev/null shift ;; -aka) aka=y shift ;; *) echo "$1: unrecognized option" shift err=yes ;; esac done if [ $err = yes ] then echo "usage: title [-s -r -cat -i -p -yr -noattr -aka -noacr -noacs -nodead -nocast" echo " -nodir -nowrite -nocine -nocomp -nocrew] -t <title>*" rm -f $names exit 1 fi # Check for "-r" with > 1 search string if [ "$raw" = "y" -a $tcnt -gt 1 ] then echo "$0: -r not available with more than one search string" rm $names exit 1 fi # turn off attributes if > 1 search string if [ $tcnt -gt 1 ] then attr=n fi # -r and -s are incompatible if [ "$substring$plain" = "yy" ] then echo "$0: -s incompatible with -p" rm $names exit 1 fi if [ $tcnt -gt 0 ] then cat $names |\ ( lcount=0 while [ $lcount -lt $tcnt ] do read title if [ -n "$aka" ] then if [ "$substring" = "y" ] then newtitle=`$greper "..|.*|.*${title}" $akadb |\ awk -F\| '{print $2; exit}'` else if [ "$plain" = "n" ] then newtitle=`$greper "..|.*|${title}$" $akadb |\ awk -F\| '{print $2; exit}'` else newtitle=`$greper -e "..|.*|${title}$" -e "..|.*|$title} (.*)|" $akadb |\ awk -F\| '{print $2; exit}'` fi fi if [ -n "$newtitle" ] then title=$newtitle echo "(aka $title)" else if [ "$substring" = "y" ] then newtitle=`$greper "..|.*${title}|" $akadb | \ awk -F\| '{print $3; exit}'` else if [ "$plain" = "n" ] then newtitle=`$greper "..|${title}|" $akadb | \ awk -F\| '{print $3; exit}'` else newtitle=`$greper -e "..|${title}|" -e "..|${title} (.*)|" $akadb | \ awk -F\| '{print $3; exit}'` fi fi if [ -n "$newtitle" ] then echo "(aka $newtitle)" fi fi fi if [ "$yr" = "y" ] then echo $title | yr | awk -F\| '{print $2 " " $4}' fi case "${raw}${substring}${attr}${plain}" in nnnn) $cater $dirdb | $greper "|${title}|" |\ awk -F\| '{print $1 " (d)"}' > $tmp.$lcount $cater $writedb | $greper "|${title}|" |\ awk -F\| '{print $1 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper "|${title}|" |\ awk -F\| '{print $1 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper "|${title}|" |\ awk -F\| '{print $1 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "|${title}|" |\ awk -F\| '{print $1}' | sort >> $tmp.$lcount ;; nynn) $cater $dirdb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 " (d)"}' > $tmp.$lcount $cater $writedb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1}' | sort >> $tmp.$lcount ;; nnyn) $cater $dirdb | $greper "|${title}|" |\ awk -F\| '{if (length($3) > 0) print $1 " (d) " $3;\ else print $1 " (d)"}' > $tmp.$lcount $cater $writedb | $greper "|${title}|" |\ awk -F\| '{if (length($3) > 0) print $1 " (w) " $3;\ else print $1 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper "|${title}|" |\ awk -F\| '{if (length($3) > 0) print $1 " (m) " $3;\ else print $1 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper "|${title}|" |\ awk -F\| '{if (length($3) > 0) print $1 " (ph) " $3;\ else print $1 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "|${title}|" |\ awk -F\| '{if (length($3) > 0) print $1 " " $3;\ else print $1}' | sort >> $tmp.$lcount ;; nyyn) $cater $dirdb | $greper "|.*${title}.*|" |\ awk -F\| '{if (length($3) > 0) print $1 " (d) " $3;\ else print $1 " (d)"}' > $tmp.$lcount $cater $writedb | $greper "|.*${title}.*|" |\ awk -F\| '{if (length($3) > 0) print $1 " (w) " $3;\ else print $1 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper "|.*${title}.*|" |\ awk -F\| '{if (length($3) > 0) print $1 " (m) " $3;\ else print $1 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper "|.*${title}.*|" |\ awk -F\| '{if (length($3) > 0) print $1 " (ph) " $3;\ else print $1 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "|.*${title}.*|" |\ awk -F\| '{if (length($3) > 0) print $1 " " $3;\ else print $1}' | sort >> $tmp.$lcount ;; yn?n) $cater $dirdb | $greper "|${title}|" |\ awk -F\| '{print $1 " (d)|" $2 "|" $3}' > $tmp.$lcount $cater $writedb | $greper "|${title}|" |\ awk -F\| '{print $1 " (w)|" $2 "|" $3}' >> $tmp.$lcount $cater $compdb | $greper "|${title}|" |\ awk -F\| '{print $1 " (m)|" $2 "|" $3}' >> $tmp.$lcount $cater $cinedb | $greper "|${title}|" |\ awk -F\| '{print $1 " (ph)|" $2 "|" $3}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "|${title}|" |\ awk -F\| '{print $1 "|" $2 "|" $3}' | sort >> $tmp.$lcount ;; yy?n) $cater $dirdb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 " (d)|" $2 "|" $3}' > $tmp.$lcount $cater $writedb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 " (w)|" $2 "|" $3}' >> $tmp.$lcount $cater $compdb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 " (m)|" $2 "|" $3}' >> $tmp.$lcount $cater $cinedb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 " (ph)|" $2 "|" $3}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "|.*${title}.*|" |\ awk -F\| '{print $1 "|" $2 "|" $3}' | sort >> $tmp.$lcount ;; nnny) $cater $dirdb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 " (d)"}' > $tmp.$lcount $cater $writedb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1}' | sort >> $tmp.$lcount ;; nnyy) $cater $dirdb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{if (length($3) > 0) print $1 " (d) " $3;\ else print $1 " (d)"}' > $tmp.$lcount $cater $writedb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{if (length($3) > 0) print $1 " (w) " $3;\ else print $1 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{if (length($3) > 0) print $1 " (m) " $3;\ else print $1 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{if (length($3) > 0) print $1 " (ph) " $3;\ else print $1 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{if (length($3) > 0) print $1 " " $3;\ else print $1}' | sort >> $tmp.$lcount ;; yn?y) $cater $dirdb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 " (d)|" $2 "|" $3}' > $tmp.$lcount $cater $writedb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 " (w)|" $2 "|" $3}' >> $tmp.$lcount $cater $compdb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 " (m)|" $2 "|" $3}' >> $tmp.$lcount $cater $cinedb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 " (ph)|" $2 "|" $3}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper -e "|${title}|" -e "|${title} (.*)|" |\ awk -F\| '{print $1 "|" $2 "|" $3}' | sort >> $tmp.$lcount ;; esac if [ $tcnt -gt 1 ] then sort -o $tmp.$lcount $tmp.$lcount fi lcount=`expr $lcount + 1` done ) if [ "$yr" = "y" ] then echo fi rm $names # output results if [ $tcnt -gt 0 ] then # find names common to all searches cp "$tmp.0" $tmp if [ $tcnt -gt 1 ] then for i in $tmp.* do comm -12 $tmp $i > $tmp2 mv $tmp2 $tmp rm $i done else rm "$tmp.0" fi $pager $tmp # remove temporary file & exit with appropriate status if [ -s $tmp ] then rm $tmp exit 0 else rm $tmp exit 1 fi fi fi @EOF set `wc -lwc <title` if test $1$2$3 != 370173212727 then echo ERROR: wc results of title are $* should be 370 1732 12727 fi chmod 750 title echo x - listall cat >listall <<'@EOF' #!/bin/sh # Script: listall version 2.2 # Purpose: list all other appearances by the cast/crew of a particular movie # Author: Col Needham <cn@otter.hpl.hp.com> PATH=.:$PATH; export PATH pager='more' while [ -n "$1" ] do case $1 in -cat) pager=cat shift ;; *) break ;; esac done if [ $# -ne 1 ] then echo "usage: listall [-cat] <title>" exit 1 fi title -noattr -t "$1" -aka |\ ( read iline while [ -n "$iline" ] do if [ "4" -ne "`expr "$iline" : \(aka`" ] then 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 comp=`expr "$iline" : '\(.*\) (m)' \| "$iline"` if [ "$iline" != "$comp" ] then list -c "$comp" else cine=`expr "$iline" : '\(.*\) (ph)' \| "$iline"` if [ "$iline" != "$cine" ] then list -ph "$cine" else list -a "$iline" fi fi fi fi echo else echo "----------------------------------------------------------------------------" echo $iline echo fi read iline done ) | $pager @EOF set `wc -lwc <listall` if test $1$2$3 != 681841451 then echo ERROR: wc results of listall are $* should be 68 184 1451 fi chmod 750 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 <cn@otter.hpl.hp.com> * * titlecpy bug fix by Don Porter <dgp@saturn.wustl.edu> * */ #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'); if (isupper(s[i])) t[i]=tolower(s[i]); else t[i]=s[i]; 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 */ int sts=1; /* status flag */ FILE *fopen(), *fp; fp = fopen("ratings.dbs","r"); /* open MRR database */ fgets(ratings,120,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); sts=0; } } return(sts); } @EOF set `wc -lwc <mrr.c` if test $1$2$3 != 722311945 then echo ERROR: wc results of mrr.c are $* should be 72 231 1945 fi chmod 640 mrr.c echo x - ltrace cat >ltrace <<'@EOF' #!/bin/sh # Script: ltrace version 2.3 # Purpose: Give details of all movies a person was involved with # Author: Col Needham <cn@otter.hpl.hp.com> # options: # # -a search for actor/actress # -d search for director # -w search for writer # -c search for composer # -ph search for cinematographer # # -yr add year data & sort results in chronological order # -yru add year data & sort in alphabetic order # -m movies only, ignore TV series # -i case sensitive PATH=.:$PATH; export PATH # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs akadb=aka.dbs cater=cat moviegreper="cat" greper="grep -i" pager=more if [ $# -eq 0 ] then err=y fi # interpret options while [ -n "$1" ] do case $1 in -a) listdb="$acrdb $acsdb $deaddb" shift name=$1 shift ;; -d) listdb="$dirdb" shift name=$1 shift ;; -w) listdb="$writedb" shift name=$1 shift ;; -c) listdb="$compdb" shift name=$1 shift ;; -ph) listdb="$cinedb" shift name=$1 shift ;; -i) greper="grep" shift ;; -yr) yropt="-yr" shift ;; -yru) yropt="-yr" yrunsort="y" shift ;; -m) moviegreper='grep -v |"' shift ;; -cat) pager=cat shift ;; *) err=y shift ;; esac done if [ "$err" = "y" ] then echo "usage: ltrace [-a -d -w -c -ph] <name> [-yr -yru -m -i -cat]" exit 1 fi ( if [ -n "$yropt" -a -z "$yrunsort" ] then $cater $listdb | $greper "^${name}|" | $moviegreper | awk -F\| '{print $2}' |\ sort -f | yr | sort -t\| -f +2 -3 | awk -F\| '{print $1}' else $cater $listdb | $greper "^${name}|" | $moviegreper | awk -F\| '{print $2}' fi ) |\ ( read iline while [ -n "$iline" ] do echo "----------------------------------------------------------------------------" if [ -z "$yropt" ] then echo $iline echo title -cat -t "$iline" else title -cat -t "$iline" -yr fi echo read iline done ) | $pager @EOF set `wc -lwc <ltrace` if test $1$2$3 != 1113032054 then echo ERROR: wc results of ltrace are $* should be 111 303 2054 fi chmod 750 ltrace echo x - updateaka cat >updateaka <<'@EOF' #!/bin/sh # Script: updateaka version 2.3 # Purpose: update aka database # Author: Col Needham <cn@otter.hpl.hp.com> # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" akalist=akalist akadb=aka.dbs trap "rm -f $tmp; exit" 1 2 15 if [ ! -r $akadb ] then touch $akadb fi if [ ! -r $akalist ] then touch $akalist fi sort -u -o akalist $akalist grep -v "^$1" $akadb > $tmp cat $akalist $tmp > $akadb sort -u +0.3 $akadb | sort -f -t\| +1 -2 -o $akadb rm $tmp $akalist @EOF set `wc -lwc <updateaka` if test $1$2$3 != 3998595 then echo ERROR: wc results of updateaka are $* should be 39 98 595 fi chmod 750 updateaka echo x - akaextract.awk cat >akaextract.awk <<'@EOF' { x=index($2, "(aka"); if (x) { y=x+1; nest=1; char=" " while (nest && char != "") { char=substr($2, y, 1); if (char=="(") nest++; if (char==")") nest--; y++;} if (nest==0) print id "|" substr($2, 1, x-2) "|" substr($2, x+5, y-x-6) >> "akalist" print $1 "|" substr($2, 1, x-2) substr($2, y, 80)} else print $0 } @EOF set `wc -lwc <akaextract.awk` if test $1$2$3 != 1354359 then echo ERROR: wc results of akaextract.awk are $* should be 13 54 359 fi chmod 640 akaextract.awk echo x - attribute.awk cat >attribute.awk <<'@EOF' { x=index($2, "(") if (x) { y=index($2, "(TV)"); offset=3; if (y==0) { y=index($2, "(V)"); offset=2 }; if (y==0) { y=index($2, "(mini)"); offset=5 }; if (y==0) { y=index($2, "(19"); if (y != 0) {offset=index(substr($2,y,10), ")") - 1 } }; if (y==0) { y=x; offset=-2 }; print $1 "|" substr($2, 1, y+offset) "|" substr($2, y+offset+2, 80) } else print $0 "|" } @EOF set `wc -lwc <attribute.awk` if test $1$2$3 != 1260393 then echo ERROR: wc results of attribute.awk are $* should be 12 60 393 fi chmod 640 attribute.awk echo x - alist cat >alist <<'@EOF' #!/bin/sh # Script : alist version 2.3 # Purpose: search attributes of list databases # Author : Col Needham <cn@otter.hpl.hp.com> # Valid options: # # Datbase opts: # # -acr search actors database # -acs search actresses database # -dead search dead actors/actresses database # -cast combines 3 options above # -dir search directors database # -write search writers database # -comp search composers database # -cine search cinematographers database # # Note: the database options can be used in any combination # e.g. -acr -dir = search actors & directors databases # # if no database options are given, all databases are searched # # Search options: # # -attr <pattern> search attribute field for <pattern> # -aa search attribute field for academy award winners # -aan search attribute field for academy award nominees # -gg search attribute field for golden globe award winners # -ggn search attribute field for golden globe award nominees # -n <name> apply attribute search to entries matching <name> # -t <title> apply attribute search to movies called <title> # # Note: -aa and -aan can be used together or # -gg and -ggn can be used together # # Output options: # # -r raw, do not format output # -s substring, allow partial matches with -n and -t # -i become case sensitive in searches # -m movies only, don't display TV series information # -cat cat, use 'cat' to display results instead of 'more' # # -yr add year information and sort chronologically # -yru add year information# -yru add year information # # Examples: # # alist -cast -aa # -- list all academy award winners in the cast databases # # alist -acr -aa -aan -n "DeNiro, Robert" # -- list all of DeNiro's academy award nominations/wins # # alist -aan -t "Color Purple, The" # -- list all the nominations for The Color Purple # # alist -attr "(novel)" -write -n "Chandler, Raymond" # -- list all the films based on Chandler novels # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" tmp2="$MOVIESTMPDIR/tmp2.$$" # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs trap "rm -f $tmp $tmp2; exit" 1 2 15 # default pager for results pager=more # default grep command greper="grep -i" cater=cat listdb="" if [ $# -eq 0 ] then echo "usage: alist [-acr -acs -dead -cast -dir -write -comp -cine" echo " -attr <string> -n <name> -t <title> -aa -aan" echo " -m -cat -i -s -r -yr -yru]" exit 1 fi # interpret options while [ -n "$1" ] do case $1 in -attr) shift attr=$1 shift ;; -m) movies=y shift ;; -cat) pager=cat shift ;; -i) greper="grep" shift ;; -s) substring=y shift ;; -r) raw=y shift ;; -n) shift name=$1 shift ;; -t) shift title=$1 shift ;; -aa) aa=y attr='(.*AA)' shift ;; -aan) aan=y attr='(.*AAN)' shift ;; -gg) gg=y attr='(.*GG)' shift ;; -ggn) ggn=y attr='(.*GGN)' shift ;; -acr) listfile="$listfile $acrdb" shift ;; -acs) listfile="$listfile $acsdb" shift ;; -dead) listfile="$listfile $deaddb" shift ;; -cast) listfile="$listfile $acrdb $acsdb $deaddb" shift ;; -dir) listfile="$listfile $dirdb" shift ;; -write) listfile="$listfile $writedb" shift ;; -comp) listfile="$listfile $compdb" shift ;; -cine) listfile="$listfile $cinedb" shift ;; -yr) yr=y yrsort=y shift ;; -yru) yr=y shift ;; *) echo "$1: unrecognized option" echo "usage: alist [-acr -acs -dead -cast -dir -write -comp -cine" echo " -attr <string> -n <name> -t <title> -aa -aan" echo " -m -cat -i -s -r -yr -yru]" exit 1 ;; esac done if [ ! -n "$listfile" ] then listfile="$acrdb $acsdb $deaddb $dirdb $writedb $compdb" fi if [ "$aa$aan" = "yy" ] then attr='(.*AAN*)' fi if [ "$gg$ggn" = "yy" ] then attr='(.*GGN*)' fi if [ -n "$substring" ] then $cater $listfile | awk -F\| '{if (length($3)) print}' | $greper "${name}.*|.*${title}.*|.*$attr" | sort -u > $tmp else $cater $listfile | awk -F\| '{if (length($3)) print}' | $greper "^${name:-.*}|${title:-.*}|.*$attr" | sort -u > $tmp fi # output results if [ -r $tmp ] then # remove TV info? if [ -n "$movies" ] then grep -v '|".*|' $tmp > $tmp2 mv $tmp2 $tmp fi if [ -n "$yr" ] then sort -t\| -f +1 -2 $tmp | yrf > $tmp2 mv $tmp2 $tmp fi if [ -n "$raw" ] then $pager $tmp else if [ -z "$yrsort" ] then sed -e 's/"/~/g' $tmp | sort | sed -e 's/~/"/g' | awk -F\| -f format.awk | $pager else sort -t\| +3 -4 +1 -2 $tmp | awk -F\| -f alist.awk | $pager fi fi if [ -s $tmp ] then rm $tmp exit 1 else rm $tmp exit 0 fi fi @EOF set `wc -lwc <alist` if test $1$2$3 != 2247775100 then echo ERROR: wc results of alist are $* should be 224 777 5100 fi chmod 750 alist echo x - alist.awk cat >alist.awk <<'@EOF' BEGIN {name=""} { if ( $4 != name ) { if ( NR > 1 ) print "" name=$4; } le=length($1); if ( le >= 16 ) { if ( length ($3) ) printf "%s\t%s %s\n", $1, $2, $3; else printf "%s\t%s\n", $1, $2; } else if ( le >= 8 ) { if ( length ($3) ) printf "%s\t\t%s %s\n", $1, $2, $3; else printf "%s\t\t%s\n", $1, $2; } else { if ( length ($3) ) printf "%s\t\t\t%s %s\n", $1, $2, $3; else printf "%s\t\t\t%s\n", $1, $2; } } @EOF set `wc -lwc <alist.awk` if test $1$2$3 != 1990476 then echo ERROR: wc results of alist.awk are $* should be 19 90 476 fi chmod 640 alist.awk echo x - mkballot cat >mkballot <<'@EOF' #!/bin/sh # Script: mkballot version 1.95 # Purpose: Generate a movie ratings report ballot for a particular person # Author: Col Needham <cn@otter.hpl.hp.com> PATH=.:$PATH; export PATH if [ $# -ne 2 ] then echo "usage: mkballot [-a -d -w -c -ph] <name>" fi list "$1" "$2" -noattr -m | sed -e 's/ (TV)//' -e 's/ (V)//' -e 's/^/vote /' > ballot @EOF set `wc -lwc <mkballot` if test $1$2$3 != 1661356 then echo ERROR: wc results of mkballot are $* should be 16 61 356 fi chmod 750 mkballot echo x - lguide cat >lguide <<'@EOF' #!/bin/sh # Script : lguide version 2.3 # Purpose: read a file of titles & output all the details known on each film # Author : Col Needham <cn@otter.hpl.hp.com> PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi guide="$MOVIESTMPDIR/tmp.$$" tmp="$MOVIESTMPDIR/tmp1.$$" trap "rm -f $tmp $guide; exit" 1 2 15 # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs mgopts="-mrr" pager=more # interpret options while [ -n "$1" ] do case $1 in -aka) mgopts="-aka ${mgopts}" aka=y shift ;; -yru) mgopts="-yru ${mgopts}" shift ;; -f) shift tfile=$1 shift ;; -cat) pager=cat shift ;; *) echo "$1: unrecognized option" shift err=yes ;; esac done if [ -z "$tfile" ] then err="y" fi if [ -n "$err" ] then echo "usage: lguide [-yru -aka -cat] -f <file>" exit 1 fi if [ ! -r $tfile ] then echo "lguide: title file not readable" exit 1 fi if [ -n "$aka" ] then akamap < $tfile | sort -u -o $tmp else sort -u -o $tmp $tfile fi awk -F\| '{print $1 "|" $2 "|" $3 "|5"}' $acrdb | sort -t\| +1 -2 |\ join -t\| -j1 2 -o 1.1 1.2 1.3 1.4 - $tmp > $guide awk -F\| '{print $1 "|" $2 "|" $3 "|5"}' $acsdb | sort -t\| +1 -2 |\ join -t\| -j1 2 -o 1.1 1.2 1.3 1.4 - $tmp >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|5"}' $deaddb | sort -t\| +1 -2 |\ join -t\| -j1 2 -o 1.1 1.2 1.3 1.4 - $tmp >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|1"}' $dirdb | sort -t\| +1 -2 |\ join -t\| -j1 2 -o 1.1 1.2 1.3 1.4 - $tmp >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|2"}' $writedb | sort -t\| +1 -2 |\ join -t\| -j1 2 -o 1.1 1.2 1.3 1.4 - $tmp >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|3"}' $compdb | sort -t\| +1 -2 |\ join -t\| -j1 2 -o 1.1 1.2 1.3 1.4 - $tmp >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|4"}' $cinedb | sort -t\| +1 -2 |\ join -t\| -j1 2 -o 1.1 1.2 1.3 1.4 - $tmp >> $guide awk '{print "|" $0 "||0"}' $tmp >> $guide sort -t\| -f +1 -2 +3 -4 -o $guide $guide mgde $mgopts < $guide | $pager rm $guide $tmp @EOF set `wc -lwc <lguide` if test $1$2$3 != 984112193 then echo ERROR: wc results of lguide are $* should be 98 411 2193 fi chmod 750 lguide echo x - format.awk cat >format.awk <<'@EOF' BEGIN {name=""} { if ( $1 == name ) { if ( length ( $3 ) ) printf "\t\t\t%s %s\n", $2, $3; else printf "\t\t\t%s\n", $2 } else { if ( NR > 1 ) print "" name=$1; le=length($1); if ( le >= 16 ) { if ( length ($3) ) printf "%s\t%s %s\n", $1, $2, $3; else printf "%s\t%s\n", $1, $2; } else if ( le >= 8 ) { if ( length ($3) ) printf "%s\t\t%s %s\n", $1, $2, $3; else printf "%s\t\t%s\n", $1, $2; } else { if ( length ($3) ) printf "%s\t\t\t%s %s\n", $1, $2, $3; else printf "%s\t\t\t%s\n", $1, $2; } } } @EOF set `wc -lwc <format.awk` if test $1$2$3 != 23109581 then echo ERROR: wc results of format.awk are $* should be 23 109 581 fi chmod 640 format.awk echo x - bin_chop.c cat >bin_chop.c <<'@EOF' /* * * Program : bin_chop * * Purpose : To speedup search on sorted movie database files using * binary chop algorithm * * Authors : Ken Kirkwood ken@cs.strath.ac.uk * Andrew Rae drew@cs.strath.ac.uk * (internet : via nsfnet-relay.ac.uk) * * Date : 20th September 1991 * * Searches one or more streams for lines whose first * field matches a specified pattern * * Usage : bin_chop [s|i] pattern stream1 stream2 stream3 ... * * argument 1 must be either "s" or "i" * s implies case sensitivity * i implies case insensitivity * * argument 2 is a string (no wildcards) to * be searched for * * arguments 3, 4, etc are each streamnames * of streams to be searched. Files * must be sorted properly * * ASSUMPTIONS: * * Each of the streams to be searched is sorted * in the following order (defined using UNIX sort) * sort -t\| -f +0 -1 * * Each line in the stream must be 200 chars or less long */ #include <stdio.h> #include <ctype.h> #define TRUE (1==1) #define FALSE (0==1) #define FIELD_SEPARATOR '|' #define MAX_LINE_LEN 200 #define MAX_FIELD_LEN MAX_LINE_LEN main(argc, argv) int argc; char *argv[]; { FILE *stream; int i; int cs; if (argc < 4) return; switch (argv[1][0]) { case 's' : cs = TRUE; break; case 'i' : cs = FALSE; break; default : cs = FALSE; break; } for (i=3; i < argc; i++) { stream = fopen(argv[i], "r"); if (stream == NULL) (void) fprintf(stderr, "Cant open %s\n", argv[i]); else { print_matches (stream, argv[2], cs); (void) fclose(stream); } } } myseek (stream, offset) FILE *stream; long offset; { if (fseek (stream, offset, 0) == -1) (void) printf("fseek error : offset = %ld\n", offset); } long find_prev (stream, pos) FILE *stream; long pos; { int ch; if (pos > 0) { do { pos--; myseek(stream, pos); ch = fgetc(stream); } while ((ch != '\n') && (ch != EOF) && (pos > 0)); if (pos != 0) pos++; else myseek(stream, pos); } else { pos = 0; myseek(stream, pos); } return pos; } int myread (stream, line, field) FILE *stream; char *line; char *field; { int infield; int linx, finx; int ch; linx = 0; finx = 0; infield = TRUE; while (((ch = fgetc(stream)) != '\n') && (ch != EOF)) { line[linx++] = ch; if (infield == TRUE) { if (ch == FIELD_SEPARATOR) infield = FALSE; else field[finx++]=ch; } } line[linx] = '\0'; field[finx] = '\0'; if (ch == EOF) return 1; else return 0; } /* compare two strings in the same manner as strcmp except allow case insensitive comparison when argument c = FALSE return 0 if s1==s2 return > 0 if s1 > s1 return < 0 if s1 > s1 */ int cmp (s1, s2, c) char *s1, *s2; int c; { char cp1[MAX_FIELD_LEN+1], cp2[MAX_FIELD_LEN+1]; char *ch1, *ch2; int res; if (c == FALSE) { for (ch2=cp1, ch1=s1; *ch1 != '\0'; ch1++, ch2++) *ch2 = isupper(*ch1) ? tolower(*ch1) : *ch1 ; *ch2 = '\0'; for (ch2=cp2, ch1=s2; *ch1 != '\0'; ch1++, ch2++) *ch2 = isupper(*ch1) ? tolower(*ch1) : *ch1 ; *ch2 = '\0'; res = strcmp(cp1, cp2); } else res = strcmp(s1, s2); return res; } /* search 'stream' for lines whose first field matches 'search_string' */ int print_matches (stream, search_string, case_sens) FILE *stream; char *search_string; int case_sens; { long match_pos, find_match(); int cmp_res; char line[MAX_LINE_LEN+1], field[MAX_FIELD_LEN+1]; match_pos = find_match(search_string, stream); if (match_pos >= 0) { do{ match_pos = find_prev (stream, match_pos-1); if (myread (stream, line, field)) break; cmp_res = cmp (search_string, field, FALSE); } while ((cmp_res == 0) && (match_pos > 0)); if (match_pos <= 0) (void) fseek (stream, 0l, 0); do{ if (myread (stream, line, field) == 1) break; cmp_res = cmp (search_string, field, case_sens); if (cmp_res == 0) (void) printf("%s\n", line); if (case_sens) cmp_res = cmp (search_string, field, FALSE); } while (cmp_res == 0); } } /* find offset of a line within 'stream' which has first field matching 'seach_string'. search is always case insensitive and is by binary chop */ long find_match (search_string, stream) char *search_string; /* string to be searched for */ FILE *stream; /* stream in which to search */ { char line[MAX_LINE_LEN+1], field[MAX_FIELD_LEN+1]; long mid, lo, up; int cmp_res; int found; found = FALSE; /* get stream size */ (void) fseek (stream, 0l, 2); up = ftell(stream); lo = 0l; while (!found && up >= lo) { mid = (up+lo)/2; mid = find_prev (stream, mid); if (myread (stream, line, field)) break; cmp_res = cmp (search_string, field, FALSE); if (cmp_res == 0) found = TRUE; else if (cmp_res > 0) lo = mid+strlen(line)+1; else up = mid-1; } if (!found) mid = -1; return mid; } @EOF set `wc -lwc <bin_chop.c` if test $1$2$3 != 2687815518 then echo ERROR: wc results of bin_chop.c are $* should be 268 781 5518 fi chmod 640 bin_chop.c echo x - linstall cat >linstall <<'@EOF' #!/bin/sh # Script : install version 2.3 # Purpose: Installs database software # Author : Col Needham <cn@otter.hpl.hp.com> # Valid options: # database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs ratedb=ratings.dbs akadb=aka.dbs movdb=movies.dbs # set default options err=n # interpret options while [ -n "$1" ] do case $1 in -fast) echo "Only the fast version is supplied now: this option is redundant" shift ;; -std) echo "Only the fast version is supplied now: this option is redundant" shift ;; -update) upd=y shift ;; *) echo "$1: unrecognized option" shift err=yes ;; esac done if [ $err = yes ] then echo "usage: install [-update]" exit 1 fi if [ -n "$upd" ] then if [ -r $acrdb ] then sort -t\| -f +0 -1 +1 -2 -o $acrdb $acrdb fi if [ -r $acsdb ] then sort -t\| -f +0 -1 +1 -2 -o $acsdb $acsdb fi if [ -r $deaddb ] then sort -t\| -f +0 -1 +1 -2 -o $deaddb $deaddb fi if [ -r $dirdb ] then sort -t\| -f +0 -1 +1 -2 -o $dirdb $dirdb fi if [ -r $writedb ] then sort -t\| -f +0 -1 +1 -2 -o $writedb $writedb fi if [ -r $compdb ] then sort -t\| -f +0 -1 +1 -2 -o $compdb $compdb fi if [ -r $cinedb ] then sort -t\| -f +0 -1 +1 -2 -o $cinedb $cinedb fi if [ -r $akadb ] then sort -f -t\| +1 -2 -o $akadb $akadb fi if [ -r $movdb ] then sort -f -t\| +0 -1 -o $movdb $movdb fi fi echo "Compiling C code for list script" cc -o bin_chop bin_chop.c echo "Compiling C code for Movie Ratings Report link" cc -o mrr mrr.c echo "Compiling C code for Titles Database" cc -o yr yr.c cc -o yrf yrf.c echo "Compiling C code for mguide script" cc -o mgde mgde.c echo "Compiling C code for lguide script" cc -o akamap akamap.c echo "Installation Complete" @EOF set `wc -lwc <linstall` if test $1$2$3 != 1113291889 then echo ERROR: wc results of linstall are $* should be 111 329 1889 fi chmod 750 linstall echo x - person cat >person <<'@EOF' #!/bin/sh # Script : person version 2.1 # Purpose: Search list databases for info on a particular person. # Author : Philippe Queinnec <queinnec@cenatls.cena.dgac.fr> # based on a script by Col Needham <cn@otter.hpl.hp.com> # Valid options: # # -n <name> list info about <name>, director marked by (d), # writer (w), composer (m) & cinematographer (ph) # # -s substring, allow partial name match # -i case sensitive, check case in name search # -r raw mode, output results in full & unsorted (useful with -s) # -cat cat, use 'cat' to display results instead of 'more' # -noattr discard attribute field when displaying results # # -yr add year information & sort in chronological order # -yru add year information but leave in alphabetical order # # -noacr don't search actors database # -noacs don't search actress database # -nodead don't search dead database # -nocast combination of the above three options # -nodir don't search directors database # -nowrite don't search writers database # -nocomp don't search composers database # -nocine don't search cinematographers database # -nocrew comibines -nodir -nowrite -nocomp -nocine # Examples: # person -n "Jarmusch, Jim" # person -n "Welles, Orson" -nocast # person -n "Jarmusch, Jim" -n "Waits, tom" # person -n "Biehn, Michael" -n "Paxton, Bill" -nocrew # person -n "Biehn, Michael" -n "Cameron, James" PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" tmp2="$MOVIESTMPDIR/tmp2.$$" names="$MOVIESTMPDIR/tmp3.$$" # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs akadb=aka.dbs cater=cat trap "rm -f $tmp* $tmp2* $names; exit" 1 2 15 # default pager for results pager=more # default grep command greper="grep -i" # initialize counters lcount=0 tcnt=0 # set default options raw=n substring=n attr=y err=n info=y movies=n yr=n if [ $# -eq 0 ] then err=yes fi # interpret options while [ -n "$1" ] do case $1 in -s) substring=y shift ;; -m) movies=y shift ;; -r) raw=y shift ;; -cat) pager=cat shift ;; -yr) yr=y shift ;; -yru) yr=y yrunsort=y shift ;; -i) greper="grep" shift ;; -n) shift echo $1 >> $names tcnt=`expr $tcnt + 1` shift ;; -noattr) attr=n shift ;; -nocine) cinedb=/dev/null shift ;; -nocomp) compdb=/dev/null shift ;; -nodir) dirdb=/dev/null shift ;; -nowrite) writedb=/dev/null shift ;; -nocast) acrdb=/dev/null acsdb=/dev/null deaddb=/dev/null shift ;; -noacr) acrdb=/dev/null shift ;; -noacs) acsdb=/dev/null shift ;; -nodead) deaddb=/dev/null shift ;; -nocrew) cinedb=/dev/null compdb=/dev/null dirdb=/dev/null writedb=/dev/null shift ;; *) echo "$1: unrecognized option" shift err=yes ;; esac done if [ $err = yes ] then echo "usage: person [-s -r -cat -i -yr -yru -noattr -noacr -noacs -nodead -nocast" echo " -nodir -nowrite -nocine -nocomp -nocrew] -n <name>*" rm -f $names exit 1 fi # Check for "-r" with > 1 search string if [ "$raw" = "y" -a $tcnt -gt 1 ] then echo "$0: -r not available with more than one search string" rm $names exit 1 fi # turn off attributes if > 1 search string if [ $tcnt -gt 1 ] then attr=n info=n fi if [ "$yr" = "y" -a "$raw" = "y" ] then echo "$0: -r not available with -yr" exit 1 fi if [ $tcnt -gt 0 ] then cat $names |\ ( lcount=0 while [ $lcount -lt $tcnt ] do read person case "${raw}${substring}${attr}${info}" in nnny) $cater $dirdb | $greper "^${person}|" |\ awk -F\| '{print $2 " (d)"}' > $tmp.$lcount $cater $writedb | $greper "^${person}|" |\ awk -F\| '{print $2 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper "^${person}|" |\ awk -F\| '{print $2 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper "^${person}|" |\ awk -F\| '{print $2 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "^${person}|" |\ awk -F\| '{print $2}' | sort >> $tmp.$lcount ;; nyny) $cater $dirdb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2 " (d)"}' > $tmp.$lcount $cater $writedb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2}' | sort >> $tmp.$lcount ;; nnyy) $cater $dirdb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " (d) " $3;\ else print $2 " (d)"}' > $tmp.$lcount $cater $writedb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " (w) " $3;\ else print $2 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " (m) " $3;\ else print $2 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " (ph) " $3;\ else print $2 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' | sort >> $tmp.$lcount ;; nyyy) $cater $dirdb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " (d) " $3;\ else print $2 " (d)"}' > $tmp.$lcount $cater $writedb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " (w) " $3;\ else print $2 " (w)"}' >> $tmp.$lcount $cater $compdb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " (m) " $3;\ else print $2 " (m)"}' >> $tmp.$lcount $cater $cinedb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " (ph) " $3;\ else print $2 " (ph)"}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' | sort >> $tmp.$lcount ;; yn??) $cater $dirdb | $greper "^${person}|" |\ awk -F\| '{print $1 " (d)|" $2 "|" $3}' > $tmp.$lcount $cater $writedb | $greper "^${person}|" |\ awk -F\| '{print $1 " (w)|" $2 "|" $3}' >> $tmp.$lcount $cater $compdb | $greper "^${person}|" |\ awk -F\| '{print $1 " (m)|" $2 "|" $3}' >> $tmp.$lcount $cater $cinedb | $greper "^${person}|" |\ awk -F\| '{print $1 " (ph)|" $2 "|" $3}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "^${person}|" |\ awk -F\| '{print $1 "|" $2 "|" $3}' | sort >> $tmp.$lcount ;; yy??) $cater $dirdb | $greper "${person}.*|" |\ awk -F\| '{print $1 " (d)|" $2 "|" $3}' > $tmp.$lcount $cater $writedb | $greper "${person}.*|" |\ awk -F\| '{print $1 " (w)|" $2 "|" $3}' >> $tmp.$lcount $cater $compdb | $greper "${person}.*|" |\ awk -F\| '{print $1 " (m)|" $2 "|" $3}' >> $tmp.$lcount $cater $cinedb | $greper "${person}.*|" |\ awk -F\| '{print $1 " (ph)|" $2 "|" $3}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "${person}.*|" |\ awk -F\| '{print $1 "|" $2 "|" $3}' | sort >> $tmp.$lcount ;; nnnn) $cater $dirdb | $greper "^${person}|" |\ awk -F\| '{print $2}' > $tmp.$lcount $cater $writedb | $greper "^${person}|" |\ awk -F\| '{print $2}' >> $tmp.$lcount $cater $compdb | $greper "^${person}|" |\ awk -F\| '{print $2}' >> $tmp.$lcount $cater $cinedb | $greper "^${person}|" |\ awk -F\| '{print $2}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "^${person}|" |\ awk -F\| '{print $2}' | sort >> $tmp.$lcount ;; nynn) $cater $dirdb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2}' > $tmp.$lcount $cater $writedb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2}' >> $tmp.$lcount $cater $compdb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2}' >> $tmp.$lcount $cater $cinedb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "${person}.*|.*|.*" |\ awk -F\| '{print $2}' | sort >> $tmp.$lcount ;; nnyn) $cater $dirdb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' > $tmp.$lcount $cater $writedb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' >> $tmp.$lcount $cater $compdb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' >> $tmp.$lcount $cater $cinedb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "^${person}|" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' | sort >> $tmp.$lcount ;; nyyn) $cater $dirdb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' > $tmp.$lcount $cater $writedb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' >> $tmp.$lcount $cater $compdb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' >> $tmp.$lcount $cater $cinedb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' >> $tmp.$lcount $cater $acrdb $acsdb $deaddb | $greper "${person}.*|.*|.*" |\ awk -F\| '{if (length($3) > 0) print $2 " " $3;\ else print $2}' | sort >> $tmp.$lcount ;; esac if [ $tcnt -gt 1 ] then sort -o $tmp.$lcount $tmp.$lcount fi lcount=`expr $lcount + 1` done ) rm $names # output results if [ $tcnt -gt 0 ] then # find names common to all searches cp "$tmp.0" $tmp if [ $tcnt -gt 1 ] then for i in $tmp.* do comm -12 $tmp $i > $tmp2 mv $tmp2 $tmp rm $i done else rm "$tmp.0" fi # output results case "${movies}${raw}${yr}" in nnn) sed -e 's/"/~/g' $tmp | sort | sed -e 's/~/"/g' | $pager ;; nyn) $pager $tmp ;; ynn) grep -v '^"' $tmp | $pager ;; yyn) grep -v '|"' $tmp | $pager ;; nny) if [ -n "$yrunsort" ] then sort -f $tmp | yr | awk -F\| '{print $2}' | sed -e 's/"/~/g' | sort |\ sed -e 's/~/"/g' | $pager else sort -f $tmp | yr | sort -t\| -f +2 -3 | awk -F\| '{print $2}'| $pager fi ;; yny) if [ -n "$yrunsort" ] then grep -v '^"' $tmp | sort -f | yr | awk -F\| '{print $2}' | $pager else grep -v '^"' $tmp | sort -f | yr | sort -t\| -f +2 -3 |\ awk -F\| '{print $2}'| $pager fi ;; esac # remove temporary file & exit with appropriate status if [ -s $tmp ] then rm $tmp exit 0 else rm $tmp exit 1 fi fi fi # end of script @EOF set `wc -lwc <person` if test $1$2$3 != 361173812938 then echo ERROR: wc results of person are $* should be 361 1738 12938 fi chmod 750 person echo x - yr.c cat >yr.c <<'@EOF' /* * Program: yr * * Function: Read sorted list of titles from stdin and look up info from titles database * * Author: Col Needham <cn@otter.hpl.hp.com> * - fieldcmp bug fix by Jon Reeves <reeves@aosg.gsf.dec.com> * * Author's note: I am not a 'C' programmer so I'm sure there's a better way to do this, * but at least it works!! * */ #include <stdio.h> #include <fcntl.h> #include <string.h> #include <ctype.h> /* * ttlform : title format * * Combines title string with line from titles database, inserting year-data in * appropriate position * */ ttlform(tdbase, title, origttl, truncpt) char tdbase[], title[], origttl[]; int truncpt; { int i=0, flag=0; /* loop counter & continuation flag */ int yridx; while ((title[i] != '|') && (flag==0)) { if (title[i] == '(') if (title[i+1] == '1' && title[i+2] == '9') flag = 1; else flag = 2; i++; } switch (flag) { case 0: yridx = findfield(tdbase); title[i]='\0'; if (truncpt) printf("%s|%s (%c%c%c%c) %s%s", origttl, title, tdbase[yridx], tdbase[yridx+1], tdbase[yridx+2], tdbase[yridx+3], title+truncpt, tdbase+yridx); else printf("%s|%s (%c%c%c%c)%s", origttl, title, tdbase[yridx], tdbase[yridx+1], tdbase[yridx+2], tdbase[yridx+3], tdbase+yridx-1); break; case 1: if (truncpt) title[truncpt-1]=' '; printf("%s|%s%s",origttl,title,tdbase+findfield(tdbase)); break; case 2: if (truncpt) title[truncpt-1]=' '; yridx = findfield(tdbase); title[i-2]='\0'; printf("%s|%s (%c%c%c%c) %s%s", origttl, title, tdbase[yridx], tdbase[yridx+1], tdbase[yridx+2], tdbase[yridx+3], title+i-1, tdbase+yridx); } } /* * convttl : convert title * * Scans along title string, looking for end of title field and adds delimiter ("|"), returns * position at which delimiter added. Also adds the null character to the end of the string * */ convttl(s, origttl) char *s, *origttl; { int idx=0; int flag=0; char *p = s; while (*s != '\n') { if (*s == '(') if (!((*(s+1)=='1' && *(s+2)=='9') || (*(s+1)=='T' && *(s+2)=='V' && *(s+3)==')') || (*(s+1)=='V' && *(s+2)==')') || (*(s+1)=='m' && *(s+2)=='i' && *(s+3)=='n' && *(s+4)=='i' && *(s+5)==')'))) { if (!flag) { *(s-1) = '|'; idx=s-p; flag=1;}; }; *origttl = *s; origttl++; s++;}; *s = '|'; s++; *s = '\0'; *origttl = '\0'; return(idx); } /* * findfields * * Scans along a string and returns index+1 of first field delimiter ("|") * */ int findfield(s) char s[]; { int i=0; while (s[i] != '|') i++; return(++i); } char icase ( ch ) char ch ; { if ( isupper ( ch ) ) return ( tolower ( ch ) ) ; else return ( ch ) ; } /* * fieldcmp * * Compares two "|" delimited strings * */ fieldcmp(s, t) char s[], t[]; { int i=0; while ( icase(s[i]) == icase(t[i]) ) if (s[i+1] == '|' && t[i+1] == '|') return(0); else if (s[i+1] == ' ' && t[i+1] == '|' && s[i+2] == '(') return(1); else i++; if (s[i] == '|') return(-1); else return(icase(s[i])-icase(t[i])); } main() { char title[160]; /* title */ char origttl[160]; char tdbase[160]; /* current line from titles database */ int flag; /* continuation flag */ int truncpt; int llen ; int sts=1; /* status flag */ FILE *fopen(), *fp; fp = fopen("movies.dbs","r"); if (fp == NULL) { fprintf (stderr, "Couldn't open movies.dbs\n"); exit (2); } fgets(tdbase,160,fp); while (fgets(title,160,stdin) != NULL) { if ( title[0] != '\n' ) { truncpt = convttl(title, origttl); flag = fieldcmp(tdbase,title); while (flag < 0 && fgets(tdbase, 160, fp) != NULL) flag = fieldcmp(tdbase,title); if (flag) /* no match, output blank data */ printf("%s|%s????|\n", origttl, title); else { ttlform(tdbase, title, origttl, truncpt); sts=0; } } } return(sts); } @EOF set `wc -lwc <yr.c` if test $1$2$3 != 1965624225 then echo ERROR: wc results of yr.c are $* should be 196 562 4225 fi chmod 640 yr.c echo x - mguide cat >mguide <<'@EOF' #!/bin/sh # Script : mguide version 2.3 # Purpose: Generate movie guide # Author : Col Needham <cn@otter.hpl.hp.com> PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi guide="$MOVIESTMPDIR/tmp.$$" trap "rm -f $guide; exit" 1 2 15 # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs resultfile=movieguide mgopts="" # interpret options while [ -n "$1" ] do case $1 in -yru) mgopts="-yru ${mgopts}" shift ;; -aka) mgopts="-aka ${mgopts}" shift ;; -mrr) mgopts="-mrr ${mgopts}" shift ;; *) echo "$1: unrecognized option" shift err=yes ;; esac done if [ -n "$err" ] then echo "usage: mguide [-mrr -aka -yru]" exit 1 fi awk -F\| '{print $1 "|" $2 "|" $3 "|5"}' $acrdb | grep -v '|"' > $guide awk -F\| '{print $1 "|" $2 "|" $3 "|5"}' $acsdb | grep -v '|"' >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|5"}' $deaddb | grep -v '|"' >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|1"}' $dirdb | grep -v '|"' >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|2"}' $writedb | grep -v '|"' >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|3"}' $compdb | grep -v '|"' >> $guide awk -F\| '{print $1 "|" $2 "|" $3 "|4"}' $cinedb | grep -v '|"' >> $guide sort -t\| -f +1 -2 +3 -4 -o $guide $guide mgde $mgopts < $guide > $resultfile rm $guide @EOF set `wc -lwc <mguide` if test $1$2$3 != 682461483 then echo ERROR: wc results of mguide are $* should be 68 246 1483 fi chmod 750 mguide echo x - yrf.c cat >yrf.c <<'@EOF' /* * Program: yrf.c * * Function: Reads database file sorted by title (second) field, add year information * to this field and also adds fourth field containing just the year * * Author: Col Needham <cn@otter.hpl.hp.com> * - fieldcmp bug fix by Jon Reeves <reeves@aosg.gsf.dec.com> * * Author's note: I am not a 'C' programmer so I'm sure there's a better way to do this, * but at least it works!! * */ #include <stdio.h> #include <fcntl.h> #include <string.h> #include <ctype.h> /* * ttlform : title format * * Combines title string with line from titles database, inserting year-data in * appropriate position * */ ttlform(namefld, title, attfld, tdbase) char namefld[], title[], attfld[], tdbase[]; { int i=0, flag=0; /* loop counter & continuation flag */ int yridx; while ((title[i] != '|') && (flag==0)) { if (title[i] == '(') if (title[i+1] == '1' && title[i+2] == '9') flag = 1; else flag = 2; i++; } yridx = findfield(tdbase); tdbase[yridx+4] = '\0'; switch (flag) { case 0: title[i]='\0'; printf("%s|%s (%s)|%s|%s\n", namefld, title, tdbase+yridx, attfld, tdbase+yridx); break; case 1: printf("%s|%s|%s\n",namefld,title,tdbase+yridx); break; case 2: title[i-2]='\0'; printf("%s|%s (%s) %s|%s\n", namefld, title, tdbase+yridx, title+i-1, tdbase+yridx); } } /* * convttl : convert title * * Scans along title string, looking for end of title field and adds delimiter ("|"), returns * position at which delimiter added. Also adds the null character to the end of the string * */ convttl(s) char *s; { char *p = s; while (*s != '\n') s++; *s = '\0'; } /* * findfields * * Scans along a string and returns index+1 of first field delimiter ("|") * */ int findfield(s) char s[]; { int i=0; while (s[i] != '|') i++; return(++i); } char icase ( ch ) char ch ; { if ( isupper ( ch ) ) return ( tolower ( ch ) ) ; else return ( ch ) ; } /* * fieldcmp * * Compares two "|" delimited strings * */ fieldcmp(s, t) char s[], t[]; { int i=0; while (icase(s[i]) == icase(t[i])) if (s[i+1] == '|' && t[i+1] == '|') return(0); else if (s[i+1] == ' ' && t[i+1] == '|' && s[i+2] == '(') return(1); else i++; if (s[i] == '|') return(-1); else return(icase(s[i])-icase(t[i])); } main() { char title[120]; /* title */ char origttl[120]; char tdbase[120]; /* current line from titles database */ int flag; /* continuation flag */ int ttlidx, attidx; int truncpt; int sts=1; /* status flag */ FILE *fopen(), *fp; fp = fopen("movies.dbs","r"); if (fp == NULL) { fprintf (stderr, "Couldn't open movies.dbs\n"); exit (2); } fgets(tdbase,120,fp); while (fgets(title,120,stdin) != NULL) { ttlidx = findfield(title); attidx = findfield(title+ttlidx); convttl(title); if (attidx == 1) printf("%s|????\n", title); else { flag = fieldcmp(tdbase,title+ttlidx); while (flag < 0 && fgets(tdbase, 160, fp) != NULL) flag = fieldcmp(tdbase,title+ttlidx); if (flag) /* no match, output blank data */ printf("%s|????\n", title); else { title[ttlidx-1] = '\0'; ttlform(title, title+ttlidx, title+ttlidx+attidx, tdbase); sts=0; } } } return(sts); } @EOF set `wc -lwc <yrf.c` if test $1$2$3 != 1734913591 then echo ERROR: wc results of yrf.c are $* should be 173 491 3591 fi chmod 640 yrf.c echo x - ldebug cat >ldebug <<'@EOF' #!/bin/sh # Script: ldebug version 2.2 # Purpose: General purpose debugging script # Author: Col Needham <cn@otter.hpl.hp.com> # options: # # -acr specify actors list # -acs specify actress list # -dead specify dead list # -dir specify director list # -write specify writer list # -comp specify composer list # -cine specify cinematographer list # -name <name> specify name of person to check entries for # -adds <file> check file of additions for new names/titles # -noyear look for movies on titles database with missing year information # -full use with -noyear, includes movies that aren't in the titles # database at all # -m movies only, ignore TV series PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" tmp2="$MOVIESTMPDIR/tmp2.$$" tmp3="$MOVIESTMPDIR/tmp3.$$" # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs akadb=aka.dbs movies=movies.dbs cater=cat moviegreper="cat" yeargreper='grep (\?\?\?\?)' if [ $# -eq 0 ] then err=y fi # interpret options while [ -n "$1" ] do case $1 in -name) shift name=$1 shift ;; -adds) shift adds=$1 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 ;; -comp) listfile=$compdb shift ;; -cine) listfile=$cinedb shift ;; -noyear) yropt=y shift ;; -full) yeargreper='grep \?\?\?\?' shift ;; -m) moviegreper='grep -v |"' shift ;; *) err=y shift ;; esac done if [ "$err" = "y" ] then echo "usage: ldebug [-acr -acs -dead -dir -write -cine -comp] -name <name>" echo " [-noyear -full -m] [-adds <file>]" exit 1 fi if [ -n "$yropt" ] then $cater $listfile | grep "^${name}|" | $moviegreper | awk -F\| '{print $2}' |\ yr | $yeargreper | awk -F\| '{print $1 "|????|" $4 }' fi if [ -n "$adds" ] then awk -F\| '{print $1}' $listfile | sort -u > $tmp awk -F\| '{print $1}' $adds | sort -u > $tmp2 comm -23 $tmp2 $tmp > $tmp3 if [ -s $tmp3 ] then echo "New Names" echo "---------" cat $tmp3 echo fi awk -F\| '{print $1}' $movies | sort -u > $tmp $moviegreper $adds | awk -F\| '{print $2}' | sort -u > $tmp2 comm -23 $tmp2 $tmp > $tmp3 if [ -s $tmp3 ] then echo "New Titles" echo "----------" cat $tmp3 fi rm -f $tmp $tmp2 $tmp3 fi @EOF set `wc -lwc <ldebug` if test $1$2$3 != 1333942757 then echo ERROR: wc results of ldebug are $* should be 133 394 2757 fi chmod 750 ldebug echo x - lformat cat >lformat <<'@EOF' #!/bin/sh # Script : lformat version 2.3 # Purpose: Formats lists or subsets of lists (adding year information and # ratings report details if required) # Notes: # (1) replaces 'sublist' + 'yrformat' & provides additional functionality # (2) requires the Unix utility 'join' which may not be present on all systems # Author : Col Needham <cn@otter.hpl.hp.com> # Valid options: # # Database opts: # # -acr search actors database # -acs search actresses database # -dead search dead actors/actresses database # -cast shortcut for combination of -acr -acs -dead # -dir search directors database # -write search writers database # -comp search composers database # -cine search cinematographers database # # Note: database options maybe combined # # Format opts: # # -yr adds year of release & sorts chronologically # -yru adds year of release # -mrr adds movie ratings report information # -smrr adds ratings report information & sorts by average rating # -vmrr adds ratings report information & sorts by number of votes # # Name file options: # # -f <file> use list of names in <file> for subset # # Output options: # # -r raw, do not format output # -m movies only, don't display TV series information # -cat cat, use 'cat' to display results instead of 'more' # -match used with the *mrr options, only outputs titles that # match the ratings database # # Examples: # # lformat -acr -f names # -- generate formatted subset of actors list consisting of actors listed # in file 'names' # # lformat -acr # -- formats entire actors list # # lformat -dir -yr # -- formats entire directors list & adds year information # # lformat -dead -mrr # -- formats entire dead list and adds ratings report info PATH=.:$PATH; export PATH # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi tmp="$MOVIESTMPDIR/tmp.$$" tmp2="$MOVIESTMPDIR/tmp2.$$" tmp3="$MOVIESTMPDIR/tmp3.$$" tmpdb="$MOVIESTMPDIR/tmp4.$$" # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs ratings=ratings.dbs trap "rm -f $tmp $tmp2 $tmp3 $tmpdb; exit" 1 2 15 # default pager for results pager=more cater=cat sorter="sort -t| +1 -2" yrsorter="sort -t| +0 -1 +3 -4" moviegreper=cat joiner="join -a1" err=no movies=n raw=n if [ $# -eq 0 ] then err=yes fi # interpret options while [ -n "$1" ] do case $1 in -m) movies=y moviegreper='grep -v ^"' shift ;; -cat) pager=cat shift ;; -r) raw=y shift ;; -f) shift names=$1 partlist=y shift ;; -acr) listfile="$listfile $acrdb" shift ;; -acs) listfile="$listfile $acsdb" shift ;; -dead) listfile="$listfile $deaddb" shift ;; -cast) listfile="$listfile $acrdb $acsdb $deaddb" shift ;; -dir) listfile="$listfile $dirdb" shift ;; -write) listfile="$listfile $writedb" shift ;; -comp) listfile="$listfile $compdb" shift ;; -cine) listfile="$listfile $cinedb" shift ;; -yr) yr=y shift ;; -yru) yrsorter="sort -d" yr=y shift ;; -mrr) mrr=y shift ;; -smrr) sorter="sort -t| +4 -5 -r +5 -6" mrr=y shift ;; -vmrr) sorter="sort -t| +3 -4 -r +5 -6" mrr=y shift ;; -match) joiner="join" shift ;; *) echo "$1: unrecognized option" err=yes shift ;; esac done if [ $err = "yes" ] then echo "usage: lformat {-acr -acs -dead -dir -write -comp -cine -cast}+ [-f <namefile>]" echo " [-m -cat -r] [-mrr|-smrr|-vmrr|-yr|-yru] [-match]" exit 1 fi # check database specified if [ ! -n "$listfile" ] then echo "lformat: no list specified" exit 1 fi # check for option mismatch if [ "$yr$mrr" = "yy" ] then echo "lformat: ratings report options not available with year options" exit 1 fi # generate subset if appropriate if [ -z "$partlist" ] then sort -t\| +0 -1 -o $tmp $listfile else sort -o $names $names sort -t\| +0 -1 -o $tmp2 $listfile join -t\| -o 2.1 2.2 2.3 $names $tmp2 > $tmp fi # output results if [ -r $tmp ] then if [ -n "$yr" ] then case "${movies}${raw}" in nn) sort -t\| -f +1 -2 $tmp | yrf | sed -e 's/"/~/g' | $yrsorter | sed -e 's/~/"/g' |\ awk -F\| -f format.awk | $pager ;; ny) sort -t\| -f +1 -2 $tmp | yrf | sed -e 's/"/~/g' | $yrsorter | sed -e 's/~/"/g' |\ awk -F\| '{print $1 "|" $2 "|" $3}' | $pager ;; yn) grep -v '|".*|' $tmp | sort -t\| -f +1 -2 | yrf | $yrsorter |\ awk -F\| -f format.awk | $pager ;; yy) grep -v '|".*|' $tmp | sort -t\| -f +1 -2 | yrf | $yrsorter |\ awk -F\| '{print $1 "|" $2 "|" $3}' | $pager ;; esac else if [ -n "$mrr" ] then $cater $tmp | sed -e 's/ (TV)//' | awk -F\| '{print $2 "|" $1}' |\ $moviegreper | tr [A-Z] [a-z] | sort -t\| +0 -1 > $tmpdb $joiner -j1 1 -j2 4 -t\| $tmpdb $ratings | sort -t\| +1 -2 > $tmp2 cat $tmp2 | awk -F\| '{print $2}' | sort -u |\ ( read iline while [ -n "$iline" ] do echo $iline echo echo $iline > $tmp3 join -j1 1 -j2 2 -t\| $tmp3 $tmp2 | sed -e 's/|"/|~/' | $sorter | sed -e 's/|~/|"/' |\ awk -F\| '{if (NF==5) printf " %s %s %s %s\n", $3, $4, $5, $2; else printf " %s\n", $2}' echo read iline done ) | $pager rm -f $tmp $tmp2 $tmp3 $tmpdb exit 0 else # remove TV info? if [ "$movies" = "y" ] then grep -v '|".*|' $tmp > $tmp2 mv $tmp2 $tmp fi if [ "$raw" = "y" ] then $pager $tmp else sed -e 's/"/~/g' $tmp | sort | sed -e 's/~/"/g' | awk -F\| -f format.awk | $pager fi fi fi fi # tidy up if [ -s $tmp ] then rm -f $tmp $tmp2 $tmp3 $tmpdb exit 0 else rm -f $tmp $tmp2 $tmp3 $tmpdb exit 1 fi @EOF set `wc -lwc <lformat` if test $1$2$3 != 2539586043 then echo ERROR: wc results of lformat are $* should be 253 958 6043 fi chmod 750 lformat echo x - akaprint cat >akaprint <<'@EOF' #!/bin/sh # Script : akaprint version 1.0 # Purpose: get a list of titles and print their aka names. # Author : Philippe Queinnec <queinnec@dgac.fr> # inspired by scripts by Col Needham <cn@otter.hpl.hp.com> # Valid options: # # None. # # Examples: # list -cat -a "Bonnaire, Sandrine" | akaprint # list -cat -d "Wenders, Wim" | akaprint # listall -cat "police" | akaprint akadb='aka.dbs' greper='grep -i' # I know the following is silly, but I want to be ready to add options. while [ -n "$1" ] do case $1 in *) echo "$1: unrecognized option" echo "Usage: akaprint" exit 1 ;; esac done awkprint1='{print $2}' awkprint2='{print $3}' if (echo "hi there\c"; echo '') | grep -s c then echoopt='-n' echotrail='' else echoopt='' echotrail='\c' fi while read title do if [ -z "$title" ]; then newtitle='' else newtitle=`$greper "^..|${title}|" $akadb | awk -F\| "$awkprint2"` if [ -z "$newtitle" ]; then newtitle=`$greper "^..|.*|${title}\$" $akadb | awk -F\| "$awkprint1"` fi fi if [ -z "$newtitle" ]; then echo "$title" else # A acrobatic way of doing what I need. # It would have been so simple with perl... echo $echoopt "${title}${echotrail}" echo "$newtitle" |\ ( while read anewtitle; do echo $echoopt " (aka ${anewtitle})${echotrail}"; done ) echo '' fi done @EOF set `wc -lwc <akaprint` if test $1$2$3 != 652091450 then echo ERROR: wc results of akaprint are $* should be 65 209 1450 fi chmod 750 akaprint echo x - corrects.mrr cat >corrects.mrr <<'@EOF' s/|'night, mother$/|'night mother/ s/|101 dalmations$/|one hundred and one dalmatians/ s/|1984 (1984)$/|nineteen eighty-four (1984)/ s/|american tail: fievel goes west, an$/|american tale: fievel goes west, an/ s/|andy warhol's trash$/|trash/ s/|angelo, my love$/|angelo my love/ s/|ay, carmela$/|ay, carmela!/ s/|buffy, the vampire slayer$/|buffy the vampire slayer/ s/|cavegirl$/|cave girl/ s/|close encounters of the third kind (1977)$/|close encounters of the third kind/ s/|close encounters of the third kind (1980)$/|close encounters of the third kind/ s/|codename: wildgeese$/|code name: wild geese/ s/|crocodile dundee ii$/|'crocodile' dundee ii/ s/|crocodile dundee$/|'crocodile' dundee/ s/|d.o.a. (1950)$/|d.o.a. (1949)/ s/|damien - omen ii$/|damien: omen ii/ s/|das boot$/|boat, the/ s/|el amor brujo$/|amor brujo, el/ s/|entre nous$/|between us/ s/|europa, europa$/|europa europa/ s/|fried green tomatoes$/|fried green tomatoes at the whistle stop cafe/ s/|great wall, a$/|great wall is a great wall, the/ s/|gremlins 2: the new batch$/|gremlins ii: the new batch/ s/|henry v (1945)$/|henry v (1944)/ s/|highlander 2: the quickening$/|highlander ii: the quickening/ s/|january man, the$/|january man/ s/|jungle book (1967)$/|jungle book, the (1967)/ s/|kickboxer 2$/|kickboxer 2: the road back/ s/|l'age d'or$/|age d'or/ s/|l'atalante$/|atalante, l'/ s/|l'avventura$/|avventura, l'/ s/|la cage aux folles 3: the wedding$/|cage aux folles 3: the wedding, la/ s/|la cage aux folles ii$/|cage aux folles ii, la/ s/|la cage aux folles$/|cage aux folles, la/ s/|la chevre$/|chevre, la/ s/|la dolce vita$/|dolce vita, la/ s/|la lectrice$/|lectrice, la/ s/|la strada$/|strada, la/ s/|la traviata$/|traviata, la/ s/|le cadeau$/|gift, the (1982)/ s/|le grand chemin$/|grand highway, the/ s/|les comperes$/|comperes, les/ s/|les enfants du paradis$/|children of paradise/ s/|les miserables (1935)$/|miserables, les (1935)/ s/|man who saw tomorrow$/|man who saw tomorrow, the/ s/|mannequin two: on the move$/|mannequin on the move/ s/|metropolis (1926)$/|metropolis/ s/|nos amours, a$/|a nos amours/ s/|oh god! book ii$/|oh, god! book ii/ s/|oh, calcutta!$/|oh calcutta/ s/|once upon a time in america (long)$/|once upon a time in america/ s/|raggedy rawney, the$/|raggedy rawney/ s/|rescuers$/|rescuers, the/ s/|roger & me$/|roger and me/ s/|rules of the game$/|rules of the game, the/ s/|scanners 2: the new order$/|scanners ii: the new order/ s/|shall we dance$/|shall we dance?/ s/|smokey and the bandit 3$/|smokey and the bandit iii/ s/|sweet hearts dance$/|sweet heart's dance/ s/|teorema$/|theorem/ s/|that was then, this is now$/|that was then...this is now/ s/|thing, the (1951)$/|thing from another world, the/ s/|three amigos$/|three amigos!/ s/|through a glass, darkly$/|through a glass darkly/ s:|tom sawyer (1973)$:|tom sawyer (1973/ii): s/|two-moon junction$/|two moon junction/ s/|withnail & i$/|withnail and i/ s/|zatoichi meets yojimbo$/|zatoichi vs. yojimbo/ s:|black rain$:|black rain (1989/i): s:|les miserables (1952)$:|miserables, les (1952/i): s:|uncommon valor$:|uncommon valor (1983/i): @EOF set `wc -lwc <corrects.mrr` if test $1$2$3 != 713883114 then echo ERROR: wc results of corrects.mrr are $* should be 71 388 3114 fi chmod 640 corrects.mrr echo x - mgde.c cat >mgde.c <<'@EOF' #include <stdio.h> #include <fcntl.h> #include <string.h> #include <ctype.h> titlecpy(s,t) 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'); if (isupper(s[i])) t[i]=tolower(s[i]); else t[i]=s[i]; i++; } if (flag) /* ordinary title, terminate string */ { t[i] = '\n'; t[i+1] = '\0' ; } else /* terminate title before bracketed information */ { t[i-2] = '\n'; t[i-1]='\0'; } } char* fieldptr ( s ) char* s ; { char* scpy ; scpy = s ; while ( *s != '|' && *s != '\0' && *s != '\n' ) s++ ; return (s) ; } remove_nl ( s ) char* s ; { while ( *s++ != '\n' ); *(s-1) = '\0' ; } title_print ( title, yrdata ) char title[] ; char yrdata[] ; { int i=0, flag=0; /* loop counter & continuation flag */ char* attrptr ; char* tmp ; if ( yrdata == NULL ) printf ( "%s\n", title ) ; else { attrptr = yrdata + 5 ; *(yrdata+4) = '\0' ; if ( *attrptr == 10 ) *attrptr = '\0' ; else { tmp = fieldptr ( attrptr ) ; *tmp = '\0' ; } while ((title[i] != '\0') && (flag==0)) { if (title[i] == '(') if (title[i+1] == '1' && title[i+2] == '9') flag = 1; else flag = 2; i++; } switch (flag) { case 0: printf("%s (%s) %s\n", title, yrdata, attrptr ); break; case 1: printf("%s %s\n", title, attrptr ); break; case 2: title[i-2]='\0' ; printf("%s (%s) %s %s\n", title, yrdata, title+i-1, attrptr ); } } } char* list_year ( year, ctitle, yrfp ) char year[] ; char ctitle[] ; FILE *yrfp ; { int flag ; char* yrdata = NULL; flag = strcasecmp( year ,ctitle ) ; while ( flag < 0 && fgets( year, 200, yrfp ) != NULL ) { yrdata = fieldptr ( year ) ; *yrdata++ = '\0' ; flag = strcasecmp( year, ctitle ); } if ( flag == 0 ) { if ( yrdata == NULL ) yrdata = year + strlen ( year ) + 1; return ( yrdata ) ; } else return ( NULL ) ; } list_aka ( aka, ctitle, akafp, mrropt ) char aka[] ; char ctitle[] ; FILE *akafp ; int mrropt ; { int flag ; char* akatitle = NULL; flag = strcasecmp(aka+3 ,ctitle); while (flag < 0 && fgets(aka, 200, akafp) != NULL) { akatitle = fieldptr ( aka + 3 ) ; *akatitle++ = '\0' ; flag = strcasecmp(aka+3, ctitle); } while ( flag == 0 ) { if ( akatitle == NULL ) akatitle = aka + strlen ( aka ) + 1; remove_nl ( akatitle ) ; if ( mrropt ) printf ( " (aka %s)\n", akatitle ) ; else printf ( "(aka %s)\n", akatitle ) ; if ( fgets(aka, 200, akafp) != NULL ) { akatitle = fieldptr ( aka + 3 ) ; *akatitle++ = '\0' ; flag = strcasecmp(aka+3, ctitle); } else flag = 1 ; } } list_mrr ( title, ratings, ratefp, cyear ) char title[]; char ratings[]; FILE* ratefp; char* cyear ; { char stitle[120] ; int flag ; titlecpy(title, stitle); flag = strcmp(ratings+22,stitle); while (flag < 0 && fgets(ratings, 200, ratefp) != NULL) flag = strcmp(ratings+22,stitle); if (flag) { printf(" " ); title_print ( title, cyear ) ; } else { ratings[10]='\0'; ratings[16]='\0'; ratings[21]='\0'; printf(" %s %s %s ",ratings,ratings+11,ratings+17); title_print ( title, cyear ) ; } } main( argc, argv ) int argc ; char *argv[] ; { char title[200]; char line[200]; char ratings[200]; char aka[200]; char year[200]; char* cyear = NULL; char* cname; char* ctitle; char* cattr; char* ctype; char* akatitle = NULL; char* yrdata = NULL; int flag, i; int opts=0 ; int yropt=0 ; int akaopt=0 ; int mrropt=0 ; FILE *fopen(), *ratefp, *akafp, *yrfp; for ( i = 1; i < argc; i++ ) if ( strcmp ( "-mrr", argv[i] ) == 0 ) mrropt = 1 ; else if ( strcmp ( "-aka", argv[i] ) == 0 ) akaopt = 1 ; else if ( strcmp ( "-yru", argv[i] ) == 0 ) yropt = 1 ; title[0] = '\0' ; if ( mrropt ) { if ( ( ratefp = fopen( "ratings.dbs", "r" ) ) == NULL ) { fprintf( stderr, "mguide: ratings database not found\n" ) ; exit ( -1 ) ; } fgets( ratings, 200, ratefp ); } if ( akaopt ) { if ( ( akafp = fopen( "aka.dbs", "r" ) ) == NULL ) { fprintf( stderr, "mguide: aka database not found\n" ) ; exit ( -1 ) ; } fgets( aka, 200, akafp ); akatitle = fieldptr ( aka + 3 ) ; *akatitle++ = '\0' ; } if ( yropt ) { if ( ( yrfp = fopen( "movies.dbs", "r" ) ) == NULL ) { fprintf( stderr, "mguide: year database not found\n" ) ; exit ( -1 ) ; } fgets( year, 200, yrfp ); yrdata = fieldptr ( year ) ; *yrdata++ = '\0' ; } while ( fgets( line, 200, stdin ) != NULL ) { cname = line ; ctitle = fieldptr ( line ) ; *ctitle++ = '\0' ; cattr = fieldptr ( ctitle ) ; *cattr++ = '\0' ; ctype = fieldptr ( cattr ) ; *ctype++ = '\0' ; if ( strcmp ( title, ctitle ) ) { strcpy ( title, ctitle ) ; printf ( "\n------------------------------------------------------------------------------\n" ) ; if ( yropt ) cyear = list_year ( year, title, yrfp ) ; switch ( (2*akaopt) + mrropt ) { case 0: title_print ( ctitle, cyear ) ; printf ( "\n" ) ; break ; case 1: list_mrr ( ctitle, ratings, ratefp, cyear ) ; printf ( "\n" ) ; break ; case 2: title_print ( ctitle, cyear ) ; list_aka ( aka, title, akafp, mrropt ) ; printf ( "\n" ) ; break ; case 3: list_mrr ( ctitle, ratings, ratefp , cyear ) ; list_aka ( aka, title, akafp, mrropt ) ; printf ( "\n" ) ; break ; default : break ; } } if ( *ctype != '0' ) { if ( *cattr == '\0' ) printf ( " %s", cname ) ; else printf ( " %s %s", cname, cattr ) ; switch ( *ctype ) { case '1' : printf ( " (d)\n" ) ; break ; case '2' : printf ( " (w)\n" ) ; break ; case '3' : printf ( " (m)\n" ) ; break ; case '4' : printf ( " (ph)\n" ) ; break ; default : printf ( "\n" ) ; } } } return(0); } @EOF set `wc -lwc <mgde.c` if test $1$2$3 != 31911196706 then echo ERROR: wc results of mgde.c are $* should be 319 1119 6706 fi chmod 640 mgde.c echo x - akamap.c cat >akamap.c <<'@EOF' #include <stdio.h> #include <fcntl.h> #include <string.h> #include <ctype.h> char* fieldptr ( s ) char* s ; { while ( *s != '|' ) s++ ; return (s) ; } remove_nl ( s ) char* s ; { while ( *s++ != '\n' ); *(s-1) = '\0' ; } main( argc, argv ) int argc ; char *argv[] ; { char line[200]; char aka[200]; char* akatitle = NULL; char* tmp = NULL; int flag=1; FILE *fopen(), *akafp; if ( ( akafp = fopen( "aka.dbs", "r" ) ) == NULL ) { fprintf( stderr, "akamap: aka database not found\n" ) ; exit ( -1 ) ; } while ( fgets( line, 200, stdin ) != NULL ) { rewind ( akafp ) ; flag = 1 ; while (flag && fgets(aka, 200, akafp) != NULL) { akatitle = fieldptr ( aka + 3 ) ; *akatitle++ = '\0' ; flag = strcasecmp( akatitle, line ); } if ( flag == 0 ) printf ( "%s\n", aka+3 ) ; else printf ( "%s", line ) ; } return(0); } @EOF set `wc -lwc <akamap.c` if test $1$2$3 != 56176936 then echo ERROR: wc results of akamap.c are $* should be 56 176 936 fi chmod 640 akamap.c echo x - lseen cat >lseen <<'@EOF' #!/bin/sh # Script : lseen version 2.3 # # Purpose: uses the votelog file from the movie ratings report voting support # scripts to sort listed names by order of the number of films # of theirs that you have seen. # # Author : Col Needham <cn@otter.hpl.hp.com> # # Valid options: # # Database opts: # # -acr select actors in database # -acs select actresses in database # -dead select dead actors/actresses # -cast combines 3 options above # -dir select directors database # -write select writers database # -comp select composers database # -cine select cinematographers database # # Output opts: # # -cat cat, use 'cat' to display results instead of 'more' # -nv no voice, ignores entries in cast databases where the person just # supplied a voice in the movie # # Ratings Report opts: # # -mrr add movie ratings for each film you've seen # -smrr add movie ratings & sort by average ratings # -vmrr add movie ratings & sort by total votes # # Examples: # # lseen -cast # -- generate sorted count for each actor/actress of no. of their films # you have seen # # lseen -dir -mrr # -- as above, but for directors & lists the ratings report entry for each # film you have seen # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi votes=$MOVIESTMPDIR/tmpfile0.$$ tmpdb=$MOVIESTMPDIR/tmpfile1.$$ tmp1=$MOVIESTMPDIR/tmpfile2.$$ tmp2=$MOVIESTMPDIR/tmpfile3.$$ tmp3=$MOVIESTMPDIR/tmpfile4.$$ ratings=ratings.dbs votelog=votelog mrrcorrs=corrects.mrr # names of database files acrdb=actors.dbs acsdb=actress.dbs deaddb=dead.dbs dirdb=directs.dbs writedb=writers.dbs compdb=composers.dbs cinedb=cine.dbs trap "rm -f $tmpdb $tmp1 $tmp2 $tmp3 $votes; exit" 1 2 15 # default pager for results pager=more cater=cat sorter=cat listfile="" if [ $# -eq 0 ] then err=y fi # interpret options while [ -n "$1" ] do case $1 in -cat) pager=cat shift ;; -acr) listfile="$listfile $acrdb" shift ;; -acs) listfile="$listfile $acsdb" shift ;; -dead) listfile="$listfile $deaddb" shift ;; -cast) listfile="$listfile $acrdb $acsdb $deaddb" shift ;; -dir) listfile="$listfile $dirdb" shift ;; -write) listfile="$listfile $writedb" shift ;; -comp) listfile="$listfile $compdb" shift ;; -cine) listfile="$listfile $cinedb" shift ;; -nv) novoice=y shift ;; -mrr) mrr=y shift ;; -smrr) sorter="sort -t| -r +4 -5" mrr=y shift ;; -vmrr) sorter="sort -t| -r +3 -4" mrr=y shift ;; *) echo "$1: unrecognized option" err=y shift ;; esac done if [ ! -n "$listfile" ] then err=y fi if [ -n "$err" ] then echo "usage: lseen [-acr -acs -dead -cast -dir -write -comp -cine] [-cat -nv" echo " -mrr -smrr -vmrr]" exit 1 fi if [ ! -r $votelog ] then echo "votelog file not found" exit 1 fi if [ ! -r $ratings ] then echo "ratings database not found" exit 1 fi awk '{print substr($0, 10, 120)}' $votelog | tr [A-Z] [a-z] > $votes if [ -r $mrrcorrs ] then awk -F\| '{print $0"|"}' $votes | sed -f $mrrcorrs -e 's/|$//' > $tmp1 mv $tmp1 $votes fi sort -u -o $votes $votes if [ -z "$novoice" ] then $cater $listfile | sed -e 's/ (TV)//' | awk -F\| '{print $2 "|" $1}' |\ grep -v '^"' | tr [A-Z] [a-z] | sort -t\| +0 -1 > $tmpdb else $cater $listfile | sed -e 's/ (TV)//' | grep -v "(voice)" |\ awk -F\| '{print $2 "|" $1}' | grep -v '^"' | tr [A-Z] [a-z] |\ sort -t\| +0 -1 > $tmpdb fi join -j1 1 -j2 4 -t\| $tmpdb $ratings > $tmp2 join -t\| $votes $tmp2 > $tmp1 awk -F\| '{print $2}' $tmp1 | sort | uniq -c |\ sed -e 's/^\([ ]*[0-9][0-9]*\)[ ]/\1|/' | sort -t\| +0 -1 -r > $tmp2 sort -t\| +1 -2 -o $tmp1 $tmp1 cat $tmp2 |\ ( read iline while [ -n "$iline" ] do num=`expr "$iline" : '\(.*\)|'` name=`expr "$iline" : '.*|\(.*\)'` if [ "1" -eq `expr $num \< 10` ] then echo " $num $name" else echo "$num $name" fi if [ -n "$mrr" ] then echo echo $name > $tmp3 join -j1 1 -j2 2 -t\| $tmp3 $tmp1 | $sorter |\ awk -F\| '{printf " %s %s %s %s\n", $3, $4, $5, $2}' echo fi read iline done ) | $pager rm -f $votes $tmpdb $tmp1 $tmp2 $tmp3 @EOF set `wc -lwc <lseen` if test $1$2$3 != 1986964326 then echo ERROR: wc results of lseen are $* should be 198 696 4326 fi chmod 755 lseen echo x - votechk cat >votechk <<'@EOF' #!/bin/sh # Script: votechk version 2.3 # Purpose: check that voted titles match titles on ratings report # Author: Col Needham <cn@otter.hpl.hp.com> # temporary files if [ -z "$MOVIESTMPDIR" ]; then if [ -z "$TMPDIR" ]; then MOVIESTMPDIR="." else MOVIESTMPDIR="$TMPDIR" fi fi vtmp="$MOVIESTMPDIR/tmp.$$" rtmp="$MOVIESTMPDIR/tmp2.$$" trap "rm -f $vtmp $rtmp; exit" 1 2 15 votes=votelog ratings=ratings.dbs if [ ! -r $votes ] then echo "votechk: votelog file not found" exit 1 fi if [ ! -r $ratings ] then echo "votechk: ratings database not found" exit 1 fi awk '{print substr($0,10,120)}' $votes | tr [A-Z] [a-z] | \ sed -e 's/^/|/' -f corrects.mrr -e 's/^|//' | sort -u > $vtmp awk -F\| '{print $4}' $ratings | sort -u > $rtmp comm -23 $vtmp $rtmp | more rm -f $vtmp $rtmp @EOF set `wc -lwc <votechk` if test $1$2$3 != 42129809 then echo ERROR: wc results of votechk are $* should be 42 129 809 fi chmod 751 votechk exit 0