Next: Complete Example (I), Previous: Freeing Allocated Resources (I), Up: Imperative Language Interpreter Usage Outline
The functions set below provides four utilities, one for character output (`obyte'), one for integer output (`omode'), one for real output (`oreal') and one for text output (`otext').
#define I_MODE(i) (*((X1f4_E4_C_MODE *) (i))) #define I_REAL(r) (*((X1f4_E4_C_REAL *) (r))) #define I_TEXT(r) (*((X1f4_E4_C_TEXT *) (r))) static int obyte(void *, void *, void **); static int omode(void *, void *, void **); static int oreal(void *, void *, void **); static int otext(void *, void *, void **); static const int c_____m__[] = { /* *INDENT-OFF* */ X1f4_E4_MODE /* *INDENT-ON* */ }, c_____r__[] = { /* *INDENT-OFF* */ X1f4_E4_REAL /* *INDENT-ON* */ }, c_____t__[] = { /* *INDENT-OFF* */ X1f4_E4_TEXT /* *INDENT-ON* */ }; const struct x1f4_function_type simple_output[] = { /* *INDENT-OFF* */ { "obyte", obyte, X1f4_E4_VOID, c_____m__, 1, X1f4_E4_KEEP_CALL, 5 }, { "omode", omode, X1f4_E4_VOID, c_____m__, 1, X1f4_E4_KEEP_CALL, 5 }, { "oreal", oreal, X1f4_E4_VOID, c_____r__, 1, X1f4_E4_KEEP_CALL, 5 }, { "otext", otext, X1f4_E4_VOID, c_____t__, 1, X1f4_E4_KEEP_CALL, 5 }, { NULL, NULL, 0, NULL, 0, 0, 1 } /* *INDENT-ON* */ }; static int obyte(void *context, void *output, void **input) { fputc(I_MODE(input[0]), stdout); return 0; } static int omode(void *context, void *output, void **input) { x1f4_fprint_lintegral(stdout, 0, 10, I_MODE(input[0])); return 0; } static int oreal(void *context, void *output, void **input) { x1f4_fprint_wfloat(stdout, 0, 0, 6, I_REAL(input[0])); return 0; } static int otext(void *context, void *output, void **input) { fputs(I_TEXT(input[0]), stdout); return 0; }
The omode
and oreal
functions may be implemented alternatively
as:
static int omode(void *context, void *output, void **input) { printf("%d", (int) I_MODE(input[0])); return 0; }
and:
static int oreal(void *context, void *output, void **input) { printf("%f", I_REAL(input[0])); return 0; }