static Command* parse_cmdline(char* buf) { /*if (nr_token > 0) reset_parser();*/ /*dump_tokens(buf);*/ if (nr_token > 0) reset_parser(); return parse_pipe(buf); }
context::~context() { m_last_obj = 0; if (!m_user_ref_count) { for (unsigned i = 0; i < m_replay_stack.size(); ++i) { dealloc(m_replay_stack[i]); } } reset_parser(); dealloc(m_solver); }
context::~context() { reset_parser(); m_last_obj = 0; u_map<api::object*>::iterator it = m_allocated_objects.begin(); while (it != m_allocated_objects.end()) { DEBUG_CODE(warning_msg("Uncollected memory: %d: %s", it->m_key, typeid(*it->m_value).name());); m_allocated_objects.remove(it->m_key); dealloc(it->m_value); it = m_allocated_objects.begin(); }
static exit_values_ty indent_multiple_files(void) { exit_values_ty exit_status = total_success; int i; /* When multiple input files are specified, make a backup copy * and then output the indented code into the same filename. */ for (i = 0; input_files; i++, input_files--) { exit_values_ty status; struct stat file_stats; in_name = in_file_names[i]; out_name = in_file_names[i]; current_input = read_file(in_file_names[i], &file_stats); open_output(out_name, "r+"); make_backup(current_input, &file_stats); /* Aborts on failure. */ /* We have safely made a backup so the open file can be truncated. */ reopen_output_trunc(out_name); reset_parser(); status = indent (current_input); if (status > exit_status) { exit_status = status; } if (settings.preserve_mtime) { close_output(&file_stats, out_name); } else { close_output(NULL, out_name); } } return exit_status; }
/* What to do when we've been interrupted, and it is safe to handle it. */ void throw_to_top_level () { int print_newline = 0; if (interrupt_state) { print_newline = 1; DELINTERRUPT; } if (interrupt_state) return; last_command_exit_value |= 128; /* Run any traps set on SIGINT. */ run_interrupt_trap (); /* Cleanup string parser environment. */ while (parse_and_execute_level) parse_and_execute_cleanup (); #if defined (JOB_CONTROL) give_terminal_to (shell_pgrp); #endif /* JOB_CONTROL */ #if defined (JOB_CONTROL) || defined (HAVE_POSIX_SIGNALS) /* This should not be necessary on systems using sigsetjmp/siglongjmp. */ sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL); #endif reset_parser (); #if defined (READLINE) if (interactive) bashline_reinitialize (); #endif /* READLINE */ #if defined (PROCESS_SUBSTITUTION) unlink_fifo_list (); #endif /* PROCESS_SUBSTITUTION */ run_unwind_protects (); loop_level = continuing = breaking = 0; return_catch_flag = 0; if (interactive && print_newline) { fflush (stdout); fprintf (stderr, "\n"); fflush (stderr); } /* An interrupted `wait' command in a script does not exit the script. */ if (interactive || (interactive_shell && !shell_initialized) || (print_newline && signal_is_trapped (SIGINT))) jump_to_top_level (DISCARD); else jump_to_top_level (EXITPROG); }
static exit_values_ty indent_single_file(BOOLEAN using_stdin) { int is_stdin = false; exit_values_ty exit_status = total_success; struct stat file_stats; if ((input_files == 0) || using_stdin) { input_files = 1; in_file_names[0] = "Standard input"; in_name = in_file_names[0]; current_input = read_stdin (); is_stdin = true; } else { /* 1 input file */ in_name = in_file_names[0]; current_input = read_file(in_file_names[0], &file_stats); if (!out_name && !settings.use_stdout) { out_name = in_file_names[0]; make_backup(current_input, &file_stats); } } /* Use stdout if it was specified ("-st"), or neither input * nor output file was specified. */ if (settings.use_stdout || !out_name) { open_output(NULL, NULL); } else { open_output(out_name, "w"); } reset_parser (); exit_status = indent (current_input); if (input_files > 0 && !using_stdin && settings.preserve_mtime) { close_output(&file_stats, out_name); } else { close_output(NULL, out_name); } if (current_input) { if (!is_stdin && current_input->name) xfree(current_input->name); xfree(current_input->data); } return exit_status; }
static ERL_NIF_TERM free_parser(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { return reset_parser( env, argc, argv ); };
uint16_t message_parser(char_fifo_t* fifo, message_t** outmessage) { uint16_t i; uint16_t br,desired; int16_t required; uint8_t *pBuffer = mf.buffer; /* Serialise the packet as an octet stream */ message_t* pPacket = (message_t*)mf.buffer; // TODO: Test if there has been an overrun switch (mf.state) { case 0: // Test for valid 4 byte header /* Read required number of bytes from the fifo */ if (mf.bdepth < sizeof(pPacket->header)) { desired = sizeof(pPacket->header)-mf.bdepth; if (desired > fifo->depth) return 0; br = fifo_read_n(fifo,((uint8_t*)mf.buffer+mf.bdepth), desired); mf.bdepth += br; /* Return if there are still not enough bytes to parse a header */ if (mf.bdepth < sizeof(pPacket->header)) return 0; } /* Test for invalid ID, TYPE and LENGTH */ if ((pPacket->header.id >= 16) || (pPacket->header.type > 32) || (pPacket->header.length < 6) || (pPacket->header.length > 64) ) { /* Shift buffer by 1 byte and wait for another */ for (i=0;i<mf.bdepth-1;i++) *pBuffer++ = *(pBuffer+1); /* Record number of bytes already waiting */ mf.bdepth--; return 0; } /* No need to test CHECKSUM until payload has been received After a valid header look for the body */ mf.state = 1; /* Test if there are already enough bytes to check the payload */ required = pPacket->header.length - mf.bdepth; if (required>fifo->depth) return 0; /* Otherwise head straight into the next state */ case 1: // PAYLOAD received /* Make sure there are enough bytes */ if (mf.bdepth < pPacket->header.length) { desired = pPacket->header.length-mf.bdepth; if (desired > fifo->depth) return 0; br = fifo_read_n(fifo,((uint8_t*)mf.buffer+mf.bdepth), desired); mf.bdepth += br; if (mf.bdepth < pPacket->header.length) return 0; } /* Always return to looking for a header after this state */ mf.state = 0; /* TODO: Calculate & test checksum */ if (pPacket->header.check != 0) { /* - If checksum is invalid then need to search the packet for another valid header - Do this by shifting the buffer up and recursively calling this function */ for (i=0;i<mf.bdepth-1;i++) *pBuffer++ = *(pBuffer+1); mf.bdepth -= 1; return 0; } /* "Return" a pointer to the valid packet */ *outmessage = (message_t *)mf.buffer; /* After a valid body look for the next header */ mf.bdepth -= pPacket->header.length; /* Realign buffer to point to remaining byte */ for (i=0;i<mf.bdepth-1;i++) *pBuffer++ = *(pBuffer+pPacket->header.length); /* By returning a positive number we confirm that a valid packet is in buffer */ return pPacket->header.length; default: // INVALID state protection reset_parser(); return 0; } }