void bif_parse(struct Runtime *rt, VAL_LOC_T arg_loc) { VAL_LOC_T size_loc, data_begin, result_begin, data_size; char *string; if (!rt_val_is_string(rt, arg_loc)) { bif_text_error_arg(1, "parse", "must be a string"); return; } rt_val_push_tuple_init(&rt->stack, &size_loc); data_begin = rt->stack.top; rt_val_push_bool(&rt->stack, true); result_begin = rt->stack.top; string = rt_val_peek_cpd_as_string(rt, arg_loc); bif_parse_any(rt, string); mem_free(string); if (err_state()) { char *message = err_msg(); /* NOTE: the error here is intentionally sweeped under the carpet. */ stack_collapse(&rt->stack, result_begin, rt->stack.top); rt_val_poke_bool(&rt->stack, data_begin, false); rt_val_push_string(&rt->stack, message, message + strlen(message)); err_reset(); mem_free(message); } data_size = rt->stack.top - data_begin; rt_val_push_cpd_final(&rt->stack, size_loc, data_size); }
VAL_LOC_T eval( struct AstNode *node, struct Runtime *rt, struct SymMap *sym_map, struct AstLocMap *alm) { VAL_LOC_T begin, result, end; #if LOG_LEVEL <= LLVL_TRACE char *node_string = ast_serialize(node); LOG_TRACE("eval BEGIN(%s)", node_string); mem_free(node_string); #endif err_reset(); /* The dispatch is delegated to another procedure as it is called * recursively during the evaluation while the current function is only * called by the top-level client. */ begin = rt->stack.top; result = eval_dispatch(node, rt, sym_map, alm); end = rt->stack.top; if (err_state()) { stack_collapse(&rt->stack, begin, end); LOG_TRACE("eval END(error)"); return -1; } else { LOG_TRACE("eval END(result=%td)", result); return result; } }
bool parse_line(char *line) { struct AstNode *node; int len = strlen(line); err_reset(); node = parse_source(line, NULL, NULL); if (!node) { ++unexpected_fails; return false; } if (!rt_consume_list(rt, node, NULL, &last_loc)) { ++unexpected_fails; return false; } mem_free(last_expression); last_expression = mem_malloc(len - 1); memcpy(last_expression, line, len - 2); last_expression[len - 2] = '\0'; return true; }
static void exitflush () { if (_err_output != _err_output_async) { err_flush (); err_reset (); } }
BT_TEST_FIXTURE(pathman, border, pathman_test_setup, pathman_test_teardown, object) { struct pathman_test * test = object; e_pdir_t dlup; e_pfile_t flup; dlup = pathman_add_dir(test->pman, "/a", 0); bt_chkerr(dlup.err); bt_assert_ptr_not_equal(dlup.dir, NULL); flup = pathman_add_file(test->pman, dlup.dir, "foo/bar", 0); bt_assert(flup.err); err_reset(); return BT_RESULT_OK; }
static void err_wcb () { int n; int cnt; if (!erruio->resid () || _err_output != _err_output_async) { fdcb (errfd, selwrite, NULL); return; } /* Try to write whole lines at a time. */ for (cnt = min (erruio->iovcnt (), (size_t) UIO_MAXIOV); cnt > 0 && (erruio->iov ()[cnt-1].iov_len == 0 || *((char *) erruio->iov ()[cnt-1].iov_base + erruio->iov ()[cnt-1].iov_len - 1) != '\n'); cnt--) ; if (!cnt) { if (erruio->iovcnt () < UIO_MAXIOV) { /* Wait for a carriage return */ fdcb (errfd, selwrite, NULL); return; } else cnt = -1; } /* Write asynchronously, but keep stderr synchronous in case of * emergency (e.g. maybe assert wants to fprintf to stderr). */ if (globaldestruction) n = erruio->output (errfd, cnt); else { _make_async (errfd); n = erruio->output (errfd, cnt); make_sync (errfd); } if (n < 0) err_reset (); if (erruio->resid () && !globaldestruction) fdcb (errfd, selwrite, wrap (err_wcb)); else fdcb (errfd, selwrite, NULL); }
int main(void) { struct termios new_flags, old_flags; int i, fd; char c; /* Set up a signal handler */ if(signal(SIGINT, sig_caught) == SIG_ERR) { err_quit("Failed to set up SIGINT handler"); } if(signal(SIGQUIT, sig_caught) == SIG_ERR) { err_quit("Failed to set up SIGQUIT handler"); } if(signal(SIGTERM, sig_caught) == SIG_ERR) { err_quit("Failed to set up SIGTERM handler"); } fd = fileno(stdin); /* Set up raw/non-canonical mode */ tcgetattr(fd, &old_flags); new_flags = old_flags; new_flags.c_lflag &= ~(ECHO | ICANON | ISIG); new_flags.c_iflag &= ~(BRKINT | ICRNL); new_flags.c_oflag &= ~OPOST; new_flags.c_cc[VTIME] = 0; new_flags.c_cc[VMIN] = 1; if(tcsetattr(fd, TCSAFLUSH, &new_flags) < 0) err_reset("Failed to change attributes", &old_flags); /* Process keystrokes until DELETE key is pressed */ puts("In RAW mode. Press DELETE key to exit"); while((i = read(fd, &c, 1)) == 1) { if((c &= 255) == 0177) { break; } printf("%o\n", c); } /* Restore original terminal attributes */ tcsetattr(fd, TCSANOW, &old_flags); exit(EXIT_SUCCESS); }
void *utf_convert(heap_t h, void *src, int src_enc, int dest_enc) { void *res; void *i; int len; if(!src) return 0; err_reset(); len = utf_length(src, src_enc) + 1; i = res = heap_alloc(h, len*4); if(err()) return 0; while(!CHAR_IS_LAST(src, src_enc)) { long c = CHAR_TO_LONG(src, src_enc); src = C_OFFSET(src, CHAR_LEN(src, src_enc)); i = LONG_TO_UTF(c, i, dest_enc); } i = UTF_WRITE4(i, 0, 0, 0, 0); return res; }
int main(void) { struct termios new_flags, old_flags; int i, fd; char c; if(signal(SIGINT, sig_caught) == SIG_ERR){ err_quit("failed to set up SIGINT handler"); } if(signal(SIGQUIT, sig_caught) == SIG_ERR){ err_quit("Failed to set up SIGQUIT handler"); } if(signal(SIGTERM, sig_caught) == SIG_ERR){ err_quit("Failed to set up SIGQUIT handler"); } fd = fileno(stdin); tcgetattr(fd, &old_flags); new_flags = old_flags; new_flags.c_lflag &= ~(ECHO | ICANON | ISIG); new_flags.c_iflag &= ~(BRKINT | ICRNL); new_flags.c_oflag &= ~OPOST; new_flags.c_cc[VTIME] = 0; new_flags.c_cc[VMIN] = 1; if(tcsetattr(fd, TCSAFLUSH, &new_flags) < 0) err_reset("Failed to change attributes", &old_flags); puts("In RAW mode , Press DELETE key to exit"); while((i = read(fd, &c, 1)) == 1){ if((c &= 255) == 0177){ break; } printf("%o\n",c); } tcsetattr(fd, TCSANOW, &old_flags); }
pid_t afork () { if (pid_t pid = fork ()) return pid; fatal_no_destruct = true; err_reset (); /* If we close/dup2 stderr before an exec, but the exec fails, we * still want warn/fatal to work so as to report the error. */ if (errfd == 2) { int fd = dup (errfd); if (fd < 3) close (fd); else { close_on_exec (fd); errfd = fd; } } /* If we exec, we want the child to get SIGPIPEs again. The signal * mask and SIG_IGN signals are preserved by execve, but not * handlers for specific functions. Thus we change the handler from * the probably more efficient SIG_IGN to an empty function. */ struct sigaction sa; bzero (&sa, sizeof (sa)); sa.sa_handler = nop; sigaction (SIGPIPE, &sa, NULL); #ifdef MAINTAINER if (afork_debug) { warn ("AFORK_DEBUG: child process pid %d\n", getpid ()); sleep (7); } #endif /* MAINTAINER */ return 0; }
static struct AstNode *parse_one( struct DomNode *dom, struct ParserState *state) { err_reset(); struct AstNode *node; if ((!err_state() && (node = parse_literal_atomic(dom, state))) || (!err_state() && (node = parse_symbol(dom, state))) || (!err_state() && (node = parse_special(dom, state))) || (!err_state() && (node = parse_func_call(dom, state))) || (!err_state() && (node = parse_literal_compound(dom, state)))) { if (state->acb) { state->acb(state->data, node, &dom->loc); } return node; } else { err_push_src( "PARSE", &dom->loc, "Failed parsing DOM node"); return NULL; } }