void loadOptions()
{
	FILE* optionsFile = getOptionsFile(L"r");

	if (optionsFile)
	{
		WCHAR option[256], value[256];
		while (fwscanf_s(optionsFile, L"%[^,],%[^\r\n] ", option, 256, value, 256) == 2)
		{
			if (wcsncmp(option, reqFSOptionName, 256) == 0)
			{
				unsigned char fullscreen;
				swscanf_s(value, L"%hhu", &fullscreen);
				reqFullscreen = fullscreen;
			}
			else if (wcsncmp(option, soundOptionName, 256) == 0)
			{
				swscanf_s(value, L"%i", &soundOption);
			}
		}

		fclose(optionsFile);
	}

	updateRequireFullScreen();
	updateSoundOption();
}
Exemple #2
0
nt::ntFloat NtFile::ReadFloat()
{
	ntFloat target = 0.0f;
	ntInt res = fwscanf_s(m_fp, L"%f", &target);
	if (res == EOF)
	{
		return false;
	}

	NTRACE(L"%f\n", target);
	return target;
}
Exemple #3
0
nt::ntInt NtFile::ReadInt()
{
	ntInt target = 0;
	ntInt res = fwscanf_s(m_fp, L"%d", &target);
	if (res == EOF)
	{
		return false;
	}

	NTRACE(L"%d\n", target);
	return target;
}
Exemple #4
0
bool NtFile::ReadTag()
{
	Crt::MemSet(m_readBuffer, sizeof(m_readBuffer));

	ntInt res = fwscanf_s(m_fp, L"%s", m_readBuffer, _countof(m_readBuffer));
	if (res == EOF)
	{
		return false;
	}
	NTRACE(L"%s\n", m_readBuffer);

	return true;
}
Exemple #5
0
void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
{
#if defined(ENABLE_DEBUG_CONFIG_OPTIONS) && CONFIG_PARSE_CONFIG_FILE
    Assert(!_hasReadConfig);
    _hasReadConfig = true;

    char16 configBuffer[MaxTokenSize];
    int err = 0;
    char16 modulename[_MAX_PATH];
    char16 filename[_MAX_PATH];

    GetModuleFileName((HMODULE)hmod, modulename, _MAX_PATH);
    char16 drive[_MAX_DRIVE];
    char16 dir[_MAX_DIR];

    _wsplitpath_s(modulename, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0);
    _wmakepath_s(filename, drive, dir, _configFileName, _u(".config"));

    FILE* configFile;
    if (_wfopen_s(&configFile, filename, _u("r, ccs=UNICODE")) != 0 || configFile == nullptr)
    {
        WCHAR configFileFullName[MAX_PATH];

        StringCchPrintf(configFileFullName, MAX_PATH, _u("%s.config"), _configFileName);

        // try the one in the current working directory (Desktop)
        if (_wfullpath(filename, configFileFullName, _MAX_PATH) == nullptr)
        {
            return;
        }
        if (_wfopen_s(&configFile, filename, _u("r, ccs=UNICODE")) != 0 || configFile == nullptr)
        {
            return;
        }
    }

    while (fwscanf_s(configFile, _u("%s"), configBuffer, MaxTokenSize) != FINISHED)
    {
        if ((err = parser.Parse(configBuffer)) != 0)
        {
            break;
        }
    }
    fclose(configFile);

    if (err !=0)
    {
        return;
    }
#endif
}
// Parses the configuration file
HRESULT ParseConfigurationFile( LPCWSTR ConfigFilePath )
{
	g_DX11PatchRenderParams.m_bAsyncModeWorkaround = true;

    FILE *pConfigFile = NULL;
    if( _wfopen_s( &pConfigFile, ConfigFilePath, L"r" ) != 0 )
    {
        CHECK_HR_RET(E_FAIL, "Failed to open the configuration file (%s)", ConfigFilePath);
    }
    
    while( !feof(pConfigFile) )
    {
        WCHAR Parameter[128];
        WCHAR EqualSign[128];

        fwscanf_s( pConfigFile, L"%s", Parameter, _countof(Parameter));
        fwscanf_s( pConfigFile, L"%s", EqualSign, _countof(EqualSign));
        if( wcscmp(EqualSign, L"=") != 0 )
        {
            // LOG_ERROR( "Equal sign (=) is missing for parameter \"%s\"", Parameter);
            goto ERROR_EXIT;
        }

        // Directories
        if( wcscmp(L"RawDEMDataFile", Parameter) == 0 )
        {
            ParseParameterString(g_strRawDEMDataFile, MAX_PATH_LENGTH, pConfigFile);
        }
        else if( wcscmp(L"EncodedRQTTriangFile", Parameter) == 0 )
        {
            ParseParameterString(g_strEncodedRQTTriangFile, MAX_PATH_LENGTH, pConfigFile);
        }
		else if( wcscmp(L"CameraTrack", Parameter) == 0 )
        {
            ParseParameterString(g_strCameraTrackPath, MAX_PATH_LENGTH, pConfigFile);
        }
        else if( wcscmp(L"TexturingMode", Parameter) == 0 )
        {
            WCHAR Value[128];
            ParseParameterString(Value, _countof(Value), pConfigFile);
            /*if( wcscmp(L"HeightBased", Value) == 0 )
                g_DX11PatchRenderParams.m_TexturingMode = CAdaptiveModelDX11Render::TM_HEIGHT_BASED;
            else ;*/
                // LOG_ERROR( "Unknown texturing mode (%s)\n"
                           //"Only the following modes are recognized:\n"
                           //"HeightBased\n", Value);
        }
        else
        {
            WCHAR Value[128];
            fwscanf_s( pConfigFile, L"%s", Value, _countof(Value));

            // Parameters
            if( wcscmp(L"ForceRecreateTriang", Parameter) == 0 )
            {
                if( FAILED(ParseParameterBool( Value, g_bForceRecreateTriang ) ) )
                {
                    // LOG_ERROR( "Failed to parse value of the parameter \"%s\"", Parameter);
                    goto ERROR_EXIT;
                }
            }
            else if( wcscmp(L"ElevationSamplingInterval", Parameter) == 0 )
            {
                g_fElevationSamplingInterval = ParseParameterFloat( Value );
            }
			else if(  wcscmp(L"ScalingFactor", Parameter) == 0 )
			{
				g_fElevationScale = ParseParameterFloat( Value );
			}
            else if( wcscmp(L"NumColumns", Parameter) == 0 )
            {
                g_iNumColumns = ParseParameterInt( Value );
            }
            else if( wcscmp(L"NumRows", Parameter) == 0 )
            {
                g_iNumRows = ParseParameterInt( Value );
            }
            else if( wcscmp(L"PatchSize", Parameter) == 0 )
            {
                g_iPatchSize = ParseParameterInt( Value );
            }
            else if( wcscmp(L"ScreenSpaceThreshold", Parameter) == 0 )
            {
                g_TerrainRenderParams.m_fScrSpaceErrorBound = ParseParameterFloat( Value );
            }
		    else if( wcscmp(L"AsyncModeWorkaround", Parameter) == 0 )
            {
                if( FAILED(ParseParameterBool( Value, g_DX11PatchRenderParams.m_bAsyncModeWorkaround) ) )
                {
                    // LOG_ERROR( "Failed to parse value of the parameter \"%s\"", Parameter);
                    goto ERROR_EXIT;
                }
            }
        }
    }

    fclose(pConfigFile);

    return S_OK;

ERROR_EXIT:

    fclose(pConfigFile);

    return E_FAIL;
}
Exemple #7
0
int Test_scan_wide( void )
/************************/
{
    int         number;
    int         violations = NumViolations;
    wchar_t     buf[64];

    VERIFY( swscanf_s( L"123", L"%d", &number ) == 1 );
    VERIFY( number == 123 );

    VERIFY( swscanf_s( NULL, L"%d", &number ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( swscanf_s( L"123", NULL, &number ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( swscanf_s( L"123", L"%d", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( swscanf_s( L"123", L"%*d", NULL ) == 0 );

    VERIFY( swscanf_s( L"123", L"%s", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( swscanf_s( L"123", L"%c", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( swscanf_s( L"123", L"%f", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( swscanf_s( L"123", L"%n", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( swscanf_s( L"123", L"%*d%n%n", &number, NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( swscanf_s( L" 123", L"%s%n", &buf, sizeof( buf ), &number ) == 1 );
    VERIFY( number == 4 && !wcscmp( L"123", buf ) );

    VERIFY( swscanf_s( L" 123", L"%s%n", &buf, 3 ) == 0 );

    VERIFY( swscanf_s( L"aaa", L"%[a]%n", &buf, 4, &number ) == 1 );
    VERIFY( number == 3 && !wcscmp( L"aaa", buf ) );

    VERIFY( swscanf_s( L"aaaa", L"%[a]", &buf, 4 ) == 0 );

    wmemset( buf, 'Q', 6 );
    VERIFY( swscanf_s( L"aaaaa", L"%5c%n", &buf, 5, &number ) == 1 );
    VERIFY( number == 5 && !wmemcmp( L"aaaaaQ", buf, 6 ) );

    VERIFY( swscanf_s( L"aaa", L"%3c%n", &buf, 2 ) == 0 );


    VERIFY( my_swscanf_s( L"123", L"%d", &number ) == 1 );
    VERIFY( number == 123 );

    VERIFY( my_swscanf_s( NULL, L"%d", &number ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_swscanf_s( L"123", NULL, &number ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_swscanf_s( L"123", L"%d", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_swscanf_s( L"123", L"%*d", NULL ) == 0 );

    VERIFY( my_swscanf_s( L"123", L"%s", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_swscanf_s( L"123", L"%c", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_swscanf_s( L"123", L"%f", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_swscanf_s( L"123", L"%n", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );


    VERIFY( wscanf_s( NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( wscanf_s( L"%n", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );


    VERIFY( my_wscanf_s( NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_wscanf_s( L"%n", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );


    VERIFY( fwscanf_s( NULL, L"%n", &number ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( fwscanf_s( stdin, NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( fwscanf_s( stdin, L"%n", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );


    VERIFY( my_fwscanf_s( NULL, L"%d", &number ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_fwscanf_s( stdin, NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    VERIFY( my_fwscanf_s( stdin, L"%n", NULL ) == WEOF );
    VERIFY( ++violations == NumViolations );

    return( 1 );
}
///////////////////////////////////////////////////////////////////////////////
//
// Function: ParseKIDFile
// Description: Parses a text file containing one or more KID strings into an
//  array of KID strings.
// Parameters: pwszInFile  - Path of the file to parse.
//             KIDStrings - Array of strings that receives the KID strings.
//              The array is allocated by this function. The function will fail
//              if it is not NULL on input.
//
// Notes: The following text shows the format of the input file"
//
// KIDFILE
// n
// <KIDString>
// ...
// 
// Where n is the number of KID strings in the file.
///////////////////////////////////////////////////////////////////////////////
HRESULT ParseKIDFile(WCHAR* pwszInFile, WCHAR*** pppKIDStrings, int* pNumStrings)
{
    HRESULT  hr    = S_OK;

    FILE*    pFile = NULL;

    int      error = 0;
    wchar_t  pwszTempString[g_TempStringSize];

    size_t   cchString           = 0;
    int      StringCompareCode = 0;

    // Check the array parameter.
    if (*pppKIDStrings != NULL)
    {
        hr = E_POINTER;
        return hr;
    }

    // Open the file for reading.
    if (SUCCEEDED(hr))
    {
        if (_wfopen_s(&pFile, pwszInFile, L"r") != 0)
        {
            hr = E_FAIL;
            DisplayError(hr, L"The specified filename is invalid.");
        }
    }    

    // Read the first token of the KID file.
    if (SUCCEEDED(hr))
    {
        error = fwscanf_s(pFile, L"%s", pwszTempString, g_TempStringSize);

        if (error != 1)
        {
            hr = E_FAIL;
            DisplayError(hr, L"KID file is improperly formatted.");
        }
    }
      
    // Check the read token against the expected file header.
    if (SUCCEEDED(hr))
    {
        // Get the length of the token.
        cchString = wcsnlen(pwszTempString, g_TempStringSize);

        // Compare the strings.
        StringCompareCode = wcsncmp(pwszTempString, 
                                    g_wszKIDFileHeaderString, 
                                    (cchString));
        
        if (StringCompareCode != 0)
        {
            hr = E_FAIL;
            DisplayError(hr, L"The specified file is not a valid KID File.");
        }
    }

    // Get the number of KID entries in the file.
    if (SUCCEEDED(hr))
    {
        error = fwscanf_s(pFile, L"%d", pNumStrings);

        if (error != 1)
        {
            hr = E_FAIL;
            DisplayError(hr, L"Error reading the number of KID entries.");
        }
        // Check that the number of strings is positive.
        else if (*pNumStrings <= 0)
        {
            hr = E_UNEXPECTED;
            DisplayError(hr, L"KID file specifies zero KID strings.");
        }
    }

    // Allocate memory for the KID string array.
    if (SUCCEEDED(hr))
    {
        // First allocate the array.
        *pppKIDStrings = new WCHAR*[*pNumStrings];

        if (*pppKIDStrings != NULL)
        {
            // Initialize the array.
            ZeroMemory(*pppKIDStrings, *pNumStrings * sizeof(WCHAR*)); 
        }
        else
        {
            hr = E_OUTOFMEMORY;
            DisplayError(hr, L"Couldn't allocate memory.");
        }
    }

    // Loop through the KID strings, allocating memory for each array member.
    for (int i = 0; i < *pNumStrings; i++)
    {
        // Get the next string.
        error = fwscanf_s(pFile, L"%s", pwszTempString, g_TempStringSize);

        if (error != 1)
        {
            hr = E_FAIL;
            DisplayError(hr, L"Could not read KID string from file.");
            break;
        }

        // Get the size of the retrieved string.
        cchString = wcsnlen(pwszTempString, g_TempStringSize);

        // Add one to the size to account for the terminator.
        cchString++;

        // Allocte memory for the string in the array.
        (*pppKIDStrings)[i] = new WCHAR[cchString];

        if ((*pppKIDStrings)[i] == NULL)
        {
            hr = E_OUTOFMEMORY;
            DisplayError(hr, L"Couldn't allocate memory.");
            break;
        }

        // Copy the string to the array.
        error = wcscpy_s((*pppKIDStrings)[i], cchString, pwszTempString);
        if (error != 0)
        {
            hr = E_FAIL;
            DisplayError(hr, L"Could not copy KID string.");
            break;
        }

        // Get ready for the next pass.
        cchString = 0;
        pwszTempString[0] = NULL;
    }

    // Clean up.

    // Release memory for the KID string array if failed.
    if ((FAILED(hr)) && (*pppKIDStrings != NULL))
    {
        for (int i = 0; i < *pNumStrings; i++)
        {
            SAFE_ARRAY_DELETE((*pppKIDStrings)[i]);
        }

        SAFE_ARRAY_DELETE(*pppKIDStrings);
    }

    // Close the file.
    SAFE_FILE_CLOSE(pFile);

    return hr;

}