Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.11 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define ABS(a) (((a) < 0) ? -(a) : (a))
  6.  
  7.  
  8. char *unescape_html_UTF8(const char *data)
  9. {
  10.     size_t i = 0;
  11.     size_t len = (data) ? strlen(data) : 0;
  12.     char *result = malloc(len + 1);
  13.  
  14.     int tagflag = 0;
  15.     int iB = 0;
  16.    
  17.     memset(result,0,len);
  18.    
  19.     for(; i  < len; ++i)
  20.     {
  21.         char *semicol = NULL;
  22.         if(data[i] == '&' && data[i+1] == '#' && (semicol = strstr(data+i,";")) != NULL)
  23.         {
  24.             int n = atoi(&data[i+2]);
  25.  
  26.             if(n >= 0x800)
  27.             {
  28.                 result[iB++] = (char)(0xe0 | ((n >> 12) & 0x0f));
  29.                 result[iB++] = (char)(0x80 | ((n >> 6 ) & 0x3f));
  30.                 result[iB++] = (char)(0x80 | ((n      ) & 0x3f));
  31.             }
  32.             else if(n >= 0x80)
  33.             {
  34.                 result[iB++] = (char)(0xc0 | ((n >> 6) & 0x1f));
  35.                 result[iB++] = (char)(0x80 | ((n     ) & 0x3f));
  36.             }
  37.             else
  38.             {
  39.                 result[iB++] = (char)n;
  40.             }
  41.             i =  (int)ABS(semicol-data);
  42.         }
  43.         else
  44.         {
  45.             /* "Replace" a <br> tag with a newline char (... not really supposed to be here... ut well..) */
  46.             if(data[i] == '<')  {
  47.                 tagflag = 1;
  48.                 continue;
  49.             }
  50.                   if(tagflag ==  0 ) result[iB++] = data[i];
  51.             else if(data[i] == '>') result[iB++] = '\n';
  52.            
  53.             if(data[i] == '>') tagflag = 0;
  54.         }
  55.     }
  56.     result[iB] = 0;
  57.     return result;
  58. }
  59.    
  60.  
  61. int main(void)
  62. {
  63.     char *lyrics = unescape_html_UTF8("&#73;&#110;&#32;&#101;&#105;&#110;&#101;&#114;&#32;&#72;&#246;&#104;&#108;&#101;&#32;&#116;&#105;&#101;&#102;&#32;&#117;&#110;&#116;&#101;&#114;&#32;&#100;&#101;&#109;&#32;&#66;&#101;&#114;&#103;<br />&#65;&#109;&#32;&#102;&#108;&#97;&#99;&#107;&#101;&#114;&#110;&#100;&#101;&#110;&#32;&#70;&#101;&#117;&#101;&#114;&#44;&#32;&#100;&#101;&#109;&#32;&#84;&#97;&#103;&#101;&#115;&#108;&#105;&#99;&#104;&#116;&#32;&#115;&#111;&#32;&#102;&#101;&#114;&#110;<br />&#76;&#101;&#98;&#116;&#32;&#100;&#97;&#32;&#101;&#105;&#110;&#32;&#77;&#228;&#110;&#110;&#99;&#104;&#101;&#110;&#44;&#32;&#115;&#111;&#32;&#104;&#117;&#116;&#122;&#101;&#108;&#105;&#103;&#32;&#117;&#110;&#100;&#32;&#97;&#108;&#116;<br />&#109;&#105;&#116;&#32;&#115;&#101;&#105;&#110;&#101;&#114;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#44;&#32;&#100;&#105;&#101;&#32;&#98;&#117;&#99;&#107;&#108;&#105;&#103;&#101;&#32;&#71;&#101;&#115;&#116;&#97;&#108;&#116;<br /><br />&#87;&#101;&#110;&#110;&#32;&#100;&#97;&#110;&#110;&#32;&#100;&#97;&#115;&#32;&#77;&#111;&#110;&#100;&#108;&#105;&#99;&#104;&#116;&#32;&#100;&#101;&#110;&#32;&#66;&#101;&#114;&#103;&#103;&#105;&#112;&#102;&#101;&#108;&#32;&#101;&#114;&#107;&#108;&#105;&#109;&#109;&#116;<br />&#68;&#97;&#110;&#110;&#32;&#112;&#97;&#99;&#107;&#116;&#32;&#101;&#114;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#44;&#32;&#103;&#97;&#110;&#122;&#32;&#108;&#105;&#101;&#98;&#101;&#118;&#111;&#108;&#108;&#32;&#103;&#101;&#115;&#116;&#105;&#109;&#109;&#116;<br />&#90;&#105;&#101;&#104;&#116;&#32;&#105;&#110;&#32;&#100;&#105;&#101;&#32;&#87;&#228;&#108;&#100;&#101;&#114;&#32;&#105;&#109;&#32;&#110;&#228;&#99;&#104;&#116;&#108;&#105;&#99;&#104;&#101;&#110;&#32;&#83;&#99;&#104;&#101;&#105;&#110;<br />&#85;&#110;&#100;&#32;&#115;&#112;&#105;&#101;&#108;&#116;&#32;&#100;&#111;&#114;&#116;&#32;&#100;&#101;&#110;&#32;&#84;&#105;&#101;&#114;&#101;&#110;&#32;&#101;&#105;&#110;&#32;&#107;&#108;&#101;&#105;&#110;&#101;&#115;&#32;&#76;&#105;&#101;&#100;&#101;&#108;&#101;&#105;&#110;<br /><br />&#65;&#110;&#100;&#228;&#99;&#104;&#116;&#105;&#103;&#32;&#108;&#97;&#117;&#115;&#99;&#104;&#101;&#110;&#32;&#100;&#105;&#101;&#32;&#86;&#246;&#103;&#101;&#108;&#32;&#100;&#101;&#109;&#32;&#71;&#101;&#115;&#112;&#105;&#101;&#108;<br />&#68;&#97;&#32;&#115;&#116;&#101;&#105;&#103;&#116;&#32;&#105;&#110;&#32;&#105;&#104;&#114;&#101;&#32;&#75;&#246;&#112;&#102;&#101;&#32;&#101;&#105;&#110;&#32;&#115;&#101;&#108;&#116;&#115;&#97;&#109;&#101;&#115;&#32;&#71;&#101;&#102;&#252;&#104;&#108;<br />&#83;&#105;&#101;&#32;&#119;&#117;&#110;&#100;&#101;&#114;&#110;&#32;&#115;&#105;&#99;&#104;&#32;&#110;&#111;&#99;&#104;&#32;&#107;&#117;&#114;&#122;&#32;&#119;&#97;&#115;&#32;&#105;&#104;&#110;&#39;&#110;&#32;&#119;&#105;&#101;&#100;&#101;&#114;&#102;&#97;&#104;&#114;&#101;&#110;&#32;&#105;&#115;&#116;<br />&#117;&#110;&#100;&#32;&#102;&#97;&#108;&#108;&#101;&#110;&#32;&#112;&#108;&#246;&#116;&#122;&#108;&#105;&#99;&#104;&#32;&#97;&#108;&#108;&#101;&#32;&#109;&#97;&#117;&#115;&#101;&#116;&#111;&#116;&#32;&#97;&#117;&#115;&#32;&#100;&#101;&#109;&#32;&#71;&#101;&#228;&#115;&#116;<br /><br />&#68;&#105;&#101;&#32;&#66;&#228;&#114;&#101;&#110;&#44;&#32;&#115;&#105;&#101;&#32;&#115;&#105;&#116;&#122;&#101;&#110;&#32;&#115;&#111;&#32;&#102;&#114;&#105;&#101;&#100;&#108;&#105;&#99;&#104;&#32;&#105;&#109;&#32;&#76;&#97;&#117;&#98;<br />&#100;&#97;&#32;&#107;&#111;&#109;&#109;&#116;&#32;&#115;&#99;&#104;&#111;&#110;&#32;&#100;&#97;&#115;&#32;&#77;&#228;&#110;&#110;&#99;&#104;&#101;&#110;&#32;&#117;&#110;&#100;&#32;&#115;&#112;&#105;&#101;&#108;&#116;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#32;&#108;&#97;&#117;&#116;<br />&#109;&#105;&#116;&#32;&#104;&#101;&#117;&#108;&#101;&#110;&#100;&#101;&#109;&#32;&#71;&#101;&#98;&#114;&#252;&#108;&#108;&#32;&#114;&#101;&#110;&#110;&#39;&#32;&#115;&#105;&#101;&#32;&#105;&#110;&#32;&#100;&#101;&#110;&#32;&#87;&#97;&#108;&#100;&#32;&#100;&#97;&#118;&#111;&#110;<br />&#100;&#111;&#99;&#104;&#32;&#119;&#105;&#101;&#100;&#101;&#114;&#32;&#101;&#105;&#110;&#109;&#97;&#108;&#32;&#118;&#105;&#101;&#108;&#32;&#122;&#117;&#32;&#115;&#112;&#228;&#116;&#32;&#117;&#110;&#100;&#32;&#107;&#101;&#105;&#110;&#101;&#114;&#32;&#101;&#110;&#116;&#107;&#97;&#109;<br /><br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#115;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;<br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#115;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;<br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#115;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;<br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#115;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;<br /><br />&#68;&#117;&#110;&#107;&#101;&#108;&#32;&#100;&#101;&#114;&#32;&#87;&#101;&#105;&#104;&#101;&#114;&#44;&#32;&#100;&#97;&#115;&#32;&#77;&#228;&#110;&#110;&#99;&#104;&#101;&#110;&#32;&#101;&#114;&#115;&#99;&#104;&#101;&#105;&#110;&#116;&#32;<br />&#87;&#101;&#105;&#116;&#32;&#252;&#98;&#101;&#114;&#32;&#100;&#97;&#115;&#32;&#87;&#97;&#115;&#115;&#101;&#114;&#32;&#100;&#101;&#114;&#32;&#75;&#108;&#97;&#110;&#103;&#32;&#100;&#101;&#114;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#32;&#114;&#101;&#105;&#99;&#104;&#116;<br />&#66;&#105;&#115;&#32;&#97;&#117;&#102;&#32;&#100;&#101;&#110;&#32;&#71;&#114;&#117;&#110;&#100;&#32;&#104;&#105;&#110;&#97;&#98;&#32;&#100;&#105;&#101;&#32;&#77;&#101;&#108;&#111;&#100;&#105;&#101;&#32;&#115;&#111;&#32;&#119;&#101;&#105;&#99;&#104;<br />&#118;&#111;&#108;&#108;&#32;&#118;&#111;&#110;&#32;&#119;&#101;&#105;&#223;&#101;&#110;&#32;&#75;&#97;&#114;&#112;&#102;&#101;&#110;&#98;&#228;&#117;&#99;&#104;&#101;&#110;&#32;&#105;&#115;&#116;&#32;&#100;&#101;&#114;&#32;&#115;&#99;&#104;&#246;&#110;&#101;&#32;&#84;&#101;&#105;&#99;&#104;<br /><br />&#69;&#105;&#110;&#115;&#97;&#109;&#44;&#32;&#103;&#101;&#115;&#99;&#104;&#108;&#97;&#103;&#101;&#110;&#44;&#32;&#100;&#97;&#115;&#32;&#77;&#228;&#110;&#110;&#99;&#104;&#101;&#110;&#32;&#122;&#105;&#101;&#104;&#116;&#32;&#110;&#117;&#110;&#32;&#104;&#101;&#105;&#109;<br />&#119;&#105;&#101;&#32;&#104;&#97;&#115;&#115;&#116;&#32;&#101;&#114;&#32;&#117;&#110;&#100;&#32;&#108;&#105;&#101;&#98;&#116;&#32;&#101;&#114;&#32;&#115;&#101;&#105;&#110;&#32;&#104;&#246;&#108;&#122;&#101;&#114;&#110;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#101;&#105;&#110;&#32;&#46;&#46;&#46;<br /><br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#115;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;<br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#115;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;<br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#115;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;<br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#44;&#32;&#115;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;<br /><br />&#77;&#101;&#105;&#108;&#101;&#110;&#32;&#100;&#101;&#115;&#32;&#87;&#97;&#110;&#100;&#101;&#114;&#110;&#115;&#32;&#100;&#117;&#114;&#99;&#104;&#115;&#32;&#68;&#105;&#99;&#107;&#105;&#99;&#104;&#116;&#32;&#115;&#111;&#32;&#116;&#105;&#101;&#102;<br />&#101;&#105;&#110;&#101;&#32;&#72;&#111;&#114;&#100;&#101;&#32;&#108;&#97;&#110;&#103;&#101;&#114;&#32;&#72;&#97;&#97;&#114;&#101;&#44;&#32;&#117;&#109;&#115;&#32;&#70;&#101;&#117;&#101;&#114;&#32;&#116;&#97;&#110;&#122;&#101;&#110;&#32;&#115;&#105;&#101;<br />&#69;&#114;&#32;&#104;&#101;&#98;&#116;&#32;&#115;&#101;&#105;&#110;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#32;&#104;&#111;&#99;&#104;&#32;&#97;&#110;&#32;&#115;&#101;&#105;&#110;&#32;&#75;&#105;&#110;&#110;&#32;&#122;&#117;&#32;&#115;&#112;&#105;&#101;&#108;&#110;<br />&#68;&#105;&#101;&#32;&#76;&#101;&#117;&#116;&#101;&#32;&#104;&#97;&#108;&#116;&#101;&#110;&#32;&#105;&#110;&#110;&#101;&#44;&#32;&#103;&#101;&#98;&#97;&#110;&#110;&#116;&#32;&#108;&#97;&#117;&#115;&#99;&#104;&#101;&#110;&#32;&#115;&#105;&#101;&#32;&#105;&#104;&#109;<br /><br />&#78;&#97;&#99;&#104;&#32;&#83;&#116;&#117;&#110;&#100;&#101;&#110;&#32;&#100;&#101;&#115;&#32;&#83;&#112;&#105;&#101;&#108;&#101;&#110;&#115;&#32;&#101;&#105;&#110;&#32;&#116;&#111;&#115;&#101;&#110;&#100;&#101;&#114;&#32;&#65;&#112;&#112;&#108;&#97;&#117;&#115;<br />&#68;&#105;&#101;&#32;&#83;&#116;&#105;&#109;&#109;&#117;&#110;&#103;&#32;&#105;&#115;&#116;&#32;&#97;&#109;&#32;&#107;&#111;&#99;&#104;&#101;&#110;&#32;&#117;&#110;&#100;&#32;&#100;&#105;&#101;&#32;&#70;&#114;&#97;&#117;&#101;&#110;&#32;&#122;&#105;&#101;&#104;&#110;&#32;&#115;&#105;&#99;&#104;&#32;&#97;&#117;&#115;&#33;<br />&#68;&#105;&#101;&#32;&#77;&#101;&#110;&#115;&#99;&#104;&#101;&#110;&#32;&#98;&#101;&#106;&#117;&#98;&#101;&#108;&#110;&#32;&#100;&#101;&#110;&#32;&#97;&#108;&#116;&#101;&#110;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#109;&#97;&#110;&#110;&#44;<br />&#100;&#101;&#114;&#32;&#70;&#114;&#97;&#117;&#110;&#32;&#109;&#105;&#116;&#32;&#115;&#101;&#105;&#110;&#101;&#110;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#110;&#32;&#110;&#111;&#99;&#104;&#32;&#118;&#105;&#101;&#108;&#32;&#102;&#114;&#111;&#104;&#101;&#114;&#32;&#109;&#97;&#99;&#104;&#101;&#110;&#32;&#107;&#97;&#110;&#110;&#33;<br /><br />&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#33;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#33;&#32;&#87;&#117;&#114;&#122;&#101;&#108;&#98;&#101;&#114;&#116;&#33;&#32;<br />&#83;&#112;&#105;&#101;&#108;&#32;&#100;&#105;&#101;&#32;&#70;&#105;&#101;&#100;&#101;&#108;&#33;");
  64.     if(lyrics) {
  65.         puts(lyrics);
  66.         if(lyrics) free(lyrics);
  67.     }
  68.     return EXIT_SUCCESS;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement