view xdwpush.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
/* 

�@�\:
  DocuWorks�����̖����ɕʂ̃t�@�C����lj�����
�g�p���@:
  xdwpush �����t�@�C���� �lj�����t�@�C����

*/

#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���@: xdwpush �����t�@�C���� �lj�����t�@�C����");
		return 0;
	}

	char in_path[_MAX_PATH], add_path[_MAX_PATH];
	_fullpath(in_path,  argv[1], _MAX_PATH);
	_fullpath(add_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_UPDATE, 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);
	int last_page = info.nPages;

	api_result = XDW_InsertDocument( h, last_page+1, add_path, NULL );
	if (api_result < 0) print_error(api_result);

	XDW_SaveDocument(h,NULL);
	// �����n���h����‚���
	XDW_CloseDocumentHandle(h, NULL);

	return (api_result >= 0);
}