/**************************************************************** File Name: extract1.cpp Executable: extract.exe (to be stored in the internal file) Author: Sameen Rehman Date: March 14,2005 Contact: sameen@ieee.org This code can be modified if necessary. ******************************************************************/ #include #include #include #include #include int main(int argc, char*argv[]) { char *sinqb; char *checkb; char *output; int i,j,c,l,maxi,maxj,index,spacecount; bool fmtSinqbOn=false; char* b; char* t; char* temp; sinqb = (char*) malloc(5000); checkb= (char*) malloc(5000); output= (char*) malloc(5000); temp= (char*) malloc(5000); sinqb[0]=0;//characters stored here checkb[0]=0; c=10000; //max limit of characters searched for in the file, used in getline if (argc<5) { cout << "No se especifico archivo o celda. Indique extraer [archivo] [cellpos(0)] [cellpos(1)]" << "\n"; cout << "Example: extract file.drw 8 25 > cell8_25.csv" << endl; cout.flush(); exit(1); } i=atoi(argv[2]);//x value j=atoi(argv[3]);//y value ifstream sinq; ifstream check; sinq.open(argv[1]); sinq.getline(sinqb,c,'\n'); //************************************************************************** //this part checks whether max values were exceeded check.open(argv[1]); check.getline(checkb,c,'\n'); check.getline(checkb,c,'\n');//checkb = 0123456.... //t=strtok(checkb,"1"); t = strtok(checkb," ");//t =0123456.... if(strstr(t,"7890123")!=0){ l=1; } else { t = strtok(0,"1"); l = strlen(t)+1;//l is the gap between two units on the window } check.getline(checkb,c,'\n');//checkb=+-----------------+ check.getline(checkb,c,'\n'); strtok(checkb,"|"); t=strtok(0,"|"); if(l==17)maxi=(strlen(t)-2)/2;//when width = 2, l = 17(this should be modified) if(l==1) maxi=(strlen(t)/2) - 1;//no gap if(l>1 && l!=17)maxi=(strlen(t)-l-1)/(l+1); check.getline(checkb,c,'\n'); while(strstr(checkb,"|")!=0){ t=strtok(checkb,"|"); maxj=atoi(t); check.getline(checkb,c,'\n'); } if(i>maxi || j>maxj){ if(i>maxi) cout<<"X value exceeds max value extracted from drawlog file."<<"\n"; if(j>maxj) cout<<"Y value exceeds max value extracted from drawlog file."<<"\n"; cout.flush(); //so this is the last window of the file. sinq.close(); //once you reach the last window, exit. check.close(); free(sinqb); free(checkb); free(temp); free(output); exit(0); } //************************************************************************** cout << "Values extracted from file: " << argv[1] << " Cell=(" << argv[2] << ":" << argv[3] <<")\n"; cout.flush(); if (strlen(sinqb)==0 || strcmp(sinqb, " ")==0) sinq.getline(sinqb,c,'\n'); if (strstr(sinqb,"Time")!=0) fmtSinqbOn=true; do{ if(strstr(argv[4],"-u")!=0){ if (fmtSinqbOn) { b=strtok(sinqb," ");//cutting through the string: Line : 840 - Time: 00:00:00:000 b=strtok(0,"-");//Time: 00:00:00:000 b=strtok(0,":");// 00:00:00:000 b=strtok(0," ");//b=00:00:00:000 b[strlen(b)-1] = '\0'; cout<0){ for(int n=0;n= 3 if(i>=0 && l!=1 && l!=17){ //if i>0 and width is greater than 2, there are gaps between cells. strncpy(output,b, (i*(l+1)+(l+1))); for(int count= 0;count=i*(l+1)) && (count<=i*(l+1)+l))) output[count] = '\0'; } index=0; spacecount=0; for(int n=0;n<(l+1);n++) { if(output[i*(l+1)+n]!=' '){ output[index] = output[i*(l+1)+n]; //cout<<"index: "<=0 && l==1){ //if i>0, and there are no gaps between cells. if(b[i]==' '){ output[0]= '0'; } else { strncpy(output,b,i+1); if(i!=0){ for(int count= 0;count=0 && l==17){ strncpy(output,b, (i*(2)+(2))); for(int count= 0;count=i*(2)) && (count<=i*(2)+1))) output[count] = '\0'; } index=0; spacecount=0; for(int n=0;n<(2);n++) { if(output[i*(2)+n]!=' '){ output[index] = output[i*(2)+n]; //cout<<"index: "<