Ejemplo n.º 1
0
/* Initialize the playing screen 
	We clear the whole screen.
*/
void 
info_screen_init(Screen *this_screen) {
	this_screen->wl_size = WL_SIZE;
	this_screen->win_list = win;
	this_screen->screen_enter = screen_enter;
	this_screen->screen_exit = screen_exit;
	this_screen->keypress = keypress;
	
	win_init(&title_win, 0, 0, 40, 128, 1, win_txt[0]);
	title_win.font = BIGFONT;	
	title_win.flags |= WINFLG_CENTER;
	title_win.fg_color = WHITE;
	title_win.bg_color = BLACK;
	win_new_text(&title_win, "Error ");	
	
	win_init(&info_win, 40, 0, 50, 128, 1, win_txt[1]);
	info_win.font = MEDIUMFONT;	
	info_win.flags |= WINFLG_CENTER;
	
	win_init(&help_win, 90, 0, 160-40-50, 128, 1, win_txt[2]);
	help_win.font = MEDIUMFONT;
	help_win.flags |= WINFLG_CENTER;
	win_new_text(&help_win, "Test Message");
	
}
Ejemplo n.º 2
0
/* Initialize the search screen 
*/
void 
search_screen_init(Screen *this_screen) {
	int cur_start_row = 0;
	
	this_screen->wl_size = WL_SIZE;
	this_screen->win_list = win;
	this_screen->screen_enter = screen_enter;
	this_screen->screen_exit = screen_exit;
	this_screen->keypress = keypress;
	
	win_init(&title_win, cur_start_row, 0, WL_SMALL_HEIGHT, 128, 1, win_txt[0]);
	title_win.font = SMALLFONT;	
	title_win.flags |= WINFLG_CENTER;
	title_win.fg_color = WHITE;
	title_win.bg_color = BLACK;
	win_new_text(&title_win, "Search Artist");	
	cur_start_row += WL_SMALL_HEIGHT;
	
	win_init(&input_win, cur_start_row, 0, 20, 128, 1, win_txt[1]);
	input_win.font = BIGFONT;	
	input_win.txt_offs_row = 3;
	win_new_text(&input_win, " ");
	cur_start_row += 20;
	
	win_init(&num_results_win, cur_start_row, 0, WL_SMALL_HEIGHT, 128, 0, win_txt[2]);
	num_results_win.font = SMALLFONT;	
	num_results_win.fg_color = BLACK;
	num_results_win.bg_color = DARK_GREY;	
	win_new_text(&num_results_win, "");
	cur_start_row += WL_SMALL_HEIGHT;
	
	init_scroll_list(&result_list, &(win[3]), win_txt[3], WIN_TXT_SIZE, RL_SIZE, &get_result, cur_start_row);

}
Ejemplo n.º 3
0
 /*
Parameters:
	sl = pointer to scroll_list structure
	pwl = pointer to the array of windows belonging to the scroll_list
	win_txt = pointer to array with space for window texts
	win_txt_len = size of each win_txt entry
	nw = number of windows in the scroll_list
	(*info_text)() = function which returns the text of a specified info index
	start_row = where shall the scroll_list start on screen
*/
void 
init_scroll_list(scroll_list *sl, struct Window *pwl, char *win_txt, int win_txt_len, int nw, 
				 char * (*info_text) (), int start_row, void (*range_set) ()  ) {
	int i;
	struct Window *pwin;

	sl->wl = pwl;
	sl->num_windows = nw;
	sl->sel_win= 0;
	sl->info_text = info_text;
	sl->range_set = range_set;
	sl->first_pos = 0;
	sl->last_pos = -1;
	sl->first_shown_pos = 0;
	
	/* These windows are scroll list lines */
	for (i=0, pwin = sl->wl; i < sl->num_windows; pwin++, i++){

		if (i==sl->sel_win){
			/* The selected window is bigger than usual */ 	
			win_init(pwin, start_row, 0, WL_HIGH_HEIGHT, 128, 1, &(win_txt[i*win_txt_len]));
			select_win(pwin);
		} else {
			win_init(pwin, start_row, 0, WL_NORMAL_HEIGHT, 128, 0, &(win_txt[i*win_txt_len]));
			unselect_win(pwin);
		};
		start_row += pwin->height;
		/* Every second window has a different background color */
		if (0 == (i & 1)) pwin->bg_color = LIGHT_GREY;
	};
};
Ejemplo n.º 4
0
int main()
{
	int key = 0;
	setlocale(LC_ALL, "");
	win_init();
	
	while((key = getch()) != 27)
	{
		switch(key)
		{
			case KEY_RIGHT:
				action_winactive(WIN_R);
			break;
			case KEY_LEFT:
				action_winactive(WIN_L);
			break;
			case KEY_DOWN:
				action_mvdown();
			break;
			case KEY_UP:
				action_mvup();
			break;
			case '\n':
				action_open();
			break;
		}
	}
	win_destroy();
}
Ejemplo n.º 5
0
int MPID_Win_create(void *base, MPI_Aint size, int disp_unit, MPIR_Info * info,
                    MPIR_Comm * comm_ptr, MPIR_Win ** win_ptr)
{
    int mpi_errno = MPI_SUCCESS;

    MPIR_FUNC_VERBOSE_STATE_DECL(MPID_STATE_MPID_WIN_CREATE);

    MPIR_FUNC_VERBOSE_RMA_ENTER(MPID_STATE_MPID_WIN_CREATE);

    /* Check to make sure the communicator hasn't already been revoked */
    if (comm_ptr->revoked) {
        MPIR_ERR_SETANDJUMP(mpi_errno, MPIX_ERR_REVOKED, "**revoked");
    }

    mpi_errno =
        win_init(size, disp_unit, MPI_WIN_FLAVOR_CREATE, MPI_WIN_UNIFIED, info, comm_ptr, win_ptr);
    if (mpi_errno)
        MPIR_ERR_POP(mpi_errno);

    (*win_ptr)->base = base;

    mpi_errno = MPIDI_CH3U_Win_fns.create(base, size, disp_unit, info, comm_ptr, win_ptr);
    if (mpi_errno)
        MPIR_ERR_POP(mpi_errno);

  fn_fail:
    MPIR_FUNC_VERBOSE_EXIT(MPID_STATE_MPID_WIN_CREATE);
    return mpi_errno;
}
Ejemplo n.º 6
0
/* Initialize the main screen.
	Start with top menu system.
	Initialize all screens.
	We clear the whole screen.
	We start the PLAYING screen.
*/
void 
mainscreen_init(void) {
	
	init_font();
	set_font(MEDIUMFONT);	
		
	win_scroll_init();
	
	win_cursor_init();
	
	// popup window
	win_init(&popup_win, POPUP_STARTPAGE * 8, 8, POPUP_PAGES * 8, 112, 1, popup_txt);
	popup_win.font = SMALLFONT;	
	popup_win.flags |= WINFLG_CENTER | WINFLG_LFTADJ;
	popup_win.buffer_size = POPUP_TXT_SIZE;
	popup_active = 0;
	deferred_screen = NO_SCREEN;
	
	playing_screen_init( &(screen_list[PLAYING_SCREEN]) );
	playlist_screen_init( &(screen_list[PLAYLIST_SCREEN]) );
	tracklist_screen_init( &(screen_list[TRACKLIST_SCREEN]) );
	search_screen_init( &(screen_list[SEARCH_SCREEN]) );
	
	set_keypress_handler(mainscreen_keypress);
	screen_enter(PLAYING_SCREEN);

};
Ejemplo n.º 7
0
int main(int ac, char **av) {
  int rc, i;

  /* simple "do we have ssl" check for run_tests.sh */
  if (ac == 2 && !strncmp(av[1], "--ssl", 5)) {
#ifdef HAVE_SSL
    return 0;
#else
    return 1;
#endif
  }

#ifdef WIN32
  win_init();
#endif

  for (i = 0; TestCases[i] != NULL; i++) {
    const struct test_case *current = TestCases[i];
    const char *name = get_test_name(current);

    printf("%-48s", name);
    fflush(stdout);
    rc = test_case_run(current);
    if (rc) {
      printf(TEST_FAILED " (%s)\n", socket_strerror(-rc));
      break;
    }
    printf(TEST_OK "\n");
  }
  return rc;
}
Ejemplo n.º 8
0
/**
 * \brief Main application function
 *
 * This function calls all the necessary initialization functions before
 * launching the calculator widget and entering the main work loop.
 *
 * The main work loop is responsible for handling the low level user input, so
 * it reads touch data from the mXT143E Xplained, translates and passes it on to
 * the window system's event queue.
 *
 * All the processing for the calculator is done by the calculator widget's
 * event handler function \ref app_calc_handler(). This function is called by
 * the window system when it maps a user input event to an interaction with the
 * calculator, i.e., a button press.
 */
int main(void)
{
	static struct mxt_device device;

	board_init();
	sysclk_init();
	membag_init();

	gfx_init();
	mxt_init(&device);
	win_init();

	setup_gui_root_window();
	win_reset_root_geometry();
	if (app_widget_launch() == false) {
		show_out_of_memory_error();
		for (;;);
	}

	while (true) {
		struct win_pointer_event win_touch_event;

		/* Queue touch events from the touchscreen if any are available */
		while (read_touch_event(&device, &win_touch_event)) {
			win_queue_pointer_event(&win_touch_event);
		}

		/* Process queued events in the windowing system */
		win_process_events();
	}
}
Ejemplo n.º 9
0
int
  main(int argc, char *argv[])
{
	win_t win;
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;

	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	win.dpy = XOpenDisplay(0);

	if (win.dpy == NULL) {
		fprintf(stderr, "Failed to open display\n");
		return 1;
	}

	win_init(&win);

	win_draw(&win);

	win_handle_events(&win);

	win_deinit(&win);

	XCloseDisplay(win.dpy);

	GdiplusShutdown(gdiplusToken);
	return 0;
}
Ejemplo n.º 10
0
int MPID_Win_create_dynamic(MPIR_Info * info, MPIR_Comm * comm_ptr, MPIR_Win ** win_ptr)
{
    int mpi_errno = MPI_SUCCESS;

    MPIR_FUNC_VERBOSE_STATE_DECL(MPID_STATE_MPID_WIN_CREATE_DYNAMIC);

    MPIR_FUNC_VERBOSE_RMA_ENTER(MPID_STATE_MPID_WIN_CREATE_DYNAMIC);

    mpi_errno = win_init(0 /* spec defines size to be 0 */ ,
                         1 /* spec defines disp_unit to be 1 */ ,
                         MPI_WIN_FLAVOR_DYNAMIC, MPI_WIN_UNIFIED, info, comm_ptr, win_ptr);

    if (mpi_errno)
        MPIR_ERR_POP(mpi_errno);

    (*win_ptr)->base = MPI_BOTTOM;

    mpi_errno = MPIDI_CH3U_Win_fns.create_dynamic(info, comm_ptr, win_ptr);
    if (mpi_errno != MPI_SUCCESS) {
        MPIR_ERR_POP(mpi_errno);
    }

  fn_fail:
    MPIR_FUNC_VERBOSE_EXIT(MPID_STATE_MPID_WIN_CREATE_DYNAMIC);
    return mpi_errno;
}
Ejemplo n.º 11
0
/* 
 * Handle SIGWINCH. Order of calling various resize
 * functions is really important.
 */
static void resize(void)
{
	get_rows_cols(&screen_rows, &screen_cols);
	resizeterm(screen_rows, screen_cols);
	wresize(main_win, screen_rows-3, screen_cols);
	win_init();
	mvwin(help_win.wd, screen_rows - 1, 0);	
//	wnoutrefresh(help_win.wd);
//	wnoutrefresh(info_win.wd);
	/* set the cursor position if necessary */
	if(current->cursor > current->rows)
		current->cursor = current->rows; 
	werase(main_win);
	current->redraw();
	wnoutrefresh(main_win);                                             
	print_help();
	pad_resize();
	print_info();
	update_load();
	menu_resize();
	box_resize();
	info_resize();
	doupdate();
	size_changed = 0;
}
Ejemplo n.º 12
0
/**
 * \brief Main application function
 *
 * This function executes the necessary initialization calls and displays the
 * demo widgets before entering the main work loop of the application.
 *
 * The main work loop reads out the touch events from the mXT143E Xplained and
 * enqueues the corresponding touch events in the window system, before
 * processing the window system's event queue.
 */
int main(void)
{
	static struct mxt_device device;

	board_init();
	sysclk_init();
	membag_init();
	gfx_init();
	mxt_init(&device);
	win_init();

	setup_root_window();
	app_widget_launch();

	while (true) {
		/* Process received messages from the maXTouch device */
		while (mxt_is_message_pending(&device)) {
			struct mxt_touch_event touch_event;
			struct win_pointer_event win_touch_event;

			/* Get the first touch event in queue */
			if (mxt_read_touch_event(&device,
					&touch_event) != STATUS_OK) {
				continue;
			}

			/* Translate touch event type into a WTK event type */
			if (touch_event.status & MXT_PRESS_EVENT) {
				win_touch_event.type = WIN_POINTER_PRESS;
			} else if (touch_event.status & MXT_MOVE_EVENT) {
				win_touch_event.type = WIN_POINTER_MOVE;
			} else if (touch_event.status & MXT_RELEASE_EVENT) {
				win_touch_event.type = WIN_POINTER_RELEASE;
			} else {
				continue;
			}

			/* Indicate the touch event is a non-relative movement
			 * with the virtual touch button pressed
			 */
			win_touch_event.is_relative = false;
			win_touch_event.buttons = WIN_TOUCH_BUTTON;

			/* Translate the touch X and Y position into a screen
			 * coordinate
			 */
			win_touch_event.pos.x =
					((uint32_t)(4096 - touch_event.x) * gfx_get_width()) / 4096;
			win_touch_event.pos.y =
					((uint32_t)(4096 - touch_event.y) * gfx_get_height()) / 4096;
			win_queue_pointer_event(&win_touch_event);
		}

		/* Process queued events in the windowing system */
		win_process_events();
	}
}
Ejemplo n.º 13
0
//
// initsystem() -- init SDL systems
//
int32_t initsystem(void)
{
#if defined NOSDLPARACHUTE
    const int sdlinitflags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
#else
    const int sdlinitflags = SDL_INIT_VIDEO;
#endif

    mutex_init(&m_initprintf);

#ifdef _WIN32
    win_init();
#endif

    if (sdlayer_checkversion())
        return -1;

    if (SDL_Init(sdlinitflags))
    {
        initprintf("Initialization failed! (%s)\nNon-interactive mode enabled\n", SDL_GetError());
        novideo = 1;
#ifdef USE_OPENGL
        nogl = 1;
#endif
    }

    atexit(uninitsystem);

    frameplace = 0;
    lockcount = 0;


    if (!novideo)
    {
        char drvname[32];

#ifdef USE_OPENGL
        if (loadgldriver(getenv("BUILD_GLDRV")))
        {
            initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n");
            nogl = 1;
        }
#endif

        if (SDL_VideoDriverName(drvname, 32))
            initprintf("Using \"%s\" video driver\n", drvname);

        wm_setapptitle(apptitle);
    }

#if defined GEKKO
    SDL_ShowCursor(SDL_DISABLE);
#endif

    return 0;
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
    struct addrset *set;
    char line[1024];
    int i;

#ifdef WIN32
    win_init();
#endif

    set = addrset_new();

    options_init();

    for (i = 1; i < argc; i++) {
        if (!addrset_add_spec(set, argv[i], o.af, !o.nodns)) {
            fprintf(stderr, "Error adding spec \"%s\".\n", argv[i]);
            exit(1);
        }
    }

    while (fgets(line, sizeof(line), stdin) != NULL) {
        char *s, *hostname;
        struct addrinfo *addrs;

        s = line;
        while ((hostname = strtok(s, " \t\n")) != NULL) {
            int rc;

            s = NULL;

            rc = resolve_name(hostname, &addrs);
            if (rc != 0) {
                fprintf(stderr, "Error resolving \"%s\": %s.\n", hostname, gai_strerror(rc));
                continue;
            }
            if (addrs == NULL) {
                fprintf(stderr, "No addresses found for \"%s\".\n", hostname);
                continue;
            }

            /* Check just the first address returned. */
            if (addrset_contains(set, addrs->ai_addr))
                    printf("%s\n", hostname);

            freeaddrinfo(addrs);
        }
    }

    addrset_free(set);

    return 0;
}
Ejemplo n.º 15
0
/*----------------------------------win_create---------------------------------*/
YT_WIN*
win_create (int w, int h)
{
  YT_WIN *win;

  win = (YT_WIN*) malloc (sizeof(YT_WIN));
  win->w = w;
  win->h = h;

  win_init (win, ' ');

  return (win);
}
Ejemplo n.º 16
0
void clear_screen()
{
    win_t win;
    win_init(&win, NULL);
    
    win.boxed = 0;
    
    win_setdims(&win, 0, 0, g_data.ui.ydim, g_data.ui.xdim);
        
    win_start(&win);
    win_draw(&win, true, true);
    win_stop(&win);
    
    win_uninit(&win);
}
Ejemplo n.º 17
0
/* Convert blocks into windows whilst ensuring blocks which
 * transverse buffers are accounted for */
int process_block(char *block) {
    long sz, bsz;
    char *regex_b, *b = NULL;
    bool alloced = false;
    window_t *w = NULL;
    extern int store_count;

    /* previous block didn't terminate so we need to merge it 
     * with the current block */
    if(blocks_require_merge()) {
        if((sz = blocks_merge(block, &b)) == RERROR)
            return RERROR;
        alloced = true;
    } else {
        b = block;
        sz = strlen(block);
    }

    regex_b = regex_creplace(b);
    bsz = strlen(regex_b);

    if(win_init(&w, regex_b, bsz)==RERROR) {
        setlocation(LOCATION, __func__);
        return RERROR;
    }

    free(regex_b);

    // need this for ngram computation over blocks
    w->mcount = store_count;
    lgprintf(LG_INFO, "merged window size: %d\n", w->wc);
    win_store_add(w);

    /* this block does not terminate so we need to store it so
     * that blocks from the next buffer can be merged with it. */
    if(!block_match(b[sz-1])) 
        blocks_store(w);
    else 
        blocks_clear();

    if(alloced) {
        free(b);
        alloced = false;
    }
    return 0;
}
Ejemplo n.º 18
0
/**
 * Initialize the templ theme
 * @param hue [0..360] hue value from HSV color space to define the theme's base color
 * @param font pointer to a font (NULL to use the default)
 * @return pointer to the initialized theme
 */
lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t *font)
{
    if(font == NULL) font = LV_FONT_DEFAULT;

    _hue = hue;
    _font = font;

    /*For backward compatibility initialize all theme elements with a default style */
    uint16_t i;
    lv_style_t **style_p = (lv_style_t**) &theme;
    for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t*); i++) {
        *style_p = &def;
        style_p++;
    }

    basic_init();
    cont_init();
    btn_init();
    label_init();
    img_init();
    line_init();
    led_init();
    bar_init();
    slider_init();
    sw_init();
    lmeter_init();
    gauge_init();
    chart_init();
    cb_init();
    btnm_init();
    kb_init();
    mbox_init();
    page_init();
    ta_init();
    list_init();
    ddlist_init();
    roller_init();
    tabview_init();
    win_init();

    return &theme;
}
Ejemplo n.º 19
0
int main(int ac, char **av) {
  int rc, i;

#ifdef WIN32
  win_init();
#endif

  for (i = 0; TestCases[i] != NULL; i++) {
    const struct test_case *current = TestCases[i];
    const char *name = get_test_name(current);

    printf("%-48s", name);
    fflush(stdout);
    rc = test_case_run(current);
    if (rc) {
      printf(TEST_FAILED " (%s)\n", socket_strerror(-rc));
      break;
    }
    printf(TEST_OK "\n");
  }
  return rc;
}
Ejemplo n.º 20
0
void clear_screen_bylines()
{
    win_t   win;
    int16_t i, rnd, pos;
    int8_t *lines = (int8_t *)malloc(g_data.ui.ydim * sizeof(int8_t));

    win_init(&win, NULL);
    win.boxed = 0;
    memset(lines, 0, g_data.ui.ydim * sizeof(int8_t));
   
    rand_open();
    
    for (i = g_data.ui.ydim; i > 0; i--)
    {
        rnd = rand_get() % i;
        pos = -1;
        
        while (rnd > -1)
        {
            if (lines[++pos] == 0)
                rnd--;
        }
        
        win_setdims(&win, pos, 0, 1, g_data.ui.xdim);
        
        win_start(&win);
        win_draw(&win, true, true);
        win_stop(&win);
        
        lines[pos] = 1;
        usleep(min(50000, (500000 / g_data.ui.ydim)));
    }

    rand_close();

    win_uninit(&win);
    free(lines);
}
Ejemplo n.º 21
0
bool_t
node_sync( intgen_t fd, off64_t off )
{
    /* sanity checks
     */
    ASSERT( sizeof( node_hdr_t ) <= NODE_HDRSZ );

    /* map the abstraction header
     */
    ASSERT( ( NODE_HDRSZ & pgmask ) == 0 );
    ASSERT( off <= ( off64_t )OFF64MAX );
    ASSERT( ! ( off % ( off64_t )pgsz ));
    node_hdrp = ( node_hdr_t * )mmap_autogrow(
                    NODE_HDRSZ,
                    fd,
                    off );
    if ( node_hdrp == (node_hdr_t *)-1 ) {
        mlog( MLOG_NORMAL | MLOG_ERROR, _(
                  "unable to map node hdr of size %d: %s\n"),
              NODE_HDRSZ,
              strerror( errno ));
        return BOOL_FALSE;
    }

    /* save transient context
     */
    node_fd = fd;

    /* initialize the window abstraction
     */
    win_init( fd,
              node_hdrp->nh_firstsegoff,
              node_hdrp->nh_segsz,
              node_hdrp->nh_segtblsz,
              node_hdrp->nh_winmapmax );

    return BOOL_TRUE;
}
Ejemplo n.º 22
0
int MPID_Win_allocate_shared(MPI_Aint size, int disp_unit, MPIR_Info * info, MPIR_Comm * comm_ptr,
                             void *base_ptr, MPIR_Win ** win_ptr)
{
    int mpi_errno = MPI_SUCCESS;

    MPIR_FUNC_VERBOSE_STATE_DECL(MPID_STATE_MPID_WIN_ALLOCATE_SHARED);

    MPIR_FUNC_VERBOSE_RMA_ENTER(MPID_STATE_MPID_WIN_ALLOCATE_SHARED);

    mpi_errno =
        win_init(size, disp_unit, MPI_WIN_FLAVOR_SHARED, MPI_WIN_UNIFIED, info, comm_ptr, win_ptr);
    if (mpi_errno)
        MPIR_ERR_POP(mpi_errno);

    mpi_errno =
        MPIDI_CH3U_Win_fns.allocate_shared(size, disp_unit, info, comm_ptr, base_ptr, win_ptr);
    if (mpi_errno != MPI_SUCCESS)
        MPIR_ERR_POP(mpi_errno);

  fn_fail:
    MPIR_FUNC_VERBOSE_EXIT(MPID_STATE_MPID_WIN_ALLOCATE_SHARED);
    return mpi_errno;
}
Ejemplo n.º 23
0
install_t
install_process()
{
#ifdef __WINDOWS__
  win_init();
#endif

  MKATOM(stdin);
  MKATOM(stdout);
  MKATOM(stderr);
  MKATOM(std);
  MKATOM(null);
  MKATOM(process);
  MKATOM(detached);
  MKATOM(cwd);
  MKATOM(env);
  MKATOM(window);
  MKATOM(timeout);
  MKATOM(release);
  MKATOM(infinite);

  MKFUNCTOR(pipe, 1);
  MKFUNCTOR(error, 2);
  MKFUNCTOR(type_error, 2);
  MKFUNCTOR(domain_error, 2);
  MKFUNCTOR(process_error, 2);
  MKFUNCTOR(system_error, 2);
  MKFUNCTOR(resource_error, 1);
  MKFUNCTOR(exit, 1);
  MKFUNCTOR(killed, 1);

  FUNCTOR_eq2 = PL_new_functor(PL_new_atom("="), 2);

  PL_register_foreign("process_create", 2, process_create, 0);
  PL_register_foreign("process_wait", 3, process_wait, 0);
  PL_register_foreign("process_kill", 2, process_kill, 0);
}
Ejemplo n.º 24
0
/* Initialize the playing screen 
	We clear the whole screen.
*/
void 
playing_screen_init(Screen *this_screen) {
	this_screen->wl_size = WL_SIZE;
	this_screen->win_list = win;
	this_screen->screen_enter = screen_enter;
	this_screen->screen_exit = screen_exit;
	this_screen->keypress = keypress;
	
	win_init(&title_win, 0, 0, 50, 128, 1, win_txt[0]);
	title_win.font = MEDIUMFONT;	
	title_win.flags |= WINFLG_CENTER;
	
	win_init(&artist_win, 49, 0, 30, 128, 1, win_txt[1]);
	artist_win.font = MEDIUMFONT;	
	artist_win.flags |= WINFLG_CENTER;
	
	win_init(&time_win, 84, 22, 10, 128-22, 0, win_txt[2]);
	time_win.font = SMALLFONT;

	/* The state window, on the same line as the time progress */
	win_init(&state_win, 89, 1, 16, 18, 0, win_txt[3]);

	state_win.font = BIGFONT;
	win_new_text(&state_win, "\xB3"); 	// play icon == b3
	
	/* This is our progressbar */
	win_init(&time_prog_win, 95, 22, 8, 102, 1, win_txt[4]);
	time_prog_win.font = SMALLFONT;
	time_prog_win.flags = WINFLG_BAR;
	time_prog_win.fg_color = DARK_GREY;
	time_prog_win.cur_char = 0;		/* current value */
	
#define VOL_ROW 114	
	/* The speaker indicator is on the same line as volume text */
	win_init(&speaker_win, VOL_ROW, 15, 18, 15, 0, win_txt[5]);
	speaker_win.font = BIGFONT;
	win_new_text(&speaker_win, "\xB8");	// speaker icon on
	
	/* Our indicator for the volume (triangle progress bar) */
	win_init(&vol_ramp_win, VOL_ROW, 31, 16, 50, 0, win_txt[6]);
	vol_ramp_win.flags = WINFLG_RAMP;
	vol_ramp_win.fg_color = BLACK;
	vol_ramp_win.cur_char = 100/2;		/* We initialize the volume with 100 % */

	/* The text portion of the volume follows on the same line as the ramp */
	win_init(&volume_win, VOL_ROW, 88, 16, 128-88, 0, win_txt[7]);
	win_new_text(&volume_win, "100 %");

	win_init(&rnd_win, 134, 0, 14, 33, 1, win_txt[8]);
	rnd_win.font = SMALLFONT;
	rnd_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE;
	rnd_win.fg_color = WHITE;
	rnd_win.bg_color = BLACK;
	win_new_text(&rnd_win, "RND" );
	
	win_init(&rpt_win, 134, 43, 14, 33, 1, win_txt[9]);
	rpt_win.font = SMALLFONT;
	rpt_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE;
	rpt_win.fg_color = WHITE;
	rpt_win.bg_color = BLACK;
	win_new_text(&rpt_win, "RPT" );
	
	win_init(&single_win, 134, 86, 14, 33, 1, win_txt[10]);
	single_win.font = SMALLFONT;
	single_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE;
	single_win.fg_color = WHITE;
	single_win.bg_color = BLACK;
	win_new_text(&single_win, "1" );
	
	win_init(&version_win, 150, 0, 10, 128, 0, win_txt[11]); 
	version_win.font = SMALLFONT;	
	version_win.flags |= WINFLG_CENTER;
	version_win.fg_color = WHITE;
	version_win.bg_color = BLACK;
	win_new_text(&version_win, "Version " VERSION);

}
Ejemplo n.º 25
0
/** \brief Main function. Execution starts here.
 */
