Here is an example of Peter's MID runtime function.
bacon.mid.c
#include "bacon.bac.generic.h"
char* __b2c__mid(char *__b2c__src, ...){ va_list __b2c__ap; long __b2c__start, __b2c__len, __b2c__l; if(__b2c__src == NULL) return("");
va_start(__b2c__ap, __b2c__src); __b2c__start = va_arg(__b2c__ap, long); if(__b2c__start < 1) return(__b2c__src); __b2c__l = strlen(__b2c__src); if(__b2c__start > __b2c__l) return(""); __b2c__len = va_arg(__b2c__ap, long);
if(__b2c__len < 0 || __b2c__start+__b2c__len > __b2c__l) __b2c__len = __b2c__l-__b2c__start+1; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= 256) __b2c__sbuffer_ptr=0; __b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)__sbuf_realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (__b2c__len+1)*sizeof(char));
memcpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__src+(__b2c__start-1)*sizeof(char), __b2c__len*sizeof(char)); __b2c__sbuffer[__b2c__sbuffer_ptr][__b2c__len] = '\0'; va_end(__b2c__ap); return (char*)(__b2c__sbuffer[__b2c__sbuffer_ptr]);}
Here is the C BASIC version of it. (cbrt_ = C BASIC Run Time) Veriadic Function
FUNCTION char PTR cbrt_mid(char PTR cbrt_src, ...)
BEGIN_FUNCTION
DIM AS va_list cbrt_ap;
DIM AS long cbrt_start, cbrt_len, cbrt_l;
IF (cbrt_src EQ NULL) THEN_DO RETURN_FUNCTION("");
va_start(cbrt_ap, cbrt_src);
cbrt_start = va_arg(cbrt_ap, long);
IF (cbrt_start < 1) THEN_DO RETURN_FUNCTION(cbrt_src);
cbrt_l = strlen(cbrt_src);
IF (cbrt_start > cbrt_l) THEN_DO RETURN_FUNCTION("");
cbrt_len = va_arg(cbrt_ap, long);
IF (cbrt_len < 0 OR cbrt_start + cbrt_len > cbrt_l) THEN_DO cbrt_len = cbrt_l - cbrt_start + 1;
INCR cbrt_sbuffer_ptr;
IF (cbrt_sbuffer_ptr >= 256) THEN_DO cbrt_sbuffer_ptr = 0;
cbrt_sbuffer[cbrt_sbuffer_ptr] = (char PTR)__sbuf_realloc(cbrt_sbuffer[cbrt_sbuffer_ptr], (cbrt_len + 1) * sizeof(char));
memcpy(cbrt_sbuffer[cbrt_sbuffer_ptr], cbrt_src + (cbrt_start - 1) * sizeof(char), cbrt_len * sizeof(char));
cbrt_sbuffer[cbrt_sbuffer_ptr][cbrt_len] = '\0';
va_end(cbrt_ap);
RETURN_FUNCTION (char PTR)(cbrt_sbuffer[cbrt_sbuffer_ptr]);
END_FUNCTION
I'm still undecided if I want to convert the BaCon run time library to C BASIC. The only advantage I see for a C BASIC mask is if a Windows version were in the plans.This would hopefully attract more contributors and make the code easier to read. My plan at the moment is to test of few of the BaCon run time function as #define {function} definitions in cbasic.h using the .o library functions.