Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mucurses_test.c 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "../include/curses.h"
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. void get_iscsi_chap_secret( char * );
  6. void mdelay( int msecs );
  7. int main ( void ) {
  8. char secret[16];
  9. initscr();
  10. echo();
  11. werase(stdscr);
  12. box( stdscr, '|', '-' );
  13. get_iscsi_chap_secret(secret);
  14. mvwprintw( stdscr, 3, 5, "password is \"%s\"", secret );
  15. mdelay(2500);
  16. stdscr->scr->exit(stdscr->scr);
  17. return 0;
  18. }
  19. void get_iscsi_chap_secret( char *sec ) {
  20. char *title = "Set new iSCSI CHAP secret",
  21. *msg = "Configure the iSCSI access secret",
  22. pw1[17], pw2[17];
  23. WINDOW *secret;
  24. secret = newwin( stdscr->height / 2,
  25. stdscr->width / 2,
  26. stdscr->height / 4,
  27. stdscr->width / 4 );
  28. wborder( secret, '|', '|', '-', '-', '+', '+', '+', '+' );
  29. mvwprintw( secret, 1, 2, "%s", title );
  30. mvwhline( secret, 2, 1, '-' | secret->attrs, secret->width - 2 );
  31. mvwprintw( secret, 4, 2, "%s", msg );
  32. mvwprintw( secret, 6, 3, "secret" );
  33. mvwprintw( secret, 8, 3, "confirm" );
  34. start:
  35. mvwhline( secret, 6, 12, '_' | secret->attrs, 16 );
  36. mvwhline( secret, 8, 12, '_' | secret->attrs, 16 );
  37. wmove( secret, 6, 12 );
  38. wgetnstr( secret, pw1, 16 );
  39. wmove( secret, 8, 12 );
  40. wgetnstr( secret, pw2, 16 );
  41. if ( strcmp( pw1, pw2 ) == 0 ) {
  42. strcpy( sec, pw1 );
  43. werase( secret );
  44. }
  45. else {
  46. mvwprintw( secret, 10, 3, "Passwords do not match" );
  47. goto start;
  48. }
  49. }
  50. void mdelay ( int msecs ) {
  51. usleep( msecs * 1000 );
  52. }