Пример #1
0
void SFMFile::logCommentSkip(LPCTSTR lpszField, LPCTSTR lpszMoreInfo)
{
	USES_CONVERSION_U8;
	ostrstream sout;
	if(m_bNothingLogged)
	{
		m_bNothingLogged=FALSE;
		sout << "The following possible problem(s) occurred while parsing the file " << T2CA(m_pathName) << "\r\n";
	}

	if(!m_bDidOutputSkippedCommentNotice)
	{
		m_bDidOutputSkippedCommentNotice = TRUE;
		sout << "Sorry, CarlaStudio did not know where to locate one or more comments.\r\n";
		sout << "You will need to copy these 'skipped comments' and paste them where you want them.\r\n";
	}
	sout << "Skipped comment: \"" << T2CU8(lpszField) << "\"\r\n";
	if(lpszMoreInfo)
				sout << "    " << T2CU8(lpszMoreInfo) <<  "\r\n";
	// to do: add line number?
	sout << "\r\n";
#ifndef rde270
	// I'm just not sure if sout.str is going to be null terminated, so do it the long way.
	int nLen = sout.pcount();
	char* pSout = (char*)alloca(nLen + 1);
	strncpy(pSout, sout.str(), nLen);
	pSout[nLen] = '\0';
	CString sError(U82CT(pSout));
#else   // rde270
	CString sError (sout.str(), sout.pcount());
#endif  // rde270
	sout.rdbuf()->freeze(0); // else get a memory leak
	LOG(sError);
}
Пример #2
0
// TODO: add line number to output
void SFMFile::throwParseFailure(LPCTSTR lpszParserName,
								LPCTSTR lpszMarker,
								LPCTSTR lpszField,
								LPCTSTR lpszMoreInfo)
{
	USES_CONVERSION_U8;
	ostrstream sout;

	sout << "The parser " << T2CA(lpszParserName) << " cannot understand ";
	sout << "\n\\" << T2CA(lpszMarker) << " " << T2CA(lpszField) << '\n';
	if(lpszMoreInfo)
		sout << T2CU8(lpszMoreInfo) << '\n';
	sout << "File: " << T2CA(m_pathName) << '\n';
	// to do: add line number?
#ifndef rde270
	// I'm just not sure if sout.str is going to be null terminated, so do it the long way.
	int nLen = sout.pcount();
	char* pSout = (char*)alloca(nLen + 1);
	strncpy(pSout, sout.str(), nLen);
	pSout[nLen] = '\0';
	CString sError(U82CT(pSout));
#else   // rde270
	CString sError (sout.str(), sout.pcount());
#endif  // rde270
	sout.rdbuf()->freeze(0); // else get a memory leak
	throw(sError);
}
Пример #3
0
// TODO: add line number to output
void SFMFile::logParseFailure(LPCTSTR lpszParserName,
								LPCTSTR lpszMarker,
								LPCTSTR lpszField,
								LPCTSTR lpszMoreInfo)
{
	USES_CONVERSION_U8;
	ostrstream sout;

	if(m_bNothingLogged)
	{
		m_bNothingLogged=FALSE;
		sout << "The following possible problem(s) occurred while parsing the file " << T2CA(m_pathName) << "\r\n";
	}

	sout << "The parser " << T2CA(lpszParserName) << " cannot understand ";
	sout << "\r\n\\" << T2CA(lpszMarker) << " " << T2CA(lpszField) << "\r\n";
	if(lpszMoreInfo)
		sout << T2CU8(lpszMoreInfo) << "\r\n";
	// to do: add line number?
#ifndef rde270
	// I'm just not sure if sout.str is going to be null terminated, so do it the long way.
	int nLen = sout.pcount();
	char* pSout = (char*)alloca(nLen + 1);
	strncpy(pSout, sout.str(), nLen);
	pSout[nLen] = '\0';
	CString sError(U82CT(pSout));
#else   // rde270
	CString sError (sout.str(), sout.pcount());
#endif  // rde270
	sout.rdbuf()->freeze(0); // else get a memory leak
	LOG2(sError,_T(""));
}
Пример #4
0
CString CPrintANAProcess::getCommandLine(CProcessStatus& status)
{
    // note: the default directory will be set the dir containing the source file
    //       so that doesn't need to be specified

    strstream sout;
    /*
    Usage: %s [-a] [-c col] [-o outf] inf
    	-a        output analyses only; no decompositions
    	-c col    specifies at which column analyses are to be printed
    	-o outf   specify the output file
    	   inf    specify the input data file
    */
    USES_CONVERSION_U8;
    ifTrueOutputItem(sout, m_bDisplayAnalysesOnly, "-a ");
    sout << "-c " << m_nDisplayBeginColumn << ' ';
    sout << T2CA(status.sANAPath.getShortPath());
    sout << " > " <<  T2CA(m_sLOGPath.getQuotedPath()) << ' ';

    if(status.sANAPath.getShortPath().IsEmpty())
        throw(CProcessFailure(this, _T("Huh?  There was no ANA file path given to the PrintANA process.  You should look into the log of the previous processor (ample or sentrans) and look for errors, then report this as a bug.")));

#ifndef rde270
    // I'm just not sure if sout.str is going to be null terminated, so do it the long way.
    int nLen = sout.pcount();
    char* pSout = (char*)alloca(nLen + 1);
    strncpy(pSout, sout.str(), nLen);
    pSout[nLen] = '\0';
    CString s(U82CT(pSout));
#else   // rde270
    CString s(sout.str(), sout.pcount());
#endif  // rde270

    sout.rdbuf()->freeze(0); // else get a memory leak

    return s;
}
Пример #5
0
void CQuickParseView::OnQuickParseGo()
{
	CWaitCursor wc;

	//---- BRING THE CONTROL FILES UP TO DATE ON THE DISK (added feb 8, 99)
	theApp.getProject()->synchronizeExternals();


	CQuickParseDoc* pDoc = (CQuickParseDoc*)GetDocument();
	UpdateData(TRUE); // get data out of form and into our members
	m_sInput.TrimLeft();
	if(m_sInput.IsEmpty())
		return;

	try
	{
//		sndPlaySound("QuickParse", SND_ASYNC );

		CCarlaLanguage* pSourceLang = pDoc->m_pSourceLang;
		ASSERTX(pSourceLang);
		pSourceLang->prepareMFSForProcessors(); // among other things, get the comment character into the MFS

		CSrcTextProcessingPrefs procPrefs(pSourceLang,
									NULL,
									CProcessingPrefs::kSourceAna);


		CProcessStatus status(	&procPrefs,
								m_sInput,
								pSourceLang,
								pSourceLang->getMFS(),
								NULL,	// output lang
								NULL); // output mfs

		// jdh 3/14/2000 changed to this from some custom code
		if (!status.setupTempDir(pSourceLang->getName()))
			return;	// assumes the user has already been informed

	// added jdh 3/13/2000
		m_bDidRefresh = FALSE; // will be set to TRUE if we refresh
		BOOL bDidGetPreprocessedDicts = status.loadPreprocessedSrcDictsArrayFromLang();
		if(!bDidGetPreprocessedDicts || m_bManualRefreshPending || getNeedDictPreprocessing(status))
			if(!this->preprocessDicts(&status))
				return;

		prepareAmpleProcess();
		loadAmpleOptions();
		m_sOutput = ""; // in case of an exception
		CString sTraceOutput;


		CString sPath;
		sPath.Format(_T("%s\\QP-Ample-Trace.log"), (LPCTSTR)status.getTempDirectory());


#ifndef hab218
		if (m_bTrace && m_bManualParse)
		  {
			m_sTraceMorphs = _T("");
			loadAmpleOptions();
			getManualParse(status, sPath, pSourceLang);
			status.m_sRAWString = m_sInput;
			loadAmpleOptions();
		  }
#endif // hab218
	// DO THE PARSING
		if(!m_bTrace)
		{	// !!! this path is needed if we want to check for errors
			m_pAmpleProcess->processRAWTextString(status, sPath);
		}
		else
		{
			m_pAmpleProcess->processRAWTextString(status, sPath);
		//	m_sOutput = status.m_sRAWString;

			TRY
			{
				CFile log(sPath, CFile::modeRead);
				DWORD sz = log.GetLength();
				if(sz)
				{
					/* If the buffer is ridiculously big (e.g. > 1MB) then the likelyhood
					 * a stack overflow increases - so we truncate early rather than later
					 * let's say that 3 bytes for one UTF8 char is a good guess
					 */
					if (sz > MAX_TRACEOUTPUT * 3)
						sz = MAX_TRACEOUTPUT * 3;
					// on the heap rather than on the stack - stack overflows are easily created
					char* buf = (char *) malloc(sz+2);
					ASSERTX(buf);
					int iReadBytes = log.Read(buf, sz);
					buf[iReadBytes] = '\0'; //terminate it
					USES_CONVERSION_U8;
					sTraceOutput = U82CT(buf);
					free(buf);
				}
				log.Close();
			}
			CATCH( CFileException, e )
			{
#ifdef Before1_04
				checkForFileError(PATH);
#else  // hab 1.04
				checkForFileError(sPath);
#endif // Before1_04
			}
			END_CATCH
		}

		// build the parse part of the answer
		CAmpleResult* pAResult = CAmpleResult::buildResult(status.m_sRAWString);
		if(pAResult)
		{
#ifndef hab218
			m_sOutput += pAResult->getStringRepresentation();
#else //hab218
			m_sOutput = pAResult->getStringRepresentation();
#endif // hab218
			delete pAResult;
		}
		else
			m_sOutput.Format (_T("You have encountered a bug in either CarlaStudio or the Ample DLL.  CarlaStudio could not understand the Ample DLL's answer, which was: %s"), (LPCTSTR)status.m_sRAWString);

		// add the trace part of the answer
		if(m_bTrace)
			m_sOutput += sTraceOutput;

		// do we need to truncate the result?
		TRACE(_T("m_sOutput.GetLength() =%d"), m_sOutput.GetLength());
		if(m_sOutput.GetLength() > MAX_TRACEOUTPUT)
		{
			m_sOutput = m_sOutput.Left(MAX_TRACEOUTPUT);
			m_sOutput += _T("\r\n--Ample's output is too long to fit here.  It has been truncated. ");
		}

		// jdh 3/14/2000 store this set of dictionaries.  we do it only now in so that an error in processing them will be in the user's face
		status.storePreprocessedSrcDictsArrayInLang();

	}
Пример #6
0
// bDisabled is ignored on input; on return, it is false if a "\dis" was found
// at the beginning of the line.
// bEnabled can be null where it isn't relevant
BOOL SFMFile::getField(CString& marker, CString& contents, BOOL *bEnabled)
{
	ASSERTX(fin.is_open());
	const int kBuffSize = 5000;	// CURRENTLY MAX FIELD SIZE TOO!

	// suck up and thow away lines at the beginning of the file that start
	// with the comment character
	if( fin.peek() == m_cCommentChar)
	{
#ifndef rde270
		// these files are not wide characters... therefore CString won't be that helpful
		LPSTR sLeadingComments = (LPSTR)alloca(kBuffSize+2);
		LPSTR x = sLeadingComments;
		LPSTR xStart = x;
#else   // rde270
		CString sLeadingComments;
		LPTSTR x = sLeadingComments.GetBuffer(kBuffSize+2);
		LPTSTR xStart = x;
#endif  // rde270
		do
		{
			fin.getline(x, kBuffSize - (x-xStart), '\n');
			x += fin.gcount();
			if(fin.gcount())
			{
				*(x-1) = '\n'; // put a carriage return in place of the null terminator
				*x = '\0';		// null terminate in case the next getline fails
			}
		} while (fin.good() && fin.gcount() && fin.peek() != '\\');

#ifndef rde270
#else   // rde270
		sLeadingComments.ReleaseBuffer();
#endif  // rde270
	}


#ifndef rde270
	LPSTR sField = (LPSTR)alloca(kBuffSize+2);
	LPSTR buff = sField;
	LPSTR start_buff = buff;
#else   // rde270
	CString sField;
	//LPTSTR start_buff = sField.GetBuffer(kBuffSize+2);
	//LPTSTR buff = start_buff;
	LPTSTR buff = sField.GetBuffer(kBuffSize+2);
	LPTSTR start_buff = buff;
#endif  // rde270

	fin.eatwhite();
	LPSTR b = buff;

	do
	{
		fin.getline(b, kBuffSize - (b-buff), '\n');
		b += fin.gcount();
		if(fin.gcount())
		{
			*(b-1) = '\n'; // put a carriage return in place of the null terminator
			*b = '\0';		// null terminate in case the next getline fails
		}

		//strlen(buff);

	} while (fin.good() && fin.gcount() && fin.peek() != '\\');



	if( (kBuffSize-1) <= (b-buff))	// to long (and thus fin.gcount() == 0)
	{
		CString s;
		s.Format(_T("The file %s appears to have a line which is longer than the maximum of %d characters which Carla Studio can handle.\n"),
					(LPCTSTR)m_pathName, kBuffSize);
		throw(s);

	}

	if(!buff[0])	// end of file
	{
#ifndef rde270
#else
		sField.ReleaseBuffer(-1);
#endif
		return FALSE;
	}

	if(bEnabled)
	{
		*bEnabled = (strncmp(buff, "\\dis", 4) != 0); // if the first marker is '\dis', the rule is disabled
		if(!*bEnabled)
		{
			buff +=4;	// skip the \dis
		}
	}

	// eat white space before the SFM Code (will always be there after a \dis)
	while(*buff && _ismbcspace(*buff))
	{
		*buff='~'; // a hack so that iSpaceLoc, below, isn't set to the space between the "\dis" and marker
		++buff;
	}

	// say we had \dis sr blah, now we want \sr blah
	//  but don't do anything if \dis \sr foo
	if(bEnabled && !*bEnabled && *buff != '\\')
	{
		--buff;
		*buff= '\\';
	}

	BOOL bHaveEnvironment = FALSE;
	if(buff[0] == '/' || (buff[0] == '+' && buff[1] == '/') || /*sentrans*/(buff[0] == '&' && buff[1] == '/'))
	{
		bHaveEnvironment = TRUE;
	}

	USES_CONVERSION_U8;
	// some lines may begin with \dis and be followed by an environment
	// these must be treated special
	if(!bHaveEnvironment && buff[0] != '\\'
		&& bEnabled && *bEnabled)	// can't expect a \ if we started with a \dis
	{	//ASSERTX(FALSE);	//  line didn't have backslash as first non-whitespace char
		static CString sRest;

#ifndef rde270
		sRest = U82CT(start_buff);
#else   // rde270
		sRest = start_buff;
		sField.ReleaseBuffer(-1);
#endif  // rde270

		ostrstream sout;
		sout << "Carla Studio encountered a serious problem while trying to read\n   " << T2CA(m_pathName) << '\n';
		sout << "It was expecting to find an SFM marker, but found instead:\n";
		sout <<  start_buff << '\n';

		// to do: add line number?
#ifndef rde270
		// I'm just not sure if sout.str is going to be null terminated, so do it the long way.
		int nLen = sout.pcount();
		char* pSout = (char*)alloca(nLen + 1);
		strncpy(pSout, sout.str(), nLen);
		pSout[nLen] = '\0';
		CString sError(U82CT(pSout));
#else   // rde270
		CString sError (sout.str(), sout.pcount());
#endif// rde270
		sout.rdbuf()->freeze(0); // else get a memory leak
		throw(sError);
	}


	int iSpaceLoc ;
	if(bHaveEnvironment)
		iSpaceLoc = (buff-start_buff)-1;
	else
	{
		// figure out where the marker ends and field contents begin
#ifndef rde270
		LPSTR lpsz = strpbrk(sField, " \t\n");
		iSpaceLoc = (lpsz == NULL) ? -1 : (int)(lpsz - sField);
#else
		iSpaceLoc = sField.FindOneOf(" \t\n");
#endif
		if(iSpaceLoc <= 1)// [0] should be the slash, [1] at least one char
		{
#ifndef rde270
#else
			sField.ReleaseBuffer(-1);
#endif
			return FALSE;
		}
	}

	if(bHaveEnvironment)
		marker = _T("ENV");
	else
	{
		start_buff[iSpaceLoc] = '\0';
#ifndef rde270
		marker = U82CT(buff + 1); // +1 to skip the slash
#else
		marker = buff + 1; // +1 to skip the slash
#endif
		marker.TrimRight();
	}

#ifndef rde270
	contents = U82CT(start_buff + iSpaceLoc+1);
#else
	contents = start_buff + iSpaceLoc+1;
#endif

	contents.TrimLeft();
	contents.TrimRight();

#ifndef rde270
#else
	sField.ReleaseBuffer(-1);
#endif
	return TRUE;
}