Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

regularexpression(3W)

textbuffer(3W)

textedit(3W)

textfield(3W)

textselection(3W)

buffer(3W)

NAMES

AllocateBuffer, Buffer Macros, CopyBuffer, FreeBuffer, GrowBuffer, InsertIntoBuffer, ReadStringIntoBuffer, strclose, strgetc, stropen − buffer utilities

SYNOPSIS AND DESCRIPTION

Text buffer utility functions. 

AllocateBuffer

#include <buffutil.h>
  ...
extern Buffer ∗ AllocateBuffer(

int element_size,
int initial_size);

The AllocateBuffer function allocates a Buffer for elements of the given element_size.  The used member of the Buffer is set to zero and the size member is set to the value of initial_size.  If initial_size is zero the pointer p is set to NULL, otherwise the amount of space required (initial_size ∗ element_size) is allocated and the pointer p is set to point to this space.  The function returns the pointer to the allocated Buffer. 

Buffer Macros

The following macros are provided for use with the Buffer Utilities

  Table 1 Buffer Macros

Macro Returns
BufferFilled(buffer) indicates buffer filled
BufferLeft(buffer) number of unused elements in buffer
BufferEmpty(buffer) indicates fIbuffer is empty

CopyBuffer

#include <buffutil.h>
  ...
extern Buffer ∗ CopyBuffer(

Buffer buffer);

The CopyBuffer function is used to allocate a new Buffer with the same attributes as the given buffer and to copy the data associated with the given buffer into the new Buffer.  A pointer to the newly allocated and initialized Buffer is returned.  It is the responsibility of the caller to free this storage when appropriate. 

FreeBuffer

#include <buffutil.h>
  ...
extern void FreeBuffer(

Buffer ∗buffer);

The FreeBuffer procedure is used to deallocate (free) storage associated with the given buffer pointer. 

GrowBuffer

#include <Xol/buffutil.h>
 . . .
extern void GrowBuffer(

Buffer ∗buffer,
int increment);

The GrowBuffer procedure is used to expand (or compress) a given buffer size by increment elements.  If the increment is negative the operation results in a reduction in the size of the Buffer. 

InsertIntoBuffer

#include <Xol/buffutil.h>
 . . .
extern int InsertIntoBuffer(

Buffer ∗target,
Buffer ∗source,
int offset);

The InsertIntoBuffer function is used to insert the elements stored in the source buffer into the target buffer before the element stored at offset.  If the offset is invalid or if the source buffer is empty the function returns zero; otherwise it returns one after completing the insertion. 

ReadFileIntoBuffer

#include <Xol/buffutil.h>
 . . .
extern int ReadFileIntoBuffer(

FILE ∗fp,
Buffer ∗buffer);

The ReadFileIntoBuffer function reads the file associated with fp and inserts the characters read into the buffer.  The read operation terminates when either EOF is returned when reading the file or when a NEWLINE is encountered.  The function returns the last character read to the caller (either EOF or NEWLINE). 

ReadStringIntoBuffer

#include <Xol/buffutil.h>
 . . .
extern int ReadStringIntoBuffer(

Buffer ∗sp,
Buffer ∗buffer);

The ReadStringIntoBuffer function reads the buffer associated with sp and inserts the characters read into buffer.  The read operation terminates when either EOF is returned when reading the buffer or when a NEWLINE is encountered.  The function returns the last character read to the caller (either EOF or NEWLINE). 

strclose

#include <Xol/buffutil.h>
 . . .
extern void strclose(

Buffer ∗sp);

The strclose procedure is used to close a string Buffer which was opened using the stropen function. 

strgetc

#include <Xol/buffutil.h>
 . . .
extern int strgetc(

Buffer ∗sp);

The strgetc function is used to read the next character stored in the string buffer.  The function returns the next character in the Buffer.  When no characters remain the routine returns EOF. 

stropen

#include <Xol/buffutil.h>
 . . .
extern Buffer ∗stropen(

char ∗string);

The stropen function copies the string into a newly allocated Buffer.  This string buffer can be read using the strgetc function and closed using the strclose procedure.  The strclose function frees the buffer allocated by stropen. 

SEE ALSO

regularexpression(3W), textbuffer(3W), textedit(3W), textfield(3W), textselection(3W)

Version 3.0.1  —  Last change: June 92

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026