Install script and bugfix

This commit is contained in:
gauvain-thomas
2024-02-25 15:54:51 +01:00
parent 92f2d344b2
commit f09d15be31
5 changed files with 46 additions and 12 deletions

25
pkmn.c
View File

@ -7,6 +7,8 @@
#include <string.h>
#include <regex.h>
const char *pkmn_path = "/usr/local/share/pkmn";
const char *argp_program_version =
"pkmn 1.0";
const char *argp_program_bug_address =
@ -14,7 +16,7 @@ const char *argp_program_bug_address =
/* Program documentation. */
static char doc[] =
"Argp example #3 -- a program with options and arguments using argp";
"pkmn -- A simple program to display a Pokémon in the terminal. Based on cowsay.";
/* A description of the arguments we accept. */
static char args_doc[] = "pokemon_name";
@ -115,10 +117,10 @@ int pkmn_name_from_file(char *pokemon_file, char *pokemon_name) {
} else {
fprintf(stderr, "Match too long for buffer\n");
}
} else if (ret == REG_NOMATCH) {
fprintf(stderr, "No match found\n");
} else {
fprintf(stderr, "Regex match failed\n");
} else if (ret == REG_NOMATCH) {
fprintf(stderr, "No match found\n");
} else {
fprintf(stderr, "Regex match failed\n");
}
// Free the regex memory
@ -129,10 +131,8 @@ int pkmn_name_from_file(char *pokemon_file, char *pokemon_name) {
int get_pokemon_file(char *arg, char *pokemon_file) {
// Finds a matching file in the pokemons directory from the argument
// Returns 0 if the file was found, 1 otherwise
// ls ~/pokemons/yes | fzf -f wp | head -1
char command[512];
sprintf(command, "ls ~/pokemons/yes | fzf -f %s | head -1 > /tmp/pkmn", arg);
sprintf(command, "ls %s/yes | fzf -f %s | head -1 > /tmp/pkmn", pkmn_path, arg);
system(command);
FILE *f = fopen("/tmp/pkmn", "r");
fscanf(f, "%s", pokemon_file);
@ -146,7 +146,6 @@ int get_pokemon_file(char *arg, char *pokemon_file) {
int main (int argc, char **argv) {
struct arguments arguments;
char pkmn_path[] = "~/pokemons/";
/* Default values. */
arguments.verbose = 0;
@ -170,7 +169,9 @@ int main (int argc, char **argv) {
char pokemon_file[512];
if (arguments.random) {
system("ls ~/pokemons/yes | shuf -n 1 > /tmp/pkmn");
char command[512];
sprintf(command, "ls %s/yes | shuf -n 1 > /tmp/pkmn", pkmn_path);
system(command);
FILE *f = fopen("/tmp/pkmn", "r");
fscanf(f, "%s", pokemon_file);
fclose(f);
@ -206,9 +207,9 @@ int main (int argc, char **argv) {
// Execute the command echo "$pokemon_name!" | cowsay -f "$cow_file" -W 70
char command[1024];
if (arguments.shiney) {
sprintf(command, "echo \"Shiny %s!\" | cowsay -f %s%s -W 70", pokemon_name, pkmn_path, pokemon_file);
sprintf(command, "echo \"Shiny %s!\" | cowsay -f %s/%s -W 70", pokemon_name, pkmn_path, pokemon_file);
} else {
sprintf(command, "echo \"%s!\" | cowsay -f %syes/%s -W 70", pokemon_name, pkmn_path, pokemon_file);
sprintf(command, "echo \"%s!\" | cowsay -f %s/yes/%s -W 70", pokemon_name, pkmn_path, pokemon_file);
}
system(command);