LICENSE at the root; the 103 files new in ext/src/mcde (none was in the CDE import) carry the CNCL line instead of the LGPL notice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
54 lines
1.7 KiB
C
54 lines
1.7 KiB
C
/*
|
|
* model.h -- dtlaunch without X: matching, the calculator, snippets, programs
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* C99 and POSIX only (ext/src/mcde/AGENTS.md); tested by test_model.c.
|
|
*/
|
|
|
|
#ifndef DTLAUNCH_MODEL_H
|
|
#define DTLAUNCH_MODEL_H
|
|
|
|
#include <stddef.h>
|
|
|
|
/*
|
|
* How well QUERY matches TEXT, case-insensitively: 0 for no match, otherwise
|
|
* a score that is higher for a match at the start, for a match at the start
|
|
* of a word, and for letters that follow each other. Every letter of QUERY
|
|
* must appear in TEXT in this order.
|
|
*/
|
|
int mx_match(const char *query, const char *text);
|
|
|
|
/*
|
|
* Evaluate an arithmetic expression: numbers, + - * / % ^, parentheses,
|
|
* unary minus. A leading '=' is ignored. Returns 0 and sets *out, or -1
|
|
* if the text is not an expression (or divides by zero).
|
|
*/
|
|
int mx_calc(const char *expr, double *out);
|
|
/* format a result the way a person writes it: no trailing zeros */
|
|
void mx_calc_format(double v, char *buf, size_t len);
|
|
|
|
/*
|
|
* Snippets: a text file, one snippet a line, "keyword<TAB>text"; in the text
|
|
* \n is a newline, \t a tab and \\ a backslash. Lines starting with '#' and
|
|
* lines without a tab are skipped.
|
|
*/
|
|
typedef struct {
|
|
char *key;
|
|
char *text;
|
|
} MxSnippet;
|
|
|
|
int mx_snippets_load(const char *path, MxSnippet **out, size_t *n);
|
|
void mx_snippets_free(MxSnippet *s, size_t n);
|
|
/* the escapes above, decoded; the result is malloc'd */
|
|
char *mx_unescape(const char *s);
|
|
|
|
/*
|
|
* The programs in $PATH (executable regular files), sorted, without
|
|
* duplicates. Returns 0; *out is a malloc'd array of malloc'd names.
|
|
*/
|
|
int mx_path_programs(const char *path, char ***out, size_t *n);
|
|
void mx_strv_free(char **v, size_t n);
|
|
|
|
#endif /* DTLAUNCH_MODEL_H */
|