/*! \brief Reads the data of the specified attribute into the pre-allocated \a result. \param name the name of the attribute \param result the BString to be set to the value of the attribute \return - \c B_OK: Everything went fine. - \c B_BAD_VALUE: \c NULL \a name or \a result - \c B_FILE_ERROR: The object is not initialized. - \c B_ENTRY_NOT_FOUND: The node has no attribute \a attr. */ status_t BNode::ReadAttrString(const char *name, BString *result) const { if (!name || !result) return B_BAD_VALUE; attr_info info; status_t error; error = GetAttrInfo(name, &info); if (error != B_OK) return error; // Lock the string's buffer so we can meddle with it char *data = result->LockBuffer(info.size+1); if (!data) return B_NO_MEMORY; // Read the attribute ssize_t bytes = ReadAttr(name, B_STRING_TYPE, 0, data, info.size); // Check for failure if (bytes < 0) { error = bytes; bytes = 0; // In this instance, we simply clear the string } else error = B_OK; // Null terminate the new string just to be sure (since it *is* // possible to read and write non-NULL-terminated strings) data[bytes] = 0; result->UnlockBuffer(); return error; }
static int DefaultCloneAttr( ATTRIBUTES *a) { MAP *in; if (appClone != NULL) { char *dummy; in = AppOpenClone(&dummy, NULL); if (in == NULL ) return 1; if (ReadAttr(a,in,FALSE)) { Mclose(in); return RetError(1,"while reading clone map '%s': %s",appClone,MstrError()); } Mclose(in); } else DefaultAttr(a); return 0; }
static int EditOption( const char *name) { ATTRIBUTES a; MAP *in = Mopen(name, M_READ_WRITE); if (in == NULL || ReadAttr(&a,in,FALSE)) { if (in != NULL) Mclose(in); return RetError(1,"while reading '%s': %s",name,MstrError()); } if (a.version != 2) return RetError(1,"'%s' is not a version 2 map, no edits possible"); a.cloneCreation = FALSE; switch(MakeCloneMenu(&a, name)) { case 0: return 0; case 1: return SetAndCloseMap(in, &a); case 2: fprintf(stderr,"No map attributes written\n"); return 0; } POSTCOND(FALSE); return 1; }
void BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, bool includeStartEntry, bool select, bool reverse, bool addShortcuts, bool navMenuEntries) { try { if (!startEntry) throw (status_t)B_ERROR; Model model(startEntry); ThrowOnInitCheckError(&model); ModelMenuItem* menu = new ModelMenuItem(&model, this, true, true); if (fMenuBar) fMenuBar->AddItem(menu); BEntry entry(*startEntry); bool showDesktop, showDisksIcon; { TrackerSettings settings; showDesktop = settings.DesktopFilePanelRoot(); showDisksIcon = settings.ShowDisksIcon(); } // might start one level above startEntry if (!includeStartEntry) { BDirectory parent; BDirectory dir(&entry); if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { // if we're at the root directory skip "mnt" and // go straight to "/" parent.SetTo("/"); } else entry.GetParent(&parent); parent.GetEntry(&entry); } BDirectory desktopDir; FSGetDeskDir(&desktopDir); BEntry desktopEntry; desktopDir.GetEntry(&desktopEntry); for (;;) { BNode node(&entry); ThrowOnInitCheckError(&node); PoseInfo info; ReadAttrResult result = ReadAttr(&node, kAttrPoseInfo, kAttrPoseInfoForeign, B_RAW_TYPE, 0, &info, sizeof(PoseInfo), &PoseInfo::EndianSwap); BDirectory parent; entry.GetParent(&parent); bool hitRoot = false; BDirectory dir(&entry); if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { // if we're at the root directory skip "mnt" and // go straight to "/" hitRoot = true; parent.SetTo("/"); } if (showDesktop) { BEntry root("/"); // warp from "/" to Desktop properly if (entry == root) { if (showDisksIcon) AddDisksIconToMenu(reverse); entry = desktopEntry; } if (entry == desktopEntry) hitRoot = true; } if (result == kReadAttrFailed || !info.fInvisible || (showDesktop && desktopEntry == entry)) { AddItemToDirMenu(&entry, originatingWindow, reverse, addShortcuts, navMenuEntries); } if (hitRoot) { if (!showDesktop && showDisksIcon && *startEntry != "/") AddDisksIconToMenu(reverse); break; } parent.GetEntry(&entry); } // select last item in menu if (!select) return; ModelMenuItem* item = dynamic_cast<ModelMenuItem*>(ItemAt(CountItems() - 1)); if (item) { item->SetMarked(true); if (menu) { entry.SetTo(item->TargetModel()->EntryRef()); ThrowOnError(menu->SetEntry(&entry)); } } } catch (status_t err) { PRINT(("BDirMenu::Populate: caught error %s\n", strerror(err))); if (!CountItems()) { BString error; error << "Error [" << strerror(err) << "] populating menu"; AddItem(new BMenuItem(error.String(), 0)); } } }
static int PrintOption( const char **names, int nrNames) { ATTRIBUTES *a = (ATTRIBUTES *)ChkMalloc(sizeof(ATTRIBUTES) * nrNames); int *colLen = (int *)ChkMalloc(sizeof(int) * nrNames); int i; if (a == NULL || colLen == NULL) return 1; for(i = 0 ; i < nrNames; i++) { MAP *m= Mopen(names[i],M_READ); if (m == NULL) { Free(a); return RetError(1,"while reading map '%s': %s",names[i],MstrError()); } ReadAttr(a+i,m,TRUE); colLen[i] = MAX(11, strlen(names[i])); Mclose(m); } if (printDataType) { for(i = 0 ; i < nrNames; i++) { int c; switch(a[i].valueScale) { case VS_LDD : c = 'L'; break; case VS_SCALAR : c = 'S'; break; case VS_BOOLEAN : c = 'B'; break; case VS_NOMINAL : c = 'N'; break; case VS_ORDINAL : c = 'O'; break; case VS_DIRECTION : c = 'D'; break; default : c = ' '; break; } printf("%c",c); } return 1; } printf("%s",HEAD); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], names[i]); printf("\n"); printf("%s",printLabels[ATTR_nrRows]); for(i = 0 ; i < nrNames; i++) printf(" %-*u", colLen[i], a[i].nrRows); printf("\n"); printf("%s",printLabels[ATTR_nrCols]); for(i = 0 ; i < nrNames; i++) printf(" %-*u", colLen[i], a[i].nrCols); printf("\n"); printf("%s",printLabels[ATTR_cellSize]); for(i = 0 ; i < nrNames; i++) printf(" %-*g", colLen[i], a[i].cellSize); printf("\n"); printf("%s",printLabels[ATTR_valueScale]); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], RstrValueScale(a[i].valueScale)); printf("\n"); printf("%s",printLabels[ATTR_cellRepr]); for(i = 0 ; i < nrNames; i++) { const char *cStr; switch(a[i].cellRepr) { case CR_UINT1 : cStr = "small"; break; case CR_INT4 : cStr = "large"; break; case CR_REAL4 : cStr = "single"; break; case CR_REAL8 : cStr = "double"; break; default : cStr = RstrCellRepr(a[i].cellRepr); } printf(" %-*s", colLen[i], cStr); } printf("\n"); printf("%s",printLabels[ATTR_projection]); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], a[i].projection ? "yb2t" : "yt2b" ); printf("\n"); printf("%s",printLabels[ATTR_angle]); for(i = 0 ; i < nrNames; i++) printf(" %-*g", colLen[i], a[i].angle); printf("\n"); printf("%s",printLabels[ATTR_xUL]); for(i = 0 ; i < nrNames; i++) printf(" %-*g", colLen[i], a[i].xUL); printf("\n"); printf("%s",printLabels[ATTR_yUL]); for(i = 0 ; i < nrNames; i++) printf(" %-*g", colLen[i], a[i].yUL); printf("\n"); printf("%s",printLabels[ATTR_minVal]); for(i = 0 ; i < nrNames; i++) if (IS_MV_REAL8(&(a[i].minVal))) printf(" %-*s", colLen[i], "mv"); else { if ((a[i].cellRepr) & CSF_FLOAT_MASK) printf(" %-*g", colLen[i], a[i].minVal); else printf(" %-*d", colLen[i], (int)a[i].minVal); } printf("\n"); printf("%s",printLabels[ATTR_maxVal]); for(i = 0 ; i < nrNames; i++) if (IS_MV_REAL8(&(a[i].maxVal))) printf(" %-*s", colLen[i], "mv"); else { if ((a[i].cellRepr) & CSF_FLOAT_MASK) printf(" %-*g", colLen[i], a[i].maxVal); else printf(" %-*d", colLen[i], (int)a[i].maxVal); } printf("\n"); printf("%s",printLabels[ATTR_version]); for(i = 0 ; i < nrNames; i++) printf(" %-*u", colLen[i], a[i].version); printf("\n"); printf("%s",printLabels[ATTR_gisFileId]); for(i = 0 ; i < nrNames; i++) printf(" %-*u", colLen[i], a[i].gisFileId); printf("\n"); printf("%s",printLabels[ATTR_byteOrder]); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], a[i].byteOrder == 1 ? "y" : "n"); printf("\n"); printf("%s",printLabels[ATTR_attrTable]); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], a[i].attrTable == 0 ? "n" : "y"); printf("\n"); return 0; }
void XmlParser::Next() { nattr.Clear(); nattr1 = nattrval1 = Null; if(empty_tag) { empty_tag = false; type = XML_END; return; } type = Null; StringBuffer raw_text; for(;;) { if(*term == '\0') { type = XML_EOF; return; } if(*term == '<') { if(term[1] == '!' && term[2] == '[' && term[3] == 'C' && term[4] == 'D' && term[5] == 'A' && term[6] == 'T' && term[7] == 'A' && term[8] == '[') { // ![CDATA[ term += 9; for(;;) { if(*term == '\0') throw XmlError("Unterminated CDATA"); if(term[0] == ']' && term[1] == ']' && term[2] == '>') { // ]]> term += 3; break; } if(*term == '\n') line++; raw_text.Cat(*term++); } type = XML_TEXT; continue; } else break; } if(*term == '\n') line++; if(*term == '&') { Ent(raw_text); type = XML_TEXT; } else { if((byte)*term > ' ') type = XML_TEXT; raw_text.Cat(*term++); } } cdata = FromUtf8(String(raw_text)).ToString(); if(cdata.GetCount() && (npreserve || preserveall)) type = XML_TEXT; if(type == XML_TEXT) return; term++; if(*term == '!') { type = XML_DECL; term++; if(term[0] == '-' && term[1] == '-') { type = XML_COMMENT; term += 2; for(;;) { if(term[0] == '-' && term[1] == '-' && term[2] == '>') break; if(*term == '\0') throw XmlError("Unterminated comment"); if(*term == '\n') line++; tagtext.Cat(*term++); } term += 3; return; } bool intdt = false; for(;;) { if (*term == '[') intdt = true; if(*term == '>' && intdt == false) { term++; break; } if(intdt == true && term[0] == ']' && term[1] == '>') { tagtext.Cat(*term++); term++; break; } if(*term == '\0') throw XmlError("Unterminated declaration"); if(*term == '\n') line++; tagtext.Cat(*term++); } } else if(*term == '?') { type = XML_PI; term++; for(;;) { if(term[0] == '?' && term[1] == '>') { term += 2; return; } if(*term == '\0') throw XmlError("Unterminated processing info"); if(*term == '\n') line++; tagtext.Cat(*term++); } } else if(*term == '/') { type = XML_END; term++; const char *t = term; while(IsXmlNameChar(*term)) term++; tagtext = String(t, term); if(*term != '>') throw XmlError("Unterminated end-tag"); term++; } else { type = XML_TAG; const char *t = term; while(IsXmlNameChar(*term)) term++; tagtext = String(t, term); for(;;) { SkipWhites(); if(*term == '>') { term++; break; } if(term[0] == '/' && term[1] == '>') { cdata.Clear(); empty_tag = true; term += 2; break; } if(*term == '\0') throw XmlError("Unterminated tag"); const char *t = term++; while((byte)*term > ' ' && *term != '=' && *term != '>') term++; String attr(t, term); SkipWhites(); if(*term == '=') { term++; SkipWhites(); StringBuffer attrval; if(*term == '\"') ReadAttr(attrval, '\"'); else if(*term == '\'') ReadAttr(attrval, '\''); else while((byte)*term > ' ' && *term != '>' && *term != '/') if(*term == '&') Ent(attrval); else { const char *e = term; while((byte)*++e > ' ' && *e != '>' && *e != '&') ; attrval.Cat(term,(int) (e - term)); term = e; } if(attr == "xml:space" && attrval.GetLength() == 8 && !memcmp(~attrval, "preserve", 8)) npreserve = true; String aval = FromUtf8(~attrval, attrval.GetLength()).ToString(); if(IsNull(nattr1)) { nattr1 = attr; nattrval1 = aval; } else nattr.Add(attr, aval); } } } }