ts.c 754 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* ts.c: minor string processing subroutines */
  2. #include "t.h"
  3. int
  4. match (char *s1, char *s2)
  5. {
  6. while (*s1 == *s2)
  7. if (*s1++ == '\0')
  8. return(1);
  9. else
  10. s2++;
  11. return(0);
  12. }
  13. int
  14. prefix(char *small, char *big)
  15. {
  16. int c;
  17. while ((c = *small++) == *big++)
  18. if (c == 0)
  19. return(1);
  20. return(c == 0);
  21. }
  22. int
  23. letter (int ch)
  24. {
  25. if (ch >= 'a' && ch <= 'z')
  26. return(1);
  27. if (ch >= 'A' && ch <= 'Z')
  28. return(1);
  29. return(0);
  30. }
  31. int
  32. numb(char *str)
  33. {
  34. /* convert to integer */
  35. int k;
  36. for (k = 0; *str >= '0' && *str <= '9'; str++)
  37. k = k * 10 + *str - '0';
  38. return(k);
  39. }
  40. int
  41. digit(int x)
  42. {
  43. return(x >= '0' && x <= '9');
  44. }
  45. int
  46. max(int a, int b)
  47. {
  48. return( a > b ? a : b);
  49. }
  50. void
  51. tcopy (char *s, char *t)
  52. {
  53. while (*s++ = *t++)
  54. ;
  55. }