/* Extraction of redirections */ #include #include #include #include #include #ifndef NULL #define NULL 0 #endif typedef int bool; #define TRUE 1 #define FALSE 0 typedef signed long longint; typedef unsigned long longword; typedef unsigned short word; typedef unsigned char byte; #define MALLOC(t) (t*)malloc(sizeof(t)) #define MALLOC_N(N,T) (T *)malloc((N)*sizeof(T)) #define STR_MALLOC(N) (char *)malloc(N+1) #define REALLOC_N(A,N,T) (T *)realloc(A, (N)*sizeof(T)) #define STRCPY(D,S) D = (char *)malloc(strlen(S)+1); strcpy(D,S) typedef struct redirect_t { char *from; char *to; struct redirect_t *next; bool isdest; bool toself; } redirect_t; redirect_t *redirects[1000]; int nr_redirects; main() { char buffer[10000]; char *start_title = "

List of redirected URLs

";
	char *start_from = "from = from;
		redirects[nr_redirects]->to = to;
		redirects[nr_redirects]->next = NULL;
		redirects[nr_redirects]->isdest = FALSE;
		redirects[nr_redirects]->toself = !strcmp(from, to);
		nr_redirects++;		
 		gets(buffer);
 		gets(buffer);
 		gets(buffer);
 		gets(buffer);
 		s = buffer;
	}
	
	// Do the redirecting
	{	
		int i,j;
		for (i = 0; i < nr_redirects; i++)
		{
			redirect_t *ri = redirects[i];
			
			for (j = 0; j < nr_redirects; j++)
				if (i != j)
				{
					redirect_t *rj = redirects[j];
					
					if (!strcmp(ri->to, rj->from))
					{
						ri->next = rj;
						rj->isdest = TRUE;
					}
				}
		}
	}
	
	{
		int i;
		
		for(i = 0; i < nr_redirects; i++)
		{
			redirect_t *next;
			printf("%d %d %d %s -> %s", i,
				   redirects[i]->toself, redirects[i]->isdest,
			       redirects[i]->from, redirects[i]->to);
			next = redirects[i]->next;
			while (next)
			{
				printf(" => %s", next->to);
				next = next->next;
			}
			printf("\n");
		}  
	}

	printf("\n\n");	
	{
		int i;
		
		for(i = 0; i < nr_redirects; i++)
		{
			redirect_t *r = redirects[i];
			
			if (!r->toself && !r->isdest)
			{
				printf("%s\t", r->from);
				
				while (r->next && !strncmp(r->next->to, "http", 4))
					r = r->next;
				printf("%s\n", r->to);
			}
		}  
	}
	

	printf("%s", buffer);
}