//int maxtextbuffer = sizeof(char)*250;
//#define SIZE sizeof(char)*250
#define SIZE 255

int frequency(char *frequencytype) {
        FILE* fp;
	//char str[SIZE];
	//char str1[20] = "";
        int count = 0;
	int count2 = 0;
        char *cpu = "cpu";
	char *mem = "mem";
	char *net = "net";
	//printf( "TEST\n");
	//printf( "%s\n", frequencytype );
	//printf( "TEST\n");
        char buf[SIZE];
	char temp[10];
	char frequencystring[14];
        int line = 0;
	char *test;
        if( ( fp = fopen( "/etc/lsnet.conf", "r" ) ) == NULL ) {
                fprintf( stderr, "Error opening file.\n" );
                exit( 1 );
        }
	int i = strcmp( frequencytype, cpu );
	int j = strcmp( frequencytype, mem);
	int k = strcmp( frequencytype, net);
	//printf( "I:%d J:%d K:%d\n", i, j ,k );
	if (i == 0)
	{
		strcpy(frequencystring, "0");
        	while( fgets(buf, sizeof(buf), fp) != NULL)
        	{
			if (buf[count] == 'C'){
				if (buf[count+1] == 'P'){
					if (buf[count+2] == 'U'){
						if (buf[count+4] == 'P'){ //count+13 till end of buf is frequency
							if (buf[count+5] == 'O')
							{
								temp[0]=buf[13];
								strcpy(frequencystring, temp);
								for (count2 = 14; count2 <= strlen(buf) && buf[count2] != '\n' ; count2++)
								{
									temp[0]=buf[count2]; 
									temp[1]=0; 
									strcat(frequencystring,&temp);
								} 
							}
						}
					}
				}
			}
		}
	}

	if (j == 0)
        {
		strcpy(frequencystring, "0");
                while( fgets(buf, sizeof(buf), fp) != NULL)
                {
                	if (buf[count] == 'M'){
                        	if (buf[count+1] == 'E'){
                                	if (buf[count+2] == 'M'){
                                        	if (buf[count+4] == 'P'){ //MEM POLLING: 30
                                                	if (buf[count+5] == 'O')
							{
                                                        	temp[0]=buf[13];
                                                                strcpy(frequencystring, temp);
                                                                for (count2 = 14; count2 <= strlen(buf) && buf[count2] != '\n' ; count2++)
                                                                {
                                                                	temp[0]=buf[count2]; 
									temp[1]=0; 
									strcat(frequencystring,&temp);
                                                                }
                                                	}
                                        	}
                                	}
                        	}  
                        }
                }
        }

        if (k == 0)
        {
		strcpy(frequencystring, "0");
                while( fgets(buf, sizeof(buf), fp) != NULL)
                {
                        if (buf[count] == 'N'){
                                if (buf[count+1] == 'E'){
                                        if (buf[count+2] == 'T'){
                                                if (buf[count+4] == 'P'){ //count+13 till end of buf is frequency
                                                        if (buf[count+5] == 'O') 
                                                        {
                                                                temp[0]=buf[13];
                                                                strcpy(frequencystring, temp);
                                                                for (count2 = 14; count2 <= strlen(buf) && buf[count2] != '\n' ; count2++)
                                                                {
                                                                        temp[0]=buf[count2]; 
									temp[1]=0; 
									strcat(frequencystring,&temp);
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }




	//frequencystring
        fclose( fp );
	//puts(frequencystring );
	count = atoi(frequencystring);
	//printf( "%d\n", count );
	return count;
}
