Example #1
0
/*
 * Display a dialog box for entering a date
 */
int
dialog_calendar(const char *title,
		const char *subtitle,
		int height,
		int width,
		int day,
		int month,
		int year)
{
    /* *INDENT-OFF* */
    static DLG_KEYS_BINDING binding[] = {
	HELPKEY_BINDINGS,
	ENTERKEY_BINDINGS,
	DLG_KEYS_DATA( DLGK_ENTER,	' ' ),
	DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
	DLG_KEYS_DATA( DLGK_GRID_DOWN,	'j' ),
	DLG_KEYS_DATA( DLGK_GRID_DOWN,	DLGK_MOUSE(KEY_NPAGE) ),
	DLG_KEYS_DATA( DLGK_GRID_DOWN,	KEY_DOWN ),
	DLG_KEYS_DATA( DLGK_GRID_DOWN,	KEY_NPAGE ),
	DLG_KEYS_DATA( DLGK_GRID_LEFT,	'-' ),
	DLG_KEYS_DATA( DLGK_GRID_LEFT,  'h' ),
	DLG_KEYS_DATA( DLGK_GRID_LEFT,  CHR_BACKSPACE ),
	DLG_KEYS_DATA( DLGK_GRID_LEFT,  CHR_PREVIOUS ),
	DLG_KEYS_DATA( DLGK_GRID_LEFT,  KEY_LEFT ),
	DLG_KEYS_DATA( DLGK_GRID_RIGHT,	'+' ),
	DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'l' ),
	DLG_KEYS_DATA( DLGK_GRID_RIGHT, CHR_NEXT ),
	DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_NEXT ),
	DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ),
	DLG_KEYS_DATA( DLGK_GRID_UP,	'k' ),
	DLG_KEYS_DATA( DLGK_GRID_UP,	KEY_PPAGE ),
	DLG_KEYS_DATA( DLGK_GRID_UP,	KEY_PREVIOUS ),
	DLG_KEYS_DATA( DLGK_GRID_UP,	KEY_UP ),
	DLG_KEYS_DATA( DLGK_GRID_UP,  	DLGK_MOUSE(KEY_PPAGE) ),
	END_KEYS_BINDING
    };
    /* *INDENT-ON* */

#ifdef KEY_RESIZE
    int old_height = height;
    int old_width = width;
#endif
    BOX dy_box, mn_box, yr_box;
    int fkey;
    int key = 0;
    int key2;
    int step;
    int button;
    int result = DLG_EXIT_UNKNOWN;
    WINDOW *dialog;
    time_t now_time = time((time_t *) 0);
    struct tm current;
    int state = dlg_defaultno_button();
    const char **buttons = dlg_ok_labels();
    char *prompt = dlg_strclone(subtitle);
    int mincols = MIN_WIDE;
    char buffer[MAX_LEN];
    DIALOG_VARS save_vars;

    dlg_save_vars(&save_vars);
    dialog_vars.separate_output = TRUE;

    dlg_does_output();

    now_time = time((time_t *) 0);
    current = *localtime(&now_time);
    if (day < 0)
	day = current.tm_mday;
    if (month < 0)
	month = current.tm_mon + 1;
    if (year < 0)
	year = current.tm_year + 1900;

    /* compute a struct tm that matches the day/month/year parameters */
    if (((year -= 1900) > 0) && (year < 200)) {
	/* ugly, but I'd like to run this on older machines w/o mktime -TD */
	for (;;) {
	    if (year > current.tm_year) {
		now_time += ONE_DAY * days_in_year(&current, 0);
	    } else if (year < current.tm_year) {
		now_time -= ONE_DAY * days_in_year(&current, -1);
	    } else if (month > current.tm_mon + 1) {
		now_time += ONE_DAY * days_in_month(&current, 0);
	    } else if (month < current.tm_mon + 1) {
		now_time -= ONE_DAY * days_in_month(&current, -1);
	    } else if (day > current.tm_mday) {
		now_time += ONE_DAY;
	    } else if (day < current.tm_mday) {
		now_time -= ONE_DAY;
	    } else {
		break;
	    }
	    current = *localtime(&now_time);
	}
    }
    dlg_button_layout(buttons, &mincols);

#ifdef KEY_RESIZE
  retry:
#endif

    dlg_auto_size(title, prompt, &height, &width, 0, mincols);
    height += MIN_HIGH - 1;
    dlg_print_size(height, width);
    dlg_ctl_size(height, width);

    dialog = dlg_new_window(height, width,
			    dlg_box_y_ordinate(height),
			    dlg_box_x_ordinate(width));
    dlg_register_window(dialog, "calendar", binding);
    dlg_register_buttons(dialog, "calendar", buttons);

    /* mainbox */
    dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    dlg_draw_bottom_box(dialog);
    dlg_draw_title(dialog, title);

    wattrset(dialog, dialog_attr);	/* text mainbox */
    dlg_print_autowrap(dialog, prompt, height, width);

    /* compute positions of day, month and year boxes */
    memset(&dy_box, 0, sizeof(dy_box));
    memset(&mn_box, 0, sizeof(mn_box));
    memset(&yr_box, 0, sizeof(yr_box));

    if (init_object(&dy_box,
		    dialog,
		    (width - DAY_WIDE) / 2,
		    1 + (height - (DAY_HIGH + BTN_HIGH + (5 * MARGIN))),
		    DAY_WIDE,
		    DAY_HIGH + 1,
		    draw_day,
		    'D') < 0
	|| DrawObject(&dy_box) < 0) {
	return CleanupResult(DLG_EXIT_ERROR, dialog, prompt, &save_vars);
    }

    if (init_object(&mn_box,
		    dialog,
		    dy_box.x,
		    dy_box.y - (HDR_HIGH + 2 * MARGIN),
		    (DAY_WIDE / 2) - MARGIN,
		    HDR_HIGH,
		    draw_month,
		    'M') < 0
	|| DrawObject(&mn_box) < 0) {
	return CleanupResult(DLG_EXIT_ERROR, dialog, prompt, &save_vars);
    }

    if (init_object(&yr_box,
		    dialog,
		    dy_box.x + mn_box.width + 2,
		    mn_box.y,
		    mn_box.width,
		    mn_box.height,
		    draw_year,
		    'Y') < 0
	|| DrawObject(&yr_box) < 0) {
	return CleanupResult(DLG_EXIT_ERROR, dialog, prompt, &save_vars);
    }

    while (result == DLG_EXIT_UNKNOWN) {
	BOX *obj = (state == sDAY ? &dy_box
		    : (state == sMONTH ? &mn_box :
		       (state == sYEAR ? &yr_box : 0)));

	button = (state < 0) ? 0 : state;
	dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
	if (obj != 0)
	    dlg_set_focus(dialog, obj->window);

	key = dlg_mouse_wgetch(dialog, &fkey);
	if (dlg_result_key(key, fkey, &result))
	    break;

	if (fkey && (key >= DLGK_MOUSE(KEY_MIN) && key <= DLGK_MOUSE(KEY_MAX))) {
	    key = dlg_lookup_key(dialog, key - M_EVENT, &fkey);
	}

	if ((key2 = dlg_char_to_button(key, buttons)) >= 0) {
	    result = key2;
	} else if (fkey) {
	    /* handle function-keys */
	    switch (key) {
	    case DLGK_MOUSE('D'):
		state = sDAY;
		break;
	    case DLGK_MOUSE('M'):
		state = sMONTH;
		break;
	    case DLGK_MOUSE('Y'):
		state = sYEAR;
		break;
	    case DLGK_ENTER:
		result = dlg_enter_buttoncode(button);
		break;
	    case DLGK_FIELD_PREV:
		state = dlg_prev_ok_buttonindex(state, sMONTH);
		break;
	    case DLGK_FIELD_NEXT:
		state = dlg_next_ok_buttonindex(state, sMONTH);
		break;
#ifdef KEY_RESIZE
	    case KEY_RESIZE:
		/* reset data */
		height = old_height;
		width = old_width;
		/* repaint */
		dlg_clear();
		dlg_del_window(dialog);
		refresh();
		dlg_mouse_free_regions();
		goto retry;
#endif
	    default:
		step = 0;
		key2 = -1;
		if (is_DLGK_MOUSE(key)) {
		    if ((key2 = dlg_ok_buttoncode(key - M_EVENT)) >= 0) {
			result = key2;
			break;
		    } else if (key >= DLGK_MOUSE(KEY_MAX)) {
			state = sDAY;
			obj = &dy_box;
			key2 = 1;
			step = (key
				- DLGK_MOUSE(KEY_MAX)
				- day_cell_number(&current));
		    }
		}
		if (obj != 0) {
		    if (key2 < 0)
			step = next_or_previous(key, (obj == &dy_box));
		    if (step != 0) {
			struct tm old = current;

			/* see comment regarding mktime -TD */
			if (obj == &dy_box) {
			    now_time += ONE_DAY * step;
			} else if (obj == &mn_box) {
			    if (step > 0)
				now_time += ONE_DAY *
				    days_in_month(&current, 0);
			    else
				now_time -= ONE_DAY *
				    days_in_month(&current, -1);
			} else if (obj == &yr_box) {
			    if (step > 0)
				now_time += (ONE_DAY
					     * days_in_year(&current, 0));
			    else
				now_time -= (ONE_DAY
					     * days_in_year(&current, -1));
			}

			current = *localtime(&now_time);

			if (obj != &dy_box
			    && (current.tm_mday != old.tm_mday
				|| current.tm_mon != old.tm_mon
				|| current.tm_year != old.tm_year))
			    DrawObject(&dy_box);
			if (obj != &mn_box && current.tm_mon != old.tm_mon)
			    DrawObject(&mn_box);
			if (obj != &yr_box && current.tm_year != old.tm_year)
			    DrawObject(&yr_box);
			(void) DrawObject(obj);
		    }
		} else if (state >= 0) {
		    if (next_or_previous(key, FALSE) < 0)
			state = dlg_prev_ok_buttonindex(state, sMONTH);
		    else if (next_or_previous(key, FALSE) > 0)
			state = dlg_next_ok_buttonindex(state, sMONTH);
		}
		break;
	    }
	}
    }

#define DefaultFormat(dst, src) \
	sprintf(dst, "%02d/%02d/%0d", \
		src.tm_mday, src.tm_mon + 1, src.tm_year + 1900)
#ifdef HAVE_STRFTIME
    if (dialog_vars.date_format != 0) {
	size_t used = strftime(buffer,
			       sizeof(buffer) - 1,
			       dialog_vars.date_format,
			       &current);
	if (used == 0 || *buffer == '\0')
	    DefaultFormat(buffer, current);
    } else
#endif
	DefaultFormat(buffer, current);

    dlg_add_result(buffer);
    dlg_add_separator();

    return CleanupResult(result, dialog, prompt, &save_vars);
}
Example #2
0
int weditstr(WINDOW *win, char *buf, int field)
{
    char org[MAXSTRLEN], *tp, *bp = buf;
    bool defdisp = TRUE, stop = FALSE, insert = FALSE;
    int cury, curx, begy, begx;
    chtype oldattr;
    WINDOW *wedit;
    int c = 0;

    if ((field >= MAXSTRLEN) || (buf == NULL) ||
        ((int)strlen(buf) > field - 1))
        return ERR;

    strcpy(org, buf);   /* save original */

    wrefresh(win);
    getyx(win, cury, curx);
    getbegyx(win, begy, begx);

    wedit = subwin(win, 1, field, begy + cury, begx + curx);
    oldattr = wedit->_attrs;
    colorbox(wedit, EDITBOXCOLOR, 0);

    keypad(wedit, TRUE);
    curs_set(1);

    while (!stop)
    {
        idle();
        repainteditbox(wedit, (int)( bp - buf), buf);

        switch (c = wgetch(wedit))
        {
        case ERR:
            break;

        case KEY_ESC:
            strcpy(buf, org);   /* restore original */
            stop = TRUE;
            break;

        case '\n':
        case KEY_UP:
        case KEY_DOWN:
            stop = TRUE;
            break;

        case KEY_LEFT:
            if (bp > buf)
                bp--;
            break;

        case KEY_RIGHT:
            defdisp = FALSE;
            if (bp - buf < (int)strlen(buf))
                bp++;
            break;

        case '\t':            /* TAB -- because insert
                                  is broken on HPUX */
        case KEY_IC:          /* enter insert mode */
        case KEY_EIC:         /* exit insert mode */
            defdisp = FALSE;
            insert = !insert;

            curs_set(insert ? 2 : 1);
            break;

        default:
            if (c == erasechar())       /* backspace, ^H */
            {
                if (bp > buf)
                {
                    memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1);
                    bp--;
                }
            }
            else if (c == killchar())   /* ^U */
            {
                bp = buf;
                *bp = '\0';
            }
            else if (c == wordchar())   /* ^W */
            {
                tp = bp;

                while ((bp > buf) && (*(bp - 1) == ' '))
                    bp--;
                while ((bp > buf) && (*(bp - 1) != ' '))
                    bp--;

                memmove((void *)bp, (const void *)tp, strlen(tp) + 1);
            }
            else if (isprint(c))
            {
                if (defdisp)
                {
                    bp = buf;
                    *bp = '\0';
                    defdisp = FALSE;
                }

                if (insert)
                {
                    if ((int)strlen(buf) < field - 1)
                    {
                        memmove((void *)(bp + 1), (const void *)bp,
                                strlen(bp) + 1);

                        *bp++ = c;
                    }
                }
                else if (bp - buf < field - 1)
                {
                    /* append new string terminator */

                    if (!*bp)
                        bp[1] = '\0';

                    *bp++ = c;
                }
            }
        }
    }

    curs_set(0);

    wattrset(wedit, oldattr);
    repainteditbox(wedit, (int)( bp - buf), buf);
    delwin(wedit);

    return c;
}
/*
 * Display a dialog box for entering a date
 */
