2010-07-18
terminal dictionary,, for macosx..
ターミナルで辞書を引を引けるようにしたい.
参考 : 辞書 (Dictionary).appを使い倒そう
http://sakito.jp/mac/dictionary.html
python だと DCSCopyTextDefinition の range
フィールドのタプルがうまく動かないっぽいので
objective-c で書いてみた.
#import <Cocoa/Cocoa.h> #import <CoreServices/CoreServices.h> //#include <DictionaryServices.h> #include <stdio.h> #include <stdlib.h> #include <string.h> void usage(void) { printf("dict [lookup_word]\n"); exit(1); } int main(int argc, char** argv) { if (argc != 2) usage(); id pool = [NSAutoreleasePool new]; //if (argc != 2 ) usage(); const char* arg; arg = argv[1]; NSString* nsarg; nsarg = [NSString stringWithUTF8String:arg]; CFRange range; range.location = 0; range.length = [nsarg length]; CFStringRef ref = NULL; ref = DCSCopyTextDefinition(NULL, (CFStringRef)nsarg, range); //NSLog(@"%@\n", ref); printf("%s\n", [(NSString*)ref UTF8String]); /* struct CFRange { CFIndex location; CFIndex lenght; }; */ /* CFStringRef DCSCopyTextDefinition ( DCSDictionaryRef dictionary, CFStringRef textString, CFRange range ); */ [pool drain]; return 0; }
で、、コンパイル
% gcc -framework Cocoa,CoreFoundation [fimename.m]
DCSCopyTextDefinition の概要は以下..
dictionary---
This parameter is reserved for future use, so pass NULL. Dictionary Services searches in all active dictionaries.
ってことで NULL を埋めるしかないらしい.
textString---
CFStringRef type, please contain lookup work..
なんだけど、、CFStringRef は使い慣れてないので、、ってか c 言語な opaque object っていまいち使いづらい..ちょくせつポインタ差し込みたい..なので、NSString の toll-free-bridge で変換..いや..これ便利.
range---
A range that specifies the location of the word or phrase in the textString parameter. If text string exactly specifies the word or phrase that you want to look up, you can pass the range of the text string.
レンジは、構造体をうめないといけない..上にかいてある.
Discussion---
This function returns the description of the first matching record found in the the active dictionaries. It searches first in the default word definition dictionary which, in the English environment, is the Oxford dictionary.
どうやら辞書自体は選べる様になっていない.ってことで日本語環境だと和英が使えない.
- 152 http://pipes.yahoo.com/pipes/pipe.info?_id=tDfBdGWF3RGl9XNm1L3fcQ
- 3 http://www.google.com/imgres?imgurl=http://f.hatena.ne.jp/images/fotolife/W/WaterFlea/20080930/20080930043957.jpg&imgrefurl=http://d.hatena.ne.jp/WaterFlea/20080929/1222283004&usg=__wUtwZZyxj_ECU9h-6v7VViXbRqk=&h=500&w=800&sz=37&hl=en&start=10&um=1&itbs=1
- 2 http://d.hatena.ne.jp/keyword/gnustep
- 2 http://www.google.co.jp/ig?refresh=1
- 1 http://counter.hatena.ne.jp/archiphoto/log?cid=11&date=&type=
- 1 http://d.hatena.ne.jp/diarylist?of=150&mode=rss&type=public
- 1 http://d.hatena.ne.jp/diarylist?of=50&mode=rss&type=public
- 1 http://d.hatena.ne.jp/inamori/20100718/p1
- 1 http://d.hatena.ne.jp/keyword/Sylpheed?kid=12917
- 1 http://d.hatena.ne.jp/keyword/gcc
