Exemple #1
0
bool QtopiaPrintEngine::newPage()
{
    flushPage();
    clearPage();
    ++(d_func()->pageNumber);
    return true;
}
Exemple #2
0
bool QtopiaPrintEngine::begin(QPaintDevice *)
{
    Q_D(QtopiaPrintEngine);
    Q_ASSERT_X(d->printerState == QPrinter::Idle, "QtopiaPrintEngine", "printer already active");

    // Create a new off-screen monochrome image to handle the drawing process.
    QSize size = paperRect().size();
    if ( d->pageImage )
	delete d->pageImage;
    d->pageImage = new QImage( size, QImage::Format_RGB32 );
    if ( !(d->pageImage) )
	return false;

    // Recreate the paint engine on the new image.
    delete d->_paintEngine;
    d->_paintEngine = 0;
    d->paintEngine()->state = state;

    // Begin the paint process on the image.
    if (!d->paintEngine()->begin(d->pageImage))
        return false;

    // Clear the first page to all-white.
    clearPage();

    // Clear the print buffer and output the image header.
    d->buffer.clear();
    d->writeG3FaxHeader();

    // The print engine is currently active.
    d->printerState = QPrinter::Active;
    return true;
}
Exemple #3
0
/*!
	Initializes translator.
 */
bool NesCpuTranslator::init()
{
	m_labels = recLabels;
	memMapping = new AnonymousMemMapping(BufferSize);
	if (!memMapping->address())
		return false;
	m_codeBuffer = (u8 *)memMapping->address();
	m_masm = new MacroAssembler(m_codeBuffer, BufferSize);

	m_checkAlertAfterInstruction = false;

	// compile some needed stubs
	mEntryPoint();
	mTranslateCaller();
	mSync();
	mAlertHandler();
#if defined(ENABLE_DEBUGGING)
	mDebugStep();
#endif

	// mark pages "used before" here to force page clearing
	m_pageUsedMask = (1<<NesNumOfCpuPages)-1;
	for (int i = 0; i < NesNumOfCpuPages; i++)
		clearPage(i);

	m_lastRecompilationInRam = 0;
	return true;
}
void wpPartitions::initializePage()
{
  listWidget->clear();
  listWidget->addItem(new ListItem(tr("Manual partitioning"), tr("You will have to do the partitioning with a partition-manager manually. This way you have more possibilities to adjust the installation to your needs. The automatic partitioning lacks several features and is only a (computer generated) list of some possible options."), "partitionmanager", "manual"));
  listWidget->addItem(new ListItem(tr("Already partitioned"), tr("If you have already partitioned for the installation and don't want to start a partition manager then select this."), "drive-harddisk", "already"));
  listWidget->setCurrentRow(0);
  clearPage();
}
Exemple #5
0
static int
clearPage_HelpScreen (void) {
  HelpPageEntry *page = getPage();

  if (!page) return 0;
  clearPage(page);
  return 1;
}
Exemple #6
0
static void
destruct_HelpScreen (void) {
  if (pageTable) {
    while (pageCount) clearPage(&pageTable[--pageCount]);
    free(pageTable);
  }

  initializePageTable();
}
Exemple #7
0
void NesCpuTranslator::checkTranslationBoundary(int pageIndex)
{
	int previousPageIndex = (pageIndex-1) & 7;
	int numUsedFromNextPage = m_numOfDataUsedFromNextPage[previousPageIndex];
	if (numUsedFromNextPage) {
		bool same = true;
		for (int i = 0; i < numUsedFromNextPage; i++) {
			if (nesCpuReadDirect((pageIndex << 13) + i) !=
				m_dataUsedFromNextPage[previousPageIndex][i]) {
				same = false;
				break;
			}
		}
		m_numOfDataUsedFromNextPage[previousPageIndex] = 0;
		if (!same)
			clearPage(previousPageIndex);
	}
}
Exemple #8
0
bool ImageItem::reload()
{
    // destroy the old image instance
    clearPage();

    //qDebug("Begin Load Image %s!\n", name().toStdString().c_str());
    // Reconstruct the image by key
    if (name() == EMPTY_BACKGROUND)
    {
        data_.reset(new QImage(EMPTY_BACKGROUND_WIDTH,
                               EMPTY_BACKGROUND_HEIGHT,
                               QImage::Format_ARGB32));
        QColor white(255, 255, 255);
        data_->fill(white.rgba());
    }
    else
    {
        data_.reset(new QImage(name()));
    }
    //qDebug("End Load Image! %s\n", name().toStdString().c_str());

    if (data_->isNull())
    {
        // if the image is broken, display the warning map
        data_->load(":/images/invalid.png");
    }

    private_info_.reset();
    dirty_    = false;
    actualSize() = data_->size();

    // reset the render setting
    // TODO. Use default rotation value
    RenderSetting setting;
    setting.setContentArea(QRect(0, 0, actualSize().width(), actualSize().height()));
    setting.setRotation(ROTATE_0_DEGREE);
    setRenderSetting(setting);
    return true;
}
Exemple #9
0
void ChatView::notify(const Notify &notify)
{
  const int type = notify.type();

  if (type == Notify::ClearChat) {
    if (m_id == notify.data().toByteArray())
      clearPage();
  }
  else if (type == Notify::FeedData || type == Notify::FeedReply) {
    const FeedNotify &n = static_cast<const FeedNotify &>(notify);
    if (n.channel() == id() || n.channel() == ChatClient::id() || (n.channel() == ChatClient::serverId() && n.feed() == FEED_NAME_ACL)) {
      const QVariantMap json = WebBridge::feed(n);
      if (json.isEmpty())
        return;

      if (!m_loaded)
        m_pendingFeeds.enqueue(json);
      else
        emit feed(json);
    }
  }
}
Exemple #10
0
void ImageItem::resetData(const QImage &new_data)
{
    clearPage();
    data_.reset(new QImage(new_data));
}
void SpectralLibraryMatchResults::updateContextMenu(Subject& subject, const std::string& signal,
                                                    const boost::any& value)
{
   ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value);
   if (pMenu == NULL)
   {
      return;
   }

   // only add actions if there are some results
   if (mpTabWidget->count() > 0)
   {
      bool isSessionItem(false);
      if (dynamic_cast<SessionExplorer*>(&subject) != NULL)
      {
         std::vector<SessionItem*> items = pMenu->getSessionItems();
         if (items.size() > 1)                                        // make sure only one item selected
         {
            return;
         }
         DockWindow* pWindow = getDockWindow();
         if (items.front() != pWindow)                             // make sure it's the results window
         {
            return;
         }
         isSessionItem = true;
      }

      QObject* pParent = pMenu->getActionParent();

      // add separator
      QAction* pSeparatorAction = new QAction(pParent);
      pSeparatorAction->setSeparator(true);
      pMenu->addAction(pSeparatorAction, SPECTRAL_LIBRARY_MATCH_RESULTS_SEPARATOR_ACTION);

      QAction* pClearAction = new QAction("&Clear", pParent);
      pClearAction->setAutoRepeat(false);
      pClearAction->setStatusTip("Clears the results from the current page");
      VERIFYNR(connect(pClearAction, SIGNAL(triggered()), this, SLOT(clearPage())));
      pMenu->addAction(pClearAction, SPECTRAL_LIBRARY_MATCH_RESULTS_CLEAR_RESULTS_ACTION);

      QAction* pAutoClearAction = new QAction("&AutoClear", pParent);
      pAutoClearAction->setAutoRepeat(false);
      pAutoClearAction->setCheckable(true);
      pAutoClearAction->setStatusTip("Enable/disable clearing existing results before adding new results");
      ResultsPage* pPage = dynamic_cast<ResultsPage*>(mpTabWidget->currentWidget());
      if (pPage != NULL)
      {
         pAutoClearAction->setChecked(pPage->getAutoClear());
         VERIFYNR(connect(pAutoClearAction, SIGNAL(toggled(bool)), pPage, SLOT(setAutoClear(bool))));
         pMenu->addAction(pAutoClearAction, SPECTRAL_LIBRARY_MATCH_RESULTS_AUTOCLEAR_ACTION);
      }

      QAction* pExpandAllAction = new QAction("&Expand All", pParent);
      pExpandAllAction->setAutoRepeat(false);
      pExpandAllAction->setStatusTip("Expands all the results nodes on the current page");
      VERIFYNR(connect(pExpandAllAction, SIGNAL(triggered()), this, SLOT(expandAllPage())));
      pMenu->addAction(pExpandAllAction, SPECTRAL_LIBRARY_MATCH_RESULTS_EXPAND_ALL_ACTION);

      QAction* pCollapseAllAction = new QAction("&Collapse All", pParent);
      pCollapseAllAction->setAutoRepeat(false);
      pCollapseAllAction->setStatusTip("Collapses all the results nodes on the current page");
      VERIFYNR(connect(pCollapseAllAction, SIGNAL(triggered()), this, SLOT(collapseAllPage())));
      pMenu->addAction(pCollapseAllAction, SPECTRAL_LIBRARY_MATCH_RESULTS_COLLAPSE_ALL_ACTION);

      QAction* pDeleteTabAction = new QAction("&Delete Page", pParent);
      pDeleteTabAction->setAutoRepeat(false);
      pDeleteTabAction->setStatusTip("Deletes the current page");
      VERIFYNR(connect(pDeleteTabAction, SIGNAL(triggered()), this, SLOT(deletePage())));
      pMenu->addAction(pDeleteTabAction, SPECTRAL_LIBRARY_MATCH_RESULTS_DELETE_PAGE_ACTION);

      if (isSessionItem == false)
      {
         QAction* pLocateAction = new QAction("&Locate Signatures", pParent);
         pLocateAction->setAutoRepeat(false);
         pLocateAction->setStatusTip("Locates the selected Signatures in the spatial data view");
         VERIFYNR(connect(pLocateAction, SIGNAL(triggered()), this, SLOT(locateSignaturesInScene())));
         pMenu->addAction(pLocateAction, SPECTRAL_LIBRARY_MATCH_RESULTS_LOCATE_ACTION);
         QAction* pCreateAverageAction = new QAction("&Create average Signature", pParent);
         pCreateAverageAction->setAutoRepeat(false);
         pCreateAverageAction->setStatusTip("Creates an average Signature from the selected "
            "Signatures in the spatial data view");
         VERIFYNR(connect(pCreateAverageAction, SIGNAL(triggered()), this, SLOT(createAverageSignature())));
         pMenu->addAction(pCreateAverageAction, SPECTRAL_LIBRARY_MATCH_RESULTS_CREATE_AVERAGE_ACTION);
      }
   }
}
Exemple #12
0
void wpPartMan::initializePage()
{
  clearPage();
}
Exemple #13
0
void Gui::exportAs(QString &suffix)
{
    float pageWidth = page.meta.LPub.page.size.value(0);
    float pageHeight = page.meta.LPub.page.size.value(1);
    if (page.meta.LPub.resolution.type() == DPI) {
        // convert to MM
        pageWidth = int(inches2centimeters(pageWidth)*10);
        pageHeight = int(inches2centimeters(pageHeight)*10);
    }

    QPrinter::PaperSize paperSize = QPrinter::PaperSize();
    QPrinter::Orientation orientation = QPrinter::Orientation();
    int bestSize;
    bestSize = bestPaperSizeOrientation(pageWidth,pageHeight,paperSize,orientation);

    // Convert closest page size to pixels for bounding rect

    if (orientation == QPrinter::Portrait) {
        pageWidth = paperSizes[bestSize].width/10.0;  // in centimeters
        pageHeight = paperSizes[bestSize].height/10.0; // in centimeters
    } else {
        pageWidth = paperSizes[bestSize].height/10.0;  // in centimeters
        pageHeight = paperSizes[bestSize].width/10.0; // in centimeters
    }

    if (resolutionType() == DPI) {
        pageWidth = centimeters2inches(pageWidth);
        pageHeight = centimeters2inches(pageHeight);
    }
    pageWidth *= resolution();
    pageHeight *= resolution();
    if (resolutionType() == DPCM) {
        pageWidth = centimeters2inches(pageWidth);
        pageHeight = centimeters2inches(pageHeight);
    }

    QGraphicsScene scene;
    LGraphicsView  view(&scene);

    int savePageNumber = displayPageNum;

    QFileInfo fileInfo(curFile);
    QString   baseName = fileInfo.baseName();

    //clearPage(KpageView,KpageScene);

    // Strangeness needing to warm up the process?

    QImage image(pageWidth,pageHeight,QImage::Format_ARGB32);

    for (displayPageNum = 1;
            displayPageNum <= maxPages && displayPageNum < 6;
            displayPageNum++) {

        qApp->processEvents();

        QRect  bounding(0,0,pageWidth,pageHeight);
        view.setGeometry(bounding);
        view.setRenderHints(QPainter::Antialiasing |
                            QPainter::TextAntialiasing |
                            QPainter::SmoothPixmapTransform);
        view.scale(1.0,1.0);
        QRectF boundingRect(0.0,0.0,pageWidth,pageHeight);
        view.centerOn(boundingRect.center());
        drawPage(&view,&scene,true);

        QPainter painter;
        painter.begin(&image);
        view.render(&painter);
        QString pn = QString("%1") .arg(displayPageNum);
        image.save(baseName + "_page_" +pn + suffix);
        painter.end();

        clearPage(&view,&scene);
    }

    for (displayPageNum = 1; displayPageNum <= maxPages; displayPageNum++) {

        qApp->processEvents();

        QRect  bounding(0,0,pageWidth,pageHeight);
        view.setGeometry(bounding);
        view.setRenderHints(QPainter::Antialiasing |
                            QPainter::TextAntialiasing |
                            QPainter::SmoothPixmapTransform);
        view.scale(1.0,1.0);
        QRectF boundingRect(0.0,0.0,pageWidth,pageHeight);
        view.centerOn(boundingRect.center());
        drawPage(&view,&scene,true);

        QPainter painter;
        painter.begin(&image);
        view.render(&painter);
        QString pn = QString("%1") .arg(displayPageNum);
        image.save(baseName + "_page_" +pn + suffix);
        painter.end();

        clearPage(&view,&scene);
    }
    displayPageNum = savePageNumber;
    drawPage(KpageView,KpageScene,false);
}
Exemple #14
0
void Gui::printToFile()
{
    float pageWidth = page.meta.LPub.page.size.value(0);
    float pageHeight = page.meta.LPub.page.size.value(1);

    if (page.meta.LPub.resolution.type() == DPI) {
        // convert to MM
        pageWidth = int(inches2centimeters(pageWidth));
        pageHeight = int(inches2centimeters(pageHeight));
    }
    pageWidth  *= 10;  // convert to mm
    pageHeight *= 10;

    QPrinter::PaperSize paperSize = QPrinter::PaperSize();
    QPrinter::Orientation orientation = QPrinter::Orientation();
    int bestSize;
    bestSize = bestPaperSizeOrientation(pageWidth,pageHeight,paperSize,orientation);

    // Convert closest page size to pixels for bounding rect

    if (orientation == QPrinter::Portrait) {
        pageWidth = paperSizes[bestSize].width/10.0;  // in centimeters
        pageHeight = paperSizes[bestSize].height/10.0; // in centimeters
    } else {
        pageWidth = paperSizes[bestSize].height/10.0;  // in centimeters
        pageHeight = paperSizes[bestSize].width/10.0; // in centimeters
    }

    if (resolutionType() == DPI) {
        pageWidth = centimeters2inches(pageWidth);
        pageHeight = centimeters2inches(pageHeight);
    }

    pageWidth *= resolution();
    pageHeight *= resolution();

    if (resolutionType() == DPCM) {
        pageWidth = centimeters2inches(pageWidth);
        pageHeight = centimeters2inches(pageHeight);
    }

    QFileInfo fileInfo(curFile);
    QString   baseName = fileInfo.baseName();

    QString fileName = QFileDialog::getSaveFileName(
                           this,
                           tr("Print File Name"),
                           QDir::currentPath() + "/" + baseName,
                           tr("PDF (*.pdf)\nPDF (*.PDF)"));

    if (fileName == "") {
        return;
    }

    fileInfo.setFile(fileName);

    QString suffix = fileInfo.suffix();
    if (suffix == "") {
        fileName += ".pdf";
    } else if (suffix != ".pdf" && suffix != ".PDF") {
        fileName = fileInfo.path() + "/" + fileInfo.completeBaseName() + ".pdf";
    }

    QPrinter printer(QPrinter::ScreenResolution);
    printer.setOutputFileName(fileName);
    printer.setOrientation(orientation);
    printer.setPaperSize(paperSize);
    printer.setPageMargins(0,0,0,0,QPrinter::Inch);
    printer.setFullPage(true);

    QPainter painter;
    painter.begin(&printer);

    int savePageNumber = displayPageNum;

    QGraphicsScene scene;
    LGraphicsView  view(&scene);

    QRectF boundingRect(0.0,0.0,pageWidth,pageHeight);
    QRect  bounding(0,0,pageWidth,pageHeight);
    view.setMinimumSize(pageWidth,pageHeight);
    view.setMaximumSize(pageWidth,pageHeight);
    view.setGeometry(bounding);
    view.setSceneRect(boundingRect);
    view.setRenderHints(QPainter::Antialiasing |
                        QPainter::TextAntialiasing |
                        QPainter::SmoothPixmapTransform);

    view.scale(1.0,1.0);
    view.centerOn(boundingRect.center());
    clearPage(&view,&scene);

    for (displayPageNum = 1; displayPageNum <= maxPages; displayPageNum++) {

        qApp->processEvents();

        drawPage(&view,&scene,true);
        view.render(&painter);
        clearPage(&view,&scene);

        if (maxPages - displayPageNum > 0) {
            printer.newPage();
        }
    }
    painter.end();
    displayPageNum = savePageNumber;
    drawPage(KpageView,KpageScene,false);
}
Exemple #15
0
void wpHdMap::initializePage()
{
  clearPage();
}
Exemple #16
0
OutputPaneManager::OutputPaneManager(QWidget *parent) :
    QWidget(parent),
    m_widgetComboBox(new QComboBox),
    m_closeButton(new QToolButton),
    m_minMaxAction(0),
    m_minMaxButton(new QToolButton),
    m_nextAction(0),
    m_prevAction(0),
    m_lastIndex(-1),
    m_outputWidgetPane(new QStackedWidget),
    m_opToolBarWidgets(new QStackedWidget),
    m_minimizeIcon(":/core/images/arrowdown.png"),
    m_maximizeIcon(":/core/images/arrowup.png"),
    m_maximised(false)
{
    setWindowTitle(tr("Output"));
    connect(m_widgetComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changePage()));

    m_clearAction = new QAction(this);
    m_clearAction->setIcon(QIcon(QLatin1String(Constants::ICON_CLEAN_PANE)));
    m_clearAction->setText(tr("Clear"));
    connect(m_clearAction, SIGNAL(triggered()), this, SLOT(clearPage()));

    m_nextAction = new QAction(this);
    m_nextAction->setIcon(QIcon(QLatin1String(Constants::ICON_NEXT)));
    m_nextAction->setText(tr("Next Item"));
    connect(m_nextAction, SIGNAL(triggered()), this, SLOT(slotNext()));

    m_prevAction = new QAction(this);
    m_prevAction->setIcon(QIcon(QLatin1String(Constants::ICON_PREV)));
    m_prevAction->setText(tr("Previous Item"));
    connect(m_prevAction, SIGNAL(triggered()), this, SLOT(slotPrev()));

    m_minMaxAction = new QAction(this);
    m_minMaxAction->setIcon(m_maximizeIcon);
    m_minMaxAction->setText(tr("Maximize Output Pane"));

    m_closeButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
    connect(m_closeButton, SIGNAL(clicked()), this, SLOT(slotHide()));

    QVBoxLayout *mainlayout = new QVBoxLayout;
    mainlayout->setSpacing(0);
    mainlayout->setMargin(0);
    m_toolBar = new Utils::StyledBar;
    QHBoxLayout *toolLayout = new QHBoxLayout(m_toolBar);
    toolLayout->setMargin(0);
    toolLayout->setSpacing(0);
    toolLayout->addWidget(m_widgetComboBox);
    m_clearButton = new QToolButton;
    toolLayout->addWidget(m_clearButton);
    m_prevToolButton = new QToolButton;
    toolLayout->addWidget(m_prevToolButton);
    m_nextToolButton = new QToolButton;
    toolLayout->addWidget(m_nextToolButton);
    toolLayout->addWidget(m_opToolBarWidgets);
    toolLayout->addWidget(m_minMaxButton);
    toolLayout->addWidget(m_closeButton);
    mainlayout->addWidget(m_toolBar);
    mainlayout->addWidget(m_outputWidgetPane, 10);
    mainlayout->addWidget(new Core::FindToolBarPlaceHolder(this));
    setLayout(mainlayout);

    m_buttonsWidget = new QWidget;
    m_buttonsWidget->setLayout(new QHBoxLayout);
    m_buttonsWidget->layout()->setContentsMargins(5,0,0,0);
    m_buttonsWidget->layout()->setSpacing(4);

}
OutputPaneManager::OutputPaneManager(QWidget *parent) :
    QWidget(parent),
    m_titleLabel(new QLabel),
    m_manageButton(new OutputPaneManageButton),
    m_closeButton(new QToolButton),
    m_minMaxAction(0),
    m_minMaxButton(new QToolButton),
    m_nextAction(0),
    m_prevAction(0),
    m_outputWidgetPane(new QStackedWidget),
    m_opToolBarWidgets(new QStackedWidget),
    m_minimizeIcon(QLatin1String(":/core/images/arrowdown.png")),
    m_maximizeIcon(QLatin1String(":/core/images/arrowup.png")),
    m_maximised(false),
    m_outputPaneHeight(0)
{
    setWindowTitle(tr("Output"));

    m_titleLabel->setContentsMargins(5, 0, 5, 0);

    m_clearAction = new QAction(this);
    m_clearAction->setIcon(QIcon(QLatin1String(Constants::ICON_CLEAN_PANE)));
    m_clearAction->setText(tr("Clear"));
    connect(m_clearAction, SIGNAL(triggered()), this, SLOT(clearPage()));

    m_nextAction = new QAction(this);
    m_nextAction->setIcon(QIcon(QLatin1String(Constants::ICON_NEXT)));
    m_nextAction->setText(tr("Next Item"));
    connect(m_nextAction, SIGNAL(triggered()), this, SLOT(slotNext()));

    m_prevAction = new QAction(this);
    m_prevAction->setIcon(QIcon(QLatin1String(Constants::ICON_PREV)));
    m_prevAction->setText(tr("Previous Item"));
    connect(m_prevAction, SIGNAL(triggered()), this, SLOT(slotPrev()));

    m_minMaxAction = new QAction(this);
    m_minMaxAction->setIcon(m_maximizeIcon);
    m_minMaxAction->setText(tr("Maximize Output Pane"));

    m_closeButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE_DOCUMENT)));
    connect(m_closeButton, SIGNAL(clicked()), this, SLOT(slotHide()));

    connect(ICore::instance(), SIGNAL(saveSettingsRequested()), this, SLOT(saveSettings()));

    QVBoxLayout *mainlayout = new QVBoxLayout;
    mainlayout->setSpacing(0);
    mainlayout->setMargin(0);
    m_toolBar = new Utils::StyledBar;
    QHBoxLayout *toolLayout = new QHBoxLayout(m_toolBar);
    toolLayout->setMargin(0);
    toolLayout->setSpacing(0);
    toolLayout->addWidget(m_titleLabel);
    toolLayout->addWidget(new Utils::StyledSeparator);
    m_clearButton = new QToolButton;
    toolLayout->addWidget(m_clearButton);
    m_prevToolButton = new QToolButton;
    toolLayout->addWidget(m_prevToolButton);
    m_nextToolButton = new QToolButton;
    toolLayout->addWidget(m_nextToolButton);
    toolLayout->addWidget(m_opToolBarWidgets);
    toolLayout->addWidget(m_minMaxButton);
    toolLayout->addWidget(m_closeButton);
    mainlayout->addWidget(m_toolBar);
    mainlayout->addWidget(m_outputWidgetPane, 10);
    mainlayout->addWidget(new Core::FindToolBarPlaceHolder(this));
    setLayout(mainlayout);

    m_buttonsWidget = new QWidget;
    m_buttonsWidget->setLayout(new QHBoxLayout);
    m_buttonsWidget->layout()->setContentsMargins(5,0,0,0);
    m_buttonsWidget->layout()->setSpacing(4);
}
Exemple #18
0
BOOLEAN mergeRuns(FILE ** sorted, int pagesize, int availableBuffers, FileList currentFiles, int * passes, int * runs, int totalRecordCount){
	RecordHeap rHeap;
	Buffer * bufferNodes;
	int bufferIndex;

/*Determine max files that can be merged in a run*/
/*That is available buffers -1 for the output buffer*/
/*This is also the output buffer indes*/
	int outputBuffIndex = availableBuffers -1;

/*Buffer array (of buffer nodes) where size of which is the number
of buffers available to store in memory*/
	bufferNodes = calloc(availableBuffers, sizeof(Buffer));
	if(!bufferNodes){
		fprintf(stderr, "Error: Failed to allocate buffer array\n");
		return FALSE;
	}

/*Allocate memory for record arrays for each buffer*/
	for(bufferIndex = 0; bufferIndex < availableBuffers; bufferIndex++){
		initBuffer(&bufferNodes[bufferIndex], pagesize);
	}

/*Initialise priority queue
It's size is the amount of files that can be merged in a run*/
/*outputBuffIndex is the last index in the buffer array*/
	if(initHeap(&rHeap, outputBuffIndex * pagesize) == FALSE){
		return FALSE;
	}

/*while more merging required, (more than 1 temporary file)*/
/*go through a pass*/
	while(currentFiles.fileCount > 1){
		int runCount = 0;
		/*Define first file to be the start of the file linked list*/
		FileNode * firstFileForRun = currentFiles.fileHeadNode;

		/*Run file list, is the files to be merged in the next pass*/
		FileList runFileList;/*= calloc(1, sizeof(FileList));*/

		float runsInPassFloat = ((float)currentFiles.fileCount/(float)(availableBuffers-1));
		int runsInPass = ceil(runsInPassFloat);

		initFileList(&runFileList);


/*while still merging required for pass*/
/*go through a run*/
		while(runCount < runsInPass){
			int buffersInUse = 0;
			int bufferIndex = 0;
			int init = 0;
			FileNode * currentRunFile = firstFileForRun;
			FILE * outputFile;
			
/*create new temp file for merge run, written to when output buffer is full*/
			if((outputFile = tmpfile()) == NULL){
				fprintf(stderr, "Error: Failed to create output temporary file for run\n");
				return FALSE;
			}

/*add file pointer to the file list for the next pass*/
			addFile(&runFileList,outputFile);

/*Read in pages from current files to buffers*/
			for(bufferIndex = 0; bufferIndex < outputBuffIndex; bufferIndex++){
				int recordPageIndex;
/*fill buffer with records from file*/
				if(currentRunFile->fp != NULL){
					for(recordPageIndex = 0; recordPageIndex < pagesize; recordPageIndex++){
						/*read in record*/
						Record record;
						if(fread(&record, sizeof(Record), 1, currentRunFile->fp) == 1){
							/*add record to page (records array)*/
							init++;
							if(addRecord(&bufferNodes[bufferIndex], record, pagesize, recordPageIndex) == FALSE)
								return FALSE;
		/*add record index to heap*/
							if(addToHeap(&rHeap, &bufferNodes[bufferIndex], recordPageIndex) == FALSE)
								return FALSE;
						}
		/*else reached file end*/
						else{
							/*temp file will be automatically deleted by the system*/
							fclose(currentRunFile->fp);
							currentRunFile->fp = NULL;
							/*removeFile(currentFiles, currentRunFile);*/
							/*add blank records*/
							/*int blankRecordCount;
							for(blankRecordCount = recordCount; blankRecordCount < pagesize; blankRecordCount++){
								int recordPageIndex = addBlankRecord(&bufferNodes[bufferIndex], pagesize);
								
								if(recordPageIndex < 0)
									return FALSE;
							}*/
							break;
						}
					}
					bufferNodes[bufferIndex].fileNode = currentRunFile;
					buffersInUse++;
					currentRunFile = currentRunFile->nextFileNode;
					if (currentRunFile == NULL)
						break;
				}
				else
					break;
			}
/*set firstFileForRun for next run*/
			firstFileForRun = currentRunFile;

/*while all buffers are not empty (there is still records in pages in
some buffer not including the output buffer)*/
			while(buffersInUse > 0 && rHeap.count > 0){
/*keep getting min record and writing to output buffer*/
/*get smallest record*/
				RecordIndex minIndex = removeMinHeap(&rHeap);
				if(minIndex.guildID == 0)
					return FALSE;
/*move smallest record from main buffer memory to output buffer*/
/*add record to output buffer*/
				addRecord(&bufferNodes[outputBuffIndex],
					minIndex.buff->pageRecords[minIndex.pgIndex], pagesize, bufferNodes[outputBuffIndex].recordCount);
/*remove the same record from original buffer*/
				removeRecord(minIndex.buff, minIndex.pgIndex);
/*if output buffer is full, write page to file*/
				if(bufferNodes[outputBuffIndex].recordCount == pagesize){
/*write page to file*/
					int written;
					written = fwrite(bufferNodes[outputBuffIndex].pageRecords, sizeof(Record),
						pagesize, outputFile);
					if(written !=pagesize){
						fprintf(stderr, "Error: Failed to write to output file, wrote %i records\n",written);
						return FALSE;
					}

					/*clear page in output buffer*/
					clearPage(&bufferNodes[outputBuffIndex], pagesize);
				}

/*if original buffer is empty, read in another page*/
				if(minIndex.buff->recordCount == 0){
					int recordPageIndex;
/*fill buffer with records from file*/
					for(recordPageIndex = 0; recordPageIndex < pagesize; recordPageIndex++){
						Record record;
						if(minIndex.buff->fileNode->fp != NULL){
							if(fread(&record, sizeof(Record), 1, minIndex.buff->fileNode->fp) == 1){
		/*add record to page (records array)*/
								if(addRecord(minIndex.buff, record, pagesize, recordPageIndex) == FALSE)
									return FALSE;
		/*add record index to heap*/
								if(addToHeap(&rHeap, minIndex.buff, recordPageIndex) == FALSE)
									return FALSE;
							}
		/*else reached file end*/
							else{
								/*temp file will be automatically deleted by the system*/
								fclose(minIndex.buff->fileNode->fp);
								minIndex.buff->fileNode->fp = NULL;
								/*removeFile(currentFiles, minIndex.buff->fileNode);*/
								break;
							}
						}
					}
				}
/*if buffer is still empty, then 0 records were read in,
therefore file is empty and the buffer is now free*/
				if(minIndex.buff->recordCount == 0)
					/*decrement buffers in use counter*/
					buffersInUse--;
			}

/*All files for run have been fully read*/
/*Write out records still in output buffer*/
			if(bufferNodes[outputBuffIndex].recordCount > 0){
/*Output buffer page was not full*/
				int i = 0;
				for(i = 0; i < pagesize; i++){
					if(bufferNodes[outputBuffIndex].pageRecords[i].GuildID != 0){
						fwrite(&bufferNodes[outputBuffIndex].pageRecords[i],
							sizeof(Record), 1, outputFile);
						removeRecord(&bufferNodes[outputBuffIndex], i);
					}
				}
			}
			/*Rewind outfile for future merge*/
			rewind(outputFile);
			runCount++;
		}
		/*set runFileListas new current file list*/
		freeFileNode(&currentFiles);
		currentFiles = runFileList;
		*passes = *passes+1;
		*runs = *runs + runCount;
		printf("Pass %i resulted in %i runs\n",*passes,runCount);
	}


/*FileList will contain link to only 1 temporary binary file*/
	if(currentFiles.fileCount != 1){
		fprintf(stderr, "Error: Number of files:%i is invalid\n",currentFiles.fileCount);
		return FALSE;
	}
	*sorted = currentFiles.fileHeadNode->fp;

	/*free allocated memory*/

	for(bufferIndex = 0; bufferIndex < availableBuffers; bufferIndex++){
		freeBuffer(&bufferNodes[bufferIndex]);
	}
	free(bufferNodes);

	freeHeap(&rHeap);

	freeFileNode(&currentFiles);

	/*free(currentFiles);*/

	return TRUE;
}