aboutsummaryrefslogtreecommitdiff
path: root/fractal-gen.c
diff options
context:
space:
mode:
Diffstat (limited to 'fractal-gen.c')
-rw-r--r--fractal-gen.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/fractal-gen.c b/fractal-gen.c
index 4401fa1..091f7d5 100644
--- a/fractal-gen.c
+++ b/fractal-gen.c
@@ -1,16 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include "trampoline.h"
-static unsigned long size;
-static unsigned long iterations;
-
-int main()
+int run(unsigned int size, unsigned int iterations)
{
- size = 1024;
- iterations = 102400;
-
fprintf(stderr, "Building CL trampoline... ");
if (tramp_init()) {
fprintf(stderr, "Failed.\n");
@@ -52,7 +47,7 @@ int main()
return 1;
}
fprintf(stderr, "Reading data from device... ");
- if (tramp_copy_data(&buffer, size*size)) {
+ if (tramp_copy_data((void*)&buffer, size*size)) {
fprintf(stderr, "Failed.\n");
return 1;
}
@@ -64,6 +59,40 @@ int main()
printf("P5\n%d\n%d\n255\n",size,size);
fwrite(buffer, size*size, 1, stdout);
+}
+
+void die_help()
+{
+ fprintf(stderr, "Syntax:\n%s [-s size] [-i max_iteratons]\n");
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int size = 0;
+ unsigned int iterations = 0;
+ char c = '\0';
+
+ while ((c = getopt(argc, argv, "s:i:")) != -1) {
+ switch (c) {
+ case 's':
+ size = atoi(optarg);
+ break;
+ case 'i':
+ iterations = atoi(optarg);
+ break;
+ case '?':
+ die_help();
+ return 1; /* mostly unreachable */
+ break; /* unreachable */
+ }
+ }
+
+ if (size == 0 || iterations == 0) {
+ die_help();
+ return 1; /* mostly unreachable */
+ }
+ run(size, iterations);
return 0;
}