typedef struct s_node
{
+ size_t id;
int checked;
t_state state;
t_state set_state;
int get_input(t_input *input);
const char *state_color_escape(t_state state);
-void draw_single(t_vec *nodes, t_vec *mosfets, size_t i);
+void draw_single(t_vec *mosfets, size_t i);
void update_nodes(t_vec *nodes);
int sim_step(t_vec *nodes, t_vec *mosfets);
int c_addfet(t_input input, t_vec *mosfets);
int c_addnode(t_input input, t_vec *nodes);
int c_bind(t_input input, t_vec *nodes, t_vec *mosfets);
-int c_draw(t_input input, t_vec *nodes, t_vec *mosfets);
+int c_draw(t_input input, t_vec *mosfets);
int c_help(t_input input);
int c_next(t_input input, t_vec *nodes, t_vec *mosfets);
int c_setnode(t_input input, t_vec *nodes);
t_node node;
ft_memset(&node, 0, sizeof(node));
+ node.id = nodes->size;
node.checked = 0;
node.state = set_state;
node.set_state = set_state;
#include "FET_sim.h"
#include "libft.h"
-int c_draw(t_input input, t_vec *nodes, t_vec *mosfets)
+int c_draw(t_input input, t_vec *mosfets)
{
size_t i;
i = 0;
while (i < mosfets->size)
{
- draw_single(nodes, mosfets, i);
+ draw_single(mosfets, i);
++i;
}
}
else if (input.argc == 1 && input.argv[0].type == num)
{
- draw_single(nodes, mosfets, input.argv[0].val.num);
+ draw_single(mosfets, input.argv[0].val.num);
}
/*else
{
return (g_red_ac);
}
-void draw_single(t_vec *nodes, t_vec *mosfets, size_t i)
+void draw_single(t_vec *mosfets, size_t i)
{
t_mosfet *mosfet;
- size_t index;
mosfet = ft_vec_access(mosfets, i);
- if (ft_vec_find_index(nodes, mosfet->source, &index) == success)
+ if (mosfet->source)
{
- ft_printf(" %u\n", index);
+ ft_printf(" %u\n", mosfet->source->id);
ft_printf(" %s|%s\n", state_color_escape(mosfet->source->state), g_default_ac);
}
else
ft_printf(" %sNULL%s\n", g_red_ac, g_default_ac);
ft_printf(" %s|%s\n", g_red_ac, g_default_ac);
}
- if (ft_vec_find_index(nodes, mosfet->gate, &index) == success)
- ft_printf("%4u%s--%s%c\n", index, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type);
+ if (mosfet->gate)
+ ft_printf("%4u%s--%s%c\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type);
else
ft_printf("%sNULL--%s%c\n", g_red_ac, g_default_ac, mosfet->type);
- if (ft_vec_find_index(nodes, mosfet->drain, &index) == success)
+ if (mosfet->drain)
{
ft_printf(" %s|%s\n", state_color_escape(mosfet->drain->state), g_default_ac);
- ft_printf(" %u\n\n", index);
+ ft_printf(" %u\n\n", mosfet->drain->id);
}
else
{
if (input.command == next)
res = c_next(input, nodes, mosfets);
else if (input.command == draw)
- res = c_draw(input, nodes, mosfets);
+ res = c_draw(input, mosfets);
else if (input.command == setnode)
res = c_setnode(input, nodes);
else if (input.command == addnode)