void
SyGViewManPageDialog::SetFunction
	(
	const JCharacter* historyStr
	)
{
	JString fnName = historyStr;

	JCharacter manIndex[] = { '\0', '\0' };
	if (fnName.GetLastCharacter() == ')')
		{
		manIndex[0] = fnName.GetCharacter(fnName.GetLength()-1);
		fnName.RemoveSubstring(fnName.GetLength()-3, fnName.GetLength());
		}

	if (manIndex[0] == '*')
		{
		manIndex[0] = '\0';
		itsAproposCheckbox->SetState(kJTrue);
		}
	else
		{
		itsAproposCheckbox->SetState(kJFalse);
		}

	itsFnName->SetText(fnName);
	itsManIndex->SetText(manIndex);
}
inline JBoolean
jTranslateRemoteToLocal1
	(
	const JCharacter*	host,
	const JString&		remotePath,
	const JCharacter*	mountDev,
	const JCharacter*	mountDir,
	JString*			localPath
	)
{
	const JString dev = mountDev;
	JIndex hostEndIndex;
	if (dev.LocateSubstring(":/", &hostEndIndex) && hostEndIndex > 1)
		{
		JString h = dev.GetSubstring(1, hostEndIndex-1);
		jGetFullHostName(&h);

		JString p = dev.GetSubstring(hostEndIndex+1, dev.GetLength());
		JAppendDirSeparator(&p);		// force complete name when check BeginsWith()

		if (host == h && remotePath.BeginsWith(p))
			{
			*localPath = remotePath;
			localPath->ReplaceSubstring(1, p.GetLength()-1, mountDir);
			JCleanPath(localPath);
			return kJTrue;
			}
		}

	return kJFalse;
}
예제 #3
0
	JString JString::operator+(const JString& rhs)
	{
		JString ret;
		unsigned _lenTotal = nLength + rhs.GetLength();
		ret.Init(_lenTotal);

		strncat_s(ret, ret.GetLength() + 1, pBuffer, nLength);
		strncat_s(ret, ret.GetLength() + 1, rhs, rhs.GetLength());

		return ret;
	}
