comparison xdwsplit.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 /* xdwsplit
2
3 �@�\:
4 DocuWorks�������w��y�[�W�����Ƃɕ���
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 ) {
50 fprintf(stderr, "�g�p���@: xdwsplit SP �����t�@�C����");
51 return 0;
52 }
53
54 int sPage, nPage;
55 char in_path[_MAX_PATH], out_path[_MAX_PATH];
56
57 sPage = atoi(argv[1]);
58 _fullpath(in_path, argv[2], _MAX_PATH);
59
60 // �����n���h�����J��
61 XDW_DOCUMENT_HANDLE h = NULL;
62 XDW_OPEN_MODE_EX mode = { sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE };
63 api_result = XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode);
64 if (api_result < 0) {
65 print_error(api_result);
66 return 0;
67 }
68 // XDW_GetDocumentInformation��p���đ��y�[�W���𓾂�
69 XDW_DOCUMENT_INFO info = { sizeof(XDW_DOCUMENT_INFO), 0, 0, 0 };
70 XDW_GetDocumentInformation(h, &info);
71 nPage = info.nPages;
72 // �����n���h����‚���
73 XDW_CloseDocumentHandle(h, NULL);
74
75 if (nPage <= sPage) {
76 fprintf(stderr, "���y�[�W�������������y�[�W�����w�肵�Ă��������B");
77 return 0;
78 }
79
80 char buf[_MAX_PATH];
81 int i = 1;
82 int z = 1;
83 if (nPage % sPage == 0) z = 0;
84 // ���C������
85 while ( i <= nPage/sPage + z ) {
86
87 sprintf(buf, "%03d.xdw", i);
88 _fullpath(out_path, buf, _MAX_PATH);
89
90 sprintf(buf, "copy %s %s", in_path, out_path);
91 system(buf);
92
93 XDW_OPEN_MODE_EX mode = { sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE };
94 api_result = XDW_OpenDocumentHandle(out_path, &h, (XDW_OPEN_MODE*)&mode);
95
96 for ( int j = nPage; j >= 1; j-- ) {
97 if ( j > sPage * i || j <= sPage * (i-1) )
98 api_result = XDW_DeletePage(h, j, NULL);
99 }
100
101 // �����n���h����‚���
102 XDW_SaveDocument(h, NULL);
103 XDW_CloseDocumentHandle(h, NULL);
104
105 i++;
106 }
107 }
108