diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..7f961e7 --- /dev/null +++ b/src/main.c @@ -0,0 +1,72 @@ +#include <stdio.h> +#include "args.h" +#include "pattern/pattern.h" +#include "io/text.h" +#include "io/svg.h" + +/* + * EX stands for EXIT STATUS and + * EXE stands for EXIT STATUS ERROR + */ +#define EX_OK 0 +#define EXE_ARGS 1 +#define EXE_IO 2 + +int main(int argc, char **argv) +{ + struct args args; + enum alr alr = load_args(argc, argv, &args); + if (alr != ALR_OK) + { + if (alr == ALR_INVALID_OPTION) + fprintf(stderr, "Invalid option!"); + else + fprintf(stderr, "Args processing error!\n"); + return EXE_ARGS; + } + struct pattern *pattern = &args.pattern; + struct coord path[16]; + pattern->path = path; + + args.params.count = 0; + FILE *out = stdout; + if (!args.standard_output && args.single_output) + { + if ((out = fopen(args.output, "w")) == NULL) + { + fprintf(stderr, "%s file cannot be opened.", args.output); + return EXE_IO; + } + } + while (args.gen(pattern) && (args.gen_count < 0 || args.params.count < args.gen_count)) + { + args.params.count++; + if ((args.from_count <= (int)args.params.count) && (((int)args.params.count <= args.to_count) || (args.to_count < 0))) + { + if (!args.standard_output && !args.single_output) + { + char file_path[512]; + sprintf(file_path, args.output, args.params.count); + if ((out = fopen(file_path, "w")) == NULL) + { + fprintf(stderr, "%s file cannot be opened.", file_path); + return EXE_IO; + } + } + + args.print(out, args.params, pattern); + if (args.wait) + { + char c; + getchar(); + } + + if (!args.standard_output && !args.single_output) + fclose(out); + } + } + if (!args.standard_output && args.single_output) + fclose(out); + + return EX_OK; +}
\ No newline at end of file |