Mercurial > mercurial > hgweb_xdwtools.cgi
view xdwaddpage2.cpp @ 11:3cecce3b2ce3
add (f)lex file.
author | pyon@macmini |
---|---|
date | Fri, 15 Jun 2018 18:44:44 +0900 (2018-06-15) |
parents | cc5262d43399 |
children |
line wrap: on
line source
/* Makefile debug: xdwaddpage2.cpp #cls gcc -g -O0 -I. xdwaddpage2.cpp xdwapi.lib release: xdwaddpage2.cpp gcc -I. xdwaddpage2.cpp xdwapi.lib -static -o xdwaddpage2.exe strip xdwaddpage2.exe clean: rm -rf tempXXXX */ #include <unistd.h> #include <stdbool.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #include <io.h> #include <windows.h> #include <xdw_api.h> #include <xdwapian.h> void print_error( int code ) { fprintf( stderr, "Error code : %d\n", 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; } } void print_help() { char prog[12] = "xdwaddpage2"; fprintf( stderr, "Usage:\n" ); fprintf( stderr, " %s infile\n", prog ); fprintf( stderr, " %s -l infile\n", prog ); fprintf( stderr, " %s -ltxt infile\n", prog ); fprintf( stderr, " %s -s S infile\n", prog ); fprintf( stderr, " %s -c infile1 infile2 ...\n", prog ); fprintf( stderr, " %s -s S -c infile1 infile2 ...\n", prog ); fprintf( stderr, " %s -s S -ltxt -c infile1 infile2 ...\n", prog ); fprintf( stderr, " %s -v infile\n", prog ); } void print_now( char const *msg ) { time_t now = time( NULL ); struct tm *ts = localtime( &now ); char buf[80]; strftime( buf, sizeof( buf ), "%H:%M:%S %Z", ts ); printf( "%s\t%s\n", buf, msg ); } int add_annotation( XDW_DOCUMENT_HANDLE h, int page, int x, int y, char* string, int* sz, int tr ) { // �e�L�X�g�A�m�e�[�V�������쐬���� XDW_ANNOTATION_HANDLE annoation; int api_result = XDW_AddAnnotation( h, XDW_AID_TEXT, page, x, y, NULL, &annoation, NULL ); if ( api_result < 0 ) return api_result; // �쐬�����A�m�e�[�V�����ɕ������ݒ肷�� api_result = XDW_SetAnnotationAttribute( h, annoation, XDW_ATN_Text, XDW_ATYPE_STRING, string, 0, NULL ); // �����e�L�X�g api_result = XDW_SetAnnotationAttribute( h, annoation, XDW_ATN_FontSize, XDW_ATYPE_INT, reinterpret_cast<char*>(sz), 0, NULL ); // �t�H���g�T�C�Y if ( tr ) { int color = XDW_COLOR_NONE; api_result = XDW_SetAnnotationAttribute( h, annoation, XDW_ATN_BackColor, XDW_ATYPE_INT, reinterpret_cast<char*>(&color), 0, NULL ); } return api_result; } int add_page( const char* file, int sp, bool pleft, const char* ltext ) { XDW_DOCUMENT_HANDLE h = NULL; // �����n���h�����J�� XDW_OPEN_MODE_EX mode = { sizeof( XDW_OPEN_MODE_EX ), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE }; int api_result = XDW_OpenDocumentHandle( file, &h, (XDW_OPEN_MODE*)&mode ); if ( api_result < 0 ) { print_error( api_result ); return 0; } XDW_DOCUMENT_INFO info = { sizeof( XDW_DOCUMENT_INFO ), 0 }; // XDW_GetDocumentInformation��p���đ��y�[�W���� XDW_GetDocumentInformation( h, &info ); int last_page = info.nPages; int sz = 80; // �����T�C�Y int tr = 1; // �����t���O char pagenum[18], lpagenum[30]; // �A�m�e�[�V������\��t���� for ( int p = 0; p < last_page; p++ ) { sprintf( pagenum, "%05d-%04d-%04d", p + sp, p + 1, last_page ); api_result = add_annotation( h, p + 1, 17500, 28500, pagenum, &sz, tr ); // �E�� if ( pleft ) { if ( ltext != NULL ) sprintf( lpagenum, "%s%s", pagenum, ltext ); else sprintf( lpagenum, "%s", pagenum ); api_result = add_annotation( h, p + 1, 1700, 5600, lpagenum, &sz, tr ); // ���� } if ( api_result < 0 ) { print_error( api_result ); break; } } if ( api_result >= 0 ) // �ύX���t�@�C���ɔ��f���� api_result = XDW_SaveDocument( h, NULL ); XDW_CloseDocumentHandle( h, NULL ); // �����n���h������� return sp + last_page; } int main( int argc, char* argv[] ) { /* �I�v�V�����̉�� */ bool pnow = false; bool pleft = false; bool chain = false; char *ltext = NULL; int sp = 1; int opt; while ( ( opt = getopt( argc, argv, "vs:l::c" ) ) != -1 ) { switch ( opt ) { case 'v': pnow = true; print_now( "start." ); break; case 'l': pleft = true; ltext = optarg; break; case 's': sp = atoi( optarg ); if ( sp == 0 ) { print_help(); exit( 1 ); } break; case 'c': // chain mode chain = true; break; default: print_help(); exit( 1 ); } } char in_path[ _MAX_PATH ]; /* �{���� */ int api_result = 0; if ( chain ) { int lp = sp; for ( int i = optind; i < argc; i++ ) { _fullpath( in_path, argv[ i ], _MAX_PATH ); lp = add_page( in_path, lp, pleft, ltext ); if ( pnow ) print_now( in_path ); } } else { _fullpath( in_path, argv[ argc - 1 ], _MAX_PATH ); add_page( in_path, sp, pleft, ltext ); } if ( pnow ) print_now( "done." ); return 0; }