Skip to content

Instantly share code, notes, and snippets.

@qunwang6
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qunwang6/795c645c0271c91d32e0 to your computer and use it in GitHub Desktop.
Save qunwang6/795c645c0271c91d32e0 to your computer and use it in GitHub Desktop.
/*
* Command-line dictionary lookup.
*
* Build with:
* clang -framework CoreServices
*/
#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]);
CFShow(definition);
CFRelease(definition);
}
else
printf("--- no definition found for %s\n\n", argv[i]);
CFRelease(searchPhrase);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment