~ubuntu-branches/ubuntu/trusty/eb/trusty

« back to all changes in this revision

Viewing changes to ebinfo/ebinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Tatsuya Kinoshita
  • Date: 2007-02-11 13:51:24 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070211135124-0nq5wjpuum6jnh42
Tags: 4.3-3
libeb12 conflicts with eb-utils (<= 4.3-1) for `eb.mo'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 1997, 98, 99, 2000, 01  
3
 
 *    Motoyuki Kasahara
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2, or (at your option)
8
 
 * any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
 
2
 * Copyright (c) 1997-2006  Motoyuki Kasahara
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 * 1. Redistributions of source code must retain the above copyright
 
8
 *    notice, this list of conditions and the following disclaimer.
 
9
 * 2. Redistributions in binary form must reproduce the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer in the
 
11
 *    documentation and/or other materials provided with the distribution.
 
12
 * 3. Neither the name of the project nor the names of its contributors
 
13
 *    may be used to endorse or promote products derived from this software
 
14
 *    without specific prior written permission.
 
15
 * 
 
16
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
 
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
19
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
 
20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
26
 * SUCH DAMAGE.
14
27
 */
15
28
 
16
29
#ifdef HAVE_CONFIG_H
19
32
 
20
33
#include <stdio.h>
21
34
#include <sys/types.h>
22
 
 
23
 
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
24
35
#include <string.h>
25
 
#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
26
 
#include <memory.h>
27
 
#endif /* not STDC_HEADERS and HAVE_MEMORY_H */
28
 
#else /* not STDC_HEADERS and not HAVE_STRING_H */
29
 
#include <strings.h>
30
 
#endif /* not STDC_HEADERS and not HAVE_STRING_H */
31
 
 
32
 
#ifdef HAVE_STDLIB_H
33
36
#include <stdlib.h>
34
 
#endif
35
37
 
36
38
#include "eb/eb.h"
37
39
#include "eb/error.h"
38
40
#include "eb/font.h"
 
41
#include "eb/booklist.h"
39
42
 
40
43
#include "getopt.h"
41
44
#include "ebutils.h"
42
45
 
43
 
#ifndef HAVE_STRCHR
44
 
#define strchr index
45
 
#define strrchr rindex
46
 
#endif /* HAVE_STRCHR */
47
 
 
48
46
#ifdef ENABLE_NLS
49
47
#ifdef HAVE_LOCALE_H
50
48
#include <locale.h>
53
51
#endif
54
52
 
55
53
/*
56
 
 * Trick for function protypes.
57
 
 */
58
 
#ifndef EB_P
59
 
#ifdef __STDC__
60
 
#define EB_P(p) p
61
 
#else /* not __STDC__ */
62
 
#define EB_P(p) ()
63
 
#endif /* not __STDC__ */
64
 
#endif /* EB_P */
65
 
 
66
 
/*
67
54
 * Tricks for gettext.
68
55
 */
69
56
#ifdef ENABLE_NLS
81
68
/*
82
69
 * Unexported functions.
83
70
 */
84
 
static void output_error_message EB_P((EB_Error_Code));
85
 
static int output_information EB_P((const char *, int));
86
 
static void output_help EB_P((void));
87
 
static void output_multi_information EB_P((EB_Book *));
 
71
static void output_error_message(EB_Error_Code error_code);
 
72
static EB_Error_Code output_booklist(const char *url);
 
73
static EB_Error_Code output_information(const char *book_path, int multi_flag);
 
74
static EB_Error_Code output_multi_information(EB_Book *book);
 
75
static void output_help(void);
88
76
 
89
77
/*
90
78
 * Program name and version.
96
84
/*
97
85
 * Command line options.
98
86
 */
99
 
static const char *short_options = "hmv";
 
87
static const char *short_options = "hlmv";
100
88
static struct option long_options[] = {
101
89
  {"help",         no_argument, NULL, 'h'},
 
90
  {"book-list",    no_argument, NULL, 'l'},
102
91
  {"multi-search", no_argument, NULL, 'm'},
103
92
  {"version",      no_argument, NULL, 'v'},
104
93
  {NULL, 0, NULL, 0}
110
99
#define DEFAULT_BOOK_DIRECTORY  "."
111
100
 
112
101
int
113
 
main(argc, argv)
114
 
    int argc;
115
 
    char *argv[];
 
102
main(int argc, char *argv[])
116
103
{
 
104
    EB_Error_Code error_code;
117
105
    int ch;
118
106
    char *book_path;
 
107
    int booklist_flag;
119
108
    int multi_flag;
120
109
 
121
110
    invoked_name = argv[0];
135
124
     * Parse command line options.
136
125
     */
137
126
    multi_flag = 0;
 
127
    booklist_flag = 0;
 
128
 
138
129
    for (;;) {
139
130
        ch = getopt_long(argc, argv, short_options, long_options, NULL);
140
131
        if (ch == -1)
147
138
            output_help();
148
139
            exit(0);
149
140
 
 
141
        case 'l':
 
142
            /*
 
143
             * Option `-l'.  Display book list on an EBNET server.
 
