The arguments can have two forms:
-d
) or to display the contents of a variable (default behaviour).
If the program is running on a Windows NT type of operating system (Windows NT/2000/XP), function doWinNT() is called to query or edit the registry. On Windows 95 type of operating systems (Windows 95/98/me), function doWin95() is called to query or edit the file autoexec.bat
. However, if optCurEnv has been set (option -e
), the current environment is used instead of the registry or autoexec.bat
.
Information about the Win32 API is obtained from the Microsoft® Win32® Programmer's Reference (Win32.hlp) help file as distributed with Borland C++ version 5.
Namespaces | |
namespace | std |
Typedefs | |
typedef void(* | signal_fptr )() |
Ctrl-C (user interrupt) handler function type. | |
Functions | |
int | author (int status, FILE *stream) |
print author contact information to stream, return status. | |
int | usage (int status, FILE *stream) |
print intent and usage of applicationto stream, return status. | |
int | manual (int status, FILE *stream) |
print a description of this program to stream, return status. | |
int | platform (int status, FILE *stream) |
print platform information to stream, return status. | |
int | doWinNT (const string &cmd, const string &name, string &value) |
set, change or delete environment variable on Windows NT type (Windows NT/2000/XP). | |
int | doWin95 (const string &cmd, const string &name, string &value) |
set, change or delete environment variable on Windows 95 type (Windows 95/98/Me). | |
int | isWinNT () |
return true if running on Windows NT type OS (Windows NT/2000/XP). | |
int | isWin95 () |
return true if running on Windows 95 type OS (Windows 95/98/Me). | |
int | splitArg (const string &arg, string &cmd, string &name, string &value) |
split arg into (name,command,value). | |
void _USERENTRY | catcher () |
Ctrl-C (user interrupt) handler. | |
int | main (int argc, char *argv[]) |
handle commandline arguments. | |
int | readCurEnv (const string &name, string &value) |
read variable from current program's environment. | |
int | writeCurEnv (const string &name, const string &value) |
write variable to current program's environment. | |
int | readRegEnv (const string &name, string &value, int cu) |
read environment variable from registry. | |
int | writeRegEnv (const string &name, const string &value, int cu) |
write environment variable to registry. | |
int | deleteRegEnv (const string &name, int cu) |
delete environment variable from registry. | |
int | readIniVar (string name, string &value, string section, string fname) |
read variable from initialization file. | |
int | writeIniVar (string name, string value, string section, string fname) |
write variable to initialization file. See editIniVar(). | |
int | deleteIniVar (string name, string section, string fname) |
delete variable from initialization file. See editIniVar(). | |
string | replaceExt (const string &name, const string &ext) |
replace filename extension. | |
int | editIniVar (string name, string value, string section, string fname, int doDelete) |
write variable to or delete variable from initialization file. | |
Variables | |
const char * | title |
program banner. | |
int | optDelete = 0 |
option -d: delete environment variable | |
int | optCurDir = 0 |
option -c: autoexec in current dir (Win95) | |
int | optCurEnv = 0 |
option -e: use current environment | |
int | optKeepReg = 0 |
option -k: keep registry editing file (WinNT) | |
int | optHKCU = 0 |
option -u: environment variable in Current User environment (WinNT) | |
int | optVerbose = 0 |
option -v/V: verbose |
|
deleteIniVar() deletes variable
However, if a See further editIniVar(). |
|
deleteRegEnv() deletes environment variable
|
|
On Windows 95 type operating systems, file
doWin95() uses functions deleteIniVar(), writeIniVar() and readIniVar() from module Note 1: if multiple definitions of the variable exist, the last but one becomes active again after removal of the last occurrence.
Note 2: unless option
Note 3: if option
|
|
On Windows NT type operating systems, the environment information is contained in the registry.
doWinNT() queries and edits the registry via the Windows API functions. To this end it uses functions deleteRegEnv(), writeRegEnv() and readRegEnv() from module
Note that it is also possible to use program
|
|
editIniVar() looks for the variable specified by
First editIniVar() opens the file specified by
Then editIniVar() locates the line(s) with variable The lines of interest are searched for by looking at the pattern {whitespace}* [sSeEtT] {whitespace}+ [a-zA-Z0-9]+
editIniVar() remembers the linenumber of the last occurrence of the variable
Now the file Note that if the edited file contains a script with labels and goto's, a line appended to the end of the file may never be reached.
Finally editEnv() makes the new file available as
|
|
main() processes the commandline arguments as follows. If no arguments are specified on the commandline, main() calls usage() to print a short help screen, otherwise main() collects the options from the commandline. If after collecting the options, there are no arguments left on the commandline specified, main() also calls usage() to print a short description of the program's usage.
Now main() starts handling the commandline arguments (
For each argument main() tries to split it into a (name, command, value) triple, using function splitArg(). If optDelete has been set (option On Windows NT types of operating systems, main() delegates the work to doWinNT() and passes it the triple, On Windows NT types of operating systems, main() delegates the work to doWin95() and passes it the triple. If main() is deleting or setting an environment variable and doWinNT() or doWin95() returns with an error main() exits, issuing an error message and reminding the user: "do you have sufficient administrative rights?". If all went well, main() returns E_OK.
|
|
readCurEnv() reads the contents of variable
If the variable does not exist, readCurEnv() returns 1, and
|
|
readIniVar() reads the contents of a variable from a Windows initializaton (
If a
readIniVar() opens the file specfied by
Then readIniVar() locates the line(s) with variable The lines of interest are searched for by looking at the pattern {whitespace}* [sSeEtT] {whitespace}+ [a-zA-Z0-9]+
If the variable is found, readIniVar() reads the ^[^=]=[\\"]?([^\\"\\n]+) When all lines are read, the file is closed. If this fails, readIniVar() returns 1. Finally readIniVar() returns 0 if the requested variable has been found, or 1 if it could not be read.
|
|
readRegEnv() reads the contents of environment variable
|
|
splitArg() takes the argument in the form
In all situations the variable name is passed via the
|
|
writeCurEnv() writes
|
|
writeIniVar() writes variable
However, if a See further editIniVar(). |
|
writeRegEnv() writes
|
|
Initial value: "editenv " VERSION_STRING " edit environment variables.\n" "Copyright (C) 2003, Leiden University. All rights reserved.\n" "editenv is free software, released under the terms of the GNU GPL." |