%From @mitvma.mit.edu:cjmchale@cs.tcd.ie Mon Jul  2 19:48:31 1990
%Return-Path: <@mitvma.mit.edu:cjmchale@cs.tcd.ie>
%Received: from mitvma.mit.edu by life.ai.mit.edu (4.1/AI-4.10) id AA07748; Mon, 2 Jul 90 19:48:24 EDT
%Received: from MITVMA.MIT.EDU by mitvma.mit.edu (IBM VM SMTP R1.2.1MX) with BSMTP id 4555; Mon, 02 Jul 90 19:47:32 EDT
%Received: from IRLEARN.UCD.IE by MITVMA.MIT.EDU (Mailer R2.05) with BSMTP id
% 0199; Mon, 02 Jul 90 19:47:23 EDT
%Received: from ccvax.ucd.ie by IRLEARN.UCD.IE (Mailer R2.03B) with BSMTP id
% 2688; Mon, 02 Jul 90 14:45:10 GMT
%Received: from cs.tcd.ie by ccvax.ucd.ie; Mon, 2 Jul 90 14:38 GMT
%Received: from csaran.cs.tcd.ie by cs.tcd.ie; Mon, 2 Jul 90 14:42 GMT
%Date: Mon, 2 Jul 90 14:39:44 BST
%From: cjmchale%cs.tcd.ie@mitvma.mit.edu
%Subject: Re: BibTex <-> Tib/Refer converter wanted
%Sender: cjmchale%cs.tcd.ie@mitvma.mit.edu
%To: tmb@wheaties.ai.mit.edu
%Newsgroups: comp.text.tex,comp.text
%In-Reply-To: <9290@life.ai.mit.edu>
%Organization: DSG, Dept. of Comp.Sc., Trinity College, Dublin, Ireland.
%Message-Id:  <9007021439.aa02454@csaran.cs.tcd.ie>
%Status: R
%
%In article <9290@life.ai.mit.edu> you write:
%>I am looking for a converter to convert BibTex bibliography files
%>to Tib/Refer files and vice versa. Even if you have just a
%>shell script that isn't completely general, that would be fine.
%>
%>                                       Thanks, Thomas.
%>
%>PS: thanks to everyone who responded to my question about refer-style
%>bibliography processors. The answer was to get Tib from ENEEVAX.UMD.EDU.
%
%You may not be aware of this but BibTeX is actually a (special
%purpose) programming language! The source code file for a BibTeX
%program is the bibliography style file (".bst"). BibTeX reads in the
%bibtex entries and the code in the ".bst" file munges them about and
%usually writes LaTeX code out. However, if you learn how to program
%BibTeX (as the local guru for its manual---it's only about 10 or 20
%pages long) then you could write your own custom ".bst" files that
%will do exactly what you want them to. In particular, instead of
%writing out LaTeX style code it could write out "Hello World" or even
%generate a file that looks quite like a refer style file.
%
%It would be difficult to get such a ".bst" file to convert TeX
%commands (which might be imbedded in the bib entries) to refer
%commands but the actual changing of "author=..." to %A ... is trivial
%(for the most part; there are a few mismatches between the fields that
%BibTeX and refer use).
%
%Anyway, I've written such a ".bst" file and a UNIX "sh" shell script
%to automate the process. I've included them below.
%
%------------------- Start of file "refer.bst" ---------------------
%
% 8/4/'90
% Hacked together by Ciaran McHale (cjmchale@cs.tcd.ie) to translate
% BibTeX bibliographies into refer format
% Based on a bib style file by Kannan Varadhan
%


ENTRY
  {                                     % entry fields
        abstract                % non standard
    address
        annote                  % non standard
    author
    booktitle
    chapter
    edition
    editor
    howpublished
    institution
    journal
    key
        keywords                % non standard
    month
    note
    number
    organization
    pages
    publisher
    school
    series
    title
    type
    volume
    year
  }
  {}                                    % no integer entry variables
  { label extra.label sort.label }      % label entry variables


STRINGS { s t a.name }


