|
The code below, would must to show the count the number of pages in a PCL file. But, don´t show. Why?? What is wrong??
//----------------------------------
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main (int argc, char **argv) {
FILE *InputFile;
char ch, EndTag, tag[2], *InputFileName;
int n, BlockSize, Pages, Copies, Quiet;
unsigned long FileSize, FilePos;
BlockSize =0; Pages =0; FileSize =0; FilePos =0;
Copies =0; Quiet =1;
InputFileName = NULL;
// Parse command line parameters
for(n = 1; n <= argc - 1; n++) {
if(! memcmp(argv[n], "-h", 2)) {
printf("Error");
exit(0);
} else if(! memcmp(argv[n], "-v", 2))
Quiet = 0;
else if(argv[n][0] == '-') {
fprintf(stderr, "-- Parameter incorrect: '%s'.\n",
argv[n]);
exit(1);
} else
InputFileName = argv[n];
}
if(InputFileName == NULL) {
fprintf(stderr, "-- Must enter a file name.\n \" Use 'pclcount -h' to get help.\n");
exit(1);
}
// Try to open the input file
if(! (InputFile = fopen(InputFileName, "r"))) {
fprintf(stderr, "--Error opening file: %s\n", argv[1]);
exit(-1);
};
// Get the file size, to show statistics if '-v' is passed
if(! Quiet) {
fseek(InputFile, 0, SEEK_END);
FileSize = ftell(InputFile);
fseek(InputFile, 0, SEEK_SET);
}
while(fread(&ch, 1, 1, InputFile)) {
switch(ch) {
case 12:
// Found FormFeed: increments page counter
Pages ++;
break;
case 27:
// Found <esc>
fread(tag, 2, 1, InputFile);
if(! (memcmp(tag, "*b", 2) && memcmp(tag, "(s", 2) &&
memcmp(tag, ")s", 2) && memcmp(tag, "&p", 2))) {
/*
Detect the operators:
<esc>*b###W -> Start of Binary Block
<esc>(s###W -> Start of Characters Description
Block
<esc>)s###W -> Start of Fonts Description Block
<esc>&p###X -> Start of non-printable Characters
Block
In these operators, '###' is the size of
respective block.
*/
// Define the block end-character
EndTag = memcmp(tag, "&p", 2) ? 'W' : 'X';
do {
fread(&ch, 1, 1, InputFile);
if((ch >= '0') && (ch <= '9')) {
// A number was read: it's part of block size
BlockSize = 10 * BlockSize + ch - '0';
}
} while ((ch >= '0') && (ch <='9'));
if(ch == EndTag) {
// The operator ends with 'W': it's a espected operator
// Do a 'seek' to jump the block
fseek(InputFile, BlockSize, SEEK_CUR);
FilePos = ftell(InputFile);
// Refreshing status message here (don't do it all the time) don't slow the process
if(! Quiet) printf("Processing... %ld of %ld bytes (%ld%%)\r", FilePos, FileSize, (FilePos * 100) / FileSize);
}
// Not a espected operator: reinitialize BlockSize
BlockSize = 0;
} else if(! (memcmp(tag, "&l", 2))) {
// The operador <esc>&l###X informs the number of copies ('###') solicited
n = 0;
for(ch = '0'; (ch >= '0') && (ch <= '9');
fread(&ch, 1, 1, InputFile)) {
n = 10 * n + ch - '0';
}
if(ch == 'X') {
// The operator ends with 'X' (as espected). Gets the number of copies
Copies = n;
}
}
break;
}
}
fclose(InputFile);
if(Quiet)
// Case '-v' wasn't passed, prints only total of pages of the job
printf("%d\n", Pages * Copies);
else
printf("Processing... Done. \n \" Number of Pages.......: %d \n \" Number of Copies......: %d \n \" Total of Pages........: %d \n", Pages, Copies,Pages * Copies);
return(0);
}
Thank´s!
raf-sp
raf-sp@bol.com.br
|
|
|
|
|
raf-sp wrote:
But, don´t show. Why?? What is wrong??
So what does it show? Is it off by one? Does the while loop not find any ASCII 12 characters? Remember that "page eject" in PCL can be any of the following commands:
RESET (EcE)
PAGE SIZE (Ec&l#A)
PAGE LENGTH (Ec&l#P)
ORIENTATION CHANGE (Ec&l#0)
PAPER SOURCE CONTROL SEQUENCE (Ec&l0H) with a value of zero
PAPER SOURCE (Ec&l#H)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
This program should to show the number of pages a file it be printed in format HP-PCL.
Does the while loop not find any ASCII 12 characters?
No, no finds.
raf-sp
|
|
|
|
|
How about using fopen(InputFileName, "rb") instead?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I tried but, did not function.
Thank you!
raf-sp
|
|
|
|
|
If you could provide me with a link to a .pcl file, I can provide you with a code snippet to do what you require.
- DC
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Ok, Thank´s!!
I write a text file in "Notepad" and send to print to file in a PCL5 Printer Driver. Then, I execute the program for count pages pcl and it does not work.
|
|
|
|
|
Heyz, can somebuddy tell me how can I grab sound from a modem thru MCI or some other API. regards
|
|
|
|
|
How do I check if "\\Computer42" exists.
I want to check before I work on some files that are located on a share on that machine.
|
|
|
|
|
How about NetServerGetInfo(L"Computer42", 100, ...) ? It will return ERROR_BAD_NETPATH if the machine does not exist.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thank you. It worked very well.
/Mathias S.
|
|
|
|
|
Currently I have drag recntangle working but problem occurs while I have Left mouse click down and scroll at the same time. At that point it would loose track of the mouse location because it doesn't include scroll in to the factor.
2 ways I can see to do this
In OnMouseMove track where the scroll window is moving. But the problem with that is Mouse isn't moving so it's not calling the function.
Or
In OnKeyDown update the movling location. The only problem I see with that there is no CPoint mouse location passed over to OnKeyDown and I have to capture OnMouseWheel also.
|
|
|
|
|
Hello everbody,
I created a hashtable in a file to search the contents of some database.
I use the standard operations (fseek, fread etc) to access the file.
Everything works ok, as long as my indexfile is read from harddisk. (There are more then 200000 entry in it and it takes less then a second to search for an specific entry).
However, if i put this on cd-rom its about 2800% !!! slower. Especially if my search returns more then one result.
Is there anyone around here who knows how to optimize a file for cd-rom access?
Sorry for my english, what i am trying to say is:
How has i file to be constructed so that it can be read from cd-rom real fast?
Any help would be highly appreciated.
|
|
|
|
|
Gunnar Mätzler wrote:
...it and it takes less then a second to search for an specific entry).
However, if i put this on cd-rom its about 2800% !!! slower.
So every second of HDD time equates to 29 seconds of CD time? It's true that CD-ROM drives will be slower than HD drives, but how much slower depends on a lot of factors. I suggest reading this guide to see what all is going on.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Every time you ask for data on a CD that is not right after the last data you asked for the CD will need 1 second to position. So you need to figure out how you can read your table in order.
Suggestion: Get Knuth's "The art of computer programing" out, and look for the sections on searching from tape.
|
|
|
|
|
Thank you
My Project Files:
MainFrm.cpp (MainFrm.h)
Outlook.cpp (Outlook.h)
OutlookDoc.cpp (OutlookDoc.h)
OutlookListView.cpp (OutlookListView.h)
OutlookTreeView.cpp (OutlookTreeView.h)
OutlookView.cpp (OutlookView.hh)
==================== From MainFrm.cpp (Fragment of Code) ====================
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
UNREFERENCED_PARAMETER(lpcs);
if (!m_wndSplitter1.CreateStatic(this, 1, 2))
return FALSE;
if (!m_wndSplitter1.CreateView(0, 0, RUNTIME_CLASS(COutlookView), CSize(0, 0), pContext))
return FALSE;
if (!m_wndSplitter2.CreateStatic(&m_wndSplitter1, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitter1.IdFromRowCol(0, 1)))
return FALSE;
if (!m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(COutlookTreeView), CSize(0, 0), pContext))
return FALSE;
if (!m_wndSplitter2.CreateView(0, 1, RUNTIME_CLASS(COutlookListView), CSize(0, 0), pContext))
return FALSE;
m_wndSplitter1.SetColumnInfo(0, 150, 0);
m_wndSplitter2.SetColumnInfo(0, 150, 0);
return TRUE;
}
==================== From OutlookTreeView.cpp (Fragment of Code) ====================
void COutlookTreeView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
const COLORREF rgb = RGB(255, 0, 255);
TV_INSERTSTRUCT tvstruct;
TCHAR rgszItems[][20] = { _T("Mail Box"), _T("Calendar"), _T("Deleted Items"), _T("Inbox"), _T("Journal"), _T("Notes"), _T("Outbox"), _T("Sent Items") };
VERIFY(m_ilTree.Create(IDB_BITMAP3, 16, 8, rgb));
GetTreeCtrl().SetImageList(&m_ilTree, TVSIL_NORMAL);
HTREEITEM hParent = NULL;
for (int nIndex = 0; nIndex < (sizeof(rgszItems) / sizeof(rgszItems[0])); nIndex++)
{
tvstruct.hParent = nIndex == 0 ? NULL : hParent;
tvstruct.hInsertAfter = TVI_LAST;
tvstruct.item.iImage = nIndex;
tvstruct.item.iSelectedImage = nIndex;
tvstruct.item.pszText = rgszItems[nIndex];
tvstruct.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;
HTREEITEM hItem = GetTreeCtrl().InsertItem(&tvstruct);
hParent = hParent == NULL ? hItem : hParent;
}
GetTreeCtrl().Expand(GetTreeCtrl().GetRootItem(), TVE_EXPAND);
}
==================== From OutlookDoc.cpp (Fragment of Code) ====================
BEGIN_MESSAGE_MAP(COutlookDoc, CDocument)
//{{AFX_MSG_MAP(COutlookDoc)
ON_COMMAND(ID_TOGGLE_TREE, OnToggleTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void COutlookDoc::OnToggleTree()
{
AfxMessageBox(_T("OnToggleTree"));
//???????????????????? CODE FOR ToggleTree ??????????????
}
|
|
|
|
|
Using GetFileTime(),can get the last-modified time of a file.i need actually the elapsed time.how can i get?
|
|
|
|
|
Monisankar wrote:
i need actually the elapsed time
Elapsed time? I can only assume you mean last_modified_time - create_time. Is that correct?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Actyally i need the intervals that have elapsed since 1601 and want to get this value as unsigned long.What should i do?
|
|
|
|
|
FILETIME ftCreate,
ftLocal;
GetFileTime(hFile, &ftCreate, ...);
FileTimeToLocalFileTime(&ftCreate, &ftLocal);
FILETIME ftSystem;
SYSTEMTIME st;
GetSystemTime(&st);
SystemTimeToFileTime(&st, &ftSystem); Now you can compare ftLocal with ftSystem .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Yesterday I learnt how to fetch text manipulate it and write it back to the screen with the code below
void CReverseView::OnReverse()
{
// TODO: Add your command handler code here
CEdit &edit = GetEditCtrl();
CString strText;
edit.GetWindowText(strText);
_strrev(strText); // do something
edit.SetWindowText(strText);
GetDocument()->SetModifiedFlag(TRUE) ;
}
edit.SetWindowText(strText); replaces all the previous text. with the result of "do something"
Lets say the result of "do something" is xyz.
How do I add "Result is " before showing xyz?
I tried edit.SetWindowText("result is"); but this gets overwritten
Thanks
|
|
|
|
|
Since strText is a CString object, you can simply use the += operator.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thank you!
|
|
|
|
|
Hello!
I am a absolute beginner!
I found a source here about HOOK - realized with DLL. I use the DLL in my app to wait for key_down. But I have problem. I want my app to come to the top, when the CALLBACK-procedure has identified a key press. How can I do it easily?
Thank you very much for code samples!
|
|
|
|
|
I have about 40 controls on a dialog that use OnCtlColor to paint themselves the same background color as the bitmapped background they sit on top of. You can page through multiple pages of data very fast, and the program kept crashing. I noticed while watching task manager, that it was eating incredible amounts of memory on paging, and removed the OnCtlColor stuff, and it stopped eating memory and crashing. Here's what the code looks like:
<br />
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) <br />
{<br />
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);<br />
<br />
switch (pWnd->GetDlgCtrlID()) <br />
{<br />
case IDC_FIELD01:<br />
pDC->SetBkColor(RED);<br />
pDC->SetTextColor(WHITE);<br />
hbr = CreateSolidBrush(RED);<br />
break;<br />
...etc...<br />
return hbr;<br />
}<br />
<br />
What is the best way to handle that problem, and anybody know why it would eat so much memory?
Thanx,
Rick
|
|
|
|
|