source: trunk/bibopa.sh @ 65

Last change on this file since 65 was 65, checked in by pinsard, 16 years ago

some improvemnt but bibopa.sh and superbib01_txt.xsl are still not fully compatible

  • Property svn:keywords set to Id
File size: 23.9 KB
RevLine 
[2]1#!/bin/bash
2#
3#    Behera, S. K., J. Luo, S. Masson, S. Rao, S. Gualdi, P. Delecluse, A.
4#    Navarra and T. Yamagata, 2004 : Paramount Impact of the Indian Ocean
5#    Dipole on the East African Short Rains: A CGCM Study, J. Climate, In
6#    press.
[22]7#
[2]8#    donnerait
[22]9#
[56]10#    <biblioentry xml:id="behara2004">
[2]11#    <authorgroup>
12#    <author><surname>Behera</surname> <firstname>S. K.</firstname> </author>
13#    <author><firstname>J.</firstname> <surname>Luo</surname></author>
14#    <author><firstname>S.</firstname> <surname>Masson</surname></author>
15#    <author><firstname>S.</firstname> <surname>Rao</surname></author>
16#    <author><firstname>S.</firstname> <surname>Gualdi</surname></author>
17#    <author><firstname>P.</firstname> <surname>Delecluse</surname></author>
18#    <author><firstname>A.</firstname> <surname>Navara</surname></author>
19#    <author><firstname>T.</firstname> <surname>Yamagata</surname></author>
20#    </authorgroup>
21#    <date>2004</date>
22#    <title>Paramount Impact of the Indian Ocean Dipole on the East African
23#    Short Rains: A CGCM Study</title>
24#    <publishername>J. Climate</publishername>
[45]25#    <biblioid class="doi">doi</biblioid>
[2]26#    <bibliomisc role="pseudoref">In press.</bibliomisc>
[22]27#    <bibliomisc role="internalref">from
[2]28#    http://www.lodyc.jussieu.fr/~opatlod/NEMO_v1/6_Menu/2_page/index.html
29#    2007-03-29T16:24:31Z fplod by hand</bibliomisc>
30#    </biblioentry>
31#
[45]32#   @book{MetReiCoh2004 ,
33#      author    = {Michael Metcalf and
34#              John Reid and Malcolm Cohen},
35#      title     = {Fortran 95/2003 explained},
36#      year      = {2004},
37#      publisher = {Oxford University Press},
38#      edition   = {Third},
39#      ISBN      = {0-19-852693-8},
40#      pages = {434}
41#   }
42# donnerait
[56]43#    <biblioentry xml:id="MetReiCoh2004">
[45]44#    <authorgroup>
45#    <author><firstname>Michael</firstname> <surname>Metcalf</surname></author>
46#    <author><firstname>John</firstname> <surname>Reid</surname></author>
47#    <author><firstname>Malcolm</firstname> <surname>Cohen</surname></author>
48#    </authorgroup>
49#    <date>2004}</date>
50#    <title>Fortran 95/2003 explained</title>
51#    <publisher><publishername>Oxford University Press</publishername></publisher>
52#    <biblioid class="isbn">0-19-852693-8</biblioid>
53#    <pagenums>434</pagenums>
54#    <edition>Third</edition>
[22]55#
[2]56# example :
[47]57# $ ./bibopa.sh -p birefnemo -i data/biball.txt -t raw
[56]58# $ ./bibopa.sh -p bibrefnemo -i data/mail2007-05-10T09:01:56Z -t mailbody
[47]59# $ ./bibopa.sh -p polyfortran -i data/petitpolyfp.bib -t bibtex -l fr
[56]60# $ ./bibopa.sh -p demo1 -i data/bibdemo1.txt -t raw -l fr
[2]61#
[31]62# see also mailtouser.sh
[2]63#
64# original location :
65# /usr/home/fplod/incas/bibnemo/src/bibnemomaf/bibopa.sh sur cerbere.locean-ipsl.upmc.fr
66#
67# update
[22]68# ++ gestion des comments
[2]69# ++ gestion des id existants (cf à la fin)
70# ++ option debug
[33]71# $Id$
[56]72# fplod 2008-04-30T07:11:58Z aedon.locean-ipsl.upmc.fr (Darwin)
73# chgt for dbk5 out
74# xmlto 0.0.18 does'nt like this docbook release. remove
75# usage of xml (xmlstarlet) for validation
76# bug fix
77# add journal names from demo1
[47]78# fplod 2008-03-12T16:11:07Z aedon.locean-ipsl.upmc.fr (Darwin)
79# add -p option (to overide bibrefnemo in file name and id)
80# add -l option by default en
[44]81# fplod 2008-03-11T11:25:27Z aedon.locean-ipsl.upmc.fr (Darwin)
82# add bibtex entry (not finished)++
[21]83# fplod 2007-06-20T17:18:02Z aedon.locean-ipsl.upmc.fr (Darwin)
84# <bibliomisc role="id"> replace by <biblioid class="doi">
[15]85# smasson 2007-06-07T16:43:42Z arete.locean-ipsl.upmc.fr (Darwin)
86# Add journals
[2]87# fplod 2007-05-10T09:17:09Z aedon.locean-ipsl.upmc.fr (Darwin)
88# dernières touches
89# fplod 2007-04-25T10:59:49Z cerbere.locean-ipsl.upmc.fr (Linux)
90# add a filein parameter and an option for mailbody
91# comments  (line begininig with #) are now possible
92# Sebastien Masson avril 2007 creation
[22]93#
[2]94
95rmbl () {
[22]96    echo "${1}" | sed -e "s/^ *//" | sed -e "s/ *$//"
[2]97}
98cleanname () {
[22]99    echo "${1}" | sed -e "s/^ *//" \
[2]100        -e "s/^ *,//" \
101        -e "s/^ *;//" \
102        -e "s/^ *\.//" \
103        -e "s/ *$//" \
104        -e "s/, *$//" \
105        -e "s/; *$//" \
106        -e "s/\. *$//"
107}
108#
109set -o posix
[56]110command=$(basename ${0})
[2]111log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
112log=/tmp/${command}.${log_date}
113#
114# test if xsltproc is available
115type xsltproc 1> /dev/null 2>&1
116status=${?}
117if [ ${status} -ne 0 ]
118then
119 echo " eee : xsltproc not found"
120 exit 1
121fi
[64]122unset status
[2]123#
[56]124# test if xml  is available
125type xml 1> /dev/null 2>&1
126status=${?}
127if [ ${status} -ne 0 ]
128then
129 echo " eee : xml not found"
130 exit 1
131fi
[64]132unset status
[56]133#
[47]134usage=" Usage : ${command} -i filein -t type -p project -l lang"
[2]135#
[47]136# default
137lang=en
138#
139minargcount=6
[56]140#echo " narg ${#}"
[22]141if [ ${#} -lt ${minargcount} ]
142then
[47]143   echo "eee : not enought arguments"
144   echo "${usage}"
145   exit 1
[22]146fi
[64]147unset minargcount
[22]148#
149while [ ! -z "${1}" ]
[2]150do
151 case ${1} in
[22]152 -i) # filein
[2]153  filein=${2}
154  shift
155 ;;
[22]156 -t) # type
[2]157  type=${2}
158  shift
159 ;;
[47]160 -p)
161  project=${2}
162  shift
163 ;;
164 -l)
165  lang=${2}
166  shift
167 ;;
[22]168 -h)
169  echo "${usage}"
170  exit 0
171 ;;
[2]172 *) # other choice
173  echo "${usage}"
174  exit 1
175 ;;
176 esac
177 shift # next flag
178done
[64]179unset usage
[22]180#
[2]181set -u
182#
[22]183# check for filein
[2]184if [ ! -f ${filein} ]
185then
[47]186   echo "eee : ${filein} not found"
187   exit 1
[2]188fi
189#
190case ${type} in
191raw) # file like data/biball.txt
192 fileraw=${filein}
193;;
194mailbody) # file like data/mail2007-04-25T08:58:16Z.txt
195 fileraw=/tmp/$(basename ${filein}).raw
196 echo "# from ${filein}" > ${fileraw}
197 echo "# ${log_date}" >> ${fileraw}
198 echo "# corrections" >> ${fileraw}
199 grep "correction_.*=" ${filein} | grep -v "correction_.*=$" | \
200 sed -e "s/correction_.*=//">> ${fileraw}
201 echo "# new references" >> ${fileraw}
202 awk "/newreferences=/,/comments=/" ${filein} | sed -e "s/newreferences=//" -e "/comments=/d" >> ${fileraw}
203 #more ${fileraw} # ++ if debug
204 #read a #++ if debug
205;;
[44]206bibtex) # file like data/petitpoly.bib
207 fileraw=/tmp/$(basename ${filein}).raw
[45]208 awk -f join_endcomma.awk ${filein} >> ${fileraw}
209 #more ${fileraw} # ++ if debug
210 #read a #++ if debug
[44]211;;
[22]212*)
[44]213   echo "eee : type should be raw, mailbody or bibtex"
[2]214   exit 1
215;;
216esac
217#
218# check for output
219fileou=$( basename ${filein} .txt).xml
220if [ -f ${fileou} ]
221then
222   echo "eee : ${fileou} already exist"
[56]223   exit 1
[2]224fi
225#
[64]226ij=1
227jlist[${ij}]="J. Climate"
228ij=$(( ${ij} + 1))
229jlist[${ij}]="Journal of Climate"
230ij=$(( ${ij} + 1))
231jlist[${ij}]="Ocean Modelling"
232ij=$(( ${ij} + 1))
233jlist[${ij}]="Geophys. Res. Lett."
234ij=$(( ${ij} + 1))
235jlist[${ij}]="J. Geophys. Res."
236ij=$(( ${ij} + 1))
237jlist[${ij}]="Tellus A"
238ij=$(( ${ij} + 1))
239jlist[${ij}]="Tellus B"
240ij=$(( ${ij} + 1))
241jlist[${ij}]="J. Phys. Oceanogr."
242ij=$(( ${ij} + 1))
243jlist[${ij}]="Clim. Dyn."
244ij=$(( ${ij} + 1))
245jlist[${ij}]="Climate Dynamics"
246ij=$(( ${ij} + 1))
247jlist[${ij}]="Dyn. Atmos. Oceans"
248ij=$(( ${ij} + 1))
249jlist[${ij}]="Mon. Wea. Rev."
250ij=$(( ${ij} + 1))
251jlist[${ij}]="Global Biogeochem. Cycles"
252ij=$(( ${ij} + 1))
253jlist[${ij}]="Nonlinear Processes in Geophysics"
254ij=$(( ${ij} + 1))
255jlist[${ij}]="Ocean Science"
256ij=$(( ${ij} + 1))
257jlist[${ij}]="J. Mar. Systems"
258ij=$(( ${ij} + 1))
259jlist[${ij}]="J. Atmos. Sc."
260ij=$(( ${ij} + 1))
261jlist[${ij}]="Proc. Royal Soc."
262ij=$(( ${ij} + 1))
263jlist[${ij}]="Bull. Amer. Meteorol. Soc."
264ij=$(( ${ij} + 1))
265jlist[${ij}]="Ocean Dyn."
266ij=$(( ${ij} + 1))
[65]267jlist[${ij}]="Geophysical Monograph Series, Earth's Climate: The Ocean-Atmosphere Interaction"
[64]268ij=$(( ${ij} + 1))
269jlist[${ij}]="Paleoceanography"
270ij=$(( ${ij} + 1))
271jlist[${ij}]="Annales Geophysicae"
272ij=$(( ${ij} + 1))
273jlist[${ij}]="Annals of Geophys."
274ij=$(( ${ij} + 1))
275jlist[${ij}]="Deep Sea Research Part II: Topical Studies in Oceanography"
276ij=$(( ${ij} + 1))
277jlist[${ij}]="Deep Sea Res. II"
278ij=$(( ${ij} + 1))
279jlist[${ij}]="Atmospheric Chemistry and Physics"
280ij=$(( ${ij} + 1))
281jlist[${ij}]="Atmospheric Chemistry and Physics Discussions"
282ij=$(( ${ij} + 1))
283jlist[${ij}]="Earth Plan. Sc. Lett."
284ij=$(( ${ij} + 1))
285jlist[${ij}]="J. Mar. Res."
286ij=$(( ${ij} + 1))
287jlist[${ij}]="PCMDI Report Series"
288ij=$(( ${ij} + 1))
289jlist[${ij}]="J. Mar. Syst."
290ij=$(( ${ij} + 1))
291jlist[${ij}]="Note du Pole de Modelisation"
292ij=$(( ${ij} + 1))
293jlist[${ij}]="Calculateurs Paralleles"
294ij=$(( ${ij} + 1))
295jlist[${ij}]="Note Scientifique du Pole de Modelisation"
296ij=$(( ${ij} + 1))
297jlist[${ij}]="Lecture Notes in Computer Science"
298ij=$(( ${ij} + 1))
299jlist[${ij}]="Prog. Oceanogr."
300ij=$(( ${ij} + 1))
301jlist[${ij}]="Deep Sea Research Part I: Oceanographic Research Papers"
302ij=$(( ${ij} + 1))
303jlist[${ij}]="Deep Sea Res. I"
304ij=$(( ${ij} + 1))
305jlist[${ij}]="IEEE Trans. Geosci. Remote Sensing"
306ij=$(( ${ij} + 1))
307jlist[${ij}]="ECMWF Tech. Memorandum"
308ij=$(( ${ij} + 1))
309jlist[${ij}]="J. Environ. Radioactivity"
310ij=$(( ${ij} + 1))
311jlist[${ij}]="Int. WOCE Newsletter"
312ij=$(( ${ij} + 1))
313jlist[${ij}]="C. R. Acad. Sci. Paris"
314ij=$(( ${ij} + 1))
315jlist[${ij}]="C. R. Acad. Sci. Paris, Earth and Planetary Sciences"
316ij=$(( ${ij} + 1))
317jlist[${ij}]="In The mathematics of models for climatology and environment"
318ij=$(( ${ij} + 1))
319jlist[${ij}]="Oceanol. Acta"
320ij=$(( ${ij} + 1))
321jlist[${ij}]="The global atmosphere and ocean system"
322ij=$(( ${ij} + 1))
323jlist[${ij}]="NATO Advanced Study Institute"
324ij=$(( ${ij} + 1))
325jlist[${ij}]="WCRP"
326ij=$(( ${ij} + 1))
327jlist[${ij}]="The Courier"
328ij=$(( ${ij} + 1))
329jlist[${ij}]="Elsevier Oceanographic Series"
330ij=$(( ${ij} + 1))
331jlist[${ij}]="In Conference Proceedings of the 1988 International Conference on Supercomputing"
332ij=$(( ${ij} + 1))
333jlist[${ij}]="In Science and engineering on Cray Supercomputers"
334ij=$(( ${ij} + 1))
335jlist[${ij}]="In Modeling the Earth's Climate and its Variability"
336ij=$(( ${ij} + 1))
337jlist[${ij}]="Fish. Oceanogr."
338ij=$(( ${ij} + 1))
339jlist[${ij}]="Q. J. R. Meteor. Soc."
340ij=$(( ${ij} + 1))
341jlist[${ij}]="In High performance computing in the geosciences"
342ij=$(( ${ij} + 1))
343jlist[${ij}]="Int. J. Numer. Meth. in Fluids"
344ij=$(( ${ij} + 1))
345jlist[${ij}]="Lecture notes in Physics"
346ij=$(( ${ij} + 1))
347jlist[${ij}]="J. Meterol. Soc. Japan"
348ij=$(( ${ij} + 1))
349jlist[${ij}]="Journal of Marine Systems"
350ij=$(( ${ij} + 1))
351jlist[${ij}]="Canadian Journal of Fisheries and Aquatic Sciences"
352ij=$(( ${ij} + 1))
353jlist[${ij}]="J. Atmos. Ocean. Tech."
354ij=$(( ${ij} + 1))
355jlist[${ij}]="EOS"
356ij=$(( ${ij} + 1))
357jlist[${ij}]="Nature"
358ij=$(( ${ij} + 1))
359jlist[${ij}]="Physics and Chemistry of the Earth, Part B: Hydrology, Oceans and Atmosphere"
360ij=$(( ${ij} + 1))
361jlist[${ij}]="Journal of Atmospheric and Oceanic Technology"
362ij=$(( ${ij} + 1))
363jlist[${ij}]="Lecture Notes in Computational Science Engineering"
364ij=$(( ${ij} + 1))
365jlist[${ij}]="In Greenhouse Gas Control Technologies"
366ij=$(( ${ij} + 1))
367jlist[${ij}]="Chemical Geology"
368ij=$(( ${ij} + 1))
369jlist[${ij}]="Marine Geology"
370ij=$(( ${ij} + 1))
371jlist[${ij}]="Developments in Paleoenvironmental Research"
372ij=$(( ${ij} + 1))
373jlist[${ij}]="Science"
374ij=$(( ${ij} + 1))
375jlist[${ij}]="In Mediterranean Climate Variability"
376ij=$(( ${ij} + 1))
377jlist[${ij}]="Global and Planetary Change"
378ij=$(( ${ij} + 1))
379jlist[${ij}]="Physical Review Letters"
[56]380#
381# following Journal name are fake ones for demo1 : references extracted from
382# Cantratrix Sopronica L. written by Georges Perec
383#find in http://www-rocq.inria.fr/who/Marc.Thiriet/PsFil/Biblio/cantatrix.ps
384ij=$(( ${ij} + 1))
[64]385jlist[$ij]="Res. Proc. neurophysiol. Fanatic Soc."
[56]386ij=$(( ${ij} + 1))
387jlist[$ij]="New Records Ass. J."
388ij=$(( ${ij} + 1))
389jlist[$ij]="Am. J. Allegrol."
390ij=$(( ${ij} + 1))
391jlist[$ij]="J. Neurochem. Neurocytol. Enzymol."
392ij=$(( ${ij} + 1))
393jlist[$ij]="Hammersmith J."
394ij=$(( ${ij} + 1))
395jlist[$ij]="Nasa Rept."
396ij=$(( ${ij} + 1))
397jlist[$ij]="C.r. Assoc. Conc. Lam."
398ij=$(( ${ij} + 1))
399jlist[$ij]="Gaz. med. franco-rus."
400ij=$(( ${ij} + 1))
401jlist[$ij]="Amer. J. music. Deciency"
[2]402#
403    cat <<EOF > ${fileou}
404<?xml version='1.0' encoding='ISO-8859-1'?>
[56]405<bibliography
406version="5.0"
407xmlns="http://docbook.org/ns/docbook"
408xml:id="bib${project}ref"
409xml:lang="${lang}">
410
411<info>
[2]412<date>$( date -u +"%Y-%m-%dT%H:%M:%SZ" )</date>
[56]413</info>
[2]414EOF
[64]415unset lang
[2]416#
417# strip comments
418fileraw_strict=/tmp/$(basename ${fileraw})_strict
419grep -v "^#" ${fileraw} > ${fileraw_strict}
420totlines=$( wc -l ${fileraw_strict} | awk '{print $1}' )
421l=1
[21]422while [ ${l} -le ${totlines}  ]
[2]423do
424# extract one line
425  line=$( sed -n ${l}p ${fileraw_strict} )
[21]426  orgline=$( echo ${line} | sed -e "s/--/- -/g" )
427  line=$( echo ${line} | sed -e "s/</\&lt;/g" -e "s/>/\&gt;/g" )
[46]428  # detect if bibtex or not bibtex (starting with @)
429  if [ ${line:0:1} != "@" ]
430  then
431     # parsing non bibtex line
432     bibtex=0
433     # before the first :
434       tmp=${line%%:*}
435     # before the last ,
436       auths=${tmp%,*},
[56]437     # replace "and" by ","
438       auths=$( echo "${auths}" | sed -e "s/ and /,/g" )
[46]439     # after the last ,
440       year=${tmp##*,}
441       year=$( rmbl "${year}" )
442     ## first author before the first .,
443       first=${auths%%.,*}.
444     # its firstname after the last ,
445       firstfn=${first##*,}
446       firstfn=$( rmbl "${firstfn}" )
447     # its surname ; before the first ,
448       firstsn=${first%%,*}
449       firstsn=$( rmbl "${firstsn}" )
450     ## ref id
451       refid=$( echo ${firstsn} | tr "[:upper:]" "[:lower:]" | tr -s " " "_"  | tr -s "'" "_" | recode -d -f ISO-8859-1..flat )${year}
[56]452       num=$( grep -c "<biblioentry xml:id=\"${refid}_[0-9][0-9]\">" ${fileou} )
[46]453       num=$(( ${num} + 1 ))
454       [ ${num} -le 9 ] && num=0${num}
455       refid=${refid}_${num}
[56]456       hasauthor=1
[46]457   else
458      # parsing bibtex line
459      bibtex=1
460      # before the first ,
461      tmp=${line%%,*}
462      endline=${line#*,}
463      # refid is after { and before the first comma
464      refid=${tmp#*{}
465      # ++ test if refid already exist
[47]466      # check if author field is there
467      echo ${endline} | grep -q "author"
468      hasauthor=${?}
[56]469      if [ ${hasauthor} -eq 0 ]
470      then
[47]471         auths=$( echo ${endline} | awk -F "," '{print $1}' | sed -e "s/\(author * = *{\)\(.*\)\(}\)/\2/")
[56]472         #echo "auths $auths" # genre  Michael Metcalf and John Reid and Malcolm Cohen
[47]473      else
474        echo "pas d'auteurs" # ++
475      fi
[46]476      endline=${endline#*,}
477      title=$( echo ${endline} | awk -F "," '{print $1}' | sed -e "s/\(title * = *{\)\(.*\)\(}\)/\2/")
[65]478      #echo "title : ${title}"
[46]479      endline=${endline#*,}
[56]480#echo ${endline} | awk -F "," '{print $1}' #++debug
[46]481      year=$( echo ${endline} | awk -F "," '{print $1}' | sed -e "s/\(year * = *{\)\(.*\)\(}\)/\2/")
482      endline=${endline#*,}
483      publisher=$( echo ${endline} | awk -F "," '{print $1}' | sed -e "s/\(publisher * = *{\)\(.*\)\(}\)/\2/")
[47]484      endline=${endline#*,}
485      edition=$( echo ${endline} | awk -F "," '{print $1}' | sed -e "s/\(edition * = *{\)\(.*\)\(}\)/\2/")
486      endline=${endline#*,}
487      isbn=$( echo ${endline} | awk -F "," '{print $1}' | sed -e "s/\(isbn * = *{\)\(.*\)\(}\)/\2/")
488      endline=${endline#*,}
489      pag=$( echo ${endline} | awk -F "," '{print $1}' | sed -e "s/\(page * = *{\)\(.*\)\(}\)/\2/")
[22]490
[56]491      if [ ${hasauthor} -eq 1 ]
492      then
[47]493         ## first author before the first and
494         first=${auths%%and*}
495         # its surname after the last " "  ++ pas vrai double nom et pb blanc dans la syntaxe
496         # firstsn=${first##* } . ok en interactif . pas ok en script
497         firstsn=$( echo ${first}  | awk '{print $2}')
[56]498         #echo "firstsn $firstsn"
[47]499         # its firstname before the first " "
500         firstfn=${first%% *}
501      fi
[46]502   fi
503
[21]504          cat <<EOF >> ${fileou}
[56]505<biblioentry xml:id="${refid}">
[2]506  <!-- date
507  $( date -u +"%Y-%m-%dT%H:%M:%SZ" )
508  -->
509  <!-- original text
[22]510  ${orgline}
[2]511  -->
[47]512EOF
[56]513      if [ ${hasauthor} -eq 1 ]
514      then
[47]515          cat <<EOF >> ${fileou}
[2]516  <authorgroup>
517    <author> <personname> <surname>${firstsn}</surname> <firstname>${firstfn}</firstname> </personname> </author>
518EOF
[22]519
[2]520## other authors..
[46]521  if [ ${bibtex} -eq 0 ]
522  then
523   previous=${first},
524   # next authors...
525   next=${auths##*${previous}}
526  fi
527  if [ ${bibtex} -eq 1 ]
528  then
529   previous=${first}"and "
530   # next authors...
[56]531   #echo "auths ${auths}"
[46]532   next=${auths##*${previous}}
533   if [ "${next}and " = "${previous}" ]
534   then
535     next=""
536   fi
537  fi
[56]538  #echo "previous ${previous}"
539  #echo "next ${next}"
[2]540# while the next author is not empty
[21]541  while [  "${next}" != "" ]
[2]542    do
[46]543      if [ ${bibtex} -eq 0 ]
544      then
545         # get the first next author; before the first ,
546         next=${next%%,*}
547         # its surname ; after the last .
548         nextsn=${next##*.}
549         nextsn=$( rmbl "${nextsn}" )
550         # its firstname ; before the last .
551         nextfn=${next%.*}.
552         nextfn=$( rmbl "${nextfn}" )
553       fi
554      if [ ${bibtex} -eq 1 ]
555      then
556         # get the first next author; before the first "and"
557         next=${next%%and *}
558         # its surname after the last " "  ++ pas vrai double nom et pb blanc dans la syntaxe
559         # nextsn=${next##* } . ok en interactif . pas ok en script
560         nextsn=$( echo ${next}  | awk '{print $2}')
[56]561         #echo "nextsn $nextsn"
[46]562         # its nextname before the first " "
563         nextfn=${next%% *}
564      fi
[2]565#
566    echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>" >> ${fileou}
[56]567    #echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>"  #++debug
[46]568    if [ ${bibtex} -eq 0 ]
569    then
570      previous=${next},
571      next=${auths##*${previous}}
572    fi
573    if [ ${bibtex} -eq 1 ]
574    then
575      previous=${next}"and "
576      next=${auths##*${previous}}
577    fi
[2]578  done
[21]579  echo "  </authorgroup>"  >> ${fileou}
[47]580  fi
[22]581
[2]582# end of the line ; after the first :
583  endline=${line#*:}
584## find the journal
585  j=1
586  jfound=""
587  jlistsize=${#jlist[@]}
[22]588  while [[ ${j} -le ${jlistsize} && "${jfound}" == "" ]]
[2]589    do
[22]590    ok=$( echo ${endline} | grep -ci "${jlist[j]} *," )
[64]591    [ ${ok} -eq 1 ] && jfound="${jlist[j]}"
[22]592    j=$(( ${j} + 1 ))
[2]593  done
[64]594  unset ok
[22]595  if [ "${jfound}" == "" ]
[2]596      then
[22]597      echo "eee: Journal not found "
[21]598      echo "${endline}"
[64]599      #++set
[56]600      #++exit 1
[47]601#+++ following lines are not yet validate
602      # it might be a book, a manual, a conference, etc. ++
603      echo "  <title>${title}</title>" >> ${fileou}
604          cat <<EOF >> ${fileou}
605  <biblioset relation="nojournal">
606    <title>${title}</title>
607    <pagenums>${pag}</pagenums>
608    <pubdate>${year}</pubdate>
609  </biblioset>
610EOF
611          cat <<EOF >> ${fileou}
612</biblioentry>
613
614EOF
615  fi # end of if jfound empty (ie not an article)
616  if [ "${jfound}" != "" ]
617  then
[22]618## title
[2]619# before the first :
620  title=${endline%%${jfound}*}
[21]621  title=$( cleanname "${title}" )
622  echo "  <title>${title}</title>" >> ${fileou}
[22]623## end
[2]624## end of the line ; after the first ${jfound}
625  endline=${endline#*${jfound}}
[21]626  endline=$( cleanname "${endline}" )
[2]627## doi
[21]628  endline=$( echo ${endline} | sed -e "s/[dD][oO][iI] *\t* *: *\t* */doi:/" )
629  ok=$( echo ${endline} | grep -ic "doi:" )
[22]630  if [ ${ok} -eq 1 ]
[2]631      then
632      doi=${endline##*doi:}
[21]633      echo "  <biblioid class=\"doi\">${doi}</biblioid>" >> ${fileou}
[64]634      unset doi
[2]635      endline=${endline%doi:*}
[21]636      endline=$( cleanname "${endline}" )
[2]637  else
[21]638      echo "non doi: ${line}"
[65]639      echo ""
[2]640  fi
[21]641  num=$( echo ${endline} |  tr -dc "," | wc -c )
642  case ${num} in
[65]643      0)
644### echo ${num}: ${endline}
645          cat <<EOF >> ${fileou}
646  <biblioset relation="journal">
647    <title>${jfound}</title>
648    <pubdate>${year}</pubdate>
649    <bibliomisc>${endline}</bibliomisc>
650  </biblioset>
651EOF
652          unset jfound
653          unset year
654      ;;
655
[22]656      1)
[21]657### echo ${num}: ${endline}
[2]658          vol=${endline%,*}
[21]659          vol=$( cleanname "${vol}" )
[22]660          pag=${endline##*,}
[21]661          pag=$( cleanname "${pag}" )
662          cat <<EOF >> ${fileou}
[2]663  <biblioset relation="journal">
664    <title>${jfound}</title>
665    <volumenum>${vol}</volumenum><pagenums>${pag}</pagenums>
666    <pubdate>${year}</pubdate>
667  </biblioset>
668EOF
[65]669          unset vol
670          unset pag
671          unset jfound
672          unset year
[2]673      ;;
[22]674      2)
[2]675          vol=${endline%,*}
[21]676          vol=$( cleanname "${vol}" )
[22]677          iss=${vol##*,}
[21]678          iss=$( cleanname "${iss}" )
[2]679          vol=${vol%,*}
[21]680          vol=$( cleanname "${vol}" )
[22]681          pag=${endline##*,}
[21]682          pag=$( cleanname "${pag}" )
683          cat <<EOF >> ${fileou}
[64]684  <biblioset relation="journal">
[2]685    <title>${jfound}</title>
686    <volumenum>${vol}</volumenum><issuenum>${iss}</issuenum><pagenums>${pag}</pagenums>
687    <pubdate>${year}</pubdate>
688  </biblioset>
689EOF
[65]690          unset vol
691          unset pag
692          unset jfound
693          unset year
694          unset iss
[2]695      ;;
[65]696      6)
697          conftitle=${endline%%,*}
698          endline=${endline#*,}
699          confdates=${endline%%,*} # day(s) month
700          endline=${endline#*,}
701          confdates="${confdates}, ${endline%%,*}" # day(s) month and year
702          confdates=$( cleanname "${confdates}" )
703          endline=${endline#*,}
704          confaddress=${endline%%,*} # Town
705          endline=${endline#*,}
706          confaddress="${confaddress}, ${endline%%,*}" # Town and country
707          confaddress=$( cleanname "${confaddress}" )
708          endline=${endline#*,}
709          publishername=${endline%%,*}
710          publishername=$( cleanname "${publishername}" )
711          endline=${endline#*,}
712          pag=${endline##*,}
713          pag=$( cleanname "${pag}" )
714#set
715#read a
716          cat <<EOF >> ${fileou}
717<biblioset relation="conference">
718 <title>${jfound}</title>
719 <pubdate>${year}</pubdate>
720 <publisher><publishername>${publishername}</publishername></publisher>
721 <pagenums>${pag}</pagenums>
722 <confgroup>
723  <conftitle>${conftitle}</conftitle>
724  <confdates>${confdates}</confdates>
725  <address>${confaddress}</address>
726 </confgroup>
727</biblioset>
728EOF
729      unset confaddress
730      unset conftitle
731      unset confdates
732      unset pag
733      unset publishername
734      unset year
735      unset jfound
736      ;;
737      10)
738          publishername=${endline%%Editors,*} 
739          publishername="${publishername} Editors"
740          publishername=$( cleanname "${publishername}" )
741          endline=${endline#*Editors,}
742          vol=${endline%%,*}
743          vol=$( cleanname "${vol}" )
744          endline=${endline#*,}
745          pag=${endline%%,*}
746          pag=$( cleanname "${pag}" )
747          endline=${endline#*,}
748          isbn=${endline%%,*}
749          isbn=$(echo ${isbn} | sed -e "s/ISBN ://")
750          isbn=$( cleanname "${isbn}" )
751          endline=${endline#*,}
752          agu=${endline%%,*}
753          agu=$(echo ${agu} | sed -e "s/AGU ://")
754          agu=$( cleanname "${agu}" )
755
756          endline=${endline#*${agu}}
757          endline=$( cleanname "${endline}" )
758          endline=$( cleanname "${endline}" )
759
760          cat <<EOF >> ${fileou}
761  <biblioid class="isbn">${isbn}</biblioid>
762  <biblioid class="other" otherclass="AGU">${agu}</biblioid>
763  <biblioset relation="journal">
764    <title>${jfound}</title>
765    <pubdate>${year}</pubdate>
766    <publisher><publishername>${publishername}</publishername></publisher>
767    <volumenum>${vol}</volumenum>
768    <pagenums>${pag}</pagenums>
769    <bibliomisc>${endline}</bibliomisc>
770  </biblioset>
771EOF
772      unset isbn
773      unset agu
774      unset pag
775      unset publishername
776      unset year
777      unset jfound
778      unset vol
779
780      ;;
[2]781      *)
[65]782echo ${num}: ${endline} # ++debug
783#set
784#exit 1 #++ debug
[21]785          cat <<EOF >> ${fileou}
[64]786  <biblioset relation="journal">
[2]787    <title>${jfound}</title>
788    <pubdate>${year}</pubdate>
789    <bibliomisc>${endline}</bibliomisc>
790  </biblioset>
791EOF
792      ;;
793  esac
[22]794
[21]795          cat <<EOF >> ${fileou}
[2]796</biblioentry>
[22]797
[2]798EOF
[47]799  fi # end of if jfound not empty
[65]800  unset title
801  unset vol
802  unset year
803  unset pag
[22]804  l=$(( ${l} + 1 ))
805
[2]806done
[64]807unset totlines
808unset l
[21]809echo "</bibliography>" >> ${fileou}
[2]810
[56]811xml val --err \
812        --xsd http://www.docbook.org/xml/5.0/xsd/docbook.xsd \
813        ${fileou} 1> xmlstarlet.log 2>&1
[2]814
815# clean
[56]816echo "iii : xslstarlet.log contains sdtout and stderr from xml command on ${fileou}"
[22]817echo "iii : which was done just to check consistence of ${fileou}"
[56]818more xmlstarlet.log
819rm -i xmlstarlet.log
820#
[2]821case ${type} in
[22]822raw)
[2]823 echo "iii : ${fileraw_strict} contains a copy of input file without comments"
824 rm -i ${fileraw_strict}
825;;
826mailbody)
827 echo "iii : ${fileraw} contains a copy of input file"
828 rm -i ${fileraw}
829 echo "iii : ${fileraw_strict} contains a copy of input file without comments"
830 rm -i ${fileraw_strict}
831;;
832esac
833#
834echo " iii : you have a some new or modified bibliographic references in ${fileou} (biblioentry)"
[47]835echo " iii : you can add them in ${fileou}" #++ filename path
836echo " iii : modify date in ${fileou}" #++ filename path
[2]837echo " iii : but please take care of id last part (after underscore) that may"
838echo " iii : be in conflict with existing ones" #++ pour s'affranchir de ce souci il faudrait donner en entrée complémentaire le fichier à compléter.
839#
840exit 0
Note: See TracBrowser for help on using the repository browser.