From 09ee6ebc4ca6284aef70d87a4abd6bd6d43f54f7 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 23 Jun 2004 12:57:16 -0500 Subject: [svn-r8733] Purpose: Code cleanup Description: Reduce compiler warnings on SGI IRIX Platforms tested: FreeBSD 4.10 (sleipnir) SGI IRIX6 (Cheryl's machine) Too minor to require full h5committest --- config/irix6.x | 4 ++-- perform/perf_meta.c | 6 ++++-- src/H5.c | 7 +++---- src/H5AC.c | 12 +++++++----- src/H5D.c | 6 +++--- src/H5Distore.c | 6 +++++- src/H5MM.c | 4 ++-- src/H5Olayout.c | 6 ++---- src/H5Omtime.c | 4 +++- src/H5Sall.c | 2 +- src/H5Shyper.c | 3 +-- src/H5Snone.c | 2 +- src/H5Sselect.c | 8 ++++++++ src/H5Tvlen.c | 4 +--- test/dtypes.c | 3 +-- tools/h5dump/h5dump.c | 2 +- 16 files changed, 45 insertions(+), 34 deletions(-) diff --git a/config/irix6.x b/config/irix6.x index a79613a..44785c0 100644 --- a/config/irix6.x +++ b/config/irix6.x @@ -73,11 +73,11 @@ case "X-$CC_BASENAME" in DEBUG_CPPFLAGS= # Extra production flags - PROD_CFLAGS="-O -s" + PROD_CFLAGS="-O -OPT:Olimit=0 -s" PROD_CPPFLAGS= # Extra profiling flags - PROFILE_CFLAGS=-pg + PROFILE_CFLAGS= PROFILE_CPPFLAGS= ;; esac diff --git a/perform/perf_meta.c b/perform/perf_meta.c index 9609b62..55adc57 100644 --- a/perform/perf_meta.c +++ b/perform/perf_meta.c @@ -668,15 +668,17 @@ error: */ double retrieve_time(void) { +#ifdef H5_HAVE_PARALLEL if(facc_type == FACC_DEFAULT) { +#endif /*H5_HAVE_PARALLEL*/ struct timeval t; gettimeofday(&t, NULL); return ((double)t.tv_sec + (double)t.tv_usec / 1000000); - } else { #ifdef H5_HAVE_PARALLEL + } else { return MPI_Wtime(); -#endif /*H5_HAVE_PARALLEL*/ } +#endif /*H5_HAVE_PARALLEL*/ } diff --git a/src/H5.c b/src/H5.c index 5c5f3ad..6f810bf 100644 --- a/src/H5.c +++ b/src/H5.c @@ -318,11 +318,10 @@ H5dont_atexit(void) H5TRACE0("e",""); if (dont_atexit_g) - HGOTO_DONE(FAIL); + ret_value=FAIL; + else + dont_atexit_g = TRUE; - dont_atexit_g = TRUE; - -done: FUNC_LEAVE_API(ret_value); } diff --git a/src/H5AC.c b/src/H5AC.c index 254d928..1f866e3 100644 --- a/src/H5AC.c +++ b/src/H5AC.c @@ -194,12 +194,10 @@ H5AC_init_interface(void) unsigned block_before_meta_write; /* "block before meta write" property value */ unsigned library_internal=1; /* "library internal" property value */ H5FD_mpio_xfer_t xfer_mode; /* I/O transfer mode property value */ -#endif /* H5_HAVE_PARALLEL */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5AC_init_interface); -#ifdef H5_HAVE_PARALLEL /* Sanity check */ assert(H5P_CLS_DATASET_XFER_g!=(-1)); @@ -272,17 +270,21 @@ H5AC_init_interface(void) xfer_mode=H5FD_MPIO_INDEPENDENT; if (H5P_set(xfer_plist,H5D_XFER_IO_XFER_MODE_NAME,&xfer_mode)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set value"); + +done: + FUNC_LEAVE_NOAPI(ret_value); #else /* H5_HAVE_PARALLEL */ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5AC_init_interface); + /* Sanity check */ assert(H5P_LST_DATASET_XFER_g!=(-1)); H5AC_dxpl_id=H5P_DATASET_XFER_DEFAULT; H5AC_noblock_dxpl_id=H5P_DATASET_XFER_DEFAULT; H5AC_ind_dxpl_id=H5P_DATASET_XFER_DEFAULT; -#endif /* H5_HAVE_PARALLEL */ -done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(SUCCEED); +#endif /* H5_HAVE_PARALLEL */ } /* end H5AC_init_interface() */ diff --git a/src/H5D.c b/src/H5D.c index 90932b5..e6b3ef9 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -607,7 +607,7 @@ done: *------------------------------------------------------------------------- */ static int -H5D_crt_fill_value_cmp(const void *value1, const void *value2, size_t size) +H5D_crt_fill_value_cmp(const void *value1, const void *value2, size_t UNUSED size) { const H5O_fill_t *fill1=(const H5O_fill_t *)value1, /* Create local aliases for values */ *fill2=(const H5O_fill_t *)value2; @@ -663,7 +663,7 @@ done: *------------------------------------------------------------------------- */ static int -H5D_crt_ext_file_list_cmp(const void *value1, const void *value2, size_t size) +H5D_crt_ext_file_list_cmp(const void *value1, const void *value2, size_t UNUSED size) { const H5O_efl_t *efl1=(const H5O_efl_t *)value1, /* Create local aliases for values */ *efl2=(const H5O_efl_t *)value2; @@ -745,7 +745,7 @@ done: *------------------------------------------------------------------------- */ static int -H5D_crt_data_pipeline_cmp(const void *value1, const void *value2, size_t size) +H5D_crt_data_pipeline_cmp(const void *value1, const void *value2, size_t UNUSED size) { const H5O_pline_t *pline1=(const H5O_pline_t *)value1, /* Create local aliases for values */ *pline2=(const H5O_pline_t *)value2; diff --git a/src/H5Distore.c b/src/H5Distore.c index 9d30387..4abf0e1 100644 --- a/src/H5Distore.c +++ b/src/H5Distore.c @@ -1694,7 +1694,9 @@ H5D_istore_readvv(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_cache, hid_t dxp { H5D_istore_ud1_t udata; /*B-tree pass-through */ haddr_t chunk_addr; /* Chunk address on disk */ +#ifndef NDEBUG size_t u; /* Local index variables */ +#endif ssize_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5D_istore_readvv, FAIL); @@ -1797,7 +1799,9 @@ H5D_istore_writevv(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_cache, { H5D_istore_ud1_t udata; /*B-tree pass-through */ haddr_t chunk_addr; /* Chunk address on disk */ +#ifndef NDEBUG size_t u; /* Local index variables */ +#endif ssize_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5D_istore_writevv, FAIL); @@ -2023,7 +2027,7 @@ H5D_istore_get_addr(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, unsigned u; haddr_t ret_value; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5D_istore_get_addr); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5D_istore_get_addr); assert(f); assert(layout && (layout->u.chunk.ndims > 0)); diff --git a/src/H5MM.c b/src/H5MM.c index dc3cd2c..afbf8b4 100644 --- a/src/H5MM.c +++ b/src/H5MM.c @@ -59,7 +59,7 @@ void * H5MM_malloc(size_t size) { /* Use FUNC_ENTER_NOAPI_NOINIT here to avoid performance issues */ - FUNC_ENTER_NOAPI_NOINIT(H5MM_malloc); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5MM_malloc); assert(size); @@ -92,7 +92,7 @@ void * H5MM_calloc(size_t size) { /* Use FUNC_ENTER_NOAPI_NOINIT here to avoid performance issues */ - FUNC_ENTER_NOAPI_NOINIT(H5MM_calloc); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5MM_calloc); assert(size); diff --git a/src/H5Olayout.c b/src/H5Olayout.c index 0b6b4a8..1839343 100644 --- a/src/H5Olayout.c +++ b/src/H5Olayout.c @@ -128,7 +128,7 @@ H5O_layout_decode(H5F_t *f, hid_t UNUSED dxpl_id, const uint8_t *p, H5O_shared_t HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "dimensionality is too large"); /* Layout class */ - mesg->type = *p++; + mesg->type = (H5D_layout_t)*p++; assert(H5D_CONTIGUOUS == mesg->type || H5D_CHUNKED == mesg->type || H5D_COMPACT == mesg->type); /* Reserved bytes */ @@ -176,7 +176,7 @@ H5O_layout_decode(H5F_t *f, hid_t UNUSED dxpl_id, const uint8_t *p, H5O_shared_t } /* end if */ else { /* Layout class */ - mesg->type = *p++; + mesg->type = (H5D_layout_t)*p++; /* Interpret the rest of the message according to the layout class */ switch(mesg->type) { @@ -340,7 +340,6 @@ H5O_layout_encode(H5F_t *f, uint8_t *p, const void *_mesg) default: HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "Invalid layout class"); - break; } /* end switch */ } /* end else */ @@ -502,7 +501,6 @@ H5O_layout_meta_size(H5F_t *f, const void *_mesg) default: HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, 0, "Invalid layout class"); - break; } /* end switch */ } /* end else */ diff --git a/src/H5Omtime.c b/src/H5Omtime.c index 0f56ee1..ac99bc1 100644 --- a/src/H5Omtime.c +++ b/src/H5Omtime.c @@ -120,6 +120,7 @@ H5O_mtime_new_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const uint8_t *p, H5O_shared_t UNUSED *sh) { time_t *mesg, the_time; + uint32_t tmp_time; /* Temporary copy of the time */ int version; /* Version of mtime information */ void *ret_value; /* Return value */ @@ -139,7 +140,8 @@ H5O_mtime_new_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const uint8_t *p, p+=3; /* Get the time_t from the file */ - UINT32DECODE(p, the_time); + UINT32DECODE(p, tmp_time); + the_time=(time_t)tmp_time; /* The return value */ if (NULL==(mesg = H5FL_MALLOC(time_t))) diff --git a/src/H5Sall.c b/src/H5Sall.c index 8b53cb9..e004800 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -415,7 +415,7 @@ done: REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_all_copy(H5S_t *dst, const H5S_t *src, hbool_t UNUSED share_selection) +H5S_all_copy(H5S_t *dst, const H5S_t UNUSED *src, hbool_t UNUSED share_selection) { herr_t ret_value=SUCCEED; /* return value */ diff --git a/src/H5Shyper.c b/src/H5Shyper.c index c93c704..269b030 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -5934,7 +5934,6 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, size_t span_size=0; /* Number of bytes in current span to actually process */ size_t io_left; /* Number of elements left to process */ size_t io_bytes_left; /* Number of bytes left to process */ - size_t start_io_bytes_left; /* Initial number of bytes left to process */ size_t io_used; /* Number of elements processed */ size_t curr_seq=0; /* Number of sequence/offsets stored in the arrays */ size_t elem_size; /* Size of each element iterating over */ @@ -5969,7 +5968,7 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, /* Set the amount of elements to perform I/O on, etc. */ H5_CHECK_OVERFLOW(iter->elmt_left,hsize_t,size_t); io_left=MIN(maxelem,(size_t)iter->elmt_left); - start_io_bytes_left=io_bytes_left=io_left*elem_size; + io_bytes_left=io_left*elem_size; /* Compute the cumulative size of dataspace dimensions */ for(i=fast_dim, acc=elem_size; i>=0; i--) { diff --git a/src/H5Snone.c b/src/H5Snone.c index 9e5e726..6a07a47 100644 --- a/src/H5Snone.c +++ b/src/H5Snone.c @@ -383,7 +383,7 @@ done: REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_none_copy(H5S_t *dst, const H5S_t *src, hbool_t UNUSED share_selection) +H5S_none_copy(H5S_t *dst, const H5S_t UNUSED *src, hbool_t UNUSED share_selection) { herr_t ret_value=SUCCEED; /* return value */ diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 891e812..31d9a41 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -37,9 +37,11 @@ static int interface_initialize_g = 0; /* Local functions */ +#ifdef LATER static herr_t H5S_select_iter_block (const H5S_sel_iter_t *iter, hssize_t *start, hssize_t *end); static htri_t H5S_select_iter_has_next_block (const H5S_sel_iter_t *iter); static herr_t H5S_select_iter_next_block(H5S_sel_iter_t *iter); +#endif /* LATER */ /* Declare external the free list for hssize_t arrays */ H5FL_ARR_EXTERN(hssize_t); @@ -843,6 +845,7 @@ done: FUNC_LEAVE_NOAPI(ret_value); } /* H5S_select_iter_coords() */ +#ifdef LATER /*-------------------------------------------------------------------------- NAME @@ -884,6 +887,7 @@ H5S_select_iter_block (const H5S_sel_iter_t *iter, hssize_t *start, hssize_t *en FUNC_LEAVE_NOAPI(ret_value); } /* H5S_select_iter_block() */ +#endif /* LATER */ /*-------------------------------------------------------------------------- @@ -923,6 +927,7 @@ done: FUNC_LEAVE_NOAPI(ret_value); } /* H5S_select_iter_nelmts() */ +#ifdef LATER /*-------------------------------------------------------------------------- NAME @@ -960,6 +965,7 @@ H5S_select_iter_has_next_block (const H5S_sel_iter_t *iter) FUNC_LEAVE_NOAPI(ret_value); } /* H5S_select_iter_has_next_block() */ +#endif /* LATER */ /*-------------------------------------------------------------------------- @@ -1005,6 +1011,7 @@ done: FUNC_LEAVE_NOAPI(ret_value); } /* H5S_select_iter_next() */ +#ifdef LATER /*-------------------------------------------------------------------------- NAME @@ -1044,6 +1051,7 @@ H5S_select_iter_next_block(H5S_sel_iter_t *iter) FUNC_LEAVE_NOAPI(ret_value); } /* H5S_select_iter_next_block() */ +#endif /* LATER */ /*-------------------------------------------------------------------------- diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 6ab21d1..2de8db6 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -754,10 +754,8 @@ H5T_vlen_disk_getlen(void *_vl) *------------------------------------------------------------------------- */ static void * -H5T_vlen_disk_getptr(void *_vl) +H5T_vlen_disk_getptr(void UNUSED *vl) { - uint8_t *vl=(uint8_t *)_vl; /* Pointer to the disk VL information */ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_vlen_disk_getptr) /* check parameters */ diff --git a/test/dtypes.c b/test/dtypes.c index 8393c5d..24f78a8 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -1663,10 +1663,9 @@ test_compound_10(void) cmpd_struct wdata[ARRAY_DIM]; cmpd_struct rdata[ARRAY_DIM]; hid_t file; - hid_t arr_tid, cmpd_tid, cstr_id, vlstr_id, dup_tid; + hid_t arr_tid, cmpd_tid, cstr_id, vlstr_id; hid_t space_id; hid_t dset_id; - hid_t xfer_pid; hsize_t arr_dim[1] = {ARRAY_DIM}; /* Array dimensions */ hsize_t dim1[1]; void *t1, *t2; diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index f608c45..3cbef84 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -2419,7 +2419,7 @@ dump_fcpl(hid_t fid) indentation(indent + COL); printf("%s %d\n","OBJECTHEADER_VERSION", shhdr); indentation(indent + COL); - printf("%s %d\n","USERBLOCK_VERSION", userblock); + HDfprintf(stdout,"%s %Hu\n","USERBLOCK_VERSION", userblock); indentation(indent + COL); printf("%s %d\n","OFFSET_SIZE", off_size); indentation(indent + COL); -- cgit v0.12 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

/*
  config.cpp
*/

#include <QtCore>

#include "archiveextractor.h"
#include "config.h"
#include "uncompressor.h"
#include <stdlib.h>

QT_BEGIN_NAMESPACE

/*
  An entry on the MetaStack.
 */
class MetaStackEntry
{
public:
    void open();
    void close();

    QStringList accum;
    QStringList next;
};

/*
 */
void MetaStackEntry::open()
{
    next.append(QString());
}

/*
 */
void MetaStackEntry::close()
{
    accum += next;
    next.clear();
}

/*
  ###
*/
class MetaStack : private QStack<MetaStackEntry>
{
public:
    MetaStack();

    void process(QChar ch, const Location& location);
    QStringList getExpanded(const Location& location);
};

MetaStack::MetaStack()
{
    push(MetaStackEntry());
    top().open();
}

void MetaStack::process(QChar ch, const Location& location)
{
    if (ch == QLatin1Char('{')) {
        push(MetaStackEntry());
        top().open();
    }
    else if (ch == QLatin1Char('}')) {
        if (count() == 1)
            location.fatal(tr("Unexpected '}'"));

        top().close();
        QStringList suffixes = pop().accum;
        QStringList prefixes = top().next;

        top().next.clear();
        QStringList::ConstIterator pre = prefixes.begin();
        while (pre != prefixes.end()) {
                QStringList::ConstIterator suf = suffixes.begin();
            while (suf != suffixes.end()) {
            top().next << (*pre + *suf);
            ++suf;
            }
            ++pre;
        }
    }
    else if (ch == QLatin1Char(',') && count() > 1) {
        top().close();
        top().open();
    }
    else {
        QStringList::Iterator pre = top().next.begin();
        while (pre != top().next.end()) {
            *pre += ch;
            ++pre;
        }
    }
}

QStringList MetaStack::getExpanded(const Location& location)
{
    if (count() > 1)
        location.fatal(tr("Missing '}'"));

    top().close();
    return top().accum;
}

QT_STATIC_CONST_IMPL QString Config::dot = QLatin1String(".");
QMap<QString, QString> Config::uncompressedFiles;
QMap<QString, QString> Config::extractedDirs;
int Config::numInstances;

/*!
  \class Config
  \brief The Config class contains the configuration variables
  for controlling how qdoc produces documentation.

  Its load() function, reads, parses, and processes a qdocconf file.
 */

/*!
  The constructor sets the \a programName and initializes all
  internal state variables to empty values.
 */
Config::Config(const QString& programName)
    : prog(programName)
{
    loc = Location::null;
    lastLoc = Location::null;
    locMap.clear();
    stringValueMap.clear();
    stringListValueMap.clear();
    numInstances++;
}

/*!
  The destructor deletes all the temporary files and
  directories it built.
 */
Config::~Config()
{
    if (--numInstances == 0) {
	QMap<QString, QString>::ConstIterator f = uncompressedFiles.begin();
	while (f != uncompressedFiles.end()) {
	    QDir().remove(*f);
	    ++f;
	}
	uncompressedFiles.clear();

	QMap<QString, QString>::ConstIterator d = extractedDirs.begin();
	while (d != extractedDirs.end()) {
	    removeDirContents(*d);
	    QDir dir(*d);
	    QString name = dir.dirName();
	    dir.cdUp();
	    dir.rmdir(name);
	    ++d;
	}
	extractedDirs.clear();
    }
}

/*!
  Loads and parses the qdoc configuration file \a fileName.
  This function calls the other load() function, which does
  the loading, parsing, and processing of the configuration
  file.

  Intializes the location variables returned by location()
  and lastLocation().
 */
void Config::load(const QString& fileName)
{
    load(Location::null, fileName);
    if (loc.isEmpty()) {
	loc = Location(fileName);
    }
    else {
	loc.setEtc(true);
    }
    lastLoc = Location::null;
}

/*!
  Joins all the strings in \a values into a single string with the
  individual \a values separated by ' '. Then it inserts the result
  into the string list map with \a var as the key.

  It also inserts the \a values string list into a separate map,
  also with \a var as the key.
 */
void Config::setStringList(const QString& var, const QStringList& values)
{
    stringValueMap[var] = values.join(QLatin1String(" "));
    stringListValueMap[var] = values;
}

/*!
  Looks up the configuarion variable \a var in the string
  map and returns the boolean value.
 */
bool Config::getBool(const QString& var) const
{
    return QVariant(getString(var)).toBool();
}

/*!
  Looks up the configuration variable \a var in the string list
  map. Iterates through the string list found, interpreting each
  string in the list as an integer and adding it to a total sum.
  Returns the sum.
 */
int Config::getInt(const QString& var) const
{
    QStringList strs = getStringList(var);
    QStringList::ConstIterator s = strs.begin();
    int sum = 0;

    while (s != strs.end()) {
	sum += (*s).toInt();
	++s;
    }
    return sum;
}

/*!
  First, this function looks up the configuration variable \a var
  in the location map and, if found, sets the internal variable
  \c{lastLoc} to the Location that \a var maps to.
  
  Then it looks up the configuration variable \a var in the string
  map, and returns the string that \a var maps to.
 */
QString Config::getString(const QString& var) const
{
    if (!locMap[var].isEmpty())
	(Location&) lastLoc = locMap[var];
    return stringValueMap[var];
}

/*!
  Looks up the configuration variable \a var in the string
  list map, converts the string list it maps to into a set
  of strings, and returns the set.
 */
QSet<QString> Config::getStringSet(const QString& var) const
{
    return QSet<QString>::fromList(getStringList(var));
}

/*!
  First, this function looks up the configuration variable \a var
  in the location map and, if found, sets the internal variable
  \c{lastLoc} the Location that \a var maps to.
  
  Then it looks up the configuration variable \a var in the string
  list map, and returns the string list that \a var maps to.
 */
QStringList Config::getStringList(const QString& var) const
{
    if (!locMap[var].isEmpty())
	(Location&) lastLoc = locMap[var];
    return stringListValueMap[var];
}

/*!
  Calls getRegExpList() with the control variable \a var and
  iterates through the resulting list of regular expressions,
  concatening them with some extras characters to form a single
  QRegExp, which is returned/

  \sa getRegExpList()
 */
QRegExp Config::getRegExp(const QString& var) const
{
    QString pattern;
    QList<QRegExp> subRegExps = getRegExpList(var);
    QList<QRegExp>::ConstIterator s = subRegExps.begin();

    while (s != subRegExps.end()) {
        if (!(*s).isValid())
            return *s;
        if (!pattern.isEmpty())
            pattern += QLatin1Char('|');
        pattern += QLatin1String("(?:") + (*s).pattern() + QLatin1Char(')');
        ++s;
    }
    if (pattern.isEmpty())
        pattern = QLatin1String("$x"); // cannot match
    return QRegExp(pattern);
}

/*!
  Looks up the configuration variable \a var in the string list
  map, converts the string list to a list of regular expressions,
  and returns it.
 */
QList<QRegExp> Config::getRegExpList(const QString& var) const
{
    QStringList strs = getStringList(var);
    QStringList::ConstIterator s = strs.begin();
    QList<QRegExp> regExps;

    while (s != strs.end()) {
	regExps += QRegExp(*s);
	++s;
    }
    return regExps;
}

/*!
  This function is slower than it could be.
 */
QSet<QString> Config::subVars(const QString& var) const
{
    QSet<QString> result;
    QString varDot = var + QLatin1Char('.');
    QMap<QString, QString>::ConstIterator v = stringValueMap.begin();
    while (v != stringValueMap.end()) {
        if (v.key().startsWith(varDot)) {
            QString subVar = v.key().mid(varDot.length());
            int dot = subVar.indexOf(QLatin1Char('.'));
            if (dot != -1)
                subVar.truncate(dot);
            result.insert(subVar);
        }
        ++v;
    }
    return result;
}

/*!
  Builds and returns a list of file pathnames for the file
  type specified by \a filesVar (e.g. "headers" or "sources").
  The files are found in the directories specified by
  \a dirsVar, and they are filtered by \a defaultNameFilter
  if a better filter can't be constructed from \a filesVar.
  The directories in \a excludedDirs are avoided.
 */
QStringList Config::getAllFiles(const QString &filesVar,
                                const QString &dirsVar,
				const QString &defaultNameFilter,
                                const QSet<QString> &excludedDirs)
{
    QStringList result = getStringList(filesVar);
    QStringList dirs = getStringList(dirsVar);

    QString nameFilter = getString(filesVar + dot +
        QLatin1String(CONFIG_FILEEXTENSIONS));
    if (nameFilter.isEmpty())
        nameFilter = defaultNameFilter;

    QStringList::ConstIterator d = dirs.begin();
    while (d != dirs.end()) {
	result += getFilesHere(*d, nameFilter, excludedDirs);
	++d;
    }
    return result;
}

/*!
  \a fileName is the path of the file to find.

  \a files and \a dirs are the lists where we must find the
  components of \a fileName.
  
  \a location is used for obtaining the file and line numbers
  for report qdoc errors.
 */
QString Config::findFile(const Location& location,
                         const QStringList& files,
                         const QStringList& dirs,
                         const QString& fileName,
                         QString& userFriendlyFilePath)
{
    if (fileName.isEmpty() || fileName.startsWith(QLatin1Char('/'))) {
        userFriendlyFilePath = fileName;
        return fileName;
    }

    QFileInfo fileInfo;
    QStringList components = fileName.split(QLatin1Char('?'));
    QString firstComponent = components.first();

    QStringList::ConstIterator f = files.begin();
    while (f != files.end()) {
	if (*f == firstComponent ||
            (*f).endsWith(QLatin1Char('/') + firstComponent)) {
	    fileInfo.setFile(*f);
	    if (!fileInfo.exists())
		location.fatal(tr("File '%1' does not exist").arg(*f));
	    break;
	}
	++f;
    }

    if (fileInfo.fileName().isEmpty()) {
	QStringList::ConstIterator d = dirs.begin();
	while (d != dirs.end()) {
	    fileInfo.setFile(QDir(*d), firstComponent);
	    if (fileInfo.exists()) {
		break;
            }
	    ++d;
	}
    }

    userFriendlyFilePath = QString();
    if (!fileInfo.exists())
	    return QString();

    QStringList::ConstIterator c = components.begin();
    for (;;) {
	bool isArchive = (c != components.end() - 1);
	ArchiveExtractor *extractor = 0;
	QString userFriendly = *c;

	if (isArchive) {
	    extractor = ArchiveExtractor::extractorForFileName(userFriendly);
        }

	if (extractor == 0) {
	    Uncompressor *uncompressor =
		    Uncompressor::uncompressorForFileName(userFriendly);
	    if (uncompressor != 0) {
		QString fileNameWithCorrectExtension =
			uncompressor->uncompressedFilePath(
				fileInfo.filePath());
		QString uncompressed = uncompressedFiles[fileInfo.filePath()];
		if (uncompressed.isEmpty()) {
		    uncompressed =
                        QTemporaryFile(fileInfo.filePath()).fileName();
		    uncompressor->uncompressFile(location,
                                                 fileInfo.filePath(),
                                                 uncompressed);
		    uncompressedFiles[fileInfo.filePath()] = uncompressed;
		}
		fileInfo.setFile(uncompressed);

		if (isArchive) {
		    extractor = ArchiveExtractor::extractorForFileName(
					fileNameWithCorrectExtension);
		}
                else {
		    userFriendly = fileNameWithCorrectExtension;
		}
	    }
	}
	userFriendlyFilePath += userFriendly;

	if (isArchive) {
	    if (extractor == 0)
		location.fatal(tr("Unknown archive type '%1'")
				.arg(userFriendlyFilePath));
	    QString extracted = extractedDirs[fileInfo.filePath()];
	    if (extracted.isEmpty()) {
		extracted = QTemporaryFile(fileInfo.filePath()).fileName();
		if (!QDir().mkdir(extracted))
		    location.fatal(tr("Cannot create temporary directory '%1'")
				    .arg(extracted));
		extractor->extractArchive(location, fileInfo.filePath(),
					   extracted);
		extractedDirs[fileInfo.filePath()] = extracted;
	    }
	    ++c;
	    fileInfo.setFile(QDir(extracted), *c);
	}
        else {
	    break;
	}
	userFriendlyFilePath += "?";
    }
    return fileInfo.filePath();
}

/*!
 */
QString Config::findFile(const Location& location,
                         const QStringList& files,
                         const QStringList& dirs,
                         const QString& fileBase,
                         const QStringList& fileExtensions,
                         QString& userFriendlyFilePath)
{
    QStringList::ConstIterator e = fileExtensions.begin();
    while (e != fileExtensions.end()) {
	QString filePath = findFile(location, files, dirs, fileBase + "." + *e,
				     userFriendlyFilePath);
	if (!filePath.isEmpty())
	    return filePath;
	++e;
    }
    return findFile(location, files, dirs, fileBase, userFriendlyFilePath);
}

/*!
  Copies the \a sourceFilePath to the file name constructed by
  concatenating \a targetDirPath and \a userFriendlySourceFilePath.
  \a location is for identifying the file and line number where
  a qdoc error occurred. The constructed output file name is
  returned.
 */
QString Config::copyFile(const Location& location,
                         const QString& sourceFilePath,
                         const QString& userFriendlySourceFilePath,
                         const QString& targetDirPath)
{
    QFile inFile(sourceFilePath);
    if (!inFile.open(QFile::ReadOnly)) {
	location.fatal(tr("Cannot open input file '%1': %2")
			.arg(inFile.fileName()).arg(inFile.errorString()));
	return "";
    }

    QString outFileName = userFriendlySourceFilePath;
    int slash = outFileName.lastIndexOf("/");
    if (slash != -1)
	outFileName = outFileName.mid(slash);

    QFile outFile(targetDirPath + "/" + outFileName);
    if (!outFile.open(QFile::WriteOnly)) {
	location.fatal(tr("Cannot open output file '%1': %2")
			.arg(outFile.fileName()).arg(outFile.errorString()));
	return "";
    }

    char buffer[1024];
    int len;
    while ((len = inFile.read(buffer, sizeof(buffer))) > 0) {
	outFile.write(buffer, len);
    }
    return outFileName;
}

/*!
  Finds the largest unicode digit in \a value in the range
  1..7 and returns it.
 */
int Config::numParams(const QString& value)
{
    int max = 0;
    for (int i = 0; i != value.length(); i++) {
        uint c = value[i].unicode();
        if (c > 0 && c < 8)
            max = qMax(max, (int)c);
    }
    return max;
}

/*!
  Removes everything from \a dir. This function is recursive.
  It doesn't remove \a dir itself, but if it was called
  recursively, then the caller will remove \a dir.
 */
bool Config::removeDirContents(const QString& dir)
{
    QDir dirInfo(dir);
    QFileInfoList entries = dirInfo.entryInfoList();

    bool ok = true;

    QFileInfoList::Iterator it = entries.begin();
    while (it != entries.end()) {
	if ((*it).isFile()) {
	    if (!dirInfo.remove((*it).fileName()))
		ok = false;
	}
        else if ((*it).isDir()) {
	    if ((*it).fileName() != "." && (*it).fileName() != "..") {
		if (removeDirContents((*it).absoluteFilePath())) {
		    if (!dirInfo.rmdir((*it).fileName()))
			ok = false;
		}
                else {
		    ok = false;
		}
	    }
	}
	++it;
    }
    return ok;
}

/*!
  Returns true if \a ch is a letter, number, '_', '.',
  '{', '}', or ','.
 */
bool Config::isMetaKeyChar(QChar ch)
{
    return ch.isLetterOrNumber()
        || ch == QLatin1Char('_')
        || ch == QLatin1Char('.')
        || ch == QLatin1Char('{')
        || ch == QLatin1Char('}')
        || ch == QLatin1Char(',');
}

/*!
  Load, parse, and process a qdoc configuration file. This
  function is only called by the other load() function, but
  this one is recursive, i.e., it calls itself when it sees
  an \c{include} statement in the qdog configuration file.
 */
void Config::load(Location location, const QString& fileName)
{
    QRegExp keySyntax("\\w+(?:\\.\\w+)*");

#define SKIP_CHAR() \
    do { \
        location.advance(c); \
        ++i; \
        c = text.at(i); \
        cc = c.unicode(); \
    } while (0)

#define SKIP_SPACES() \
    while (c.isSpace() && cc != '\n') \
        SKIP_CHAR()

#define PUT_CHAR() \
    word += c; \
    SKIP_CHAR();

    if (location.depth() > 16)
        location.fatal(tr("Too many nested includes"));

    QFile fin(fileName);
    if (!fin.open(QFile::ReadOnly | QFile::Text)) {
        fin.setFileName(fileName + ".qdoc");
        if (!fin.open(QFile::ReadOnly | QFile::Text))
            location.fatal(tr("Cannot open file '%1': %2").arg(fileName).arg(fin.errorString()));
    }

    QString text = fin.readAll();
    text += QLatin1String("\n\n");
    text += QChar('\0');
    fin.close();

    location.push(fileName);
    location.start();

    int i = 0;
    QChar c = text.at(0);
    uint cc = c.unicode();
    while (i < (int) text.length()) {
        if (cc == 0)
            ++i;
        else if (c.isSpace()) {
            SKIP_CHAR();
        }
        else if (cc == '#') {
            do {
                SKIP_CHAR();
            } while (cc != '\n');
        }
        else if (isMetaKeyChar(c)) {
            Location keyLoc = location;
            bool plus = false;
            QString stringValue;
            QStringList stringListValue;
            QString word;
            bool inQuote = false;
            bool prevWordQuoted = true;
            bool metWord = false;

            MetaStack stack;
            do {
                stack.process(c, location);
                SKIP_CHAR();
            } while (isMetaKeyChar(c));

            QStringList keys = stack.getExpanded(location);
            SKIP_SPACES();

            if (keys.count() == 1 && keys.first() == "include") {
                QString includeFile;

                if (cc != '(')
                    location.fatal(tr("Bad include syntax"));
                SKIP_CHAR();
                SKIP_SPACES();
                while (!c.isSpace() && cc != '#' && cc != ')') {
                    includeFile += c;
                    SKIP_CHAR();
                }
                SKIP_SPACES();
                if (cc != ')')
                    location.fatal(tr("Bad include syntax"));
                SKIP_CHAR();
                SKIP_SPACES();
                if (cc != '#' && cc != '\n')
                    location.fatal(tr("Trailing garbage"));

                /*
                  Here is the recursive call.
                 */
                load(location,
                      QFileInfo(QFileInfo(fileName).dir(), includeFile)
                      .filePath());
            }
            else {
                /*
                  It wasn't an include statement, so it;s something else.
                 */
                if (cc == '+') {
                    plus = true;
                    SKIP_CHAR();
                }
                if (cc != '=')
                    location.fatal(tr("Expected '=' or '+=' after key"));
                SKIP_CHAR();
                SKIP_SPACES();

                for (;;) {
                    if (cc == '\\') {
                        int metaCharPos;

                        SKIP_CHAR();
                        if (cc == '\n') {
                            SKIP_CHAR();
                        }
                        else if (cc > '0' && cc < '8') {
                            word += QChar(c.digitValue());
                            SKIP_CHAR();
                        }
                        else if ((metaCharPos = QString::fromLatin1("abfnrtv").indexOf(c)) != -1) {
                            word += "\a\b\f\n\r\t\v"[metaCharPos];
                            SKIP_CHAR();
                        }
                        else {
                            PUT_CHAR();
                        }
                    }
                    else if (c.isSpace() || cc == '#') {
                        if (inQuote) {
                            if (cc == '\n')
                                location.fatal(tr("Unterminated string"));
                            PUT_CHAR();
                        }
                        else {
                            if (!word.isEmpty()) {
                                if (metWord)
                                    stringValue += QLatin1Char(' ');
                                stringValue += word;
                                stringListValue << word;
                                metWord = true;
                                word.clear();
                                prevWordQuoted = false;
                            }
                            if (cc == '\n' || cc == '#')
                                break;
                            SKIP_SPACES();
                        }
                    }
                    else if (cc == '"') {
                        if (inQuote) {
                            if (!prevWordQuoted)
                                stringValue += QLatin1Char(' ');
                            stringValue += word;
                            if (!word.isEmpty())
                                stringListValue << word;
                            metWord = true;
                            word.clear();
                            prevWordQuoted = true;
                        }
                        inQuote = !inQuote;
                        SKIP_CHAR();
                    }
                    else if (cc == '$') {
                        QString var;
                        SKIP_CHAR();
                        while (c.isLetterOrNumber() || cc == '_') {
                            var += c;
                            SKIP_CHAR();
                        }
                        if (!var.isEmpty()) {
                            char *val = getenv(var.toLatin1().data());
                            if (val == 0) {
                                location.fatal(tr("Environment variable '%1' undefined").arg(var));
                            }
                            else {
                                word += QString(val);
                            }
                        }
                    }
                    else {
                        if (!inQuote && cc == '=')
                            location.fatal(tr("Unexpected '='"));
                        PUT_CHAR();
                    }
                }

                QStringList::ConstIterator key = keys.begin();
                while (key != keys.end()) {
                    if (!keySyntax.exactMatch(*key))
                        keyLoc.fatal(tr("Invalid key '%1'").arg(*key));

                    if (plus) {
                        if (locMap[*key].isEmpty()) {
                            locMap[*key] = keyLoc;
                        }
                        else {
                            locMap[*key].setEtc(true);
                        }
                        if (stringValueMap[*key].isEmpty()) {
                            stringValueMap[*key] = stringValue;
                        }
                        else {
                            stringValueMap[*key] +=
                                QLatin1Char(' ') + stringValue;
                        }
                        stringListValueMap[*key] += stringListValue;
                    }
                    else {
                        locMap[*key] = keyLoc;
                        stringValueMap[*key] = stringValue;
                        stringListValueMap[*key] = stringListValue;
                    }
                    ++key;
                }
            }
        }
        else {
            location.fatal(tr("Unexpected character '%1' at beginning of line")
                            .arg(c));
        }
    }
}

QStringList Config::getFilesHere(const QString& dir,
                                 const QString& nameFilter,
                                 const QSet<QString> &excludedDirs)
{
    QStringList result;
    if (excludedDirs.contains(dir))
        return result;

    QDir dirInfo(dir);
    QStringList fileNames;
    QStringList::const_iterator fn;

    dirInfo.setNameFilters(nameFilter.split(' '));
    dirInfo.setSorting(QDir::Name);
    dirInfo.setFilter(QDir::Files);
    fileNames = dirInfo.entryList();
    fn = fileNames.constBegin();
    while (fn != fileNames.constEnd()) {
        if (!fn->startsWith(QLatin1Char('~')))
            result.append(dirInfo.filePath(*fn));
	++fn;
    }    
    
    dirInfo.setNameFilters(QStringList("*"));
    dirInfo.setFilter(QDir::Dirs|QDir::NoDotAndDotDot);
    fileNames = dirInfo.entryList();
    fn = fileNames.constBegin();
    while (fn != fileNames.constEnd()) {
        result += getFilesHere(dirInfo.filePath(*fn), nameFilter, excludedDirs);
	++fn;
    }
    return result;
}

QT_END_NAMESPACE