int main()
{
   initscr();
   keypad(stdscr, TRUE);
   noecho();
   start_color();
   init_pair(1, COLOR_GREEN,   COLOR_BLACK);
   init_pair(2, COLOR_MAGENTA, COLOR_BLACK);
   finit(9,9,0,2);
   clear();
   printw(
   "      Etherial Void   \n\n"
   "Is it that all exists only in the\n"
   "etherial landscape of the mind?\n\n"
   "The past is uncertian,\n\n"
   "The present is now the past,\n\n"
   "The future might only be thought of.\n\n"
   "Is then not our mind's eye\n"
   "the root of reality?\n\n"
   "But should that eye be blind,\n"
   "where then would rest the soul?"
   "\n\n"
   "(press any key to continue)\n");
   getch();
   clear();
   printw(
   "   I look,\n"
   "but I see nothing.");
   getch();
   clear();
   getch();
   printw(
   "   Perhaps,\n"
   "there is nothing to see.");
   getch();
   helpmsg="Use the arrow keys or WASD to move the charecter.";
   clear();
   while(loop)
   {  
      switch(z)
      {  
         case 0:
            nroom=1;
            eroom=2;
            sroom=3;
            wroom=4;
            uroom=5;
            light=2;
            wall=
            "Some sort of wall mesage should be displayed here,\n"
            "It should inform the player of the solidity of this wall,\n"
            "and it should warn that attempts to surpass this fact are admonishable.";
            
            msg(9,6,
            "   I <do> see something:\n"
            "There seem to be dimly glowing etchings on the ground which signify,\n"
            "'There is naught to the north.'");

            msg(12,9,
            "   There is <something> here:\n"
            "In the ground there are shallow grooves filled with a\n"
            "faintly luminescent material. I cannot comprehend them.");
            if(sw[0]&&sw[1]&&sw[2]&&sw[3])
            {
               map[0][9][9]='^';
               smsg(9,9,
               "This is a new stairwell.");
            }
            break;
         case 1:
            sroom=0;
            lvr(9,9,0);
            break;
         case 2:
            wroom=0;
            wall=
            "There are some large deep grooves on the wall";
            lvr(9,9,1);
            break;
         case 3:
            nroom=0;
            lvr(9,9,2);
            break;
         case 4:
            eroom=0;
            lvr(9,9,3);
            break;
         case 5:
            eroom=6;
            droom=1;
            break;
         case 6:
            wroom=5;
            break;
         default:
            endwin();
            printf("Error: 42\n");
            loop=0;
            exit(42);
      }
      unmove();
      uncover(0);
      showmap();
      input();
   }
   endwin();
   return 0;
}
static void
test_add_wchstr(int level)
{
    static bool first = TRUE;

    int ch;
    int limit;
    int row = 1;
    int col;
    int row2, col2;
    int length;
    wchar_t buffer[BUFSIZ];
    WINDOW *look = 0;
    WINDOW *work = 0;
    WINDOW *show = 0;
    int margin = (2 * MY_TABSIZE) - 1;
    Options option = ((m_opt ? oMove : oDefault)
		      | ((w_opt || (level > 0)) ? oWindow : oDefault));

    if (first) {
	static char cmd[80];
	setlocale(LC_ALL, "");

	putenv(strcpy(cmd, "TABSIZE=8"));

	initscr();
	(void) cbreak();	/* take input chars one at a time, no wait for \n */
	(void) noecho();	/* don't echo input */
	keypad(stdscr, TRUE);
    }

    limit = LINES - 5;
    if (level > 0) {
	look = newwin(limit, COLS - (2 * (level - 1)), 0, level - 1);
	work = newwin(limit - 2, COLS - (2 * level), 1, level);
	show = newwin(4, COLS, limit + 1, 0);
	box(look, 0, 0);
	wnoutrefresh(look);
	limit -= 2;
    } else {
	work = stdscr;
	show = derwin(stdscr, 4, COLS, limit + 1, 0);
    }
    keypad(work, TRUE);

    for (col = margin + 1; col < COLS; col += MY_TABSIZE)
	MvWVLine(work, row, col, '.', limit - 2);

    MvWVLine(work, row, margin, ACS_VLINE, limit - 2);
    MvWVLine(work, row, margin + 1, ACS_VLINE, limit - 2);
    limit /= 2;

    (void) mvwadd_wchstr(work, 1, 2, ChStr("String"));
    (void) mvwadd_wchstr(work, limit + 1, 2, ChStr("Chars"));
    wnoutrefresh(work);

    buffer[length = 0] = '\0';
    legend(show, level, option, buffer, length);
    wnoutrefresh(show);

    doupdate();

    /*
     * Show the characters added in color, to distinguish from those that
     * are shifted.
     */
    if (has_colors()) {
	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLUE);
	wbkgdset(work, COLOR_PAIR(1) | ' ');
    }

    while ((ch = read_linedata(work)) != ERR && !isQUIT(ch)) {
	wmove(work, row, margin + 1);
	switch (ch) {
	case key_RECUR:
	    test_add_wchstr(level + 1);

	    touchwin(look);
	    touchwin(work);
	    touchwin(show);

	    wnoutrefresh(look);
	    wnoutrefresh(work);
	    wnoutrefresh(show);

	    doupdate();
	    break;
	case key_NEWLINE:
	    if (row < limit) {
		++row;
		/* put the whole string in, all at once */
		col2 = margin + 1;
		switch (option) {
		case oDefault:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    if (move(row, col2) != ERR) {
				AddNStr(ChWStr(buffer + col), LEN(col));
			    }
			}
		    } else {
			if (move(row, col2) != ERR) {
			    AddStr(ChWStr(buffer));
			}
		    }
		    break;
		case oMove:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    MvAddNStr(row, col2, ChWStr(buffer + col), LEN(col));
			}
		    } else {
			MvAddStr(row, col2, ChWStr(buffer));
		    }
		    break;
		case oWindow:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    if (wmove(work, row, col2) != ERR) {
				WAddNStr(work, ChWStr(buffer + col), LEN(col));
			    }
			}
		    } else {
			if (wmove(work, row, col2) != ERR) {
			    WAddStr(work, ChWStr(buffer));
			}
		    }
		    break;
		case oMoveWindow:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    MvWAddNStr(work, row, col2, ChWStr(buffer +
							       col), LEN(col));
			}
		    } else {
			MvWAddStr(work, row, col2, ChWStr(buffer));
		    }
		    break;
		}

		/* do the corresponding single-character add */
		row2 = limit + row;
		for (col = 0; col < length; ++col) {
		    col2 = ColOf(buffer, col, margin);
		    switch (option) {
		    case oDefault:
			if (move(row2, col2) != ERR) {
			    AddCh((chtype) buffer[col]);
			}
			break;
		    case oMove:
			MvAddCh(row2, col2, (chtype) buffer[col]);
			break;
		    case oWindow:
			if (wmove(work, row2, col2) != ERR) {
			    WAddCh(work, (chtype) buffer[col]);
			}
			break;
		    case oMoveWindow:
			MvWAddCh(work, row2, col2, (chtype) buffer[col]);
			break;
		    }
		}
	    } else {
		beep();
	    }
	    break;
	default:
	    buffer[length++] = ch;
	    buffer[length] = '\0';

	    /* put the string in, one character at a time */
	    col = ColOf(buffer, length - 1, margin);
	    switch (option) {
	    case oDefault:
		if (move(row, col) != ERR) {
		    AddStr(ChWStr(buffer + length - 1));
		}
		break;
	    case oMove:
		MvAddStr(row, col, ChWStr(buffer + length - 1));
		break;
	    case oWindow:
		if (wmove(work, row, col) != ERR) {
		    WAddStr(work, ChWStr(buffer + length - 1));
		}
		break;
	    case oMoveWindow:
		MvWAddStr(work, row, col, ChWStr(buffer + length - 1));
		break;
	    }

	    /* do the corresponding single-character add */
	    switch (option) {
	    case oDefault:
		if (move(limit + row, col) != ERR) {
		    AddCh(ch);
		}
		break;
	    case oMove:
		MvAddCh(limit + row, col, ch);
		break;
	    case oWindow:
		if (wmove(work, limit + row, col) != ERR) {
		    WAddCh(work, ch);
		}
		break;
	    case oMoveWindow:
		MvWAddCh(work, limit + row, col, ch);
		break;
	    }

	    wnoutrefresh(work);

	    legend(show, level, option, buffer, length);
	    wnoutrefresh(show);

	    doupdate();
	    break;
	}
    }
    if (level > 0) {
	delwin(show);
	delwin(work);
	delwin(look);
    }
}
Exemple #3
0
int main(int argc, char *argv[]) {
int right[4], guess[4], backup[4];
int halfrights,rights;
int tmp,i;
int tries = 3;
int maxtries;
int place,color;
int x,y;
char charbuffer[10];
char question[2];
int pplace[4];
pplace[0] = 13;
pplace[1] = 15;
pplace[2] = 17;
pplace[3] = 19;

halfrights=rights=0;

srand(time(0));

printf("Can two places be the same color? (y/n) ");
scanf("%s",charbuffer);
strcpy(question,"n");
if (strcmp(charbuffer,question) == 0) {
	for (i=0;i<4;i++) {
		BACK:
		right[i] = (8.0*rand()/RAND_MAX+1.0);
		for (tmp=0;tmp<4;tmp++) {
			if (right[i] == right[tmp] && i != tmp) {
				goto BACK;
			}
		}
		guess[i] = 0;
	}
} else {
	for (i=0;i<4;i++) {
		right[i] = (8.0*rand()/RAND_MAX+1.0);
		guess[i] = 0;
	}
}


for (i=0;i<4;i++) {
	backup[i] = right[i];
}

printf("How many tries would you like? ");
scanf("%i",&maxtries);
printf("\n");
if (maxtries <= 0) {
printf("Ok, fine.\n");
return 1;
}

printf("\nI have come up with a color combination. Press enter to start the game.\n");

getchar();
getchar();

initscr();
start_color();

getmaxyx(stdscr,y,x);

if (y < 22) {
	endwin();
	printf("Terminal too small\n");
	return 1;
}

if (maxtries > (x/3-3)) {
endwin();
printf("You have too many tries to be on the screen.\n");
return 1;
}

/* Color definations: */
init_pair(1, COLOR_WHITE, COLOR_RED);
init_pair(2, COLOR_WHITE, COLOR_GREEN);
init_pair(3, COLOR_WHITE, COLOR_BLUE);
init_pair(4, COLOR_WHITE, COLOR_BLACK);
init_pair(5, COLOR_WHITE, COLOR_MAGENTA);
init_pair(6, COLOR_BLACK, COLOR_WHITE);
init_pair(7, COLOR_WHITE, COLOR_CYAN);
init_pair(8, COLOR_WHITE, COLOR_YELLOW);


mvprintw(5,0,"Colors: 1: Red, 2: Green, 3: Blue, 4: Black");
mvprintw(6,0,"Colors: 5: Magenta, 6: White, 7: Cyan, 8: Yellow");

mvprintw(8,0,"Right colors on right places:");
mvprintw(10,0,"Right colors on wrong places:");

mvprintw(pplace[0],0,"1:");
mvprintw(pplace[1],0,"2:");
mvprintw(pplace[2],0,"3:");
mvprintw(pplace[3],0,"4:");

mvprintw(0,x/2-10,"Tries left: %i ",maxtries);

GETPLACE:
mvprintw(0,0,"Place:");
mvprintw(1,2," ");
mvprintw(1,0,"? ");
scanw("%i",&place);
if (place < 1 || place > 4) { /* if the user types too many */
	for (i=2;i<=x;i++) {  /* cifers, we want to clean it up */
	mvprintw(1,i," ");
	}
goto GETPLACE;
}
GETCOLOR:
mvprintw(0,0,"Color:");
mvprintw(1,2," ");
move(1,2);
scanw("%i",&color);
if (color < 1 || color > 8) { /* same here */
	for (i=2;i<=x;i++) {
	mvprintw(1,i," ");
	}
goto GETCOLOR;
}

attrset(COLOR_PAIR(color));

mvprintw(pplace[place-1],tries,"%i",color);

attrset(A_NORMAL);

guess[place-1] = color;

tmp = 1;
for (i=0;i<4;i++) {
	if (guess[i] == 0) {
	tmp = 0;	
	}
}

if (tmp) { /* All fields are filled */
	mvprintw(pplace[3]+2,4,"Is that a guess? (y/n) ");
	refresh();
	scanw("%s",charbuffer);
	strcpy(question,"y");
	for (i=4;i<=x;i++) {
		mvprintw(pplace[3]+2,i," ");
	}

	if (strcmp(charbuffer,question) == 0) {
		for (i=0;i<4;i++) {
			if (right[i] == guess[i]) {  /* Finds out how many right colors on right places */
				rights++;	     /* the user has placed. */
				right[i] = guess[i] = 0; /* This line makes sure this guess is not counted again */
			}
		}
		for (i=0;i<4;i++) {
			for (tmp=0;tmp<4;tmp++) {

				if (guess[tmp] == right[i] && right[i] != 0) {
					halfrights++;
					guess[tmp] = right[i] = 0; /* This line makes sure this guess is not counted again */
				}

			}
		}

		if (rights == 4) {
			endwin();
			printf("CONGRATULATIONS!\n");
			printf("You guessed the right combination!\n");
			printf("You used %i tries\n", tries/3);

			return 0;
		}
	
		for (i=0;i<4;i++) {
			right[i] = backup[i];  /* We deleted the right[] array, we have to get it back for next check */
		}


		mvprintw(9,tries,"%i",rights);
		mvprintw(11,tries,"%i",halfrights);
		

		halfrights=rights=0;
		for (i=0;i<4;i++) {
			guess[i] = 0;
		}
		tries = tries+3;
		maxtries--;
		mvprintw(0,x/2-10,"Tries left: %i ",maxtries);
		if (maxtries == 0) {
			for (i=0;i<4;i++) {
				attrset(COLOR_PAIR(right[i]));

				mvprintw(pplace[i],0,"%i",right[i]);

				attrset(A_NORMAL);

			}
			mvprintw(y-2,0,"Wrong, and you are out of tries..\n");
			printw("Press enter to end program");
			refresh();
			getchar();
			endwin();
			return 1;
		}
	}
}


goto GETPLACE;

endwin();
return 0;
}
Exemple #4
0
int main(int argc, char **argv) {
	int y, x;
	int oldy, oldx;
	int graphy;
	int xhalf, graphyx2;
	int key;
	bool redraw = true;
	bool erase = true;
	bool changedelay = false;
	long timer = 0;
	struct timeval tv;
	struct iface ifa;
	WINDOW *rxgraph, *txgraph, *rxstats, *txstats;

	memset(&ifa, 0, sizeof(ifa));

	ARGBEGIN {
	case 'v':
		eprintf("nbwmon-%s\n", VERSION);
	case 'C':
		colors = false;
		break;
	case 's':
		siunits = true;
		break;
	case 'm':
		minimum = true;
		break;
	case 'g':
		globalmax = true;
		break;
	case 'd':
		delay = estrtod(EARGF(usage()));
		break;
	case 'i':
		strlcpy(ifa.ifname, EARGF(usage()), IFNAMSIZ);
		break;
	default:
		usage();
	} ARGEND;

	if (!detectiface(ifa.ifname))
		eprintf("Can't find network interface\n");
	if (!getcounters(ifa.ifname, &ifa.rx, &ifa.tx))
		eprintf("Can't read rx and tx bytes for %s\n", ifa.ifname);

	initscr();
	curs_set(FALSE);
	noecho();
	timeout(10);
	if (colors && has_colors()) {
		start_color();
		use_default_colors();
		init_pair(1, COLOR_GREEN, -1);
		init_pair(2, COLOR_RED, -1);
	}
	getmaxyx(stdscr, y, x);
	getmaxyx(stdscr, oldy, oldx);

	ifa.rxs = ecalloc(x - 3, sizeof(*ifa.rxs));
	ifa.txs = ecalloc(x - 3, sizeof(*ifa.txs));

	graphy = (y - 7) / 2;
	rxgraph = newwin(graphy, x, 0, 0);
	txgraph = newwin(graphy, x, graphy, 0);
	rxstats = newwin(y - graphy * 2, x / 2, graphy * 2, 0);
	txstats = newwin(y - graphy * 2, x - x / 2, graphy * 2, x / 2);

	for (key = ERR; key != 'q'; key = getch()) {
		if (key != ERR)
			redraw = true;
		switch (key) {
		case 's':
			siunits = !siunits;
			break;
		case 'm':
			minimum = !minimum;
			break;
		case 'g':
			globalmax = !globalmax;
			break;
		case '+':
			if (delay < 8) {
				delay *= 2;
				changedelay = true;
			}
			break;
		case '-':
			if (delay > 0.25) {
				delay /= 2;
				changedelay = true;
			}
			break;
		}

		if (y < 11 || x < 44) {
			werase(stdscr);
			addstr("terminal too small");
			wrefresh(stdscr);
			if (key == KEY_RESIZE)
				getmaxyx(stdscr, y, x);
			erase = true;
			continue;
		}
		if (erase) {
			werase(stdscr);
			wnoutrefresh(stdscr);
			erase = false;
		}

		if (oldy != y || oldx != x) {
			graphy = (y - 7) / 2;
			graphyx2 = graphy * 2;
			xhalf = x / 2;
			wresize(rxgraph, graphy, x);
			wresize(txgraph, graphy, x);
			wresize(rxstats, y - graphyx2, xhalf);
			wresize(txstats, y - graphyx2, x - xhalf);
			mvwin(rxgraph, 0, 0);
			mvwin(txgraph, graphy, 0);
			mvwin(rxstats, graphyx2, 0);
			mvwin(txstats, graphyx2, xhalf);
			if (oldx != x) {
				arrayresize(&ifa.rxs, x - 3, oldx - 3);
				arrayresize(&ifa.txs, x - 3, oldx - 3);
			}
			redraw = true;
		}

		gettimeofday(&tv, NULL);
		tv.tv_usec = (tv.tv_sec * 1000 + tv.tv_usec / 1000) / (delay * 1000.0);
		if (changedelay) {
			timer = tv.tv_usec;
			changedelay = false;
		}
		if (timer != tv.tv_usec) {
			timer = tv.tv_usec;
			if (!getdata(&ifa, x - 3))
				eprintf("Can't read rx and tx bytes for %s\n", ifa.ifname);
			redraw = true;
		}

		if (redraw) {
			printgraphw(rxgraph, "Received", ifa.ifname, COLOR_PAIR(1),
					ifa.rxs, ifa.rxmin, ifa.rxmax);
			printgraphw(txgraph, "Transmitted", NULL, COLOR_PAIR(2),
					ifa.txs, ifa.txmin, ifa.txmax);
			printstatsw(rxstats, "Received",
					ifa.rxs[x - 4], ifa.rxmin, ifa.rxavg, ifa.rxmax, ifa.rx);
			printstatsw(txstats, "Transmitted",
					ifa.txs[x - 4], ifa.txmin, ifa.txavg, ifa.txmax, ifa.tx);
			doupdate();
			redraw = false;
		}

		oldy = y;
		oldx = x;
		if (key == KEY_RESIZE)
			getmaxyx(stdscr, y, x);
	}

	delwin(rxgraph);
	delwin(txgraph);
	delwin(rxstats);
	delwin(txstats);
	endwin();
	free(ifa.rxs);
	free(ifa.txs);

	return EXIT_SUCCESS;
}
Exemple #5
0
/**
 * Set up a highlighting group to be displayed as the user wishes.
 *
 * \param group
 * The highlighting group
 *
 * \param mono_attrs
 * Attributes avialable in mono mode
 *
 * \param color_attrs
 * Attributes available during color mode
 *
 * \param fore_color
 * The foreground color
 *
 * \param back_color
 * The backgroud color
 *
 * \return
 * 0 on success, -1 on error.
 */
