1 /* 2 Copyright (C) 2015-2021, Dirk Krause 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by the dkct program (see 8 http://dktools.sourceforge.net/ for details). 9 Changes you make here will be lost if dkct is run again! 10 You should modify the original source and run dkct on it. 11 Original source: dk4a85e.ctr 12 */ 13 14 #ifndef DK4A85E_H_INCLUDED 15 /** Avoid multiple inclusions. */ 16 #define DK4A85E_H_INCLUDED 1 17 18 19 /** @file dk4a85e.h ASCII-85 encoder. 20 21 First initialize the encoder using the dk4a85_enc_init(). 22 23 Now add the binary bytes one by one using the dk4a85_enc_add() function, as 24 long as you have bytes available and the function returns DK4_EDSTM_ACCEPT 25 or DK4_EDSTM_FINISHED. 26 27 If the function returns DK4_EDSTM_ACCEPT, no further action is required, 28 the byte was successfully stored in the internal data structures. 29 30 If dk4a85_enc_add() returns DK4_EDSTM_FINISHED, a sequence of 4 binary 31 bytes was processed successfully, a 1 character or 5 character sequence 32 was produced. Use dk4a85_enc_output() to obtain the characters. 33 34 Input data length is not necessarily a multiple of 4, so after feeding 35 all binary bytes some values might still be stored in the encoder. 36 Use dk4a85_enc_finish() to check whether an incomplete final sequence 37 is available. If the function returns DK4_EDSTM_FINISHED, use 38 dk4a85_enc_output() to obtain the text characters for the final bytes. 39 40 */ 41 42 #ifndef DK4CONF_H_INCLUDED 43 #if DK4_BUILDING_DKTOOLS4 44 #include "dk4conf.h" 45 #else 46 #include <dktools-4/dk4conf.h> 47 #endif 48 #endif 49 50 #ifndef DK4ERROR_H_INCLUDED 51 #if DK4_BUILDING_DKTOOLS4 52 #include <libdk4base/dk4error.h> 53 #else 54 #include <dktools-4/dk4error.h> 55 #endif 56 #endif 57 58 #ifndef DK4EDSTM_H_INCLUDED 59 #if DK4_BUILDING_DKTOOLS4 60 #include <libdk4c/dk4edstm.h> 61 #else 62 #include <dktools-4/dk4edstm.h> 63 #endif 64 #endif 65 66 67 /** ASCII 85 encoder. 68 */ 69 typedef struct { 70 char ob[6]; /**< Output bytes, 5 + finalizer */ 71 unsigned char ib[4]; /**< Input bytes to process. */ 72 size_t ci; /**< Index of current input byte. */ 73 size_t os; /**< Number of outupt bytes available */ 74 short az; /**< Allow z encoding */ 75 } dk4_a85_enc_t; 76 77 78 #ifdef __cplusplus 79 extern "C" { 80 #endif 81 82 /** Initialize ASCII 85 encoder before adding data. 83 @param enc Encoder to initialize. 84 @param az Flag: Allow 'z' output character. 85 @param erp Error report, may be NULL. 86 87 Error codes: 88 - DK4_E_INVALID_ARGUMENTS if enc is NULL. 89 */ 90 void 91 92 dk4a85_enc_init(dk4_a85_enc_t *enc, int az, dk4_er_t *erp); 93 94 /** Add one byte to encoder. 95 @param enc Encoder to use. 96 @param input Input byte to add. 97 @param erp Error report, may be NULL. 98 @return Action to take, one from: 99 - DK4_EDSTM_ACCEPT<br> 100 if input was accepted, no further action necessary at the moment. 101 - DK4_EDSTM_FINISHED<br> 102 if a sequence of 4 input bytes was completed, use 103 dk4a85_enc_output() to obtain the text characters. 104 - DK4_EDSTM_ERROR<br> 105 if an error occured. 106 107 Error codes: 108 - DK4_E_INVALID_ARGUMENTS if enc is NULL. 109 */ 110 int 111 112 dk4a85_enc_add(dk4_a85_enc_t *enc, unsigned char input, dk4_er_t *erp); 113 114 /** Check for incomplete sequence in state machine after processing 115 all input bytes. 116 @param enc Encoder to use. 117 @param erp Error report, may be NULL. 118 @return Action to take, one from: 119 - DK4_EDSTM_ACCEPT<br> 120 if there is no incomplete sequence in the state machine, 121 no further action necessary. 122 - DK4_EDSTM_FINISHED<br> 123 if an incomplete final sequence is available, use 124 dk4a85_enc_output() to obtain the text characters. 125 - DK4_EDSTM_ERROR<br> 126 if an error occured. 127 128 Error codes: 129 - DK4_E_INVALID_ARGUMENTS if enc is NULL. 130 */ 131 int 132 133 dk4a85_enc_finish(dk4_a85_enc_t *enc, dk4_er_t *erp); 134 135 /** Retrieve text sequence. 136 @param dptr Address of destination pointer to set, should be 137 initialized to NULL. 138 @param szptr Address of size variable to set, should be 139 initialized to 0. 140 @param enc Encoder to use. 141 @param erp Error report, may be NULL. 142 @return 1 on success (text available), 0 otherwise. 143 144 Error codes: 145 - DK4_E_INVALID_ARGUMENTS if enc, dptr, or szptr is NULL. 146 */ 147 int 148 149 dk4a85_enc_output( 150 const char **dptr, 151 size_t *szptr, 152 dk4_a85_enc_t const *enc, 153 dk4_er_t *erp 154 ); 155 156 #ifdef __cplusplus 157 } 158 #endif 159 160 161 #endif 162