Debian Codegraph @

caca-php/examples/import.php

raw
1 #!/usr/bin/php5
2 <?php
3 /*
4 * import libcaca importers test program
5 * Copyright (c) 2008 Benjamin C. Wiley Sittler <[email protected]>
6 *
7 * This file is a Php port of "examples/import.c"
8 * which is:
9 * Copyright (c) 2006 Jean-Yves Lamoureux <[email protected]>
10 * All Rights Reserved
11 *
12 * This program is free software. It comes without any warranty, to
13 * the extent permitted by applicable law. You can redistribute it
14 * and/or modify it under the terms of the Do What the Fuck You Want
15 * to Public License, Version 2, as published by Sam Hocevar. See
16 * http://www.wtfpl.net/ for more details.
17 */
18
19 if (php_sapi_name() != "cli") {
20 die("You have to run this program with php-cli!\n");
21 }
22
23 $imports = caca_get_import_list();
24
25 if($argc < 2 || $argc > 3)
26 {
27 $msg = ($argv[0] . ": wrong argument count\n" .
28 "usage: " . $argv[0] . " file [<format>]\n" .
29 "where <format> is one of:\n");
30 foreach($imports as $format => $name)
31 $msg .= " \"" . $name . "\" (" . $format . ")\n";
32 die($msg);
33 }
34
35 $cv = caca_create_canvas(0, 0);
36 if(! $cv)
37 {
38 die("Can't create canvas\n");
39 }
40
41 if(caca_import_file($cv, $argv[1], $argc >= 3 ? $argv[2] : "") < 0)
42 {
43 die($argv[0] . ": could not open `" . $argv[1] . "'.\n");
44 }
45
46 $dp = caca_create_display($cv);
47 if(! $dp)
48 {
49 die("Can't create display\n");
50 }
51
52 caca_refresh_display($dp);
53
54 caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
55
56 ?>