summaryrefslogtreecommitdiff
path: root/experimental/tectonics/main.c
blob: 93b32fb299f9f981aa7e6c49171470a6e4f384af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <cairo.h>

#include "tectonics.h"
#include "drawing.h"
#include "logging.h"

#define X_RES 1024
#define Y_RES X_RES


int parse_options(char **output_file, int argc, char **argv);
   

int main(int argc, char **argv)
{
   char *output_file;
   if (parse_options(&output_file, argc, argv))
      return 1;
   
   cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, X_RES, Y_RES);
   cairo_t *cr = cairo_create(surface);

   struct world_t world;
   create_world(&world, 100000);
   if (world.points == NULL)
      return 1;
   draw_world(cr, &world);
   free_world(&world);
   
   cairo_destroy(cr);
   cairo_surface_write_to_png(surface, "output.png");
   cairo_surface_destroy(surface);
   return 0;
}


#include <stdio.h>
#include <unistd.h>

static void print_usage(const char *progname)
{
   printf("Usage: %s [-c config_file] [-v[v[v]]] [-q[q[q]]] [-h] [-s script]\n"
	  "  -v    Increase output verbosity (-vvv displays every log message)\n"
	  "  -q    Decrease output verbosity (-qqq suppresses even fatal errors)\n"
	  "  -c    Specify configuration file to read (default 'config.lua')\n"
	  "  -s    Override the built-in Lua script\n"
	  "  -h    Print this help message and exit\n",
	  progname);	  
}

int parse_options(char **output_file, int argc, char **argv)
{
   int log_level = WARN;
   *output_file = "output.png";
   
   int opt;
   while ((opt = getopt(argc, argv, "qvo:h")) != -1) {
      switch (opt) {
      case 'q':
	 log_level -= 1;
	 break;
	 
      case 'v':
	 log_level += 1;
	 break;
	 
      case 'o':
	 *output_file = optarg;

      case 'h':
	 print_usage(argv[0]);
	 return 2;

      default:
	 print_usage(argv[0]);
	 return 1;
      }
   }

   // ew, globals (sorry)
   global_log_level = log_level;

   return 0;
}