void main( int argc, char *argv[] ) { int fp; HelpHeader header; unsigned i; if( argc != 2 ) { printf( "Usage: helpdump <help file name>\n" ); return; } fp = open( argv[1], O_RDONLY | O_BINARY ); if( fp == -1 ) { printf( "Unable to open %s\n", argv[1] ); return; } read( fp, &header, sizeof( HelpHeader ) ); PrintHeader( &header ); read( fp, Buffer, header.str_size ); PrintStrings( Buffer ); read( fp, Buffer, header.datapagecnt * sizeof( uint_16 ) ); PrintItemIndex( &header ); for( i = 0; i < header.indexpagecnt + header.datapagecnt; i++ ) { read( fp, Buffer, HLP_PAGE_SIZE ); PrintPage(); } }
static void DoPrintPrint( void * junk ) /* * Called when print:print button is clicked. * Print all the printable pages and mark them * non-print. */ { wIndex_t x, y; int copy, copies; long noDecoration; if (pageCount == 0) { NoticeMessage( MSG_PRINT_NO_PAGES, _("Ok"), NULL ); return; } wPrefGetInteger( "print", "nodecoration", &noDecoration, 0 ); print_d.CoOrd2Pix = page_d.CoOrd2Pix = mainD.CoOrd2Pix; wSetCursor( wCursorWait ); if (!wPrintDocStart( Title1, pageCount, &copies )) { wSetCursor( wCursorNormal ); return; } if (copies <= 0) copies = 1; for ( copy=1; copy<=copies; copy++) { if ( printOrder == 0 ) { for (x=bm.x0; x<bm.x1; x++) for (y=bm.y1-1; y>=bm.y0; y--) if (!PrintPage( x, y )) goto quitPrinting; } else { for (y=bm.y0; y<bm.y1; y++) for (x=bm.x0; x<bm.x1; x++) if (!PrintPage( x, y )) goto quitPrinting; } for (y=bm.y0; y<bm.y1; y++) for (x=bm.x0; x<bm.x1; x++) if (BITMAP(bm,x,y)) { if (copy < copies) MarkPage( x, y ); else BITMAP(bm,x,y) = 0; } } quitPrinting: wPrintDocEnd(); wSetCursor( wCursorNormal ); Reset(); /* undraws grid, resets pagecount, etc */ }
bool CPrintFolder::PrintPage(UINT nPage, HDC hDC) { CDCHandle dc(hDC); if (m_clrBackGround != RGB(255,255,255)) { dc.FillSolidRect(&_rectExtents, m_clrBackGround); } return PrintPage(dc, nPage-1) && PrintHeaders(dc, nPage-1); }
// Painting helper void CPrintFolder::DoPaint(CDCHandle dc, CRect& rc, int nCurPage) { dc.SetMapMode(MM_ANISOTROPIC); dc.SetWindowExt(m_rcOutput.right - m_rcOutput.left, m_rcOutput.bottom - m_rcOutput.top); dc.SetWindowOrg(0, 0); dc.SetViewportExt(rc.right - rc.left, rc.bottom - rc.top); dc.SetViewportOrg(rc.left, rc.top); PrePrintPage(nCurPage, dc); PrintPage(nCurPage, dc); PostPrintPage(nCurPage, dc); }
void CvSqlQueryLowerView::DoFilePrint() { CDC dc; CPrintDialog printDlg(FALSE); if (printDlg.DoModal() == IDCANCEL) // Get printer settings from user return; dc.Attach(printDlg.GetPrinterDC()); // Attach a printer DC dc.m_bPrinting = TRUE; CString strTitle; // Get the application title strTitle.LoadString(AFX_IDS_APP_TITLE); DOCINFO di; // Initialise print document details ::ZeroMemory (&di, sizeof (DOCINFO)); di.cbSize = sizeof (DOCINFO); di.lpszDocName = strTitle; BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job // Get the printing extents and store in the m_rectDraw field of a CPrintInfo object CPrintInfo Info; Info.m_rectDraw.SetRect(0,0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); Info.m_bPreview = TRUE; OnBeginPrinting(&dc, &Info); // Call your "Init printing" funtion if (m_nPageWidth > Info.m_rectDraw.Width()) m_nPageWidth = Info.m_rectDraw.Width(); if (m_nPageHeight > Info.m_rectDraw.Height()) m_nPageHeight = Info.m_rectDraw.Height(); while (bPrintingOK) { dc.StartPage(); // begin new page PrintPageHeader(&dc, Info.m_nCurPage); // updates m_nHeaderHeight PrintPageFooter(&dc, Info.m_nCurPage); // updates m_nFooterHeight ASSERT (m_nHeaderHeight >= 0); ASSERT (m_nFooterHeight >= 0); PrintPage(&dc, Info.m_nCurPage); Info.m_nCurPage++; dc.EndPage(); bPrintingOK = ((int)Info.m_nCurPage > m_nbPrintPage) ? FALSE: TRUE; } OnEndPrinting(&dc, &Info); dc.EndDoc(); dc.Detach(); }
void CvSqlQueryLowerView::OnPrint(CDC* pDC, CPrintInfo* pInfo) { // Pre-adjust width and height if (m_nPageWidth > pInfo->m_rectDraw.Width()) m_nPageWidth = pInfo->m_rectDraw.Width(); if (m_nPageHeight > pInfo->m_rectDraw.Height()) m_nPageHeight = pInfo->m_rectDraw.Height(); PrintPageHeader(pDC, pInfo->m_nCurPage); // updates m_nHeaderHeight PrintPageFooter(pDC, pInfo->m_nCurPage); // updates m_nFooterHeight ASSERT (m_nHeaderHeight >= 0); ASSERT (m_nFooterHeight >= 0); PrintPage(pDC, pInfo->m_nCurPage); }
bool RemotePrintJobParent::RecvProcessPage(Shmem&& aStoredPage) { nsresult rv = PrintPage(aStoredPage); // Always deallocate the shared memory no matter what the result. if (!DeallocShmem(aStoredPage)) { NS_WARNING("Failed to deallocated shared memory, remote print will abort."); rv = NS_ERROR_FAILURE; } if (NS_FAILED(rv)) { Unused << SendAbortPrint(rv); } else { Unused << SendPageProcessed(); } return true; }
void CWebSock::OnPageRequest(const CString& sURI) { CString sPageRet; EPageReqResult eRet = OnPageRequestInternal(sURI, sPageRet); switch (eRet) { case PAGE_PRINT: PrintPage(sPageRet); break; case PAGE_DEFERRED: // Something else will later call Close() break; case PAGE_DONE: // Redirect or something like that, it's done, just make sure // the connection will be closed Close(CLT_AFTERWRITE); break; case PAGE_NOTFOUND: default: PrintNotFound(); break; } }
// more.c must print one page, then accept user input for controls // if the user presses space, print an entire page // if the user presses enter, print a line // if the user presses q, quit more.c int main(int argc, char *argv[]) { char c, userInput, tty[64]; int fd, read, i, j; //If we only have "more" as our argument, then we are probably in a pipe, let's handle it // // cat f | more // |_____________| // | // v // stdin = cat f; //we need to read from the terminal AND from cat f // fd = dup(0); //first you need to duplicate your stdin // close(0) // CLOSE 0 so it becomes free on fd table // gettty(tty) //we don't know our tty name, get it // open(tty, 0) //Open it for read, since we closed 0, it will take the place of stdin // // if (argc == 1) { //Let's say we got passed cat f | more, cat f will be our stdin (0) fd = dup(0); //DUPLICATE "cat f" into our file decriptor close(0); //close "cat f" so we can replace it with our terminal gettty(tty); //We need to know what our tty is, get it from our PROC.tty[] open(tty, 0); //Open it for read or "in", since we still need to accept user input } //Otherwise, we have a a file input, and we are probably not piping else { fd = open(argv[1], 0); //Open the file for reading } //Just in case we screw up our fd if (fd < 0) { printf("more: cannot find the file %s\n", argv[1]); return -1; } //When we get here we should have a valid fd open, and be ready to print stuff to the screen while (1) { PrintPage(fd); while (1) { userInput = getc(); switch(userInput) { case '\r': //If we get an enter we need to print just a line and move the screen up PrintLine(fd); break; case ' ': //If we get a space character, print the entire screen. PrintPage(fd); break; case 'q': //If we get a 'q' the user wants to end more printf("\n"); printf("more: quitting...\n\n"); return 0; break; default: break; } } } }
DWORD WINAPI ReadWritePages(LPVOID lpParam ) { //Check if the parameter is NULL if (lpParam == NULL) { return 1; } ThreadData* pData = (ThreadData*)lpParam; //Get the buffer Buffer* pBuffer = pData->pBuffer; //Get the mutex manager STK::CMutexManager* pMutexManager = pData->pMutexManager; //Get the mutex for printing DWORD dwMutexIndex = pData->dwMutexIndex; //Check if the buffer or mutex manager is NULL if ((pBuffer == NULL) || (pMutexManager == NULL)) { return 1; } //The return value int iRet = 0; //Sets a random starting point. srand(GetTickCount()); //Access the page randomly for (DWORD dwIndex = 0; dwIndex < pBuffer->dwPageNumber * 1000; dwIndex++) { //Get the random number DWORD dwRand = rand(); //Get the page number DWORD dwPageNumber = dwRand % pBuffer->dwPageNumber; //Get the page pointer Page *pPage = pBuffer->arrayPage + dwPageNumber; //Lock the page STK::CMutex objMutex (pMutexManager, pPage->dwMutexIndex); if (!objMutex.Lock()) { iRet = 1; break; } //Lock the page again if (!objMutex.Lock()) { iRet = 1; break; } //Check the data integrity bool bNormal = true; for (DWORD dwValueIndex = 0; dwValueIndex < VALUE_NUMBER; dwValueIndex++) { if ((dwValueIndex < (VALUE_NUMBER - 1)) && (pPage->arrayValue[dwValueIndex] != pPage->arrayValue[dwValueIndex+1])) { bNormal = false; break; } } //Print out the page values PrintPage (bNormal, pPage, dwPageNumber, pMutexManager, dwMutexIndex); //Modify the page value for (dwValueIndex = 0; dwValueIndex < VALUE_NUMBER; dwValueIndex++) { SwitchToThread(); pPage->arrayValue[dwValueIndex] = dwRand; } //Unlock the page if (!objMutex.Unlock()) { iRet = 1; break; } //Unlock the page again if (!objMutex.Unlock()) { iRet = 1; break; } } return iRet; }
/** * \brief Simulates the output * * This routine simulates the movement of paper in the engine. * The first part of the loop determines if a sheet can be lifted from a paper tray, * the second part determines if the sheet has reached the output tray. */ void PMSOutput(void * dummy) { PMS_TyPage *ThisPage = NULL; /* pointer the the current page being checked */ PMS_TyPage LastPage; /* pointer the the last sheet that was picked up */ PMS_TyPageList *tmpPageList; /* local pagelist pointer */ unsigned int uCurrentPageGap; /* the gap between sheet pickup */ unsigned int uLastPickUp; /* the time the last sheet was pickup from inout tray */ unsigned int uPagesInMotion; /* the number of sheets travelling in the system */ UNUSED_PARAM(void *, dummy); uCurrentPageGap = 0; uLastPickUp = 0; uPagesInMotion = 0; g_eJobState = PMS_Waiting_For_Page; /* loop until the RIP has quit */ while(g_eJobState != PMS_AllJobs_Completed) /* pages in motion OR RIP active */ { /* keep a local copy of the pagelist for local manipulation */ tmpPageList = g_pstPageList; if(g_tSystemInfo.uUseEngineSimulator) { /* small delay to prevent total processor consumption */ PMS_Delay(PAGECHECK_FREQUENCY); } else if(tmpPageList==NULL) { /* wait for a page to arrive */ PMS_WaitOnSemaphore_Forever(g_semPageQueue); } /* walk through all the pages */ while (tmpPageList!=NULL) { ThisPage = tmpPageList->pPage; if(g_tSystemInfo.uUseEngineSimulator) PMS_Delay(PAGECHECK_FREQUENCY); /* is there a page waiting to start travelling */ if (ThisPage->eState==PMS_CHECKEDIN) { /* work out the gap between last page and this page */ uCurrentPageGap = EngineGetInterpageGap(ThisPage, &LastPage); /* has enough time passed since the last sheet pickup */ if(PMS_TimeInMilliSecs() > (uLastPickUp + uCurrentPageGap)) { /* pick up sheet, mark as printing */ ThisPage->eState = PMS_PRINTING; ThisPage->ulPickupTime = PMS_TimeInMilliSecs(); ThisPage->ulOutputTime = ThisPage->ulPickupTime + EngineGetTravelTime(g_pstPageList->pPage); uPagesInMotion++; /* PMS_SHOW("Pickup Sheet: %d - output: %d\n", ThisPage->ulPickupTime, ThisPage->ulOutputTime); */ /* record some stats about this page incase next page is different a requires a stall in paper path */ LastPage.uTotalPlanes = ThisPage->uTotalPlanes; /* record pickup time in global */ uLastPickUp = PMS_TimeInMilliSecs(); } break; } /* check sheets that are printing */ if (ThisPage->eState==PMS_PRINTING) { /* has a sheet reached output bin */ if(PMS_TimeInMilliSecs() > (ThisPage->ulOutputTime)) { /* print sheet */ PrintPage(ThisPage); ThisPage->eState = PMS_COMPLETE; /* PMS_SHOW("Output Sheet: %d\n", PMS_TimeInMilliSecs()); */ /* send page done at this point*/ OIL_PageDone(ThisPage); /* remove sheet from system, RemovePage is protected against other threads */ RemovePage(ThisPage); uPagesInMotion--; /* page list modified so break out and start again */ break; } } /* move onto the next page */ tmpPageList = tmpPageList->pNext; } if(uPagesInMotion == 0) { /* set the job state to indicate pms is waiting for next page. */ g_eJobState = PMS_Waiting_For_Page; } else { /* set the job state to indicate pms has received a page and is processing it. */ g_eJobState = PMS_Page_In_Progress; } /* if RIP has finished ripping and page list is empty means all jobs are printed */ if((g_eRipState == PMS_Rip_Finished) && (g_pstPageList == NULL)) { g_eJobState = PMS_AllJobs_Completed; } } return; }
status_t PrinterDriver::PrintJob ( BFile *jobFile, // spool file BNode *printerNode, // printer node, used by OpenTransport() to find & load transport add-on BMessage *jobMsg // job message ) { print_file_header pfh; status_t status; BMessage *msg; int32 page; uint32 copy; uint32 copies; const int32 passes = 2; fJobFile = jobFile; fPrinterNode = printerNode; fJobMsg = jobMsg; if (!fJobFile || !fPrinterNode) return B_ERROR; if (fPrintTransport.Open(fPrinterNode) != B_OK) { return B_ERROR; } if (fPrintTransport.IsPrintToFileCanceled()) { return B_OK; } // read print file header fJobFile->Seek(0, SEEK_SET); fJobFile->Read(&pfh, sizeof(pfh)); // read job message fJobMsg = msg = new BMessage(); msg->Unflatten(fJobFile); // We have to load the settings here for Dano/Zeta because they don't store // all fields from the message returned by config_job in the job file! PrinterSettings::Read(printerNode, msg, PrinterSettings::kJobSettings); if (msg->HasInt32("copies")) { copies = msg->FindInt32("copies"); } else { copies = 1; } // force creation of Report object Report::Instance(); // show status window StatusWindow* statusWindow = new StatusWindow(passes, pfh.page_count, this); status = BeginJob(); fPrinting = true; for (fPass = 0; fPass < passes && status == B_OK && fPrinting; fPass++) { for (copy = 0; copy < copies && status == B_OK && fPrinting; copy++) { for (page = 1; page <= pfh.page_count && status == B_OK && fPrinting; page++) { statusWindow->NextPage(); status = PrintPage(page, pfh.page_count); } // re-read job message for next page fJobFile->Seek(sizeof(pfh), SEEK_SET); msg->Unflatten(fJobFile); } } status_t s = EndJob(); if (status == B_OK) status = s; delete fJobMsg; // close status window if (Report::Instance()->CountItems() != 0) { statusWindow->WaitForClose(); } if (statusWindow->Lock()) { statusWindow->Quit(); } // delete Report object Report::Instance()->Free(); return status; }
//--------------------------------------------------------------------------- void __fastcall TFormMain::PrintBtnClick(TObject *Sender) { int trips; // number of times to print from first to last int dups; // number of copies of each page to print each time int firstpg; int lastpg; bool needsnewpg=false; // make sure the current page is saved before printing pages[TabSet1->TabIndex]->Text = Memo1->Text; if (!PrintDialog1->Execute()) return; // user did not press OK // if we're not collating, we only go from the first page to last page once // but each time through we print duplicates of each page. if (!PrintDialog1->Collate) { trips = 1; dups = PrintDialog1->Copies; } // if we're collating, we go from the first page to the last page // multiple times but only print one duplicate each time through. else { trips = PrintDialog1->Copies; dups = 1; } // user has selected to print all pages... if (PrintDialog1->PrintRange == prAllPages) { firstpg = 1; lastpg = 5; } // ...or a range of pages else { firstpg = PrintDialog1->FromPage; lastpg = PrintDialog1->ToPage; } // Initialize print job Printer()->BeginDoc(); // Title to appear in the print manager and network print banners Printer()->Title = "C++Builder Printer Example"; for (int x=0; x<trips; x++) // for each pass for (int y=firstpg-1; y<lastpg; y++) // for each page for (int z=0; z<dups; z++) // for each dup of the page { if (needsnewpg) // page 1 does not need a page break Printer()->NewPage(); PrintPage(y); // print the page needsnewpg = true; // subsequent pages need page breaks } Printer()->EndDoc(); }