Exemple #1
0
/* Open file */
fb_file *fb_open ( const char *path, int decompress, int compress )
{
  fb_file *ret = NULL;
  fb_dir *dir = NULL;
  char *tmp = strdup(path);
  char *pos = strrchr(tmp, '/');
  if (!pos) {
    free(tmp);
    return NULL;
  }
    
  /* Find directory */
  *pos = '\0';
  dir  = fb_opendir(tmp);
  if (!dir) {
    free(tmp);
    return NULL;
  }

  /* Open */
  ret = fb_open2(dir, pos+1, decompress, compress);
  fb_closedir(dir);
  free(tmp);
  return ret;
}
Exemple #2
0
/*
 * Process a file
 */
static void
scanfile_load_file
  ( const char *type, fb_dir *dir, const char *name )
{
  int i, opos;
  fb_file *fp;
  scanfile_region_t *reg = NULL;
  scanfile_network_t *net;
  char *str;
  char buf[256], buf2[256], buf3[256];
  tvhtrace("scanfile", "load file %s", name);

  fp = fb_open2(dir, name, 1, 0);
  if (!fp) return;

  /* Region */
  strncpy(buf, name, sizeof(buf));
  if (!strcmp(type, "dvb-s")) {
    reg = scanfile_region_create(type, "geo", "Geo-synchronous Orbit");
  } else {
    str = buf;
    while (*str) {
      if (*str == '-') {
        *str = '\0';
        reg  = scanfile_region_create(type, buf, tldcode2longname(buf));
        *str = '-';
        break;
      }
      str++;
    }
  }
  if (!reg) {
    fb_close(fp);
    return;
  }

  /* Network */
  str = buf;
  while (*str) {
    if (!isprint(*str)) *str = '_';
    str++;
  }
  *str = '\0';
  if (!strcmp(type, "dvb-s") && scanfile_network_dvbs_pos(buf, &opos)) {
    snprintf(buf3, sizeof(buf3), "%c%3i.%i%c:%s", opos < 0 ? '<' : '>',
                                                   abs(opos) / 10, abs(opos) % 10,
                                                   opos < 0 ? 'W' :'E', buf);
    strcpy(buf, buf3);
  }
  snprintf(buf2, sizeof(buf2), "%s_%s", type, buf);
  net = calloc(1, sizeof(scanfile_network_t));
  net->sfn_id   = strdup(buf2);
  net->sfn_name = strdup(buf);
  LIST_INSERT_SORTED(&reg->sfr_networks, net, sfn_link, scanfile_network_cmp);

  /* Process file */
  while (!fb_eof(fp)) {

    /* Get line */
    memset(buf, 0, sizeof(buf));
    if (!fb_gets(fp, buf, sizeof(buf) - 1)) break;
    i = 0;
    while (buf[i]) {
      if (buf[i] == '#') 
        buf[i] = '\0';
      else
        i++;
    }
    while (i > 0 && buf[i-1] < 32) buf[--i] = 0;

    /* Process mux */
    switch (*buf) {
      case 'A':
      case 'C':
      case 'T':
      case 'S':
        scanfile_load_one(net, buf);
      default:
        break;
    }
  }
  fb_close(fp);
}
Exemple #3
0
/*
 * Process a file
 */
static void _muxes_load_file
  ( const char *type, fb_dir *dir, const char *name )
{
  int i;
  fb_file *fp;
  region_t *reg = NULL;
  network_t *net;
  char *str;
  char buf[256], buf2[256];

  fp = fb_open2(dir, name, 1, 0);
  if (!fp) return;

  /* Region */
  strncpy(buf, name, sizeof(buf));
  if (!strcmp(type, "dvb-s")) {
    reg = _muxes_region_create(type, "geo", "Geo-synchronous Orbit");
  } else {
    str = buf;
    while (*str) {
      if (*str == '-') {
        *str = '\0';
        reg  = _muxes_region_create(type, buf, tldcode2longname(buf));
        *str = '-';
        break;
      }
      str++;
    }
  }
  if (!reg) {
    fb_close(fp);
    return;
  }

  /* Network */
  str = buf;
  while (*str) {
    if (!isalnum(*str)) *str = '_';
    str++;
  }
  *str = '\0';
  snprintf(buf2, sizeof(buf2), "%s_%s", type, buf);
  net = calloc(1, sizeof(network_t));
  net->id   = strdup(buf2);
  net->name = strdup(buf);
  LIST_INSERT_SORTED(&reg->networks, net, link, _net_cmp);

  /* Process file */
  while (!fb_eof(fp)) {

    /* Get line */
    memset(buf, 0, sizeof(buf));
    if (!fb_gets(fp, buf, sizeof(buf) - 1)) break;
    i = 0;
    while (buf[i]) {
      if (buf[i] == '#') 
        buf[i] = '\0';
      else
        i++;
    }
    while (i > 0 && buf[i-1] < 32) buf[--i] = 0;

    /* Process mux */
    switch (*buf) {
      case 'A':
      case 'C':
      case 'T':
      case 'S':
        _muxes_load_one(net, buf);
      default:
        break;
    }
  }
  fb_close(fp);
}