comparison xdwgrep.cpp @ 0:c1ebc8b218f2

xdwtools source code.
author pyon@macmini
date Sun, 29 Mar 2015 18:11:58 +0900 (2015-03-29)
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c1ebc8b218f2
1 /* xdwapi�̃T���v��
2
3 �@�\:
4 DocuWorks������GREP
5
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <io.h>
11
12 #include <windows.h>
13
14 #include <xdw_api.h>
15
16 void print_error(int code)
17 {
18 switch (code) {
19 case XDW_E_NOT_INSTALLED:
20 fprintf(stderr, "DocuWorks���C���X�g�[������Ă��܂���B");
21 break;
22 case XDW_E_FILE_NOT_FOUND:
23 fprintf(stderr, "�w�肳�ꂽ�t�@�C�������‚���܂���B");
24 break;
25 case XDW_E_FILE_EXISTS:
26 fprintf(stderr, "�w�肳�ꂽ�t�@�C���͂��łɑ��݂��܂��B");
27 break;
28 case XDW_E_ACCESSDENIED:
29 case XDW_E_INVALID_NAME:
30 case XDW_E_BAD_NETPATH:
31 fprintf(stderr, "�w�肳�ꂽ�t�@�C�����J�����Ƃ��ł��܂���B");
32 break;
33 case XDW_E_BAD_FORMAT:
34 fprintf(stderr, "�w�肳�ꂽ�t�@�C���͐������t�H�[�}�b�g�ł͂���܂���B");
35 break;
36 case XDW_E_INVALID_ACCESS:
37 fprintf(stderr, "�w�肳�ꂽ��������錠��������܂���B");
38 break;
39 default:
40 fprintf(stderr, "�G���[���������܂����B");
41 break;
42 }
43 }
44
45 int main(int argc, char** argv)
46 {
47 int api_result = 0;
48
49 if (argc != 3 && argc != 4) {
50 fprintf(stderr, "�g�p���@: xdwgrep �������� �����t�@�C����");
51 fprintf(stderr, "�g�p���@: xdwgrep -v �������� �����t�@�C����");
52 fprintf(stderr, "\n���������̓_�u���N�H�[�g�ł�����");
53 return 0;
54 }
55
56 char in_path[_MAX_PATH], out_path[_MAX_PATH];
57 char buf[256], searchtext[256];
58 int rev_flag=0;
59
60 if (argc == 3) {
61 sprintf( searchtext, "%s", argv[1] );
62 sprintf( in_path, "%s", argv[2] );
63 }
64 if (argc == 4 && !strcmp( argv[1], "-v" ) ) {
65 rev_flag=1;
66 sprintf( searchtext, "%s", argv[2] );
67 sprintf( in_path, "%s", argv[3] );
68 }
69 sprintf( out_path, "%s.xdw", searchtext );
70
71 sprintf( buf, "copy %s %s", in_path, out_path );
72 system( buf );
73
74 int page = 0;
75
76 _fullpath(out_path, out_path, _MAX_PATH);
77 // �����n���h�����J��
78 XDW_DOCUMENT_HANDLE h = NULL;
79 XDW_OPEN_MODE_EX mode = { sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE };
80 api_result = XDW_OpenDocumentHandle(out_path, &h, (XDW_OPEN_MODE*)&mode);
81 if (api_result < 0) {
82 print_error(api_result);
83 return 0;
84 }
85
86 // XDW_GetDocumentInformation��p���đ��y�[�W���𓾂�
87 XDW_DOCUMENT_INFO info = { sizeof(XDW_DOCUMENT_INFO), 0, 0, 0 };
88 XDW_GetDocumentInformation(h, &info);
89 int last_page = info.nPages;
90 XDW_FOUND_HANDLE pFoundHandle = NULL;
91
92 if ( !rev_flag ) {
93 for ( int i=last_page; i>=1; i-- ) {
94 api_result = XDW_FindTextInPage( h, i, searchtext, NULL, &pFoundHandle, NULL );
95
96 if ( pFoundHandle == NULL ) {
97 api_result = XDW_DeletePage( h, i, NULL );
98 }
99 XDW_CloseFoundHandle( pFoundHandle );
100 }
101 }
102 else {
103 for ( int i=last_page; i>=1; i-- ) {
104 api_result = XDW_FindTextInPage( h, i, searchtext, NULL, &pFoundHandle, NULL );
105
106 if ( pFoundHandle != NULL ) {
107 api_result = XDW_DeletePage( h, i, NULL );
108 }
109 XDW_CloseFoundHandle( pFoundHandle );
110 }
111 }
112
113 // �����n���h����‚���
114 XDW_SaveDocument( h, NULL );
115 XDW_CloseDocumentHandle(h, NULL);
116
117 return (api_result >= 0);
118 }