The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/port/latin1.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #include <u.h>
    2 
    3 /*
    4  * The code makes two assumptions: strlen(ld) is 1 or 2; latintab[i].ld can be a
    5  * prefix of latintab[j].ld only when j<i.
    6  */
    7 struct cvlist
    8 {
    9         char    *ld;            /* must be seen before using this conversion */
   10         char    *si;            /* options for last input characters */
   11         Rune    *so;            /* the corresponding Rune for each si entry */
   12 } latintab[] = {
   13 #include "../port/latin1.h"
   14         0,      0,              0
   15 };
   16 
   17 /*
   18  * Given 5 characters k[0]..k[4], find the rune or return -1 for failure.
   19  */
   20 long
   21 unicode(Rune *k)
   22 {
   23         long i, c;
   24 
   25         k++;    /* skip 'X' */
   26         c = 0;
   27         for(i=0; i<4; i++,k++){
   28                 c <<= 4;
   29                 if(''<=*k && *k<='9')
   30                         c += *k-'';
   31                 else if('a'<=*k && *k<='f')
   32                         c += 10 + *k-'a';
   33                 else if('A'<=*k && *k<='F')
   34                         c += 10 + *k-'A';
   35                 else
   36                         return -1;
   37         }
   38         return c;
   39 }
   40 
   41 /*
   42  * Given n characters k[0]..k[n-1], find the corresponding rune or return -1 for
   43  * failure, or something < -1 if n is too small.  In the latter case, the result
   44  * is minus the required n.
   45  */
   46 long
   47 latin1(Rune *k, int n)
   48 {
   49         struct cvlist *l;
   50         int c;
   51         char* p;
   52 
   53         if(k[0] == 'X')
   54                 if(n>=5)
   55                         return unicode(k);
   56                 else
   57                         return -5;
   58         for(l=latintab; l->ld!=0; l++)
   59                 if(k[0] == l->ld[0]){
   60                         if(n == 1)
   61                                 return -2;
   62                         if(l->ld[1] == 0)
   63                                 c = k[1];
   64                         else if(l->ld[1] != k[1])
   65                                 continue;
   66                         else if(n == 2)
   67                                 return -3;
   68                         else
   69                                 c = k[2];
   70                         for(p=l->si; *p!=0; p++)
   71                                 if(*p == c)
   72                                         return l->so[p - l->si];
   73                         return -1;
   74                 }
   75         return -1;
   76 }

Cache object: d235bed60add49e6822fa930cff2a7db


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.