ICU-165 create the binary file for convrtrs.txt

X-SVN-Rev: 233
This commit is contained in:
Markus Scherer 1999-11-23 02:17:43 +00:00
parent 773518b3e0
commit e89416b81d
4 changed files with 463 additions and 1 deletions

View file

@ -102,6 +102,24 @@ Package=<4>
###############################################################################
Project: "gencnval"=..\tools\gencnval\gencnval.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name common
End Project Dependency
Begin Project Dependency
Project_Dep_Name toolutil
End Project Dependency
}}}
###############################################################################
Project: "gencol"=..\tools\gencol\gencol.dsp - Package Owner=<4>
Package=<5>

View file

@ -0,0 +1,336 @@
/*
*******************************************************************************
* *
* COPYRIGHT: *
* (C) Copyright International Business Machines Corporation, 1999 *
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************
* file name: gencnval.c
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* created on: 1999nov05
* created by: Markus W. Scherer
*
* This program reads convrtrs.txt and writes a memory-mappable
* converter name alias table to cnvalias.dat .
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "utypes.h"
#include "cmemory.h"
#include "cstring.h"
#include "filestrm.h"
#include "unewdata.h"
#define STRING_STORE_SIZE 100000
#define MAX_ALIAS_COUNT 2000
#define DATA_NAME "cnvalias"
#define DATA_TYPE "dat"
#define DATA_COPYRIGHT "\n" \
"*******************************************************************************\n" \
"* COPYRIGHT: *\n" \
"* (C) Copyright International Business Machines Corporation, 1999 *\n" \
"* Licensed Material - Program-Property of IBM - All Rights Reserved. *\n" \
"* US Government Users Restricted Rights - Use, duplication, or disclosure *\n" \
"* restricted by GSA ADP Schedule Contract with IBM Corp. *\n" \
"*******************************************************************************\n"
/* UDataInfo cf. udata.h */
static const UDataInfo dataInfo={
sizeof(UDataInfo),
0,
U_IS_BIG_ENDIAN,
U_CHARSET_FAMILY,
sizeof(UChar),
0,
0x43, 0x76, 0x41, 0x6c, /* dataFormat="CvAl" */
1, 0, 0, 0, /* formatVersion */
1, 3, 1, 0 /* dataVersion */
};
static char stringStore[STRING_STORE_SIZE];
static uint32_t stringTop=0;
typedef struct {
const char *alias, *converter;
} Alias;
static Alias aliases[MAX_ALIAS_COUNT];
static uint16_t aliasCount=0;
typedef struct {
const char *converter;
uint16_t aliasCount;
} Converter;
static Converter converters[MAX_ALIAS_COUNT];
static uint16_t converterCount=0;
/* prototypes --------------------------------------------------------------- */
static void
parseLine(const char *line);
static void
addAlias(const char *alias, const char *converter);
static Converter *
addConverter(const char *converter);
static char *
allocString(uint32_t length);
static int
compareAliases(const void *file1, const void *file2);
static int
compareConverters(const void *converter1, const void *converter2);
/* -------------------------------------------------------------------------- */
extern int
main(int argc, char *argv[]) {
char line[512];
const char *path, *arg;
FileStream *in;
UNewDataMemory *out;
char *s;
UErrorCode errorCode=U_ZERO_ERROR;
int i;
uint16_t stringOffset;
bool_t haveCopyright=TRUE;
fprintf(stderr,
"usage: %s [-c[+|-]]\n"
"\tread convrtrs.txt and create " DATA_NAME "." DATA_TYPE "\n"
"\t\t-c[+|-] do (not) include a copyright notice\n",
argv[0]);
for(i=1; i<argc; ++i) {
arg=argv[i];
if(arg[0]=='-') {
switch(arg[1]) {
case 'c':
haveCopyright= arg[2]=='+';
break;
default:
break;
}
}
}
path=u_getDataDirectory();
if(path!=NULL) {
icu_strcpy(line, path);
icu_strcat(line, "convrtrs.txt");
path=line;
} else {
path="convrtrs.txt";
}
in=T_FileStream_open(path, "r");
if(in==NULL) {
fprintf(stderr, "gencnval: unable to open input file convrtrs.txt\n");
exit(U_FILE_ACCESS_ERROR);
}
/* read the list of aliases */
while(T_FileStream_readLine(in, line, sizeof(line))!=NULL) {
/* remove trailing newline characters */
s=line;
while(*s!=0) {
if(*s=='\r' || *s=='\n') {
*s=0;
break;
}
++s;
}
parseLine(line);
}
T_FileStream_close(in);
/* sort the aliases and the converters */
qsort(aliases, aliasCount, sizeof(Alias), compareAliases);
qsort(converters, converterCount, sizeof(Converter), compareConverters);
/* create the output file */
out=udata_create(DATA_TYPE, DATA_NAME, &dataInfo,
haveCopyright ? DATA_COPYRIGHT : NULL, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "gencnval: unable to open output file - error %s\n", errorName(errorCode));
exit(errorCode);
}
/* determine the length of tables for the data offset of the strings */
stringOffset=2+4*aliasCount+2+4*converterCount;
/* write the table of aliases */
udata_write16(out, aliasCount);
for(i=0; i<aliasCount; ++i) {
udata_write16(out, (uint16_t)(stringOffset+(aliases[i].alias-stringStore)));
udata_write16(out, (uint16_t)(stringOffset+(aliases[i].converter-stringStore)));
}
/* write the table of converters */
udata_write16(out, converterCount);
for(i=0; i<converterCount; ++i) {
udata_write16(out, (uint16_t)(stringOffset+(converters[i].converter-stringStore)));
udata_write16(out, converters[i].aliasCount);
}
/* write the strings */
udata_writeString(out, stringStore, stringTop);
/* finish */
udata_finish(out, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "gencnval: error finishing output file - %s\n", errorName(errorCode));
exit(errorCode);
}
return 0;
}
static void
parseLine(const char *line) {
Converter *cnv;
uint16_t pos=0, start, limit, length;
char *converter, *alias, *s;
/* skip leading white space */
while(line[pos]!=0 && isspace((unsigned char)line[pos])) {
++pos;
}
/* is there only a comment on this line? */
if(line[pos]==0 || line[pos]=='#') {
return;
}
/* get the converter name */
start=pos;
while(line[pos]!=0 && line[pos]!='#' && !isspace((unsigned char)line[pos])) {
++pos;
}
limit=pos;
/* store the converter name */
length=limit-start;
converter=allocString(length+1);
icu_strncpy(converter, line+start, length);
converter[length]=0;
/* add the converter to the converter table */
cnv=addConverter(converter);
/* add a lowercase version of the converter name as the first alias */
alias=s=allocString(length+1);
while(length>0) {
*s++=icu_tolower(line[start++]);
--length;
}
*s=0;
/* add the alias/converter pair to the alias table */
addAlias(alias, converter);
/* get all the real aliases */
for(;;) {
/* skip white space */
while(line[pos]!=0 && isspace((unsigned char)line[pos])) {
++pos;
}
/* is there no more alias name on this line? */
if(line[pos]==0 || line[pos]=='#') {
break;
}
/* get an alias name */
start=pos;
while(line[pos]!=0 && line[pos]!='#' && !isspace((unsigned char)line[pos])) {
++pos;
}
limit=pos;
/* store the alias name in lowercase */
length=limit-start;
alias=s=allocString(length+1);
while(length>0) {
*s++=icu_tolower(line[start++]);
--length;
}
*s=0;
/* add the alias/converter pair to the alias table */
addAlias(alias, converter);
/* count it for the converter */
++cnv->aliasCount;
}
}
static void
addAlias(const char *alias, const char *converter) {
if(aliasCount==MAX_ALIAS_COUNT) {
fprintf(stderr, "gencnval: too many aliases\n");
exit(U_BUFFER_OVERFLOW_ERROR);
}
aliases[aliasCount].alias=alias;
aliases[aliasCount].converter=converter;
++aliasCount;
}
static Converter *
addConverter(const char *converter) {
if(converterCount==MAX_ALIAS_COUNT) {
fprintf(stderr, "gencnval: too many converters\n");
exit(U_BUFFER_OVERFLOW_ERROR);
}
converters[converterCount].converter=converter;
converters[converterCount].aliasCount=0;
++converterCount;
return converters+converterCount-1;
}
static char *
allocString(uint32_t length) {
uint32_t top=stringTop+length;
char *p;
if(top>STRING_STORE_SIZE) {
fprintf(stderr, "gencnval: out of memory\n");
exit(U_MEMORY_ALLOCATION_ERROR);
}
p=stringStore+stringTop;
stringTop=top;
return p;
}
static int
compareAliases(const void *alias1, const void *alias2) {
return icu_strcmp(((Alias *)alias1)->alias, ((Alias *)alias2)->alias);
}
static int
compareConverters(const void *converter1, const void *converter2) {
return icu_strcmp(((Converter *)converter1)->converter, ((Converter *)converter2)->converter);
}

