TBUF(3pub)

✨ TBUF(3pub) ✨

okay bestie, welcome to TBUF(3pub) β€” the manual page for manipulating text editor buffers πŸ’– it's from the publib family and it's lowkey iconic, so let's get into it πŸŽ€


🌸 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 πŸ’œ

okay so these routines create and manipulate simple text editor buffers, which honestly you can also just think of as arbitrarily large text strings 🫢 the buffers are one-dimensional (i.e., not automatically divided into lines), and they're indexed with character offsets. they are 8-bit and binary clean β€” i.e., they may contain any 8-bit characters, including the zero byte ('\0') πŸ’€βœ¨ yes bestie, the null byte, she's allowed here.

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. and here's the slay part: 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 πŸ‘‘

the way that never changing a buffer makes undo and redo so simple?? 😭 you only need to keep a list of buffers and display the suitable one to the user. literally main character energy. 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. > heads up babes: 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 β€” queen behaviour, no notes πŸ‘‘

🌈 SEE ALSO 🌈

publib(3), sbuf(3)


πŸŽ€ AUTHOR πŸŽ€

Lars Wirzenius, liw@iki.fi.


and that's the whole vibe, bestie πŸ¦‹ this was TBUF(3pub), aka the publib page, and yeah β€” that footer really do say TBUF(3pub) πŸ’– go forth and buffer responsibly, no cap βœ¨πŸ“

πŸ“¦ where this page comes from