static int
setup_group(hl_groups_ptr hl_groups, enum hl_group_kind group,
        int mono_attrs, int color_attrs, int fore_color, int back_color)
{
  /** Starts creating new colors at 1, and then is incremented each time. */
    static int next_color_pair = 1;
    struct hl_group_info *info;

    if (!hl_groups)
        return -1;

    info = lookup_group_info_by_key(hl_groups, group);

    if (!info)
        return -1;

    if (mono_attrs != UNSPECIFIED_COLOR)
        info->mono_attrs = mono_attrs;
    if (color_attrs != UNSPECIFIED_COLOR)
        info->color_attrs = color_attrs;

    /* The rest of this function sets up the colors, so we can stop here
     * if color isn't used. */
    if (!hl_groups->in_color)
        return 0;

    /* If no colors are specified, we're done. */
    if (fore_color == UNSPECIFIED_COLOR && back_color == UNSPECIFIED_COLOR)
        return 0;

    /* Don't allow -1 to be used in curses mode */
#ifndef NCURSES_VERSION
    if (fore_color < 0 || back_color < 0)
        return 0;
#endif

    /* If either the foreground or background color is unspecified, we
     * need to read the other so we don't clobber it. */
    if (fore_color == UNSPECIFIED_COLOR) {
        short old_fore_color, old_back_color;

        pair_content(info->color_pair, &old_fore_color, &old_back_color);
        fore_color = old_fore_color;
    } else if (back_color == UNSPECIFIED_COLOR) {
        short old_fore_color, old_back_color;

        pair_content(info->color_pair, &old_fore_color, &old_back_color);
        back_color = old_back_color;
    }

    /* If the group is already using the default colors, and we're not changing
     * it, don't consume a color pair. */
    if (fore_color < 0 && back_color < 0 && info->color_pair == 0)
        return 0;

    /* Allocate a new color pair if the group doesn't have one yet. */
    if (info->color_pair == 0) {
        info->color_pair = next_color_pair;
        next_color_pair += 1;
    }

    /* Set up the color pair. */
    if (info->color_pair < COLOR_PAIRS) {
        if (init_pair(info->color_pair, fore_color, back_color) != OK)
            return -1;
    } else
        return -1;

    return 0;
}
Exemple #6
0
/* initialize curses colors */
void
init_colors ()
{
   use_default_colors ();

   init_pair (COL_BLUE, COLOR_BLUE, -1);
   if (conf.color_scheme == STD_GREEN)
      init_pair (COL_GREEN, COLOR_GREEN, -1);
   else
      init_pair (COL_GREEN, COLOR_WHITE, -1);

   init_pair (COL_RED, COLOR_RED, -1);
   init_pair (COL_BLACK, COLOR_BLACK, -1);
   init_pair (COL_CYAN, COLOR_CYAN, -1);
   init_pair (COL_YELLOW, COLOR_YELLOW, -1);

   if (conf.color_scheme == STD_GREEN)
      init_pair (BLUE_GREEN, COLOR_BLUE, COLOR_GREEN);
   else
      init_pair (BLUE_GREEN, COLOR_BLUE, COLOR_WHITE);

   init_pair (BLACK_GREEN, COLOR_BLACK, COLOR_GREEN);
   init_pair (BLACK_CYAN, COLOR_BLACK, COLOR_CYAN);
   init_pair (WHITE_RED, COLOR_WHITE, COLOR_RED);
}
Exemple #7
0
/** Initialize the curses interface windows. */
static bool initialize_windows(void)
{
  bool bStatus = false;

  if (NULL == (application_windows.pMainWin = initscr())) {
    goto main_fail;
  }

  start_color();

  f_nLeft = application_windows.pMainWin->_begx;
  f_nTop = application_windows.pMainWin->_begy;
  f_nWidth = application_windows.pMainWin->_maxx;
  f_nHeight = application_windows.pMainWin->_maxy;

  if (NULL == (application_windows.pTitleWin = newwin(3, f_nWidth, 0, 0))) {
    goto title_fail;
  }

  if (NULL == (application_windows.pProgressWin = newwin(2, f_nWidth, 3, 0))) {
    goto progress_fail;
  }

  if (NULL == (application_windows.pSummaryWin = newwin(1, f_nWidth, 5, 0))) {
    goto summary_fail;
  }

  if (NULL == (application_windows.pRunSummaryWin = newwin(1, f_nWidth, 6, 0))) {
    goto run_summary_fail;
  }

  if (NULL == (application_windows.pDetailsWin = newwin(f_nHeight - f_nTop - 7 , f_nWidth, 7, 0))) {
    goto details_fail;
  }

  if (NULL == (application_windows.pOptionsWin = newwin(1, f_nWidth, f_nHeight - f_nTop, 0))) {
    goto option_fail;
  }

  curs_set(0);
  noecho();
  cbreak();
  keypad(application_windows.pMainWin, CU_TRUE);
  init_pair(CLEAR_COLOR, COLOR_WHITE, COLOR_BLACK);
  init_pair(TITLE_COLOR, COLOR_WHITE, COLOR_BLACK);
  init_pair(PROGRESS_BACKGROUND_COLOR, COLOR_BLACK, COLOR_WHITE);
  init_pair(PROGRESS_SUCCESS_COLOR, COLOR_WHITE, COLOR_GREEN);
  init_pair(PROGRESS_FAILURE_COLOR, COLOR_WHITE, COLOR_RED);
  init_pair(MENU_COLOR, COLOR_WHITE, COLOR_BLACK);

  refresh_windows();
  bStatus = true;
  goto main_fail;

  /*
   * Error Handlers for all the stages.
   */
option_fail:
  delwin(application_windows.pDetailsWin);

details_fail:
  delwin(application_windows.pRunSummaryWin);

run_summary_fail:
  delwin(application_windows.pSummaryWin);

summary_fail:
  delwin(application_windows.pProgressWin);

progress_fail:
  delwin(application_windows.pTitleWin);

title_fail:
  endwin();

main_fail:
  return bStatus;

}
/* available colors:
   COLOR_BLACK   0
   COLOR_RED     1
   COLOR_GREEN   2
   COLOR_YELLOW  3
   COLOR_BLUE    4
   COLOR_MAGENTA 5
   COLOR_CYAN    6
   COLOR_WHITE   7
   */
static void set_normal_colors(void)
{
	init_pair(NORMAL, -1, -1);
	init_pair(MAIN_HEADING, COLOR_MAGENTA, -1);

	/* FORE is for the selected item */
	init_pair(MAIN_MENU_FORE, -1, -1);
	/* BACK for all the rest */
	init_pair(MAIN_MENU_BACK, -1, -1);
	init_pair(MAIN_MENU_GREY, -1, -1);
	init_pair(MAIN_MENU_HEADING, COLOR_GREEN, -1);
	init_pair(MAIN_MENU_BOX, COLOR_YELLOW, -1);

	init_pair(SCROLLWIN_TEXT, -1, -1);
	init_pair(SCROLLWIN_HEADING, COLOR_GREEN, -1);
	init_pair(SCROLLWIN_BOX, COLOR_YELLOW, -1);

	init_pair(DIALOG_TEXT, -1, -1);
	init_pair(DIALOG_BOX, COLOR_YELLOW, -1);
	init_pair(DIALOG_MENU_BACK, COLOR_YELLOW, -1);
	init_pair(DIALOG_MENU_FORE, COLOR_RED, -1);

	init_pair(INPUT_BOX, COLOR_YELLOW, -1);
	init_pair(INPUT_HEADING, COLOR_GREEN, -1);
	init_pair(INPUT_TEXT, -1, -1);
	init_pair(INPUT_FIELD, -1, -1);

	init_pair(FUNCTION_HIGHLIGHT, -1, -1);
	init_pair(FUNCTION_TEXT, COLOR_YELLOW, -1);
}
Exemple #9
0
int initcolor(void)
{
/*	if (!has_colors)	address was always true .. */
/*		return 0; */
	initscr();		/* Start ncurses */
	start_color();		/* Initialize color support */
	refresh();		/* Clear screen */
	noecho();		/* Don't echo */
	wattrset(stdscr, 0);	/* Clear attributes */
	scrollok(stdscr, TRUE);	/* Like a scrolling Stone... */
	leaveok(stdscr, TRUE);	/* Cursor position doesn't really matter */
	idlok(stdscr, TRUE);	/* Use hardware ins/del of the terminal */
	nodelay(stdscr, TRUE);	/* Make getch() nonblocking */

	/* Pick colors for each type */
	init_pair(T_PORT, COLOR_GREEN, COLOR_BLACK);
	init_pair(T_DATA, COLOR_WHITE, COLOR_BLACK);
	init_pair(T_ERROR, COLOR_RED, COLOR_BLACK);
	init_pair(T_PROTOCOL, COLOR_CYAN, COLOR_BLACK);
	init_pair(T_AXHDR, COLOR_WHITE, COLOR_BLACK);
	init_pair(T_IPHDR, COLOR_WHITE, COLOR_BLACK);
	init_pair(T_ADDR, COLOR_GREEN, COLOR_BLACK);
	init_pair(T_ROSEHDR, COLOR_WHITE, COLOR_BLACK);
	init_pair(T_TIMESTAMP, COLOR_YELLOW, COLOR_BLACK);
	init_pair(T_KISS, COLOR_MAGENTA, COLOR_BLACK);
	init_pair(T_BPQ, COLOR_MAGENTA, COLOR_BLACK);
	init_pair(T_TCPHDR, COLOR_BLUE, COLOR_BLACK);
	init_pair(T_FLEXNET, COLOR_BLUE, COLOR_BLACK);


	return 1;
}
Exemple #10
0
int main()
{
	FIELD *field[3];
	FORM  *my_form;
	WINDOW *my_form_win;
	int ch, rows, cols;
	
	/* Initialize curses */
	initscr();
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);

	/* Initialize few color pairs */
   	init_pair(1, COLOR_RED, COLOR_BLACK);

	/* Initialize the fields */
	field[0] = new_field(1, 10, 6, 1, 0, 0);
	field[1] = new_field(1, 10, 8, 1, 0, 0);
	field[2] = NULL;

	/* Set field options */
	set_field_back(field[0], A_UNDERLINE);
	field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */
					      /* Field is filled up 		*/
	set_field_back(field[1], A_UNDERLINE); 
	field_opts_off(field[1], O_AUTOSKIP);
	
	/* Create the form and post it */
	my_form = new_form(field);
	
	/* Calculate the area required for the form */
	scale_form(my_form, &rows, &cols);

	/* Create the window to be associated with the form */
        my_form_win = newwin(rows + 4, cols + 4, 4, 4);
        keypad(my_form_win, TRUE);

	/* Set main window and sub window */
        set_form_win(my_form, my_form_win);
        set_form_sub(my_form, derwin(my_form_win, rows, cols, 2, 2));

	/* Print a border around the main window and print a title */
        box(my_form_win, 0, 0);
	print_in_middle(my_form_win, 1, 0, cols + 4, "My Form", COLOR_PAIR(1));
	
	post_form(my_form);
	wrefresh(my_form_win);

	mvprintw(LINES - 2, 0, "Use UP, DOWN arrow keys to switch between fields");
	refresh();

	/* Loop through to get user requests */
	while((ch = wgetch(my_form_win)) != KEY_F(1))
	{	switch(ch)
		{	case KEY_DOWN:
				/* Go to next field */
				form_driver(my_form, REQ_NEXT_FIELD);
				/* Go to the end of the present buffer */
				/* Leaves nicely at the last character */
				form_driver(my_form, REQ_END_LINE);
				break;
			case KEY_UP:
				/* Go to previous field */
				form_driver(my_form, REQ_PREV_FIELD);
				form_driver(my_form, REQ_END_LINE);
				break;
			default:
				/* If this is a normal character, it gets */
				/* Printed				  */	
				form_driver(my_form, ch);
				break;
		}
	}

	/* Un post form and free the memory */
	unpost_form(my_form);
	free_form(my_form);
	free_field(field[0]);
	free_field(field[1]); 

	endwin();
	return 0;
}
Exemple #11
0
int main()
{	WINDOW *my_wins[3];
	PANEL  *my_panels[3];
	PANEL_DATA  *top;
	PANEL *stack_top;
	WINDOW *temp_win, *old_win;
	int ch;
	int newx, newy, neww, newh;
	int size = FALSE, move = FALSE;

	/* Initialize curses */
	initscr();
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);

	/* Initialize all the colors */
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);
	init_pair(3, COLOR_BLUE, COLOR_BLACK);
	init_pair(4, COLOR_CYAN, COLOR_BLACK);

	init_wins(my_wins, 3);
	
	/* Attach a panel to each window */ 	/* Order is bottom up */
	my_panels[0] = new_panel(my_wins[0]); 	/* Push 0, order: stdscr-0 */
	my_panels[1] = new_panel(my_wins[1]); 	/* Push 1, order: stdscr-0-1 */
	my_panels[2] = new_panel(my_wins[2]); 	/* Push 2, order: stdscr-0-1-2 */

	set_user_ptrs(my_panels, 3);
	/* Update the stacking order. 2nd panel will be on top */
	update_panels();

	/* Show it on the screen */
	attron(COLOR_PAIR(4));
	mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing");
	mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)");
	attroff(COLOR_PAIR(4));
	doupdate();

	stack_top = my_panels[2];
	top = (PANEL_DATA *)panel_userptr(stack_top);
	newx = top->x;
	newy = top->y;
	neww = top->w;
	newh = top->h;
	while((ch = getch()) != KEY_F(1))
	{	switch(ch)
		{	case 9:		/* Tab */
				top = (PANEL_DATA *)panel_userptr(stack_top);
				top_panel(top->next);
				stack_top = top->next;
				top = (PANEL_DATA *)panel_userptr(stack_top);
				newx = top->x;
				newy = top->y;
				neww = top->w;
				newh = top->h;
				break;
			case 'r':	/* Re-Size*/
				size = TRUE;
				attron(COLOR_PAIR(4));
				mvprintw(LINES - 4, 0, "Entered Resizing :Use Arrow Keys to resize and press <ENTER> to end resizing");
				refresh();
				attroff(COLOR_PAIR(4));
				break;
			case 'm':	/* Move */
				attron(COLOR_PAIR(4));
				mvprintw(LINES - 4, 0, "Entered Moving: Use Arrow Keys to Move and press <ENTER> to end moving");
				refresh();
				attroff(COLOR_PAIR(4));
				move = TRUE;
				break;
			case KEY_LEFT:
				if(size == TRUE)
				{	--newx;
					++neww;
				}
				if(move == TRUE)
					--newx;
				break;
			case KEY_RIGHT:
				if(size == TRUE)
				{	++newx;
					--neww;
				}
				if(move == TRUE)
					++newx;
				break;
			case KEY_UP:
				if(size == TRUE)
				{	--newy;
					++newh;
				}
				if(move == TRUE)
					--newy;
				break;
			case KEY_DOWN:
				if(size == TRUE)
				{	++newy;
					--newh;
				}
				if(move == TRUE)
					++newy;
				break;
			case 10:	/* Enter */
				move(LINES - 4, 0);
				clrtoeol();
				refresh();
				if(size == TRUE)
				{	old_win = panel_window(stack_top);
					temp_win = newwin(newh, neww, newy, newx);
					replace_panel(stack_top, temp_win);
					win_show(temp_win, top->label, top->label_color); 
					delwin(old_win);
					size = FALSE;
				}
				if(move == TRUE)
				{	move_panel(stack_top, newy, newx);
					move = FALSE;
				}
				break;
			
		}
		attron(COLOR_PAIR(4));
		mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing");
	    	mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)");
	    	attroff(COLOR_PAIR(4));
	        refresh();	
		update_panels();
		doupdate();
	}
	endwin();
	return 0;
}
Exemple #12
0
int main(int argc, char *argv[])
{
	world_t world;
	unsigned int each_iteration;
	unsigned int each_organism;
	unsigned int x;
	unsigned int y;
	char c;
	char color;
	organism_t organisms[ORGANISM_COUNT];

	srandom(RANDOM_SEED);

#if CURSES_VISUALIZATION
	initscr();
	start_color();

#if CURSES_SOLID_COLORS
	init_pair(1, COLOR_BLACK, COLOR_RED);
	init_pair(2, COLOR_BLACK, COLOR_GREEN);
	init_pair(3, COLOR_BLACK, COLOR_BLUE);
	init_pair(4, COLOR_BLACK, COLOR_WHITE);
	init_pair(5, COLOR_BLACK, COLOR_BLACK);
#else
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);
	init_pair(3, COLOR_BLUE, COLOR_BLACK);
	init_pair(4, COLOR_WHITE, COLOR_BLACK);
	init_pair(5, COLOR_BLACK, COLOR_BLACK);
