home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l200 / 6.ddi / TOOL / STRING.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-21  |  1.5 KB  |  99 lines

  1. /* string.c - special string handling routines
  2.         
  3.     Copyright (c) 1984 by JMI Software Consultants, Inc.
  4. */
  5. #include "acom.h"
  6.  
  7. /*    strlen(s) returns the length of the string s
  8. */
  9.  
  10. INT strlen(s)
  11.     FAST TEXT *s;
  12.     {
  13.     FAST TEXT *t;
  14.  
  15.     for (t = s; *t++; )
  16.         ;
  17.     return (t - s - 1);
  18.     }
  19.  
  20. /*    strcpy(s1, s2) will copy the string s2 to s1.
  21. */
  22.  
  23. TEXT *strcpy(s1, s2)
  24.     FAST TEXT *s1, *s2;
  25.     {
  26.     while (*s1++ = *s2++)
  27.         ;
  28.     return (s1 - 1);
  29.     }
  30.  
  31. /*    strcmp compares two strings.
  32.     It returns the first difference encountered.
  33. */
  34.  
  35. INT strcmp(s1, s2)
  36.     FAST TEXT *s1, *s2;
  37.     {
  38.     FAST COUNT d;
  39.  
  40.     for (; !(d = tolower(*s1) - tolower(*s2)) && *s1; ++s1, ++s2)
  41.         ;
  42.     return (d);
  43.     }
  44.  
  45. /*    strcat(s1, s2) will concatenate string s2 onto string s1.
  46. */
  47.  
  48. TEXT *strcat(s1, s2)
  49.     FAST TEXT *s1, *s2;
  50.     {
  51.     FAST TEXT *orig_s1;
  52.  
  53.     orig_s1 = s1;
  54.     while (*s1)
  55.         s1++;
  56.     while (*s2)
  57.         *s1++ = *s2++;
  58.     *s1 = NULLCH;
  59.     return (orig_s1);
  60.     }
  61.  
  62. /* lookup -- look up a string in a table
  63. */
  64.  
  65. INT lookup(s, tab)
  66.     TEXT *s, **tab;
  67.     {
  68.     TEXT string[80];
  69.     INT i;
  70.  
  71.     for (i = 0; string[i] = tolower(*s); ++i)
  72.         ++s;
  73.     for (i = 0; tab[i]; ++i)
  74.         if (strcmp(string, tab[i]) == 0)
  75.             return (i);
  76.     return (-1);
  77.     }
  78.  
  79. /* namcpy.c -- copy filename up to the last period
  80. */
  81.  
  82. TEXT *namcpy(buf, name)
  83.     TEXT *buf, *name;
  84.     {
  85.     TEXT *s, *t;
  86.  
  87.     s = t = buf;
  88.     while (*buf = *name++)
  89.         {
  90.         if (*buf == '.')
  91.             s = buf;
  92.         ++buf;
  93.         }
  94.     if (s - t)
  95.         return(s);
  96.     else
  97.         return(buf);
  98.     }
  99.