home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / cenvi29.zip / ENVSORT.CMD < prev    next >
OS/2 REXX Batch file  |  1994-10-10  |  2KB  |  59 lines

  1. @echo OFF
  2. REM ****************************************************************
  3. REM *** EnvSort.cmd - Sort environment variables alphabetically. ***
  4. REM *** ver.1         This works by writing a temporary batch    ***
  5. REM ***               file to set all of the environment         ***
  6. REM ***               variables in alphabetic order, then        ***
  7. REM ***               removing the batch file.                   ***
  8. REM ****************************************************************
  9. ECHO SORTING ENVIRONMENT VARIABLES...
  10.  
  11. REM *** USE TEMP OR TMP VARIABLE TO FIND DIRECTORY ***
  12. REM *** TO STORE TEMPORARY FILE                    ***
  13. SET __CMD=.
  14. IF NOT "%TMP%"=="" SET __CMD=%TEMP%
  15. IF NOT "%TEMP%"=="" SET __CMD=%TEMP%
  16. REM REMOVE BACKSLASH IF THERE IS ONE
  17. CEnvi i=strlen(__CMD); if(__CMD[i-1]=='\\') __CMD[i-1]=0;
  18. SET __CMD=%__CMD%\_ENVSORT.CMD
  19.  
  20. SET | CEnvi %0.cmd
  21. GOTO CENVI_EXIT
  22.  
  23.    // Build list of all environment variables
  24.    Count = 0;
  25.    while ( ELine = gets() )
  26.       Lines[Count++] = ELine;
  27.  
  28.    // Sort variable lines
  29.    qsort(Lines,Count,"strcmpi");
  30.  
  31.    // open temporary batch output file
  32.    if ( !(fp = fopen(__CMD,"wt")) ) {
  33.       printf("Error opening \"%s\" for writing.\a",__CMD);
  34.       exit(EXIT_FAILURE);
  35.    }
  36.  
  37.    // for each variable, write out to set to nothing
  38.    for ( i = 0; i < Count; i++ ) {
  39.       ELine = Lines[i];
  40.       if ( Equal = strchr(ELine,'=') )
  41.          fprintf(fp,"SET %.*s\n",Equal-ELine+1,ELine);
  42.    }
  43.  
  44.    // write out all the variable lines to batch file
  45.    for ( i = 0; i < Count; i++ )
  46.       fprintf(fp,"SET %s\n",Lines[i]);
  47.  
  48.    // all done. close batch file
  49.    fclose(fp);
  50.  
  51. :CENVI_EXIT
  52.  
  53. REM *** PLAY BACK THE TEMPORARY BATCH FILE; ALL DONE
  54. CALL %__CMD%
  55. DEL %__CMD%
  56. SET __CMD=
  57.  
  58. REM *** ENVIRONMENT
  59.