<commit_before>/*
 * Copyright (c) 2007, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * Sat solver application layer
 *
 * Helper functions
 *
 */

#include <stdarg.h>
#include <stdlib.h>
#include "applayer.h"

/************************************************
 * string handling
 *
 */

/* helper for string representation, snprintf + strdup */

char *to_string(const char *format, ...)
{
  char buf[2048];
  va_list args;
  va_start(args, format);
  vsnprintf(buf, sizeof(buf), format, args);
  return strdup(buf);
}

struct debugdata {
  Pool *pool;
  int debugmask;
  char *buf;
  int length;
};

static struct debugdata dd;

static void
app_debugcallback(struct _Pool *p, void *data, int type, const char *str)
{
  struct debugdata *ddp = (struct debugdata *)data;
  int len = strlen(str);
  ddp->buf = realloc(ddp->buf, ddp->length + len + 1);
  if (ddp->length == 0) *ddp->buf = 0;
  strcat(ddp->buf, str);
  ddp->length += len;
}

void
app_debugstart(Pool *p, int type)
{
  dd.buf = NULL;
  dd.length = 0;
  dd.debugmask = p->debugmask;
  p->debugmask = type;
  p->debugcallback = app_debugcallback;
  p->debugcallbackdata = &dd;
  dd.pool = p;
}

char *
app_debugend()
{
  dd.pool->debugcallback = NULL;
  dd.pool->debugmask = dd.debugmask;
  return dd.buf;
}

/************************************************
 * Id
 *
 */

const char *
my_id2str( const Pool *pool, Id id )
{
  if (id == STRID_NULL)
    return NULL;
  if (id == STRID_EMPTY)
    return "";
  return id2str( pool, id );
}

/************************************************
 * Pool
 *
 */

unsigned int
pool_xsolvables_count( const Pool *pool )
{
  const Solvable *s;
  Id p;
  int count = 0;
  /* skip Id 0 since it is reserved
   * skip Id 1 since it is the system solvable and not
   *   accessible to the outside
   */
  for (p = 2, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
    {
      if (!s)
	continue;
      if (!s->name)
        continue;
      ++count;
    }
  
  return count;<commit_msg>id2str changed signature in the past<commit_after>/*
 * Copyright (c) 2007, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * Sat solver application layer
 *
 * Helper functions
 *
 */

#include <stdarg.h>
#include <stdlib.h>
#include "applayer.h"
#include "xsolvables.h"

/************************************************
 * string handling
 *
 */

/* helper for string representation, snprintf + strdup */

char *to_string(const char *format, ...)
{
  char buf[2048];
  va_list args;
  va_start(args, format);
  vsnprintf(buf, sizeof(buf), format, args);
  return strdup(buf);
}

struct debugdata {
  Pool *pool;
  int debugmask;
  char *buf;
  int length;
};

static struct debugdata dd;

static void
app_debugcallback(struct _Pool *p, void *data, int type, const char *str)
{
  struct debugdata *ddp = (struct debugdata *)data;
  int len = strlen(str);
  ddp->buf = realloc(ddp->buf, ddp->length + len + 1);
  if (ddp->length == 0) *ddp->buf = 0;
  strcat(ddp->buf, str);
  ddp->length += len;
}

void
app_debugstart(Pool *p, int type)
{
  dd.buf = NULL;
  dd.length = 0;
  dd.debugmask = p->debugmask;
  p->debugmask = type;
  p->debugcallback = app_debugcallback;
  p->debugcallbackdata = &dd;
  dd.pool = p;
}

char *
app_debugend()
{
  dd.pool->debugcallback = NULL;
  dd.pool->debugmask = dd.debugmask;
  return dd.buf;
}

/************************************************
 * Id
 *
 */

const char *
my_id2str( const Pool *pool, Id id )
{
  if (id == STRID_NULL)
    return NULL;
  if (id == STRID_EMPTY)
    return "";
#if SATSOLVER_VERSION > 0
  return id2str( pool, id );
#else /* drop const for older satsolver */
  return id2str( (Pool *)pool, id );
#endif
}

/************************************************
 * Pool
 *
 */

unsigned int
pool_xsolvables_count( const Pool *pool )
{
  const Solvable *s;
  Id p;
  int count = 0;
  /* skip Id 0 since it is reserved
   * skip Id 1 since it is the system solvable and not
   *   accessible to the outside
   */
  for (p = 2, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
    {
      if (!s)
	continue;
      if (!s->name)
        continue;
      ++count;
    }
  
  return count;
{'fraction_non_alphanumeric': 0.19995333644423705, 'fraction_numerical': 0.009099393373775081, 'mean_word_length': 3.2529761904761907, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 40, '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': '3993886', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1494, 'n_words': 439}