URI: 
       tscore.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tscore.c (740B)
       ---
            1 #include "stdinc.h"
            2 #include "dat.h"
            3 #include "fns.h"
            4 
            5 u8int zeroscore[VtScoreSize];
            6 
            7 /* Call this function to force linking of score.o for zeroscore on OS X */
            8 void needzeroscore(void) { }
            9 
           10 void
           11 scoremem(u8int *score, u8int *buf, int n)
           12 {
           13         DigestState s;
           14 
           15         memset(&s, 0, sizeof s);
           16         sha1(buf, n, score, &s);
           17 }
           18 
           19 static int
           20 hexv(int c)
           21 {
           22         if(c >= '0' && c <= '9')
           23                 return c - '0';
           24         if(c >= 'a' && c <= 'f')
           25                 return c - 'a' + 10;
           26         if(c >= 'A' && c <= 'F')
           27                 return c - 'A' + 10;
           28         return -1;
           29 }
           30 
           31 int
           32 strscore(char *s, u8int *score)
           33 {
           34         int i, c, d;
           35 
           36         for(i = 0; i < VtScoreSize; i++){
           37                 c = hexv(s[2 * i]);
           38                 if(c < 0)
           39                         return -1;
           40                 d = hexv(s[2 * i + 1]);
           41                 if(d < 0)
           42                         return -1;
           43                 score[i] = (c << 4) + d;
           44         }
           45         return s[2 * i] == '\0';
           46 }