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

  1. /*
  2. **    $RCSfile: UnFreeze.c,v $
  3. **    $Filename: UnFreeze.c $
  4. **    $Revision: 0.12 $
  5. **    $Date: 1995/02/18 17:33:51 $
  6. **
  7. **    sysmon.library startup command UnFreeze (version 0.3)
  8. **    
  9. **    (C) Copyright 1995 by Etienne Vogt
  10. */
  11.  
  12. #include <exec/alerts.h>
  13. #include <dos/dos.h>
  14. #include <workbench/startup.h>
  15. #define __USE_SYSBASE
  16. #include <proto/exec.h>
  17. #include <proto/dos.h>
  18. #include <string.h>
  19. #include <stdlib.h>
  20. #include "sysmon_protos.h"
  21. #include "sysmon_pragmas.h"
  22.  
  23. struct ExecBase *SysBase;
  24. struct DosLibrary *DOSBase;
  25. struct Library *SysmonBase;
  26. static struct WBStartup *wbmsg;
  27. static struct RDArgs *myrda;
  28.  
  29. ULONG __saveds main(void);
  30. static void cleanexit(ULONG rc);
  31.  
  32. static UBYTE version[] = "$VER: UnFreeze 0.3 (5.8.95)";
  33. static UBYTE template[] = "TASK,ADDR=ADDRESS/K";
  34.  
  35. #define    OPT_TASK    0
  36. #define OPT_ADDRESS    1
  37. #define OPTMAX        2
  38.  
  39. ULONG __saveds main(void)    /* No startup code */
  40. {
  41.   struct Process *myproc;
  42.   struct Task *task = NULL;
  43.   LONG opts[OPTMAX];
  44.  
  45.   SysBase = *(struct ExecBase **)4;
  46.   DOSBase = NULL;
  47.   SysmonBase = NULL;
  48.   wbmsg = NULL;
  49.   myrda = NULL;
  50.  
  51.   myproc = (struct Process *)FindTask(NULL);
  52.   if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",36)) == NULL)
  53.   { Alert(AT_Recovery|AG_OpenLib|AO_DOSLib);
  54.     return 100;
  55.   }
  56.  
  57.   if (!(myproc->pr_CLI))        /* If started from WB, exit cleanly */
  58.   { WaitPort(&(myproc->pr_MsgPort));
  59.     wbmsg = (struct WBStartup *)GetMsg(&(myproc->pr_MsgPort));
  60.     cleanexit(20);
  61.   }
  62.   else
  63.   { memset((char *)opts, 0, sizeof(opts));
  64.     if ((SysmonBase = OpenLibrary("sysmon.library",0)) == NULL)
  65.     { Printf("UnFreeze : Couldn't open sysmon.library\n");
  66.       cleanexit(20);
  67.     }
  68.     if ((myrda = ReadArgs(template, opts, NULL)) == NULL)
  69.     { PrintFault(IoErr(),NULL);
  70.       cleanexit(20);
  71.     }
  72.     if (opts[OPT_TASK])
  73.     { if ((task = FindTask((STRPTR)opts[OPT_TASK])) == NULL)
  74.       { Printf("UnFreeze : Unable to find task %s\n",opts[OPT_TASK]);
  75.     cleanexit(20);
  76.       }
  77.     }
  78.     else if (opts[OPT_ADDRESS])
  79.     { task = (struct Task *)strtoul((const char *)opts[OPT_ADDRESS], NULL, 16);
  80.       if (task == NULL) task = FindTask(0);
  81.       if (TypeOfMem(task) == NULL || (task->tc_Node.ln_Type != NT_TASK && task->tc_Node.ln_Type != NT_PROCESS))
  82.       { Printf("UnFreeze : Address %08lx is not a valid Task structure\n", task);
  83.     cleanexit(20);
  84.       }
  85.     }
  86.     else
  87.     { Printf("UnFreeze : Required Argument missing\n");
  88.       cleanexit(20);
  89.     }
  90.     if (!smUnFreeze(task))
  91.     { Printf("UnFreeze : Task %08lx couldn't be unfrozen.\n", task);
  92.       cleanexit(10);
  93.     }
  94.   }
  95.   cleanexit(0);
  96. }
  97.  
  98. static void cleanexit(ULONG rc)
  99. {
  100.   if (myrda) FreeArgs(myrda);
  101.   if (DOSBase) CloseLibrary((struct Library *)DOSBase);
  102.   if (SysmonBase) CloseLibrary(SysmonBase);
  103.   if (wbmsg)
  104.   { Forbid();
  105.     ReplyMsg((struct Message *)wbmsg);
  106.   }
  107.   Exit(rc);
  108. }
  109.