home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PTREE10.ZIP / P_PRINT.C < prev    next >
C/C++ Source or Header  |  1990-03-22  |  2KB  |  120 lines

  1. /* p_print.c
  2. **
  3. ** Non-Copyright (c) 1990, Christopher Laforet.
  4. ** Released to the public domain.
  5. **
  6. ** Revision History:
  7. **
  8. ** $Header$
  9. **
  10. */
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "proctree.h"
  17.  
  18.  
  19.  
  20. short check_parent(USHORT parent,USHORT node)
  21.     {
  22.     short count;
  23.  
  24.     for (count = (node + 1); count < cur_nodes; count++)
  25.         {
  26.         if (nodes[count]->ppid == parent)
  27.             return 1;
  28.         }
  29.     return 0;
  30.     }
  31.  
  32.  
  33.  
  34. short check_line(USHORT parent)
  35.     {
  36.     USHORT count;
  37.  
  38.     for (count = 0; count < cur_nodes; count++)
  39.         {
  40.         if (!nodes[count]->printed && nodes[count]->ppid == parent)
  41.             return 1;
  42.         }
  43.     return 0;
  44.     }
  45.  
  46.  
  47.  
  48. USHORT get_parent(USHORT pid)
  49.     {
  50.     short count;
  51.  
  52.     for (count = 0; count < cur_nodes; count++)
  53.         {
  54.         if (nodes[count]->pid == pid)
  55.             return nodes[count]->ppid;
  56.         }
  57.     printf("\nError: Unknown parent for PID %04x\n",pid);
  58.     exit(1);
  59.     }
  60.  
  61.  
  62. void print_tree(USHORT parent,short level)
  63.     {
  64.     USHORT count;
  65.     USHORT kount;
  66.     USHORT counter;
  67.     USHORT parent_check;
  68.  
  69.     for (count = 0; count < cur_nodes; count++)
  70.         {
  71.         if (nodes[count]->ppid == parent && !nodes[count]->printed)
  72.             {
  73.             if (level)
  74.                 {
  75.                 if (check_line(0))
  76.                     printf(" \xb3   ");
  77.                 else
  78.                     printf("     ");
  79.                 for (kount = 1; kount < level; kount++)
  80.                     {
  81.                     parent_check = nodes[count]->ppid;
  82.                     for (counter = 0; counter < level - kount; counter++)
  83.                         parent_check = get_parent(parent_check);
  84.                     if (check_line(parent_check))
  85.                         printf(" \xb3   ");
  86.                     else
  87.                         printf("     ");
  88.                     }
  89.                 }
  90.             if (level >= 0)
  91.                 {
  92.                 if (check_parent(parent,count))
  93.                     printf(" \xc3\xc4\xc4\xc4");
  94.                 else
  95.                     printf(" \xc0\xc4\xc4\xc4");
  96.                 }
  97.             printf(" %s (PID=%04x Th=%u)\n",nodes[count]->name,nodes[count]->pid,nodes[count]->threads);
  98.             nodes[count]->printed = 1;
  99.             print_tree(nodes[count]->pid,level + 1);
  100.             }
  101.         }
  102.     }
  103.  
  104.  
  105.  
  106. #if 0
  107. void print_tree(void)
  108.     {
  109.     int count;
  110.  
  111.     for (count = 0; count < cur_nodes; count++)
  112.         {
  113.         if (nodes[count]->name)
  114.             printf("PID=%04x PPID=%04x Name=%s (%u)\n",nodes[count]->pid,nodes[count]->ppid,nodes[count]->name,nodes[count]->threads);
  115.         else 
  116.             printf("PID=%04x PPID=%04x Name=\"PID%04x\" (%u)\n",nodes[count]->pid,nodes[count]->ppid,nodes[count]->pid,nodes[count]->threads);
  117.         }
  118.     }
  119. #endif
  120.