Files
kryon/include/kry_eval.h
T
waozi cce4b2fe77 Add spreadsheet string-literal and error-name scanners to kry_eval
eval_parse_string_literal: gnumeric-compatible lexer for quoted string
literals (doubled quotes and backslash escapes, which drop the
backslash and keep the next character verbatim).

eval_scan_error_name: recognizes the eight spreadsheet error names
(#DIV/0! .. #CYCLE!) and returns a canonical index.
2026-09-06 11:36:36 -03:00

51 lines
2.0 KiB
C

#ifndef KRY_EVAL_H
#define KRY_EVAL_H
/*
* kry_eval.h: spreadsheet-style evaluation primitives shared by
* formula engines — gnumeric-compatible cell addressing and the
* ulp-grace rounding family (fake floor/round/trunc/ceil and the
* nextafter-style epsilon nudges).
*
* Plain C99 on libm only.
*/
/* Column index to A1 letters: 0 -> "A", 25 -> "Z", 26 -> "AA". Writes a
* NUL-terminated string to out (at least 8 bytes) and returns its length. */
int eval_col_name (int col, char *out);
/* Whether a sheet name needs 'quoting' in a reference. */
int eval_sheet_name_needs_quote (const char *name);
/* Emit the sheet prefix including the trailing separator: name! or
* 'name'! (empty name yields just "!"). Returns bytes written. */
int eval_sheet_prefix (const char *name, char *out);
/* The gnumeric-compatible ulp-grace rounding family: these treat values
* within one ulp of an integer as that integer. */
double eval_fake_floor (double x);
double eval_fake_round (double x);
double eval_fake_trunc (double x);
double eval_fake_ceil (double x);
/* One-ulp nudges away from/toward zero (nextafter equivalents built on
* frexp/ldexp so no C99 nextafter dependency is needed). */
double eval_add_epsilon (double x);
double eval_sub_epsilon (double x);
/* Scan a gnumeric-compatible string literal starting at text[*pos]
* (which must point at the opening quote). Doubled quotes yield one
* quote and a backslash escapes the next character (itself dropped);
* anything else is copied verbatim. Writes a NUL-terminated value to
* out and advances pos past the closing quote. Returns 1 on success,
* 0 on an unterminated literal or missing opening quote. */
int eval_parse_string_literal (const char *text, int *pos, char *out, int cap);
/* If text[*pos] starts a spreadsheet error name (#DIV/0!, #VALUE!,
* #REF!, #NAME?, #NUM!, #N/A, #NULL!, #CYCLE!), advance pos past it
* and return its index 0..7 in that order. Returns -1 otherwise with
* pos untouched. */
int eval_scan_error_name (const char *text, int *pos);
#endif /* KRY_EVAL_H */