/* ** tuiSetLocatorContent(). ** Function to set the content of the locator */ void tuiSetLocatorContent (struct frame_info *frameInfo) { TuiGenWinInfoPtr locator = locatorWinInfoPtr (); TuiWinElementPtr element; struct symtab_and_line symtabAndLine; /* Allocate the element if necessary */ if (locator->contentSize <= 0) { TuiWinContent contentPtr; if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL) error ("Unable to Allocate Memory to Display Location."); locator->contentSize = 1; } if (frameInfo != (struct frame_info *) NULL) tuiUpdateLocatorInfoFromFrame (frameInfo, &((TuiWinElementPtr) locator->content[0])->whichElement.locator); else tuiSetLocatorInfo ((char *) NULL, (char *) NULL, 0, (CORE_ADDR) 0, &((TuiWinElementPtr) locator->content[0])->whichElement.locator); return; } /* tuiSetLocatorContent */
/* ** addContentElements(). ** Adds the input number of elements to the windows's content. If ** no content has been allocated yet, allocContent() is called to ** do this. The index of the first element added is returned, ** unless there is a memory allocation error, in which case, (-1) ** is returned. */ int addContentElements (TuiGenWinInfoPtr winInfo, int numElements) { TuiWinElementPtr elementPtr; int i, indexStart; if (winInfo->content == (OpaquePtr) NULL) { winInfo->content = (OpaquePtr) allocContent (numElements, winInfo->type); indexStart = 0; } else indexStart = winInfo->contentSize; if (winInfo->content != (OpaquePtr) NULL) { for (i = indexStart; (i < numElements + indexStart); i++) { if ((elementPtr = (TuiWinElementPtr) xmalloc (sizeof (TuiWinElement))) != (TuiWinElementPtr) NULL) { winInfo->content[i] = (Opaque) elementPtr; initContentElement (elementPtr, winInfo->type); winInfo->contentSize++; } else /* things must be really hosed now! We ran out of memory!? */ return (-1); } } return indexStart; } /* addContentElements */
ByteBuffer::ByteBuffer(bufsize_t v_size, bufsize_t v_padding) : content(NULL), contentSize(v_size), padding(v_padding) { if (v_size == 0) throw BufferException("Zero size requested"); this->content = allocContent(v_size, v_padding); this->contentSize = v_size; }
char * File::readAll(){ if(opened() && mMode[0]=='r'){ int n = size(); allocContent(n); int numRead = fread(mContent, sizeof(char), n, mFP); if(numRead < n){} } return mContent; }
/* ** initContentElement(). */ void initContentElement (TuiWinElementPtr element, TuiWinType type) { element->highlight = FALSE; switch (type) { case SRC_WIN: case DISASSEM_WIN: element->whichElement.source.line = (char *) NULL; element->whichElement.source.lineOrAddr.lineNo = 0; element->whichElement.source.isExecPoint = FALSE; element->whichElement.source.hasBreak = FALSE; break; case DATA_WIN: initGenericPart (&element->whichElement.dataWindow); element->whichElement.dataWindow.type = DATA_ITEM_WIN; ((TuiGenWinInfoPtr) & element->whichElement.dataWindow)->content = (OpaquePtr) allocContent (1, DATA_ITEM_WIN); ((TuiGenWinInfoPtr) & element->whichElement.dataWindow)->contentSize = 1; break; case CMD_WIN: element->whichElement.command.line = (char *) NULL; break; case DATA_ITEM_WIN: element->whichElement.data.name = (char *) NULL; element->whichElement.data.type = TUI_REGISTER; element->whichElement.data.itemNo = UNDEFINED_ITEM; element->whichElement.data.value = (Opaque) NULL; element->whichElement.data.highlight = FALSE; break; case LOCATOR_WIN: element->whichElement.locator.fileName[0] = element->whichElement.locator.procName[0] = (char) 0; element->whichElement.locator.lineNo = 0; element->whichElement.locator.addr = 0; break; case EXEC_INFO_WIN: memset(element->whichElement.simpleString, ' ', sizeof(element->whichElement.simpleString)); break; default: break; } return; } /* initContentElement */
ByteBuffer::ByteBuffer(AbstractByteBuffer *v_parent, offset_t v_offset, bufsize_t v_size, bufsize_t v_padding) { if (v_parent == NULL) throw BufferException("Cannot make subBuffer for NULL buffer!"); if (v_size == 0) throw BufferException("Cannot make 0 size buffer!"); bufsize_t parentSize = v_parent->getContentSize(); bufsize_t copySize = v_size < parentSize ? v_size : parentSize; bufsize_t allocSize = v_size > parentSize ? v_size : parentSize; BYTE *bContent = v_parent->getContentAt(v_offset, copySize); if (bContent == NULL) throw BufferException("Cannot make Buffer for NULL content!"); this->content = allocContent(allocSize, v_padding); this->contentSize = allocSize; memcpy(this->content, bContent, copySize); TRACE(); }
bool ByteBuffer::resize(bufsize_t newSize) { if (newSize == this->contentSize) return true; BYTE *newContent = NULL; try { newContent = allocContent(newSize, this->padding); } catch(BufferException &e) { newContent = NULL; } if (newContent == NULL) return false; BYTE *oldContent = this->content; bufsize_t oldSize = this->contentSize; bufsize_t copySize = newSize < oldSize ? newSize : oldSize; memcpy(newContent, oldContent, copySize); this->content = newContent; this->contentSize = newSize; delete []oldContent; return true; }