home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1989 / 08 / tricks / env.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-24  |  2.7 KB  |  95 lines

  1. /* ------------------------------------------------------ */
  2. /*                     ENV.C                              */
  3. /*               Environment-Editor                       */
  4. /*       (c) 1989  Peter Plucinski & TOOLBOX              */
  5. /*     ACHTUNG: für Dateiname 'ENV' benutzen              */
  6. /* ------------------------------------------------------ */
  7.  
  8. #include <stdio.h>
  9. #include <ctype.h>
  10. #include <dos.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #define BS  0x08                      /* Backspace        */
  15. #define CR  0x0D                      /* Return           */
  16. #define ESC 0x1B                      /* Escape           */
  17. #define LT  0x14B                     /* Pfeil links      */
  18. #define RT  0x14D                     /* Pfeil rechts     */
  19. #define HOM 0x147                     /* Home             */
  20. #define END 0x14F                     /* End              */
  21. #define DEL 0x153                     /* Delete           */
  22.  
  23. int getkey(x,y)                       /* Zeichen einlesen */
  24. int x,y;
  25. {
  26.   union REGS reg;
  27.  
  28.   gotoxy(x,y);
  29.   reg.h.ah = 0;
  30.   int86(0x16, ®, ®);
  31.   return ((reg.h.al) ? reg.h.al : reg.h.ah+256);
  32. }
  33.  
  34. void main(int argc, char *argv[])
  35. {
  36.   char *envst, var[80], *path;
  37.   int key, len, x, y;
  38.   FILE *f;
  39.  
  40.   strupr(argv[1]);         /* umwandeln in Großbuchstaben */
  41.   envst = getenv(argv[1]);       /* Variableninhalt holen */
  42.   len = strlen(envst);
  43.   x = len + 1;
  44.  
  45.   if (envst == NULL) {
  46.     puts("\nVariable ist nicht definiert!");
  47.     exit(1);
  48.   }
  49.  
  50.   path = getenv("ENVNAME");          /* Batch-Datei holen */
  51.   if (path == NULL) path = "envbat.bat";
  52.  
  53.   printf("\n%s", envst);
  54.   y = wherey();
  55.   while ((key = getkey(x,y)) != CR) {
  56.     switch (key) {
  57.       case LT  : if (x>1) x--; break;
  58.       case RT  : if (x<=len) x++; break;
  59.       case HOM : x=1; break;
  60.       case END : x=len+1; break;
  61.       case BS  : if (x>1) {
  62.      movmem(&envst[x-1],&envst[x-2],len-x+2);
  63.      len--; x--;
  64.      gotoxy(1,y); printf("%s ",envst);
  65.    }
  66.    break;
  67.       case DEL : if (x<=len) {
  68.      movmem(&envst[x],&envst[x-1],len-x+1);
  69.      len--;
  70.      gotoxy(1,y); printf("%s ",envst);
  71.    }
  72.    break;
  73.       default  : if (isprint(key)) {
  74.      movmem(&envst[x-1],&envst[x],len-x+2);
  75.      envst[x-1] = key;
  76.      gotoxy(1,y); printf("%s", envst);
  77.      len++; x++;
  78.    }
  79.     }
  80.   }
  81.  /* Set-Befehl erzeugen */
  82.   strcpy(var, "set ");
  83.   strcat(var, argv[1]);
  84.   strcat(var, "=");
  85.   strcat(var, envst);
  86.  
  87.  /* Batch-Datei schreiben */
  88.   f = fopen(path, "w");
  89.   fputs(var, f);
  90.   fclose(f);
  91.   exit(0);
  92. }
  93. /* ------------------------------------------------------ */
  94. /*                   Ende von ENV.C                       */
  95.