Subversion Repositories Kolibri OS

Rev

Rev 8443 | Rev 8445 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. struct _tag
  3. {
  4.         char name[32];
  5.         char prior[32];
  6.         bool opened;
  7.         collection attributes;
  8.         collection values;
  9.         dword value;
  10.         bool is();
  11.         bool parse();
  12.         void debug_tag();
  13.         dword get_next_param();
  14.         dword get_value_of();
  15. } tag=0;
  16.  
  17. bool _tag::is(dword _text)
  18. {
  19.         if ( !strcmp(#name, _text) ) {
  20.                 return true;
  21.         } else {
  22.                 return false;
  23.         }
  24. }
  25.  
  26. bool _tag::parse(dword _bufpos, bufend)
  27. {
  28.         bool retok = true;
  29.         dword bufpos = ESDWORD[_bufpos];
  30.         dword params, paramsend;
  31.  
  32.         dword closepos;
  33.         dword whitepos;
  34.  
  35.         if (name) strcpy(#prior, #name); else prior = '\0';
  36.         name = '\0';
  37.         attributes.drop();
  38.         values.drop();         
  39.  
  40.         if (!strncmp(bufpos,"!--",3))
  41.         {
  42.                 bufpos+=3;
  43.                 //STRSTR
  44.                 while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufend)
  45.                 {
  46.                         bufpos++;
  47.                 }
  48.                 bufpos+=2;
  49.                 retok = false;
  50.                 goto _RET;
  51.         }
  52.  
  53.         if (ESBYTE[bufpos] == '/') {
  54.                 opened = false;
  55.                 bufpos++;
  56.         } else {
  57.                 opened = true;
  58.         }
  59.  
  60.         closepos = strchr(bufpos, '>');
  61.         whitepos = strchrw(bufpos, bufend-bufpos);
  62.  
  63.         if (debug_mode) {
  64.                 if (!closepos) debugln("null closepos");
  65.                 if (!whitepos) debugln("null whitepos");
  66.         }
  67.  
  68.         if (!whitepos) || (whitepos > closepos) {
  69.                 //no param
  70.                 strncpy(#name, bufpos, math.min(closepos - bufpos, sizeof(tag.name)));
  71.                 debug_tag();
  72.                 bufpos = closepos;
  73.         } else {
  74.                 //we have param
  75.                 strncpy(#name, bufpos, math.min(whitepos - bufpos, sizeof(tag.name)));
  76.                 debug_tag();
  77.                 bufpos = closepos;
  78.  
  79.                 params = malloc(closepos - whitepos + 1);
  80.                 strncpy(params, whitepos, closepos - whitepos);
  81.                 if (debug_mode) { debug("params: "); debugln(params+1); }
  82.                 paramsend = params + closepos - whitepos;
  83.                 while (paramsend = get_next_param(params, paramsend-1));
  84.                 free(params);
  85.         }
  86.  
  87.         if (name) {
  88.                 strlwr(#name);
  89.                 // ignore text inside the next tags
  90.                 if (is("script")) || (is("style")) || (is("binary")) || (is("select")) {
  91.                         strcpy(#prior, #name);
  92.                         sprintf(#name, "</%s>", #prior);
  93.                         if (strstri(bufpos, #name)) bufpos = EAX-1;
  94.                         retok = false;
  95.                 } else {
  96.                         if (name[strlen(#name)-1]=='/') name[strlen(#name)-1]=NULL; //for <br/>
  97.                 }
  98.         } else {
  99.                 retok = false;
  100.         }
  101.  
  102. _RET:
  103.         ESDWORD[_bufpos] = bufpos;
  104.         return retok;
  105. }
  106.  
  107. void _tag::debug_tag()
  108. {
  109.         if (debug_mode) {
  110.                 debugch('<');
  111.                 if (!opened) debugch('/');
  112.                 debug(#name);
  113.                 debugln(">");
  114.         }
  115. }
  116.  
  117. dword _tag::get_next_param(dword ps, pe)
  118. {
  119.         // "ps" - param start
  120.         // "pe" - param end
  121.         // "q"  - quote char
  122.         char q = NULL;
  123.         dword fixeq;
  124.         unsigned char  val[6000];
  125.         dword attr;
  126.        
  127.         if (ESBYTE[pe] == '/') pe--;
  128.         while (pe>ps) && (__isWhite(ESBYTE[pe])) pe--;
  129.  
  130.         if (ESBYTE[pe] == '"') || (ESBYTE[pe] == '\'')
  131.         {
  132.                 //remove quote
  133.                 q = ESBYTE[pe];
  134.                 ESBYTE[pe] = '\0';
  135.                 pe--;
  136.  
  137.                 //find VAL start and copy
  138.                 pe = strrchr(ps, q) + ps;
  139.                 strlcpy(#val, pe, sizeof(val)-1);
  140.                 ESBYTE[pe] = '\0';
  141.                 pe--;
  142.  
  143.                 //find ATTR end
  144.                 while (pe > ps) && (ESBYTE[pe] != '=') pe--;
  145.                 ESBYTE[pe] = '\0';
  146.         }
  147.         else
  148.         {
  149.                 //find VAL start and copy
  150.                 while (pe > ps) && (ESBYTE[pe] != '=') pe--;
  151.                 strlcpy(#val, pe+1, sizeof(val)-1);
  152.                 ESBYTE[pe] = '\0';
  153.                 //already have ATTR end
  154.         }
  155.  
  156.         //find ATTR start and copy
  157.         while (pe>ps) && (!__isWhite(ESBYTE[pe])) pe--;
  158.         attr = pe + 1;
  159.         ESBYTE[pe] = '\0';
  160.  
  161.         //fix case: src=./images/KolibriOS_logo2.jpg?sid=e8ece8b38b
  162.         fixeq = strchr(attr,'=');
  163.         if (!q) && (fixeq) {
  164.                 strlcpy(#val, fixeq+1, sizeof(val)-1);
  165.                 ESBYTE[fixeq+1] = '\0';
  166.         }
  167.         strlwr(attr);
  168.         strrtrim(#val);
  169.  
  170.         attributes.add(attr);
  171.         values.add(#val);
  172.  
  173.         if (debug_mode) {
  174.                 debug("atr: "); debugln(attr);
  175.                 debug("val: "); debugln(#val);
  176.                 debugch('\n');
  177.         }
  178.  
  179.         if (pe==ps) return NULL;
  180.         return pe;
  181. }
  182.  
  183. dword _tag::get_value_of(dword _attr_name)
  184. {
  185.         int pos = attributes.get_pos_by_name(_attr_name);
  186.         if (pos == -1) {
  187.                 value = 0;
  188.         } else {
  189.                 value = values.get(pos);
  190.         }
  191.         return value;
  192. }
  193.