ledit

Text editor (WIP)
git clone git://lumidify.org/ledit.git (fast, but not encrypted)
git clone https://lumidify.org/ledit.git (encrypted, but very slow)
git clone git://4kcetb7mo7hj6grozzybxtotsub5bempzo4lirzc3437amof2c2impyd.onion/ledit.git (over tor)
Log | Files | Refs | README | LICENSE

util.h (1605B)


      1 #ifndef _UTIL_H_
      2 #define _UTIL_H_
      3 
      4 /*
      5  * Return the position of the next start of a utf8 character.
      6  * If there is none, the position of the terminating NUL is
      7  * returned.
      8  */
      9 char *next_utf8(char *str);
     10 
     11 /*
     12  * Same as above, but also works with non-nul-terminated strings.
     13  * Instead of a pointer, the index of the next utf8 char is
     14  * returned.
     15  */
     16 size_t next_utf8_len(char *str, size_t len);
     17 
     18 /*
     19  * Add size_t values and abort if overflow would occur.
     20  * FIXME: Maybe someone with actual experience could tell me
     21  * if this overflow checking actually works.
     22  */
     23 size_t add_sz(size_t a, size_t b);
     24 size_t add_sz3(size_t a, size_t b, size_t c);
     25 
     26 void swap_sz(size_t *a, size_t *b);
     27 void sort_range(size_t *l1, size_t *b1, size_t *l2, size_t *b2);
     28 
     29 /*
     30  * Compare the nul-terminated string 'terminated' with the char
     31  * array 'array' with length 'len'.
     32  * Returns non-zero if they are equal, 0 otherwise.
     33  */
     34 /* Note: this doesn't work if array contains '\0'. */
     35 int str_array_equal(const char *terminated, const char *array, size_t len);
     36 
     37 #define LEDIT_MIN(x, y) ((x) < (y) ? (x) : (y))
     38 #define LEDIT_MAX(x, y) ((x) > (y) ? (x) : (y))
     39 
     40 /* Apparently, ISO C99 requires at least one argument for
     41    variadic macros, so there are two versions of the macro here. */
     42 #ifdef LEDIT_DEBUG
     43 	#define ledit_debug(fmt) do {fprintf(stderr, "%s:%d: " fmt, __FILE__, __LINE__);} while (0)
     44 	#define ledit_debug_fmt(fmt, ...) do {fprintf(stderr, "%s:%d: " fmt, __FILE__, __LINE__, __VA_ARGS__);} while (0)
     45 #else
     46 	#define ledit_debug(fmt) do {} while (0)
     47 	#define ledit_debug_fmt(fmt, ...) do {} while (0)
     48 #endif
     49 
     50 #endif