#include #include # define MAXLENGTH 500 int removeChar(char *temp, char rem); int removeTrailingChar(char *temp,char trail); void parsePDPLog(char *,char *); int main(int argc, char **argv){ char command[100]; if(argc!=3) { printf("Usage: \n"); exit(0); } if(strcmp(argv[1],"-h")==0){ printf("Usage: \n"); exit(0); } parsePDPLog(argv[1],"octavetemp"); strcpy(command,"./parsePDPlog.pl octavetemp "); strcat(command,argv[2]); system(command); system("octave"); } void parsePDPLog(char *in,char *out){ FILE *input; FILE *output; int i,datacount,j,rows,cols,num; char str_buffer[256],*temp,**token,*ret,temp_buffer[256],temp1[2],*temp2; float **data,crap; datacount = -1; input = fopen(in,"r"); if(input == NULL) { printf("File \"%s\" cannot be opened. Program quitting...\n",in); exit(1);} output = fopen(out,"w"); if(output == NULL){ printf("File \"%s\" cannot be opened. Program quitting...\n",out); exit(1); } temp = (char *)malloc(sizeof(char) * 50); temp2 = (char *)malloc(sizeof(char) * 50); do{ /*first get line-type indicator*/ ret= fgets(str_buffer,4,input); if(strcmp(str_buffer,"_H:")==0){ /*header tokenzie str_buffer*/ ret= fgets(str_buffer,256,input); removeTrailingChar(str_buffer,'\n'); strncpy(temp_buffer,str_buffer,strlen(str_buffer)+1); i=0; temp = (char *)strtok(str_buffer,"\t"); do{ temp =(char *) strtok(NULL,"\t"); i++; }while(temp!=NULL); token = (char **)malloc(sizeof(char *)*(i+1)); temp = (char *)strtok(temp_buffer,"\t"); i=0; do{ if(temp==NULL) break; removeChar(temp, '&'); removeChar(temp,'|'); removeChar(temp,'$'); removeChar(temp,'.'); if(temp[0] == '<' && temp[2]=='>'){ removeChar(temp,'<'); removeChar(temp,'>'); temp1[0] = temp[0]; temp1[1] = 0; removeChar(temp,temp1[0]); strcat(temp,temp1); } removeChar(temp,'<'); removeChar(temp,'>'); token[i] = (char *)malloc(sizeof(char)*50); strncpy(token[i],temp,strlen(temp)); temp =(char *) strtok(NULL,"\t"); i++; }while(temp!=NULL); token[i] = NULL; fprintf(output,"%s","_H: "); for(i=0;token[i]!=NULL;i++){ fprintf(output,"%s ",token[i]); } fprintf(output,"\n"); } // end of header check else { if(strcmp(str_buffer,"_D:")==0){ fprintf(output,"%s","_D: "); datacount++; // for each row of data ret = fgets(str_buffer,256,input); // get rest of data removeTrailingChar(str_buffer,'\n'); strncpy(temp_buffer,str_buffer,strlen(str_buffer)+1); temp = (char *)strtok(str_buffer,"\t"); do{ if(temp!=NULL){ fprintf(output,"%s ",temp); } temp = (char *)strtok(NULL,"\t"); }while(temp!=NULL); fprintf(output,"\n"); }// end of this row of data } // end of else }while(ret != NULL); fclose(output); fclose(input); } int removeTrailingChar(char *temp,char trail){ char *ret_ch; if(temp == NULL) return 1; ret_ch = (char *)strchr((char *)temp,trail); //character found if(ret_ch!=NULL){ if(temp[strlen(temp)-1] == trail) //last character temp[strlen(temp)-1] = '\0'; } return 0; } int removeChar(char *temp, char rem){ char *ret_ch,buffer[250]; int i,j; if(temp==NULL) return 1; ret_ch = (char *)buffer; for(i=0,j=0;i