int
dialog_calendar(const char *title,
		const char *subtitle,
		int height,
		int width,
		int day,
		int month,
		int year)
{
    BOX dy_box, mn_box, yr_box;
    int fkey;
    int key = 0;
    int key2;
    int step;
    int button = 0;
    int result = DLG_EXIT_UNKNOWN;
    WINDOW *dialog;
    time_t now_time = time((time_t *) 0);
    struct tm current;
    STATES state = 0;
    const char **buttons = dlg_ok_labels();
    char *prompt = strclone(subtitle);

    dlg_does_output();

    now_time = time((time_t *) 0);
    current = *localtime(&now_time);
    if (day < 0)
	day = current.tm_mday;
    if (month < 0)
	month = current.tm_mon + 1;
    if (year < 0)
	year = current.tm_year + 1900;

    /* compute a struct tm that matches the day/month/year parameters */
    if (((year -= 1900) > 0) && (year < 200)) {
	/* ugly, but I'd like to run this on older machines w/o mktime -TD */
	for (;;) {
	    if (year > current.tm_year) {
		now_time += ONE_DAY * days_in_year(&current, 0);
	    } else if (year < current.tm_year) {
		now_time -= ONE_DAY * days_in_year(&current, -1);
	    } else if (month > current.tm_mon + 1) {
		now_time += ONE_DAY * days_in_month(&current, 0);
	    } else if (month < current.tm_mon + 1) {
		now_time -= ONE_DAY * days_in_month(&current, -1);
	    } else if (day > current.tm_mday) {
		now_time += ONE_DAY;
	    } else if (day < current.tm_mday) {
		now_time -= ONE_DAY;
	    } else {
		break;
	    }
	    current = *localtime(&now_time);
	}
    }

    auto_size(title, prompt, &height, &width, 0, 0);
    height += MIN_HIGH;
    if (width < MIN_WIDE)
	width = MIN_WIDE;
    print_size(height, width);
    ctl_size(height, width);

    /* FIXME: how to make this resizable? */
    dialog = new_window(height, width,
			box_y_ordinate(height),
			box_x_ordinate(width));

    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    draw_bottom_box(dialog);
    draw_title(dialog, title);

    wattrset(dialog, dialog_attr);
    print_autowrap(dialog, prompt, height, width);

    /* compute positions of day, month and year boxes */
    memset(&dy_box, 0, sizeof(dy_box));
    memset(&mn_box, 0, sizeof(mn_box));
    memset(&yr_box, 0, sizeof(yr_box));

    if (init_object(&dy_box,
		    dialog,
		    (width - DAY_WIDE) / 2,
		    (height - (DAY_HIGH + BTN_HIGH + (4 * MARGIN))),
		    DAY_WIDE,
		    DAY_HIGH + (2 * MARGIN),
		    draw_day,
		    'D') < 0
	|| DrawObject(&dy_box) < 0)
	return DLG_EXIT_ERROR;

    if (init_object(&mn_box,
		    dialog,
		    dy_box.x,
		    dy_box.y - (HDR_HIGH + 2 * MARGIN),
		    (DAY_WIDE / 2) - MARGIN,
		    HDR_HIGH,
		    draw_month,
		    'M') < 0
	|| DrawObject(&mn_box) < 0)
	return DLG_EXIT_ERROR;

    if (init_object(&yr_box,
		    dialog,
		    dy_box.x + mn_box.width + 2,
		    mn_box.y,
		    mn_box.width,
		    mn_box.height,
		    draw_year,
		    'Y') < 0
	|| DrawObject(&yr_box) < 0)
	return DLG_EXIT_ERROR;

    while (result == DLG_EXIT_UNKNOWN) {
	BOX *obj = (state == sDAY ? &dy_box
		    : (state == sMONTH ? &mn_box :
		       (state == sYEAR ? &yr_box : 0)));

	button = (state < 0) ? 0 : state;
	dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
	if (obj != 0)
	    dlg_set_focus(dialog, obj->window);

	key = mouse_wgetch(dialog, &fkey);

	if ((key2 = dlg_char_to_button(key, buttons)) >= 0) {
	    result = key2;
	} else {
	    /* handle non-functionkeys */
	    if (!fkey) {
		fkey = TRUE;
		switch (key) {
		case ' ':
		case '\n':
		case '\r':
		    key = KEY_ENTER;
		    break;
		case TAB:
		    key = KEY_RIGHT;
		    break;
		case CHR_PREVIOUS:
		case CHR_NEXT:
		case CHR_BACKSPACE:
		case 'h':
		case 'j':
		case 'k':
		case 'l':
		    /* treat these as function-keys */
		    break;
		case ESC:
		    result = DLG_EXIT_ESC;
		    fkey = FALSE;
		    break;
		default:
		    fkey = FALSE;
		    break;
		}
	    }

	    /* handle functionkeys */
	    if (fkey) {
		switch (key) {
		case M_EVENT + 'D':
		    state = sDAY;
		    break;
		case M_EVENT + 'M':
		    state = sMONTH;
		    break;
		case M_EVENT + 'Y':
		    state = sYEAR;
		    break;
		case KEY_ENTER:
		    result = dlg_ok_buttoncode(button);
		    break;
		case KEY_LEFT:
		case KEY_BTAB:
		    state = dlg_prev_ok_buttonindex(state, sMONTH);
		    break;
		case KEY_RIGHT:
		    state = dlg_next_ok_buttonindex(state, sMONTH);
		    break;
		default:
		    step = 0;
		    key2 = -1;
		    if (key >= M_EVENT) {
			if ((key2 = dlg_ok_buttoncode(key - M_EVENT)) >= 0) {
			    result = key2;
			    break;
			} else if (key >= (M_EVENT + KEY_MAX)) {
			    state = sDAY;
			    obj = &dy_box;
			    key2 = 1;
			    step = (key
				    - (M_EVENT + KEY_MAX)
				    - day_cell_number(&current));
			}
		    }
		    if (obj != 0) {
			if (key2 < 0)
			    step = next_or_previous(key, (obj == &dy_box));
			if (step != 0) {
			    struct tm old = current;

			    /* see comment regarding mktime -TD */
			    if (obj == &dy_box) {
				now_time += ONE_DAY * step;
			    } else if (obj == &mn_box) {
				if (step > 0)
				    now_time += ONE_DAY *
					days_in_month(&current, 0);
				else
				    now_time -= ONE_DAY *
					days_in_month(&current, -1);
			    } else if (obj == &yr_box) {
				if (step > 0)
				    now_time += (ONE_DAY
						 * days_in_year(&current, 0));
				else
				    now_time -= (ONE_DAY
						 * days_in_year(&current, -1));
			    }

			    current = *localtime(&now_time);

			    if (obj != &dy_box
				&& (current.tm_mday != old.tm_mday
				    || current.tm_mon != old.tm_mon
				    || current.tm_year != old.tm_year))
				DrawObject(&dy_box);
			    if (obj != &mn_box && current.tm_mon != old.tm_mon)
				DrawObject(&mn_box);
			    if (obj != &yr_box && current.tm_year != old.tm_year)
				DrawObject(&yr_box);
			    (void) DrawObject(obj);
			}
		    }
		    break;
		}
	    }
	}
    }

    del_window(dialog);
    sprintf(dialog_vars.input_result, "%02d/%02d/%0d\n",
	    current.tm_mday, current.tm_mon + 1, current.tm_year + 1900);
    mouse_free_regions();
    free(prompt);
    return result;
}
Example #4
0
void ncurses_setup(struct winstruct *screen, struct satstruct *sat, struct tlmframestruct *tlmframe)
{

  int i,j;					/* Loop Counters */
  int w;					/* Raw Win Vert Offset */
  int tlmwin;					/* 0 if we are a 1 pkt bird */

  char hdr_gen_txt[28];				/* Header Text */

  /* Setup ncurses stuff */

   initscr();
   curs_set(0);                                 /* Turn the Cursor Off */
   cbreak();                                    /* Raw, Immediate Input */
   noecho();                                    /* Don't Do Any Echoing */
   nodelay(stdscr,TRUE);                        /* No Delays! */

   if(has_colors() == TRUE)
   {
      start_color();
      init_pair(TLM_COLOUR_HDR, COLOR_YELLOW, COLOR_BLACK); 
      init_pair(TLM_COLOUR_CLK, COLOR_RED, COLOR_BLACK); /* also QTH */
      init_pair(TLM_COLOUR_NOM, COLOR_WHITE, COLOR_BLACK);
      init_pair(TLM_COLOUR_STATIC, COLOR_BLACK, COLOR_CYAN);
      init_pair(TLM_COLOUR_DERIVED, COLOR_BLUE, COLOR_BLACK);   
      init_pair(TLM_COLOUR_INVIS, COLOR_BLACK, COLOR_BLACK); 
   }

   /* Create the clock, header, location, and binary windows. */
   /* Also create their borders */

   screen->hdr_win=newwin(5,25,0,28);
   screen->clk_win=newwin(5,29,0,0);
   screen->qth_win=newwin(5,28,0,52);
   screen->bin_win=newwin(5,80,19,0);

   wborder(screen->hdr_win,0,0,0,0,ACS_TTEE,ACS_TTEE,ACS_BTEE,ACS_BTEE);
   wborder(screen->clk_win,0,0,0,0,0,ACS_TTEE,ACS_LTEE,ACS_BTEE);
   wborder(screen->qth_win,0,0,0,0,ACS_TTEE,0,ACS_BTEE,ACS_RTEE);
   wborder(screen->bin_win,0,0,0,0,ACS_LTEE,ACS_RTEE,0,0);

   /* Setup non standard colours */

   if (has_colors() == TRUE)
   {
      wattrset(screen->hdr_win,COLOR_PAIR(TLM_COLOUR_HDR));
      wattrset(screen->clk_win,COLOR_PAIR(TLM_COLOUR_CLK));
      wattrset(screen->qth_win,COLOR_PAIR(TLM_COLOUR_QTH));
   }

   /* Now create the actual telemetry windows and panels, and border them */
   /* Also add the header line, to save another for loop */

   for (i=0; i<sat->tlmviews; i++)
   {
      screen->tlm_win[i]=newwin(15,80,5,0);
      screen->tlm_pan[i]=new_panel(screen->tlm_win[i]);
      wborder(screen->tlm_win[i],ACS_VLINE,ACS_VLINE,' ',ACS_HLINE,ACS_VLINE,ACS_VLINE,ACS_LTEE,ACS_RTEE);
      mvwprintw(screen->tlm_win[i],0,((80-strlen(sat->tlmhdr[i]))/2),sat->tlmhdr[i]);
   } 

   /* Setup Any Window Headers */

   strcpy(hdr_gen_txt,"APRS TELEMETRY VIEWER");
   mvwprintw(screen->hdr_win,2,((25-strlen(hdr_gen_txt))/2),hdr_gen_txt);
   mvwprintw(screen->hdr_win,1,((25-strlen(sat->label))/2),sat->label);


   if (sat->frametypes>0)
      mvwprintw(screen->tlm_win[0],2,1,"FRAME T#NNN CH1 CH2 CH3 CH4 CH5 CMD BITS SF Z     PACKET RECIEVED DATE");
   else
      mvwprintw(screen->tlm_win[0],2,24,"T#nnn --- --- --- --- --- CMD-BITS");

   /* Display the tlm labels */

   if (sat->frametypes==0)
      tlmwin=0;
   else
      tlmwin=1;

   for (i=0; i<=sat->frametypes; i++)
   {
      if (i<=3)
         w=0;
      else
         w=2;

      for (j=0; j<=4; j++)
      {
         mvwprintw(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j],"%s",tlmframe[i].lbl[j]);

         switch(tlmframe[i].valtype[j])
         {
            case TLM_VAL_TYPE_VOLT:
               mvwprintw(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+15,"V S");
               break;
            case TLM_VAL_TYPE_CURR:
               mvwprintw(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+14,"mA S");
               break;
            case TLM_VAL_TYPE_TEMP:
               mvwprintw(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+15,"C S");
               mvwaddch(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+14,ACS_DEGREE);
               break;
            case TLM_VAL_TYPE_TEMP_SHORTLBL:
               mvwprintw(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+15,"C S");
               mvwaddch(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+14,ACS_DEGREE);
               mvwaddch(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+6,ACS_DEGREE);
               break;
            case TLM_VAL_TYPE_WATT:
               mvwprintw(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+15,"W S");
               break;
            case TLM_VAL_TYPE_RAW:
               mvwprintw(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+15,"  S");
               break;

         }
         mvwchgat(screen->tlm_win[tlmwin],tlmframe[i].loc[0][j],tlmframe[i].loc[1][j]+17,1,A_NORMAL,TLM_COLOUR_INVIS,NULL);
      }

      if (sat->frametypes!=0)
      {
         mvwprintw(screen->tlm_win[0],3+w+i,78,"S");
         mvwchgat(screen->tlm_win[0],3+w+i,78,1,A_NORMAL,TLM_COLOUR_INVIS,NULL);
      }
      else
      {
         mvwprintw(screen->tlm_win[0],0,26,"S");
         mvwchgat(screen->tlm_win[0],0,26,1,A_NORMAL,TLM_COLOUR_INVIS,NULL);
         mvwprintw(screen->tlm_win[0],2,59,"S");
         mvwchgat(screen->tlm_win[0],2,59,1,A_NORMAL,TLM_COLOUR_INVIS,NULL);
      }
   }
   
   /* Setup cmd bits strings */

   for (i=0; i<=11; i++)
   {
      mvwprintw(screen->bin_win,sat->cmdloc[0][i],sat->cmdloc[1][i],sat->cmdstring[i]);
      mvwprintw(screen->bin_win,sat->cmdloc[0][i],(sat->cmdloc[1][i])+15,"S"); 
      mvwchgat(screen->bin_win,sat->cmdloc[0][i],sat->cmdloc[1][i],17,A_NORMAL,TLM_COLOUR_INVIS,NULL); 
   }

   /* Set raw view to be the default */

   screen->curtlmview=0;
   show_panel(screen->tlm_pan[screen->curtlmview]);
}
Example #5
0
//--------------------------------------------------------------------
void ConWindow::setAttribs(Style color)
{
    wattrset(win, attribStyle[color]);
} // end ConWindow::setAttribs
Example #6
0
/*
 * Display a dialog box for inputing a string
 */
int dialog_inputbox(const char *title, const char *prompt, int height, int width,
                    const char *init)
{
	int i, x, y, box_y, box_x, box_width;
	int input_x = 0, scroll = 0, key = 0, button = -1;
	char *instr = dialog_input_result;
	WINDOW *dialog;

	if (!init)
		instr[0] = '\0';
	else
		strcpy(instr, init);

do_resize:
	if (getmaxy(stdscr) <= (height - 2))
		return -ERRDISPLAYTOOSMALL;
	if (getmaxx(stdscr) <= (width - 2))
		return -ERRDISPLAYTOOSMALL;

	/* center dialog box on screen */
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);
	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	wattrset(dialog, dlg.dialog.atr);
	print_autowrap(dialog, prompt, width - 2, 1, 3);

	/* Draw the input field box */
	box_width = width - 6;
	getyx(dialog, y, x);
	box_y = y + 2;
	box_x = (width - box_width) / 2;
	draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
		 dlg.border.atr, dlg.dialog.atr);

	print_buttons(dialog, height, width, 0);

	/* Set up the initial value */
	wmove(dialog, box_y, box_x);
	wattrset(dialog, dlg.inputbox.atr);

	input_x = strlen(instr);

	if (input_x >= box_width) {
		scroll = input_x - box_width + 1;
		input_x = box_width - 1;
		for (i = 0; i < box_width - 1; i++)
			waddch(dialog, instr[scroll + i]);
	} else {
		waddstr(dialog, instr);
	}

	wmove(dialog, box_y, box_x + input_x);

	wrefresh(dialog);

	while (key != KEY_ESC) {
		key = wgetch(dialog);

		if (button == -1) {	/* Input box selected */
			switch (key) {
			case TAB:
			case KEY_UP:
			case KEY_DOWN:
				break;
			case KEY_LEFT:
				continue;
			case KEY_RIGHT:
				continue;
			case KEY_BACKSPACE:
			case 127:
			case '\b':
				if (input_x || scroll) {
					wattrset(dialog, dlg.inputbox.atr);
					if (!input_x) {
						scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
						wmove(dialog, box_y, box_x);
						for (i = 0; i < box_width; i++)
							waddch(dialog,
							       instr[scroll + input_x + i] ?
							       instr[scroll + input_x + i] : ' ');
						input_x = strlen(instr) - scroll;
					} else
						input_x--;
					instr[scroll + input_x] = '\0';
					mvwaddch(dialog, box_y, input_x + box_x, ' ');
					wmove(dialog, box_y, input_x + box_x);
					wrefresh(dialog);
				}
				continue;
			default:
				if (key < 0x100 && isprint(key)) {
					if (scroll + input_x < MAX_LEN) {
						wattrset(dialog, dlg.inputbox.atr);
						instr[scroll + input_x] = key;
						instr[scroll + input_x + 1] = '\0';
						if (input_x == box_width - 1) {
							scroll++;
							wmove(dialog, box_y, box_x);
							for (i = 0; i < box_width - 1; i++)
								waddch(dialog, instr [scroll + i]);
						} else {
							wmove(dialog, box_y, input_x++ + box_x);
							waddch(dialog, key);
						}
						wrefresh(dialog);
					} else
						flash();	/* Alarm user about overflow */
					continue;
				}
			}
		}
		switch (key) {
		case 'O':
		case 'o':
			delwin(dialog);
			return 0;
		case 'H':
		case 'h':
			delwin(dialog);
			return 1;
		case KEY_UP:
		case KEY_LEFT:
			switch (button) {
			case -1:
				button = 1;	/* Indicates "Cancel" button is selected */
				print_buttons(dialog, height, width, 1);
				break;
			case 0:
				button = -1;	/* Indicates input box is selected */
				print_buttons(dialog, height, width, 0);
				wmove(dialog, box_y, box_x + input_x);
				wrefresh(dialog);
				break;
			case 1:
				button = 0;	/* Indicates "OK" button is selected */
				print_buttons(dialog, height, width, 0);
				break;
			}
			break;
		case TAB:
		case KEY_DOWN:
		case KEY_RIGHT:
			switch (button) {
			case -1:
				button = 0;	/* Indicates "OK" button is selected */
				print_buttons(dialog, height, width, 0);
				break;
			case 0:
				button = 1;	/* Indicates "Cancel" button is selected */
				print_buttons(dialog, height, width, 1);
				break;
			case 1:
				button = -1;	/* Indicates input box is selected */
				print_buttons(dialog, height, width, 0);
				wmove(dialog, box_y, box_x + input_x);
				wrefresh(dialog);
				break;
			}
			break;
		case ' ':
		case '\n':
			delwin(dialog);
			return (button == -1 ? 0 : button);
		case 'X':
		case 'x':
			key = KEY_ESC;
			break;
		case KEY_ESC:
			key = on_key_esc(dialog);
			break;
#ifdef NCURSES_VERSION
		case KEY_RESIZE:
			delwin(dialog);
			on_key_resize();
			goto do_resize;
#endif
		}
	}

	delwin(dialog);
	return KEY_ESC;		/* ESC pressed */
}
int dialog_inputbox(WINDOW *main_window,
		const char *title, const char *prompt,
		const char *init, char **resultp, int *result_len)
{
	int prompt_lines = 0;
	int prompt_width = 0;
	WINDOW *win;
	WINDOW *prompt_win;
	WINDOW *form_win;
	PANEL *panel;
	int i, x, y;
	int res = -1;
	int cursor_position = strlen(init);
	int cursor_form_win;
	char *result = *resultp;

	if ((int)strlen(init)+1 > *result_len) {
		*result_len = strlen(init)+1;
		*resultp = result = realloc(result, *result_len);
	}

	/* find the widest line of msg: */
	prompt_lines = get_line_no(prompt);
	for (i = 0; i < prompt_lines; i++) {
		const char *line = get_line(prompt, i);
		int len = get_line_length(line);
		prompt_width = max(prompt_width, len);
	}

	if (title)
		prompt_width = max(prompt_width, (int)strlen(title));

	/* place dialog in middle of screen */
	y = (LINES-(prompt_lines+4))/2;
	x = (COLS-(prompt_width+4))/2;

	strncpy(result, init, *result_len);

	/* create the windows */
	win = newwin(prompt_lines+6, prompt_width+7, y, x);
	prompt_win = derwin(win, prompt_lines+1, prompt_width, 2, 2);
	form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2);
	keypad(form_win, TRUE);

	(void) wattrset(form_win, attributes[INPUT_FIELD]);

	(void) wattrset(win, attributes[INPUT_BOX]);
	box(win, 0, 0);
	(void) wattrset(win, attributes[INPUT_HEADING]);
	if (title)
		mvwprintw(win, 0, 3, "%s", title);

	/* print message */
	(void) wattrset(prompt_win, attributes[INPUT_TEXT]);
	fill_window(prompt_win, prompt);

	mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
	cursor_form_win = min(cursor_position, prompt_width-1);
	mvwprintw(form_win, 0, 0, "%s",
		  result + cursor_position-cursor_form_win);

	/* create panels */
	panel = new_panel(win);

	/* show the cursor */
	curs_set(1);

	touchwin(win);
	refresh_all_windows(main_window);
	while ((res = wgetch(form_win))) {
		int len = strlen(result);
		switch (res) {
		case 10: /* ENTER */
		case 27: /* ESCAPE */
		case KEY_F(F_HELP):
		case KEY_F(F_EXIT):
		case KEY_F(F_BACK):
			break;
		case 127:
		case KEY_BACKSPACE:
			if (cursor_position > 0) {
				memmove(&result[cursor_position-1],
						&result[cursor_position],
						len-cursor_position+1);
				cursor_position--;
				cursor_form_win--;
				len--;
			}
			break;
		case KEY_DC:
			if (cursor_position >= 0 && cursor_position < len) {
				memmove(&result[cursor_position],
						&result[cursor_position+1],
						len-cursor_position+1);
				len--;
			}
			break;
		case KEY_UP:
		case KEY_RIGHT:
			if (cursor_position < len) {
				cursor_position++;
				cursor_form_win++;
			}
			break;
		case KEY_DOWN:
		case KEY_LEFT:
			if (cursor_position > 0) {
				cursor_position--;
				cursor_form_win--;
			}
			break;
		case KEY_HOME:
			cursor_position = 0;
			cursor_form_win = 0;
			break;
		case KEY_END:
			cursor_position = len;
			cursor_form_win = min(cursor_position, prompt_width-1);
			break;
		default:
			if ((isgraph(res) || isspace(res))) {
				/* one for new char, one for '\0' */
				if (len+2 > *result_len) {
					*result_len = len+2;
					*resultp = result = realloc(result,
								*result_len);
				}
				/* insert the char at the proper position */
				memmove(&result[cursor_position+1],
						&result[cursor_position],
						len-cursor_position+1);
				result[cursor_position] = res;
				cursor_position++;
				cursor_form_win++;
				len++;
			} else {
				mvprintw(0, 0, "unknown key: %d\n", res);
			}
			break;
		}
		if (cursor_form_win < 0)
			cursor_form_win = 0;
		else if (cursor_form_win > prompt_width-1)
			cursor_form_win = prompt_width-1;

		wmove(form_win, 0, 0);
		wclrtoeol(form_win);
		mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
		mvwprintw(form_win, 0, 0, "%s",
			result + cursor_position-cursor_form_win);
		wmove(form_win, 0, cursor_form_win);
		touchwin(win);
		refresh_all_windows(main_window);

		if (res == 10) {
			res = 0;
			break;
		} else if (res == 27 || res == KEY_F(F_BACK) ||
				res == KEY_F(F_EXIT)) {
			res = KEY_EXIT;
			break;
		} else if (res == KEY_F(F_HELP)) {
			res = 1;
			break;
		}
	}

	/* hide the cursor */
	curs_set(0);
	del_panel(panel);
	delwin(prompt_win);
	delwin(form_win);
	delwin(win);
	return res;
}
Example #8
0
/*
 * Display a dialog box with two buttons - Yes and No
 */
