Exemple #1
0
void tx_stdwinset(WINDOW * win)
{
	meta(win, TRUE);
	keypad(win, TRUE);
	notimeout(win, 0);
	scrollok(win, 1);
}
static bool
test_opaque_notimeout(WINDOW *win, int mode)
{
    if (mode >= 0) {
	notimeout(win, mode);
    }
    return is_notimeout(win);
}
Exemple #3
0
Input::Input() {
   this->keybinding = Config::provider->GetConfig().GetKeybinding();

   this->InputTimeout = -1;
   notimeout(stdscr, TRUE);
#ifndef PDCURSES
   set_escdelay(0); // Needed so ESC key doesn't take a full second to do something.
#endif
}
/* Prints typical menus that you might see in games */
int
main (int argc, char *argv[])
{
    int menu_ret = 1, menu_ret2 = 1;
    char alts[][100] = {{"Start Game"},     /* Every menu needs an */
                         {"Load Game"},     /* array like these to */
                         {"Quit Game"},};   /* hold the entries.   */
    char alts2[][100] = {{"Slot 1"},
                         {"Slot 2"},
                         {"Slot 3"},
                         {"Return"},};

    setlocale (LC_CTYPE, "");

    initscr();                  /* Most of the below initialisers are */
    noecho();                   /* not necessary for this example.    */
    keypad (stdscr, TRUE);      /* It's just a template for a         */
    meta (stdscr, TRUE);        /* hypothetical program that might    */
    nodelay (stdscr, FALSE);    /* need them.                         */
    notimeout (stdscr, TRUE);
    raw();
    curs_set (0);

    do  /* This loop terminates when MAIN MENU returns 3, Quit Game.   */
    {   /* menu_ret is sent as the start value, to make the last entry */
        /* highlighted when you return to the main menu.               */
        menu_ret = print_menu (2, 5, 3, 15,
                               "MAIN MENU", alts, menu_ret);

        if (menu_ret == 1)  /* This is just an example program. */
        {                   /* You can't start an actual game.  */
            mvprintw (5, 23, "Lol jk! This is a demo program.");
            mvprintw (6, 26, "Press any key to return.");
            getch();
        }

        else if (menu_ret == 2) /* If you select load game, a new    */
        {                       /* menu will show up without erasing */
            do                  /* the main menu. */
            {
                menu_ret2 = print_menu (6, 22, 4, 15,
                                        "SELECT SLOT", alts2, 1);
            }
            while (menu_ret2 != 4);
        }

        erase();    /* When you return from the SELECT SLOT menu,      */
    }               /* everything will be erased and MAIN MENU will be */
    while (menu_ret != 3); /* reprinted.                               */

    endwin();
    return 0;
}
Exemple #5
0
int main(void)
{
	int ch = '\0';

	initscr();

	keypad(stdscr,TRUE);
	notimeout(stdscr,FALSE);
	addstr("Press the Esc key and note the delay:\n");
	refresh();
	while( ch != '\n')
		ch = getch();

	ch = '\0';
	notimeout(stdscr,TRUE);
	mvaddstr(3,0,"Now with notimeout TRUE, press Esc:\n");
	refresh();
	while( ch != '\n')
		ch = getch();

	endwin();
	return 0;
}
Exemple #6
0
Control Console::get_control()
{
	switch(getch()) {
		case 27: {
			log("Read 27");
			timeout(0);
			int code = getch();
			notimeout(stdscr, TRUE);
			log("Read {0}").arg(code);
			if(code == ERR || code == 27) {
				log("It was an ERR and I got an ESC.");
				return Control::CANCEL; // Escape;
			} else {
				// Have an ALT+code here.
			}
			break;
		}
        case 'h': return Control::LEFT;
        case 'j': return Control::DOWN;
        case 'k': return Control::UP;
        case 'l': return Control::RIGHT;
        case 'b': return Control::DOWN_LEFT;
        case 'n': return Control::DOWN_RIGHT;
        case 'y': return Control::UP_LEFT;
        case 'u': return Control::UP_RIGHT;

        case 'H': return Control(Control::LEFT, true);
        case 'J': return Control(Control::DOWN, true);
        case 'K': return Control(Control::UP, true);
        case 'L': return Control(Control::RIGHT, true);
        case 'B': return Control(Control::DOWN_LEFT, true);
        case 'N': return Control(Control::DOWN_RIGHT, true);
        case 'Y': return Control(Control::UP_LEFT, true);
        case 'U': return Control(Control::UP_RIGHT, true);

        case 'o': return Control::OPEN;
        case 'c': return Control::CLOSE;

        case 'x': return Control::EXAMINE;
        case '.': return Control::TARGET;
        case 'q': return Control::QUIT;
        case 'Q': return Control::SUICIDE;
        default: return Control::UNKNOWN;
    }
	return Control::UNKNOWN;
}
Exemple #7
0
void init_io(void)
{
#if defined(__TS_LINUX__)
  /* Basic setup. */
  if (initscr() == NULL)
    die("could not open the screen");

  notimeout(stdscr, 1);
  noecho();
  cbreak();
  keypad(stdscr, 1);
#elif defined(__TS_DOS__)
#elif defined(__WINDOWS__)
#else
# error Please define 'init_io' for your target system.
#endif
  
  initialize_colors();
}
Exemple #8
0
int
create_windows()
{
    int		menusize;
    int		infosize;

    initscr();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    signal(SIGWINCH, signal_handler);

    if(LINES < 7) {
	endwin();
	fprintf(stderr, "%s: window too small for curses interactive mode: LINES = %d\n",
		g_programName, LINES);
	exit(1);
    }

    mainmenu = newpad(100, COLS);
    keypad(mainmenu, TRUE);
    notimeout(mainmenu, TRUE);

    menusize = (LINES - 2) - INFO_SIZE;
    if(menusize <= 0)
	menusize = 1;

    prefresh(mainmenu,
	     0, 0,
	     1, 0,
	     menusize, COLS - 1);

    infosize = INFO_SIZE;
    if(infosize <= 0)
	infosize = 1;

    infowin = newwin(infosize, COLS, menusize + 1, 0);
    keypad(infowin, TRUE);
    wrefresh(infowin);

    return menusize;
}
Exemple #9
0
void initmenu(struct MENU *menu, int y1, int x1, int y2, int x2)
{
    menu->itemlist = NULL;
    menu->itemcount = 0;
    strcpy(menu->shortcuts, "");
    menu->x1 = x1;
    menu->y1 = y1;
    menu->x2 = x2;
    menu->y2 = y2;
    menu->menuwin = newwin(y1, x1, y2, x2);
    menu->menupanel = new_panel(menu->menuwin);
    menu->menu_maxx = x1 - 2;

    keypad(menu->menuwin, 1);
    meta(menu->menuwin, 1);
    noecho();
    wtimeout(menu->menuwin, -1);	/* block until input */
    notimeout(menu->menuwin, 0);	/* disable Esc timer */
    nonl();
    cbreak();
}
ModuleNcurses::ModuleNcurses(uint x, uint y)
{
  if (initscr() != stdscr || raw() == ERR || noecho() == ERR)
    throw Exception(strerror(errno));
  if ((this->win = newwin(x, y, 0, 0)) == NULL)
    throw Exception(strerror(errno));
  if (curs_set(0) == ERR ||
      start_color() == ERR)
    throw Exception(strerror(errno));
  if (init_pair(1, COLOR_BLUE, COLOR_CYAN) == ERR ||
      init_pair(2, COLOR_RED, COLOR_CYAN) == ERR ||
      init_pair(3, COLOR_BLUE, COLOR_CYAN) == ERR)
    throw Exception(strerror(errno));
  if (keypad(this->win, TRUE) == ERR)
    throw Exception(strerror(errno));
  intrflush(this->win, FALSE);
  if (werase(this->win) == ERR ||
      wrefresh(this->win) == ERR ||
      notimeout(this->win, TRUE) == ERR ||
      nodelay(this->win, TRUE) == ERR)
    throw Exception(strerror(errno));
}
Exemple #11
0
Screen::Screen() {
   initscr();
#ifdef WIN32
   PDC_set_title("Harvest Rogue");
   resize_term(40, 120);
#endif
   noecho();
   cbreak();
   keypad(stdscr, TRUE);
   nodelay(stdscr, FALSE);
   notimeout(stdscr, TRUE);
   raw();
   curs_set(0);
   start_color();
   clear();

   for (short i = 0; i < 16; i++) {
      init_pair(i + 1, i, CLR_BLACK);
   }
   for (short i = 16; i < 32; i++) {
      init_pair(i + 1, i - 15, CLR_WHITE);
   }

}
int
sc_enterStructuredMode ()
{
  if (initscr() == NULL)
    return FALSE;

  start_color();

  scrollok(stdscr, TRUE);
  immedok(stdscr, FALSE);
  leaveok(stdscr, FALSE);
  idlok(stdscr, TRUE);
  idcok(stdscr, TRUE);
  intrflush(stdscr, FALSE);
  keypad(stdscr, FALSE);

  notimeout(stdscr, FALSE);

  raw();
  noecho();
  nl();

  return TRUE;
}
Exemple #13
0
void
curses_loop()
{
	int key, w_height, w_width;

	notimeout(main_win, true);

	for (;;) {
		getmaxyx(status_win, w_height, w_width);
		mvwprintw(status_win, w_height - 2 , 1, "p - play, s - stop, q - quit");
		wrefresh(status_win);

		key = wgetch(main_win);
		switch (key) {
		case KEY_UP:
			break;
		case 10:	// 10 == ENTER
		case 'p':
			key_enter();
			break;
		case ' ':
			mvwprintw(status_win, 1, 5, "CMD: PAUSE");
			send_pause_command(sock_fd);
			break;
		case 'q':
			mvwprintw(status_win, 1, 5, "CMD: QUIT ");
			send_quit_command(sock_fd);
			wrefresh(status_win);
			return;
		case 's':
			mvwprintw(status_win, 1, 5, "CMD: STOP ");
			send_stop_command(sock_fd);
			break;
		case 68:
			mvwprintw(status_win, 1, 5, "CMD: REV  ");
			send_rev_command(sock_fd);
			break;
		case 67:
			mvwprintw(status_win, 1, 5, "CMD: FF   ");
			send_ff_command(sock_fd);
			break;
		case 66:
			// DOWN - scroll files
			key_down();
			break;
		case 65:
			// UP - scroll files
			key_up();
			break;
		//case 410:
		case KEY_RESIZE:
			resize_windows();
			break;
		default:
			mvwprintw(status_win, 10, 1, "pressed:");
			mvwprintw(status_win, 11, 1, "%3d as '%c'", key, key);
			break;
		}
		wrefresh(status_win);
	}
}
Exemple #14
0
shNCursesInterface::shNCursesInterface ()
{
    WINDOW *win = initscr ();

    if (!win) {
        fprintf (stderr, "Sorry, curses support is required.\n");
        exitPRIME (-1);
    }

    if (!has_colors ()) {
        endwin ();
        fprintf (stderr, "Sorry, color support is required.\n");
        exitPRIME (-1);
    }
    start_color ();

    for (int i = 1; i < COLOR_PAIRS; ++i) {
        init_pair (i, i %8, i/8);
    }


#ifdef _WIN32
    curs_set (1);
    ColorMap[kBlack] = COLOR_BLACK;
    ColorMap[kRed] = COLOR_PAIR (4);
    ColorMap[kGreen] = COLOR_PAIR (2);
    ColorMap[kBrown] = COLOR_PAIR (6);
    ColorMap[kBlue] = COLOR_PAIR (1);
    ColorMap[kMagenta] = COLOR_PAIR (5);
    ColorMap[kCyan] = COLOR_PAIR (3);
    ColorMap[kGray] = COLOR_PAIR (7);
    ColorMap[kOrange] = COLOR_PAIR (4) | A_BOLD;
    ColorMap[kLime] = COLOR_PAIR (2) | A_BOLD;
    ColorMap[kYellow] = COLOR_PAIR (6) | A_BOLD;
    ColorMap[kNavy] = COLOR_PAIR (1)| A_BOLD;
    ColorMap[kPink] = COLOR_PAIR (5) | A_BOLD;
    ColorMap[kAqua] = COLOR_PAIR (3) | A_BOLD;
    ColorMap[kWhite] = COLOR_PAIR (7) | A_BOLD;

#else
    ColorMap[kBlack] = COLOR_BLACK;
    ColorMap[kRed] = COLOR_PAIR (1);
    ColorMap[kGreen] = COLOR_PAIR (2);
    ColorMap[kBrown] = COLOR_PAIR (3);
    ColorMap[kBlue] = COLOR_PAIR (4);
    ColorMap[kMagenta] = COLOR_PAIR (5);
    ColorMap[kCyan] = COLOR_PAIR (6);
    ColorMap[kGray] = COLOR_PAIR (7);
    ColorMap[kOrange] = COLOR_PAIR (1) | A_BOLD;
    ColorMap[kLime] = COLOR_PAIR (2) | A_BOLD;
    ColorMap[kYellow] = COLOR_PAIR (3) | A_BOLD;
    ColorMap[kNavy] = COLOR_PAIR (4)| A_BOLD;
    ColorMap[kPink] = COLOR_PAIR (5) | A_BOLD;
    ColorMap[kAqua] = COLOR_PAIR (6) | A_BOLD;
    ColorMap[kWhite] = COLOR_PAIR (7) | A_BOLD;

#endif

    mColor = kGray;

//    cbreak ();
    raw ();
    noecho ();
#ifdef DJGPP
    nl ();
#else
    nonl ();
#endif

    mXMax = 64;
    mYMax = 20;

    mWin[kMain] = newwin (20, mXMax, 0, 0);
    if (!mWin[kMain]) goto toosmall;
    mPan[kMain] = new_panel (mWin[kMain]);
    notimeout (mWin[kMain], TRUE);
    mWin[kSide] = newwin (20, 80 - mXMax, 0, mXMax);
    if (!mWin[kSide]) goto toosmall;
    mPan[kSide] = new_panel (mWin[kSide]);
    mWin[kLog] = newwin (5, 80, 20, 0);
    if (!mWin[kLog]) goto toosmall;
    mPan[kLog] = new_panel (mWin[kLog]);
    mWin[kDiag] = NULL;
    if (BOFH and LINES >= 30) {
        mWin[kDiag] = newwin (0, 80, 25, 0);
        scrollok (mWin[kDiag], TRUE);
    }
    mWin[kTemp] = newwin (0, 0, 0, 0);
    notimeout (mWin[kLog], TRUE);
    mLogSize = 5;
    mLogRow = 0;
    mHistoryIdx = 0;
    mHistoryWrapped = 0;
    mNoNewline = 0;
    mLogSCount = 0;
    mPause = 0;

    mX0 = 0;
    mY0 = 0;

    intrflush (mWin[kMain], FALSE);
    keypad (mWin[kMain], TRUE);
    intrflush (mWin[kLog], FALSE);
    scrollok (mWin[kLog], TRUE);
#ifndef WIN32
    set_escdelay (50);
#endif

    debug.log ("COLORS: %d", COLORS);
    debug.log ("COLOR_PAIRS: %d", COLOR_PAIRS);
    debug.log ("can change: %d", can_change_color());

    return;

toosmall:
    endwin ();
    fprintf (stderr, "Sorry, but a terminal with dimensions of at least 80x25"
             " is required.\n");
    exitPRIME (-1);
}
EIF_INTEGER c_ecurses_notimeout (EIF_POINTER w, EIF_BOOLEAN b)
{
    return notimeout( ((WINDOW *) w), (bool)b) ;
};
Exemple #16
0
int chkr_notimeout(WINDOW *win,bool arg)
{
   return(notimeout(win,arg));
}
Exemple #17
0
Fichier : lex.c Projet : recalcc/sc
void
resetkbd()
{
    keypad(stdscr, FALSE);
    notimeout(stdscr, FALSE);
}
Exemple #18
0
Fichier : lex.c Projet : recalcc/sc
void
kbd_again()
{
    keypad(stdscr, TRUE);
    notimeout(stdscr,TRUE);
}
Exemple #19
0
Fichier : lex.c Projet : recalcc/sc
void
initkbd()
{
    keypad(stdscr, TRUE);
    notimeout(stdscr,TRUE);
}
Exemple #20
0
/* Runs the host editor.  Another big use for this is to open sites
 * that are in your host list.
 */