144
             */
 
145
            booklist_flag = 1;
 
146
            break;
 
147
 
150
148
        case 'm':
151
149
            /*
152
150
             * Option `-m'.  Also output multi-search information.
184
182
    else
185
183
        book_path = argv[optind];
186
184
 
187
 
    if (output_information(book_path, multi_flag) < 0)
 
185
    if (booklist_flag)
 
186
        error_code = output_booklist(book_path);
 
187
    else
 
188
        error_code = output_information(book_path, multi_flag);
 
189
    if (error_code != EB_SUCCESS)
188
190
        exit(1);
189
191
 
190
192
    return 0;
195
197
 * Output an error message to standard error.
196
198
 */
197
199
static void
198
 
output_error_message(error_code)
199
 
    EB_Error_Code error_code;
 
200
output_error_message(EB_Error_Code error_code)
200
201
{
201
202
    fprintf(stderr, "%s: %s\n", invoked_name, eb_error_message(error_code));
202
203
    fflush(stderr);
204
205
 
205
206
 
206
207
/*
 
208
 * Output a list of books that an EBNET server provides.
 
209
 */
 
210
static EB_Error_Code
 
211
output_booklist(const char *url)
 
212
{
 
213
    EB_BookList booklist;
 
214
    EB_Error_Code error_code;
 
215
    int book_count;
 
216
    char *name;
 
217
    char *title;
 
218
    size_t name_length;
 
219
    int i;
 
220
 
 
221
    error_code = eb_initialize_library();
 
222
    if (error_code != EB_SUCCESS) {
 
223
        output_error_message(error_code);
 
224
        return error_code;
 
225
    }
 
226
 
 
227
    eb_initialize_booklist(&booklist);
 
228
 
 
229
    error_code = eb_bind_booklist(&booklist, url);
 
230
    if (error_code != EB_SUCCESS) {
 
231
        output_error_message(error_code);
 
232
        return error_code;
 
233
    }
 
234
 
 
235
    printf("%-20s  %s\n", _("Name"), _("Title"));
 
236
 
 
237
    error_code = eb_booklist_book_count(&booklist, &book_count);
 
238
    if (error_code != EB_SUCCESS) {
 
239
        output_error_message(error_code);
 
240
        return error_code;
 
241
    }
 
242
 
 
243
    for (i = 0; i < book_count; i++) {
 
244
        error_code = eb_booklist_book_name(&booklist, i, &name);
 
245
        if (error_code != EB_SUCCESS) {
 
246
            output_error_message(error_code);
 
247
            break;
 
248
        }
 
249
        error_code = eb_booklist_book_title(&booklist, i, &title);
 
250
        if (error_code != EB_SUCCESS) {
 
251
            output_error_message(error_code);
 
252
            break;
 
253
        }
 
254
 
 
255
        name_length = strlen(name);
 
256
 
 
257
        printf("%-20s  ", name);
 
258
        fputs_eucjp_to_locale(title, stdout);
 
259
        if (4 < name_length && strcmp(name + name_length - 4, ".app") == 0)
 
260
            fputs(" (appendix)", stdout);
 
261
        fputc('\n', stdout);
 
262
    }
 
263
 
 
264
    eb_finalize_booklist(&booklist);
 
265
    eb_finalize_library();
 
266
 
 
267
    return EB_SUCCESS;
 
268
}
 
269
 
 
270
 
 
271
/*
207
272
 * Output information about the book at `path'.
208
273
 * If `multi_flag' is enabled, multi-search information are also output.
209
274
 */
210
 
static int
211
 
output_information(book_path, multi_flag)
212
 
    const char *book_path;
213
 
    int multi_flag;
 
275
static EB_Error_Code
 
276
output_information(const char *book_path, int multi_flag)
214
277
{
215
278
    EB_Book book;
 
279
    EB_Error_Code return_code = EB_SUCCESS;
216
280
    EB_Error_Code error_code;
217
281
    EB_Disc_Code disc_code;
218
282
    EB_Character_Code character_code;
229
293
     * Start to use a book.
230
294
     */
231
295
    error_code = eb_initialize_library();
232
 
    if (error_code != EB_SUCCESS)
 
296
    if (error_code != EB_SUCCESS) {
 
297
        output_error_message(error_code);
 
298
        return_code = error_code;
233
299
        goto failed;
 
300
    }
234
301
    eb_initialize_book(&book);
235
302
    error_code = eb_bind(&book, book_path);
236
 
    if (error_code != EB_SUCCESS)
 
303
    if (error_code != EB_SUCCESS) {
 
304
        output_error_message(error_code);
 
305
        return_code = error_code;
237
306
        goto failed;
 
307
    }
238
308
 
239
309
    /*
240
310
     * Output disc type.
241
311
     */
242
312
    error_code = eb_disc_type(&book, &disc_code);
243
 
    if (error_code != EB_SUCCESS)
 
313
    if (error_code != EB_SUCCESS) {
 
314
        output_error_message(error_code);
 
315
        return_code = error_code;
244
316
        goto failed;
 
317
    }
245
318
    printf(_("disc type: "));
246
319
    if (disc_code == EB_DISC_EB)
247
320
        printf("EB/EBG/EBXA/EBXA-C/S-EBXA\n");
252
325
     * Output character code.
253
326
     */
254
327
    error_code = eb_character_code(&book, &character_code);
255
 
    if (error_code != EB_SUCCESS)
 
328
    if (error_code != EB_SUCCESS) {
 
329
        output_error_message(error_code);
 
330
        return_code = error_code;
256
331
        goto failed;
 
332
    }
257
333
    printf(_("character code: "));
258
334
    switch (character_code) {
259
335
    case EB_CHARCODE_ISO8859_1:
274
350
     * Output the number of subbooks in the book.
275
351
     */
276
352
    error_code = eb_subbook_list(&book, subbook_list, &subbook_count);
277
 
    if (error_code != EB_SUCCESS)
 
353
    if (error_code != EB_SUCCESS) {
 
354
        output_error_message(error_code);
 
355
        return_code = error_code;
278
356
        goto failed;
 
357
    }
279
358
    printf(_("the number of subbooks: %d\n\n"), subbook_count);
280
359
 
281
360
    /*
288
367
         * Output a title of the subbook.
289
368
         */
290
369
        error_code = eb_subbook_title2(&book, subbook_list[i], title);
291
 
        if (error_code != EB_SUCCESS)
 
370
        if (error_code != EB_SUCCESS) {
 
371
            return_code = error_code;
292
372
            continue;
293
 
        printf(_("  title: %s\n"), title);
 
373
        }
 
374
        printf(_("  title: "), title);
 
375
        fputs_eucjp_to_locale(title, stdout);
 
376
        fputc('\n', stdout);
294
377
 
295
378
        /*
296
379
         * Output a directory name of the subbook.
297
380
         */
298
381
        error_code = eb_subbook_directory2(&book, subbook_list[i], directory);
299
 
        if (error_code != EB_SUCCESS)
 
382
        if (error_code != EB_SUCCESS) {
 
383
            return_code = error_code;
300
384
            continue;
 
385
        }
301
386
        printf(_("  directory: %s\n"), directory);
302
387
 
303
388
        /*
306
391
        error_code = eb_set_subbook(&book, subbook_list[i]);
307
392
        if (error_code != EB_SUCCESS) {
308
393
            output_error_message(error_code);
 
394
            return_code = error_code;
309
395
            continue;
310
396
        }
311
397
 
319
405
            fputs(_("endword "), stdout);
320
406
        if (eb_have_keyword_search(&book))
321
407
            fputs(_("keyword "), stdout);
 
408
        if (eb_have_cross_search(&book))
 
409
            fputs(_("cross "), stdout);
322
410
        if (eb_have_multi_search(&book))
323
411
            fputs(_("multi "), stdout);
324
412
        if (eb_have_menu(&book))
325
413
            fputs(_("menu "), stdout);
 
414
        if (eb_have_image_menu(&book))
 
415
            fputs(_("image-menu "), stdout);
326
416
        if (eb_have_copyright(&book))
327
417
            fputs(_("copyright "), stdout);
328
418
        fputc('\n', stdout);
335
425
        if (error_code != EB_SUCCESS) {
336
426
            fputc('\n', stdout);
337
427
            output_error_message(error_code);
 
428
            return_code = error_code;
338
429
        } else {
339
430
            for (j = 0; j < font_count; j++) {
340
431
                error_code = eb_font_height2(font_list[j], &font_height);
341
432
                if (error_code == EB_SUCCESS)
342
433
                    printf("%d ", font_height);
 
434
                else {
 
435
                    output_error_message(error_code);
 
436
                    return_code = error_code;
 
437
                }
343
438
            }
344
439
            fputc('\n', stdout);
345
440
        }
366
461
            else {
367
462
                fputc('\n', stdout);
368
463
                output_error_message(error_code);
 
464
                return_code = error_code;
369
465
            }
370
466
        } else {
371
467
            fputc('\n', stdout);
393
489
            else {
394
490
                fputc('\n', stdout);
395
491
                output_error_message(error_code);
 
492
                return_code = error_code;
396
493
            }
397
494
        } else {
398
495
            fputc('\n', stdout);
399
496
        }
400
497
 
401
 
        if (multi_flag)
402
 
            output_multi_information(&book);
 
498
        if (multi_flag) {
 
499
            error_code = output_multi_information(&book);
 
500
            if (error_code != EB_SUCCESS)
 
501
                return_code = error_code;
 
502
        }
403
503
        fputc('\n', stdout);
404
504
    }
405
505
    fflush(stdout);
410
510
    eb_finalize_book(&book);
411
511
    eb_finalize_library();
412
512
 
413
 
    return 0;
 
513
    return return_code;
414
514
 
415
515
    /*
416
516
     * An error occurs...
418
518
  failed:
419
519
    fflush(stdout);
420
520
    fflush(stderr);
421
 
    output_error_message(error_code);
422
521
    eb_finalize_book(&book);
423
522
    eb_finalize_library();
424
523
 
425
 
    return -1;
 
524
    return return_code;
426
525
}
427
526
 
428
527
/*
429
528
 * Output information about multi searches.
430
529
 */
431
 
static void
432
 
output_multi_information(book)
433
 
    EB_Book *book;
 
530
static EB_Error_Code
 
531
output_multi_information(EB_Book *book)
434
532
{
 
533
    EB_Error_Code return_code = EB_SUCCESS;
435
534
    EB_Error_Code error_code;
436
535
    EB_Multi_Search_Code multi_list[EB_MAX_MULTI_SEARCHES];
437
536
    int multi_count;
440
539
    char entry_label[EB_MAX_MULTI_LABEL_LENGTH + 1];
441
540
    int i, j;
442
541
 
 
542
    /*
 
543
     * Get a list of mutli search codes.
 
544
     */
443
545
    error_code = eb_multi_search_list(book, multi_list, &multi_count);
444
546
    if (error_code != EB_SUCCESS) {
445
547
        output_error_message(error_code);
446
 
        return;
 
548
        return_code = error_code;
 
549
        multi_count = 0;
447
550
    }
 
551
 
 
552
    /*
 
553
     * Output information.
 
554
     */
448
555
    for (i = 0; i < multi_count; i++) {
449
556
        printf(_("  multi search %d:\n"), i + 1);
450
557
        error_code = eb_multi_entry_count(book, multi_list[i], &entry_count);
451
558
        if (error_code != EB_SUCCESS) {
452
559
            output_error_message(error_code);
 
560
            return_code = error_code;
453
561
            continue;
454
562
        }
455
563
 
456
564
        error_code = eb_multi_title(book, multi_list[i], search_title);
457
565
        if (error_code != EB_SUCCESS) {
458
566
            output_error_message(error_code);
 
567
            return_code = error_code;
459
568
            continue;
460
569
        }
461
 
        printf(_("    title: %s\n"), search_title);
 
570
        printf(_("    title: "), search_title);
 
571
        fputs_eucjp_to_locale(search_title, stdout);
 
572
        fputc('\n', stdout);
462
573
 
463
574
        for (j = 0; j < entry_count; j++) {
464
575
            error_code = eb_multi_entry_label(book, multi_list[i], j,
465
576
                entry_label);
466
577
            if (error_code != EB_SUCCESS) {
467
578
                output_error_message(error_code);
 
579
                return_code = error_code;
468
580
                continue;
469
581
            }
470
582
 
471
 
            printf(_("    label %d: %s\n"), j + 1, entry_label);
 
583
            printf(_("    label %d: "), j + 1);
 
584
            fputs_eucjp_to_locale(entry_label, stdout);
 
585
            fputc('\n', stdout);
 
586
 
472
587
            fputs(_("      candidates: "), stdout);
473
588
            if (eb_multi_entry_have_candidates(book, multi_list[i], j))
474
589
                fputs(_("exist\n"), stdout);
475
 
            else 
 
590
            else
476
591
                fputs(_("not-exist\n"), stdout);
477
592
        }
478
593
    }
 
594
 
479
595
    fflush(stdout);
 
596
 
 
597
    return return_code;
480
598
}
481
599
 
482
600
 
484
602
 * Output help message to stdandard out.
485
603
 */
486
604
static void
487
 
output_help()
 
605
output_help(void)
488
606
{
489
607
    printf(_("Usage: %s [option...] [book-directory]\n"),
490
608
        program_name);
491
609
    printf(_("Options:\n"));
492
610
    printf(_("  -h  --help                 display this help, then exit\n"));
 
611
    printf(_("  -l  --book-list            output a list of books on an EBENT server\n"));
493
612
    printf(_("  -m  --multi-search         also output multi-search information\n"));
494
613
    printf(_("  -v  --version              display version number, then exit\n"));
495
614
    printf(_("\nArgument:\n"));