int main(void)
{
	uint8_t uc_result;

	/* Initialize the sleep manager */
	sleepmgr_init();
	membag_init();
	sysclk_init();
	init_specific_board();

	/* Initialize the console uart */
	configure_console();

	/* Output demo infomation. */
	printf("-- SAM Toolkit Demo Example --\n\r");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
	/* Configure systick for 1 ms. */
	puts("Configure system tick to get 1ms tick period.\r");
	if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
		puts("Systick configuration error\r");
		while (1) {
		}
	}

	/* Initialize gfx module */
	gfx_init();
	win_init();

	/* Initialize FatFS and bitmap draw interface */
	demo_draw_bmpfile_init();

	/* Initialize touchscreen without calibration */
	rtouch_init(LCD_WIDTH, LCD_HEIGHT);
	rtouch_enable();
	rtouch_set_event_handler(event_handler);

	/* Initialize demo parameters */
	demo_parameters_initialize();
	while (g_demo_parameters.calib_points[0].raw.x == 0) {
		uc_result = rtouch_calibrate();
		if (uc_result == 0) {
			demo_set_special_mode_status(DEMO_LCD_CALIBRATE_MODE, 0);
			puts("Calibration successful !\r");
			break;
		} else {
			puts("Calibration failed; error delta is too big ! Please retry calibration procedure...\r");
		}
	}

	/* Re-caculate the calibration data */
	rtouch_compute_calibration(
			(rtouch_calibration_point_t *)&g_demo_parameters.calib_points[0]);

	/* Setup root window */
	setup_gui_root_window();
	gfx_draw_bitmap(&win_startup_bmp, 0, 40);

	/* Set backlight by the data read from demo parameters */
	aat31xx_set_backlight(g_demo_parameters.backlight);

	/* Default RTC configuration, 24-hour mode */
	rtc_set_hour_mode(RTC, 0);
	rtc_set_time(RTC, g_demo_parameters.hour, g_demo_parameters.minute,
			g_demo_parameters.second);
	rtc_set_date( RTC, g_demo_parameters.year, g_demo_parameters.month,
			g_demo_parameters.day, 1 );

	/* Create a semaphore to manage the memories data transfer */
	vSemaphoreCreateBinary(main_trans_semphr);

	/* Turn on main widget */
	app_widget_main_on(true);

	/* Initialize QTouch */
	demo_qt_init();

	/* Start USB stack to authorize VBus monitoring */
	udc_start();
	if (!udc_include_vbus_monitoring()) {
		/* VBUS monitoring is not available on this product
		 * thereby VBUS has to be considered as present */
		main_vbus_action(true);
	}

	/* Create task to window task */
	if (xTaskCreate(task_win, "WIN", TASK_WIN_STACK_SIZE, NULL,
			TASK_WIN_STACK_PRIORITY, NULL) != pdPASS) {
		printf("Failed to create test led task\r\n");
	}

	/* Create task to usb mass storage task */
	if (xTaskCreate(task_usb, "USB", TASK_USB_STACK_SIZE, NULL,
			TASK_USB_STACK_PRIORITY, NULL) != pdPASS) {
		printf("Failed to create test led task\r\n");
	}

	/* Start the scheduler. */
	vTaskStartScheduler();

	/* Will only get here if there was insufficient memory to create the
	 * idle task. */
	return 0;
}
Ejemplo n.º 26
0
/* ARGSUSED */
bool_t
node_init( intgen_t fd,
           off64_t off,
           size_t usrnodesz,
           ix_t nodehkix,
           size_t nodealignsz,
           size64_t vmsz,
           size64_t dirs_nondirs_cnt )
{
    size64_t nodesz;
    size64_t winmap_mem;
    size64_t segsz;
    size64_t segtablesz;
    size64_t nodesperseg;
    size64_t minsegsz;
    size64_t winmapmax;
    intgen_t rval;

    /* sanity checks
     */
    ASSERT( sizeof( node_hdr_t ) <= NODE_HDRSZ );
    ASSERT( sizeof( nh_t ) < sizeof( off64_t ));
    ASSERT( nodehkix < usrnodesz );
    ASSERT( usrnodesz >= sizeof( char * ) + 1 );
    /* so node is at least big enough to hold
     * the free list linkage and the housekeeping byte
     */
    ASSERT( nodehkix > sizeof( char * ));
    /* since beginning of each node is used to
     * link it in the free list.
     */

    /* adjust the user's node size to meet user's alignment constraint
    */
    nodesz = ( usrnodesz + nodealignsz - 1 ) & ~( nodealignsz - 1 );

#define	WINMAP_MAX	20	/* maximum number of windows to use */
#define	WINMAP_MIN	4	/* minimum number of windows to use */
#define	HARDLINK_FUDGE	1.2	/* approx 1.2 hard links per file */

    /* Calculate the expected size of the segment table using the number
     * of dirs and non-dirs.  Since we don't know how many hard-links
     * there will be, scale the size upward using HARDLINK_FUDGE.
     */

    segtablesz = ( (size64_t)(HARDLINK_FUDGE * (double)dirs_nondirs_cnt) * nodesz);

    /* Figure out how much memory is available for use by winmaps, and
     * use that to pick an appropriate winmapmax, segsz, and nodesperseg,
     * the goal being that if at all possible we want the entire segment
     * table to be mapped so that we aren't constantly mapping and
     * unmapping winmaps.  There must be at least WINMAP_MIN winmaps
     * because references can be held on more than one winmap at the
     * same time.  More winmaps are generally better to reduce the
     * number of nodes that are unmapped if unmapping does occur.
     */

    minsegsz = pgsz * nodesz;	/* must be pgsz and nodesz multiple */
    winmap_mem = min(vmsz, segtablesz);
    segsz = (((winmap_mem / WINMAP_MAX) + minsegsz - 1) / minsegsz) * minsegsz;
    segsz = max(segsz, minsegsz);

    nodesperseg = segsz / nodesz;

    winmapmax = min(WINMAP_MAX, vmsz / segsz);
    winmapmax = max(winmapmax, WINMAP_MIN);

    /* map the abstraction header
     */
    ASSERT( ( NODE_HDRSZ & pgmask ) == 0 );
    ASSERT( ! ( NODE_HDRSZ % pgsz ));
    ASSERT( off <= OFF64MAX );
    ASSERT( ! ( off % ( off64_t )pgsz ));
    node_hdrp = ( node_hdr_t * )mmap_autogrow(
                    NODE_HDRSZ,
                    fd,
                    off );
    if ( node_hdrp == (node_hdr_t *)-1 ) {
        mlog( MLOG_NORMAL | MLOG_ERROR, _(
                  "unable to map node hdr of size %d: %s\n"),
              NODE_HDRSZ,
              strerror( errno ));
        return BOOL_FALSE;
    }

    /* initialize and save persistent context.
     */
    node_hdrp->nh_nodesz = nodesz;
    node_hdrp->nh_nodehkix = nodehkix;
    node_hdrp->nh_segsz = segsz;
    node_hdrp->nh_segtblsz = segtablesz;
    node_hdrp->nh_winmapmax = winmapmax;
    node_hdrp->nh_nodesperseg = nodesperseg;
    node_hdrp->nh_nodealignsz = nodealignsz;
    node_hdrp->nh_freenix = NIX_NULL;
    node_hdrp->nh_firstsegoff = off + ( off64_t )NODE_HDRSZ;
    node_hdrp->nh_virgsegreloff = 0;
    node_hdrp->nh_virgrelnix = 0;

    /* save transient context
     */
    node_fd = fd;

    /* autogrow the first segment
     */
    mlog( MLOG_DEBUG,
          "pre-growing new node array segment at %lld "
          "size %lld\n",
          node_hdrp->nh_firstsegoff,
          ( off64_t )node_hdrp->nh_segsz );
    rval = ftruncate64( node_fd,
                        node_hdrp->nh_firstsegoff
                        +
                        ( off64_t )node_hdrp->nh_segsz );
    if ( rval ) {
        mlog( MLOG_NORMAL | MLOG_ERROR | MLOG_TREE, _(
                  "unable to autogrow first node segment: %s (%d)\n"),
              strerror( errno ),
              errno );
        return BOOL_FALSE;
    }

    /* initialize the window abstraction
     */
    win_init( fd,
              node_hdrp->nh_firstsegoff,
              segsz,
              segtablesz,
              winmapmax );

    /* announce the results
     */
    mlog( MLOG_DEBUG | MLOG_TREE,
          "node_init:"
          " vmsz = %llu (0x%llx)"
          " segsz = %u (0x%x)"
          " segtblsz = %llu (0x%llx)"
          " nodesperseg = %u (0x%x)"
          " winmapmax = %llu (0x%llx)"
          "\n",
          vmsz, vmsz,
          segsz, segsz,
          segtablesz, segtablesz,
          nodesperseg, nodesperseg,
          winmapmax, winmapmax );

    return BOOL_TRUE;
}
Ejemplo n.º 27
0
int main(int argc, char **argv)
{
  int c;			/* Command character */
  int quit = 0;			/* 'q' or 'x' pressed */
  char *s, *bufp;		/* Scratch pointers */
  int doinit = 1;		/* -o option */
  char capname[128];		/* Name of capture file */
  struct passwd *pwd;		/* To look up user name */
  char *use_port;		/* Name of initialization file */
  char *args[20];		/* New argv pointer */
  int argk = 1;			/* New argc */
  char *mc;			/* For 'MINICOM' env. variable */
  int env_args;			/* Number of args in env. variable */
  char *cmd_dial;		/* Entry from the command line. */
  int alt_code = 0;		/* Type of alt key */
  char *cmdline_baudrate = NULL;/* Baudrate given on the command line via -b */
  char *cmdline_device = NULL;  /* Device/Port given on the command line via -D */
  char *remote_charset = NULL;  /* Remote charset given on the command line via -R */
  char pseudo[64];
  /* char* console_encoding = getenv ("LC_CTYPE"); */

  static struct option long_options[] =
  {
    { "setup",         no_argument,       NULL, 's' },
    { "help",          no_argument,       NULL, 'h' },
    { "ptty",          required_argument, NULL, 'p' },
    { "metakey",       no_argument,       NULL, 'm' },
    { "metakey8",      no_argument,       NULL, 'M' },
    { "ansi",          no_argument,       NULL, 'l' },
    { "iso",           no_argument,       NULL, 'L' },
    { "term",          required_argument, NULL, 't' },
    { "noinit",        no_argument,       NULL, 'o' },
    { "color",         required_argument, NULL, 'c' },
    { "attrib",        required_argument, NULL, 'a' },
    { "dial",          required_argument, NULL, 'd' },
    { "statline",      no_argument,       NULL, 'z' },
    { "capturefile",   required_argument, NULL, 'C' },
    { "script",        required_argument, NULL, 'S' },
    { "7bit",          no_argument,       NULL, '7' },
    { "8bit",          no_argument,       NULL, '8' },
    { "version",       no_argument,       NULL, 'v' },
    { "wrap",          no_argument,       NULL, 'w' },
    { "displayhex",    no_argument,       NULL, 'H' },
    { "disabletime",   no_argument,       NULL, 'T' }, // obsolete
    { "baudrate",      required_argument, NULL, 'b' },
    { "device",        required_argument, NULL, 'D' },
    { "remotecharset", required_argument, NULL, 'R' },
    { "statlinefmt",   required_argument, NULL, 'F' },
    { NULL, 0, NULL, 0 }
  };

  /* initialize locale support */
  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);

  /* Initialize global variables */
  portfd =  -1;
  capfp = NULL;
  docap = 0;
  online = -1;
  linespd = 0;
  stdattr = XA_NORMAL;
  us = NULL;
  addlf = 0;
  addcr = 0;
  line_timestamp = 0;
  wrapln = 0;
  display_hex = 0;
  option_T_used = 0;
  local_echo = 0;
  strcpy(capname, "minicom.cap");
  lockfile[0] = 0;
  tempst = 0;
  st = NULL;
  us = NULL;
  bogus_dcd = 0;
  usecolor = 0;
  screen_ibmpc = screen_iso = 1;
  useattr = 1;
  strncpy(termtype, getenv("TERM") ? getenv("TERM") : "dumb", sizeof(termtype));
  stdattr = XA_NORMAL;
  use_port = "dfl";
  alt_override = 0;
  scr_name[0] = 0;
  scr_user[0] = 0;
  scr_passwd[0] = 0;
  dial_name = (char *)NULL;
  dial_number = (char *)NULL;
  dial_user = (char *)NULL;
  dial_pass = (char *)NULL;
  size_changed = 0;
  escape = 1;
  cmd_dial = NULL;

  /* fmg 1/11/94 colors (set defaults) */
  /* MARK updated 02/17/95 to be more similiar to TELIX */
  mfcolor = YELLOW;
  mbcolor = BLUE;
  tfcolor = WHITE;
  tbcolor = BLACK;
  sfcolor = WHITE;
  sbcolor = RED;
  st_attr = XA_NORMAL;


  /* If no LANG or LC_ALL is set, fall back to 7bit mode
   * since in 8bit mode we can't have fancy window borders... */
  {
    char *e1 = getenv("LANG"), *e2 = getenv("LC_ALL");
    if ((!e1 || !strcmp("C", e1) || !strcmp("POSIX", e1)) &&
	(!e2 || !strcmp("C", e2) || !strcmp("POSIX", e2)))
      screen_ibmpc = screen_iso = 0;
  }


  /* MARK updated 02/17/95 default history buffer size */
  num_hist_lines = 256;

  /* fmg - but we reset these to F=WHITE, B=BLACK if -b flag found */

  /* Before processing the options, first add options
   * from the environment variable 'MINICOM'.
   */
  args[0] = "minicom";
  if ((mc = getenv("MINICOM")) != NULL) {
    char buf[80];
    strncpy(buf, mc, 80);
    bufp = buf;
    buf[79] = 0;
    while (isspace(*bufp))
      bufp++;
    while (*bufp && argk < 19) {
      for (s = bufp; !isspace(*bufp) && *bufp; bufp++)
	;
      args[argk++] = s;
      while (isspace(*bufp))
	*bufp++ = 0;
    }
  }
  env_args = argk;

  /* Add command - line options */
  for(c = 1; c < argc && argk < 19; c++)
    args[argk++] = argv[c];
  args[argk] = NULL;

  do {
    /* Process options with getopt */
    while ((c = getopt_long(argk, args, "v78zhlLsomMHb:wTc:a:t:d:p:C:S:D:R:F:",
                            long_options, NULL)) != EOF)
      switch(c) {
	case 'v':
	  printf(_("%s version %s"), PACKAGE, VERSION);
#ifdef __DATE__
	  printf(_(" (compiled %s)"), __DATE__);
#endif
	  printf("\n");
	  printf(_("Copyright (C) Miquel van Smoorenburg.\n\n"));
	  printf("This program is free software; you can redistribute it and/or\n"
	         "modify it under the terms of the GNU General Public License\n"
                 "as published by the Free Software Foundation; either version\n"
                 "2 of the License, or (at your option) any later version.\n\n");
          exit(1);
          break;
        case 's': /* setup mode */
          dosetup = 1;
          break;
        case 'h':
          helpthem();
          exit(1);
          break;
        case 'p': /* Pseudo terminal to use. */
          if (strncmp(optarg, "/dev/", 5) == 0)
            optarg += 5;
          if (((strncmp(optarg, "tty", 3) != 0)
                /* /dev/pts support --misiek. */
                && (strncmp(optarg, "pts", 3) != 0)
                /* /dev/pty support --jl. */
                && (strncmp(optarg, "pty", 3) != 0))
              || !strchr("pqrstuvwxyz/", optarg[3])) {
            fprintf(stderr, _("minicom: argument to -p must be a pty\n"));
            exit(1);
          }
          snprintf(pseudo, sizeof(pseudo), "/dev/%s", optarg);
          dial_tty = pseudo;
          break;
        case 'm': /* ESC prefix metakey */
          alt_override++;
          alt_code = 27;
          break;
        case 'M': /* 8th bit metakey. */
          alt_override++;
          alt_code = 128;
          break;
        case 'l': /* Don't assume literal ANSI chars */
          screen_ibmpc = 0;
          break;
        case 'L': /* Don't assume literal ISO8859 chars */
          screen_iso = 0;
          break;
        case 't': /* Terminal type */
          strncpy(termtype, optarg, sizeof(termtype));
#ifdef __GLIBC__
          /* Bug in older libc's (< 4.5.26 I think) */
          if ((s = getenv("TERMCAP")) != NULL && *s != '/')
            unsetenv("TERMCAP");
#endif
          break;
        case 'o': /* DON'T initialize */
          doinit = 0;
          break;
        case 'c': /* Color on/off */
          if (strcmp("on", optarg) == 0) {
            usecolor = 1;
            stdattr = XA_BOLD;
            break;
          }
          if (strcmp("off", optarg) == 0) {
            usecolor = 0;
            stdattr = XA_NORMAL;
            break;
          }
          usage(env_args, optind - 1, mc);
          break;
        case 'a': /* Attributes on/off */
          if (strcmp("on", optarg) == 0) {
            useattr = 1;
            break;
          }
          if (strcmp("off", optarg) == 0) {
            useattr = 0;
            break;
          }
          usage(env_args, optind - 1, mc);
          break;
        case 'd': /* Dial from the command line. */
          cmd_dial = optarg;
          break;
        case 'z': /* Enable status line. */
          use_status = 1;
          break;
        case 'C': /* Capturing */
          capfp = fopen(optarg, "a");
          if (capfp == NULL) {
            werror(_("Cannot open capture file"));
            exit(1);
          }
          docap = 1;
          vt_set(addlf, -1, docap, -1, -1, -1, -1, -1, addcr);
          break;
        case 'S': /* start Script */
          strncpy(scr_name, optarg, 33);
          break;
        case '7': /* 7bit fallback mode */
	  screen_ibmpc = screen_iso = 0;
          break;
	case '8': /* force 8bit mode */
	  screen_ibmpc = screen_iso = 1;
	  break;
        case 'w': /* Linewrap on */
          wrapln = 1;
          break;
        case 'H': /* Display in hex */
          display_hex = 1;
          break;
        case 'T':
          option_T_used = 1;
          break;
        case 'F': /* format of status line */
          set_status_line_format(optarg);
          break;
	case 'b':
	  cmdline_baudrate = optarg;
	  break;
	case 'D':
	  cmdline_device = optarg;
	  break;
	case 'R':
	  remote_charset = optarg;
	  break;
        default:
          usage(env_args, optind, mc);
          break;
      }

    /* Now, get portname if mentioned. Stop at end or '-'. */
    while (optind < argk && args[optind][0] != '-')
      use_port = args[optind++];

    /* Loop again if more options */
  } while (optind < argk);

  init_iconv(remote_charset);

  if (screen_iso && screen_ibmpc)
    /* init VT */
    vt_set(-1, -1, -1, -1, -1, -1, 1, -1, -1);

  /* Avoid fraude ! */	
  for (s = use_port; *s; s++)
    if (*s == '/')
      *s = '_';
  snprintf(parfile, sizeof(parfile), "%s/minirc.%s", CONFDIR, use_port);

  /* Get password file information of this user. */
  if ((pwd = getpwuid(getuid())) == NULL) {
    fputs(_("You don't exist. Go away.\n"), stderr);
    exit(1);
  }

  /* Remember home directory and username. */
  if ((s = getenv("HOME")) == NULL)
    strncpy(homedir, pwd->pw_dir, sizeof(homedir));
  else
    strncpy(homedir, s, sizeof(homedir));
  strncpy(username, pwd->pw_name, sizeof(username));

  /* Get personal parameter file */
  snprintf(pparfile, sizeof(pparfile), "%s/.minirc.%s", homedir, use_port);

  read_parms();
  num_hist_lines = atoi(P_HISTSIZE);
  strcpy(logfname,P_LOGFNAME);

  /* Set default terminal behaviour */
  addlf      = strcasecmp(P_ADDLINEFEED, "yes") == 0;
  local_echo = strcasecmp(P_LOCALECHO,   "yes") == 0;
  addcr      = strcasecmp(P_ADDCARRIAGERETURN, "yes") == 0;

  /* -w overrides config file */
  if (!wrapln)
    wrapln = strcasecmp(P_LINEWRAP, "yes") == 0;

  /* -H overrides config file */
  if (!display_hex)
    display_hex = strcasecmp(P_DISPLAYHEX, "yes") == 0;

  /* After reading in the config via read_parms we can possibly overwrite
   * the baudrate with a value given at the cmdline */
  if (cmdline_baudrate) {
    unsigned int b = strtol(cmdline_baudrate, (char **)NULL, 0);
    if (speed_valid(b)) {
      snprintf(P_BAUDRATE, sizeof(P_BAUDRATE), "%d", b);
      P_BAUDRATE[sizeof(P_BAUDRATE) - 1] = 0;
    }
  }

  /* Now we can also overwrite the device name, if one was given */
  if (cmdline_device) {
    strncpy(P_PORT, cmdline_device, sizeof(P_PORT));
    P_PORT[sizeof(P_PORT) - 1] = 0;
  }

  stdwin = NULL; /* It better be! */

  /* Reset colors if we don't use 'em. */
  if (!usecolor) {
    mfcolor = tfcolor = sfcolor = WHITE;
    mbcolor = tbcolor = sbcolor = BLACK;
    st_attr = XA_REVERSE;
  }

  if (dial_tty == NULL) {
    if (!dosetup) {
      while ((dial_tty = get_port(P_PORT)) != NULL && open_term(doinit, 1, 0) < 0)
        ;
      if (dial_tty == NULL)
        exit(1);
    }
  }
  else {
    if (!dosetup && open_term(doinit, 1, 0) < 0)
      exit(1);
  }

  mc_setenv("TERM", termtype);

  if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0)
    leave("");

  if (COLS < 40 || LINES < 10)
    leave(_("Sorry. Your screen is too small.\n"));

  if (dosetup) {
    if (config(1)) {
      mc_wclose(stdwin, 1);
      exit(0);
    }
    while ((dial_tty = get_port(P_PORT)) != NULL && open_term(doinit, 1, 0) < 0)
      ;
    if (dial_tty == NULL)
      exit(1);
  }

  /* Signal handling */
  signal(SIGTERM, hangsig);
  signal(SIGHUP, hangsig);
  signal(SIGINT, SIG_IGN);
  signal(SIGQUIT, SIG_IGN);
  signal(SIGPIPE, SIG_IGN);

