File: programming/cocoa/

/* gi_blorb.c: Blorb library layer for Glk API.
    gi_blorb version 1.4.
    Designed by Andrew Plotkin <>
    This file is copyright 1998-2000 by Andrew Plotkin. You may copy,
    distribute, and incorporate it into your own programs, by any means
    and under any conditions, as long as you do not modify it. You may
    also modify this file, incorporate it into your own programs,
    and distribute the modified version, as long as you retain a notice
    in your program or documentation which mentions my name and the URL
    shown above.
#include "glk.h"
#include "gi_blorb.h"
#ifndef NULL
#define NULL 0
#ifndef TRUE
#define TRUE 1
#ifndef FALSE
#define FALSE 0
/* The magic macro of endian conversion. */
#define giblorb_native4(v)   \
    ( (((glui32)((v)[3])      ) & 0x000000ff)    \
    | (((glui32)((v)[2]) <<  8) & 0x0000ff00)    \
    | (((glui32)((v)[1]) << 16) & 0x00ff0000)    \
    | (((glui32)((v)[0]) << 24) & 0xff000000))
/* More four-byte constants. */
#define giblorb_ID_FORM (giblorb_make_id('F', 'O', 'R', 'M'))
#define giblorb_ID_IFRS (giblorb_make_id('I', 'F', 'R', 'S'))
#define giblorb_ID_RIdx (giblorb_make_id('R', 'I', 'd', 'x'))
/* giblorb_chunkdesc_t: Describes one chunk of the Blorb file. *//* start of chunk header */
    glui32 datpos; /* start of data (either startpos or startpos+8) *//* pointer to malloc'd data, if loaded *//* entry in the auxsound/auxpict array; -1 if none.
        This only applies to chunks that represent resources;  */
} giblorb_chunkdesc_t;
/* giblorb_resdesc_t: Describes one resource in the Blorb file. *//* giblorb_map_t: Holds the complete description of an open Blorb file. *//* holds giblorb_Inited_Magic if the map structure is 
        valid *//* list of chunk descriptors *//* list of resource descriptors */
    giblorb_resdesc_t **ressorted; /* list of pointers to descriptors 
        in map->resources -- sorted by usage and resource number. */
#define giblorb_Inited_Magic (0xB7012BED) 
/* Static variables. *//* First, chew through the file and index the chunks. *//* The basic IFF structure seems to be ok, and we have a list of
        chunks. Now we allocate the map structure itself. *//*map->releasenum = 0;
    map->zheader = NULL;
    map->resolution = NULL;
    map->palettechunk = -1;
    map->palette = NULL;
    map->auxsound = NULL;
    map->auxpict = NULL;*/
    /* Now we do everything else involved in loading the Blorb file,
        such as building resource lists. *//* It is important that the map structure be kept valid during this
        function. If this returns an error, giblorb_destroy_map() will 
        be called. *//* Resource index chunk: build the resource list and 
                sort it. *//* duplicate index chunk *//* bad length field *//* start pos does  
                                not match a real chunk */
                        res->chunknum = ix2;
                        ressorted[jx] = res;
                    /* Sort a resource list (actually a list of pointers to 
                        structures in map->resources.) This makes it easy 
                        to find resources by usage and resource number. *//* Chunk-handling functions. *//* do nothing *//* Sorting and searching. *//* The list is short enough for a bubble-sort. *//* Split the list. *//* Sort the halves. *//* Boring utility functions. If your platform doesn't support ANSI 
    malloc(), feel free to edit these however you like. */
#include <stdlib.h> /* The OS-native header file -- you can edit 

This code uses the PclZip Zip File reading code, which is subject to the GNU LGPL. It also uses the GeSHi syntax highlighter, subject to the GPL. Ask if you want this for your own web site, it's free.