Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.68 KB | None | 0 0
  1. #include "common.h"
  2. #include "han.h"
  3.  
  4. char Lowercase(char ch)
  5. /* Lowercase of a char */
  6. {
  7.     if('A' <= ch && ch <= 'Z')
  8.     return (ch + 'a' - 'A');
  9.     return ch;
  10. }
  11.  
  12. int NotNameChar(char ch)
  13. /* Judge if a char is a name char */
  14. {
  15.     if('a' <= ch && ch <= 'z')
  16.     return 0;
  17.     if('A' <= ch && ch <= 'Z')
  18.     return 0;
  19.     if('0' <= ch && ch <= '9')
  20.     return 0;
  21.     if(ch == '_')
  22.     return 0;
  23.     return 1;
  24. }
  25.  
  26. int IsNumber(char ch)
  27. /* Judge if a char is a number */
  28. {
  29.     if('0' <= ch && ch <= '9')
  30.     return 1;
  31.     return 0;
  32. }
  33.  
  34. void OpenHZK(void *n)
  35. /* Changed. Oct 18. Open the HZK file on the program loading progress */
  36. {
  37.     State *s;
  38.     s = (void *)n;
  39.     s -> hzkfile = fopen("HZK16", "rb");
  40.     if(s -> hzkfile == NULL)
  41.     /* Failed to open the HZK file */
  42.     {
  43.     outtextxy(10, 10, "Cannot open hzk file!\n");
  44.     exit(1);
  45.     }
  46. }
  47.  
  48. void CloseHZK(void *n)
  49. /* Changed. Oct 18. Close the HZK file when closing program */
  50. {
  51.     State *s;
  52.     s = (void *)n;
  53.     fclose(s -> hzkfile);
  54. }
  55.  
  56. void disp_hz(void *n,int left,int top,unsigned char byte1,unsigned char byte2,int color)
  57. /* Show a specific Chinese Character */
  58. {
  59.     unsigned char buf[32];
  60.     unsigned char mark;
  61.     long p;
  62.     int i, j, y;
  63.     int quma, weima;
  64.     /* Qu Wei Code */
  65.    
  66.     State *s;
  67.     s = (void *)n;
  68.     if((byte1 >= 0xa1 && byte1 <= 0xfe) && (byte2 >= 0xa1 && byte2 <= 0xfe))
  69.     /* Make sure it is really a Chinese Character */
  70.     {
  71.     quma = byte1 - 0xa0;
  72.     weima = byte2 - 0xa0;
  73.     /* Calculate the Qu Wei Code */
  74.    
  75.     p = (quma - 1) * 94 + weima - 1;
  76.     p *= 32;
  77.     fseek(s -> hzkfile, (long)p, SEEK_SET);
  78.     /* Seeking the character in the HZK file */
  79.    
  80.     fread(buf, sizeof(unsigned char), 32, s -> hzkfile);
  81.     /* Read the Chinese Character Module */
  82.    
  83.     for(i = 0, y = top; i < 31; i += 2, y ++)
  84.         for(mark = 0x80, j = 0; mark > 0; mark = mark >> 1, j++)
  85.         {
  86.         if((buf[i] & mark) != 0)
  87.             putpixel(left + j, y, color);
  88.         if((buf[i + 1] & mark) != 0)
  89.             putpixel(left + j + 8, y, color);
  90.         /* Put every pixel in the module */
  91.         }
  92.     }
  93. }
  94.  
  95. void OutTextxy(void *n, int x, int y, char *p, int color)
  96. /* Output a normal string that may include any character including Chinese */
  97. {
  98.     char blue[32][10];
  99.     char q[2];
  100.  
  101.     int oldcolor, i, j, l, k = 0;
  102.     char lp = 0;
  103.     void disp_hz(void *n,
  104.         int left, int top, unsigned char byte1, unsigned char byte2, int color);
  105.     State *s;
  106.     s = (void *)n;
  107.        
  108.     oldcolor=getcolor();
  109.     /* Save the original color */
  110.    
  111.     strcpy(blue[0], "char");
  112.     strcpy(blue[1], "double");
  113.     strcpy(blue[2], "enum");
  114.     strcpy(blue[3], "float");
  115.     strcpy(blue[4], "int");
  116.     strcpy(blue[5], "long");
  117.     strcpy(blue[6], "short");
  118.     strcpy(blue[7], "signed");
  119.     strcpy(blue[8], "struct");
  120.     strcpy(blue[9], "union");
  121.     strcpy(blue[10], "unsigned");
  122.     strcpy(blue[11], "void");
  123.     strcpy(blue[12], "for");
  124.     strcpy(blue[13], "do");
  125.     strcpy(blue[14], "while");
  126.     strcpy(blue[15], "break");
  127.     strcpy(blue[16], "continue");
  128.     strcpy(blue[17], "if");
  129.     strcpy(blue[18], "else");
  130.     strcpy(blue[19], "goto");
  131.     strcpy(blue[20], "switch");
  132.     strcpy(blue[21], "case");
  133.     strcpy(blue[22], "default");
  134.     strcpy(blue[23], "return");
  135.     strcpy(blue[24], "auto");
  136.     strcpy(blue[25], "extern");
  137.     strcpy(blue[26], "register");
  138.     strcpy(blue[27], "static");
  139.     strcpy(blue[28], "const");
  140.     strcpy(blue[29], "sizeof");
  141.     strcpy(blue[30], "typedef");
  142.     strcpy(blue[31], "volatile");
  143.    
  144.     SetColor(color);
  145.     while(*p)
  146.     {
  147.     if(strlen(p) > 1 && (((unsigned char)*p >= 0xa1 && (unsigned char)*p <= 0xfe)
  148.          && ((unsigned char) * (p + 1) >= 0xa1 && (unsigned char) * (p + 1) <= 0xfe)))
  149.     /* It is a Chinese Character */
  150.     {
  151.         if((x + 16) > getmaxx() || (y + 16) > getmaxy())
  152.         /* Out of screen range */
  153.             return;
  154.        
  155.         if(k == 0)
  156.             SetColor(color);
  157.         else
  158.             k -= 2;
  159.        
  160.         disp_hz(n, x, y, *p, *(p+1), getcolor());
  161.         /* Changed. Oct 18. Provide pointer n to get the HZK file pointer */
  162.        
  163.         p += 2;
  164.         x += 16;
  165.         moveto(x, y);
  166.     }
  167.     else
  168.     {
  169.         moveto(x, y);
  170.         *q = *p;
  171.         *(q + 1) = '\0';
  172.        
  173.         setusercharsize(1, 1, 3, 2);
  174.         settextstyle(TRIPLEX_FONT, HORIZ_DIR, 0);
  175.         /* FIXME: Scaling no use at all */
  176.        
  177.         if(s -> isedit && !s -> ischildwindow && !s -> ispinyin && s -> highlight)
  178.         {
  179.             i = 0;
  180.             if(*p == '\"' && !k)
  181.             {
  182.             SetColor(2);
  183.             k ++;
  184.             while(*(p + k) != '\"' && k < 100)
  185.                 k ++;
  186.             k ++;
  187.             }
  188.            
  189.             if(*p == '\'' && !k)
  190.             {
  191.             SetColor(2);
  192.             k ++;
  193.             while(*(p + k) != '\'' && k < 100)
  194.                 k ++;
  195.             k ++;
  196.             }
  197.            
  198.             if(*p == '/' && *(p + 1) == '/' && !k)
  199.             {
  200.             SetColor(7);
  201.             k = 99;
  202.             }
  203.            
  204.             if(*p == '/' && *(p + 1) == '*' && !k)
  205.             {
  206.             SetColor(7);
  207.             while((*(p + k) != '*' || *(p + k + 1) != '/') && k < 100)
  208.                 k ++;
  209.             k += 2;
  210.             }
  211.            
  212.             if(*p == '#' && !k)
  213.             {
  214.             SetColor(3);
  215.             k ++;
  216.             while(*(p + k) != ' ' && k < 100)
  217.                 k ++;
  218.             k ++;
  219.             }
  220.            
  221.             if(IsNumber(*p) && !k && NotNameChar(lp))
  222.             {
  223.             SetColor(6);
  224.             k ++;
  225.             while(IsNumber(*(p + k)) && k < 100)
  226.                 k ++;
  227.             if(!NotNameChar(*(p + k)))
  228.             k = 0;
  229.             }
  230.            
  231.             for(i = 0; NotNameChar(lp) && !k && i < 32; i ++)
  232.             {
  233.             l = strlen(blue[i]);
  234.             for(j = 0; j < l; j ++)
  235.                 if(*(p + j) != blue[i][j])
  236.                 break;
  237.             if(j == l && NotNameChar(*(p + l)))
  238.             {
  239.                 SetColor(9);
  240.                 k = l;
  241.                 break;
  242.             }
  243.             }
  244.         }
  245.        
  246.         if(k == 0)
  247.             SetColor(color);
  248.         else
  249.             k --;
  250.        
  251.         outtextxy(x, y+4, q);
  252.         x += 8;
  253.         lp = *p;
  254.         p ++;
  255.         /* Go to next character */
  256.     }
  257.     }
  258.     SetColor(oldcolor);
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement