/* ******************************************************************************* * * Copyright (C) 2000-2003, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: ucmkbase.c * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 * * created on: 2003nov01 * created by: Markus W. Scherer * * This tool generates a base conversion file that is suitable for multiple * delta files. See usage text. * * ucmkbase requires a build using the ICU common (icuuc) and toolutil libraries. * On Windows (on one line): * * cl -nologo -MD * -I..\..\..\icu\source\common * -I..\..\..\icu\source\tools\toolutil * ucmkbase.c -link /LIBPATH:..\..\..\icu\lib icuuc.lib icutu.lib */ /* ### TODO special mode to ignore intersectBase when the base mapping is SBCS? -> for 1390 vs. 16684 */ #include "unicode/utypes.h" #include "cstring.h" #include "cmemory.h" #include "filestrm.h" #include "ucnv_ext.h" #include "ucm.h" #include static void stripEndline(char *s) { char *end=uprv_strchr(s, 0); while(sbaseName[0]!=0) { fprintf(stderr, "error: \"%s\" is a delta file\n", argv[1]); return U_INVALID_TABLE_FORMAT; } baseStates=&baseFile->states; ucm_processStates(baseStates); /* read the base file base table */ errorCode=U_ZERO_ERROR; ucm_readTable(baseFile, fileStream, TRUE, baseStates, &errorCode); if(U_FAILURE(errorCode)) { fprintf(stderr, "error %s parsing the base file base table\n", u_errorName(errorCode)); return errorCode; } /* read the base file extension table, if any */ while(T_FileStream_readLine(fileStream, line, sizeof(line))!=NULL) { stripEndline(line); if(line[0]!=0 && line[0]!='#') { if(0==uprv_strcmp(line, "CHARMAP")) { ucm_readTable(baseFile, fileStream, FALSE, baseStates, &errorCode); break; } else { fprintf(stderr, "unexpected text after the base mapping table\n"); return U_INVALID_TABLE_FORMAT; } } } if(U_FAILURE(errorCode)) { fprintf(stderr, "error %s parsing the base file extension table\n", u_errorName(errorCode)); return errorCode; } T_FileStream_close(fileStream); if(!ucm_checkBaseExt(baseStates, baseFile->base, baseFile->ext, baseFile->ext, FALSE)) { fprintf(stderr, "error processing the base file \"%s\"\n", argv[1]); return U_INVALID_TABLE_FORMAT; } /* read and process each delta file ------------------------------------- */ for(i=2; i", 13) && NULL!=uprv_strstr(line, "DBCS")) { intersectBase=2; /* special mode for ucm_checkBaseExt() */ } else if(0==uprv_strcmp(line, "CHARMAP")) { break; } } /* read the delta file base table */ ucm_readTable(extFile, fileStream, FALSE, baseStates, &errorCode); if(U_FAILURE(errorCode)) { fprintf(stderr, "error %s parsing the delta file \"%s\" base table\n", u_errorName(errorCode), argv[i]); return errorCode; } /* read the delta file extension table, if any */ while(T_FileStream_readLine(fileStream, line, sizeof(line))!=NULL) { stripEndline(line); if(line[0]!=0 && line[0]!='#') { if(0==uprv_strcmp(line, "CHARMAP")) { ucm_readTable(extFile, fileStream, FALSE, baseStates, &errorCode); break; } else { fprintf(stderr, "unexpected text after the \"%s\" base mapping table\n", argv[i]); return U_INVALID_TABLE_FORMAT; } } } if(U_FAILURE(errorCode)) { fprintf(stderr, "error %s parsing the delta file \"%s\" extension table\n", u_errorName(errorCode), argv[i]); return errorCode; } T_FileStream_close(fileStream); if(!ucm_checkBaseExt(baseStates, baseFile->base, extFile->ext, baseFile->ext, intersectBase)) { fprintf(stderr, "error processing the delta file \"%s\"\n", argv[i]); return U_INVALID_TABLE_FORMAT; } ucm_resetTable(extFile->ext); } /* sort and write all mappings; write at least one table, even if empty */ puts("CHARMAP"); ucm_printTable(baseFile->base, stdout, TRUE); puts("END CHARMAP"); if(baseFile->ext->mappingsLength>0) { puts("\nCHARMAP"); ucm_printTable(baseFile->ext, stdout, TRUE); puts("END CHARMAP"); } ucm_close(baseFile); ucm_close(extFile); return 0; }