int dialog_yesno(const char *title, const char *prompt, int height, int width)
{
    int i, x, y, key = 0, button = 0;
    WINDOW *dialog;

do_resize:
    if (getmaxy(stdscr) < (height + YESNO_HEIGTH_MIN))
        return -ERRDISPLAYTOOSMALL;
    if (getmaxx(stdscr) < (width + YESNO_WIDTH_MIN))
        return -ERRDISPLAYTOOSMALL;

    /* center dialog box on screen */
    x = (getmaxx(stdscr) - width) / 2;
    y = (getmaxy(stdscr) - height) / 2;

    draw_shadow(stdscr, y, x, height, width);

    dialog = newwin(height, width, y, x);
    keypad(dialog, TRUE);

    draw_box(dialog, 0, 0, height, width,
             dlg.dialog.atr, dlg.border.atr);
    wattrset(dialog, dlg.border.atr);
    mvwaddch(dialog, height - 3, 0, ACS_LTEE);
    for (i = 0; i < width - 2; i++)
        waddch(dialog, ACS_HLINE);
    wattrset(dialog, dlg.dialog.atr);
    waddch(dialog, ACS_RTEE);

    print_title(dialog, title, width);

    wattrset(dialog, dlg.dialog.atr);
    print_autowrap(dialog, prompt, width - 2, 1, 3);

    print_buttons(dialog, height, width, 0);

    while (key != KEY_ESC) {
        key = wgetch(dialog);
        switch (key) {
        case 'Y':
        case 'y':
            delwin(dialog);
            return 0;
        case 'N':
        case 'n':
            delwin(dialog);
            return 1;

        case TAB:
        case KEY_LEFT:
        case KEY_RIGHT:
            button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);

            print_buttons(dialog, height, width, button);
            wrefresh(dialog);
            break;
        case ' ':
        case '\n':
            delwin(dialog);
            return button;
        case KEY_ESC:
            key = on_key_esc(dialog);
            break;
        case KEY_RESIZE:
            delwin(dialog);
            on_key_resize();
            goto do_resize;
        }
    }

    delwin(dialog);
    return key;		/* ESC pressed */
}
Example #9
0
void Paint(STATE* state)
{
    size_t X = 0, Y = 0;

    attron(COLOR_PAIR(12) | A_BOLD);
    mvprintw(0, 0, "%s\n", gs_appname);

    move(state->Wy - 1, 0);
    for (X = 0; X < sizeof(state->keymap) / sizeof(int); X++) {
        attron(COLOR_PAIR(15));
        printw("%s", keymap_desc[X]);
        attron(COLOR_PAIR(11));
        printw("[");
        attron(COLOR_PAIR(14));
        printw("%s", keyname(state->keymap[X]));
        attron(COLOR_PAIR(11));
        printw("] ");
    }

    attroff(A_BOLD);
    attron(COLOR_PAIR(13));
    mvprintw(state->Wy - 1, state->Wx - strlen(state->clock),
            "%s", state->clock);

    // begin painting the status window
    if (state->statuswin) {
        StatusWindowPaint(state);
    }

    // begin painting the board
    werase(state->fieldwin);
    wattrset(state->fieldwin, A_NORMAL);
    box(state->fieldwin, 0, 0);

    if (! state->pause_f || state->do_pause_blocks) {
        for (Y = 0; Y < state->By; Y++) {
            wmove(state->fieldwin, Y + 1, 1);
            for (X = 0; X < state->Bx; X++) {
                wattrset(state->fieldwin, A_NORMAL);
                if (state->field[state->Bx * Y + X] == CLEARED) {
                        switch (state->do_clear) {
                        case CLEAR_FLASH:
                            wattron(state->fieldwin, COLOR_PAIR(rand() % 7 + 1));
                            break;
                        case CLEAR_BLANK:
                        default:
                            break;
                    }
                } else {
                    wattron(state->fieldwin, COLOR_PAIR(state->field[state->Bx * Y + X]));
                }

                waddch(state->fieldwin, ' ');
                waddch(state->fieldwin, ' ');
            }
        }
    }

    if (state->pause_f) {
        StatusMessage(state, state->fieldwin, gs_pause);
    }

    wattrset(state->fieldwin, A_NORMAL);
    if (state->game_over_f) {
        StatusMessage(state, state->fieldwin, gs_gameover);
    }


    // paint the tetrad
    if (state->tetrad)
        TetradPaint(state->fieldwin,
                state->tetrad->y + 1,
                state->tetrad->x + 1,
                state->tetrad);

    return;
}
Example #10
0
void
shNCursesInterface::showVersion ()
{
    const char *splash_logo[] =
    { /* PRIME logo designed by Psiweapon. */
        ".   _______________________   .",
        "  _/                       \\_  ",
        "=|  ####  ####  # #   #####  |=",
        " >------#-----#-#-##-##------< ",
        "=|  ####  ####  # # # #####  |=",
        "=|  #     #   # # #   #      |=",
        "=|_ #     #   # # #   ##### _|=",
        ".  \\[                     ]/  ."
    };
    const int len = strlen(splash_logo[0]);
    WINDOW *win;
    PANEL *panel;
    win = newwin (18, 60, 3, 10);
    if (!win) {
        return;
    }
    panel = new_panel (win);

    for (int y = 0; y < 8; ++y) {
        for (int x = 0; x < len; ++x) {
            if (splash_logo[y][x] == '#') {
                wattrset (win, ColorMap[kLime]);
            } else {
                wattrset (win, ColorMap[kGreen]);
            }
            mvwaddnstr (win, y, x + 15, &splash_logo[y][x], 1);
        }
    }

    wattrset (win, ColorMap[kBrown]);
    mvwaddstr (win, 7, 20, PRIME_VERSION"/Asbestos and webs");
    mvwaddstr (win, 9, 7, "Pesky Reticulans, Improvements, More Everything");
    /* The everything part includes bugs.  Tell no one! -- MB */
    wattrset (win, ColorMap[kYellow]);
    mvwaddstr (win, 9, 7,  "P");
    mvwaddstr (win, 9, 13, "R");
    mvwaddstr (win, 9, 25, "I");
    mvwaddstr (win, 9, 39, "M");
    mvwaddstr (win, 9, 44, "E");
    wattrset (win, ColorMap[kOrange]);
    mvwaddstr (win, 11, 14, "Unofficial variant of ZAPM v" ZAPM_VERSION " ");
    mvwaddstr (win, 12, 14, "by Psiweapon and Michal Bielinski");
    wattrset (win, ColorMap[kRed]);
    mvwaddstr (win, 13, 13, "http://arcywidmo.republika.pl/prime/");
    wattrset (win, A_NORMAL);
    mvwaddstr (win, 15, 15, "ZAPM (C) 2002-2010 Cyrus Dolph.");
    mvwaddstr (win, 16, 20, "All rights reserved.");
    mvwaddstr (win, 17, 20, "http://www.zapm.org");
    wattrset (win, ColorMap[kLime]);
    wattrset (win, A_NORMAL);

    update_panels ();
    doupdate ();
    getChar ();
    hide_panel (panel);
    del_panel (panel);
    delwin (win);
    update_panels ();
}
Example #11
0
void
shNCursesInterface::setWinColor (Window win, shColor color)
{
    wattrset (mWin[win], ColorMap[color]);
}
Example #12
0
File: ui.c Project: BlackLight/vifm
int
setup_ncurses_interface()
{
	int screen_x, screen_y;
	int i, x, y;

	initscr();
	noecho();
	nonl();
	raw();

	getmaxyx(stdscr, screen_y, screen_x);
	/* screen is too small to be useful*/
	if(screen_y < 10)
		finish("Terminal is too small to run vifm\n");
	if(screen_x < 30)
		finish("Terminal is too small to run vifm\n");

	if(! has_colors())
		finish("Vifm requires a console that can support color.\n");

	start_color();
	// Changed for pdcurses
	use_default_colors();

	x = 0;

	for (i = 0; i < cfg.color_scheme_num; i++)
	{
		for(x = 0; x < 12; x++)
			init_pair(col_schemes[i].color[x].name,
				col_schemes[i].color[x].fg, col_schemes[i].color[x].bg);
	}
	
	werase(stdscr);

	menu_win = newwin(screen_y - 1, screen_x, 0, 0);
	wbkgdset(menu_win, COLOR_PAIR(WIN_COLOR));
	werase(menu_win);

	sort_win = newwin(NUM_SORT_OPTIONS + 3, 30, (screen_y -12)/2, (screen_x -30)/2);
	wbkgdset(sort_win, COLOR_PAIR(WIN_COLOR));
	werase(sort_win);

	change_win = newwin(20, 30, (screen_y -20)/2, (screen_x -30)/2);
	wbkgdset(change_win, COLOR_PAIR(WIN_COLOR));
	werase(change_win);

	error_win = newwin(10, screen_x -2, (screen_y -10)/2, 1);
	wbkgdset(error_win, COLOR_PAIR(WIN_COLOR));
	werase(error_win);

	/* lborder = newwin(screen_y - 2, 1, 0, 0); */
	/* wbkgdset(lborder, COLOR_PAIR(BORDER_COLOR)); */
	/* werase(lborder); */

	if (curr_stats.number_of_windows == 1)
		lwin.title = newwin(0, screen_x -2, 0, 0);
	else
		lwin.title = newwin(0, screen_x/2 -1, 0, 1);
		
	/* wattrset(lwin.title, A_BOLD); */
	/* wbkgdset(lwin.title, COLOR_PAIR(BORDER_COLOR)); */
	/* werase(lwin.title); */

	if (curr_stats.number_of_windows == 1)
		lwin.win = newwin(screen_y -3, screen_x -2, 1, 1);
	else
		lwin.win = newwin(screen_y -3, screen_x/2 -2, 1, 1);

	keypad(lwin.win, TRUE);
	wbkgdset(lwin.win, COLOR_PAIR(WIN_COLOR));
	wattrset(lwin.win, A_BOLD);
	wattron(lwin.win, A_BOLD);
	werase(lwin.win);

	getmaxyx(lwin.win, y, x);
	lwin.window_rows = y -2;
	lwin.window_width = x -1;

	/* mborder = newwin(screen_y, 1, 0, screen_x/2 -1); */
	/* wbkgdset(mborder, COLOR_PAIR(BORDER_COLOR)); */
	/* werase(mborder); */

	if (curr_stats.number_of_windows == 1)
		rwin.title = newwin(0, screen_x -2  , 0, 1);
	else
		rwin.title = newwin(1, screen_x/2+2, 0, screen_x/2-1 );

	/* wbkgdset(rwin.title, COLOR_PAIR(BORDER_COLOR)); */
	/* wattrset(rwin.title, A_BOLD); */
	/* wattroff(rwin.title, A_BOLD); */
	/* werase(rwin.title); */

	if (curr_stats.number_of_windows == 1)
		rwin.win = newwin(screen_y - 3, screen_x -2 , 1, 1);
	else
		rwin.win = newwin(screen_y - 3, screen_x/2 -2 , 1, screen_x/2 +1);

	keypad(rwin.win, TRUE);
	wattrset(rwin.win, A_BOLD);
	wattron(rwin.win, A_BOLD);
	wbkgdset(rwin.win, COLOR_PAIR(WIN_COLOR));
	werase(rwin.win);
	getmaxyx(rwin.win, y, x);
	rwin.window_rows = y -2;
	rwin.window_width = x -1;

	/* rborder = newwin(screen_y - 2, 1, 0, screen_x -1); */
	/* wbkgdset(rborder, COLOR_PAIR(BORDER_COLOR)); */
	/* werase(rborder); */

	stat_win = newwin(1, screen_x, screen_y -2, 0);

	wbkgdset(stat_win, COLOR_PAIR(BORDER_COLOR));
	werase(stat_win);

	status_bar = newwin(1, screen_x - 19, screen_y -1, 0);
	keypad(status_bar, TRUE);
	wattrset(status_bar, A_BOLD);
	wattron(status_bar, A_BOLD);
	wbkgdset(status_bar, COLOR_PAIR(STATUS_BAR_COLOR));
	werase(status_bar);

	pos_win = newwin(1, 13, screen_y - 1, screen_x -13);
	wattrset(pos_win, A_BOLD);
	wattron(pos_win, A_BOLD);
	wbkgdset(pos_win, COLOR_PAIR(STATUS_BAR_COLOR));
	werase(pos_win);

	num_win = newwin(1, 6, screen_y - 1, screen_x -19);
	wattrset(num_win, A_BOLD);
	wattron(num_win, A_BOLD);
	wbkgdset(num_win, COLOR_PAIR(STATUS_BAR_COLOR));
	werase(num_win);


	wnoutrefresh(lwin.title);
	wnoutrefresh(lwin.win);
	wnoutrefresh(rwin.win);
	wnoutrefresh(rwin.title);
	wnoutrefresh(stat_win);
	wnoutrefresh(status_bar);
	wnoutrefresh(pos_win);
	wnoutrefresh(num_win);
	/* wnoutrefresh(lborder); */
	/* wnoutrefresh(mborder); */
	/* wnoutrefresh(rborder); */

	return 1;
}
Example #13
0
static bool garmin_bin_initialize(void)
{
    /*@-globstate@*/
    unsigned int i;

#ifndef CONTROLSEND_ENABLE
    if(serial) {
	monitor_complain("Direct mode doesn't supported.");
	return false;
    }
#endif

    /*@ -onlytrans @*/
    miscwin = subwin(devicewin, 1, 80, 1, 0);
    mid51win = subwin(devicewin, 12, 18, 2, 0);
    mid114win = subwin(devicewin, GARMIN_CHANNELS + 3, 23, 2, 18);
    if (miscwin == NULL || mid51win == NULL || mid114win == NULL)
	return false;

    (void)syncok(miscwin, true);
    (void)syncok(mid51win, true);
    (void)syncok(mid114win, true);

    /*@ -nullpass @*/
    (void)wattrset(miscwin, A_BOLD);
    display(miscwin, 0, 0, "Time:");
    (void)wattrset(miscwin, A_NORMAL);

    (void)wborder(mid51win, 0, 0, 0, 0, 0, 0, 0, 0),
    (void)wattrset(mid51win, A_BOLD);
    display(mid51win, 0, 4, " Position ");
    display(mid51win, 1, 2, "Fix:");
    display(mid51win, 2, 2, "Lat:");
    (void)mvwaddch(mid51win, 2, 16, ACS_DEGREE);
    display(mid51win, 3, 2, "Lon:");
    (void)mvwaddch(mid51win, 3, 16, ACS_DEGREE);
    display(mid51win, 4, 2, "Alt:          m");
    display(mid51win, 5, 2, "Speed:      m/s");
    display(mid51win, 6, 2, "Climb:      m/s");
    display(mid51win, 7, 2, "Leap:   sec");
    display(mid51win, 8, 2, "epe:       m");
    display(mid51win, 9, 2, "eph:       m");
    display(mid51win, 10, 2, "epv:       m");
    display(mid51win, 11, 3, " ID 51 (0x33) ");
    (void)wattrset(mid51win, A_NORMAL);

    (void)wborder(mid114win, 0, 0, 0, 0, 0, 0, 0, 0),
	(void)wattrset(mid114win, A_BOLD);
    display(mid114win, 1, 1, "Ch PRN  Az El  SNR ST");
    for (i = 0; i < GARMIN_CHANNELS; i++) {
	display(mid114win, (int)i + 2, 1, "%2d", i);
    }
    display(mid114win, 0, 5, " Satellite ");
    display(mid114win, 14, 4, " ID 114 (0x72) ");
    (void)wattrset(mid114win, A_NORMAL);

    /* initialize the GPS context's time fields */
    gpsd_time_init(session.context, time(NULL));

    return true;
    /*@+globstate@*/
}
Example #14
0
static void ui_window_draw(UiWin *w) {
	UiCursesWin *win = (UiCursesWin*)w;
	if (!ui_window_draw_sidebar(win))
		return;

	wbkgd(win->win, style_to_attr(&win->styles[UI_STYLE_DEFAULT]));
	wmove(win->win, 0, 0);
	int width = view_width_get(win->view);
	CellStyle *prev_style = NULL;
	size_t cursor_lineno = -1;

	if (win->options & UI_OPTION_CURSOR_LINE && win->ui->selwin == win) {
		Cursor *cursor = view_cursors(win->view);
		Filerange selection = view_cursors_selection_get(cursor);
		if (!view_cursors_next(cursor) && !text_range_valid(&selection))
			cursor_lineno = view_cursor_getpos(win->view).line;
	}

	short selection_bg = win->styles[UI_STYLE_SELECTION].bg;
	short cursor_line_bg = win->styles[UI_STYLE_CURSOR_LINE].bg;
	bool multiple_cursors = view_cursors_multiple(win->view);
	attr_t attr = A_NORMAL;

	for (const Line *l = view_lines_get(win->view); l; l = l->next) {
		bool cursor_line = l->lineno == cursor_lineno;
		for (int x = 0; x < width; x++) {
			enum UiStyles style_id = l->cells[x].style;
			if (style_id == 0)
				style_id = UI_STYLE_DEFAULT;
			CellStyle *style = &win->styles[style_id];

			if (l->cells[x].cursor && win->ui->selwin == win) {
				if (multiple_cursors && l->cells[x].cursor_primary)
					attr = style_to_attr(&win->styles[UI_STYLE_CURSOR_PRIMARY]);
				else
					attr = style_to_attr(&win->styles[UI_STYLE_CURSOR]);
				prev_style = NULL;
			} else if (l->cells[x].selected) {
				if (style->fg == selection_bg)
					attr |= A_REVERSE;
				else
					attr = style->attr | COLOR_PAIR(color_pair_get(style->fg, selection_bg));
				prev_style = NULL;
			} else if (cursor_line) {
				attr = style->attr | COLOR_PAIR(color_pair_get(style->fg, cursor_line_bg));
				prev_style = NULL;
			} else if (style != prev_style) {
				attr = style_to_attr(style);
				prev_style = style;
			}
			wattrset(win->win, attr);
			waddstr(win->win, l->cells[x].data);
		}
		/* try to fixup display issues, in theory we should always output a full line */
		int x, y;
		getyx(win->win, y, x);
		(void)y;
		wattrset(win->win, A_NORMAL);
		for (; 0 < x && x < width; x++)
			waddstr(win->win, " ");
	}

	wclrtobot(win->win);

	if (win->winstatus)
		ui_window_draw_status(w);
}
Example #15
0
int dialog_textbox(const char *title, const char *tbuf,
		   int initial_height, int initial_width)
{
	int i, x, y, cur_x, cur_y, key = 0;
	int height, width, boxh, boxw;
	int passed_end;
	WINDOW *dialog, *box;

	begin_reached = 1;
	end_reached = 0;
	page_length = 0;
	hscroll = 0;
	buf = tbuf;
	page = buf;	/* page is pointer to start of page to be displayed */

do_resize:
	getmaxyx(stdscr, height, width);
	if (height < 8 || width < 8)
		return -ERRDISPLAYTOOSMALL;
	if (initial_height != 0)
		height = initial_height;
	else
		if (height > 4)
			height -= 4;
		else
			height = 0;
	if (initial_width != 0)
		width = initial_width;
	else
		if (width > 5)
			width -= 5;
		else
			width = 0;

	/* center dialog box on screen */
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	/* Create window for box region, used for scrolling text */
	boxh = height - 4;
	boxw = width - 2;
	box = subwin(dialog, boxh, boxw, y + 1, x + 1);
	wattrset(box, dlg.dialog.atr);
	wbkgdset(box, dlg.dialog.atr & A_COLOR);

	keypad(box, TRUE);

	/* register the new window, along with its borders */
	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);

	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	print_button(dialog, gettext(" Exit "), height - 2, width / 2 - 4, TRUE);
	wnoutrefresh(dialog);
	getyx(dialog, cur_y, cur_x);	/* Save cursor position */

	/* Print first page of text */
	attr_clear(box, boxh, boxw, dlg.dialog.atr);
	refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);

	while ((key != KEY_ESC) && (key != '\n')) {
		key = wgetch(dialog);
		switch (key) {
		case 'E':	/* Exit */
		case 'e':
		case 'X':
		case 'x':
			delwin(box);
			delwin(dialog);
			return 0;
		case 'g':	/* First page */
		case KEY_HOME:
			if (!begin_reached) {
				begin_reached = 1;
				page = buf;
				refresh_text_box(dialog, box, boxh, boxw,
						 cur_y, cur_x);
			}
			break;
		case 'G':	/* Last page */
		case KEY_END:

			end_reached = 1;
			/* point to last char in buf */
			page = buf + strlen(buf);
			back_lines(boxh);
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case 'K':	/* Previous line */
		case 'k':
		case KEY_UP:
			if (!begin_reached) {
				back_lines(page_length + 1);

				/* We don't call print_page() here but use
				 * scrolling to ensure faster screen update.
				 * However, 'end_reached' and 'page_length'
				 * should still be updated, and 'page' should
				 * point to start of next page. This is done
				 * by calling get_line() in the following
				 * 'for' loop. */
				scrollok(box, TRUE);
				wscrl(box, -1);	/* Scroll box region down one line */
				scrollok(box, FALSE);
				page_length = 0;
				passed_end = 0;
				for (i = 0; i < boxh; i++) {
					if (!i) {
						/* print first line of page */
						print_line(box, 0, boxw);
						wnoutrefresh(box);
					} else
						/* Called to update 'end_reached' and 'page' */
						get_line();
					if (!passed_end)
						page_length++;
					if (end_reached && !passed_end)
						passed_end = 1;
				}

				print_position(dialog);
				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
				wrefresh(dialog);
			}
			break;
		case 'B':	/* Previous page */
		case 'b':
		case KEY_PPAGE:
			if (begin_reached)
				break;
			back_lines(page_length + boxh);
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case 'J':	/* Next line */
		case 'j':
		case KEY_DOWN:
			if (!end_reached) {
				begin_reached = 0;
				scrollok(box, TRUE);
				scroll(box);	/* Scroll box region up one line */
				scrollok(box, FALSE);
				print_line(box, boxh - 1, boxw);
				wnoutrefresh(box);
				print_position(dialog);
				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
				wrefresh(dialog);
			}
			break;
		case KEY_NPAGE:	/* Next page */
		case ' ':
			if (end_reached)
				break;

			begin_reached = 0;
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case '0':	/* Beginning of line */
		case 'H':	/* Scroll left */
		case 'h':
		case KEY_LEFT:
			if (hscroll <= 0)
				break;

			if (key == '0')
				hscroll = 0;
			else
				hscroll--;
			/* Reprint current page to scroll horizontally */
			back_lines(page_length);
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case 'L':	/* Scroll right */
		case 'l':
		case KEY_RIGHT:
			if (hscroll >= MAX_LEN)
				break;
			hscroll++;
			/* Reprint current page to scroll horizontally */
			back_lines(page_length);
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case KEY_ESC:
			key = on_key_esc(dialog);
			break;
		case KEY_RESIZE:
			back_lines(height);
			delwin(box);
			delwin(dialog);
			on_key_resize();
			goto do_resize;
		}
	}
	delwin(box);
	delwin(dialog);
	return key;		/* ESC pressed */
}
Example #16
0
/*
 * Display text from a file in a dialog box.
 */
int
dialog_textbox(const char *title, const char *file, int height, int width)
{
    int i, x, y, cur_x, cur_y, fpos, key = 0;
    int passed_end;
    char search_term[MAX_LEN + 1];
    WINDOW *dialog, *text;

    search_term[0] = '\0';	/* no search term entered yet */

    /* Open input file for reading */
    if ((fd = open(file, O_RDONLY)) == -1) {
	endwin();
	fprintf(stderr, "\nCan't open input file in dialog_textbox().\n");
	exit(-1);
    }
    /* Get file size. Actually, 'file_size' is the real file size - 1,
       since it's only the last byte offset from the beginning */
    if ((file_size = lseek(fd, 0, SEEK_END)) == -1) {
	endwin();
	fprintf(stderr, "\nError getting file size in dialog_textbox().\n");
	exit(-1);
    }
    /* Restore file pointer to beginning of file after getting file size */
    if (lseek(fd, 0, SEEK_SET) == -1) {
	endwin();
	fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
	exit(-1);
    }
    /* Allocate space for read buffer */
    if ((buf = malloc(BUF_SIZE + 1)) == NULL) {
	endwin();
	fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n");
	exit(-1);
    }
    if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
	endwin();
	fprintf(stderr, "\nError reading file in dialog_textbox().\n");
	exit(-1);
    }
    buf[bytes_read] = '\0';	/* mark end of valid data */
    page = buf;			/* page is pointer to start of page to be displayed */

    /* center dialog box on screen */
    x = (COLS - width) / 2;
    y = (LINES - height) / 2;


    draw_shadow(stdscr, y, x, height, width);

    dialog = newwin(height, width, y, x);
    keypad(dialog, TRUE);

    /* Create window for text region, used for scrolling text */
    text = subwin(dialog, height - 4, width - 2, y + 1, x + 1);
    wattrset(text, dialog_attr);
    wbkgdset(text, dialog_attr & A_COLOR);

    keypad(text, TRUE);

    /* register the new window, along with its borders */
    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);

    wattrset(dialog, border_attr);
    mvwaddch(dialog, height - 3, 0, ACS_LTEE);
    for (i = 0; i < width - 2; i++)
	waddch(dialog, ACS_HLINE);
    wattrset(dialog, dialog_attr);
    wbkgdset(dialog, dialog_attr & A_COLOR);
    waddch(dialog, ACS_RTEE);

    if (title != NULL && strlen(title) >= width - 2) {
	/* truncate long title -- mec */
	char *title2 = malloc(width - 2 + 1);
	memcpy(title2, title, width - 2);
	title2[width - 2] = '\0';
	title = title2;
    }

    if (title != NULL) {
	wattrset(dialog, title_attr);
	mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
	waddstr(dialog, (char *) title);
	waddch(dialog, ' ');
    }
    print_button(dialog, " Exit ", height - 2, width / 2 - 4, TRUE);
    wnoutrefresh(dialog);
    getyx(dialog, cur_y, cur_x);	/* Save cursor position */

    /* Print first page of text */
    attr_clear(text, height - 4, width - 2, dialog_attr);
    print_page(text, height - 4, width - 2);
    print_position(dialog, height, width);
    wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
    wrefresh(dialog);

    while ((key != ESC) && (key != '\n')) {
	key = wgetch(dialog);
	switch (key) {
	case 'E':		/* Exit */
	case 'e':
	case 'X':
	case 'x':
	    delwin(dialog);
	    free(buf);
	    close(fd);
	    return 0;
	case 'g':		/* First page */
	case KEY_HOME:
	    if (!begin_reached) {
		begin_reached = 1;
		/* First page not in buffer? */
		if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
		    endwin();
		    fprintf(stderr,
			    "\nError moving file pointer in dialog_textbox().\n");
		    exit(-1);
		}
		if (fpos > bytes_read) {	/* Yes, we have to read it in */
		    if (lseek(fd, 0, SEEK_SET) == -1) {
			endwin();
			fprintf(stderr, "\nError moving file pointer in "
				"dialog_textbox().\n");
			exit(-1);
		    }
		    if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
			endwin();
			fprintf(stderr,
				"\nError reading file in dialog_textbox().\n");
			exit(-1);
		    }
		    buf[bytes_read] = '\0';
		}
		page = buf;
		print_page(text, height - 4, width - 2);
		print_position(dialog, height, width);
		wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
		wrefresh(dialog);
	    }
	    break;
	case 'G':		/* Last page */
	case KEY_END:

	    end_reached = 1;
	    /* Last page not in buffer? */
	    if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
		endwin();
		fprintf(stderr,
			"\nError moving file pointer in dialog_textbox().\n");
		exit(-1);
	    }
	    if (fpos < file_size) {	/* Yes, we have to read it in */
		if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) {
		    endwin();
		    fprintf(stderr,
			    "\nError moving file pointer in dialog_textbox().\n");
		    exit(-1);
		}
		if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
		    endwin();
		    fprintf(stderr,
			    "\nError reading file in dialog_textbox().\n");
		    exit(-1);
		}
		buf[bytes_read] = '\0';
	    }
	    page = buf + bytes_read;
	    back_lines(height - 4);
	    print_page(text, height - 4, width - 2);
	    print_position(dialog, height, width);
	    wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
	    wrefresh(dialog);
	    break;
	case 'K':		/* Previous line */
	case 'k':
	case KEY_UP:
	    if (!begin_reached) {
		back_lines(page_length + 1);

		/* We don't call print_page() here but use scrolling to ensure
		   faster screen update. However, 'end_reached' and
		   'page_length' should still be updated, and 'page' should
		   point to start of next page. This is done by calling
		   get_line() in the following 'for' loop. */
		scrollok(text, TRUE);
		wscrl(text, -1);	/* Scroll text region down one line */
		scrollok(text, FALSE);
		page_length = 0;
		passed_end = 0;
		for (i = 0; i < height - 4; i++) {
		    if (!i) {
			/* print first line of page */
			print_line(text, 0, width - 2);
			wnoutrefresh(text);
		    } else
			/* Called to update 'end_reached' and 'page' */
			get_line();
		    if (!passed_end)
			page_length++;
		    if (end_reached && !passed_end)
			passed_end = 1;
		}

		print_position(dialog, height, width);
		wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
		wrefresh(dialog);
	    }
	    break;
	case 'B':		/* Previous page */
	case 'b':
	case KEY_PPAGE:
	    if (begin_reached)
		break;
	    back_lines(page_length + height - 4);
	    print_page(text, height - 4, width - 2);
	    print_position(dialog, height, width);
	    wmove(dialog, cur_y, cur_x);
	    wrefresh(dialog);
	    break;
	case 'J':		/* Next line */
	case 'j':
	case KEY_DOWN:
	    if (!end_reached) {
		begin_reached = 0;
		scrollok(text, TRUE);
		scroll(text);	/* Scroll text region up one line */
		scrollok(text, FALSE);
		print_line(text, height - 5, width - 2);
		wnoutrefresh(text);
		print_position(dialog, height, width);
		wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
		wrefresh(dialog);
	    }
	    break;
	case KEY_NPAGE:	/* Next page */
	case ' ':
	    if (end_reached)
		break;

	    begin_reached = 0;
	    print_page(text, height - 4, width - 2);
	    print_position(dialog, height, width);
	    wmove(dialog, cur_y, cur_x);
	    wrefresh(dialog);
	    break;
	case '0':		/* Beginning of line */
	case 'H':		/* Scroll left */
	case 'h':
	case KEY_LEFT:
	    if (hscroll <= 0)
		break;

	    if (key == '0')
		hscroll = 0;
	    else
		hscroll--;
	    /* Reprint current page to scroll horizontally */
	    back_lines(page_length);
	    print_page(text, height - 4, width - 2);
	    wmove(dialog, cur_y, cur_x);
	    wrefresh(dialog);
	    break;
	case 'L':		/* Scroll right */
	case 'l':
	case KEY_RIGHT:
	    if (hscroll >= MAX_LEN)
		break;
	    hscroll++;
	    /* Reprint current page to scroll horizontally */
	    back_lines(page_length);
	    print_page(text, height - 4, width - 2);
	    wmove(dialog, cur_y, cur_x);
	    wrefresh(dialog);
	    break;
	case ESC:
	    break;
	}
    }

    delwin(dialog);
    free(buf);
    close(fd);
    return -1;			/* ESC pressed */
}
Example #17
0
void printothpentry(struct othptable *table, struct othptabent *entry,
		    unsigned int target_row, int logging, FILE * logfile)
{
	char protname[SHORTSTRING_MAX];
	char description[SHORTSTRING_MAX];
	char additional[MSGSTRING_MAX];
	char msgstring[MSGSTRING_MAX];
	char scratchpad[MSGSTRING_MAX];
	char *startstr;

	char *packet_type;

	struct in_addr uninitialized_var(saddr);

	char rarp_mac_addr[18];

	unsigned int unknown = 0;

	struct protoent *protptr;

	wmove(table->borderwin, table->obmaxy - 1, 1);
	if ((table->lastvisible == table->tail) && (table->htstat != TIND)
	    && (table->count >= table->oimaxy)) {
		wprintw(table->borderwin, " Bottom ");
		table->htstat = TIND;
	} else if ((table->firstvisible == table->head)
		   && (table->htstat != HIND)) {
		wprintw(table->borderwin, " Top ");
		table->htstat = HIND;
	}
	if (!(entry->is_ip)) {
		wmove(table->othpwin, target_row, 0);
		scrollok(table->othpwin, 0);
		wattrset(table->othpwin, UNKNATTR);
		wprintw(table->othpwin, "%*c", COLS - 2, ' ');
		scrollok(table->othpwin, 1);
		wmove(table->othpwin, target_row, 1);

		switch (entry->protocol) {
		case ETH_P_ARP:
			sprintf(msgstring, "ARP ");
			switch (ntohs(entry->un.arp.opcode)) {
			case ARPOP_REQUEST:
				strcat(msgstring, "request for ");
				memcpy(&(saddr.s_addr),
				       entry->un.arp.dest_ip_address, 4);
				break;
			case ARPOP_REPLY:
				strcat(msgstring, "reply from ");
				memcpy(&(saddr.s_addr),
				       entry->un.arp.src_ip_address, 4);
				break;
			}

			inet_ntop(AF_INET, &saddr, scratchpad, sizeof(scratchpad));
			strcat(msgstring, scratchpad);
			wattrset(table->othpwin, ARPATTR);
			break;
		case ETH_P_RARP:
			sprintf(msgstring, "RARP ");
			memset(rarp_mac_addr, 0, sizeof(rarp_mac_addr));
			switch (ntohs(entry->un.rarp.opcode)) {
			case ARPOP_RREQUEST:
				strcat(msgstring, "request for ");
				convmacaddr(entry->un.rarp.dest_mac_address,
					    rarp_mac_addr);
				break;
			case ARPOP_RREPLY:
				strcat(msgstring, "reply from ");
				convmacaddr(entry->un.rarp.src_mac_address,
					    rarp_mac_addr);
				break;
			}

			sprintf(scratchpad, "%s", rarp_mac_addr);
			strcat(msgstring, scratchpad);
			wattrset(table->othpwin, ARPATTR);
			break;
		default:
			packet_type = packetlookup(entry->protocol);
			if (packet_type == NULL)
				sprintf(msgstring, "Non-IP (0x%x)",
					entry->protocol);
			else
				sprintf(msgstring, "Non-IP (%s)", packet_type);

			wattrset(table->othpwin, UNKNATTR);
		}

		strcpy(protname, msgstring);
		sprintf(scratchpad, " (%u bytes)", entry->pkt_length);
		strcat(msgstring, scratchpad);

		if ((entry->linkproto == ARPHRD_ETHER)
		    || (entry->linkproto == ARPHRD_FDDI)) {
			sprintf(scratchpad, " from %s to %s on %s",
				entry->smacaddr, entry->dmacaddr, entry->iface);

			strcat(msgstring, scratchpad);
		}
		startstr = msgstring + table->strindex;
		waddnstr(table->othpwin, startstr, COLS - 4);
		writeothplog(logging, logfile, protname, "", "", 0, 0, entry);
		return;
	}
	strcpy(additional, "");
	strcpy(description, "");

	switch (entry->protocol) {
	case IPPROTO_UDP:
		wattrset(table->othpwin, UDPATTR);
		strcpy(protname, "UDP");
		break;
	case IPPROTO_ICMP:
		wattrset(table->othpwin, STDATTR);
		strcpy(protname, "ICMP");
		break;
	case IPPROTO_OSPFIGP:
		wattrset(table->othpwin, OSPFATTR);
		strcpy(protname, "OSPF");
		break;
	case IPPROTO_IGP:
		wattrset(table->othpwin, IGPATTR);
		strcpy(protname, "IGP");
		break;
	case IPPROTO_IGMP:
		wattrset(table->othpwin, IGMPATTR);
		strcpy(protname, "IGMP");
		break;
	case IPPROTO_IGRP:
		wattrset(table->othpwin, IGRPATTR);
		strcpy(protname, "IGRP");
		break;
	case IPPROTO_GRE:
		wattrset(table->othpwin, GREATTR);
		strcpy(protname, "GRE");
		break;
	case IPPROTO_ICMPV6:
		wattrset(table->othpwin, ICMPV6ATTR);
		strcpy(protname, "ICMPv6");
		break;
	case IPPROTO_IPV6:
		wattrset(table->othpwin, IPV6ATTR);
		strcpy(protname, "IPv6 tun");
		break;
	default:
		wattrset(table->othpwin, UNKNIPATTR);
		protptr = getprotobynumber(entry->protocol);
		if (protptr != NULL) {
			sprintf(protname, "%s", protptr->p_aliases[0]);
		} else {
			sprintf(protname, "IP protocol");
			unknown = 1;
		}
	}

	if (!(entry->fragment)) {
		if (entry->protocol == IPPROTO_ICMP) {
			switch (entry->un.icmp.type) {
			case ICMP_ECHOREPLY:
				strcpy(description, "echo rply");
				break;
			case ICMP_ECHO:
				strcpy(description, "echo req");
				break;
			case ICMP_DEST_UNREACH:
				strcpy(description, "dest unrch");
				switch (entry->un.icmp.code) {
				case ICMP_NET_UNREACH:
					strcpy(additional, "ntwk");
					break;
				case ICMP_HOST_UNREACH:
					strcpy(additional, "host");
					break;
				case ICMP_PROT_UNREACH:
					strcpy(additional, "proto");
					break;
				case ICMP_PORT_UNREACH:
					strcpy(additional, "port");
					break;
				case ICMP_FRAG_NEEDED:
					strcpy(additional, "DF set");
					break;
				case ICMP_SR_FAILED:
					strcpy(additional, "src rte fail");
					break;
				case ICMP_NET_UNKNOWN:
					strcpy(additional, "net unkn");
					break;
				case ICMP_HOST_UNKNOWN:
					strcpy(additional, "host unkn");
					break;
				case ICMP_HOST_ISOLATED:
					strcpy(additional, "src isltd");
					break;
				case ICMP_NET_ANO:
					strcpy(additional, "net comm denied");
					break;
				case ICMP_HOST_ANO:
					strcpy(additional, "host comm denied");
					break;
				case ICMP_NET_UNR_TOS:
					strcpy(additional, "net unrch for TOS");
					break;
				case ICMP_HOST_UNR_TOS:
					strcpy(additional,
					       "host unrch for TOS");
					break;
				case ICMP_PKT_FILTERED:
					strcpy(additional, "pkt fltrd");
					break;
				case ICMP_PREC_VIOLATION:
					strcpy(additional, "prec violtn");
					break;
				case ICMP_PREC_CUTOFF:
					strcpy(additional, "prec cutoff");
					break;
				}

				break;
			case ICMP_SOURCE_QUENCH:
				strcpy(description, "src qnch");
				break;
			case ICMP_REDIRECT:
				strcpy(description, "redirct");
				break;
			case ICMP_TIME_EXCEEDED:
				strcpy(description, "time excd");
				break;
			case ICMP_PARAMETERPROB:
				strcpy(description, "param prob");
				break;
			case ICMP_TIMESTAMP:
				strcpy(description, "timestmp req");
				break;
			case ICMP_INFO_REQUEST:
				strcpy(description, "info req");
				break;
			case ICMP_INFO_REPLY:
				strcpy(description, "info rep");
				break;
			case ICMP_ADDRESS:
				strcpy(description, "addr mask req");
				break;
			case ICMP_ADDRESSREPLY:
				strcpy(description, "addr mask rep");
				break;
			default:
				strcpy(description, "bad/unkn");
				break;
			}
		} else if (entry->protocol == IPPROTO_ICMPV6) {
			switch (entry->un.icmp6.type) {
			case ICMP6_DST_UNREACH:
				strcpy(description, "dest unrch");
				switch (entry->un.icmp6.code) {
				case ICMP6_DST_UNREACH_NOROUTE:
					strcpy(additional, "no route");
					break;
				case ICMP6_DST_UNREACH_ADMIN:
					strcpy(additional, "admin");
					break;
#ifdef ICMP6_DST_UNREACH_NOTNEIGHBOR
				case ICMP6_DST_UNREACH_NOTNEIGHBOR:
					strcpy(additional, "not neigh");
#else
				case ICMP6_DST_UNREACH_BEYONDSCOPE:
					strcpy(additional, "not beyondsp");
#endif
					break;
				case ICMP6_DST_UNREACH_ADDR:
					strcpy(additional, "unreach addr");
					break;
				case ICMP6_DST_UNREACH_NOPORT:
					strcpy(additional, "no port");
					break;
				}
				break;
			case ICMP6_PACKET_TOO_BIG:
				strcpy(description, "pkt too big");
				break;
			case ICMP6_TIME_EXCEEDED:
				strcpy(description, "time exceeded");
				break;
			case ICMP6_PARAM_PROB:
				strcpy(description, "param prob");
				break;
			case ICMP6_ECHO_REQUEST:
				strcpy(description, "echo req");
				break;
			case ICMP6_ECHO_REPLY:
				strcpy(description, "echo rply");
				break;
			case ND_ROUTER_SOLICIT:
				strcpy(description, "router sol");
				break;
			case ND_ROUTER_ADVERT:
				strcpy(description, "router adv");
				break;
#ifdef ICMP6_MEMBERSHIP_QUERY
			case ICMP6_MEMBERSHIP_QUERY:
				strcpy(description, "mbrship query");
				break;
#endif
#ifdef ICMP6_MEMBERSHIP_REPORT
			case ICMP6_MEMBERSHIP_REPORT:
				strcpy(description, "mbrship report");
				break;
#endif
#ifdef ICMP6_MEMBERSHIP_REDUCTION
			case ICMP6_MEMBERSHIP_REDUCTION:
				strcpy(description, "mbrship reduc");
				break;
#endif
			case ND_NEIGHBOR_SOLICIT:
				strcpy(description, "neigh sol");
				break;
			case ND_NEIGHBOR_ADVERT:
				strcpy(description, "neigh adv");
				break;
			case ND_REDIRECT:
				strcpy(description, "redirect");
				break;
			default:
				strcpy(description, "bad/unkn");
				break;
			}
		} else if (entry->protocol == IPPROTO_OSPFIGP) {
			switch (entry->un.ospf.type) {
			case OSPF_TYPE_HELLO:
				strcpy(description, "hlo");
				break;
			case OSPF_TYPE_DB:
				strcpy(description, "DB desc");
				break;
			case OSPF_TYPE_LSR:
				strcpy(description, "LSR");
				break;
			case OSPF_TYPE_LSU:
				strcpy(description, "LSU");
				break;
			case OSPF_TYPE_LSA:
				strcpy(description, "LSA");
				break;
			}
			sprintf(additional, "a=%lu r=%s", entry->un.ospf.area,
				entry->un.ospf.routerid);
		}
	} else
		strcpy(description, "fragment");

	strcpy(msgstring, protname);
	strcat(msgstring, " ");

	if (strcmp(description, "") != 0) {
		strcat(msgstring, description);
		strcat(msgstring, " ");
	}
	if (strcmp(additional, "") != 0) {
		sprintf(scratchpad, "(%s) ", additional);
		strcat(msgstring, scratchpad);
	}
	if (unknown) {
		sprintf(scratchpad, "%u ", entry->protocol);
		strcat(msgstring, scratchpad);
	}
	sprintf(scratchpad, "(%u bytes) ", entry->pkt_length);
	strcat(msgstring, scratchpad);

	if ((entry->protocol == IPPROTO_UDP) && (!(entry->fragment))) {
		sprintf(scratchpad, "from %.40s:%s to %.40s:%s", entry->s_fqdn,
			entry->un.udp.s_sname, entry->d_fqdn,
			entry->un.udp.d_sname);
	} else {
		sprintf(scratchpad, "from %.40s to %.40s", entry->s_fqdn,
			entry->d_fqdn);
	}

	strcat(msgstring, scratchpad);

	if (((entry->smacaddr)[0] != '\0') && options.mac) {
		snprintf(scratchpad, MSGSTRING_MAX, " (src HWaddr %s)",
			 entry->smacaddr);
		strcat(msgstring, scratchpad);
	}
	strcat(msgstring, " on ");
	strcat(msgstring, entry->iface);

	scrollok(table->othpwin, 0);
	mvwprintw(table->othpwin, target_row, 0, "%*c", COLS - 2, ' ');
	scrollok(table->othpwin, 1);
	wmove(table->othpwin, target_row, 1);
	startstr = msgstring + table->strindex;
	waddnstr(table->othpwin, startstr, COLS - 4);

	if (logging)
		writeothplog(logging, logfile, protname, description,
			     additional, 1, options.mac, entry);
}
Example #18
0
/*
 * Display a dialog box with two buttons - Yes and No
 */
