Subversion Repositories Kolibri OS

Rev

Rev 7752 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. struct _tag
  3. {
  4.         char name[32];
  5.         char prior[32];
  6.         char params[5000];
  7.         bool opened;
  8.         collection attributes;
  9.         collection values;
  10.         bool is();
  11.         bool reset();
  12.         bool parse_params();
  13.         bool get_next_param();
  14.         dword get_value_of();
  15. } tag;
  16.  
  17. bool _tag::is(dword _text)
  18. {
  19.         if ( !strcmp(#tag.name, _text) ) {
  20.                 return true;
  21.         } else {
  22.                 return false;
  23.         }
  24. }
  25.  
  26. bool _tag::reset()
  27. {
  28.         if (!name) return false;
  29.         strcpy(#prior, #name);
  30.         name = NULL;
  31.         opened = true;
  32.         attributes.drop();
  33.         values.drop();
  34.         return true;
  35. }
  36.  
  37. bool _tag::parse_params()
  38. {
  39.         bool result = false;
  40.         if (!name) return false;
  41.         if (debug_mode) {
  42.                 debugln(" ");
  43.                 debugln(" ");
  44.                 debug("tag: "); debugln(#name);
  45.                 debug("params: "); debugln(#params);
  46.                 debugln(" ");
  47.         }
  48.         while (get_next_param()) {
  49.                 result = true;
  50.                 if (debug_mode) {
  51.                         debug("attribute: "); debugln(attributes.get(attributes.count-1));
  52.                         debug("value: "); debugln(values.get(values.count-1));
  53.                         debugln(" ");
  54.                 }
  55.         };
  56.         return result;
  57. }
  58.  
  59. bool _tag::get_next_param()
  60. {
  61.         byte  quotes = NULL;
  62.         int   i;
  63.         unsigned char  val[4000];
  64.         unsigned char attr[4000];
  65.  
  66.         if (!params) return false;
  67.        
  68.         i = strlen(#params) - 1;
  69.         if (params[i] == '/') i--;
  70.         while (i>0) && (__isWhite(params[i])) i--;
  71.  
  72.         if (params[i] == '"') || (params[i] == '\'')
  73.         {
  74.                 //remove quotes
  75.                 quotes = params[i];
  76.                 params[i] = EOS;
  77.                 i--;
  78.  
  79.                 //find VAL start and copy
  80.                 i = strrchr(#params, quotes);
  81.                 strlcpy(#val, #params + i, sizeof(val)-1);
  82.                 params[i] = EOS;
  83.                 i--;
  84.  
  85.                 //find ATTR end
  86.                 while (i > 0) && (params[i] != '=') i--;
  87.                 params[i+1] = EOS;
  88.         }
  89.         else
  90.         {
  91.                 //find VAL start and copy
  92.                 while (i > 0) && (params[i] != '=') i--;
  93.                 i++;
  94.                 strlcpy(#val, #params + i, sizeof(val)-1);
  95.  
  96.                 //already have ATTR end
  97.         }
  98.  
  99.         //find ATTR start and copy
  100.         while (i>0) && (!__isWhite(params[i])) i--;
  101.         strlcpy(#attr, #params + i + 1, sizeof(attr)-1);
  102.         strlwr(#attr);
  103.         params[i] = '\0';
  104.  
  105.         //fix case: src=./images/KolibriOS_logo2.jpg?sid=e8ece8b38b
  106.         i = strchr(#attr,'=');
  107.         if (!quotes) && (i) {
  108.                 strlcpy(#val, i+1, sizeof(val)-1);
  109.                 ESBYTE[i+1] = '\0';
  110.         }
  111.  
  112.         attributes.add(#attr);
  113.         values.add(#val);
  114.  
  115.         return true;
  116. }
  117.  
  118. dword _tag::get_value_of(dword _attr_name)
  119. {
  120.         int pos = attributes.get_pos_by_name(_attr_name);
  121.         if (pos == -1) {
  122.                 return 0;
  123.         } else {
  124.                 return values.get(pos);
  125.         }
  126. }
  127.