hyx

Minimalist but powerful terminal hex editor
git clone https://git.sinitax.com/yx7/hyx
Log | Files | Refs | sfeed.txt

blob.h (1803B)


      1#ifndef BLOB_H
      2#define BLOB_H
      3
      4#include "common.h"
      5#include "history.h"
      6
      7enum blob_alloc {
      8    BLOB_MALLOC = 0,
      9    BLOB_MMAP,
     10};
     11
     12struct blob {
     13    enum blob_alloc alloc;
     14
     15    size_t len;
     16    byte *data;
     17
     18    char *filename;
     19
     20    uint8_t *dirty;
     21
     22    struct diff *undo, *redo;
     23    ssize_t saved_dist;
     24
     25    struct {
     26        size_t len;
     27        byte *data;
     28    } clipboard;
     29};
     30
     31void blob_init(struct blob *blob);
     32void blob_replace(struct blob *blob, size_t pos, byte const *data, size_t len, bool save_history);
     33void blob_insert(struct blob *blob, size_t pos, byte const *data, size_t len, bool save_history);
     34void blob_delete(struct blob *blob, size_t pos, size_t len, bool save_history);
     35void blob_free(struct blob *blob);
     36
     37bool blob_can_move(struct blob const *blob);
     38
     39bool blob_undo(struct blob *blob, size_t *pos);
     40bool blob_redo(struct blob *blob, size_t *pos);
     41
     42void blob_yank(struct blob *blob, size_t pos, size_t len);
     43size_t blob_paste(struct blob *blob, size_t pos, enum op_type type);
     44
     45ssize_t blob_search(struct blob *blob, byte const *needle, size_t len, size_t start, ssize_t dir);
     46
     47void blob_load(struct blob *blob, char const *filename);
     48void blob_load_stream(struct blob *blob, FILE *fp);
     49enum blob_save_error {
     50    BLOB_SAVE_OK = 0,
     51    BLOB_SAVE_FILENAME,
     52    BLOB_SAVE_NONEXISTENT,
     53    BLOB_SAVE_PERMISSIONS,
     54    BLOB_SAVE_BUSY,
     55} blob_save(struct blob *blob, char const *filename);
     56bool blob_is_saved(struct blob const *blob);
     57
     58static inline size_t blob_length(struct blob const *blob)
     59    { return blob->len; }
     60byte const *blob_lookup(struct blob const *blob, size_t pos, size_t *len);
     61static inline byte blob_at(struct blob const *blob, size_t pos)
     62    { return *blob_lookup(blob, pos, NULL); }
     63void blob_read_strict(struct blob *blob, size_t pos, byte *buf, size_t len);
     64
     65#endif