ICU-889 add decmn tool
X-SVN-Rev: 4042
This commit is contained in:
parent
574623ab1a
commit
1f895aa6a9
@ -71,6 +71,9 @@ Package=<4>
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name ustdio
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name decmn
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
@ -141,6 +144,18 @@ Package=<4>
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "decmn"=..\tools\gencmn\decmn.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "genccode"=..\tools\genccode\genccode.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
|
206
icu4c/source/tools/gencmn/decmn.c
Normal file
206
icu4c/source/tools/gencmn/decmn.c
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2000, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: decmn.c
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2001mar05
|
||||
* created by: Markus W. Scherer
|
||||
*
|
||||
* This tool takes an ICU common data file (icuxyz.dat),
|
||||
* outputs a list of components,
|
||||
* and writes one file per packaged data piece in the common file.
|
||||
* This can be used to add, remove, or replace data.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/udata.h"
|
||||
|
||||
static uint8_t buffer[100000], buffer2[128*1024];
|
||||
|
||||
static int
|
||||
compareFiles(const void *file1, const void *file2) {
|
||||
/* sort by file offset */
|
||||
int32_t diff=*((int32_t *)file1+1)-*((int32_t *)file2+1);
|
||||
if(diff!=0) {
|
||||
return (int)(diff>>15)|1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
copyFile(FILE *in, int32_t offset, int32_t size, const char *name) {
|
||||
FILE *out;
|
||||
int32_t length;
|
||||
|
||||
if(0!=fseek(in, offset, SEEK_SET)) {
|
||||
fprintf(stderr, "error: cannot seek to position %ld for file \"%s\"\n", offset, name);
|
||||
return 4;
|
||||
}
|
||||
out=fopen(name, "wb");
|
||||
if(out==NULL) {
|
||||
fprintf(stderr, "error: unable to open output file \"%s\"\n", name);
|
||||
return 5;
|
||||
}
|
||||
|
||||
/* copy the contents into the new, separate file */
|
||||
while(size>sizeof(buffer2)) {
|
||||
length=(int32_t)fread(buffer2, 1, sizeof(buffer2), in);
|
||||
if(length<=0) {
|
||||
fprintf(stderr, "error: read error while copying output file \"%s\"\n", name);
|
||||
fclose(out);
|
||||
return 4;
|
||||
}
|
||||
if(length!=(int32_t)fwrite(buffer2, 1, length, out)) {
|
||||
fprintf(stderr, "error: write error while copying output file \"%s\"\n", name);
|
||||
fclose(out);
|
||||
return 5;
|
||||
}
|
||||
size-=length;
|
||||
}
|
||||
while(size>0) {
|
||||
length=(int32_t)fread(buffer2, 1, size, in);
|
||||
if(length<=0) {
|
||||
fprintf(stderr, "error: read error while copying output file \"%s\"\n", name);
|
||||
fclose(out);
|
||||
return 4;
|
||||
}
|
||||
if(length!=(int32_t)fwrite(buffer2, 1, length, out)) {
|
||||
fprintf(stderr, "error: write error while copying output file \"%s\"\n", name);
|
||||
fclose(out);
|
||||
return 5;
|
||||
}
|
||||
size-=length;
|
||||
}
|
||||
|
||||
fclose(out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int
|
||||
main(int argc, const char *argv[]) {
|
||||
FILE *in;
|
||||
UDataInfo *info;
|
||||
uint8_t *base;
|
||||
int32_t *p;
|
||||
int32_t i, length, count, baseOffset;
|
||||
int result;
|
||||
|
||||
if(argc!=2) {
|
||||
fprintf(stderr,
|
||||
"usage: %s icu-data-filename\n"
|
||||
" unpackages ICU common data files:\n"
|
||||
" reads a memory-mappable ICU data file, outputs the list of data pieces to stdout\n"
|
||||
" and writes the packaged data files as separate files in the current folder.\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
in=fopen(argv[1], "rb");
|
||||
if(in==NULL) {
|
||||
fprintf(stderr, "error: unable to open input file \"%s\"\n", argv[1]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* read the beginning of the file */
|
||||
length=(int32_t)fread(buffer, 1, sizeof(buffer), in);
|
||||
if(length<20) {
|
||||
fprintf(stderr, "error: input file too short\n");
|
||||
fclose(in);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* check the validity of the file */
|
||||
if(buffer[2]!=0xda || buffer[3]!=0x27) {
|
||||
fprintf(stderr, "error: not an ICU data file\n");
|
||||
fclose(in);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* check the platform properties for the file */
|
||||
info=(UDataInfo *)(buffer+4);
|
||||
if(info->isBigEndian!=U_IS_BIG_ENDIAN) {
|
||||
fprintf(stderr, "error: the file is in the opposite byte endianness\n");
|
||||
fclose(in);
|
||||
return 3;
|
||||
}
|
||||
if(info->charsetFamily!=U_CHARSET_FAMILY) {
|
||||
fprintf(stderr, "error: the file is not built for this machine's charset family\n");
|
||||
fclose(in);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* check that this is a common data file */
|
||||
if(info->dataFormat[0]!=0x43 || info->dataFormat[1]!=0x6d || info->dataFormat[2]!=0x6e || info->dataFormat[3]!=0x44) {
|
||||
fprintf(stderr, "error: this file is not a common data file\n");
|
||||
fclose(in);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* check for version 1 */
|
||||
if(info->formatVersion[0]!=1) {
|
||||
fprintf(stderr, "error: the format version %d.%d.%d.%d is not known\n",
|
||||
info->formatVersion[0], info->formatVersion[1], info->formatVersion[2], info->formatVersion[3]);
|
||||
fclose(in);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* is there a comment? */
|
||||
if(*(uint16_t *)buffer>4+info->size) {
|
||||
printf("comment=%s\n", buffer+4+info->size);
|
||||
}
|
||||
|
||||
/* output all filenames */
|
||||
baseOffset=*(uint16_t *)buffer;
|
||||
base=buffer+baseOffset;
|
||||
p=(int32_t *)base;
|
||||
count=*p++;
|
||||
printf("files[%ld]\n", count);
|
||||
for(i=0; i<count; ++i) {
|
||||
printf("file[%ld]=%s\n", i, base+*p);
|
||||
p+=2;
|
||||
}
|
||||
puts("endfiles");
|
||||
|
||||
/* sort all files by their offsets in the common file */
|
||||
qsort(base+4, count, 8, compareFiles);
|
||||
|
||||
/* write all files except the last one */
|
||||
p=(int32_t *)(base+4);
|
||||
--count;
|
||||
for(i=0; i<count; ++i) {
|
||||
/* the size is the difference between this file's offset and the next one's */
|
||||
result=copyFile(in, baseOffset+p[1], p[3]-p[1], (const char *)(base+*p));
|
||||
if(result!=0) {
|
||||
fclose(in);
|
||||
return result;
|
||||
}
|
||||
p+=2;
|
||||
}
|
||||
|
||||
/* write the last file */
|
||||
if(count>=0) {
|
||||
/* the size is the number of bytes to the end of the common file */
|
||||
if(0!=fseek(in, 0, SEEK_END)) {
|
||||
fprintf(stderr, "error: unable to seek to the end of the common file\n");
|
||||
return 4;
|
||||
}
|
||||
result=copyFile(in, baseOffset+p[1], (int32_t)ftell(in)-baseOffset-p[1], (const char *)(base+*p));
|
||||
if(result!=0) {
|
||||
fclose(in);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
119
icu4c/source/tools/gencmn/decmn.dsp
Normal file
119
icu4c/source/tools/gencmn/decmn.dsp
Normal file
@ -0,0 +1,119 @@
|
||||
# Microsoft Developer Studio Project File - Name="decmn" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=decmn - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "decmn.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "decmn.mak" CFG="decmn - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "decmn - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "decmn - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "decmn - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "decmn___Win32_Release"
|
||||
# PROP BASE Intermediate_Dir "decmn___Win32_Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "decmn___Win32_Release"
|
||||
# PROP Intermediate_Dir "decmn___Win32_Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /Za /W4 /GX /O2 /I "..\..\common" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# Begin Custom Build
|
||||
InputPath=.\decmn___Win32_Release\decmn.exe
|
||||
InputName=decmn
|
||||
SOURCE="$(InputPath)"
|
||||
|
||||
"..\..\..\bin\$(InputName).exe" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
copy $(InputPath) ..\..\..\bin
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ELSEIF "$(CFG)" == "decmn - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "decmn___Win32_Debug"
|
||||
# PROP BASE Intermediate_Dir "decmn___Win32_Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "decmn___Win32_Debug"
|
||||
# PROP Intermediate_Dir "decmn___Win32_Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /GB /MDd /Za /W4 /Gm /GX /ZI /Od /I "..\..\common" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# Begin Custom Build
|
||||
InputPath=.\decmn___Win32_Debug\decmn.exe
|
||||
InputName=decmn
|
||||
SOURCE="$(InputPath)"
|
||||
|
||||
"..\..\..\bin\$(InputName).exe" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
copy $(InputPath) ..\..\..\bin
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "decmn - Win32 Release"
|
||||
# Name "decmn - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\decmn.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
Loading…
Reference in New Issue
Block a user