<commit_before>#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include "logreader.h"
#include "SeqUtil.h"

/*log_node represents a line in a log file*/
typedef struct log_node {
  char *timestamp;
  char *seqnode;
  char *msgtype;
  char *seqmsg;
  char *seqloop;
  
  struct log_node *next;
} lognode;

/*keep these to retrieve the list*/
lognode *root_node = NULL;
lognode *current_node = NULL;

/*add node to linked list plus set root node if the list is empty*/
int addNode ( char *timestamp, char *seqnode, char *msgtype, char *seqloop, char *seqmsg ) {
   
  lognode *tmpptr = (lognode*)malloc(sizeof(lognode));
  if (tmpptr == NULL || timestamp == NULL) {
    return -1;
  }
  
  tmpptr->timestamp = timestamp;
  tmpptr->seqnode = seqnode;
  tmpptr->msgtype = msgtype;
  tmpptr->seqloop = seqloop;
  tmpptr->seqmsg = seqmsg;
  
  tmpptr->next=NULL;
  if (current_node != NULL) {
    current_node->next=tmpptr;
  }
  current_node=tmpptr;
  if (root_node == NULL) {
    root_node = tmpptr;
  }
  
  return 0;
}

/*remove old information of exp nodes from linked list,*/
/*not used on root exp nodes*/
int removeOldNodes (lognode *lastsubmit) {
  
  lognode *remove_iterator;
  lognode *last_known;
  
  if ((root_node == NULL) || (lastsubmit == NULL)) {
    return -1;
  }
  
  remove_iterator=root_node;
  
  while ((remove_iterator != NULL) && (remove_iterator != lastsubmit)) {
    last_known=remove_iterator;
    remove_iterator=remove_iterator->next;
    if ((strcmp(last_known->seqnode, lastsubmit->seqnode) == 0) && (strcmp(last_known->seqloop, lastsubmit->seqloop) == 0) && ((strncmp(last_known->msgtype, "abort", 5) != 0) && 
       (strncmp(last_known->msgtype, "info", 4) != 0) && (strncmp(last_known->msgtype, "event", 5) != 0) && (strncmp(last_known->msgtype, "init", 4) != 0) /*&& 
       (strncmp(last_known->msgtype, "abortx", 6) != 0) && (strncmp(last_known->msgtype, "endx", 4) != 0) && 
       (strncmp(last_known->msgtype, "beginx", 6) != 0) && (strncmp(last_known->msgtype, "infox", 5) != 0)*/) ) {
       SeqUtil_TRACE("removeOldNodes: removing %s %s\n", last_known->seqnode, last_known->seqloop);
       deleteNode(last_known);
    }
  }
  return 0;
}

/*delete a node from the list*/
int deleteNode (lognode *node) {
  
  lognode *todelete=NULL;
  lognode *prev=NULL;
  
  if ((root_node == NULL) || (node == NULL)) {
    return -1;
  }
  
  todelete=root_node;
  while((todelete != node) && (todelete->next != NULL)) {
    prev=todelete;
    todelete = todelete->next;
  }
  if(prev != NULL) {
    prev->next=todelete->next;
  }
  if (todelete == current_node) {
    prev->next=NULL;
    current_node=prev;
  } else if (todelete == root_node) {
    root_node = todelete->next;
  }
  
  free(todelete);
  todelete=NULL;
  
  return 0;
}

