diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..596cff8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.*.swp +*~ diff --git a/audio.c b/audio.c index b987b85..c33a68d 100644 --- a/audio.c +++ b/audio.c @@ -1,20 +1,36 @@ #include -const char* audio_dev = "/dev/audio"; -FILE* audio; +#include "audio.h" -void init(char* dev_file_name) { - if (dev_file_name != NULL) { - audio = fopen(dev_file_name, "a"); +//const char* audio_dev = "/dev/audio"; +FILE* audio = NULL; +int quiet = 0; + +void init(struct s_config s) { + if (s.filename != NULL) { + audio = fopen(s.filename, "a"); + } + if (s.quiet == 1) { + quiet = 1; } else { - audio = stdout; + quiet = 0; } } void p(int i) { - //fputc(i, audio); - putchar(i); + if (audio != NULL) { + fputc(i, audio); + } + if (!quiet) { + putchar(i); + } +} + +void quit() { + if (audio != stdout) { + fclose(audio); + } } // vim:set sw=2 sts=2 et ai: diff --git a/audio.h b/audio.h index 49d63c0..7632ccd 100644 --- a/audio.h +++ b/audio.h @@ -1,4 +1,16 @@ -void init(); +#ifndef BITORC_AUDIO_H +#define BITORC_AUDIO_H + +struct s_config { + int quiet; + char* filename; +}; + +void init(struct s_config s); void p(int i); +void quit(); +#endif + +// vim:set sw=2 sts=2 et ai: diff --git a/main.c b/main.c index a2e2899..9d2a09c 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,70 @@ #include +#include #include +#include -int main(int ac, char** av) { - //init(); - return 0; +#include "audio.h" +#include "sounds.h" + +void usage(char* name, int exit_stat) { + fprintf(stderr, "Usage: %s [-f filename] < -s 1-6 >\n", name); + exit(exit_stat); +} + +int main(int ac, char* av[]) { + int opt; + int sound_choice = 0; + //int quiet = 0; + //char* filename = NULL; + struct s_config s; + + while ((opt = getopt(ac, av, "hf:s:q")) != -1) { + switch (opt) { + case 'q': + s.quiet = 1; + break; + case 's': + sound_choice = atoi(optarg); + break; + case 'f': + s.filename = optarg; + break; + case 'h': + usage(av[0], EXIT_SUCCESS); + default: + usage(av[0], EXIT_FAILURE); + } + } + + if (sound_choice == 0) { + fprintf(stderr, "ERROR: pleaese choice a sound (currently 1-6)\n"); + usage(av[0], EXIT_FAILURE); + } + + init(s); + + switch (sound_choice) { + case 1: + sound_loop_1(sound_1, 0); + break; + case 2: + sound_loop_1(sound_2, 0); + break; + case 3: + sound_loop_1(sound_3, 0); + break; + case 4: + sound_loop_1(sound_4, 0); + break; + case 5: + sound_loop_1(sound_5, 0); + break; + case 6: + sound_loop_1(sound_6, 0); + break; + } + + exit(EXIT_SUCCESS); } // vim:set sw=2 sts=2 et ai: diff --git a/sounds.h b/sounds.h index cb5f5b4..79189ed 100644 --- a/sounds.h +++ b/sounds.h @@ -1,4 +1,7 @@ +#ifndef BITORC_SOUNDS_H +#define BITORC_SOUNDS_H + void sound_loop_1(int (*sp)(int i), int t); int sound_1(int t); int sound_2(int t); @@ -7,4 +10,6 @@ int sound_4(int t); int sound_5(int t); int sound_6(int t); +#endif + // vim:set sw=2 sts=2 et ai: