root/misc/trunk/bin/importbookcd.sh

Revision 1899, 3.1 KB (checked in by chous, 18 months ago)

Added copyright notices. refs #117

  • Property svn:executable set to *
Line 
1#!/bin/sh -f
2###############################################################################
3#
4#  Copyright (C) 2007  Jose San Leandro Armendáriz
5#                      chous@acm-sl.org
6#
7#  This library is free software; you can redistribute it and/or
8#  modify it under the terms of the GNU General Public
9#  License as published by the Free Software Foundation; either
10#  version 2 of the License, or any later version.
11#
12#  This library is distributed in the hope that it will be useful,
13#  but WITHOUT ANY WARRANTY; without even the implied warranty of
14#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15#  General Public License for more details.
16#
17#  You should have received a copy of the GNU General Public
18#  License along with this library; if not, write to the Free Software
19#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20#
21#
22#  Thanks to ACM S.L. for distributing this library under the LGPL license.
23#  Contact info: jose.sanleandro@acm-sl.com
24#  Postal Address: c/Playa de Lagoa, 1
25#                  Urb. Valdecabañas
26#                  Boadilla del monte
27#                  28660 Madrid
28#                  Spain
29#
30###############################################################################
31#
32# Filename: $RCSfile: importbookcd.sh $
33#
34# Author: Jose San Leandro Armendáriz
35#
36# Description: Writes a minimal BibTeX entry for a given file.
37#
38###############################################################################
39
40# functions
41usage () {
42cat << USAGE
43
44$0 file
45
46Writes a minimal BibTeX entry for given file.
47
48Parameters:
49    file the file to process.
50USAGE
51        exit 1;
52}
53
54checkInput() {
55
56  if [ "x${file}" == "x" ]; then
57    file=$@;
58  fi;
59  if [ "x${file}" == "x" ]; then
60    from_stdin=true;
61  fi;
62  [ "x${from_stdin}" == "xfalse" ] && [ "x${file}" == "x" ] && usage
63}
64
65generate_bibtex() {
66  _dir=`echo "$1" | awk -F"/" 'BEGIN{any=0;}{for(i=2;i<=NF;i++){any=1;printf("%s", $i);}}END{if(any==1)print "";}'`
67  shift
68  echo "$@" | \
69  awk -F"-" -v quote="'" -v dollar="$" -v dir="${_dir}" 'BEGIN{printf("echo -n \"@book{\"\n");}{printf("echo \"%s\" | awk -F\".\" %s{if(NF==1){printf(\"%%s\", %si);}else{for (i=1;i<NF;i++){printf(\"%%s\", %si);}}}END{print \",\";}%s | tr \" \" \"_\"\necho -n \"  title=\\\"\"\necho \"%s\" | awk -F\".\" %s{if(NF==1){printf(\"%%s\", %si)}else{for (i=1;i<NF;i++){printf(\"%%s\", %si);}}}%s\necho \"\\\",\"\necho \"  publisher=\\\"%s\\\"\",\necho \"  note=\\\"%s/%s\\\"\"\necho }\n", $2, quote, dollar, dollar, quote, $2, quote, dollar, dollar, quote, $1, dir, $0);}' | sh
70}
71
72from_stdin=false;
73
74checkInput $@
75
76read line
77while [ "x${line}" != "x" ];
78do
79generate_bibtex "`dirname "$line"`" "`basename "$line"`"
80read line
81done
82
83if [ "x${from_stdin}" == "xfalse" ] && [ "x${file} != "x" ]; then
84generate_bibtex "`dirname "$file"`" "`basename "$file"`"
85fi
86
87# | awk -F"-" -v quote="'" -v dollar="$" 'BEGIN{printf("echo -n \"@book{\"\n");}{printf("echo %s | awk -F\".\" %s{print %s1;}%s | tr \" \" \"_\"\necho -n \"  title=\\\"\"\necho %s | awk -F\".\" %s{printf(\"%%s\", %s1);}%s\necho \"\\\"\"\necho \"  publisher=\\\"%s\\\"\"\necho }\n", $2, quote, dollar, quote, $2, quote, dollar, quote, $1);}'
Note: See TracBrowser for help on using the browser.