// 判断目录是否存在
BOOL CCommonInterface::FolderExists(std::wstring s)
{
	DWORD attr;
	attr = GetFileAttributes(s.data());
	return (attr != (DWORD)(-1)) && (attr & FILE_ATTRIBUTE_DIRECTORY);
}
示例#2
0
int main()
{
    {
        std::locale l("en_US");
        {
            typedef std::ctype<wchar_t> F;
            const F& f = std::use_facet<F>(l);
            const std::wstring in(L"\x00DA A\x07.a1");
            std::vector<F::mask> m(in.size());
            assert(f.scan_is(F::space, in.data(), in.data() + in.size()) - in.data() == 1);
            assert(f.scan_is(F::print, in.data(), in.data() + in.size()) - in.data() == 0);
            assert(f.scan_is(F::cntrl, in.data(), in.data() + in.size()) - in.data() == 3);
            assert(f.scan_is(F::upper, in.data(), in.data() + in.size()) - in.data() == 0);
            assert(f.scan_is(F::lower, in.data(), in.data() + in.size()) - in.data() == 5);
            assert(f.scan_is(F::alpha, in.data(), in.data() + in.size()) - in.data() == 0);
            assert(f.scan_is(F::digit, in.data(), in.data() + in.size()) - in.data() == 6);
            assert(f.scan_is(F::punct, in.data(), in.data() + in.size()) - in.data() == 4);
            assert(f.scan_is(F::xdigit, in.data(), in.data() + in.size()) - in.data() == 2);
            assert(f.scan_is(F::blank, in.data(), in.data() + in.size()) - in.data() == 1);
            assert(f.scan_is(F::alnum, in.data(), in.data() + in.size()) - in.data() == 0);
            assert(f.scan_is(F::graph, in.data(), in.data() + in.size()) - in.data() == 0);
        }
    }
    {
        std::locale l("C");
        {
            typedef std::ctype<wchar_t> F;
            const F& f = std::use_facet<F>(l);
            const std::wstring in(L"\x00DA A\x07.a1");
            std::vector<F::mask> m(in.size());
            assert(f.scan_is(F::space, in.data(), in.data() + in.size()) - in.data() == 1);
            assert(f.scan_is(F::print, in.data(), in.data() + in.size()) - in.data() == 1);
            assert(f.scan_is(F::cntrl, in.data(), in.data() + in.size()) - in.data() == 3);
            assert(f.scan_is(F::upper, in.data(), in.data() + in.size()) - in.data() == 2);
            assert(f.scan_is(F::lower, in.data(), in.data() + in.size()) - in.data() == 5);
            assert(f.scan_is(F::alpha, in.data(), in.data() + in.size()) - in.data() == 2);
            assert(f.scan_is(F::digit, in.data(), in.data() + in.size()) - in.data() == 6);
            assert(f.scan_is(F::punct, in.data(), in.data() + in.size()) - in.data() == 4);
            assert(f.scan_is(F::xdigit, in.data(), in.data() + in.size()) - in.data() == 2);
            assert(f.scan_is(F::blank, in.data(), in.data() + in.size()) - in.data() == 1);
            assert(f.scan_is(F::alnum, in.data(), in.data() + in.size()) - in.data() == 2);
            assert(f.scan_is(F::graph, in.data(), in.data() + in.size()) - in.data() == 2);
        }
    }
}
示例#3
0
/*
%a Abbreviated weekday name * Thu
%A Full weekday name *  Thursday
%b Abbreviated month name * Aug
%B Full month name * August
%c Date and time representation * Thu Aug 23 14:55:02 2001
%C Year divided by 100 and truncated to integer (00-99) 20
%d Day of the month, zero-padded (01-31) 23
%D Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01
%e Day of the month, space-padded ( 1-31) 23
%F Short YYYY-MM-DD date, equivalent to %Y-%m-%d 2001-08-23
%g Week-based year, last two digits (00-99) 01
%G Week-based year 2001
%h Abbreviated month name * (same as %b) Aug
%H Hour in 24h format (00-23) 14
%I Hour in 12h format (01-12) 02
%j Day of the year (001-366) 235
%m Month as a decimal number (01-12) 08
%M Minute (00-59) 55
%n New-line character ('\n')
%p AM or PM designation PM
%r 12-hour clock time * 02:55:02 pm
%R 24-hour HH:MM time, equivalent to %H:%M 14:55
%S Second (00-61) 02
%t Horizontal-tab character ('\t')
%T ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S 14:55:02
%u ISO 8601 weekday as number with Monday as 1 (1-7) 4
%U Week number with the first Sunday as the first day of week one (00-53) 33
%V ISO 8601 week number (00-53) 34
%w Weekday as a decimal number with Sunday as 0 (0-6) 4
%W Week number with the first Monday as the first day of week one (00-53) 34
%x Date representation * 08/23/01
%X Time representation * 14:55:02
%y Year, last two digits (00-99) 01
%Y Year 2001
%z ISO 8601 offset from UTC in timezone (1 minute=1, 1 hour=100)
 If timezone cannot be termined, no characters +100
%Z Timezone name or abbreviation *
 If timezone cannot be termined, no characters CDT
%% A % sign %
*/
void TestTimePut()
{

	auto now = std::chrono::system_clock::now();
	auto t = std::chrono::system_clock::to_time_t(now);
	std::wcout<<L"Local Time:"<<std::endl;
	auto ptm = std::localtime(&t);
#if defined _WIN32
	/* Windows dosen't support the time zone */
	const std::wstring FMT(L"%Y-%m-%d %H:%M:%S %A\n");
#else
	const std::wstring FMT(L"%Y-%m-%d %H:%M:%S %A %Z\n");
#endif
	//const std::time_put<char>& ctp = std::use_facet<std::time_put<char> >(std::locale("C"));
	//const std::time_put<char>& dtp = std::use_facet<std::time_put<char> >(std::locale());
	//const std::time_put<char>& ntp = std::use_facet<std::time_put<char> >(std::locale(""));
	//ctp.put(std::wcout, std::wcout, '0', ptm, FMT.data(), FMT.data() + FMT.length());
	//dtp.put(std::wcout, std::wcout, '0', ptm, FMT.data(), FMT.data() + FMT.length());
	//ntp.put(std::wcout, std::wcout, '0', ptm, FMT.data(), FMT.data() + FMT.length());


	std::locale curlocale = std::wcout.getloc();

	try
	{
		std::wcout<<L"C Locale:";
		std::use_facet<std::time_put<wchar_t> >(std::locale("C")).put(std::wcout, std::wcout, L'0', ptm, FMT.data(), FMT.data() + FMT.length());

		std::wcout<<L"Default Locale:";
		std::use_facet<std::time_put<wchar_t> >(std::locale()).put(std::wcout, std::wcout, L'0', ptm, FMT.data(), FMT.data() + FMT.length());

		std::wcout<<L"Native Locale:";
		std::use_facet<std::time_put<wchar_t> >(std::locale("")).put(std::wcout, std::wcout, L'0', ptm, FMT.data(), FMT.data() + FMT.length());

		if (std::wcout.bad())
		{
			std::wcout.clear();
			std::wcout.flush();
			std::wcout<<"Reset std::wcout"<<std::endl;
		}
	}
	catch (...)
	{
		std::wcerr<<std::strerror(errno)<<std::endl;
	}

	std::wcout.imbue(curlocale);
}
示例#4
0
int parseLibFile(const std::wstring& _wstXML, MacroInfoList& info, std::wstring& libname)
{
    info.clear();

    char* pstFile = wide_string_to_UTF8(_wstXML.data());

    if (FileExist(pstFile) == FALSE)
    {
        FREE(pstFile);
        return 1;
    }

    char *encoding = GetXmlFileEncoding(pstFile);

    /* Don't care about line return / empty line */
    xmlKeepBlanksDefault(0);
    /* check if the XML file has been encoded with utf8 (unicode) or not */
    if (stricmp("utf-8", encoding))
    {
        FREE(pstFile);
        free(encoding);
        return NULL;
    }

    xmlDocPtr doc;
    xmlXPathContextPtr xpathCtxt = NULL;
    xmlXPathObjectPtr xpathObj = NULL;
    wchar_t* pstName = NULL;
    wchar_t* pstLibName = NULL;
    wchar_t* pstFileName = NULL;
    wchar_t* pstMd5 = NULL;

    free(encoding);

    doc = xmlParseFile(pstFile);

    if (doc == NULL)
    {
        FREE(pstFile);
        return 1;
    }

    FREE(pstFile);

    xpathCtxt = xmlXPathNewContext(doc);
    xpathObj = xmlXPathEval((const xmlChar*)"//scilablib", xpathCtxt);
    if (xpathObj && xpathObj->nodesetval->nodeMax)
    {
        xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[0]->properties;
        if (xmlStrEqual(attrib->name, (const xmlChar*)"name"))
        {
            /* we found the tag name */
            const char *str = (const char*)attrib->children->content;
            pstLibName = to_wide_string(str);
            libname = pstLibName;
            FREE(pstLibName);
            xmlXPathFreeObject(xpathObj);
        }
        else
        {
            if (xpathCtxt)
            {
                xmlXPathFreeContext(xpathCtxt);
            }
            xmlXPathFreeObject(xpathObj);
            return 1;
        }
    }

    xpathObj = xmlXPathEval((const xmlChar*)"//scilablib/macro", xpathCtxt);
    if (xpathObj && xpathObj->nodesetval->nodeMax)
    {
        /* the Xpath has been understood and there are node */
        for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
        {
            xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties;
            /* Get the properties of <module>  */
            while (attrib != NULL)
            {
                /* loop until when have read all the attributes */
                if (xmlStrEqual(attrib->name, (const xmlChar*)"name"))
                {
                    /* we found the tag name */
                    const char *str = (const char*)attrib->children->content;
                    pstName = to_wide_string(str);
                }
                else if (xmlStrEqual(attrib->name, (const xmlChar*)"file"))
                {
                    /* we found the tag activate */
                    const char *str = (const char*)attrib->children->content;
                    pstFileName = to_wide_string(str);
                }
                else if (xmlStrEqual(attrib->name, (const xmlChar*)"md5"))
                {
                    /* we found the tag activate */
                    const char *str = (const char*)attrib->children->content;
                    pstMd5 = to_wide_string(str);
                }
                attrib = attrib->next;
            }

            if (pstName && pstFileName && pstMd5)
            {
                info[pstFileName] = MacroInfo(pstName, pstFileName, pstMd5);
            }

            if (pstName)
            {
                FREE(pstName);
                pstName = NULL;
            }

            if (pstFileName)
            {
                FREE(pstFileName);
                pstFileName = NULL;
            }

            if (pstMd5)
            {
                FREE(pstMd5);
                pstMd5 = NULL;
            }
        }
    }

    if (xpathObj)
    {
        xmlXPathFreeObject(xpathObj);
    }
    if (xpathCtxt)
    {
        xmlXPathFreeContext(xpathCtxt);
    }

    xmlFreeDoc(doc);
    return 0;
}
示例#5
0
void test(const std::wstring& s1, const std::wstring& s2) {
    std::locale loc(std::locale(), new xxd::collate_dict_es());
    const std::collate<wchar_t>& col = std::use_facet<std::collate<wchar_t> >(loc);
    std::wcout << col.compare(s1.data(), s1.data()+s1.size(), s2.data(), s2.data()+s2.size()) << std::endl;
}
示例#6
0
//
// Converts wchar_t sequence into UTF-8 string
//
std::string convertWCHARtoUTF8(const std::wstring & str)
{
	return convertWCHARtoUTF8(str.data(), str.length());
}
示例#7
0
INT64 StringUtility::WStringToInt64( std::wstring str )
{
	INT64 i;
	i = _wtoi64(str.data());
	return i;
}
示例#8
0
/*--------------------------------------------------------------------------*/
Diary::Diary(const std::wstring& _wfilename, int _mode, int ID, bool autorename)
{
    std::ios::openmode wofstream_mode;

    std::wstring fullfilename = getUniqueFilename(_wfilename);
    if (autorename)
    {
        fullfilename = getUniqueFilename(_wfilename);

        wchar_t* ws = getFullFilenameW(fullfilename.data());
        fullfilename = ws;
        FREE(ws);
    }
    else
    {
        wchar_t* ws = getFullFilenameW(_wfilename.data());
        fullfilename = ws;
        FREE(ws);
    }

    suspendwrite = false;

    PrefixTimeFormat = PREFIX_TIME_FORMAT_UNIX_EPOCH;
    IoModeFilter = DIARY_FILTER_INPUT_AND_OUTPUT;   // default command & input
    PrefixIoModeFilter = PREFIX_FILTER_NONE;    // no prefix

    if (_mode == 0)
    {
        wofstream_mode = std::ios::trunc | std::ios::binary;
    }
    else
    {
        wofstream_mode = std::ios::app | std::ios::binary;
    }

#ifdef _MSC_VER
    std::wofstream fileDiary(fullfilename, wofstream_mode);
#else
    wchar_t *wcfile = (wchar_t *) fullfilename.c_str();
    char *filename = wide_string_to_UTF8(wcfile);

    std::ofstream fileDiary(filename, wofstream_mode);

    if (filename)
    {
        FREE(filename);
        filename = NULL;
    }
#endif

    if (fileDiary.bad())
    {
        wfilename = std::wstring(L"");
        fileAttribMode = -1;
        setID(-1);
    }
    else
    {
        wfilename = fullfilename;
        fileAttribMode = wofstream_mode;
        setID(ID);
    }
    fileDiary.close();
}
示例#9
0
long StringUtility::StringToLong( std::wstring str )
{
	long n = 0;
	n = _wtol(str.data());
	return n;
}
示例#10
0
int StringUtility::WSTringToInt( std::wstring str )
{
	int n = 0;
	n = _wtoi(str.data());
	return n;
}
static int
run_test (int, char**)
{
    // find all installed locales for which setlocale(LC_ALL) succeeds
    const char* const locale_list =
        rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL);

    // array of locale names to use for testing
    const char* locales [sizeof punct_data / sizeof *punct_data];

    const std::size_t maxinx = sizeof locales / sizeof *locales;

    // iterate over locales, initializing a global punct_data array
    for (const char *name = locale_list; *name; name += std::strlen (name) +1) {

        std::locale loc;

        MoneypunctData* const pdata = punct_data + nlocales;

        pdata->locale_name_ = name;
        locales [nlocales]  = name;

        try {
            loc = std::locale (name);

            typedef std::moneypunct<char, false> Punct;

            const Punct &mp = std::use_facet<Punct>(loc);

            const char           dp  = mp.decimal_point ();
            const char           ts  = mp.thousands_sep ();
            const std::string    grp = mp.grouping ();
            const std::string    cur = mp.curr_symbol ();
            const std::string    pos = mp.positive_sign ();
            const std::string    neg = mp.negative_sign ();
            const int            fd  = mp.frac_digits ();
            const Punct::pattern pfm = mp.pos_format ();
            const Punct::pattern nfm = mp.neg_format ();

            pdata->decimal_point_ = dp;
            pdata->thousands_sep_ = ts;
            pdata->frac_digits_   = fd;

            std::strcpy (pdata->grouping_, grp.c_str ());
            std::strcpy (pdata->curr_symbol_, cur.c_str ());
            std::strcpy (pdata->positive_sign_, pos.c_str ());
            std::strcpy (pdata->negative_sign_, neg.c_str ());
            std::memcpy (pdata->pos_format_, &pfm, sizeof pfm);
            std::memcpy (pdata->neg_format_, &nfm, sizeof nfm);
        }
        catch (...) {
            rw_warn (0, 0, __LINE__,
                     "std::locale(%#s) threw an exception, skipping", name);
            continue;
        }

        try {
            typedef std::moneypunct<char, true> Punct;

            const Punct &mp = std::use_facet<Punct>(loc);

            const std::string    cur = mp.curr_symbol ();
            const int            fd  = mp.frac_digits ();
            const Punct::pattern pfm = mp.pos_format ();
            const Punct::pattern nfm = mp.neg_format ();

            pdata->int_frac_digits_ = fd;

            std::strcpy (pdata->int_curr_symbol_, cur.c_str ());
            std::memcpy (pdata->int_pos_format_, &pfm, sizeof pfm);
            std::memcpy (pdata->int_neg_format_, &nfm, sizeof nfm);
        }
        catch (...) {
            rw_warn (0, 0, __LINE__,
                     "std::locale(%#s) threw an exception, skipping", name);
            continue;
        }

#ifndef _RWSTD_NO_WCHAR_T

        try {
            typedef std::moneypunct<wchar_t, false> Punct;

            const Punct &mp = std::use_facet<Punct>(loc);

            const wchar_t      dp  = mp.decimal_point ();
            const wchar_t      ts  = mp.thousands_sep ();
            const std::wstring cur = mp.curr_symbol ();
            const std::wstring pos = mp.positive_sign ();
            const std::wstring neg = mp.negative_sign ();

            pdata->wdecimal_point_ = dp;
            pdata->wthousands_sep_ = ts;

            typedef std::wstring::traits_type Traits;

            Traits::copy (pdata->wcurr_symbol_,   cur.data (), cur.size ());
            Traits::copy (pdata->wpositive_sign_, pos.data (), pos.size ());
            Traits::copy (pdata->wnegative_sign_, neg.data (), neg.size ());
        }
        catch (...) {
            rw_warn (0, 0, __LINE__,
                     "std::locale(%#s) threw an exception, skipping", name);
            continue;
        }

        try {
            typedef std::moneypunct<wchar_t, true> Punct;

            const Punct &mp = std::use_facet<Punct>(loc);

            const std::wstring cur = mp.curr_symbol ();
            const std::wstring pos = mp.positive_sign ();
            const std::wstring neg = mp.negative_sign ();

            typedef std::wstring::traits_type Traits;

            Traits::copy (pdata->wint_curr_symbol_, cur.data (), cur.size ());
        }
        catch (...) {
            rw_warn (0, 0, __LINE__,
                     "std::locale(%#s) threw an exception, skipping", name);
            continue;
        }

#endif   // _RWSTD_NO_WCHAR_T

        ++nlocales;

        if (nlocales == maxinx)
            break;
    }

    // unless the number of iterations was explicitly specified
    // on the command line, decrease the number to equal the number
    // of excericsed locales when only one thread is being tested
    if (1 == opt_nthreads && opt_nloops < 0)
        opt_nloops = int (nlocales);

    // when the number of iterations wasn't explicitly specified
    // on the command line set it to the default value
    if (opt_nloops < 0)
        opt_nloops = DFLT_LOOPS;

    rw_fatal (0 < nlocales, 0, __LINE__,
              "must have at least one valid locale to test");

    rw_info (0, 0, 0,
             "testing std::moneypunct<charT> with %d thread%{?}s%{;}, "
             "%d iteration%{?}s%{;} each, in %zu locales { %{ .*A@} }",
             opt_nthreads, 1 != opt_nthreads,
             opt_nloops, 1 != opt_nloops,
             nlocales, int (nlocales), "%#s", locales);

    rw_info (0, 0, 0, "exercising std::moneypunct<char>");

    test_char  = true;
    test_wchar = false;

    // create and start a pool of threads and wait for them to finish
    int result =
        rw_thread_pool (0, std::size_t (opt_nthreads), 0,
                        thread_func, 0, std::size_t (opt_timeout));

    rw_error (result == 0, 0, __LINE__,
              "rw_thread_pool(0, %d, 0, %{#f}, 0) failed",
              opt_nthreads, thread_func);

