<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "uapi/mosaic.h"

/*
 * FIXME -- below is not the part of UAPI
 */
#include "mosaic.h"
#include "tessera.h"
#include "status.h"

static inline int argv_is(char *argv, char *is)
{
	while (1) {
		if (*argv == '\0')
			return 1;
		if (*is == '\0')
			return 0;
		if (*is != *argv)
			return 0;

		is++;
		argv++;
	}
}

static void usage(void)
{
	printf(
"Usage: moctl <object> <action> [<options>]\n"
"\n"
" * Objects:\n"
"    m|mosaic\n"
"    t|tessera\n"
"\n"
" * Actions:\n"
"   Common:\n"
"    l|list\n"
"    s|show    <name>\n"
"\n"
"   Mosaic:\n"
"    a|add     <name> [<elements>]\n"
"    d|del     <name>\n"
"    c|change  <name> [<elements>]\n"
"    m|mount   <name> <location> [<mount-options>]\n"
"\n"
"     Element: <name>:<age>:<location>[:options=<mount-options>]\n"
"              for \"change\" <name>:del to remove\n"
"\n"
"   Tessera:\n"
"    a|add     <name> <type> [<type-options>]\n"
"    d|del     <name>\n"
"    m|mount   <name>:<age> <location> [<mount-options>]\n"
"    g|grow    <name> <new-age>[:<base-age>]\n"
);
}

/*
 * Mosaic CLI
 */

static int print_mosaic(struct mosaic *m, void *x)
{
	printf("%s\n", m->m_name);
	return 0;
}

static int list_mosaics(void)
{
	return mosaic_iterate(print_mosaic, NULL);
}

static int print_element(struct mosaic *m, struct element *e, void *x)
{
	printf("  - name: %s\n", e->t->t_name);
	if (e->e_age == 0)
		printf("    age:     base\n");
	else
		printf("    age:     %d\n", e->e_age);
	printf("    at:      %s\n", e->e_at ? : "-");
	printf("    options: %s\n", e->e_options ? : "none");
	printf("\n");

	return 0;
}

static int show_mosaic(int argc, char **argv)
{
	struct mosaic *m;

	if (argc < 1) {
		printf("Usage: moctl mosaic show <name>\n");
		return 1;
	}

	m = mosaic_find_by_name(argv[0]);
	if (!m) {
		printf("No such mosaic %s\n", argv[0]);
		return 1;
	}

	st_show_mounted(m);

	if (!list_empty(&m->elements))
		printf("elements:\n");

	return mosaic_iterate_elements(m, print_element, NULL);
}

static int set_elements(struct mosaic *m, int argc, char **argv)
{
	int i;

	for (i = 0; i < argc; i++) {
		int age;
		char *at, *ed, *aux;

		/* Name */
		aux = strchr(argv[1], ':');
		if (!aux)
			goto err;

		*aux = '\0';

		/* Age */
		ed = aux + 1;

		if (!strcmp(ed, "del")) {
			if (mosaic_del_element(m, argv[1]))
				return 1;

			continue;
		}

		aux = strchr(ed, ':');
		if (!aux)<commit_msg>Fix elements parse<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "uapi/mosaic.h"

/*
 * FIXME -- below is not the part of UAPI
 */
#include "mosaic.h"
#include "tessera.h"
#include "status.h"

static inline int argv_is(char *argv, char *is)
{
	while (1) {
		if (*argv == '\0')
			return 1;
		if (*is == '\0')
			return 0;
		if (*is != *argv)
			return 0;

		is++;
		argv++;
	}
}

static void usage(void)
{
	printf(
"Usage: moctl <object> <action> [<options>]\n"
"\n"
" * Objects:\n"
"    m|mosaic\n"
"    t|tessera\n"
"\n"
" * Actions:\n"
"   Common:\n"
"    l|list\n"
"    s|show    <name>\n"
"\n"
"   Mosaic:\n"
"    a|add     <name> [<elements>]\n"
"    d|del     <name>\n"
"    c|change  <name> [<elements>]\n"
"    m|mount   <name> <location> [<mount-options>]\n"
"\n"
"     Element: <name>:<age>:<location>[:options=<mount-options>]\n"
"              for \"change\" <name>:del to remove\n"
"\n"
"   Tessera:\n"
"    a|add     <name> <type> [<type-options>]\n"
"    d|del     <name>\n"
"    m|mount   <name>:<age> <location> [<mount-options>]\n"
"    g|grow    <name> <new-age>[:<base-age>]\n"
);
}

/*
 * Mosaic CLI
 */

static int print_mosaic(struct mosaic *m, void *x)
{
	printf("%s\n", m->m_name);
	return 0;
}

static int list_mosaics(void)
{
	return mosaic_iterate(print_mosaic, NULL);
}

static int print_element(struct mosaic *m, struct element *e, void *x)
{
	printf("  - name: %s\n", e->t->t_name);
	if (e->e_age == 0)
		printf("    age:     base\n");
	else
		printf("    age:     %d\n", e->e_age);
	printf("    at:      %s\n", e->e_at ? : "-");
	printf("    options: %s\n", e->e_options ? : "none");
	printf("\n");

	return 0;
}

static int show_mosaic(int argc, char **argv)
{
	struct mosaic *m;

	if (argc < 1) {
		printf("Usage: moctl mosaic show <name>\n");
		return 1;
	}

	m = mosaic_find_by_name(argv[0]);
	if (!m) {
		printf("No such mosaic %s\n", argv[0]);
		return 1;
	}

	st_show_mounted(m);

	if (!list_empty(&m->elements))
		printf("elements:\n");

	return mosaic_iterate_elements(m, print_element, NULL);
}

static int set_elements(struct mosaic *m, int argc, char **argv)
{
	int i;

	for (i = 0; i < argc; i++) {
		int age;
		char *at, *ed, *aux;

		/* Name */
		aux = strchr(argv[i], ':');
		if (!aux)
			goto err;

		*aux = '\0';

		/* Age */
		ed = aux + 1;

		if (!strcmp(ed, "del")) {
			if (mosaic_del_element(m, argv[i]))
				return 1;

			continue;
		}

		aux = strchr(ed, ':');
		if (!aux)
{'fraction_non_alphanumeric': 0.22091370558375634, 'fraction_numerical': 0.007715736040609137, 'mean_word_length': 2.9064234734337826, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5233221', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2087, 'n_words': 495}