JBoolean
JDirInfo::BuildRegexFromWildcardFilter
	(
	const JCharacter*	origFilterStr,
	JString*			regexStr
	)
{
	regexStr->Clear();

	JString filterStr = origFilterStr;
	filterStr.TrimWhitespace();

	if (filterStr.IsEmpty())
		{
		return kJFalse;
		}

	JIndex index;
	while (filterStr.LocateSubstring(" ", &index))
		{
		assert( index > 1 );
		const JString str = filterStr.GetSubstring(1, index-1);

		AppendRegex(str, regexStr);

		filterStr.RemoveSubstring(1, index);
		filterStr.TrimWhitespace();
		}

	assert( !filterStr.IsEmpty() );
	AppendRegex(filterStr, regexStr);
	return kJTrue;
}
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();
		}
}
Пример #3
0
void
XDLink::SendRaw
	(
	const JCharacter* text
	)
{
	if (itsLink != NULL)
		{
		JString s = text;
		s.TrimWhitespace();

		JIndex i;
		while (s.LocateSubstring("  ", &i))
			{
			s.ReplaceSubstring(i, i+1, " ");
			}

		itsLink->SendMessage(s);
		itsLink->StartTimer();

		if (!itsDebuggerBusyFlag)
			{
			itsDebuggerBusyFlag = kJTrue;
			Broadcast(DebuggerBusy());
			}

		Broadcast(DebugOutput(s, kCommandType));
		}
}
Пример #4
0
const JCharacter*
JXMenu::GetDefaultFont
	(
	JSize* size
	)
{
	if (!theDefaultMenuFontInitFlag)
		{
		theDefaultMenuFontInitFlag = kJTrue;
		theDefaultFontName         = JGetDefaultFontName();
		theDefaultFontSize         = kJDefaultFontSize;

		JString fileName;
		if (JExpandHomeDirShortcut(kMenuFontFileName, &fileName))
			{
			ifstream input(fileName);
			input >> ws;
			JString name = JReadLine(input);
			name.TrimWhitespace();
			JSize size;
			input >> size;
			if (input.good())
				{
				theDefaultFontName = name;
				theDefaultFontSize = size;
				}
			}
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);
}
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);
			}
		}
}
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;
		}
}
JString
JXFileHistoryMenu::GetFile
	(
	const JIndex index
	)
	const
{
	JString path;
	const JBoolean ok = GetItemNMShortcut(index, &path);
	assert( ok );
	path.TrimWhitespace();

	return JCombinePathAndName(path, JXTextMenu::GetItemText(index));
}
void
JXTipOfTheDayDialog::AddTip
	(
	JString tip
	)
{
	tip.TrimWhitespace();
	if (tip.IsEmpty())
		{
		return;
		}

	JString* s = new JString(tip);
	assert( s != NULL );
	itsTipList->Append(s);
}
void
GMessageHeader::DecodeMIMEHeader
	(
	JString* header
	)
{
	JArray<JIndexRange> subList;
	JSize count	= encodedMIMEQRegex.MatchAll(*header, &subList);
	JBoolean qType	= kJTrue;
	if (count == 0)
		{
		count	= encodedMIMEBRegex.MatchAll(*header, &subList);
		qType	= kJFalse;
		}
	if (count > 0)
		{
		JString temp;
		JIndex mIndex		= 1;
		const JSize count	= subList.GetElementCount();
		for (JIndex i = 1; i <= count; i++)
			{
			JIndexRange range	= subList.GetElement(i);
//			if ((range.first != mIndex) &&
//				RangeContainsNWS(*header, mIndex, range.first))
//				{
//				temp += header->GetSubstring(mIndex, range.first - 1);
//				}
			if (range.first != mIndex)
				{
				JString trimmed = header->GetSubstring(mIndex, range.first - 1);
				trimmed.TrimWhitespace();
				if (!trimmed.IsEmpty())
					{
					temp += header->GetSubstring(mIndex, range.first - 1);
					}
				}
			temp   += DecodeMIMEWord(qType, header, range);
			mIndex	= range.last + 1;
			}
		if (mIndex < header->GetLength())
			{
			temp   += header->GetSubstring(mIndex, header->GetLength());
			}
		*header = temp;
		}
}
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);
		}
