home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / text / edit / FrexxEdA.lha / FrexxEd / fpl / FrexxShell.FPL < prev    next >
Text File  |  1995-08-06  |  3KB  |  121 lines

  1. /* FrexxEd Shell Environment
  2.    by Carsten Orthbandt
  3.    $VER: FrexxShell V 1.0 5.7.95
  4.    Read FrexxShell.FPL.README for further information
  5. */
  6.  
  7. int bufferid;
  8. string currentdir;
  9. string cmdfname,outfname,dirfname,errfname;
  10.  
  11. int ValidCommand(string cmd)
  12. {
  13.   int count, len;
  14.   len=strlen(cmd);
  15.  
  16.   for (count=0; count<len; count++) {
  17.     if (cmd[count]>32)
  18.       return 1;
  19.   }
  20.   return 0;
  21. }
  22.  
  23. void DoShellCmnd(string cmd)
  24. {
  25.  int errc;
  26.  if(ReadInfo("filehandler")) {
  27.    outfname = ReadInfo("disk_name")+":"+ReadInfo("full_file_name");
  28.    if (ReadInfo("file_number")>1)
  29.      outfname+=","+ltostr(ReadInfo("file_number"));
  30.  }
  31.  if (strlen(cmd) && cmd[strlen(cmd)-1]<32)
  32.    cmd[strlen(cmd)-1]=' ';
  33.  
  34.  SaveString(cmdfname,"failat 21\ncd \""+currentdir+"\"\n"+cmd+" <NIL: >>"+outfname+"\ncd >"+dirfname+"\n");
  35.  errc=System("Execute >>"+outfname+" "+cmdfname,"",errfname);
  36.  GotoLine(-1,-1);
  37.  if(!ReadInfo("filehandler")) {
  38.    InsertFile(outfname);
  39.    Output(LoadString(errfname));
  40.  }
  41.  currentdir=LoadString(dirfname);
  42.  currentdir=substr(currentdir,0,strlen(currentdir)-1);
  43.  Output(currentdir+">"); 
  44.  SetInfo(-1,"changes",0);
  45. };
  46.  
  47. export void TabFNC()
  48. {
  49.  int cmndstrt,flns;
  50.  string cmline,flnm,nflnm;
  51.  string files[1];
  52.  int filecnt;
  53.  if (GetBufferID()==bufferid)
  54.  {
  55.   GotoLine(-1,260);
  56.   cmline=GetLine();
  57.   cmndstrt=strstr(cmline,">",0)+1;
  58.   cmline=substr(cmline,cmndstrt,-1);
  59.   flns=strlen(cmline)-1;
  60.   if (flns!=-1){
  61.   while ((flns>=0)&&(cmline[flns] != ' ')&&(cmline[flns] != '\"'))
  62.   {flns--;};flns++;}
  63.   else{flns=0;};
  64.   flnm=substr(cmline,flns,-1);
  65.   cmline=substr(cmline,0,flns);
  66.   if (strlen(flnm)==0){flnm=currentdir;};
  67.   nflnm=flnm;
  68.   filecnt=GetFileList(nflnm+"#?",&files);
  69.   if(RequestWindow("Select File",50,"","A",&files,&nflnm,filecnt))
  70.   {
  71.    cmline=cmline+nflnm;
  72.   }else
  73.   {
  74.    cmline=cmline+flnm;
  75.   }
  76.   GotoLine(-1,cmndstrt);DeleteEol();
  77.   Output(cmline);
  78.  }else
  79.  {
  80.   Output("\t");
  81.  }
  82. }
  83.  
  84. export void ProcessShellCmndLine()
  85. {
  86.  int cmndstrt;
  87.  string cmline;
  88.  cmline=GetLine();
  89.  Output("\n");
  90.  if (GetBufferID()==bufferid)
  91.  {
  92.   GotoLine(-1,260);
  93.   cmndstrt=strstr(cmline,">",0)+1;
  94.   cmline=substr(cmline,cmndstrt,-1);
  95.   if (ValidCommand(cmline))
  96.    {DoShellCmnd(cmline);}else{DoShellCmnd("Echo");};
  97.   System("Delete "+outfname,"","NIL:");
  98.  }
  99. };
  100.  
  101. void SetupFrexxShell()
  102. {
  103.  string bfids;
  104.  AssignKey("ProcessShellCmndLine();","'Return'");
  105.  AssignKey("TabFNC();","'Tab'");
  106.  currentdir="SYS:";
  107.  bufferid=New();
  108.  Activate(bufferid,1);
  109.  CurrentBuffer(bufferid);
  110.  Rename("FrexxCon");
  111.  bufferid=GetBufferID("FrexxCon");
  112.  bfids=itoa(bufferid);
  113.  cmdfname="T:FShCmd_"+bfids;
  114.  outfname="T:FShOut_"+bfids;
  115.  dirfname="T:FShDir_"+bfids;
  116.  errfname="T:FShErr_"+bfids;
  117.  DoShellCmnd("echo FrexxShell by Carsten Orthbandt");
  118. };
  119.  
  120. SetupFrexxShell();
  121.