#include        "web.h"
#include 	<stdio.h>
#include 	<stdlib.h>
#include 	<fcntl.h>

#define size_table 2

char list[size_table][500];
char *table[size_table] = {
"s1","q1"
};
              

#define size_url 8
char *url[size_url] = {
"search.yahoo.com/bin/search?p=",
"altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=&q=",
"www.lycos.com/cgi-bin/pursuit?query=",
"www2.infoseek.com/Titles?qt=",
"search.excite.com/search.gw?trace=a&search=",
"www.search.hotbot.com/hResult.html/?MT=",
"webcrawler.com/cgi-bin/WebQuery?",
"www.mckinley.com/search.gw?search="
};
              

main(int argc, char *argv[] )
{
	int i;

 	get_list_data();
	
   for( i = 0 ; i < size_url ; i++ ){
     if( list[0][0] == '1'+i ){
	printf("Location: http://%s%s\n\n",url[i],list[1]);
	break;
     }
   }

    if( i = size_url ){
	printf ( "Content-type: text/html%c%c", 10, 10 ) ;                
	printf("ERR");
    }
}


get_list_data()
{
        register        int     x, m = 0 ;
        postentry     entries[100] ;        /* name value pairs         */
        int i;
        m = ProcessPostMethod(entries);

        for( x = 0 ; x < size_table ; x++ )
                list[x][0] = 0;

        for ( x = 0 ; x <= m ; x++ ) {
             for( i = 0 ; i < size_table ; i++ ){
                if ( !strcmp(entries[x].name,table[i])) {
                        if( strlen(entries[x].val ) > 1000 )
                                strncpy( list[i],entries[x].val,1000 );
                        else
                                strcpy ( list[i],entries[x].val );
                        /*
                        if( list[i][0] == 0 )
                                strcpy( list[i],"Empty");
                        */
                        break;
                }
             }
        }
}
