s_cmp.c 722 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "f2c.h"
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. /* compare two strings */
  6. #ifdef KR_headers
  7. integer s_cmp(a0, b0, la, lb) char *a0, *b0; ftnlen la, lb;
  8. #else
  9. integer s_cmp(char *a0, char *b0, ftnlen la, ftnlen lb)
  10. #endif
  11. {
  12. register unsigned char *a, *aend, *b, *bend;
  13. a = (unsigned char *)a0;
  14. b = (unsigned char *)b0;
  15. aend = a + la;
  16. bend = b + lb;
  17. if(la <= lb)
  18. {
  19. while(a < aend)
  20. if(*a != *b)
  21. return( *a - *b );
  22. else
  23. { ++a; ++b; }
  24. while(b < bend)
  25. if(*b != ' ')
  26. return( ' ' - *b );
  27. else ++b;
  28. }
  29. else
  30. {
  31. while(b < bend)
  32. if(*a == *b)
  33. { ++a; ++b; }
  34. else
  35. return( *a - *b );
  36. while(a < aend)
  37. if(*a != ' ')
  38. return(*a - ' ');
  39. else ++a;
  40. }
  41. return(0);
  42. }
  43. #ifdef __cplusplus
  44. }
  45. #endif