inline JBoolean cbIsQualified ( const JString& s ) { return JI2B(s.Contains(":") || s.Contains(".")); }
inline JBoolean JXFontManager::IsPostscript ( const JString& name ) const { #if ONLY_STD_PS_FONTS return JI2B(name == "Arial" || // Helvetica sucks on OS X name.BeginsWith("Courier") || name.BeginsWith("Helvetica") || name == "Symbol" || name == "Times" || name.Contains("Bookman") || name.Contains("Century Schoolbook") || name.Contains("Chancery") || name.Contains("Palatino")); #else return kJTrue; #endif }
void JXButton::SetShortcuts ( const JCharacter* list ) { JXWindow* w = GetWindow(); w->ClearShortcuts(this); w->InstallShortcuts(this, list); const JBoolean wasReturnButton = itsIsReturnButtonFlag; itsIsReturnButtonFlag = kJFalse; if (list != NULL) { JString shortcuts = list; if (shortcuts.Contains("^M") || shortcuts.Contains("^m")) { itsIsReturnButtonFlag = kJTrue; } } const JSize borderWidth = GetBorderWidth(); if (!wasReturnButton && itsIsReturnButtonFlag) { SetBorderWidth(borderWidth+1); } else if (wasReturnButton && !itsIsReturnButtonFlag && borderWidth > 0) { SetBorderWidth(borderWidth-1); } Refresh(); }
void GPMProcessEntry::ReadStat() { const JSize uTime = itsUTime, sTime = itsSTime; JString str = JCombinePathAndName(itsProcPath, "stat"); std::ifstream is(str); if (is.good()) { is >> itsPID; is >> std::ws; itsCommand = JReadUntilws(is); if (itsCommand.GetLength() > 2) { itsCommand = itsCommand.GetSubstring(2, itsCommand.GetLength() - 1); } JString state = JReadUntilws(is); if (state.Contains("S")) { itsState = kSleep; } else if (state.Contains("D")) { itsState = kUnIntSleep; } else if (state.Contains("Z")) { itsState = kZombie; } else if (state.Contains("T")) { itsState = kStopped; } else { itsState = kRun; } is >> itsPPID; is >> std::ws; int toss; is >> toss; is >> toss; is >> toss; is >> toss; is >> toss; is >> toss; is >> toss; is >> toss; is >> toss; is >> itsUTime; is >> itsSTime; is >> toss; is >> toss; is >> itsPriority; is >> itsNice; }
inline JBoolean JXFontManager::IsUseless ( const JString& name ) const { return JI2B(name.Contains("Dingbats") || name.Contains("Standard Symbols") || name.Contains("Cursor") || name.EndsWith(" Ti")); }
JBoolean JSearchFile ( const JCharacter* fileName, const JCharacter* searchStr, const JBoolean caseSensitive, JIndex* lineIndex ) { ifstream input(fileName); *lineIndex = 0; while (!input.eof()) { (*lineIndex)++; const JString line = JReadLine(input); if (input.fail()) { break; } if (line.Contains(searchStr, caseSensitive)) { return kJTrue; } } return kJFalse; }
void JWebBrowser::ShowFileLocation ( const JCharacter* fileName ) { if (!JStringEmpty(itsShowFileLocationCmd)) { JString fullName = fileName; JStripTrailingDirSeparator(&fullName); JString path, name; JSplitPathAndName(fullName, &path, &name); const JCharacter* map[] = { kFileVarName, fullName, kPathVarName, path }; JString s = itsShowFileLocationCmd; if (!s.Contains("$")) { s += " '$"; s += kFileVarName; s += "'"; } (JGetStringManager())->Replace(&s, map, sizeof(map)); JSimpleProcess::Create(s, kJTrue); } }
void JUpdateCVSIgnore ( const JCharacter* ignoreFullName ) { JString path, name; JSplitPathAndName(ignoreFullName, &path, &name); const JString cvsFile = JCombinePathAndName(path, ".cvsignore"); if (!JFileExists(cvsFile) && JGetVCSType(path) != kJCVSType) { return; } JString cvsData; JReadFile(cvsFile, &cvsData); if (!cvsData.IsEmpty() && !cvsData.EndsWith("\n")) { cvsData += "\n"; } name += "\n"; if (!cvsData.Contains(name)) { JEditVCS(cvsFile); cvsData += name; ofstream output(cvsFile); cvsData.Print(output); } }
JString CMLink::Build1DArrayExpressionForCFamilyLanguage ( const JCharacter* origExpr, const JInteger index ) { JString expr = origExpr; const JString indexStr(index, 0); // must use floating point conversion if (expr.Contains("$i")) { const JCharacter* map[] = { "i", indexStr.GetCString() }; (JGetStringManager())->Replace(&expr, map, sizeof(map)); } else { if (expr.GetFirstCharacter() != '(' || expr.GetLastCharacter() != ')') { expr.PrependCharacter('('); expr.AppendCharacter(')'); } expr.AppendCharacter('['); expr += indexStr; expr.AppendCharacter(']'); } return expr; }
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; }
JString CMLink::Build2DArrayExpressionForCFamilyLanguage ( const JCharacter* origExpr, const JInteger rowIndex, const JInteger colIndex ) { JString expr = origExpr; const JBoolean usesI = expr.Contains("$i"); // row const JBoolean usesJ = expr.Contains("$j"); // col const JString iStr(rowIndex, 0); // must use floating point conversion const JString jStr(colIndex, 0); // must use floating point conversion // We have to do both at the same time because otherwise we lose a $. if (usesI || usesJ) { const JCharacter* map[] = { "i", iStr.GetCString(), "j", jStr.GetCString() }; (JGetStringManager())->Replace(&expr, map, sizeof(map)); } if (!usesI || !usesJ) { if (expr.GetFirstCharacter() != '(' || expr.GetLastCharacter() != ')') { expr.PrependCharacter('('); expr.AppendCharacter(')'); } if (!usesI) { expr.AppendCharacter('['); expr += iStr; expr.AppendCharacter(']'); } if (!usesJ) { expr.AppendCharacter('['); expr += jStr; expr.AppendCharacter(']'); } } return expr; }
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); } } } }
JString XDLink::Build1DArrayExpression ( const JCharacter* origExpr, const JInteger index ) { JString expr = origExpr; const JString indexStr(index, 0); // must use floating point conversion if (expr.Contains("$i")) { // double literal $'s for (JIndex i=expr.GetLength()-1; i>=1; i--) { if (expr.GetCharacter(i) == '$' && expr.GetCharacter(i+1) != 'i') { expr.InsertCharacter('$', i); } } const JCharacter* map[] = { "i", indexStr.GetCString() }; (JGetStringManager())->Replace(&expr, map, sizeof(map)); } else { expr.AppendCharacter('['); expr += indexStr; expr.AppendCharacter(']'); } return expr; }
JBoolean CBSymbolList::InContext ( const JString& fullName, const JPtrArray<JString>& contextNamespace, const JBoolean caseSensitive ) const { const JSize count = contextNamespace.GetElementCount(); for (JIndex i=1; i<=count; i+=2) { const JString* cns1 = contextNamespace.NthElement(i); const JString* cns2 = contextNamespace.NthElement(i+1); if (fullName.BeginsWith(*cns1, caseSensitive) || fullName.Contains(*cns2, caseSensitive)) { return kJTrue; } } return kJFalse; }
JString XDLink::Build2DArrayExpression ( const JCharacter* origExpr, const JInteger rowIndex, const JInteger colIndex ) { JString expr = origExpr; const JBoolean usesI = expr.Contains("$i"); // row const JBoolean usesJ = expr.Contains("$j"); // col const JString iStr(rowIndex, 0); // must use floating point conversion const JString jStr(colIndex, 0); // must use floating point conversion // We have to do both at the same time because otherwise we lose a $. if (usesI || usesJ) { // double literal $'s for (JIndex i=expr.GetLength()-1; i>=1; i--) { if (expr.GetCharacter(i) == '$' && expr.GetCharacter(i+1) != 'i' && expr.GetCharacter(i+1) != 'j') { expr.InsertCharacter('$', i); } } const JCharacter* map[] = { "i", iStr.GetCString(), "j", jStr.GetCString() }; (JGetStringManager())->Replace(&expr, map, sizeof(map)); } if (!usesI || !usesJ) { if (expr.GetFirstCharacter() != '(' || expr.GetLastCharacter() != ')') { expr.PrependCharacter('('); expr.AppendCharacter(')'); } if (!usesI) { expr.AppendCharacter('['); expr += iStr; expr.AppendCharacter(']'); } if (!usesJ) { expr.AppendCharacter('['); expr += jStr; expr.AppendCharacter(']'); } } return expr; }
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); }
void GFGLink::ParseLine ( const JString& data ) { // we only care about virtual functions JBoolean required = kJFalse; if (data.Contains("implementation:pure virtual")) { required = kJTrue; } else if (!data.Contains("implementation:virtual")) { return; } JArray<JIndexRange> subList; if (memberLine.Match(data, &subList)) { JIndexRange sRange = subList.GetElement(2); JString name = data.GetSubstring(sRange); if (name.BeginsWith("~")) { return; } GFGMemberFunction* fn = jnew GFGMemberFunction(); assert(fn != NULL); fn->SetFnName(name); fn->ShouldBeRequired(required); sRange = subList.GetElement(3); JIndex line; JString lineStr = data.GetSubstring(sRange); lineStr.ConvertToUInt(&line); sRange = subList.GetElement(4); JString base = data.GetSubstring(sRange); if (base != itsCurrentClass) { jdelete fn; return; } sRange = subList.GetElement(5); JString access = data.GetSubstring(sRange); if (access == "protected") { fn->ShouldBeProtected(kJTrue); } ParseInterface(fn, line); // Override entry from base class so function will only be // marked as pure virtual if nobody implemented it. JBoolean found; const JIndex i = itsClassList->SearchSorted1(fn, JOrderedSetT::kAnyMatch, &found); if (found) { itsClassList->DeleteElement(i); } itsClassList->InsertAtIndex(i, fn); } }
void SMTPMessage::Send() { HandleAddresses(); AppendToOutbox("From "); AppendToOutbox(*itsFrom); AppendToOutbox(" "); struct timeb tp; ftime(&tp); JString date(ctime(&(tp.time))); AppendToOutbox(date); std::istrstream is(date.GetCString(), date.GetLength()); JString dow; JString mon; JString day; JString rest; dow = JReadUntilws(is); mon = JReadUntilws(is); day = JReadUntilws(is); JReadAll(is, &rest); AppendToOutbox("Date: "); AppendToOutbox(dow); AppendToOutbox(", "); AppendToOutbox(day); AppendToOutbox(" "); AppendToOutbox(mon); AppendToOutbox(" "); AppendToOutbox(rest); JString addrStr = itsSMTPServer; if (!addrStr.Contains(":")) { addrStr += ":25"; } ACE_INET_Addr addr(addrStr); itsLink = new InetLink; assert(itsLink != NULL); itsConnector = new INETConnector; assert( itsConnector != NULL ); ACE_Synch_Options options(ACE_Synch_Options::USE_REACTOR, ACE_Time_Value(kMaxWaitSeconds)); if (itsConnector->connect(itsLink, addr, options) == -1 && jerrno() != EAGAIN) { JString notice = "No response from sendmail : Error number "; int errNumber = jerrno(); notice += JString(errNumber); JGetUserNotification()->ReportError(notice); itsDeleteTask = new JXTimerTask(1000,kJTrue); assert( itsDeleteTask != NULL ); itsDeleteTask->Start(); ListenTo(itsDeleteTask); Broadcast(SendFailure()); // itsLink = NULL; return; } itsTimeoutTask = new JXTimerTask(kMaxWaitSeconds * 1000,kJTrue); assert( itsTimeoutTask != NULL ); itsTimeoutTask->Start(); ListenTo(itsTimeoutTask); ClearWhenGoingAway(itsLink, &itsLink); }
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 ); } }
JBoolean JProgramAvailable ( const JCharacter* programName, JString* fixedName ) { if (JStringEmpty(programName) || !JExpandHomeDirShortcut(programName, fixedName)) { return kJFalse; } if (fixedName->GetFirstCharacter() == '/') { return JFileExecutable(*fixedName); } JString fullName = programName; if (fullName.Contains("/")) { const JString dir = JGetCurrentDirectory(); fullName = JCombinePathAndName(dir, fullName); return JFileExecutable(fullName); } // check each directory in the exec path list const JCharacter* cpath = getenv("PATH"); JString path(cpath == NULL ? "" : cpath); if (theIncludeCWDOnPathFlag) { path.Prepend(".:"); } if (path.IsEmpty()) { return kJFalse; } JIndex colonIndex; while (path.LocateSubstring(":", &colonIndex)) { if (colonIndex > 1) { const JString dir = path.GetSubstring(1, colonIndex-1); fullName = JCombinePathAndName(dir, programName); if (JFileExists(fullName) && JFileExecutable(fullName)) { if (dir == ".") { fixedName->Prepend("./"); // in case we added this to PATH } return kJTrue; } } path.RemoveSubstring(1, colonIndex); } if (path.IsEmpty()) { return kJFalse; } fullName = JCombinePathAndName(path, programName); return JFileExecutable(fullName); }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { JProcess* p; int outFD; const JError err = JProcess::Create(&p, kMountCmd, kJIgnoreConnection, NULL, kJCreatePipe, &outFD, kJIgnoreConnection, NULL); if (!err.OK()) { if (state != NULL) { jdelete state->mountCmdOutput; state->mountCmdOutput = NULL; } return kJFalse; } JString mountData; JReadAll(outFD, &mountData); p->WaitUntilFinished(); const JBoolean success = p->SuccessfulFinish(); jdelete p; p = NULL; if (!success) { if (state != NULL) { jdelete state->mountCmdOutput; state->mountCmdOutput = NULL; } return kJFalse; } if (state != NULL && state->mountCmdOutput != NULL && mountData == *(state->mountCmdOutput)) { return kJFalse; } list->CleanOut(); if (state != NULL && state->mountCmdOutput == NULL) { state->mountCmdOutput = jnew JString(mountData); assert( state->mountCmdOutput != NULL ); } else if (state != NULL) { *(state->mountCmdOutput) = mountData; } JIndexRange r; JArray<JIndexRange> matchList; JString options; ACE_stat stbuf; while (theLinePattern.MatchAfter(mountData, r, &matchList)) { r = matchList.GetFirstElement(); options = mountData.GetSubstring(matchList.GetElement(4)); if (options.Contains("nobrowse")) { continue; } JString* path = jnew JString(mountData.GetSubstring(matchList.GetElement(3))); assert( path != NULL ); JString* devicePath = jnew JString(mountData.GetSubstring(matchList.GetElement(2))); assert( devicePath != NULL ); const JMountType type = JGetUserMountPointType(*path, *devicePath, ""); if (type == kJUnknownMountType || ACE_OS::stat(*path, &stbuf) != 0) { jdelete path; jdelete devicePath; continue; } JFileSystemType fsType = kOtherFSType; if (options.Contains("msdos")) { fsType = kVFATType; } list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } return kJTrue; }
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); } } }