Created
August 18, 2017 21:12
-
-
Save darcyliu/8e48a1d614de133df0dfb5a387af94fb to your computer and use it in GitHub Desktop.
OSX dictionary definition lookup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Command-line dictionary lookup. | |
// | |
// Build with: | |
// clang -framework CoreServices | |
// clang -fobjc-arc -fmodules definition.m -o definition | |
#import <CoreFoundation/CoreFoundation.h> | |
#import <CoreServices/CoreServices.h> | |
int main(int argc, char *argv[]) { | |
if (argc < 2) | |
return 1; | |
for (int i = 1; i < argc; i++) { | |
CFStringRef searchPhrase = CFStringCreateWithCString(NULL, argv[i], kCFStringEncodingUTF8); | |
if (searchPhrase) { | |
CFRange searchRange = DCSGetTermRangeInString(NULL, searchPhrase, 0); | |
CFStringRef definition = DCSCopyTextDefinition(NULL, searchPhrase, searchRange); | |
if (definition) { | |
printf("--- definition of %s:\n", argv[i]); | |
} else { | |
printf("--- no definition found for %s\n\n", argv[i]); | |
} | |
CFShow(definition); | |
CFRelease(definition); | |
} | |
CFRelease(searchPhrase); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment