<commit_before>/*
 *  nym - Unix-style program for creating acronyms and initialisms
 *  Copyright (C) 2015 <NAME>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, version 3 only.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <unistd.h>
#include <getopt.h>

#include "nym.h"

#ifdef HAVE_CONFIG_H
# include "config.h"
# define VERSION_STRING PACKAGE_STRING
# define PROG PACKAGE
#else
# define VERSION_STRING "nym custom build"
# define PROG "nym"
#endif

#define USAGE_INFO "USAGE: " PROG " [options]\n\n"	\
  PROG " reads from stdin and writes an initialism of it to stdout.\n\n\
OPTIONS:\n\
\t-h, --help\tPrints this help message and exits\n\
\t-v, --version\tPrints version info and exits\n"

#define VERSION_INFO VERSION_STRING "\n\
Copyright (C) 2015 <NAME> II\n\
License AGPLv3: GNU AGPL version 3 only <http://gnu.org/licenses/agpl.html>.\n\
This is libre software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n\n\
Written by <NAME>."

int
main (int argc, char *argv[])
{
  struct option longopts[] =
    {
      {"help",    no_argument, 0, 'h'},
      {"version", no_argument, 0, 'v'},
      {0, 0, 0, 0}
    };

  if (argc > 1)
    {
      int c;
      int longindex;
      while ((c = getopt_long (argc, argv, "hv", longopts, &longindex)) != -1)
	{
	  switch (c)
	    {
	    case 'h':
	      puts (USAGE_INFO);
	      return 0;

	    case 'v':
	      puts (VERSION_INFO);
	      return 0;

	    case '?':
	      return 1;
	    }
	}
    }

  struct nym_buffer *buf = nym_mkbuf ();
  if (!buf)
    {
      fprintf (stderr, "Could not allocate input buffer: %s\n",
	       nym_estring ());
      return nym_errno;
    }

  int c;
  while ((c = getchar ()) != EOF)
    {
      nym_errno = nym_pushbuf (buf, c);
      if (nym_errno)
	goto end;
    }

  char *nym = nym_convert (buf->data);
  if (!nym)
    {
      fprintf (stderr, "Could not nymify: %s\n", nym_estring ());
      goto end;
    }

  puts (nym);
  free (nym);

 end:
  nym_freebuf (buf, true);
  return nym_errno;
}<commit_msg>Print error if input buffer loading fails<commit_after>/*
 *  nym - Unix-style program for creating acronyms and initialisms
 *  Copyright (C) 2015-2016 <NAME>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, version 3 only.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <unistd.h>
#include <getopt.h>

#include "nym.h"

#ifdef HAVE_CONFIG_H
# include "config.h"
# define VERSION_STRING PACKAGE_STRING
# define PROG PACKAGE
#else
# define VERSION_STRING "nym custom build"
# define PROG "nym"
#endif

#define USAGE_INFO "USAGE: " PROG " [options]\n\n"	\
  PROG " reads from stdin and writes an initialism of it to stdout.\n\n\
OPTIONS:\n\
\t-h, --help\tPrints this help message and exits\n\
\t-v, --version\tPrints version info and exits\n"

#define VERSION_INFO VERSION_STRING "\n\
Copyright (C) 2015-2016 <NAME>\n\
License AGPLv3: GNU AGPL version 3 only <http://gnu.org/licenses/agpl.html>.\n\
This is libre software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n\n\
Written by <NAME>."

int
main (int argc, char *argv[])
{
  struct option longopts[] =
    {
      {"help",    no_argument, 0, 'h'},
      {"version", no_argument, 0, 'v'},
      {0, 0, 0, 0}
    };

  if (argc > 1)
    {
      int c;
      int longindex;
      while ((c = getopt_long (argc, argv, "hv", longopts, &longindex)) != -1)
	{
	  switch (c)
	    {
	    case 'h':
	      puts (USAGE_INFO);
	      return 0;

	    case 'v':
	      puts (VERSION_INFO);
	      return 0;

	    case '?':
	      return 1;
	    }
	}
    }

  struct nym_buffer *buf = nym_mkbuf ();
  if (!buf)
    {
      fprintf (stderr, "Could not allocate input buffer: %s\n",
	       nym_estring ());
      return nym_errno;
    }

  int c;
  while ((c = getchar ()) != EOF)
    {
      nym_errno = nym_pushbuf (buf, c);
      if (nym_errno)
	{
	  fprintf (stderr, "Error loading input: %s\n", nym_estring ());
	  goto end;
	}
    }

  char *nym = nym_convert (buf->data);
  if (!nym)
    {
      fprintf (stderr, "Could not nymify: %s\n", nym_estring ());
      goto end;
    }

  puts (nym);
  free (nym);

 end:
  nym_freebuf (buf, true);
  return nym_errno;
}
{'fraction_non_alphanumeric': 0.1225721289835942, 'fraction_numerical': 0.009805770318687535, 'mean_word_length': 2.7404795486600846, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1096714', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1857, 'n_words': 644}