#ifdef SIGTSTP
  signal(SIGTSTP, shjump);
  signal(SIGTTIN, SIG_IGN);
  signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTINT
  signal(SIGTINT, SIG_IGN);
#endif
#ifdef SIGWINCH
  signal(SIGWINCH, change_size);
#endif

#ifdef DEBUG
  for(c = 1; c < _NSIG; c++) {
    if (c == SIGTERM)
      continue; /* Saviour when hung */
    signal(c, signore);
  }
#endif

  keyboard(KINSTALL, 0);

  if (strcmp(P_BACKSPACE, "BS") != 0)
    keyboard(KSETBS, P_BACKSPACE[0] == 'B' ? 8 : 127);
  if (alt_override)
    keyboard(KSETESC, alt_code);
  else if (strcmp(P_ESCAPE, "^A") != 0) {
    switch (P_ESCAPE[0]) {
      case '^':
        c = P_ESCAPE[1] & 31;
        break;
      case 'E':
        c = 27;
        break;
      default:
        c = 128;
        break;
    }
    keyboard(KSETESC, c);
  }

  st = NULL;
  us = NULL;

  init_emul(VT100, 1);

  if (doinit)
    modeminit();

  if (option_T_used)
    mc_wprintf(us, "WARNING: Option -T ignored, use -F now\n\n");

  mc_wprintf(us, "\n%s %s\r\n", _("Welcome to minicom"), VERSION);
  mc_wprintf(us, "\n%s: %s\r\n", _("OPTIONS"), option_string);
