]>
git.saurik.com Git - apple/system_cmds.git/blob - kmodload.tproj/vers_rsrc.c
c10f288b5e3071974b70d9b2aac070a957dbf8da
3 int vers_isdigit(char c
) {
5 c
== '1' || c
== '2' || c
== '3' ||
6 c
== '4' || c
== '5' || c
== '6' ||
7 c
== '7' || c
== '8' || c
== '9');
10 int vers_isspace(char c
) {
18 int isreleasestate(char c
) {
19 return (c
== 'd' || c
== 'a' || c
== 'b' || c
== 'f');
23 UInt8
BCD_digit_for_char(char c
) {
25 case '0': return 0; break;
26 case '1': return 1; break;
27 case '2': return 2; break;
28 case '3': return 3; break;
29 case '4': return 4; break;
30 case '5': return 5; break;
31 case '6': return 6; break;
32 case '7': return 7; break;
33 case '8': return 8; break;
34 case '9': return 9; break;
35 default: return BCD_illegal
; break;
41 char BCD_char_for_digit(UInt8 digit
) {
43 case 0: return '0'; break;
44 case 1: return '1'; break;
45 case 2: return '2'; break;
46 case 3: return '3'; break;
47 case 4: return '4'; break;
48 case 5: return '5'; break;
49 case 6: return '6'; break;
50 case 7: return '7'; break;
51 case 8: return '8'; break;
52 case 9: return '9'; break;
53 default: return '?'; break;
59 VERS_revision
VERS_revision_for_string(char ** string_p
) {
62 if (!string_p
|| !*string_p
) {
68 if (vers_isspace(string
[0]) || string
[0] == '\0') {
73 if (vers_isdigit(string
[1])) {
74 *string_p
= &string
[1];
75 return VERS_development
;
79 if (vers_isdigit(string
[1])) {
80 *string_p
= &string
[1];
85 if (vers_isdigit(string
[1])) {
86 *string_p
= &string
[1];
91 if (vers_isdigit(string
[1])) {
92 *string_p
= &string
[1];
93 return VERS_candidate
;
94 } else if (string
[1] == 'c' && vers_isdigit(string
[2])) {
95 *string_p
= &string
[2];
96 return VERS_candidate
;
111 int VERS_parse_string(char * vers_string
, UInt32
* version_num
) {
114 char * current_char_p
;
117 if (!vers_string
|| *vers_string
== '\0') {
123 current_char_p
= &vers_string
[0];
127 * Check for an initial digit of the major release number.
129 vers
.bytes
[0] = BCD_digit_for_char(*current_char_p
);
130 if (vers
.bytes
[0] == BCD_illegal
) {
138 * Check for a second digit of the major release number.
140 if (*current_char_p
== '\0') {
141 vers
.bytes
[2] = VERS_release
;
142 vers
.bytes
[3] = 0xff;
144 } else if (vers_isdigit(*current_char_p
)) {
145 scratch
= BCD_digit_for_char(*current_char_p
);
146 if (scratch
== BCD_illegal
) {
149 vers
.bytes
[0] = BCD_combine(vers
.bytes
[0], scratch
);
152 if (*current_char_p
== '\0') {
153 vers
.bytes
[2] = VERS_release
;
154 vers
.bytes
[3] = 0xff;
156 } else if (isreleasestate(*current_char_p
)) {
158 } else if (*current_char_p
== '.') {
163 } else if (isreleasestate(*current_char_p
)) {
165 } else if (*current_char_p
== '.') {
173 * Check for the minor release number.
175 if (*current_char_p
== '\0') {
176 vers
.bytes
[2] = VERS_release
;
177 vers
.bytes
[3] = 0xff;
179 } else if (vers_isdigit(*current_char_p
)) {
180 vers
.bytes
[1] = BCD_digit_for_char(*current_char_p
);
181 if (vers
.bytes
[1] == BCD_illegal
) {
185 // Make sure its the first nibble of byte 1!
186 vers
.bytes
[1] = BCD_combine(vers
.bytes
[1], 0);
190 if (*current_char_p
== '\0') {
191 vers
.bytes
[2] = VERS_release
;
192 vers
.bytes
[3] = 0xff;
194 } else if (isreleasestate(*current_char_p
)) {
196 } else if (*current_char_p
== '.') {
207 * Check for the bugfix number.
209 if (*current_char_p
== '\0') {
210 vers
.bytes
[2] = VERS_release
;
211 vers
.bytes
[3] = 0xff;
213 } else if (vers_isdigit(*current_char_p
)) {
214 scratch
= BCD_digit_for_char(*current_char_p
);
215 if (scratch
== BCD_illegal
) {
219 /* vers.bytes[1] has its left nibble set already */
220 vers
.bytes
[1] = vers
.bytes
[1] | scratch
;
224 if (*current_char_p
== '\0') {
225 vers
.bytes
[2] = VERS_release
;
226 vers
.bytes
[3] = 0xff;
228 } else if (isreleasestate(*current_char_p
)) {
241 * Check for the release state.
243 if (*current_char_p
== '\0') {
244 vers
.bytes
[2] = VERS_release
;
245 vers
.bytes
[3] = 0xff;
248 vers
.bytes
[2] = VERS_revision_for_string(¤t_char_p
);
249 if (vers
.bytes
[2] == VERS_invalid
) {
256 * Get the nonrelease revision number (0..255).
258 if (vers
.bytes
[2] != VERS_release
) {
259 UInt32 revision_num
= 0;
262 if (*current_char_p
== '\0' || !vers_isdigit(*current_char_p
)) {
265 for (i
= 0; i
< 3 && *current_char_p
!= '\0'; i
++, current_char_p
++) {
267 scratch_digit
= BCD_digit_for_char(*current_char_p
);
268 if (scratch_digit
== BCD_illegal
) {
272 revision_num
+= scratch_digit
;
274 if (vers_isdigit(*current_char_p
) || revision_num
> 255) {
277 vers
.bytes
[3] = (UInt8
)revision_num
;
280 if (vers
.bytes
[2] == VERS_release
) {
281 vers
.bytes
[3] = 0xff;
283 if (vers
.bytes
[2] == VERS_candidate
) {
284 if (vers
.bytes
[3] == 0) {
287 vers
.bytes
[2] = VERS_release
;
294 *version_num
= CFSwapInt32BigToHost(vers
.vnum
);
299 #define VERS_STRING_MAX_LEN (12)
301 int VERS_string(char * buffer
, UInt32 length
, UInt32 vers
) {
302 VERS_version version
;
304 int result
= 1; // assume success
311 version
.vnum
= CFSwapInt32HostToBig(vers
);
313 /* No buffer or length less than longest possible vers string,
316 if (!buffer
|| length
< VERS_STRING_MAX_LEN
) {
321 bzero(buffer
, length
* sizeof(char));
325 * Major version number.
327 major1
= BCD_char_for_digit(BCD_get_left(version
.bytes
[0]));
330 } /* this is not an 'else' situation */
332 buffer
[cpos
] = major1
;
336 major2
= BCD_char_for_digit(BCD_get_right(version
.bytes
[0]));
341 buffer
[cpos
] = major2
;
346 * Minor & bug-fix version numbers.
348 minor
= BCD_char_for_digit(BCD_get_left(version
.bytes
[1]));
352 bugfix
= BCD_char_for_digit(BCD_get_right(version
.bytes
[1]));
358 /* Always display the minor version number.
362 buffer
[cpos
] = minor
;
366 /* Only display the bugfix version number if it's nonzero.
371 buffer
[cpos
] = bugfix
;
376 /* If the release state is final, we're done!
378 if (version
.bytes
[2] == VERS_release
&& version
.bytes
[3] == 255) {
384 * Do the release state and update level.
386 switch (version
.bytes
[2]) {
387 case VERS_development
:
400 if (version
.bytes
[3] < 255) {
402 buffer
[cpos
+1] = 'c';
415 if (version
.bytes
[2] != VERS_release
) {
416 sprintf(&buffer
[cpos
], "%d", version
.bytes
[3]);
418 if (version
.bytes
[3] < 255) {
419 sprintf(&buffer
[cpos
], "%d", version
.bytes
[3] + 1);