2023-07-26 14:34:22 +00:00
|
|
|
base_SQL="SELECT title,author,journal,year,token,doi,arxiv,citeref,prauth,bibtex,url FROM bibliography"
|
|
|
|
base_SQL_noprauth="SELECT title,author,journal,year,token,doi,arxiv,citeref,bibtex,url FROM bibliography"
|
2017-05-02 20:20:48 +00:00
|
|
|
|
|
|
|
# add quotes
|
|
|
|
function SQL_addquotes {
|
|
|
|
while read -r line; do
|
|
|
|
# add quotes and escape string
|
|
|
|
if [ -n "$line" ]; then
|
|
|
|
line=$(escape_string "$line")
|
|
|
|
line="${line/%=/= }"
|
|
|
|
line="${line/ = /=\"}"
|
|
|
|
line="${line/%/\"}"
|
|
|
|
fi
|
|
|
|
echo "$line"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# SQL command for alphabetical ordering
|
|
|
|
function generate_SQL_alpha {
|
|
|
|
echo -n "$base_SQL WHERE citeref='"
|
|
|
|
|
|
|
|
# whether there is a citeref
|
|
|
|
exists_citeref=0
|
|
|
|
|
|
|
|
# sift through aux file
|
2019-11-13 16:22:41 +00:00
|
|
|
grep -h "$aux_cmd" $aux | while read -r citerefs; do
|
|
|
|
eval "citerefs=\${citerefs#$aux_cmd}"
|
|
|
|
citerefs="${citerefs%\}}"
|
2017-05-02 20:20:48 +00:00
|
|
|
|
2019-11-13 16:22:41 +00:00
|
|
|
# can be a comma separated list
|
|
|
|
for citeref in $(echo -n "$citerefs" | tr ',' '\n'); do
|
2017-05-02 20:20:48 +00:00
|
|
|
|
2019-11-13 16:22:41 +00:00
|
|
|
# replace the citeref with a ref_map if there is any
|
|
|
|
if [ -n "$ref_map" ]; then
|
|
|
|
citeref=$(map_citeref "$citeref")
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Only query the db if there is no matching extra entry
|
|
|
|
foundit=0
|
|
|
|
if [ ${#extra} -gt 0 ]; then
|
|
|
|
for entry in "${extra[@]}"; do
|
|
|
|
ref="${entry#*:}"
|
|
|
|
ref="${ref%%:*}"
|
|
|
|
if [ "$ref" = "$citeref" ]; then
|
|
|
|
foundit=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$foundit" = 0 ]; then
|
|
|
|
echo -n "$citeref' OR citeref='"
|
|
|
|
exists_citeref=1
|
|
|
|
fi
|
|
|
|
done
|
2017-05-02 20:20:48 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# if there are no citerefs close '
|
|
|
|
[ $exists_citeref = 0 ] && echo -n "'"
|
|
|
|
}
|
|
|
|
|
|
|
|
# fetch entries by alphabetical order
|
|
|
|
function fetch_BBlog_entries_alpha {
|
|
|
|
SQL="$(generate_SQL_alpha)"
|
|
|
|
SQL="${SQL% OR citeref=\'} ORDER BY prauth,year"
|
|
|
|
sqlite3 -line "$db" "$SQL" | SQL_addquotes
|
|
|
|
# add an empty line
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
# fetch entries by order of appearance
|
|
|
|
function fetch_BBlog_entries_appearance {
|
|
|
|
# keep track of citerefs to avoid repetitions
|
|
|
|
citeref_list=""
|
|
|
|
|
|
|
|
# sift through aux file
|
2019-11-13 16:22:41 +00:00
|
|
|
grep -h "$aux_cmd" $aux | while read -r citerefs; do
|
|
|
|
eval "citerefs=\${citerefs#$aux_cmd}"
|
|
|
|
citerefs="${citerefs%\}}"
|
2017-05-02 20:20:48 +00:00
|
|
|
|
2019-11-13 16:22:41 +00:00
|
|
|
# can be a comma separated list
|
|
|
|
for citeref in $(echo -n "$citerefs" | tr ',' '\n'); do
|
2017-05-02 20:20:48 +00:00
|
|
|
|
2019-11-13 16:22:41 +00:00
|
|
|
# replace the citeref with a ref_map if there is any
|
|
|
|
if [ -n "$ref_map" ]; then
|
|
|
|
citeref=$(map_citeref "$citeref")
|
2017-05-02 20:20:48 +00:00
|
|
|
fi
|
2019-11-13 16:22:41 +00:00
|
|
|
|
|
|
|
# check whether the reference was already cited
|
|
|
|
citeref_list="$citeref_list;"
|
|
|
|
if $(echo "$citeref_list" | grep -q ";$citeref;"); then
|
|
|
|
# remove trailing ';'
|
|
|
|
citeref_list="${citeref_list%;}"
|
2017-05-02 20:20:48 +00:00
|
|
|
else
|
2019-11-13 16:22:41 +00:00
|
|
|
citeref_list="$citeref_list$citeref"
|
2017-05-02 20:20:48 +00:00
|
|
|
|
2019-11-13 16:22:41 +00:00
|
|
|
# Only query the db if there is no matching extra entry
|
|
|
|
foundit=0
|
|
|
|
if [ ${#extra} -gt 0 ]; then
|
|
|
|
for entry in "${extra[@]}"; do
|
|
|
|
ref="${entry#*:}"
|
|
|
|
ref="${ref%%:*}"
|
|
|
|
if [ "$ref" = "$citeref" ]; then
|
|
|
|
foundit=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$foundit" = 0 ]; then
|
|
|
|
SQL="$base_SQL_noprauth WHERE citeref='$citeref'"
|
|
|
|
sqlite3 -line "$db" "$SQL" | SQL_addquotes
|
|
|
|
else
|
|
|
|
echo "citeref=$citeref"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# add an empty line
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
done
|
2017-05-02 20:20:48 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|