00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUTEXT_SRC_H
00019 #define CUTEXT_SRC_H
00020
00021 #include <cutext/fwd.h>
00022 #include <cutext/encoding.h>
00023 #include <cu/clos.h>
00024 #include <cu/buffer.h>
00025 #include <cu/debug.h>
00026
00027 CU_BEGIN_DECLARATIONS
00028
00029 typedef cu_clop(cutext_producer_t, cutext_status_t, void **p, size_t size);
00030
00031 struct cutext_src
00032 {
00033 struct cu_buffer buf;
00034 cutext_producer_t produce;
00035 };
00036
00037 void cutext_src_init(cutext_src_t, cutext_producer_t);
00038 cutext_src_t cutext_src_new(cutext_producer_t);
00039
00040 void cutext_src_init_grab(cutext_src_t src_init, cutext_src_t src_drop);
00041 cutext_src_t cutext_src_new_grab(cutext_src_t src_drop);
00042
00043
00044 cutext_status_t cutextP_src_lookahead(cutext_src_t src, size_t size);
00045
00046 CU_SINLINE cutext_status_t
00047 cutext_src_lookahead(cutext_src_t src, size_t size)
00048 {
00049 if (cu_ptr_diff(src->buf.content_end, src->buf.content_start) < size)
00050 return cutextP_src_lookahead(src, size);
00051 else
00052 return cutext_status_ok;
00053 }
00054
00055 CU_SINLINE void *
00056 cutext_src_data_start(cutext_src_t src) { return src->buf.content_start; }
00057
00058 CU_SINLINE void *
00059 cutext_src_data_end(cutext_src_t src) { return src->buf.content_end; }
00060
00061 CU_SINLINE size_t
00062 cutext_src_data_size(cutext_src_t src)
00063 {
00064 return cu_ptr_diff(src->buf.content_end, src->buf.content_start);
00065 }
00066
00067 CU_SINLINE void
00068 cutext_src_advance(cutext_src_t src, size_t size)
00069 {
00070 src->buf.content_start = cu_ptr_add(src->buf.content_start, size);
00071 cu_debug_assert(src->buf.content_start <= src->buf.content_end);
00072 }
00073
00074 cutext_producer_t cutext_producer_new_charr(char const *arr, size_t size);
00075 cutext_producer_t cutext_producer_new_read(int fd);
00076 cutext_producer_t cutext_producer_new_iconv(cutext_src_t src,
00077 cutext_encoding_t src_chenc,
00078 cutext_encoding_t self_chenc);
00079
00080
00081
00082
00083
00084 cutext_encoding_t cutext_src_detect_chenc(cutext_src_t src);
00085
00086
00087 #define cutext_src_cct cutext_src_init
00088 #define cutext_src_cct_move cutext_src_init_grab
00089 #define cutext_src_new_move cutext_src_new_grab
00090
00091 CU_END_DECLARATIONS
00092
00093 #endif