int dialog_yesno(const char *title, const char *prompt, int height, int width)
{
	int i, x, y, key = 0, button = 0;
	WINDOW *dialog;

	/* center dialog box on screen */
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
	wattrset(dialog, border_attr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dialog_attr);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	wattrset(dialog, dialog_attr);
	print_autowrap(dialog, prompt, width - 2, 1, 3);

	print_buttons(dialog, height, width, 0);

	while (key != ESC) {
		key = wgetch(dialog);
		switch (key) {
		case 'Y':
		case 'y':
			delwin(dialog);
			return 0;
		case 'N':
		case 'n':
			delwin(dialog);
			return 1;

		case TAB:
		case KEY_LEFT:
		case KEY_RIGHT:
			button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);

			print_buttons(dialog, height, width, button);
			wrefresh(dialog);
			break;
		case ' ':
		case '\n':
			delwin(dialog);
			return button;
		case ESC:
			break;
		}
	}

	delwin(dialog);
	return -1;		/* ESC pressed */
}
Example #19
0
void color_msg(WINDOW *win, string message)
{

	char buffer[255];
	char *tmp;
	size_t found;

	time_t rawtime;
	struct tm *tm;
	time ( &rawtime );
	tm = localtime ( &rawtime );

	strncpy(buffer, message.c_str(), 255);

	// Print time
	tmp = buffer;
	found = message.find(" ");
	buffer[found] = '\0';

	wattrset(win, A_DIM | COLOR_PAIR(8));
	wprintw(win, "%s ", tmp);

	// Print type
	++found;
	tmp = &buffer[found];
	found = message.find("]", found);
	++found;
	buffer[found] = '\0';

	wattrset(win, A_BOLD|COLOR_PAIR(5));
	wprintw(win, "%s ", tmp);

	// Print command
	++found;
	tmp = &buffer[found];
	found = message.find(" ", found);
	buffer[found] = '\0';

	wattrset(win, A_BOLD|COLOR_PAIR(4));
	wprintw(win, "%s ", tmp);

	// Print rest of command
	++found;
	tmp = &buffer[found];
	found = message.find("[", found);
	--found;
	buffer[found] = '\0';

	wattrset(win, A_BOLD | COLOR_PAIR(8));
	wprintw(win, "%s ", tmp);

	// Print action
	++found;
	tmp = &buffer[found];
	found = message.find("]", found);
	++found;
	buffer[found] = '\0';

	wattrset(win, A_BOLD|COLOR_PAIR(5));
	wprintw(win, "%s ", tmp);

	// Print username
	++found;
	tmp = &buffer[found];
	found = message.find(" ", found);
	buffer[found] = '\0';

	wattrset(win, A_BOLD|COLOR_PAIR(10));
	wprintw(win, "%s ", tmp);

	// Print ID
	++found;
	tmp = &buffer[found];
	wattrset(win, A_BOLD|COLOR_PAIR(2));
	wprintw(win, "%s ", tmp);

	wprintw(win, "\n\n");

}
Example #20
0
/*
 * Display a dialog box with a list of options that can be turned on or off
 * in the style of radiolist (only one option turned on at a time).
 */
