Beispiel #1
0
int tsh_fg(int argc, char* argv[])
{
    if (argc < 2 || !argv[1] || (argv[1][0] != '%'))
    {
        fprintf(stderr, "Usage: fg %%<job>\n");
        return 0;
    }

    int jobID = atoi(&(argv[1][1]));
    if (jobID >= MAX_BG_JOB)
    {
        fprintf(stderr, "tsh: fg %%%d: no such job\n", jobID);
        return 0;
    }

    ProcessGroup* currGroup = backgroundGroup[jobID];
    if (currGroup == NULL)
        fprintf(stderr, "tsh: fg %%%d: no such job\n", jobID);
    else
    {
        int idxPID;
        for (idxPID = 0 ; idxPID < currGroup->proc_num ; idxPID ++)
        {
            int status = currGroup->status[idxPID];
            if ((currGroup->isRunning[idxPID] == 0) && WIFSTOPPED(currGroup->status[idxPID]))
            {
                currGroup->isRunning[idxPID] = 1;
                kill(currGroup->pids[idxPID], SIGCONT);
            }
            fprintf(stderr, "[%d]", jobID);
            fprintf(stderr, "\t%d\t", currGroup->pids[idxPID]);
            if (currGroup->isRunning[idxPID])
                fprintf(stderr, "running");
            else if (WIFEXITED(status))
                fprintf(stderr, "exited (%d)", WEXITSTATUS(status));
            else if (WIFSIGNALED(status))
                fprintf(stderr, "killed (%d)", WTERMSIG(status));
            else if (WIFSTOPPED(status))
                fprintf(stderr, "stopped (%d)", WSTOPSIG(status));
            fprintf(stderr, "\t\t%s\n", currGroup->cmdlines[idxPID]);
        }
        moveToForeground(currGroup);
        backgroundGroup[jobID] = NULL;
    }
    return 0;
}
//-----------------------------------------------------------------------------------------
bool GenericTextEditor::displayText(QString docName, QString text, QString extension, QString optionalData)
{
    // If there is no extra extension passed, then try to find the matching one based on the doc name
    ITextEditorCodecFactory* codecFactory;
    if(extension == "")    
        codecFactory = GenericTextEditor::findMatchingCodecFactory(docName);
    else
        codecFactory = GenericTextEditor::findMatchingCodecFactory(extension);

    if(codecFactory == 0)
        return false;

    GenericTextEditorDocument* document = 0;
    if(!isDocAlreadyShowing(docName, document) || isAllowDoubleDisplay())
    {
        document = new GenericTextEditorDocument(this);
        ITextEditorCodec* codec = codecFactory->create(document, docName);
        document->setCodec(codec);
        document->displayText(docName, text, optionalData);
        QMdiSubWindow *window = addSubWindow(document);
        window->setWindowIcon(QIcon(codec->getDocumentIcon()));
        document->showMaximized();
        QTabBar* tabBar = findChildren<QTabBar*>().at(0);
        tabBar->setTabToolTip(findChildren<QMdiSubWindow*>().size() - 1, docName);    
    }
    else
    {
        document->getCodec()->setOptionalData(optionalData);
        document->getCodec()->onDisplayRequest();
        setActiveSubWindow(qobject_cast<QMdiSubWindow*>(document->window()));
        document->setFocus(Qt::ActiveWindowFocusReason);
    }

    moveToForeground();

    connect(document, SIGNAL(textChanged()), document, SLOT(documentWasModified()));
    mActSave->setEnabled(false);

    return true;
}
//-----------------------------------------------------------------------------------------
bool GenericTextEditor::displayTextFromFile(QString filePath, QString optionalData)
{
    ITextEditorCodecFactory* codecFactory = GenericTextEditor::findMatchingCodecFactory(filePath);

    if(codecFactory == 0)
       return false;    
    
    GenericTextEditorDocument* document = 0;
    if(!isPathAlreadyShowing(filePath, document) || isAllowDoubleDisplay())
    {
        document = new GenericTextEditorDocument(this);
        ITextEditorCodec* codec = codecFactory->create(document, filePath);
        document->setCodec(codec);
        document->displayTextFromFile(QFile(filePath).fileName(), filePath, optionalData);
        QMdiSubWindow *window = addSubWindow(document);
        window->setWindowIcon(QIcon(codec->getDocumentIcon()));
        document->showMaximized();
        QTabBar* tabBar = findChildren<QTabBar*>().at(0);
        tabBar->setTabToolTip(findChildren<QMdiSubWindow*>().size() - 1, QFile(filePath).fileName());   
    }
    else
    {
        document->getCodec()->setOptionalData(optionalData);
        document->getCodec()->onDisplayRequest();
        setActiveSubWindow(qobject_cast<QMdiSubWindow*>(document->window()));
        document->setFocus(Qt::ActiveWindowFocusReason);
    }

    moveToForeground();   

    connect(document, SIGNAL(textChanged()), document, SLOT(documentWasModified()));
    
    mActSave->setEnabled(false);

    return true;
}