Go to the first, previous, next, last section, table of contents.


Initialization

In EB Library, all accesses to a CD-ROM book are done through a data object of the EB_Book type.

EB_Book book;

Of course, the space of the data object may be allocated by malloc():

EB_Book *book_pointer;

book_pointer = (EB_Book *) malloc(sizeof(EB_Book));

Since contents of the EB_Book object (i.e. the contents of the book variable, and the space refered by book_pointer) have not initialized yet, we initialize the object by the following way:

eb_initialize(&book);
eb_initialize(book_pointer);

Please note that an argument passed to eb_initialize() is a pointer to a EB_Book object, not a EB_Book object itself. Many functions in EB Library take a pointer to EB_Book object as the first argument.

Then, we bind the EB_Book object to a CD-ROM book entity. It is done by the function eb_bind().

(EB_Book object)            (CD-ROM book)
  +-------+             +-------------------+
  |       |  eb_bind()  |                   |
  |       |=============|    /mnt/cdrom     |
  +-------+             |                   |
                        +-------------------+

This is the sample source code of eb_bind():

if (eb_bind(&book, "/mnt/cdrom") == -1) {
    fprintf(stderr, "failed to bind the book\n");
    exit(1);
}

The path `/mnt/cdrom' is the top directory of the book where the file `CATALOG' or `CATALOGS' resides. When eb_bind() is failed, it returns -1. However, meaning of the return value are not important at this point. Details about error handling are described at section Error Handling.

Contrary to eb_bind(), eb_clear() undoes the binding. When you close a book, you must invoke eb_clear() to the EB_Book object bound to the book. A bound object opens some files and allocates memories internally. eb_clear() closes all opened files and release all allocated memories.

(EB_Book object)            (CD-ROM book)
  +-------+             +-------------------+
  |       |  eb_clear() |                   |
  |       |=           =|    /mnt/cdrom     |
  +-------+             |                   |
                        +-------------------+

This is the sample source code of eb_clear():

eb_clear(&book);

A EB_Book object whose memories are allocated by malloc() can be released by free() safely when the object is unbound.

Compressed Book

EB Library can access a book compressed by the ebzip command. Since the library automatically uncompress data, you don't have to be aware of whether the bound book is compressed or not.

(see see section `Compression' in ebzip, for more details about compression).

Sample Program

/*
 * Filename:
 *     disctype.c
 *
 * Usage:
 *     disctype book-path
 *
 * Example:
 *     disctype /cdrom
 *
 * Description:
 *     This program shows disc type (EB/EBG/EBXA/EBXA-C/S-EBXA or
 *     EPWING) of a CD-ROM book.  `book-path' points to the top
 *     directory of the CD-ROM book where the file CATALOG or CATALOGS
 *     resides.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#include <eb/eb.h>
#include <eb/error.h>

int
main(argc, argv)
    int argc;
    char *argv[];
{
    EB_Book book;
    EB_Disc_Code disc_code;

    /*
     * Check for command line arguments.
     */
    if (argc != 2) {
	fprintf(stderr, "Usage: %s book-path\n", argv[0]);
	exit(1);
    }

    /*
     * Initialize `book'.
     */
    eb_initialize(&book);

    /*
     * Bind a book.  Exit if it fails.
     */
    if (eb_bind(&book, argv[1]) == -1) {
	fprintf(stderr, "%s: failed to bind the book: %s\n",
	    argv[0], argv[1]);
	exit(1);
    }

    /*
     * Show disc type.
     */
    disc_code = eb_disc_type(&book);
    fputs("disc type: ", stdout);
    if (disc_code == EB_DISC_EB) {
	fputs("EB/EBG/EBXA", stdout);
    } else if (disc_code == EB_DISC_EPWING) {
	fputs("WPING", stdout);
    } else {
	fputs("unknown", stdout);
    }
    fputc('\n', stdout);

    /*
     * Clear the book.
     */
    eb_clear(&book);

    exit(0);
}

Data Types

Please include `eb/eb.h' to use the data types described in this section:

#include <eb/eb.h>

Data type: EB_Book

The data type EB_Book represents a CD-ROM book. In EB Library, all accesses to the CD-ROM book are done through an object of this type.

Data type: EB_Disc_Code

The data type EB_Disc_Code represents a format code of CD-ROM book. EB_DISC_EB and EB_DISC_EPWING are currently defined as the format codes. This type is defined from a signed integral type, so that you can compare two codes by the == and != binomial operators.

Data type: EB_Character_Code

The EB_Character_Code type represents a character code used in a CD-ROM book. EB_CHARCODE_ISO8859_1 and EB_CHARCODE_JISX0208 are currently defined as the character codes. This type is defined from a signed integral type, so that you can compare two codes by the == and != binomial operators.

Functions

Please include `eb/eb.h' to use the functions described in this section:

#include <eb/eb.h>

(see section Error Handling for more details about error codes and the global variable eb_error).

Function: void eb_initialize (EB_Book *book)

The function eb_initialize() initializes an EB_Book object pointed by book. Each object must be initialized just once, before any other EB Library function is called to the object.

Don't call another EB Library function to an uninitialized object. Don't call eb_initialize() twice to an object. They may cause memory leak.

Function: int eb_bind (EB_Book *book, const char *path)

The function eb_bind() binds an EB_Book object pointed by book to a CD-ROM book on path. The path must points to the top directory of the book where the file `CATALOG' or `CATALOGS' resides. If the path may not be started with slash (/), it is assumed that the path is relative to the current directory. The empty path is assumed to be the current directory (.). If book has already bound a book, this function unbinds it, and then binds the object to the book on path.

If it succeeds to bind the object, it returns 0. Otherwise, it returns -1, and sets eb_errno. In this case, the object becomes unbound.

Function: void eb_suspend (EB_Book *book)

The function eb_suspend() unsets all current status in an EB_Book object; unsets the current subbook, current language, and current font height. If the EB_Book object is unbound, or has already been suspended, this function does nothing.

Function: void eb_clear (EB_Book *book)

The function eb_clear() unbinds an EB_Book object pointed by book. All alocated memories kept in the object are released, and all file descriptors managed by the object are closed. The function does nothing to an object which has already been unbound. To use the object again, you must call eb_bind() for it.

Function: int eb_is_bound (EB_Book *book)

The function eb_is_bound() examines whether book is bound or not. If it is bound, this function returns 1. Otherwise it returns 0, and it sets eb_error to EB_ERR_UNBOUND_BOOK.

Function: const char * eb_path (EB_Book *book)

The function eb_path() returns the path of the book bound to book. book must have been bound beforehand.

The returned path may be different from that specified at eb_bind(), since the function always returns the path as canonicalized form. The term canonicalized means:

If succeeds, this function returns the path. Otherwise, it returns -1 and sets eb_error.

Function: EB_Disc_Code eb_disc_type (EB_Book *book)

The function eb_disc_type() inspects the format type of book. book must have been bound beforehand.

If the book is EB/EBG/EBXA/EBXA-C/S-EBXA, it returns EB_DISC_EB. If the book is EPWING, it returns EB_DISC_EPWING. If this function fails, it returns -1 and sets eb_error.

Function: EB_Character_Code eb_character_code (EB_Book *book)

The function eb_character_code() inspects the character code in which book is written. book must have been bound beforehand.

If the book is written in ISO 8859-1, it returns EB_CHARCODE_ISO8859_1. If the book is written in JIS X 0208, it returns EB_CHARCODE_JISX0208. If this function fails, it returns -1 and sets eb_error.


Go to the first, previous, next, last section, table of contents.