/* * main -- * This is the main loop for the standalone curses editor. */ int main(int argc, char **argv) { static int reenter; CL_PRIVATE *clp; GS *gp; WIN *wp; size_t rows, cols; int rval; char **p_av, **t_av; const char *ttype; /* If loaded at 0 and jumping through a NULL pointer, stop. */ if (reenter++) abort(); /* Create and initialize the global structure. */ __global_list = gp = gs_init(argv[0]); /* * Strip out any arguments that vi isn't going to understand. There's * no way to portably call getopt twice, so arguments parsed here must * be removed from the argument list. */ for (p_av = t_av = argv;;) { if (*t_av == NULL) { *p_av = NULL; break; } if (!strcmp(*t_av, "--")) { while ((*p_av++ = *t_av++) != NULL); break; } *p_av++ = *t_av++; } /* Create new window */ wp = gs_new_win(gp); /* Create and initialize the CL_PRIVATE structure. */ clp = cl_init(wp); /* * Initialize the terminal information. * * We have to know what terminal it is from the start, since we may * have to use termcap/terminfo to find out how big the screen is. */ if ((ttype = getenv("TERM")) == NULL) { if (isatty(STDIN_FILENO)) fprintf(stderr, "%s: warning: TERM is not set\n", gp->progname); ttype = "unknown"; } term_init(gp->progname, ttype); /* Add the terminal type to the global structure. */ if ((OG_D_STR(gp, GO_TERM) = OG_STR(gp, GO_TERM) = strdup(ttype)) == NULL) perr(gp->progname, NULL); /* Figure out how big the screen is. */ if (cl_ssize(NULL, 0, &rows, &cols, NULL)) exit (1); /* Add the rows and columns to the global structure. */ OG_VAL(gp, GO_LINES) = OG_D_VAL(gp, GO_LINES) = rows; OG_VAL(gp, GO_COLUMNS) = OG_D_VAL(gp, GO_COLUMNS) = cols; /* Ex wants stdout to be buffered. */ (void)setvbuf(stdout, NULL, _IOFBF, 0); /* Start catching signals. */ if (sig_init(gp, NULL)) exit (1); /* Run ex/vi. */ rval = editor(wp, argc, argv); /* Clean out the global structure. */ gs_end(gp); /* Clean up signals. */ sig_end(gp); /* Clean up the terminal. */ (void)cl_quit(gp); /* * XXX * Reset the O_MESG option. */ if (clp->tgw != TGW_UNKNOWN) (void)cl_omesg(NULL, clp, clp->tgw == TGW_SET); /* * XXX * Reset the X11 xterm icon/window name. */ if (F_ISSET(clp, CL_RENAME)) cl_setname(gp, clp->oname); /* If a killer signal arrived, pretend we just got it. */ if (clp->killersig) { (void)signal(clp->killersig, SIG_DFL); (void)kill(getpid(), clp->killersig); /* NOTREACHED */ } /* Free the global and CL private areas. */ #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY) cl_end(clp); free(gp); #endif exit (rval); }
/*call by main*/ int next_cmd(char *out_cmd) { unsigned char c = 0; int key_no = 0; int seq_char = 0; int str_valid = 0; /*set terminal new attrib */ term_config(); /*termial initial */ term_init(out_cmd); /*main loop */ while ((c = getc(stdin)) != '\n') { key_no = 0; seq_char = 0; if (!_isspace(c)) { str_valid = 1; } if (c == 27) /*escape sequence */ { if ((c = getc(stdin)) == '[' || c == 'O') { c = getc(stdin); seq_char = 1; } } /*search for bind key handle function */ while (key_no < sizeof (key_bind) / sizeof (key_bind[0])) { if ((seq_char == key_bind[key_no].is_eseq) && (c == key_bind[key_no].key_last)) { key_bind[key_no].func(); break; } key_no++; } if (key_no == sizeof (key_bind) / sizeof (key_bind[0])) handle_normal(out_cmd, c); } /*handle enter when at the end of a line */ if (term_cursor) putchar('\n'); /* record command history without '\n' */ history_record(out_cmd); #if 0 /* add '\n' to out_cmd */ if (str_valid) { out_cmd[cmd_strlen++] = '\n'; } else { cmd_strlen = 0; out_cmd[cmd_strlen++] = '\n'; } if (cmd_strlen > 1 && out_cmd[cmd_strlen - 1] == '\n') out_cmd[cmd_strlen - 1] = 0; #else if (!str_valid) cmd_strlen = 0; #endif /*retore terminal to orginal status */ term_restore(); fflush(stdout); return cmd_strlen; }
si_t application_init(si_t video_access_mode, si_t application_type, char* name) { /** * 加载配置项 **/ if(0 != application_load_config()) { EGUI_PRINT_ERROR("failed to load config."); return -1; } /** * 初始化客户端通信句柄 **/ if(0 != uds_init(&global_application.uds, SOCK_STREAM, global_application.server_path, PEER_ROLE_CLIENT)) { EGUI_PRINT_ERROR("Failed to init client uds"); return -1; } /** * 初始化消息队列 **/ queue_init(&global_application.message_queue); client_lib_init(&global_application.uds, &global_application.message_queue); /** * 初始化event_listener **/ event_listener_init(&global_application.app_event_listener); global_application.exec_flag = 0; /** * init focus list **/ list_init(&(global_application.focus_list)); /* 初始化向量 */ vector_init(&(global_application.window_vector)); /** * 应用程序名称 **/ global_application.name = malloc(strlen(name) + 1); if(NULL == global_application.name) { EGUI_PRINT_SYS_ERROR("failed to malloc for application name %s. malloc()", name); return -1; } strncpy(global_application.name, name, strlen(name) + 1); global_application.application_type = application_type; if(0 != register_application(video_access_mode, application_type, name)) { EGUI_PRINT_ERROR("failed to register application %s.", name); return -1; } global_application.focus = NULL; global_application.main_window = NULL; global_application.desktop_ptr = NULL; global_application.desktop_msg_handler = NULL; term_init(); return 0; }
mvcp_error_code client_queue_maintenance( client demo, client_queue queue ) { printf( "Queue Maintenance for Unit %d\n\n", queue->unit ); if ( !queue->mode ) { char ch; printf( "Activate queueing? [Y] " ); ch = get_keypress( ); if ( ch == 'y' || ch == 'Y' || ch == '\r' ) queue->mode = 1; printf( "\n\n" ); } if ( queue->mode ) { int terminated = 0; int last_position = -2; term_init( ); while ( !terminated ) { int first = ( queue->position + 1 ) % 50; int index = first; if ( first == queue->tail ) index = first = queue->head; if ( queue->head == queue->tail ) { if ( last_position == -2 ) { printf( "Queue is empty\n" ); printf( "\n" ); printf( "0 = exit, t = turn off queueing\n\n" ); last_position = -1; } } else if ( last_position != queue->position ) { printf( "Order of play\n\n" ); do { printf( "%c%02d: %s\n", index == first ? '*' : ' ', index, queue->list[ index ] + 1 ); index = ( index + 1 ) % 50; if ( index == queue->tail ) index = queue->head; } while( index != first ); printf( "\n" ); printf( "0 = exit, t = turn off queueing, c = clear queue\n\n" ); last_position = queue->position; } client_change_status( demo, 1 ); switch( term_read( ) ) { case -1: break; case '0': terminated = 1; break; case 't': terminated = 1; queue->mode = 0; break; case 'c': queue->head = queue->tail = 0; queue->position = -1; last_position = -2; break; } client_change_status( demo, 0 ); } term_exit( ); } return mvcp_ok; }
mvcp_error_code client_transport( client demo ) { mvcp_error_code error = mvcp_ok; int refresh = 1; int terminated = 0; mvcp_status_t status; mvcp_notifier notifier = mvcp_get_notifier( demo->dv ); while ( !terminated ) { if ( refresh ) { printf( " +----+ +------+ +----+ +------+ +---+ +-----+ +------+ +-----+ +---+ \n" ); printf( " |1=-5| |2=-2.5| |3=-1| |4=-0.5| |5=1| |6=0.5| |7=1.25| |8=2.5| |9=5| \n" ); printf( " +----+ +------+ +----+ +------+ +---+ +-----+ +------+ +-----+ +---+ \n" ); printf( "\n" ); printf( "+----------------------------------------------------------------------+\n" ); printf( "| 0 = quit, x = eXecute, 'space' = pause |\n" ); printf( "| g = goto a frame, q = queue maintenance |\n" ); printf( "| h = step -1, j = end of clip, k = start of clip, l = step 1 |\n" ); printf( "| eof handling: p = pause, r = repeat, t = terminate |\n" ); printf( "| i = set in point, o = set out point, c = clear in/out |\n" ); printf( "| u = use point settings, d = don't use point settings |\n" ); printf( "+----------------------------------------------------------------------+\n" ); printf( "\n" ); term_init( ); refresh = 0; } client_change_status( demo, 1 ); switch( term_read( ) ) { case '0': terminated = 1; break; case -1: break; case ' ': error = mvcp_unit_pause( demo->dv, demo->selected_unit ); break; case '1': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, -5000 ); break; case '2': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, -2500 ); break; case '3': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, -1000 ); break; case '4': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, -500 ); break; case '5': error = mvcp_unit_play( demo->dv, demo->selected_unit ); break; case '6': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, 500 ); break; case '7': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, 1250 ); break; case '8': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, 2500 ); break; case '9': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, 5000 ); break; case 's': error = mvcp_unit_goto( demo->dv, demo->selected_unit, 0 ); break; case 'h': error = mvcp_unit_step( demo->dv, demo->selected_unit, -1 ); break; case 'j': mvcp_notifier_get( notifier, &status, demo->selected_unit ); error = mvcp_unit_goto( demo->dv, demo->selected_unit, status.tail_out ); break; case 'k': mvcp_notifier_get( notifier, &status, demo->selected_unit ); error = mvcp_unit_goto( demo->dv, demo->selected_unit, status.in ); break; case 'l': error = mvcp_unit_step( demo->dv, demo->selected_unit, 1 ); break; case 'p': error = mvcp_unit_set( demo->dv, demo->selected_unit, "eof", "pause" ); break; case 'r': error = mvcp_unit_set( demo->dv, demo->selected_unit, "eof", "loop" ); break; case 't': error = mvcp_unit_set( demo->dv, demo->selected_unit, "eof", "stop" ); break; case 'i': error = client_set_in( demo ); break; case 'o': error = client_set_out( demo ); break; case 'g': client_change_status( demo, 0 ); term_exit( ); error = client_goto( demo ); refresh = 1; break; case 'c': error = client_clear_in_out( demo ); break; case 'u': error = mvcp_unit_set( demo->dv, demo->selected_unit, "points", "use" ); break; case 'd': error = mvcp_unit_set( demo->dv, demo->selected_unit, "points", "ignore" ); break; case 'x': client_change_status( demo, 0 ); term_exit( ); client_execute( demo ); refresh = 1; break; case 'q': client_change_status( demo, 0 ); term_exit( ); client_queue_maintenance( demo, &demo->queues[ demo->selected_unit ] ); refresh = 1; break; } client_change_status( demo, 0 ); } term_exit( ); return error; }
void term_suspend(void) { term_done(); kill(getpid(), SIGSTOP); term_init(); }
///////////////////////////////////////////////////////////////////////////// // Main-Funktion ///////////////////////////////////////////////////////////////////////////// int main(int argc, const char *argv[]) { // Initializations // // first some basic hardware infrastructure timer_init(); // Timer Interrupt initialisieren led_init(); provider_init(); // needs to be in the beginning, as other // modules like serial register here term_init(); // does not need endpoint/provider yet // but can take up to a buffer of text #ifdef __AVR__ stdout = &term_stdout; // redirect stdout #else device_setup(argc, argv); #endif // server communication uarthw_init(); // first hardware provider_t *serial = serial_init(); // then logic layer // now prepare for terminal etc // (note: in the future the assign parameter could be used // to distinguish different UARTs for example) void *epdata = serial->prov_assign(NAMEINFO_UNUSED_DRIVE, NULL); term_endpoint.provider = serial; term_endpoint.provdata = epdata; // and set as default provider_set_default(serial, epdata); // debug output via "terminal" term_set_endpoint(&term_endpoint); // init file handling (active open calls) file_init(); // buffer structures buffer_init(); // direct buffer handling direct_init(); // relfile handling relfile_init(); // init main channel handling channel_init(); // before we init any busses, we init the runtime config code // note it gets the provider to register a listener for X command line params rtconfig_init(&term_endpoint); // bus init // first the general bus (with bus counter) bus_init(); // this call initializes the device-specific hardware // e.g. IEEE488 and IEC busses on xs1541, plus SD card on petSD and so on // it also handles the interrupt initialization if necessary device_init(); #ifdef HAS_EEPROM // read bus-independent settings from non volatile memory nv_restore_common_config(); #endif // enable interrupts enable_interrupts(); // sync with the server serial_sync(); // pull in command line config options from server // also send directory charset rtconfig_pullconfig(argc, argv); #ifdef USE_FAT // register fat provider provider_register("FAT", &fat_provider); //provider_assign(0, "FAT", "/"); // might be overwritten when fetching X-commands //provider_assign(1, "FAT", "/"); // from the server, but useful for standalone-mode #endif // show our version... ListVersion(); // ... and some system info term_printf((" %u Bytes free"), BytesFree()); term_printf((", %d kHz"), FreqKHz()); #ifdef __AVR__ fuse_info(); #endif term_putcrlf(); term_putcrlf(); while (1) // Mainloop-Begin { // keep data flowing on the serial line main_delay(); if (!is_locked) device_loop(); // send out log messages term_flush(); } }
static void do_term_init() { term_init(); initscr(); }
/* * Initialize a term_data */ static errr term_data_init(term_data *td, Widget topLevel, int key_buf, String name, ArgList widget_arg, Cardinal widget_arg_no, int i) { Widget parent; term *t = &td->t; int cols = 80; int rows = 24; char buf[80]; cptr str; int val; /* Create the shell widget */ parent = XtCreatePopupShell(name, topLevelShellWidgetClass, topLevel, NULL, 0); /* Window specific cols */ sprintf(buf, "ANGBAND_X11_COLS_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) cols = val; /* Window specific rows */ sprintf(buf, "ANGBAND_X11_ROWS_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) rows = val; /* Hack the main window must be at least 80x24 */ if (i == 0) { if (cols < 80) cols = 80; if (rows < 24) rows = 24; } /* Reset the initial size */ widget_arg[0].value = rows; widget_arg[1].value = cols; /* Hack ox==oy in xaw port */ /* Window specific inner border offset (ox) */ sprintf(buf, "ANGBAND_X11_IBOX_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) widget_arg[6].value = val; /* Window specific inner border offset (oy) */ sprintf(buf, "ANGBAND_X11_IBOY_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) widget_arg[6].value = val; /* Create the interior widget */ td->widget = (AngbandWidget) XtCreateManagedWidget(name, angbandWidgetClass, parent, widget_arg, widget_arg_no); /* Initialize the term (full size) */ term_init(t, cols, rows, key_buf); /* Use a "soft" cursor */ t->soft_cursor = TRUE; /* Erase with "white space" */ t->attr_blank = TERM_WHITE; t->char_blank = ' '; /* Hooks */ t->xtra_hook = Term_xtra_xaw; t->curs_hook = Term_curs_xaw; t->bigcurs_hook = Term_bigcurs_xaw; t->wipe_hook = Term_wipe_xaw; t->text_hook = Term_text_xaw; /* Save the data */ t->data = td; /* Register the keypress event handler */ XtAddEventHandler((Widget)td->widget, KeyPressMask, False, (XtEventHandler) handle_event, td); /* Redraw callback */ XtAddCallback((Widget)td->widget, XtNredrawCallback, react_redraw, td); /* Realize the widget */ XtRealizeWidget(parent); /* Have we redefined the font? */ if (streq(td->widget->angband.font, DEFAULT_X11_FONT)) { XFontStruct *fnt; /* Check if the font exists */ fnt = getFont(td->widget, (String) get_default_font(i), FALSE); /* The font didn't exist */ if (fnt == NULL) { XtWarning("Couldn't find the requested font!"); } else { int height, width; /* Free the old font */ XFreeFont(XtDisplay((Widget)td->widget), td->widget->angband.fnt); /* Update font information */ td->widget->angband.fontheight = fnt->ascent + fnt->descent; td->widget->angband.fontwidth = fnt->max_bounds.width; if (use_bigtile) td->widget->angband.tilewidth = 2 * td->widget->angband.fontwidth; else td->widget->angband.tilewidth = td->widget->angband.fontwidth; td->widget->angband.fontascent = fnt->ascent; for (i = 0; i < NUM_COLORS; i++) { /* Be sure the correct font is ready */ XSetFont(XtDisplay((Widget)td->widget), td->widget->angband.gc[i], fnt->fid); } /* Get the window shape */ height = (td->widget->angband.start_rows * td->widget->angband.fontheight + 2 * td->widget->angband.internal_border); width = (td->widget->angband.start_columns * td->widget->angband.fontwidth + 2 * td->widget->angband.internal_border); /* Request a change to the new shape */ if (XtMakeResizeRequest((Widget)td->widget, width, height, NULL, NULL) == XtGeometryNo) { /* Not allowed */ XtWarning("Size change denied!"); } else { /* Recalculate size hints */ calculateSizeHints(td->widget); } } } /* Make it visible */ XtPopup(parent, XtGrabNone); /* Activate (important) */ Term_activate(t); Resize_term(td->widget); return 0; }
main(int argc, char *argv[]) { NODE *exec_list = NIL; #ifdef MEM_DEBUG extern long int mem_allocated, mem_freed; #endif #ifdef x_window x_window_init(argc, argv); #endif #ifdef mac init_mac_memory(); #endif term_init(); if (argc < 2) { if (isatty(1)) lcleartext(); printf("Welcome to Berkeley Logo version 3.0.1"); new_line(stdout); } init(); #ifdef ibm signal(SIGINT, SIG_IGN); #ifdef __ZTC__ _controlc_handler = do_ctrl_c; controlc_open(); #endif #else signal(SIGINT, logo_stop); #endif signal(SIGQUIT, logo_pause); /* SIGQUITs never happen on the IBM */ argv++; while (--argc > 0 && NOT_THROWING) { silent_load(NIL,*argv++); } for (;;) { if (NOT_THROWING) { #ifdef MEM_DEBUG printf("alloc=%d, freed=%d, used=%d\n", mem_allocated, mem_freed, mem_allocated-mem_freed); #endif current_line = reref(current_line, reader(stdin,"? ")); if (feof(stdin) && !isatty(0)) lbye(); exec_list = parser(current_line, TRUE); val_status = 0; if (exec_list != NIL) eval_driver(exec_list); } if (stopping_flag == THROWING) { if (compare_node(throw_node, Error, TRUE) == 0) { err_print(); } else if (compare_node(throw_node, System, TRUE) == 0) break; else if (compare_node(throw_node, Toplevel, TRUE) != 0) { err_logo(NO_CATCH_TAG, throw_node); err_print(); } stopping_flag = RUN; } if (stopping_flag == STOP || stopping_flag == OUTPUT) { print_node(stdout, make_static_strnode( "You must be in a procedure to use OUTPUT or STOP.\n")); stopping_flag = RUN; } } prepare_to_exit(TRUE); }
int main(int argc, char **argv) { static int version = 0; static GOptionEntry options[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display Irssi version", NULL }, { NULL } }; int loglev; core_register_options(); fe_common_core_register_options(); args_register(options); args_execute(argc, argv); if (version) { printf(PACKAGE_TARNAME" " PACKAGE_VERSION" (%d %04d)\n", IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); return 0; } srand(time(NULL)); quitting = FALSE; core_preinit(argv[0]); check_files(); #ifdef HAVE_SOCKS SOCKSinit(argv[0]); #endif /* setlocale() must be called at the beginning before any calls that affect it, especially regexps seem to break if they're generated before this call. locales aren't actually used for anything else than autodetection of UTF-8 currently.. furthermore to get the users's charset with g_get_charset() properly you have to call setlocale(LC_ALL, "") */ setlocale(LC_ALL, ""); /* Temporarily raise the fatal level to abort on config errors. */ loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL); textui_init(); if (!term_init()) { fprintf(stderr, "Can't initialize screen handling.\n"); return 1; } g_log_set_always_fatal(loglev); textui_finish_init(); main_loop = g_main_new(TRUE); /* Does the same as g_main_run(main_loop), except we can call our dirty-checker after each iteration */ while (!quitting) { if (reload_config) { /* SIGHUP received, do /RELOAD */ reload_config = FALSE; signal_emit("command reload", 1, ""); } dirty_check(); term_refresh_freeze(); g_main_iteration(TRUE); term_refresh_thaw(); } g_main_destroy(main_loop); textui_deinit(); session_upgrade(); /* if we /UPGRADEd, start the new process */ return 0; }
int main(int argc, char **argv) { term_init(); set_default_opts(); if (getenv("NVC_GDB") != NULL) register_gdb_signal_handlers(); else register_trace_signal_handlers(); atexit(fbuf_cleanup); static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "work", required_argument, 0, 'w' }, { "dump", no_argument, 0, 'd' }, { "codegen", no_argument, 0, 'c' }, { "make", no_argument, 0, 'm' }, { "std", required_argument, 0, 's' }, { 0, 0, 0, 0 } }; int c, index = 0; const char *spec = "aehrvL:"; while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) { switch (c) { case 0: // Set a flag break; case 'h': usage(); exit(EXIT_SUCCESS); case 'v': printf("%s\n%s\n", version_string, copy_string); exit(EXIT_SUCCESS); case 'w': opt_set_str("work-name", optarg); break; case 'L': lib_add_search_path(optarg); break; case 's': set_standard(parse_standard(optarg)); break; case 'a': case 'e': case 'd': case 'r': case 'c': case 'm': // Subcommand options are parsed later argc -= (optind - 1); argv += (optind - 1); goto getopt_out; case '?': // getopt_long already printed an error message exit(EXIT_FAILURE); default: abort(); } } getopt_out: switch (c) { case 'a': return analyse(argc, argv); case 'e': return elaborate(argc, argv); case 'r': return run(argc, argv); case 'd': return dump_cmd(argc, argv); case 'c': return codegen(argc, argv); case 'm': return make_cmd(argc, argv); default: fprintf(stderr, "%s: missing command\n", PACKAGE); return EXIT_FAILURE; } }
void reattach_tty(char *tty, char *password) { int s = -1; char *name; struct sockaddr_in addr; struct hostent *hp; int len = 0; fd_set rd_fd; struct timeval tm = {0}; char chr_c[] = "\003"; /* * this buffer has to be big enough to handle a full screen of * information from the detached process. */ unsigned char buffer[6 * BIG_BUFFER_SIZE+1]; char *p; int port = 0; #if defined (TIOCGWINSZ) struct winsize window; #endif memset(&parm, 0, sizeof(struct param)); if (!(name = find_detach_socket(socket_path, tty))) { fprintf(stderr, "No detached process to attach to.\r\n"); _exit(1); } strcpy(parm.cookie, get_cookie(name)); if (!*parm.cookie) _exit(1); if ((p = strrchr(name, '/'))) p++; sscanf(p, "%d.%*s.%*s", &port); displays = 1; if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { displays = 0; _exit(1); } chmod(name, SOCKMODE); set_socket_options(s); memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_port = htons(port); addr.sin_family = AF_INET; if((hp = gethostbyname("localhost"))) memcpy(&addr.sin_addr, hp->h_addr, hp->h_length); else inet_aton("127.0.0.1", (struct in_addr *)&addr.sin_addr); if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { fprintf(stderr, "connection refused for %s\r\n", name); _exit(1); } parm.pid = getpid(); parm.pgrp = getpgrp(); parm.uid = getuid(); strcpy(parm.tty, ttyname(0)); strncpy(parm.termid, getenv("TERM"), 80); if (password) strncpy(parm.password, password, 60); fprintf(stderr, "attempting to wakeup %s\r\n", find_tty_name(name)); #if defined (TIOCGWINSZ) if (ioctl(0, TIOCGWINSZ, &window) > -1) { parm.cols = window.ws_col; parm.rows = window.ws_row; } else #endif { parm.cols = 79; parm.rows = 25; } write(s, &parm, sizeof(struct param)); sleep(2); alarm(15); len = read(s, &parm, sizeof(struct param)); alarm(0); if (len <= 0) { fprintf(stderr, "[1;37merror[0;37m reconnecting to %s\r\n", find_tty_name(name)); displays = 0; chmod(name, SOCKMODE); exit(1); } unlink(name); term_init(parm.termid); set_term_eight_bit(1); charset_ibmpc(); term_clear_screen(); term_resize(); term_move_cursor(0,0); my_signal(SIGPIPE, handle_pipe, 0); my_signal(SIGINT, handle_ctrlc, 0); my_signal(SIGHUP, handle_hup, 0); /* * according to MHacker we need to set errno to 0 under BSD. * for some reason we get a address in use from a socket * */ errno = 0; while (1) { FD_ZERO(&rd_fd); FD_SET(0, &rd_fd); FD_SET(s, &rd_fd); tm.tv_sec = 2; switch(select(s+1, &rd_fd, NULL, NULL, &tm)) { case -1: if (ctrl_c) { write(s, chr_c, 1); ctrl_c = 0; } else if (errno != EINTR) { close(s); _exit(1); } break; case 0: break; default: { if (FD_ISSET(0, &rd_fd)) { len = read(0, buffer, sizeof(buffer)-1); write(s, buffer, len); } if (FD_ISSET(s, &rd_fd)) { len = read(s, buffer, sizeof(buffer)-1); write(1, buffer, len); } } } } close(s); fprintf(stderr, "Never should have got here"); _exit(1); return; /* error return */ }
int main(int argc, char **argv) { char *locale = setlocale(LC_ALL, ""); for(int i = 0; i < 256; i++) localised_up_case[i] = toupper(i); if (locale) { struct re_pattern_buffer re_pb; struct re_registers re_reg; memset(&re_pb, 0, sizeof re_pb); memset(&re_reg, 0, sizeof re_reg); re_pb.translate = localised_up_case; re_compile_pattern(LOCALE_REGEX, strlen(LOCALE_REGEX), &re_pb); if (re_search(&re_pb, locale, strlen(locale), 0, strlen(locale), &re_reg) >= 0) { if (re_reg.start[1] >= 0) io_utf8 = true; } free(re_reg.start); free(re_reg.end); } bool no_config = false; char *macro_name = NULL, *key_bindings_name = NULL, *menu_conf_name = NULL, *startup_prefs_name = DEF_PREFS_NAME; char * const skiplist = calloc(argc, 1); if (!skiplist) exit(1); /* We need this many flags. */ for(int i = 1; i < argc; i++) { if (argv[i][0] == '-' && (!strcmp(&argv[i][1], "h") || !strcmp(&argv[i][1], "-help" "\0" VERSION_STRING))) { puts(ARG_HELP); exit(0); } /* Special arguments start with two dashes. If we find one, we cancel its entry in argv[], so that it will be skipped when opening the specified files. The only exception is +N for skipping to the N-th line. */ if (argv[i][0] == '-' && argv[i][1] == '-') { if (!argv[i][2]) i++; /* You can use "--" to force the next token to be a filename */ else if (!strcmp(&argv[i][2], "noconfig") || !strcmp(&argv[i][2], "no-config")) { no_config = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "noansi") || !strcmp(&argv[i][2], "no-ansi")) { ansi = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "no-syntax")) { do_syntax = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "prefs")) { if (i < argc-1) { startup_prefs_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "ansi")) { ansi = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "utf8")) { io_utf8 = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "no-utf8")) { io_utf8 = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "macro")) { if (i < argc-1) { macro_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "keys")) { if (i < argc-1) { key_bindings_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "menus")) { if (i < argc-1) { menu_conf_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } } } #ifdef NE_TEST /* Dump the builtin menu and key bindings to compare to doc/default.menus and doc/default.keys. */ int dump_config(void); dump_config(); #endif /* Unless --noconfig was specified, we try to configure the menus and the keyboard. Note that these functions can exit() on error. */ if (!no_config) { get_menu_configuration(menu_conf_name); get_key_bindings(key_bindings_name); } /* If we cannot even create a buffer, better go... */ if (!new_buffer()) exit(1); /* Now that key_bindings are loaded, try to fix up the message for NOT_FOUND. */ { char *repeat_last_keystroke, *new_not_found; if ((repeat_last_keystroke = find_key_strokes(REPEATLAST_A, 1))) { if ((new_not_found = malloc(39+strlen(repeat_last_keystroke)))) { strcat(strcat(strcpy(new_not_found, "Not Found. (RepeatLast with "), repeat_last_keystroke), " to wrap.)"); error_msg[NOT_FOUND] = new_not_found; } free(repeat_last_keystroke); } } clear_buffer(cur_buffer); /* The INT_MAX clip always exists, and it is used by the Through command. */ clip_desc * const cd = alloc_clip_desc(INT_MAX, 0); if (!cd) exit(1); add_head(&clips, &cd->cd_node); /* General terminfo and cursor motion initalization. From here onwards, we cannot exit() lightly. */ term_init(); /* We will be always using the last line for the status bar. */ set_terminal_window(ne_lines-1); /* We read in all the key capabilities. */ read_key_capabilities(); /* Some initializations of other modules... */ re_set_syntax( RE_CONTEXT_INDEP_ANCHORS | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE | RE_NEWLINE_ALT | RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES ); bool first_file = true; load_virtual_extensions(); load_auto_prefs(cur_buffer, startup_prefs_name); buffer *stdin_buffer = NULL; if (!isatty(fileno(stdin))) { first_file = false; const int error = load_fd_in_buffer(cur_buffer, fileno(stdin)); print_error(error); stdin_buffer = cur_buffer; if (!(freopen("/dev/tty", "r", stdin))) { fprintf(stderr, "Cannot reopen input tty\n"); abort(); } } /* The terminal is prepared for interactive I/O. */ set_interactive_mode(); clear_entire_screen(); /* This function sets fatal_code() as signal interrupt handler for all the dangerous signals (SIGILL, SIGSEGV etc.). */ set_fatal_code(); if (argc > 1) { /* The first file opened does not need a NEWDOC_A action. Note that file loading can be interrupted (wildcarding can sometimes produce unwanted results). */ uint64_t first_line = 0, first_col = 0; bool binary = false, skip_plus = false, read_only = false; stop = false; for(int i = 1; i < argc && !stop; i++) { if (argv[i] && !skiplist[i]) { if (argv[i][0] == '+' && !skip_plus) { /* looking for "+", or "+N" or "+N,M" */ uint64_t tmp_l = INT64_MAX, tmp_c = 0; char *d; errno = 0; if (argv[i][1]) { if (isdigit((unsigned char)argv[i][1])) { tmp_l = strtoll(argv[i]+1, &d, 10); if (!errno) { if (*d) { /* separator between N and M */ if (isdigit((unsigned char)d[1])) { tmp_c = strtoll(d+1, &d, 10); if (*d) errno = ERANGE; } else errno = ERANGE; } } } else errno = ERANGE; } if (!errno) { first_line = tmp_l; first_col = tmp_c; } else { skip_plus = true; i--; } } else if (!strcmp(argv[i], "--binary")) { binary = true; } else if (!strcmp(argv[i], "--read-only") || !strcmp(argv[i], "--readonly") || !strcmp(argv[i], "--ro")) { read_only = true; } else { if (!strcmp(argv[i], "-") && stdin_buffer) { stdin_buffer->opt.binary = binary; if (read_only) stdin_buffer->opt.read_only = read_only; if (first_line) do_action(stdin_buffer, GOTOLINE_A, first_line, NULL); if (first_col) do_action(stdin_buffer, GOTOCOLUMN_A, first_col, NULL); stdin_buffer = NULL; } else { if (!strcmp(argv[i], "--")) i++; if (!first_file) do_action(cur_buffer, NEWDOC_A, -1, NULL); else first_file = false; cur_buffer->opt.binary = binary; if (i < argc) do_action(cur_buffer, OPEN_A, 0, str_dup(argv[i])); if (first_line) do_action(cur_buffer, GOTOLINE_A, first_line, NULL); if (first_col) do_action(cur_buffer, GOTOCOLUMN_A, first_col, NULL); if (read_only) cur_buffer->opt.read_only = read_only; } first_line = first_col = 0; skip_plus = binary = read_only = false; } } } free(skiplist); /* This call makes current the first specified file. It is called only if more than one buffer exist. */ if (get_nth_buffer(1)) do_action(cur_buffer, NEXTDOC_A, -1, NULL); } /* We delay updates. In this way the macro activity does not cause display activity. */ reset_window(); delay_update(); if (macro_name) do_action(cur_buffer, MACRO_A, -1, str_dup(macro_name)); else if (first_file) { /* If there is no file to load, and no macro to execute, we display the "NO WARRANTY" message. */ about(); } while(true) { /* If we are displaying the "NO WARRANTY" info, we should not refresh the window now */ if (!displaying_info) { refresh_window(cur_buffer); if (cur_buffer->opt.automatch) automatch_bracket(cur_buffer, true); } draw_status_bar(); move_cursor(cur_buffer->cur_y, cur_buffer->cur_x); int c = get_key_code(); if (window_changed_size) { print_error(do_action(cur_buffer, REFRESH_A, 0, NULL)); window_changed_size = displaying_info = false; cur_buffer->automatch.shown = 0; } if (c == INVALID_CHAR) continue; /* Window resizing. */ const input_class ic = CHAR_CLASS(c); if (displaying_info) { refresh_window(cur_buffer); displaying_info = false; } if (cur_buffer->automatch.shown) automatch_bracket(cur_buffer, false); switch(ic) { case INVALID: print_error(INVALID_CHARACTER); break; case ALPHA: print_error(do_action(cur_buffer, INSERTCHAR_A, c, NULL)); break; case TAB: print_error(do_action(cur_buffer, INSERTTAB_A, 1, NULL)); break; case RETURN: print_error(do_action(cur_buffer, INSERTLINE_A, -1, NULL)); break; case COMMAND: if (c < 0) c = -c - 1; if (key_binding[c]) print_error(execute_command_line(cur_buffer, key_binding[c])); break; default: break; } } }
int main(int argc, char **argv){ int n, i; char c[4], bp[1024], area[2048], print=FALSE; struct termio line; if (argc < 2) { my_str("Usage: ./select <file(s)>\n"); return 1; } init_tty(); fill_elems(argc, argv); signal(SIGWINCH, show_params); term_vi(); term_init(bp, area); ioctl(0, TCGETA, &line); gl_env.line = line; line.c_lflag &= ~(ECHO | ISIG | ICANON); line.c_cc[VMIN] = 3; line.c_cc[VTIME] = VTI; ioctl(0, TCSETA, &line); show_params(); while(1){ n = read(0, c, 3); c[n] = '\0'; /*my_str("\n"); for(i=0;i<n;i++){ my_int(c[i]); my_char('\n'); } my_str("\n");*/ if (my_strcmp(c, gl_env.esc) == 0) { // esc break; } else if (my_strcmp(c, "\n") == 0) { // enter print = TRUE; break; } else if (my_strcmp(c, " ") == 0) { // space gl_env.elems[gl_env.current].mode = 1 - gl_env.elems[gl_env.current].mode; if (gl_env.elems[gl_env.current].mode) { gl_env.current = gl_env.current + 1; if (gl_env.current >= gl_env.nbelems) gl_env.current = 0; } show_params(); } else if (my_strcmp(c, KU) == 0) { // up gl_env.current -= 1; if (gl_env.current < 0) gl_env.current = gl_env.nbelems - 1; show_params(); } else if (my_strcmp(c, KD) == 0) { // down gl_env.current += 1; if (gl_env.current >= gl_env.nbelems) gl_env.current = 0; show_params(); } else if (my_strcmp(c, KL) == 0) { // left gl_env.current -= gl_env.win.ws_row; if (gl_env.current < 0) gl_env.current = 0; show_params(); } else if (my_strcmp(c, KR) == 0) { //right gl_env.current += gl_env.win.ws_row; if (gl_env.current >= gl_env.nbelems) gl_env.current = gl_env.nbelems-1; show_params(); } } term_clear(); ioctl(0, TCSETA, &(gl_env.line)); term_ve(); restore_tty(); if (print) { //term_clear(); //term_pos(0, 0); for (i=0;i<gl_env.nbelems;i++){ if (gl_env.elems[i].mode) { my_str(gl_env.elems[i].elem); my_char(' '); } } } return 0; }
/* * Initialize a term_data */ static errr term_data_init(term_data *td, int i) { term *t = &td->t; cptr name = angband_term_name[i]; cptr font; int x = 0; int y = 0; int cols = 80; int rows = 24; int ox = 1; int oy = 1; int wid, hgt, num; char buf[80]; cptr str; int val; XClassHint *ch; char res_name[20]; char res_class[20]; XSizeHints *sh; /* Get default font for this term */ font = get_default_font(i); /* Window specific location (x) */ sprintf(buf, "ANGBAND_X11_AT_X_%d", i); str = getenv(buf); x = (str != NULL) ? atoi(str) : -1; /* Window specific location (y) */ sprintf(buf, "ANGBAND_X11_AT_Y_%d", i); str = getenv(buf); y = (str != NULL) ? atoi(str) : -1; /* Window specific cols */ sprintf(buf, "ANGBAND_X11_COLS_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) cols = val; /* Window specific rows */ sprintf(buf, "ANGBAND_X11_ROWS_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) rows = val; /* Hack the main window must be at least 80x24 */ if (!i) { if (cols < 80) cols = 80; if (rows < 24) rows = 24; } /* Window specific inner border offset (ox) */ sprintf(buf, "ANGBAND_X11_IBOX_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) ox = val; /* Window specific inner border offset (oy) */ sprintf(buf, "ANGBAND_X11_IBOY_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) oy = val; /* Prepare the standard font */ MAKE(td->fnt, infofnt); Infofnt_set(td->fnt); if (Infofnt_init_data(font)) quit_fmt("Couldn't load the requested font. (%s)", font); /* Hack -- key buffer size */ num = ((i == 0) ? 1024 : 16); /* Assume full size windows */ wid = cols * td->fnt->wid + (ox + ox); hgt = rows * td->fnt->hgt + (oy + oy); /* Create a top-window */ MAKE(td->win, infowin); Infowin_set(td->win); Infowin_init_top(x, y, wid, hgt, 0, Metadpy->fg, Metadpy->bg); /* Ask for certain events */ Infowin_set_mask(ExposureMask | StructureNotifyMask | KeyPressMask); /* Set the window name */ Infowin_set_name(name); /* Save the inner border */ Infowin->ox = ox; Infowin->oy = oy; /* Make Class Hints */ ch = XAllocClassHint(); if (ch == NULL) quit("XAllocClassHint failed"); my_strcpy(res_name, name, sizeof(res_name)); res_name[0] = FORCELOWER(res_name[0]); ch->res_name = res_name; strcpy(res_class, "Angband"); ch->res_class = res_class; XSetClassHint(Metadpy->dpy, Infowin->win, ch); /* Make Size Hints */ sh = XAllocSizeHints(); /* Oops */ if (sh == NULL) quit("XAllocSizeHints failed"); /* Main window has a differing minimum size */ if (i == 0) { /* Main window min size is 80x24 */ sh->flags = PMinSize | PMaxSize; sh->min_width = 80 * td->fnt->wid + (ox + ox); sh->min_height = 24 * td->fnt->hgt + (oy + oy); sh->max_width = 255 * td->fnt->wid + (ox + ox); sh->max_height = 255 * td->fnt->hgt + (oy + oy); } /* Other windows can be shrunk to 1x1 */ else { /* Other windows */ sh->flags = PMinSize | PMaxSize; sh->min_width = td->fnt->wid + (ox + ox); sh->min_height = td->fnt->hgt + (oy + oy); sh->max_width = 255 * td->fnt->wid + (ox + ox); sh->max_height = 255 * td->fnt->hgt + (oy + oy); } /* Resize increment */ sh->flags |= PResizeInc; sh->width_inc = td->fnt->wid; sh->height_inc = td->fnt->hgt; /* Base window size */ sh->flags |= PBaseSize; sh->base_width = (ox + ox); sh->base_height = (oy + oy); /* Use the size hints */ XSetWMNormalHints(Metadpy->dpy, Infowin->win, sh); /* Map the window */ Infowin_map(); /* Move the window to requested location */ if ((x >= 0) && (y >= 0)) Infowin_impell(x, y); /* Initialize the term */ term_init(t, cols, rows, num); /* Use a "soft" cursor */ t->soft_cursor = TRUE; /* Erase with "white space" */ t->attr_blank = TERM_WHITE; t->char_blank = ' '; /* Hooks */ t->xtra_hook = Term_xtra_x11; t->curs_hook = Term_curs_x11; t->bigcurs_hook = Term_bigcurs_x11; t->wipe_hook = Term_wipe_x11; t->text_hook = Term_text_x11; /* Save the data */ t->data = td; /* Activate (important) */ Term_activate(t); /* Success */ return (0); }
static void transport( mlt_producer producer, mlt_consumer consumer ) { mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer ); int silent = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "silent" ); int progress = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "progress" ); struct timespec tm = { 0, 40000 }; int total_length = mlt_producer_get_length( producer ); int last_position = 0; if ( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) ) { if ( !silent && !progress ) { term_init( ); fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" ); fprintf( stderr, "|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|\n" ); fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" ); fprintf( stderr, "+---------------------------------------------------------------------+\n" ); fprintf( stderr, "| H = back 1 minute, L = forward 1 minute |\n" ); fprintf( stderr, "| h = previous frame, l = next frame |\n" ); fprintf( stderr, "| g = start of clip, j = next clip, k = previous clip |\n" ); fprintf( stderr, "| 0 = restart, q = quit, space = play |\n" ); fprintf( stderr, "+---------------------------------------------------------------------+\n" ); } while( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) ) { int value = ( silent || progress )? -1 : term_read( ); if ( value != -1 ) { char string[ 2 ] = { value, 0 }; transport_action( producer, string ); } #ifdef __DARWIN__ event_handling( producer, consumer ); #endif if ( !silent && mlt_properties_get_int( properties, "stats_off" ) == 0 ) { if ( progress ) { int current_position = mlt_producer_position( producer ); if ( current_position > last_position ) { fprintf( stderr, "Current Frame: %10d, percentage: %10d\r", current_position, 100 * current_position / total_length ); last_position = current_position; } } else { fprintf( stderr, "Current Position: %10d\r", (int)mlt_producer_position( producer ) ); } } if ( silent ) nanosleep( &tm, NULL ); } if ( !silent ) fprintf( stderr, "\n" ); } }
/* * main -- * This is the main loop for the standalone curses editor. */ int main(int argc, char *argv[]) { CL_PRIVATE *clp; GS *gp; size_t rows, cols; int rval; char *ttype; /* Create and initialize the global structure. */ __global_list = gp = gs_init(); /* Create and initialize the CL_PRIVATE structure. */ clp = cl_init(gp); /* * Initialize the terminal information. * * We have to know what terminal it is from the start, since we may * have to use termcap/terminfo to find out how big the screen is. */ if ((ttype = getenv("TERM")) == NULL) ttype = "unknown"; term_init(ttype); /* Add the terminal type to the global structure. */ if ((OG_D_STR(gp, GO_TERM) = OG_STR(gp, GO_TERM) = strdup(ttype)) == NULL) err(1, NULL); /* Figure out how big the screen is. */ if (cl_ssize(NULL, 0, &rows, &cols, NULL)) exit (1); /* Add the rows and columns to the global structure. */ OG_VAL(gp, GO_LINES) = OG_D_VAL(gp, GO_LINES) = rows; OG_VAL(gp, GO_COLUMNS) = OG_D_VAL(gp, GO_COLUMNS) = cols; /* Ex wants stdout to be buffered. */ (void)setvbuf(stdout, NULL, _IOFBF, 0); /* Start catching signals. */ if (sig_init(gp, NULL)) exit (1); /* Run ex/vi. */ rval = editor(gp, argc, argv); /* Clean up signals. */ sig_end(gp); /* Clean up the terminal. */ (void)cl_quit(gp); /* * XXX * Reset the O_MESG option. */ if (clp->tgw != TGW_UNKNOWN) (void)cl_omesg(NULL, clp, clp->tgw == TGW_SET); /* * XXX * Reset the X11 xterm icon/window name. */ if (F_ISSET(clp, CL_RENAME)) { (void)printf(XTERM_RENAME, ttype); (void)fflush(stdout); } /* If a killer signal arrived, pretend we just got it. */ if (clp->killersig) { (void)signal(clp->killersig, SIG_DFL); (void)kill(getpid(), clp->killersig); /* NOTREACHED */ } /* Free the global and CL private areas. */ #if defined(DEBUG) || defined(PURIFY) free(clp); free(gp); #endif exit (rval); }
/* * Use global *tty_tmp and term_parent */ int main( int argc, char **argv ) { struct cl_args *cl_args; struct term_node *tty_node = NULL; pid_t pid; pid_t parent_id; #if defined(HAVE_PTHREAD_SETCONCURRENCY) && !defined(LINUX) int concurrent; #endif handle_signals_parent(); tcgetattr(0, &term_parent); parent_id = getpid(); if ((pid = fork()) < 0) { exit(1); } else { if (pid != 0) { wait(NULL); tcsetattr(0, TCSANOW, &term_parent); exit(0); } } fatal_error = 4; /* Disable all signals while initializing data...*/ handle_signals(); setvbuf(stdout, NULL, _IONBF, 0); tty_tmp = (struct term_tty *)calloc(1,sizeof(struct term_tty)); if (tty_tmp == NULL) { printf("Out of memory on calloc tty_tmp\n"); clean_exit(); } tty_tmp->term = (struct termios *)calloc(1,sizeof(struct termios)); if (tty_tmp->term == NULL) { printf("Out of memory on calloc tty_tmp->term\n"); clean_exit(); } /* default values */ tty_tmp->interactive = 0; tty_tmp->gtk = 0; tty_tmp->attack = -1; tty_tmp->mac_spoofing = -1; tty_tmp->splash = -1; strncpy(tty_tmp->username, VTY_USER, MAX_USERNAME); strncpy(tty_tmp->password, VTY_PASS, MAX_PASSWORD); strncpy(tty_tmp->e_password, VTY_ENABLE, MAX_PASSWORD); tty_tmp->port = VTY_PORT; tty_tmp->ip_filter = NULL; #ifdef HAVE_GTK tty_tmp->buffer_log = NULL; #endif cl_args = (struct cl_args *)calloc(1,sizeof(struct cl_args)); if (cl_args == NULL) { printf("Out of memory on calloc cl_args\n"); clean_exit(); } if ( argc == 1 ) { printf("GNU %s %s %s\n", PACKAGE, VERSION, "$Date: 2006/03/23 08:40:14 $"); printf("Try '%s -h' to display the help.\n",PACKAGE); clean_exit(); } if (getuid() != 0) { printf("You must be root to run %s %s\n", PACKAGE, VERSION); clean_exit(); } if (term_init() < 0) g00dbye(); /* Register all the protocols */ protocol_init(); cl_args->proto_index = -1; if (parser_initial(tty_tmp, cl_args, argc, argv) < 0) { clean_exit(); } init_log(); #if defined(HAVE_PTHREAD_SETCONCURRENCY) && !defined(LINUX) /* concurrent = pthread_getconcurrency();*/ concurrent = 15;/*(MAX_TERMS*MAX_PROTOCOLS*MAX_THREAD_ATTACK*2)+3;*/ if (pthread_setconcurrency(concurrent) != 0) { thread_error("init pthread_setconcurrency()",errno); g00dbye(); } #endif if (interfaces_init(&terms->pcap_listen_th) < 0 ) g00dbye(); /* Establish TERM signal handler...*/ posix_signal(SIGTERM, final); #ifdef HAVE_REMOTE_ADMIN if (tty_tmp->daemonize) { if (admin_init(tty_tmp) < 0) g00dbye(); } #endif if (thread_create(&terms->uptime_th.id, &th_uptime, (void *)NULL) < 0) g00dbye(); /* Command line and ncurses cannot be choosed simultaneously...*/ if ((!tty_tmp->interactive) && (!tty_tmp->gtk) && (cl_args->proto_index != -1)) { terms->work_state = INITIAL; tty_node = term_type[TERM_TTY].list; if (thread_create(&tty_node[0].thread.id, &th_tty_peer, (void *)cl_args) < 0) g00dbye(); while(terms->work_state != STOPPED) thread_usleep(100000); } #ifdef HAS_CURSES if (tty_tmp->interactive) { terms->work_state = INITIAL; if (thread_create(&terms->gui_th.id, &ncurses_gui, NULL) < 0 ) g00dbye(); /* Wait until the ncurses GUI is over */ while(terms->work_state != STOPPED) thread_usleep(100000); } else { #endif #ifdef HAVE_GTK if (tty_tmp->gtk) { terms->work_state = INITIAL; if (thread_create(&terms->gui_gtk_th.id, >k_gui, NULL) < 0 ) g00dbye(); /* Wait until the GTK GUI is over */ while(terms->work_state != STOPPED) thread_usleep(100000); } #endif #ifdef HAS_CURSES } #endif #ifdef HAVE_REMOTE_ADMIN if (tty_tmp->daemonize) { /* Ok, now that console (ncurses) is finished * we can become a true daemon... */ become_daemon(parent_id); /* Wait until some important thread exits due to fatal_error...*/ while (fatal_error == 4) thread_usleep(100000); } #endif g00dbye(); exit(1); }
int main(int argc, char **argv) { static int version = 0; static GOptionEntry options[] = { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, "Use the dummy terminal mode", NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display irssi version", NULL }, { NULL } }; #ifdef USE_GC g_mem_set_vtable(&gc_mem_table); #endif core_register_options(); fe_common_core_register_options(); args_register(options); args_execute(argc, argv); if (version) { printf(PACKAGE_TARNAME" " PACKAGE_VERSION" (%d %04d)\n", IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); return 0; } srand(time(NULL)); dummy = FALSE; quitting = FALSE; core_preinit(argv[0]); check_files(); #ifdef WIN32 winsock_init(); #endif #ifdef HAVE_SOCKS SOCKSinit(argv[0]); #endif /* setlocale() must be called at the beginning before any calls that affect it, especially regexps seem to break if they're generated before this call. locales aren't actually used for anything else than autodetection of UTF-8 currently.. furthermore to get the users's charset with g_get_charset() properly you have to call setlocale(LC_ALL, "") */ setlocale(LC_ALL, ""); textui_init(); if (!dummy && !term_init()) { fprintf(stderr, "Can't initialize screen handling, quitting.\n"); fprintf(stderr, "You can still use the dummy mode with -d parameter\n"); return 1; } textui_finish_init(); main_loop = g_main_new(TRUE); /* Does the same as g_main_run(main_loop), except we can call our dirty-checker after each iteration */ while (!quitting) { #ifdef USE_GC GC_collect_a_little(); #endif if (!dummy) term_refresh_freeze(); g_main_iteration(TRUE); if (!dummy) term_refresh_thaw(); if (reload_config) { /* SIGHUP received, do /RELOAD */ reload_config = FALSE; signal_emit("command reload", 1, ""); } dirty_check(); } g_main_destroy(main_loop); textui_deinit(); session_upgrade(); /* if we /UPGRADEd, start the new process */ return 0; }
/* * main -- * This is the main loop for the standalone curses editor. */ int main(int argc, char *argv[]) { static int reenter; CL_PRIVATE *clp; GS *gp; size_t rows, cols; int rval; char *ttype; #ifdef RUNNING_IP char *ip_arg; char **p_av, **t_av; #endif /* If loaded at 0 and jumping through a NULL pointer, stop. */ if (reenter++) abort(); /* Create and initialize the global structure. */ __global_list = gp = gs_init(argv[0]); /* * Strip out any arguments that vi isn't going to understand. There's * no way to portably call getopt twice, so arguments parsed here must * be removed from the argument list. */ #ifdef RUNNING_IP ip_arg = NULL; for (p_av = t_av = argv;;) { if (*t_av == NULL) { *p_av = NULL; break; } if (!strcmp(*t_av, "--")) { while ((*p_av++ = *t_av++) != NULL); break; } if (!memcmp(*t_av, "-I", sizeof("-I") - 1)) { if (t_av[0][2] != '\0') { ip_arg = t_av[0] + 2; ++t_av; --argc; continue; } if (t_av[1] != NULL) { ip_arg = t_av[1]; t_av += 2; argc -= 2; continue; } } *p_av++ = *t_av++; } /* * If we're being called as an editor library, we're done here, we * get loaded with the curses screen, we don't share much code. */ if (ip_arg != NULL) exit (ip_main(argc, argv, gp, ip_arg)); #endif /* Create and initialize the CL_PRIVATE structure. */ clp = cl_init(gp); /* * Initialize the terminal information. * * We have to know what terminal it is from the start, since we may * have to use termcap/terminfo to find out how big the screen is. */ if ((ttype = getenv("TERM")) == NULL) ttype = "unknown"; term_init(gp->progname, ttype); /* Add the terminal type to the global structure. */ if ((OG_D_STR(gp, GO_TERM) = OG_STR(gp, GO_TERM) = strdup(ttype)) == NULL) perr(gp->progname, NULL); /* Figure out how big the screen is. */ if (cl_ssize(NULL, 0, &rows, &cols, NULL)) exit (1); /* Add the rows and columns to the global structure. */ OG_VAL(gp, GO_LINES) = OG_D_VAL(gp, GO_LINES) = rows; OG_VAL(gp, GO_COLUMNS) = OG_D_VAL(gp, GO_COLUMNS) = cols; /* Ex wants stdout to be buffered. */ (void)setvbuf(stdout, NULL, _IOFBF, 0); /* Start catching signals. */ if (sig_init(gp, NULL)) exit (1); /* Run ex/vi. */ rval = editor(gp, argc, argv); /* Clean up signals. */ sig_end(gp); /* Clean up the terminal. */ (void)cl_quit(gp); /* * XXX * Reset the O_MESG option. */ if (clp->tgw != TGW_UNKNOWN) (void)cl_omesg(NULL, clp, clp->tgw == TGW_SET); /* * XXX * Reset the X11 xterm icon/window name. */ if (F_ISSET(clp, CL_RENAME)) { (void)printf(XTERM_RENAME, ttype); (void)fflush(stdout); } /* If a killer signal arrived, pretend we just got it. */ if (clp->killersig) { (void)signal(clp->killersig, SIG_DFL); (void)kill(getpid(), clp->killersig); /* NOTREACHED */ } /* Free the global and CL private areas. */ #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY) free(clp); free(gp); #endif exit (rval); }
/* * Prepare "SLang" for use by the file "term.c" * Installs the "hook" functions defined above */ errr init_sla(void) { int i, err; term *t = &term_screen_body; /* Initialize, check for errors */ err = (SLang_init_tty(-1, TRUE, 0) == -1); /* Quit on error */ if (err) quit("SLang initialization failed"); /* Get terminal info */ SLtt_get_terminfo(); /* Initialize some more */ if (SLsmg_init_smg() == 0) { quit("Could not get virtual display memory"); } /* Check we have enough screen. */ err = ((SLtt_Screen_Rows < 24) || (SLtt_Screen_Cols < 80)); /* Quit with message */ if (err) quit("SLang screen must be at least 80x24"); /* Now let's go for a little bit of color! */ err = !has_colors(); /* Do we have color available? */ can_use_color = !err; /* Init the Color-pairs and set up a translation table */ /* If the terminal has enough colors */ /* Color-pair 0 is *always* WHITE on BLACK */ /* XXX XXX XXX See "main-gcu.c" for proper method */ /* Only do this on color machines */ if (can_use_color) { /* Prepare the color pairs */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_BLACK, COLOR_BLACK); init_pair(9, COLOR_BRED, COLOR_BLACK); init_pair(10, COLOR_BGREEN, COLOR_BLACK); init_pair(11, COLOR_BYELLOW, COLOR_BLACK); init_pair(12, COLOR_BBLUE, COLOR_BLACK); init_pair(13, COLOR_BMAGENTA, COLOR_BLACK); init_pair(14, COLOR_BCYAN, COLOR_BLACK); init_pair(15, COLOR_BBLACK, COLOR_BLACK); /* Prepare the color table */ colortable[0] = 7; /* Black */ colortable[1] = 0; /* White */ colortable[2] = 6; /* Grey XXX */ colortable[3] = 11; /* Orange XXX */ colortable[4] = 1; /* Red */ colortable[5] = 2; /* Green */ colortable[6] = 4; /* Blue */ colortable[7] = 3; /* Brown */ colortable[8] = 15; /* Dark-grey XXX */ colortable[9] = 14; /* Light-grey XXX */ colortable[10] = 5; /* Purple */ colortable[11] = 11; /* Yellow */ colortable[12] = 9; /* Light Red */ colortable[13] = 10; /* Light Green */ colortable[14] = 12; /* Light Blue */ colortable[15] = 3; /* Light Brown XXX */ } /* Initialize the term */ term_init(t, 80, 24, 64); /* Stick in some hooks */ t->nuke_hook = Term_nuke_sla; t->init_hook = Term_init_sla; /* Stick in some more hooks */ t->xtra_hook = Term_xtra_sla; t->curs_hook = Term_curs_sla; t->wipe_hook = Term_wipe_sla; t->text_hook = Term_text_sla; /* Save the term */ term_screen = t; /* Activate it */ Term_activate(t); /* Success */ return 0; }
mvcp_error_code client_load( client demo ) { mvcp_error_code error = mvcp_ok; int terminated = 0; int refresh = 1; int start = 0; strcpy( demo->current_directory, demo->last_directory ); term_init( ); while ( !terminated ) { mvcp_dir dir = mvcp_dir_init( demo->dv, demo->current_directory ); if ( mvcp_dir_count( dir ) == -1 ) { printf( "Invalid directory - retrying %s\n", demo->last_directory ); mvcp_dir_close( dir ); dir = mvcp_dir_init( demo->dv, demo->last_directory ); if ( mvcp_dir_count( dir ) == -1 ) { printf( "Invalid directory - going back to /\n" ); mvcp_dir_close( dir ); dir = mvcp_dir_init( demo->dv, "/" ); strcpy( demo->current_directory, "/" ); } else { strcpy( demo->current_directory, demo->last_directory ); } } terminated = mvcp_dir_count( dir ) == -1; if ( !terminated ) { int index = 0; int selected = 0; int max = 9; int end = 0; end = mvcp_dir_count( dir ); strcpy( demo->last_directory, demo->current_directory ); while ( !selected && !terminated ) { mvcp_dir_entry_t entry; int pressed; if ( refresh ) { const char *action = "Load & Play"; if ( demo->queues[ demo->selected_unit ].mode ) action = "Queue"; printf( "%s from %s\n\n", action, demo->current_directory ); if ( strcmp( demo->current_directory, "/" ) ) printf( "-: Parent directory\n" ); for ( index = start; index < end && ( index - start ) < max; index ++ ) { mvcp_dir_get( dir, index, &entry ); printf( "%d: %s\n", index - start + 1, entry.name ); } while ( ( index ++ % 9 ) != 0 ) printf( "\n" ); printf( "\n" ); if ( start + max < end ) printf( "space = more files" ); else if ( end > max ) printf( "space = return to start of list" ); if ( start > 0 ) printf( ", b = previous files" ); printf( "\n" ); printf( "0 = abort, t = transport, x = execute command, q = queue maintenance\n\n" ); refresh = 0; } client_change_status( demo, 1 ); pressed = term_read( ); switch( pressed ) { case -1: break; case '0': terminated = 1; break; case 'b': refresh = start - max >= 0; if ( refresh ) start = start - max; break; case ' ': refresh = start + max < end; if ( refresh ) { start = start + max; } else if ( end > max ) { start = 0; refresh = 1; } break; case '-': if ( strcmp( demo->current_directory, "/" ) ) { selected = 1; ( *strrchr( demo->current_directory, '/' ) ) = '\0'; ( *( strrchr( demo->current_directory, '/' ) + 1 ) ) = '\0'; } break; case 't': client_change_status( demo, 0 ); term_exit( ); client_transport( demo ); term_init( ); selected = 1; break; case 'x': client_change_status( demo, 0 ); term_exit( ); client_execute( demo ); term_init( ); selected = 1; break; case 'q': client_change_status( demo, 0 ); term_exit( ); client_queue_maintenance( demo, &demo->queues[ demo->selected_unit ] ); term_init( ); selected = 1; break; default: if ( pressed >= '1' && pressed <= '9' ) { if ( ( start + pressed - '1' ) < end ) { mvcp_dir_get( dir, start + pressed - '1', &entry ); selected = 1; strcat( demo->current_directory, entry.name ); } } break; } client_change_status( demo, 0 ); } mvcp_dir_close( dir ); } if ( !terminated && demo->current_directory[ strlen( demo->current_directory ) - 1 ] != '/' ) { if ( demo->queues[ demo->selected_unit ].mode == 0 ) { error = mvcp_unit_load( demo->dv, demo->selected_unit, demo->current_directory ); mvcp_unit_play( demo->dv, demo->selected_unit ); } else { client_queue_add( demo, &demo->queues[ demo->selected_unit ], demo->current_directory ); printf( "File %s added to queue.\n", demo->current_directory ); } strcpy( demo->current_directory, demo->last_directory ); refresh = 0; } else { refresh = 1; start = 0; } } term_exit( ); return error; }
int kvm_cmd_run(int argc, const char **argv, const char *prefix) { struct virtio_net_parameters net_params; static char real_cmdline[2048]; struct framebuffer *fb = NULL; unsigned int nr_online_cpus; int exit_code = 0; int max_cpus; char *hi; int i; void *ret; signal(SIGALRM, handle_sigalrm); signal(SIGQUIT, handle_sigquit); signal(SIGUSR1, handle_sigusr1); signal(SIGUSR2, handle_sigusr2); nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN); while (argc != 0) { argc = parse_options(argc, argv, options, run_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (argc != 0) { if (kernel_filename) { fprintf(stderr, "Cannot handle parameter: " "%s\n", argv[0]); usage_with_options(run_usage, options); return EINVAL; } /* first unhandled parameter is treated as a kernel image */ kernel_filename = argv[0]; argv++; argc--; } } if (!kernel_filename) kernel_filename = find_kernel(); if (!kernel_filename) { kernel_usage_with_options(); return EINVAL; } vmlinux_filename = find_vmlinux(); if (nrcpus == 0) nrcpus = nr_online_cpus; else if (nrcpus < 1 || nrcpus > KVM_NR_CPUS) die("Number of CPUs %d is out of [1;%d] range", nrcpus, KVM_NR_CPUS); if (!ram_size) ram_size = get_ram_size(nrcpus); if (ram_size < MIN_RAM_SIZE_MB) die("Not enough memory specified: %lluMB (min %lluMB)", ram_size, MIN_RAM_SIZE_MB); if (ram_size > host_ram_size()) pr_warning("Guest memory size %lluMB exceeds host physical RAM size %lluMB", ram_size, host_ram_size()); ram_size <<= MB_SHIFT; if (!kvm_dev) kvm_dev = DEFAULT_KVM_DEV; if (!console) console = DEFAULT_CONSOLE; if (!strncmp(console, "virtio", 6)) active_console = CONSOLE_VIRTIO; else active_console = CONSOLE_8250; if (!host_ip_addr) host_ip_addr = DEFAULT_HOST_ADDR; if (!guest_mac) guest_mac = DEFAULT_GUEST_MAC; if (!script) script = DEFAULT_SCRIPT; if (virtio_9p_dir) { char tmp[PATH_MAX]; if (realpath(virtio_9p_dir, tmp)) virtio_9p__init(kvm, tmp); else die("Failed resolving 9p path"); } symbol__init(vmlinux_filename); term_init(); kvm = kvm__init(kvm_dev, ram_size); ioeventfd__init(); max_cpus = kvm__max_cpus(kvm); if (nrcpus > max_cpus) { printf(" # Limit the number of CPUs to %d\n", max_cpus); kvm->nrcpus = max_cpus; } kvm->nrcpus = nrcpus; /* * vidmode should be either specified * either set by default */ if (vnc || sdl) { if (vidmode == -1) vidmode = 0x312; } else vidmode = 0; memset(real_cmdline, 0, sizeof(real_cmdline)); strcpy(real_cmdline, "notsc noapic noacpi pci=conf1"); if (vnc || sdl) { strcat(real_cmdline, " video=vesafb console=tty0"); } else strcat(real_cmdline, " console=ttyS0 earlyprintk=serial"); strcat(real_cmdline, " "); if (kernel_cmdline) strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline)); hi = NULL; if (!image_filename[0]) { hi = host_image(real_cmdline, sizeof(real_cmdline)); if (hi) { image_filename[0] = hi; readonly_image[0] = true; image_count++; } } if (!strstr(real_cmdline, "root=")) strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline)); if (image_count) { kvm->nr_disks = image_count; kvm->disks = disk_image__open_all(image_filename, readonly_image, image_count); if (!kvm->disks) die("Unable to load all disk images."); virtio_blk__init_all(kvm); } free(hi); printf(" # kvm run -k %s -m %Lu -c %d\n", kernel_filename, ram_size / 1024 / 1024, nrcpus); if (!kvm__load_kernel(kvm, kernel_filename, initrd_filename, real_cmdline, vidmode)) die("unable to load kernel %s", kernel_filename); kvm->vmlinux = vmlinux_filename; ioport__setup_legacy(); rtc__init(); serial8250__init(kvm); pci__init(); if (active_console == CONSOLE_VIRTIO) virtio_console__init(kvm); if (virtio_rng) while (virtio_rng--) virtio_rng__init(kvm); if (!network) network = DEFAULT_NETWORK; if (!strncmp(network, "virtio", 6)) { net_params = (struct virtio_net_parameters) { .host_ip = host_ip_addr, .kvm = kvm, .script = script }; sscanf(guest_mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", net_params.guest_mac, net_params.guest_mac+1, net_params.guest_mac+2, net_params.guest_mac+3, net_params.guest_mac+4, net_params.guest_mac+5); virtio_net__init(&net_params); }
int main(int argc, char *argv[], char *envp[]) { char *channel; debug_init(); srand((unsigned)time(NULL)); time(&start_time); time(&idle_time); time(&now); #ifdef WINNT fprintf(stdout, "%s %s\r\n", nap_version, internal_version); fprintf(stdout, "%s\r\n", main_version); #else fprintf(stdout, "%s %s\n", nap_version, internal_version); fprintf(stdout, "%s\n", main_version); #endif channel = parse_args(argv, argc, envp); FD_ZERO(&readables); FD_ZERO(&writables); if (term_init(NULL)) _exit(1); /* my_signal(SIGQUIT, SIG_IGN, 0);*/ my_signal(SIGHUP, irc_exit_old, 0); my_signal(SIGTERM, irc_exit_old, 0); my_signal(SIGPIPE, SIG_IGN, 0); my_signal(SIGINT, cntl_c, 0); my_signal(SIGALRM, nothing, 0); my_signal(SIGCHLD, child_reap, 0); my_signal(SIGCONT, term_cont, 0); my_signal(SIGWINCH, sig_refresh_screen, 0); my_signal(SIGUSR1, sigusr1, 0); if (!init_screen()) { create_new_screen(); new_window(main_screen); } init_keys(); init_keys2(); init_variables(); #ifdef WANT_THREAD init_share_mutexes(); #ifdef WANT_NSLOOKUP start_dns(); #endif #ifdef WANT_MP3PLAYER start_mp3(); #endif #ifdef GTK start_tgtk(); #endif #endif build_status(current_window, NULL, 0); update_input(UPDATE_ALL); #ifndef WINNT charset_ibmpc(); #endif load_scripts(); read_unfinished_list(); if (auto_connect) { int serv = 0; reload_save(NULL, NULL, NULL, NULL, 0); if (starting_server != -1) serv = starting_server; connect_to_server_by_refnum(serv, -1, create); current_window->server = serv; xterm_settitle(); } else { if (do_get_napigator) get_napigator(); display_server_list(); } set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0); for (;;) io("main"); #ifdef GUI1 gui_exit(); #else nappanic("get_line() returned"); #endif return (-((int)0xdead)); }
int main(int argc, char *argv[]) { NODE *exec_list = NIL; NODE *cl_tail = NIL; int argc2; char **argv2; bottom_stack = &exec_list; /*GC*/ (void) addseg(); term_init(); init(); math_init(); my_init(); signal(SIGINT, logo_stop); if (argc < 2) { if (1 || isatty(1)) // fix this. for interactive from menu bar. { char version[20]; lcleartext(NIL); strcpy(version, "5.6"); ndprintf(stdout, message_texts[WELCOME_TO], version); new_line(stdout); } } setvalnode__caseobj(LogoVersion, make_floatnode(5.6)); setflag__caseobj(LogoVersion, VAL_BURIED); argv2 = argv; argc2 = argc; if (!strcmp(*argv + strlen(*argv) - 4, "logo")) { argv++; while (--argc > 0 && strcmp(*argv, "-") && NOT_THROWING) { argv++; } } argv++; while (--argc > 0) { if (command_line == NIL) cl_tail = command_line = cons(make_static_strnode(*argv++), NIL); else { setcdr(cl_tail, cons(make_static_strnode(*argv++), NIL)); cl_tail = cdr(cl_tail); } } setvalnode__caseobj(CommandLine, command_line); silent_load(Startuplg, logolib); silent_load(Startup, NULL); /* load startup.lg */ if (!strcmp(*argv2 + strlen(*argv2) - 4, "logo")) { argv2++; while (--argc2 > 0 && strcmp(*argv2, "-") && NOT_THROWING) { silent_load(NIL, *argv2++); } } for (;;) { if (NOT_THROWING) { check_reserve_tank(); current_line = reader(stdin, "? "); if (feof(stdin) && !isatty(0)) lbye(NIL); if (NOT_THROWING) { exec_list = parser(current_line, TRUE); if (exec_list != NIL) eval_driver(exec_list); } } if (stopping_flag == THROWING) { if (isName(throw_node, Name_error)) { err_print(NULL); } else if (isName(throw_node, Name_system)) break; else if (!isName(throw_node, Name_toplevel)) { err_logo(NO_CATCH_TAG, throw_node); err_print(NULL); } stopping_flag = RUN; } if (stopping_flag == STOP || stopping_flag == OUTPUT) { /* ndprintf(stdout, "%t\n", message_texts[CANT_STOP]); */ stopping_flag = RUN; } } //prepare_to_exit(TRUE); my_finish(); exit(0); return 0; }
/** * Instantiate a "term_data" structure * * This is one way to prepare the "term_data" structures and to * "link" the various informational pieces together. * * This function assumes that every window should be 80x24 in size * (the standard size) and should be able to queue 256 characters. * Technically, only the "main screen window" needs to queue any * characters, but this method is simple. One way to allow some * variation is to add fields to the "term_data" structure listing * parameters for that window, initialize them in the "init_xxx()" * function, and then use them in the code below. * * Note that "activation" calls the "Term_init_xxx()" hook for * the "term" structure, if needed. */ static void term_data_link(int i) { term_data *td = &data[i]; term *t = &td->t; /* Initialize the term */ term_init(t, 80, 24, 256); /* Choose "soft" or "hard" cursor XXX XXX XXX */ /* A "soft" cursor must be explicitly "drawn" by the program */ /* while a "hard" cursor has some "physical" existance and is */ /* moved whenever text is drawn on the screen. See "ui-term.c". */ /* t->soft_cursor = TRUE; */ /* Avoid the "corner" of the window XXX XXX XXX */ /* t->icky_corner = TRUE; */ /* Use "Term_pict()" for all attr/char pairs XXX XXX XXX */ /* See the "Term_pict_xxx()" function above. */ /* t->always_pict = TRUE; */ /* Use "Term_pict()" for some attr/char pairs XXX XXX XXX */ /* See the "Term_pict_xxx()" function above. */ /* t->higher_pict = TRUE; */ /* Use "Term_text()" even for "black" text XXX XXX XXX */ /* See the "Term_text_xxx()" function above. */ /* t->always_text = TRUE; */ /* Ignore the "TERM_XTRA_BORED" action XXX XXX XXX */ /* This may make things slightly more efficient. */ /* t->never_bored = TRUE; */ /* Ignore the "TERM_XTRA_FROSH" action XXX XXX XXX */ /* This may make things slightly more efficient. */ /* t->never_frosh = TRUE; */ /* Erase with "white space" XXX XXX XXX */ /* t->attr_blank = COLOUR_WHITE; */ /* t->char_blank = ' '; */ /* Prepare the init/nuke hooks */ t->init_hook = Term_init_xxx; t->nuke_hook = Term_nuke_xxx; /* Prepare the template hooks */ t->xtra_hook = Term_xtra_xxx; t->curs_hook = Term_curs_xxx; t->wipe_hook = Term_wipe_xxx; t->text_hook = Term_text_xxx; t->pict_hook = Term_pict_xxx; /* Remember where we came from */ t->data = td; /* Activate it */ Term_activate(t); /* Global pointer */ angband_term[i] = t; }
int main(int argc, char *argv[]) { char dic_filename[1024]; struct stat st; int update_interval = 300; /* milli second */ int is_print_random = 0; snprintf(dic_filename, sizeof(dic_filename), "%s%s%s", getenv("HOME"), "/", HOME_DIC_FILENAME); if(stat(dic_filename, &st) == -1) { strcpy(dic_filename, SYSTEM_DIC_PATH); } while(1) { int c; c = getopt(argc, argv, "d:t:1hvi:"); if(c == -1) break; switch(c) { case 'd': strcpy(dic_filename, optarg); break; case 't': theme_no = atoi(optarg); break; case 'i': update_interval = atoi(optarg); break; case '1': is_print_random = 1; break; case 'h': usage(argv[0]); case 'v': printf(PROGRAM " version " VERSION "\n"); exit(0); case ':': case '?': exit(1); } } if(is_print_random) { print_random(dic_filename); exit(0); } myd = myd_open(dic_filename); if(!myd) { perror(dic_filename); exit(1); } term_init(); term_timeout(update_interval); #ifdef USE_XSELECTION get_sel_init(getenv("DISPLAY")); #endif main_loop(); finish(0); return 0; }
/* * Prepare "S-Lang" for use by the file "z-term.c" * Installs the "hook" functions defined above */ errr init_sla(int argc, char **argv) { int err; term *t = &term_screen_body; /* Unused parameters */ (void)argc; (void)argv; /* Block signals, so signals cannot confuse the setup */ SLsig_block_signals(); /* Initialize, check for errors */ err = (SLang_init_tty(-1, TRUE, 0) == -1); /* Quit on error */ if (err) quit("S-Lang initialization failed"); /* Get terminal info */ SLtt_get_terminfo(); #ifdef HANDLE_SIGNALS /* Allow keyboard generated suspend signal (on Unix, ^Z) */ SLtty_set_suspend_state(TRUE); /* Instead of signal(), use sigaction():SA_RESTART via SLsignal() */ signal_aux = SLsignal; #endif /* Initialize some more */ if (SLsmg_init_smg() == -1) { SLang_reset_tty(); quit("Could not get virtual display memory"); } /* Check we have enough screen. */ err = ((SLtt_Screen_Rows < 24) || (SLtt_Screen_Cols < 80)); /* Quit with message */ if (err) { SLsmg_reset_smg(); SLang_reset_tty(); quit("S-Lang screen must be at least 80x24"); } /* Now let's go for a little bit of color! */ err = !has_colors(); /* Do we have color available? */ can_use_color = !err; /* Init the Color-pairs and set up a translation table */ /* If the terminal has enough colors */ /* Color-pair 0 is *always* WHITE on BLACK */ /* XXX XXX XXX See "main-gcu.c" for proper method */ /* Only do this on color machines */ if (can_use_color) { /* Prepare the color pairs */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_BLACK, COLOR_BLACK); init_pair(9, COLOR_BRED, COLOR_BLACK); init_pair(10, COLOR_BGREEN, COLOR_BLACK); init_pair(11, COLOR_BYELLOW, COLOR_BLACK); init_pair(12, COLOR_BBLUE, COLOR_BLACK); init_pair(13, COLOR_BMAGENTA, COLOR_BLACK); init_pair(14, COLOR_BCYAN, COLOR_BLACK); init_pair(15, COLOR_BBLACK, COLOR_BLACK); /* Prepare the color table */ colortable[0] = 7; /* Black */ colortable[1] = 0; /* White */ colortable[2] = 6; /* Grey XXX */ colortable[3] = 11; /* Orange XXX */ colortable[4] = 1; /* Red */ colortable[5] = 2; /* Green */ colortable[6] = 4; /* Blue */ colortable[7] = 3; /* Brown */ colortable[8] = 15; /* Dark-grey XXX */ colortable[9] = 14; /* Light-grey XXX */ colortable[10] = 5; /* Purple */ colortable[11] = 11; /* Yellow */ colortable[12] = 9; /* Light Red */ colortable[13] = 10; /* Light Green */ colortable[14] = 12; /* Light Blue */ colortable[15] = 3; /* Light Brown XXX */ } /* Done with blocking */ SLsig_unblock_signals(); /* Initialize the term */ term_init(t, 80, 24, 64); /* Stick in some hooks */ t->nuke_hook = Term_nuke_sla; t->init_hook = Term_init_sla; /* Stick in some more hooks */ t->xtra_hook = Term_xtra_sla; t->curs_hook = Term_curs_sla; t->wipe_hook = Term_wipe_sla; t->text_hook = Term_text_sla; /* Save the term */ term_screen = t; /* Activate it */ Term_activate(t); /* Success */ return 0; }
int main (int argc, char **argv) { fd_set reads; int nread; char * port; char * host; char * tmp; char stuff[100]; my_signal(SIGHUP, SIG_IGN); my_signal(SIGQUIT, SIG_IGN); my_signal(SIGINT, ignore); my_signal(SIGWINCH, sigwinch_func); if (argc != 3) /* no socket is passed */ my_exit(1); host = argv[1]; port = argv[2]; if ((data = connectory(host, port)) < 0) my_exit(23); if ((cmd = connectory(host, port)) < 0) my_exit(25); /* * First thing we do is tell the parent what protocol we plan on * talking. We will start the protocol at version 4, for this is * the fourth generation of wservs. * * We cannot use 'snprintf' here because we do not have the compat * functions and some systems do not have snprintf! This use of * sprintf is demonstrably safe. */ sprintf(stuff, "version=%d\n", CURRENT_WSERV_VERSION); write(cmd, stuff, strlen(stuff)); /* * Next thing we take care of is to tell the parent client * what tty we are using and tell them what geometry our screen * is. This provides some amount of sanity against whatever * brain damage might occur. The parent client takes our word * for what size this screen should be, and handles it accordingly. * * Warning: I am using sprintf() and write() because previous * attempts to use writev() have shown that linux does not have * an atomic writev() function (boo, hiss). The parent client * does not take kindly to this data coming in multiple packets. */ tmp = ttyname(0); sprintf(stuff, "tty=%s\n", tmp); write(cmd, stuff, strlen(stuff)); term_init(); /* Set up the xterm */ term_resize(); /* Figure out how big xterm is and tell epic */ /* * The select call.. reads from the socket, and from the window.. * and pipes the output from out to the other.. nice and simple. * The command pipe is write-only. The parent client does not * send anything to us over the command pipe. */ for (;;) { FD_ZERO(&reads); FD_SET(0, &reads); FD_SET(data, &reads); if (select(data + 1, &reads, NULL, NULL, NULL) <= 0) { if (errno == EINTR && got_sigwinch) { got_sigwinch = 0; term_resize(); } continue; } if (FD_ISSET(0, &reads)) { if ((nread = read(0, buffer, sizeof(buffer))) > 0) write(data, buffer, nread); else my_exit(3); } if (FD_ISSET(data, &reads)) { if ((nread = read(data, buffer, sizeof(buffer))) > 0) write(0, buffer, nread); else my_exit(4); } } my_exit(8); }