xref: /netbsd-src/external/ibm-public/postfix/dist/src/util/alldig.c (revision 67b9b338a7386232ac596b5fd0cd5a9cc8a03c71)
1*67b9b338Schristos /*	$NetBSD: alldig.c,v 1.2 2022/10/08 16:12:50 christos Exp $	*/
241fbaed0Stron 
341fbaed0Stron /*++
441fbaed0Stron /* NAME
541fbaed0Stron /*	alldig 3
641fbaed0Stron /* SUMMARY
741fbaed0Stron /*	predicate if string is all numerical
841fbaed0Stron /* SYNOPSIS
941fbaed0Stron /*	#include <stringops.h>
1041fbaed0Stron /*
1141fbaed0Stron /*	int	alldig(string)
1241fbaed0Stron /*	const char *string;
134a672054Schristos /*
144a672054Schristos /*	int	allalnum(string)
154a672054Schristos /*	const char *string;
1641fbaed0Stron /* DESCRIPTION
1741fbaed0Stron /*	alldig() determines if its argument is an all-numerical string.
184a672054Schristos /*
194a672054Schristos /*	allalnum() determines if its argument is an all-alphanumerical
204a672054Schristos /*	string.
2141fbaed0Stron /* SEE ALSO
2241fbaed0Stron /*	An alldig() routine appears in Brian W. Kernighan, P.J. Plauger:
2341fbaed0Stron /*	"Software Tools", Addison-Wesley 1976.
2441fbaed0Stron /* LICENSE
2541fbaed0Stron /* .ad
2641fbaed0Stron /* .fi
2741fbaed0Stron /*	The Secure Mailer license must be distributed with this software.
2841fbaed0Stron /* AUTHOR(S)
2941fbaed0Stron /*	Wietse Venema
3041fbaed0Stron /*	IBM T.J. Watson Research
3141fbaed0Stron /*	P.O. Box 704
3241fbaed0Stron /*	Yorktown Heights, NY 10598, USA
334a672054Schristos /*
344a672054Schristos /*	Wietse Venema
354a672054Schristos /*	Google, Inc.
364a672054Schristos /*	111 8th Avenue
374a672054Schristos /*	New York, NY 10011, USA
3841fbaed0Stron /*--*/
3941fbaed0Stron 
4041fbaed0Stron /* System library. */
4141fbaed0Stron 
4241fbaed0Stron #include <sys_defs.h>
4341fbaed0Stron #include <ctype.h>
4441fbaed0Stron 
4541fbaed0Stron /* Utility library. */
4641fbaed0Stron 
4741fbaed0Stron #include <stringops.h>
4841fbaed0Stron 
4941fbaed0Stron /* alldig - return true if string is all digits */
5041fbaed0Stron 
alldig(const char * string)5141fbaed0Stron int     alldig(const char *string)
5241fbaed0Stron {
5341fbaed0Stron     const char *cp;
5441fbaed0Stron 
5541fbaed0Stron     if (*string == 0)
5641fbaed0Stron 	return (0);
5741fbaed0Stron     for (cp = string; *cp != 0; cp++)
5841fbaed0Stron 	if (!ISDIGIT(*cp))
5941fbaed0Stron 	    return (0);
6041fbaed0Stron     return (1);
6141fbaed0Stron }
624a672054Schristos 
634a672054Schristos /* allalnum - return true if string is all alphanum */
644a672054Schristos 
allalnum(const char * string)654a672054Schristos int allalnum(const char *string)
664a672054Schristos {
674a672054Schristos     const char *cp;
684a672054Schristos 
694a672054Schristos     if (*string == 0)
704a672054Schristos         return (0);
714a672054Schristos     for (cp = string; *cp != 0; cp++)
724a672054Schristos         if (!ISALNUM(*cp))
734a672054Schristos             return (0);
744a672054Schristos     return (1);
754a672054Schristos }
76