Пример #1
0
/**
 * Replace various chars with a dash
 */
static char *
cleanup_filename(char *s, dvr_config_t *cfg)
{
  int i, len = strlen(s), len2;
  char *s1;

  s1 = intlconv_utf8safestr(cfg->dvr_charset_id, s, len * 2);
  if (s1 == NULL) {
    tvherror("dvr", "Unsupported charset %s using ASCII", cfg->dvr_charset);
    s1 = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
                             s, len * 2);
    if (s1 == NULL)
      return NULL;
  }
  s = s1;

  /* Do not create hidden files */
  if (s[0] == '.')
    s[0] = '_';

  len2 = strlen(s);
  for (i = 0; i < len2; i++) {

    if(s[i] == '/')
      s[i] = '-';

    else if(cfg->dvr_whitespace_in_title &&
            (s[i] == ' ' || s[i] == '\t'))
      s[i] = '-';	

    else if(cfg->dvr_clean_title &&
            ((s[i] < 32) || (s[i] > 122) ||
             (strchr("/:\\<>|*?'\"", s[i]) != NULL)))
      s[i] = '_';
    else if(cfg->dvr_windows_compatible_filenames &&
             (strchr("/:\\<>|*?'\"", s[i]) != NULL))
      s[i] = '_';
  }

  if(cfg->dvr_windows_compatible_filenames) {
    // trim trailing spaces and dots
    for (i = len2 - 1; i >= 0; i--) {
      if((s[i] != ' ') && (s[i] != '.'))
        break;
      s[i] = '\0';
    }
  }

  return s;
}
Пример #2
0
/**
 * Replace various chars with a dash
 */
static char *
cleanup_filename(char *s, dvr_config_t *cfg)
{
  int i, len = strlen(s);
  char *s1;

  s1 = intlconv_utf8safestr(cfg->dvr_charset_id, s, len * 2);
  if (s1 == NULL) {
    tvherror("dvr", "Unsupported charset %s using ASCII", cfg->dvr_charset);
    s1 = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
                             s, len * 2);
    if (s1 == NULL)
      return NULL;
  }
  s = s1;

  /* Do not create hidden files */
  if (s[0] == '.')
    s[0] = '_';

  for (i = 0, len = strlen(s); i < len; i++) {

    if(s[i] == '/')
      s[i] = '-';

    else if(cfg->dvr_whitespace_in_title &&
            (s[i] == ' ' || s[i] == '\t'))
      s[i] = '-';	

    else if(cfg->dvr_clean_title &&
            ((s[i] < 32) || (s[i] > 122) ||
             (strchr("/:\\<>|*?'\"", s[i]) != NULL)))
      s[i] = '_';
  }

  return s;
}