File: tmate-env.c

package info (click to toggle)
tmate 2.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,560 kB
  • sloc: ansic: 38,233; awk: 339; makefile: 252; sh: 44; perl: 41
file content (36 lines) | stat: -rw-r--r-- 768 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "tmate.h"

struct tmate_env {
	TAILQ_ENTRY(tmate_env) entry;
	char *name;
	char *value;
};

TAILQ_HEAD(, tmate_env) tmate_env_list;

void tmate_set_env(const char *name, const char *value)
{
	struct tmate_env *tmate_env;

	TAILQ_FOREACH(tmate_env, &tmate_env_list, entry) {
		if (!strcmp(tmate_env->name, name)) {
			free(tmate_env->value);
			tmate_env->value = xstrdup(value);
			return;
		}
	}

	tmate_env = xmalloc(sizeof(*tmate_env));
	tmate_env->name = xstrdup(name);
	tmate_env->value = xstrdup(value);
	TAILQ_INSERT_HEAD(&tmate_env_list, tmate_env, entry);
}

void tmate_format(struct format_tree *ft)
{
	struct tmate_env *tmate_env;

	TAILQ_FOREACH(tmate_env, &tmate_env_list, entry) {
		format_add(ft, tmate_env->name, "%s", tmate_env->value);
	}
}