home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------ */
- /* ENV.C */
- /* Environment-Editor */
- /* (c) 1989 Peter Plucinski & TOOLBOX */
- /* ACHTUNG: für Dateiname 'ENV' benutzen */
- /* ------------------------------------------------------ */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <dos.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define BS 0x08 /* Backspace */
- #define CR 0x0D /* Return */
- #define ESC 0x1B /* Escape */
- #define LT 0x14B /* Pfeil links */
- #define RT 0x14D /* Pfeil rechts */
- #define HOM 0x147 /* Home */
- #define END 0x14F /* End */
- #define DEL 0x153 /* Delete */
-
- int getkey(x,y) /* Zeichen einlesen */
- int x,y;
- {
- union REGS reg;
-
- gotoxy(x,y);
- reg.h.ah = 0;
- int86(0x16, ®, ®);
- return ((reg.h.al) ? reg.h.al : reg.h.ah+256);
- }
-
- void main(int argc, char *argv[])
- {
- char *envst, var[80], *path;
- int key, len, x, y;
- FILE *f;
-
- strupr(argv[1]); /* umwandeln in Großbuchstaben */
- envst = getenv(argv[1]); /* Variableninhalt holen */
- len = strlen(envst);
- x = len + 1;
-
- if (envst == NULL) {
- puts("\nVariable ist nicht definiert!");
- exit(1);
- }
-
- path = getenv("ENVNAME"); /* Batch-Datei holen */
- if (path == NULL) path = "envbat.bat";
-
- printf("\n%s", envst);
- y = wherey();
- while ((key = getkey(x,y)) != CR) {
- switch (key) {
- case LT : if (x>1) x--; break;
- case RT : if (x<=len) x++; break;
- case HOM : x=1; break;
- case END : x=len+1; break;
- case BS : if (x>1) {
- movmem(&envst[x-1],&envst[x-2],len-x+2);
- len--; x--;
- gotoxy(1,y); printf("%s ",envst);
- }
- break;
- case DEL : if (x<=len) {
- movmem(&envst[x],&envst[x-1],len-x+1);
- len--;
- gotoxy(1,y); printf("%s ",envst);
- }
- break;
- default : if (isprint(key)) {
- movmem(&envst[x-1],&envst[x],len-x+2);
- envst[x-1] = key;
- gotoxy(1,y); printf("%s", envst);
- len++; x++;
- }
- }
- }
- /* Set-Befehl erzeugen */
- strcpy(var, "set ");
- strcat(var, argv[1]);
- strcat(var, "=");
- strcat(var, envst);
-
- /* Batch-Datei schreiben */
- f = fopen(path, "w");
- fputs(var, f);
- fclose(f);
- exit(0);
- }
- /* ------------------------------------------------------ */
- /* Ende von ENV.C */