static int init_console(void) { int fd; int ret = 0; /* Clean up */ ioctl(STDIN_FILENO, TIOCNOTTY, 0); close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); setsid(); /* Reopen console */ if ((fd = open(_PATH_CONSOLE, O_RDWR)) < 0) { ret = errno; perror(_PATH_CONSOLE); if ((fd = open("/dev/null", O_RDWR)) < 0) { perror("/dev/null"); return errno; } } dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); ioctl(STDIN_FILENO, TIOCSCTTY, 1); tcsetpgrp(STDIN_FILENO, getpgrp()); setup_term(); return ret; }
/** * @brief Main. * * This function starts everything. * It initialises the Network and Keypad. * If either of these fail then the program exits with an error. * * If not, then threads are initialised and the * function 'closing_time' is associated with a signal to exit. * This allows the threads of be killed safely and the * 7 segment display to be cleared. * * After initialisation, the user is asked to toggle the * emergency state with the letter 'e', or to e'x'it the program. * * @param Void. * @return Void. */ int main (void) { int ret; int prev_state = state; // sighandler_t if(ret = networkSetup() != 0){ printd("Socket failed to init, error no: %d\n", ret); printf("Network setup failed\n"); return 1; } printd("Setting up USB ACM terminal\n"); setup_term(); /* error handling - reset leds */ atexit(closing_time); signal(SIGINT, (void *)closing_time); printd("Setting up threads\n"); start_threads(); printf("press 'e' and 'enter' to toggle emergency state\n"); printf("press 'x' and 'enter' to exit\n"); while((ret = getchar()) != 'x' && alive){ if (ret == 'e'){ pthread_mutex_lock(&state_Mutex); if (state == EMERGENCY){ state = prev_state; if(state == SUBMENU_SELECT){ state = MENU_SELECT; } } else { prev_state = state; state = EMERGENCY; } pthread_cond_broadcast(&state_Signal); pthread_mutex_unlock(&state_Mutex); pthread_mutex_lock(&button_Mutex); // Unlock state machine pthread_cond_broadcast(&button_Signal); pthread_mutex_unlock(&button_Mutex); } } alive = FALSE; // fallen out by pressing 'x' return 0; }
void DisassemblerContext::setup_term(const ValuePtr<>& term) { if (!m_visited_terms.insert(term).second) return; setup_term_name(term); switch (term->term_type()) { case term_apply: { ValuePtr<ApplyType> apply = value_cast<ApplyType>(term); setup_term(apply->recursive()); for (std::vector<ValuePtr<> >::const_iterator ii = apply->parameters().begin(), ie = apply->parameters().end(); ii != ie; ++ii) setup_term(*ii); break; } case term_exists: { ValuePtr<Exists> exists = value_cast<Exists>(term); setup_term(exists->result()); break; } case term_parameter_placeholder: case term_recursive_parameter: { setup_term(term->type()); break; } case term_functional: { class MyVisitor : public FunctionalValueVisitor { DisassemblerContext *m_self; public: MyVisitor(DisassemblerContext *self) : m_self(self) {} virtual void next(const ValuePtr<>& v) {if (v) m_self->setup_term(v);} }; MyVisitor my_visitor(this); value_cast<FunctionalValue>(term)->functional_visit(my_visitor); break; } case term_function_type: { ValuePtr<FunctionType> cast_term = value_cast<FunctionType>(term); const std::vector<ParameterType>& parameter_types = cast_term->parameter_types(); for (std::vector<ParameterType>::const_iterator ii = parameter_types.begin(), ie = parameter_types.end(); ii != ie; ++ii) setup_term(ii->value); setup_term(cast_term->result_type().value); break; } default: return; // Skip adding to definition list } if (TermDefinitionList *dl = term_definition_list(term)) dl->push_back(term); }
/** * Linux specific setup * * (1) Open device files * (2) Get initial data * (3) Set up terminal **/ void gp2021_init (void) { /* open device files */ if ((fd_status = open ("/dev/gps/status", O_RDWR)) == -1) perror ("open of GPS status device"); if ((fd_measurement = open ("/dev/gps/measurement", O_RDWR)) == -1) perror ("open of GPS measurement device"); if ((fd_data = open ("/dev/gps/data", O_RDONLY)) == -1) perror ("open of GPS data message device"); if ((fd_status == -1) || (fd_measurement == -1) || (fd_data == -1)) exit (EXIT_FAILURE); check_for_new_data (); setup_term (); }
void DisassemblerContext::setup_function(const ValuePtr<Function>& function) { for (Function::ParameterList::const_iterator ii = function->parameters().begin(), ie = function->parameters().end(); ii != ie; ++ii) setup_term_definition(*ii); setup_term(function->result_type()); for (Function::BlockList::const_iterator ii = function->blocks().begin(), ie = function->blocks().end(); ii != ie; ++ii) { const ValuePtr<Block>& block = *ii; setup_term_name(block); for (Block::PhiList::const_iterator ji = block->phi_nodes().begin(), je = block->phi_nodes().end(); ji != je; ++ji) m_names.insert(std::make_pair(*ji, make_term_name(*ji, function))); for (Block::InstructionList::const_iterator ji = block->instructions().begin(), je = block->instructions().end(); ji != je; ++ji) m_names.insert(std::make_pair(*ji, make_term_name(*ji, function))); for (Function::BlockList::const_iterator ji = function->blocks().begin(), je = function->blocks().end(); ji != je; ++ji) { setup_term_name(*ji); setup_block(*ji); } } }
gboolean term_new(gpointer data) { GtkWidget *term, *win; struct term_options *to = (struct term_options *)data; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(win), to->title); gtk_window_set_wmclass(GTK_WINDOW(win), to->wm_name, to->wm_class); term = vte_terminal_new(); gtk_container_add(GTK_CONTAINER(win), term); if (!setup_term(win, term, to)) gtk_widget_destroy(win); if (to->argv != NULL) free(to->argv); free(to->message); free(to); /* Remove this source. */ return FALSE; }
int main(int argc, char *argv[]) { char errbuf[_POSIX2_LINE_MAX]; extern char *optarg; extern int optind; double delay = 5; char *viewstr = NULL; gid_t gid; int countmax = 0; int maxlines = 0; int ch; ut = open(_PATH_UTMP, O_RDONLY); if (ut < 0) { warn("No utmp"); } kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); gid = getgid(); if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); while ((ch = getopt(argc, argv, "BNabd:ins:w:")) != -1) { switch (ch) { case 'a': maxlines = -1; break; case 'B': averageonly = 1; if (countmax < 2) countmax = 2; /* FALLTHROUGH */ case 'b': rawmode = 1; interactive = 0; break; case 'd': countmax = atoi(optarg); if (countmax < 0) countmax = 0; break; case 'i': interactive = 1; break; case 'N': nflag = 0; break; case 'n': /* this is a noop, -n is the default */ nflag = 1; break; case 's': delay = atof(optarg); if (delay <= 0) delay = 5; break; case 'w': rawwidth = atoi(optarg); if (rawwidth < 1) rawwidth = DEFAULT_WIDTH; if (rawwidth >= MAX_LINE_BUF) rawwidth = MAX_LINE_BUF - 1; break; default: usage(); /* NOTREACHED */ } } if (kd == NULL) warnx("kvm_openfiles: %s", errbuf); argc -= optind; argv += optind; if (argc == 1) { double del = atof(argv[0]); if (del == 0) viewstr = argv[0]; else delay = del; } else if (argc == 2) { viewstr = argv[0]; delay = atof(argv[1]); if (delay <= 0) delay = 5; } udelay = (useconds_t)(delay * 1000000.0); if (udelay < 1) udelay = 1; naptime = (double)udelay / 1000000.0; gethostname(hostname, sizeof (hostname)); gethz(); initialize(); set_order(NULL); if (viewstr && set_view(viewstr)) { fprintf(stderr, "Unknown/ambiguous view name: %s\n", viewstr); return 1; } if (check_termcap()) { rawmode = 1; interactive = 0; } setup_term(maxlines); if (rawmode && countmax == 0) countmax = 1; gotsig_alarm = 1; engine_loop(countmax); return 0; }
void DisassemblerContext::setup_term_definition(const ValuePtr<>& term) { if (!m_defined_terms.insert(term).second) return; setup_term_name(term); switch (term->term_type()) { case term_recursive: { ValuePtr<RecursiveType> recursive = value_cast<RecursiveType>(term); for (RecursiveType::ParameterList::const_iterator ii = recursive->parameters().begin(), ie = recursive->parameters().end(); ii != ie; ++ii) { setup_term_name(*ii); setup_term((*ii)->type()); } if (recursive->result()) setup_term(recursive->result()); break; } case term_global_variable: { ValuePtr<GlobalVariable> gvar = value_cast<GlobalVariable>(term); setup_term(gvar->value_type()); if (gvar->value()) setup_term(gvar->value()); break; } case term_function: { ValuePtr<Function> function = value_cast<Function>(term); setup_function(function); break; } case term_function_parameter: { ValuePtr<FunctionParameter> param = value_cast<FunctionParameter>(term); setup_term(param->type()); break; } case term_instruction: { class MyVisitor : public InstructionVisitor { DisassemblerContext *m_self; public: MyVisitor(DisassemblerContext *self) : m_self(self) {} virtual void next(ValuePtr<>& v) {if (v) m_self->setup_term(v);} }; MyVisitor my_visitor(this); ValuePtr<Instruction> insn = value_cast<Instruction>(term); insn->instruction_visit(my_visitor); m_local_definitions[insn->block()].push_back(insn); break; } case term_phi: { ValuePtr<Phi> phi = value_cast<Phi>(term); const std::vector<PhiEdge>& edges = phi->edges(); for (std::vector<PhiEdge>::const_iterator ii = edges.begin(), ie = edges.end(); ii != ie; ++ii) { setup_term(ii->block); setup_term(ii->value); } break; } default: setup_term(term); break; } }
int main(int argc, char **argv){ /* * Init Variables */ WINDOW *w_game = NULL; //game field WINDOW *w_gamefrm = NULL; // frame around the game field /* prepare panels in order */ PANEL *p_game=NULL, *p_gamefrm=NULL; FILE *urandom; urandom = fopen("/dev/urandom", "rb");// treat as binary int *xPos, *yPos; //current x and y positions frame term, game; /* * Gameplay Variables */ snake snk; xPos = &(snk.body[0][0]); yPos = &(snk.body[1][0]); snk.bodysym = ACS_BLOCK; snk.length=1; int cookie[2] = {0,0}; // stores cookie location x y; negative vals are invalid float speed = 150; // steps/ms char vector[2] = {0,0}; // movement vector x y int lastPos[2]; // store last position bool mod_length=FALSE; bool vec_diff=FALSE; /* * Setup Terminal */ setup_term(&term, w_game); /* * Setup Game Field */ w_game = prep_game(w_game, w_gamefrm, p_game, p_gamefrm, &game, &term, xPos, yPos, &snk); placeCookie(w_game, &game, cookie, urandom); getch(); while(true){ mvwprintw(stdscr, 22, 1, "snklen:%d", snk.length); chdir_snake(w_game, &term, xPos, yPos, vector, &snk, &vec_diff); mod_length=mv_snake(w_game, &game, &term, &snk, xPos, yPos, vector, cookie, urandom, vec_diff); if(mod_length){ xPos=&(snk.body[0][(snk.length)-1]); // need to renew position of head in arr yPos=&(snk.body[1][(snk.length)-1]); } debug(stdscr, &term, xPos, yPos); mvwprintw(stdscr, 5,1, "%d %d", snk.body[0][0], snk.body[1][0]); mvwprintw(stdscr, 6,1, "%d %d", snk.body[0][1], snk.body[1][1]); mvwprintw(stdscr, 7,1, "%d %d", snk.body[0][2], snk.body[1][2]); mvwprintw(stdscr, 8,1, "%d %d", snk.body[0][3], snk.body[1][3]); mvwprintw(stdscr, 9,1, "%d %d", snk.body[0][4], snk.body[1][4]); do_refresh(w_game, xPos, yPos, vector, &snk); wait(vector, &speed); } do_exit(urandom, 0); return 0; }