#if defined (__DATE__) && defined (__TIME__)
  mc_wprintf(us, "%s %s, %s.\r\n",_("Compiled on"), __DATE__,__TIME__);
#endif
  {
    struct stat st;
    char port_date[20] = "";
    if (stat(P_PORT, &st) == 0)
      {
	time_t t = time(NULL);
        struct tm tm;
        if (   st.st_mtime + 20 * 60 * 60 > t
            && localtime_r(&st.st_mtime, &tm))
            {
              strftime(port_date, sizeof(port_date), ", %T", &tm);
              port_date[sizeof(port_date) - 1] = 0;
            }
      }
    mc_wprintf(us, "%s %s%s\r\n", _("Port"), P_PORT, port_date);
  }
  if (using_iconv())
    mc_wprintf(us, "%s\r\n", _("Using character set conversion"));
  mc_wprintf(us, _("\nPress %sZ for help on special keys%c\n\n"),esc_key(),'\r');

  readdialdir();

  if (scr_name[0])
    runscript (0, scr_name, "", "");

  if (cmd_dial)
    dialone(cmd_dial);

  set_local_echo(local_echo);
  set_addlf(addlf);
  set_line_timestamp(line_timestamp);

  /* The main loop calls do_terminal and gets a function key back. */
  while (!quit) {
    c = do_terminal();
dirty_goto:
    switch (c + 32 *(c >= 'A' && c <= 'Z')) {
      case 'a': /* Add line feed */
        toggle_addlf();
        s = addlf ?  _("Add linefeed ON") : _("Add linefeed OFF");
        status_set_display(s, 0);
        break;
      case 'u': /* Add carriage return */
        toggle_addcr();
        s = addcr ?  _("Add carriage return ON") : _("Add carriage return OFF");
        status_set_display(s, 0);
        break;
      case 'e': /* Local echo on/off. */
        toggle_local_echo();
        s = local_echo ?  _("Local echo ON") : _("Local echo OFF");
        status_set_display(s, 0);
        break;
      case 'z': /* Help */
        c = help();
        if (c != 'z')
          goto dirty_goto;
        break;
      case 'c': /* Clear screen */
        mc_winclr(us);
        break;
      case 'f': /* Send break */
        sendbreak();
        break;
      case 'b': /* Scroll back */
        scrollback();
        break;
      case 'm': /* Initialize modem */
        if (P_HASDCD[0]=='Y' && online >= 0) {
          c = ask(_("You are online. Really initialize?"), c1);
          if (c != 0)
            break;
        }
        modeminit();
        break;
      case 'q': /* Exit without resetting */
        c = ask(_("Leave without reset?"), c1);
        if (c == 0)
          quit = NORESET;
        if (!strcmp(P_MACCHG,"CHANGED")) {
          c = ask (_("Save macros?"),c1);
          if (c == 0)
            if (dodflsave() < 0) { /* fmg - error */
              c = 'O'; /* hehe */
              quit = 0;
              goto dirty_goto;
            }
        }
        break;
      case 'x': /* Exit Minicom */
        c = ask(_("Leave Minicom?"), c1);
        if (c == 0) {
          quit = RESET;
          if(online >= 0)
            do_hang(0);
          modemreset();
        }
        if (!strcmp(P_MACCHG,"CHANGED")) {
          c = ask (_("Save macros?"), c1);
          if (c == 0)
            if (dodflsave() < 0) { /* fmg - error */
              c = 'O'; /* hehe */
              quit = 0;
              goto dirty_goto;
            }
        }
        break;
      case 'l': /* Capture file */
        if (capfp == (FILE *)0 && !docap) {
          s = input(_("Capture to which file? "), capname);
          if (s == NULL || *s == 0)
            break;
          if ((capfp = fopen(s, "a")) == (FILE *)NULL) {
            werror(_("Cannot open capture file"));
            break;
          }
          docap = 1;
        } else if (capfp != (FILE *)0 && !docap) {
          c = ask(_("Capture file"), c3);
          if (c == 0) {
            fclose(capfp);
            capfp = (FILE *)NULL;
            docap = 0;
          }
          if (c == 1)
            docap = 1;
        } else if (capfp != (FILE *)0 && docap) {
          c = ask(_("Capture file"), c2);
          if (c == 0) {
            fclose(capfp);
            capfp = (FILE *)NULL;
            docap = 0;
          }
          if (c == 1)
            docap = 0;
        }
        vt_set(addlf, -1, docap, -1, -1, -1, -1, -1, addcr);
        break;
      case 'p': /* Set parameters */
        get_bbp(P_BAUDRATE, P_BITS, P_PARITY, P_STOPB, 0);
        port_init();
        show_status();
        quit = 0;
        break;
      case 'k': /* Run kermit */
        kermit();
        break;
      case 'h': /* Hang up */
        do_hang(1);
        break;
      case 'd': /* Dial */
        dialdir();
        break;
      case 't': /* Terminal emulation */
        c = dotermmenu();
        if (c > 0)
          init_emul(c, 1);
        break;
      case 'w': /* Line wrap on-off */
        c = !us->wrap;
        vt_set(addlf, c, docap, -1, -1, -1, -1, -1, addcr);
        s = c ? _("Linewrap ON") : _("Linewrap OFF");
	status_set_display(s, 0);
        break;
      case 'n': /* Line timestamp */
	toggle_line_timestamp();
        switch (line_timestamp)
          {
          default:
          case TIMESTAMP_LINE_OFF:
            s = _("Timestamp OFF");
            break;
          case TIMESTAMP_LINE_SIMPLE:
            s = _("Timestamp every line (simple)");
            break;
          case TIMESTAMP_LINE_EXTENDED:
            s = _("Timestamp every line (extended)");
            break;
          case TIMESTAMP_LINE_PER_SECOND:
            s = _("Timestamp lines every second");
            break;
          }
        status_set_display(s, 0);
        break;
      case 'o': /* Configure Minicom */
        (void) config(0);
        break;
      case 's': /* Upload */
        updown('U', 0);
        break;
      case 'r': /* Download */
        updown('D', 0);
        break;
      case 'j': /* Jump to a shell */
        shjump(0);
        break;
      case 'g': /* Run script */
        runscript(1, "", "", "");
        break;
      case 'i': /* Re-init, re-open portfd. */
        cursormode = (cursormode == NORMAL) ? APPL : NORMAL;
        keyboard(cursormode == NORMAL ? KCURST : KCURAPP, 0);
        show_status();
        break;
      case 'y': /* Paste file */
	paste_file();
	break;
      case EOF: /* Cannot read from stdin anymore, exit silently */
        quit = NORESET;
        break;
      default:
        break;
    }
  };

  /* Reset parameters */
  if (quit != NORESET)
    m_restorestate(portfd);
  else {
    if (P_LOGCONN[0] == 'Y' && online > 0)
      do_log("%s", _("Quit without reset while online."));
    m_hupcl(portfd, 0);
  }

  signal(SIGTERM, SIG_IGN);
  signal(SIGHUP, SIG_IGN);
