home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Internet / Strony_WWW / Opus4.x / DOpus414JRsrc.lha / DirectoryOpus4 / DOpusRT / DOpusRT.c next >
C/C++ Source or Header  |  2000-03-04  |  11KB  |  340 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. //#include <fctype.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <exec/types.h>
  35. #include <exec/memory.h>
  36. #include <exec/execbase.h>
  37. #include <dos/dos.h>
  38. #include <dos/dosextens.h>
  39. #include <dos/exall.h>
  40. #include <intuition/intuitionbase.h>
  41. #include <graphics/gfxbase.h>
  42. #include <devices/input.h>
  43. #include <proto/all.h>
  44.  
  45. #include <proto/dopus.h>
  46.  
  47. extern struct ExecBase *SysBase;
  48. extern struct DosLibrary *DOSBase;
  49. struct DOpusBase *DOpusBase;
  50.  
  51. void main(int,char **);
  52. void WBRun(int,char **);
  53. int setarg(struct WBArg *,char *,BPTR);
  54. BPTR FindPath(char *);
  55.  
  56. void InputHandler(void);
  57.  
  58. char *version="$VER: DOpusRT 4.4 (3 Mar 2000) recompiled under GPL license by Jacek Rzeuski";
  59.  
  60. char
  61.     *pathlists[7]={
  62.         "Workbench",
  63.         "Initial CLI",
  64.         "Shell Process",
  65.         "New CLI",
  66.         "AmigaShell",
  67.         "New_WShell",
  68.         "Background CLI"};
  69.  
  70. void main(argc,argv)
  71. int argc;
  72. char *argv[];
  73. {
  74.     int a,out,x,y,flag;
  75.     struct MsgPort *port,*port1;
  76.     struct Process *myproc;
  77.     struct Message msg;
  78.     struct InfoData __aligned ind;
  79.     struct Window *win;
  80.     struct CommandLineInterface *cli;
  81.     void *cont;
  82.     BPTR path;
  83.     ULONG arg;
  84.     struct IntuitionBase *IntuitionBase;
  85.     struct GfxBase *GfxBase;
  86.     struct Interrupt *interrupt;
  87.     struct IOStdReq *inputreq;
  88.  
  89.     if (argc<2 ||
  90.         !(DOpusBase=(struct DOpusBase *)OpenLibrary("dopus.library",0))) _exit(0);
  91.     IntuitionBase=DOpusBase->IntuitionBase;
  92.     GfxBase=DOpusBase->GfxBase;
  93.  
  94.     myproc=(struct Process *)FindTask(NULL);
  95.     cli=(struct CommandLineInterface *)(myproc->pr_CLI<<2);
  96.  
  97.     win=NULL;
  98.     if ((cont=myproc->pr_ConsoleTask)) {
  99.         arg=(ULONG)(&ind)>>2;
  100.         if (SendPacket(cont,ACTION_DISK_INFO,&arg,1))
  101.             win=(struct Window *)ind.id_VolumeNode;
  102.     }
  103.     out=Output();
  104.  
  105.     if (LStrnCmp(argv[1],"-s",2)==0) {
  106.         if (win) {
  107.             if ((win->WScreen->Flags&SCREENTYPE)!=WBENCHSCREEN) {
  108.                 myproc->pr_WindowPtr=(APTR)win;
  109.                 SetFont(win->RPort,GfxBase->DefaultFont);
  110.                 Write(out,"\x1b\x63",2);
  111.             }
  112.         }
  113.         if (cli && !cli->cli_CommandDir) {
  114.             for (a=0;a<7;a++) if ((path=FindPath(pathlists[a]))) break;
  115.             cli->cli_CommandDir=path;
  116.         }
  117.     }
  118.     else if (LStrnCmp(argv[1],"-w",2)==0) {
  119.         if ((a=atoi(argv[2]))>60) a=60;
  120.         if (a>0) Delay(a*50);
  121.         else if (a==-1) {
  122.             if (out) {
  123.                 if (port=LCreatePort(NULL,0)) {
  124.                     if (inputreq=(struct IOStdReq *)LCreateExtIO(port,sizeof(struct IOStdReq))) {
  125.                         if (!(OpenDevice("input.device",NULL,(struct IORequest *)inputreq,NULL))) {
  126.                             if (interrupt=AllocMem(sizeof(struct Interrupt),MEMF_CLEAR|MEMF_PUBLIC)) {
  127.                                 interrupt->is_Code=InputHandler;
  128.                                 interrupt->is_Node.ln_Pri=51;
  129.                                 interrupt->is_Node.ln_Name="DOpusRT";
  130.                                 interrupt->is_Data=myproc;
  131.                                 if (argc>3) {
  132.                                     Write(out,"\n",1);
  133.                                     Write(out,argv[3],strlen(argv[3]));
  134.                                 }
  135.                                 else Write(out,"\nPress left mouse button to continue...",39);
  136.                                 inputreq->io_Data=(APTR)interrupt;
  137.                                 inputreq->io_Command=IND_ADDHANDLER;
  138.                                 DoIO((struct IORequest *)inputreq);
  139.                                 flag=0;
  140.                                 FOREVER {
  141.                                     a=Wait(3);
  142.                                     if (!win) break;
  143.                                     if (IntuitionBase->ActiveWindow==win) {
  144.                                         if (a&1) {
  145.                                             x=win->MouseX; y=win->MouseY;
  146.                                             if (x<=win->BorderLeft || x>=win->Width-win->BorderRight ||
  147.                                                 y<=win->BorderTop && y>=win->Height-win->BorderBottom) flag=0;
  148.                                             else flag=1;
  149.                                         }
  150.                                         else if (a&2 && flag) {
  151.                                             flag=0;
  152.                                             if (x>win->BorderLeft && x<win->Width-win->BorderRight &&
  153.                                                 y>win->BorderTop && y<win->Height-win->BorderBottom) break;
  154.                                         }
  155.                                     }
  156.                                 }
  157.                                 inputreq->io_Data=(APTR)interrupt;
  158.                                 inputreq->io_Command=IND_REMHANDLER;
  159.                                 DoIO((struct IORequest *)inputreq);
  160.                                 FreeMem(interrupt,sizeof(struct Interrupt));
  161.                             }
  162.                             CloseDevice((struct IORequest *)inputreq);
  163.                         }
  164.                         LDeleteExtIO((struct IORequest *)inputreq);
  165.                     }
  166.                     LDeletePort(port);
  167.                 }
  168.             }
  169.         }
  170.     }
  171.     else if (LStrnCmp(argv[1],"-p",2)==0) {
  172.         Forbid();
  173.         if ((port=FindPort(argv[2]))) {
  174.             Permit();
  175.             port1=LCreatePort(0,0);
  176.             msg.mn_Node.ln_Type=NT_MESSAGE;
  177.             msg.mn_ReplyPort=port1;
  178.             msg.mn_Length=sizeof(struct Message);
  179.             PutMsg(port,&msg);
  180.             WaitPort(port1);
  181.             LDeletePort(port1);
  182.         }
  183.         else Permit();
  184.     }
  185.     else if (LStrnCmp(argv[1],"-r",2)==0) WBRun(argc-2,&argv[2]);
  186.     CloseLibrary((struct Library *)DOpusBase);
  187.     _exit(0);
  188. }
  189.  
  190. BPTR FindPath(taskname)
  191. char *taskname;
  192. {
  193.     struct Process *teacher;
  194.     struct CommandLineInterface *teachcli;
  195.     BPTR *wext,*mext,*lastmext,newpath=0;
  196.  
  197.     if (!(teacher=(struct Process *)FindTask(taskname))) return(0);
  198.     lastmext=&newpath;
  199.     if (!(teachcli=(struct CommandLineInterface *)(teacher->pr_CLI<<2)))
  200.         return(0);
  201.     Forbid();
  202.     for (wext=(BPTR *)(teachcli->cli_CommandDir<<2);wext;wext=(BPTR *)(*wext<<2)) {
  203.         if (!(mext=AllocMem(3*sizeof(BPTR),MEMF_PUBLIC))) break;
  204.         *lastmext=(long)(mext+1)>>2;
  205.         lastmext=mext+1;
  206.         mext[2]=DupLock(wext[1]);
  207.         mext[1]=0;
  208.         *mext=3*sizeof(BPTR);
  209.     }
  210.     Permit();
  211.     return(newpath);
  212. }
  213.  
  214. void WBRun(argc,argv)
  215. int argc;
  216. char **argv;
  217. {
  218.     struct WBStartup *WBStartup;
  219.     struct DiskObject *diskobj;
  220.     char namebuf[256];
  221.     int stacksize,i;
  222.     struct Process *ourtask;
  223.     struct MsgPort *replyport;
  224.     BPTR olddir;
  225.     struct IconBase *IconBase;
  226.     struct DOpusRemember *key;
  227.     struct CommandLineInterface *cli;
  228.  
  229.     diskobj=NULL; replyport=NULL; olddir=-1; key=NULL;
  230.  
  231.     if (argc<1 ||
  232.         !(IconBase=(struct IconBase *)OpenLibrary("icon.library",0))) return;
  233.  
  234.     ourtask=(struct Process *)FindTask(NULL);
  235.     if (!(WBStartup=LAllocRemember(&key,sizeof(struct WBStartup),MEMF_CLEAR)) ||
  236.         !(WBStartup->sm_ArgList=LAllocRemember(&key,sizeof(struct WBArg)*(argc+1),MEMF_CLEAR)) ||
  237.         !(replyport=LCreatePort(NULL,0))) goto done;
  238.  
  239.     WBStartup->sm_Message.mn_ReplyPort=replyport;
  240.     WBStartup->sm_NumArgs=argc;
  241.  
  242.     for (i=0;i<argc;i++)
  243.         if (setarg(&WBStartup->sm_ArgList[i],argv[i],ourtask->pr_CurrentDir))
  244.             goto done;
  245.  
  246.     olddir=CurrentDir(WBStartup->sm_ArgList[0].wa_Lock);
  247.     if (!(diskobj=GetDiskObject(WBStartup->sm_ArgList[0].wa_Name))) {
  248.         if (!(SearchPathList(argv[0],namebuf,256))) goto done;
  249.     }
  250.     else if (diskobj->do_Type==WBTOOL) strcpy(namebuf,argv[0]);
  251.     else if (diskobj->do_Type==WBPROJECT) {
  252.         if (!(SearchPathList(diskobj->do_DefaultTool,namebuf,256))) goto done;
  253.         for (i=argc-1;i>=0;i--)
  254.             CopyMem(&WBStartup->sm_ArgList[i],&WBStartup->sm_ArgList[i+1],
  255.                 sizeof(struct WBArg));
  256.         if (setarg(&WBStartup->sm_ArgList[0],namebuf,WBStartup->sm_ArgList[0].wa_Lock))
  257.             goto done;
  258.         ++WBStartup->sm_NumArgs;
  259.     }
  260.     else goto done;
  261.  
  262.     if (!diskobj) {
  263.         if ((cli=(struct CommandLineInterface *)(ourtask->pr_CLI<<2)))
  264.             stacksize=cli->cli_DefaultStack*4;
  265.         else stacksize=4096;
  266.     }
  267.     else stacksize=diskobj->do_StackSize;
  268.  
  269.     stacksize=(stacksize+3)&(~3);
  270.     if (stacksize<4096) stacksize=4096;
  271.  
  272.     if (!(WBStartup->sm_Segment=(BPTR)LoadSeg(namebuf))) goto done;
  273.  
  274.     Forbid();
  275.     if (!(WBStartup->sm_Process=CreateProc(BaseName(namebuf),
  276.         ourtask->pr_Task.tc_Node.ln_Pri,WBStartup->sm_Segment,stacksize))) {
  277.         Permit();
  278.         goto done;
  279.     }
  280.  
  281.     if (DOSBase->dl_lib.lib_Version>=36) {
  282.         struct Process *proc;
  283.         char *ptr;
  284.  
  285.         if (ptr=BaseName(namebuf)) *ptr=0;
  286.         proc=(struct Process *)WBStartup->sm_Process->mp_SigTask;
  287.         proc->pr_HomeDir=Lock(ptr,ACCESS_READ);
  288.     }
  289.  
  290.     WBStartup->sm_ToolWindow=(diskobj)?diskobj->do_ToolWindow:NULL;
  291.     Permit();
  292.  
  293.     PutMsg(WBStartup->sm_Process,(struct Message *)WBStartup);
  294.     WaitPort(replyport);
  295. done:
  296.     if (replyport) LDeletePort(replyport);
  297.     if (diskobj) FreeDiskObject(diskobj);
  298.     if (olddir!=-1) CurrentDir(olddir);
  299.     if (WBStartup) {
  300.         if (WBStartup->sm_Segment) UnLoadSeg(WBStartup->sm_Segment);
  301.         if (WBStartup->sm_ArgList) {
  302.             for (i=0;i<WBStartup->sm_NumArgs;i++) {
  303.                 if (WBStartup->sm_ArgList[i].wa_Lock)
  304.                     UnLock(WBStartup->sm_ArgList[i].wa_Lock);
  305.             }
  306.         }
  307.     }
  308.     LFreeRemember(&key);
  309.     if (IconBase) CloseLibrary((struct Library *)IconBase);
  310. }
  311.  
  312. int setarg(WBArg,name,curdir)
  313. struct WBArg *WBArg;
  314. char *name;
  315. BPTR curdir;
  316. {
  317.     char *p,*lastc;
  318.     unsigned char c;
  319.  
  320.     if (!name || !name[0]) return(1);
  321.  
  322.     lastc=NULL;
  323.     for (p=name;*p;p++)
  324.         if (*p==':' || *p=='/') lastc=p+1;
  325.  
  326.     if (!lastc) {
  327.         WBArg->wa_Lock=DupLock(curdir);
  328.         WBArg->wa_Name=name;
  329.     }
  330.     else {
  331.         if (!lastc[0]) return(1);
  332.         WBArg->wa_Name=lastc;
  333.         c=lastc[0];
  334.         lastc[0]=0;
  335.         if (!(WBArg->wa_Lock=Lock(name,ACCESS_READ))) return(1);
  336.         *lastc=c;
  337.     }
  338.     return(0);
  339. }
  340.