#ifndef _RWSTD_NO_WCHAR_T

    rw_info (0, 0, 0, "exercising std::moneypunct<wchar_t>");

    test_char  = false;
    test_wchar = true;

    // start a pool of threads to exercise the thread safety
    // of the wchar_t specialization
    result =
        rw_thread_pool (0, std::size_t (opt_nthreads), 0,
                        thread_func, 0, std::size_t (opt_timeout));

    rw_error (result == 0, 0, __LINE__,
              "rw_thread_pool(0, %d, 0, %{#f}, 0) failed",
              opt_nthreads, thread_func);

    // exercise both the char and the wchar_t specializations
    // at the same time

    rw_info (0, 0, 0,
             "exercising both std::moneypunct<char> "
             "and std::moneypunct<wchar_t>");

    test_char  = true;
    test_wchar = true;

    // start a pool of threads to exercise wstring thread safety
    result =
        rw_thread_pool (0, std::size_t (opt_nthreads), 0,
                        thread_func, 0, std::size_t (opt_timeout));

    rw_error (result == 0, 0, __LINE__,
              "rw_thread_pool(0, %d, 0, %{#f}, 0) failed",
              opt_nthreads, thread_func);

#endif   // _RWSTD_NO_WCHAR_T

    return result;
}
示例#12
0
 static void format(reckless::output_buffer* pbuffer, std::wstring const& s)
 {
     pbuffer->write(s.data(), sizeof(wchar_t)*s.size());
 }
