/* $Id: parsebuf.c,v 1.18 2004/04/03 04:17:37 jmuelmen Exp $ */ #include #include #include "shell.h" #include "scheduler.h" #include "act.h" #include "buf.h" /* parsebuf is a buffer that buffers the results of parsing an input * stream. If the parser encounters an error in the middle of a * stream, it can simply clear the buffer; this is a lot less messy * than trying to clean the effects of the half-parsed stream out of * the scheduler. */ static buf_t parsebuf; static int _saved_pos; /* parsebuf_buf buffers an action; the return value is the index of the * action in the buffer */ int parsebuf_buf (parse_action_t *a) { return buf_buf(&parsebuf, a); } /* parsebuf_clear discards all the actions that have been buffered */ int parsebuf_clear () { return buf_clear(&parsebuf); } /* process the buffered actions */ int parsebuf_process () { static parse_action_t **i = NULL; pthread_mutex_lock(&parsebuf.mut); if (!i) i = parsebuf.actions; if (i < parsebuf.actions + parsebuf.n_actions) { buf_process_segment(&parsebuf, &i, parsebuf.actions[parsebuf.n_actions - 1], 0); ++i; } pthread_mutex_unlock(&parsebuf.mut); return 0; } /* get a parse action out of the buffer by index */ parse_action_t *parsebuf_get_idx (int i) { return buf_get_idx(&parsebuf, i); } void parsebuf_dump () { printf("Parse buffer:\n"); buf_dump(&parsebuf); } void parsebuf_init () { buf_init(&parsebuf); } void parsebuf_save_pos () { _saved_pos = parsebuf.n_actions; } void parsebuf_clear_after_pos () { buf_clear_from_idx(&parsebuf, _saved_pos); }