/*when the list is done, create the final output file*/
/*note that the linked list is deleted*/
int processList(const char* outputfile) {
  
  FILE *outFile;
  lognode *slowiterator=root_node, *fastiterator=root_node, *lastiterator; 
  char* tmpoutput=NULL;
  /*char tmpoutputline[1024];*/
  
  if(root_node == NULL) {
    return -1;
  }
  
  /*determine where to send the output*/
  if ( outputfile == NULL ) {
    tmpoutput="stdout";
  } else {
    outFile = fopen (outputfile,"w");
    if (outFile != NULL) {
      tmpoutput="outFile";
    }
    else {
      SeqUtil_TRACE("logreader: cannot open output file %s, sending output to stdout\n", outputfile);
      tmpoutput="stdout";
    }
  }
  
  SeqUtil_TRACE("logreader: processing log list, first node: %s\n", root_node->seqnode);
  
  /*write formatted log linked list to output stream*/
  while (slowiterator != NULL) {
    while (fastiterator != NULL) {
      if (strcmp(slowiterator->seqnode, fastiterator->seqnode) == 0) {
        if (strcmp(tmpoutput, "stdout") == 0) {
            fprintf(stdout, "\n%s!~!%s!~!%s!~!%s!~!%s", fastiterator->timestamp, fastiterator->seqnode, fastiterator->msgtype, fastiterator->seqloop, fastiterator->seqmsg);
        } else { 
            fprintf(outFile, "\n%s!~!%s!~!%s!~!%s!~!%s", fastiterator->timestamp, fastiterator->seqnode, fastiterator->msgtype, fastiterator->seqloop, fastiterator->seqmsg);
        }
      }
      lastiterator=fastiterator;
      fastiterator=fastiterator->next;
      if ((lastiterator != slowiterator) && (strcmp(slowiterator->seqnode, lastiterator->seqnode) == 0)) {
        deleteNode(lastiterator);
      }
    }
  
    slowiterator=slowiterator->next;
    fastiterator=slowiterator;<commit_msg>Fixed output of logreader to only output info, abort, event<commit_after>#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include "logreader.h"
#include "SeqUtil.h"

/*log_node represents a line in a log file*/
typedef struct log_node {
  char *timestamp;
  char *seqnode;
  char *msgtype;
  char *seqmsg;
  char *seqloop;
  
  struct log_node *next;
} lognode;

/*keep these to retrieve the list*/
lognode *root_node = NULL;
lognode *current_node = NULL;

/*add node to linked list plus set root node if the list is empty*/
int addNode ( char *timestamp, char *seqnode, char *msgtype, char *seqloop, char *seqmsg ) {
   
  lognode *tmpptr = (lognode*)malloc(sizeof(lognode));
  if (tmpptr == NULL || timestamp == NULL) {
    return -1;
  }
  
  tmpptr->timestamp = timestamp;
  tmpptr->seqnode = seqnode;
  tmpptr->msgtype = msgtype;
  tmpptr->seqloop = seqloop;
  tmpptr->seqmsg = seqmsg;
  
  tmpptr->next=NULL;
  if (current_node != NULL) {
    current_node->next=tmpptr;
  }
  current_node=tmpptr;
  if (root_node == NULL) {
    root_node = tmpptr;
  }
  
  return 0;
}

/*remove old information of exp nodes from linked list,*/
/*not used on root exp nodes*/
int removeOldNodes (lognode *lastsubmit) {
  
  lognode *remove_iterator;
  lognode *last_known;
  
  if ((root_node == NULL) || (lastsubmit == NULL)) {
    return -1;
  }
  
  remove_iterator=root_node;
  
  while ((remove_iterator != NULL) && (remove_iterator != lastsubmit)) {
    last_known=remove_iterator;
    remove_iterator=remove_iterator->next;
    
    if ((strcmp(last_known->seqnode, lastsubmit->seqnode) == 0) && (strcmp(last_known->seqloop, lastsubmit->seqloop) == 0) && (strcmp(last_known->msgtype, "abort") != 0) && 
       (strcmp(last_known->msgtype, "info") != 0) && (strcmp(last_known->msgtype, "event") != 0) && (strcmp(last_known->msgtype, "init") != 0)) {
       SeqUtil_TRACE("removeOldNodes: removing %s %s\n", last_known->seqnode, last_known->seqloop);
       deleteNode(last_known);
    }
  }  
  return 0;
}

/*delete a node from the list*/
int deleteNode (lognode *node) {
  
  lognode *todelete=NULL;
  lognode *prev=NULL;
  
  if ((root_node == NULL) || (node == NULL)) {
    return -1;
  }
  
  todelete=root_node;
  while((todelete != node) && (todelete->next != NULL)) {
    prev=todelete;
    todelete = todelete->next;
  }
  if(prev != NULL) {
    prev->next=todelete->next;
  }
  if (todelete == current_node) {
    prev->next=NULL;
    current_node=prev;
  } else if (todelete == root_node) {
    root_node = todelete->next;
  }
  
  free(todelete);
  todelete=NULL;
  
  return 0;
}

/*when the list is done, create the final output file*/
/*note that the linked list is deleted*/
int processList(const char* outputfile) {
  
  FILE *outFile;
  lognode *slowiterator=root_node, *fastiterator=root_node, *lastiterator; 
  char* tmpoutput=NULL;
  /*char tmpoutputline[1024];*/
  
  if(root_node == NULL) {
    return -1;
  }
  
  /*determine where to send the output*/
  if ( outputfile == NULL ) {
    tmpoutput="stdout";
  } else {
    outFile = fopen (outputfile,"w");
    if (outFile != NULL) {
      tmpoutput="outFile";
    }
    else {
      SeqUtil_TRACE("logreader: cannot open output file %s, sending output to stdout\n", outputfile);
      tmpoutput="stdout";
    }
  }
  
  SeqUtil_TRACE("logreader: processing log list, first node: %s\n", root_node->seqnode);
  
  /*write formatted log linked list to output stream*/
  while (slowiterator != NULL) {
    while (fastiterator != NULL) {
      if (strcmp(slowiterator->seqnode, fastiterator->seqnode) == 0) {
        if (strcmp(tmpoutput, "stdout") == 0) {
            fprintf(stdout, "%s!~!%s!~!%s!~!%s!~!%s\n", fastiterator->timestamp, fastiterator->seqnode, fastiterator->msgtype, fastiterator->seqloop, fastiterator->seqmsg);
        } else { 
            fprintf(outFile, "%s!~!%s!~!%s!~!%s!~!%s\n", fastiterator->timestamp, fastiterator->seqnode, fastiterator->msgtype, fastiterator->seqloop, fastiterator->seqmsg);
        }
      }
      lastiterator=fastiterator;
      fastiterator=fastiterator->next;
      if ((lastiterator != slowiterator) && (strcmp(slowiterator->seqnode, lastiterator->seqnode) == 0)) {
        deleteNode(lastiterator);
      }
    }
  
    slowiterator=slowiterator->next;
    fastiterator=slowiterator;
{'fraction_non_alphanumeric': 0.15424395727937043, 'fraction_numerical': 0.005845980888139404, 'mean_word_length': 3.515736040609137, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1725510', 'n_tokens_mistral': 3182, 'n_tokens_neox': 3156, 'n_words': 720}