Changes in trunk/bibopa.sh [22:15]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bibopa.sh
r22 r15 5 5 # Dipole on the East African Short Rains: A CGCM Study, J. Climate, In 6 6 # press. 7 # 7 # 8 8 # donnerait 9 # 9 # 10 10 # <biblioentry id="behara2004"> 11 11 # <authorgroup> … … 23 23 # Short Rains: A CGCM Study</title> 24 24 # <publishername>J. Climate</publishername> 25 # <biblio id class="doi">doi</bibliomisc>25 # <bibliomisc role="doi">doi</bibliomisc> 26 26 # <bibliomisc role="pseudoref">In press.</bibliomisc> 27 # <bibliomisc role="internalref">from 27 # <bibliomisc role="internalref">from 28 28 # http://www.lodyc.jussieu.fr/~opatlod/NEMO_v1/6_Menu/2_page/index.html 29 29 # 2007-03-29T16:24:31Z fplod by hand</bibliomisc> 30 30 # </biblioentry> 31 # 31 # 32 32 # 33 33 # example : … … 41 41 # 42 42 # update 43 # ++ gestion des comments 43 # ++ gestion des comments 44 44 # ++ gestion des id existants (cf à la fin) 45 45 # ++ option debug 46 # fplod 2007-06-20T17:18:02Z aedon.locean-ipsl.upmc.fr (Darwin)47 # <bibliomisc role="id"> replace by <biblioid class="doi">48 46 # smasson 2007-06-07T16:43:42Z arete.locean-ipsl.upmc.fr (Darwin) 49 47 # Add journals … … 54 52 # comments (line begininig with #) are now possible 55 53 # Sebastien Masson avril 2007 creation 56 # 54 # 57 55 58 56 rmbl () { 59 echo "$ {1}" | sed -e "s/^ *//" | sed -e "s/ *$//"57 echo "$1" | sed -e "s/^ *//" | sed -e "s/ *$//" 60 58 } 61 59 cleanname () { 62 echo "$ {1}" | sed -e "s/^ *//" \60 echo "$1" | sed -e "s/^ *//" \ 63 61 -e "s/^ *,//" \ 64 62 -e "s/^ *;//" \ … … 86 84 usage=" Usage : ${command} -i filein -t type" 87 85 # 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}" ] 86 while [ ! -z "${1}" ] # ++ pb bash 98 87 do 99 88 case ${1} in 100 -i) # filein 89 -i) # filein 101 90 filein=${2} 102 91 shift 103 92 ;; 104 -t) # type 93 -t) # type 105 94 type=${2} 106 95 shift 107 ;;108 -h)109 echo "${usage}"110 exit 0111 96 ;; 112 97 *) # other choice … … 117 102 shift # next flag 118 103 done 119 # 104 # 120 105 set -u 121 106 # 122 # check for filein 107 # check for filein 123 108 if [ ! -f ${filein} ] 124 109 then … … 143 128 #read a #++ if debug 144 129 ;; 145 *) 130 *) 146 131 echo "eee : type should be raw or mailbody" 147 132 exit 1 … … 252 237 totlines=$( wc -l ${fileraw_strict} | awk '{print $1}' ) 253 238 l=1 254 while [ $ {l} -le ${totlines}]239 while [ $l -le $totlines ] 255 240 do 256 241 # extract one line 242 257 243 line=$( sed -n ${l}p ${fileraw_strict} ) 258 orgline=$( echo $ {line}| sed -e "s/--/- -/g" )259 line=$( echo $ {line}| sed -e "s/</\</g" -e "s/>/\>/g" )244 orgline=$( echo $line | sed -e "s/--/- -/g" ) 245 line=$( echo $line | sed -e "s/</\</g" -e "s/>/\>/g" ) 260 246 # before the first : 261 247 tmp=${line%%:*} … … 263 249 auths=${tmp%,*}, 264 250 # supress and 265 auths=$( echo "$ {auths}" | sed -e "s/ and //g" )251 auths=$( echo "$auths" | sed -e "s/ and //g" ) 266 252 # after the last , 267 253 year=${tmp##*,} 268 year=$( rmbl "$ {year}" )254 year=$( rmbl "$year" ) 269 255 ## first author before the first ., 270 256 first=${auths%%.,*}. 271 257 # its firstname after the last , 272 258 firstfn=${first##*,} 273 firstfn=$( rmbl "$ {firstfn}" )259 firstfn=$( rmbl "$firstfn" ) 274 260 # its surname ; before the first , 275 261 firstsn=${first%%,*} 276 firstsn=$( rmbl "$ {firstsn}" )262 firstsn=$( rmbl "$firstsn" ) 277 263 ## 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 285 271 <biblioentry id="${refid}"> 286 272 <!-- date … … 288 274 --> 289 275 <!-- original text 290 $ {orgline}276 $orgline 291 277 --> 292 278 <authorgroup> 293 279 <author> <personname> <surname>${firstsn}</surname> <firstname>${firstfn}</firstname> </personname> </author> 294 280 EOF 295 281 296 282 ## other authors.. 297 283 previous=${first}, … … 299 285 next=${auths##*${previous}} 300 286 # while the next author is not empty 301 while [ "$ {next}" != "" ]287 while [ "$next" != "" ] 302 288 do 303 289 # get the first next author; before the first , … … 305 291 # its surname ; after the last . 306 292 nextsn=${next##*.} 307 nextsn=$( rmbl "$ {nextsn}" )293 nextsn=$( rmbl "$nextsn" ) 308 294 # its firstname ; before the last . 309 295 nextfn=${next%.*}. 310 nextfn=$( rmbl "$ {nextfn}" )296 nextfn=$( rmbl "$nextfn" ) 311 297 # 312 298 echo " <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>" >> ${fileou} 313 echo " <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>" #++debug314 299 previous=${next}, 315 300 next=${auths##*${previous}} 316 301 317 302 done 318 echo " </authorgroup>" >> $ {fileou}319 303 echo " </authorgroup>" >> $fileou 304 320 305 # end of the line ; after the first : 321 306 endline=${line#*:} 322 307 323 308 ## find the journal 324 309 j=1 325 310 jfound="" 326 311 jlistsize=${#jlist[@]} 327 while [[ $ {j} -le ${jlistsize}&& "${jfound}" == "" ]]312 while [[ $j -le $jlistsize && "${jfound}" == "" ]] 328 313 do 329 ok=$( echo $ {endline} | grep -ci "${jlist[j]} *," )314 ok=$( echo $endline | grep -ci "${jlist[j]} *," ) 330 315 [ $ok -eq 1 ] && jfound="${jlist[j]}" 331 j=$(( $ {j}+ 1 ))316 j=$(( $j + 1 )) 332 317 done 333 if [ "$ {jfound}" == "" ]318 if [ "$jfound" == "" ] 334 319 then 335 echo "eee: Journal not found "336 echo "${endline}"320 echo ERROR Journal not found 321 echo $endline 337 322 exit 338 323 fi 339 ## title 324 ## title 340 325 # before the first : 341 326 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 345 330 ## end of the line ; after the first ${jfound} 346 331 endline=${endline#*${jfound}} 347 endline=$( cleanname "$ {endline}" )332 endline=$( cleanname "$endline" ) 348 333 ## 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 ] 352 337 then 353 338 doi=${endline##*doi:} 354 echo " <biblio id class=\"doi\">${doi}</biblioid>" >> ${fileou}339 echo " <bibliomisc role=\"doi\">${doi}</bibliomisc>" >> $fileou 355 340 endline=${endline%doi:*} 356 endline=$( cleanname "$ {endline}" )341 endline=$( cleanname "$endline" ) 357 342 else 358 echo "non doi: ${line}"343 echo non doi: $line 359 344 fi 360 num=$( echo $ {endline}| tr -dc "," | wc -c )361 case $ {num}in362 1) 363 ### echo $ {num}: ${endline}345 num=$( echo $endline | tr -dc "," | wc -c ) 346 case $num in 347 1) 348 ### echo $num: ${endline} 364 349 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 369 354 <biblioset relation="journal"> 370 355 <title>${jfound}</title> … … 374 359 EOF 375 360 ;; 376 2) 361 2) 377 362 vol=${endline%,*} 378 vol=$( cleanname "$ {vol}" )379 iss=${vol##*,} 380 iss=$( cleanname "$ {iss}" )363 vol=$( cleanname "$vol" ) 364 iss=${vol##*,} 365 iss=$( cleanname "$iss" ) 381 366 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 386 371 <biblioset role="journal"> 387 372 <title>${jfound}</title> … … 392 377 ;; 393 378 *) 394 echo $ {num}: ${endline}395 cat <<EOF >> $ {fileou}379 echo $num: ${endline} 380 cat <<EOF >> $fileou 396 381 <biblioset role="journal"> 397 382 <title>${jfound}</title> … … 402 387 ;; 403 388 esac 404 405 cat <<EOF >> $ {fileou}389 390 cat <<EOF >> $fileou 406 391 </biblioentry> 407 408 EOF 409 410 411 412 413 414 l=$(( $ {l}+ 1 ))415 392 393 EOF 394 395 396 397 398 399 l=$(( $l + 1 )) 400 416 401 done 417 echo "</bibliography>" >> $ {fileou}402 echo "</bibliography>" >> $fileou 418 403 419 404 xsltproc \ … … 426 411 # clean 427 412 echo "iii : xml.err contains stderr from the following command " 428 echo "iii : which was done just to check consistence of ${fileou}" 413 echo "iii : which was done just to check consistence of ${fileou}" 429 414 echo "iii : xmlto pdf ${fileou}" 430 415 rm -i xml.err 431 416 case ${type} in 432 raw) 417 raw) 433 418 echo "iii : ${fileraw_strict} contains a copy of input file without comments" 434 419 rm -i ${fileraw_strict}
Note: See TracChangeset
for help on using the changeset viewer.