Пример #1
0
int main(int argc,char *argv[])
{
char *ptr;

progname=argv[0]?argv[0]:"aylet";
if((ptr=strrchr(progname,'/'))!=NULL)
  progname=ptr+1;

parseoptions(argc,argv);

if(list_only)
  {
  do_list();
  exit(0);
  }

/* even when not using curses/GTK+ we go via the UI code
 * (apart from the above :-)).
 */
ui_init(argc,argv);

if(!sound_init())
  {
  ui_end();
  fprintf(stderr,"%s: couldn't open sound device.\n",progname);
  exit(1);
  }

mainloop();

if(sound_enabled)
  sound_end();

ui_end();

exit(0);
}
Пример #2
0
/* read a file and play it. sound_init() should already have been called,
 * and sound device should still be open when we exit.
 */
void mainloop(void)
{
int oldfile=-1;

aydata.filedata=NULL;
aydata.tracks=NULL;

/* this is kind of a weird multi-level event loop (if
 * you consider do_interrupt()); it's difficult to do it very
 * differently without turning the Z80 emulation inside-out.
 */
while(!want_quit)
  {
  /* load a new file if we need to */
  if(ay_file!=oldfile)
    {
    if(aydata.tracks) free(aydata.tracks);
    if(aydata.filedata) free(aydata.filedata);
    
    if(!read_ay_file(ay_filenames[ay_file]))
      {
      ui_end();
      if(sound_enabled) sound_end();
      fprintf(stderr,"%s: reading `%s' failed.\n",
              progname,ay_filenames[ay_file]);
      exit(1);
      }

    if(!play_one_track_only)
      ay_track=0;
    else
      {
      ay_track=play_one_track_only-1;
      
      if(ay_track>=aydata.num_tracks)
        {
        ui_end();
        if(sound_enabled) sound_end();
        fprintf(stderr,"%s: `%s' has only %d track%s.\n",
                progname,ay_filenames[ay_file],
                aydata.num_tracks,(aydata.num_tracks==1)?"":"s");
        exit(1);
        }
      }

    if(go_to_last)
      {
      go_to_last=0;
      ay_track=aydata.num_tracks-1;
      }
    }
  
  oldfile=ay_file;

  /* only do the whole emulation thing if we're actually playing... */
  if(playing)
    {
    /* re-enable sound after stopping, if needed */
    if(!sound_enabled && !sound_init())
      {
      ui_end();
      fprintf(stderr,"%s: couldn't reopen sound device.\n",progname);
      exit(1);
      }
  
    ay_current_reg=0;
    sound_ay_reset();
    mem_init(ay_track);
    tunetime_reset();
    tsmax=FRAME_STATES_128;
    do_cpc=0;
    z80loop(aydata.tracks[ay_track].data,
            aydata.tracks[ay_track].data_stacketc);
    }

  /* if stopped, close sound device */
  if(sound_enabled && !playing)
    sound_end();
  
  /* do reset now, so any paused/stopped status time makes sense */
  tunetime_reset();
  while((!playing || paused) && ay_file==oldfile)
    do_interrupt();
  }

free(aydata.tracks);
free(aydata.filedata);
}
Пример #3
0
int main(int argc, char *argv[])
{
	const char *term = getenv("TERM");
	const char *home = getenv("HOME");
	const char *tag = NULL;
	const char *rc = NULL;
	const char *command = NULL;
	char *command_history_filename;
	char *search_history_filename;
	char *editor_dir;
	bool read_rc = true;
	int i;

	if (!home)
		home = "";
	home_dir = xstrdup(home);

	for (i = 1; i < argc; i++) {
		const char *opt = argv[i];

		if (opt[0] != '-' || !opt[1])
			break;
		if (!opt[2]) {
			switch (opt[1]) {
			case 'R':
				read_rc = false;
				continue;
			case 't':
				tag = opt_arg(opt, argv[++i]);
				continue;
			case 'r':
				rc = opt_arg(opt, argv[++i]);
				continue;
			case 'c':
				command = opt_arg(opt, argv[++i]);
				continue;
			case 'V':
				printf("%s %s\nWritten by Timo Hirvonen\n", program, version);
				return 0;
			}
			if (opt[1] == '-') {
				i++;
				break;
			}
		}
		printf("Usage: %s [-R] [-V] [-c command] [-t tag] [-r rcfile] [file]...\n", argv[0]);
		return 1;
	}

	if (!isatty(1)) {
		fprintf(stderr, "stdout doesn't refer to a terminal\n");
		return 1;
	}
	if (term == NULL || term[0] == 0) {
		fprintf(stderr, "TERM not set\n");
		return 1;
	}
	switch (term_init(term)) {
	case -1:
		fprintf(stderr, "terminal is hardcopy\n");
		return 1;
	case -2:
		fprintf(stderr, "terminal could not be found\n");
		return 1;
	case -3:
		fprintf(stderr, "terminfo database could not be found\n");
		return 1;
	}

	// create this early. needed if lock-files is true
	editor_dir = editor_file("");
	mkdir(editor_dir, 0755);
	free(editor_dir);

	setlocale(LC_CTYPE, "");
	charset = nl_langinfo(CODESET);
	if (streq(charset, "UTF-8"))
		term_utf8 = true;

	exec_builtin_rc(builtin_rc);
	fill_builtin_colors();

	// NOTE: syntax_changed() uses window. should possibly create window after reading rc
	window = new_window();
	root_frame = new_root_frame(window);

	if (read_rc) {
		if (rc) {
			read_config(commands, rc, true);
		} else {
			char *filename = editor_file("rc");
			if (read_config(commands, filename, false)) {
				free(filename);
				filename = xsprintf("%s/rc", pkgdatadir);
				read_config(commands, filename, true);
			}
			free(filename);
		}
	}

	update_all_syntax_colors();
	sort_aliases();

	/* Terminal does not generate signals for control keys. */
	set_signal_handler(SIGINT, SIG_IGN);
	set_signal_handler(SIGQUIT, SIG_IGN);
	set_signal_handler(SIGPIPE, SIG_IGN);

	/* Terminal does not generate signal for ^Z but someone can send
	 * us SIGTSTP nevertheless. SIGSTOP can't be caught.
	 */
	set_signal_handler(SIGTSTP, handle_sigtstp);

	set_signal_handler(SIGCONT, handle_sigcont);
	set_signal_handler(SIGWINCH, handle_sigwinch);

	load_file_history();
	command_history_filename = editor_file("command-history");
	search_history_filename = editor_file("search-history");
	history_load(&command_history, command_history_filename, command_history_size);
	history_load(&search_history, search_history_filename, search_history_size);
	if (search_history.count)
		search_set_regexp(search_history.ptrs[search_history.count - 1]);

	/* Initialize terminal but don't update screen yet.  Also display
	 * "Press any key to continue" prompt if there were any errors
	 * during reading configuration files.
	 */
	term_raw();
	if (nr_errors) {
		any_key();
		clear_error();
	}

	editor_status = EDITOR_RUNNING;

	for (; i < argc; i++)
		window_open_buffer(window, argv[i], false, NULL);
	if (window->views.count == 0)
		window_open_empty_buffer(window);
	set_view(window->views.ptrs[0]);

	if (command || tag)
		resize();

	if (command)
		handle_command(commands, command);
	if (tag) {
		PTR_ARRAY(array);
		ptr_array_add(&array, xstrdup("tag"));
		ptr_array_add(&array, xstrdup(tag));
		ptr_array_add(&array, NULL);
		run_commands(commands, &array);
		ptr_array_free(&array);
	}
	resize();
	main_loop();
	ui_end();

	// unlock files and add files to file history
	remove_frame(root_frame);

	history_save(&command_history, command_history_filename);
	history_save(&search_history, search_history_filename);
	free(command_history_filename);
	free(search_history_filename);
	save_file_history();
	return 0;
}
Пример #4
0
static void run_main_loop(void)
{
    glViewport(0, 0, window_w, window_h);
    glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, window_w, window_h, 0, -1, 1);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    ui_begin();

    if (search_active)
    {
        float start_time = glfwGetTime();

        if (ui.key == KEY_ESCAPE)
            search_active = 0;

        /* ignore events during search */
        ui.key = ui.mod = 0;
        ui.down = ui.middle = ui.right = 0;

        while (glfwGetTime() < start_time + 0.2)
        {
            search_hit_count = fz_search_page_number(ctx, doc, search_page, search_needle,
                               search_hit_bbox, nelem(search_hit_bbox));
            if (search_hit_count)
            {
                search_active = 0;
                search_hit_page = search_page;
                jump_to_page(search_hit_page);
                break;
            }
            else
            {
                search_page += search_dir;
                if (search_page < 0 || search_page == fz_count_pages(ctx, doc))
                {
                    search_active = 0;
                    break;
                }
            }
        }

        /* keep searching later */
        if (search_active)
            ui_needs_update = 1;
    }

    do_app();

    canvas_w = window_w - canvas_x;
    canvas_h = window_h - canvas_y;

    do_canvas();

    if (showinfo)
        do_info();

    if (showoutline)
        do_outline(outline, canvas_x);

    if (showsearch)
    {
        int state = ui_input(canvas_x, 0, canvas_x + canvas_w, ui.lineheight+4, &search_input);
        if (state == -1)
        {
            ui.focus = NULL;
            showsearch = 0;
        }
        else if (state == 1)
        {
            ui.focus = NULL;
            showsearch = 0;
            search_page = -1;
            if (search_needle)
            {
                fz_free(ctx, search_needle);
                search_needle = NULL;
            }
            if (search_input.end > search_input.text)
            {
                search_needle = fz_strdup(ctx, search_input.text);
                search_active = 1;
                search_page = currentpage;
            }
        }
        ui_needs_update = 1;
    }

    if (search_active)
    {
        char buf[256];
        sprintf(buf, "Searching page %d of %d.", search_page + 1, fz_count_pages(ctx, doc));
        ui_label_draw(canvas_x, 0, canvas_x + canvas_w, ui.lineheight+4, buf);
    }

    ui_end();

    glfwSwapBuffers(window);

    ogl_assert(ctx, "swap buffers");
}
Пример #5
0
void run_ui(void){
    ui_flag = 0;
    int i;
    char line[30];
    char name[30] = "";
    switch(ui_mode){
        case UI_MODE_MAIN:
            if(fgets(line, sizeof line - 1, stdin) == NULL){
                _NOP();//ui_mode = UI_MODE_BUILD_LINE;
            }
            printf("\n");
            if(sscanf(line, "%02d", &i)){
                i = i+10;
                if(i > 10 && i <= 14){
                    ui_mode = i;
                    ui_flag = 1;
                }
                else {
                    ui_end();
                }
            }
            else {
                ui_end();
            }
            break;
            
        case UI_MODE_END:
            setup_ui();
            break;
            
        case UI_MODE_BUILD_LINE:
            printf("\n%s\n", line);
            ui_mode = UI_MODE_MAIN;
            break;
            
        case UI_MODE_DISPLAY_TIME:
            display_time();
            ui_end();
            break;
        case UI_MODE_TZ:
            if(fgets(line, sizeof line - 1, stdin) == NULL){
                _NOP();//ui_mode = UI_MODE_BUILD_LINE;
            }
            if(sscanf(line, "%29s", name)){
                printf("%s\n", name);
                if(name[0] == '!'){
                    ui_end();
                }
                else if(name[0] == 'l'){
                    list_zones();
                    printf(">");
                }
                else if(strlen(name)>3){
                    if(tz_update(name)){
                        printf("Set %s\n", name);
                        ui_end();
                    }
                }
                else{
                    printf("\nPlease Enter a Timezone\nl - to list\n! - to exit\n>");
                }
            }
            break;
        case UI_MODE_TEST:
            ds3231_debug();
            ui_end();
            break;
    }
}