JBoolean
CBStringCompleter::Complete
	(
	JTextEditor*			te,
	const JBoolean			includeNS,
	JXStringCompletionMenu*	menu
	)
{
	assert( menu != NULL );

	JIndex caretIndex;
	if (!te->GetCaretLocation(&caretIndex))
		{
		return kJFalse;
		}

	const JString& text = te->GetText();
	JIndex i            = caretIndex;
	while (i > 1 && IsWordCharacter(text, i-1, includeNS))
		{
		i--;
		}

	if (i == caretIndex)
		{
		return kJFalse;
		}

	JString s;
	const JString prefix   = text.GetSubstring(i, caretIndex-1);
	const JSize matchCount = Complete(prefix, &s, menu);
	if (matchCount > 0 &&
		s.GetLength() > prefix.GetLength())
		{
		s.RemoveSubstring(1, prefix.GetLength());
		te->Paste(s);
		menu->ClearRequestCount();
		return kJTrue;
		}
	else if (matchCount > 1)
		{
		menu->CompletionRequested(prefix.GetLength());
		return kJTrue;
		}
	else if (matchCount == 0 && includeNS)
		{
		// try once more without namespace
		return Complete(te, kJFalse, menu);
		}

	return kJFalse;
}
inline JBoolean
jTranslateLocalToRemote1
	(
	const JString&		localPath,
	const JCharacter*	mountDev,
	const JCharacter*	mountDir,
	JBoolean*			found,
	JString*			host,
	JString*			remotePath
	)
{
	if (!JIsSamePartition(localPath, mountDir))
		{
		return kJFalse;
		}

	const JString dev = mountDev;
	JIndex hostEndIndex;
	if (dev.LocateSubstring(":/", &hostEndIndex) && hostEndIndex > 1)
		{
		*host = dev.GetSubstring(1, hostEndIndex-1);

		#ifdef _J_CYGWIN
		if (host->GetLength() == 1 &&
			'A' <= host->GetFirstCharacter() && host->GetFirstCharacter() <= 'Z')
			{
			*host       = JGetHostName();
			*remotePath = localPath;
			JCleanPath(remotePath);
			*found = kJTrue;
			return kJTrue;
			}
		#endif

		jGetFullHostName(host);

		*remotePath = dev.GetSubstring(hostEndIndex+1, dev.GetLength());
		JAppendDirSeparator(remotePath);

		// use JIndexRange to allow empty

		JIndexRange r(strlen(mountDir)+1, localPath.GetLength());
		*remotePath += localPath.GetSubstring(r);
		JCleanPath(remotePath);

		*found = kJTrue;
		}

	return kJTrue;
}
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
		{
void
GMMIMEParser::WriteAttachment
	(
	const JString&		data,
	const GMIMEHeader&	header
	)
{
	JString filename = header.GetFileName();
	if (filename.IsEmpty())
		{
		const JError err = JCreateTempFile(itsAttachDir, NULL, &filename);
		if (!err.OK())
			{
			err.ReportIfError();
			return;
			}
		}
	else
		{
		filename = JCombinePathAndName(itsAttachDir, filename);
		}

	AdjustAttachmentName(header, &filename);
	std::ofstream os(filename);
	if (header.GetEncoding() == kBase64Encoding)
		{
		std::istrstream is(data.GetCString(), data.GetLength());
		JDecodeBase64(is, os);
		}
	else
		{
		data.Print(os);
		}
}
JString
JPrepArgForExec
	(
	const JCharacter* arg
	)
{
	JString str    = arg;
	JBoolean quote = kJFalse;

	const JSize length = str.GetLength();
	for (JIndex i=length; i>=1; i--)
		{
		const JCharacter c = str.GetCharacter(i);
		if (c == '"' || c == '\'' || c == '\\' || c == ';')
			{
			str.InsertSubstring("\\", i);
			}
		else if (isspace(c))
			{
			quote = kJTrue;
			}
		}

	if (quote)
		{
		str.PrependCharacter('"');
		str.AppendCharacter('"');
		}
	return str;
}
void
JPTPrinter::InvertPageOrder
	(
	const JString&	text,
	ostream&		output
	)
	const
{
	JIndex endIndex   = text.GetLength() + 1;
	JIndex startIndex = endIndex - 1;
	while (text.LocatePrevSubstring(kPageSeparatorStr, kPageSeparatorStrLength, &startIndex))
		{
		const JIndex i = startIndex + kPageSeparatorStrLength;
		if (endIndex > i)
			{
			output.write(text.GetCString() + i-1, endIndex - i);
			}
		output << kPageSeparatorStr;

		endIndex = startIndex;
		startIndex--;
		}

	if (endIndex > 1)
		{
		output.write(text.GetCString(), endIndex-1);
		}
}
예제 #10
0
void
CBPTPrinter::PrintHeader
	(
	ostream&		output,
	const JIndex	pageIndex
	)
{
	if (itsPrintHeaderFlag)
		{
		const JString dateStr = JGetTimeStamp();

		JString pageStr(pageIndex, 0);
		pageStr.Prepend("Page ");

		itsHeaderName.Print(output);
		output << '\n';

		dateStr.Print(output);
		const JInteger spaceCount =
			GetPageWidth() - dateStr.GetLength() - pageStr.GetLength();
		for (JInteger i=1; i<=spaceCount; i++)
			{
			output << ' ';
			}
		pageStr.Print(output);
		output << "\n\n\n";
		}
}
예제 #11
0
JBoolean
JSplitPathAndName
	(
	const JCharacter*	fullName,
	JString*			path,
	JString*			name
	)
{
	assert( !JStringEmpty(fullName) );

	JString pathAndName = fullName;
	assert( pathAndName.GetLastCharacter() != ACE_DIRECTORY_SEPARATOR_CHAR );

	JIndex i;
	if (pathAndName.LocateLastSubstring(ACE_DIRECTORY_SEPARATOR_STR, &i))
		{
		*path = pathAndName.GetSubstring(1,i);
		*name = pathAndName.GetSubstring(i+1, pathAndName.GetLength());

		JCleanPath(path);
		return kJTrue;
		}
	else
		{
		*path = JGetCurrentDirectory();
		*name = pathAndName;
		return kJFalse;
		}
}
void
JMemoryManager::HandleDebugRequest()
	const
{
	assert( itsLink != NULL );

	JString text;
	const JBoolean ok = itsLink->GetNextMessage(&text);
	assert( ok );

	std::string s(text, text.GetLength());
	std::istringstream input(s);

	JFileVersion vers;
	input >> vers;
	if (vers != kJMemoryManagerDebugVersion)
		{
		cerr << "JMemoryManager::HandleDebugRequest received version (" << vers;
		cerr << ") different than expected (" << kJMemoryManagerDebugVersion << ")" << endl;
		return;
		}

	long type;
	input >> type;

	if (type == kRunningStatsMessage)
		{
		SendRunningStats();
		}
	else if (type == kRecordsMessage)
		{
		SendRecords(input);
		}
}
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);
		}
}
void
CBCommandPathInput::AdjustStylesBeforeRecalc
	(
	const JString&		buffer,
	JRunArray<JFont>*	styles,
	JIndexRange*		recalcRange,
	JIndexRange*		redrawRange,
	const JBoolean		deletion
	)
{
	if (!buffer.IsEmpty() && buffer.GetFirstCharacter() == '@')
		{
		const JColormap* colormap = GetColormap();
		const JSize totalLength   = buffer.GetLength();
		JFont f                   = styles->GetFirstElement();
		styles->RemoveAll();
		f.SetColor(colormap->GetBlackColor());
		styles->AppendElements(f, totalLength);
		*redrawRange += JIndexRange(1, totalLength);
		}
	else
		{
		return JXPathInput::AdjustStylesBeforeRecalc(buffer, styles, recalcRange,
													 redrawRange, deletion);
		}
}
void
JAbsoluteToRelativePath
	(
	const JCharacter* relativeTo,
	JString* path
	)
{
	JString base(relativeTo);
	JString test(*path);
	JAppendDirSeparator(&base);
	JAppendDirSeparator(&test);
	JIndex charindex = 2;
	JBoolean success = kJTrue;
	JString compare;
	JString store;
	success = test.LocateNextSubstring("/", &charindex);
	if (success)
		{
		compare = test.GetSubstring(1, charindex);
		}
	while (success && base.BeginsWith(compare))
		{
		store = compare;
		success = test.LocateNextSubstring("/", &charindex);
		if (success)
			{
			compare = test.GetSubstring(1, charindex);
			charindex ++;
			}
		}
	if (test.GetLength() >= store.GetLength())
		{
		test.RemoveSubstring(1, store.GetLength());
		}
	if (base.GetLength() >= store.GetLength())
		{
		base.RemoveSubstring(1, store.GetLength());
		}
	success = base.LocateSubstring("/", &charindex);
	while (success)
		{
		base.RemoveSubstring(1, charindex);
		test.Prepend("../");
		success = base.LocateSubstring("/", &charindex);
		}
	*path = test;
}
예제 #16
0
void
GMMIMEParser::ParseContentParameters
	(
	const JString&		text,
	JPtrArray<JString>*	strings
	)
{
	JString tmp = text;
	JString* str;
	JIndex findex;
	while (tmp.LocateSubstring("=", &findex) && findex > 1)
		{
		str = new JString(tmp.GetSubstring(1, findex - 1));
		assert(str != NULL);
		str->TrimWhitespace();
		str->ToLower();
		strings->Append(str);

		tmp.RemoveSubstring(1, findex);
		tmp.TrimWhitespace();

		// now we need to get the corresponding value.
		// we need to check for quotes first.
		JIndex index = 1;
		if (tmp.GetLength() > 1 && tmp.GetCharacter(1) == '\"')
			{
			FindStringEnd(tmp, &index);
			str = new JString(tmp.GetSubstring(2, index-1));
			assert(str != NULL);
			if (tmp.LocateSubstring(";", &findex))
				{
				tmp.RemoveSubstring(1, findex);
				}
			}
		else if (tmp.LocateSubstring(";", &index))
			{
			str = new JString();
			assert(str != NULL);
			if (index > 1)
				{
				*str = tmp.GetSubstring(1, index-1);
				}
			tmp.RemoveSubstring(1, index);
			}
		else
			{
			str = new JString(tmp);
			assert(str != NULL);
			}

		str->TrimWhitespace();
		strings->Append(str);

		tmp.TrimWhitespace();
		}
}
void
GDBGetSourceFileList::HandleSuccess
	(
	const JString& origData
	)
{
	if (origData.BeginsWith("Source files for which symbols have been read in:"))
		{
		(JXGetApplication())->DisplayBusyCursor();

		JXFileListTable* table = (GetFileList())->GetTable();
		table->RemoveAllFiles();

		JString data = origData;
		JIndex i,j;
		while (data.LocateSubstring("Source files for which symbols", &i))
			{
			j = i;
			if (!data.LocateNextSubstring(":", &j))
				{
				j = data.GetLength();
				}
			data.ReplaceSubstring(i, j, ",");
			}
		data.TrimWhitespace();		// no comma after last file

		std::istrstream input(data.GetCString(), data.GetLength());
		JString fullName, path, name, s;
		JBoolean foundDelimiter;
		do
			{
			input >> ws;
			fullName = JReadUntil(input, ',', &foundDelimiter);
			fullName.TrimWhitespace();
			if (!fullName.IsEmpty())
				{
				JSplitPathAndName(fullName, &path, &name);
				table->AddFile(name);
				}
			}
			while (foundDelimiter);
		}
예제 #18
0
	JString JString::operator+(const char* rhs)
	{
		JString ret;
		unsigned _lenTotal = nLength + strlen(rhs);
		ret.Init(_lenTotal);

		strncat_s(ret, ret.GetLength() + 1, pBuffer, nLength);
		strncat_s(ret, ret.GetLength() + 1, rhs, strlen(rhs));

		return ret;
	}
예제 #19
0
JString
JConvertToTimeStamp
	(
	const time_t t
	)
{
	JString timeStamp  = ctime(&t);
	const JSize length = timeStamp.GetLength();
	timeStamp.RemoveSubstring(length, length);
	return timeStamp;
}
예제 #20
0
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;
}
예제 #21
0
JBoolean
CBHTMLStyler::GetXMLStyle
	(
	const JString&	tagName,
	JFontStyle*		style
	)
{
	JIndex i;
	if (!tagName.LocateLastSubstring(":", &i))
		{
		return kJFalse;
		}

	// tag name takes priority over XML namespaces

	JString s;
	if (i < tagName.GetLength())
		{
		s = tagName.GetSubstring(i+1, tagName.GetLength());
		if (GetWordStyle(s, style))
			{
			itsLatestTagName = s;
			return kJTrue;
			}
		}

	do
		{
		s = tagName.GetSubstring(1, i);
		if (GetWordStyle(s, style))
			{
			itsLatestTagName = s;
			return kJTrue;
			}

		i--;	// skip past the one we found
		}
		while (itsLatestTagName.LocatePrevSubstring(":", &i));

	return kJFalse;
}
JBoolean
SplitClassNameAndArgs
	(
	const JString&	str,
	JString*		name,
	JString*		args
	)
{
	JIndex i;
	const JBoolean hasArgs = str.LocateSubstring("(", &i);
	if (hasArgs && 1 < i && i < str.GetLength())
		{
		*name = str.GetSubstring(1, i-1);
		*args = str.GetSubstring(i+1, str.GetLength());

		name->TrimWhitespace();
		args->TrimWhitespace();
		return kJTrue;
		}
	else if (hasArgs && i == 1)
		{
		cerr << "No class name in " << str << endl;
		name->Clear();
		args->Clear();
		return kJFalse;
		}
	else
		{
		if (hasArgs)
			{
			*name = str.GetSubstring(1, i-1);
			}
		else
			{
			*name = str;
			}
		name->TrimWhitespace();
		args->Clear();
		return kJTrue;
		}
}
void
CBCSharpScanner::Undo
	(
	const JIndexRange&	range,
	const JString&		text
	)
{
	for (JIndex i=text.GetLength(); i>=1; i--)
		{
		yyunput(text.GetCharacter(i), yytext);
		}

	itsCurrentRange.first = itsCurrentRange.last = range.first - 1;
}
JString
CMLineAddressTable::BuildAddress
	(
	const JString& addr
	)
{
	JString s = addr;
	JIndex i;
	if (s.LocateSubstring(" ", &i))
		{
		s.RemoveSubstring(i, s.GetLength());
		}

	s.Prepend("0x");
	return s;
}
JBoolean
CBCPreprocessor::IsEntireWord
	(
	const JString&	text,
	const JIndex	wordIndex,
	const JSize		wordLength
	)
	const
{
	return JI2B(!(wordIndex > 1 &&
				  IsIDCharacter(text.GetCharacter(wordIndex)) &&
				  IsIDCharacter(text.GetCharacter(wordIndex - 1))) &&
				!(wordIndex + wordLength <= text.GetLength() &&
				  IsIDCharacter(text.GetCharacter(wordIndex + wordLength - 1)) &&
				  IsIDCharacter(text.GetCharacter(wordIndex + wordLength))));
}
inline void
jGetFullHostName
	(
	JString* host
	)
{
	if (!host->Contains("."))
		{
		const JString localhost = JGetHostName();
		JIndex dotIndex;
		if (localhost.LocateSubstring(".", &dotIndex))
			{
			*host += localhost.GetSubstring(dotIndex, localhost.GetLength());
			}
		}
}
예제 #27
0
JBoolean
JXPathInput::GetDroppedDirectory
	(
	const Time		time,
	const JBoolean	reportErrors,
	JString*		dirName
	)
{
	dirName->Clear();

	JXSelectionManager* selMgr = GetSelectionManager();

	Atom returnType;
	unsigned char* data;
	JSize dataLength;
	JXSelectionManager::DeleteMethod delMethod;
	if (selMgr->GetData(GetDNDManager()->GetDNDSelectionName(),
						time, selMgr->GetURLXAtom(),
						&returnType, &data, &dataLength, &delMethod))
		{
		if (returnType == selMgr->GetURLXAtom())
			{
			JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll),
							   urlList(JPtrArrayT::kDeleteAll);
			JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList);
			if (fileNameList.GetElementCount() == 1 &&
				(JDirectoryExists(*(fileNameList.FirstElement())) ||
				 JFileExists(*(fileNameList.FirstElement()))))
				{
				*dirName = *(fileNameList.FirstElement());

				JString homeDir;
				if (JGetHomeDirectory(&homeDir) &&
					dirName->BeginsWith(homeDir))
					{
					dirName->ReplaceSubstring(1, homeDir.GetLength(), "~" ACE_DIRECTORY_SEPARATOR_STR);
					}
				}
			JXReportUnreachableHosts(urlList);
			}

		selMgr->DeleteData(&data, delMethod);
		}

	return !dirName->IsEmpty();
}
예제 #28
0
void
GMMIMEParser::ParseContentDisposition
	(
	const JString&	val,
	GMIMEHeader*	header
	)
{
	// we first need to strip the type. this will be found before the
	// first ';' which will be followed by the parameters.
	JString tVal	= val;
	tVal.TrimWhitespace();
	JSize length	= tVal.GetLength();

	JIndex findex;
	if (tVal.LocateSubstring(";", &findex) && (findex > 1))
		{
		tVal.RemoveSubstring(1, findex);
		tVal.TrimWhitespace();
		}
	else
		{
		return;
		}

	JPtrArray<JString> strings(JPtrArrayT::kDeleteAll);
	ParseContentParameters(tVal, &strings);
	JSize count = strings.GetElementCount();
	for (JIndex i = 1; i <= count; i += 2)
		{
		JString* str = strings.NthElement(i);
		if ((*str == "filename") &&
			(strings.IndexValid(i+1)))
			{
			str	= strings.NthElement(i+1);
			if (str->LocateLastSubstring("/", &findex))
				{
				str->RemoveSubstring(1, findex);
				}
			if (str->LocateLastSubstring("\\", &findex))
				{
				str->RemoveSubstring(1, findex);
				}
			header->SetFileName(*str);
			}
		}
}
void
CBSymbolList::ParseFile
	(
	const JCharacter*		fileName,
	const CBTextFileType	fileType,
	const JFAID_t			id
	)
{
	JString data;
	CBLanguage lang;
	if (ProcessFile(fileName, fileType, &data, &lang))
		{
		std::istrstream input(data.GetCString(), data.GetLength());
		ReadSymbolList(input, lang, fileName, id);
		itsChangedDuringParseFlag = kJTrue;
		}
}
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;
}