home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_12 / 9n12021a < prev    next >
Text File  |  1991-10-15  |  2KB  |  74 lines

  1.  
  2. /* ------------------------------------------------------------ */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <signal.h>
  7. #include <string.h>
  8.  
  9. #define EXACT 1            /* locate_node match flags */
  10. #define INEXACT 2
  11. #define NUMELEM(a) (sizeof(a)/sizeof((a)[0]))
  12.  
  13. typedef struct node {
  14.     struct node *pfwd;    /* ptr to next node in list */
  15.     struct node *pbwd;    /* ptr to prev node in list */
  16.     void (*process)(unsigned);    /* function to call */
  17.     unsigned priority;    /* function priority */
  18. } Node;
  19.  
  20. Node *proot_node;    /* start of data list */
  21. Node *pfree_node = NULL;/* next free node */
  22.  
  23. Node *get_free_node(void);
  24. Node *locate_node(unsigned priority, int match);
  25.  
  26. void add_node(void);        /* action functions */
  27. void help(void);
  28. void myexit(void);
  29.  
  30. void proc_cmd(int dummy);
  31.  
  32. void idle(unsigned);        /* process functions */
  33. void pro1(unsigned);
  34. void pro2(unsigned);
  35. void pro3(unsigned);
  36.  
  37. /* --------------------------------------------------------------
  38.  
  39. FUNCTION MAIN: 
  40.     
  41. The dummy header node head_node is allocated and initialized in
  42. the declaration.
  43.  
  44. A. Register proc_cmd as the handler for the next SIGINT signal.
  45.     
  46. B. Cycle indefinitely through circular list, processing nodes.
  47.     
  48. -------------------------------------------------------------- */
  49.     
  50. main()
  51. {
  52.     const Node *pnode;        /* Node just allocated */
  53.     static Node head_node = {
  54.         &head_node,
  55.         &head_node,
  56.         &idle,
  57.         0
  58.     };
  59.  
  60. /*A*/    pnode = proot_node = &head_node;
  61.     if (signal(SIGINT, proc_cmd) == SIG_ERR) {
  62.         fprintf(stderr, "can't register handler\n");
  63.         exit(EXIT_FAILURE);
  64.     }
  65.  
  66. /*B*/    while (1) {
  67.         (*pnode->process)(pnode->priority);
  68.         pnode = pnode->pfwd;
  69.     }
  70.  
  71.     return(EXIT_SUCCESS);
  72. }
  73.  
  74.