#ifdef SIGTSTP
  signal(SIGTSTP, SIG_DFL);
#endif
  signal(SIGQUIT, SIG_DFL);

  if (capfp != (FILE *)0)
    fclose(capfp);
  mc_wclose(us, 0);
  mc_wclose(st, 0);
  mc_wclose(stdwin, 1);
  keyboard(KUNINSTALL, 0);
  lockfile_remove();
  close(portfd);

  if (quit != NORESET && P_CALLIN[0])
    fastsystem(P_CALLIN, NULL, NULL, NULL);

  close_iconv();

  return 0;
}
Ejemplo n.º 28
0
int main(int argc, char* argv[])
{
    printf("START! pid = %d\n", getpid());

    if (!system("./restart.rb"))
        exit(1);

    if (signal(SIGUSR1, RestartHandler) == SIG_ERR) {
        fprintf(stderr, "An error occurred while setting a signal handler.\n");
        exit(1);
    }

    bool fullscreen = true;
    s_config = new AppConfig(fullscreen, false, 1280, 800);
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
    SDL_Window* displayWindow;
    SDL_Renderer* displayRenderer;

    uint32_t flags = SDL_WINDOW_OPENGL | (s_config->fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
	int err = SDL_CreateWindowAndRenderer(s_config->width, s_config->height, flags, &displayWindow, &displayRenderer);
	if (err == -1 || !displayWindow || !displayRenderer) {
		fprintf(stderr, "SDL_CreateWindowAndRenderer failed!\n");
	}

	SDL_RendererInfo displayRendererInfo;
    SDL_GetRendererInfo(displayRenderer, &displayRendererInfo);
    /* TODO: Check that we have OpenGL */
    if ((displayRendererInfo.flags & SDL_RENDERER_ACCELERATED) == 0 ||
        (displayRendererInfo.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
        /* TODO: Handle this. We have no render surface and not accelerated. */
        fprintf(stderr, "NO RENDERER wtf!\n");
    }

    atexit(SDL_Quit);

    JOYSTICK_Init();

    AppConfig& config = *s_config;
    config.title = "riftty";

    //SDL_WM_SetCaption(config.title.c_str(), config.title.c_str());
    //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

    /*
    // clear
    glClearColor(s_clearColor.x, s_clearColor.y, s_clearColor.z, s_clearColor.w);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    SDL_GL_SwapWindow(displayWindow);
    */

    RiftSetup();

    RenderInit();

    win_init();

    init_config();

    struct passwd *pw = getpwuid(getuid());
    const char *homedir = pw->pw_dir;
    char config_filename[512];
    strncpy(config_filename, homedir, 512);
    strncat(config_filename, "/.riftty", 512);
    load_config(config_filename);

    cs_init();  // TODO: code pages do not want

    // TODO: determine this based on window-size & font-size or vice versa.
    cfg.rows = 25;
    cfg.cols = 80;

    // TODO: load config from /etc/riffty or ~/.rifttyrc
    finish_config();
    win_reconfig();

    // TODO: get SHELL from env

    cs_reconfig(); // TODO: do not want

    term_init();
    term_reset();
    term_resize(cfg.rows, cfg.cols);

    // TODO:
    int font_width = 10;
    int font_height = 10;
    unsigned short term_width = font_width * cfg.cols;
    unsigned short term_height = font_height * cfg.rows;

    char login[128];
    strncpy(login, getlogin(), 128);
    const char* login_argv[] = {"login", "-pfl", login, NULL};
    unsigned short rows = cfg.rows;
    unsigned short cols = cfg.cols;
    winsize ws = {rows, cols, term_width, term_height};
    child_create(login_argv, &ws);

    bool done = false;
    while (!done)
    {
        JOYSTICK_ClearFlags();

        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_QUIT:
                done = true;
                break;

            case SDL_MOUSEMOTION:
                if (event.motion.state & SDL_BUTTON(1)) {
                    // move touch
                }
                break;

            case SDL_MOUSEBUTTONDOWN:
                if (event.button.button == SDL_BUTTON_LEFT) {
                    // start touch
                }
                break;

            case SDL_MOUSEBUTTONUP:
                if (event.button.button == SDL_BUTTON_LEFT) {
                    // end touch
                }
                break;

            case SDL_JOYAXISMOTION:
                JOYSTICK_UpdateMotion(&event.jaxis);
                break;

            case SDL_JOYBUTTONDOWN:
            case SDL_JOYBUTTONUP:
                JOYSTICK_UpdateButton(&event.jbutton);
                break;

            case SDL_KEYDOWN:
            case SDL_KEYUP:
                if (ProcessKeyEvent(&event.key)) {
                    done = true;
                }
                break;
            }
        }

        if (!done)
        {
            if (s_needsRestart)
                Restart();

            unsigned int now = SDL_GetTicks();  // milliseconds
            float dt = (now - s_ticks) / 1000.0f;	// convert to seconds.
            s_ticks = now;

            //printf("fps = %.0f\n", 1.0f/dt);

            Process(dt);
            Render(dt);
        }
    }

    child_kill(true);
    win_shutdown();

    RiftShutdown();
    JOYSTICK_Shutdown();

    return 0;
}
Ejemplo n.º 29
0
/* Initialize the playing screen 
	We clear the whole screen.
*/
void 
playing_screen_init(Screen *this_screen) {
	int cur_start_row;
	
	this_screen->wl_size = WL_SIZE;
	this_screen->win_list = win;
	this_screen->screen_enter = screen_enter;
	this_screen->screen_exit = screen_exit;
	this_screen->keypress = keypress;
	
	cur_start_row = WL_START_ROW;	
	
	win_init(&title_win, cur_start_row, 0, 50, 128, 1, win_txt[1]);
	title_win.font = MEDIUMFONT;	
	title_win.flags |= WINFLG_CENTER;
	
	// The first line overlaps with the last line of the previous window
	cur_start_row += 49;

	win_init(&artist_win, cur_start_row, 0, 30, 128, 1, win_txt[2]);
	artist_win.font = MEDIUMFONT;	
	artist_win.flags |= WINFLG_CENTER;
	
	// leave some room between artist and time window
	cur_start_row += 30 + 5;			// 84
			
	win_init(&time_win, cur_start_row, 22, 10, 128-22, 0, win_txt[3]);
	time_win.font = SMALLFONT;
	
	// state windows lies between time window and progress bar
	cur_start_row +=  5;				// 89

	/* The state window, a bit higher than the time progress */
	win_init(&state_win, cur_start_row - 2, 1, 16, 18, 0, win_txt[4]);

	state_win.font = BIGFONT;
	win_new_text(&state_win, "\xB3"); 	// play icon == b3
	
	cur_start_row +=  5;				// 94
	
	/* This is our progressbar */
	win_init(&time_prog_win, cur_start_row, 22, 8, 102, 1, win_txt[5]);
	time_prog_win.font = SMALLFONT;
	time_prog_win.flags = WINFLG_BAR;
	time_prog_win.fg_color = DARK_GREY;
	time_prog_win.cur_char = 0;		/* current value */
	
	cur_start_row +=  16;				// 110

	/* The speaker indicator is on the same line as volume text */
	win_init(&speaker_win, cur_start_row, 15, 18, 15, 0, win_txt[6]);
	speaker_win.font = BIGFONT;
	win_new_text(&speaker_win, "\xB8");	// speaker icon on
	
	/* Our indicator for the volume (triangle progress bar) */
	win_init(&vol_ramp_win, cur_start_row, 31, 16, 50, 0, win_txt[7]);
	vol_ramp_win.flags = WINFLG_RAMP;
	vol_ramp_win.fg_color = BLACK;
	vol_ramp_win.cur_char = 100/2;		/* We initialize the volume with 100 % */

	/* The text portion of the volume follows on the same line as the ramp */
	win_init(&volume_win, cur_start_row, 88, 16, 128-88, 0, win_txt[8]);
	win_new_text(&volume_win, "100 %");
	
	cur_start_row +=  20;				// 130

	win_init(&rnd_win, cur_start_row, 0, 14, 32, 1, win_txt[9]);
	rnd_win.font = SMALLFONT;
	rnd_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE;
	rnd_win.fg_color = WHITE;
	rnd_win.bg_color = BLACK;
	win_new_text(&rnd_win, "RND" );
	
	win_init(&rpt_win, cur_start_row, 48, 14, 32, 1, win_txt[10]);
	rpt_win.font = SMALLFONT;
	rpt_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE;
	rpt_win.fg_color = WHITE;
	rpt_win.bg_color = BLACK;
	win_new_text(&rpt_win, "RPT" );
	
	win_init(&single_win, cur_start_row, 96, 14, 32, 1, win_txt[11]);
	single_win.font = SMALLFONT;
	single_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE;
	single_win.fg_color = WHITE;
	single_win.bg_color = BLACK;
	win_new_text(&single_win, "1" );
		
	cur_start_row +=  20;				// 150
	
	/* The caption window is the last window */
	win_init(&caption_win, cur_start_row, 0, WL_SMALL_HEIGHT, 128,0, win_txt[0]);
	caption_win.font = SMALLFONT;
	caption_win.fg_color = BLACK;
	caption_win.bg_color = LIGHT_GREY;
	caption_win.flags |= WINFLG_CENTER;
}
Ejemplo n.º 30
0
/*
 * The main terminal loop:
 *	- If there are characters received send them
 *	  to the screen via the appropriate translate function.
 */
