This source file includes following definitions.
- __strverscmp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #ifndef _LIBC
21 # include <libc-config.h>
22 # define __strverscmp strverscmp
23 #endif
24
25 #include <stdint.h>
26 #include <string.h>
27 #include <ctype.h>
28
29
30
31 #define S_N 0x0
32 #define S_I 0x3
33 #define S_F 0x6
34 #define S_Z 0x9
35
36
37 #define CMP 2
38 #define LEN 3
39
40
41
42
43
44
45
46 int
47 __strverscmp (const char *s1, const char *s2)
48 {
49 const unsigned char *p1 = (const unsigned char *) s1;
50 const unsigned char *p2 = (const unsigned char *) s2;
51
52
53
54 static const uint_least8_t next_state[] =
55 {
56
57 S_N, S_I, S_Z,
58 S_N, S_I, S_I,
59 S_N, S_F, S_F,
60 S_N, S_F, S_Z
61 };
62
63 static const int_least8_t result_type[] =
64 {
65
66
67 CMP, CMP, CMP, CMP, LEN, CMP, CMP, CMP, CMP,
68 CMP, -1, -1, +1, LEN, LEN, +1, LEN, LEN,
69 CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
70 CMP, +1, +1, -1, CMP, CMP, -1, CMP, CMP
71 };
72
73 if (p1 == p2)
74 return 0;
75
76 unsigned char c1 = *p1++;
77 unsigned char c2 = *p2++;
78
79 int state = S_N + ((c1 == '0') + (isdigit (c1) != 0));
80
81 int diff;
82 while ((diff = c1 - c2) == 0)
83 {
84 if (c1 == '\0')
85 return diff;
86
87 state = next_state[state];
88 c1 = *p1++;
89 c2 = *p2++;
90 state += (c1 == '0') + (isdigit (c1) != 0);
91 }
92
93 state = result_type[state * 3 + (((c2 == '0') + (isdigit (c2) != 0)))];
94
95 switch (state)
96 {
97 case CMP:
98 return diff;
99
100 case LEN:
101 while (isdigit (*p1++))
102 if (!isdigit (*p2++))
103 return 1;
104
105 return isdigit (*p2) ? -1 : diff;
106
107 default:
108 return state;
109 }
110 }
111 libc_hidden_def (__strverscmp)
112 weak_alias (__strverscmp, strverscmp)