Install script and bugfix
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
*.o
|
||||
.vscode
|
||||
23
Makefile
Normal file
23
Makefile
Normal file
@ -0,0 +1,23 @@
|
||||
.POSIX:
|
||||
|
||||
CC = gcc
|
||||
# CFLAGS = -Wall -Wextra -ansi -pedantic -std=c99 -g
|
||||
CFLAGS = -Wall -ansi -pedantic -std=c99 -g -fsanitize=address
|
||||
|
||||
all: pkmn
|
||||
|
||||
install: all
|
||||
cp pkmn /usr/local/bin
|
||||
cp -r pokemons /usr/local/share/pkmn
|
||||
|
||||
uninstall:
|
||||
rm /usr/local/bin/pkmn
|
||||
rm -r /usr/local/share/pkmn
|
||||
|
||||
pkmn: pkmn.o
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
||||
|
||||
pkmn.o: pkmn.c
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
@ -4,6 +4,12 @@
|
||||
|
||||
A simple program to display a Pokémon in the terminal. Based on cowsay.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
sudo make install
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
@ -38,6 +44,7 @@ pkmn -rs
|
||||
## TODO
|
||||
- [ ] Add option to list available pokémon
|
||||
- [ ] Add option to open an fzf window to select a pokémon
|
||||
- Until added use : `ls ~/pokemons/yes | fzf --prompt='Type a pokemon name : ' --preview 'pkmn {}' | xargs pkmn`
|
||||
- [ ] Add argument to display a message
|
||||
|
||||
|
||||
|
||||
25
pkmn.c
25
pkmn.c
@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user