ts.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /* ts.c: minor string processing subroutines */
  10. #include "t.h"
  11. int
  12. match (char *s1, char *s2)
  13. {
  14. while (*s1 == *s2)
  15. if (*s1++ == '\0')
  16. return(1);
  17. else
  18. s2++;
  19. return(0);
  20. }
  21. int
  22. prefix(char *small, char *big)
  23. {
  24. int c;
  25. while ((c = *small++) == *big++)
  26. if (c == 0)
  27. return(1);
  28. return(c == 0);
  29. }
  30. int
  31. letter (int ch)
  32. {
  33. if (ch >= 'a' && ch <= 'z')
  34. return(1);
  35. if (ch >= 'A' && ch <= 'Z')
  36. return(1);
  37. return(0);
  38. }
  39. int
  40. numb(char *str)
  41. {
  42. /* convert to integer */
  43. int k;
  44. for (k = 0; *str >= '0' && *str <= '9'; str++)
  45. k = k * 10 + *str - '0';
  46. return(k);
  47. }
  48. int
  49. digit(int x)
  50. {
  51. return(x >= '0' && x <= '9');
  52. }
  53. int
  54. max(int a, int b)
  55. {
  56. return( a > b ? a : b);
  57. }
  58. void
  59. tcopy (char *s, char *t)
  60. {
  61. while (*s++ = *t++)
  62. ;
  63. }