[office/tellico] /: Add ISBN formatting script

Robby Stephenson <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 21f716c59d4d4efb25b0b98d22bbbfb38bf420ed by Robby Stephenson.
Committed on 08/08/2026 at 23:52.
Pushed by rstephenson into branch 'master'.

Add ISBN formatting script

M  +4    -0    ChangeLog
A  +81   -0    src/utils/isbn-rangemessage.sh
M  +0    -1    src/utils/isbnvalidator_range.h

https://invent.kde.org/office/tellico/-/commit/21f716c59d4d4efb25b0b98d22bbbfb38bf420ed

diff --git a/ChangeLog b/ChangeLog
index 2cc38dcda..b4a37bcc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2026-08-08  Robby Stephenson  <[email protected]>
+
+	* Updated ISBN formatting, with script from Alex Oio.
+
 2026-08-02  Robby Stephenson  <[email protected]>
 
 	* Updated ISBN validation for multiple values.
diff --git a/src/utils/isbn-rangemessage.sh b/src/utils/isbn-rangemessage.sh
new file mode 100755
index 000000000..6e2d12bdd
--- /dev/null
+++ b/src/utils/isbn-rangemessage.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+# output su stdout
+# input RangeMessage.xml from https://www.isbn-international.org/range_file_generation
+
+IFS=$'\t\n'
+fFileInp=${1:-RangeMessage.xml}
+echo '#ifndef TELLICO_ISBNVALIDATOR_RANGE_H'
+echo '#define TELLICO_ISBNVALIDATOR_RANGE_H'
+echo
+echo "//--------------------------------------:--------------------------------------:"
+echo "// Source:        $(grep -m1 '<MessageSource>' "${fFileInp}"|sed -r 's/^[^>]+>([^<]+)<.+$/\1/')"
+echo "// Serial Number: $(grep -m1 'MessageSerialNumber>' "${fFileInp}"|sed -r 's/^[^>]+>([^<]+)<.+$/\1/')"
+echo "// Date:          $(grep -m1 '<MessageDate>' "${fFileInp}"|sed -r 's/^[^>]+>([^<]+)<.+$/\1/')"
+echo "// Generated by:  Alex Oio"
+echo "//--------------------------------------:--------------------------------------:"
+echo
+echo "ISBNValidator::isbn_band* ISBNValidator::bands;"
+echo
+
+# read -p 'continua ...' xxxx
+
+sOldEan=''
+sOldPrefix=''
+for sRow in $(sed -n '/<RegistrationGroups>/,/<\/RegistrationGroups>/p' "${fFileInp}"|\
+              grep -E '<(Prefix|Range|Length|Agency|/Rule)>'|\
+              sed ':a;N;$!ba;s/\n//g'|sed -re 's/ *<\/Rule>/\n/g' -e 's/^ +//g'); do
+
+   cmdSetData=$(echo "${sRow}"|sed -re 's/<([^\/][^>]+)>/s\1="/g' -e 's/<\/[^>]+>/"; /g')
+   eval "${cmdSetData}"
+
+   sRangeMin=${sRange%-*}
+   sRangeMax=${sRange#*-}
+   sPrefixEan=${sPrefix%-*}
+   sPrefixLng=${sPrefix#*-}
+   sIsbnMin=$(printf '%.8s' "${sPrefixLng}${sRangeMin}")
+   sIsbnMax=$(printf '%.8s' "${sPrefixLng}${sRangeMax}")
+
+   if [ "${sPrefixEan}" != "${sOldEan}" ]; then
+      sNextMin='00000001'
+      echo "Initialize ${sPrefixEan}" 1>&2
+      test "${sOldEan}" != '' && echo "//--------------------------------------: end of last group"
+      test "${sOldEan}" != '' && echo "};" && echo
+      echo "//--------------------------------------:--------------------------------------:"
+      echo "ISBNValidator::isbn_band ISBNValidator::bands${sPrefixEan}[] = {"
+      sOldEan="${sPrefixEan}"
+      sOldPrefix=''
+   fi
+
+   if [ "${sNextMin}" -lt "${sIsbnMin}" ]; then
+      test "${sOldPrefix}" == '' && sOldPrefix="${sPrefixEan}-0"
+      sPrevLng=${sOldPrefix#*-}
+      sPrevMax=$(printf '%08i' $((10#${sIsbnMin}-1)))
+      sPrefixFake=$(printf "%.${#sPrevLng}s" ${sPrevMax})
+      sRangeFake=$(printf '%.7s' "${sPrevMax#${sPrefixFake}}99999")
+echo "Dummy range:" 1>&2
+echo "- sIsbnMin=${sIsbnMin}" 1>&2
+echo "- sPrevMax=${sPrevMax}" 1>&2
+echo "- #sPrefixLng=${#sPrefixLng} (${sPrefixLng})" 1>&2
+echo "- sPrefixFake=${sPrefixFake}" 1>&2
+echo "- sRangeFake=${sRangeFake}" 1>&2
+
+      echo "//--------------------------------------: Dummy (${sPrefixEan}-${sPrefixFake})"
+      echo "ISBNGRP_${#sPrefixFake}DUMMY(${sPrefixFake},$(printf "% $((6-${#sPrefixFake}))s" ' ') ISBNPUB_7DIGIT($(printf '% 7s' $((10#${sRangeFake})))), 0, 9),"
+      read -p 'continua ...' xxxx
+   fi
+    if [ "${sOldPrefix}" != "${sPrefix}" ]; then
+      echo "//--------------------------------------: ${sAgency} (${sPrefix})"
+      sOldPrefix="${sPrefix}"
+   fi
+   nMidPos=0
+   test ${sLength} -ne 0 && nMidPos=$((${#sPrefixLng} + ${sLength}))
+   echo "ISBNGRP_${#sPrefixLng}DIGIT(${sPrefixLng},$(printf "% $((6-${#sPrefixLng}))s" ' ') ISBNPUB_7DIGIT(${sRangePrt}$(printf '% 7s' $((10#${sRangeMax})))), ${nMidPos}, 9),"
+   sNextMin=$(printf '%08s' $((10#${sIsbnMax}+1)))
+
+done
+echo "//--------------------------------------: Dummy (${sPrefixEan}-9)"
+echo "ISBNGRP_1DUMMY(9,      ISBNPUB_7DIGIT(9999999), 0, 9)"
+echo "//--------------------------------------: end of last group"
+echo "};"
+echo "//--------------------------------------:--------------------------------------:"
+echo '#endif'
diff --git a/src/utils/isbnvalidator_range.h b/src/utils/isbnvalidator_range.h
index c9486b220..ed2613f1e 100644
--- a/src/utils/isbnvalidator_range.h
+++ b/src/utils/isbnvalidator_range.h
@@ -8,7 +8,6 @@
 // Generated by:  Alex Oio
 //--------------------------------------:--------------------------------------:
 
-// how to format an ISBN, after categorising it into a range of numbers.
 ISBNValidator::isbn_band* ISBNValidator::bands;
 
 //--------------------------------------:--------------------------------------:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.