void
CBCtagsUser::ReadExtensionFlags
	(
	istream&				input,
	JStringPtrMap<JString>*	flags
	)
	const
{
	flags->DeleteAll();

	JIgnoreUntil(input, ";\"\t");			// fluff

	JString data, key;
	JCharacter delimiter = '\t';
	while (delimiter != '\n')
		{
		if (!JReadUntil(input, 2, "\t\n", &data, &delimiter))
			{
			delimiter = '\n';
			}

		JString* value = new JString;
		assert( value != NULL );

		JIndex colonIndex;
		if (data.LocateSubstring(":", &colonIndex))
			{
			if (colonIndex > 1)
				{
				key = data.GetSubstring(1, colonIndex-1);
				}
			else
				{
				key.Clear();
				}

			if (colonIndex < data.GetLength())
				{
				*value = data.GetSubstring(colonIndex+1, data.GetLength());
				}
			}
		else
			{
			key    = "kind";
			*value = data;
			}

		flags->SetElement(key, value, JPtrArrayT::kDelete);
		}
}
JBoolean
CBCtagsUser::ProcessFile
	(
	const JCharacter*		fileName,
	const CBTextFileType	fileType,
	JString*				result,
	CBLanguage*				lang
	)
{
	if (!StartProcess(fileType, lang))
		{
		result->Clear();
		return kJFalse;
		}

	*itsCmdPipe << fileName << endl;

	JBoolean found;
	*result = JReadUntil(itsResultFD, kDelimiter, &found);
	if (found)
		{
		return kJTrue;
		}
	else if (itsTryRestartFlag)
		{
		DeleteProcess();

		itsTryRestartFlag = kJFalse;
		const JBoolean ok = ProcessFile(fileName, fileType, result, lang);
		itsTryRestartFlag = kJTrue;
		return ok;
		}
	else
		{
		DeleteProcess();
		itsIsActiveFlag = kJFalse;

		if (!CBInUpdateThread())
			{
			(JGetUserNotification())->ReportError(
				"ctags is not responding correctly, "
				"so some features will not work.");
			}

		return kJFalse;
		}
}
void
GFGLink::ParseClass
	(
	GFGClass* 		  list,
	const JCharacter* filename, 
	const JCharacter* classname
	)
{
	JBoolean ok	= kJTrue;
	if (itsCTagsProcess == NULL)
		{
		ok = StartCTags();
		}

	if (ok)
		{
		itsClassList	= list;
		itsCurrentClass	= classname;
		itsCurrentFile	= filename;

		JConvertToAbsolutePath(filename, "", &itsCurrentFile);

		itsCurrentFile.Print(*itsOutputLink);
		*itsOutputLink << std::endl;
		itsOutputLink->flush();

		JBoolean found = kJFalse;
		JString result = JReadUntil(itsInputFD, kDelimiter, &found);

		if (found)
			{
			JIndex findex;
			while (	result.LocateSubstring("\n", &findex) &&
					findex > 1)
				{
				JString line	= result.GetSubstring(1, findex - 1);
				result.RemoveSubstring(1, findex);
				ParseLine(line);
				}
			Broadcast(FileParsed());
			}
		}
}
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);
		}
