parsescore.c 931 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include <u.h>
  10. #include <libc.h>
  11. #include <oventi.h>
  12. int
  13. vtParseScore(char *buf, uint n, uint8_t score[VtScoreSize])
  14. {
  15. int i, c;
  16. memset(score, 0, VtScoreSize);
  17. if(n != VtScoreSize*2)
  18. return 0;
  19. for(i=0; i<VtScoreSize*2; i++){
  20. if(buf[i] >= '0' && buf[i] <= '9')
  21. c = buf[i] - '0';
  22. else if(buf[i] >= 'a' && buf[i] <= 'f')
  23. c = buf[i] - 'a' + 10;
  24. else if(buf[i] >= 'A' && buf[i] <= 'F')
  25. c = buf[i] - 'A' + 10;
  26. else
  27. return 0;
  28. if((i & 1) == 0)
  29. c <<= 4;
  30. score[i>>1] |= c;
  31. }
  32. return 1;
  33. }