<commit_before>/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 *
 *  Based on code from the OggTheora software codec source code,
 *  Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors.
 */
#include <errno.h>
#include <stdlib.h>
#include <string.h>

#include "vpx/vpx_integer.h"
#include "y4minput.h"

// Reads 'size' bytes from 'file' into 'buf' with some fault tolerance.
// Returns true on success.
static int file_read(void *buf, size_t size, FILE *file) {
  const int kMaxRetries = 5;
  int retry_count = 0;
  int file_error;
  size_t len = 0;
  do {
    const size_t n = fread((uint8_t *)buf + len, 1, size - len, file);
    len += n;
    file_error = ferror(file);
    if (file_error) {
      if (errno == EINTR || errno == EAGAIN) {
        clearerr(file);
        continue;
      } else {
        fprintf(stderr, "Error reading file: %u of %u bytes read, %d: %s\n",
                (uint32_t)len, (uint32_t)size, errno, strerror(errno));
        return 0;
      }
    }
  } while (!feof(file) && len < size && ++retry_count < kMaxRetries);

  if (!feof(file) && len != size) {
    fprintf(stderr,
            "Error reading file: %u of %u bytes read,"
            " error: %d, retries: %d, %d: %s\n",
            (uint32_t)len, (uint32_t)size, file_error, retry_count, errno,
            strerror(errno));
  }
  return len == size;
}

static int y4m_parse_tags(y4m_input *_y4m, char *_tags) {
  int got_w;
  int got_h;
  int got_fps;
  int got_interlace;
  int got_par;
  int got_chroma;
  char *p;
  char *q;
  got_w = got_h = got_fps = got_interlace = got_par = got_chroma = 0;
  for (p = _tags;; p = q) {
    /*Skip any leading spaces.*/
    while (*p == ' ') p++;
    /*If that's all we have, stop.*/
    if (p[0] == '\0') break;
    /*Find the end of this tag.*/
    for (q = p + 1; *q != '\0' && *q != ' '; q++)
      ;
    /*Process the tag.*/
    switch (p[0]) {
      case 'W': {
        if (sscanf(p + 1, "%d", &_y4m->pic_w) != 1) return -1;
        got_w = 1;
      } break;
      case 'H': {
        if (sscanf(p + 1, "%d", &_y4m->pic_h) != 1) return -1;
        got_h = 1;
      } break;
      case 'F': {
        if (sscanf(p + 1, "%d:%d", &_y4m->fps_n, &_y4m->fps_d) != 2) {<commit_msg>y4minput.c: correct empty loop formatting<commit_after>/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 *
 *  Based on code from the OggTheora software codec source code,
 *  Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors.
 */
#include <errno.h>
#include <stdlib.h>
#include <string.h>

#include "vpx/vpx_integer.h"
#include "y4minput.h"

// Reads 'size' bytes from 'file' into 'buf' with some fault tolerance.
// Returns true on success.
static int file_read(void *buf, size_t size, FILE *file) {
  const int kMaxRetries = 5;
  int retry_count = 0;
  int file_error;
  size_t len = 0;
  do {
    const size_t n = fread((uint8_t *)buf + len, 1, size - len, file);
    len += n;
    file_error = ferror(file);
    if (file_error) {
      if (errno == EINTR || errno == EAGAIN) {
        clearerr(file);
        continue;
      } else {
        fprintf(stderr, "Error reading file: %u of %u bytes read, %d: %s\n",
                (uint32_t)len, (uint32_t)size, errno, strerror(errno));
        return 0;
      }
    }
  } while (!feof(file) && len < size && ++retry_count < kMaxRetries);

  if (!feof(file) && len != size) {
    fprintf(stderr,
            "Error reading file: %u of %u bytes read,"
            " error: %d, retries: %d, %d: %s\n",
            (uint32_t)len, (uint32_t)size, file_error, retry_count, errno,
            strerror(errno));
  }
  return len == size;
}

static int y4m_parse_tags(y4m_input *_y4m, char *_tags) {
  int got_w;
  int got_h;
  int got_fps;
  int got_interlace;
  int got_par;
  int got_chroma;
  char *p;
  char *q;
  got_w = got_h = got_fps = got_interlace = got_par = got_chroma = 0;
  for (p = _tags;; p = q) {
    /*Skip any leading spaces.*/
    while (*p == ' ') p++;
    /*If that's all we have, stop.*/
    if (p[0] == '\0') break;
    /*Find the end of this tag.*/
    for (q = p + 1; *q != '\0' && *q != ' '; q++) {
    }
    /*Process the tag.*/
    switch (p[0]) {
      case 'W': {
        if (sscanf(p + 1, "%d", &_y4m->pic_w) != 1) return -1;
        got_w = 1;
      } break;
      case 'H': {
        if (sscanf(p + 1, "%d", &_y4m->pic_h) != 1) return -1;
        got_h = 1;
      } break;
      case 'F': {
        if (sscanf(p + 1, "%d:%d", &_y4m->fps_n, &_y4m->fps_d) != 2) {
{'fraction_non_alphanumeric': 0.14761354888375675, 'fraction_numerical': 0.019438029253271746, 'mean_word_length': 2.4716098864395457, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1004108', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1925, 'n_words': 628}