ref: a0d30aba763788d63e47878756cbd4e5cc6f6798
dir: /sym.c/
#include <u.h> #include <libc.h> #include "sym.h" Symbol* syms = nil; uint id; Symbol* symfind(char *name) { Symbol *s; if (!syms) { syms = malloc(sizeof(Symbol)); syms->name = name; syms->next = nil; syms->id = id = 0; return syms; } s = syms; while (s) { if (strcmp(s->name, name) == 0) { return s; } if (!s->next) { s->next = malloc(sizeof(Symbol)); s = s->next; s->next = nil; s->name = name; s->id = ++id; return s; } s = s->next; } return nil; } void printsyms() { Symbol *s; for (s = syms; s; s = s->next) { print("symbol: %s (%d)\n", s->name, s->id); } }