Files
lotherkandClaude Sonnet 5.5 048e842776 MCDE dtlaunch: the panes of System Settings are results; dtsystemsettings -list-panes (t0185, first part)
dtsystemsettings -list-panes prints the panes (ID, name, category, keywords; a
PANE_LATER pane is left out) before any X setup.  dtlaunch asks for them once
(pipe and exec, no shell, a 3 s poll limit; no waitpid, SIGCHLD is ignored
there) and model.c parses and matches them: the name at full score, a keyword
at half, the ID checked because it ends up in dtsystemsettings -pane ID.  A
result reads '[settings] Displays (Hardware)' and starts through the same
Parental Controls as a program (run_args).  dtlaunch -text STRING fills the
field of the first opening, for tests and tools/mcde-shot.sh.

Measured: make mcde-linux 'check programs/dtlaunch programs/dtsystemsettings'
exit=0, test_model PASS (test_panes: parse incl. unsafe IDs, matching incl. a
German keyword); -list-panes: 24 lines, exit 0 with DISPLAY unset, no dock;
Spotlight-mcde.png: typing 'disp' lists '[settings] Displays (Hardware)'
second; Return on 'displays' starts 'dtsystemsettings -pane displays' and a
window 'Displays' appears (Xvfb).  Not done: the grouped two-column list,
documents/mail/PDF/web results, the dtbar magnifier, the clipboard without the
1 s poll (t0185, t0080).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 22:28:06 +00:00

77 lines
2.5 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);
/*
* The panes of System Settings, as `dtsystemsettings -list-panes' prints them:
* one a line, "ID<TAB>name<TAB>category<TAB>keywords" (keywords may be
* missing). ID is what `dtsystemsettings -pane ID' takes and ends up in an
* exec, so the text is not trusted: an ID of anything but letters, digits, '-'
* and '_' (at most 40), an empty name or category, or fewer than three fields
* skips the line. *out is malloc'd; free it with mx_panes_free.
*/
typedef struct {
char *id;
char *name;
char *category;
char *keywords;
} MxPane;
int mx_panes_parse(const char *text, MxPane **out, size_t *n);
void mx_panes_free(MxPane *p, size_t n);
/*
* How well QUERY matches a pane: its name as mx_match scores it, or a word of
* its keywords at half that. 0 for no match.
*/
int mx_pane_match(const char *query, const MxPane *p);
#endif /* DTLAUNCH_MODEL_H */