00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "global.h"
00022 #include "htdebug.h"
00023 #include "htstring.h"
00024 #include "httag.h"
00025 #include "tools.h"
00026
00027 #include <stdarg.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030
00031
00032
00033
00034 static dword hexb(char *s)
00035 {
00036 byte b=*(byte*)s;
00037 b-='0';
00038 if (b>9) b-='a'-'0'-10;
00039 byte c=*(byte*)(s+1);
00040 c-='0';
00041 if (c>9) c-='a'-'0'-10;
00042 return (b<<4)+c;
00043 }
00044
00045 static dword hexw(char *s)
00046 {
00047 return (hexb(s)<<8) | hexb(s+2);
00048 }
00049
00050 static dword hexd(char *s)
00051 {
00052 return (hexw(s)<<16) | hexw(s+4);
00053 }
00054
00055
00056 TAGSTRING *tag_make_sel(TAGSTRING *buf, char *string)
00057 {
00058 return tag_make_ref(buf, 0, 0, 0, 0, string);
00059 }
00060
00061 TAGSTRING *tag_make_ref_len(TAGSTRING *buf, dword id128_1, dword id128_2, dword id128_3, dword id128_4, char *string, int strlen)
00062 {
00063 ht_tag_sel *tag=(ht_tag_sel*)buf;
00064 tag->escape = '\e';
00065 tag->magic = HT_TAG_SEL;
00066 UNALIGNED_MOVE(tag->id128_1, id128_1);
00067 UNALIGNED_MOVE(tag->id128_2, id128_2);
00068 UNALIGNED_MOVE(tag->id128_3, id128_3);
00069 UNALIGNED_MOVE(tag->id128_4, id128_4);
00070 UNALIGNED_MOVE(tag->strlen, strlen);
00071
00072 memmove(buf+sizeof (ht_tag_sel), string, strlen);
00073
00074 return buf+sizeof (ht_tag_sel)+strlen;
00075 }
00076
00077 TAGSTRING *tag_make_ref(TAGSTRING *buf, dword id128_1, dword id128_2, dword id128_3, dword id128_4, char *string)
00078 {
00079 return tag_make_ref_len(buf, id128_1, id128_2, id128_3, id128_4, string, strlen(string));
00080 }
00081
00082 TAGSTRING *tag_make_flags(TAGSTRING *buf, dword ofs32, dword id)
00083 {
00084 ht_tag_flags *tag=(ht_tag_flags*)buf;
00085 tag->escape = '\e';
00086 tag->magic = HT_TAG_FLAGS;
00087 UNALIGNED_MOVE(tag->offset, ofs32);
00088 UNALIGNED_MOVE(tag->id, id);
00089 return buf+sizeof (ht_tag_flags);
00090 }
00091
00092 TAGSTRING *tag_make_group(TAGSTRING *buf)
00093 {
00094 ht_tag_group *tag=(ht_tag_group*)buf;
00095 tag->escape='\e';
00096 tag->magic=HT_TAG_GROUP;
00097 return buf+sizeof (ht_tag_group);
00098 }
00099
00100 TAGSTRING *tag_make_color(TAGSTRING *buf, dword color)
00101 {
00102 ht_tag_color *tag=(ht_tag_color*)buf;
00103 tag->escape='\e';
00104 tag->magic=HT_TAG_COLOR;
00105 UNALIGNED_MOVE(tag->color, color);
00106 return buf+sizeof (ht_tag_color);
00107 }
00108
00109 TAGSTRING *tag_make_default_color(TAGSTRING *buf)
00110 {
00111 ht_tag_color *tag = (ht_tag_color*)buf;
00112 tag->escape = '\e';
00113 tag->magic = HT_TAG_COLOR;
00114 UNALIGNED_MOVE_CONST(tag->color, 0xffffffff, dword);
00115 return buf+sizeof (ht_tag_color);
00116 }
00117
00118 TAGSTRING *tag_make_edit_byte(TAGSTRING *buf, FILEOFS ofs32)
00119 {
00120 ht_tag_edit_byte *tag=(ht_tag_edit_byte*)buf;
00121 tag->escape='\e';
00122 tag->magic=HT_TAG_EDIT_BYTE;
00123 UNALIGNED_MOVE(tag->offset, ofs32);
00124 return buf+sizeof (ht_tag_edit_byte);
00125 }
00126
00127 TAGSTRING *tag_make_edit_word(TAGSTRING *buf, FILEOFS ofs32, tag_endian e)
00128 {
00129 ht_tag_edit_word_generic *tag=(ht_tag_edit_word_generic*)buf;
00130 tag->escape='\e';
00131 byte m = 0xff;
00132 switch (e) {
00133 case tag_endian_big:
00134 m = HT_TAG_EDIT_WORD_BE;
00135 break;
00136 case tag_endian_little:
00137 m = HT_TAG_EDIT_WORD_LE;
00138 break;
00139 case tag_endian_var:
00140 m = HT_TAG_EDIT_WORD_VE;
00141 break;
00142 }
00143 tag->magic=m;
00144 UNALIGNED_MOVE(tag->offset, ofs32);
00145 return buf+sizeof (ht_tag_edit_word_generic);
00146 }
00147
00148 TAGSTRING *tag_make_edit_dword(TAGSTRING *buf, FILEOFS ofs32, tag_endian e)
00149 {
00150 ht_tag_edit_dword_generic *tag=(ht_tag_edit_dword_generic*)buf;
00151 tag->escape='\e';
00152 byte m=0xff;
00153 switch (e) {
00154 case tag_endian_big:
00155 m = HT_TAG_EDIT_DWORD_BE;
00156 break;
00157 case tag_endian_little:
00158 m = HT_TAG_EDIT_DWORD_LE;
00159 break;
00160 case tag_endian_var:
00161 m = HT_TAG_EDIT_DWORD_VE;
00162 break;
00163 }
00164 tag->magic=m;
00165 UNALIGNED_MOVE(tag->offset, ofs32);
00166 return buf+sizeof (ht_tag_edit_dword_generic);
00167 }
00168
00169 TAGSTRING *tag_make_edit_qword(TAGSTRING *buf, FILEOFS ofs32, tag_endian e)
00170 {
00171 ht_tag_edit_qword_generic *tag=(ht_tag_edit_qword_generic*)buf;
00172 tag->escape='\e';
00173 byte m=0xff;
00174 switch (e) {
00175 case tag_endian_big:
00176 m = HT_TAG_EDIT_QWORD_BE;
00177 break;
00178 case tag_endian_little:
00179 m = HT_TAG_EDIT_QWORD_LE;
00180 break;
00181 case tag_endian_var:
00182 m = HT_TAG_EDIT_QWORD_VE;
00183 break;
00184 }
00185 tag->magic=m;
00186 UNALIGNED_MOVE(tag->offset, ofs32);
00187 return buf+sizeof (ht_tag_edit_qword_generic);
00188 }
00189
00190 TAGSTRING *tag_make_edit_time(TAGSTRING *buf, FILEOFS ofs32)
00191 {
00192 ht_tag_edit_time *tag=(ht_tag_edit_time*)buf;
00193 tag->escape='\e';
00194 tag->magic=HT_TAG_EDIT_TIME;
00195 UNALIGNED_MOVE(tag->offset, ofs32);
00196 return buf+sizeof (ht_tag_edit_time);
00197 }
00198
00199 TAGSTRING *tag_make_edit_char(TAGSTRING *buf, FILEOFS ofs32)
00200 {
00201 ht_tag_edit_char *tag=(ht_tag_edit_char*)buf;
00202 tag->escape='\e';
00203 tag->magic=HT_TAG_EDIT_CHAR;
00204 UNALIGNED_MOVE(tag->offset, ofs32);
00205 return buf+sizeof (ht_tag_edit_char);
00206 }
00207
00208 TAGSTRING *tag_make_edit_bit(TAGSTRING *buf, FILEOFS ofs32, int bitidx)
00209 {
00210 ht_tag_edit_bit *tag=(ht_tag_edit_bit*)buf;
00211 tag->escape='\e';
00212 tag->magic=HT_TAG_EDIT_BIT;
00213 UNALIGNED_MOVE(tag->offset, ofs32);
00214 UNALIGNED_MOVE(tag->bitidx, bitidx);
00215 return buf+sizeof (ht_tag_edit_bit);
00216 }
00217
00218 TAGSTRING *tag_make_edit_selvis(TAGSTRING *buf, FILEOFS offset, char ch)
00219 {
00220 ht_tag_edit_selvis *tag=(ht_tag_edit_selvis*)buf;
00221 tag->escape='\e';
00222 tag->magic=HT_TAG_EDIT_SELVIS;
00223 UNALIGNED_MOVE(tag->offset, offset);
00224 tag->ch=ch;
00225 return buf+sizeof (ht_tag_edit_selvis);
00226 }
00227
00228 TAGSTRING *tag_make_desc_byte(TAGSTRING *buf, FILEOFS ofs32, dword id32)
00229 {
00230 ht_tag_desc_byte *tag=(ht_tag_desc_byte*)buf;
00231 tag->escape='\e';
00232 tag->magic=HT_TAG_DESC_BYTE;
00233 UNALIGNED_MOVE(tag->offset, ofs32);
00234 UNALIGNED_MOVE(tag->id, id32);
00235 return buf+sizeof (ht_tag_desc_byte);
00236 }
00237
00238 TAGSTRING *tag_make_desc_word(TAGSTRING *buf, FILEOFS ofs32, dword id32, tag_endian e)
00239 {
00240 ht_tag_desc_word_generic *tag=(ht_tag_desc_word_generic*)buf;
00241 tag->escape='\e';
00242 byte m=0xff;
00243 switch (e) {
00244 case tag_endian_big:
00245 m = HT_TAG_DESC_WORD_BE;
00246 break;
00247 case tag_endian_little:
00248 m = HT_TAG_DESC_WORD_LE;
00249 break;
00250 case tag_endian_var:
00251 m = HT_TAG_DESC_WORD_VE;
00252 break;
00253 }
00254 tag->magic=m;
00255 UNALIGNED_MOVE(tag->offset, ofs32);
00256 UNALIGNED_MOVE(tag->id, id32);
00257 return buf+sizeof (ht_tag_desc_word_generic);
00258 }
00259
00260 TAGSTRING *tag_make_desc_dword(TAGSTRING *buf, FILEOFS ofs32, dword id32, tag_endian e)
00261 {
00262 ht_tag_desc_dword_generic *tag=(ht_tag_desc_dword_generic*)buf;
00263 tag->escape='\e';
00264 byte m=0xff;
00265 switch (e) {
00266 case tag_endian_big:
00267 m = HT_TAG_DESC_DWORD_BE;
00268 break;
00269 case tag_endian_little:
00270 m = HT_TAG_DESC_DWORD_LE;
00271 break;
00272 case tag_endian_var:
00273 m = HT_TAG_DESC_DWORD_VE;
00274 break;
00275 }
00276 tag->magic=m;
00277 UNALIGNED_MOVE(tag->offset, ofs32);
00278 UNALIGNED_MOVE(tag->id, id32);
00279 return buf+sizeof (ht_tag_desc_dword_generic);
00280 }
00281
00282 TAGSTRING *tag_make_desc_qword(TAGSTRING *buf, FILEOFS ofs32, dword id32, tag_endian e)
00283 {
00284 ht_tag_desc_qword_generic *tag=(ht_tag_desc_qword_generic*)buf;
00285 tag->escape='\e';
00286 byte m=0xff;
00287 switch (e) {
00288 case tag_endian_big:
00289 m = HT_TAG_DESC_QWORD_BE;
00290 break;
00291 case tag_endian_little:
00292 m = HT_TAG_DESC_QWORD_LE;
00293 break;
00294 case tag_endian_var:
00295 m = HT_TAG_DESC_QWORD_VE;
00296 break;
00297 }
00298 tag->magic=m;
00299 UNALIGNED_MOVE(tag->offset, ofs32);
00300 UNALIGNED_MOVE(tag->id, id32);
00301 return buf+sizeof (ht_tag_desc_qword_generic);
00302 }
00303
00304
00305
00306 void statictag_to_tag(char *statictag_str, TAGSTRING *tag_str, dword relocation, bool std_bigendian)
00307 {
00308 FILEOFS ofs=0;
00309 ID id;
00310 while (*statictag_str) {
00311 if (*statictag_str=='\e') {
00312 switch ((byte)*(statictag_str+1)) {
00313 case HT_STATICTAG_EDIT_BYTE:
00314 ofs=hexd(statictag_str+2);
00315 tag_str=tag_make_edit_byte(tag_str, ofs+relocation);
00316 statictag_str+=2+8;
00317 break;
00318 case HT_STATICTAG_EDIT_WORD_LE:
00319 ofs=hexd(statictag_str+2);
00320 tag_str=tag_make_edit_word(tag_str, ofs+relocation, tag_endian_little);
00321 statictag_str+=2+8;
00322 break;
00323 case HT_STATICTAG_EDIT_DWORD_LE:
00324 ofs=hexd(statictag_str+2);
00325 tag_str=tag_make_edit_dword(tag_str, ofs+relocation, tag_endian_little);
00326 statictag_str+=2+8;
00327 break;
00328 case HT_STATICTAG_EDIT_QWORD_LE:
00329 ofs=hexd(statictag_str+2);
00330 tag_str=tag_make_edit_qword(tag_str, ofs+relocation, tag_endian_little);
00331 statictag_str+=2+8;
00332 break;
00333 case HT_STATICTAG_EDIT_WORD_BE:
00334 ofs=hexd(statictag_str+2);
00335 tag_str=tag_make_edit_word(tag_str, ofs+relocation, tag_endian_big);
00336 statictag_str+=2+8;
00337 break;
00338 case HT_STATICTAG_EDIT_DWORD_BE:
00339 ofs=hexd(statictag_str+2);
00340 tag_str=tag_make_edit_dword(tag_str, ofs+relocation, tag_endian_big);
00341 statictag_str+=2+8;
00342 break;
00343 case HT_STATICTAG_EDIT_QWORD_BE:
00344 ofs=hexd(statictag_str+2);
00345 tag_str=tag_make_edit_qword(tag_str, ofs+relocation, tag_endian_big);
00346 statictag_str+=2+8;
00347 break;
00348 case HT_STATICTAG_EDIT_WORD_VE:
00349 ofs=hexd(statictag_str+2);
00350 tag_str=tag_make_edit_word(tag_str, ofs+relocation, std_bigendian ? tag_endian_big : tag_endian_little);
00351 statictag_str+=2+8;
00352 break;
00353 case HT_STATICTAG_EDIT_DWORD_VE:
00354 ofs=hexd(statictag_str+2);
00355 tag_str=tag_make_edit_dword(tag_str, ofs+relocation, std_bigendian ? tag_endian_big : tag_endian_little);
00356 statictag_str+=2+8;
00357 break;
00358 case HT_STATICTAG_EDIT_QWORD_VE:
00359 ofs=hexd(statictag_str+2);
00360 tag_str=tag_make_edit_qword(tag_str, ofs+relocation, std_bigendian ? tag_endian_big : tag_endian_little);
00361 statictag_str+=2+8;
00362 break;
00363 case HT_STATICTAG_EDIT_TIME:
00364 ofs=hexd(statictag_str+2);
00365 tag_str=tag_make_edit_time(tag_str, ofs+relocation);
00366 statictag_str+=2+8;
00367 break;
00368 case HT_STATICTAG_EDIT_CHAR:
00369 ofs=hexd(statictag_str+2);
00370 tag_str=tag_make_edit_char(tag_str, ofs+relocation);
00371 statictag_str+=2+8;
00372 break;
00373 case HT_STATICTAG_EDIT_BIT: {
00374 ofs=hexd(statictag_str+2);
00375 int bitidx=hexb(statictag_str+2+8);
00376 tag_str=tag_make_edit_bit(tag_str, ofs+relocation, bitidx);
00377 statictag_str+=2+8+2;
00378 break;
00379 }
00380 case HT_STATICTAG_EDIT_SELVIS: {
00381 ofs=hexd(statictag_str+2);
00382 char ch=hexb(statictag_str+2+8);
00383 tag_str=tag_make_edit_selvis(tag_str, ofs+relocation, ch);
00384 statictag_str+=2+8+2;
00385 break;
00386 }
00387 case HT_STATICTAG_DESC_BYTE:
00388 ofs=hexd(statictag_str+2);
00389 id=hexd(statictag_str+2+8);
00390 tag_str=tag_make_desc_byte(tag_str, ofs+relocation, id);
00391 statictag_str+=2+8+8;
00392 break;
00393 case HT_STATICTAG_DESC_WORD_LE:
00394 ofs=hexd(statictag_str+2);
00395 id=hexd(statictag_str+2+8);
00396 tag_str=tag_make_desc_word(tag_str, ofs+relocation, id, tag_endian_little);
00397 statictag_str+=2+8+8;
00398 break;
00399 case HT_STATICTAG_DESC_DWORD_LE:
00400 ofs=hexd(statictag_str+2);
00401 id=hexd(statictag_str+2+8);
00402 tag_str=tag_make_desc_dword(tag_str, ofs+relocation, id, tag_endian_little);
00403 statictag_str+=2+8+8;
00404 break;
00405 case HT_STATICTAG_DESC_QWORD_LE:
00406 ofs=hexd(statictag_str+2);
00407 id=hexd(statictag_str+2+8);
00408 tag_str=tag_make_desc_qword(tag_str, ofs+relocation, id, tag_endian_little);
00409 statictag_str+=2+8+8;
00410 break;
00411 case HT_STATICTAG_DESC_WORD_BE:
00412 ofs=hexd(statictag_str+2);
00413 id=hexd(statictag_str+2+8);
00414 tag_str=tag_make_desc_word(tag_str, ofs+relocation, id, tag_endian_big);
00415 statictag_str+=2+8+8;
00416 break;
00417 case HT_STATICTAG_DESC_DWORD_BE:
00418 ofs=hexd(statictag_str+2);
00419 id=hexd(statictag_str+2+8);
00420 tag_str=tag_make_desc_dword(tag_str, ofs+relocation, id, tag_endian_big);
00421 statictag_str+=2+8+8;
00422 break;
00423 case HT_STATICTAG_DESC_QWORD_BE:
00424 ofs=hexd(statictag_str+2);
00425 id=hexd(statictag_str+2+8);
00426 tag_str=tag_make_desc_qword(tag_str, ofs+relocation, id, tag_endian_big);
00427 statictag_str+=2+8+8;
00428 break;
00429 case HT_STATICTAG_DESC_WORD_VE:
00430 ofs=hexd(statictag_str+2);
00431 id=hexd(statictag_str+2+8);
00432 tag_str=tag_make_desc_word(tag_str, ofs+relocation, id, std_bigendian ? tag_endian_big : tag_endian_little);
00433 statictag_str+=2+8+8;
00434 break;
00435 case HT_STATICTAG_DESC_DWORD_VE:
00436 ofs=hexd(statictag_str+2);
00437 id=hexd(statictag_str+2+8);
00438 tag_str=tag_make_desc_dword(tag_str, ofs+relocation, id, std_bigendian ? tag_endian_big : tag_endian_little);
00439 statictag_str+=2+8+8;
00440 break;
00441 case HT_STATICTAG_DESC_QWORD_VE:
00442 ofs=hexd(statictag_str+2);
00443 id=hexd(statictag_str+2+8);
00444 tag_str=tag_make_desc_qword(tag_str, ofs+relocation, id, std_bigendian ? tag_endian_big : tag_endian_little);
00445 statictag_str+=2+8+8;
00446 break;
00447 case HT_STATICTAG_SEL: {
00448 dword id_1=hexd(statictag_str+2);
00449 dword id_2=hexd(statictag_str+2+8);
00450 dword id_3=hexd(statictag_str+2+16);
00451 dword id_4=hexd(statictag_str+2+24);
00452 byte len=hexb(statictag_str+2+8+8+8+8);
00453 tag_str=tag_make_ref_len(tag_str, id_1, id_2, id_3, id_4, statictag_str+2+8+8+8+8+2, len);
00454 statictag_str+=2+8+8+8+8+2+len;
00455 break;
00456 }
00457 case HT_STATICTAG_FLAGS: {
00458 ofs=hexd(statictag_str+2);
00459 id=hexd(statictag_str+2+8);
00460 tag_str=tag_make_flags(tag_str, id, ofs+relocation);
00461 statictag_str+=2+8+8;
00462 break;
00463 }
00464 case HT_STATICTAG_GROUP:
00465 tag_str=tag_make_group(tag_str);
00466 statictag_str+=2;
00467 break;
00468 case HT_STATICTAG_COLOR: {
00469 byte color=hexb(statictag_str+2);
00470 tag_str=tag_make_color(tag_str, color);
00471 statictag_str+=2+2;
00472 break;
00473 }
00474 default:
00475 HT_ERROR("error in statictag string !");
00476 }
00477 } else {
00478 *(tag_str++)=*(statictag_str++);
00479 }
00480 }
00481 *tag_str=0;
00482 }
00483
00484 TAGSTRING *tag_findnext(const TAGSTRING *tagstring)
00485 {
00486 return strchr(tagstring, '\e');
00487 }
00488
00489 int tag_get_len(const TAGSTRING *tagstring)
00490 {
00491 switch (tagstring[1]) {
00492 case HT_TAG_EDIT_BYTE:
00493 return HT_TAG_EDIT_BYTE_LEN;
00494 case HT_TAG_EDIT_WORD_LE:
00495 return HT_TAG_EDIT_WORD_LE_LEN;
00496 case HT_TAG_EDIT_DWORD_LE:
00497 return HT_TAG_EDIT_DWORD_LE_LEN;
00498 case HT_TAG_EDIT_QWORD_LE:
00499 return HT_TAG_EDIT_QWORD_LE_LEN;
00500 case HT_TAG_EDIT_WORD_BE:
00501 return HT_TAG_EDIT_WORD_BE_LEN;
00502 case HT_TAG_EDIT_DWORD_BE:
00503 return HT_TAG_EDIT_DWORD_BE_LEN;
00504 case HT_TAG_EDIT_QWORD_BE:
00505 return HT_TAG_EDIT_QWORD_BE_LEN;
00506 case HT_TAG_EDIT_WORD_VE:
00507 return HT_TAG_EDIT_WORD_VE_LEN;
00508 case HT_TAG_EDIT_DWORD_VE:
00509 return HT_TAG_EDIT_DWORD_VE_LEN;
00510 case HT_TAG_EDIT_QWORD_VE:
00511 return HT_TAG_EDIT_QWORD_VE_LEN;
00512 case HT_TAG_EDIT_TIME:
00513 return HT_TAG_EDIT_TIME_LEN;
00514 case HT_TAG_EDIT_CHAR:
00515 return HT_TAG_EDIT_CHAR_LEN;
00516 case HT_TAG_EDIT_BIT:
00517 return HT_TAG_EDIT_BIT_LEN;
00518 case HT_TAG_EDIT_SELVIS:
00519 return HT_TAG_EDIT_SELVIS_LEN;
00520 case HT_TAG_SEL:
00521 return HT_TAG_SEL_LEN(((ht_tag_sel*)tagstring)->strlen);
00522 case HT_TAG_FLAGS:
00523 return HT_TAG_FLAGS_LEN;
00524 case HT_TAG_COLOR:
00525 return HT_TAG_COLOR_LEN;
00526 case HT_TAG_GROUP:
00527 return HT_TAG_GROUP_LEN;
00528 case HT_TAG_DESC_BYTE:
00529 return HT_TAG_DESC_BYTE_LEN;
00530 case HT_TAG_DESC_WORD_LE:
00531 return HT_TAG_DESC_WORD_LE_LEN;
00532 case HT_TAG_DESC_DWORD_LE:
00533 return HT_TAG_DESC_DWORD_LE_LEN;
00534 case HT_TAG_DESC_QWORD_LE:
00535 return HT_TAG_DESC_QWORD_LE_LEN;
00536 case HT_TAG_DESC_WORD_BE:
00537 return HT_TAG_DESC_WORD_BE_LEN;
00538 case HT_TAG_DESC_DWORD_BE:
00539 return HT_TAG_DESC_DWORD_BE_LEN;
00540 case HT_TAG_DESC_QWORD_BE:
00541 return HT_TAG_DESC_QWORD_BE_LEN;
00542 case HT_TAG_DESC_WORD_VE:
00543 return HT_TAG_DESC_WORD_VE_LEN;
00544 case HT_TAG_DESC_DWORD_VE:
00545 return HT_TAG_DESC_DWORD_VE_LEN;
00546 case HT_TAG_DESC_QWORD_VE:
00547 return HT_TAG_DESC_QWORD_VE_LEN;
00548 }
00549 assert(0);
00550 return -1;
00551 }
00552
00553 int tag_get_vlen(const TAGSTRING *tagstring)
00554 {
00555 switch (tagstring[1]) {
00556 case HT_TAG_EDIT_BYTE:
00557 return HT_TAG_EDIT_BYTE_VLEN;
00558 case HT_TAG_EDIT_WORD_LE:
00559 return HT_TAG_EDIT_WORD_LE_VLEN;
00560 case HT_TAG_EDIT_DWORD_LE:
00561 return HT_TAG_EDIT_DWORD_LE_VLEN;
00562 case HT_TAG_EDIT_QWORD_LE:
00563 return HT_TAG_EDIT_QWORD_LE_VLEN;
00564 case HT_TAG_EDIT_WORD_BE:
00565 return HT_TAG_EDIT_WORD_BE_VLEN;
00566 case HT_TAG_EDIT_DWORD_BE:
00567 return HT_TAG_EDIT_DWORD_BE_VLEN;
00568 case HT_TAG_EDIT_QWORD_BE:
00569 return HT_TAG_EDIT_QWORD_BE_VLEN;
00570 case HT_TAG_EDIT_WORD_VE:
00571 return HT_TAG_EDIT_WORD_VE_VLEN;
00572 case HT_TAG_EDIT_DWORD_VE:
00573 return HT_TAG_EDIT_DWORD_VE_VLEN;
00574 case HT_TAG_EDIT_QWORD_VE:
00575 return HT_TAG_EDIT_QWORD_VE_VLEN;
00576 case HT_TAG_EDIT_TIME:
00577 return HT_TAG_EDIT_TIME_VLEN;
00578 case HT_TAG_EDIT_CHAR:
00579 return HT_TAG_EDIT_CHAR_VLEN;
00580 case HT_TAG_EDIT_BIT:
00581 return HT_TAG_EDIT_BIT_VLEN;
00582 case HT_TAG_EDIT_SELVIS:
00583 return HT_TAG_EDIT_SELVIS_VLEN;
00584 case HT_TAG_SEL: {
00585 return HT_TAG_SEL_VLEN(((ht_tag_sel*)tagstring)->strlen);
00586 }
00587 default:
00588 return 0;
00589 }
00590 }
00591
00592 int time_mp[14]={0,1,3,4,6,7,9,10,12,13,15,16,17,18};
00593
00594 int tag_get_micropos(const TAGSTRING *tagstring, int i)
00595 {
00596 switch (tagstring[1]) {
00597 case HT_TAG_EDIT_BYTE:
00598 case HT_TAG_EDIT_WORD_LE:
00599 case HT_TAG_EDIT_DWORD_LE:
00600 case HT_TAG_EDIT_QWORD_LE:
00601 case HT_TAG_EDIT_WORD_BE:
00602 case HT_TAG_EDIT_DWORD_BE:
00603 case HT_TAG_EDIT_QWORD_BE:
00604 case HT_TAG_EDIT_WORD_VE:
00605 case HT_TAG_EDIT_DWORD_VE:
00606 case HT_TAG_EDIT_QWORD_VE:
00607 case HT_TAG_EDIT_CHAR:
00608 case HT_TAG_EDIT_BIT:
00609 return i;
00610 case HT_TAG_EDIT_TIME:
00611 return time_mp[i];
00612 }
00613
00614 return -1;
00615 }
00616
00617 int tag_get_microsize(const TAGSTRING *tagstring)
00618 {
00619 switch (tagstring[1]) {
00620 case HT_TAG_EDIT_BYTE:
00621 return HT_TAG_EDIT_BYTE_VLEN;
00622 case HT_TAG_EDIT_WORD_LE:
00623 return HT_TAG_EDIT_WORD_LE_VLEN;
00624 case HT_TAG_EDIT_DWORD_LE:
00625 return HT_TAG_EDIT_DWORD_LE_VLEN;
00626 case HT_TAG_EDIT_QWORD_LE:
00627 return HT_TAG_EDIT_QWORD_LE_VLEN;
00628 case HT_TAG_EDIT_WORD_BE:
00629 return HT_TAG_EDIT_WORD_BE_VLEN;
00630 case HT_TAG_EDIT_DWORD_BE:
00631 return HT_TAG_EDIT_DWORD_BE_VLEN;
00632 case HT_TAG_EDIT_QWORD_BE:
00633 return HT_TAG_EDIT_QWORD_BE_VLEN;
00634 case HT_TAG_EDIT_WORD_VE:
00635 return HT_TAG_EDIT_WORD_VE_VLEN;
00636 case HT_TAG_EDIT_DWORD_VE:
00637 return HT_TAG_EDIT_DWORD_VE_VLEN;
00638 case HT_TAG_EDIT_QWORD_VE:
00639 return HT_TAG_EDIT_QWORD_VE_VLEN;
00640 case HT_TAG_EDIT_TIME:
00641 return 14;
00642 case HT_TAG_EDIT_CHAR:
00643 return HT_TAG_EDIT_CHAR_VLEN;
00644 case HT_TAG_EDIT_BIT:
00645 return HT_TAG_EDIT_BIT_VLEN;
00646 default:
00647 return 1;
00648 }
00649 }
00650
00651 int tag_get_size(const TAGSTRING *tagstring)
00652 {
00653 switch (tagstring[1]) {
00654 case HT_TAG_EDIT_BYTE:
00655 return HT_TAG_EDIT_BYTE_SIZE;
00656 case HT_TAG_EDIT_WORD_LE:
00657 return HT_TAG_EDIT_WORD_LE_SIZE;
00658 case HT_TAG_EDIT_DWORD_LE:
00659 return HT_TAG_EDIT_DWORD_LE_SIZE;
00660 case HT_TAG_EDIT_QWORD_LE:
00661 return HT_TAG_EDIT_QWORD_LE_SIZE;
00662 case HT_TAG_EDIT_WORD_BE:
00663 return HT_TAG_EDIT_WORD_BE_SIZE;
00664 case HT_TAG_EDIT_DWORD_BE:
00665 return HT_TAG_EDIT_DWORD_BE_SIZE;
00666 case HT_TAG_EDIT_QWORD_BE:
00667 return HT_TAG_EDIT_QWORD_BE_SIZE;
00668 case HT_TAG_EDIT_WORD_VE:
00669 return HT_TAG_EDIT_WORD_VE_SIZE;
00670 case HT_TAG_EDIT_DWORD_VE:
00671 return HT_TAG_EDIT_DWORD_VE_SIZE;
00672 case HT_TAG_EDIT_QWORD_VE:
00673 return HT_TAG_EDIT_QWORD_VE_SIZE;
00674 case HT_TAG_EDIT_TIME:
00675 return HT_TAG_EDIT_TIME_SIZE;
00676 case HT_TAG_EDIT_CHAR:
00677 return HT_TAG_EDIT_CHAR_SIZE;
00678 case HT_TAG_EDIT_BIT:
00679 return HT_TAG_EDIT_BIT_SIZE;
00680 default:
00681 return 0;
00682 }
00683 }
00684
00685 dword tag_get_offset(const TAGSTRING *tagstring)
00686 {
00687 FILEOFS f;
00688 switch (tagstring[1]) {
00689 case HT_TAG_EDIT_BYTE: {
00690 UNALIGNED_MOVE(f, ((ht_tag_edit_byte*)tagstring)->offset);
00691 return f;
00692 }
00693 case HT_TAG_EDIT_WORD_LE:
00694 case HT_TAG_EDIT_WORD_BE:
00695 case HT_TAG_EDIT_WORD_VE: {
00696 UNALIGNED_MOVE(f, ((ht_tag_edit_word_generic*)tagstring)->offset);
00697 return f;
00698 }
00699 case HT_TAG_EDIT_DWORD_LE:
00700 case HT_TAG_EDIT_DWORD_BE:
00701 case HT_TAG_EDIT_DWORD_VE: {
00702 UNALIGNED_MOVE(f, ((ht_tag_edit_dword_generic*)tagstring)->offset);
00703 return f;
00704 }
00705 case HT_TAG_EDIT_QWORD_LE:
00706 case HT_TAG_EDIT_QWORD_BE:
00707 case HT_TAG_EDIT_QWORD_VE: {
00708 UNALIGNED_MOVE(f, ((ht_tag_edit_qword_generic*)tagstring)->offset);
00709 return f;
00710 }
00711 case HT_TAG_EDIT_TIME: {
00712 UNALIGNED_MOVE(f, ((ht_tag_edit_time*)tagstring)->offset);
00713 return f;
00714 }
00715 case HT_TAG_EDIT_CHAR: {
00716 UNALIGNED_MOVE(f, ((ht_tag_edit_char*)tagstring)->offset);
00717 return f;
00718 }
00719 case HT_TAG_EDIT_BIT: {
00720 UNALIGNED_MOVE(f, ((ht_tag_edit_bit*)tagstring)->offset);
00721 return f;
00722 }
00723 case HT_TAG_EDIT_SELVIS: {
00724 UNALIGNED_MOVE(f, ((ht_tag_edit_selvis*)tagstring)->offset);
00725 return f;
00726 }
00727 case HT_TAG_DESC_BYTE: {
00728 UNALIGNED_MOVE(f, ((ht_tag_desc_byte*)tagstring)->offset);
00729 return f;
00730 }
00731 case HT_TAG_DESC_WORD_LE:
00732 case HT_TAG_DESC_WORD_BE:
00733 case HT_TAG_DESC_WORD_VE: {
00734 UNALIGNED_MOVE(f, ((ht_tag_desc_word_generic*)tagstring)->offset);
00735 return f;
00736 }
00737 case HT_TAG_DESC_DWORD_LE:
00738 case HT_TAG_DESC_DWORD_BE:
00739 case HT_TAG_DESC_DWORD_VE: {
00740 UNALIGNED_MOVE(f, ((ht_tag_desc_dword_generic*)tagstring)->offset);
00741 return f;
00742 }
00743 case HT_TAG_DESC_QWORD_LE:
00744 case HT_TAG_DESC_QWORD_BE:
00745 case HT_TAG_DESC_QWORD_VE: {
00746 UNALIGNED_MOVE(f, ((ht_tag_desc_qword_generic*)tagstring)->offset);
00747 return f;
00748 }
00749 case HT_TAG_FLAGS: {
00750 UNALIGNED_MOVE(f, ((ht_tag_flags*)tagstring)->offset);
00751 return f;
00752 }
00753 }
00754 assert(0);
00755 return 0;
00756 }
00757
00758 void tag_get_id(const TAGSTRING *tagstring, dword *id128_1, dword *id128_2, dword *id128_3, dword *id128_4)
00759 {
00760 if (tagstring[1]==HT_TAG_SEL) {
00761 UNALIGNED_MOVE(*id128_1, ((ht_tag_sel*)tagstring)->id128_1);
00762 UNALIGNED_MOVE(*id128_2, ((ht_tag_sel*)tagstring)->id128_2);
00763 UNALIGNED_MOVE(*id128_3, ((ht_tag_sel*)tagstring)->id128_3);
00764 UNALIGNED_MOVE(*id128_4, ((ht_tag_sel*)tagstring)->id128_4);
00765 }
00766 }
00767
00768 TAGSTRING *tag_get_seltext(const TAGSTRING *tagstring)
00769 {
00770 return (TAGSTRING *)(tagstring+sizeof(ht_tag_sel));
00771 }
00772
00773 int tag_get_seltextlen(const TAGSTRING *tagstring)
00774 {
00775 if (tagstring[1]==HT_TAG_SEL) {
00776 return ((ht_tag_sel*)tagstring)->strlen;
00777 }
00778 return -1;
00779 }
00780
00781 vcp tag_get_color(const TAGSTRING *tagstring)
00782 {
00783 vcp c;
00784 UNALIGNED_MOVE(c, ((ht_tag_color*)tagstring)->color);
00785 return c;
00786 }
00787
00788 bool tag_get_desc_id(const TAGSTRING *tagstring, dword *id)
00789 {
00790 switch (tagstring[1]) {
00791 case HT_TAG_DESC_BYTE:
00792 UNALIGNED_MOVE(*id, ((ht_tag_desc_byte*)tagstring)->id);
00793 return true;
00794 case HT_TAG_DESC_WORD_LE:
00795 case HT_TAG_DESC_WORD_BE:
00796 case HT_TAG_DESC_WORD_VE:
00797 UNALIGNED_MOVE(*id, ((ht_tag_desc_word_generic*)tagstring)->id);
00798 return true;
00799 case HT_TAG_DESC_DWORD_LE:
00800 case HT_TAG_DESC_DWORD_BE:
00801 case HT_TAG_DESC_DWORD_VE:
00802 UNALIGNED_MOVE(*id, ((ht_tag_desc_dword_generic*)tagstring)->id);
00803 return true;
00804 case HT_TAG_DESC_QWORD_LE:
00805 case HT_TAG_DESC_QWORD_BE:
00806 case HT_TAG_DESC_QWORD_VE:
00807 UNALIGNED_MOVE(*id, ((ht_tag_desc_qword_generic*)tagstring)->id);
00808 return true;
00809 }
00810 return false;
00811 }
00812
00813 void tag_set_offset(const TAGSTRING *tagstring, dword offset)
00814 {
00815 switch (tagstring[1]) {
00816 case HT_TAG_EDIT_BYTE:
00817 UNALIGNED_MOVE(((ht_tag_edit_byte*)tagstring)->offset, offset);
00818 break;
00819 case HT_TAG_EDIT_WORD_LE:
00820 case HT_TAG_EDIT_WORD_BE:
00821 case HT_TAG_EDIT_WORD_VE:
00822 UNALIGNED_MOVE(((ht_tag_edit_word_generic*)tagstring)->offset, offset);
00823 break;
00824 case HT_TAG_EDIT_DWORD_LE:
00825 case HT_TAG_EDIT_DWORD_BE:
00826 case HT_TAG_EDIT_DWORD_VE:
00827 UNALIGNED_MOVE(((ht_tag_edit_dword_generic*)tagstring)->offset, offset);
00828 break;
00829 case HT_TAG_EDIT_QWORD_LE:
00830 case HT_TAG_EDIT_QWORD_BE:
00831 case HT_TAG_EDIT_QWORD_VE:
00832 UNALIGNED_MOVE(((ht_tag_edit_qword_generic*)tagstring)->offset, offset);
00833 break;
00834 case HT_TAG_EDIT_TIME:
00835 UNALIGNED_MOVE(((ht_tag_edit_time*)tagstring)->offset, offset);
00836 break;
00837 case HT_TAG_EDIT_CHAR:
00838 UNALIGNED_MOVE(((ht_tag_edit_char*)tagstring)->offset, offset);
00839 break;
00840 case HT_TAG_EDIT_BIT:
00841 UNALIGNED_MOVE(((ht_tag_edit_bit*)tagstring)->offset, offset);
00842 break;
00843 }
00844 }
00845
00846 int tag_is_editable(const TAGSTRING *tagstring)
00847 {
00848 switch (tagstring[1]) {
00849 case HT_TAG_EDIT_BYTE:
00850 case HT_TAG_EDIT_WORD_LE:
00851 case HT_TAG_EDIT_DWORD_LE:
00852 case HT_TAG_EDIT_QWORD_LE:
00853 case HT_TAG_EDIT_WORD_BE:
00854 case HT_TAG_EDIT_DWORD_BE:
00855 case HT_TAG_EDIT_QWORD_BE:
00856 case HT_TAG_EDIT_WORD_VE:
00857 case HT_TAG_EDIT_DWORD_VE:
00858 case HT_TAG_EDIT_QWORD_VE:
00859 case HT_TAG_EDIT_TIME:
00860 case HT_TAG_EDIT_CHAR:
00861 case HT_TAG_EDIT_BIT:
00862 return 1;
00863 default:
00864 return 0;
00865 }
00866 assert(0);
00867 return -1;
00868 }
00869
00870 void tag_strcat(TAGSTRING *dest, const TAGSTRING *src)
00871 {
00872 int l=tag_strlen(dest);
00873 tag_strcpy(dest+l, src);
00874 }
00875
00876 void tag_strcpy(TAGSTRING *dest, const TAGSTRING *src)
00877 {
00878 int l=tag_strlen(src);
00879 memmove(dest, src, l);
00880 dest[l]=0;
00881 }
00882
00883 TAGSTRING *tag_strdup(const TAGSTRING *tagstring)
00884 {
00885 int l=tag_strlen(tagstring);
00886 TAGSTRING *s=(TAGSTRING*)malloc((sizeof(TAGSTRING)+1)*l);
00887 memmove(s, tagstring, sizeof(TAGSTRING)*l);
00888 s[l]=0;
00889 return s;
00890 }
00891
00892 int tag_strlen(const TAGSTRING *tagstring)
00893 {
00894 int c=0, r;
00895 while (*tagstring) {
00896 if (tagstring[0]=='\e') {
00897 r=tag_get_len(tagstring);
00898 } else {
00899 r=1;
00900 }
00901 tagstring+=r;
00902 c+=r;
00903 }
00904 return c;
00905 }
00906
00907 int tag_strvlen(const TAGSTRING *tagstring)
00908 {
00909 int c=0, r, v;
00910 while (*tagstring) {
00911 if (tagstring[0]=='\e') {
00912 r=tag_get_len(tagstring);
00913 v=tag_get_vlen(tagstring);
00914 } else {
00915 r=1;
00916 v=1;
00917 }
00918 tagstring+=r;
00919 c+=v;
00920 }
00921 return c;
00922 }
00923
00924 int tag_count_selectable_tags_in_group(const TAGSTRING *tagstring, int group)
00925 {
00926 int c=0;
00927 tagstring=tag_get_group(tagstring, group);
00928 while ((tagstring=tag_findnext(tagstring))) {
00929 switch (tagstring[1]) {
00930 case HT_TAG_EDIT_BYTE:
00931 c++;
00932 tagstring+=HT_TAG_EDIT_BYTE_LEN;
00933 break;
00934 case HT_TAG_EDIT_WORD_LE:
00935 c++;
00936 tagstring+=HT_TAG_EDIT_WORD_LE_LEN;
00937 break;
00938 case HT_TAG_EDIT_DWORD_LE:
00939 c++;
00940 tagstring+=HT_TAG_EDIT_DWORD_LE_LEN;
00941 break;
00942 case HT_TAG_EDIT_QWORD_LE:
00943 c++;
00944 tagstring+=HT_TAG_EDIT_QWORD_LE_LEN;
00945 break;
00946 case HT_TAG_EDIT_WORD_BE:
00947 c++;
00948 tagstring+=HT_TAG_EDIT_WORD_BE_LEN;
00949 break;
00950 case HT_TAG_EDIT_DWORD_BE:
00951 c++;
00952 tagstring+=HT_TAG_EDIT_DWORD_BE_LEN;
00953 break;
00954 case HT_TAG_EDIT_QWORD_BE:
00955 c++;
00956 tagstring+=HT_TAG_EDIT_QWORD_BE_LEN;
00957 break;
00958 case HT_TAG_EDIT_WORD_VE:
00959 c++;
00960 tagstring+=HT_TAG_EDIT_WORD_VE_LEN;
00961 break;
00962 case HT_TAG_EDIT_DWORD_VE:
00963 c++;
00964 tagstring+=HT_TAG_EDIT_DWORD_VE_LEN;
00965 break;
00966 case HT_TAG_EDIT_QWORD_VE:
00967 c++;
00968 tagstring+=HT_TAG_EDIT_QWORD_VE_LEN;
00969 break;
00970 case HT_TAG_EDIT_TIME:
00971 c++;
00972 tagstring+=HT_TAG_EDIT_TIME_LEN;
00973 break;
00974 case HT_TAG_EDIT_CHAR:
00975 c++;
00976 tagstring+=HT_TAG_EDIT_CHAR_LEN;
00977 break;
00978 case HT_TAG_EDIT_BIT:
00979 c++;
00980 tagstring+=HT_TAG_EDIT_BIT_LEN;
00981 break;
00982 case HT_TAG_SEL:
00983 c++;
00984 tagstring+=HT_TAG_SEL_LEN(((ht_tag_sel*)tagstring)->strlen);
00985 break;
00986 case HT_TAG_FLAGS:
00987 c++;
00988 tagstring+=HT_TAG_FLAGS_LEN;
00989 break;
00990 case HT_TAG_GROUP:
00991 return c;
00992 case HT_TAG_DESC_BYTE:
00993 c++;
00994 tagstring+=HT_TAG_DESC_BYTE_LEN;
00995 break;
00996 case HT_TAG_DESC_WORD_LE:
00997 c++;
00998 tagstring+=HT_TAG_DESC_WORD_LE_LEN;
00999 break;
01000 case HT_TAG_DESC_DWORD_LE:
01001 c++;
01002 tagstring+=HT_TAG_DESC_DWORD_LE_LEN;
01003 break;
01004 case HT_TAG_DESC_QWORD_LE:
01005 c++;
01006 tagstring+=HT_TAG_DESC_QWORD_LE_LEN;
01007 break;
01008 case HT_TAG_DESC_WORD_BE:
01009 c++;
01010 tagstring+=HT_TAG_DESC_WORD_BE_LEN;
01011 break;
01012 case HT_TAG_DESC_DWORD_BE:
01013 c++;
01014 tagstring+=HT_TAG_DESC_DWORD_BE_LEN;
01015 break;
01016 case HT_TAG_DESC_QWORD_BE:
01017 c++;
01018 tagstring+=HT_TAG_DESC_QWORD_BE_LEN;
01019 break;
01020 case HT_TAG_DESC_WORD_VE:
01021 c++;
01022 tagstring+=HT_TAG_DESC_WORD_VE_LEN;
01023 break;
01024 case HT_TAG_DESC_DWORD_VE:
01025 c++;
01026 tagstring+=HT_TAG_DESC_DWORD_VE_LEN;
01027 break;
01028 case HT_TAG_DESC_QWORD_VE:
01029 c++;
01030 tagstring+=HT_TAG_DESC_QWORD_VE_LEN;
01031 break;
01032 default:
01033 tagstring+=tag_get_len(tagstring);
01034 break;
01035 }
01036 }
01037 return c;
01038 }
01039
01040 int tag_count_selectable_tags(const TAGSTRING *tagstring)
01041 {
01042 int c=0;
01043 while ((tagstring=tag_findnext(tagstring))) {
01044 switch (tagstring[1]) {
01045 case HT_TAG_EDIT_BYTE:
01046 c++;
01047 tagstring+=HT_TAG_EDIT_BYTE_LEN;
01048 break;
01049 case HT_TAG_EDIT_WORD_LE:
01050 c++;
01051 tagstring+=HT_TAG_EDIT_WORD_LE_LEN;
01052 break;
01053 case HT_TAG_EDIT_DWORD_LE:
01054 c++;
01055 tagstring+=HT_TAG_EDIT_DWORD_LE_LEN;
01056 break;
01057 case HT_TAG_EDIT_QWORD_LE:
01058 c++;
01059 tagstring+=HT_TAG_EDIT_QWORD_LE_LEN;
01060 break;
01061 case HT_TAG_EDIT_WORD_BE:
01062 c++;
01063 tagstring+=HT_TAG_EDIT_WORD_BE_LEN;
01064 break;
01065 case HT_TAG_EDIT_DWORD_BE:
01066 c++;
01067 tagstring+=HT_TAG_EDIT_DWORD_BE_LEN;
01068 break;
01069 case HT_TAG_EDIT_QWORD_BE:
01070 c++;
01071 tagstring+=HT_TAG_EDIT_QWORD_BE_LEN;
01072 break;
01073 case HT_TAG_EDIT_WORD_VE:
01074 c++;
01075 tagstring+=HT_TAG_EDIT_WORD_VE_LEN;
01076 break;
01077 case HT_TAG_EDIT_DWORD_VE:
01078 c++;
01079 tagstring+=HT_TAG_EDIT_DWORD_VE_LEN;
01080 break;
01081 case HT_TAG_EDIT_QWORD_VE:
01082 c++;
01083 tagstring+=HT_TAG_EDIT_QWORD_VE_LEN;
01084 break;
01085 case HT_TAG_EDIT_TIME:
01086 c++;
01087 tagstring+=HT_TAG_EDIT_TIME_LEN;
01088 break;
01089 case HT_TAG_EDIT_CHAR:
01090 c++;
01091 tagstring+=HT_TAG_EDIT_CHAR_LEN;
01092 break;
01093 case HT_TAG_EDIT_BIT:
01094 c++;
01095 tagstring+=HT_TAG_EDIT_BIT_LEN;
01096 break;
01097 case HT_TAG_SEL:
01098 c++;
01099 tagstring+=HT_TAG_SEL_LEN(((ht_tag_sel*)tagstring)->strlen);
01100 break;
01101 case HT_TAG_FLAGS:
01102 c++;
01103 tagstring+=HT_TAG_FLAGS_LEN;
01104 break;
01105 case HT_TAG_DESC_BYTE:
01106 c++;
01107 tagstring+=HT_TAG_DESC_BYTE_LEN;
01108 break;
01109 case HT_TAG_DESC_WORD_LE:
01110 c++;
01111 tagstring+=HT_TAG_DESC_WORD_LE_LEN;
01112 break;
01113 case HT_TAG_DESC_DWORD_LE:
01114 c++;
01115 tagstring+=HT_TAG_DESC_DWORD_LE_LEN;
01116 break;
01117 case HT_TAG_DESC_QWORD_LE:
01118 c++;
01119 tagstring+=HT_TAG_DESC_QWORD_LE_LEN;
01120 break;
01121 case HT_TAG_DESC_WORD_BE:
01122 c++;
01123 tagstring+=HT_TAG_DESC_WORD_BE_LEN;
01124 break;
01125 case HT_TAG_DESC_DWORD_BE:
01126 c++;
01127 tagstring+=HT_TAG_DESC_DWORD_BE_LEN;
01128 break;
01129 case HT_TAG_DESC_QWORD_BE:
01130 c++;
01131 tagstring+=HT_TAG_DESC_QWORD_BE_LEN;
01132 break;
01133 case HT_TAG_DESC_WORD_VE:
01134 c++;
01135 tagstring+=HT_TAG_DESC_WORD_VE_LEN;
01136 break;
01137 case HT_TAG_DESC_DWORD_VE:
01138 c++;
01139 tagstring+=HT_TAG_DESC_DWORD_VE_LEN;
01140 break;
01141 case HT_TAG_DESC_QWORD_VE:
01142 c++;
01143 tagstring+=HT_TAG_DESC_QWORD_VE_LEN;
01144 break;
01145 default:
01146 tagstring+=tag_get_len(tagstring);
01147 break;
01148 }
01149 }
01150 return c;
01151 }
01152
01153 int tag_count_groups(const TAGSTRING *tagstring)
01154 {
01155 int c=1;
01156 while ((tagstring=tag_findnext(tagstring))) {
01157 if (tagstring[1]==HT_TAG_GROUP) {
01158 c++;
01159 tagstring+=HT_TAG_GROUP_LEN;
01160 } else {
01161 tagstring+=tag_get_len(tagstring);
01162 }
01163 }
01164 return c;
01165 }
01166
01167 TAGSTRING *tag_get_selectable_tag(const TAGSTRING *tagstring, int n, int group)
01168 {
01169 const TAGSTRING *r=NULL;
01170 if (group>0) tagstring=tag_get_group(tagstring, group);
01171 n++;
01172 while ((n) && (tagstring=tag_findnext(tagstring))) {
01173 switch (tagstring[1]) {
01174 case HT_TAG_EDIT_BYTE:
01175 n--;
01176 r=tagstring;
01177 tagstring+=HT_TAG_EDIT_BYTE_LEN;
01178 break;
01179 case HT_TAG_EDIT_WORD_LE:
01180 n--;
01181 r=tagstring;
01182 tagstring+=HT_TAG_EDIT_WORD_LE_LEN;
01183 break;
01184 case HT_TAG_EDIT_DWORD_LE:
01185 n--;
01186 r=tagstring;
01187 tagstring+=HT_TAG_EDIT_DWORD_LE_LEN;
01188 break;
01189 case HT_TAG_EDIT_QWORD_LE:
01190 n--;
01191 r=tagstring;
01192 tagstring+=HT_TAG_EDIT_QWORD_LE_LEN;
01193 break;
01194 case HT_TAG_EDIT_WORD_BE:
01195 n--;
01196 r=tagstring;
01197 tagstring+=HT_TAG_EDIT_WORD_BE_LEN;
01198 break;
01199 case HT_TAG_EDIT_DWORD_BE:
01200 n--;
01201 r=tagstring;
01202 tagstring+=HT_TAG_EDIT_DWORD_BE_LEN;
01203 break;
01204 case HT_TAG_EDIT_QWORD_BE:
01205 n--;
01206 r=tagstring;
01207 tagstring+=HT_TAG_EDIT_QWORD_BE_LEN;
01208 break;
01209 case HT_TAG_EDIT_WORD_VE:
01210 n--;
01211 r=tagstring;
01212 tagstring+=HT_TAG_EDIT_WORD_VE_LEN;
01213 break;
01214 case HT_TAG_EDIT_DWORD_VE:
01215 n--;
01216 r=tagstring;
01217 tagstring+=HT_TAG_EDIT_DWORD_VE_LEN;
01218 break;
01219 case HT_TAG_EDIT_QWORD_VE:
01220 n--;
01221 r=tagstring;
01222 tagstring+=HT_TAG_EDIT_QWORD_VE_LEN;
01223 break;
01224 case HT_TAG_EDIT_TIME:
01225 n--;
01226 r=tagstring;
01227 tagstring+=HT_TAG_EDIT_TIME_LEN;
01228 break;
01229 case HT_TAG_EDIT_CHAR:
01230 n--;
01231 r=tagstring;
01232 tagstring+=HT_TAG_EDIT_CHAR_LEN;
01233 break;
01234 case HT_TAG_EDIT_BIT:
01235 n--;
01236 r=tagstring;
01237 tagstring+=HT_TAG_EDIT_BIT_LEN;
01238 break;
01239 case HT_TAG_SEL:
01240 n--;
01241 r=tagstring;
01242 tagstring+=HT_TAG_SEL_LEN(((ht_tag_sel*)tagstring)->strlen);
01243 break;
01244 case HT_TAG_FLAGS:
01245 n--;
01246 r=tagstring;
01247 tagstring+=HT_TAG_FLAGS_LEN;
01248 break;
01249 case HT_TAG_GROUP:
01250 if (group!=-1) return (char*)r;
01251 tagstring+=HT_TAG_GROUP_LEN;
01252 break;
01253 case HT_TAG_DESC_BYTE:
01254 n--;
01255 r=tagstring;
01256 tagstring+=HT_TAG_DESC_BYTE_LEN;
01257 break;
01258 case HT_TAG_DESC_WORD_LE:
01259 n--;
01260 r=tagstring;
01261 tagstring+=HT_TAG_DESC_WORD_LE_LEN;
01262 break;
01263 case HT_TAG_DESC_DWORD_LE:
01264 n--;
01265 r=tagstring;
01266 tagstring+=HT_TAG_DESC_DWORD_LE_LEN;
01267 break;
01268 case HT_TAG_DESC_QWORD_LE:
01269 n--;
01270 r=tagstring;
01271 tagstring+=HT_TAG_DESC_QWORD_LE_LEN;
01272 break;
01273 case HT_TAG_DESC_WORD_BE:
01274 n--;
01275 r=tagstring;
01276 tagstring+=HT_TAG_DESC_WORD_BE_LEN;
01277 break;
01278 case HT_TAG_DESC_DWORD_BE:
01279 n--;
01280 r=tagstring;
01281 tagstring+=HT_TAG_DESC_DWORD_BE_LEN;
01282 break;
01283 case HT_TAG_DESC_QWORD_BE:
01284 n--;
01285 r=tagstring;
01286 tagstring+=HT_TAG_DESC_QWORD_BE_LEN;
01287 break;
01288 case HT_TAG_DESC_WORD_VE:
01289 n--;
01290 r=tagstring;
01291 tagstring+=HT_TAG_DESC_WORD_VE_LEN;
01292 break;
01293 case HT_TAG_DESC_DWORD_VE:
01294 n--;
01295 r=tagstring;
01296 tagstring+=HT_TAG_DESC_DWORD_VE_LEN;
01297 break;
01298 case HT_TAG_DESC_QWORD_VE:
01299 n--;
01300 r=tagstring;
01301 tagstring+=HT_TAG_DESC_QWORD_VE_LEN;
01302 break;
01303 default:
01304 tagstring+=tag_get_len(tagstring);
01305 break;
01306 }
01307 }
01308 return (n == 0) ? (char*)r : NULL;
01309 }
01310
01311 TAGSTRING *tag_get_group(const TAGSTRING *tagstring, int group)
01312 {
01313 const TAGSTRING *r=tagstring;
01314 while ((group) && (tagstring=tag_findnext(tagstring))) {
01315 switch (tagstring[1]) {
01316 case HT_TAG_GROUP:
01317 group--;
01318 tagstring+=HT_TAG_GROUP_LEN;
01319 r=tagstring;
01320 break;
01321 default:
01322 tagstring+=tag_get_len(tagstring);
01323 break;
01324 }
01325 }
01326 return (TAGSTRING *)r;
01327 }
01328
01329 int tag_get_class(const TAGSTRING *tagstring)
01330 {
01331 switch (tagstring[1]) {
01332 case HT_TAG_EDIT_BYTE:
01333 case HT_TAG_EDIT_WORD_LE:
01334 case HT_TAG_EDIT_DWORD_LE:
01335 case HT_TAG_EDIT_QWORD_LE:
01336 case HT_TAG_EDIT_WORD_BE:
01337 case HT_TAG_EDIT_DWORD_BE:
01338 case HT_TAG_EDIT_QWORD_BE:
01339 case HT_TAG_EDIT_WORD_VE:
01340 case HT_TAG_EDIT_DWORD_VE:
01341 case HT_TAG_EDIT_QWORD_VE:
01342 case HT_TAG_EDIT_TIME:
01343 case HT_TAG_EDIT_CHAR:
01344 case HT_TAG_EDIT_BIT:
01345 return tag_class_edit;
01346 case HT_TAG_SEL:
01347 case HT_TAG_FLAGS:
01348 case HT_TAG_DESC_BYTE:
01349 case HT_TAG_DESC_WORD_LE:
01350 case HT_TAG_DESC_DWORD_LE:
01351 case HT_TAG_DESC_QWORD_LE:
01352 case HT_TAG_DESC_WORD_BE:
01353 case HT_TAG_DESC_DWORD_BE:
01354 case HT_TAG_DESC_QWORD_BE:
01355 case HT_TAG_DESC_WORD_VE:
01356 case HT_TAG_DESC_DWORD_VE:
01357 case HT_TAG_DESC_QWORD_VE:
01358 return tag_class_sel;
01359 default:
01360 return tag_class_no;
01361 }
01362 }
01363
01364 char *tag_striptags(char *dest, const TAGSTRING *src)
01365 {
01366 if (!dest) return NULL;
01367 if (!src) {
01368 *dest = 0;
01369 return dest;
01370 }
01371 char *d = dest;
01372 while (*src) {
01373 if (src[0]=='\e') {
01374 switch (src[1]) {
01375 case HT_TAG_SEL: {
01376 src += sizeof (ht_tag_sel);
01377 break;
01378 }
01379 default:
01380 src+=tag_get_len(src);
01381 }
01382 } else {
01383 *dest = *src;
01384 dest++;
01385 src++;
01386 }
01387 }
01388 *dest = 0;
01389 return d;
01390 }
01391