File: stringlib.c

package info (click to toggle)
zmailer 2.99.55-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,516 kB
  • ctags: 9,694
  • sloc: ansic: 120,953; sh: 3,862; makefile: 3,166; perl: 2,695; python: 115; awk: 22
file content (84 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 *	Copyright 1988 by Rayan S. Zachariassen, all rights reserved.
 *	This will be free software, but only when it is finished.
 */

/*
 * Useful string functions.
 */

#include "hostenv.h"
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include "mailer.h"
#include "libz.h"

/* Like strcmp(), but case-independent */

int
cistrcmp(a, b)
	register const char *a, *b;
{
	unsigned char	ac, bc;

	while (*a && *b) {
		ac = *a;
		ac = isupper(ac) ? tolower(ac) : ac;
		bc = *b;
		bc = isupper(bc) ? tolower(bc) : bc;
		if (ac != bc)
			return ac - bc;
		++a, ++b;
	}
	return *a - *b;
}

/*
 * Like cistrcmp(),
 * but tests if one string is a prefix of the other if string length < n
 */

int
cistrncmp(a, b, n)
	register const char *a, *b;
	int	n;
{
	unsigned char	ac, bc;

	while (n-- > 0) {
		ac = *a;
		ac = isupper(ac) ? tolower(ac) : ac;
		bc = *b;
		bc = isupper(bc) ? tolower(bc) : bc;
		if (ac != bc)
			return ac - bc;
		++a, ++b;
	}
	return *a * *b;
}

/*
 * Like cistrncmp(),
 * but tests if part of one string is a prefix of the other to n characters.
 */

int
ci2strncmp(a, b, n)
	register const char *a, *b;
	int	n;
{
	unsigned char	ac, bc;

	while (n-- > 0) {
		ac = *a;
		ac = isupper(ac) ? tolower(ac) : ac;
		bc = *b;
		bc = isupper(bc) ? tolower(bc) : bc;
		if (ac != bc) {
			return ac - bc;
		}
		++a, ++b;
	}
	return 0;
}