home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 309_01 / strings.h < prev    next >
Text File  |  1990-03-20  |  2KB  |  115 lines

  1. /* strings.h  for 6809 */
  2.  
  3. #code
  4.  
  5. strcmp(s, t)                   /* if s > t, return > 0                 */
  6. char *s, *t;                   /* if s = t, return   0                 */
  7. {                              /* if s < t, return < 0                 */
  8.   while( *s == *t++)
  9.     if( !*s++) return 0;
  10.   return *s-t[-1];
  11. }
  12.  
  13. strrev(str)        /* reverse characters in s */
  14. char *str;
  15. {
  16.   char *head, *tail, temp;
  17.   int count;
  18.  
  19.   head = str;
  20.   tail = str;
  21.   count = 0;
  22.   while( *tail != 0x00 ) {  tail++; count++; }
  23.   tail--;
  24.   count = count >> 1;
  25.   while( count-- )
  26.   {
  27.     temp = *head;
  28.     *head = *tail;
  29.     head++;
  30.     *tail = temp;
  31.     tail--;
  32.   }
  33. }
  34.  
  35. strcat(s, t)             /* concats t onto s */
  36. char *s, *t;
  37. {
  38.   while( *s++ );
  39.   for( --s; *s++ = *t++; );
  40.   *s = 0x00;
  41. }
  42.  
  43. strcpy(dst, src)         /* copies src to dst                    */
  44. char *dst, *src;
  45. {
  46.   while( *dst++ = *src++ );
  47.   *dst = 0x00;
  48. }
  49.  
  50.  
  51. stricmp(s1, s2)         /* compare s2 against s1, ignore case, return 0 if equal */
  52. char *s1, *s2;
  53. {
  54.         char t1, t2;
  55.  
  56.         while( *s1 || *s2 )
  57.         {
  58.                 t1 = *s1 & 0xdf;
  59.                 t2 = *s2 & 0xdf;
  60.                 if( t1 != t2 ) return 1;
  61.                 s1++; s2++;
  62.         }
  63.         return 0;
  64. }
  65.  
  66. strncmp(s1, s2, count)  /* compare count characters of s1 and s2 */
  67. char *s1, *s2;
  68. int count;
  69. {
  70.   while( --count )
  71.   {
  72.     if( *s1++ != *s2++ )
  73.         return 1;
  74.   }
  75.   return 0;
  76. }
  77.  
  78. strncat(s1, s2, count)          /* copies s2 onto end of s1 */
  79. char *s1, *s2;
  80. int count;
  81. {
  82.         while( *s1 != 0x00 )          /* find end of s1 */
  83.                 s1++;
  84.  
  85.         while( (*s2) && (count != 0) )
  86.         {
  87.                 *s1++ = *s2++;
  88.                 count--;
  89.         }
  90.         *s1 = 0x00;
  91. }
  92.  
  93.  
  94. strncpy(s2, s1, count)   /* copy count characters from s1 to s2  */
  95. char *s1, *s2;
  96. int count;
  97. {
  98.   while ( *s2 != 0x00 )
  99.         s2++;
  100.  
  101.   while( (*s2++ = *s1++) && --count)
  102.     ;
  103.   *s2 = '\0';
  104. }
  105.  
  106. strlen(s)                  /* return length of s                   */
  107. char *s;
  108. {
  109.   int l;
  110.   l = 0;
  111.   while( *s++ ) ++l;
  112.   return l;
  113. }
  114.  
  115.