int HostWindow(void)
{
	int c;
	char cmd[256];
	volatile BookmarkPtr toOpen;
	vsigproc_t si;
	int maxy, maxx;
	int lmaxy;

	si = (sigproc_t) (-1);
	if (gWinInit) {
		gHostListWin = NULL;
		gHostWin = NULL;

		gHostWin = newwin(LINES, COLS, 0, 0);
		if (gHostWin == NULL)
			return (-1);

		curs_set(0);
		cbreak();
		
		/* Set the clear flag for the first update. */
		wclear(gHostWin);
		keypad(gHostWin, TRUE);		/* For arrow keys. */
#ifdef HAVE_NOTIMEOUT
		notimeout(gHostWin, TRUE);
#endif

#ifdef HAVE_SIGSETJMP
		if (sigsetjmp(gHostWinJmp, 1) == 0) {
#else	/* HAVE_SIGSETJMP */
		if (setjmp(gHostWinJmp) == 0) {
#endif	/* HAVE_SIGSETJMP */
			/* Gracefully cleanup the screen if the user ^C's. */
			si = NcSignal(SIGINT, SigIntHostWin);
			
			/* Initialize the page start and select a host to be
			 * the current one.
			 */
			gHostListWinStart = 0;
			gHilitedHost = 0;
			if (gNumBookmarks == 0)
				gCurHostListItem = NULL;
			else
				gCurHostListItem = &gBookmarkTable[gHilitedHost];
			
			/* Initially, we don't want to connect to any site in
			 * the host list.
			 */
			toOpen = NULL;
	
			getmaxyx(gHostWin, maxy, maxx);
			WAttr(gHostWin, kBold, 1);
			WAddCenteredStr(gHostWin, 0, "NcFTP Bookmark Editor");
			WAttr(gHostWin, kBold, 0);
			
			DrawStrAt(gHostWin, 3, 2, "Open selected site:       <enter>");
			DrawStrAt(gHostWin, 4, 2, "Edit selected site:       /ed");
			DrawStrAt(gHostWin, 5, 2, "Delete selected site:     /del");
			DrawStrAt(gHostWin, 6, 2, "Duplicate selected site:  /dup");
			DrawStrAt(gHostWin, 7, 2, "Add a new site:           /new");
			DrawStrAt(gHostWin, 9, 2, "Up one:                   <u>");
			DrawStrAt(gHostWin, 10, 2, "Down one:                 <d>");
			DrawStrAt(gHostWin, 11, 2, "Previous page:            <p>");
			DrawStrAt(gHostWin, 12, 2, "Next page:                <n>");
			DrawStrAt(gHostWin, 14, 2, "Capital letters selects first");
			DrawStrAt(gHostWin, 15, 2, "  site starting with the letter.");
			DrawStrAt(gHostWin, 17, 2, "Exit the bookmark editor: <x>");
		
			/* Initialize the scrolling host list window. */
			if (maxx < 110) {
				gHostListWinWide = 0;
				gHostListWin = subwin(
					gHostWin,
					LINES - 7,
					40,
					3,
					COLS - 40 - 2
				);
			} else {
				gHostListWinWide = COLS - 42;
				gHostListWin = subwin(
					gHostWin,
					LINES - 7,
					gHostListWinWide,
					3,
					38	
				);
			}

			if (gHostListWin == NULL)
				return (-1);
			lmaxy = getmaxy(gHostListWin);
			gHostListPageSize = lmaxy;
			DrawHostList();
			wmove(gHostWin, maxy - 1, 0);
			UpdateHostWindows(1);

			for (;;) {
				c = HostWinGetKey();
				if (gNeedToClearMsg) {
					wmove(gHostWin, maxy - 2, 0);
					wclrtoeol(gHostWin);
					wrefresh(gHostWin);
				}
				if ((c >= 'A') && (c <= 'Z')) {
					/* isupper can coredump if wgetch returns a meta key. */
					HostWinZoomTo(c);
				} else if (c == '/') {
					/* Get an "extended" command.  Sort of like vi's
					 * :colon commands.
					 */
					HostWinGetStr(cmd, sizeof(cmd));
	
					if (ISTREQ(cmd, "ed"))
						HostWinEdit();
					else if (ISTREQ(cmd, "dup"))
						HostWinDup();
					else if (ISTREQ(cmd, "del"))
						HostWinDelete();
					else if (ISTREQ(cmd, "new"))
						HostWinNew();
					else
						HostWinMsg("Invalid bookmark editor command.");
				} else switch(c) {
					case 10:	/* ^J == newline */
						goto enter;
					case 13:	/* ^M == carriage return */
						goto enter;
#ifdef KEY_ENTER
					case KEY_ENTER:
						Trace(1, "  [0x%04X, %s]\n", c, "ENTER");
#endif
enter:
						if (gCurHostListItem == NULL)
							HostWinMsg("Nothing to open.  Try 'open sitename' from the main screen.");
						else {
							toOpen = (BookmarkPtr) gCurHostListItem;
							goto done;
						}
						break;
	
					case kControl_L:
						UpdateHostWindows(1);
						break;
	
					case 'u':
					case 'k':	/* vi up key */
					case 'h':	/* vi left key */
						HostListLineUp();
						break;
#ifdef KEY_UP
					case KEY_UP:
						Trace(1, "  [0x%04X, %s]\n", c, "UP");
						HostListLineUp();
						break;
#endif

#ifdef KEY_LEFT
					case KEY_LEFT:
						Trace(1, "  [0x%04X, %s]\n", c, "LEFT");
						HostListLineUp();
						break;
#endif
					
					case 'd':
					case 'j':	/* vi down key */
					case 'l':	/* vi right key */
						HostListLineDown();
						break;

#ifdef KEY_DOWN
					case KEY_DOWN:
						Trace(1, "  [0x%04X, %s]\n", c, "DOWN");
						HostListLineDown();
						break;
#endif

#ifdef KEY_RIGHT
					case KEY_RIGHT:
						Trace(1, "  [0x%04X, %s]\n", c, "RIGHT");
						HostListLineDown();
						break;
#endif
						
					case 'p':
						HostListPageUp();
						break;

#ifdef KEY_PPAGE
					case KEY_PPAGE:
						Trace(1, "  [0x%04X, %s]\n", c, "PPAGE");
						HostListPageUp();
						break;
#endif

					case 'n':
						HostListPageDown();
						break;

#ifdef KEY_NPAGE
					case KEY_NPAGE:
						Trace(1, "  [0x%04X, %s]\n", c, "NPAGE");
						HostListPageDown();
						break;
#endif

					case 'x':
					case 'q':
						goto done;
	
					default:
						HostWinMsg("Invalid key.");
						Trace(1, "  [0x%04X, %s]\n", c, "<invalid>");
						break;
				}
			}
		}
		NcSignal(SIGINT, (FTPSigProc) SIG_IGN);
done:
		if (gHostListWin != NULL)
			delwin(gHostListWin);
		if (gHostWin != NULL)
			delwin(gHostWin);
		gHostListWin = gHostWin = NULL;
		if (si != (sigproc_t) (-1))
			NcSignal(SIGINT, si);
		if (toOpen != (BookmarkPtr) 0) {
			/* If the user selected a site to open, connect to it now. */
			if (gStandAlone != 0) {
				LaunchNcFTP(toOpen->bookmarkName);
				/*NOTREACHED*/
				Exit(0);
			} else if (gBookmarkSelectionFile != NULL) {
				WriteSelectedBMToFile(toOpen->bookmarkName);
			}
			return (kNoErr);
		}
	}
	return (kNoErr);
}	/* HostWindow */




main_void_return_t
main(int argc, const char **argv)
{
	int result;
	int argi;

	gStandAlone = 1;
	gBookmarkSelectionFile = NULL;

	InitUserInfo();
	if (LoadBookmarkTable() < 0) {
		exit(7);
	}
	if (argc > 1) {
		/* The following hack is used by NcFTP
		 * to get the number of columns without
		 * having to link with curses/termcap.
		 * This simplifies things since the
		 * system may or may not have a good
		 * curses implementation, and we don't
		 * want to complicate NcFTP itself with
		 * that.
		 */
		argi = 1;
		if (strcmp(argv[1], "--dimensions") == 0) {
			result = PrintDimensions(0);
			exit((result == 0) ? 0 : 1);
		} else if (strcmp(argv[1], "--dimensions-terse") == 0) {
			result = PrintDimensions(1);
			exit((result == 0) ? 0 : 1);
		} else if (strcmp(argv[1], "--debug") == 0) {
			SetDebug(1);
			argi++;
		}
		/* Requested that we were run from ncftp. */
		gStandAlone = 0;
		if ((argc > argi) && (argv[argi][0] == '/'))
			gBookmarkSelectionFile = (const char *) argv[argi];
		if (gNumBookmarks < 1)
			exit(7);
	}

	result = FTPInitLibrary(&gLib);
	if (result < 0) {
		(void) fprintf(stderr, "ncftp: init library error %d (%s).\n", result, FTPStrError(result));
		exit(1);
	}

	result = FTPInitConnectionInfo(&gLib, &gConn, kDefaultFTPBufSize);
	if (result < 0) {
		(void) fprintf(stderr, "ncftp: init connection info error %d (%s).\n", result, FTPStrError(result));
		exit(1);
	}

	if (gDebug > 0)
		OpenTrace();
	InitPrefs();
	LoadFirewallPrefs(0);
	LoadPrefs();

	InitWindows();
	Trace(1, "Terminal size is %d columns by %d rows.\n", gScreenWidth, gScreenHeight);
	HostWindow();
	if (gDebug > 0)
		CloseTrace();
	EndWin();
	exit(0);
}	/* main */
Exemple #21
0
// Codigo principal del cliente
void main(int argc, char * argv[]){
	
	// Declaraciones
	int max_desc;
	char message[MAX_MESSAGE_LEN], command[MAX_FULLM_LEN], 
		pipe[MAX_PIPE_LEN], cmd[MAX_MESSAGE_LEN];
	char buffer[MAX_MESSAGE_LEN] = "", c[2] = {0,'\0'};
	fd_set lectura;
	fd_set c_lectura;
	struct timeval tv;
	int status,i,alto,x,y,salir = 0;
	
	// Inicializar senales.
	if (signal(SIGINT, term_handler) == SIG_ERR) {
        	printf("Ocurrio un error al colocar la signal.\n");
		exit(1);
    	}
		
	// Interfaz.
	initscr();
	alto = LINES - ALTO;
	ventanaOutput = newwin(alto, 0, 0, 0);
	ventanaInput = newwin(ALTO, 0, alto, 0);
	nonl();
	cbreak();
	noecho();
	notimeout(ventanaInput, TRUE);
	nodelay(ventanaInput, TRUE);
	scrollok(ventanaOutput, TRUE);
	scrollok(ventanaInput, TRUE);
	limpiarVentanaInput();
	// Fin Interfaz

	// Verificar tamanio del terminal
  	if (LINES < LINES_MIN || COLS < COLS_MIN) {
        	endwin(); // Restaurar la operación del terminal a modo normal
        	printf("El terminal es muy pequeño para correr este programa.\n");
        	exit(1);
    	}

	// Obtener nombre para el cliente.
	strcpy(name,getlogin());
	if ( strcmp(name, "" ) == 0 ) { perror("Error getting name"); }	

	// Obtener pipe a utilizar.
	strcpy(pipe, DEFAULT_PIPE);
	if (argc > 1) {
		for (i = 1; i < argc; i ++){
			if ( strcmp(argv[i], "-p") == 0) {
				if ( strlen(argv[i]) <= MAX_PIPE_LEN - 1 ) {
					strcpy(pipe, argv[i+1]);
					i++;
				} else { 
					endwin();
					printf("El path del pipe escogido es muy largo,\
						debe ser menor a %d caracteres.", MAX_PIPE_LEN - 1);
					exit(1);
				}
			} else {
				if ( strlen(argv[i]) <= MAX_NAME_LEN - 1 ) {
					strcpy(name,argv[i]);
				} else {
					endwin();
					printf("El nombre escogido es muy largo,\
						debe ser menor a %d caracteres.", MAX_NAME_LEN - 1);
					exit(1);
				}
			}
		}
	}