Jump to content

DosScanEnv: Difference between revisions

From EDM2
No edit summary
Ak120 (talk | contribs)
mNo edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Description==
This call scans (searches) an environment segment for an environment variable.
This call scans (searches) an environment segment for an environment variable.  


==Syntax==
==Syntax==
  DosScanEnv (EnvVarName, ResultPointer)
  DosScanEnv(pszName, ppszValue)


==Parameters==
==Parameters==
; EnvVarName (PSZ) - input : Address of the name of the environment variable. Do not include a trailing " = ", since this is not part of the name.  
;pszName (PSZ) - input : Address of the name of the environment variable. Do not include a trailing equal sign ( = ), since this is not part of the name.
;ppszValue (PSZ *) - output : A pointer to the PSZ in which a pointer to the environment string is returned by the system.
:ppszValue points to the first character of the string that is the value of the environment variable, and can be passed directly to DosSearchPath.


; ResultPointer (PSZ FAR *) - output : Address where the system returns the pointer to the environment string. ResultPointer points to the first character of the string that is the value of the environment variable and can be passed directly into DosSearchPath.
==Return Code==
 
;ulrc (APIRET) - returns:DosScanEnv returns the following values:
==Return==
* 0 NO_ERROR
 
*203 ERROR_ENVVAR_NOT_FOUND
rc (USHORT) - return
 
Return code descriptions are:
 
* 0       NO_ERROR  
* 203     ERROR_ENVVAR_NOT_FOUND  


==Remarks==
==Remarks==
Assume that the process' environment contains:
Assume that the process' environment contains:
 
  "DPATH=c:\sysdir;c:\libdir"
            "DPATH=c:\sysdir;c:\libdir"
        |
                  |
        |
                  ³
        |
                  ³
        |----> pszValue points here after the
                  À---- ResultPointer points here after the
                following call to DosScanEnv:
                            following call to DosScanEnv:
   
   
            DosScanEnv("DPATH", &ResultPointer);
DosScanEnv("DPATH", pszValue);


As noted above, ResultPointer points to the first character of the value of the environment variable.  
ppszValue points to the first character of the value of the environment variable.


==C Binding==
==Example Code==
This example scans the environment segment for the "PATH" variable and displays it. It then searches the path, plus the current directory of the "VIEW.EXE" program.
<PRE>
<PRE>
#define INCL_DOSQUEUES
#define INCL_DOS
 
  #define INCL_DOSERRORS      /* DOS error values */
USHORT rc = DosScanEnv(EnvVarName, ResultPointer);
#include <os2.h>
 
#include <stdio.h>
PSZ              EnvVarName;    /* Environment variable name string */
PSZ FAR *        ResultPointer; /* Search result pointer (returned) */
 
USHORT          rc;            /* return code */
 
Example


The following example scans the environment segment for the PATH variable and prints its value. It then searches the path given by inserting the current directory into the value of the PATH variable for the file named "cmd.exe", and prints the full filename.
int main(VOID) {


#define INCL_DOS
  PSZ      PathValue        = "";        /* PATH environment variable  */
  UCHAR    SearchResult[256] = "";        /* Result of PATH search      */
  APIRET    rc                = NO_ERROR;  /* Return code                */


#include <os2.h>
  rc=DosScanEnv("PATH",&PathValue);  /* Get contents of PATH environment
                                        variable                        */
  if (rc != NO_ERROR) {
      printf("DosScanEnv error: return code = %u\n",rc);
      return 1;
  } else {
      printf("PATH is:\n%s\n\n", PathValue);
  }
      /* Scan the current directory and path for the VIEW.EXE program.
        Ignore any errors from network drives which may not be in use. */


#define ENVVARNAME            "PATH"      /* Environment variable name */
   rc=DosSearchPath(SEARCH_CUR_DIRECTORY | SEARCH_IGNORENETERRS,
#define FILENAME              "cmd.exe"    /* File for which to search */
                    PathValue,              /* Path value just obtained */
#define SEARCH_CUR_DIRECTORY  0x03        /* Search control - current
                    "VIEW.EXE",              /* Name of file to look for */
                                                    dir., */
                    SearchResult,            /* Result of the search    */
                                          /*  then environment variable */
                    sizeof(SearchResult))/* Length of search buffer  */
 
main()
{
  PSZ FAR  *ResultPointer;        /* Environment scan result pointer
                                      (returned) */
  BYTE      ResultBuffer[128];    /* Path search result
                                                (returned) */
  USHORT   rc;                    /* return code */
 
  /** Scan environment segment for PATH; notice the far-string pointer **/
  /**  specification ("%Fs") used to print.                          **/
 
  if(!(rc=DosScanEnv(ENVVARNAME,       /* Environment variable name */
                    &ResultPointer)))  /* Scan result pointer
                                                (returned) */
    printf("%s is %Fs\n", ENVVARNAME, ResultPointer);
 
  /** Search current directory + PATH variable for "cmd.exe"   **/
  if(!(rc=DosSearchPath(SEARCH_CUR_DIRECTORY,    /* Search control
                                                          vector */
                        ENVVARNAME,              /* Search path reference
                                                    string */
                        FILENAME,                /* File name string */
                        ResultBuffer,            /* Search result
                                                    (returned) */
                        sizeof(ResultBuffer))))  /* Length of search
                                                    result */
    printf("Found desired file -- %s\n", ResultBuffer);
}


  if (rc != NO_ERROR) {
      printf("DosSearchPath error: return code = %u\n",rc);
      return 1;
  } else {
      printf("Found desired file -- %s\n", SearchResult);
  }
  return NO_ERROR;
}
</PRE>
</PRE>


