예제 #1
0
int main()
{
    char users_name[ 100 ];
    
    initscr();
    (void)echo();
    
    addstr( "What is your name> " );
    refresh();
    getnstr( users_name, sizeof( users_name ) - 1 );
    
    /* Here is where we clear the screen.                  */
    /* (Remember, when using Curses, no change will appear */
    /* on the screen until <b>refresh</b>() is called.     */
    clear();
    
    printw( "Greetings and salutations %s!\n", users_name );
    refresh();
    
    printw( "\n\n\nPress ENTER to quit." );
    refresh();
    getnstr( users_name, sizeof( users_name ) - 1 );
    
    endwin();
    return 0;
}
예제 #2
0
파일: main.c 프로젝트: compmstr/dcpu16-c
int main(int argc, char **argv){
	initscr();
	cbreak();
	noecho();

	char input;
	char buf1[256];
	char buf2[256];
	while(1){
		clear();
		printw("Menu:\n--------------\n1) Compile\n2) Run\nq) Exit\n----------\n> ");
		input = getch();
		if(input == '1'){
			clear();
			printw("Compiling: \n");
			printw("Enter file to compile (test.dasm) : ");

			echo();
			refresh();
			getnstr(buf1, 255);
			printw("Enter file to output (test.dbin) : ");
			refresh();
			getnstr(buf2, 255);

			noecho();

			if(strlen(buf1) == 0){
				strncpy(buf1, "test.dasm", 100);
			}
			if(strlen(buf2) == 0){
				strncpy(buf2, "test.dbin", 100);
			}

			printw("Compiling %s to %s\n", buf1, buf2);
			refresh();

			printw("Press any key to continue");
			refresh();
			getch();
		}
		if(input == '2'){
			clear();
			printw("Running: \n");
			refresh();
			sleep(1);
		}
		if(input == 'q'){
			clear();
			printw("Exiting... \n");
			refresh();
			break;
		}
	}

	endwin();
	
  return 0;
}
예제 #3
0
/* prompt the player for their move */
static void do_human_move(int side)
{
    bool good=false;
    print_string("\nWHAT ACTION DO YOU WISH TO TAKE?\n\n  1. MISSILE LAUNCH\n  2. PEACE TALKS\n  3. SURRENDER\n  4. NOTHING\n\n");
    int move=0;
    while(!good)
    {
        print_string("PLEASE CHOOSE ONE:  ");
        char buf[32];
        getnstr(buf, 32);
        sscanf(buf, "%u", &move);
        if(move>0 && move<5)
            good=true;
    }
    switch(move)
    {
    case 1:
        do_missile_launch(side);
        break;
    case 2:
        do_peace_talks(side);
        break;
    case 3:
        surrender=true;
        winner=side==1?2:1;
        break;
    case 4:
        break;
    }
}
예제 #4
0
char* getInfo(int request)
{
	#define NAME_LENGTH 40
	
	char buffer[NAME_LENGTH];
	char* ptr;
		
	if(request == NL_ASK_NAME)
		message = "Enter your name: ";
	else if(request == NL_ASK_IP)
		message = "dest:port: ";
	else if(request == NL_ASK_FILE)
		message = "File to send: ";
	else// if(request == NL_ASK_MESSAGE)
		message = "Enter your message: ";
/*	else
		message = "Unknown request: ";*/

	redraw(0);
	getnstr(buffer, NAME_LENGTH);
	message = NULL;
	
	if((ptr = strchr(buffer, '\n')) != NULL)
		*ptr = '\0';
		
	if(request == NL_ASK_NAME)
	{
		free(my_name);
		my_name = m_strdup(buffer);
	}
	
	return m_strdup(buffer);
}
예제 #5
0
파일: addspot.c 프로젝트: wildj79/tlf
int addspot(void)
{
    extern float freq;
    extern char hiscall[];
    extern int trx_control;

    char frequency[8];

    if (strlen(hiscall) < 3)
	return(0);

    if (trx_control == 0) {

	attron(COLOR_PAIR(C_LOG) | A_STANDOUT);

	mvprintw(13, 20, "freq.: ");
	echo();
	getnstr(frequency, 7);
	noecho();
	freq = atof(frequency);
    }

    add_to_spots(hiscall, freq);

    hiscall[0] = '\0';

    return (0);
}
예제 #6
0
파일: lancode.c 프로젝트: thatchristoph/tlf
int talk(void)
{

    char talkline[61] = "";

    mvprintw(24, 0,
	     "                                                                           ");
    mvprintw(24, 0, "T>");
    refreshp();
    echo();
    getnstr(talkline, 60);
    noecho();

    strcat(talkline, "\n");

    send_lan_message(TLFMSG, talkline);

    talkline[0] = '\0';
    attron(COLOR_PAIR(C_HEADER));
    mvprintw(24, 0,
	     "                                                                               ");
    refreshp();

    return (0);
}
예제 #7
0
static int
new_command(char *buffer, int length, attr_t underline)
{
    int code;

    attron(A_BOLD);
    printw("Command: ");
    attron(underline);
    code = getnstr(buffer, length);
    /*
     * If this returns anything except ERR/OK, it would be one of ncurses's
     * extensions.  Fill the buffer with something harmless that the shell
     * will execute as a comment.
     */
#ifdef KEY_EVENT
    if (code == KEY_EVENT)
	strcpy(buffer, "# event!");
#endif
#ifdef KEY_RESIZE
    if (code == KEY_RESIZE) {
	strcpy(buffer, "# resize!");
	getch();
    }
#endif
    attroff(underline);
    attroff(A_BOLD);
    printw("\n");

    return code;
}
예제 #8
0
void menuInteractive()
{
    int i, num;
    char buf[255];
    
    while (1) {
        mvprintw (2, 0, "Dvorak7Min, Ragnar Hojland Espinosa, 1998-2003" );
        mvprintw (3, 0, "enhanced by Smoke of CRAP, 1999 and Nopik, 2003");
        for (i = 0; lessons[i*2]; ++i) {
            mvprintw (i/2 + 5, (i%2) * 40, "%2d. %s", i+1, lessons[i*2]);
        }
        move (21, 0); clrtobot();
        mvprintw (21, 0, "Type a lesson number ([N]astiness [H]ide keyboard [Q]uit)? ");
        refresh();
        echo();
        getnstr (buf, sizeof(buf));
        buf[0] = toupper(buf[0]);
        if (buf[0] == 'N') {
            nastiness = !nastiness;
            if (nastiness)
                mvprintw (23, 0, "Nastiness is now turned ON. Press any key.");
            else
                mvprintw (23, 0, "Nastiness is now turned OFF. Press any key.");
            getch();
            continue;
        }

        if (buf[0] == 'H') {
            hideKeys = !hideKeys;
            if (hideKeys)
                mvprintw (23, 0, "Keyboard layout is now OFF. Press any key.");
            else
                mvprintw (23, 0, "Keyboard layout is now ON. Press any key.");
            getch();
            continue;
        }
	
        if (buf[0] == 'Q' || buf[0] == 27) {
            clear();
            move (0,0);
            refresh();
            return;
        }
        num = atoi (buf);
        if (!buf[0] || num < 1 || num > i) {
            mvprintw (23, 0, "Invalid lesson number. Press any key.");
            getch();
            continue;
        }
        
        clear();
        refresh();
        do_text(lessons[(num-1)*2+1]);
    }
}
int main() {
  // the space in front serves a purpose; it isn't ever printed, but allows
  // a clean while loop. See the code at line 47.
  char name[NAME_LEN];
  char password[PW_LEN];
  const char *real_password = "******";

  int i = 0;
  initscr();

  move(5, 10);
  printw("%s", "Please login:"******"%s", "User name:");
  getnstr(name, NAME_LEN); // get a string with length-checking
  // normally no referesh is needed above because get functions automatically
  // refresh. In some old versions of curses this is not the case.
  //
  // note that printw leaves the curser at the end of the printed string

  move(8, 10);
  printw("%s", "Password:"******"Correct");
  } else {
      printw("Incorrect");
  }
  printw(" password.");

  refresh();
  sleep(2);

  endwin();
  exit(EXIT_SUCCESS);
}
예제 #10
0
파일: ttylock.c 프로젝트: mcarden/junkcode
int main (int argc, char* argv[])
{
    char password[LEN+1];
    int  pigs_can_fly = 1;

    /* Catch what we can, pretend that SIGKILL is catchable */
    if (DEBUG != 1)
    {
        signal(SIGHUP,  SIG_IGN);
        signal(SIGINT,  SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
        signal(SIGKILL, SIG_IGN);
        signal(SIGTERM, SIG_IGN);
        signal(SIGTSTP, SIG_IGN);
    }

    /* Initialise Curses */
    initscr();

    /* Let me process everything, and turn off auto echo */
    raw(); 
    if (DEBUG != 1)
    {
        noecho();
    }

    while (pigs_can_fly) {

        /* printf won't work due to noecho() */
        printw("Password:"******"Without the password, you're going nowhere :-)\n");
        }
    }

    /* Turn echo'ing back on, and leave raw mode */
    if (DEBUG != 1)
    {
        echo();
    }
    noraw();

    /* Cleanup from curses */
    endwin();

    return 0;
}
예제 #11
0
int get_number(INT *i)
{
  int err;
  char tmp[BLOCK_SEARCH_SIZE];
  echo();
  getnstr(tmp, BLOCK_SEARCH_SIZE - 1);
  noecho();
  if (strbeginswith(tmp, "0x"))
    err = sscanf(tmp + strlen("0x"), "%llx", i);
  else
    err = sscanf(tmp, "%lld", i);
  return err == 1;
}
예제 #12
0
파일: Terminal.cpp 프로젝트: Lisoph/MORL
  std::string ReadString() {
    nodelay(stdscr, false);
    echo();

    std::unique_ptr<char[]> buf(new char[ReadStringBufferSize]);
    getnstr(buf.get(), ReadStringBufferSize - 1);
    buf[ReadStringBufferSize - 1] = 0;
    std::string str{buf.get()};

    noecho();
    nodelay(stdscr, true);
    return str;
  }
