Changeset 3264 for libcaca


Ignore:
Timestamp:
Nov 4, 2008, 4:32:42 AM (11 years ago)
Author:
bsittler
Message:

PHPification of import.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/import.php

    • Property svn:executable set to *
    r3263 r3264  
     1#!/usr/bin/php5
     2<?php
    13/*
    24 *  import        libcaca importers test program
     5 *  Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
     6 *
     7 *  This file is a Php port of "examples/import.c"
     8 *  which is:
    39 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
    410 *                All Rights Reserved
     
    1319 */
    1420
    15 #include "config.h"
    16 
    17 #if !defined(__KERNEL__)
    18 #   include <stdio.h>
    19 #   include <stdlib.h>
    20 #endif
    21 
    22 #include "caca.h"
    23 
    24 int main(int argc, char *argv[])
     21if($argc < 2)
    2522{
    26     caca_canvas_t *cv;
    27     caca_display_t *dp;
    28 
    29     if(argc < 2)
    30     {
    31         fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
    32         fprintf(stderr, "usage: %s <filename> [<format>]\n", argv[0]);
    33         return 1;
    34     }
    35 
    36     cv = caca_create_canvas(0, 0);
    37     if(cv == NULL)
    38     {
    39         printf("Can't create canvas\n");
    40         return -1;
    41     }
    42 
    43     if(caca_import_file(cv, argv[1], argc >= 3 ? argv[2] : "") < 0)
    44     {
    45         fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
    46         caca_free_canvas(cv);
    47         return 1;
    48     }
    49 
    50     dp = caca_create_display(cv);
    51     if(dp == NULL)
    52     {
    53         printf("Can't create display\n");
    54         return -1;
    55     }
    56 
    57     caca_refresh_display(dp);
    58 
    59     caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
    60 
    61     caca_free_display(dp);
    62     caca_free_canvas(cv);
    63 
    64     return 0;
     23        die($argv[0] . ": missing argument (filename).\n" .
     24                "usage: " . $argv[0] . " <filename> [<format>]\n");
    6525}
    6626
     27$cv = caca_create_canvas(0, 0);
     28if(! $cv)
     29{
     30        die("Can't create canvas\n");
     31}
     32
     33if(caca_import_file($cv, $argv[1], $argc >= 3 ? $argv[2] : "") < 0)
     34{
     35        die($argv[0] . ": could not open `" . $argv[1] . "'.\n");
     36}
     37
     38$dp = caca_create_display($cv);
     39if(! $dp)
     40{
     41        die("Can't create display\n");
     42}
     43
     44caca_refresh_display($dp);
     45
     46caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
     47
     48?>
Note: See TracChangeset for help on using the changeset viewer.