int do_terminal(void)
{
  char buf[128];
  int buf_offset = 0;
  int c;
  int x;
  int blen;
  int zauto = 0;
  static const char zsig[] = "**\030B00";
  int zpos = 0;
  const char *s;
  dirflush = 0;
  WIN *error_on_open_window = NULL;

dirty_goto:
  /* Show off or online time */
  update_status_time();

  /* If the status line was shown temporarily, delete it again. */
  if (tempst) {
    tempst = 0;
    mc_wclose(st, 1);
    st = NULL;
  }


  /* Auto Zmodem? */
  if (P_PAUTO[0] >= 'A' && P_PAUTO[0] <= 'Z')
    zauto = P_PAUTO[0];
  /* Set the terminal modes */
  setcbreak(2); /* Raw, no echo */

  keyboard(KSTART, 0);

  /* Main loop */
  while (1) {
    /* See if window size changed */
    if (size_changed) {
      size_changed = 0;
      wrapln = us->wrap;
      /* I got the resize code going again! Yeah! */
      mc_wclose(us, 0);
      us = NULL;
      if (st)
        mc_wclose(st, 0);
      st = NULL;
      mc_wclose(stdwin, 0);
      if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0)
        leave(_("Could not re-initialize window system."));
      /* Set the terminal modes */
      setcbreak(2); /* Raw, no echo */
      init_emul(terminal, 0);
    }
    /* Update the timer. */
    timer_update();

    /* check if device is ok, if not, try to open it */
    if (!get_device_status(portfd_connected)) {
      /* Ok, it's gone, most probably someone unplugged the USB-serial, we
       * need to free the FD so that a replug can get the same device
       * filename, open it again and be back */
      int reopen = portfd == -1;
      close(portfd);
      lockfile_remove();
      portfd = -1;
      if (open_term(reopen, reopen, 1) < 0) {
        if (!error_on_open_window)
          error_on_open_window = mc_tell(_("Cannot open %s!"), dial_tty);
      } else {
        if (error_on_open_window) {
          mc_wclose(error_on_open_window, 1);
          error_on_open_window = NULL;
        }
      }
    }

    /* Check for I/O or timer. */
    x = check_io(portfd_connected, 0, 1000,
                 buf + buf_offset, sizeof(buf) - buf_offset, &blen);
    blen += buf_offset;
    buf_offset = 0;

    /* Data from the modem to the screen. */
    if ((x & 1) == 1) {
      char obuf[sizeof(buf)];
      char *ptr;

      if (using_iconv()) {
        char *otmp = obuf;
        size_t output_len = sizeof(obuf);
        size_t input_len = blen;

        ptr = buf;
        do_iconv(&ptr, &input_len, &otmp, &output_len);

        // something happened at all?
        if (output_len < sizeof(obuf))
          {
            if (input_len)
              { // something remained, we need to adapt buf accordingly
                memmove(buf, ptr, input_len);
                buf_offset = input_len;
              }

            blen = sizeof(obuf) - output_len;
            ptr = obuf;
          }
	else
	  ptr = buf;
      } else {
        ptr = buf;
      }

      while (blen-- > 0) {
        /* Auto zmodem detect */
        if (zauto) {
          if (zsig[zpos] == *ptr)
            zpos++;
          else
            zpos = 0;
        }
        if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S')
          *ptr &= 0x7f;
        if (display_hex) {
          unsigned char c = *ptr++;
          unsigned char u = c >> 4;
          c &= 0xf;
          vt_out(u > 9 ? 'a' + (u - 10) : '0' + u);
          vt_out(c > 9 ? 'a' + (c - 10) : '0' + c);
          vt_out(' ');
        } else
          vt_out(*ptr++);
        if (zauto && zsig[zpos] == 0) {
          dirflush = 1;
          keyboard(KSTOP, 0);
          updown('D', zauto - 'A');
          dirflush = 0;
          zpos = 0;
          blen = 0;
          goto dirty_goto;
        }
      }
      mc_wflush();
    }