int dialog_checklist(const char *title, const char *prompt, int height,
                     int width, int list_height)
{
    int i, x, y, box_x, box_y;

    int key = 0, button = 0, choice = 0, scroll = 0, max_choice;

    WINDOW *dialog, *list;

    /*
     * which item to highlight
     */
    item_foreach() {
        if (item_is_tag('X'))
            choice = item_n();
        if (item_is_selected()) {
            choice = item_n();
            break;
        }
    }

do_resize:
    if (getmaxy(stdscr) < (height + 6))
        return -ERRDISPLAYTOOSMALL;
    if (getmaxx(stdscr) < (width + 6))
        return -ERRDISPLAYTOOSMALL;

    max_choice = MIN(list_height, item_count());

    /*
     * center dialog box on screen
     */
    x = (COLS - width) / 2;
    y = (LINES - height) / 2;

    draw_shadow(stdscr, y, x, height, width);

    dialog = newwin(height, width, y, x);
    keypad(dialog, TRUE);

    draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr);
    wattrset(dialog, dlg.border.atr);
    mvwaddch(dialog, height - 3, 0, ACS_LTEE);
    for (i = 0; i < width - 2; i++)
        waddch(dialog, ACS_HLINE);
    wattrset(dialog, dlg.dialog.atr);
    waddch(dialog, ACS_RTEE);

    print_title(dialog, title, width);

    wattrset(dialog, dlg.dialog.atr);
    print_autowrap(dialog, prompt, width - 2, 1, 3);

    list_width = width - 6;
    box_y = height - list_height - 5;
    box_x = (width - list_width) / 2 - 1;

    /*
     * create new window for the list
     */
    list = subwin(dialog, list_height, list_width, y + box_y + 1,
                  x + box_x + 1);

    keypad(list, TRUE);

    /*
     * draw a box around the list items
     */
    draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
             dlg.menubox_border.atr, dlg.menubox.atr);

    /*
     * Find length of longest item in order to center checklist
     */
    check_x = 0;
    item_foreach()
    check_x = MAX(check_x, strlen(item_str()) + 4);

    check_x = (list_width - check_x) / 2;
    item_x = check_x + 4;

    if (choice >= list_height) {
        scroll = choice - list_height + 1;
        choice -= scroll;
    }

    /*
     * Print the list
     */
    for (i = 0; i < max_choice; i++) {
        item_set(scroll + i);
        print_item(list, i, i == choice);
    }

    print_arrows(dialog, choice, item_count(), scroll,
                 box_y, box_x + check_x + 5, list_height);

    print_buttons(dialog, height, width, 0);

    wnoutrefresh(dialog);
    wnoutrefresh(list);
    doupdate();

    while (key != KEY_ESC) {
        key = wgetch(dialog);

        for (i = 0; i < max_choice; i++) {
            item_set(i + scroll);
            if (toupper(key) == toupper(item_str()[0]))
                break;
        }

        if (i < max_choice || key == KEY_UP || key == KEY_DOWN ||
                key == '+' || key == '-') {
            if (key == KEY_UP || key == '-') {
                if (!choice) {
                    if (!scroll)
                        continue;
                    /*
                     * Scroll list down
                     */
                    if (list_height > 1) {
                        /*
                         * De-highlight current first item
                         */
                        item_set(scroll);
                        print_item(list, 0, FALSE);
                        scrollok(list, TRUE);
                        wscrl(list, -1);
                        scrollok(list, FALSE);
                    }
                    scroll--;
                    item_set(scroll);
                    print_item(list, 0, TRUE);
                    print_arrows(dialog, choice, item_count(),
                                 scroll, box_y, box_x + check_x + 5,
                                 list_height);

                    wnoutrefresh(dialog);
                    wrefresh(list);

                    continue;   /* wait for another key press */
                } else
                    i = choice - 1;
            } else if (key == KEY_DOWN || key == '+') {
                if (choice == max_choice - 1) {
                    if (scroll + choice >= item_count() - 1)
                        continue;
                    /*
                     * Scroll list up
                     */
                    if (list_height > 1) {
                        /*
                         * De-highlight current last item before scrolling up
                         */
                        item_set(scroll + max_choice - 1);
                        print_item(list, max_choice - 1, FALSE);
                        scrollok(list, TRUE);
                        wscrl(list, 1);
                        scrollok(list, FALSE);
                    }
                    scroll++;
                    item_set(scroll + max_choice - 1);
                    print_item(list, max_choice - 1, TRUE);

                    print_arrows(dialog, choice, item_count(),
                                 scroll, box_y, box_x + check_x + 5,
                                 list_height);

                    wnoutrefresh(dialog);
                    wrefresh(list);

                    continue;   /* wait for another key press */
                } else
                    i = choice + 1;
            }
            if (i != choice) {
                /*
                 * De-highlight current item
                 */
                item_set(scroll + choice);
                print_item(list, choice, FALSE);
                /*
                 * Highlight new item
                 */
                choice = i;
                item_set(scroll + choice);
                print_item(list, choice, TRUE);
                wnoutrefresh(dialog);
                wrefresh(list);
            }
            continue;           /* wait for another key press */
        }
        switch (key) {
        case 'H':
        case 'h':
        case '?':
            button = 1;
        /*
         * fall-through
         */
        case 'S':
        case 's':
        case ' ':
        case '\n':
            item_foreach()
            item_set_selected(0);
            item_set(scroll + choice);
            item_set_selected(1);
            delwin(list);
            delwin(dialog);
            return button;
        case TAB:
        case KEY_LEFT:
        case KEY_RIGHT:
            button = ((key == KEY_LEFT ? --button : ++button) < 0)
                     ? 1 : (button > 1 ? 0 : button);

            print_buttons(dialog, height, width, button);
            wrefresh(dialog);
            break;
        case 'X':
        case 'x':
            key = KEY_ESC;
            break;
        case KEY_ESC:
            key = on_key_esc(dialog);
            break;
        case KEY_RESIZE:
            delwin(list);
            delwin(dialog);
            on_key_resize();
            goto do_resize;
        }

        /*
         * Now, update everything...
         */
        doupdate();
    }
    delwin(list);
    delwin(dialog);
    return key;                 /* ESC pressed */
}
Example #21
0
/* layman's scrollable window... */
void show_scroll_win(WINDOW *main_window,
		const char *title,
		const char *text)
{
	int res;
	int total_lines = get_line_no(text);
	int x, y;
	int start_x = 0, start_y = 0;
	int text_lines = 0, text_cols = 0;
	int total_cols = 0;
	int win_cols = 0;
	int win_lines = 0;
	int i = 0;
	WINDOW *win;
	WINDOW *pad;
	PANEL *panel;

	/* find the widest line of msg: */
	total_lines = get_line_no(text);
	for (i = 0; i < total_lines; i++) {
		const char *line = get_line(text, i);
		int len = get_line_length(line);
		total_cols = max(total_cols, len+2);
	}

	/* create the pad */
	pad = newpad(total_lines+10, total_cols+10);
	(void) wattrset(pad, attributes[SCROLLWIN_TEXT]);
	fill_window(pad, text);

	win_lines = min(total_lines+4, LINES-2);
	win_cols = min(total_cols+2, COLS-2);
	text_lines = max(win_lines-4, 0);
	text_cols = max(win_cols-2, 0);

	/* place window in middle of screen */
	y = (LINES-win_lines)/2;
	x = (COLS-win_cols)/2;

	win = newwin(win_lines, win_cols, y, x);
	keypad(win, TRUE);
	/* show the help in the help window, and show the help panel */
	(void) wattrset(win, attributes[SCROLLWIN_BOX]);
	box(win, 0, 0);
	(void) wattrset(win, attributes[SCROLLWIN_HEADING]);
	mvwprintw(win, 0, 3, " %s ", title);
	panel = new_panel(win);

	/* handle scrolling */
	do {

		copywin(pad, win, start_y, start_x, 2, 2, text_lines,
				text_cols, 0);
		print_in_middle(win,
				text_lines+2,
				0,
				text_cols,
				"<OK>",
				attributes[DIALOG_MENU_FORE]);
		wrefresh(win);

		res = wgetch(win);
		switch (res) {
		case KEY_NPAGE:
		case ' ':
		case 'd':
			start_y += text_lines-2;
			break;
		case KEY_PPAGE:
		case 'u':
			start_y -= text_lines+2;
			break;
		case KEY_HOME:
			start_y = 0;
			break;
		case KEY_END:
			start_y = total_lines-text_lines;
			break;
		case KEY_DOWN:
		case 'j':
			start_y++;
			break;
		case KEY_UP:
		case 'k':
			start_y--;
			break;
		case KEY_LEFT:
		case 'h':
			start_x--;
			break;
		case KEY_RIGHT:
		case 'l':
			start_x++;
			break;
		}
		if (res == 10 || res == 27 || res == 'q' ||
			res == KEY_F(F_HELP) || res == KEY_F(F_BACK) ||
			res == KEY_F(F_EXIT))
			break;
		if (start_y < 0)
			start_y = 0;
		if (start_y >= total_lines-text_lines)
			start_y = total_lines-text_lines;
		if (start_x < 0)
			start_x = 0;
		if (start_x >= total_cols-text_cols)
			start_x = total_cols-text_cols;
	} while (res);

	del_panel(panel);
	delwin(win);
	refresh_all_windows(main_window);
}
Example #22
0
void
handle_loopback (struct deviceinfo *unit, struct digi_node *node, struct digi_chan *chan, int port)
{
	char full_line[81];

	int i = 0, option = EOF;

	struct termios sv_tios;
	char test_data[TBUFSIZ + 1];
	char read_data[TBUFSIZ + 1];
	char string[200], ttyname[200];

	int r = 3;
	int rwfd;

	WINDOW *lbwin = GetWin(LBWin);

#define TITLE_LINE  1
#define DESC_LINE   2
#define DESC2_LINE  3
#define SEP_LINE    4
#define FIRST_DATA  5
#define SEP2_LINE   15
#define RESULT_LINE 16

	show_panel (GetPan(LBWin));
	update_panels ();
	doupdate ();

	next_result = 0;
	test_cases = 0;
	test_passes = 0;

	if (DPAGetPortName(unit, node, chan, port, ttyname) == NULL) {
		ttyname[0] ='\0';
	}

	while (option == EOF)
	{
		erase_win (LBWin);
		wattrset (lbwin, make_attr (A_BOLD, WHITE, BLUE));
		mvwprintw (lbwin, TITLE_LINE,  1, "%-*.*s", 76, 76, " ");
		mvwprintw (lbwin, RESULT_LINE, 1, "%-*.*s", 76, 76, " ");
		mvwprintw (lbwin, TITLE_LINE, 32, " Loop Back Test ");
		sprintf (full_line, "Tests Executed: %-12d Passed: %-12d Failed: %d",
		         test_cases, test_passes, test_cases - test_passes);
		mvwprintw (lbwin, RESULT_LINE,
		           center(LBWin, strlen(full_line)), full_line);

		sprintf (clbuf, "Unit IP Address: %s       Port #: %d            Name: %s",
		         unit->host, port + 1, ttyname);
		i = strlen (clbuf);
		mvwprintw (GetWin(LBWin), DESC_LINE, 1, "%*s",
		           GetWidth(LBWin) - 2, " ");

		mvwprintw (GetWin(LBWin), DESC2_LINE, 1, "%*s",
		           GetWidth(LBWin) - 2, " ");

		mvwprintw (lbwin, DESC2_LINE, 2, clbuf);

		mvwprintw (lbwin, DESC_LINE, 2, "Device Description: %-*.*s",
		           GetWidth(LBWin) - 2 - 2 - 2 - 20,
		           GetWidth(LBWin) - 2 - 2 - 2 - 20,
		           node->nd_ps_desc);

		if (!vanilla)
			wattrset (lbwin, make_attr (A_ALTCHARSET, CYAN, BLACK));
		else
			wattrset (lbwin, make_attr (A_NORMAL, CYAN, BLACK));

		wmove (lbwin, SEP_LINE, 1);
		for (i = 0; i < 77; i++)
			waddch (lbwin, mapchar(ACS_HLINE));
		mvwaddch (lbwin, SEP_LINE, 0, mapchar(ACS_LTEE));
		mvwaddch (lbwin, SEP_LINE, 77, mapchar(ACS_RTEE));

		wmove (lbwin, SEP2_LINE, 1);
		for (i = 0; i < 77; i++)
			waddch (lbwin, mapchar(ACS_HLINE));
		mvwaddch (lbwin, SEP2_LINE, 0, mapchar(ACS_LTEE));
		mvwaddch (lbwin, SEP2_LINE, 77, mapchar(ACS_RTEE));

		wattrset (lbwin, make_attr (A_NORMAL, WHITE, BLACK));

		wrefresh (lbwin);

		wattrset (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));
		commandline (clbuf, "Press ANY key to Halt the test", NULL);
		mvwprintw (GetWin(MainWin), KEY_LINE, 0, clbuf);
		wattroff (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));
		wrefresh (GetWin(MainWin));

		change_term (0, 10);

		option = EOF;
		r = 5;

		if (chan->ch_open) {
			mvwprintw (lbwin, r++, 2, "***** Port is Busy.");
                        wrefresh(lbwin);
			test_cases++;
			sleep(1);
			goto user_input;
		}

		for (i = 0; i < 256; i++) {
			test_data[i] = (char) i;
		}

		test_data[TBUFSIZ]='\0';

		/* Get port name.  Can't run the test without it. */
		if (DPAGetPortName(unit, node, chan, port, ttyname) == NULL) {
                        mvwprintw (lbwin, r++, 2,
                        "***** Loop Back Test Failure. Port has no known tty name");
			test_cases++;
                        wrefresh (lbwin);
			sleep(1);
			goto user_input;
                }

		sprintf(string, "/dev/%s", ttyname);

		if( (rwfd = tty_open(string, &sv_tios )) < 0 ) {
			test_cases++;
			goto user_input;
		}

		tcflush(rwfd, TCIOFLUSH);

                if ((i = test_send (test_data, TBUFSIZ, rwfd)) != 0)
                {
                        mvwprintw (lbwin, r++, 2,
                        "***** Loop Back Test Failure=%d, Sending %d Bytes", i, TBUFSIZ);
                        wrefresh (lbwin);
                        tty_close (rwfd, &sv_tios);
                        test_cases++;
			goto user_input;
                }

                mvwprintw (lbwin, r++, 2, "Loop Back: %d Bytes Sent.", TBUFSIZ);
                wrefresh (lbwin);
                mvwprintw (lbwin, r++, 2, "Loop Back: Receiving %d Bytes.", TBUFSIZ);
                wrefresh (lbwin);

                if ((i = test_recv (read_data, TBUFSIZ, 5, rwfd)) != TBUFSIZ)
                {
                        mvwprintw (lbwin, r++, 2,
                                "***** Loop Back Failure=%d Receiving %d bytes.", i, TBUFSIZ);
                        wrefresh (lbwin);
                        tty_close (rwfd, &sv_tios);
                        test_cases++;
			goto user_input;
                }


                /* Reset termios as before and close channel */
                tty_close (rwfd, &sv_tios);

                mvwprintw (lbwin, r++, 2, "Loop Back: Verifying %d bytes.", TBUFSIZ);
                wrefresh (lbwin);

                if (memcmp (test_data, read_data, TBUFSIZ))
                {
                        mvwprintw (lbwin, r++, 2,
                                "***** Loop Back Failure Verifying %d Bytes.", TBUFSIZ);
                        mvwprintw (lbwin, r++, 2, "***** Data Incorrectly Transferred.");
                        wrefresh (lbwin);
                        test_cases++;
			goto user_input;
                }
                else
                {
                        mvwprintw (lbwin, r++, 2, "Loop Back: Test Passed.");
                        wrefresh (lbwin);
                        test_cases++;
                        test_passes++;
                }