#endif

#endif

	create_world(&world);
	for (each_organism = 0; each_organism < ORGANISM_COUNT; each_organism++) {
		create_organism(&world, &organisms[each_organism]);
	}
	for (each_iteration = 0; each_iteration < ITERATIONS; each_iteration++) {
		for (each_organism = 0; each_organism < ORGANISM_COUNT;
			 each_organism++) {
			move_organism(&world, &organisms[each_organism]);
		}
#if CURSES_VISUALIZATION
		for (x = 0; x < WORLD_WIDTH; x++) {
			for (y = 0; y < WORLD_HEIGHT; y++) {
				if (NULL == world.cells[x][y]) {
					color = 'x';
					c = ' ';
				}
				else {
					color = display_color(world.cells[x][y]);
					c = world.cells[x][y]->face;
				}
				switch (color) {
					case 'r':
						mvaddch(y, x, c | COLOR_PAIR(1));
						break;
					case 'g':
						mvaddch(y, x, c | COLOR_PAIR(2));
						break;
					case 'b':
						mvaddch(y, x, c | COLOR_PAIR(3));
						break;
					case 'w':
						mvaddch(y, x, c | COLOR_PAIR(4));
						break;
					default:
						mvaddch(y, x, c | COLOR_PAIR(5));
						break;
				}
			}
		}
		refresh();
		usleep(SLEEP_US);
#endif
	}

	for (each_organism = 0; each_organism < ORGANISM_COUNT; each_organism++) {
		destroy_organism(&world, &organisms[each_organism]);
	}

#if CURSES_VISUALIZATION
	endwin();
#endif

	return 0;
}
int main(){

	WINDOW *my_win, *menu_win, *my_menu_win;
	ITEM **my_items;
	MENU *my_menu;
	list *FileBuffer;
	
	int height, width, startx, starty, exit = 0;
	int highlight = 1;
	int ch, c, choice = 0, i, j;
	char str[81];
	
	FileBuffer = (list *)malloc(sizeof(list));
	
	
	if (FileBuffer == NULL)
		return;
	
	InitialiseBuffer(FileBuffer);
	
	initscr();
	clear();
	noecho();
	cbreak();
	
	start_color();
	
	
	/*Checking whether the terminal supports colors*/
	if (has_colors() == FALSE){
		endwin();
		printf("Your terminal does not support colors\n");
	}
		
	
	keypad(stdscr, TRUE);
	
	height = 3;
	width = 10;
	starty = (LINES - height)/2;
	startx = (COLS - width) / 2;	

	refresh();
	
	my_win = Create_NewWindow(height, width, starty, startx);

	mvwhline(my_win, 5, 1,	ACS_HLINE, width - 1);
	
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_CYAN, COLOR_BLACK);
	
	/* Create items */
    my_items = (ITEM **)calloc(nchoices, sizeof(ITEM *));
    for(i = 0; i < nchoices; ++i)
    	my_items[i] = new_item(menu_options[i], menu_options[i]);

	/* Create menu */	
	my_menu = new_menu((ITEM **)my_items);

	/* Set menu option not to show the description */
	menu_opts_off(my_menu, O_SHOWDESC);

	/* Create the window to be associated with the menu */
    my_menu_win = newwin(0, 0, 0, 0);
    keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
	set_menu_sub(my_menu, derwin(my_menu_win, 0, 0, 0, 0));
 	set_menu_format(my_menu, 1, 6);
	set_menu_mark(my_menu, " * ");


	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
	
	i = 0;
		
	mvwhline(my_menu_win, 1, 0, ACS_HLINE, COLS);
	mvwprintw(my_menu_win, LINES - 1, 0, "Press F3 to go to the menu, F6 to exit", c);
	
	
	while(1){
		choice = ToggleMenu(my_menu_win, my_menu, i);
		i = choice;
		switch(choice){
			case 0:
				MenuOpen(FileBuffer, my_menu_win);
				break;
			case 1:
				MenuNew(FileBuffer, my_menu_win, my_menu);
				break;
			case 2:
				MenuSave(FileBuffer, my_menu_win);
				break;
			case 3:
				MenuSaveAs(FileBuffer, my_menu_win);
				break;
			case 4:
				MenuEdit(FileBuffer, my_menu_win);
				break;
			case 5:
				MenuExit(FileBuffer, my_menu_win);
				exit = 1;
				break;
			default:
				break;
		}
		if (exit)
			break;
	}
	/*Assertion: the user wants to exit the program*/
    
		
	/* Unpost and free all the memory taken up */
       unpost_menu(my_menu);
       free_menu(my_menu);
       for(j = 0; j < nchoices; ++j)
               free_item(my_items[j]);
                
	clrtoeol();
	refresh();	
	
	/*Ending curses mode*/
	
	endwin();		
	return 0;
}
int main(int argc, char *argv[])
{
  /*****
   * boolean value indicates when to break main loop
   * (and thus finish this configuration tool)
   *****/
  int request_finish = 0;

  int current         = 0; /***** menu selection related variables */
  int menu_items      = 5;
  enum state status[] = {active, active, active, active, active};

  WINDOW *mainscr; /***** ncurses related variables */
  int i, j;

  /***** load configuration */

  if (loadConfiguration() == 0)
  {
    fprintf(stderr, "couldn't load configuration!");
    exit(-1);
  }

  /***** setup speaker model */

  model = (Model *) malloc(sizeof(Model));
  initModel(model);

  /***** ignore Ctrl-C */

  signal(SIGINT, SIG_IGN);

  /***** ncurses stuff */

  initscr();      /***** initialize the curses library */

  if (color_term != -1) /***** define dialog color pairs if terminal supports colors */
   {
      start_color ();
      if ((color_term = has_colors ()))
      {
         color_term = 1;
         init_pair (1, COLOR_WHITE, COLOR_BLUE);
         init_pair (2, COLOR_YELLOW, COLOR_BLUE);
         init_pair (3, COLOR_BLUE, COLOR_YELLOW);
         init_pair (4, COLOR_YELLOW, COLOR_CYAN);
      }
   }
   else
      color_term = 0;

  keypad(stdscr, TRUE);  /* enable keyboard mapping */
  scrollok (stdscr, FALSE);
  cbreak();              /* take input chars one at a time, no wait for \n */
  noecho();              /* don't echo input */
  refresh();

  mainscr = popupWindow(COLS, LINES); /***** dialog window that contains the main menu */
  leaveok (mainscr, FALSE);

  while (!request_finish)
  {
    wattrset (mainscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */

    /*****
     * draw a box around the dialog window
     * and empty it.
     *****/
    box(mainscr, 0, 0);
    for (i = 1; i < COLS-1; i++)
      for (j = 1; j < LINES-1; j++)
	mvwaddch(mainscr, j, i, ' ');

    /***** dialog header */

    mvwaddstr(mainscr, 1, 2, "CVoiceControl");
    mvwaddstrrght(mainscr, 1, COLS, "(c) 2000 Daniel Kiecza");
    mvwaddseparator(mainscr, 2, COLS);
    mvwaddstrcntr(mainscr, 3, COLS, "Speaker Model Editor");
    mvwaddseparator(mainscr, 4, COLS);

    /***** display main menu */

    mvwaddstr(mainscr, 5, 2, "Please Select:");
    mvwaddstr(mainscr, 5, 35, "Model:");

    if (model_file_name != NULL)
      mvwaddstr(mainscr, 5, 42, model_file_name);
    else
      mvwaddstr(mainscr, 5, 42, "(none)");

    setHighlight(mainscr, status[0], current == 0);
    mvwaddstr(mainscr,  7, 5,"New Speaker Model");
    setHighlight(mainscr, status[1], current == 1);
    mvwaddstr(mainscr,  8, 5,"Load Speaker Model");
    setHighlight(mainscr, status[2], current == 2);
    mvwaddstr(mainscr,  9, 5,"Edit Speaker Model");
    setHighlight(mainscr, status[3], current == 3);
    mvwaddstr(mainscr, 10, 5,"Save Speaker Model");
    setHighlight(mainscr, status[4], current == 4);
    mvwaddstr(mainscr, 11, 5,"Exit");

    wmove(mainscr, 5, 17); /***** move cursor to an appropriate location */
    wrefresh(mainscr);     /***** refresh dialog window */

    /* process the command keystroke */

    switch(getch())
    {
    case KEY_UP:   /***** cursor up */
      current = (current == 0 ? menu_items - 1 : current - 1);
      break;
    case KEY_DOWN: /***** cursor down */
      current = (current == menu_items-1 ? 0 : current + 1);
      break;
    case ENTER:    /***** handle menu selections */
    case BLANK:
      switch (current)
      {
      case 0: /***** reset model, but make sure no data gets lost */
	safeResetModel();
	break;
      case 1: /***** load model */
	if (safeResetModel())
	{
	  int max_file_length = 80;
	  char *file_name;
	  char show_file_name[82];
	
	  int width = 45, height = 11, i, j;             /***** ncurses related variables */
	  WINDOW *loadscr = popupWindow (width, height);

	  wattrset (loadscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */

	  /*****
	   * draw a box around the dialog window
	   * and empty it.
	   *****/
	  werase (loadscr);
	  box (loadscr, 0, 0);
	  for (i = 1; i < width-1; i++)
	    for (j = 1; j < height-1; j++)
	      mvwaddch(loadscr, j, i, ' ');

	  /***** dialog header */
	
	  mvwaddstr(loadscr, 1, 2, "Please enter file name:");
	  mvwaddseparator(loadscr, 2, width);

	  wrefresh (loadscr);
	  wattroff(loadscr, A_BOLD);
	
	  file_name = wstringInput(loadscr, 4, 2, max_file_length, width-5, ""); /***** get file name */

	  /*****
	   * show_file_name is set to "file" if the file_name is longer
	   * than 15 characters. That way dialog messages stay within the
	   * boundaries of the dialog
	   *****/
	  if (strlen(file_name) <= 15)
	    strcpy(show_file_name, file_name);
	  else
	    strcpy(show_file_name, "file");

	  /***** display information that model is being loaded */
	
	  wattrset (loadscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL);
	  mvwaddstr(loadscr, 6,  2, "Loading");
	  mvwaddstr(loadscr, 6, 10, show_file_name);
	  mvwaddstr(loadscr, 6, 11+strlen(show_file_name), "...");
	  wrefresh(loadscr);

	  if (loadModel(model, file_name, 1) == 1) /***** loading model is successful */
	  {
	    mvwaddstr(loadscr, 6, 15+strlen(show_file_name), "success!");

	    /***** set variable model_file_name */
	
	    if (strstr(file_name, model_file_extension) !=
		file_name+strlen(file_name)-strlen(model_file_extension))
	    {
	      model_file_name = malloc(strlen(file_name) + strlen(model_file_extension) + 1);
	      strcpy(model_file_name, file_name);
	      strcat(model_file_name, model_file_extension);
	    }
	    else
	    {
	      model_file_name = malloc(strlen(file_name) + 1);
	      strcpy(model_file_name, file_name);
	    }
	  }
	  else /***** loading model has failed */
	    mvwaddstr(loadscr, 6, 15+strlen(show_file_name), "failed!");
	  mvwaddstrcntr(loadscr, 8, width,"Press <Space> to return to menu ...");
	  wrefresh(loadscr); /***** refresh dialog */
	  getch();           /***** wait for keyboard input */

	  delwin(loadscr);   /***** delete ncurses dialog window */
	  free (file_name);
	}
	break;
      case 2: /***** edit the speaker model */
	editModel();
	break;
      case 3: /***** save the speaker model */
	if (model->number_of_items > 0)
	{
	  char *file_name;
	  int max_file_length = 84;
	
	  int width = 45, height = 11, i, j; /***** ncurses related variables */
	  WINDOW *savescr = popupWindow (width, height);

	  wattrset (savescr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */

	  /*****
	   * draw a box around the dialog window
	   * and empty it.
	   *****/
	  werase (savescr);
	  box (savescr, 0, 0);
	  for (i = 1; i < width-1; i++)
	    for (j = 1; j < height-1; j++)
	      mvwaddch(savescr, j, i, ' ');

	  /***** display dialog header */
	
	  mvwaddstr(savescr, 1, 2, "Please enter file name:");
	  mvwaddseparator(savescr, 2, width);

	  wrefresh (savescr);
	  wattroff(savescr, A_BOLD);
	
	  file_name = wstringInput(savescr, 4, 2, max_file_length,
				   width-5, model_file_name); /***** get file name */
	
	  /***** display information that model is being saved */

	  wattrset (savescr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL);
	  mvwaddstr(savescr, 6,  2, "Saving ...");
	  wrefresh(savescr);

	  if (saveModel(model, file_name) == 1) /***** saving successful */
	  {
	    mvwaddstr(savescr, 6, 13, "success!");

	    /***** update model_file_name if necessary */

	    if (model_file_name != NULL && strcmp(model_file_name, file_name) != 0)
	    {
	      free(model_file_name);
	      model_file_name = malloc(strlen(file_name) + 1);
	      strcpy(model_file_name, file_name);
	    }
	
	    modified = 0; /***** switch modified to '0' */
	  }
	  else /***** saving failed */
	    mvwaddstr(savescr, 6, 13, "failed!");
	  mvwaddstrcntr(savescr, 8, width,"Press <Space> to return to menu ...");
	  wrefresh(savescr); /***** refresh dialog */
	  getch();           /***** wait for keyboard input */

	  delwin(savescr);   /***** delete ncurses dialog window */
	  free (file_name);
	}
	break;
      case 4: /***** quit program */
	if (safeResetModel())
	{
	  wrefresh(mainscr);
  	  request_finish = 1;
	  delwin(mainscr);   /***** delete ncurses dialog window */
	}
	break;
      }
      break;
    }
  }

  endwin(); /***** wrap up ncurses stuff */
  exit(0);  /***** exit program */
}
Exemple #15
0
static void
test_inserts(int level)
{
    static bool first = TRUE;

    wint_t ch;
    int code;
    int limit;
    int row = 1;
    int col;
    int row2, col2;
    int length;
    wchar_t buffer[BUFSIZ];
    WINDOW *look = 0;
    WINDOW *work = 0;
    WINDOW *show = 0;
    int margin = (2 * TABSIZE) - 1;
    Options option = ((m_opt ? oMove : oDefault)
		      | ((w_opt || (level > 0)) ? oWindow : oDefault));

    if (first) {
	static char cmd[80];
	setlocale(LC_ALL, "");

	putenv(strcpy(cmd, "TABSIZE=8"));

	initscr();
	(void) cbreak();	/* take input chars one at a time, no wait for \n */
	(void) noecho();	/* don't echo input */
	keypad(stdscr, TRUE);
    }

    limit = LINES - 5;
    if (level > 0) {
	look = newwin(limit, COLS - (2 * (level - 1)), 0, level - 1);
	work = newwin(limit - 2, COLS - (2 * level), 1, level);
	show = newwin(4, COLS, limit + 1, 0);
	box(look, 0, 0);
	wnoutrefresh(look);
	limit -= 2;
    } else {
	work = stdscr;
	show = derwin(stdscr, 4, COLS, limit + 1, 0);
    }
    keypad(work, TRUE);

    for (col = margin + 1; col < COLS; col += TABSIZE)
	mvwvline(work, row, col, '.', limit - 2);

    mvwvline(work, row, margin, ACS_VLINE, limit - 2);
    mvwvline(work, row, margin + 1, ACS_VLINE, limit - 2);
    limit /= 2;

    mvwaddstr(work, 1, 2, "String");
    mvwaddstr(work, limit + 1, 2, "Chars");
    wnoutrefresh(work);

    buffer[length = 0] = '\0';
    legend(show, level, option, buffer, length);
    wnoutrefresh(show);

    doupdate();

    /*
     * Show the characters inserted in color, to distinguish from those that
     * are shifted.
     */
    if (has_colors()) {
	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLUE);
	wbkgdset(work, COLOR_PAIR(1) | ' ');
    }

    while ((code = wget_wch(work, &ch)) != ERR) {

	if (code == KEY_CODE_YES) {
	    switch (ch) {
	    case KEY_DOWN:
		ch = CTRL('N');
		break;
	    case KEY_BACKSPACE:
		ch = '\b';
		break;
	    default:
		beep();
		continue;
	    }
	} else if (code == ERR) {
	    beep();
	    break;
	}
	if (ch == 'q')
	    break;

	wmove(work, row, margin + 1);
	switch (ch) {
	case 'w':
	    test_inserts(level + 1);

	    touchwin(look);
	    touchwin(work);
	    touchwin(show);

	    wnoutrefresh(look);
	    wnoutrefresh(work);
	    wnoutrefresh(show);

	    doupdate();
	    break;
	case CTRL('N'):
	    if (row < limit) {
		++row;
		/* put the whole string in, all at once */
		col2 = margin + 1;
		switch (option) {
		case oDefault:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    if (move(row, col2) != ERR) {
				InsNStr(buffer + col, LEN(col));
			    }
			}
		    } else {
			if (move(row, col2) != ERR) {
			    InsStr(buffer);
			}
		    }
		    break;
		case oMove:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    MvInsNStr(row, col2, buffer + col, LEN(col));
			}
		    } else {
			MvInsStr(row, col2, buffer);
		    }
		    break;
		case oWindow:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    if (wmove(work, row, col2) != ERR) {
				WInsNStr(work, buffer + col, LEN(col));
			    }
			}
		    } else {
			if (wmove(work, row, col2) != ERR) {
			    WInsStr(work, buffer);
			}
		    }
		    break;
		case oMoveWindow:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    MvWInsNStr(work, row, col2, buffer + col, LEN(col));
			}
		    } else {
			MvWInsStr(work, row, col2, buffer);
		    }
		    break;
		}

		/* do the corresponding single-character insertion */
		row2 = limit + row;
		for (col = 0; col < length; ++col) {
		    col2 = ColOf(buffer, col, margin);
		    switch (option) {
		    case oDefault:
			if (move(row2, col2) != ERR) {
			    InsCh((chtype) buffer[col]);
			}
			break;
		    case oMove:
			MvInsCh(row2, col2, (chtype) buffer[col]);
			break;
		    case oWindow:
			if (wmove(work, row2, col2) != ERR) {
			    WInsCh(work, (chtype) buffer[col]);
			}
			break;
		    case oMoveWindow:
			MvWInsCh(work, row2, col2, (chtype) buffer[col]);
			break;
		    }
		}
	    } else {
		beep();
	    }
	    break;
	case KEY_BACKSPACE:
	    ch = '\b';
	    /* FALLTHRU */
	default:
	    buffer[length++] = ch;
	    buffer[length] = '\0';

	    /* put the string in, one character at a time */
	    col = ColOf(buffer, length - 1, margin);
	    switch (option) {
	    case oDefault:
		if (move(row, col) != ERR) {
		    InsStr(buffer + length - 1);
		}
		break;
	    case oMove:
		MvInsStr(row, col, buffer + length - 1);
		break;
	    case oWindow:
		if (wmove(work, row, col) != ERR) {
		    WInsStr(work, buffer + length - 1);
		}
		break;
	    case oMoveWindow:
		MvWInsStr(work, row, col, buffer + length - 1);
		break;
	    }

	    /* do the corresponding single-character insertion */
	    switch (option) {
	    case oDefault:
		if (move(limit + row, col) != ERR) {
		    InsCh(ch);
		}
		break;
	    case oMove:
		MvInsCh(limit + row, col, ch);
		break;
	    case oWindow:
		if (wmove(work, limit + row, col) != ERR) {
		    WInsCh(work, ch);
		}
		break;
	    case oMoveWindow:
		MvWInsCh(work, limit + row, col, ch);
		break;
	    }

	    wnoutrefresh(work);

	    legend(show, level, option, buffer, length);
	    wnoutrefresh(show);

	    doupdate();
	    break;
	}
    }
    if (level > 0) {
	delwin(show);
	delwin(work);
	delwin(look);
    }
}
Exemple #16
0
/* Main execution loop in live mode. Builds the list of processes,
 * collects statistics, and prints using curses. Repeats after some
 * delay, also catching key presses.
 */
