<commit_before>/*DEBUGGER FOR BLINKY BLOCK SIMULATOR*/

#include <string.h>
#include <pthread.h>
#include <iostream>
#include <sstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "debug_Simprompt.hpp"
#include "debug_Simhandler.hpp"
#include "serialization.hpp"
#include "types.hpp"
#include "blinkyBlocksVM.h"
#include <list>

using namespace std;
using namespace debugger;


namespace debugger {

#define SIZE (sizeof(message_type))
#define BROADCAST true

    /*****************************************************************/

    /*GLOBAL STORED VARS*/

    /****************************************************************/

    ConcurrentQueue<message_type*> *messageQueue;
    /*global variables to controll main thread*/
    static bool isSystemPaused = true;
    static bool isDebug = false;
    static bool isSimDebug = false;
    static bool isPausedAtBreakpoint = false;
	static bool okayToBroadcastPause = true;

    static bool okayToPauseSimulation = false;

    static bool printLimitation = true;
    static bool okayToPrint = true;

    /*number of messages the Master expects to recieve*/
    int numberExpected = 0;

    bool verboseMode = false;
    bool serializationMode = false;

    /*cache ...rcvMessageList holds containters for
     * different lists of broken messages*/
    std::list<struct msgListContainer*>* rcvMessageList;

    /*BROKEN UP MESSAGE CONTAINERS TO BE STORED IN CACHE*/

    /*rcvMessageList Elems -- contains a list that holds incoming messages
     * from a certain node*/
    struct msgListContainer {
        int instruction;
        int node;
        std::list<struct msgListElem*>* msglist;
    };

    /*msgListElems -- holds the information necessary to reconstruct the
     * the message*/
    struct msgListElem{
        int priority;
        string content;
    };


    /**********************************************************************/

    /* I/0 SPECIFICATION PARSING - extract the different parts of
     * a specification format*/

    /*********************************************************************/


    /*CHARACTER IN STRING INDEX -- returns the index of a character in a string,
     *if it is not there it returns -1*/
    int characterInStringIndex(string str, char character){
        for(unsigned int i = 0; i < str.length(); i++){
            if (str[i] == character)
                return (int)i;
        }
        return -1;
    }


    /*GET TYPE -- extracts the type from the specification from input line
     *returns the type of breakpoint from the specification
     *invariant-- the type is always specified*/
    string getType(string specification){
        string build = "";
        for (unsigned int i = 0; i < specification.length(); i++){
            if(specification[i] == ':' || specification[i] == '@')
                return build;
            else
                build += specification[i];
        }
        return build;
    }


    /*GET NAME -- extracts the name from the specification
     *returns the name from the specification
     *returns "" if name is not present*/
    string getName(string specification){
        string build = "";
        //find index of colon
        int index = characterInStringIndex(specification, ':');
        // if colon not there
        if (index == -1)
            return "";
        for (unsigned int i = index +1;
             i < specification.length(); i++){
            if (specification[i] == '@')
                return build;
            else
                build += specification[i];
        }
        return build;
    }


    /*GET NODE -- extracts the node from the specification
     *returns the node from the specification
     *returns "" if node is not given*/
    string getNode(string specification){
        string build = "";
        int index = characterInStringIndex(specification, '@');
        if (index == -1)
            return "";
        for (unsigned int i = index+1; i < specification.length(); i++){
            build+=specification[i];
        }
        return build;
    }

    /*TYPE INT TO STRING -- given the encoding return
     *  the corresponding string for
     *  break point types*/
    string typeInt2String(int type){
        switch(type){
            case FACTDER:
                return "factDer";
            case FACTCON:
                return "factCon";
            case FACTRET:
                return "factRet";
            case ACTION:
                return "action";
            case SENSE:
                return "sense";
            case BLOCK:
                return "block";
        }
        return "";
    }

    /**********************************************************************/

    /*SIMULATION DEBUGGING FUNCTIONS*/

    /*********************************************************************/


    /*SETFLAGS -- switch to different debugging modes based on user input*/
   void setFlags(string specification){
        ostringstream msg;
        for (int i = 0; i < specification.length(); i++){
            if ((uint)specification[i] == 'V'){
                verboseMode = true;
            } else if ((uint)specification[i] == 'S'){
                serializationMode = true;
            }
        }
    }