user_input:

		option = getch();


		/*
		 * If the user hasn't selected anything, loop.
		 * Otherwise, break.
		 */

		switch (option)
		{
		case EOF:
			break;

		case '':
			refresh_screen ();
			option = EOF;
			break;

#ifdef KEY_PRINT
		case KEY_PRINT:
#endif
		case '':
			screen_save (LBWin, logfile);
			touchwin (lbwin);
			wrefresh (lbwin);
			update_panels ();
			doupdate ();
			option = EOF;
			break;

		default:
			break;
		}						   /* End Case */
	}							   /* End While */

	hide_panel (GetPan(LBWin));
	update_panels ();
	doupdate ();
	return;
}
Example #23
0
void PrintCmosScreen() {

    int i, j;
    char tmp;


        if( ibuf == KEY_UP ) {

            if( x > 0 ) {

                x--;
            }

            input = 0;
        }
        else if( ibuf == KEY_DOWN ) {

            if( x < 15 ) {

                x++;
            }

            input = 0;
        }
        else if( ibuf == KEY_LEFT ) {

            if( y > 0 ) {

                y--;
            }

            input = 0;
        }
        else if( ibuf == KEY_RIGHT ) {

            if( y < 15 ) {

                y++;
            }

            input = 0;
        }
        else if( ibuf == KEY_NPAGE ) {

            if( (0xffffffff - cmos_addr) >= LFDD_MASSBUF_SIZE ) {
        
                cmos_addr += LFDD_MASSBUF_SIZE;
            }
            else {
        
                cmos_addr = 0;
            }

            input = 0;
        }
        else if( ibuf == KEY_PPAGE ) {

            if( cmos_addr >= LFDD_MASSBUF_SIZE ) {
        
                cmos_addr -= LFDD_MASSBUF_SIZE;
            }
            else {
        
                cmos_addr = (0xffffffff - LFDD_MASSBUF_SIZE + 1);
            }

            input = 0;
        }
        else if( ibuf == 0x0a ) {

            if( input ) {

                input = 0;
				WriteCmosByteValue();
            }
        }
        else if ( ((ibuf >= '0') && (ibuf <= '9'))
                || ((ibuf >= 'a') && (ibuf <= 'f'))
                || ((ibuf >= 'A') && (ibuf <= 'F')) ) {

            if( !input ) {

                wbuf = 0x00;
                input = 1;
            }


            wbuf <<= 4;
            wbuf &= 0xf0;


            if( ibuf <= '9' ) {

                wbuf |= ibuf - 0x30;
            }
            else if( ibuf > 'F' ) {

                wbuf |= ibuf - 0x60 + 9;
            }
            else {

                wbuf |= ibuf - 0x40 + 9;
            }
        }


    //
    // Print Offset Text
    //
    PrintFixedWin( CmosScreen, offset, 17, 52, 4, 1, RED_BLUE, "0000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F0000\n0010\n0020\n0030\n0040\n0050\n0060\n0070\n0080\n0090\n00A0\n00B0\n00C0\n00D0\n00E0\n00F0" );


    //
    // Print memory address
    //
    if( !CmosScreen.info ) {

        CmosScreen.info = newwin( 1, 47, 22, 0 );
        CmosScreen.p_info = new_panel( CmosScreen.info );
    }
    wbkgd( CmosScreen.info, COLOR_PAIR( WHITE_BLUE ) );
    wattrset( CmosScreen.info, COLOR_PAIR( WHITE_BLUE ) | A_BOLD );
    mvwprintw( CmosScreen.info, 0, 0, "Type: CMOS" );


    //
    // Read memory space 256 bytes
    //
	ReadCmos256Bytes( lfdd_io_data.mass_buf );


    //
    // Print ASCII content
    //
    if( !CmosScreen.ascii ) {

        CmosScreen.ascii = newwin( 17, 16, 4, 58 );
        CmosScreen.p_ascii = new_panel( CmosScreen.ascii );
    }


    wbkgd( CmosScreen.ascii, COLOR_PAIR( CYAN_BLUE ) );
    wattrset( CmosScreen.ascii, COLOR_PAIR( CYAN_BLUE ) | A_BOLD );
    mvwprintw( CmosScreen.ascii, 0, 0, "" );

    wprintw( CmosScreen.ascii, "0123456789ABCDEF" );
    for( i = 0 ; i < LFDK_BYTE_PER_LINE ; i++ ) {

        for( j = 0 ; j < LFDK_BYTE_PER_LINE ; j++ ) {

            tmp = ((unsigned char)lfdd_io_data.mass_buf[ (i * LFDK_BYTE_PER_LINE) + j ]);
            if( (tmp >= '!') && (tmp <= '~') ) {
            
                wprintw( CmosScreen.ascii, "%c", tmp );
            }
            else {

                wprintw( CmosScreen.ascii, "." ); 
            }
        }
    }

    wattrset( CmosScreen.ascii, A_NORMAL );


    //
    // Print 256bytes content
    //
    if( !CmosScreen.value ) {

        CmosScreen.value = newwin( 17, 47, 5, 6 );
        CmosScreen.p_value = new_panel( CmosScreen.value );
    }


    wbkgd( CmosScreen.value, COLOR_PAIR( WHITE_BLUE ) );
    mvwprintw( CmosScreen.value, 0, 0, "" );


    for( i = 0 ; i < LFDK_BYTE_PER_LINE ; i++ ) {

        for( j = 0 ; j < LFDK_BYTE_PER_LINE ; j++ ) {
    
                
            //
            // Change Color Pair
            //
            if( y == j && x == i ) {
              
                if( input ) {
                
                    if( counter % 2 ) {
                    
                        wattrset( CmosScreen.value, COLOR_PAIR( YELLOW_RED ) | A_BOLD );
                    }
                    else {
                    
                        wattrset( CmosScreen.value, COLOR_PAIR( YELLOW_BLACK ) | A_BOLD );
                    }
                    
                    counter++;
                }
                else {

                    wattrset( CmosScreen.value, COLOR_PAIR( BLACK_YELLOW ) | A_BOLD ); 
                }
            }
            else if( ((unsigned char)lfdd_io_data.mass_buf[ (i * LFDK_BYTE_PER_LINE) + j ]) ) {
           
                wattrset( CmosScreen.value, COLOR_PAIR( YELLOW_BLUE ) | A_BOLD );            
            }
            else {
            
                wattrset( CmosScreen.value, COLOR_PAIR( WHITE_BLUE ) | A_BOLD );
            }


            //
            // Handle input display
            //
            if( y == j && x == i ) {


                if( input ) {
                
                    wprintw( CmosScreen.value, "%2.2X", (unsigned char)wbuf );
                }
                else {
                
                    wprintw( CmosScreen.value, "%2.2X", (unsigned char)lfdd_io_data.mass_buf[ (i * LFDK_BYTE_PER_LINE) + j ] );
                }
            }
            else {

                wprintw( CmosScreen.value, "%2.2X", (unsigned char)lfdd_io_data.mass_buf[ (i * LFDK_BYTE_PER_LINE) + j ] );
            }


            //
            // End of color pair
            //
            wattrset( CmosScreen.value, A_NORMAL );


            //
            // Move to next byte
            //
            if( j != 15 ) {
          
                wprintw( CmosScreen.value, " " );
            }
        }
    }
}
Example #24
0
void Scoreboard::update()
{
  wattrset( mWindow, COLOR_PAIR( INSTRUCTIONS ) );

  int line = 1;

  int red = 0;
  int blue = 0;

  for( std::vector<Plant>::iterator i = getAttr( state )->plants.begin(); i != getAttr( state )->plants.end(); i++ )
  {
    // Count Red Plants
    if( i->ownerID == 0 )
      ++red;
    else
      ++blue;
  }

  setAttr( player1Plants, red );
  setAttr( player2Plants, blue );

  mvwprintw( mWindow, line++, 2, "Turn: %d      ", getAttr( turnNumber ) );

  wattrset( mWindow, COLOR_PAIR( PLAYER_1_COLOR ) );
  mvwprintw( mWindow, line++, 2, "---------------------------" );
  wattron( mWindow, A_BOLD );
  mvwprintw( mWindow, line++, 3, getAttr( player1Name ) );
  wattroff( mWindow, A_BOLD );
  mvwprintw( mWindow, line++, 2, "---------------------------" );
  mvwprintw( mWindow, line++, 3, "Score: %d       ", getAttr( player1Score ) );
  mvwprintw( mWindow, line++, 3, "Light: %d       ", getAttr( player1Light ) );
  mvwprintw( mWindow, line++, 3, "Plants: %d      ", red );


  wattrset( mWindow, COLOR_PAIR( PLAYER_2_COLOR ) );

  line = 9;

  mvwprintw( mWindow, line++, 2, "---------------------------" );
  wattron( mWindow, A_BOLD );
  mvwprintw( mWindow, line++, 3, getAttr( player2Name ) );
  wattroff( mWindow, A_BOLD );
  mvwprintw( mWindow, line++, 2, "---------------------------" );
  mvwprintw( mWindow, line++, 3, "Score: %d       ", getAttr( player2Score ) );
  mvwprintw( mWindow, line++, 3, "Light: %d       ", getAttr( player2Light ) );
  mvwprintw( mWindow, line++, 3, "Plants: %d      ", blue );


  wattrset( mWindow, COLOR_PAIR( INSTRUCTIONS ) );

  line = getAttr( maxY )*2 - 12;

  mvwprintw( mWindow, line++, 3, "Visualizer Usage:" );
  mvwprintw( mWindow, line++, 3, "Q     | Quit" );
  mvwprintw( mWindow, line++, 3, "P     | Pause/Play" );
  mvwprintw( mWindow, line++, 3, "R     | Rewind" );
  mvwprintw( mWindow, line++, 3, "+     | Increase Speed" );
  mvwprintw( mWindow, line++, 3, "-     | Decrease Speed" );
  mvwprintw( mWindow, line++, 3, ">     | Go ahead one frame" );
  mvwprintw( mWindow, line++, 3, "<     | Go back one frame" );
  mvwprintw( mWindow, line++, 3, "E     | Go to last frame" );
  mvwprintw( mWindow, line++, 3, "S     | Go to first frame" );
  mvwprintw( mWindow, line++, 3, "Left  | Move Cursor Left" );
  mvwprintw( mWindow, line++, 3, "Right | Move Cursor Right" );
  mvwprintw( mWindow, line++, 3, "Up    | Move Cursor Up" );
  mvwprintw( mWindow, line++, 3, "Down  | Move Cursor Down" );


  wattroff( mWindow, COLOR_PAIR( 8 ) );

  wrefresh( mWindow );

}
Example #25
0
void setoptions(void)
{
	int row = 1;
	int trow = 1;		/* row for timer submenu */
	int aborted;

	struct MENU menu;
	struct MENU timermenu;

	WINDOW *statwin;
	PANEL *statpanel;

	struct porttab *ports;

	loadaddports(&ports);

	makeoptionmenu(&menu);

	statwin = newwin(15, 35, (LINES - 19) / 2 - 1, (COLS - 40) / 16 + 40);
	statpanel = new_panel(statwin);

	wattrset(statwin, BOXATTR);
	tx_colorwin(statwin);
	tx_box(statwin, ACS_VLINE, ACS_HLINE);
	wmove(statwin, 9, 1);
	whline(statwin, ACS_HLINE, 33);
	mvwprintw(statwin, 0, 1, " Current Settings ");
	wattrset(statwin, STDATTR);
	mvwprintw(statwin, 1, 2, "Reverse DNS lookups:");
	mvwprintw(statwin, 2, 2, "Service names:");
	mvwprintw(statwin, 3, 2, "Promiscuous:");
	mvwprintw(statwin, 4, 2, "Color:");
	mvwprintw(statwin, 5, 2, "Logging:");
	mvwprintw(statwin, 6, 2, "Activity mode:");
	mvwprintw(statwin, 7, 2, "MAC addresses:");
	mvwprintw(statwin, 8, 2, "v6-in-v4 as IPv6:");
	mvwprintw(statwin, 10, 2, "TCP timeout:");
	mvwprintw(statwin, 11, 2, "Log interval:");
	mvwprintw(statwin, 12, 2, "Update interval:");
	mvwprintw(statwin, 13, 2, "Closed/idle persist:");
	showoptions(statwin);

	do {
		tx_showmenu(&menu);
		tx_operatemenu(&menu, &row, &aborted);

		switch (row) {
		case 1:
			options.revlook = ~options.revlook;
			break;
		case 2:
			options.servnames = ~options.servnames;
			break;
		case 3:
			options.promisc = ~options.promisc;
			break;
		case 4:
			options.color = ~options.color;
			break;
		case 5:
			options.logging = ~options.logging;
			break;
		case 6:
			options.actmode = ~options.actmode;
			break;
		case 7:
			options.mac = ~options.mac;
			break;
		case 8:
			options.v6inv4asv6 = ~options.v6inv4asv6;
			break;
		case 10:
			maketimermenu(&timermenu);
			trow = 1;
			do {
				tx_showmenu(&timermenu);
				tx_operatemenu(&timermenu, &trow, &aborted);

				switch (trow) {
				case 1:
					settimeout(&options.timeout,
						   "minutes", DONT_ALLOW_ZERO,
						   &aborted);
					if (!aborted)
						updatetimes(statwin);
					break;
				case 2:
					settimeout(&options.logspan,
						   "minutes", DONT_ALLOW_ZERO,
						   &aborted);
					if (!aborted) {
						options.logspan =
						    options.logspan * 60;
						updatetimes(statwin);
					}
					break;
				case 3:
					settimeout(&options.updrate, "seconds",
						   ALLOW_ZERO, &aborted);
					if (!aborted)
						updatetimes(statwin);
					break;
				case 4:
					settimeout(&options.closedint,
						   "minutes", ALLOW_ZERO,
						   &aborted);
					if (!aborted)
						updatetimes(statwin);
					break;
				}
			} while (trow != 6);

			tx_destroymenu(&timermenu);
			update_panels();
			doupdate();
			break;
		case 12:
			addmoreports(&ports);
			break;
		case 13:
			removeaport(&ports);
			break;
		case 15:
			manage_eth_desc(ARPHRD_ETHER);
			break;
		case 16:
			manage_eth_desc(ARPHRD_FDDI);
			break;
		}

		indicatesetting(row, statwin);
	} while (row != 18);

	destroyporttab(ports);
	tx_destroymenu(&menu);
	del_panel(statpanel);
	delwin(statwin);
	update_panels();
	doupdate();
}
Example #26
0
int
atualizar_jogo(WINDOW * win,corpo ** snake,int sentido)
{
  size_t i;
  int ymax,xmax;

  getmaxyx(win,ymax,xmax);
  werase(win);
  borda(win,_borda_vertical);

  wattrset(win,COLOR_PAIR(COR_DA_COMIDA));
  mvwaddch(win,comida.posy,comida.posx,_formato_da_comida);
  wattroff(win,COLOR_PAIR(COR_DA_COMIDA));

  asteroids(win,snake);  
  
  for(i = 0; i < _tamanho;i++)
    {
      /* Guarda o ultimo sentido seguido por um seguimento da cobra */
      (*snake)[i].psentido = (*snake)[i].sentido;
	
	if(i > 0)
	  (*snake)[i].sentido = (*snake)[i - 1].psentido;
	else (*snake)[0].sentido = sentido;

	switch((*snake)[i].sentido)
	{
	  /*
	    A função batida() vai pegar esse -1 e retornar
	    1 antes que chegue na função mvwaddch() 
	  */
	case UP: if((*snake)[i].posy > -1) (*snake)[i].posy--;
	  break;

	  /*A mesma coisa aqui !*/
	case DOWN:if((*snake)[i].posy < ymax) (*snake)[i].posy++;
	  break;

	case LEFT:	  

	  /*
	    Quando a cobra entra no buraco da esquerda,
	    ela é teletransportada para o da direita
	  */
	  if((*snake)[i].posx == 0 
	     && ((*snake)[i].posy > ymax/2 - (_tamanho_do_buraco/2 + 1) 
		 && (*snake)[i].posy < ymax/2  + _tamanho_do_buraco/2)) 
	    (*snake)[i].posx = xmax - 1;
	  
	  else (*snake)[i].posx--;

	  break;

	case RIGHT: 
	  /* 
	     Quando a cobra entra no buraco da direita,
	     ela é teletransportda para o da esquerda
	  */
	  if((*snake)[i].posx == xmax - 1 
	     && ((*snake)[i].posy > ymax/2 - (_tamanho_do_buraco/2 + 1)  
		 && (*snake)[i].posy < ymax/2  + _tamanho_do_buraco/2)) 
	    (*snake)[i].posx = 0;
	  
	  else (*snake)[i].posx++;
	  
	  break;
	  
	}
	
	/*
	  Para verificar se a cobra bateu em algo,
	  precisamos somente verificar as cordenadas da cabeça dela.	 
	*/
	if( i == 0)
	  {
	    
	    if(batida(win,snake) == 1){
	      _tamanho = 5;
	      _score = 0;

	      *snake = realloc(*snake,sizeof **snake * _tamanho);
	      if(*snake == NULL) err("realloc()");
	      
	      
	      return 1;
	    }
	    
	  }
	
	if(i == 0) wattrset(win,COLOR_PAIR(COR_DO_CRANIO));
	mvwaddch(win,(*snake)[i].posy,(*snake)[i].posx,_formato_do_corpo);
	if( i == 0 ) wattroff(win,COLOR_PAIR(COR_DO_CRANIO));
        
    }

  wrefresh(win);
  return 0;
}
/*
 * Draw the day-of-month selection box
 */
