Skip to content
suit Documentation
Login

Documentation

#ifndef SUIT_ATTENTION_H
#define SUIT_ATTENTION_H

#include <stdbool.h>
#include <stddef.h>

// $SUIT_HOME/attention: what needs the user. An item is a line, "KIND NAME"
// or "KIND NAME: what", and the lines indented by two spaces after it, which
// belong to it. The file is written beside, synced and renamed, and is removed
// when it would be empty. Each returns 0, or 1 after saying what failed.

constexpr size_t ATTENTION_FILE_MAX = 131072;

// Take out the items of NAME, of kind KIND (every kind if null). Writes
// nothing when there is none.
int attention_remove(const char *path, const char *kind, const char *name);

// Replace the item KIND NAME with HEADER and DETAILS: lines, each ending in a
// newline, kept under it indented (null for none). Writes nothing when the
// file would not change.
int attention_add(const char *path, const char *kind, const char *name, const char *header, const char *details);

// Make the items of kind KIND be exactly the N given: HEADERS[i] (a line with
// no newline) under NAMES[i]. An item already there with its header as given
// stays where it is; one that is not wanted, or whose header differs, is
// taken out; one missing is added at the end. Items of other kinds are not
// touched. Writes nothing when the file would not change, and removes it when
// it would be empty. N is at most ATTENTION_SYNC_MAX.
constexpr size_t ATTENTION_SYNC_MAX = 256;
int attention_sync(const char *path, const char *kind, size_t n, const char *const *names, const char *const *headers);

// Print "needs you:" and the file's lines, or nothing when there are none.
int attention_print(const char *path);

// How many items the file holds: its lines that are not indented. 0 in *COUNT
// when it is not there. Returns 0, or 1 after saying what failed.
int attention_count(const char *path, unsigned *count);

// Whether the item KIND NAME is in the file: false in *HAS when it is not
// there. Returns 0, or 1 after saying what failed.
int attention_has(const char *path, const char *kind, const char *name, bool *has);

#endif