<commit_before>/***********************************************************************/
/*                                                                     */
/*                           Objective Caml                            */
/*                                                                     */
/*            <NAME>, <NAME>, <NAME>         */
/*                                                                     */
/*  Copyright 1996 Institut National de Recherche en Informatique et   */
/*  Automatique.  Distributed only by permission.                      */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

/* Read and output terminal commands */

#include "config.h"
#include "alloc.h"
#include "fail.h"
#include "io.h"
#include "mlvalues.h"

#ifdef HAS_TERMCAP

extern int tgetent (char * buffer, char * name);
extern int tgetstr (char * id, char ** area);
extern int tgetnum (char * id);
extern int tputs (char * str, int count, int (*outchar)(int c));

value terminfo_setup(value unit)      /* ML */
{
  static char buffer[1024];
  if (tgetent(buffer, getenv("TERM")) != 1) failwith("Terminfo.setupterm");
  return Val_unit;
}

value terminfo_getstr(value capa)     /* ML */
{
  char buff[1024];
  char * p = buff;
  if (tgetstr(String_val(capa), &p) == 0) raise_not_found();
  return copy_string(buff);
}

value terminfo_getnum(value capa)     /* ML */
{
  int res = tgetnum(String_val(capa));
  if (res == -1) raise_not_found();
  return Val_int(res);
}

static struct channel * terminfo_putc_channel;

static int terminfo_putc(int c)
{
  putch(terminfo_putc_channel, c);
  return c;
}

value terminfo_puts(value vchan, value str, value count) /* ML */
{
  terminfo_putc_channel = Channel(vchan);
  tputs(String_val(str), Int_val(count), terminfo_putc);
  return Val_unit;
}

#else

value terminfo_setup(value unit)
{
  failwith("Terminfo.setupterm");<commit_msg>Erreur dans le proto de tgetstr (signale par Jerome).<commit_after>/***********************************************************************/
/*                                                                     */
/*                           Objective Caml                            */
/*                                                                     */
/*            <NAME>, <NAME>, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 1996 Institut National de Recherche en Informatique et   */
/*  Automatique.  Distributed only by permission.                      */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

/* Read and output terminal commands */

#include "config.h"
#include "alloc.h"
#include "fail.h"
#include "io.h"
#include "mlvalues.h"

#ifdef HAS_TERMCAP

extern int tgetent (char * buffer, char * name);
extern char * tgetstr (char * id, char ** area);
extern int tgetnum (char * id);
extern int tputs (char * str, int count, int (*outchar)(int c));

value terminfo_setup(value unit)      /* ML */
{
  static char buffer[1024];
  if (tgetent(buffer, getenv("TERM")) != 1) failwith("Terminfo.setupterm");
  return Val_unit;
}

value terminfo_getstr(value capa)     /* ML */
{
  char buff[1024];
  char * p = buff;
  char * s = tgetstr(String_val(capa), &p);
  if (s == NULL) raise_not_found();
  return copy_string(s);
}

value terminfo_getnum(value capa)     /* ML */
{
  int res = tgetnum(String_val(capa));
  if (res == -1) raise_not_found();
  return Val_int(res);
}

static struct channel * terminfo_putc_channel;

static int terminfo_putc(int c)
{
  putch(terminfo_putc_channel, c);
  return c;
}

value terminfo_puts(value vchan, value str, value count) /* ML */
{
  terminfo_putc_channel = Channel(vchan);
  tputs(String_val(str), Int_val(count), terminfo_putc);
  return Val_unit;
}

#else

value terminfo_setup(value unit)
{
  failwith("Terminfo.setupterm");
{'fraction_non_alphanumeric': 0.18705565089482717, 'fraction_numerical': 0.007109585682765384, 'mean_word_length': 2.0244625648628616, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1411358', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1155, 'n_words': 295}