home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / System / Sysmon / src / Request.c < prev    next >
C/C++ Source or Header  |  2000-05-30  |  3KB  |  107 lines

  1. /*
  2. **    $RCSfile: Request.c,v $
  3. **    $Filename: Request.c $
  4. **    $Revision: 0.1 $
  5. **    $Date: 1995/04/15 17:33:51 $
  6. **
  7. **    sysmon.library support command Request (version 0.1)
  8. **    
  9. **    (C) Copyright 1995 by Etienne Vogt
  10. */
  11.  
  12. #include <exec/alerts.h>
  13. #include <exec/memory.h>
  14. #include <dos/dos.h>
  15. #include <workbench/startup.h>
  16. #define __USE_SYSBASE
  17. #include <proto/exec.h>
  18. #include <proto/dos.h>
  19. #include <clib/alib_protos.h>
  20. #include <string.h>
  21.  
  22. struct ExecBase *SysBase;
  23. struct DosLibrary *DOSBase;
  24. static struct WBStartup *wbmsg;
  25. static struct RDArgs *myrda;
  26.  
  27. static UBYTE version[] = "$VER: Request 0.1 (6.8.95)";
  28. static UBYTE template[] = "OFF/S,ON/S,WB/S";
  29.  
  30. #define    OPT_OFF    0
  31. #define    OPT_ON    1
  32. #define OPT_WB    2
  33. #define OPTMAX    3
  34.  
  35. ULONG __saveds main(void);
  36. static void cleanexit(ULONG rc);
  37.  
  38. ULONG __saveds main(void)    /* No startup code */
  39. {
  40.   struct Process *myproc;
  41.   LONG opts[OPTMAX];
  42.  
  43.   SysBase = *(struct ExecBase **)4;
  44.   DOSBase = NULL;
  45.   wbmsg = NULL;
  46.   myrda = NULL;
  47.  
  48.   myproc = (struct Process *)FindTask(NULL);
  49.   if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",36)) == NULL)
  50.   { Alert(AT_Recovery|AG_OpenLib|AO_DOSLib);
  51.     return 100;
  52.   }
  53.  
  54.   if (!(myproc->pr_CLI))        /* If started from WB, exit cleanly */
  55.   { WaitPort(&(myproc->pr_MsgPort));
  56.     wbmsg = (struct WBStartup *)GetMsg(&(myproc->pr_MsgPort));
  57.     cleanexit(20);
  58.   }
  59.   else
  60.   { memset((char *)opts, 0, sizeof(opts));
  61.     if ((myrda = ReadArgs(template, opts, NULL)) == NULL)
  62.     { PrintFault(IoErr(),"Request failed");
  63.       cleanexit(20);
  64.     }
  65.     if (opts[OPT_OFF]) myproc->pr_WindowPtr = (APTR)-1L;
  66.     if (opts[OPT_WB]) myproc->pr_WindowPtr = NULL;
  67.     if (opts[OPT_ON])
  68.     { struct MsgPort *conport;
  69.       struct InfoData *myinfo;
  70.       APTR cliwin = NULL;
  71.  
  72.       if (myinfo = AllocVec(sizeof(struct InfoData), MEMF_PUBLIC | MEMF_CLEAR))
  73.       { if (conport = GetConsoleTask())
  74.     { if (DoPkt1(conport, ACTION_DISK_INFO, MKBADDR(myinfo)) == DOSTRUE) cliwin = (APTR)myinfo->id_VolumeNode;
  75.     }
  76.     FreeVec(myinfo);
  77.       }
  78.       myproc->pr_WindowPtr = cliwin;
  79.     }
  80.     PutStr("System Requesters are ");
  81.     switch ((LONG)myproc->pr_WindowPtr)
  82.     { case 0:
  83.     PutStr("On Default Public Screen.\n");
  84.     break;
  85.       case -1:
  86.     PutStr("Disabled.\n");
  87.     break;
  88.       default:
  89.     PutStr("On Window Screen.\n");
  90.     break;
  91.     }
  92.   }
  93.  
  94.   cleanexit(0);
  95. }
  96.  
  97. static void cleanexit(ULONG rc)
  98. {
  99.   if (myrda) FreeArgs(myrda);
  100.   if (DOSBase) CloseLibrary((struct Library *)DOSBase);
  101.   if (wbmsg)
  102.   { Forbid();
  103.     ReplyMsg((struct Message *)wbmsg);
  104.   }
  105.   Exit(rc);
  106. }
  107.