[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5. Subbook

A CD-ROM book usually has some subbooks. For example, a certain CD-ROM book has three subbooks; Japanese dictionary, English dictinary and Encyclopedia. Each subbook itself is an independent book.

 
           (CD-ROM book)
+---------------------------------+
| [Japanese Dicctionary](subbook) |
|                                 |
| [English Dicctionary] (subbook) |
|                                 |
| [Encyclopedia]        (subbook) |
+---------------------------------+

EB Library assigns a subbook code to each subbook. EB Library uses the code to identify a subbook, so that each subbook code is unique in a book. The type EB_Subbook_Code represents the subbook code. eb_subbook_list() returns a list of subbook codes of all subbooks in a book. The following source code is an example of eb_subbook_list().

 
/* It assumes that book is a variable of EB_Book and */
/* it has already been bound to a book.                  */
EB_Subbook_Code subbook_codes[EB_MAX_SUBBOOKS];
int count, i;

count = eb_subbook_list(&book, subbook_codes);
if (count == -1) {
    fprintf(stderr, "failed to get a subbook list, %s\n",
        eb_error_message());
}

If eb_subbook_list() succeeds, the subbook list is stored into subbook_codes. The subbook code of the first subbook in the list is represented as subbook_codes[0], the next code is represented as subbook_codes[1], and so on. The last code is represented as subbook_codes[count -1], because eb_subbook_list() returns the number of subbooks in the book. For example, you can get the title of the first subbook by the following way.

 
title = eb_subbook_title2(&book, subbook_codes[0]);

5.1 Current Subbook  
5.2 Sample Program  
5.3 Data Types  
5.4 Functions  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1 Current Subbook

Only one subbook may becomes the current subbook in a book at the same time. Most operations, such as searching a word and getting text, are permitted to the current subbook only. The function eb_set_subbook() sets the current subbook to the specified subbook.

 
(EB_Book object)                        (CD-ROM book)
  +-------+                  +---------------------------------+
  |current|                  | [Japanese Dicctionary](subbook) |
  |subbook| eb_set_subbook() |                                 |
  |   *----------------------->[English Dicctionary] (subbook) |
  |       |                  |                                 |
  +-------+                  | [Encyclopedia]        (subbook) |
                             +---------------------------------+

At the initial state, no subbok is selected as the current subbook.

eb_set_subbook() takes a subbook code as an argument. If the function succeeds, the subbook of the code is set to the current subbook. The following source code is an example of eb_set_subbook().

 
/* It assumes that book is a variable of EB_Book and */
/* it has already been bound to a book.                  */
EB_Subbook_Code subbook_codes[EB_MAX_SUBBOOKS];
int count, i;

count = eb_subbook_list(&book, subbook_codes);
if (count == -1) {
    /* eb_subbook_list() is failed */
}

for (i = 0; i < count; i++) {
    if (eb_set_subbook(&book, subbook_codes[i]) == -1) {
        /* eb_set_subbook() is failed */
    }
}


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.2 Sample Program

 
/*
 * Filename:
 *     subbook.c
 *
 * Usage:
 *     subbook book-path
 *
 * Example:
 *     subbook /cdrom
 *
 * Description:
 *     This program shows titles of subbooks in a 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_Subbook_Code sublist[EB_MAX_SUBBOOKS];
    int subcount;
    const char *title;
    int i;

    /*
     * 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 to `book'.
     */
    if (eb_bind(&book, argv[1]) == -1) {
	fprintf(stderr, "%s: failed to bind the book, %s: %s\n",
	    argv[0], eb_error_message(), argv[1]);
	exit(1);
    }

    /*
     * Get the subbook list.
     */
    subcount = eb_subbook_list(&book, sublist);
    if (subcount < 0) {
	fprintf(stderr, "%s: failed to get the subbbook list, %s\n",
	    argv[0], eb_error_message());
	eb_clear(&book);
	exit(1);
    }

    /*
     * Output titles of subbooks in the book.
     */
    for (i = 0; i < subcount; i++) {
	title = eb_subbook_title2(&book, sublist[i]);
	if (title == NULL) {
	    fprintf(stderr, "%s: failed to get the title, %s\n",
		argv[0], eb_error_message());
	    continue;
	}
	printf("%d: %s\n", i, title);
    }

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

    exit(0);
}


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3 Data Types

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

 
#include <eb/eb.h>

Data type: EB_Subbook_Code

