vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

text-internal.h

(1285B)


      1 #ifndef TEXT_INTERNAL
      2 #define TEXT_INTERNAL
      3 
      4 #include <stdbool.h>
      5 #include <stddef.h>
      6 #include "text.h"
      7 
      8 /* Block holding the file content, either readonly mmap(2)-ed from the original
      9  * file or heap allocated to store the modifications.
     10  */
     11 typedef struct {
     12 	size_t size;               /* maximal capacity */
     13 	size_t len;                /* current used length / insertion position */
     14 	char *data;                /* actual data */
     15 	enum {                     /* type of allocation */
     16 		BLOCK_TYPE_MMAP_ORIG, /* mmap(2)-ed from an external file */
     17 		BLOCK_TYPE_MMAP,      /* mmap(2)-ed from a temporary file only known to this process */
     18 		BLOCK_TYPE_MALLOC,    /* heap allocated block using malloc(3) */
     19 	} type;
     20 } Block;
     21 
     22 Block *block_alloc(size_t size);
     23 Block *block_read(size_t size, int fd);
     24 Block *block_mmap(size_t size, int fd, off_t offset);
     25 Block *block_load(int dirfd, const char *filename, enum TextLoadMethod method, struct stat *info);
     26 void block_free(Block*);
     27 bool block_capacity(Block*, size_t len);
     28 const char *block_append(Block*, const char *data, size_t len);
     29 bool block_insert(Block*, size_t pos, const char *data, size_t len);
     30 bool block_delete(Block*, size_t pos, size_t len);
     31 
     32 Block *text_block_mmaped(Text*);
     33 void text_saved(Text*, struct stat *meta);
     34 
     35 #endif