JMemoryManager*
JMemoryManager::Instance()
{
	// Guarantees access is only through this function
	static JMemoryManager* manager = NULL;

	if (manager == NULL)
		{
		theConstructingFlag = kJTrue;
		manager = new(__FILE__, __LINE__) JMemoryManager;
		assert(manager != NULL);

		// Create the error printer proxy to do the printing work.
		// Construction of the error printer must take place here, after
		// the manager is fully constructed; the recursive call to Instance
		// is harmless.
		manager->itsErrorPrinter = new(__FILE__, __LINE__) JMMErrorPrinter;
		assert(manager->itsErrorPrinter != NULL);

		const JCharacter* pipeName = getenv("JMM_PIPE");
		if (!JStringEmpty(pipeName))
			{
			manager->itsErrorStream = new(__FILE__, __LINE__) JMMDebugErrorStream;
			assert(manager->itsErrorStream != NULL);
			}

		theConstructingFlag = kJFalse;
		manager->EmptyStacks();

		// do it here since it calls delete as well as new

		if (!JStringEmpty(pipeName))
			{
			manager->ConnectToDebugger(pipeName);
			ACE_Object_Manager::at_exit(NULL, ::JMMHandleACEExit, NULL);

			// If we create the file when we actually need it, it
			// re-constructs JStringManager.

			JString fileName;
			const JError err = JCreateTempFile(&fileName);
			if (err.OK())
				{
				theInternalFlag = kJTrue;

				manager->itsExitStatsFileName = new JString(fileName);
				assert( manager->itsExitStatsFileName != NULL );

				theInternalFlag = kJFalse;
				}
			else
				{
				cerr << "Failed to create exit stats file:" << endl;
				cerr << err.GetMessage() << endl;
				}
			}
		}

	return manager;
}
Esempio n. 2
0
void
JStringManager::ReportError
	(
	const JCharacter*	id,
	const JError&		err
	)
	const
{
	if (!err.OK())
		{
		ReportError(id, err.GetMessage());
		}
}
Esempio n. 3
0
JBoolean
SyGExec
	(
	const JCharacter*	cmd,
	const JBoolean		report
	)
{
	JString errOutput;
	const JError err = JRunProgram(cmd, &errOutput);
	if (!err.OK() && report)
		{
		(JGetUserNotification())->ReportError(err.GetMessage());
		}
	return err.OK();
}
void
GenerateForm
	(
	istream&			input,
	const JString&		formName,
	const JString&		tagName,
	const JString&		enclName,
	const JString&		codePath,
	const JString&		stringPath,
	const JString&		codeSuffix,
	const JString&		headerSuffix,
	JPtrArray<JString>*	backupList
	)
{
	const JString codeFileName    = codePath + formName + codeSuffix;
	const JString codeFileBakName = codeFileName + kBackupSuffix;

	const JString headerFileName    = codePath + formName + headerSuffix;
	const JString headerFileBakName = headerFileName + kBackupSuffix;

	if (!JFileExists(codeFileName))
		{
		cerr << codeFileName << " not found" << endl;
		return;
		}
	if (!JFileExists(headerFileName))
		{
		cerr << headerFileName << " not found" << endl;
		return;
		}

	cout << "Generating: " << formName << ", " << tagName << endl;

	const JBoolean shouldBackup = ShouldBackupForm(formName, backupList);

	// copy code file contents before start delimiter

	JString tempCodeFileName;
	JError err = JCreateTempFile(codePath, NULL, &tempCodeFileName);
	if (!err.OK())
		{
		cerr << "Unable to create temporary file in " << codePath << endl;
		cerr << "  (" << err.GetMessage() << ')' << endl;
		return;
		}

	ifstream origCode(codeFileName);
	ofstream outputCode(tempCodeFileName);
	if (!outputCode.good())
		{
		cerr << "Unable to open temporary file in " << codePath << endl;
		remove(tempCodeFileName);
		return;
		}
	if (!CopyBeforeCodeDelimiter(tagName, origCode, outputCode))
		{
		cerr << "No starting delimiter in " << codeFileName << endl;
		outputCode.close();
		remove(tempCodeFileName);
		return;
		}

	// generate code for each object in the form

	JPtrArray<JString> objTypes(JPtrArrayT::kDeleteAll),
					   objNames(JPtrArrayT::kDeleteAll);
	GenerateCode(input, outputCode, stringPath, formName, tagName, enclName,
				 &objTypes, &objNames);

	// copy code file contents after end delimiter

	JBoolean done = CopyAfterCodeDelimiter(tagName, origCode, outputCode);
	origCode.close();
	outputCode.close();

	if (!done)
		{
		cerr << "No ending delimiter in " << codeFileName << endl;
		remove(tempCodeFileName);
		return;
		}
	else if (shouldBackup && rename(codeFileName, codeFileBakName) != 0)
		{
		cerr << "Unable to rename original " << codeFileName << endl;
		remove(tempCodeFileName);
		return;
		}
	JEditVCS(codeFileName);
	rename(tempCodeFileName, codeFileName);

	// copy header file contents before start delimiter

	JString tempHeaderFileName;
	err = JCreateTempFile(codePath, NULL, &tempHeaderFileName);
	if (!err.OK())
		{
		cerr << "Unable to create temporary file in " << codePath << endl;
		cerr << "  (" << err.GetMessage() << ')' << endl;
		return;
		}

	ifstream origHeader(headerFileName);
	ofstream outputHeader(tempHeaderFileName);
	if (!outputHeader.good())
		{
		cerr << "Unable to open temporary file in " << codePath << endl;
		remove(tempHeaderFileName);
		return;
		}
	if (!CopyBeforeCodeDelimiter(tagName, origHeader, outputHeader))
		{
		cerr << "No starting delimiter in " << headerFileName << endl;
		outputHeader.close();
		remove(tempHeaderFileName);
		return;
		}

	// generate instance variable for each object in the form

	GenerateHeader(outputHeader, objTypes, objNames);

	// copy header file contents after end delimiter

	done = CopyAfterCodeDelimiter(tagName, origHeader, outputHeader);
	origHeader.close();
	outputHeader.close();

	if (!done)
		{
		cerr << "No ending delimiter in " << headerFileName << endl;
		remove(tempHeaderFileName);
		return;
		}

	// check if header file actually changed

	JString origHeaderText, newHeaderText;
	JReadFile(headerFileName, &origHeaderText);
	JReadFile(tempHeaderFileName, &newHeaderText);
	if (newHeaderText != origHeaderText)
		{
		if (shouldBackup && rename(headerFileName, headerFileBakName) != 0)
			{
			cerr << "Unable to rename original " << headerFileName << endl;
			remove(tempHeaderFileName);
			return;
			}
		JEditVCS(headerFileName);
		rename(tempHeaderFileName, headerFileName);
		}
	else
		{
		remove(tempHeaderFileName);
		}
}
Esempio n. 5
0
void
CBFileNode::CreateFilesForTemplate
	(
	istream&			input,
	const JFileVersion	vers
	)
	const
{
	CBFileNodeBase::CreateFilesForTemplate(input, vers);

	JBoolean exists;
	input >> exists;
	if (exists)
		{
		JString relName, data;
		input >> relName >> data;

		JString path, name;
		JSplitPathAndName(relName, &path, &name);

		const CBProjectTree* projTree = dynamic_cast<const CBProjectTree*>(GetTree());
		assert( projTree != NULL );

		const JString& basePath = (projTree->GetProjectDoc())->GetFilePath();
		path = JCombinePathAndName(basePath, path);

		JUserNotification* un = JGetUserNotification();
		if (!JDirectoryExists(path))
			{
			const JError err = JCreateDirectory(path);
			if (!err.OK())
				{
				JString msg = "Unable to create the file ";
				msg += relName;
				msg += " from the template because:\n\n";
				msg += err.GetMessage();
				un->ReportError(msg);
				return;
				}
			}

		const JString fullName = JCombinePathAndName(path, name);
		if (JFileExists(fullName))
			{
			JString msg = fullName;
			msg.PrependCharacter('"');
			msg += "\" already exists.  Do you want to overwrite it?";
			if (!un->AskUserNo(msg))
				{
				return;
				}
			}

		ofstream output(fullName);
		if (output.good())
			{
			data.Print(output);
			}
		else
			{
			JString msg = "Unable to create the file ";
			msg += relName;
			msg += " from the template.";
			un->ReportError(msg);
			}
		}
}