home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / ENVIEDIT.CMD < prev    next >
OS/2 REXX Batch file  |  1995-08-15  |  1KB  |  48 lines

  1. @echo off
  2. REM ***********************************************************
  3. REM *** EnviEdit.cmd - Edit the environment with EPM editor ***
  4. REM *** ver.1                                               ***
  5. REM ***********************************************************
  6.  
  7. SET > ~ENVEDT~.CMD
  8. CEnvi2 %0.cmd
  9. GOTO CENVI_EXIT
  10.  
  11. // read all the environment variables to initially clear them
  12. fp = fopen("~ENVEDT~.CMD","rt");
  13. oldvcount = 0;
  14. while ( line = fgets(fp) ) {
  15.    if ( line[0]  &&  (Equal=strchr(line,'=')) ) {
  16.       Equal[0] = 0;
  17.       oldvarlist[oldvcount++] = line;
  18.    }
  19. }
  20. fclose(fp);
  21.  
  22. // let the standard editor edit this file
  23. system("SESSION /F /PM /WAIT EPM.EXE ~ENVEDT~.CMD");
  24.  
  25. // read in the newly-edited file
  26. fp = fopen("~ENVEDT~.CMD","rt");
  27. newvcount = 0;
  28. while ( line = fgets(fp) ) {
  29.    if ( line[0]  &&  (Equal=strchr(line,'=')) ) {
  30.       newvarlist[newvcount++] = line;
  31.    }
  32. }
  33. fclose(fp);
  34.  
  35. // add old lines to remove old variables
  36. fp = fopen("~ENVEDT~.CMD","wt");
  37. fprintf(fp,"@echo off\n");
  38. for ( i = 0; i < oldvcount; i++ )
  39.    fprintf(fp,"SET %s=\n",oldvarlist[i]);
  40. // add lines to set new variables
  41. for ( i = 0; i < newvcount; i++ )
  42.    fprintf(fp,"SET %s",newvarlist[i]);
  43. fclose(fp);
  44.  
  45. :CENVI_EXIT
  46. CALL ~ENVEDT~.CMD
  47. DEL ~ENVEDT~.CMD /F
  48.