source: trunk/config.tests/mac/xcodeversion.cpp@ 243

Last change on this file since 243 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 1.4 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <CoreFoundation/CoreFoundation.h>
4#include <Carbon/Carbon.h>
5
6int success = 0;
7int fail = 1;
8int internal_error = success; // enable dwarf on internal errors
9
10int main(int argc, const char **argv)
11{
12 CFURLRef cfurl;
13 OSStatus err = LSFindApplicationForInfo(0, CFSTR("com.apple.Xcode"), 0, 0, &cfurl);
14 if (err != noErr)
15 return internal_error;
16
17 CFBundleRef bundle = CFBundleCreate(0, cfurl);
18 if (bundle == 0)
19 return internal_error;
20
21 CFStringRef str = CFStringRef(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("CFBundleShortVersionString")));
22 const char * ptr = CFStringGetCStringPtr(str, 0);
23 if (ptr == 0)
24 return internal_error;
25
26 // self-test
27 const char * fail1 = "2.4";
28 const char * fail2 = "2.4.0";
29 const char * fail3 ="2.3";
30 const char * ok1 = "2.4.1";
31 const char * ok2 ="2.5";
32 const char * ok3 ="3.0";
33// ptr = fail1;
34// printf ("string: %s\n", ptr);
35
36 int length = strlen(ptr);
37 if (length < 3) // expect "x.y" at least
38 return internal_error;
39
40 // fail on 2.4 and below (2.4.1 is ok)
41
42 if (ptr[0] < '2')
43 return fail;
44
45 if (ptr[0] >= '3')
46 return success;
47
48 if (ptr[2] < '4')
49 return fail;
50
51 if (length < 5)
52 return fail;
53
54 if (ptr[4] < '1')
55 return fail;
56
57 return success;
58}
Note: See TracBrowser for help on using the repository browser.