Exemple #1
0
void MatcherModel::setExpression(const QString &expr)
{
    QString e = expr.split(' ').first();
    if (m_expression == e) {
        return;
    }

    m_expression = e;
    matchExpression();
}
Exemple #2
0
MatcherModel::MatcherModel()
            : QAbstractListModel()
{
    QString path = qgetenv("PATH");
    for (const QString &p: path.split(':')) {
        QDir dir(p);
        for (const QFileInfo &f: dir.entryInfoList(QDir::Files)) {
            if (!f.isExecutable()) {
                continue;
            }

            m_items << f.fileName();
        }
    }
    m_items.sort();
    m_items.removeDuplicates();

    matchExpression();
}
Exemple #3
0
void parser(char *parseToken) 
{
	/* function parser(char *)
	Parameters: char *
	Return: nothing
	description: Scanner grabs the token from the buffer and passes it to parser.
				 Parser then knows what the token should be and matches it.
				 If parser finds a unexpected token it prints a syntax error.*/
	if (parse == 0) // the program is expecting begin
		matchBegin(parseToken);
	else if (parse == 1)// the program is expecting a read,write,id or end
		matchStatement(parseToken);
	else if (parse == 3)//the program is expecting a :=
		matchAssignOp(parseToken);
	else if (parse == 4)// the program is expecting a (
		matchLparen(parseToken);
	else if (parse == 5)//the program is expecting a Id
		matchId(parseToken);
	else if (parse == 6)//the program is expecting a ) or a comma
		matchRparen(parseToken);
	else if (parse == 7) //the program is expecting a ;
		matchSemiColon(parseToken);
	else if (parse == 8)
		matchExpression(parseToken);// the program is expecting a int or Id
	else if (parse == 9)
		matchSemiColonRead(parseToken);//the program is expecting a ; or + or -


	if(idFlag == 1)
		insertSymbolTable(parseToken);
	if(writeFlag == 1 && idFlag == 1)
		convertWrite(parseToken);
	if(readFlag == 1 && idFlag == 1)
		convertRead(parseToken);


	return;
}
Exemple #4
0
static void parse( Translator *tor )
{
    QString text;
    QString com;
    QString extracomment;

    yyCh = getChar();

    yyTok = getToken();
    while ( yyTok != Tok_Eof ) {
        switch ( yyTok ) {
        case Tok_class:
            yyTok = getToken();
            if(yyTok == Tok_Ident) {
                yyScope.push(new Scope(yyIdent, Scope::Clazz, yyLineNo));
            }
            else {
                yyMsg() << qPrintable(LU::tr("'class' must be followed by a class name.\n"));
                break;
            }
            while (!match(Tok_LeftBrace)) {
                yyTok = getToken();
            }
            break;

        case Tok_tr:
            yyTok = getToken();
            if ( match(Tok_LeftParen) && matchString(text) ) {
                com.clear();
                bool plural = false;

                if ( match(Tok_RightParen) ) {
                    // no comment
                } else if (match(Tok_Comma) && matchStringOrNull(com)) {   //comment
                    if ( match(Tok_RightParen)) {
                        // ok,
                    } else if (match(Tok_Comma)) {
                        plural = true;
                    }
                }
                if (!text.isEmpty())
                    recordMessage(tor, context(), text, com, extracomment, plural);
            }
            break;
        case Tok_translate:
        {
            QString contextOverride;
            yyTok = getToken();
            if ( match(Tok_LeftParen) &&
                    matchString(contextOverride) &&
                    match(Tok_Comma) &&
                    matchString(text) ) {

                com.clear();
                bool plural = false;
                if (!match(Tok_RightParen)) {
                    // look for comment
                    if ( match(Tok_Comma) && matchStringOrNull(com)) {
                        if (!match(Tok_RightParen)) {
                            if (match(Tok_Comma) && matchExpression() && match(Tok_RightParen)) {
                                plural = true;
                            } else {
                                break;
                            }
                        }
                    } else {
                        break;
                    }
                }
                if (!text.isEmpty())
                    recordMessage(tor, contextOverride, text, com, extracomment, plural);
            }
        }
        break;

        case Tok_Ident:
            yyTok = getToken();
            break;

        case Tok_Comment:
            if (yyComment.startsWith(QLatin1Char(':'))) {
                yyComment.remove(0, 1);
                extracomment.append(yyComment);
            }
            yyTok = getToken();
            break;

        case Tok_RightBrace:
            if ( yyScope.isEmpty() ) {
                yyMsg() << qPrintable(LU::tr("Excess closing brace.\n"));
            }
            else
                delete (yyScope.pop());
            extracomment.clear();
            yyTok = getToken();
            break;

        case Tok_LeftBrace:
            yyScope.push(new Scope(QString(), Scope::Other, yyLineNo));
            yyTok = getToken();
            break;

        case Tok_Semicolon:
            extracomment.clear();
            yyTok = getToken();
            break;

        case Tok_Package:
            yyTok = getToken();
            while(!match(Tok_Semicolon)) {
                switch(yyTok) {
                case Tok_Ident:
                    yyPackage.append(yyIdent);
                    break;
                case Tok_Dot:
                    yyPackage.append(QLatin1String("."));
                    break;
                default:
                    yyMsg() << qPrintable(LU::tr("'package' must be followed by package name.\n"));
                    break;
                }
                yyTok = getToken();
            }
            break;

        default:
            yyTok = getToken();
        }
    }

    if ( !yyScope.isEmpty() )
        yyMsg(yyScope.top()->line) << qPrintable(LU::tr("Unbalanced opening brace.\n"));
    else if ( yyParenDepth != 0 )
        yyMsg(yyParenLineNo) << qPrintable(LU::tr("Unbalanced opening parenthesis.\n"));
}
Exemple #5
0
static void parse( MetaTranslator *tor, const char *initialContext,
           const char *defaultContext )
{
    QMap<QByteArray, QByteArray> qualifiedContexts;
    QByteArray context;
    QByteArray text;
    QByteArray com;
    QByteArray functionContext = initialContext;
    QByteArray prefix;
    bool utf8 = false;

    yyTok = getToken();
    while ( yyTok != Tok_Eof ) {
        switch ( yyTok ) {
        case Tok_class:
                yyTok = getToken();
                functionContext = yyIdent;
                yyTok = getToken();
                break;
            case Tok_tr:
            case Tok_trUtf8:
                utf8 = (yyTok == Tok_trUtf8 || (yyCodecForTr && strcmp(yyCodecForTr->name(), "UTF-8") == 0));
                yyTok = getToken();
                if (match(Tok_LeftParen) && matchString(&text))
                {
                    com = "";
                    bool plural = false;

                    if (match(Tok_RightParen))
                    {
                        // There is no comment or plural arguments.
                    }
                    else if (match(Tok_Comma) && matchStringOrNone(&com))
                    {
                        // There is a comment argument.
                        if (match(Tok_RightParen))
                        {
                            // There is no plural argument.
                        }
                        else if (match(Tok_Comma))
                        {
                            // There is a plural argument.
                            plural = true;
                        }
                    }

                    if (prefix.isNull())
                        context = defaultContext;
                    else if (qstrcmp(prefix, "self") == 0)
                        context = functionContext;
                    else
                        context = prefix;

                    prefix = (const char *) 0;

                    if (qualifiedContexts.contains(context))
                        context = qualifiedContexts[context];

                    if (!text.isEmpty())
                    {
                        tor->insert(MetaTranslatorMessage(context, text, com, 
                                yyFileName, yyParenLineNo,
                                QStringList(), utf8,
                                MetaTranslatorMessage::Unfinished, plural));
                    }
                }
                break;
            case Tok_translate:
                utf8 = false;
                yyTok = getToken();
                if ( match(Tok_LeftParen) &&
                 matchString(&context) &&
                 match(Tok_Comma) &&
                 matchString(&text) ) {
                    com = "";
                    bool plural = false;
                    if (!match(Tok_RightParen)) {
                        // look for comment
                        if ( match(Tok_Comma) && matchStringOrNone(&com)) {
                            if (!match(Tok_RightParen)) {
                                // look for encoding
                                if (match(Tok_Comma)) {
                                    if (matchEncoding(&utf8)) {
                                        if (!match(Tok_RightParen)) {
                                            // look for the plural quantifier,
                                            // this can be a number, an identifier or a function call,
                                            // so for simplicity we mark it as plural if we know we have a comma instead of an
                                            // right parentheses.
                                            plural = match(Tok_Comma);
                                        }
                                    } else {
                                        // This can be a QTranslator::translate("context", "source", "comment", n) plural translation
                                        if (matchExpression() && match(Tok_RightParen)) {
                                            plural = true;
                                        } else {
                                            break;
                                        }
                                    }
                                } else {
                                    break;
                                }
                            }
                        } else {
                            break;
                        }
                    }
                    if (!text.isEmpty())
                    {
                        tor->insert( MetaTranslatorMessage(context, text, com, 
                                                        yyFileName, yyParenLineNo,
                                                        QStringList(), utf8,
                                                        MetaTranslatorMessage::Unfinished,
                                                        plural) );
                    }
                }
                break;
            case Tok_Ident:
                if ( !prefix.isNull() )
                    prefix += ".";
                prefix += yyIdent;
                yyTok = getToken();
                if ( yyTok != Tok_Dot )
                    prefix = (const char *) 0;
                break;
            case Tok_Comment:
                com = yyComment;
                com = com.simplified();
                if ( com.left(sizeof(MagicComment) - 1) == MagicComment ) {
                    com.remove( 0, sizeof(MagicComment) - 1 );
                    int k = com.indexOf( ' ' );
                    if ( k == -1 ) {
                        context = com;
                    } else {
                        context = com.left( k );
                        com.remove( 0, k + 1 );
                        tor->insert( MetaTranslatorMessage(context, "", com,
                                                        yyFileName, yyParenLineNo,
                                                        QStringList(), false) );
    
                    }
                }
                yyTok = getToken();
                break;
            default:
                yyTok = getToken();
        }
    }

    if ( yyParenDepth != 0 )
        qWarning( "%s: Unbalanced parentheses in Python code",
            (const char *) yyFileName );
}
void OSInterface::getDirInfo(std::string path, std::string pattern){
    WIN32_FIND_DATA data;
    repairPath(path);

    path.append("*");
    std::wstring ppath, whole_name;
    ppath.assign(path.begin(), path.end());
    path.pop_back();
    dirEntryT *de;
    HANDLE hFile = FindFirstFile(ppath.c_str(), &data);

    if  ((hFile == INVALID_HANDLE_VALUE) && (GetLastError() != ERROR_FILE_NOT_FOUND)) return;
    //throw new OSException(path, "Failed to open dir.");
    std::string name, tmpname;
    while(FindNextFile(hFile, &data) != 0 || GetLastError() != ERROR_NO_MORE_FILES)
    {
        de = new dirEntryT();
        whole_name = whole_name = data.cFileName;
        name.assign(whole_name.begin(), whole_name.end());
        tmpname = path + name;
        std::cout << name << std::endl;
        whole_name.assign(tmpname.begin(), tmpname.end());
        de->ext_name = getExtension(name);
        WIN32_FILE_ATTRIBUTE_DATA fileInfo;
        if(!GetFileAttributesEx(whole_name.c_str(), GetFileExInfoStandard, &fileInfo)) continue;
        DWORD ftype = fileInfo.dwFileAttributes;
        if (ftype == INVALID_FILE_ATTRIBUTES) continue;
        // throw new OSException(name, "Invalid file");
        if((name == ".") || name == "..") continue;
        if((!matchExpression(name, pattern)) && !isDir(name)) continue;
        de->name = name;
        if((ftype & FILE_ATTRIBUTE_NORMAL) || (ftype & FILE_ATTRIBUTE_SYSTEM) || (ftype & FILE_ATTRIBUTE_COMPRESSED)){
            de->type = de->FILE;
            de->type_name = "FILE";
        }else if(ftype & FILE_ATTRIBUTE_DIRECTORY){
            de->type = de->DIR;
            de->type_name = "DIR";
        }else if(ftype & FILE_ATTRIBUTE_VIRTUAL){
            de->type = de->LINK;
            de->type_name = "LINK";
        }else{
            de->type = de->UNKNOWN;
            de->type_name = "UNKNOWN";
        }
        if(isArch(de->ext_name)){
            de->type_name = "ARCHIVE";
            de->type = de->ARCHIVE;
        }
        de->byte_size = getSize(name);
        SYSTEMTIME stUTC, stLocal;
        LPTSTR lpszString;
        FileTimeToSystemTime(&fileInfo.ftLastWriteTime, &stUTC);
        SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
        char buf[255];
        sprintf(buf, "%02d.%02d.%d  %02d:%02d",
                stLocal.wDay, stLocal.wMonth, stLocal.wYear,
                stLocal.wHour, stLocal.wMinute);
        de->mod_time = std::string(buf);

        dirs.push_back(de);
    }
    std::sort(dirs.begin(), dirs.end(),[=](dirEntryT *d1, dirEntryT *d2){
        if ((d1->type == d1->DIR) && (d2->type != d2->DIR))
            return true;
        else if ((d1->type != d1->DIR) && (d2->type == d2->DIR))
            return false;
        else
            return d1->name < d2->name; });
}
void OSInterface::getDirInfo(std::string path, std::string pattern){
    DIR *dir;
    if((dir = opendir(path.c_str())) == NULL){
        throw new OSException(path, "Failed to open dir.");
        //return;
    }
    struct dirent *entry = new struct dirent();
    struct stat *finfo = new struct stat();
    std::string abs_path(path), name;
    dirEntryT *de;
    while((entry = readdir(dir))){
        de = new dirEntryT();
        name = entry->d_name;
        de->ext_name = getExtension(name);
        if((name == ".") || name == "..") continue;
        if((!matchExpression(name, pattern)) && !isDir(abs_path + dir_sep + name)) continue;
        lstat((abs_path + dir_sep + name).c_str(), finfo);
        if(finfo == NULL)
            throw new OSException(name, std::string("failed to read file info."));
        de->name = name;
        if(S_ISREG(finfo->st_mode)){
            de->type = de->Type::FILE;
            de->type_name = "FILE";
        }else if(S_ISDIR(finfo->st_mode)){
            de->type = de->Type::DIR;
            de->type_name = "DIR";
        }else if(S_ISLNK(finfo->st_mode)){
            de->type = de->Type::LINK;
            de->type_name = "LINK";
        }else{
            de->type = de->Type::UNKNOWN;
            de->type_name = "UNKNOWN";
        }
        if(isArch(de->name)){
            de->type_name = "ARCHIVE";
            de->type = de->Type::ARCHIVE;
        }
        de->byte_size = finfo->st_size;
        char buf[255];
        sprintf(buf, "%s", ctime(&finfo->st_mtime));
        std::stringstream ss;
        mode_t mode = finfo->st_mode;
        std::string date(buf);
        date = date.substr(0, date.size() - 1);
        de->mod_time = date;
        if((mode & S_IRWXU) & S_IRUSR) ss << "r"; else ss << "-";
        if((mode & S_IRWXU) & S_IWUSR) ss << "w"; else ss << "-";
        if((mode & S_IRWXU) & S_IXUSR) ss << "x"; else ss << "-";
        ss << " ";
        if((mode & S_IRWXG) & S_IRGRP) ss << "r"; else ss << "-";
        if((mode & S_IRWXG) & S_IWGRP) ss << "w"; else ss << "-";
        if((mode & S_IRWXG) & S_IXGRP) ss << "x"; else ss << "-";
        ss << " ";
        if((mode & S_IRWXO) & S_IROTH) ss << "r"; else ss << "-";
        if((mode & S_IRWXO) & S_IWOTH) ss << "w"; else ss << "-";
        if((mode & S_IRWXO) & S_IXOTH) ss << "x"; else ss << "-";
        de->perms = std::string(ss.str());
        dirs.push_back(de);
    }
    closedir(dir);
    std::sort(dirs.begin(), dirs.end(),[=](dirEntryT *d1, dirEntryT *d2){
        if ((d1->type == d1->Type::DIR) && (d2->type != d2->Type::DIR))
            return true;
        else if ((d1->type != d1->Type::DIR) && (d2->type == d2->Type::DIR))
            return false;
        else
            return d1->name < d2->name; });
}