csi-trace.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include "config.h"
  35. #include "cairo-script.h"
  36. #include "cairo-script-interpreter.h"
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <libgen.h>
  41. static cairo_surface_t *
  42. _script_surface_create (void *closure,
  43. cairo_content_t content,
  44. double width, double height,
  45. long uid)
  46. {
  47. return cairo_script_surface_create (closure, content, width, height);
  48. }
  49. int
  50. main (int argc, char **argv)
  51. {
  52. cairo_script_interpreter_t *csi;
  53. cairo_script_interpreter_hooks_t hooks = {
  54. .surface_create = _script_surface_create,
  55. };
  56. int i;
  57. char buf[4096];
  58. csi = cairo_script_interpreter_create ();
  59. for (i = 1; i < argc; i++) {
  60. if (strcmp (argv[i], "--version")) {
  61. printf ("%s: version %s\n", argv[0], __DATE__);
  62. exit (0);
  63. } else if (strcmp (argv[i], "--help")) {
  64. printf ("usage: %s < in > out\n", argv[0]);
  65. exit (0);
  66. }
  67. snprintf (buf, sizeof (buf), "%s.trace", basename (argv[i]));
  68. cairo_device_destroy (hooks.closure);
  69. hooks.closure = cairo_script_create (buf);
  70. cairo_script_interpreter_install_hooks (csi, &hooks);
  71. cairo_script_interpreter_run (csi, argv[i]);
  72. }
  73. cairo_device_destroy (hooks.closure);
  74. return cairo_script_interpreter_destroy (csi);
  75. }