annotate xdwgrep2.cpp @ 10:e421bcd3bce4

xdwaddatn2 done.
author pyon@macmini
date Fri, 06 Apr 2018 18:30:09 +0900
parents 61ce4754737e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
1 /* Makefile
8
61ce4754737e bug fix.
pyon@macmini
parents: 7
diff changeset
2 debug: xdwgrep2.cpp
61ce4754737e bug fix.
pyon@macmini
parents: 7
diff changeset
3 gcc -g -O0 -I. xdwgrep2.cpp xdwapi.lib
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
4 #date
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
5 #./a.exe target.xdw
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
6 #date
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
7
8
61ce4754737e bug fix.
pyon@macmini
parents: 7
diff changeset
8 release: xdwgrep2.cpp
61ce4754737e bug fix.
pyon@macmini
parents: 7
diff changeset
9 gcc -I. xdwgrep2.cpp xdwapi.lib -static -o xdwgrep2.exe
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
10 strip xdwgrep2.exe
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
11
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
12 */
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
13
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
14 #include <stdbool.h>
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
15 #include <stdio.h>
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
16 #include <string.h>
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
17 #include <stdlib.h>
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
18 #include <time.h>
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
19 #include <io.h>
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
20 #include <windows.h>
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
21 #include <xdw_api.h>
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
22
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
23 #define MAXKWORD 256
8
61ce4754737e bug fix.
pyon@macmini
parents: 7
diff changeset
24 #define MAXLINE 4096
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
25
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
26 void print_error( int code ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
27 fprintf( stderr, "Error code : %d\n", code );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
28 switch ( code ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
29 case XDW_E_NOT_INSTALLED:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
30 fprintf( stderr, "DocuWorksがインストールされていません。" );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
31 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
32 case XDW_E_FILE_NOT_FOUND:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
33 fprintf( stderr, "指定されたファイルが見つかりません。" );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
34 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
35 case XDW_E_FILE_EXISTS:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
36 fprintf( stderr, "指定されたファイルはすでに存在します。" );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
37 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
38 case XDW_E_ACCESSDENIED:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
39 case XDW_E_INVALID_NAME:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
40 case XDW_E_BAD_NETPATH:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
41 fprintf( stderr, "指定されたファイルを開くことができません。" );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
42 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
43 case XDW_E_BAD_FORMAT:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
44 fprintf( stderr, "指定されたファイルは正しいフォーマットではありません。" );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
45 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
46 case XDW_E_INVALID_ACCESS:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
47 fprintf( stderr, "指定された操作をする権利がありません。" );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
48 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
49 default:
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
50 fprintf( stderr, "エラーが発生しました。" );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
51 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
52 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
53 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
54
8
61ce4754737e bug fix.
pyon@macmini
parents: 7
diff changeset
55 void print_now( const char *msg ) {
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
56 time_t now = time( NULL );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
57 struct tm *ts = localtime( &now );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
58
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
59 char buf[80];
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
60 strftime( buf, sizeof( buf ), "%H:%M:%S %Z", ts );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
61 printf( "%s\t%s\n", buf, msg );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
62 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
63
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
64 /* 指定された単語で検索 */
8
61ce4754737e bug fix.
pyon@macmini
parents: 7
diff changeset
65 int xdw_grep( const char infile[ _MAX_PATH ], const char outfile[ _MAX_PATH ], const char keyword[ MAXKWORD ], int inv ) {
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
66
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
67 char in_path[ _MAX_PATH ], out_path[ _MAX_PATH ], tmp_path[ _MAX_PATH ];
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
68 _fullpath( in_path, infile, _MAX_PATH );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
69 _fullpath( out_path, outfile, _MAX_PATH );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
70 _fullpath( tmp_path, "tempXXXX.xdw", _MAX_PATH );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
71
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
72 remove( tmp_path );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
73 remove( out_path );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
74
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
75 char buf[ _MAX_PATH ];
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
76 sprintf( buf, "copy %s %s", in_path, tmp_path );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
77 system( buf );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
78
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
79 int api_result = 0;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
80
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
81 // 文書ハンドルを開く
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
82 XDW_DOCUMENT_HANDLE h = NULL;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
83 XDW_OPEN_MODE_EX mode = { sizeof( XDW_OPEN_MODE_EX ), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE };
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
84 api_result = XDW_OpenDocumentHandle( tmp_path, &h, ( XDW_OPEN_MODE* )&mode );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
85 if ( api_result < 0 ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
86 print_error( api_result );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
87 return 1;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
88 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
89
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
90 XDW_DOCUMENT_INFO info = { sizeof( XDW_DOCUMENT_INFO ), 0, 0, 0 }; // 総ページ数を得る
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
91 XDW_GetDocumentInformation( h, &info );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
92 int last_page = info.nPages;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
93
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
94 XDW_FOUND_HANDLE pFoundHandle = NULL;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
95 for ( int i = last_page; i >= 1; i-- ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
96 api_result = XDW_FindTextInPage( h, i, keyword, NULL, &pFoundHandle, NULL );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
97
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
98 if ( inv == 0 && pFoundHandle == NULL )
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
99 api_result = XDW_DeletePage( h, i, NULL );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
100 else if ( inv == 1 && pFoundHandle != NULL )
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
101 api_result = XDW_DeletePage( h, i, NULL );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
102
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
103 XDW_CloseFoundHandle( pFoundHandle );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
104 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
105 // 文書ハンドルを閉じる
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
106 XDW_SaveDocument( h, NULL );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
107 XDW_CloseDocumentHandle( h, NULL );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
108
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
109 // 最適化
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
110 api_result = XDW_OptimizeDocument( tmp_path, out_path, NULL );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
111 if ( api_result < 0 ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
112 print_error( api_result );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
113 exit( 1 );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
114 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
115 remove( tmp_path );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
116
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
117 return 0;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
118 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
119
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
120 /* 検索する単語のリストをファイルから読み込む */
8
61ce4754737e bug fix.
pyon@macmini
parents: 7
diff changeset
121 int xdw_grep_list( const char infile[ _MAX_PATH ], const char outfile[ _MAX_PATH ], bool inv ) {
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
122
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
123 char in_path[ _MAX_PATH ], out_path[ _MAX_PATH ], tmp_path[ _MAX_PATH ];
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
124 _fullpath( in_path, infile, _MAX_PATH );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
125 _fullpath( out_path, outfile, _MAX_PATH );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
126 _fullpath( tmp_path, "tempXXXX.xdw", _MAX_PATH );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
127
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
128 remove( tmp_path );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
129 remove( out_path );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
130
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
131 char buf[ _MAX_PATH ];
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
132 sprintf( buf, "copy %s %s", in_path, tmp_path );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
133 system( buf );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
134
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
135 /* リストの取り込み */
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
136 char *al = (char*)malloc( MAXLINE * sizeof( char ) * MAXKWORD );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
137 int alN = 0;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
138 FILE *fp;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
139
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
140 if ( al == NULL ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
141 fprintf( stderr, "can't allocate memory\n" );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
142 exit( 1 );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
143 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
144
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
145 if ( ( fp = fopen( "grep.list", "r" ) ) == NULL ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
146 fprintf( stderr, "can't open file [grep.list]\n" );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
147 exit ( 1 );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
148 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
149 char *p;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
150 while ( fgets( buf, sizeof buf, fp ) ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
151 if ( !strncmp( buf, "#", 1 ) ) continue;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
152 if ( !strncmp( buf, "//", 2 ) ) continue;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
153 if ( !strcmp( buf, "\n" ) ) continue;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
154
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
155 if ( ( p = strchr( buf, '\n' ) ) != NULL ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
156 *p = '\0';
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
157 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
158 strncpy( &al[ alN * MAXKWORD ], buf, MAXKWORD );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
159 alN++;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
160 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
161 fclose( fp );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
162 int api_result = 0;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
163
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
164 // 文書ハンドルを開く
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
165 XDW_DOCUMENT_HANDLE h = NULL;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
166 XDW_OPEN_MODE_EX mode = { sizeof( XDW_OPEN_MODE_EX ), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE };
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
167 api_result = XDW_OpenDocumentHandle( tmp_path, &h, ( XDW_OPEN_MODE* )&mode );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
168 if ( api_result < 0 ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
169 print_error( api_result );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
170 return 1;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
171 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
172
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
173 XDW_DOCUMENT_INFO info = { sizeof( XDW_DOCUMENT_INFO ), 0, 0, 0 }; // 総ページ数を得る
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
174 XDW_GetDocumentInformation( h, &info );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
175 int last_page = info.nPages;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
176
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
177 XDW_FOUND_HANDLE pFoundHandle = NULL;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
178 bool f[9999];
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
179 for ( int p = 0; p < last_page; p++ )
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
180 f[p] = false;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
181
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
182 for ( int p = 0; p < last_page; p++ ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
183 for ( int i = 0; i < alN; i++ ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
184 api_result = XDW_FindTextInPage( h, p + 1, &al[ i * MAXKWORD ], NULL, &pFoundHandle, NULL );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
185 if ( pFoundHandle ) f[p] = true;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
186 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
187 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
188 XDW_CloseFoundHandle( pFoundHandle );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
189
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
190 if ( inv )
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
191 for ( int p = 0; p < last_page; p++ )
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
192 f[p] = !f[p];
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
193
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
194 for ( int p = last_page; p >= 1; p-- ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
195 if ( !f[ p - 1 ] )
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
196 api_result = XDW_DeletePage( h, p, NULL );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
197 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
198 // 文書ハンドルを閉じる
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
199 XDW_SaveDocument( h, NULL );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
200 XDW_CloseDocumentHandle( h, NULL );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
201
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
202 // 最適化
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
203 api_result = XDW_OptimizeDocument( tmp_path, out_path, NULL );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
204 if ( api_result < 0 ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
205 print_error( api_result );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
206 exit( 1 );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
207 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
208 remove( tmp_path );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
209
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
210 return 0;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
211 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
212
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
213
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
214 int main( int argc, char* argv[] ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
215
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
216 /* オプションの解析 */
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
217 char prog[128];
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
218 strcpy( prog, argv[0] );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
219
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
220 bool pnow = false;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
221 bool match = true;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
222 bool unmatch = false;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
223 bool list = false;
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
224 char c;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
225 while ( --argc > 0 && ( *++argv )[0] == '-' ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
226 while ( c = *++argv[0] ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
227 switch ( c ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
228 case 'l':
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
229 pnow = true;
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
230 print_now( "start." );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
231 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
232 case 'v':
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
233 match = false;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
234 unmatch = true;
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
235 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
236 case 'w':
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
237 unmatch = true;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
238 break;
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
239 case 'i':
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
240 list = true;
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
241 break;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
242 default:
3
edfa39292d78 small fix.
pyon@macmini
parents: 2
diff changeset
243 fprintf( stderr, "error: illegal option '%c'.\n", c );
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
244 exit( 1 );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
245 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
246 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
247 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
248
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
249
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
250 if ( list ) {
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
251 xdw_grep_list( argv[0], "mout.xdw", unmatch );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
252 exit( 0 );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
253 }
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
254
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
255 if ( argc < 2 ) {
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
256 fprintf( stderr, "%s keyword infile\n", prog );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
257 fprintf( stderr, "%s -v keyword infile\n", prog );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
258 fprintf( stderr, "%s -w keyword infile\n", prog );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
259 fprintf( stderr, "%s -l keyword infile\n", prog );
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
260 fprintf( stderr, "%s -i infile\n", prog );
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
261 fprintf( stderr, "%s -i -v infile\n", prog );
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
262 exit( 1 );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
263 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
264
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
265 /* 検索 */
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
266 if ( pnow ) print_now( "searching xdw-file." );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
267
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
268 if ( match ) // unmatch == 0|1
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
269 xdw_grep( argv[1], "mout.xdw", argv[0], 0 );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
270 else // match == 0 && unmatch == 1
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
271 xdw_grep( argv[1], "uout.xdw", argv[0], 1 );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
272
7
8de5b1bd9506 update xdwgrep2.
pyon@macmini
parents: 3
diff changeset
273 if ( match && unmatch )
2
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
274 xdw_grep( argv[1], "uout.xdw", argv[0], 1 );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
275
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
276 if ( pnow ) print_now( "done." );
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
277 return 0;
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
278 }
f96c40f7aeae add xdwgrep2.
pyon@macmini
parents:
diff changeset
279