view xdw2txtb.cpp @ 4:af8f454d20ed

add xdwsplit2.
author pyon@macmini
date Fri, 27 Oct 2017 01:48:00 +0900 (2017-10-26)
parents c1ebc8b218f2
children
line wrap: on
line source
/* xdw2txtB

�@�\:
  DocuWorks��������w�肵���y�[�W���ƂɃe�L�X�g�𒊏o

*/

#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 != 2 ) {
		fprintf(stderr, "�g�p���@: xdw2txtb �����t�@�C����");
		return 0;
	}

    int nPage;
	char in_path[_MAX_PATH], out_path[_MAX_PATH];

    _fullpath(in_path,  argv[1], _MAX_PATH);
    _fullpath(out_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;

    long datasize;
    char* lpszvalue;
    // ���C������
    for ( int i=1; i<=nPage; i++ ) {
        datasize = XDW_GetPageTextToMemory( h, i, NULL, 0, NULL );
        lpszvalue = (char*)malloc( sizeof(char)*datasize);
        XDW_GetPageTextToMemory( h, i, lpszvalue, datasize, NULL );
        printf( "%s\n", lpszvalue );
        free(lpszvalue);
    }

	if (api_result < 0) print_error(api_result);

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

	return (api_result >= 0);
}