==MASM Binding==
==Related Functions==
<PRE>
* [[DosSearchPath]]
EXTRN  DosScanEnv:FAR
INCL_DOSQUEUES      EQU 1
 
PUSH@  ASCIIZ  EnvVarName    ;Environment variable name string
PUSH@  DWORD  ResultPointer ;Search result pointer (returned)
CALL  DosScanEnv
 
Returns WORD
</PRE>


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 22:31, 24 November 2019

This call scans (searches) an environment segment for an environment variable.

Syntax

DosScanEnv(pszName, ppszValue)

Parameters

pszName (PSZ) - input
Address of the name of the environment variable. Do not include a trailing equal sign ( = ), since this is not part of the name.
ppszValue (PSZ *) - output
A pointer to the PSZ in which a pointer to the environment string is returned by the system.
ppszValue points to the first character of the string that is the value of the environment variable, and can be passed directly to DosSearchPath.

Return Code

ulrc (APIRET) - returns
DosScanEnv returns the following values:
  • 0 NO_ERROR
  • 203 ERROR_ENVVAR_NOT_FOUND

Remarks

Assume that the process' environment contains:

 "DPATH=c:\sysdir;c:\libdir"
        |
        |
        |
        |----> pszValue points here after the
               following call to DosScanEnv:

DosScanEnv("DPATH", pszValue);

ppszValue points to the first character of the value of the environment variable.

Example Code

This example scans the environment segment for the "PATH" variable and displays it. It then searches the path, plus the current directory of the "VIEW.EXE" program.

 #define INCL_DOS
 #define INCL_DOSERRORS       /* DOS error values */
 #include <os2.h>
 #include <stdio.h>

int main(VOID) {

   PSZ       PathValue         = "";        /* PATH environment variable  */
   UCHAR     SearchResult[256] = "";        /* Result of PATH search      */
   APIRET    rc                = NO_ERROR;  /* Return code                */

   rc=DosScanEnv("PATH",&PathValue);  /* Get contents of PATH environment
                                         variable                         */
   if (rc != NO_ERROR) {
       printf("DosScanEnv error: return code = %u\n",rc);
       return 1;
   } else {
       printf("PATH is:\n%s\n\n", PathValue);
   }
      /* Scan the current directory and path for the VIEW.EXE program.
         Ignore any errors from network drives which may not be in use. */

   rc=DosSearchPath(SEARCH_CUR_DIRECTORY | SEARCH_IGNORENETERRS,
                    PathValue,               /* Path value just obtained */
                    "VIEW.EXE",              /* Name of file to look for */
                    SearchResult,            /* Result of the search     */
                    sizeof(SearchResult));   /* Length of search buffer  */

   if (rc != NO_ERROR) {
       printf("DosSearchPath error: return code = %u\n",rc);
       return 1;
   } else {
       printf("Found desired file -- %s\n", SearchResult);
   }
  return NO_ERROR;
 }

Related Functions