#include #include #include #include #include "web.h" const char * getxreffield(const char * tag) { if (!strcmp(tag, "A")) return "HREF"; else if (!strcmp(tag, "IMG")) return "SRC"; else if (!strcmp(tag, "FRAME")) return "SRC"; else if (!strcmp(tag, "BODY")) return "BACKGROUND"; else if (!strcmp(tag, "LINK")) return "HREF"; else if (!strcmp(tag, "LAYER")) return "SRC"; else return NULL; } #define getpnext (p++ + (index++ * 0)) /* return p, postincrement index & p */ #define nextp p++, index++ int getxref(FILE * fp, xreflist * xrefs) { int incomment = 0; /* 1 if in a comment */ int intag = 0; /* 1 if in a tag */ int intagname = -1; /* number of characters in if in tag name, 0 if before tag name */ char tagnamebuf[80]; int lookxref = 0; /* 1 if in a tag which contains xrefs */ const char * xreffield; /* if lookxref, the string that starts a reference */ int matchedfield = 0; long size; int inquotes = 0; int foundxref = 0; int inxref = 0; int wspacecount = 0; char * buf; char * p, *xrefstart; int index = 0, nxrefstart; xrefs -> nrefs = 0; fseek(fp, 0, SEEK_END); buf = malloc((size = ftell(fp)) + 1); if (! buf) { fprintf(stderr, "malloc failed\n"); return 1; } fseek(fp, 0, SEEK_SET); fread(buf, 1, size, fp); buf[size] = 0; p = buf; while (*p) { if (incomment) { if (!strncmp(p, "-->", 3)) { incomment = 0; } nextp; continue; } if (! intag) { if (!strncmp(p, "