/*static*/ BString Playlist::_GetExceptExtension(const BString& path) { int32 periodPos = path.FindLast('.'); if (periodPos <= path.FindLast('/')) return path; return BString(path.String(), periodPos); }
void TeamDescriptionView::SetItem(TeamListItem* item) { fItem = item; int32 styleStart = 0; int32 styleEnd = 0; BTextView* view = NULL; if (item == NULL) { BString text; text.SetToFormat(fInfoString, fSeconds); fInfoTextView->SetText(text); if (fRebootRunner != NULL && fSeconds < 4) { styleStart = text.FindLast('\n'); styleEnd = text.Length(); } view = fInfoTextView; } else { BString text = item->Path()->Path(); if (item->IsSystemServer()) text << "\n" << fSysComponentString; if (item->IsRefusingToQuit()) { text << "\n\n" << fQuitOverdueString; styleStart = text.FindLast('\n'); styleEnd = text.Length(); } view = fIconTextView; fIconTextView->SetText(text); fIconView->SetIcon(item->Path()->Path()); } if (styleStart != styleEnd && view != NULL) { BFont font; view->GetFont(&font); font.SetFace(B_BOLD_FACE); view->SetStylable(true); view->SetFontAndColor(styleStart, styleEnd, &font); } if (fLayout == NULL) return; if (item == NULL) fLayout->SetVisibleItem((int32)0); else fLayout->SetVisibleItem((int32)1); Invalidate(); }
void AddTorrentWindow::UpdateFileList() { // // int fileCount = fTorrent->Info()->fileCount; tr_file* fileList = fTorrent->Info()->files; for( int i = 0; i < fileCount; i++ ) { char FormatBuffer[128] = { 0 }; BRow* row = new BRow(FILE_COLUMN_HEIGHT); const char* name = fTorrent->IsFolder() ? (strchr(fileList[i].name, '/') + 1) : fileList[i].name; // // // BString FileExtension = B_EMPTY_STRING; BString FilePath = fileList[i].name; FilePath.CopyInto(FileExtension, FilePath.FindLast('.') + 1, FilePath.CountChars()); const char* info = tr_formatter_mem_B(FormatBuffer, fileList[i].length, sizeof(FormatBuffer));; const BBitmap* icon = GetIconFromExtension(FileExtension); row->SetField(new FileField(icon, name, info), COLUMN_FILE_NAME); row->SetField(new CheckBoxField(true), COLUMN_FILE_DOWNLOAD); ////row->SetField(new BIntegerField(PeerStatus[i].progress * 100.0), COLUMN_PEER_PROGRESS); fFileList->AddRow(row, i); } }
void BMailRemoteStorageProtocol::SyncMailbox(const char *mailbox) { BPath path(runner->Chain()->MetaData()->FindString("path")); path.Append(mailbox); BDirectory folder(path.Path()); BEntry entry; BFile snoodle; BString string; uint32 chain; bool append; while (folder.GetNextEntry(&entry) == B_OK) { if (!entry.IsFile()) continue; while (snoodle.SetTo(&entry,B_READ_WRITE) == B_BUSY) snooze(100); append = false; while (snoodle.Lock() != B_OK) snooze(100); snoodle.Unlock(); if (snoodle.ReadAttr("MAIL:chain",B_INT32_TYPE,0,&chain,sizeof(chain)) < B_OK) append = true; if (chain != runner->Chain()->ID()) append = true; if (snoodle.ReadAttrString("MAIL:unique_id",&string) < B_OK) append = true; BString folder(string), id(""); int32 j = string.FindLast('/'); if ((!append) && (j >= 0)) { folder.Truncate(j); string.CopyInto(id,j + 1,string.Length()); if (folder == mailbox) continue; } else { append = true; } if (append) AddMessage(mailbox,&snoodle,&id); //---We should check for partial messages here else CopyMessage(folder.String(),mailbox,&id); string = mailbox; string << '/' << id; /*snoodle.RemoveAttr("MAIL:unique_id"); snoodle.RemoveAttr("MAIL:chain");*/ chain = runner->Chain()->ID(); snoodle.WriteAttr("MAIL:chain",B_INT32_TYPE,0,&chain,sizeof(chain)); snoodle.WriteAttrString("MAIL:unique_id",&string); (*manifest) += string.String(); (*unique_ids) += string.String(); string = runner->Chain()->Name(); snoodle.WriteAttrString("MAIL:account",&string); } }
void TeamDescriptionView::SetItem(TeamListItem* item) { fItem = item; if (item == NULL) { int32 styleStart = 0; int32 styleEnd = 0; BString text; text.SetToFormat(fInfoString, fSeconds); fInfoTextView->SetText(text); if (fRebootRunner != NULL && fSeconds < 4) { styleStart = text.FindLast('\n'); styleEnd = text.Length(); } if (styleStart != styleEnd && fInfoTextView != NULL) { BFont font; fInfoTextView->GetFont(&font); font.SetFace(B_BOLD_FACE); fInfoTextView->SetStylable(true); fInfoTextView->SetFontAndColor(styleStart, styleEnd, &font); } } else { fTeamName->SetText(item->Path()->Path()); if (item->IsSystemServer()) { if (fSysComponent->IsHidden(fSysComponent)) fSysComponent->Show(); } else { if (!fSysComponent->IsHidden(fSysComponent)) fSysComponent->Hide(); } if (item->IsRefusingToQuit()) { if (fQuitOverdue->IsHidden(fQuitOverdue)) fQuitOverdue->Show(); } else { if (!fQuitOverdue->IsHidden(fQuitOverdue)) fQuitOverdue->Hide(); } fIconView->SetIcon(item->Path()->Path()); } if (fLayout == NULL) return; if (item == NULL) fLayout->SetVisibleItem((int32)0); else fLayout->SetVisibleItem((int32)1); Invalidate(); }
FindOpenFileWindow::FindOpenFileWindow(const char* panelText) : DWindow(BRect(0, 0, 0, 0), TR("Find and open file"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) { AddCommonFilter(new EscapeCancelFilter()); BView* top = GetBackgroundView(); fNameTextControl = new AutoTextControl("nameText", TR("Open: "), "", new BMessage); fNameTextControl->SetExplicitMinSize( BSize(fNameTextControl->StringWidth("M") * 20, B_SIZE_UNSET)); fSystemCheckBox = new BCheckBox("systembox", TR("Search only system folders"), new BMessage); BButton* cancel = new BButton("cancel", TR("Cancel"), new BMessage(B_QUIT_REQUESTED)); BButton* open = new BButton("open", TR("Open"), new BMessage(M_FIND_FILE)); BLayoutBuilder::Group<>(top, B_VERTICAL) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0) .Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0) .Add(fSystemCheckBox, 1, 1) .End() .AddGlue() .AddGroup(B_HORIZONTAL) .AddGlue() .Add(cancel) .Add(open) .End() .SetInsets(B_USE_WINDOW_INSETS) .End(); BString text = panelText; if (text.CountChars() > 1) { fNameTextControl->SetText(text.String()); int32 position = text.FindLast("."); if (position > 0) fNameTextControl->TextView()->Select(0, position); else fNameTextControl->TextView()->SelectAll(); } else { fNameTextControl->SetText(".h"); fNameTextControl->TextView()->GoToLine(0); } open->MakeDefault(true); fNameTextControl->MakeFocus(true); CenterOnScreen(); }
BString FormatResultString(const BString& resultPath) { BString result; int32 end = resultPath.FindFirst("CodeName") - 2; int32 start = resultPath.FindLast('/', end) + 1; if (end - start > 1) { resultPath.CopyInto(result, start, end - start + 1); result += "::"; result += &resultPath.String()[resultPath.FindLast('/', resultPath.Length()) + 1]; } else { int32 secbegin = resultPath.FindLast('/', resultPath.Length()) + 1; resultPath.CopyInto(result, secbegin, resultPath.Length() - secbegin); } return result; }
BUrl::BUrl(const BUrl& base, const BString& location) : fUrlString(), fProtocol(), fUser(), fPassword(), fHost(), fPort(0), fPath(), fRequest(), fHasAuthority(false) { // This implements the algorithm in RFC3986, Section 5.2. BUrl relative(location); if (relative.HasProtocol()) { SetProtocol(relative.Protocol()); SetAuthority(relative.Authority()); SetPath(relative.Path()); // TODO _RemoveDotSegments() SetRequest(relative.Request()); } else { if (relative.HasAuthority()) { SetAuthority(relative.Authority()); SetPath(relative.Path()); // TODO _RemoveDotSegments() SetRequest(relative.Request()); } else { if (relative.Path().IsEmpty()) { SetPath(base.Path()); if (relative.HasRequest()) SetRequest(relative.Request()); else SetRequest(Request()); } else { if (relative.Path()[0] == '/') SetPath(relative.Path()); else { BString path = base.Path(); // Remove last part of path (the file, if any) so we get the // "current directory" path.Truncate(path.FindLast('/') + 1); path += relative.Path(); // TODO _RemoveDotSegments() SetPath(path); } SetRequest(relative.Request()); } SetAuthority(base.Authority()); } SetProtocol(base.Protocol()); } SetFragment(relative.Fragment()); }
bool AutoConfigView::IsValidMailAddress(BString email) { int32 atPos = email.FindFirst("@"); if (atPos < 0) return false; BString provider; email.CopyInto(provider, atPos + 1, email.Length() - atPos); if (provider.FindLast(".") < 0) return false; return true; }
OpenPackageAction(PackageInfoRef package, Model* model, const DeskbarLink& link) : PackageAction(PACKAGE_ACTION_OPEN, package, model), fDeskbarLink(link), fLabel(B_TRANSLATE("Open %DeskbarLink%")) { BString target = fDeskbarLink.link; int32 lastPathSeparator = target.FindLast('/'); if (lastPathSeparator > 0 && lastPathSeparator + 1 < target.Length()) target.Remove(0, lastPathSeparator + 1); fLabel.ReplaceAll("%DeskbarLink%", target); }
bool StringCompare(const BString &from, const BString &to, const char *mode, const bool &match_case) { if (!mode) { debugger("NULL mode in StringCompare"); return false; } if (strcmp(mode,"is") == 0) if (match_case) return from.Compare(to) == 0; else return from.ICompare(to) == 0; else if (strcmp(mode,"is not") == 0) if (match_case) return from.Compare(to) != 0; else return from.ICompare(to) != 0; else if (strcmp(mode,"contains") == 0) if (match_case) return to.FindFirst(from) >= 0; else return to.IFindFirst(from) >= 0; else if (strcmp(mode,"does not contain") == 0) if (match_case) return to.FindFirst(from) < 0; else return to.IFindFirst(from) < 0; else if (strcmp(mode,"starts with") == 0) if (match_case) return to.FindFirst(from) == 0; else return to.IFindFirst(from) == 0; else if (strcmp(mode,"ends with") == 0) { int32 pos; if (match_case) pos = to.FindLast(from); else pos = to.IFindLast(from); return (to.CountChars() - from.CountChars() == pos); } return false; }
void _SplitNormalizedPath(const BString& path, BString& _directory, BString& _name) { // handle single component (including root dir) cases int32 lastSlash = path.FindLast('/'); if (lastSlash < 0 || path.Length() == 1) { _directory = (const char*)NULL; _name = path; return; } // handle root dir + one component and multi component cases if (lastSlash == 0) _directory = "/"; else _directory.SetTo(path, lastSlash); _name = path.String() + (lastSlash + 1); }
void PanelView::GotoParent(void) //////////////////////////////////////////////////////////////////////// { // To set the cursor to the child entry where we came from... BString oldpath; SetPanelMode(PM_NORMAL); oldpath.SetTo(m_Path.String()); oldpath.Remove(0,oldpath.FindLast('/')+1); BPath path((const char *)m_Path.String()); if (path.GetParent(&path)==B_OK) m_Path.SetTo(path.Path()); SetPathStringView(); ClearFileList(); ReadDirectory(oldpath.String()); }
BHttpAuthentication& BUrlContext::GetAuthentication(const BUrl& url) { BString domain = url.Host(); domain += url.Path(); BHttpAuthentication* authentication = NULL; do { authentication = fAuthenticationMap->Get( HashString(domain.String(), domain.Length())); domain.Truncate(domain.FindLast('/')); } while(authentication == NULL); return *authentication; }
bool Project::IsProject(const entry_ref &ref) { BNode node(&ref); BString type; node.ReadAttrString("BEOS:TYPE",&type); if (type.CountChars() > 0 && type == PROJECT_MIME_TYPE) return true; BString extension = BPath(&ref).Path(); int32 pos = extension.FindLast("."); if (pos >= 0) { extension = extension.String() + pos; if (extension.ICompare(".pld") == 0) return true; } return false; }
status_t POP3Protocol::_RetrieveUniqueIDs() { fUniqueIDs.MakeEmpty(); fSizes.clear(); fTotalSize = 0; status_t status = SendCommand("UIDL" CRLF); if (status != B_OK) return status; BString result; int32 uidOffset; while (ReceiveLine(result) > 0) { if (result.ByteAt(0) == '.') break; uidOffset = result.FindFirst(' ') + 1; result.Remove(0, uidOffset); fUniqueIDs.Add(result); } if (SendCommand("LIST" CRLF) != B_OK) return B_ERROR; while (ReceiveLine(result) > 0) { if (result.ByteAt(0) == '.') break; int32 index = result.FindLast(" "); int32 size; if (index >= 0) size = atol(&result.String()[index]); else size = 0; fTotalSize += size; fSizes.push_back(size); } return B_OK; }
static bool strip_port(BString& host, BString& port) { int32 first = host.FindFirst(':'); int32 separator = host.FindLast(':'); if (separator != first && (separator == 0 || host.ByteAt(separator - 1) != ']')) { return false; } if (separator != -1) { // looks like there is a port host.CopyInto(port, separator + 1, -1); host.Truncate(separator); return true; } return false; }
status_t POP3Protocol::_UniqueIDs() { fUniqueIDs.MakeEmpty(); status_t ret = B_OK; ret = SendCommand("UIDL" CRLF); if (ret != B_OK) return ret; BString result; int32 uid_offset; while (ReceiveLine(result) > 0) { if (result.ByteAt(0) == '.') break; uid_offset = result.FindFirst(' ') + 1; result.Remove(0,uid_offset); fUniqueIDs.AddItem(result.String()); } if (SendCommand("LIST" CRLF) != B_OK) return B_ERROR; int32 b; while (ReceiveLine(result) > 0) { if (result.ByteAt(0) == '.') break; b = result.FindLast(" "); if (b >= 0) b = atol(&(result.String()[b])); else b = 0; fSizes.AddItem((void *)(b)); } return ret; }
status_t POP3Protocol::UniqueIDs() { status_t ret = B_OK; runner->ReportProgress(0, 0, MDR_DIALECT_CHOICE("Getting UniqueIDs...", "固有のIDを取得中...")); ret = SendCommand("UIDL" CRLF); if (ret != B_OK) return ret; BString result; int32 uid_offset; while (ReceiveLine(result) > 0) { if (result.ByteAt(0) == '.') break; uid_offset = result.FindFirst(' ') + 1; result.Remove(0,uid_offset); unique_ids->AddItem(result.String()); } if (SendCommand("LIST" CRLF) != B_OK) return B_ERROR; int32 b; while (ReceiveLine(result) > 0) { if (result.ByteAt(0) == '.') break; b = result.FindLast(" "); if (b >= 0) b = atol(&(result.String()[b])); else b = 0; fSizes.AddItem((void *)(b)); } return ret; }
void TeamWindow::_HandleResolveMissingSourceFile(entry_ref& locatedPath) { if (fActiveFunction != NULL) { LocatableFile* sourceFile = fActiveFunction->GetFunctionDebugInfo() ->SourceFile(); if (sourceFile != NULL) { BString sourcePath; sourceFile->GetPath(sourcePath); BString sourceFileName(sourcePath); int32 index = sourcePath.FindLast('/'); if (index >= 0) sourceFileName.Remove(0, index + 1); BPath targetFilePath(&locatedPath); if (targetFilePath.InitCheck() != B_OK) return; if (strcmp(sourceFileName.String(), targetFilePath.Leaf()) != 0) { BString message; message.SetToFormat("The names of source file '%s' and located" " file '%s' differ. Use file anyway?", sourceFileName.String(), targetFilePath.Leaf()); BAlert* alert = new(std::nothrow) BAlert( "Source path mismatch", message.String(), "Cancel", "Use"); if (alert == NULL) return; int32 choice = alert->Go(); if (choice <= 0) return; } fListener->SourceEntryLocateRequested(sourcePath, targetFilePath.Path()); fListener->FunctionSourceCodeRequested(fActiveFunction); } } }
status_t BLocaleRoster::_PrepareCatalogEntry(const entry_ref& ref, BString& signature, BString& context, BString& string, bool traverse) { BEntry entry(&ref, traverse); if (!entry.Exists()) return B_ENTRY_NOT_FOUND; BNode node(&entry); status_t status = node.InitCheck(); if (status != B_OK) return status; status = node.ReadAttrString("SYS:NAME", &signature); if (status != B_OK) return status; int32 first = signature.FindFirst(':'); int32 last = signature.FindLast(':'); if (first == last) return B_ENTRY_NOT_FOUND; context = signature; string = signature; signature.Truncate(first); context.Truncate(last); context.Remove(0, first + 1); string.Remove(0, last + 1); if (signature.Length() == 0 || context.Length() == 0 || string.Length() == 0) return B_ENTRY_NOT_FOUND; return B_OK; }
BUrl& BUrl::SetPath(const BString& path) { // Implements RFC3986 section 5.2.4, "Remove dot segments" // 1. BString output; BString input(path); // 2. while(!input.IsEmpty()) { // 2.A. if (input.StartsWith("./")) { input.Remove(0, 2); continue; } if (input.StartsWith("../")) { input.Remove(0, 3); continue; } // 2.B. if (input.StartsWith("/./")) { input.Remove(0, 2); continue; } if (input == "/.") { input.Remove(1, 1); continue; } // 2.C. if (input.StartsWith("/../")) { input.Remove(0, 3); output.Truncate(output.FindLast('/')); continue; } if (input == "/..") { input.Remove(1, 2); output.Truncate(output.FindLast('/')); continue; } // 2.D. if (input == "." || input == "..") { break; } if (input == "/.") { input.Remove(1, 1); continue; } // 2.E. int slashpos = input.FindFirst('/', 1); if (slashpos > 0) { output.Append(input, slashpos); input.Remove(0, slashpos); } else { output.Append(input); break; } } _SetPathUnsafe(output); return *this; }
/* * Given a single line of the output of db_delta.py * Figures out what to do and does it. * (adds and removes files and directories) */ int App::parse_command(BString command) { command.RemoveAll("\n"); //remove trailing whitespace if(command.Compare("RESET") == 0) { printf("Burn Everything. 8D\n"); status_t err = stop_watching(be_app_messenger); if(err != B_OK) printf("stop_watching error: %s\n",strerror(err)); BDirectory dir = BDirectory(local_path_string); rm_rf(&dir); BString str = BString("/"); //create_local_path wants a remote path create_local_directory(&str); this->recursive_watch(&dir); } else if(command.Compare("FILE ",5) == 0) { BString path, dirpath, partial_path; BPath *bpath; int32 last_space = command.FindLast(" "); command.CopyInto(path,5,last_space - 5); path.CopyInto(dirpath,0,path.FindLast("/")); create_local_directory(&dirpath); //TODO fix watching new dirs bpath = new BPath(db_to_local_filepath(path.String()).String()); BEntry new_file = BEntry(bpath->Path()); if(new_file.InitCheck() && new_file.Exists()) { this->new_paths.AddItem((void*)bpath); } else { this->edited_paths.AddItem((void*)bpath); } printf("create a file at |%s|\n",path.String()); char *argv[3]; argv[0] = "db_get.py"; char not_const1[path.CountChars() + 1]; strcpy(not_const1,path.String()); argv[1] = not_const1; BString tmp = db_to_local_filepath(path.String()); char not_const2[tmp.CountChars() + 1]; //plus one for null strcpy(not_const2,tmp.String()); argv[2] = not_const2; //create/update file //potential problem: takes awhile to do this step // having watching for dir turned off is risky. BString * b = run_python_script(argv,3); delete b; //start watching the new/updated file node_ref nref; new_file = BEntry(db_to_local_filepath(path.String()).String()); new_file.GetNodeRef(&nref); status_t err = watch_node(&nref,B_WATCH_STAT,be_app_messenger); BString parent_rev; command.CopyInto(parent_rev,last_space + 1, command.CountChars() - (last_space+1)); BNode node = BNode(db_to_local_filepath(path.String()).String()); set_parent_rev(&node,&parent_rev); } else if(command.Compare("FOLDER ",7) == 0) { BString path; command.CopyInto(path,7,command.FindLast(" ") - 7); //ignore the creation message BPath bpath = BPath(db_to_local_filepath(path.String()).String()); BPath *actually_exists = find_existing_subpath(&bpath); this->new_paths.AddItem((void*)actually_exists); //create all nescessary dirs in path printf("create a folder at |%s|\n", path.String()); create_local_directory(&path); //start watching the new dir BDirectory existing_dir = BDirectory(actually_exists->Path()); recursive_watch(&existing_dir); } else if(command.Compare("REMOVE ",7) == 0) { //TODO: deal with Dropbox file paths being case-insensitive //which here means all lower case BString path; command.CopyInto(path,7,command.Length() - 7); const char * pathstr = db_to_local_filepath(path.String()).String(); BPath *bpath = new BPath(pathstr); //TODO: check if it exists... this->removed_paths.AddItem((void*)bpath); printf("Remove whatever is at |%s|\n", pathstr); BEntry entry = BEntry(pathstr); status_t err = entry.Remove(); if(err != B_OK) printf("Removal error: %s\n", strerror(err)); } else { printf("Did not recognize command.\n"); return B_ERROR; } return B_OK; }
void FoldLineAtWhiteSpaceAndAddCRLF (BString &string) { int inputLength = string.Length(); int lineStartIndex; const int maxLineLength = 78; // Doesn't include CRLF. BString output; int splitIndex; int tempIndex; lineStartIndex = 0; while (true) { // If we don't need to wrap the text, just output the remainder, if any. if (lineStartIndex + maxLineLength >= inputLength) { if (lineStartIndex < inputLength) { output.Insert (string, lineStartIndex /* source offset */, inputLength - lineStartIndex /* count */, output.Length() /* insert at */); output.Append (CRLF); } break; } // Look ahead for a convenient spot to split it, between a comma and // space, which you often see between e-mail addresses like this: // "Joe Who" [email protected], "Someone Else" [email protected] tempIndex = lineStartIndex + maxLineLength; if (tempIndex > inputLength) tempIndex = inputLength; splitIndex = string.FindLast (", ", tempIndex); if (splitIndex >= lineStartIndex) splitIndex++; // Point to the space character. // If none of those exist, try splitting at any white space. if (splitIndex <= lineStartIndex) splitIndex = string.FindLast (" ", tempIndex); if (splitIndex <= lineStartIndex) splitIndex = string.FindLast ("\t", tempIndex); // If none of those exist, allow for a longer word - split at the next // available white space. if (splitIndex <= lineStartIndex) splitIndex = string.FindFirst (" ", lineStartIndex + 1); if (splitIndex <= lineStartIndex) splitIndex = string.FindFirst ("\t", lineStartIndex + 1); // Give up, the whole rest of the line can't be split, just dump it // out. if (splitIndex <= lineStartIndex) { if (lineStartIndex < inputLength) { output.Insert (string, lineStartIndex /* source offset */, inputLength - lineStartIndex /* count */, output.Length() /* insert at */); output.Append (CRLF); } break; } // Do the split. The current line up to but not including the space // gets output, followed by a CRLF. The space remains to become the // start of the next line (and that tells the message reader that it is // a continuation line). output.Insert (string, lineStartIndex /* source offset */, splitIndex - lineStartIndex /* count */, output.Length() /* insert at */); output.Append (CRLF); lineStartIndex = splitIndex; } string.SetTo (output); }
_EXPORT void extract_address_name(BString &header) { BString name; const char *start = header.String(); const char *stop = start + strlen (start); // Find a string S in the header (email foo) that matches: // Old style name in brackets: [email protected] (S) // New style quotes: "S" <*****@*****.**> // New style no quotes if nothing else found: S <*****@*****.**> // If nothing else found then use the whole thing: S for (int i = 0; i <= 3; i++) { // Set p1 to the first letter in the name and p2 to just past the last // letter in the name. p2 stays NULL if a name wasn't found in this // pass. const char *p1 = NULL, *p2 = NULL; switch (i) { case 0: // [email protected] (S) if ((p1 = strchr(start,'(')) != NULL) { p1++; // Advance to first letter in the name. size_t nest = 1; // Handle nested brackets. for (p2 = p1; p2 < stop; ++p2) { if (*p2 == ')') --nest; else if (*p2 == '(') ++nest; if (nest <= 0) break; } if (nest != 0) p2 = NULL; // False alarm, no terminating bracket. } break; case 1: // "S" <*****@*****.**> if ((p1 = strchr(start, '\"')) != NULL) p2 = strchr(++p1, '\"'); break; case 2: // S <*****@*****.**> p1 = start; if (name.Length() == 0) p2 = strchr(start, '<'); break; case 3: // S p1 = start; if (name.Length() == 0) p2 = stop; break; } // Remove leading and trailing space-like characters and save the // result if it is longer than any other likely names found. if (p2 != NULL) { while (p1 < p2 && (isspace (*p1))) ++p1; while (p1 < p2 && (isspace (p2[-1]))) --p2; int newLength = p2 - p1; if (name.Length() < newLength) name.SetTo(p1, newLength); } } int32 lessIndex = name.FindFirst('<'); int32 greaterIndex = name.FindLast('>'); if (lessIndex == 0) { // Have an address of the form <address> and nothing else, so remove // the greater and less than signs, if any. if (greaterIndex > 0) name.Remove(greaterIndex, 1); name.Remove(lessIndex, 1); } else if (lessIndex > 0 && lessIndex < greaterIndex) { // Yahoo stupidly inserts the e-mail address into the name string, so // this bit of code fixes: "Joe <*****@*****.**>" <*****@*****.**> name.Remove(lessIndex, greaterIndex - lessIndex + 1); } trim_white_space(name); header = name; }
bool TermView::HyperLinkState::_GetHyperLinkAt(BPoint where, bool pathPrefixOnly, HyperLink& _link, TermPos& _start, TermPos& _end) { TerminalBuffer* textBuffer = fView->fTextBuffer; BAutolock textBufferLocker(textBuffer); TermPos pos = fView->_ConvertToTerminal(where); // try to get a URL first BString text; if (!textBuffer->FindWord(pos, &fURLCharClassifier, false, _start, _end)) return false; text.Truncate(0); textBuffer->GetStringFromRegion(text, _start, _end); text.Trim(); // We're only happy, if it has a protocol part which we know. int32 colonIndex = text.FindFirst(':'); if (colonIndex >= 0) { BString protocol(text, colonIndex); if (strstr(kKnownURLProtocols, protocol) != NULL) { _link = HyperLink(text, HyperLink::TYPE_URL); return true; } } // no obvious URL -- try file name if (!textBuffer->FindWord(pos, fView->fCharClassifier, false, _start, _end)) return false; // In path-prefix-only mode we determine the end position anew by omitting // the '/' in the allowed word chars. if (pathPrefixOnly) { TermPos componentStart; TermPos componentEnd; if (textBuffer->FindWord(pos, &fPathComponentCharClassifier, false, componentStart, componentEnd)) { _end = componentEnd; } else { // That means pos points to a '/'. We simply use the previous // position. _end = pos; if (_start == _end) { // Well, must be just "/". Advance to the next position. if (!textBuffer->NextLinePos(_end, false)) return false; } } } text.Truncate(0); textBuffer->GetStringFromRegion(text, _start, _end); text.Trim(); if (text.IsEmpty()) return false; // Collect a list of colons in the string and their respective positions in // the text buffer. We do this up-front so we can unlock the text buffer // while we're doing all the entry existence tests. typedef Array<CharPosition> ColonList; ColonList colonPositions; TermPos searchPos = _start; for (int32 index = 0; (index = text.FindFirst(':', index)) >= 0;) { TermPos foundStart; TermPos foundEnd; if (!textBuffer->Find(":", searchPos, true, true, false, foundStart, foundEnd)) { return false; } CharPosition colonPosition; colonPosition.index = index; colonPosition.position = foundStart; if (!colonPositions.Add(colonPosition)) return false; index++; searchPos = foundEnd; } textBufferLocker.Unlock(); // Since we also want to consider ':' a potential path delimiter, in two // nested loops we chop off components from the beginning respective the // end. BString originalText = text; TermPos originalStart = _start; TermPos originalEnd = _end; int32 colonCount = colonPositions.Count(); for (int32 startColonIndex = -1; startColonIndex < colonCount; startColonIndex++) { int32 startIndex; if (startColonIndex < 0) { startIndex = 0; _start = originalStart; } else { startIndex = colonPositions[startColonIndex].index + 1; _start = colonPositions[startColonIndex].position; if (_start >= pos) break; _start.x++; // Note: This is potentially a non-normalized position (i.e. // the end of a soft-wrapped line). While not that nice, it // works anyway. } for (int32 endColonIndex = colonCount; endColonIndex > startColonIndex; endColonIndex--) { int32 endIndex; if (endColonIndex == colonCount) { endIndex = originalText.Length(); _end = originalEnd; } else { endIndex = colonPositions[endColonIndex].index; _end = colonPositions[endColonIndex].position; if (_end <= pos) break; } originalText.CopyInto(text, startIndex, endIndex - startIndex); if (text.IsEmpty()) continue; // check, whether the file exists BString actualPath; if (_EntryExists(text, actualPath)) { _link = HyperLink(text, actualPath, HyperLink::TYPE_PATH); return true; } // As such this isn't an existing path. We also want to recognize: // * "<path>:<line>" // * "<path>:<line>:<column>" BString path = text; for (int32 i = 0; i < 2; i++) { int32 colonIndex = path.FindLast(':'); if (colonIndex <= 0 || colonIndex == path.Length() - 1) break; char* numberEnd; strtol(path.String() + colonIndex + 1, &numberEnd, 0); if (*numberEnd != '\0') break; path.Truncate(colonIndex); if (_EntryExists(path, actualPath)) { BString address = path == actualPath ? text : BString(actualPath) << (text.String() + colonIndex); _link = HyperLink(text, address, i == 0 ? HyperLink::TYPE_PATH_WITH_LINE : HyperLink::TYPE_PATH_WITH_LINE_AND_COLUMN); return true; } } } } return false; }
void DownloadProgressView::_UpdateStatusText() { fInfoView->SetText(""); BString buffer; if (sShowSpeed && fBytesPerSecond != 0.0) { // Draw speed info char sizeBuffer[128]; buffer = "("; // Get strings for current and expected size and remove the unit // from the current size string if it's the same as the expected // size unit. BString currentSize = string_for_size((double)fCurrentSize, sizeBuffer, sizeof(sizeBuffer)); BString expectedSize = string_for_size((double)fExpectedSize, sizeBuffer, sizeof(sizeBuffer)); int currentSizeUnitPos = currentSize.FindLast(' '); int expectedSizeUnitPos = expectedSize.FindLast(' '); if (currentSizeUnitPos >= 0 && expectedSizeUnitPos >= 0 && strcmp(currentSize.String() + currentSizeUnitPos, expectedSize.String() + expectedSizeUnitPos) == 0) { currentSize.Truncate(currentSizeUnitPos); } buffer << currentSize; buffer << " of "; buffer << expectedSize; buffer << ", "; buffer << string_for_size(fBytesPerSecond, sizeBuffer, sizeof(sizeBuffer)); buffer << "/s)"; float stringWidth = fInfoView->StringWidth(buffer.String()); if (stringWidth < fInfoView->Bounds().Width()) fInfoView->SetText(buffer.String()); else { // complete string too wide, try with shorter version buffer << string_for_size(fBytesPerSecond, sizeBuffer, sizeof(sizeBuffer)); buffer << "/s"; stringWidth = fInfoView->StringWidth(buffer.String()); if (stringWidth < fInfoView->Bounds().Width()) fInfoView->SetText(buffer.String()); } } else if (!sShowSpeed && fCurrentSize < fExpectedSize) { double totalBytesPerSecond = (double)(fCurrentSize - fEstimatedFinishReferenceSize) * 1000000LL / (system_time() - fEstimatedFinishReferenceTime); double secondsRemaining = (fExpectedSize - fCurrentSize) / totalBytesPerSecond; time_t now = (time_t)real_time_clock(); time_t finishTime = (time_t)(now + secondsRemaining); tm _time; tm* time = localtime_r(&finishTime, &_time); int32 year = time->tm_year + 1900; char timeText[32]; time_t secondsPerDay = 24 * 60 * 60; // TODO: Localization of time string... if (now < finishTime - secondsPerDay) { // process is going to take more than a day! sprintf(timeText, "%0*d:%0*d %0*d/%0*d/%ld", 2, time->tm_hour, 2, time->tm_min, 2, time->tm_mon + 1, 2, time->tm_mday, year); } else { sprintf(timeText, "%0*d:%0*d", 2, time->tm_hour, 2, time->tm_min); } BString buffer1("Finish: "); buffer1 << timeText; finishTime -= now; time = gmtime(&finishTime); BString buffer2; if (finishTime > secondsPerDay) { int64 days = finishTime / secondsPerDay; if (days == 1) buffer2 << "Over 1 day"; else buffer2 << "Over " << days << " days"; } else if (finishTime > 60 * 60) { int64 hours = finishTime / (60 * 60); if (hours == 1) buffer2 << "Over 1 hour"; else buffer2 << "Over " << hours << " hours"; } else if (finishTime > 60) { int64 minutes = finishTime / 60; if (minutes == 1) buffer2 << "Over 1 minute"; else buffer2 << minutes << " minutes"; } else { if (finishTime == 1) buffer2 << "1 second"; else buffer2 << finishTime << " seconds"; } buffer2 << " left"; buffer = "("; buffer << buffer1 << " - " << buffer2 << ")"; float stringWidth = fInfoView->StringWidth(buffer.String()); if (stringWidth < fInfoView->Bounds().Width()) fInfoView->SetText(buffer.String()); else { // complete string too wide, try with shorter version buffer = "("; buffer << buffer1 << ")"; stringWidth = fInfoView->StringWidth(buffer.String()); if (stringWidth < fInfoView->Bounds().Width()) fInfoView->SetText(buffer.String()); } } }
void TimeZoneView::_BuildZoneMenu() { BTimeZone defaultTimeZone; BLocaleRoster::Default()->GetDefaultTimeZone(&defaultTimeZone); BLanguage language; BLocale::Default()->GetLanguage(&language); /* * Group timezones by regions, but filter out unwanted (duplicate) regions * and add an additional region with generic GMT-offset timezones at the end */ typedef std::map<BString, TimeZoneListItem*, TimeZoneItemLess> ZoneItemMap; ZoneItemMap zoneItemMap; const char* kOtherRegion = B_TRANSLATE_MARK("<Other>"); const char* kSupportedRegions[] = { B_TRANSLATE_MARK("Africa"), B_TRANSLATE_MARK("America"), B_TRANSLATE_MARK("Antarctica"), B_TRANSLATE_MARK("Arctic"), B_TRANSLATE_MARK("Asia"), B_TRANSLATE_MARK("Atlantic"), B_TRANSLATE_MARK("Australia"), B_TRANSLATE_MARK("Europe"), B_TRANSLATE_MARK("Indian"), B_TRANSLATE_MARK("Pacific"), kOtherRegion, NULL }; // Since the zone-map contains translated country-names (we get those from // ICU), we need to use translated region names in the zone-map, too: typedef std::map<BString, BString> TranslatedRegionMap; TranslatedRegionMap regionMap; for (const char** region = kSupportedRegions; *region != NULL; ++region) { BString translatedRegion = B_TRANSLATE_NOCOLLECT(*region); regionMap[*region] = translatedRegion; TimeZoneListItem* regionItem = new TimeZoneListItem(translatedRegion, NULL, NULL); regionItem->SetOutlineLevel(0); zoneItemMap[translatedRegion] = regionItem; } // Get all time zones BMessage zoneList; BLocaleRoster::Default()->GetAvailableTimeZonesWithRegionInfo(&zoneList); typedef std::map<BString, std::vector<const char*> > ZonesByCountyMap; ZonesByCountyMap zonesByCountryMap; const char *zoneID; BString countryCode; for (int tz = 0; zoneList.FindString("timeZone", tz, &zoneID) == B_OK && zoneList.FindString("region", tz, &countryCode) == B_OK; tz++) { // From the global ("001") timezones, we only accept the generic GMT // timezones, as all the other world-zones are duplicates of others. if (countryCode == "001" && strncmp(zoneID, "Etc/GMT", 7) != 0) continue; zonesByCountryMap[countryCode].push_back(zoneID); } ZonesByCountyMap::const_iterator countryIter = zonesByCountryMap.begin(); for (; countryIter != zonesByCountryMap.end(); ++countryIter) { BCountry country(countryIter->first.String()); BString countryName; country.GetName(countryName); size_t zoneCountInCountry = countryIter->second.size(); for (size_t tz = 0; tz < zoneCountInCountry; tz++) { BString zoneID(countryIter->second[tz]); int32 slashPos = zoneID.FindFirst('/'); BString region(zoneID, slashPos); if (region == "Etc") region = kOtherRegion; // just accept timezones from our supported regions, others are // aliases and would just make the list even longer TranslatedRegionMap::iterator regionIter = regionMap.find(region); if (regionIter == regionMap.end()) continue; BString fullCountryID = regionIter->second; bool countryIsRegion = countryName == regionIter->second || region == kOtherRegion; if (!countryIsRegion) fullCountryID << "/" << countryName; BTimeZone* timeZone = new BTimeZone(zoneID, &language); BString tzName; BString fullZoneID = fullCountryID; if (zoneCountInCountry > 1) { // we can't use the country name as timezone name, since there // are more than one timezones in this country - fetch the // localized name of the timezone and use that tzName = timeZone->Name(); int32 openParenthesisPos = tzName.FindFirst('('); if (openParenthesisPos >= 0) { tzName.Remove(0, openParenthesisPos + 1); int32 closeParenthesisPos = tzName.FindLast(')'); if (closeParenthesisPos >= 0) tzName.Truncate(closeParenthesisPos); } fullZoneID << "/" << tzName; } else { tzName = countryName; fullZoneID << "/" << zoneID; } // skip duplicates ZoneItemMap::iterator zoneIter = zoneItemMap.find(fullZoneID); if (zoneIter != zoneItemMap.end()) { delete timeZone; continue; } TimeZoneListItem* countryItem = NULL; TimeZoneListItem* zoneItem = NULL; if (zoneCountInCountry > 1) { ZoneItemMap::iterator countryIter = zoneItemMap.find(fullCountryID); if (countryIter == zoneItemMap.end()) { countryItem = new TimeZoneListItem(countryName, NULL, NULL); countryItem->SetOutlineLevel(1); zoneItemMap[fullCountryID] = countryItem; } else countryItem = countryIter->second; zoneItem = new TimeZoneListItem(tzName, NULL, timeZone); zoneItem->SetOutlineLevel(countryIsRegion ? 1 : 2); } else { zoneItem = new TimeZoneListItem(tzName, NULL, timeZone); zoneItem->SetOutlineLevel(1); } zoneItemMap[fullZoneID] = zoneItem; if (timeZone->ID() == defaultTimeZone.ID()) { fCurrentZoneItem = zoneItem; if (countryItem != NULL) countryItem->SetExpanded(true); ZoneItemMap::iterator regionItemIter = zoneItemMap.find(regionIter->second); if (regionItemIter != zoneItemMap.end()) regionItemIter->second->SetExpanded(true); } } } fOldZoneItem = fCurrentZoneItem; ZoneItemMap::iterator zoneIter; bool lastWasCountryItem = false; TimeZoneListItem* currentCountryItem = NULL; for (zoneIter = zoneItemMap.begin(); zoneIter != zoneItemMap.end(); ++zoneIter) { if (zoneIter->second->OutlineLevel() == 2 && lastWasCountryItem) { /* Some countries (e.g. Spain and Chile) have their timezones * spread across different regions. As a result, there might still * be country items with only one timezone below them. We manually * filter those country items here. */ ZoneItemMap::iterator next = zoneIter; ++next; if (next != zoneItemMap.end() && next->second->OutlineLevel() != 2) { fZoneList->RemoveItem(currentCountryItem); zoneIter->second->SetText(currentCountryItem->Text()); zoneIter->second->SetOutlineLevel(1); delete currentCountryItem; } } fZoneList->AddItem(zoneIter->second); if (zoneIter->second->OutlineLevel() == 1) { lastWasCountryItem = true; currentCountryItem = zoneIter->second; } else lastWasCountryItem = false; } }
// Parser Test void MimeSnifferTest::ParserTest() { // test a couple of valid and invalid rules struct test_case { const char *rule; const char *error; // NULL, if valid } testCases[] = { // valid rules { "1.0 (\"ABCD\")", NULL }, { "1.0 ('ABCD')", NULL }, { " 1.0 ('ABCD') ", NULL }, { "0.8 [0:3] ('ABCDEFG' | 'abcdefghij')", NULL }, { "0.5([10]'ABCD'|[17]'abcd'|[13]'EFGH')", NULL } , { "0.5 \n [0:3] \t ('ABCD' \n | 'abcd' | 'EFGH')", NULL }, { "0.8 [ 0 : 3 ] ('ABCDEFG' | 'abcdefghij')", NULL }, { "0.8 [0:3] ('ABCDEFG' & 'abcdefg')", NULL }, // These two rules are accepted by the R5 sniffer checker, but not // by the parser. Thus, we're not accepting them with either. // { "1.0 ('ABCD') | ('EFGH')", NULL }, // { "1.0 [0:3] ('ABCD') | [2:4] ('EFGH')", NULL }, { "0.8 [0:3] (\\077Mkl0x34 & 'abcdefgh')", NULL }, { "0.8 [0:3] (\\077034 & 'abcd')", NULL }, { "0.8 [0:3] (\\077\\034 & 'ab')", NULL }, { "0.8 [0:3] (\\77\\034 & 'ab')", NULL }, { "0.8 [0:3] (\\7 & 'a')", NULL }, { "0.8 [0:3] (\"\\17\" & 'a')", NULL }, { "0.8 [0:3] ('\\17' & 'a')", NULL }, { "0.8 [0:3] (\\g & 'a')", NULL }, { "0.8 [0:3] (\\g&\\b)", NULL }, { "0.8 [0:3] (\\g\\&b & 'abc')", NULL }, { "0.8 [0:3] (0x3457 & 'ab')", NULL }, { "0.8 [0:3] (0xA4b7 & 'ab')", NULL }, { "0.8 [0:3] ('ab\"' & 'abc')", NULL }, { "0.8 [0:3] (\"ab\\\"\" & 'abc')", NULL }, { "0.8 [0:3] (\"ab\\A\" & 'abc')", NULL }, { "0.8 [0:3] (\"ab'\" & 'abc')", NULL }, { "0.8 [0:3] (\"ab\\\\\" & 'abc')", NULL }, { "0.8 [-5:-3] (\"abc\" & 'abc')", NULL }, // Also accepted by the R5 sniffer but not the R5 parser. We reject. // { "0.8 [5:3] (\"abc\" & 'abc')", NULL }, { "1.0 ('ABCD')", NULL }, { ".2 ('ABCD')", NULL }, { "0. ('ABCD')", NULL }, { "1 ('ABCD')", NULL }, { "+1 ('ABCD')", NULL }, // We accept extended notation floating point numbers now, but // not invalid priorities. // { "1E25 ('ABCD')", NULL }, // { "1e25 ('ABCD')", NULL }, // R5 chokes on this rule :-( #if !TEST_R5 { "1e-3 ('ABCD')", NULL }, #endif { "+.003e2 ('ABCD')", NULL }, // This one too. See how much better our parser is? :-) #if !TEST_R5 { "-123e-9999999999 ('ABCD')", NULL }, // Hooray for the stunning accuracy of floating point ;-) #endif // invalid rules { "0.0 ('')", "Sniffer pattern error: illegal empty pattern" }, { "('ABCD')", "Sniffer pattern error: match level expected" }, { "[0:3] ('ABCD')", "Sniffer pattern error: match level expected" }, { "0.8 [0:3] ( | 'abcdefghij')", "Sniffer pattern error: missing pattern" }, { "0.8 [0:3] ('ABCDEFG' | )", "Sniffer pattern error: missing pattern" }, { "[0:3] ('ABCD')", "Sniffer pattern error: match level expected" }, { "1.0 (ABCD')", #if TEST_R5 "Sniffer pattern error: misplaced single quote" #else "Sniffer pattern error: invalid character 'A'" #endif }, { "1.0 ('ABCD)", #if TEST_R5 "Sniffer pattern error: unterminated rule" #else "Sniffer pattern error: unterminated single-quoted string" #endif }, { "1.0 (ABCD)", #if TEST_R5 "Sniffer pattern error: missing pattern" #else "Sniffer pattern error: invalid character 'A'" #endif }, { "1.0 (ABCD 'ABCD')", #if TEST_R5 "Sniffer pattern error: missing pattern" #else "Sniffer pattern error: invalid character 'A'" #endif }, { "1.0 'ABCD')", #if TEST_R5 "Sniffer pattern error: missing pattern" #else "Sniffer pattern error: missing pattern" #endif }, { "1.0 ('ABCD'", "Sniffer pattern error: unterminated rule" }, { "1.0 'ABCD'", #if TEST_R5 "Sniffer pattern error: missing sniff pattern" #else "Sniffer pattern error: missing pattern" #endif }, { "0.5 [0:3] ('ABCD' | 'abcd' | [13] 'EFGH')", "Sniffer pattern error: missing pattern" }, { "0.5('ABCD'|'abcd'|[13]'EFGH')", "Sniffer pattern error: missing pattern" }, { "0.5[0:3]([10]'ABCD'|[17]'abcd'|[13]'EFGH')", "Sniffer pattern error: missing pattern" }, { "0.8 [0x10:3] ('ABCDEFG' | 'abcdefghij')", "Sniffer pattern error: pattern offset expected" }, { "0.8 [0:A] ('ABCDEFG' | 'abcdefghij')", #if TEST_R5 "Sniffer pattern error: pattern range end expected" #else "Sniffer pattern error: invalid character 'A'" #endif }, { "0.8 [0:3] ('ABCDEFG' & 'abcdefghij')", "Sniffer pattern error: pattern and mask lengths do not match" }, { "0.8 [0:3] ('ABCDEFG' & 'abcdefg' & 'xyzwmno')", #if TEST_R5 "Sniffer pattern error: unterminated rule" #else "Sniffer pattern error: expecting '|', ')', or possibly '&'" #endif }, { "0.8 [0:3] (\\g&b & 'a')", #if TEST_R5 "Sniffer pattern error: missing mask" #else "Sniffer pattern error: invalid character 'b'" #endif }, { "0.8 [0:3] (\\19 & 'a')", "Sniffer pattern error: pattern and mask lengths do not match" }, { "0.8 [0:3] (0x345 & 'ab')", "Sniffer pattern error: bad hex literal" }, { "0.8 [0:3] (0x3457M & 'abc')", #if TEST_R5 "Sniffer pattern error: expecting '|' or '&'" #else "Sniffer pattern error: invalid character 'M'" #endif }, { "0.8 [0:3] (0x3457\\7 & 'abc')", #if TEST_R5 "Sniffer pattern error: expecting '|' or '&'" #else "Sniffer pattern error: expecting '|', ')', or possibly '&'" #endif }, // Miscellaneous tests designed to hit every remaining // relevant "throw new Err()" statement in the scanner. // R5 versions will come later... #if !TEST_R5 { "\x03 ", "Sniffer pattern error: invalid character '\x03'" }, { "\"blah", "Sniffer pattern error: unterminated double-quoted string" }, { "0xThisIsNotAHexCode", "Sniffer pattern error: incomplete hex code" }, { "0xAndNeitherIsThis:-)", "Sniffer pattern error: bad hex literal" }, { ".NotAFloat", "Sniffer pattern error: incomplete floating point number" }, { "-NotANumber", "Sniffer pattern error: incomplete signed number" }, { "+NotANumber", "Sniffer pattern error: incomplete signed number" }, { "0.0e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "1.0e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { ".0e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "0e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "1e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1.e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1.e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1.0e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1.0e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "0.0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "1.0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { ".0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "1e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1.e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1.e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1.0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1.0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "0.0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "1.0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { ".0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "1e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1.e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1.e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1.0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1.0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "\\11\\", "Sniffer pattern error: incomplete escape sequence" }, { "\"Escape!! \\", "Sniffer pattern error: incomplete escape sequence" }, { "'Escape!! \\", "Sniffer pattern error: incomplete escape sequence" }, { "\\x", "Sniffer pattern error: incomplete escaped hex code" }, { "\\xNotAHexCode", "Sniffer pattern error: incomplete escaped hex code" }, { "\\xAlsoNotAHexCode", "Sniffer pattern error: incomplete escaped hex code" }, { "\\x0", "Sniffer pattern error: incomplete escaped hex code" }, { "1.0 (\\377)", NULL }, { "\\400", "Sniffer pattern error: invalid octal literal (octals must be between octal 0 and octal 377 inclusive)" }, { "\\777", "Sniffer pattern error: invalid octal literal (octals must be between octal 0 and octal 377 inclusive)" }, { "1.0 (\\800)", NULL }, { NULL, "Sniffer pattern error: NULL pattern" }, { "-2", "Sniffer pattern error: invalid priority" }, { "+2", "Sniffer pattern error: invalid priority" }, { "1.0", "Sniffer pattern error: missing expression" }, #endif // !TEST_R5 // { "1E-25 ('ABCD')", "Sniffer pattern error: missing pattern" }, // I don't currently understand what's wrong with the above rule... R5 // rejects it though, for some reason. }; const int testCaseCount = sizeof(testCases) / sizeof(test_case); BMimeType type; for (int32 i = 0; i < testCaseCount; i++) { //cout << endl << "----------------------------------------------------------------------" << endl; NextSubTest(); test_case &testCase = testCases[i]; //cout << endl << testCase.rule << endl; BString parseError; status_t error = BMimeType::CheckSnifferRule(testCase.rule, &parseError); if (testCase.error == NULL) { if (error != B_OK) { cout << endl << "This sucker's gonna fail..." << endl << "RULE: '" << testCase.rule << "'" << endl << "ERROR: " << endl << parseError.String() << endl; } CHK(error == B_OK); } else { // if (parseError.FindLast(testCase.error) >= 0) { // cout << endl << parseError.String(); // << endl; // cout << endl << testCase.error << endl; // } // cout << endl << parseError.String(); // << endl; /* if (parseError.FindLast(testCase.error) >= 0) { cout << " -- OKAY" << endl; } else { cout << " -- NOGO" << endl; cout << testCase.error << endl; } */ if (testCase.rule && error != B_BAD_MIME_SNIFFER_RULE) { printf("rule: `%s'", testCase.rule); RES(error); } CHK(error == (testCase.rule ? B_BAD_MIME_SNIFFER_RULE : B_BAD_VALUE)); CHK(parseError.FindLast(testCase.error) >= 0); } } }
void App::OpenFile(entry_ref ref, int32 line, int32 column) { if (!ref.name) return; BNode node(&ref); BString type; if (node.ReadAttrString("BEOS:TYPE",&type) != B_OK) { update_mime_info(BPath(&ref).Path(),0,0,1); node.ReadAttrString("BEOS:TYPE",&type); } if (type.CountChars() > 0) { if (type == PROJECT_MIME_TYPE || type.FindFirst("text/") != 0) { STRACE(2,("Launching text or project file in roster...\n")); be_roster->Launch(&ref); return; } } else { BString extension = BPath(&ref).Path(); int32 pos = extension.FindLast("."); if (pos >= 0) { extension = extension.String() + pos; if (extension.ICompare(".cpp") != 0 && extension.ICompare(".h") != 0 && extension.ICompare(".hpp") != 0 && extension.ICompare(".c") != 0) { return; } } } BMessage* msg = new BMessage(B_REFS_RECEIVED); msg->AddRef("refs",&ref); if (line >= 0) msg->AddInt32("be:line",line); if (column >= 0) msg->AddInt32("be:column",column); STRACE(2,("Paladin Launching File Ref: %s:%i:%i\n",ref.name,line,column)); /* ANTI-PATTERN - this code left here for future developers' reference Using the below method launches the app, and then be_roster sends ANOTHER B_REFS_REVEIVED of its own, causing the file to be opened twice, or once at the wrong location (i.e. without a line number). be_roster->Launch(&ref,msg); */ /* entry_ref appRef; be_roster->FindApp(&ref,&appRef); app_info appInfo; be_roster->GetAppInfo(&appRef,&appInfo); BMessenger messenger(appInfo.signature); messenger.SendMessage(msg,(BHandler*)NULL,B_INFINITE_TIMEOUT); // The above results in nothing happening unless the app is ALREADY running */ // Final effort - use the text_search tracker messenger mechanism BMessenger target("application/x-vnd.Be-TRAK"); target.SendMessage(msg); }