Skip to content
suit Artifact [37448708f8]
Login

Artifact [37448708f8]

Artifact 37448708f89867bf8cb2ee5e40031eb1c513f8857f53788c34eff5fa5afcf01e:


#ifndef SUIT_CURATE_H
#define SUIT_CURATE_H

#include <stddef.h>
#include <stdint.h>

// `suit curate` (docs/curate.md): one self-contained HTML page that shows every
// skill, agent and command of the wardrobes beside how it is used, and a text
// file of the choices made on it. It changes nothing else.

constexpr uint32_t CURATE_ASSETS_MAX = 4096;    // assets on a page
constexpr uint32_t CURATE_PROJECTS_MAX = 64;    // projects listed for one asset; the rest are summed
constexpr uint32_t CURATE_TOP = 10;             // names used that match no asset, listed
constexpr size_t CURATE_HEAD_MAX = 16384;       // bytes of a file read for its description
constexpr size_t CURATE_DESC_KEEP = 300;        // bytes of a description kept
constexpr uint32_t CURATE_FILES_MAX = 4096;     // files of one asset counted for its size
constexpr int CURATE_DEPTH_MAX = 16;            // folders nested in one asset counted for its size
constexpr size_t CURATE_PAGE_MAX = 16777216;    // bytes of the page
constexpr uint32_t CURATE_RECS_MAX = 600000;    // (asset, project) uses and unmatched uses held at once

// `suit curate [--since DAYS] [--out FILE]`. ARGV is what follows "curate".
// 0; 1 after a message (a file cannot be read or written, a bound is passed);
// 2 for bad arguments or a config that cannot be used; EXIT_BUSY.
int cmd_curate(int argc, char **argv);

// ---- for the tests ----------------------------------------------------------

// The `description` of the front matter in the first LEN bytes of a file, whitespace
// collapsed, into OUT (room for LEN + 1 bytes), and its length: 0 when there is no
// front matter (a first line "---" and a later one) or no description.
size_t curate_front_description(const char *data, size_t len, char *out);

// The length of the first MAX bytes of S (LEN bytes) cut so as not to split a UTF-8 character.
size_t curate_cut(const char *s, size_t len, size_t max);

// A bounded buffer. OVER is set when something did not fit; nothing is then added.
typedef struct {
    char *p;
    size_t cap;
    size_t len;
    bool over;
} CurateBuf;

// Append the N bytes of S to B, or set OVER if they do not fit.
void curate_put(CurateBuf *b, const char *s, size_t n);

// Append the LEN bytes of S as a JSON string, quotes included, in which every
// "<", ">", "&", U+2028 and U+2029 is a \u escape and every byte that is not
// UTF-8 is U+FFFD.
void curate_json_string(CurateBuf *b, const char *s, size_t len);

// Call CB for the index of each of the N names (sorted, byte order) that the
// usage name USAGE (LEN bytes) is an invocation of: it is equal to the name, or
// ends with a colon and the name. Returns how many.
uint32_t curate_matches(const char *const *names, uint32_t n, const char *usage, size_t len,
    void (*cb)(void *state, uint32_t index), void *state);

// The times, as "YYYY-MM-DDTHH:MM:SS", from which a use counts: in the window of
// DAYS, in the last 90 days, and in each of the last four 7-day periods before NOW.
typedef struct {
    char window[20];
    char d90[20];
    char week[4][20];
} CurateCuts;

void curate_cuts(int64_t now, int days, CurateCuts *c);
// The period of the time T (at least TALLY_TIME_LEN bytes): 0 the oldest to 3 the
// newest, -1 when it is older than 28 days.
int curate_week(const CurateCuts *c, const char *t);

#endif