main(int argc, char *argv[]){ char *t; t = "test"; char *d = ReverseCopy(t); printf("Reversing String now\n"); printf("String:%s\n",d); printf("-------------Question 2--------------\n"); stackADT stack = NewStack(); FILE *in; //char *test = (char *)malloc(256*sizeof(char)), *test2 , *t1; int tM; char *test, *test2 , *t1; int tM; in = fopen("webpage.html","r"); if (in == NULL) printf("Null File my n***a\n"); string t1 = read_a_tag(in); string t2 = read_a_tag(in); /* if (tag_match(read_a_tag(in),read_a_tag(in))){ printf("Testing double method calls\n"); } else{ printf("Did not work\n"); } */ test = read_a_tag(in); printf("Testing read_a_tag method, tag:%s \n",test); test2 = read_a_tag(in); printf("Testing read_a_tag method, tag:%s \n",test2); tM = tag_match(test,test2); printf("Did these tags match?:%d\n", tM); test = read_a_tag(in); t1 = (char *) malloc(strlen(test) * sizeof(char)); if (t1 == NULL) printf("No Memory\n"); t1 = test; printf("Testing read_a_tag method, tag:%s \n",t1); test2 = read_a_tag(in); printf("Testing read_a_tag method, tag:%s \n",test2); tM = tag_match(t1,test2); printf("Did these tags match?:%d\n", tM); fclose(in); }
/* Fall through . . */ case 107: if (tolower (ch) == 'h') { state = 1; start = n; } else state = ST_INITIAL; break; case ST_START_FOUND: if (isspace ((int) ((unsigned char) ch)) || (ch == '"') || (ch == '>')) { end = n; state = ST_END_FOUND; } break; } # undef CHK # undef CCHK } else { if (state == ST_START_FOUND) { end = n; state = ST_END_FOUND; } else state = ST_INITIAL; } n += clen; } else { if (state == ST_START_FOUND) { end = n; state = ST_END_FOUND; } ++n; } if (state == ST_END_FOUND) { int ulen, m, o; ulen = end - start; for (m = 0; m < blockmail -> url_count; ++m) if ((blockmail -> url[m] -> usage & mask) && (blockmail -> url[m] -> dlen == ulen) && (! xmlStrncmp (blockmail -> url[m] -> dptr, cont + start, ulen))) break; if (m < blockmail -> url_count) { if (lstore < start) xmlBufferAdd (block -> out, cont + lstore, start - lstore); for (o = 0; o < rec -> url_count; ++o) if (rec -> url[o] -> uid == blockmail -> url[m] -> uid) break; if (o < rec -> url_count) xmlBufferAdd (block -> out, rec -> url[o] -> dptr, rec -> url[o] -> dlen); lstore = end; changed = true; } state = ST_INITIAL; } } if (changed) { if (lstore < len) xmlBufferAdd (block -> out, cont + lstore, len - lstore); SWAP (block); } return true; }/*}}}*/ static bool_t collect_links (blockmail_t *blockmail, block_t *block, links_t *links) /*{{{*/ { bool_t rc; int n, clen; int len; const xmlChar *cont; int start; rc = true; len = xmlBufferLength (block -> in); cont = xmlBufferContent (block -> in); for (n = 0; rc && (n < len); ) { clen = xmlCharLength (cont[n]); if ((clen == 1) && (cont[n] == 'h')) { start = n; ++n; if ((n + 3 < len) && (cont[n] == 't') && (cont[n + 1] == 't') && (cont[n + 2] == 'p')) { n += 3; if ((n + 1 < len) && (cont[n] == 's')) ++n; if ((n + 3 < len) && (cont[n] == ':') && (cont[n + 1] == '/') && (cont[n + 2] == '/')) { n += 3; while ((n < len) && (xmlCharLength (cont[n]) == 1) && (cont[n] != '"') && (cont[n] != '<') && (cont[n] != '>') && (! isspace (cont[n]))) ++n; rc = links_nadd (links, (const char *) (cont + start), n - start); } } } else n += clen; } return rc; }/*}}}*/ static int find_top (const xmlChar *cont, int len) /*{{{*/ { int pos; int state; int n; int clen; unsigned char ch; for (pos = -1, state = 0, n = 0; (n < len) && (pos == -1); ) { clen = xmlCharLength (cont[n]); if (clen > 1) state = 0; else { ch = cont[n]; switch (state) { case 0: if (ch == '<') state = 1; break; case 1: if ((ch == 'b') || (ch == 'B')) state = 2; else if (ch == '>') state = 0; else if (! isspace (ch)) state = 100; break; case 2: if ((ch == 'o') || (ch == 'O')) state = 3; else if (ch == '>') state = 0; else state = 100; break; case 3: if ((ch == 'd') || (ch == 'D')) state = 4; else if (ch == '>') state = 0; else state = 100; break; case 4: if ((ch == 'y') || (ch == 'Y')) state = 5; else if (ch == '>') state = 0; else state = 100; break; case 5: if (ch == '>') { pos = n + clen; state = 0; } else if (isspace (ch)) state = 6; else state = 100; break; case 6: if (ch == '>') { pos = n + clen; state = 0; } # ifdef STRICT else if (ch == '"') state = 7; break; case 7: if (ch == '"') state = 6; # endif /* STRICT */ break; case 100: if (ch == '>') state = 0; break; } } n += clen; } return pos; }/*}}}*/ static int find_bottom (const xmlChar *cont, int len) /*{{{*/ { int pos; int last; int m; int bclen; for (pos = -1, last = len, m = len - 1; (m >= 0) && (pos == -1); ) { bclen = xmlCharLength (cont[m]); if ((bclen == 1) && (cont[m] == '<')) { int n; int state; int clen; unsigned char ch; for (n = m + bclen, state = 1; (n < last) && (state > 0) && (state != 99); ) { clen = xmlCharLength (cont[n]); if (clen != 1) state = 0; else { ch = cont[n]; switch (state) { case 1: if (ch == '/') state = 2; else if (! isspace (ch)) state = 0; break; case 2: if ((ch == 'b') || (ch == 'B')) state = 3; else if (! isspace (ch)) state = 0; break; case 3: if ((ch == 'o') || (ch == 'O')) state = 4; else state = 0; break; case 4: if ((ch == 'd') || (ch == 'D')) state = 5; else state = 0; break; case 5: if ((ch == 'y') || (ch == 'Y')) state = 6; else state = 0; break; case 6: if ((ch == '>') || isspace (ch)) state = 99; else state = 0; break; } } n += clen; } if (state == 99) pos = m; } else if ((bclen == 1) && (cont[m] == '>')) last = m + bclen; m -= bclen; } return pos; }/*}}}*/ static bool_t add_onepixellog_image (blockmail_t *blockmail, receiver_t *rec, block_t *block, opl_t opl) /*{{{*/ { bool_t rc; const xmlChar tname[] = "[agnONEPIXEL]"; int tlen = sizeof (tname) - 1; tag_t *opltag; rc = true; for (opltag = rec -> tag; opltag; opltag = opltag -> next) if (tag_match (opltag, tname, tlen)) break; if (opltag && opltag -> value) { int pos; int len; const xmlChar *cont; pos = -1; len = xmlBufferLength (block -> in); cont = xmlBufferContent (block -> in); switch (opl) { case OPL_None: break; case OPL_Top: pos = find_top (cont, len); if (pos == -1) pos = 0; break; case OPL_Bottom: pos = find_bottom (cont, len); if (pos == -1) pos = len; break; } if (pos != -1) { const xmlChar lprefix[] = "<img src=\""; const xmlChar lpostfix[] = "\" alt=\"\" border=\"0\" height=\"1\" width=\"1\">"; xmlBufferEmpty (block -> out); if (pos > 0) xmlBufferAdd (block -> out, cont, pos); xmlBufferAdd (block -> out, lprefix, sizeof (lprefix) - 1); xmlBufferAdd (block -> out, xmlBufferContent (opltag -> value), xmlBufferLength (opltag -> value)); xmlBufferAdd (block -> out, lpostfix, sizeof (lpostfix) - 1); if (pos < len) xmlBufferAdd (block -> out, cont + pos, len - pos); SWAP (block); } } return rc; }/*}}}*/
static bool_t expand_tags (tag_t *base) /*{{{*/ { bool_t st; tag_t *cur, *tmp; const xmlChar *ptr; int len; int n, pos; int bstart; xmlBufferPtr out; st = true; for (cur = base; cur; cur = cur -> next) { for (tmp = base; tmp; tmp = tmp -> next) tmp -> used = (tmp == cur ? true : false); ptr = xmlBufferContent (cur -> value); len = xmlBufferLength (cur -> value); pos = 0; bstart = 0; out = NULL; while (pos < len) { n = xmlCharLength (ptr[pos]); if ((n == 1) && (ptr[pos] == '[')) { int start, end; start = pos++; end = -1; while (pos < len) { n = xmlCharLength (ptr[pos]); if ((n == 1) && (ptr[pos] == ']')) { ++pos; end = pos; break; } pos += n; } if (end != -1) { for (tmp = base; tmp; tmp = tmp -> next) if ((! tmp -> used) && tag_match (tmp, ptr + start, end - start)) break; if (tmp) { if (! out) if (! (out = xmlBufferCreate ())) { st = false; break; } if (bstart < start) xmlBufferAdd (out, ptr + bstart, start - bstart); xmlBufferAdd (out, xmlBufferContent (tmp -> value), xmlBufferLength (tmp -> value)); tmp -> used = true; bstart = pos; } } } else pos += n; } if (out) { if (bstart < len) xmlBufferAdd (out, ptr + bstart, len - bstart); xmlBufferFree (cur -> value); cur -> value = out; } } return st; }/*}}}*/