home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / batch.lzh / ENVIRON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-23  |  2.1 KB  |  61 lines

  1. /*    environ.c
  2.  
  3.     This file contains routines to manipulate the system environment
  4.     string on MSDOS.  These routines assume that the assembly routine
  5.     GETENV has been used to initialize the values of enl and env
  6.     below.  Disasterous results will occur if this is not done.
  7.     All these routines were compiled with Computer innovaions C 
  8.     compiler using the large memory model.  Access to the environment
  9.     in the manner used here REQUIRES the large memory model.
  10. */
  11.  
  12. #include <stdio.h>
  13.  
  14. char    *env;        /*pointer to start of environment string*/
  15. char    *tem;        /*temporary pointer for searching*/
  16. int    enl;        /*length of environment in bytes*/
  17.  
  18. char *search_for(str)    /*searches environment for string*/
  19. char    *str;    /*string to search for*/
  20. {
  21.     int    l;    /*scratch string length*/
  22.  
  23.     l=strlen(str);    /*calculate length of argument string*/
  24.     tem=env;
  25.     while(*tem!=0)    /*loop for all strings in environment*/
  26.     {
  27.     if (strncmp(tem,str,l)==0)    /*if you find it,*/
  28.         return(tem);        /*return a pointer to it*/
  29.     while(*tem++ != 0);        /*else, skip to next string*/
  30.     }
  31.     return(NULL);        /*if no such string, return NULL*/
  32. }
  33.  
  34. del_string(str)        /*deletes a string from the environment*/
  35. char    *str;    /*name (including =) of string to delete*/
  36. {
  37.     int    l;    /*length of string being deleted*/
  38.  
  39.     if (search_for(str) == NULL)    /*if no such string,*/
  40.     return;                /*then deleting is easy!*/
  41.     l=strlen(tem)+1;        /*calc length of string (count nul)*/
  42.     movmem(tem+l,tem,(enl-(int)tem)-l);    /*and whack it out*/
  43.     return;
  44. }
  45.  
  46. int ins_string(str)    /*insert a new string in the environment*/
  47. char    *str;    /*string (including name=) to add to environment*/
  48. {
  49.     int    l;        /*length of string being inserted*/
  50.  
  51.     l=strlen(str);        /*get length of new string*/
  52.     if ((enl-(int)env)-l <=0)    /*is there room for this?*/
  53.     return(0);        /*no, return zero*/
  54.     tem=env;
  55.     while(*tem != 0)    /*loop until you find the double nul at end*/
  56.     while (*tem++ != 0);    /*skip past end of next string*/
  57.     strcpy(tem,str);        /*copy new string into the environment*/
  58.     *(tem+l+1) = 0;        /*write the second nul at the end*/
  59.     return(1);
  60. }
  61.