home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / lib / c / c_string.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  1.4 KB  |  68 lines

  1. /* << ACE >> - db.lib module: C string functions.
  2. ** Copyright (C) 1998 David Benn
  3. ** 
  4. ** This program is free software; you can redistribute it and/or
  5. ** modify it under the terms of the GNU General Public License
  6. ** as published by the Free Software Foundation; either version 2
  7. ** of the License, or (at your option) any later version.
  8. **
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU General Public License for more details.
  13. **
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. **
  18. **  Author: David J Benn
  19. **    Date: 19th,20th March 1994,
  20. **        17th October 1996
  21. */
  22.  
  23. #include <exec/types.h>
  24.  
  25. /* functions */
  26.  
  27. void stringcopy(a,b)
  28. char *a,*b;
  29. {
  30.      /* copy contents of b to a */
  31.  
  32.     while (*a++ = *b++);
  33. }
  34.  
  35. ULONG stringlength(a)
  36. char *a;
  37. {
  38. long i=0;
  39.  
  40.     /* return length of a */
  41.  
  42.     while (a[i]) i++;
  43.     return(i);            
  44. }
  45.  
  46. LONG stringcompare(s,t)
  47. char *s,*t;
  48. {
  49.     /* lexicographical comparison of 2 strings */
  50.  
  51.     while (s && t && *s == *t)
  52.     {
  53.         if (!*s) return(0);  /* EOS */
  54.         s++;
  55.         t++;
  56.     }
  57.  
  58.     /* if either string is null treat as if it were "" ? */
  59.  
  60.     if (s && !t) 
  61.         return(*s);   /* ie. *s - 0 */
  62.     else
  63.     if (!s && t) 
  64.         return(0 - *t);
  65.     else
  66.         return(*s - *t);
  67. }
  68.