void
SVNInfoLog::Execute
	(
	const JCharacter* cmd
	)
{
	(JXGetApplication())->DisplayBusyCursor();

	pid_t pid;
	int outFD, errFD;
	JError err = JExecute(cmd, &pid,
						  kJIgnoreConnection, NULL,
						  kJCreatePipe, &outFD,
						  kJCreatePipe, &errFD);
	if (!err.OK())
		{
		err.ReportIfError();
		return;
		}

	const JFontStyle red(kJTrue, kJFalse, 0, kJFalse, (GetColormap())->GetRedColor());

	JString text;
	JReadAll(errFD, &text);
	SetCurrentFontStyle(red);
	Paste(text);

	JReadAll(outFD, &text);
	SetCurrentFontStyle(JFontStyle());
	Paste(text);
}
CMChooseProcessDialog::CMChooseProcessDialog
	(
	JXDirector*		supervisor,
	const JBoolean	attachToSelection,
	const JBoolean	stopProgram
	)
	:
	JXDialogDirector(supervisor, kJTrue),
	itsAttachToSelectionFlag(attachToSelection),
	itsStopProgramFlag(stopProgram)
{
	BuildWindow();

	int inFD;
	const JError err = JExecute(kCmdStr, NULL,
								kJIgnoreConnection, NULL,
								kJCreatePipe, &inFD);
	if (err.OK())
		{
		JString text;
		JReadAll(inFD, &text);
		text.TrimWhitespace();
		itsText->SetText(text);
		}

	ListenTo(this);
}
JBoolean
JConvertToStream
(
    const int		input,
    ifstream*		input2,
    JString*		tempFullName,
    const JBoolean	closeInput
)
{
    JString data;
    if (!JReadAll(input, &data, closeInput))
    {
        return kJFalse;
    }

    if (!(JCreateTempFile(tempFullName)).OK())
    {
        return kJFalse;
    }

    ofstream output(*tempFullName);
    data.Print(output);
    output.close();

    input2->open(*tempFullName);
    return JI2B(input2->good());
}
void
CBSearchDocument::AppendText
	(
	const JString& text
	)
{
	if (text.GetFirstCharacter() == CBSearchTE::kIncrementProgress)
		{
		itsIndicator->IncrementValue();
		return;
		}

	CBTextEditor* te = GetTextEditor();

	itsFoundFlag = kJTrue;
	const std::string s(text.GetCString(), text.GetLength());
	std::istringstream input(s);

	if (text.GetFirstCharacter() == CBSearchTE::kError)
		{
		input.ignore();
		JString msg;
		JReadAll(input, &msg);

		const JIndex startIndex = te->GetTextLength() + 1;
		te->SetCaretLocation(startIndex);
		te->Paste(msg);
		te->Paste("\n");
		if (!itsOnlyListFilesFlag)
			{
			te->Paste("\n");
			}

		te->SetFontStyle(startIndex, startIndex + msg.GetLength()-1,
						 GetErrorStyle(), kJTrue);
		}
	else if (itsOnlyListFilesFlag)
		{
		JString fileName;
		input >> fileName;
		CBExecOutputDocument::AppendText(fileName);

		if (itsIsReplaceFlag)
			{
			ReplaceAll(fileName);
			}
		}
	else
		{
示例#5
0
JBoolean
JGetSVNEntryType
	(
	const JCharacter*	url,
	JString*			type,
	JString*			error
	)
{
	type->Clear();
	error->Clear();

	JString cmd = "svn info --xml " + JPrepArgForExec(url);
	JProcess* p;
	int fromFD, errFD;
	JError err = JProcess::Create(&p, cmd, kJIgnoreConnection, NULL,
								  kJCreatePipe, &fromFD, kJCreatePipe, &errFD);
	if (!err.OK())
		{
		err.ReportIfError();
		return kJFalse;
		}

	p->WaitUntilFinished();
	if (p->SuccessfulFinish())
		{
		xmlDoc* doc = xmlReadFd(fromFD, NULL, NULL, XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA);
		close(fromFD);
		if (doc != NULL)
			{
			xmlNode* root = xmlDocGetRootElement(doc);

			if (root != NULL &&
				strcmp((char*) root->name, "info") == 0 &&
				strcmp((char*) root->children->name, "entry") == 0)
				{
				*type = JGetXMLNodeAttr(root->children, "kind");
				return kJTrue;
				}
			}
		}

	JReadAll(errFD, error, kJTrue);
	return kJFalse;
}
JBoolean
GMMIMEParser::GetTextSegment
	(
	const JIndex	index,
	JString*		text,
	TextFormat*		format,
	JString*		charset
	)
{
	assert(itsTextInfo != NULL);
	assert(index <= itsTextInfo->GetEntryCount());
	JString name = itsTextInfo->GetEntry(index).GetFullName();
	std::ifstream is(name);
	if (is.good())
		{
		JReadAll(is, text);
		if (name.EndsWith(kPlainType))
			{
			*format = kPlain;
			}
		else if (name.EndsWith(kHTMLType))
			{
			*format = kHTML;
			}
		JIndex findex;
		JBoolean ok = name.LocateLastSubstring(".", &findex);
		assert(ok);
		name.RemoveSubstring(findex, name.GetLength());
		ok = name.LocateLastSubstring(".", &findex);
		if (findex < name.GetLength())
			{
			*charset = name.GetSubstring(findex + 1, name.GetLength());
			}
		}
	else
		{
		itsIsSuccessful = kJFalse;
		}

	return itsIsSuccessful;
}
示例#7
0
void
JXFontManager::GetFontNames
	(
	JPtrArray<JString>* fontNames
	)
	const
{
	if (itsAllFontNames != NULL)
		{
		fontNames->CopyObjects(*itsAllFontNames, fontNames->GetCleanUpAction(), kJFalse);
		}
	else
		{
		fontNames->CleanOut();
		fontNames->SetCompareFunction(JCompareStringsCaseInsensitive);
		fontNames->SetSortOrder(JOrderedSetT::kSortAscending);

#ifdef _J_USE_XFT
		FcBool scalable = 1;
		XftFontSet* fs = XftListFonts(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_SCALABLE, XftTypeBool, scalable, 0, XFT_FAMILY, 0);

		for (int i=0; i<fs->nfont; i++)
		{
			char* raw_name;
			if (XftPatternGetString(fs->fonts[i], XFT_FAMILY, 0, &raw_name) == XftResultMatch)
			{
				JString name(raw_name);
				JBoolean isDuplicate;
				const JIndex index = fontNames->GetInsertionSortIndex(&name, &isDuplicate);
				if (!isDuplicate)
				{
					fontNames->InsertAtIndex(index, name);
				}
			}
		}
		
		XftFontSetDestroy(fs);		
#else
		int nameCount;
		char** nameList = XListFonts(*itsDisplay, "-*-*-*-*-*-*-*-*-75-75-*-*-*-*",
									 INT_MAX, &nameCount);
		if (nameList == NULL)
			{
			return;
			}

		JString name, charSet;
		for (int i=0; i<nameCount; i++)
			{
			const std::string s(nameList[i], strlen(nameList[i]));
			std::istringstream input(s);
			input.ignore();						// initial dash
			JIgnoreUntil(input, '-');			// foundry name
			name = JReadUntil(input, '-');		// font name
			JIgnoreUntil(input, "-75-75-");		// ignore specs
			JIgnoreUntil(input, '-');
			JIgnoreUntil(input, '-');
			JReadAll(input, &charSet);			// char set

			if (name.IsEmpty() || name == "nil")
				{
				continue;
				}

			ConvertToPSFontName(&name);

			// Until JPSPrinter can embed fonts in a Postscript file, we are limited
			// to only the standard Postscript fonts.

			if (name == JXGetCourierFontName()   ||
				name == JXGetHelveticaFontName() ||
				name == JXGetSymbolFontName()    ||
				name == JXGetTimesFontName())
				{
//				if (name != JXGetSymbolFontName())
//					{
//					name = CombineNameAndCharacterSet(name, charSet);
//					}

				JBoolean isDuplicate;
				const JIndex index =
					fontNames->GetInsertionSortIndex(&name, &isDuplicate);
				if (!isDuplicate)
					{
					fontNames->InsertAtIndex(index, name);
					}
				}
			}

		XFreeFontNames(nameList);
#endif

		// save names for next time

		JXFontManager* me = const_cast<JXFontManager*>(this);

		me->itsAllFontNames =
			new JPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll, kJTrue);
		assert( me->itsAllFontNames != NULL );
		}
}
示例#8
0
JBoolean
JXFontManager::GetFontCharSets
	(
	const JCharacter*	name,
	const JSize			size,
	JPtrArray<JString>*	charSetList
	)
	const
{
	charSetList->CleanOut();
	charSetList->SetCompareFunction(JCompareStringsCaseInsensitive);
	charSetList->SetSortOrder(JOrderedSetT::kSortAscending);

	JString xFontName, charSet;
	ConvertToXFontName(name, &xFontName, &charSet);		// strip charSet

	const JString regexStr =
		"-*-" + xFontName + "-*-*-*-*-*-" +
		JString(10*size, 0, JString::kForceNoExponent) +
		"-75-75-*-*-*-*";

	int nameCount;
	char** nameList = XListFonts(*itsDisplay, regexStr, INT_MAX, &nameCount);
	if (nameList == NULL)
		{
		return kJFalse;
		}

	for (int i=0; i<nameCount; i++)
		{
		const std::string s(nameList[i], strlen(nameList[i]));
		std::istringstream input(s);
		input.ignore();							// initial dash
		JIgnoreUntil(input, '-');				// foundry name
		JIgnoreUntil(input, '-');				// font name
		JIgnoreUntil(input, '-');				// medium/bold
		JIgnoreUntil(input, '-');				// roman/oblique/italic
		JIgnoreUntil(input, '-');				// character spacing
		input.ignore();							// extra dash
		JIgnoreUntil(input, '-');				// pixel height
		JIgnoreUntil(input, '-');				// 10*(point size)
		JIgnoreUntil(input, '-');				// x resolution
		JIgnoreUntil(input, '-');				// y resolution
		JIgnoreUntil(input, '-');				// ?
		JIgnoreUntil(input, '-');				// ?
		JReadAll(input, &charSet);

		JBoolean isDuplicate;
		const JIndex index =
			charSetList->GetInsertionSortIndex(&charSet, &isDuplicate);
		if (!isDuplicate)
			{
			JString* s = new JString(charSet);
			assert( s != NULL );
			charSetList->InsertElementAtIndex(index, s);
			}
		}

	XFreeFontNames(nameList);
	return JNegate( charSetList->IsEmpty() );
}
示例#9
0
void
JXFontManager::GetMonospaceFontNames
	(
	JPtrArray<JString>* fontNames
	)
	const
{
	if (itsMonoFontNames != NULL)
		{
		fontNames->CopyObjects(*itsMonoFontNames, fontNames->GetCleanUpAction(), kJFalse);
		}
	else
		{
		(JXGetApplication())->DisplayBusyCursor();

		fontNames->CleanOut();
		fontNames->SetCompareFunction(JCompareStringsCaseInsensitive);
		fontNames->SetSortOrder(JOrderedSetT::kSortAscending);

#ifdef _J_USE_XFT
		FcBool scalable = 1;
		XftFontSet* fs = XftListFonts(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_SPACING, XftTypeInteger, XFT_MONO,
																			XFT_SCALABLE, XftTypeBool, scalable, 0, XFT_FAMILY, 0);

		for (int i=0; i<fs->nfont; i++)
		{
			char* raw_name;
			if (XftPatternGetString(fs->fonts[i], XFT_FAMILY, 0, &raw_name) == XftResultMatch)
			{
				JString name(raw_name);
				JBoolean isDuplicate;
				const JIndex index = fontNames->GetInsertionSortIndex(&name, &isDuplicate);
				if (!isDuplicate)
				{
					fontNames->InsertAtIndex(index, name);
				}
			}
		}
		
		XftFontSetDestroy(fs);		
#else
		JPtrArray<JString> allFontNames(JPtrArrayT::kDeleteAll);
		allFontNames.SetCompareFunction(JCompareStringsCaseInsensitive);
		allFontNames.SetSortOrder(JOrderedSetT::kSortAscending);

		for (int j=0; j<kMonospaceFontPatternCount; j++)
			{
			int nameCount;
			char** nameList = XListFonts(*itsDisplay, kMonospaceFontPattern[j],
										 INT_MAX, &nameCount);
			if (nameList == NULL)
				{
				return;
				}

			JString name, charSet;
			for (int i=0; i<nameCount; i++)
				{
				const std::string s(nameList[i], strlen(nameList[i]));
				std::istringstream input(s);
				input.ignore();						// initial dash
				JIgnoreUntil(input, '-');			// foundry name
				name = JReadUntil(input, '-');		// font name
				JIgnoreUntil(input, "-iso");		// ignore specs
				JReadAll(input, &charSet);			// char set

				if (name.IsEmpty() || name == "nil")
					{
					continue;
					}

				ConvertToPSFontName(&name);

#if ! QUERY_FOR_MONOSPACE
				if (name == "Clean" || name == "Courier" || name == "Fixed" ||
					name == "Terminal" || name == "Lucidatypewriter" ||
					name == "Profontwindows")
					{
#endif

//				charSet.Prepend("iso");
//				name = CombineNameAndCharacterSet(name, charSet);

				JBoolean isDuplicate;
				const JIndex index =
					allFontNames.GetInsertionSortIndex(&name, &isDuplicate);
				if (!isDuplicate)
					{
					allFontNames.InsertAtIndex(index, name);

//					cout << nameList[i] << endl;

					XFontStruct* xfont = XLoadQueryFont(*itsDisplay, nameList[i]);
					if (xfont != NULL)
						{
						if (IsMonospace(*xfont))
							{
							JString* n = new JString(name);
							assert( n != NULL );
							const JBoolean ok = fontNames->InsertSorted(n, kJFalse);
							assert( ok );
							}
						XFreeFont(*itsDisplay, xfont);
						}
					}
#if ! QUERY_FOR_MONOSPACE
					}
#endif
				}

			XFreeFontNames(nameList);
			}
#endif

		// save names for next time

		JXFontManager* me = const_cast<JXFontManager*>(this);

		me->itsMonoFontNames =
			new JPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll, kJTrue);
		assert( me->itsMonoFontNames != NULL );
		}
}
JBoolean
CBCtagsUser::HasExuberantCtags()
{
	if (itsHasExuberantCtagsFlag == kUntested)
		{
		itsHasExuberantCtagsFlag = kFailure;

		// this hack is required on Linux kernel 2.3.x (4/19/2000)
		j_sig_func*	origHandler = signal(SIGCHLD, emptyHandler);

		pid_t pid;

		#if defined _J_SUNOS
		pid_t* ppid = NULL;
		#else
		pid_t* ppid = &pid;
		#endif

		int fromFD;
		JError err = JExecute(kCheckVersionCmd, ppid,
							  kJIgnoreConnection, NULL,
							  kJCreatePipe, &fromFD,
							  kJTossOutput, NULL);
		if (err.OK())
			{
			JString vers;
			JReadAll(fromFD, &vers);

			JArray<JIndexRange> matchList;
			if (versionPattern.Match(vers, &matchList))
				{
				matchList.RemoveElement(1);

				const JSize count = matchList.GetElementCount();
				JString s;
				for (JIndex i=1; i<=count; i++)
					{
					JUInt v = 0;
					const JIndexRange r = matchList.GetElement(i);
					if (!r.IsEmpty())
						{
						s = vers.GetSubstring(r);
						while (!isdigit(s.GetFirstCharacter()))
							{
							s.RemoveSubstring(1, 1);
							}
						const JBoolean ok = s.ConvertToUInt(&v);
						assert( ok );
						}

					if (v > kMinVersion[i-1] ||
						(i == count && v == kMinVersion[i-1]))
						{
						itsHasExuberantCtagsFlag = kSuccess;
						break;
						}
					else if (v < kMinVersion[i-1])
						{
						break;
						}
					}
				}
			}

		if (origHandler != SIG_ERR)
			{
			signal(SIGCHLD, origHandler);
			}
		}

	return JI2B( itsHasExuberantCtagsFlag == kSuccess );
}
JBoolean
JGetUserMountPointList
	(
	JMountPointList*	list,
	JMountState*		state
	)
{
	JProcess* p;
	int outFD;
	const JError err = JProcess::Create(&p, kMountCmd,
										kJIgnoreConnection, NULL,
										kJCreatePipe, &outFD,
										kJIgnoreConnection, NULL);
	if (!err.OK())
		{
		if (state != NULL)
			{
			jdelete state->mountCmdOutput;
			state->mountCmdOutput = NULL;
			}
		return kJFalse;
		}

	JString mountData;
	JReadAll(outFD, &mountData);

	p->WaitUntilFinished();
	const JBoolean success = p->SuccessfulFinish();
	jdelete p;
	p = NULL;

	if (!success)
		{
		if (state != NULL)
			{
			jdelete state->mountCmdOutput;
			state->mountCmdOutput = NULL;
			}
		return kJFalse;
		}

	if (state != NULL && state->mountCmdOutput != NULL &&
		mountData == *(state->mountCmdOutput))
		{
		return kJFalse;
		}

	list->CleanOut();
	if (state != NULL && state->mountCmdOutput == NULL)
		{
		state->mountCmdOutput = jnew JString(mountData);
		assert( state->mountCmdOutput != NULL );
		}
	else if (state != NULL)
		{
		*(state->mountCmdOutput) = mountData;
		}

	JIndexRange r;
	JArray<JIndexRange> matchList;
	JString options;
	ACE_stat stbuf;
	while (theLinePattern.MatchAfter(mountData, r, &matchList))
		{
		r = matchList.GetFirstElement();

		options = mountData.GetSubstring(matchList.GetElement(4));
		if (options.Contains("nobrowse"))
			{
			continue;
			}

		JString* path = jnew JString(mountData.GetSubstring(matchList.GetElement(3)));
		assert( path != NULL );
		JString* devicePath = jnew JString(mountData.GetSubstring(matchList.GetElement(2)));
		assert( devicePath != NULL );

		const JMountType type =
			JGetUserMountPointType(*path, *devicePath, "");
		if (type == kJUnknownMountType ||
			ACE_OS::stat(*path, &stbuf) != 0)
			{
			jdelete path;
			jdelete devicePath;
			continue;
			}

		JFileSystemType fsType = kOtherFSType;
		if (options.Contains("msdos"))
			{
			fsType = kVFATType;
			}

		list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType));
		}

	return kJTrue;
}
示例#12
0
void
SMTPMessage::Send()
{
	HandleAddresses();

	AppendToOutbox("From ");
	AppendToOutbox(*itsFrom);
	AppendToOutbox(" ");

	struct timeb tp;
	ftime(&tp);
	JString date(ctime(&(tp.time)));
	AppendToOutbox(date);

	std::istrstream is(date.GetCString(), date.GetLength());
	JString dow;
	JString mon;
	JString day;
	JString rest;
	dow = JReadUntilws(is);
	mon = JReadUntilws(is);
	day = JReadUntilws(is);
	JReadAll(is, &rest);

	AppendToOutbox("Date: ");
	AppendToOutbox(dow);
	AppendToOutbox(", ");
	AppendToOutbox(day);
	AppendToOutbox(" ");
	AppendToOutbox(mon);
	AppendToOutbox(" ");
	AppendToOutbox(rest);

	JString addrStr = itsSMTPServer;
	if (!addrStr.Contains(":"))
		{
		addrStr += ":25";
		}
	ACE_INET_Addr addr(addrStr);

	itsLink = new InetLink;
	assert(itsLink != NULL);

	itsConnector = new INETConnector;
	assert( itsConnector != NULL );

	ACE_Synch_Options options(ACE_Synch_Options::USE_REACTOR, ACE_Time_Value(kMaxWaitSeconds));

	if (itsConnector->connect(itsLink, addr, options) == -1 &&
		jerrno() != EAGAIN)
		{
		JString notice	= "No response from sendmail : Error number ";
		int errNumber	= jerrno();
		notice += JString(errNumber);
		JGetUserNotification()->ReportError(notice);
		itsDeleteTask = new JXTimerTask(1000,kJTrue);
		assert( itsDeleteTask != NULL );
		itsDeleteTask->Start();
		ListenTo(itsDeleteTask);
		Broadcast(SendFailure());
//		itsLink = NULL;
		return;
		}
	itsTimeoutTask = new JXTimerTask(kMaxWaitSeconds * 1000,kJTrue);
	assert( itsTimeoutTask != NULL );
	itsTimeoutTask->Start();
	ListenTo(itsTimeoutTask);
	ClearWhenGoingAway(itsLink, &itsLink);
}