Exemplo n.º 1
0
static const char*
parse_extension (const char *filename)
{
  const char *compression;
  const char *last_separator;

  compression = file_is_compressed (filename);

  /* if the file is compressed we might have a double extension */
  if (compression != NULL) {
    int i;
    static const char * const extensions[] = {"tar", "ps", "xcf", "dvi", "txt", "text", NULL};

    for (i = 0; extensions[i] != NULL; i++) {
      char *suffix;
      suffix = g_strdup_printf (".%s%s", extensions[i], compression);

      if (g_str_has_suffix (filename, suffix)) {
        char *p;

        p = g_strrstr (filename, suffix);
        g_free (suffix);

        return p;
      }

      g_free (suffix);
    }
  }

  /* no compression, just look for the last dot in the filename */
  last_separator = strrchr (filename, G_DIR_SEPARATOR);
  return strrchr ((last_separator) ? last_separator : filename, '.');
}
Exemplo n.º 2
0
/*--------------------------------------------------------------------------*/
int file_checkfile (char *urltype, char *infile, char *outfile)
{
    /* special case: if file:// driver, check if the file is compressed */
    if ( file_is_compressed(infile) )
    {
        /* if output file has been specified, save the name for future use: */
        /* This is the name of the uncompressed file to be created on disk. */
        if (strlen(outfile))
        {
            if (!strncmp(outfile, "mem:", 4) )
            {
                /* uncompress the file in memory, with READ and WRITE access */
                strcpy(urltype, "compressmem://");  /* use special driver */
                *file_outfile = '\0';
            }
            else
            {
                strcpy(urltype, "compressfile://");  /* use special driver */

                /* don't copy the "file://" prefix, if present.  */
                if (!strncmp(outfile, "file://", 7) )
                    strcpy(file_outfile,outfile+7);
                else
                    strcpy(file_outfile,outfile);
            }
        }
        else
        {
            /* uncompress the file in memory */
            strcpy(urltype, "compress://");  /* use special driver */
            *file_outfile = '\0';  /* no output file was specified */
        }
    }
    else  /* an ordinary, uncompressed FITS file on disk */
    {
        /* save the output file name for later use when opening the file. */
        /* In this case, the file to be opened will be opened READONLY,   */
        /* and copied to this newly created output file.  The original file */
        /* will be closed, and the copy will be opened by CFITSIO for     */
        /* subsequent processing (possibly with READWRITE access).        */
        if (strlen(outfile)) {
            file_outfile[0] = '\0';
            strncat(file_outfile,outfile,FLEN_FILENAME-1);
        }
    }

    return 0;
}