예제 #13
0
파일: main.c 프로젝트: stoicism2323/cReddit
char *getPassword()
{
    const int MAX_PASSWD_SIZE = 200;
    char *password = malloc(MAX_PASSWD_SIZE);

    clear();
    mvprintw(0, 0, "Password: ");
    refresh();

    getnstr(password, MAX_PASSWD_SIZE);
    password[MAX_PASSWD_SIZE - 1] = '\0';
    return password;
}
예제 #14
0
int main()
{
  char buf[BUFSIZ];
  setlocale(LC_ALL, "");
  initscr();

  move(0, 0);
  addstr("こんにちWorld");
  getnstr(buf, BUFSIZ);
  addstr(buf);

  endwin();
  return (0);
}
예제 #15
0
int main (void) {

    char first[4];
    char last[4];

    initscr();
    addstr("What are first 3 of your first name? ");
    refresh();
    getnstr(first,3);

    addstr("What are first 3 of last name? ");
    refresh();
    getnstr(last,3);

    addstr("Your secret agent name is ");
    printw("%s%s", first, last);
    addch('!');
    refresh();
    getch();

    endwin();
    return 0;
}
예제 #16
0
파일: Engine.cpp 프로젝트: case93/Chiasmus2
void Engine::processInput()
{
	mvprintw(50,0,"Input: ");
	int input = getch();
	char line[100];

	if (input == 'c')
		running = false;
	else if (input == '1') {
		mvprintw(50,0,"Message to game log: ");
		getnstr(line,101);
		windowM->writeToGameLog(line);
	}
	else if (input == '2') {
		mvprintw(50,0,"Message to debug log: ");
		getnstr(line,101);
		windowM->writeToDebugLog(line);
	}
	else
		listenerCM->addNoise(player,NSPair(input,NullEntity));

	mvhline(50,0,' ',103);
}
예제 #17
0
void set_proposal_name(proposal_info_type *info) {
    char buf[101];
    size_t rcv_cnt;
    
    print_str("Enter the proposal name (max 100 chars): ");
    
    rcv_cnt=getnstr(buf, 101);
    
    if (rcv_cnt > 0)
		strlcpy(buf, info->title, rcv_cnt);

    return;
    
}
예제 #18
0
파일: pager.c 프로젝트: tamentis/mdp
/*
 * Request search keywords from the user.
 */
