コード例 #1
0
ファイル: snb.c プロジェクト: The-Compiler/snb
int main(int argc, char *argv[]) {
  FILE *fp;
  Result res;
  Entry *root;
  char *path, *locale;
  int opt;

#ifdef SCR_WIDTH
  ui_scr_width = SCR_WIDTH;
#else
  ui_scr_width = 0;
#endif

  locale = "";
  while ((opt = getopt(argc, argv, "hvl:w:b")) != -1) {
    switch (opt) {
      case 'b':
        use_term_colors = !use_term_colors;
        break;
      case 'w':
        ui_scr_width = atoi(optarg);
        if (ui_scr_width < 0) {
          fprintf(stderr, "WARN: Wrong width value, fixed-column is off\n");
          fprintf(stderr, "Press enter to continue.\n");
          fgetc(stdin);
          ui_scr_width = 0;
        }
        break;
      case 'l':
        locale = optarg;
        break;
      case 'v':
        version();
        break;
      case 'h':
      default:
        usage(argv[0]);
        break;
    }
  }

  fp = NULL;

  if (setlocale(LC_ALL, locale) == NULL) {
    fprintf(stderr, "WARN: Couldn't change LC_ALL to '%s'\n", locale);
    fprintf(stderr, "Press enter to continue.\n");
    fgetc(stdin);
  }

  if (optind < argc) {
    fp = fopen(argv[optind], "r");
    if (fp == NULL) {
      perror("Can't open your file");
      exit(1);
    }
    path = argv[optind];
  }
#ifdef DEFAULT_FILE
  else {
    fp = fopen(DEFAULT_FILE, "r");
    path = DEFAULT_FILE;
  }
#endif

  UI_File.path = NULL;
  if (fp) {
    res = data_load(fp);
    UI_File.loaded = true;
    UI_File.path = realpath(path, NULL);
    if (!UI_File.path) {
      perror("Couldn't resolve path");
      exit(3);
    }
    fclose(fp);
  } else {
    res = entry_new(32);
    UI_File.loaded = false;
  }

  if (!res.success) {
    fwprintf(stderr, L"ERROR: %S.\n", res.msg);
    perror("Unix error");
    exit(2);
  }

  ui_start();

  root = (Entry *)res.data;
  if (!fp)
    root->length = 0;
  res = ui_set_root(root);
  if (!res.success) {
    fwprintf(stderr, L"ERROR: %S.\n", res.msg);
    perror("Unix error");
    exit(3);
  }
  ui_refresh();

  ui_mainloop();
  ui_stop();

  res = ui_get_root();
  if (!res.success) {
    fwprintf(stderr, L"ERROR: %S.\n", res.msg);
    perror("Unix error");
    exit(4);
  }

  data_unload((Entry *)res.data);
  free(UI_File.path);

  return 0;
}
コード例 #2
0
ファイル: dt_player.c プロジェクト: jih488/dtplayer_c
int main (int argc, char **argv)
{
    int ret = 0;
    version_info ();
    if (argc < 2)
    {
        dt_info ("", " no enough args\n");
        show_usage ();
        return 0;
    }
    memset(&ply_ctx,0,sizeof(ply_ctx_t));
    ply_ctx.disp_width = 720;
    ply_ctx.disp_height = 480;

    player_register_all();
    register_ex_all();

    dtplayer_para_t para;
    parse_cmd(argc,argv,&para);
    
    void *player_priv = dtplayer_init (&para);
    if (!player_priv)
        return -1;

    //get media info
	dt_media_info_t info;
	ret = dtplayer_get_mediainfo(player_priv, &info);
	if(ret < 0)
	{
		dt_info(TAG,"Get mediainfo failed, quit \n");
		return -1;
	}
	dt_info(TAG,"Get Media Info Ok,filesize:%lld fulltime:%lld S \n",info.file_size,info.duration);

    //set display win size
    int width = 720;
    int height = 480;
    if(info.has_video)
    {
        vstream_info_t *vstream = info.vstreams[0];
        width = vstream->width;
        height = vstream->height;
    }
    if(width <= 0 || width > 1280)
        width = 720;
    if(height <= 0 || height >720)
        height = 480;

    dtplayer_set_video_size(player_priv, width, height);

    ui_init(width,height); 
    render_init();

	dtplayer_start (player_priv);

    //event handle
    player_event_t event = EVENT_NONE;
    int arg = -1;
    while(1)
    {
        if(ply_ctx.exit_flag == 1)
            break;
        event = get_event(&arg,&ply_ctx);
        if(event == EVENT_NONE)
        {
            usleep(100);
            continue;
        }
        
        switch(event)
        {
            case EVENT_PAUSE:
                dtplayer_pause (player_priv);
                break;
            case EVENT_RESUME:
                dtplayer_resume (player_priv);
                break;
            case EVENT_SEEK:
                dtplayer_seekto (player_priv, arg);
                break;
            case EVENT_STOP:
                dtplayer_stop (player_priv);
                goto QUIT_CHECK;
                break;
            default:
                dt_info(TAG,"UNKOWN CMD, IGNORE \n");
                break;
        }

    }
QUIT_CHECK:
    while(!ply_ctx.exit_flag)
    {
        usleep(100);
        break;
    }
    render_stop();
    ui_stop(); 
    dt_info ("", "QUIT DTPLAYER-TEST\n");
    return 0;
}