From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via "Emacs development discussions." Newsgroups: gmane.emacs.devel,gmane.emacs.help Subject: Re: verify ISSN (issn-verify.el) Date: Fri, 11 Sep 2020 08:32:50 +0200 Message-ID: <87h7s47rhp.fsf@ebih.ebihd> References: <87r1r96len.fsf@ebih.ebihd> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28898"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: emacs-devel@gnu.org Cancel-Lock: sha1:uGT6Ld68HCalFNfEaienpymmyvY= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 11 08:34:05 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kGcdJ-0007Or-05 for ged-emacs-devel@m.gmane-mx.org; Fri, 11 Sep 2020 08:34:05 +0200 Original-Received: from localhost ([::1]:36120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGcdI-0005R5-2t for ged-emacs-devel@m.gmane-mx.org; Fri, 11 Sep 2020 02:34:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGccG-0004yB-JW for emacs-devel@gnu.org; Fri, 11 Sep 2020 02:33:00 -0400 Original-Received: from static.214.254.202.116.clients.your-server.de ([116.202.254.214]:46838 helo=ciao.gmane.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGccE-0002h2-UP for emacs-devel@gnu.org; Fri, 11 Sep 2020 02:33:00 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1kGccB-00065o-Uc for emacs-devel@gnu.org; Fri, 11 Sep 2020 08:32:55 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Followup-To: gmane.emacs.help Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/11 01:48:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:255099 gmane.emacs.help:124017 Archived-At: See https://dataswamp.org/~incal/emacs-init/issn-verify.el for further (very small) changes... ;;; issn-verify.el --- verify ISSN -*- lexical-binding: t ;; ;;; Commentary: ;; ;; This Elisp package provides functions to verify ;; ISSN by computing their check digits. ;; ;; Author: Emanuel Berg (incal) ;; Created: 2020-09-06 ;; Keywords: bib, tex ;; License: GPL3+ ;; Package-Requires: ((cl-lib "1.0")) ;; URL: https://dataswamp.org/~incal/emacs-init/issn-verify.el ;; Version: 1.1.0 ;; ;; Also see: ;; ;; https://dataswamp.org/~incal/emacs-init/isbn-verify.el ;; ;; To install this package, with this file in ;; a buffer, do: ;; ;; M-x load-file RET RET ;; ;; International Standard Serial Number: ;; ;; ISO 3297, 1975 ;; ;; format: ;; ;; The Ring Magazine: ISSN 0035-5410 ;; d_1d_2d_3d_4-d_5d_6d_7c ;; d_i for i \in [1, 7] is an integer ;; c, the check digit, is 0..9 or X for 10 ;; ;; compute check digit c: ;; ;; c' = 8d_1*7d_2*6d_3*5d_4*4d_5*3d_6*2d_7 mod 11 ;; ;; { 0 c' = 0 ;; c = { ;; { 11 - c' else ;; ;;; Code: (require 'cl-lib) (defun issn--get-digits (issn) (if (and (= 9 (length issn)) (zerop (string-match "[[:digit:]]\\{4\\}-[[:digit:]]\\{3\\}[X[:digit:]]" issn)) ) (let*((issn-lst (string-to-list issn)) (dash-pos 4)) (mapcar (lambda (c) (if (eq ?X c) "X" (- c ?0))) (append (cl-subseq issn-lst 0 dash-pos) (cl-subseq issn-lst (1+ dash-pos)) ))) (error "Malformed ISSN") )) (defun issn-verify-issn (issn) (let*((issn-lst (issn--get-digits issn)) (c-prop (car (last issn-lst))) (c-w (cl-loop with cwl = 0 for d in issn-lst for w downfrom 8 to 2 do (cl-incf cwl (* w d)) finally return cwl) ) (c-prime (mod c-w 11)) (c (if (zerop c-prime) 0 (- 11 c-prime) )) (c-x (if (= 10 c) "X" c)) ) (if (equal c-prop c-x) (message "%s (OK)" c-x) (message "NOT OK! is %s, should be %s" c-prop c-x) ))) ;; Bicycle Quarterly (issn-verify-issn "1941-8809") ; 9 (OK) ;; Bicycling (issn-verify-issn "1651-9744") ; 4 (OK) ;; Black Belt (issn-verify-issn "0277-3066") ; 6 (OK) ;; Filter (issn-verify-issn "1654-9813") ; 3 (OK) ;; Linux Pro (issn-verify-issn "1471-5679") ; NOT OK! is 9, should be 8 ;; National Geographic (issn-verify-issn "2535-41241") ; Malformed ISSN ;; Outside (issn-verify-issn "0278-433") ; Malformed ISSN ;; The Economist (issn-verify-issn "0013-06a4") ; Malformed ISSN ;; The Ring (issn-verify-issn "0035x5410") ; Malformed ISSN (provide 'issn-verify) ;;; issn-verify.el ends here -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal