コード例 #1
0
ファイル: platform_dep.cpp プロジェクト: carriercomm/armware
int
mkdir(
    char const *pathname,
    mode_t mode)
{
    assert(pathname != 0);

    wchar_t * const pathname_w = fmtstr_mbstowcs(pathname, NULL);
    assert(pathname_w != NULL);

    int const result = CreateDirectory(pathname_w, NULL);

    fmtstr_delete(static_cast<void *>(pathname_w));

    /* mkdir returns 0 for success, opposite of
     * CreateDirectory().
     */
    return ((result != 0) ? 0 : -1);
}
コード例 #2
0
ファイル: platform_dep.cpp プロジェクト: carriercomm/armware
void *
library_load(
    char const * const filename)
{
#if LINUX
    return ::dlopen(filename, RTLD_LAZY);
#elif WIN32
    wchar_t * const filename_w = fmtstr_mbstowcs(filename, NULL);

    HMODULE module = LoadLibrary(filename_w);
    assert(module != NULL);

    fmtstr_delete(static_cast<void *>(filename_w));

    return module;
#else
#error "Platform doesn't support dlopen and we have no implementation."
#endif
}
コード例 #3
0
ファイル: main.cpp プロジェクト: yuan-/wei-parser-generator
bool
analyser_environment_t::parse_command_line(int argc, char **argv)
{
    int i;
    bool correct = true;

    for (i = 1; i < argc; ++i)
    {
        wchar_t * const tmp = fmtstr_mbstowcs(argv[i], 0);
        assert(tmp != 0);
        boost::shared_ptr<wchar_t> parm_ptr(tmp, fmtstr_delete);

        if ((0 == wcscmp(L"-h", parm_ptr.get())) ||
                (0 == wcscmp(L"--help", parm_ptr.get())))
        {
            fwprintf(stderr, L"%s\n", USAGE_MESSAGE);
        }
#if defined(_DEBUG)
        else if (0 == wcscmp(L"-cmp_ans", parm_ptr.get()))
        {
            m_cmp_ans = true;
        }
#endif
        else if (0 == wcscmp(L"-o", parm_ptr.get()))
        {
            wchar_t * const tmp = fmtstr_mbstowcs(argv[++i], 0);
            assert(tmp != 0);
            parm_ptr.reset(tmp, fmtstr_delete);

            wchar_t * const filename = fmtstr_new(L"%s%d",
                                                  parm_ptr.get(),
                                                  m_curr_output_filename_idx);
            mp_output_file = new std::wfstream(filename,
                                               std::ios_base::out |
                                               std::ios_base::binary);
            fmtstr_delete(filename);
            if (false == mp_output_file->is_open())
            {
                fwprintf(stderr, L"Can not open output file: %s\n", argv[i]);
                return false;
            }
            m_output_filename = parm_ptr.get();
        }
        else
        {
            if (L'-' == *parm_ptr)
            {
                fprintf(stderr, "unknown option: %s\n", parm_ptr.get());
                correct = false;
            }
            else
            {
                // The only possible now is source file,
                // then try to find one.
                m_grammar_file_name = parm_ptr.get();
                m_grammar_file.open(parm_ptr.get(), std::ios_base::in | std::ios_base::binary);

                if (false == m_grammar_file.is_open())
                {
                    fwprintf(stderr, L"Can not open grammar file: %s\n", argv[i]);
                    return false;
                }
            }
        }
    }

    if (false == correct)
    {
        return false;
    }
    if (false == m_grammar_file.is_open())
    {
        fprintf(stderr, "You must specify a grammar file.\n");
        return false;
    }

    return true;
}