static int
draw_day(BOX * data, struct tm *current)
{
#ifdef ENABLE_NLS
    char *of_week[] =
    {
	nl_langinfo(ABDAY_1),
	nl_langinfo(ABDAY_2),
	nl_langinfo(ABDAY_3),
	nl_langinfo(ABDAY_4),
	nl_langinfo(ABDAY_5),
	nl_langinfo(ABDAY_6),
	nl_langinfo(ABDAY_7)
    };
#else
    static const char *const of_week[] =
    {
	"Sunday",
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday"
    };
#endif
    int cell_wide = MON_WIDE;
    int y, x, this_x = 0;
    int save_y = 0, save_x = 0;
    int day = current->tm_mday;
    int mday;
    int week;
    int last = days_in_month(current, 0);
    int prev = days_in_month(current, -1);

    werase(data->window);
    draw_box(data->parent,
	     data->y - MARGIN, data->x - MARGIN,
	     data->height + (2 * MARGIN), data->width + (2 * MARGIN),
	     border_attr, dialog_attr);

    wattrset(data->window, item_selected_attr);
    for (x = 0; x < 7; x++) {
	mvwprintw(data->window,
		  0, (x + 1) * cell_wide, "%*.*s ",
		  cell_wide - 1,
		  cell_wide - 1,
		  of_week[x]);
    }
    wattrset(data->window, item_attr);

    mday = ((6 + current->tm_mday - current->tm_wday) % 7) - 7;
    if (mday <= -7)
	mday += 7;
    /* mday is now in the range -6 to 0. */
    week = (current->tm_yday + 6 + mday - current->tm_mday) / 7;

    for (y = 1; mday < last; y++) {
	wattrset(data->window, item_selected_attr);
	mvwprintw(data->window,
		  y, 0,
		  "%*d ",
		  cell_wide - 1,
		  ++week);
	for (x = 0; x < 7; x++) {
	    this_x = 1 + (x + 1) * cell_wide;
	    ++mday;
	    if (wmove(data->window, y, this_x) == ERR)
		continue;
	    wattrset(data->window, item_attr);
	    if (mday == day) {
		wattrset(data->window, item_selected_attr);
		save_y = y;
		save_x = this_x;
	    }
	    if (mday > 0) {
		if (mday <= last) {
		    wprintw(data->window, "%*d", cell_wide - 2, mday);
		} else if (mday == day) {
		    wprintw(data->window, "%*d", cell_wide - 2, mday - last);
		}
	    } else if (mday == day) {
		wprintw(data->window, "%*d", cell_wide - 2, mday + prev);
	    }
	    wattrset(data->window, item_attr);
	}
	wmove(data->window, save_y, save_x);
    }
    dlg_draw_arrows(data->parent, TRUE, TRUE,
		    data->x + 5,
		    data->y - 1,
		    data->y + data->height);

    return 0;
}
Example #28
0
list_part_t *search_superblock(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind, const int interface)
{
  unsigned char *buffer=(unsigned char *)MALLOC(2*0x200);
  uint64_t hd_offset;
  int nbr_sb=0;
  list_part_t *list_part=NULL;
  int ind_stop=0;
#ifdef HAVE_NCURSES
  unsigned long int old_percent=0;
#endif
  struct ext2_super_block *sb=(struct ext2_super_block *)buffer;
  partition_t *new_partition=partition_new(disk_car->arch);
  log_trace("search_superblock\n");
#ifdef HAVE_NCURSES
  if(interface>0)
  {
    aff_copy(stdscr);
    wmove(stdscr,4,0);
    wprintw(stdscr,"%s",disk_car->description(disk_car));
    mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
    wmove(stdscr,6,0);
    aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
    wmove(stdscr,22,0);
    wattrset(stdscr, A_REVERSE);
    waddstr(stdscr,"  Stop  ");
    wattroff(stdscr, A_REVERSE);
  }
#endif
  for(hd_offset=0;hd_offset<partition->part_size && nbr_sb<10 && ind_stop==0;hd_offset=next_sb(hd_offset))
  {
#ifdef HAVE_NCURSES
    unsigned long int percent;
    percent=hd_offset*100/partition->part_size;
    if(interface>0 && percent!=old_percent)
    {
      wmove(stdscr,9,0);
      wclrtoeol(stdscr);
      wprintw(stdscr,"Search ext2/ext3/ext4 superblock %10lu/%lu %lu%%", (long unsigned)(hd_offset/disk_car->sector_size),
	  (long unsigned)(partition->part_size/disk_car->sector_size),percent);
      wrefresh(stdscr);
      ind_stop|=check_enter_key_or_s(stdscr);
      old_percent=percent;
    }
#endif
    if(disk_car->pread(disk_car, buffer, 1024, partition->part_offset + hd_offset) == 1024)
    {
      /* ext2/ext3/ext4 */
      if(le16(sb->s_magic)==EXT2_SUPER_MAGIC)
      {
	dup_partition_t(new_partition,partition);
	new_partition->part_offset+=hd_offset;
	if(recover_EXT2(disk_car,sb,new_partition,verbose,dump_ind)==0)
	{
	  int insert_error=0;
	  if(hd_offset<=(EXT2_MIN_BLOCK_SIZE<<2))
	    new_partition->part_offset-=hd_offset;
	  if(partition->blocksize==0)
	  {
	    partition->sborg_offset=new_partition->sborg_offset;
	    partition->sb_offset   =new_partition->sb_offset;
	    partition->sb_size     =new_partition->sb_size;
	    partition->blocksize   =new_partition->blocksize;
	  }
	  log_info("Ext2 superblock found at sector %llu (block=%llu, blocksize=%u)\n",
	      (long long unsigned) hd_offset/DEFAULT_SECTOR_SIZE,
	      (long long unsigned) hd_offset>>(EXT2_MIN_BLOCK_LOG_SIZE+le32(sb->s_log_block_size)),
	      EXT2_MIN_BLOCK_SIZE<<le32(sb->s_log_block_size));
#ifdef HAVE_NCURSES
	  wmove(stdscr,10+nbr_sb,0);
	  wprintw(stdscr,"Ext2 superblock found at sector %llu (block=%llu, blocksize=%u)        \n",
	      (long long unsigned) hd_offset/DEFAULT_SECTOR_SIZE,
	      (long long unsigned) hd_offset>>(EXT2_MIN_BLOCK_LOG_SIZE+le32(sb->s_log_block_size)),
	      EXT2_MIN_BLOCK_SIZE<<le32(sb->s_log_block_size));
#endif
	  list_part=insert_new_partition(list_part, new_partition, 1, &insert_error);
	  new_partition=partition_new(disk_car->arch);
	  nbr_sb++;
	}
      }
    }
Example #29
0
/* get the message, and buttons.
 * each button must be a char*
 * return the selected button
 *
 * this dialog is used for 2 different things:
 * 1) show a text box, no buttons.
 * 2) show a dialog, with horizontal buttons
 */
int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
{
	va_list ap;
	char *btn;
	int btns_width = 0;
	int msg_lines = 0;
	int msg_width = 0;
	int total_width;
	int win_rows = 0;
	WINDOW *win;
	WINDOW *msg_win;
	WINDOW *menu_win;
	MENU *menu;
	ITEM *btns[btn_num+1];
	int i, x, y;
	int res = -1;


	va_start(ap, btn_num);
	for (i = 0; i < btn_num; i++) {
		btn = va_arg(ap, char *);
		btns[i] = new_item(btn, "");
		btns_width += strlen(btn)+1;
	}
	va_end(ap);
	btns[btn_num] = NULL;

	/* find the widest line of msg: */
	msg_lines = get_line_no(msg);
	for (i = 0; i < msg_lines; i++) {
		const char *line = get_line(msg, i);
		int len = get_line_length(line);
		if (msg_width < len)
			msg_width = len;
	}

	total_width = max(msg_width, btns_width);
	/* place dialog in middle of screen */
	y = (getmaxy(stdscr)-(msg_lines+4))/2;
	x = (getmaxx(stdscr)-(total_width+4))/2;


	/* create the windows */
	if (btn_num > 0)
		win_rows = msg_lines+4;
	else
		win_rows = msg_lines+2;

	win = newwin(win_rows, total_width+4, y, x);
	keypad(win, TRUE);
	menu_win = derwin(win, 1, btns_width, win_rows-2,
			1+(total_width+2-btns_width)/2);
	menu = new_menu(btns);
	msg_win = derwin(win, win_rows-2, msg_width, 1,
			1+(total_width+2-msg_width)/2);

	set_menu_fore(menu, attributes[DIALOG_MENU_FORE]);
	set_menu_back(menu, attributes[DIALOG_MENU_BACK]);

	(void) wattrset(win, attributes[DIALOG_BOX]);
	box(win, 0, 0);

	/* print message */
	(void) wattrset(msg_win, attributes[DIALOG_TEXT]);
	fill_window(msg_win, msg);

	set_menu_win(menu, win);
	set_menu_sub(menu, menu_win);
	set_menu_format(menu, 1, btn_num);
	menu_opts_off(menu, O_SHOWDESC);
	menu_opts_off(menu, O_SHOWMATCH);
	menu_opts_on(menu, O_ONEVALUE);
	menu_opts_on(menu, O_NONCYCLIC);
	set_menu_mark(menu, "");
	post_menu(menu);


	touchwin(win);
	refresh_all_windows(main_window);
	while ((res = wgetch(win))) {
		switch (res) {
		case KEY_LEFT:
			menu_driver(menu, REQ_LEFT_ITEM);
			break;
		case KEY_RIGHT:
			menu_driver(menu, REQ_RIGHT_ITEM);
			break;
		case 10: /* ENTER */
		case 27: /* ESCAPE */
		case ' ':
		case KEY_F(F_BACK):
		case KEY_F(F_EXIT):
			break;
		}
		touchwin(win);
		refresh_all_windows(main_window);

		if (res == 10 || res == ' ') {
			res = item_index(current_item(menu));
			break;
		} else if (res == 27 || res == KEY_F(F_BACK) ||
				res == KEY_F(F_EXIT)) {
			res = KEY_EXIT;
			break;
		}
	}

	unpost_menu(menu);
	free_menu(menu);
	for (i = 0; i < btn_num; i++)
		free_item(btns[i]);

	delwin(win);
	return res;
}
Example #30
0
/*
 * Draw the day-of-month selection box
 */
static int
draw_day(BOX * data, struct tm *current)
{
    int cell_wide = MON_WIDE;
    int y, x, this_x = 0;
    int save_y = 0, save_x = 0;
    int day = current->tm_mday;
    int mday;
    int week;
    int last = days_in_month(current, 0);
    int prev = days_in_month(current, -1);

    werase(data->window);
    dlg_draw_box(data->parent,
		 data->y - MARGIN, data->x - MARGIN,
		 data->height + (2 * MARGIN), data->width + (2 * MARGIN),
		 menubox_border_attr, menubox_attr);	/* border of daybox */

    wattrset(data->window, menubox_attr);	/* daynames headline */
    for (x = 0; x < 7; x++) {
	mvwprintw(data->window,
		  0, (x + 1) * cell_wide, "%*.*s ",
		  cell_wide - 1,
		  cell_wide - 1,
		  nameOfDayOfWeek(x));
    }

    mday = ((6 + current->tm_mday - current->tm_wday) % 7) - 7;
    if (mday <= -7)
	mday += 7;
    /* mday is now in the range -6 to 0. */
    week = (current->tm_yday + 6 + mday - current->tm_mday) / 7;

    for (y = 1; mday < last; y++) {
	wattrset(data->window, menubox_attr);	/* weeknumbers headline */
	mvwprintw(data->window,
		  y, 0,
		  "%*d ",
		  cell_wide - 1,
		  ++week);
	for (x = 0; x < 7; x++) {
	    this_x = 1 + (x + 1) * cell_wide;
	    ++mday;
	    if (wmove(data->window, y, this_x) == ERR)
		continue;
	    wattrset(data->window, item_attr);	/* not selected days */
	    if (mday == day) {
		wattrset(data->window, item_selected_attr);	/* selected day */
		save_y = y;
		save_x = this_x;
	    }
	    if (mday > 0) {
		if (mday <= last) {
		    wprintw(data->window, "%*d", cell_wide - 2, mday);
		} else if (mday == day) {
		    wprintw(data->window, "%*d", cell_wide - 2, mday - last);
		}
	    } else if (mday == day) {
		wprintw(data->window, "%*d", cell_wide - 2, mday + prev);
	    }
	}
	wmove(data->window, save_y, save_x);
    }
    /* just draw arrows - scrollbar is unsuitable here */
    dlg_draw_arrows(data->parent, TRUE, TRUE,
		    data->x + ARROWS_COL,
		    data->y - 1,
		    data->y + data->height);

    return 0;
}