/************************************************************************* * * © 2016 and later: Unicode, Inc. and others. * License & terms of use: http://www.unicode.org/copyright.html#License * ************************************************************************** ************************************************************************** * * Copyright (C) 2001-2006, International Business Machines * Corporation and others. All Rights Reserved. * ************************************************************************** * * ufortune - An ICU resources sample program * * Demonstrates * Defining resources for use by an application * Compiling and packaging them into a dll * Referencing the resource-containing dll from application code * Loading resource data using ICU's API * * Created Nov. 7, 2001 by Andy Heninger * * ufortune is a variant of the Unix "fortune" command, with * ICU resources that contain the fortune-cookie sayings. * Using resources allows fortunes in different languages to * be selected based on locale. */ #include #include #include #include #include "unicode/udata.h" /* ICU API for data handling. */ #include "unicode/ures.h" /* ICU API for resource loading */ #include "unicode/ustdio.h" /* ICU API for reading & writing Unicode data */ /* to files, possibly including character */ /* set conversions. */ #include "unicode/ustring.h" #ifndef UFORTUNE_NOSETAPPDATA /* * Resource Data Reference. The data is packaged as a dll (or .so or * whatever, depending on the platform) that exports a data * symbol. The application (that's us) references that symbol, * here, and will pass the data address to ICU, which will then * be able to fetch resources from the data. */ extern const void U_IMPORT *fortune_resources_dat; #endif void u_write(const UChar *what, int len); /* * main() This one function is all of the application code. */ int main(int argc, char **argv) { UBool displayUsage = FALSE; /* Set true if command line err or help */ /* option was requested. */ UBool verbose = FALSE; /* Set true if -v command line option. */ char *optionError = NULL; /* If command line contains an unrecognized */ /* option, this will point to it. */ char *locale=NULL; /* Locale name. Null for system default, */ /* otherwise set from command line. */ const char * programName = argv[0]; /* Program invocation name. */ UFILE *u_stdout; /* Unicode stdout file. */ UErrorCode err = U_ZERO_ERROR; /* Error return, used for most ICU */ /* functions. */ UResourceBundle *myResources; /* ICU Resource "handles" */ UResourceBundle *fortunes_r; int32_t numFortunes; /* Number of fortune strings available. */ int i; const UChar *resString; /* Points to strings fetched from Resources. */ int32_t len; /* Process command line options. * -l locale specify a locale * -v verbose mode. Display extra messages. * -? or --help display a usage line */ for (i=1; i