ses.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef ses_H_INCLUDED
  2. #define ses_H_INCLUDED
  3. /* Simple explicit string handling and growing.
  4. * These functions help handling strings without
  5. * using struct wrappers, you need to pass in the parameters explicitly.
  6. *
  7. * Nevertheless a struct wrapper is also provided as a Swis, namely a
  8. * Simple wrapped idiotic string. The wrapper must be alocated by the user.
  9. */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. int ses_bad_p(char **me, size_t * size, size_t * space);
  13. char * ses_make_empty(char ** me, size_t * size, size_t * space);
  14. char * ses_nul_terminate(char ** me, size_t * size, size_t * space);
  15. char * ses_alloc(char ** me, size_t * size, size_t * space, size_t init_space);
  16. char * ses_grow(char ** me, size_t * size, size_t * space, size_t new_space);
  17. char * ses_ensure_space(char ** me, size_t * size, size_t * space, size_t grow_by);
  18. char * ses_append_char(char ** me, size_t * size, size_t * space, char ch);
  19. char * ses_append_buf(char ** me, size_t * size, size_t * space, char * buf, size_t bufsize);
  20. char * ses_append_cstr(char ** me, size_t * size, size_t * space, char * str);
  21. char * ses_init_buf(char ** me, size_t * size, size_t * space, char * buf, size_t bufsize);
  22. char * ses_init_cstr(char ** me, size_t * size, size_t * space, char * buf);
  23. char * ses_new_buf(char **me, size_t * size, size_t * space, char * buf, size_t bufsize);
  24. char * ses_new(char **me, size_t * size, size_t * space, char * init);
  25. char * ses_new_empty(char **me, size_t * size, size_t * space);
  26. char * ses_free(char ** me, size_t * size, size_t * space);
  27. char * ses_read_file(char ** me, size_t * size, size_t * space, FILE * file);
  28. char * ses_read_filename(char ** me, size_t * size, size_t * space, char * fn);
  29. typedef struct Swis_ Swis;
  30. struct Swis_ {
  31. char * text;
  32. size_t size;
  33. size_t space;
  34. };
  35. int swis_bad_p(Swis * me);
  36. Swis * swis_make_empty(Swis * me);
  37. Swis * swis_nul_terminate(Swis * me);
  38. Swis * swis_alloc(Swis * me, size_t init_space);
  39. Swis * swis_grow(Swis * me, size_t new_space);
  40. Swis * swis_ensure_space(Swis * me, size_t grow_by);
  41. Swis * swis_append_char(Swis * me, char ch);
  42. Swis * swis_append_buf(Swis * me, char * buf, size_t bufsize);
  43. Swis * swis_append_cstr(Swis * me, char * str);
  44. Swis * swis_init_buf(Swis * me, char * buf, size_t bufsize);
  45. Swis * swis_init_cstr(Swis * me, char * buf);
  46. Swis * swis_new_buf(Swis * me, char * buf, size_t bufsize);
  47. Swis * swis_new(Swis * me, char * init);
  48. Swis * swis_new_empty(Swis * me);
  49. Swis * swis_free(Swis * me);
  50. Swis * swis_read_file(Swis * me, FILE * file);
  51. Swis * swis_read_filename(Swis * me, char * fn);
  52. #endif