Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 436bbd1a authored by Elliott Hughes's avatar Elliott Hughes
Browse files

The 'localize' tool is dead.

Change-Id: I6486e50fd1d2f82dd040371a308a2a756beadb64
parent 476b03b0
Loading
Loading
Loading
Loading

tools/localize/Android.mk

deleted100644 → 0
+0 −55
Original line number Diff line number Diff line
# 
# Copyright 2006 The Android Open Source Project
#
# Android Asset Packaging Tool
#

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
    file_utils.cpp \
    localize.cpp \
    merge_res_and_xliff.cpp \
    res_check.cpp \
    xmb.cpp \
    Configuration.cpp \
    Perforce.cpp \
    SourcePos.cpp \
    Values.cpp \
    ValuesFile.cpp \
    XLIFFFile.cpp \
    XMLHandler.cpp

LOCAL_C_INCLUDES := \
    external/expat/lib \
    build/libs/host/include

LOCAL_CFLAGS += -g -O0

LOCAL_STATIC_LIBRARIES := \
    libexpat \
    libhost \
    libutils \
	libcutils
    
ifeq ($(HOST_OS),linux)
LOCAL_LDLIBS += -lrt -ldl -lpthread
endif


LOCAL_MODULE := localize

ifeq (a,a)
    LOCAL_CFLAGS += -DLOCALIZE_WITH_TESTS
    LOCAL_SRC_FILES += \
        test.cpp \
        localize_test.cpp \
        merge_res_and_xliff_test.cpp \
        Perforce_test.cpp \
        ValuesFile_test.cpp \
        XLIFFFile_test.cpp \
        XMLHandler_test.cpp
endif

include $(BUILD_HOST_EXECUTABLE)

tools/localize/Configuration.cpp

deleted100644 → 0
+0 −76
Original line number Diff line number Diff line
#include "Configuration.h"
#include <string.h>

int
Configuration::Compare(const Configuration& that) const
{
    int n;

    n = locale.compare(that.locale);
    if (n != 0) return n;

    n = vendor.compare(that.vendor);
    if (n != 0) return n;

    n = orientation.compare(that.orientation);
    if (n != 0) return n;

    n = density.compare(that.density);
    if (n != 0) return n;

    n = touchscreen.compare(that.touchscreen);
    if (n != 0) return n;

    n = keyboard.compare(that.keyboard);
    if (n != 0) return n;

    n = navigation.compare(that.navigation);
    if (n != 0) return n;

    n = screenSize.compare(that.screenSize);
    if (n != 0) return n;

    return 0;
}

string
Configuration::ToString() const
{
    string s;
    if (locale.length() > 0) {
        if (s.length() > 0) {
            s += "-";
        }
        s += locale;
    }
    return s;
}

bool
split_locale(const string& in, string* language, string* region)
{
    const int len = in.length();
    if (len == 2) {
        if (isalpha(in[0]) && isalpha(in[1])) {
            *language = in;
            region->clear();
            return true;
        } else {
            return false;
        }
    }
    else if (len == 5) {
        if (isalpha(in[0]) && isalpha(in[1]) && (in[2] == '_' || in[2] == '-')
                && isalpha(in[3]) && isalpha(in[4])) {
            language->assign(in.c_str(), 2);
            region->assign(in.c_str()+3, 2);
            return true;
        } else {
            return false;
        }
    }
    else {
        return false;
    }
}

tools/localize/Configuration.h

deleted100644 → 0
+0 −38
Original line number Diff line number Diff line
#ifndef CONFIGURATION_H
#define CONFIGURATION_H

#include <string>

using namespace std;

struct Configuration
{
    string locale;
    string vendor;
    string orientation;
    string density;
    string touchscreen;
    string keyboard;
    string navigation;
    string screenSize;

    // Compare two configurations
    int Compare(const Configuration& that) const;

    inline bool operator<(const Configuration& that) const { return Compare(that) < 0; }
    inline bool operator<=(const Configuration& that) const { return Compare(that) <= 0; }
    inline bool operator==(const Configuration& that) const { return Compare(that) == 0; }
    inline bool operator!=(const Configuration& that) const { return Compare(that) != 0; }
    inline bool operator>=(const Configuration& that) const { return Compare(that) >= 0; }
    inline bool operator>(const Configuration& that) const { return Compare(that) > 0; }

    // Parse a directory name, like "values-en-rUS".  Return the first segment in resType.
    bool ParseDiectoryName(const string& dir, string* resType);

    string ToString() const;
};

bool split_locale(const string& in, string* language, string* region);


#endif // CONFIGURATION_H

tools/localize/Perforce.cpp

deleted100644 → 0
+0 −234
Original line number Diff line number Diff line
#include "Perforce.h"
#include "log.h"
#include <string.h>
#include <cstdio>
#include <stdlib.h>
#include <sstream>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <cstdio>

using namespace std;

extern char** environ;

