| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

file_is_program

#include "sflfile.h"
Bool
file_is_program (
    const char *filename)

Synopsis

Returns TRUE if the specified filename is an executable program on the PATH. Under DOS, and Windows, appends ".exe", ".com" to the file, in that order, to build an executable filename, then searches the PATH definition for the executable filename. Under OS/2, appends ".exe" to the file to build an executable filename, then searches the PATH definition for the executable filename. If the filename already has a path specifier, will not use the PATH definition. Under VMS, appends "exe" and "com" to the file, in that order, to build an executable filename. Searches the PATH if necessary.

Source Code - (sflfile.c)

{
    Bool
        executable = FALSE;             /*  Return code                      */

#if (defined (__UNIX__))
    char
        *found_file;

    ASSERT (filename);

    found_file = file where ('r', "PATH", filename, "");
    if (found_file && (file_mode (found_file) & S_IEXEC))
        executable = TRUE;              /*  Executable file found            */

#elif (defined (__VMS__))
    char
        *found_file;

    ASSERT (filename);

    found_file = file where ('r', "PATH", filename, "");
    if (!found_file)
        found_file = file where ('r', "PATH", filename, ".exe");
    if (!found_file)
        found_file = file where ('r', "PATH", filename, ".com");

    if (found_file && (file_mode (found_file) & S_IEXEC))
        executable = TRUE;              /*  Executable file found            */

#elif (defined (MSDOS_FILESYSTEM))
    char
        *path;                          /*  What path do we search?          */

    ASSERT (filename);
    /*  If the filename already contains a path, don't look at PATH          */
    if (strchr (filename, '/') || strchr (filename, '\\'))
        path = NULL;
    else
        path = "PATH";

#   if (defined (__WINDOWS__))
    if (file where ('r', path, filename, ".exe")
    ||  file where ('r', path, filename, ".com")
    ||  file where ('r', path, filename, ".bat"))
        executable = TRUE;              /*  Executable file found            */

#   else /* OS/2 */
    if (file where ('r', path, filename, ".exe"))
        executable = TRUE;
#   endif
#endif

    return (executable);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation