int match_bracket(buffer *b) { int64_t match_line, match_pos; const int rc = find_matching_bracket(b, 0, b->num_lines-1, &match_line, &match_pos, NULL, NULL); if (rc == OK) { goto_line_pos(b, match_line, match_pos); return OK; } return rc; }
void run(char *program) { char *p; char mem[MEMORY_SIZE]; char *m; char c; // set cells to zero bzero(mem, sizeof(mem)); // instruction pointer p = program; // memory pointer m = mem; // current instruction c = *p; // Reads to end of string. while( c != '\0' ) { switch(c) { case '>': m++; break; case '<': m--; break; case '+': (*m)++; break; case '-': (*m)--; break; case '.': fputc(*m, stdout); break; case ',': (*m) = getc(stdin); break; case '[': if( (*m) == 0 ) { p = find_matching_bracket(p, '['); } break; case ']': if( (*m) != 0 ) { p = find_matching_bracket(p, ']'); } break; default: break; } // move instruction pointer forward c = *(++p); } }