Ignore:
Timestamp:
Mar 7, 2001, 10:41:07 PM (24 years ago)
Author:
umoeller
Message:

Misc. changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dosh.c

    r40 r43  
    18741874
    18751875/*
     1876 *@@ doshFindExecutable:
     1877 *      this searches the PATH for the specified pcszCommand
     1878 *      by calling DosSearchPath.
     1879 *
     1880 *      papcszExtensions determines if additional searches are to be
     1881 *      performed if DosSearchPath returns ERROR_FILE_NOT_FOUND.
     1882 *      This must point to an array of strings specifying the extra
     1883 *      extensions to search for.
     1884 *
     1885 *      If both papcszExtensions and cExtensions are null, no
     1886 *      extra searches are performed.
     1887 *
     1888 *      If this returns NO_ERROR, pszExecutable receives
     1889 *      the full path of the executable found by DosSearchPath.
     1890 *      Otherwise ERROR_FILE_NOT_FOUND is returned.
     1891 *
     1892 *      Example:
     1893 *
     1894 +      const char *aExtensions[] = {  "EXE",
     1895 +                                     "COM",
     1896 +                                     "CMD"
     1897 +                                  };
     1898 +      CHAR szExecutable[CCHMAXPATH];
     1899 +      APIRET arc = doshFindExecutable("lvm",
     1900 +                                      szExecutable,
     1901 +                                      sizeof(szExecutable),
     1902 +                                      aExtensions,
     1903 +                                      3);
     1904 *
     1905 *@@added V0.9.9 (2001-03-07) [umoeller]
     1906 */
     1907
     1908APIRET doshFindExecutable(const char *pcszCommand,      // in: command (e.g. "lvm")
     1909                          PSZ pszExecutable,            // out: full path (e.g. "F:\os2\lvm.exe")
     1910                          ULONG cbExecutable,           // in: sizeof (*pszExecutable)
     1911                          const char **papcszExtensions, // in: array of extensions (without dots)
     1912                          ULONG cExtensions)            // in: array item count
     1913{
     1914    APIRET arc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY,
     1915                               "PATH",
     1916                               (PSZ)pcszCommand,
     1917                               pszExecutable,
     1918                               cbExecutable);
     1919    if (    (arc == ERROR_FILE_NOT_FOUND)           // not found?
     1920         && (cExtensions)                    // any extra searches wanted?
     1921       )
     1922    {
     1923        // try additional things then
     1924        PSZ psz2 = malloc(strlen(pcszCommand) + 20);
     1925        if (psz2)
     1926        {
     1927            ULONG   ul;
     1928            for (ul = 0;
     1929                 ul < cExtensions;
     1930                 ul++)
     1931            {
     1932                const char *pcszExtThis = papcszExtensions[ul];
     1933                sprintf(psz2, "%s.%s", pcszCommand, pcszExtThis);
     1934                arc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY,
     1935                                    "PATH",
     1936                                    psz2,
     1937                                    pszExecutable,
     1938                                    cbExecutable);
     1939                if (arc != ERROR_FILE_NOT_FOUND)
     1940                    break;
     1941            }
     1942
     1943            free(psz2);
     1944        }
     1945        else
     1946            arc = ERROR_NOT_ENOUGH_MEMORY;
     1947    }
     1948
     1949    return (arc);
     1950}
     1951
     1952/*
    18761953 *@@ doshExecVIO:
    18771954 *      executes cmd.exe with the /c parameter
Note: See TracChangeset for help on using the changeset viewer.