score.c 588 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "stdinc.h"
  2. #include "dat.h"
  3. #include "fns.h"
  4. u8int zeroScore[VtScoreSize];
  5. void
  6. scoreMem(u8int *score, u8int *buf, int n)
  7. {
  8. vtSha1(score, buf, n);
  9. }
  10. static int
  11. hexv(int c)
  12. {
  13. if(c >= '0' && c <= '9')
  14. return c - '0';
  15. if(c >= 'a' && c <= 'f')
  16. return c - 'a' + 10;
  17. if(c >= 'A' && c <= 'F')
  18. return c - 'A' + 10;
  19. return -1;
  20. }
  21. int
  22. strScore(char *s, u8int *score)
  23. {
  24. int i, c, d;
  25. for(i = 0; i < VtScoreSize; i++){
  26. c = hexv(s[2 * i]);
  27. if(c < 0)
  28. return 0;
  29. d = hexv(s[2 * i + 1]);
  30. if(d < 0)
  31. return 0;
  32. score[i] = (c << 4) + d;
  33. }
  34. return s[2 * i] == '\0';
  35. }