void CBMacroTable::ReadData ( const JCharacter* fileName, const JBoolean replace ) { JStringTableData* data = GetStringData(); if (replace) { data->RemoveAllRows(); } JIndex firstNewRow = 0; ifstream input(fileName); JString macro, script; JIndex state = 1; while (!input.eof() && !input.fail()) { if (state == 1) { macro = JReadLine(input); if (!macro.IsEmpty()) { state = 2; } } else if (state == 2) { script = JReadLine(input); if (!script.IsEmpty()) { data->AppendRows(1); const JSize rowCount = data->GetRowCount(); data->SetString(rowCount,kMacroColumn, macro); data->SetString(rowCount,kScriptColumn, script); if (firstNewRow == 0) { firstNewRow = rowCount; } state = 1; } } } if (firstNewRow != 0) { ScrollTo((GetBounds()).bottomLeft()); BeginEditing(JPoint(kMacroColumn, firstNewRow)); } }
void GXDataDocument::LoadFile ( const JCharacter* fileName ) { std::ifstream is(fileName); if (is.bad()) { JGetUserNotification()->ReportError("Error opening file."); } else { const JString str = JReadLine(is); if (str == kGloveFileSignature) { if (!LoadNativeFile(is)) { JGetUserNotification()->ReportError( "This file was created by a newer version of Glove. " "You need the newest version in order to open it."); } } else { is.close(); FileChanged(fileName, kJFalse); itsCurrentFileName = fileName; ChooseFileFilter(); } } }
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; } }
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; }
JBoolean JIsManagedByVCS ( const JCharacter* fullName, JVCSType* returnType ) { const JVCSType type = JGetVCSType(fullName); JBoolean isManaged = kJFalse; if (type == kJSVNType) { 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)*?>"; const JRegex r(pattern); isManaged = r.Match(data); } 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"; JIgnoreUntil(input, pattern, &isManaged); } } } else if (type == kJGitType) { isManaged = kJTrue; // TODO: ask git (until then, better safe than sorry) } if (returnType != NULL) { *returnType = (isManaged ? type : kJUnknownVCSType); } return isManaged; }
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 CBSearchTextDialog::LoadFileSet() { JString fullName; if (itsCSF->ChooseFile("", NULL, &fullName)) { if (itsCSF->ReplaceExisting()) { itsFileList->RemoveAllFiles(); } std::ifstream input(fullName); JString file; while (!input.eof() && !input.fail()) { file = JReadLine(input); if (JFileReadable(file)) { itsFileList->AddFile(file); } } } }
int GMScanner::yylex() { if (itsCurrentPosition == 0) { itsIs >> std::ws; itsCurrentPosition = JTellg(*itsIs); itsCurrentHeaderStart = itsCurrentPosition; itsText = JReadLine(*itsIs); JRegex regex; JBoolean matched; JArray<JStringRange>* subList = new JArray<JStringRange>; assert(subList != NULL); err = regex.SetPattern("^From[[:space:]]+.*.{3}[[:space:]]+.{3}[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+:[[:digit:]]+:[[:digit:]]+[[:space:]]+[[:digit:]]{4}"); assert(err.OK()); matched = regex.Match(itsText, subList); delete subList; if (matched) { itsState = kHeaderStart; return itsState; } }
JBoolean MatchesCookie ( const JCharacter* cookie, const JDirEntry& entry ) { JString file = entry.GetFullName(); if (!JFileReadable(file)) { return kJFalse; } mode_t perms; JError err = JGetPermissions(file, &perms); if (!err.OK()) { perms = 0600; } ifstream is(file); is >> ws; JString line1 = JReadLine(is); is.close(); if (line1 == "") { return kJTrue; } JArray<JIndexRange> subList; JRegex regex; err = regex.SetPattern(cookie); JBoolean matched = regex.Match(line1, &subList); if (matched) { return kJTrue; } return kJFalse; }
void GAddressBookMgr::AddAddressBook ( const JCharacter* name, JTree* tree ) { if (!JFileExists(name)) { return; } JDirEntry* dirEntry = new JDirEntry(name); assert(dirEntry != NULL); JTreeNode* jbase = tree->GetRoot(); JNamedTreeNode* base = dynamic_cast<JNamedTreeNode*>(jbase); assert(base != NULL); GAddressBookTreeNode* book = new GAddressBookTreeNode(dirEntry, base, dirEntry->GetName()); assert(book != NULL); std::ifstream is(name); while (is.good()) { JString line = JReadLine(is); GAddressBookEntry* entry = new GAddressBookEntry(); assert( entry != NULL ); JString name; if (GetNextRecord(line, name, is)) { GetNextRecord(line, entry->fullname, is); if (GetNextRecord(line, entry->address, is)) { GetNextRecord(line, entry->fcc, is); GetNextRecord(line, entry->comment, is); itsAddresses->SetElement(name, entry, JPtrArrayT::kDelete); GAddressEntryTreeNode* aEntry = new GAddressEntryTreeNode(book, entry->fullname); assert(aEntry != NULL); GAddressItemTreeNode* item = new GAddressItemTreeNode(GAddressItemTreeNode::kName, aEntry, name, kJFalse); assert(item != NULL); JString address = entry->address; if (address.BeginsWith("(") && address.GetLength() > 2) { address = address.GetSubstring(2, address.GetLength() - 1); JPtrArray<JString> list(JPtrArrayT::kForgetAll); GParseNameList(address, list); const JSize count = list.GetElementCount(); for (JSize i = count; i >= 1; i--) { item = new GAddressItemTreeNode(GAddressItemTreeNode::kEMail, aEntry, *(list.NthElement(i)), kJFalse); assert(item != NULL); } list.DeleteAll(); } else { item = new GAddressItemTreeNode(GAddressItemTreeNode::kEMail, aEntry, address, kJFalse); } if (!entry->comment.IsEmpty()) { item = new GAddressItemTreeNode(GAddressItemTreeNode::kComment, aEntry, entry->comment, kJFalse); assert(item != NULL); } if (!entry->fcc.IsEmpty()) { item = new GAddressItemTreeNode(GAddressItemTreeNode::kFcc, aEntry, entry->fcc, kJFalse); assert(item != NULL); } book->InsertSorted(aEntry); continue; } } delete entry; } }
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); }
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; }
JBoolean JGetVCSRepositoryPath ( const JCharacter* origPath, JString* repoPath ) { JString path = origPath, name; if (JFileExists(origPath) || !JDirectoryExists(origPath)) // broken link { JSplitPathAndName(origPath, &path, &name); } const JVCSType type = JGetVCSType(path); JBoolean found = kJFalse; if (type == kJCVSType) { const JString cvsPath = JCombinePathAndName(path, kCVSDirName); JString fullName = JCombinePathAndName(cvsPath, "Root"); JReadFile(fullName, repoPath); fullName = JCombinePathAndName(cvsPath, "Repository"); JString repo; JReadFile(fullName, &repo); if (!repoPath->IsEmpty() && !repo.IsEmpty()) { *repoPath = JCombinePathAndName(*repoPath, repo); found = kJTrue; } } else if (type == kJSVNType) { JString entriesFileName, data; entriesFileName = JCombinePathAndName(path, kSubversionDirName); entriesFileName = JCombinePathAndName(entriesFileName, kSubversionFileName); JReadFile(entriesFileName, &data); if (data.BeginsWith("<?xml")) { JIndexRange range; JArray<JIndexRange> matchList; if (svn4RepositoryPattern1.Match(data, &range) && svn4RepositoryPattern2.MatchWithin(data, range, &matchList)) { *repoPath = data.GetSubstring(matchList.GetElement(2)); found = kJTrue; } } else { std::istrstream input(data, data.GetLength()); const JString version = JReadLine(input); if (version == "8" || version == "9" || version == "10") { JIgnoreLine(input); // ??? JIgnoreLine(input); // dir JIgnoreLine(input); // latest update version *repoPath = JReadLine(input); found = JI2B(input.good()); } } } if (found) { if (!name.IsEmpty()) { *repoPath = JCombinePathAndName(*repoPath, name); } return kJTrue; } else { repoPath->Clear(); return kJFalse; } }
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); } } }
int main ( int argc, char* argv[] ) { // find the configuration files if (!FindConfigFile(&classMapFile) || !FindConfigFile(&optionMapFile) || !FindConfigFile(&needFontListFile) || !FindConfigFile(&needStringListFile) || !FindConfigFile(&needCreateListFile)) { return 1; } // parse the command line options JString inputName, codePath, stringPath, codeSuffix, headerSuffix; JString postCmd; JPtrArray<JString> userFormList(JPtrArrayT::kDeleteAll); // empty => generate all forms JPtrArray<JString> backupList(JPtrArrayT::kDeleteAll); // forms that have been backed up GetOptions(argc, argv, &inputName, &codePath, &stringPath, &codeSuffix, &headerSuffix, &postCmd, &userFormList); // generate each requested form JBoolean changed = kJFalse; ifstream input(inputName); while (!input.eof() && !input.fail()) { const JString line = JReadLine(input); if (line == kBeginFormLine) { // get form name JString formName = JReadLine(input); RemoveIdentifier(kFormNameMarker, &formName); // look for custom tag const JSize formNameLength = formName.GetLength(); JString tagName = kDefaultDelimTag; JString enclName; JIndex tagMarkerIndex; if (formName.LocateSubstring(kCustomTagMarker, &tagMarkerIndex) && tagMarkerIndex <= formNameLength - kCustomTagMarkerLength) { tagName = formName.GetSubstring( tagMarkerIndex + kCustomTagMarkerLength, formNameLength); formName.RemoveSubstring(tagMarkerIndex, formNameLength); // get enclosure name const JSize tagNameLength = tagName.GetLength(); JIndex enclMarkerIndex; if (tagName.LocateSubstring(kCustomTagMarker, &enclMarkerIndex) && enclMarkerIndex <= tagNameLength - kCustomTagMarkerLength) { enclName = tagName.GetSubstring( enclMarkerIndex + kCustomTagMarkerLength, tagNameLength); tagName.RemoveSubstring(enclMarkerIndex, tagNameLength); } // report errors if (tagName != kDefaultDelimTag) { if (enclName.IsEmpty()) { cerr << formName << ", " << tagName; cerr << ": no enclosure specified" << endl; } } else if (!enclName.IsEmpty() && enclName != kDefTopEnclVarName) { cerr << formName << ", " << tagName; cerr << ": not allowed to specify enclosure other than "; cerr << kDefTopEnclVarName << endl; } } if (ShouldGenerateForm(formName, userFormList)) { GenerateForm(input, formName, tagName, enclName, codePath, stringPath, codeSuffix, headerSuffix, &backupList); changed = kJTrue; } } } if (changed && !postCmd.IsEmpty()) { const JError err = JExecute(postCmd, NULL); err.ReportIfError(); } return 0; }
void LLDBGetAssembly::HandleSuccess ( const JString& cmdData ) { LLDBLink* link = dynamic_cast<LLDBLink*>(CMGetLink()); if (link == NULL) { return; } lldb::SBCommandInterpreter interp = link->GetDebugger()->GetCommandInterpreter(); if (!interp.IsValid()) { return; } const CMLocation& loc = (GetDirector())->GetDisassemblyLocation(); const JString cmd = "disassemble -n " + JPrepArgForExec(loc.GetFunctionName()); lldb::SBCommandReturnObject result; interp.HandleCommand(cmd, result); JPtrArray<JString> addrList(JPtrArrayT::kDeleteAll); JString instText; if (result.IsValid() && result.Succeeded() && result.HasResult()) { std::istringstream input(result.GetOutput()); JString line, s; JSize maxOffsetLength = 0; while (!input.eof() && !input.fail()) { line = JReadLine(input); JIndex i; if (line.LocateSubstring(":", &i) && i < line.GetLength()) { s = line.GetSubstring(1, i-1); if (s.BeginsWith("->") && s.GetLength() > 2) { s = s.GetSubstring(3, s.GetLength()); } s.TrimWhitespace(); addrList.Append(s); JIndexRange r; if (offsetPattern.Match(s, &r)) { maxOffsetLength = JMax(maxOffsetLength, r.GetLength()); } if (!instText.IsEmpty()) { instText.AppendCharacter('\n'); } s = line.GetSubstring(i+1, line.GetLength()); s.TrimWhitespace(); instText.Append(s); } } const JSize count = addrList.GetElementCount(); for (JIndex i=1; i<count; i++) { JString* s = addrList.NthElement(i); JIndexRange r; if (offsetPattern.Match(*s, &r)) { const JSize pad = maxOffsetLength - r.GetLength(); for (JIndex j=0; j<pad; j++) { s->InsertCharacter('0', r.first+2); } } } } (GetDirector())->DisplayDisassembly(&addrList, instText); }
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()); } }
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(); }
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 GMMIMEParser::ParseMixed ( std::istream& input, const GMIMEHeader& header ) { JString boundary = "-" + header.GetBoundary(); JString endBoundary = boundary + "--"; // slurp the initial empty part JIndex bstart, bend; ReadUntilBoundary(input, boundary, &bstart, &bend); JIndex current = JTellg(input); JString data; data.Read(input, bend - current + 1); while (1) { GMIMEHeader child; ParseMIMEHeader(input, &child); // when the following function returns true, it has found the // last boundary data.Clear(); JBoolean end; if (child.GetEncoding() == kBase64Encoding) { JString filename = child.GetFileName(); if (filename.IsEmpty()) { JCreateTempFile(itsAttachDir, NULL, &filename); } else { filename = JCombinePathAndName(itsAttachDir, filename); } if (!filename.IsEmpty()) { AdjustAttachmentName(child, &filename); std::ofstream os(filename); JDecodeBase64(input, os); end = ReadUntilBoundary(input, boundary, &bstart, &bend); // JBoolean found; // JString line; // while (line.IsEmpty() && !input.fail()) // { // line = JReadLine(input, &found); // } // JString endBoundary = boundary + "--"; // if (line.Contains(endBoundary)) // { // end = kJTrue; // } } } else if ((child.GetType() != kMultipartType) && (!child.GetFileName().IsEmpty())) { JIndex startI = JTellg(input); JIndex findex = startI; if (itsData->LocateNextSubstring(boundary, &findex)) { const JCharacter* c = itsData->GetCString() + startI; JString filename = child.GetFileName(); if (filename.IsEmpty()) { JCreateTempFile(itsAttachDir, NULL, &filename); } else { filename = JCombinePathAndName(itsAttachDir, filename); } if (!filename.IsEmpty()) { AdjustAttachmentName(child, &filename); std::ofstream os(filename); JSeekg(input, findex - 1); if (child.GetEncoding() == kQPEncoding) { JString data = itsData->GetSubstring(startI, findex - 3); ParseQuotedPrintable(&data); data.Print(os); } else { os.write(c, findex - startI - 3); } JBoolean found; JString line = JReadLine(input, &found); if (line.BeginsWith(endBoundary)) { end = kJTrue; } } } } else { end = ReadUntilBoundary(input, boundary, &bstart, &bend); ParseByType(input, child, bstart - 1); current = JTellg(input); data.Read(input, bend - current + 1); } if (end) { break; } } if (itsTextInfo != NULL) { itsTextInfo->ForceUpdate(); } if (itsAttachInfo != NULL) { itsAttachInfo->ForceUpdate(); } }