示例#1
0
void TableGenerator::parseIncludeInstruction(QString line)
{
    // Parse something that looks like:
    // include "/usr/share/X11/locale/en_US.UTF-8/Compose"
    QString quote = QStringLiteral("\"");
    line.remove(0, line.indexOf(quote) + 1);
    line.chop(line.length() - line.indexOf(quote));

    // expand substitutions if present
    line.replace(QLatin1String("%H"), QString(qgetenv("HOME")));
    line.replace(QLatin1String("%L"), systemComposeDir() +  QLatin1Char('/')  + composeTableForLocale());
    line.replace(QLatin1String("%S"), systemComposeDir());

    processFile(line);
}
示例#2
0
void TableGenerator::findComposeFile()
{
    bool found = false;
    // check if XCOMPOSEFILE points to a Compose file
    if (qEnvironmentVariableIsSet("XCOMPOSEFILE")) {
        QString composeFile(qgetenv("XCOMPOSEFILE"));
        if (composeFile.endsWith(QLatin1String("Compose")))
            found = processFile(composeFile);
        else
            qWarning("Qt Warning: XCOMPOSEFILE doesn't point to a valid Compose file");
#ifdef DEBUG_GENERATOR
        if (found)
            qDebug() << "Using Compose file from: " << composeFile;
#endif
    }
    // check if user’s home directory has a file named .XCompose
    if (!found && cleanState()) {
        QString composeFile = qgetenv("HOME") + QStringLiteral("/.XCompose");
        if (QFile(composeFile).exists())
            found = processFile(composeFile);
#ifdef DEBUG_GENERATOR
        if (found)
            qDebug() << "Using Compose file from: " << composeFile;
#endif
    }
    // check for the system provided compose files
    if (!found && cleanState()) {
        QString table = composeTableForLocale();
        if (cleanState()) {
            if (table.isEmpty())
                // no table mappings for the system's locale in the compose.dir
                m_state = UnsupportedLocale;
            else
                found = processFile(systemComposeDir() + QLatin1Char('/') + table);
#ifdef DEBUG_GENERATOR
            if (found)
                qDebug() << "Using Compose file from: " <<
                            systemComposeDir() + QLatin1Char('/') + table;
#endif
        }
    }

    if (found && m_composeTable.isEmpty())
        m_state = EmptyTable;

    if (!found)
        m_state = MissingComposeFile;
}
示例#3
0
QString TableGenerator::findComposeFile()
{
    // check if XCOMPOSEFILE points to a Compose file
    if (qEnvironmentVariableIsSet("XCOMPOSEFILE")) {
        const QString path = QFile::decodeName(qgetenv("XCOMPOSEFILE"));
        if (QFile::exists(path))
            return path;
        else
            qWarning("$XCOMPOSEFILE doesn't point to an existing file");
    }

    // check if user’s home directory has a file named .XCompose
    if (cleanState()) {
        QString path = qgetenv("HOME") + QLatin1String("/.XCompose");
        if (QFile::exists(path))
            return path;
    }

    // check for the system provided compose files
    if (cleanState()) {
        QString table = composeTableForLocale();
        if (cleanState()) {
            if (table.isEmpty())
                // no table mappings for the system's locale in the compose.dir
                m_state = UnsupportedLocale;
            else {
                QString path = QDir(systemComposeDir()).filePath(table);
                if (QFile::exists(path))
                    return path;
            }
        }
    }
    return QString();
}
示例#4
0
QString TableGenerator::readLocaleMappings(const QByteArray &locale)
{
    QString file;
    if (locale.isEmpty())
        return file;

    QFile mappings(systemComposeDir() + QLatin1String("/compose.dir"));
    if (mappings.open(QIODevice::ReadOnly)) {
        const int localeNameLength = locale.size();
        const char * const localeData = locale.constData();

        char l[1024];
        // formating of compose.dir has some inconsistencies
        while (!mappings.atEnd()) {
            int read = mappings.readLine(l, sizeof(l));
            if (read <= 0)
                break;

            char *line = l;
            if (*line >= 'a' && *line <= 'z') {
                // file name
                while (*line && *line != ':' && *line != ' ' && *line != '\t')
                    ++line;
                if (!*line)
                    continue;
                const char * const composeFileNameEnd = line;
                *line = '\0';
                ++line;

                // locale name
                while (*line && (*line == ' ' || *line == '\t'))
                    ++line;
                const char * const lc = line;
                while (*line && *line != ' ' && *line != '\t' && *line != '\n')
                    ++line;
                *line = '\0';
                if (localeNameLength == (line - lc) && !strncasecmp(lc, localeData, line - lc)) {
                    file = QString::fromLocal8Bit(l, composeFileNameEnd - l);
                    break;
                }
            }
        }
        mappings.close();
    }
    return file;
}
示例#5
0
QByteArray TableGenerator::readLocaleAliases(const QByteArray &locale)
{
    QFile aliases(systemComposeDir() + QLatin1String("/locale.alias"));
    QByteArray fullLocaleName;
    if (aliases.open(QIODevice::ReadOnly)) {
        while (!aliases.atEnd()) {
            char l[1024];
            int read = aliases.readLine(l, sizeof(l));
            char *line = l;
            if (read && ((*line >= 'a' && *line <= 'z') ||
                         (*line >= 'A' && *line <= 'Z'))) {
                const char *alias = line;
                while (*line && *line != ':' && *line != ' ' && *line != '\t')
                    ++line;
                if (!*line)
                    continue;
                *line = 0;
                if (locale.size() == (line - alias)
                        && !strncasecmp(alias, locale.constData(), line - alias)) {
                    // found a match for alias, read the real locale name
                    ++line;
                    while (*line && (*line == ' ' || *line == '\t'))
                        ++line;
                    const char *fullName = line;
                    while (*line && *line != ' ' && *line != '\t' && *line != '\n')
                        ++line;
                    *line = 0;
                    fullLocaleName = fullName;
#ifdef DEBUG_GENERATOR
                    qDebug() << "Alias for: " << alias << "is: " << fullLocaleName;
                    break;
#endif
                }
            }
        }
        aliases.close();
    }
    return fullLocaleName;
}