GMMIMEParser::GMMIMEParser ( JString* data, const JCharacter* rootDir ) : itsTextSegments(NULL), itsTextInfo(NULL), itsAttachInfo(NULL), itsIsSuccessful(kJTrue), itsTextFileIndex(100), itsData(data) { std::istrstream input(data->GetCString(), data->GetLength()); JError err = JCreateTempDirectory(rootDir, kAttachDirPrefix, &itsAttachDir); if (!err.OK()) { itsIsSuccessful = kJFalse; err.ReportIfError(); } err = JCreateTempDirectory(rootDir, kTextDirPrefix, &itsTextDir); if (!err.OK()) { itsIsSuccessful = kJFalse; err.ReportIfError(); } if (itsIsSuccessful) { if (!JDirInfo::Create(itsTextDir, &itsTextInfo)) { itsIsSuccessful = kJFalse; err.ReportIfError(); } if (!JDirInfo::Create(itsAttachDir, &itsAttachInfo)) { itsIsSuccessful = kJFalse; err.ReportIfError(); } } if (itsIsSuccessful) { itsTextInfo->ShowHidden(kJTrue); itsAttachInfo->ShowHidden(kJTrue); Parse(input, itsData->GetLength()); } }
void CBSearchTextDialog::SearchFiles() const { JString searchStr, replaceStr; JBoolean searchIsRegex, caseSensitive, entireWord, wrapSearch; JBoolean replaceIsRegex, preserveCase; JRegex* regex; JPtrArray<JString> fileList(JPtrArrayT::kDeleteAll), nameList(JPtrArrayT::kDeleteAll); if (GetSearchParameters( &searchStr, &searchIsRegex, &caseSensitive, &entireWord, &wrapSearch, &replaceStr, &replaceIsRegex, &preserveCase, ®ex) && BuildSearchFileList(&fileList, &nameList)) { const JError err = CBSearchDocument::Create(fileList, nameList, searchStr, itsOnlyListFilesFlag, itsListFilesWithoutMatchFlag); err.ReportIfError(); } }
JBoolean SVNPropertiesList::RemoveNextProperty() { if (!itsRemovePropertyCmdList->IsEmpty()) { const JString cmd = *(itsRemovePropertyCmdList->FirstElement()); itsRemovePropertyCmdList->DeleteElement(1); JSimpleProcess* p; const JError err = JSimpleProcess::Create(&p, cmd, kJTrue); if (err.OK()) { itsProcessList->Append(p); ListenTo(p); return kJTrue; } else { err.ReportIfError(); return kJFalse; } } else { if ((GetDirector())->OKToStartActionProcess()) { RefreshContent(); } (GetDirector())->ScheduleStatusRefresh(); return kJTrue; } }
JBoolean SVNPropertiesList::CreateProperty1() { assert( itsCreatePropertyDialog != NULL ); const JString prop = JPrepArgForExec(itsCreatePropertyDialog->GetString()); const JString file = JPrepArgForExec(itsFullName); JSubstitute subst; subst.DefineVariable("prop_name", prop); subst.DefineVariable("file_name", file); JString cmd = kPropEditCmd; subst.Substitute(&cmd); JSimpleProcess* p; const JError err = JSimpleProcess::Create(&p, cmd, kJTrue); if (err.OK()) { itsProcessList->Append(p); ListenTo(p); return kJTrue; } else { err.ReportIfError(); return kJFalse; } }
void GMMIMEParser::WriteAttachment ( const JString& data, const GMIMEHeader& header ) { JString filename = header.GetFileName(); if (filename.IsEmpty()) { const JError err = JCreateTempFile(itsAttachDir, NULL, &filename); if (!err.OK()) { err.ReportIfError(); return; } } else { filename = JCombinePathAndName(itsAttachDir, filename); } AdjustAttachmentName(header, &filename); std::ofstream os(filename); if (header.GetEncoding() == kBase64Encoding) { std::istrstream is(data.GetCString(), data.GetLength()); JDecodeBase64(is, os); } else { data.Print(os); } }
void SVNInfoLog::Execute ( const JCharacter* cmd ) { (JXGetApplication())->DisplayBusyCursor(); pid_t pid; int outFD, errFD; JError err = JExecute(cmd, &pid, kJIgnoreConnection, NULL, kJCreatePipe, &outFD, kJCreatePipe, &errFD); if (!err.OK()) { err.ReportIfError(); return; } const JFontStyle red(kJTrue, kJFalse, 0, kJFalse, (GetColormap())->GetRedColor()); JString text; JReadAll(errFD, &text); SetCurrentFontStyle(red); Paste(text); JReadAll(outFD, &text); SetCurrentFontStyle(JFontStyle()); Paste(text); }
void SVNListBase::RefreshContent() { if (itsProcess != NULL) { JProcess* p = itsProcess; itsProcess = NULL; p->Kill(); delete p; DeleteLinks(); } else { itsSavedSelection->CleanOut(); JTableSelection& s = GetTableSelection(); JTableSelectionIterator iter(&s); JPoint cell; while (iter.Next(&cell)) { const JString* line = itsLineList->NthElement(cell.y); itsSavedSelection->InsertSorted(new JString(ExtractRelativePath(*line))); } } itsDisplayState = SaveDisplayState(); itsLineList->CleanOut(); int outFD, errFD; JError err = JNoError(); if ((GetDirector())->HasPath()) { err = JProcess::Create(&itsProcess, GetPath(), itsCmd, kJIgnoreConnection, NULL, kJCreatePipe, &outFD, kJCreatePipe, &errFD); } else // working with URL { err = JProcess::Create(&itsProcess, itsCmd, kJIgnoreConnection, NULL, kJCreatePipe, &outFD, kJCreatePipe, &errFD); } if (err.OK()) { itsProcess->ShouldDeleteWhenFinished(); ListenTo(itsProcess); (GetDirector())->RegisterActionProcess(this, itsProcess, itsRefreshRepoFlag, itsRefreshStatusFlag, itsReloadOpenFilesFlag); SetConnection(outFD, errFD); } else { err.ReportIfError(); } }
JBoolean JXRegexReplaceInput::InputValid() { if (!JXInputField::InputValid()) { return kJFalse; } else { const JString& text = GetText(); if (!IsRequired() && text.IsEmpty()) { return kJTrue; } const JError err = itsTestRegex->SetReplacePattern(text); if (err.OK()) { return kJTrue; } else { err.ReportIfError(); return kJFalse; } } }
void JXFLInputBase::Receive ( JBroadcaster* sender, const Message& message ) { if (sender == itsHistoryMenu && message.Is(JXMenu::kItemSelected)) { const JString origStr = GetText(); const JString newStr = itsHistoryMenu->GetItemText(message); SetText(newStr); const JError err = Apply(); if (err.OK()) { itsHistoryMenu->AddString(newStr); } else { SetText(origStr); err.ReportIfError(); } } else { JXInputField::Receive(sender, message); } }
JBoolean JXFSBindingTable::ExtractInputData ( const JPoint& cell ) { assert( itsTextInput != NULL ); const JString& s = itsTextInput->GetText(); JBoolean ok = itsTextInput->InputValid(); if (ok && cell.x == kPatternColumn) { const JFSBinding* b = itsBindingList->GetBinding(cell.y); const JBoolean changed = JI2B(b->GetPattern() != s); if (JFSBinding::WillBeRegex(s)) { const JError err = itsTestRegex->SetPattern(s); err.ReportIfError(); ok = err.OK(); } JIndex newIndex; if (ok && changed && itsBindingList->SetPattern(cell.y, s, &newIndex)) { JTableSelection& s = GetTableSelection(); s.ClearSelection(); s.SelectCell(newIndex, kPatternColumn); Broadcast(DataChanged()); } else if (ok && changed) { ok = kJFalse; const JCharacter* map[] = { "pattern", s.GetCString() }; const JString msg = JGetString(kPatternUsedID, map, sizeof(map)); (JGetUserNotification())->ReportError(msg); } } else if (ok && cell.x == kCommandColumn && itsBindingList->SetCommand(cell.y, s)) { Broadcast(DataChanged()); } return ok; }
void JXSaveFileDialog::Save ( const JCharacter* path ) { JDirInfo* dirInfo = GetDirInfo(); const JError err = dirInfo->GoTo(path); err.ReportIfError(); if (err.OK() && itsFileNameInput->Focus()) { EndDialog(kJTrue); } }
JError JSimpleProcess::Create ( const JCharacter* cmdStr, const JBoolean detach ) { JSimpleProcess* p; const JError err = Create(&p, cmdStr, kJTrue); err.ReportIfError(); if (err.OK() && detach) { JThisProcess::Ignore(p); } return err; }
JError JSimpleProcess::Create ( const JPtrArray<JString>& argList, const JBoolean detach ) { JSimpleProcess* p; const JError err = Create(&p, argList, kJTrue); err.ReportIfError(); if (err.OK() && detach) { JThisProcess::Ignore(p); } return err; }
void SyGDuplicateProcess::ProcessNextFile() { if (itsFullNameList.IsEmpty()) { JXDeleteObjectTask<JBroadcaster>::Delete(this); return; } const JString* origName = itsFullNameList.FirstElement(); JString path, name, root, suffix; JSplitPathAndName(*origName, &path, &name); if (JSplitRootAndSuffix(name, &root, &suffix)) { suffix.PrependCharacter('.'); } root += "_copy"; name = JGetUniqueDirEntryName(path, root, suffix); JSplitPathAndName(name, &path, &itsCurrentName); const JCharacter* argv[] = { "cp", "-Rdf", *origName, name, NULL }; JVCSType type; if (JIsManagedByVCS(*origName, &type) && type == kJSVNType) { argv[0] = "svn"; argv[1] = "cp"; } const JError err = JSimpleProcess::Create(&itsProcess, argv, sizeof(argv)); err.ReportIfError(); itsFullNameList.DeleteElement(1); // before ProcessNextFile() if (err.OK()) { ListenTo(itsProcess); JThisProcess::Ignore(itsProcess); // detach so it always finishes } else { itsProcess = NULL; itsNodeList.RemoveElement(1); ProcessNextFile(); } }
JBoolean JGetSVNEntryType ( const JCharacter* url, JString* type, JString* error ) { type->Clear(); error->Clear(); JString cmd = "svn info --xml " + JPrepArgForExec(url); JProcess* p; int fromFD, errFD; JError err = JProcess::Create(&p, cmd, kJIgnoreConnection, NULL, kJCreatePipe, &fromFD, kJCreatePipe, &errFD); if (!err.OK()) { err.ReportIfError(); return kJFalse; } p->WaitUntilFinished(); if (p->SuccessfulFinish()) { xmlDoc* doc = xmlReadFd(fromFD, NULL, NULL, XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA); close(fromFD); if (doc != NULL) { xmlNode* root = xmlDocGetRootElement(doc); if (root != NULL && strcmp((char*) root->name, "info") == 0 && strcmp((char*) root->children->name, "entry") == 0) { *type = JGetXMLNodeAttr(root->children, "kind"); return kJTrue; } } } JReadAll(errFD, error, kJTrue); return kJFalse; }
JBoolean JXFLInputBase::OKToUnfocus() { if (!JXInputField::OKToUnfocus()) { return kJFalse; } const JError err = Apply(); if (err.OK()) { itsHistoryMenu->AddString(GetText()); return kJTrue; } else { err.ReportIfError(); return kJFalse; } }
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; }
int main ( int argc, char* argv[] ) { if (argc == 1) { char buffer[BUFSIZ]; while (1) { ssize_t count = read(0, buffer, sizeof(buffer)); if (count < 0 && jerrno() == EINTR) { // keep going } else if (count <= 0) { break; } else { // cerr << count << endl; cout.write(buffer, count); JWait(0.01); } } return 0; } JProcess* p; int fromFD; const JError err = JProcess::Create(&p, argv[1], kJIgnoreConnection, NULL, kJForceNonblockingPipe, &fromFD, kJAttachToFromFD, NULL); if (err.OK()) { char buffer[BUFSIZ]; while (1) { ssize_t count = read(fromFD, buffer, sizeof(buffer)); if (count < 0 && jerrno() == EINTR) { // keep going } else if (count <= 0) { break; } else { // cerr << count << endl; cout.write(buffer, count); JWait(0.02); } } /* ProcessLink* link = new ProcessLink(fromFD); assert( link != NULL ); ACE_Time_Value delta(20); ACE_Reactor::instance()->run_reactor_event_loop(delta); link->Dump(); delete link; */ return 0; } else { JInitCore(); err.ReportIfError(); return 1; } }
JBoolean CBCommand::StartProcess() { // check if we are finished while (!itsCmdList->IsEmpty() && (itsCmdList->GetElement(1)).IsEndOfSequence()) { CmdInfo info = itsCmdList->GetElement(1); info.Free(kJTrue); itsCmdList->RemoveElement(1); } if (itsCmdList->IsEmpty()) { if (itsBeepFlag && itsParent == NULL) { ((JXGetApplication())->GetCurrentDisplay())->Beep(); } DeleteThis(); return kJFalse; } // check if we can use the window itsInQueueFlag = kJFalse; if (itsOutputDoc != NULL && itsOutputDoc->ProcessRunning()) { itsInQueueFlag = kJTrue; ListenTo(itsOutputDoc); return kJTrue; // wait for message from itsOutputDoc } // check if need to run a subroutine CmdInfo info = itsCmdList->GetElement(1); if (info.cmdObj != NULL) { StopListening(itsOutputDoc); // wait for CBCommand to notify us const JBoolean result = (info.cmdObj)->Start(*(info.cmdInfo)); info.Free(kJFalse); itsCmdList->RemoveElement(1); return result; } // start process assert( info.cmd != NULL ); JShouldIncludeCWDOnPath(kJTrue); JProcess* p; int toFD, fromFD; JError execErr = JNoError(); if (itsOutputDoc != NULL) { execErr = JProcess::Create(&p, itsCmdPath, *(info.cmd), kJCreatePipe, &toFD, kJCreatePipe, &fromFD, kJAttachToFromFD, NULL); } else { JSimpleProcess* p1; execErr = JSimpleProcess::Create(&p1, itsCmdPath, *(info.cmd), kJTrue); p = p1; } JShouldIncludeCWDOnPath(kJFalse); if (!execErr.OK()) { execErr.ReportIfError(); DeleteThis(); return kJFalse; } if (itsOutputDoc != NULL) { const JSize count = info.cmd->GetElementCount(); JString cmd; for (JIndex i=1; i<=count; i++) { cmd += JPrepArgForExec(*info.cmd->NthElement(i)); cmd += " "; } itsOutputDoc->SetConnection(p, fromFD, toFD, itsWindowTitle, itsDontCloseMsg, itsCmdPath, cmd, kJTrue); // We can't do this in Start() because we might be waiting for // itsMakeDependCmd. We must not listen to both at the same time. ListenTo(itsOutputDoc); } else { ListenTo(p); JThisProcess::Ignore(p); } info.Free(kJTrue); itsCmdList->RemoveElement(1); return kJTrue; }
JBoolean JXSearchTextDialog::GetSearchParameters ( JString* searchStr, JBoolean* searchIsRegex, JBoolean* caseSensitive, JBoolean* entireWord, JBoolean* wrapSearch, JString* replaceStr, JBoolean* replaceIsRegex, JBoolean* preserveCase, JRegex** regex ) const { if (!HasSearchText()) { (JGetUserNotification())->ReportError("You must enter something for which to search."); itsSearchInput->Focus(); return kJFalse; } *wrapSearch = itsWrapSearchCB->IsChecked(); *caseSensitive = !itsIgnoreCaseCB->IsChecked(); *preserveCase = itsPreserveCaseCB->IsChecked(); *searchStr = itsSearchInput->GetText(); *searchIsRegex = itsSearchIsRegexCB->IsChecked(); if (*searchIsRegex) { itsRegex->SetCaseSensitive(*caseSensitive); itsRegex->SetSingleLine(itsSingleLineCB->IsChecked()); const JError err = itsRegex->SetPattern(*searchStr); if (!err.OK()) { itsSearchInput->Focus(); err.ReportIfError(); return kJFalse; } } *replaceStr = itsReplaceInput->GetText(); *replaceIsRegex = itsReplaceIsRegexCB->IsChecked(); if (*replaceIsRegex) { itsRegex->SetMatchCase(*preserveCase); JIndexRange errRange; const JError err = itsRegex->SetReplacePattern(*replaceStr, &errRange); if (!err.OK()) { itsReplaceInput->Focus(); itsReplaceInput->SetSelection(errRange); err.ReportIfError(); return kJFalse; } } if (*searchIsRegex || itsSearchInput->IsEntireWord(1, itsSearchInput->GetTextLength())) { *entireWord = itsEntireWordCB->IsChecked(); } else { *entireWord = kJFalse; } *regex = itsRegex; // use the original strings, not the substituted ones itsPrevSearchMenu->AddString(itsSearchInput->GetText()); itsPrevReplaceMenu->AddString(itsReplaceInput->GetText()); // broadcast to other programs who support Xsearch protocol if (itsNeedXSearchBcastFlag) { SetXSearch(); } return kJTrue; }
JBoolean CBFileNameDisplay::InputValid() { const JString& text = GetText(); if (itsUnfocusAction == kCancel) { return kJTrue; } else if (text.IsEmpty()) { (JGetUserNotification())->ReportError(JGetString(kEmptyErrorID)); return kJFalse; } else if (text.EndsWith(ACE_DIRECTORY_SEPARATOR_STR)) { (JGetUserNotification())->ReportError(JGetString(kNoFileNameID)); return kJFalse; } else if (JIsRelativePath(text)) { return kJTrue; // open Choose File dialog } JString path, fullPath, name; JSplitPathAndName(text, &path, &name); if (!JExpandHomeDirShortcut(path, &fullPath)) { return kJFalse; } const JString fullName = JCombinePathAndName(fullPath, name); JBoolean onDisk; const JString origFullName = itsDoc->GetFullName(&onDisk); if (onDisk && JSameDirEntry(origFullName, fullName)) { itsUnfocusAction = kCancel; return kJTrue; } if (JFileExists(fullName)) { const JCharacter* map[] = { "f", text }; const JString msg = JGetString(kOKToReplaceID, map, sizeof(map)); if (!(JGetUserNotification())->AskUserNo(msg)) { return kJFalse; } } if (!JDirectoryExists(fullPath)) { const JError err = JCreateDirectory(fullPath); if (!err.OK()) { err.ReportIfError(); return kJFalse; } } else if (!JDirectoryWritable(fullPath)) { const JError err = JAccessDenied(fullPath); err.ReportIfError(); return kJFalse; } if (itsUnfocusAction == kRename) { const JError err = JRenameVCS(origFullName, fullName); err.ReportIfError(); return err.OK(); } else { return kJTrue; } }