home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / ENV Server / Common src / utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-31  |  2.2 KB  |  99 lines  |  [TEXT/ALFA]

  1. /*
  2. ** utils.c
  3. **
  4. ** Contains code to check if a trap exists and a few small string
  5. ** functions put here for convenience.
  6. */
  7.  
  8. #include <OSUtils.h>
  9. #include <Traps.h>
  10. #include <Types.h>
  11. #include "utils.h"
  12.  
  13.  
  14. static TrapType GetTrapType(int);
  15. /*=================================================== */
  16. /*
  17. ** this is the code supporting Apple's official method
  18. ** of checking for the existence of a specific trap.
  19. ** See p. 3-8 of IM-VI for the details.
  20. */
  21.  
  22. #define NumToolboxTraps ( (NGetTrapAddress(_InitGraf, ToolTrap)==   \
  23.                          NGetTrapAddress(0xAA6e, ToolTrap)) ? 0x0200 : 0x0400)
  24.  
  25.  
  26. static TrapType GetTrapType(int theTrap)
  27. {
  28.     unsigned TrapMask = 0x0800;
  29.     return ((theTrap & TrapMask)>0 ? ToolTrap : OSTrap);
  30. } /* GetTrapType() */
  31.  
  32.  
  33. Boolean TrapAvailable(int theTrap)
  34. {
  35.     TrapType tType = GetTrapType( theTrap);
  36.     if (tType == ToolTrap) {
  37.         theTrap = (int)theTrap & (int)0x07ff;
  38.         if (theTrap >= NumToolboxTraps)
  39.             theTrap = _Unimplemented;
  40.     }
  41.     return (Boolean)(NGetTrapAddress(theTrap, tType) !=
  42.             NGetTrapAddress(_Unimplemented, ToolTrap));
  43. } /* TrapAvailable() */
  44.  
  45.  
  46. /*=================================================== */
  47.  
  48. /**************************
  49. ** mystrlen
  50. ** mystrcpy
  51. ** mystrcat
  52. **
  53. ** String routines put here for convenience.
  54. ** s2 is usually the "source" and s1 is the "destination."
  55. ** Would somebody like to recode these in assembly??
  56. ***************************/
  57. long mystrlen( char *s)
  58. {
  59.     register char *e = s;
  60.  
  61.     while (*e) e++;        /* find ending null */
  62.     return (e - s);        /* length = end - start */
  63. } /* mystrlen */
  64.  
  65.  
  66. char *mystrcpy( char *s1, char *s2)
  67.                 /* s2 into s1 */
  68. {
  69.     register char *dst = s1,   *src = s2;
  70.     while ( *dst++ = *src++) ;
  71.     return s1;
  72. } /* mystrcpy */
  73.  
  74.  
  75. char *mystrcat( char *s1, char *s2)
  76.                 /* s2 onto end of s1 */
  77. {
  78.     char *p;
  79.     p = s1 + mystrlen( s1);        /* p points to s1's nul */
  80.     mystrcpy( p, s2);            /* copy s2 onto end of s1; programmer must
  81.                                 ** ensure s1 is long enough - not my job! */
  82.     return s1;
  83. } /* mystrcat */
  84.  
  85.  
  86. char *mystrchr( char *s1, char c)
  87.                 /* find 1st occurrance of c in s1 */
  88. {
  89.     register char *p=s1;
  90.     while (*p && (*p != c)) p++;
  91.     if (*p == c)
  92.         return p;            /* if we found what we're looking for, rtn ptr */
  93.     else
  94.         return NULL;            /* if not found, return NULL */
  95. } /* mystrchr */
  96.  
  97.  
  98.  
  99.