コード例 #1
0
ファイル: MapObject.cpp プロジェクト: jasonjei/libyaml-cpp
void MapObject::exportYaml(std::wstring fileName) {
	yaml_emitter_t emitter;
	yaml_event_t event;
 
	FILE *file;
	_wfopen_s(&file, fileName.c_str(), _T("wb"));
 
	yaml_emitter_initialize(&emitter);
	yaml_emitter_set_output_file(&emitter, file);
	yaml_emitter_set_encoding(&emitter, YAML_UTF8_ENCODING);
 
	if (! yamlDocProlog(&emitter, &event))
		return;
 
	if (this->mapPtr->map.size()) yamlMap(&emitter, &event, this->mapPtr);
	else if (this->mapObjects.size()) yamlSequence(&emitter, &event, &this->mapObjects, (this->flow == true ? 1 : 0));
	else {
		yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*) (this->value.c_str()), (int) this->value.length(), 1, 1, YAML_ANY_SCALAR_STYLE);
		yaml_emitter_emit(&emitter, &event);
	}
 
	yamlDocEpilog(&emitter, &event);
	yaml_emitter_flush(&emitter);
	fclose(file);
 
	yaml_event_delete(&event);
	yaml_emitter_delete(&emitter);
}
コード例 #2
0
ファイル: rubyext.c プロジェクト: alloy/MacRuby
static VALUE
rb_yaml_emitter_document(VALUE self, SEL sel, int argc, VALUE *argv)
{
    yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;

    VALUE impl_beg = Qnil, impl_end = Qnil;
    rb_scan_args(argc, argv, "02", &impl_beg, &impl_end);
    if (NIL_P(impl_beg)) {
	impl_beg = Qfalse;
    }
    if (NIL_P(impl_end)) {
	impl_end = Qtrue;
    }

    yaml_event_t ev;
    yaml_document_start_event_initialize(&ev, NULL, NULL, NULL, 0);
    yaml_emitter_emit(emitter, &ev);

    rb_yield(self);

    yaml_document_end_event_initialize(&ev, 1);
    yaml_emitter_emit(emitter, &ev);
    yaml_emitter_flush(emitter);
    return self;
}
コード例 #3
0
ファイル: YamlEmitter.cpp プロジェクト: darkfall/exlibs
result_t CYamlEmitter::SaveStreamEnd ( yaml_emitter_t& _emitter ) const
{
    result_t result_t = eResult_OK;

    yaml_event_t event;
    yaml_stream_end_event_initialize ( &event );
    yaml_emitter_emit ( &_emitter, &event ) || yaml_emitter_flush ( &_emitter );

    return eResult;
}
コード例 #4
0
ファイル: YamlEmitter.cpp プロジェクト: darkfall/exlibs
result_t CYamlEmitter::SaveStreamStart ( yaml_emitter_t& _emitter ) const
{
    result_t result_t = eResult_OK;

    yaml_event_t event;
    yaml_stream_start_event_initialize ( &event, GetEncoding(m_Encoding) );
    yaml_emitter_emit ( &_emitter, &event ) || yaml_emitter_flush ( &_emitter );

    return eResult;
}
コード例 #5
0
ファイル: rubyext.c プロジェクト: alloy/MacRuby
static VALUE
rb_yaml_emitter_stream(VALUE self, SEL sel)
{
    yaml_event_t ev;
    yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;

    // RADAR: allow the encoding to be configurable
    yaml_stream_start_event_initialize(&ev, YAML_UTF8_ENCODING); 
    yaml_emitter_emit(emitter, &ev);

    rb_yield(self);

    yaml_stream_end_event_initialize(&ev);
    yaml_emitter_emit(emitter, &ev);
    yaml_emitter_flush(emitter);
    yaml_emitter_delete(emitter);
    // XXX: more cleanup here...
    return RYAMLEmitter(self)->output;
}
コード例 #6
0
ファイル: run-dumper.c プロジェクト: jubalh/libyaml
int
main(int argc, char *argv[])
{
    int number;
    int canonical = 0;
    int unicode = 0;

    number = 1;
    while (number < argc) {
        if (strcmp(argv[number], "-c") == 0) {
            canonical = 1;
        }
        else if (strcmp(argv[number], "-u") == 0) {
            unicode = 1;
        }
        else if (argv[number][0] == '-') {
            printf("Unknown option: '%s'\n", argv[number]);
            return 0;
        }
        if (argv[number][0] == '-') {
            if (number < argc-1) {
                memmove(argv+number, argv+number+1, (argc-number-1)*sizeof(char *));
            }
            argc --;
        }
        else {
            number ++;
        }
    }

    if (argc < 2) {
        printf("Usage: %s [-c] [-u] file1.yaml ...\n", argv[0]);
        return 0;
    }

    for (number = 1; number < argc; number ++)
    {
        FILE *file;
        yaml_parser_t parser;
        yaml_emitter_t emitter;

        yaml_document_t document;
        unsigned char buffer[BUFFER_SIZE];
        size_t written = 0;
        yaml_document_t documents[MAX_DOCUMENTS];
        size_t document_number = 0;
        int done = 0;
        int count = 0;
        int error = 0;
        int k;
        memset(buffer, 0, BUFFER_SIZE);
        memset(documents, 0, MAX_DOCUMENTS*sizeof(yaml_document_t));

        printf("[%d] Loading, dumping, and loading again '%s': ", number, argv[number]);
        fflush(stdout);

        file = fopen(argv[number], "rb");
        assert(file);

        assert(yaml_parser_initialize(&parser));
        yaml_parser_set_input_file(&parser, file);
        assert(yaml_emitter_initialize(&emitter));
        if (canonical) {
            yaml_emitter_set_canonical(&emitter, 1);
        }
        if (unicode) {
            yaml_emitter_set_unicode(&emitter, 1);
        }
        yaml_emitter_set_output_string(&emitter, buffer, BUFFER_SIZE, &written);
        yaml_emitter_open(&emitter);

        while (!done)
        {
            if (!yaml_parser_load(&parser, &document)) {
                error = 1;
                break;
            }

            done = (!yaml_document_get_root_node(&document));
            if (!done) {
                assert(document_number < MAX_DOCUMENTS);
                assert(copy_document(&(documents[document_number++]), &document));
                assert(yaml_emitter_dump(&emitter, &document) ||
                        (yaml_emitter_flush(&emitter) && print_output(argv[number], buffer, written, count)));
                count ++;
            }
            else {
                yaml_document_delete(&document);
            }
        }

        yaml_parser_delete(&parser);
        assert(!fclose(file));
        yaml_emitter_close(&emitter);
        yaml_emitter_delete(&emitter);

        if (!error)
        {
            count = done = 0;
            assert(yaml_parser_initialize(&parser));
            yaml_parser_set_input_string(&parser, buffer, written);

            while (!done)
            {
                assert(yaml_parser_load(&parser, &document) || print_output(argv[number], buffer, written, count));
                done = (!yaml_document_get_root_node(&document));
                if (!done) {
                    assert(compare_documents(documents+count, &document) || print_output(argv[number], buffer, written, count));
                    count ++;
                }
                yaml_document_delete(&document);
            }
            yaml_parser_delete(&parser);
        }

        for (k = 0; k < document_number; k ++) {
            yaml_document_delete(documents+k);
        }

        printf("PASSED (length: %d)\n", written);
        print_output(argv[number], buffer, written, -1);
    }

    return 0;
}
コード例 #7
0
ファイル: main.c プロジェクト: fengye/swfdec-dumper
int main (int argc, char **argv)
{
  SwfdecPlayer *player;
  SwfdecURL *url;
  yaml_emitter_t emitter;
  yaml_event_t event;
  FILE *output;

  int i;
  const char* directory_prefix = NULL;
  char output_filename_serial[256] = {0};
  unsigned long frame_interval = 0;
  unsigned long accum_interval = 0;
  int frame_count = 1;
  unsigned int override_width = 0;
  unsigned int override_height = 0;
  float override_scale = 1.0f;
  const char* input_filename = NULL;
  const char* output_filename = NULL;
  int base_index = 0;
  cairo_surface_t *surface[2] = {NULL, NULL};
  cairo_t *cr[2] = {NULL, NULL};
  int loop = 0;
  int center_x = -1;
  int center_y = -1;
  
  /* Parse the command line arguments */
  for(i = 1; i < argc; ++i )
  {
    const char* arg = argv[i];
    if ( arg[0] == '-' )
    {
      if ( arg[1] == 'w' )
      {
        override_width = atoi(arg+3);
      }
      else if ( arg[1] == 'h' )
      {
        override_height = atoi(arg+3);
      }
      else if ( arg[1] == 's' )
      {
        override_scale = (float)atof(arg+3);
      }
      else if ( arg[1] == 'f' )
      {
        frame_count = atof(arg+3);
      }
      else if ( arg[1] == 'l' )
      {
        loop = atoi(arg+3);
      }
      else if ( arg[1] == 'd' )
      {
        directory_prefix = arg+3;
      }
      else if ( arg[1] == 'x' )
      {
        center_x = atoi(arg+3);
      }
      else if ( arg[1] == 'y' )
      {
        center_y = atoi(arg+3);
      }
      else
      {
        printf("Unknown option: %s\n", arg);
      }
    }
    else
    {
      if (!input_filename )
      {
        input_filename = arg;
      }
      else
      {
        output_filename = arg;
      }
    }
  }

  if (!input_filename || !output_filename)
  {
    print_usage(argv[0]);
    return 1;
  }

  /* Create the Emitter object. */
  yaml_emitter_initialize(&emitter);

  
  // init
  swfdec_init ();

  url = swfdec_url_new_from_input (input_filename);
  if (!url)
  {
     printf("Input file not found: %s.\n", input_filename);
     return 1;
  }

  /* Set a file output. */
  sprintf(output_filename_serial, "%s.yaml", output_filename);
  output = fopen(output_filename_serial, "wb");
  yaml_emitter_set_output_file(&emitter, output);
  //yaml_emitter_set_output(&emitter, write_handler, output);

  player = swfdec_player_new (NULL);
  swfdec_player_set_url (player, url);

  /* Create and emit the STREAM-START event. */
  yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING);
  yaml_emitter_emit(&emitter, &event);
  /* Create document */
  yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 1);
  yaml_emitter_emit(&emitter, &event);
  /* Create mapping */
  yaml_mapping_start_event_initialize(&event, NULL, NULL, 1, YAML_ANY_SCALAR_STYLE);
  yaml_emitter_emit(&emitter, &event);

  yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"type", strlen("type"), 1, 1, YAML_ANY_SCALAR_STYLE);
  yaml_emitter_emit(&emitter, &event);  
  yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"keyframe", strlen("keyframe"), 1, 1, YAML_ANY_SCALAR_STYLE);
  yaml_emitter_emit(&emitter, &event);

  swfdec_player_advance (player, 0);

  if ( override_width == 0 || override_height == 0 )
  {
    swfdec_player_get_default_size(player, &override_width, &override_height);
  }

  /* need to set player size */
  swfdec_player_set_size(player, 
    (unsigned int)override_width * override_scale, 
    (unsigned int)override_height * override_scale);

  {
  char buf[256] = {0};

  yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"defaultframerate", strlen("defaultframerate"), 1, 1, YAML_ANY_SCALAR_STYLE);
  yaml_emitter_emit(&emitter, &event);
  sprintf(buf, "%f", swfdec_player_get_rate(player));  
  yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)buf, strlen(buf), 1, 1, YAML_ANY_SCALAR_STYLE);
  yaml_emitter_emit(&emitter, &event);

  }

  yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"loop", strlen("loop"), 1, 1, YAML_ANY_SCALAR_STYLE);
  yaml_emitter_emit(&emitter, &event);  
  if ( loop )
  {
    yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"true", strlen("true"), 1, 1, YAML_ANY_SCALAR_STYLE);
    yaml_emitter_emit(&emitter, &event);
  }
  else
  {
    yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"false", strlen("false"), 1, 1, YAML_ANY_SCALAR_STYLE);
    yaml_emitter_emit(&emitter, &event);
  }

  if (center_x >= 0 )
  {
    char buf[256] = {0};
    yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"center_point_x", strlen("center_point_x"), 1, 1, YAML_ANY_SCALAR_STYLE); 
    yaml_emitter_emit(&emitter, &event);

    sprintf(buf, "%d", center_x);
    yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)buf, strlen(buf), 1, 1, YAML_ANY_SCALAR_STYLE);
    yaml_emitter_emit(&emitter, &event);
  }
  if (center_y >= 0 )
  {
    char buf[256] = {0};
    yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"center_point_y", strlen("center_point_y"), 1, 1, YAML_ANY_SCALAR_STYLE); 
    yaml_emitter_emit(&emitter, &event);

    sprintf(buf, "%d", center_y);
    yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)buf, strlen(buf), 1, 1, YAML_ANY_SCALAR_STYLE);
    yaml_emitter_emit(&emitter, &event);
  }
  

  printf("Default frame rate: %f\n", swfdec_player_get_rate(player));
  frame_interval = (unsigned long)(1000.0 / swfdec_player_get_rate(player));
  printf("Default frame interval: %ld\n", frame_interval);

  
  yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)"content", strlen("content"), 1, 1, YAML_ANY_SCALAR_STYLE);
  yaml_emitter_emit(&emitter, &event);  

  /* Create mapping */
  yaml_mapping_start_event_initialize(&event, NULL, NULL, 1, YAML_ANY_SCALAR_STYLE);
  yaml_emitter_emit(&emitter, &event);

  for(i = 0; i < frame_count; ++i )
  {
    int new_index = (base_index + 1) % 2;
    surface[new_index] = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 
      (unsigned int)(override_width * override_scale), 
      (unsigned int)(override_height * override_scale));
    cr[new_index] = cairo_create (surface[new_index]);
    // render the image
    swfdec_player_render (player, cr[new_index]);

    frame_interval = swfdec_player_get_next_event(player);
    accum_interval += frame_interval;

    if ( compare_images(surface[base_index], surface[new_index]) <= 5 )
    {
      cairo_destroy (cr[new_index]);
      cairo_surface_destroy (surface[new_index]);
      cr[new_index] = NULL;
      surface[new_index] = NULL;

      if ( frame_interval > 0 )
        swfdec_player_advance (player, frame_interval);
    }
    else
    {

      if ( surface[base_index] && surface[new_index] )
      {
        char buf[256] = {0};
        sprintf(buf, "%f", (double)accum_interval / 1000.0);
        yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)output_filename_serial, strlen(output_filename_serial), 1, 1, YAML_ANY_SCALAR_STYLE);
        yaml_emitter_emit(&emitter, &event);
        yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)buf, strlen(buf), 1, 1, YAML_ANY_SCALAR_STYLE);
        yaml_emitter_emit(&emitter, &event);
        accum_interval = 0;
      }

      cairo_destroy (cr[base_index]);
      cairo_surface_destroy (surface[base_index]);
      cr[base_index] = NULL;
      surface[base_index] = NULL;

      if (directory_prefix)
        sprintf(output_filename_serial, "%s/%s%3.3d.png", directory_prefix, output_filename, i+1);
      else
        sprintf(output_filename_serial, "%s%3.3d.png", output_filename, i+1);

      cairo_surface_write_to_png (surface[new_index], output_filename_serial);
      if ( frame_interval > 0 )
        swfdec_player_advance (player, frame_interval);
      
      base_index = new_index;
    }
  }

  /* the last frame output */
  if ( surface[base_index] )
  {
    char buf[256] = {0};
    sprintf(buf, "%f", (double)accum_interval / 1000.0);
    yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)output_filename_serial, strlen(output_filename_serial), 1, 1, YAML_ANY_SCALAR_STYLE);
    yaml_emitter_emit(&emitter, &event);
    yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*)buf, strlen(buf), 1, 1, YAML_ANY_SCALAR_STYLE);
    yaml_emitter_emit(&emitter, &event);
    accum_interval = 0;
  }

  cairo_destroy (cr[base_index]);
  cairo_surface_destroy (surface[base_index]);

  g_object_unref (player);
  swfdec_url_free(url);

  /* End mapping */
  yaml_mapping_end_event_initialize(&event);
  yaml_emitter_emit(&emitter, &event);

  /* End mapping */
  yaml_mapping_end_event_initialize(&event);
  yaml_emitter_emit(&emitter, &event);

  /* End of document */
  yaml_stream_end_event_initialize(&event);
  yaml_emitter_emit(&emitter, &event);

  /* Create and emit the STREAM-END event. */
  yaml_stream_end_event_initialize(&event);
  yaml_emitter_emit(&emitter, &event);

  yaml_emitter_flush(&emitter);
  /* Destroy the Emitter object. */
  yaml_emitter_delete(&emitter);

  fclose(output);

  return 0;
}