Back to index

tetex-bin  3.0
Functions
mime.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * figure_mime_type (const char *filename)
char * figure_viewer (const char *mime_type, const char **format_string, Boolean *needs_terminal, const char *arg)

Function Documentation

char* figure_mime_type ( const char *  filename)

Definition at line 579 of file mime.c.

{
    int i;
    char *extension, *cp;
    char *content_type = NULL;

    /* First check for the mailcap and mime files */
    parsemimes();
    parsemailcap();

    if (globals.debug & DBG_HTEX)
       fprintf(stderr, "figure_mime_type: Called to find type of %s\n",
              filename);
    
    /* See if this is a directory */
    if (filename[strlen(filename) - 1] == '/') {
       if (globals.debug & DBG_HTEX)
           fprintf(stderr, "It's a directory, returning unknownExtensionMimeType: %s\n",
                  resource.unknown_mime_suffix);
       return resource.unknown_mime_suffix;
    }

    /* See if filename extension is on the mime list: */
    extension = strrchr(filename, '.');

    if (extension == NULL) {
       TRACE_HTEX((stderr,
                  "No extension, defaulting to noExtensionMimeType: %s\n",
                  resource.no_mime_suffix));
       return resource.no_mime_suffix;
    }
    extension++;
    /*
     * corrupt URLs might have empty extensions; we need to catch this,
     * since the while loop below would not terminate in that case:
     */
    if (strcmp(extension, "") == 0) {
       XDVI_WARNING((stderr, "Empty extension for file name or URL `%s'\n", filename));
       return resource.no_mime_suffix;
    }

    for (i = 0; i < m_mimemap_currlen; i++) {
       /*
        * find extension in m_mimemap[i].extensions, a space-separated list
        * of extension strings.
        */
       cp = m_mimemap[i].extensions;
       while ((cp = strstr(cp, extension)) != NULL) {
           if ((cp - m_mimemap[i].extensions > 0) && (cp[-1] != ' ')) {
              cp++;
              continue;
           }
           cp += strlen(extension);
           if ((*cp != ' ') && (*cp != '\0'))
              continue;
           content_type = m_mimemap[i].content_type;
           break;
       }
       if (content_type != NULL)
           break;
    }

    if (content_type == NULL) {
       content_type = xstrdup(resource.unknown_mime_suffix);
       TRACE_HTEX((stderr,
                  "Unknown extension, defaulting to unknownExtensionMimeType: %s",
                  content_type));
    }
    else {
       TRACE_HTEX((stderr, "Found mime type: %s", content_type));
    }

    return content_type;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* figure_viewer ( const char *  mime_type,
const char **  format_string,
Boolean needs_terminal,
const char *  arg 
)

Definition at line 542 of file mime.c.

{
    int i;

    /* special case so that xdvizilla isn't used, which would be
       too dangerous since xdvizilla tries to unlink the DVI file by default.
       FIXME: A better way would be to always copy the original file, like
       e.g. Acroread does it; see comment in launch_program(), hypertex.c.
    */
    if (strcmp(content_type, "application/x-dvi") == 0) {
       *format_string = "%s";
       *needs_terminal = False;
       return xstrdup("xdvi %s");
    }
    /* try each command from our mailcap list */
    for (i = 0; i < m_mailcap_currlen; i++) {
       if (globals.debug & DBG_HTEX) {
           fprintf(stderr, "type |%s| viewer |%s| needsterminal=%s testcmd |%s|\n",
                  m_mailcap[i].content_type, m_mailcap[i].command,
                  m_mailcap[i].needsterminal ? "yes" : "no",
                  m_mailcap[i].testcmd ? m_mailcap[i].testcmd : "None");
       }
       if (match_content_type(m_mailcap[i].content_type, content_type)
           && run_test_command(m_mailcap[i].testcmd, arg)) {
           *format_string = m_mailcap[i].format_string;
           *needs_terminal = m_mailcap[i].needsterminal;
           return xstrdup(m_mailcap[i].command);
       }
    }
    /* failure */
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function: