changeset 158:3698c8192d2d

libutil: hex digit functions factored out
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 26 Feb 2021 20:41:31 +0000
parents f064dbcc5f41
children 2557012666ea
files libutil/Makefile libutil/hexdigits.c libutil/hexstr.c libutil/revnibbles.c
diffstat 4 files changed, 25 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/libutil/Makefile	Fri Feb 26 20:19:58 2021 +0000
+++ b/libutil/Makefile	Fri Feb 26 20:41:31 2021 +0000
@@ -2,8 +2,8 @@
 CFLAGS=	-O2
 OBJS=	alpha_decode.o alpha_fromfile.o alpha_valid.o decimal_str.o \
 	filesearch.o gsm7_decode.o gsm7_encode.o gsm7_encode_table.o \
-	gsm7_unpack.o hexread.o hexstr.o number_decode.o number_encode.o \
-	pinentry.o plmncodes.o revnibbles.o
+	gsm7_unpack.o hexdigits.o hexread.o hexstr.o number_decode.o \
+	number_encode.o pinentry.o plmncodes.o revnibbles.o
 LIB=	libutil.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libutil/hexdigits.c	Fri Feb 26 20:41:31 2021 +0000
@@ -0,0 +1,23 @@
+/*
+ * This module contains elementary functions for working with hex digits.
+ */
+
+decode_hex_digit(c)
+{
+	if (c >= '0' && c <= '9')
+		return(c - '0');
+	if (c >= 'A' && c <= 'F')
+		return(c - 'A' + 10);
+	if (c >= 'a' && c <= 'f')
+		return(c - 'a' + 10);
+	return(-1);
+}
+
+encode_hex_digit(d)
+	unsigned d;
+{
+	if (d <= 9)
+		return(d + '0');
+	else
+		return(d - 10 + 'A');
+}
--- a/libutil/hexstr.c	Fri Feb 26 20:19:58 2021 +0000
+++ b/libutil/hexstr.c	Fri Feb 26 20:41:31 2021 +0000
@@ -4,21 +4,7 @@
 
 #include <sys/types.h>
 #include <ctype.h>
-#include <string.h>
-#include <strings.h>
 #include <stdio.h>
-#include <stdlib.h>
-
-decode_hex_digit(c)
-{
-	if (c >= '0' && c <= '9')
-		return(c - '0');
-	if (c >= 'A' && c <= 'F')
-		return(c - 'A' + 10);
-	if (c >= 'a' && c <= 'f')
-		return(c - 'a' + 10);
-	return(-1);
-}
 
 decode_hex_data_from_string(arg, databuf, minlen, maxlen)
 	char *arg;
--- a/libutil/revnibbles.c	Fri Feb 26 20:19:58 2021 +0000
+++ b/libutil/revnibbles.c	Fri Feb 26 20:41:31 2021 +0000
@@ -4,15 +4,6 @@
 
 #include <sys/types.h>
 
-encode_hex_digit(d)
-	unsigned d;
-{
-	if (d <= 9)
-		return(d + '0');
-	else
-		return(d - 10 + 'A');
-}
-
 decode_reversed_nibbles(bytes, nbytes, dest)
 	u_char *bytes;
 	unsigned nbytes;