diff options
author | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
commit | 1f457376b478257b88d4a857f5ec1b6155442dd7 (patch) | |
tree | 2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk4strm.ctr | |
parent | ac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff) |
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk4strm.ctr')
-rw-r--r-- | support/dktools/dk4strm.ctr | 120 |
1 files changed, 105 insertions, 15 deletions
diff --git a/support/dktools/dk4strm.ctr b/support/dktools/dk4strm.ctr index f26d0f93cb..137ca68898 100644 --- a/support/dktools/dk4strm.ctr +++ b/support/dktools/dk4strm.ctr @@ -2,7 +2,7 @@ copyright owner = Dirk Krause copyright year = 2015-xxxx -license = bsd +SPDX-License-Identifier: BSD-3-Clause @@ -16,15 +16,27 @@ license = bsd */ #ifndef DK4CONF_H_INCLUDED +#if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" +#else +#include <dktools-4/dk4conf.h> +#endif #endif #ifndef DK4TYPES_H_INCLUDED +#if DK4_BUILDING_DKTOOLS4 #include "dk4types.h" +#else +#include <dktools-4/dk4types.h> +#endif #endif #ifndef DK4ERROR_H_INCLUDED +#if DK4_BUILDING_DKTOOLS4 #include "dk4error.h" +#else +#include <dktools-4/dk4error.h> +#endif #endif #ifndef STDLIB_H_INCLUDED @@ -50,8 +62,8 @@ typedef void dk4_stream_api_fct_t(dk4_stream_api_t *); /** Generic I/O stream. */ typedef struct { - void *d; /**< Low level data object. */ dk4_stream_api_fct_t *fct; /**< Function for low level operations. */ + void *d; /**< Low level data object. */ char *bi; /**< Buffer for input. */ char *bo; /**< Buffer for output. */ dk4_um_t bwr; /**< Number of bytes written. */ @@ -129,7 +141,7 @@ dk4stream_close(dk4_stream_t *strm, dk4_er_t *erp); - DK4_E_WRITE_FAILED<br> if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED<br> - if flusing data downwards failed. + if flushing data downwards failed. */ int dk4stream_write_byte(dk4_stream_t *strm, char c, dk4_er_t *erp); @@ -147,7 +159,7 @@ dk4stream_write_byte(dk4_stream_t *strm, char c, dk4_er_t *erp); - DK4_E_WRITE_FAILED<br> if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED<br> - if flusing data downwards failed. + if flushing data downwards failed. */ int dk4stream_write(dk4_stream_t *strm, const void *b, size_t sz, dk4_er_t *erp); @@ -165,7 +177,7 @@ dk4stream_write(dk4_stream_t *strm, const void *b, size_t sz, dk4_er_t *erp); - DK4_E_WRITE_FAILED<br> if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED<br> - if flusing data downwards failed. + if flushing data downwards failed. */ int dk4stream_write_char_string(dk4_stream_t *strm, const char *str, dk4_er_t *erp); @@ -184,7 +196,7 @@ dk4stream_write_char_string(dk4_stream_t *strm, const char *str, dk4_er_t *erp); - DK4_E_WRITE_FAILED<br> if writing one ore multiple bytes to the stream failed - DK4_E_FLUSH_FAILED<br> - if flusing data downwards failed. + if flushing data downwards failed. */ int dk4stream_flush(dk4_stream_t *strm, int flfl, dk4_er_t *erp); @@ -358,11 +370,18 @@ enum { +#include "dk4conf.h" #include "dk4strm.h" #include "dk4mem.h" #include "dk4enc.h" #include "dk4numco.h" +#if DK4_HAVE_ASSERT_H +#ifndef ASSERT_H_INCLUDED +#include <assert.h> +#define ASSERT_H_INCLUDED 1 +#endif +#endif $!trace-include @@ -375,6 +394,9 @@ void dk4stream_api_init(dk4_stream_api_t *ptr) { $? "+ dk4stream_api_init" +#if DK4_USE_ASSERT + assert(NULL != ptr); +#endif DK4_MEMRES(ptr, sizeof(dk4_stream_api_t)); ptr->d = NULL; ptr->b = NULL; @@ -395,6 +417,9 @@ void dk4stream_release_memory(dk4_stream_t *strm) { $? "+ dk4stream_release_memory PTR=%d", TR_IPTR(strm) +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL != strm) { dk4mem_release(strm->bi); dk4mem_release(strm->bo); @@ -427,6 +452,9 @@ dk4stream_i_flush_write(dk4_stream_t *strm, int flfl, dk4_er_t *erp) $? "+ dk4stream_i_flush_write" /* Write buffer contents (if any) downwards. */ +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (0 != strm->usbo) { $? ". bytes in output buffer" dk4stream_api_init(&api); api.cmd = DK4_STREAM_API_WRITE; @@ -472,6 +500,9 @@ dk4stream_i_write_byte(dk4_stream_t *strm, char c, dk4_er_t *erp) { int back = 0; $? "+ dk4stream_i_write_byte" +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (strm->usbo < strm->szbo) { (strm->bo)[strm->usbo] = c; strm->usbo += 1; @@ -491,15 +522,18 @@ dk4stream_i_write_byte(dk4_stream_t *strm, char c, dk4_er_t *erp) /** Internal function to read a single character. @param dst Pointer to variable for result. @param strm Stream to read from. - @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ static int -dk4stream_i_c8_read_byte(char *dst, dk4_stream_t *strm, dk4_er_t *erp) +dk4stream_i_c8_read_byte(char *dst, dk4_stream_t *strm) { dk4_stream_api_t api; int back = 0; +#if DK4_USE_ASSERT + assert(NULL != strm); + assert(NULL != dst); +#endif $? "+ dk4stream_i_c8_read_byte" if ((0 == strm->feoi) && ((strm->usbi == 0) || (strm->rebi >= strm->usbi))) { $? ". low level read required" @@ -567,6 +601,10 @@ dk4stream_open( $? "+ dk4stream_open" /* Check arguments */ +#if DK4_USE_ASSERT + assert(NULL != obj); + assert(NULL != fct); +#endif if ((NULL == obj) || (NULL == fct)) { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); goto finished; @@ -592,7 +630,11 @@ dk4stream_open( back->usbi = 0; back->usbo = 0; back->rebi = 0; back->fl = fl; back->feoi = 0; back->bwo = 0; - back->oenc = DK4_FILE_ENCODING_ASCII; +#if DK4_ON_WINDOWS + back->oenc = DK4_FILE_ENCODING_WIN1252; +#else + back->oenc = DK4_FILE_ENCODING_PLAIN; +#endif back->zreof = 0; /* Allocate input buffer or destroy object */ @@ -638,6 +680,9 @@ dk4stream_close(dk4_stream_t *strm, dk4_er_t *erp) $? "+ dk4stream_close" /* Check argument. */ +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL == strm) { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); goto finished; @@ -649,7 +694,7 @@ dk4stream_close(dk4_stream_t *strm, dk4_er_t *erp) /* Write bytes in output buffer downwards. */ - if ((strm->fl) & DK4_STREAM_WRITE) { + if ((0 != ((strm->fl) & DK4_STREAM_WRITE)) && (0 < strm->usbo)) { dk4stream_api_init(&api); api.cmd = DK4_STREAM_API_WRITE; api.d = strm->d; @@ -657,7 +702,7 @@ dk4stream_close(dk4_stream_t *strm, dk4_er_t *erp) api.sz_in = strm->usbo; (*(strm->fct))(&api); if (0 == api.res) { - back = 0; + back = 0; $? "! final write failed" dk4error_set_simple_error_code(erp, DK4_E_WRITE_FAILED); } } @@ -670,7 +715,7 @@ dk4stream_close(dk4_stream_t *strm, dk4_er_t *erp) api.d = strm->d; (*(strm->fct))(&api); if (0 == api.res) { - back = 0; + back = 0; $? "! final flush failed" dk4error_set_simple_error_code(erp, DK4_E_FLUSH_FAILED); } } @@ -682,7 +727,7 @@ dk4stream_close(dk4_stream_t *strm, dk4_er_t *erp) api.d = strm->d; (*(strm->fct))(&api); if (0 == api.res) { - back = 0; + back = 0; $? "! close data failed" dk4error_set_simple_error_code(erp, DK4_E_CLOSE_FAILED); } @@ -702,6 +747,9 @@ dk4stream_write_byte(dk4_stream_t *strm, char c, dk4_er_t *erp) { int back = 0; $? "+ dk4stream_write_byte" +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL != strm) { if ((strm->fl) & DK4_STREAM_WRITE) { back = dk4stream_i_write_byte(strm, c, erp); @@ -724,6 +772,11 @@ dk4stream_write(dk4_stream_t *strm, const void *b, size_t sz, dk4_er_t *erp) char *cptr; /* Traverse buffer */ int back = 0; $? "+ dk4stream_write" +#if DK4_USE_ASSERT + assert(NULL != strm); + assert(NULL != b); + assert(0 < sz); +#endif if ((NULL != strm) && (NULL != b) && (0 < sz)) { if ((strm->fl) & DK4_STREAM_WRITE) { back = 1; @@ -753,6 +806,11 @@ dk4stream_write(dk4_stream_t *strm, const void *b, size_t sz, dk4_er_t *erp) int cc; $? "+ dk4stream_write %lu", (unsigned long)sz +#if DK4_USE_ASSERT + assert(NULL != strm); + assert(NULL != b); + assert(0 < sz); +#endif if ((NULL != strm) && (NULL != b) && (0 < sz)) { if ((strm->fl) & DK4_STREAM_WRITE) { back = 1; @@ -805,6 +863,10 @@ dk4stream_write_char_string(dk4_stream_t *strm, const char *str, dk4_er_t *erp) { size_t sl; int back = 0; +#if DK4_USE_ASSERT + assert(NULL != strm); + assert(NULL != str); +#endif if ((NULL != strm) && (NULL != str)) { sl = strlen(str); back = dk4stream_write(strm, str, sl, erp); @@ -822,6 +884,9 @@ dk4stream_flush_read(dk4_stream_t *strm, dk4_er_t *erp) { int back = 0; $? "+ dk4stream_flush_read" +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL != strm) { if ((strm->fl) & DK4_STREAM_READ) { back = 1; @@ -843,6 +908,9 @@ dk4stream_flush_write(dk4_stream_t *strm, int flfl, dk4_er_t *erp) { int back = 0; $? "+ dk4stream_flush_write" +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL != strm) { if ((strm->fl) & DK4_STREAM_WRITE) { back = dk4stream_i_flush_write(strm, flfl, erp); @@ -862,6 +930,9 @@ dk4stream_flush(dk4_stream_t *strm, int flfl, dk4_er_t *erp) { int back = 0; $? "+ dk4stream_flush" +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL != strm) { back = 1; if ((strm->fl) & DK4_STREAM_WRITE) { @@ -887,9 +958,13 @@ dk4stream_c8_read_byte(char *dst, dk4_stream_t *strm, dk4_er_t *erp) { int back = 0; $? "+ dk4stream_c8_read_byte" +#if DK4_USE_ASSERT + assert(NULL != strm); + assert(NULL != dst); +#endif if ((NULL != dst) && (NULL != strm)) { $? ". pointers ok" if ((strm->fl) & DK4_STREAM_READ) { $? ". read" - back = dk4stream_i_c8_read_byte(dst, strm, erp); + back = dk4stream_i_c8_read_byte(dst, strm); } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } @@ -910,12 +985,18 @@ dk4stream_read(void *b, size_t *szptr, dk4_stream_t *strm, dk4_er_t *erp) int back = 0; /* Function result */ int cc = 1; /* Flag: Can continue */ $? "+ dk4stream_read" +#if DK4_USE_ASSERT + assert(NULL != strm); + assert(NULL != b); + assert(NULL != szptr); + assert(0 < *szptr); +#endif if ((NULL != b) && (NULL != szptr) && (NULL != strm)) { if (((strm->fl) & DK4_STREAM_READ) && (0 < *szptr)) { szin = *szptr; szout = 0; cptr = (char *)b; do { - if (0 != dk4stream_i_c8_read_byte(cptr++, strm, erp)) { + if (0 != dk4stream_i_c8_read_byte(cptr++, strm)) { szout++; if (szout >= szin) { cc = 0; @@ -950,6 +1031,9 @@ dk4_um_t dk4stream_bytes_written(const dk4_stream_t *strm) { dk4_um_t back = (dk4_um_t)0UL; +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL != strm) { back = strm->bwr; } return back; } @@ -960,6 +1044,9 @@ int dk4stream_overflow_bytes_written(const dk4_stream_t *strm) { int back = 0; +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL != strm) { back = strm->bwo; } return back; } @@ -970,6 +1057,9 @@ int dk4stream_found_eof(const dk4_stream_t *strm) { int back = 0; +#if DK4_USE_ASSERT + assert(NULL != strm); +#endif if (NULL != strm) { back = strm->feoi; } |