    /*HANDLE PAUSE COMMAND -- broadcast a pause message to all VMs
     *  -used when the user presses P for a runnung system*/
    void handlePauseCommand(void){

        sendMsg(-1,PAUSE,"",BROADCAST);
        okayToBroadcastPause = false;<commit_msg>fixed type<commit_after>/*DEBUGGER FOR BLINKY BLOCK SIMULATOR*/

#include <string.h>
#include <pthread.h>
#include <iostream>
#include <sstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "debug_Simprompt.hpp"
#include "debug_Simhandler.hpp"
#include "serialization.hpp"
#include "types.hpp"
#include "blinkyBlocksVM.h"
#include <list>

using namespace std;
using namespace debugger;


namespace debugger {

#define SIZE (sizeof(message_type))
#define BROADCAST true

    /*****************************************************************/

    /*GLOBAL STORED VARS*/

    /****************************************************************/

    ConcurrentQueue<message_type*> *messageQueue;
    /*global variables to controll main thread*/
  static bool isSystemPaused = true;
    static bool isDebug = false;
    static bool isSimDebug = false;
    static bool isPausedAtBreakpoint = false;
	static bool okayToBroadcastPause = true;

    static bool okayToPauseSimulation = false;

    static bool printLimitation = true;
    static bool okayToPrint = true;

    /*number of messages the Master expects to recieve*/
    int numberExpected = 0;

    bool verboseMode = false;
    bool serializationMode = false;

    /*cache ...rcvMessageList holds containters for
     * different lists of broken messages*/
    std::list<struct msgListContainer*>* rcvMessageList;

    /*BROKEN UP MESSAGE CONTAINERS TO BE STORED IN CACHE*/

    /*rcvMessageList Elems -- contains a list that holds incoming messages
     * from a certain node*/
    struct msgListContainer {
        int instruction;
        int node;
        std::list<struct msgListElem*>* msglist;
    };

    /*msgListElems -- holds the information necessary to reconstruct the
     * the message*/
    struct msgListElem{
        int priority;
        string content;
    };


    /**********************************************************************/

    /* I/0 SPECIFICATION PARSING - extract the different parts of
     * a specification format*/

    /*********************************************************************/


    /*CHARACTER IN STRING INDEX -- returns the index of a character in a string,
     *if it is not there it returns -1*/
    int characterInStringIndex(string str, char character){
        for(unsigned int i = 0; i < str.length(); i++){
            if (str[i] == character)
                return (int)i;
        }
        return -1;
    }


    /*GET TYPE -- extracts the type from the specification from input line
     *returns the type of breakpoint from the specification
     *invariant-- the type is always specified*/
    string getType(string specification){
        string build = "";
        for (unsigned int i = 0; i < specification.length(); i++){
            if(specification[i] == ':' || specification[i] == '@')
                return build;
            else
                build += specification[i];
        }
        return build;
    }


    /*GET NAME -- extracts the name from the specification
     *returns the name from the specification
     *returns "" if name is not present*/
    string getName(string specification){
        string build = "";
        //find index of colon
        int index = characterInStringIndex(specification, ':');
        // if colon not there
        if (index == -1)
            return "";
        for (unsigned int i = index +1;
             i < specification.length(); i++){
            if (specification[i] == '@')
                return build;
            else
                build += specification[i];
        }
        return build;
    }


    /*GET NODE -- extracts the node from the specification
     *returns the node from the specification
     *returns "" if node is not given*/
    string getNode(string specification){
        string build = "";
        int index = characterInStringIndex(specification, '@');
        if (index == -1)
            return "";
        for (unsigned int i = index+1; i < specification.length(); i++){
            build+=specification[i];
        }
        return build;
    }

    /*TYPE INT TO STRING -- given the encoding return
     *  the corresponding string for
     *  break point types*/
    string typeInt2String(int type){
        switch(type){
            case FACTDER:
                return "factDer";
            case FACTCON:
                return "factCon";
            case FACTRET:
                return "factRet";
            case ACTION:
                return "action";
            case SENSE:
                return "sense";
            case BLOCK:
                return "block";
        }
        return "";
    }

    /**********************************************************************/

    /*SIMULATION DEBUGGING FUNCTIONS*/

    /*********************************************************************/


    /*SETFLAGS -- switch to different debugging modes based on user input*/
   void setFlags(string specification){
        ostringstream msg;
        for (uint i = 0; i < specification.length(); i++){
            if ((uint)specification[i] == 'V'){
                verboseMode = true;
            } else if ((uint)specification[i] == 'S'){
                serializationMode = true;
            }
        }
    }


    /*HANDLE PAUSE COMMAND -- broadcast a pause message to all VMs
     *  -used when the user presses P for a runnung system*/
    void handlePauseCommand(void){

        sendMsg(-1,PAUSE,"",BROADCAST);
        okayToBroadcastPause = false;
{'fraction_non_alphanumeric': 0.16633520159103235, 'fraction_numerical': 0.002350388718134153, 'mean_word_length': 2.3043608124253288, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 27, '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': '4823742', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2742, 'n_words': 942}