示例#13
0
//
// Translates wchar_t sequence into multibyte sequence in local charset
//
std::string convertWCHARtoLocal8Bit(const std::wstring & source)
{
	return convertWCHARtoLocal8Bit(source.data(), source.length());
}
void sqlite3_command::bind(int index, const std::wstring &data) {
	if(sqlite3_bind_text16(this->stmt, index, data.data(), (int)data.length()*2, SQLITE_STATIC)!=SQLITE_OK)
		throw database_error(&m_con);
}
示例#15
0
Std_String HashMD5Impl::GetStringHash(std::wstring strValue)
{
	int nLen = strValue.size() * sizeof(wchar_t);
	const unsigned char* pBuf = (const unsigned char*)strValue.data();
	return ComputeHash(pBuf, nLen);
}
示例#16
0
System::String^ FP::Cloud::OnlineRateTable::PCalcLib::Convert::ToString(std::wstring source)
{
    System::IntPtr _ep = (IntPtr)(wchar_t*)source.data();
    String^ result = Marshal::PtrToStringUni(_ep);;
    return result;
}
示例#17
0
void TileSourceGDAL::put_url( const std::wstring& strUrl )
{
	getOrCreateInnerObject()->url() = CStringA( strUrl.data() ).GetString();
}
示例#18
0
/*----------------------------------------------------------------------------------------------
	Convert a feature string as used by FieldWorks into a set of feature-IDs-plus-values.
	Private.

	TODO: find a way to merge this method with the FwGrEngine version.
----------------------------------------------------------------------------------------------*/
void FwGrTxtSrc::ParseFeatureString(std::wstring stuFeat, int cMax,
	FeatureSetting * prgfset, int * pcFeat)
{
	wchar_t * pchw = const_cast<wchar_t *>(stuFeat.data());
	wchar_t * pchwLim = pchw + stuFeat.size();
	while (pchw < pchwLim)
	{
		int nID = 0;
		int nValue = 0;
		bool fNeg = false;

		//	Read the ID.
		while (*pchw != '=' && *pchw != ' ')
		{
			if (*pchw < '0' || *pchw > '9')
				goto LNext;	// syntax error: skip this setting
			nID = nID * 10 + (*pchw - '0');
			pchw++;
		}
		while (*pchw == ' ')
			pchw++;
		Assert(*pchw == '=');
		pchw++;
		while (*pchw == ' ')
			pchw++;

		//	Read the value.
		if (*pchw == '"')
		{
			//	Language ID string--form an integer out of the first four bytes, ignore
			//	the rest.
			pchw++;	// skip quote
			byte b1 = (*pchw != '"') ? *pchw++ : 0;
			byte b2 = (*pchw != '"') ? *pchw++ : 0;
			byte b3 = (*pchw != '"') ? *pchw++ : 0;
			byte b4 = (*pchw != '"') ? *pchw++ : 0;
			while (pchw < pchwLim  && *pchw != '"')	// skip superfluous chars
				pchw++;
			if (pchw >= pchwLim)
				goto LNext;
			pchw++;	// skip quote
			nValue = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
		}
		else
		{
			//	Numerical value
			if (*pchw == '-')
			{
				pchw++;
				fNeg = true;
			}
			else if (*pchw == '+')
			{
				pchw++;
				fNeg = false;
			}
			while (*pchw != ',' && *pchw != ' ' && pchw < pchwLim)
			{
				if (*pchw < '0' || *pchw > '9')
					goto LNext;	// syntax error skip this setting
				nValue = nValue * 10 + (*pchw - '0');
				pchw++;
			}
			if (fNeg)
				nValue = nValue * -1;
		}

		//	Set the feature value.
		int ifeat;
		for (ifeat = 0; ifeat < *pcFeat; ifeat++)
		{
			if (prgfset[ifeat].id == nID)
				break;	// already in list; overwrite
		}
		if (ifeat < cMax)
		{
			prgfset[ifeat].id = nID;
			prgfset[ifeat].value = nValue;
		}
		// else: don't write past the end of the available space
		*pcFeat = max(*pcFeat, ifeat + 1);

LNext:
		//	Find the next setting.
		while (pchw < pchwLim && *pchw != ',')
			pchw++;
		while (pchw < pchwLim && (*pchw < '0' || *pchw > '9'))
			pchw++;
	}
}
示例#19
0
文件: filesel.cpp 项目: MASHinfo/mame
void menu_file_selector::populate(float &customtop, float &custombottom)
{
	const file_selector_entry *selected_entry = nullptr;


	// clear out the menu entries
	m_entrylist.clear();

	// open the directory
	util::zippath_directory::ptr directory;
	osd_file::error const err = util::zippath_directory::open(m_current_directory, directory);

	// add the "[empty slot]" entry if available
	if (m_has_empty)
		append_entry(SELECTOR_ENTRY_TYPE_EMPTY, "", "");

	// add the "[create]" entry
	if (m_has_create && !directory->is_archive())
		append_entry(SELECTOR_ENTRY_TYPE_CREATE, "", "");

	// add and select the "[software list]" entry if available
	if (m_has_softlist)
		selected_entry = &append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, "", "");

	// add the drives
	int i = 0;
	for (char const *volume_name = osd_get_volume_name(i); volume_name; volume_name = osd_get_volume_name(++i))
		append_entry(SELECTOR_ENTRY_TYPE_DRIVE, volume_name, volume_name);

	// mark first filename entry
	std::size_t const first = m_entrylist.size() + 1;

	// build the menu for each item
	if (osd_file::error::NONE != err)
	{
		osd_printf_verbose("menu_file_selector::populate: error opening directory '%s' (%d)\n", m_current_directory.c_str(), int(err));
	}
	else
	{
		for (osd::directory::entry const *dirent = directory->readdir(); dirent; dirent = directory->readdir())
		{
			// append a dirent entry
			file_selector_entry const *entry = append_dirent_entry(dirent);
			if (entry)
			{
				// set the selected item to be the first non-parent directory or file
				if (!selected_entry && strcmp(dirent->name, ".."))
					selected_entry = entry;

				// do we have to select this file?
				if (!core_stricmp(m_current_file.c_str(), dirent->name))
					selected_entry = entry;
			}
		}
	}
	directory.reset();

	// sort the menu entries
	const std::collate<wchar_t> &coll = std::use_facet<std::collate<wchar_t>>(std::locale());
	std::sort(
			m_entrylist.begin() + first,
			m_entrylist.end(),
			[&coll] (file_selector_entry const &x, file_selector_entry const &y)
			{
				std::wstring const xstr = wstring_from_utf8(x.basename);
				std::wstring const ystr = wstring_from_utf8(y.basename);
				return coll.compare(xstr.data(), xstr.data()+xstr.size(), ystr.data(), ystr.data()+ystr.size()) < 0;
			});

	// append all of the menu entries
	for (file_selector_entry const &entry : m_entrylist)
		append_entry_menu_item(&entry);

	// set the selection (if we have one)
	if (selected_entry)
		set_selection((void *)selected_entry);

	// set up custom render proc
	customtop = ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER;
}
示例#20
0
/**
 * Get platform string
 */
