예제 #1
0
CString CHexEditView::create_header(const char *fmt, long pagenum)
{
	bool bDiskFile = GetDocument()->pfile1_ != NULL;
	bool bDevice = bDiskFile && GetDocument()->IsDevice();
	CString retval;                     // Return string
	CString sin = fmt;                  // Rest of input string
	int pos;                            // Posn in string of param.
	CString ss;                         // Temporary string
	CHexFileList *pfl = theApp.GetFileList();
	int ii = -1;
	if (GetDocument()->pfile1_ != NULL) // make sure there is a disk file (pfl requires a disk file name)
		ii = pfl->GetIndex(GetDocument()->pfile1_->GetFilePath());

	CFileStatus status;                 // Get status of file (for times)
	if (bDiskFile && !bDevice)
		GetDocument()->pfile1_->GetStatus(status);

	while ((pos = sin.Find("&")) != -1)
	{
		retval += sin.Left(pos);
		if (sin.GetLength() > pos + 1)
		{
			switch (toupper(sin[pos+1]))
			{
			case 'F':
				if (bDiskFile)
					retval += GetDocument()->pfile1_->GetFileName();
				break;
			case 'A':
				if (bDevice)
					retval += GetDocument()->pfile1_->GetFileName();
				else if (bDiskFile)
					retval += GetDocument()->pfile1_->GetFilePath();
				break;
			case 'P':
				ss.Format("%ld", long(pagenum));
				retval += ss;
				break;
			case 'D':
				retval += print_time_.Format("%x");
				break;
			case 'T':
				retval += print_time_.Format("%X");
				break;
			case 'N':
				retval += print_time_.Format("%#c");
				break;
			case 'C':
				if (bDiskFile && !bDevice)
					retval += status.m_ctime.Format("%c");
				break;
			case 'M':
				if (bDiskFile && !bDevice)
					retval += status.m_mtime.Format("%c");
				break;
#if 0 // Since we have the file open the last access time is now so don't bother with this one
			case 'U':
				if (bDiskFile && !bDevice)
					retval += status.m_atime.Format("%c");
				break;
#endif
			case 'G':
				if (ii > -1)
					retval += pfl->GetData(ii, CHexFileList::CATEGORY);
				break;
			case 'K':
				if (ii > -1)
					retval += pfl->GetData(ii, CHexFileList::KEYWORDS);
				break;
			case 'X':
				if (ii > -1)
					retval += pfl->GetData(ii, CHexFileList::COMMENTS);
				break;
			default:
			case '&':
				retval += sin[pos+1];
			}
			sin = sin.Mid(pos+2);
		}
		else
		{
			sin.Empty();
			break;
		}
	}
	retval += sin;

	return retval;
}