home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <exec/io.h>
- #include <proto/exec.h>
-
-
- struct Cookie {
- struct Cookie *next;
- char *text;
- };
-
-
-
- struct Cookie *clist = NULL;
- char cbuf[20000]; /* large enough to hold one complete cookie */
- char line[1024]; /* large enough to hold the longest line */
-
-
-
- void read_cookies(FILE *fp)
- {
- fprintf(stderr,"reading cookies"); fflush(stderr);
- if (fp) {
- struct Cookie *i;
- long cbuflen;
- if (i = clist = AllocVec(sizeof(struct Cookie),MEMF_CLEAR)) {
- strcpy(cbuf,"");
- while (fgets(line,1024,fp)) {
- if (strcmp(line,"%%\n")==0) {
- cbuflen = strlen(cbuf)+1;
- if (i->text = AllocVec(cbuflen,0L)) {
- CopyMem(cbuf,i->text,cbuflen);
- }
- if (!(i->next = AllocVec(sizeof(struct Cookie),MEMF_CLEAR))) {
- struct Cookie *l,*nxt;
- for (l=clist; l; l=nxt) {
- nxt = l->next;
- FreeVec(l->text);
- FreeVec(l);
- }
- fprintf(stderr,"failed memory allocation\n");
- exit(20);
- }
- i = i->next;
- strcpy(cbuf,"");
- }
- else {
- strcat(cbuf,line);
- }
- }
- }
- }
- fprintf(stderr,", done.\n");
- }
-
-
-
- void write_cookies(FILE *fp)
- {
- fprintf(stderr,"writing cookies"); fflush(stderr);
- if (fp) {
- struct Cookie *l,*nxt=NULL;
- for (l=clist; l; l=nxt) {
- if (l->text) {
- fwrite(l->text,strlen(l->text),1,fp);
- fwrite("%%\n",3,1,fp);
- FreeVec(l->text);
- }
- nxt = l->next;
- FreeVec(l);
- }
- }
- fprintf(stderr,", done.\n");
- }
-
-
-
- void one_cookie(void)
- {
- struct Cookie *l,*i;
- long dbl = 0L;
- fprintf(stderr,"removing double entries"); fflush(stderr);
- for (l=clist; l; l=l->next) {
- if (l->text) {
- for (i=l->next; i; i=i->next) {
- if (i->text) {
- if (strcmp(l->text,i->text)==0) {
- FreeVec(i->text);
- i->text = NULL;
- ++dbl;
- }
- }
- }
- }
- }
- fprintf(stderr,", done. (%ld found)\n",dbl);
- }
-
-
-
- int main(int argc, char *argv[])
- {
- read_cookies(stdin);
- one_cookie();
- write_cookies(stdout);
- exit(0);
- }
-
-