summaryrefslogtreecommitdiff
path: root/src/common/ibuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/ibuf.h')
-rw-r--r--src/common/ibuf.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/common/ibuf.h b/src/common/ibuf.h
new file mode 100644
index 0000000..b57e374
--- /dev/null
+++ b/src/common/ibuf.h
@@ -0,0 +1,71 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * ibuf.h - prototypes pour la lecture progressive d'un tampon de données
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _COMMON_IBUF_H
+#define _COMMON_IBUF_H
+
+
+#include <stdint.h>
+#include <sys/types.h>
+
+
+
+/* Rassemblement de données d'un tampon */
+typedef struct _input_buffer
+{
+ union
+ {
+ const char *text; /* Contenu textuel disponible */
+ const uint8_t *data; /* Données brutes à traiter */
+ };
+
+ size_t len; /* Quantité d'octets présents */
+ size_t pos; /* Position de tête de lecture */
+
+} input_buffer;
+
+
+/* Initialise un contenu textuel pour une lecture ultérieure. */
+void init_text_input_buffer(input_buffer *, const char *);
+
+/* Compte le nombre d'octets encore non lus. */
+size_t count_input_buffer_remaining(const input_buffer *);
+
+/* Avance la tête de lecture dans le tampon de données. */
+void advance_input_buffer(input_buffer *, size_t);
+
+/* Fournit un accès brut au niveau de la tête de lecture. */
+const char *get_input_buffer_text_access(const input_buffer *);
+
+/* Fournit et avance la tête de lecture courante. */
+char text_input_buffer_next_char(input_buffer *);
+
+/* Note la position courante de la tête de lecture. */
+void save_input_buffer_pos(const input_buffer *, size_t *);
+
+/* Restaure la position de la tête de lecture. */
+void restore_input_buffer_pos(input_buffer *, size_t);
+
+
+
+#endif /* _COMMON_IBUF_H */