shithub: blie

ref: a3477b9d29227db6e78cede76fdd9d6b83f5ea76
dir: /editor.c/

View raw version
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <event.h>
#include "blie.h"

void
loadeditors(void)
{
	addeditor(&p9image);
}

typedef struct Leditor Leditor;
struct Leditor {
	Editor *editor;
	Leditor *next;
};

Leditor *firsteditor = nil;

int
addeditor(Editor *ed)
{
	Leditor *l;
	if (geteditor(ed->name)) {
		werrstr("editor already registered: %s", ed->name);
		return 0;
	}
	if (!firsteditor) {
		firsteditor = mallocz(sizeof(Leditor), 1);
		firsteditor->editor = ed;
		if (ed->init)
			ed->init();
		return 1;
	}
	for (l = firsteditor; l->next; l = l->next)
		continue;
	l->next = mallocz(sizeof(Leditor), 1);
	l = l->next;
	l->editor = ed;
	if (ed->init)
		ed->init();
	return 1;
}

Editor*
geteditor(char *name)
{
	Leditor *l;
	for (l = firsteditor; l; l = l->next) {
		if (cistrcmp(name, l->editor->name) == 0)
			return l->editor;
	}
	return nil;
}