Mercurial > mercurial > hgweb_xdwtools.cgi
diff xdwsort.cpp @ 8:61ce4754737e
bug fix.
author | pyon@macmini |
---|---|
date | Tue, 03 Apr 2018 00:11:01 +0900 |
parents | edfa39292d78 |
children |
line wrap: on
line diff
--- a/xdwsort.cpp Sat Mar 24 08:51:45 2018 +0900 +++ b/xdwsort.cpp Tue Apr 03 00:11:01 2018 +0900 @@ -1,20 +1,21 @@ /* Makefile -debug: xdwsort.c +debug: xdwsort.cpp #rm -rf tempXXXX #cls - gcc -g -O0 -I. xdwsort.c xdwapi.lib + gcc -g -O0 -I. xdwsort.cpp xdwapi.lib #date #./a.exe target.xdw #date -release: xdwsort.c - gcc -I. xdwsort.c xdwapi.lib -static -o xdwsort.exe +release: xdwsort.cpp + gcc -I. xdwsort.cpp xdwapi.lib -static -o xdwsort.exe strip xdwsort.exe clean: rm -rf tempXXXX */ +#include <stdbool.h> #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -57,7 +58,7 @@ } } -void print_now( char *msg ) { +void print_now( const char *msg ) { time_t now = time( NULL ); struct tm *ts = localtime( &now ); @@ -72,17 +73,23 @@ char prog[128]; strcpy( prog, argv[0] ); - int pnow = 0; + bool pnow = false; + bool debug = false; char c; while ( --argc > 0 && ( *++argv )[0] == '-' ) { while ( c = *++argv[0] ) { switch ( c ) { case 'v': - pnow = 1; + pnow = true; print_now( "start." ); break; case 'l': /* now writing... */ break; + case 'd': + pnow = true; + debug = true; + print_now( "debug-mode start." ); + break; default: fprintf( stderr, "error: illegal option '%c'.\n", c ); exit( 1 ); @@ -93,6 +100,7 @@ if ( argc < 1 ) { fprintf( stderr, "%s infile\n", prog ); fprintf( stderr, "%s -v infile\n", prog ); + fprintf( stderr, "%s -d infile\n", prog ); exit( 1 ); } @@ -109,7 +117,7 @@ } if ( ( fp = fopen( "sort.list", "r" ) ) == NULL ) { - fprintf( stderr, "%s: can't open file [sort.list]\n", argv[0] ); + fprintf( stderr, "%s: can't open file [sort.list]\n", prog ); exit ( 1 ); } @@ -223,14 +231,15 @@ strncpy( &blk_path[ m * _MAX_PATH ], in_path, _MAX_PATH ); blk_path_addr[m] = &blk_path[ m * _MAX_PATH ]; } - if ( last_page % BLOCKSZ != 0 ) { - sprintf( buf, "tempXXXX/b%04d.xdw", ++bn ); - _fullpath( in_path, buf, _MAX_PATH ); - api_result = XDW_MergeXdwFiles( blk_path_addr, last_page % BLOCKSZ, in_path, NULL ); - if ( api_result < 0 ) { - print_error( api_result ); - exit( 1 ); - } + + sprintf( buf, "tempXXXX/b%04d.xdw", ++bn ); + _fullpath( in_path, buf, _MAX_PATH ); + int mod = last_page % BLOCKSZ; + if ( mod == 0 ) mod = BLOCKSZ; + api_result = XDW_MergeXdwFiles( blk_path_addr, mod, in_path, NULL ); + if ( api_result < 0 ) { + print_error( api_result ); + exit( 1 ); } // ブロックをまとめる @@ -291,15 +300,17 @@ } /* 後処理 */ - if ( pnow ) print_now( "cleaning." ); - glob_t globbuf; - glob( "tempXXXX/*.*", 0, NULL, &globbuf ); - for ( int i = 0; i < globbuf.gl_pathc; i++ ) { - _fullpath( in_path, globbuf.gl_pathv[i], _MAX_PATH ); - remove( in_path ); - } - globfree( &globbuf ); - rmdir( "tempXXXX" ); + if ( !debug ) { + if ( pnow ) print_now( "cleaning." ); + glob_t globbuf; + glob( "tempXXXX/*.*", 0, NULL, &globbuf ); + for ( int i = 0; i < globbuf.gl_pathc; i++ ) { + _fullpath( in_path, globbuf.gl_pathv[i], _MAX_PATH ); + remove( in_path ); + } + globfree( &globbuf ); + rmdir( "tempXXXX" ); + } if ( pnow ) print_now( "done." ); return 0;