The EB_Subbook_Code data type represents a subbook code. Each subbook in a book has an unique subbook code. This type is defined from a signed integral type, so that you can compare two codes by the == and != binomial operators.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.4 Functions

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

 
#include <eb/eb.h>

Function: int eb_initialize_all_subbooks (EB_Book *book)

The function eb_initialize_all_subbooks() initializes all subbooks in book. book must have been bound beforehand.

Usually, initialization of a subbook is done at the first time the subbook is set as the current subbook. The function does the initialization in advance. This function is usuful for standalone server applications. Call eb_initialize_all_subbooks() before accepting connections from clients. When a connected client requests to set a subbook, the server can respond to the request faster than usual because the initialization of the subbook has already been done.

If succeeds, it returns the number of subbooks in book. Otherwise, it returns -1 and sets eb_error. This function never changes the current subbook of book.

Function: int eb_subbook_count (EB_Book *book)

The function eb_subbook_count() gets the number of subbooks in book. book must have been bound beforehand.

If succeeds, it returns the number of subbooks. Otherwise, it returns -1 and sets eb_error.

Function: int eb_subbook_list (EB_Book *book, EB_Subbook_Code *list)

The function eb_subbook_list() makes a list of the subbook codes of the subbooks in book. book must have been bound beforehand. This function puts the generated list into list as an array of EB_Subbook_Code. The array contains EB_MAX_SUBBOOKS elements maximum.

If succeeds, it returns the number of subbooks in book. Otherwise, it returns -1 and sets eb_error.

Function: EB_Subbook_Code eb_subbook (EB_Book *book)

The function eb_subbook() gets the subbook code of the current subbook of book. The current subbook of book must have been set beforehand.

If succeeds, it returns the number of subbooks in book. Otherwise, it returns -1 and sets eb_error.

Function: const char * eb_subbook_title (EB_Book *book)

The function eb_subbook_title() gets the title of the current subbook of book. The current subbook of book must have been set beforehand. The length of the title string is EB_MAXLEN_TITLE maximum. The length doesn't count the terminating NUL character. The title is written in EUC-JP or ISO 8859-1.

If succeeds, it returns the title (e.g. "English Japanese Dictionary"). Otherwise, it returns NULL and sets eb_error.

Please note that the title returned from this function is a constant string kept in book. When book becomes unbound (i.e. call eb_clear for book), also the title string is destroyed. Accordingly, you must not refer to the title in the unbound book.

Function: const char * eb_subbook_title2 (EB_Book *book, EB_Subbook_Code code)

The function eb_subbook_title2() is the same as eb_subbook_title(), except that it returns the title of the subbook specified at the argument code. The current subbook of book may be unset, but book must have been bound beforehand.

Function: const char * eb_subbook_directory (EB_Book *book)

The function eb_subbook_directory() gets the directory name of the current subbook of book. The current subbook of book must have been set beforehand. All files which belong to the current subbook are resides under the directory relative to the top directory of the CD-ROM book. The length of the directory name is EB_MAXLEN_BASENAME maximum. The length doesn't count the terminating NUL character. The directory name consists of `d' characters (space, digit, upper case letter, and underscore) defined in ISO 9660.

If succeeds, it returns the directory name (e.g. "JPDICT"). Otherwise, it returns NULL and sets eb_error.

Please note that the directory name returned from this function is a constant string kept in book. When book becomes unbound (i.e. call eb_clear for book), also the directory name is destroyed. Accordingly, you must not refer to the directory name in the unbound book.

Function: const char * eb_subbook_directory2 (EB_Book *book, EB_Subbook_Code code)

The function eb_subbook_directory2() is the same as eb_subbook_directory(), except that it returns the directory name of the subbook specified at the argument code. The current subbook of book may be unset, but book must have been bound beforehand.

Function: int eb_set_subbook (EB_Book *book, EB_Subbook_Code code)

The function eb_set_subbook() sets the current subbook of book to code. book must have been bound beforehand. When the current subbook has already been set to the specified subbook, this function unsets the current subbook, and then it sets the current subbook to code.

If succeeds, it returns 0. Otherwise, it returns -1, sets eb_error, and unsets the current subbook.

Function: void eb_unset_subbook (EB_Book *book)

The function eb_unset_subbook() unsets the current subbook of book. If book is unbound, or if the current subbook has not been set, this function does nothing.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Motoyuki Kasahara on July, 7 2000 using texi2html