home *** CD-ROM | disk | FTP | other *** search
- /* environ.c
-
- This file contains routines to manipulate the system environment
- string on MSDOS. These routines assume that the assembly routine
- GETENV has been used to initialize the values of enl and env
- below. Disasterous results will occur if this is not done.
- All these routines were compiled with Computer innovaions C
- compiler using the large memory model. Access to the environment
- in the manner used here REQUIRES the large memory model.
- */
-
- #include <stdio.h>
-
- char *env; /*pointer to start of environment string*/
- char *tem; /*temporary pointer for searching*/
- int enl; /*length of environment in bytes*/
-
- char *search_for(str) /*searches environment for string*/
- char *str; /*string to search for*/
- {
- int l; /*scratch string length*/
-
- l=strlen(str); /*calculate length of argument string*/
- tem=env;
- while(*tem!=0) /*loop for all strings in environment*/
- {
- if (strncmp(tem,str,l)==0) /*if you find it,*/
- return(tem); /*return a pointer to it*/
- while(*tem++ != 0); /*else, skip to next string*/
- }
- return(NULL); /*if no such string, return NULL*/
- }
-
- del_string(str) /*deletes a string from the environment*/
- char *str; /*name (including =) of string to delete*/
- {
- int l; /*length of string being deleted*/
-
- if (search_for(str) == NULL) /*if no such string,*/
- return; /*then deleting is easy!*/
- l=strlen(tem)+1; /*calc length of string (count nul)*/
- movmem(tem+l,tem,(enl-(int)tem)-l); /*and whack it out*/
- return;
- }
-
- int ins_string(str) /*insert a new string in the environment*/
- char *str; /*string (including name=) to add to environment*/
- {
- int l; /*length of string being inserted*/
-
- l=strlen(str); /*get length of new string*/
- if ((enl-(int)env)-l <=0) /*is there room for this?*/
- return(0); /*no, return zero*/
- tem=env;
- while(*tem != 0) /*loop until you find the double nul at end*/
- while (*tem++ != 0); /*skip past end of next string*/
- strcpy(tem,str); /*copy new string into the environment*/
- *(tem+l+1) = 0; /*write the second nul at the end*/
- return(1);
- }