static void
keyword_prompt(void)
{
	char kw[50] = "";

	curs_set(1);

	wmove(screen, window_height - 1, 0);
	waddstr(screen, "Keywords: ");

	refresh();
	echo();
	getnstr(kw, 50);

	keywords_load_from_char(kw);
}
예제 #19
0
int main()
{
    control_config_t cfg;
    int i;
    load_config("cfg.json", &cfg);
    printf("cfg loaded\narea count=%d\n", cfg.area_count);
    for(i=0; i<cfg.area_count; ++i)
    {
        printf("area [%d]: \tleft top x=%lf, y=%lf, z=%lf\n\t\tright buttom"
               "x=%lf, y=%lf, z=%lf\n\n",
               i, cfg.area[i].lt.x,cfg.area[i].lt.y,cfg.area[i].lt.z,
               cfg.area[i].rb.x,cfg.area[i].rb.y,cfg.area[i].rb.z);
    }
    printf("time period is %d\n", cfg.time_period);
    printf("picture store path is %s\n", cfg.pic_path);
    printf("There are %d channel\n", cfg.channel_count);
    for(i=0; i< cfg.channel_count; ++i)
    {
        printf("channel [%d]\t net device name :%s\n", i, cfg.net_device[i].name);
    }
    //return 0;
    mtig_thread_start();
    sleep(2);

    initscr();
    char line[256];
    mtig_data_t data;
    while(1)
    {
        getnstr(line, 255);
        //mvscanw(20,0,"%s", line);
        if( line[0] == 'q')
        {
            break;
        }
        //sleep(1);
        //mtig_read_data(&data);
        //mvprintw(20,0, "
        //printf("roll: %d, pitch:%f,yaw:%f\n", data.status, data.pitch, data.yaw);

    }
    endwin();

    mtig_thread_stop();

    return 0;
}
예제 #20
0
파일: addspot.c 프로젝트: patlc/tlf
int addspot(void)
{
    extern float freq;
    extern char hiscall[];
    extern int trx_control;
    extern int lanspotflg;
    extern struct tm *time_ptr;
    extern char thisnode;

    char spotline[160];
    char frequency[8];
    char spottime[6];

    if (strlen(hiscall) < 3)
	return(0);

    if (trx_control == 0) {

	attron(COLOR_PAIR(C_LOG) | A_STANDOUT);

	mvprintw(13, 20, "freq.: ");
	echo();
	getnstr(frequency, 7);
	noecho();
	freq = atof(frequency);
    }

    sprintf(spotline, "DX de TLF-%c:     %9.3f  %s", thisnode, freq, hiscall);

    strcat(spotline, "                                           ");

    get_time();

    strftime(spottime, sizeof(spottime), "%H%MZ", time_ptr);
    strcpy(spotline + 70, spottime);
    strcat(spotline, "\n\n");

    send_lan_message(TLFSPOT, spotline);
    lanspotflg = 1;
    addtext(spotline);
    lanspotflg = 0;
    spotline[0] = '\0';
    hiscall[0] = '\0';

    return (0);
}
예제 #21
0
int displayMessageAndGetString(char *msg, char **last, char *p, int p_size)
{
  int ret = TRUE;

  displayOneLineMessage(msg);
  ungetstr(*last);
  echo();
  getnstr(p, p_size - 1);
  noecho();
  if (*p == '\0') {
    if (*last) strcpy(p, *last); else ret = FALSE;
  } else {
    FREE(*last);
    *last = strdup(p);
  }
  return ret;
}
예제 #22
0
int main(void)
{
	char buffer[81];

	initscr();

	addstr("Type on the keyboard whilest I wait...\n");
	refresh();
	napms(5000);			/* 5 seconds */

	addstr("Here is what you typed:\n");
	getnstr(buffer,80);
	refresh();
	
	endwin();
	return 0;
}
예제 #23
0
void ler_movimento(char jogador, unsigned int mov[4]) {
    if(jogador == MERCENARIOS)
        addstr("Mercenario, ");
    else
        addstr("Guarda, ");
    addstr("qual o seu movimento? ");
    refresh();
    nocbreak();
    echo();
    char in[5];
    getnstr(in, 5);
    cbreak();
    noecho();
    mov[0] = toupper(in[0]) - 'A';
    mov[1] = in[1] - '1';
    mov[2] = toupper(in[3]) - 'A';
    mov[3] = in[4] - '1';
}
예제 #24
0
파일: display.c 프로젝트: UNGLinux/Obase
int
readline(char *buffer, int size)
{
	size_t cnt;

	/* allow room for null terminator */
	size -= 1;

	if (smart_terminal)
		getnstr(buffer, size);
	else
		return readlinedumb(buffer, size);

	cnt = strlen(buffer);
	if (cnt > 0 && buffer[cnt - 1] == '\n')
		buffer[cnt - 1] = '\0';
	return (cnt == 0 ? -1 : cnt);
}
예제 #25
0
int main(int argc, char *argv[])
{
        char buffer[81];

        initscr();

        addstr("Type on the keyboard whilst I wait...\n");
        refresh();
        napms(5000);    // 5 seconds

        addstr("Here is what you typed:\n");
        flushinp();
        getnstr(buffer, 80);
        refresh();

        endwin();
        return 0;
}
예제 #26
0
파일: empire.c 프로젝트: ErikStaats/empire
static void SummaryScreen(void)
{
    char     input[80];
    Player  *player;
    Country *country;
    int      i;

    /* Reset screen. */
    clear();
    move(0, 0);

    /* Display summary. */
    printw("SUMMARY\n");
    printw("NOBLES   SOLDIERS   MERCHANTS   SERFS   LAND    PALACE\n\n");
    for (i = 0; i < COUNTRY_COUNT; i++)
    {
        /* Get the country and player records. */
        country = &(countryList[i]);
        player = &(playerList[i]);

        /* Skip dead players. */
        if (player->dead)
            continue;

        /* Display player summary. */
        printw("%s %s OF %s\n", player->title, player->name, country->name);
        printw(" %3d       %5d       %5d    %6d   %5d  %3d%%\n",
               player->nobleCount,
               player->soldierCount,
               player->merchantCount,
               player->serfCount,
               player->land,
               10 * player->palaceCount);
    }

    /* Wait for player. */
    printw("<ENTER>? ");
    getnstr(input, sizeof(input));
}
예제 #27
0
파일: IoCurses.c 프로젝트: Akiyah/io
IoObject *IoCurses_get(IoCurses *self, IoObject *locals, IoMessage *m)
{
	/*doc Curses get(n)
	Returns n characters from the terminal. n is optional and defaults to 1.
	*/

	int inputCharacterLimit = IO_CURSES_INPUT_BUFFER_LENGTH;
	char string[inputCharacterLimit];

	if (IoMessage_argCount(m) > 0)
	{
		IoNumber *number = IoMessage_locals_numberArgAt_(m, locals, 0);
		inputCharacterLimit = IoNumber_asInt(number);
	}

	if (getnstr(string, inputCharacterLimit) == ERR)
	{
		return IONIL(self);
	}

	return IoState_symbolWithCString_(IOSTATE, string);
}
예제 #28
0
int main(void)
{
	FILE *termin,*termout;
	SCREEN *tp1,*tp2;
	char name[81];

/* Open terminal one for reading
   Open terminal two for writing */
	termin = fopen(INTERM,"r");
	termout = fopen(OUTTERM,"w");
	if( termin==NULL || termout==NULL )
	{
			puts("Unable to open terminal.");
			return(1);
	}

/* set up the new terminal in NCurses */
	tp2 = newterm(NULL,termout,termin);
	if( tp2 == NULL)
	{ 
		puts("Unable to open terminal window.");
		return(2);
	}

/* NCurses is now started for the new terminal */
	tp1 = set_term(tp2);
	printw("Welcome to Curses output on terminal %s.\n",OUTTERM);
	printw("You can type on terminal %s, and see it here.\n",INTERM);
	addstr("What is your name: ");
	refresh();
	getnstr(name,80);
	printw("%s, glad to have you aboard!",name);
	refresh();
	getch();

	endwin();
	return 0;
}
예제 #29
0
파일: joshua.c 프로젝트: laudarch/wargames
void be_joshua()
{
  initscr();
  clear();
  signal(SIGINT, &cleanup);
  /*
  start_color();
  init_pair(1, COLOR_BLUE, COLOR_BLACK);
  attron(COLOR_PAIR(1));*/
  scrollok(stdscr, true);
  bool gamesPhase=false;
  char buf[33];
  int maxx, maxy;
  getmaxyx(stdscr, maxy, maxx);
  for(int i=0;i<maxx*2;++i)
    {
      print_string(" ");
    }
  do {
    if(!gamesPhase)
      print_string("LOGON: ");
    refresh();
    int ret=getnstr(buf, 32);
    allLower(buf);
    usleep(SLEEP_TIME*100);
    if(strcmp(buf, "help logon")==0 && !gamesPhase)
      {
        print_string("\nHELP NOT AVAILABLE\n\n\n");
      }
    else if(strcmp(buf, "help games")==0)
      {
        print_string("\n'GAMES' REFERS TO MODELS, SIMULATIONS AND GAMES\nWHICH HAVE TACTICAL AND STRATEGIC APPLICATIONS.\n\n\n");
        gamesPhase=true;
      }
    else if(strcmp(buf, "list games")==0 && gamesPhase)
      {
        print_string("\nFALKEN'S MAZE\nBLACK JACK\nGIN RUMMY\nHEARTS\nBRIDGE\nCHECKERS\nCHESS\nPOKER\nFIGHTER COMBAT\nGUERRILLA ENGAGEMENT\nDESERT WARFARE\nAIR-TO-GROUND ACTIONS\nTHEATERWIDE TACTICAL WARFARE\nTHEATERWIDE BIOTOXIC AND CHEMICAL WARFARE\n\nGLOBAL THERMONUCLEAR WAR\n\n\n");
      }
    else if(ret==ERR || strcmp(buf, "joshua") && !gamesPhase)
      {
        print_string("\nIDENTIFICATION NOT RECOGNIZED BY SYSTEM\n--CONNECTION TERMINATED--");
        return;
      }
  } while(strcmp(buf, "joshua") || gamesPhase);
  random_stuff();
  usleep(SLEEP_TIME*100);
  print_string("GREETINGS, PROFESSOR FALKEN.\n\n");
  refresh();
  getnstr(buf, 32);
  allLower(buf);
  remove_punct(buf);
  for(int i=0;i<sizeof(exit_triggers)/sizeof(const char*);++i)
    {
      if(strcmp(buf, exit_triggers[i])==0)
	{
	  print_string("\n\n");
	  print_string(exit_responses[rand()%sizeof(exit_responses)/sizeof(const char*)]);
	  print_string("\n--CONNECTION TERMINATED--");
	  return;
	}
    }
  print_string("\n\nHOW ARE YOU FEELING TODAY?\n\n");
  refresh();
  do_chatbot();
  endwin();
}
예제 #30
0
파일: client_main.c 프로젝트: zt515/wetalk
int client_main(int argc, char **argv) {
	if (argc < 4) {
		fprintf(stderr, "Usage: wetalk -c <ip> <uid> <password>\n"
						"Or   : wetalk -r <ip> <username> <password>\n");
		return wetalk_usage("wetalk");
	}

	int uid = 0;
	char *ipaddr = argv[1];
	char *password = argv[3];

	if (strlen(password) >= PASSWORD_MAX) {
		fprintf(stderr, "错误的密码长度\n");
		return 1;
	}

	if (!client_init(argv[1], on_msg_recv)) {
		wetalk_error("初始化客户端失败\n");
	}

	if (!strcmp(argv[0], "-r")) {
		uid = client_register(argv[2], password);
		if (uid > 0) {
			fprintf(stderr, "注册成功,您的 uid 为: %d\n这是以后登陆时必要的信息,请牢记\n回车键以继续", uid);
			getchar();
		} else {
			fprintf(stderr, "注册失败\n");
			return 1;
		}
	} else {
		uid = atoi(argv[2]);
		if (uid <= 0) {
			fprintf(stderr, "错误的uid\n");
			return 1;
		}
	}

	if (!client_login(uid, password)) {
		wetalk_error("登陆失败\n");
	}

	client_main_run = true;
	int r;

	setlocale(LC_ALL, "");
	initscr();
	getmaxyx(stdscr, window_y, window_x);

	char input[BUFFER_SIZE] = {0};
	while(client_main_run) {
		draw_editarea();

		getnstr(input, BUFFER_SIZE - 1);
		r = strlen(input);
		input[r] = '\0';

		if (r > 0) {
			client_send(input);
		}
	}

	endwin();
	return 0;
}