gsl-statique-litterateur/var/lib/gsl/scripts/gsl__post_checkers

888 lines
21 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# file: gsl__post_checkers
# Folder: /var/lib/gsl/scripts
2022-06-14 18:51:19 +02:00
# By echolib (XMPP: im@echolib.re)
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================
2022-06-14 18:51:19 +02:00
# Get arguments from COMMAND (check)
# $2 -F (to force) or File
# $3 File
#======================================================================
2022-06-14 18:51:19 +02:00
check__OPTIONS() {
gsl_proc="check"
while test "$2"
do
case "$2" in
-F)
gsl_force_check=true
log_info_force="Force "
;;
-N)
unset gsl_force_check
gsl_check_newer=true
;;
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
*".gsl")
if__file "$2" post
gsl_post="$2"
post_only="$2"
;;
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
*)
gsl__invalid_option "$2" "-F|-N|(FILE)"
;;
esac
shift
done
if ! [[ "$gsl_post" ]];then
log_info_all=" ALL"
[[ $gsl_check_newer ]] \
&& log_info_all+=" NEWER"
2022-02-27 19:16:16 +01:00
fi
2022-06-14 18:51:19 +02:00
log__process_begin "${log_info_force}Check${log_info_all}"
posts__loop check
# For logs ; set post or unset if all
[[ $log_info_all ]] && unset gsl_post
[[ $post_only ]] && gsl_post="$post_only"
log__process_end "${log_info_force}Check${log_info_all}"
2022-02-27 19:16:16 +01:00
}
2022-06-14 18:51:19 +02:00
#======================================================================
2022-06-14 18:51:19 +02:00
# From post__loop() ; get and CHECK headers values
# Called from read__line_with() in gsl__do_commons
# $1: marker
# $2: type (meta/metas)
#======================================================================
2022-06-14 18:51:19 +02:00
check__headers_from_filter() {
case "$4" in
meta)
check__meta_header "$3"
2022-02-27 19:16:16 +01:00
;;
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
metas|content)
case "$3" in
"title") check__titles ;;
"link") check__link ;;
"abbr") check__abbr ;;
"image") check__file_image ;;
"flink") check__file_link ;;
"fcode") check__file_code ;;
"fbrut") check__file_brut ;;
esac
2022-02-27 19:16:16 +01:00
;;
esac
}
2022-06-14 18:51:19 +02:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Call in posts_loop() for process before Checkers()
# Check if error in meta marker
# From get__needed_headers() in gsl__do_commons
# $1: marker
#======================================================================
2022-06-14 18:51:19 +02:00
check__meta_header() {
if ! [[ "$header_f1" ]];then
gsl__logs_print -e -h \
"$1" \
"Not set" \
"$PWD/$gsl_post"
return 1
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
case "$1" in
2022-06-23 12:24:01 +02:00
# TYPE
2022-06-14 18:51:19 +02:00
"$gsl_marker_type")
gsl_post_type="$header_f1"
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
case "$gsl_post_type" in
page|post)
gsl__logs_print -i -h \
"$1" \
"Set to '$gsl_post_type'" \
"${PWD}/$gsl_post"
;;
*)
gsl__logs_print -e -h \
"$1" \
"Wrong '$gsl_post_type' ; $gsl_log_act_type" \
"${PWD}/$gsl_post"
;;
esac
;;
2022-06-28 22:56:48 +02:00
2022-06-23 12:24:01 +02:00
# CSS
2022-06-14 18:51:19 +02:00
"$gsl_marker_css")
gsl_post_css=" $header_f1"
gsl__logs_print -i -h \
"$1" \
2022-06-14 18:51:19 +02:00
"Body template: $header_f1" \
"$PWD/$gsl_post"
;;
2022-06-28 22:56:48 +02:00
2022-06-23 12:24:01 +02:00
# Title
2022-06-14 18:51:19 +02:00
"$gsl_marker_title")
gsl_post_title="$header_f1"
;;
2022-06-28 22:56:48 +02:00
2022-06-23 12:24:01 +02:00
# DATE
2022-06-14 18:51:19 +02:00
"$gsl_marker_date")
gsl_post_date="$header_f1"
2022-06-28 22:56:48 +02:00
case "$gsl_post_date" in
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])
gsl_date_m=`awk -F- '{print $2}' <<<"$gsl_post_date"`
if (( "$gsl_date_m" > 12 ));then
gsl__logs_print -e -h \
2022-06-14 18:51:19 +02:00
"$1" \
"'$gsl_post_date' ; Month: $gsl_date_m > 12..." \
"${PWD}/$gsl_post"
2022-06-28 22:56:48 +02:00
return
fi
# timestamp date to db too (sidebar sort)
false_time=`date +%T`
2022-06-14 18:51:19 +02:00
gsl_date_y=`awk -F- '{print $1}' <<<"$gsl_post_date"`
gsl_date_d=`awk -F- '{print $3}' <<<"$gsl_post_date"`
2022-06-28 22:56:48 +02:00
date_epoch="$gsl_date_y-$gsl_date_m-$gsl_date_d $false_time"
date_epoch=`date +%s -u -d "$date_epoch"`
;;
*)
gsl__logs_print -e -h \
"$1" \
"Mismatch '$gsl_post_date' ; not YYYY-MM-DD" \
"${PWD}/$gsl_post"
;;
esac
2022-06-14 18:51:19 +02:00
;;
2022-06-23 12:24:01 +02:00
# SLUG
2022-06-14 18:51:19 +02:00
"$gsl_marker_slug")
gsl_post_slug="$header_f1"
gsl_post_slug_src="$gsl_post_slug"
gsl_hash_slug_src=`cksum <<<"$gsl_post_slug_src"`
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
# Type page with "/" in
if [[ "$gsl_post_type" == "page" ]] && \
[[ `grep '/' <<<"$gsl_post_slug"` ]];then
gsl_post_slug=${gsl_post_slug////-}
gsl__logs_print -w -h \
"$1" \
"Has '/' for type $gsl_post_type ; Replaced with '-'" \
"${PWD}/$gsl_post"
fi
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
# Ensure no ending / for slug
gsl_post_slug=${gsl_post_slug/%\//}
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
# Has space
gsl_post_slug=${gsl_post_slug// /-}
gsl_hash_slug=`cksum <<<"$gsl_post_slug"`
if ! [[ "$gsl_hash_slug" == "$gsl_hash_slug_src" ]];then
mark_slug_src="$gsl_marker_slug $gsl_post_slug_src"
mark_slug_new="$gsl_marker_slug $gsl_post_slug"
sed -i \
"s^$mark_slug_src^$mark_slug_new^" \
"$gsl_post"
gsl__logs_print -w -h \
"$1" \
"Changed to: '$gsl_post_slug'" \
"${PWD}/$gsl_post"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
article__sum "$gsl_post"
fi
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
# Already used slug
while read -r "file_db"
do
gsl_slug_db_hash=`
awk -F= '/article_Hash_DB/ {print $2}' \
"$file_db"`
gsl_slug_db_type=`
awk -F= '/article_Type/ {print $2}' \
"$file_db"`
! [[ "$gsl_slug_db_type" == "$gsl_post_type" ]] \
&& continue
[[ "$gsl_slug_db_hash" == "$article_Hash_DB" ]] \
&& continue
gsl__logs_print -e -h \
"$1" \
"'$header_f1' already in use ; change it" \
"$file_db"
break
done < <(grep -sl "article_Slug=\"$gsl_post_slug\"" \
$gsl_dir_db_domain/*.db)
;;
2022-06-23 12:24:01 +02:00
# AUTHOR
2022-06-14 18:51:19 +02:00
"$gsl_marker_author")
gsl_post_author="$header_f1"
if ! [[ `grep "^$gsl_post_author$" "$gsl_file_domain_authors"` ]];then
gsl__logs_print -e -h \
"$1" \
"'$gsl_post_author' ; not registred !" \
"${PWD}/$gsl_post"
fi
;;
2022-02-27 19:16:16 +01:00
2022-06-23 12:24:01 +02:00
# INFO
2022-06-14 18:51:19 +02:00
"$gsl_marker_info")
gsl_post_info="$header_f1"
if (( ${#gsl_post_info} <= 18 ));then
gsl__logs_print -w -h \
"$1" \
"'$gsl_post_info' ; not too short ?" \
"${PWD}/$gsl_post"
fi
;;
2022-02-27 19:16:16 +01:00
2022-06-23 12:24:01 +02:00
# TAGS
2022-06-14 18:51:19 +02:00
"$gsl_marker_tags")
gsl_post_tags="$header_f1"
gsl_stat_tags=`awk -F, '{print NF}' <<<$gsl_post_tags`
;;
esac
}
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# --------------------------------
# Do all checkers From: loop_posts
# --------------------------------
#======================================================================
Checkers() {
get__needed_headers "check" "$gsl_tmp_head"
! [[ $gsl_do_check ]] && return
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
stats__init # init stats values
gsl_tmp_db=`mktemp` # Create tmp DB for found files to add then to DB
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Check for links
read__line_with "^$gsl_marker_link" "check" \
"link" "metas" "$gsl_tmp_head"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Check abbrs
read__line_with "^$gsl_marker_abbr" "check" \
"abbr" "metas" "$gsl_tmp_head"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Check images
read__line_with "^$gsl_marker_image" "check" \
"image" "metas" "$gsl_tmp_head"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Check files
read__line_with "^$gsl_marker_flink" "check" \
"flink" "metas" "$gsl_tmp_head"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Check filesCODE
read__line_with "^$gsl_marker_fcode" "check" \
"fcode" "metas" "$gsl_tmp_head"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Check for brut code file
read__line_with "^$gsl_marker_fbrut" "check" \
"fbrut" "metas" "$gsl_tmp_head"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Check for content titles
read__line_with "^#[1-6]" "check" \
"title" "content" "$gsl_tmp_post"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Independant modules
check__paragraphs "$gsl_tmp_post" # Check for paragraphs markers
check__lists "$gsl_tmp_post" # Check for lists markers
check__blockquote "$gsl_tmp_post" # Check for blockquote markers
2022-06-28 22:56:48 +02:00
check__bsis "$gsl_tmp_post" # Check paired & stats
check__icode "$gsl_tmp_post" # Check paired & stats for inline-code
2022-06-14 18:51:19 +02:00
# Errors => remove from DB and srv WIP
[[ "$gsl_checker_err" ]] \
&& article_Errors="yes" \
|| article_Errors="no"
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
Stat__words "$gsl_tmp_post"
DB__set_status chk
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Remove temp files
rm -f "$gsl_tmp_post" \
"$gsl_tmp_head" \
"$gsl_tmp_db"
2022-02-27 19:16:16 +01:00
}
2022-06-14 18:51:19 +02:00
#----------------------------------------------------------------------
# -------------------------------------------------
# Modules checkers
# -------------------------------------------------
#----------------------------------------------------------------------
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Checking titles
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
check__titles() {
((gsl_stat_titles++))
mark_title=`awk '{print $1}' <<<"$gsl_line"`
content_title=`awk '{print $2}' <<<"$gsl_line"`
post_ln=$((ln + gsl_post_begin - 1))
[[ "$content_title" ]] && return
gsl__logs_print -e -c \
"Title" \
"Line: $post_ln ; No content for $mark_title" \
"${PWD}/$gsl_post"
}
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# Check link
#======================================================================
check__link() {
if ! [[ "$header_f1" && "$header_f2" ]];then
gsl__logs_print -e -h \
"$gsl_marker_link" \
"Line: $ln not set ; $gsl_log_act_link" \
"${PWD}/$gsl_post"
return
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if ! [[ "$header_f3" ]];then
gsl__logs_print -w -h \
"$gsl_marker_link" \
"Line: $ln No Alt-Text ; $gsl_log_act_link" \
"${PWD}/$gsl_post"
fi
2022-06-14 18:51:19 +02:00
if ! [[ `grep "\<_$header_f1\>" "$gsl_tmp_post"` ]];then
gsl__logs_print -e -c \
"$gsl_marker_link" \
"Line: $ln ; Unused: '_$header_f1'" \
"${PWD}/$gsl_post"
return
fi
2022-02-27 19:16:16 +01:00
2022-06-23 12:24:01 +02:00
# For online stats, convert /... url
# article not yet in www ; do not check status and count
case "$header_f2" in
"/"*)
[[ $gsl_srv_www_file ]] \
&& header_f2="$site_url$header_f2"
;;
esac
2022-06-14 18:51:19 +02:00
# Get Online status
case "$header_f2" in
"http"*)
url_status=`
timeout 2 \
curl -o /dev/null --silent --head --write-out \
'%{http_code}' \
"$header_f2" 2>/dev/null \
|| url_status="T"`
;;
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
*)
url_status=NS
;;
esac
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Analyse Online Status
case "$url_status" in
1*|2*|3*)
gsl__logs_print -i -h \
"$gsl_marker_link" \
"Online: $url_status ; ${header_f2:0:30}..." \
"${PWD}/$gsl_post"
((gsl_stat_links_online++))
;;
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
NS)
gsl__logs_print -w -h \
"$gsl_marker_link" \
"No status ; ${header_f2:0:30}..." \
"${PWD}/$gsl_post"
;;
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
T)
gsl__logs_print -w -h \
"$gsl_marker_link" \
"Timeout ; ${header_f2:0:30}..." \
"${PWD}/$gsl_post"
;;
""|*)
gsl__logs_print -w -h \
"$gsl_marker_link" \
"Offline: $url_status ; ${header_f2:0:30}..." \
"${PWD}/$gsl_post"
;;
esac
# Stat: Count
((gsl_stat_links++))
}
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# Check paragraphs markers
#======================================================================
check__paragraphs() {
gsl_post_po=`
grep "^$gsl_mark_p_start$\|^$gsl_mark_p_start " "$1" \
| wc -l`
gsl_post_pc=`
grep "^$gsl_mark_p_close$" "$1" \
| wc -l`
if (( "$gsl_post_po" == 0 ));then
gsl__logs_print -w -c \
"Paragraphs" \
"Unused '$gsl_mark_p_start' & '$gsl_mark_p_close' at begining lines" \
2022-02-27 19:16:16 +01:00
"${PWD}/$gsl_post"
2022-06-14 18:51:19 +02:00
gsl_stat_p="0"
elif (( "$gsl_post_po" == "$gsl_post_pc" ));then
gsl_stat_p="$gsl_post_po"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
else
gsl__logs_print -e -c \
"Paragraphs" \
"Mismatch '$gsl_mark_p_start' & '$gsl_mark_p_close' ; not paired" \
"${PWD}/$gsl_post"
2022-02-27 19:16:16 +01:00
fi
}
2022-06-14 18:51:19 +02:00
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Check paragraphs markers
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
check__lists() {
gsl_post_lo=`grep "^<<$\|^<< " "$1" | wc -l`
gsl_post_lc=`grep "^>>$" "$1" | wc -l`
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if (( "$gsl_post_lo" == "$gsl_post_lc" ));then
gsl_stat_lists="$gsl_post_lo"
2022-02-27 19:16:16 +01:00
else
2022-06-14 18:51:19 +02:00
gsl__logs_print -e -c \
"Lists" \
"Mismatch '<<' & '>>' ; not paired" \
2022-02-27 19:16:16 +01:00
"${PWD}/$gsl_post"
fi
}
2022-06-14 18:51:19 +02:00
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Check blockquotes markers
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
check__blockquote() {
gsl_post_bq=`grep "^$gsl_mark_blockquote" "$1" | wc -l`
gsl_post_bq_paired=$(( $gsl_post_bq % 2 ))
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if [[ "$gsl_post_bq_paired" -eq 0 ]];then
gsl_stat_bq=$(( gsl_post_bq / 2 ))
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
else
gsl__logs_print -e -c \
"Blockquote" \
"Mismatch: '$gsl_mark_blockquote' ; not paired" \
"${PWD}/$gsl_post"
fi
}
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# Check ABBR
#======================================================================
check__abbr() {
if ! [[ "$header_f1" && "$header_f2" ]];then
gsl__logs_print -e -h \
"$gsl_marker_abbr" \
"Line: $ln not set ; $gsl_log_act_abbr" \
"${PWD}/$gsl_post"
# must be in caps lock
elif ! [[ "$header_f1" == ${header_f1^^} ]];then
gsl__logs_print -e -c \
"$gsl_marker_abbr" \
"Line: $ln ; '$header_f1' not UPPER case" \
"${PWD}/$gsl_post"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# ! forget space ↓
elif ! [[ `grep -E " $header_f1|^$header_f1 " "$gsl_tmp_post"` ]];then
gsl__logs_print -e -c \
"$gsl_marker_abbr" \
"Line: $ln ; Unused: '$header_f1'" \
"${PWD}/$gsl_post"
2022-02-27 19:16:16 +01:00
else
2022-06-14 18:51:19 +02:00
((gsl_stat_abbrs++))
fi
}
2022-02-27 19:16:16 +01:00
2022-03-01 18:39:46 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# Check Flink
#======================================================================
check__file_link() {
if ! [[ "$header_f1" && "$header_f2" ]];then
gsl__logs_print -e -h \
"$gsl_marker_flink" \
"Line: $ln not set ; $gsl_log_act_flink" \
"${PWD}/$gsl_post"
return
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if ! [[ "$header_f3" ]];then
gsl__logs_print -w -h \
"$gsl_marker_flink" \
"Line: $ln No Alt-Text ; $gsl_log_act_flink" \
"${PWD}/$gsl_post"
2022-02-27 19:16:16 +01:00
fi
2022-06-14 18:51:19 +02:00
if ! [[ `grep "\<__$header_f1\>" "$gsl_tmp_post"` ]];then
gsl__logs_print -e -c \
"$gsl_marker_flink" \
"Unused: '__$header_f1'" \
"${PWD}/$gsl_post"
gsl_flink_err=true
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if ! [[ -f "$gsl_dir_domain_files/$header_f2" ]];then
gsl__logs_print -e -h \
"$gsl_marker_flink" \
"Not found: $header_f2" \
"$gsl_dir_domain_docs/$header_f2"
gsl_flink_err=true
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
[[ $gsl_flink_err ]] && return
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Register file to DB
printf '%s\n' \
"# Flink_URI:$gsl_dir_domain_fles/$header_f2" \
>> "$gsl_tmp_db"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Stat
((gsl_stat_flinks++))
2022-02-27 19:16:16 +01:00
}
2022-06-14 18:51:19 +02:00
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Check images
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
check__file_image() {
if ! [[ "$header_f1" && "$header_f2" && "$header_f3" ]];then
gsl__logs_print -e -h \
"$gsl_marker_image" \
"Line: $ln not set ; $gsl_log_act_image" \
"${PWD}/$gsl_post"
return
fi
2022-04-25 13:17:09 +02:00
2022-06-14 18:51:19 +02:00
if ! [[ `grep "_image:$header_f1" "$gsl_tmp_post"` ]];then
gsl__logs_print -e -c \
"$gsl_marker_image" \
"Unused: '_image:$header_f1'" \
"${PWD}/$gsl_post"
gsl_image_err=true
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if ! [[ -f "$gsl_dir_domain_images/$header_f2" ]];then
gsl__logs_print -e -h \
2022-04-25 13:17:09 +02:00
"$gsl_marker_image" \
2022-06-14 18:51:19 +02:00
"Not found: $header_f2" \
"$gsl_dir_domain_images/$header_f2"
gsl_image_err=true
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
[[ $gsl_image_err ]] && return
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Register file to DB
printf '%s\n' \
"# Image_URI:$gsl_dir_domain_images/$header_f2" \
>> "$gsl_tmp_db"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Stat
((gsl_stat_images++))
}
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# Check fcode: file code to convert and import in content
#======================================================================
check__file_code() {
if ! [[ "$header_f1" && "$header_f2" ]];then
gsl__logs_print -e -h \
"$gsl_marker_fcode" \
"Line: $ln not set ; $gsl_log_act_fcode" \
"${PWD}/$gsl_post"
return
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if ! [[ "$header_f3" ]];then
gsl__logs_print -w -h \
"$gsl_marker_fcode" \
"Line: $ln No Alt-Text ; $gsl_log_act_fcode" \
"${PWD}/$gsl_post"
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if ! [[ `grep "$gsl_mark_fcode:$header_f1" "$gsl_tmp_post"` ]];then
gsl__logs_print -e -c \
"$gsl_marker_fcode" \
"Unused: '$gsl_mark_fcode:$header_f1'" \
2022-02-27 19:16:16 +01:00
"${PWD}/$gsl_post"
2022-06-14 18:51:19 +02:00
gsl_fcode_err=true
fi
if ! [[ -f "$gsl_dir_domain_files/$header_f2" ]];then
gsl__logs_print -e -h \
"$gsl_marker_fcode" \
"Not found: $header_f2" \
"$gsl_dir_domain_precodes/$header_f2"
gsl_fcode_err=true
2022-02-27 19:16:16 +01:00
fi
2022-06-14 18:51:19 +02:00
[[ $gsl_fcode_err ]] && return
# Register file to DB
printf '%s\n' \
"# Fcode_URI:$gsl_dir_domain_files/$header_f2" \
>> "$gsl_tmp_db"
# Stat
((gsl_stat_fcodes++))
2022-02-27 19:16:16 +01:00
}
2022-06-14 18:51:19 +02:00
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Check fbrut : brut file to import in content
2022-02-27 19:16:16 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
check__file_brut() {
if ! [[ "$header_f1" && "$header_f2" ]];then
gsl__logs_print -e -h \
"$gsl_marker_fbrut" \
"Line: $ln not set ; $gsl_log_act_fbrut" \
"${PWD}/$gsl_post"
return
fi
2022-03-12 16:16:21 +01:00
2022-06-14 18:51:19 +02:00
if ! [[ `grep "$gsl_mark_fbrut:$header_f1" "$gsl_tmp_post"` ]];then
gsl__logs_print -e -c \
"$gsl_marker_fbrut" \
"Unused: '$gsl_mark_fbrut:$header_f1'" \
"${PWD}/$gsl_post"
gsl_fbrut_err=true
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if ! [[ -f "$gsl_dir_domain_files/$header_f2" ]];then
gsl__logs_print -e -h \
"$gsl_marker_fbrut" \
"Not found: $header_f2" \
"$gsl_dir_domain_files/$header_f2"
gsl_fbrut_err=true
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
[[ $gsl_fcode_err ]] && return
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Register file to DB
printf '%s\n' \
"# Fbrut_URI:$gsl_dir_domain_files/$header_f2" \
>> "$gsl_tmp_db"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Stat
((gsl_stat_fbruts++))
}
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
2022-06-28 22:56:48 +02:00
# Check bsis + stats
# $1: file (gsl_tmp_post)
2022-06-14 18:51:19 +02:00
#======================================================================
2022-06-28 22:56:48 +02:00
check__bsis() {
while read -r "ln" "gsl_line"
do
ln=$(( ln + $gsl_post_begin - 1 ))
unset line_has_bold \
line_has_strong \
line_has_em \
line_has_cross \
line_has_del
case "$gsl_line" in
*"$gsl_mark_bold"*|\
*"$gsl_mark_strike"*|\
*"$gsl_mark_em"*|\
*"$gsl_mark_strong"*|\
*"$gsl_mark_del"*)
check__bsis_stats
;;
esac
if [[ $line_has_bold ]];then
bold_paired=$(( $found_bold % 2 ))
if ! [[ "$bold_paired" -eq 0 ]];then
gsl__logs_print -e -c \
"Bold" \
"Line: $ln ; $found_bold '$gsl_mark_bold' ; not paired" \
"$PWD/$gsl_post"
else
gsl_stat_bolds=$(( gsl_stat_bolds + found_bold / 2 ))
fi
fi
if [[ $line_has_strong ]];then
strong_paired=$(( $found_strong % 2 ))
if ! [[ "$strong_paired" -eq 0 ]];then
gsl__logs_print -e -c \
"Strong" \
"Line: $ln ; $found_strong '$gsl_mark_strong' ; not paired" \
"$PWD/$gsl_post"
else
gsl_stat_strongs=$(( gsl_stat_strongs + found_strong / 2 ))
fi
fi
if [[ $line_has_em ]];then
em_paired=$(( $found_em % 2 ))
if ! [[ "$em_paired" -eq 0 ]];then
gsl__logs_print -e -c \
"Emphasis" \
"Line: $ln ; $found_em '$gsl_mark_em' ; not paired" \
"$PWD/$gsl_post"
else
gsl_stat_italics=$(( gsl_stat_italics + found_em / 2 ))
fi
fi
if [[ $line_has_cross ]];then
cross_paired=$(( $found_cross % 2 ))
if ! [[ "$cross_paired" -eq 0 ]];then
gsl__logs_print -e -c \
"Cross" \
"Line: $ln ; $found_cross '$gsl_mark_cross' ; not paired" \
"$PWD/$gsl_post"
else
gsl_stat_strikes=$(( gsl_stat_strikes + found_cross / 2 ))
fi
fi
if [[ $line_has_del ]];then
del_paired=$(( $found_del % 2 ))
if ! [[ "$del_paired" -eq 0 ]];then
gsl__logs_print -e -c \
"Del" \
"Line: $ln ; $found_del '$gsl_mark_del' ; not paired" \
"$PWD/$gsl_post"
else
gsl_stat_dels=$(( gsl_stat_dels + found_del / 2 ))
fi
fi
done < <(cat -n "$1")
2022-06-14 18:51:19 +02:00
}
2022-02-27 19:16:16 +01:00
2022-06-28 22:56:48 +02:00
check__bsis_stats() {
found_bold=0
found_strong=0
found_em=0
found_cross=0
found_del=0
for (( i=0; i<${#gsl_line}; i++ ))
do
case "${gsl_line:$i:1}" in
"$gsl_mark_icode")
[[ $code_open ]] \
&& unset code_open \
|| code_open=true
;;
"$gsl_mark_bold")
[[ $code_open ]] && continue
((found_bold++))
line_has_bold=true
;;
*"$gsl_mark_strong"*)
[[ $code_open ]] && continue
((found_strong++))
line_has_strong=true
;;
*"$gsl_mark_em"*)
[[ $code_open ]] && continue
((found_em++))
line_has_em=true
;;
*"$gsl_mark_cross"*)
[[ $code_open ]] && continue
((found_cross++))
line_has_cross=true
;;
*"$gsl_mark_del"*)
[[ $code_open ]] && continue
((found_del++))
line_has_del=true
;;
esac
done
2022-06-14 18:51:19 +02:00
}
2022-06-14 18:51:19 +02:00
#======================================================================
2022-06-28 22:56:48 +02:00
# Check iCode + stats
# $1: file (gsl_tmp_post)
2022-06-14 18:51:19 +02:00
#======================================================================
2022-06-28 22:56:48 +02:00
check__icode() {
while read -r "ln" "gsl_line"
do
ln=$(( ln + $gsl_post_begin - 1 ))
unset line_has_icode
case "$gsl_line" in
*"$gsl_mark_icode"*)
found_icode=0
for (( i=0; i<${#gsl_line}; i++ ))
do
case "${gsl_line:$i:1}" in
"$gsl_mark_icode")
((found_icode++))
line_has_icode=true
;;
esac
done
;;
esac
2022-06-14 18:51:19 +02:00
2022-06-28 22:56:48 +02:00
if [[ $line_has_icode ]];then
icode_paired=$(( $found_icode % 2 ))
if ! [[ "$icode_paired" -eq 0 ]];then
gsl__logs_print -e -c \
"i-Code" \
"Line: $ln ; $found_icode '$gsl_mark_icode' ; not paired" \
"$PWD/$gsl_post"
else
gsl_stat_icodes=$(( gsl_stat_icodes + found_icode / 2 ))
fi
fi
2022-02-14 02:57:58 +01:00
2022-06-28 22:56:48 +02:00
done < <(cat -n "$1")
2022-02-14 02:57:58 +01:00
}