/*  This file is part of lsnet.

    Lsnet is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Lsnet is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with lsnet.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

int main(int argc, char **argv) {
	FILE* fp1;
	FILE* fp2;
	int i, j;
	int count = 0; 
	int proceed = 0;
	int die = 0;
	int line = 0;
	int empty;

	int count20 = 1;
	char temp[10];
	char buf[SIZE];
	char filestr[SIZE];

        if(argc != 2){
                printf("Error, incorrect usage!\n\n");

                //usage();
                return 0;
        }


        for(i=0;i<argc;i++)
        {
                if(i==1){
                        empty = sprintf(filestr, "%s", argv[i]);
                }

        }



	if( ( fp1 = fopen( filestr, "r" ) ) == NULL ) {
		fprintf( stderr, "Error opening file.\n" );
		exit( 1 );
	}

        while( fgets(buf, sizeof(buf), fp1) != NULL)
        {
	
		if (buf[count] == 'X' && die != 1){
			//if (buf[count+1] == 'D'){
				//if (buf[count+2] == 'J'){
					//if (buf[count+3] == '0' || buf[count+3] == '1' || buf[count+3] == '2' || buf[count+3] == '3' || 
					//	buf[count+3] == '4' || buf[count+3] == '5' || buf[count+3] == '6' || buf[count+3] == '7' 
					//		|| buf[count+3] == '8' || buf[count+3] == '9'){
						proceed=1;

				//}
			//}
		}
		line++;


		//Help
/*
                if (buf[count] == 'H'){
                        if (buf[count+1] == 'e'){
                                if (buf[count+2] == 'l'){
                                	if (buf[count+3] == 'p'){
						proceed=0;
					}
        
                                }
                        } 
                }
*/


		if (proceed == 1 && die == 0){
			if (buf[count] == ' '){
				if (buf[count+1] == ' '){
					if (buf[count+2] == ' '){
						if (buf[count+3] == '['){
							//for(i=4; i<7; i++){
								for ( i=4; buf[count+i] == '0' || buf[count+i] == '1' || buf[count+i] == '2' || 
buf[count+i] == '3' || buf[count+i] == '4' || buf[count+i] == '5' || buf[count+i] == '6' || buf[count+i] == '7' || buf[count+i] == '8' || 
buf[count+i] == '9'; i++)
								{
									proceed=0;
								}
							//}
								//i++;
							//printf("success\n");

						if (buf[count+i] == ']'){

                if (buf[count+i+1] == 'H'){
                        if (buf[count+i+2] == 'e'){
                                if (buf[count+i+3] == 'l'){
                                        if (buf[count+i+4] == 'p'){
                                               die=1;
                                        }
                                                           
                                }
                        }
                }






							if(proceed == 0 && die == 0)
							{
								
								//printf("success\n");	
					
								//if (buf[count+i] == ']'){
									j=0;
									i++;
									while(buf[count+i] != ' '){
										temp[j]=buf[count+i];
										j++;
										i++;	
									}
									temp[j]='\0';

									if(count20 < 20){
										printf("ASX:%s ", temp);
										count20++;
									}else if(count20 > 19){
										printf("ASX:%s\n", temp);
										count20 = 1;
									}

									proceed=1;
								//}
							}



							}

						}
					
					}
				}
			}
		}


	}
	//printf( "NUMBER OF CORES: %d\n", coresdetected );

//printf("success\n");
	fclose( fp1 );
	//exit (0);
	return 0;
}