string crashReportPlatformString() {
   TCHAR pszOS[BUFSIZE];
   OSVERSIONINFOEX osvi;
   SYSTEM_INFO si;
   PGNSI pGNSI;
   PGPI pGPI;
   BOOL bOsVersionInfoEx;
   DWORD dwType;

   ZeroMemory(&si, sizeof(SYSTEM_INFO));
   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
   bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi);

   if(bOsVersionInfoEx == NULL ) return "Unknown Windows OS";

   // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.

   pGNSI = (PGNSI) GetProcAddress(
      GetModuleHandle(TEXT("kernel32.dll")), 
      "GetNativeSystemInfo");
   if(NULL != pGNSI)
      pGNSI(&si);
   else GetSystemInfo(&si);

   if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && 
        osvi.dwMajorVersion > 4 ) {
      StringCchCopy(pszOS, BUFSIZE, TEXT("Microsoft "));

      // Test for the specific product.

      if ( osvi.dwMajorVersion == 6 ) {
         if( osvi.dwMinorVersion == 0 ) {
            if( osvi.wProductType == VER_NT_WORKSTATION )
                StringCchCat(pszOS, BUFSIZE, TEXT("Windows Vista "));
            else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 " ));
         }

         if ( osvi.dwMinorVersion == 1 ) {
            if( osvi.wProductType == VER_NT_WORKSTATION )
                StringCchCat(pszOS, BUFSIZE, TEXT("Windows 7 "));
            else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 R2 " ));
         }
         
         pGPI = (PGPI) GetProcAddress(
            GetModuleHandle(TEXT("kernel32.dll")), 
            "GetProductInfo");

         pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);

         switch( dwType ) {
            case PRODUCT_ULTIMATE:
               StringCchCat(pszOS, BUFSIZE, TEXT("Ultimate Edition" ));
               break;
            case PRODUCT_PROFESSIONAL:
               StringCchCat(pszOS, BUFSIZE, TEXT("Professional" ));
               break;
            case PRODUCT_HOME_PREMIUM:
               StringCchCat(pszOS, BUFSIZE, TEXT("Home Premium Edition" ));
               break;
            case PRODUCT_HOME_BASIC:
               StringCchCat(pszOS, BUFSIZE, TEXT("Home Basic Edition" ));
               break;
            case PRODUCT_ENTERPRISE:
               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition" ));
               break;
            case PRODUCT_BUSINESS:
               StringCchCat(pszOS, BUFSIZE, TEXT("Business Edition" ));
               break;
            case PRODUCT_STARTER:
               StringCchCat(pszOS, BUFSIZE, TEXT("Starter Edition" ));
               break;
            case PRODUCT_CLUSTER_SERVER:
               StringCchCat(pszOS, BUFSIZE, TEXT("Cluster Server Edition" ));
               break;
            case PRODUCT_DATACENTER_SERVER:
               StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition" ));
               break;
            case PRODUCT_DATACENTER_SERVER_CORE:
               StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition (core installation)" ));
               break;
            case PRODUCT_ENTERPRISE_SERVER:
               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition" ));
               break;
            case PRODUCT_ENTERPRISE_SERVER_CORE:
               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition (core installation)" ));
               break;
            case PRODUCT_ENTERPRISE_SERVER_IA64:
               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems" ));
               break;
            case PRODUCT_SMALLBUSINESS_SERVER:
               StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server" ));
               break;
            case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
               StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server Premium Edition" ));
               break;
            case PRODUCT_STANDARD_SERVER:
               StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition" ));
               break;
            case PRODUCT_STANDARD_SERVER_CORE:
               StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition (core installation)" ));
               break;
            case PRODUCT_WEB_SERVER:
               StringCchCat(pszOS, BUFSIZE, TEXT("Web Server Edition" ));
               break;
         }
      }

      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) {
         if( GetSystemMetrics(SM_SERVERR2) )
            StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Server 2003 R2, "));
         else if ( osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER )
            StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Storage Server 2003"));
         else if ( osvi.wSuiteMask & VER_SUITE_WH_SERVER )
            StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Home Server"));
         else if( osvi.wProductType == VER_NT_WORKSTATION &&
                  si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) 
         {
            StringCchCat(pszOS, BUFSIZE, TEXT( "Windows XP Professional x64 Edition"));
         }
         else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2003, "));

         // Test for the server type.
         if ( osvi.wProductType != VER_NT_WORKSTATION ) {
            if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 ) {
                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Edition for Itanium-based Systems" ));
                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise Edition for Itanium-based Systems" ));
            } else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) {
                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter x64 Edition" ));
                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise x64 Edition" ));
                else StringCchCat(pszOS, BUFSIZE, TEXT( "Standard x64 Edition" ));
            } else {
                if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
                   StringCchCat(pszOS, BUFSIZE, TEXT( "Compute Cluster Edition" ));
                else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Edition" ));
                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise Edition" ));
                else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
                   StringCchCat(pszOS, BUFSIZE, TEXT( "Web Edition" ));
                else StringCchCat(pszOS, BUFSIZE, TEXT( "Standard Edition" ));
            }
         }
      }

      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) {
         StringCchCat(pszOS, BUFSIZE, TEXT("Windows XP "));
         if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
            StringCchCat(pszOS, BUFSIZE, TEXT( "Home Edition" ));
         else StringCchCat(pszOS, BUFSIZE, TEXT( "Professional" ));
      }

      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) {
         StringCchCat(pszOS, BUFSIZE, TEXT("Windows 2000 "));

         if ( osvi.wProductType == VER_NT_WORKSTATION ) {
            StringCchCat(pszOS, BUFSIZE, TEXT( "Professional" ));
         } else  {
            if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
               StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Server" ));
            else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
               StringCchCat(pszOS, BUFSIZE, TEXT( "Advanced Server" ));
            else StringCchCat(pszOS, BUFSIZE, TEXT( "Server" ));
         }
      }

       // Include service pack (if any) and build number.

      if( _tcslen(osvi.szCSDVersion) > 0 ) {
          StringCchCat(pszOS, BUFSIZE, TEXT(" ") );
          StringCchCat(pszOS, BUFSIZE, osvi.szCSDVersion);
      }

      TCHAR buf[80];

      StringCchPrintf( buf, 80, TEXT(" (build %d)"), osvi.dwBuildNumber);
      StringCchCat(pszOS, BUFSIZE, buf);

      if ( osvi.dwMajorVersion >= 6 ) {
         if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
            StringCchCat(pszOS, BUFSIZE, TEXT( ", 64-bit" ));
         else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
            StringCchCat(pszOS, BUFSIZE, TEXT(", 32-bit"));
      }

      /* Cast from unicode to string */
      const std::wstring ws = pszOS;
      const std::locale locale("");
      typedef std::codecvt<wchar_t, char, std::mbstate_t> converter_type;
      const converter_type& converter = std::use_facet<converter_type>(locale);
      std::vector<char> to(ws.length() * converter.max_length());
      std::mbstate_t state;
      const wchar_t* from_next;
      char* to_next;
      const converter_type::result result = converter.out(state, ws.data(), ws.data() + ws.length(), from_next, &to[0], &to[0] + to.size(), to_next);
      if (result == converter_type::ok || result == converter_type::noconv) {
          const std::string s(&to[0], to_next);
          return s;
      } else {
          return "Windows (Could not convert unicode name)";
      }
   }

   else {  
       return "Unknown Windows OS";
   }
}
示例#21
0
std::string app2net(const std::wstring &str, int cp){
	return app2net(str.data(), cp);
}