#!/bin/csh
# file: ads-abs2solabs = convert ADS abs/name.txt to solabs_name.html
# init: Oct 18 2019  Rob Rutten  Deil = from former adslinks2html
# last: Mar 30 2021  Rob Rutten  Deil
# note: usage ads-abs2solabs name

# work in /tmp
cd /tmp

# set parameters
setenv name $1

# start on the abstract.txt file
cp /home/rutten/rr/www/bibfiles/ads/abs/${name}.txt vbtemp.txt

# remove start marker
sed -i '/^--------/d' vbtemp.txt

# add break marker
sed -i 's/Title: /\n@------------------------------------------\nTitle: /g' vbtemp.txt

# ---- stop-start verbatim around bibcodes
# add @@ after bibcode as marker
# (leave altcodes ascii, users see here they exist for access at ADS)
sed -i '/^Bibcode: / s/$/@@/' vbtemp.txt
changestringinfile vbtemp.txt "Bibcode: " "\\end{verbatim}\\ADSabsnew{"
changestringinfile vbtemp.txt "@@" "}\\begin{verbatim}"

# add explanation with link to my website at the top 
echo "~~~~~~~~~~~~~~\htmladdnormallink{explanation}{https://robrutten.nl/Recipes_publications.html}~~~~~~blue bibcodes open ADS page with paths to full text" > explan.txt

# make the verbatim wrapper
rm -f verbatim*
cp ~/rr/tex/templates/verbatim* .
rm -f verbatimfile.txt
cat explan.txt verbatimbegin.txt vbtemp.txt verbatimend.txt > verbatimfile.txt

# use filename, not verbatim.tex, for Google to come up with right name
cat verbatimhtml.tex >> ${name}.tex

# make the html 
latex2html -verbosity 0 -no_subdir -no_navigation -info 0 ${name}.tex > /dev/null

# remove the white space introduced by verbatim environments
changestringinfile  ${name}.html '<BR>' ''
# next one removes rest of line (trick from Google)
cat $name.html | sed  '/<P>/{N;s/\n//;}'  > vbtemp.html
cat vbtemp.html | sed  '/<\/A>/{N;s/\n//;}'  > vbtemp2.html
cat vbtemp2.html | sed '/./\!d' > vbtemp3.html  # cut out all blank lines
cat vbtemp3.html | sed 's|@-----|\n--------------------|g' > vbtemp2.html
cat vbtemp2.html | sed  '/<\/PRE>/{N;s/\n//;}' > $name.html
changestringinfile  ${name}.html '<\/PRE>' ''
changestringinfile  ${name}.html '<P>' ''
##changestringinfile  ${name}.html 'tex2html_preform' ''
sed -i 's/<PRE>Altcode/    Altcode/g' ${name}.html
## sed -i 's/\n<A NAME/  <A NAME/g' ${name}.html # doettutniet

# insert statcount java script
mv  $name.html stattmp
changestringinfile stattmp '<\/BODY>' ''
changestringinfile stattmp '<\/HTML>' ''
cat stattmp /nethome/rutte101/rr/www/solabsstatcounter.txt > ${name}.html
rm -f stattmp

# write result
mv ${name}.html /home/rutten/rr/www/bibfiles/ads/abstracts/solabs\_${name}.html

# cleanup
rm -f vbtemp*
rm -f verbatim*
rm -f ${name}.tex
rm -f *.aux *.dvi *.lis *.blg *.log *.css *~
rm -f labels.pl WARNINGS index.html

# get back from /tmp
back
