//-------------------------------------------------------------------- // // Tool for generating Unicode Confusable data files (.cfu files). // .cfu files contain the compiled of the confusable data // derived from the Unicode Consortium data described in // Unicode UAX 39. // // Usage: gencfu [options] -r confusables-file.txt -o output-file.cfu // // options: -v verbose // -? or -h help // // The input rule file are plain text files containing confusable character // definitions in the input format defined by Unicode UAX39 for the files // confusables.txt. This source (.txt) format // is also accepted by ICU spoof detectors. The // files must be encoded in utf-8 format, with or without a BOM. // // The script used to compile confusablesWholeScript.txt into the CFU file // until the Unicode consortium deprecated it. // //--------------------------------------------------------------------
void usageAndDie(int retCode) {
printf("Usage: %s [-v] [-options] -r confusablesRules.txt -o output-file\n", progName);
printf("\tRead in Unicode confusable character definitions and write out the binary data\n" "options:\n" "\t-h or -? or --help this usage text\n" "\t-V or --version show a version message\n" "\t-c or --copyright include a copyright notice\n" "\t-v or --verbose turn on verbose output\n" "\t-q or --quiet do not display warnings and progress\n" "\t-i or --icudatadir directory for locating any needed intermediate data files,\n" "\t followed by path, defaults to %s\n" "\t-d or --destdir destination directory, followed by the path\n",
u_getDataDirectory()); exit (retCode);
}
{ 0x43, 0x66, 0x75, 0x20 }, // dataFormat="Cfu "
{ 0xff, 0, 0, 0 }, // formatVersion. Filled in later with values // from the builder. The values declared // here should never appear in any real data.
{ 5, 1, 0, 0 } // dataVersion (Unicode version)
}};
#endif
// Forward declaration for function for reading source files. staticconstchar *readFile(constchar *fileName, int32_t *len);
//---------------------------------------------------------------------------- // // main for gencfu // //---------------------------------------------------------------------------- int main(int argc, char **argv) {
UErrorCode status = U_ZERO_ERROR; constchar *confFileName; constchar *outFileName; constchar *outDir = nullptr; constchar *copyright = nullptr;
// // Pick up and check the command line arguments, // using the standard ICU tool utils option handling. //
U_MAIN_INIT_ARGS(argc, argv);
progName = argv[0];
argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); if(argc<0) { // Unrecognized option
fprintf(stderr, "error in command line argument \"%s\"\n", argv[-argc]);
usageAndDie(U_ILLEGAL_ARGUMENT_ERROR);
}
if(options[0].doesOccur || options[1].doesOccur) { // -? or -h for help.
usageAndDie(0);
}
if (!(options[3].doesOccur && options[5].doesOccur)) {
fprintf(stderr, "confusables file and output file must all be specified.\n");
usageAndDie(U_ILLEGAL_ARGUMENT_ERROR);
}
confFileName = options[3].value;
outFileName = options[5].value;
if (options[6].doesOccur) {
u_setDataDirectory(options[6].value);
}
status = U_ZERO_ERROR;
/* Combine the directory with the file name */ if(options[7].doesOccur) {
outDir = options[7].value;
} if (options[8].doesOccur) {
copyright = U_COPYRIGHT_STRING;
}
#if UCONFIG_NO_REGULAR_EXPRESSIONS || UCONFIG_NO_NORMALIZATION || UCONFIG_NO_FILE_IO // spoof detection data file parsing is dependent on regular expressions. // TODO: have the tool return an error status. Requires fixing the ICU data build // so that it doesn't abort entirely on that error.
UNewDataMemory *pData; char msg[1024];
/* write message with just the name */
snprintf(msg, sizeof(msg), "gencfu writes dummy %s because of UCONFIG_NO_REGULAR_EXPRESSIONS and/or UCONFIG_NO_NORMALIZATION and/or UCONFIG_NO_FILE_IO, see uconfig.h", outFileName);
fprintf(stderr, "%s\n", msg);
#else /* Initialize ICU */
u_init(&status); if (U_FAILURE(status)) {
fprintf(stderr, "%s: can not initialize ICU. status = %s\n",
argv[0], u_errorName(status)); exit(1);
}
status = U_ZERO_ERROR;
// // Create the Spoof Detector from the source confusables files. // This will compile the data. //
UParseError parseError;
parseError.line = 0;
parseError.offset = 0;
int32_t errType;
USpoofChecker *sc = uspoof_openFromSource(confusables, confusablesLen,
nullptr, 0,
&errType, &parseError, &status); if (U_FAILURE(status)) {
fprintf(stderr, "gencfu: uspoof_openFromSource error \"%s\" at file %s, line %d, column %d\n",
u_errorName(status), confFileName, static_cast<int>(parseError.line), static_cast<int>(parseError.offset)); exit(status);
}
// // Get the compiled rule data from the USpoofChecker. //
uint32_t outDataSize;
uint8_t *outData;
outDataSize = uspoof_serialize(sc, nullptr, 0, &status); if (status != U_BUFFER_OVERFLOW_ERROR) {
fprintf(stderr, "gencfu: uspoof_serialize() returned %s\n", u_errorName(status)); exit(status);
}
status = U_ZERO_ERROR;
outData = new uint8_t[outDataSize];
uspoof_serialize(sc, outData, outDataSize, &status);
// Copy the data format version numbers from the spoof data header into the UDataMemory header.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.