View file

@ -0,0 +1,102 @@
# Microsoft Developer Studio Project File - Name="gencnval" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=gencnval - 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 "gencnval.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 "gencnval.mak" CFG="gencnval - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "gencnval - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "gencnval - 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)" == "gencnval - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# 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 /W3 /GX /O2 /I "..\..\common" /I "..\toolutil" /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 toolutil.lib icuuc.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 /libpath:"..\toolutil\Release" /libpath:"..\..\..\lib\Release"
!ELSEIF "$(CFG)" == "gencnval - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "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 /MDd /W3 /Gm /GX /ZI /Od /I "..\..\common" /I "..\toolutil" /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 toolutil.lib icuuc.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 /libpath:"..\toolutil\Debug" /libpath:"..\..\..\lib\Debug"
!ENDIF
# Begin Target
# Name "gencnval - Win32 Release"
# Name "gencnval - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\gencnval.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

View file

@ -30,16 +30,22 @@ echo create unames.dat and unames_dat.c from UnicodeData.txt
gennames\%toolversion%\gennames -v- -c- "%ICU_DATA%UnicodeData-3.0.0.txt"
genccode\%toolversion%\genccode "%ICU_DATA%unames.dat"
echo create cnvalias.dat and cnvalias_dat.c from convrtrs.txt
gencnval\%toolversion%\gencnval -c-
genccode\%toolversion%\genccode "%ICU_DATA%cnvalias.dat"
echo create the data DLL
cl "/I..\..\include" /GD /c "%ICU_DATA%unames_dat.c"
cl "/I..\..\include" /GD /c "%ICU_DATA%unames_dat.c" "%ICU_DATA%cnvalias_dat.c"
echo "/out:%ICU_DATA%icudata.dll">mkdll.tmp
echo unames_dat.obj>>mkdll.tmp
echo cnvalias_dat.obj>>mkdll.tmp
type mkdll.lk>>mkdll.tmp
link @mkdll.tmp
echo create the common, memory-mappable file
del "%ICU_DATA%icudata.dat"
echo %ICU_DATA%unames.dat>mkmap.tmp
echo %ICU_DATA%cnvalias.dat>mkmap.tmp
gencmn\%toolversion%\gencmn 1000000 mkmap.tmp
goto :end