home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CTASK22.ZIP / TSKNAME.C < prev    next >
C/C++ Source or Header  |  1990-10-12  |  3KB  |  114 lines

  1. /*
  2.    --- Version 2.2 90-10-12 10:33 ---
  3.  
  4.    CTask Name searching routines
  5.  
  6.    Public Domain Software written by
  7.       Thomas Wagner
  8.       Ferrari electronic Gmbh
  9.       Beusselstrasse 27
  10.       D-1000 Berlin 21
  11.       Germany
  12.  
  13.    This file is new with version 2.1.
  14.    The find_name and find_group_name functions were moved here from
  15.    'tsksub.c', since they are not needed in the basic kernel.
  16.    This will save some code in applications not using the routines.
  17.  
  18.    The add_name function to add a statically allocated structure to
  19.    the name list has been added in version 2.1.
  20. */
  21.  
  22. #include "tsk.h"
  23. #include "tsklocal.h"
  24.  
  25. #if (TSK_NAMED)
  26.  
  27. local int Staticfunc tsk_streq (byteptr n1, byteptr n2)
  28. {
  29.    while (*n1 && *n1 == *n2)
  30.       {
  31.       n1++;
  32.       n2++;
  33.       }
  34.    return *n1 == *n2; 
  35. }
  36.  
  37. /*
  38.    find_name
  39.    find_group_name
  40.       find structure, given name and type. 
  41.       If type is less than zero, the first name-element matching the
  42.       name is returned.
  43.       If type is greater or equal to zero, the first structure matching
  44.       the name and type is returned.
  45. */
  46.  
  47. #if (GROUPS)
  48. farptr Globalfunc find_group_name (gcbptr group, byteptr name, int kind)
  49. {
  50.    queptr curr;
  51.  
  52.    if (kind == TYP_GROUP && tsk_streq (name, group->namelist.name))
  53.       return group;
  54.  
  55.    for (curr = group->namelist.list.first; !(curr->kind & Q_HEAD); curr = curr->next)
  56.       if (kind < 0 || (int)curr->kind == kind)
  57.          if (tsk_streq (name, ((nameptr)curr)->name))
  58.             return (kind >= 0) ? ((nameptr)curr)->strucp : curr;
  59.  
  60.    return LNULL;
  61. }
  62. #endif
  63.  
  64.  
  65. farptr Globalfunc find_name (byteptr name, int kind)
  66. {
  67. #if (GROUPS)
  68.    farptr curr;
  69.    gcbptr group;
  70.  
  71.    if (tsk_global == LNULL)
  72.       if (!ctask_resident ())
  73.          return LNULL;
  74.  
  75.    for (group = GLOBDATA current_task->group; 
  76.         group != LNULL; group = group->home)
  77.       if ((curr = find_group_name (group, name, kind)) != LNULL)
  78.          return curr;
  79. #else
  80.    queptr curr;
  81.  
  82.    if (kind == TYP_GROUP)
  83.       return LNULL;
  84.  
  85.    for (curr = GLOBDATA name_list.list.first; !(curr->kind & Q_HEAD);
  86.         curr = curr->next)
  87.       if (kind < 0 || (int)curr->kind == kind)
  88.          if (tsk_streq (name, ((nameptr)curr)->name))
  89.             return (kind >= 0) ? ((nameptr)curr)->strucp : curr;
  90. #endif
  91.  
  92.    return LNULL;
  93. }
  94.  
  95.  
  96. void Globalfunc add_event_name (nameptr elem)
  97. {
  98.    CRITICAL;
  99.  
  100.    if (elem->name [0] && elem->list.first == LNULL)
  101.       {
  102.       C_ENTER;
  103. #if (GROUPS)
  104.       tsk_putqueue (&GLOBDATA current_task->group->namelist.list, (queptr)&elem->list);
  105. #else
  106.       tsk_putqueue (&GLOBDATA name_list.list, (queptr)&elem->list);
  107. #endif
  108.       C_LEAVE;
  109.       }
  110. }
  111. #endif
  112.  
  113.  
  114.