Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!cs.tamu.edu From: skdutta@cs.tamu.edu (Saumen K Dutta) Newsgroups: comp.text.tex Subject: Re: addbib for bibtex Message-ID: <7515@helios.TAMU.EDU> Date: 17 Aug 90 19:39:27 GMT Sender: usenet@helios.TAMU.EDU Organization: Computer Science Department, Texas A&M University Lines: 397 HI! I have written this program to insert bibliography in bibtex. Please try it out yourself and let me know what are the shortcomings. I could write it in C but I thought that writing it in this way is inexpensive. Also the source is not compiled and can be changed very easily to suit individual requirements. Note: Before you execute it, copy it in a file and make the file executable. Be sure that you are working with the BSD version of UNIX. If you are working with system V unix you need to change the "echo" statements in the shell script. If you have any problems write to me. ------------> CUT HERE <----------------------- #! /bin/sh # # Written by : # # Saumen K. Dutta # Graduate student # Computer Science Department # Texas A & M university # Dated: Aug. 17 1990 # # contact me at for any problems, # suggestions and criticism. # # BUGS : # # 1. Works only with the BSD version of unix. The command echo creates # the problem. It can be circumvented by redefining the echo command # according to your system. # read_Val1() { echo -n $1"(R) => " ; read $1; x='eval echo $`echo $1`' while [ -z "`eval $x`" ] do echo $1 cannot be blank , Type again echo -n $1"(R) => " ; read $1; done } read_Val() { echo -n $1"(O) => " ; read $1; } write_Val1() { x='eval echo $`echo $1`'; echo $1 = \"`eval $x`\" ,;} write_Val() { x='eval echo $`echo $1`'; if [ "`eval $x`" ] then echo $1 = \"`eval $x`\" , fi } write_key() { if [ "$key" ] then echo " " $key , else echo fi } multi_rd1() { for i in $1 do read_Val1 $i done } multi_rd() { for i in $1 do read_Val $i done } multi_wr1() { for i in $1 do write_Val1 $i done } multi_wr() { for i in $1 do write_Val $i done } confirm() { echo ; echo -n "Are you Sure (y/n):" ; read yes_no; if [ -z "$yes_no" ] then yes_no="N" else if [ "$yes_no" = "y" ]||[ "$yes_no" = "yes" ]|| \ [ "$yes_no" = "Y" ] then yes_no="Y" fi fi } Entry_bib () { echo echo Following are the various codes: echo echo "" 1. article echo "" 2. book echo "" 3. booklet echo "" 4. inproceedings / conference echo "" 5. inbook echo "" 6. incollection echo "" 7. manual echo "" 8. masterthesis echo "" 9. misc echo 10. phdthesis echo 11. proceedings echo 12. techreport echo 13. unpublished echo "" H. HELP echo "" E. Examine or Edit the database echo "" C. Search for key clash in the database echo echo -n "TYPE the code: " read type echo case $type in 1) read_Val key ; multi_rd1 "author title journal year" ; multi_rd "volume number pages month note" ; confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @article { >> $1 ; write_key >> $1 ; multi_wr1 "author title journal year" >> $1 ; multi_wr "volume number pages month note" >> $1 ; echo } >> $1 ; fi ;; 2) read_Val key ; multi_rd1 "author title publisher year" ; multi_rd "volume series address edition month note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @book { >> $1 ; write_key >> $1 ; multi_wr1 "author title publisher year" >> $1 ; multi_wr "volume series address edition month note" >> $1 echo } >> $1 ; fi ;; 3) read_Val key ; read_Val1 title ; multi_rd "author howpublished address month year note" ; confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @booklet { >> $1 ; write_key >> $1 ; write_Val1 title >> $1 ; multi_wr "author howpublished address" >> $1 multi_wr "month year note" >> $1 ; echo } >> $1 ; fi ;; 4) read_Val key ; multi_rd1 "author title booktitle year" multi_rd "editor pages organisation publisher address" multi_rd "month note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @inproceedings { >> $1 ; write_key >> $1 ; multi_wr1 "author title booktitle year" >> $1 multi_wr "editor pages organisation publisher" >> $1 multi_wr "address month note" >> $1 echo } >> $1 ; fi ;; 5) read_Val key ; multi_rd1 "author title" echo -n "chapter(O) = " ; read chapter; echo -n "pages(O) = " ; read pages; while [ -z "$chapter" ] && [ -z "$pages" ] do echo Chapter and Pages both cannot be blank, Type again echo -n "chapter(O) = " ; read chapter; echo -n "pages(O) = " ; read pages; done multi_rd1 "publisher year" multi_rd "volume series address edition month note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @inbook { >> $1 ; write_key >> $1 ; multi_wr1 "author title" >> $1 if [ "$chapter" ] then echo chapter = \"$chapter\", >> $1 fi if [ "$pages" ] then echo pages = \"$pages\", >> $1 fi multi_wr1 "publisher year" >> $1 multi_wr "volume series address edition month note" >> $1 echo } >> $1 ; fi ;; 6) read_Val key ; multi_rd1 "author title booktitle publisher year" multi_rd "chapter pages address month note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @incollection { >> $1 ; write_key >> $1 ; multi_wr1 "author title booktitle publisher year" >> $1 multi_wr "chapter pages address month note" >> $1 echo } >> $1 ; fi ;; 7) read_Val key ; read_Val1 title ; multi_rd "author organization address edition month" multi_rd "year note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @manual { >> $1 ; write_key >> $1 ; write_Val1 title >> $1 ; multi_wr "author organization address edition month" >> $1 multi_wr "year note" >> $1 echo } >> $1 ; fi ;; 8) read_Val key ; multi_rd1 "author title school year" multi_rd "address month note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @masterthesis { >> $1 ; write_key >> $1 ; multi_wr1 "author title school year" >> $1 multi_wr "address month note" >> $1 echo } >> $1 ; fi ;; 9) read_Val key ; multi_rd "author title howpublished month year note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @misc { >> $1 ; write_key >> $1 ; multi_wr "author title howpublished month year note" >> $1 echo } >> $1 ; fi ;; 10) read_Val key ; multi_rd1 "author title school year" multi_rd "address month note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @phdthesis { >> $1 ; write_key >> $1 ; multi_wr1 "author title school year" >> $1 multi_wr "address month note" >> $1 echo } >> $1 ; fi ;; 11) read_Val key ; multi_rd1 "title year" multi_rd "editor publisher organization address" multi_rd "month note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @proceedings { >> $1 ; write_key >> $1 ; multi_wr1 "title year" >> $1 multi_wr "editor publisher organization address" >> $1 multi_wr "month note" >> $1 echo } >> $1 ; fi ;; 12) read_Val key ; multi_rd1 "author title institution year" multi_rd "type number address month note" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @techreport { >> $1 ; write_key >> $1 ; multi_wr1 "author title institution year" >> $1 multi_wr "type number address month note" >> $1 echo } >> $1 ; fi ;; 13) read_Val key ; multi_rd1 "author title note" multi_rd "month year" confirm ; if [ "$yes_no" = "Y" ] then echo >> $1 echo -n @unpublished { >> $1 ; write_key >> $1 ; multi_wr1 "author title note" >> $1 multi_wr "month year" >> $1 echo } >> $1 ; fi ;; h|H) cat << EOF | more -------------------------------------------------------- To skip any entry press . Fields are marked as (R) or (O) specifying Required or Optional. Double quotes need not be put, they are automatically inserted by the software. To insert more than one line for a particular field, end the line with a backslash. Following are the explanations of various entry types: article : An article from a journal or magazine. book : A book with an explicit publisher. booklet : A work that is printed and bound but without a named publisher or sponsoring institution. conference : The same as inproceedings. inbook : A part of book, which may be a chapter and/or a range of pages. incollection : A part of book with it's own title. inproceedings : An article in a conference proceedings. manual : Technical documentation. masterthesis : A Master's thesis. misc : Use this type when nothing else fits. phdthesis : A Ph.D thesis. proceedings : The proceedings of a conference. techreport: A report published by a school or other institution, usually numbered within a series. unpublished : A document with an author and title but not formally published. --------------------------------------------------------- EOF ;; e|E) vi $1 ;; c|C) echo ; echo "Takes a while....... Hang on" sed -n '/^[ ]*@/p' $1 | awk 'BEGIN {FS="," ; RS="{"} { print $1 }' | awk '{if ( $1 != "" ) print $1}'| sort | uniq -d | more ;; esac } ext_fl="N" if [ -z "$1" ] then echo "You must specify a bibliography file (database)." echo Usage : $0 filename else while [ "$ext_fl" != "Y" ] do Entry_bib $1 echo echo -n "Do you want to exit (y/n) : " ; read ext_fl; if [ -z "$ext_fl" ] then ext_fl="N" fi if [ "$ext_fl" = "y" ]||[ "$ext_fl" = "yes" ]|| \ [ "$ext_fl" = "Y" ] then ext_fl="Y" fi done fi ------------> CUT HERE <----------------------- -- _ ||Internet: skdutta@cssun.tamu.edu ( /_ _ / --/-/- _ ||Bitnet : skd8107@tamvenus.bitnet __)_/(_____(_/_(_/_(_(__(_/_______ ||Uucp : uunet!cssun.tamu.edu!skdutta .. ||Yellnet: (409) 846-8803