JBoolean
CBCStyler::SlurpPPComment
	(
	JIndexRange* totalRange
	)
{
	const JString& text = GetText();
	const JString s     = text.GetSubstring((GetPPNameRange()).first, totalRange->last);
	if (!ppCommentPattern.Match(s))
		{
		return kJFalse;
		}

	Token token;
	JString ppCmd;
	JSize nestCount = 1;
	while (1)
		{
		token = NextToken();
		if (token.type == kEOF)
			{
			break;
			}
		else if (token.type == kPPDirective)
			{
			ppCmd = text.GetSubstring(GetPPNameRange());
			if (ppIfPattern.Match(ppCmd))
				{
				nestCount++;
				}
			else if (ppEndPattern.Match(ppCmd))
				{
				nestCount--;
				if (nestCount == 0)
					{
					break;
					}
				}
			else if (ppElsePattern.Match(ppCmd) && nestCount == 1)
				{
				Undo(token.range, text.GetSubstring(token.range));	// rescan
				token.range.last = token.range.first - 1;
				break;
				}
			}
		}

	totalRange->last = token.range.last;
	return kJTrue;
}
JXPSPrintSetupDialog*
CBPSPrinter::CreatePrintSetupDialog
	(
	const Destination	destination,
	const JCharacter*	printCmd,
	const JCharacter*	fileName,
	const JBoolean		collate,
	const JBoolean		bw
	)
{
	assert( itsCBPrintSetupDialog == NULL );

	if (itsFontSize == kUnsetFontSize)
		{
		JString fontName;
		CBGetPrefsManager()->GetDefaultFont(&fontName, &itsFontSize);

		JArray<JIndexRange> matchList;
		if (nxmRegex.Match(fontName, &matchList))
			{
			const JString hStr = fontName.GetSubstring(matchList.GetElement(2));
			const JBoolean ok  = hStr.ConvertToUInt(&itsFontSize);
			assert( ok );
			itsFontSize--;
			}
		}

	itsCBPrintSetupDialog =
		CBPSPrintSetupDialog::Create(destination, printCmd, fileName,
									 collate, bw, itsFontSize,
									 (CBGetPTTextPrinter())->WillPrintHeader());
	return itsCBPrintSetupDialog;
}
const JString&
GMessageHeader::GetBaseSubject()
{
	if (itsHasBaseSubject)
		{
		return itsBaseSubject;
		}
	itsHasBaseSubject	= kJTrue;
	itsBaseSubject		= GetSubject();
	kFixSubjectRegex.SetCaseSensitive(kJFalse);
	JArray<JIndexRange> subList;
	while (kFixSubjectRegex.Match(itsBaseSubject, &subList))
		{
		itsBaseSubject	= itsBaseSubject.GetSubstring(subList.GetElement(subList.GetElementCount()));
		itsBaseSubject.TrimWhitespace();
		subList.RemoveAll();
		}
	const JSize length	= itsBaseSubject.GetLength();
	JIndex findex		= 1;
	while (findex <= length && 
		   !isalnum(itsBaseSubject.GetCharacter(findex)))
		{
		findex++;
		}
	if (findex > 1 && findex <= length)
		{
		itsBaseSubject	= itsBaseSubject.GetSubstring(findex, length);
		}
	return itsBaseSubject;
}
Exemple #4
0
JBoolean
JXFontManager::BuildTrueTypeFontName
	(
	const JCharacter*	xName,
	const JSize			size,
	const JFontStyle&	style,
	JString*			xFontStr
	)
	const
{
	xFontStr->Clear();

	// NxM is not TrueType.  Symbol is strange.

	if (nxmRegex.Match(xName) ||
		JStringCompare(xName, "Symbol", kJFalse) == 0)
		{
		return kJFalse;
		}

	// name

	xFontStr->Append(xName);

	// size

	xFontStr->Append("-");
	xFontStr->Append( JString(size, JString::kBase10) );

	// regular or boldface

	if (style.bold)
		{
		xFontStr->Append(":weight=bold");
		}
	else
		{
		xFontStr->Append(":weight=light");
		}

	// regular or italic

	if (style.italic)
		{
		xFontStr->Append(":slant=oblique,italic");
		}
	else
		{
		xFontStr->Append(":slant=roman");
		}

	// success

	return kJTrue;
}
CMLocation
GDBGetStopLocation::GetLocation()
	const
{
	const JString& data = GetLastResult();

	CMLocation loc;
	JIndexRange r;
	if (locationPattern.Match(data, &r))
		{
		std::istringstream stream(data.GetCString());
		stream.seekg(r.last);

		JStringPtrMap<JString> map(JPtrArrayT::kDeleteAll);
		JString *s, *s1, *fullName;
		JIndex lineIndex;
		const JBoolean parsed = GDBLink::ParseMap(stream, &map);
		if (!parsed)
			{
			(CMGetLink())->Log("invalid data map");
			}
		else if (!map.GetElement("fullname", &fullName))
			{
			(CMGetLink())->Log("missing file name");
			}
		else if (!map.GetElement("line", &s))
			{
			(CMGetLink())->Log("missing line index");
			}
		else if (!s->ConvertToUInt(&lineIndex))
			{
			(CMGetLink())->Log("line index is not integer");
			}
		else
			{
			loc.SetFileName(*fullName);
			loc.SetLineNumber(lineIndex);
			}

		if (parsed && map.GetElement("func", &s) && map.GetElement("addr", &s1))
			{
			loc.SetFunctionName(*s);
			loc.SetMemoryAddress(*s1);
			}
		}
	else
		{
		(CMGetLink())->Log("GDBGetStopLocation failed to match");
		}

	return loc;
}
JBoolean
CBCommandTable::ExtractInputData
	(
	const JPoint& cell
	)
{
	assert( itsTextInput != NULL && cell.x != kOptionsColumn );

	CBCommandManager::CmdInfo info = itsCmdList->GetElement(cell.y);

	const JString& text = itsTextInput->GetText();

	JString* s = NULL;
	if (cell.x == kMenuTextColumn)
		{
		s = info.menuText;
		}
	else if (cell.x == kMenuShortcutColumn)
		{
		s = info.menuShortcut;
		}
	else if (cell.x == kScriptNameColumn)
		{
		if (illegalNamePattern.Match(text))
			{
			(JGetUserNotification())->ReportError(JGetString(kNoSpacesInCmdNameID));
			return kJFalse;
			}
		s = info.name;
		}
	else if (cell.x == kCommandColumn)
		{
		s = info.cmd;
		}
	else if (cell.x == kPathColumn)
		{
		s = info.path;
		}
	assert( s != NULL );

	if (itsTextInput->InputValid())
		{
		*s = text;
		s->TrimWhitespace();
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
void
GDBGetProgramName::HandleSuccess
(
    const JString& data
)
{
    JString fileName;

    JArray<JIndexRange> matchList;
    if (fileNamePattern.Match(data, &matchList) ||
            osxNamePattern.Match(data, &matchList))
    {
        fileName = data.GetSubstring(matchList.GetElement(2));
    }
    else
    {
        (CMGetLink())->Log("GDBGetProgramName failed to match");
    }

    // CMLink has to broadcast SymbolsLoaded regardless of whether or not
    // we get what we expect from gdb.

    dynamic_cast<GDBLink*>(CMGetLink())->SaveProgramName(fileName);
}
void
SVNInfoLog::GetSelectedFiles
	(
	JPtrArray<JString>*	fullNameList,
	const JBoolean		includeDeleted
	)
{
	fullNameList->CleanOut();
	fullNameList->SetCleanUpAction(JPtrArrayT::kDeleteAll);

	JString s;
	if (GetSelection(&s) && revisionPattern.Match(s))
		{
		fullNameList->Append(itsFullName);
		}
}
JBoolean
JParseURL
	(
	const JCharacter*	url,
	JString*			protocol,
	JString*			host,
	JIndex*				port,
	JString*			path
	)
{
	*path = url;

	JArray<JIndexRange> matchList;
	if (urlPattern.Match(url, &matchList))
		{
		protocol->Set(url, matchList.GetElement(2));
		host->Set(url, matchList.GetElement(3));

		JIndexRange r = matchList.GetElement(4);
		if (!r.IsEmpty())
			{
			const JString s(url, r);
			if (!s.ConvertToUInt(port))
				{
				*port = 0;
				}
			}
		else
			{
			*port = 0;
			}

		r = matchList.GetElement(5);
		if (!r.IsEmpty())
			{
			path->Set(url, r);
			}
		else
			{
			*path = "/";
			}

		return kJTrue;
		}

	return kJFalse;
}
JBoolean
JVIKeyHandler::GetPrevCharacter
	(
	JCharacter* c
	)
	const
{
	if (prevCharPattern.Match(itsKeyBuffer))
		{
		*c = itsKeyBuffer.GetLastCharacter();
		return kJTrue;
		}
	else
		{
		*c = 0;
		return kJFalse;
		}
}
void
THXBaseConvDirector::Convert()
{
	const JInteger fromBase = itsFromBase->GetBase();

	const JString& fromStr = itsFromValue->GetText();
	if (fromBase != 16 && hexRegex.Match(fromStr))
		{
		itsFromBase->SetBase(16);	// calls us again
		return;
		}

	JUInt value;
	if (!fromStr.ConvertToUInt(&value, fromBase))
		{
		itsToValue->SetText("");
		return;
		}

	JString toValue;
	const JInteger toBase = itsToBase->GetBase();
	if (value == 0)
		{
		toValue = "0";
		}
	else if (toBase == 2)
		{
		do
			{
			if (value & 0x01)
				{
				toValue.PrependCharacter('1');
				}
			else
				{
				toValue.PrependCharacter('0');
				}
			value = value >> 1;
			}
			while (value != 0);
		}
	else
		{
JBoolean
SVNInfoLog::GetBaseRevision
	(
	JString* rev
	)
{
	JString s;
	JArray<JIndexRange> matchList;
	if (GetSelection(&s) && revisionPattern.Match(s, &matchList))
		{
		*rev = s.GetSubstring(matchList.GetElement(2));
		return kJTrue;
		}
	else
		{
		rev->Clear();
		return kJFalse;
		}
}
Exemple #13
0
void
JExtractFileAndLine
	(
	const JCharacter*	str,
	JString*			fileName,
	JIndex*				startLineIndex,
	JIndex*				endLineIndex
	)
{
	static JRegex lineIndexRegex(":([0-9]+)(-([0-9]+))?$");

	*fileName = str;

	JArray<JIndexRange> matchList;
	if (lineIndexRegex.Match(*fileName, &matchList))
		{
		JString s   = fileName->GetSubstring(matchList.GetElement(2));
		JBoolean ok = s.ConvertToUInt(startLineIndex);
		assert( ok );

		const JIndexRange endRange = matchList.GetElement(4);
		if (endLineIndex != NULL && !endRange.IsEmpty())
			{
			s  = fileName->GetSubstring(endRange);
			ok = s.ConvertToUInt(endLineIndex);
			assert( ok );
			}
		else if (endLineIndex != NULL)
			{
			*endLineIndex = *startLineIndex;
			}

		fileName->RemoveSubstring(matchList.GetElement(1));
		}
	else
		{
		*startLineIndex = 0;
		if (endLineIndex != NULL)
			{
			*endLineIndex = 0;
			}
		}
}
void
JXFontManager::GetXFontNames
	(
	const JRegex&		regex,
	JPtrArray<JString>*	fontNames,
	JSortXFontNamesFn	compare
	)
	const
{
	fontNames->CleanOut();
	fontNames->SetCompareFunction(
					compare != NULL ? compare : JCompareStringsCaseInsensitive);
	fontNames->SetSortOrder(JOrderedSetT::kSortAscending);

#ifdef _J_USE_XFT
#else
	int nameCount;
	char** nameList = XListFonts(*itsDisplay, "*", INT_MAX, &nameCount);
	if (nameList == NULL)
		{
		return;
		}

	for (int i=0; i<nameCount; i++)
		{
		if (regex.Match(nameList[i]) && strcmp(nameList[i], "nil") != 0)
			{
			JString name = nameList[i];
			JBoolean isDuplicate;
			const JIndex index =
				fontNames->GetInsertionSortIndex(&name, &isDuplicate);
			if (!isDuplicate)
				{
				JString* n = new JString(name);
				assert( n != NULL );
				fontNames->InsertAtIndex(index, n);
				}
			}
		}

	XFreeFontNames(nameList);
#endif
}
void
JXChooseMonoFont::UpdateMenus
	(
	const JBoolean updateSize
	)
{
	const JString& fontName = itsFontMenu->GetFontName();
	if (fontRegex.Match(fontName))
		{
		itsSizeMenu->Deactivate();
		}
	else
		{
		itsSizeMenu->Activate();
		if (updateSize)
			{
			itsSizeMenu->SetFontName(fontName);
			}
		}
}
void
CBCompileDocument::OpenNextListItem()
{
	CBTextEditor* te    = GetTextEditor();
	const JString& text = te->GetText();
	JString s;
	JIndexRange r;
	while (ShowNextError())
		{
		const JBoolean ok = te->GetSelection(&r);
		assert( ok );
		s = text.GetSubstring(r);
		if (makeErrorRegex.Match(s))
			{
			continue;
			}

		GetTextEditor()->OpenSelection();
		break;
		}
}
void
GDBVarCommand::HandleSuccess
	(
	const JString& data
	)
{
	JString s = data;
	s.TrimWhitespace();

	JBoolean success = kJFalse;

	JIndexRange r;
	prefixPattern.SetSingleLine();
	if (prefixPattern.Match(data, &r))
		{
		s.RemoveSubstring(r);
		SetData(s);

		GDBVarTreeParser parser(s);
		if (parser.yyparse() == 0)
			{
			parser.ReportRecoverableError();
			success = kJTrue;
			Broadcast(ValueMessage(kValueUpdated, parser.GetRootNode()));
			}
		}
	else
		{
		(CMGetLink())->Log("GDBVarCommand failed to match");
		}

	if (!success)
		{
		Broadcast(ValueMessage(kValueFailed, NULL));
		}

	s.Clear();
	SetData(s);
}
void
GDBGetFrame::HandleSuccess
	(
	const JString& cmdData
	)
{
	const JString& data = GetLastResult();

	JIndexRange r;
	if (framePattern.Match(data, &r))
		{
		std::istringstream stream(data.GetCString());
		stream.seekg(r.last);

		JStringPtrMap<JString> map(JPtrArrayT::kDeleteAll);
		JString* s;
		JIndex frameIndex;
		if (!GDBLink::ParseMap(stream, &map))
			{
			(CMGetLink())->Log("invalid data map");
			}
		else if (!map.GetElement("level", &s))
			{
			(CMGetLink())->Log("missing frame index");
			}
		else if (!s->ConvertToUInt(&frameIndex))
			{
			(CMGetLink())->Log("frame index is not integer");
			}
		else
			{
			itsWidget->SelectFrame(frameIndex);
			}
		}
	else
		{
		(CMGetLink())->Log("GDBGetFrame failed to match");
		}
}
int
GMScanner::yylex()
{
	if (itsCurrentPosition == 0)
		{
		itsIs >> std::ws;
		itsCurrentPosition = JTellg(*itsIs);
		itsCurrentHeaderStart = itsCurrentPosition;
		itsText = JReadLine(*itsIs);
		JRegex regex;
		JBoolean matched;
		JArray<JStringRange>* subList = new JArray<JStringRange>;
		assert(subList != NULL);
		err = regex.SetPattern("^From[[:space:]]+.*.{3}[[:space:]]+.{3}[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+:[[:digit:]]+:[[:digit:]]+[[:space:]]+[[:digit:]]{4}");
		assert(err.OK());
		matched = regex.Match(itsText, subList);
		delete subList;
		if (matched)
			{
			itsState = kHeaderStart;
			return itsState;
			}
		}
JBoolean
MatchesCookie
	(
	const JCharacter*	cookie,
	const JDirEntry&	entry
	)
{
	JString file = entry.GetFullName();
	if (!JFileReadable(file))
		{
		return kJFalse;
		}

	mode_t perms;
	JError err = JGetPermissions(file, &perms);
	if (!err.OK())
		{
		perms = 0600;
		}
	ifstream is(file);
	is >> ws;
	JString line1 = JReadLine(is);
	is.close();
	if (line1 == "")
		{
		return kJTrue;
		}
	JArray<JIndexRange> subList;
	JRegex regex;
	err = regex.SetPattern(cookie);
	JBoolean matched = regex.Match(line1, &subList);
	if (matched)
		{
		return kJTrue;
		}
	return kJFalse;
}
void
GetTempVarName
	(
	const JCharacter*			tagName,
	JString*					varName,
	const JPtrArray<JString>&	objNames
	)
{
	JString suffix = tagName;
	JIndexRange r;
	while (illegalCChar.Match(suffix, &r))
		{
		suffix.RemoveSubstring(r);
		}
	suffix.PrependCharacter('_');

	const JString prefix = "obj";
	const JSize count    = objNames.GetElementCount();
	for (JIndex i=1; i<=INT_MAX; i++)
		{
		*varName = prefix + JString(i) + suffix;
		JBoolean unique = kJTrue;
		for (JIndex j=1; j<=count; j++)
			{
			const JString* usedName = objNames.NthElement(j);
			if (*varName == *usedName)
				{
				unique = kJFalse;
				break;
				}
			}
		if (unique)
			{
			break;
			}
		}
}
JString
JXFontManager::BuildFontName
	(
	const JCharacter*	xName,
	const JCharacter*	charSet,
	const JSize			size,
	const JFontStyle&	style,
	const JCharacter*	italicStr,
	const JBoolean		iso
	)
	const
{
#ifdef _J_USE_XFT
	JString xFontName;
	return xFontName;
#else
	// handle NxM separately

	nxmRegex.SetMatchOnly(kJTrue);
	if (nxmRegex.Match(xName))
		{
		JString xFontName = xName;
		if (style.bold)
			{
			xFontName += "bold";
			}
		return xFontName;
		}

	// any foundry

	JString xFontName = "-*-";

	// given name

	xFontName.Append(xName);

	// regular or boldface

	if (style.bold)
		{
		xFontName.Append("-bold");
		}
	else
		{
		xFontName.Append("-medium");
		}

	// regular or italic

	if (style.italic)
		{
		xFontName.Append(italicStr);
		}
	else
		{
		xFontName.Append("-r");
		}

	// normal character spacing, any pixel size

	xFontName.Append("-normal-*-*-");

	// font size

	xFontName.Append( JString(10*size, 0, JString::kForceNoExponent) );

	// screen resolution (apparently, we should always just use 75 dpi fonts),
	// any spacing, any avg width

	xFontName.Append("-75-75-*-*-");

	JIndex latinIndex;
	if (!JStringEmpty(charSet))
		{
		xFontName.Append(charSet);
		}
	else if (iso && JXGetLatinCharacterSetIndex(&latinIndex))
		{
		JString s = "iso8859-";
		s += JString(latinIndex, 0);
		xFontName.Append(s);
		}
	else if (iso)
		{
		xFontName.Append("iso*-*");
		}
	else
		{
		xFontName.Append("*-*");
		}

	// return the result

	return xFontName;
#endif
}
void
GARMessageHeader::SetDate
	(
	const JString& date
	)
{
	itsDate = date;
	itsDate.TrimWhitespace();
	JArray<JIndexRange> subList;
	JString year	= JString(itsYear, JString::kBase10);
	JBoolean matched = monthRegex1.Match(itsDate, &subList);
	if (matched)
		{
		JIndexRange sRange = subList.GetElement(3);
		itsMonth = itsDate.GetSubstring(sRange);
		sRange = subList.GetElement(2);
		JString day = itsDate.GetSubstring(sRange);
		if (!day.IsEmpty())
			{
			if (day.GetFirstCharacter() == '0')
				{
				day.RemoveSubstring(1,1);
				}
			}
		day.ConvertToUInt(&itsDay);
		itsShortDate = itsMonth + " " + day;
		time_t now;
		struct tm *local_time;
		time(&now);
		local_time = localtime(&now);
		if (itsYear != (JIndex)(local_time->tm_year + 1900))
			{
			JString year	= JString(itsYear, JString::kBase10);
			itsShortDate += " " + year;
			}

		return;
		}
	matched = monthRegex2.Match(itsDate, &subList);
	if (matched)
		{
		JIndexRange sRange = subList.GetElement(3);
		itsMonth = itsDate.GetSubstring(sRange);
		sRange = subList.GetElement(2);
		JString day = itsDate.GetSubstring(sRange);
		if (!day.IsEmpty())
			{
			if (day.GetFirstCharacter() == '0')
				{
				day.RemoveSubstring(1,1);
				}
			}
		day.ConvertToUInt(&itsDay);
		itsShortDate = itsMonth + " " + day;
		time_t now;
		struct tm *local_time;
		time(&now);
		local_time = localtime(&now);
		if (itsYear != (JIndex)(local_time->tm_year + 1900))
			{
			JString year	= JString(itsYear, JString::kBase10);
			itsShortDate += " " + year;
			}
		return;
		}
	else
		{
		itsShortDate = itsDate;
		}
}
void
GFGLink::ParseLine
	(
	const JString& data
	)
{
	// we only care about virtual functions
	JBoolean required	= kJFalse;
	if (data.Contains("implementation:pure virtual"))
		{
		required	= kJTrue;
		}
	else if (!data.Contains("implementation:virtual"))
		{
		return;
		}

	JArray<JIndexRange> subList;
	if (memberLine.Match(data, &subList))
		{
		JIndexRange sRange	= subList.GetElement(2);
		JString name		= data.GetSubstring(sRange);
		if (name.BeginsWith("~"))
			{
			return;
			}

		GFGMemberFunction* fn	= jnew GFGMemberFunction();
		assert(fn != NULL);

		fn->SetFnName(name);
		fn->ShouldBeRequired(required);

		sRange	= subList.GetElement(3);
		JIndex line;
		JString lineStr		= data.GetSubstring(sRange);
		lineStr.ConvertToUInt(&line);

		sRange	= subList.GetElement(4);
		JString base		= data.GetSubstring(sRange);
		if (base != itsCurrentClass)
			{
			jdelete fn;
			return;
			}

		sRange	= subList.GetElement(5);
		JString access		= data.GetSubstring(sRange);
		if (access == "protected")
			{
			fn->ShouldBeProtected(kJTrue);
			}

		ParseInterface(fn, line);

		// Override entry from base class so function will only be
		// marked as pure virtual if nobody implemented it.

		JBoolean found;
		const JIndex i =
			itsClassList->SearchSorted1(fn, JOrderedSetT::kAnyMatch, &found);
		if (found)
			{
			itsClassList->DeleteElement(i);
			}
		itsClassList->InsertAtIndex(i, fn);
		}
}
Exemple #25
0
JString
JXFontManager::BuildStdFontName
	(
	const JCharacter*	xName,
	const JSize			size,
	const JFontStyle&	style,
	const JCharacter*	italicStr,
	const JCharacter*	iso
	)
	const
{
	// handle NxM separately

	if (nxmRegex.Match(xName))
		{
		JString xFontStr = xName;
		if (style.bold)
			{
			xFontStr += "bold";
			}
		return xFontStr;
		}

	// any foundry

	JString xFontStr = "-*-";

	// given name

	xFontStr.Append(xName);

	// regular or boldface

	if (style.bold)
		{
		xFontStr.Append("-bold");
		}
	else
		{
		xFontStr.Append("-medium");
		}

	// regular or italic

	if (style.italic)
		{
		xFontStr.Append(italicStr);
		}
	else
		{
		xFontStr.Append("-r");
		}

	// normal character spacing, any pixel size

	xFontStr.Append("-normal-*-*-");

	// font size

	xFontStr.Append( JString(10*(size+2), JString::kBase10) );

	// screen resolution (apparently, we should always just use 75 dpi fonts),
	// any spacing, any avg width, charset to match unicode

	xFontStr.Append("-75-75-*-*-");
	xFontStr.Append(iso);

	// return the result

	return xFontStr;
}
void
GMessageHeader::SetHeader
	(
	const JString& header
	)
{
	itsHeader = header;
	itsHeader.TrimWhitespace();
	return;
	JArray<JIndexRange> subList;
	JBoolean matched = yearRegex.Match(itsHeader, &subList);
	if (matched)
		{
		JIndexRange sRange = subList.GetElement(2);
		JString year = itsHeader.GetSubstring(sRange);
		year.ConvertToUInt(&itsYear);
		}

	matched = timeRegex1.Match(itsHeader, &subList);
	if (matched)
		{
		JIndexRange sRange = subList.GetElement(2);
		itsTime = itsHeader.GetSubstring(sRange);
		if (itsYear == 0)
			{
			sRange = subList.GetElement(3);
			JString year = itsHeader.GetSubstring(sRange);
			year.ConvertToUInt(&itsYear);
			}
		}
	else
		{
		matched = timeRegex2.Match(itsHeader, &subList);
		if (matched)
			{
			JIndexRange sRange = subList.GetElement(2);
			itsTime = itsHeader.GetSubstring(sRange);
			if (itsYear == 0)
				{
				sRange = subList.GetElement(3);
				JString year = itsHeader.GetSubstring(sRange);
				year.ConvertToUInt(&itsYear);
				}
			}
		}
	matched = dateRegex.Match(itsHeader, &subList);
	if (matched)
		{
		JIndexRange sRange = subList.GetElement(2);
		JString dow	= itsHeader.GetSubstring(sRange);
		sRange		= subList.GetElement(3);
		itsMonth	= itsHeader.GetSubstring(sRange);
		sRange = subList.GetElement(4);
		JString day = itsHeader.GetSubstring(sRange);
		day.ConvertToUInt(&itsDay);
		itsShortDate	= itsMonth + " " + day;

		time_t now;
		struct tm *local_time;
		time(&now);
		local_time = localtime(&now);
		if (itsYear != (JIndex)(local_time->tm_year + 1900))
			{
			JString year	= JString(itsYear, JString::kBase10);
			itsShortDate += " " + year;
			}

		itsDate			= dow + ", " + day + " " + itsMonth + " " + JString(itsYear) + " " + itsTime;
		}
}
Exemple #27
0
void
LLDBGetAssembly::HandleSuccess
	(
	const JString& cmdData
	)
{
	LLDBLink* link = dynamic_cast<LLDBLink*>(CMGetLink());
	if (link == NULL)
		{
		return;
		}

	lldb::SBCommandInterpreter interp = link->GetDebugger()->GetCommandInterpreter();
	if (!interp.IsValid())
		{
		return;
		}

	const CMLocation& loc = (GetDirector())->GetDisassemblyLocation();

	const JString cmd = "disassemble -n " + JPrepArgForExec(loc.GetFunctionName());
	lldb::SBCommandReturnObject result;
	interp.HandleCommand(cmd, result);

	JPtrArray<JString> addrList(JPtrArrayT::kDeleteAll);
	JString instText;

	if (result.IsValid() && result.Succeeded() && result.HasResult())
		{
		std::istringstream input(result.GetOutput());
		JString line, s;
		JSize maxOffsetLength = 0;
		while (!input.eof() && !input.fail())
			{
			line = JReadLine(input);

			JIndex i;
			if (line.LocateSubstring(":", &i) && i < line.GetLength())
				{
				s = line.GetSubstring(1, i-1);
				if (s.BeginsWith("->") && s.GetLength() > 2)
					{
					s = s.GetSubstring(3, s.GetLength());
					}
				s.TrimWhitespace();
				addrList.Append(s);

				JIndexRange r;
				if (offsetPattern.Match(s, &r))
					{
					maxOffsetLength = JMax(maxOffsetLength, r.GetLength());
					}

				if (!instText.IsEmpty())
					{
					instText.AppendCharacter('\n');
					}
				s = line.GetSubstring(i+1, line.GetLength());
				s.TrimWhitespace();
				instText.Append(s);
				}
			}

		const JSize count = addrList.GetElementCount();
		for (JIndex i=1; i<count; i++)
			{
			JString* s = addrList.NthElement(i);
			JIndexRange r;
			if (offsetPattern.Match(*s, &r))
				{
				const JSize pad = maxOffsetLength - r.GetLength();
				for (JIndex j=0; j<pad; j++)
					{
					s->InsertCharacter('0', r.first+2);
					}
				}
			}
		}

	(GetDirector())->DisplayDisassembly(&addrList, instText);
}
void
CBCompileDocument::AppendText
	(
	const JString& origText
	)
{
	const JString* text = &origText;
	JBoolean deleteText = kJFalse;
	if (strchr(*text, kMultibyteMarker) != NULL)
		{
		JString* s = jnew JString(origText);
		assert( s != NULL );
		text       = s;
		deleteText = kJTrue;

		JSize length = s->GetLength();
		for (JIndex i=1; i<=length; i++)
			{
			if (s->GetCharacter(i) == kMultibyteMarker && i <= length-2)
				{
				const unsigned char c1 = s->GetCharacter(i+1);
				const unsigned char c2 = s->GetCharacter(i+2);
				const JIndex u = (((unsigned int) (unsigned char) c1) << 8) |
								 ((unsigned int) (unsigned char) c2);

				if (u == 32920 || u == 32921)
					{
					s->ReplaceSubstring(i, i+2, "'");
					}
				else
					{
					std::cout << "jcc: AppendText: unicode: " << u << std::endl;
					s->ReplaceSubstring(i, i+2, "\x80");
					}

				length -= 2;
				}
			}
		}

	const JBoolean isJavacError = javacOutputRegex.Match(*text);

	JIndexRange gccPrevLineRange, gccRange;
	const JBoolean isGCCError = JI2B(!isJavacError && gccErrorRegex.Match(*text, &gccRange));

	JIndexRange flexRange;
	const JBoolean isFlexError = flexErrorRegex.Match(*text, &flexRange);

	JIndexRange bisonRange;
	const JBoolean isBisonError = bisonErrorRegex.Match(*text, &bisonRange);

	JIndexRange makeRange;
	const JBoolean isMakeError = JI2B(
		makeErrorRegex.Match(*text, &makeRange) && !text->EndsWith(makeIgnoreErrorStr) );

	JArray<JIndexRange> absoftRangeList;
	const JBoolean isAbsoftError = absoftErrorRegex.Match(*text, &absoftRangeList);

	JArray<JIndexRange> maven2RangeList;
	const JBoolean isMaven2Error = maven2ErrorRegex.Match(*text, &maven2RangeList);

	JArray<JIndexRange> maven3RangeList;
	const JBoolean isMaven3Error = maven3ErrorRegex.Match(*text, &maven3RangeList);

	if (isGCCError &&
		gccErrorRegex.Match(itsPrevLine, &gccPrevLineRange) &&
		gccPrevLineRange == gccRange &&
		JCompareMaxN(itsPrevLine, *text, gccRange.last, kJTrue))
		{
		JString s = *text;
		s.RemoveSubstring(1, gccRange.last - 1);
		s.Prepend(" /");

		// in front of 1 or 2 trailing newlines

		CBTextEditor* te = GetTextEditor();
		te->SetCaretLocation(te->GetTextLength() - (theDoubleSpaceFlag ? 1 : 0));
		te->Paste(s);
		}
	else if (!isJavacError && !isGCCError &&
			 gccErrorRegex.Match(itsPrevLine, &gccPrevLineRange) &&
			 text->BeginsWith(gccMultilinePrefix) &&
			 text->GetLength() > kGCCMultilinePrefixLength &&
			 !isspace(text->GetCharacter(kGCCMultilinePrefixLength+1)))
		{
		JString s = *text;
		s.RemoveSubstring(1, strlen(gccMultilinePrefix));

		CBTextEditor* te = GetTextEditor();
		te->SetCaretLocation(te->GetTextLength() - (theDoubleSpaceFlag ? 1 : 0));
		te->Paste(s);
		}
	else
		{
		CBTextEditor* te        = GetTextEditor();
		const JIndex startIndex = te->GetTextLength() + 1;

		CBExecOutputDocument::AppendText(*text);
		if (theDoubleSpaceFlag)
			{
			te->Paste("\n");
			}

		itsPrevLine = *text;

		// display file name in bold and activate Errors menu

		JIndexRange boldRange;
		if (isJavacError)
			{
			JArray<JIndexRange> javacMatchList;
			if (javacErrorRegex.Match(*text, &javacMatchList))
				{
				const JIndexRange r = javacMatchList.GetElement(2);
				boldRange.Set(startIndex + r.first-1, startIndex + r.last-1);
				}
			}
		else if (isGCCError)
			{
			boldRange.Set(startIndex, startIndex + gccRange.first - 1);
			}
		else if (isFlexError)
			{
			boldRange.Set(startIndex+1, startIndex + flexRange.first);
			}
		else if (isBisonError)
			{
			boldRange.Set(startIndex+2, startIndex + bisonRange.first + 1);
			}
		else if (isMakeError)
			{
			boldRange.SetFirstAndLength(startIndex, text->GetLength());
			}
		else if (isAbsoftError)
			{
			boldRange  = absoftRangeList.GetElement(2);
			boldRange += startIndex-1;
			}
		else if (isMaven2Error)
			{
			boldRange  = maven2RangeList.GetElement(2);
			boldRange += startIndex-1;
			}
		else if (isMaven3Error)
			{
			boldRange  = maven3RangeList.GetElement(2);
			boldRange += startIndex-1;
			}

		if (!boldRange.IsEmpty())
			{
			te->JTextEditor::SetFont(boldRange.first, boldRange.last, GetErrorFont(), kJTrue);

			if (!itsHasErrorsFlag)
				{
				itsHasErrorsFlag = kJTrue;
				itsErrorMenu->Activate();

				JXWindow* window    = GetWindow();
				JString windowTitle = window->GetTitle();
				windowTitle.SetCharacter(1, '!');
				windowTitle.SetCharacter(2, '!');
				windowTitle.SetCharacter(3, '!');
				window->SetTitle(windowTitle);
				}
			}
		}

	if (deleteText)
		{
		jdelete text;
		}
}
void
CMVarNode::ConvertToBase()
{
	itsCanConvertBaseFlag = kJFalse;
	if (itsOrigValue != NULL && !itsOrigValue->IsEmpty())
		{
		JTree* tree;
		if (itsValue != *itsOrigValue && GetTree(&tree))
			{
			tree->BroadcastChange(this);
			}
		itsValue = *itsOrigValue;
		}

	if (itsBase == 0 || itsIsPointerFlag)
		{
		return;		// avoid constructing matchList
		}

	JArray<JIndexRange> matchList;
	if (valuePattern.Match(itsValue, &matchList))
		{
		JString vStr = itsValue.GetSubstring(matchList.GetElement(2));

		JUInt v;
		itsCanConvertBaseFlag = JI2B(
			vStr.ConvertToUInt(&v, vStr.GetFirstCharacter() == '0' ? 8 : 10) &&
			(itsBase != 1 || (0 <= v && v <= 255)));
		if (itsCanConvertBaseFlag)
			{
			// save value for when base reset to "default"

			itsOrigValue = new JString(itsValue);
			assert( itsOrigValue != NULL );

			// replace only the value, preserving whatever else is there

			if (itsBase == 1)
				{
				assert( 0 <= v && v <= 255 );

				vStr  = JString(v, JString::kBase16, kJTrue);
				vStr += " '";

				JBoolean found = kJFalse;
				for (JIndex i=0; i<kSpecialCharCount; i++)
					{
					if (JCharacter(v) == kSpecialCharInfo[i].c)
						{
						vStr += kSpecialCharInfo[i].s;
						found = kJTrue;
						}
					}
				if (!found)
					{
					vStr.AppendCharacter(v);
					}

				vStr.AppendCharacter('\'');
				}
			else
				{
				vStr = JString(v, (JString::Base) itsBase, kJTrue);
				if (itsBase == 8)
					{
					vStr.PrependCharacter('0');
					}
				}

			JIndexRange r;
			itsValue.ReplaceSubstring(matchList.GetElement(2), vStr, &r);

			JTree* tree;
			if (GetTree(&tree))
				{
				tree->BroadcastChange(this);
				}
			}
		}
}
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 );
}