<commit_before>// Copyright (c) 2012, 2013 <NAME> - see LICENSE for further details

#include <boost/format.hpp>
#include <boost/regex.hpp>

#include "vpi_user.h"
#include "exm_python.h"
#include "message.h"

int exm_python_vpi(char* arg) {
  vpiHandle href;
  vpiHandle arglist;
  s_vpi_value vpi_value;

  href = vpi_handle(vpiSysTfCall, 0);
  arglist = vpi_iterate(vpiArgument, href);
  vpi_value.format = vpiStringVal;
  vpi_get_value(vpi_scan(arglist), &vpi_value);

  return exm_python(vpi_value.value.str);
}

int exm_message(char* level, ...) {
  vpiHandle href;
  vpiHandle arglist;
  vpiHandle arg;
  s_vpi_value vpi_value;
  const char *result;
  va_list args;
  boost::format tmpl;

  // regexp stuff
  static boost::regex fmt("%(-?[0-9\056]+)?([defms])", boost::regex::extended);
  static boost::regex mod("%m", boost::regex::extended);

  href = vpi_handle(vpiSysTfCall, 0);
  arglist = vpi_iterate(vpiArgument, href);
  vpi_value.format = vpiStringVal;
  if (arg=vpi_scan(arglist)) {
    vpi_get_value(arg, &vpi_value);
  } else {
    WARNING("Message has no arguments");
    result = "** No Message Given **";
    goto emit;
  }

  {

  boost::cregex_iterator re_match(vpi_value.value.str, vpi_value.value.str+strlen(vpi_value.value.str), fmt);
  boost::cregex_iterator end;

  // now replace %m with %s for format
  std::string fmt_str(boost::regex_replace(std::string(vpi_value.value.str), mod, "%s"));

  try {
    tmpl.parse(fmt_str);
  } catch (boost::io::bad_format_string& exc) {
    WARNING("Format raised %s", exc.what());
    result = "** Format Failed **";
    goto emit;
  }

  // now iterate over remaining arguments
  while (arg=vpi_scan(arglist)) {
  again:
    char fident;
    if (re_match != end) {
      fident = *(*re_match)[(*re_match).size()-1].first;
      re_match++;
      switch (fident) {
      case 'd' : vpi_value.format = vpiIntVal; break;
      case 'm' : goto insert;
      case 's' : vpi_value.format = vpiStringVal;
      }
    } else {
      WARNING("Not enough");
      goto emit;
    }
    vpi_get_value(arg, &vpi_value);
  insert:
    try {
      switch (fident) {
      case 'd' : tmpl % vpi_value.value.integer; break;
      case 'm' : {
        vpiHandle scope = vpi_handle(vpiScope, href);
        tmpl % vpi_get_str(vpiFullName, scope); 
        break;
      }
      case 's' : tmpl % vpi_value.value.str;
      }
    } catch (boost::io::too_many_args& exc) {
      WARNING(exc.what());
      goto emit;
    }
    if (fident == 'm') goto again;
  }

  try {
    result = tmpl.str().c_str();<commit_msg>base expected args on format string<commit_after>// Copyright (c) 2012, 2013 <NAME> - see LICENSE for further details

#include <boost/format.hpp>
#include <boost/regex.hpp>

#include "vpi_user.h"
#include "exm_python.h"
#include "message.h"

int exm_python_vpi(char* arg) {
  vpiHandle href;
  vpiHandle arglist;
  s_vpi_value vpi_value;

  href = vpi_handle(vpiSysTfCall, 0);
  arglist = vpi_iterate(vpiArgument, href);
  vpi_value.format = vpiStringVal;
  vpi_get_value(vpi_scan(arglist), &vpi_value);

  return exm_python(vpi_value.value.str);
}

int exm_message(char* level, ...) {
  vpiHandle href;
  vpiHandle arglist;
  vpiHandle arg;
  s_vpi_value vpi_value;
  const char *result;
  va_list args;
  boost::format tmpl;

  // regexp stuff
  static boost::regex fmt("%(-?[0-9\056]+)?([defhimosx])", boost::regex::extended);
  static boost::regex mod("%[bhm]", boost::regex::extended);

  href = vpi_handle(vpiSysTfCall, 0);
  arglist = vpi_iterate(vpiArgument, href);
  vpi_value.format = vpiStringVal;
  if (arg=vpi_scan(arglist)) {
    vpi_get_value(arg, &vpi_value);
  } else {
    WARNING("Message has no arguments");
    result = "** No Message Given **";
    goto emit;
  }

  {

  boost::cregex_iterator re_match(vpi_value.value.str, vpi_value.value.str+strlen(vpi_value.value.str), fmt);
  boost::cregex_iterator end;

  // now replace %m with %s for format
  std::string fmt_str(boost::regex_replace(std::string(vpi_value.value.str), mod, "%s"));

  try {
    tmpl.parse(fmt_str);
  } catch (boost::io::bad_format_string& exc) {
    WARNING("Format raised %s", exc.what());
    result = "** Format Failed **";
    goto emit;
  }

  // now iterate over remaining arguments
  for (; re_match != end; re_match++) {
    char fident = *(*re_match)[(*re_match).size()-1].first;
    switch (fident) {
      case 'b' : vpi_value.format = vpiBinStrVal; break;
      case 'h' : vpi_value.format = vpiHexStrVal; break;
      case 'e' :
      case 'f' : vpi_value.format = vpiRealVal; break;
      case 'i' :
      case 'o' :
      case 'x' :
      case 'd' : vpi_value.format = vpiIntVal; break;
      case 'm' : goto insert;
      case 's' : vpi_value.format = vpiStringVal; break;
    }
    if (!(arg=vpi_scan(arglist))) {
      WARNING("Not enough vpi arguments");
      goto emit;
    }
    vpi_get_value(arg, &vpi_value);
  insert:
    try {
      switch (fident) {
        case 'i' :
        case 'x' :
        case 'o' :
        case 'd' : tmpl % vpi_value.value.integer; break;
        case 'm' : {
          vpiHandle scope = vpi_handle(vpiScope, href);
          tmpl % vpi_get_str(vpiFullName, scope);
          vpi_free_object(scope);
          break;
        }
        case 'b' :
        case 'h' :
        case 's' : tmpl % vpi_value.value.str;
      }
    } catch (boost::io::too_many_args& exc) {
      WARNING(exc.what());
      goto emit;
    }
  }

  try {
    result = tmpl.str().c_str();
{'fraction_non_alphanumeric': 0.14925100474972597, 'fraction_numerical': 0.005845816587504567, 'mean_word_length': 3.1351963746223563, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5576943', 'n_tokens_mistral': 2113, 'n_tokens_neox': 2046, 'n_words': 431}