Lugaru's Epsilon
Programmer's
Editor 14.04

Context:
Epsilon User's Manual and Reference
   Primitives and EEL Subroutines
      Buffer Primitives
         Changing Buffer Contents
         Moving Text Between Buffers
         Getting Text from a Buffer
         Spots
         Narrowing
         . . .
      Display Primitives
         Creating & Destroying Windows
         Window Resizing Primitives
         Preserving Window Arrangements
         . . .
         Colors
      . . .

Previous   Up    Next
Moving Text Between Buffers  Primitives and EEL Subroutines   Spots


Epsilon User's Manual and Reference > Primitives and EEL Subroutines > Buffer Primitives >

Getting Text from a Buffer

grab(int pos1, int pos2, char *to)
grab_expanding(int pos1, int pos2, char **toptr, int minlen)
buf_grab_bytes(int buf, int from, int to, char *dest)

The grab( ) primitive copies characters from the buffer to a string. It takes the range of characters to copy, and a character pointer indicating where to copy them. The buffer doesn't change. The positions may be in either order. The resulting string will be null-terminated.

The grab_expanding( ) subroutine is similar, but works with a dynamically allocated character pointer, not a fixed-length character array. Pass a pointer to a char * variable, and the subroutine will resize it as needed to hold the result. The char * variable may hold NULL initially. The minlen parameter provides a minimum allocation length for the result.

The buf_grab_bytes( ) subroutine copies characters in the specified range in the buffer buf into the character array dest, in the same fashion as grab( ). Despite its name, it operates on 16-bit characters, not 8-bit bytes.

grab_full_line(int bnum, char *str) /* buffer.e */
grab_line(int bnum, char *str)      /* buffer.e */

The grab_full_line( ) subroutine copies the entire current line of buffer number bnum into the character array str. It doesn't change point. The grab_line( ) subroutine copies the remainder of bnum's current line to str, and moves to the start of the next line. Neither function copies the <Newline> at the end of the line, and each returns the number of characters copied.

grab_line_offset(int b, char *s, int offset, int wrap)
get_line_from_buffer(int buf, int line, char *res)
move_line_to_buffer(int dest)

The grab_line_offset( ) subroutine copies a line from buffer b into s, discarding any trailing newline and returning the string's length. The offset parameter specifies which line: 0 means the buffer's current line, 1 means the next, and so forth. The subroutine moves to end of the appropriate line. If offset is negative, the subroutine moves to a previous line and copies it, remaining at its start. The wrap parameter, if nonzero, makes the subroutine wrap around to the opposite end of the buffer if it hits an end when counting lines; if zero, a too-high offset returns zero and empties s.

The get_line_from_buffer( ) subroutine copies the line'th line in buffer buf to res.

The move_line_to_buffer( ) subroutine copies the current line to the buffer dest, then deletes it from the current buffer.

int grab_numbers(int bnum, int *nums)    /* buffer.e */
int break_into_numbers(char *s, int *nums)

The grab_numbers( ) subroutine uses grab_line( ) to retrieve a line from buffer bnum. Then it breaks the line into words (separated by spaces and tabs), and tries to interpret each word as a number by calling the numtoi( ) subroutine. It puts the resulting numbers in the array nums. The function returns the number of words on the line.

The break_into_numbers( ) subroutine is similar, but retrieves the numbers from a string s. It returns the count of numbers it found, putting their values into the nums array.

int grab_string(int bnum, char *s, char *endmark) /* buffer.e */
int grab_string_expanding(int bnum, char **s, 
                          char *endmark, int minlen)

The grab_string( ) subroutine copies from buffer bnum into s. It copies from the buffer's current position to the beginning of the next occurrence of the text endmark, and leaves the buffer's point after that text. It returns 1, unless it couldn't find the endmark text. In that case, it moves to the end of the buffer, sets s to the empty string, and returns 0.

The grab_string_expanding( ) subroutine is similar, but works with dynamically allocated character pointers, not fixed-length character arrays. Pass a pointer to a char * variable, and the subroutine will resize it as needed to hold the result. The char * variable may hold NULL initially. The minlen parameter provides a minimum allocation length for the result.



Previous   Up    Next
Moving Text Between Buffers  Primitives and EEL Subroutines   Spots


Lugaru Epsilon Programmer's Editor 14.04 manual. Copyright (C) 1984, 2021 by Lugaru Software Ltd. All rights reserved.