home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / programming / osclid / !OscliD / Tools / c / toollib < prev   
Encoding:
Text File  |  1997-08-31  |  1.1 KB  |  64 lines

  1. /* toollib.c
  2.  * Library for OscliD tools
  3.  * (c) Chris Rutter 1996
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "os:os.h"
  10. #include "os:wimp.h"
  11. #include "os:taskmanage.h"
  12.  
  13. extern void tool_main (int argc, char *argv[]);
  14. wimp_t taskhandle (char *);
  15.  
  16. wimp_block block[1];
  17.  
  18. int main (int argc, char *argv[])
  19. {
  20.     xwimp_initialise (wimp_VERSION_RO3, TOOLNAME, 0, 0, 0);
  21.     tool_main (argc, argv);
  22. }
  23.  
  24. void wait (int cs)
  25. {
  26.     wimp_poll_idle (0, block, os_read_monotonic_time() + cs, 0);
  27. }
  28.  
  29. int running (char *name)
  30. {
  31.     if (taskhandle (name)) return TRUE;
  32.     else return FALSE;
  33. }
  34.  
  35. void kill (char *name)
  36. {
  37.     wimp_message message;
  38.     message.size=256;
  39.     message.your_ref=0;
  40.     message.action=0;
  41.     if (running (name)) wimp_send_message (wimp_USER_MESSAGE, &message, taskhandle (name));
  42. }
  43.  
  44. void reset (void)
  45. {
  46.     taskmanager_shutdown (0);
  47. }
  48.  
  49. wimp_t taskhandle (char *name)
  50. {
  51.     int context = 0;
  52.     char *end = 0;
  53.     wimp_t handle = 0;
  54.     taskmanager_task task;
  55.     while (context >= 0)
  56.     {
  57.         context = taskmanager_enumerate_tasks (context, &task, sizeof task, &end);
  58.         if (!strcmp (task.name, name)) handle = task.task;
  59.     }
  60.     return handle;
  61. }
  62.  
  63. void tool_main (int argc, char *argv[])
  64.