RadAd
5/19/2017 - 12:29 AM

ConPrint.cpp

#include <stdio.h>
#include <tchar.h>

void SlashDecode(_Out_writes_z_(_size) TCHAR* dst, _In_ rsize_t _size, _In_z_ TCHAR const* src)
{
    size_t is = 0;
    size_t id = 0;
    while (src[is] != _T('\0'))
    {
        if (src[is] == _T('\\'))
        {
            ++is;
            switch (src[is])
            {
            case _T('a'):   dst[id] = _T('\a'); break;
            case _T('b'):   dst[id] = _T('\b'); break;
            case _T('f'):   dst[id] = _T('\f'); break;
            case _T('e'):   dst[id] = 27; break;// _T('\e');
            case _T('r'):   dst[id] = _T('\r'); break;
            case _T('n'):   dst[id] = _T('\n'); break;
            case _T('t'):   dst[id] = _T('\t'); break;
            case _T('v'):   dst[id] = _T('\v'); break;
            case _T('\\'):  dst[id] = _T('\\'); break;
            case _T('\''):  dst[id] = _T('\''); break;
            case _T('\"'):  dst[id] = _T('\"'); break;
            case _T('\?'):  dst[id] = _T('\?'); break;
            default:        dst[id] = src[is]; break;
            }
            ++is;
            ++id;
        }
        else
        {
            dst[id] = src[is];
            ++is;
            ++id;
        }
    }
    dst[id] = _T('\0');
}

template<size_t Size>
void SlashDecode(TCHAR(&_Dst)[Size], _In_z_ TCHAR const* src)
{
    SlashDecode(_Dst, Size, src);
}

int _tmain(int argc, const TCHAR* argv[])
{
    bool first = true;
    for (int i = 1; i < argc; ++i)
    {
        if (!first)
            _tprintf(_T(" "));
        TCHAR str[1024];
        //_tcscpy_s(str, argv[i]);
        SlashDecode(str, argv[i]);
        _tprintf(str);
        first = false;
    }
    return 0;
}