"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/c2btools/ris2bib" (12 Feb 2021, 2793 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "ris2bib": 2.0.0_vs_2.0.1.

    1 #!/bin/sh
    2 #-------------------------------------------------------------------------------
    3 # ris2bib  --  Script to convert RIS format to BibTeX
    4 # cb2Bib Tools
    5 #
    6 # Copyright (C) 2005-2021 by Pere Constans
    7 # constans@molspaces.com
    8 #
    9 # Improvements and modifications:
   10 # Copyright (C) 2009 by Filippo Rusconi
   11 # rusconi@mnhn.fr
   12 #
   13 # May/June 2009:
   14 # - Added checks to ensure that the used commands are available on
   15 #   system.
   16 # - Make use of mktemp to create a temp directory.
   17 #
   18 # See LICENSE file that comes with this distribution
   19 #
   20 # Usage: ris2bib input_ris output_bib
   21 #-------------------------------------------------------------------------------
   22 # Using ris2xml and xml2bib utilities from:
   23 # http://bibutils.refbase.org/
   24 #-------------------------------------------------------------------------------
   25 
   26 #-------------------------------------------------------------------------------
   27 # Init variables
   28 #-------------------------------------------------------------------------------
   29 # Modify accordingly
   30 #ris2xml=/usr/local/bin/ris2xml
   31 #xml2bib=/usr/local/bin/xml2bib
   32 ris2xml=ris2xml
   33 xml2bib=xml2bib
   34 ris2xml_flags="-u"
   35 xml2bib_flags="-sd -b"
   36 #-------------------------------------------------------------------------------
   37 
   38 # Immediately check that the needed programs are there:
   39 "${ris2xml}" --version > /dev/null 2>&1
   40 
   41 if [ "$?" != "0" ]
   42 then
   43     echo "Program ris2xml (suite bibutils) is required."
   44     echo "Set it in your path, and/or modify $0 accordingly."
   45     echo "Ending processing."
   46     exit 1
   47 fi
   48 
   49 "${xml2bib}" --version > /dev/null 2>&1
   50 
   51 if [ "$?" != "0" ]
   52 then
   53     echo "Program xml2bib (suite bibutils) is required."
   54     echo "Set it in your path, and/or modify $0 accordingly."
   55     echo "Ending processing."
   56     exit 1
   57 fi
   58 
   59 # Make sure we trap errors (we put that after the tests above because
   60 # we need the tests to fail, in case, without exiting immediately).
   61 set -e
   62 
   63 # Getting filenames from command line
   64 echo "cb2Bib Tools: Script to convert RIS format to BibTeX"
   65 echo ""
   66 echo "It uses external package bibutils from"
   67 echo "http://bibutils.refbase.org/"
   68 echo ""
   69 if test "$#" != 2; then
   70     cat <<EOF
   71 Usage: $0 input_ris output_bib
   72 EOF
   73     exit 2
   74 fi
   75 
   76 # Create temporary directory
   77 # Note that we use the mktemp utility that ensures that
   78 # we do not overwrite any preexisting directory
   79 tmp_dir=$(mktemp -d --tmpdir c2b_tools_tmp.XXXXXXXX)
   80 
   81 # Setting files
   82 ris="$1"
   83 bib="$2"
   84 work_dir="$PWD"
   85 
   86 # Preparing temporary files
   87 cp "$ris" "${tmp_dir}"/c2b_tmp.ris
   88 cp "$ris" "${tmp_dir}"/c2b_tmp.bib
   89 
   90 # bibutils procedure
   91 cd "${tmp_dir}"
   92 "${ris2xml}" ${ris2xml_flags} c2b_tmp.ris > c2b_tmp.xml
   93 "${xml2bib}" ${xml2bib_flags} c2b_tmp.xml | sed 's%^ISSUE=%NUMBER=%g' > c2b_tmp.bib
   94 
   95 # Clean up
   96 cd "${work_dir}"
   97 cp "${tmp_dir}"/c2b_tmp.bib "$bib"
   98 rm -rf "${tmp_dir}"
   99 echo ""
  100 echo "$0 ended."