esh.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef ESH_H_INCLUDED
  2. #define EHS_H_INCLUDED
  3. /* Explicit String Handling. These functions help handling strings directly
  4. * using struct wrappers, you need to pass in the parameters explicitly and
  5. * most often by reference.
  6. *
  7. * Nevertheless a struct wrapper is also provided , named woesb,
  8. * or WOE String Buffer.
  9. */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. int esh_bad_p(char **me, size_t * size, size_t * space);
  14. char * esh_make_empty(char ** me, size_t * size, size_t * space);
  15. char * esh_nul_terminate(char ** me, size_t * size, size_t * space);
  16. char * esh_alloc(char ** me, size_t * size, size_t * space, size_t init_space);
  17. char * esh_grow(char ** me, size_t * size, size_t * space, size_t new_space);
  18. char * esh_ensure_space(char ** me, size_t * size, size_t * space, size_t grow_by);
  19. char * esh_append_char(char ** me, size_t * size, size_t * space, char ch);
  20. char * esh_append_buf(char ** me, size_t * size, size_t * space, char * buf, size_t bufsize);
  21. char * esh_append_cstr(char ** me, size_t * size, size_t * space, char * str);
  22. char * esh_init_buf(char ** me, size_t * size, size_t * space, char * buf, size_t bufsize);
  23. char * esh_init_cstr(char ** me, size_t * size, size_t * space, char * buf);
  24. char * esh_new_buf(char **me, size_t * size, size_t * space, char * buf, size_t bufsize);
  25. char * esh_new(char **me, size_t * size, size_t * space, char * init);
  26. char * esh_new_empty(char **me, size_t * size, size_t * space);
  27. char * esh_free(char ** me, size_t * size, size_t * space);
  28. char * esh_read_file(char ** me, size_t * size, size_t * space, FILE * file);
  29. char * esh_read_filename(char ** me, size_t * size, size_t * space, char * fn);
  30. char * esh_join(char ** me, size_t * size, size_t * space, ...);
  31. char * esh_join_va(char ** me, size_t * size, size_t * space, va_list strings);
  32. char * esh_init_join_cstr(char ** me, size_t * size, size_t * space, char * first, ...);
  33. char * esh_init_join_cstr_va(char ** me, size_t * size, size_t * space, char * first, va_list strings);
  34. struct woesb {
  35. char * text;
  36. size_t size;
  37. size_t space;
  38. };
  39. int woesb_bad_p(struct woesb * me);
  40. struct woesb * woesb_make_empty(struct woesb * me);
  41. struct woesb * woesb_nul_terminate(struct woesb * me);
  42. struct woesb * woesb_alloc(struct woesb * me, size_t init_space);
  43. struct woesb * woesb_grow(struct woesb * me, size_t new_space);
  44. struct woesb * woesb_ensure_space(struct woesb * me, size_t grow_by);
  45. struct woesb * woesb_append_char(struct woesb * me, char ch);
  46. struct woesb * woesb_append_buf(struct woesb * me, char * buf, size_t bufsize);
  47. struct woesb * woesb_append_cstr(struct woesb * me, char * str);
  48. struct woesb * woesb_init_buf(struct woesb * me, char * buf, size_t bufsize);
  49. struct woesb * woesb_init_cstr(struct woesb * me, char * buf);
  50. struct woesb * woesb_new_buf(struct woesb * me, char * buf, size_t bufsize);
  51. struct woesb * woesb_new(struct woesb * me, char * init);
  52. struct woesb * woesb_new_empty(struct woesb * me);
  53. struct woesb * woesb_free(struct woesb * me);
  54. struct woesb * woesb_read_file(struct woesb * me, FILE * file);
  55. struct woesb * woesb_read_filename(struct woesb * me, char * fn);
  56. struct woesb * woesb_join(struct woesb * me, ...);
  57. struct woesb * woesb_join_va(struct woesb * me, va_list strings);
  58. struct woesb * woesb_init_join(struct woesb * me, char * first, ...);
  59. struct woesb * woesb_init_join_va(struct woesb * me, char * first, va_list strings);
  60. struct woesb * woesb_new_join_va(struct woesb * me, char * first, va_list strings);
  61. struct woesb * woesb_new_join(struct woesb * me, char * first, ...);
  62. #endif