static int live_mode(struct process_list* proc_list, screen_t* screen)
{
  WINDOW*         help_win = NULL;
  WINDOW*         error_win = NULL;
  fd_set          fds;
  struct process** p;
  int             num_iter = 0;
  int             with_colors = 0;
  int             pos;

  /* start curses */
  initscr();
  cbreak();
  noecho();
  keypad(stdscr, TRUE);

  /* Prepare help window */
  help_win = prepare_help_win(screen);

  if (has_colors()) {
    /* initialize curses colors */
    with_colors = 1;
    start_color();
    init_pair(1, COLOR_BLACK, COLOR_WHITE);
    init_pair(2, COLOR_WHITE, COLOR_BLACK);
    init_pair(3, COLOR_GREEN, COLOR_BLACK);
    init_pair(4, COLOR_YELLOW, COLOR_BLACK);
    init_pair(5, COLOR_RED, COLOR_BLACK);
    attron(COLOR_PAIR(0));
  }

  tv.tv_sec = 0;
  tv.tv_usec = 200000; /* 200 ms for first iteration */

  header = gen_header(screen, &options, COLS - 1, active_col);

  pos = screen_pos(screen);

  for(num_iter=0; !options.max_iter || num_iter<options.max_iter; num_iter++) {
    int  i, zz, printed, num_fd, num_dead;

    /* print various info */
    erase();
    mvprintw(0, 0, "tiptop -");

    if ((num_errors() > 0) && (COLS >= 37))
      mvprintw(LINES-1, 30, "[errors]");
    if ((options.config_file == 1) && (COLS >= 60))
      mvprintw(0, COLS-60, "[conf]");
    if ((options.euid == 0) && (COLS >= 54))
      mvprintw(0, COLS-54, "[root]");
    if ((options.watch_uid != -1) && (COLS >= 48))
      mvprintw(0, COLS-48, "[uid]");
    if ((options.only_pid || options.only_name) && (COLS >= 43))
      mvprintw(0, COLS-43, "[pid]");
    if (options.show_kernel && (COLS >= 38))
      mvprintw(0, COLS-38, "[kernel]");
    if (options.sticky && (COLS >= 30))
      mvprintw(0, COLS-30, "[sticky]");
    if (options.show_threads && (COLS >= 22))
      mvprintw(0, COLS-22, "[threads]");
    if (options.idle && (COLS >= 13))
      mvprintw(0, COLS-13, "[idle]");
    if (options.debug && (COLS >= 7))
      mvprintw(0, COLS-7, "[debug]");

    if (options.show_epoch && (COLS >= 18))
      mvprintw(LINES-1, COLS-18, "Epoch: %u", time(NULL));

    if (options.show_timestamp)
      mvprintw(LINES-1, 0, "Iteration: %u", num_iter);

    /* print main header */
    if (with_colors)
      attron(COLOR_PAIR(1));
    mvprintw(3, 0, "%s", header);
    for(zz=strlen(header); zz < COLS-1; zz++)
      printw(" ");
    printw("\n");
    if (with_colors)
      attroff(COLOR_PAIR(1));

    /* update the list of processes/threads and accumulate info if needed */
    num_dead = update_proc_list(proc_list, screen, &options);

    if (!options.show_threads)
      accumulate_stats(proc_list);

    p = proc_list->proc_ptrs;

    /* prepare for select */
    FD_ZERO(&fds);
    FD_SET(STDIN_FILENO, &fds);

    /* generate the text version of all rows */
    build_rows(proc_list, screen, COLS - 1);

    /* sort by %CPU */
    qsort(p, proc_list->num_tids, sizeof(struct process*), sorting_fun);

    printed = 0;

    /* Iterate over all threads */
    for(i=0; i < proc_list->num_tids; i++) {

      if (p[i]->skip)
        continue;

      /* highlight watched process, if any */
      if (with_colors) {
        if (p[i]->dead) {
          attron(COLOR_PAIR(5));
        }
        else if ((p[i]->tid == options.watch_pid) ||
                 (options.watch_name && options.show_cmdline &&
                                strstr(p[i]->cmdline, options.watch_name)) ||
                 (options.watch_name && !options.show_cmdline &&
                                strstr(p[i]->name, options.watch_name)))
          attron(COLOR_PAIR(3));
      }

      if (options.show_threads || (p[i]->pid == p[i]->tid)) {
        printw("%s\n", p[i]->txt);
        printed++;
      }

      if (with_colors)
        attroff(COLOR_PAIR(3));

      if (printed >= LINES - 5)  /* stop printing at bottom of window */
        break;
    }

    mvprintw(1, 0, "Tasks: %3d total, %3d displayed",
             proc_list->num_tids, printed);
    if (options.sticky)
      printw(", %3d dead", num_dead);

    /* print the screen name, make sure it fits, or truncate */
    if (with_colors)
      attron(COLOR_PAIR(4));
    if (35 + 20 + 11 + strlen(screen->name) < COLS) {
      mvprintw(1, COLS - 11 - strlen(screen->name),
               "screen %2d: %s\n", pos, screen->name);
    }
    else if (COLS >= 35 + 20 + 11) {
      char screen_str[50] = { 0 };
      snprintf(screen_str, sizeof(screen_str) - 1, "%s\n", screen->name);
      screen_str[COLS - 35 - 20 - 11] = '\0';  /* truncate */
      mvprintw(1, 35+20, "screen %2d: %s", pos, screen_str);
    }
    if (with_colors)
      attroff(COLOR_PAIR(4));

    /* print message if any */
    if (message) {
      if (with_colors)
        attron(COLOR_PAIR(1));
      mvprintw(2, 0, "%s", message);
      if (with_colors)
        attroff(COLOR_PAIR(1));
      message = NULL;  /* reset message */
    }

    refresh();  /* display everything */
    if (options.error) {
      if (options.error == 1) {
        options.error = 2;
        show_error_win(error_win, printed);
      }
      else
        show_error_win(error_win, -1);
    }
    if (options.help)
      show_help_win(help_win, screen);

    if ((num_dead) && (!options.sticky))
      compact_proc_list(proc_list);

    /* wait some delay, or until a key is pressed */
    num_fd = select(1 + STDIN_FILENO, &fds, NULL, NULL, &tv);
    if (num_fd > 0) {
      int c = handle_key();
      if (c == 'q')
        break;
      if (c == '>') {
        if (active_col < screen->num_columns )
          active_col++;
        free(header);
        header = gen_header(screen, &options, COLS - 1, active_col);
      }
      if (c == '<') {
        if (active_col > -1)
          active_col--;
        free(header);
        header = gen_header(screen, &options, COLS - 1, active_col);
      }
      if (c == 'H') {
        if (options.show_threads) {
          reset_values(proc_list);
          message = "Show threads On";
        }
        else
          message = "Show threads Off";
      }
      if (c == 'U') {
        free(header);
        header = gen_header(screen, &options, COLS - 1, active_col);
      }
      if ((c == '+') || (c == '-') || (c == KEY_LEFT) || (c == KEY_RIGHT))
        return c;

      if ((c == 'u') || (c == 'K') || (c == 'p')) /* need to rebuild tasks list */
        return c;

      if (c == 'e') {
        if (options.error > 0) {
          options.error = 0;
          delwin(error_win);
          error_win = NULL;
        }
        else
          options.error = 1;
      }
    }
    tv.tv_sec = options.delay;
    tv.tv_usec = (options.delay - tv.tv_sec) * 1000000.0;
  }

  free(header);

  delwin(help_win);

  endwin();  /* stop curses */
  return 'q';
}
Exemple #17
0
int main(int argc, char **argv)
{
    int c, i;

    struct panelw *actw;
    MEVENT event;
    const char *cb;

    args.address = 0x20;
    args.bus = 0x02;
    args.columns = 16;
    args.rows = 2;

    do
    {
        i = 0;
        c = getopt_long(argc, argv, "abc::r::h", options, &i);
        switch(c)
        {
            case 'a':
                if (optarg)
                {
                    args.address = strtoul(optarg, NULL, 0);
                    if (args.address == 0x00)
                        help(argv, "Address of a chip must be a number!");
                }
                break;
            case 'b':
                if (optarg)
                {
                    args.bus = strtoul(optarg, NULL, 0);
                    if (args.bus == 0x00)
                        help(argv, "Bus number must be a number!");
                }
                break;
            case 'c':
                if (optarg)
                {
                    args.columns = strtoul(optarg, NULL, 0);
                    if (args.columns == 0x00)
                        help(argv, "The display is not in the list below:");
                }
                break;
            case 'r':
                if (optarg)
                {
                    args.rows = strtoul(optarg, NULL, 0);
                    if (args.rows == 0x00)
                        help(argv, "The display is not in the list below:");
                }
                break;
            case 'f':
                if (optarg)
                    strncpy(args.headername, optarg, 32);
                else
                    strncpy(args.headername, "./gcbitmap.h", 32);
                break;
            case 'h':
                help(argv, "");
            case -1:
                break;
            case '?':
                help(argv, "Unknown option");
                break;
            default:
                help(argv, "No options given");
                break;

        }
    }while(c != -1);

    initscr();
    refresh();
    keypad(stdscr, TRUE);
    nonl();
    cbreak();
    noecho();
    curs_set(1);

    if (has_colors())
    {
	start_color();
	init_pair(1, COLOR_BLACK, COLOR_GREEN);
	init_pair(2, COLOR_WHITE, COLOR_BLACK);
	init_pair(3, COLOR_WHITE, COLOR_BLUE);
	init_pair(4, COLOR_GREEN, COLOR_BLACK);

	wattron(stdscr, COLOR_PAIR(4));
	wbkgd(stdscr, COLOR_PAIR(4));
    }

    openEditor(&args, &ed);
    actw = ed._actw;
    for(i=0; i < 8; i++)
        lcdSetGC(&ed.lcd, i, gcbitmap[i]);
    setWindowState(actw, 1);
    gcActivateHandler(actw->next);

    while(((c = wgetch(actw->win)) != KEY_F(10)))
    {
	//
	switch(c)
	{
	    case KEY_F(5):
		ed.brght -= ed.brght > 0 ? 1 : 0;
		lcdSetBacklight(&ed.lcd, ed.brght);
                mvwprintw(ed.potss->win, 1, 1, "Brightness:\t0x%02X", ed.brght);
                update_panels();
                doupdate();
		refresh();
	    continue;
	    case KEY_F(6):
		ed.brght += ed.brght < 0x3f ? 1 : 0;
		lcdSetBacklight(&ed.lcd, ed.brght);
		mvwprintw(ed.potss->win, 1, 1, "Brightness:\t0x%02X", ed.brght);
                update_panels();
                doupdate();
		refresh();
	    continue;
	    case KEY_F(4):
		ed.contr -= ed.contr > 0 ? 1 : 0;
		lcdSetContrast(&ed.lcd, ed.contr);
                mvwprintw(ed.potss->win, 2, 1, "Contrast:\t0x%02X", ed.contr);
                update_panels();
                doupdate();
		refresh();
	    continue;
	    case KEY_F(3):
		ed.contr += ed.contr < 0x3f ? 1 : 0;
		lcdSetContrast(&ed.lcd, ed.contr);
		mvwprintw(ed.potss->win, 2, 1, "Contrast:\t0x%02X", ed.contr);
                update_panels();
                doupdate();
		refresh();
	    continue;
            case 9:
                setWindowState(actw, 0);
                actw = returnNextWindow(&ed);
                setWindowState(actw, 1);
                continue;
	    case KEY_MOUSE:
		if(getmouse(&event) == OK)
		{
		    printf("%d %d\n", event.x, event.y);
		}
		continue;
            default:
                if(actw->handler)
                    actw->handler(actw, c);
                continue;
	}

    }

    closeEditor(&ed);

    clear();
    endwin();

    return 0;
}
static void display_window(TALLOC_CTX *mem_ctx, struct registry_context *ctx)
{
	struct regedit *regedit;
	struct tree_node *root;
	bool colors;
	int key;

	initscr();

	cbreak();
	noecho();

	fault_configure(regedit_panic_handler);

	colors = has_colors();
	if (colors) {
		start_color();
		use_default_colors();
		assume_default_colors(COLOR_WHITE, COLOR_BLUE);
		init_pair(PAIR_YELLOW_CYAN, COLOR_YELLOW, COLOR_CYAN);
		init_pair(PAIR_BLACK_CYAN, COLOR_BLACK, COLOR_CYAN);
		init_pair(PAIR_YELLOW_BLUE, COLOR_YELLOW, COLOR_BLUE);
	}

	regedit = talloc_zero(mem_ctx, struct regedit);
	SMB_ASSERT(regedit != NULL);
	regedit_main = regedit;

	regedit->registry_context = ctx;
	regedit->main_window = stdscr;
	keypad(regedit->main_window, TRUE);

	mvwprintw(regedit->main_window, 0, 0, "Path: ");
	regedit->path_label = newpad(1, PATH_WIDTH_MAX);
	SMB_ASSERT(regedit->path_label);
	wprintw(regedit->path_label, "/");
	show_path(regedit_main);

	root = tree_node_new_root(regedit, ctx);
	SMB_ASSERT(root != NULL);

	regedit->keys = tree_view_new(regedit, root, KEY_HEIGHT, KEY_WIDTH,
				      KEY_START_Y, KEY_START_X);
	SMB_ASSERT(regedit->keys != NULL);

	regedit->vl = value_list_new(regedit, VAL_HEIGHT, VAL_WIDTH,
				     VAL_START_Y, VAL_START_X);
	SMB_ASSERT(regedit->vl != NULL);

	regedit->tree_input = true;
	print_heading(regedit);

	tree_view_show(regedit->keys);
	load_values(regedit);
	value_list_show(regedit->vl);

	update_panels();
	doupdate();

	do {
		key = regedit_getch();

		handle_main_input(regedit, key);
		update_panels();
		doupdate();
	} while (key != 'q' || key == 'Q');

	endwin();
}
Exemple #19
0
/*
 * Prepare "curses" for use by the file "z-term.c"
 *
 * Installs the "hook" functions defined above, and then activates
 * the main screen "term", which clears the screen and such things.
 *
 * Someone should really check the semantics of "initscr()"
 */
