예제 #1
0
파일: loc.cpp 프로젝트: devgopher/Isotoxin
int proc_unix2dos(const wstrings_c & pars)
{
    if (pars.size() < 3) return 0;
    wstr_c pts = pars.get(1); fix_path(pts, FNO_SIMPLIFY);

    if (!dir_present(pts))
    {
        Print(FOREGROUND_RED, "path-to-files not found: %s", pts.cstr()); return 0;
    }

    wstrings_c exts(pars.get(2), '.');

    if (exts.size() == 0)
    {
        Print(FOREGROUND_RED, "no exts defined");
        return 0;
    }


    wstrings_c lines;
    wstrings_c sfiles;
    fill_dirs_and_files(pts, sfiles, lines);


    for (const wstr_c & f : sfiles)
    {
        bool ok = false;
        for (const wstr_c & e : exts)
            if (f.ends(ts::wstr_c(CONSTWSTR(".")).append(e)) || fn_get_name_with_ext(f).equals(e))
            {
                ok = true;
                break;
            }

        if (ok)
        {
            buf_c b;
            b.load_from_disk_file(f);

            for (int i = b.size() - 1; i >= 0; --i)
            {
                if (b.data()[i] == '\r')
                    b.cut(i, 1);
            }

            for (int i = b.size() - 1; i >= 0; --i)
            {
                if (b.data()[i] == '\n')
                    *b.expand(i, 1) = '\r';
            }

            b.save_to_file(f);
        }
    }


    return 0;
}
예제 #2
0
파일: loc.cpp 프로젝트: devgopher/Isotoxin
int proc_lochange(const wstrings_c & pars)
{
    if (pars.size() < 3) return 0;
    wstr_c pts = pars.get(1); fix_path(pts, FNO_SIMPLIFY);

    if (!dir_present(pts))
    {
        Print(FOREGROUND_RED, "path-to-source not found: %s", pts.cstr()); return 0;
    }

    wstr_c ptl = pars.get(2); fix_path(ptl, FNO_SIMPLIFY);
    if (!dir_present(ptl))
    {
        Print(FOREGROUND_RED, "path-to-loc not found: %s", ptl.cstr()); return 0;
    }

    wstr_c tolocale = CONSTWSTR("en");
    if (pars.size() >= 4)
        tolocale = pars.get(3);

    wstrings_c lines;
    wstrings_c sfiles;
    fill_dirs_and_files(pts, sfiles, lines);


    hashmap_t<int, wstr_c> localehash;
    wstrings_c localelines;
    parse_text_file(fn_join(ptl, tolocale) + CONSTWSTR(".labels.lng"), localelines, true);
    for (const wstr_c &ls : localelines)
    {
        token<wchar> t(ls, '=');
        pwstr_c stag = *t;
        int tag = t->as_int(-1);
        ++t;
        wstr_c l(*t); l.trim();

        if (tag > 0)
            localehash[tag] = l;
    }


    for (const wstr_c & f : sfiles)
    {
        if (f.ends(CONSTWSTR(".h")) || f.ends(CONSTWSTR(".cpp")))
        {
            parse_text_file(f, lines);
            bool cmnt = false;
            bool changed = false;
            int cnt = lines.size();
            for (int ln = 0; ln < cnt; ++ln)
            {
                wstr_c & l = lines.get(ln);
                int workindex = 0;
                wstr_c txt;
                int tag, left, rite;

                while (findTTT(l, txt, tag, cmnt, left, rite, workindex))
                {
                    if (tag >= 0)
                    {
                        wstr_c txtto = localehash[tag];
                        l.replace( left, rite-left, CONSTWSTR("TTT(\"") + txtto + CONSTWSTR("\",") + wmake(tag) + CONSTWSTR(")") );
                        changed = true;
                    }
                }

            }
            if (changed)
                savelines(f, lines);

        }
    }
    return 0;
}