source: trunk/bibopa.sh @ 76

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

comments in shell scripts in ReStructured? Text

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