TEXT.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef TEXT_HEADER
  2. #define TEXT_HEADER
  3. // this header needs
  4. #include <stdio.h>
  5. #include "../FILE.h"
  6. // text_t enum
  7. // enum with supported
  8. // text file types
  9. typedef enum
  10. {
  11. TEXT_NO_TYPE,
  12. TEXT_CSV,
  13. } text_t;
  14. // text_err_cd enum
  15. // enum with general error
  16. // codes for a text file
  17. typedef enum
  18. {
  19. TEXT_ERR_NO_ERR, // file has no errors
  20. // ...
  21. /**********/
  22. TEXT_ERR_LN, // errors below this (in numeric value) are non-fatal, above are fatal
  23. /**********/
  24. TEXT_ERR_UNKNOWN_ENC,
  25. TEXT_ERR_NULL_PATH,
  26. // ...
  27. } text_err_cd;
  28. // text_enc enum
  29. // enum with supported
  30. // text file encoding types
  31. typedef enum
  32. {
  33. TEXT_ENC_UNKNOWN, // encoding is unsupported
  34. TEXT_ENC_ASCII,
  35. TEXT_ENC_CP1252,
  36. TEXT_ENC_CP932,
  37. TEXT_ENC_SHIFT_JIS,
  38. TEXT_ENC_UTF8,
  39. TEXT_ENC_UTF16BE,
  40. TEXT_ENC_UTF16LE,
  41. TEXT_ENC_END_INT, // not an encoding
  42. } text_enc;
  43. // text general structure
  44. typedef struct
  45. {
  46. char * PATH; // extra information I want to be able to see
  47. byte * DATA; // the bytes of the file loaded in memory
  48. umax SIZE; // size is very variable on text files
  49. text_enc ENC; // text file encoding
  50. text_err_cd ERR_CD_INC; // error code from check_text_inc()
  51. text_t TYPE; // text file type
  52. text_err_cd ERR_CD_TP; // error code from a text file type function (reuses the text_err_cd type)
  53. void * ST; // pointer to the text structure (specific to each type of text file)
  54. } text;
  55. // text_data_t enum
  56. // enum with text file data types
  57. typedef enum
  58. {
  59. TEXT_UINT, // unsigned integer
  60. TEXT_SINT, // signed integer
  61. TEXT_FLOAT, // floating point number
  62. TEXT_CHAR_ARR, // character array (fixed size)
  63. TEXT_STR, // string (until some character)
  64. } text_data_t;
  65. // build, close and print an incomplete text structure (a complete build
  66. // will have to be made by more file type specific functions)
  67. text_enc check_text_enc(char * text_file_path);
  68. text_err_cd check_text_inc(char * text_file_path);
  69. text * open_text_inc(char * text_file_path);
  70. void close_text_inc(text * text_file);
  71. void print_text_inc(text * text_file);
  72. // other functions
  73. bool insert_text_chars(text * txt_f, void * txt_pos, umax * chints, umax csize);
  74. bool remove_text_chars(text * txt_f, void * txt_pos, umax rm_size);
  75. #include "TEXT.c"
  76. #endif // TEXT_HEADER