diff options
Diffstat (limited to 'plugins/MirOTR/ekhtml/src')
-rw-r--r-- | plugins/MirOTR/ekhtml/src/ekhtml.c | 16 | ||||
-rw-r--r-- | plugins/MirOTR/ekhtml/src/ekhtml_comment.c | 12 | ||||
-rw-r--r-- | plugins/MirOTR/ekhtml/src/ekhtml_endtag.c | 10 | ||||
-rw-r--r-- | plugins/MirOTR/ekhtml/src/ekhtml_mktables.c | 8 | ||||
-rw-r--r-- | plugins/MirOTR/ekhtml/src/ekhtml_special.c | 6 | ||||
-rw-r--r-- | plugins/MirOTR/ekhtml/src/ekhtml_starttag.c | 30 | ||||
-rw-r--r-- | plugins/MirOTR/ekhtml/src/hash.c | 12 |
7 files changed, 52 insertions, 42 deletions
diff --git a/plugins/MirOTR/ekhtml/src/ekhtml.c b/plugins/MirOTR/ekhtml/src/ekhtml.c index 8c432cc00e..f3697469f6 100644 --- a/plugins/MirOTR/ekhtml/src/ekhtml.c +++ b/plugins/MirOTR/ekhtml/src/ekhtml.c @@ -89,7 +89,7 @@ static void ekhtml_buffer_grow(ekhtml_parser_t *parser){ newsize = parser->nalloced + EKHTML_BLOCKSIZE; - if ((newbuf = realloc(parser->buf, newsize)) == NULL){ + if((newbuf = realloc(parser->buf, newsize)) == NULL){ fprintf(stderr, "BAD! Can't allocate %d bytes in ekhtml_buffer_grow\n", newsize); fflush(stderr); /* Just in case someone changes the buffering scheme */ @@ -119,7 +119,7 @@ int parser_state_determine(const char *startp, const char *endp){ assert(startp != endp); - if (*startp != '<') + if(*startp != '<') return EKHTML_STATE_INDATA; firstchar = startp + 1; @@ -130,7 +130,7 @@ int parser_state_determine(const char *startp, const char *endp){ if(newstate == EKHTML_STATE_NONE){ if(firstchar + 2 >= endp) /* Not enough data to evaluate */ return EKHTML_STATE_NONE; - if (*(firstchar + 1) == '-' && *(firstchar + 2) == '-') + if(*(firstchar + 1) == '-' && *(firstchar + 2) == '-') return EKHTML_STATE_COMMENT; else return EKHTML_STATE_SPECIAL; @@ -238,7 +238,7 @@ void ekhtml_parser_feed(ekhtml_parser_t *parser, ekhtml_string_t *str){ parser->nbuf += tocopy; if(parser->nalloced == parser->nbuf){ /* Process the buffer */ - if (!ekhtml_parser_flush(parser, 0)) { + if(!ekhtml_parser_flush(parser, 0)){ /* If we didn't actually process anything, grow our buffer */ ekhtml_buffer_grow(parser); } @@ -270,7 +270,7 @@ ekhtml_parser_startendcb_add(ekhtml_parser_t *parser, const char *tag, unsigned int taglen; hnode_t *hn; - if (!tag){ + if(!tag){ if(isStart) parser->startcb_unk = startcb; else @@ -289,7 +289,7 @@ ekhtml_parser_startendcb_add(ekhtml_parser_t *parser, const char *tag, lookup_str.str = newtag; lookup_str.len = taglen; - if ((hn = hash_lookup(parser->startendcb, &lookup_str))) { + if((hn = hash_lookup(parser->startendcb, &lookup_str))){ cont = hnode_get(hn); free(newtag); if(isStart) @@ -333,7 +333,7 @@ static hash_val_t ekhtml_string_hash(const void *key){ size_t len = s->len; int c; - while(len--) { + while(len--){ c = str[len]; res = ((res << 5) + res) + c; /* res * 33 + c */ } @@ -353,7 +353,7 @@ void ekhtml_parser_destroy(ekhtml_parser_t *ekparser){ hscan_t hs; hash_scan_begin(&hs, ekparser->startendcb); - while((hn = hash_scan_next(&hs))) { + while((hn = hash_scan_next(&hs))){ ekhtml_string_t *key = (ekhtml_string_t *)hnode_getkey(hn); ekhtml_tag_container *cont = hnode_get(hn); diff --git a/plugins/MirOTR/ekhtml/src/ekhtml_comment.c b/plugins/MirOTR/ekhtml/src/ekhtml_comment.c index 11c4e8cf2e..e37cc487b5 100644 --- a/plugins/MirOTR/ekhtml/src/ekhtml_comment.c +++ b/plugins/MirOTR/ekhtml/src/ekhtml_comment.c @@ -66,22 +66,22 @@ char *ekhtml_parse_comment(ekhtml_parser_t *parser, void **state_data, if(comstate->dashes == 0){ /* Still on the quest for the double dash*/ /* XXX -- Searching for '--' could be faster, doing multibyte searching, or something similar */ - for (; workp < endp - 1; workp += 2){ - if (*workp == '-') + for(; workp < endp - 1; workp += 2){ + if(*workp == '-') break; } - if (!(workp < endp - 1)) { + if(!(workp < endp - 1)){ *offset = endp - 1 - curp; return NULL; } - if ((*(workp - 1) == '-') && + if((*(workp - 1) == '-') && (workp - curp) > (sizeof("<!--") - 1)) { comstate->lastdash = workp - 1 - curp; comstate->dashes = 1; - } else if (*(workp + 1) == '-') { + } else if(*(workp + 1) == '-'){ comstate->lastdash = workp - curp; comstate->dashes = 1; } else { @@ -99,7 +99,7 @@ char *ekhtml_parse_comment(ekhtml_parser_t *parser, void **state_data, return NULL; } - if (*workp == '>') { + if(*workp == '>'){ if(parser->commentcb){ ekhtml_string_t str; diff --git a/plugins/MirOTR/ekhtml/src/ekhtml_endtag.c b/plugins/MirOTR/ekhtml/src/ekhtml_endtag.c index 7e4ba7650d..f7095dcdfe 100644 --- a/plugins/MirOTR/ekhtml/src/ekhtml_endtag.c +++ b/plugins/MirOTR/ekhtml/src/ekhtml_endtag.c @@ -47,7 +47,7 @@ static void handle_endtag(ekhtml_parser_t *parser, ekhtml_string_t *str){ ekhtml_tag_container *container; hnode_t *hn; - if ((hn = hash_lookup(parser->startendcb, str)) && + if((hn = hash_lookup(parser->startendcb, str)) && (container = hnode_get(hn)) && container->endfunc) { @@ -73,8 +73,8 @@ char *ekhtml_parse_endtag(ekhtml_parser_t *parser, void **state_data, const char *secondchar = curp + 2; /* Initial check to make sure this isn't some bad tag */ - if (!isalpha(*secondchar)) { - if (*secondchar != '>' && *secondchar != '<') { + if(!isalpha(*secondchar)){ + if(*secondchar != '>' && *secondchar != '<'){ /* Bogus tag */ *baddata = EKHTML_STATE_BADDATA; return (char *)curp; @@ -100,7 +100,7 @@ char *ekhtml_parse_endtag(ekhtml_parser_t *parser, void **state_data, arrowp != endp && *arrowp != '<' && *arrowp != '>'; arrowp++) { - if (!(EKCMap_CharMap[(unsigned char)*arrowp] & EKHTML_CHAR_WHITESPACE)) + if(!(EKCMap_CharMap[(unsigned char)*arrowp] & EKHTML_CHAR_WHITESPACE)) endstate->lastchar = arrowp - curp; } @@ -120,7 +120,7 @@ char *ekhtml_parse_endtag(ekhtml_parser_t *parser, void **state_data, handle_endtag(parser, &str); *state_data = NULL; assert(arrowp < endp); - if (*arrowp == '<') { /* Malformed HTML */ + if(*arrowp == '<'){ /* Malformed HTML */ return (char *)(arrowp); } else { return (char *)(arrowp + 1); diff --git a/plugins/MirOTR/ekhtml/src/ekhtml_mktables.c b/plugins/MirOTR/ekhtml/src/ekhtml_mktables.c index 235a0a7e75..9a8dea2a03 100644 --- a/plugins/MirOTR/ekhtml/src/ekhtml_mktables.c +++ b/plugins/MirOTR/ekhtml/src/ekhtml_mktables.c @@ -106,21 +106,21 @@ static EKHTML_CHARMAP_TYPE charmap_values(char in){ #define EKHTML_STRINGIFY(x) #x -static void print_charmap(char *name, EKHTML_CHARMAP_TYPE (*cmap_func)(char)) { +static void print_charmap(char *name, EKHTML_CHARMAP_TYPE (*cmap_func)(char)){ int ch; char sbuf[256]; sprintf_s(sbuf, 256, "0x%%0%dx ", EKHTML_CHARMAP_LEN * 2); printf("#ifdef EKHTML_USE_TABLES\n"); printf("const %s %s[256] = {\n", EKHTML_CHARMAP_TYPE_S, name); - for(ch=0; ch < 256; ch++) { + for(ch=0; ch < 256; ch++){ printf(sbuf, cmap_func((char)ch)); if(isgraph(ch)) printf("/* '%c' */", ch); else printf("/* 0x%.2x */", ch); printf(", "); - if (!((ch + 1) % 4)) + if(!((ch + 1) % 4)) printf("\n"); } printf("};\n\n"); @@ -129,7 +129,7 @@ static void print_charmap(char *name, EKHTML_CHARMAP_TYPE (*cmap_func)(char)) { printf("#endif\n"); } -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]){ printf("#ifndef EKHTML_MKTABLES_DOT_H\n"); printf("#define EKHTML_MKTABLES_DOT_H\n"); diff --git a/plugins/MirOTR/ekhtml/src/ekhtml_special.c b/plugins/MirOTR/ekhtml/src/ekhtml_special.c index b29e6422cd..f43a62dac4 100644 --- a/plugins/MirOTR/ekhtml/src/ekhtml_special.c +++ b/plugins/MirOTR/ekhtml/src/ekhtml_special.c @@ -41,13 +41,13 @@ char *ekhtml_parse_special(ekhtml_parser_t *parser, void **state_data, assert(*curp == '<' && *(curp + 1) == '!'); - if (*state_data == NULL){/* Only called the first time the tag is started */ + if(*state_data == NULL){/* Only called the first time the tag is started */ *offset = 2; *state_data = (void *)1; /* Assign it any non-NULL value */ } for(workp=curp + *offset;workp != endp; workp++) - if (*workp == '<' || *workp == '>') + if(*workp == '<' || *workp == '>') break; if(workp == endp){ @@ -65,7 +65,7 @@ char *ekhtml_parse_special(ekhtml_parser_t *parser, void **state_data, } *state_data = NULL; - if (*workp == '<') /* Malformed HTML */ + if(*workp == '<') /* Malformed HTML */ return (char *)workp; else return (char *)workp + 1; diff --git a/plugins/MirOTR/ekhtml/src/ekhtml_starttag.c b/plugins/MirOTR/ekhtml/src/ekhtml_starttag.c index ea0b213ec7..cfd3ea4fd4 100644 --- a/plugins/MirOTR/ekhtml/src/ekhtml_starttag.c +++ b/plugins/MirOTR/ekhtml/src/ekhtml_starttag.c @@ -133,7 +133,7 @@ static void handle_starttag(ekhtml_parser_t *parser, char *curp, str.str = upper_str; str.len = taglen; - if ((hn = hash_lookup(parser->startendcb, &str)) && + if((hn = hash_lookup(parser->startendcb, &str)) && (container = hnode_get(hn)) && container->startfunc) { @@ -141,14 +141,14 @@ static void handle_starttag(ekhtml_parser_t *parser, char *curp, } else if(parser->startcb_unk) cback = parser->startcb_unk; - if (!cback) + if(!cback) return; /* Formulate real attribute callback data from the 'offset' pointer values */ for(attr=sstate->attrs;attr;attr=attr->next){ attr->name.str = curp + (int)attr->name.str; - if (!attr->isBoolean) + if(!attr->isBoolean) attr->val.str = curp + (int)attr->val.str; } @@ -223,7 +223,7 @@ char *ekhtml_parse_starttag(ekhtml_parser_t *parser, void **state_data, if(workp == endp) break; - if (!(EKCMap_CharMap[(unsigned char)*workp] & + if(!(EKCMap_CharMap[(unsigned char)*workp] & EKHTML_CHAR_BEGATTRNAME)) { /* Bad attrname character */ @@ -254,11 +254,11 @@ char *ekhtml_parse_starttag(ekhtml_parser_t *parser, void **state_data, of file */ startstate->curattr->name.len = workp - (curp + (int)startstate->curattr->name.str); - if (*workp == '=') { + if(*workp == '='){ startstate->mode = EKHTML_STMODE_BEGVALUE; workp++; /* Skip the equals sign */ } else { - if (!(EKCMap_CharMap[(unsigned char)*workp] & + if(!(EKCMap_CharMap[(unsigned char)*workp] & EKHTML_CHAR_WHITESPACE)) { /* Found something we weren't expecting. Use the current @@ -277,7 +277,7 @@ char *ekhtml_parse_starttag(ekhtml_parser_t *parser, void **state_data, if(workp == endp) break; - if (*workp != '=') { + if(*workp != '='){ /* Unexpected value. Could either be time to suck, or this was really only a boolean value */ scroll_attribute(startstate); @@ -306,12 +306,12 @@ char *ekhtml_parse_starttag(ekhtml_parser_t *parser, void **state_data, startstate->curattr->isBoolean = 0; startstate->curattr->val.str = (char *)NULL + (workp - curp); startstate->quote = '\0'; - if (*workp == '"' || *workp == '\'') { + if(*workp == '"' || *workp == '\''){ startstate->curattr->val.str++; /* Skip the quote */ startstate->mode = EKHTML_STMODE_GETVALUE; startstate->quote = *workp; workp++; - } else if (!(EKCMap_CharMap[(unsigned char)*workp] & + } else if(!(EKCMap_CharMap[(unsigned char)*workp] & EKHTML_CHAR_ATTRVALUE)) { /* Bad value .. */ @@ -326,8 +326,8 @@ char *ekhtml_parse_starttag(ekhtml_parser_t *parser, void **state_data, if(startstate->mode == EKHTML_STMODE_GETVALUE){ if(startstate->quote){ - for (;workp != endp && *workp != '>' && *workp != '<'; workp++) { - if (*workp == startstate->quote){ + for(;workp != endp && *workp != '>' && *workp != '<'; workp++){ + if(*workp == startstate->quote){ startstate->curattr->val.len = workp - (curp + (int)startstate->curattr->val.str); scroll_attribute(startstate); @@ -351,12 +351,12 @@ char *ekhtml_parse_starttag(ekhtml_parser_t *parser, void **state_data, workp - (curp + (int)startstate->curattr->val.str); scroll_attribute(startstate); - if (*workp == '>' || *workp == '<') { + if(*workp == '>' || *workp == '<') { *offset = workp - curp; handle_starttag(parser, curp, startstate); release_attributes(parser, startstate); *state_data = NULL; - if (*workp == '<') + if(*workp == '<') return workp; else return workp + 1; @@ -369,7 +369,7 @@ char *ekhtml_parse_starttag(ekhtml_parser_t *parser, void **state_data, if(startstate->mode == EKHTML_STMODE_SUCK){ /* The sucking mode is here in case someone puts a bad character in an attribute name. We suck until what looks like end of tag*/ - for (;workp != endp && *workp != '<' && *workp != '>'; workp++) + for(;workp != endp && *workp != '<' && *workp != '>'; workp++) ; if(workp == endp) break; @@ -378,7 +378,7 @@ char *ekhtml_parse_starttag(ekhtml_parser_t *parser, void **state_data, handle_starttag(parser, curp, startstate); release_attributes(parser, startstate); *state_data = NULL; - if (*workp == '<') + if(*workp == '<') return workp; else return workp + 1; diff --git a/plugins/MirOTR/ekhtml/src/hash.c b/plugins/MirOTR/ekhtml/src/hash.c index 441e4cb9be..95651d4e76 100644 --- a/plugins/MirOTR/ekhtml/src/hash.c +++ b/plugins/MirOTR/ekhtml/src/hash.c @@ -54,7 +54,6 @@ static const char rcsid[] = "$Id: hash.c,v 1.1 2002/09/17 02:49:36 jick Exp $"; #define table hash_table #define chain hash_chain -#define hash_val_t_bit (compute_bits()) static hnode_t *hnode_alloc(void *context); static void hnode_free(hnode_t *node, void *context); @@ -76,7 +75,18 @@ int hash_val_t_bit; * right, replacing the topmost bit by zero. */ +static void compute_bits(void) +{ + hash_val_t val = HASH_VAL_T_MAX; /* 1 */ + int bits = 0; + + while (val) { /* 2 */ + bits++; + val >>= 1; + } + hash_val_t_bit = bits; +} /* * Verify whether the given argument is a power of two. |