int
Perforce::RunCommand(const string& cmd, string* result, bool printOnFailure)
{
    int err;
    int outPipe[2];
    int errPipe[2];
    pid_t pid;

    log_printf("Perforce::RunCommand: %s\n", cmd.c_str());

    err = pipe(outPipe);
    err |= pipe(errPipe);
    if (err == -1) {
        printf("couldn't create pipe. exiting.\n");
        exit(1);
        return -1;
    }

    pid = fork();
    if (pid == -1) {
        printf("couldn't fork. eixiting\n");
        exit(1);
        return -1;
    }
    else if (pid == 0) {
        char const* args[] = {
            "/bin/sh",
            "-c",
            cmd.c_str(),
            NULL
        };
        close(outPipe[0]);
        close(errPipe[0]);
        dup2(outPipe[1], 1);
        dup2(errPipe[1], 2);
        execve(args[0], (char* const*)args, environ);
        // done
    }

    close(outPipe[1]);
    close(errPipe[1]);

    result->clear();

    char buf[1024];

    // stdout
    while (true) {
        size_t amt = read(outPipe[0], buf, sizeof(buf));
        result->append(buf, amt);
        if (amt <= 0) {
            break;
        }
    }

    // stderr -- the messages are short so it ought to just fit in the buffer
    string error;
    while (true) {
        size_t amt = read(errPipe[0], buf, sizeof(buf));
        error.append(buf, amt);
        if (amt <= 0) {
            break;
        }
    }

    close(outPipe[0]);
    close(errPipe[0]);

    waitpid(pid, &err, 0);
    if (WIFEXITED(err)) {
        err = WEXITSTATUS(err);
    } else {
        err = -1;
    }
    if (err != 0 && printOnFailure) {
        write(2, error.c_str(), error.length());
    }
    return err;
}

int
Perforce::GetResourceFileNames(const string& version, const string& base,
                                const vector<string>& apps, vector<string>* results,
                                bool printOnFailure)
{
    int err;
    string text;
    stringstream cmd;

    cmd << "p4 files";

    const size_t I = apps.size();
    for (size_t i=0; i<I; i++) {
        cmd << " \"" << base << '/' << apps[i] << "/res/values/strings.xml@" << version << '"';
    }

    err = RunCommand(cmd.str(), &text, printOnFailure);

    const char* str = text.c_str();
    while (*str) {
        const char* lineend = strchr(str, '\n');
        if (lineend == str) {
            str++;
            continue;
        }
        if (lineend-str > 1023) {
            fprintf(stderr, "line too long!\n");
            return 1;
        }

        string s(str, lineend-str);

        char filename[1024];
        char edit[1024];
        int count = sscanf(str, "%[^#]#%*d - %s change %*d %*[^\n]\n", filename, edit);

        if (count == 2 && 0 != strcmp("delete", edit)) {
            results->push_back(string(filename));
        }

        str = lineend + 1;
    }

    return err;
}

int
Perforce::GetFile(const string& file, const string& version, string* result,
        bool printOnFailure)
{
    stringstream cmd;
    cmd << "p4 print -q \"" << file << '@' << version << '"';
    return RunCommand(cmd.str(), result, printOnFailure);
}

string
Perforce::GetCurrentChange(bool printOnFailure)
{
    int err;
    string text;

    err = RunCommand("p4 changes -m 1 \\#have", &text, printOnFailure);
    if (err != 0) {
        return "";
    }

    long long n;
    int count = sscanf(text.c_str(), "Change %lld on", &n);
    if (count != 1) {
        return "";
    }

    char result[100];
    sprintf(result, "%lld", n);

    return string(result);
}

static int
do_files(const string& op, const vector<string>& files, bool printOnFailure)
{
    string text;
    stringstream cmd;

    cmd << "p4 " << op;

    const size_t I = files.size();
    for (size_t i=0; i<I; i++) {
        cmd << " \"" << files[i] << "\"";
    }

    return Perforce::RunCommand(cmd.str(), &text, printOnFailure);
}

int
Perforce::EditFiles(const vector<string>& files, bool printOnFailure)
{
    return do_files("edit", files, printOnFailure);
}

int
Perforce::AddFiles(const vector<string>& files, bool printOnFailure)
{
    return do_files("add", files, printOnFailure);
}

int
Perforce::DeleteFiles(const vector<string>& files, bool printOnFailure)
{
    return do_files("delete", files, printOnFailure);
}

string
Perforce::Where(const string& depotPath, bool printOnFailure)
{
    int err;
    string text;
    string cmd = "p4 where ";
    cmd += depotPath;

    err = RunCommand(cmd, &text, printOnFailure);
    if (err != 0) {
        return "";
    }

    size_t index = text.find(' ');
    if (index == text.npos) {
        return "";
    }
    index = text.find(' ', index+1)+1;
    if (index == text.npos) {
        return "";
    }

    return text.substr(index, text.length()-index-1);
}

tools/localize/Perforce.h

deleted100644 → 0
+0 −25
Original line number Diff line number Diff line
#ifndef PERFORCE_H
#define PERFORCE_H

#include <string>
#include <vector>

using namespace std;

class Perforce
{
public:
    static int RunCommand(const string& cmd, string* result, bool printOnFailure);
    static int GetResourceFileNames(const string& version, const string& base,
                                const vector<string>& apps, vector<string>* result,
                                bool printOnFailure);
    static int GetFile(const string& file, const string& version, string* result,
                                bool printOnFailure);
    static string GetCurrentChange(bool printOnFailure);
    static int EditFiles(const vector<string>& filename, bool printOnFailure);
    static int AddFiles(const vector<string>& files, bool printOnFailure);
    static int DeleteFiles(const vector<string>& files, bool printOnFailure);
    static string Where(const string& depotPath, bool printOnFailure);
};

#endif // PERFORCE_H
Loading