Subversion Repositories Kolibri OS

Rev

Rev 7970 | 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=0;
  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.                 debug("\n\ntag: "); debugln(#name);
  43.                 debug("params: "); debugln(#params);
  44.                 debugln(" ");
  45.         }
  46.         while (get_next_param()) {
  47.                 result = true;
  48.                 if (debug_mode) {
  49.                         debug("attribute: "); debugln(attributes.get(attributes.count-1));
  50.                         debug("value: "); debugln(values.get(values.count-1));
  51.                         debugln(" ");
  52.                 }
  53.         };
  54.         return result;
  55. }
  56.  
  57. bool _tag::get_next_param()
  58. {
  59.         byte  quotes = NULL;
  60.         int   i;
  61.         unsigned char  val[4000];
  62.         unsigned char attr[4000];
  63.  
  64.         if (!params) return false;
  65.        
  66.         i = strlen(#params) - 1;
  67.         if (params[i] == '/') i--;
  68.         while (i>0) && (__isWhite(params[i])) i--;
  69.  
  70.         if (params[i] == '"') || (params[i] == '\'')
  71.         {
  72.                 //remove quotes
  73.                 quotes = params[i];
  74.                 params[i] = '\0';
  75.                 i--;
  76.  
  77.                 //find VAL start and copy
  78.                 i = strrchr(#params, quotes);
  79.                 strlcpy(#val, #params + i, sizeof(val)-1);
  80.                 params[i] = '\0';
  81.                 i--;
  82.  
  83.                 //find ATTR end
  84.                 while (i > 0) && (params[i] != '=') i--;
  85.                 params[i+1] = '\0';
  86.         }
  87.         else
  88.         {
  89.                 //find VAL start and copy
  90.                 while (i > 0) && (params[i] != '=') i--;
  91.                 i++;
  92.                 strlcpy(#val, #params + i, sizeof(val)-1);
  93.  
  94.                 //already have ATTR end
  95.         }
  96.  
  97.         //find ATTR start and copy
  98.         while (i>0) && (!__isWhite(params[i])) i--;
  99.         strlcpy(#attr, #params + i + 1, sizeof(attr)-1);
  100.         params[i] = '\0';
  101.  
  102.         //fix case: src=./images/KolibriOS_logo2.jpg?sid=e8ece8b38b
  103.         i = strchr(#attr,'=');
  104.         if (!quotes) && (i) {
  105.                 strlcpy(#val, i+1, sizeof(val)-1);
  106.                 ESBYTE[i+1] = '\0';
  107.         }
  108.         strlwr(#attr);
  109.  
  110.         attributes.add(#attr);
  111.         values.add(#val);
  112.  
  113.         return true;
  114. }
  115.  
  116. dword _tag::get_value_of(dword _attr_name)
  117. {
  118.         int pos = attributes.get_pos_by_name(_attr_name);
  119.         if (pos == -1) {
  120.                 return 0;
  121.         } else {
  122.                 return values.get(pos);
  123.         }
  124. }
  125.