Mercurial > mercurial > hgweb_xdwtools.cgi
view xdwsplit.cpp @ 0:c1ebc8b218f2
xdwtools source code.
author | pyon@macmini |
---|---|
date | Sun, 29 Mar 2015 18:11:58 +0900 (2015-03-29) |
parents | |
children |
line wrap: on
line source
/* xdwsplit �@�\: DocuWorks�������w��y�[�W�����Ƃɕ��� */ #include <stdio.h> #include <stdlib.h> #include <io.h> #include <windows.h> #include <xdw_api.h> void print_error(int code) { switch (code) { case XDW_E_NOT_INSTALLED: fprintf(stderr, "DocuWorks���C���X�g�[������Ă��܂���B"); break; case XDW_E_FILE_NOT_FOUND: fprintf(stderr, "�w�肳�ꂽ�t�@�C����������܂���B"); break; case XDW_E_FILE_EXISTS: fprintf(stderr, "�w�肳�ꂽ�t�@�C���͂��łɑ��݂��܂��B"); break; case XDW_E_ACCESSDENIED: case XDW_E_INVALID_NAME: case XDW_E_BAD_NETPATH: fprintf(stderr, "�w�肳�ꂽ�t�@�C�����J�����Ƃ��ł��܂���B"); break; case XDW_E_BAD_FORMAT: fprintf(stderr, "�w�肳�ꂽ�t�@�C���͐������t�H�[�}�b�g�ł͂���܂���B"); break; case XDW_E_INVALID_ACCESS: fprintf(stderr, "�w�肳�ꂽ��������錠��������܂���B"); break; default: fprintf(stderr, "�G���[���������܂����B"); break; } } int main(int argc, char** argv) { int api_result = 0; if (argc != 3 ) { fprintf(stderr, "�g�p���@: xdwsplit SP �����t�@�C����"); return 0; } int sPage, nPage; char in_path[_MAX_PATH], out_path[_MAX_PATH]; sPage = atoi(argv[1]); _fullpath(in_path, argv[2], _MAX_PATH); // �����n���h�����J�� XDW_DOCUMENT_HANDLE h = NULL; XDW_OPEN_MODE_EX mode = { sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE }; api_result = XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode); if (api_result < 0) { print_error(api_result); return 0; } // XDW_GetDocumentInformation��p���đ��y�[�W���� XDW_DOCUMENT_INFO info = { sizeof(XDW_DOCUMENT_INFO), 0, 0, 0 }; XDW_GetDocumentInformation(h, &info); nPage = info.nPages; // �����n���h������� XDW_CloseDocumentHandle(h, NULL); if (nPage <= sPage) { fprintf(stderr, "���y�[�W�������������y�[�W�����w�肵�Ă��������B"); return 0; } char buf[_MAX_PATH]; int i = 1; int z = 1; if (nPage % sPage == 0) z = 0; // ���C������ while ( i <= nPage/sPage + z ) { sprintf(buf, "%03d.xdw", i); _fullpath(out_path, buf, _MAX_PATH); sprintf(buf, "copy %s %s", in_path, out_path); system(buf); XDW_OPEN_MODE_EX mode = { sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE }; api_result = XDW_OpenDocumentHandle(out_path, &h, (XDW_OPEN_MODE*)&mode); for ( int j = nPage; j >= 1; j-- ) { if ( j > sPage * i || j <= sPage * (i-1) ) api_result = XDW_DeletePage(h, j, NULL); } // �����n���h������� XDW_SaveDocument(h, NULL); XDW_CloseDocumentHandle(h, NULL); i++; } }