JBoolean
JXStringCompletionMenu::AddString
	(
	const JCharacter* str
	)
{
	const JIndex i = GetItemCount()+1;
	if (i <= kMaxItemCount)
		{
		if (IsEmpty())
			{
			JFontID id;
			JSize size;
			JFontStyle style;
			itsTE->GetDefaultFont(&id, &size, &style);
			SetDefaultFont(id, size, style, kJFalse);
			}

		JString shortcut;
		if (i <= 10)
			{
			shortcut = JString(i%10, JString::kBase10);
			}
		else if (i <= 36)
			{
			shortcut = " ";
			shortcut.SetCharacter(1, 'a' + i - 11);
			}

		JString s = kItemPrefixStr;
		s += str;
		if (!shortcut.IsEmpty())
			{
			s.SetCharacter(1, shortcut.GetFirstCharacter());
			s.SetCharacter(3, '-');
			}

		AppendItem(s, kPlainType, shortcut);
		return kJTrue;
		}
	else if (i == kMaxItemCount+1)
		{
		AppendItem(kTruncationStr);
		SetItemFont(i, JGetDefaultFontName(), kJDefaultFontSize,
					JFontStyle(kJFalse, kJTrue, 0, kJFalse));
		return kJFalse;
		}
	else
		{
		return kJFalse;
		}
}
void
JCheckSiteName
	(
	const JCharacter*	encSiteSuffix,
	const JCharacter	siteCode,
	const JCharacter*	map[],
	const JSize			size
	)
{
	JString siteSuffix = encSiteSuffix;
	const JSize len    = siteSuffix.GetLength();
	for (JIndex i=1; i<=len; i++)
		{
		siteSuffix.SetCharacter(i, siteSuffix.GetCharacter(i) ^ siteCode);
		}

	map[1] = siteSuffix.GetCString();

	if (!(JGetHostName()).EndsWith(siteSuffix, kJFalse))
		{
		const JString msg = JGetString(kWrongSiteID, map, size);
		(JGetUserNotification())->DisplayMessage(msg);
		exit(0);
		}
}
예제 #3
0
JString
JGetPermissionsString
	(
	const mode_t mode
	)
{
	JString modeString = "---------";
	if (mode & S_IRUSR)
		{
		modeString.SetCharacter(1, 'r');
		}
	if (mode & S_IWUSR)
		{
		modeString.SetCharacter(2, 'w');
		}
	if (mode & S_IXUSR)
		{
		modeString.SetCharacter(3, 'x');
		}
	if (mode & S_IRGRP)
		{
		modeString.SetCharacter(4, 'r');
		}
	if (mode & S_IWGRP)
		{
		modeString.SetCharacter(5, 'w');
		}
	if (mode & S_IXGRP)
		{
		modeString.SetCharacter(6, 'x');
		}
	if (mode & S_IROTH)
		{
		modeString.SetCharacter(7, 'r');
		}
	if (mode & S_IWOTH)
		{
		modeString.SetCharacter(8, 'w');
		}
	if (mode & S_IXOTH)
		{
		modeString.SetCharacter(9, 'x');
		}

	return modeString;
}
const JCharacter*
SyGApplication::GetNMShortcut
	(
	JIndex* i
	)
	const
{
	if (*i <= kShortcutKeyCount)
		{
		kShortcutStr.SetCharacter(6, kShortcutKey[*i-1]);
		(*i)++;
		return kShortcutStr.GetCString();
		}
	else
		{
		return NULL;
		}
}
void
JDirInfo::AppendRegex
	(
	const JCharacter*	origStr,
	JString*			regexStr
	)
{
JIndex i;

	JString str = origStr;

	// Convert wildcard multiples (*) to regex multiples (.*)
	// and wildcard singles (?) to regex singles (.)

	for (i = str.GetLength(); i>=1; i--)
		{
		const JCharacter c = str.GetCharacter(i);
		if (c == '*')
			{
			str.InsertSubstring(".", i);
			}
		else if (c == '?')
			{
			str.SetCharacter(i, '.');
			}
		else if (JRegex::NeedsBackslashToBeLiteral(c))
			{
			str.InsertSubstring("\\", i);
			}
		}

	// Add instructions that it must match the entire file name.

	str.PrependCharacter('^');
	str.AppendCharacter('$');

	// append to regexStr

	if (!regexStr->IsEmpty())
		{
		regexStr->AppendCharacter('|');
		}
	*regexStr += str;
}
JBoolean
JNameValid
	(
	const JCharacter* str
	)
{
JIndex i;

	const JSize length = strlen(str);
	if (length == 0)
		{
		(JGetUserNotification())->ReportError("Names cannot be empty.");
		return kJFalse;
		}

	const JCharacter greekPrefix = JPGetGreekCharPrefixChar();

	for (i=1; i<=length; i++)
		{
		const JCharacter c = str[i-1];

		JBoolean valid = JConvertToBoolean( (i>1 && JIsAlnum(c)) || (i==1 && JIsAlpha(c)) );
		if (i == 1)
			{
			valid = JConvertToBoolean( valid || c == greekPrefix );
			}
		else if (i > 1)
			{
			JSize j = 0;
			while (!valid && j < validCharCount)
				{
				valid = JConvertToBoolean( c == validChar[j] );
				j++;
				}
			}

		if (!valid)
			{
			JString errorStr = "Illegal character 'x";
			errorStr.SetCharacter(errorStr.GetLength(), c);
			errorStr += "' in \"";
			errorStr += str;
			errorStr += "\".";
			(JGetUserNotification())->ReportError(errorStr);
			return kJFalse;
			}
		}

	const JSize nameCount           = JPGetNamedConstCount();
	const JNamedConstInfo* nameInfo = JPGetNamedConstInfo();

	for (i=1; i<=nameCount; i++)
		{
		if (strcmp(str, nameInfo[i-1].name) == 0)
			{
			JString errorStr = "\"";
			errorStr += nameInfo[i-1].name;
			errorStr += "\" is already used to represent a constant.";
			(JGetUserNotification())->ReportError(errorStr);
			return kJFalse;
			}
		}

	return kJTrue;
}
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;
		}
}
예제 #8
0
void
JXDocumentManager::UpdateDocumentMenu
	(
	JXDocumentMenu* menu
	)
{
	if (menu->IsOpen())
		{
		DocumentMenusNeedUpdate();
		return;
		}

	menu->RemoveAllItems();

	// It almost always is sorted, so we only pay O(N) instead of O(N^2).
	// (but we can't sort when document is created!)

	if (!itsDocList->IsSorted())
		{
		itsDocList->Sort();
		}

	const JSize count = itsDocList->GetElementCount();
	for (JIndex i=1; i<=count; i++)
		{
		DocInfo info        = itsDocList->GetElement(i);
		const JString& name = (info.doc)->GetName();

		menu->AppendItem(name);
		if ((info.doc)->NeedsSave())
			{
			menu->SetItemFontStyle(i, (menu->GetColormap())->GetDarkRedColor());
			}

		const JXImage* icon;
		if ((info.doc)->GetMenuIcon(&icon) &&
			icon->GetDisplay()  == menu->GetDisplay() &&
			icon->GetColormap() == menu->GetColormap())
			{
			menu->SetItemImage(i, const_cast<JXImage*>(icon), kJFalse);
			}

		if (itsWantShortcutFlag &&
			kFirstShortcut <= info.shortcut && info.shortcut <= kLastShortcut)
			{
			const JXMenu::Style style = JXMenu::GetDefaultStyle();
			JString nmShortcut;
			if (style == JXMenu::kWindowsStyle)
				{
				nmShortcut = "Ctrl-0";
				}
			else
				{
				assert( style == JXMenu::kMacintoshStyle );
				nmShortcut = "Meta-0";
				}
			nmShortcut.SetCharacter(nmShortcut.GetLength(),
									kShortcutChar [ info.shortcut ]);
			menu->SetItemNMShortcut(i, nmShortcut);
			}
		}
}