Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bibopa.sh

    r22 r15  
    55#    Dipole on the East African Short Rains: A CGCM Study, J. Climate, In 
    66#    press. 
    7 # 
     7#     
    88#    donnerait 
    9 # 
     9#     
    1010#    <biblioentry id="behara2004"> 
    1111#    <authorgroup> 
     
    2323#    Short Rains: A CGCM Study</title> 
    2424#    <publishername>J. Climate</publishername> 
    25 #    <biblioid class="doi">doi</bibliomisc> 
     25#    <bibliomisc role="doi">doi</bibliomisc> 
    2626#    <bibliomisc role="pseudoref">In press.</bibliomisc> 
    27 #    <bibliomisc role="internalref">from 
     27#    <bibliomisc role="internalref">from  
    2828#    http://www.lodyc.jussieu.fr/~opatlod/NEMO_v1/6_Menu/2_page/index.html 
    2929#    2007-03-29T16:24:31Z fplod by hand</bibliomisc> 
    3030#    </biblioentry> 
    31 # 
     31#     
    3232# 
    3333# example : 
     
    4141# 
    4242# update 
    43 # ++ gestion des comments 
     43# ++ gestion des comments  
    4444# ++ gestion des id existants (cf à la fin) 
    4545# ++ option debug 
    46 # fplod 2007-06-20T17:18:02Z aedon.locean-ipsl.upmc.fr (Darwin) 
    47 # <bibliomisc role="id"> replace by <biblioid class="doi"> 
    4846# smasson 2007-06-07T16:43:42Z arete.locean-ipsl.upmc.fr (Darwin) 
    4947# Add journals 
     
    5452# comments  (line begininig with #) are now possible 
    5553# Sebastien Masson avril 2007 creation 
    56 # 
     54#  
    5755 
    5856rmbl () { 
    59     echo "${1}" | sed -e "s/^ *//" | sed -e "s/ *$//" 
     57    echo "$1" | sed -e "s/^ *//" | sed -e "s/ *$//" 
    6058} 
    6159cleanname () { 
    62     echo "${1}" | sed -e "s/^ *//" \ 
     60    echo "$1" | sed -e "s/^ *//" \ 
    6361        -e "s/^ *,//" \ 
    6462        -e "s/^ *;//" \ 
     
    8684usage=" Usage : ${command} -i filein -t type" 
    8785# 
    88 minargcount=4 
    89 echo " narg ${#}" 
    90 if [ ${#} -lt ${minargcount} ] 
    91 then 
    92   echo "eee : not enought arguments" 
    93   echo "${usage}" 
    94   exit 1 
    95 fi 
    96 # 
    97 while [ ! -z "${1}" ] 
     86while [ ! -z "${1}" ] # ++ pb bash 
    9887do 
    9988 case ${1} in 
    100  -i) # filein 
     89 -i) # filein  
    10190  filein=${2} 
    10291  shift 
    10392 ;; 
    104  -t) # type 
     93 -t) # type  
    10594  type=${2} 
    10695  shift 
    107  ;; 
    108  -h) 
    109   echo "${usage}" 
    110   exit 0 
    11196 ;; 
    11297 *) # other choice 
     
    117102 shift # next flag 
    118103done 
    119 # 
     104#  
    120105set -u 
    121106# 
    122 # check for filein 
     107# check for filein  
    123108if [ ! -f ${filein} ] 
    124109then 
     
    143128 #read a #++ if debug 
    144129;; 
    145 *) 
     130*)  
    146131   echo "eee : type should be raw or mailbody" 
    147132   exit 1 
     
    252237totlines=$( wc -l ${fileraw_strict} | awk '{print $1}' ) 
    253238l=1 
    254 while [ ${l} -le ${totlines}  ] 
     239while [ $l -le $totlines  ] 
    255240do 
    256241# extract one line 
     242 
    257243  line=$( sed -n ${l}p ${fileraw_strict} ) 
    258   orgline=$( echo ${line} | sed -e "s/--/- -/g" ) 
    259   line=$( echo ${line} | sed -e "s/</\&lt;/g" -e "s/>/\&gt;/g" ) 
     244  orgline=$( echo $line | sed -e "s/--/- -/g" ) 
     245  line=$( echo $line | sed -e "s/</\&lt;/g" -e "s/>/\&gt;/g" ) 
    260246# before the first : 
    261247  tmp=${line%%:*} 
     
    263249  auths=${tmp%,*}, 
    264250# supress and 
    265   auths=$( echo "${auths}" | sed -e "s/ and //g" ) 
     251  auths=$( echo "$auths" | sed -e "s/ and //g" ) 
    266252# after the last , 
    267253  year=${tmp##*,} 
    268   year=$( rmbl "${year}" ) 
     254  year=$( rmbl "$year" ) 
    269255## first author before the first ., 
    270256  first=${auths%%.,*}. 
    271257# its firstname after the last , 
    272258  firstfn=${first##*,} 
    273   firstfn=$( rmbl "${firstfn}" ) 
     259  firstfn=$( rmbl "$firstfn" ) 
    274260# its surname ; before the first , 
    275261  firstsn=${first%%,*} 
    276   firstsn=$( rmbl "${firstsn}" ) 
     262  firstsn=$( rmbl "$firstsn" ) 
    277263## ref id 
    278   refid=$( echo ${firstsn} | tr "[:upper:]" "[:lower:]" | tr -s " " "_"  | tr -s "'" "_" | recode -d -f ISO-8859-1..flat )${year} 
    279   num=$( grep -c "<biblioentry id=\"${refid}_[0-9][0-9]\">" ${fileou} ) 
    280   num=$(( ${num} + 1 )) 
    281   [ ${num} -le 9 ] && num=0${num} 
    282   refid=${refid}_${num} 
    283  
    284           cat <<EOF >> ${fileou} 
     264  refid=$( echo $firstsn | tr "[:upper:]" "[:lower:]" | tr -s " " "_"  | tr -s "'" "_" | recode -d -f ISO-8859-1..flat )$year 
     265  num=$( grep -c "<biblioentry id=\"${refid}_[0-9][0-9]\">" $fileou ) 
     266  num=$(( $num + 1 )) 
     267  [ $num -le 9 ] && num=0$num  
     268  refid=${refid}_$num 
     269   
     270          cat <<EOF >> $fileou 
    285271<biblioentry id="${refid}"> 
    286272  <!-- date 
     
    288274  --> 
    289275  <!-- original text 
    290   ${orgline} 
     276  $orgline 
    291277  --> 
    292278  <authorgroup> 
    293279    <author> <personname> <surname>${firstsn}</surname> <firstname>${firstfn}</firstname> </personname> </author> 
    294280EOF 
    295  
     281   
    296282## other authors.. 
    297283  previous=${first}, 
     
    299285  next=${auths##*${previous}} 
    300286# while the next author is not empty 
    301   while [  "${next}" != "" ] 
     287  while [  "$next" != "" ] 
    302288    do 
    303289# get the first next author; before the first , 
     
    305291# its surname ; after the last . 
    306292    nextsn=${next##*.} 
    307     nextsn=$( rmbl "${nextsn}" ) 
     293    nextsn=$( rmbl "$nextsn" ) 
    308294# its firstname ; before the last . 
    309295    nextfn=${next%.*}. 
    310     nextfn=$( rmbl "${nextfn}" ) 
     296    nextfn=$( rmbl "$nextfn" ) 
    311297# 
    312298    echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>" >> ${fileou} 
    313     echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>"  #++debug 
    314299    previous=${next}, 
    315300    next=${auths##*${previous}} 
    316  
     301     
    317302  done 
    318   echo "  </authorgroup>"  >> ${fileou} 
    319  
     303  echo "  </authorgroup>"  >> $fileou 
     304   
    320305# end of the line ; after the first : 
    321306  endline=${line#*:} 
    322  
     307   
    323308## find the journal 
    324309  j=1 
    325310  jfound="" 
    326311  jlistsize=${#jlist[@]} 
    327   while [[ ${j} -le ${jlistsize} && "${jfound}" == "" ]] 
     312  while [[ $j -le $jlistsize && "${jfound}" == "" ]] 
    328313    do 
    329     ok=$( echo ${endline} | grep -ci "${jlist[j]} *," ) 
     314    ok=$( echo $endline | grep -ci "${jlist[j]} *," )  
    330315    [ $ok -eq 1 ] && jfound="${jlist[j]}" 
    331     j=$(( ${j} + 1 )) 
     316    j=$(( $j + 1 )) 
    332317  done 
    333   if [ "${jfound}" == "" ] 
     318  if [ "$jfound" == "" ] 
    334319      then 
    335       echo "eee: Journal not found " 
    336       echo "${endline}" 
     320      echo ERROR Journal not found 
     321      echo $endline 
    337322      exit 
    338323  fi 
    339 ## title 
     324## title  
    340325# before the first : 
    341326  title=${endline%%${jfound}*} 
    342   title=$( cleanname "${title}" ) 
    343   echo "  <title>${title}</title>" >> ${fileou} 
    344 ## end 
     327  title=$( cleanname "$title" ) 
     328  echo "  <title>${title}</title>" >> $fileou 
     329## end  
    345330## end of the line ; after the first ${jfound} 
    346331  endline=${endline#*${jfound}} 
    347   endline=$( cleanname "${endline}" ) 
     332  endline=$( cleanname "$endline" ) 
    348333## doi 
    349   endline=$( echo ${endline} | sed -e "s/[dD][oO][iI] *\t* *: *\t* */doi:/" ) 
    350   ok=$( echo ${endline} | grep -ic "doi:" ) 
    351   if [ ${ok} -eq 1 ] 
     334  endline=$( echo $endline | sed -e "s/[dD][oO][iI] *\t* *: *\t* */doi:/" ) 
     335  ok=$( echo $endline | grep -ic "doi:" ) 
     336  if [ $ok -eq 1 ] 
    352337      then 
    353338      doi=${endline##*doi:} 
    354       echo "  <biblioid class=\"doi\">${doi}</biblioid>" >> ${fileou} 
     339      echo "  <bibliomisc role=\"doi\">${doi}</bibliomisc>" >> $fileou 
    355340      endline=${endline%doi:*} 
    356       endline=$( cleanname "${endline}" ) 
     341      endline=$( cleanname "$endline" ) 
    357342  else 
    358       echo "non doi: ${line}" 
     343      echo non doi: $line 
    359344  fi 
    360   num=$( echo ${endline} |  tr -dc "," | wc -c ) 
    361   case ${num} in 
    362       1) 
    363 ### echo ${num}: ${endline} 
     345  num=$( echo $endline |  tr -dc "," | wc -c ) 
     346  case $num in 
     347      1)  
     348### echo $num: ${endline} 
    364349          vol=${endline%,*} 
    365           vol=$( cleanname "${vol}" ) 
    366           pag=${endline##*,} 
    367           pag=$( cleanname "${pag}" ) 
    368           cat <<EOF >> ${fileou} 
     350          vol=$( cleanname "$vol" ) 
     351          pag=${endline##*,}  
     352          pag=$( cleanname "$pag" ) 
     353          cat <<EOF >> $fileou 
    369354  <biblioset relation="journal"> 
    370355    <title>${jfound}</title> 
     
    374359EOF 
    375360      ;; 
    376       2) 
     361      2)  
    377362          vol=${endline%,*} 
    378           vol=$( cleanname "${vol}" ) 
    379           iss=${vol##*,} 
    380           iss=$( cleanname "${iss}" ) 
     363          vol=$( cleanname "$vol" ) 
     364          iss=${vol##*,}  
     365          iss=$( cleanname "$iss" ) 
    381366          vol=${vol%,*} 
    382           vol=$( cleanname "${vol}" ) 
    383           pag=${endline##*,} 
    384           pag=$( cleanname "${pag}" ) 
    385           cat <<EOF >> ${fileou} 
     367          vol=$( cleanname "$vol" ) 
     368          pag=${endline##*,}  
     369          pag=$( cleanname "$pag" ) 
     370          cat <<EOF >> $fileou 
    386371  <biblioset role="journal"> 
    387372    <title>${jfound}</title> 
     
    392377      ;; 
    393378      *) 
    394 echo ${num}: ${endline} 
    395           cat <<EOF >> ${fileou} 
     379echo $num: ${endline} 
     380          cat <<EOF >> $fileou 
    396381  <biblioset role="journal"> 
    397382    <title>${jfound}</title> 
     
    402387      ;; 
    403388  esac 
    404  
    405           cat <<EOF >> ${fileou} 
     389  
     390          cat <<EOF >> $fileou 
    406391</biblioentry> 
    407  
    408 EOF 
    409  
    410  
    411  
    412  
    413  
    414   l=$(( ${l} + 1 )) 
    415  
     392   
     393EOF 
     394 
     395 
     396 
     397 
     398   
     399  l=$(( $l + 1 )) 
     400   
    416401done 
    417 echo "</bibliography>" >> ${fileou} 
     402echo "</bibliography>" >> $fileou 
    418403 
    419404xsltproc \ 
     
    426411# clean 
    427412echo "iii : xml.err contains stderr from the following command " 
    428 echo "iii : which was done just to check consistence of ${fileou}" 
     413echo "iii : which was done just to check consistence of ${fileou}"  
    429414echo "iii : xmlto pdf ${fileou}" 
    430415rm -i xml.err 
    431416case ${type} in 
    432 raw) 
     417raw)  
    433418 echo "iii : ${fileraw_strict} contains a copy of input file without comments" 
    434419 rm -i ${fileraw_strict} 
Note: See TracChangeset for help on using the changeset viewer.