extras/physfs_rb/physfs/rb_physfs_file.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 11 Dec 2002 15:37:23 +0000
changeset 514 f4e89d934fee
child 654 c0ae01de361d
permissions -rw-r--r--
Initial import of Ruby bindings for PhysicsFS.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
514
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * PhysicsFS File abstraction - ruby interface
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 * 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Author::  Ed Sinjiashvili (slimb@vlinkmail.com)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 * License:: LGPL
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
#include "physfs.h"
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#include "ruby.h"
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include "rb_physfs.h"
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include "rb_physfs_file.h"
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include "physfsrwops.h"
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
VALUE classPhysfsFile;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
 * construct new PhysicsFS::File object
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
VALUE physfs_file_new (PHYSFS_file *file)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
        return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
    return Data_Wrap_Struct (classPhysfsFile, 0, 0, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
}
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
 * PhysicsFS::File#close 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
 *
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
 * Close the file. It's illegal to use the object after its closure.
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
VALUE physfs_file_close (VALUE self)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
    int result;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    PHYSFS_file *file;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    Data_Get_Struct (self, PHYSFS_file, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
	return Qfalse;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    result = PHYSFS_close (file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    DATA_PTR(self) = 0;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
    if (result)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        return Qtrue;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    return Qfalse;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
}
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
 * PhysicsFS::File#read obj_size, num_objects
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
 *
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
 * Read *objCount* objects which are *objSize* each.
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
 * return String instance containing raw data or nil if failure.
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
 * #length of string will reflect real number of objects read.
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
VALUE physfs_file_read (VALUE self, VALUE objSize, VALUE objCount)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    int objRead;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    void *buffer;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    VALUE result;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    PHYSFS_file *file;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    Data_Get_Struct (self, PHYSFS_file, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
	return Qnil; //wasted file - no read possible
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    buffer  = malloc (FIX2UINT(objSize) * FIX2UINT(objCount));
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    if (buffer == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
	return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    objRead = PHYSFS_read (file, buffer, FIX2UINT(objSize), FIX2UINT(objCount));
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    if (objRead == -1)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
    {
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
        free (buffer);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
        return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    }
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    result = rb_str_new (buffer, objRead * FIX2UINT(objSize));
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    free (buffer);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    return result;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
}
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
 * PhysicsFS::File#write buffer, obj_size, num_objects
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
 *
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
 * return nil on failure or number of objects written.
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
VALUE physfs_file_write (VALUE self, VALUE buf, VALUE objSize, VALUE objCount)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
    int result;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    PHYSFS_file *file;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
    Data_Get_Struct (self, PHYSFS_file, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
	return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    result = PHYSFS_write (file, STR2CSTR(buf), 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
                           FIX2UINT(objSize), FIX2UINT(objCount));
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
    if (result == -1)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
        return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
    return INT2FIX(result);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
}
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
 * PhysicsFS::File#eof? 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
VALUE physfs_file_eof (VALUE self)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
    int result;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
    PHYSFS_file *file;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    Data_Get_Struct (self, PHYSFS_file, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
	return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    result = PHYSFS_eof (file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    if (result)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
        return Qtrue;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
    return Qfalse;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
}
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
 * PhysicsFS::File#tell
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
 *
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
 * tells current position in file
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
VALUE physfs_file_tell (VALUE self)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    int result;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    PHYSFS_file *file;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
    Data_Get_Struct (self, PHYSFS_file, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
	return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    result = PHYSFS_tell (file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    if (result == -1)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
        return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    return INT2FIX(result);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
}    
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
 * PhysicsFS::File#seek pos
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
 *
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
 * seek to pos in file
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
VALUE physfs_file_seek (VALUE self, VALUE pos)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    int result;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    PHYSFS_file *file;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    Data_Get_Struct (self, PHYSFS_file, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
	return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    result = PHYSFS_seek (file, FIX2LONG(pos));
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    if (result)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
        return Qtrue;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    return Qfalse;    
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
}
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
 * PhysicsFS::File#length 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
VALUE physfs_file_length (VALUE self)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    int result;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    PHYSFS_file *file;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    Data_Get_Struct (self, PHYSFS_file, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
	return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    result = PHYSFS_fileLength (file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    if (result == -1)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
        return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    return INT2FIX(result);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
}
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
/*
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
 * PhysicsFS::File#to_rwops
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
 *
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
 * File object is converted to RWops object. 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
 * File object becomes unusable after that - every operation
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
 * should be done through new-born RWops object. 
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
 */
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
VALUE physfs_file_to_rwops (VALUE self)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    PHYSFS_file *file;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
    SDL_RWops   *rwops;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
    Data_Get_Struct (self, PHYSFS_file, file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
    if (file == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
	return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
    rwops = PHYSFSRWOPS_makeRWops (file);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
    if (rwops == 0)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
	return Qnil;
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    DATA_PTR(self) = 0; // oh, gosh, we've sacrificed ourselves!
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    return sdl_rwops_new (rwops);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
}
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
void init_physfs_file (void)
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
{
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    classPhysfsFile = rb_define_class_under (modulePhysfs, "File", rb_cObject);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
    rb_define_method (classPhysfsFile, "close",    physfs_file_close,    0);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
    rb_define_method (classPhysfsFile, "eof?",     physfs_file_eof,      0);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
    rb_define_method (classPhysfsFile, "tell",     physfs_file_tell,     0);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    rb_define_method (classPhysfsFile, "seek",     physfs_file_seek,     1);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
    rb_define_method (classPhysfsFile, "length",   physfs_file_length,   0);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
    rb_define_method (classPhysfsFile, "read",     physfs_file_read,     2);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    rb_define_method (classPhysfsFile, "write",    physfs_file_write,    3);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    rb_define_method (classPhysfsFile, "to_rwops", physfs_file_to_rwops, 0);
f4e89d934fee Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
}