/* * This demonstrates the Cdk preprocess feature. */ int main (void) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKENTRY *widget = 0; const char *title = "<C>Type in anything you want\n<C>but the dreaded letter </B>G<!B>!"; char *info; const char *mesg[10]; char temp[256]; cdkscreen = initCDKScreen (NULL); /* Start CDK colors. */ initCDKColor (); /* Create the entry field widget. */ widget = newCDKEntry (cdkscreen, CENTER, CENTER, title, 0, A_NORMAL, '.', vMIXED, 40, 0, 256, TRUE, FALSE); /* Is the widget null? */ if (widget == 0) { /* Clean up. */ destroyCDKScreen (cdkscreen); endCDK (); printf ("Cannot create the entry box. Is the window too small?\n"); ExitProgram (EXIT_FAILURE); } setCDKEntryPreProcess (widget, entryPreProcessCB, 0); /* Activate the entry field. */ info = activateCDKEntry (widget, 0); /* Tell them what they typed. */ if (widget->exitType == vESCAPE_HIT) { mesg[0] = "<C>You hit escape. No information passed back."; mesg[1] = "", mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3); } else if (widget->exitType == vNORMAL) { mesg[0] = "<C>You typed in the following"; sprintf (temp, "<C>(%.*s)", (int)(sizeof (temp) - 20), info); mesg[1] = temp; mesg[2] = ""; mesg[3] = "<C>Press any key to continue."; popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 4); } /* Clean up and exit. */ destroyCDKEntry (widget); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }
int main(int argc, char **argv) { /* Declare variables. */ CDKSCREEN *cdkscreen; CDKLABEL *demo; WINDOW *cursesWin; char *mesg[4]; CDK_PARAMS params; CDKparseParams(argc, argv, ¶ms, CDK_MIN_PARAMS); /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK Colors. */ initCDKColor(); /* Set the labels up. */ mesg[0] = "</5><#UL><#HL(30)><#UR>"; mesg[1] = "</5><#VL(10)>Hello World!<#VL(10)>"; mesg[2] = "</5><#LL><#HL(30)><#LR>"; /* Declare the labels. */ demo = newCDKLabel (cdkscreen, CDKparamValue(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), mesg, 3, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, 'S', TRUE)); setCDKLabelBackgroundAttrib (demo, COLOR_PAIR(2)); /* Is the label null? */ if (demo == 0) { /* Clean up the memory. */ destroyCDKScreen (cdkscreen); /* End curses... */ endCDK(); /* Spit out a message. */ printf ("Oops. Can't seem to create the label. Is the window too small?\n"); ExitProgram (EXIT_FAILURE); } /* Draw the CDK screen. */ refreshCDKScreen (cdkscreen); waitCDKLabel (demo, ' '); /* Clean up. */ destroyCDKLabel (demo); destroyCDKScreen (cdkscreen); endCDK(); ExitProgram (EXIT_SUCCESS); }
static void do_options(int c, char *op[]) { register int i; if (c > 1) { for (i = 1; i < c; i++) { switch (op[i][0]) { default: case '?': (void) fprintf(stderr, "Usage: battle [-s | -b] [-c]\n"); (void) fprintf(stderr, "\tWhere the options are:\n"); (void) fprintf(stderr, "\t-s : play a salvo game\n"); (void) fprintf(stderr, "\t-b : play a blitz game\n"); (void) fprintf(stderr, "\t-c : ships may be adjacent\n"); ExitProgram(EXIT_FAILURE); break; case '-': switch (op[i][1]) { case 'b': blitz = 1; if (salvo == 1) { (void) fprintf(stderr, "Bad Arg: -b and -s are mutually exclusive\n"); ExitProgram(EXIT_FAILURE); } break; case 's': salvo = 1; if (blitz == 1) { (void) fprintf(stderr, "Bad Arg: -s and -b are mutually exclusive\n"); ExitProgram(EXIT_FAILURE); } break; case 'c': closepack = 1; break; default: (void) fprintf(stderr, "Bad arg: type \"%s ?\" for usage message\n", op[0]); ExitProgram(EXIT_FAILURE); } } } } }
static void usage(void) { #define SKIP(s) /* nothing */ #define KEEP(s) s "\n" static const char msg[] = { KEEP("") KEEP("Options:") SKIP(" -a arpanet (obsolete)") KEEP(" -c set control characters") SKIP(" -d dialup (obsolete)") KEEP(" -e ch erase character") KEEP(" -I no initialization strings") KEEP(" -i ch interrupt character") KEEP(" -k ch kill character") KEEP(" -m mapping map identifier to type") SKIP(" -p plugboard (obsolete)") KEEP(" -Q do not output control key settings") KEEP(" -q display term only, do no changes") KEEP(" -r display term on stderr") SKIP(" -S (obsolete)") KEEP(" -s output TERM set command") KEEP(" -V print curses-version") KEEP(" -w set window-size") KEEP("") KEEP("If neither -c/-w are given, both are assumed.") }; #undef KEEP #undef SKIP (void) fprintf(stderr, "Usage: %s [options] [terminal]\n", _nc_progname); fputs(msg, stderr); ExitProgram(EXIT_FAILURE); /* NOTREACHED */ }
/* ** bye_kids(exit-condition) ** ** Shutdown the terminal, clear the signals, and exit */ void bye_kids(int n) { /* reset the tty and exit */ ignoresig(); if (send_reset_init) { if (exit_ca_mode) { tc_putp(exit_ca_mode); } if (initial_stty_query(TTY_XON_XOFF)) { if (enter_xon_mode) { tc_putp(enter_xon_mode); } } else if (exit_xon_mode) { tc_putp(exit_xon_mode); } } if (debug_fp) { fclose(debug_fp); } if (log_fp) { fclose(log_fp); } tty_reset(); fclose(stdin); fclose(stdout); fclose(stderr); if (not_a_tty) sleep(1); ExitProgram(n); }
int main(int argc, char *argv[]) { WINDOW *stsbox; WINDOW *stswin; setlocale(LC_ALL, ""); if (argc < 2) { fprintf(stderr, "usage: %s file\n", argv[0]); return EXIT_FAILURE; } initscr(); test_set_escdelay(); test_set_tabsize(); stsbox = derwin(stdscr, BASE_Y, COLS, 0, 0); box(stsbox, 0, 0); wnoutrefresh(stsbox); stswin = derwin(stsbox, BASE_Y - 2, COLS - 2, 1, 1); keypad(stswin, TRUE); test_opaque(1, argv, stswin); endwin(); ExitProgram(EXIT_SUCCESS); }
static void die(int onsig) { (void) signal(onsig, SIG_IGN); endwin(); ExitProgram(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { WINDOW *chrbox; WINDOW *chrwin; WINDOW *strwin; setlocale(LC_ALL, ""); if (argc < 2) { fprintf(stderr, "usage: %s file\n", argv[0]); return EXIT_FAILURE; } initscr(); chrbox = derwin(stdscr, BASE_Y, COLS, 0, 0); box(chrbox, 0, 0); wnoutrefresh(chrbox); chrwin = derwin(chrbox, 1, COLS - 2, 1, 1); strwin = derwin(chrbox, 4, COLS - 2, 2, 1); test_inchs(1, argv, chrwin, strwin); endwin(); ExitProgram(EXIT_SUCCESS); }
static void failed(const char *msg) { perror(msg); cleanup(); ExitProgram(EXIT_FAILURE); }
int main(int argc, char *argv[]) { long badanswer = 1; long *response = &badanswer; setlocale(LC_ALL, ""); initscr(); scrollok(stdscr, TRUE); idlok(stdscr, TRUE); echo(); #if 0 trace(TRACE_UPDATE | TRACE_CALLS); #endif while (argc > 1) { if (isdigit(UChar(*argv[1]))) move(atoi(argv[1]), 0); else if (!strcmp(argv[1], "-k")) keypad(stdscr, TRUE); argc--, argv++; } while (badanswer) { printw("Enter a number (0 to quit):\n"); printw("--> "); scanw("%20ld", response); /* yes, it's a pointer */ } endwin(); ExitProgram(EXIT_SUCCESS); }
static void failed(const char *s) { perror(s); endwin(); ExitProgram(EXIT_FAILURE); }
static void usage(void) { static const char *msg[] = { "Usage: demo_terminfo [options] [terminal]", "", "If no options are given, print all (boolean, numeric, string)", "capabilities for the given terminal, using short names.", "", "Options:", " -b print boolean-capabilities", " -f print full names", " -n print numeric-capabilities", " -r COUNT repeat for given count", " -s print string-capabilities", #ifdef NCURSES_VERSION " -x print extended capabilities", #endif }; unsigned n; for (n = 0; n < SIZEOF(msg); ++n) { fprintf(stderr, "%s\n", msg[n]); } ExitProgram(EXIT_FAILURE); }
static void onsig(int n GCC_UNUSED) { interrupted = TRUE; cleanup(); ExitProgram(EXIT_FAILURE); }
static void onsig(int n GCC_UNUSED) { curs_set(1); endwin(); ExitProgram(EXIT_FAILURE); }
int main(int argc, char *argv[]) { int ch; char buffer[80]; attr_t underline; bool i_option = FALSE; setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "i")) != -1) { switch (ch) { case 'i': i_option = TRUE; break; default: usage(); } } printf("starting filter program using %s...\n", i_option ? "initscr" : "newterm"); filter(); if (i_option) { initscr(); } else { (void) newterm((char *) 0, stdout, stdin); } cbreak(); keypad(stdscr, TRUE); if (has_colors()) { int background = COLOR_BLACK; start_color(); #if HAVE_USE_DEFAULT_COLORS if (use_default_colors() != ERR) background = -1; #endif init_pair(1, COLOR_CYAN, (short) background); underline = (attr_t) COLOR_PAIR(1); } else { underline = A_UNDERLINE; } while (new_command(buffer, sizeof(buffer) - 1, underline) != ERR && strlen(buffer) != 0) { reset_shell_mode(); printf("\n"); fflush(stdout); IGNORE_RC(system(buffer)); reset_prog_mode(); touchwin(stdscr); erase(); refresh(); } printw("done"); refresh(); endwin(); ExitProgram(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int n; int repeat; char *name; int r_opt = 1; while ((n = getopt(argc, argv, "bfnr:sx")) != -1) { switch (n) { case 'b': b_opt = TRUE; break; case 'f': f_opt = TRUE; break; case 'n': n_opt = TRUE; break; case 'r': if ((r_opt = atoi(optarg)) <= 0) usage(); break; case 's': s_opt = TRUE; break; #ifdef NCURSES_VERSION case 'x': x_opt = TRUE; use_extended_names(TRUE); break; #endif default: usage(); break; } } if (!(b_opt || n_opt || s_opt || x_opt)) { b_opt = TRUE; n_opt = TRUE; s_opt = TRUE; } for (repeat = 0; repeat < r_opt; ++repeat) { if (optind < argc) { for (n = optind; n < argc; ++n) { demo_terminfo(argv[n]); } } else if ((name = getenv("TERM")) != 0) { demo_terminfo(name); } else { static char dumb[] = "dumb"; demo_terminfo(dumb); } } ExitProgram(EXIT_SUCCESS); }
XilinxGUI::XilinxGUI(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { ui.setupUi(this); QObject::connect(ui.actExit, SIGNAL(triggered()), this, SLOT(ExitProgram())); QObject::connect(ui.btnShowPic, SIGNAL(clicked()), this, SLOT(ShowPic())); }
static void FatalError(const char *f,...) { va_list args; va_start(args, f); vfprintf(stderr, f, args); va_end(args); ExitProgram(1); }
static void exit_error(void) { restore_tty_settings(); (void) fprintf(stderr, "\n"); fflush(stderr); ExitProgram(EXIT_FAILURE); /* NOTREACHED */ }
static RETSIGTYPE sighndl(int signo) { signal(signo, sighndl); sigtermed = signo; if (redirected) { endwin(); ExitProgram(EXIT_FAILURE); } }
static void exit_error(void) { if (can_restore) SET_TTY(STDERR_FILENO, &original); (void) fprintf(stderr, "\n"); fflush(stderr); ExitProgram(EXIT_FAILURE); /* NOTREACHED */ }
static RETSIGTYPE uninitgame(int sig GCC_UNUSED) /* end the game, either normally or due to signal */ { clear(); (void) refresh(); (void) reset_shell_mode(); (void) echo(); (void) endwin(); ExitProgram(sig ? EXIT_FAILURE : EXIT_SUCCESS); }
void GetInput() { int ch; static int chtmp; int tmp; ch = getch(); //Buffer input if(ch == ERR) ch = chtmp; chtmp = ch; switch (ch) { case KEY_UP: case 'w': case 'W': if(Loc[4][0] == 0) tmp = 28; else tmp = Loc[4][0] - 1; if((Level[tmp][Loc[4][1]] != 1) && (Level[tmp][Loc[4][1]] != 4)) { Dir[4][0] = -1; Dir[4][1] = 0; } break; case KEY_DOWN: case 's': case 'S': if(Loc[4][0] == 28) tmp = 0; else tmp = Loc[4][0] + 1; if((Level[tmp][Loc[4][1]] != 1) && (Level[tmp][Loc[4][1]] != 4)) { Dir[4][0] = 1; Dir[4][1] = 0; } break; case KEY_LEFT: case 'a': case 'A': if(Loc[4][1] == 0) tmp = 27; else tmp = Loc[4][1] - 1; if((Level[Loc[4][0]][tmp] != 1) && (Level[Loc[4][0]][tmp] != 4)) { Dir[4][0] = 0; Dir[4][1] = -1; } break; case KEY_RIGHT: case 'd': case 'D': if(Loc[4][1] == 27) tmp = 0; else tmp = Loc[4][1] + 1; if((Level[Loc[4][0]][tmp] != 1) && (Level[Loc[4][0]][tmp] != 4)) { Dir[4][0] = 0; Dir[4][1] = 1; } break; case 'p': case 'P': PauseGame(); chtmp = getch(); break; case 'q': case 'Q': ExitProgram("Bye"); break; } }
int main(int argc, char *argv[]) { int ch; setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "dj:m:o:t:")) != -1) { switch (ch) { case 'd': d_option = TRUE; break; case 'j': j_value = atoi(optarg); if (j_value < NO_JUSTIFICATION || j_value > JUSTIFY_RIGHT) usage(); break; case 'm': m_value = atoi(optarg); break; case 'o': o_value = atoi(optarg); break; case 't': t_value = optarg; break; default: usage(); } } initscr(); cbreak(); noecho(); raw(); nonl(); /* lets us read ^M's */ intrflush(stdscr, FALSE); keypad(stdscr, TRUE); if (has_colors()) { start_color(); init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_CYAN, COLOR_BLACK); bkgd((chtype) COLOR_PAIR(1)); refresh(); } demo_forms(); endwin(); ExitProgram(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int c; bool monochrome = FALSE; InitPanel myInit = init_panel; FillPanel myFill = fill_panel; setlocale(LC_ALL, ""); while ((c = getopt(argc, argv, "i:o:mwx")) != -1) { switch (c) { case 'i': log_in = fopen(optarg, "r"); break; case 'o': log_out = fopen(optarg, "w"); break; case 'm': monochrome = TRUE; break; #if USE_WIDEC_SUPPORT case 'w': myInit = init_wide_panel; myFill = fill_wide_panel; break; #endif case 'x': unboxed = TRUE; break; default: usage(); } } if (unboxed) myFill = fill_unboxed; initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); use_colors = monochrome ? FALSE : has_colors(); if (use_colors) start_color(); demo_panels(myInit, myFill); endwin(); close_input(); close_output(); ExitProgram(EXIT_SUCCESS); }
static void quit(int status, const char *fmt,...) { va_list argp; va_start(argp, fmt); fprintf(stderr, "%s: ", prg_name); vfprintf(stderr, fmt, argp); fprintf(stderr, "\n"); va_end(argp); ExitProgram(status); }
static void failed(const char *msg) { int code = errno; (void) fprintf(stderr, "%s: %s: %s\n", _nc_progname, msg, strerror(code)); restore_tty_settings(); (void) fprintf(my_file, "\n"); fflush(my_file); ExitProgram(ErrSystem(code)); /* NOTREACHED */ }
int main(int argc, char *argv[]) { if (argc > 1) { railroad(argv + 1); } else { static char world[] = "Hello World"; static char *hello[] = {world, 0}; railroad(hello); } ExitProgram(EXIT_SUCCESS); }
static void usage(void) { static const char *msg[] = { "Usage: filter [options]" ,"" ,"Options:" ," -i use initscr() rather than newterm()" }; unsigned n; for (n = 0; n < SIZEOF(msg); n++) fprintf(stderr, "%s\n", msg[n]); ExitProgram(EXIT_FAILURE); }
static void randomfire(int *px, int *py) /* random-fire routine -- implements simple diagonal-striping strategy */ { static int turncount = 0; static int srchstep = BEGINSTEP; static int huntoffs; /* Offset on search strategy */ int ypossible[BWIDTH * BDEPTH], xpossible[BWIDTH * BDEPTH], nposs; int ypreferred[BWIDTH * BDEPTH], xpreferred[BWIDTH * BDEPTH], npref; int x, y, i; if (turncount++ == 0) huntoffs = rnd(srchstep); /* first, list all possible moves */ nposs = npref = 0; for (x = 0; x < BWIDTH; x++) for (y = 0; y < BDEPTH; y++) if (!hits[COMPUTER][x][y]) { xpossible[nposs] = x; ypossible[nposs] = y; nposs++; if (((x + huntoffs) % srchstep) != (y % srchstep)) { xpreferred[npref] = x; ypreferred[npref] = y; npref++; } } if (npref) { i = rnd(npref); *px = xpreferred[i]; *py = ypreferred[i]; } else if (nposs) { i = rnd(nposs); *px = xpossible[i]; *py = ypossible[i]; if (srchstep > 1) --srchstep; } else { error("No moves possible?? Help!"); ExitProgram(EXIT_FAILURE); /*NOTREACHED */ } }