FUNCTION {not}
{   { #0 }
    { #1 }
  if$
}

FUNCTION {and}
{   'skip$
    { pop$ #0 }
  if$
}

FUNCTION {or}
{   { pop$ #1 }
    'skip$
  if$
}

INTEGERS { nameptr namesleft numnames }

FUNCTION {handle.names}
{ 't :=         % type e.g. "A" for authors, "E" for editors
  's :=         % the string containing the names
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }

    { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 'a.name :=

      a.name "others" =
        'skip$  % don't print out "%A others"
        { "%" t * " " * a.name * write$ newline$ }
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}



MACRO {jan} {"January"}

MACRO {feb} {"February"}

MACRO {mar} {"March"}

MACRO {apr} {"April"}

MACRO {may} {"May"}

MACRO {jun} {"June"}

MACRO {jul} {"July"}

MACRO {aug} {"August"}

MACRO {sep} {"September"}

MACRO {oct} {"October"}

MACRO {nov} {"November"}

MACRO {dec} {"December"}






MACRO {acmcs} {"ACM Computing Surveys"}

MACRO {acta} {"Acta Informatica"}

MACRO {cacm} {"Communications of the ACM"}

MACRO {ibmjrd} {"IBM Journal of Research and Development"}

MACRO {ibmsj} {"IBM Systems Journal"}

MACRO {ieeese} {"IEEE Transactions on Software Engineering"}

MACRO {ieeetc} {"IEEE Transactions on Computers"}

MACRO {ieeetcad}
 {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}

MACRO {ipl} {"Information Processing Letters"}

MACRO {jacm} {"Journal of the ACM"}

MACRO {jcss} {"Journal of Computer and System Sciences"}

MACRO {scp} {"Science of Computer Programming"}

MACRO {sicomp} {"SIAM Journal on Computing"}

MACRO {tocs} {"ACM Transactions on Computer Systems"}

MACRO {tods} {"ACM Transactions on Database Systems"}

MACRO {tog} {"ACM Transactions on Graphics"}

MACRO {toms} {"ACM Transactions on Mathematical Software"}

MACRO {toois} {"ACM Transactions on Office Information Systems"}

MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}

MACRO {tcs} {"Theoretical Computer Science"}





STRINGS { is.digit.tmp }

FUNCTION {is.digit}

{
  'is.digit.tmp :=
  is.digit.tmp "0" =
  is.digit.tmp "1" = or
  is.digit.tmp "2" = or
  is.digit.tmp "3" = or
  is.digit.tmp "4" = or
  is.digit.tmp "5" = or
  is.digit.tmp "6" = or
  is.digit.tmp "7" = or
  is.digit.tmp "8" = or
  is.digit.tmp "9" = or
}

FUNCTION {handle.maybe.empty}
{
  't :=
  duplicate$
  empty$
    'pop$
    { "%" t * " " * swap$ * write$ newline$ }
  if$
}

FUNCTION {translate}
{
  newline$      % get a blank line between each entry

  title "T" handle.maybe.empty
  booktitle "B" handle.maybe.empty

  % there may be multiple authors so handle it differently
  author empty$
    { " empty author in " cite$ * warning$ }
    { author "A" handle.names }
  if$
  editor "E" handle.maybe.empty
  journal "J" handle.maybe.empty
  keywords "K" handle.maybe.empty
  cite$ "L" handle.maybe.empty
  volume "V" handle.maybe.empty
  abstract "X" handle.maybe.empty

  % The date, if present may be just the year or both the month and year
  % or might even be just the month
  month empty$ year empty$ and
    'skip$      % no date of publication so nothing to do
    {
      month empty$      % I'm using the if statement because I'm not
        { "" }          % sure that--- month " " year * --- would work.
        { month " " * } % (The manual doesn't mention anything about
      if$               % this so I'm playing safe)
      year empty$
        { "" }
        { year }
      if$
      *
      "D" handle.maybe.empty
    }
  if$
  pages "P" handle.maybe.empty
  note "O" handle.maybe.empty
  number "N" handle.maybe.empty
  series "S" handle.maybe.empty
  annote "Y" handle.maybe.empty
  address "C" handle.maybe.empty

}


FUNCTION {article} { translate }
FUNCTION {book} { translate }
FUNCTION {booklet} { translate }
FUNCTION {inbook} { translate }
FUNCTION {incollection} { translate }
FUNCTION {inproceedings} { translate }
FUNCTION {manual} { translate }
FUNCTION {mastersthesis} { translate }
FUNCTION {misc} { translate }
FUNCTION {phdthesis} { translate }
FUNCTION {proceedings} { translate }
FUNCTION {techreport} { translate }
FUNCTION {unpublished} { translate }
FUNCTION {default.type} { translate }


READ

ITERATE {call.type$}
------------------- End of file "refer.bst" ---------------------

------------------- Start of file "bib2refer" ---------------------
#! /bin/sh
# Written by Ciaran McHale (cjmchale@cs.tcd.ie) 8/4/'90

FN=`basename $0`

case $# in
0)      echo "Usage: $FN <filename> [<filename>*]" ; exit 1 ;;
esac

#
# This shell script uses bibtex and a custom made bibliography style file
# to translate BibTeX bibliographies into refer format. It is based on
# another shell script written by Eamonn McManus, Alan Judge and Ciaran McHale.
#
STYLE=refer     # BibTeX-to-refer style file

FILE=tmp
RESULT=${FN}.out
BIBFILE=${FILE}.bib

# clean up if interrupted
trap 'rm ${FILE}.bbl ${FILE}.aux ${FILE}.blg ; exit 1' 1 2 3 15

> ${FILE}.bbl           # truncate the files
> ${FILE}.aux
> ${FILE}.blg

#
#Hand craft the .aux file
#
BIBRECD=""
for i
do
        file="`echo $i | sed 's/.bib//'`"
        BIBRECD="${BIBRECD},${file}"
done
BIBRECD="`echo $BIBRECD | sed 's/^,//'`"        # remove 1st " "

echo "\bibstyle{$STYLE}"        >> ${FILE}.aux
echo "\bibdata{$BIBRECD}"       >> ${FILE}.aux

# Read all the files (command line arguments) and use them to write
# the necessary info into the .aux file.
for i
do
        file="`echo $i | sed 's/.bib//'`"
        bibfile=${file}.bib
        echo FILE $bibfile has `egrep '^@' $bibfile | wc -l` records
        # create the .aux file with \citation commands in it
        sed -n 's/^@.*[{(][     ]*\(.*\)/\\citation {\1}/p' $bibfile  |
                sed 's/[,       ]//g' >>${FILE}.aux

done

bibtex $FILE
cp ${FILE}.bbl ${RESULT}

echo; echo ${FN}: output in ${RESULT}; echo

# Cleanup...
rm ${FILE}.bbl ${FILE}.aux ${FILE}.blg

exit 0
------------------- End of file "bib2refer" ---------------------


This was written as a quick hack and I haven't tested it thoroughly so
if you see any problems then be prepared to get out the BibTeX
programming manual and change a line or two (hopefully that won't be
necessary).


Ciaran.
--
Ciaran McHale
Department of Computer Science, Trinity College, Dublin 2, Ireland.
Telephone: +353-1-772941 ext 1538    FAX: +353-1-772204   Telex: 93782 TCD EI
email: cjmchale@cs.tcd.ie       or      cjmchale%cs.tcd.ie@cunyvm.cuny.edu
        My opinions and bad language do not represent Trinity