Пример #1
0
BOOL PathNameEx::CreateLocation()
{
	PORTNOTETRACE("other","PathNameEx::CreateLocation - do nothing");
#ifndef EXCLUDE_FROM_XARALX
	if (!IsValid())
		return FALSE;
	
	// We'll walk the location string from left to right - if we come across non-existent directories,
	// we create them
	String_256			strLocation = GetLocation(FALSE);
	String_256			strDirPath = drivename;
	INT32					nPos =  drivename.Length(); // start after the drivename
	while( nPos < strLocation.Length() )
	{
		while( ( strLocation[nPos] != chPathSep ) && ( nPos < strLocation.Length() ) )
		{
			strDirPath += strLocation[nPos];
			nPos++;
		}
		// strDirPath has been added a directory, we check if it exists
		
		if (_access((TCHAR*) strDirPath, 0) == -1) // not found, try to create the directory
		{
			if (_mkdir((TCHAR*) strDirPath))
			{
#ifdef _DEBUG
				TCHAR szMsg[256];
				TCHAR szError[128];
				switch (errno)
				{
					case EACCES:
						camStrcpy(szError, "access denied (EACCES)");
						break;
					case ENOENT:
						camStrcpy(szError, "path not found (ENOENT)");
						break;
					default:
						wsprintf(szError, "errno = %d", errno);
				}
				wsprintf(szMsg, "Create directory %s failed, %s", strDirPath, szError);
				ERROR3(szMsg);
#endif
				return FALSE;
			}
		}
		strDirPath += chPathSep; // add a backslash in case there are further subdirectories  
		nPos++; // move to the next position
	}
#endif
	return TRUE;
}
Пример #2
0
String_32::String_32(const wxString& wxs)
{
	*(text = fixedbuf) = 0;
	length = FIX_LEN_BUFSIZE;
	ERROR3IF(wxs.Len() >= length, "String_32::String_32 overflow");
	camStrcpy(text, (LPCTSTR)wxs);
}
Пример #3
0
void String_32::CopyConstruct( const StringBase &other )
{
	*(text = fixedbuf) = 0;
	length = FIX_LEN_BUFSIZE;
	ERROR3IF((const TCHAR*) other == 0, "StringBase to be copied has not been ALLOCated");
	ERROR3IF(camStrlen((const TCHAR*) other) >= length,
				"Constructed String_32 not large enough to hold StringBase copy");
	camStrcpy(text, (const TCHAR*) other);
}
Пример #4
0
// Create & join an Item.
Item::Item(const TCHAR* s, INT32 ps, ArgType t)
{
	camStrcpy(str = new TCHAR[camStrlen(s) + 1], s);
	pos = ps;
	type = t;
	next = 0;
	if (tail) tail = tail->next = this;
		else head = tail = this;
}
Пример #5
0
String_32::String_32(const TCHAR* psz)
{
	*(text = fixedbuf) = 0;
	length = FIX_LEN_BUFSIZE;
	if (psz != 0)
	{
		ERROR3IF(camStrlen(psz) >= length, "String_32::String_32 overflow");
		camStrcpy(text, psz);
	}
}
Пример #6
0
void Error::SetErrorSerious( const TCHAR* errstring )
{
	// this must succeed. In particular it must NOT cause any other errors or ENSUREs
	ErrorID = 0; 
	ModuleID = 0;
	InSetError = 0;
	ErrStatus = ERRORSTAT_TEXT;
	ErrorHasBeenReported = FALSE;
	camStrcpy( ErrorString, errstring );
}
Пример #7
0
void CDECL Error::TraceTime (TCHAR * t)
{
	TCHAR buf[256];
#if !defined(EXCLUDE_FROM_XARLIB)
	CamProfile::GetTimeString(buf, 256);
#else
	camStrcpy(buf, _T("unknown"));
#endif
	TraceAll(_T("[%s] %s"), buf, t);
}
Пример #8
0
String_32::String_32(UINT32 resID, UINT32 hinst)
{
	*(text = fixedbuf) = 0;
	length = FIX_LEN_BUFSIZE;
	if (!Load(resID, hinst))
	{	
		ERROR3("String resource failed to load");
		TCHAR buf[128];
		camSnprintf(buf, 128, TEXT("<%X:%X>"), (INT32) resID, (INT32) hinst);
		camStrcpy(text, (camStrlen(buf) <= 32) ? buf : TEXT("!"));
	}
}
Пример #9
0
void Error::SetError(UINT32 number, const TCHAR* errstring, UINT32 module)
{
	static TCHAR BASED_CODE LastResort[] = wxT("Cannot perform SetError (1)");
	// We now check for a real recursive call. Should only happen if we can't get translate
	// an ID to an error string. Perhaps if we're really low on memory. We must then set the
	// minimum acceptable error string...
	if (InSetError)
	{
		TRACE(_T("SetError really has been called recursively (1)\n"));
		RalphErrorID =ErrorID = _R(IDE_EX_BADOP); // should have it's own, but...
		ErrStatus = ERRORSTAT_TEXT;
		ErrorHasBeenReported=FALSE;
		ModuleID = module;
		camStrcpy( ErrorString, LastResort );
		return;
	}
	InSetError++;

// Andy has stubbed this code out as it caused problems, e.g.
// 'save changes' dialog after a GP fault had been caught made the dialog have the 'save
// changes' buttons, with the GP fault text
#if 0
	if (!ErrorHasBeenReported)
	{
		// ENSURE(FALSE, "Recursive SetError call"); IMHO this is pointless - Alex
		TRACE( _T("SetError called twice: ID = %u: %s\n"), number, errstring);
		InSetError--;
		return;
	}
#endif

	RalphErrorID = ErrorID = number;
	camStrcpy(ErrorString, errstring);
	ModuleID = module;
	ErrStatus = ERRORSTAT_TEXT;
	ErrorHasBeenReported = FALSE;
	TRACE( _T("Setting error: ID = %u: %s\n"), ErrorID, ErrorString);
	InSetError--;
}                          
Пример #10
0
/********************************************************************************************

  >	INT32 HTMLExportFilter::Write(TCHAR* pcToWrite, CCLexFile* pfileToWrite, TCHAR* pcBuffer)

	Author:		Graham_Walmsley (Xara Group Ltd) <*****@*****.**>
	Created:	9/4/97
	Inputs:		pcToWrite		The string to write
				pfileToWrite	The file to write to (may be NULL)
				pcBuffer		The text buffer to write to (may be NULL)

	Returns:	The number of TCHARs written
	Purpose:	Writes the specified string to the file, or the text buffer,
				or both, or neither.

				This function returns the number of TCHARS written. So you
				can call this function first with all parameters NULL to find out
				the length of the text buffer you need, then set up that text buffer,
				then call this function again to write to that text buffer.

				Note that this should be the *only* function that actually writes
				to the file. All other write functions must call this one. That's
				because this function handles the word wrapping.

  Notes:		This is how the word wrapping works:

				First this function writes out the string passed to it (e.g. "<HTML>").
				It does not put any EOLs in the middle of this string.

				Then it checks to see if word wrapping is turned on (from our 
				member flag m_fShouldWordWrap).

				If so, it checks to see if the number of characters written on the
				line so far is greater than the word wrap limit.

				If so, this function puts an EOL line after the string that has
				been written.

				Note that, if you write an end of line string ("\r\n") directly to
				the write function without calling WriteEOL, the word wrapping
				will not work properly.


********************************************************************************************/
INT32 HTMLExportFilter::Write(TCHAR* pcToWrite, CCLexFile* pfileToWrite, TCHAR* pcBuffer)
{
	//If we've been passed a NULL pointer, then simply write nothing
	if (pcToWrite==NULL)
		return 0;

	//If we have a file, then write to it
	if (pfileToWrite)
		pfileToWrite->write(pcToWrite, camStrlen(pcToWrite));

	//If we have a text buffer, then write to it
	if (pcBuffer)
	{
		//We want to start writing at the NULL character where the text
		//buffer ends at the moment.
		
		//So find the length of the buffer
		INT32 lBufLen=camStrlen(pcBuffer);

		//And start writing at the NULL character
		camStrcpy(pcBuffer+lBufLen*sizeof(TCHAR), pcToWrite);
	}

	//So, the number of characters written is equal to the length of the string
	INT32 lCharsWritten= camStrlen(pcToWrite);

	//Now, if we should be doing word wrapping
	if (m_fShouldWordWrap)
	{
		//Then update the number of characters on this line
		m_lCharsOnThisLine+=lCharsWritten;

		//And if we have now exceeded the maximum number of characters
		//that should be written on this line
		if (m_lCharsOnThisLine > m_lWordWrap)
		{
			//Then write out an end of line
			//This will also reset m_lCharsOnThisLine to zero
			lCharsWritten+=WriteEOL(pfileToWrite, pcBuffer);
		}
	}

	//And return the number of characters written
	return lCharsWritten;
}
Пример #11
0
void Error::SetError(UINT32 number, UINT32 module)
{
	static TCHAR BASED_CODE LastResort[] = _T("Cannot perform SetError (2)");
	// We now check for a real recursive call. Should only happen if we can't get translate
	// an ID to an error string. Perhaps if we're really low on memory. We must then set the
	// minimum acceptable error string...
	if (InSetError)
	{
		TRACE(_T("SetError really has been called recursively (2)\n"));
		ErrorID = _R(IDE_EX_BADOP); // should have it's own, but...
		ErrStatus = ERRORSTAT_TEXT;
		ErrorHasBeenReported=FALSE;
		ModuleID = module;
		camStrcpy( ErrorString, LastResort );
		return;
	}
	InSetError++;
	if (!ErrorHasBeenReported)
	{
		// ENSURE(FALSE, "Recursive SetError call"); IMHO this is pointless - Alex
		TRACE( _T("SetError called twice: ID = %u  Module = %u\n"), number, module);
		InSetError--;
		return;
	}
	RalphErrorID = ErrorID = number;
	ModuleID = module;
	ErrorString[0] = 0;
	ErrStatus = ERRORSTAT_ID;
	ErrorHasBeenReported = FALSE;
	if (!SmartLoadString(module, ErrorID, ErrorString, 256 * sizeof(TCHAR)) )
	{
		camSnprintf( ErrorString, 256, _T("Error Number %u from module ID %u"), ErrorID, ModuleID );
	}
	
	TRACE( _T("Setting error: ID = %d: \"%s\"\n"), ErrorID, ErrorString);
	InSetError--;
}
Пример #12
0
/**************************************************************************************
>	INT32 StringBase::CCvsprintf(const TCHAR* layout, va_list va)

	Author:		Justin_Flude (Xara Group Ltd) <*****@*****.**>
	Created:	22nd April 1993
	Inputs:		A pointer to the format string, a variable-parameter pointer to the
				arguments to be formatted.
	Returns:	The length of the StringBase once the arguments have been substituted into
				it.
	Purpose:	This private helper function takes the list generated by
				StringBase::BuildList and scans through it, formatting stack-frame
				parameters according to their list entry.  This produces another list,
				this time of formatted parameters, which is then concatenated to
				produce the final output.
	Scope:		Private
***************************************************************************************/
INT32 StringBase::CCvsprintf(const TCHAR* layout, va_list va)
{
/*	if (IsUserName("JustinF"))
		TRACE( _T("CCvsprintf called with format string %s\n"), layout);
*/
	INT32 n = BuildList(layout);
	for (INT32 i = 1; i <= n; i++)
	{
		for (Item* p = Item::head; p; p = p->next)
			if (p->pos != i)
				continue;
			else
			{  	// Found specifier i in the list, so grab from the stack
				// and call wsprintf() to convert to text.  The converted
				// text is put in the temp[] buffer - note the enormous
				// size of this, in accordance with the C standard.
				TCHAR temp[512];
				switch (p->type)
				{
					// type 'c' - single character
					case CHAR_ARG:
#if defined(__WXMSW__)
						camSnprintf( temp, 512, p->str, va_arg(va, TCHAR) );
#else					// TCHARs are promoted to INT32 when passed via ... under GCC
						camSnprintf( temp, 512, p->str, va_arg(va, INT32) );
#endif
						break;
					// type 'd' / 'i' - signed decimal integer
					case SIGNED_INT_ARG:
						camSnprintf(temp, 512, p->str, va_arg(va, INT32));
						break;
					// type 'ld' / 'li' - signed decimal INT32
					case SIGNED_INT32_ARG:
						camSnprintf(temp, 512, p->str, va_arg(va, INT32));
						break;
					// type 'u' - unsigned decimal integer
					case UNSIGNED_INT_ARG:
						camSnprintf(temp, 512, p->str, va_arg(va, UINT32));
						break;
					// type 'lu' / 'lx' / 'lX' - unsigned decimal INT32
					case UNSIGNED_INT32_ARG:
						camSnprintf(temp, 512, p->str, va_arg(va, UINT32));
						break;
					// type 's' - long pointer to array of (constant) char
					case CHAR_POINTER_ARG:
						camSnprintf(temp, 512, p->str, va_arg(va, LPCTSTR));
						break;
					// type 'p' a pointer
					case UINT_PTR_ARG:
						camSnprintf(temp, 512, p->str, va_arg(va, UINT_PTR));
						break;
					// type 'S' - a pointer to a StringBase.  First change the
					// %S format specifier, which is our own, into a sprintf()
					// compatible %s.  Note that the 'S' is always the last
					// character of the format specifier.
					case STRING_POINTER_ARG:
						(p->str)[camStrlen(p->str) - 1] = TEXT('s');
						camSnprintf(temp, 512, p->str, LPCTSTR(va_arg(va, const StringBase*)->text));
						break;
					default:
						break;
				}
				// Replace the format specifier with the formatted text
				delete[] p->str;
				camStrcpy(p->str = new TCHAR[camStrlen(temp) + 1], temp);
				break;
			}
	}
	
	// Concatenate every string in the list, tidy up, and return in "this" string
	*text = 0;
	UINT32 NextChar = 0;
	INT32 Index = 0;
	for (Item* p = Item::head; (p != NULL && NextChar < length) ; p = p->next)
	{
/*		if (camStrlen(text) + camStrlen(p->str) < length)
			camStrcat(text, p->str);
		else
		{
			ENSURE(FALSE, "Call to String::MakeMsg will overflow - text has been truncated");
		}
*/
		for (Index = 0; p->str[Index] != 0 && NextChar < length; Index++)
			text[NextChar++] = p->str[Index];
	}

	if (NextChar > length)
		NextChar = length;
	text[NextChar] = TCHAR('\0');

	delete Item::head;
	return camStrlen(text);
}
Пример #13
0
static void InternalAssert(const TCHAR * AssertDescription, const char * lpszFileName, INT32 nLine, BOOL UseMFC)
{
	if (!UseMFC)
#if defined(__WXMSW__)
		MessageBeep(MB_ICONASTERISK);
#else
		::wxBell();
#endif


#ifdef _ENSURES

	TCHAR				sz[256];
	static TCHAR BASED_CODE szTitle[] = wxT("Ensure Failed!");

	// In Unicode we need to convert the filename to TCHAR
#if 0 != wxUSE_UNICODE
	TCHAR szRealFile[256];
	size_t count = camMbstowcs(szRealFile, lpszFileName, 255);
	if (count == (size_t)-1)
		count = 0;
	szRealFile[count] = (TCHAR)0;
	const TCHAR* lpszRealFile = szRealFile;
#else
	const TCHAR* lpszRealFile = lpszFileName;
#endif

	static TCHAR BASED_CODE szMessage[] = wxT("%s, File %s, Line %d");
	static TCHAR BASED_CODE szMessageNoReason[] = wxT("Error %d@%s");			// note number first

	// get app name or NULL if unknown (don't call assert)
//	const TCHAR		   *pszAppName = wxGetApp().GetAppName();

	if (AssertDescription != NULL)
	{
		camSnprintf(sz, 255,
			szMessage,                       
			AssertDescription, 
			lpszRealFile, 
			nLine);    
	}
	else   
	{
		camSnprintf(sz, 255,
			szMessageNoReason,
			nLine,
			lpszRealFile);
	}
	
#ifdef _DEBUG
//PORTNOTE("other","Remove afxTraceEnabled")
//#ifndef EXCLUDE_FROM_XARALX
//	if (afxTraceEnabled)
#if defined(__WXMSW__)
	{
		// assume the debugger or auxiliary port
		#ifndef _MAC
		::OutputDebugString(sz);
		::OutputDebugString(_T(", "));
		::OutputDebugString(szTitle);
		::OutputDebugString(_T("\n\r"));
		#else
		// Mac version needs them all together
		camStrcat(sz, _T(", "));
		camStrcat(sz,szTitle);
		camStrcat(sz,_T("\n\r"));
		::OutputDebugString(sz);
		#endif
	}
#endif
#endif


	if (AssertBusy > 0)
	{
		// getting assertion while inside an assertion
		//  - it has already been traced, but 
		// break into the debugger (or Dr Watson log)
		DEBUGBREAK;									// else Win32s might die (just beeps)
		return;
	}

	AssertBusy++;

	if ( Error::IsInRenderThread() )
	{
		TRACE( wxT("In RenderThread so clearing up system") );
		Error::RenderThreadReset();
													// Commented out - no problem using wx for render errors
//		UseMFC = FALSE;								// mustn't use MFC for render errors 
	}

	INT32					result;

	TCHAR				RealErrorMsg[256];

	if (UseMFC)
	{
		// use our error handler to report ensures as it is more robust instead of MessageBox
		// The arrangement of buttons is the same as the exception handler dialog, not the same
		// as the original Ensure dialog (which was Abort/Retry/Ignore)
		ErrorInfo Info;

		// try to preserve original error message
		camStrcpy( RealErrorMsg, Error::GetErrorString() );

		Error::SetErrorSerious( sz );			// set error msg (vaping any previous one)
		Info.ErrorMsg = 0;
		Info.Button[0] = _R(IDS_CONTINUE);
		Info.Button[1] = _R(IDS_QUIT);
#ifndef EXCLUDE_FROM_XARALX
		if (IsWin32NT())
		{
#endif
			// only NT can cope with an Abort button
			Info.Button[2] = _R(IDS_ABORT);
			Info.Button[3] = _R(IDS_DEBUG);
#ifndef EXCLUDE_FROM_XARALX
		}
		else
		{
			Info.Button[2] = _R(IDS_DEBUG);
		}
#endif
													// no default button (or Help)
		Info.Cancel = 1;							// Esc = Continue

		result = InformGeneral( ERRORTYPE_ENSURE, &Info );
	}
	else

	{
		CamResource::DoneInit();
		CCamApp::DisableSystem();

		// e.g. if this an MFC assert, don't use our lovely error handler becuase that itself
		// uses MFC. Instead we use good old MessageBox

#if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
		wxWindow	   *pParent = AfxGetApp().GetTopWindow(); 
PORTNOTE("other","Use CInformErrorDialog::GetSafeParent() when implemented")
#ifndef EXCLUDE_FROM_XARALX
		CInformErrorDialog::GetSafeParent();
#endif
#else
		wxWindow	   *pParent = NULL;
#endif

		wxMessageDialog	Dialog( pParent, sz, szTitle, wxICON_HAND | wxYES_NO | wxCANCEL );
		INT32 nCode = Dialog.ShowModal();

		CCamApp::EnableSystem();

		// convert MessageBox return value into a sane button ID
		switch (nCode)
		{
			case wxID_NO:
				result = _R(IDS_ABORT);
				break;
			case wxID_YES:
				result = _R(IDS_DEBUG);
				break;
			case wxID_CANCEL:
			default:
				result = _R(IDS_CONTINUE);
				break;
		}
	}

	AssertBusy--;

	if ((ResourceID)result == _R(IDS_DEBUG))
	{
		DEBUGBREAK;
	}
	// no action on _R(IDS_CONTINUE))
	else if ((ResourceID)result == _R(IDS_QUIT))
	{
		// quit in a slightly nice way
		wxWindow *MainWnd = AfxGetApp().GetTopWindow();
		if( MainWnd && MainWnd->IsShown() )
		{
			MainWnd->Destroy();
		}
	} // drop through
	if (((ResourceID)result == _R(IDS_ABORT)) || ((ResourceID)result == _R(IDS_QUIT)))
	{
		// if no window, try nasty exit
		AfxAbort();
		return; // how did we get here?
	}

	// if we ever get here we just carry on as if nothing happened

PORTNOTE("other","We can never use MFC again")
#ifndef EXCLUDE_FROM_XARALX
	if (UseMFC)
	{
		if (RealErrorMsg[0])
			Error::SetErrorSerious( RealErrorMsg );		// restore previous error msg
		else
			Error::ClearError();
	} 
#endif
#else
	// parameters not used if non-debug
	(void)lpszFileName;
	(void)nLine;
#endif // _ENSURES

}