diff --git a/caca-php/examples/import.php b/caca-php/examples/import.php old mode 100644 new mode 100755 index d235f62..e81e959 --- a/caca-php/examples/import.php +++ b/caca-php/examples/import.php @@ -1,5 +1,11 @@ +#!/usr/bin/php5 + + * + * This file is a Php port of "examples/import.c" + * which is: * Copyright (c) 2006 Jean-Yves Lamoureux * All Rights Reserved * @@ -12,55 +18,31 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -#include "config.h" - -#if !defined(__KERNEL__) -# include -# include -#endif - -#include "caca.h" - -int main(int argc, char *argv[]) +if($argc < 2) { - caca_canvas_t *cv; - caca_display_t *dp; - - if(argc < 2) - { - fprintf(stderr, "%s: missing argument (filename).\n", argv[0]); - fprintf(stderr, "usage: %s []\n", argv[0]); - return 1; - } - - cv = caca_create_canvas(0, 0); - if(cv == NULL) - { - printf("Can't create canvas\n"); - return -1; - } - - if(caca_import_file(cv, argv[1], argc >= 3 ? argv[2] : "") < 0) - { - fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]); - caca_free_canvas(cv); - return 1; - } + die($argv[0] . ": missing argument (filename).\n" . + "usage: " . $argv[0] . " []\n"); +} - dp = caca_create_display(cv); - if(dp == NULL) - { - printf("Can't create display\n"); - return -1; - } +$cv = caca_create_canvas(0, 0); +if(! $cv) +{ + die("Can't create canvas\n"); +} - caca_refresh_display(dp); +if(caca_import_file($cv, $argv[1], $argc >= 3 ? $argv[2] : "") < 0) +{ + die($argv[0] . ": could not open `" . $argv[1] . "'.\n"); +} - caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); +$dp = caca_create_display($cv); +if(! $dp) +{ + die("Can't create display\n"); +} - caca_free_display(dp); - caca_free_canvas(cv); +caca_refresh_display($dp); - return 0; -} +caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1); +?>