Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

tbuf_cat(3pub) [debian man page]

TBUF(3pub)																TBUF(3pub)

NAME
tbuf_create, tbuf_destroy, tbuf_copy, tbuf_cat, tbuf_length, tbuf_chars - manipulate text editor buffer SYNOPSIS
#include <publib.h> Tbuf *tbuf_create(const char *chars, size_t len); void tbuf_destroy(Tbuf *tbuf); Tbuf *tbuf_copy(Tbuf *tbuf, size_t offset, size_tlen); Tbuf *tbuf_cat(Tbuf *tbuf, Tbuf * tbuf); size_t tbuf_length(Tbuf *tbuf); void tbuf_chars(char *chars, Tbuf *tbuf, size_t offset, size_t len); DESCRIPTION
These routines create and manipulate simple text editor buffers, which can also be thought of as arbitrarily large text strings. The buf- fers are one-dimensional (i.e., not automatically divided into lines), and are indexed with character offsets. They are 8-bit and binary clean, i.e., they may contain any 8-bit characters, including the zero byte (''). tbuf_create creates a buffer from a C character array, and tbuf_destroy destroys it. Once it's created, a buffer may not be modified. Instead, a new buffer needs to be created, using tbuf_cat and tbuf_copy. They create the new buffer so that it shares as much memory as possible with the old buffer, so the immutability does not necessarily waste memory much. By never changing a buffer, it is rather simple to implement undo and redo: you only need to keep a list of buffers and display the suitable one to the user. The caller should remember to call tbuf_destroy for unnecessary buffers, of course. tbuf_length returns the number of characters in the buffer. tbuf_copy copies part of a buffer into a C character array. The array is not zero-terminated; the caller must do it himself. RETURN VALUE
tbuf_create, tbuf_copy, and tbuf_cat return a pointer to the new buffer, or NULL if the operation failed. tbuf_length returns the number of characters in the buffer. tbuf_destroy and tbuf_chars return nothing and cannot fail. SEE ALSO
publib(3), sbuf(3) AUTHOR
Lars Wirzenius, liw@iki.fi. TBUF(3pub)

Check Out this Related Man Page

STRCSTR(3pub)						       C Programmer's Manual						     STRCSTR(3pub)

NAME
strcstr - convert memory block to printable C string notation SYNOPSIS
#include <publib.h> void strcstr(char *str, size_t max, const void *block, size_t n); DESCRIPTION
strcstr converts the contents of an arbitrary memory block (which need not be a zero terminated string) into a printable notation using normal C string literal syntax. This can be used for example to store potentially binary data in a file, or in debugging outputs. All characters for which there is a simple shorthand escape sequence (', ", ?, , a, , f, , , , v) are stored using that nota- tion. is stored as . All other non-printable characters are stored using a hexadecimal escape sequence. All other printable charac- ters are stored as is. The isprint(3) macro is used to determine whether a character is printable (i.e., whether it is printed as is, or using special notation). Therefore, the output depends on the locale. RETURN VALUE
strcstr returns nothing. EXAMPLE
The following code dumps input to the standard output in a guaranteed (modulo locale bugs) printable format. It might be used for debug- ging. #include <stdio.h> #include <publib.h> int main(void) { char line[512]; char cstr[512*(CHAR_BIT/4+1+2)+1]; /* +2 for x, +1 for , the rest to be able to store the hex code for 512 chars. */ while (fgets(line, sizeof(line), stdin) != NULL) { strcstr(cstr, sizeof(cstr), line, strlen(line)); printf("%s0, cstr); } return 0; } SEE ALSO
publib(3), strins(3) AUTHOR
Lars Wirzenius (lars.wirzenius@helsinki.fi) Publib C Programmer's Manual STRCSTR(3pub)
Man Page