Files
gw-basic-2026/include/strings.h
Eremey Valetov d8e8375366 Phase 1: expression calculator with direct mode
GW-BASIC reimplementation in C11, using Microsoft's open-sourced 8088
assembly as the authoritative reference.

Tokenizer (CRUNCH/LIST), expression evaluator with operator precedence,
all math functions (SIN, COS, TAN, ATN, SQR, LOG, EXP, RND, etc.),
string functions (LEFT$, RIGHT$, MID$, CHR$, ASC, VAL, STR$, etc.),
PRINT statement with comma/semicolon zones, TAB(), SPC().

Handles integer/single/double types with correct promotion, D exponent
for double-precision literals, type suffixes (%, !, #), &H hex/&O octal
literals, MBF conversion routines, and GW-BASIC-compatible number
formatting.

Platform-independent via HAL vtable; POSIX backend included.
2026-02-10 10:25:08 -05:00

33 lines
987 B
C

#ifndef GW_STRINGS_H
#define GW_STRINGS_H
#include "types.h"
#include <stdint.h>
/* String creation/management */
gw_string_t gw_str_alloc(int len);
gw_string_t gw_str_from_cstr(const char *s);
gw_string_t gw_str_copy(gw_string_t *s);
void gw_str_free(gw_string_t *s);
char *gw_str_to_cstr(gw_string_t *s); /* caller must free */
/* String functions */
gw_value_t gw_fn_len(gw_value_t *s);
gw_value_t gw_fn_left(gw_value_t *s, int n);
gw_value_t gw_fn_right(gw_value_t *s, int n);
gw_value_t gw_fn_mid(gw_value_t *s, int start, int len);
gw_value_t gw_fn_chr(int code);
gw_value_t gw_fn_asc(gw_value_t *s);
gw_value_t gw_fn_val(gw_value_t *s);
gw_value_t gw_fn_str(gw_value_t *v);
gw_value_t gw_fn_space(int n);
gw_value_t gw_fn_strings(int n, int code);
gw_value_t gw_fn_instr(int start, gw_value_t *haystack, gw_value_t *needle);
gw_value_t gw_fn_hex(int16_t n);
gw_value_t gw_fn_oct(int16_t n);
/* Concatenation */
gw_value_t gw_str_concat(gw_value_t *a, gw_value_t *b);
#endif