Files
mcde/programs/dtlaunch/model.h
T
lotherkandClaude Opus 5.5 07c3ce19f0 mcde: dtlaunch, the launcher: hot key, programs, snippets, clipboard history, calculator
programs/dtlaunch: Alt+space (Dtlaunch*hotkey) opens a field and a list;
matches programs in $PATH, ~/.dt/snippets (keyword TAB text), the
clipboard history (polled CLIPBOARD, 50 entries, memory only) and
calculations (=12*(3+4)).  Return starts the program or puts the text on
CLIPBOARD and PRIMARY.  One per display (_MCDE_DTLAUNCH); a second start
opens the first.  C99/POSIX + Xt/Motif, no warnings with -Wpedantic.
model.c (no X) with test_model.c: make check PASS.  Started in every
session by config/Xsession.d/0080.dtlaunch.  Tested on Xvfb: snippet and
result reach the clipboard (build/mcde-shots/dtlaunch-*.png).
tools/mcde-linux.sh: check mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:41:14 +00:00

54 lines
1.7 KiB
C

/*
* model.h -- dtlaunch without X: matching, the calculator, snippets, programs
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*
* 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 */