From 0948b09a847cb3c4865a3fc2fd914f60dca8ab7f Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Tue, 22 Jan 2019 15:48:21 +0100 Subject: [PATCH] Fix ipcalc. Signed-off-by: Andreas Gerler --- lisp/ipcalc.el | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lisp/ipcalc.el b/lisp/ipcalc.el index 59fdec76..a095e9d6 100644 --- a/lisp/ipcalc.el +++ b/lisp/ipcalc.el @@ -31,7 +31,7 @@ ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ;; COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR @@ -41,9 +41,9 @@ ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED ;; OF THE POSSIBILITY OF SUCH DAMAGE. -;;; Code +;;; Code: -(defconst cidr-default 32 "CIDR value") +(defconst cidr-default 32 "CIDR value.") (defun int-to-bin-string (n &optional length) ;; 08 Jun 1997 Jamie Zawinski comp.emacs @@ -59,7 +59,7 @@ s)) (defun octets-as-binary (list-of-octets) - "return LST of octets as a single binary string" + "return LST of octets as a single binary string." (let ((binary "")) (while list-of-octets (setq binary @@ -70,16 +70,16 @@ binary)) (defun ip-to-octets (ip) - "split IP address and return the octets" + "split IP address and return the octets." (let ((octets (split-string ip "\\."))) (if (= 4 (length octets)) octets (message "not correct IP format")))) (defun ones-and-pad (num) - "return 1's equal to NUM and pad the rest up to 32" + "return 1's equal to NUM and pad the rest up to 32." (unless (and (<= num cidr-default) (> num 0)) - (error "wrong value provided")) + (error "Wrong value provided")) (concat (make-string num ?1) (make-string (- cidr-default num) ?0))) @@ -93,7 +93,7 @@ (remove-if-not (lambda (ch) (position ch "01")) num))) (defun network (ip cidr) - "Takes IP & CIDR and produces network" + "Takes IP & CIDR and produces network." (let ((cidr-as-int (string-to-int cidr))) (concat (substring (octets-as-binary @@ -101,7 +101,7 @@ (make-string (- cidr-default cidr-as-int) ?0)))) (defun host+1 (binary-ip) - "increment the given BINARY-IP by 1" + "increment the given BINARY-IP by 1." (let ((tmp binary-ip)) (aset tmp (- cidr-default 1) ?1) tmp)) @@ -115,29 +115,29 @@ ip)) (defun hosts/net (num) - "Calculate Hosts/Net for the NUM given" + "Calculate Hosts/Net for the NUM given." (- (expt 2 (- cidr-default num)) 2)) (defmacro list-to-string (lst) - "convert LST to string" + "convert LST to string." `(mapconcat - '(lambda (val) + #'(lambda (val) (identity (if (integerp val) (int-to-string val) val))) ,lst "")) (defun insert-values (lst) - "insert given LST" + "insert given LST." (insert (list-to-string lst))) (defun bin-to-int (bin) - "Convert binary to integer" + "Convert binary to integer." (int-to-string (read (concat "#b" bin)))) (defun binary-to-ip (binary) - "convert binary to IP address" + "convert binary to IP address." (let* (full-ip (count 0) (1st-octet (substring binary 0 8)) @@ -153,7 +153,7 @@ (concat full-ip (car (last octets))))) (defun ipcalc (ip/cidr) - "IP calculator" + "IP calculator." (let* ((ip (car (split-string ip/cidr "/"))) (ip-in-binary (octets-as-binary (ip-to-octets ip))) (cidr (car (cdr (split-string ip/cidr "/")))) -- 2.47.3