home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / exec.swg / 0022_Shell to DOS with PROMPT.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-02-15  |  3.2 KB  |  62 lines

  1.  
  2.  {change the dos prompt when Shelling to DOS without
  3.   having to change the current or master enviroment(It makes it's own).}
  4.  
  5. {***********************************************************************}
  6. PROGRAM PromptDemo;             { Feb 12/94, Greg Estabrooks.           }
  7. {$M 16840,0,0}                  { Reserved some memory for the shell.   }
  8. USES CRT,                         { IMPORT Clrscr,Writeln.              }
  9.      DOS;                         { IMPORT Exec.                        }
  10.  
  11. PROCEDURE ShellWithPrompt( Prompt :STRING );
  12.                          { Routine to allocate a temporary Enviroment   }
  13.                          { with our prompt and the execute COMMAND.COM. }
  14.                          { NOTE: This does NO error checking.           }
  15. VAR
  16.    NewEnv :WORD;                { Points to our newly allocated env.    }
  17.    OldEnv :WORD;                { Holds Old Env Segment.                }
  18.    EnvPos :WORD;                { Position inside our enviroment.       }
  19.    EnvLp  :WORD;                { Variable to loop through ENVStrings.  }
  20.    TempStr:STRING;              { Holds temporary EnvString info.       }
  21. BEGIN
  22.   ASM
  23.    Mov AH,$48                   { Routine to allocate memory.           }
  24.    Mov BX,1024                  { Allocate 1024(1k) of memory.          }
  25.    Int $21                      { Call DOS to allocate memory.          }
  26.    Mov NewEnv,AX                { Save segment address of our memory.   }
  27.   END;
  28.  
  29.   EnvPos := 0;                  { Initiate pos within our Env.          }
  30.   FOR EnvLp := 1 TO EnvCount DO { Loop through entire enviroment.       }
  31.    BEGIN
  32.     TempStr := EnvStr(EnvLp);   { Retrieve Envirment string.            }
  33.     IF Pos('PROMPT=',TempStr) <> 0 THEN  { If its our prompt THEN ....  }
  34.      TempStr := 'PROMPT='+Prompt+#0  { Create our new prompt.           }
  35.     ELSE                        {  .... otherwise.........              }
  36.      TempStr := TempStr + #0;   { Add NUL to make it ASCIIZ compatible. }
  37.     Move(TempStr[1],Mem[NewEnv:EnvPos],Length(TempStr)); { Put in Env.  }
  38.     INC(EnvPos,Length(TempStr)); { Point to new position in Enviroment. }
  39.    END;{For}
  40.  
  41.   OldEnv := MemW[PrefixSeg:$2C];{ Save old enviroment segment.          }
  42.   MemW[PrefixSeg:$2C] := NewEnv;{ Point to our new enviroment.          }
  43.   SwapVectors;                  { Swap Int vectors in case of conflicts.}
  44.   Exec(GetEnv('COMSPEC'),'');   { Call COMMAND.COM.                     }
  45.   SwapVectors;                  { Swap em back.                         }
  46.   MemW[PrefixSeg:$2C] := OldEnv;{ Point back to old enviroment.         }
  47.  
  48.   ASM
  49.    Push ES                      { Save ES.                              }
  50.    Mov AH,$49                   { Routine to deallocate memory.         }
  51.    Mov ES,NewEnv                { Point ES to area to deallocate.       }
  52.    Int $21;                     { Call DOS to free memory.              }
  53.    Pop ES                       { Restore ES.                           }
  54.   END;
  55. END;{ShellWithPrompt}
  56.  
  57. BEGIN
  58.   Clrscr;                        { Clear the screen.                    }
  59.   Writeln('Type EXIT to return');{ Show message on how to exit shell.   }
  60.   ShellWithPrompt('[PromptDemo] $P$G'); { shell to DOS with our prompt. }
  61. END.{PromptDemo}
  62.