8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsm / strrevcmp.c
blobf2714aeea8b33eb3cf4174f8dd77facf3d9c03fb
1 /*
2 * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 */
11 #pragma ident "%Z%%M% %I% %E% SMI"
13 #include <sm/gen.h>
14 SM_RCSID("@(#)$Id: strrevcmp.c,v 1.2 2001/08/27 22:21:51 gshapiro Exp $")
16 #include <sm/config.h>
17 #include <sm/string.h>
18 #include <string.h>
20 /* strcasecmp.c */
21 extern const unsigned char charmap[];
24 ** SM_STRREVCASECMP -- compare two strings starting at the end (ignore case)
26 ** Parameters:
27 ** s1 -- first string.
28 ** s2 -- second string.
30 ** Returns:
31 ** strcasecmp(reverse(s1), reverse(s2))
34 int
35 sm_strrevcasecmp(s1, s2)
36 const char *s1, *s2;
38 register int i1, i2;
40 i1 = strlen(s1) - 1;
41 i2 = strlen(s2) - 1;
42 while (i1 >= 0 && i2 >= 0 &&
43 charmap[(unsigned char) s1[i1]] ==
44 charmap[(unsigned char) s2[i2]])
46 --i1;
47 --i2;
49 if (i1 < 0)
51 if (i2 < 0)
52 return 0;
53 else
54 return -1;
56 else
58 if (i2 < 0)
59 return 1;
60 else
61 return (charmap[(unsigned char) s1[i1]] -
62 charmap[(unsigned char) s2[i2]]);
65 \f/*
66 ** SM_STRREVCMP -- compare two strings starting at the end
68 ** Parameters:
69 ** s1 -- first string.
70 ** s2 -- second string.
72 ** Returns:
73 ** strcmp(reverse(s1), reverse(s2))
76 int
77 sm_strrevcmp(s1, s2)
78 const char *s1, *s2;
80 register int i1, i2;
82 i1 = strlen(s1) - 1;
83 i2 = strlen(s2) - 1;
84 while (i1 >= 0 && i2 >= 0 && s1[i1] == s2[i2])
86 --i1;
87 --i2;
89 if (i1 < 0)
91 if (i2 < 0)
92 return 0;
93 else
94 return -1;
96 else
98 if (i2 < 0)
99 return 1;
100 else
101 return s1[i1] - s2[i2];