<commit_before>/*
 * cara.c
 *
 * Copyright: 2012 <NAME> <<EMAIL>>
 * 
 * License: (the MIT license)
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include "cara.h"
#include "cmd.h"

#include <stdio.h>
#include <string.h>

void help(const char* progname){
  printf("Usage: %s [--version] [--help] [--usage]\n", progname);
  printf("            <command> [args]\n");
  printf("\n");
  printf("  A package manager for Caroline Linux.\n");
  printf("\n");
  printf("  Commands:\n");
  printf("  installs                   Install a package");
  printf("\n\n");
  printf("  Options:\n");
  printf("  -h, --help                 Print this help\n");
  printf("  -u, --usage                Output usage info\n");
  printf("  -v, --version              Show version\n");
  printf("\n\n");
  printf("This program is licensed under the MIT license.\n");
  printf("If you have any questions/found a bug, write to <<EMAIL>>\n");
}

void usage(const char* progname){
  printf("Usage: %s [option] [--help] <command> [args]\n", progname);
}

void version(void){
  printf("\n");
  printf("   Cara v%s\n", VERSION);
  printf("   Copyright (c) 2012 by <NAME> <<EMAIL>>\n");
  printf("\n");
  printf("   This program is licensed under the MIT license.\n");
  printf("\n");
}

int main(int argc, char* argv[]){
  /* original program's name */
  const char* progname = argv[0];

  /* show help if not specified any args */
  if (argc < 2){
    usage(progname);
    return 1;
  }

  /*
   * These options ought to be passed after the programs name ('cara')
   * and before the command, as argv[1].
   *
   * Unless it won't work..
   */
  if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")){
    version();
    return 0;
  } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
    help(progname);
    return 0;
  } else if (!strcmp(argv[1], "-u") || !strcmp(argv[1], "--usage")){
    usage(progname);
    return 0;
  }

  static struct cmd_struct commands[] = {
    { "installs", cmd_installs },
  };

  /* command to be run */
  static char* cmd;

  cmd = argv[1];

  int i, cmd_found = 1;
  for (i = 0; i < ARRAY_SIZE(commands); i++){
    struct cmd_struct *p = commands + i;
    if (strcmp(p->cmd, cmd)){
      cmd_found = 0;
      continue;
    }

    /* run the command */
    return p->function(argc, argv, progname);
  }

  if (!cmd_found){
    printf("%s: unknown command ‘%s’\n", progname, cmd);<commit_msg>Say 'unkown option' if it is an unknown option.<commit_after>/*
 * cara.c
 *
 * Copyright: 2012 <NAME> <<EMAIL>>
 * 
 * License: (the MIT license)
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include "cara.h"
#include "cmd.h"

#include <stdio.h>
#include <string.h>

void help(const char* progname){
  printf("Usage: %s [--version] [--help] [--usage]\n", progname);
  printf("            <command> [args]\n");
  printf("\n");
  printf("  A package manager for Caroline Linux.\n");
  printf("\n");
  printf("  Commands:\n");
  printf("  installs                   Install a package");
  printf("\n\n");
  printf("  Options:\n");
  printf("  -h, --help                 Print this help\n");
  printf("  -u, --usage                Output usage info\n");
  printf("  -v, --version              Show version\n");
  printf("\n\n");
  printf("This program is licensed under the MIT license.\n");
  printf("If you have any questions/found a bug, write to <<EMAIL>>\n");
}

void usage(const char* progname){
  printf("Usage: %s [option] [--help] <command> [args]\n", progname);
}

void version(void){
  printf("\n");
  printf("   Cara v%s\n", VERSION);
  printf("   Copyright (c) 2012 by <NAME> <<EMAIL>>\n");
  printf("\n");
  printf("   This program is licensed under the MIT license.\n");
  printf("\n");
}

int main(int argc, char* argv[]){
  /* original program's name */
  const char* progname = argv[0];

  /* show help if not specified any args */
  if (argc < 2){
    usage(progname);
    return 1;
  }

  /*
   * These options ought to be passed after the programs name ('cara')
   * and before the command, as argv[1].
   *
   * Unless it won't work..
   */
  if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")){
    version();
    return 0;
  } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
    help(progname);
    return 0;
  } else if (!strcmp(argv[1], "-u") || !strcmp(argv[1], "--usage")){
    usage(progname);
    return 0;
    /*
     * yarharhar!
     *
     * we 're checking if the first character of argv[0] and
     * --deadbeef is the same - if it is, that means the
     * previous else-ifs didn't catch that option, so there is
     * obviously no such option.
     */
  } else if (!strncmp(argv[1], "--deadbeef", 1)){
    printf("%s: unknown option ‘%s’\n", progname, argv[1]);
    return 1;
  }

  static struct cmd_struct commands[] = {
    { "installs", cmd_installs },
  };

  /* command to be run */
  static char* cmd;

  cmd = argv[1];

  int i, cmd_found = 1;
  for (i = 0; i < ARRAY_SIZE(commands); i++){
    struct cmd_struct *p = commands + i;
    if (strcmp(p->cmd, cmd)){
      cmd_found = 0;
      continue;
    }

    /* run the command */
    return p->function(argc, argv, progname);
  }

  if (!cmd_found){
    printf("%s: unknown command ‘%s’\n", progname, cmd);
{'fraction_non_alphanumeric': 0.14980863860032806, 'fraction_numerical': 0.007517769272826681, 'mean_word_length': 3.0247524752475248, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '1278823', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2251, 'n_words': 868}