1
/*
2
 * Copyright © 2008 Chris Wilson <chris@chris-wilson.co.uk>
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it either under the terms of the GNU Lesser General Public
6
 * License version 2.1 as published by the Free Software Foundation
7
 * (the "LGPL") or, at your option, under the terms of the Mozilla
8
 * Public License Version 1.1 (the "MPL"). If you do not alter this
9
 * notice, a recipient may use your version of this file under either
10
 * the MPL or the LGPL.
11
 *
12
 * You should have received a copy of the LGPL along with this library
13
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
15
 * You should have received a copy of the MPL along with this library
16
 * in the file COPYING-MPL-1.1
17
 *
18
 * The contents of this file are subject to the Mozilla Public License
19
 * Version 1.1 (the "License"); you may not use this file except in
20
 * compliance with the License. You may obtain a copy of the License at
21
 * http://www.mozilla.org/MPL/
22
 *
23
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
24
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
25
 * the specific language governing rights and limitations.
26
 *
27
 * The Original Code is the cairo graphics library.
28
 *
29
 * The Initial Developer of the Original Code is Chris Wilson.
30
 *
31
 * Contributor(s):
32
 *      Chris Wilson <chris@chris-wilson.co.uk>
33
 */
34

            
35
#include "config.h"
36

            
37
#include "cairo-script.h"
38
#include "cairo-script-interpreter.h"
39

            
40
#include <stdio.h>
41
#include <stdlib.h>
42
#include <string.h>
43
#include <libgen.h>
44

            
45
static cairo_surface_t *
46
_script_surface_create (void *closure,
47
			 cairo_content_t content,
48
			 double width, double height,
49
			 long uid)
50
{
51
    return cairo_script_surface_create (closure, content, width, height);
52
}
53

            
54
int
55
main (int argc, char **argv)
56
{
57
    cairo_script_interpreter_t *csi;
58
    cairo_script_interpreter_hooks_t hooks = {
59
	.surface_create = _script_surface_create,
60
    };
61
    int i;
62
    char buf[4096];
63

            
64
    csi = cairo_script_interpreter_create ();
65

            
66
    for (i = 1; i < argc; i++) {
67
        if (strcmp (argv[i], "--version") == 0) {
68
            printf ("%s: version %s\n", argv[0], __DATE__);
69
	    exit (0);
70
        } else if (strcmp (argv[i], "--help") == 0) {
71
	    printf ("usage: %s < in > out\n", argv[0]);
72
	    exit (0);
73
        }
74

            
75
	snprintf (buf, sizeof (buf), "%s.trace", basename (argv[i]));
76
	cairo_device_destroy (hooks.closure);
77
	hooks.closure = cairo_script_create (buf);
78
	cairo_script_interpreter_install_hooks (csi, &hooks);
79
	cairo_script_interpreter_run (csi, argv[i]);
80
    }
81
    cairo_device_destroy (hooks.closure);
82

            
83
    return cairo_script_interpreter_destroy (csi);
84
}