In message <_A71@freyasx.ML_> on 10/25/05(21:33:44) you Hiroshi Suzuki <pj4yabth4-mxhgu47wyh3w.ml@delegate.org> wrote: |鈴木です。 | |DeleGate/9.0.5-pre7 + FreyaSX-0.99.13 で、 | |-Fany2fdif -c.pdf 'command' | |のようにしても動かなかったので、なんでかなと色々やって見たのですが、 |そもそも、拡張子 pdf が対象になっていないように見えるので、 |ちょっと、ソースをのぞいていたのですが、 | |fsx/any2fdif.c に以下の記述があり、 | |/* | * screening by suffix of URL | * this table should be loadable from any2fdif.conf | */ |... | {"pdf", T_TEXT}, |... | |のように、ハードコーディングしてみたらいちおう、動くようになりました。 |他に方法がありましたらお教え願います。 なるほど。 未知の拡張子 .ext について、-c.ext で定義すると、T_TEXT と定義するよう になって索引化の対象になるのですが、.pdf は(非テキストと)予め定義済み なので、対象にされなかったわけですね。 ということで、-c.ext で指定された時に、型が非テキストになっていたら、 T_TEXT に変更する、というようにします。それと、-c.ext "commmand" の "command" が索引化の対象になるというバグがあったので、これも修正します。 *** ../delegate9.0.5-pre7/fsx/any2fdif.c Sat Oct 8 22:09:44 2005 --- fsx/any2fdif.c Tue Oct 25 22:56:22 2005 *************** *** 264,269 **** --- 264,273 ---- for( xi = 0; cext = types[xi].ext; xi++ ){ if( strcaseeq(ext,cext) ){ + if( types[xi].itype == 0 ){ + types[xi].itype = T_TEXT; + /* might be T_HTML or other ... */ + } types[xi].cnv = strdup(cnv); return; } *************** *** 1224,1229 **** --- 1228,1234 ---- if( strncmp(a1,"-c",2) == 0 ){ if( ai+1 < ac ){ if( a1[2] == '.' ){ + ++ai; }else{ conv = av[++ai]; } #any2fdif.c の中の "pdf" の行を削除する、という対処法も、無くはないですね:) |# any2fdif.conf というのがあるようにも見えますが、 |# 書式がわかりませんでした。 えーと、これは実は DeleGate のパラメタファイルそのものです。リモートの サーバから収集して来る時に、プロキシやらキャッシュやらタイムアウトやらを 指定するのに使いますが、コメントにあるような any2fdif を制御するための 機能は、たぶん、まだ実現しておりません。(外部フィルタとか、ファイルの 型定義とかは、any2fdif 用にも使えるかも知れませんが) ところで、先日のやりとりの後で、例えば converter -i input-file -o output-file のような変換コマンドに対して、 -c.ext "converter -i ^^i -o ^^o" のようにして、any2fdif から入力ファイル "^^i" と出力ファイル "^^o" を コマンドに渡せるようにしてみました。また、変換コマンドは system("command") として実行されるので、コマンドインタプリタを経由しますが、このオーバヘッド やらを除くために、"-exec" というのを前置して、直接 exec() するようにでき ます。 -c.ext "-exec command" 変換コマンドを指定した場合の処理速度を簡単に調べてみました。以下、 mail-lists/delegate-en の記事がテストデータです(MacOSX10.2 /1GHz PPC/iMac) any2fdif -q -r delegate-en ... 220記事/秒 any2fdif -q -c cat -r delegate-en ... 40記事/秒 any2fdif -q -c "-exec cat" -r delegate-en ... 60記事/秒 any2fdif -q -c "cp ^^i ^^o" -r delegate-en ... 40記事/秒 any2fdif -q -c "-exec cp ^^i ^^o" -r delegate-en ... 60記事/秒 any2fdif -q -c "xcat" -r delegate-en ... 12記事/秒 any2fdif -q -c "-exec xcat" -r delegate-en ... 13記事/秒 [xcat] #!/bin/sh cat > /tmp/$$i cp /tmp/$$i /tmp/$$o cat /tmp/$$o rm /tmp/$$i /tmp/$$o この記法やら実装やらは、まだ試行的なものですが、 変換コマンド自体が軽くて、かつ比較的多数のファイルに適用される場合、 テンポラリファイルへの受渡しをコマンド側で行うと、それが実行性能に影響 して来ますので、このような方法が必要と思います。記法が確定したらDeleGate のCFIでも使えるようにしたいと思っています。 D G ┌─┐┬┌──┬┐ //\^^ ( - ); {Do the more with the less -- B. Fuller} ├─┤│└─┐│ / 877m\_< >_ <URL:http://www.delegate.org/delegate/> ┴ └┴──┘┴────────────────────────────── 佐藤豊@情報技術研究部門.産業技術総合研究所(独立行政法人) *** ../delegate9.0.5-pre7/fsx/any2fdif.c Sat Oct 8 22:09:44 2005 --- fsx/any2fdif.c Tue Oct 25 22:59:17 2005 *************** *** 24,29 **** --- 24,30 ---- typedef struct sed_env SedEnv; int sed_compile(SedEnv *se,PCStr(command)); void sed_execute1(SedEnv *se,PCStr(in),PVStr(out),int err); + int relay_file(FILE *in,FILE *out,int sizemax,int timeout,int timemax); int scanAttrs(PCStr(src),int an,PCStr(nam1),PVStr(val1),int vsiz1,PCStr(nam2),PVStr(val2),int vsiz2); static void scanUrls(FILE *flist,int optr,PCStr(strip),PCStr(pre),PCStr(conv),FILE *out,FILE *descf); *************** *** 37,42 **** --- 38,46 ---- int scanMeta(PCStr(src),PVStr(nam),int nsiz,PVStr(con),int csiz); void backseek(FILE *in, int disp); + void setnamedtmpbase(PCStr(path)); + void removenamedtmpfiles(); + static double Start; #ifdef MAIN *************** *** 264,269 **** --- 268,277 ---- for( xi = 0; cext = types[xi].ext; xi++ ){ if( strcaseeq(ext,cext) ){ + if( types[xi].itype == 0 ){ + types[xi].itype = T_TEXT; + /* might be T_HTML or other ... */ + } types[xi].cnv = strdup(cnv); return; } *************** *** 346,351 **** --- 354,387 ---- return types[xi].itype; } + static int CCX_nonASCII; + static int CCX_ASCII; + int CCXpending(CCXP ccx); + static int doCCX(CCXP ccx,PCStr(is),int il,PVStr(os),int oz){ + int ol; + const char *sp; + char ch; + int ii; + sp = is; + + if( CCXpending(ccx) ){ + CCX_nonASCII += il; + return CCXexec(ccx,is,il,BVStr(os),oz); + } + for( ii = 0; ii < il; ii++ ){ + ch = *sp++; + if( ch == 033 || ch & 0x80 ){ + CCX_nonASCII += il; + ol = CCXexec(ccx,is,il,BVStr(os),oz); + return ol; + } + } + CCX_ASCII += il; + strcpy(os,is); + return il; + } + #define CCXexec(ccx,is,il,os,oz) doCCX(ccx,is,il,os,oz) + #define E_OK 0 #define E_EOF 1 #define E_CTRL 2 *************** *** 401,406 **** --- 437,443 ---- fprintf(stderr,"Indexed: %d (with Author: %d+%d)\n",NumPut, withAuthor,guessedAuthor); + fprintf(stderr,"in-ASCII: %d, non-ASCII: %d\n",CCX_ASCII,CCX_nonASCII); } static void Lap(int force,int outlen,PCStr(fmt),...); *************** *** 928,933 **** --- 965,971 ---- fprintf(stderr,"Error: %s\n",outname); exit(-1); } + setnamedtmpbase(outname); scanUrls(flist,optr,strip,pre,conv,Out,Descf); } void updateSrt(PCStr(base),PCStr(strip),PCStr(pre)) *************** *** 1224,1229 **** --- 1262,1268 ---- if( strncmp(a1,"-c",2) == 0 ){ if( ai+1 < ac ){ if( a1[2] == '.' ){ + ++ai; }else{ conv = av[++ai]; } *************** *** 1308,1313 **** --- 1347,1353 ---- scanFilelist(outbase,outname,outmode,strip,pre,conv,Tmp4,optr); } dumptypes(); + removenamedtmpfiles(); return 0; } *************** *** 1588,1593 **** --- 1628,1711 ---- void scanMail(FILE *in,FILE *out,PCStr(apath),int ismbox,int lev); void scanHtml(FILE *in,FILE *tmp,PCStr(apath)); + #define FA_IN "^^i" + #define FA_OUT "^^o" + + static struct { + FILE *t_fp; + char *t_name; + char *t_path; + } tmpfiles[8]; + static char *tmpbase; + static int tmpfilex; + void setnamedtmpbase(PCStr(path)){ + int crc; + const char *dp; + CStr(base,128); + crc = strCRC32(path,strlen(path)); + if( dp = strrpbrk(path,"/\\") ) + dp++; + else dp = path; + sprintf(base,"%X-%s",crc,dp); + tmpbase = stralloc(base); + } + void removenamedtmpfiles(){ + int fi; + for( fi = 0; fi < tmpfilex; fi++ ){ + unlink(tmpfiles[fi].t_path); + free(tmpfiles[fi].t_name); + free(tmpfiles[fi].t_path); + } + tmpfilex = 0; + if( tmpbase ){ + free(tmpbase); + tmpbase = 0; + } + } + FILE *namedtmpfile(FILE *ofp,PVStr(path),PCStr(name),PCStr(mode)){ + FILE *fp; + refQStr(dp,path); + CStr(tpath,1024); + CStr(xpath,1024); + const char *cpath = 0; + int fi; + + for( fi = 0; fi < tmpfilex; fi++ ){ + if( strcmp(name,tmpfiles[fi].t_name) == 0 ){ + strcpy(path,tmpfiles[fi].t_path); + fp = freopen(path,mode,ofp); + return fp; + } + } + if( ofp ){ + fclose(ofp); + } + + fp = TMPFILEX(AVStr(tpath)); + fclose(fp); + strcpy(xpath,tpath); + if( *name ){ + if( dp = strrpbrk(xpath,"/\\") ){ + dp++; + strcpy(dp,name); + if( tmpbase ){ + Xsprintf(TVStr(dp),"-%s",tmpbase); + } + if( rename(tpath,xpath) == 0 ){ + strcpy(tpath,xpath); + } + } + } + if( tmpfilex < elnumof(tmpfiles) ){ + tmpfiles[tmpfilex].t_name = stralloc(name); + tmpfiles[tmpfilex].t_path = stralloc(tpath); + tmpfilex++; + } + strcpy(path,tpath); + fp = fopen(tpath,mode); + return fp; + } + int any2fdif(PCStr(pre),PCStr(strip),PCStr(apath),int mi,PCStr(sub),PCStr(conv),FILE *ain,FILE *out,FILE *descf,int *itypep) { FILE *in = ain; const char *path = apath; *************** *** 1632,1642 **** --- 1750,1791 ---- } if( conv != NULL ){ FILE *Tmp3; + static CStr(ifile,1024); + static CStr(ofile,1024); + static FILE *fin; + static FILE *fout; + CStr(xconv,1024); + + strcpy(xconv,conv); + if( strstr(conv,FA_IN) ){ + fin = namedtmpfile(fin,AVStr(ifile),"fsx-i","w"); + relay_file(in,fin,0,0,0); + ftruncate(fileno(fin),(off_t)ftell(fin)); + strsubst(AVStr(xconv),FA_IN,ifile); + fseek(fin,0,0); /*this is necessary for the first data + otherwise fgets(in) will fail by unknown reason ???*/ + } + if( strstr(conv,FA_OUT) ){ + fout = namedtmpfile(fout,AVStr(ofile),"fsx-o","r"); + fclose(fout); + strsubst(AVStr(xconv),FA_OUT,ofile); + sysfilter(xconv,in,fout); + fout = fopen(ofile,"r"); + if( fout == NULL ){ + fprintf(stderr,"cannot open %s\n",ofile); + exit(0); + } + in = fout; + }else{ Tmp3 = getTmp(TMP3); ftruncate(fileno(Tmp3),(off_t)0); + /* sysfilter(conv,in,Tmp3); + */ + sysfilter(xconv,in,Tmp3); fseek(Tmp3,0,0); in = Tmp3; + } } Title[0] = 0; *************** *** 2714,2723 **** --- 2863,2884 ---- int sysfilter(PCStr(filter),FILE *in,FILE *out) { int sv0,sv1; FILE *pfp; + int ac; + const char *av[32]; + CStr(argb,1024); sv0 = dup(0); dup2(fileno(in),0); sv1 = dup(1); dup2(fileno(out),1); + + if( strncmp(filter,"-exec ",6) == 0 ){ + if( fork() == 0 ){ + ac = decomp_args(av,elnumof(av),filter,AVStr(argb)); + Execvp("sysfilter",av[1],&av[1]); + exit(-1); + } + }else{ system(filter); + } wait(0); dup2(sv1,1); close(sv1); dup2(sv0,0); close(sv0);