void
WizChatShortcutMenu::CheckForShortcut()
{
	JString nmShortcut;
	const JString& text = itsMessage->GetText();

	const JSize count = GetItemCount();
	for (JIndex i=1; i<=count; i++)
		{
		if (GetItemNMShortcut(i, &nmShortcut))
			{
			nmShortcut.TrimWhitespace();
			if (nmShortcut == text)
				{
				itsMessage->SetText(GetItemText(i));
				return;
				}
			}
		}
}
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);
}
JBoolean
GLPolyFitDialog::OKToDeactivate()
{
	if (!JXDialogDirector::OKToDeactivate())
		{
		return kJFalse;
		}
	if (Cancelled())
		{
		return kJTrue;
		}
	JString name	= itsNameInput->GetText();
	name.TrimWhitespace();
	if (name.IsEmpty())
		{
		JGetUserNotification()->ReportError("You must specify a name for this fit.");
		itsNameInput->Focus();
		return kJFalse;
		}

	JBoolean checked	= kJFalse;
	const JSize count	= 10;
	for (JIndex i = 1; i <= count; i++)
		{
		if (itsCB[i-1]->IsChecked())
			{
			checked		= kJTrue;
			break;
			}
		}

	if (!checked)
		{
		JGetUserNotification()->ReportError("You must add at least one power.");
		}

	return checked;
}
Пример #15
0
void
GMMIMEParser::ParseMIMEHeader
	(
	std::istream&		input,
	GMIMEHeader*	header,
	const JBoolean	display
	)
{
	JString data;
	JCharacter c	= input.peek();
	if (c == '\n')
		{
//		input.get(c);
		}
//	input >> std::ws;

	// first we need to search for the first empty line. This line is the
	// end of the header.

	JString line;
	while (1)
		{
		JBoolean found;
		line = JReadLine(input, &found);
		if (line.IsEmpty())
			{
			break;
			}
		if (isspace(line.GetFirstCharacter()))
			{
			line.TrimWhitespace();
			if (line.IsEmpty())
				{
				break;
				}
			data.AppendCharacter(' ');
			}
		else if (!data.IsEmpty())
			{
			data.AppendCharacter('\n');
			}
		data += line;
		}
	data.AppendCharacter('\n');

	// we now need to search through the header for parameter:value pairs
	// using the gmime_header_regex defined above.

	JArray<JIndexRange> ranges;
	gmime_header_regex.MatchAll(data, &ranges);

	JSize count = ranges.GetElementCount();
	for (JSize i = 1; i <= count; i++)
		{
		JIndexRange range = ranges.GetElement(i);
		JString parmValPair = data.GetSubstring(range);
		JString parm;
		JString val;
		if (parmValPair.BeginsWith("MIME") ||
			parmValPair.BeginsWith("Mime") ||
			parmValPair.BeginsWith("Content"))
			{
			CleanParmValPair(parmValPair, &parm, &val);
			parm.ToLower();
			if (parm == "mime-Version")
				{
				val.TrimWhitespace();
				header->SetVersion(val);
				}
			else if (parm == "content-type")
				{
				ParseContentType(val, header);
				}
			else if (parm == "content-transfer-encoding")
				{
				val.TrimWhitespace();
				val.ToLower();
				header->SetEncoding(val);
				}
			else if (parm == "content-disposition")
				{
				ParseContentDisposition(val, header);
				}
			}
		}

	// this is a nested message, so some of the headers need to be displayed
	if (display)
		{
		JString text = "---------\n";
		JIndex findex	= 1;
		if (data.BeginsWith("From: ") || data.LocateSubstring("\nFrom: ", &findex))
			{
			if (findex > 1)
				{
				findex ++;
				}
			JIndex eindex	= findex;
			if (data.LocateNextSubstring("\n", &eindex) && (eindex > findex + 1))
				{
				text += data.GetSubstring(findex, eindex - 1);
				text += "\n";
				}
			}
		findex	= 1;
		if (data.BeginsWith("Date: ") || data.LocateSubstring("\nDate: ", &findex))
			{
			if (findex > 1)
				{
				findex ++;
				}
			JIndex eindex	= findex;
			if (data.LocateNextSubstring("\n", &eindex) && (eindex > findex + 1))
				{
				text += data.GetSubstring(findex, eindex - 1);
				text += "\n";
				}
			}
		findex	= 1;
		const JCharacter* kSubjectStr	= "Subject: ";
		if (data.BeginsWith("Subject: ") || data.LocateSubstring("\nSubject: ", &findex))
			{
			if (findex > 1)
				{
				findex ++;
				}
			JIndex eindex	= findex;
			if (data.LocateNextSubstring("\n", &eindex) && (eindex > findex + 1))
				{
				text += data.GetSubstring(findex, eindex - 1);
				text += "\n";
				}
			}
		WriteTextString(&text, GMIMEHeader());
		}
}
Пример #16
0
void
XDLink::SetProgram
	(
	const JCharacter* fileName
	)
{
	Send("detach");

//	StopDebugger();		// avoid broadcasting DebuggerRestarted
//	StartDebugger();

	itsProgramConfigFileName.Clear();
	itsSourcePathList->DeleteAll();

	JString fullName;
	if (!JConvertToAbsolutePath(fileName, NULL, &fullName) ||
		!JFileReadable(fullName))
		{
		const JString error = JGetString("ConfigFileUnreadable::XDLink");
		Broadcast(UserOutput(error, kJTrue));
		return;
		}
	else if (CMMDIServer::IsBinary(fullName))
		{
		const JString error = JGetString("ConfigFileIsBinary::XDLink");
		Broadcast(UserOutput(error, kJTrue));
		return;
		}

	JString line;
	if (!CMMDIServer::GetLanguage(fullName, &line) ||
		JStringCompare(line, "php", kJFalse) != 0)
		{
		const JString error = JGetString("ConfigFileWrongLanguage::XDLink");
		Broadcast(UserOutput(error, kJTrue));
		return;
		}

	JString path, name, suffix;
	JSplitPathAndName(fullName, &path, &name);
	JSplitRootAndSuffix(name, &itsProgramName, &suffix);

	itsProgramConfigFileName = fullName;

	ifstream input(fullName);
	while (1)
		{
		line = JReadLine(input);
		line.TrimWhitespace();

		if (line.BeginsWith("source-path:"))
			{
			line.RemoveSubstring(1, 12);
			line.TrimWhitespace();

			name = JCombinePathAndName(path, line);
			itsSourcePathList->Append(name);
			}
		else if (!line.IsEmpty() && !line.BeginsWith("code-medic:"))
			{
			line.Prepend("Unknown option: ");
			line.AppendCharacter('\n');
			Broadcast(UserOutput(line, kJTrue));
			}

		if (!input.good())
			{
			break;
			}
		}

	XDSetProgramTask* task = new XDSetProgramTask();
	assert( task != NULL );
	task->Go();
}
Пример #17
0
void
GFGLink::ParseInterface
	(
	GFGMemberFunction* 	fn,
	const JIndex 		line
	)
{
	std::ifstream is(itsCurrentFile);
	if (!is.good())
		{
		return;
		}

	// skip to the function's line
	JString str;
	for (JIndex i = 1; i < line; i++)
		{
		str	= JReadLine(is);
		}

	JSize p1	= JTellg(is);

	is >> std::ws;
	str	= JReadUntilws(is);
	if (str != "virtual")
		{
		return;
		}

	is >> std::ws;

	// return type
	str	= JReadUntilws(is);
	if (str	== "const")
		{
		str	+= " " + JReadUntilws(is);
		}
	fn->SetReturnType(str);

	is >> std::ws;

	// this should be the function name
	str	= JReadUntil(is, '(');
	str.TrimWhitespace();
	if (str != fn->GetFnName())
		{
		return;
		}

	// get arguments
	JCharacter delim	= ',';
	while (delim == ',')
		{
		JBoolean ok	= JReadUntil(is, 2, ",)", &str, &delim);
		if (!ok)
			{
			return;
			}
		JIndex findex;
		if (str.LocateSubstring("//", &findex))
			{
			JIndex eindex;
			if (str.LocateSubstring("\n", &eindex) &&
				eindex >= findex)
				{
				str.RemoveSubstring(findex, eindex);
				}
			}
		str.TrimWhitespace();
		if (!str.IsEmpty())
			{
			fn->AddArg(str);
			}		
		}

	is >> std::ws;

	// is it const;
	str	= JReadUntil(is, ';');
	if (str.Contains("const"))
		{
		fn->ShouldBeConst(kJTrue);
		}

	JSize p2	= JTellg(is);
	JSeekg(is, p1);

	str	= JRead(is, p2 - p1);
	fn->SetInterface(str);
}
Пример #18
0
int
main
	(
	int		argc,
	char*	argv[]
	)
{
	// check if we are being invoked to build the dependency graph

	if (argc > 2 && strcmp(argv[1], "--depend") == 0)
		{
		CalcDepend(2, argc, argv);
		return 0;
		}

	// parse the command line options

	JString defSuffix, defineText, headerName, inputName, outputName, outputDirName;
	JPtrArray<JString> userTargetList(JPtrArrayT::kDeleteAll);	// empty => include all targets
	JBoolean searchSysDir, assumeAutoGen;

	JPtrArray<JString> suffixMapIn(JPtrArrayT::kDeleteAll),
					   suffixMapOut(JPtrArrayT::kDeleteAll);

	GetOptions(argc, argv, &defSuffix, &defineText, &headerName, &inputName,
			   &outputName, &outputDirName, &userTargetList, &searchSysDir,
			   &assumeAutoGen, &suffixMapIn, &suffixMapOut);

	// process the input file

	JPtrArray<JString> mainTargetList(JPtrArrayT::kDeleteAll),
					   mainTargetObjsList(JPtrArrayT::kDeleteAll);
	JArray<JBoolean>   javaTargetList;
	JPtrArray<JString> targetList(JPtrArrayT::kDeleteAll),
					   prefixList(JPtrArrayT::kDeleteAll),
					   suffixList(JPtrArrayT::kDeleteAll);
	JPtrArray<JString> outPrefixList(JPtrArrayT::kDeleteAll),
					   outSuffixList(JPtrArrayT::kDeleteAll);

	JArray<JIndexRange> matchList;

	targetList.SetCompareFunction(JCompareStringsCaseSensitive);

	// skip comments and check for possible first suffix instruction

	ifstream input(inputName);
	input >> ws;
	while (!input.eof() && !input.fail())
		{
		if (input.peek() == '-')
			{
			input.ignore(1);
			JString cmd   = JReadUntil(input, ' ');
			JString value = JReadUntil(input, '\n');
			input >> ws;
			value.TrimWhitespace();
			if (cmd == "suffix")
				{
				defSuffix = value;
				}
			else
				{
				cerr << argv[0] << ": unknown parameter: " << cmd << '\n';
				}
			}
		else if (input.peek() == '#')
Пример #19
0
void
GDBGetCompletions::HandleSuccess
	(
	const JString& data
	)
{
	JPtrArray<JString> lines(JPtrArrayT::kDeleteAll);
	lines.SetSortOrder(JOrderedSetT::kSortAscending);
	lines.SetCompareFunction(JCompareStringsCaseSensitive);

	// loop through each line and add each one to our list

	JIndex i = 1, j = 1;
	while (data.LocateNextSubstring("\n", &j))
		{
		if (j > i)
			{
			JString* s = new JString(data, JIndexRange(i, j-1));
			assert( s != NULL );
			s->TrimWhitespace();
			if (s->IsEmpty() || !lines.InsertSorted(s, kJFalse))
				{
				delete s;
				}
			}
		i = j+1;
		j = i;
		}

	if (i <= data.GetLength())
		{
		JString* s = new JString(data, JIndexRange(i, data.GetLength()));
		assert( s != NULL );
		s->TrimWhitespace();
		if (s->IsEmpty() || !lines.InsertSorted(s, kJFalse))
			{
			delete s;
			}
		}

	if (lines.IsEmpty())
		{
		(itsInput->GetDisplay())->Beep();
		return;
		}

	// Check if we're done. If we find our test prefix in the array, and
	// the array has only one element, we're done.  Otherwise, our test
	// prefix is the 'start' of several possible commands.

	const JSize stringCount = lines.GetElementCount();
	JBoolean found;
	JIndex startIndex = lines.SearchSorted1(&itsPrefix, JOrderedSetT::kAnyMatch, &found);
	if (found)
		{
		if (stringCount == 1)
			{
			// The input text is already complete.  We just need to add a
			// space at the end to show that it is a complete word.

			itsPrefix += " ";
			}
		else
			{
			// We can't add anything to what the user has types, so we show
			// all possible completions.

			itsHistory->PlaceCursorAtEnd();
			itsHistory->Paste("\n");
			itsHistory->Paste(data);
			}
		itsInput->SetText(itsPrefix);
		itsInput->SetCaretLocation(itsInput->GetTextLength() + 1);
		return;
		}

	JString maxPrefix;

	maxPrefix = *(lines.NthElement(startIndex));
	if (stringCount == 1)
		{
		// There's only one completion, which must be what we meant so we
		// fill in the input with this word.

		maxPrefix += " ";
		itsInput->SetText(maxPrefix);
		itsInput->SetCaretLocation(itsInput->GetTextLength() + 1);
		return;
		}

	for (JIndex i=startIndex+1; i<=stringCount; i++)
		{
		const JString* s = lines.NthElement(i);
		const JSize matchLength  = JCalcMatchLength(maxPrefix, *s);
		const JSize prefixLength = maxPrefix.GetLength();
		if (matchLength < prefixLength)
			{
			maxPrefix.RemoveSubstring(matchLength+1, prefixLength);
			}
		}

	if (maxPrefix == itsPrefix)
		{
		// The input text is all that the words have in common so we can't
		// add anything to the input. We therefore need to dump everything
		// to the history window.

		itsHistory->PlaceCursorAtEnd();
		itsHistory->Paste("\n");
		itsHistory->Paste(data);
		}
	else
		{
		itsInput->SetText(maxPrefix);
		itsInput->SetCaretLocation(itsInput->GetTextLength() + 1);
		}
}
void
GenerateCode
	(
	istream&			input,
	ostream&			output,
	const JString&		stringPath,
	const JString&		formName,
	const JString&		tagName,
	const JString&		userTopEnclVarName,
	JPtrArray<JString>*	objTypes,
	JPtrArray<JString>*	objNames
	)
{
JIndex i;

	// width

	input >> ws;
	JString line = JReadUntilws(input);
	assert( line == kFormWidthMarker );
	JSize formWidth;
	input >> formWidth;

	// height

	input >> ws;
	line = JReadUntilws(input);
	assert( line == kFormHeightMarker );
	JSize formHeight;
	input >> formHeight;

	// object count (marker contains whitespace)

	input >> ws;
	line = JReadUntil(input, ':') + ":";
	assert( line == kFormObjCountMarker );
	JSize itemCount;
	input >> itemCount;

	// create window

	const JString topEnclFrameName = tagName + "_Frame";
	const JString topEnclApName    = tagName + "_Aperture";

	JString topEnclVarName;
	if (tagName == kDefaultDelimTag)
		{
		topEnclVarName = kDefTopEnclVarName;

		output << "    JXWindow* window = new JXWindow(this, ";
		output << formWidth << ',' << formHeight;
		output << ", \"\");" << endl;
		output << "    assert( window != NULL );" << endl;
		output << endl;
		}
	else
		{
		assert( !userTopEnclVarName.IsEmpty() );
		topEnclVarName = userTopEnclVarName;

		output << "    const JRect ";
		topEnclFrameName.Print(output);
		output << "    = ";
		topEnclVarName.Print(output);
		output << "->GetFrame();" << endl;

		output << "    const JRect ";
		topEnclApName.Print(output);
		output << " = ";
		topEnclVarName.Print(output);
		output << "->GetAperture();" << endl;

		output << "    ";
		topEnclVarName.Print(output);
		output << "->AdjustSize(" << formWidth << " - ";
		topEnclApName.Print(output);
		output << ".width(), " << formHeight << " - ";
		topEnclApName.Print(output);
		output << ".height());" << endl;

		output << endl;
		}

	// We need to calculate the enclosure for each object.  Since objects
	// are drawn in the order added, an object must come after its enclosure
	// in the list in order to be visible.

	JArray<JRect>    rectList(10);
	JArray<JBoolean> isInstanceVar(10);

	// This array is used to send the options to ApplyOptions.
	// It does not own the pointers that it contains.

	JPtrArray<JString> optionValues(JPtrArrayT::kForgetAll, kOptionCount);
	for (i=1; i<=kOptionCount; i++)
		{
		optionValues.Append(NULL);
		}

	// generate code for each object

	JStringManager stringMgr;

	JIndex objCount = 1;
	for (i=1; i<=itemCount; i++)
		{
		// check for start-of-object

		input >> ws;
		line = JReadLine(input);
		assert( line == kBeginObjLine );

		// object class

		JString flClass = JReadLine(input);
		RemoveIdentifier(kObjClassMarker, &flClass);

		// object type

		JString flType = JReadLine(input);
		RemoveIdentifier(kObjTypeMarker, &flType);

		// object frame

		input >> ws;
		line = JReadUntilws(input);
		assert( line == kObjRectMarker );
		JCoordinate x,y,w,h;
		input >> x >> y >> w >> h >> ws;
		const JRect frame(y, x, y+h, x+w);
		rectList.AppendElement(frame);

		// box type

		JString boxType = JReadLine(input);
		RemoveIdentifier(kObjBoxTypeMarker, &boxType);

		// colors

		input >> ws;
		line = JReadUntilws(input);
		assert( line == kObjColorsMarker );
		JString col1 = JReadUntilws(input);
		optionValues.SetElement(kCol1Index, &col1, JPtrArrayT::kForget);
		JString col2 = JReadUntilws(input);
		optionValues.SetElement(kCol2Index, &col2, JPtrArrayT::kForget);

		// label info

		JString lAlign = JReadLine(input);
		RemoveIdentifier(kObjLAlignMarker, &lAlign);
		JString lStyle = JReadLine(input);
		RemoveIdentifier(kObjLStyleMarker, &lStyle);
		JString lSize  = JReadLine(input);
		RemoveIdentifier(kObjLSizeMarker, &lSize);
		JString lColor = JReadLine(input);
		RemoveIdentifier(kObjLColorMarker, &lColor);
		JString label  = JReadLine(input);
		RemoveIdentifier(kObjLabelMarker, &label);

		// shortcuts

		JString shortcuts = JReadLine(input);
		RemoveIdentifier(kObjShortcutMarker, &shortcuts);
		optionValues.SetElement(kShortcutsIndex, &shortcuts, JPtrArrayT::kForget);

		// resizing (ignored)

		JIgnoreLine(input);

		// gravity

		input >> ws;
		line = JReadUntilws(input);
		assert( line == kObjGravityMarker );
		const JString nwGravity = JReadUntilws(input);
		const JString seGravity = JReadUntilws(input);

		// variable name

		JBoolean isLocal = kJFalse;
		JString* varName = new JString(JReadLine(input));
		assert( varName != NULL );
		RemoveIdentifier(kObjNameMarker, varName);
		if (varName->IsEmpty())
			{
			isInstanceVar.AppendElement(kJFalse);
			GetTempVarName(tagName, varName, *objNames);
			isLocal = kJTrue;
			}
		else if (varName->GetFirstCharacter() == '(' &&
				 varName->GetLastCharacter()  == ')')
			{
			isInstanceVar.AppendElement(kJFalse);
			isLocal  = kJTrue;
			*varName = varName->GetSubstring(2, varName->GetLength()-1);
			}
		else if (varName->GetFirstCharacter() == '<' &&
				 varName->GetLastCharacter()  == '>')
			{
			isInstanceVar.AppendElement(kJFalse);
			*varName = varName->GetSubstring(2, varName->GetLength()-1);
			}
		else
			{
			isInstanceVar.AppendElement(kJTrue);
			}
		objNames->Append(varName);

		// callback (ignored)

		JIgnoreLine(input);

		// callback argument

		JString cbArg = JReadLine(input);
		RemoveIdentifier(kObjCBArgMarker, &cbArg);

		JString cbArgExtra;
		do
			{
			cbArgExtra = JReadLine(input);
			cbArgExtra.TrimWhitespace();
			}
			while (!cbArgExtra.IsEmpty());

		// don't bother to generate code for initial box
		// if it is FL_BOX, FLAT_BOX, FL_COL1

		if (i==1 && flClass == "FL_BOX" && flType == "FLAT_BOX" && col1 == "FL_COL1")
			{
			rectList.RemoveElement(objCount);
			isInstanceVar.RemoveElement(objCount);
			objNames->DeleteElement(objCount);
			continue;
			}

		// check for errors -- safe since we have read in entire object

		JString hSizing, vSizing;
		if (!ParseGravity(nwGravity, &hSizing, &vSizing))
			{
			cerr << "Illegal sizing specification ";
			cerr << nwGravity << ',' << seGravity;
			cerr << " for '" << *varName << '\'' << endl;
			rectList.RemoveElement(objCount);
			isInstanceVar.RemoveElement(objCount);
			objNames->DeleteElement(objCount);
			continue;
			}

		if (*varName == topEnclVarName)
			{
			cerr << "Cannot use reserved name '" << topEnclVarName << '\'' << endl;
			rectList.RemoveElement(objCount);
			isInstanceVar.RemoveElement(objCount);
			objNames->DeleteElement(objCount);
			continue;
			}

		// get the object's enclosure

		JIndex enclIndex;
		JString enclName;
		JRect localFrame = frame;
		if (GetEnclosure(rectList, objCount, &enclIndex))
			{
			enclName = *(objNames->NthElement(enclIndex));
			const JRect enclFrame = rectList.GetElement(enclIndex);
			localFrame.Shift(-enclFrame.topLeft());
			}
		else
			{
			enclName = topEnclVarName;
			}

		// get the class name and additional arguments

		JString* className = new JString;
		assert( className != NULL );
		objTypes->Append(className);

		JString argList;
		if (!GetConstructor(flClass, flType, &label, className, &argList))
			{
			cerr << "Unsupported class: " << flClass << ", " << flType << endl;
			rectList.RemoveElement(objCount);
			isInstanceVar.RemoveElement(objCount);
			objNames->DeleteElement(objCount);
			objTypes->DeleteElement(objCount);
			continue;
			}

		// generate the actual code

		const JBoolean needCreate = NeedsCreateFunction(*className);

		output << "    ";
		if (isLocal)
			{
			className->Print(output);
			output << "* ";
			}
		varName->Print(output);
		output << " =" << endl;
		output << "        ";
		if (!needCreate)
			{
			output << "new ";
			}
		className->Print(output);
		if (needCreate)
			{
			output << "::Create";
			}
		output << '(';
		if (!argList.IsEmpty())
			{
			argList.Print(output);
			if (argList.GetLastCharacter() != ',')
				{
				output << ',';
				}
			output << ' ';
			}

		if (!cbArg.IsEmpty())
			{
			cbArg.Print(output);
			if (cbArg.GetLastCharacter() != ',')
				{
				output << ',';
				}
			output << ' ';
			}

		if ((*className == "JXStaticText" && cbArg.IsEmpty()) ||
			NeedsStringArg(*className))
			{
			JString id = *varName;
			id += "::";
			id += formName;
			id += "::";
			id += tagName;		// last since it is almost always the same

			output << "JGetString(\"";
			id.Print(output);
			output << "\"), ";

			stringMgr.SetElement(id, label, JPtrArrayT::kDelete);
			}

		enclName.Print(output);
		output << ',' << endl;
		output << "                    JXWidget::";
		hSizing.Print(output);
		output << ", JXWidget::";
		vSizing.Print(output);
		output << ", " << localFrame.left << ',' << localFrame.top << ", ";
		output << localFrame.width() << ',' << localFrame.height() << ");" << endl;

		output << "    assert( ";
		varName->Print(output);
		output << " != NULL );" << endl;

		ApplyOptions(output, *className, formName, tagName, *varName, optionValues,
					 lSize, lStyle, lColor, &stringMgr);

		if (*className == "JXStaticText" && cbArg.IsEmpty() &&
			!lAlign.Contains("FL_ALIGN_TOP") && localFrame.height() <= 20)
			{
			output << "    ";
			varName->Print(output);
			output << "->SetToLabel();" << endl;
			}

		output << endl;

		// now we know the object is valid

		objCount++;
		}

	// write string database

	JString dbFileName = stringPath + formName;
	if (tagName != kDefaultDelimTag)
		{
		dbFileName += kCustomTagMarker + tagName;
		}
	dbFileName += "_layout";

	if (stringMgr.GetElementCount() > 0)
		{
		JEditVCS(dbFileName);
		ofstream dbOutput(dbFileName);
		stringMgr.WriteFile(dbOutput);
		}
	else
		{
		JRemoveVCS(dbFileName);
		JRemoveFile(dbFileName);
		}

	// reset enclosure size

	if (tagName != kDefaultDelimTag)
		{
		output << "    ";
		topEnclVarName.Print(output);
		output << "->SetSize(";
		topEnclFrameName.Print(output);
		output << ".width(), ";
		topEnclFrameName.Print(output);
		output << ".height());" << endl;
		output << endl;
		}

	// throw away temporary variables

	objCount--;
	assert( objCount == isInstanceVar.GetElementCount() );
	assert( objCount == objTypes->GetElementCount() );
	assert( objCount == objNames->GetElementCount() );
	for (i=objCount; i>=1; i--)
		{
		if (!isInstanceVar.GetElement(i))
			{
			objTypes->DeleteElement(i);
			objNames->DeleteElement(i);
			}
		}
}
Пример #21
0
void
GMMIMEParser::ParseContentType
	(
	const JString&	val,
	GMIMEHeader*	header
	)
{
	// we first need to determine the type. this will be found before the
	// first '/' which will be followed by the subtype.
	JString tVal	= val;
	tVal.TrimWhitespace();
	JSize length	= tVal.GetLength();

	JString type;
	JIndex findex;
	if (tVal.LocateSubstring("/", &findex) && (findex > 1))
		{
		type = tVal.GetSubstring(1, findex - 1);
		tVal.RemoveSubstring(1, findex);
		tVal.TrimWhitespace();
		type.ToLower();
		header->SetType(type);
		}
	else
		{
		return;
		}

	// now we need to determine the subtype
	JString subType;
	length			= tVal.GetLength();
	JBoolean found	= kJFalse;
	JIndex index;
	if (tVal.LocateSubstring(";", &index))
		{
		subType = tVal.GetSubstring(1, index - 1);
		tVal.RemoveSubstring(1, index);
		}
	else
		{
		subType = tVal;
		tVal.Clear();
		}

	tVal.TrimWhitespace();
	subType.TrimWhitespace();
	subType.ToLower();
	header->SetSubType(subType);

	if (tVal.IsEmpty())
		{
		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 (type == kTextType)
			{
			if (*str == "charset")
				{
				if (strings.IndexValid(i+1))
					{
					str	= strings.NthElement(i+1);
					header->SetCharSet(*str);
					}
				}
			}
		else if (type == kMultipartType)
			{
			if (*str == "boundary")
				{
				if (strings.IndexValid(i+1))
					{
					str	= strings.NthElement(i+1);
					header->SetBoundary(*str);
					}
				}
			}
		if ((type == kAppType) ||
			(type == kImageType) ||
			(type == kTextType))
			{
			if (*str == "name")
				{
				if (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);
					}
				}
			}
		}
}