errr init_gcu(int argc, char **argv)
{
	int i;

	int num_term = MAX_TERM_DATA, next_win = 0;

	bool use_big_screen = FALSE;


	/* Parse args */
	for (i = 1; i < argc; i++)
	{
		if (prefix(argv[i], "-b"))
		{
			use_big_screen = TRUE;
			continue;
		}

		plog_fmt("Ignoring option: %s", argv[i]);
	}


	/* Extract the normal keymap */
	keymap_norm_prepare();


#if defined(USG)
	/* Initialize for USG Unix */
	if (initscr() == NULL) return ( -1);
#else
/* Initialize for other systems */
	if (initscr() == (WINDOW*)ERR) return ( -1);
#endif

	/* Activate hooks */
	quit_aux = hook_quit;
	core_aux = hook_quit;

	/* Require standard size screen */
	if ((LINES < 24) || (COLS < 80))
	{
		quit("Angband needs at least an 80x24 'curses' screen");
	}


#ifdef USE_GRAPHICS

	/* Set graphics flag */
	use_graphics = arg_graphics;

#endif

#ifdef A_COLOR

	/*** Init the Color-pairs and set up a translation table ***/

	/* Do we have color, and enough color, available? */
	can_use_color = ((start_color() != ERR) && has_colors() &&
	                 (COLORS >= 8) && (COLOR_PAIRS >= 8));

#ifdef REDEFINE_COLORS

	/* Can we change colors? */
	can_fix_color = (can_use_color && can_change_color() &&
	                 (COLORS >= 16) && (COLOR_PAIRS > 8));

#endif

	/* Attempt to use customized colors */
	if (can_fix_color)
	{
		/* Prepare the color pairs */
		for (i = 1; i <= 8; i++)
		{
			/* Reset the color */
			if (init_pair(i, i - 1, 0) == ERR)
			{
				quit("Color pair init failed");
			}

			/* Set up the colormap */
			colortable[i - 1] = (COLOR_PAIR(i) | A_NORMAL);
			colortable[i + 7] = (COLOR_PAIR(i) | A_BRIGHT);
		}

		/* Take account of "gamma correction" XXX XXX XXX */

		/* Prepare the "Angband Colors" */
		Term_xtra_gcu_react();
	}

	/* Attempt to use colors */
	else if (can_use_color)
	{
		/* Color-pair 0 is *always* WHITE on BLACK */

		/* 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);

		/* Prepare the "Angband Colors" -- Bright white is too bright */
		colortable[0] = (COLOR_PAIR(7) | A_NORMAL); 	/* Black */
		colortable[1] = (COLOR_PAIR(0) | A_NORMAL); 	/* White */
		colortable[2] = (COLOR_PAIR(6) | A_NORMAL); 	/* Grey XXX */
		colortable[3] = (COLOR_PAIR(1) | A_BRIGHT); 	/* Orange XXX */
		colortable[4] = (COLOR_PAIR(1) | A_NORMAL); 	/* Red */
		colortable[5] = (COLOR_PAIR(2) | A_NORMAL); 	/* Green */
		colortable[6] = (COLOR_PAIR(4) | A_NORMAL); 	/* Blue */
		colortable[7] = (COLOR_PAIR(3) | A_NORMAL); 	/* Umber */
		colortable[8] = (COLOR_PAIR(7) | A_BRIGHT); 	/* Dark-grey XXX */
		colortable[9] = (COLOR_PAIR(6) | A_BRIGHT); 	/* Light-grey XXX */
		colortable[10] = (COLOR_PAIR(5) | A_NORMAL); 	/* Purple */
		colortable[11] = (COLOR_PAIR(3) | A_BRIGHT); 	/* Yellow */
		colortable[12] = (COLOR_PAIR(5) | A_BRIGHT); 	/* Light Red XXX */
		colortable[13] = (COLOR_PAIR(2) | A_BRIGHT); 	/* Light Green */
		colortable[14] = (COLOR_PAIR(4) | A_BRIGHT); 	/* Light Blue */
		colortable[15] = (COLOR_PAIR(3) | A_NORMAL); 	/* Light Umber XXX */
	}

#endif


	/*** Low level preparation ***/

#ifdef USE_GETCH

	/* Paranoia -- Assume no waiting */
	nodelay(stdscr, FALSE);

#endif

	/* Prepare */
	cbreak();
	noecho();
	nonl();

	/* Extract the game keymap */
	keymap_game_prepare();


	/*** Now prepare the term(s) ***/

	/* Big screen -- one big term */
	if (use_big_screen)
	{
		/* Create a term */
		term_data_init_gcu(&data[0], LINES, COLS, 0, 0);

		/* Remember the term */
		angband_term[0] = &data[0].t;
	}

	/* No big screen -- create as many term windows as possible */
	else
	{
		/* Create several terms */
		for (i = 0; i < num_term; i++)
		{
			int rows, cols, y, x;

			/* Decide on size and position */
			switch (i)
			{
				/* Upper left */
			case 0:
				{
					rows = 24;
					cols = 80;
					y = x = 0;
					break;
				}

				/* Lower left */
			case 1:
				{
					rows = LINES - 25;
					cols = 80;
					y = 25;
					x = 0;
					break;
				}

				/* Upper right */
			case 2:
				{
					rows = 24;
					cols = COLS - 81;
					y = 0;
					x = 81;
					break;
				}

				/* Lower right */
			case 3:
				{
					rows = LINES - 25;
					cols = COLS - 81;
					y = 25;
					x = 81;
					break;
				}

				/* XXX */
			default:
				{
					rows = cols = y = x = 0;
					break;
				}
			}

			/* Skip non-existant windows */
			if (rows <= 0 || cols <= 0) continue;

			/* Create a term */
			term_data_init_gcu(&data[next_win], rows, cols, y, x);

			/* Remember the term */
			angband_term[next_win] = &data[next_win].t;

			/* One more window */
			next_win++;
		}
	}

	/* Activate the "Angband" window screen */
	Term_activate(&data[0].t);

	/* Remember the active screen */
	term_screen = &data[0].t;

	/* Success */
	return (0);
}
Exemple #20
0
static WINDOW *
ncurses_setup(void){
	struct ncurses_input_marshal *nim;
	const char *errstr = NULL;
	WINDOW *w = NULL;

	fprintf(stderr,"Entering ncurses mode...\n");
	if(initscr() == NULL){
		fprintf(stderr,"Couldn't initialize ncurses\n");
		return NULL;
	}
	if(cbreak() != OK){
		errstr = "Couldn't disable input buffering\n";
		goto err;
	}
	if(noecho() != OK){
		errstr = "Couldn't disable input echoing\n";
		goto err;
	}
	if(intrflush(stdscr,TRUE) != OK){
		errstr = "Couldn't set flush-on-interrupt\n";
		goto err;
	}
	if(scrollok(stdscr,FALSE) != OK){
		errstr = "Couldn't disable scrolling\n";
		goto err;
	}
	if(nonl() != OK){
		errstr = "Couldn't disable nl translation\n";
		goto err;
	}
	if(start_color() != OK){
		errstr = "Couldn't initialize ncurses color\n";
		goto err;
	}
	if(use_default_colors()){
		errstr = "Couldn't initialize ncurses colordefs\n";
		goto err;
	}
	w = stdscr;
	ESCDELAY = 100;
	keypad(stdscr,TRUE);
	if(nodelay(stdscr,FALSE) != OK){
		errstr = "Couldn't set blocking input\n";
		goto err;
	}
	if(curs_set(0) == ERR){
		errstr = "Couldn't disable cursor\n";
		goto err;
	}
	if(setup_statusbar(COLS)){
		errstr = "Couldn't setup status bar\n";
		goto err;
	}
	if(COLORS < 16){
		assert(init_pair(BORDER_COLOR,COLOR_GREEN,-1) == OK);
		assert(init_pair(HEADER_COLOR,COLOR_BLUE,-1) == OK);
		assert(init_pair(FOOTER_COLOR,COLOR_YELLOW,-1) == OK);
		assert(init_pair(DBORDER_COLOR,COLOR_WHITE,-1) == OK);
		assert(init_pair(DHEADING_COLOR,COLOR_WHITE,-1) == OK);
		assert(init_pair(UBORDER_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(UHEADING_COLOR,COLOR_BLUE,-1) == OK);
		assert(init_pair(PBORDER_COLOR,COLOR_YELLOW,-1) == OK);
		assert(init_pair(PHEADING_COLOR,COLOR_RED,-1) == OK);
		assert(init_pair(BULKTEXT_COLOR,COLOR_WHITE,-1) == OK);
		assert(init_pair(BULKTEXT_ALTROW_COLOR,COLOR_WHITE,-1) == OK);
		assert(init_pair(IFACE_COLOR,COLOR_WHITE,-1) == OK);
		assert(init_pair(LCAST_COLOR,COLOR_CYAN,-1) == OK); // will use A_BOLD via OUR_BOLD
		assert(init_pair(UCAST_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(MCAST_COLOR,COLOR_BLUE,-1) == OK);
		assert(init_pair(BCAST_COLOR,COLOR_MAGENTA,-1) == OK);
		assert(init_pair(LSELECTED_COLOR,-1,COLOR_CYAN) == OK);
		assert(init_pair(USELECTED_COLOR,-1,COLOR_CYAN) == OK);
		assert(init_pair(MSELECTED_COLOR,-1,COLOR_BLUE) == OK);
		assert(init_pair(BSELECTED_COLOR,-1,COLOR_MAGENTA) == OK);
		assert(init_pair(LCAST_L3_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(UCAST_L3_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(MCAST_L3_COLOR,COLOR_BLUE,-1) == OK);
		assert(init_pair(BCAST_L3_COLOR,COLOR_MAGENTA,-1) == OK);
		assert(init_pair(LCAST_RES_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(UCAST_RES_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(MCAST_RES_COLOR,COLOR_BLUE,-1) == OK);
		assert(init_pair(BCAST_RES_COLOR,COLOR_MAGENTA,-1) == OK);
		assert(init_pair(LCAST_ALTROW_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(UCAST_ALTROW_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(MCAST_ALTROW_COLOR,COLOR_BLUE,-1) == OK);
		assert(init_pair(BCAST_ALTROW_COLOR,COLOR_MAGENTA,-1) == OK);
		assert(init_pair(LCAST_ALTROW_L3_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(UCAST_ALTROW_L3_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(MCAST_ALTROW_L3_COLOR,COLOR_BLUE,-1) == OK);
		assert(init_pair(BCAST_ALTROW_L3_COLOR,COLOR_MAGENTA,-1) == OK);
		assert(init_pair(LCAST_ALTROW_RES_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(UCAST_ALTROW_RES_COLOR,COLOR_CYAN,-1) == OK);
		assert(init_pair(MCAST_ALTROW_RES_COLOR,COLOR_BLUE,-1) == OK);
		assert(init_pair(BCAST_ALTROW_RES_COLOR,COLOR_MAGENTA,-1) == OK);
		assert(init_pair(SUBDISPLAY_COLOR,COLOR_WHITE,-1) == OK);
	}else{
		int z;

		assert(init_pair(BORDER_COLOR,COLOR_ALUMINIUM,-1) == OK);
		assert(init_pair(HEADER_COLOR,COLOR_MODBLUE,-1) == OK);
		assert(init_pair(FOOTER_COLOR,COLOR_MODYELLOW,-1) == OK);
		assert(init_pair(DBORDER_COLOR,COLOR_ALUMINIUM,-1) == OK);
		assert(init_pair(DHEADING_COLOR,COLOR_MODWHITE,-1) == OK);
		assert(init_pair(UBORDER_COLOR,COLOR_MODCYAN,-1) == OK);
		assert(init_pair(UHEADING_COLOR,COLOR_ORANGE,-1) == OK);
		assert(init_pair(PBORDER_COLOR,COLOR_MODBLUE,-1) == OK);
		assert(init_pair(PHEADING_COLOR,COLOR_MODRED,-1) == OK);
		assert(init_pair(BULKTEXT_COLOR,COLOR_MODWHITE,-1) == OK);
		assert(init_pair(BULKTEXT_ALTROW_COLOR,COLOR_MODWHITE,COLOR_PALEALUMINIUM) == OK);
		assert(init_pair(IFACE_COLOR,COLOR_MODWHITE,-1) == OK);
		assert(init_pair(LCAST_COLOR,COLOR_CHAMELEON,-1) == OK);
		assert(init_pair(UCAST_COLOR,COLOR_MODBLUE,-1) == OK);
		assert(init_pair(MCAST_COLOR,COLOR_SKYBLUE,-1) == OK);
		assert(init_pair(BCAST_COLOR,COLOR_MODVIOLET,-1) == OK);
		assert(init_pair(LSELECTED_COLOR,COLOR_MODWHITE,COLOR_CHAMELEON_50) == OK);
		assert(init_pair(USELECTED_COLOR,COLOR_MODWHITE,COLOR_BLUE_50) == OK);
		assert(init_pair(MSELECTED_COLOR,COLOR_MODWHITE,COLOR_SKYBLUE_50) == OK);
		assert(init_pair(BSELECTED_COLOR,COLOR_MODWHITE,COLOR_VIOLET_50) == OK);
		assert(init_pair(LCAST_L3_COLOR,COLOR_CHAMELEON_75,-1) == OK);
		assert(init_pair(UCAST_L3_COLOR,COLOR_BLUE_75,-1) == OK);
		assert(init_pair(MCAST_L3_COLOR,COLOR_SKYBLUE_75,-1) == OK);
		assert(init_pair(BCAST_L3_COLOR,COLOR_VIOLET_75,-1) == OK);
		assert(init_pair(LCAST_RES_COLOR,COLOR_CHAMELEON_50,-1) == OK);
		assert(init_pair(UCAST_RES_COLOR,COLOR_BLUE_50,-1) == OK);
		assert(init_pair(MCAST_RES_COLOR,COLOR_SKYBLUE_50,-1) == OK);
		assert(init_pair(BCAST_RES_COLOR,COLOR_VIOLET_50,-1) == OK);

		// Disable altrow stuff for now. It's hard to read and ugly.
		assert(init_pair(LCAST_ALTROW_COLOR,COLOR_CHAMELEON,-1) == OK);
		assert(init_pair(UCAST_ALTROW_COLOR,COLOR_MODBLUE,-1) == OK);
		assert(init_pair(MCAST_ALTROW_COLOR,COLOR_SKYBLUE,-1) == OK);
		assert(init_pair(BCAST_ALTROW_COLOR,COLOR_MODVIOLET,-1) == OK);
		assert(init_pair(LCAST_ALTROW_L3_COLOR,COLOR_CHAMELEON_75,-1) == OK);
		assert(init_pair(UCAST_ALTROW_L3_COLOR,COLOR_BLUE_75,-1) == OK);
		assert(init_pair(MCAST_ALTROW_L3_COLOR,COLOR_SKYBLUE_75,-1) == OK);
		assert(init_pair(BCAST_ALTROW_L3_COLOR,COLOR_VIOLET_75,-1) == OK);
		assert(init_pair(LCAST_ALTROW_RES_COLOR,COLOR_CHAMELEON_50,-1) == OK);
		assert(init_pair(UCAST_ALTROW_RES_COLOR,COLOR_BLUE_50,-1) == OK);
		assert(init_pair(MCAST_ALTROW_RES_COLOR,COLOR_SKYBLUE_50,-1) == OK);
		assert(init_pair(BCAST_ALTROW_RES_COLOR,COLOR_VIOLET_50,-1) == OK);
		assert(init_pair(SUBDISPLAY_COLOR,COLOR_MODWHITE,-1) == OK);

		for(z = FIRST_FREE_COLOR ; z < COLORS && z < COLOR_PAIRS ; ++z){
			assert(init_pair(z,z,-1) == OK);
		}
	}
	if(draw_main_window(w)){
		errstr = "Couldn't use ncurses\n";
		goto err;
	}
	if((nim = malloc(sizeof(*nim))) == NULL){
		goto err;
	}
	nim->w = w;
	nim->maintid = pthread_self();
	// Panels aren't yet being used, so we need call refresh() to
	// paint the main window.
	refresh();
	if(pthread_create(&inputtid,NULL,ncurses_input_thread,nim)){
		errstr = "Couldn't create UI thread\n";
		free(nim);
		goto err;
	}
	// FIXME install SIGWINCH() handler...?
	return w;

err:
	mandatory_cleanup(&w);
	fprintf(stderr,"%s",errstr);
	return NULL;
}
Exemple #21
0
int main(void)
{
    uint32_t reg[16]={0};       //se creo un arreglo de 13 variables de 32 bits para los 13 registros
	char bandera[4]={0};        //La bandera se definio como un arreglo de 4 variables siendo la primera la bandera de negativo
    int ch=0,j=0,z;
    uint16_t Mnem=0x0;
    uint8_t MemRAM[256],m=0;
    reg[13]=0x100;
    for(j=0;j<=0xff;j++)
    {
        MemRAM[j]=0xff;
    }
    int num_instructions;
    ins_t read;
    char** instructions;
    instruction_t instruction;
    num_instructions = readFile("code.txt", &read);
    if(num_instructions==-1)    {   return 0;   }
    if(read.array==NULL)        {   return 0;	}
    instructions = read.array;

    initscr();	                /* Inicia modo curses */
    curs_set(0);	            /* Cursor Invisible */
    raw();			            /* Activa modo raw */
	keypad(stdscr, TRUE);   	/* Obtener F1, F2, etc */
    noecho();	            	/* No imprimir los caracteres leidos */
    start_color();	            /* Permite manejar colores */
    init_pair(1, COLOR_WHITE, COLOR_CYAN); 	/* Pair 1 -> Texto blanco fondo cyan */
    bkgd(COLOR_PAIR(1));           //se rellena el todo el fondo de color cyan
	mostrar_registro(reg);
    move(4, 40); printw("Banderas");
    move(6, 40); printw("N=%d\n",bandera[0]);
    move(7, 40); printw("Z=%d\n",bandera[1]);
    move(8, 40); printw("C=%d\n",bandera[2]);
    move(9, 40); printw("V=%d\n",bandera[3]);
    move(11, 40); printw("PC=%X\n",reg[15]*2);
    move(12, 40); printw("LR=%X\n",reg[14]*2);
    move(13, 40); printw("SP=%X\n",reg[13]);
    move(4, 55); printw("Emulador ARM Cortex-M0");
    mostrar_ram(MemRAM);
    initIO();showPorts();
    border( ACS_VLINE, ACS_VLINE,
            ACS_HLINE, ACS_HLINE,
            ACS_ULCORNER, ACS_URCORNER,
            ACS_LLCORNER, ACS_LRCORNER	);
    refresh();
	while(ch != 'q')
    {
        ch = getch();            /* Espera entrada del usuario */
        if(ch=='a'||ch=='b')
        {
           teclas(ch,&m);
        }
        clear();
        INT(irq, reg, MemRAM, bandera, &m);
        showPorts();
        move(2, 15); printw("%s",instructions[reg[15]]);
        instruction = getInstruction(instructions[reg[15]]);
        decodeInstruction(instruction, reg, bandera, MemRAM, &Mnem);
        mostrar_registro(reg);
        move(2, 40); printw("Instruccion --> 0x%.4X",Mnem);
        move(4, 40); printw("Banderas");
        move(6, 40); printw("N=%d\n",bandera[0]);
        move(7, 40); printw("Z=%d\n",bandera[1]);
        move(8, 40); printw("C=%d\n",bandera[2]);
        move(9, 40); printw("V=%d\n",bandera[3]);
        move(11, 40); printw("PC=%X\n",reg[15]*2);
        move(12, 40); printw("LR=%X\n",reg[14]);
        move(13, 40); printw("SP=%X\n",reg[13]);
        move(4, 55); printw("Emulador ARM Cortex-M0");
        move(5, 55); printw("Presione q para Salir");
        move(6, 55); printw("Presione a para modificar el estado del puerto A");
        move(7, 55); printw("Presione b para modificar el estado del puerto B");
        mostrar_ram(MemRAM);
        border( ACS_VLINE, ACS_VLINE,
                ACS_HLINE, ACS_HLINE,
                ACS_ULCORNER, ACS_URCORNER,
                ACS_LLCORNER, ACS_LRCORNER	);
        refresh();	            /* Imprime en la pantalla Sin esto el printw no es mostrado */
    }
    attroff(COLOR_PAIR(1));     	/* DEshabilita los colores Pair 1 */
    endwin();
	free(read.array);

    /* Finaliza el modo curses */

    return 0;
}
Exemple #22
0
int main(int argc, char* argv[]){
  /* Initialize pseudo random number generator */
  srand(time(NULL));

  /* Read command line arguments */
  struct basic_options op;
  struct multi_options mop;
  if (get_options(argc, argv, &op, &mop) == 1) return 1;
 
  /* Setup signal handlers */
  struct sigaction newhandler;            /* new settings         */
  sigset_t         blocked;               /* set of blocked sigs  */
  newhandler.sa_flags = SA_RESTART;       /* options     */
  sigemptyset(&blocked);                  /* clear all bits       */
  newhandler.sa_mask = blocked;           /* store blockmask      */
  newhandler.sa_handler = on_timer;      /* handler function     */
  if ( sigaction(SIGALRM, &newhandler, NULL) == -1 )
    perror("sigaction");


  /* prepare the terminal for the animation */
  setlocale(LC_ALL, "");
  initscr();     /* initialize the library and screen */
  cbreak();      /* put terminal into non-blocking input mode */
  noecho();      /* turn off echo */
  start_color();
  clear();       /* clear the screen */
  curs_set(0);   /* hide the cursor */

  use_default_colors();
  init_pair(0, COLOR_WHITE, COLOR_BLACK);
  init_pair(1, COLOR_WHITE, COLOR_BLACK);
  init_pair(2, COLOR_BLACK, COLOR_BLACK);
  init_pair(3, COLOR_RED, COLOR_BLACK);
  init_pair(4, COLOR_GREEN, COLOR_BLACK);
  init_pair(5, COLOR_BLUE, COLOR_BLACK);
  init_pair(6, COLOR_YELLOW, COLOR_BLACK);
  init_pair(7, COLOR_MAGENTA, COLOR_BLACK);
  init_pair(8, COLOR_CYAN, COLOR_BLACK);
 
  color_set(0, NULL);
  assume_default_colors(COLOR_WHITE, COLOR_BLACK);
  clear();
    
  struct state st;
  struct ui ui;

  /* Initialize the parameters of the program */
  attrset(A_BOLD | COLOR_PAIR(2));
  mvaddstr(0,0,"Map is generated. Please wait.");
  refresh();

  state_init(&st, &op, &mop);
 
  ui_init(&st, &ui);

  clear();
 
  /* non-blocking input */
  int fd_flags = fcntl(0, F_GETFL);
  fcntl(0, F_SETFL, (fd_flags|O_NONBLOCK));

  /* Start the real time interval timer with delay interval size */
  struct itimerval it;
  it.it_value.tv_sec = 0;
  it.it_value.tv_usec = 10000;
  it.it_interval.tv_sec = 0;
  it.it_interval.tv_usec = 10000;
  setitimer(ITIMER_REAL, &it, NULL);
  
  refresh();        
  input_ready = 0;
  time_to_redraw = 1;

  if (!mop.multiplayer_flag) {
    /* Run the game */
    run(&st, &ui);
  }
  else {
    if (mop.server_flag) run_server(&st, mop.clients_num, mop.val_server_port);
    else run_client(&st, &ui, mop.val_server_addr, mop.val_server_port, mop.val_client_port);
  }

  /* Restore the teminal state */
  echo();
  curs_set(1);
  clear();
  endwin();

  if (!mop.multiplayer_flag || mop.server_flag)
    printf ("Random seed was %i\n", st.map_seed);

  free(mop.val_server_addr);
  free(mop.val_server_port);
  free(mop.val_client_port);
  return 0;
}
Exemple #23
0
int main(int argc, char *argv[])
{
    RedditUserLogged *user = NULL;
    char *subreddit = NULL;
    char *password = NULL, *username = NULL;
    optParser parser;

    DEBUG_START(DEBUG_FILE, DEBUG_FILENAME);

    memset(&parser, 0, sizeof(optParser));

    parser.argc = argc;
    parser.argv = argv;

    optAddOptions (&parser, mainOptions, MOPT_ARG_COUNT);

    handleArguments(&parser);

    if (mainOptions[MOPT_HELP].isSet) {
        displayHelp(&parser);
        return 0;
    }

    optClearParser(&parser);

    setlocale(LC_CTYPE, "");


    initscr();
    raw();//We want character for character input
    keypad(stdscr,1);//Enable extra keys like arrowkeys
    noecho();
    start_color();
    use_default_colors();
    init_pair(1, -1, -1);
    init_pair(2, COLOR_BLACK, COLOR_WHITE);

    DEBUG_PRINT(L"Starting...\n");

    /* Start libreddit */
    redditGlobalInit();

    globalState = redditStateNew();

    globalState->userAgent = redditCopyString("cReddit/0.0.1");

    redditStateSet(globalState);

    if (mainOptions[MOPT_USERNAME].isSet) {
        username = mainOptions[MOPT_USERNAME].svalue;
        if (!mainOptions[MOPT_PASSWORD].isSet)
            password = getPassword();
        else
            password = mainOptions[MOPT_PASSWORD].svalue;

        user = redditUserLoggedNew();
        redditUserLoggedLogin(user, username, password);

        /* Don't want to leave that important Reddit password in memory */
        memset(password, 0, strlen(password));
        if (!mainOptions[MOPT_PASSWORD].isSet)
            free(password);
    }
    if (mainOptions[MOPT_SUBREDDIT].isSet) {
        subreddit = mainOptions[MOPT_SUBREDDIT].svalue;
        if (!startsWith("/r/", subreddit) && strcmp("/", subreddit) != 0)
            prepend("/r/", subreddit);

    } else {
        subreddit = "/";
    }
    showSubreddit(subreddit);

    redditUserLoggedFree(user);
    redditStateFree(globalState);
    redditGlobalCleanup();
    endwin();

    DEBUG_END(DEBUG_FILE);
    return 0;
}
Exemple #24
0
int
main(int argc, char *argv[])
{
int x, y;
int n;
struct worm *w;
struct options *op;
int h;
short *ip;
int last, bottom;

    for (x=1;x<argc;x++) {
		register char *p;
		p=argv[x];
		if (*p=='-') p++;
		switch (*p) {
		case 'f':
		    field="WORM";
		    break;
		case 'l':
		    if (++x==argc) goto usage;
		    if ((length=atoi(argv[x]))<2||length>1024) {
				fprintf(stderr,"%s: Invalid length\n",*argv);
				exit(1);
		    }
		    break;
		case 'n':
		    if (++x==argc) goto usage;
		    if ((number=atoi(argv[x]))<1||number>40) {
				fprintf(stderr,"%s: Invalid number of worms\n",*argv);
				exit(1);
		    }
		    break;
		case 't':
		    trail='.';
		    break;
#ifdef TRACE
		case 'S':
		    singlestep = TRUE;
		    break;
		case 'T':
		    trace_start = atoi(argv[++x]);
		    trace_end   = atoi(argv[++x]);
		    break;
		case 'N':
		    no_optimize = TRUE;		/* declared by ncurses */
		    break;
#endif /* TRACE */
		default:
		usage:
		    fprintf(stderr, "usage: %s [-field] [-length #] [-number #] [-trail]\n",*argv);
		    exit(1);
		    break;
		}
    }

    signal(SIGINT, onsig);
    initscr();
#ifdef TRACE
    noecho();
    cbreak();
#endif /* TRACE */
    nonl();
    bottom = LINES-1;
    last = COLS-1;

#ifdef A_COLOR
    if (has_colors())
    {
	start_color();
 
	init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
	init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
	init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
	init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
	init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
	init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
	init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);

	flavor[0] |= COLOR_PAIR(COLOR_GREEN) | A_BOLD;
	flavor[1] |= COLOR_PAIR(COLOR_RED) | A_BOLD;
	flavor[2] |= COLOR_PAIR(COLOR_CYAN) | A_BOLD;
	flavor[3] |= COLOR_PAIR(COLOR_WHITE) | A_BOLD;
	flavor[4] |= COLOR_PAIR(COLOR_MAGENTA) | A_BOLD;
	flavor[5] |= COLOR_PAIR(COLOR_BLUE) | A_BOLD;
	flavor[6] |= COLOR_PAIR(COLOR_YELLOW) | A_BOLD;
    }
#endif /* A_COLOR */

    ip=(short *)malloc(LINES*COLS*sizeof (short));

    for (n=0;n<LINES;) {
		ref[n++]=ip; ip+=COLS;
    }
    for (ip=ref[0],n=LINES*COLS;--n>=0;) *ip++=0;

#ifdef BADCORNER
    /* if addressing the lower right corner doesn't work in your curses */
    ref[bottom][last]=1;
#endif /* BADCORNER */

    for (n=number, w= &worm[0];--n>=0;w++) {
		w->orientation=w->head=0;
		if (!(ip=(short *)malloc((length+1)*sizeof (short)))) {
		    fprintf(stderr,"%s: out of memory\n",*argv);
		    exit(1);
		}
		w->xpos=ip;
		for (x=length;--x>=0;) *ip++ = -1;
		if (!(ip=(short *)malloc((length+1)*sizeof (short)))) {
		    fprintf(stderr,"%s: out of memory\n",*argv);
		    exit(1);
		}
		w->ypos=ip;
		for (y=length;--y>=0;) *ip++ = -1;
    }
    if (field) {
		register char *p;
		p=field;
		for (y=bottom;--y>=0;) {
		    for (x=COLS;--x>=0;) {
				addch((chtype)(*p++));
				if (!*p) p=field;
		    }
            addch('\n');
        }
    }
   refresh();
   napms(100);

    for (;;) {
#ifdef TRACE
		if (trace_start || trace_end) {
		    if (generation == trace_start) {
			trace(TRACE_CALLS);
			getch();
		    } else if (generation == trace_end) {
			trace(0);
			getch();
		    }

		    if (singlestep && generation > trace_start && generation < trace_end)
			getch();

		    generation++;
		}
#endif /* TRACE */

		for (n=0,w= &worm[0];n<number;n++,w++) {
		    if ((x=w->xpos[h=w->head])<0) {
				cursor(x=w->xpos[h]=0,y=w->ypos[h]=bottom);
				addch(flavor[n % MAXWORMS]);
				ref[y][x]++;
		    }
		    else y=w->ypos[h];
		    if (++h==length) h=0;
		    if (w->xpos[w->head=h]>=0) {
				register int x1, y1;
				x1=w->xpos[h]; y1=w->ypos[h];
				if (--ref[y1][x1]==0) {
				    cursor(x1,y1); addch(trail);
				}
		    }
            op= &(x==0 ? (y==0 ? upleft : (y==bottom ? lowleft : left)) :
                (x==last ? (y==0 ? upright : (y==bottom ? lowright : right)) :
			(y==0 ? upper : (y==bottom ? lower : normal))))[w->orientation];
		    switch (op->nopts) {
		    case 0:
				refresh();
				endwin();
				exit(0);
		    case 1:
				w->orientation=op->opts[0];
				break;
		    default:
				w->orientation=op->opts[(int)(ranf()*(float)op->nopts)];
		    }
		    cursor(x+=xinc[w->orientation], y+=yinc[w->orientation]);

		    if (y < 0 ) y = 0;
		    addch(flavor[n % MAXWORMS]);
		    ref[w->ypos[h]=y][w->xpos[h]=x]++;
		}
       napms(100);
		refresh();
    }
}
Exemple #25
0
/*
 * Prepare "curses" for use by the file "term.c"
 *
 * Installs the "hook" functions defined above, and then activates
 * the main screen "term", which clears the screen and such things.
 *
 * Someone should really check the semantics of "initscr()"
 */
errr init_gcu(int argc, char *argv[])
{
   int i;
   char path[1024];

#ifdef USE_SOUND

   /* Build the "sound" path */
   path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");

   /* Allocate the path */
   ANGBAND_DIR_XTRA_SOUND = z_string_make(path);

#endif

   /* Extract the normal keymap */
   keymap_norm_prepare();

   if (!getenv("ESCDELAY"))
       putenv("ESCDELAY=20");

#if defined(USG)
   /* Initialize for USG Unix */
   if (initscr() == NULL) return (-1);
#else
   /* Initialize for others systems */
   if (initscr() == (WINDOW*)ERR) return (-1);
#endif

   /* Activate hooks */
   quit_aux = hook_quit;
   core_aux = hook_quit;

   /* Hack -- Require large screen, or Quit with message */
   i = ((LINES < 27) || (COLS < 80));
   if (i) quit("Angband needs an 80x27 'curses' screen");


#ifdef A_COLOR

   /*** Init the Color-pairs and set up a translation table ***/

   /* Do we have color, and enough color, available? */
   can_use_color = ((start_color() != ERR) && has_colors() &&
		    (COLORS >= 8) && (COLOR_PAIRS >= 8));

#ifdef REDEFINE_COLORS
	/* Can we change colors? */
	can_fix_color = (can_use_color && can_change_color() &&
			 (COLORS >= 16) && (COLOR_PAIRS > 8));
#endif

#ifdef HAVE_USE_DEFAULT_COLORS
    /* Should we use curses' "default color" */
    if (use_default_colors() == OK) bg_color = -1;
#endif

   /* Attempt to use colors */
   if (can_use_color)
   {
		/* Color-pair 0 is *always* WHITE on BLACK */

		/* Prepare the color pairs */
        init_pair(1, COLOR_RED,     bg_color);
        init_pair(2, COLOR_GREEN,   bg_color);
        init_pair(3, COLOR_YELLOW,  bg_color);
        init_pair(4, COLOR_BLUE,    bg_color);
        init_pair(5, COLOR_MAGENTA, bg_color);
        init_pair(6, COLOR_CYAN,    bg_color);
        init_pair(7, COLOR_BLACK,   bg_color);

		/* Prepare the "Angband Colors" -- Bright white is too bright */
		/* Changed in Drangband. Cyan as grey sucks -- -TM- */
		colortable[0] = (COLOR_PAIR(7) | A_NORMAL);	/* Black */
		colortable[1] = (COLOR_PAIR(0) | A_BRIGHT);	/* White */
		colortable[2] = (COLOR_PAIR(0) | A_NORMAL);	/* Grey XXX */
		colortable[3] = (COLOR_PAIR(1) | A_BRIGHT);	/* Orange XXX */
		colortable[4] = (COLOR_PAIR(1) | A_NORMAL);	/* Red */
		colortable[5] = (COLOR_PAIR(2) | A_NORMAL);	/* Green */
		colortable[6] = (COLOR_PAIR(4) | A_NORMAL);	/* Blue */
		colortable[7] = (COLOR_PAIR(3) | A_NORMAL);	/* Umber */
		colortable[8] = (COLOR_PAIR(7) | A_BRIGHT);	/* Dark-grey XXX */
		colortable[9] = (COLOR_PAIR(0) | A_NORMAL);	/* Light-grey XXX */
		colortable[10] = (COLOR_PAIR(5) | A_NORMAL);	/* Purple */
		colortable[11] = (COLOR_PAIR(3) | A_BRIGHT);	/* Yellow */
		colortable[12] = (COLOR_PAIR(5) | A_BRIGHT);	/* Light Red XXX */
		colortable[13] = (COLOR_PAIR(2) | A_BRIGHT);	/* Light Green */
		colortable[14] = (COLOR_PAIR(4) | A_BRIGHT);	/* Light Blue */
		colortable[15] = (COLOR_PAIR(3) | A_NORMAL);	/* Light Umber XXX */

   }

#endif

#ifdef USE_SOUND
   /* Handle "arg_sound" */
   if (use_sound != arg_sound)
   {
      /* Initialize (if needed) */
      if (arg_sound && !init_sound())
      {
	 /* Warning */
	 plog("Cannot initialize sound!");

	 /* Cannot enable */
	 arg_sound = FALSE;
      }

      /* Change setting */
      use_sound = arg_sound;
   }
#endif

#ifdef USE_GRAPHICS

   /* Try graphics */
   if (arg_graphics)
   {
      /* if USE_NCURSES_ACS is defined, we can do something with graphics in curses! */
#ifdef USE_NCURSES_ACS
      use_graphics = TRUE;
#endif
   }

#endif /* USE_GRAPHICS */



   /*** Low level preparation ***/

#ifdef USE_GETCH

   /* Paranoia -- Assume no waiting */
   nodelay(stdscr, FALSE);

#endif

   /* Prepare */
   cbreak();
   noecho();
   nonl();
   raw();

   /* Extract the game keymap */
   keymap_game_prepare();

   /* Parse Args and Prepare the Terminals. Rectangles are specified
      as Width x Height, right? The game will allow you to have two
      strips of extra terminals, one on the right and one on the bottom.
      The map terminal will than fit in as big as possible in the remaining
      space.

      Examples:
        poschengband -mgcu -- -right 30x27,* -bottom *x7 will layout as

        Term-0: Map (COLS-30)x(LINES-7) | Term-1: 30x27
        --------------------------------|----------------------
        <----Term-3: (COLS-30)x7------->| Term-2: 30x(LINES-27)

        poschengband -mgcu -- -bottom *x7 -right 30x27,* will layout as

        Term-0: Map (COLS-30)x(LINES-7) | Term-2: 30x27
                                        |------------------------------
                                        | Term-3: 30x(LINES-27)
        ---------------------------------------------------------------
        <----------Term-1: (COLS)x7----------------------------------->

        Notice the effect on the bottom terminal by specifying its argument
        second or first. Notice the sequence numbers for the various terminals
        as you will have to blindly configure them in the window setup screen.
    */
    {
        int  spacer_cx = 1;
        int  spacer_cy = 1;
        int  min_cy = 3;
        int  min_cx = 10;
        int  right_cx = 0;
        int  right_cys[10] = {0};
        int  right_ct = 0;
        int  bottom_cy = 0;
        int  bottom_cxs[10] = {0};
        int  bottom_ct = 0;
        bool right_first = TRUE;
        int  map_cx, map_cy;
        int  next_win = 0;

        for (i = 1; i < argc; i++)
        {
            if (strcmp(argv[i], "-b") == 0)
            {
                term_data_init(&data[0], LINES, COLS, 0, 0);
                angband_term[0] = Term;
                break;
            }
            else if (strcmp(argv[i], "-right") == 0)
            {
                cptr arg, tmp;

                if (!bottom_cy)
                    right_first = TRUE;

                i++;
                if (i >= argc)
                    quit("Missing size specifier for -right");

                arg = argv[i];
                tmp = strchr(arg, 'x');
                if (!tmp)
                    quit("Expected something like -right 60x27,* for two right hand terminals of 60 columns, the first 27 lines and the second whatever is left.");
                right_cx = atoi(arg);
                tmp++;
                right_ct = _parse_size_list(tmp, right_cys, 10);
            }
            else if (strcmp(argv[i], "-bottom") == 0)
            {
                cptr arg, tmp;

                if (!right_cx)
                    right_first = FALSE;

                i++;
                if (i >= argc)
                    quit("Missing size specifier for -bottom");

                arg = argv[i];
                tmp = strchr(arg, 'x');
                if (!tmp)
                    quit("Expected something like -bottom *x7 for a single bottom terminal of 7 lines using as many columns as are available.");
                tmp++;
                bottom_cy = atoi(tmp);
                bottom_ct = _parse_size_list(arg, bottom_cxs, 10);
            }
        }

        if (right_cx)
            map_cx = COLS - (right_cx + spacer_cx);
        else
            map_cx = COLS;

        if (bottom_cy)
            map_cy = LINES - (bottom_cy + spacer_cy);
        else
            map_cy = LINES;

        if (map_cx < 80 || map_cy < 27)
            quit(format("Failed: PosChengband needs an 80x27 map screen, not %dx%d", map_cx, map_cy));

        /* Map Window: Upper Left */
        term_data_init(&data[next_win], map_cy, map_cx, 0, 0);
        angband_term[next_win] = Term;
        next_win++;

        /* Right Hand Strip */
        if (right_first)
        {
            int cy_remaining = LINES;
            int x = map_cx + spacer_cx;
            int y = 0;

            for (i = 0; i < right_ct; i++)
            {
                int cy = right_cys[i];

                if (!cy) break;

                if (cy > cy_remaining)
                    cy = cy_remaining;

                if (cy > min_cy)
                {
                    term_data_init(&data[next_win], cy, right_cx, y, x);
                    angband_term[next_win] = Term;
                    next_win++;

                    y += cy + spacer_cy;
                    cy_remaining -= cy + spacer_cy;
                }
            }
        }

        /* Bottom Strip */
        {
            int cx_remaining = COLS;
            int x = 0;
            int y = map_cy + spacer_cy;

            if (right_first)
                cx_remaining -= (right_cx + spacer_cx);

            for (i = 0; i < bottom_ct; i++)
            {
                int cx = bottom_cxs[i];

                if (!cx) break;

                if (cx > cx_remaining)
                    cx = cx_remaining;

                if (cx > min_cx)
                {
                    term_data_init(&data[next_win], bottom_cy, cx, y, x);
                    angband_term[next_win] = Term;
                    next_win++;

                    x += cx + spacer_cx;
                    cx_remaining -= cx + spacer_cx;
                }
            }
        }

        /* Right Hand Strip: TODO: Refactor this code duplication!
           But note that if the user specifies -right before bottom,
           then the terminal sequence numbers should reflect this fact! */
        if (!right_first)
        {
            int cy_remaining = LINES - bottom_cy;
            int x = map_cx + spacer_cx;
            int y = 0;

            for (i = 0; i < right_ct; i++)
            {
                int cy = right_cys[i];

                if (!cy) break;

                if (cy > cy_remaining)
                    cy = cy_remaining;

                if (cy > min_cy)
                {
                    term_data_init(&data[next_win], cy, right_cx, y, x);
                    angband_term[next_win] = Term;
                    next_win++;

                    y += cy + spacer_cy;
                    cy_remaining -= cy + spacer_cy;
                }
            }
        }
    }

   /* Activate the "Angband" window screen */
   Term_activate(&data[0].t);

   /* Store */
   term_screen = &data[0].t;

#ifdef USE_GETCH
   /* Title screen (news.txt) won't draw otherwise for some reason ... */
   wrefresh(stdscr);
#endif

   /* Success */
   return (0);
}
Exemple #26
0
int main(int argc, char **argv){
	extern char *optarg;
	int c;
	int colouron = 0;

	time_t last_update = 0;

	WINDOW *window;

	extern int errno;

	int delay=2;

	sg_init();
	if(sg_drop_privileges() != 0){
		fprintf(stderr, "Failed to drop setuid/setgid privileges\n");
		return 1;
	}

#ifdef COLOR_SUPPORT
	while ((c = getopt(argc, argv, "d:cvh")) != -1){
#else
	while ((c = getopt(argc, argv, "d:vh")) != -1){
#endif
		switch (c){
			case 'd':
				delay = atoi(optarg);
				if (delay < 1){
					fprintf(stderr, "Time must be 1 second or greater\n");
					exit(1);
				}
				break;
#ifdef COLOR_SUPPORT
			case 'c':
				colouron = 1;
				break;
#endif
			case 'v':
				version_num(argv[0]);
				break;
			case 'h':
			default:
				usage(argv[0]);
				return 1;
				break;
		}
	}

	signal(SIGWINCH, sig_winch_handler);
	initscr();
#ifdef COLOR_SUPPORT
	/* turn on colour */
	if (colouron) {
		if (has_colors()) {
			start_color();
			use_default_colors();
			init_pair(1,COLOR_RED,-1);
			init_pair(2,COLOR_GREEN,-1);
			init_pair(3,COLOR_YELLOW,-1);
			init_pair(4,COLOR_BLUE,-1);
			init_pair(5,COLOR_MAGENTA,-1);
			init_pair(6,COLOR_CYAN,-1);
		} else {
			fprintf(stderr, "Colour support disabled: your terminal does not support colour.");
			colouron = 0;
		}
	}
#endif
	nonl();
	curs_set(0);
	cbreak();
	noecho();
	timeout(delay * 1000);
	window=newwin(0, 0, 0, 0);
	clear();

	if(!get_stats()){
		fprintf(stderr, "Failed to get all the stats. Please check correct permissions\n");
		endwin();
		return 1;
	}

	display_headings();

	for(;;){
		time_t now;
		int ch = getch();

		if (ch == 'q'){
			break;
		}

		/* To keep the numbers slightly accurate we do not want them
		 * updating more frequently than once a second.
		 */
		now = time(NULL);
		if ((now - last_update) >= 1) {
			get_stats();
		}
		last_update = now;

		if(sig_winch_flag) {
			clear();
			display_headings();
			sig_winch_flag = 0;
		}

		display_data(colouron);
	}

	endwin();
	return 0;
}
Exemple #27
0
int main()
{

 initscr();
 curs_set(0);
 raw();
 start_color();
 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_WHITE,COLOR_BLACK);
 init_pair(5,COLOR_CYAN,COLOR_BLACK);
 init_pair(6,COLOR_MAGENTA,COLOR_BLACK);


  int k = 1,z;


  while(k)
   {
     attron(A_BOLD|COLOR_PAIR(1));

    for(i=3; i>=0; i--)
 	 {
 	 printw("\n (Tips: Use 0 for false & 1 for true) ");
   	 printw("\n PLEASE WAIT. LOADING PROJECT \n\n ");
 	 printw("\n\n Loaded %d%% \n",((3-i)*100/3));
 	 refresh();
 		system("sleep 1");
 		clear();
 	  }

    refresh();

    attron(A_UNDERLINE|A_REVERSE|COLOR_PAIR(2));
    printw("\n MICROPROJECT - DATA STRUCTURES (NOV 2014) ");
    printw("\n DEVELOPER - Aman Garg ");
    printw("\n ROLL - 13103050 \n");
    attroff(A_UNDERLINE|A_REVERSE);

    printw("\n\n Following data structures are available \n");

    printw("\n 1: Array Sorts ");
    printw("\n 2: Linked Lists ");
    printw("\n 3: Stacks ");
    printw("\n 4: Queues ");
    printw("\n 5: Trees ");
    printw("\n 6: Binary Search Trees ");
    printw("\n 7: AVL Trees ");
    printw("\n 0: Exit ");
    		attroff(COLOR_PAIR(2));
    		refresh();
		scanw("%d",&k);
    switch(k)
     {
       case 1:  					     //Arrays
       		system("clear ");
       		attron(COLOR_PAIR(3));
		printw("\n Enter number of elements : ");
		refresh();
  		scanw(" %d",&n);
  		printw("\n Enter %d (line separated) elements : \n",n);
  		refresh();

  		for(i=0;i<n ;i++ )
  		scanw("%d",&a[i]);

  		printw("\n Size of array is %d ",n);
		printw("\n The entered list : ");
 		for(i=0; i<n; i++)
 		{printw(" %d ",a[i]);
 		refresh();
 		}

        system("clear ");
 		endwin();
 		options_s(a);
		system("clear ");
		refresh();
   		attron(COLOR_PAIR(3));
   					break;

 	case 2:  {
 		  attron(COLOR_PAIR(4));
 		  system("clear ");					//Linked lists
 	 	  printw("\n 1: Singly Linked ");
    		  printw("\n 2: Doubly Linked ");
    		  printw("\n 0: Back 	\t");
    		  		refresh();
 	 	 		scanw("%d",&k);
 	 	 switch(k)
    		  {
    		  case 0:	system("clear "); main(); break;
 	 	  case 2:	{
 	 	  		system("clear ");
 	 	 		node *head=NULL;
 	 	 		endwin();
  		 		head=createlist();
  		 		system("clear ");
  		 		if(head) options_dl(head);
  		 		system("clear ");
  		 		refresh();
  		 		}	break;

 	 	  case 1:	{
 	 	  		system("clear ");
 	 	 		node *head=NULL;
 	 	 		endwin();
  		 		head=createlists();
  		 		system("clear ");
  		 		if(head) options(head);
  		 		system("clear ");
  		 		refresh();
  		 		}	break;
  		   }
  		 }	attroff(COLOR_PAIR(4)); break;

 								//stacks
 	case 3:
 		{
 		  attron(COLOR_PAIR(5));
 			system("clear ");
 	 	  printw("\n 1: Stacks using arrays ");
    		  printw("\n 2: Stacks using linked lists ");
    		  printw("\n 3: Polish Notations ");
    		  printw("\n 4: Tower of Hanoi ");
    		  printw("\n 0: Back 	\t");
    		  		refresh();
 	 	 		scanw("%d",&k);
 	 	 switch(k)

    		  {
    		  case 0:	system("clear "); main(); break;
    		  case 1:	{
    		  		 system("clear ");
    		  		 stack_a s;
    		  		 s.top=-1;
    		  		 endwin();
 				 options_sa(&s);
 				 system("clear ");
    		  		 refresh();
    		  		}	break;

    		  case 2:	{
    		  		 system("clear ");
    		  		 stack_l *top=NULL;
    		  		 endwin();
    		  		 options_sl(top);
    		  		 system("clear ");
    		  		 refresh();
    		  		}	break;


 	 	  case 3:	{
 	 	  		 system("clear ");
 	 	  		 stack k;
 	 	  		 endwin();
 	 	  		 create_p(&k);
 				 options_p(&k);
 				 system("clear ");
 				 refresh();
  		 		}	break;

 	 	  case 4:	{
 	 	  		 system("clear ");
 	 	  		 char src='A',tmp='C',dest='B' ;
 	 	  		 printw("\n Enter the number of disks ");
 	 	  		 refresh();
  				 scanw("%d",&z);
   				 TOH(z,src,tmp,dest);
   				 system("sleep 2");
   				 system("clear ");
   				 refresh();
 	 	  		}
 	 	  			break;
  		   }
  		 }	break;
 			attroff(COLOR_PAIR(5));
 	 		break;

 	case 4:
 			{
 			attron(COLOR_PAIR(6));
 				system("clear ");					//Queues
 	 	  printw("\n 1: Queues using arrays ");
    		  printw("\n 2: Queues using linked lists ");
    		  printw("\n 0: Back 	\t");
    		  		refresh();
    		  		scanw("%d",&k);
 	 	 switch(k)
    		  {
    		  case 0:	system("clear "); main(); break;
    		  case 1:	{system("clear ");
    		  		 front_a=-1;
    		  		 rear_a=-1;
    		  		 endwin();
    		  		 options_qa(&q);
    		  		 system("clear ");
    		  		 refresh();
    		  		}	break;

    		  case 2:	{system("clear ");
    		  		 count=0;
    		  		 front=NULL;
  				 rear=NULL;
  				 endwin();
   				 options_ql();
   				 system("clear ");
   				 refresh();
    		  		}	break;
  		   }
  		 }	break;
 			attroff(COLOR_PAIR(6));
 			break;

 								//Binary Tree
 	case 5:		{
 			   attron(COLOR_PAIR(1));
 			   system("clear ");
 			   printw("\n BINARY TREE PROGRAM \n");
 			   printw(" Enter (-1) wherever null \n\n");
 			   refresh();
   			   tree * root;
   			   tos=-1; fr=-1; rr=-1;
   			   system("sleep 2");
   			   endwin();
 			   root=createtree();
 			   system("clear ");
		           options_bt(root);
		           system("clear ");
		           refresh();
		           attroff(COLOR_PAIR(1));
 			}

 					break;
 								//Binary Search Tree
 	case 6:		{
 	  		  attron(COLOR_PAIR(3));
 	 		  system("clear ");
 			  printw("\n BINARY SEARCH TREE PROGRAM \n");
  			  printw(" Enter (-1) wherever null \n\n");
  			  refresh();
    			  tree *root=NULL;
    			  tos=-1; fr=-1; rr=-1;
    			  system("sleep 2");
    			  endwin();
     			  options_bst(root);
 			  system("clear ");
 			  refresh();
 			  attroff(COLOR_PAIR(3));
 			}

 					break;			//AVL Tree
 	case 7:		{
 	 		  attron(COLOR_PAIR(4));
 			  system("clear ");
 			  printw("\n AVL TREE PROGRAM \n");
  			  printw(" Enter (-1) wherever null \n\n");
  			  refresh();
  			  tree *root=NULL;
  			  tos=-1; fr=-1; rr=-1;
  			  system("sleep 2");
  			  endwin();
   			  options_av(root);
   			  system("clear ");
   			  refresh();
   			  attroff(COLOR_PAIR(4));
 			}

 					break;
 	case 0:
 		attroff(COLOR_PAIR(1));
 		system("clear ");
 		printw("\n Are you sure to exit : ");
 		refresh();
 		scanw("%d",&z);
 		if(z==1)
 		{

 		for(i=4; i>=0; i--)
 		  {

 		system("clear ");
 		printw("\n Exiting the execution : ");
 		printw("\n Removing core dumps . Please wait. \n");

 		printw("\n\n ACKNOWLEDGEMENTS : ");
 		printw("\n Ashish Sir ");

 		printw("\n\n REFERENCES : ");
 		printw("\n 1: Linux Manual : ");
 		printw("\n 2: Internet ");
 		printw("\n 3: DSA Books\n ");

 		printw("\n THANKS : \n");

 		printw("\n\n Releasing assets %d%% \n",((4-i)*100/4));
 		refresh();

 		system("sleep 1");
 		clear();
 		   }
 		   break;
 		}

 		else	system("clear "); main();


 		break;

 	default:

 		 printw("\n\n Wrong choice specified in the main menu \n");
 		 refresh();
 		 break;

      }

   }
   	attroff(COLOR_PAIR(1));
   	endwin();
   	return 0;
  }
Exemple #28
0
void main() {

	#define PALSIZE 8
	char *palette=" -=*O@@@@_";
	
	srand(time(NULL));
	// Needed
	initscr(); cbreak(); noecho();
	// Optional
	nonl(); intrflush(stdscr,FALSE); keypad(stdscr,FALSE);
	printf("%i x %i\n",COLS,LINES);

	if (has_colors()) {
		start_color();
		init_pair(0,COLOR_BLACK,COLOR_BLACK);
		init_pair(1,COLOR_BLUE,COLOR_BLACK);
		init_pair(2,COLOR_RED,COLOR_BLACK);
		init_pair(3,COLOR_MAGENTA,COLOR_BLACK);
		init_pair(4,COLOR_GREEN,COLOR_BLACK);
		init_pair(5,COLOR_CYAN,COLOR_BLACK);
		init_pair(6,COLOR_YELLOW,COLOR_BLACK);
		init_pair(7,COLOR_WHITE,COLOR_BLACK);
	}

	frames=0;

	cls();

	while (true) {
		
		// doSummat(&lonewriteToPoint);

		cenx = COLS / 2;
		ceny = LINES / 2;
		swirlang = (float)frames * M_PI / 800.0;
		// Zooming in and out over time
		spacePerSwirl = 0.08+0.03*cos(0.000638*(float)frames);

		move(0,0);
		attrset(COLOR_PAIR(2) | A_BOLD);

		for (int y = 0;y<LINES;y++) {
			for (int x = 0;x<COLS;x++) {

				float swirlHeight=getSwirlHeight(x,y);
				{
					int c=
							( getSwirlHeight(x+1,y+1) > 0 ? 1 : 0 )
						+	( getSwirlHeight(x,y+1) > 0 ? 1 : 0 )
						+	( getSwirlHeight(x+1,y) > 0 ? 1 : 0 )
						+	( getSwirlHeight(x,y) > 0 ? 1 : 0 )
						+	( getSwirlHeight((float)x+0.5,(float)y+0.5) > 0 ? 1 : 0 );
					char ch = palette[c];
					// mvaddch(y,x,32);
					addch(ch);
				}

			}
		}

		// int x = frames%COLS;
		// int y = (frames/COLS)%LINES;
		// move(y,x);
		// attrset(COLOR_PAIR(7));
		// char *str;
		// sprintf(str," (- %i -) ",frames);
		// addstr(str);
		// printf("%i ",frames);
		// move(1,0);
		// attrset(COLOR_PAIR(0));
		// printf("%i ",frames);
		wrefresh(stdscr);

		frames += 10;

	}

	cls();

	// Needed
	endwin();
}