JBoolean
GAddressBookMgr::GetNextRecord
	(
	JString& line,
	JString& record,
	std::istream& is
	)
{
	if (line.IsEmpty())
		{
		return kJFalse;
		}
	JIndex index;
	if (line.LocateSubstring("\t", &index))
		{
		if (index > 1)
			{
			record = line.GetSubstring(1, index - 1);
			line.RemoveSubstring(1, index);
			return kJTrue;
			}
		line.RemoveSubstring(1, 1);
		return kJFalse;
		}
	record = line;
	if (record.Contains("(") && !record.Contains(")"))
		{
		JString temp = JReadUntil(is, ')');
		record += temp + ")";
		line = JReadLine(is);
		if (!line.IsEmpty() && (line.GetFirstCharacter() == '\t'))
			{
			line.RemoveSubstring(1, 1);
			}
		}
	else
		{
		line.Clear();
		}
	return kJTrue;
}
void
CBApp::GetSystemIncludeDirectories()
{
	int pid, fd, inFD;
	const JError err = JExecute("gcc -Wp,-v -x c++ -fsyntax-only -", &pid,
								kJCreatePipe, &inFD,
								kJCreatePipe, &fd,
								kJAttachToFromFD);
	if (!err.OK())
		{
		for (const JCharacter* s : kSysIncludeDir)
			{
			itsSystemIncludeDirs->Append(s);
			}
		return;
		}

	close(inFD);

	JString s;
	while (1)
		{
		s = JReadUntil(fd, '\n');
		if (s.IsEmpty())
			{
			break;
			}

		if (s.GetFirstCharacter() == ' ')
			{
			s.RemoveSubstring(1,1);
			if (!s.Contains(" "))
				{
				itsSystemIncludeDirs->Append(s);
				}
			}
		}
}
void
JXFontManager::GetMonospaceFontNames
	(
	JPtrArray<JString>* fontNames
	)
	const
{
	if (itsMonoFontNames != NULL)
		{
		fontNames->CopyObjects(*itsMonoFontNames, fontNames->GetCleanUpAction(), kJFalse);
		}
	else
		{
		(JXGetApplication())->DisplayBusyCursor();

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

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

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

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

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

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

				ConvertToPSFontName(&name);

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

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

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

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

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

			XFreeFontNames(nameList);
			}
#endif

		// save names for next time

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

		me->itsMonoFontNames =
			new JPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll, kJTrue);
		assert( me->itsMonoFontNames != NULL );
		}
}
void
WizChatShortcutMenu::InitMenu
	(
	const JIndex playerIndex
	)
{
	SetTitle((WizGetApplication())->GetPlayerName(), NULL, kJFalse);

	RemoveAllItems();

	JString fileName;
	if (WWGetDataFileName(kSetupFileName, &fileName))
		{
		ifstream input(fileName);

		JIndex i = 0;
		JString nmShortcut, text;
		while (1)
			{
			// read one line

			JCharacter c;
			const JBoolean found = JReadUntil(input, delimiterCount, delimiters,
											  &nmShortcut, &c);
			text.Clear();
			if (!found)
				{
				if (!nmShortcut.IsEmpty())
					{
					i++;
					AppendItem(nmShortcut);
					}
				break;
				}
			else if (found && c != '\n')
				{
				text = JReadLine(input);
				text.TrimWhitespace();
				}

			// create the menu item

			if (nmShortcut.IsEmpty() && text.IsEmpty())
				{
				if (i > 0)
					{
					ShowSeparatorAfter(i);
					}
				}
			else if (nmShortcut.IsEmpty())
				{
				i++;
				AppendItem(text);
				}
			else if (text.IsEmpty())
				{
				i++;
				AppendItem(nmShortcut);
				}
			else
				{
				i++;
				AppendItem(text);
				nmShortcut.PrependCharacter(' ');	// avoid accidental match
				SetItemNMShortcut(i, nmShortcut);
				}
			}
		}

	const JSize itemCount = GetItemCount();
	if (itemCount > 0)
		{
		ShowSeparatorAfter(itemCount, kJFalse);
		}
}
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);
}
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() == '#')
Exemple #11
0
JBoolean
JGetCurrentSVNRevision
	(
	const JCharacter*	fullName,
	JString*			rev
	)
{
	JString path, name, entriesFileName, data, pattern;
	JSplitPathAndName(fullName, &path, &name);
	entriesFileName = JCombinePathAndName(path, kSubversionDirName);
	entriesFileName = JCombinePathAndName(entriesFileName, kSubversionFileName);
	JReadFile(entriesFileName, &data);

	if (data.BeginsWith("<?xml"))
		{
		pattern = "<entry[^>]+name=\"" + JRegex::BackslashForLiteral(name) + "\"(.|\n)*?>";
		JRegex r(pattern);
		JIndexRange range;
		JArray<JIndexRange> matchList;
		if (r.Match(data, &range) &&
			svn4RevisionPattern.MatchWithin(data, range, &matchList))
			{
			*rev = data.GetSubstring(matchList.GetElement(2));
			return kJTrue;
			}
		}
	else
		{
		std::istrstream input(data, data.GetLength());

		const JString version = JReadLine(input);
		if (version == "8" || version == "9" || version == "10")
			{
			pattern = "\n\f\n" + name + "\n";

			JBoolean found;
			JIgnoreUntil(input, pattern, &found);
			if (found)
				{
				const JString data2 = JReadUntil(input, '\f');
				std::istrstream input2(data2, data2.GetLength());

				JIgnoreLine(input2);		// file
				JIgnoreLine(input2);		// ???
				JIgnoreLine(input2);		// ???
				JIgnoreLine(input2);		// ???
				JIgnoreLine(input2);		// ???
				JIgnoreLine(input2);		// timestamp
				JIgnoreLine(input2);		// hash
				JIgnoreLine(input2);		// timestamp

				*rev = JReadLine(input2);
				if (input2.good())
					{
					return kJTrue;
					}
				}
			}
		}

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

		JString name;

#if ENABLE_TRUE_TYPE

		FcFontSet* set = XftListFonts(*itsDisplay, itsDisplay->GetScreen(), NULL, FC_FAMILY, NULL);
		for (int i=0; i < set->nfont; i++)
			{
			FcChar8* s = FcNameUnparse(set->fonts[i]);
			name.Set((JCharacter*) s);
//			cout << "tt  font: " << name << endl;

			if (!IsPostscript(name) || IsUseless(name))
				{
				FcStrFree(s);
				continue;
				}

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

			FcStrFree(s);
			}
		FcFontSetDestroy(set);

#endif

		int nameCount;
		char** nameList = XListFonts(*itsDisplay, "-*-*-medium-r-normal-*-*-*-75-75-*-*-*-*",
									 INT_MAX, &nameCount);
		if (nameList == NULL)
			{
			return;
			}

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

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

			ConvertToPSFontName(&name);
//			cout << "std font: " << name << endl;

			if (!IsPostscript(name) || IsUseless(name))
				{
				continue;
				}

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

		XFreeFontNames(nameList);

		// save names for next time

		itsAllFontNames = new JDCCPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll);
		assert( itsAllFontNames != NULL );
		}
}
void
CBSymbolList::ReadSymbolList
	(
	istream&			input,
	const CBLanguage	lang,
	const JCharacter*	fullName,
	const JFAID_t		fileID
	)
{
	JString path, fileName;
	JSplitPathAndName(fullName, &path, &fileName);

	input >> ws;
	while (input.peek() == '!')
		{
		JIgnoreLine(input);
		input >> ws;
		}

	JStringPtrMap<JString> flags(JPtrArrayT::kDeleteAll);
	while (1)
		{
		JString* name = new JString;
		assert( name != NULL );

		input >> ws;
		*name = JReadUntil(input, '\t');		// symbol name
		if (input.eof() || input.fail())
			{
			delete name;
			break;
			}

		JIgnoreUntil(input, '\t');				// file name

		JIndex lineIndex;
		input >> lineIndex;						// line index

		ReadExtensionFlags(input, &flags);

		JCharacter typeChar = ' ';
		JString* value;
		if (flags.GetElement("kind", &value) && !value->IsEmpty())
			{
			typeChar = value->GetFirstCharacter();
			}

		JString* signature = NULL;
		if (flags.GetElement("signature", &value) && !value->IsEmpty())
			{
			signature = new JString(*value);
			assert( signature != NULL );
			signature->PrependCharacter(' ');
			}

		if (IgnoreSymbol(*name))
			{
			delete name;
			}
		else
			{
			const Type type = DecodeSymbolType(lang, typeChar);
			if (signature == NULL &&
				(IsFunction(type) || IsPrototype(type)))
				{
				signature = new JString(" ( )");
				assert( signature != NULL );
				}

			const SymbolInfo info(name, signature, lang, type,
								  kJFalse, fileID, lineIndex);
			itsSymbolList->InsertSorted(info);

			// add file:name

			if (IsFileScope(type))
				{
				JString* name1 = new JString(fileName);
				assert( name1 != NULL );
				*name1 += ":";
				*name1 += *name;

				JString* sig1 = NULL;
				if (signature != NULL)
					{
					sig1 = new JString(*signature);
					assert( sig1 != NULL );
					}

				const SymbolInfo info1(name1, sig1, lang, type,
									   kJTrue, fileID, lineIndex);
				itsSymbolList->InsertSorted(info1);
				}
			}
		}
}
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);
			}
		}
}
void
CBFnMenuUpdater::ReadFunctionList
	(
	std::istream&	input,
	CBLanguage		lang,
	const JBoolean	sort,
	const JBoolean	includeNS,
	JXTextMenu*		menu,
	JArray<JIndex>*	lineIndexList
	)
{
	JPtrArray<JString> fnNameList(JPtrArrayT::kDeleteAll);
	fnNameList.SetCompareFunction(JCompareStringsCaseInsensitive);
	fnNameList.SetSortOrder(JOrderedSetT::kSortAscending);

	lineIndexList->SetCompareFunction(JCompareIndices);
	lineIndexList->SetSortOrder(JOrderedSetT::kSortAscending);

	// build symbol list

	const JBoolean hasNS = CBHasNamespace(lang);
	JString fnName;
	while (1)
		{
		input >> std::ws;
		fnName = JReadUntil(input, '\t');	// fn name
		if (input.eof() || input.fail())
			{
			break;
			}

		JIgnoreUntil(input, '\t');			// file name

		JIndex lineIndex;
		input >> lineIndex;					// line index

		if (IgnoreSymbol(fnName))
			{
			continue;
			}

		// toss qualified or unqualified version

		if (hasNS && !includeNS && cbIsQualified(fnName))
			{
			continue;
			}

		// save symbol

		JIndex i;
		if (sort)
			{
			i = fnNameList.GetInsertionSortIndex(&fnName);
			}
		else
			{
			i = lineIndexList->GetInsertionSortIndex(lineIndex);
			}
		fnNameList.InsertAtIndex(i, fnName);
		lineIndexList->InsertElementAtIndex(i, lineIndex);
		}

	if (hasNS && includeNS)
		{
		JSize count = fnNameList.GetElementCount();
		for (JIndex i=1; i<=count; i++)
			{
			const JString* fnName  = fnNameList.NthElement(i);
			const JIndex lineIndex = lineIndexList->GetElement(i);
			if (cbIsQualified(*fnName))
				{
				for (JIndex j=1; j<=count; j++)
					{
					if (j != i && lineIndexList->GetElement(j) == lineIndex)
						{
						fnNameList.DeleteElement(j);
						lineIndexList->RemoveElement(j);
						count--;
						if (j < i)
							{
							i--;
							}
						break;
						}
					}
				}
			}
		}

	// build menu

	const JSize count = fnNameList.GetElementCount();
	for (JIndex i=1; i<=count; i++)
		{
		menu->AppendItem(*(fnNameList.NthElement(i)));
		}
}
JFontStyle
JXFontManager::GetFontStyles
	(
	const JCharacter*	name,
	const JSize			size
	)
	const
{
	JFontStyle style(kJFalse, kJFalse, 0, kJTrue);

#ifdef _J_USE_XFT
	double raw_size = size;
	XftFontSet* fs = XftListFonts(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_FAMILY, XftTypeString, name, XFT_SIZE, XftTypeDouble, raw_size, 0, XFT_SLANT, XFT_WEIGHT, 0);

	if (fs->nfont == 0)
	{
		return style;
	}

	for (int i=0; i<fs->nfont; i++)
	{
		int raw_slant;
		if (XftPatternGetInteger(fs->fonts[i], XFT_SLANT, 0, &raw_slant) == XftResultMatch)
		{
			if (raw_slant == XFT_SLANT_ITALIC)
				style.italic = kJTrue;
		}

		int raw_weight;
		if (XftPatternGetInteger(fs->fonts[i], XFT_WEIGHT, 0, &raw_weight) == XftResultMatch)
		{
			if (raw_weight == XFT_WEIGHT_BOLD)
				style.bold = kJTrue;
		}
	}
	
	XftFontSetDestroy(fs);		
#else
	JString xFontName, charSet;
	if (!ConvertToXFontName(name, &xFontName, &charSet))
		{
		charSet = "*-*";
		}

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

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

	JString weight, slant;
	for (int i=0; i<nameCount; i++)
		{
		const std::string s(nameList[i], strlen(nameList[i]));
		std::istringstream input(s);
		input.ignore();							// initial dash
		JIgnoreUntil(input, '-');				// foundry name
		JIgnoreUntil(input, '-');				// font name
		weight = JReadUntil(input, '-');		// medium/bold
		slant  = JReadUntil(input, '-');		// roman/oblique/italic

		if (weight == "bold")
			{
			style.bold = kJTrue;
			}
		if (slant == "o" || slant == "i")
			{
			style.italic = kJTrue;
			}
		}

	XFreeFontNames(nameList);
#endif

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

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

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

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

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

			ConvertToPSFontName(&name);

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

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

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

		XFreeFontNames(nameList);
#endif

		// save names for next time

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

		me->itsAllFontNames =
			new JPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll, kJTrue);
		assert( me->itsAllFontNames != NULL );
		}
}
Exemple #18
0
void
JXFontManager::GetMonospaceFontNames
	(
	JPtrArray<JString>* fontNames
	)
	const
{
	if (itsMonoFontNames != NULL)
		{
		fontNames->CopyObjects(*itsMonoFontNames, fontNames->GetCleanUpAction(), kJFalse);
		}
	else
		{
		(JXGetApplication())->DisplayBusyCursor();

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

		JPtrArray<JString> allFontNames(JPtrArrayT::kDeleteAll);
		allFontNames.SetCompareFunction(JCompareStringsCaseInsensitive);
		allFontNames.SetSortOrder(JOrderedSetT::kSortAscending);

		JString name;

#if ENABLE_TRUE_TYPE

		FcFontSet* set =
			XftListFonts(*itsDisplay, itsDisplay->GetScreen(),
						 FC_SPACING, FcTypeInteger, FC_MONO, NULL,
						 FC_FAMILY, NULL);
		for (int i=0; i < set->nfont; i++)
			{
			FcChar8* s = FcNameUnparse(set->fonts[i]);
			name.Set((JCharacter*) s);
//			cout << "tt  mono: " << name << endl;

#if ONLY_STD_MONOSPACE

			if (!name.BeginsWith("Courier") &&
				!name.BeginsWith("Consolas") &&
				!name.Contains(" Mono")     &&
				name != "LucidaTypewriter")
				{
				FcStrFree(s);
				continue;
				}

#endif

			if (IsUseless(name))
				{
				FcStrFree(s);
				continue;
				}

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

				JString* n = new JString(name);
				assert( n != NULL );
				const JBoolean ok = fontNames->InsertSorted(n, kJFalse);
				assert( ok );
				}

			FcStrFree(s);
			}
		FcFontSetDestroy(set);

#else

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

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

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

				ConvertToPSFontName(&name);
//				cout << "std mono: " << name << endl;

#if ONLY_STD_MONOSPACE

				if (name != "Clean" && name != "Fixed" && name != "Terminal" &&
					name != "Courier" && name != "Lucidatypewriter" &&
					name != "Profontwindows")
					{
					continue;
					}

#endif

				if (IsUseless(name))
					{
					continue;
					}

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

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

			XFreeFontNames(nameList);
			}

#endif

		// save names for next time

		itsMonoFontNames = new JDCCPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll);
		assert( itsMonoFontNames != NULL );
		}
}